added midway presets; williams sprites; fixed 2x compile bug

This commit is contained in:
Steven Hugg 2017-04-04 14:19:47 -04:00
parent 03a5745bb5
commit fdc40fc553
6 changed files with 369 additions and 45 deletions

View File

@ -88,9 +88,6 @@ 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}
;
@ -101,8 +98,20 @@ 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}
;
{2,17,0x00,0x00,0x00,0x0c,0x04,0x1e,0x46,0x3f,0xb8,0x7f,0xb0,0x7f,0xba,0x7f,0xfd,0x3f,0xfc,0x07,0xfc,0x07,0xfd,0x3f,0xba,0x7f,0xb0,0x7f,0xb8,0x7f,0x46,0x3f,0x04,0x1e,0x00,0x0c};
const byte enemy2_bitmap[] =
{2,16,0x26,0x00,0x59,0x10,0x10,0x30,0x33,0x18,0xe6,0x61,0xc4,0x56,0x03,0x03,0xdc,0x03,0xdc,0x03,0x03,0x03,0xc4,0x56,0xe6,0x61,0x33,0x18,0x10,0x30,0x59,0x10,0x26,0x00};
const byte enemy3_bitmap[] =
{2,16,0x80,0x1f,0xc0,0x03,0xf8,0x3f,0x70,0x00,0xf0,0x01,0xfc,0x07,0xe8,0x01,0xf8,0x03,0xf8,0x03,0xe8,0x01,0xf8,0x07,0xf0,0x01,0x70,0x00,0xf8,0x3f,0xc0,0x03,0x80,0x1f};
const byte enemy4_bitmap[] =
{2,16,0x06,0x00,0x0c,0x00,0x28,0x00,0x70,0x1f,0x84,0x3f,0xde,0x37,0xbb,0x3f,0xf0,0x3f,0xf0,0x3f,0xbb,0x3f,0xde,0x37,0x84,0x3f,0x70,0x1f,0x28,0x00,0x0c,0x00,0x06,0x00};
const byte* const enemy_bitmaps[4] = {
enemy1_bitmap,
enemy2_bitmap,
enemy3_bitmap,
enemy4_bitmap
};
void draw_sprite(const byte* src, byte x, byte y) {
byte i,j;
@ -188,18 +197,20 @@ typedef struct {
MarchMode this_mode, next_mode;
void init_entities() {
int i,x,y;
byte i,x,y,bm;
x=0;
y=26;
bm=0;
for (i=0; i<MAX_ENTITIES; i++) {
Entity* e = &entities[i];
e->x = x;
e->y = y;
e->shape = enemy1_bitmap;
e->shape = enemy_bitmaps[bm];
x += 28;
if (x > 180) {
x = 0;
y -= 3;
bm++;
}
}
num_entities = MAX_ENTITIES;
@ -284,9 +295,7 @@ void gameloop() {
watchdog_strobe = 0b0111 / 14;
draw_bunker(30, 40, 15, 15, 20);
draw_bunker(120, 40, 15, 15, 20);
draw_sprite(enemy1_bitmap, 10, 20);
init_entities();
//draw_sprite(bitmap1, 0, 0);
player_x = 96;
while (1) {
if (LEFT1 && player_x>0) player_x -= 2;

View File

@ -0,0 +1,86 @@
#include <string.h>
typedef unsigned char byte;
typedef unsigned short word;
typedef signed char sbyte;
const __sfr __at (0x0) command;
__sfr __at (0x0) dac;
#define HALT __asm halt __endasm;
// press "2" or higher to activate...
typedef struct {
word duration;
word offset;
word delta;
int deltainc;
byte wavetable;
signed char lfo;
} SoundEffect;
const char WAVES[] = {
-64,-64,-64,-64,-64,-64,-64,
-64,-64,-64,-64,-64,-64,-64,
64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,
-64,64,-64,64,-64,64,-64,64,
-64,64,-64,64,-64,64,-64,64,
-64,64,-64,64,-64,64,-64,64,
-64,64,-64,64,-64,64,-64,64,
-0x80,-0x78,-0x70,-0x68, -0x60,-0x58,-0x50,-0x48,
-0x40,-0x38,-0x30,-0x28, -0x20,-0x18,-0x10,-0x08,
0x00,0x08,0x10,0x18, 0x20,0x28,0x30,0x38,
0x40,0x48,0x50,0x58, 0x60,0x68,0x70,0x78,
0x60,0x37,0x3f,0x5c,0x16,0xca,0xc2,0xa5,0xfe,0xba,0x77,0x89,0xaa,0x77,0x13,0xd8,
0xae,0x82,0xfd,0x22,0x9c,0x46,0xde,0x14,0x50,0xb4,0x97,0x46,0x54,0x9d,0x60,0x2b,
};
const sbyte* wav;
SoundEffect e;
const SoundEffect DEFAULT_SOUND = {
2000, 0, 3000, -1, 0x40, 0
};
void play();
void main() {
if (command == 0) HALT;
memcpy(&e, &DEFAULT_SOUND, sizeof(e));
play();
/*
char i;
char j;
for (i=0; i<255; i++) {
for (j=0; j<i; j++) dac=j^i;
}
*/
HALT;
}
void sample() {
dac = wav[(e.offset >> 11) & 0x1f];
e.offset += e.delta;
}
void play() {
wav = &WAVES[e.wavetable];
while (e.duration--) {
sample();
sample();
sample();
sample();
sample();
sample();
sample();
sample();
e.delta += e.deltainc;
e.deltainc += e.lfo;
}
}

View File

@ -5,11 +5,11 @@ typedef unsigned char byte;
typedef unsigned short word;
byte __at (0xc000) palette[16];
volatile byte __at (0xc800) input0;
volatile byte __at (0xc802) input1;
volatile byte __at (0xc804) input2;
byte __at (0xc800) input0;
byte __at (0xc802) input1;
byte __at (0xc804) input2;
byte __at (0xc900) rom_select;
volatile byte __at (0xcb00) video_counter;
byte __at (0xcb00) video_counter;
byte __at (0xcbff) watchdog0x39;
byte __at (0xcc00) nvram[0x400];
@ -42,15 +42,53 @@ void start() {
__asm
LD SP,#0xc000
DI
; copy initialized data
LD BC, #l__INITIALIZER
LD A, B
LD DE, #s__INITIALIZED
LD HL, #s__INITIALIZER
LDIR
__endasm;
main();
}
const byte palette_data[16] = {
0x00, 0x03, 0x19, 0x50, 0x52, 0x07, 0x1f, 0x37, 0xe0, 0xa4, 0xfd, 0xff, 0x00, 0x00, 0x00, 0x00, };
#define LOCHAR 0x21
#define HICHAR 0x5e
const byte sprite_data[] = {
8,128,
const byte font8x8[HICHAR-LOCHAR+1][8] = {
{ 0x18,0x18,0x18,0x18,0x00,0x00,0x18,0x00 }, { 0x66,0x66,0x66,0x00,0x00,0x00,0x00,0x00 }, { 0x66,0x66,0xff,0x66,0xff,0x66,0x66,0x00 }, { 0x18,0x3e,0x60,0x3c,0x06,0x7c,0x18,0x00 }, { 0x62,0x66,0x0c,0x18,0x30,0x66,0x46,0x00 }, { 0x3c,0x66,0x3c,0x38,0x67,0x66,0x3f,0x00 }, { 0x06,0x0c,0x18,0x00,0x00,0x00,0x00,0x00 }, { 0x0c,0x18,0x30,0x30,0x30,0x18,0x0c,0x00 }, { 0x30,0x18,0x0c,0x0c,0x0c,0x18,0x30,0x00 }, { 0x00,0x66,0x3c,0xff,0x3c,0x66,0x00,0x00 }, { 0x00,0x18,0x18,0x7e,0x18,0x18,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30 }, { 0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00 }, { 0x00,0x03,0x06,0x0c,0x18,0x30,0x60,0x00 }, { 0x3c,0x66,0x6e,0x76,0x66,0x66,0x3c,0x00 }, { 0x18,0x18,0x38,0x18,0x18,0x18,0x7e,0x00 }, { 0x3c,0x66,0x06,0x0c,0x30,0x60,0x7e,0x00 }, { 0x3c,0x66,0x06,0x1c,0x06,0x66,0x3c,0x00 }, { 0x06,0x0e,0x1e,0x66,0x7f,0x06,0x06,0x00 }, { 0x7e,0x60,0x7c,0x06,0x06,0x66,0x3c,0x00 }, { 0x3c,0x66,0x60,0x7c,0x66,0x66,0x3c,0x00 }, { 0x7e,0x66,0x0c,0x18,0x18,0x18,0x18,0x00 }, { 0x3c,0x66,0x66,0x3c,0x66,0x66,0x3c,0x00 }, { 0x3c,0x66,0x66,0x3e,0x06,0x66,0x3c,0x00 }, { 0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00 }, { 0x00,0x00,0x18,0x00,0x00,0x18,0x18,0x30 }, { 0x0e,0x18,0x30,0x60,0x30,0x18,0x0e,0x00 }, { 0x00,0x00,0x7e,0x00,0x7e,0x00,0x00,0x00 }, { 0x70,0x18,0x0c,0x06,0x0c,0x18,0x70,0x00 }, { 0x3c,0x66,0x06,0x0c,0x18,0x00,0x18,0x00 }, { 0x3c,0x66,0x6e,0x6e,0x60,0x62,0x3c,0x00 }, { 0x18,0x3c,0x66,0x7e,0x66,0x66,0x66,0x00 }, { 0x7c,0x66,0x66,0x7c,0x66,0x66,0x7c,0x00 }, { 0x3c,0x66,0x60,0x60,0x60,0x66,0x3c,0x00 }, { 0x78,0x6c,0x66,0x66,0x66,0x6c,0x78,0x00 }, { 0x7e,0x60,0x60,0x78,0x60,0x60,0x7e,0x00 }, { 0x7e,0x60,0x60,0x78,0x60,0x60,0x60,0x00 }, { 0x3c,0x66,0x60,0x6e,0x66,0x66,0x3c,0x00 }, { 0x66,0x66,0x66,0x7e,0x66,0x66,0x66,0x00 }, { 0x3c,0x18,0x18,0x18,0x18,0x18,0x3c,0x00 }, { 0x1e,0x0c,0x0c,0x0c,0x0c,0x6c,0x38,0x00 }, { 0x66,0x6c,0x78,0x70,0x78,0x6c,0x66,0x00 }, { 0x60,0x60,0x60,0x60,0x60,0x60,0x7e,0x00 }, { 0x63,0x77,0x7f,0x6b,0x63,0x63,0x63,0x00 }, { 0x66,0x76,0x7e,0x7e,0x6e,0x66,0x66,0x00 }, { 0x3c,0x66,0x66,0x66,0x66,0x66,0x3c,0x00 }, { 0x7c,0x66,0x66,0x7c,0x60,0x60,0x60,0x00 }, { 0x3c,0x66,0x66,0x66,0x66,0x3c,0x0e,0x00 }, { 0x7c,0x66,0x66,0x7c,0x78,0x6c,0x66,0x00 }, { 0x3c,0x66,0x60,0x3c,0x06,0x66,0x3c,0x00 }, { 0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x00 }, { 0x66,0x66,0x66,0x66,0x66,0x66,0x3c,0x00 }, { 0x66,0x66,0x66,0x66,0x66,0x3c,0x18,0x00 }, { 0x63,0x63,0x63,0x6b,0x7f,0x77,0x63,0x00 }, { 0x66,0x66,0x3c,0x18,0x3c,0x66,0x66,0x00 }, { 0x66,0x66,0x66,0x3c,0x18,0x18,0x18,0x00 }, { 0x7e,0x06,0x0c,0x18,0x30,0x60,0x7e,0x00 }, { 0x3c,0x30,0x30,0x30,0x30,0x30,0x3c,0x00 }, { 0x00,0x60,0x30,0x18,0x0c,0x06,0x03,0x00 }, { 0x3c,0x0c,0x0c,0x0c,0x0c,0x0c,0x3c,0x00 }, { 0x00,0x18,0x3c,0x7e,0x18,0x18,0x18,0x18 }
};
static byte font_table[HICHAR-LOCHAR+1][8*4];
void fill_char_table_entry(char ch) {
const byte* src = &font8x8[ch-LOCHAR][0];
byte* data = &font_table[ch-LOCHAR][0];
int i,j,pixels;
for (i=0; i<8; i++) {
byte b = *src++;
for (j=0; j<4; j++) {
pixels = 0;
if (b & 0x80) pixels |= 0xf0;
if (b & 0x40) pixels |= 0x0f;
*data++ = pixels;
b <<= 2;
}
}
}
void fill_char_table() {
char ch;
for (ch=LOCHAR; ch<=HICHAR; ch++) {
fill_char_table_entry(ch);
}
}
const byte palette_data[16] = {
0x00, 0x03, 0x19, 0x50, 0x52, 0x07, 0x1f, 0x37, 0xe0, 0xa4, 0xfd, 0xff, 0x00, 0x00, 0x00, 0xf8, };
const byte sprite1[2+16*16/2] = {
8,16,
0x00,0x09,0x99,0x00,0x00,0x99,0x90,0x00,
0x00,0x94,0x94,0x90,0x09,0x49,0x49,0x00,
0x04,0x49,0x49,0x90,0x09,0x94,0x94,0x90,
@ -66,7 +104,30 @@ const byte sprite_data[] = {
0x03,0x30,0x00,0x33,0x33,0x00,0x03,0x30,
0x00,0x30,0x03,0x00,0x00,0x30,0x03,0x00,
0x00,0x00,0x00,0x30,0x03,0x00,0x00,0x00,
0x00,0x09,0x99,0x00,0x00,0x99,0x90,0x00,
};
const byte sprite2[2+16*16/2] = {
8,16,
0x00,0x94,0x94,0x90,0x09,0x49,0x49,0x00,
0x04,0x49,0x49,0x90,0x09,0x94,0x94,0x90,
0x94,0x99,0x94,0x90,0x09,0x49,0x99,0x49,
0x99,0x99,0x49,0x93,0x39,0x94,0x99,0x99,
0x04,0x49,0x99,0x94,0x49,0x99,0x94,0x90,
0x00,0x94,0x94,0x43,0x34,0x49,0x49,0x00,
0x00,0x09,0x43,0x94,0x49,0x34,0x90,0x00,
0x00,0x90,0x00,0x39,0x93,0x00,0x09,0x00,
0x00,0x09,0x83,0x33,0x33,0x33,0x90,0x00,
0x00,0x09,0x32,0x23,0x32,0x23,0x90,0x00,
0x00,0x03,0x03,0x23,0x82,0x30,0x30,0x00,
0x03,0x30,0x00,0x33,0x33,0x00,0x03,0x30,
0x00,0x30,0x03,0x00,0x00,0x30,0x03,0x00,
0x00,0x00,0x00,0x30,0x03,0x00,0x00,0x00,
0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
};
const byte sprite3[2+16*16/2] = {
8,16,
0x00,0x00,0x00,0x01,0x10,0x00,0x00,0x00,
0x00,0x00,0x00,0x11,0x11,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x10,0x00,0x00,0x00,
@ -83,6 +144,10 @@ const byte sprite_data[] = {
0x00,0x10,0x01,0x00,0x00,0x10,0x01,0x00,
0x00,0x10,0x00,0x00,0x00,0x00,0x01,0x00,
0x00,0x01,0x10,0x00,0x00,0x01,0x10,0x00,
};
const byte sprite4[2+16*16/2] = {
8,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xbb,0xbb,0x00,0x00,0x00,
0x00,0x00,0x00,0xbb,0xbb,0x00,0x00,0x00,
@ -99,6 +164,10 @@ const byte sprite_data[] = {
0x01,0x00,0x01,0x51,0x15,0x10,0x00,0x10,
0x00,0x10,0x01,0x10,0x01,0x10,0x01,0x00,
0x01,0x01,0x10,0x10,0x01,0x01,0x10,0x10,
};
const byte sprite5[2+16*16/2] = {
8,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x22,0x00,0x00,0x22,0x00,0x00,
0x00,0x20,0x20,0x00,0x00,0x02,0x02,0x00,
@ -115,10 +184,10 @@ const byte sprite_data[] = {
0x20,0x00,0x22,0x12,0x21,0x22,0x00,0x02,
0x20,0x02,0x20,0x20,0x02,0x02,0x20,0x02,
0x02,0x02,0x00,0x20,0x02,0x00,0x20,0x20,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const byte sprite6[2+12*16/2] = {
8,12,
0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x00,
0x00,0x00,0x00,0x00,0x44,0x44,0x44,0x40,
0x00,0x00,0x04,0x04,0x49,0x49,0x99,0x44,
@ -129,9 +198,10 @@ const byte sprite_data[] = {
0x04,0x44,0x00,0x49,0x44,0x40,0x00,0x00,
0x04,0x40,0x00,0x04,0x00,0x00,0x00,0x00,
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const byte sprite7[2+16*16/2] = {
8,16,
0x00,0x60,0x00,0x00,0x00,0x00,0x06,0x00,
0x60,0x60,0x00,0x00,0x00,0x00,0x06,0x06,
0x60,0x60,0x50,0x00,0x00,0x05,0x06,0x06,
@ -146,8 +216,10 @@ const byte sprite_data[] = {
0x00,0x10,0x01,0x01,0x10,0x10,0x01,0x00,
0x00,0x10,0x11,0x00,0x00,0x11,0x01,0x00,
0x00,0x00,0x10,0x00,0x00,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const byte sprite8[2+16*16/2] = {
8,16,
0x00,0x00,0x11,0x11,0x11,0x11,0x00,0x00,
0x00,0x01,0x61,0x11,0x21,0x12,0x10,0x00,
0x00,0x11,0x12,0x11,0x61,0x11,0x11,0x00,
@ -163,7 +235,10 @@ const byte sprite_data[] = {
0x88,0x00,0x88,0x00,0x00,0x88,0x00,0x88,
0x80,0x00,0x08,0x80,0x08,0x80,0x00,0x08,
0x00,0x00,0x00,0x80,0x08,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const byte sprite9[2+13*16/2] = {
8,13,
0x00,0x00,0xaa,0x00,0x00,0xaa,0x00,0x00,
0x00,0x00,0xa0,0x0a,0xa0,0x0a,0x00,0x00,
0x0a,0xaa,0xa4,0xaa,0xaa,0x3a,0xaa,0xa0,
@ -177,8 +252,18 @@ const byte sprite_data[] = {
0x00,0xa3,0xa0,0x00,0x00,0x0a,0x4a,0x00,
0x00,0xaa,0xa0,0x00,0x00,0x0a,0xaa,0x00,
0x00,0x0a,0xa0,0x00,0x00,0x0a,0xa0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const byte* const all_sprites[9] = {
sprite1,
sprite2,
sprite3,
sprite4,
sprite5,
sprite6,
sprite7,
sprite8,
sprite9,
};
inline word swapw(word j) {
@ -200,7 +285,6 @@ inline void blit_copy(byte x1, byte y1, byte w, byte h, const byte* data) {
blitter.height = h^4;
blitter.sstart = swapw((word)data);
blitter.dstart = x1+y1*256; // swapped
blitter.solid = 0;
blitter.flags = DSTSCREEN|FGONLY;
}
@ -218,24 +302,164 @@ inline void draw_sprite(const byte* data, byte x, byte y) {
blitter.height = data[1]^4;
blitter.sstart = swapw((word)(data+2));
blitter.dstart = x+y*256; // swapped
blitter.solid = 0;
blitter.flags = DSTSCREEN|FGONLY;
}
inline void draw_sprite_solid(const byte* data, byte x, byte y, byte color) {
blitter.width = data[0]^4;
blitter.height = data[1]^4;
blitter.sstart = swapw((word)(data+2));
blitter.dstart = x+y*256; // swapped
blitter.solid = color;
blitter.flags = DSTSCREEN|FGONLY|SOLID;
}
inline void erase_sprite_rect(const byte* data, byte x, byte y) {
blitter.width = data[0]^4;
blitter.height = data[1]^4;
blitter.dstart = x+y*256; // swapped
blitter.solid = 0;
blitter.flags = DSTSCREEN|SOLID;
}
inline void draw_sprite_strided(const byte* data, byte x, byte y, byte stride) {
const byte* src = data+2;
byte height = data[1]^4;
byte width = data[0]^4;
while (height--) {
blit_copy(x, y, width, 1, src);
y += stride;
src += width;
}
}
inline void draw_char(char ch, byte x, byte y, byte color) {
if (ch < LOCHAR || ch > HICHAR) return;
blit_copy_solid(x, y, 4, 8, font_table[ch - LOCHAR], color);
}
void draw_string(const char* str, byte x, byte y, byte color) {
while (*str) {
draw_char(*str++, x, y, color);
x += 4;
}
}
typedef struct Actor* a;
typedef void ActorUpdateFn(struct Actor* a);
typedef void ActorDrawFn(struct Actor* a);
typedef struct Actor {
byte grid_index;
byte next_actor;
byte x,y;
byte* shape;
ActorUpdateFn* update;
ActorDrawFn* draw;
} Actor;
#define GBITS 4
#define GDIM (1<<GBITS)
#define MAX_ACTORS 256
static byte grid[GDIM*GDIM]; // should be 256
static Actor actors[MAX_ACTORS];
inline byte xy2grid(byte x, byte y) {
return (x >> (8-GBITS)) | (y & ((GDIM-1) << GBITS));
}
void insert_into_grid(byte gi, byte actor_index) {
actors[actor_index].grid_index = gi;
actors[actor_index].next_actor = grid[gi];
grid[gi] = actor_index;
}
void delete_from_grid(byte gi, byte actor_index) {
byte i = grid[gi];
if (i == actor_index) {
grid[gi] = actors[actor_index].next_actor;
} else {
do {
byte j = actors[i].next_actor;
if (j == actor_index) {
actors[i].next_actor = actors[actor_index].next_actor;
break;
}
i = j;
} while (1);
// watchdog reset if actor not found to delete
}
}
void draw_actor_debug(struct Actor* a) {
draw_sprite_solid(a->shape, a->x, a->y, a->next_actor?0xff:0x33);
}
void update_actor(byte actor_index) {
struct Actor* a = &actors[actor_index];
byte gi0,gi1;
if (!a->shape) return;
gi0 = a->grid_index;
draw_sprite_solid(a->shape, a->x, a->y, 0);
if (a->update) a->update(a);
if (a->draw) a->draw(a);
//draw_sprite_strided(a->shape, a->x, a->y, 2);
gi1 = xy2grid(a->x, a->y);
if (gi0 != gi1) {
delete_from_grid(gi0, actor_index);
insert_into_grid(gi1, actor_index);
}
}
//
word lfsr = 1;
word rand() {
byte lsb = lfsr & 1;
lfsr >>= 1;
if (lsb) lfsr ^= 0xd400;
return lfsr;
}
signed char random_dir() {
byte x = rand();
if (x < 85) return 0;
else if (x < 85*2) return -1;
else return 1;
}
void random_walk(Actor* a) {
a->x += random_dir();
a->y += random_dir();
}
void main() {
byte y = 0;
byte i;
byte num_actors = 32;
blit_solid(0, 0, 255, 255, 0);
memset(grid, 0, sizeof(grid));
memset(actors, 0, sizeof(actors));
memcpy(palette, palette_data, 16);
draw_sprite(sprite_data, 20, 20);
while (1) {
for (i=0; i<8; i++) {
byte xpos = 40+i*12;
const byte* sprdata = sprite_data+2+i*8*16;
blit_copy_solid(xpos, y-1, 8, 16, sprdata, 0);
blit_copy(xpos, y, 8, 16, sprdata);
}
y++;
fill_char_table();
for (i=0; i<num_actors; i++) {
Actor* a = &actors[i];
a->x = (i & 3) * 16 + 32;
a->y = (i / 4) * 16 + 64;
a->shape = (void*) all_sprites[i%9];
a->update = random_walk;
a->draw = draw_actor_debug;
insert_into_grid(xy2grid(a->x, a->y), i);
watchdog0x39 = 0x39;
}
while (1) {
for (i=0; i<num_actors; i++) {
update_actor(i);
watchdog0x39 = 0x39;
}
y++;
}
}

View File

@ -3,7 +3,8 @@
// http://www.computerarcheology.com/Arcade/
var MW8080BW_PRESETS = [
{id:'game2.c', name:'Game #2'},
{id:'game2.c', name:'Shoot-em-up Game'},
{id:'shifter.c', name:'Sprite w/ Bit Shifter'},
];
var Midway8080BWPlatform = function(mainElement) {

View File

@ -142,8 +142,7 @@ function newEditor(mode) {
editor.on('changes', function(ed, changeobj) {
clearTimeout(timer);
timer = setTimeout(function() {
var text = editor.getValue() || "";
setCode(text);
setCode(editor.getValue());
}, 200);
});
editor.setOption("mode", mode);
@ -170,10 +169,9 @@ function updatePreset(current_preset_id, text) {
function loadCode(text, fileid) {
var tool = platform.getToolForFilename(fileid);
newEditor(tool && TOOL_TO_SOURCE_STYLE[tool]);
editor.setValue(text);
editor.setValue(text); // calls setCode()
editor.clearHistory();
current_output = null;
setCode(text);
setLastPreset(fileid);
}
@ -378,6 +376,7 @@ function setCompileOutput(data) {
editor.setGutterMarker(line, "gutter-info", div);
}
if (data.errors.length > 0) {
// TODO: move cursor to error line if offscreen?
toolbar.addClass("has-errors");
editor.clearGutter("gutter-info");
var numLines = editor.lineCount();
@ -638,6 +637,7 @@ function constraintEquals(a,b) {
return null;
}
// TODO: move to file
function _traceInstructions(pc, minclocks, maxclocks, subaddr, constraints) {
//console.log("trace", hex(pc), minclocks, maxclocks);
if (!minclocks) minclocks = 0;

View File

@ -30,3 +30,7 @@ ship1.pbm: ship1.png
%.rot.pbm: %.pbm
convert $< -transpose -bordercolor white -border 4x4 $@
baddies-horiz.rot.pbm: baddies-horiz.png
convert $< +dither -brightness-contrast 50x50 -fill black -transpose -negate $@
convert $@ foo.png