comparison blastcpm.c @ 2053:3414a4423de1 segacd

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Sat, 15 Jan 2022 13:15:21 -0800
parents 95e36a227c9d
children 8fe162bdb038 a66916828c9b
comparison
equal deleted inserted replaced
1692:5dacaef602a7 2053:3414a4423de1
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <stddef.h> 3 #include <stddef.h>
4 #include <string.h> 4 #include <string.h>
5 #include <time.h>
5 #include <sys/select.h> 6 #include <sys/select.h>
6 7
8 #ifdef NEW_CORE
9 #include "z80.h"
10 #else
7 #include "z80_to_x86.h" 11 #include "z80_to_x86.h"
12 #endif
8 #include "util.h" 13 #include "util.h"
9 14
10 uint8_t ram[64 * 1024]; 15 uint8_t ram[64 * 1024];
11 16
12 #define START_OFF 0x100 17 #define START_OFF 0x100
13 #define OS_START 0xE400 18 #define OS_START 0xE400
14 #define OS_RESET 0xE403 19 #define OS_RESET 0xE403
15 int headless = 1; 20 int headless = 1;
16 21
22 #ifndef NEW_CORE
17 void z80_next_int_pulse(z80_context * context) 23 void z80_next_int_pulse(z80_context * context)
18 { 24 {
19 context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER; 25 context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER;
20 } 26 }
27 #endif
21 28
22 void render_errorbox(char *title, char *message) 29 void render_errorbox(char *title, char *message)
23 { 30 {
24 } 31 }
25 32
53 timeout.tv_usec = 0; 60 timeout.tv_usec = 0;
54 FD_SET(fileno(stdin), &read_fds); 61 FD_SET(fileno(stdin), &read_fds);
55 return select(fileno(stdin)+1, &read_fds, NULL, NULL, &timeout) > 0; 62 return select(fileno(stdin)+1, &read_fds, NULL, NULL, &timeout) > 0;
56 } 63 }
57 64
65 time_t start;
66 uint64_t total_cycles;
58 void *exit_write(uint32_t address, void *context, uint8_t value) 67 void *exit_write(uint32_t address, void *context, uint8_t value)
59 { 68 {
69 time_t duration = time(NULL) - start;
70 z80_context *z80 = context;
71 #ifdef NEW_CORE
72 total_cycles += z80->cycles;
73 #else
74 total_cycles += context->current_cycle;
75 #endif
76 printf("Effective clock speed: %f MHz\n", ((double)total_cycles) / (1000000.0 * duration));
60 exit(0); 77 exit(0);
61 return context; 78 return context;
62 } 79 }
63 80
64 const memmap_chunk z80_map[] = { 81 const memmap_chunk z80_map[] = {
65 { 0x0000, 0x10000, 0xFFFF, 0, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, ram, NULL, NULL, NULL, NULL}, 82 { 0x0000, 0x10000, 0xFFFF, 0, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, ram, NULL, NULL, NULL, NULL},
66 }; 83 };
67 84
68 const memmap_chunk io_map[] = { 85 memmap_chunk io_map[] = {
69 { 0x0, 0x1, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, console_read, console_write}, 86 { 0x0, 0x1, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, console_read, console_write},
70 { 0x1, 0x2, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, console_status_read, console_flush_write}, 87 { 0x1, 0x2, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, console_status_read, console_flush_write},
71 { 0x2, 0x3, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, NULL, exit_write}, 88 { 0x2, 0x3, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, NULL, exit_write},
72 }; 89 };
73 90
101 118
102 z80_options opts; 119 z80_options opts;
103 z80_context *context; 120 z80_context *context;
104 init_z80_opts(&opts, z80_map, 1, io_map, 3, 1, 0xFF); 121 init_z80_opts(&opts, z80_map, 1, io_map, 3, 1, 0xFF);
105 context = init_z80_context(&opts); 122 context = init_z80_context(&opts);
123 start = time(NULL);
106 for(;;) 124 for(;;)
107 { 125 {
126 #ifdef NEW_CORE
127 z80_execute(context, 1000000);
128 total_cycles += context->cycles;
129 context->cycles = 0;
130 #else
108 z80_run(context, 1000000); 131 z80_run(context, 1000000);
132 total_cycles += context->current_cycle;
109 context->current_cycle = 0; 133 context->current_cycle = 0;
134 #endif
135
110 } 136 }
111 return 0; 137 return 0;
112 } 138 }