annotate stateview.c @ 619:3072fb746601

Added support for JR and JRcc in Z80 test generator
author Michael Pavone <pavone@retrodev.com>
date Mon, 29 Dec 2014 21:36:17 -0800
parents 140af5509ce7
children 6e751a8f46aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 465
diff changeset
1 /*
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 465
diff changeset
2 Copyright 2013 Michael Pavone
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 465
diff changeset
3 This file is part of BlastEm.
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 465
diff changeset
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 465
diff changeset
5 */
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include <stdlib.h>
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 #include <stdio.h>
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include "vdp.h"
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 #include "render.h"
75
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
10 #include "blastem.h"
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
11
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
12 //not used, but referenced by the renderer since it handles input
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
13 io_port gamepad_1;
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
14 io_port gamepad_2;
465
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
15 uint8_t reset = 1;
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
16 uint8_t busreq = 0;
75
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
17
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
18 uint16_t read_dma_value(uint32_t address)
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
19 {
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
20 return 0;
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
21 }
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
22
465
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
23 void ym_data_write(ym2612_context * context, uint8_t value)
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
24 {
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
25 }
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
26
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
27 void ym_address_write_part1(ym2612_context * context, uint8_t address)
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
28 {
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
29 }
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
30
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
31 void ym_address_write_part2(ym2612_context * context, uint8_t address)
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
32 {
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
33 }
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
34
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
35 void handle_keydown(int keycode)
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
36 {
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
37 }
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
38
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
39 void handle_keyup(int keycode)
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
40 {
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
41 }
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
42
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
43 void handle_joydown(int joystick, int button)
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
44 {
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
45 }
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
46
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
47 void handle_joyup(int joystick, int button)
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
48 {
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
49 }
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
50
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
51 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value)
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
52 {
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
53 }
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
54
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
55 tern_node * config;
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
56
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57 int main(int argc, char ** argv)
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 if (argc < 2) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60 fprintf(stderr, "Usage: stateview FILENAME\n");
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61 exit(1);
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
62 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 FILE * state_file = fopen(argv[1], "rb");
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
64 if (!state_file) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 fprintf(stderr, "Failed to open %s\n", argv[1]);
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 exit(1);
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 }
465
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
68 config = load_config(argv[0]);
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
69 int width = -1;
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
70 int height = -1;
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
71 if (argc > 2) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
72 width = atoi(argv[2]);
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
73 if (argc > 3) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
74 height = atoi(argv[3]);
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
75 }
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
76 }
465
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
77 int def_width = 0;
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
78 char *config_width = tern_find_ptr(config, "videowidth");
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
79 if (config_width) {
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
80 def_width = atoi(config_width);
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
81 }
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
82 if (!def_width) {
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
83 def_width = 640;
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
84 }
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
85 width = width < 320 ? def_width : width;
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
86 height = height < 240 ? (width/320) * 240 : height;
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
87
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 vdp_context context;
465
dc322bc77ea2 Fix stateview. Update "all" target in Makefile.
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
89 render_init(width, height, "GST State Viewer", 60, 0);
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 init_vdp_context(&context);
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 322
diff changeset
91 vdp_load_gst(&context, state_file);
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
92 vdp_run_to_vblank(&context);
322
8e2fa485c0f2 Remove z80_ram reference in SDL renderer to get stateview compiling again. Print out the sprite list in stateview.
Mike Pavone <pavone@retrodev.com>
parents: 75
diff changeset
93 vdp_print_sprite_table(&context);
75
108e587165c0 Implement DMA (untested)
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
94 printf("Display %s\n", (context.regs[REG_MODE_2] & DISPLAY_ENABLE) ? "enabled" : "disabled");
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95 render_context(&context);
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
96 render_wait_quit(&context);
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
97 return 0;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
98 }