]>
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 | ||
eb85ce65 | 29 | ;------------------------------------------ Defines for CPM Structures |
7300c5e4 FZ |
30 | #define PART_TYPE 4 |
31 | #define PART_START 8 | |
29ce189c L |
32 | #define PART_SIZE 12 |
33 | ||
7300c5e4 | 34 | #define PARTID_CPM 0x52 /* Partition table id */ |
29ce189c | 35 | /* http://www.win.tue.nl/~aeb/partitions/partition_types-1.html */ |
7300c5e4 FZ |
36 | ;----------------------------------------------- Start of Data Segment |
37 | ||
29ce189c L |
38 | .dseg |
39 | ||
eb85ce65 | 40 | ;----------------------------------------------- Start of Code Segment |
29ce189c | 41 | .cseg |
7300c5e4 | 42 | |
29ce189c | 43 | ; ==================================================================== |
7300c5e4 | 44 | ; Function: Does a Disk write operation |
29ce189c L |
45 | ; ==================================================================== |
46 | ; Parameters | |
47 | ; -------------------------------------------------------------------- | |
48 | ; Registers : none | |
49 | ; Variables : [r] seekdsk Number of Disk to Read | |
50 | ; [r] seeksec Sector to read | |
51 | ; [r] seektrk Track to read | |
7300c5e4 FZ |
52 | ; hostdsk = host disk #, (partition #) |
53 | ; hostlba = host block #, relative to partition start | |
29ce189c L |
54 | ; Read/Write "hostsize" bytes to/from hostbuf |
55 | ; -------------------------------------------------------------------- | |
56 | ; Description: | |
7300c5e4 FZ |
57 | ; ==================================================================== |
58 | ||
59 | cpm_hostparam: | |
60 | lds xl,hostdsk | |
29ce189c | 61 | |
7300c5e4 FZ |
62 | .if HOSTRW_DEBUG |
63 | mov temp,xl | |
64 | subi temp,-('A') | |
65 | rcall uartputc | |
66 | printstring ": " | |
67 | .endif | |
29ce189c | 68 | |
7300c5e4 | 69 | rcall dsk_getpartentry ; get partition entry |
29ce189c | 70 | |
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 | |
29ce189c | 119 | adc yh,_0 |
7300c5e4 FZ |
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 " " | |
29ce189c | 135 | .endif |
7300c5e4 FZ |
136 | |
137 | ori temp,255 | |
138 | cpm_hpex: | |
139 | ret | |
140 | ||
29ce189c | 141 | ; ==================================================================== |
7300c5e4 | 142 | ; Function: Does a Disk write operation |
29ce189c L |
143 | ; ==================================================================== |
144 | ; Parameters | |
145 | ; -------------------------------------------------------------------- | |
146 | ; Registers : none | |
147 | ; Variables : [r] seekdsk Number of Disk to Read | |
148 | ; [r] seeksec Sector to read | |
149 | ; [r] seektrk Track to read | |
150 | ; -------------------------------------------------------------------- | |
151 | ; Description: | |
7300c5e4 FZ |
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 | |
29ce189c | 163 | tst temp |
7300c5e4 | 164 | brne cpm_rdwr_err |
29ce189c | 165 | |
7300c5e4 | 166 | rjmp cpm_rdwr_ok |
29ce189c | 167 | |
7300c5e4 | 168 | |
29ce189c | 169 | ; ==================================================================== |
7300c5e4 | 170 | ; Function: Does a Disk read operation |
29ce189c L |
171 | ; ==================================================================== |
172 | ; Parameters | |
173 | ; -------------------------------------------------------------------- | |
174 | ; Registers : none | |
175 | ; Variables : [r] seekdsk Number of Disk to Read | |
176 | ; [r] seeksec Sector to read | |
177 | ; [r] seektrk Track to read | |
178 | ; -------------------------------------------------------------------- | |
179 | ; Description: | |
7300c5e4 FZ |
180 | ; ==================================================================== |
181 | cpm_readhost: | |
182 | .if HOSTRW_DEBUG | |
183 | printnewline | |
184 | printstring "host read " | |
29ce189c | 185 | .endif |
7300c5e4 FZ |
186 | |
187 | rcall cpm_hostparam | |
188 | breq cpm_rdwr_err | |
189 | ||
190 | rcall mmcReadSect | |
29ce189c | 191 | tst temp |
7300c5e4 FZ |
192 | brne cpm_rdwr_err |
193 | ||
194 | cpm_rdwr_ok: | |
29ce189c | 195 | sts erflag,_0 |
7300c5e4 FZ |
196 | ret |
197 | ||
198 | cpm_rdwr_err: | |
29ce189c L |
199 | sts erflag,_255 |
200 | ret | |
201 | ||
202 | ||
203 | ; ==================================================================== | |
7300c5e4 | 204 | ; Function: Add's a CP/M Partition to the Partition table |
29ce189c L |
205 | ; ==================================================================== |
206 | ; Parameters | |
207 | ; -------------------------------------------------------------------- | |
208 | ; Registers : none | |
209 | ; Variables : [r] seekdsk Number of Disk to Read | |
210 | ; [r] seeksec Sector to read | |
211 | ; [r] seektrk Track to read | |
212 | ; -------------------------------------------------------------------- | |
213 | ; Description: | |
7300c5e4 FZ |
214 | ; ==================================================================== |
215 | cpm_add_partition: | |
29ce189c L |
216 | |
217 | ldi temp,dskType_CPM | |
218 | st y+,temp | |
7300c5e4 FZ |
219 | |
220 | ldd temp,z+PART_START | |
221 | st y+,temp | |
222 | ldd temp,z+PART_START+1 | |
223 | st y+,temp | |
224 | ldd temp,z+PART_START+2 | |
225 | st y+,temp | |
226 | ldd temp,z+PART_START+3 | |
227 | st y+,temp | |
228 | ||
229 | ldd temp,z+PART_SIZE | |
230 | st y+,temp | |
231 | ldd temp,z+PART_SIZE+1 | |
232 | st y+,temp | |
233 | ldd temp,z+PART_SIZE+2 | |
234 | st y+,temp | |
235 | ldd temp,z+PART_SIZE+3 | |
236 | st y+,temp | |
29ce189c L |
237 | ret |
238 | ||
239 | #endif |