Mercurial > repos > blastem
annotate io.c @ 2688:b42f00a3a937 default tip
Fix default target. Ensure m68k.h and z80.h are built before anything else when no dep info is available
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 31 Mar 2025 21:06:18 -0700 |
parents | 462e43f54abf |
children |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
2 Copyright 2013 Michael Pavone |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
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:
451
diff
changeset
|
5 */ |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
6 #ifndef _WIN32 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
7 #include <unistd.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
8 #include <fcntl.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
9 #include <sys/socket.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
10 #include <sys/un.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
11 #include <sys/types.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
12 #include <sys/stat.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
13 #include <errno.h> |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
14 #endif |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
15 #include <string.h> |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
16 #include <stdlib.h> |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
17 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
18 #include "serialize.h" |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 #include "io.h" |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 #include "blastem.h" |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 #include "render.h" |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
22 #include "util.h" |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
23 #include "bindings.h" |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
25 #define CYCLE_NEVER 0xFFFFFFFF |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
26 #define MIN_POLL_INTERVAL 6840 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
27 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
28 const char * device_type_names[] = { |
1650
d6c403135e64
Re-order IO device type enum so "None" is selected when no device is specified for a port
Michael Pavone <pavone@retrodev.com>
parents:
1610
diff
changeset
|
29 "None", |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
30 "SMS gamepad", |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
31 "3-button gamepad", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
32 "6-button gamepad", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
33 "Mega Mouse", |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
34 "Saturn Keyboard", |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
35 "XBAND Keyboard", |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
36 "Menacer", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
37 "Justifier", |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
38 "Sega Multi-tap", |
2238
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
39 "EA 4-way Play", |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
40 "EA 4-way Play", |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
41 "Sega Parallel Transfer Board", |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
42 "Generic Device", |
2027
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
43 "Generic Serial", |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
44 "Heartbeat Personal Trainer" |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
45 }; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
46 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
47 #define GAMEPAD_TH0 0 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
48 #define GAMEPAD_TH1 1 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
49 #define GAMEPAD_EXTRA 2 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
50 #define GAMEPAD_NONE 0xF |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
52 #define IO_TH0 0 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
53 #define IO_TH1 1 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
54 #define IO_STATE 2 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
56 enum { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
57 IO_WRITE_PENDING, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
58 IO_WRITTEN, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
59 IO_READ_PENDING, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
60 IO_READ |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
61 }; |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
62 |
2027
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
63 enum { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
64 HBPT_NEED_INIT, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
65 HBPT_IDLE, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
66 HBPT_CMD_PAYLOAD, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
67 HBPT_REPLY |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
68 }; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
69 |
2238
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
70 #define EA_PASSTHRU_MODE 0xFF |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
71 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
72 typedef struct { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
73 uint8_t states[2], value; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
74 } gp_button_def; |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
75 |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
76 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
77 static gp_button_def button_defs[NUM_GAMEPAD_BUTTONS] = { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
78 [DPAD_UP] = {.states = {GAMEPAD_TH0, GAMEPAD_TH1}, .value = 0x1}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
79 [DPAD_DOWN] = {.states = {GAMEPAD_TH0, GAMEPAD_TH1}, .value = 0x2}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
80 [DPAD_LEFT] = {.states = {GAMEPAD_TH1, GAMEPAD_NONE}, .value = 0x4}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
81 [DPAD_RIGHT] = {.states = {GAMEPAD_TH1, GAMEPAD_NONE}, .value = 0x8}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
82 [BUTTON_A] = {.states = {GAMEPAD_TH0, GAMEPAD_NONE}, .value = 0x10}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
83 [BUTTON_B] = {.states = {GAMEPAD_TH1, GAMEPAD_NONE}, .value = 0x10}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
84 [BUTTON_C] = {.states = {GAMEPAD_TH1, GAMEPAD_NONE}, .value = 0x20}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
85 [BUTTON_START] = {.states = {GAMEPAD_TH0, GAMEPAD_NONE}, .value = 0x20}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
86 [BUTTON_X] = {.states = {GAMEPAD_EXTRA, GAMEPAD_NONE}, .value = 0x4}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
87 [BUTTON_Y] = {.states = {GAMEPAD_EXTRA, GAMEPAD_NONE}, .value = 0x2}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
88 [BUTTON_Z] = {.states = {GAMEPAD_EXTRA, GAMEPAD_NONE}, .value = 0x1}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
89 [BUTTON_MODE] = {.states = {GAMEPAD_EXTRA, GAMEPAD_NONE}, .value = 0x8}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
90 }; |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
91 |
2422
1978bd770023
Expose gamepad state in debugger
Michael Pavone <pavone@retrodev.com>
parents:
2238
diff
changeset
|
92 io_port *find_gamepad(sega_io *io, uint8_t gamepad_num) |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
93 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
94 for (int i = 0; i < 3; i++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
95 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
96 io_port *port = io->ports + i; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
97 if (port->device_type < IO_MOUSE && port->device.pad.gamepad_num == gamepad_num) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
98 return port; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
99 } |
2027
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
100 if (port->device_type == IO_HEARTBEAT_TRAINER && port->device.heartbeat_trainer.device_num == gamepad_num) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
101 return port; |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
102 } |
2238
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
103 if (port->device_type == IO_SEGA_MULTI || port->device_type == IO_EA_MULTI_A) { |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
104 for (int j = 0; j < 4; j++) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
105 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
106 io_port *tap_port = port->device.multitap.ports + j; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
107 if (tap_port->device_type < IO_MOUSE && tap_port->device.pad.gamepad_num == gamepad_num) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
108 return tap_port; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
109 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
110 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
111 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
112 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
113 return NULL; |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
114 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
115 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
116 static io_port *find_mouse(sega_io *io, uint8_t mouse_num) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
118 for (int i = 0; i < 3; i++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
119 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
120 io_port *port = io->ports + i; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
121 if (port->device_type == IO_MOUSE && port->device.mouse.mouse_num == mouse_num) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
122 return port; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
123 } |
2238
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
124 if (port->device_type == IO_SEGA_MULTI) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
125 for (int j = 0; j < 4; j++) |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
126 { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
127 io_port *tap_port = port->device.multitap.ports + j; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
128 if (tap_port->device_type == IO_MOUSE && tap_port->device.mouse.mouse_num == mouse_num) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
129 return tap_port; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
130 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
131 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
132 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
134 return NULL; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
137 static io_port *find_keyboard(sega_io *io) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
139 for (int i = 0; i < 3; i++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
140 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
141 io_port *port = io->ports + i; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
142 if (port->device_type == IO_SATURN_KEYBOARD || port->device_type == IO_XBAND_KEYBOARD) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
143 return port; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
144 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
146 return NULL; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 |
1610 | 149 void io_port_gamepad_down(io_port *port, uint8_t button) |
150 { | |
151 gp_button_def *def = button_defs + button; | |
152 port->input[def->states[0]] |= def->value; | |
153 if (def->states[1] != GAMEPAD_NONE) { | |
154 port->input[def->states[1]] |= def->value; | |
155 } | |
156 } | |
157 | |
158 void io_port_gamepad_up(io_port *port, uint8_t button) | |
159 { | |
160 gp_button_def *def = button_defs + button; | |
161 port->input[def->states[0]] &= ~def->value; | |
162 if (def->states[1] != GAMEPAD_NONE) { | |
163 port->input[def->states[1]] &= ~def->value; | |
164 } | |
165 } | |
166 | |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
167 void io_gamepad_down(sega_io *io, uint8_t gamepad_num, uint8_t button) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
169 io_port *port = find_gamepad(io, gamepad_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
170 if (port) { |
1610 | 171 io_port_gamepad_down(port, button); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
175 void io_gamepad_up(sega_io *io, uint8_t gamepad_num, uint8_t button) |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
176 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
177 io_port *port = find_gamepad(io, gamepad_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
178 if (port) { |
1610 | 179 io_port_gamepad_up(port, button); |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
180 } |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
181 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
182 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
183 void io_mouse_down(sega_io *io, uint8_t mouse_num, uint8_t button) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
185 io_port *port = find_mouse(io, mouse_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
186 if (port) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
187 port->input[0] |= button; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
191 void io_mouse_up(sega_io *io, uint8_t mouse_num, uint8_t button) |
493
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
192 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
193 io_port *port = find_mouse(io, mouse_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
194 if (port) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
195 port->input[0] &= ~button; |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
196 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
199 void io_mouse_motion_absolute(sega_io *io, uint8_t mouse_num, uint16_t x, uint16_t y) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
200 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
201 io_port *port = find_mouse(io, mouse_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
202 if (port) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
203 port->device.mouse.cur_x = x; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
204 port->device.mouse.cur_y = y; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
205 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
206 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
207 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
208 void io_mouse_motion_relative(sega_io *io, uint8_t mouse_num, int32_t x, int32_t y) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
209 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
210 io_port *port = find_mouse(io, mouse_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
211 if (port) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
212 port->device.mouse.cur_x += x; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
213 port->device.mouse.cur_y += y; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
214 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
215 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
216 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
217 void store_key_event(io_port *keyboard_port, uint16_t code) |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
218 { |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
219 if (keyboard_port && keyboard_port->device.keyboard.write_pos != keyboard_port->device.keyboard.read_pos) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
220 //there's room in the buffer, record this event |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
221 keyboard_port->device.keyboard.events[keyboard_port->device.keyboard.write_pos] = code; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
222 if (keyboard_port->device.keyboard.read_pos == 0xFF) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
223 //ring buffer was empty, update read_pos to indicate there is now data |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
224 keyboard_port->device.keyboard.read_pos = keyboard_port->device.keyboard.write_pos; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
225 } |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
226 keyboard_port->device.keyboard.write_pos = (keyboard_port->device.keyboard.write_pos + 1) & 7; |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
227 } |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
228 } |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
229 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
230 void io_keyboard_down(sega_io *io, uint8_t scancode) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
232 store_key_event(find_keyboard(io), scancode); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
235 void io_keyboard_up(sega_io *io, uint8_t scancode) |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
236 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
237 store_key_event(find_keyboard(io), 0xF000 | scancode); |
1576
2b132d894d76
Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
238 } |
2b132d894d76
Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
239 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
240 uint8_t io_has_keyboard(sega_io *io) |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
241 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
242 return find_keyboard(io) != NULL; |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
243 } |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
244 |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
245 static void set_serial_clock(io_port *port) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
246 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
247 switch(port->serial_ctrl >> 6) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
248 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
249 case 0: port->serial_divider = 11186; break; //4800 bps |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
250 case 1: port->serial_divider = 22372; break; //2400 bps |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
251 case 2: port->serial_divider = 44744; break; //1200 bps |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
252 case 3: port->serial_divider = 178976; break; //300 bps |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
253 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
254 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
255 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
256 void process_device(char * device_type, io_port * port) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
257 { |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
258 set_serial_clock(port); |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
259 //assuming that the io_port struct has been zeroed if this is the first time this has been called |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
260 if (!device_type) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
261 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
262 return; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
263 } |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
264 io_port *old_ports = NULL; |
2238
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
265 if (port->device_type == IO_SEGA_MULTI || port->device_type == IO_EA_MULTI_A) { |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
266 old_ports = port->device.multitap.ports; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
267 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
268 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
269 const int gamepad_len = strlen("gamepad"); |
1783 | 270 if (startswith(device_type, "gamepad")) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
271 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
272 if ( |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
273 (device_type[gamepad_len] != '3' && device_type[gamepad_len] != '6' && device_type[gamepad_len] != '2') |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
274 || device_type[gamepad_len+1] != '.' || device_type[gamepad_len+2] < '1' |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
275 || device_type[gamepad_len+2] > '8' || device_type[gamepad_len+3] != 0 |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
276 ) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
277 warning("%s is not a valid gamepad type\n", device_type); |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
278 } else if (device_type[gamepad_len] == '3') { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
279 port->device_type = IO_GAMEPAD3; |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
280 } else if (device_type[gamepad_len] == '2') { |
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
281 port->device_type = IO_GAMEPAD2; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
282 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
283 port->device_type = IO_GAMEPAD6; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
284 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
285 port->device.pad.gamepad_num = device_type[gamepad_len+2] - '0'; |
2027
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
286 } else if(startswith(device_type, "heartbeat_trainer.")) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
287 port->device_type = IO_HEARTBEAT_TRAINER; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
288 port->device.heartbeat_trainer.nv_memory = NULL; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
289 port->device.heartbeat_trainer.device_num = device_type[strlen("heartbeat_trainer.")] - '0'; |
1783 | 290 } else if(startswith(device_type, "mouse")) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
291 if (port->device_type != IO_MOUSE) { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
292 port->device_type = IO_MOUSE; |
1783 | 293 port->device.mouse.mouse_num = device_type[strlen("mouse")+1] - '0'; |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
294 port->device.mouse.last_read_x = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
295 port->device.mouse.last_read_y = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
296 port->device.mouse.cur_x = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
297 port->device.mouse.cur_y = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
298 port->device.mouse.latched_x = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
299 port->device.mouse.latched_y = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
300 port->device.mouse.ready_cycle = CYCLE_NEVER; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
301 port->device.mouse.tr_counter = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
302 } |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
303 } else if(!strcmp(device_type, "saturn keyboard")) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
304 if (port->device_type != IO_SATURN_KEYBOARD) { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
305 port->device_type = IO_SATURN_KEYBOARD; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
306 port->device.keyboard.read_pos = 0xFF; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
307 port->device.keyboard.write_pos = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
308 } |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
309 } else if(!strcmp(device_type, "xband keyboard")) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
310 if (port->device_type != IO_XBAND_KEYBOARD) { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
311 port->device_type = IO_XBAND_KEYBOARD; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
312 port->device.keyboard.read_pos = 0xFF; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
313 port->device.keyboard.write_pos = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
314 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
315 } else if(!strcmp(device_type, "sega_parallel")) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
316 if (port->device_type != IO_SEGA_PARALLEL) { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
317 port->device_type = IO_SEGA_PARALLEL; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
318 port->device.stream.data_fd = -1; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
319 port->device.stream.listen_fd = -1; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
320 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
321 } else if(!strcmp(device_type, "generic")) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
322 if (port->device_type != IO_GENERIC) { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
323 port->device_type = IO_GENERIC; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
324 port->device.stream.data_fd = -1; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
325 port->device.stream.listen_fd = -1; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
326 } |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
327 } else if(!strcmp(device_type, "serial")) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
328 if (port->device_type != IO_GENERIC_SERIAL) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
329 port->device_type = IO_GENERIC_SERIAL; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
330 port->device.stream.data_fd = -1; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
331 port->device.stream.listen_fd = -1; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
332 } |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
333 } else if(startswith(device_type, "sega_multitap.")) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
334 if (port->device_type != IO_SEGA_MULTI) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
335 port->device_type = IO_SEGA_MULTI; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
336 port->device.multitap.ports = old_ports ? old_ports : calloc(4, sizeof(io_port)); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
337 port->device.multitap.tap_num = device_type[strlen("sega_multitap.")] - '0'; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
338 if (!old_ports) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
339 port->device.multitap.tr_counter = 0; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
340 port->device.multitap.ready_cycle = CYCLE_NEVER; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
341 port->input[0] = 0x13; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
342 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
343 old_ports = NULL; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
344 } |
2238
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
345 } else if(!strcmp(device_type, "ea_multitap_port_a")) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
346 if (port->device_type != IO_EA_MULTI_A) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
347 port->device_type = IO_EA_MULTI_A; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
348 port->device.multitap.ports = old_ports ? old_ports : calloc(4, sizeof(io_port)); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
349 port->device.multitap.tap_num = 1; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
350 port->device.multitap.cur_port = EA_PASSTHRU_MODE; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
351 old_ports = NULL; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
352 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
353 } else if(!strcmp(device_type, "ea_multitap_port_b")) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
354 port->device_type = IO_EA_MULTI_B; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
355 port->device.multitap.ports = NULL; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
356 port->device.multitap.tap_num = 1; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
357 } |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
358 free(old_ports); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
359 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
360 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
361 char * io_name(int i) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
362 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
363 switch (i) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
364 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
365 case 0: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
366 return "1"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
367 case 1: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
368 return "2"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
369 case 2: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
370 return "EXT"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
371 default: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
372 return "invalid"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
373 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
374 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
375 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
376 static char * sockfile_name; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
377 static void cleanup_sockfile() |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
378 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
379 unlink(sockfile_name); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
380 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
381 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
382 void setup_io_devices(tern_node * config, rom_info *rom, sega_io *io) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
383 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
384 io_port * ports = io->ports; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1294
diff
changeset
|
385 tern_node *io_nodes = tern_find_path(config, "io\0devices\0", TVAL_NODE).ptrval; |
1689
7f42a93f18a4
Have a suitable default IO port configuration when nonIO is present from the config file. Fixed off by one in processing gamepad button events in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1650
diff
changeset
|
386 char * io_1 = rom->port1_override ? rom->port1_override : tern_find_ptr_default(io_nodes, "1", "gamepad6.1"); |
7f42a93f18a4
Have a suitable default IO port configuration when nonIO is present from the config file. Fixed off by one in processing gamepad button events in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1650
diff
changeset
|
387 char * io_2 = rom->port2_override ? rom->port2_override : tern_find_ptr_default(io_nodes, "2", "gamepad6.2"); |
7f42a93f18a4
Have a suitable default IO port configuration when nonIO is present from the config file. Fixed off by one in processing gamepad button events in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1650
diff
changeset
|
388 char * io_ext = rom->ext_override ? rom->ext_override : tern_find_ptr(io_nodes, "ext"); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
389 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
390 process_device(io_1, ports); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
391 process_device(io_2, ports+1); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
392 process_device(io_ext, ports+2); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
393 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
394 uint8_t mouse_mode; |
1396
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
395 if (ports[0].device_type == IO_MOUSE || ports[1].device_type == IO_MOUSE || ports[2].device_type == IO_MOUSE) { |
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
396 if (render_fullscreen()) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
397 mouse_mode = MOUSE_RELATIVE; |
1396
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
398 } else { |
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
399 if (rom->mouse_mode && !strcmp(rom->mouse_mode, "absolute")) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
400 mouse_mode = MOUSE_ABSOLUTE; |
1396
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
401 } else { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
402 mouse_mode = MOUSE_CAPTURE; |
1396
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
403 } |
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
404 } |
916
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
405 } else { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
406 mouse_mode = MOUSE_NONE; |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
407 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
408 bindings_set_mouse_mode(mouse_mode); |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
409 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
410 for (int i = 0; i < 3; i++) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
411 { |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
412 #ifndef _WIN32 |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
413 if (ports[i].device_type == IO_SEGA_PARALLEL && ports[i].device.stream.data_fd == -1) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
414 { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1294
diff
changeset
|
415 char *pipe_name = tern_find_path(config, "io\0parallel_pipe\0", TVAL_PTR).ptrval; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
416 if (!pipe_name) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
417 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
418 warning("IO port %s is configured to use the sega parallel board, but no paralell_pipe is set!\n", io_name(i)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
419 ports[i].device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
420 } else { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1791
diff
changeset
|
421 debug_message("IO port: %s connected to device '%s' with pipe name: %s\n", io_name(i), device_type_names[ports[i].device_type], pipe_name); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
422 if (!strcmp("stdin", pipe_name)) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
423 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
424 ports[i].device.stream.data_fd = STDIN_FILENO; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
425 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
426 if (mkfifo(pipe_name, 0666) && errno != EEXIST) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
427 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
428 warning("Failed to create fifo %s for Sega parallel board emulation: %d %s\n", pipe_name, errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
429 ports[i].device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
430 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
431 ports[i].device.stream.data_fd = open(pipe_name, O_NONBLOCK | O_RDONLY); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
432 if (ports[i].device.stream.data_fd == -1) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
433 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
434 warning("Failed to open fifo %s for Sega parallel board emulation: %d %s\n", pipe_name, errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
435 ports[i].device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
436 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
437 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
438 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
439 } |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
440 } else if (ports[i].device_type == IO_GENERIC || ports[i].device_type == IO_GENERIC_SERIAL && ports[i].device.stream.data_fd == -1) { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1294
diff
changeset
|
441 char *sock_name = tern_find_path(config, "io\0socket\0", TVAL_PTR).ptrval; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
442 if (!sock_name) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
443 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
444 warning("IO port %s is configured to use generic IO, but no socket is set!\n", io_name(i)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
445 ports[i].device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
446 } else { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1791
diff
changeset
|
447 debug_message("IO port: %s connected to device '%s' with socket name: %s\n", io_name(i), device_type_names[ports[i].device_type], sock_name); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
448 ports[i].device.stream.data_fd = -1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
449 ports[i].device.stream.listen_fd = socket(AF_UNIX, SOCK_STREAM, 0); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
450 size_t pathlen = strlen(sock_name); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
451 size_t addrlen = offsetof(struct sockaddr_un, sun_path) + pathlen + 1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
452 struct sockaddr_un *saddr = malloc(addrlen); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
453 saddr->sun_family = AF_UNIX; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
454 memcpy(saddr->sun_path, sock_name, pathlen+1); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
455 if (bind(ports[i].device.stream.listen_fd, (struct sockaddr *)saddr, addrlen)) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
456 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
457 warning("Failed to bind socket for IO Port %s to path %s: %d %s\n", io_name(i), sock_name, errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
458 goto cleanup_sock; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
459 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
460 if (listen(ports[i].device.stream.listen_fd, 1)) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
461 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
462 warning("Failed to listen on socket for IO Port %s: %d %s\n", io_name(i), errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
463 goto cleanup_sockfile; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
464 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
465 sockfile_name = sock_name; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
466 atexit(cleanup_sockfile); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
467 continue; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
468 cleanup_sockfile: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
469 unlink(sock_name); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
470 cleanup_sock: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
471 close(ports[i].device.stream.listen_fd); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
472 ports[i].device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
473 } |
883
9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents:
796
diff
changeset
|
474 } else |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
475 #endif |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
476 if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6 || ports[i].device_type == IO_GAMEPAD2) { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1791
diff
changeset
|
477 debug_message("IO port %s connected to gamepad #%d with type '%s'\n", io_name(i), ports[i].device.pad.gamepad_num, device_type_names[ports[i].device_type]); |
2027
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
478 } else if (ports[i].device_type == IO_HEARTBEAT_TRAINER) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
479 debug_message("IO port %s connected to Heartbeat Personal Trainer #%d\n", io_name(i), ports[i].device.heartbeat_trainer.device_num); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
480 if (rom->save_type == SAVE_HBPT) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
481 ports[i].device.heartbeat_trainer.nv_memory = rom->save_buffer; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
482 uint32_t page_size = 16; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
483 for (; page_size < 128; page_size *= 2) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
484 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
485 if (rom->save_size / page_size < 256) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
486 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
487 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
488 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
489 ports[i].device.heartbeat_trainer.nv_page_size = page_size; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
490 uint32_t num_pages = rom->save_size / page_size; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
491 ports[i].device.heartbeat_trainer.nv_pages = num_pages < 256 ? num_pages : 255; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
492 } else { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
493 ports[i].device.heartbeat_trainer.nv_page_size = 16; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
494 ports[i].device.heartbeat_trainer.nv_pages = 32; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
495 size_t bufsize = |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
496 ports[i].device.heartbeat_trainer.nv_page_size * ports[i].device.heartbeat_trainer.nv_pages |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
497 + 5 + 8; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
498 ports[i].device.heartbeat_trainer.nv_memory = malloc(bufsize); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
499 memset(ports[i].device.heartbeat_trainer.nv_memory, 0xFF, bufsize); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
500 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
501 ports[i].device.heartbeat_trainer.state = HBPT_NEED_INIT; |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
502 } else if (ports[i].device_type == IO_SEGA_MULTI) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
503 char path[] = "io\0sega_multitap.1\0"; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
504 path[17] = '0' + ports[i].device.multitap.tap_num; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
505 tern_node *port_defs = tern_find_path(config, path, TVAL_NODE).ptrval; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
506 debug_message("IO port %s connected to Sega multitap %d\n", io_name(i), ports[i].device.multitap.tap_num); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
507 for (int j = 0; j < 4; j++) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
508 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
509 char port_num[] = {'1' + j, 0, 0}; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
510 char *dev_type = tern_find_ptr(port_defs, port_num); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
511 process_device(dev_type, ports[i].device.multitap.ports + j); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
512 debug_message("\tTap port %d connected to device '%s'\n", j + 1, device_type_names[ports[i].device.multitap.ports[j].device_type]); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
513 if (ports[i].control & ports[i].output & 0x40) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
514 io_control_write(ports[i].device.multitap.ports + j, 0x40, 0); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
515 io_data_write(ports[i].device.multitap.ports + j, 0x40, 0); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
516 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
517 } |
2238
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
518 } else if (ports[i].device_type == IO_EA_MULTI_A) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
519 char path[] = "io\0ea_multitap\0"; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
520 tern_node *port_defs = tern_find_path(config, path, TVAL_NODE).ptrval; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
521 debug_message("IO port %s connected to EA 4-way Play A-side\n", io_name(i)); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
522 for (int j = 0; j < 4; j++) |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
523 { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
524 char port_num[] = {'1' + j, 0, 0}; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
525 char *dev_type = tern_find_ptr(port_defs, port_num); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
526 process_device(dev_type, ports[i].device.multitap.ports + j); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
527 debug_message("\tTap port %d connected to device '%s'\n", j + 1, device_type_names[ports[i].device.multitap.ports[j].device_type]); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
528 io_control_write(ports[i].device.multitap.ports + j, 0x40, 0); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
529 io_data_write(ports[i].device.multitap.ports + j, 0, 0); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
530 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
531 } else if (ports[i].device_type == IO_EA_MULTI_B) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
532 debug_message("IO port %s connected to EA 4-way Play B-side\n", io_name(i)); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
533 for (int j = 0; j < 3; j++) |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
534 { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
535 if (ports[j].device_type == IO_EA_MULTI_A) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
536 ports[i].device.multitap.ports = ports + j; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
537 break; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
538 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
539 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
540 } else { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1791
diff
changeset
|
541 debug_message("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
542 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
543 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
544 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
545 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
546 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
547 #define TH 0x40 |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
548 #define TR 0x20 |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
549 #define TL 0x10 |
694
7497334bb548
Adjust TH timeout value to take into account the move to master clock cycles
Michael Pavone <pavone@retrodev.com>
parents:
645
diff
changeset
|
550 #define TH_TIMEOUT 56000 |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
551 #define SLOW_RISE_DEVICE (30*7) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
552 #define SLOW_RISE_INPUT (12*7) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
553 |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
554 static uint8_t get_output_value(io_port *port, uint32_t current_cycle, uint32_t slow_rise_delay) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
555 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
556 uint8_t output = (port->control | 0x80) & port->output; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
557 for (int i = 0; i < 8; i++) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
558 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
559 if (!(port->control & 1 << i)) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
560 if (port->slow_rise_start[i] != CYCLE_NEVER) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
561 if (current_cycle - port->slow_rise_start[i] >= slow_rise_delay) { |
2661
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
562 port->slow_rise_start[i] = CYCLE_NEVER; |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
563 output |= 1 << i; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
564 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
565 } else { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
566 output |= 1 << i; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
567 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
568 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
569 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
570 return output; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
571 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
572 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
573 void mouse_check_ready(io_port *port, uint32_t current_cycle) |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
574 { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
575 if (current_cycle >= port->device.mouse.ready_cycle) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
576 port->device.mouse.tr_counter++; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
577 port->device.mouse.ready_cycle = CYCLE_NEVER; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
578 if (port->device.mouse.tr_counter == 3) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
579 port->device.mouse.latched_x = port->device.mouse.cur_x; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
580 port->device.mouse.latched_y = port->device.mouse.cur_y; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
581 /* FIXME mouse mode owned by bindings now |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
582 if (current_io->mouse_mode == MOUSE_ABSOLUTE) { |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
583 //avoid overflow in absolute mode |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
584 int deltax = port->device.mouse.latched_x - port->device.mouse.last_read_x; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
585 if (abs(deltax) > 255) { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
586 port->device.mouse.latched_x = port->device.mouse.last_read_x + (deltax > 0 ? 255 : -255); |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
587 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
588 int deltay = port->device.mouse.latched_y - port->device.mouse.last_read_y; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
589 if (abs(deltay) > 255) { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
590 port->device.mouse.latched_y = port->device.mouse.last_read_y + (deltay > 0 ? 255 : -255); |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
591 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
592 }*/ |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
593 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
594 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
595 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
596 |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
597 void multitap_check_ready(io_port *port, uint32_t current_cycle) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
598 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
599 if (current_cycle >= port->device.multitap.ready_cycle) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
600 if (port->device.multitap.reset_state) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
601 uint8_t output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
602 if (output & TR) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
603 port->input[0] |= TL; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
604 port->device.multitap.reset_state = 0; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
605 } else { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
606 port->input[0] &= TR; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
607 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
608 port->device.multitap.ready_cycle = CYCLE_NEVER; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
609 return; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
610 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
611 port->device.multitap.tr_counter++; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
612 port->device.multitap.ready_cycle = CYCLE_NEVER; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
613 switch (port->device.multitap.tr_counter) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
614 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
615 case 1: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
616 for (int i = 0; i < 4; i++) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
617 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
618 uint8_t id = io_data_read(port->device.multitap.ports + i, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
619 io_data_write(port->device.multitap.ports + i, 0, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
620 uint8_t value = io_data_read(port->device.multitap.ports + i, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
621 uint8_t pad_data = (id & 0x3F) | (value << 2 & 0xC0); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
622 id = (id & 0xA) | (id << 1 & 0xA); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
623 id |= (value & 0x5) | (value >> 1 & 0x5); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
624 id = (id & 0x9) | (id << 1 & 0x4) | (id >> 1 & 0x2); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
625 if (id == 0xD || id == 0xC) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
626 port->device.multitap.data[i] = pad_data; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
627 io_data_write(port->device.multitap.ports + i, 0x40, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
628 } else if (id == 0x3) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
629 //set TR to output for mouse |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
630 io_control_write(port->device.multitap.ports + i, 0x60, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
631 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
632 port->device.multitap.device_ids[i] = id; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
633 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
634 port->input[0] = 0; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
635 break; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
636 case 2: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
637 for (int i = 0; i < 4; i++) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
638 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
639 if (port->device.multitap.device_ids[i] == 0xC || port->device.multitap.device_ids[i] == 0xD) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
640 io_data_write(port->device.multitap.ports + i, 0, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
641 } else if (port->device.multitap.device_ids[i] == 0x3) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
642 //TODO: Fix delays so mouse has enough time to respond |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
643 io_data_write(port->device.multitap.ports + i, 0x20, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
644 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
645 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
646 port->input[0] = 0x10; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
647 break; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
648 case 3: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
649 for (int i = 0; i < 4; i++) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
650 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
651 if (port->device.multitap.device_ids[i] == 0xC || port->device.multitap.device_ids[i] == 0xD) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
652 io_data_write(port->device.multitap.ports + i, 0x40, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
653 io_data_write(port->device.multitap.ports + i, 0, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
654 uint8_t value = io_data_read(port->device.multitap.ports + i, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
655 if (value & 0xF) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
656 //3 button |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
657 port->device.multitap.device_ids[i] = 0; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
658 } else { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
659 port->device.multitap.device_ids[i] = 1; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
660 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
661 } else if (port->device.multitap.device_ids[i] == 0xC) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
662 //TODO: Fix delays so mouse has enough time to respond |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
663 io_data_write(port->device.multitap.ports + i, 0, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
664 port->device.multitap.device_ids[i] = 2; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
665 } else { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
666 port->device.multitap.device_ids[i] = 0xF; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
667 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
668 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
669 port->input[0] = port->device.multitap.device_ids[0]; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
670 break; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
671 case 4: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
672 port->input[0] = 0x10 | port->device.multitap.device_ids[1]; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
673 break; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
674 case 5: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
675 port->input[0] = port->device.multitap.device_ids[2]; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
676 break; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
677 case 6: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
678 port->input[0] = 0x10 | port->device.multitap.device_ids[3]; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
679 port->device.multitap.cur_port = 0; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
680 port->device.multitap.port_start = 7; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
681 break; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
682 default: { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
683 port->input[0] = (port->input[0] & ~TL) | ((~port->input[0]) & TL); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
684 uint8_t tr_diff = port->device.multitap.tr_counter - port->device.multitap.port_start; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
685 for (;;) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
686 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
687 if (port->device.multitap.cur_port > 3) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
688 return; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
689 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
690 switch (port->device.multitap.device_ids[port->device.multitap.cur_port]) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
691 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
692 case 0: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
693 if (tr_diff) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
694 port->input[0] = (port->input[0] & 0xF0) | (port->device.multitap.data[port->device.multitap.cur_port] >> 4); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
695 port->device.multitap.cur_port++; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
696 port->device.multitap.port_start = port->device.multitap.tr_counter + 1; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
697 } else { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
698 port->input[0] = (port->input[0] & 0xF0) | (port->device.multitap.data[port->device.multitap.cur_port] & 0xF); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
699 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
700 return; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
701 case 1: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
702 if (tr_diff == 2) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
703 uint8_t value = io_data_read(port->device.multitap.ports + port->device.multitap.cur_port, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
704 port->input[0] = (port->input[0] & 0xF0) | (value & 0xF); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
705 //finish 6-button cycle |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
706 io_data_write(port->device.multitap.ports + port->device.multitap.cur_port, 0, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
707 port->device.multitap.cur_port++; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
708 port->device.multitap.port_start = port->device.multitap.tr_counter + 1; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
709 } else if (tr_diff) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
710 io_data_write(port->device.multitap.ports + port->device.multitap.cur_port, 0x40, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
711 port->input[0] = (port->input[0] & 0xF0) | (port->device.multitap.data[port->device.multitap.cur_port] >> 4); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
712 } else { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
713 port->input[0] = (port->input[0] & 0xF0) | (port->device.multitap.data[port->device.multitap.cur_port] & 0xF); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
714 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
715 return; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
716 case 2: { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
717 io_port *dst_port = port->device.multitap.ports + port->device.multitap.cur_port; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
718 uint8_t value = io_data_read(dst_port, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
719 io_data_write(dst_port, (~dst_port->output) & TR, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
720 if (tr_diff == 5) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
721 port->device.multitap.cur_port++; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
722 port->device.multitap.port_start = port->device.multitap.tr_counter + 1; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
723 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
724 return; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
725 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
726 default: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
727 port->device.multitap.cur_port++; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
728 port->device.multitap.port_start = port->device.multitap.tr_counter; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
729 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
730 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
731 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
732 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
733 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
734 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
735 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
736 void io_adjust_cycles(io_port * port, uint32_t current_cycle, uint32_t deduction) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
737 { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
738 /*uint8_t control = pad->control | 0x80; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
739 uint8_t th = control & pad->output; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
740 if (pad->input[GAMEPAD_TH0] || pad->input[GAMEPAD_TH1]) { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
741 printf("adjust_cycles | control: %X, TH: %X, GAMEPAD_TH0: %X, GAMEPAD_TH1: %X, TH Counter: %d, Timeout: %d, Cycle: %d\n", control, th, pad->input[GAMEPAD_TH0], pad->input[GAMEPAD_TH1], pad->th_counter,pad->timeout_cycle, current_cycle); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
742 }*/ |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
743 if (port->device_type == IO_GAMEPAD6) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
744 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
745 if (current_cycle >= port->device.pad.timeout_cycle) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
746 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
747 port->device.pad.th_counter = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
748 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
749 port->device.pad.timeout_cycle -= deduction; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
750 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
751 } else if (port->device_type == IO_MOUSE) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
752 mouse_check_ready(port, current_cycle); |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
753 if (port->device.mouse.ready_cycle != CYCLE_NEVER) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
754 port->device.mouse.ready_cycle -= deduction; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
755 } |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
756 } else if (port->device_type == IO_SEGA_MULTI) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
757 multitap_check_ready(port, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
758 if (port->device.multitap.ready_cycle != CYCLE_NEVER) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
759 port->device.multitap.ready_cycle -= deduction; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
760 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
761 for (int i = 0; i < 4; i++) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
762 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
763 io_adjust_cycles(port->device.multitap.ports + i, current_cycle, deduction); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
764 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
765 } |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
766 for (int i = 0; i < 8; i++) |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
767 { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
768 if (port->slow_rise_start[i] != CYCLE_NEVER) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
769 if (port->slow_rise_start[i] >= deduction) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
770 port->slow_rise_start[i] -= deduction; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
771 } else { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
772 port->slow_rise_start[i] = CYCLE_NEVER; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
773 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
774 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
775 } |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
776 if (port->transmit_end >= deduction) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
777 port->transmit_end -= deduction; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
778 } else { |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
779 port->transmit_end = 0; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
780 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
781 if (port->receive_end >= deduction) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
782 port->receive_end -= deduction; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
783 } else { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
784 port->receive_end = 0; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
785 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
786 if (port->last_poll_cycle >= deduction) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
787 port->last_poll_cycle -= deduction; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
788 } else { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
789 port->last_poll_cycle = 0; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
790 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
791 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
792 |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
793 #ifndef _WIN32 |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
794 static void wait_for_connection(io_port *port) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
795 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
796 if (port->device.stream.data_fd == -1) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
797 { |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
798 debug_message("Waiting for socket connection...\n"); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
799 port->device.stream.data_fd = accept(port->device.stream.listen_fd, NULL, NULL); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
800 fcntl(port->device.stream.data_fd, F_SETFL, O_NONBLOCK | O_RDWR); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
801 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
802 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
803 |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
804 static void poll_for_connection(io_port *port) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
805 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
806 if (port->device.stream.data_fd == -1) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
807 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
808 fcntl(port->device.stream.listen_fd, F_SETFL, O_NONBLOCK | O_RDWR); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
809 port->device.stream.data_fd = accept(port->device.stream.listen_fd, NULL, NULL); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
810 fcntl(port->device.stream.listen_fd, F_SETFL, O_RDWR); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
811 if (port->device.stream.data_fd != -1) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
812 fcntl(port->device.stream.data_fd, F_SETFL, O_NONBLOCK | O_RDWR); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
813 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
814 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
815 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
816 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
817 static void write_serial_byte(io_port *port) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
818 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
819 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
820 for (int sent = 0; sent != sizeof(port->serial_transmitting);) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
821 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
822 sent = send(port->device.stream.data_fd, &port->serial_transmitting, sizeof(port->serial_transmitting), 0); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
823 if (sent < 0) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
824 close(port->device.stream.data_fd); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
825 port->device.stream.data_fd = -1; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
826 wait_for_connection(port); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
827 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
828 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
829 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
830 fcntl(port->device.stream.data_fd, F_SETFL, O_NONBLOCK | O_RDWR); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
831 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
832 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
833 static void read_serial_byte(io_port *port) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
834 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
835 poll_for_connection(port); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
836 if (port->device.stream.data_fd == -1) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
837 return; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
838 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
839 int read = recv(port->device.stream.data_fd, &port->serial_receiving, sizeof(port->serial_receiving), 0); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
840 if (read < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
841 close(port->device.stream.data_fd); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
842 port->device.stream.data_fd = -1; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
843 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
844 if (read > 0) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
845 port->receive_end = port->serial_cycle + 10 * port->serial_divider; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
846 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
847 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
848 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
849 static void service_pipe(io_port *port) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
850 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
851 uint8_t value; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
852 int numRead = read(port->device.stream.data_fd, &value, sizeof(value)); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
853 if (numRead > 0) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
854 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
855 port->input[IO_TH0] = (value & 0xF) | 0x10; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
856 port->input[IO_TH1] = (value >> 4) | 0x10; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
857 } else if(numRead == -1 && errno != EAGAIN && errno != EWOULDBLOCK) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
858 warning("Error reading pipe for IO port: %d %s\n", errno, strerror(errno)); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
859 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
860 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
861 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
862 static void service_socket(io_port *port) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
863 { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
864 uint8_t buf[32]; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
865 uint8_t blocking = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
866 int numRead = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
867 while (numRead <= 0) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
868 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
869 numRead = recv(port->device.stream.data_fd, buf, sizeof(buf), 0); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
870 if (numRead > 0) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
871 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
872 port->input[IO_TH0] = buf[numRead-1]; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
873 if (port->input[IO_STATE] == IO_READ_PENDING) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
874 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
875 port->input[IO_STATE] = IO_READ; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
876 if (blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
877 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
878 //pending read satisfied, back to non-blocking mode |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
879 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR | O_NONBLOCK); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
880 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
881 } else if (port->input[IO_STATE] == IO_WRITTEN) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
882 port->input[IO_STATE] = IO_READ; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
883 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
884 } else if (numRead == 0) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
885 port->device.stream.data_fd = -1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
886 wait_for_connection(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
887 } else if (errno != EAGAIN && errno != EWOULDBLOCK) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
888 warning("Error reading from socket for IO port: %d %s\n", errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
889 close(port->device.stream.data_fd); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
890 wait_for_connection(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
891 } else if (port->input[IO_STATE] == IO_READ_PENDING) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
892 //clear the nonblocking flag so the next read will block |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
893 if (!blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
894 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
895 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
896 blocking = 1; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
897 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
898 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
899 //no new data, but that's ok |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
900 break; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
901 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
902 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
903 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
904 if (port->input[IO_STATE] == IO_WRITE_PENDING) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
905 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
906 uint8_t value = port->output & port->control; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
907 int written = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
908 blocking = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
909 while (written <= 0) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
910 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
911 send(port->device.stream.data_fd, &value, sizeof(value), 0); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
912 if (written > 0) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
913 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
914 port->input[IO_STATE] = IO_WRITTEN; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
915 if (blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
916 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
917 //pending write satisfied, back to non-blocking mode |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
918 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR | O_NONBLOCK); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
919 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
920 } else if (written == 0) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
921 port->device.stream.data_fd = -1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
922 wait_for_connection(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
923 } else if (errno != EAGAIN && errno != EWOULDBLOCK) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
924 warning("Error writing to socket for IO port: %d %s\n", errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
925 close(port->device.stream.data_fd); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
926 wait_for_connection(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
927 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
928 //clear the nonblocking flag so the next write will block |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
929 if (!blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
930 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
931 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
932 blocking = 1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
933 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
934 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
935 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
936 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
937 } |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
938 #endif |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
939 |
2027
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
940 enum { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
941 HBPT_UNKNOWN1 = 1, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
942 HBPT_POLL, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
943 HBPT_READ_PAGE = 5, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
944 HBPT_WRITE_PAGE, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
945 HBPT_READ_RTC, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
946 HBPT_SET_RTC, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
947 HBPT_GET_STATUS, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
948 HBPT_ERASE_NVMEM, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
949 HBPT_NVMEM_PARAMS, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
950 HBPT_INIT |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
951 }; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
952 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
953 static void start_reply(io_port *port, uint8_t bytes, const uint8_t *src) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
954 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
955 port->device.heartbeat_trainer.remaining_bytes = bytes; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
956 port->device.heartbeat_trainer.state = HBPT_REPLY; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
957 port->device.heartbeat_trainer.cur_buffer = (uint8_t *)src; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
958 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
959 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
960 static void simple_reply(io_port *port, uint8_t value) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
961 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
962 port->device.heartbeat_trainer.param = value; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
963 start_reply(port, 1, &port->device.heartbeat_trainer.param); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
964 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
965 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
966 static void expect_payload(io_port *port, uint8_t bytes, uint8_t *dst) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
967 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
968 port->device.heartbeat_trainer.remaining_bytes = bytes; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
969 port->device.heartbeat_trainer.state = HBPT_CMD_PAYLOAD; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
970 port->device.heartbeat_trainer.cur_buffer = dst; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
971 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
972 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
973 void hbpt_check_init(io_port *port) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
974 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
975 if (port->device.heartbeat_trainer.state == HBPT_NEED_INIT) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
976 port->device.heartbeat_trainer.rtc_base_timestamp = 0; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
977 for (int i = 0; i < 8; i ++) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
978 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
979 port->device.heartbeat_trainer.rtc_base_timestamp <<= 8; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
980 port->device.heartbeat_trainer.rtc_base_timestamp |= port->device.heartbeat_trainer.nv_memory[i]; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
981 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
982 memcpy(port->device.heartbeat_trainer.rtc_base, port->device.heartbeat_trainer.nv_memory + 8, 5); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
983 if (port->device.heartbeat_trainer.rtc_base_timestamp == UINT64_MAX) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
984 //uninitialized save, set the appropriate status bit |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
985 port->device.heartbeat_trainer.status |= 1; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
986 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
987 port->device.heartbeat_trainer.bpm = 60; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
988 port->device.heartbeat_trainer.state = HBPT_IDLE; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
989 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
990 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
991 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
992 void hbpt_check_send_reply(io_port *port) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
993 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
994 if (port->device.heartbeat_trainer.state == HBPT_REPLY && !port->receive_end) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
995 port->serial_receiving = *(port->device.heartbeat_trainer.cur_buffer++); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
996 port->receive_end = port->serial_cycle + 10 * port->serial_divider; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
997 if (!--port->device.heartbeat_trainer.remaining_bytes) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
998 port->device.heartbeat_trainer.state = HBPT_IDLE; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
999 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1000 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1001 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1002 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1003 uint8_t is_leap_year(uint16_t year) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1004 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1005 if (year & 3) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1006 return 0; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1007 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1008 if (year % 100) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1009 return 1; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1010 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1011 if (year % 400) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1012 return 0; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1013 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1014 return 1; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1015 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1016 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1017 uint8_t days_in_month(uint8_t month, uint16_t year) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1018 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1019 static uint8_t days_per_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1020 if (month == 2 && is_leap_year(year)) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1021 return 29; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1022 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1023 if (month > 12 || !month) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1024 return 30; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1025 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1026 return days_per_month[month-1]; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1027 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1028 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1029 void hbpt_write_byte(io_port *port) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1030 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1031 hbpt_check_init(port); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1032 uint8_t reply; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1033 switch (port->device.heartbeat_trainer.state) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1034 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1035 case HBPT_IDLE: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1036 port->device.heartbeat_trainer.cmd = port->serial_transmitting; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1037 switch (port->device.heartbeat_trainer.cmd) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1038 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1039 case HBPT_UNKNOWN1: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1040 start_reply(port, 11, NULL); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1041 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1042 case HBPT_POLL: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1043 start_reply(port, 3, &port->device.heartbeat_trainer.bpm); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1044 if (port->serial_cycle - port->last_poll_cycle > MIN_POLL_INTERVAL) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1045 process_events(); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1046 port->last_poll_cycle = port->serial_cycle; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1047 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1048 port->device.heartbeat_trainer.buttons = (port->input[GAMEPAD_TH0] << 2 & 0xC0) | (port->input[GAMEPAD_TH1] & 0x1F); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1049 if (port->device.heartbeat_trainer.cadence && port->input[GAMEPAD_TH1] & 0x20) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1050 port->device.heartbeat_trainer.cadence--; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1051 printf("Cadence: %d\n", port->device.heartbeat_trainer.cadence); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1052 } else if (port->device.heartbeat_trainer.cadence < 255 && port->input[GAMEPAD_EXTRA] & 1) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1053 port->device.heartbeat_trainer.cadence++; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1054 printf("Cadence: %d\n", port->device.heartbeat_trainer.cadence); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1055 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1056 if (port->device.heartbeat_trainer.bpm && port->input[GAMEPAD_EXTRA] & 4) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1057 port->device.heartbeat_trainer.bpm--; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1058 printf("Heart Rate: %d\n", port->device.heartbeat_trainer.bpm); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1059 } else if (port->device.heartbeat_trainer.bpm < 255 && port->input[GAMEPAD_EXTRA] & 2) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1060 port->device.heartbeat_trainer.bpm++; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1061 printf("Heart Rate: %d\n", port->device.heartbeat_trainer.bpm); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1062 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1063 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1064 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1065 case HBPT_READ_PAGE: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1066 case HBPT_WRITE_PAGE: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1067 //strictly speaking for the write case, we want 1 + page size here |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1068 //but the rest of the payload goes to a different destination |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1069 expect_payload(port, 1, &port->device.heartbeat_trainer.param); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1070 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1071 case HBPT_READ_RTC: { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1072 uint8_t *rtc = port->device.heartbeat_trainer.rtc_base; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1073 start_reply(port, 5, rtc); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1074 uint64_t now = time(NULL); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1075 uint64_t delta = (now - port->device.heartbeat_trainer.rtc_base_timestamp + 30) / 60; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1076 rtc[4] += delta % 60; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1077 if (rtc[4] > 59) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1078 rtc[4] -= 60; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1079 rtc[3]++; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1080 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1081 delta /= 60; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1082 if (delta) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1083 rtc[3] += delta % 24; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1084 delta /= 24; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1085 if (rtc[3] > 23) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1086 rtc[3] -= 24; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1087 delta++; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1088 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1089 if (delta) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1090 uint16_t year = rtc[0] < 81 ? 2000 + rtc[0] : 1900 + rtc[0]; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1091 uint8_t days_cur_month = days_in_month(rtc[1], year); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1092 while (delta + rtc[2] > days_cur_month) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1093 delta -= days_cur_month + 1 - rtc[2]; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1094 rtc[2] = 1; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1095 if (++rtc[1] == 13) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1096 rtc[1] = 1; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1097 year++; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1098 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1099 days_cur_month = days_in_month(rtc[1], year); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1100 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1101 rtc[1] += delta; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1102 rtc[0] = year % 100; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1103 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1104 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1105 printf("RTC %02d-%02d-%02d %02d:%02d\n", rtc[0], rtc[1], rtc[2], rtc[3], rtc[4]); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1106 port->device.heartbeat_trainer.rtc_base_timestamp = now; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1107 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1108 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1109 case HBPT_SET_RTC: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1110 port->device.heartbeat_trainer.rtc_base_timestamp = time(NULL); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1111 expect_payload(port, 5, port->device.heartbeat_trainer.rtc_base); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1112 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1113 case HBPT_GET_STATUS: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1114 simple_reply(port, port->device.heartbeat_trainer.status); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1115 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1116 case HBPT_ERASE_NVMEM: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1117 expect_payload(port, 1, &port->device.heartbeat_trainer.param); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1118 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1119 case HBPT_NVMEM_PARAMS: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1120 start_reply(port, 2, &port->device.heartbeat_trainer.nv_page_size); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1121 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1122 case HBPT_INIT: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1123 expect_payload(port, 19, NULL); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1124 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1125 default: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1126 // it's unclear what these commands do as they are unused by Outback Joey |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1127 // just return 0 to indicate failure |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1128 simple_reply(port, 0); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1129 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1130 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1131 case HBPT_CMD_PAYLOAD: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1132 if (port->device.heartbeat_trainer.cur_buffer) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1133 *(port->device.heartbeat_trainer.cur_buffer++) = port->serial_transmitting; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1134 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1135 if (!--port->device.heartbeat_trainer.remaining_bytes) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1136 switch (port->device.heartbeat_trainer.cmd) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1137 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1138 case HBPT_READ_PAGE: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1139 case HBPT_WRITE_PAGE: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1140 if ( |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1141 port->device.heartbeat_trainer.cmd == HBPT_WRITE_PAGE |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1142 && port->device.heartbeat_trainer.cur_buffer != &port->device.heartbeat_trainer.param + 1) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1143 simple_reply(port, 1); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1144 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1145 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1146 port->device.heartbeat_trainer.remaining_bytes = port->device.heartbeat_trainer.nv_page_size; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1147 port->device.heartbeat_trainer.cur_buffer = |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1148 port->device.heartbeat_trainer.param < port->device.heartbeat_trainer.nv_pages |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1149 ? port->device.heartbeat_trainer.nv_memory + 5 + 8 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1150 + port->device.heartbeat_trainer.param * port->device.heartbeat_trainer.nv_page_size |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1151 : NULL; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1152 if (port->device.heartbeat_trainer.cmd == HBPT_WRITE_PAGE) { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1153 return; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1154 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1155 port->device.heartbeat_trainer.state = HBPT_REPLY; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1156 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1157 case HBPT_SET_RTC: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1158 //save RTC base values back to nv memory area so it's saved to disk on exit |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1159 for (int i = 0; i < 8; i++) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1160 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1161 port->device.heartbeat_trainer.nv_memory[i] = port->device.heartbeat_trainer.rtc_base_timestamp >> (56 - i*8); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1162 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1163 memcpy(port->device.heartbeat_trainer.nv_memory + 8, port->device.heartbeat_trainer.rtc_base, 5); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1164 simple_reply(port, 1); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1165 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1166 case HBPT_ERASE_NVMEM: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1167 memset( |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1168 port->device.heartbeat_trainer.nv_memory + 5 + 8, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1169 port->device.heartbeat_trainer.param, |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1170 port->device.heartbeat_trainer.nv_pages * port->device.heartbeat_trainer.nv_page_size |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1171 ); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1172 simple_reply(port, 1); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1173 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1174 case HBPT_INIT: { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1175 static const char reply[] = "(C) HEARTBEAT CORP"; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1176 start_reply(port, strlen(reply), reply); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1177 break; |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1178 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1179 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1180 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1181 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1182 hbpt_check_send_reply(port); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1183 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1184 |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1185 void hbpt_read_byte(io_port *port) |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1186 { |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1187 hbpt_check_init(port); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1188 hbpt_check_send_reply(port); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1189 } |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1190 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1191 const int mouse_delays[] = {112*7, 120*7, 96*7, 132*7, 104*7, 96*7, 112*7, 96*7}; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1192 |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1193 enum { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1194 KB_SETUP, |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1195 KB_READ, |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1196 KB_WRITE |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1197 }; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1198 |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1199 enum { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1200 SCTRL_BIT_TX_FULL = 1, |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1201 SCTRL_BIT_RX_READY = 2, |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1202 SCTRL_BIT_RX_ERROR = 4, |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1203 SCTRL_BIT_RX_INTEN = 8, |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1204 SCTRL_BIT_TX_ENABLE = 0x10, |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1205 SCTRL_BIT_RX_ENABLE = 0x20 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1206 }; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1207 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1208 void io_run(io_port *port, uint32_t current_cycle) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1209 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1210 uint32_t new_serial_cycle = ((current_cycle - port->serial_cycle) / port->serial_divider) * port->serial_divider + port->serial_cycle; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1211 if (port->transmit_end && port->transmit_end <= new_serial_cycle) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1212 port->transmit_end = 0; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1213 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1214 if (port->serial_ctrl & SCTRL_BIT_TX_ENABLE) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1215 switch (port->device_type) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1216 { |
2027
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1217 case IO_HEARTBEAT_TRAINER: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1218 hbpt_write_byte(port); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1219 break; |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1220 #ifndef _WIN32 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1221 case IO_GENERIC_SERIAL: |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1222 write_serial_byte(port); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1223 break; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1224 #endif |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1225 //TODO: think about how serial mode might interact with non-serial peripherals |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1226 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1227 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1228 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1229 if (!port->transmit_end && new_serial_cycle != port->serial_cycle && (port->serial_ctrl & SCTRL_BIT_TX_FULL)) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1230 //there's a transmit byte pending and no byte is currently being sent |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1231 port->serial_transmitting = port->serial_out; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1232 port->serial_ctrl &= ~SCTRL_BIT_TX_FULL; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1233 //1 start bit, 8 data bits and 1 stop bit |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1234 port->transmit_end = new_serial_cycle + 10 * port->serial_divider; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1235 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1236 port->serial_cycle = new_serial_cycle; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1237 if (port->serial_ctrl && SCTRL_BIT_RX_ENABLE) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1238 if (port->receive_end && new_serial_cycle >= port->receive_end) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1239 port->serial_in = port->serial_receiving; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1240 port->serial_ctrl |= SCTRL_BIT_RX_READY; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1241 port->receive_end = 0; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1242 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1243 if (!port->receive_end) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1244 switch(port->device_type) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1245 { |
2027
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1246 case IO_HEARTBEAT_TRAINER: |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1247 hbpt_read_byte(port); |
0f54a898db03
Implement Heartbeat Personal Trainer peripheral and add ROM DB entry for Outback Joey
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
1248 break; |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1249 #ifndef _WIN32 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1250 case IO_GENERIC_SERIAL: |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1251 read_serial_byte(port); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1252 break; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1253 #endif |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1254 //TODO: think about how serial mode might interact with non-serial peripherals |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1255 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1256 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1257 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1258 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1259 |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1260 void io_control_write(io_port *port, uint8_t value, uint32_t current_cycle) |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1261 { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1262 uint8_t changes = value ^ port->control; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1263 if (changes) { |
2661
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1264 uint8_t old_output; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1265 if (port->device_type == IO_GAMEPAD6) { |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1266 //slow IO rise could have caused a TH transition |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1267 if (port->slow_rise_start[6] != CYCLE_NEVER && current_cycle - port->slow_rise_start[6] >= SLOW_RISE_DEVICE) { |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1268 uint32_t rise_cycle = port->slow_rise_start[6] + SLOW_RISE_DEVICE; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1269 if (rise_cycle >= port->device.pad.timeout_cycle) { |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1270 port->device.pad.th_counter = 0; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1271 } |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1272 |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1273 port->device.pad.th_counter++; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1274 port->device.pad.timeout_cycle = rise_cycle + TH_TIMEOUT; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1275 } |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1276 old_output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE); |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1277 } |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1278 for (int i = 0; i < 8; i++) |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1279 { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1280 if (!(value & 1 << i) && !(port->output & 1 << i)) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1281 //port switched from output to input and the output value was 0 |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1282 //since there is a weak pull-up on input pins, this will lead |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1283 //to a slow rise from 0 to 1 if the pin isn't being externally driven |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1284 port->slow_rise_start[i] = current_cycle; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1285 } else { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1286 port->slow_rise_start[i] = CYCLE_NEVER; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1287 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1288 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1289 port->control = value; |
2661
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1290 if (port->device_type == IO_GAMEPAD6) { |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1291 uint8_t output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE); |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1292 if (TH & (old_output ^ output)) { |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1293 if (current_cycle >= port->device.pad.timeout_cycle) { |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1294 port->device.pad.th_counter = 0; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1295 } |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1296 if ((output & TH)) { |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1297 port->device.pad.th_counter++; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1298 } |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1299 port->device.pad.timeout_cycle = current_cycle + TH_TIMEOUT; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1300 } |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1301 } |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1302 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1303 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1304 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1305 void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1306 { |
2661
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1307 if (port->device_type == IO_GAMEPAD6) { |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1308 //slow IO rise could have caused a TH transition |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1309 if (port->slow_rise_start[6] != CYCLE_NEVER && current_cycle - port->slow_rise_start[6] >= SLOW_RISE_DEVICE) { |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1310 uint32_t rise_cycle = port->slow_rise_start[6] + SLOW_RISE_DEVICE; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1311 if (rise_cycle >= port->device.pad.timeout_cycle) { |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1312 port->device.pad.th_counter = 0; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1313 } |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1314 |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1315 port->device.pad.th_counter++; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1316 port->device.pad.timeout_cycle = rise_cycle + TH_TIMEOUT; |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1317 } |
462e43f54abf
Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
Michael Pavone <pavone@retrodev.com>
parents:
2524
diff
changeset
|
1318 } |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1319 uint8_t old_output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1320 port->output = value; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1321 uint8_t output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1322 switch (port->device_type) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1323 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1324 case IO_GAMEPAD6: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1325 //check if TH has changed |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1326 if ((old_output & TH) ^ (output & TH)) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1327 if (current_cycle >= port->device.pad.timeout_cycle) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1328 port->device.pad.th_counter = 0; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1329 } |
1144
be3df2d8530a
Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
1330 if ((output & TH)) { |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1331 port->device.pad.th_counter++; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1332 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1333 port->device.pad.timeout_cycle = current_cycle + TH_TIMEOUT; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1334 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1335 break; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1336 case IO_MOUSE: |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1337 mouse_check_ready(port, current_cycle); |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1338 if (output & TH) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1339 //request is over or mouse is being reset |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1340 if (port->device.mouse.tr_counter) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1341 //request is over |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1342 port->device.mouse.last_read_x = port->device.mouse.latched_x; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1343 port->device.mouse.last_read_y = port->device.mouse.latched_y; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1344 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1345 port->device.mouse.tr_counter = 0; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1346 port->device.mouse.ready_cycle = CYCLE_NEVER; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1347 } else { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1348 if ((output & TR) != (old_output & TR)) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1349 int delay_index = port->device.mouse.tr_counter >= sizeof(mouse_delays) ? sizeof(mouse_delays)-1 : port->device.mouse.tr_counter; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1350 port->device.mouse.ready_cycle = current_cycle + mouse_delays[delay_index]; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1351 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1352 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1353 break; |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1354 case IO_SATURN_KEYBOARD: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1355 if (output & TH) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1356 //request is over |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1357 if (port->device.keyboard.tr_counter >= 10 && port->device.keyboard.read_pos != 0xFF) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1358 //remove scan code from buffer |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1359 port->device.keyboard.read_pos++; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1360 port->device.keyboard.read_pos &= 7; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1361 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1362 port->device.keyboard.read_pos = 0xFF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1363 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1364 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1365 port->device.keyboard.tr_counter = 0; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1366 } else { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1367 if ((output & TR) != (old_output & TR)) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1368 port->device.keyboard.tr_counter++; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1369 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1370 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1371 break; |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1372 case IO_XBAND_KEYBOARD: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1373 if (output & TH) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1374 //request is over |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1375 if ( |
1257
db28178bd2a1
Fix removal of scan codes from buffer in XBAND keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1256
diff
changeset
|
1376 port->device.keyboard.mode == KB_READ && port->device.keyboard.tr_counter > 6 |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1377 && (port->device.keyboard.tr_counter & 1) |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1378 ) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1379 if (port->device.keyboard.events[port->device.keyboard.read_pos] & 0xFF00) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1380 port->device.keyboard.events[port->device.keyboard.read_pos] &= 0xFF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1381 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1382 port->device.keyboard.read_pos++; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1383 port->device.keyboard.read_pos &= 7; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1384 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1385 port->device.keyboard.read_pos = 0xFF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1386 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1387 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1388 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1389 port->device.keyboard.tr_counter = 0; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1390 port->device.keyboard.mode = KB_SETUP; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1391 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1392 if ((output & TR) != (old_output & TR)) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1393 port->device.keyboard.tr_counter++; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1394 if (port->device.keyboard.tr_counter == 2) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1395 port->device.keyboard.mode = (output & 0xF) ? KB_READ : KB_WRITE; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1396 } else if (port->device.keyboard.mode == KB_WRITE) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1397 switch (port->device.keyboard.tr_counter) |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1398 { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1399 case 3: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1400 //host writes 0b0001 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1401 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1402 case 4: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1403 //host writes 0b0000 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1404 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1405 case 5: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1406 //host writes 0b0000 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1407 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1408 case 6: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1409 port->device.keyboard.cmd = output << 4; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1410 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1411 case 7: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1412 port->device.keyboard.cmd |= output & 0xF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1413 //TODO: actually do something with the command |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1414 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1415 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1416 } else if ( |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1417 port->device.keyboard.mode == KB_READ && port->device.keyboard.tr_counter > 7 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1418 && !(port->device.keyboard.tr_counter & 1) |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1419 ) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1420 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1421 if (port->device.keyboard.events[port->device.keyboard.read_pos] & 0xFF00) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1422 port->device.keyboard.events[port->device.keyboard.read_pos] &= 0xFF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1423 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1424 port->device.keyboard.read_pos++; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1425 port->device.keyboard.read_pos &= 7; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1426 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1427 port->device.keyboard.read_pos = 0xFF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1428 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1429 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1430 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1431 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1432 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1433 break; |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1434 case IO_SEGA_MULTI: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1435 multitap_check_ready(port, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1436 if (output & TH) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1437 //request is over |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1438 port->device.multitap.tr_counter = 0; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1439 if ((output & TR) != (old_output & TR)) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1440 port->device.multitap.ready_cycle = current_cycle + 16 * 7; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1441 port->device.multitap.reset_state = 1; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1442 } else if (!port->device.multitap.reset_state) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1443 port->device.multitap.ready_cycle = CYCLE_NEVER; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1444 port->input[0] = 0x13; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1445 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1446 for (int i = 0; i < 4; i++) |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1447 { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1448 io_control_write(port->device.multitap.ports + i, 0x40, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1449 io_data_write(port->device.multitap.ports + i, 0x40, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1450 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1451 } else { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1452 if (old_output & TH) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1453 port->input[0] = 0x1F; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1454 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1455 if ((output & TR) != (old_output & TR)) { |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1456 //TODO: measure actual delays |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1457 port->device.multitap.ready_cycle = current_cycle + 16 * 7; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1458 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1459 } |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1460 break; |
2238
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1461 case IO_EA_MULTI_A: |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1462 if ((output & TH) != (old_output & TH)) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1463 uint8_t port_num = port->device.multitap.cur_port == EA_PASSTHRU_MODE ? 1 : port->device.multitap.cur_port; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1464 if (port_num < 4) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1465 io_data_write(port->device.multitap.ports + port_num, output & 0x40, current_cycle); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1466 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1467 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1468 break; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1469 case IO_EA_MULTI_B: { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1470 io_port *main_port = port->device.multitap.ports; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1471 io_port *passthru = main_port->device.multitap.ports + 1; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1472 if (main_port->device.multitap.cur_port == EA_PASSTHRU_MODE) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1473 output &= port->control | 0x40; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1474 output |= io_data_read(passthru, current_cycle) & ~(port->control | 0x40); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1475 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1476 uint8_t old_port = main_port->device.multitap.cur_port; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1477 if ((output & 0xF) == 0xC) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1478 main_port->device.multitap.cur_port = output >> 4 & 7; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1479 } else { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1480 main_port->device.multitap.cur_port = EA_PASSTHRU_MODE; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1481 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1482 if (old_port == EA_PASSTHRU_MODE && main_port->device.multitap.cur_port < 4) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1483 //switched from passthru to multitap mode, set TH for selected controller to port A value |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1484 output = get_output_value(main_port, current_cycle, SLOW_RISE_DEVICE); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1485 io_data_write(main_port->device.multitap.ports + main_port->device.multitap.cur_port, output & 0x40, current_cycle); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1486 } else if (main_port->device.multitap.cur_port == EA_PASSTHRU_MODE) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1487 //in passhtru mode, set TH to controller 2 to port B value |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1488 io_data_write(main_port->device.multitap.ports + 1, output & 0x40, current_cycle); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1489 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1490 break; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1491 } |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1492 #ifndef _WIN32 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1493 case IO_GENERIC: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1494 wait_for_connection(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1495 port->input[IO_STATE] = IO_WRITE_PENDING; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1496 service_socket(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1497 break; |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1498 #endif |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1499 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1500 port->output = value; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1501 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1502 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1503 |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1504 void io_tx_write(io_port *port, uint8_t value, uint32_t current_cycle) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1505 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1506 io_run(port, current_cycle); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1507 port->serial_out = value; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1508 port->serial_ctrl |= SCTRL_BIT_TX_FULL; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1509 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1510 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1511 void io_sctrl_write(io_port *port, uint8_t value, uint32_t current_cycle) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1512 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1513 io_run(port, current_cycle); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1514 port->serial_ctrl = (port->serial_ctrl & 0x7) | (value & 0xF8); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1515 set_serial_clock(port); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1516 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1517 |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1518 uint8_t get_scancode_bytes(io_port *port) |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1519 { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1520 if (port->device.keyboard.read_pos == 0xFF) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1521 return 0; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1522 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1523 uint8_t bytes = 0, read_pos = port->device.keyboard.read_pos; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1524 do { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1525 bytes += port->device.keyboard.events[read_pos] & 0xFF00 ? 2 : 1; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1526 read_pos++; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1527 read_pos &= 7; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1528 } while (read_pos != port->device.keyboard.write_pos); |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1529 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1530 return bytes; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1531 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1532 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1533 uint8_t io_data_read(io_port * port, uint32_t current_cycle) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1534 { |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1535 uint8_t output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1536 uint8_t control = port->control | 0x80; |
911
73732ae76fa8
IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents:
910
diff
changeset
|
1537 uint8_t th = output & 0x40; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1538 uint8_t input; |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1539 uint8_t device_driven; |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1540 if (current_cycle - port->last_poll_cycle > MIN_POLL_INTERVAL) { |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1541 process_events(); |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1542 port->last_poll_cycle = current_cycle; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1543 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1544 switch (port->device_type) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1545 { |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
1546 case IO_GAMEPAD2: |
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
1547 input = ~port->input[GAMEPAD_TH1]; |
1379
65f1d6558e9e
Update SMS code for changes supporting slow rise time emulation in IO code
Michael Pavone <pavone@retrodev.com>
parents:
1377
diff
changeset
|
1548 device_driven = 0x3F; |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
1549 break; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1550 case IO_GAMEPAD3: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1551 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1552 input = port->input[th ? GAMEPAD_TH1 : GAMEPAD_TH0]; |
888
bc127fa1f800
Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents:
886
diff
changeset
|
1553 if (!th) { |
bc127fa1f800
Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents:
886
diff
changeset
|
1554 input |= 0xC; |
bc127fa1f800
Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents:
886
diff
changeset
|
1555 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1556 //controller output is logically inverted |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1557 input = ~input; |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1558 device_driven = 0x3F; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1559 break; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1560 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1561 case IO_GAMEPAD6: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1562 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1563 if (current_cycle >= port->device.pad.timeout_cycle) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1564 port->device.pad.th_counter = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1565 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1566 /*if (port->input[GAMEPAD_TH0] || port->input[GAMEPAD_TH1]) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1567 printf("io_data_read | control: %X, TH: %X, GAMEPAD_TH0: %X, GAMEPAD_TH1: %X, TH Counter: %d, Timeout: %d, Cycle: %d\n", control, th, port->input[GAMEPAD_TH0], port->input[GAMEPAD_TH1], port->th_counter,port->timeout_cycle, context->current_cycle); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1568 }*/ |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1569 if (th) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1570 if (port->device.pad.th_counter == 3) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1571 input = port->input[GAMEPAD_EXTRA]; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1572 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1573 input = port->input[GAMEPAD_TH1]; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1574 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1575 } else { |
1144
be3df2d8530a
Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
1576 if (port->device.pad.th_counter == 2) { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1577 input = port->input[GAMEPAD_TH0] | 0xF; |
1144
be3df2d8530a
Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
1578 } else if(port->device.pad.th_counter == 3) { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1579 input = port->input[GAMEPAD_TH0] & 0x30; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1580 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1581 input = port->input[GAMEPAD_TH0] | 0xC; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1582 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1583 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1584 //controller output is logically inverted |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1585 input = ~input; |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1586 device_driven = 0x3F; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1587 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1588 } |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1589 case IO_MOUSE: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1590 { |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1591 mouse_check_ready(port, current_cycle); |
911
73732ae76fa8
IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents:
910
diff
changeset
|
1592 uint8_t tr = output & TR; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1593 if (th) { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1594 if (tr) { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1595 input = 0x10; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1596 } else { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1597 input = 0; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1598 } |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1599 } else { |
913
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
912
diff
changeset
|
1600 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1601 int16_t delta_x = port->device.mouse.latched_x - port->device.mouse.last_read_x; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1602 int16_t delta_y = port->device.mouse.last_read_y - port->device.mouse.latched_y; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1603 switch (port->device.mouse.tr_counter) |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1604 { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1605 case 0: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1606 input = 0xB; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1607 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1608 case 1: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1609 case 2: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1610 input = 0xF; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1611 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1612 case 3: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1613 input = 0; |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1614 if (delta_y > 255 || delta_y < -255) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1615 input |= 8; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1616 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1617 if (delta_x > 255 || delta_x < -255) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1618 input |= 4; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1619 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1620 if (delta_y < 0) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1621 input |= 2; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1622 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1623 if (delta_x < 0) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1624 input |= 1; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1625 } |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1626 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1627 case 4: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1628 input = port->input[0]; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1629 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1630 case 5: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1631 input = delta_x >> 4 & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1632 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1633 case 6: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1634 input = delta_x & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1635 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1636 case 7: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1637 input = delta_y >> 4 & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1638 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1639 case 8: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1640 default: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1641 input = delta_y & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1642 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1643 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1644 input |= ((port->device.mouse.tr_counter & 1) == 0) << 4; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1645 } |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1646 device_driven = 0x1F; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1647 break; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1648 } |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1649 case IO_SATURN_KEYBOARD: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1650 { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1651 if (th) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1652 input = 0x11; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1653 } else { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1654 uint8_t tr = output & TR; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1655 uint16_t code = port->device.keyboard.read_pos == 0xFF ? 0 |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1656 : port->device.keyboard.events[port->device.keyboard.read_pos]; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1657 switch (port->device.keyboard.tr_counter) |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1658 { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1659 case 0: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1660 input = 1; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1661 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1662 case 1: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1663 //Saturn peripheral ID |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1664 input = 3; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1665 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1666 case 2: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1667 //data size |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1668 input = 4; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1669 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1670 case 3: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1671 //d-pad |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1672 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1673 input = 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1674 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1675 case 4: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1676 //Start ABC |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1677 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1678 input = 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1679 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1680 case 5: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1681 //R XYZ |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1682 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1683 input = 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1684 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1685 case 6: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1686 //L and KBID |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1687 //TODO: set L based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1688 input = 0x8; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1689 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1690 case 7: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1691 //Capslock, Numlock, Scrolllock |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1692 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1693 input = 0; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1694 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1695 case 8: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1696 input = 6; |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1697 if (code & 0xFF00) { |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1698 //break |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1699 input |= 1; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1700 } else if (code) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1701 input |= 8; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1702 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1703 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1704 case 9: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1705 input = code >> 4 & 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1706 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1707 case 10: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1708 input = code & 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1709 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1710 case 11: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1711 input = 0; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1712 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1713 default: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1714 input = 1; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1715 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1716 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1717 input |= ((port->device.keyboard.tr_counter & 1) == 0) << 4; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1718 } |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1719 device_driven = 0x1F; |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1720 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1721 } |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1722 case IO_XBAND_KEYBOARD: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1723 { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1724 if (th) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1725 input = 0x1C; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1726 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1727 uint8_t size; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1728 if (port->device.keyboard.mode == KB_SETUP || port->device.keyboard.mode == KB_READ) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1729 switch (port->device.keyboard.tr_counter) |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1730 { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1731 case 0: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1732 input = 0x3; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1733 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1734 case 1: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1735 input = 0x6; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1736 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1737 case 2: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1738 //This is where thoe host indicates a read or write |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1739 //presumably, the keyboard only outputs this if the host |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1740 //is not already driving the data bus low |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1741 input = 0x9; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1742 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1743 case 3: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1744 size = get_scancode_bytes(port); |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1745 if (size) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1746 ++size; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1747 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1748 if (size > 15) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1749 size = 15; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1750 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1751 input = size; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1752 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1753 case 4: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1754 case 5: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1755 //always send packet type 0 for now |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1756 input = 0; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1757 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1758 default: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1759 if (port->device.keyboard.read_pos == 0xFF) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1760 //we've run out of bytes |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1761 input = 0; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1762 } else if (port->device.keyboard.events[port->device.keyboard.read_pos] & 0xFF00) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1763 if (port->device.keyboard.tr_counter & 1) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1764 input = port->device.keyboard.events[port->device.keyboard.read_pos] >> 8 & 0xF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1765 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1766 input = port->device.keyboard.events[port->device.keyboard.read_pos] >> 12; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1767 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1768 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1769 if (port->device.keyboard.tr_counter & 1) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1770 input = port->device.keyboard.events[port->device.keyboard.read_pos] & 0xF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1771 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1772 input = port->device.keyboard.events[port->device.keyboard.read_pos] >> 4; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1773 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1774 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1775 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1776 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1777 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1778 input = 0xF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1779 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1780 input |= ((port->device.keyboard.tr_counter & 1) == 0) << 4; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1781 } |
1453
cd6e566eb6b9
Fix regression in XBAND keyboard support. Fixes ticket:33
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1782 //this is not strictly correct at all times, but good enough for now |
cd6e566eb6b9
Fix regression in XBAND keyboard support. Fixes ticket:33
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1783 device_driven = 0x1F; |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1784 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1785 } |
2235
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1786 case IO_SEGA_MULTI: |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1787 multitap_check_ready(port, current_cycle); |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1788 device_driven = 0x1F; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1789 input = port->input[0]; |
93918a6a8ab7
Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents:
2028
diff
changeset
|
1790 break; |
2238
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1791 case IO_EA_MULTI_A: |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1792 device_driven = 0x3F; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1793 if (port->device.multitap.cur_port == EA_PASSTHRU_MODE) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1794 input = io_data_read(port->device.multitap.ports, current_cycle); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1795 } else if (port->device.multitap.cur_port < 4) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1796 input = io_data_read(port->device.multitap.ports + port->device.multitap.cur_port, current_cycle); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1797 } else { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1798 input = 0x3C; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1799 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1800 break; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1801 case IO_EA_MULTI_B: { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1802 io_port *main_port = port->device.multitap.ports; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1803 if (main_port->device.multitap.cur_port == EA_PASSTHRU_MODE) { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1804 input = io_data_read(main_port->device.multitap.ports + 1, current_cycle); |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1805 device_driven = 0x3F; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1806 } else { |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1807 input = 0; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1808 device_driven = 0; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1809 } |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1810 break; |
0a107b2d5837
Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents:
2235
diff
changeset
|
1811 } |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1812 #ifndef _WIN32 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1813 case IO_SEGA_PARALLEL: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1814 if (!th) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1815 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1816 service_pipe(port); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1817 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1818 input = port->input[th ? IO_TH1 : IO_TH0]; |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1819 device_driven = 0x3F; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1820 break; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1821 case IO_GENERIC: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1822 if (port->input[IO_TH0] & 0x80 && port->input[IO_STATE] == IO_WRITTEN) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1823 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1824 //device requested a blocking read after writes |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1825 port->input[IO_STATE] = IO_READ_PENDING; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1826 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1827 service_socket(port); |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1828 input = port->input[IO_TH0]; |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1829 device_driven = 0x7F; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1830 break; |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1831 #endif |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1832 default: |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1833 input = 0; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1834 device_driven = 0; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1835 break; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1836 } |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1837 uint8_t value = (input & (~control) & device_driven) | (port->output & control); |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1838 //deal with pins that are configured as inputs, but not being actively driven by the device |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1839 uint8_t floating = (~device_driven) & (~control); |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1840 if (floating) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1841 value |= get_output_value(port, current_cycle, SLOW_RISE_INPUT) & floating; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1842 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1843 /*if (port->input[GAMEPAD_TH0] || port->input[GAMEPAD_TH1]) { |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1844 printf ("value: %X\n", value); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1845 }*/ |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1846 return value; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1847 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1848 |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1849 uint8_t io_rx_read(io_port * port, uint32_t current_cycle) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1850 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1851 io_run(port, current_cycle); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1852 port->serial_ctrl &= ~SCTRL_BIT_RX_READY; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1853 return port->serial_in; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1854 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1855 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1856 uint8_t io_sctrl_read(io_port *port, uint32_t current_cycle) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1857 { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1858 io_run(port, current_cycle); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1859 return port->serial_ctrl; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1860 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1861 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1862 uint32_t io_next_interrupt(io_port *port, uint32_t current_cycle) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1863 { |
2524
25e40370e0e4
Fix some IO port serial mode bugs
Michael Pavone <pavone@retrodev.com>
parents:
2422
diff
changeset
|
1864 |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1865 if (port->serial_ctrl & SCTRL_BIT_RX_INTEN) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1866 if (port->serial_ctrl & SCTRL_BIT_RX_READY) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1867 return current_cycle; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1868 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1869 if ((port->serial_ctrl & SCTRL_BIT_RX_ENABLE) && port->receive_end) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1870 return port->receive_end; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1871 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1872 } |
2524
25e40370e0e4
Fix some IO port serial mode bugs
Michael Pavone <pavone@retrodev.com>
parents:
2422
diff
changeset
|
1873 /*if (port->control & 0x80) { |
25e40370e0e4
Fix some IO port serial mode bugs
Michael Pavone <pavone@retrodev.com>
parents:
2422
diff
changeset
|
1874 //TODO: handle external interrupts from TH transitions |
25e40370e0e4
Fix some IO port serial mode bugs
Michael Pavone <pavone@retrodev.com>
parents:
2422
diff
changeset
|
1875 }*/ |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1876 return CYCLE_NEVER; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1877 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1878 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1879 void io_serialize(io_port *port, serialize_buffer *buf) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1880 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1881 save_int8(buf, port->output); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1882 save_int8(buf, port->control); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1883 save_int8(buf, port->serial_out); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1884 save_int8(buf, port->serial_in); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1885 save_int8(buf, port->serial_ctrl); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1886 save_int8(buf, port->device_type); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1887 save_buffer32(buf, port->slow_rise_start, 8); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1888 switch (port->device_type) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1889 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1890 case IO_GAMEPAD6: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1891 save_int32(buf, port->device.pad.timeout_cycle); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1892 save_int16(buf, port->device.pad.th_counter); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1893 break; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1894 case IO_MOUSE: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1895 save_int32(buf, port->device.mouse.ready_cycle); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1896 save_int16(buf, port->device.mouse.last_read_x); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1897 save_int16(buf, port->device.mouse.last_read_y); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1898 save_int16(buf, port->device.mouse.latched_x); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1899 save_int16(buf, port->device.mouse.latched_y); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1900 save_int8(buf, port->device.mouse.tr_counter); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1901 break; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1902 case IO_SATURN_KEYBOARD: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1903 case IO_XBAND_KEYBOARD: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1904 save_int8(buf, port->device.keyboard.tr_counter); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1905 if (port->device_type == IO_XBAND_KEYBOARD) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1906 save_int8(buf, port->device.keyboard.mode); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1907 save_int8(buf, port->device.keyboard.cmd); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1908 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1909 break; |
2028
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1910 case IO_HEARTBEAT_TRAINER: |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1911 save_int8(buf, port->device.heartbeat_trainer.bpm); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1912 save_int8(buf, port->device.heartbeat_trainer.cadence); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1913 save_int8(buf, port->device.heartbeat_trainer.param); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1914 save_int8(buf, port->device.heartbeat_trainer.state); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1915 save_int8(buf, port->device.heartbeat_trainer.status); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1916 save_int8(buf, port->device.heartbeat_trainer.cmd); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1917 save_int8(buf, port->device.heartbeat_trainer.remaining_bytes); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1918 break; |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1919 } |
2028
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1920 save_int32(buf, port->serial_cycle); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1921 save_int32(buf, port->transmit_end); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1922 save_int32(buf, port->receive_end); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1923 save_int8(buf, port->serial_transmitting); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1924 save_int8(buf, port->serial_receiving); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1925 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1926 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1927 void io_deserialize(deserialize_buffer *buf, void *vport) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1928 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1929 io_port *port = vport; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1930 port->output = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1931 port->control = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1932 port->serial_out = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1933 port->serial_in = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1934 port->serial_ctrl = load_int8(buf); |
2028
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1935 set_serial_clock(port); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1936 uint8_t device_type = load_int8(buf); |
2028
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1937 load_buffer32(buf, port->slow_rise_start, 8); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1938 if (device_type != port->device_type) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1939 warning("Loaded save state has a different device type from the current configuration"); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1940 return; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1941 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1942 switch (port->device_type) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1943 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1944 case IO_GAMEPAD6: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1945 port->device.pad.timeout_cycle = load_int32(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1946 port->device.pad.th_counter = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1947 break; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1948 case IO_MOUSE: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1949 port->device.mouse.ready_cycle = load_int32(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1950 port->device.mouse.last_read_x = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1951 port->device.mouse.last_read_y = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1952 port->device.mouse.latched_x = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1953 port->device.mouse.latched_y = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1954 port->device.mouse.tr_counter = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1955 break; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1956 case IO_SATURN_KEYBOARD: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1957 case IO_XBAND_KEYBOARD: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1958 port->device.keyboard.tr_counter = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1959 if (port->device_type == IO_XBAND_KEYBOARD) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1960 port->device.keyboard.mode = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1961 port->device.keyboard.cmd = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1962 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1963 break; |
2028
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1964 case IO_HEARTBEAT_TRAINER: |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1965 port->device.heartbeat_trainer.bpm = load_int8(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1966 port->device.heartbeat_trainer.cadence = load_int8(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1967 port->device.heartbeat_trainer.param = load_int8(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1968 port->device.heartbeat_trainer.state = load_int8(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1969 port->device.heartbeat_trainer.status = load_int8(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1970 port->device.heartbeat_trainer.cmd = load_int8(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1971 port->device.heartbeat_trainer.remaining_bytes = load_int8(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1972 break; |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1973 } |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1974 if (buf->cur_pos < buf->size) { |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1975 port->serial_cycle = load_int32(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1976 port->transmit_end = load_int32(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1977 port->receive_end = load_int32(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1978 port->serial_transmitting = load_int8(buf); |
e597572f45ce
Add new serial state, and Heartbeat Personal Trainer state to save state serialize/deserialize code and fix bug in IO deserialize implementation
Michael Pavone <pavone@retrodev.com>
parents:
2027
diff
changeset
|
1979 port->serial_receiving = load_int8(buf); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1980 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1981 } |