mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Allow OPT to modify -L
-L is a Boolean flag option, so you specify 'OPT L' or 'OPT !L'.
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
extern bool haltnop;
|
extern bool haltnop;
|
||||||
extern bool optimizeloads;
|
extern bool optimizeLoads;
|
||||||
extern bool verbose;
|
extern bool verbose;
|
||||||
extern bool warnings; /* True to enable warnings, false to disable them. */
|
extern bool warnings; /* True to enable warnings, false to disable them. */
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,15 @@
|
|||||||
#ifndef RGBDS_OPT_H
|
#ifndef RGBDS_OPT_H
|
||||||
#define RGBDS_OPT_H
|
#define RGBDS_OPT_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
void opt_B(char chars[2]);
|
void opt_B(char chars[2]);
|
||||||
void opt_G(char chars[4]);
|
void opt_G(char chars[4]);
|
||||||
void opt_P(uint8_t fill);
|
void opt_P(uint8_t fill);
|
||||||
|
void opt_L(bool optimize);
|
||||||
void opt_Parse(char const *option);
|
void opt_Parse(char const *option);
|
||||||
|
|
||||||
void opt_Push(void);
|
void opt_Push(void);
|
||||||
void opt_Pop(void);
|
void opt_Pop(void);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ bool oGeneratePhonyDeps;
|
|||||||
char *tzTargetFileName;
|
char *tzTargetFileName;
|
||||||
|
|
||||||
bool haltnop;
|
bool haltnop;
|
||||||
bool optimizeloads;
|
bool optimizeLoads;
|
||||||
bool verbose;
|
bool verbose;
|
||||||
bool warnings; /* True to enable warnings, false to disable them. */
|
bool warnings; /* True to enable warnings, false to disable them. */
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ int main(int argc, char *argv[])
|
|||||||
opt_B("01");
|
opt_B("01");
|
||||||
opt_G("0123");
|
opt_G("0123");
|
||||||
opt_P(0);
|
opt_P(0);
|
||||||
optimizeloads = true;
|
optimizeLoads = true;
|
||||||
haltnop = true;
|
haltnop = true;
|
||||||
verbose = false;
|
verbose = false;
|
||||||
warnings = true;
|
warnings = true;
|
||||||
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'L':
|
case 'L':
|
||||||
optimizeloads = false;
|
optimizeLoads = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -7,6 +6,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
|
#include "asm/main.h"
|
||||||
#include "asm/section.h"
|
#include "asm/section.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@ struct OptStackEntry {
|
|||||||
char binary[2];
|
char binary[2];
|
||||||
char gbgfx[4];
|
char gbgfx[4];
|
||||||
int32_t fillByte;
|
int32_t fillByte;
|
||||||
|
bool optimizeLoads;
|
||||||
struct OptStackEntry *next;
|
struct OptStackEntry *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,6 +35,11 @@ void opt_P(uint8_t fill)
|
|||||||
fillByte = fill;
|
fillByte = fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void opt_L(bool optimize)
|
||||||
|
{
|
||||||
|
optimizeLoads = optimize;
|
||||||
|
}
|
||||||
|
|
||||||
void opt_Parse(char *s)
|
void opt_Parse(char *s)
|
||||||
{
|
{
|
||||||
switch (s[0]) {
|
switch (s[0]) {
|
||||||
@@ -66,6 +72,28 @@ void opt_Parse(char *s)
|
|||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
error("Unknown option '%c'\n", s[0]);
|
error("Unknown option '%c'\n", s[0]);
|
||||||
break;
|
break;
|
||||||
@@ -90,6 +118,8 @@ void opt_Push(void)
|
|||||||
|
|
||||||
entry->fillByte = fillByte; // Pulled from section.h
|
entry->fillByte = fillByte; // Pulled from section.h
|
||||||
|
|
||||||
|
entry->optimizeLoads = optimizeLoads; // Pulled from main.h
|
||||||
|
|
||||||
entry->next = stack;
|
entry->next = stack;
|
||||||
stack = entry;
|
stack = entry;
|
||||||
}
|
}
|
||||||
@@ -106,6 +136,7 @@ void opt_Pop(void)
|
|||||||
opt_B(entry->binary);
|
opt_B(entry->binary);
|
||||||
opt_G(entry->gbgfx);
|
opt_G(entry->gbgfx);
|
||||||
opt_P(entry->fillByte);
|
opt_P(entry->fillByte);
|
||||||
|
opt_L(entry->optimizeLoads);
|
||||||
stack = entry->next;
|
stack = entry->next;
|
||||||
free(entry);
|
free(entry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1831,7 +1831,7 @@ z80_ld_mem : T_Z80_LD op_mem_ind T_COMMA T_MODE_SP {
|
|||||||
out_RelWord(&$2, 1);
|
out_RelWord(&$2, 1);
|
||||||
}
|
}
|
||||||
| T_Z80_LD op_mem_ind T_COMMA T_MODE_A {
|
| T_Z80_LD op_mem_ind T_COMMA T_MODE_A {
|
||||||
if (optimizeloads && rpn_isKnown(&$2)
|
if (optimizeLoads && rpn_isKnown(&$2)
|
||||||
&& $2.nVal >= 0xFF00) {
|
&& $2.nVal >= 0xFF00) {
|
||||||
out_AbsByte(0xE0);
|
out_AbsByte(0xE0);
|
||||||
out_AbsByte($2.nVal & 0xFF);
|
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 {
|
| T_Z80_LD reg_r T_COMMA op_mem_ind {
|
||||||
if ($2 == REG_A) {
|
if ($2 == REG_A) {
|
||||||
if (optimizeloads && rpn_isKnown(&$4)
|
if (optimizeLoads && rpn_isKnown(&$4)
|
||||||
&& $4.nVal >= 0xFF00) {
|
&& $4.nVal >= 0xFF00) {
|
||||||
out_AbsByte(0xF0);
|
out_AbsByte(0xF0);
|
||||||
out_AbsByte($4.nVal & 0xFF);
|
out_AbsByte($4.nVal & 0xFF);
|
||||||
|
|||||||
@@ -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:
|
takes a comma-separated list of options as its argument:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
PUSHO
|
PUSHO
|
||||||
OPT g.oOX ;Set the GB graphics constants to use these characters
|
OPT g.oOX, !L ; acts like command-line -g.oOX and omitting -L
|
||||||
DW `..ooOOXX
|
DW `..ooOOXX ; uses the graphics constant characters from OPT g
|
||||||
|
LD [$FF88], A ; encoded as LD, not LDH
|
||||||
POPO
|
POPO
|
||||||
DW `00112233
|
DW `00112233 ; uses the default graphics constant characters
|
||||||
|
LD [$FF88], A ; optimized to use LDH if -L was passed
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The options that OPT can modify are currently:
|
The options that OPT can modify are currently:
|
||||||
.Cm b , g
|
.Cm b , g , p ,
|
||||||
and
|
and
|
||||||
.Cm p .
|
.Cm L .
|
||||||
|
The Boolean flag option
|
||||||
|
.Cm L
|
||||||
|
can be specified as
|
||||||
|
.Ql OPT L
|
||||||
|
or
|
||||||
|
.Ql OPT !L .
|
||||||
.Pp
|
.Pp
|
||||||
.Ic POPO
|
.Ic POPO
|
||||||
and
|
and
|
||||||
|
|||||||
10
test/asm/opt.asm
Normal file
10
test/asm/opt.asm
Normal 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
0
test/asm/opt.err
Normal file
0
test/asm/opt.out
Normal file
0
test/asm/opt.out
Normal file
BIN
test/asm/opt.out.bin
Normal file
BIN
test/asm/opt.out.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user