comparison debug.c @ 2422:1978bd770023

Expose gamepad state in debugger
author Michael Pavone <pavone@retrodev.com>
date Sat, 20 Jan 2024 21:15:56 -0800
parents 64cf80e683aa
children cb62730d5c99
comparison
equal deleted inserted replaced
2421:bcfa5e272f5e 2422:1978bd770023
2034 2034
2035 new_readonly_variable(root, "frequency", new_fixed_array(psg, debug_psgfreq_get, debug_psgfreq_set, 4)); 2035 new_readonly_variable(root, "frequency", new_fixed_array(psg, debug_psgfreq_get, debug_psgfreq_set, 4));
2036 new_readonly_variable(root, "counter", new_fixed_array(psg, debug_psgcount_get, debug_psgcount_set, 4)); 2036 new_readonly_variable(root, "counter", new_fixed_array(psg, debug_psgcount_get, debug_psgcount_set, 4));
2037 new_readonly_variable(root, "volume", new_fixed_array(psg, debug_psgvol_get, debug_psgvol_set, 4)); 2037 new_readonly_variable(root, "volume", new_fixed_array(psg, debug_psgvol_get, debug_psgvol_set, 4));
2038 2038
2039 return root;
2040 }
2041
2042 static debug_val debug_iopad_get(debug_array *array, uint32_t index)
2043 {
2044 io_port *port = find_gamepad(array->base, index + 1);
2045 uint32_t ret = 0;
2046 if (port) {
2047 ret |= port->input[1];
2048 ret |= port->input[0] << 2 & 0xC0;
2049 ret |= port->input[2] << 8 & 0xF00;
2050 }
2051 return debug_int(ret);
2052 }
2053
2054 static void debug_iopad_set(debug_array *array, uint32_t index, debug_val val)
2055 {
2056 uint32_t ival;
2057 if (!debug_cast_int(val, &ival)) {
2058 fprintf(stderr, "pad state can only be set to integers\n");
2059 return;
2060 }
2061 io_port *port = find_gamepad(array->base, index + 1);
2062 if (port) {
2063 port->input[1] &= ~0x3F;
2064 port->input[1] |= ival & 0x3F;
2065 port->input[0] &= ~0x33;
2066 port->input[0] |= ival & 0x3;
2067 port->input[0] |= ival >> 2 & 0x30;
2068 port->input[2] &= ~0xF;
2069 port->input[2] |= ival >> 8 & 0xF;
2070 }
2071 }
2072
2073 debug_root *find_io_root(sega_io *io)
2074 {
2075 debug_root *root = find_root(io);
2076
2077 new_readonly_variable(root, "pads", new_fixed_array(io, debug_iopad_get, debug_iopad_set, MAX_JOYSTICKS));
2078
2039 return root; 2079 return root;
2040 } 2080 }
2041 2081
2042 void ambiguous_iter(char *key, tern_val val, uint8_t valtype, void *data) 2082 void ambiguous_iter(char *key, tern_val val, uint8_t valtype, void *data)
2043 { 2083 {
4795 genesis_context *gen = context->system; 4835 genesis_context *gen = context->system;
4796 root->other_roots = tern_insert_ptr(root->other_roots, "z80", find_z80_root(gen->z80)); 4836 root->other_roots = tern_insert_ptr(root->other_roots, "z80", find_z80_root(gen->z80));
4797 root->other_roots = tern_insert_ptr(root->other_roots, "vdp", find_vdp_root(gen->vdp)); 4837 root->other_roots = tern_insert_ptr(root->other_roots, "vdp", find_vdp_root(gen->vdp));
4798 root->other_roots = tern_insert_ptr(root->other_roots, "ym", find_ym2612_root(gen->ym)); 4838 root->other_roots = tern_insert_ptr(root->other_roots, "ym", find_ym2612_root(gen->ym));
4799 root->other_roots = tern_insert_ptr(root->other_roots, "psg", find_psg_root(gen->psg)); 4839 root->other_roots = tern_insert_ptr(root->other_roots, "psg", find_psg_root(gen->psg));
4840 root->other_roots = tern_insert_ptr(root->other_roots, "io", find_io_root(&gen->io));
4800 add_commands(root, genesis_commands, NUM_GENESIS); 4841 add_commands(root, genesis_commands, NUM_GENESIS);
4801 var = calloc(1, sizeof(debug_var)); 4842 var = calloc(1, sizeof(debug_var));
4802 var->get = debug_frame_get; 4843 var->get = debug_frame_get;
4803 var->ptr = gen->vdp; 4844 var->ptr = gen->vdp;
4804 root->variables = tern_insert_ptr(root->variables, "frame", var); 4845 root->variables = tern_insert_ptr(root->variables, "frame", var);