Mercurial > repos > blastem
annotate blastcpm.c @ 1971:80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 08 May 2020 11:40:30 -0700 |
parents | 95e36a227c9d |
children | 8fe162bdb038 a66916828c9b |
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> |
1760
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
5 #include <time.h> |
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
|
6 #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
|
7 |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
8 #ifdef NEW_CORE |
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
9 #include "z80.h" |
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
10 #else |
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
|
11 #include "z80_to_x86.h" |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
12 #endif |
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
|
13 #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
|
14 |
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 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
|
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 #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
|
18 #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
|
19 #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
|
20 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
|
21 |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
22 #ifndef NEW_CORE |
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
|
23 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
|
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 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
|
26 } |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
27 #endif |
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
|
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 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
|
30 { |
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 |
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 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
|
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 |
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 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
|
38 { |
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 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
|
40 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
|
41 } |
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 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
|
44 { |
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 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
|
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 |
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 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
|
49 { |
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 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
|
51 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
|
52 } |
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 |
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 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
|
55 { |
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 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
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 |
1760
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
65 time_t start; |
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
66 uint64_t total_cycles; |
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
|
67 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
|
68 { |
1760
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
69 time_t duration = time(NULL) - start; |
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
70 z80_context *z80 = context; |
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
71 #ifdef NEW_CORE |
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
72 total_cycles += z80->cycles; |
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
73 #else |
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
74 total_cycles += context->current_cycle; |
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
75 #endif |
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
76 printf("Effective clock speed: %f MHz\n", ((double)total_cycles) / (1000000.0 * duration)); |
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
|
77 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
|
78 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
|
79 } |
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 const memmap_chunk z80_map[] = { |
1130
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
82 { 0x0000, 0x10000, 0xFFFF, 0, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, ram, NULL, NULL, NULL, NULL}, |
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
|
83 }; |
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 |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
85 memmap_chunk io_map[] = { |
1130
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
86 { 0x0, 0x1, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, console_read, console_write}, |
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
87 { 0x1, 0x2, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, console_status_read, console_flush_write}, |
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
88 { 0x2, 0x3, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, NULL, exit_write}, |
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
|
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 |
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 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
|
92 { |
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 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
|
94 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
|
95 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
|
96 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
|
97 } |
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 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
|
99 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
|
100 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
|
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 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
|
103 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
|
104 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
|
105 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
|
106 } |
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 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
|
108 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
|
109 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
|
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 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 |
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
|
119 z80_options opts; |
1130
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
120 z80_context *context; |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
820
diff
changeset
|
121 init_z80_opts(&opts, z80_map, 1, io_map, 3, 1, 0xFF); |
1130
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
122 context = init_z80_context(&opts); |
1760
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
123 start = time(NULL); |
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
|
124 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
|
125 { |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
126 #ifdef NEW_CORE |
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
127 z80_execute(context, 1000000); |
1760
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
128 total_cycles += context->cycles; |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
129 context->cycles = 0; |
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
130 #else |
1130
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
131 z80_run(context, 1000000); |
1760
95e36a227c9d
Add emulated MHz output to blastcpm
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
132 total_cycles += context->current_cycle; |
1130
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
133 context->current_cycle = 0; |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
134 #endif |
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
135 |
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
|
136 } |
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
|
137 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
|
138 } |