summaryrefslogtreecommitdiff
path: root/emulators/pcemu/files/patch-d1-dyndisks
blob: 04f63d94a81f7be96ea250d3e5ebdc1cbeff4293 (plain) (blame)
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
31
32
33
34
35
36
37
38
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
--- bios.h.orig	Wed Jun 22 16:24:50 1994
+++ bios.h	Mon Feb 21 22:34:26 2000
@@ -22,6 +22,28 @@
 
 #define BOOT
 
+#if defined(BOOT720)
+#       define BOOTSECTORS 9
+#       define BOOTTRACKS 80
+#elif defined(BOOT1_44)
+#       define BOOTSECTORS 18
+#       define BOOTTRACKS 80
+#elif defined(BOOT1_2)
+#       define BOOTSECTORS 15
+#       define BOOTTRACKS 80
+#elif defined(BOOT360)
+#       define BOOTSECTORS 9
+#       define BOOTTRACKS 40
+#endif
+
+#ifndef BOOTFILE
+#define BOOTFILE "DriveA"
+#endif
+
+struct DiskTab;
+extern struct DiskTab *fdisk, *hdisk;
+extern int numfdisks, numhdisks;
+
 void init_bios(void);
 void init_timer(void);
 void bios_off(void);
@@ -38,5 +60,9 @@
 
 char *set_boot_file(char *);
 char *set_boot_type(int);
+char *set_floppydisk(char *buf);
+char *set_harddisk(char *buf);
+struct DiskTab *add_disk(struct DiskTab *dt, int *count, const char *fn,
+			 int s, int c, int h);
 
 #endif
--- bios.c.orig	Mon Feb 21 21:16:21 2000
+++ bios.c	Mon Feb 21 22:37:17 2000
@@ -17,6 +17,7 @@
 #include "global.h"
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <time.h>
@@ -70,50 +71,17 @@
 #define update_flag(flag, key, state) \
        if (state) flag &= ~(key); else flag |= key;
 
-#define MAXHDISKS 2
-#define MAXFDISKS 2
-
-#define NUMHDISKS 0
-#define NUMFDISKS 1
-
-typedef struct
+struct DiskTab
 {
     char *name;
     unsigned sectors;
     unsigned cylinders;
     unsigned heads;
     int fd;
-} DiskTab;
-
-#if defined(BOOT720)
-#       define BOOTSECTORS 9
-#       define BOOTTRACKS 80
-#elif defined(BOOT1_44)
-#       define BOOTSECTORS 18
-#       define BOOTTRACKS 80
-#elif defined(BOOT1_2)
-#       define BOOTSECTORS 15
-#       define BOOTTRACKS 80
-#elif defined(BOOT360)
-#       define BOOTSECTORS 9
-#       define BOOTTRACKS 40
-#endif
-
-#ifndef BOOTFILE
-#define BOOTFILE "DriveA"
-#endif
-
-DiskTab fdisk[MAXFDISKS] =
-{
-{ BOOTFILE, BOOTSECTORS, BOOTTRACKS, 2 },
-{ "/dev/fd0", 18, 80, 2 }
 };
 
-DiskTab hdisk[MAXHDISKS] =
-{
-{ "/dev/wd0", 63, 407, 64 },
-{ "/some/file", 32, 120, 64 },
-};
+struct DiskTab *fdisk, *hdisk;
+int numfdisks, numhdisks;
 
 int bootdisk = 0x0;
 static unsigned pos = INT_ROUTINE_START;
@@ -133,7 +101,7 @@
 static unsigned num = 0;
 
 struct vm86_struct vm86s;
-char tmpdir[] = "/usr/tmp";
+char tmpdir[] = "/var/tmp";
 
 #include "keytabs.h"
 
@@ -207,6 +175,54 @@
     PutMemW(memory,4*intno+2,seg);
 }
 
+struct DiskTab *add_disk(struct DiskTab *dt, int *count, const char *fn,
+			 int s, int c, int h)
+{
+	struct DiskTab *newdt;
+	int newcount;
+
+	newcount = ++(*count);
+	if ((newdt = realloc(dt, sizeof(struct DiskTab) * newcount)) == 0) {
+	  bailout:
+		fprintf(stderr,
+			"Warning: Insufficient memory to add %s to disktab\n",
+			fn);
+		(*count)--;
+		return dt;
+	}
+	newcount--;
+	if ((newdt[newcount].name = strdup(fn)) == 0)
+		goto bailout;
+	newdt[newcount].sectors = s;
+	newdt[newcount].cylinders = c;
+	newdt[newcount].heads = h;
+
+	return newdt;
+}
+
+char *set_floppydisk(char *buf)
+{
+	char fname[1024];	/* sufficient, read_pcemurc() only has 1024 */
+	int ncyl, nhead, nsec;
+	
+	if(sscanf(buf, " %*s %s %d %d %d", fname, &nsec, &ncyl, &nhead) != 4)
+		return "usage: floppydisk <filename> <nsec> <ncyl> <nhead>";
+	fdisk = add_disk(fdisk, &numfdisks, fname, nsec, ncyl, nhead);
+
+	return 0;
+}
+
+char *set_harddisk(char *buf)
+{
+	char fname[1024];	/* sufficient, read_pcemurc() only has 1024 */
+	int ncyl, nhead, nsec;
+	
+	if(sscanf(buf, " %*s %s %d %d %d", fname, &nsec, &ncyl, &nhead) != 4)
+		return "usage: harddisk <filename> <nsec> <ncyl> <nhead>";
+	hdisk = add_disk(hdisk, &numhdisks, fname, nsec, ncyl, nhead);
+
+	return 0;
+}
 
 static void int_serial(void)
 {
@@ -807,16 +823,16 @@
 }
 
 
-static DiskTab *get_disk_tab(int num)
+static struct DiskTab *get_disk_tab(int num)
 {
-    if (num >= 0    && num < NUMFDISKS)
+    if (num >= 0    && num < numfdisks)
         return &fdisk[num];
-    if (num >= 0x80 && num < 0x80 + NUMHDISKS)
+    if (num >= 0x80 && num < 0x80 + numhdisks)
 	return &hdisk[num&0x7f];
     return NULL;
 }
 
-static int disk_seek(DiskTab *disk, int cylinder, int head, int sector)
+static int disk_seek(struct DiskTab *disk, int cylinder, int head, int sector)
 {
     unsigned pos;
 
@@ -845,7 +861,7 @@
 {
     int head, sector, cylinder, res, num;
     BYTE *buffer;
-    DiskTab *disk;
+    struct DiskTab *disk;
 
     res = 0;
 
@@ -970,7 +986,7 @@
                                                  & 0x300) >> 2);
             *bregs[DH] = (disk->heads -1) | (((disk->cylinders - 1)
 					     & 0xc00)>> 4);
-            *bregs[DL] = *bregs[DL]  < 0x80 ? NUMFDISKS : NUMHDISKS;
+            *bregs[DL] = *bregs[DL]  < 0x80 ? numfdisks : numhdisks;
             *bregs[AL] = 0;
             CF = 0;
         }
@@ -1182,8 +1198,8 @@
 
     memory[0xf0000+0xfffe] = SYSTEMID;
 
-    if (NUMFDISKS > 0)
-        equip |= (1 | ((NUMFDISKS-1) << 6));
+    if (numfdisks > 0)
+        equip |= (1 | ((numfdisks-1) << 6));
     equip |= mono ? 0x30 : 0x20;
 
 
@@ -1199,7 +1215,7 @@
     PutMemB(data_segment, 0x40, 0);
     PutMemB(data_segment, 0x41, 0);
     PutMemW(data_segment, 0x72, 0x1234);
-    PutMemW(data_segment, 0x75, NUMHDISKS);
+    PutMemW(data_segment, 0x75, numhdisks);
     PutMemW(data_segment, 0x96, 16);            /* 101/102 keyboard */
     PutMemB(data_segment, 0x17, NUMLOCK);
 
@@ -1251,12 +1267,12 @@
 void init_bios(void)
 {
     int i;
-    DiskTab *hd;
+    struct DiskTab *hd;
 #ifdef BOOT
-    DiskTab *boot;
+    struct DiskTab *boot;
 #endif
 
-    for (i = 0; i < NUMHDISKS; i++)
+    for (i = 0; i < numhdisks; i++)
     {
         if ((hdisk[i].fd = open(hdisk[i].name,O_RDWR)) < 0)
         {
@@ -1265,7 +1281,7 @@
             exit(1);
         }
     }
-    for (i = 0; i < NUMFDISKS; i++)
+    for (i = 0; i < numfdisks; i++)
     {
         if ((fdisk[i].fd = open(fdisk[i].name,O_RDWR)) < 0)
         {
@@ -1341,11 +1357,6 @@
 }
 
 
-char *set_hd(char *file, int hd)
-{
-}
-
-
 char *set_boot_type(int type)
 {
     fdisk[0].heads = 2;
@@ -1379,7 +1390,9 @@
 void bios_off(void)
 {
   int i;
-    
-   for (i = 0; i < NUMHDISKS; i++)
+
+  for (i = 0; i < numhdisks; i++)
        close(hdisk[i].fd);
+  for (i = 0; i < numfdisks; i++)
+       close(fdisk[i].fd);
 }
--- main.c.orig	Mon Feb 21 21:04:45 2000
+++ main.c	Mon Feb 21 22:28:47 2000
@@ -103,6 +103,10 @@
             check_error(set_cursor_rate(strtol(value, NULL,10)), line);
 	else if (strcasecmp(keyword,"keymap") == 0)
 		check_error(set_keymap(buffer), line);
+	else if (strcasecmp(keyword,"floppydisk") == 0)
+		check_error(set_floppydisk(buffer), line);
+	else if (strcasecmp(keyword,"harddisk") == 0)
+		check_error(set_harddisk(buffer), line);
         else
             check_error("Syntax error in .pcemu file", line);
     }
@@ -110,7 +114,7 @@
 }           
 
 
-void main(int argc, char **argv)
+int main(int argc, char **argv)
 {
     progname = (progname = strrchr(argv[0],'/')) ? progname : argv[0];
 
@@ -140,6 +144,9 @@
     fread(memory+0x800,1,MEMORY_SIZE-0x800,f1);
     fclose(f1);
 #endif
+
+    /* this needs to be done before parsing .pcemurc */
+    fdisk = add_disk(fdisk, &numfdisks, BOOTFILE, BOOTSECTORS, BOOTTRACKS, 2);
 
     read_pcemurc();
     disable();