jmechner
100755 304 lines (219 sloc) 3.676 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
 lst off

 org $E00

errcode = 0
get8bit = $E74C

buffer = $1000 ;7 tracks long
bufferend = buffer+$7E00

rw18 = $D000 ;both versions!

slot = $FD
track = $FE
lastrack = $FF

*-------------------------------------------------
*
* CALL RT - moves rw18 routines to their homes in aux mem
*
* CALL RT+3,<5.25" slot>,<BbundID>,<start track>,<end track>
* ,<3.5" slot>,<block offset>
*

 jmp move

* Get source information:

start jsr get8bit
 stx slot525
 jsr get8bit
 stx BbundID
 jsr get8bit
 stx track
 jsr get8bit
 inx
 stx ENDtrack

* Destination information

 jsr get8bit
 stx slot35
 jsr $DEBE ;get16bit
 jsr $DD67
 jsr $E752
 sty Boffset
 sta Boffset+1

* From now on we are using aux zpage and $D000

 lda track
 sta $C009
 sta track

 jsr recal525

loop lda track

 pha
 jsr read525
 bcs :plarts
 pla

 sta track
 jsr write35
 bcs :rts

 lda track
 eor ENDtrack
 bne loop

 pha

:plarts pla
:rts lda #0
 rol
 sta $C008 ;back to main mem
 sta errcode
 bit $C081
 rts

ENDtrack db $11

*------------------------------------------------- read525
*
* Read up to 7 tracks from 5.25" floppy.
*

read525 jsr prep525

* Drive on, delay .5 seconds

 jsr rw18
 db 0,1,5

* Read until buffer is full

 lda #>buffer

:loop sta :readbuf

 jsr rw18
 db $43 ;auto-inc, readsequ
:readbuf db $11
 bcs :error

 lda :readbuf
 jsr buffend?
 bcc :loop
 clc

:error php
 jsr rw18
 db 1 ;drive off
 plp
 rts

*------------------------------------------------- buffend?
*
* Have we reached the end of buffer, or ENDtrack?
* Enter: a - last buffer address
*
* Exit: cs - no more buffer, or ENDtrack reached
* cc - keep going, a=new buffer address
*

buffend? clc
 adc #$12
 cmp #>bufferend
 bcs :rts

 ldy track
 cpy ENDtrack

:rts rts

*------------------------------------------------- prep525
*
* Prepare to use 5.25" RW18 routine
*

* Normal RW18 routine is in second bank of $D000

prep525 bit $C08B
 bit $C08B

* Set slot of 5.25" drive

 lda #$11
slot525 = *-1
 asl
 asl
 asl
 asl
 sta slot
 tax

* Turn off all phases

 lda $C080,x
 lda $C082,x
 lda $C084,x
 lda $C086,x

* Set Broderbund ID byte

 jsr rw18
 db 7
BbundID db $11

 rts

*------------------------------------------------- recal525
*
* Recalibrate 5.25" floppy drive
*

recal525 jsr prep525

 lda #$A0
 sta lastrack

* Drive on

 jsr rw18
 db 0,1,3 ;.3 second delay

* Seek to track zero

 lda track
 pha

 jsr rw18
 db 2,0,0

 pla
 sta track
 sta :track

* Now seek first track

 jsr rw18
 db 2,0
:track db $11

 rts

*------------------------------------------------- write35
*
* Write up to 7 tracks to 3.5" disk.
*

write35 jsr prep35

* Write until no more buffer, or ENDtrack is reached

 lda #>buffer

:loop sta :writebuf

 jsr rw18
 db $45 ;auto-inc, writesequ
:writebuf db $11
 bcs :error

 lda :writebuf
 jsr buffend?
 bcc :loop
 clc

:error rts

*------------------------------------------------- prep35
*
* Prepare to use 3.5" RW18 routine
*

* 3.5" RW18 routine is in first bank of $D000

prep35 bit $C083
 bit $C083

* Set slot of 3.5" drive

 lda #$11
slot35 = *-1
 asl
 asl
 asl
 asl
 sta slot
 tax

* Set offset into 3.5" disk

 jsr rw18
 db 8
Boffset da $1111

 rts

*------------------------------------------------- move
*
* Move the RW18 routines to their respective homes.
*
* $1000 - 3.5" rw18 routine
* $2000 - 5.25" rw18 routine
*

move ldx #$83
 lda #$10
 jsr :0
 ldx #$8B
 lda #$20

:0 sta :source+2
 lda #$D0
 sta :dest+2

 lda $C000,x
 lda $C000,x

 sta $C009 ;aux $D000

 ldx #$10
 ldy #0
:source lda $1000,y
:dest sta $D000,y
 iny
 bne :source

 inc :source+2
 inc :dest+2

 dex
 bne :source

 sta $C008
 bit $C081

 rts

*------------------------------------------------- EOF

Markdown Cheat Sheet

Format Text

Headers

# This is an <h1> tag
## This is an <h2> tag
###### This is an <h6> tag

Text styles

*This text will be italic*
_This will also be italic_
**This text will be bold**
__This will also be bold__

*You **can** combine them*

Lists

Unordered

* Item 1
* Item 2
  * Item 2a
  * Item 2b

Ordered

1. Item 1
2. Item 2
3. Item 3
   * Item 3a
   * Item 3b

Miscellaneous

Images

![GitHub Logo](/images/logo.png)
Format: ![Alt Text](url)

Links

http://github.com - automatic!
[GitHub](http://github.com)

Blockquotes

As Kanye West said:

> We're living the future so
> the present is our past.

Code Examples in Markdown

Syntax highlighting with GFM

```javascript
function fancyAlert(arg) {
  if(arg) {
    $.facebox({div:'#foo'})
  }
}
```

Or, indent your code 4 spaces

Here is a Python code example
without syntax highlighting:

    def foo:
      if not bar:
        return true

Inline code for comments

I think you should use an
`<addr>` element here instead.

Something went wrong with that request. Please try again. Dismiss

Looking for the GitHub logo?