How to read bytes from 1541/71/81 drives?

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

How to read bytes from 1541/71/81 drives?

Post by nbla000 »

I just want to read some bytes from a certain location ($0500) of the drive. In basic i've no problems i use this routines:

Code: Select all

10 OPEN 15,8,15
20 PRINT#15,"M-R"CHR$(0)CHR$(5)CHR$(5)
30 FOR T=1TO5
40 GET#15,A$:A=ASC(A$+CHR$(0))
50 PRINT A
60 NEXT T
70 CLOSE 15
With this basic routine i simply read the first 5 bytes of location $500 of the drive (normally 0 or other bytes if previously written), now i want to do the same using ML but probably i'm wrong in some place, this is LM code:

Code: Select all

lda #lmrcmd  ; cmd string length (6)
ldx #<mrcmd  ; string address lo-byte "M-R..." mrcmd:
ldy #>mrcmd  ; string address hi-byte
jsr $ffbd    ; SETNAM
ldx #8       ; DRIVE NR
lda #$0e     ; lfn #15    
ldy #$60     ; sa 96 ?!?
jsr $ffba    ; SETLFS
jsr $ffc0    ; OPEN
        
ldx #$0e     ; lfn #15
jsr $ffc6    ; CHKIN select lfn 15 for input

jsr $ffcf    ; CHRIN read byte $500 
jsr $ffd2    ; CHROUT  (print byte $DC) 
jsr $ffcf    ; CHRIN read byte $501
jsr $ffd2    ; CHROUT  (print byte $0D) 
jsr $ffcf    ; CHRIN read byte $502
jsr $ffd2    ; CHROUT  (print byte $0D) 
jsr $ffcf    ; CHRIN read byte $503
jsr $ffd2    ; CHROUT  (print byte $0D) 
jsr $ffcf    ; CHRIN read byte $504
jsr $ffd2    ; CHROUT  (print byte $0D) 
rts

mrcmd:
	dc.b "M-R",$0,$5,$5 ;drive command (read 5 bytes from $500)
lmrcmd = . - mrcmd     ;command length
i don't get zeros bytes or my previous written bytes but always $dc,$0d,$0d,$0d,$0d
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Hm, shouldn't that be #$0f if you want lfn #15?
Anders Carlsson

Image Image Image Image Image
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

Post by nbla000 »

Thanks Carlsson, i've read the code at least 20 times!!!
It's incredible how a bug may be so stupid!!!! :oops:

For guys that are interested, here there is the right ML code:

Code: Select all

lda #lmrcmd  ; cmd string length (6)
ldx #<mrcmd  ; string address lo-byte "M-R..." mrcmd:
ldy #>mrcmd  ; string address hi-byte
jsr $ffbd    ; SETNAM
lda #15      ; lfn #15    
ldx #8       ; DRIVE NR
ldy #15      ; sa #15
jsr $ffba    ; SETLFS
jsr $ffc0    ; OPEN
      
jsr $ffcc    ; CLRCHN reset IO status

ldx #15      ; lfn #15
jsr $ffc6    ; CHKIN select lfn #15 for input

msgloop:
jsr $ffe4    ; GETIN
jsr $ffd2    ; CHROUT
cmp #13      ; check for carriage return
bne msgloop

lda #15     
jsr $ffc3    ; CLOSE #15
        
jsr $ffcc    ; CLRCHN reset IO status

rts

mrcmd:
   dc.b "M-R",$0,$5,$5 ;drive command (read 5 bytes from $500)
lmrcmd = . - mrcmd     ;command length 
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Ah, the added benefit of using a cross-assembler that lets you mix number formats as you need. Well, perhaps some native assemblers let you do it as well, but I'm not as sure.
Anders Carlsson

Image Image Image Image Image
Post Reply