home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol236 / move.mac < prev    next >
Encoding:
Text File  |  1986-02-13  |  5.4 KB  |  146 lines

  1.         title 'bank & move module for CP/M3 linked BIOS'
  2.                                 ; use M80 to assemble
  3.  
  4. true    equ -1
  5. false   equ 0
  6.  
  7. banked  equ true                ; banked version
  8.         .z80
  9.  
  10.         entry ?move,?xmove,?bank
  11.                 if banked
  12.         entry ?bank0,?rbank,?trans,@xsp,@xmvst
  13.         external @cbnk
  14.                 endif
  15.  
  16.         cseg
  17.  
  18.  
  19. ?move:
  20.                 if banked
  21.         ld a,(@xmvst)           ; get xmove status
  22.         and a                   ; set flags
  23.                 endif
  24.         ex de,hl                ; we are passed source in DE and dest in HL
  25.                 if banked
  26.         jr nz,ibnk              ; interbank transfer
  27.                 endif
  28.         ldir                    ; use Z80 block move instruction
  29.         ex de,hl                ; need next addresses in same regs
  30.         ret
  31.  
  32.                 if banked
  33. ibnk:                           ; interbank transfer
  34.         xor a                   ; clear a
  35.         ld (@xmvst),a           ; reset xmove status
  36.         ld (@xsp),sp            ; switch stack
  37.         ld sp,@xsp
  38.         ld a,(xmvsou)           ; source bank
  39.         call ?bank              ; set bank
  40.         push de                 ; keep destination
  41.         push bc                 ; keep length
  42.         ld de,ibuff             ; buffer in common memory
  43.         ldir                    ; copy to buffer
  44.         ld a,(xmvdes)           ; destination bank
  45.         call ?bank              ; set bank
  46.         pop bc                  ; get length
  47.         ex (sp),hl              ; dest in hl, end of source in stack
  48.         ex de,hl                ; destination in de
  49.         ld hl,ibuff             ; buffer in common memory
  50.         ldir                    ; copy from buffer
  51.         ex de,hl                ; end of destination in hl
  52.         pop de                  ; end of source in de
  53.         ld a,(@cbnk)            ; bank we started with
  54.         call ?bank              ; restore bank
  55.         ld sp,(@xsp)            ; restore stack
  56.         ret
  57.  
  58. ?bank:
  59.         out (0feh),a            ; switch board
  60.         and a                   ; to get flags
  61.         ld a,0                  ; clear a
  62.         jr nz,zero              ; disk contr on for bank zero
  63.         inc a                   ; set a to 1
  64. zero:   out (40h),a             ; switch disk controller
  65.         ret
  66.  
  67. ?bank0:                         ; get bank 0
  68.         pop hl                  ; get return address
  69.         ld (@xsp),sp            ; store stack pointer
  70.         ld sp,@xsp              ; use temporary stack in common memory
  71.         push af
  72.         xor a                   ; a=0
  73.         call ?bank              ; set bank
  74.         pop af
  75.         jp (hl)                 ; return
  76.  
  77. ?rbank:                         ; restore bank
  78.         pop hl                  ; get return address
  79.         push af
  80.         ld a,(@cbnk)            ; get last bank
  81.         call ?bank              ; set bank
  82.         pop af
  83.         ld sp,(@xsp)            ; restore stack pointer
  84.         jp (hl)                 ; return
  85.  
  86. ?trans:                         ; transfer a series of 128 byte blocks
  87.                                 ;   from one bank to another
  88.                                 ; a = number of blocks
  89.                                 ; b = destination bank
  90.                                 ; c = source bank
  91.                                 ; de = source initial location
  92.                                 ; hl = destination initial location
  93.         and a                   ; check a non-zero
  94.         ret z
  95.         ex de,hl                ; source in hl, destination in de
  96.         ld (xtrsou),bc          ; remember bc
  97.         ld (@xsp),sp            ; set up stack in common memory
  98.         ld sp,@xsp
  99.         ld b,a                  ; number of blocks
  100. tloop:  push bc                 ; keep block count
  101.         ld a,(xtrsou)           ; source bank
  102.         call ?bank
  103.         push de                 ; destination on stack
  104.         ld de,ibuff             ; 128 byte buffer
  105.         ld bc,128
  106.         ldir                    ; copy to common memory
  107.         ld a,(xtrdes)           ; destination bank
  108.         call ?bank
  109.         ex (sp),hl              ; source on stack, destination in hl
  110.         ex de,hl                ; destination in de
  111.         ld hl,ibuff             ; 128 byte buffer
  112.         ld bc,128
  113.         ldir                    ; copy from common memory
  114.         pop hl                  ; source on hl
  115.         pop bc                  ; get back block count
  116.         djnz tloop              ; loop
  117.         ex de,hl                ; to conform to DR's convention
  118.         ld a,(@cbnk)            ; restore bank
  119.         call ?bank
  120.         ld sp,(@xsp)            ; restore stack
  121.         ret
  122.  
  123.         ds 16                   ; temporary stack
  124. @xsp:   ds 2                    ; temporary storage for sp
  125.  
  126. xmvsou: ds 1                    ; source bank
  127. xmvdes: ds 1                    ; destination bank
  128. @xmvst: db 0                    ; xmove status (0ffh for interbank mv)
  129. xtrsou: ds 1                    ; source bank used by transfer
  130. xtrdes: ds 1                    ; destination bank used by transfer
  131. ibuff:  ds 128                  ; buffer for interbank move
  132.  
  133.         dseg
  134.  
  135. ?xmove:                         ; setup interbank move
  136.         ld (xmvsou),bc          ; load source & destination banks
  137.         ld a,0ffh
  138.         ld (@xmvst),a           ; xmove status
  139.         ret
  140.  
  141.                 else
  142. ?bank:                          ; dummy routines for unbanked system
  143. ?xmove: ret
  144.                 endif 
  145.         end
  146.