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

Introduces OAM struct.

This commit is contained in:
jespergravgaard 2020-05-24 01:15:58 +02:00
parent c8cd5a0e51
commit 7c965b6ef6
5 changed files with 411 additions and 373 deletions

View File

@ -71,22 +71,6 @@ interrupt(hardware_stack) void vblank() {
}
// move the Luigi sprites right
void moveLuigiRight() {
OAM_BUFFER[0x03]++;
OAM_BUFFER[0x07]++;
OAM_BUFFER[0x0b]++;
OAM_BUFFER[0x0f]++;
}
// move the Luigi sprites left
void moveLuigiLeft() {
OAM_BUFFER[0x03]--;
OAM_BUFFER[0x07]--;
OAM_BUFFER[0x0b]--;
OAM_BUFFER[0x0f]--;
}
// Copy palette values to PPU
void initPaletteData() {
// Reset the high/low latch to "high"
@ -100,16 +84,6 @@ void initPaletteData() {
PPU->PPUDATA = PALETTE[i];
}
// OAM (Object Attribute Memory) Buffer
// Will be transfered to the PPU via DMA
char * const OAM_BUFFER = 0x0200;
// Initialize OAM (Object Attribute Memory) Buffer
void initSpriteData() {
for(char i=0;i<sizeof(SPRITES);i++)
OAM_BUFFER[i] = SPRITES[i];
}
char PALETTE[0x20] = {
// Background palettes
0x0f, 0x31, 0x32, 0x33,
@ -123,13 +97,49 @@ char PALETTE[0x20] = {
0x0f, 0x0f, 0x0f, 0x0f // All black
};
// Sprite Object Attribute Memory Structure
struct ObjectAttribute {
char y;
char tile;
char attributes;
char x;
};
// OAM (Object Attribute Memory) Buffer
// Will be transfered to the PPU via DMA
struct ObjectAttribute * const OAM_BUFFER = 0x0200;
// move the Luigi sprites right
void moveLuigiRight() {
OAM_BUFFER[0].x++;
OAM_BUFFER[1].x++;
OAM_BUFFER[2].x++;
OAM_BUFFER[3].x++;
}
// move the Luigi sprites left
void moveLuigiLeft() {
OAM_BUFFER[0].x--;
OAM_BUFFER[1].x--;
OAM_BUFFER[2].x--;
OAM_BUFFER[3].x--;
}
// Initialize OAM (Object Attribute Memory) Buffer
void initSpriteData() {
char i=0;
do {
((char*)OAM_BUFFER)[i] = ((char*)SPRITES)[i];
} while (++i!=sizeof(SPRITES));
}
// Small Luigi Sprite Data
char SPRITES[] = {
struct ObjectAttribute SPRITES[] = {
// Y , TILE, ATTR , X
128, 0x36, 0b00000010, 128, // Sprite 0
128, 0x37, 0b00000010, 136, // Sprite 1
136, 0x38, 0b00000010, 128, // Sprite 2
136, 0x39, 0b00000010, 136 // Sprite 3
{ 128, 0x36, 0b00000010, 128 }, // Sprite 0
{ 128, 0x37, 0b00000010, 136 }, // Sprite 1
{ 136, 0x38, 0b00000010, 128 }, // Sprite 2
{ 136, 0x39, 0b00000010, 136 } // Sprite 3
};
// Tiles

View File

@ -28,6 +28,7 @@
// Mirroring nibble 0001 == Vertical mirroring only
.segment Code
.const SIZEOF_STRUCT_OBJECTATTRIBUTE = 4
.const OFFSET_STRUCT_RICOH_2A03_DMC_FREQ = $10
.const OFFSET_STRUCT_RICOH_2C02_PPUMASK = 1
.const OFFSET_STRUCT_RICOH_2C02_PPUSTATUS = 2
@ -36,6 +37,7 @@
.const OFFSET_STRUCT_RICOH_2A03_JOY1 = $16
.const OFFSET_STRUCT_RICOH_2C02_PPUADDR = 6
.const OFFSET_STRUCT_RICOH_2C02_PPUDATA = 7
.const OFFSET_STRUCT_OBJECTATTRIBUTE_X = 3
.const SIZEOF_BYTE = 1
// $3000-$3EFF $0F00 Mirrors of $2000-$2EFF
// $3F00-$3F1F $0020 Palette RAM indexes
@ -138,18 +140,15 @@ main: {
initSpriteData: {
ldx #0
__b1:
// for(char i=0;i<sizeof(SPRITES);i++)
cpx #$10*SIZEOF_BYTE
bcc __b2
// }
rts
__b2:
// OAM_BUFFER[i] = SPRITES[i]
// ((char*)OAM_BUFFER)[i] = ((char*)SPRITES)[i]
lda SPRITES,x
sta OAM_BUFFER,x
// for(char i=0;i<sizeof(SPRITES);i++)
// while (++i!=sizeof(SPRITES))
inx
jmp __b1
cpx #4*SIZEOF_STRUCT_OBJECTATTRIBUTE
bne __b1
// }
rts
}
// Copy palette values to PPU
initPaletteData: {
@ -231,27 +230,27 @@ vblank: {
}
// move the Luigi sprites left
moveLuigiLeft: {
// OAM_BUFFER[0x03]--;
dec OAM_BUFFER+3
// OAM_BUFFER[0x07]--;
dec OAM_BUFFER+7
// OAM_BUFFER[0x0b]--;
dec OAM_BUFFER+$b
// OAM_BUFFER[0x0f]--;
dec OAM_BUFFER+$f
// OAM_BUFFER[0].x--;
dec OAM_BUFFER+OFFSET_STRUCT_OBJECTATTRIBUTE_X
// OAM_BUFFER[1].x--;
dec OAM_BUFFER+OFFSET_STRUCT_OBJECTATTRIBUTE_X+1*SIZEOF_STRUCT_OBJECTATTRIBUTE
// OAM_BUFFER[2].x--;
dec OAM_BUFFER+OFFSET_STRUCT_OBJECTATTRIBUTE_X+2*SIZEOF_STRUCT_OBJECTATTRIBUTE
// OAM_BUFFER[3].x--;
dec OAM_BUFFER+OFFSET_STRUCT_OBJECTATTRIBUTE_X+3*SIZEOF_STRUCT_OBJECTATTRIBUTE
// }
rts
}
// move the Luigi sprites right
moveLuigiRight: {
// OAM_BUFFER[0x03]++;
inc OAM_BUFFER+3
// OAM_BUFFER[0x07]++;
inc OAM_BUFFER+7
// OAM_BUFFER[0x0b]++;
inc OAM_BUFFER+$b
// OAM_BUFFER[0x0f]++;
inc OAM_BUFFER+$f
// OAM_BUFFER[0].x++;
inc OAM_BUFFER+OFFSET_STRUCT_OBJECTATTRIBUTE_X
// OAM_BUFFER[1].x++;
inc OAM_BUFFER+OFFSET_STRUCT_OBJECTATTRIBUTE_X+1*SIZEOF_STRUCT_OBJECTATTRIBUTE
// OAM_BUFFER[2].x++;
inc OAM_BUFFER+OFFSET_STRUCT_OBJECTATTRIBUTE_X+2*SIZEOF_STRUCT_OBJECTATTRIBUTE
// OAM_BUFFER[3].x++;
inc OAM_BUFFER+OFFSET_STRUCT_OBJECTATTRIBUTE_X+3*SIZEOF_STRUCT_OBJECTATTRIBUTE
// }
rts
}

View File

@ -70,17 +70,15 @@ main::@2: scope:[main] from main::@2 main::enableVideoOutput1
initSpriteData: scope:[initSpriteData] from main::@4
[34] phi()
to:initSpriteData::@1
initSpriteData::@1: scope:[initSpriteData] from initSpriteData initSpriteData::@2
[35] (byte) initSpriteData::i#2 ← phi( initSpriteData/(byte) 0 initSpriteData::@2/(byte) initSpriteData::i#1 )
[36] if((byte) initSpriteData::i#2<(byte) $10*(const byte) SIZEOF_BYTE) goto initSpriteData::@2
initSpriteData::@1: scope:[initSpriteData] from initSpriteData initSpriteData::@1
[35] (byte) initSpriteData::i#2 ← phi( initSpriteData/(byte) 0 initSpriteData::@1/(byte) initSpriteData::i#1 )
[36] *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER + (byte) initSpriteData::i#2) ← *((byte*)(const struct ObjectAttribute*) SPRITES + (byte) initSpriteData::i#2)
[37] (byte) initSpriteData::i#1 ← ++ (byte) initSpriteData::i#2
[38] if((byte) initSpriteData::i#1!=(byte) 4*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE) goto initSpriteData::@1
to:initSpriteData::@return
initSpriteData::@return: scope:[initSpriteData] from initSpriteData::@1
[37] return
[39] return
to:@return
initSpriteData::@2: scope:[initSpriteData] from initSpriteData::@1
[38] *((const nomodify byte*) OAM_BUFFER + (byte) initSpriteData::i#2) ← *((const byte*) SPRITES + (byte) initSpriteData::i#2)
[39] (byte) initSpriteData::i#1 ← ++ (byte) initSpriteData::i#2
to:initSpriteData::@1
(void()) initPaletteData()
initPaletteData: scope:[initPaletteData] from main::@3
@ -103,7 +101,7 @@ initPaletteData::@2: scope:[initPaletteData] from initPaletteData::@1
interrupt(HARDWARE_STACK)(void()) vblank()
vblank: scope:[vblank] from
[48] *((byte*)(const struct RICOH_2C02*) PPU+(const byte) OFFSET_STRUCT_RICOH_2C02_OAMADDR) ← (byte) 0
[49] *((byte*)(const struct RICOH_2A03*) APU+(const byte) OFFSET_STRUCT_RICOH_2A03_OAMDMA) ← >(const nomodify byte*) OAM_BUFFER
[49] *((byte*)(const struct RICOH_2A03*) APU+(const byte) OFFSET_STRUCT_RICOH_2A03_OAMDMA) ← >(const nomodify struct ObjectAttribute*) OAM_BUFFER
[50] *((byte*)(const struct RICOH_2A03*) APU+(const byte) OFFSET_STRUCT_RICOH_2A03_JOY1) ← (byte) 1
[51] *((byte*)(const struct RICOH_2A03*) APU+(const byte) OFFSET_STRUCT_RICOH_2A03_JOY1) ← (byte) 0
[52] (byte~) vblank::$1 ← *((byte*)(const struct RICOH_2A03*) APU+(const byte) OFFSET_STRUCT_RICOH_2A03_JOY1) & (byte) 1
@ -127,10 +125,10 @@ vblank::@return: scope:[vblank] from vblank::@1 vblank::@3
(void()) moveLuigiLeft()
moveLuigiLeft: scope:[moveLuigiLeft] from vblank::@3
[61] *((const nomodify byte*) OAM_BUFFER+(byte) 3) ← -- *((const nomodify byte*) OAM_BUFFER+(byte) 3)
[62] *((const nomodify byte*) OAM_BUFFER+(byte) 7) ← -- *((const nomodify byte*) OAM_BUFFER+(byte) 7)
[63] *((const nomodify byte*) OAM_BUFFER+(byte) $b) ← -- *((const nomodify byte*) OAM_BUFFER+(byte) $b)
[64] *((const nomodify byte*) OAM_BUFFER+(byte) $f) ← -- *((const nomodify byte*) OAM_BUFFER+(byte) $f)
[61] *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X) ← -- *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X)
[62] *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 1*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE) ← -- *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 1*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE)
[63] *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 2*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE) ← -- *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 2*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE)
[64] *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 3*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE) ← -- *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 3*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE)
to:moveLuigiLeft::@return
moveLuigiLeft::@return: scope:[moveLuigiLeft] from moveLuigiLeft
[65] return
@ -138,10 +136,10 @@ moveLuigiLeft::@return: scope:[moveLuigiLeft] from moveLuigiLeft
(void()) moveLuigiRight()
moveLuigiRight: scope:[moveLuigiRight] from vblank::@2
[66] *((const nomodify byte*) OAM_BUFFER+(byte) 3) ← ++ *((const nomodify byte*) OAM_BUFFER+(byte) 3)
[67] *((const nomodify byte*) OAM_BUFFER+(byte) 7) ← ++ *((const nomodify byte*) OAM_BUFFER+(byte) 7)
[68] *((const nomodify byte*) OAM_BUFFER+(byte) $b) ← ++ *((const nomodify byte*) OAM_BUFFER+(byte) $b)
[69] *((const nomodify byte*) OAM_BUFFER+(byte) $f) ← ++ *((const nomodify byte*) OAM_BUFFER+(byte) $f)
[66] *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X) ← ++ *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X)
[67] *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 1*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE) ← ++ *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 1*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE)
[68] *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 2*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE) ← ++ *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 2*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE)
[69] *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 3*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE) ← ++ *((byte*)(const nomodify struct ObjectAttribute*) OAM_BUFFER+(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X+(byte) 3*(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE)
to:moveLuigiRight::@return
moveLuigiRight::@return: scope:[moveLuigiRight] from moveLuigiRight
[70] return

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,8 @@
.segmentout [ segments="ProgramRom" ]
.segmentout [ segments="CharacterRom" ]
}}
(const nomodify byte*) OAM_BUFFER = (byte*) 512
(const nomodify struct ObjectAttribute*) OAM_BUFFER = (struct ObjectAttribute*) 512
(const byte) OFFSET_STRUCT_OBJECTATTRIBUTE_X = (byte) 3
(const byte) OFFSET_STRUCT_RICOH_2A03_DMC_FREQ = (byte) $10
(const byte) OFFSET_STRUCT_RICOH_2A03_JOY1 = (byte) $16
(const byte) OFFSET_STRUCT_RICOH_2A03_OAMDMA = (byte) $14
@ -17,6 +18,10 @@
(const byte) OFFSET_STRUCT_RICOH_2C02_PPUDATA = (byte) 7
(const byte) OFFSET_STRUCT_RICOH_2C02_PPUMASK = (byte) 1
(const byte) OFFSET_STRUCT_RICOH_2C02_PPUSTATUS = (byte) 2
(byte) ObjectAttribute::attributes
(byte) ObjectAttribute::tile
(byte) ObjectAttribute::x
(byte) ObjectAttribute::y
(const byte*) PALETTE[(number) $20] = { (byte) $f, (byte) $31, (byte) $32, (byte) $33, (byte) $f, (byte) $35, (byte) $36, (byte) $37, (byte) $f, (byte) $39, (byte) $3a, (byte) $3b, (byte) $f, (byte) $3d, (byte) $3e, (byte) $f, (byte) $f, (byte) $1c, (byte) $15, (byte) $14, (byte) $f, (byte) 2, (byte) $38, (byte) $3c, (byte) $f, (byte) $30, (byte) $37, (byte) $1a, (byte) $f, (byte) $f, (byte) $f, (byte) $f }
(const struct RICOH_2C02*) PPU = (struct RICOH_2C02*) 8192
(const nomodify byte*) PPU_PALETTE = (byte*) 16128
@ -54,7 +59,8 @@
(byte) RICOH_2C02::PPUSCROLL
(volatile byte) RICOH_2C02::PPUSTATUS loadstore
(const byte) SIZEOF_BYTE = (byte) 1
(const byte*) SPRITES[] = { (byte) $80, (byte) $36, (byte) 2, (byte) $80, (byte) $80, (byte) $37, (byte) 2, (byte) $88, (byte) $88, (byte) $38, (byte) 2, (byte) $80, (byte) $88, (byte) $39, (byte) 2, (byte) $88 }
(const byte) SIZEOF_STRUCT_OBJECTATTRIBUTE = (byte) 4
(const struct ObjectAttribute*) SPRITES[] = { { y: (byte) $80, tile: (byte) $36, attributes: (byte) 2, x: (byte) $80 }, { y: (byte) $80, tile: (byte) $37, attributes: (byte) 2, x: (byte) $88 }, { y: (byte) $88, tile: (byte) $38, attributes: (byte) 2, x: (byte) $80 }, { y: (byte) $88, tile: (byte) $39, attributes: (byte) 2, x: (byte) $88 } }
(const byte*) TILES[] = kickasm {{ .import binary "smb1_chr.bin"
}}
(const to_nomodify void()**) VECTORS[] = { &interrupt(HARDWARE_STACK)(void()) vblank(), &(void()) main(), (void()*) 0 }
@ -67,11 +73,10 @@
(byte) initPaletteData::i#2 reg byte x 1334.6666666666667
(void()) initSpriteData()
(label) initSpriteData::@1
(label) initSpriteData::@2
(label) initSpriteData::@return
(byte) initSpriteData::i
(byte) initSpriteData::i#1 reg byte x 2002.0
(byte) initSpriteData::i#2 reg byte x 1668.3333333333335
(byte) initSpriteData::i#1 reg byte x 1501.5
(byte) initSpriteData::i#2 reg byte x 2002.0
(void()) main()
(label) main::@1
(label) main::@2