forked from mamedev/mame
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathui.tcl
executable file
·162 lines (150 loc) · 4.46 KB
/
ui.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env wish
# set up window
wm title . "Basic MARP GUI"
wm geometry . 600x600
# GUI elements
frame .border -relief groove -borderwidth 5 -padx 5 -pady 5
frame .listframe -relief groove -borderwidth 5 -padx 5 -pady 5
label .txt1 -text "Select game:"
listbox .gamelist -yscrollcommand ".scroll set" -height 800 -font courier
label .txt2 -text "Additional parameters:"
entry .param
label .txt3 -text "INP filename:"
entry .inppath
button .record -text "Record INP"
button .play -text "Play INP"
scrollbar .scroll -orient v -command ".gamelist yview"
button .browse -text "Browse..."
# event procedures
proc click_browse {} {
set ftypes {
{{MAME input logs} {*.inp}}
{{All files} {*}}
}
set filename [tk_getOpenFile -filetypes $ftypes]
.inppath delete 0 end ;# clear entry box
.inppath insert 0 $filename
}
proc click_record {} {
global cmdfilename
global gamelistshortnames
global nullfile
set sel [.gamelist curselection]
if { $sel == "" } {
tk_messageBox -message "Please select a game from the list"
return
}
if { [.inppath get] == "" } {
tk_messageBox -message "Please enter an INP filename to record to"
return
}
if { [string match "*.inp" [.inppath get]] == 0} {
tk_messageBox -message "INP filenames require the .inp extension"
return
}
set index [lindex $sel 0]
set command $cmdfilename
append command " "
append command [lindex $gamelistshortnames $index]
append command " -record "
append command [.inppath get]
append command " -nvram_directory "
append command $nullfile
append command " "
append command [.param get]
tk_messageBox -message $command
set reccmd [open $command r]
set output [read $reccmd]
close $reccmd
tk_messageBox -title "Console output" -message $output
}
proc click_playback {} {
global cmdfilename
global gamelistshortnames
global nullfile
set sel [.gamelist curselection]
if { $sel == "" } {
tk_messageBox -message "Please select a game from the list"
return
}
if { [.inppath get] == "" } {
tk_messageBox -message "Please enter an INP filename to playback"
return
}
if { [string match "*.inp" [.inppath get]] == 0} {
tk_messageBox -message "INP filenames require the .inp extension"
return
}
set index [lindex $sel 0]
set command $cmdfilename
append command " "
append command [lindex $gamelistshortnames $index]
append command " -playback "
append command [.inppath get]
append command " -nvram_directory "
append command $nullfile
append command " "
append command [.param get]
tk_messageBox -message $command
set playcmd [open $command r]
set output [read $playcmd]
close $playcmd
tk_messageBox -title "Console output" -message $output
}
# figure out if we're using a 32-bit or 64-bit version of MAME
set cmdfilename "|./mame"
if { [catch {exec ./mame -help}] } {
set cmdfilename "|./mame64"
if { [catch {exec ./mame64 -help}] } {
set cmdfilename "none"
tk_messageBox -title "Error" -type ok -message "Cannot find a MAME executable."
exit 1
}
}
# figure out the platform we are running on
global tcl_platform
switch -glob -- [lindex $tcl_platform(os) 0] {
Win* {
set nullfile "NUL" ;# Windows
}
default {
set nullfile "/dev/null" ;# everything else (except maybe old Macs)
}
}
# populate listbox
set gamelistitems [list]
set gamelistshortnames [list]
set cmdline $cmdfilename
append cmdline " -listfull"
set cmd [open $cmdline r]
# TODO: handle ini parsing errors, which will screw this up
gets $cmd ;# ignore first line, it contains the headers
while {[gets $cmd line] >= 0} {
set gamedata [split $line "\t\""]
set str [string trim [lindex $gamedata 0] " "]
lappend gamelistshortnames $str
lappend gamelistitems [lindex $gamedata 1]
set listtext [lindex $gamedata 0]
append listtext [lindex $gamedata 1]
.gamelist insert end $listtext
}
close $cmd
# GUI management
grid columnconfigure . {0 1 2 3 4} -weight 1
grid columnconfigure . 5 -weight 0
grid rowconfigure . {0 2 3 4 5 6} -weight 0
grid rowconfigure . 1 -weight 3
grid .txt1 -row 0 -column 0 -columnspan 6
grid .gamelist -row 1 -column 0 -columnspan 5 -sticky ew
grid .scroll -row 1 -column 5 -sticky nse
grid .txt3 -row 2 -column 0 -columnspan 6
grid .inppath -row 3 -column 0 -columnspan 6 -sticky ew
#grid .browse -row 3 -column 4 -columnspan 2 -sticky nsew
grid .txt2 -row 4 -column 0 -columnspan 6
grid .param -row 5 -column 0 -columnspan 6 -sticky ew
grid .record -row 6 -column 1
grid .play -row 6 -column 3
# event bindings
#bind .browse <ButtonPress-1> { click_browse }
bind .record <ButtonPress-1> { click_record }
bind .play <ButtonPress-1> { click_playback }