]> cloudbase.mooo.com Git - avrcpm.git/blame - avr/dsk_cpm.asm
* avr/dsk_fsys.asm
[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 56.endif
29ce189c 57
7300c5e4 58 rcall dsk_getpartentry ; get partition entry
29ce189c 59
637689de
L
60 lds temp,hostlba ; get sector to access
61 lds temp2,hostlba+1
7300c5e4
FZ
62
63.if HOSTRW_DEBUG
2ccaac16 64 printstring ": lba "
825ecc9d
L
65 push r15
66 push r14
67 clr r14
68 clr r15
dd7aea8c 69 lcall print_ultoa
825ecc9d
L
70 pop r14
71 pop r15
7300c5e4
FZ
72.endif
73
637689de
L
74 ldd xl,z+5 ; get disksize
75 ldd xh,z+6
7300c5e4 76
637689de
L
77 cp temp,xl ; check given sector against disksize
78 cpc temp2,xh
7300c5e4
FZ
79 brcs cpm_hp1
80
81.if HOSTRW_DEBUG
82 printstring ", max: "
825ecc9d
L
83 push r15
84 push r14
7300c5e4
FZ
85 push temp2
86 push temp
87 movw temp,x
825ecc9d
L
88 clr r14
89 clr r15
5482d75f 90 lcall print_ultoa
637689de
L
91 pop temp
92 pop temp2
825ecc9d
L
93 pop r14
94 pop r15
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
637689de
L
109 adc yl,_0
110 adc yh,_0
7300c5e4
FZ
111
112.if HOSTRW_DEBUG
2ccaac16 113 printstring ", abs "
825ecc9d
L
114 push r15
115 push r14
7300c5e4
FZ
116 push temp2
117 push temp
118 movw temp,x
825ecc9d 119 movw r14,y
5482d75f 120 lcall print_ultoa
637689de
L
121 pop temp
122 pop temp2
825ecc9d
L
123 pop r14
124 pop r15
29ce189c 125.endif
7300c5e4 126
637689de 127 ori temp,255
7300c5e4
FZ
128cpm_hpex:
129 ret
130
29ce189c 131; ====================================================================
7300c5e4 132; Function: Does a Disk write operation
29ce189c
L
133; ====================================================================
134; Parameters
135; --------------------------------------------------------------------
136; Registers : none
137; Variables : [r] seekdsk Number of Disk to Read
138; [r] seeksec Sector to read
139; [r] seektrk Track to read
140; --------------------------------------------------------------------
141; Description:
7300c5e4
FZ
142; ====================================================================
143
144cpm_writehost:
145.if HOSTRW_DEBUG
2ccaac16 146 printstring ", hst WR "
7300c5e4
FZ
147.endif
148 rcall cpm_hostparam
149 breq cpm_rdwr_err
150
151 rcall mmcWriteSect
29ce189c 152 tst temp
7300c5e4 153 brne cpm_rdwr_err
29ce189c 154
7300c5e4 155 rjmp cpm_rdwr_ok
29ce189c 156
7300c5e4 157
29ce189c 158; ====================================================================
7300c5e4 159; Function: Does a Disk read operation
29ce189c
L
160; ====================================================================
161; Parameters
162; --------------------------------------------------------------------
163; Registers : none
164; Variables : [r] seekdsk Number of Disk to Read
165; [r] seeksec Sector to read
166; [r] seektrk Track to read
167; --------------------------------------------------------------------
168; Description:
7300c5e4 169; ====================================================================
2ccaac16 170
7300c5e4
FZ
171cpm_readhost:
172.if HOSTRW_DEBUG
2ccaac16 173 printstring ", hst RD "
29ce189c 174.endif
7300c5e4
FZ
175 rcall cpm_hostparam
176 breq cpm_rdwr_err
177
178 rcall mmcReadSect
29ce189c 179 tst temp
7300c5e4
FZ
180 brne cpm_rdwr_err
181
182cpm_rdwr_ok:
29ce189c 183 sts erflag,_0
7300c5e4
FZ
184 ret
185
186cpm_rdwr_err:
29ce189c
L
187 sts erflag,_255
188 ret
189
190
191; ====================================================================
7300c5e4 192; Function: Add's a CP/M Partition to the Partition table
29ce189c
L
193; ====================================================================
194; Parameters
195; --------------------------------------------------------------------
196; Registers : none
197; Variables : [r] seekdsk Number of Disk to Read
198; [r] seeksec Sector to read
199; [r] seektrk Track to read
200; --------------------------------------------------------------------
201; Description:
7300c5e4
FZ
202; ====================================================================
203cpm_add_partition:
29ce189c 204
637689de
L
205 ldi temp,dskType_CPM
206 std y+0,temp
7300c5e4
FZ
207
208 ldd temp,z+PART_START
637689de 209 std y+1,temp
7300c5e4 210 ldd temp,z+PART_START+1
637689de 211 std y+2,temp
7300c5e4 212 ldd temp,z+PART_START+2
637689de 213 std y+3,temp
7300c5e4 214 ldd temp,z+PART_START+3
637689de 215 std y+4,temp
7300c5e4 216
637689de
L
217 ldd temp,z+PART_SIZE+2
218 ldd temp2,z+PART_SIZE+3
219 or temp,temp2 ;part size larger than 65535 sectors?
220 brne cpm_add_prune
221
7300c5e4 222 ldd temp,z+PART_SIZE
637689de 223 std y+5,temp
7300c5e4 224 ldd temp,z+PART_SIZE+1
637689de
L
225 std y+6,temp
226 rjmp cpm_add_e
227
228cpm_add_prune:
229 std y+5,_255
230 std y+6,_255
231
232cpm_add_e:
29ce189c
L
233 ret
234
235#endif
5482d75f
L
236
237; vim:set ts=8 noet nowrap
238