From f0859c8356c1f99590bfea7746cb267c6c54e12e Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 2 Dec 2024 20:16:39 -0500 Subject: [PATCH] the assembler allows relative instructions (per, bra, etc) to external labels which won't link correctly. Merlin flags them as an error. Additionally, per was generating a relocation record which causes the linked code to be wrong (even with an internal label). --- src/asm/asm.eval.s | 41 +++++++++++++++++++++++++++++++++++++++++ src/asm/asm.opcodes.s | 23 ++++++----------------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/asm/asm.eval.s b/src/asm/asm.eval.s index 366024d..cf25664 100644 --- a/src/asm/asm.eval.s +++ b/src/asm/asm.eval.s @@ -1439,3 +1439,44 @@ cnvttbl adrl 0,1,2,3,4,5,6,7,8,9 adrl 0,1000000000,2000000000,3000000000,4000000000,5000000000 adrl 6000000000,7000000000,8000000000,900000000 + + +eval_rel +* like eval but returns an error if this is a reference to an external label +* assumes 16-bit m/x + +* lableused values: +* $ffff - no labels encountered in eval (eg, $1234) +* $7fff - relative value (eg, *) +* 0-$7ffe - label # ; may be internal or external. + + mx %00 + jsr eval + bcc :check + rts + +:check lda lableused + bmi :ok ; merlin allows it... + cmp #$7fff + beq :ok + asl + asl + tay + lda [lableptr1],y + sta lableptr + iny + iny + lda [lableptr1],y + sta lableptr+2 + ldy #o_labtype + lda [lableptr],y + bit #externalbit + beq :ok + + sec + lda #badrelative ; merlin: bad external (bra, etc) + rts ; or or illegal forward ref (brl/per) + +:ok clc + rts + diff --git a/src/asm/asm.opcodes.s b/src/asm/asm.opcodes.s index 86a8828..e457c5d 100644 --- a/src/asm/asm.opcodes.s +++ b/src/asm/asm.opcodes.s @@ -7,7 +7,7 @@ dobranch ldy passnum jeq :p1 ldx #$00 - jsr eval + jsr eval_rel bcc :offset jmp :errput2 :offset lda objptr @@ -73,7 +73,7 @@ dobranch ldy passnum beq :p1 ldx #$00 - jsr eval + jsr eval_rel bcc :offset1 jmp :errput3 :offset1 lda objptr @@ -446,16 +446,10 @@ perop lda passnum and #amforce24.amforce16.amforce8!$FFFF bne :bad ldx #$00 - jsr eval + jsr eval_rel bcc :ok rts -:ok lda #relflag ;if rel'ing you can't use an - bit modeflag ;absolute value - beq :ok1 - bit lableused - bpl :ok1 - ;check for lableused -:ok1 lda objptr +:ok lda objptr clc adc #$03 pha @@ -470,13 +464,8 @@ perop lda passnum jsr putbyte lda lvalue+1 jsr putbyte - lda #$7fff - sta lableused - lda lvalue - sta noshift - jmp relcorrect -* clc -* rts + clc + rts :bad lda #badaddress sec rts