05 ; #D:RELJSR.LST
0100 ;
0120 ;RELJSR jumps to a label
0140 ;RELJSR orgadr, label, relstart
0160 ;
0180 ;orgadr is the ORG address
0200 ;label is the address of the label you want to jump to
0220 ;relstart is the start address of the string that contains the ML code from BASIC
0240 ;
0260 ;have BASIC put ADR(sting$)
0280 ;store it at $D2 and $D3, $D4 through $FF, $100 and $101
0300 ;don't ust $D4 through $FF if your ML program calls the floating Point Package
0320 ;
0340 ;or get relstart from $D4 and $D5, FR0 - the first floating point register
0360 ;FR0 won't hold the runtime start address after your ML program accesses the floating point package
0380 ;
0400 ;this routine uses the A and X registers
0420 ;
0440 ;RELJSR orgadr, label, relstart
0460 ;
0480 .MACRO RELJSR
0500 CLC ;calculate the return
0520 LDA # <[?@@@@-%1]-1 ;calculate low byte
0540 ADC %3
0560 TAX ;put it in the X register
0580 ;----------------------
0600 LDA # >[?@@@@-%1]-1 ;high byte
0620 ADC %3+1
0640 PHA
0660 ;----------------------
0680 TXA ;get low byte from the X register
0700 PHA ;push low byte
0720 ;
1500 CLC ;calculate the jump
1520 LDA # <[%2-%1]-1 ;calculate low byte
1540 ADC %3
1560 TAX ;put it in the X register
1580 ;----------------------
1600 LDA # >[%2-%1]-1 ;high byte
1620 ADC %3+1
1640 PHA
1660 ;----------------------
1680 TXA ;get low byte from the X register
1700 PHA ;push low byte
1720 ;
1740 RTS ;jump to label
1760 ?@@@@
1780 NOP
1800 ;
1820 .ENDM
Back