1
0

FLOOR,IF THEN @LABEL,ボタン入力を実�

This commit is contained in:
otya128
2015-08-20 16:13:27 +09:00
parent e02fd58838
commit 86eee04de3
4 changed files with 69 additions and 22 deletions

View File

@@ -1,3 +1,4 @@
GOSUB@A GOSUB@A
GOTO@B GOTO@B
'A=SIN(B) 'A=SIN(B)

View File

@@ -108,7 +108,7 @@ class BuiltinFunction
} }
static int BUTTON(PetitComputer p, DefaultValue!(int, false) mode) 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) 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; double val = str.to!double;
return val; return val;
} }
static double FLOOR(double val)
{
return val.floor;
}
static wstring MID(wstring str, int i, int len) static wstring MID(wstring str, int i, int len)
{ {
//挙動未定 //挙動未定

View File

@@ -614,12 +614,20 @@ class Parser
Statements ifStatements() Statements ifStatements()
{ {
auto statements = new Statements(); auto statements = new Statements();
bool flag = true;
while(!lex.empty()) while(!lex.empty())
{ {
auto type = lex.front().type; auto type = lex.front().type;
flag = false;
if(type == TokenType.NewLine) break; if(type == TokenType.NewLine) break;
if(type == TokenType.Else) break; if(type == TokenType.Else) break;
if(type == TokenType.Endif) break; if(type == TokenType.Endif) break;
if(type == TokenType.Label)
{
statements.addStatement(new Goto(lex.front.value.stringValue));
lex.popFront;
continue;
}
auto statement = statement(); auto statement = statement();
if(statement != Statement.NOP) if(statement != Statement.NOP)
{ {
@@ -1110,13 +1118,12 @@ class Parser
{ {
var.addDefineArray(cast(DefineArray)v); var.addDefineArray(cast(DefineArray)v);
} }
token = lex.front();
//VARの評価順は順番通り //VARの評価順は順番通り
//VAR iden[=expr], //VAR iden[=expr],
if(token.type == TokenType.Comma) if(token.type == TokenType.Comma)
{ {
lex.popFront(); lex.popFront();
writeln("NOTIMPL");
syntaxError();
} }
else else
{ {

View File

@@ -10,6 +10,23 @@ import std.string;
import std.c.stdio; import std.c.stdio;
import core.sync.mutex; import core.sync.mutex;
import otya.smilebasic.parser; 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 class GraphicPage
{ {
static GLenum textureScaleMode = GL_NEAREST; 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); return SDL_Color(r >> 5 << 5, g >> 5 << 5, b >> 5 << 5, a == 255 ? 255 : 0);
} }
Button button;
ConsoleCharacter[][] console; ConsoleCharacter[][] console;
bool visibleGRP = true; bool visibleGRP = true;
int showGRP; int showGRP;
@@ -480,9 +498,16 @@ class PetitComputer
drawflag = false; drawflag = false;
} }
Button[] buttonTable;
void render() 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 try
{ {
version(Windows) version(Windows)
@@ -554,8 +579,16 @@ class PetitComputer
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
SDL_Quit(); SDL_Quit();
return; return;
case SDL_KEYDOWN: case SDL_KEYUP:
{
auto key = event.key.keysym.sym; auto key = event.key.keysym.sym;
button &= ~buttonTable[event.key.keysym.scancode];
}
break;
case SDL_KEYDOWN:
{
auto key = event.key.keysym.sym;
button |= buttonTable[event.key.keysym.scancode];
if(key == SDLK_BACKSPACE) if(key == SDLK_BACKSPACE)
{ {
keybuffermutex.lock(); keybuffermutex.lock();
@@ -568,6 +601,7 @@ class PetitComputer
sendKey('\u000D'); sendKey('\u000D');
keybuffermutex.unlock(); keybuffermutex.unlock();
} }
}
break; break;
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
auto text = event.text.text[0..event.text.text.indexOf('\0')].to!wstring; auto text = event.text.text[0..event.text.text.indexOf('\0')].to!wstring;
@@ -584,7 +618,7 @@ class PetitComputer
} }
while(true) while(true)
{ {
long delay = (1000/60) - cast(long)(SDL_GetTicks() - profile); long delay = (1000/60) - (cast(long)SDL_GetTicks() - profile);
if(delay > 0) if(delay > 0)
SDL_Delay(cast(uint)delay); SDL_Delay(cast(uint)delay);
break; break;
@@ -621,7 +655,8 @@ class PetitComputer
thread.start(); thread.start();
auto startTicks = SDL_GetTicks(); 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(input("LOAD PROGRAM:", true).to!string).to!wstring
//readText("./SYS/EX1TEXT.TXT").to!wstring //readText("./SYS/EX1TEXT.TXT").to!wstring
//readText("FIZZBUZZ.TXT").to!wstring //readText("FIZZBUZZ.TXT").to!wstring
@@ -668,10 +703,10 @@ class PetitComputer
auto vm = parser.compile(); auto vm = parser.compile();
bool running = true; bool running = true;
vm.init(this); vm.init(this);
gpset(0, 10, 10, 0xFF00FF00); //gpset(0, 10, 10, 0xFF00FF00);
gline(0, 0, 0, 399, 239, RGB(0, 255, 0)); //gline(0, 0, 0, 399, 239, RGB(0, 255, 0));
gfill(0, 78, 78, 40, 40, RGB(0, 255, 255)); //gfill(0, 78, 78, 40, 40, RGB(0, 255, 255));
gbox(0, 78, 78, 40, 40, RGB(255, 255, 0)); //gbox(0, 78, 78, 40, 40, RGB(255, 255, 0));
while (true) while (true)
{ {
uint elapse; uint elapse;
@@ -918,8 +953,8 @@ class PetitComputer
} }
void renderConsoleGL() void renderConsoleGL()
{ {
consolem.lock(); //consolem.lock();
scope(exit) consolem.unlock(); //scope(exit) consolem.unlock();
glBindTexture(GL_TEXTURE_2D, GRPF.glTexture); glBindTexture(GL_TEXTURE_2D, GRPF.glTexture);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS); glBegin(GL_QUADS);