[Contents] [Commodore] [New] [Search] [Home]

Commodore 1571 firmware
Seek

        .page  
	.subttl 'lccseek1.src'

jseak   lda  #90        ; search 90 headers
        sta  tmp         

1$	jsr  jsync      ; find sync char

2$	bit  pota1	; wait for block id
	bmi  2$

        lda  data2      ; clear pa1 in the gate array
        cmp  #$52       ; test if header block
        bne  3$		; not header

        sta  stab,y   	; store 1st byte
        iny      

4$	bit  pota1
	bmi  4$

        lda  data2       
        sta  stab,y     ; store gcr header off

        iny      
        cpy  #8         ; 8 gcr bytes in header
        bne  4$

        jsr  jcnvbin    ; convert header in stabof to binary in header

        ldy  #4         ; compute checksum
        lda  #0          

5$	eor  header,y    
        dey      
        bpl  5$

        cmp  #0         ; test if ok
        bne  9$		; nope, checksum error in header

        lda  header+2    
        sta  drvtrk      

        lda  job        ; test if a seek job
        cmp  #$30        
        beq  6$

        lda  dskid       
        cmp  header      
        bne  8$

        lda  dskid+1     
        cmp  header+1    
        bne  8$

	jmp  7$		; find best sector to service

3$	dec  tmp        ; search more?
        bne  1$		; yes

        lda  #2         ; cant find a sector
        jsr  jerrr        

6$	lda  header     ; sta disk id's
        sta  dskid      ; *
        lda  header+1   
        sta  dskid+1   

	lda  #1         ; return ok code
        .byte    skip2   

8$	lda  #11        ; disk id mismatch
        .byte    skip2   

9$	lda  #9         ; checksum error in header
        jmp  jerrr        

7$	lda  #$7f       ; find best job
        sta  csect       

        lda  header+3   ; get upcoming sector #
        clc      
        adc  #2          
        cmp  sectr       
        bcc  10$

        sbc  sectr      ; wrap around

10$	sta  nexts      ; next sector

        ldx  #numjob-1   
        stx  jobn        

        ldx  #$ff        

12$	jsr  jsetjb       
        bpl  11$

        and  #drvmsk     
        cmp  cdrive     ; test if same drive
        bne  11$	; nope

        ldy  #0         ; test if same track
        lda  (hdrpnt),y          
        cmp  tracc       
        bne  11$

	lda  job
	cmp  #execd
	beq  13$

        ldy  #1          
        sec      
        lda  (hdrpnt),y          
        sbc  nexts       
        bpl  13$

        clc      
        adc  sectr       

13$	cmp  csect       
        bcs  11$

        pha     	; save it
        lda  job         
        beq  16$	; must be a read

        pla      
        cmp  #wrtmin    ; +if(csect<4)return;
        bcc  11$	; +if(csect>8)return;

        cmp  #wrtmax     
        bcs  11$

15$	sta  csect      ; its better
        lda  jobn        
        tax      
        clc      
        adc  #>bufs      
        sta  bufpnt+1    

        bne  11$

16$	pla      
        cmp  #rdmax     ; if(csect>6)return;
        bcc  15$

11$	dec  jobn        
        bpl  12$

        txa     	; test if a job to do
        bpl  14$

        jmp  jend       ; no job found

14$	stx  jobn        
        jsr  jsetjb       
        lda  job         
        jmp  jread        

jcnvbin lda  bufpnt      
        pha      
        lda  bufpnt+1    
        pha     	; save buffer pntr

        lda  #<stab	; stab offset
        sta  bufpnt     ; point at gcr code
        lda  #>stab
        sta  bufpnt+1    

        lda  #0          
        sta  gcrpnt      

        jsr  jget4gb    ; convert 4 bytes

        lda  btab+3      
        sta  header+2    

        lda  btab+2      
        sta  header+3    

        lda  btab+1      
        sta  header+4    


        jsr  jget4gb    ; get 2 more

        lda  btab       ; get id
        sta  header+1    
        lda  btab+1      
        sta  header      

        pla      
        sta  bufpnt+1   ; restore pointer
        pla      
        sta  bufpnt      
        rts

[Contents] [Commodore] [New] [Search] [Home]
This page has been created by Sami Rautiainen.
Read the small print. Last updated September 05, 2020.