From e964bd26be4243226322462e317a845703b24954 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 19 Aug 2018 19:25:42 -0400 Subject: [PATCH] clearBreakpoint before loadRom() to refresh memory; refresh listing view --- doc/notes.txt | 4 ++++ presets/nes/shoot2.c | 40 +++++++++++++++++++++++++++++++++++++--- src/baseplatform.ts | 2 ++ src/platform/vector.ts | 2 +- src/ui.ts | 7 +++++-- src/views.ts | 27 ++++++++++++++++++++++++--- test/cli/teststore.js | 7 ++++--- 7 files changed, 77 insertions(+), 12 deletions(-) diff --git a/doc/notes.txt b/doc/notes.txt index d0426e19..8d02d0d8 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -50,6 +50,10 @@ TODO: - BOM in upload/download? - stack view for Z80 platforms using memory map - online tools for music etc +- tools (memory, disasm) use debugging state +- loadROM needs to stop debugging before loading +- text log debugging script +- update listing when recompiling FYI: Image links for the books on http://8bitworkshop.com/ are broken On the website the additional grey spacing next to the program line numbers is not dynamically resized when the web browser window size is changed. Intentional? diff --git a/presets/nes/shoot2.c b/presets/nes/shoot2.c index 092191e5..80eef825 100644 --- a/presets/nes/shoot2.c +++ b/presets/nes/shoot2.c @@ -404,6 +404,14 @@ const byte SINTBL[32] = { -127, -125, -117, -106, -90, -71, -49, -25, }; +// pre-multiplied by 2 +const int SINTBL2[32] = { + 0, 25*2, 49*2, 71*2, 90*2, 106*2, 117*2, 125*2, + 127*2, 125*2, 117*2, 106*2, 90*2, 71*2, 49*2, 25*2, + 0*2, -25*2, -49*2, -71*2, -90*2, -106*2, -117*2, -125*2, + -127*2, -125*2, -117*2, -106*2, -90*2, -71*2, -49*2, -25*2, +}; + signed char isin(byte dir) { return SINTBL[dir & 31]; } @@ -412,6 +420,29 @@ signed char icos(byte dir) { return isin(dir+8); } +// Fast 8-bit table lookup macro +// dest: destination +// ident: table identifier +// index: 8-bit index +#define FASTLUT8(dest,ident,index) \ + __AX__ = (index); \ + asm ("tax"); \ + asm ("lda %v,x", ident); \ + (dest) = __AX__; + +// Fast 16-bit table lookup (single table of 2-byte words, 128 entries max) +// dest: destination (16 bits) +// ident: table identifier +// index: 8-bit index +#define FASTLUT16(dest,ident,index) \ + __AX__ = (index); \ + asm ("asl"); \ + asm ("tay"); \ + asm ("lda %v+1,y", ident); \ + asm ("tax"); \ + asm ("lda %v,y", ident); \ + (dest) = __AX__; + #define FORMATION_X0 0 #define FORMATION_Y0 19 #define FORMATION_XSPACE 24 @@ -467,8 +498,11 @@ void return_attacker(register AttackingEnemy* a) { void fly_attacker(register AttackingEnemy* a) { byte dir = a->dir; #if 1 - a->x += SINTBL[dir & 31] * 2; - a->y += SINTBL[(dir+8) & 31] * 2; + int sincos; + sincos = FASTLUT16(sincos, SINTBL2, dir&31); + a->x += sincos; + sincos = FASTLUT16(sincos, SINTBL2, (dir+8)&31); + a->y += sincos; #else a->x += isin(dir) * 2; a->y += icos(dir) * 2; @@ -660,7 +694,7 @@ void does_missile_hit_player() { return; for (i=0; i> 12; - //console.log(hex(pc*2+bofs), hex(w), hex(x>>2), hex(y>>2)); + //console.log(hex(pc*2+bofs), hex(w), hex(x>>2), hex(y>>2), hex(32-pcstack.length*2)); pc++; switch (op) { // VEC diff --git a/src/ui.ts b/src/ui.ts index 3bde8bcb..0b733646 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -148,13 +148,14 @@ function refreshWindowList() { }); // add listings + // TODO: update listing when recompiling var listings = current_project.getListings(); if (listings) { for (var lstfn in listings) { var lst = listings[lstfn]; if (lst.assemblyfile) { addWindowItem(lstfn, getFilenameForPath(lstfn), function(path) { - return new Views.ListingView(lst.assemblyfile); + return new Views.ListingView(lstfn); }); } } @@ -309,6 +310,7 @@ function _shareFile(e) { return true; } +// TODO: reset file, not project function _resetPreset(e) { if (!current_preset_entry) { alert("Can only reset built-in file examples.") @@ -399,8 +401,9 @@ function setCompileOutput(data: WorkerResult) { var rom = data.output; if (rom) { // TODO instanceof Uint8Array) { try { + clearBreakpoint(); // so we can replace memory (TODO: change toolbar btn) platform.loadROM(getCurrentPresetTitle(), rom); - if (!userPaused) resume(); + if (!userPaused) _resume(); current_output = rom; // TODO: reset profiler etc? (Tell views?) } catch (e) { diff --git a/src/views.ts b/src/views.ts index b02c9fc2..3eb62958 100644 --- a/src/views.ts +++ b/src/views.ts @@ -279,7 +279,7 @@ export class SourceEditor implements ProjectView { refreshListing() { // lookup corresponding sourcefile for this file, using listing var lst = current_project.getListingForFile(this.path); - if (lst && lst.sourcefile && lst.sourcefile != this.sourcefile) { + if (lst && lst.sourcefile && lst.sourcefile !== this.sourcefile) { this.sourcefile = lst.sourcefile; this.dirtylisting = true; } @@ -484,13 +484,24 @@ export class DisassemblerView implements ProjectView { export class ListingView extends DisassemblerView implements ProjectView { assemblyfile : SourceFile; + path : string; - constructor(assemblyfile : SourceFile) { + constructor(lstfn : string) { super(); - this.assemblyfile = assemblyfile; + this.path = lstfn; + } + + refreshListing() { + // lookup corresponding assemblyfile for this file, using listing + var lst = current_project.getListingForFile(this.path); + if (lst && lst.assemblyfile && lst.assemblyfile !== this.assemblyfile) { + this.assemblyfile = lst.assemblyfile; + } } refresh(moveCursor: boolean) { + this.refreshListing(); + if (!this.assemblyfile) return; // TODO? var state = lastDebugState || platform.saveState(); var pc = state.c ? state.c.PC : 0; var asmtext = this.assemblyfile.text; @@ -515,11 +526,21 @@ export class ListingView extends DisassemblerView implements ProjectView { /// +// TODO: make it use debug state export class MemoryView implements ProjectView { memorylist; dumplines; maindiv : HTMLElement; static IGNORE_SYMS = {s__INITIALIZER:true, /* s__GSINIT:true, */ _color_prom:true}; + /* + read(addr:number) { + // TODO: b offset ? + if (lastDebugState && lastDebugState.b && addr < lastDebugState.b.length) + return lastDebugState.b[addr]; + else + return this.platform.readMemory(addr); + } + */ createDiv(parent : HTMLElement) { var div = document.createElement('div'); diff --git a/test/cli/teststore.js b/test/cli/teststore.js index df4390a6..ebd36148 100644 --- a/test/cli/teststore.js +++ b/test/cli/teststore.js @@ -146,9 +146,10 @@ describe('Store', function() { assert.deepEqual([false], msgs); var lst = buildresult.listings.test; console.log(lst); - assert.equal(3, lst.sourcefile.findLineForOffset(61440+15)); - assert.equal(null, lst.sourcefile.findLineForOffset(61440+16)); - assert.equal(null, lst.sourcefile.findLineForOffset(61440-1)); + assert.equal(3, lst.sourcefile.findLineForOffset(61440+15, 15)); + assert.equal(null, lst.sourcefile.findLineForOffset(61440+16, 15)); + assert.equal(null, lst.sourcefile.findLineForOffset(61440+1, 0)); + assert.equal(null, lst.sourcefile.findLineForOffset(61440-1, 16)); assert.equal(1, lst.sourcefile.lineCount()); done(); });