optimize cx16 sys.wait and sys.waitvsync to use WAI instruction

This commit is contained in:
Irmen de Jong 2021-05-17 18:44:42 +02:00
parent ca61248861
commit e4fb5946dd

View File

@ -759,28 +759,28 @@ sys {
}} }}
} }
sub wait(uword jiffies) { asmsub wait(uword jiffies @AY) {
; --- wait approximately the given number of jiffies (1/60th seconds) ; --- wait approximately the given number of jiffies (1/60th seconds) (N or N+1)
repeat jiffies { ; note: regular system vsync irq handler must be running, and no nother irqs
ubyte jiff = lsb(c64.RDTIM16()) %asm {{
while jiff==lsb(c64.RDTIM16()) { - wai ; wait for irq (assume it was vsync)
; wait until 1 jiffy has passed cmp #0
} bne +
} dey
+ dec a
bne -
cpy #0
bne -
rts
}}
} }
asmsub waitvsync() clobbers(A, X, Y) { inline asmsub waitvsync() {
; --- busy wait till the next vsync has occurred (approximately), without depending on custom irq handling. ; --- suspend execution until the next vsync has occurred, without depending on custom irq handling.
; note: system vsync irq handler has to be active for this routine to work. ; note: system vsync irq handler has to be active for this routine to work (and no other irqs).
; note 2: a more accurate way to wait for vsync is to set up a vsync irq handler instead. ; note: a more accurate way to wait for vsync is to set up a vsync irq handler instead.
%asm {{ %asm {{
jsr c64.RDTIM wai
sta _mod + 1
inc _mod + 1
_loop jsr c64.RDTIM
_mod cmp #255 ; modified
bne _loop
rts
}} }}
} }