Changeset 6f4087cb6b11c592278ebb86b5b90cc298e3c857

User picture

Commiter: Charles Childers

Author: Charles Childers

Parent: 43fd6a76ba

(2010/03/10 18:31) Almost 2 years ago

fread now returns the character read, not stores it in an address

Affected files

Updated image/source/files.retro Download diff

43fd6a76ba79839cb7b101945b85dac8dd07f9aa6f4087cb6b11c592278ebb86b5b90cc298e3c857
7
  : file.io ( n-f ) 4 out wait 4 in ;
7
  : file.io ( n-f ) 4 out wait 4 in ;
8
---reveal---
8
---reveal---
9
  : fopen  ( $m-f ) -1 file.io ;
9
  : fopen  ( $m-f ) -1 file.io ;
10
  : fread  ( hc-f ) -2 file.io ;
10
  : fread  (  h-f ) -2 file.io ;
11
  : fwrite ( ch-f ) -3 file.io ;
11
  : fwrite ( ch-f ) -3 file.io ;
12
  : fclose ( h -f ) -4 file.io ;
12
  : fclose ( h -f ) -4 file.io ;
13
  : fpos   ( h -n ) -5 file.io ;
13
  : fpos   ( h -n ) -5 file.io ;
14
  : fseek  ( nh-f ) -6 file.io ;
14
  : fseek  ( nh-f ) -6 file.io ;
15
  : fsize  ( h-n  ) -7 file.io ;
15
  : fsize  (  h-n ) -7 file.io ;
16
}}
16
}}
17
))
17
))
18
18

Updated library/files.retro Download diff

43fd6a76ba79839cb7b101945b85dac8dd07f9aa6f4087cb6b11c592278ebb86b5b90cc298e3c857
4
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
4
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
5
' files open
5
' files open
6
6
7
: fread! ( ha-f ) swap fread dup rot ! ;
8
7
: slurp ( a"- )
9
: slurp ( a"- )
8
  :r fopen dup
10
  :r fopen dup
9
  if
11
  if
10
    swap repeat 2dup fread not if 0 swap ! fclose drop ;then 1+ again
12
    swap repeat 2dup fread! 0 =if 0 swap ! fclose drop ;then 1+ again
11
  else
13
  else
12
    drop 0 swap !
14
    drop 0 swap !
13
  then ;
15
  then ;

Updated vm/console/files.c Download diff

43fd6a76ba79839cb7b101945b85dac8dd07f9aa6f4087cb6b11c592278ebb86b5b90cc298e3c857
30
}
30
}
31
31
32
int file_readc(VM *vm) {
32
int file_readc(VM *vm) {
33
  int cell = TOS; DROP;
34
  FILE *handle = (FILE *) TOS; DROP;
33
  FILE *handle = (FILE *) TOS; DROP;
35
  int c = fgetc(handle);
34
  int c = fgetc(handle);
36
  vm->image[cell] = c;
37
  if ( c == EOF ) {
35
  if ( c == EOF ) {
38
    return 0;
36
    return 0;
39
  } else {
37
  } else {
40
    return -1;
38
    return c;
41
  }
39
  }
42
}
40
}
43
41

Updated vm/fast-console/vm.c Download diff

43fd6a76ba79839cb7b101945b85dac8dd07f9aa6f4087cb6b11c592278ebb86b5b90cc298e3c857
541
541
542
          /* Read a char; response indicates success/failure */
542
          /* Read a char; response indicates success/failure */
543
          if (vm->ports[4] == -2) {
543
          if (vm->ports[4] == -2) {
544
            int cell = acc; DROP;
545
            FILE *handle = (FILE *) acc; DROP;
544
            FILE *handle = (FILE *) acc; DROP;
546
            int c = fgetc(handle);
545
            int c = fgetc(handle);
547
            vm->image[cell] = c;
546
            if   ( c == EOF ) vm->ports[4] = 0;
548
            if   ( c == EOF ) vm->ports[4] =  0;
547
            else              vm->ports[4] = c;
549
            else              vm->ports[4] = -1;
550
            vm->ports[0] = 1;
548
            vm->ports[0] = 1;
551
          }
549
          }
552
550

Updated vm/graphical/devices.c Download diff

43fd6a76ba79839cb7b101945b85dac8dd07f9aa6f4087cb6b11c592278ebb86b5b90cc298e3c857
330
330
331
    /* Read a char; response indicates success/failure */
331
    /* Read a char; response indicates success/failure */
332
    if (vm.ports[4] == -2) {
332
    if (vm.ports[4] == -2) {
333
      int cell = TOS; DROP;
334
      FILE *handle = (FILE *) TOS; DROP;
333
      FILE *handle = (FILE *) TOS; DROP;
335
      int c = fgetc(handle);
334
      int c = fgetc(handle);
336
      vm.image[cell] = c;
335
      if   ( c == EOF ) vm.ports[4] = 0;
337
      if   ( c == EOF ) vm.ports[4] =  0;
336
      else              vm.ports[4] = c;
338
      else              vm.ports[4] = -1;
339
      vm.ports[0] = 1;
337
      vm.ports[0] = 1;
340
    }
338
    }
341
339