From 5995fcb7b4989e1a114e931f22e4fb305cff6a21 Mon Sep 17 00:00:00 2001 From: otya128 Date: Sat, 22 Jul 2017 12:41:40 +0900 Subject: [PATCH] Implement BGFILL(string) --- SMILEBASIC/bg.d | 18 ++++++++++++++++++ SMILEBASIC/builtinfunctions.d | 31 +++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/SMILEBASIC/bg.d b/SMILEBASIC/bg.d index 8a4d192..24461cc 100644 --- a/SMILEBASIC/bg.d +++ b/SMILEBASIC/bg.d @@ -213,6 +213,24 @@ class BG chip[i + y * width].i = id; }*/ } + void fill(int x, int y, int x2, int y2, ushort[] screendata) + { + import std.algorithm; + if(x > x2) swap(x, x2); + if(y > y2) swap(y, y2); + int index = 0; + if (screendata.length == 0) + { + fill(x, y, x2, y2, 0); + return; + } + for(; y <= y2; y++) + for(int i = x; i <= x2; i++) + { + chip[i + y * width] = BGChip(screendata[index] & 4095); + index = (index + 1) % screendata.length; + } + } int get(int x, int y, int flag) { if (flag) diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 2b9e3c0..c2d5696 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -2608,13 +2608,40 @@ class BuiltinFunction } return p.getBG(layer).rot; } - static void BGFILL(PetitComputer p, int layer, int x, int y, int x2, int y2, int screendata) + static void BGFILL(PetitComputer p, int layer, int x, int y, int x2, int y2, Value sd) { if (!p.isValidLayer(layer)) { throw new OutOfRange("BGFILL", 1); } - p.getBG(layer).fill(x, y, x2, y2, screendata); + if (sd.type == ValueType.String) + { + wstring screendata = sd.castDString; + if (screendata.length % 4 != 0) + { + throw new IllegalFunctionCall("BGFILL", 6); + } + ushort[] screendatas = new ushort[screendata.length / 4]; + for (int i = 0; i < screendata.length; i += 4) + { + ushort a; + auto b = screendata[i..i + 4]; + if (!tryParse(b, 16, a)) + { + throw new IllegalFunctionCall("BGFILL", 6); + } + screendatas[i / 4] = a; + } + p.getBG(layer).fill(x, y, x2, y2, screendatas); + } + else if (sd.isNumber) + { + p.getBG(layer).fill(x, y, x2, y2, sd.castInteger); + } + else + { + throw new TypeMismatch("BGFILL", 6); + } } static void BGPAGE(PetitComputer p, int page) {