Beispiel #1
0
unsigned char loadoverlay (unsigned char num)
{
    if (overlay[num - 1].page < 0) {
#ifndef __CBM__

        int file;

        printf ("Dbg: Loading overlay %u from file\n", num);
        file = open (overlay[num - 1].name, O_RDONLY);
        if (file == -1) {
            log ("Opening overlay file failed");
            return 0;
        }
        read (file, overlay[num - 1].addr,
                    overlay[num - 1].size);
        close (file);

#else

        if (cbm_load (overlay[num - 1].name, getcurrentdevice (), NULL) == 0) {
            log ("Loading overlay file failed");
            return 0;
        }

#endif
        return 1;
    } else {
        struct em_copy copyinfo;

        printf ("Dbg: Loading overlay %u from memory\n", num);
        copyinfo.offs  = 0;
        copyinfo.page  = overlay[num - 1].page;
        copyinfo.buf   = overlay[num - 1].addr;
        copyinfo.count = overlay[num - 1].size;
        em_copyfrom (&copyinfo);
        return 1;
    }
}
Beispiel #2
0
unsigned char loadfile (char *name, void *addr, void *size)
{
#ifndef __CBM__

    int file = open (name, O_RDONLY);
    if (file == -1) {
        log ("Opening overlay file failed");
        return 0;
    }
    read (file, addr, (unsigned) size);
    close (file);

#else

    /* Avoid compiler warnings about unused parameters. */
    (void) addr; (void) size;
    if (cbm_load (name, getcurrentdevice (), NULL) == 0) {
        log ("Loading overlay file failed");
        return 0;
    }

#endif
    return 1;
}
Beispiel #3
0
int __fastcall__
exec(const char *progname, const char *cmdline)
{
  static int fd;
  static unsigned char dv, n;

  /* Exclude devices that can't load files. */
  /* (Use hand optimization, to make smaller code.) */
  dv = getcurrentdevice();
  if(dv < 8 && __AX__ != 1 || __AX__ > 30) {
    return _mappederrno(9);             /* illegal device number */
  }
  utoa(dv, basic.unit, 10);

  /* Tape files can be openned only once; skip this test for the Datasette. */
  if(dv != 1) {
    /* Don't try to run a program that can't be found. */
    fd = cfs_open(progname, CFS_READ);
    if(fd < 0) {
      return -1;
    }
    cfs_close(fd);
  }

  n = 0;
  do {
    if((basic.name[n] = progname[n]) == '\0') {
      break;
    }
  } while(++n < 20);                    /* truncate long names */
  basic.name[n] = '\"';

/* This next part isn't needed by machines that put
** BASIC source and variables in different RAM banks.
*/
#if !defined(__C128__)
  /* cc65 program loads might extend beyond the end of the RAM that is allowed
  ** for BASIC.  Then, the LOAD statement would complain that it is "out of
  ** memory".  Some pointers that say where to put BASIC program variables
  ** must be changed, so that we do not get that error.  One pointer is
  ** changed here; a BASIC CLR statement changes the others.  Some space is
  ** needed for the file-name string.  Subtracting an entire RAM page allows
  ** better optimization of this expression.
  */
  vartab = (char*)memsize - 0x0100;
#endif

  /* Build the next program's argument list. */
  basbuf[0] = 0x8F;                     /* REM token */
  basbuf[1] = '\0';
  if(cmdline != NULL) {
    strncat(basbuf, cmdline, (size_t)basbuf_len - 2);
  }

  /* Tell the ROM where to find that BASIC program. */
  txtptr = &basic;

  /* (The return code, in ST [status], will be destroyed by LOAD.
  ** So, don't bother to set it here.)
  */
  exit(__AX__);
}