From 5cee75af6f705c0b1a30d713c64927289934e254 Mon Sep 17 00:00:00 2001 From: otya128 Date: Tue, 13 Dec 2016 23:24:44 +0900 Subject: [PATCH] Implement GSAVE --- SMILEBASIC/builtinfunctions.d | 49 +++++++++++++++++++++++++++++++++++ SMILEBASIC/graphic.d | 41 +++++++++++++++++++++++++++-- SMILEBASIC/type.d | 9 +++++++ 3 files changed, 97 insertions(+), 2 deletions(-) diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 9f8a89a..a2861c2 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -538,6 +538,55 @@ class BuiltinFunction { 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) { } diff --git a/SMILEBASIC/graphic.d b/SMILEBASIC/graphic.d index d7fd2ff..f7a067a 100644 --- a/SMILEBASIC/graphic.d +++ b/SMILEBASIC/graphic.d @@ -554,13 +554,50 @@ class Graphic } int gspoit(int page, int x, int y) { - glBindFramebufferEXT(GL_FRAMEBUFFER, this.GRP[page].buffer); int ui; //flush - updateVM(); + //if (drc) + // glFinish(); + //drc = 0; glReadPixels(x, y, 1, 1, GRP[page].textureFormat, GL_UNSIGNED_BYTE, &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; void render() { diff --git a/SMILEBASIC/type.d b/SMILEBASIC/type.d index abb40a7..a865308 100644 --- a/SMILEBASIC/type.d +++ b/SMILEBASIC/type.d @@ -388,5 +388,14 @@ class Array(T) array ~= v; dim[0]++; } + @property void length(int size) + { + if (dimCount != 1) + { + throw new TypeMismatch(); + } + array.length = size; + dim[0] = size; + } }