Reading file byte-per-byte in assembler

Started by MIRKOSOFT, July 18, 2010, 12:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MIRKOSOFT

Hi!


I have any problem. I want to read file byte-per-byte and show on screen data. In BASIC it's not problem:
1DOPEN#1,"NAME,P"
2GET#1,A$
3PRINTA$;
4IFST<>64THEN2
5DCLOSE#1
my problem in assembler and also BASIC 2.0 (C64 mode) is that it seems that it reads one first byte only and loop forever...
Here's code:



// IO - variables
.var read = $ffe4
.var setlfs = $ffba
.var setnam = $ffbd
.var open = $ffc0
.var clrch = $ffcc
.var close = $ffc3
.var chkin = $ffc6
.var ckout = $ffc9
.var chrin = $ffcf
.var bsout = $ffd2


 start: lda #7
ldx #<dirnam
ldy #>dirnam
jsr setnam

lda #1
ldx device
ldy #1
jsr setlfs

ldx #$01
jsr chkin
ldx #$00
back: jsr read
sta $0400,x
inx
lda $90
bvc back
jsr clrch
lda #1
jsr close
rts

dirnam:
.text "KOD,P,R"

device:
.byte 8




Where I did a mistake?


Many many many thanks for every reply!


Miro
MIRKOSOFT of megabytes

Commodore 64 was great, Commodore 128 is bigger, better, faster and more!!!

http://www.mirkosoft.sk

LokalHorst

Hi Miro,

the error is here:
...
back:   jsr read
   sta $0400,x
   inx
   lda $90  <- it has to be BIT $90 as LDA didn't set/clear the overflow flag. (EOF)
   bvc back
...

Wagner

You might want to lda $90, beq back since if you bit $90, bvc back you might set up a condition where you have an endless loop, since only an EOI will terminate your loop.

MIRKOSOFT

Hi!


Thanks. Yes, I fixed this error before, but still it does endless loop with the same value, don't you know why?


Thanks.


Miro
MIRKOSOFT of megabytes

Commodore 64 was great, Commodore 128 is bigger, better, faster and more!!!

http://www.mirkosoft.sk

MIRKOSOFT

Hi!


Thanks for all advices, now is problem solved.
I was amazed what can to do secondary address - in this case equals #2.
Else one Q as last: first two readed bytes are address from where was file saved?


Many many thanks.


Miro
MIRKOSOFT of megabytes

Commodore 64 was great, Commodore 128 is bigger, better, faster and more!!!

http://www.mirkosoft.sk

Wagner

You setnam, setlfs, and chkin, but never seem to open the file.