Mercurial > repos > blastem
comparison blastem.c @ 215:2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 19 Apr 2013 21:36:00 -0700 |
parents | 464513050c85 |
children | 625f8e4d5fd2 |
comparison
equal
deleted
inserted
replaced
214:9126c33cc33c | 215:2b1c2c28b261 |
---|---|
21 uint8_t z80_ram[Z80_RAM_BYTES]; | 21 uint8_t z80_ram[Z80_RAM_BYTES]; |
22 | 22 |
23 io_port gamepad_1; | 23 io_port gamepad_1; |
24 io_port gamepad_2; | 24 io_port gamepad_2; |
25 | 25 |
26 int headless = 0; | |
27 | |
26 #ifndef MIN | 28 #ifndef MIN |
27 #define MIN(a,b) ((a) < (b) ? (a) : (b)) | 29 #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
28 #endif | 30 #endif |
29 | 31 |
30 #define SMD_HEADER_SIZE 512 | 32 #define SMD_HEADER_SIZE 512 |
126 vdp_context * v_context = context->next_context; | 128 vdp_context * v_context = context->next_context; |
127 uint32_t mclks = context->current_cycle * MCLKS_PER_68K; | 129 uint32_t mclks = context->current_cycle * MCLKS_PER_68K; |
128 if (mclks >= MCLKS_PER_FRAME) { | 130 if (mclks >= MCLKS_PER_FRAME) { |
129 //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, mclks); | 131 //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, mclks); |
130 vdp_run_context(v_context, MCLKS_PER_FRAME); | 132 vdp_run_context(v_context, MCLKS_PER_FRAME); |
131 break_on_sync |= wait_render_frame(v_context); | 133 if (!headless) { |
134 break_on_sync |= wait_render_frame(v_context); | |
135 } | |
132 mclks -= MCLKS_PER_FRAME; | 136 mclks -= MCLKS_PER_FRAME; |
133 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME); | 137 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME); |
134 io_adjust_cycles(&gamepad_1, context->current_cycle, MCLKS_PER_FRAME/MCLKS_PER_68K); | 138 io_adjust_cycles(&gamepad_1, context->current_cycle, MCLKS_PER_FRAME/MCLKS_PER_68K); |
135 io_adjust_cycles(&gamepad_2, context->current_cycle, MCLKS_PER_FRAME/MCLKS_PER_68K); | 139 io_adjust_cycles(&gamepad_2, context->current_cycle, MCLKS_PER_FRAME/MCLKS_PER_68K); |
136 context->current_cycle -= MCLKS_PER_FRAME/MCLKS_PER_68K; | 140 context->current_cycle -= MCLKS_PER_FRAME/MCLKS_PER_68K; |
159 if (vdp_port < 4) { | 163 if (vdp_port < 4) { |
160 while (vdp_data_port_write(v_context, value) < 0) { | 164 while (vdp_data_port_write(v_context, value) < 0) { |
161 while(v_context->flags & FLAG_DMA_RUN) { | 165 while(v_context->flags & FLAG_DMA_RUN) { |
162 vdp_run_dma_done(v_context, MCLKS_PER_FRAME); | 166 vdp_run_dma_done(v_context, MCLKS_PER_FRAME); |
163 if (v_context->cycles >= MCLKS_PER_FRAME) { | 167 if (v_context->cycles >= MCLKS_PER_FRAME) { |
164 wait_render_frame(v_context); | 168 if (!headless) { |
169 wait_render_frame(v_context); | |
170 } | |
165 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME); | 171 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME); |
166 io_adjust_cycles(&gamepad_1, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K); | 172 io_adjust_cycles(&gamepad_1, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K); |
167 io_adjust_cycles(&gamepad_2, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K); | 173 io_adjust_cycles(&gamepad_2, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K); |
168 } | 174 } |
169 } | 175 } |
174 if (blocked) { | 180 if (blocked) { |
175 while (blocked) { | 181 while (blocked) { |
176 while(v_context->flags & FLAG_DMA_RUN) { | 182 while(v_context->flags & FLAG_DMA_RUN) { |
177 vdp_run_dma_done(v_context, MCLKS_PER_FRAME); | 183 vdp_run_dma_done(v_context, MCLKS_PER_FRAME); |
178 if (v_context->cycles >= MCLKS_PER_FRAME) { | 184 if (v_context->cycles >= MCLKS_PER_FRAME) { |
179 wait_render_frame(v_context); | 185 if (!headless) { |
186 wait_render_frame(v_context); | |
187 } | |
180 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME); | 188 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME); |
181 io_adjust_cycles(&gamepad_1, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K); | 189 io_adjust_cycles(&gamepad_1, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K); |
182 io_adjust_cycles(&gamepad_2, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K); | 190 io_adjust_cycles(&gamepad_2, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K); |
183 } | 191 } |
184 } | 192 } |
846 debug = 1; | 854 debug = 1; |
847 break; | 855 break; |
848 case 'l': | 856 case 'l': |
849 address_log = fopen("address.log", "w"); | 857 address_log = fopen("address.log", "w"); |
850 break; | 858 break; |
859 case 'v': | |
860 headless = 1; | |
861 break; | |
851 default: | 862 default: |
852 fprintf(stderr, "Unrecognized switch %s\n", argv[i]); | 863 fprintf(stderr, "Unrecognized switch %s\n", argv[i]); |
853 return 1; | 864 return 1; |
854 } | 865 } |
855 } else if (width < 0) { | 866 } else if (width < 0) { |
858 height = atoi(argv[i]); | 869 height = atoi(argv[i]); |
859 } | 870 } |
860 } | 871 } |
861 width = width < 320 ? 320 : width; | 872 width = width < 320 ? 320 : width; |
862 height = height < 240 ? (width/320) * 240 : height; | 873 height = height < 240 ? (width/320) * 240 : height; |
863 render_init(width, height); | 874 if (!headless) { |
875 render_init(width, height); | |
876 } | |
864 vdp_context v_context; | 877 vdp_context v_context; |
865 | 878 |
866 init_vdp_context(&v_context); | 879 init_vdp_context(&v_context); |
867 init_run_cpu(&v_context, debug, address_log); | 880 init_run_cpu(&v_context, debug, address_log); |
868 return 0; | 881 return 0; |