2008-07-27 maxxy hangs in a routine starts from c150 C169 C16C C16D C170 C171 C169 C16C C16D C170 C171 C169 : $0500 is supposed to be 0x62 @C169, but is cleared to zero --> where is $0500 cleared? code is inserted in maxxy prg CMP $0500,Y ; D9 00 05 BNE LDA #1 STA $7FFF BNE LDA #0 STA $7FFF BNE +5613 20 00:8000 AD 00 05 LDA $0500 ; D9 00 05 21 00:8003 C9 62 CMP #$62 22 00:8005 D0 02 BNE .l1 23 00:8007 F0 07 BEQ .l2 24 25 00:8009 .l1: 26 00:8009 A9 01 LDA #1 27 00:800B 8D FF 7F STA $7FFF 28 00:800E D0 F9 BNE .l1 29 30 00:8010 .l2: 31 00:8010 A9 00 LDA #0 32 00:8012 8D FF 7F STA $7FFF 33 00:8015 F0 F9 BEQ .l2 LC141: TSX ; C141 BA TXA ; C142 8A AND #$C0 ; C143 29 C0 TAY ; C145 A8 LC146: TSX ; C146 BA TXA ; C147 8A LDX $0100,Y ; C148 BE 00 01 STA $0100,Y ; C14B 99 00 01 TXS ; C14E 9A RTS ; C14F 60 <-- $500 = 0x62 at this point C890 --> C141 --> RTS --> C065 (the C141 routine tweaks the return address) when X=0: NG: LDY $0500,X ; C157 BC 00 05 OK: LDA $0500 --> the $500 data is not cleared to zero; read fails to get the correct value LDY $0500,X ; C157 BC 00 05 INX ; C15A E8 LDA $0500,X ; C15B BD 00 05 INX ; C15E E8 STA $2006 ; C15F 8D 06 20 STY $2006 ; C162 8C 06 20 changed not to use LDY $0500,X to see if this code works correctly: LDA $0501,X ; C157 BD 01 05 STA $2006 ; C15F 8D 06 20 LDA $0500,X ; C15B BD 00 05 STA $2006 ; C15F 8D 06 20 INX ; C15E E8 INX ; C15E E8 --> the alternative code worked. --> something must be wrong with "ldy $abs,x" [2008-7-28] LDx abs/abs,x/abs,y sequence ST[0]: AluInA=Operand1, AluInB=0/X/Y, AluInC=0, AluOP=ADC ST[1]: EAL<=AluOut, AluInA=Operand2, AluInB=0, AluInC=AluC7, AluOP=ADC ST[2]: AluInA=AluOut, AluInB=0, AluOP=ADC (skipped if AluC7=0 on ST[1]) ST[3]: Addr=AluOut|EAL ST[4]: Addr=PCH|PCL, I<=DIN Execution log of C157: LDY $0500,X on the real FPGA PC I d1 d2 Y d3 d4 C158 BC 61 20 19 08 01 C159 BC E1 01 19 08 03 C15A BC 14 08 19 80 01 C15A BC E0 00 19 00 05 [C158] = ST[0]: AluInA=Operand1, AluInB=0/X/Y, AluInC=0, AluOP=ADC d1 = 61 = 0110 0001 w_DataMux_ALU = 0 w_AddrLMux_PCL = 1 w_AddrHMux_PCH = 1 w_AddrLMux_EAL = 0 w_AddrLMux_ALU = 0 w_AddrHMux_ALU = 0 w_AluAMux_ALU = 0 w_AluAMux_DIN = 1 d2 = 20 = 0010 0000 w_AluBMux_01 = 0 w_AluBMux_A = 0 w_AluBMux_X = 1 w_AluBMux_Y = 0 w_AluBMux_DIN = 0 w_AluCMux_1 = 0 w_AluCMux_CF = 0 w_AluCMux_C7 = 0 d3 = 08 = 0000 1000 w_AluOp_OR = 0 w_AluOp_AND = 0 w_AluOp_XOR = 0 w_AluOp_BIT = 0 w_AluOp_ADC = 1 w_AluOp_SBC = 0 w_AluOp_ROR = 0 (unassigned) = 0 d4 = 01 = 0000 0001 (unassigned) = 0 (unassigned) = 0 (unassigned) = 0 (unassigned) = 0 (unassigned) = 0 w_WriteY = 0 w_nRD = 0 w_nWR = 1 [C159] = ST[1]: EAL<=AluOut, AluInA=Operand2, AluInB=0, AluInC=AluC7, AluOP=ADC d1 = E1 = 1110 0001 w_DataMux_ALU = 1 w_AddrLMux_PCL = 1 w_AddrHMux_PCH = 1 w_AddrLMux_EAL = 0 w_AddrLMux_ALU = 0 w_AddrHMux_ALU = 0 w_AluAMux_ALU = 0 w_AluAMux_DIN = 1 d2 = 01 = 0000 0001 w_AluBMux_01 = 0 w_AluBMux_A = 0 w_AluBMux_X = 0 w_AluBMux_Y = 0 w_AluBMux_DIN = 0 w_AluCMux_1 = 0 w_AluCMux_CF = 0 w_AluCMux_C7 = 1 d3 = 08 = 0000 1000 w_AluOp_OR = 0 w_AluOp_AND = 0 w_AluOp_XOR = 0 w_AluOp_BIT = 0 w_AluOp_ADC = 1 w_AluOp_SBC = 0 w_AluOp_ROR = 0 (unassigned) = 0 d4 = 03 = 0000 0011 (unassigned) = 0 (unassigned) = 0 (unassigned) = 0 (unassigned) = 0 (unassigned) = 0 w_WriteY = 0 w_nRD = 1 <-- WRONG! w_nWR = 1 The root cause was that ldy abs,x did not set w_nRD = 0 on ST[1]. --> mappy worked after the bug fix --> Wrecking Crew worked after the bug fix --> Super Mario Bros showed correct image after the bug fix --> Demo screen of Ninja Hattori-kun worked (Hattori-kun died as soon as demo started before the fix) --> Demo screen of Xevious worked after the bug fix --> Demo screen of Clu Clu Land worked correctly after the bug fix --> Demo screen of Baseball worked correctly after the bug fix --> Demo screen of Star Force worked better after the bug fix (still glitches) --> Demo screen of Lode Runner showed no garbage and hole goes back to undigged state completely after the bug fix --> DQ2 nsf works much better (still some triangle tones missing, but this is probably due to bug in APU) probably many other games should work now --> Zippy Race still hangs on the title screen --> Spelunker still hangs upon transition to demo screen