EtchedPixels / Fuzix-Compiler-Kit

Fuzix C Compiler Project
Other
49 stars 14 forks source link

support6800/__switch.s doesn't return correct results #98

Closed zu2 closed 1 month ago

zu2 commented 1 month ago

INX breaks the Z flag, need to change the order.

--- ../Fuzix-Compiler-Kit/support6800/__switch.s    2024-10-02 15:56:16
+++ support6800/__switch.s  2024-10-09 13:47:20
@@ -2,29 +2,27 @@

 __switch:
    ; X holds the switch table, D the value
-   staa @tmp
-   stab @tmp+1
-   ldaa ,x
+   pshb
    ldab 1,x
-   staa @tmp1
-   stab @tmp1+1
    inx
    inx
+   stab @tmp1+1
+   pulb
    beq gotit
 next:
-   ldaa ,x
-   ldab 1,x
-   cmpa @tmp
+   cmpa ,x
+   bne nomatch
+   cmpb 1,x
    bne nomatch
-   cmpb @tmp+1
+   ldx 2,x
+   jmp ,x
 nomatch:
    inx
    inx
-   beq gotit
    inx
    inx
-   dec @tmp1
-   bne next
+   dec @tmp1+1     ; We know < 256 entries per switch
+   bne next
 gotit:
    ldx ,x
    jmp ,x