ref: deb44eaeef9e2ea5b5f15e4d14e8f3869f3522a4
parent: 338c176b372768ac71efe2df504e4bee0d405736
parent: 2ea2e47231bb98437dfa00908a65ca3052275f42
author: Sanqui <[email protected]>
date: Tue Oct 13 18:37:25 EDT 2015
Merge branch 'master' into HEAD
--- a/include/link/main.h
+++ b/include/link/main.h
@@ -4,6 +4,6 @@
#include "types.h"
extern SLONG fillchar;
-extern char smartlinkstartsymbol[256];
+extern char *smartlinkstartsymbol;
#endif
--- a/include/link/symbol.h
+++ b/include/link/symbol.h
@@ -4,7 +4,7 @@
#include "types.h"
void sym_Init(void);
-void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank);
+void sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank);
SLONG sym_GetValue(char *tzName);
SLONG sym_GetBank(char *tzName);
--- a/src/asm/asmy.y
+++ b/src/asm/asmy.y
@@ -20,6 +20,49 @@
char *tzNewMacro;
ULONG ulNewMacroSize;
+void
+bankrangecheck(char *name, ULONG secttype, SLONG org, SLONG bank)
+{
+ SLONG minbank, maxbank;
+ char *stype;
+ switch (secttype) {
+ case SECT_ROMX:
+ stype = "ROMX";
+ minbank = 1;
+ maxbank = 0x1ff;
+ break;
+ case SECT_SRAM:
+ stype = "SRAM";
+ minbank = 0;
+ maxbank = 0x1ff;
+ break;
+ case SECT_WRAMX:
+ stype = "WRAMX";
+ minbank = 1;
+ maxbank = 7;
+ break;
+ case SECT_VRAM:
+ stype = "VRAM";
+ minbank = 0;
+ maxbank = 1;
+ break;
+ default:
+ yyerror("BANK only allowed for "
+ "ROMX, WRAMX, SRAM, or VRAM sections");
+ }
+
+ if (bank < minbank || bank > maxbank) {
+ yyerror("%s bank value $%x out of range ($%x to $%x)",
+ stype, bank, minbank, maxbank);
+ }
+
+ if (secttype == SECT_WRAMX) {
+ bank -= minbank;
+ }
+
+ out_NewAbsSection(name, secttype, org, bank);
+}
+
size_t symvaluetostring(char *dest, size_t maxLength, char *sym)
{
size_t length;
@@ -497,14 +540,9 @@
%%
-asmfile : lines lastline;
+asmfile : lines;
-lastline : /* empty */
- | line {
- nLineNo += 1;
- nTotalLines += 1;
- };
-
+/* Note: The lexer add '\n' at the end of the input */
lines : /* empty */
| lines line '\n' {
nLineNo += 1;
@@ -511,8 +549,7 @@
nTotalLines += 1;
};
-line : /* empty */
- | label
+line : label
| label cpu_command
| label macro
| label simple_pseudoop
@@ -1060,76 +1097,14 @@
}
| T_POP_SECTION string ',' sectiontype ',' T_OP_BANK '[' const ']'
{
- if( $4==SECT_ROMX ) {
- if( $8>=1 && $8<=0x1ff )
- out_NewAbsSection($2,$4,-1,$8);
- else
- yyerror("ROM bank value $%x out of range (1 to $1ff)", $8);
- } else if ($4 == SECT_SRAM) {
- if ($8 >= 0 && $8 <= 3) {
- out_NewAbsSection($2, $4, -1, $8);
- } else {
- yyerror("SRAM bank value $%x out of range (0 to 3)", $8);
- }
- } else if ($4 == SECT_WRAMX) {
- if ($8 >= 1 && $8 <= 7) {
- out_NewAbsSection($2, $4, -1, $8 - 1);
- } else {
- yyerror("WRAMX bank value $%x out of range (1 to 7)", $8);
- }
- } else if ($4 == SECT_VRAM) {
- if ($8 >= 0 && $8 <= 1) {
- out_NewAbsSection($2, $4, -1, $8);
- } else {
- yyerror("VRAM bank value $%x out of range (0 to 1)", $8);
- }
- } else {
- yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
- }
+ bankrangecheck($2, $4, -1, $8);
}
| T_POP_SECTION string ',' sectiontype '[' const ']' ',' T_OP_BANK '[' const ']'
{
- if( $4==SECT_ROMX ) {
- if( $6>=0 && $6<0x10000 ) {
- if( $11>=1 && $11<=0x1ff )
- out_NewAbsSection($2,$4,$6,$11);
- else
- yyerror("ROM bank value $%x out of range (1 to $1ff)", $11);
- } else
- yyerror("Address $%x not 16-bit", $6);
- } else if ($4 == SECT_SRAM) {
- if ($6 >= 0 && $6 < 0x10000) {
- if ($11 >= 0 && $11 <= 3) {
- out_NewAbsSection($2, $4, $6, $11);
- } else {
- yyerror("SRAM bank value $%x out of range (0 to 3)", $11);
- }
- } else {
- yyerror("Address $%x not 16-bit", $6);
- }
- } else if ($4 == SECT_WRAMX) {
- if ($6 >= 0 && $6 < 0x10000) {
- if ($11 >= 1 && $11 <= 7) {
- out_NewAbsSection($2, $4, $6, $11 - 1);
- } else {
- yyerror("WRAMX bank value $%x out of range (1 to 7)", $11);
- }
- } else {
- yyerror("Address $%x not 16-bit", $6);
- }
- } else if ($4 == SECT_VRAM) {
- if ($6 >= 0 && $6 < 0x10000) {
- if ($11 >= 0 && $11 <= 1) {
- out_NewAbsSection($2,$4,$6,$11);
- } else {
- yyerror("VRAM bank value $%x out of range (0 to 1)", $11);
- }
- } else {
- yyerror("Address $%x not 16-bit", $6);
- }
- } else {
- yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
+ if ($6 < 0 || $6 > 0x10000) {
+ yyerror("Address $%x not 16-bit", $6);
}
+ bankrangecheck($2, $4, $6, $11);
}
;
--- a/src/asm/globlex.c
+++ b/src/asm/globlex.c
@@ -161,7 +161,7 @@
if (*src == '@')
marg = sym_FindMacroArg(-1);
else if (*src >= '0' && *src <= '9')
- marg = sym_FindMacroArg(*src);
+ marg = sym_FindMacroArg(*src - '0');
else {
fatalerror("Malformed ID");
return (0);
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -389,7 +389,10 @@
rpnexpr[rpnptr++] = value >> 16;
rpnexpr[rpnptr++] = value >> 24;
} else {
- symptr = addsymbol(sym_FindSymbol(tzSym));
+ struct sSymbol *sym;
+ if ((sym = sym_FindSymbol(tzSym)) == NULL)
+ break;
+ symptr = addsymbol(sym);
rpnexpr[rpnptr++] = RPN_SYM;
rpnexpr[rpnptr++] = symptr & 0xFF;
rpnexpr[rpnptr++] = symptr >> 8;
@@ -397,15 +400,19 @@
rpnexpr[rpnptr++] = symptr >> 24;
}
break;
- case RPN_BANK:
+ case RPN_BANK: {
+ struct sSymbol *sym;
symptr = 0;
while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0);
- symptr = addsymbol(sym_FindSymbol(tzSym));
+ if ((sym = sym_FindSymbol(tzSym)) == NULL)
+ break;
+ symptr = addsymbol(sym);
rpnexpr[rpnptr++] = RPN_BANK;
rpnexpr[rpnptr++] = symptr & 0xFF;
rpnexpr[rpnptr++] = symptr >> 8;
rpnexpr[rpnptr++] = symptr >> 16;
rpnexpr[rpnptr++] = symptr >> 24;
+ }
break;
default:
rpnexpr[rpnptr++] = rpndata;
--- a/src/link/main.c
+++ b/src/link/main.c
@@ -22,7 +22,7 @@
SLONG options = 0;
SLONG fillchar = 0;
-char smartlinkstartsymbol[256];
+char *smartlinkstartsymbol;
char *progname;
@@ -79,7 +79,7 @@
break;
case 's':
options |= OPT_SMART_C_LINK;
- strcpy(smartlinkstartsymbol, optarg);
+ smartlinkstartsymbol = optarg;
break;
case 't':
options |= OPT_SMALL;
--- a/src/link/symbol.c
+++ b/src/link/symbol.c
@@ -76,7 +76,7 @@
}
void
-sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
+sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank)
{
if (strcmp(tzName, "@") == 0)
return;