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

Subversion Repositories eco32

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

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

powered by: WebSVN 2.1.0

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