From ba12e481f7b439e7f20935f8dac637e1a3c104e8 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sat, 18 Aug 2018 10:21:18 -0400 Subject: [PATCH] try to load local/ paths in include dependencies; don't update gutters of nonactive windows --- presets/nes/nesdefs.asm | 39 ++++++++++++++++++++++++++++++++++----- src/platform/vector.ts | 6 ++++-- src/project.ts | 10 ++++++++-- src/ui.ts | 1 - src/views.ts | 19 ++++++++++--------- src/windows.ts | 1 - src/workertypes.ts | 4 ++-- test/cli/teststore.js | 9 ++++++--- 8 files changed, 64 insertions(+), 25 deletions(-) diff --git a/presets/nes/nesdefs.asm b/presets/nes/nesdefs.asm index 148545cf..2050a84e 100644 --- a/presets/nes/nesdefs.asm +++ b/presets/nes/nesdefs.asm @@ -1,4 +1,4 @@ - + processor 6502 ;;;;; CONSTANTS @@ -129,10 +129,9 @@ NES_MIRR_QUAD = 8 sta PPU_DATA ENDM -;;;;; SAVE_REGS - save flags/A/X/Y registers +;;;;; SAVE_REGS - save A/X/Y registers MAC SAVE_REGS - php pha txa pha @@ -140,7 +139,7 @@ NES_MIRR_QUAD = 8 pha ENDM -;;;;; SAVE_REGS - restore Y/X/A/flags registers +;;;;; SAVE_REGS - restore Y/X/A registers MAC RESTORE_REGS pla @@ -148,5 +147,35 @@ NES_MIRR_QUAD = 8 pla tax pla - plp ENDM + +;------------------------------------------------------------------------------- +; SLEEP clockcycles +; Original author: Thomas Jentzsch +; Inserts code which takes the specified number of cycles to execute. This is +; useful for code where precise timing is required. +; LEGAL OPCODE VERSION MAY AFFECT FLAGS (uses 'bit' opcode) + +NO_ILLEGAL_OPCODES = 1 + + MAC SLEEP ;usage: SLEEP n (n>1) +.CYCLES SET {1} + + IF .CYCLES < 2 + ECHO "MACRO ERROR: 'SLEEP': Duration must be > 1" + ERR + ENDIF + + IF .CYCLES & 1 + IFNCONST NO_ILLEGAL_OPCODES + nop 0 + ELSE + bit $00 + ENDIF +.CYCLES SET .CYCLES - 3 + ENDIF + + REPEAT .CYCLES / 2 + nop + REPEND + ENDM diff --git a/src/platform/vector.ts b/src/platform/vector.ts index 9f4dccde..7a531144 100644 --- a/src/platform/vector.ts +++ b/src/platform/vector.ts @@ -449,7 +449,9 @@ var DVGBWStateMachine = function(bus, video, bofs) { function readWord(a) { a &= 0xfff; - return bus.read(a*2+bofs) + (bus.read(a*2+bofs+1) << 8); + var v = bus.read(a*2+bofs) + (bus.read(a*2+bofs+1) << 8); + //console.log(hex(a*2+bofs,4), hex(v,4), hex(x>>2), hex(y>>2)); + return v; } function decodeSigned(w, o2) { @@ -488,7 +490,7 @@ var DVGBWStateMachine = function(bus, video, bofs) { if (!running) return; var w = readWord(pc); var op = w >> 12; - //console.log(hex(pc), hex(w)); + //console.log(hex(pc*2+bofs), hex(w), hex(x>>2), hex(y>>2)); pc++; switch (op) { // VEC diff --git a/src/project.ts b/src/project.ts index ddb3d788..1ee44a1d 100644 --- a/src/project.ts +++ b/src/project.ts @@ -59,14 +59,15 @@ export class CodeProject { var re = /^\s*(`include|[.]include)\s+"(.+?)"/gm; var m; while (m = re.exec(text)) { + files.push('local/'+m[2]); files.push(m[2]); - //files.push('local/'+m[2]); // TODO: shows up 2x in interface } } else { // for .asm -- [.]include "file" // for .c -- #include "file" var re2 = /^\s+([.#]?include)\s+"(.+?)"/gm; while (m = re2.exec(text)) { + files.push('local/'+m[2]); files.push(m[2]); } } @@ -82,6 +83,7 @@ export class CodeProject { var re = /^\s*([;#]|[/][/][#])link\s+"(.+?)"/gm; var m; while (m = re.exec(text)) { + files.push('local/' + m[2]); files.push(m[2]); } } @@ -171,7 +173,8 @@ export class CodeProject { this.filedata[path] = value; addResult(path, value); loadNext(); - } else { + } else if (!path.startsWith("local/")) { + // don't load local/ // found on remote fetch? var preset_id = this.platform_id; preset_id = preset_id.replace(/[.]\w+/,''); // remove .suffix from preset name @@ -191,6 +194,9 @@ export class CodeProject { this.filedata[path] = null; loadNext(); }); + } else { + // not gonna find it, keep going + loadNext(); } }); } diff --git a/src/ui.ts b/src/ui.ts index 6cdbbe95..3bde8bcb 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -1,6 +1,5 @@ "use strict"; - // 8bitworkshop IDE user interface import $ = require("jquery"); diff --git a/src/views.ts b/src/views.ts index da298d17..b02c9fc2 100644 --- a/src/views.ts +++ b/src/views.ts @@ -170,9 +170,7 @@ export class SourceEditor implements ProjectView { getSourceFile() : SourceFile { return this.sourcefile; } - // TODO: update gutter only when refreshing this window - updateListing(_sourcefile : SourceFile) { - this.sourcefile = _sourcefile; + updateListing() { // update editor annotations this.editor.clearGutter("gutter-info"); this.editor.clearGutter("gutter-bytes"); @@ -263,7 +261,7 @@ export class SourceEditor implements ProjectView { var state = lastDebugState; if (state && state.c && this.sourcefile) { var PC = state.c.PC; - var line = this.sourcefile.findLineForOffset(PC); + var line = this.sourcefile.findLineForOffset(PC, 15); return line; } else return -1; @@ -279,12 +277,15 @@ export class SourceEditor implements ProjectView { } refreshListing() { - if (!this.dirtylisting) return; - this.dirtylisting = false; + // lookup corresponding sourcefile for this file, using listing var lst = current_project.getListingForFile(this.path); - if (lst && lst.sourcefile) { - this.updateListing(lst.sourcefile); // updates sourcefile variable + if (lst && lst.sourcefile && lst.sourcefile != this.sourcefile) { + this.sourcefile = lst.sourcefile; + this.dirtylisting = true; } + if (!this.sourcefile || !this.dirtylisting) return; + this.dirtylisting = false; + this.updateListing(); } refresh(moveCursor: boolean) { @@ -501,7 +502,7 @@ export class ListingView extends DisassemblerView implements ProjectView { disasmview.setValue(asmtext); var findPC = platform.getDebugCallback() ? pc : -1; if (findPC >= 0 && this.assemblyfile) { - var lineno = this.assemblyfile.findLineForOffset(findPC); + var lineno = this.assemblyfile.findLineForOffset(findPC, 15); if (lineno && moveCursor) { // set cursor while debugging if (platform.getDebugCallback()) diff --git a/src/windows.ts b/src/windows.ts index 3f86add3..21b9e443 100644 --- a/src/windows.ts +++ b/src/windows.ts @@ -57,7 +57,6 @@ export class ProjectWindows { } refresh(moveCursor:boolean) { - // TODO: activate window that contains debug line? // refresh current window if (this.activewnd && this.activewnd.refresh) this.activewnd.refresh(moveCursor); diff --git a/src/workertypes.ts b/src/workertypes.ts index e83b4f80..1707bcd3 100644 --- a/src/workertypes.ts +++ b/src/workertypes.ts @@ -27,9 +27,9 @@ export class SourceFile { } } } - findLineForOffset(PC:number):number { + findLineForOffset(PC:number, lookbehind:number):number { if (this.offset2line) { - for (var i=0; i<16; i++) { + for (var i=0; i<=lookbehind; i++) { var line = this.offset2line[PC]; if (line >= 0) { return line; diff --git a/test/cli/teststore.js b/test/cli/teststore.js index 03d85892..df4390a6 100644 --- a/test/cli/teststore.js +++ b/test/cli/teststore.js @@ -70,14 +70,17 @@ describe('Store', function() { it('Should load local project', function(done) { localStorage.clear(); - localStorage.setItem('_TEST/test', 'a'); + localStorage.setItem('_TEST/local/test', 'a'); var store = mstore.createNewPersistentStore(test_platform_id, function() { var worker = {}; var platform = {}; var project = new prj.CodeProject(worker, test_platform_id, platform, store); - project.loadFiles(['test'], function(err, result) { + var remote = []; + project.callbackGetRemote = function(path) { remote.push(path); return {fail:function(failfn){failfn({status:404})}} }; + project.loadFiles(['local/test','test'], function(err, result) { assert.equal(null, err); - assert.deepEqual([ { path: 'test', filename: 'test', data: 'a', link:true } ], result); + assert.deepEqual(["presets/_TEST/test"], remote); + assert.deepEqual([ { path: 'local/test', filename: 'test', data: 'a', link:true } ], result); done(); }); });