mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-12-21 21:29:17 +00:00
72 lines
13 KiB
C
72 lines
13 KiB
C
|
|
||
|
#include <peekpoke.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
extern void (*INTVEC)();
|
||
|
#pragma zpsym("INTVEC")
|
||
|
|
||
|
char framecount;
|
||
|
|
||
|
void irq_handler() {
|
||
|
asm("inc _framecount");
|
||
|
asm("rti");
|
||
|
}
|
||
|
|
||
|
void irq_setup() {
|
||
|
INTVEC = irq_handler;
|
||
|
}
|
||
|
|
||
|
// lower 4 bits are background
|
||
|
// upper 2 bits are sprites
|
||
|
const char PALETTE[3] = {
|
||
|
0b01000001, // red
|
||
|
0b11111010, // green
|
||
|
0b10111100, // blue
|
||
|
};
|
||
|
|
||
|
/*{w:8,h:8,brev:1,count:256}*/
|
||
|
const char FONT[256][8] = {
|
||
|
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x38,0x44,0x6c,0x44,0x54,0x44,0x38,0x00 }, { 0x38,0x7c,0x54,0x7c,0x44,0x7c,0x38,0x00 }, { 0x00,0x28,0x7c,0x7c,0x7c,0x38,0x10,0x00 }, { 0x00,0x10,0x38,0x7c,0x7c,0x38,0x10,0x00 }, { 0x10,0x38,0x38,0x10,0x7c,0x7c,0x10,0x00 }, { 0x00,0x10,0x38,0x7c,0x7c,0x10,0x38,0x00 }, { 0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00 }, { 0xfc,0xfc,0xfc,0xcc,0xcc,0xfc,0xfc,0xfc }, { 0x00,0x00,0x78,0x48,0x48,0x78,0x00,0x00 }, { 0xfc,0xfc,0x84,0xb4,0xb4,0x84,0xfc,0xfc }, { 0x00,0x1c,0x0c,0x34,0x48,0x48,0x30,0x00 }, { 0x38,0x44,0x44,0x38,0x10,0x38,0x10,0x00 }, { 0x10,0x18,0x14,0x10,0x30,0x70,0x60,0x00 }, { 0x0c,0x34,0x2c,0x34,0x2c,0x6c,0x60,0x00 }, { 0x00,0x54,0x38,0x6c,0x38,0x54,0x00,0x00 }, { 0x20,0x30,0x38,0x3c,0x38,0x30,0x20,0x00 }, { 0x08,0x18,0x38,0x78,0x38,0x18,0x08,0x00 }, { 0x10,0x38,0x7c,0x10,0x7c,0x38,0x10,0x00 }, { 0x28,0x28,0x28,0x28,0x28,0x00,0x28,0x00 }, { 0x3c,0x54,0x54,0x34,0x14,0x14,0x14,0x00 }, { 0x38,0x44,0x30,0x28,0x18,0x44,0x38,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x78,0x78,0x00 }, { 0x10,0x38,0x7c,0x10,0x7c,0x38,0x10,0x38 }, { 0x10,0x38,0x7c,0x10,0x10,0x10,0x10,0x00 }, { 0x10,0x10,0x10,0x10,0x7c,0x38,0x10,0x00 }, { 0x00,0x10,0x18,0x7c,0x18,0x10,0x00,0x00 }, { 0x00,0x10,0x30,0x7c,0x30,0x10,0x00,0x00 }, { 0x00,0x00,0x00,0x40,0x40,0x40,0x7c,0x00 }, { 0x00,0x28,0x28,0x7c,0x28,0x28,0x00,0x00 }, { 0x10,0x10,0x38,0x38,0x7c,0x7c,0x00,0x00 }, { 0x7c,0x7c,0x38,0x38,0x10,0x10,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x10,0x38,0x38,0x10,0x10,0x00,0x10,0x00 }, { 0x6c,0x6c,0x48,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x28,0x7c,0x28,0x28,0x7c,0x28,0x00 }, { 0x20,0x38,0x40,0x30,0x08,0x70,0x10,0x00 }, { 0x64,0x64,0x08,0x10,0x20,0x4c,0x4c,0x00 }, { 0x20,0x50,0x50,0x20,0x54,0x48,0x34,0x00 }, { 0x30,0x30,0x20,0x00,0x00,0x00,0x00,0x00 }, { 0x10,0x20,0x20,0x20,0x20,0x20,0x10,0x00 }, { 0x20,0x10,0x10,0x10,0x10,0x10,0x20,0x00 }, { 0x00,0x28,0x38,0x7c,0x38,0x28,0x00,0x00 }, { 0x00,0x10,0x10,0x7c,0x10,0x10,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x20 }, { 0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00 }, { 0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00 }, { 0x38,0x44,0x4c,0x54,0x64,0x44,0x38,0x00 }, { 0x10,0x30,0x10,0x10,0x10,0x10,0x38,0x00 }, { 0x38,0x44,0x04,0x18,0x20,0x40,0x7c,0x00 }, { 0x38,0x44,0x04,0x38,0x04,0x44,0x38,0x00 }, { 0x08,0x18,0x28,0x48,0x7c,0x08,0x08,0x00 }, { 0x7c,0x40,0x40,0x78,0x04,0x44,0x38,0x00 }, { 0x18,0x20,0x40,0x78,0x44,0x44,0x38,0x00 }, { 0x7c,0x04,0x08,0x10,0x20,0x20,0x20,0x00 }, { 0x38,0x44,0x44,0x38,0x44,0x44,0x38,0x00 }, { 0x38,0x44,0x44,0x3c,0x04,0x08,0x30,0x00 }, { 0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x00 }, { 0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x20 }, { 0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00 }, { 0x00,0x00,0x7c,0x00,0x00,0x7c,0x00,0x00 }, { 0x20,0x10,0x08,0x04,0x08,0x10,0x20,0x00 }, { 0x38,0x44,0x04,0x18,0x10,0x00,0x10,0x00 }, { 0x38,0x44,0x5c,0x54,0x5c,0x40,0x38,0x00 }, { 0x38,0x44,0x44,0x44,0x7c,0x44,0x44,0x00 }, { 0x78,0x44,0x44,0x78,0x44,0x44,0x78,0x00 }, { 0x38,0x44,0x40,0x40,0x40,0x44,0x38,0x00 }, { 0x78,0x44,0x44,0x44,0x44,0x44,0x78,0x00 }, { 0x7c,0x40,0x40,0x78,0x40,0x40,0x7c,0x00 }, { 0x7c,0x40,0x40,0x78,0x40,0x40,0x40,0x00 }, { 0x38,0x44,0x40,0x5c,0x44,0x44,0x3c,0x00 }, { 0x44,0x44,0x44,0x7c,0x44,0x44,0x44,0x00 }, { 0x38,0x10,0x10,0x10,0x10,0x10,0x38,0x00 }, { 0x04,0x04,0x04,0x04,0x44,0x44,0x38,0x00 }, { 0x44,0x48,0x50,0x60,0x50,0x48,0x44,0x00 }, { 0x40,0x40,0x40,0x40,0x40,0x40,0x7c,0x00 }, { 0x44,0x6c,0x54,0x44,0x44,0x44,0x44,0x00 }, { 0x44,0x64,0x54,0x4c,0x44,0x44,0x44,0x00 }, { 0x38,0x44,0x44,0x44,0x44,0x44,0x38,0x00 }, { 0x78,0x44,0x44,0x78,0x40,0x40,0x40,0x00 }, { 0x38,0x44,0x44,0x44,0x54,0x48,0x34,0x00 }, { 0x78,0x44,0x44,0x78,0x48,0x44,0x44,0x00 }, { 0x38,0x44,0x40,0x38,0x04,0x44,0x38,0x00 }, { 0x7c,0x10,0x10,0x10,0x10,0x10,0x10,0x00 }, { 0x44,0x44,0x44,0x44,0x44,0x44,0x38,0x00 }, { 0x44,0x44,0x44,0x44,0x44,0x28,0x10,0x00 }, { 0x44,0x44,0x54,0x54,0x54,0x54,0x28,0x00 }, { 0x44,0x44,0x28,0x10,0x28,0x44,0x44,0x00 }, { 0x44,0x44,0x44,0x28,0x10,0x10,0x10,0x00 }, { 0x78,0x08,0x10,0x20,0x40,0x40,0x78,0x00 },
|
||
|
};
|
||
|
|
||
|
#pragma rodata-name (push, "SPRITES")
|
||
|
const char SPRITES[2][16*2] = {
|
||
|
/*{w:16,h:16,brev:1,remap:[4,0,1,2,3,5,6,7,8,9],count:2}*/
|
||
|
{
|
||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x3F,
|
||
|
0x35, 0x2A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3F,
|
||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x40, 0xFC,
|
||
|
0x54, 0xAC, 0x04, 0x04, 0x04, 0x04, 0x04, 0xFC,
|
||
|
},{
|
||
|
0x00, 0x19, 0x1F, 0x0A, 0x05, 0x07, 0x0E, 0x1C,
|
||
|
0x3A, 0x2A, 0x3C, 0x2E, 0x1E, 0x18, 0x0E, 0x07,
|
||
|
0x00, 0x80, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0x38,
|
||
|
0xFC, 0xF4, 0x7C, 0xB4, 0xB8, 0x68, 0xF0, 0xE0,
|
||
|
}
|
||
|
};
|
||
|
#pragma rodata-name (pop)
|
||
|
|
||
|
void main() {
|
||
|
int i;
|
||
|
|
||
|
// copy tile bitmaps
|
||
|
memcpy((char*)0x6800, FONT, sizeof(FONT));
|
||
|
// set up screen
|
||
|
for (i=0; i<32*32; i++) {
|
||
|
POKE(0x4000+i, i);
|
||
|
}
|
||
|
memcpy((char*)0x5210, PALETTE, 3);
|
||
|
|
||
|
// setup interrupt handler
|
||
|
irq_setup();
|
||
|
|
||
|
while (1) {
|
||
|
// move sprites
|
||
|
POKE(0x5000, 16); // sprite 0 x
|
||
|
POKE(0x5040, 16); // sprite 0 y
|
||
|
POKE(0x5080, framecount); // sprite 0 x
|
||
|
POKE(0x50C0, 16); // sprite 1 y
|
||
|
POKE(0x5100, 0x01);
|
||
|
}
|
||
|
}
|