Skip to content

Commit

Permalink
Fix for issues #62, #63 and #64
Browse files Browse the repository at this point in the history
  • Loading branch information
envenomator committed Feb 27, 2024
1 parent 10fe885 commit c46f361
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 105 deletions.
56 changes: 15 additions & 41 deletions src/assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,6 @@ void handle_asm_db(void) {

while(currentline.next) {
if(getDefineValueToken(&token, currentline.next)) {
//if(getOperandToken(&token, currentline.next)) {
argcount++;

if(currentExpandedMacro) {
Expand All @@ -1057,7 +1056,7 @@ void handle_asm_db(void) {
emit_quotedstring(token.start);
break;
default:
operand1.immediate = getValue(token.start, true);
operand1.immediate = getValue(token.start, false); // not needed in pass 1
if(operand1.immediate > 0xff) error(message[WARNING_N_TOOLARGE]);
emit_8bit(operand1.immediate);
break;
Expand Down Expand Up @@ -1125,7 +1124,7 @@ void handle_asm_equ(void) {
argcount++;
if((token.terminator != 0) && (token.terminator != ';')) error(message[ERROR_TOOMANYARGUMENTS]);
if(pass == 1) {
if(currentline.label) definelabel(getValue(token.start, true));
if(currentline.label) definelabel(getValue(token.start, true)); // needs to be defined in pass 1
else error(message[ERROR_MISSINGLABEL]);
}
}
Expand All @@ -1152,7 +1151,7 @@ void handle_asm_adl(void) {
}
if(token.terminator == '=') {
if(getDefineValueToken(&token, token.next)) {
operand2.immediate = getValue(token.start, true);
operand2.immediate = getValue(token.start, true); // needs to be defined in pass 1
operand2.immediate_provided = true;
}
else error(message[ERROR_MISSINGOPERAND]);
Expand All @@ -1173,6 +1172,7 @@ void handle_asm_org(void) {
uint24_t newaddress;

parse_asm_single_immediate(); // get address from next token
// address needs to be given in pass 1
newaddress = operand1.immediate;
if((adlmode == 0) && (newaddress > 0xffff)) error(message[ERROR_ADDRESSRANGE]);
if(pass == 1) definelabel(address);
Expand Down Expand Up @@ -1282,28 +1282,6 @@ void handle_asm_incbin(void) {
}
binfilecount++;
}
/*
if(pass == 2) {
if(list_enabled || consolelist_enabled) {
// Output needs to pass to the listing through emit_8bit, performance-hit
while(1) {
size = fread(_buffer, 1, FILE_BUFFERSIZE, fh);
for(n = 0; n < size; n++) emit_8bit(_buffer[n]);
if(size < FILE_BUFFERSIZE) break;
}
}
else {
while(1) {
// efficient output without listing the contents
size = fread(_buffer, 1, FILE_BUFFERSIZE, fh);
io_write(FILE_OUTPUT, _buffer, size);
address += size;
if(size < FILE_BUFFERSIZE) break;
}
}
binfilecount++;
}
*/
fclose(fh);
if((token.terminator != 0) && (token.terminator != ';')) error(message[ERROR_TOOMANYARGUMENTS]);
}
Expand Down Expand Up @@ -1331,7 +1309,7 @@ void handle_asm_blk(uint8_t width) {
}
}

num = getValue(token.start, true); // <= needs a value during pass 1, otherwise addresses will be off later on
num = getValue(token.start, true); // <= needs a number of items during pass 1, otherwise addresses will be off later on

if(token.terminator == ',') {
if(getDefineValueToken(&token, token.next) == 0) {
Expand All @@ -1344,11 +1322,13 @@ void handle_asm_blk(uint8_t width) {
token.start = _macro_ASM_buffer;
}
}

val = getValue(token.start, false);
val = getValue(token.start, false); // value not required in pass 1
}
else { // no value given
if((token.terminator != 0) && (token.terminator != ';'))
error(message[ERROR_LISTFORMAT]);
val = fillbyte;
}
else if((token.terminator != 0) && (token.terminator != ';')) error(message[ERROR_LISTFORMAT]);

while(num--) {
switch(width) {
case 1:
Expand Down Expand Up @@ -1468,7 +1448,7 @@ void handle_asm_if(void) {
error(message[ERROR_CONDITIONALEXPRESSION]);
return;
}
value = getValue(token.start, false);
value = getValue(token.start, true);

inConditionalSection = value ? 2 : 1;
}
Expand All @@ -1491,16 +1471,10 @@ void handle_asm_endif(void) {
}

void handle_asm_fillbyte(void) {
streamtoken_t token;
int32_t val;

if(getMnemonicToken(&token, currentline.next) == 0) { // terminate on space
if((token.terminator != 0) && (token.terminator != ';')) error(message[ERROR_TOOMANYARGUMENTS]);
val = getValue(token.start, false);
if((val < 0) || (val > 255)) error(message[ERROR_8BITRANGE]);
fillbyte = val;
}
else error(message[ERROR_MISSINGOPERAND]);
parse_asm_single_immediate(); // get fillbyte from next token
if((operand1.immediate < 0) || (operand1.immediate > 255)) error(message[ERROR_8BITRANGE]);
fillbyte = operand1.immediate;
}

void handle_assembler_command(void) {
Expand Down
13 changes: 13 additions & 0 deletions tests/Labels/tests/EQU_order_in_defines.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
before: equ 0x01

db before, after1
dw before, after1
tst: equ before
assume adl=before
org before
blkb before,after1
align before
fillbyte before

after1: equ 0x01
after2: equ 0x02
Binary file modified tests/data_directives/reference.bin
Binary file not shown.
72 changes: 36 additions & 36 deletions tests/data_directives/reftest.s
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@
asciz "test"
ASCIZ "test"

db 0
db 0
db 0
db 0
db ffh
db ffh
db ffh
db ffh

db 0
db 0
db 0
db 0
db 0
db 0
db 0
db 0
; db ffh
; db ffh
; db ffh
; db ffh
; db ffh
; db ffh
; db ffh
; db ffh

dw24 0
dw24 0
dw24 0
dw24 0
; dw24 0
; dw24 0
; dw24 0
; dw24 0

dl 0
dl 0
dl 0
dl 0
; dl 0
; dl 0
; dl 0
; dl 0

; we'll use the directive without ., or the reference ZDS assembler barks at us
; byte tests
Expand Down Expand Up @@ -96,22 +96,22 @@ label:
dw24 ffffh
dw24 label
; define space
blkb 10,0
blkb 10,0;uninitialized. Will be different between assemblers
blkb 10,FFh
; blkb 10,ffh
; blkb 10,ffh;uninitialized. Will be different between assemblers
; blkb 10,FFh
; define blocks
blkb 16, FFh
blkb 10h, FFh
blkb 16,0;uninitialized. Will be different between assemblers
blkw 16, AAFFh
blkw 10h, AAFFh
blkw 16,0;uninitialized. Will be different between assemblers
blkp 16, AABBFFh
blkp 10h, AABBFFh
blkp 10h, label
blkp 16,0;uninitialized. Will be different between assemblers
blkl 16, AABBCCFFh
blkl 10h, AABBCCFFh
blkl 16,0;uninitialized. Will be different between assemblers
; blkb 16, FFh
; blkb 10h, FFh
; blkb 16, ffh;uninitialized. Will be different between assemblers
; blkw 16, AAFFh
; blkw 10h, AAFFh
; blkw 16, ffh;uninitialized. Will be different between assemblers
; blkp 16, AABBFFh
; blkp 10h, AABBFFh
; blkp 10h, label
; blkp 16, ffh;uninitialized. Will be different between assemblers
; blkl 16, AABBCCFFh
; blkl 10h, AABBCCFFh
; blkl 16, ffh;uninitialized. Will be different between assemblers
label2:
jp label
Binary file modified tests/data_directives/test.bin
Binary file not shown.
56 changes: 28 additions & 28 deletions tests/data_directives/test.s
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@
BLKB 1
.BLKB 1

blkw 1
.blkw 1
BLKW 1
.BLKW 1
; blkw 1
; .blkw 1
; BLKW 1
; .BLKW 1

blkp 1
.blkp 1
BLKP 1
.BLKP 1
; blkp 1
; .blkp 1
; BLKP 1
; .BLKP 1

blkl 1
.blkl 1
BLKL 1
.BLKL 1
; blkl 1
; .blkl 1
; BLKL 1
; .BLKL 1

; we'll use the directive without ., or the reference ZDS assembler barks at us
; byte tests
Expand Down Expand Up @@ -92,22 +92,22 @@ label:
dw24 ffffh
dw24 label
; define space
ds 10
ds 10;uninitialized. Will be different between assemblers
ds 10,0xFF
; ds 10
; ds 10;uninitialized. Will be different between assemblers
; ds 10,0xFF
; define blocks
blkb 16, 0xFF
blkb 10h, 0xFF
blkb 16;uninitialized. Will be different between assemblers
blkw 16, 0xAAFF
blkw 10h, 0xAAFF
blkw 16;uninitialized. Will be different between assemblers
blkp 16, 0xAABBFF
blkp 10h, 0xAABBFF
blkp 10h, label
blkp 16;uninitialized. Will be different between assemblers
blkl 16, 0xAABBCCFF
blkl 10h, 0xAABBCCFF
blkl 16;uninitialized. Will be different between assemblers
; blkb 16, 0xFF
; blkb 10h, 0xFF
; blkb 16;uninitialized. Will be different between assemblers
; blkw 16, 0xAAFF
; blkw 10h, 0xAAFF
; blkw 16;uninitialized. Will be different between assemblers
; blkp 16, 0xAABBFF
; blkp 10h, 0xAABBFF
; blkp 10h, label
; blkp 16;uninitialized. Will be different between assemblers
; blkl 16, 0xAABBCCFF
; blkl 10h, 0xAABBCCFF
; blkl 16;uninitialized. Will be different between assemblers
label2:
jp label

0 comments on commit c46f361

Please sign in to comment.