Make it possible to disable emitting nop after halt.

This commit is contained in:
Anthony J. Bentley
2013-05-19 17:56:41 -06:00
parent 34d40a67c9
commit 6ccd386587
4 changed files with 33 additions and 4 deletions

View File

@@ -153,8 +153,13 @@ z80_ex : T_Z80_EX T_MODE_HL comma T_MODE_SP_IND
{ out_AbsByte(0xE3); } { out_AbsByte(0xE3); }
; ;
z80_halt : T_Z80_HALT z80_halt: T_Z80_HALT
{ out_AbsByte(0x76); out_AbsByte(0x00); } {
out_AbsByte(0x76);
if (haltnop) {
out_AbsByte(0x00);
}
}
; ;
z80_inc : T_Z80_INC reg_r z80_inc : T_Z80_INC reg_r

View File

@@ -8,6 +8,7 @@
#include <math.h> #include <math.h>
#include <getopt.h> #include <getopt.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -29,6 +30,8 @@ void setuplex(void);
* *
*/ */
bool haltnop;
clock_t nStartClock, nEndClock; clock_t nStartClock, nEndClock;
SLONG nLineNo; SLONG nLineNo;
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors; ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
@@ -238,7 +241,8 @@ PrintUsage(void)
{ {
printf("RGBAsm v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION printf("RGBAsm v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION
")\n\n"); ")\n\n");
printf("Usage: rgbasm [-b chars] [-g chars] [-i path] [-o outfile] [-p pad_value] file\n"); printf("Usage: rgbasm [-h] [-b chars] [-g chars] [-i path] [-o outfile] [-p pad_value]\n"
" file\n");
exit(1); exit(1);
} }
/* /*
@@ -258,6 +262,8 @@ main(int argc, char *argv[])
char *tzMainfile; char *tzMainfile;
haltnop = true;
if (argc == 1) if (argc == 1)
PrintUsage(); PrintUsage();
@@ -275,7 +281,7 @@ main(int argc, char *argv[])
newopt = CurrentOptions; newopt = CurrentOptions;
while ((ch = getopt(argc, argv, "b:g:i:o:p:")) != -1) { while ((ch = getopt(argc, argv, "b:g:hi:o:p:")) != -1) {
switch (ch) { switch (ch) {
case 'b': case 'b':
if (strlen(optarg) == 2) { if (strlen(optarg) == 2) {
@@ -299,6 +305,9 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }
break; break;
case 'h':
haltnop = false;
break;
case 'i': case 'i':
fstk_AddIncludePath(optarg); fstk_AddIncludePath(optarg);
break; break;

View File

@@ -6,6 +6,7 @@
.Nd Game Boy assembler .Nd Game Boy assembler
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm rgbasm .Nm rgbasm
.Op Fl h
.Op Fl b Ar chars .Op Fl b Ar chars
.Op Fl g Ar chars .Op Fl g Ar chars
.Op Fl i Ar path .Op Fl i Ar path
@@ -24,6 +25,17 @@ The defaults are 01.
.It Fl g Ar chars .It Fl g Ar chars
Change the four characters used for binary constants. Change the four characters used for binary constants.
The defaults are 0123. The defaults are 0123.
.It Fl h
By default,
.Nm
inserts a
.Sq nop
instruction immediately after any
.Sq halt
instruction.
The
.Fl h
option disables this behavior.
.It Fl i Ar path .It Fl i Ar path
Add an include path. Add an include path.
.It Fl o Ar outfile .It Fl o Ar outfile

View File

@@ -1,6 +1,7 @@
%{ %{
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -15,6 +16,8 @@
#include "asm/main.h" #include "asm/main.h"
#include "asm/lexer.h" #include "asm/lexer.h"
extern bool haltnop;
char *tzNewMacro; char *tzNewMacro;
ULONG ulNewMacroSize; ULONG ulNewMacroSize;