Implement GSAVE
This commit is contained in:
@@ -538,6 +538,55 @@ class BuiltinFunction
|
|||||||
{
|
{
|
||||||
return p.graphic.gspoit(p.graphic.useGRP, x, y);
|
return p.graphic.gspoit(p.graphic.useGRP, x, y);
|
||||||
}
|
}
|
||||||
|
static void GSAVE(PetitComputer p, int savepage, int x, int y, int w, int h, Value ary, int flag)
|
||||||
|
{
|
||||||
|
if (w < 0)
|
||||||
|
throw new OutOfRange("GSAVE", 4);
|
||||||
|
if (h < 0)
|
||||||
|
throw new OutOfRange("GSAVE", 5);
|
||||||
|
if (!ary.isNumberArray)
|
||||||
|
throw new TypeMismatch("GSAVE", 6);
|
||||||
|
int size = w * h;
|
||||||
|
if (ary.type == ValueType.IntegerArray)
|
||||||
|
{
|
||||||
|
if (size > ary.length)
|
||||||
|
{
|
||||||
|
ary.integerArray.length = size;
|
||||||
|
}
|
||||||
|
p.graphic.gsave(savepage, x, y, w, h, ary.integerArray.array, flag);
|
||||||
|
}
|
||||||
|
else if (ary.type == ValueType.DoubleArray)
|
||||||
|
{
|
||||||
|
if (size > ary.length)
|
||||||
|
{
|
||||||
|
ary.doubleArray.length = size;
|
||||||
|
}
|
||||||
|
p.graphic.gsave(savepage, x, y, w, h, ary.doubleArray.array, flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void GSAVE(PetitComputer p, int x, int y, int w, int h, Value ary, int flag)
|
||||||
|
{
|
||||||
|
if (w < 0)
|
||||||
|
throw new OutOfRange("GSAVE", 3);
|
||||||
|
if (h < 0)
|
||||||
|
throw new OutOfRange("GSAVE", 4);
|
||||||
|
if (!ary.isNumberArray)
|
||||||
|
throw new TypeMismatch("GSAVE", 5);
|
||||||
|
GSAVE(p, p.graphic.useGRP, x, y, w, h, ary, flag);
|
||||||
|
}
|
||||||
|
static void GSAVE(PetitComputer p, int savepage, Value ary, int flag)
|
||||||
|
{
|
||||||
|
if (!ary.isNumberArray)
|
||||||
|
throw new TypeMismatch("GSAVE", 2);
|
||||||
|
auto writeArea = p.graphic.writeArea[p.displaynum];
|
||||||
|
GSAVE(p, savepage, writeArea.x, writeArea.y, writeArea.w, writeArea.h, ary, flag);
|
||||||
|
}
|
||||||
|
static void GSAVE(PetitComputer p, Value ary, int flag)
|
||||||
|
{
|
||||||
|
if (!ary.isNumberArray)
|
||||||
|
throw new TypeMismatch("GSAVE", 1);
|
||||||
|
GSAVE(p, p.graphic.useGRP, ary, flag);
|
||||||
|
}
|
||||||
static void BGMPLAY(PetitComputer p, int music)
|
static void BGMPLAY(PetitComputer p, int music)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -554,13 +554,50 @@ class Graphic
|
|||||||
}
|
}
|
||||||
int gspoit(int page, int x, int y)
|
int gspoit(int page, int x, int y)
|
||||||
{
|
{
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER, this.GRP[page].buffer);
|
|
||||||
int ui;
|
int ui;
|
||||||
//flush
|
//flush
|
||||||
updateVM();
|
//if (drc)
|
||||||
|
// glFinish();
|
||||||
|
//drc = 0;
|
||||||
glReadPixels(x, y, 1, 1, GRP[page].textureFormat, GL_UNSIGNED_BYTE, &ui);
|
glReadPixels(x, y, 1, 1, GRP[page].textureFormat, GL_UNSIGNED_BYTE, &ui);
|
||||||
return ui;
|
return ui;
|
||||||
}
|
}
|
||||||
|
void gsave(int savepage, int x, int y, int w, int h, double[] array, int flag)
|
||||||
|
{
|
||||||
|
if (w * h > array.length)
|
||||||
|
return;
|
||||||
|
gsave(savepage, x, y, w, h, cast(int[])paint.buffer, flag);
|
||||||
|
for (int i = 0; i < array.length; i++)
|
||||||
|
{
|
||||||
|
array[i] = cast(double)cast(int)paint.buffer[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void gsave(int savepage, int x, int y, int w, int h, int[] array, int flag)
|
||||||
|
{
|
||||||
|
if (w * h > array.length)
|
||||||
|
return;
|
||||||
|
//endian?
|
||||||
|
if (false && flag)//0=32bit
|
||||||
|
{
|
||||||
|
glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, array.ptr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glReadPixels(x, y, w, h, GL_BGRA, GL_UNSIGNED_BYTE, array.ptr);
|
||||||
|
}
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
//ARRRRRGGGGGBBBBB
|
||||||
|
for (int i = 0; i < array.length; i++)
|
||||||
|
{
|
||||||
|
auto a = (array[i] & 0xFF000000) >> 24;
|
||||||
|
auto r = (array[i] & 0x00FF0000) >> 16;
|
||||||
|
auto g = (array[i] & 0x0000FF00) >> 8;
|
||||||
|
auto b = (array[i] & 0x000000FF);
|
||||||
|
array[i] = (a == 255) | r >> 3 << 11 | g >> 3 << 6 | b >> 3 << 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
int gprio;
|
int gprio;
|
||||||
void render()
|
void render()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -388,5 +388,14 @@ class Array(T)
|
|||||||
array ~= v;
|
array ~= v;
|
||||||
dim[0]++;
|
dim[0]++;
|
||||||
}
|
}
|
||||||
|
@property void length(int size)
|
||||||
|
{
|
||||||
|
if (dimCount != 1)
|
||||||
|
{
|
||||||
|
throw new TypeMismatch();
|
||||||
|
}
|
||||||
|
array.length = size;
|
||||||
|
dim[0] = size;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user