From cd6c33a92c046ed700103fb4e530948a2c3f26fe Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Thu, 17 Dec 2020 23:34:39 +0100 Subject: [PATCH] CX16 sprite example is now a 256-color 64*64 TUT sprite. #581 --- src/test/kc/examples/cx16/sprites.c | 12 +- src/test/ref/examples/cx16/sprites.asm | 21 ++-- src/test/ref/examples/cx16/sprites.cfg | 6 +- src/test/ref/examples/cx16/sprites.log | 155 ++++++++++++------------- src/test/ref/examples/cx16/sprites.sym | 7 +- 5 files changed, 97 insertions(+), 104 deletions(-) diff --git a/src/test/kc/examples/cx16/sprites.c b/src/test/kc/examples/cx16/sprites.c index b1daf920c..aa697dabd 100644 --- a/src/test/kc/examples/cx16/sprites.c +++ b/src/test/kc/examples/cx16/sprites.c @@ -8,7 +8,7 @@ #define NUM_SPRITES 32 // A 64*64 8bpp TUT sprite -align(0x1200) char SPRITE_PIXELS[64*64] = kickasm(resource "tut.png") {{ +align(0x1000) char SPRITE_PIXELS[64*64+0x200] = kickasm(resource "tut.png") {{ .var pic = LoadPicture("tut.png") // palette: rgb->idx .var palette = Hashtable() @@ -29,14 +29,14 @@ align(0x1200) char SPRITE_PIXELS[64*64] = kickasm(resource "tut.png") {{ .byte idx } } - // Output sprite palette (offset 64*64 bytes= + // Output sprite palette (offset 64*64 bytes) .for(var i=0;i<256;i++) { .var rgb = palList.get(i) .var red = floor(rgb / [256*256]) .var green = floor(rgb/256) & 255 .var blue = rgb & 255 // bits 4-8: green, bits 0-3 blue - .byte (green/16)>>4 | blue/16 + .byte green&$f0 | blue/16 // bits bits 0-3 red .byte red/16 } @@ -51,7 +51,7 @@ struct VERA_SPRITE SPRITE_ATTR = { <(SPRITE_PIXELS_VRAM/32)|VERA_SPRITE_8BPP, 32 void main() { // Copy sprite data to VRAM - memcpy_to_vram((char)>SPRITE_PIXELS_VRAM, SPRITE_PIXELS_VRAM, VERA_PALETTE, =SINX_LEN) i_x -= SINX_LEN; - i_y += 5; if(i_y>=SINY_LEN) i_y -= SINY_LEN; + i_x += 25; if(i_x>=SINX_LEN) i_x -= SINX_LEN; + i_y += 19; if(i_y>=SINY_LEN) i_y -= SINY_LEN; } // Reset the VSYNC interrupt diff --git a/src/test/ref/examples/cx16/sprites.asm b/src/test/ref/examples/cx16/sprites.asm index 78c06a237..68611d737 100644 --- a/src/test/ref/examples/cx16/sprites.asm +++ b/src/test/ref/examples/cx16/sprites.asm @@ -36,7 +36,6 @@ .const OFFSET_STRUCT_VERA_SPRITE_X = 2 .const OFFSET_STRUCT_VERA_SPRITE_Y = 4 .const VERA_SPRITES_ENABLE = $40 - .const SIZEOF_BYTE = 1 // $9F20 VRAM Address (7:0) .label VERA_ADDRX_L = $9f20 // $9F21 VRAM Address (15:8) @@ -238,8 +237,8 @@ irq_vsync: { bcc !+ inc.z vram_sprite_pos+1 !: - // i_x += 9 - lda #9 + // i_x += 25 + lda #$19 clc adc.z i_x sta.z i_x @@ -262,8 +261,8 @@ irq_vsync: { sbc #0 sta.z i_x+1 __b8: - // i_y += 5 - lda #5 + // i_y += 19 + lda #$13 clc adc.z i_y sta.z i_y @@ -294,11 +293,11 @@ main: { // Copy 8* sprite attributes to VRAM .label vram_sprite_attr = $a .label s = 9 - // memcpy_to_vram((char)>SPRITE_PIXELS_VRAM, SPRITE_PIXELS_VRAM, $40*$40*SIZEOF_BYTE + lda #>$40*$40 sta.z memcpy_to_vram.num+1 lda #idx @@ -490,14 +489,14 @@ SPRITE_PIXELS: .byte idx } } - // Output sprite palette (offset 64*64 bytes= + // Output sprite palette (offset 64*64 bytes) .for(var i=0;i<256;i++) { .var rgb = palList.get(i) .var red = floor(rgb / [256*256]) .var green = floor(rgb/256) & 255 .var blue = rgb & 255 // bits 4-8: green, bits 0-3 blue - .byte (green/16)>>4 | blue/16 + .byte green&$f0 | blue/16 // bits bits 0-3 red .byte red/16 } diff --git a/src/test/ref/examples/cx16/sprites.cfg b/src/test/ref/examples/cx16/sprites.cfg index dbdc6a46f..51ac72381 100644 --- a/src/test/ref/examples/cx16/sprites.cfg +++ b/src/test/ref/examples/cx16/sprites.cfg @@ -60,7 +60,7 @@ irq_vsync::@6: scope:[irq_vsync] from irq_vsync::@5 to:irq_vsync::@12 irq_vsync::@12: scope:[irq_vsync] from irq_vsync::@6 [27] irq_vsync::vram_sprite_pos#1 = irq_vsync::vram_sprite_pos#2 + SIZEOF_STRUCT_VERA_SPRITE - [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + 9 + [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + $19 [29] if(irq_vsync::i_x#1VERA_SPRITE_ATTR, main::@5/(byte)>VERA_PALETTE ) [56] memcpy_to_vram::vdest#4 = phi( irq_vsync::@6/memcpy_to_vram::vdest#3, main/(void*)VERA_SPRITE_ATTR main::vram_sprite_attr &SPRITE_ATTR main::$6 +Setting struct to load/store in variable affected by address-of main::$6 = call memcpy_to_vram (byte)>VERA_SPRITE_ATTR main::vram_sprite_attr &SPRITE_ATTR main::$5 Setting struct to load/store in variable affected by address-of irq_vsync::$5 = call memcpy_to_vram irq_vsync::vram_sprite_attr_bank irq_vsync::vram_sprite_pos &SPRITE_ATTR+2 4 -Resolving sizeof() main::$6 = sizeof SPRITE_ATTR -Resolving sizeof() main::$8 = sizeof SPRITE_ATTR +Resolving sizeof() main::$5 = sizeof SPRITE_ATTR +Resolving sizeof() main::$7 = sizeof SPRITE_ATTR Resolving sizeof() irq_vsync::$6 = sizeof SPRITE_ATTR Inlined call call SEI Inlined call call CLI @@ -46,11 +46,10 @@ memcpy_to_vram::@return: scope:[memcpy_to_vram] from memcpy_to_vram::@1 void main() main: scope:[main] from __start::@1 - main::$0 = sizeof SPRITE_PIXELS memcpy_to_vram::vbank#0 = (byte)>SPRITE_PIXELS_VRAM memcpy_to_vram::vdest#0 = (void*)VERA_SPRITE_ATTR memcpy_to_vram::vdest#2 = (void*)main::vram_sprite_attr#2 memcpy_to_vram::src#2 = (void*)&SPRITE_ATTR - memcpy_to_vram::num#2 = main::$6 + memcpy_to_vram::num#2 = main::$5 call memcpy_to_vram to:main::@7 main::@7: scope:[main] from main::@2 main::s#3 = phi( main::@2/main::s#4 ) main::vram_sprite_attr#3 = phi( main::@2/main::vram_sprite_attr#2 ) - main::$8 = SIZEOF_STRUCT_VERA_SPRITE - main::vram_sprite_attr#1 = main::vram_sprite_attr#3 + main::$8 + main::$7 = SIZEOF_STRUCT_VERA_SPRITE + main::vram_sprite_attr#1 = main::vram_sprite_attr#3 + main::$7 main::s#1 = ++ main::s#3 to:main::@1 main::@3: scope:[main] from main::@1 @@ -162,7 +161,7 @@ irq_vsync::@12: scope:[irq_vsync] from irq_vsync::@6 irq_vsync::vram_sprite_pos#3 = phi( irq_vsync::@6/irq_vsync::vram_sprite_pos#2 ) irq_vsync::$6 = SIZEOF_STRUCT_VERA_SPRITE irq_vsync::vram_sprite_pos#1 = irq_vsync::vram_sprite_pos#3 + irq_vsync::$6 - irq_vsync::i_x#1 = irq_vsync::i_x#4 + 9 + irq_vsync::i_x#1 = irq_vsync::i_x#4 + $19 irq_vsync::$7 = irq_vsync::i_x#1 >= SINX_LEN irq_vsync::$8 = ! irq_vsync::$7 if(irq_vsync::$8) goto irq_vsync::@8 @@ -176,7 +175,7 @@ irq_vsync::@8: scope:[irq_vsync] from irq_vsync::@10 irq_vsync::@12 irq_vsync::i_x#9 = phi( irq_vsync::@10/irq_vsync::i_x#2, irq_vsync::@12/irq_vsync::i_x#1 ) irq_vsync::s#5 = phi( irq_vsync::@10/irq_vsync::s#6, irq_vsync::@12/irq_vsync::s#7 ) irq_vsync::i_y#4 = phi( irq_vsync::@10/irq_vsync::i_y#7, irq_vsync::@12/irq_vsync::i_y#8 ) - irq_vsync::i_y#1 = irq_vsync::i_y#4 + 5 + irq_vsync::i_y#1 = irq_vsync::i_y#4 + $13 irq_vsync::$9 = irq_vsync::i_y#1 >= SINY_LEN irq_vsync::$10 = ! irq_vsync::$9 if(irq_vsync::$10) goto irq_vsync::@9 @@ -235,7 +234,7 @@ const nomodify byte SINY_LEN = $fb const byte SIZEOF_STRUCT_VERA_SPRITE = 8 const byte SIZEOF_WORD = 2 struct VERA_SPRITE SPRITE_ATTR loadstore = { ADDR: (word)idx .var palette = Hashtable() // RGB value for each palette index @@ -255,14 +254,14 @@ const byte* SPRITE_PIXELS[$40*$40] = kickasm {{ .var pic = LoadPicture("tut.png .byte idx } } - // Output sprite palette (offset 64*64 bytes= + // Output sprite palette (offset 64*64 bytes) .for(var i=0;i<256;i++) { .var rgb = palList.get(i) .var red = floor(rgb / [256*256]) .var green = floor(rgb/256) & 255 .var blue = rgb & 255 // bits 4-8: green, bits 0-3 blue - .byte (green/16)>>4 | blue/16 + .byte green&$f0 | blue/16 // bits bits 0-3 red .byte red/16 } @@ -343,10 +342,9 @@ byte* irq_vsync::vram_sprite_pos#6 byte* irq_vsync::vram_sprite_pos#7 byte* irq_vsync::vram_sprite_pos#8 void main() -byte~ main::$0 -bool~ main::$5 -byte~ main::$6 -byte~ main::$8 +bool~ main::$4 +byte~ main::$5 +byte~ main::$7 byte main::s byte main::s#0 byte main::s#1 @@ -404,9 +402,10 @@ volatile word sin_idx_y loadstore Adding number conversion cast (unumber) = SINX_LEN -Inversing boolean not [94] irq_vsync::$10 = irq_vsync::i_y#1 < SINY_LEN from [93] irq_vsync::$9 = irq_vsync::i_y#1 >= SINY_LEN +Inversing boolean not [56] irq_vsync::$1 = sin_idx_x != SINX_LEN from [55] irq_vsync::$0 = sin_idx_x == SINX_LEN +Inversing boolean not [60] irq_vsync::$3 = sin_idx_y != $ffff from [59] irq_vsync::$2 = sin_idx_y == $ffff +Inversing boolean not [86] irq_vsync::$8 = irq_vsync::i_x#1 < SINX_LEN from [85] irq_vsync::$7 = irq_vsync::i_x#1 >= SINX_LEN +Inversing boolean not [93] irq_vsync::$10 = irq_vsync::i_y#1 < SINY_LEN from [92] irq_vsync::$9 = irq_vsync::i_y#1 >= SINY_LEN Successful SSA optimization Pass2UnaryNotSimplification Alias memcpy_to_vram::end#0 = memcpy_to_vram::$3 Alias memcpy_to_vram::s#2 = memcpy_to_vram::s#3 Alias memcpy_to_vram::end#1 = memcpy_to_vram::end#2 -Alias memcpy_to_vram::num#0 = main::$0 Alias main::vram_sprite_attr#2 = main::vram_sprite_attr#4 main::vram_sprite_attr#3 Alias main::s#2 = main::s#4 main::s#3 -Alias memcpy_to_vram::num#2 = main::$6 +Alias memcpy_to_vram::num#2 = main::$5 Alias irq_vsync::i_x#3 = irq_vsync::i_x#6 irq_vsync::i_x#4 Alias irq_vsync::i_y#3 = irq_vsync::i_y#6 irq_vsync::i_y#8 irq_vsync::i_y#7 Alias irq_vsync::vram_sprite_pos#2 = irq_vsync::vram_sprite_pos#4 irq_vsync::vram_sprite_pos#3 @@ -498,19 +497,19 @@ Successful SSA optimization Pass2AliasElimination Identical Phi Values memcpy_to_vram::end#1 memcpy_to_vram::end#0 Successful SSA optimization Pass2IdenticalPhiElimination Simple Condition memcpy_to_vram::$4 [13] if(memcpy_to_vram::s#2!=memcpy_to_vram::end#0) goto memcpy_to_vram::@2 -Simple Condition main::$5 [31] if(main::s#2<$20) goto main::@2 +Simple Condition main::$4 [31] if(main::s#2<$20) goto main::@2 Simple Condition irq_vsync::$1 [51] if(sin_idx_x!=SINX_LEN) goto irq_vsync::@1 Simple Condition irq_vsync::$3 [54] if(sin_idx_y!=$ffff) goto irq_vsync::@2 Simple Condition irq_vsync::$4 [63] if(irq_vsync::s#2<$20) goto irq_vsync::@6 Simple Condition irq_vsync::$8 [77] if(irq_vsync::i_x#1SPRITE_PIXELS_VRAM Constant memcpy_to_vram::vdest#0 = (void*)VERA_PALETTE Constant memcpy_to_vram::vdest#1 = (void*)VERA_SPRITE_ATTR Constant memcpy_to_vram::src#2 = (void*)&SPRITE_ATTR -Constant main::$8 = SIZEOF_STRUCT_VERA_SPRITE +Constant main::$7 = SIZEOF_STRUCT_VERA_SPRITE Constant irq_vsync::vram_sprite_pos#0 = (byte*)SPRITE_PIXELS_VRAM in Successful SSA optimization PassNSimplifyConstantZero Simplifying constant integer cast VERA_SPRITE_ATTR Constant inlined memcpy_to_vram::num#3 = 4 Constant inlined memcpy_to_vram::num#2 = SIZEOF_STRUCT_VERA_SPRITE Constant inlined memcpy_to_vram::vbank#3 = irq_vsync::vram_sprite_attr_bank -Constant inlined main::$8 = SIZEOF_STRUCT_VERA_SPRITE +Constant inlined main::$7 = SIZEOF_STRUCT_VERA_SPRITE Constant inlined memcpy_to_vram::num#1 = $200 Successful SSA optimization Pass2ConstantInlining Eliminating unused constant SIZEOF_WORD Successful SSA optimization PassNEliminateUnusedVars Finalized unsigned number type (byte) $40 Finalized unsigned number type (byte) $40 +Finalized unsigned number type (word) $200 Finalized unsigned number type (word) $140 Finalized unsigned number type (byte) $20 Finalized unsigned number type (byte) $f0 Finalized unsigned number type (byte) $20 Finalized unsigned number type (byte) $40 Finalized unsigned number type (byte) $40 +Finalized unsigned number type (byte) $40 +Finalized unsigned number type (byte) $40 Successful SSA optimization PassNFinalizeNumberTypeConversions Simplifying constant integer cast $140-$20 Successful SSA optimization PassNCastSimplification @@ -700,7 +698,7 @@ irq_vsync::@6: scope:[irq_vsync] from irq_vsync::@5 to:irq_vsync::@12 irq_vsync::@12: scope:[irq_vsync] from irq_vsync::@6 [27] irq_vsync::vram_sprite_pos#1 = irq_vsync::vram_sprite_pos#2 + SIZEOF_STRUCT_VERA_SPRITE - [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + 9 + [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + $19 [29] if(irq_vsync::i_x#1VERA_SPRITE_ATTR, main::@5/(byte)>VERA_PALETTE ) [56] memcpy_to_vram::vdest#4 = phi( irq_vsync::@6/memcpy_to_vram::vdest#3, main/(void*)memcpy_to_vram] memcpy_to_vram_from_main: - // [56] phi memcpy_to_vram::num#4 = (word)$40*$40*SIZEOF_BYTE [phi:main->memcpy_to_vram#0] -- vwuz1=vwuc1 - lda #<$40*$40*SIZEOF_BYTE + // [56] phi memcpy_to_vram::num#4 = (word)$40*$40 [phi:main->memcpy_to_vram#0] -- vwuz1=vwuc1 + lda #<$40*$40 sta.z memcpy_to_vram.num - lda #>$40*$40*SIZEOF_BYTE + lda #>$40*$40 sta.z memcpy_to_vram.num+1 // [56] phi memcpy_to_vram::src#4 = (void*)SPRITE_PIXELS [phi:main->memcpy_to_vram#1] -- pvoz1=pvoc1 lda #idx @@ -1698,14 +1695,14 @@ SPRITE_PIXELS: .byte idx } } - // Output sprite palette (offset 64*64 bytes= + // Output sprite palette (offset 64*64 bytes) .for(var i=0;i<256;i++) { .var rgb = palList.get(i) .var red = floor(rgb / [256*256]) .var green = floor(rgb/256) & 255 .var blue = rgb & 255 // bits 4-8: green, bits 0-3 blue - .byte (green/16)>>4 | blue/16 + .byte green&$f0 | blue/16 // bits bits 0-3 red .byte red/16 } @@ -1805,10 +1802,9 @@ const nomodify byte SINX_LEN = $f1 const word* SINY[SINY_LEN] = kickasm {{ .fillword 256, 208+208*sin(i*2*PI/SINY_LEN) }} const nomodify byte SINY_LEN = $fb -const byte SIZEOF_BYTE = 1 const byte SIZEOF_STRUCT_VERA_SPRITE = 8 struct VERA_SPRITE SPRITE_ATTR loadstore mem[8] = { ADDR: idx .var palette = Hashtable() // RGB value for each palette index @@ -1828,14 +1824,14 @@ const byte* SPRITE_PIXELS[$40*$40] = kickasm {{ .var pic = LoadPicture("tut.png .byte idx } } - // Output sprite palette (offset 64*64 bytes= + // Output sprite palette (offset 64*64 bytes) .for(var i=0;i<256;i++) { .var rgb = palList.get(i) .var red = floor(rgb / [256*256]) .var green = floor(rgb/256) & 255 .var blue = rgb & 255 // bits 4-8: green, bits 0-3 blue - .byte (green/16)>>4 | blue/16 + .byte green&$f0 | blue/16 // bits bits 0-3 red .byte red/16 } @@ -1977,7 +1973,6 @@ Score: 8528 .const OFFSET_STRUCT_VERA_SPRITE_X = 2 .const OFFSET_STRUCT_VERA_SPRITE_Y = 4 .const VERA_SPRITES_ENABLE = $40 - .const SIZEOF_BYTE = 1 // $9F20 VRAM Address (7:0) .label VERA_ADDRX_L = $9f20 // $9F21 VRAM Address (15:8) @@ -2230,9 +2225,9 @@ irq_vsync: { bcc !+ inc.z vram_sprite_pos+1 !: - // i_x += 9 - // [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + 9 -- vwuz1=vwuz1_plus_vbuc1 - lda #9 + // i_x += 25 + // [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + $19 -- vwuz1=vwuz1_plus_vbuc1 + lda #$19 clc adc.z i_x sta.z i_x @@ -2261,9 +2256,9 @@ irq_vsync: { // [31] phi irq_vsync::i_x#7 = irq_vsync::i_x#2 [phi:irq_vsync::@10/irq_vsync::@12->irq_vsync::@8#0] -- register_copy // irq_vsync::@8 __b8: - // i_y += 5 - // [32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + 5 -- vwuz1=vwuz1_plus_vbuc1 - lda #5 + // i_y += 19 + // [32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + $13 -- vwuz1=vwuz1_plus_vbuc1 + lda #$13 clc adc.z i_y sta.z i_y @@ -2307,14 +2302,14 @@ main: { // Copy 8* sprite attributes to VRAM .label vram_sprite_attr = $a .label s = 9 - // memcpy_to_vram((char)>SPRITE_PIXELS_VRAM, SPRITE_PIXELS_VRAM, memcpy_to_vram] - // [56] phi memcpy_to_vram::num#4 = (word)$40*$40*SIZEOF_BYTE [phi:main->memcpy_to_vram#0] -- vwuz1=vwuc1 - lda #<$40*$40*SIZEOF_BYTE + // [56] phi memcpy_to_vram::num#4 = (word)$40*$40 [phi:main->memcpy_to_vram#0] -- vwuz1=vwuc1 + lda #<$40*$40 sta.z memcpy_to_vram.num - lda #>$40*$40*SIZEOF_BYTE + lda #>$40*$40 sta.z memcpy_to_vram.num+1 // [56] phi memcpy_to_vram::src#4 = (void*)SPRITE_PIXELS [phi:main->memcpy_to_vram#1] -- pvoz1=pvoc1 lda #idx @@ -2570,14 +2565,14 @@ SPRITE_PIXELS: .byte idx } } - // Output sprite palette (offset 64*64 bytes= + // Output sprite palette (offset 64*64 bytes) .for(var i=0;i<256;i++) { .var rgb = palList.get(i) .var red = floor(rgb / [256*256]) .var green = floor(rgb/256) & 255 .var blue = rgb & 255 // bits 4-8: green, bits 0-3 blue - .byte (green/16)>>4 | blue/16 + .byte green&$f0 | blue/16 // bits bits 0-3 red .byte red/16 } diff --git a/src/test/ref/examples/cx16/sprites.sym b/src/test/ref/examples/cx16/sprites.sym index 63f591205..ffcf6e5c0 100644 --- a/src/test/ref/examples/cx16/sprites.sym +++ b/src/test/ref/examples/cx16/sprites.sym @@ -7,10 +7,9 @@ const nomodify byte SINX_LEN = $f1 const word* SINY[SINY_LEN] = kickasm {{ .fillword 256, 208+208*sin(i*2*PI/SINY_LEN) }} const nomodify byte SINY_LEN = $fb -const byte SIZEOF_BYTE = 1 const byte SIZEOF_STRUCT_VERA_SPRITE = 8 struct VERA_SPRITE SPRITE_ATTR loadstore mem[8] = { ADDR: idx .var palette = Hashtable() // RGB value for each palette index @@ -30,14 +29,14 @@ const byte* SPRITE_PIXELS[$40*$40] = kickasm {{ .var pic = LoadPicture("tut.png .byte idx } } - // Output sprite palette (offset 64*64 bytes= + // Output sprite palette (offset 64*64 bytes) .for(var i=0;i<256;i++) { .var rgb = palList.get(i) .var red = floor(rgb / [256*256]) .var green = floor(rgb/256) & 255 .var blue = rgb & 255 // bits 4-8: green, bits 0-3 blue - .byte (green/16)>>4 | blue/16 + .byte green&$f0 | blue/16 // bits bits 0-3 red .byte red/16 }