From eeda288b291e9dafe90092ef7c262f4f1016fb79 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 17 Dec 2017 17:21:06 +0000 Subject: [PATCH] Add break Don't use this instruction unless you know what you're doing. It does *not* touch the if/call stacks, so the following code will behave in an unexpected way (and cannot be fixed by inserting nops): ``` ifu true for ... ifu true break .end .end .else ; will be executed since the inner if is still on the stack .end ``` breakc has the same problem but does not require a separate condition. --- Manual.md | 1 + source/maestro_opcodes.h | 2 +- source/picasso_assembler.cpp | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Manual.md b/Manual.md index a30da01..6381adc 100644 --- a/Manual.md +++ b/Manual.md @@ -319,6 +319,7 @@ Syntax | Description `cmp rSrc1, opx, opy, rSrc2` | `call procName` | `for iReg` | +`break` | (not recommended) `breakc condExp` | `callc condExp, procName` | `ifc condExp` | diff --git a/source/maestro_opcodes.h b/source/maestro_opcodes.h index 67981c2..de8cff0 100644 --- a/source/maestro_opcodes.h +++ b/source/maestro_opcodes.h @@ -35,7 +35,7 @@ enum MAESTRO_unk1E, MAESTRO_unk1F, - MAESTRO_unk20, + MAESTRO_BREAK, MAESTRO_NOP, MAESTRO_END, MAESTRO_BREAKC, diff --git a/source/picasso_assembler.cpp b/source/picasso_assembler.cpp index bb6360d..48afaa2 100644 --- a/source/picasso_assembler.cpp +++ b/source/picasso_assembler.cpp @@ -1242,6 +1242,7 @@ static const cmdTableType cmdTable[] = DEC_COMMAND(NOP, format0), DEC_COMMAND(END, format0), DEC_COMMAND(EMIT, format0), + DEC_COMMAND(BREAK, format0), DEC_COMMAND(ADD, format1), DEC_COMMAND(DP3, format1), @@ -1373,6 +1374,7 @@ DEF_DIRECTIVE(end) u32 lastOpcode = BUF[p-1] >> 26; if (lastOpcode == MAESTRO_JMPC || lastOpcode == MAESTRO_JMPU || lastOpcode == MAESTRO_CALL || lastOpcode == MAESTRO_CALLC || lastOpcode == MAESTRO_CALLU + || (elem.type == SE_FOR && lastOpcode == MAESTRO_BREAK) || (elem.type == SE_FOR && lastOpcode == MAESTRO_BREAKC) || (elem.type != SE_ARRAY && (p - elem.pos) < (elem.type != SE_PROC ? 2 : 1))) insertPaddingNop();