6502 Code Reproduces Bug -- Curiousity
Posted: Wed Jul 16, 2008 3:32 am
I had memory back in time when I played with Apple II Plus. Apple II Plus uses an original 6502 microprocessor chip. Few software programs use illegal instructions because some illegal instructions treated like NOP. Only 65C02 added NOP to all illegal instructions.
Try to compare Opcode -- 02 and 03 or 13. If you use Opcode -- 02, 6502 MPU is frozen until you pull RESET' line low to restart. A question is why can't Opcode 03 or 13 be frozen until you pull RESET' line low to restart.
Possibly, Opcode 13 is like immediate. You enter the code 13 03 = ??? 03. It treats NOP. You can try to enter the code 13 08 = ??? 08. It treats frozen until you pull RESET' line low.
Let me give you an example code.
2000: LDY #00
2002: LDA #00
2004: 13 03 (??? # 03)
2006: NOP
2007: STA 3000,Y
200A: INC 2003
200B: INY
200E: BNE 2002
200F: RTS
Notice 200A: INC 2003? It is not a practice to modify code when it is supposed to modify data outside of code. Anyway, LDA #00 can be replaced to LDX #00, but I don't trust INX and DEX because illegal instructions might modify Accumulator register, Index X register, and Index Y register. It is best to modify inside code at run time while one byte in a code can be loaded into register again from memory.
Type "2000G" to run a program couple times. Then type "3000.30FF" to examine data in memory. Notice that memory reads 00 01 02 03 04 .... FF. Try to modify from ??? 03 to ??? 01 or ??? 02 and run again. Notice data in the memory? It does not look like real random. Run "2000G" again two or three more times until memory reads 00 01 02 03 04 .... FF.
Try to modify and use ??? 08 and so forth. You may notice that 6502 MPU is frozen until you pull RESET' line low.
Please let me know what you think. You can invest your time to try and play with my code. You can try to reproduce 6502 bug!
I like to do my experiment to reproduce bug when ADC and SBC use decimal mode. They claim Overflow flag has bug as invalid with invalid Negative flag, Zero flag, and Carry flag. However, in my conclusion, Overflow flag is 100% correct while in decimal mode!
Bryan Parkoff
Try to compare Opcode -- 02 and 03 or 13. If you use Opcode -- 02, 6502 MPU is frozen until you pull RESET' line low to restart. A question is why can't Opcode 03 or 13 be frozen until you pull RESET' line low to restart.
Possibly, Opcode 13 is like immediate. You enter the code 13 03 = ??? 03. It treats NOP. You can try to enter the code 13 08 = ??? 08. It treats frozen until you pull RESET' line low.
Let me give you an example code.
2000: LDY #00
2002: LDA #00
2004: 13 03 (??? # 03)
2006: NOP
2007: STA 3000,Y
200A: INC 2003
200B: INY
200E: BNE 2002
200F: RTS
Notice 200A: INC 2003? It is not a practice to modify code when it is supposed to modify data outside of code. Anyway, LDA #00 can be replaced to LDX #00, but I don't trust INX and DEX because illegal instructions might modify Accumulator register, Index X register, and Index Y register. It is best to modify inside code at run time while one byte in a code can be loaded into register again from memory.
Type "2000G" to run a program couple times. Then type "3000.30FF" to examine data in memory. Notice that memory reads 00 01 02 03 04 .... FF. Try to modify from ??? 03 to ??? 01 or ??? 02 and run again. Notice data in the memory? It does not look like real random. Run "2000G" again two or three more times until memory reads 00 01 02 03 04 .... FF.
Try to modify and use ??? 08 and so forth. You may notice that 6502 MPU is frozen until you pull RESET' line low.
Please let me know what you think. You can invest your time to try and play with my code. You can try to reproduce 6502 bug!
I like to do my experiment to reproduce bug when ADC and SBC use decimal mode. They claim Overflow flag has bug as invalid with invalid Negative flag, Zero flag, and Carry flag. However, in my conclusion, Overflow flag is 100% correct while in decimal mode!
Bryan Parkoff