Mercurial > repos > blastem
annotate blastcpm.c @ 900:30efd12b1be1
Replace some hard-coded instruction length assumptions with a calculation so they will work properly on both 32-bit and 64-bit hosts
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 27 Nov 2015 10:47:35 -0800 |
parents | cf6149b7c6e5 |
children | fe8c79f82c22 |
rev | line source |
---|---|
820
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <stdio.h> |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <stddef.h> |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include <string.h> |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include <sys/select.h> |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "z80_to_x86.h" |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include "util.h" |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 uint8_t ram[64 * 1024]; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 #define START_OFF 0x100 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #define OS_START 0xE400 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 #define OS_RESET 0xE403 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 int headless = 1; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 void z80_next_int_pulse(z80_context * context) |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 void render_errorbox(char *title, char *message) |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 void render_infobox(char *title, char *message) |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 void *console_write(uint32_t address, void *context, uint8_t value) |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 putchar(value); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 return context; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 uint8_t console_read(uint32_t address, void *context) |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 return getchar(); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 void *console_flush_write(uint32_t address, void *context, uint8_t value) |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 fflush(stdout); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 return context; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 uint8_t console_status_read(uint32_t address, void *context) |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 fd_set read_fds; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 FD_ZERO(&read_fds); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 struct timeval timeout; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 timeout.tv_sec = 0; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 timeout.tv_usec = 0; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 FD_SET(fileno(stdin), &read_fds); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 return select(fileno(stdin)+1, &read_fds, NULL, NULL, &timeout) > 0; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 void *exit_write(uint32_t address, void *context, uint8_t value) |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 exit(0); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 return context; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 const memmap_chunk z80_map[] = { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 { 0x0000, 0x10000, 0xFFFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, ram, NULL, NULL, NULL, NULL}, |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 }; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 const memmap_chunk io_map[] = { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 { 0x0, 0x1, 0xFFFF, 0, 0, NULL, NULL, NULL, console_read, console_write}, |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 { 0x1, 0x2, 0xFFFF, 0, 0, NULL, NULL, NULL, console_status_read, console_flush_write}, |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 { 0x2, 0x3, 0xFFFF, 0, 0, NULL, NULL, NULL, NULL, exit_write}, |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 }; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 int main(int argc, char **argv) |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 FILE *f = fopen("fake_cpm.bin", "rb"); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 long fsize = file_size(f); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 if (fsize > sizeof(ram) - OS_START) { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 fsize = sizeof(ram) - OS_START; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 if (fread(ram + OS_START, 1, fsize, f) != fsize) { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 fprintf(stderr, "Error reading from fake_cpm.bin\n"); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 exit(1); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 f = fopen(argv[1], "rb"); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 fsize = file_size(f); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 if (fsize > OS_START - START_OFF) { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 fsize = OS_START - START_OFF; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 if (fread(ram + START_OFF, 1, fsize, f) != fsize) { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 fprintf(stderr, "Error reading from file %s\n", argv[1]); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 exit(1); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 fclose(f); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 ram[0] = 0xC3; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 ram[1] = OS_RESET & 0xFF; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 ram[2] = OS_RESET >> 8; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 ram[5] = 0xC3; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 ram[6] = OS_START & 0xFF; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 ram[7] = OS_START >> 8; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 z80_options opts; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 z80_context context; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 init_z80_opts(&opts, z80_map, 1, io_map, 3, 1); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 init_z80_context(&context, &opts); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 for(;;) |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 { |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 z80_run(&context, 1000000); |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 context.current_cycle = 0; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 } |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 return 0; |
cf6149b7c6e5
Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 } |