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