Page 1 of 1

Some files won't read from disk in assembly.

Posted: Sun Jan 17, 2016 2:38 pm
by pixel
Am trying to read a file sequentially (in VICE and from SD2IEC). Pretty straightforward:

Code: Select all

main:
    lda #2
    ldx #8
    tay
    jsr $ffba   ; SETLFS

    lda #@(- txt_file_end txt_file)
    ldx #<txt_file
    ldy #>txt_file
    jsr $ffbd   ; CHKIN
    jsr $ffc0   ; OPEN
    bcs error
    ldx #2
    jsr $ffc6   ; CHKIN

l:  jsr $ffb7
    bne done

    jsr $ffcf   ; CHRIN
    bcs error

    jmp l

done:
    jsr $ffcc   ; CLRCHN
    lda #2
    jmp $ffc3   ; CLOSE

error:
    jmp error

txt_file:
    "MASTER"
txt_file_end:
Some files just give me the default BASIC load address followed by zeroes, others are just being read without problems. All are PRG files. POPEYE.TAP doesn't work, some shell script works, 1.5M of raw data also works, TAP file with header cut out again doesn't. What the flipping heck is causing that mess, please? :(

Re: Some files won't read from disk in assembly.

Posted: Sun Jan 17, 2016 2:50 pm
by Mike
If you open a file on a disk drive with secondary address >=2, you need to supply file type and access method appended to the file name: in your case ",P,R", without the quotes, appended to MASTER.

With PRG files on disk drives, secondary address 0 is equivalent to ",P,R", secondary address 1 is equivalent to ",P,W".

In VICE, VDrive accesses to a directory on the host's harddrive ignore the filetype, but the access method must still match (either ",R"/",W" or secondary address 0/1). Same applies to file accesses on SD2IEC devices outside disk images.

BTW, your first JSR to "CHKIN" at $FFBD in fact calls SETNAM. :)

Also, checking the carry flag on CHRIN for errors (like EOF) doesn't work at all from IEC devices. Some time ago I devised a small subroutine, which actually does the Right Thing™:

Code: Select all

.GetByte
 JSR $FFCF
 PHA
 LDA $90
 CMP #1    ; set carry when ST>=1 (i.e., <>0!)
 PLA       ; keep carry, and possibly set Z flag for byte=0
 RTS

Re: Some files won't read from disk in assembly.

Posted: Sun Jan 17, 2016 3:11 pm
by pixel
Thanks! I did the secondary address thing but it still fails like before. :( No error codes caught despite patch.

Re: Some files won't read from disk in assembly.

Posted: Sun Jan 17, 2016 3:24 pm
by Mike
@pixel: PM sent

Re: Some files won't read from disk in assembly.

Posted: Mon Jan 18, 2016 12:01 pm
by pixel
Solved! It's a VICE thing and my questionable talent for debugging. :p

Thanks!