×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library

AAA9 USR

Submitted by Steve Fewell

Description:

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.
br>

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.
After the routine &9304 has been executed, and the machine code routine has been run, the 6502 register and flag values
(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

AAA9   032 180 150 20 B4 96 JSR &96B4 Get value and convert it to Integer
AAAC   032 004 147 20 04 93 JSR &9304 Execute the machine code routine pointed to by the IWA (&2A-&2B)
AAAF * 133 042 85 2A STA &2A
AAB1 + 134 043 86 2B STX &2B
AAB3 , 132 044 84 2C STY &2C
AAB5   008 08 PHP
AAB6 h 104 68 PLA
AAB7 - 133 045 85 2D STA &2D
AAB9   216 D8 CLD
AABA   128 212 80 D4 BRA -44 --> &AA90 Exit with A=&40

 


 Back to 8BS
Or