Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add some extra RNG to your NES Open experience.
-- NES Open Hard Mode
-- Written by Turbulent Eddie
-- Randomly adjusts the aim, wind speed, and wind direction every few frames
-- Set the RAM pointers
pntrs = {};
pntrs['aim'] = 0x00B7;
pntrs['u_dir'] = 0x0096;
pntrs['u_mag'] = 0x0097;
pntrs['power'] = 0x00D6;
pntrs['curve'] = 0x00D7;
pntrs['ready'] = 0x00FF;
menu = true; -- Only change values while menuing
while (true) do
-- Get the RAM values
vals = {};
for key,value in pairs(pntrs) do
vals[key] = memory.readbyte(value);
end;
-- Every 15th frame (0.25 seconds)
if (emu.framecount() % (60/4) == 0) and menu then
-- Modify the values by a random amount
memory.writebyte(pntrs['aim'], vals['aim'] + math.random(-1, 1)); -- [-1, 0, +1]
memory.writebyte(pntrs['u_dir'], vals['u_dir'] + math.random(-1, 1)*16); -- [-16, 0, +16] (one secondary-intercardinal direction)
memory.writebyte(pntrs['u_mag'], math.max(0, math.min(9, vals['u_mag'] + math.random(-1, 1)))); -- [-1, 0, +1] clamped to [0,9]
end;
-- The wind speed value is not automatically rendered, so write it ourselves,
-- but only when menuing
if (vals['power'] == 48) and (vals['curve'] == 48) and (vals['ready'] == 0) then
gui.box(40, 78, 46, 87, 'black');
gui.text(41, 79, string.format('%1d', memory.readbyte(0x0097)));
menu = true;
else
menu = false;
end;
emu.frameadvance();
end;
@TurbulentEddie

This comment has been minimized.

Copy link
Owner Author

commented Aug 12, 2015

Here are some more RAM locations to play with:

00C9 - Lie:
0: Fairway
1: Tee
2: Rough
3: Sand
4: Water
5: OB
6: Green

00CB - Rough Type:
0: Short
1: Long

00CC - Sand Type:
0: On Top
1: Half Buried
2: Full Buried

0096 - Wind Direction:
0: North
64: East
128: South
192: West

0097 - Wind Speed:
0: Minimum
9: Maximum

00B7 - Direction select:
0: North
64: East
128: South
192: West

00CD - Club select:
0-4: Woods
5-12: Irons
13-14: Wedges
15: Putter

00CE - Speed select:
0: Slow
1: Medium
2: Fast

00D6 - Power select:
48: Minimum power
0: Maximum power

00D7 - Curve select:
00-47: Slice
48: Straight
48-75: Hook

012E - Spin select:
0: Top 2
1: Top 1
2: Normal
3: Back 1
4: Back 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.