1 Utility utility;
2
3 #include "system-state.cpp"
4 #include "window.cpp"
5
inputEvent(uint16_t scancode)6 void Utility::inputEvent(uint16_t scancode) {
7 //release mouse capture if escape key is pressed on any keyboard
8 for(unsigned i = 0; i < Keyboard::Count; i++) {
9 if(scancode == keyboard(i)[Keyboard::Escape] && mapper().state(scancode)) {
10 if(mainWindow->isActive() && input.acquired()) {
11 input.unacquire();
12 return;
13 }
14 }
15 }
16 }
17
18 //display message in main window statusbar area for three seconds
showMessage(const char * message)19 void Utility::showMessage(const char *message) {
20 mainWindow->statusBar->showMessage(string() << message, 3000);
21 }
22
23 //updates system state text at bottom-right of main window statusbar
updateSystemState()24 void Utility::updateSystemState() {
25 string text;
26
27 if(SNES::cartridge.loaded() == false) {
28 text = "No cartridge loaded";
29 } else if(application.power == false) {
30 text = "Power off";
31 } else if(application.pause == true || application.autopause == true) {
32 text = "Paused";
33 } else if(SNES::ppu.status.frames_updated == true) {
34 SNES::ppu.status.frames_updated = false;
35 text << SNES::ppu.status.frames_executed;
36 text << " fps";
37 } else {
38 //nothing to update
39 return;
40 }
41
42 mainWindow->systemState->setText(text);
43 }
44
acquireMouse()45 void Utility::acquireMouse() {
46 if(SNES::cartridge.loaded()) {
47 if(SNES::config.controller_port1 == SNES::Input::DeviceMouse
48 || SNES::config.controller_port2 == SNES::Input::DeviceMouse
49 || SNES::config.controller_port2 == SNES::Input::DeviceSuperScope
50 || SNES::config.controller_port2 == SNES::Input::DeviceJustifier
51 || SNES::config.controller_port2 == SNES::Input::DeviceJustifiers
52 ) input.acquire();
53 }
54 }
55
unacquireMouse()56 void Utility::unacquireMouse() {
57 input.unacquire();
58 }
59
updateAvSync()60 void Utility::updateAvSync() {
61 video.set(Video::Synchronize, config().video.synchronize);
62 audio.set(Audio::Synchronize, config().audio.synchronize);
63 }
64
updateVideoMode()65 void Utility::updateVideoMode() {
66 if(config().video.context->region == 0) {
67 SNES::video.set_mode(SNES::Video::ModeNTSC);
68 } else {
69 SNES::video.set_mode(SNES::Video::ModePAL);
70 }
71 }
72
updateColorFilter()73 void Utility::updateColorFilter() {
74 filter.contrast = config().video.contrastAdjust;
75 filter.brightness = config().video.brightnessAdjust;
76 filter.gamma = 100 + config().video.gammaAdjust;
77 filter.gamma_ramp = config().video.enableGammaRamp;
78 filter.colortable_update();
79 }
80
updatePixelShader()81 void Utility::updatePixelShader() {
82 string filedata;
83
84 if(filedata.readfile(config().path.fragmentShader)) {
85 video.set(Video::FragmentShader, (const char*)filedata);
86 } else {
87 video.set(Video::FragmentShader, (const char*)0);
88 }
89
90 if(filedata.readfile(config().path.vertexShader)) {
91 video.set(Video::VertexShader, (const char*)filedata);
92 } else {
93 video.set(Video::VertexShader, (const char*)0);
94 }
95 }
96
updateHardwareFilter()97 void Utility::updateHardwareFilter() {
98 video.set(Video::Filter, config().video.context->hwFilter);
99 }
100
updateSoftwareFilter()101 void Utility::updateSoftwareFilter() {
102 filter.renderer = config().video.context->swFilter;
103 }
104
updateEmulationSpeed()105 void Utility::updateEmulationSpeed() {
106 config().system.speed = max(0, min(4, (signed)config().system.speed));
107
108 double scale[] = {
109 config().system.speedSlowest / 100.0,
110 config().system.speedSlow / 100.0,
111 config().system.speedNormal / 100.0,
112 config().system.speedFast / 100.0,
113 config().system.speedFastest / 100.0,
114 };
115 unsigned outfreq = config().audio.outputFrequency;
116 unsigned infreq = config().audio.inputFrequency * scale[config().system.speed] + 0.5;
117
118 audio.set(Audio::Resample, true); //always resample (required for volume adjust + frequency scaler)
119 audio.set(Audio::ResampleRatio, (double)infreq / (double)outfreq);
120 }
121
updateControllers()122 void Utility::updateControllers() {
123 SNES::input.port_set_device(0, SNES::config.controller_port1);
124 SNES::input.port_set_device(1, SNES::config.controller_port2);
125
126 switch(config().input.port1) { default:
127 case ControllerPort1::None: mapper().port1 = 0; break;
128 case ControllerPort1::Gamepad: mapper().port1 = &Controllers::gamepad1; break;
129 case ControllerPort1::Asciipad: mapper().port1 = &Controllers::asciipad1; break;
130 case ControllerPort1::Multitap: mapper().port1 = &Controllers::multitap1; break;
131 case ControllerPort1::Mouse: mapper().port1 = &Controllers::mouse1; break;
132 }
133
134 switch(config().input.port2) { default:
135 case ControllerPort2::None: mapper().port2 = 0; break;
136 case ControllerPort2::Gamepad: mapper().port2 = &Controllers::gamepad2; break;
137 case ControllerPort2::Asciipad: mapper().port2 = &Controllers::asciipad2; break;
138 case ControllerPort2::Multitap: mapper().port2 = &Controllers::multitap2; break;
139 case ControllerPort2::Mouse: mapper().port2 = &Controllers::mouse2; break;
140 case ControllerPort2::SuperScope: mapper().port2 = &Controllers::superscope; break;
141 case ControllerPort2::Justifier: mapper().port2 = &Controllers::justifier1; break;
142 case ControllerPort2::Justifiers: mapper().port2 = &Controllers::justifiers; break;
143 }
144
145 mainWindow->syncUi();
146 }
147