moved wait() and reset_system() to sys block so they are now unified across c64 and cx16

This commit is contained in:
Irmen de Jong 2021-01-03 02:36:45 +01:00
parent 3e7c7ab497
commit cb65480c6c
9 changed files with 60 additions and 63 deletions

View File

@ -294,23 +294,6 @@ asmsub init_system() {
}}
}
asmsub reset_system() {
; Soft-reset the system back to Basic prompt.
%asm {{
sei
lda #14
sta $01 ; bank the kernal in
jmp (c64.RESET_VEC)
}}
}
sub wait(uword jiffies) {
c64.SETTIM(0,0,0) ; TODO do the wait without resetting the jiffy clock
while c64.RDTIM16() < jiffies {
; wait till the time catches up
}
}
asmsub disable_runstop_and_charsetswitch() clobbers(A) {
%asm {{
lda #$80
@ -486,9 +469,28 @@ _raster_irq_handler
; ---- end of C64 specific system utility routines ----
}
sys {
; ------- lowlevel system routines --------
asmsub reset_system() {
; Soft-reset the system back to Basic prompt.
%asm {{
sei
lda #14
sta $01 ; bank the kernal in
jmp (c64.RESET_VEC)
}}
}
sub wait(uword jiffies) {
c64.SETTIM(0,0,0) ; TODO do the wait without resetting the jiffy clock
while c64.RDTIM16() < jiffies {
; wait till the time catches up
}
}
}
cx16 {

View File

@ -73,7 +73,6 @@ asmsub STOP2() -> ubyte @A {
}}
}
asmsub RDTIM16() -> uword @AY {
; -- like RDTIM() but only returning the lower 16 bits for convenience
%asm {{
@ -88,7 +87,6 @@ asmsub RDTIM16() -> uword @AY {
}}
}
}
cx16 {
@ -276,9 +274,9 @@ romsub $fed2 = kbdbuf_put(ubyte key @A) clobbers(A,X,Y)
romsub $fecf = entropy_get() -> ubyte @A, ubyte @X, ubyte @Y
romsub $fecc = monitor() clobbers(A,X,Y)
; ---- end of kernal routines ----
; ---- utilities -----
asmsub vpeek(ubyte bank @A, uword address @XY) -> ubyte @A {
; -- get a byte from VERA's video memory
@ -297,7 +295,6 @@ asmsub vpeek(ubyte bank @A, uword address @XY) -> ubyte @A {
}}
}
asmsub vaddr(ubyte bank @A, uword address @R0, ubyte addrsel @R1, byte autoIncrOrDecrByOne @Y) clobbers(A) {
; -- setup the VERA's data address register 0 or 1
%asm {{
@ -323,7 +320,6 @@ asmsub vaddr(ubyte bank @A, uword address @R0, ubyte addrsel @R1, byte autoIncrO
}}
}
asmsub vpoke(ubyte bank @A, uword address @R0, ubyte value @Y) clobbers(A) {
; -- write a single byte to VERA's video memory
; note: inefficient when writing multiple sequential bytes!
@ -428,18 +424,7 @@ _loop ldy #0
}}
}
sub wait(uword jiffies) {
c64.SETTIM(0,0,0) ; TODO do the wait without resetting the jiffy clock
while c64.RDTIM16() < jiffies {
; wait till the time catches up
}
}
; ---- system stuff -----
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
@ -472,15 +457,27 @@ asmsub init_system() {
}}
}
asmsub reset_system() {
; Soft-reset the system back to Basic prompt.
%asm {{
sei
lda #14
sta $01
stz cx16.d1prb ; bank the kernal in
jmp (cx16.RESET_VEC)
}}
}
sys {
; ------- lowlevel system routines --------
asmsub reset_system() {
; Soft-reset the system back to Basic prompt.
%asm {{
sei
lda #14
sta $01
stz cx16.d1prb ; bank the kernal in
jmp (cx16.RESET_VEC)
}}
}
sub wait(uword jiffies) {
c64.SETTIM(0,0,0) ; TODO do the wait without resetting the jiffy clock
while c64.RDTIM16() < jiffies {
; wait till the time catches up
}
}
}

View File

@ -152,9 +152,9 @@ internal class AsmGen(private val program: Program,
if(options.zeropage !in setOf(ZeropageType.BASICSAFE, ZeropageType.DONTUSE)) {
out("""
; zeropage is clobbered so we need to reset the machine at exit
lda #>${CompilationTarget.instance.name}.reset_system
lda #>sys.reset_system
pha
lda #<${CompilationTarget.instance.name}.reset_system
lda #<sys.reset_system
pha""")
}

View File

@ -4,7 +4,6 @@ TODO
- move all str* builtin functions to a str library module
- make the syslib.wait() functions not reset the jiffy clock to 0
- move wait() and others? to sys.* block to unify them from c64.* and cx16.* separation
- detect variables that are written but never read - mark those as unused too and remove them, such as uword unused = memory("unused222", 20) - also remove the memory slab allocation
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
- make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_'

View File

@ -37,7 +37,7 @@ main {
angley+=217
anglez+=452
c64.wait(2)
sys.wait(2)
; test_stack.test()
}

View File

@ -62,7 +62,7 @@ main {
}
gfx2.text(80, 420, 1, @"cos(x)+x")
cx16.wait(3*60)
sys.wait(3*60)
gfx2.circle(320, 240, 220, 1)
gfx2.circle(320, 240, 210, 1)
@ -74,11 +74,11 @@ main {
gfx2.disc(320, 240, 90, 1)
gfx2.disc(320, 240, 40, 0)
cx16.wait(2*60)
sys.wait(2*60)
repeat 255
gfx2.line(rndw() % 640, rndw() % 480, rndw() % 640, rndw() % 480, 1)
cx16.wait(1*60)
sys.wait(1*60)
}
}

View File

@ -60,12 +60,12 @@ main {
if iff_module.show_image(filenameptr) {
if iff_module.num_cycles {
repeat 500 {
cx16.wait(1)
sys.wait(1)
iff_module.cycle_colors_each_jiffy()
}
}
else
cx16.wait(180)
sys.wait(180)
} else {
load_error(filenameptr)
}
@ -74,7 +74,7 @@ main {
;txt.print("loading ")
;txt.print("pcx\n")
if pcx_module.show_image(filenameptr) {
cx16.wait(180)
sys.wait(180)
} else {
load_error(filenameptr)
}
@ -83,7 +83,7 @@ main {
;txt.print("loading ")
;txt.print("koala\n")
if koala_module.show_image(filenameptr) {
cx16.wait(180)
sys.wait(180)
} else {
load_error(filenameptr)
}
@ -92,7 +92,7 @@ main {
;txt.print("loading ")
;txt.print("bmp\n")
if bmp_module.show_image(filenameptr) {
cx16.wait(180)
sys.wait(180)
} else {
load_error(filenameptr)
}
@ -101,7 +101,7 @@ main {
;; txt.print("loading ")
;; txt.print("ci\n")
; if ci_module.show_image(filenameptr) {
; cx16.wait(180)
; sys.wait(180)
; } else {
; load_error(filenameptr)
; }

View File

@ -125,7 +125,7 @@ main {
xx+=4
}
cx16.wait(3*60)
sys.wait(3*60)
demo2()
@ -143,7 +143,7 @@ main {
for mode in modes {
gfx2.screen_mode(mode)
draw()
cx16.wait(200)
sys.wait(200)
}
}
@ -185,7 +185,7 @@ main {
gfx2.line(x1, y1, x2, y2, i+1)
}
cx16.wait(60)
sys.wait(60)
gfx2.clear_screen()
ubyte radius

View File

@ -1,7 +1,6 @@
%import test_stack
%import textio
%import floats
%zeropage basicsafe
%zeropage full
%option no_sysinit
main {
@ -9,11 +8,11 @@ main {
sub start () {
uword current_time
repeat {
repeat 5 {
current_time = c64.RDTIM16()
txt.print_uw(current_time)
txt.chrout('\n')
repeat 20000 {
repeat 60000 {
current_time++
}
}