From e65c5402d78467323592c9e0f54750257f52d74e Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 22 Feb 2021 01:44:07 +0100 Subject: [PATCH] added cx16 rasterbars example --- compiler/res/prog8lib/cx16/syslib.p8 | 25 +++++++++---- examples/cx16/rasterbars.p8 | 53 ++++++++++++++++++++++++++++ examples/test.p8 | 43 ++++------------------ 3 files changed, 77 insertions(+), 44 deletions(-) create mode 100644 examples/cx16/rasterbars.p8 diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index 27dea9a9c..e18de4abd 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -614,13 +614,8 @@ asmsub set_rasterirq(uword handler @AY, uword rasterpos @R0) clobbers(A) { ora #%00000010 ; enable the line (raster) irq sta cx16.VERA_IEN lda cx16.r0 - sta cx16.VERA_IRQ_LINE_L - lda cx16.r0+1 - lsr a - ror a - and #%10000000 - ora cx16.VERA_IEN - sta cx16.VERA_IEN ; high bit of the raster line + ldy cx16.r0+1 + jsr set_rasterline lda #<_raster_irq_handler sta cx16.CINV lda #>_raster_irq_handler @@ -643,6 +638,22 @@ _modified jsr $ffff ; modified }} } +asmsub set_rasterline(uword line @AY) { + %asm {{ + sta cx16.VERA_IRQ_LINE_L + lda cx16.VERA_IEN + and #%01111111 + sta cx16.VERA_IEN + tya + lsr a + ror a + and #%10000000 + ora cx16.VERA_IEN + sta cx16.VERA_IEN + rts + }} +} + } diff --git a/examples/cx16/rasterbars.p8 b/examples/cx16/rasterbars.p8 new file mode 100644 index 000000000..c918a4b70 --- /dev/null +++ b/examples/cx16/rasterbars.p8 @@ -0,0 +1,53 @@ +%import textio + +main { + + sub start() { + cx16.screen_set_mode(0) + txt.plot(14,14) + txt.print("raster bars!") + cx16.set_rasterirq(&irq.irq, 0) + + repeat { + ; don't exit + } + } +} + + +irq { + uword[32] colors = [ + $011, $112, $213, $214, + $315, $316, $417, $418, + $519, $51a, $62b, $62c, + $73d, $73e, $84f, $94f, + $93e, $83d, $82c, $72b, + $71a, $619, $618, $517, + $516, $415, $414, $313, + $312, $211, $100, $000 + ] + + uword next_irq_line = 0 + ubyte color_idx = 0 + ubyte yanim = 0 + const ubyte barheight = 4 + + sub irq() { + uword c = colors[color_idx] + color_idx++ + color_idx &= 31 + + if color_idx==0 { + yanim++ + next_irq_line = $0030 + sin8u(yanim) + } else { + next_irq_line += barheight + } + + ; set new screen background color + cx16.vpoke(1, $fa00, lsb(c)) + cx16.vpoke(1, $fa01, msb(c)) + + cx16.set_rasterline(next_irq_line) + } +} diff --git a/examples/test.p8 b/examples/test.p8 index 23f1ef511..84e92a775 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,47 +1,16 @@ %import textio -%zeropage dontuse -%option no_sysinit main { ; $1F9C0 - $1F9FF PSG registers sub start() { - cx16.set_rasterirq(&irq.irq, 100) - ;cx16.set_irq(&irq.irq, true) - sys.wait(100) - cx16.restore_irq() + txt.print("tone") -; uword freq = 1181 -; cx16.vpoke(1, $f9c0, lsb(freq)) -; cx16.vpoke(1, $f9c1, msb(freq)) -; cx16.vpoke(1, $f9c2, %11111111) ; volume -; cx16.vpoke(1, $f9c3, %11000000) ; triangle waveform - } -} - - -irq { - %option force_output - - uword counter = 0 - - sub irq() { - cx16.vpoke(1, $fa00+6*2, lsb(counter)) - cx16.vpoke(1, $fa01+6*2, msb(counter)) - repeat 20 { - uword xx - repeat 16 { - xx++ - } - cx16.vpoke(1, $fa00+6*2, 0) - cx16.vpoke(1, $fa01+6*2, 255) - repeat 16 { - xx++ - } - cx16.vpoke(1, $fa00+6*2, 0) - cx16.vpoke(1, $fa01+6*2, 0) - } - counter++ + uword freq = 1181 + cx16.vpoke(1, $f9c0, lsb(freq)) + cx16.vpoke(1, $f9c1, msb(freq)) + cx16.vpoke(1, $f9c2, %11111111) ; volume + cx16.vpoke(1, $f9c3, %11000000) ; triangle waveform } }