Allow OPT to modify -L

-L is a Boolean flag option, so you specify 'OPT L' or 'OPT !L'.
This commit is contained in:
Rangi
2021-03-15 09:44:38 -04:00
committed by Eldred Habert
parent 432c769d60
commit 2c30ab8731
10 changed files with 63 additions and 13 deletions

View File

@@ -16,7 +16,7 @@
#include "helpers.h"
extern bool haltnop;
extern bool optimizeloads;
extern bool optimizeLoads;
extern bool verbose;
extern bool warnings; /* True to enable warnings, false to disable them. */

View File

@@ -9,14 +9,15 @@
#ifndef RGBDS_OPT_H
#define RGBDS_OPT_H
#include <stdbool.h>
void opt_B(char chars[2]);
void opt_G(char chars[4]);
void opt_P(uint8_t fill);
void opt_L(bool optimize);
void opt_Parse(char const *option);
void opt_Push(void);
void opt_Pop(void);
#endif

View File

@@ -51,7 +51,7 @@ bool oGeneratePhonyDeps;
char *tzTargetFileName;
bool haltnop;
bool optimizeloads;
bool optimizeLoads;
bool verbose;
bool warnings; /* True to enable warnings, false to disable them. */
@@ -166,7 +166,7 @@ int main(int argc, char *argv[])
opt_B("01");
opt_G("0123");
opt_P(0);
optimizeloads = true;
optimizeLoads = true;
haltnop = true;
verbose = false;
warnings = true;
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
break;
case 'L':
optimizeloads = false;
optimizeLoads = false;
break;
case 'M':

View File

@@ -1,4 +1,3 @@
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
@@ -7,6 +6,7 @@
#include <string.h>
#include "asm/lexer.h"
#include "asm/main.h"
#include "asm/section.h"
#include "asm/warning.h"
@@ -14,6 +14,7 @@ struct OptStackEntry {
char binary[2];
char gbgfx[4];
int32_t fillByte;
bool optimizeLoads;
struct OptStackEntry *next;
};
@@ -34,6 +35,11 @@ void opt_P(uint8_t fill)
fillByte = fill;
}
void opt_L(bool optimize)
{
optimizeLoads = optimize;
}
void opt_Parse(char *s)
{
switch (s[0]) {
@@ -66,6 +72,28 @@ void opt_Parse(char *s)
}
break;
case 'L':
if (s[1] == '\0')
opt_L(true);
else
error("Option 'L' does not take an argument\n");
break;
case '!': // negates flag options that do not take an argument
switch (s[1]) {
case 'L':
if (s[2] == '\0')
opt_L(false);
else
error("Option '!L' does not take an argument\n");
break;
default:
error("Unknown option '!%c'\n", s[1]);
break;
}
break;
default:
error("Unknown option '%c'\n", s[0]);
break;
@@ -90,6 +118,8 @@ void opt_Push(void)
entry->fillByte = fillByte; // Pulled from section.h
entry->optimizeLoads = optimizeLoads; // Pulled from main.h
entry->next = stack;
stack = entry;
}
@@ -106,6 +136,7 @@ void opt_Pop(void)
opt_B(entry->binary);
opt_G(entry->gbgfx);
opt_P(entry->fillByte);
opt_L(entry->optimizeLoads);
stack = entry->next;
free(entry);
}

View File

@@ -1831,7 +1831,7 @@ z80_ld_mem : T_Z80_LD op_mem_ind T_COMMA T_MODE_SP {
out_RelWord(&$2, 1);
}
| T_Z80_LD op_mem_ind T_COMMA T_MODE_A {
if (optimizeloads && rpn_isKnown(&$2)
if (optimizeLoads && rpn_isKnown(&$2)
&& $2.nVal >= 0xFF00) {
out_AbsByte(0xE0);
out_AbsByte($2.nVal & 0xFF);
@@ -1879,7 +1879,7 @@ z80_ld_a : T_Z80_LD reg_r T_COMMA c_ind {
}
| T_Z80_LD reg_r T_COMMA op_mem_ind {
if ($2 == REG_A) {
if (optimizeloads && rpn_isKnown(&$4)
if (optimizeLoads && rpn_isKnown(&$4)
&& $4.nVal >= 0xFF00) {
out_AbsByte(0xF0);
out_AbsByte($4.nVal & 0xFF);

View File

@@ -1883,16 +1883,24 @@ can be used to change some of the options during assembling from within the sour
takes a comma-separated list of options as its argument:
.Bd -literal -offset indent
PUSHO
OPT g.oOX ;Set the GB graphics constants to use these characters
DW `..ooOOXX
OPT g.oOX, !L ; acts like command-line -g.oOX and omitting -L
DW `..ooOOXX ; uses the graphics constant characters from OPT g
LD [$FF88], A ; encoded as LD, not LDH
POPO
DW `00112233
DW `00112233 ; uses the default graphics constant characters
LD [$FF88], A ; optimized to use LDH if -L was passed
.Ed
.Pp
The options that OPT can modify are currently:
.Cm b , g
.Cm b , g , p ,
and
.Cm p .
.Cm L .
The Boolean flag option
.Cm L
can be specified as
.Ql OPT L
or
.Ql OPT !L .
.Pp
.Ic POPO
and

10
test/asm/opt.asm Normal file
View File

@@ -0,0 +1,10 @@
SECTION "test", ROM0
pusho
opt p42, !L
ds 1
ld [$ff88], a
popo
ds 1
ld [$ff88], a

0
test/asm/opt.err Normal file
View File

0
test/asm/opt.out Normal file
View File

BIN
test/asm/opt.out.bin Normal file

Binary file not shown.