]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blame - cbios/move.180
Time/Date support
[z180-stamp-cpm3.git] / cbios / move.180
CommitLineData
ea5293bb
L
1 title 'Bank & Move Module for the Modular CP/M 3 BIOS'
2
3; CP/M-80 Version 3 -- Modular BIOS
4; Bank and Move Module for Z180-Stamp
5; Initial version 1.0
6; Compile with M80, slr180, or compatible
7
8 public ?move,?xmove,?bank
9
10 extrn bnk2log,bnk2phy
11 extrn @cbnk
12
13
14 include config.inc
15 include z180reg.inc
16
17
18 cseg ; must be in common memory
19
20?xmove:
21 if banked
22 ld (src$bnk),bc ; c -> src$bnk, b -> dst$bnk
23 endif
24 ret
25
26?move:
27 ex de,hl ; we are passed source in DE and dest in HL
28 if banked
29 ld a,(src$bnk) ; contains 0FEh if normal block move
30 cp 0FEh
31 jr nz,inter_bank_move
32 endif
33 ldir ; use Z80 block move instruction
34 ex de,hl ; need next address in same regs
35 ret
36
37; select bank in A
38
39?bank:
40 if banked
41 call bnk2log
42 out0 (bbr),a
43 endif
44 ret
45
46 if banked
47
48inter_bank_move: ; source in HL, dest in DE, count in BC
49 if 0 ; *** DOES NOT WORK PROPERLY
50 ; (Crossing Bank boundary problems)
51 push bc
52 push de
53 push hl
54
55;TODO: check if source range crosses bank/common boundary
56
57 ld a,(src$bnk)
58 call bnk2phy
59
60 out0 (sar0l),l ; setup DMA src address
61 out0 (sar0h),h
62 out0 (sar0b),a
63
64;TODO: check if destination range crosses bank/common boundary
65
66 ex de,hl
67 ld a,(dst$bnk)
68 call bnk2phy
69
70 out0 (dar0l),l ; setup DMA dst address
71 out0 (dar0h),h
72 out0 (dar0b),a
73
74 ld a,M_MMOD ; DMA burst mode
75 out0 (dmode),a
76 out0 (bcr0l),c ; setup DMA count
77 out0 (bcr0h),b
78 ld a,M_DE0+M_NDWE1 ; enable DMA0
79 out0 (dstat),a ; move the block
80
81 pop hl
82 pop de
83 pop bc
84
85 add hl,bc ; src must point past end block
86 ex de,hl
87 add hl,bc ; and so must dst
88 ld bc,0
89
90 ld a,0FEh
91 ld (src$bnk),a
92
93 ret ; return with src in DE, dst in HL, count = 0
94
95 else ; *** INNEFICIENT, BUT WORKS
96
97 ld (tmp$sp),sp
98 ld sp,tmp$stk
99 ex af,af' ;
100 push af
101mv$blk:
102 ld a,(src$bnk) ;
103 call ?bank
104 ld a,(hl)
105 ex af,af' ;
106 ld a,(dst$bnk)
107 call ?bank
108 ex af,af' ;
109 ld (de),a
110 inc hl
111 inc de
112 dec bc
113 ld a,b
114 or c
115 jr nz,mv$blk
116 ld a,(@cbnk)
117 call ?bank
118 ld a,0FEh
119 ld (src$bnk),a
120 ex de,hl
121 pop af
122 ex af,af' ;
123 ld sp,(tmp$sp)
124 ret
125
126 ds 16
127tmp$stk:
128tmp$sp: ds 2
129
130 endif
131
132src$bnk: db 0FEh
133dst$bnk: db 0FEh
134
135
136 endif ;banked
137
138 end