]> cloudbase.mooo.com Git - avrcpm.git/blob - avrcpm/avr/dsk_cpm.asm
* Start of dynamic disk size code.
[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 brne cpm_rdwr_err
165
166 rjmp cpm_rdwr_ok
167
168
169 ; ====================================================================
170 ; Function: Does a Disk read operation
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:
180 ; ====================================================================
181 cpm_readhost:
182 .if HOSTRW_DEBUG
183 printnewline
184 printstring "host read "
185 .endif
186
187 rcall cpm_hostparam
188 breq cpm_rdwr_err
189
190 rcall mmcReadSect
191 tst temp
192 brne cpm_rdwr_err
193
194 cpm_rdwr_ok:
195 sts erflag,_0
196 ret
197
198 cpm_rdwr_err:
199 sts erflag,_255
200 ret
201
202
203 ; ====================================================================
204 ; Function: Add's a CP/M Partition to the Partition table
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:
214 ; ====================================================================
215 cpm_add_partition:
216
217 ldi temp,dskType_CPM
218 st y+,temp
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
237 ret
238
239 #endif