root/src/load.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. addcerrlist_load
  2. loadassemble

   1 #include <stdio.h>
   2 #include <string.h>
   3 #include <assert.h>
   4 #include <stdlib.h>
   5 #include <ctype.h>
   6 
   7 #include "word.h"
   8 #include "struct.h"
   9 #include "cerr.h"
  10 
  11 /**
  12  * @brief ファイル読み込みのエラー定義
  13  */
  14 static CERR cerr_load[] = {
  15     { 210, "load - memory overflow" },
  16     { 211, "object file not specified" },
  17     { 212, "invalid option" },
  18     { 213, "invalid argument" },
  19 };
  20 
  21 /* load.hで定義された関数群 */
  22 void addcerrlist_load()
  23 {
  24     addcerrlist(ARRAYSIZE(cerr_load), cerr_load);
  25 }
  26 
  27 WORD loadassemble(const char *file, WORD start)
  28 {
  29     FILE *fp = NULL;
  30     WORD end = 0;
  31 
  32     assert(file != NULL);
  33     if((fp = fopen(file, "rb")) == NULL) {
  34         perror(file);
  35         return 0;
  36     }
  37     end = start + fread(sys->memory + start, sizeof(WORD), sys->memsize - start, fp);
  38     if(end == sys->memsize) {
  39         setcerr(210, file);    /* load - memory overflow */
  40         fprintf(stderr, "Load error - %d: %s\n", cerr->num, cerr->msg);
  41     }
  42     fclose(fp);
  43     return end;
  44 }

/* [<][>][^][v][top][bottom][index][help] */