]>
Commit | Line | Data |
---|---|---|
7300c5e4 FZ |
1 | ; Various functions for the Interaction with the CPM Filesystem |
2 | ; | |
3 | ; Copyright (C) 2010 Frank Zoll | |
4 | ; | |
5 | ; This file is part of avrcpm. | |
6 | ; | |
7 | ; avrcpm is free software: you can redistribute it and/or modify it | |
8 | ; under the terms of the GNU General Public License as published by | |
9 | ; the Free Software Foundation, either version 3 of the License, or | |
10 | ; (at your option) any later version. | |
11 | ; | |
12 | ; avrcpm is distributed in the hope that it will be useful, | |
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ; GNU General Public License for more details. | |
16 | ; | |
17 | ; You should have received a copy of the GNU General Public License | |
18 | ; along with avrcpm. If not, see <http://www.gnu.org/licenses/>. | |
19 | ; | |
20 | ; $Id$ | |
21 | ;\r | |
22 | \r | |
23 | #ifndef CPMDSK_SUPPORT\r | |
24 | #define CPMDSK_SUPPORT 1 \r | |
25 | #endif\r | |
26 | \r | |
27 | #if CPMDSK_SUPPORT\r | |
28 | \r | |
eb85ce65 | 29 | ;------------------------------------------ Defines for CPM Structures |
7300c5e4 FZ |
30 | #define PART_TYPE 4 |
31 | #define PART_START 8 | |
32 | #define PART_SIZE 12\r | |
33 | \r | |
34 | #define PARTID_CPM 0x52 /* Partition table id */ | |
35 | /* http://www.win.tue.nl/~aeb/partitions/partition_types-1.html */\r | |
36 | ;----------------------------------------------- Start of Data Segment | |
37 | ||
38 | .dseg\r | |
39 | \r | |
eb85ce65 | 40 | ;----------------------------------------------- Start of Code Segment |
7300c5e4 FZ |
41 | .cseg\r |
42 | ||
43 | ; ====================================================================\r | |
44 | ; Function: Does a Disk write operation | |
45 | ; ====================================================================\r | |
46 | ; Parameters\r | |
47 | ; --------------------------------------------------------------------\r | |
48 | ; Registers : none\r | |
49 | ; Variables : [r] seekdsk Number of Disk to Read\r | |
50 | ; [r] seeksec Sector to read\r | |
51 | ; [r] seektrk Track to read\r | |
52 | ; hostdsk = host disk #, (partition #) | |
53 | ; hostlba = host block #, relative to partition start | |
54 | ; Read/Write "hostsize" bytes to/from hostbuf\r | |
55 | ; --------------------------------------------------------------------\r | |
56 | ; Description:\r | |
57 | ; ==================================================================== | |
58 | ||
59 | cpm_hostparam: | |
60 | lds xl,hostdsk | |
61 | \r | |
62 | .if HOSTRW_DEBUG | |
63 | mov temp,xl | |
64 | subi temp,-('A') | |
65 | rcall uartputc | |
66 | printstring ": " | |
67 | .endif | |
68 | \r | |
69 | rcall dsk_getpartentry ; get partition entry | |
7300c5e4 | 70 | \r |
7300c5e4 FZ |
71 | lds temp,hostlba ; get sector to access |
72 | lds temp2,hostlba+1 | |
73 | lds temp3,hostlba+2 | |
74 | ||
75 | .if HOSTRW_DEBUG | |
76 | printstring "lba: " | |
77 | clr temp4 | |
78 | rcall print_ultoa | |
79 | .endif | |
80 | ||
81 | ldd xl,z+5 ; get disksize | |
82 | ldd xh,z+6 | |
83 | ldd yl,z+7 | |
84 | ||
85 | cp temp,xl ; check given sector against disksize | |
86 | cpc temp2,xh | |
87 | cpc temp3,yl | |
88 | brcs cpm_hp1 | |
89 | ||
90 | .if HOSTRW_DEBUG | |
91 | printstring ", max: " | |
92 | push temp4 | |
93 | push temp3 | |
94 | push temp2 | |
95 | push temp | |
96 | movw temp,x | |
97 | mov temp3,yl | |
98 | clr temp4 | |
99 | rcall print_ultoa | |
100 | pop temp | |
101 | pop temp2 | |
102 | pop temp3 | |
103 | pop temp4 | |
104 | printstring " " | |
105 | .endif | |
106 | ||
107 | clr temp | |
108 | ret | |
109 | ||
110 | cpm_hp1: | |
111 | ldd xl,z+1 ; get startsector of partition | |
112 | ldd xh,z+2 | |
113 | ldd yl,z+3 | |
114 | ldd yh,z+4 | |
115 | ||
116 | add xl,temp ; add offset to startsector | |
117 | adc xh,temp2 | |
118 | adc yl,temp3 | |
119 | adc yh,_0\r | |
120 | ||
121 | .if HOSTRW_DEBUG | |
122 | printstring ", abs:" | |
123 | push temp4 | |
124 | push temp3 | |
125 | push temp2 | |
126 | push temp | |
127 | movw temp,x | |
128 | movw temp3,y | |
129 | rcall print_ultoa | |
130 | pop temp | |
131 | pop temp2 | |
132 | pop temp3 | |
133 | pop temp4 | |
134 | printstring " " | |
135 | .endif\r | |
136 | ||
137 | ori temp,255 | |
138 | cpm_hpex: | |
139 | ret | |
140 | ||
141 | ; ====================================================================\r | |
142 | ; Function: Does a Disk write operation | |
143 | ; ====================================================================\r | |
144 | ; Parameters\r | |
145 | ; --------------------------------------------------------------------\r | |
146 | ; Registers : none\r | |
147 | ; Variables : [r] seekdsk Number of Disk to Read\r | |
148 | ; [r] seeksec Sector to read\r | |
149 | ; [r] seektrk Track to read\r | |
150 | ; --------------------------------------------------------------------\r | |
151 | ; Description:\r | |
152 | ; ==================================================================== | |
153 | ||
154 | cpm_writehost: | |
155 | .if HOSTRW_DEBUG | |
156 | printnewline | |
157 | printstring "host write " | |
158 | .endif | |
159 | rcall cpm_hostparam | |
160 | breq cpm_rdwr_err | |
161 | ||
162 | rcall mmcWriteSect | |
163 | tst temp | |
164 | breq cpm_rdwr_ok | |
165 | ||
eb85ce65 L |
166 | rjmp cpm_rdwr_err ; skip disk change detection code |
167 | ||
168 | ; After a second thought, the following code doesn't make sense, because | |
169 | ; disk change (change of one or more disk images) can not reliably detected. | |
170 | ; At least with the existing code. | |
171 | ||
172 | rcall mgr_init_partitions ;reinit card | |
173 | cbr temp,0x80 ;this should have been a test of bit 7. | |
7300c5e4 FZ |
174 | breq cpm_rdwr_err |
175 | ||
eb85ce65 | 176 | rcall cpm_hostparam ;if same card, try again. |
7300c5e4 FZ |
177 | breq cpm_rdwr_err |
178 | rcall mmcWriteSect | |
179 | tst temp | |
180 | brne cpm_rdwr_err | |
181 | rjmp cpm_rdwr_ok | |
182 | ||
183 | ; ====================================================================\r | |
184 | ; Function: Does a Disk read operation | |
185 | ; ====================================================================\r | |
186 | ; Parameters\r | |
187 | ; --------------------------------------------------------------------\r | |
188 | ; Registers : none\r | |
189 | ; Variables : [r] seekdsk Number of Disk to Read\r | |
190 | ; [r] seeksec Sector to read\r | |
191 | ; [r] seektrk Track to read\r | |
192 | ; --------------------------------------------------------------------\r | |
193 | ; Description:\r | |
194 | ; ==================================================================== | |
195 | cpm_readhost: | |
196 | .if HOSTRW_DEBUG | |
197 | printnewline | |
198 | printstring "host read " | |
199 | .endif\r | |
200 | ||
201 | rcall cpm_hostparam | |
202 | breq cpm_rdwr_err | |
203 | ||
204 | rcall mmcReadSect | |
205 | tst temp | |
206 | breq cpm_rdwr_ok | |
207 | ||
eb85ce65 L |
208 | rjmp cpm_rdwr_err ; skip disk change detection code |
209 | ||
210 | rcall mgr_init_partitions ;reinit card | |
7300c5e4 FZ |
211 | cbr temp,0x80 |
212 | breq cpm_rdwr_err | |
213 | ||
eb85ce65 | 214 | rcall cpm_hostparam ;if same card, try again. |
7300c5e4 FZ |
215 | breq cpm_rdwr_err |
216 | rcall mmcReadSect | |
217 | tst temp | |
218 | brne cpm_rdwr_err | |
219 | ||
220 | cpm_rdwr_ok: | |
221 | sts erflag,_0 | |
222 | ret | |
223 | ||
224 | cpm_rdwr_err: | |
225 | sts erflag,_255 | |
226 | ret\r | |
227 | \r | |
228 | \r | |
229 | ; ====================================================================\r | |
230 | ; Function: Add's a CP/M Partition to the Partition table | |
231 | ; ====================================================================\r | |
232 | ; Parameters\r | |
233 | ; --------------------------------------------------------------------\r | |
234 | ; Registers : none\r | |
235 | ; Variables : [r] seekdsk Number of Disk to Read\r | |
236 | ; [r] seeksec Sector to read\r | |
237 | ; [r] seektrk Track to read\r | |
238 | ; --------------------------------------------------------------------\r | |
239 | ; Description:\r | |
240 | ; ==================================================================== | |
241 | cpm_add_partition: | |
242 | \r | |
243 | ldi temp,dskType_CPM\r | |
244 | st y+,temp\r | |
245 | ||
246 | ldd temp,z+PART_START | |
247 | st y+,temp | |
248 | ldd temp,z+PART_START+1 | |
249 | st y+,temp | |
250 | ldd temp,z+PART_START+2 | |
251 | st y+,temp | |
252 | ldd temp,z+PART_START+3 | |
253 | st y+,temp | |
254 | ||
255 | ldd temp,z+PART_SIZE | |
256 | st y+,temp | |
257 | ldd temp,z+PART_SIZE+1 | |
258 | st y+,temp | |
259 | ldd temp,z+PART_SIZE+2 | |
260 | st y+,temp | |
261 | ldd temp,z+PART_SIZE+3 | |
262 | st y+,temp | |
263 | ret\r | |
264 | \r | |
265 | #endif\r |