comparison blastcpm.c @ 1760:95e36a227c9d

Add emulated MHz output to blastcpm
author Michael Pavone <pavone@retrodev.com>
date Tue, 19 Feb 2019 22:51:53 -0800
parents 48a43dff4dc0
children 8fe162bdb038 a66916828c9b
comparison
equal deleted inserted replaced
1759:6e4faa10f9ee 1760:95e36a227c9d
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
7 #ifdef NEW_CORE 8 #ifdef NEW_CORE
8 #include "z80.h" 9 #include "z80.h"
9 #else 10 #else
59 timeout.tv_usec = 0; 60 timeout.tv_usec = 0;
60 FD_SET(fileno(stdin), &read_fds); 61 FD_SET(fileno(stdin), &read_fds);
61 return select(fileno(stdin)+1, &read_fds, NULL, NULL, &timeout) > 0; 62 return select(fileno(stdin)+1, &read_fds, NULL, NULL, &timeout) > 0;
62 } 63 }
63 64
65 time_t start;
66 uint64_t total_cycles;
64 void *exit_write(uint32_t address, void *context, uint8_t value) 67 void *exit_write(uint32_t address, void *context, uint8_t value)
65 { 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));
66 exit(0); 77 exit(0);
67 return context; 78 return context;
68 } 79 }
69 80
70 const memmap_chunk z80_map[] = { 81 const memmap_chunk z80_map[] = {
107 118
108 z80_options opts; 119 z80_options opts;
109 z80_context *context; 120 z80_context *context;
110 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);
111 context = init_z80_context(&opts); 122 context = init_z80_context(&opts);
123 start = time(NULL);
112 for(;;) 124 for(;;)
113 { 125 {
114 #ifdef NEW_CORE 126 #ifdef NEW_CORE
115 z80_execute(context, 1000000); 127 z80_execute(context, 1000000);
128 total_cycles += context->cycles;
116 context->cycles = 0; 129 context->cycles = 0;
117 #else 130 #else
118 z80_run(context, 1000000); 131 z80_run(context, 1000000);
132 total_cycles += context->current_cycle;
119 context->current_cycle = 0; 133 context->current_cycle = 0;
120 #endif 134 #endif
121 135
122 } 136 }
123 return 0; 137 return 0;