From 86eee04de3d5a7009e55b121d921c511b1962b1a Mon Sep 17 00:00:00 2001 From: otya128 Date: Thu, 20 Aug 2015 16:13:27 +0900 Subject: [PATCH] =?UTF-8?q?FLOOR,IF=20THEN=20@LABEL,=E3=83=9C=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E5=85=A5=E5=8A=9B=E3=82=92=E5=AE=9F=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SMILEBASIC/TEST.txt | 1 + SMILEBASIC/builtinfunctions.d | 6 ++- SMILEBASIC/parser.d | 11 +++++- SMILEBASIC/petitcomputer.d | 73 ++++++++++++++++++++++++++--------- 4 files changed, 69 insertions(+), 22 deletions(-) diff --git a/SMILEBASIC/TEST.txt b/SMILEBASIC/TEST.txt index 93b7e9f..7725d8d 100644 --- a/SMILEBASIC/TEST.txt +++ b/SMILEBASIC/TEST.txt @@ -1,3 +1,4 @@ + GOSUB@A GOTO@B 'A=SIN(B) diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 752262b..cd84a8e 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -108,7 +108,7 @@ class BuiltinFunction } static int BUTTON(PetitComputer p, DefaultValue!(int, false) mode) { - return 0; + return p.button; } static void VISIBLE(PetitComputer p, DefaultValue!(int) console, DefaultValue!(int) graphic, DefaultValue!(int) BG, DefaultValue!(int) sprite) { @@ -192,6 +192,10 @@ class BuiltinFunction double val = str.to!double; return val; } + static double FLOOR(double val) + { + return val.floor; + } static wstring MID(wstring str, int i, int len) { //挙動未定 diff --git a/SMILEBASIC/parser.d b/SMILEBASIC/parser.d index 36c52d7..72b9a54 100644 --- a/SMILEBASIC/parser.d +++ b/SMILEBASIC/parser.d @@ -614,12 +614,20 @@ class Parser Statements ifStatements() { auto statements = new Statements(); + bool flag = true; while(!lex.empty()) { auto type = lex.front().type; + flag = false; if(type == TokenType.NewLine) break; if(type == TokenType.Else) break; if(type == TokenType.Endif) break; + if(type == TokenType.Label) + { + statements.addStatement(new Goto(lex.front.value.stringValue)); + lex.popFront; + continue; + } auto statement = statement(); if(statement != Statement.NOP) { @@ -1110,13 +1118,12 @@ class Parser { var.addDefineArray(cast(DefineArray)v); } + token = lex.front(); //VARの評価順は順番通り //VAR iden[=expr], if(token.type == TokenType.Comma) { lex.popFront(); - writeln("NOTIMPL"); - syntaxError(); } else { diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index f7d2929..cd827ca 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -10,6 +10,23 @@ import std.string; import std.c.stdio; import core.sync.mutex; import otya.smilebasic.parser; +enum Button +{ + UP = 1, + DOWN = 2, + LEFT = 4, + RIGHT = 8, + A = 16, + B = 32, + X = 64, + Y = 128, + L = 256, + R = 512, + UNUSED = 1024, + ZR = 2048, + ZL = 4096, + START = 8192, +} class GraphicPage { static GLenum textureScaleMode = GL_NEAREST; @@ -120,6 +137,7 @@ class PetitComputer { return SDL_Color(r >> 5 << 5, g >> 5 << 5, b >> 5 << 5, a == 255 ? 255 : 0); } + Button button; ConsoleCharacter[][] console; bool visibleGRP = true; int showGRP; @@ -480,9 +498,16 @@ class PetitComputer drawflag = false; } + Button[] buttonTable; void render() { - bool renderprofile; + buttonTable = new Button[SDL_SCANCODE_SLEEP + 1]; + buttonTable[SDL_SCANCODE_UP] = Button.UP; + buttonTable[SDL_SCANCODE_DOWN] = Button.DOWN; + buttonTable[SDL_SCANCODE_LEFT] = Button.LEFT; + buttonTable[SDL_SCANCODE_RIGHT] = Button.RIGHT; + buttonTable[SDL_SCANCODE_SPACE] = Button.A; + bool renderprofile;// = true; try { version(Windows) @@ -554,19 +579,28 @@ class PetitComputer SDL_DestroyWindow(window); SDL_Quit(); return; - case SDL_KEYDOWN: - auto key = event.key.keysym.sym; - if(key == SDLK_BACKSPACE) + case SDL_KEYUP: { - keybuffermutex.lock(); - sendKey('\u0008'); - keybuffermutex.unlock(); + auto key = event.key.keysym.sym; + button &= ~buttonTable[event.key.keysym.scancode]; } - if(key == SDLK_RETURN) + break; + case SDL_KEYDOWN: { - keybuffermutex.lock(); - sendKey('\u000D'); - keybuffermutex.unlock(); + auto key = event.key.keysym.sym; + button |= buttonTable[event.key.keysym.scancode]; + if(key == SDLK_BACKSPACE) + { + keybuffermutex.lock(); + sendKey('\u0008'); + keybuffermutex.unlock(); + } + if(key == SDLK_RETURN) + { + keybuffermutex.lock(); + sendKey('\u000D'); + keybuffermutex.unlock(); + } } break; case SDL_TEXTINPUT: @@ -584,7 +618,7 @@ class PetitComputer } while(true) { - long delay = (1000/60) - cast(long)(SDL_GetTicks() - profile); + long delay = (1000/60) - (cast(long)SDL_GetTicks() - profile); if(delay > 0) SDL_Delay(cast(uint)delay); break; @@ -621,7 +655,8 @@ class PetitComputer thread.start(); auto startTicks = SDL_GetTicks(); //とりあえず - auto parser = new Parser(readText("./SYS/EX5BIORHYTHM.TXT").to!wstring + auto parser = new Parser( + readText("./SYS/EX7ALIEN.TXT").to!wstring //readText(input("LOAD PROGRAM:", true).to!string).to!wstring //readText("./SYS/EX1TEXT.TXT").to!wstring //readText("FIZZBUZZ.TXT").to!wstring @@ -668,10 +703,10 @@ class PetitComputer auto vm = parser.compile(); bool running = true; vm.init(this); - gpset(0, 10, 10, 0xFF00FF00); - gline(0, 0, 0, 399, 239, RGB(0, 255, 0)); - gfill(0, 78, 78, 40, 40, RGB(0, 255, 255)); - gbox(0, 78, 78, 40, 40, RGB(255, 255, 0)); + //gpset(0, 10, 10, 0xFF00FF00); + //gline(0, 0, 0, 399, 239, RGB(0, 255, 0)); + //gfill(0, 78, 78, 40, 40, RGB(0, 255, 255)); + //gbox(0, 78, 78, 40, 40, RGB(255, 255, 0)); while (true) { uint elapse; @@ -918,8 +953,8 @@ class PetitComputer } void renderConsoleGL() { - consolem.lock(); - scope(exit) consolem.unlock(); + //consolem.lock(); + //scope(exit) consolem.unlock(); glBindTexture(GL_TEXTURE_2D, GRPF.glTexture); glDisable(GL_TEXTURE_2D); glBegin(GL_QUADS);