Skip to content

Commit

Permalink
EQU: #112 related - allow optional explicit pageNumber for EQU defini…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
ped7g committed Aug 8, 2020
1 parent cc7bc60 commit 21127a5
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 14 deletions.
17 changes: 12 additions & 5 deletions sjasm/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ void ParseLabel() {
if (White()) return;
if (Options::syx.IsPseudoOpBOF && ParseDirective(true)) return;
char temp[LINEMAX], * tp = temp, * ttp;
aint val;
aint val, equPageNum = LABEL_PAGE_UNDEFINED;
while (*lp && !White() && *lp != ':' && *lp != '=') {
*tp = *lp; ++tp; ++lp;
}
Expand Down Expand Up @@ -618,11 +618,18 @@ void ParseLabel() {
bool IsDEFL = NeedDEFL(), IsEQU = NeedEQU();
if (IsDEFL || IsEQU) {
Relocation::isResultAffected = false;
if (!ParseExpression(lp, val)) {
if (!ParseExpressionNoSyntaxError(lp, val)) {
Error("Expression error", lp);
val = 0;
}
if (IsLabelNotFound && IsDEFL) Error("Forward reference", NULL, EARLY);
// check for explicit page defined by EQU
if (IsEQU && comma(lp)) {
if (!ParseExpressionNoSyntaxError(lp, equPageNum)) {
Error("Expression error", lp);
equPageNum = LABEL_PAGE_UNDEFINED;
}
}
} else {
int gl = 0;
char* p = lp,* n;
Expand Down Expand Up @@ -653,7 +660,7 @@ void ParseLabel() {
return;
}
if (IsDEFL) { //re-set DEFL value
LabelTable.Insert(tp, val, false, true, false);
LabelTable.Insert(tp, val, false, true);
} else if (IsSldExportActive()) {
// SLD (Source Level Debugging) tracing-data logging
WriteToSldFile(IsEQU ? -1 : label->page, val, IsEQU ? 'D' : 'F', tp);
Expand All @@ -668,9 +675,9 @@ void ParseLabel() {

delete[] buf;
}
} else if (pass == 2 && !LabelTable.Insert(tp, val, false, IsDEFL, IsEQU) && !LabelTable.Update(tp, val)) {
} else if (pass == 2 && !LabelTable.Insert(tp, val, false, IsDEFL, IsEQU, equPageNum) && !LabelTable.Update(tp, val)) {
Error("Duplicate label", tp, EARLY);
} else if (pass == 1 && !LabelTable.Insert(tp, val, false, IsDEFL, IsEQU)) {
} else if (pass == 1 && !LabelTable.Insert(tp, val, false, IsDEFL, IsEQU, equPageNum)) {
Error("Duplicate label", tp, EARLY);
}

Expand Down
14 changes: 11 additions & 3 deletions sjasm/tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static short getAddressPageNumber(const aint address, bool forceRecalculateByAdd
return page;
}

int CLabelTable::Insert(const char* nname, aint nvalue, bool undefined, bool IsDEFL, bool IsEQU) {
int CLabelTable::Insert(const char* nname, aint nvalue, bool undefined, bool IsDEFL, bool IsEQU, short equPageNum) {
if (NextLocation >= LABTABSIZE * 2 / 3) {
Error("Label table full", NULL, FATAL);
}
Expand All @@ -272,7 +272,11 @@ int CLabelTable::Insert(const char* nname, aint nvalue, bool undefined, bool IsD
} else {
//if label already added (as used, or in previous pass), just refresh values
label->value = nvalue;
label->page = getAddressPageNumber(nvalue, IsDEFL|IsEQU);
if (IsEQU && LABEL_PAGE_UNDEFINED != equPageNum) {
label->page = equPageNum;
} else {
label->page = getAddressPageNumber(nvalue, IsDEFL|IsEQU);
}
label->IsDEFL = IsDEFL;
label->IsEQU = IsEQU;
label->isRelocatable = isRelocatable;
Expand All @@ -293,7 +297,11 @@ int CLabelTable::Insert(const char* nname, aint nvalue, bool undefined, bool IsD
label->updatePass = pass;
label->value = nvalue;
label->used = undefined;
label->page = undefined ? LABEL_PAGE_UNDEFINED : getAddressPageNumber(nvalue, IsDEFL|IsEQU);
if (IsEQU && LABEL_PAGE_UNDEFINED != equPageNum) {
label->page = equPageNum;
} else {
label->page = undefined ? LABEL_PAGE_UNDEFINED : getAddressPageNumber(nvalue, IsDEFL|IsEQU);
}
label->isRelocatable = !undefined && isRelocatable; // ignore "relocatable" for "undefined"
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions sjasm/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int GetLocalLabelValue(char*& op, aint& val);

constexpr int LABEL_PAGE_UNDEFINED = -1;
constexpr int LABEL_PAGE_ROM = 0x7F00; // must be minimum of special values (but positive)
constexpr int LABEL_PAGE_OUT_OF_BOUNDS = 0x7F01; // label is defined, but not within Z80 address space
constexpr int LABEL_PAGE_OUT_OF_BOUNDS = 0x7F80; // label is defined, but not within Z80 address space

class CLabelTableEntry {
public:
Expand All @@ -74,7 +74,7 @@ class CLabelTableEntry {
class CLabelTable {
public:
CLabelTable();
int Insert(const char* nname, aint nvalue, bool undefined = false, bool IsDEFL = false, bool IsEQU = false);
int Insert(const char* nname, aint nvalue, bool undefined = false, bool IsDEFL = false, bool IsEQU = false, short equPageNum = LABEL_PAGE_UNDEFINED);
int Update(char*, aint);
CLabelTableEntry* Find(const char* name, bool onlyDefined = false);
bool Remove(const char* name);
Expand Down
8 changes: 4 additions & 4 deletions tests/devices/extra/Issue111_LABELSLIST_EQU.lst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
18 0000 OTHER_EQU EQU $10000
19 0000
20 0000 PagesTab:
Issue111_LABELSLIST_EQU.asm(21): warning: value 0x7F01 is truncated to 8bit value: 0x01
21 0000 02 07 03 01 DB $$ADDR3_8000, $$ADDR3_0, $$ADDR3_C000, $$OTHER_EQU, $$PagesTab
Issue111_LABELSLIST_EQU.asm(21): warning: value 0x7F80 is truncated to 8bit value: 0x80
21 0000 02 07 03 80 DB $$ADDR3_8000, $$ADDR3_0, $$ADDR3_C000, $$OTHER_EQU, $$PagesTab
21 0004 07
22 0005
23 0005 ORG $C000
Expand All @@ -30,8 +30,8 @@ Issue111_LABELSLIST_EQU.asm(21): warning: value 0x7F01 is truncated to 8bit valu
27 C000
28 C000 OTHER_EQU2 EQU $10000
29 C000
Issue111_LABELSLIST_EQU.asm(30): warning: value 0x7F01 is truncated to 8bit value: 0x01
30 C000 03 02 01 DB $$ORG_ADR, $$ORG_ADR_EQU, $$OTHER_EQU2
Issue111_LABELSLIST_EQU.asm(30): warning: value 0x7F80 is truncated to 8bit value: 0x80
30 C000 03 02 80 DB $$ORG_ADR, $$ORG_ADR_EQU, $$OTHER_EQU2
31 C003
32 C003 LABELSLIST "Issue111_LABELSLIST_EQU.lbl"
33 C003
Expand Down
18 changes: 18 additions & 0 deletions tests/parsing/equ_with_explicit_page.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
DEVICE ZXSPECTRUM1024
ORG $8000
regular:

equClassic: EQU $4000
; actually in current v1.17.0 this will still receive "page 5" page based
; on the current memory mapping and the address value, but in docs it's
; described as "irrelevant". This test is documenting the behaviour for
; the sake of the test, not making it official/guaranteed, avoid using it

equWithPage: EQU $4001 , 1

ASSERT $8000 == regular && 2 == $$regular
ASSERT $4000 == equClassic && 5 == $$equClassic
ASSERT $4001 == equWithPage && 1 == $$equWithPage

errorEqu1 EQU $4002 ,
errorEqu2 EQU $4003 , @
32 changes: 32 additions & 0 deletions tests/parsing/equ_with_explicit_page.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# file opened: equ_with_explicit_page.asm
1 0000 DEVICE ZXSPECTRUM1024
2 0000 ORG $8000
3 8000 regular:
4 8000
5 8000 equClassic: EQU $4000
6 8000 ; actually in current v1.17.0 this will still receive "page 5" page based
7 8000 ; on the current memory mapping and the address value, but in docs it's
8 8000 ; described as "irrelevant". This test is documenting the behaviour for
9 8000 ; the sake of the test, not making it official/guaranteed, avoid using it
10 8000
11 8000 equWithPage: EQU $4001 , 1
12 8000
13 8000 ASSERT $8000 == regular && 2 == $$regular
14 8000 ASSERT $4000 == equClassic && 5 == $$equClassic
15 8000 ASSERT $4001 == equWithPage && 1 == $$equWithPage
16 8000
equ_with_explicit_page.asm(17): error: Expression error:
17 8000 errorEqu1 EQU $4002 ,
equ_with_explicit_page.asm(18): error: Expression error: @
equ_with_explicit_page.asm(18): error: Unrecognized instruction:
18 8000 errorEqu2 EQU $4003 , @
19 8000
# file closed: equ_with_explicit_page.asm

Value Label
------ - -----------------------------------------------------------
0x8000 regular
0x4000 equClassic
0x4001 equWithPage
0x4002 X errorEqu1
0x4003 X errorEqu2

0 comments on commit 21127a5

Please sign in to comment.