If you are writing "BASIC-friendly" assembly language that is meant to get called from within a BASIC program, but there isn't room for the assembly source and the calling program, then this little function might help a little with debugging, without you having to wheel out something like EXMON II and trash your BASIC program:(Obviously adjust the line number to fit around your program.)
S% is the starting address of a machine code routine you want to call. F% is the address of the first instruction not to be executed; which will be temporarily overwritten with an RTS, and automatically restored afterwards. The function returns a value like USR() (which it's using internally), giving the contents of the accumulator, X and Y registers and the processor flags.
You can use this to run a chunk of machine code (being sure to set A%, X% and Y% beforehand if necessary) and exit from it early; check memory contents as required, to make sure all the right stuff is happening (maybe using your own BASIC display routines, which can sometimes be a little more friendly than the bunch of hex digits a machine code monitor will show you); run another chunk of code if you need to; and so on, until you encounter the misbehaviour.
You'll still to look at the assembly source (and probably run it, with the *SAVE removed) to find the "finishing" addresses you need; but at least once you have them, you can keep your own BASIC program in memory.
Code:
10000DEFFNdebug(S%,F%):LOCALG%,U%10010G%=?F%:?F%=&6010020U%=USRS%:?F%=G%:=U%
S% is the starting address of a machine code routine you want to call. F% is the address of the first instruction not to be executed; which will be temporarily overwritten with an RTS, and automatically restored afterwards. The function returns a value like USR() (which it's using internally), giving the contents of the accumulator, X and Y registers and the processor flags.
You can use this to run a chunk of machine code (being sure to set A%, X% and Y% beforehand if necessary) and exit from it early; check memory contents as required, to make sure all the right stuff is happening (maybe using your own BASIC display routines, which can sometimes be a little more friendly than the bunch of hex digits a machine code monitor will show you); run another chunk of code if you need to; and so on, until you encounter the misbehaviour.
You'll still to look at the assembly source (and probably run it, with the *SAVE removed) to find the "finishing" addresses you need; but at least once you have them, you can keep your own BASIC program in memory.
Statistics: Posted by julie_m — Fri Aug 09, 2024 4:43 pm