- title 'Bank & Move Module for the Modular CP/M 3 BIOS'
-
-; CP/M-80 Version 3 -- Modular BIOS
-; Bank and Move Module for Z180-Stamp
-; Initial version 1.0
-; Compile with M80, slr180, or compatible
-
- public ?move,?xmove,?bank
-
- extrn bnk2log,bnk2phy
- extrn @cbnk
-
-
- include config.inc
- include z180reg.inc
-
-
- cseg ; must be in common memory
-
-?xmove:
- if banked
- ld (src$bnk),bc ; c -> src$bnk, b -> dst$bnk
- endif
- ret
-
-?move:
- ex de,hl ; we are passed source in DE and dest in HL
- if banked
- ld a,(src$bnk) ; contains 0FEh if normal block move
- cp 0FEh
- jr nz,inter_bank_move
- endif
- ldir ; use Z80 block move instruction
- ex de,hl ; need next address in same regs
- ret
-
-; select bank in A
-
-?bank:
- if banked
- call bnk2log
- out0 (bbr),a
- endif
- ret
-
- if banked
-
-inter_bank_move: ; source in HL, dest in DE, count in BC
- if 0 ; *** DOES NOT WORK PROPERLY
- ; (Crossing Bank boundary problems)
- push bc
- push de
- push hl
-
-;TODO: check if source range crosses bank/common boundary
-
- ld a,(src$bnk)
- call bnk2phy
-
- out0 (sar0l),l ; setup DMA src address
- out0 (sar0h),h
- out0 (sar0b),a
-
-;TODO: check if destination range crosses bank/common boundary
-
- ex de,hl
- ld a,(dst$bnk)
- call bnk2phy
-
- out0 (dar0l),l ; setup DMA dst address
- out0 (dar0h),h
- out0 (dar0b),a
-
- ld a,M_MMOD ; DMA burst mode
- out0 (dmode),a
- out0 (bcr0l),c ; setup DMA count
- out0 (bcr0h),b
- ld a,M_DE0+M_NDWE1 ; enable DMA0
- out0 (dstat),a ; move the block
-
- pop hl
- pop de
- pop bc
-
- add hl,bc ; src must point past end block
- ex de,hl
- add hl,bc ; and so must dst
- ld bc,0
-
- ld a,0FEh
- ld (src$bnk),a
-
- ret ; return with src in DE, dst in HL, count = 0
-
- else ; *** INNEFICIENT, BUT WORKS
-
- ld (tmp$sp),sp
- ld sp,tmp$stk
- ex af,af' ;
- push af
-mv$blk:
- ld a,(src$bnk) ;
- call ?bank
- ld a,(hl)
- ex af,af' ;
- ld a,(dst$bnk)
- call ?bank
- ex af,af' ;
- ld (de),a
- inc de
- cpi
- jp pe,mv$blk
- ld a,(@cbnk)
- call ?bank
- ld a,0FEh
- ld (src$bnk),a
- ex de,hl
- pop af
- ex af,af' ;
- ld sp,(tmp$sp)
- ret
-
- ds 16
-tmp$stk:
-tmp$sp: ds 2
-
- endif
-
-src$bnk: db 0FEh
-dst$bnk: db 0FEh
-
-
- endif ;banked
-
- end
+ title 'Bank & Move Module for the Modular CP/M 3 BIOS'\r
+\r
+; CP/M-80 Version 3 -- Modular BIOS\r
+; Bank and Move Module for Z180-Stamp\r
+; Initial version 1.0\r
+; Compile with M80, slr180, or compatible\r
+\r
+ public ?move,?xmove,?bank\r
+\r
+ extrn bnk2log,bnk2phy\r
+ extrn @cbnk\r
+\r
+\r
+ maclib z180reg.inc\r
+ maclib config.inc\r
+\r
+\r
+ cseg ; must be in common memory\r
+\r
+?xmove:\r
+ if banked\r
+ ld (src$bnk),bc ; c -> src$bnk, b -> dst$bnk\r
+ endif\r
+ ret\r
+\r
+?move:\r
+ ex de,hl ; we are passed source in DE and dest in HL\r
+ if banked\r
+ ld a,(src$bnk) ; contains 0FEh if normal block move\r
+ cp 0FEh\r
+ jr nz,inter_bank_move\r
+ endif\r
+ ldir ; use Z80 block move instruction\r
+ ex de,hl ; need next address in same regs\r
+ ret\r
+\r
+; select bank in A\r
+\r
+?bank:\r
+ if banked\r
+ call bnk2log\r
+ out0 (bbr),a\r
+ endif\r
+ ret\r
+\r
+ if banked\r
+\r
+inter_bank_move: ; source in HL, dest in DE, count in BC\r
+\r
+ if 1 ; works with new memory map\r
+\r
+ out0 (bcr0l),c ; setup DMA count\r
+ out0 (bcr0h),b\r
+\r
+ push hl\r
+ push de\r
+ ld a,(src$bnk)\r
+ call bnk2phy\r
+ out0 (sar0l),l ; setup DMA src address\r
+ out0 (sar0h),h\r
+ out0 (sar0b),a\r
+\r
+ ex de,hl\r
+ ld a,(dst$bnk)\r
+ call bnk2phy\r
+ out0 (dar0l),l ; setup DMA dst address\r
+ out0 (dar0h),h\r
+ out0 (dar0b),a\r
+\r
+ ld a,M_MMOD ; DMA burst mode\r
+ out0 (dmode),a\r
+ ld a,M_DE0+M_NDWE1 ; enable DMA0\r
+ out0 (dstat),a ; move the block\r
+\r
+ pop de\r
+ pop hl\r
+ add hl,bc ; src must point past end block\r
+ ex de,hl\r
+ add hl,bc ; and so must dst\r
+ ld bc,0\r
+\r
+ ld a,0FEh\r
+ ld (src$bnk),a\r
+\r
+ ret ; return with src in DE, dst in HL, count = 0\r
+\r
+ else ; inefficient fall back\r
+\r
+ ld (tmp$sp),sp\r
+ ld sp,tmp$stk\r
+ ex af,af' ;\r
+ push af\r
+mv$blk:\r
+ ld a,(src$bnk) ;\r
+ call ?bank\r
+ ld a,(hl)\r
+ ex af,af' ;\r
+ ld a,(dst$bnk)\r
+ call ?bank\r
+ ex af,af' ;\r
+ ld (de),a\r
+ inc de\r
+ cpi\r
+ jp pe,mv$blk\r
+ ld a,(@cbnk)\r
+ call ?bank\r
+ ld a,0FEh\r
+ ld (src$bnk),a\r
+ ex de,hl\r
+ pop af\r
+ ex af,af' ;\r
+ ld sp,(tmp$sp)\r
+ ret\r
+\r
+ ds 16\r
+tmp$stk:\r
+tmp$sp: ds 2\r
+\r
+ endif\r
+\r
+src$bnk: db 0FEh\r
+dst$bnk: db 0FEh\r
+\r
+\r
+ endif ;banked\r
+\r
+ end\r