Shop OBEX P1 Docs P2 Docs Learn Events
Problem reading a binary files — Parallax Forums

Problem reading a binary files

MGreimMGreim Posts: 114

Hi,

I am trying to read a binary file from SD card. After some hours fiddling around i found the following solution working for me:

pub FILEDUMP ( -- ) 
FOPEN test.bin
FSIZE@
0
." ----- " CRLF
DO
 I  16  //   \ CRLF each 16 bytes
 0=
  IF
    CRLF
    I .ADDR ." " 
  THEN
 I SDC@
 .BYTE ."  | "
LOOP
FCLOSE
;

for the first call it works perfectly
BUT
at a second call I got different data.
For me it seems that TAQOZ was reading another sector after the first call of the word.
A 3rd and 4th call of FILEDUMP is showing the same wrong data.
Any ideas, or is there a better solution? The max. file size is about 32 kByte.
I want to output the data 4 byte by 4 byte to some device and forget the data afterwards.

Markus

Comments

  • Hi,
    problem solved.
    First the filename then FOPEN$ of course.
    This works for me with TAQOZ 2.8 as well as with the latest TAQOZ 2.14:

    pub FILEDUMP ( -- ) 
      " MESSEN  .BIN"
     FOPEN$ 
     FSIZE@
     0
     DO
     I  16  //   \ CRLF each 16 bytes
     0=
     IF
      CRLF
      I .ADDR ." " 
     THEN
     I SDC@
     .BYTE ." | "
     LOOP
     FCLOSE
     !SP
     ;
    

    P.S. some more general examples would be helpful.
    Reverse engineering from the sources is educational but tiring.

    Markus

  • RossHRossH Posts: 5,350

    I`'m always astounded when I read forth code. I read it ... and read it ... and read it ... and it almost makes sense ... and then my stack overflows :).

  • @RossH said:
    I`'m always astounded when I read forth code. I read it ... and read it ... and read it ... and it almost makes sense ... and then my stack overflows :).

    ..same for me.
    BTW the " MESSEN .BIN" is not necessary " messen.bin" or " MESSEN.BIN" without spaces works as well.
    So it seems that file names are not case sensitive and the length of the string doesn't matter as long as you
    don't exceed the old maximum 8.3 DOS format.
    Markus

Sign In or Register to comment.