]>
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$ | |
29ce189c L |
21 | ; |
22 | ||
23 | #ifndef CPMDSK_SUPPORT | |
24 | #define CPMDSK_SUPPORT 1 | |
25 | #endif | |
26 | ||
27 | #if CPMDSK_SUPPORT | |
28 | ||
29ce189c | 29 | |
eb85ce65 | 30 | ;----------------------------------------------- Start of Code Segment |
29ce189c | 31 | .cseg |
7300c5e4 | 32 | |
29ce189c | 33 | ; ==================================================================== |
7300c5e4 | 34 | ; Function: Does a Disk write operation |
29ce189c L |
35 | ; ==================================================================== |
36 | ; Parameters | |
37 | ; -------------------------------------------------------------------- | |
38 | ; Registers : none | |
39 | ; Variables : [r] seekdsk Number of Disk to Read | |
40 | ; [r] seeksec Sector to read | |
41 | ; [r] seektrk Track to read | |
7300c5e4 FZ |
42 | ; hostdsk = host disk #, (partition #) |
43 | ; hostlba = host block #, relative to partition start | |
29ce189c L |
44 | ; Read/Write "hostsize" bytes to/from hostbuf |
45 | ; -------------------------------------------------------------------- | |
46 | ; Description: | |
7300c5e4 FZ |
47 | ; ==================================================================== |
48 | ||
49 | cpm_hostparam: | |
dd7aea8c | 50 | lds zl,hostdsk |
29ce189c | 51 | |
7300c5e4 | 52 | .if HOSTRW_DEBUG |
dd7aea8c | 53 | mov temp,zl |
7300c5e4 | 54 | subi temp,-('A') |
dd7aea8c | 55 | lcall uartputc |
7300c5e4 FZ |
56 | printstring ": " |
57 | .endif | |
29ce189c | 58 | |
7300c5e4 | 59 | rcall dsk_getpartentry ; get partition entry |
29ce189c | 60 | |
637689de L |
61 | lds temp,hostlba ; get sector to access |
62 | lds temp2,hostlba+1 | |
7300c5e4 FZ |
63 | |
64 | .if HOSTRW_DEBUG | |
65 | printstring "lba: " | |
825ecc9d L |
66 | push r15 |
67 | push r14 | |
68 | clr r14 | |
69 | clr r15 | |
dd7aea8c | 70 | lcall print_ultoa |
825ecc9d L |
71 | pop r14 |
72 | pop r15 | |
7300c5e4 FZ |
73 | .endif |
74 | ||
637689de L |
75 | ldd xl,z+5 ; get disksize |
76 | ldd xh,z+6 | |
7300c5e4 | 77 | |
637689de L |
78 | cp temp,xl ; check given sector against disksize |
79 | cpc temp2,xh | |
7300c5e4 FZ |
80 | brcs cpm_hp1 |
81 | ||
82 | .if HOSTRW_DEBUG | |
83 | printstring ", max: " | |
825ecc9d L |
84 | push r15 |
85 | push r14 | |
7300c5e4 FZ |
86 | push temp2 |
87 | push temp | |
88 | movw temp,x | |
825ecc9d L |
89 | clr r14 |
90 | clr r15 | |
5482d75f | 91 | lcall print_ultoa |
637689de L |
92 | pop temp |
93 | pop temp2 | |
825ecc9d L |
94 | pop r14 |
95 | pop r15 | |
7300c5e4 FZ |
96 | printstring " " |
97 | .endif | |
98 | ||
637689de | 99 | clr temp |
7300c5e4 FZ |
100 | ret |
101 | ||
102 | cpm_hp1: | |
637689de L |
103 | ldd xl,z+1 ; get startsector of partition |
104 | ldd xh,z+2 | |
105 | ldd yl,z+3 | |
106 | ldd yh,z+4 | |
7300c5e4 | 107 | |
637689de L |
108 | add xl,temp ; add offset to startsector |
109 | adc xh,temp2 | |
637689de L |
110 | adc yl,_0 |
111 | adc yh,_0 | |
7300c5e4 FZ |
112 | |
113 | .if HOSTRW_DEBUG | |
114 | printstring ", abs:" | |
825ecc9d L |
115 | push r15 |
116 | push r14 | |
7300c5e4 FZ |
117 | push temp2 |
118 | push temp | |
119 | movw temp,x | |
825ecc9d | 120 | movw r14,y |
5482d75f | 121 | lcall print_ultoa |
637689de L |
122 | pop temp |
123 | pop temp2 | |
825ecc9d L |
124 | pop r14 |
125 | pop r15 | |
7300c5e4 | 126 | printstring " " |
29ce189c | 127 | .endif |
7300c5e4 | 128 | |
637689de | 129 | ori temp,255 |
7300c5e4 FZ |
130 | cpm_hpex: |
131 | ret | |
132 | ||
29ce189c | 133 | ; ==================================================================== |
7300c5e4 | 134 | ; Function: Does a Disk write operation |
29ce189c L |
135 | ; ==================================================================== |
136 | ; Parameters | |
137 | ; -------------------------------------------------------------------- | |
138 | ; Registers : none | |
139 | ; Variables : [r] seekdsk Number of Disk to Read | |
140 | ; [r] seeksec Sector to read | |
141 | ; [r] seektrk Track to read | |
142 | ; -------------------------------------------------------------------- | |
143 | ; Description: | |
7300c5e4 FZ |
144 | ; ==================================================================== |
145 | ||
146 | cpm_writehost: | |
147 | .if HOSTRW_DEBUG | |
148 | printnewline | |
149 | printstring "host write " | |
150 | .endif | |
151 | rcall cpm_hostparam | |
152 | breq cpm_rdwr_err | |
153 | ||
154 | rcall mmcWriteSect | |
29ce189c | 155 | tst temp |
7300c5e4 | 156 | brne cpm_rdwr_err |
29ce189c | 157 | |
7300c5e4 | 158 | rjmp cpm_rdwr_ok |
29ce189c | 159 | |
7300c5e4 | 160 | |
29ce189c | 161 | ; ==================================================================== |
7300c5e4 | 162 | ; Function: Does a Disk read operation |
29ce189c L |
163 | ; ==================================================================== |
164 | ; Parameters | |
165 | ; -------------------------------------------------------------------- | |
166 | ; Registers : none | |
167 | ; Variables : [r] seekdsk Number of Disk to Read | |
168 | ; [r] seeksec Sector to read | |
169 | ; [r] seektrk Track to read | |
170 | ; -------------------------------------------------------------------- | |
171 | ; Description: | |
7300c5e4 FZ |
172 | ; ==================================================================== |
173 | cpm_readhost: | |
174 | .if HOSTRW_DEBUG | |
175 | printnewline | |
176 | printstring "host read " | |
29ce189c | 177 | .endif |
7300c5e4 FZ |
178 | |
179 | rcall cpm_hostparam | |
180 | breq cpm_rdwr_err | |
181 | ||
182 | rcall mmcReadSect | |
29ce189c | 183 | tst temp |
7300c5e4 FZ |
184 | brne cpm_rdwr_err |
185 | ||
186 | cpm_rdwr_ok: | |
29ce189c | 187 | sts erflag,_0 |
7300c5e4 FZ |
188 | ret |
189 | ||
190 | cpm_rdwr_err: | |
29ce189c L |
191 | sts erflag,_255 |
192 | ret | |
193 | ||
194 | ||
195 | ; ==================================================================== | |
7300c5e4 | 196 | ; Function: Add's a CP/M Partition to the Partition table |
29ce189c L |
197 | ; ==================================================================== |
198 | ; Parameters | |
199 | ; -------------------------------------------------------------------- | |
200 | ; Registers : none | |
201 | ; Variables : [r] seekdsk Number of Disk to Read | |
202 | ; [r] seeksec Sector to read | |
203 | ; [r] seektrk Track to read | |
204 | ; -------------------------------------------------------------------- | |
205 | ; Description: | |
7300c5e4 FZ |
206 | ; ==================================================================== |
207 | cpm_add_partition: | |
29ce189c | 208 | |
637689de L |
209 | ldi temp,dskType_CPM |
210 | std y+0,temp | |
7300c5e4 FZ |
211 | |
212 | ldd temp,z+PART_START | |
637689de | 213 | std y+1,temp |
7300c5e4 | 214 | ldd temp,z+PART_START+1 |
637689de | 215 | std y+2,temp |
7300c5e4 | 216 | ldd temp,z+PART_START+2 |
637689de | 217 | std y+3,temp |
7300c5e4 | 218 | ldd temp,z+PART_START+3 |
637689de | 219 | std y+4,temp |
7300c5e4 | 220 | |
637689de L |
221 | ldd temp,z+PART_SIZE+2 |
222 | ldd temp2,z+PART_SIZE+3 | |
223 | or temp,temp2 ;part size larger than 65535 sectors? | |
224 | brne cpm_add_prune | |
225 | ||
7300c5e4 | 226 | ldd temp,z+PART_SIZE |
637689de | 227 | std y+5,temp |
7300c5e4 | 228 | ldd temp,z+PART_SIZE+1 |
637689de L |
229 | std y+6,temp |
230 | rjmp cpm_add_e | |
231 | ||
232 | cpm_add_prune: | |
233 | std y+5,_255 | |
234 | std y+6,_255 | |
235 | ||
236 | cpm_add_e: | |
29ce189c L |
237 | ret |
238 | ||
239 | #endif | |
5482d75f L |
240 | |
241 | ; vim:set ts=8 noet nowrap | |
242 |