Open breakintoprogram opened 1 year ago
This only affects 16-bit MOS commands like Hello_16 or Memdump. The solution is to adjust the stack pointer to &8000 in the initialisation code, restoring the stack before returning to MOS. This has been implemented in Memdump and Hello_16.
Keeping this card open as there is a further consideration with regards to MOS and SPS, as the MOS CALL.LIS may potentially overwrite the topmost entry.
This issue was raised by Reinhard Schu on Facebook:
I have written a stacktest program that runs as a MOS command. Please see the output in the attached screenshot. My init.inc code automatically detects when its running as a MOS command and re-adjusts the SPS to $7FFE. Without this adjustment, if you study the output of my stacktest program, you will see that a MOS command that pushes more than 256 bytes onto the SPS with PUSH and POP instructions in Z80 (16-bit) mode will conflict with the SPL, as the top of both SPL and SPS will be at $08FFFF.
I have written my own init.inc code to correct this, but I would suggest it is best to fix the MOS to set the SPS to $7FFE when spawning a MOS ccommand, otherwise MOS commands could have unpredictable results due to SPS/SPL stack conflict.