OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [sim/] [main.c] - Blame information for rev 17

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 hellwig
/*
2
 * main.c -- ECO32 simulator
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
 
10
#include "common.h"
11
#include "console.h"
12
#include "error.h"
13
#include "command.h"
14
#include "instr.h"
15
#include "cpu.h"
16
#include "mmu.h"
17
#include "memory.h"
18
#include "timer.h"
19
#include "dspkbd.h"
20
#include "term.h"
21
#include "disk.h"
22
#include "output.h"
23
#include "graph.h"
24
 
25
 
26
static void usage(char *myself) {
27
  fprintf(stderr, "Usage: %s\n", myself);
28
  fprintf(stderr, "         [-i]             set interactive mode\n");
29
  fprintf(stderr, "         [-m <n>]         install n MB of RAM (1-%d)\n",
30
          RAM_SIZE_MAX / M);
31
  fprintf(stderr, "         [-l <prog>]      set program file name\n");
32
  fprintf(stderr, "         [-r <rom>]       set ROM image file name\n");
33
  fprintf(stderr, "         [-d <disk>]      set disk image file name\n");
34
  fprintf(stderr, "         [-t <n>]         connect n terminals (0-%d)\n",
35
          MAX_NTERMS);
36
  fprintf(stderr, "         [-g]             install graphics controller\n");
37
  fprintf(stderr, "         [-c]             install console\n");
38
  fprintf(stderr, "         [-o <file>]      bind output device to file\n");
39
  fprintf(stderr, "The options -l and -r are mutually exclusive.\n");
40
  fprintf(stderr, "If both are omitted, interactive mode is assumed.\n");
41
  exit(1);
42
}
43
 
44
 
45
int main(int argc, char *argv[]) {
46
  int i;
47
  char *argp;
48
  char *endp;
49
  Bool interactive;
50
  int memSize;
51
  char *progName;
52
  char *romName;
53
  char *diskName;
54
  int numTerms;
55
  Bool graphics;
56
  Bool console;
57
  char *outputName;
58
  Word initialPC;
59
  char command[20];
60
  char *line;
61
 
62
  interactive = false;
63
  memSize = RAM_SIZE_DFL / M;
64
  progName = NULL;
65
  romName = NULL;
66
  diskName = NULL;
67
  numTerms = 0;
68
  graphics = false;
69
  console = false;
70
  outputName = NULL;
71
  for (i = 1; i < argc; i++) {
72
    argp = argv[i];
73
    if (*argp != '-') {
74
      usage(argv[0]);
75
    }
76
    argp++;
77
    switch (*argp) {
78
      case 'i':
79
        interactive = true;
80
        break;
81
      case 'm':
82
        if (i == argc - 1) {
83
          usage(argv[0]);
84
        }
85
        memSize = strtol(argv[++i], &endp, 10);
86
        if (*endp != '\0' ||
87
            memSize <= 0 ||
88
            memSize > RAM_SIZE_MAX / M) {
89
          usage(argv[0]);
90
        }
91
        break;
92
      case 'l':
93
        if (i == argc - 1 || progName != NULL || romName != NULL) {
94
          usage(argv[0]);
95
        }
96
        progName = argv[++i];
97
        break;
98
      case 'r':
99
        if (i == argc - 1 || romName != NULL || progName != NULL) {
100
          usage(argv[0]);
101
        }
102
        romName = argv[++i];
103
        break;
104
      case 'd':
105
        if (i == argc - 1 || diskName != NULL) {
106
          usage(argv[0]);
107
        }
108
        diskName = argv[++i];
109
        break;
110
      case 't':
111
        if (i == argc - 1) {
112
          usage(argv[0]);
113
        }
114
        numTerms = strtol(argv[++i], &endp, 10);
115
        if (*endp != '\0' ||
116
            numTerms < 0 ||
117
            numTerms > MAX_NTERMS) {
118
          usage(argv[0]);
119
        }
120
        break;
121
      case 'g':
122
        graphics = true;
123
        break;
124
      case 'c':
125
        console = true;
126
        break;
127
      case 'o':
128
        if (i == argc - 1 || outputName != NULL) {
129
          usage(argv[0]);
130
        }
131
        outputName = argv[++i];
132
        break;
133
      default:
134
        usage(argv[0]);
135
    }
136
  }
137
  cInit();
138
  cPrintf("ECO32 Simulator started\n");
139
  if (progName == NULL && romName == NULL && !interactive) {
140
    cPrintf("Neither a program to load nor a system ROM was\n");
141
    cPrintf("specified, so interactive mode is assumed.\n");
142
    interactive = true;
143
  }
144
  initInstrTable();
145
  timerInit();
146
  if (console) {
147
    displayInit();
148
    keyboardInit();
149
  }
150
  termInit(numTerms);
151
  diskInit(diskName);
152
  outputInit(outputName);
153
  if (graphics) {
154
    graphInit();
155
  }
156
  memoryInit(memSize * M, progName, romName);
157
  mmuInit();
158
  if (progName != NULL) {
159
    initialPC = 0xC0000000;
160
  } else {
161
    initialPC = 0xC0000000 | ROM_BASE;
162
  }
163
  cpuInit(initialPC);
164
  if (!interactive) {
165
    cPrintf("Start executing...\n");
166
    strcpy(command, "c\n");
167
    execCommand(command);
168
  } else {
169
    while (1) {
170
      line = cGetLine("ECO32 > ");
171
      if (*line == '\0') {
172
        break;
173
      }
174
      cAddHist(line);
175
      if (execCommand(line)) {
176
        break;
177
      }
178
    }
179
  }
180
  cpuExit();
181
  mmuExit();
182
  memoryExit();
183
  timerExit();
184
  displayExit();
185
  keyboardExit();
186
  termExit();
187
  diskExit();
188
  outputExit();
189
  graphExit();
190
  cPrintf("ECO32 Simulator finished\n");
191
  cExit();
192
  return 0;
193
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.