drmortalwombat / oscar64

Optimizing Small memory C Compiler Assembler and Runtime for C64
GNU General Public License v3.0
273 stars 24 forks source link

Wrong jmp address (inline assembly) #64

Closed AGPX closed 5 months ago

AGPX commented 5 months ago

Hi,

I've some trouble with an inlnie assembly routine in which a jmp is translated with a wrong (backward) address:

setNs01:
        sty _ns                     // ns = j
        tya
        ldy #0
        sta (nsAlias),y

exit101:
        lda #0                      // i = 0
        sta vi

        ldy #1                      // reg.y = regy = 1

repeat01:
        lda vi                      // if (i >= ns) goto exit201
        cmp _ns
        bcc sets01
        jmp exit201

                ...
exit201:
0db1 : 84 3a __ STY T5 + 0 
0db3 : 98 __ __ TYA
0db4 : a0 00 __ LDY #$00
0db6 : 91 38 __ STA (T4 + 0),y 
0db8 : a9 00 __ LDA #$00
0dba : 85 3f __ STA T9 + 0 
0dbc : a0 01 __ LDY #$01
0dbe : a5 3f __ LDA T9 + 0 
0dc0 : c5 3a __ CMP T5 + 0 
0dc2 : 90 03 __ BCC $0dc7 ; (Actor::setupFrame.s3 + 239)
0dc4 : 4c 52 0d JMP $0d52 ; (Actor::setupFrame.s3 + 122)   // This is wrong.... the exit201 label is after this code, not before!

Attached the full code. Is there some limitation in jump distance?

code.txt

drmortalwombat commented 5 months ago

Fix checked in

AGPX commented 5 months ago

Ok, tested. It works.