Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/NES/RBIBaseball.lua
2 views
1
--RBI Baseball script
2
--Written by adelikat
3
--Shows stats and information on screen and can even change a batter or pitcher's hand
4
5
local PitchingScreenAddr = 0x001A;
6
local PitchingScreen;
7
8
local p1PitchHealthAddr = 0x060D;
9
local p1PitchHealth;
10
11
local p2PitchHealthAddr = 0x061D;
12
local p2PitchHealth;
13
14
local p1OutsAddr = 0x0665;
15
local p1Outs;
16
17
local pitchtypeAddr = 0x0112;
18
local pitchtype;
19
20
local P1currHitterPowerAddr = 0x062B --2 byte
21
local P1currSpeedAddr = 0x062D
22
local P1currContactAddr = 0x062A
23
24
local P2currHitterPowerAddr = 0x063B --2 byte
25
local P2currSpeedAddr = 0x063D
26
local P2currContactAddr = 0x063A
27
28
local topinningAddr = 0x0115
29
30
--Extra Ram map notes
31
--0627 = P1 Batter Lefy or Righty (even or odd)
32
--0628 = P1 Bat average 150 + this address
33
--0629 = P1 # of Home Runs
34
--0638 = P2 Bat average 2 150 + this address
35
--0639 = P2 # of Home Runs
36
--0637 = P2 Batter Lefy or Righty (even or odd)
37
38
--060x = P1 pitcher, 061x = P2 pitcher
39
40
--0607 =
41
--Right digit = P1 Pitcher Lefty or Right (even or odd)
42
--Left digit = P1 Pitcher drop rating
43
44
--0609 = P1 Sinker ball speed
45
--060A = P1 Regular ball Speed
46
--060B = P1 Fastball Speed
47
--060C = P1 Pitcher Curve rating left digit is curve left, right is curve right
48
49
--0114 = Current Inning
50
--0115 = 10 if bottom of inning, 0 if on top, controls which player can control the batter
51
52
--0728 & 0279 - In charge of inning music
53
54
--TODO
55
--A hotkeys for boosting/lowering current pitcher (p1 or 2) health
56
--fix pitcher L/R switching to not kill the left digit (drop rating) in the process
57
--Do integer division on curve rating
58
--Outs display is wrong
59
--Music on/off toggle
60
61
console.writeline("RBI Baseball script");
62
console.writeline("Written by adelikat");
63
console.writeline("Description: Shows stats and information on screen and can even change a batter or pitcher's hand");
64
console.writeline("\nHotkeys: ");
65
console.writeline("Toggle Hand of player 2: \nH/J");
66
console.writeline("Toggle Hand of player 1: \nK/L");
67
68
function P1BoostHitter()
69
mainmemory.write_u16_le(0x062B, mainmemory.read_u16_le(0x062B) + 128);
70
end
71
72
function P1DropHitter()
73
mainmemory.write_u16_le(0x062B, mainmemory.read_u16_le(0x062B) - 128);
74
end
75
76
function P2BoostHitter()
77
mainmemory.write_u16_le(0x063B, mainmemory.read_u16_le(0x063B) + 128);
78
end
79
80
function P2DropHitter()
81
mainmemory.write_u16_le(0x063B, mainmemory.read_u16_le(0x063B) - 128);
82
end
83
84
function SwitchP1LHand()
85
if (inningtb == 0x10) then
86
mainmemory.write_u8(0x0607, 0)
87
end
88
if (inningtb == 0) then
89
mainmemory.write_u8(0x0627, 0)
90
end
91
end
92
93
function SwitchP1RHand()
94
if (inningtb == 0x10) then
95
mainmemory.write_u8(0x0607, 1)
96
end
97
if (inningtb == 0) then
98
mainmemory.write_u8(0x0627, 1)
99
end
100
end
101
102
function SwitchP2LHand()
103
if (inningtb == 0x0) then
104
mainmemory.write_u8(0x0617, 0)
105
end
106
if (inningtb == 0x10) then
107
mainmemory.write_u8(0x0637, 0)
108
end
109
end
110
111
function SwitchP2RHand()
112
if (inningtb == 0x0) then
113
mainmemory.write_u8(0x0617, 1)
114
end
115
if (inningtb == 0x10) then
116
mainmemory.write_u8(0x0637, 1)
117
end
118
end
119
120
h_window = forms.newform(345, 205, "RBI Lua");
121
122
label_p1switch = forms.label(h_window, "Player 1", 10, 5);
123
124
label_p1switch = forms.label(h_window, "Switch Player Hand", 10, 35);
125
h_toggleP1L = forms.button(h_window, "Left", SwitchP1LHand, 10, 60, 50, 23);
126
h_toggleP1R = forms.button(h_window, "Right", SwitchP1RHand, 70, 60, 50, 23);
127
label_p1switch = forms.label(h_window, "Batter Power", 10, 100);
128
h_toggleP1R = forms.button(h_window, "More!", P1BoostHitter, 10, 125, 50, 23);
129
h_toggleP1R = forms.button(h_window, "Less", P1DropHitter, 70, 125, 50, 23);
130
131
label_p2switch = forms.label(h_window, "Player 2", 160, 5);
132
label_p2switch = forms.label(h_window, "Switch Player Hand", 160, 35);
133
h_toggleP2L = forms.button(h_window, "Left", SwitchP2LHand, 160, 60, 50, 23);
134
h_toggleP2R = forms.button(h_window, "Right", SwitchP2RHand, 160, 60, 50, 23);
135
label_p2switch = forms.label(h_window, "Batter Power", 160, 100);
136
h_toggleP2R = forms.button(h_window, "More!", P2BoostHitter, 160, 125, 50, 23);
137
h_toggleP2R = forms.button(h_window, "Less", P2DropHitter, 220, 125, 50, 23);
138
139
140
141
142
while true do
143
144
mainmemory.write_u8(0x0726, 0) --Turn of inning music
145
mainmemory.write_u8(0x0727, 0)
146
mainmemory.write_u8(0x0728, 0)
147
mainmemory.write_u8(0x0729, 0)
148
149
inningtb = mainmemory.read_u8(topinningAddr);
150
i = input.get();
151
152
--Switch P1 batter hands
153
if (i.K == true) then
154
SwitchP1LHand()
155
end
156
157
if (i.L == true) then
158
SwitchP1RHand();
159
end
160
161
--Switch P2 batter hands
162
if (i.H == true) then
163
SwitchP2LHand();
164
end
165
166
if (i.J == true) then
167
SwitchP2RHand();
168
end
169
170
PitchingScreen = mainmemory.read_u8(PitchingScreenAddr);
171
172
-------------------------------------------------------
173
if (PitchingScreen == 0x003E) then
174
175
176
pitchtype = mainmemory.read_u8(pitchtypeAddr);
177
178
--What the pitcher will pitch
179
if (pitchtype == 0) then
180
gui.text(0,0,"Sinker!!", null, null, "bottomright");
181
end
182
if (pitchtype == 2) then
183
gui.text(0,0, "Fast Ball", null, null, "bottomright")
184
end
185
if (pitchtype == 1) then
186
gui.text(0,0,"Regular Pitch", null, null, "bottomright")
187
end
188
189
--Top of Inning
190
if (inningtb == 0) then
191
gui.text(0,0, "Health " .. mainmemory.read_u8(0x061D), null, null, "topright")
192
gui.text(0,12,"Drop " .. mainmemory.read_u8(0x0617) % 16, null, null, "topright")
193
gui.text(0,24,"CurveL " .. mainmemory.read_u8(0x061C) / 16, null, null, "topright")
194
gui.text(0,36,"CurveR " .. mainmemory.read_u8(0x061C) % 16, null, null, "topright")
195
gui.text(0,48,"Fast SP " .. mainmemory.read_u8(0x061B), null, null, "topright")
196
gui.text(0,60,"Reg SP " .. mainmemory.read_u8(0x061A), null, null, "topright")
197
gui.text(0,72,"Sink SP " .. mainmemory.read_u8(0x0619), null, null, "topright")
198
199
P1currPower = mainmemory.read_u8(P1currHitterPowerAddr) + (mainmemory.read_u8(P1currHitterPowerAddr+1) * 256);
200
gui.text(0,108, "Power: " .. P1currPower, null, null, "topright");
201
P1currSpeed = mainmemory.read_u8(P1currSpeedAddr);
202
gui.text(0,120, "Speed: " .. P1currSpeed, null, null, "topright");
203
P1currCt = mainmemory.read_u8(P1currContactAddr);
204
gui.text(0,132, "Contact: " .. P1currCt, null, null, "topright");
205
end
206
207
--Bottom of Inning
208
if (inningtb == 0x10) then
209
gui.text(0,0,"Health " .. mainmemory.read_u8(0x060D), null, null, "topright")
210
gui.text(0,12,"Drop " .. mainmemory.read_u8(0x0607) % 16, null, null, "topright")
211
gui.text(0,24,"CurveL " .. mainmemory.read_u8(0x060C) / 16, null, null, "topright")
212
gui.text(0,36,"CurveR " .. mainmemory.read_u8(0x060C) % 16, null, null, "topright")
213
gui.text(0,48,"Fast SP " .. mainmemory.read_u8(0x060B), null, null, "topright")
214
gui.text(0,60,"Reg SP " .. mainmemory.read_u8(0x060A), null, null, "topright")
215
gui.text(0,72,"Sink SP " .. mainmemory.read_u8(0x0609), null, null, "topright")
216
217
P2currPower = mainmemory.read_u8(P2currHitterPowerAddr) + (mainmemory.read_u8(P2currHitterPowerAddr+1) * 256);
218
gui.text(0,108, "Power: " .. P2currPower, null, null, "topright");
219
P2currSpeed = mainmemory.read_u8(P2currSpeedAddr);
220
gui.text(0,120, "Speed: " .. P2currSpeed, null, null, "topright");
221
P2currCt = mainmemory.read_u8(P2currContactAddr);
222
gui.text(0,132, "Contact: " .. P2currCt, null, null, "topright");
223
end
224
225
end
226
-------------------------------------------------------
227
228
if (PitchingScreen == 0x0036) then
229
230
p1Outs = mainmemory.read_u8(p1OutsAddr);
231
gui.text(0,0, "Outs " .. p1Outs, null, null, "topright");
232
233
end
234
-------------------------------------------------------
235
236
emu.frameadvance()
237
238
end
239