The BBC and Master Computer Public Domain Library
Page Last Altered:
Submitted by Steve Fewell
Call routine &96B4 to obtain the result of the expression after the CALL Keyword and convert the result value to
Integer (if it was float, or issue 'Type mismatch' error if the result value was a String). Now the IWA contains the CALL
address for the machine code routine that is required to be executed.
After the routine &9304 has been executed, and the machine code routine has been run, the 6502 register and flag values
Unlike CALL, USR does not provide the facility for any variables to be passed to the machine code routine, so the machine
code can now be executed directly by calling routine &9304, which does the following:
- * Set A to &040C (the LSB of the C% variable) and shift the bits right 1 place, so that the carry flag is
- set to the value of the first bit (bit 0) of the &040C value.
- * Set A to &0404 (the LSB byte of the A% variable)
- * Set X to &0460 (the LSB byte of the X% variable)
- * Set Y to &0464 (the LSB byte of the Y% variable)
- * jump to the machine code address pointed to by IWA bytes &2A-&2B. The machine code routine will provide
- the return instruction to return from the &9304 subroutine.
(containing the 6502 processor state immediately after the machine code routine was executed) are stored in the IWA.
The A register is stored in &2A (the LSB byte of the IWA), X is stored in &2B, Y is stored in &2C and the
processor flags are stored in &2D (the MSB byte of the IWA).
Next, the decimal flag is cleared (incase is had been set by the machine code routine - as BASIC requires the decimal
flag to be clear - otherwise its calculations will be incorrect).
Lastly, as USR is a function, A is set to #&40 (to indicate that the function result is an Integer value - stored in
the IWA) and the USR routine exits back to the BASIC expression handler.
Disassembly for the USR routine
||032 180 150
||20 B4 96
||JSR &96B4 Get value and convert it to Integer
||032 004 147
||20 04 93
||JSR &9304 Execute the machine code routine pointed to by the IWA (&2A-&2B)
||BRA -44 --> &AA90 Exit with A=&40