AppleWin / AppleWin

Apple II emulator for Windows
GNU General Public License v2.0
714 stars 163 forks source link

Are LDA ($FF,X) and LDY ($FF),Y wrapping correctly? #500

Closed tomcw closed 6 years ago

tomcw commented 6 years ago

From csa2, "Cycles question"

For the y-reg, it would read from $FF and $100.

This small program proves it.

300: LDY #0 LDA ($FF),Y JMP $FDDA

00:61 FF:0 60 300:A0 00 B1 FF 4C DA FD 6000:CC 6100:BB

This will print out CC

NB. AppleWin 1.26.3.2 prints out: BB - both 6502 and 65C02

tomcw commented 6 years ago

Also this

300:LDX #0 LDA($FF,X) JMP $FDDA

00:61 FF:0 60 300:A2 00 A1 FF 4C DA FD 6000:CC 6100:BB

This will print out CC

NB. AppleWin 1.26.3.2 prints out: BB - both 6502 and 65C02

Michaelangel007 commented 6 years ago

Stand-alone assembly

- - - 8< wrap.s - - - 
; Test ($00FF),Y wrap 
; https://groups.google.com/d/msg/comp.sys.apple2/q2QN5XpCV9c/yyEbZZ-eBgAJ 

        ORG $300 

        LDA #$00 ; is this the byte we expect? 
        STA $6100 

        LDA #$CC ; or is it this one? 
        STA $6000 

        LDA #$60 ; hi-order byte of address 
        STA $00 

        LDA #$5F ; hi-order byte of address 
        STA $0100 

        LDA #$FF ; lo-order byte of address 
        STA $FF 

        LDY #$01 
        LDA ($FF),Y ; *: PLUS 1 CYCLE IF CROSSING PAGE BOUNDARY 
        BNE Wrong 
;       BNE MJM_IS_WRONG_THIS_ONE_TIME 
;       BEQ MJM_IS_ALWAYS_RIGHT 
Right 
        LDA #'R' + $80 
        DB  $2C 
Wrong 
        LDA #'W' + $80 
        JMP $FDED 

Hexdump

0300:A9 00 8D 00 61 A9 CC 8D 
0308:00 60 A9 60 85 00 A9 5F 
0310:8D 00 01 A9 FF 85 FF A0 
0318:01 B1 FF D0 03 A9 D2 2C 
0320:A9 D7 4C ED FD 
300G 

Output

R if working W it broken

sicklittlemonkey commented 6 years ago

AppleWin is correct with BB.

Rob was using the Sweet 16 emulator which has a bug in 8-bit emulation mode. (CC is normal in 65C816 native (16-bit) mode.

After all, it's pretty hard to get these lines wrong.

define ZPGX addr = ((*(mem+regs.pc++))+regs.x) & 0xFF;

define ZPGY addr = ((*(mem+regs.pc++))+regs.y) & 0xFF;

But there's nothing wrong with double and triple-checking. ; - )

Cheers, Nick.

tomcw commented 6 years ago

Thanks - closing this issue.