From a50e50c1e86c721434a175fef639a12ed7c98b71 Mon Sep 17 00:00:00 2001 From: otya128 Date: Fri, 30 Dec 2016 20:27:11 +0900 Subject: [PATCH] Implement SCROLL --- SMILEBASIC/builtinfunctions.d | 4 +++ SMILEBASIC/console.d | 63 +++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 70ea94b..2a0af62 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -3366,6 +3366,10 @@ class BuiltinFunction { p.console.initGRPF(); } + static void SCROLL(PetitComputer p, int x, int y) + { + p.console.scroll(x, y); + } //alias void function(PetitComputer, Value[], Value[]) BuiltinFunc; static BuiltinFunctions[wstring] builtinFunctions; static wstring getBasicName(BFD)(const wstring def) diff --git a/SMILEBASIC/console.d b/SMILEBASIC/console.d index e7d7cd5..1ee1375 100644 --- a/SMILEBASIC/console.d +++ b/SMILEBASIC/console.d @@ -497,6 +497,69 @@ class Console consoleC[consoleHeightC - 1] = tmp; tmp[] = ConsoleCharacter(0, foreColor, backColor, attr, CSRZ); } + import std.range; + void tonikakusugokutesutekinasaikyounaFill(T, T2)(T input, T2 v) + { + foreach (ref e; input) + { + e[] = v; + } + } + void scroll(int x, int y) + { + import std.math; + if (abs(x) >= consoleWidthC) + { + auto oldCSRX = CSRX; + auto oldCSRY = CSRY; + auto oldCSRZ = CSRZ; + cls(); + CSRX = oldCSRX; + CSRY = oldCSRY; + CSRZ = oldCSRZ; + return; + } + if (abs(y) >= consoleHeightC) + { + cls(); + return; + } + for (int i = 0; i < consoleHeightC; i++) + { + if (x > 0) + { + for (int j = x; j < consoleWidthC; j++) + { + consoleC[i][j - x] = consoleC[i][j]; + } + consoleC[i][$ - x..$] = ConsoleCharacter(0, foreColor, backColor); + } + else if (x < 0) + { + for (int j = consoleWidthC - 1; j >= -x; j--) + { + consoleC[i][j] = consoleC[i][j + x]; + } + consoleC[i][0..-x] = ConsoleCharacter(0, foreColor, backColor); + } + } + if (y > 0) + { + for (int i = y; i < consoleHeightC; i++) + { + consoleC[i - y][] = consoleC[i][]; + } + tonikakusugokutesutekinasaikyounaFill(consoleC[$ - y..$], ConsoleCharacter(0, foreColor, backColor)); + } + else if (y < 0) + { + for (int i = consoleHeightC - 1; i >= -y; i--) + { + consoleC[i][] = consoleC[i + y][]; + } + tonikakusugokutesutekinasaikyounaFill(consoleC[0..-y], ConsoleCharacter(0, foreColor, backColor)); + } + } bool canDefine(ushort a) { return fontTable[a].define;