1
0

Implement ATTR function

This commit is contained in:
otya128
2016-12-04 17:27:51 +09:00
parent 8907277290
commit 19a20f7c5a
3 changed files with 94 additions and 41 deletions

View File

@@ -231,6 +231,12 @@ class BuiltinFunction
p.console.consoleForeColor = cast(int)fore; p.console.consoleForeColor = cast(int)fore;
p.console.consoleBackColor = cast(int)back; p.console.consoleBackColor = cast(int)back;
} }
static void ATTR(PetitComputer p, int attr)
{
if (attr < 0 || attr > 15)
throw new OutOfRange("ATTR", 1);
p.console.attr = cast(otya.smilebasic.console.ConsoleAttribute)attr;
}
static void VSYNC(PetitComputer p, DefaultValue!int time) static void VSYNC(PetitComputer p, DefaultValue!int time)
{ {
time.setDefaultValue(1); time.setDefaultValue(1);

View File

@@ -16,10 +16,20 @@ struct ConsoleCharacter
wchar character; wchar character;
int foreColor; int foreColor;
int backColor; int backColor;
byte attr; ConsoleAttribute attr;
int z; int z;
} }
enum ConsoleAttribute
{
TROT0 = 0,
TROT90 = 1,
TROT180= 2,
TROT270 = 3,
TREVH = 4,
TREVV = 8,
}
class Console class Console
{ {
@@ -176,6 +186,71 @@ class Console
consoleWidthC = consoleWidth; consoleWidthC = consoleWidth;
consoleC = console; consoleC = console;
} }
void drawCharacter(int x, int y, ConsoleCharacter ch)
{
import std.algorithm.mutation : swap;
auto fore = consoleColorGL[ch.foreColor];
auto rect = &fontTable[ch.character];
ConsoleAttribute rot = ch.attr & ConsoleAttribute.TROT270;
int z = ch.z;
glColor4ubv(cast(ubyte*)&fore);
float tx1 = (rect.x) / 512f - 1;
float ty1 = (rect.y + 8) / 512f - 1;
float tx2 = (rect.x + 8) / 512f - 1;
float ty2 = (rect.y) / 512f - 1;
int x1 = x * 8;
int x2 = x * 8 + 8;
int y1 = y * 8;
int y2 = y * 8 + 8;
if (ch.attr & ConsoleAttribute.TREVH)
swap(x1, x2);
if (ch.attr & ConsoleAttribute.TREVV)
swap(y1, y2);
if (rot == ConsoleAttribute.TROT0)
{
glTexCoord2f(tx1 , ty1);
glVertex3i(x1, y2, z);
glTexCoord2f(tx1, ty2);
glVertex3i(x1, y1, z);
glTexCoord2f(tx2, ty2);
glVertex3i(x2, y1, z);
glTexCoord2f(tx2, ty1);
glVertex3i(x2, y2, z);
}
if (rot == ConsoleAttribute.TROT90)
{
glTexCoord2f(tx2, ty1);
glVertex3i(x1, y2, z);
glTexCoord2f(tx1 , ty1);
glVertex3i(x1, y1, z);
glTexCoord2f(tx1, ty2);
glVertex3i(x2, y1, z);
glTexCoord2f(tx2, ty2);
glVertex3i(x2, y2, z);
}
if (rot == ConsoleAttribute.TROT180)
{
glTexCoord2f(tx2, ty2);
glVertex3i(x1, y2, z);
glTexCoord2f(tx2, ty1);
glVertex3i(x1, y1, z);
glTexCoord2f(tx1 , ty1);
glVertex3i(x2, y1, z);
glTexCoord2f(tx1, ty2);
glVertex3i(x2, y2, z);
}
if (rot == ConsoleAttribute.TROT270)
{
glTexCoord2f(tx1, ty2);
glVertex3i(x1, y2, z);
glTexCoord2f(tx2, ty2);
glVertex3i(x1, y1, z);
glTexCoord2f(tx2, ty1);
glVertex3i(x2, y1, z);
glTexCoord2f(tx1 , ty1);
glVertex3i(x2, y2, z);
}
}
void render() void render()
{ {
if(petitcom.xscreenmode == 2) if(petitcom.xscreenmode == 2)
@@ -211,18 +286,7 @@ class Console
for(int y = 0; y < consoleHeight4; y++) for(int y = 0; y < consoleHeight4; y++)
for(int x = 0; x < consoleWidth4; x++) for(int x = 0; x < consoleWidth4; x++)
{ {
auto fore = consoleColorGL[console4[y][x].foreColor]; drawCharacter(x, y, console4[y][x]);
auto rect = &fontTable[console4[y][x].character];
glColor4ubv(cast(ubyte*)&fore);
int z = console4[y][x].z;
glTexCoord2f((rect.x) / 512f - 1 , (rect.y + 8) / 512f - 1);
glVertex3f((x * 8), (y * 8 + 8), z);
glTexCoord2f((rect.x) / 512f - 1, (rect.y) / 512f - 1);
glVertex3f((x * 8), (y * 8), z);
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y) / 512f - 1);
glVertex3f((x * 8 + 8), (y * 8), z);
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y +8) / 512f - 1);
glVertex3f((x * 8 + 8), (y * 8 + 8), z);
} }
glEnd(); glEnd();
return; return;
@@ -258,18 +322,7 @@ class Console
for(int y = 0; y < consoleHeight; y++) for(int y = 0; y < consoleHeight; y++)
for(int x = 0; x < consoleWidth; x++) for(int x = 0; x < consoleWidth; x++)
{ {
auto fore = consoleColorGL[console[y][x].foreColor]; drawCharacter(x, y, console[y][x]);
auto rect = &fontTable[console[y][x].character];
float z = console[y][x].z;
glColor4ubv(cast(ubyte*)&fore);
glTexCoord2f((rect.x) / 512f - 1 , (rect.y + 8) / 512f - 1);
glVertex3f((x * 8), (y * 8 + 8), z);
glTexCoord2f((rect.x) / 512f - 1, (rect.y) / 512f - 1);
glVertex3f((x * 8), (y * 8), z);
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y) / 512f - 1);
glVertex3f((x * 8 + 8), (y * 8), z);
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y +8) / 512f - 1);
glVertex3f((x * 8 + 8), (y * 8 + 8), z);
} }
glEnd(); glEnd();
if(petitcom.xscreenmode != 1) if(petitcom.xscreenmode != 1)
@@ -309,18 +362,7 @@ class Console
for(int y = 0; y < consoleHeightDisplay1; y++) for(int y = 0; y < consoleHeightDisplay1; y++)
for(int x = 0; x < consoleWidthDisplay1; x++) for(int x = 0; x < consoleWidthDisplay1; x++)
{ {
auto fore = consoleColorGL[consoleDisplay1[y][x].foreColor]; drawCharacter(x, y, consoleDisplay1[y][x]);
auto rect = &fontTable[consoleDisplay1[y][x].character];
float z = consoleDisplay1[y][x].z;
glColor4ubv(cast(ubyte*)&fore);
glTexCoord2f((rect.x) / 512f - 1 , (rect.y + 8) / 512f - 1);
glVertex3f((x * 8), (y * 8 + 8), z);
glTexCoord2f((rect.x) / 512f - 1, (rect.y) / 512f - 1);
glVertex3f((x * 8), (y * 8), z);
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y) / 512f - 1);
glVertex3f((x * 8 + 8), (y * 8), z);
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y +8) / 512f - 1);
glVertex3f((x * 8 + 8), (y * 8 + 8), z);
} }
glEnd(); glEnd();
} }
@@ -333,7 +375,7 @@ class Console
} }
//0<=TABSTEP<=16 //0<=TABSTEP<=16
int TABSTEP = 4; int TABSTEP = 4;
byte consoleAttr; ConsoleAttribute attr;
int tab; int tab;
void printString(wstring text) void printString(wstring text)
{ {
@@ -356,7 +398,7 @@ class Console
else else
{ {
auto t = min(CSRX + TABSTEP - CSRX % TABSTEP, consoleWidthC - 1); auto t = min(CSRX + TABSTEP - CSRX % TABSTEP, consoleWidthC - 1);
consoleC[CSRY][CSRX..t] = ConsoleCharacter(0, consoleForeColor, consoleBackColor, consoleAttr, CSRZ); consoleC[CSRY][CSRX..t] = ConsoleCharacter(0, consoleForeColor, consoleBackColor, attr, CSRZ);
CSRX += TABSTEP - (CSRX % TABSTEP) - 1; CSRX += TABSTEP - (CSRX % TABSTEP) - 1;
if(CSRX + 1 >= consoleWidthC) if(CSRX + 1 >= consoleWidthC)
{ {
@@ -367,7 +409,7 @@ class Console
} }
else if(c != '\n') else if(c != '\n')
{ {
consoleC[CSRY][CSRX] = ConsoleCharacter(c, consoleForeColor, consoleBackColor, consoleAttr, CSRZ); consoleC[CSRY][CSRX] = ConsoleCharacter(c, consoleForeColor, consoleBackColor, attr, CSRZ);
tab = tab ? 2 : 0; tab = tab ? 2 : 0;
} }
CSRX++; CSRX++;
@@ -384,7 +426,7 @@ class Console
consoleC[i] = consoleC[i + 1]; consoleC[i] = consoleC[i + 1];
} }
consoleC[consoleHeightC - 1] = tmp; consoleC[consoleHeightC - 1] = tmp;
tmp[] = ConsoleCharacter(0, consoleForeColor, consoleBackColor, consoleAttr, CSRZ); tmp[] = ConsoleCharacter(0, consoleForeColor, consoleBackColor, attr, CSRZ);
CSRY = consoleHeightC - 1; CSRY = consoleHeightC - 1;
} }
} }

View File

@@ -87,6 +87,11 @@ class OutOfRange : SmileBasicError
this.errnum = 10; this.errnum = 10;
super("Out of range"); super("Out of range");
} }
this(string func, int arg)
{
this.errnum = 10;
super("Out of range(" ~ func ~ ":" ~ arg.to!string ~ ")");
}
} }
class OutOfDATA : SmileBasicError class OutOfDATA : SmileBasicError
{ {