VSYNC,CLS実装,引数なし関数をコンパイルするときに暴走しないように
This commit is contained in:
@@ -70,6 +70,11 @@ class VM
|
|||||||
}
|
}
|
||||||
void push(ref Value value)
|
void push(ref Value value)
|
||||||
{
|
{
|
||||||
|
if(stacki >= this.stack.length)
|
||||||
|
{
|
||||||
|
writeln("Stack OF");
|
||||||
|
readln();
|
||||||
|
}
|
||||||
stack[stacki++] = value;
|
stack[stacki++] = value;
|
||||||
}
|
}
|
||||||
void push(Value value)
|
void push(Value value)
|
||||||
@@ -138,17 +143,17 @@ class PrintCode : Code
|
|||||||
switch(arg.type)
|
switch(arg.type)
|
||||||
{
|
{
|
||||||
case ValueType.Integer:
|
case ValueType.Integer:
|
||||||
write(arg.integerValue);
|
//write(arg.integerValue);
|
||||||
if(vm.petitcomputer)
|
if(vm.petitcomputer)
|
||||||
vm.petitcomputer.printConsole(arg.integerValue);
|
vm.petitcomputer.printConsole(arg.integerValue);
|
||||||
break;
|
break;
|
||||||
case ValueType.Double:
|
case ValueType.Double:
|
||||||
write(arg.doubleValue);
|
//write(arg.doubleValue);
|
||||||
if(vm.petitcomputer)
|
if(vm.petitcomputer)
|
||||||
vm.petitcomputer.printConsole(arg.doubleValue);
|
vm.petitcomputer.printConsole(arg.doubleValue);
|
||||||
break;
|
break;
|
||||||
case ValueType.String:
|
case ValueType.String:
|
||||||
write(arg.stringValue);
|
//write(arg.stringValue);
|
||||||
if(vm.petitcomputer)
|
if(vm.petitcomputer)
|
||||||
vm.petitcomputer.printConsole(arg.stringValue);
|
vm.petitcomputer.printConsole(arg.stringValue);
|
||||||
break;
|
break;
|
||||||
@@ -880,5 +885,6 @@ class CallBuiltinFunction : Code
|
|||||||
result = vm.stack[vm.stacki - argcount..vm.stacki - argcount + outcount];//雑;
|
result = vm.stack[vm.stacki - argcount..vm.stacki - argcount + outcount];//雑;
|
||||||
}
|
}
|
||||||
func.func(vm.petitcomputer, arg, result);
|
func.func(vm.petitcomputer, arg, result);
|
||||||
|
vm.stacki -= func.argments.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,16 @@ class BuiltinFunction
|
|||||||
p.consoleForeColor = cast(int)fore;
|
p.consoleForeColor = cast(int)fore;
|
||||||
p.consoleBackColor = cast(int)back;
|
p.consoleBackColor = cast(int)back;
|
||||||
}
|
}
|
||||||
|
static void VSYNC(PetitComputer p, DefaultValue!int time)
|
||||||
|
{
|
||||||
|
time.setDefaultValue(1);
|
||||||
|
p.vsync(cast(int)time);
|
||||||
|
}
|
||||||
|
//TODO:プチコンのCLSには引数の個数制限がない
|
||||||
|
static void CLS(PetitComputer p/*vaarg*/)
|
||||||
|
{
|
||||||
|
p.cls;
|
||||||
|
}
|
||||||
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
||||||
static BuiltinFunction[wstring] builtinFunctions;
|
static BuiltinFunction[wstring] builtinFunctions;
|
||||||
static this()
|
static this()
|
||||||
@@ -176,6 +186,13 @@ template GetFunctionParamType(T, string N)
|
|||||||
{
|
{
|
||||||
enum GetFunctionParamType = mixin("[" ~ Array!(ParameterTypeTuple!(__traits(getMember, T, N))) ~ "]");
|
enum GetFunctionParamType = mixin("[" ~ Array!(ParameterTypeTuple!(__traits(getMember, T, N))) ~ "]");
|
||||||
private template Array(P...)
|
private template Array(P...)
|
||||||
|
{
|
||||||
|
static if(P.length == 0)
|
||||||
|
{
|
||||||
|
const string arg = "";
|
||||||
|
enum Array = "";
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
static if(is(P[0] == double))
|
static if(is(P[0] == double))
|
||||||
{
|
{
|
||||||
@@ -194,9 +211,16 @@ template GetFunctionParamType(T, string N)
|
|||||||
const string arg = "ValueType.Integer, true";
|
const string arg = "ValueType.Integer, true";
|
||||||
}
|
}
|
||||||
else static if(is(P[0] == PetitComputer))
|
else static if(is(P[0] == PetitComputer))
|
||||||
|
{
|
||||||
|
static if(P.length != 0)
|
||||||
{
|
{
|
||||||
enum Array = Array!(P[1..$]);
|
enum Array = Array!(P[1..$]);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
enum Array = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
static if(1 == P.length && !is(P[0] == PetitComputer))
|
static if(1 == P.length && !is(P[0] == PetitComputer))
|
||||||
{
|
{
|
||||||
enum Array = "BuiltinFunctionArgument(" ~ arg ~ ")";
|
enum Array = "BuiltinFunctionArgument(" ~ arg ~ ")";
|
||||||
@@ -207,6 +231,7 @@ template GetFunctionParamType(T, string N)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
template AddFuncArg(int L, int N, int M, P...)
|
template AddFuncArg(int L, int N, int M, P...)
|
||||||
{
|
{
|
||||||
enum I = L - N;
|
enum I = L - N;
|
||||||
|
|||||||
@@ -613,7 +613,7 @@ class Compiler
|
|||||||
auto bfun = otya.smilebasic.builtinfunctions.BuiltinFunction.builtinFunctions.get(func.name, null);
|
auto bfun = otya.smilebasic.builtinfunctions.BuiltinFunction.builtinFunctions.get(func.name, null);
|
||||||
if(bfun)
|
if(bfun)
|
||||||
{
|
{
|
||||||
auto k = bfun.argments.length - func.args.length;
|
int k = bfun.argments.length - func.args.length;
|
||||||
foreach(l;0..k)
|
foreach(l;0..k)
|
||||||
{
|
{
|
||||||
genCodeImm(Value(ValueType.Void));
|
genCodeImm(Value(ValueType.Void));
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ class PetitComputer
|
|||||||
wchar charater;
|
wchar charater;
|
||||||
int foreColor;
|
int foreColor;
|
||||||
int backColor;
|
int backColor;
|
||||||
|
byte attr;
|
||||||
}
|
}
|
||||||
SDL_Color PetitColor(byte r, byte g, byte b, byte a)
|
SDL_Color PetitColor(byte r, byte g, byte b, byte a)
|
||||||
{
|
{
|
||||||
@@ -71,6 +72,8 @@ class PetitComputer
|
|||||||
ConsoleCharacter[][] console;
|
ConsoleCharacter[][] console;
|
||||||
GraphicPage[] grp;
|
GraphicPage[] grp;
|
||||||
GraphicPage GRPF;
|
GraphicPage GRPF;
|
||||||
|
GraphicPage[] GRPFColor;
|
||||||
|
GraphicPage[][] GRPFColorFore;
|
||||||
//PNG画像から透過色のpixelを指定して透過しGRPを作る
|
//PNG画像から透過色のpixelを指定して透過しGRPを作る
|
||||||
GraphicPage createGraphicPage(string file, int pixel)
|
GraphicPage createGraphicPage(string file, int pixel)
|
||||||
{
|
{
|
||||||
@@ -89,6 +92,67 @@ class PetitComputer
|
|||||||
SDL_RWclose(stream);
|
SDL_RWclose(stream);
|
||||||
return grp;
|
return grp;
|
||||||
}
|
}
|
||||||
|
GraphicPage createGRPF(int color, SDL_Surface *src)
|
||||||
|
{
|
||||||
|
SDL_Surface* surface = SDL_CreateRGBSurface(0, src.w, src.h, 32, 0, 0, 0, 0);
|
||||||
|
auto srcpixels = (cast(uint*)src.pixels);
|
||||||
|
auto pixels = (cast(uint*)surface.pixels);
|
||||||
|
for(int x = 0; x < src.w; x++)
|
||||||
|
{
|
||||||
|
for(int y = 0; y < src.h; y++)
|
||||||
|
{
|
||||||
|
ubyte r, g, b, a;
|
||||||
|
SDL_GetRGBA(*srcpixels, src.format, &r, &g, &b, &a);
|
||||||
|
//if(a == 0)
|
||||||
|
{
|
||||||
|
auto back = consoleColor[color];
|
||||||
|
r = back >> 16 & 0xFF;
|
||||||
|
g = back >> 8 & 0xFF;
|
||||||
|
b = back & 0xFF;
|
||||||
|
a = back >> 24 & 0xFF;
|
||||||
|
}
|
||||||
|
*pixels = SDL_MapRGBA(surface.format, r, g, b, a);
|
||||||
|
pixels++;
|
||||||
|
srcpixels++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new GraphicPage(surface);
|
||||||
|
}
|
||||||
|
GraphicPage createGRPF(int color, int colorFore, SDL_Surface *src)
|
||||||
|
{
|
||||||
|
SDL_Surface* surface = SDL_CreateRGBSurface(0, src.w, src.h, 32, 0, 0, 0, 0);
|
||||||
|
auto srcpixels = (cast(uint*)src.pixels);
|
||||||
|
auto pixels = (cast(uint*)surface.pixels);
|
||||||
|
for(int x = 0; x < src.w; x++)
|
||||||
|
{
|
||||||
|
for(int y = 0; y < src.h; y++)
|
||||||
|
{
|
||||||
|
ubyte r, g, b, a;
|
||||||
|
SDL_GetRGBA(*srcpixels, src.format, &r, &g, &b, &a);
|
||||||
|
if(r == 158 && g == 0 && b == 93 && a == 255)
|
||||||
|
{
|
||||||
|
auto back = consoleColor[color];
|
||||||
|
r = back >> 16 & 0xFF;
|
||||||
|
g = back >> 8 & 0xFF;
|
||||||
|
b = back & 0xFF;
|
||||||
|
a = back >> 24 & 0xFF;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//雑
|
||||||
|
auto fore = consoleColor[colorFore];
|
||||||
|
r = fore >> 16 & 0xFF;
|
||||||
|
g = fore >> 8 & 0xFF;
|
||||||
|
b = fore & 0xFF;
|
||||||
|
a = fore >> 24 & 0xFF;
|
||||||
|
}
|
||||||
|
*pixels = SDL_MapRGBA(surface.format, r, g, b, a);
|
||||||
|
pixels++;
|
||||||
|
srcpixels++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new GraphicPage(surface);
|
||||||
|
}
|
||||||
struct Point
|
struct Point
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
@@ -158,6 +222,20 @@ class PetitComputer
|
|||||||
fontFile);
|
fontFile);
|
||||||
}
|
}
|
||||||
GRPF = createGraphicPage(fontFile, 0);
|
GRPF = createGraphicPage(fontFile, 0);
|
||||||
|
GRPFColor = new GraphicPage[consoleColor.length];
|
||||||
|
GRPFColorFore = new GraphicPage[][consoleColor.length];
|
||||||
|
for(int i = 0; i < GRPFColor.length; i++)
|
||||||
|
{
|
||||||
|
GRPFColor[i] = createGRPF(i, GRPF.surface);
|
||||||
|
}
|
||||||
|
/+for(int i = 0; i < GRPFColor.length; i++)
|
||||||
|
{
|
||||||
|
GRPFColorFore[i] = new GraphicPage[consoleColor.length];
|
||||||
|
for(int j = 0; j < GRPFColor.length; j++)
|
||||||
|
{
|
||||||
|
GRPFColorFore[i][j] = createGRPF(i, j, GRPF.surface);
|
||||||
|
}
|
||||||
|
}+/
|
||||||
if(!exists(spriteFile))
|
if(!exists(spriteFile))
|
||||||
{
|
{
|
||||||
writeln("download sprite");
|
writeln("download sprite");
|
||||||
@@ -193,21 +271,80 @@ class PetitComputer
|
|||||||
{
|
{
|
||||||
console[i] = new ConsoleCharacter[consoleWidth];
|
console[i] = new ConsoleCharacter[consoleWidth];
|
||||||
console[i][] = ConsoleCharacter(0, consoleForeColor, consoleBackColor);
|
console[i][] = ConsoleCharacter(0, consoleForeColor, consoleBackColor);
|
||||||
/*
|
}
|
||||||
for(int j = 0; j < console[i].length; j++)
|
}
|
||||||
console[i][j] = '\0';*/
|
void cls()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < console.length; i++)
|
||||||
|
{
|
||||||
|
console[i][] = ConsoleCharacter(0, consoleForeColor, consoleBackColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_Renderer* renderer;
|
SDL_Renderer* renderer;
|
||||||
void run()
|
int vsyncFrame;
|
||||||
|
int vsyncCount;
|
||||||
|
void vsync(int f)
|
||||||
{
|
{
|
||||||
init();
|
vsyncCount = 0;
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
vsyncFrame = f;
|
||||||
SDL_Window* window = SDL_CreateWindow("SMILEBASIC", SDL_WINDOWPOS_UNDEFINED,
|
}
|
||||||
|
void render()
|
||||||
|
{
|
||||||
|
bool renderprofile;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
window = SDL_CreateWindow("SMILEBASIC", SDL_WINDOWPOS_UNDEFINED,
|
||||||
SDL_WINDOWPOS_UNDEFINED, 400, 240,
|
SDL_WINDOWPOS_UNDEFINED, 400, 240,
|
||||||
SDL_WINDOW_SHOWN);
|
SDL_WINDOW_SHOWN);
|
||||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||||
GRPF.createTexture(renderer);
|
GRPF.createTexture(renderer);
|
||||||
|
for(int i = 0; i < GRPFColor.length; i++)
|
||||||
|
{
|
||||||
|
GRPFColor[i].createTexture(renderer);
|
||||||
|
}
|
||||||
|
write("OK!");
|
||||||
|
SDL_Event event;
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
auto profile = SDL_GetTicks();
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
renderConsole;
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
auto a = (SDL_GetTicks() - profile);
|
||||||
|
if(renderprofile) writeln(a);
|
||||||
|
while (SDL_PollEvent(&event))
|
||||||
|
{
|
||||||
|
switch (event.type)
|
||||||
|
{
|
||||||
|
case SDL_QUIT:
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Throwable t)
|
||||||
|
{
|
||||||
|
writeln(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SDL_Window* window;
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
/+for(int i = 0; i < GRPFColor.length; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < GRPFColor.length; j++)
|
||||||
|
{
|
||||||
|
GRPFColorFore[i][j].createTexture(renderer);
|
||||||
|
}
|
||||||
|
}+/
|
||||||
//とりあえず
|
//とりあえず
|
||||||
auto parser = new Parser(/*readText("FIZZBUZZ.TXT").to!wstring*//*"
|
auto parser = new Parser(/*readText("FIZZBUZZ.TXT").to!wstring*//*"
|
||||||
?ABS(-1)
|
?ABS(-1)
|
||||||
@@ -219,7 +356,7 @@ NEXT
|
|||||||
DEF FACT(N)
|
DEF FACT(N)
|
||||||
IF N<=1 THEN RETURN 1
|
IF N<=1 THEN RETURN 1
|
||||||
RETURN N*FACT(N-1)
|
RETURN N*FACT(N-1)
|
||||||
END"*/
|
END"*//*
|
||||||
`CLS : CL=0 : Z=0
|
`CLS : CL=0 : Z=0
|
||||||
WHILE 1
|
WHILE 1
|
||||||
INC Z : IF Z>200 THEN Z=0
|
INC Z : IF Z>200 THEN Z=0
|
||||||
@@ -228,19 +365,31 @@ WHILE 1
|
|||||||
PRINT "★ 梅雨で雨が多い季節ですね ★"
|
PRINT "★ 梅雨で雨が多い季節ですね ★"
|
||||||
NEXT
|
NEXT
|
||||||
CL=(CL+1) MOD 16 : VSYNC 2
|
CL=(CL+1) MOD 16 : VSYNC 2
|
||||||
WEND`);
|
WEND`*/
|
||||||
|
`CLS : CL=0
|
||||||
|
@LOOP
|
||||||
|
FOR I=0 TO 15
|
||||||
|
LOCATE 9,4+I : COLOR (CL+I) MOD 16
|
||||||
|
PRINT "Ё プチコン3ゴウ Ж"
|
||||||
|
NEXT
|
||||||
|
CL=(CL+1) MOD 16 : VSYNC 1
|
||||||
|
GOTO @LOOP`
|
||||||
|
);
|
||||||
auto vm = parser.compile();
|
auto vm = parser.compile();
|
||||||
bool running = true;
|
bool running = true;
|
||||||
vm.init(this);
|
vm.init(this);
|
||||||
|
core.thread.Thread thread = new core.thread.Thread(&render);
|
||||||
|
thread.start();
|
||||||
|
auto startTicks = SDL_GetTicks();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
auto startTicks = SDL_GetTicks();
|
|
||||||
uint elapse;
|
uint elapse;
|
||||||
|
startTicks = SDL_GetTicks();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(running) running = vm.runStep();
|
if(!vsyncFrame && running) running = vm.runStep();
|
||||||
}
|
}
|
||||||
catch(SmileBasicError sbe)
|
catch(SmileBasicError sbe)
|
||||||
{
|
{
|
||||||
@@ -266,24 +415,8 @@ WEND`);
|
|||||||
}
|
}
|
||||||
elapse = SDL_GetTicks() - startTicks;
|
elapse = SDL_GetTicks() - startTicks;
|
||||||
} while(elapse <= 1000 / 60);
|
} while(elapse <= 1000 / 60);
|
||||||
SDL_Event event;
|
vsyncCount++;
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
if(vsyncFrame <= vsyncCount) vsyncFrame = 0;
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
renderConsole;
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
while (SDL_PollEvent(&event))
|
|
||||||
{
|
|
||||||
switch (event.type)
|
|
||||||
{
|
|
||||||
case SDL_QUIT:
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
SDL_Quit();
|
|
||||||
return;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
@@ -298,13 +431,29 @@ WEND`);
|
|||||||
for(int x = 0; x < consoleWidth; x++)
|
for(int x = 0; x < consoleWidth; x++)
|
||||||
{
|
{
|
||||||
SDL_Rect rect = SDL_Rect(x * 8, y * 8, 8, 8);
|
SDL_Rect rect = SDL_Rect(x * 8, y * 8, 8, 8);
|
||||||
auto back = consoleColor[console[y][x].backColor];
|
auto back = console[y][x].backColor;
|
||||||
SDL_SetRenderDrawColor(renderer, back >> 16 & 0xFF, back >> 8 & 0xFF, back & 0xFF, back >> 24 & 0xFF);
|
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
|
||||||
auto fore = consoleColor[console[y][x].foreColor];
|
auto fore = consoleColor[console[y][x].foreColor];
|
||||||
|
auto texture = GRPFColor[back].texture;
|
||||||
|
//SDL_RenderCopy(renderer, texture, &fontTable[console[y][x].charater], &rect);
|
||||||
SDL_SetTextureColorMod(GRPF.texture, fore >> 16 & 0xFF, fore >> 8 & 0xFF, fore & 0xFF);
|
SDL_SetTextureColorMod(GRPF.texture, fore >> 16 & 0xFF, fore >> 8 & 0xFF, fore & 0xFF);
|
||||||
SDL_SetTextureAlphaMod(GRPF.texture, fore >> 24 & 0xFF);
|
SDL_SetTextureAlphaMod(GRPF.texture, fore >> 24 & 0xFF);
|
||||||
SDL_RenderCopy(renderer, GRPF.texture, &fontTable[console[y][x].charater], &rect);
|
SDL_RenderCopy(renderer, GRPF.texture, &fontTable[console[y][x].charater], &rect);
|
||||||
|
/*
|
||||||
|
auto back = console[y][x].backColor;
|
||||||
|
auto fore = console[y][x].foreColor;
|
||||||
|
auto texture = GRPFColorFore[back][fore].texture;
|
||||||
|
SDL_RenderCopy(renderer, texture, &fontTable[console[y][x].charater], &rect);*/
|
||||||
|
/*
|
||||||
|
auto back = consoleColor[console[y][x].backColor];
|
||||||
|
auto texture = GRPFColor[back].texture;
|
||||||
|
SDL_RenderCopy(renderer, texture, &fontTable[console[y][x].charater], &rect);
|
||||||
|
texture = GRPF.texture;
|
||||||
|
//SDL_SetRenderDrawColor(renderer, back >> 16 & 0xFF, back >> 8 & 0xFF, back & 0xFF, back >> 24 & 0xFF);
|
||||||
|
//SDL_RenderFillRect(renderer, &rect);
|
||||||
|
auto fore = consoleColor[console[y][x].foreColor];
|
||||||
|
SDL_SetTextureColorMod(texture, fore >> 16 & 0xFF, fore >> 8 & 0xFF, fore & 0xFF);
|
||||||
|
SDL_SetTextureAlphaMod(texture, fore >> 24 & 0xFF);
|
||||||
|
SDL_RenderCopy(renderer, texture, &fontTable[console[y][x].charater], &rect);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void printConsole(T...)(T args)
|
void printConsole(T...)(T args)
|
||||||
|
|||||||
Reference in New Issue
Block a user