mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Add pushc and popc directives
This commit is contained in:
@@ -35,6 +35,8 @@ struct Charmap {
|
|||||||
void charmap_InitMain(void);
|
void charmap_InitMain(void);
|
||||||
struct Charmap *charmap_New(const char *name, const char *baseName);
|
struct Charmap *charmap_New(const char *name, const char *baseName);
|
||||||
void charmap_Set(const char *name);
|
void charmap_Set(const char *name);
|
||||||
|
void charmap_Push(void);
|
||||||
|
void charmap_Pop(void);
|
||||||
int32_t charmap_Add(char *input, uint8_t output);
|
int32_t charmap_Add(char *input, uint8_t output);
|
||||||
int32_t charmap_Convert(char **input);
|
int32_t charmap_Convert(char **input);
|
||||||
|
|
||||||
|
|||||||
@@ -621,6 +621,8 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
|
|||||||
%token T_POP_CHARMAP
|
%token T_POP_CHARMAP
|
||||||
%token T_POP_NEWCHARMAP
|
%token T_POP_NEWCHARMAP
|
||||||
%token T_POP_SETCHARMAP
|
%token T_POP_SETCHARMAP
|
||||||
|
%token T_POP_PUSHC
|
||||||
|
%token T_POP_POPC
|
||||||
%token T_POP_SHIFT
|
%token T_POP_SHIFT
|
||||||
%token T_POP_ENDR
|
%token T_POP_ENDR
|
||||||
%token T_POP_FAIL
|
%token T_POP_FAIL
|
||||||
@@ -776,6 +778,8 @@ simple_pseudoop : include
|
|||||||
| charmap
|
| charmap
|
||||||
| newcharmap
|
| newcharmap
|
||||||
| setcharmap
|
| setcharmap
|
||||||
|
| pushc
|
||||||
|
| popc
|
||||||
| rept
|
| rept
|
||||||
| shift
|
| shift
|
||||||
| fail
|
| fail
|
||||||
@@ -1047,11 +1051,19 @@ newcharmap : T_POP_NEWCHARMAP T_ID
|
|||||||
{
|
{
|
||||||
charmap_New($2, $4);
|
charmap_New($2, $4);
|
||||||
}
|
}
|
||||||
|
;
|
||||||
|
|
||||||
setcharmap : T_POP_SETCHARMAP T_ID
|
setcharmap : T_POP_SETCHARMAP T_ID
|
||||||
{
|
{
|
||||||
charmap_Set($2);
|
charmap_Set($2);
|
||||||
}
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
pushc : T_POP_PUSHC { charmap_Push(); }
|
||||||
|
;
|
||||||
|
|
||||||
|
popc : T_POP_POPC { charmap_Pop(); }
|
||||||
|
;
|
||||||
|
|
||||||
printt : T_POP_PRINTT string
|
printt : T_POP_PRINTT string
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,11 +20,18 @@
|
|||||||
|
|
||||||
#define CHARMAP_HASH_SIZE (1 << 9)
|
#define CHARMAP_HASH_SIZE (1 << 9)
|
||||||
|
|
||||||
|
struct CharmapStackEntry {
|
||||||
|
struct Charmap *charmap;
|
||||||
|
struct CharmapStackEntry *next;
|
||||||
|
};
|
||||||
|
|
||||||
static struct Charmap *tHashedCharmaps[CHARMAP_HASH_SIZE];
|
static struct Charmap *tHashedCharmaps[CHARMAP_HASH_SIZE];
|
||||||
|
|
||||||
static struct Charmap *mainCharmap;
|
static struct Charmap *mainCharmap;
|
||||||
static struct Charmap *currentCharmap;
|
static struct Charmap *currentCharmap;
|
||||||
|
|
||||||
|
struct CharmapStackEntry *charmapStack;
|
||||||
|
|
||||||
static void warnSectionCharmap(void)
|
static void warnSectionCharmap(void)
|
||||||
{
|
{
|
||||||
static bool warned = false;
|
static bool warned = false;
|
||||||
@@ -119,6 +126,32 @@ void charmap_Set(const char *name)
|
|||||||
currentCharmap = *ppCharmap;
|
currentCharmap = *ppCharmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void charmap_Push(void)
|
||||||
|
{
|
||||||
|
struct CharmapStackEntry *stackEntry;
|
||||||
|
|
||||||
|
stackEntry = malloc(sizeof(struct CharmapStackEntry));
|
||||||
|
if (stackEntry == NULL)
|
||||||
|
fatalerror("No memory for charmap stack");
|
||||||
|
|
||||||
|
stackEntry->charmap = currentCharmap;
|
||||||
|
stackEntry->next = charmapStack;
|
||||||
|
|
||||||
|
charmapStack = stackEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void charmap_Pop(void)
|
||||||
|
{
|
||||||
|
if (charmapStack == NULL)
|
||||||
|
fatalerror("No entries in the charmap stack");
|
||||||
|
|
||||||
|
struct CharmapStackEntry *top = charmapStack;
|
||||||
|
|
||||||
|
currentCharmap = top->charmap;
|
||||||
|
charmapStack = top->next;
|
||||||
|
free(top);
|
||||||
|
}
|
||||||
|
|
||||||
void charmap_InitMain(void)
|
void charmap_InitMain(void)
|
||||||
{
|
{
|
||||||
mainCharmap = charmap_New("main", NULL);
|
mainCharmap = charmap_New("main", NULL);
|
||||||
|
|||||||
@@ -481,6 +481,8 @@ const struct sLexInitString lexer_strings[] = {
|
|||||||
{"charmap", T_POP_CHARMAP},
|
{"charmap", T_POP_CHARMAP},
|
||||||
{"newcharmap", T_POP_NEWCHARMAP},
|
{"newcharmap", T_POP_NEWCHARMAP},
|
||||||
{"setcharmap", T_POP_SETCHARMAP},
|
{"setcharmap", T_POP_SETCHARMAP},
|
||||||
|
{"pushc", T_POP_PUSHC},
|
||||||
|
{"popc", T_POP_POPC},
|
||||||
|
|
||||||
{"fail", T_POP_FAIL},
|
{"fail", T_POP_FAIL},
|
||||||
{"warn", T_POP_WARN},
|
{"warn", T_POP_WARN},
|
||||||
|
|||||||
@@ -1146,7 +1146,8 @@ a different encoding for other purposes, for example. Initially, there is
|
|||||||
one character map called
|
one character map called
|
||||||
.Sy main
|
.Sy main
|
||||||
and it is automatically selected as the current character map from the
|
and it is automatically selected as the current character map from the
|
||||||
beginning.
|
beginning. There is also a character map stack that can be used to save and
|
||||||
|
restore which character map is currently active.
|
||||||
.Bl -column "NEWCHARMAP name, basename"
|
.Bl -column "NEWCHARMAP name, basename"
|
||||||
.It Sy Command Ta Sy Meaning
|
.It Sy Command Ta Sy Meaning
|
||||||
.It Ic NEWCHARMAP Ar name Ta Creates a new, empty character map called
|
.It Ic NEWCHARMAP Ar name Ta Creates a new, empty character map called
|
||||||
@@ -1156,6 +1157,8 @@ beginning.
|
|||||||
copied from character map
|
copied from character map
|
||||||
.Ic basename .
|
.Ic basename .
|
||||||
.It Ic SETCHARMAP Ar name Ta Switch to character map Ic name .
|
.It Ic SETCHARMAP Ar name Ta Switch to character map Ic name .
|
||||||
|
.It Ic PUSHC Ta Push the current character map onto the stack.
|
||||||
|
.It Ic POPC Ta Pop a character map off the stack and switch to it.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
.Sy Note:
|
.Sy Note:
|
||||||
|
|||||||
@@ -1,88 +1,104 @@
|
|||||||
|
new_: MACRO
|
||||||
|
IF _NARG > 1
|
||||||
|
printt "newcharmap \1, \2\n"
|
||||||
|
newcharmap \1, \2
|
||||||
|
ELSE
|
||||||
|
printt "newcharmap \1\n"
|
||||||
|
newcharmap \1
|
||||||
|
ENDC
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
set_: MACRO
|
||||||
|
printt "setcharmap \1\n"
|
||||||
|
setcharmap \1
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
push_: MACRO
|
||||||
|
printt "pushc\n"
|
||||||
|
pushc
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
pop_: MACRO
|
||||||
|
printt "popc\n"
|
||||||
|
popc
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
print: MACRO
|
||||||
|
x = \1
|
||||||
|
printt "{x}\n"
|
||||||
|
ENDM
|
||||||
|
|
||||||
printt "main charmap\n"
|
printt "main charmap\n"
|
||||||
|
|
||||||
charmap "ab", $0
|
charmap "ab", $0
|
||||||
|
|
||||||
x = "ab"
|
print "ab"
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
printt "newcharmap map1\n"
|
new_ map1
|
||||||
newcharmap map1
|
|
||||||
|
|
||||||
x = "ab"
|
print "ab"
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
printt "newcharmap map2, main\n"
|
new_ map2, main
|
||||||
newcharmap map2, main
|
|
||||||
|
|
||||||
x = "ab"
|
print "ab"
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
printt "setcharmap map1\n"
|
set_ map1
|
||||||
setcharmap map1
|
|
||||||
|
|
||||||
x = "ab"
|
print "ab"
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
printt "newcharmap map3\n"
|
new_ map3
|
||||||
newcharmap map3
|
|
||||||
|
|
||||||
charmap "ab", $1
|
charmap "ab", $1
|
||||||
|
|
||||||
x = "ab"
|
print "ab"
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
printt "newcharmap map4, map3\n"
|
new_ map4, map3
|
||||||
newcharmap map4, map3
|
|
||||||
|
|
||||||
charmap "ab", $1
|
charmap "ab", $1
|
||||||
charmap "cd", $2
|
charmap "cd", $2
|
||||||
|
|
||||||
x = "ab"
|
print "ab"
|
||||||
printt "{x}\n"
|
print "cd"
|
||||||
|
|
||||||
x = "cd"
|
set_ map3
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
printt "setcharmap map3\n"
|
print "ab"
|
||||||
setcharmap map3
|
print "cd"
|
||||||
|
|
||||||
x = "ab"
|
set_ main
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
x = "cd"
|
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
printt "setcharmap main\n"
|
|
||||||
setcharmap main
|
|
||||||
|
|
||||||
SECTION "sec0", ROM0
|
SECTION "sec0", ROM0
|
||||||
|
|
||||||
x = "ab"
|
print "ab"
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
printt "override main charmap\n"
|
printt "override main charmap\n"
|
||||||
charmap "ef", $3
|
charmap "ef", $3
|
||||||
|
|
||||||
x = "ab"
|
print "ab"
|
||||||
printt "{x}\n"
|
print "ef"
|
||||||
|
|
||||||
x = "ef"
|
set_ map1
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
printt "setcharmap map3\n"
|
push_
|
||||||
setcharmap map3
|
set_ map2
|
||||||
|
push_
|
||||||
|
|
||||||
x = "ab"
|
set_ map3
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
x = "cd"
|
print "ab"
|
||||||
printt "{x}\n"
|
print "cd"
|
||||||
|
print "ef"
|
||||||
|
|
||||||
x = "ef"
|
pop_
|
||||||
printt "{x}\n"
|
|
||||||
|
|
||||||
printt "newcharmap map1\n"
|
print "ab"
|
||||||
newcharmap map1
|
|
||||||
|
|
||||||
printt "setcharmap map5\n"
|
pop_
|
||||||
setcharmap map5
|
|
||||||
|
print "ab"
|
||||||
|
|
||||||
|
new_ map1
|
||||||
|
|
||||||
|
set_ map5
|
||||||
|
|
||||||
|
pop_
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
warning: multiple-charmaps.asm(64):
|
warning: multiple-charmaps.asm(75):
|
||||||
Using 'charmap' within a section when the current charmap is 'main' is deprecated
|
Using 'charmap' within a section when the current charmap is 'main' is deprecated
|
||||||
ERROR: multiple-charmaps.asm(85):
|
ERROR: multiple-charmaps.asm(100) -> new_(5):
|
||||||
Charmap 'map1' already exists
|
Charmap 'map1' already exists
|
||||||
ERROR: multiple-charmaps.asm(88):
|
ERROR: multiple-charmaps.asm(102) -> set_(2):
|
||||||
Charmap 'map5' doesn't exist
|
Charmap 'map5' doesn't exist
|
||||||
error: Assembly aborted (2 errors)!
|
ERROR: multiple-charmaps.asm(104) -> pop_(2):
|
||||||
|
No entries in the charmap stack
|
||||||
main charmap
|
main charmap
|
||||||
$0
|
$0
|
||||||
newcharmap map1
|
newcharmap map1
|
||||||
@@ -26,9 +27,18 @@ $0
|
|||||||
override main charmap
|
override main charmap
|
||||||
$6162
|
$6162
|
||||||
$3
|
$3
|
||||||
|
setcharmap map1
|
||||||
|
pushc
|
||||||
|
setcharmap map2
|
||||||
|
pushc
|
||||||
setcharmap map3
|
setcharmap map3
|
||||||
$1
|
$1
|
||||||
$6364
|
$6364
|
||||||
$6566
|
$6566
|
||||||
|
popc
|
||||||
|
$0
|
||||||
|
popc
|
||||||
|
$6162
|
||||||
newcharmap map1
|
newcharmap map1
|
||||||
setcharmap map5
|
setcharmap map5
|
||||||
|
popc
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
warning: -(64):
|
warning: -(75):
|
||||||
Using 'charmap' within a section when the current charmap is 'main' is deprecated
|
Using 'charmap' within a section when the current charmap is 'main' is deprecated
|
||||||
ERROR: -(85):
|
ERROR: -(100) -> new_(5):
|
||||||
Charmap 'map1' already exists
|
Charmap 'map1' already exists
|
||||||
ERROR: -(88):
|
ERROR: -(102) -> set_(2):
|
||||||
Charmap 'map5' doesn't exist
|
Charmap 'map5' doesn't exist
|
||||||
error: Assembly aborted (2 errors)!
|
ERROR: -(104) -> pop_(2):
|
||||||
|
No entries in the charmap stack
|
||||||
main charmap
|
main charmap
|
||||||
$0
|
$0
|
||||||
newcharmap map1
|
newcharmap map1
|
||||||
@@ -26,9 +27,18 @@ $0
|
|||||||
override main charmap
|
override main charmap
|
||||||
$6162
|
$6162
|
||||||
$3
|
$3
|
||||||
|
setcharmap map1
|
||||||
|
pushc
|
||||||
|
setcharmap map2
|
||||||
|
pushc
|
||||||
setcharmap map3
|
setcharmap map3
|
||||||
$1
|
$1
|
||||||
$6364
|
$6364
|
||||||
$6566
|
$6566
|
||||||
|
popc
|
||||||
|
$0
|
||||||
|
popc
|
||||||
|
$6162
|
||||||
newcharmap map1
|
newcharmap map1
|
||||||
setcharmap map5
|
setcharmap map5
|
||||||
|
popc
|
||||||
|
|||||||
Reference in New Issue
Block a user