diff --git a/presets/mw8080bw/game2.c b/presets/mw8080bw/game2.c new file mode 100644 index 00000000..6e18bbdb --- /dev/null +++ b/presets/mw8080bw/game2.c @@ -0,0 +1,327 @@ + +#include + +typedef unsigned char byte; +typedef unsigned char word; + +__sfr __at (0x0) input0; +__sfr __at (0x1) input1; +__sfr __at (0x2) input2; +__sfr __at (0x2) bitshift_offset; +__sfr __at (0x3) bitshift_read; +__sfr __at (0x4) bitshift_value; +__sfr __at (0x6) watchdog_strobe; +byte __at (0x2400) vidmem[0x1c00]; // 256x224x1 video memory + +#define FIRE1 (input1 & 0x10) +#define LEFT1 (input1 & 0x20) +#define RIGHT1 (input1 & 0x40) + +void main(); +void scanline96() __interrupt; +void scanline224(); + +// start routine @ 0x0 +// set stack pointer, enable interrupts +void start() { +__asm + LD SP,#0x2400 + EI + NOP +__endasm; + main(); +} + +// scanline 96 interrupt @ 0x8 +// we don't have enough bytes to make this an interrupt +// because the next routine is at 0x10 +void _RST_8() { +__asm + NOP + NOP + NOP + NOP + NOP +__endasm; + scanline96(); +} + +// scanline 224 interrupt @ 0x10 +// this one, we make an interrupt so it saves regs. +void RST_10() __interrupt { + scanline224(); +} + +// scanline 96 function, saves regs +void scanline96() __interrupt { +} + +// scanline 224 function, regs already saved +void scanline224() { +} + +/// GRAPHICS FUNCTIONS + +void draw_vline(byte x, byte y1, byte y2) { + byte yb1 = y1/8; + byte yb2 = y2/8; + byte* dest = &vidmem[x*32+yb1]; + signed char nbytes = yb2 - yb1; + *dest++ ^= 0xff << (y1&7); + if (nbytes > 0) { + while (--nbytes > 0) { + *dest++ ^= 0xff; + } + *dest ^= 0xff >> (~y2&7); + } else { + *--dest ^= 0xff << ((y2+1)&7); + } +} + +#define LOCHAR 0x20 +#define HICHAR 0x5e + +const byte font8x8[HICHAR-LOCHAR+1][8] = { +{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x79,0x79,0x00,0x00,0x00 }, { 0x00,0x70,0x70,0x00,0x00,0x70,0x70,0x00 }, { 0x14,0x7f,0x7f,0x14,0x14,0x7f,0x7f,0x14 }, { 0x00,0x12,0x3a,0x6b,0x6b,0x2e,0x24,0x00 }, { 0x00,0x63,0x66,0x0c,0x18,0x33,0x63,0x00 }, { 0x00,0x26,0x7f,0x59,0x59,0x77,0x27,0x05 }, { 0x00,0x00,0x00,0x10,0x30,0x60,0x40,0x00 }, { 0x00,0x00,0x1c,0x3e,0x63,0x41,0x00,0x00 }, { 0x00,0x00,0x41,0x63,0x3e,0x1c,0x00,0x00 }, { 0x08,0x2a,0x3e,0x1c,0x1c,0x3e,0x2a,0x08 }, { 0x00,0x08,0x08,0x3e,0x3e,0x08,0x08,0x00 }, { 0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00 }, { 0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00 }, { 0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00 }, { 0x00,0x01,0x03,0x06,0x0c,0x18,0x30,0x20 }, { 0x00,0x3e,0x7f,0x49,0x51,0x7f,0x3e,0x00 }, { 0x00,0x01,0x11,0x7f,0x7f,0x01,0x01,0x00 }, { 0x00,0x23,0x67,0x45,0x49,0x79,0x31,0x00 }, { 0x00,0x22,0x63,0x49,0x49,0x7f,0x36,0x00 }, { 0x00,0x0c,0x0c,0x14,0x34,0x7f,0x7f,0x04 }, { 0x00,0x72,0x73,0x51,0x51,0x5f,0x4e,0x00 }, { 0x00,0x3e,0x7f,0x49,0x49,0x6f,0x26,0x00 }, { 0x00,0x60,0x60,0x4f,0x5f,0x70,0x60,0x00 }, { 0x00,0x36,0x7f,0x49,0x49,0x7f,0x36,0x00 }, { 0x00,0x32,0x7b,0x49,0x49,0x7f,0x3e,0x00 }, { 0x00,0x00,0x00,0x12,0x12,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x13,0x13,0x00,0x00,0x00 }, { 0x00,0x08,0x1c,0x36,0x63,0x41,0x41,0x00 }, { 0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00 }, { 0x00,0x41,0x41,0x63,0x36,0x1c,0x08,0x00 }, { 0x00,0x20,0x60,0x45,0x4d,0x78,0x30,0x00 }, { 0x00,0x3e,0x7f,0x41,0x59,0x79,0x3a,0x00 }, { 0x00,0x1f,0x3f,0x68,0x68,0x3f,0x1f,0x00 }, { 0x00,0x7f,0x7f,0x49,0x49,0x7f,0x36,0x00 }, { 0x00,0x3e,0x7f,0x41,0x41,0x63,0x22,0x00 }, { 0x00,0x7f,0x7f,0x41,0x63,0x3e,0x1c,0x00 }, { 0x00,0x7f,0x7f,0x49,0x49,0x41,0x41,0x00 }, { 0x00,0x7f,0x7f,0x48,0x48,0x40,0x40,0x00 }, { 0x00,0x3e,0x7f,0x41,0x49,0x6f,0x2e,0x00 }, { 0x00,0x7f,0x7f,0x08,0x08,0x7f,0x7f,0x00 }, { 0x00,0x00,0x41,0x7f,0x7f,0x41,0x00,0x00 }, { 0x00,0x02,0x03,0x41,0x7f,0x7e,0x40,0x00 }, { 0x00,0x7f,0x7f,0x1c,0x36,0x63,0x41,0x00 }, { 0x00,0x7f,0x7f,0x01,0x01,0x01,0x01,0x00 }, { 0x00,0x7f,0x7f,0x30,0x18,0x30,0x7f,0x7f }, { 0x00,0x7f,0x7f,0x38,0x1c,0x7f,0x7f,0x00 }, { 0x00,0x3e,0x7f,0x41,0x41,0x7f,0x3e,0x00 }, { 0x00,0x7f,0x7f,0x48,0x48,0x78,0x30,0x00 }, { 0x00,0x3c,0x7e,0x42,0x43,0x7f,0x3d,0x00 }, { 0x00,0x7f,0x7f,0x4c,0x4e,0x7b,0x31,0x00 }, { 0x00,0x32,0x7b,0x49,0x49,0x6f,0x26,0x00 }, { 0x00,0x40,0x40,0x7f,0x7f,0x40,0x40,0x00 }, { 0x00,0x7e,0x7f,0x01,0x01,0x7f,0x7e,0x00 }, { 0x00,0x7c,0x7e,0x03,0x03,0x7e,0x7c,0x00 }, { 0x00,0x7f,0x7f,0x06,0x0c,0x06,0x7f,0x7f }, { 0x00,0x63,0x77,0x1c,0x1c,0x77,0x63,0x00 }, { 0x00,0x70,0x78,0x0f,0x0f,0x78,0x70,0x00 }, { 0x00,0x43,0x47,0x4d,0x59,0x71,0x61,0x00 }, { 0x00,0x00,0x7f,0x7f,0x41,0x41,0x00,0x00 }, { 0x00,0x20,0x30,0x18,0x0c,0x06,0x03,0x01 }, { 0x00,0x00,0x41,0x41,0x7f,0x7f,0x00,0x00 }, { 0x00,0x08,0x18,0x3f,0x3f,0x18,0x08,0x00 } +}; + +const byte bitmap1[] = +{6,63,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0x00,0x80,0x63,0x00,0x00,0x00,0x00,0xc0,0xc0,0x00,0x00,0x00,0x00,0x5e,0x80,0x00,0x00,0x00,0x00,0x73,0x80,0x00,0x00,0x00,0x00,0xe3,0x83,0x00,0x00,0x00,0x00,0xe3,0x9f,0x00,0x00,0x00,0x00,0xc2,0xbf,0x00,0x00,0x00,0xc0,0x03,0xff,0x00,0x00,0x00,0x70,0x06,0xfe,0x01,0x00,0x00,0x18,0x0c,0x00,0x03,0x00,0x00,0x0c,0x18,0x00,0x02,0x00,0x00,0x02,0x30,0x00,0x02,0x00,0x00,0x0f,0xe0,0x00,0x03,0x00,0xc0,0x10,0x80,0xef,0x01,0x00,0x40,0x27,0x00,0x38,0x00,0x00,0xa0,0x47,0x00,0x60,0x00,0x00,0xe0,0x4f,0xf8,0x60,0x00,0x00,0xe0,0x4f,0x0c,0xe1,0x00,0x00,0xe0,0x4f,0x06,0xe2,0x01,0x00,0xe0,0x4f,0xf2,0xe2,0x03,0xfc,0xe0,0x4f,0xfb,0xe4,0x03,0xfe,0xff,0x4f,0xf9,0xe4,0x0f,0xff,0x87,0x27,0xf9,0xe5,0x0f,0xff,0x07,0x36,0xf9,0xe5,0x1f,0xff,0x07,0x18,0xf9,0xe4,0x3f,0xff,0x07,0x00,0xfa,0xe4,0x7f,0xfe,0x07,0x00,0x72,0xe2,0x7f,0xfc,0x03,0x00,0x06,0xe2,0x7f,0xdc,0x00,0x02,0xb8,0xe1,0xff,0x08,0x00,0x04,0x60,0xe0,0xff,0x30,0x00,0x1c,0x00,0xe0,0xff,0x60,0x80,0x03,0x00,0xc0,0x7f,0xc0,0xff,0x01,0x00,0x80,0x7f,0x00,0x00,0x01,0x00,0x80,0x3f,0x00,0x00,0x01,0x00,0x00,0x0e,0x00,0x00,0x01,0x00,0x00,0x02,0x00,0x00,0x01,0x00,0x00,0x02,0x00,0x00,0x01,0x00,0x00,0x02,0x00,0x80,0x01,0x00,0x01,0x02,0x00,0x80,0x00,0x00,0x09,0x02,0x00,0xc0,0x00,0x00,0x09,0x02,0x00,0xc0,0x00,0x00,0x09,0x02,0x00,0xc0,0x00,0x00,0x09,0x02,0x00,0xc0,0x00,0x80,0x08,0x02,0x00,0xc0,0x00,0x80,0x04,0x03,0x00,0xa0,0x00,0x80,0x04,0x03,0x00,0xa0,0x01,0x40,0x04,0x01,0x00,0x20,0x02,0x70,0x82,0x01,0x00,0x70,0xf4,0x1f,0x83,0x00,0x00,0x98,0x1d,0xf8,0xc0,0x00,0x00,0x88,0x0f,0x00,0x60,0x00,0x00,0x88,0x08,0x07,0x38,0x00,0x80,0x8f,0x08,0x3f,0x0e,0x00,0x80,0x98,0x08,0xe1,0x03,0x00,0x80,0x80,0x07,0x01,0x00,0x00,0x80,0xc1,0x0c,0x01,0x00,0x00,0x00,0x83,0x90,0x01,0x00,0x00,0x00,0xfe,0x81,0x00,0x00,0x00,0x00,0x00,0x86,0x00,0x00,0x00,0x00,0x00,0xd8,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00} +; +const byte player_bitmap[] = +{2,27,0,0,0,0,0x0f,0x00,0x3e,0x00,0xf4,0x07,0xec,0x00,0x76,0x00,0x2b,0x00,0x33,0x00,0x75,0x00,0xf5,0x00,0xeb,0x31,0xbf,0xef,0x3f,0xcf,0xbf,0xef,0xeb,0x31,0xf5,0x00,0x75,0x00,0x33,0x00,0x2b,0x00,0x76,0x00,0xec,0x00,0xf4,0x07,0x3e,0x00,0x0f,0x00,0x00,0x00,0,0} +; +const byte bullet_bitmap2[] = +{4,2,0,0x88,0x88,0,0,0x44,0x44,0,} +; +const byte bullet_bitmap[] = +{2,2,0x88,0x88,0x44,0x44} +; +const byte enemy1_bitmap[] = +{2,24,0x0f,0x00,0x3e,0x00,0xf4,0x07,0xec,0x00,0x76,0x00,0x2b,0x00,0x33,0x00,0x75,0x00,0xf5,0x00,0xeb,0x31,0xbf,0xef,0x3f,0xcf,0xbf,0xef,0xeb,0x31,0xf5,0x00,0x75,0x00,0x33,0x00,0x2b,0x00,0x76,0x00,0xec,0x00,0xf4,0x07,0x3e,0x00,0x0f,0x00,0x00,0x00,0,0} +; + +void draw_sprite(const byte* src, byte x, byte y) { + byte i,j; + byte* dest = &vidmem[y+x*32]; + byte w = *src++; + byte h = *src++; + for (j=0; jx = x; + e->y = y; + e->shape = enemy1_bitmap; + x += 28; + if (x > 180) { + x = 0; + y -= 3; + } + } + num_entities = MAX_ENTITIES; + this_mode.right = 1; + this_mode.down = 0; + next_mode.right = 1; + next_mode.down = 0; +} + +void delete_entity(Entity* e) { + erase_sprite(e->shape, e->x, e->y); + memmove(e, e+1, sizeof(Entity)*(entities-e+MAX_ENTITIES-1)); + num_entities--; // update_next_entity() will check entity_index +} + +void update_next_entity() { + Entity* e; + if (entity_index >= num_entities) { + entity_index = 0; + memcpy(&this_mode, &next_mode, sizeof(this_mode)); + } + e = &entities[entity_index]; + erase_sprite(e->shape, e->x, e->y); + if (this_mode.down) { + e->y--; + next_mode.down = 0; + } else { + if (this_mode.right) { + e->x += 2; + if (e->x >= 200) { + next_mode.down = 1; + next_mode.right = 0; + } + } else { + e->x -= 2; + if (e->x == 0) { + next_mode.down = 1; + next_mode.right = 1; + } + } + } + draw_sprite(e->shape, e->x, e->y); + entity_index++; +} + +void draw_bunker(byte x, byte y, byte y2, byte h, byte w) { + byte i; + for (i=0; ishape[0]; + byte w = e->shape[1]; + return (x >= e->x && x <= e->x+w && y >= e->y && y <= e->y+h); +} + +Entity* find_entity_at(byte x, byte y) { + byte i; + for (i=0; i0) player_x -= 2; + if (RIGHT1 && player_x<200) player_x += 2; + if (FIRE1 && bullet_y == 0) { + bullet_x = player_x + 13; + bullet_y = 3; + xor_sprite(bullet_bitmap, bullet_x, bullet_y); // draw + } + draw_sprite(player_bitmap, player_x, 1); + draw_sprite(player_bitmap, player_x, 1); + if (bullet_y) { + byte leftover = xor_sprite(bullet_bitmap, bullet_x, bullet_y); // erase + if (leftover || bullet_y > 26) { + erase_sprite(bullet_bitmap, bullet_x, bullet_y); + check_bullet_hit(bullet_x, bullet_y+2); + bullet_y = 0; + } else { + bullet_y++; + xor_sprite(bullet_bitmap, bullet_x, bullet_y); // draw + } + } + update_next_entity(); + watchdog_strobe = 0; + } +} + +void clrscr() { + memset(vidmem, 0, sizeof(vidmem)); +} + +void main() { + // TODO: clear memory + clrscr(); + draw_string("PLAYER 1", 0, 31); + draw_string("PLAYER 2", 20, 31); + gameloop(); +} diff --git a/presets/vicdual/minimal.c b/presets/vicdual/minimal.c index 2cf44d3f..a3b8cb1e 100644 --- a/presets/vicdual/minimal.c +++ b/presets/vicdual/minimal.c @@ -10,6 +10,7 @@ byte __at (0xe800) tileram[256][8]; void main(); +// start routine @ 0x0 void start() { __asm LD SP,#0xE800 ; set up stack pointer @@ -18,17 +19,15 @@ __endasm; main(); } -#if start != 0x0 -#error start() function must be at address 0x0! -#endif - void main() { byte x,y; + palette = 1; memset(tileram, 0xfe, sizeof(tileram)); + memset(cellram, 0, sizeof(tileram)); for (y=0; y<32; y++) { for (x=0; x<32; x++) { - cellram[x][y] = y*8; + cellram[x][y] = (y<<3); } } while (1) ; diff --git a/presets/vicdual/snake1.c b/presets/vicdual/snake1.c new file mode 100644 index 00000000..e53777b4 --- /dev/null +++ b/presets/vicdual/snake1.c @@ -0,0 +1,212 @@ +#include + +typedef unsigned char byte; +typedef unsigned short word; + +// PLATFORM DEFINITION + +__sfr __at (0x0) input0; +__sfr __at (0x1) input1; +__sfr __at (0x2) input2; +__sfr __at (0x3) input3; + +__sfr __at (0x40) palette; + +byte __at (0xe000) cellram[32][32]; +byte __at (0xe800) tileram[256][8]; + +#define LEFT1 !(input1 & 0x10) +#define RIGHT1 !(input1 & 0x20) +#define UP1 !(input1 & 0x40) +#define DOWN1 !(input1 & 0x80) +#define FIRE1 !(input2 & 0x20) +#define COIN1 (input3 & 0x8) +#define START1 !(input2 & 0x10) +#define START2 !(input3 & 0x20) + +// GAME DATA + +typedef struct { + byte x; + byte y; + byte dir; + char head_attr; + char tail_attr; + char collided:1; +} Player; + +Player players[2]; + +#define FRAMES_PER_MOVE 10 + +// GAME CODE + +void main(); + +// start routine @ 0x0 +void start() { +__asm + LD SP,#0xE800 ; set up stack pointer + DI ; disable interrupts +__endasm; + main(); +} + +//////// + +void wait_for_vsync() { + while ((input1 & 0x8) != 0) ; // wait for VSYNC end + while ((input1 & 0x8) == 0) ; // wait for VSYNC start +} + +#define LOCHAR 0x0 +#define HICHAR 0xff +#define CHAR(ch) (ch-LOCHAR) + +void clrscr() { + memset(cellram, CHAR(' '), sizeof(cellram)); +} + +byte getchar(byte x, byte y) { + return cellram[x][y]; +} + +void putchar(byte x, byte y, byte attr) { + cellram[x][y] = attr; +} + +void putstring(byte x, byte y, const char* string) { + while (*string) { + putchar(x++, y, (*string++ - LOCHAR)); + } +} + +// PC font (code page 437) +const byte font8x8[0x100][8] = { +{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x7e,0x81,0x95,0xb1,0xb1,0x95,0x81,0x7e }, { 0x7e,0xff,0xeb,0xcf,0xcf,0xeb,0xff,0x7e }, { 0x0e,0x1f,0x3f,0x7e,0x3f,0x1f,0x0e,0x00 }, { 0x08,0x1c,0x3e,0x7f,0x3e,0x1c,0x08,0x00 }, { 0x38,0x3a,0x9f,0xff,0x9f,0x3a,0x38,0x00 }, { 0x10,0x38,0xbc,0xff,0xbc,0x38,0x10,0x00 }, { 0x00,0x00,0x18,0x3c,0x3c,0x18,0x00,0x00 }, { 0xff,0xff,0xe7,0xc3,0xc3,0xe7,0xff,0xff }, { 0x00,0x3c,0x66,0x42,0x42,0x66,0x3c,0x00 }, { 0xff,0xc3,0x99,0xbd,0xbd,0x99,0xc3,0xff }, { 0x70,0xf8,0x88,0x88,0xfd,0x7f,0x07,0x0f }, { 0x00,0x4e,0x5f,0xf1,0xf1,0x5f,0x4e,0x00 }, { 0xc0,0xe0,0xff,0x7f,0x05,0x05,0x07,0x07 }, { 0xc0,0xff,0x7f,0x05,0x05,0x65,0x7f,0x3f }, { 0x99,0x5a,0x3c,0xe7,0xe7,0x3c,0x5a,0x99 }, { 0x7f,0x3e,0x3e,0x1c,0x1c,0x08,0x08,0x00 }, { 0x08,0x08,0x1c,0x1c,0x3e,0x3e,0x7f,0x00 }, { 0x00,0x24,0x66,0xff,0xff,0x66,0x24,0x00 }, { 0x00,0x5f,0x5f,0x00,0x00,0x5f,0x5f,0x00 }, { 0x06,0x0f,0x09,0x7f,0x7f,0x01,0x7f,0x7f }, { 0xda,0xbf,0xa5,0xa5,0xfd,0x59,0x03,0x02 }, { 0x00,0x70,0x70,0x70,0x70,0x70,0x70,0x00 }, { 0x80,0x94,0xb6,0xff,0xff,0xb6,0x94,0x80 }, { 0x00,0x04,0x06,0x7f,0x7f,0x06,0x04,0x00 }, { 0x00,0x10,0x30,0x7f,0x7f,0x30,0x10,0x00 }, { 0x08,0x08,0x08,0x2a,0x3e,0x1c,0x08,0x00 }, { 0x08,0x1c,0x3e,0x2a,0x08,0x08,0x08,0x00 }, { 0x3c,0x3c,0x20,0x20,0x20,0x20,0x20,0x00 }, { 0x08,0x1c,0x3e,0x08,0x08,0x3e,0x1c,0x08 }, { 0x30,0x38,0x3c,0x3e,0x3e,0x3c,0x38,0x30 }, { 0x06,0x0e,0x1e,0x3e,0x3e,0x1e,0x0e,0x06 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x06,0x5f,0x5f,0x06,0x00,0x00,0x00 }, { 0x00,0x07,0x07,0x00,0x07,0x07,0x00,0x00 }, { 0x14,0x7f,0x7f,0x14,0x7f,0x7f,0x14,0x00 }, { 0x24,0x2e,0x6b,0x6b,0x3a,0x12,0x00,0x00 }, { 0x46,0x66,0x30,0x18,0x0c,0x66,0x62,0x00 }, { 0x30,0x7a,0x4f,0x5d,0x37,0x7a,0x48,0x00 }, { 0x04,0x07,0x03,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x1c,0x3e,0x63,0x41,0x00,0x00,0x00 }, { 0x00,0x41,0x63,0x3e,0x1c,0x00,0x00,0x00 }, { 0x08,0x2a,0x3e,0x1c,0x1c,0x3e,0x2a,0x08 }, { 0x08,0x08,0x3e,0x3e,0x08,0x08,0x00,0x00 }, { 0x00,0xa0,0xe0,0x60,0x00,0x00,0x00,0x00 }, { 0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00 }, { 0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00 }, { 0x60,0x30,0x18,0x0c,0x06,0x03,0x01,0x00 }, { 0x3e,0x7f,0x59,0x4d,0x7f,0x3e,0x00,0x00 }, { 0x42,0x42,0x7f,0x7f,0x40,0x40,0x00,0x00 }, { 0x62,0x73,0x59,0x49,0x6f,0x66,0x00,0x00 }, { 0x22,0x63,0x49,0x49,0x7f,0x36,0x00,0x00 }, { 0x18,0x1c,0x16,0x13,0x7f,0x7f,0x10,0x00 }, { 0x27,0x67,0x45,0x45,0x7d,0x39,0x00,0x00 }, { 0x3c,0x7e,0x4b,0x49,0x79,0x30,0x00,0x00 }, { 0x03,0x63,0x71,0x19,0x0f,0x07,0x00,0x00 }, { 0x36,0x7f,0x49,0x49,0x7f,0x36,0x00,0x00 }, { 0x06,0x4f,0x49,0x69,0x3f,0x1e,0x00,0x00 }, { 0x00,0x00,0x6c,0x6c,0x00,0x00,0x00,0x00 }, { 0x00,0xa0,0xec,0x6c,0x00,0x00,0x00,0x00 }, { 0x08,0x1c,0x36,0x63,0x41,0x00,0x00,0x00 }, { 0x14,0x14,0x14,0x14,0x14,0x14,0x00,0x00 }, { 0x00,0x41,0x63,0x36,0x1c,0x08,0x00,0x00 }, { 0x02,0x03,0x51,0x59,0x0f,0x06,0x00,0x00 }, { 0x3e,0x7f,0x41,0x5d,0x5d,0x1f,0x1e,0x00 }, { 0x7c,0x7e,0x13,0x13,0x7e,0x7c,0x00,0x00 }, { 0x41,0x7f,0x7f,0x49,0x49,0x7f,0x36,0x00 }, { 0x1c,0x3e,0x63,0x41,0x41,0x63,0x22,0x00 }, { 0x41,0x7f,0x7f,0x41,0x63,0x7f,0x1c,0x00 }, { 0x41,0x7f,0x7f,0x49,0x5d,0x41,0x63,0x00 }, { 0x41,0x7f,0x7f,0x49,0x1d,0x01,0x03,0x00 }, { 0x1c,0x3e,0x63,0x41,0x51,0x73,0x72,0x00 }, { 0x7f,0x7f,0x08,0x08,0x7f,0x7f,0x00,0x00 }, { 0x00,0x41,0x7f,0x7f,0x41,0x00,0x00,0x00 }, { 0x30,0x70,0x40,0x41,0x7f,0x3f,0x01,0x00 }, { 0x41,0x7f,0x7f,0x08,0x1c,0x77,0x63,0x00 }, { 0x41,0x7f,0x7f,0x41,0x40,0x60,0x70,0x00 }, { 0x7f,0x7f,0x06,0x0c,0x06,0x7f,0x7f,0x00 }, { 0x7f,0x7f,0x06,0x0c,0x18,0x7f,0x7f,0x00 }, { 0x1c,0x3e,0x63,0x41,0x63,0x3e,0x1c,0x00 }, { 0x41,0x7f,0x7f,0x49,0x09,0x0f,0x06,0x00 }, { 0x1e,0x3f,0x21,0x71,0x7f,0x5e,0x00,0x00 }, { 0x41,0x7f,0x7f,0x19,0x39,0x6f,0x46,0x00 }, { 0x26,0x67,0x4d,0x59,0x7b,0x32,0x00,0x00 }, { 0x03,0x41,0x7f,0x7f,0x41,0x03,0x00,0x00 }, { 0x7f,0x7f,0x40,0x40,0x7f,0x7f,0x00,0x00 }, { 0x1f,0x3f,0x60,0x60,0x3f,0x1f,0x00,0x00 }, { 0x7f,0x7f,0x30,0x18,0x30,0x7f,0x7f,0x00 }, { 0x63,0x77,0x1c,0x08,0x1c,0x77,0x63,0x00 }, { 0x07,0x4f,0x78,0x78,0x4f,0x07,0x00,0x00 }, { 0x67,0x73,0x59,0x4d,0x47,0x63,0x71,0x00 }, { 0x00,0x7f,0x7f,0x41,0x41,0x00,0x00,0x00 }, { 0x01,0x03,0x06,0x0c,0x18,0x30,0x60,0x00 }, { 0x00,0x41,0x41,0x7f,0x7f,0x00,0x00,0x00 }, { 0x08,0x0c,0x06,0x03,0x06,0x0c,0x08,0x00 }, { 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80 }, { 0x00,0x00,0x03,0x07,0x04,0x00,0x00,0x00 }, { 0x20,0x74,0x54,0x54,0x3c,0x78,0x40,0x00 }, { 0x41,0x3f,0x7f,0x44,0x44,0x7c,0x38,0x00 }, { 0x38,0x7c,0x44,0x44,0x6c,0x28,0x00,0x00 }, { 0x30,0x78,0x48,0x49,0x3f,0x7f,0x40,0x00 }, { 0x38,0x7c,0x54,0x54,0x5c,0x18,0x00,0x00 }, { 0x48,0x7e,0x7f,0x49,0x03,0x02,0x00,0x00 }, { 0x98,0xbc,0xa4,0xa4,0xf8,0x7c,0x04,0x00 }, { 0x41,0x7f,0x7f,0x08,0x04,0x7c,0x78,0x00 }, { 0x00,0x44,0x7d,0x7d,0x40,0x00,0x00,0x00 }, { 0x40,0xc4,0x84,0xfd,0x7d,0x00,0x00,0x00 }, { 0x41,0x7f,0x7f,0x10,0x38,0x6c,0x44,0x00 }, { 0x00,0x41,0x7f,0x7f,0x40,0x00,0x00,0x00 }, { 0x7c,0x7c,0x0c,0x18,0x0c,0x7c,0x78,0x00 }, { 0x7c,0x7c,0x04,0x04,0x7c,0x78,0x00,0x00 }, { 0x38,0x7c,0x44,0x44,0x7c,0x38,0x00,0x00 }, { 0x84,0xfc,0xf8,0xa4,0x24,0x3c,0x18,0x00 }, { 0x18,0x3c,0x24,0xa4,0xf8,0xfc,0x84,0x00 }, { 0x44,0x7c,0x78,0x44,0x1c,0x18,0x00,0x00 }, { 0x48,0x5c,0x54,0x54,0x74,0x24,0x00,0x00 }, { 0x00,0x04,0x3e,0x7f,0x44,0x24,0x00,0x00 }, { 0x3c,0x7c,0x40,0x40,0x3c,0x7c,0x40,0x00 }, { 0x1c,0x3c,0x60,0x60,0x3c,0x1c,0x00,0x00 }, { 0x3c,0x7c,0x60,0x30,0x60,0x7c,0x3c,0x00 }, { 0x44,0x6c,0x38,0x10,0x38,0x6c,0x44,0x00 }, { 0x9c,0xbc,0xa0,0xa0,0xfc,0x7c,0x00,0x00 }, { 0x4c,0x64,0x74,0x5c,0x4c,0x64,0x00,0x00 }, { 0x08,0x08,0x3e,0x77,0x41,0x41,0x00,0x00 }, { 0x00,0x00,0x00,0x77,0x77,0x00,0x00,0x00 }, { 0x41,0x41,0x77,0x3e,0x08,0x08,0x00,0x00 }, { 0x02,0x03,0x01,0x03,0x02,0x03,0x01,0x00 }, { 0x78,0x7c,0x46,0x43,0x46,0x7c,0x78,0x00 }, { 0x0e,0x9f,0x91,0xb1,0xfb,0x4a,0x00,0x00 }, { 0x3a,0x7a,0x40,0x40,0x7a,0x7a,0x40,0x00 }, { 0x38,0x7c,0x54,0x55,0x5d,0x19,0x00,0x00 }, { 0x02,0x23,0x75,0x55,0x55,0x7d,0x7b,0x42 }, { 0x21,0x75,0x54,0x54,0x7d,0x79,0x40,0x00 }, { 0x21,0x75,0x55,0x54,0x7c,0x78,0x40,0x00 }, { 0x20,0x74,0x57,0x57,0x7c,0x78,0x40,0x00 }, { 0x18,0x3c,0xa4,0xa4,0xa4,0xe4,0x40,0x00 }, { 0x02,0x3b,0x7d,0x55,0x55,0x5d,0x1b,0x02 }, { 0x39,0x7d,0x54,0x54,0x5d,0x19,0x00,0x00 }, { 0x39,0x7d,0x55,0x54,0x5c,0x18,0x00,0x00 }, { 0x01,0x45,0x7c,0x7c,0x41,0x01,0x00,0x00 }, { 0x02,0x03,0x45,0x7d,0x7d,0x43,0x02,0x00 }, { 0x01,0x45,0x7d,0x7c,0x40,0x00,0x00,0x00 }, { 0x79,0x7d,0x26,0x26,0x7d,0x79,0x00,0x00 }, { 0x70,0x78,0x2b,0x2b,0x78,0x70,0x00,0x00 }, { 0x44,0x7c,0x7c,0x55,0x55,0x45,0x00,0x00 }, { 0x20,0x74,0x54,0x54,0x7c,0x7c,0x54,0x54 }, { 0x7c,0x7e,0x0b,0x09,0x7f,0x7f,0x49,0x00 }, { 0x32,0x7b,0x49,0x49,0x7b,0x32,0x00,0x00 }, { 0x32,0x7a,0x48,0x48,0x7a,0x32,0x00,0x00 }, { 0x32,0x7a,0x4a,0x48,0x78,0x30,0x00,0x00 }, { 0x3a,0x7b,0x41,0x41,0x7b,0x7a,0x40,0x00 }, { 0x3a,0x7a,0x42,0x40,0x78,0x78,0x40,0x00 }, { 0xba,0xba,0xa0,0xa0,0xfa,0x7a,0x00,0x00 }, { 0x19,0x3d,0x66,0x66,0x66,0x3d,0x19,0x00 }, { 0x3d,0x7d,0x40,0x40,0x7d,0x3d,0x00,0x00 }, { 0x18,0x3c,0x24,0xe7,0xe7,0x24,0x24,0x00 }, { 0x68,0x7e,0x7f,0x49,0x43,0x66,0x20,0x00 }, { 0x2b,0x2f,0x7c,0x7c,0x2f,0x2b,0x00,0x00 }, { 0x7f,0x7f,0x09,0x2f,0xf6,0xf8,0xa0,0x00 }, { 0x40,0xc8,0x88,0xfe,0x7f,0x09,0x0b,0x02 }, { 0x20,0x74,0x54,0x55,0x7d,0x79,0x40,0x00 }, { 0x00,0x44,0x7d,0x7d,0x41,0x00,0x00,0x00 }, { 0x30,0x78,0x48,0x4a,0x7a,0x32,0x00,0x00 }, { 0x38,0x78,0x40,0x42,0x7a,0x7a,0x40,0x00 }, { 0x7a,0x7a,0x0a,0x0a,0x7a,0x70,0x00,0x00 }, { 0x7d,0x7d,0x19,0x31,0x7d,0x7d,0x00,0x00 }, { 0x00,0x26,0x2f,0x29,0x2f,0x2f,0x28,0x00 }, { 0x00,0x26,0x2f,0x29,0x29,0x2f,0x26,0x00 }, { 0x30,0x78,0x4d,0x45,0x60,0x20,0x00,0x00 }, { 0x38,0x38,0x08,0x08,0x08,0x08,0x00,0x00 }, { 0x08,0x08,0x08,0x08,0x38,0x38,0x00,0x00 }, { 0x67,0x37,0x18,0xcc,0xee,0xab,0xb9,0x90 }, { 0x6f,0x3f,0x18,0x4c,0x66,0x73,0xf9,0xf8 }, { 0x00,0x00,0x60,0xfa,0xfa,0x60,0x00,0x00 }, { 0x08,0x1c,0x36,0x22,0x08,0x1c,0x36,0x22 }, { 0x22,0x36,0x1c,0x08,0x22,0x36,0x1c,0x08 }, { 0xaa,0x00,0x55,0x00,0xaa,0x00,0x55,0x00 }, { 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55 }, { 0x55,0xff,0xaa,0xff,0x55,0xff,0xaa,0xff }, { 0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x00 }, { 0x10,0x10,0x10,0xff,0xff,0x00,0x00,0x00 }, { 0x14,0x14,0x14,0xff,0xff,0x00,0x00,0x00 }, { 0x10,0x10,0xff,0xff,0x00,0xff,0xff,0x00 }, { 0x10,0x10,0xf0,0xf0,0x10,0xf0,0xf0,0x00 }, { 0x14,0x14,0x14,0xfc,0xfc,0x00,0x00,0x00 }, { 0x14,0x14,0xf7,0xf7,0x00,0xff,0xff,0x00 }, { 0x00,0x00,0xff,0xff,0x00,0xff,0xff,0x00 }, { 0x14,0x14,0xf4,0xf4,0x04,0xfc,0xfc,0x00 }, { 0x14,0x14,0x17,0x17,0x10,0x1f,0x1f,0x00 }, { 0x10,0x10,0x1f,0x1f,0x10,0x1f,0x1f,0x00 }, { 0x14,0x14,0x14,0x1f,0x1f,0x00,0x00,0x00 }, { 0x10,0x10,0x10,0xf0,0xf0,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x1f,0x1f,0x10,0x10,0x10 }, { 0x10,0x10,0x10,0x1f,0x1f,0x10,0x10,0x10 }, { 0x10,0x10,0x10,0xf0,0xf0,0x10,0x10,0x10 }, { 0x00,0x00,0x00,0xff,0xff,0x10,0x10,0x10 }, { 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10 }, { 0x10,0x10,0x10,0xff,0xff,0x10,0x10,0x10 }, { 0x00,0x00,0x00,0xff,0xff,0x14,0x14,0x14 }, { 0x00,0x00,0xff,0xff,0x00,0xff,0xff,0x10 }, { 0x00,0x00,0x1f,0x1f,0x10,0x17,0x17,0x14 }, { 0x00,0x00,0xfc,0xfc,0x04,0xf4,0xf4,0x14 }, { 0x14,0x14,0x17,0x17,0x10,0x17,0x17,0x14 }, { 0x14,0x14,0xf4,0xf4,0x04,0xf4,0xf4,0x14 }, { 0x00,0x00,0xff,0xff,0x00,0xf7,0xf7,0x14 }, { 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14 }, { 0x14,0x14,0xf7,0xf7,0x00,0xf7,0xf7,0x14 }, { 0x14,0x14,0x14,0x17,0x17,0x14,0x14,0x14 }, { 0x10,0x10,0x1f,0x1f,0x10,0x1f,0x1f,0x10 }, { 0x14,0x14,0x14,0xf4,0xf4,0x14,0x14,0x14 }, { 0x10,0x10,0xf0,0xf0,0x10,0xf0,0xf0,0x10 }, { 0x00,0x00,0x1f,0x1f,0x10,0x1f,0x1f,0x10 }, { 0x00,0x00,0x00,0x1f,0x1f,0x14,0x14,0x14 }, { 0x00,0x00,0x00,0xfc,0xfc,0x14,0x14,0x14 }, { 0x00,0x00,0xf0,0xf0,0x10,0xf0,0xf0,0x10 }, { 0x10,0x10,0xff,0xff,0x00,0xff,0xff,0x10 }, { 0x14,0x14,0x14,0xf7,0xf7,0x14,0x14,0x14 }, { 0x10,0x10,0x10,0x1f,0x1f,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0xf0,0xf0,0x10,0x10,0x10 }, { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, { 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0 }, { 0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff }, { 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f }, { 0x38,0x7c,0x44,0x6c,0x38,0x6c,0x44,0x00 }, { 0xfc,0xfe,0x2a,0x2a,0x3e,0x14,0x00,0x00 }, { 0x7e,0x7e,0x02,0x02,0x02,0x06,0x06,0x00 }, { 0x02,0x7e,0x7e,0x02,0x7e,0x7e,0x02,0x00 }, { 0x41,0x63,0x77,0x5d,0x49,0x63,0x63,0x00 }, { 0x38,0x7c,0x44,0x44,0x7c,0x3c,0x04,0x00 }, { 0x80,0xfe,0x7e,0x20,0x20,0x3e,0x1e,0x00 }, { 0x04,0x06,0x02,0x7e,0x7c,0x06,0x02,0x00 }, { 0x99,0xbd,0xe7,0xe7,0xbd,0x99,0x00,0x00 }, { 0x1c,0x3e,0x6b,0x49,0x6b,0x3e,0x1c,0x00 }, { 0x4c,0x7e,0x73,0x01,0x73,0x7e,0x4c,0x00 }, { 0x30,0x78,0x4a,0x4f,0x7d,0x39,0x00,0x00 }, { 0x18,0x3c,0x24,0x3c,0x3c,0x24,0x3c,0x18 }, { 0x98,0xfc,0x64,0x3c,0x3e,0x27,0x3d,0x18 }, { 0x1c,0x3e,0x6b,0x49,0x49,0x49,0x00,0x00 }, { 0x7e,0x7f,0x01,0x01,0x7f,0x7e,0x00,0x00 }, { 0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x00,0x00 }, { 0x44,0x44,0x5f,0x5f,0x44,0x44,0x00,0x00 }, { 0x40,0x51,0x5b,0x4e,0x44,0x40,0x00,0x00 }, { 0x40,0x44,0x4e,0x5b,0x51,0x40,0x00,0x00 }, { 0x00,0x00,0x00,0xfe,0xff,0x01,0x07,0x06 }, { 0x60,0xe0,0x80,0xff,0x7f,0x00,0x00,0x00 }, { 0x08,0x08,0x6b,0x6b,0x08,0x08,0x00,0x00 }, { 0x24,0x12,0x12,0x36,0x24,0x24,0x12,0x00 }, { 0x00,0x06,0x0f,0x09,0x0f,0x06,0x00,0x00 }, { 0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x10,0x10,0x00,0x00,0x00 }, { 0x10,0x30,0x70,0xc0,0xff,0xff,0x01,0x01 }, { 0x00,0x1f,0x1f,0x01,0x1f,0x1e,0x00,0x00 }, { 0x00,0x19,0x1d,0x15,0x17,0x12,0x00,0x00 }, { 0x00,0x00,0x3c,0x3c,0x3c,0x3c,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } +}; + +const char BOX_CHARS[8] = { 218, 191, 192, 217, 196, 196, 179, 179 }; + +void draw_box(byte x, byte y, byte x2, byte y2, const char* chars) { + byte x1 = x; + putchar(x, y, chars[2]); + putchar(x2, y, chars[3]); + putchar(x, y2, chars[0]); + putchar(x2, y2, chars[1]); + while (++x < x2) { + putchar(x, y, chars[5]); + putchar(x, y2, chars[4]); + } + while (++y < y2) { + putchar(x1, y, chars[6]); + putchar(x2, y, chars[7]); + } +} + +void draw_playfield() { + draw_box(0,0,27,29,BOX_CHARS); +} + +typedef enum { D_RIGHT, D_DOWN, D_LEFT, D_UP } dir_t; +const char DIR_X[4] = { 1, 0, -1, 0 }; +const char DIR_Y[4] = { 0, -1, 0, 1 }; + +void init_game() { + memset(players, 0, sizeof(players)); + players[0].head_attr = CHAR('1'); + players[1].head_attr = CHAR('2'); + players[0].tail_attr = 254; + players[1].tail_attr = 254; +} + +void reset_players() { + players[0].x = players[0].y = 6; + players[0].dir = D_RIGHT; + players[1].x = players[1].y = 21; + players[1].dir = D_LEFT; + players[0].collided = players[1].collided = 0; +} + +void draw_player(Player* p) { + putchar(p->x, p->y, p->head_attr); +} + +void move_player(Player* p) { + putchar(p->x, p->y, p->tail_attr); + p->x += DIR_X[p->dir]; + p->y += DIR_Y[p->dir]; + if (getchar(p->x, p->y) != CHAR(' ')) + p->collided = 1; + draw_player(p); +} + +void human_control(Player* p) { + byte dir = 0xff; + if (LEFT1) dir = D_LEFT; + if (RIGHT1) dir = D_RIGHT; + if (UP1) dir = D_UP; + if (DOWN1) dir = D_DOWN; + // don't let the player reverse + if (dir < 0x80 && dir != (p->dir ^ 2)) { + p->dir = dir; + } +} + +void ai_control(Player* p) { + byte x,y; + dir_t dir = p->dir; + x = p->x + DIR_X[dir]; + y = p->y + DIR_Y[dir]; + if (getchar(x,y) != CHAR(' ')) { + p->dir = (dir + 1) & 3; + } +} + +void flash_colliders() { + byte i; + // flash players that collided + for (i=0; i<60; i++) { + if (players[0].collided) players[0].head_attr ^= 0x80; + if (players[1].collided) players[1].head_attr ^= 0x80; + wait_for_vsync(); + wait_for_vsync(); + draw_player(&players[0]); + draw_player(&players[1]); + palette = i; + } + palette = 0; +} + +void make_move() { + byte i; + for (i=0; i>4)&0xf)), x, y); -} - -void draw_bcd_word2(byte x, byte y, word bcd) { - draw_bcd_byte(x+2, y, bcd); - draw_bcd_byte(x, y, bcd>>8); -} -*/ - void draw_playfield() { draw_box(0,0,27,29,BOX_CHARS); putstring(0,31,"PLAYER 1"); diff --git a/src/platform/mw8080bw.js b/src/platform/mw8080bw.js index 5362aed1..422a0506 100644 --- a/src/platform/mw8080bw.js +++ b/src/platform/mw8080bw.js @@ -3,6 +3,7 @@ // http://www.computerarcheology.com/Arcade/ var MW8080BW_PRESETS = [ + {id:'game2.c', name:'Game #2'}, ]; var Midway8080BWPlatform = function(mainElement) { diff --git a/src/platform/vicdual.js b/src/platform/vicdual.js index 10c4d9fb..0dd5d63d 100644 --- a/src/platform/vicdual.js +++ b/src/platform/vicdual.js @@ -5,7 +5,8 @@ var VICDUAL_PRESETS = [ {id:'hello.c', name:'Hello World'}, {id:'gfxtest.c', name:'Graphics Test'}, {id:'soundtest.c', name:'Sound Test'}, - {id:'snake.c', name:'Snake Game'}, + {id:'snake1.c', name:'Snake Game #1'}, + {id:'snake2.c', name:'Snake Game #2'}, ]; var VicDualPlatform = function(mainElement) { diff --git a/src/ui.js b/src/ui.js index 551d1a62..af19811e 100644 --- a/src/ui.js +++ b/src/ui.js @@ -541,9 +541,9 @@ function getCurrentLine() { function getDisasmViewPC() { var line = disasmview.getCursor().line; - if (line) { + if (line >= 0) { var toks = disasmview.getLine(line).split(/\s+/); - if (toks) { + if (toks && toks[0].length == 4) { return parseInt(toks[0], 16); } } @@ -551,11 +551,12 @@ function getDisasmViewPC() { function getCurrentPC() { var line = getCurrentLine(); - var pc = sourcefile.line2offset[line]; - if (!(pc >= 0)) { - return getDisasmViewPC(); + while (line >= 0) { + var pc = sourcefile.line2offset[line]; + if (pc >= 0) return pc; + line--; } - return pc; + return getDisasmViewPC(); } function runToCursor() {