]> cloudbase.mooo.com Git - avrcpm.git/blob - avrcpm/cpm/bios.asm
* avr/z80.asm:
[avrcpm.git] / avrcpm / cpm / bios.asm
1 ; CP/M BIOS for avrcpm
2 ; Copyright (C) 2010 Sprite_tm
3 ;
4 ; This program is free software: you can redistribute it and/or modify
5 ; it under the terms of the GNU General Public License as published by
6 ; the Free Software Foundation, either version 3 of the License, or
7 ; (at your option) any later version.
8 ;
9 ; This program is distributed in the hope that it will be useful,
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ; GNU General Public License for more details.
13 ;
14 ; You should have received a copy of the GNU General Public License
15 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 msize: equ 62 ;size of available RAM in k
18
19 bias: equ (msize-20) * 1024
20 ccp: equ $3400+bias ;base of cpm ccp
21 bdos: equ ccp+$806 ;base of bdos
22 bios: equ ccp+$1600 ;base of bios
23 cdisk: equ $0004 ;current disk number (0 ... 15)
24 iobyte: equ $0003 ;intel iobyte
25 buff: equ $0080 ;default buffer address
26 retry: equ 3 ;max retries on disk i/o before error
27
28 cr: equ 13
29 lf: equ 10
30
31 READ_FUNC: equ 7
32 WRITE_FUNC: equ 6
33 BOOT_FUNC: equ 5
34 HOME_FUNC: equ 4
35
36 org bios
37 nsects: equ ($-ccp)/128 ;warm start sector count
38
39 jp boot
40 wboote:
41 jp wboot
42 jp const
43 jp conin
44 jp conout
45 jp list
46 jp punch
47 jp reader
48 jp home
49 jp seldsk
50 jp settrk
51 jp setsec
52 jp setdma
53 jp read
54 jp write
55 jp listst
56 jp sectran
57
58 signon:
59 db cr,lf
60 db msize/10+'0'
61 db msize - (msize/10)*10 + '0' ;modulo doesn't work?
62 db "k cp/m vers 2.2"
63 db cr,lf,0
64
65 boot:
66 ld sp,buff
67 ld hl,signon
68 call prmsg
69 xor a
70 ld (iobyte),a
71 ld (cdisk),a
72 jp gocpm
73
74 wboot: ;re-load CP/M
75 ld sp,buff
76 ld a,1<<BOOT_FUNC
77 out (22),a
78 ld c,0
79 call seldsk
80 call home
81 ld b,nsects
82 ld c,0 ;track
83 ld d,1 ;sektor (0 based)
84 ld hl,ccp
85 load1:
86 push bc
87 push de
88 push hl
89 ld c,d
90 ld b,0
91 call setsec
92 pop bc
93 push bc
94 call setdma
95 call read
96 cp 0 ;read error?
97 jp nz,wboot
98
99 pop hl
100 ld de,128
101 add hl,de
102 pop de
103 pop bc
104 dec b
105 jp z,gocpm
106
107 inc d
108 ld a,d
109 cp 26 ;if sector >= 26 then change tracks
110 jp c,load1
111
112 ld d,0
113 inc c
114 push bc
115 push de
116 push hl
117 ld b,0
118 call settrk
119 pop hl
120 pop de
121 pop bc
122 jp load1
123
124 gocpm:
125 ld a,0c3h
126 ld (0),a
127 ld hl,wboote
128 ld (1),hl
129 ld (5),a
130 ld hl,bdos
131 ld (6),hl
132
133 ld bc,buff
134 call setdma
135 ld a,(cdisk)
136 ld c,a
137 jp ccp
138
139 const:
140 in a,(0)
141 ret
142
143 conin:
144 in a,(0)
145 cp $ff
146 jp nz,conin
147
148 in a,(1)
149 ret
150
151 conout:
152 ld a,c
153 out (2),a
154 ret
155
156 list:
157 ret
158
159 listst:
160 ld a,0
161 ret
162
163 punch:
164 ret
165
166 reader:
167 ld a,$1F
168 ret
169
170 seldsk:
171 ld hl,0 ;error return code
172 ld a,c
173 out (15),a
174 in a,(15) ;querry, if disk exists
175 or a ;0 = disk is ok
176 ret nz
177
178 ld l,c
179 ld h,0
180 add hl,hl
181 add hl,hl
182 add hl,hl
183 add hl,hl ;*16
184 ld de,dpbase
185 add hl,de ;return disk parameter header address
186 ret
187
188 home:
189 ld a,1<<HOME_FUNC
190 out (22),a
191
192 ld bc,0 ; same as seek to track 0
193 settrk:
194 ld a,c
195 out (16),a
196 ld a,b
197 out (17),a
198 ret
199
200 setsec:
201 ld a,c
202 out (18),a
203 ret
204
205 setdma:
206 ld a,c
207 out (20),a
208 ld a,b
209 out (21),a
210 ret
211
212 read:
213 ld a,1<<READ_FUNC
214 out (22),a
215 ld a,0
216 ret
217
218 write:
219 ld a,1<<WRITE_FUNC
220 or c ;merge write type in c
221 out (22),a
222 ld a,0
223 ret
224
225 sectran:
226 ;translate sector bc using table at de, res into hl
227 ld h,b
228 ld l,c
229 ld a,d
230 or e
231 ret z
232 ex de,hl
233 add hl,bc
234 ld l,(hl)
235 ld h,0
236 ret
237
238 prmsg:
239 ld a,(hl)
240 or a
241 ret z
242 push hl
243 ld c,a
244 call conout
245 pop hl
246 inc hl
247 jp prmsg
248
249
250 ;Disk Parameter Header
251 dpbase:
252 dpe0: dw 0 ;XLT: No sector translation table
253 dw 0 ;000: Scratchpad
254 dw 0 ;000: Scratchpad
255 dw 0 ;000: Scratchpad
256 dw dirbuf ;DIRBUF: Address of a dirbuff scratchpad
257 dw dpb ;DPB: Address of a disk parameter block
258 dw chk0 ;CSV: Address of scratchpad area for changed disks
259 dw all0 ;ALV: Address of an allocation info sratchpad
260 dpe1: dw 0 ;XLT: No sector translation table
261 dw 0 ;000: Scratchpad
262 dw 0 ;000: Scratchpad
263 dw 0 ;000: Scratchpad
264 dw dirbuf ;DIRBUF: Address of a dirbuff scratchpad
265 dw dpb ;DPB: Address of a disk parameter block
266 dw chk1 ;CSV: Address of scratchpad area for changed disks
267 dw all1 ;ALV: Address of an allocation info sratchpad
268 dpe2: dw 0 ;XLT: No sector translation table
269 dw 0 ;000: Scratchpad
270 dw 0 ;000: Scratchpad
271 dw 0 ;000: Scratchpad
272 dw dirbuf ;DIRBUF: Address of a dirbuff scratchpad
273 dw dpb ;DPB: Address of a disk parameter block
274 dw chk2 ;CSV: Address of scratchpad area for changed disks
275 dw all2 ;ALV: Address of an allocation info sratchpad
276 dpe3: dw 0 ;XLT: No sector translation table
277 dw 0 ;000: Scratchpad
278 dw 0 ;000: Scratchpad
279 dw 0 ;000: Scratchpad
280 dw dirbuf ;DIRBUF: Address of a dirbuff scratchpad
281 dw dpb ;DPB: Address of a disk parameter block
282 dw chk3 ;CSV: Address of scratchpad area for changed disks
283 dw all3 ;ALV: Address of an allocation info sratchpad
284
285 dpb:
286 dw 26 ;SPT: sectors per track
287 db 3 ;BSH: data allocation block shift factor
288 db 7 ;BLM: Data Allocation Mask
289 db 0 ;Extent mask
290 dw 242 ;DSM: Disk storage capacity
291 dw 63 ;DRM, no of directory entries
292 db 192 ;AL0
293 db 0 ;AL1
294 dw 16 ;CKS, size of dir check vector
295 dw 2 ;OFF, no of reserved tracks
296
297
298 dirbuf:
299 ds 128
300
301 chk0: ds 16
302 all0: ds 31
303 chk1: ds 16
304 all1: ds 31
305 chk2: ds 16
306 all2: ds 31
307 chk3: ds 16
308 all3: ds 31
309
310 end
311