I had some free time this weekend, so I threw together a 6502 emulator, this is the first time I've ever looked at 6502, or written an emulator, so I'm sure there are lots of flaws.
Of course, I couldn't leave it at that, so I started researching the NES, and I wrote a rom file loaded.
Once a rom is loaded (Mario 1) and the instruction pointer pointed at the ROM bank, it gives the following output:
As you can tell, it immediately starts by hitting BRK, which jumps to $F081, it then runs a couple instructions before it hits a Branch If Carry which jumps back to $998D, the next instruction from that is another BRK, which causes the loop to repeat.
My question is, do I have a bug in BRK and BCC causing it to jump to the wrong addresses?
Is this normal behavior if I'm not handling something?
Full debug breakout for the emulator (All Registers and Flags) is available here:
http://pastebin.com/f4f3d680c
And the full source is available here:
http://www.codeplex.com/Cpu6502/SourceC ... SetId=1810
I'm hoping my CPU emulation is correct, and this is just what the NES would do if it is missing something in the implementation.
Thanks in advance.
Of course, I couldn't leave it at that, so I started researching the NES, and I wrote a rom file loaded.
Once a rom is loaded (Mario 1) and the instruction pointer pointed at the ROM bank, it gives the following output:
Quote:
Program Counter Was At: 32768
Executing Instruction: Cpu6502.Opcodes.BRK with argument: 0
Program Counter Now At: 61569
Program Counter Was At: 61569
Executing Instruction: Cpu6502.Opcodes.LDX_A with argument: 1805
Program Counter Now At: 61572
Program Counter Was At: 61572
Executing Instruction: Cpu6502.Opcodes.CLC with argument: 0
Program Counter Now At: 61573
Program Counter Was At: 61573
Executing Instruction: Cpu6502.Opcodes.ADC_I with argument: 1
Program Counter Now At: 61575
Program Counter Was At: 61575
Executing Instruction: Cpu6502.Opcodes.DEC_ZP with argument: 0
Program Counter Now At: 61577
Program Counter Was At: 61577
Executing Instruction: Cpu6502.Opcodes.BCC with argument: -22270
Program Counter Now At: 39309
Program Counter Was At: 39309
Executing Instruction: Cpu6502.Opcodes.SBC_I with argument: 160
Program Counter Now At: 39311
Program Counter Was At: 39311
Executing Instruction: Cpu6502.Opcodes.BRK with argument: 0
Program Counter Now At: 61569
Executing Instruction: Cpu6502.Opcodes.BRK with argument: 0
Program Counter Now At: 61569
Program Counter Was At: 61569
Executing Instruction: Cpu6502.Opcodes.LDX_A with argument: 1805
Program Counter Now At: 61572
Program Counter Was At: 61572
Executing Instruction: Cpu6502.Opcodes.CLC with argument: 0
Program Counter Now At: 61573
Program Counter Was At: 61573
Executing Instruction: Cpu6502.Opcodes.ADC_I with argument: 1
Program Counter Now At: 61575
Program Counter Was At: 61575
Executing Instruction: Cpu6502.Opcodes.DEC_ZP with argument: 0
Program Counter Now At: 61577
Program Counter Was At: 61577
Executing Instruction: Cpu6502.Opcodes.BCC with argument: -22270
Program Counter Now At: 39309
Program Counter Was At: 39309
Executing Instruction: Cpu6502.Opcodes.SBC_I with argument: 160
Program Counter Now At: 39311
Program Counter Was At: 39311
Executing Instruction: Cpu6502.Opcodes.BRK with argument: 0
Program Counter Now At: 61569
As you can tell, it immediately starts by hitting BRK, which jumps to $F081, it then runs a couple instructions before it hits a Branch If Carry which jumps back to $998D, the next instruction from that is another BRK, which causes the loop to repeat.
My question is, do I have a bug in BRK and BCC causing it to jump to the wrong addresses?
Is this normal behavior if I'm not handling something?
Full debug breakout for the emulator (All Registers and Flags) is available here:
http://pastebin.com/f4f3d680c
And the full source is available here:
http://www.codeplex.com/Cpu6502/SourceC ... SetId=1810
I'm hoping my CPU emulation is correct, and this is just what the NES would do if it is missing something in the implementation.
Thanks in advance.