1
+ -- Script by amaurea, andymac and feos for FCEUX 2.2.0 and earlier versions.
2
+ -- Allows customizable recording of Frame, Lag, Timer and Input display to AVI dump.
3
+ -- Drag and drop HUD items with mouse, use Numpad 1-6 to switch them on/off.
4
+
5
+ print (" Drag and drop HUD items with mouse, use Numpad 1-6 to switch them on/off." )
6
+
7
+ screen = {w = 256 ,h = 231 }
8
+ move = {object = nil ,offx = 0 ,offy = 0 }
9
+
10
+ pads = {
11
+ {num = 1 ,on = true , color = " red" , x = 9 , y = 220 ,w = 34 ,h = 10 ,toggle = " numpad1" },
12
+ {num = 2 ,on = true , color = " yellow" ,x = 54 , y = 220 ,w = 34 ,h = 10 ,toggle = " numpad2" },
13
+ {num = 3 ,on = false ,color = " green" , x = 99 , y = 220 ,w = 34 ,h = 10 ,toggle = " numpad3" },
14
+ {num = 4 ,on = false ,color = " orange" ,x = 144 ,y = 220 ,w = 34 ,h = 10 ,toggle = " numpad4" }
15
+ }
16
+
17
+ buttons = {
18
+ A = {x = 30 ,y = 5 ,w = 3 ,h = 3 },
19
+ B = {x = 24 ,y = 5 ,w = 3 ,h = 3 },
20
+ select = {x = 18 ,y = 7 ,w = 3 ,h = 1 },
21
+ start = {x = 12 ,y = 7 ,w = 3 ,h = 1 },
22
+ up = {x = 4 , y = 1 ,w = 2 ,h = 2 },
23
+ down = {x = 4 , y = 7 ,w = 2 ,h = 2 },
24
+ left = {x = 1 , y = 4 ,w = 2 ,h = 2 },
25
+ right = {x = 7 , y = 4 ,w = 2 ,h = 2 }
26
+ }
27
+
28
+ text = {on = true ,x = 1 , y = 9 ,w = 30 ,h = 16 ,toggle = " numpad5" }
29
+ timer = {on = true ,x = 197 ,y = 9 ,w = 58 ,h = 7 ,toggle = " numpad6" }
30
+
31
+ function drawpad (pad )
32
+ gui .drawbox ( pad .x , pad .y , pad .x + pad .w , pad .y + pad .h , " #3070ffb0" )
33
+ gui .drawbox ( pad .x + 4 , pad .y + 4 , pad .x + 6 , pad .y + 6 , " black" )
34
+ controller = joypad .read (pad .num )
35
+ for name , b in pairs (buttons ) do
36
+ gui .drawbox ( pad .x + b .x , pad .y + b .y , pad .x + b .x + b .w , pad .y + b .y + b .h ,
37
+ controller [name ] and pad .color or " black" )
38
+ end
39
+ end
40
+
41
+ function mouseover (pad , margin )
42
+ return keys .xmouse >= pad .x - margin and keys .xmouse <= pad .x + pad .w + margin and
43
+ keys .ymouse >= pad .y - margin and keys .ymouse <= pad .y + pad .h + margin
44
+ end
45
+
46
+ function inrange (upper , lower , testval )
47
+ if testval >= upper then return upper
48
+ elseif testval <= lower then return lower
49
+ else return testval
50
+ end
51
+ end
52
+
53
+ function concat (tables )
54
+ local res = {}
55
+ for _ , tab in ipairs (tables ) do
56
+ for _ , val in ipairs (tab ) do
57
+ table.insert (res , val )
58
+ end
59
+ end
60
+ return res
61
+ end
62
+
63
+ prev_keys = input .get ()
64
+ objects = concat ({pads , {text , timer }})
65
+
66
+ function everything ()
67
+ keys = input .get ()
68
+
69
+ -- Are we moving anything around?
70
+ if move .object then
71
+ if keys [" leftclick" ] then
72
+ -- Do not go outside screen
73
+ local safex = inrange (screen .w - move .object .w , 0 , keys .xmouse - move .offx )
74
+ local safey = inrange (screen .h - move .object .h , 8 , keys .ymouse - move .offy )
75
+ move .object .x = safex
76
+ move .object .y = safey
77
+ else move .object = nil end
78
+
79
+ -- Try to pick something up
80
+ elseif keys [" leftclick" ] then
81
+ for _ ,object in ipairs (objects ) do
82
+ if mouseover (object ,0 ) then
83
+ move .object = object
84
+ move .offx = keys .xmouse - object .x
85
+ move .offy = keys .ymouse - object .y
86
+ end
87
+ end
88
+ end
89
+
90
+ -- Toggle displays
91
+ for _ , object in ipairs (objects ) do
92
+ if keys [object .toggle ] and not prev_keys [object .toggle ] then
93
+ object .on = not object .on
94
+ end
95
+ end
96
+
97
+ -- Actually draw the stuff
98
+ if timer .on then
99
+ mins = math.floor (movie .framecount ()/ 3600 )
100
+ secs = movie .framecount ()/ 60 - mins * 60
101
+ gui .text ( timer .x , timer .y , string.format (" %s:%05.2f" ,os.date (" !%H:%M" ,mins * 60 ),secs ), " white" )
102
+ end
103
+
104
+ if text .on then
105
+ local done = movie .mode () == " finished" or movie .mode () == nil
106
+ gui .text ( text .x , text .y , movie .framecount (), done and " red" or " white" )
107
+ gui .text ( text .x , text .y + 9 , FCEU .lagcount (), FCEU .lagged () and " red" or " green" )
108
+ end
109
+
110
+ for _ , pad in ipairs (pads ) do
111
+ if pad .on then drawpad (pad ) end
112
+ end
113
+
114
+ prev_keys = keys
115
+ end
116
+
117
+ gui .register (everything )
118
+
119
+ while (true ) do
120
+ FCEU .frameadvance ()
121
+ end
0 commit comments