]> cloudbase.mooo.com Git - avrcpm.git/blame - avrcpm/cpm/bios.asm
* avr/z80.asm:
[avrcpm.git] / avrcpm / cpm / bios.asm
CommitLineData
fdcfcd44
L
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
701f0287 17msize: equ 62 ;size of available RAM in k
fdcfcd44 18
701f0287
L
19bias: equ (msize-20) * 1024
20ccp: equ $3400+bias ;base of cpm ccp
21bdos: equ ccp+$806 ;base of bdos
22bios: equ ccp+$1600 ;base of bios
23cdisk: equ $0004 ;current disk number (0 ... 15)
24iobyte: equ $0003 ;intel iobyte
25buff: equ $0080 ;default buffer address
26retry: equ 3 ;max retries on disk i/o before error
27
28cr: equ 13
29lf: equ 10
30
db568140
L
31READ_FUNC: equ 7
32WRITE_FUNC: equ 6
33BOOT_FUNC: equ 5
34HOME_FUNC: equ 4
35
701f0287
L
36 org bios
37nsects: equ ($-ccp)/128 ;warm start sector count
38
fdcfcd44 39 jp boot
701f0287 40wboote:
fdcfcd44
L
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
701f0287
L
58signon:
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
fdcfcd44 64
701f0287
L
65boot:
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
fdcfcd44 73
701f0287
L
74wboot: ;re-load CP/M
75 ld sp,buff
db568140
L
76 ld a,1<<BOOT_FUNC
77 out (22),a
701f0287
L
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
85load1:
86 push bc
87 push de
88 push hl
89 ld c,d
db568140 90 ld b,0
701f0287
L
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
fdcfcd44 111
701f0287
L
112 ld d,0
113 inc c
114 push bc
115 push de
116 push hl
db568140 117 ld b,0
701f0287
L
118 call settrk
119 pop hl
120 pop de
121 pop bc
122 jp load1
123
124gocpm:
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
fdcfcd44
L
138
139const:
140 in a,(0)
141 ret
142
143conin:
144 in a,(0)
145 cp $ff
146 jp nz,conin
147
148 in a,(1)
149 ret
150
151conout:
fdcfcd44
L
152 ld a,c
153 out (2),a
fdcfcd44
L
154 ret
155
156list:
157 ret
158
701f0287
L
159listst:
160 ld a,0
161 ret
162
fdcfcd44
L
163punch:
164 ret
165
166reader:
167 ld a,$1F
168 ret
169
fdcfcd44 170seldsk:
db568140 171 ld hl,0 ;error return code
fdcfcd44 172 ld a,c
db568140
L
173 out (15),a
174 cp 0 ;only one disk supportet
fdcfcd44 175 jp nz,seldsk_na
db568140 176 ld hl,dph ;return disk parameter header address
fdcfcd44 177seldsk_na:
fdcfcd44
L
178 ret
179
db568140
L
180home:
181 ld a,1<<HOME_FUNC
182 out (22),a
183
184 ld bc,0 ; same as seek to track 0
fdcfcd44 185settrk:
fdcfcd44
L
186 ld a,c
187 out (16),a
db568140
L
188 ld a,b
189 out (17),a
fdcfcd44
L
190 ret
191
192setsec:
fdcfcd44
L
193 ld a,c
194 out (18),a
fdcfcd44
L
195 ret
196
197setdma:
fdcfcd44
L
198 ld a,c
199 out (20),a
200 ld a,b
201 out (21),a
fdcfcd44
L
202 ret
203
204read:
db568140 205 ld a,1<<READ_FUNC
fdcfcd44
L
206 out (22),a
207 ld a,0
208 ret
209
210write:
db568140
L
211 ld a,1<<WRITE_FUNC
212 or c ;merge write type in c
213 out (22),a
214 ld a,0
fdcfcd44
L
215 ret
216
fdcfcd44
L
217sectran:
218 ;translate sector bc using table at de, res into hl
fdcfcd44
L
219 ld h,b
220 ld l,c
db568140
L
221 ld a,d
222 or e
223 ret z
224 ex de,hl
225 add hl,bc
226 ld l,(hl)
227 ld h,0
fdcfcd44
L
228 ret
229
701f0287
L
230prmsg:
231 ld a,(hl)
232 or a
233 ret z
234 push hl
235 ld c,a
236 call conout
237 pop hl
238 inc hl
239 jp prmsg
240
fdcfcd44
L
241
242;Disk Parameter Header
243dph:
db568140
L
244 dw 0 ;XLT: No sector translation table
245 dw 0 ;000: Scratchpad
246 dw 0 ;000: Scratchpad
247 dw 0 ;000: Scratchpad
248 dw dirbuf ;DIRBUF: Address of a dirbuff scratchpad
249 dw dpb ;DPB: Address of a disk parameter block
250 dw chk ;CSV: Address of scratchpad area for changed disks
251 dw all ;ALV: Address of an allocation info sratchpad
fdcfcd44
L
252
253dpb:
db568140
L
254 dw 26 ;SPT: sectors per track
255 db 3 ;BSH: data allocation block shift factor
256 db 7 ;BLM: Data Allocation Mask
257 db 0 ;Extent mask
258 dw 242 ;DSM: Disk storage capacity
259 dw 63 ;DRM, no of directory entries
260 db 192 ;AL0
261 db 0 ;AL1
262 dw 16 ;CKS, size of dir check vector
263 dw 2 ;OFF, no of reserved tracks
264
fdcfcd44
L
265
266dirbuf:
267 ds 128
268
269chk:
270 ds 16
271
272all:
273 ds 31
701f0287 274end
db568140 275