]> cloudbase.mooo.com Git - avrcpm.git/blob - avrcpm/avr/dsk_cpm.asm
git-svn-id: svn://cu.loc/avr-cpm/trunk@129 57430480-672e-4586-8877-bcf8adbbf3b7
[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 ; Partition table offsets:
41 tmp_tbl:
42 .byte PARTENTRY_SIZE*MAXDISKS
43
44 ; ---------------------------------------------- Start of Code Segment
45 .cseg
46
47 ; ====================================================================
48 ; Function: Does a Disk write operation
49 ; ====================================================================
50 ; Parameters
51 ; --------------------------------------------------------------------
52 ; Registers : none
53 ; Variables : [r] seekdsk Number of Disk to Read
54 ; [r] seeksec Sector to read
55 ; [r] seektrk Track to read
56 ; hostdsk = host disk #, (partition #)
57 ; hostlba = host block #, relative to partition start
58 ; Read/Write "hostsize" bytes to/from hostbuf
59 ; --------------------------------------------------------------------
60 ; Description:
61 ; ====================================================================
62
63 cpm_hostparam:
64 lds xl,hostdsk
65
66 .if HOSTRW_DEBUG
67 mov temp,xl
68 subi temp,-('A')
69 rcall uartputc
70 printstring ": "
71 .endif
72
73 rcall dsk_getpartentry ; get partition entry
74
75
76 cpm_hostlend:
77 lds temp,hostlba ; get sector to access
78 lds temp2,hostlba+1
79 lds temp3,hostlba+2
80
81 .if HOSTRW_DEBUG
82 printstring "lba: "
83 clr temp4
84 rcall print_ultoa
85 .endif
86
87 ldd xl,z+5 ; get disksize
88 ldd xh,z+6
89 ldd yl,z+7
90
91 cp temp,xl ; check given sector against disksize
92 cpc temp2,xh
93 cpc temp3,yl
94 brcs cpm_hp1
95
96 .if HOSTRW_DEBUG
97 printstring ", max: "
98 push temp4
99 push temp3
100 push temp2
101 push temp
102 movw temp,x
103 mov temp3,yl
104 clr temp4
105 rcall print_ultoa
106 pop temp
107 pop temp2
108 pop temp3
109 pop temp4
110 printstring " "
111 .endif
112
113 clr temp
114 ret
115
116 cpm_hp1:
117 ldd xl,z+1 ; get startsector of partition
118 ldd xh,z+2
119 ldd yl,z+3
120 ldd yh,z+4
121
122 add xl,temp ; add offset to startsector
123 adc xh,temp2
124 adc yl,temp3
125 adc yh,_0
126
127 .if HOSTRW_DEBUG
128 printstring ", abs:"
129 push temp4
130 push temp3
131 push temp2
132 push temp
133 movw temp,x
134 movw temp3,y
135 rcall print_ultoa
136 pop temp
137 pop temp2
138 pop temp3
139 pop temp4
140 printstring " "
141 .endif
142
143 ori temp,255
144 cpm_hpex:
145 ret
146
147 ; ====================================================================
148 ; Function: Does a Disk write operation
149 ; ====================================================================
150 ; Parameters
151 ; --------------------------------------------------------------------
152 ; Registers : none
153 ; Variables : [r] seekdsk Number of Disk to Read
154 ; [r] seeksec Sector to read
155 ; [r] seektrk Track to read
156 ; --------------------------------------------------------------------
157 ; Description:
158 ; ====================================================================
159
160 cpm_writehost:
161 .if HOSTRW_DEBUG
162 printnewline
163 printstring "host write "
164 .endif
165 rcall cpm_hostparam
166 breq cpm_rdwr_err
167
168 rcall mmcWriteSect
169 tst temp
170 breq cpm_rdwr_ok
171
172 rcall mgr_init_partitions
173 cbr temp,0x80
174 breq cpm_rdwr_err
175
176 rcall cpm_hostparam
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 rcall mgr_init_partitions
209 cbr temp,0x80
210 breq cpm_rdwr_err
211
212 rcall cpm_hostparam
213 breq cpm_rdwr_err
214 rcall mmcReadSect
215 tst temp
216 brne cpm_rdwr_err
217
218 cpm_rdwr_ok:
219 sts erflag,_0
220 ret
221
222 cpm_rdwr_err:
223 sts erflag,_255
224 ret
225
226
227 ; ====================================================================
228 ; Function: Add's a CP/M Partition to the Partition table
229 ; ====================================================================
230 ; Parameters
231 ; --------------------------------------------------------------------
232 ; Registers : none
233 ; Variables : [r] seekdsk Number of Disk to Read
234 ; [r] seeksec Sector to read
235 ; [r] seektrk Track to read
236 ; --------------------------------------------------------------------
237 ; Description:
238 ; ====================================================================
239 cpm_add_partition:
240
241 ldi temp,dskType_CPM
242 st y+,temp
243
244 ldd temp,z+PART_START
245 st y+,temp
246 ldd temp,z+PART_START+1
247 st y+,temp
248 ldd temp,z+PART_START+2
249 st y+,temp
250 ldd temp,z+PART_START+3
251 st y+,temp
252
253 ldd temp,z+PART_SIZE
254 st y+,temp
255 ldd temp,z+PART_SIZE+1
256 st y+,temp
257 ldd temp,z+PART_SIZE+2
258 st y+,temp
259 ldd temp,z+PART_SIZE+3
260 st y+,temp
261 ret
262
263 #endif