
 1000  *SAVE JOHNSON'S USE AUXMEM
 1010  *--------------------------------
 1020  * SWITCH.MIND Command:  ^Y
 1030  *
 1040  *   When in main bank, enters monitor in
 1050  *   auxmem BSR (hooks I/O through main
 1060  *   and brings USE.AUXMEM to auxmem too)
 1070  *   When in aux bank, returns to main bank
 1080  *   Best used w/80 column firmware active
 1090  *--------------------------------
 1100  * USE.AUXMOVE Command:  DEST<SOURCE.END^Y{CARRY}
 1110  *
 1120  *   DEST      = Destination in one bank
 1130  *   SOURCE    = Start in other bank
 1140  *   END       = End in other bank
 1150  *   CARRY     = Direction of move
 1160  *               (1 = Main Ram-->Card Ram)
 1170  *               (0 = Card Ram-->Main Ram)
 1180  *   DEST, SOURCE, & END must be: >=$0200 & <=$BFFF
 1190  *--------------------------------
 1200  * USE.XFER Command:  ADDRESS^Y{CARRY}{OVERFLOW}
 1210  *
 1220  *   ADDRESS   = Transfer address
 1230  *   CARRY     = Desired 48K Bank ($0200 - $BFFF)
 1240  *               (1 = Use 48K in Card Ram)
 1250  *               (0 = Use 48K in Main Ram)
 1260  *   OVERFLOW  = Desired ZP/STK/BSR
 1270  *               (1 = Use ZP/STK/BSR in Card Ram)
 1280  *               (0 = Use ZP/STK/BSR in Main Ram)
 1290  *   If using USE.XFER from auxmem, routine in main mem
 1300  *   MUST LDX BANK.SP.SAVE, TXS if it uses the stack at all
 1310  *--------------------------------
 1320  MON.BASL         .EQ $28,$29
 1330  MON.YSAV         .EQ $34
 1340  MON.CSWL         .EQ $36,$37
 1350  MON.KSWL         .EQ $38,$39
 1360  MON.A1           .EQ $3C,$3D   Source,Address
 1370  MON.A2           .EQ $3E,$3F   End
 1380  MON.A4           .EQ $42,$43   Dest
 1390  MON.STATUS       .EQ $48
 1400  *--------------------------------
 1410  IN                       .EQ $0200 - $02FF
 1420  BANK.X.SAVE              .EQ $03CC
 1430  BANK.BSR.BANK.SAVE       .EQ $03CD
 1440  BANK.BSR.RAM.READ.SAVE   .EQ $03CE
 1450  BANK.SP.SAVE             .EQ $03CF
 1460  TRANSFER                 .EQ $03ED,$03EE
 1470  MON.BRKV                 .EQ $03F0,$03F1
 1480  USRADR                   .EQ $03F8 - $03FA
 1490  NMI                      .EQ $03FB - $03FD
 1500  MON.IRQLOC               .EQ $03FE,$03FF
 1510  *--------------------------------
 1520  READ.MAIN.RAM            .EQ $C002
 1530  READ.AUX.RAM             .EQ $C003
 1540  WRITE.MAIN.RAM           .EQ $C004
 1550  WRITE.AUX.RAM            .EQ $C005
 1560  USE.MAIN.ZP.STK.BSR      .EQ $C008
 1570  USE.AUX.ZP.STK.BSR       .EQ $C009
 1580  READ.BSR.BANK            .EQ $C011
 1590  READ.BSR.RAM.READ        .EQ $C012
 1600  READ.RAM.READ.STATUS     .EQ $C013
 1610  READ.RAM.WRITE.STATUS    .EQ $C014
 1620  READ.ZP.STK.BSR.STATUS   .EQ $C016
 1630  BSR.2.RAM.READ.ONLY      .EQ $C080
 1640  BSR.2.ROM.READ.RAM.WRITE .EQ $C081
 1650  BSR.2.ROM.READ.ONLY      .EQ $C082
 1660  BSR.2.RAM.READ.RAM.WRITE .EQ $C083
 1670  BSR.1.RAM.READ.ONLY      .EQ $C088
 1680  BSR.1.ROM.READ.RAM.WRITE .EQ $C089
 1690  BSR.1.ROM.READ.ONLY      .EQ $C08A
 1700  BSR.1.RAM.READ.RAM.WRITE .EQ $C08B
 1710  *--------------------------------
 1720  AUXMOVE                  .EQ $C311
 1730  XFER                     .EQ $C314
 1740  MONITOR                  .EQ $F800 - $FFFF
 1750  MON.OLDBRK               .EQ $FA59
 1760  BEEP                     .EQ $FBDD
 1770  MON.RDKEY                .EQ $FD0C
 1780  MON.JSR.CLREOL           .EQ $FD8B - $FD8D
 1790  MON.COUT                 .EQ $FDED
 1800  MON                      .EQ $FF65
 1810  *--------------------------------
 1820             .OR $0803
 1830  USE.AUXMEM
 1840  G
 1850             JMP CONNECT.CONTROL.Y
 1860  JMP.TO.RETURN.TO.MAIN
 1870             JMP RETURN.TO.MAIN
 1880  JMP.TO.RETURN.TO.AUX
 1890             JMP RETURN.TO.AUX
 1900  JMP.TO.SAVE.BSR.STATE
 1910             JMP SAVE.BSR.STATE
 1920  JMP.TO.RESTORE.BSR.STATE
 1930             JMP RESTORE.BSR.STATE
 1940  *--------------------------------
 1950  CONNECT.CONTROL.Y
 1960             LDA /USE.AUXMEM.CONTROL.Y.HANDLER
 1970             STA USRADR+2
 1980             LDA #USE.AUXMEM.CONTROL.Y.HANDLER
 1990             STA USRADR+1
 2000             LDA #$4C      JMP
 2010             STA USRADR
 2020             RTS
 2030  *--------------------------------
 2040  USE.AUXMEM.CONTROL.Y.HANDLER
 2050  * Reconstruct monitor mode byte
 2060  * after "Bryan" messed with it
 2070  * ("Br" is NOPish)
 2080             PHA
 2090             LDA IN
 2100             CMP #"$"
 2110  * Branch w/Carry set causa S-C or Mini-Asm
 2120             BEQ .1
 2130             CLC
 2140  .1         PLA
 2150  * These lines are for you Bryan
 2160             .DA #'y'
 2170             .AS -'an'     Builds SBC $EEE1,Y
 2180  * Check for user specified address
 2190             CPX #$01
 2200             BNE SWITCH.MIND
 2210             TAY
 2220  * Lesser complex is USE.XFER
 2230             BEQ USE.XFER
 2240  * Most complex is USE.AUXMOVE
 2250  *--------------------------------
 2260  USE.AUXMOVE
 2270  * Fetch what should be a "0"
 2280  * or "1" to be AUXMOVE's carry
 2290             LDY MON.YSAV
 2300             LDA IN,Y
 2310  * Shift what we fetched to carry
 2320             LSR
 2330  * Save carry while comparing
 2340             PHP
 2350  * This is a "0" or "1" after a LSR
 2360             CMP #"0"/2
 2370             BNE INVALID.CARRY
 2380             INC MON.YSAV
 2390  * Recover Carry
 2400             PLP
 2410  CALL.AUXMOVE.WITH.CARRY
 2420             JSR AUXMOVE
 2430             RTS
 2440  *--------------------------------
 2450  USE.XFER
 2460  * Set XFER Transfer address
 2470  * from monitor parameter
 2480             LDA MON.A1,X
 2490             STA TRANSFER,X
 2500             DEX
 2510             BPL USE.XFER
 2520  * Fetch what should be a "0"
 2530  * or "1" to be XFER's carry
 2540             LDY MON.YSAV
 2550             LDA IN,Y
 2560  * Shift what we fetched to carry
 2570             LSR
 2580  * Save carry for a while
 2590             PHP
 2600  * This is a "0" or "1" after a LSR
 2610             CMP #"0"/2
 2620             BNE INVALID.CARRY
 2630             INC MON.YSAV
 2640  * Fetch what should be a "0"
 2650  * or a "1" to be XFER's overflow
 2660             INY
 2670             LDA IN,Y
 2680  * Shift what we fetched to carry
 2690             LSR
 2700  * Save this carry too, while we compare
 2710             PHP
 2720  * This is a "0" or "1" after a LSR
 2730             CMP #"0"/2
 2740             BNE INVALID.OVERFLOW
 2750             INC MON.YSAV
 2760  * Recovered carry is valid overflow
 2770             PLP
 2780  * Move it back to bit 0
 2790             ROL
 2800  * Recover carry
 2810             PLP
 2820  * Construct overflow
 2830             CLV
 2840             AND #%0000.0001
 2850             BEQ .1
 2860             BIT SEV
 2870  * Save BSR bank, BSR ram read, and SP
 2880  * for any calls or returns to main/auxmem
 2890  .1         JSR SAVE.BSR.STATE
 2900             TSX
 2910             STX BANK.SP.SAVE
 2920  JMP.XFER.WITH.CARRY.AND.OVERFLOW
 2930  * Routines in aux/main bank may jmp
 2940  * to RETURN.TO.MAIN/AUX when done
 2950  SEV        JMP XFER
 2960  *--------------------------------
 2970  INVALID.OVERFLOW
 2980             PLP
 2990  INVALID.CARRY
 3000             PLP
 3010  * Let's not process rest of line
 3020             LDY MON.YSAV
 3030             LDA #$8D
 3040             STA IN,Y
 3050             JMP BEEP
 3060  *--------------------------------
 3070  SWITCH.MIND
 3080  * Check in main or aux now
 3090             LDA READ.RAM.READ.STATUS
 3100             BPL ENTER.AUX.MON
 3110             JMP RETURN.TO.MAIN
 3120  ENTER.AUX.MON
 3130  * Move USE.AUXMEM to auxmem too
 3140             LDA #USE.AUXMEM
 3150             STA MON.A1
 3160             STA MON.A4
 3170             LDA /USE.AUXMEM
 3180             STA MON.A1+1
 3190             STA MON.A4+1
 3200             LDA #USE.AUXMEM.END
 3210             STA MON.A2
 3220             LDA /USE.AUXMEM.END
 3230             STA MON.A2+1
 3240             SEC
 3250             JSR AUXMOVE
 3260  * Save BSR bank, BSR ram read, and SP
 3270  * for calls and return to main mem
 3280             JSR SAVE.BSR.STATE
 3290             TSX
 3300             STX BANK.SP.SAVE
 3310  * Continue in auxmem w/rom
 3320             STA READ.AUX.RAM
 3330             STA WRITE.AUX.RAM
 3340             STA USE.AUX.ZP.STK.BSR
 3350             LDA BSR.2.ROM.READ.RAM.WRITE
 3360             LDA BSR.2.ROM.READ.RAM.WRITE
 3370  * What else but this too
 3380             LDX #$FF
 3390             TXS
 3400  * Copy rom monitor to auxmem BSR
 3410             LDY #MONITOR
 3420             STY MON.A1
 3430             STY MON.STATUS
 3440             LDA /MONITOR
 3450             STA MON.A1+1
 3460  .1         LDA (MON.A1),Y
 3470             STA (MON.A1),Y
 3480             INY
 3490             BNE .1
 3500             INC MON.A1+1
 3510             BNE .1
 3520  * Now use auxmem BSR
 3530             LDA BSR.2.RAM.READ.RAM.WRITE
 3540             LDA BSR.2.RAM.READ.RAM.WRITE
 3550  * Fix monitor in BSR
 3560             LDA /DO.CLREOL
 3570             STA MON.JSR.CLREOL+2
 3580             LDA #DO.CLREOL
 3590             STA MON.JSR.CLREOL+1
 3600  * Hook I/O through main
 3610             LDA #COUT.TO.MAIN
 3620             STA MON.CSWL
 3630             LDA #RDKEY.FROM.MAIN
 3640             STA MON.KSWL
 3650             LDA /COUT.TO.MAIN
 3660             STA MON.CSWL+1
 3670  *          LDA /RDKEY.FROM.MAIN
 3680             STA MON.KSWL+1
 3690  * USE.AUXMEM in auxmem too
 3700             JSR CONNECT.CONTROL.Y
 3710  * Do page 3 locs
 3720             STA NMI
 3730             LDA #MON
 3740             STA NMI+1
 3750             STA MON.IRQLOC
 3760             LDA /MON
 3770             STA NMI+2
 3780             STA MON.IRQLOC+1
 3790             LDA #MON.OLDBRK
 3800             STA MON.BRKV
 3810             LDA /MON.OLDBRK
 3820             STA MON.BRKV+1
 3830  * Enter monitor in auxmem BSR
 3840             JMP MON
 3850  *--------------------------------
 3860  RETURN.TO.AUX
 3870  * Continue in aux ram
 3880             STA READ.AUX.RAM
 3890             STA WRITE.AUX.RAM
 3900             STA USE.AUX.ZP.STK.BSR
 3910             JMP RETURN.COMMON
 3920  RETURN.TO.MAIN
 3930  * Continue in main ram
 3940             STA READ.MAIN.RAM
 3950             STA WRITE.MAIN.RAM
 3960             STA USE.MAIN.ZP.STK.BSR
 3970  RETURN.COMMON
 3980  * Recover SP
 3990             LDX BANK.SP.SAVE
 4000             TXS
 4010  RESTORE.BSR.STATE
 4020             CLV
 4030             LDX BANK.BSR.BANK.SAVE
 4040             BPL .2
 4050             LDX BANK.BSR.RAM.READ.SAVE
 4060             BPL .1
 4070             LDX BSR.2.RAM.READ.RAM.WRITE
 4080             LDX BSR.2.RAM.READ.RAM.WRITE
 4090             BVC .4
 4100  .1         LDX BSR.2.ROM.READ.RAM.WRITE
 4110             LDX BSR.2.ROM.READ.RAM.WRITE
 4120             BVC .4
 4130  .2         LDX BANK.BSR.RAM.READ.SAVE
 4140             BPL .3
 4150             LDX BSR.1.RAM.READ.RAM.WRITE
 4160             LDX BSR.1.RAM.READ.RAM.WRITE
 4170             BVC .4
 4180  .3         LDX BSR.1.ROM.READ.RAM.WRITE
 4190             LDX BSR.1.ROM.READ.RAM.WRITE
 4200  .4         RTS
 4210  *--------------------------------
 4220  SAVE.BSR.STATE
 4230             LDX READ.BSR.BANK
 4240             STX BANK.BSR.BANK.SAVE
 4250             LDX READ.BSR.RAM.READ
 4260             STX BANK.BSR.RAM.READ.SAVE
 4270             RTS
 4280  *--------------------------------
 4290  DO.CLREOL
 4300             LDA #"]"-'@'
 4310  COUT.TO.MAIN
 4320  * Save auxmem's X
 4330             STX BANK.X.SAVE
 4340  * Save BSR bank, BSR ram read, and SP
 4350  * over call to main ram
 4360             JSR SAVE.BSR.STATE
 4370             TSX
 4380             STX BANK.SP.SAVE
 4390  * Continue in main ram
 4400             STA READ.MAIN.RAM
 4410             STA WRITE.MAIN.RAM
 4420             STA USE.MAIN.ZP.STK.BSR
 4430  * Recover SP
 4440             LDX BANK.SP.SAVE
 4450             TXS
 4460             JSR RESTORE.BSR.STATE
 4470             JSR MON.COUT
 4480             JMP IO.COMMON
 4490  *--------------------------------
 4500  RDKEY.FROM.MAIN
 4510  * Repair monitor's sillier attempt
 4520             STA (MON.BASL),Y
 4530  * Save auxmem's X
 4540             STX BANK.X.SAVE
 4550  * Save BSR bank, BSR ram read, and SP
 4560  * over call to main ram
 4570             JSR SAVE.BSR.STATE
 4580             TSX
 4590             STX BANK.SP.SAVE
 4600  * Continue in main ram
 4610             STA READ.MAIN.RAM
 4620             STA WRITE.MAIN.RAM
 4630             STA USE.MAIN.ZP.STK.BSR
 4640             LDX BANK.SP.SAVE       Recover SP
 4650             TXS
 4660             JSR RESTORE.BSR.STATE
 4670             JSR MON.RDKEY
 4680  *--------------------------------
 4690  IO.COMMON
 4700             STA READ.AUX.RAM       Continue in Aux RAM
 4710             STA WRITE.AUX.RAM
 4720             STA USE.AUX.ZP.STK.BSR
 4730             LDX BANK.SP.SAVE       Recover SP
 4740             TXS
 4750             JSR RESTORE.BSR.STATE
 4760             LDX BANK.X.SAVE        Recover X
 4770             RTS
 4780  *--------------------------------
 4790  USE.AUXMEM.END           .EQ *-1

