*BANKIT

* This is the part of the BANKIT code that should be assembled into every
* used Eprom bank. The main part of BANKIT is placed into the RAM bank 0
* during the powerup routine. For safety, maybe we should think about placing
* it there during every DSR call?
*
* This routine will bank in the requested eprom bank and branch to the routine
* specified. For convenience, all routines will have the bank and offset
* equated to a label.
*
* calling format 1:
*
* BLWP @BANKIT
* DATA <bank# & offset>       as equated
*
* control will be returned to the bank that called the routine, directly
* following the DATA statement.
*
* for the sub to return control to the caller, all it has to do is to B or BL
* to address BNKRT. The sub must make sure that RAM 0 is mapped in.
*
* calling format 2:
*
* BL   @BLNKIT
* DATA <bank# & offset>
*
* Functions the same as bankit, but will map in ram bank 0 for you.
* There is also a return that will bank in ram 0 for you: BLRET. All bankit
* routines may be used interchangably. You may call your return with the
* BLWP @BANKIT and use the B (or BL) @BLRET to return to the calling
* routine. Or whatever. The only difference is if you want the bankit routines
* to map in ram bank 0 or not. There is less overhead (read: it's faster) if
* you don't use the BL calls to bankit.
*
*
* By Brad Snyder for the WHT SCSI Adaptor. 12-23-94.
* Updated 12-28-94 bls
* debug 1/3/94 bls - had blwp vectors reversed.
* updated 01-06-95 - addresses changed
* updated 01-17-95 - moved stack handler to rom
* updated 02-05-95 - added BL call to bankit
* updated 02-16-95 - added equates for dsrrt routine
* updated 03-29-95 - added direct access to bank routine called XFER

* Addresses used in bank 0 of SCSI ram

AINIT  EQU  >5C58             init string
ALWS   EQU  >5C5C             WS for allocate and de-allocate
*PATH  EQU  >5C7C             path buffer (Now in bank 2)
DSRRT  EQU  >5CA4             routine in ram to return from dsr
PABADR EQU  >5CC0             2 byte pab pointer
PABBUF EQU  >5CC2             10 byte pab buffer
TMPWS  EQU  >5CCC             32 bytes for saving WS registers
SAVR1  EQU  TMPWS+2
SAVR11 EQU  TMPWS+22
FNCB   EQU  >5CEC
STACK  EQU  >5CF6             pointer to bankit stack
BANKWS EQU  >5DB6
SAVDEV EQU  >5DFB             last device # (scsi id) accessed
SAVSEC EQU  >5DFC             sector number last accessed (2 words)
SECBUF EQU  >5E00             512 byte last sector read
STINIT EQU  >5CF8             stack init value
STK    EQU  >5CF6             stack pointer

* Bankit routines for ROM

BANKIT DATA BANKWS,BNKIT1     Using WS in RAM bank 0. RAM bank 0 must be
*                             mapped in before calling this routine!

ZERO   DATA 0                 general purpose zero

* BL call to bankit. R12 must hold the CRU base of the SCSI card in the
* MSbyte. Bank 0 of the ram will be mapped in and left mapped in, even on
* return to the caller.

* Registers dest.: R12

BLNKIT ANDI R12,>FF00
       AI   R12,12*2          point to ram mapper
       LDCR @ZERO,4           map in bank zero
       MOV  R11,@BANKWS+28    save return address for rtwp return
       STWP R11
       MOV  R11,@BANKWS+26    store current WP
       STST R11
       MOV  R11,@BANKWS+30    store status
       LWPI BANKWS            use bankws

* This code used by both versions of bankit

BNKIT1 MOV  @STACK,R9         get stack pointer
       MOV  @BANKN,*R9+       save calling eprom bank on stack
       MOV  *R14+,R1          move called routine bank and offset to RO
       MOV  R13,*R9+          save return WS
       MOV  R14,*R9+          save return address
       MOV  R15,*R9+          save status
       MOV  R9,@STACK         save stack pointer
       B    @>5DD6            branch to banking code already in RAM

* BL return to caller routine

* R12 must contain the CRU base of the SCSI card

BLRET  ANDI R12,>FF00
       AI   R12,12*2
       LDCR @ZERO,4           map bank 0 ram back in

* Code used by both versions of the return to caller routine

BNKRT  LWPI BANKWS            be sure!
       MOV  @STACK,R9         get stack pointer
       AI   R9,-8             point back to old stuph
       MOV  R9,@STACK         save pointer
       MOV  *R9+,R10          get bank to return to
       MOV  *R9+,R13          get WS
       MOV  *R9+,R14          get ret. addr.
       MOV  *R9+,R15          get status
       B    @>5DEC            branch to code in ram

