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:23:46 +01:00
parent 559d4f65c7
commit e6962d38ac
9 changed files with 908 additions and 612 deletions

View File

@ -165,7 +165,14 @@ char * const VERA_SPI_DATA = 0x9f3e;
// Bit 0: Select // Bit 0: Select
char * const VERA_SPI_CTRL = 0x9f3f; char * const VERA_SPI_CTRL = 0x9f3f;
// Sprite Attributes address in VERA VRAM // VERA Palette address in VRAM $1FA00 - $1FBFF
// 256 entries of 2 bytes
// byte 0 bits 4-7: Green
// byte 0 bits 0-3: Blue
// byte 1 bits 0-3: Red
const unsigned long VERA_PALETTE = 0x1fa00;
// Sprite Attributes address in VERA VRAM $1FC00 - $1FFFF
const unsigned long VERA_SPRITE_ATTR = 0x1fc00; const unsigned long VERA_SPRITE_ATTR = 0x1fc00;
// The VERA structure of a sprite (8 bytes) // The VERA structure of a sprite (8 bytes)

View File

@ -464,8 +464,8 @@ public class TestPrograms {
} }
@Test @Test
public void testCx16Sprite() throws IOException, URISyntaxException { public void testCx16Sprites() throws IOException, URISyntaxException {
compileAndCompare("examples/cx16/sprite.c"); compileAndCompare("examples/cx16/sprites.c");
} }
@Test @Test

Binary file not shown.

Before

Width:  |  Height:  |  Size: 650 B

View File

@ -1,19 +1,47 @@
// Example program for the Commander X16 // Example program for the Commander X16
// Displays some sprites - exceeding the per-line limits of the CX16 // Displays 32 64*64 TUT sprites
#pragma target(cx16) #pragma target(cx16)
#include <cx16.h> #include <cx16.h>
#include <6502.h> #include <6502.h>
// A 64*64 8bpp sprite #define NUM_SPRITES 32
align(0x100) char SPRITE_PIXELS[64*64] = kickasm(resource "sprite.png") {{
.var pic = LoadPicture("sprite.png", List().add($000000, $ffffff))
.for (var x=0;x<64; x++)
.for (var y=0; y<64; y++)
.byte (pic.getPixel(x,y)==0) ? 0 : 1
}};
#define NUM_SPRITES 128 // A 64*64 8bpp TUT sprite
align(0x1200) char SPRITE_PIXELS[64*64] = kickasm(resource "tut.png") {{
.var pic = LoadPicture("tut.png")
// palette: rgb->idx
.var palette = Hashtable()
// RGB value for each palette index
.var palList = List()
// Next palette index
.var nxt_idx = 0;
.for (var y=0; y<64; y++) {
.for (var x=0;x<64; x++) {
.var rgb = pic.getPixel(x,y);
.var idx = palette.get(rgb)
.if(idx==null) {
.eval idx = nxt_idx++;
.eval palette.put(rgb,idx);
.eval palList.add(rgb)
}
// Output pixel index
.byte idx
}
}
// 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
// bits bits 0-3 red
.byte red/16
}
}};
// Address to use for sprite pixels in VRAM // Address to use for sprite pixels in VRAM
const unsigned long SPRITE_PIXELS_VRAM = 0x08000; const unsigned long SPRITE_PIXELS_VRAM = 0x08000;
@ -24,6 +52,8 @@ struct VERA_SPRITE SPRITE_ATTR = { <(SPRITE_PIXELS_VRAM/32)|VERA_SPRITE_8BPP, 32
void main() { void main() {
// Copy sprite data to VRAM // 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, sizeof(SPRITE_PIXELS));
// Copy sprite palette to VRAM
memcpy_to_vram((char)>VERA_PALETTE, <VERA_PALETTE, SPRITE_PIXELS+64*64, 0x200);
// Copy 8* sprite attributes to VRAM // Copy 8* sprite attributes to VRAM
char* vram_sprite_attr = <VERA_SPRITE_ATTR; char* vram_sprite_attr = <VERA_SPRITE_ATTR;
for(char s=0;s<NUM_SPRITES;s++) { for(char s=0;s<NUM_SPRITES;s++) {
@ -32,12 +62,6 @@ void main() {
memcpy_to_vram((char)>VERA_SPRITE_ATTR, vram_sprite_attr, &SPRITE_ATTR, sizeof(SPRITE_ATTR)); memcpy_to_vram((char)>VERA_SPRITE_ATTR, vram_sprite_attr, &SPRITE_ATTR, sizeof(SPRITE_ATTR));
vram_sprite_attr += sizeof(SPRITE_ATTR); vram_sprite_attr += sizeof(SPRITE_ATTR);
} }
// Make a border
//*VERA_CTRL |= VERA_DCSEL;
//*VERA_DC_HSTART = 16/4;
//*VERA_DC_HSTOP = 624/4;
//*VERA_DC_VSTART = 16/2;
//*VERA_DC_VSTOP = 464/2;
// Enable sprites // Enable sprites
*VERA_CTRL &= ~VERA_DCSEL; *VERA_CTRL &= ~VERA_DCSEL;
*VERA_DC_VIDEO |= VERA_SPRITES_ENABLE; *VERA_DC_VIDEO |= VERA_SPRITES_ENABLE;
@ -49,13 +73,15 @@ void main() {
} }
// X sine [0;640-64] // X sine [0;640-64]
align(0x100) unsigned int SINX[241] = kickasm {{ const char SINX_LEN = 241;
.fillword 256, 288+288*sin(i*2*PI/241) align(0x100) unsigned int SINX[SINX_LEN] = kickasm {{
.fillword 256, 288+288*sin(i*2*PI/SINX_LEN)
}}; }};
// Y sine [0;480-64] // Y sine [0;480-64]
align(0x100) unsigned int SINY[251] = kickasm {{ const char SINY_LEN = 251;
.fillword 256, 208+208*sin(i*2*PI/251) align(0x100) unsigned int SINY[SINY_LEN] = kickasm {{
.fillword 256, 208+208*sin(i*2*PI/SINY_LEN)
}}; }};
// X sine index // X sine index
@ -65,12 +91,9 @@ volatile unsigned int sin_idx_y = 79;
// VSYNC Interrupt Routine // VSYNC Interrupt Routine
void irq_vsync() { void irq_vsync() {
// Color border
//*VERA_CTRL &= ~VERA_DCSEL;
//*VERA_DC_BORDER = 2;
// Move the sprite around // Move the sprite around
if(++sin_idx_x==241) sin_idx_x = 0; if(++sin_idx_x==SINX_LEN) sin_idx_x = 0;
if(--sin_idx_y==0xffff) sin_idx_y = 251-1; if(--sin_idx_y==0xffff) sin_idx_y = SINY_LEN-1;
const char vram_sprite_attr_bank = (char)>VERA_SPRITE_ATTR; const char vram_sprite_attr_bank = (char)>VERA_SPRITE_ATTR;
char *vram_sprite_pos = <VERA_SPRITE_ATTR+2; char *vram_sprite_pos = <VERA_SPRITE_ATTR+2;
unsigned int i_x = sin_idx_x; unsigned int i_x = sin_idx_x;
@ -81,12 +104,10 @@ void irq_vsync() {
// Copy sprite positions to VRAM (the 4 relevant bytes in VERA_SPRITE_ATTR) // 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); memcpy_to_vram(vram_sprite_attr_bank, vram_sprite_pos, &SPRITE_ATTR+2, 4);
vram_sprite_pos += sizeof(SPRITE_ATTR); vram_sprite_pos += sizeof(SPRITE_ATTR);
i_x += 3; if(i_x>=241) i_x -= 241; i_x += 9; if(i_x>=SINX_LEN) i_x -= SINX_LEN;
i_y += 5; if(i_y>=251) i_y -= 251; i_y += 5; if(i_y>=SINY_LEN) i_y -= SINY_LEN;
} }
// Black border
//*VERA_CTRL &= ~VERA_DCSEL;
//*VERA_DC_BORDER = 0;
// Reset the VSYNC interrupt // Reset the VSYNC interrupt
*VERA_ISR = VERA_VSYNC; *VERA_ISR = VERA_VSYNC;
// Exit CX16 KERNAL IRQ // Exit CX16 KERNAL IRQ

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1,8 +1,8 @@
// Example program for the Commander X16 // Example program for the Commander X16
// Displays some sprites - exceeding the per-line limits of the CX16 // Displays 32 64*64 TUT sprites
.cpu _65c02 .cpu _65c02
// Commodore 64 PRG executable file // Commodore 64 PRG executable file
.file [name="sprite.prg", type="prg", segments="Program"] .file [name="sprites.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"] .segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801] .segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d] .segmentdef Code [start=$80d]
@ -16,12 +16,22 @@
.const VERA_DCSEL = 2 .const VERA_DCSEL = 2
.const VERA_ADDRSEL = 1 .const VERA_ADDRSEL = 1
.const VERA_VSYNC = 1 .const VERA_VSYNC = 1
// Sprite Attributes address in VERA VRAM // VERA Palette address in VRAM $1FA00 - $1FBFF
// 256 entries of 2 bytes
// byte 0 bits 4-7: Green
// byte 0 bits 0-3: Blue
// byte 1 bits 0-3: Red
.const VERA_PALETTE = $1fa00
// Sprite Attributes address in VERA VRAM $1FC00 - $1FFFF
.const VERA_SPRITE_ATTR = $1fc00 .const VERA_SPRITE_ATTR = $1fc00
// 8BPP sprite mode (add to VERA_SPRITE.ADDR to enable) // 8BPP sprite mode (add to VERA_SPRITE.ADDR to enable)
.const VERA_SPRITE_8BPP = $8000 .const VERA_SPRITE_8BPP = $8000
// Address to use for sprite pixels in VRAM // Address to use for sprite pixels in VRAM
.const SPRITE_PIXELS_VRAM = $8000 .const SPRITE_PIXELS_VRAM = $8000
// X sine [0;640-64]
.const SINX_LEN = $f1
// Y sine [0;480-64]
.const SINY_LEN = $fb
.const SIZEOF_STRUCT_VERA_SPRITE = 8 .const SIZEOF_STRUCT_VERA_SPRITE = 8
.const OFFSET_STRUCT_VERA_SPRITE_X = 2 .const OFFSET_STRUCT_VERA_SPRITE_X = 2
.const OFFSET_STRUCT_VERA_SPRITE_Y = 4 .const OFFSET_STRUCT_VERA_SPRITE_Y = 4
@ -100,16 +110,16 @@ irq_vsync: {
.label s = 2 .label s = 2
.label __13 = $16 .label __13 = $16
.label __14 = $18 .label __14 = $18
// if(++sin_idx_x==241) // if(++sin_idx_x==SINX_LEN)
inc.z sin_idx_x inc.z sin_idx_x
bne !+ bne !+
inc.z sin_idx_x+1 inc.z sin_idx_x+1
!: !:
lda.z sin_idx_x+1 lda.z sin_idx_x+1
cmp #>$f1 cmp #>SINX_LEN
bne __b1 bne __b1
lda.z sin_idx_x lda.z sin_idx_x
cmp #<$f1 cmp #<SINX_LEN
bne __b1 bne __b1
// sin_idx_x = 0 // sin_idx_x = 0
lda #<0 lda #<0
@ -128,10 +138,10 @@ irq_vsync: {
lda.z sin_idx_y lda.z sin_idx_y
cmp #<$ffff cmp #<$ffff
bne __b2 bne __b2
// sin_idx_y = 251-1 // sin_idx_y = SINY_LEN-1
lda #<$fb-1 lda #<SINY_LEN-1
sta.z sin_idx_y sta.z sin_idx_y
lda #>$fb-1 lda #>SINY_LEN-1
sta.z sin_idx_y+1 sta.z sin_idx_y+1
__b2: __b2:
// i_x = sin_idx_x // i_x = sin_idx_x
@ -153,12 +163,9 @@ irq_vsync: {
__b5: __b5:
// for(char s=0;s<NUM_SPRITES;s++) // for(char s=0;s<NUM_SPRITES;s++)
lda.z s lda.z s
cmp #$80 cmp #$20
bcc __b6 bcc __b6
// *VERA_ISR = VERA_VSYNC // *VERA_ISR = VERA_VSYNC
// Black border
//*VERA_CTRL &= ~VERA_DCSEL;
//*VERA_DC_BORDER = 0;
// Reset the VSYNC interrupt // Reset the VSYNC interrupt
lda #VERA_VSYNC lda #VERA_VSYNC
sta VERA_ISR sta VERA_ISR
@ -231,25 +238,25 @@ irq_vsync: {
bcc !+ bcc !+
inc.z vram_sprite_pos+1 inc.z vram_sprite_pos+1
!: !:
// i_x += 3 // i_x += 9
lda #3 lda #9
clc clc
adc.z i_x adc.z i_x
sta.z i_x sta.z i_x
bcc !+ bcc !+
inc.z i_x+1 inc.z i_x+1
!: !:
// if(i_x>=241) // if(i_x>=SINX_LEN)
lda.z i_x+1 lda.z i_x+1
bne !+ bne !+
lda.z i_x lda.z i_x
cmp #$f1 cmp #SINX_LEN
bcc __b8 bcc __b8
!: !:
// i_x -= 241 // i_x -= SINX_LEN
sec sec
lda.z i_x lda.z i_x
sbc #$f1 sbc #SINX_LEN
sta.z i_x sta.z i_x
lda.z i_x+1 lda.z i_x+1
sbc #0 sbc #0
@ -263,17 +270,17 @@ irq_vsync: {
bcc !+ bcc !+
inc.z i_y+1 inc.z i_y+1
!: !:
// if(i_y>=251) // if(i_y>=SINY_LEN)
lda.z i_y+1 lda.z i_y+1
bne !+ bne !+
lda.z i_y lda.z i_y
cmp #$fb cmp #SINY_LEN
bcc __b9 bcc __b9
!: !:
// i_y -= 251 // i_y -= SINY_LEN
sec sec
lda.z i_y lda.z i_y
sbc #$fb sbc #SINY_LEN
sta.z i_y sta.z i_y
lda.z i_y+1 lda.z i_y+1
sbc #0 sbc #0
@ -303,6 +310,22 @@ main: {
lda #>SPRITE_PIXELS_VRAM&$ffff lda #>SPRITE_PIXELS_VRAM&$ffff
sta.z memcpy_to_vram.vdest+1 sta.z memcpy_to_vram.vdest+1
jsr memcpy_to_vram jsr memcpy_to_vram
// memcpy_to_vram((char)>VERA_PALETTE, <VERA_PALETTE, SPRITE_PIXELS+64*64, 0x200)
// Copy sprite palette to VRAM
lda #<$200
sta.z memcpy_to_vram.num
lda #>$200
sta.z memcpy_to_vram.num+1
lda #<SPRITE_PIXELS+$40*$40
sta.z memcpy_to_vram.src
lda #>SPRITE_PIXELS+$40*$40
sta.z memcpy_to_vram.src+1
ldx #VERA_PALETTE>>$10
lda #<VERA_PALETTE&$ffff
sta.z memcpy_to_vram.vdest
lda #>VERA_PALETTE&$ffff
sta.z memcpy_to_vram.vdest+1
jsr memcpy_to_vram
lda #<VERA_SPRITE_ATTR&$ffff lda #<VERA_SPRITE_ATTR&$ffff
sta.z vram_sprite_attr sta.z vram_sprite_attr
lda #>VERA_SPRITE_ATTR&$ffff lda #>VERA_SPRITE_ATTR&$ffff
@ -312,15 +335,9 @@ main: {
__b1: __b1:
// for(char s=0;s<NUM_SPRITES;s++) // for(char s=0;s<NUM_SPRITES;s++)
lda.z s lda.z s
cmp #$80 cmp #$20
bcc __b2 bcc __b2
// *VERA_CTRL &= ~VERA_DCSEL // *VERA_CTRL &= ~VERA_DCSEL
// Make a border
//*VERA_CTRL |= VERA_DCSEL;
//*VERA_DC_HSTART = 16/4;
//*VERA_DC_HSTOP = 624/4;
//*VERA_DC_VSTART = 16/2;
//*VERA_DC_VSTOP = 464/2;
// Enable sprites // Enable sprites
lda #VERA_DCSEL^$ff lda #VERA_DCSEL^$ff
and VERA_CTRL and VERA_CTRL
@ -450,23 +467,49 @@ memcpy_to_vram: {
jmp __b1 jmp __b1
} }
.segment Data .segment Data
// A 64*64 8bpp sprite // A 64*64 8bpp TUT sprite
.align $100 .align $1200
SPRITE_PIXELS: SPRITE_PIXELS:
.var pic = LoadPicture("sprite.png", List().add($000000, $ffffff)) .var pic = LoadPicture("tut.png")
.for (var x=0;x<64; x++) // palette: rgb->idx
.for (var y=0; y<64; y++) .var palette = Hashtable()
.byte (pic.getPixel(x,y)==0) ? 0 : 1 // RGB value for each palette index
.var palList = List()
// Next palette index
.var nxt_idx = 0;
.for (var y=0; y<64; y++) {
.for (var x=0;x<64; x++) {
.var rgb = pic.getPixel(x,y);
.var idx = palette.get(rgb)
.if(idx==null) {
.eval idx = nxt_idx++;
.eval palette.put(rgb,idx);
.eval palList.add(rgb)
}
// Output pixel index
.byte idx
}
}
// 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
// bits bits 0-3 red
.byte red/16
}
// X sine [0;640-64]
.align $100 .align $100
SINX: SINX:
.fillword 256, 288+288*sin(i*2*PI/241) .fillword 256, 288+288*sin(i*2*PI/SINX_LEN)
// Y sine [0;480-64]
.align $100 .align $100
SINY: SINY:
.fillword 256, 208+208*sin(i*2*PI/251) .fillword 256, 208+208*sin(i*2*PI/SINY_LEN)
// Sprite attributes: 8bpp, in front, 64x64, address SPRITE_PIXELS_VRAM // Sprite attributes: 8bpp, in front, 64x64, address SPRITE_PIXELS_VRAM
SPRITE_ATTR: .word (SPRITE_PIXELS_VRAM/$20&$ffff)|VERA_SPRITE_8BPP, $140-$20, $f0-$20 SPRITE_ATTR: .word (SPRITE_PIXELS_VRAM/$20&$ffff)|VERA_SPRITE_8BPP, $140-$20, $f0-$20

View File

@ -18,7 +18,7 @@ __start::@return: scope:[__start] from __start::@1
void irq_vsync() void irq_vsync()
irq_vsync: scope:[irq_vsync] from irq_vsync: scope:[irq_vsync] from
[6] sin_idx_x = ++ sin_idx_x [6] sin_idx_x = ++ sin_idx_x
[7] if(sin_idx_x!=$f1) goto irq_vsync::@1 [7] if(sin_idx_x!=SINX_LEN) goto irq_vsync::@1
to:irq_vsync::@3 to:irq_vsync::@3
irq_vsync::@3: scope:[irq_vsync] from irq_vsync irq_vsync::@3: scope:[irq_vsync] from irq_vsync
[8] sin_idx_x = 0 [8] sin_idx_x = 0
@ -28,7 +28,7 @@ irq_vsync::@1: scope:[irq_vsync] from irq_vsync irq_vsync::@3
[10] if(sin_idx_y!=$ffff) goto irq_vsync::@2 [10] if(sin_idx_y!=$ffff) goto irq_vsync::@2
to:irq_vsync::@4 to:irq_vsync::@4
irq_vsync::@4: scope:[irq_vsync] from irq_vsync::@1 irq_vsync::@4: scope:[irq_vsync] from irq_vsync::@1
[11] sin_idx_y = $fb-1 [11] sin_idx_y = SINY_LEN-1
to:irq_vsync::@2 to:irq_vsync::@2
irq_vsync::@2: scope:[irq_vsync] from irq_vsync::@1 irq_vsync::@4 irq_vsync::@2: scope:[irq_vsync] from irq_vsync::@1 irq_vsync::@4
[12] irq_vsync::i_x#0 = sin_idx_x [12] irq_vsync::i_x#0 = sin_idx_x
@ -39,7 +39,7 @@ irq_vsync::@5: scope:[irq_vsync] from irq_vsync::@2 irq_vsync::@9
[14] irq_vsync::i_y#3 = phi( irq_vsync::@2/irq_vsync::i_y#0, irq_vsync::@9/irq_vsync::i_y#9 ) [14] irq_vsync::i_y#3 = phi( irq_vsync::@2/irq_vsync::i_y#0, irq_vsync::@9/irq_vsync::i_y#9 )
[14] irq_vsync::i_x#3 = phi( irq_vsync::@2/irq_vsync::i_x#0, irq_vsync::@9/irq_vsync::i_x#7 ) [14] irq_vsync::i_x#3 = phi( irq_vsync::@2/irq_vsync::i_x#0, irq_vsync::@9/irq_vsync::i_x#7 )
[14] irq_vsync::s#2 = phi( irq_vsync::@2/0, irq_vsync::@9/irq_vsync::s#1 ) [14] irq_vsync::s#2 = phi( irq_vsync::@2/0, irq_vsync::@9/irq_vsync::s#1 )
[15] if(irq_vsync::s#2<$80) goto irq_vsync::@6 [15] if(irq_vsync::s#2<$20) goto irq_vsync::@6
to:irq_vsync::@7 to:irq_vsync::@7
irq_vsync::@7: scope:[irq_vsync] from irq_vsync::@5 irq_vsync::@7: scope:[irq_vsync] from irq_vsync::@5
[16] *VERA_ISR = VERA_VSYNC [16] *VERA_ISR = VERA_VSYNC
@ -55,24 +55,24 @@ irq_vsync::@6: scope:[irq_vsync] from irq_vsync::@5
[22] irq_vsync::$12 = irq_vsync::i_y#3 << 1 [22] irq_vsync::$12 = irq_vsync::i_y#3 << 1
[23] irq_vsync::$14 = SINY + irq_vsync::$12 [23] irq_vsync::$14 = SINY + irq_vsync::$12
[24] *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) = *irq_vsync::$14 [24] *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) = *irq_vsync::$14
[25] memcpy_to_vram::vdest#2 = (void*)irq_vsync::vram_sprite_pos#2 [25] memcpy_to_vram::vdest#3 = (void*)irq_vsync::vram_sprite_pos#2
[26] call memcpy_to_vram [26] call memcpy_to_vram
to:irq_vsync::@12 to:irq_vsync::@12
irq_vsync::@12: scope:[irq_vsync] from irq_vsync::@6 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 [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 + 3 [28] irq_vsync::i_x#1 = irq_vsync::i_x#3 + 9
[29] if(irq_vsync::i_x#1<$f1) goto irq_vsync::@8 [29] if(irq_vsync::i_x#1<SINX_LEN) goto irq_vsync::@8
to:irq_vsync::@10 to:irq_vsync::@10
irq_vsync::@10: scope:[irq_vsync] from irq_vsync::@12 irq_vsync::@10: scope:[irq_vsync] from irq_vsync::@12
[30] irq_vsync::i_x#2 = irq_vsync::i_x#1 - $f1 [30] irq_vsync::i_x#2 = irq_vsync::i_x#1 - SINX_LEN
to:irq_vsync::@8 to:irq_vsync::@8
irq_vsync::@8: scope:[irq_vsync] from irq_vsync::@10 irq_vsync::@12 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 ) [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 + 5
[33] if(irq_vsync::i_y#1<$fb) goto irq_vsync::@9 [33] if(irq_vsync::i_y#1<SINY_LEN) goto irq_vsync::@9
to:irq_vsync::@11 to:irq_vsync::@11
irq_vsync::@11: scope:[irq_vsync] from irq_vsync::@8 irq_vsync::@11: scope:[irq_vsync] from irq_vsync::@8
[34] irq_vsync::i_y#2 = irq_vsync::i_y#1 - $fb [34] irq_vsync::i_y#2 = irq_vsync::i_y#1 - SINY_LEN
to:irq_vsync::@9 to:irq_vsync::@9
irq_vsync::@9: scope:[irq_vsync] from irq_vsync::@11 irq_vsync::@8 irq_vsync::@9: scope:[irq_vsync] from irq_vsync::@11 irq_vsync::@8
[35] irq_vsync::i_y#9 = phi( irq_vsync::@11/irq_vsync::i_y#2, irq_vsync::@8/irq_vsync::i_y#1 ) [35] irq_vsync::i_y#9 = phi( irq_vsync::@11/irq_vsync::i_y#2, irq_vsync::@8/irq_vsync::i_y#1 )
@ -83,64 +83,68 @@ void main()
main: scope:[main] from __start::@1 main: scope:[main] from __start::@1
[37] phi() [37] phi()
[38] call memcpy_to_vram [38] call memcpy_to_vram
to:main::@5
main::@5: scope:[main] from main
[39] phi()
[40] call memcpy_to_vram
to:main::@1 to:main::@1
main::@1: scope:[main] from main main::@5 main::@1: scope:[main] from main::@5 main::@6
[39] main::vram_sprite_attr#2 = phi( main/(byte*)<VERA_SPRITE_ATTR, main::@5/main::vram_sprite_attr#1 ) [41] main::vram_sprite_attr#2 = phi( main::@5/(byte*)<VERA_SPRITE_ATTR, main::@6/main::vram_sprite_attr#1 )
[39] main::s#2 = phi( main/0, main::@5/main::s#1 ) [41] main::s#2 = phi( main::@5/0, main::@6/main::s#1 )
[40] if(main::s#2<$80) goto main::@2 [42] if(main::s#2<$20) goto main::@2
to:main::@3 to:main::@3
main::@3: scope:[main] from main::@1 main::@3: scope:[main] from main::@1
[41] *VERA_CTRL = *VERA_CTRL & ~VERA_DCSEL [43] *VERA_CTRL = *VERA_CTRL & ~VERA_DCSEL
[42] *VERA_DC_VIDEO = *VERA_DC_VIDEO | VERA_SPRITES_ENABLE [44] *VERA_DC_VIDEO = *VERA_DC_VIDEO | VERA_SPRITES_ENABLE
to:main::SEI1 to:main::SEI1
main::SEI1: scope:[main] from main::@3 main::SEI1: scope:[main] from main::@3
asm { sei } asm { sei }
to:main::@4 to:main::@4
main::@4: scope:[main] from main::SEI1 main::@4: scope:[main] from main::SEI1
[44] *KERNEL_IRQ = &irq_vsync [46] *KERNEL_IRQ = &irq_vsync
[45] *VERA_IEN = VERA_VSYNC [47] *VERA_IEN = VERA_VSYNC
to:main::CLI1 to:main::CLI1
main::CLI1: scope:[main] from main::@4 main::CLI1: scope:[main] from main::@4
asm { cli } asm { cli }
to:main::@return to:main::@return
main::@return: scope:[main] from main::CLI1 main::@return: scope:[main] from main::CLI1
[47] return [49] return
to:@return to:@return
main::@2: scope:[main] from main::@1 main::@2: scope:[main] from main::@1
[48] *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_X) = *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_X) + $a [50] *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_X) = *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_X) + $a
[49] *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) = *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) + $a [51] *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) = *((word*)&SPRITE_ATTR+OFFSET_STRUCT_VERA_SPRITE_Y) + $a
[50] memcpy_to_vram::vdest#1 = (void*)main::vram_sprite_attr#2 [52] memcpy_to_vram::vdest#2 = (void*)main::vram_sprite_attr#2
[51] call memcpy_to_vram [53] call memcpy_to_vram
to:main::@5 to:main::@6
main::@5: scope:[main] from main::@2 main::@6: scope:[main] from main::@2
[52] main::vram_sprite_attr#1 = main::vram_sprite_attr#2 + SIZEOF_STRUCT_VERA_SPRITE [54] main::vram_sprite_attr#1 = main::vram_sprite_attr#2 + SIZEOF_STRUCT_VERA_SPRITE
[53] main::s#1 = ++ main::s#2 [55] main::s#1 = ++ main::s#2
to:main::@1 to:main::@1
void memcpy_to_vram(byte memcpy_to_vram::vbank , void* memcpy_to_vram::vdest , void* memcpy_to_vram::src , word memcpy_to_vram::num) 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 memcpy_to_vram: scope:[memcpy_to_vram] from irq_vsync::@6 main main::@2 main::@5
[54] memcpy_to_vram::num#3 = phi( irq_vsync::@6/4, main/(word)$40*$40*SIZEOF_BYTE, main::@2/SIZEOF_STRUCT_VERA_SPRITE ) [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 )
[54] memcpy_to_vram::src#3 = phi( irq_vsync::@6/(void*)&SPRITE_ATTR+2, main/(void*)SPRITE_PIXELS, main::@2/(void*)&SPRITE_ATTR ) [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 )
[54] memcpy_to_vram::vbank#3 = phi( irq_vsync::@6/irq_vsync::vram_sprite_attr_bank, main/0, main::@2/(byte)>VERA_SPRITE_ATTR ) [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 )
[54] memcpy_to_vram::vdest#3 = phi( irq_vsync::@6/memcpy_to_vram::vdest#2, main/(void*)<SPRITE_PIXELS_VRAM, main::@2/memcpy_to_vram::vdest#1 ) [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 )
[55] *VERA_CTRL = *VERA_CTRL & ~VERA_ADDRSEL [57] *VERA_CTRL = *VERA_CTRL & ~VERA_ADDRSEL
[56] memcpy_to_vram::$0 = < memcpy_to_vram::vdest#3 [58] memcpy_to_vram::$0 = < memcpy_to_vram::vdest#4
[57] *VERA_ADDRX_L = memcpy_to_vram::$0 [59] *VERA_ADDRX_L = memcpy_to_vram::$0
[58] memcpy_to_vram::$1 = > memcpy_to_vram::vdest#3 [60] memcpy_to_vram::$1 = > memcpy_to_vram::vdest#4
[59] *VERA_ADDRX_M = memcpy_to_vram::$1 [61] *VERA_ADDRX_M = memcpy_to_vram::$1
[60] memcpy_to_vram::$2 = VERA_INC_1 | memcpy_to_vram::vbank#3 [62] memcpy_to_vram::$2 = VERA_INC_1 | memcpy_to_vram::vbank#4
[61] *VERA_ADDRX_H = memcpy_to_vram::$2 [63] *VERA_ADDRX_H = memcpy_to_vram::$2
[62] memcpy_to_vram::end#0 = (byte*)memcpy_to_vram::src#3 + memcpy_to_vram::num#3 [64] memcpy_to_vram::end#0 = (byte*)memcpy_to_vram::src#4 + memcpy_to_vram::num#4
[63] memcpy_to_vram::s#4 = (byte*)memcpy_to_vram::src#3 [65] memcpy_to_vram::s#4 = (byte*)memcpy_to_vram::src#4
to:memcpy_to_vram::@1 to:memcpy_to_vram::@1
memcpy_to_vram::@1: scope:[memcpy_to_vram] from memcpy_to_vram memcpy_to_vram::@2 memcpy_to_vram::@1: scope:[memcpy_to_vram] from memcpy_to_vram memcpy_to_vram::@2
[64] memcpy_to_vram::s#2 = phi( memcpy_to_vram/memcpy_to_vram::s#4, memcpy_to_vram::@2/memcpy_to_vram::s#1 ) [66] memcpy_to_vram::s#2 = phi( memcpy_to_vram/memcpy_to_vram::s#4, memcpy_to_vram::@2/memcpy_to_vram::s#1 )
[65] if(memcpy_to_vram::s#2!=memcpy_to_vram::end#0) goto memcpy_to_vram::@2 [67] if(memcpy_to_vram::s#2!=memcpy_to_vram::end#0) goto memcpy_to_vram::@2
to:memcpy_to_vram::@return to:memcpy_to_vram::@return
memcpy_to_vram::@return: scope:[memcpy_to_vram] from memcpy_to_vram::@1 memcpy_to_vram::@return: scope:[memcpy_to_vram] from memcpy_to_vram::@1
[66] return [68] return
to:@return to:@return
memcpy_to_vram::@2: scope:[memcpy_to_vram] from memcpy_to_vram::@1 memcpy_to_vram::@2: scope:[memcpy_to_vram] from memcpy_to_vram::@1
[67] *VERA_DATA0 = *memcpy_to_vram::s#2 [69] *VERA_DATA0 = *memcpy_to_vram::s#2
[68] memcpy_to_vram::s#1 = ++ memcpy_to_vram::s#2 [70] memcpy_to_vram::s#1 = ++ memcpy_to_vram::s#2
to:memcpy_to_vram::@1 to:memcpy_to_vram::@1

View File

@ -1,17 +1,47 @@
const nomodify void()** KERNEL_IRQ = (void()**) 788 const nomodify void()** KERNEL_IRQ = (void()**) 788
const byte OFFSET_STRUCT_VERA_SPRITE_X = 2 const byte OFFSET_STRUCT_VERA_SPRITE_X = 2
const byte OFFSET_STRUCT_VERA_SPRITE_Y = 4 const byte OFFSET_STRUCT_VERA_SPRITE_Y = 4
const word* SINX[$f1] = kickasm {{ .fillword 256, 288+288*sin(i*2*PI/241) const word* SINX[SINX_LEN] = kickasm {{ .fillword 256, 288+288*sin(i*2*PI/SINX_LEN)
}} }}
const word* SINY[$fb] = kickasm {{ .fillword 256, 208+208*sin(i*2*PI/251) 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_BYTE = 1
const byte SIZEOF_STRUCT_VERA_SPRITE = 8 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 } 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("sprite.png", List().add($000000, $ffffff)) const byte* SPRITE_PIXELS[$40*$40] = kickasm {{ .var pic = LoadPicture("tut.png")
.for (var x=0;x<64; x++) // palette: rgb->idx
.for (var y=0; y<64; y++) .var palette = Hashtable()
.byte (pic.getPixel(x,y)==0) ? 0 : 1 // RGB value for each palette index
.var palList = List()
// Next palette index
.var nxt_idx = 0;
.for (var y=0; y<64; y++) {
.for (var x=0;x<64; x++) {
.var rgb = pic.getPixel(x,y);
.var idx = palette.get(rgb)
.if(idx==null) {
.eval idx = nxt_idx++;
.eval palette.put(rgb,idx);
.eval palList.add(rgb)
}
// Output pixel index
.byte idx
}
}
// 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
// bits bits 0-3 red
.byte red/16
}
}} }}
const nomodify dword SPRITE_PIXELS_VRAM = $8000 const nomodify dword SPRITE_PIXELS_VRAM = $8000
const nomodify byte VERA_ADDRSEL = 1 const nomodify byte VERA_ADDRSEL = 1
@ -25,6 +55,7 @@ const nomodify byte* VERA_DC_VIDEO = (byte*) 40745
const nomodify byte* VERA_IEN = (byte*) 40742 const nomodify byte* VERA_IEN = (byte*) 40742
const nomodify byte VERA_INC_1 = $10 const nomodify byte VERA_INC_1 = $10
const nomodify byte* VERA_ISR = (byte*) 40743 const nomodify byte* VERA_ISR = (byte*) 40743
const nomodify dword VERA_PALETTE = $1fa00
const byte VERA_SPRITES_ENABLE = $40 const byte VERA_SPRITES_ENABLE = $40
const nomodify word VERA_SPRITE_8BPP = $8000 const nomodify word VERA_SPRITE_8BPP = $8000
const nomodify dword VERA_SPRITE_ATTR = $1fc00 const nomodify dword VERA_SPRITE_ATTR = $1fc00
@ -68,19 +99,19 @@ byte~ memcpy_to_vram::$2 reg byte a 2002.0
byte* memcpy_to_vram::end byte* memcpy_to_vram::end
byte* memcpy_to_vram::end#0 end zp[2]:16 16833.666666666664 byte* memcpy_to_vram::end#0 end zp[2]:16 16833.666666666664
word memcpy_to_vram::num word memcpy_to_vram::num
word memcpy_to_vram::num#3 num zp[2]:16 125.125 word memcpy_to_vram::num#4 num zp[2]:16 125.125
byte* memcpy_to_vram::s byte* memcpy_to_vram::s
byte* memcpy_to_vram::s#1 s zp[2]:14 200002.0 byte* memcpy_to_vram::s#1 s zp[2]:14 200002.0
byte* memcpy_to_vram::s#2 s zp[2]:14 133668.3333333333 byte* memcpy_to_vram::s#2 s zp[2]:14 133668.3333333333
byte* memcpy_to_vram::s#4 s zp[2]:14 2002.0 byte* memcpy_to_vram::s#4 s zp[2]:14 2002.0
void* memcpy_to_vram::src void* memcpy_to_vram::src
void* memcpy_to_vram::src#3 src zp[2]:14 void* memcpy_to_vram::src#4 src zp[2]:14
byte memcpy_to_vram::vbank byte memcpy_to_vram::vbank
byte memcpy_to_vram::vbank#3 reg byte x 166.83333333333334 byte memcpy_to_vram::vbank#4 reg byte x 166.83333333333334
void* memcpy_to_vram::vdest void* memcpy_to_vram::vdest
void* memcpy_to_vram::vdest#1 vdest zp[2]:12 202.0 void* memcpy_to_vram::vdest#2 vdest zp[2]:12 202.0
void* memcpy_to_vram::vdest#2 vdest zp[2]:12 22.0 void* memcpy_to_vram::vdest#3 vdest zp[2]:12 22.0
void* memcpy_to_vram::vdest#3 vdest zp[2]:12 528.5 void* memcpy_to_vram::vdest#4 vdest zp[2]:12 528.5
volatile word sin_idx_x loadstore zp[2]:18 1.9999999999999998 volatile word sin_idx_x loadstore zp[2]:18 1.9999999999999998
volatile word sin_idx_y loadstore zp[2]:20 1.714285714285714 volatile word sin_idx_y loadstore zp[2]:20 1.714285714285714
@ -90,10 +121,10 @@ zp[2]:5 [ irq_vsync::i_y#3 irq_vsync::i_y#0 irq_vsync::i_y#9 irq_vsync::i_y#2 ir
zp[2]:7 [ irq_vsync::vram_sprite_pos#2 irq_vsync::vram_sprite_pos#1 ] zp[2]:7 [ irq_vsync::vram_sprite_pos#2 irq_vsync::vram_sprite_pos#1 ]
zp[1]:9 [ main::s#2 main::s#1 ] zp[1]:9 [ main::s#2 main::s#1 ]
zp[2]:10 [ main::vram_sprite_attr#2 main::vram_sprite_attr#1 ] zp[2]:10 [ main::vram_sprite_attr#2 main::vram_sprite_attr#1 ]
zp[2]:12 [ memcpy_to_vram::vdest#3 memcpy_to_vram::vdest#2 memcpy_to_vram::vdest#1 ] zp[2]:12 [ memcpy_to_vram::vdest#4 memcpy_to_vram::vdest#3 memcpy_to_vram::vdest#2 ]
reg byte x [ memcpy_to_vram::vbank#3 ] reg byte x [ memcpy_to_vram::vbank#4 ]
zp[2]:14 [ memcpy_to_vram::src#3 memcpy_to_vram::s#2 memcpy_to_vram::s#4 memcpy_to_vram::s#1 ] zp[2]:14 [ memcpy_to_vram::src#4 memcpy_to_vram::s#2 memcpy_to_vram::s#4 memcpy_to_vram::s#1 ]
zp[2]:16 [ memcpy_to_vram::num#3 memcpy_to_vram::end#0 ] zp[2]:16 [ memcpy_to_vram::num#4 memcpy_to_vram::end#0 ]
zp[2]:18 [ sin_idx_x ] zp[2]:18 [ sin_idx_x ]
zp[2]:20 [ sin_idx_y ] zp[2]:20 [ sin_idx_y ]
zp[2]:22 [ irq_vsync::$11 irq_vsync::$13 ] zp[2]:22 [ irq_vsync::$11 irq_vsync::$13 ]