jmechner
100755 450 lines (355 sloc) 5.267 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
 lst off
 tr on
 org $D000
 xc off

*-------------------------------------------------
*
* 07/02/87
*
* Unidisk 3.5 interface for
* 18 sector read/write routine
*
* Copyright 1985, 1987
* by Roland Gustafsson
*
*-------------------------------------------------
*
* Permanent vars
*

slot = $FD
track = $FE
 ;lastrack = $FF ;NOT USED

* Zero page usage:

zpage = $40
zpagelen = 16

temp = $40
command = $41

* Device Driver Parameters:

DDPcmd = $42
DDPunit = $43
DDPbuflo = $44
DDPbufhi = $45
DDPblklo = $46
DDPblkhi = $47

CARD = $4E

*-------------------------------------------------
 jmp RW18
*-------------------------------------------------

OFFSET = 16 ;default offset

*-------------------------------------------------
*
* READ/WRITE 18 sectors!
*

READ lda #1
 hex 2C
WRITE lda #2
 sta DDPcmd

* Calculate starting block
* (OFFSET+track*9)

 lda track ;0-34
 asl
 asl
 asl
 tax ;x=lo

 lda #0
 rol
 tay ;y=hi

 txa
 adc track
 tax

 tya
 adc #0
 tay

 txa
 adc #OFFSET
BOFFLO = *-1
 sta BLOCKLO

 tya
 adc #>OFFSET
BOFFHI = *-1
 sta BLOCKHI

* Loop for 18 sectors, 2 at a time.

 ldy #0
:0 tya
 pha

* Do 2 sectors

 lda BUFTABLE,Y
 sta ]rbuf0
 sta ]wbuf0
 ldx BUFTABLE+1,Y
 stx ]rbuf1
 stx ]wbuf1
 dex
 cpx ]rbuf0
 jsr RWSECTS

 pla
 tay

 bcs rts

* Next 2 sectors

 inc BLOCKLO
 bne :1
 inc BLOCKHI

:1 iny
 iny
 cpy #18
 bne :0

 clc
rts rts

*-----------
*
* Read or write 2 sectors
*
* If the two sectors are sequential
* then just go to the Device Driver.
*
RWSECTS beq JMPDD

 ldy DDPcmd
 dey
 bne WSECTS

* Read two non-contiguous sectors

RSECTS lda ]rbuf0
 ora ]rbuf1
 clc
 beq :rts

 jsr JMPDDBUF
 bcs :rts

* Now move them to where they belong

 ldx #$2C ; bit ABS
 ldy #$99 ; sta ABS,Y

* If this sector is to be ignored,
* then change sta $FF00,Y to bit.

 sty ]rmod0
 lda ]rbuf0
 bne *+5
 stx ]rmod0

 sty ]rmod1
 lda ]rbuf1
 bne *+5
 stx ]rmod1

 ldy #0
:0 lda BLOCKBUF,Y
]rmod0 sta $FF00,Y
]rbuf0 = *-1
 lda BLOCKBUF+256,Y
]rmod1 sta $FF00,Y
]rbuf1 = *-1
 iny
 bne :0
:rts rts

*-----------
*
* Write two non-contiguous sectors
*

WSECTS ldy #0
:0 lda $FF00,Y
]wbuf0 = *-1
 sta BLOCKBUF,Y
 lda $FF00,Y
]wbuf1 = *-1
 sta BLOCKBUF+256,Y
 iny
 bne :0

JMPDDBUF lda #>BLOCKBUF

*-----------
*
* Jump to Device Driver
*
* Enter: A - address of buffer
*

JMPDD sta DDPbufhi

* Set block number

 lda #$11
BLOCKLO = *-1
 sta DDPblklo
 lda #$11
BLOCKHI = *-1
 sta DDPblkhi

* Get address of firmware

 lda slot
 sta DDPunit
 lsr
 lsr
 lsr
 lsr
 ora #$C0
 sta CARD+1
 lda #0
 sta CARD
 sta DDPbuflo

* Get address of Device Driver

 ldy #$FF
 lda (CARD),Y
 sta CARD

* Jump to it!!!

 jmp (CARD)

*------------------------------------------------- RW18
*
* Entry point into RW18
*

RW18 pla
 sta GOTBYTE+1
 pla
 sta GOTBYTE+2

 bit $CFFF

 jsr SWAPZPAG

 jsr GETBYTE
 sta command
 and #$0F
 asl
 tax

 lda cmdadr,X
 sta :1+1
 lda cmdadr+1,X
 sta :1+2
:1 jsr $FFFF

 lda GOTBYTE+2
 pha
 lda GOTBYTE+1
 pha

SWAPZPAG php
 ldx #0
:0 lda zpage,x
 ldy ZPAGSAVE,X
 sta ZPAGSAVE,X
 sty zpage,x
 inx
 cpx #zpagelen
 bne :0
 plp
 rts

cmdadr da SKIP2 ; CMDRIVON
 da rts ; CMDRIVOF
 da CMseek
 da CMreadseq
 da CMreadgroup
 da CMwriteseq
 da CMwritegroup
 da CMid
 da CMoffset

*------------------------------------------------- CMseek
*
* SEEK
* <check disk for lastrack?>,
* <track>
*
CMseek jsr GETBYTE
 jsr GETBYTE
 sta track
 rts

*------------------------------------------------- CMreadseq
*------------------------------------------------- CMreadgroup
*
* Read sequence
* <buf adr>
*
* Read group
* <18 buf adr's>
*
CMreadseq ldx #1
 hex 2C
CMreadgroup ldx #18
 jsr CMADINFO

CMREAD2 jsr READ

*-------------------------------------------------
*
* READ/WRITE exit.
*
INCTRAK? bit command
 bcs WHOOP?

* If bit 6 set, then inc track

 bvc ]rts
 inc track
]rts rts

* If bit 7 set then whoop speaker
* WARNING:use only with READ

WHOOP? bpl ]rts
 ldy #0
:1 tya
 bit $C030
:2 sec
 sbc #1
 bne :2
 dey
 bne :1
 beq CMREAD2

*------------------------------------------------- CMwriteseq
*------------------------------------------------- CMwritegroup
*
* Same as READ
*

CMwriteseq ldx #1
 hex 2C
CMwritegroup ldx #18
 jsr CMADINFO
 jsr WRITE
 jmp INCTRAK?

*------------------------------------------------- CMid
*
* Change offset based on ID
*

CMid jsr GETBYTE
 sta :IDmod+1

 ldy #-3
:0 iny
 iny
 iny
 lda :IDlist,y
 beq :rts

:IDmod cmp #$11
 bne :0

 lda :IDlist+1,y
 sta BOFFLO
 lda :IDlist+2,y
 sta BOFFHI

:rts rts

:IDlist db $A9
 dw 16 ;side one

 db $AD
 dw 16+315 ;side two

 db 0 ;end of list

*------------------------------------------------- CMoffset
*
* Set new block offset
*

CMoffset jsr GETBYTE
 sta BOFFLO
 jsr GETBYTE
 sta BOFFHI
 rts

*-------------------------------------------------
*
* Get buffer info.
*

CMADINFO stx temp
 ldx #0
:0 jsr GETBYTE
 sta BUFTABLE,X
 inx
 cpx temp
 bcc :0
 tay

* If sequence, then fill table

:1 iny
 cpx #18
 beq :2
 tya
 sta BUFTABLE,X
 inx
 bne :1

:2 rts

*-------------------------------------------------
*
SKIP2 jsr GETBYTE
SKIP1

GETBYTE inc GOTBYTE+1
 bne GOTBYTE
 inc GOTBYTE+2
GOTBYTE lda $FFFF
 rts

*-------------------------------------------------

 sav rw1835

ZPAGSAVE ds $100
BUFTABLE ds 18
 ds \
BLOCKBUF ds 512

*-------------------------------------------------

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?