From a4c40948eab6f0daf00164b624c244d1498b2121 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Thu, 6 Apr 2017 10:28:51 -0400 Subject: [PATCH] working on williams sound, sprites --- index.html | 18 ++++------ presets/vector-z80color/font.c | 11 +++--- presets/williams-z80/sprites.c | 65 +++++++++++++++++++++++----------- src/audio/z80worker.js | 9 ++++- src/platform/williams.js | 17 ++++++--- src/ui.js | 1 - 6 files changed, 78 insertions(+), 43 deletions(-) diff --git a/index.html b/index.html index 60f2a724..bc1515fc 100644 --- a/index.html +++ b/index.html @@ -58,15 +58,11 @@ body { right:0; background-color: #666; } -div.editor { - position:absolute; - left:0; - top:0; - bottom:0; - right:0; - width:50%; - height:95vh; +div.workspace { background-color:#999; +} +div.editor { + width:50%; line-height:1.25; font-size:12pt; } @@ -75,7 +71,6 @@ div.emulator { left:50%; top:0; width:50%; - overflow-y: scroll; background-color: #666; margin-top: 20px auto 0; } @@ -236,12 +231,11 @@ div.bitmap_editor { - + -
-
+
diff --git a/presets/vector-z80color/font.c b/presets/vector-z80color/font.c index 6d131570..82fe35b5 100644 --- a/presets/vector-z80color/font.c +++ b/presets/vector-z80color/font.c @@ -188,6 +188,7 @@ void draw_string(const char* str, byte spacing) { } void main() { + int r = 512; dvgwrofs = 0x800; draw_string("HELLO WORLD", 0); RTSL(); @@ -195,12 +196,12 @@ void main() { dvgreset(); CNTR(); SCAL(0x7f); - //SCAL(frame & 0xff); STAT(RED, 0); - VCTR(200, 200, 1); - VCTR(-200, 200, 3); - VCTR(-200, -200, 5); - VCTR(200, -200, 7); + VCTR(r, r, 1); + VCTR(-r*2, 0, 3); + VCTR(0, -r*2, 5); + VCTR(r*2, 0, 7); + VCTR(0, r*2, 7); CNTR(); STAT(GREEN, 0); VCTR(100, -100, 0); diff --git a/presets/williams-z80/sprites.c b/presets/williams-z80/sprites.c index d4c305bc..24d22e71 100644 --- a/presets/williams-z80/sprites.c +++ b/presets/williams-z80/sprites.c @@ -5,11 +5,11 @@ typedef unsigned char byte; typedef unsigned short word; byte __at (0xc000) palette[16]; -byte __at (0xc800) input0; -byte __at (0xc802) input1; -byte __at (0xc804) input2; +volatile byte __at (0xc800) input0; +volatile byte __at (0xc802) input1; +volatile byte __at (0xc804) input2; byte __at (0xc900) rom_select; -byte __at (0xcb00) video_counter; +volatile byte __at (0xcb00) video_counter; byte __at (0xcbff) watchdog0x39; byte __at (0xcc00) nvram[0x400]; @@ -359,7 +359,7 @@ typedef struct Actor { ActorDrawFn* draw; } Actor; -#define GBITS 4 +#define GBITS 3 #define GDIM (1<grid_index = gi; + a->next_actor = grid[gi]; grid[gi] = actor_index; } void delete_from_grid(byte gi, byte actor_index) { byte i = grid[gi]; + byte next = actors[actor_index].next_actor; + // is actor to delete at head of list? if (i == actor_index) { - grid[gi] = actors[actor_index].next_actor; + grid[gi] = next; } else { + // iterate through the list do { byte j = actors[i].next_actor; if (j == actor_index) { - actors[i].next_actor = actors[actor_index].next_actor; + actors[i].next_actor = next; break; } i = j; - } while (1); - // watchdog reset if actor not found to delete + } while (1); // watchdog reset if actor not found to delete } + actors[actor_index].next_actor = 0; + actors[actor_index].grid_index = 0; } 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) { +byte update_actor(byte actor_index) { struct Actor* a = &actors[actor_index]; + byte next_actor; byte gi0,gi1; - if (!a->shape) return; + if (!a->shape) return 0; + next_actor = a->next_actor; gi0 = a->grid_index; draw_sprite_solid(a->shape, a->x, a->y, 0); if (a->update) a->update(a); @@ -411,6 +418,7 @@ void update_actor(byte actor_index) { delete_from_grid(gi0, actor_index); insert_into_grid(gi1, actor_index); } + return next_actor; } // @@ -436,8 +444,23 @@ void random_walk(Actor* a) { a->y += random_dir(); } +void update_grid_cell(byte grid_index) { + byte actor_index = grid[grid_index]; + while (actor_index) { + actor_index = update_actor(actor_index); + } +} + +void update_grid_rows(byte row_start, byte row_end) { + byte i0 = row_start * GDIM; + byte i1 = row_end * GDIM; + byte i; + for (i=i0; i!=i1; i++) { + update_grid_cell(i); + } +} + void main() { - byte y = 0; byte i; byte num_actors = 32; blit_solid(0, 0, 255, 255, 0); @@ -445,7 +468,7 @@ void main() { memset(actors, 0, sizeof(actors)); memcpy(palette, palette_data, 16); fill_char_table(); - for (i=0; ix = (i & 3) * 16 + 32; a->y = (i / 4) * 16 + 64; @@ -456,10 +479,12 @@ void main() { watchdog0x39 = 0x39; } while (1) { - for (i=0; i= 0x80) ; + update_grid_rows(GDIM/2,GDIM); + watchdog0x39 = 0x39; } } diff --git a/src/audio/z80worker.js b/src/audio/z80worker.js index e114be96..f94fb30e 100644 --- a/src/audio/z80worker.js +++ b/src/audio/z80worker.js @@ -63,7 +63,9 @@ function fillBuffer() { function start() { ram = new RAM(0x400); - rom = [0xe,0x0,0x6,0x0,0x78,0xb9,0x30,0x06,0xa9,0xd3,0x00,0x04,0x18,0xf6,0x0c,0x79,0xd6,0xff,0x38,0xee,0x76,0x18,0xea]; // TODO + rom = new RAM(0x4000).mem; + // sample: [0xe,0x0,0x6,0x0,0x78,0xb9,0x30,0x06,0xa9,0xd3,0x00,0x04,0x18,0xf6,0x0c,0x79,0xd6,0xff,0x38,0xee,0x76,0x18,0xea]; + rom.fill(0x76); // HALT opcodes membus = { read: new AddressDecoder([ [0x0000, 0x3fff, 0x3fff, function(a) { return rom ? rom[a] : null; }], @@ -107,6 +109,7 @@ function timerCallback() { timer = setTimeout(timerCallback, dt); } else { timer = 0; + //console.log("HALT @ " + cpu.getPC()); } } @@ -130,6 +133,10 @@ onmessage = function(e) { bufferLength = numChannels*sampleRate*timerPeriod/1000; start(); reset(); + } else if (e.data.rom) { + rom = e.data.rom; + command = 0x0; + reset(); } } } diff --git a/src/platform/williams.js b/src/platform/williams.js index 11f03d6a..68d37601 100644 --- a/src/platform/williams.js +++ b/src/platform/williams.js @@ -139,8 +139,8 @@ var WilliamsPlatform = function(mainElement, proto) { ]); var memread_williams = new AddressDecoder([ - [0x0000, 0x97ff, 0xffff, function(a) { return banksel ? rom[a] : ram.mem[a]; }], - [0x9800, 0xbfff, 0xffff, function(a) { return ram.mem[a]; }], + [0x0000, 0x8fff, 0xffff, function(a) { return banksel ? rom[a] : ram.mem[a]; }], + [0x9000, 0xbfff, 0xffff, function(a) { return ram.mem[a]; }], [0xc000, 0xcfff, 0x0fff, ioread_williams], [0xd000, 0xffff, 0xffff, function(a) { return rom ? rom[a-0x4000] : 0; }], ]); @@ -324,11 +324,20 @@ var WilliamsPlatform = function(mainElement, proto) { }); } + this.loadSoundROM = function(data) { + var soundrom = padBytes(data, 0x4000); + worker.postMessage({rom:soundrom}); + } + this.loadROM = function(title, data) { if (data.length > 2) { - rom = padBytes(data, 0xc000); + if (data.length > 0xc000) { + self.loadSoundROM(data.slice(0xc000)); + rom = rom.slice(data, 0, 0xc000); + } else { + rom = padBytes(data, 0xc000); + } } - // TODO self.reset(); } diff --git a/src/ui.js b/src/ui.js index eb8514ee..826c152f 100644 --- a/src/ui.js +++ b/src/ui.js @@ -591,7 +591,6 @@ function runStepBackwards() { function clearBreakpoint() { lastDebugState = null; platform.clearDebug(); - $("#dbg_info").empty(); showMemory(); }