diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 11c19f4..83b9ef1 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -3198,6 +3198,19 @@ class BuiltinFunction } p.program.delete_(count); } + static int PRGSIZE(PetitComputer p) + { + return PRGSIZE(p, p.vm.currentSlotNumber, 0); + } + static int PRGSIZE(PetitComputer p, int slot) + { + return PRGSIZE(p, slot, 0); + } + static int PRGSIZE(PetitComputer p, int slot, int type) + { + import otya.smilebasic.program; + return p.program.size(slot, cast(SizeType)type); + } //alias void function(PetitComputer, Value[], Value[]) BuiltinFunc; static BuiltinFunctions[wstring] builtinFunctions; static wstring getBasicName(BFD)(const wstring def) diff --git a/SMILEBASIC/program.d b/SMILEBASIC/program.d index e85f8f6..f50c677 100644 --- a/SMILEBASIC/program.d +++ b/SMILEBASIC/program.d @@ -3,7 +3,6 @@ import otya.smilebasic.error; import std.range; import std.container; import std.algorithm; -import std.algorithm; unittest { @@ -161,6 +160,13 @@ unittest assert(slot.get() == ""); } +enum SizeType +{ + Line = 0, + Char = 1, + FreeChar = 2, +} + struct Slot { DList!wstring program; @@ -312,6 +318,21 @@ struct Slot range = program.linearRemove(range.take(count)); } } + int memorySize = 1048476;//WiiU..? + int size(SizeType type) + { + switch(type) + { + case SizeType.Line: + return program[].walkLength; + case SizeType.Char: + return program[].map!(x => x.length).sum; + case SizeType.FreeChar: + return (memorySize - program[].map!(x => x.length).sum).max(0); + default: + throw new OutOfRange("PRGSIZE", 2); + } + } } class Program @@ -358,4 +379,8 @@ class Program throw new UsePRGEDITBeforeAnyPRGFunction("PRGDEL"); this.slot[currentSlot].delete_(count); } + int size(int slot, SizeType st) + { + return this.slot[slot].size(st); + } }