diff --git a/compiler/res/prog8lib/c64/syslib.p8 b/compiler/res/prog8lib/c64/syslib.p8 index e9b0ca9da..9615ec8d4 100644 --- a/compiler/res/prog8lib/c64/syslib.p8 +++ b/compiler/res/prog8lib/c64/syslib.p8 @@ -502,6 +502,8 @@ sys { ; --- busy wait till the next vsync has occurred (approximately), without depending on custom irq handling. ; note: a more accurate way to wait for vsync is to set up a vsync irq handler instead. %asm {{ +- lda c64.RASTER + beq - - lda c64.RASTER bne - bit c64.SCROLY @@ -510,6 +512,15 @@ sys { }} } + inline asmsub waitrastborder() { + ; --- busy wait till the raster position has reached the bottom screen border (approximately) + ; note: a more accurate way to do this is by using a raster irq handler instead. + %asm {{ +- bit c64.SCROLY + bpl - + }} + } + asmsub memcopy(uword source @R0, uword target @R1, uword count @AY) clobbers(A,X,Y) { %asm {{ ldx cx16.r0 diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index 9eed96d48..f0050f05c 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -105,9 +105,15 @@ sys (part of syslib) ``waitvsync()`` busy wait till the next vsync has occurred (approximately), without depending on custom irq handling. + can be used to avoid screen flicker/tearing when updating screen contents. note: a more accurate way to wait for vsync is to set up a vsync irq handler instead. note for cx16: the system irq handler has to be active for this to work (this is not required on c64) +``waitrastborder()`` (c64 target only) + busy wait till the raster position has reached the bottom screen border (approximately) + can be used to avoid screen flicker/tearing when updating screen contents. + note: a more accurate way to do this is by using a raster irq handler instead. + ``reset_system()`` 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) diff --git a/examples/test.p8 b/examples/test.p8 index 89c29f404..7eb4329cf 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,10 +1,26 @@ %import textio %zeropage basicsafe +%option no_sysinit main { sub start() { + ubyte color=0 + ubyte xx + uword ptr = $0400 + + @($02) = 0 + + repeat { + sys.waitvsync() + %asm {{ + ldy $02 + lda #'*' + sta $0400,y + inc $02 + }} + } txt.print("hello") ; str filename = "titlescreen.bin"