]> cloudbase.mooo.com Git - avrcpm.git/blob - avr/dsk_cpm.asm
* Z80/8080 registers BC, DE, HL moved from RAM to AVR CPU registers. 'temp4' removed.
[avrcpm.git] / 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
30 ;----------------------------------------------- Start of Code Segment
31 .cseg
32
33 ; ====================================================================
34 ; Function: Does a Disk write operation
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
42 ; hostdsk = host disk #, (partition #)
43 ; hostlba = host block #, relative to partition start
44 ; Read/Write "hostsize" bytes to/from hostbuf
45 ; --------------------------------------------------------------------
46 ; Description:
47 ; ====================================================================
48
49 cpm_hostparam:
50 lds zl,hostdsk
51
52 .if HOSTRW_DEBUG
53 mov temp,zl
54 subi temp,-('A')
55 lcall uartputc
56 printstring ": "
57 .endif
58
59 rcall dsk_getpartentry ; get partition entry
60
61 lds temp,hostlba ; get sector to access
62 lds temp2,hostlba+1
63
64 .if HOSTRW_DEBUG
65 printstring "lba: "
66 push r15
67 push r14
68 clr r14
69 clr r15
70 lcall print_ultoa
71 pop r14
72 pop r15
73 .endif
74
75 ldd xl,z+5 ; get disksize
76 ldd xh,z+6
77
78 cp temp,xl ; check given sector against disksize
79 cpc temp2,xh
80 brcs cpm_hp1
81
82 .if HOSTRW_DEBUG
83 printstring ", max: "
84 push r15
85 push r14
86 push temp2
87 push temp
88 movw temp,x
89 clr r14
90 clr r15
91 lcall print_ultoa
92 pop temp
93 pop temp2
94 pop r14
95 pop r15
96 printstring " "
97 .endif
98
99 clr temp
100 ret
101
102 cpm_hp1:
103 ldd xl,z+1 ; get startsector of partition
104 ldd xh,z+2
105 ldd yl,z+3
106 ldd yh,z+4
107
108 add xl,temp ; add offset to startsector
109 adc xh,temp2
110 adc yl,_0
111 adc yh,_0
112
113 .if HOSTRW_DEBUG
114 printstring ", abs:"
115 push r15
116 push r14
117 push temp2
118 push temp
119 movw temp,x
120 movw r14,y
121 lcall print_ultoa
122 pop temp
123 pop temp2
124 pop r14
125 pop r15
126 printstring " "
127 .endif
128
129 ori temp,255
130 cpm_hpex:
131 ret
132
133 ; ====================================================================
134 ; Function: Does a Disk write operation
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:
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
155 tst temp
156 brne cpm_rdwr_err
157
158 rjmp cpm_rdwr_ok
159
160
161 ; ====================================================================
162 ; Function: Does a Disk read operation
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:
172 ; ====================================================================
173 cpm_readhost:
174 .if HOSTRW_DEBUG
175 printnewline
176 printstring "host read "
177 .endif
178
179 rcall cpm_hostparam
180 breq cpm_rdwr_err
181
182 rcall mmcReadSect
183 tst temp
184 brne cpm_rdwr_err
185
186 cpm_rdwr_ok:
187 sts erflag,_0
188 ret
189
190 cpm_rdwr_err:
191 sts erflag,_255
192 ret
193
194
195 ; ====================================================================
196 ; Function: Add's a CP/M Partition to the Partition table
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:
206 ; ====================================================================
207 cpm_add_partition:
208
209 ldi temp,dskType_CPM
210 std y+0,temp
211
212 ldd temp,z+PART_START
213 std y+1,temp
214 ldd temp,z+PART_START+1
215 std y+2,temp
216 ldd temp,z+PART_START+2
217 std y+3,temp
218 ldd temp,z+PART_START+3
219 std y+4,temp
220
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
226 ldd temp,z+PART_SIZE
227 std y+5,temp
228 ldd temp,z+PART_SIZE+1
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:
237 ret
238
239 #endif
240
241 ; vim:set ts=8 noet nowrap
242