From 32af97aa8fa2e75c9f128197006a457a961481e4 Mon Sep 17 00:00:00 2001 From: otya128 Date: Mon, 22 Feb 2016 23:26:44 +0900 Subject: [PATCH] =?UTF-8?q?=E5=A4=89=E6=95=B0=E5=91=A8=E3=82=8A=E3=81=AE?= =?UTF-8?q?=E3=83=90=E3=82=B0=E5=8F=96=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SMILEBASIC/VM.d | 5 +++++ SMILEBASIC/compiler.d | 2 ++ SMILEBASIC/petitcomputer.d | 31 ++++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/SMILEBASIC/VM.d b/SMILEBASIC/VM.d index 628d40e..d8988f3 100644 --- a/SMILEBASIC/VM.d +++ b/SMILEBASIC/VM.d @@ -56,9 +56,14 @@ class VM slots[i] = new VMSlot(); } } + int currentSlotNumber() + { + return slot; + } void setCurrentSlot(int slot) { currentSlot = slots[slot]; + this.slot = slot; } void directSlot(int start, Code[] code, int len, VMVariable[wstring] globalTable, Function[wstring] functions, DataTable gdt/*GNU Debugging Tools*/, int[wstring] globalLabel, DebugInfo dinfo) diff --git a/SMILEBASIC/compiler.d b/SMILEBASIC/compiler.d index be11a00..90970c7 100644 --- a/SMILEBASIC/compiler.d +++ b/SMILEBASIC/compiler.d @@ -23,6 +23,7 @@ class DebugInfo } SourceLocation getLocationByAddress(int addr) { + if(location.length <= addr) return SourceLocation(0, 0, 0); return location[addr]; } } @@ -1062,6 +1063,7 @@ class Compiler auto start = vm.currentSlot.code.length; this.code = vm.currentSlot.code; globalIndex = vm.currentSlot.global.length; + functions = vm.currentSlot.functions; compileProgram(); vm.directSlot(start, code, globalIndex + 1, global, functions, globalScope.data, globalLabel, debugInfo); } diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index 4fdb59c..13d381b 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -820,6 +820,7 @@ class PetitComputer buttonTable[SDL_SCANCODE_LEFT] = Button.LEFT; buttonTable[SDL_SCANCODE_RIGHT] = Button.RIGHT; buttonTable[SDL_SCANCODE_SPACE] = Button.A; + buttonTable[SDL_SCANCODE_ESCAPE] = Button.START; if(!window) { write("can't create window: "); @@ -1000,6 +1001,10 @@ class PetitComputer { auto key = event.key.keysym.sym; button |= buttonTable[event.key.keysym.scancode]; + if(Button.START & buttonTable[event.key.keysym.scancode]) + { + stop(); + } if(key == SDLK_BACKSPACE) { keybuffermutex.lock(); @@ -1041,6 +1046,13 @@ class PetitComputer SDL_Window* window; otya.smilebasic.vm.VM vm; int maincnt; + bool running; + bool stopflg; + void stop() + { + running = false; + stopflg = true; + } void run() { keybuffer = new wchar[128]; @@ -1057,7 +1069,6 @@ class PetitComputer auto startTicks = SDL_GetTicks(); Parser parser; otya.smilebasic.vm.VM vm; - bool running; bool directMode = false; //デバッグ用 version(NDirectMode) @@ -1195,7 +1206,7 @@ class PetitComputer try { printConsole(sbe.getErrorMessage, "\n"); - printConsole(sbe.getErrorMessage2, "\n"); + if(sbe.getErrorMessage2.length) printConsole(sbe.getErrorMessage2, "\n"); //printConsole(sbe.to!string); writeln(sbe.to!string); writeln(sbe.getErrorMessage2); @@ -1254,10 +1265,6 @@ class PetitComputer printConsole(loc.line, ":", loc.pos, ":", parser.getLine(loc)); } } - if(!running) - { - if(directMode) break; - } } catch(SmileBasicError sbe) { @@ -1265,7 +1272,7 @@ class PetitComputer try { printConsole(sbe.getErrorMessage, "\n"); - printConsole(sbe.getErrorMessage2, "\n"); + if(sbe.getErrorMessage2.length) printConsole(sbe.getErrorMessage2, "\n"); //printConsole(sbe.to!string); writeln(sbe.to!string); writeln(sbe.getErrorMessage2); @@ -1291,6 +1298,16 @@ class PetitComputer writeln(t); } } + if(!running || stopflg) + { + if(stopflg) + { + loc = vm.currentLocation; + printConsole("Break on ", vm.currentSlotNumber, ":", loc.line, "\n"); + stopflg = false; + } + if(directMode) break; + } //elapse = SDL_GetTicks() - startTicks; } //while(elapse <= 1000 / 60); if(vsyncFrame)