diff --git a/src-tests/nl/grauw/glass/SourceTest.java b/src-tests/nl/grauw/glass/SourceTest.java index df3a720..9f45a6c 100644 --- a/src-tests/nl/grauw/glass/SourceTest.java +++ b/src-tests/nl/grauw/glass/SourceTest.java @@ -783,6 +783,14 @@ public class SourceTest { " ENDS"); } + @Test + public void testFill() { + assertArrayEquals(b(0x3E, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x0A, 0x00), assemble( + " ld a,86H", + " fill 8H,0H", + " ld hl,$")); + } + public byte[] assemble(String... sourceLines) { StringBuilder builder = new StringBuilder(); for (String lineText : sourceLines) { diff --git a/src/nl/grauw/glass/GlobalScope.java b/src/nl/grauw/glass/GlobalScope.java index 3d3d09e..9eb1667 100644 --- a/src/nl/grauw/glass/GlobalScope.java +++ b/src/nl/grauw/glass/GlobalScope.java @@ -33,6 +33,7 @@ import nl.grauw.glass.instructions.Equ; import nl.grauw.glass.instructions.Error; import nl.grauw.glass.instructions.Ex; import nl.grauw.glass.instructions.Exx; +import nl.grauw.glass.instructions.Fill; import nl.grauw.glass.instructions.Halt; import nl.grauw.glass.instructions.Im; import nl.grauw.glass.instructions.In; @@ -106,13 +107,9 @@ public class GlobalScope extends Scope { addBuiltInSymbol("cpir", new Instruction(new Cpir())); addBuiltInSymbol("cpl", new Instruction(new Cpl())); addBuiltInSymbol("daa", new Instruction(new Daa())); - addBuiltInSymbol("db", new Instruction(new Db())); - addBuiltInSymbol("dd", new Instruction(new Dd())); addBuiltInSymbol("dec", new Instruction(new Dec())); addBuiltInSymbol("di", new Instruction(new Di())); addBuiltInSymbol("djnz", new Instruction(new Djnz())); - addBuiltInSymbol("ds", new Instruction(new Ds())); - addBuiltInSymbol("dw", new Instruction(new Dw())); addBuiltInSymbol("ei", new Instruction(new Ei())); addBuiltInSymbol("ex", new Instruction(new Ex())); addBuiltInSymbol("exx", new Instruction(new Exx())); @@ -167,6 +164,13 @@ public class GlobalScope extends Scope { addBuiltInSymbol("sub", new Instruction(new Sub())); addBuiltInSymbol("xor", new Instruction(new Xor())); + addBuiltInSymbol("db", new Instruction(new Db())); + addBuiltInSymbol("dd", new Instruction(new Dd())); + addBuiltInSymbol("ds", new Instruction(new Ds())); + addBuiltInSymbol("dw", new Instruction(new Dw())); + addBuiltInSymbol("byte", new Instruction(new Db())); + addBuiltInSymbol("word", new Instruction(new Dw())); + addBuiltInSymbol("include", new Instruction(new Include())); addBuiltInSymbol("equ", new Instruction(new Equ())); addBuiltInSymbol("org", new Instruction(new Org())); @@ -178,6 +182,27 @@ public class GlobalScope extends Scope { addBuiltInSymbol("else", new Instruction(new Else())); addBuiltInSymbol("error", new Instruction(new Error())); addBuiltInSymbol("warning", new Instruction(new Warning())); + addBuiltInSymbol("fill", new Instruction(new Fill())); + + addBuiltInSymbol(".db", new Instruction(new Db())); + addBuiltInSymbol(".dd", new Instruction(new Dd())); + addBuiltInSymbol(".ds", new Instruction(new Ds())); + addBuiltInSymbol(".dw", new Instruction(new Dw())); + addBuiltInSymbol(".byte", new Instruction(new Db())); + addBuiltInSymbol(".word", new Instruction(new Dw())); + + addBuiltInSymbol(".include", new Instruction(new Include())); + addBuiltInSymbol(".equ", new Instruction(new Equ())); + addBuiltInSymbol(".org", new Instruction(new Org())); + addBuiltInSymbol(".endm", new Instruction(new Endm())); + addBuiltInSymbol(".endp", new Instruction(new Endp())); + addBuiltInSymbol(".ends", new Instruction(new Ends())); + addBuiltInSymbol(".end", new Instruction(new End())); + addBuiltInSymbol(".endif", new Instruction(new Endif())); + addBuiltInSymbol(".else", new Instruction(new Else())); + addBuiltInSymbol(".error", new Instruction(new Error())); + addBuiltInSymbol(".warning", new Instruction(new Warning())); + addBuiltInSymbol(".fill", new Instruction(new Fill())); } private void addBuiltInSymbol(String symbol, Expression value) { diff --git a/src/nl/grauw/glass/SourceBuilder.java b/src/nl/grauw/glass/SourceBuilder.java index 3daf289..8befe34 100644 --- a/src/nl/grauw/glass/SourceBuilder.java +++ b/src/nl/grauw/glass/SourceBuilder.java @@ -155,35 +155,55 @@ public class SourceBuilder { switch (line.getMnemonic()) { case "equ": case "EQU": + case ".equ": + case ".EQU": return new Equ(); case "include": case "INCLUDE": + case ".include": + case ".INCLUDE": return getIncludeDirective(line, sourceFile); case "incbin": case "INCBIN": + case ".incbin": + case ".INCBIN": return new Incbin(sourceFile, includePaths); case "macro": case "MACRO": + case ".macro": + case ".MACRO": return new Macro(parseBlock(line.getScope(), ENDM_TERMINATORS, reader, sourceFile)); case "rept": case "REPT": + case ".rept": + case ".REPT": return new Rept(parseBlock(line.getScope(), ENDM_TERMINATORS, reader, sourceFile)); case "irp": case "IRP": + case ".irp": + case ".IRP": return new Irp(parseBlock(line.getScope(), ENDM_TERMINATORS, reader, sourceFile)); case "proc": case "PROC": + case ".proc": + case ".PROC": return new Proc(parseBlock(line.getScope(), ENDP_TERMINATORS, reader, sourceFile)); case "if": case "IF": + case ".if": + case ".IF": Source thenBlock = parseBlock(source.getScope(), ELSE_TERMINATORS, reader, sourceFile); Source elseBlock = !ENDIF_TERMINATORS.contains(thenBlock.getLastLine().getMnemonic()) ? parseBlock(source.getScope(), ENDIF_TERMINATORS, reader, sourceFile) : null; return new If(thenBlock, elseBlock); case "section": case "SECTION": + case ".section": + case ".SECTION": return new Section(parseBlock(source.getScope(), ENDS_TERMINATORS, reader, sourceFile)); case "ds": case "DS": + case ".ds": + case ".DS": return new Ds(); case "endm": case "ENDM": @@ -191,6 +211,12 @@ public class SourceBuilder { case "ENDP": case "ends": case "ENDS": + case ".endm": + case ".ENDM": + case ".endp": + case ".ENDP": + case ".ends": + case ".ENDS": if (!terminators.contains(line.getMnemonic())) { throw new AssemblyException("Unexpected " + line.getMnemonic() + "."); } diff --git a/src/nl/grauw/glass/instructions/Fill.java b/src/nl/grauw/glass/instructions/Fill.java new file mode 100644 index 0000000..9c028fd --- /dev/null +++ b/src/nl/grauw/glass/instructions/Fill.java @@ -0,0 +1,46 @@ +package nl.grauw.glass.instructions; + +import java.util.Arrays; + +import nl.grauw.glass.Scope; +import nl.grauw.glass.expressions.Expression; +import nl.grauw.glass.expressions.Schema; + +public class Fill extends InstructionFactory { + + public static Schema ARGUMENTS_N_N = new Schema(Schema.INTEGER, Schema.INTEGER); + + @Override + public InstructionObject createObject(Scope context, Expression arguments) { + if (ARGUMENTS_N_N.check(arguments)) { + return new Fill_N_N(context, arguments.getElement(0), arguments.getElement(1)); + } + throw new ArgumentException(); + } + + public class Fill_N_N extends InstructionObject { + + private final Expression size; + private final Expression value; + + public Fill_N_N(Scope context, Expression size, Expression value) { + super(context); + this.size = size; + this.value = value; + } + + @Override + public int getSize() { + return size.getInteger(); + } + + @Override + public byte[] getBytes() { + byte[] bytes = new byte[size.getInteger()]; + Arrays.fill(bytes, (byte) value.getInteger()); + return bytes; + } + + } + +}