Skip to content

Commit

Permalink
possible workaround for SMC issue that could make sys.reset_system() …
Browse files Browse the repository at this point in the history
…and sys.poweroff_system() not work properly
  • Loading branch information
irmen committed Feb 24, 2025
1 parent 3e2b2a6 commit 94653e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
13 changes: 9 additions & 4 deletions compiler/res/prog8lib/cx16/syslib.p8
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ _continue iny

sub poweroff_system() {
; -- use the SMC to shutdown the computer
void cx16.i2c_write_byte($42, $01, $00)
sys.poweroff_system()
}

sub set_led_state(bool on) {
Expand Down Expand Up @@ -1530,16 +1530,21 @@ asmsub set_rasterline(uword line @AY) {
; (note: this is an asmsub on purpose! don't change into a normal sub)
%asm {{
sei
ldx #$42
- ldx #$42
ldy #2
lda #0
jmp cx16.i2c_write_byte
jsr cx16.i2c_write_byte
bra - ; to work around an issue where the routine does not in fact immediately reset the system
; !notreached!
}}
}

sub poweroff_system() {
; use the SMC to shutdown the computer
void cx16.i2c_write_byte($42, $01, $00)
; in a loop for the event where the shutdown command does not in fact immediately shutdown the system
repeat {
void cx16.i2c_write_byte($42, $01, $00)
}
}

asmsub wait(uword jiffies @AY) clobbers(X) {
Expand Down
1 change: 0 additions & 1 deletion docs/source/todo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Future Things and Ideas

IR/VM
-----
- can onetimeInitializationNumericValue be removed from IRStStaticVariable?
- getting it in shape for code generation...: the IR file should be able to encode every detail about a prog8 program (the VM doesn't have to actually be able to run all of it though!)
- fix call() return value handling
- proper code gen for the CALLI instruction and that it (optionally) returns a word value that needs to be assigned to a reg
Expand Down
12 changes: 3 additions & 9 deletions examples/test.p8
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
%option no_sysinit, romable

main {
ubyte[100] @shared array1
ubyte[100] @shared array2 = [42] *100

sub start() {
uword @shared pointer = $4000
ubyte @shared size = 42

for cx16.r0L in 5 to size {
@(pointer)++
@(pointer)--
repeat {
if cbm.GETIN2()==27
sys.poweroff_system()
}
}
}

0 comments on commit 94653e5

Please sign in to comment.