Some files won't read from disk in assembly.

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
pixel
Vic 20 Scientist
Posts: 1328
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Some files won't read from disk in assembly.

Post 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? :(
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

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

Post 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
Last edited by Mike on Sun Jan 17, 2016 3:11 pm, edited 1 time in total.
User avatar
pixel
Vic 20 Scientist
Posts: 1328
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

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

Post by pixel »

Thanks! I did the secondary address thing but it still fails like before. :( No error codes caught despite patch.
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

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

Post by Mike »

@pixel: PM sent
User avatar
pixel
Vic 20 Scientist
Posts: 1328
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

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

Post by pixel »

Solved! It's a VICE thing and my questionable talent for debugging. :p

Thanks!
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
Post Reply