Skip to content

Commit

Permalink
All assembler directives now respecting if/else/endif, part of fix fo…
Browse files Browse the repository at this point in the history
…r issue #88
  • Loading branch information
envenomator committed Nov 8, 2024
1 parent 3042c18 commit 25b3f89
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ void handle_asm_data(uint8_t wordtype) {
void handle_asm_equ(void) {
streamtoken_t token;

if(inConditionalSection == 1) return;

if(currentline.next) {
if(getDefineValueToken(&token, currentline.next)) {
if((token.terminator != 0) && (token.terminator != ';')) error(message[ERROR_TOOMANYARGUMENTS],0);
Expand All @@ -652,6 +654,8 @@ void handle_asm_equ(void) {
void handle_asm_adl(void) {
streamtoken_t token;

if(inConditionalSection == 1) return;

if(currentline.next) {
if(getDefineValueToken(&token, currentline.next) == 0) {
error(message[ERROR_MISSINGOPERAND],0);
Expand Down Expand Up @@ -690,6 +694,8 @@ void handle_asm_adl(void) {
void handle_asm_org(void) {
uint24_t newaddress;

if(inConditionalSection == 1) return;

parse_asm_single_immediate(); // get address from next token
// address needs to be given in pass 1
newaddress = operand1.immediate;
Expand Down Expand Up @@ -871,6 +877,8 @@ uint24_t alignment;
uint24_t base;
uint24_t delta;

if(inConditionalSection == 1) return;

parse_asm_single_immediate();
if(operand1.immediate <= 0) {
error(message[ERROR_ZEROORNEGATIVE],"%s",operand1.immediate_name);
Expand Down Expand Up @@ -904,6 +912,8 @@ void handle_asm_definemacro(void) {
macro_t *macro;
uint16_t startlinenumber,linelength,macrolength;

if(inConditionalSection == 1) return;

definelabel(address);

_macrobuffer[0] = 0; // empty string
Expand Down Expand Up @@ -1038,6 +1048,8 @@ void handle_asm_endif(void) {

void handle_asm_fillbyte(void) {

if(inConditionalSection == 1) return;

parse_asm_single_immediate(); // get fillbyte from next token
if((!ignore_truncation_warnings) && ((operand1.immediate < -128) || (operand1.immediate > 255))) {
warning(message[WARNING_TRUNCATED_8BIT],"%s",operand1.immediate_name);
Expand Down Expand Up @@ -1112,7 +1124,9 @@ void handle_assembler_command(void) {
handle_asm_endif();
break;
case(ASM_MACRO_END):
error(message[ERROR_MACRONOTSTARTED],0);
if(inConditionalSection == 0) {
error(message[ERROR_MACRONOTSTARTED],0);
}
break;
}
return;
Expand Down
Binary file added tests/Conditional_asm/tests/adl.expect
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/Conditional_asm/tests/adl.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; Test conditional ADL
;

assume ADL=1; disable startup assumptions and set up for failure if not implemented

.if 1
assume ADL=0
.else ; will run if not implemented, resulting in ADL mode 1, resulting in an error later on
assume ADL=1
.endif

ld hl, 0 ; this should produce 0x21 0x00 0x00, if properly implemented
Binary file added tests/Conditional_asm/tests/align.expect
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/Conditional_asm/tests/align.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; Test alignment
; Don't specifically test else statement; if alignment doesn't respect if/else, then the output will be different
.db 0
.if 1
.align 16
.else
.align 32
.endif

.db 0
9 changes: 9 additions & 0 deletions tests/Conditional_asm/tests/equ.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; Test conditional EQU

.if 1
test: EQU 1
.else
test: EQU 2 ; will produce an error when not implemented
.endif

.db test
Binary file added tests/Conditional_asm/tests/fillbyte.expect
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/Conditional_asm/tests/fillbyte.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; Test conditional fillbyte

.if 1
fillbyte 0x00
.else
fillbyte 0x01
.endif

.db 0xff
.blkb 16; use fillbyte, should be 16x 0x00 if properly implemented
.db 0xff
Binary file added tests/Conditional_asm/tests/macro.expect
Binary file not shown.
18 changes: 18 additions & 0 deletions tests/Conditional_asm/tests/macro.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; Test conditional macros
;

.if 1

macro test
.db 0
endmacro

.else

macro test
.db 1
endmacro

.endif

test
1 change: 1 addition & 0 deletions tests/Conditional_asm/tests/org.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�����������������
12 changes: 12 additions & 0 deletions tests/Conditional_asm/tests/org.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; Test conditional org

.org 0x40000
.db 0xff

.if 1
.org 0x40010
.else
.org 0x40020
.endif

.db 0xff

0 comments on commit 25b3f89

Please sign in to comment.