From 1e9bbd662b713b66c23478a2e8883abcacaa8baa Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 15 Dec 2024 23:32:50 +0100 Subject: [PATCH] add palette.set_rgb_nosplit() and set_rbg_be_nosplit() fix stream-wav missing rts which corrupted playback fix showbmx example palette and image centering --- compiler/res/prog8lib/cx16/palette.p8 | 38 ++++++++++++++---- docs/source/libraries.rst | 6 +-- docs/source/todo.rst | 20 +++++----- examples/cx16/balloonflight.p8 | 6 +-- examples/cx16/bubbleuniverse.p8 | 2 +- examples/cx16/pcmaudio/play-adpcm.p8 | 3 +- examples/cx16/pcmaudio/stream-wav.p8 | 5 +-- examples/cx16/showbmx.p8 | 24 +++++++----- examples/cx16/tehtriz.p8 | 55 ++++++++++++++------------- examples/test.p8 | 12 +++--- 10 files changed, 98 insertions(+), 73 deletions(-) diff --git a/compiler/res/prog8lib/cx16/palette.p8 b/compiler/res/prog8lib/cx16/palette.p8 index 8eee5a33d..15555eb92 100644 --- a/compiler/res/prog8lib/cx16/palette.p8 +++ b/compiler/res/prog8lib/cx16/palette.p8 @@ -22,7 +22,18 @@ palette { } sub set_rgb_be(uword palette_ptr, uword num_colors, ubyte startindex) { - ; 1 word per color entry, $0rgb in big endian format + ; 1 word per color entry, $0rgb in big endian format (split arrays) + cx16.vaddr(1, $fa00+(startindex as uword * 2), 0, 1) + repeat num_colors { + cx16.VERA_DATA0 = @(palette_ptr+num_colors) + cx16.VERA_DATA0 = @(palette_ptr) + palette_ptr++ + } + cx16.VERA_ADDR_H &= 1 + } + + sub set_rgb_be_nosplit(uword palette_ptr, uword num_colors, ubyte startindex) { + ; 1 word per color entry, $0rgb in big endian format (linear arrays) cx16.vaddr(1, $fa00+(startindex as uword * 2), 0, 1) repeat num_colors { cx16.VERA_DATA0 = @(palette_ptr+1) @@ -33,7 +44,18 @@ palette { } sub set_rgb(uword palette_words_ptr, uword num_colors, ubyte startindex) { - ; 1 word per color entry (in little endian format as layed out in video memory, so $gb;$0r) + ; 1 word per color entry (in little endian format as layed out in video memory, so $gb;$0r) (split arrays) + cx16.vaddr(1, $fa00+(startindex as uword * 2), 0, 1) + repeat num_colors { + cx16.VERA_DATA0 = @(palette_words_ptr) + cx16.VERA_DATA0 = @(palette_words_ptr+num_colors) + palette_words_ptr++ + } + cx16.VERA_ADDR_H &= 1 + } + + sub set_rgb_nosplit(uword palette_words_ptr, uword num_colors, ubyte startindex) { + ; 1 word per color entry (in little endian format as layed out in video memory, so $gb;$0r) (linear arrays) cx16.vaddr(1, $fa00+(startindex as uword * 2), 0, 1) repeat num_colors { cx16.VERA_DATA0 = @(palette_words_ptr) @@ -188,7 +210,7 @@ palette { sub set_c64pepto() { ; set first 16 colors to the "Pepto" PAL commodore-64 palette http://www.pepto.de/projects/colorvic/ - uword[] colors = [ + uword[] @nosplit colors = [ $000, ; 0 = black $FFF, ; 1 = white $833, ; 2 = red @@ -206,12 +228,12 @@ palette { $76e, ; 14 = light blue $bbb ; 15 = light grey ] - set_rgb(colors, len(colors), 0) + set_rgb_nosplit(colors, len(colors), 0) } sub set_c64ntsc() { ; set first 16 colors to a NTSC commodore-64 palette - uword[] colors = [ + uword[] @nosplit colors = [ $000, ; 0 = black $FFF, ; 1 = white $934, ; 2 = red @@ -229,12 +251,12 @@ palette { $36f, ; 14 = light blue $ccc ; 15 = light grey ] - set_rgb(colors, len(colors), 0) + set_rgb_nosplit(colors, len(colors), 0) } sub set_default16() { ; set first 16 colors to the defaults on the X16 - uword[] colors = [ + uword[] @nosplit colors = [ $000, ; 0 = black $fff, ; 1 = white $800, ; 2 = red @@ -252,6 +274,6 @@ palette { $08f, ; 14 = light blue $bbb ; 15 = light grey ] - set_rgb(colors, len(colors), 0) + set_rgb_nosplit(colors, len(colors), 0) } } diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index 0baf08004..83fa57fa8 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -950,9 +950,9 @@ On the other targets, it only contains the definition of the 16 memory-mapped vi bmx (cx16 only) ---------------- -Routines to load and save "BMX" files, the CommanderX16 bitmap file format. -Specification available here: https://cx16forum.com/forum/viewtopic.php?t=6945 -Only *uncompressed* bitmaps are supported in this library for now. +Routines to load and save "BMX" files, the CommanderX16 bitmap file format: +`BMX file format specification `_ +Only the *uncompressed* bitmaps variant is supported in this library for now. The routines are designed to be fast and bulk load/save the data directly into or from vram, without the need to buffer something in main memory. diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 7aeb80837..ac8bb8cd7 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,20 +2,18 @@ TODO ==== - DONE: make word arrays split by default (remove @split tag) and use new @nosplit tag to make an array use the old storage format? -- DONE: invert -splitarrays command line option to -dontsplitarrays -- DONE: remove "splitarrays" %option switch +- DONE: &splitarray will give you the start address of the lsb-array (which is immediately followed by the msb-array) +- DONE: invert -splitarrays command line option: -dontsplitarrays and remove "splitarrays" %option switch - DONE: added sprites.pos_batch_nosplit when the x/y arrays are linear instead of split word arrays -- update Syntax files + Document all of this (also that word arrays can then have length 256 by default as well, and that @linear will reduce it to half.) -- test all examples and projects - - (paint has wrong palette colors) - - cx16/balloonflight is black - - cx16/bubbleunivers,kefrenbars has wrong colors - - cx16 stream-wav has broken playback? -- benchmark program became slower!? (did get smaller, just slower????) -- showbmx example has wrong colors and doesn't center the picture correctly (robocat4.bmx) (imageviewer is fine?) -- cx16/tehtriz should be better centered vertically +- DONE: add palette.set_rgb_nosplit() and set_rbg_be_nosplit() for linear instead of split word arrays +- update Syntax files + Document all of this (also that word arrays can then have length 256 by default as well, and that @nosplit will reduce it to half.) +- also document that kernal routines such as FB_set_palette() expect a @nosplit word array otherwise colors turn up bad +- benchmark program became slower!? (did get smaller) - add &< and &> operators to get the address of the lsb-array and msb-array, respectively. +- remove the error when using @split and make it so that @split always splits the array even when the dontsplit option is enabled. (ast check that you can only put this on word arrays) + +- announce prog8 on the 6502.org site? ... diff --git a/examples/cx16/balloonflight.p8 b/examples/cx16/balloonflight.p8 index 5c6988cf0..44817d8e0 100644 --- a/examples/cx16/balloonflight.p8 +++ b/examples/cx16/balloonflight.p8 @@ -124,9 +124,9 @@ spritedata { for cx16.r0 in 0 to 32*32/2-1 cx16.VERA_DATA0 = @(&moonsprite + cx16.r0) - for cx16.r1L in 0 to 15 { - palette.set_color(cx16.r1L + 16, balloon_pallette[cx16.r1L]) - palette.set_color(cx16.r1L + 32, moon_pallette[cx16.r1L]) + for cx16.r4L in 0 to 15 { + palette.set_color(cx16.r4L + 16, balloon_pallette[cx16.r4L]) + palette.set_color(cx16.r4L + 32, moon_pallette[cx16.r4L]) } } diff --git a/examples/cx16/bubbleuniverse.p8 b/examples/cx16/bubbleuniverse.p8 index db73e66cf..bcd018179 100644 --- a/examples/cx16/bubbleuniverse.p8 +++ b/examples/cx16/bubbleuniverse.p8 @@ -15,7 +15,7 @@ main { const ubyte s = 60 float t - uword[] palette = [$000, $000, $00f, $f0f, $0ff, $fff] + uword[] @nosplit palette = [$000, $000, $00f, $f0f, $0ff, $fff] cx16.FB_set_palette(palette, 0, len(palette)) repeat { diff --git a/examples/cx16/pcmaudio/play-adpcm.p8 b/examples/cx16/pcmaudio/play-adpcm.p8 index 9b34f965f..47b801ef1 100644 --- a/examples/cx16/pcmaudio/play-adpcm.p8 +++ b/examples/cx16/pcmaudio/play-adpcm.p8 @@ -278,8 +278,7 @@ stereo { lda p8v_right_msb,y sta cx16.VERA_AUDIO_DATA iny - iny - cpy #16 + cpy #8 bne - }} } diff --git a/examples/cx16/pcmaudio/stream-wav.p8 b/examples/cx16/pcmaudio/stream-wav.p8 index 60edfdc5e..5bea754d2 100644 --- a/examples/cx16/pcmaudio/stream-wav.p8 +++ b/examples/cx16/pcmaudio/stream-wav.p8 @@ -285,7 +285,7 @@ _lp2 lda $ffff,y inc _lp2+2 dex bne _loop - ; !notreached! + rts }} ; original prog8 code: ; uword @requirezp ptr = main.start.buffer @@ -391,8 +391,7 @@ _lp2 lda $ffff,y lda p8v_right_msb,y sta cx16.VERA_AUDIO_DATA iny - iny - cpy #16 + cpy #8 bne - }} } diff --git a/examples/cx16/showbmx.p8 b/examples/cx16/showbmx.p8 index 37aed17f7..b036c7688 100644 --- a/examples/cx16/showbmx.p8 +++ b/examples/cx16/showbmx.p8 @@ -58,6 +58,12 @@ main { ; need to use the slower load routine that does padding ; center the image on the screen nicely uword offset = (320-bmx.width)/2 + (240-bmx.height)/2*320 + when(bmx.bitsperpixel) { + 1 -> offset /= 8 + 2 -> offset /= 4 + 4 -> offset /= 2 + else -> {} + } if bmx.continue_load_stamp(0, offset, 320) { activate_palette() void txt.waitkey() @@ -78,16 +84,16 @@ main { } sub activate_palette() { - ; copies the pallette data from the memory buffer into vram + ; copies the palette data from the memory buffer into vram cx16.VERA_DC_BORDER = bmx.border - cx16.r1 = bmx.palette_buffer_ptr - cx16.r2L = bmx.palette_start - cx16.r3L = lsb(bmx.palette_entries) + cx16.r4 = bmx.palette_buffer_ptr + cx16.r5L = bmx.palette_start + cx16.r6L = lsb(bmx.palette_entries) do { - palette.set_color(cx16.r2L, peekw(cx16.r1)) - cx16.r1+=2 - cx16.r2L++ - cx16.r3L-- - } until cx16.r3L==0 + palette.set_color(cx16.r5L, peekw(cx16.r4)) + cx16.r4+=2 + cx16.r5L++ + cx16.r6L-- + } until cx16.r6L==0 } } diff --git a/examples/cx16/tehtriz.p8 b/examples/cx16/tehtriz.p8 index a8f8f052f..dc04b918e 100644 --- a/examples/cx16/tehtriz.p8 +++ b/examples/cx16/tehtriz.p8 @@ -15,7 +15,7 @@ main { const ubyte boardOffsetX = 14 - const ubyte boardOffsetY = 3 + const ubyte boardOffsetY = 5 const ubyte boardWidth = 10 const ubyte boardHeight = 20 const ubyte startXpos = boardOffsetX + 3 @@ -306,25 +306,26 @@ waitkey: } sub gameOver() { + const ubyte yoffset = 7 sound.gameover() - txt.plot(7, 7) + txt.plot(7, yoffset) txt.chrout('U') txt.print("────────────────────────") txt.chrout('I') - txt.plot(7, 8) + txt.plot(7, yoffset+1) txt.print("│*** g a m e o v e r ***│") - txt.plot(7, 9) + txt.plot(7, yoffset+2) txt.chrout('J') txt.print("────────────────────────") txt.chrout('K') - txt.plot(7, 18) + txt.plot(7, yoffset+11) txt.chrout('U') txt.print("────────────────────────") txt.chrout('I') - txt.plot(7, 19) + txt.plot(7, yoffset+12) txt.print("│ f1/start for new game │") - txt.plot(7, 20) + txt.plot(7, yoffset+13) txt.chrout('J') txt.print("────────────────────────") txt.chrout('K') @@ -367,36 +368,37 @@ waitkey: } sub drawBoard() { + const ubyte yoffset = 2 txt.clear_screen() txt.color(7) - txt.plot(1,1) + txt.plot(1,1+yoffset) txt.print("* tehtriz *") txt.color(5) - txt.plot(6,4) + txt.plot(6,4+yoffset) txt.print("hold:") - txt.plot(2,22) + txt.plot(2,22+yoffset) txt.print("speed: ") - txt.plot(28,3) + txt.plot(28,3+yoffset) txt.print("next:") - txt.plot(28,10) + txt.plot(28,10+yoffset) txt.print("lines:") - txt.plot(28,14) + txt.plot(28,14+yoffset) txt.print("score:") txt.color(12) - txt.plot(27,18) + txt.plot(27,18+yoffset) txt.print("controls:") txt.color(11) - txt.plot(28,19) + txt.plot(28,19+yoffset) txt.print(",/ move") - txt.plot(28,20) + txt.plot(28,20+yoffset) txt.print("zx rotate") - txt.plot(29,21) + txt.plot(29,21+yoffset) txt.print(". descend") - txt.plot(27,22) + txt.plot(27,22+yoffset) txt.print("spc drop") - txt.plot(29,23) + txt.plot(29,23+yoffset) txt.print("c hold") - txt.plot(25,24) + txt.plot(25,24+yoffset) txt.print("or joystick #1") txt.setcc(boardOffsetX-1, boardOffsetY-2, 255, 0) ; invisible barrier @@ -423,25 +425,26 @@ waitkey: for i in len(colors)-1 downto 0 { ubyte x for x in 5 downto 0 { - txt.setcc(6+x-i, 11+2*i, 102, colors[i]) + txt.setcc(6+x-i, 11+2*i+yoffset, 102, colors[i]) } } drawScore() } sub drawScore() { + const ubyte yoffset=2 txt.color(1) - txt.plot(30,11) + txt.plot(30,11+yoffset) txt.print_uw(lines) - txt.plot(30,15) + txt.plot(30,15+yoffset) txt.print_uw(score) - txt.plot(9,22) + txt.plot(9,22+yoffset) txt.print_ub(speedlevel) } sub drawNextBlock() { const ubyte nextBlockXpos = 29 - const ubyte nextBlockYpos = 5 + const ubyte nextBlockYpos = 7 ubyte x for x in nextBlockXpos+3 downto nextBlockXpos { txt.setcc2(x, nextBlockYpos, ' ', 0) @@ -457,7 +460,7 @@ waitkey: sub drawHoldBlock() { const ubyte holdBlockXpos = 7 - const ubyte holdBlockYpos = 6 + const ubyte holdBlockYpos = 8 ubyte x for x in holdBlockXpos+3 downto holdBlockXpos { txt.setcc2(x, holdBlockYpos, '@', 0) diff --git a/examples/test.p8 b/examples/test.p8 index 3d37b8ce1..db12c4541 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,14 +1,12 @@ %import textio +%import palette %zeropage basicsafe +%option no_sysinit main { sub start() { - uword[] addresses = [scores2, start] - uword[] scores1 = [10, 25, 50, 100] - uword[] scores2 = [100, 250, 500, 1000] - - cx16.r0 = &scores1 - cx16.r1 = &scores2 - cx16.r2 = &addresses + palette.set_c64pepto() + sys.wait(100) + palette.set_default16() } }