.main. hcd65xx v3.1 10july87 page 1 0:burst subs.src,s,r error addr code seq source statement 1 2 3 4 5 6 7 ;* ------------------ * 8 ;* ---------------------- BURST SUBROUTINES -- (rev 2) ----------- * 9 ;* ------------------ * 10 ;* * 11 ;* These assembly language sub-routines are designed for use in your * 12 ;* BASIC and machine code programs. A BASIC program needs simply to * 13 ;* POKE the appropriate values into the variable locations shown below, * 14 ;* and then SYS to the desired routine. All of the BURST protocol and * 15 ;* handshaking is done for you. The BASIC program can then PEEK any * 16 ;* values returned. * 17 ;* 18 ;* The routines in this listing that require data buffer storage areas * 19 ;* are passed the location of the buffer in BUFLOC. BUFLOC points to * 20 ;* RAM location in RAM bank 0 of the start of the buffer. Since the * 21 ;* KERNEL and I/O are needed, you must put BUFLOC below $C000. But be * 22 ;* sure to put it in RAM above your BASIC text. As a general rule, * 23 ;* work your way back from $C000 and you'll be OK. * 24 ;* 25 ;* To use these routines, your BASIC program must first BLOAD the file * 26 ;* 'BURST SUBS.BIN'. The routines load at $1300, so they are in a * 27 ;* safe place below BASIC text area. * 28 ;* 29 ;* There is no BURST FORMAT routine provided. The following BASIC * 30 ;* commands will format physical tracks 10 through 20 of the disk with * 31 ;* 5 1024 byte sectors: * 32 ;* 33 ;* OPEN 1,8,15 * 34 ;* PRINT#1,"U0";CHR$(3);CHR$(20);CHR$(5);CHR$(10); * 35 ;* 36 ;* Note the use of the semicolon (;) at the end of the statement. * 37 ;* This is very important! If there was no semicolon, the C128 would * 38 ;* send a carriage return after the last parameter. Since the 1581 * 39 ;* counts the number of bytes sent to determine the number of optional * 40 ;* parameters that are being sent, it would misinterpret the carriage * 41 ;* return as the next optional parameter. In this case, it would be * 42 ;* fill byte. Any formatting errors can be checked via the command * 43 ;* channel. * 44 ;* 45 ;* Since the BURST commands make use of the command channel to the * 46 ;* drive, the command channel must first be OPENed in your BASIC * 47 ;* program. The logical file number which you assigned to the command * 48 ;* channel should be poked to LF before calling any of these routines. * 49 ;* * 50 51 52 53 54 55 56 57 .main. hcd65xx v3.1 10july87 page 2 0:burst subs.src,s,r error addr code seq source statement 58 ;******************************************************************** 59 ; Variables - Values from BASIC can be POKEd, PEEKed to these areas. 60 ;******************************************************************** 61 =1300 62 *=$1300 63 1300 00 64 STATUS .byte 0 ; status byte 1301 08 65 DEV .byte 8 ; device number 1302 08 66 LF .byte 8 ; logical file number 1303 =1304 67 TRACK *=*+1 ; track 1304 =1305 68 SECTOR *=*+1 ; sector 1305 =1306 69 NUMSEC *=*+1 ; Number of sectors. 1306 =1308 70 BUFLOC *=*+2 ; Page # of buffer to get/put data. 1308 =1309 71 SECSIZE *=*+1 ; Sector size (1=256, 2=512, 4=1024) 1309 =130a 72 SIDE *=*+1 ; Physical side of the disk (0 or 1). 130a =130b 73 MINSEC *=*+1 ; Minimum logical sector found in QUERY. 130b =130c 74 MAXSEC *=*+1 ; Maximum logical sector found in QUERY. 130c =130d 75 INTLV *=*+1 ; Physical interleave found in QUERY. 130d =130e 76 FLAG *=*+1 ; Empty track flag. 77 ; This flag is used to indicate that the 78 ; track or data just read contains all 0's. This is handy in some cases, 79 ; such as during a disk copy program. When a disk is formatted, the sectors 80 ; are filled with 0's. If a sector to be copied contains all 0's, then we 81 ; don't bother to write it to the destination disk 82 83 84 ;**************************************************** 85 ; Other variables used in the following routines.... 86 ;**************************************************** 87 88 130e 89 cmdline 130e 55 30 90 .byte 'u0' ; Burst prefix. =131a 91 *=*+10 ; Parameter space for burst command. 131a =131b 92 cmdlen *=*+1 ; Length of the command string (# of bytes). 131b =131c 93 oldclk *=*+1 ; Status of clock line. 131c =131d 94 temp *=*+1 95 96 ;****************************************************************** 97 ; JUMP TABLE of available burst routines. SYS to these locations 98 ; from BASIC. The BURST routines themselves can then be modified 99 ; or customized without affecting the SYS locations from BASIC. 100 ;****************************************************************** 101 =1340 102 *=$1340 103 1340 104 J_INQUIRE_FORMAT 1340 4c 148d 105 jmp INQUIRE_FORMAT 1343 106 J_PHYSICAL_READ 1343 4c 136b 107 jmp PREAD 1346 108 J_LOGICAL_READ 1346 4c 135e 109 jmp LREAD 1349 110 J_PHYSICAL_WRITE 1349 4c 13f9 111 jmp PWRITE 134c 112 J_LOGICAL_WRITE 134c 4c 13ec 113 jmp LWRITE 114 .main. hcd65xx v3.1 10july87 page 3 0:burst subs.src,s,r error addr code seq source statement 115 134f 116 J_MEMORY_READ 134f 4c 1532 117 jmp MEMORY_READ 1352 118 J_MEMORY_WRITE 1352 4c 1594 119 jmp MEMORY_WRITE 1355 120 J_DUMP_CACHE 1355 4c 15fb 121 jmp DUMP_CACHE 1358 122 J_QUERY_FORMAT 1358 4c 14af 123 jmp QUERY_FORMAT 135b 124 J_COMPARE_MEMORY 135b 4c 162a 125 jmp COMPARE_MEMORY 126 127 ;*************************************** 128 ; Locations of important C128 stuff... 129 ;*************************************** 130 =ffc9 131 chkout=$ffc9 ; kernel channel output =ffcc 132 clrchn=$ffcc ; kernel clear channel =ffba 133 setlfs=$ffba ; kernel set logical file number =ffbd 134 setnam=$ffbd ; kernel set filename =ffd2 135 bsout =$ffd2 ; kernel basic input/output =ff47 136 spin_out=$ff47 ; Set up fast serial for input or output. 137 ; SEC for output, CLC for input. =dd00 138 d2pra =$dd00 ; C128 serial port location =0010 139 clkout=$10 ; slow serial clock output bit mask =0040 140 clkin =$40 ; slow serial clock input bit mask =dc0d 141 d1icr =$dc0d ; 6526 CIA interrupt control register =dc0c 142 d1sdr =$dc0c ; 6526 CIA serial data register =00fa 143 buffer=$fa ; zero page pointer variable =00fc 144 buffer2=$fc ; zero page pointer variable 145 146 ;****************************** 147 ; BURST command primitives 148 ;****************************** 149 =0000 150 PBURSTRD =$00 ; Physical burst read. =0002 151 PBURSTWR =$02 ; Physical burst write. =0080 152 LBURSTRD =$80 ; Logical burst read =0082 153 LBURSTWR =$82 ; Logical burst write. =0004 154 BURST_INQUIRE =$04 ; Burst inquire. =009d 155 DUMPCACHE =$9D ; Dump track cache ('force' bit set) =008a 156 BURST_QUERY =$8A ; Query disk format. 157 158 ;********************************************************* 159 ;* --------------- BURST ROUTINES -------------------- * 160 ;********************************************************* 161 135e 162 LREAD ;Logical sector read from the device indicated by LF. 163 ;The track and sector are in TRACK, SECTOR. The location 164 ;Status byte from drive is returned in STATUS. 165 135e a9 80 166 lda #lburstrd ;logical burst read command 1360 8d 1310 167 sta cmdline+2 1363 a9 01 168 lda #$01 1365 8d 1308 169 sta SECSIZE ;Logical sector size is always 256 bytes. 1368 4c 1377 170 jmp READ 171 .main. hcd65xx v3.1 10july87 page 4 0:burst subs.src,s,r error addr code seq source statement 172 173 136b 174 PREAD ;Physical sector read from device indicated by LF. 175 ;The track and sector are in TRACK, SECTOR. The location 176 ;of start of the C128 buffer to put the read data in BUFLOC. 177 ;The physical sector size in SECSIZE (1=256,2=512,4=1024). 178 ;Number of sectors in NUMSEC. 179 ;Physical side of the disk in SIDE (0 or 1). 180 ;Status byte from drive is returned in STATUS. 181 136b a9 00 182 lda #PBURSTRD ;Physical burst read command. 136d ae 1309 183 ldx SIDE ; Check which side to read from. 1370 f0 02 184 beq 1$ 1372 09 10 185 ora #$10 ; If side 1, then set bit in the command byte. 1374 8d 1310 186 1$ sta cmdline+2 187 188 1377 189 READ 190 1377 ad ff00 191 lda $ff00 ;Save old MMU setup. 137a 48 192 pha 193 137b a9 0e 194 lda #$0e ;Set MMU for RAM0,KERNEL,I/O. 137d 8d ff00 195 sta $ff00 196 1380 20 167d 197 jsr SETU0 ;Put "U0" at start of command string. 198 1383 ad 1303 199 lda TRACK 1386 8d 1311 200 sta CMDLINE+3 ; track 1389 ad 1304 201 lda SECTOR 138c 8d 1312 202 sta CMDLINE+4 ; sector 138f ad 1305 203 lda NUMSEC 1392 8d 1313 204 sta CMDLINE+5 ; Number of sectors to read. 205 1395 a9 06 206 lda #$06 ; Length of command string. 1397 8d 131a 207 sta CMDLEN 139a 20 1664 208 jsr sendcmd ; send cmd string 209 139d ad 1306 210 lda BUFLOC ; Set up zero page indirect pointer. 13a0 85 fa 211 sta BUFFER 13a2 ad 1307 212 lda BUFLOC+1 13a5 85 fb 213 sta BUFFER+1 214 13a7 a0 00 215 ldy #0 ; clear the 'empty sector(s)' flag. 13a9 8c 130d 216 sty flag 217 13ac 78 218 sei ; No irq's allowed during handshake. 13ad 2c dc0d 219 bit d1icr ; clear pending 220 13b0 20 169c 221 jsr CLK_CHNG ;Change state of clock. 222 13b3 ae 1308 223 1$ ldx SECSIZE ; Sector size gives # of pages per sector. 224 13b6 20 16a5 225 jsr WAIT ;Wait for fast byte (1st is status). 13b9 ad dc0c 226 lda d1sdr ;Get status byte. 13bc 8d 1300 227 sta STATUS 228 .main. hcd65xx v3.1 10july87 page 5 0:burst subs.src,s,r error addr code seq source statement 229 230 13bf 29 0f 231 and #15 ;Was there an error? 13c1 c9 02 232 cmp #2 ; 13c3 b0 21 233 bcs 5$ ; branch if error occured. 234 13c5 20 169c 235 jsr CLK_CHNG ;Change clock so next byte is sent. 236 13c8 20 16a5 237 3$ jsr WAIT ;Wait for the next byte. 238 13cb 20 169c 239 jsr CLK_CHNG ;Change state of clock so next byte is sent. 13ce ad dc0c 240 lda D1SDR ;Get the data byte 13d1 91 fa 241 sta (buffer),y ; and save it 242 ; while next byte is being transmitted. 243 13d3 0d 130d 244 ora flag ;Update 'zero' sector flag. 13d6 8d 130d 245 sta flag 246 13d9 c8 247 iny ;Any more in this page? 13da d0 ec 248 bne 3$ 249 13dc e6 fb 250 inc BUFFER+1 13de ca 251 dex ;Loop for the # of pages per sector. 13df d0 e7 252 bne 3$ 253 13e1 ce 1313 254 dec CMDLINE+5 ;Loop for the number of sectors. 13e4 d0 cd 255 bne 1$ 256 13e6 58 257 5$ cli 258 13e7 68 259 pla ;Restore MMU to old configuration. 13e8 8d ff00 260 sta $ff00 261 13eb 60 262 rts 263 264 ;**************************************************************** 265 13ec 266 LWRITE ;Logical sector write to the device indicated by LF. 267 ;The track and sector are in TRACK, SECTOR. The location 268 ;of start of C128 buffer containing write data in BUFLOC. 269 ;Status byte from drive is returned in STATUS. 270 13ec a9 82 271 lda #lburstwr 13ee 8d 1310 272 sta cmdline+2 ; burst write 13f1 a9 01 273 lda #$01 13f3 8d 1308 274 sta SECSIZE ; Logical sector size is always 256 bytes. 13f6 4c 1405 275 jmp WRITE 276 277 13f9 278 PWRITE ;Physical sector write to the device indicated by LF. 279 ;The track and sector are in TRACK, SECTOR. The location 280 ;of start of C128 buffer containing write data in BUFLOC. 281 ;The physical sector size in SECSIZE (1=256,2=512,4=1024). 282 ;Number of sectors in NUMSEC. 283 ;Physical side in SIDE. 284 ;Status byte from drive is returned in STATUS. 285 .main. hcd65xx v3.1 10july87 page 6 0:burst subs.src,s,r error addr code seq source statement 286 287 13f9 a9 02 288 lda #PBURSTWR ;Physical burst write command. 13fb ae 1309 289 ldx SIDE ; Check which side to write to. 13fe f0 02 290 beq 1$ 1400 09 10 291 ora #$10 ; If side 1, then set bit in the command byte. 1402 8d 1310 292 1$ sta cmdline+2 293 294 1405 295 WRITE 296 1405 ad ff00 297 lda $ff00 ;Save old MMU setup. 1408 48 298 pha 299 1409 a9 0e 300 lda #$0e ;Set MMU for RAM0,KERNEL,I/O. 140b 8d ff00 301 sta $ff00 302 140e 20 167d 303 jsr SETU0 ;Put "U0" at start of command string. 1411 ad 1303 304 lda TRACK 1414 8d 1311 305 sta CMDLINE+3 ; track 1417 ad 1304 306 lda SECTOR 141a 8d 1312 307 sta CMDLINE+4 ; sector 141d ad 1305 308 lda NUMSEC 1420 8d 1313 309 sta CMDLINE+5 ; Number of sectors to write. 310 1423 a9 06 311 lda #$06 1425 8d 131a 312 sta CMDLEN ;Command length. 1428 20 1664 313 jsr sendcmd ; send cmd string 314 142b ad 1306 315 lda BUFLOC ; Set up zero page indirect pointer. 142e 85 fa 316 sta BUFFER 1430 ad 1307 317 lda BUFLOC+1 1433 85 fb 318 sta BUFFER+1 319 1435 a9 40 320 lda #clkin ;Initial clock status. 1437 8d 131b 321 sta oldclk 322 143a a0 00 323 ldy #0 143c 78 324 sei ; no irq's during burst handshake 325 143d ae 1308 326 1$ ldx SECSIZE ; Sector size gives # of pages per sector. 327 1440 38 328 sec ;Turn fast serial to output mode. 1441 20 ff47 329 jsr spin_out 330 1444 ad dd00 331 2$ lda d2pra ;Wait for state change. 1447 4d 131b 332 eor oldclk 144a 29 40 333 and #clkin 144c f0 f6 334 beq 2$ 335 144e 4d 131b 336 eor oldclk ;Change status of OLDCLK. 1451 8d 131b 337 sta oldclk 338 1454 b1 fa 339 lda (buffer),y ; get data 1456 8d dc0c 340 sta d1sdr ; & send it 341 1459 20 16a5 342 jsr WAIT ;Wait for the byte to be transmitted. .main. hcd65xx v3.1 10july87 page 7 0:burst subs.src,s,r error addr code seq source statement 343 344 145c c8 345 iny 145d d0 e5 346 bne 2$ ;Any more left in this page? 347 145f e6 fb 348 inc buffer+1 1461 ca 349 dex ;Loop for the # of pages per sector. 1462 d0 e0 350 bne 2$ 351 1464 18 352 clc ;Turn around to input mode to get STATUS. 1465 20 ff47 353 jsr spin_out 354 1468 2c dc0d 355 bit d1icr ; clear pending 356 146b 20 1688 357 jsr clklo ; set clock low when ready for status 358 146e 20 16a5 359 jsr WAIT ;Wait for the byte to be shifted in. 1471 ad dc0c 360 lda d1sdr ;Get the status byte. 1474 8d 1300 361 sta STATUS ;Save it. 1477 48 362 pha 1478 20 1693 363 jsr clkhi ;Release the slow clock line. 147b 68 364 pla 365 147c 29 0f 366 and #15 ;Check for any error. 147e c9 02 367 cmp #2 1480 b0 05 368 bcs 7$ ; branch if there was an error. 369 1482 ce 1313 370 dec CMDLINE+5 ;Loop for the number of sectors. 1485 d0 b6 371 bne 1$ 372 1487 58 373 7$ cli 1488 68 374 pla ;Restore old memory configuration. 1489 8d ff00 375 sta $ff00 148c 60 376 rts 377 378 ;************************************************************ 379 148d 380 INQUIRE_FORMAT ;Sends an INQUIRE DISK command to the drive indicate by 381 ;the logical file (LF). Status is returned in STATUS. 382 148d 20 167d 383 jsr SETU0 ;Put "U0" at start of command string. 1490 a9 04 384 lda #BURST_INQUIRE ; inquire burst command 1492 8d 1310 385 sta cmdline+2 1495 a9 03 386 lda #$03 ; length of command. 1497 8d 131a 387 sta CMDLEN 149a 20 1664 388 jsr sendcmd ; send cmd string 389 149d 78 390 sei ;Disable interrupts during handshake. 391 149e 2c dc0d 392 bit D1ICR ;Clear any byte ready that's pending. 393 14a1 20 169c 394 jsr CLK_CHNG ;Change clock so 1581 sends next. 14a4 20 16a5 395 jsr WAIT ;Wait for the byte to be shifted in. 14a7 ad dc0c 396 lda D1SDR ;Get the status byte. 14aa 8d 1300 397 sta STATUS ;Save it off. 14ad 58 398 cli 14ae 60 399 rts .main. hcd65xx v3.1 10july87 page 8 0:burst subs.src,s,r error addr code seq source statement 400 401 402 ;************************************************************ 403 14af 404 QUERY_FORMAT ;Sends a QUERY DISK FORMAT command to the drive indicate by 405 ;the logical file (LF). Physical track number to query 406 ;should be provided in TRACK. Physical side should 407 ;be provided in SIDE. Status is returned in STATUS. 408 ;Number of sectors found on the track returned in NUMSEC. 409 ;Logical track number found in the sector headers returned 410 ;in TRACK. Minimum logical sector number found in the 411 ;sector headers is returned in MINSEC. The maximium 412 ;logical sector is returned MAXSEC. Physical interleave 413 ;is returned in INTLV. 414 ;If an error is encountered in compiling this information 415 ;(as indicated by STATUS), then none of the return values 416 ;are valid (except STATUS). 417 14af 20 167d 418 jsr SETU0 ;Put "U0" at start of command string. 419 14b2 a9 8a 420 lda #BURST_QUERY ;QUERY DISK burst command 14b4 ae 1309 421 ldx SIDE ; Set the side bit accordingly. 14b7 d0 02 422 bne 4$ 14b9 09 10 423 ora #$10 14bb 8d 1310 424 4$ sta cmdline+2 425 14be ad 1303 426 lda TRACK ; Physical track offset. 14c1 8d 1311 427 sta cmdline+3 14c4 a9 04 428 lda #$04 ; length of command. 14c6 8d 131a 429 sta CMDLEN 14c9 20 1664 430 jsr sendcmd ; send cmd string 431 14cc 78 432 sei ;Disable interrupts during handshake. 14cd 2c dc0d 433 bit D1ICR ;Clear any byte ready that's pending. 434 14d0 20 169c 435 jsr CLK_CHNG ;Change state of clock so 1581 sends next. 14d3 20 16a5 436 jsr WAIT ;Wait for the first status byte. 14d6 ad dc0c 437 lda D1SDR ;Get the status byte (status of track 0). 14d9 8d 1300 438 sta STATUS ;Save it off. 439 14dc 29 0f 440 and #$0f ;Was there an error? 14de c9 02 441 cmp #2 14e0 b0 4e 442 bcs 5$ ; branch if there was an error. 443 14e2 20 169c 444 jsr CLK_CHNG ;Change state of clock, so 1581 sends next. 14e5 20 16a5 445 jsr WAIT ;Wait for next status byte to be ready. 14e8 ad dc0c 446 lda D1SDR ;Get it (status of track TRACK). 14eb 8d 1300 447 sta STATUS ;Save it. 448 14ee 29 0f 449 and #$0f ;Was there an error? 14f0 c9 02 450 cmp #2 14f2 b0 3c 451 bcs 5$ ; branch if an error. 452 14f4 20 169c 453 jsr CLK_CHNG ;Change state of clock, so 1581 sends next. 14f7 20 16a5 454 jsr WAIT ;Wait for 'number of sectors byte' to be ready. 14fa ad dc0c 455 lda D1SDR ;Get it. 14fd 8d 1305 456 sta NUMSEC ;Save it. .main. hcd65xx v3.1 10july87 page 9 0:burst subs.src,s,r error addr code seq source statement 457 458 1500 20 169c 459 jsr CLK_CHNG ;Change state of clock, so 1581 sends next. 1503 20 16a5 460 jsr WAIT ;Wait for 'logical track #' byte to be ready. 1506 ad dc0c 461 lda D1SDR ;Get it. 1509 8d 1303 462 sta TRACK ;Save it. 463 150c 20 169c 464 jsr CLK_CHNG ;Change state of clock, so 1581 sends next. 150f 20 16a5 465 jsr WAIT ;Wait for 'minimum sector #' byte to be ready. 1512 ad dc0c 466 lda D1SDR ;Get it. 1515 8d 130a 467 sta MINSEC ;Save it. 468 1518 20 169c 469 jsr CLK_CHNG ;Change state of clock, so 1581 sends next. 151b 20 16a5 470 jsr WAIT ;Wait for 'maximum sector #' byte to be ready. 151e ad dc0c 471 lda D1SDR ;Get it. 1521 8d 130b 472 sta MAXSEC ;Save it. 473 1524 20 169c 474 jsr CLK_CHNG ;Change state of clock, so 1581 sends next. 1527 20 16a5 475 jsr WAIT ;Wait for 'interleave' byte to be ready. 152a ad dc0c 476 lda D1SDR ;Get it. 152d 8d 130c 477 sta INTLV ;Save it. 478 1530 58 479 5$ cli 1531 60 480 rts 481 482 ;*************************************************************** 483 1532 484 MEMORY_READ ;Burst memory read of the 1581. Page in 1581 memory to 485 ;start reading at in .X, number of pages to read in .Y, 486 ;location to store data in C128 memory in BUFLOC. 487 ;Logical file to be read from in LF. 488 1532 ad ff00 489 lda $ff00 ;Save old MMU setup. 1535 48 490 pha 491 1536 a9 0e 492 lda #$0e ;Set MMU for RAM0,KERNEL,I/O. 1538 8d ff00 493 sta $ff00 494 153b 20 167d 495 jsr SETU0 ;Put "U0" at start of command string. 153e a9 3e 496 lda #$3E ;('>') 'burst memory read' command string. 1540 8d 1310 497 sta CMDLINE+2 ; ( "U0>MR" ) 1543 a9 4d 498 lda #$4D ;('M') 1545 8d 1311 499 sta CMDLINE+3 1548 a9 52 500 lda #$52 ;('R') 154a 8d 1312 501 sta CMDLINE+4 154d 8e 1313 502 stx CMDLINE+5 ; 1581 page to start reading from. 1550 8c 1314 503 sty CMDLINE+6 ; # of pages to read. 504 1553 a9 07 505 lda #$07 ; Length of command string. 1555 8d 131a 506 sta CMDLEN 1558 20 1664 507 jsr sendcmd ; send cmd string 508 155b ad 1306 509 lda BUFLOC ; Set up zero page indirect pointer. 155e 85 fa 510 sta BUFFER 1560 ad 1307 511 lda BUFLOC+1 1563 85 fb 512 sta BUFFER+1 513 .main. hcd65xx v3.1 10july87 page 10 0:burst subs.src,s,r error addr code seq source statement 514 1565 a9 00 515 lda #0 ; clear the 'empty sector(s)' flag. 1567 8d 130d 516 sta flag 517 156a 78 518 sei ; No irq's allowed during handshake. 519 156b 2c dc0d 520 bit d1icr ; clear pending 521 156e 20 169c 522 jsr CLK_CHNG ;Change state of clock. 523 1571 a0 00 524 ldy #0 1573 20 16a5 525 3$ jsr WAIT ;Wait for the byte to be shifted in. 526 1576 20 169c 527 jsr CLK_CHNG ;Change clock so next byte is sent. 1579 ad dc0c 528 lda d1sdr ; get data 157c 91 fa 529 sta (buffer),y ; and save it while next byte is transmitted. 530 157e 0d 130d 531 ora flag ; Update 'zero' flag. 1581 8d 130d 532 sta flag 533 1584 c8 534 iny 1585 d0 ec 535 bne 3$ ;Any more in this page? 536 1587 e6 fb 537 inc BUFFER+1 1589 ce 1314 538 dec CMDLINE+6 ;Any more pages to do? 158c d0 e5 539 bne 3$ 540 158e 58 541 5$ cli 542 158f 68 543 pla ;Restore old memory configuration. 1590 8d ff00 544 sta $ff00 545 1593 60 546 rts 547 548 ;************************************************************ 549 1594 550 MEMORY_WRITE ;Burst memory write to the 1581's memory. The 551 ;location in C128 memory to send data from in BUFLOC. 552 ;The page in 1581 memory to start writing to in .X. 553 ;The number of pages to write in .Y. 554 ;Logical file to be written to in LF. 555 1594 ad ff00 556 lda $ff00 ;Save old MMU setup. 1597 48 557 pha 558 1598 a9 0e 559 lda #$0e ;Set MMU for RAM0,KERNEL,I/O. 159a 8d ff00 560 sta $ff00 561 159d 20 167d 562 jsr SETU0 ;Put "U0" at start of command string. 15a0 a9 3e 563 lda #$3E ;('>') 'burst memory write' command string. 15a2 8d 1310 564 sta CMDLINE+2 ; ( "U0>MW" ) 15a5 a9 4d 565 lda #$4D ;('M') 15a7 8d 1311 566 sta CMDLINE+3 15aa a9 57 567 lda #$57 ;('W') 15ac 8d 1312 568 sta CMDLINE+4 15af 8e 1313 569 stx CMDLINE+5 ; 1581 page to start writing to. 15b2 8c 1314 570 sty CMDLINE+6 ; # of pages to write. .main. hcd65xx v3.1 10july87 page 11 0:burst subs.src,s,r error addr code seq source statement 571 572 15b5 a9 07 573 lda #$07 ; Length of command string. 15b7 8d 131a 574 sta CMDLEN 575 15ba 20 1664 576 jsr sendcmd ; send cmd string 577 15bd ad 1306 578 lda BUFLOC ; Set up zero page indirect pointer. 15c0 85 fa 579 sta BUFFER 15c2 ad 1307 580 lda BUFLOC+1 15c5 85 fb 581 sta BUFFER+1 582 15c7 a9 40 583 lda #clkin ;Initial clock status. 15c9 8d 131b 584 sta oldclk 585 15cc a0 00 586 ldy #0 15ce 78 587 sei ;No IRQ's allowed during handshake. 588 15cf 38 589 sec ; Set to output mode. 15d0 20 ff47 590 jsr SPIN_OUT 591 15d3 ad dd00 592 2$ lda d2pra ;Wait for state (slow clock line) change. 15d6 4d 131b 593 eor OLDCLK 15d9 29 40 594 and #CLKIN 15db f0 f6 595 beq 2$ 596 15dd 4d 131b 597 eor OLDCLK ;Change status of OLDCLK variable. 15e0 8d 131b 598 sta OLDCLK 599 15e3 b1 fa 600 lda (BUFFER),y ;Get data to write. 15e5 8d dc0c 601 sta D1SDR ;Send it. 602 15e8 20 16a5 603 jsr WAIT ;Wait for the byte to be sent. 604 15eb c8 605 iny 15ec d0 e5 606 bne 2$ ;More in this page? 607 15ee e6 fb 608 inc BUFFER+1 15f0 ce 1314 609 dec CMDLINE+6 15f3 d0 de 610 bne 2$ ;Any more pages to send? 611 15f5 58 612 cli 613 15f6 68 614 pla ;Restore old memory configuration. 15f7 8d ff00 615 sta $ff00 616 15fa 60 617 rts 618 619 620 ;********************************************************** 621 622 15fb 623 DUMP_CACHE ;Dumps the track cache at 1581 $0C00 to the physical track 624 ;specified in TRACK, on the side specified in SIDE. The 625 ;'force' bit is set, so it is written whether dirty or not. 626 627 .main. hcd65xx v3.1 10july87 page 12 0:burst subs.src,s,r error addr code seq source statement 628 15fb 20 167d 629 jsr SETU0 15fe a9 9d 630 lda #DUMPCACHE ;Dump track cache command. 631 1600 ae 1309 632 ldx SIDE ; Set SIDE bit accordingly. 1603 f0 02 633 beq 1$ 1605 09 40 634 ora #$40 635 1607 8d 1310 636 1$ sta CMDLINE+2 ; Put the command byte into command string. 160a ad 1303 637 lda TRACK 160d 8d 1311 638 sta CMDLINE+3 ; Physical track to dump cache to. 639 1610 a9 04 640 lda #4 1612 8d 131a 641 sta CMDLEN ;Length of the command string. 1615 20 1664 642 jsr SENDCMD 643 1618 78 644 sei ;Disable interrupts during handshake. 645 1619 2c dc0d 646 bit D1ICR ;Clear any byte ready that's pending. 647 161c 20 169c 648 jsr CLK_CHNG ;Change clock so 1581 will send status byte. 161f 20 16a5 649 jsr WAIT ;Wait for byte to be shifted in. 1622 ad dc0c 650 lda D1SDR ;Get the status byte. 1625 8d 1300 651 sta STATUS ;Save it off. 652 1628 58 653 cli 1629 60 654 rts 655 656 657 ;************************************************************* 658 162a 659 COMPARE_MEMORY ;Compares memory blocks in the C128 memory. 660 ;Number of pages to compare in .A. 661 ;First page of first memory block in .X. 662 ;First page of second memory block in .Y. 663 ;If they are equal, then STATUS=0. 664 162a 8d 131c 665 sta temp 666 162d ad ff00 667 lda $ff00 ;Save old MMU setup. 1630 48 668 pha 669 1631 a9 0e 670 lda #$0e ;Set MMU for RAM0,KERNEL,I/O. 1633 8d ff00 671 sta $ff00 672 1636 86 fb 673 stx buffer+1 ;Set up MSB of 1st memory pointer. 1638 84 fd 674 sty buffer2+1 ;Set up MSB of 2nd memory pointer. 163a ae 131c 675 ldx temp ;Number of pages to compare. 676 163d a9 00 677 lda #0 ;Set up LSB's of memory pointers. 163f 85 fa 678 sta buffer 1641 85 fc 679 sta buffer2 680 1643 8d 1300 681 sta STATUS ;Initialize STATUS. 682 1646 a0 00 683 ldy #0 684 .main. hcd65xx v3.1 10july87 page 13 0:burst subs.src,s,r error addr code seq source statement 685 1648 b1 fa 686 2$ lda (buffer),y 164a d1 fc 687 cmp (buffer2),y 164c f0 07 688 beq 1$ 689 164e a9 ff 690 lda #$ff ;Not equal! Load STATUS with nonzero. 1650 8d 1300 691 sta STATUS 1653 d0 0a 692 bne 99$ ; (branch always) 693 1655 c8 694 1$ iny 1656 d0 f0 695 bne 2$ ;More in this page? 696 1658 e6 fb 697 inc buffer+1 165a e6 fd 698 inc buffer2+1 165c ca 699 dex ;# of pages counter. 165d d0 e9 700 bne 2$ 701 165f 68 702 99$ pla ;Restore old memory configuration. 1660 8d ff00 703 sta $ff00 704 1663 60 705 rts 706 707 ;********************************************************** 708 1664 709 SENDCMD ;Sends the command in CMDLINE to the logical file 710 ;indicated by LF. Length of the command should be in CMDLEN. 711 1664 ae 1302 712 ldx LF 1667 20 ffc9 713 jsr chkout ; channel output (pointed to by .X) 166a a2 00 714 ldx #0 166c ac 131a 715 ldy cmdlen ; send cmd 166f bd 130e 716 1$ lda cmdline,x 1672 20 ffd2 717 jsr bsout 1675 e8 718 inx 1676 88 719 dey 1677 d0 f6 720 bne 1$ 721 1679 20 ffcc 722 jsr clrchn ; send buffered char & eoi 167c 60 723 rts 724 725 ;*********************************************************** 726 167d a9 55 727 SETU0 lda #85 ;'U' 167f 8d 130e 728 sta CMDLINE 1682 a9 30 729 lda #48 ;'0' 1684 8d 130f 730 sta CMDLINE+1 1687 60 731 rts 732 733 1688 734 CLKLO ; set clock low 1688 48 735 pha 1689 ad dd00 736 lda d2pra 168c 09 10 737 ora #clkout 168e 8d dd00 738 sta d2pra 1691 68 739 pla 1692 60 740 rts 741 .main. hcd65xx v3.1 10july87 page 14 0:burst subs.src,s,r error addr code seq source statement 742 743 1693 744 CLKHI ; set clock high 1693 ad dd00 745 lda d2pra 1696 29 ef 746 and #$ff-clkout 1698 8d dd00 747 sta d2pra 169b 60 748 rts 749 169c 750 CLK_CHNG ; change the state of the clock line output. 169c ad dd00 751 lda D2PRA 169f 49 10 752 eor #clkout 16a1 8d dd00 753 sta D2PRA 16a4 60 754 rts 755 16a5 756 WAIT ; wait for the shift register to be full or empty. 16a5 a9 08 757 1$ lda #8 16a7 2c dc0d 758 bit D1ICR 16aa f0 f9 759 beq 1$ 16ac 60 760 rts 761 762 763 .end 0 errors detected .main. hcd65xx v3.1 10july87 page 15 symbol table = label, <=> = symbol, <+>= multibly defined bsout =ffd2 buffer =00fa buffer2 =00fc bufloc 1306 burst_inquire =0004 burst_query =008a chkout =ffc9 clkhi 1693 clkin =0040 clklo 1688 clkout =0010 clk_chng 169c clrchn =ffcc cmdlen 131a cmdline 130e compare_memory 162a d1icr =dc0d d1sdr =dc0c d2pra =dd00 dev 1301 dumpcache =009d dump_cache 15fb flag 130d inquire_format 148d intlv 130c j_compare_memory 135b j_dump_cache 1355 j_inquire_format 1340 j_logical_read 1346 j_logical_write 134c j_memory_read 134f j_memory_write 1352 j_physical_read 1343 j_physical_write 1349 j_query_format 1358 lburstrd =0080 lburstwr =0082 lf 1302 lread 135e lwrite 13ec maxsec 130b memory_read 1532 memory_write 1594 minsec 130a numsec 1305 oldclk 131b pburstrd =0000 pburstwr =0002 pread 136b pwrite 13f9 query_format 14af read 1377 secsize 1308 sector 1304 sendcmd 1664 setlfs =ffba setnam =ffbd setu0 167d side 1309 spin_out =ff47 status 1300 temp 131c track 1303 wait 16a5 write 1405