]> cloudbase.mooo.com Git - avrcpm.git/blob - avrcpm/avr/dsk_cpm.asm
6835c9395bbd0fb10190cfad24d39ccaca3b3b44
[avrcpm.git] / avrcpm / avr / dsk_cpm.asm
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 ;
22
23 #ifndef CPMDSK_SUPPORT
24 #define CPMDSK_SUPPORT 1
25 #endif
26
27 #if CPMDSK_SUPPORT
28
29 ;------------------------------------------ Defines for CPM Structures
30 #define PART_TYPE 4
31 #define PART_START 8
32 #define PART_SIZE 12
33
34 #define PARTID_CPM 0x52 /* Partition table id */
35 /* http://www.win.tue.nl/~aeb/partitions/partition_types-1.html */
36 ;----------------------------------------------- Start of Data Segment
37
38 .dseg
39
40 ;----------------------------------------------- Start of Code Segment
41 .cseg
42
43 ; ====================================================================
44 ; Function: Does a Disk write operation
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
52 ; hostdsk = host disk #, (partition #)
53 ; hostlba = host block #, relative to partition start
54 ; Read/Write "hostsize" bytes to/from hostbuf
55 ; --------------------------------------------------------------------
56 ; Description:
57 ; ====================================================================
58
59 cpm_hostparam:
60 lds xl,hostdsk
61
62 .if HOSTRW_DEBUG
63 mov temp,xl
64 subi temp,-('A')
65 rcall uartputc
66 printstring ": "
67 .endif
68
69 rcall dsk_getpartentry ; get partition entry
70
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
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
136
137 ori temp,255
138 cpm_hpex:
139 ret
140
141 ; ====================================================================
142 ; Function: Does a Disk write operation
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:
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
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.
174 breq cpm_rdwr_err
175
176 rcall cpm_hostparam ;if same card, try again.
177 breq cpm_rdwr_err
178 rcall mmcWriteSect
179 tst temp
180 brne cpm_rdwr_err
181 rjmp cpm_rdwr_ok
182
183 ; ====================================================================
184 ; Function: Does a Disk read operation
185 ; ====================================================================
186 ; Parameters
187 ; --------------------------------------------------------------------
188 ; Registers : none
189 ; Variables : [r] seekdsk Number of Disk to Read
190 ; [r] seeksec Sector to read
191 ; [r] seektrk Track to read
192 ; --------------------------------------------------------------------
193 ; Description:
194 ; ====================================================================
195 cpm_readhost:
196 .if HOSTRW_DEBUG
197 printnewline
198 printstring "host read "
199 .endif
200
201 rcall cpm_hostparam
202 breq cpm_rdwr_err
203
204 rcall mmcReadSect
205 tst temp
206 breq cpm_rdwr_ok
207
208 rjmp cpm_rdwr_err ; skip disk change detection code
209
210 rcall mgr_init_partitions ;reinit card
211 cbr temp,0x80
212 breq cpm_rdwr_err
213
214 rcall cpm_hostparam ;if same card, try again.
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
227
228
229 ; ====================================================================
230 ; Function: Add's a CP/M Partition to the Partition table
231 ; ====================================================================
232 ; Parameters
233 ; --------------------------------------------------------------------
234 ; Registers : none
235 ; Variables : [r] seekdsk Number of Disk to Read
236 ; [r] seeksec Sector to read
237 ; [r] seektrk Track to read
238 ; --------------------------------------------------------------------
239 ; Description:
240 ; ====================================================================
241 cpm_add_partition:
242
243 ldi temp,dskType_CPM
244 st y+,temp
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
264
265 #endif