NickH93 wrote:
EDIT: Also, I forgot to mention. I noticed the mini_mon.asm for the simulator has a CLD command before running BASIC. I hadn't been putting one in for my board. Just resetting the stack. Would this cause issues?
Possibly. When in decimal mode the MPU has a markedly different behavior in processing the
ADC and
SBC instructions.
It's best not to make any assumptions about the MPU's state, including whether it is in binary or decimal mode. This is especially important with the NMOS parts, which do not initialize the
D bit in the status register to any particular value following a reset or hardware interrupt. So what I would do would be:
Code:
;SIMPLE 6502/65C02 HARD RESET PREAMBLE
;
HRST SEI ;disallow IRQs
CLD ;ensure binary mode
LDX #$FF ;initialize...
TXS ;MPU stack
...carry out other initialization steps as required...
CLI ;allow IRQs...
...program continues...
Use the top-of-stack value required for your application.
The order in which this is carried out is important. The initial
SEI is there to take care of the case where the
HRST routine is called from software. A hard reset would automatically mask IRQs, but jumping to
HRST would not without the
SEI. Only after all initialization steps are carried out would you enable IRQs.
Unlike the NMOS parts, the 65C02 will clear decimal mode following any kind of interrupt, hard or soft (asserting reset is seen as a hard interrupt). Hence the
CLD in the above would be redundant, but should be retained for the same reason that the
SEI is present.