annotate jcart.c @ 1921:5d028088e320

Added help commands to debugger
author Eric Fry <yuv422@users.noreply.github.com>
date Fri, 10 Apr 2020 13:30:16 +1000
parents 395f684c5379
children d74d3998482c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1688
395f684c5379 Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1612
diff changeset
1 #include <stdlib.h>
1610
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include "genesis.h"
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 static io_port *get_ports(m68k_context *m68k)
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 genesis_context *gen = m68k->system;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 if (!gen->extra) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 io_port *ports = calloc(2, sizeof(io_port));
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 ports[0].device_type = IO_GAMEPAD3;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 ports[0].device.pad.gamepad_num = 3;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 ports[1].device_type = IO_GAMEPAD3;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 ports[1].device.pad.gamepad_num = 4;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 io_control_write(ports, 0x40, 0);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 io_control_write(ports + 1, 0x40, 0);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 gen->extra = ports;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 return gen->extra;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 void *jcart_write_w(uint32_t address, void *context, uint16_t value)
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 m68k_context *m68k= context;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 io_port *ports = get_ports(m68k);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 value = value << 6 & 0x40;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 io_data_write(ports, value, m68k->current_cycle);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 io_data_write(ports + 1, value, m68k->current_cycle);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 return context;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 void *jcart_write_b(uint32_t address, void *context, uint8_t value)
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 if (address & 1) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 return jcart_write_w(address, context, value);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 return context;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 uint16_t jcart_read_w(uint32_t address, void *context)
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 m68k_context *m68k= context;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 io_port *ports = get_ports(m68k);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 //according to Eke, bit 14 is forced low, at least on the Micro Machines 2 cart
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 //TODO: Test behavior of actual cart
1612
28ec17387be5 Remove stray / in jcart.c
Michael Pavone <pavone@retrodev.com>
parents: 1610
diff changeset
45 uint16_t value = io_data_read(ports, m68k->current_cycle) << 8;
1610
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 value |= io_data_read(ports + 1, m68k->current_cycle);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 return value;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 uint8_t jcart_read_b(uint32_t address, void *context)
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 m68k_context *m68k= context;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 io_port *ports = get_ports(m68k);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 return io_data_read(ports + (address & 1), m68k->current_cycle);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 void jcart_adjust_cycles(genesis_context *context, uint32_t deduction)
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 io_port *ports = get_ports(context->m68k);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 io_adjust_cycles(ports, context->m68k->current_cycle, deduction);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 io_adjust_cycles(ports + 1, context->m68k->current_cycle, deduction);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 void jcart_gamepad_down(genesis_context *context, uint8_t gamepad_num, uint8_t button)
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 io_port *ports = get_ports(context->m68k);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 if (gamepad_num == ports[1].device.pad.gamepad_num) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 ports++;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 } else if (gamepad_num != ports[0].device.pad.gamepad_num) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 ports = NULL;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 if (ports) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 io_port_gamepad_down(ports, button);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 void jcart_gamepad_up(genesis_context *context, uint8_t gamepad_num, uint8_t button)
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 io_port *ports = get_ports(context->m68k);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 if (gamepad_num == ports[1].device.pad.gamepad_num) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 ports++;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 } else if (gamepad_num != ports[0].device.pad.gamepad_num) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 ports = NULL;
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 if (ports) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 io_port_gamepad_up(ports, button);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 }
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 }