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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
|
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
var slot_info = Object.create(null);
var bios_sets = Object.create(null);
var machine_flags = Object.create(null);
function make_slot_popup_id(name) { return ('select-slot-choice-' + name).replace(/:/g, '-'); }
function get_slot_popup(name) { return document.getElementById(make_slot_popup_id(name)); }
function update_cmd_preview()
{
var inifmt = document.getElementById('select-options-format').value == 'ini';
var result = '';
var first = true;
function add_option(flag, value)
{
if (first)
first = false;
else if (inifmt)
result += '\n';
else
result += ' ';
if (inifmt)
{
result += flag + ' ';
if (flag.length < 25)
result += ' '.repeat(25 - flag.length);
result += value;
}
else
{
result += '-' + flag + ' ';
if (value == '')
result += '""';
else
result += value;
}
}
var elide_defaults = !document.getElementById('check-explicit-defaults').checked;
// add system BIOS if applicable
var sysbios = document.getElementById('select-system-bios');
if (sysbios && (!elide_defaults || (sysbios.selectedOptions[0].getAttribute('data-isdefault') != 'yes')))
add_option('bios', sysbios.value);
// add RAM option if applicable
var ramopt = document.getElementById('select-ram-option');
if (ramopt && (!elide_defaults || (ramopt.selectedOptions[0].getAttribute('data-isdefault') != 'yes')))
add_option('ramsize', ramopt.value);
var slotslist = document.getElementById('list-slot-options');
if (slotslist)
{
for (var item = slotslist.firstChild; item; item = item.nextSibling)
{
if (item.nodeName == 'DT')
{
// need to set the slot option if it has non-default card and/or non-default card BIOS
var slotname = item.getAttribute('data-slotname');
var selection = get_slot_popup(slotname).selectedOptions[0];
var biospopup = document.getElementById(('select-slot-bios-' + slotname).replace(/:/g, '-'));
var defcard = selection.getAttribute('data-isdefault') == 'yes';
var defbios = !biospopup || (biospopup.selectedOptions[0].getAttribute('data-isdefault') == 'yes');
if (!elide_defaults || !defcard || !defbios)
{
var card = selection.value;
add_option(slotname, card + ((biospopup && (!elide_defaults || !defbios)) ? (',bios=' + biospopup.value) : ''));
}
}
}
}
// replace the preview with appropriate element
var target = document.getElementById('para-cmd-preview');
var replacement = document.createElement(inifmt ? 'pre' : 'tt');
replacement.setAttribute('id', 'para-cmd-preview');
replacement.textContent = result;
target.parentNode.replaceChild(replacement, target);
}
function set_default_system_bios()
{
// search for an explicit default option
var sysbios = document.getElementById('select-system-bios');
var len = sysbios.options.length;
for (var i = 0; i < len; i++)
{
if (sysbios.options[i].getAttribute('data-isdefault') == 'yes')
{
// select it and add a button for restoring it
sysbios.selectedIndex = i;
var dflt = make_restore_default_button('default', 'btn-def-system-bios', sysbios, i);
sysbios.onchange = make_slot_bios_change_handler(dflt);
sysbios.parentNode.appendChild(document.createTextNode(' '));
sysbios.parentNode.appendChild(dflt);
break;
}
}
update_cmd_preview();
}
function set_default_ram_option()
{
// search for an explicit default option
var ramopt = document.getElementById('select-ram-option');
var len = ramopt.options.length;
for (var i = 0; i < len; i++)
{
if (ramopt.options[i].getAttribute('data-isdefault') == 'yes')
{
// select it and add a button for restoring it
ramopt.selectedIndex = i;
var dflt = make_restore_default_button('default', 'btn-def-ram-option', ramopt, i);
ramopt.onchange = make_slot_bios_change_handler(dflt);
ramopt.parentNode.appendChild(document.createTextNode(' '));
ramopt.parentNode.appendChild(dflt);
break;
}
}
update_cmd_preview();
}
var fetch_bios_sets = (function ()
{
var pending = Object.create(null);
return function (device)
{
if (!Object.prototype.hasOwnProperty.call(bios_sets, device) && !Object.prototype.hasOwnProperty.call(pending, device))
{
pending[device] = true;
var req = new XMLHttpRequest();
req.open('GET', appurl + 'rpc/bios/' + device, true);
req.responseType = 'json';
req.onload =
function ()
{
delete pending[device];
if (req.status == 200)
{
bios_sets[device] = req.response;
var slotslist = document.getElementById('list-slot-options');
if (slotslist)
{
for (var item = slotslist.firstChild; item; item = item.nextSibling)
{
if ((item.nodeName == 'DT') && (item.getAttribute('data-slotcard') == device))
add_bios_row(item.getAttribute('data-slotname'), item.nextSibling.firstChild, device);
}
}
}
};
req.send();
}
};
})();
var fetch_machine_flags = (function ()
{
var pending = Object.create(null);
return function (device)
{
if (!Object.prototype.hasOwnProperty.call(machine_flags, device) && !Object.prototype.hasOwnProperty.call(pending, device))
{
pending[device] = true;
var req = new XMLHttpRequest();
req.open('GET', appurl + 'rpc/flags/' + device, true);
req.responseType = 'json';
req.onload =
function ()
{
delete pending[device];
if (req.status == 200)
{
machine_flags[device] = req.response;
var slotslist = document.getElementById('list-slot-options');
if (slotslist)
{
for (var item = slotslist.firstChild; item; item = item.nextSibling)
{
if ((item.nodeName == 'DT') && (item.getAttribute('data-slotcard') == device))
add_flag_rows(item.nextSibling.firstChild, device);
}
}
}
};
req.send();
}
};
})();
function add_flag_rows(table, device)
{
var sorted_features = Object.keys(machine_flags[device].features).sort();
var imperfect = [], unemulated = [];
var len = sorted_features.length;
for (var i = 0; i < len; i++)
((machine_flags[device].features[sorted_features[i]].overall == 'unemulated') ? unemulated : imperfect).push(sorted_features[i]);
function add_one(flags, title)
{
var len = flags.length;
if (len > 0)
{
var row = document.createElement('tr');
row.appendChild(document.createElement('th')).textContent = title;
var cell = row.appendChild(document.createElement('td'));
cell.textContent = flags[0];
for (i = 1; i < len; i++)
cell.textContent += ', ' + flags[i];
if (table.lastChild.getAttribute('class') == 'devbios')
table.insertBefore(row, table.lastChild);
else
table.appendChild(row);
}
}
add_one(unemulated, 'Unemulated features:');
add_one(imperfect, 'Imperfect features:');
}
function add_bios_row(slot, table, device)
{
var sorted_sets = Object.keys(bios_sets[device]).sort();
var len = sorted_sets.length;
if (len > 0)
{
// create table row, add heading
var row = document.createElement('tr');
row.setAttribute('class', 'devbios');
row.appendChild(document.createElement('th')).textContent = 'BIOS:';
var cell = document.createElement('td');
// make the BIOS popul itself
var popup = document.createElement('select');
popup.setAttribute('id', ('select-slot-bios-' + slot).replace(/:/g, '-'));
for (var i = 0; i < len; i++)
{
var set = sorted_sets[i];
var detail = bios_sets[device][set];
var option = document.createElement('option');
option.setAttribute('value', set);
option.setAttribute('data-isdefault', detail.isdefault ? 'yes' : 'no');
option.textContent = set + ' - ' + detail.description;
popup.appendChild(option);
if (detail.isdefault)
popup.selectedIndex = i;
}
cell.appendChild(popup);
// make a button to restore the default
var dflt;
if (popup.selectedOptions[0].getAttribute('data-isdefault') == 'yes')
{
dflt = make_restore_default_button('default', ('btn-def-slot-bios-' + slot).replace(/:/g, '-'), popup, popup.selectedIndex);
cell.appendChild(document.createTextNode(' '))
cell.appendChild(dflt);
}
// drop the controls into a cell, add it to the table, keep the command line preview up-to-date
popup.onchange = make_slot_bios_change_handler(dflt);
row.appendChild(cell);
table.appendChild(row);
update_cmd_preview();
}
}
function make_slot_term(name, slot, defaults)
{
var len, i;
// see if we can find a default, outer layers take precedence
var defcard = '';
len = defaults.length;
for (i = 0; (i < len) && (defcard == ''); i++)
{
if (Object.prototype.hasOwnProperty.call(defaults[i], name))
defcard = defaults[i][name];
}
// create a container with the slot name and popup
var term = document.createElement('dt');
term.setAttribute('id', ('item-slot-choice-' + name).replace(/:/g, '-'));
term.setAttribute('data-slotname', name);
term.setAttribute('data-slotcard', '');
term.textContent = name + ': ';
var popup = document.createElement('select');
popup.setAttribute('id', make_slot_popup_id(name));
term.appendChild(popup);
// add the empty slot option
var option = document.createElement('option');
option.setAttribute('value', '');
option.setAttribute('data-isdefault', ('' == defcard) ? 'yes' : 'no');
option.textContent = '-';
popup.appendChild(option);
popup.selectedIndex = 0;
// add options for the cards
var sorted_choices = Object.keys(slot).sort();
len = sorted_choices.length;
for (i = 0; i < len; i++)
{
var choice = sorted_choices[i];
var card = slot[choice];
option = document.createElement('option');
option.setAttribute('value', choice);
option.setAttribute('data-isdefault', (choice == defcard) ? 'yes' : 'no');
option.textContent = choice + ' - ' + card.description;
popup.appendChild(option);
if (choice == defcard)
popup.selectedIndex = i + 1;
}
// make a button for restoring the default and hook up events
var dflt = make_restore_default_button('default', ('btn-def-slot-choice-' + name).replace(/:/g, '-'), popup, popup.selectedIndex);
term.appendChild(document.createTextNode(' '));
term.appendChild(dflt);
popup.onchange = make_slot_change_handler(name, slot, defaults, dflt);
return term;
}
function add_slot_items(root, device, defaults, slotslist, pos)
{
// add another layer of defaults for this device
var defvals = Object.create(null);
for (var key in slot_info[device].defaults)
defvals[root + key] = slot_info[device].defaults[key];
defaults = defaults.slice();
defaults.push(defvals);
var defcnt = defaults.length;
// add controls for each subslot
var slots = slot_info[device].slots;
var sorted_slots = Object.keys(slots).sort();
var len = sorted_slots.length;
for (var i = 0; i < len; i++)
{
var slotname = sorted_slots[i];
var slotabs = root + slotname;
var slot = slots[slotname];
var term = make_slot_term(slotabs, slot, defaults);
var def = document.createElement('dd');
def.setAttribute('id', ('item-slot-detail-' + slotabs).replace(/:/g, '-'));
if (pos)
{
slotslist.insertBefore(term, pos);
slotslist.insertBefore(def, pos);
}
else
{
slotslist.appendChild(term);
slotslist.appendChild(def);
}
// force a change event to populate subslot controls if the default isn't empty
get_slot_popup(slotabs).dispatchEvent(new Event('change'));
}
update_cmd_preview();
}
function make_slot_change_handler(name, slot, defaults, dfltbtn)
{
var selection = null;
return function (event)
{
var choice = event.target.value;
var slotslist = event.target.parentNode.parentNode;
var def = event.target.parentNode.nextSibling;
var slotname = event.target.parentNode.getAttribute('data-slotname');
selection = (choice == '') ? null : slot[choice];
dfltbtn.disabled = event.target.selectedOptions[0].getAttribute('data-isdefault') == 'yes';
// clear out any subslots from previous selection
var prefix = slotname + ':';
for (var candidate = def.nextSibling; candidate && candidate.getAttribute('data-slotname').startsWith(prefix); )
{
var next = candidate.nextSibling;
slotslist.removeChild(candidate);
candidate = next.nextSibling;
slotslist.removeChild(next);
}
if (selection === null)
{
// no selection, remove the slot card details table
event.target.parentNode.setAttribute('data-slotcard', '');
if (def.firstChild)
def.removeChild(def.firstChild);
}
else
{
// stash the selected device where it's easy to find
event.target.parentNode.setAttribute('data-slotcard', selection.device);
// create details table and add a link to the device's page
var tbl = document.createElement('table');
tbl.setAttribute('class', 'sysinfo');
var row = tbl.appendChild(document.createElement('tr'));
row.appendChild(document.createElement('th')).textContent = 'Short name:';
var link = row.appendChild(document.createElement('td')).appendChild(document.createElement('a'));
link.textContent = selection.device;
link.setAttribute('href', appurl + 'machine/' + selection.device);
// if we have emulation flags, populate now, otherwise fetch asynchronously
if (!Object.prototype.hasOwnProperty.call(machine_flags, selection.device))
fetch_machine_flags(selection.device);
else
add_flag_rows(tbl, selection.device);
// if we have BIOS details, populate now, otherwise fetch asynchronously
if (!Object.prototype.hasOwnProperty.call(bios_sets, selection.device))
fetch_bios_sets(selection.device);
else
add_bios_row(slotname, tbl, selection.device);
// drop the details table into the list
if (def.firstChild)
def.replaceChild(tbl, def.firstChild);
else
def.appendChild(tbl);
// create controls for subslots
add_slot_items(slotname + ':' + choice, selection.device, defaults, slotslist, def.nextSibling);
}
update_cmd_preview();
};
}
function make_slot_bios_change_handler(dflt)
{
return function (event)
{
if (dflt)
dflt.disabled = event.target.selectedOptions[0].getAttribute('data-isdefault') == 'yes';
update_cmd_preview();
}
}
function populate_slots(machine)
{
var placeholder = document.getElementById('para-slots-placeholder');
var slotslist = document.createElement('dl');
slotslist.setAttribute('id', 'list-slot-options');
placeholder.parentNode.replaceChild(slotslist, placeholder);
add_slot_items('', machine, [], slotslist, null);
}
function slot_retrieve_error(device)
{
var errors;
var placeholder = document.getElementById('para-slots-placeholder');
if (placeholder)
{
errors = document.createElement('div');
errors.setAttribute('id', 'div-slots-errors');
placeholder.parentNode.replaceChild(errors, placeholder);
}
else
{
errors = document.getElementById('div-slots-errors');
}
var message = document.createElement('p');
message.textContent = 'Error retrieving slot information for ' + device + '.';
errors.appendChild(message);
}
function fetch_slots(machine)
{
function make_request(device)
{
var req = new XMLHttpRequest();
req.open('GET', appurl + 'rpc/slots/' + device, true);
req.responseType = 'json';
req.onload =
function ()
{
if (req.status == 200)
{
slot_info[device] = req.response;
delete pending[device];
for (var slotname in req.response.slots)
{
var slot = req.response.slots[slotname];
for (var choice in slot)
{
var card = slot[choice].device
if (!Object.prototype.hasOwnProperty.call(slot_info, card) && !Object.prototype.hasOwnProperty.call(pending, card))
{
pending[card] = true;
make_request(card);
}
}
}
if (!Object.keys(pending).length)
populate_slots(machine);
}
else
{
slot_retrieve_error(device);
}
};
req.send();
}
var pending = Object.create(null);
pending[machine] = true;
make_request(machine);
}
|