Commodore 128 Alive!

Commodore 128 => 128 programmers => Assembly => Topic started by: MIRKOSOFT on July 18, 2010, 12:37 PM

Title: Reading file byte-per-byte in assembler
Post by: MIRKOSOFT on July 18, 2010, 12:37 PM
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
Title: Re: Reading file byte-per-byte in assembler
Post by: LokalHorst on July 19, 2010, 04:05 AM
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
...
Title: Re: Reading file byte-per-byte in assembler
Post by: Wagner on July 19, 2010, 10:18 AM
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.
Title: Re: Reading file byte-per-byte in assembler
Post by: MIRKOSOFT on July 19, 2010, 12:32 PM
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
Title: Re: Reading file byte-per-byte in assembler - solved
Post by: MIRKOSOFT on July 19, 2010, 06:38 PM
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
Title: Re: Reading file byte-per-byte in assembler
Post by: Wagner on July 20, 2010, 12:49 PM
You setnam, setlfs, and chkin, but never seem to open the file.
EhPortal 1.34 © 2025, WebDev