Lua: Fix type confusion between signed and unsigned
[lsnes.git] / bsnes-patches / v085 / 0014-Support-alternate-more-accurate-poll-timings.patch
blobad9be399decc0a22a759c4cb83281cb8d6cf338c
1 From 40c456dadd79cb2c94379fda8b41a4d0ba051ad1 Mon Sep 17 00:00:00 2001
2 From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
3 Date: Sat, 7 Dec 2013 23:32:44 +0200
4 Subject: [PATCH 14/26] Support alternate (more accurate) poll timings
6 ---
7 snes/config/config.cpp | 1 +
8 snes/config/config.hpp | 1 +
9 snes/cpu/timing/joypad.cpp | 40 ++++++++++++++++++++++++++++++++++++++++
10 snes/cpu/timing/timing.cpp | 16 ++++++++++++----
11 snes/cpu/timing/timing.hpp | 1 +
12 snes/snes.hpp | 1 +
13 6 files changed, 56 insertions(+), 4 deletions(-)
15 diff --git a/snes/config/config.cpp b/snes/config/config.cpp
16 index 701af94..206daae 100755
17 --- a/snes/config/config.cpp
18 +++ b/snes/config/config.cpp
19 @@ -13,6 +13,7 @@ Configuration::Configuration() {
20 cpu.ntsc_frequency = 21477272; //315 / 88 * 6000000
21 cpu.pal_frequency = 21281370;
22 cpu.wram_init_value = 0x55;
23 + cpu.alt_poll_timings = false;
25 smp.ntsc_frequency = 24607104; //32040.5 * 768
26 smp.pal_frequency = 24607104;
27 diff --git a/snes/config/config.hpp b/snes/config/config.hpp
28 index 1f4d037..dabde59 100755
29 --- a/snes/config/config.hpp
30 +++ b/snes/config/config.hpp
31 @@ -10,6 +10,7 @@ struct Configuration {
32 unsigned ntsc_frequency;
33 unsigned pal_frequency;
34 unsigned wram_init_value;
35 + bool alt_poll_timings;
36 } cpu;
38 struct SMP {
39 diff --git a/snes/cpu/timing/joypad.cpp b/snes/cpu/timing/joypad.cpp
40 index 6a98de0..ae8e94f 100755
41 --- a/snes/cpu/timing/joypad.cpp
42 +++ b/snes/cpu/timing/joypad.cpp
43 @@ -29,4 +29,44 @@ void CPU::step_auto_joypad_poll() {
47 +//called every 128 clocks; see CPU::add_clocks()
48 +void CPU::step_auto_joypad_poll_NEW(bool polarity) {
49 + if(status.auto_joypad_counter > 0 && status.auto_joypad_counter <= 34) {
50 + if(!status.auto_joypad_latch) {
51 + //FIXME: Is this right, busy flag goes on even if not enabled???
52 + if(status.auto_joypad_counter == 1)
53 + status.auto_joypad_active = true;
54 + if(status.auto_joypad_counter == 34)
55 + status.auto_joypad_active = false;
56 + } else {
57 + if(status.auto_joypad_counter == 1) {
58 + status.auto_joypad_active = true;
59 + input.port1->latch(1);
60 + input.port2->latch(1);
61 + }
62 + if(status.auto_joypad_counter == 3) {
63 + input.port1->latch(0);
64 + input.port2->latch(0);
65 + }
66 + if((status.auto_joypad_counter & 1) != 0 && status.auto_joypad_counter != 1) {
67 + uint2 port0 = input.port1->data();
68 + uint2 port1 = input.port2->data();
70 + status.joy1 = (status.joy1 << 1) | (bool)(port0 & 1);
71 + status.joy2 = (status.joy2 << 1) | (bool)(port1 & 1);
72 + status.joy3 = (status.joy3 << 1) | (bool)(port0 & 2);
73 + status.joy4 = (status.joy4 << 1) | (bool)(port1 & 2);
74 + }
75 + if(status.auto_joypad_counter == 34)
76 + status.auto_joypad_active = false;
77 + }
78 + status.auto_joypad_counter++;
79 + }
80 + if(vcounter() >= (ppu.overscan() == false ? 225 : 240) && status.auto_joypad_counter == 0 && !polarity) {
81 + status.auto_joypad_latch = status.auto_joypad_poll;
82 + status.auto_joypad_counter = 1;
83 + }
87 #endif
88 diff --git a/snes/cpu/timing/timing.cpp b/snes/cpu/timing/timing.cpp
89 index f1378f0..d7cf24f 100755
90 --- a/snes/cpu/timing/timing.cpp
91 +++ b/snes/cpu/timing/timing.cpp
92 @@ -17,10 +17,18 @@ void CPU::add_clocks(unsigned clocks) {
94 step(clocks);
96 - status.auto_joypad_clock += clocks;
97 - if(status.auto_joypad_clock >= 256) {
98 - status.auto_joypad_clock -= 256;
99 - step_auto_joypad_poll();
100 + if(config.cpu.alt_poll_timings) {
101 + bool opolarity = (status.auto_joypad_clock & 128);
102 + status.auto_joypad_clock = (status.auto_joypad_clock + clocks) & 0xFF;
103 + bool npolarity = (status.auto_joypad_clock & 128);
104 + if(opolarity != npolarity)
105 + step_auto_joypad_poll_NEW(opolarity);
106 + } else {
107 + status.auto_joypad_clock += clocks;
108 + if(status.auto_joypad_clock >= 256) {
109 + status.auto_joypad_clock -= 256;
110 + step_auto_joypad_poll();
114 if(status.dram_refreshed == false && hcounter() >= status.dram_refresh_position) {
115 diff --git a/snes/cpu/timing/timing.hpp b/snes/cpu/timing/timing.hpp
116 index 6c225da..bf15a72 100755
117 --- a/snes/cpu/timing/timing.hpp
118 +++ b/snes/cpu/timing/timing.hpp
119 @@ -22,3 +22,4 @@ alwaysinline bool irq_test();
121 //joypad.cpp
122 void step_auto_joypad_poll();
123 +void step_auto_joypad_poll_NEW(bool polarity);
124 diff --git a/snes/snes.hpp b/snes/snes.hpp
125 index 37ed1fe..4e3ba64 100755
126 --- a/snes/snes.hpp
127 +++ b/snes/snes.hpp
128 @@ -1,6 +1,7 @@
129 #ifndef SNES_HPP
130 #define SNES_HPP
131 #define BSNES_SUPPORTS_ADV_BREAKPOINTS
132 +#define BSNES_SUPPORTS_ALT_TIMINGS
134 namespace SNES {
135 namespace Info {
137 2.8.1