improved and added a few system routines for the cx16

This commit is contained in:
Irmen de Jong 2023-04-18 23:20:28 +02:00
parent a296d26328
commit 5b2d29bef6
3 changed files with 25 additions and 46 deletions

View File

@ -917,13 +917,27 @@ sys {
asmsub reset_system() { asmsub reset_system() {
; Soft-reset the system back to initial power-on Basic prompt. ; Soft-reset the system back to initial power-on Basic prompt.
; We do this via the SMC so that a true reset is performed that also resets the Vera fully.
%asm {{ %asm {{
sei sei
stz $01 ; bank the kernal in ldx #$42
jmp (cx16.RESET_VEC) ldy #1
tya
jsr cx16.i2c_write_byte
bra *
}} }}
} }
sub poweroff_system() {
; use the SMC to shutdown the computer
cx16.i2c_write_byte($42, $01, $00)
}
sub set_leds_brightness(ubyte activity, ubyte power) {
cx16.i2c_write_byte($42, $04, power)
cx16.i2c_write_byte($42, $05, activity)
}
asmsub wait(uword jiffies @AY) { asmsub wait(uword jiffies @AY) {
; --- wait approximately the given number of jiffies (1/60th seconds) (N or N+1) ; --- wait approximately the given number of jiffies (1/60th seconds) (N or N+1)
; note: the system irq handler has to be active for this to work as it depends on the system jiffy clock ; note: the system irq handler has to be active for this to work as it depends on the system jiffy clock

View File

@ -112,6 +112,12 @@ sys (part of syslib)
Soft-reset the system back to initial power-on BASIC prompt. Soft-reset the system back to initial power-on BASIC prompt.
(called automatically by Prog8 when the main subroutine returns and the program is not using basicsafe zeropage option) (called automatically by Prog8 when the main subroutine returns and the program is not using basicsafe zeropage option)
``poweroff_system()`` (commander x16 only)
Powers down the computer.
``set_leds_brightness(ubyte activity, ubyte power)`` (commander x16 only)
Sets the brightness of the activity and power leds on the computer.
conv conv
---- ----

View File

@ -1,50 +1,9 @@
%import textio %import textio
%import math
%import floats
%import string
main { main {
ubyte a
sub func1() {
a++
}
sub func2() -> ubyte {
a++
return a
}
sub start() { sub start() {
a=42 sys.set_leds_brightness(255, 255)
func1() sys.wait(120)
txt.print_ub(a) sys.reset_system()
txt.nl()
txt.print_ub(func2())
txt.nl()
floats.print_f(floats.PI)
sys.wait(60)
} }
} }
;main33 {
;
; sub calc(ubyte x, ubyte y) -> uword {
; %ir {{
; loadcpu.b r42,A
; loadcpu.w r42,XY
; }}
; repeat x+y {
; x++
; }
; when x {
; 1 -> y++
; 3 -> y++
; else -> y++
; }
; y--
; return x as uword * y
; }
; sub start() {
; txt.print_uw(calc(22, 33))
; }
;}