comparison jcart.c @ 1692:5dacaef602a7 segacd

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Sat, 05 Jan 2019 00:58:08 -0800
parents 28ec17387be5
children 395f684c5379
comparison
equal deleted inserted replaced
1504:95b3a1a8b26c 1692:5dacaef602a7
1 #include "genesis.h"
2
3 static io_port *get_ports(m68k_context *m68k)
4 {
5 genesis_context *gen = m68k->system;
6 if (!gen->extra) {
7 io_port *ports = calloc(2, sizeof(io_port));
8 ports[0].device_type = IO_GAMEPAD3;
9 ports[0].device.pad.gamepad_num = 3;
10 ports[1].device_type = IO_GAMEPAD3;
11 ports[1].device.pad.gamepad_num = 4;
12 io_control_write(ports, 0x40, 0);
13 io_control_write(ports + 1, 0x40, 0);
14 gen->extra = ports;
15 }
16
17 return gen->extra;
18 }
19
20 void *jcart_write_w(uint32_t address, void *context, uint16_t value)
21 {
22 m68k_context *m68k= context;
23 io_port *ports = get_ports(m68k);
24 value = value << 6 & 0x40;
25 io_data_write(ports, value, m68k->current_cycle);
26 io_data_write(ports + 1, value, m68k->current_cycle);
27 return context;
28 }
29
30 void *jcart_write_b(uint32_t address, void *context, uint8_t value)
31 {
32 if (address & 1) {
33 return jcart_write_w(address, context, value);
34 }
35 return context;
36 }
37
38 uint16_t jcart_read_w(uint32_t address, void *context)
39 {
40 m68k_context *m68k= context;
41 io_port *ports = get_ports(m68k);
42 //according to Eke, bit 14 is forced low, at least on the Micro Machines 2 cart
43 //TODO: Test behavior of actual cart
44 uint16_t value = io_data_read(ports, m68k->current_cycle) << 8;
45 value |= io_data_read(ports + 1, m68k->current_cycle);
46 return value;
47 }
48
49 uint8_t jcart_read_b(uint32_t address, void *context)
50 {
51 m68k_context *m68k= context;
52 io_port *ports = get_ports(m68k);
53 return io_data_read(ports + (address & 1), m68k->current_cycle);
54 }
55
56 void jcart_adjust_cycles(genesis_context *context, uint32_t deduction)
57 {
58 io_port *ports = get_ports(context->m68k);
59 io_adjust_cycles(ports, context->m68k->current_cycle, deduction);
60 io_adjust_cycles(ports + 1, context->m68k->current_cycle, deduction);
61 }
62
63 void jcart_gamepad_down(genesis_context *context, uint8_t gamepad_num, uint8_t button)
64 {
65 io_port *ports = get_ports(context->m68k);
66 if (gamepad_num == ports[1].device.pad.gamepad_num) {
67 ports++;
68 } else if (gamepad_num != ports[0].device.pad.gamepad_num) {
69 ports = NULL;
70 }
71 if (ports) {
72 io_port_gamepad_down(ports, button);
73 }
74 }
75
76 void jcart_gamepad_up(genesis_context *context, uint8_t gamepad_num, uint8_t button)
77 {
78 io_port *ports = get_ports(context->m68k);
79 if (gamepad_num == ports[1].device.pad.gamepad_num) {
80 ports++;
81 } else if (gamepad_num != ports[0].device.pad.gamepad_num) {
82 ports = NULL;
83 }
84 if (ports) {
85 io_port_gamepad_up(ports, button);
86 }
87 }