;license:BSD-3-Clause ;bootable zpage seek/read ;copyright (c) Peter Ferrie 2015-16, 2018 ;thanks to 4am for inspiration and testing ;assemble using ACME !cpu 6502 !to "0boot",plain *=$800 tracks = $d1 ;user-defined first_trk = $01 ;user-defined address = $d1 ;user-defined, high byte of first page entry = $d1d1 ;user-defined sectors = $00 ;user-defined, sectors to load from partial track (increase tracks count first) interleave= 0 ;user-defined, to retain .dsk sector ordering multi_regn= 0 ;user-defined, load to non-sequential addresses !if multi_regn=1 { !macro region {region !byte $d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0} ;user-defined ;assign every '$d1' from left ;for track with alternative address ;or zero to continue from last address ;beginning with second track ;array size = tracks*2 } version = 3 ;memory usage: ;256 bytes ($200-2FF) static table grouped = $200 ;106 bytes ($36C-3D5) static table preshift = $36C ;86 bytes ($300-355) dynamic table (2-bit array) bit2tbl = $300 !byte 1 ;we'll read the other one ourselves lsr ;check sector number bne + ;branch if not 1 inc $3d ;increment sector (faster to find) txa jsr $f87b ora #$c0 ;slot to PROM base pha lda #$5b ;read-1 pha rts ;the following TAY is a workaround for a CFFA bug ;the bug is that Y isn't zero on entry ;the workaround sets it to one instead ;it's not zero, but it's better than #$10 + tay txa ora #$8c ;slot to Q6L - ldx $900, y stx $0, y ;copy RTS to zpage iny bne - - iny ldx <(patchtbl-1), y sta $0, x ;replace placeholders with Q6L bne - and #$f0 ;PHASEOFF sta <(slotpatch6+1) ora #8 ;MOTOROFF sta <(slotpatch8+1) !if interleave=1 { ldx #$0f txs - lda sectbl, x pha dex bpl - } lda #>(entry-1) pha lda #<(entry-1) pha ldx #(stackend-addrtbl) - lda <(addrtbl-1), x pha ;copy stack frame dex bne - ldy #<(tracks*2) !if sectors>0 { txa pha lda #0 { ++ } pha lda #<(seek-1) pha ;push seek twice for two phases dey bne - !if first_trk>1 { ldy #((first_trk-1)*2) - txa pha lda #<(seek-1) pha ;push seek twice for two phases dey bne - } ;construct denibbilisation table ;pre-shifted for interleave read ldx #$6a - asl preshift-1,x asl preshift-1,x dex bne - ;construct 2-bit group table iny -- lsr <(curtrk+1) lsr <(curtrk+1) - lda 0 { !byte $2c ldx #<(-sectors) } stx $ff { !serious "code is too large, ends at *" } }