1
0

Add LOCATE range check

This commit is contained in:
otya128
2017-01-21 22:33:59 +09:00
parent d1b3b78321
commit 025fb673d4

View File

@@ -245,14 +245,24 @@ class BuiltinFunction
//static ABS = function double(double x) => abs(this.result == ValueType.Double ? 1 : 0); //static ABS = function double(double x) => abs(this.result == ValueType.Double ? 1 : 0);
static void LOCATE(PetitComputer p, DefaultValue!int x, DefaultValue!int y, int z) static void LOCATE(PetitComputer p, DefaultValue!int x, DefaultValue!int y, int z)
{ {
if (!x.isDefault && x < 0 || x >= p.console.consoleWidthC)
throw new OutOfRange(smilebasicFunctionName, 1);
if (!y.isDefault && y < 0 || y >= p.console.consoleHeightC)
throw new OutOfRange(smilebasicFunctionName, 2);
x.setDefaultValue(p.console.CSRX); x.setDefaultValue(p.console.CSRX);
y.setDefaultValue(p.console.CSRY); y.setDefaultValue(p.console.CSRY);
if (z < -256 || z > 1024)
throw new OutOfRange(smilebasicFunctionName, 3);
p.console.CSRX = cast(int)x; p.console.CSRX = cast(int)x;
p.console.CSRY = cast(int)y; p.console.CSRY = cast(int)y;
p.console.CSRZ = cast(int)z; p.console.CSRZ = cast(int)z;
} }
static void LOCATE(PetitComputer p, DefaultValue!int x, DefaultValue!int y) static void LOCATE(PetitComputer p, DefaultValue!int x, DefaultValue!int y)
{ {
if (!x.isDefault && x < 0 || x >= p.console.consoleWidthC)
throw new OutOfRange(smilebasicFunctionName, 1);
if (!y.isDefault && y < 0 || y >= p.console.consoleHeightC)
throw new OutOfRange(smilebasicFunctionName, 2);
x.setDefaultValue(p.console.CSRX); x.setDefaultValue(p.console.CSRX);
y.setDefaultValue(p.console.CSRY); y.setDefaultValue(p.console.CSRY);
p.console.CSRX = cast(int)x; p.console.CSRX = cast(int)x;