1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-26 12:49:21 +00:00

CX16 sprite example is now a 256-color 64*64 TUT sprite. #581

This commit is contained in:
jespergravgaard 2020-12-17 23:34:39 +01:00
parent e6962d38ac
commit cd6c33a92c
5 changed files with 97 additions and 104 deletions

View File

@ -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, SPRITE_PIXELS, sizeof(SPRITE_PIXELS));
memcpy_to_vram((char)>SPRITE_PIXELS_VRAM, <SPRITE_PIXELS_VRAM, SPRITE_PIXELS, 64*64);
// Copy sprite palette to VRAM
memcpy_to_vram((char)>VERA_PALETTE, <VERA_PALETTE, SPRITE_PIXELS+64*64, 0x200);
// Copy 8* sprite attributes to VRAM
@ -104,8 +104,8 @@ void irq_vsync() {
// Copy sprite positions to VRAM (the 4 relevant bytes in VERA_SPRITE_ATTR)
memcpy_to_vram(vram_sprite_attr_bank, vram_sprite_pos, &SPRITE_ATTR+2, 4);
vram_sprite_pos += sizeof(SPRITE_ATTR);
i_x += 9; if(i_x>=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

View File

@ -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, SPRITE_PIXELS, sizeof(SPRITE_PIXELS))
// memcpy_to_vram((char)>SPRITE_PIXELS_VRAM, <SPRITE_PIXELS_VRAM, SPRITE_PIXELS, 64*64)
// Copy sprite data to VRAM
lda #<$40*$40*SIZEOF_BYTE
lda #<$40*$40
sta.z memcpy_to_vram.num
lda #>$40*$40*SIZEOF_BYTE
lda #>$40*$40
sta.z memcpy_to_vram.num+1
lda #<SPRITE_PIXELS
sta.z memcpy_to_vram.src
@ -468,7 +467,7 @@ memcpy_to_vram: {
}
.segment Data
// A 64*64 8bpp TUT sprite
.align $1200
.align $1000
SPRITE_PIXELS:
.var pic = LoadPicture("tut.png")
// palette: rgb->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
}

View File

@ -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#1<SINX_LEN) goto irq_vsync::@8
to:irq_vsync::@10
irq_vsync::@10: scope:[irq_vsync] from irq_vsync::@12
@ -68,7 +68,7 @@ irq_vsync::@10: scope:[irq_vsync] from irq_vsync::@12
to:irq_vsync::@8
irq_vsync::@8: scope:[irq_vsync] from irq_vsync::@10 irq_vsync::@12
[31] irq_vsync::i_x#7 = phi( irq_vsync::@10/irq_vsync::i_x#2, irq_vsync::@12/irq_vsync::i_x#1 )
[32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + 5
[32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + $13
[33] if(irq_vsync::i_y#1<SINY_LEN) goto irq_vsync::@9
to:irq_vsync::@11
irq_vsync::@11: scope:[irq_vsync] from irq_vsync::@8
@ -123,7 +123,7 @@ main::@6: scope:[main] from main::@2
void memcpy_to_vram(byte memcpy_to_vram::vbank , void* memcpy_to_vram::vdest , void* memcpy_to_vram::src , word memcpy_to_vram::num)
memcpy_to_vram: scope:[memcpy_to_vram] from irq_vsync::@6 main main::@2 main::@5
[56] memcpy_to_vram::num#4 = phi( irq_vsync::@6/4, main/(word)$40*$40*SIZEOF_BYTE, main::@2/SIZEOF_STRUCT_VERA_SPRITE, main::@5/$200 )
[56] memcpy_to_vram::num#4 = phi( irq_vsync::@6/4, main/(word)$40*$40, main::@2/SIZEOF_STRUCT_VERA_SPRITE, main::@5/$200 )
[56] memcpy_to_vram::src#4 = phi( irq_vsync::@6/(void*)&SPRITE_ATTR+2, main/(void*)SPRITE_PIXELS, main::@2/(void*)&SPRITE_ATTR, main::@5/(void*)SPRITE_PIXELS+(word)$40*$40 )
[56] memcpy_to_vram::vbank#4 = phi( irq_vsync::@6/irq_vsync::vram_sprite_attr_bank, main/0, main::@2/(byte)>VERA_SPRITE_ATTR, main::@5/(byte)>VERA_PALETTE )
[56] memcpy_to_vram::vdest#4 = phi( irq_vsync::@6/memcpy_to_vram::vdest#3, main/(void*)<SPRITE_PIXELS_VRAM, main::@2/memcpy_to_vram::vdest#2, main::@5/(void*)<VERA_PALETTE )

View File

@ -1,8 +1,8 @@
Resolved forward reference irq_vsync to void irq_vsync()
Setting struct to load/store in variable affected by address-of main::$7 = call memcpy_to_vram (byte)>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*)<SPRITE_PIXELS_VRAM
memcpy_to_vram::src#0 = (void*)SPRITE_PIXELS
memcpy_to_vram::num#0 = main::$0
memcpy_to_vram::num#0 = $40*$40
call memcpy_to_vram
to:main::@5
main::@5: scope:[main] from main
@ -67,26 +66,26 @@ main::@6: scope:[main] from main::@5
main::@1: scope:[main] from main::@6 main::@7
main::vram_sprite_attr#4 = phi( main::@6/main::vram_sprite_attr#0, main::@7/main::vram_sprite_attr#1 )
main::s#2 = phi( main::@6/main::s#0, main::@7/main::s#1 )
main::$5 = main::s#2 < $20
if(main::$5) goto main::@2
main::$4 = main::s#2 < $20
if(main::$4) goto main::@2
to:main::@3
main::@2: scope:[main] from main::@1
main::s#4 = phi( main::@1/main::s#2 )
main::vram_sprite_attr#2 = phi( main::@1/main::vram_sprite_attr#4 )
*((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_X) = *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_X) + $a
*((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) = *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) + $a
main::$6 = SIZEOF_STRUCT_VERA_SPRITE
main::$5 = SIZEOF_STRUCT_VERA_SPRITE
memcpy_to_vram::vbank#2 = (byte)>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)<SPRITE_PIXELS_VRAM/$20|VERA_SPRITE_8BPP, X: (word)$140-$20, Y: (word)$f0-$20, CTRL1: $c, CTRL2: $f0 }
const byte* SPRITE_PIXELS[$40*$40] = kickasm {{ .var pic = LoadPicture("tut.png")
const byte* SPRITE_PIXELS[$40*$40+$200] = kickasm {{ .var pic = LoadPicture("tut.png")
// palette: rgb->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) <SPRITE_PIXELS_VRAM/$20 in
Adding number conversion cast (unumber) $20 in
Adding number conversion cast (unumber) $40*$40 in memcpy_to_vram::num#0 = $40*$40
Adding number conversion cast (unumber) $40*$40 in memcpy_to_vram::src#1 = (void*)SPRITE_PIXELS+$40*$40
Adding number conversion cast (unumber) $200 in memcpy_to_vram::num#1 = $200
Adding number conversion cast (unumber) $20 in main::$5 = main::s#2 < $20
Adding number conversion cast (unumber) $20 in main::$4 = main::s#2 < $20
Adding number conversion cast (unumber) $a in *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_X) = *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_X) + $a
Adding number conversion cast (unumber) $a in *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) = *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) + $a
Adding number conversion cast (unumber) $ffff in irq_vsync::$2 = sin_idx_y == $ffff
@ -417,10 +416,11 @@ Adding number conversion cast (unumber) 1 in sin_idx_y = ((unumber)) SINY_LEN-1
Adding number conversion cast (unumber) $20 in irq_vsync::$4 = irq_vsync::s#2 < $20
Adding number conversion cast (unumber) 2 in memcpy_to_vram::src#3 = (void*)&SPRITE_ATTR+2
Adding number conversion cast (unumber) 4 in memcpy_to_vram::num#3 = 4
Adding number conversion cast (unumber) 9 in irq_vsync::i_x#1 = irq_vsync::i_x#4 + 9
Adding number conversion cast (unumber) 5 in irq_vsync::i_y#1 = irq_vsync::i_y#4 + 5
Adding number conversion cast (unumber) $19 in irq_vsync::i_x#1 = irq_vsync::i_x#4 + $19
Adding number conversion cast (unumber) $13 in irq_vsync::i_y#1 = irq_vsync::i_y#4 + $13
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast memcpy_to_vram::s#0 = (byte*)memcpy_to_vram::src#4
Inlining cast memcpy_to_vram::num#0 = (unumber)$40*$40
Inlining cast memcpy_to_vram::num#1 = (unumber)$200
Inlining cast sin_idx_x = (unumber)0
Inlining cast sin_idx_y = (unumber)SINY_LEN-(unumber)1
@ -449,8 +449,8 @@ Simplifying constant integer cast 1
Simplifying constant integer cast $20
Simplifying constant integer cast 2
Simplifying constant integer cast 4
Simplifying constant integer cast 9
Simplifying constant integer cast 5
Simplifying constant integer cast $19
Simplifying constant integer cast $13
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $20
Finalized unsigned number type (word) $200
@ -464,21 +464,20 @@ Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) $20
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 4
Finalized unsigned number type (byte) 9
Finalized unsigned number type (byte) 5
Finalized unsigned number type (byte) $19
Finalized unsigned number type (byte) $13
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inversing boolean not [57] irq_vsync::$1 = sin_idx_x != SINX_LEN from [56] irq_vsync::$0 = sin_idx_x == SINX_LEN
Inversing boolean not [61] irq_vsync::$3 = sin_idx_y != $ffff from [60] irq_vsync::$2 = sin_idx_y == $ffff
Inversing boolean not [87] irq_vsync::$8 = irq_vsync::i_x#1 < SINX_LEN from [86] irq_vsync::$7 = irq_vsync::i_x#1 >= 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#1<SINX_LEN) goto irq_vsync::@8
Simple Condition irq_vsync::$10 [83] if(irq_vsync::i_y#1<SINY_LEN) goto irq_vsync::@9
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [17] memcpy_to_vram::num#0 = sizeof SPRITE_PIXELS
Constant right-side identified [20] memcpy_to_vram::num#0 = (unumber)$40*$40
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant memcpy_to_vram::num#0 = sizeof SPRITE_PIXELS
Constant memcpy_to_vram::vbank#0 = (byte)>SPRITE_PIXELS_VRAM
Constant memcpy_to_vram::vdest#0 = (void*)<SPRITE_PIXELS_VRAM
Constant memcpy_to_vram::src#0 = (void*)SPRITE_PIXELS
Constant memcpy_to_vram::num#0 = (unumber)$40*$40
Constant memcpy_to_vram::vbank#1 = (byte)>VERA_PALETTE
Constant memcpy_to_vram::vdest#1 = (void*)<VERA_PALETTE
Constant memcpy_to_vram::src#1 = (void*)SPRITE_PIXELS+(word)$40*$40
@ -520,7 +519,7 @@ Constant main::s#0 = 0
Constant memcpy_to_vram::num#2 = SIZEOF_STRUCT_VERA_SPRITE
Constant memcpy_to_vram::vbank#2 = (byte)>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*)<VERA_SPRITE_ATTR+2
Constant irq_vsync::s#0 = 0
Constant memcpy_to_vram::vbank#3 = irq_vsync::vram_sprite_attr_bank
@ -535,20 +534,16 @@ Simplifying constant evaluating to zero (byte)>SPRITE_PIXELS_VRAM in
Successful SSA optimization PassNSimplifyConstantZero
Simplifying constant integer cast <SPRITE_PIXELS_VRAM/$20|VERA_SPRITE_8BPP
Successful SSA optimization PassNCastSimplification
Resolving array sizeof() sizeof SPRITE_PIXELS
Successful SSA optimization PassNSizeOfSimplification
Adding number conversion cast (unumber) $40*$40 in
Successful SSA optimization PassNAddNumberTypeConversions
Inlining Noop Cast [8] memcpy_to_vram::$5 = (byte*)memcpy_to_vram::src#4 keeping memcpy_to_vram::src#4
Inlining Noop Cast [10] memcpy_to_vram::s#0 = (byte*)memcpy_to_vram::src#4 keeping memcpy_to_vram::src#4
Successful SSA optimization Pass2NopCastInlining
Rewriting multiplication to use shift [43] irq_vsync::$11 = irq_vsync::i_x#3 * SIZEOF_WORD
Rewriting multiplication to use shift [46] irq_vsync::$12 = irq_vsync::i_y#3 * SIZEOF_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings memcpy_to_vram::num#0
Inlining constant with var siblings memcpy_to_vram::vbank#0
Inlining constant with var siblings memcpy_to_vram::vdest#0
Inlining constant with var siblings memcpy_to_vram::src#0
Inlining constant with var siblings memcpy_to_vram::num#0
Inlining constant with var siblings memcpy_to_vram::vbank#1
Inlining constant with var siblings memcpy_to_vram::vdest#1
Inlining constant with var siblings memcpy_to_vram::src#1
@ -563,7 +558,7 @@ Inlining constant with var siblings main::vram_sprite_attr#0
Inlining constant with var siblings main::s#0
Inlining constant with var siblings irq_vsync::vram_sprite_pos#0
Inlining constant with var siblings irq_vsync::s#0
Constant inlined memcpy_to_vram::num#0 = (word)$40*$40*SIZEOF_BYTE
Constant inlined memcpy_to_vram::num#0 = (word)$40*$40
Constant inlined main::s#0 = 0
Constant inlined memcpy_to_vram::src#3 = (void*)&SPRITE_ATTR+2
Constant inlined memcpy_to_vram::vdest#0 = (void*)<SPRITE_PIXELS_VRAM
@ -581,19 +576,22 @@ Constant inlined memcpy_to_vram::vbank#2 = (byte)>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#1<SINX_LEN) goto irq_vsync::@8
to:irq_vsync::@10
irq_vsync::@10: scope:[irq_vsync] from irq_vsync::@12
@ -708,7 +706,7 @@ irq_vsync::@10: scope:[irq_vsync] from irq_vsync::@12
to:irq_vsync::@8
irq_vsync::@8: scope:[irq_vsync] from irq_vsync::@10 irq_vsync::@12
[31] irq_vsync::i_x#7 = phi( irq_vsync::@10/irq_vsync::i_x#2, irq_vsync::@12/irq_vsync::i_x#1 )
[32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + 5
[32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + $13
[33] if(irq_vsync::i_y#1<SINY_LEN) goto irq_vsync::@9
to:irq_vsync::@11
irq_vsync::@11: scope:[irq_vsync] from irq_vsync::@8
@ -763,7 +761,7 @@ main::@6: scope:[main] from main::@2
void memcpy_to_vram(byte memcpy_to_vram::vbank , void* memcpy_to_vram::vdest , void* memcpy_to_vram::src , word memcpy_to_vram::num)
memcpy_to_vram: scope:[memcpy_to_vram] from irq_vsync::@6 main main::@2 main::@5
[56] memcpy_to_vram::num#4 = phi( irq_vsync::@6/4, main/(word)$40*$40*SIZEOF_BYTE, main::@2/SIZEOF_STRUCT_VERA_SPRITE, main::@5/$200 )
[56] memcpy_to_vram::num#4 = phi( irq_vsync::@6/4, main/(word)$40*$40, main::@2/SIZEOF_STRUCT_VERA_SPRITE, main::@5/$200 )
[56] memcpy_to_vram::src#4 = phi( irq_vsync::@6/(void*)&SPRITE_ATTR+2, main/(void*)SPRITE_PIXELS, main::@2/(void*)&SPRITE_ATTR, main::@5/(void*)SPRITE_PIXELS+(word)$40*$40 )
[56] memcpy_to_vram::vbank#4 = phi( irq_vsync::@6/irq_vsync::vram_sprite_attr_bank, main/0, main::@2/(byte)>VERA_SPRITE_ATTR, main::@5/(byte)>VERA_PALETTE )
[56] memcpy_to_vram::vdest#4 = phi( irq_vsync::@6/memcpy_to_vram::vdest#3, main/(void*)<SPRITE_PIXELS_VRAM, main::@2/memcpy_to_vram::vdest#2, main::@5/(void*)<VERA_PALETTE )
@ -935,10 +933,10 @@ Statement [23] irq_vsync::$14 = SINY + irq_vsync::$12 [ irq_vsync::s#2 irq_vsync
Statement [24] *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) = *irq_vsync::$14 [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#2 SPRITE_ATTR ] ( [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#2 SPRITE_ATTR ] { { memcpy_to_vram::vdest#3 = memcpy_to_vram::vdest#4 } } ) always clobbers reg byte a reg byte y
Statement [25] memcpy_to_vram::vdest#3 = (void*)irq_vsync::vram_sprite_pos#2 [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#2 SPRITE_ATTR memcpy_to_vram::vdest#3 ] ( [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#2 SPRITE_ATTR memcpy_to_vram::vdest#3 ] { { memcpy_to_vram::vdest#3 = memcpy_to_vram::vdest#4 } } ) always clobbers reg byte a
Statement [27] irq_vsync::vram_sprite_pos#1 = irq_vsync::vram_sprite_pos#2 + SIZEOF_STRUCT_VERA_SPRITE [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR ] ( [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR ] { } ) always clobbers reg byte a
Statement [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + 9 [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] ( [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] { } ) always clobbers reg byte a
Statement [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + $19 [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] ( [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] { } ) always clobbers reg byte a
Statement [29] if(irq_vsync::i_x#1<SINX_LEN) goto irq_vsync::@8 [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] ( [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] { } ) always clobbers reg byte a
Statement [30] irq_vsync::i_x#2 = irq_vsync::i_x#1 - SINX_LEN [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#2 ] ( [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#2 ] { } ) always clobbers reg byte a
Statement [32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + 5 [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] ( [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] { } ) always clobbers reg byte a
Statement [32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + $13 [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] ( [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] { } ) always clobbers reg byte a
Statement [33] if(irq_vsync::i_y#1<SINY_LEN) goto irq_vsync::@9 [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] ( [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] { } ) always clobbers reg byte a
Statement [34] irq_vsync::i_y#2 = irq_vsync::i_y#1 - SINY_LEN [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#2 ] ( [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#2 ] { } ) always clobbers reg byte a
Statement [43] *VERA_CTRL = *VERA_CTRL & ~VERA_DCSEL [ ] ( main:4 [ ] { } ) always clobbers reg byte a
@ -976,10 +974,10 @@ Statement [23] irq_vsync::$14 = SINY + irq_vsync::$12 [ irq_vsync::s#2 irq_vsync
Statement [24] *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) = *irq_vsync::$14 [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#2 SPRITE_ATTR ] ( [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#2 SPRITE_ATTR ] { { memcpy_to_vram::vdest#3 = memcpy_to_vram::vdest#4 } } ) always clobbers reg byte a reg byte y
Statement [25] memcpy_to_vram::vdest#3 = (void*)irq_vsync::vram_sprite_pos#2 [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#2 SPRITE_ATTR memcpy_to_vram::vdest#3 ] ( [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#2 SPRITE_ATTR memcpy_to_vram::vdest#3 ] { { memcpy_to_vram::vdest#3 = memcpy_to_vram::vdest#4 } } ) always clobbers reg byte a
Statement [27] irq_vsync::vram_sprite_pos#1 = irq_vsync::vram_sprite_pos#2 + SIZEOF_STRUCT_VERA_SPRITE [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR ] ( [ irq_vsync::s#2 irq_vsync::i_x#3 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR ] { } ) always clobbers reg byte a
Statement [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + 9 [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] ( [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] { } ) always clobbers reg byte a
Statement [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + $19 [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] ( [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] { } ) always clobbers reg byte a
Statement [29] if(irq_vsync::i_x#1<SINX_LEN) goto irq_vsync::@8 [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] ( [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#1 ] { } ) always clobbers reg byte a
Statement [30] irq_vsync::i_x#2 = irq_vsync::i_x#1 - SINX_LEN [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#2 ] ( [ irq_vsync::s#2 irq_vsync::i_y#3 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_x#2 ] { } ) always clobbers reg byte a
Statement [32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + 5 [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] ( [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] { } ) always clobbers reg byte a
Statement [32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + $13 [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] ( [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] { } ) always clobbers reg byte a
Statement [33] if(irq_vsync::i_y#1<SINY_LEN) goto irq_vsync::@9 [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] ( [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#1 ] { } ) always clobbers reg byte a
Statement [34] irq_vsync::i_y#2 = irq_vsync::i_y#1 - SINY_LEN [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#2 ] ( [ irq_vsync::s#2 irq_vsync::i_x#7 irq_vsync::vram_sprite_pos#1 SPRITE_ATTR irq_vsync::i_y#2 ] { } ) always clobbers reg byte a
Statement [43] *VERA_CTRL = *VERA_CTRL & ~VERA_DCSEL [ ] ( main:4 [ ] { } ) always clobbers reg byte a
@ -1093,7 +1091,6 @@ ASSEMBLER BEFORE OPTIMIZATION
.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)
@ -1355,8 +1352,8 @@ irq_vsync: {
bcc !+
inc.z vram_sprite_pos+1
!:
// [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + 9 -- vwuz1=vwuz1_plus_vbuc1
lda #9
// [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
@ -1388,8 +1385,8 @@ irq_vsync: {
jmp __b8
// irq_vsync::@8
__b8:
// [32] irq_vsync::i_y#1 = irq_vsync::i_y#3 + 5 -- vwuz1=vwuz1_plus_vbuc1
lda #5
// [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
@ -1440,10 +1437,10 @@ main: {
// Copy sprite data to VRAM
// [56] phi from main to memcpy_to_vram [phi:main->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 #<SPRITE_PIXELS
@ -1676,7 +1673,7 @@ memcpy_to_vram: {
// File Data
.segment Data
// A 64*64 8bpp TUT sprite
.align $1200
.align $1000
SPRITE_PIXELS:
.var pic = LoadPicture("tut.png")
// palette: rgb->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: <SPRITE_PIXELS_VRAM/$20|VERA_SPRITE_8BPP, X: $140-$20, Y: (word)$f0-$20, CTRL1: $c, CTRL2: $f0 }
const byte* SPRITE_PIXELS[$40*$40] = kickasm {{ .var pic = LoadPicture("tut.png")
const byte* SPRITE_PIXELS[$40*$40+$200] = kickasm {{ .var pic = LoadPicture("tut.png")
// palette: rgb->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, SPRITE_PIXELS, sizeof(SPRITE_PIXELS))
// memcpy_to_vram((char)>SPRITE_PIXELS_VRAM, <SPRITE_PIXELS_VRAM, SPRITE_PIXELS, 64*64)
// [38] call memcpy_to_vram
// Copy sprite data to VRAM
// [56] phi from main to memcpy_to_vram [phi:main->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 #<SPRITE_PIXELS
@ -2548,7 +2543,7 @@ memcpy_to_vram: {
// File Data
.segment Data
// A 64*64 8bpp TUT sprite
.align $1200
.align $1000
SPRITE_PIXELS:
.var pic = LoadPicture("tut.png")
// palette: rgb->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
}

View File

@ -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: <SPRITE_PIXELS_VRAM/$20|VERA_SPRITE_8BPP, X: $140-$20, Y: (word)$f0-$20, CTRL1: $c, CTRL2: $f0 }
const byte* SPRITE_PIXELS[$40*$40] = kickasm {{ .var pic = LoadPicture("tut.png")
const byte* SPRITE_PIXELS[$40*$40+$200] = kickasm {{ .var pic = LoadPicture("tut.png")
// palette: rgb->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
}