| 1 | #include "../ethos.hpp" |
| 2 | Interface* interface = nullptr; |
| 3 | |
| 4 | void Interface::loadRequest(unsigned id, string name, string type) { |
| 5 | return utility->loadRequest(id, name, type); |
| 6 | } |
| 7 | |
| 8 | void Interface::loadRequest(unsigned id, string path) { |
| 9 | return utility->loadRequest(id, path); |
| 10 | } |
| 11 | |
| 12 | void Interface::saveRequest(unsigned id, string path) { |
| 13 | return utility->saveRequest(id, path); |
| 14 | } |
| 15 | |
| 16 | uint32_t Interface::videoColor(unsigned source, uint16_t a, uint16_t r, uint16_t g, uint16_t b) { |
| 17 | if(config->video.shader != "Display Emulation") { |
| 18 | if(config->video.saturation != 100) { |
| 19 | uint16_t grayscale = uclamp<16>((r + g + b) / 3); |
| 20 | double saturation = config->video.saturation * 0.01; |
| 21 | double inverse = max(0.0, 1.0 - saturation); |
| 22 | r = uclamp<16>(r * saturation + grayscale * inverse); |
| 23 | g = uclamp<16>(g * saturation + grayscale * inverse); |
| 24 | b = uclamp<16>(b * saturation + grayscale * inverse); |
| 25 | } |
| 26 | |
| 27 | if(config->video.gamma != 100) { |
| 28 | double exponent = config->video.gamma * 0.01; |
| 29 | double reciprocal = 1.0 / 32767.0; |
| 30 | r = r > 32767 ? r : 32767 * pow(r * reciprocal, exponent); |
| 31 | g = g > 32767 ? g : 32767 * pow(g * reciprocal, exponent); |
| 32 | b = b > 32767 ? b : 32767 * pow(b * reciprocal, exponent); |
| 33 | } |
| 34 | |
| 35 | if(config->video.luminance != 100) { |
| 36 | double luminance = config->video.luminance * 0.01; |
| 37 | r = r * luminance; |
| 38 | g = g * luminance; |
| 39 | b = b * luminance; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | if(program->depth == 30) { |
| 44 | a >>= 14, r >>= 6, g >>= 6, b >>= 6; |
| 45 | return a << 30 | r << 20 | g << 10 | b << 0; |
| 46 | } |
| 47 | |
| 48 | if(program->depth == 24) { |
| 49 | a >>= 8, r >>= 8, g >>= 8, b >>= 8; |
| 50 | return a << 24 | r << 16 | g << 8 | b << 0; |
| 51 | } |
| 52 | |
| 53 | return 0u; |
| 54 | } |
| 55 | |
| 56 | void Interface::videoRefresh(const uint32_t* palette, const uint32_t* data, unsigned pitch, unsigned width, unsigned height) { |
| 57 | uint32_t* output; |
| 58 | unsigned outputPitch; |
| 59 | |
| 60 | if(video.lock(output, outputPitch, width, height)) { |
| 61 | pitch >>= 2, outputPitch >>= 2; |
| 62 | |
| 63 | for(unsigned y = 0; y < height; y++) { |
| 64 | const uint32_t* sp = data + y * pitch; |
| 65 | uint32_t* dp = output + y * outputPitch; |
| 66 | for(unsigned x = 0; x < width; x++) { |
| 67 | *dp++ = palette[*sp++]; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if(system().information.overscan && config->video.maskOverscan.enable) { |
| 72 | unsigned h = config->video.maskOverscan.horizontal; |
| 73 | unsigned v = config->video.maskOverscan.vertical; |
| 74 | |
| 75 | if(h) for(unsigned y = 0; y < height; y++) { |
| 76 | memset(output + y * outputPitch, 0, 4 * h); |
| 77 | memset(output + y * outputPitch + (width - h), 0, 4 * h); |
| 78 | } |
| 79 | |
| 80 | if(v) for(unsigned y = 0; y < v; y++) { |
| 81 | memset(output + y * outputPitch, 0, 4 * width); |
| 82 | memset(output + (height - 1 - y) * outputPitch, 0, 4 * width); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | video.unlock(); |
| 87 | video.refresh(); |
| 88 | } |
| 89 | |
| 90 | static unsigned frameCounter = 0; |
| 91 | static time_t previous, current; |
| 92 | frameCounter++; |
| 93 | |
| 94 | time(¤t); |
| 95 | if(current != previous) { |
| 96 | previous = current; |
| 97 | utility->setStatusText({"FPS: ", frameCounter}); |
| 98 | frameCounter = 0; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | void Interface::audioSample(int16_t lsample, int16_t rsample) { |
| 103 | signed samples[] = {lsample, rsample}; |
| 104 | dspaudio.sample(samples); |
| 105 | while(dspaudio.pending()) { |
| 106 | dspaudio.read(samples); |
| 107 | audio.sample(samples[0], samples[1]); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | int16_t Interface::inputPoll(unsigned port, unsigned device, unsigned input) { |
| 112 | unsigned guid = system().port[port].device[device].input[input].guid; |
| 113 | return inputManager->inputMap[guid]->poll(); |
| 114 | } |
| 115 | |
| 116 | void Interface::inputRumble(unsigned port, unsigned device, unsigned input, bool enable) { |
| 117 | unsigned guid = system().port[port].device[device].input[input].guid; |
| 118 | return inputManager->inputMap[guid]->rumble(enable); |
| 119 | } |
| 120 | |
| 121 | unsigned Interface::dipSettings(const Markup::Node& node) { |
| 122 | return dipSwitches->run(node); |
| 123 | } |
| 124 | |
| 125 | string Interface::path(unsigned group) { |
| 126 | return utility->path(group); |
| 127 | } |
| 128 | |
| 129 | string Interface::server() { |
| 130 | return { |
| 131 | config->server.username, ":", |
| 132 | config->server.password, "@", |
| 133 | config->server.hostname |
| 134 | }; |
| 135 | } |
| 136 | |
| 137 | void Interface::notify(string text) { |
| 138 | MessageWindow().setParent(*presentation).setText(text).information(); |
| 139 | } |