boot.c 3.66 KB
Newer Older
Michael Stolovitzsky's avatar
Michael Stolovitzsky committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
 * This file is part of 'pdp', a PDP-11 simulator.
 *
 * For information contact:
 *
 *   Computer Science House
 *   Attn: Eric Edwards
 *   Box 861
 *   25 Andrews Memorial Drive
 *   Rochester, NY 14623
 *
 * Email:  mag@potter.csh.rit.edu
 * FTP:    ftp.csh.rit.edu:/pub/csh/mag/pdp.tar.Z
 * 
 * Copyright 1994, Eric A. Edwards
 *
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any purpose and without
 * fee is hereby granted, provided that the above copyright
 * notice appear in all copies.  Eric A. Edwards makes no
 * representations about the suitability of this software
 * for any purpose.  It is provided "as is" without expressed
 * or implied warranty.
 */

/*
 * boot.c - Boot Code
 */

#include "defines.h"
31
#include "intl.h"
Michael Stolovitzsky's avatar
Michael Stolovitzsky committed
32
33
34
35
36
37

/*
 * load_rom() - Read the contents of the ROM into the array. 
 * Used for BK-0010 style ROM - stores into the mapped memory.
 */

38
void load_rom(unsigned start, const char * rompath, unsigned min_size, unsigned max_size) {
Michael Stolovitzsky's avatar
Michael Stolovitzsky committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	char * path;
	int i;
	unsigned long saved_ram_map = pdp_ram_map;
	FILE * romf;

	if (!rompath || !*rompath) return;
	path = malloc(strlen(romdir)+strlen(rompath)+2);

	if (!path) { fprintf(stderr, _("No memory\n")); exit(1); }

	/* If rompath is a real path, do not apply romdir to it */
	if (*romdir && !strchr(rompath, '/'))
		sprintf(path, "%s/%s", romdir, rompath);
	else
		strcpy(path, rompath);

	fprintf(stderr, _("Loading %s..."), path);

	romf = fopen(path, "r");
	if (!romf) {
		fprintf(stderr, _("Couldn't open file.\n"));
		exit(1);
	}
	pdp_ram_map = ~0l;
	for (i = 0; i < max_size/2; i++, start+=2) {
		int lobyte = getc(romf);
		int hibyte = getc(romf);
		d_word data;
		if (hibyte < 0) break;
		data = lobyte | hibyte<<8;
		sc_word(start, data);
	}
	if (i < min_size/2) {
		fprintf(stderr, _("Incomplete or damaged file.\n"));
		exit(1);
	}
	fclose(romf);
	free(path);
        fprintf(stderr, _("Done.\n"));
	pdp_ram_map = saved_ram_map;
}

/*
 * Loads BK-0011 ROM into the givem ROM block from a given offset.
 */
84
void load_rom11(d_word * rombuf, int byte_off, const char * rompath, int byte_size) {
Michael Stolovitzsky's avatar
Michael Stolovitzsky committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
	char * path;
	int i;

	if (!rompath || !*rompath) return;
	path = malloc(strlen(romdir)+strlen(rompath)+2);

	if (!path) { fprintf(stderr, _("No memory\n")); exit(1); }

	/* If rompath is a real path, do not apply romdir to it */
	if (*romdir && !strchr(rompath, '/'))
		sprintf(path, "%s/%s", romdir, rompath);
	else
		strcpy(path, rompath);

	fprintf(stderr, _("Loading %s..."), path);

	FILE * romf = fopen(path, "r");
	if (!romf) {
		fprintf(stderr, _("Couldn't open file.\n"));
		exit(1);
	}
106
107
	rombuf += byte_off/2;
	for (i = 0; i < byte_size/2; i++, rombuf++) {
Michael Stolovitzsky's avatar
Michael Stolovitzsky committed
108
109
110
111
112
		int lobyte = getc(romf);
		int hibyte = getc(romf);
		d_word data;
		if (hibyte < 0) break;
		data = lobyte | hibyte<<8;
113
		*rombuf = data;
Michael Stolovitzsky's avatar
Michael Stolovitzsky committed
114
115
116
117
118
119
120
121
122
123
	}
	if (i < byte_size/2) {
		fprintf(stderr, _("Incomplete or damaged file.\n"));
		exit(1);
	}
	fclose(romf);
	free(path);
        fprintf(stderr, _("Done.\n"));
}

124
void
Michael Stolovitzsky's avatar
Michael Stolovitzsky committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
boot_init()
{
	static unsigned char boot_done = 0;
	if (boot_done) return;

	boot_done = 1;

	if (terak) {
		/* So far we only have Terak boot ROM */
		load_rom(0173000, "TERAK.ROM", 128, 128);
		return;
	}
	if (bkmodel != 0) {
		load_rom11(system_rom, 0, bos11rom, 8192);
		load_rom11(system_rom, 8192, diskrom, 4096);
		load_rom11(rom[0], 0, basic11arom, 16384);
		load_rom11(rom[1], 0, basic11brom, 8192);
		load_rom11(rom[1], 8192, bos11extrom, 8192);
		return;
	}

	/* Monitor must be exactly 8k */
	load_rom(0100000, rompath10, 8192, 8192);

gameblabla's avatar
gameblabla committed
149
150
	/* Basic or Focal ROM may be 24448 to 24576 bytes */
	load_rom(0120000, rompath12, 24448, 24576);
Michael Stolovitzsky's avatar
Michael Stolovitzsky committed
151
152

	/* Disk controller BIOS is exactly 4k */
gameblabla's avatar
gameblabla committed
153
	load_rom(0160000, rompath16, 4096, 4096);
Michael Stolovitzsky's avatar
Michael Stolovitzsky committed
154
}