mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 07:10:00 -06:00
Merge remote-tracking branch 'remotes/upstream/master' into feature/qt-platform
# Conflicts: # src/frontend/qt_sdl/CMakeLists.txt # src/frontend/qt_sdl/Platform.cpp # src/frontend/qt_sdl/main.cpp
This commit is contained in:
@ -32,6 +32,33 @@ enum
|
||||
ROMSlot_MAX
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
Load_OK = 0,
|
||||
|
||||
Load_BIOS9Missing,
|
||||
Load_BIOS9Bad,
|
||||
|
||||
Load_BIOS7Missing,
|
||||
Load_BIOS7Bad,
|
||||
|
||||
Load_FirmwareMissing,
|
||||
Load_FirmwareBad,
|
||||
Load_FirmwareNotBootable,
|
||||
|
||||
Load_DSiBIOS9Missing,
|
||||
Load_DSiBIOS9Bad,
|
||||
|
||||
Load_DSiBIOS7Missing,
|
||||
Load_DSiBIOS7Bad,
|
||||
|
||||
Load_DSiNANDMissing,
|
||||
Load_DSiNANDBad,
|
||||
|
||||
// TODO: more precise errors for ROM loading
|
||||
Load_ROMLoadError,
|
||||
};
|
||||
|
||||
extern char ROMPath [ROMSlot_MAX][1024];
|
||||
extern char SRAMPath[ROMSlot_MAX][1024];
|
||||
extern bool SavestateLoaded;
|
||||
@ -41,11 +68,18 @@ extern bool SavestateLoaded;
|
||||
void Init_ROM();
|
||||
|
||||
// load the BIOS/firmware and boot from it
|
||||
bool LoadBIOS();
|
||||
int LoadBIOS();
|
||||
|
||||
// load a ROM file to the specified cart slot
|
||||
// note: loading a ROM to the NDS slot resets emulation
|
||||
bool LoadROM(const char* file, int slot);
|
||||
int LoadROM(const char* file, int slot);
|
||||
|
||||
// unload the ROM loaded in the specified cart slot
|
||||
// simulating ejection of the cartridge
|
||||
void UnloadROM(int slot);
|
||||
|
||||
// reset execution of the current ROM
|
||||
int Reset();
|
||||
|
||||
// get the filename associated with the given savestate slot (1-8)
|
||||
void GetSavestateName(int slot, char* filename, int len);
|
||||
@ -64,6 +98,33 @@ bool SaveState(const char* filename);
|
||||
void UndoStateLoad();
|
||||
|
||||
|
||||
// setup the display layout based on the provided display size and parameters
|
||||
// * screenWidth/screenHeight: size of the host display
|
||||
// * screenLayout: how the DS screens are laid out
|
||||
// 0 = natural (top screen above bottom screen always)
|
||||
// 1 = vertical
|
||||
// 2 = horizontal
|
||||
// * rotation: angle at which the DS screens are presented: 0/1/2/3 = 0/90/180/270
|
||||
// * sizing: how the display size is shared between the two screens
|
||||
// 0 = even (both screens get same size)
|
||||
// 1 = emphasize top screen (make top screen as big as possible, fit bottom screen in remaining space)
|
||||
// 2 = emphasize bottom screen
|
||||
// * screenGap: size of the gap between the two screens
|
||||
// * integerScale: force screens to be scaled up at integer scaling factors
|
||||
void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int rotation, int sizing, int screenGap, bool integerScale);
|
||||
|
||||
// get a 2x3 transform matrix for each screen
|
||||
// note: the transform assumes an origin point at the top left of the display,
|
||||
// X going left and Y going down
|
||||
// for each screen the source coordinates should be (0,0) and (256,192)
|
||||
// 'top' and 'bot' should point each to an array of 6 floats
|
||||
void GetScreenTransforms(float* top, float* bot);
|
||||
|
||||
// de-transform the provided host display coordinates to get coordinates
|
||||
// on the bottom screen
|
||||
void GetTouchCoords(int& x, int& y);
|
||||
|
||||
|
||||
// initialize the audio utility
|
||||
void Init_Audio(int outputfreq);
|
||||
|
||||
@ -72,9 +133,20 @@ void Init_Audio(int outputfreq);
|
||||
int AudioOut_GetNumSamples(int outlen);
|
||||
|
||||
// resample audio from the core audio output to match the frontend's
|
||||
// output frequency, and apply user-specified volume
|
||||
// output frequency, and apply specified volume
|
||||
// note: this assumes the output buffer is interleaved stereo
|
||||
void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen);
|
||||
void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen, int volume);
|
||||
|
||||
// feed silence to the microphone input
|
||||
void Mic_FeedSilence();
|
||||
|
||||
// feed random noise to the microphone input
|
||||
void Mic_FeedNoise();
|
||||
|
||||
// feed an external buffer to the microphone input
|
||||
// buffer should be mono
|
||||
void Mic_FeedExternalBuffer();
|
||||
void Mic_SetExternalBuffer(s16* buffer, u32 len);
|
||||
|
||||
}
|
||||
|
||||
|
@ -17,16 +17,15 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "FrontendUtil.h"
|
||||
#include "Config.h"
|
||||
#include "qt_sdl/PlatformConfig.h" // FIXME!!!
|
||||
#include "Platform.h"
|
||||
|
||||
#include "NDS.h"
|
||||
#include "GBACart.h"
|
||||
|
||||
#include "mic_blow.h"
|
||||
|
||||
|
||||
namespace Frontend
|
||||
@ -35,13 +34,22 @@ namespace Frontend
|
||||
int AudioOut_Freq;
|
||||
float AudioOut_SampleFrac;
|
||||
|
||||
s16* MicBuffer;
|
||||
u32 MicBufferLength;
|
||||
u32 MicBufferReadPos;
|
||||
|
||||
|
||||
void Init_Audio(int outputfreq)
|
||||
{
|
||||
AudioOut_Freq = outputfreq;
|
||||
AudioOut_SampleFrac = 0;
|
||||
|
||||
MicBuffer = nullptr;
|
||||
MicBufferLength = 0;
|
||||
MicBufferReadPos = 0;
|
||||
}
|
||||
|
||||
|
||||
int AudioOut_GetNumSamples(int outlen)
|
||||
{
|
||||
float f_len_in = (outlen * 32823.6328125) / (float)AudioOut_Freq;
|
||||
@ -52,14 +60,12 @@ int AudioOut_GetNumSamples(int outlen)
|
||||
return len_in;
|
||||
}
|
||||
|
||||
void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen)
|
||||
void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen, int volume)
|
||||
{
|
||||
float res_incr = inlen / (float)outlen;
|
||||
float res_timer = 0;
|
||||
int res_pos = 0;
|
||||
|
||||
int volume = Config::AudioVolume;
|
||||
|
||||
for (int i = 0; i < outlen; i++)
|
||||
{
|
||||
outbuf[i*2 ] = (inbuf[res_pos*2 ] * volume) >> 8;
|
||||
@ -74,4 +80,56 @@ void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Mic_FeedSilence()
|
||||
{
|
||||
MicBufferReadPos = 0;
|
||||
NDS::MicInputFrame(NULL, 0);
|
||||
}
|
||||
|
||||
void Mic_FeedNoise()
|
||||
{
|
||||
int sample_len = sizeof(mic_blow) / sizeof(u16);
|
||||
static int sample_pos = 0;
|
||||
|
||||
s16 tmp[735];
|
||||
|
||||
for (int i = 0; i < 735; i++)
|
||||
{
|
||||
tmp[i] = mic_blow[sample_pos];
|
||||
sample_pos++;
|
||||
if (sample_pos >= sample_len) sample_pos = 0;
|
||||
}
|
||||
|
||||
NDS::MicInputFrame(tmp, 735);
|
||||
}
|
||||
|
||||
void Mic_FeedExternalBuffer()
|
||||
{
|
||||
if (!MicBuffer) return Mic_FeedSilence();
|
||||
|
||||
if ((MicBufferReadPos + 735) > MicBufferLength)
|
||||
{
|
||||
s16 tmp[735];
|
||||
u32 len1 = MicBufferLength - MicBufferReadPos;
|
||||
memcpy(&tmp[0], &MicBuffer[MicBufferReadPos], len1*sizeof(s16));
|
||||
memcpy(&tmp[len1], &MicBuffer[0], (735 - len1)*sizeof(s16));
|
||||
|
||||
NDS::MicInputFrame(tmp, 735);
|
||||
MicBufferReadPos = 735 - len1;
|
||||
}
|
||||
else
|
||||
{
|
||||
NDS::MicInputFrame(&MicBuffer[MicBufferReadPos], 735);
|
||||
MicBufferReadPos += 735;
|
||||
}
|
||||
}
|
||||
|
||||
void Mic_SetExternalBuffer(s16* buffer, u32 len)
|
||||
{
|
||||
MicBuffer = buffer;
|
||||
MicBufferLength = len;
|
||||
MicBufferReadPos = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -50,6 +50,11 @@ void Init_ROM()
|
||||
memset(PrevSRAMPath[ROMSlot_GBA], 0, 1024);
|
||||
}
|
||||
|
||||
// TODO: currently, when failing to load a ROM for whatever reason, we attempt
|
||||
// to revert to the previous state and resume execution; this may not be a very
|
||||
// good thing, depending on what state the core was left in.
|
||||
// should we do a better state revert (via the savestate system)? completely stop?
|
||||
|
||||
void SetupSRAMPath(int slot)
|
||||
{
|
||||
strncpy(SRAMPath[slot], ROMPath[slot], 1023);
|
||||
@ -57,8 +62,166 @@ void SetupSRAMPath(int slot)
|
||||
strncpy(SRAMPath[slot] + strlen(ROMPath[slot]) - 3, "sav", 3);
|
||||
}
|
||||
|
||||
bool LoadBIOS()
|
||||
int VerifyDSBIOS()
|
||||
{
|
||||
FILE* f;
|
||||
long len;
|
||||
|
||||
f = Platform::OpenLocalFile(Config::BIOS9Path, "rb");
|
||||
if (!f) return Load_BIOS9Missing;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
if (len != 0x1000)
|
||||
{
|
||||
fclose(f);
|
||||
return Load_BIOS9Bad;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
f = Platform::OpenLocalFile(Config::BIOS7Path, "rb");
|
||||
if (!f) return Load_BIOS7Missing;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
if (len != 0x4000)
|
||||
{
|
||||
fclose(f);
|
||||
return Load_BIOS7Bad;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return Load_OK;
|
||||
}
|
||||
|
||||
int VerifyDSiBIOS()
|
||||
{
|
||||
FILE* f;
|
||||
long len;
|
||||
|
||||
// TODO: check the first 32 bytes
|
||||
|
||||
f = Platform::OpenLocalFile(Config::DSiBIOS9Path, "rb");
|
||||
if (!f) return Load_DSiBIOS9Missing;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
if (len != 0x10000)
|
||||
{
|
||||
fclose(f);
|
||||
return Load_DSiBIOS9Bad;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
f = Platform::OpenLocalFile(Config::DSiBIOS7Path, "rb");
|
||||
if (!f) return Load_DSiBIOS7Missing;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
if (len != 0x10000)
|
||||
{
|
||||
fclose(f);
|
||||
return Load_DSiBIOS7Bad;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return Load_OK;
|
||||
}
|
||||
|
||||
int VerifyDSFirmware()
|
||||
{
|
||||
FILE* f;
|
||||
long len;
|
||||
|
||||
f = Platform::OpenLocalFile(Config::FirmwarePath, "rb");
|
||||
if (!f) return Load_FirmwareMissing;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
if (len == 0x20000)
|
||||
{
|
||||
// 128KB firmware, not bootable
|
||||
fclose(f);
|
||||
return Load_FirmwareNotBootable;
|
||||
}
|
||||
else if (len != 0x40000 && len != 0x80000)
|
||||
{
|
||||
fclose(f);
|
||||
return Load_FirmwareBad;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return Load_OK;
|
||||
}
|
||||
|
||||
int VerifyDSiFirmware()
|
||||
{
|
||||
FILE* f;
|
||||
long len;
|
||||
|
||||
f = Platform::OpenLocalFile(Config::DSiFirmwarePath, "rb");
|
||||
if (!f) return Load_FirmwareMissing;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
if (len != 0x20000)
|
||||
{
|
||||
// not 128KB
|
||||
// TODO: check whether those work
|
||||
fclose(f);
|
||||
return Load_FirmwareBad;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return Load_OK;
|
||||
}
|
||||
|
||||
int VerifyDSiNAND()
|
||||
{
|
||||
FILE* f;
|
||||
long len;
|
||||
|
||||
f = Platform::OpenLocalFile(Config::DSiNANDPath, "rb");
|
||||
if (!f) return Load_DSiNANDMissing;
|
||||
|
||||
// TODO: some basic checks
|
||||
// check that it has the nocash footer, and all
|
||||
|
||||
fclose(f);
|
||||
|
||||
return Load_OK;
|
||||
}
|
||||
|
||||
int LoadBIOS()
|
||||
{
|
||||
int res;
|
||||
|
||||
res = VerifyDSBIOS();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
if (Config::ConsoleType == 1)
|
||||
{
|
||||
res = VerifyDSiBIOS();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
res = VerifyDSiFirmware();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
res = VerifyDSiNAND();
|
||||
if (res != Load_OK) return res;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = VerifyDSFirmware();
|
||||
if (res != Load_OK) return res;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// original code in the libui frontend called NDS::LoadGBAROM() if needed
|
||||
// should this be carried over here?
|
||||
@ -67,16 +230,54 @@ bool LoadBIOS()
|
||||
ROMPath[ROMSlot_NDS][0] = '\0';
|
||||
SRAMPath[ROMSlot_NDS][0] = '\0';
|
||||
|
||||
NDS::SetConsoleType(Config::ConsoleType);
|
||||
NDS::LoadBIOS();
|
||||
|
||||
SavestateLoaded = false;
|
||||
|
||||
// TODO: error reporting?
|
||||
return true;
|
||||
return Load_OK;
|
||||
}
|
||||
|
||||
bool LoadROM(const char* file, int slot)
|
||||
int LoadROM(const char* file, int slot)
|
||||
{
|
||||
int res;
|
||||
bool directboot = Config::DirectBoot != 0;
|
||||
|
||||
if (Config::ConsoleType == 1 && slot == 1)
|
||||
{
|
||||
// cannot load a GBA ROM into a DSi
|
||||
return Load_ROMLoadError;
|
||||
}
|
||||
|
||||
res = VerifyDSBIOS();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
if (Config::ConsoleType == 1)
|
||||
{
|
||||
res = VerifyDSiBIOS();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
res = VerifyDSiFirmware();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
res = VerifyDSiNAND();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
GBACart::Eject();
|
||||
ROMPath[ROMSlot_GBA][0] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
res = VerifyDSFirmware();
|
||||
if (res != Load_OK)
|
||||
{
|
||||
if (res == Load_FirmwareNotBootable)
|
||||
directboot = true;
|
||||
else
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
char oldpath[1024];
|
||||
char oldsram[1024];
|
||||
strncpy(oldpath, ROMPath[slot], 1024);
|
||||
@ -88,31 +289,107 @@ bool LoadROM(const char* file, int slot)
|
||||
SetupSRAMPath(0);
|
||||
SetupSRAMPath(1);
|
||||
|
||||
if (slot == ROMSlot_NDS && NDS::LoadROM(ROMPath[slot], SRAMPath[slot], Config::DirectBoot))
|
||||
NDS::SetConsoleType(Config::ConsoleType);
|
||||
|
||||
if (slot == ROMSlot_NDS && NDS::LoadROM(ROMPath[slot], SRAMPath[slot], directboot))
|
||||
{
|
||||
SavestateLoaded = false;
|
||||
|
||||
// Reload the inserted GBA cartridge (if any)
|
||||
// TODO: report failure there??
|
||||
if (ROMPath[ROMSlot_GBA][0] != '\0') NDS::LoadGBAROM(ROMPath[ROMSlot_GBA], SRAMPath[ROMSlot_GBA]);
|
||||
|
||||
strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety
|
||||
return true;
|
||||
return Load_OK;
|
||||
}
|
||||
else if (slot == ROMSlot_GBA && NDS::LoadGBAROM(ROMPath[slot], SRAMPath[slot]))
|
||||
{
|
||||
SavestateLoaded = false;
|
||||
SavestateLoaded = false; // checkme??
|
||||
|
||||
strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety
|
||||
return true;
|
||||
return Load_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ROMPath[slot], oldpath, 1024);
|
||||
strncpy(SRAMPath[slot], oldsram, 1024);
|
||||
return false;
|
||||
return Load_ROMLoadError;
|
||||
}
|
||||
}
|
||||
|
||||
void UnloadROM(int slot)
|
||||
{
|
||||
if (slot == ROMSlot_NDS)
|
||||
{
|
||||
// TODO!
|
||||
}
|
||||
else if (slot == ROMSlot_GBA)
|
||||
{
|
||||
GBACart::Eject();
|
||||
}
|
||||
|
||||
ROMPath[slot][0] = '\0';
|
||||
}
|
||||
|
||||
int Reset()
|
||||
{
|
||||
int res;
|
||||
bool directboot = Config::DirectBoot != 0;
|
||||
|
||||
res = VerifyDSBIOS();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
if (Config::ConsoleType == 1)
|
||||
{
|
||||
res = VerifyDSiBIOS();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
res = VerifyDSiFirmware();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
res = VerifyDSiNAND();
|
||||
if (res != Load_OK) return res;
|
||||
|
||||
GBACart::Eject();
|
||||
ROMPath[ROMSlot_GBA][0] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
res = VerifyDSFirmware();
|
||||
if (res != Load_OK)
|
||||
{
|
||||
if (res == Load_FirmwareNotBootable)
|
||||
directboot = true;
|
||||
else
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
SavestateLoaded = false;
|
||||
|
||||
NDS::SetConsoleType(Config::ConsoleType);
|
||||
|
||||
if (ROMPath[ROMSlot_NDS][0] == '\0')
|
||||
{
|
||||
NDS::LoadBIOS();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetupSRAMPath(0);
|
||||
if (!NDS::LoadROM(ROMPath[ROMSlot_NDS], SRAMPath[ROMSlot_NDS], directboot))
|
||||
return Load_ROMLoadError;
|
||||
}
|
||||
|
||||
if (ROMPath[ROMSlot_GBA][0] != '\0')
|
||||
{
|
||||
SetupSRAMPath(1);
|
||||
if (!NDS::LoadGBAROM(ROMPath[ROMSlot_GBA], SRAMPath[ROMSlot_GBA]))
|
||||
return Load_ROMLoadError;
|
||||
}
|
||||
|
||||
return Load_OK;
|
||||
}
|
||||
|
||||
|
||||
// SAVESTATE TODO
|
||||
// * configurable paths. not everyone wants their ROM directory to be polluted, I guess.
|
||||
@ -241,10 +518,6 @@ bool SaveState(const char* filename)
|
||||
}
|
||||
}
|
||||
|
||||
/*char msg[64];
|
||||
if (slot > 0) sprintf(msg, "State saved to slot %d", slot);
|
||||
else sprintf(msg, "State saved to file");
|
||||
OSD::AddMessage(0, msg);*/
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -264,8 +537,6 @@ void UndoStateLoad()
|
||||
strncpy(SRAMPath[ROMSlot_NDS], PrevSRAMPath[ROMSlot_NDS], 1024);
|
||||
NDS::RelocateSave(SRAMPath[ROMSlot_NDS], false);
|
||||
}
|
||||
|
||||
//OSD::AddMessage(0, "State load undone");
|
||||
}
|
||||
|
||||
}
|
||||
|
334
src/frontend/Util_Video.cpp
Normal file
334
src/frontend/Util_Video.cpp
Normal file
@ -0,0 +1,334 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
#include "FrontendUtil.h"
|
||||
|
||||
|
||||
namespace Frontend
|
||||
{
|
||||
|
||||
float TopScreenMtx[6];
|
||||
float BotScreenMtx[6];
|
||||
float TouchMtx[6];
|
||||
|
||||
|
||||
void M23_Identity(float* m)
|
||||
{
|
||||
m[0] = 1; m[1] = 0;
|
||||
m[2] = 0; m[3] = 1;
|
||||
m[4] = 0; m[5] = 0;
|
||||
}
|
||||
|
||||
void M23_Scale(float* m, float s)
|
||||
{
|
||||
m[0] *= s; m[1] *= s;
|
||||
m[2] *= s; m[3] *= s;
|
||||
m[4] *= s; m[5] *= s;
|
||||
}
|
||||
|
||||
void M23_RotateFast(float* m, int angle)
|
||||
{
|
||||
if (angle == 0) return;
|
||||
|
||||
float temp[4]; memcpy(temp, m, sizeof(float)*4);
|
||||
|
||||
switch (angle)
|
||||
{
|
||||
case 1: // 90
|
||||
m[0] = temp[2];
|
||||
m[1] = temp[3];
|
||||
m[2] = -temp[0];
|
||||
m[3] = -temp[1];
|
||||
break;
|
||||
|
||||
case 2: // 180
|
||||
m[0] = -temp[0];
|
||||
m[1] = -temp[1];
|
||||
m[2] = -temp[2];
|
||||
m[3] = -temp[3];
|
||||
break;
|
||||
|
||||
case 3: // 270
|
||||
m[0] = -temp[2];
|
||||
m[1] = -temp[3];
|
||||
m[2] = temp[0];
|
||||
m[3] = temp[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void M23_Translate(float* m, float tx, float ty)
|
||||
{
|
||||
m[4] += tx;
|
||||
m[5] += ty;
|
||||
}
|
||||
|
||||
void M23_Multiply(float* m, float* _a, float* _b)
|
||||
{
|
||||
float a[6]; memcpy(a, _a, 6*sizeof(float));
|
||||
float b[6]; memcpy(b, _b, 6*sizeof(float));
|
||||
|
||||
m[0] = (a[0] * b[0]) + (a[2] * b[1]);
|
||||
m[1] = (a[1] * b[0]) + (a[3] * b[1]);
|
||||
|
||||
m[2] = (a[0] * b[2]) + (a[2] * b[3]);
|
||||
m[3] = (a[1] * b[2]) + (a[3] * b[3]);
|
||||
|
||||
m[4] = (a[0] * b[4]) + (a[2] * b[5]) + a[4];
|
||||
m[5] = (a[1] * b[4]) + (a[3] * b[5]) + a[5];
|
||||
}
|
||||
|
||||
void M23_Transform(float* m, float& x, float& y)
|
||||
{
|
||||
float vx = x;
|
||||
float vy = y;
|
||||
|
||||
x = (vx * m[0]) + (vy * m[2]) + m[4];
|
||||
y = (vx * m[1]) + (vy * m[3]) + m[5];
|
||||
}
|
||||
|
||||
|
||||
void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int rotation, int sizing, int screenGap, bool integerScale)
|
||||
{
|
||||
float refpoints[4][2] =
|
||||
{
|
||||
{0, 0}, {256, 192},
|
||||
{0, 0}, {256, 192}
|
||||
};
|
||||
|
||||
int layout = screenLayout == 0
|
||||
? ((rotation % 2 == 0) ? 0 : 1)
|
||||
: screenLayout - 1;
|
||||
|
||||
float botScale = 1;
|
||||
float botTrans[4] = {0};
|
||||
|
||||
M23_Identity(TopScreenMtx);
|
||||
M23_Identity(BotScreenMtx);
|
||||
|
||||
M23_Translate(TopScreenMtx, -256/2, -192/2);
|
||||
M23_Translate(BotScreenMtx, -256/2, -192/2);
|
||||
|
||||
// rotation
|
||||
{
|
||||
float rotmtx[6];
|
||||
M23_Identity(rotmtx);
|
||||
|
||||
M23_RotateFast(rotmtx, rotation);
|
||||
M23_Multiply(TopScreenMtx, rotmtx, TopScreenMtx);
|
||||
M23_Multiply(BotScreenMtx, rotmtx, BotScreenMtx);
|
||||
|
||||
M23_Transform(TopScreenMtx, refpoints[0][0], refpoints[0][1]);
|
||||
M23_Transform(TopScreenMtx, refpoints[1][0], refpoints[1][1]);
|
||||
M23_Transform(BotScreenMtx, refpoints[2][0], refpoints[2][1]);
|
||||
M23_Transform(BotScreenMtx, refpoints[3][0], refpoints[3][1]);
|
||||
}
|
||||
|
||||
// move screens apart
|
||||
{
|
||||
int idx = layout == 0 ? 1 : 0;
|
||||
float offset =
|
||||
(((layout == 0 && (rotation % 2 == 0)) || (layout == 1 && (rotation % 2 == 1))
|
||||
? 192.f : 256.f)
|
||||
+ screenGap) / 2.f;
|
||||
if (rotation == 1 || rotation == 2)
|
||||
offset *= -1.f;
|
||||
|
||||
M23_Translate(TopScreenMtx, (idx==0)?-offset:0, (idx==1)?-offset:0);
|
||||
M23_Translate(BotScreenMtx, (idx==0)?offset:0, (idx==1)?offset:0);
|
||||
|
||||
refpoints[0][idx] -= offset;
|
||||
refpoints[1][idx] -= offset;
|
||||
refpoints[2][idx] += offset;
|
||||
refpoints[3][idx] += offset;
|
||||
|
||||
botTrans[idx] = offset;
|
||||
}
|
||||
|
||||
// scale
|
||||
{
|
||||
if (sizing == 0)
|
||||
{
|
||||
float minX = refpoints[0][0], maxX = minX;
|
||||
float minY = refpoints[0][1], maxY = minY;
|
||||
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
minX = std::min(minX, refpoints[i][0]);
|
||||
minY = std::min(minY, refpoints[i][1]);
|
||||
maxX = std::max(maxX, refpoints[i][0]);
|
||||
maxY = std::max(maxY, refpoints[i][1]);
|
||||
}
|
||||
|
||||
float hSize = maxX - minX;
|
||||
float vSize = maxY - minY;
|
||||
|
||||
// scale evenly
|
||||
float scale = std::min(screenWidth / hSize, screenHeight / vSize);
|
||||
|
||||
if (integerScale)
|
||||
scale = floor(scale);
|
||||
|
||||
M23_Scale(TopScreenMtx, scale);
|
||||
M23_Scale(BotScreenMtx, scale);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
refpoints[i][0] *= scale;
|
||||
refpoints[i][1] *= scale;
|
||||
}
|
||||
|
||||
botScale = scale;
|
||||
}
|
||||
else
|
||||
{
|
||||
int primOffset = (sizing == 1) ? 0 : 2;
|
||||
int secOffset = (sizing == 1) ? 2 : 0;
|
||||
float* primMtx = (sizing == 1) ? TopScreenMtx : BotScreenMtx;
|
||||
float* secMtx = (sizing == 1) ? BotScreenMtx : TopScreenMtx;
|
||||
|
||||
float primMinX = refpoints[primOffset][0], primMaxX = primMinX;
|
||||
float primMinY = refpoints[primOffset][1], primMaxY = primMinY;
|
||||
float secMinX = refpoints[secOffset][0], secMaxX = secMinX;
|
||||
float secMinY = refpoints[secOffset][1], secMaxY = secMinY;
|
||||
|
||||
primMinX = std::min(primMinX, refpoints[primOffset+1][0]);
|
||||
primMinY = std::min(primMinY, refpoints[primOffset+1][1]);
|
||||
primMaxX = std::max(primMaxX, refpoints[primOffset+1][0]);
|
||||
primMaxY = std::max(primMaxY, refpoints[primOffset+1][1]);
|
||||
|
||||
secMinX = std::min(secMinX, refpoints[secOffset+1][0]);
|
||||
secMinY = std::min(secMinY, refpoints[secOffset+1][1]);
|
||||
secMaxX = std::max(secMaxX, refpoints[secOffset+1][0]);
|
||||
secMaxY = std::max(secMaxY, refpoints[secOffset+1][1]);
|
||||
|
||||
float primHSize = layout == 1 ? std::max(primMaxX, -primMinX) : primMaxX - primMinX;
|
||||
float primVSize = layout == 0 ? std::max(primMaxY, -primMinY) : primMaxY - primMinY;
|
||||
|
||||
float secHSize = layout == 1 ? std::max(secMaxX, -secMinX) : secMaxX - secMinX;
|
||||
float secVSize = layout == 0 ? std::max(secMaxY, -secMinY) : secMaxY - secMinY;
|
||||
|
||||
float primScale = std::min(screenWidth / primHSize, screenHeight / primVSize);
|
||||
float secScale = 1.f;
|
||||
|
||||
if (layout == 0)
|
||||
{
|
||||
if (screenHeight - primVSize * primScale < secVSize)
|
||||
primScale = std::min(screenWidth / primHSize, (screenHeight - secVSize) / primVSize);
|
||||
else
|
||||
secScale = std::min((screenHeight - primVSize * primScale) / secVSize, screenWidth / secHSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (screenWidth - primHSize * primScale < secHSize)
|
||||
primScale = std::min((screenWidth - secHSize) / primHSize, screenHeight / primVSize);
|
||||
else
|
||||
secScale = std::min((screenWidth - primHSize * primScale) / secHSize, screenHeight / secVSize);
|
||||
}
|
||||
|
||||
if (integerScale)
|
||||
{
|
||||
primScale = floor(primScale);
|
||||
secScale = floor(secScale);
|
||||
}
|
||||
|
||||
M23_Scale(primMtx, primScale);
|
||||
M23_Scale(secMtx, secScale);
|
||||
|
||||
refpoints[primOffset+0][0] *= primScale;
|
||||
refpoints[primOffset+0][1] *= primScale;
|
||||
refpoints[primOffset+1][0] *= primScale;
|
||||
refpoints[primOffset+1][1] *= primScale;
|
||||
refpoints[secOffset+0][0] *= secScale;
|
||||
refpoints[secOffset+0][1] *= secScale;
|
||||
refpoints[secOffset+1][0] *= secScale;
|
||||
refpoints[secOffset+1][1] *= secScale;
|
||||
|
||||
botScale = (sizing == 1) ? secScale : primScale;
|
||||
}
|
||||
}
|
||||
|
||||
// position
|
||||
{
|
||||
float minX = refpoints[0][0], maxX = minX;
|
||||
float minY = refpoints[0][1], maxY = minY;
|
||||
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
minX = std::min(minX, refpoints[i][0]);
|
||||
minY = std::min(minY, refpoints[i][1]);
|
||||
maxX = std::max(maxX, refpoints[i][0]);
|
||||
maxY = std::max(maxY, refpoints[i][1]);
|
||||
}
|
||||
|
||||
float width = maxX - minX;
|
||||
float height = maxY - minY;
|
||||
|
||||
float tx = (screenWidth/2) - (width/2) - minX;
|
||||
float ty = (screenHeight/2) - (height/2) - minY;
|
||||
|
||||
M23_Translate(TopScreenMtx, tx, ty);
|
||||
M23_Translate(BotScreenMtx, tx, ty);
|
||||
|
||||
botTrans[2] = tx; botTrans[3] = ty;
|
||||
}
|
||||
|
||||
// prepare a 'reverse' matrix for the touchscreen
|
||||
// this matrix undoes the transforms applied to the bottom screen
|
||||
// and can be used to calculate touchscreen coords from host screen coords
|
||||
{
|
||||
M23_Identity(TouchMtx);
|
||||
|
||||
M23_Translate(TouchMtx, -botTrans[2], -botTrans[3]);
|
||||
M23_Scale(TouchMtx, 1.f / botScale);
|
||||
M23_Translate(TouchMtx, -botTrans[0], -botTrans[1]);
|
||||
|
||||
float rotmtx[6];
|
||||
M23_Identity(rotmtx);
|
||||
M23_RotateFast(rotmtx, (4-rotation) & 3);
|
||||
M23_Multiply(TouchMtx, rotmtx, TouchMtx);
|
||||
|
||||
M23_Translate(TouchMtx, 256/2, 192/2);
|
||||
}
|
||||
}
|
||||
|
||||
void GetScreenTransforms(float* top, float* bot)
|
||||
{
|
||||
memcpy(top, TopScreenMtx, 6*sizeof(float));
|
||||
memcpy(bot, BotScreenMtx, 6*sizeof(float));
|
||||
}
|
||||
|
||||
void GetTouchCoords(int& x, int& y)
|
||||
{
|
||||
float vx = x;
|
||||
float vy = y;
|
||||
|
||||
M23_Transform(TouchMtx, vx, vy);
|
||||
|
||||
x = (int)vx;
|
||||
y = (int)vy;
|
||||
}
|
||||
|
||||
}
|
||||
|
5539
src/frontend/mic_blow.h
Normal file
5539
src/frontend/mic_blow.h
Normal file
File diff suppressed because it is too large
Load Diff
103
src/frontend/qt_sdl/AudioSettingsDialog.cpp
Normal file
103
src/frontend/qt_sdl/AudioSettingsDialog.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include "types.h"
|
||||
#include "Platform.h"
|
||||
#include "Config.h"
|
||||
#include "PlatformConfig.h"
|
||||
|
||||
#include "AudioSettingsDialog.h"
|
||||
#include "ui_AudioSettingsDialog.h"
|
||||
|
||||
|
||||
AudioSettingsDialog* AudioSettingsDialog::currentDlg = nullptr;
|
||||
|
||||
extern char* EmuDirectory;
|
||||
|
||||
|
||||
AudioSettingsDialog::AudioSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::AudioSettingsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
oldVolume = Config::AudioVolume;
|
||||
|
||||
ui->slVolume->setValue(Config::AudioVolume);
|
||||
|
||||
grpMicMode = new QButtonGroup(this);
|
||||
grpMicMode->addButton(ui->rbMicNone, 0);
|
||||
grpMicMode->addButton(ui->rbMicExternal, 1);
|
||||
grpMicMode->addButton(ui->rbMicNoise, 2);
|
||||
grpMicMode->addButton(ui->rbMicWav, 3);
|
||||
connect(grpMicMode, SIGNAL(buttonClicked(int)), this, SLOT(onChangeMicMode(int)));
|
||||
grpMicMode->button(Config::MicInputType)->setChecked(true);
|
||||
|
||||
ui->txtMicWavPath->setText(Config::MicWavPath);
|
||||
|
||||
bool iswav = (Config::MicInputType == 3);
|
||||
ui->txtMicWavPath->setEnabled(iswav);
|
||||
ui->btnMicWavBrowse->setEnabled(iswav);
|
||||
}
|
||||
|
||||
AudioSettingsDialog::~AudioSettingsDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void AudioSettingsDialog::on_AudioSettingsDialog_accepted()
|
||||
{
|
||||
Config::MicInputType = grpMicMode->checkedId();
|
||||
strncpy(Config::MicWavPath, ui->txtMicWavPath->text().toStdString().c_str(), 1023); Config::MicWavPath[1023] = '\0';
|
||||
Config::Save();
|
||||
|
||||
closeDlg();
|
||||
}
|
||||
|
||||
void AudioSettingsDialog::on_AudioSettingsDialog_rejected()
|
||||
{
|
||||
Config::AudioVolume = oldVolume;
|
||||
|
||||
closeDlg();
|
||||
}
|
||||
|
||||
void AudioSettingsDialog::on_slVolume_valueChanged(int val)
|
||||
{
|
||||
Config::AudioVolume = val;
|
||||
}
|
||||
|
||||
void AudioSettingsDialog::onChangeMicMode(int mode)
|
||||
{
|
||||
bool iswav = (mode == 3);
|
||||
ui->txtMicWavPath->setEnabled(iswav);
|
||||
ui->btnMicWavBrowse->setEnabled(iswav);
|
||||
}
|
||||
|
||||
void AudioSettingsDialog::on_btnMicWavBrowse_clicked()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(this,
|
||||
"Select WAV file...",
|
||||
EmuDirectory,
|
||||
"WAV files (*.wav);;Any file (*.*)");
|
||||
|
||||
if (file.isEmpty()) return;
|
||||
|
||||
ui->txtMicWavPath->setText(file);
|
||||
}
|
69
src/frontend/qt_sdl/AudioSettingsDialog.h
Normal file
69
src/frontend/qt_sdl/AudioSettingsDialog.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef AUDIOSETTINGSDIALOG_H
|
||||
#define AUDIOSETTINGSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QButtonGroup>
|
||||
|
||||
namespace Ui { class AudioSettingsDialog; }
|
||||
class AudioSettingsDialog;
|
||||
|
||||
class AudioSettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AudioSettingsDialog(QWidget* parent);
|
||||
~AudioSettingsDialog();
|
||||
|
||||
static AudioSettingsDialog* currentDlg;
|
||||
static AudioSettingsDialog* openDlg(QWidget* parent)
|
||||
{
|
||||
if (currentDlg)
|
||||
{
|
||||
currentDlg->activateWindow();
|
||||
return currentDlg;
|
||||
}
|
||||
|
||||
currentDlg = new AudioSettingsDialog(parent);
|
||||
currentDlg->show();
|
||||
return currentDlg;
|
||||
}
|
||||
static void closeDlg()
|
||||
{
|
||||
currentDlg = nullptr;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void on_AudioSettingsDialog_accepted();
|
||||
void on_AudioSettingsDialog_rejected();
|
||||
|
||||
void on_slVolume_valueChanged(int val);
|
||||
void onChangeMicMode(int mode);
|
||||
void on_btnMicWavBrowse_clicked();
|
||||
|
||||
private:
|
||||
Ui::AudioSettingsDialog* ui;
|
||||
|
||||
int oldVolume;
|
||||
QButtonGroup* grpMicMode;
|
||||
};
|
||||
|
||||
#endif // AUDIOSETTINGSDIALOG_H
|
174
src/frontend/qt_sdl/AudioSettingsDialog.ui
Normal file
174
src/frontend/qt_sdl/AudioSettingsDialog.ui
Normal file
@ -0,0 +1,174 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AudioSettingsDialog</class>
|
||||
<widget class="QDialog" name="AudioSettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>482</width>
|
||||
<height>230</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Audio settings - melonDS</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Audio output</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Volume:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSlider" name="slVolume">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Controls the volume of the audio output.</p></body></html></string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>256</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>16</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Microphone input</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="txtMicWavPath">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>290</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Forward a WAV file to the emulated microphone.</p><p>This input mode is activated by holding the microphone hotkey (see Input and Hotkeys).</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QRadioButton" name="rbMicWav">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Forward a WAV file to the emulated microphone.</p><p>This input mode is activated by holding the microphone hotkey (see Input and Hotkeys).</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>WAV file:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="btnMicWavBrowse">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QRadioButton" name="rbMicExternal">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Input from an external microphone, if available, will be forwarded to the emulated microphone.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>External microphone</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QRadioButton" name="rbMicNoise">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Noise will be forwarded to the emulated microphone, simulating blowing into the microphone.</p><p>This input mode is activated by holding the microphone hotkey (see Input and Hotkeys).</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Blow noise</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QRadioButton" name="rbMicNone">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>No microphone input.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>None</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AudioSettingsDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AudioSettingsDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -2,56 +2,93 @@ project(qt_sdl)
|
||||
|
||||
SET(SOURCES_QT_SDL
|
||||
main.cpp
|
||||
main_shaders.h
|
||||
EmuSettingsDialog.cpp
|
||||
InputConfigDialog.cpp
|
||||
VideoSettingsDialog.cpp
|
||||
AudioSettingsDialog.cpp
|
||||
WifiSettingsDialog.cpp
|
||||
Input.cpp
|
||||
LAN_PCap.cpp
|
||||
LAN_Socket.cpp
|
||||
OSD.cpp
|
||||
OSD_shaders.h
|
||||
font.h
|
||||
Platform.cpp
|
||||
PlatformConfig.cpp
|
||||
|
||||
|
||||
../Util_ROM.cpp
|
||||
../Util_Video.cpp
|
||||
../Util_Audio.cpp
|
||||
../FrontendUtil.h
|
||||
../mic_blow.h
|
||||
|
||||
../../../melon.qrc
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -i <SOURCE> -o <OBJECT>")
|
||||
endif()
|
||||
|
||||
find_package(Qt5 COMPONENTS Core REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Gui REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||
find_package(Threads REQUIRED)
|
||||
if (BUILD_STATIC AND QT5_STATIC_DIR)
|
||||
set(QT5_STATIC_BASE ${QT5_STATIC_DIR}/lib/cmake/Qt5)
|
||||
set(Qt5_DIR ${QT5_STATIC_BASE})
|
||||
set(Qt5Core_DIR ${QT5_STATIC_BASE}Core)
|
||||
set(Qt5Gui_DIR ${QT5_STATIC_BASE}Gui)
|
||||
set(Qt5Widgets_DIR ${QT5_STATIC_BASE}Widgets)
|
||||
endif()
|
||||
|
||||
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(SDL2 REQUIRED sdl2)
|
||||
|
||||
add_executable(melonDS ${SOURCES_QT_SDL})
|
||||
if (WIN32 AND (CMAKE_BUILD_TYPE STREQUAL Release))
|
||||
add_executable(melonDS WIN32 ${SOURCES_QT_SDL})
|
||||
else()
|
||||
add_executable(melonDS ${SOURCES_QT_SDL})
|
||||
endif()
|
||||
|
||||
target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS})
|
||||
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..")
|
||||
target_link_libraries(melonDS core ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(melonDS core)
|
||||
|
||||
if (BUILD_STATIC)
|
||||
target_link_libraries(melonDS -static ${SDL2_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(melonDS ${SDL2_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if (UNIX)
|
||||
option(PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF)
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
target_link_libraries(melonDS dl Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
endif ()
|
||||
target_link_libraries(melonDS dl Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
elseif (WIN32)
|
||||
option(PORTABLE "Make a portable build that looks for its configuration in the current directory" ON)
|
||||
target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc")
|
||||
target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
endif ()
|
||||
|
||||
target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32)
|
||||
if (BUILD_STATIC)
|
||||
target_link_libraries(melonDS imm32 winmm version setupapi -static Qt5::Core Qt5::Gui Qt5::Widgets z zstd)
|
||||
else()
|
||||
target_link_libraries(melonDS Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (PORTABLE)
|
||||
add_definitions(-DPORTABLE)
|
||||
endif()
|
||||
|
||||
install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
|
||||
install(FILES ../../icon/melon_16x16.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/16x16/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../icon/melon_32x32.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/32x32/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../icon/melon_48x48.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/48x48/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../icon/melon_64x64.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/64x64/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../icon/melon_128x128.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/128x128/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonDS)
|
||||
install(FILES ../../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
|
||||
install(FILES ../../../icon/melon_16x16.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/16x16/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../../icon/melon_32x32.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/32x32/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../../icon/melon_48x48.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/48x48/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../../icon/melon_64x64.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/64x64/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../../icon/melon_128x128.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/128x128/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(FILES ../../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps RENAME net.kuribo64.melonDS.png)
|
||||
install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
|
213
src/frontend/qt_sdl/EmuSettingsDialog.cpp
Normal file
213
src/frontend/qt_sdl/EmuSettingsDialog.cpp
Normal file
@ -0,0 +1,213 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "types.h"
|
||||
#include "Platform.h"
|
||||
#include "Config.h"
|
||||
#include "PlatformConfig.h"
|
||||
|
||||
#include "EmuSettingsDialog.h"
|
||||
#include "ui_EmuSettingsDialog.h"
|
||||
|
||||
|
||||
EmuSettingsDialog* EmuSettingsDialog::currentDlg = nullptr;
|
||||
|
||||
extern char* EmuDirectory;
|
||||
|
||||
|
||||
EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::EmuSettingsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
ui->txtBIOS9Path->setText(Config::BIOS9Path);
|
||||
ui->txtBIOS7Path->setText(Config::BIOS7Path);
|
||||
ui->txtFirmwarePath->setText(Config::FirmwarePath);
|
||||
|
||||
ui->txtDSiBIOS9Path->setText(Config::DSiBIOS9Path);
|
||||
ui->txtDSiBIOS7Path->setText(Config::DSiBIOS7Path);
|
||||
ui->txtDSiFirmwarePath->setText(Config::DSiFirmwarePath);
|
||||
ui->txtDSiNANDPath->setText(Config::DSiNANDPath);
|
||||
|
||||
ui->cbxConsoleType->addItem("DS");
|
||||
ui->cbxConsoleType->addItem("DSi (experimental)");
|
||||
ui->cbxConsoleType->setCurrentIndex(Config::ConsoleType);
|
||||
|
||||
ui->chkDirectBoot->setChecked(Config::DirectBoot != 0);
|
||||
}
|
||||
|
||||
EmuSettingsDialog::~EmuSettingsDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EmuSettingsDialog::verifyFirmware()
|
||||
{
|
||||
// verify the firmware
|
||||
//
|
||||
// there are dumps of an old hacked firmware floating around on the internet
|
||||
// and those are problematic
|
||||
// the hack predates WFC, and, due to this, any game that alters the WFC
|
||||
// access point data will brick that firmware due to it having critical
|
||||
// data in the same area. it has the same problem on hardware.
|
||||
//
|
||||
// but this should help stop users from reporting that issue over and over
|
||||
// again, when the issue is not from melonDS but from their firmware dump.
|
||||
//
|
||||
// I don't know about all the firmware hacks in existence, but the one I
|
||||
// looked at has 0x180 bytes from the header repeated at 0x3FC80, but
|
||||
// bytes 0x0C-0x14 are different.
|
||||
|
||||
char filename[1024];
|
||||
strncpy(filename, ui->txtFirmwarePath->text().toStdString().c_str(), 1023); filename[1023] = '\0';
|
||||
FILE* f = Platform::OpenLocalFile(filename, "rb");
|
||||
u8 chk1[0x180], chk2[0x180];
|
||||
|
||||
fseek(f, 0, SEEK_SET);
|
||||
fread(chk1, 1, 0x180, f);
|
||||
fseek(f, -0x380, SEEK_END);
|
||||
fread(chk2, 1, 0x180, f);
|
||||
|
||||
memset(&chk1[0x0C], 0, 8);
|
||||
memset(&chk2[0x0C], 0, 8);
|
||||
|
||||
fclose(f);
|
||||
|
||||
if (!memcmp(chk1, chk2, 0x180))
|
||||
{
|
||||
QMessageBox::warning((QWidget*)this->parent(),
|
||||
"Problematic firmware dump",
|
||||
"You are using an old hacked firmware dump.\n"
|
||||
"Firmware boot will stop working if you run any game that alters WFC settings.\n\n"
|
||||
"Note that the issue is not from melonDS, it would also happen on an actual DS.");
|
||||
}
|
||||
}
|
||||
|
||||
void EmuSettingsDialog::on_EmuSettingsDialog_accepted()
|
||||
{
|
||||
verifyFirmware();
|
||||
|
||||
strncpy(Config::BIOS9Path, ui->txtBIOS9Path->text().toStdString().c_str(), 1023); Config::BIOS9Path[1023] = '\0';
|
||||
strncpy(Config::BIOS7Path, ui->txtBIOS7Path->text().toStdString().c_str(), 1023); Config::BIOS7Path[1023] = '\0';
|
||||
strncpy(Config::FirmwarePath, ui->txtFirmwarePath->text().toStdString().c_str(), 1023); Config::FirmwarePath[1023] = '\0';
|
||||
|
||||
strncpy(Config::DSiBIOS9Path, ui->txtDSiBIOS9Path->text().toStdString().c_str(), 1023); Config::DSiBIOS9Path[1023] = '\0';
|
||||
strncpy(Config::DSiBIOS7Path, ui->txtDSiBIOS7Path->text().toStdString().c_str(), 1023); Config::DSiBIOS7Path[1023] = '\0';
|
||||
strncpy(Config::DSiFirmwarePath, ui->txtDSiFirmwarePath->text().toStdString().c_str(), 1023); Config::DSiFirmwarePath[1023] = '\0';
|
||||
strncpy(Config::DSiNANDPath, ui->txtDSiNANDPath->text().toStdString().c_str(), 1023); Config::DSiNANDPath[1023] = '\0';
|
||||
|
||||
Config::ConsoleType = ui->cbxConsoleType->currentIndex();
|
||||
Config::DirectBoot = ui->chkDirectBoot->isChecked() ? 1:0;
|
||||
|
||||
Config::Save();
|
||||
|
||||
closeDlg();
|
||||
}
|
||||
|
||||
void EmuSettingsDialog::on_EmuSettingsDialog_rejected()
|
||||
{
|
||||
closeDlg();
|
||||
}
|
||||
|
||||
void EmuSettingsDialog::on_btnBIOS9Browse_clicked()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(this,
|
||||
"Select DS-mode ARM9 BIOS...",
|
||||
EmuDirectory,
|
||||
"BIOS files (*.bin *.rom);;Any file (*.*)");
|
||||
|
||||
if (file.isEmpty()) return;
|
||||
|
||||
ui->txtBIOS9Path->setText(file);
|
||||
}
|
||||
|
||||
void EmuSettingsDialog::on_btnBIOS7Browse_clicked()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(this,
|
||||
"Select DS-mode ARM7 BIOS...",
|
||||
EmuDirectory,
|
||||
"BIOS files (*.bin *.rom);;Any file (*.*)");
|
||||
|
||||
if (file.isEmpty()) return;
|
||||
|
||||
ui->txtBIOS7Path->setText(file);
|
||||
}
|
||||
|
||||
void EmuSettingsDialog::on_btnFirmwareBrowse_clicked()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(this,
|
||||
"Select DS-mode firmware...",
|
||||
EmuDirectory,
|
||||
"Firmware files (*.bin *.rom);;Any file (*.*)");
|
||||
|
||||
if (file.isEmpty()) return;
|
||||
|
||||
ui->txtFirmwarePath->setText(file);
|
||||
}
|
||||
|
||||
void EmuSettingsDialog::on_btnDSiBIOS9Browse_clicked()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(this,
|
||||
"Select DSi-mode ARM9 BIOS...",
|
||||
EmuDirectory,
|
||||
"BIOS files (*.bin *.rom);;Any file (*.*)");
|
||||
|
||||
if (file.isEmpty()) return;
|
||||
|
||||
ui->txtDSiBIOS9Path->setText(file);
|
||||
}
|
||||
|
||||
void EmuSettingsDialog::on_btnDSiBIOS7Browse_clicked()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(this,
|
||||
"Select DSi-mode ARM7 BIOS...",
|
||||
EmuDirectory,
|
||||
"BIOS files (*.bin *.rom);;Any file (*.*)");
|
||||
|
||||
if (file.isEmpty()) return;
|
||||
|
||||
ui->txtDSiBIOS7Path->setText(file);
|
||||
}
|
||||
|
||||
void EmuSettingsDialog::on_btnDSiFirmwareBrowse_clicked()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(this,
|
||||
"Select DSi DS-mode firmware...",
|
||||
EmuDirectory,
|
||||
"Firmware files (*.bin *.rom);;Any file (*.*)");
|
||||
|
||||
if (file.isEmpty()) return;
|
||||
|
||||
ui->txtDSiFirmwarePath->setText(file);
|
||||
}
|
||||
|
||||
void EmuSettingsDialog::on_btnDSiNANDBrowse_clicked()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(this,
|
||||
"Select DSi NAND...",
|
||||
EmuDirectory,
|
||||
"NAND files (*.bin *.rom);;Any file (*.*)");
|
||||
|
||||
if (file.isEmpty()) return;
|
||||
|
||||
ui->txtDSiNANDPath->setText(file);
|
||||
}
|
72
src/frontend/qt_sdl/EmuSettingsDialog.h
Normal file
72
src/frontend/qt_sdl/EmuSettingsDialog.h
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef EMUSETTINGSDIALOG_H
|
||||
#define EMUSETTINGSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui { class EmuSettingsDialog; }
|
||||
class EmuSettingsDialog;
|
||||
|
||||
class EmuSettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EmuSettingsDialog(QWidget* parent);
|
||||
~EmuSettingsDialog();
|
||||
|
||||
static EmuSettingsDialog* currentDlg;
|
||||
static EmuSettingsDialog* openDlg(QWidget* parent)
|
||||
{
|
||||
if (currentDlg)
|
||||
{
|
||||
currentDlg->activateWindow();
|
||||
return currentDlg;
|
||||
}
|
||||
|
||||
currentDlg = new EmuSettingsDialog(parent);
|
||||
currentDlg->show();
|
||||
return currentDlg;
|
||||
}
|
||||
static void closeDlg()
|
||||
{
|
||||
currentDlg = nullptr;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void on_EmuSettingsDialog_accepted();
|
||||
void on_EmuSettingsDialog_rejected();
|
||||
|
||||
void on_btnBIOS9Browse_clicked();
|
||||
void on_btnBIOS7Browse_clicked();
|
||||
void on_btnFirmwareBrowse_clicked();
|
||||
|
||||
void on_btnDSiBIOS9Browse_clicked();
|
||||
void on_btnDSiBIOS7Browse_clicked();
|
||||
void on_btnDSiFirmwareBrowse_clicked();
|
||||
void on_btnDSiNANDBrowse_clicked();
|
||||
|
||||
private:
|
||||
void verifyFirmware();
|
||||
|
||||
Ui::EmuSettingsDialog* ui;
|
||||
};
|
||||
|
||||
#endif // EMUSETTINGSDIALOG_H
|
313
src/frontend/qt_sdl/EmuSettingsDialog.ui
Normal file
313
src/frontend/qt_sdl/EmuSettingsDialog.ui
Normal file
@ -0,0 +1,313 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>EmuSettingsDialog</class>
|
||||
<widget class="QDialog" name="EmuSettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>490</width>
|
||||
<height>392</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Emu settings - melonDS</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>DS mode</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="txtBIOS9Path">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>290</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>DS-mode ARM9 BIOS</p><p>Size should be 4 KB</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>DS firmware:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>DS ARM7 BIOS:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>DS ARM9 BIOS:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="btnBIOS9Browse">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="txtBIOS7Path">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>DS-mode ARM7 BIOS</p><p>Size should be 16 KB</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="btnBIOS7Browse">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="txtFirmwarePath">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>DS-mode firmware</p><p><br/></p><p>Possible firmwares:</p><p>* 128 KB: DS-mode firmware from a DSi or 3DS. Not bootable.</p><p>* 256 KB: regular DS firmware.</p><p>* 512 KB: iQue DS firmware.</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="btnFirmwareBrowse">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>DSi mode</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="btnDSiBIOS9Browse">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>DSi ARM9 BIOS:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="btnDSiFirmwareBrowse">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="txtDSiBIOS7Path">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>DSi-mode ARM7 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="txtDSiFirmwarePath">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>DSi-mode firmware (used for DS-mode backwards compatibility)</p><p><br/></p><p>Size should be 128 KB</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>DSi ARM7 BIOS:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>DSi firmware:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="btnDSiBIOS7Browse">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="txtDSiBIOS9Path">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>DSi-mode ARM9 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>DSi NAND:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="txtDSiNANDPath">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>DSi NAND dump</p><p><br/></p><p>Should have 'nocash footer' at the end</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="btnDSiNANDBrowse">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>General</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Console type:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="cbxConsoleType">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>The type of console to emulate</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="chkDirectBoot">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>When loading a ROM, completely skip the regular boot process (&quot;Nintendo DS&quot; screen) to boot the ROM directly.</p><p><br/></p><p>Note: if your firmware dump isn't bootable, the ROM will be booted directly regardless of this setting.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Boot game directly</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>EmuSettingsDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>EmuSettingsDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
244
src/frontend/qt_sdl/Input.cpp
Normal file
244
src/frontend/qt_sdl/Input.cpp
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "Input.h"
|
||||
#include "PlatformConfig.h"
|
||||
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
int JoystickID;
|
||||
SDL_Joystick* Joystick = nullptr;
|
||||
|
||||
u32 KeyInputMask, JoyInputMask;
|
||||
u32 KeyHotkeyMask, JoyHotkeyMask;
|
||||
u32 HotkeyMask, LastHotkeyMask;
|
||||
u32 HotkeyPress, HotkeyRelease;
|
||||
|
||||
u32 InputMask;
|
||||
|
||||
|
||||
void Init()
|
||||
{
|
||||
KeyInputMask = 0xFFF;
|
||||
JoyInputMask = 0xFFF;
|
||||
InputMask = 0xFFF;
|
||||
|
||||
KeyHotkeyMask = 0;
|
||||
JoyHotkeyMask = 0;
|
||||
HotkeyMask = 0;
|
||||
LastHotkeyMask = 0;
|
||||
}
|
||||
|
||||
|
||||
void OpenJoystick()
|
||||
{
|
||||
if (Joystick) SDL_JoystickClose(Joystick);
|
||||
|
||||
int num = SDL_NumJoysticks();
|
||||
if (num < 1)
|
||||
{
|
||||
Joystick = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if (JoystickID >= num)
|
||||
JoystickID = 0;
|
||||
|
||||
Joystick = SDL_JoystickOpen(JoystickID);
|
||||
}
|
||||
|
||||
void CloseJoystick()
|
||||
{
|
||||
if (Joystick)
|
||||
{
|
||||
SDL_JoystickClose(Joystick);
|
||||
Joystick = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int GetEventKeyVal(QKeyEvent* event)
|
||||
{
|
||||
int key = event->key();
|
||||
int mod = event->modifiers();
|
||||
bool ismod = (key == Qt::Key_Control ||
|
||||
key == Qt::Key_Alt ||
|
||||
key == Qt::Key_AltGr ||
|
||||
key == Qt::Key_Shift ||
|
||||
key == Qt::Key_Meta);
|
||||
|
||||
if (!ismod)
|
||||
key |= mod;
|
||||
else if (Input::IsRightModKey(event))
|
||||
key |= (1<<31);
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
void KeyPress(QKeyEvent* event)
|
||||
{
|
||||
int keyHK = GetEventKeyVal(event);
|
||||
int keyKP = keyHK & ~event->modifiers();
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
if (keyKP == Config::KeyMapping[i])
|
||||
KeyInputMask &= ~(1<<i);
|
||||
|
||||
for (int i = 0; i < HK_MAX; i++)
|
||||
if (keyHK == Config::HKKeyMapping[i])
|
||||
KeyHotkeyMask |= (1<<i);
|
||||
}
|
||||
|
||||
void KeyRelease(QKeyEvent* event)
|
||||
{
|
||||
int keyHK = GetEventKeyVal(event);
|
||||
int keyKP = keyHK & ~event->modifiers();
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
if (keyKP == Config::KeyMapping[i])
|
||||
KeyInputMask |= (1<<i);
|
||||
|
||||
for (int i = 0; i < HK_MAX; i++)
|
||||
if (keyHK == Config::HKKeyMapping[i])
|
||||
KeyHotkeyMask &= ~(1<<i);
|
||||
}
|
||||
|
||||
|
||||
bool JoystickButtonDown(int val)
|
||||
{
|
||||
if (val == -1) return false;
|
||||
|
||||
bool hasbtn = ((val & 0xFFFF) != 0xFFFF);
|
||||
|
||||
if (hasbtn)
|
||||
{
|
||||
if (val & 0x100)
|
||||
{
|
||||
int hatnum = (val >> 4) & 0xF;
|
||||
int hatdir = val & 0xF;
|
||||
Uint8 hatval = SDL_JoystickGetHat(Joystick, hatnum);
|
||||
|
||||
bool pressed = false;
|
||||
if (hatdir == 0x1) pressed = (hatval & SDL_HAT_UP);
|
||||
else if (hatdir == 0x4) pressed = (hatval & SDL_HAT_DOWN);
|
||||
else if (hatdir == 0x2) pressed = (hatval & SDL_HAT_RIGHT);
|
||||
else if (hatdir == 0x8) pressed = (hatval & SDL_HAT_LEFT);
|
||||
|
||||
if (pressed) return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int btnnum = val & 0xFFFF;
|
||||
Uint8 btnval = SDL_JoystickGetButton(Joystick, btnnum);
|
||||
|
||||
if (btnval) return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (val & 0x10000)
|
||||
{
|
||||
int axisnum = (val >> 24) & 0xF;
|
||||
int axisdir = (val >> 20) & 0xF;
|
||||
Sint16 axisval = SDL_JoystickGetAxis(Joystick, axisnum);
|
||||
|
||||
switch (axisdir)
|
||||
{
|
||||
case 0: // positive
|
||||
if (axisval > 16384) return true;
|
||||
break;
|
||||
|
||||
case 1: // negative
|
||||
if (axisval < -16384) return true;
|
||||
break;
|
||||
|
||||
case 2: // trigger
|
||||
if (axisval > 0) return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Process()
|
||||
{
|
||||
SDL_JoystickUpdate();
|
||||
|
||||
if (Joystick)
|
||||
{
|
||||
if (!SDL_JoystickGetAttached(Joystick))
|
||||
{
|
||||
SDL_JoystickClose(Joystick);
|
||||
Joystick = NULL;
|
||||
}
|
||||
}
|
||||
if (!Joystick && (SDL_NumJoysticks() > 0))
|
||||
{
|
||||
JoystickID = Config::JoystickID;
|
||||
OpenJoystick();
|
||||
}
|
||||
|
||||
JoyInputMask = 0xFFF;
|
||||
for (int i = 0; i < 12; i++)
|
||||
if (JoystickButtonDown(Config::JoyMapping[i]))
|
||||
JoyInputMask &= ~(1<<i);
|
||||
|
||||
InputMask = KeyInputMask & JoyInputMask;
|
||||
|
||||
JoyHotkeyMask = 0;
|
||||
for (int i = 0; i < HK_MAX; i++)
|
||||
if (JoystickButtonDown(Config::HKJoyMapping[i]))
|
||||
JoyHotkeyMask |= (1<<i);
|
||||
|
||||
HotkeyMask = KeyHotkeyMask | JoyHotkeyMask;
|
||||
HotkeyPress = HotkeyMask & ~LastHotkeyMask;
|
||||
HotkeyRelease = LastHotkeyMask & ~HotkeyMask;
|
||||
LastHotkeyMask = HotkeyMask;
|
||||
}
|
||||
|
||||
|
||||
bool HotkeyDown(int id) { return HotkeyMask & (1<<id); }
|
||||
bool HotkeyPressed(int id) { return HotkeyPress & (1<<id); }
|
||||
bool HotkeyReleased(int id) { return HotkeyRelease & (1<<id); }
|
||||
|
||||
|
||||
// TODO: MacOS version of this!
|
||||
// distinguish between left and right modifier keys (Ctrl, Alt, Shift)
|
||||
// Qt provides no real cross-platform way to do this, so here we go
|
||||
// for Windows and Linux we can distinguish via scancodes (but both
|
||||
// provide different scancodes)
|
||||
#ifdef __WIN32__
|
||||
bool IsRightModKey(QKeyEvent* event)
|
||||
{
|
||||
quint32 scan = event->nativeScanCode();
|
||||
return (scan == 0x11D || scan == 0x138 || scan == 0x36);
|
||||
}
|
||||
#else
|
||||
bool IsRightModKey(QKeyEvent* event)
|
||||
{
|
||||
quint32 scan = event->nativeScanCode();
|
||||
return (scan == 0x69 || scan == 0x6C || scan == 0x3E);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
51
src/frontend/qt_sdl/Input.h
Normal file
51
src/frontend/qt_sdl/Input.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
extern int JoystickID;
|
||||
extern SDL_Joystick* Joystick;
|
||||
|
||||
extern u32 InputMask;
|
||||
|
||||
void Init();
|
||||
|
||||
// set joystickID before calling openJoystick()
|
||||
void OpenJoystick();
|
||||
void CloseJoystick();
|
||||
|
||||
void KeyPress(QKeyEvent* event);
|
||||
void KeyRelease(QKeyEvent* event);
|
||||
|
||||
void Process();
|
||||
|
||||
bool HotkeyDown(int id);
|
||||
bool HotkeyPressed(int id);
|
||||
bool HotkeyReleased(int id);
|
||||
|
||||
bool IsRightModKey(QKeyEvent* event);
|
||||
|
||||
}
|
||||
|
||||
#endif // INPUT_H
|
494
src/frontend/qt_sdl/InputConfigDialog.cpp
Normal file
494
src/frontend/qt_sdl/InputConfigDialog.cpp
Normal file
@ -0,0 +1,494 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "Config.h"
|
||||
#include "PlatformConfig.h"
|
||||
|
||||
#include "Input.h"
|
||||
#include "InputConfigDialog.h"
|
||||
#include "ui_InputConfigDialog.h"
|
||||
|
||||
|
||||
InputConfigDialog* InputConfigDialog::currentDlg = nullptr;
|
||||
|
||||
const int dskeyorder[12] = {0, 1, 10, 11, 5, 4, 6, 7, 9, 8, 2, 3};
|
||||
const char* dskeylabels[12] = {"A", "B", "X", "Y", "Left", "Right", "Up", "Down", "L", "R", "Select", "Start"};
|
||||
|
||||
const int hk_addons[] =
|
||||
{
|
||||
HK_SolarSensorIncrease,
|
||||
HK_SolarSensorDecrease,
|
||||
};
|
||||
|
||||
const char* hk_addons_labels[] =
|
||||
{
|
||||
"[Boktai] Sunlight + ",
|
||||
"[Boktai] Sunlight - ",
|
||||
};
|
||||
|
||||
const int hk_general[] =
|
||||
{
|
||||
HK_Pause,
|
||||
HK_Reset,
|
||||
HK_FastForward,
|
||||
HK_FastForwardToggle,
|
||||
HK_Lid,
|
||||
HK_Mic,
|
||||
};
|
||||
|
||||
const char* hk_general_labels[] =
|
||||
{
|
||||
"Pause/resume",
|
||||
"Reset",
|
||||
"Fast forward",
|
||||
"Toggle FPS limit",
|
||||
"Close/open lid",
|
||||
"Microphone",
|
||||
};
|
||||
|
||||
|
||||
InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new Ui::InputConfigDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
keypadKeyMap[i] = Config::KeyMapping[dskeyorder[i]];
|
||||
keypadJoyMap[i] = Config::JoyMapping[dskeyorder[i]];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
addonsKeyMap[i] = Config::HKKeyMapping[hk_addons[i]];
|
||||
addonsJoyMap[i] = Config::HKJoyMapping[hk_addons[i]];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
hkGeneralKeyMap[i] = Config::HKKeyMapping[hk_general[i]];
|
||||
hkGeneralJoyMap[i] = Config::HKJoyMapping[hk_general[i]];
|
||||
}
|
||||
|
||||
populatePage(ui->tabInput, 12, dskeylabels, keypadKeyMap, keypadJoyMap);
|
||||
populatePage(ui->tabAddons, 2, hk_addons_labels, addonsKeyMap, addonsJoyMap);
|
||||
populatePage(ui->tabHotkeysGeneral, 6, hk_general_labels, hkGeneralKeyMap, hkGeneralJoyMap);
|
||||
|
||||
int njoy = SDL_NumJoysticks();
|
||||
if (njoy > 0)
|
||||
{
|
||||
for (int i = 0; i < njoy; i++)
|
||||
{
|
||||
const char* name = SDL_JoystickNameForIndex(i);
|
||||
ui->cbxJoystick->addItem(QString(name));
|
||||
}
|
||||
ui->cbxJoystick->setCurrentIndex(Input::JoystickID);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->cbxJoystick->addItem("(no joysticks available)");
|
||||
ui->cbxJoystick->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
InputConfigDialog::~InputConfigDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels, int* keymap, int* joymap)
|
||||
{
|
||||
// kind of a hack
|
||||
bool ishotkey = (page != ui->tabInput);
|
||||
|
||||
QHBoxLayout* main_layout = new QHBoxLayout();
|
||||
|
||||
QGroupBox* group;
|
||||
QGridLayout* group_layout;
|
||||
|
||||
group = new QGroupBox("Keyboard mappings:");
|
||||
main_layout->addWidget(group);
|
||||
group_layout = new QGridLayout();
|
||||
group_layout->setSpacing(1);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
QLabel* label = new QLabel(QString(labels[i])+":");
|
||||
KeyMapButton* btn = new KeyMapButton(&keymap[i], ishotkey);
|
||||
|
||||
group_layout->addWidget(label, i, 0);
|
||||
group_layout->addWidget(btn, i, 1);
|
||||
}
|
||||
group_layout->setRowStretch(num, 1);
|
||||
group->setLayout(group_layout);
|
||||
group->setMinimumWidth(275);
|
||||
|
||||
group = new QGroupBox("Joystick mappings:");
|
||||
main_layout->addWidget(group);
|
||||
group_layout = new QGridLayout();
|
||||
group_layout->setSpacing(1);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
QLabel* label = new QLabel(QString(labels[i])+":");
|
||||
JoyMapButton* btn = new JoyMapButton(&joymap[i], ishotkey);
|
||||
|
||||
group_layout->addWidget(label, i, 0);
|
||||
group_layout->addWidget(btn, i, 1);
|
||||
}
|
||||
group_layout->setRowStretch(num, 1);
|
||||
group->setLayout(group_layout);
|
||||
group->setMinimumWidth(275);
|
||||
|
||||
page->setLayout(main_layout);
|
||||
}
|
||||
|
||||
void InputConfigDialog::on_InputConfigDialog_accepted()
|
||||
{
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
Config::KeyMapping[dskeyorder[i]] = keypadKeyMap[i];
|
||||
Config::JoyMapping[dskeyorder[i]] = keypadJoyMap[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Config::HKKeyMapping[hk_addons[i]] = addonsKeyMap[i];
|
||||
Config::HKJoyMapping[hk_addons[i]] = addonsJoyMap[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
Config::HKKeyMapping[hk_general[i]] = hkGeneralKeyMap[i];
|
||||
Config::HKJoyMapping[hk_general[i]] = hkGeneralJoyMap[i];
|
||||
}
|
||||
|
||||
Config::JoystickID = Input::JoystickID;
|
||||
Config::Save();
|
||||
|
||||
closeDlg();
|
||||
}
|
||||
|
||||
void InputConfigDialog::on_InputConfigDialog_rejected()
|
||||
{
|
||||
Input::JoystickID = Config::JoystickID;
|
||||
Input::OpenJoystick();
|
||||
|
||||
closeDlg();
|
||||
}
|
||||
|
||||
void InputConfigDialog::on_cbxJoystick_currentIndexChanged(int id)
|
||||
{
|
||||
// prevent a spurious change
|
||||
if (ui->cbxJoystick->count() < 2) return;
|
||||
|
||||
Input::JoystickID = id;
|
||||
Input::OpenJoystick();
|
||||
}
|
||||
|
||||
|
||||
KeyMapButton::KeyMapButton(int* mapping, bool hotkey) : QPushButton()
|
||||
{
|
||||
this->mapping = mapping;
|
||||
this->isHotkey = hotkey;
|
||||
|
||||
setCheckable(true);
|
||||
setText(mappingText());
|
||||
|
||||
connect(this, &KeyMapButton::clicked, this, &KeyMapButton::onClick);
|
||||
}
|
||||
|
||||
KeyMapButton::~KeyMapButton()
|
||||
{
|
||||
}
|
||||
|
||||
void KeyMapButton::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
if (!isChecked()) return QPushButton::keyPressEvent(event);
|
||||
|
||||
printf("KEY PRESSED = %08X %08X | %08X %08X %08X\n", event->key(), event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode());
|
||||
|
||||
int key = event->key();
|
||||
int mod = event->modifiers();
|
||||
bool ismod = (key == Qt::Key_Control ||
|
||||
key == Qt::Key_Alt ||
|
||||
key == Qt::Key_AltGr ||
|
||||
key == Qt::Key_Shift ||
|
||||
key == Qt::Key_Meta);
|
||||
|
||||
if (!mod)
|
||||
{
|
||||
if (key == Qt::Key_Escape) { click(); return; }
|
||||
if (key == Qt::Key_Backspace) { *mapping = -1; click(); return; }
|
||||
}
|
||||
|
||||
if (isHotkey)
|
||||
{
|
||||
if (ismod)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ismod)
|
||||
key |= mod;
|
||||
else if (Input::IsRightModKey(event))
|
||||
key |= (1<<31);
|
||||
|
||||
*mapping = key;
|
||||
click();
|
||||
}
|
||||
|
||||
void KeyMapButton::focusOutEvent(QFocusEvent* event)
|
||||
{
|
||||
if (isChecked())
|
||||
{
|
||||
// if we lost the focus while mapping, consider it 'done'
|
||||
click();
|
||||
}
|
||||
|
||||
QPushButton::focusOutEvent(event);
|
||||
}
|
||||
|
||||
void KeyMapButton::onClick()
|
||||
{
|
||||
if (isChecked())
|
||||
{
|
||||
setText("[press key]");
|
||||
}
|
||||
else
|
||||
{
|
||||
setText(mappingText());
|
||||
}
|
||||
}
|
||||
|
||||
QString KeyMapButton::mappingText()
|
||||
{
|
||||
int key = *mapping;
|
||||
|
||||
if (key == -1) return "None";
|
||||
|
||||
QString isright = (key & (1<<31)) ? "Right " : "Left ";
|
||||
key &= ~(1<<31);
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case Qt::Key_Control: return isright + "Ctrl";
|
||||
case Qt::Key_Alt: return "Alt";
|
||||
case Qt::Key_AltGr: return "AltGr";
|
||||
case Qt::Key_Shift: return isright + "Shift";
|
||||
case Qt::Key_Meta: return "Meta";
|
||||
}
|
||||
|
||||
QKeySequence seq(key);
|
||||
QString ret = seq.toString();
|
||||
|
||||
// weak attempt at detecting garbage key names
|
||||
if (ret.length() == 2 && ret[0].unicode() > 0xFF)
|
||||
return QString("[%1]").arg(key, 8, 16);
|
||||
|
||||
return ret.replace("&", "&&");
|
||||
}
|
||||
|
||||
|
||||
JoyMapButton::JoyMapButton(int* mapping, bool hotkey) : QPushButton()
|
||||
{
|
||||
this->mapping = mapping;
|
||||
this->isHotkey = hotkey;
|
||||
|
||||
setCheckable(true);
|
||||
setText(mappingText());
|
||||
|
||||
connect(this, &JoyMapButton::clicked, this, &JoyMapButton::onClick);
|
||||
|
||||
timerID = 0;
|
||||
}
|
||||
|
||||
JoyMapButton::~JoyMapButton()
|
||||
{
|
||||
}
|
||||
|
||||
void JoyMapButton::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
if (!isChecked()) return QPushButton::keyPressEvent(event);
|
||||
|
||||
int key = event->key();
|
||||
int mod = event->modifiers();
|
||||
|
||||
if (!mod)
|
||||
{
|
||||
if (key == Qt::Key_Escape) { click(); return; }
|
||||
if (key == Qt::Key_Backspace) { *mapping = -1; click(); return; }
|
||||
}
|
||||
}
|
||||
|
||||
void JoyMapButton::focusOutEvent(QFocusEvent* event)
|
||||
{
|
||||
if (isChecked())
|
||||
{
|
||||
// if we lost the focus while mapping, consider it 'done'
|
||||
click();
|
||||
}
|
||||
|
||||
QPushButton::focusOutEvent(event);
|
||||
}
|
||||
|
||||
void JoyMapButton::timerEvent(QTimerEvent* event)
|
||||
{
|
||||
SDL_Joystick* joy = Input::Joystick;
|
||||
if (!joy) { click(); return; }
|
||||
if (!SDL_JoystickGetAttached(joy)) { click(); return; }
|
||||
|
||||
int oldmap;
|
||||
if (*mapping == -1) oldmap = 0xFFFF;
|
||||
else oldmap = *mapping;
|
||||
|
||||
int nbuttons = SDL_JoystickNumButtons(joy);
|
||||
for (int i = 0; i < nbuttons; i++)
|
||||
{
|
||||
if (SDL_JoystickGetButton(joy, i))
|
||||
{
|
||||
*mapping = (oldmap & 0xFFFF0000) | i;
|
||||
click();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int nhats = SDL_JoystickNumHats(joy);
|
||||
if (nhats > 16) nhats = 16;
|
||||
for (int i = 0; i < nhats; i++)
|
||||
{
|
||||
Uint8 blackhat = SDL_JoystickGetHat(joy, i);
|
||||
if (blackhat)
|
||||
{
|
||||
if (blackhat & 0x1) blackhat = 0x1;
|
||||
else if (blackhat & 0x2) blackhat = 0x2;
|
||||
else if (blackhat & 0x4) blackhat = 0x4;
|
||||
else blackhat = 0x8;
|
||||
|
||||
*mapping = (oldmap & 0xFFFF0000) | 0x100 | blackhat | (i << 4);
|
||||
click();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int naxes = SDL_JoystickNumAxes(joy);
|
||||
if (naxes > 16) naxes = 16;
|
||||
for (int i = 0; i < naxes; i++)
|
||||
{
|
||||
Sint16 axisval = SDL_JoystickGetAxis(joy, i);
|
||||
int diff = abs(axisval - axesRest[i]);
|
||||
|
||||
if (axesRest[i] < -16384 && axisval >= 0)
|
||||
{
|
||||
*mapping = (oldmap & 0xFFFF) | 0x10000 | (2 << 20) | (i << 24);
|
||||
click();
|
||||
return;
|
||||
}
|
||||
else if (diff > 16384)
|
||||
{
|
||||
int axistype;
|
||||
if (axisval > 0) axistype = 0;
|
||||
else axistype = 1;
|
||||
|
||||
*mapping = (oldmap & 0xFFFF) | 0x10000 | (axistype << 20) | (i << 24);
|
||||
click();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JoyMapButton::onClick()
|
||||
{
|
||||
if (isChecked())
|
||||
{
|
||||
setText("[press button/axis]");
|
||||
timerID = startTimer(50);
|
||||
|
||||
memset(axesRest, 0, sizeof(axesRest));
|
||||
if (Input::Joystick && SDL_JoystickGetAttached(Input::Joystick))
|
||||
{
|
||||
int naxes = SDL_JoystickNumAxes(Input::Joystick);
|
||||
if (naxes > 16) naxes = 16;
|
||||
for (int a = 0; a < naxes; a++)
|
||||
{
|
||||
axesRest[a] = SDL_JoystickGetAxis(Input::Joystick, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setText(mappingText());
|
||||
if (timerID) { killTimer(timerID); timerID = 0; }
|
||||
}
|
||||
}
|
||||
|
||||
QString JoyMapButton::mappingText()
|
||||
{
|
||||
int id = *mapping;
|
||||
|
||||
if (id == -1) return "None";
|
||||
|
||||
bool hasbtn = ((id & 0xFFFF) != 0xFFFF);
|
||||
QString str;
|
||||
|
||||
if (hasbtn)
|
||||
{
|
||||
if (id & 0x100)
|
||||
{
|
||||
int hatnum = ((id >> 4) & 0xF) + 1;
|
||||
|
||||
switch (id & 0xF)
|
||||
{
|
||||
case 0x1: str = "Hat %1 up"; break;
|
||||
case 0x2: str = "Hat %1 right"; break;
|
||||
case 0x4: str = "Hat %1 down"; break;
|
||||
case 0x8: str = "Hat %1 left"; break;
|
||||
}
|
||||
|
||||
str = str.arg(hatnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
str = QString("Button %1").arg((id & 0xFFFF) + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
str = "";
|
||||
}
|
||||
|
||||
if (id & 0x10000)
|
||||
{
|
||||
int axisnum = ((id >> 24) & 0xF) + 1;
|
||||
|
||||
if (hasbtn) str += " / ";
|
||||
|
||||
switch ((id >> 20) & 0xF)
|
||||
{
|
||||
case 0: str += QString("Axis %1 +").arg(axisnum); break;
|
||||
case 1: str += QString("Axis %1 -").arg(axisnum); break;
|
||||
case 2: str += QString("Trigger %1").arg(axisnum); break;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
123
src/frontend/qt_sdl/InputConfigDialog.h
Normal file
123
src/frontend/qt_sdl/InputConfigDialog.h
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef INPUTCONFIGDIALOG_H
|
||||
#define INPUTCONFIGDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPushButton>
|
||||
|
||||
namespace Ui { class InputConfigDialog; }
|
||||
class InputConfigDialog;
|
||||
|
||||
class InputConfigDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InputConfigDialog(QWidget* parent);
|
||||
~InputConfigDialog();
|
||||
|
||||
static InputConfigDialog* currentDlg;
|
||||
static InputConfigDialog* openDlg(QWidget* parent)
|
||||
{
|
||||
if (currentDlg)
|
||||
{
|
||||
currentDlg->activateWindow();
|
||||
return currentDlg;
|
||||
}
|
||||
|
||||
currentDlg = new InputConfigDialog(parent);
|
||||
currentDlg->open();
|
||||
return currentDlg;
|
||||
}
|
||||
static void closeDlg()
|
||||
{
|
||||
currentDlg = nullptr;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void on_InputConfigDialog_accepted();
|
||||
void on_InputConfigDialog_rejected();
|
||||
|
||||
void on_cbxJoystick_currentIndexChanged(int id);
|
||||
|
||||
private:
|
||||
void populatePage(QWidget* page, int num, const char** labels, int* keymap, int* joymap);
|
||||
|
||||
Ui::InputConfigDialog* ui;
|
||||
|
||||
int keypadKeyMap[12], keypadJoyMap[12];
|
||||
int addonsKeyMap[2], addonsJoyMap[2];
|
||||
int hkGeneralKeyMap[6], hkGeneralJoyMap[6];
|
||||
};
|
||||
|
||||
|
||||
class KeyMapButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit KeyMapButton(int* mapping, bool hotkey);
|
||||
~KeyMapButton();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void focusOutEvent(QFocusEvent* event) override;
|
||||
|
||||
bool focusNextPrevChild(bool next) override { return false; }
|
||||
|
||||
private slots:
|
||||
void onClick();
|
||||
|
||||
private:
|
||||
QString mappingText();
|
||||
|
||||
int* mapping;
|
||||
bool isHotkey;
|
||||
};
|
||||
|
||||
class JoyMapButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit JoyMapButton(int* mapping, bool hotkey);
|
||||
~JoyMapButton();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void focusOutEvent(QFocusEvent* event) override;
|
||||
void timerEvent(QTimerEvent* event) override;
|
||||
|
||||
bool focusNextPrevChild(bool next) override { return false; }
|
||||
|
||||
private slots:
|
||||
void onClick();
|
||||
|
||||
private:
|
||||
QString mappingText();
|
||||
|
||||
int* mapping;
|
||||
bool isHotkey;
|
||||
|
||||
int timerID;
|
||||
int axesRest[16];
|
||||
};
|
||||
|
||||
#endif // INPUTCONFIGDIALOG_H
|
131
src/frontend/qt_sdl/InputConfigDialog.ui
Normal file
131
src/frontend/qt_sdl/InputConfigDialog.ui
Normal file
@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>InputConfigDialog</class>
|
||||
<widget class="QDialog" name="InputConfigDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>488</width>
|
||||
<height>365</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Input and hotkeys - melonDS</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tabInput">
|
||||
<attribute name="title">
|
||||
<string>DS keypad</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabAddons">
|
||||
<attribute name="title">
|
||||
<string>Add-ons</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabHotkeysGeneral">
|
||||
<attribute name="title">
|
||||
<string>General hotkeys</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Joystick:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cbxJoystick">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Selects which joystick will be used for joystick input, if any is present.</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>InputConfigDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>InputConfigDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
387
src/frontend/qt_sdl/LAN_PCap.cpp
Normal file
387
src/frontend/qt_sdl/LAN_PCap.cpp
Normal file
@ -0,0 +1,387 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
// direct LAN interface. Currently powered by libpcap, may change.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <pcap/pcap.h>
|
||||
#include "../Wifi.h"
|
||||
#include "LAN_PCap.h"
|
||||
#include "PlatformConfig.h"
|
||||
|
||||
#ifdef __WIN32__
|
||||
#include <iphlpapi.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <netinet/in.h>
|
||||
#include <linux/if_packet.h>
|
||||
#endif
|
||||
|
||||
|
||||
// welp
|
||||
#ifndef PCAP_OPENFLAG_PROMISCUOUS
|
||||
#define PCAP_OPENFLAG_PROMISCUOUS 1
|
||||
#endif
|
||||
|
||||
|
||||
#define DECL_PCAP_FUNC(ret, name, args, args2) \
|
||||
typedef ret (*type_##name) args; \
|
||||
type_##name ptr_##name = NULL; \
|
||||
ret name args { return ptr_##name args2; }
|
||||
|
||||
DECL_PCAP_FUNC(int, pcap_findalldevs, (pcap_if_t** alldevs, char* errbuf), (alldevs,errbuf))
|
||||
DECL_PCAP_FUNC(void, pcap_freealldevs, (pcap_if_t* alldevs), (alldevs))
|
||||
DECL_PCAP_FUNC(pcap_t*, pcap_open_live, (const char* src, int snaplen, int flags, int readtimeout, char* errbuf), (src,snaplen,flags,readtimeout,errbuf))
|
||||
DECL_PCAP_FUNC(void, pcap_close, (pcap_t* dev), (dev))
|
||||
DECL_PCAP_FUNC(int, pcap_setnonblock, (pcap_t* dev, int nonblock, char* errbuf), (dev,nonblock,errbuf))
|
||||
DECL_PCAP_FUNC(int, pcap_sendpacket, (pcap_t* dev, const u_char* data, int len), (dev,data,len))
|
||||
DECL_PCAP_FUNC(int, pcap_dispatch, (pcap_t* dev, int num, pcap_handler callback, u_char* data), (dev,num,callback,data))
|
||||
DECL_PCAP_FUNC(const u_char*, pcap_next, (pcap_t* dev, struct pcap_pkthdr* hdr), (dev,hdr))
|
||||
|
||||
|
||||
namespace LAN_PCap
|
||||
{
|
||||
|
||||
const char* PCapLibNames[] =
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
// TODO: name for npcap in non-WinPCap mode
|
||||
"wpcap.dll",
|
||||
#else
|
||||
// Linux lib names
|
||||
"libpcap.so.1",
|
||||
"libpcap.so",
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
AdapterData* Adapters = NULL;
|
||||
int NumAdapters = 0;
|
||||
|
||||
void* PCapLib = NULL;
|
||||
pcap_t* PCapAdapter = NULL;
|
||||
AdapterData* PCapAdapterData;
|
||||
|
||||
u8 PacketBuffer[2048];
|
||||
int PacketLen;
|
||||
volatile int RXNum;
|
||||
|
||||
|
||||
#define LOAD_PCAP_FUNC(sym) \
|
||||
ptr_##sym = (type_##sym)SDL_LoadFunction(lib, #sym); \
|
||||
if (!ptr_##sym) return false;
|
||||
|
||||
bool TryLoadPCap(void* lib)
|
||||
{
|
||||
LOAD_PCAP_FUNC(pcap_findalldevs)
|
||||
LOAD_PCAP_FUNC(pcap_freealldevs)
|
||||
LOAD_PCAP_FUNC(pcap_open_live)
|
||||
LOAD_PCAP_FUNC(pcap_close)
|
||||
LOAD_PCAP_FUNC(pcap_setnonblock)
|
||||
LOAD_PCAP_FUNC(pcap_sendpacket)
|
||||
LOAD_PCAP_FUNC(pcap_dispatch)
|
||||
LOAD_PCAP_FUNC(pcap_next)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Init(bool open_adapter)
|
||||
{
|
||||
// TODO: how to deal with cases where an adapter is unplugged or changes config??
|
||||
if (!PCapLib)
|
||||
{
|
||||
PCapLib = NULL;
|
||||
|
||||
for (int i = 0; PCapLibNames[i]; i++)
|
||||
{
|
||||
void* lib = SDL_LoadObject(PCapLibNames[i]);
|
||||
if (!lib) continue;
|
||||
|
||||
if (!TryLoadPCap(lib))
|
||||
{
|
||||
SDL_UnloadObject(lib);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("PCap: lib %s, init successful\n", PCapLibNames[i]);
|
||||
PCapLib = lib;
|
||||
break;
|
||||
}
|
||||
|
||||
if (PCapLib == NULL)
|
||||
{
|
||||
printf("PCap: init failed\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
PCapAdapter = NULL;
|
||||
PacketLen = 0;
|
||||
RXNum = 0;
|
||||
|
||||
NumAdapters = 0;
|
||||
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
int ret;
|
||||
|
||||
pcap_if_t* alldevs;
|
||||
ret = pcap_findalldevs(&alldevs, errbuf);
|
||||
if (ret < 0 || alldevs == NULL)
|
||||
{
|
||||
printf("PCap: no devices available\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
pcap_if_t* dev = alldevs;
|
||||
while (dev) { NumAdapters++; dev = dev->next; }
|
||||
|
||||
Adapters = new AdapterData[NumAdapters];
|
||||
memset(Adapters, 0, sizeof(AdapterData)*NumAdapters);
|
||||
|
||||
AdapterData* adata = &Adapters[0];
|
||||
dev = alldevs;
|
||||
while (dev)
|
||||
{
|
||||
adata->Internal = dev;
|
||||
|
||||
#ifdef __WIN32__
|
||||
// hax
|
||||
int len = strlen(dev->name);
|
||||
len -= 12; if (len > 127) len = 127;
|
||||
strncpy(adata->DeviceName, &dev->name[12], len);
|
||||
adata->DeviceName[len] = '\0';
|
||||
#else
|
||||
strncpy(adata->DeviceName, dev->name, 127);
|
||||
adata->DeviceName[127] = '\0';
|
||||
|
||||
strncpy(adata->FriendlyName, adata->DeviceName, 127);
|
||||
adata->FriendlyName[127] = '\0';
|
||||
#endif // __WIN32__
|
||||
|
||||
dev = dev->next;
|
||||
adata++;
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
||||
ULONG bufsize = 16384;
|
||||
IP_ADAPTER_ADDRESSES* buf = (IP_ADAPTER_ADDRESSES*)HeapAlloc(GetProcessHeap(), 0, bufsize);
|
||||
ULONG uret = GetAdaptersAddresses(AF_INET, 0, NULL, buf, &bufsize);
|
||||
if (uret == ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, buf);
|
||||
buf = (IP_ADAPTER_ADDRESSES*)HeapAlloc(GetProcessHeap(), 0, bufsize);
|
||||
uret = GetAdaptersAddresses(AF_INET, 0, NULL, buf, &bufsize);
|
||||
}
|
||||
if (uret != ERROR_SUCCESS)
|
||||
{
|
||||
printf("GetAdaptersAddresses() shat itself: %08X\n", uret);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NumAdapters; i++)
|
||||
{
|
||||
adata = &Adapters[i];
|
||||
IP_ADAPTER_ADDRESSES* addr = buf;
|
||||
while (addr)
|
||||
{
|
||||
if (strcmp(addr->AdapterName, adata->DeviceName))
|
||||
{
|
||||
addr = addr->Next;
|
||||
continue;
|
||||
}
|
||||
|
||||
WideCharToMultiByte(CP_UTF8, 0, addr->FriendlyName, 127, adata->FriendlyName, 127, NULL, NULL);
|
||||
adata->FriendlyName[127] = '\0';
|
||||
|
||||
WideCharToMultiByte(CP_UTF8, 0, addr->Description, 127, adata->Description, 127, NULL, NULL);
|
||||
adata->Description[127] = '\0';
|
||||
|
||||
if (addr->PhysicalAddressLength != 6)
|
||||
{
|
||||
printf("weird MAC addr length %d for %s\n", addr->PhysicalAddressLength, addr->AdapterName);
|
||||
}
|
||||
else
|
||||
memcpy(adata->MAC, addr->PhysicalAddress, 6);
|
||||
|
||||
IP_ADAPTER_UNICAST_ADDRESS* ipaddr = addr->FirstUnicastAddress;
|
||||
while (ipaddr)
|
||||
{
|
||||
SOCKADDR* sa = ipaddr->Address.lpSockaddr;
|
||||
if (sa->sa_family == AF_INET)
|
||||
{
|
||||
struct in_addr sa4 = ((sockaddr_in*)sa)->sin_addr;
|
||||
memcpy(adata->IP_v4, &sa4, 4);
|
||||
}
|
||||
|
||||
ipaddr = ipaddr->Next;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, buf);
|
||||
|
||||
#else
|
||||
|
||||
struct ifaddrs* addrs;
|
||||
if (getifaddrs(&addrs) != 0)
|
||||
{
|
||||
printf("getifaddrs() shat itself :(\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NumAdapters; i++)
|
||||
{
|
||||
adata = &Adapters[i];
|
||||
struct ifaddrs* curaddr = addrs;
|
||||
while (curaddr)
|
||||
{
|
||||
if (strcmp(curaddr->ifa_name, adata->DeviceName))
|
||||
{
|
||||
curaddr = curaddr->ifa_next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!curaddr->ifa_addr)
|
||||
{
|
||||
printf("Device (%s) does not have an address :/\n", curaddr->ifa_name);
|
||||
curaddr = curaddr->ifa_next;
|
||||
continue;
|
||||
}
|
||||
|
||||
u16 af = curaddr->ifa_addr->sa_family;
|
||||
if (af == AF_INET)
|
||||
{
|
||||
struct sockaddr_in* sa = (sockaddr_in*)curaddr->ifa_addr;
|
||||
memcpy(adata->IP_v4, &sa->sin_addr, 4);
|
||||
}
|
||||
else if (af == AF_PACKET)
|
||||
{
|
||||
struct sockaddr_ll* sa = (sockaddr_ll*)curaddr->ifa_addr;
|
||||
if (sa->sll_halen != 6)
|
||||
printf("weird MAC length %d for %s\n", sa->sll_halen, curaddr->ifa_name);
|
||||
else
|
||||
memcpy(adata->MAC, sa->sll_addr, 6);
|
||||
}
|
||||
|
||||
curaddr = curaddr->ifa_next;
|
||||
}
|
||||
}
|
||||
|
||||
freeifaddrs(addrs);
|
||||
|
||||
#endif // __WIN32__
|
||||
|
||||
if (!open_adapter) return true;
|
||||
if (PCapAdapter) pcap_close(PCapAdapter);
|
||||
|
||||
// open pcap device
|
||||
PCapAdapterData = &Adapters[0];
|
||||
for (int i = 0; i < NumAdapters; i++)
|
||||
{
|
||||
if (!strncmp(Adapters[i].DeviceName, Config::LANDevice, 128))
|
||||
PCapAdapterData = &Adapters[i];
|
||||
}
|
||||
|
||||
dev = (pcap_if_t*)PCapAdapterData->Internal;
|
||||
PCapAdapter = pcap_open_live(dev->name, 2048, PCAP_OPENFLAG_PROMISCUOUS, 1, errbuf);
|
||||
if (!PCapAdapter)
|
||||
{
|
||||
printf("PCap: failed to open adapter %s\n", errbuf);
|
||||
return false;
|
||||
}
|
||||
|
||||
pcap_freealldevs(alldevs);
|
||||
|
||||
if (pcap_setnonblock(PCapAdapter, 1, errbuf) < 0)
|
||||
{
|
||||
printf("PCap: failed to set nonblocking mode\n");
|
||||
pcap_close(PCapAdapter); PCapAdapter = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeInit()
|
||||
{
|
||||
if (PCapLib)
|
||||
{
|
||||
if (PCapAdapter)
|
||||
{
|
||||
pcap_close(PCapAdapter);
|
||||
PCapAdapter = NULL;
|
||||
}
|
||||
|
||||
SDL_UnloadObject(PCapLib);
|
||||
PCapLib = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RXCallback(u_char* blarg, const struct pcap_pkthdr* header, const u_char* data)
|
||||
{
|
||||
while (RXNum > 0);
|
||||
|
||||
if (header->len > 2048-64) return;
|
||||
|
||||
PacketLen = header->len;
|
||||
memcpy(PacketBuffer, data, PacketLen);
|
||||
RXNum = 1;
|
||||
}
|
||||
|
||||
int SendPacket(u8* data, int len)
|
||||
{
|
||||
if (PCapAdapter == NULL)
|
||||
return 0;
|
||||
|
||||
if (len > 2048)
|
||||
{
|
||||
printf("LAN_SendPacket: error: packet too long (%d)\n", len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pcap_sendpacket(PCapAdapter, data, len);
|
||||
// TODO: check success
|
||||
return len;
|
||||
}
|
||||
|
||||
int RecvPacket(u8* data)
|
||||
{
|
||||
if (PCapAdapter == NULL)
|
||||
return 0;
|
||||
|
||||
int ret = 0;
|
||||
if (RXNum > 0)
|
||||
{
|
||||
memcpy(data, PacketBuffer, PacketLen);
|
||||
ret = PacketLen;
|
||||
RXNum = 0;
|
||||
}
|
||||
|
||||
pcap_dispatch(PCapAdapter, 1, RXCallback, NULL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
53
src/frontend/qt_sdl/LAN_PCap.h
Normal file
53
src/frontend/qt_sdl/LAN_PCap.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef LAN_PCAP_H
|
||||
#define LAN_PCAP_H
|
||||
|
||||
#include "../types.h"
|
||||
|
||||
namespace LAN_PCap
|
||||
{
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char DeviceName[128];
|
||||
char FriendlyName[128];
|
||||
char Description[128];
|
||||
|
||||
u8 MAC[6];
|
||||
u8 IP_v4[4];
|
||||
|
||||
void* Internal;
|
||||
|
||||
} AdapterData;
|
||||
|
||||
|
||||
extern AdapterData* Adapters;
|
||||
extern int NumAdapters;
|
||||
|
||||
|
||||
bool Init(bool open_adapter);
|
||||
void DeInit();
|
||||
|
||||
int SendPacket(u8* data, int len);
|
||||
int RecvPacket(u8* data);
|
||||
|
||||
}
|
||||
|
||||
#endif // LAN_PCAP_H
|
1145
src/frontend/qt_sdl/LAN_Socket.cpp
Normal file
1145
src/frontend/qt_sdl/LAN_Socket.cpp
Normal file
File diff suppressed because it is too large
Load Diff
38
src/frontend/qt_sdl/LAN_Socket.h
Normal file
38
src/frontend/qt_sdl/LAN_Socket.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef LAN_SOCKET_H
|
||||
#define LAN_SOCKET_H
|
||||
|
||||
#include "../types.h"
|
||||
|
||||
namespace LAN_Socket
|
||||
{
|
||||
|
||||
//
|
||||
|
||||
|
||||
bool Init();
|
||||
void DeInit();
|
||||
|
||||
int SendPacket(u8* data, int len);
|
||||
int RecvPacket(u8* data);
|
||||
|
||||
}
|
||||
|
||||
#endif // LAN_SOCKET_H
|
474
src/frontend/qt_sdl/OSD.cpp
Normal file
474
src/frontend/qt_sdl/OSD.cpp
Normal file
@ -0,0 +1,474 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <deque>
|
||||
#include <SDL2/SDL.h>
|
||||
#include "../types.h"
|
||||
|
||||
#include "main.h"
|
||||
#include <QPainter>
|
||||
|
||||
#include "OSD.h"
|
||||
#include "OSD_shaders.h"
|
||||
#include "font.h"
|
||||
|
||||
#include "PlatformConfig.h"
|
||||
|
||||
extern MainWindow* mainWindow;
|
||||
|
||||
namespace OSD
|
||||
{
|
||||
|
||||
const u32 kOSDMargin = 6;
|
||||
|
||||
struct Item
|
||||
{
|
||||
Uint32 Timestamp;
|
||||
char Text[256];
|
||||
u32 Color;
|
||||
|
||||
u32 Width, Height;
|
||||
u32* Bitmap;
|
||||
|
||||
bool NativeBitmapLoaded;
|
||||
QImage NativeBitmap;
|
||||
|
||||
bool GLTextureLoaded;
|
||||
GLuint GLTexture;
|
||||
|
||||
};
|
||||
|
||||
std::deque<Item> ItemQueue;
|
||||
|
||||
QOpenGLShaderProgram* Shader;
|
||||
GLint uScreenSize, uOSDPos, uOSDSize;
|
||||
GLuint OSDVertexArray;
|
||||
GLuint OSDVertexBuffer;
|
||||
|
||||
volatile bool Rendering;
|
||||
|
||||
|
||||
bool Init(QOpenGLFunctions_3_2_Core* f)
|
||||
{
|
||||
if (f)
|
||||
{
|
||||
Shader = new QOpenGLShaderProgram();
|
||||
Shader->addShaderFromSourceCode(QOpenGLShader::Vertex, kScreenVS_OSD);
|
||||
Shader->addShaderFromSourceCode(QOpenGLShader::Fragment, kScreenFS_OSD);
|
||||
|
||||
GLuint pid = Shader->programId();
|
||||
f->glBindAttribLocation(pid, 0, "vPosition");
|
||||
f->glBindFragDataLocation(pid, 0, "oColor");
|
||||
|
||||
Shader->link();
|
||||
|
||||
Shader->bind();
|
||||
Shader->setUniformValue("OSDTex", (GLint)0);
|
||||
Shader->release();
|
||||
|
||||
uScreenSize = Shader->uniformLocation("uScreenSize");
|
||||
uOSDPos = Shader->uniformLocation("uOSDPos");
|
||||
uOSDSize = Shader->uniformLocation("uOSDSize");
|
||||
|
||||
float vertices[6*2] =
|
||||
{
|
||||
0, 0,
|
||||
1, 1,
|
||||
1, 0,
|
||||
0, 0,
|
||||
0, 1,
|
||||
1, 1
|
||||
};
|
||||
|
||||
f->glGenBuffers(1, &OSDVertexBuffer);
|
||||
f->glBindBuffer(GL_ARRAY_BUFFER, OSDVertexBuffer);
|
||||
f->glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
f->glGenVertexArrays(1, &OSDVertexArray);
|
||||
f->glBindVertexArray(OSDVertexArray);
|
||||
f->glEnableVertexAttribArray(0); // position
|
||||
f->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)(0));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeInit(QOpenGLFunctions_3_2_Core* f)
|
||||
{
|
||||
for (auto it = ItemQueue.begin(); it != ItemQueue.end(); )
|
||||
{
|
||||
Item& item = *it;
|
||||
|
||||
if (item.GLTextureLoaded && f) f->glDeleteTextures(1, &item.GLTexture);
|
||||
if (item.Bitmap) delete[] item.Bitmap;
|
||||
|
||||
it = ItemQueue.erase(it);
|
||||
}
|
||||
|
||||
if (f) delete Shader;
|
||||
}
|
||||
|
||||
|
||||
int FindBreakPoint(const char* text, int i)
|
||||
{
|
||||
// i = character that went out of bounds
|
||||
|
||||
for (int j = i; j >= 0; j--)
|
||||
{
|
||||
if (text[j] == ' ')
|
||||
return j;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void LayoutText(const char* text, u32* width, u32* height, int* breaks)
|
||||
{
|
||||
u32 w = 0;
|
||||
u32 h = 14;
|
||||
u32 totalw = 0;
|
||||
u32 maxw = mainWindow->panel->width() - (kOSDMargin*2);
|
||||
int lastbreak = -1;
|
||||
int numbrk = 0;
|
||||
u16* ptr;
|
||||
|
||||
memset(breaks, 0, sizeof(int)*64);
|
||||
|
||||
for (int i = 0; text[i] != '\0'; )
|
||||
{
|
||||
int glyphsize;
|
||||
if (text[i] == ' ')
|
||||
{
|
||||
glyphsize = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 ch = text[i];
|
||||
if (ch < 0x10 || ch > 0x7E) ch = 0x7F;
|
||||
|
||||
ptr = &font[(ch-0x10) << 4];
|
||||
glyphsize = ptr[0];
|
||||
if (!glyphsize) glyphsize = 6;
|
||||
else glyphsize += 2; // space around the character
|
||||
}
|
||||
|
||||
w += glyphsize;
|
||||
if (w > maxw)
|
||||
{
|
||||
// wrap shit as needed
|
||||
if (text[i] == ' ')
|
||||
{
|
||||
if (numbrk >= 64) break;
|
||||
breaks[numbrk++] = i;
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int brk = FindBreakPoint(text, i);
|
||||
if (brk != lastbreak) i = brk;
|
||||
|
||||
if (numbrk >= 64) break;
|
||||
breaks[numbrk++] = i;
|
||||
|
||||
lastbreak = brk;
|
||||
}
|
||||
|
||||
w = 0;
|
||||
h += 14;
|
||||
}
|
||||
else
|
||||
i++;
|
||||
|
||||
if (w > totalw) totalw = w;
|
||||
}
|
||||
|
||||
*width = totalw;
|
||||
*height = h;
|
||||
}
|
||||
|
||||
u32 RainbowColor(u32 inc)
|
||||
{
|
||||
// inspired from Acmlmboard
|
||||
|
||||
if (inc < 100) return 0xFFFF9B9B + (inc << 8);
|
||||
else if (inc < 200) return 0xFFFFFF9B - ((inc-100) << 16);
|
||||
else if (inc < 300) return 0xFF9BFF9B + (inc-200);
|
||||
else if (inc < 400) return 0xFF9BFFFF - ((inc-300) << 8);
|
||||
else if (inc < 500) return 0xFF9B9BFF + ((inc-400) << 16);
|
||||
else return 0xFFFF9BFF - (inc-500);
|
||||
}
|
||||
|
||||
void RenderText(u32 color, const char* text, Item* item)
|
||||
{
|
||||
u32 w, h;
|
||||
int breaks[64];
|
||||
|
||||
bool rainbow = (color == 0);
|
||||
u32 rainbowinc = ((text[0] * 17) + (SDL_GetTicks() * 13)) % 600;
|
||||
|
||||
color |= 0xFF000000;
|
||||
const u32 shadow = 0xE0000000;
|
||||
|
||||
LayoutText(text, &w, &h, breaks);
|
||||
|
||||
item->Width = w;
|
||||
item->Height = h;
|
||||
item->Bitmap = new u32[w*h];
|
||||
memset(item->Bitmap, 0, w*h*sizeof(u32));
|
||||
|
||||
u32 x = 0, y = 1;
|
||||
u32 maxw = mainWindow->panel->width() - (kOSDMargin*2);
|
||||
int curline = 0;
|
||||
u16* ptr;
|
||||
|
||||
for (int i = 0; text[i] != '\0'; )
|
||||
{
|
||||
int glyphsize;
|
||||
if (text[i] == ' ')
|
||||
{
|
||||
x += 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 ch = text[i];
|
||||
if (ch < 0x10 || ch > 0x7E) ch = 0x7F;
|
||||
|
||||
ptr = &font[(ch-0x10) << 4];
|
||||
int glyphsize = ptr[0];
|
||||
if (!glyphsize) x += 6;
|
||||
else
|
||||
{
|
||||
x++;
|
||||
|
||||
if (rainbow)
|
||||
{
|
||||
color = RainbowColor(rainbowinc);
|
||||
rainbowinc = (rainbowinc + 30) % 600;
|
||||
}
|
||||
|
||||
// draw character
|
||||
for (int cy = 0; cy < 12; cy++)
|
||||
{
|
||||
u16 val = ptr[4+cy];
|
||||
|
||||
for (int cx = 0; cx < glyphsize; cx++)
|
||||
{
|
||||
if (val & (1<<cx))
|
||||
item->Bitmap[((y+cy) * w) + x+cx] = color;
|
||||
}
|
||||
}
|
||||
|
||||
x += glyphsize;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
if (breaks[curline] && i >= breaks[curline])
|
||||
{
|
||||
i = breaks[curline++];
|
||||
if (text[i] == ' ') i++;
|
||||
|
||||
x = 0;
|
||||
y += 14;
|
||||
}
|
||||
}
|
||||
|
||||
// shadow
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
val = item->Bitmap[(y * w) + x];
|
||||
if ((val >> 24) == 0xFF) continue;
|
||||
|
||||
if (x > 0) val = item->Bitmap[(y * w) + x-1];
|
||||
if (x < w-1) val |= item->Bitmap[(y * w) + x+1];
|
||||
if (y > 0)
|
||||
{
|
||||
if (x > 0) val |= item->Bitmap[((y-1) * w) + x-1];
|
||||
val |= item->Bitmap[((y-1) * w) + x];
|
||||
if (x < w-1) val |= item->Bitmap[((y-1) * w) + x+1];
|
||||
}
|
||||
if (y < h-1)
|
||||
{
|
||||
if (x > 0) val |= item->Bitmap[((y+1) * w) + x-1];
|
||||
val |= item->Bitmap[((y+1) * w) + x];
|
||||
if (x < w-1) val |= item->Bitmap[((y+1) * w) + x+1];
|
||||
}
|
||||
|
||||
if ((val >> 24) == 0xFF)
|
||||
item->Bitmap[(y * w) + x] = shadow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AddMessage(u32 color, const char* text)
|
||||
{
|
||||
if (!Config::ShowOSD) return;
|
||||
|
||||
while (Rendering);
|
||||
|
||||
Item item;
|
||||
|
||||
item.Timestamp = SDL_GetTicks();
|
||||
strncpy(item.Text, text, 255); item.Text[255] = '\0';
|
||||
item.Color = color;
|
||||
item.Bitmap = nullptr;
|
||||
|
||||
item.NativeBitmapLoaded = false;
|
||||
item.GLTextureLoaded = false;
|
||||
|
||||
ItemQueue.push_back(item);
|
||||
}
|
||||
|
||||
void Update(QOpenGLFunctions_3_2_Core* f)
|
||||
{
|
||||
if (!Config::ShowOSD)
|
||||
{
|
||||
Rendering = true;
|
||||
for (auto it = ItemQueue.begin(); it != ItemQueue.end(); )
|
||||
{
|
||||
Item& item = *it;
|
||||
|
||||
if (item.GLTextureLoaded && f) f->glDeleteTextures(1, &item.GLTexture);
|
||||
if (item.Bitmap) delete[] item.Bitmap;
|
||||
|
||||
it = ItemQueue.erase(it);
|
||||
}
|
||||
Rendering = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Rendering = true;
|
||||
|
||||
Uint32 tick_now = SDL_GetTicks();
|
||||
Uint32 tick_min = tick_now - 2500;
|
||||
|
||||
for (auto it = ItemQueue.begin(); it != ItemQueue.end(); )
|
||||
{
|
||||
Item& item = *it;
|
||||
|
||||
if (item.Timestamp < tick_min)
|
||||
{
|
||||
if (item.GLTextureLoaded) f->glDeleteTextures(1, &item.GLTexture);
|
||||
if (item.Bitmap) delete[] item.Bitmap;
|
||||
|
||||
it = ItemQueue.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!item.Bitmap)
|
||||
{
|
||||
RenderText(item.Color, item.Text, &item);
|
||||
}
|
||||
|
||||
it++;
|
||||
}
|
||||
|
||||
Rendering = false;
|
||||
}
|
||||
|
||||
void DrawNative(QPainter& painter)
|
||||
{
|
||||
if (!Config::ShowOSD) return;
|
||||
|
||||
Rendering = true;
|
||||
|
||||
u32 y = kOSDMargin;
|
||||
|
||||
painter.resetTransform();
|
||||
|
||||
for (auto it = ItemQueue.begin(); it != ItemQueue.end(); )
|
||||
{
|
||||
Item& item = *it;
|
||||
|
||||
if (!item.NativeBitmapLoaded)
|
||||
{
|
||||
item.NativeBitmap = QImage((const uchar*)item.Bitmap, item.Width, item.Height, QImage::Format_ARGB32_Premultiplied);
|
||||
item.NativeBitmapLoaded = true;
|
||||
}
|
||||
|
||||
painter.drawImage(kOSDMargin, y, item.NativeBitmap);
|
||||
|
||||
y += item.Height;
|
||||
it++;
|
||||
}
|
||||
|
||||
Rendering = false;
|
||||
}
|
||||
|
||||
void DrawGL(QOpenGLFunctions_3_2_Core* f, float w, float h)
|
||||
{
|
||||
if (!Config::ShowOSD) return;
|
||||
if (!mainWindow || !mainWindow->panel) return;
|
||||
|
||||
Rendering = true;
|
||||
|
||||
u32 y = kOSDMargin;
|
||||
|
||||
Shader->bind();
|
||||
|
||||
f->glUniform2f(uScreenSize, w, h);
|
||||
|
||||
f->glBindBuffer(GL_ARRAY_BUFFER, OSDVertexBuffer);
|
||||
f->glBindVertexArray(OSDVertexArray);
|
||||
|
||||
f->glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
f->glEnable(GL_BLEND);
|
||||
f->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
for (auto it = ItemQueue.begin(); it != ItemQueue.end(); )
|
||||
{
|
||||
Item& item = *it;
|
||||
|
||||
if (!item.GLTextureLoaded)
|
||||
{
|
||||
f->glGenTextures(1, &item.GLTexture);
|
||||
f->glBindTexture(GL_TEXTURE_2D, item.GLTexture);
|
||||
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
f->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, item.Width, item.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, item.Bitmap);
|
||||
|
||||
item.GLTextureLoaded = true;
|
||||
}
|
||||
|
||||
f->glBindTexture(GL_TEXTURE_2D, item.GLTexture);
|
||||
f->glUniform2i(uOSDPos, kOSDMargin, y);
|
||||
f->glUniform2i(uOSDSize, item.Width, item.Height);
|
||||
f->glDrawArrays(GL_TRIANGLES, 0, 2*3);
|
||||
|
||||
y += item.Height;
|
||||
it++;
|
||||
}
|
||||
|
||||
f->glDisable(GL_BLEND);
|
||||
Shader->release();
|
||||
|
||||
Rendering = false;
|
||||
}
|
||||
|
||||
}
|
36
src/frontend/qt_sdl/OSD.h
Normal file
36
src/frontend/qt_sdl/OSD.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef OSD_H
|
||||
#define OSD_H
|
||||
|
||||
namespace OSD
|
||||
{
|
||||
|
||||
bool Init(QOpenGLFunctions_3_2_Core* f);
|
||||
void DeInit(QOpenGLFunctions_3_2_Core* f);
|
||||
|
||||
void AddMessage(u32 color, const char* text);
|
||||
|
||||
void Update(QOpenGLFunctions_3_2_Core* f);
|
||||
void DrawNative(QPainter& painter);
|
||||
void DrawGL(QOpenGLFunctions_3_2_Core* f, float w, float h);
|
||||
|
||||
}
|
||||
|
||||
#endif // OSD_H
|
65
src/frontend/qt_sdl/OSD_shaders.h
Normal file
65
src/frontend/qt_sdl/OSD_shaders.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef OSD_SHADERS_H
|
||||
#define OSD_SHADERS_H
|
||||
|
||||
const char* kScreenVS_OSD = R"(#version 140
|
||||
|
||||
uniform vec2 uScreenSize;
|
||||
|
||||
uniform ivec2 uOSDPos;
|
||||
uniform ivec2 uOSDSize;
|
||||
|
||||
in vec2 vPosition;
|
||||
|
||||
smooth out vec2 fTexcoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 fpos;
|
||||
|
||||
vec2 osdpos = (vPosition * vec2(uOSDSize));
|
||||
fTexcoord = osdpos;
|
||||
osdpos += uOSDPos;
|
||||
|
||||
fpos.xy = ((osdpos * 2.0) / uScreenSize) - 1.0;
|
||||
fpos.y *= -1;
|
||||
fpos.z = 0.0;
|
||||
fpos.w = 1.0;
|
||||
|
||||
gl_Position = fpos;
|
||||
}
|
||||
)";
|
||||
|
||||
const char* kScreenFS_OSD = R"(#version 140
|
||||
|
||||
uniform sampler2D OSDTex;
|
||||
|
||||
smooth in vec2 fTexcoord;
|
||||
|
||||
out vec4 oColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 pixel = texelFetch(OSDTex, ivec2(fTexcoord), 0);
|
||||
oColor = pixel.bgra;
|
||||
}
|
||||
)";
|
||||
|
||||
#endif // OSD_SHADERS_H
|
@ -27,8 +27,9 @@
|
||||
|
||||
#include "Platform.h"
|
||||
#include "PlatformConfig.h"
|
||||
//#include "LAN_Socket.h"
|
||||
//#include "LAN_PCap.h"
|
||||
#include "LAN_Socket.h"
|
||||
#include "LAN_PCap.h"
|
||||
#include <string>
|
||||
|
||||
#ifdef __WIN32__
|
||||
#define NTDDI_VERSION 0x06000000 // GROSS FUCKING HACK
|
||||
@ -56,9 +57,10 @@
|
||||
#endif
|
||||
|
||||
|
||||
extern char* EmuDirectory;
|
||||
char* EmuDirectory;
|
||||
|
||||
void Stop(bool internal);
|
||||
void emuStop();
|
||||
void* oglGetProcAddress(const char* proc);
|
||||
|
||||
|
||||
namespace Platform
|
||||
@ -71,11 +73,57 @@ u8 PacketBuffer[2048];
|
||||
#define NIFI_VER 1
|
||||
|
||||
|
||||
void Init(int argc, char** argv)
|
||||
{
|
||||
#if defined(__WIN32__) || defined(UNIX_PORTABLE)
|
||||
if (argc > 0 && strlen(argv[0]) > 0)
|
||||
{
|
||||
int len = strlen(argv[0]);
|
||||
while (len > 0)
|
||||
{
|
||||
if (argv[0][len] == '/') break;
|
||||
if (argv[0][len] == '\\') break;
|
||||
len--;
|
||||
}
|
||||
if (len > 0)
|
||||
{
|
||||
EmuDirectory = new char[len+1];
|
||||
strncpy(EmuDirectory, argv[0], len);
|
||||
EmuDirectory[len] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
EmuDirectory = new char[2];
|
||||
strcpy(EmuDirectory, ".");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EmuDirectory = new char[2];
|
||||
strcpy(EmuDirectory, ".");
|
||||
}
|
||||
#else
|
||||
QString confdir;
|
||||
QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
|
||||
config.mkdir("melonDS");
|
||||
confdir = config.absolutePath() + "/melonDS/";
|
||||
EmuDirectory = new char[confdir.length() + 1];
|
||||
memcpy(EmuDirectory, confdir.toUtf8().data(), confdir.length());
|
||||
#endif
|
||||
}
|
||||
|
||||
void DeInit()
|
||||
{
|
||||
delete[] EmuDirectory;
|
||||
}
|
||||
|
||||
|
||||
void StopEmu()
|
||||
{
|
||||
//Stop(true);
|
||||
emuStop();
|
||||
}
|
||||
|
||||
|
||||
FILE* OpenFile(const char* path, const char* mode, bool mustexist)
|
||||
{
|
||||
QFile f(path);
|
||||
@ -200,30 +248,30 @@ void Semaphore_Post(void* sema)
|
||||
|
||||
void* GL_GetProcAddress(const char* proc)
|
||||
{
|
||||
return (void*) QOpenGLContext::globalShareContext()->getProcAddress(proc);
|
||||
return oglGetProcAddress(proc);
|
||||
}
|
||||
|
||||
|
||||
bool MP_Init()
|
||||
{
|
||||
int opt_true = 1;
|
||||
int res;
|
||||
int opt_true = 1;
|
||||
int res;
|
||||
|
||||
#ifdef __WIN32__
|
||||
WSADATA wsadata;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsadata) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
WSADATA wsadata;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsadata) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // __WIN32__
|
||||
|
||||
MPSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
MPSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (MPSocket < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEADDR, (const char*) &opt_true, sizeof(int));
|
||||
res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt_true, sizeof(int));
|
||||
if (res < 0)
|
||||
{
|
||||
closesocket(MPSocket);
|
||||
@ -233,8 +281,8 @@ bool MP_Init()
|
||||
|
||||
sockaddr_t saddr;
|
||||
saddr.sa_family = AF_INET;
|
||||
*(u32*) &saddr.sa_data[2] = htonl(Config::SocketBindAnyAddr ? INADDR_ANY : INADDR_LOOPBACK);
|
||||
*(u16*) &saddr.sa_data[0] = htons(7064);
|
||||
*(u32*)&saddr.sa_data[2] = htonl(Config::SocketBindAnyAddr ? INADDR_ANY : INADDR_LOOPBACK);
|
||||
*(u16*)&saddr.sa_data[0] = htons(7064);
|
||||
res = bind(MPSocket, &saddr, sizeof(sockaddr_t));
|
||||
if (res < 0)
|
||||
{
|
||||
@ -243,7 +291,7 @@ bool MP_Init()
|
||||
return false;
|
||||
}
|
||||
|
||||
res = setsockopt(MPSocket, SOL_SOCKET, SO_BROADCAST, (const char*) &opt_true, sizeof(int));
|
||||
res = setsockopt(MPSocket, SOL_SOCKET, SO_BROADCAST, (const char*)&opt_true, sizeof(int));
|
||||
if (res < 0)
|
||||
{
|
||||
closesocket(MPSocket);
|
||||
@ -252,50 +300,50 @@ bool MP_Init()
|
||||
}
|
||||
|
||||
MPSendAddr.sa_family = AF_INET;
|
||||
*(u32*) &MPSendAddr.sa_data[2] = htonl(INADDR_BROADCAST);
|
||||
*(u16*) &MPSendAddr.sa_data[0] = htons(7064);
|
||||
*(u32*)&MPSendAddr.sa_data[2] = htonl(INADDR_BROADCAST);
|
||||
*(u16*)&MPSendAddr.sa_data[0] = htons(7064);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MP_DeInit()
|
||||
{
|
||||
if (MPSocket >= 0)
|
||||
closesocket(MPSocket);
|
||||
if (MPSocket >= 0)
|
||||
closesocket(MPSocket);
|
||||
|
||||
#ifdef __WIN32__
|
||||
WSACleanup();
|
||||
WSACleanup();
|
||||
#endif // __WIN32__
|
||||
}
|
||||
|
||||
int MP_SendPacket(u8* data, int len)
|
||||
{
|
||||
if (MPSocket < 0)
|
||||
return 0;
|
||||
if (MPSocket < 0)
|
||||
return 0;
|
||||
|
||||
if (len > 2048 - 8)
|
||||
{
|
||||
printf("MP_SendPacket: error: packet too long (%d)\n", len);
|
||||
return 0;
|
||||
}
|
||||
if (len > 2048-8)
|
||||
{
|
||||
printf("MP_SendPacket: error: packet too long (%d)\n", len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*(u32*) &PacketBuffer[0] = htonl(0x4946494E); // NIFI
|
||||
PacketBuffer[4] = NIFI_VER;
|
||||
PacketBuffer[5] = 0;
|
||||
*(u16*) &PacketBuffer[6] = htons(len);
|
||||
memcpy(&PacketBuffer[8], data, len);
|
||||
*(u32*)&PacketBuffer[0] = htonl(0x4946494E); // NIFI
|
||||
PacketBuffer[4] = NIFI_VER;
|
||||
PacketBuffer[5] = 0;
|
||||
*(u16*)&PacketBuffer[6] = htons(len);
|
||||
memcpy(&PacketBuffer[8], data, len);
|
||||
|
||||
int slen = sendto(MPSocket, (const char*) PacketBuffer, len + 8, 0, &MPSendAddr, sizeof(sockaddr_t));
|
||||
if (slen < 8) return 0;
|
||||
return slen - 8;
|
||||
int slen = sendto(MPSocket, (const char*)PacketBuffer, len+8, 0, &MPSendAddr, sizeof(sockaddr_t));
|
||||
if (slen < 8) return 0;
|
||||
return slen - 8;
|
||||
}
|
||||
|
||||
int MP_RecvPacket(u8* data, bool block)
|
||||
{
|
||||
if (MPSocket < 0)
|
||||
return 0;
|
||||
if (MPSocket < 0)
|
||||
return 0;
|
||||
|
||||
fd_set fd;
|
||||
fd_set fd;
|
||||
struct timeval tv;
|
||||
|
||||
FD_ZERO(&fd);
|
||||
@ -303,83 +351,82 @@ int MP_RecvPacket(u8* data, bool block)
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = block ? 5000 : 0;
|
||||
|
||||
if (!select(MPSocket + 1, &fd, 0, 0, &tv))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!select(MPSocket+1, &fd, 0, 0, &tv))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
sockaddr_t fromAddr;
|
||||
socklen_t fromLen = sizeof(sockaddr_t);
|
||||
int rlen = recvfrom(MPSocket, (char*) PacketBuffer, 2048, 0, &fromAddr, &fromLen);
|
||||
if (rlen < 8 + 24)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
rlen -= 8;
|
||||
sockaddr_t fromAddr;
|
||||
socklen_t fromLen = sizeof(sockaddr_t);
|
||||
int rlen = recvfrom(MPSocket, (char*)PacketBuffer, 2048, 0, &fromAddr, &fromLen);
|
||||
if (rlen < 8+24)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
rlen -= 8;
|
||||
|
||||
if (ntohl(*(u32*) &PacketBuffer[0]) != 0x4946494E)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (ntohl(*(u32*)&PacketBuffer[0]) != 0x4946494E)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (PacketBuffer[4] != NIFI_VER)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (PacketBuffer[4] != NIFI_VER)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ntohs(*(u16*) &PacketBuffer[6]) != rlen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (ntohs(*(u16*)&PacketBuffer[6]) != rlen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(data, &PacketBuffer[8], rlen);
|
||||
return rlen;
|
||||
memcpy(data, &PacketBuffer[8], rlen);
|
||||
return rlen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool LAN_Init()
|
||||
{
|
||||
/*if (Config::DirectLAN)
|
||||
{
|
||||
if (!LAN_PCap::Init(true))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!LAN_Socket::Init())
|
||||
return false;
|
||||
}*/
|
||||
if (Config::DirectLAN)
|
||||
{
|
||||
if (!LAN_PCap::Init(true))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!LAN_Socket::Init())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LAN_DeInit()
|
||||
{
|
||||
// checkme. blarg
|
||||
//if (Config::DirectLAN)
|
||||
// LAN_PCap::DeInit();
|
||||
//else
|
||||
// LAN_Socket::DeInit();
|
||||
/*LAN_PCap::DeInit();
|
||||
LAN_Socket::DeInit();*/
|
||||
// checkme. blarg
|
||||
//if (Config::DirectLAN)
|
||||
// LAN_PCap::DeInit();
|
||||
//else
|
||||
// LAN_Socket::DeInit();
|
||||
LAN_PCap::DeInit();
|
||||
LAN_Socket::DeInit();
|
||||
}
|
||||
|
||||
int LAN_SendPacket(u8* data, int len)
|
||||
{
|
||||
/*if (Config::DirectLAN)
|
||||
return LAN_PCap::SendPacket(data, len);
|
||||
else
|
||||
return LAN_Socket::SendPacket(data, len);*/
|
||||
return 0;
|
||||
if (Config::DirectLAN)
|
||||
return LAN_PCap::SendPacket(data, len);
|
||||
else
|
||||
return LAN_Socket::SendPacket(data, len);
|
||||
}
|
||||
|
||||
int LAN_RecvPacket(u8* data)
|
||||
{
|
||||
/*if (Config::DirectLAN)
|
||||
return LAN_PCap::RecvPacket(data);
|
||||
else
|
||||
return LAN_Socket::RecvPacket(data);*/
|
||||
return 0;
|
||||
if (Config::DirectLAN)
|
||||
return LAN_PCap::RecvPacket(data);
|
||||
else
|
||||
return LAN_Socket::RecvPacket(data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,16 +40,24 @@ int ScreenRotation;
|
||||
int ScreenGap;
|
||||
int ScreenLayout;
|
||||
int ScreenSizing;
|
||||
int IntegerScaling;
|
||||
int ScreenFilter;
|
||||
|
||||
int ScreenUseGL;
|
||||
int ScreenVSync;
|
||||
int ScreenRatio;
|
||||
int ScreenVSyncInterval;
|
||||
|
||||
int _3DRenderer;
|
||||
int Threaded3D;
|
||||
|
||||
int GL_ScaleFactor;
|
||||
int GL_Antialias;
|
||||
|
||||
int LimitFPS;
|
||||
int AudioSync;
|
||||
int ShowOSD;
|
||||
|
||||
int ConsoleType;
|
||||
int DirectBoot;
|
||||
|
||||
int SocketBindAnyAddr;
|
||||
@ -60,25 +68,25 @@ int SavestateRelocSRAM;
|
||||
|
||||
int AudioVolume;
|
||||
int MicInputType;
|
||||
char MicWavPath[512];
|
||||
char MicWavPath[1024];
|
||||
|
||||
char LastROMFolder[512];
|
||||
char LastROMFolder[1024];
|
||||
|
||||
|
||||
ConfigEntry PlatformConfigFile[] =
|
||||
{
|
||||
{"Key_A", 0, &KeyMapping[0], 32, NULL, 0},
|
||||
{"Key_B", 0, &KeyMapping[1], 31, NULL, 0},
|
||||
{"Key_Select", 0, &KeyMapping[2], 57, NULL, 0},
|
||||
{"Key_Start", 0, &KeyMapping[3], 28, NULL, 0},
|
||||
{"Key_Right", 0, &KeyMapping[4], 333, NULL, 0},
|
||||
{"Key_Left", 0, &KeyMapping[5], 331, NULL, 0},
|
||||
{"Key_Up", 0, &KeyMapping[6], 328, NULL, 0},
|
||||
{"Key_Down", 0, &KeyMapping[7], 336, NULL, 0},
|
||||
{"Key_R", 0, &KeyMapping[8], 54, NULL, 0},
|
||||
{"Key_L", 0, &KeyMapping[9], 86, NULL, 0},
|
||||
{"Key_X", 0, &KeyMapping[10], 17, NULL, 0},
|
||||
{"Key_Y", 0, &KeyMapping[11], 30, NULL, 0},
|
||||
{"Key_A", 0, &KeyMapping[0], -1, NULL, 0},
|
||||
{"Key_B", 0, &KeyMapping[1], -1, NULL, 0},
|
||||
{"Key_Select", 0, &KeyMapping[2], -1, NULL, 0},
|
||||
{"Key_Start", 0, &KeyMapping[3], -1, NULL, 0},
|
||||
{"Key_Right", 0, &KeyMapping[4], -1, NULL, 0},
|
||||
{"Key_Left", 0, &KeyMapping[5], -1, NULL, 0},
|
||||
{"Key_Up", 0, &KeyMapping[6], -1, NULL, 0},
|
||||
{"Key_Down", 0, &KeyMapping[7], -1, NULL, 0},
|
||||
{"Key_R", 0, &KeyMapping[8], -1, NULL, 0},
|
||||
{"Key_L", 0, &KeyMapping[9], -1, NULL, 0},
|
||||
{"Key_X", 0, &KeyMapping[10], -1, NULL, 0},
|
||||
{"Key_Y", 0, &KeyMapping[11], -1, NULL, 0},
|
||||
|
||||
{"Joy_A", 0, &JoyMapping[0], -1, NULL, 0},
|
||||
{"Joy_B", 0, &JoyMapping[1], -1, NULL, 0},
|
||||
@ -93,14 +101,14 @@ ConfigEntry PlatformConfigFile[] =
|
||||
{"Joy_X", 0, &JoyMapping[10], -1, NULL, 0},
|
||||
{"Joy_Y", 0, &JoyMapping[11], -1, NULL, 0},
|
||||
|
||||
{"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], 0x0D, NULL, 0},
|
||||
{"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], 0x35, NULL, 0},
|
||||
{"HKKey_Pause", 0, &HKKeyMapping[HK_Pause], -1, NULL, 0},
|
||||
{"HKKey_Reset", 0, &HKKeyMapping[HK_Reset], -1, NULL, 0},
|
||||
{"HKKey_FastForward", 0, &HKKeyMapping[HK_FastForward], 0x0F, NULL, 0},
|
||||
{"HKKey_FastForwardToggle", 0, &HKKeyMapping[HK_FastForwardToggle], -1, NULL, 0},
|
||||
{"HKKey_SolarSensorDecrease", 0, &HKKeyMapping[HK_SolarSensorDecrease], 0x4B, NULL, 0},
|
||||
{"HKKey_SolarSensorIncrease", 0, &HKKeyMapping[HK_SolarSensorIncrease], 0x4D, NULL, 0},
|
||||
{"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], -1, NULL, 0},
|
||||
{"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], -1, NULL, 0},
|
||||
{"HKKey_Pause", 0, &HKKeyMapping[HK_Pause], -1, NULL, 0},
|
||||
{"HKKey_Reset", 0, &HKKeyMapping[HK_Reset], -1, NULL, 0},
|
||||
{"HKKey_FastForward", 0, &HKKeyMapping[HK_FastForward], -1, NULL, 0},
|
||||
{"HKKey_FastForwardToggle", 0, &HKKeyMapping[HK_FastForwardToggle], -1, NULL, 0},
|
||||
{"HKKey_SolarSensorDecrease", 0, &HKKeyMapping[HK_SolarSensorDecrease], -1, NULL, 0},
|
||||
{"HKKey_SolarSensorIncrease", 0, &HKKeyMapping[HK_SolarSensorIncrease], -1, NULL, 0},
|
||||
|
||||
{"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1, NULL, 0},
|
||||
{"HKJoy_Mic", 0, &HKJoyMapping[HK_Mic], -1, NULL, 0},
|
||||
@ -121,16 +129,24 @@ ConfigEntry PlatformConfigFile[] =
|
||||
{"ScreenGap", 0, &ScreenGap, 0, NULL, 0},
|
||||
{"ScreenLayout", 0, &ScreenLayout, 0, NULL, 0},
|
||||
{"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0},
|
||||
{"IntegerScaling", 0, &IntegerScaling, 0, NULL, 0},
|
||||
{"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0},
|
||||
|
||||
{"ScreenUseGL", 0, &ScreenUseGL, 1, NULL, 0},
|
||||
{"ScreenVSync", 0, &ScreenVSync, 0, NULL, 0},
|
||||
{"ScreenRatio", 0, &ScreenRatio, 0, NULL, 0},
|
||||
{"ScreenUseGL", 0, &ScreenUseGL, 1, NULL, 0},
|
||||
{"ScreenVSync", 0, &ScreenVSync, 0, NULL, 0},
|
||||
{"ScreenVSyncInterval", 0, &ScreenVSyncInterval, 1, NULL, 0},
|
||||
|
||||
{"3DRenderer", 0, &_3DRenderer, 1, NULL, 0},
|
||||
{"Threaded3D", 0, &Threaded3D, 1, NULL, 0},
|
||||
|
||||
{"GL_ScaleFactor", 0, &GL_ScaleFactor, 1, NULL, 0},
|
||||
{"GL_Antialias", 0, &GL_Antialias, 0, NULL, 0},
|
||||
|
||||
{"LimitFPS", 0, &LimitFPS, 0, NULL, 0},
|
||||
{"AudioSync", 0, &AudioSync, 1, NULL, 0},
|
||||
{"ShowOSD", 0, &ShowOSD, 1, NULL, 0},
|
||||
|
||||
{"ConsoleType", 0, &ConsoleType, 0, NULL, 0},
|
||||
{"DirectBoot", 0, &DirectBoot, 1, NULL, 0},
|
||||
|
||||
{"SockBindAnyAddr", 0, &SocketBindAnyAddr, 0, NULL, 0},
|
||||
@ -141,9 +157,9 @@ ConfigEntry PlatformConfigFile[] =
|
||||
|
||||
{"AudioVolume", 0, &AudioVolume, 256, NULL, 0},
|
||||
{"MicInputType", 0, &MicInputType, 1, NULL, 0},
|
||||
{"MicWavPath", 1, MicWavPath, 0, "", 511},
|
||||
{"MicWavPath", 1, MicWavPath, 0, "", 1023},
|
||||
|
||||
{"LastROMFolder", 1, LastROMFolder, 0, "", 511},
|
||||
{"LastROMFolder", 1, LastROMFolder, 0, "", 1023},
|
||||
|
||||
{"", -1, NULL, 0, NULL, 0}
|
||||
};
|
||||
|
@ -53,16 +53,24 @@ extern int ScreenRotation;
|
||||
extern int ScreenGap;
|
||||
extern int ScreenLayout;
|
||||
extern int ScreenSizing;
|
||||
extern int IntegerScaling;
|
||||
extern int ScreenFilter;
|
||||
|
||||
extern int ScreenUseGL;
|
||||
extern int ScreenVSync;
|
||||
extern int ScreenRatio;
|
||||
extern int ScreenVSyncInterval;
|
||||
|
||||
extern int _3DRenderer;
|
||||
extern int Threaded3D;
|
||||
|
||||
extern int GL_ScaleFactor;
|
||||
extern int GL_Antialias;
|
||||
|
||||
extern int LimitFPS;
|
||||
extern int AudioSync;
|
||||
extern int ShowOSD;
|
||||
|
||||
extern int ConsoleType;
|
||||
extern int DirectBoot;
|
||||
|
||||
extern int SocketBindAnyAddr;
|
||||
@ -73,9 +81,9 @@ extern int SavestateRelocSRAM;
|
||||
|
||||
extern int AudioVolume;
|
||||
extern int MicInputType;
|
||||
extern char MicWavPath[512];
|
||||
extern char MicWavPath[1024];
|
||||
|
||||
extern char LastROMFolder[512];
|
||||
extern char LastROMFolder[1024];
|
||||
|
||||
}
|
||||
|
||||
|
169
src/frontend/qt_sdl/VideoSettingsDialog.cpp
Normal file
169
src/frontend/qt_sdl/VideoSettingsDialog.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include "types.h"
|
||||
#include "Platform.h"
|
||||
#include "Config.h"
|
||||
#include "PlatformConfig.h"
|
||||
|
||||
#include "VideoSettingsDialog.h"
|
||||
#include "ui_VideoSettingsDialog.h"
|
||||
|
||||
|
||||
VideoSettingsDialog* VideoSettingsDialog::currentDlg = nullptr;
|
||||
|
||||
|
||||
VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::VideoSettingsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
oldRenderer = Config::_3DRenderer;
|
||||
oldGLDisplay = Config::ScreenUseGL;
|
||||
oldVSync = Config::ScreenVSync;
|
||||
oldVSyncInterval = Config::ScreenVSyncInterval;
|
||||
oldSoftThreaded = Config::Threaded3D;
|
||||
oldGLScale = Config::GL_ScaleFactor;
|
||||
|
||||
grp3DRenderer = new QButtonGroup(this);
|
||||
grp3DRenderer->addButton(ui->rb3DSoftware, 0);
|
||||
grp3DRenderer->addButton(ui->rb3DOpenGL, 1);
|
||||
connect(grp3DRenderer, SIGNAL(buttonClicked(int)), this, SLOT(onChange3DRenderer(int)));
|
||||
grp3DRenderer->button(Config::_3DRenderer)->setChecked(true);
|
||||
|
||||
ui->cbGLDisplay->setChecked(Config::ScreenUseGL != 0);
|
||||
|
||||
ui->cbVSync->setChecked(Config::ScreenVSync != 0);
|
||||
ui->sbVSyncInterval->setValue(Config::ScreenVSyncInterval);
|
||||
|
||||
ui->cbSoftwareThreaded->setChecked(Config::Threaded3D != 0);
|
||||
|
||||
for (int i = 1; i <= 16; i++)
|
||||
ui->cbxGLResolution->addItem(QString("%1x native (%2x%3)").arg(i).arg(256*i).arg(192*i));
|
||||
ui->cbxGLResolution->setCurrentIndex(Config::GL_ScaleFactor-1);
|
||||
|
||||
if (!Config::ScreenVSync)
|
||||
ui->sbVSyncInterval->setEnabled(false);
|
||||
|
||||
if (Config::_3DRenderer == 0)
|
||||
{
|
||||
ui->cbGLDisplay->setEnabled(true);
|
||||
ui->cbSoftwareThreaded->setEnabled(true);
|
||||
ui->cbxGLResolution->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->cbGLDisplay->setEnabled(false);
|
||||
ui->cbSoftwareThreaded->setEnabled(false);
|
||||
ui->cbxGLResolution->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
VideoSettingsDialog::~VideoSettingsDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void VideoSettingsDialog::on_VideoSettingsDialog_accepted()
|
||||
{
|
||||
Config::Save();
|
||||
|
||||
closeDlg();
|
||||
}
|
||||
|
||||
void VideoSettingsDialog::on_VideoSettingsDialog_rejected()
|
||||
{
|
||||
bool old_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
|
||||
|
||||
Config::_3DRenderer = oldRenderer;
|
||||
Config::ScreenUseGL = oldGLDisplay;
|
||||
Config::ScreenVSync = oldVSync;
|
||||
Config::ScreenVSyncInterval = oldVSyncInterval;
|
||||
Config::Threaded3D = oldSoftThreaded;
|
||||
Config::GL_ScaleFactor = oldGLScale;
|
||||
|
||||
bool new_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
|
||||
emit updateVideoSettings(old_gl != new_gl);
|
||||
|
||||
closeDlg();
|
||||
}
|
||||
|
||||
void VideoSettingsDialog::onChange3DRenderer(int renderer)
|
||||
{
|
||||
bool old_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
|
||||
|
||||
Config::_3DRenderer = renderer;
|
||||
|
||||
if (renderer == 0)
|
||||
{
|
||||
ui->cbGLDisplay->setEnabled(true);
|
||||
ui->cbSoftwareThreaded->setEnabled(true);
|
||||
ui->cbxGLResolution->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->cbGLDisplay->setEnabled(false);
|
||||
ui->cbSoftwareThreaded->setEnabled(false);
|
||||
ui->cbxGLResolution->setEnabled(true);
|
||||
}
|
||||
|
||||
bool new_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
|
||||
emit updateVideoSettings(old_gl != new_gl);
|
||||
}
|
||||
|
||||
void VideoSettingsDialog::on_cbGLDisplay_stateChanged(int state)
|
||||
{
|
||||
bool old_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
|
||||
|
||||
Config::ScreenUseGL = (state != 0);
|
||||
|
||||
bool new_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
|
||||
emit updateVideoSettings(old_gl != new_gl);
|
||||
}
|
||||
|
||||
void VideoSettingsDialog::on_cbVSync_stateChanged(int state)
|
||||
{
|
||||
bool vsync = (state != 0);
|
||||
ui->sbVSyncInterval->setEnabled(vsync);
|
||||
Config::ScreenVSync = vsync;
|
||||
}
|
||||
|
||||
void VideoSettingsDialog::on_sbVSyncInterval_valueChanged(int val)
|
||||
{
|
||||
Config::ScreenVSyncInterval = val;
|
||||
}
|
||||
|
||||
void VideoSettingsDialog::on_cbSoftwareThreaded_stateChanged(int state)
|
||||
{
|
||||
Config::Threaded3D = (state != 0);
|
||||
|
||||
emit updateVideoSettings(false);
|
||||
}
|
||||
|
||||
void VideoSettingsDialog::on_cbxGLResolution_currentIndexChanged(int idx)
|
||||
{
|
||||
// prevent a spurious change
|
||||
if (ui->cbxGLResolution->count() < 16) return;
|
||||
|
||||
Config::GL_ScaleFactor = idx+1;
|
||||
|
||||
emit updateVideoSettings(false);
|
||||
}
|
84
src/frontend/qt_sdl/VideoSettingsDialog.h
Normal file
84
src/frontend/qt_sdl/VideoSettingsDialog.h
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef VIDEOSETTINGSDIALOG_H
|
||||
#define VIDEOSETTINGSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QButtonGroup>
|
||||
|
||||
namespace Ui { class VideoSettingsDialog; }
|
||||
class VideoSettingsDialog;
|
||||
|
||||
class VideoSettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VideoSettingsDialog(QWidget* parent);
|
||||
~VideoSettingsDialog();
|
||||
|
||||
static VideoSettingsDialog* currentDlg;
|
||||
static VideoSettingsDialog* openDlg(QWidget* parent)
|
||||
{
|
||||
if (currentDlg)
|
||||
{
|
||||
currentDlg->activateWindow();
|
||||
return currentDlg;
|
||||
}
|
||||
|
||||
currentDlg = new VideoSettingsDialog(parent);
|
||||
currentDlg->show();
|
||||
return currentDlg;
|
||||
}
|
||||
static void closeDlg()
|
||||
{
|
||||
currentDlg = nullptr;
|
||||
}
|
||||
|
||||
signals:
|
||||
void updateVideoSettings(bool glchange);
|
||||
|
||||
private slots:
|
||||
void on_VideoSettingsDialog_accepted();
|
||||
void on_VideoSettingsDialog_rejected();
|
||||
|
||||
void onChange3DRenderer(int renderer);
|
||||
void on_cbGLDisplay_stateChanged(int state);
|
||||
void on_cbVSync_stateChanged(int state);
|
||||
void on_sbVSyncInterval_valueChanged(int val);
|
||||
|
||||
void on_cbxGLResolution_currentIndexChanged(int idx);
|
||||
|
||||
void on_cbSoftwareThreaded_stateChanged(int state);
|
||||
|
||||
private:
|
||||
Ui::VideoSettingsDialog* ui;
|
||||
|
||||
QButtonGroup* grp3DRenderer;
|
||||
|
||||
int oldRenderer;
|
||||
int oldGLDisplay;
|
||||
int oldVSync;
|
||||
int oldVSyncInterval;
|
||||
int oldSoftThreaded;
|
||||
int oldGLScale;
|
||||
};
|
||||
|
||||
#endif // VIDEOSETTINGSDIALOG_H
|
||||
|
229
src/frontend/qt_sdl/VideoSettingsDialog.ui
Normal file
229
src/frontend/qt_sdl/VideoSettingsDialog.ui
Normal file
@ -0,0 +1,229 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>VideoSettingsDialog</class>
|
||||
<widget class="QDialog" name="VideoSettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>482</width>
|
||||
<height>237</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Video settings - melonDS</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item row="1" column="1">
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>OpenGL renderer</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Internal resolution:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QComboBox" name="cbxGLResolution">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>The resolution at which the 3D graphics will be rendered. Higher resolutions improve graphics quality when the main window is enlarged, but may also cause glitches.</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Software renderer</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="cbSoftwareThreaded">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Run the software renderer on a separate thread. Yields better performance on multi-core CPUs.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use separate thread</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="3">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Display settings</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>The interval at which to synchronize to the monitor's refresh rate. Set to 1 for a 60Hz monitor, 2 for 120Hz, ...</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>VSync interval:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QSpinBox" name="sbVSyncInterval">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>The interval at which to synchronize to the monitor's refresh rate. Set to 1 for a 60Hz monitor, 2 for 120Hz, ...</p></body></html></string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>20</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="cbGLDisplay">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Use OpenGL to draw the DS screens to the main window. May result in better frame pacing. Mandatory when using the OpenGL 3D renderer.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>OpenGL display</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="cbVSync">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>When using OpenGL, synchronize the video output to your monitor's refresh rate.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>VSync</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QRadioButton" name="rb3DOpenGL">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>The OpenGL renderer may be faster than software and supports graphical enhancements, but is more prone to glitches.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>OpenGL</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QRadioButton" name="rb3DSoftware">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>The software renderer is more accurate and less prone to rendering glitches, but requires more CPU power.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Software</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>3D renderer:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>VideoSettingsDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>VideoSettingsDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
140
src/frontend/qt_sdl/WifiSettingsDialog.cpp
Normal file
140
src/frontend/qt_sdl/WifiSettingsDialog.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include "types.h"
|
||||
#include "Platform.h"
|
||||
#include "Config.h"
|
||||
#include "PlatformConfig.h"
|
||||
|
||||
#include "LAN_Socket.h"
|
||||
#include "LAN_PCap.h"
|
||||
#include "Wifi.h"
|
||||
|
||||
#include "WifiSettingsDialog.h"
|
||||
#include "ui_WifiSettingsDialog.h"
|
||||
|
||||
|
||||
#ifdef __WIN32__
|
||||
#define PCAP_NAME "winpcap/npcap"
|
||||
#else
|
||||
#define PCAP_NAME "libpcap"
|
||||
#endif
|
||||
|
||||
|
||||
WifiSettingsDialog* WifiSettingsDialog::currentDlg = nullptr;
|
||||
|
||||
|
||||
WifiSettingsDialog::WifiSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::WifiSettingsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
LAN_Socket::Init();
|
||||
haspcap = LAN_PCap::Init(false);
|
||||
|
||||
ui->cbDirectMode->setText("Direct mode (requires " PCAP_NAME " and ethernet connection)");
|
||||
|
||||
ui->cbBindAnyAddr->setChecked(Config::SocketBindAnyAddr != 0);
|
||||
|
||||
int sel = 0;
|
||||
for (int i = 0; i < LAN_PCap::NumAdapters; i++)
|
||||
{
|
||||
LAN_PCap::AdapterData* adapter = &LAN_PCap::Adapters[i];
|
||||
|
||||
ui->cbxDirectAdapter->addItem(QString(adapter->FriendlyName));
|
||||
|
||||
if (!strncmp(adapter->DeviceName, Config::LANDevice, 128))
|
||||
sel = i;
|
||||
}
|
||||
ui->cbxDirectAdapter->setCurrentIndex(sel);
|
||||
|
||||
ui->cbDirectMode->setChecked(Config::DirectLAN != 0);
|
||||
if (!haspcap) ui->cbDirectMode->setEnabled(false);
|
||||
|
||||
updateAdapterControls();
|
||||
}
|
||||
|
||||
WifiSettingsDialog::~WifiSettingsDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void WifiSettingsDialog::on_WifiSettingsDialog_accepted()
|
||||
{
|
||||
Config::SocketBindAnyAddr = ui->cbBindAnyAddr->isChecked() ? 1:0;
|
||||
Config::DirectLAN = ui->cbDirectMode->isChecked() ? 1:0;
|
||||
|
||||
int sel = ui->cbxDirectAdapter->currentIndex();
|
||||
if (sel < 0 || sel >= LAN_PCap::NumAdapters) sel = 0;
|
||||
if (LAN_PCap::NumAdapters < 1)
|
||||
{
|
||||
Config::LANDevice[0] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(Config::LANDevice, LAN_PCap::Adapters[sel].DeviceName, 127);
|
||||
Config::LANDevice[127] = '\0';
|
||||
}
|
||||
|
||||
Config::Save();
|
||||
|
||||
closeDlg();
|
||||
}
|
||||
|
||||
void WifiSettingsDialog::on_WifiSettingsDialog_rejected()
|
||||
{
|
||||
closeDlg();
|
||||
}
|
||||
|
||||
void WifiSettingsDialog::on_cbDirectMode_stateChanged(int state)
|
||||
{
|
||||
updateAdapterControls();
|
||||
}
|
||||
|
||||
void WifiSettingsDialog::on_cbxDirectAdapter_currentIndexChanged(int sel)
|
||||
{
|
||||
if (!haspcap) return;
|
||||
|
||||
if (sel < 0 || sel >= LAN_PCap::NumAdapters) return;
|
||||
if (LAN_PCap::NumAdapters < 1) return;
|
||||
|
||||
LAN_PCap::AdapterData* adapter = &LAN_PCap::Adapters[sel];
|
||||
char tmp[64];
|
||||
|
||||
sprintf(tmp, "MAC: %02X:%02X:%02X:%02X:%02X:%02X",
|
||||
adapter->MAC[0], adapter->MAC[1], adapter->MAC[2],
|
||||
adapter->MAC[3], adapter->MAC[4], adapter->MAC[5]);
|
||||
ui->lblAdapterMAC->setText(QString(tmp));
|
||||
|
||||
sprintf(tmp, "IP: %d.%d.%d.%d",
|
||||
adapter->IP_v4[0], adapter->IP_v4[1],
|
||||
adapter->IP_v4[2], adapter->IP_v4[3]);
|
||||
ui->lblAdapterIP->setText(QString(tmp));
|
||||
}
|
||||
|
||||
void WifiSettingsDialog::updateAdapterControls()
|
||||
{
|
||||
bool enable = haspcap && ui->cbDirectMode->isChecked();
|
||||
|
||||
ui->cbxDirectAdapter->setEnabled(enable);
|
||||
ui->lblAdapterMAC->setEnabled(enable);
|
||||
ui->lblAdapterIP->setEnabled(enable);
|
||||
}
|
68
src/frontend/qt_sdl/WifiSettingsDialog.h
Normal file
68
src/frontend/qt_sdl/WifiSettingsDialog.h
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef WIFISETTINGSDIALOG_H
|
||||
#define WIFISETTINGSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui { class WifiSettingsDialog; }
|
||||
class WifiSettingsDialog;
|
||||
|
||||
class WifiSettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WifiSettingsDialog(QWidget* parent);
|
||||
~WifiSettingsDialog();
|
||||
|
||||
static WifiSettingsDialog* currentDlg;
|
||||
static WifiSettingsDialog* openDlg(QWidget* parent)
|
||||
{
|
||||
if (currentDlg)
|
||||
{
|
||||
currentDlg->activateWindow();
|
||||
return currentDlg;
|
||||
}
|
||||
|
||||
currentDlg = new WifiSettingsDialog(parent);
|
||||
currentDlg->show();
|
||||
return currentDlg;
|
||||
}
|
||||
static void closeDlg()
|
||||
{
|
||||
currentDlg = nullptr;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void on_WifiSettingsDialog_accepted();
|
||||
void on_WifiSettingsDialog_rejected();
|
||||
|
||||
void on_cbDirectMode_stateChanged(int state);
|
||||
void on_cbxDirectAdapter_currentIndexChanged(int sel);
|
||||
|
||||
private:
|
||||
Ui::WifiSettingsDialog* ui;
|
||||
|
||||
bool haspcap;
|
||||
|
||||
void updateAdapterControls();
|
||||
};
|
||||
|
||||
#endif // WIFISETTINGSDIALOG_H
|
165
src/frontend/qt_sdl/WifiSettingsDialog.ui
Normal file
165
src/frontend/qt_sdl/WifiSettingsDialog.ui
Normal file
@ -0,0 +1,165 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>WifiSettingsDialog</class>
|
||||
<widget class="QDialog" name="WifiSettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>479</width>
|
||||
<height>217</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Wifi settings - melonDS</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Local</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="cbBindAnyAddr">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Enabling this allows (theoretically) playing local multiplayer games over a local network. It may or may not help make for a better connection in general.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Bind socket to any address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Online</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>MAC address:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="cbDirectMode">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Direct mode directly routes network traffic to the host network. It is the most reliable, but requires an ethernet connection.</p><p><br/></p><p>Non-direct mode uses a layer of emulation to get around this, but is more prone to problems.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Direct mode [TEXT PLACEHOLDER]</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cbxDirectAdapter">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>350</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Selects the network adapter through which to route network traffic under direct mode.</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Network adapter:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>IP address:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="lblAdapterMAC">
|
||||
<property name="text">
|
||||
<string>[PLACEHOLDER]</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="lblAdapterIP">
|
||||
<property name="text">
|
||||
<string>[PLACEHOLDER]</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>WifiSettingsDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>WifiSettingsDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
135
src/frontend/qt_sdl/font.h
Normal file
135
src/frontend/qt_sdl/font.h
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef FONT_H
|
||||
#define FONT_H
|
||||
unsigned short font[] = {
|
||||
12, 0, 0, 0,0x0C03, 0x0E07, 0x070E, 0x039C, 0x01F8, 0x00F0, 0x00F0, 0x01F8, 0x039C, 0x070E, 0x0E07, 0x0C03,
|
||||
12, 0, 0, 0,0x01C0, 0x00E0, 0x0060, 0x0860, 0x0C60, 0x0FE0, 0x07F0, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
2, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, 0x0003, 0x0003, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x01EF, 0x01EF, 0x018C, 0x01CE, 0x00E7, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x00CC, 0x00CC, 0x03FF, 0x03FF, 0x00CC, 0x00CC, 0x03FF, 0x03FF, 0x00CC, 0x00CC, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x0018, 0x00FE, 0x00FF, 0x001B, 0x007F, 0x00FE, 0x00D8, 0x00FF, 0x007F, 0x0018, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0306, 0x038F, 0x01CF, 0x00E6, 0x0070, 0x0038, 0x019C, 0x03CE, 0x03C7, 0x0183, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x007C, 0x00FE, 0x00C6, 0x00EE, 0x007C, 0x037E, 0x03E7, 0x01F3, 0x03BF, 0x031E, 0x0000, 0x0000,
|
||||
4, 0, 0, 0,0x000F, 0x000F, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
4, 0, 0, 0,0x000C, 0x000E, 0x0007, 0x0003, 0x0003, 0x0003, 0x0003, 0x0007, 0x000E, 0x000C, 0x0000, 0x0000,
|
||||
4, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x000C, 0x000C, 0x000C, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0030, 0x0333, 0x03B7, 0x01FE, 0x00FC, 0x00FC, 0x01FE, 0x03B7, 0x0333, 0x0030, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0030, 0x0030, 0x0030, 0x0030, 0x03FF, 0x03FF, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000,
|
||||
4, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000F, 0x000F, 0x000C, 0x000E, 0x0007, 0x0003,
|
||||
10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x03FF, 0x03FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
3, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0007, 0x0007, 0x0007, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0300, 0x0380, 0x01C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000,
|
||||
4, 0, 0, 0,0x0006, 0x0007, 0x0007, 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x000F, 0x000F, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C0, 0x00FE, 0x007F, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x007F, 0x00FF, 0x00C0, 0x00C0, 0x007C, 0x00FC, 0x00C0, 0x00C0, 0x00FF, 0x007F, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x00FF, 0x00FE, 0x0060, 0x0060, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x00FF, 0x00FF, 0x0003, 0x0003, 0x007F, 0x00FF, 0x00C0, 0x00C0, 0x00FF, 0x007F, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x007E, 0x007F, 0x0003, 0x0003, 0x007F, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x00FF, 0x00FF, 0x00C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000C, 0x000C, 0x000C, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x00FE, 0x00C0, 0x00C0, 0x00FE, 0x007E, 0x0000, 0x0000,
|
||||
3, 0, 0, 0,0x0000, 0x0000, 0x0007, 0x0007, 0x0000, 0x0000, 0x0000, 0x0007, 0x0007, 0x0000, 0x0000, 0x0000,
|
||||
4, 0, 0, 0,0x0000, 0x0000, 0x000E, 0x000E, 0x0000, 0x0000, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000,
|
||||
6, 0, 0, 0,0x0030, 0x0038, 0x001C, 0x000E, 0x0007, 0x0007, 0x000E, 0x001C, 0x0038, 0x0030, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x007F, 0x007F, 0x0000, 0x0000, 0x007F, 0x007F, 0x0000, 0x0000, 0x0000,
|
||||
6, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x001C, 0x0038, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00F0, 0x0078, 0x0018, 0x0000, 0x0018, 0x0018, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x00FC, 0x01FE, 0x0387, 0x0333, 0x037B, 0x03FB, 0x01F3, 0x0007, 0x03FE, 0x03FC, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x00FE, 0x01FF, 0x0183, 0x0183, 0x0183, 0x01FF, 0x01FF, 0x0183, 0x0183, 0x0183, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x00FE, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x00FF, 0x00FE, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x007F, 0x00FF, 0x01C3, 0x0183, 0x0183, 0x0183, 0x0183, 0x01C3, 0x00FF, 0x007F, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x01FF, 0x01FF, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0003, 0x0003, 0x01FF, 0x01FF, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x01FF, 0x01FF, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x01FE, 0x01FF, 0x0003, 0x0003, 0x01F3, 0x01F3, 0x0183, 0x0183, 0x01FF, 0x00FE, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x0183, 0x0183, 0x0183, 0x0183, 0x01FF, 0x01FF, 0x0183, 0x0183, 0x0183, 0x0183, 0x0000, 0x0000,
|
||||
6, 0, 0, 0,0x003F, 0x003F, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x003F, 0x003F, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x01F0, 0x01F0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x0183, 0x01C3, 0x00E3, 0x0073, 0x003F, 0x003F, 0x0073, 0x00E3, 0x01C3, 0x0183, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x007F, 0x007F, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0303, 0x0387, 0x03CF, 0x03FF, 0x037B, 0x0333, 0x0303, 0x0303, 0x0303, 0x0303, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0303, 0x0307, 0x030F, 0x031F, 0x033B, 0x0373, 0x03E3, 0x03C3, 0x0383, 0x0303, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x01FE, 0x03FF, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x03FF, 0x01FE, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x01FE, 0x03FF, 0x0303, 0x0303, 0x0333, 0x0373, 0x03E3, 0x01C3, 0x03FF, 0x037E, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0073, 0x00E3, 0x01C3, 0x0183, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x01FE, 0x01FF, 0x0003, 0x0003, 0x01FF, 0x03FE, 0x0300, 0x0300, 0x03FE, 0x01FE, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x03FF, 0x03FF, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000,
|
||||
9, 0, 0, 0,0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x01FF, 0x00FE, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0303, 0x0303, 0x0303, 0x0303, 0x0333, 0x037B, 0x03FF, 0x03CF, 0x0387, 0x0303, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0078, 0x00FC, 0x01CE, 0x0387, 0x0303, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x03FF, 0x03FF, 0x01C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x03FF, 0x03FF, 0x0000, 0x0000,
|
||||
4, 0, 0, 0,0x000F, 0x000F, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x000F, 0x000F, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x001C, 0x0038, 0x0070, 0x00E0, 0x01C0, 0x0380, 0x0300, 0x0000, 0x0000,
|
||||
4, 0, 0, 0,0x000F, 0x000F, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000F, 0x000F, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x0018, 0x003C, 0x007E, 0x00E7, 0x00C3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03FF, 0x03FF,
|
||||
4, 0, 0, 0,0x000F, 0x000F, 0x0003, 0x0007, 0x000E, 0x000C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0000, 0x0000, 0x003E, 0x007E, 0x0060, 0x007E, 0x007F, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x007F, 0x003F, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0003, 0x0003, 0x0003, 0x0003, 0x007F, 0x007E, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0060, 0x0060, 0x0060, 0x007E, 0x007F, 0x0063, 0x0063, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0000, 0x0000, 0x003E, 0x007F, 0x0063, 0x007F, 0x003F, 0x0003, 0x003F, 0x003E, 0x0000, 0x0000,
|
||||
6, 0, 0, 0,0x003C, 0x003E, 0x0006, 0x0006, 0x001F, 0x001F, 0x0006, 0x0006, 0x0006, 0x0006, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0063, 0x0063, 0x007F, 0x007E, 0x0060, 0x0060, 0x007E, 0x003E,
|
||||
7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0000, 0x0000,
|
||||
2, 0, 0, 0,0x0003, 0x0003, 0x0000, 0x0000, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0060, 0x0060, 0x0000, 0x0000, 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x0063, 0x007F, 0x003E,
|
||||
8, 0, 0, 0,0x0003, 0x0003, 0x00E3, 0x0073, 0x003B, 0x001F, 0x001F, 0x003B, 0x0073, 0x00E3, 0x0000, 0x0000,
|
||||
4, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x000F, 0x000E, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0000, 0x0000, 0x01FF, 0x03FF, 0x0333, 0x0333, 0x0333, 0x0333, 0x0333, 0x0333, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0000, 0x0000, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0000, 0x0000, 0x003F, 0x007F, 0x0063, 0x0063, 0x007F, 0x003F, 0x0003, 0x0003, 0x0003, 0x0003,
|
||||
7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0063, 0x0063, 0x007F, 0x007E, 0x0060, 0x0060, 0x0060, 0x0060,
|
||||
7, 0, 0, 0,0x0000, 0x0000, 0x003B, 0x007F, 0x0067, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0003, 0x007F, 0x00FE, 0x00C0, 0x00FE, 0x007E, 0x0000, 0x0000,
|
||||
6, 0, 0, 0,0x0006, 0x0006, 0x003F, 0x003F, 0x0006, 0x0006, 0x0006, 0x0006, 0x003E, 0x003C, 0x0000, 0x0000,
|
||||
7, 0, 0, 0,0x0000, 0x0000, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0303, 0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0303, 0x0333, 0x037B, 0x03FF, 0x03CF, 0x0387, 0x0303, 0x0000, 0x0000,
|
||||
8, 0, 0, 0,0x0000, 0x0000, 0x00C3, 0x00E7, 0x007E, 0x003C, 0x003C, 0x007E, 0x00E7, 0x00C3, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0307, 0x038E, 0x01DC, 0x00F8, 0x0070, 0x0038, 0x001C, 0x000E, 0x0006,
|
||||
8, 0, 0, 0,0x0000, 0x0000, 0x00FF, 0x00FF, 0x0070, 0x0038, 0x001C, 0x000E, 0x00FF, 0x00FF, 0x0000, 0x0000,
|
||||
6, 0, 0, 0,0x0038, 0x003C, 0x000C, 0x000C, 0x000F, 0x000F, 0x000C, 0x000C, 0x003C, 0x0038, 0x0000, 0x0000,
|
||||
2, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000,
|
||||
6, 0, 0, 0,0x0007, 0x000F, 0x000C, 0x000C, 0x003C, 0x003C, 0x000C, 0x000C, 0x000F, 0x0007, 0x0000, 0x0000,
|
||||
10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x031C, 0x03BE, 0x01F7, 0x00E3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
11, 0, 0, 0,0x0555, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0555, 0x0000,
|
||||
};
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -21,8 +21,17 @@
|
||||
|
||||
#include <QThread>
|
||||
#include <QWidget>
|
||||
#include <QWindow>
|
||||
#include <QMainWindow>
|
||||
#include <QImage>
|
||||
#include <QActionGroup>
|
||||
|
||||
#include <QOffscreenSurface>
|
||||
#include <QOpenGLWidget>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QOpenGLFunctions_3_2_Core>
|
||||
#include <QOpenGLShaderProgram>
|
||||
|
||||
|
||||
class EmuThread : public QThread
|
||||
@ -33,43 +42,124 @@ class EmuThread : public QThread
|
||||
public:
|
||||
explicit EmuThread(QObject* parent = nullptr);
|
||||
|
||||
void initOpenGL();
|
||||
void deinitOpenGL();
|
||||
|
||||
void* oglGetProcAddress(const char* proc);
|
||||
|
||||
void changeWindowTitle(char* title);
|
||||
|
||||
// to be called from the UI thread
|
||||
void emuRun();
|
||||
void emuPause(bool refresh);
|
||||
void emuPause();
|
||||
void emuUnpause();
|
||||
void emuStop();
|
||||
|
||||
bool emuIsRunning();
|
||||
|
||||
signals:
|
||||
void windowUpdate();
|
||||
void windowTitleChange(QString title);
|
||||
|
||||
void windowEmuStart();
|
||||
void windowEmuStop();
|
||||
void windowPauseToggle();
|
||||
void windowEmuPause();
|
||||
void windowEmuReset();
|
||||
|
||||
void windowLimitFPSChange();
|
||||
|
||||
void screenLayoutChange();
|
||||
|
||||
private:
|
||||
volatile int EmuStatus;
|
||||
int PrevEmuStatus;
|
||||
int EmuRunning;
|
||||
|
||||
QOffscreenSurface* oglSurface;
|
||||
QOpenGLContext* oglContext;
|
||||
};
|
||||
|
||||
|
||||
class MainWindowPanel : public QWidget
|
||||
class ScreenHandler
|
||||
{
|
||||
Q_GADGET
|
||||
|
||||
public:
|
||||
virtual ~ScreenHandler() {}
|
||||
|
||||
protected:
|
||||
void screenSetupLayout(int w, int h);
|
||||
|
||||
QSize screenGetMinSize();
|
||||
|
||||
void screenOnMousePress(QMouseEvent* event);
|
||||
void screenOnMouseRelease(QMouseEvent* event);
|
||||
void screenOnMouseMove(QMouseEvent* event);
|
||||
|
||||
float screenMatrix[2][6];
|
||||
|
||||
bool touching;
|
||||
};
|
||||
|
||||
|
||||
class ScreenPanelNative : public QWidget, public ScreenHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindowPanel(QWidget* parent);
|
||||
~MainWindowPanel();
|
||||
explicit ScreenPanelNative(QWidget* parent);
|
||||
~ScreenPanelNative();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void onScreenLayoutChanged();
|
||||
|
||||
private:
|
||||
QImage* screen[2];
|
||||
void setupScreenLayout();
|
||||
|
||||
QImage screen[2];
|
||||
QTransform screenTrans[2];
|
||||
};
|
||||
|
||||
|
||||
class ScreenPanelGL : public QOpenGLWidget, public ScreenHandler, protected QOpenGLFunctions_3_2_Core
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ScreenPanelGL(QWidget* parent);
|
||||
~ScreenPanelGL();
|
||||
|
||||
protected:
|
||||
void initializeGL() override;
|
||||
|
||||
void paintGL() override;
|
||||
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
void resizeGL(int w, int h) override;
|
||||
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void onScreenLayoutChanged();
|
||||
|
||||
private:
|
||||
void setupScreenLayout();
|
||||
|
||||
QOpenGLShaderProgram* screenShader;
|
||||
GLuint screenVertexBuffer;
|
||||
GLuint screenVertexArray;
|
||||
GLuint screenTexture;
|
||||
};
|
||||
|
||||
|
||||
@ -81,8 +171,20 @@ public:
|
||||
explicit MainWindow(QWidget* parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
bool hasOGL;
|
||||
QOpenGLContext* getOGLContext();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void keyReleaseEvent(QKeyEvent* event) override;
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
signals:
|
||||
void screenLayoutChange();
|
||||
|
||||
private slots:
|
||||
void onOpenFile();
|
||||
@ -96,15 +198,40 @@ private slots:
|
||||
void onReset();
|
||||
void onStop();
|
||||
|
||||
void onOpenEmuSettings();
|
||||
void onOpenInputConfig();
|
||||
void onInputConfigFinished(int res);
|
||||
void onOpenVideoSettings();
|
||||
void onOpenAudioSettings();
|
||||
void onAudioSettingsFinished(int res);
|
||||
void onOpenWifiSettings();
|
||||
void onWifiSettingsFinished(int res);
|
||||
void onChangeSavestateSRAMReloc(bool checked);
|
||||
void onChangeScreenSize();
|
||||
void onChangeScreenRotation(QAction* act);
|
||||
void onChangeScreenGap(QAction* act);
|
||||
void onChangeScreenLayout(QAction* act);
|
||||
void onChangeScreenSizing(QAction* act);
|
||||
void onChangeIntegerScaling(bool checked);
|
||||
void onChangeScreenFiltering(bool checked);
|
||||
void onChangeShowOSD(bool checked);
|
||||
void onChangeLimitFramerate(bool checked);
|
||||
void onChangeAudioSync(bool checked);
|
||||
|
||||
void onTitleUpdate(QString title);
|
||||
|
||||
void onEmuStart();
|
||||
void onEmuStop();
|
||||
void onEmuPause();
|
||||
void onEmuUnpause();
|
||||
|
||||
void onUpdateVideoSettings(bool glchange);
|
||||
|
||||
private:
|
||||
MainWindowPanel* panel;
|
||||
void createScreenPanel();
|
||||
|
||||
QString loadErrorStr(int error);
|
||||
|
||||
public:
|
||||
QWidget* panel;
|
||||
|
||||
QAction* actOpenROM;
|
||||
QAction* actBootFirmware;
|
||||
@ -116,6 +243,27 @@ private:
|
||||
QAction* actPause;
|
||||
QAction* actReset;
|
||||
QAction* actStop;
|
||||
|
||||
QAction* actEmuSettings;
|
||||
QAction* actInputConfig;
|
||||
QAction* actVideoSettings;
|
||||
QAction* actAudioSettings;
|
||||
QAction* actWifiSettings;
|
||||
QAction* actSavestateSRAMReloc;
|
||||
QAction* actScreenSize[4];
|
||||
QActionGroup* grpScreenRotation;
|
||||
QAction* actScreenRotation[4];
|
||||
QActionGroup* grpScreenGap;
|
||||
QAction* actScreenGap[6];
|
||||
QActionGroup* grpScreenLayout;
|
||||
QAction* actScreenLayout[3];
|
||||
QActionGroup* grpScreenSizing;
|
||||
QAction* actScreenSizing[4];
|
||||
QAction* actIntegerScaling;
|
||||
QAction* actScreenFiltering;
|
||||
QAction* actShowOSD;
|
||||
QAction* actLimitFramerate;
|
||||
QAction* actAudioSync;
|
||||
};
|
||||
|
||||
#endif // MAIN_H
|
||||
|
64
src/frontend/qt_sdl/main_shaders.h
Normal file
64
src/frontend/qt_sdl/main_shaders.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef MAIN_SHADERS_H
|
||||
#define MAIN_SHADERS_H
|
||||
|
||||
const char* kScreenVS = R"(#version 140
|
||||
|
||||
uniform vec2 uScreenSize;
|
||||
uniform mat2x3 uTransform;
|
||||
|
||||
in vec2 vPosition;
|
||||
in vec2 vTexcoord;
|
||||
|
||||
smooth out vec2 fTexcoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 fpos;
|
||||
|
||||
fpos.xy = vec3(vPosition, 1.0) * uTransform;
|
||||
|
||||
fpos.xy = ((fpos.xy * 2.0) / uScreenSize) - 1.0;
|
||||
fpos.y *= -1;
|
||||
fpos.z = 0.0;
|
||||
fpos.w = 1.0;
|
||||
|
||||
gl_Position = fpos;
|
||||
fTexcoord = vTexcoord;
|
||||
}
|
||||
)";
|
||||
|
||||
const char* kScreenFS = R"(#version 140
|
||||
|
||||
uniform sampler2D ScreenTex;
|
||||
|
||||
smooth in vec2 fTexcoord;
|
||||
|
||||
out vec4 oColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 pixel = texture(ScreenTex, fTexcoord);
|
||||
|
||||
oColor = vec4(pixel.bgr, 1.0);
|
||||
}
|
||||
)";
|
||||
|
||||
#endif // MAIN_SHADERS_H
|
56
src/frontend/qt_sdl/pcap/bluetooth.h
Normal file
56
src/frontend/qt_sdl/pcap/bluetooth.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Paolo Abeni (Italy)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* bluetooth data struct
|
||||
* By Paolo Abeni <paolo.abeni@email.it>
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_bluetooth_h
|
||||
#define lib_pcap_bluetooth_h
|
||||
|
||||
#include <pcap/pcap-inttypes.h>
|
||||
|
||||
/*
|
||||
* Header prepended libpcap to each bluetooth h4 frame,
|
||||
* fields are in network byte order
|
||||
*/
|
||||
typedef struct _pcap_bluetooth_h4_header {
|
||||
uint32_t direction; /* if first bit is set direction is incoming */
|
||||
} pcap_bluetooth_h4_header;
|
||||
|
||||
/*
|
||||
* Header prepended libpcap to each bluetooth linux monitor frame,
|
||||
* fields are in network byte order
|
||||
*/
|
||||
typedef struct _pcap_bluetooth_linux_monitor_header {
|
||||
uint16_t adapter_id;
|
||||
uint16_t opcode;
|
||||
} pcap_bluetooth_linux_monitor_header;
|
||||
|
||||
#endif
|
270
src/frontend/qt_sdl/pcap/bpf.h
Normal file
270
src/frontend/qt_sdl/pcap/bpf.h
Normal file
@ -0,0 +1,270 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from the Stanford/CMU enet packet filter,
|
||||
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
|
||||
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
|
||||
* Berkeley Laboratory.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is libpcap's cut-down version of bpf.h; it includes only
|
||||
* the stuff needed for the code generator and the userland BPF
|
||||
* interpreter, and the libpcap APIs for setting filters, etc..
|
||||
*
|
||||
* "pcap-bpf.c" will include the native OS version, as it deals with
|
||||
* the OS's BPF implementation.
|
||||
*
|
||||
* At least two programs found by Google Code Search explicitly includes
|
||||
* <pcap/bpf.h> (even though <pcap.h>/<pcap/pcap.h> includes it for you),
|
||||
* so moving that stuff to <pcap/pcap.h> would break the build for some
|
||||
* programs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If we've already included <net/bpf.h>, don't re-define this stuff.
|
||||
* We assume BSD-style multiple-include protection in <net/bpf.h>,
|
||||
* which is true of all but the oldest versions of FreeBSD and NetBSD,
|
||||
* or Tru64 UNIX-style multiple-include protection (or, at least,
|
||||
* Tru64 UNIX 5.x-style; I don't have earlier versions available to check),
|
||||
* or AIX-style multiple-include protection (or, at least, AIX 5.x-style;
|
||||
* I don't have earlier versions available to check), or QNX-style
|
||||
* multiple-include protection (as per GitHub pull request #394).
|
||||
*
|
||||
* We do not check for BPF_MAJOR_VERSION, as that's defined by
|
||||
* <linux/filter.h>, which is directly or indirectly included in some
|
||||
* programs that also include pcap.h, and <linux/filter.h> doesn't
|
||||
* define stuff we need.
|
||||
*
|
||||
* This also provides our own multiple-include protection.
|
||||
*/
|
||||
#if !defined(_NET_BPF_H_) && !defined(_NET_BPF_H_INCLUDED) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h)
|
||||
#define lib_pcap_bpf_h
|
||||
|
||||
#include <pcap/funcattrs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* BSD style release date */
|
||||
#define BPF_RELEASE 199606
|
||||
|
||||
#ifdef MSDOS /* must be 32-bit */
|
||||
typedef long bpf_int32;
|
||||
typedef unsigned long bpf_u_int32;
|
||||
#else
|
||||
typedef int bpf_int32;
|
||||
typedef u_int bpf_u_int32;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Alignment macros. BPF_WORDALIGN rounds up to the next
|
||||
* even multiple of BPF_ALIGNMENT.
|
||||
*
|
||||
* Tcpdump's print-pflog.c uses this, so we define it here.
|
||||
*/
|
||||
#ifndef __NetBSD__
|
||||
#define BPF_ALIGNMENT sizeof(bpf_int32)
|
||||
#else
|
||||
#define BPF_ALIGNMENT sizeof(long)
|
||||
#endif
|
||||
#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
|
||||
|
||||
/*
|
||||
* Structure for "pcap_compile()", "pcap_setfilter()", etc..
|
||||
*/
|
||||
struct bpf_program {
|
||||
u_int bf_len;
|
||||
struct bpf_insn *bf_insns;
|
||||
};
|
||||
|
||||
#include <pcap/dlt.h>
|
||||
|
||||
/*
|
||||
* The instruction encodings.
|
||||
*
|
||||
* Please inform tcpdump-workers@lists.tcpdump.org if you use any
|
||||
* of the reserved values, so that we can note that they're used
|
||||
* (and perhaps implement it in the reference BPF implementation
|
||||
* and encourage its implementation elsewhere).
|
||||
*/
|
||||
|
||||
/*
|
||||
* The upper 8 bits of the opcode aren't used. BSD/OS used 0x8000.
|
||||
*/
|
||||
|
||||
/* instruction classes */
|
||||
#define BPF_CLASS(code) ((code) & 0x07)
|
||||
#define BPF_LD 0x00
|
||||
#define BPF_LDX 0x01
|
||||
#define BPF_ST 0x02
|
||||
#define BPF_STX 0x03
|
||||
#define BPF_ALU 0x04
|
||||
#define BPF_JMP 0x05
|
||||
#define BPF_RET 0x06
|
||||
#define BPF_MISC 0x07
|
||||
|
||||
/* ld/ldx fields */
|
||||
#define BPF_SIZE(code) ((code) & 0x18)
|
||||
#define BPF_W 0x00
|
||||
#define BPF_H 0x08
|
||||
#define BPF_B 0x10
|
||||
/* 0x18 reserved; used by BSD/OS */
|
||||
#define BPF_MODE(code) ((code) & 0xe0)
|
||||
#define BPF_IMM 0x00
|
||||
#define BPF_ABS 0x20
|
||||
#define BPF_IND 0x40
|
||||
#define BPF_MEM 0x60
|
||||
#define BPF_LEN 0x80
|
||||
#define BPF_MSH 0xa0
|
||||
/* 0xc0 reserved; used by BSD/OS */
|
||||
/* 0xe0 reserved; used by BSD/OS */
|
||||
|
||||
/* alu/jmp fields */
|
||||
#define BPF_OP(code) ((code) & 0xf0)
|
||||
#define BPF_ADD 0x00
|
||||
#define BPF_SUB 0x10
|
||||
#define BPF_MUL 0x20
|
||||
#define BPF_DIV 0x30
|
||||
#define BPF_OR 0x40
|
||||
#define BPF_AND 0x50
|
||||
#define BPF_LSH 0x60
|
||||
#define BPF_RSH 0x70
|
||||
#define BPF_NEG 0x80
|
||||
#define BPF_MOD 0x90
|
||||
#define BPF_XOR 0xa0
|
||||
/* 0xb0 reserved */
|
||||
/* 0xc0 reserved */
|
||||
/* 0xd0 reserved */
|
||||
/* 0xe0 reserved */
|
||||
/* 0xf0 reserved */
|
||||
|
||||
#define BPF_JA 0x00
|
||||
#define BPF_JEQ 0x10
|
||||
#define BPF_JGT 0x20
|
||||
#define BPF_JGE 0x30
|
||||
#define BPF_JSET 0x40
|
||||
/* 0x50 reserved; used on BSD/OS */
|
||||
/* 0x60 reserved */
|
||||
/* 0x70 reserved */
|
||||
/* 0x80 reserved */
|
||||
/* 0x90 reserved */
|
||||
/* 0xa0 reserved */
|
||||
/* 0xb0 reserved */
|
||||
/* 0xc0 reserved */
|
||||
/* 0xd0 reserved */
|
||||
/* 0xe0 reserved */
|
||||
/* 0xf0 reserved */
|
||||
#define BPF_SRC(code) ((code) & 0x08)
|
||||
#define BPF_K 0x00
|
||||
#define BPF_X 0x08
|
||||
|
||||
/* ret - BPF_K and BPF_X also apply */
|
||||
#define BPF_RVAL(code) ((code) & 0x18)
|
||||
#define BPF_A 0x10
|
||||
/* 0x18 reserved */
|
||||
|
||||
/* misc */
|
||||
#define BPF_MISCOP(code) ((code) & 0xf8)
|
||||
#define BPF_TAX 0x00
|
||||
/* 0x08 reserved */
|
||||
/* 0x10 reserved */
|
||||
/* 0x18 reserved */
|
||||
/* #define BPF_COP 0x20 NetBSD "coprocessor" extensions */
|
||||
/* 0x28 reserved */
|
||||
/* 0x30 reserved */
|
||||
/* 0x38 reserved */
|
||||
/* #define BPF_COPX 0x40 NetBSD "coprocessor" extensions */
|
||||
/* also used on BSD/OS */
|
||||
/* 0x48 reserved */
|
||||
/* 0x50 reserved */
|
||||
/* 0x58 reserved */
|
||||
/* 0x60 reserved */
|
||||
/* 0x68 reserved */
|
||||
/* 0x70 reserved */
|
||||
/* 0x78 reserved */
|
||||
#define BPF_TXA 0x80
|
||||
/* 0x88 reserved */
|
||||
/* 0x90 reserved */
|
||||
/* 0x98 reserved */
|
||||
/* 0xa0 reserved */
|
||||
/* 0xa8 reserved */
|
||||
/* 0xb0 reserved */
|
||||
/* 0xb8 reserved */
|
||||
/* 0xc0 reserved; used on BSD/OS */
|
||||
/* 0xc8 reserved */
|
||||
/* 0xd0 reserved */
|
||||
/* 0xd8 reserved */
|
||||
/* 0xe0 reserved */
|
||||
/* 0xe8 reserved */
|
||||
/* 0xf0 reserved */
|
||||
/* 0xf8 reserved */
|
||||
|
||||
/*
|
||||
* The instruction data structure.
|
||||
*/
|
||||
struct bpf_insn {
|
||||
u_short code;
|
||||
u_char jt;
|
||||
u_char jf;
|
||||
bpf_u_int32 k;
|
||||
};
|
||||
|
||||
/*
|
||||
* Auxiliary data, for use when interpreting a filter intended for the
|
||||
* Linux kernel when the kernel rejects the filter (requiring us to
|
||||
* run it in userland). It contains VLAN tag information.
|
||||
*/
|
||||
struct bpf_aux_data {
|
||||
u_short vlan_tag_present;
|
||||
u_short vlan_tag;
|
||||
};
|
||||
|
||||
/*
|
||||
* Macros for insn array initializers.
|
||||
*/
|
||||
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
|
||||
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
|
||||
|
||||
PCAP_API int bpf_validate(const struct bpf_insn *, int);
|
||||
PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
|
||||
extern u_int bpf_filter_with_aux_data(const struct bpf_insn *, const u_char *, u_int, u_int, const struct bpf_aux_data *);
|
||||
|
||||
/*
|
||||
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
|
||||
*/
|
||||
#define BPF_MEMWORDS 16
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !defined(_NET_BPF_H_) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h) */
|
56
src/frontend/qt_sdl/pcap/can_socketcan.h
Normal file
56
src/frontend/qt_sdl/pcap/can_socketcan.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from the Stanford/CMU enet packet filter,
|
||||
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
|
||||
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
|
||||
* Berkeley Laboratory.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_can_socketcan_h
|
||||
#define lib_pcap_can_socketcan_h
|
||||
|
||||
#include <pcap/pcap-inttypes.h>
|
||||
|
||||
/*
|
||||
* SocketCAN header, as per Documentation/networking/can.txt in the
|
||||
* Linux source.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t can_id;
|
||||
uint8_t payload_length;
|
||||
uint8_t pad;
|
||||
uint8_t reserved1;
|
||||
uint8_t reserved2;
|
||||
} pcap_can_socketcan_hdr;
|
||||
|
||||
#endif
|
152
src/frontend/qt_sdl/pcap/compiler-tests.h
Normal file
152
src/frontend/qt_sdl/pcap/compiler-tests.h
Normal file
@ -0,0 +1,152 @@
|
||||
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
|
||||
/*
|
||||
* Copyright (c) 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the Computer Systems
|
||||
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_compiler_tests_h
|
||||
#define lib_pcap_compiler_tests_h
|
||||
|
||||
|
||||
/*
|
||||
* This was introduced by Clang:
|
||||
*
|
||||
* http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
|
||||
*
|
||||
* in some version (which version?); it has been picked up by GCC 5.0.
|
||||
*/
|
||||
#ifndef __has_attribute
|
||||
/*
|
||||
* It's a macro, so you can check whether it's defined to check
|
||||
* whether it's supported.
|
||||
*
|
||||
* If it's not, define it to always return 0, so that we move on to
|
||||
* the fallback checks.
|
||||
*/
|
||||
#define __has_attribute(x) 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Note that the C90 spec's "6.8.1 Conditional inclusion" and the
|
||||
* C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say:
|
||||
*
|
||||
* Prior to evaluation, macro invocations in the list of preprocessing
|
||||
* tokens that will become the controlling constant expression are
|
||||
* replaced (except for those macro names modified by the defined unary
|
||||
* operator), just as in normal text. If the token "defined" is
|
||||
* generated as a result of this replacement process or use of the
|
||||
* "defined" unary operator does not match one of the two specified
|
||||
* forms prior to macro replacement, the behavior is undefined.
|
||||
*
|
||||
* so you shouldn't use defined() in a #define that's used in #if or
|
||||
* #elif. Some versions of Clang, for example, will warn about this.
|
||||
*
|
||||
* Instead, we check whether the pre-defined macros for particular
|
||||
* compilers are defined and, if not, define the "is this version XXX
|
||||
* or a later version of this compiler" macros as 0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Check whether this is GCC major.minor or a later release, or some
|
||||
* compiler that claims to be "just like GCC" of that version or a
|
||||
* later release.
|
||||
*/
|
||||
|
||||
#if ! defined(__GNUC__)
|
||||
#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) 0
|
||||
#else
|
||||
#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \
|
||||
(__GNUC__ > (major) || \
|
||||
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check whether this is Sun C/SunPro C/Oracle Studio major.minor
|
||||
* or a later release.
|
||||
*
|
||||
* The version number in __SUNPRO_C is encoded in hex BCD, with the
|
||||
* uppermost hex digit being the major version number, the next
|
||||
* one or two hex digits being the minor version number, and
|
||||
* the last digit being the patch version.
|
||||
*
|
||||
* It represents the *compiler* version, not the product version;
|
||||
* see
|
||||
*
|
||||
* https://sourceforge.net/p/predef/wiki/Compilers/
|
||||
*
|
||||
* for a partial mapping, which we assume continues for later
|
||||
* 12.x product releases.
|
||||
*/
|
||||
|
||||
#if ! defined(__SUNPRO_C)
|
||||
#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) 0
|
||||
#else
|
||||
#define PCAP_SUNPRO_VERSION_TO_BCD(major, minor) \
|
||||
(((minor) >= 10) ? \
|
||||
(((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \
|
||||
(((major) << 8) | ((minor) << 4)))
|
||||
#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) \
|
||||
(__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor)))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check whether this is IBM XL C major.minor or a later release.
|
||||
*
|
||||
* The version number in __xlC__ has the major version in the
|
||||
* upper 8 bits and the minor version in the lower 8 bits.
|
||||
*/
|
||||
|
||||
#if ! defined(__xlC__)
|
||||
#define PCAP_IS_AT_LEAST_XL_C_VERSION(major,minor) 0
|
||||
#else
|
||||
#define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \
|
||||
(__xlC__ >= (((major) << 8) | (minor)))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check whether this is HP aC++/HP C major.minor or a later release.
|
||||
*
|
||||
* The version number in __HP_aCC is encoded in zero-padded decimal BCD,
|
||||
* with the "A." stripped off, the uppermost two decimal digits being
|
||||
* the major version number, the next two decimal digits being the minor
|
||||
* version number, and the last two decimal digits being the patch version.
|
||||
* (Strip off the A., remove the . between the major and minor version
|
||||
* number, and add two digits of patch.)
|
||||
*/
|
||||
|
||||
#if ! defined(__HP_aCC)
|
||||
#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) 0
|
||||
#else
|
||||
#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) \
|
||||
(__HP_aCC >= ((major)*10000 + (minor)*100))
|
||||
#endif
|
||||
|
||||
#endif /* lib_pcap_funcattrs_h */
|
1389
src/frontend/qt_sdl/pcap/dlt.h
Normal file
1389
src/frontend/qt_sdl/pcap/dlt.h
Normal file
File diff suppressed because it is too large
Load Diff
242
src/frontend/qt_sdl/pcap/funcattrs.h
Normal file
242
src/frontend/qt_sdl/pcap/funcattrs.h
Normal file
@ -0,0 +1,242 @@
|
||||
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
|
||||
/*
|
||||
* Copyright (c) 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the Computer Systems
|
||||
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_funcattrs_h
|
||||
#define lib_pcap_funcattrs_h
|
||||
|
||||
#include <pcap/compiler-tests.h>
|
||||
|
||||
/*
|
||||
* Attributes to apply to functions and their arguments, using various
|
||||
* compiler-specific extensions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PCAP_API_DEF must be used when defining *data* exported from
|
||||
* libpcap. It can be used when defining *functions* exported
|
||||
* from libpcap, but it doesn't have to be used there. It
|
||||
* should not be used in declarations in headers.
|
||||
*
|
||||
* PCAP_API must be used when *declaring* data or functions
|
||||
* exported from libpcap; PCAP_API_DEF won't work on all platforms.
|
||||
*/
|
||||
|
||||
#if defined(_WIN32)
|
||||
/*
|
||||
* For Windows:
|
||||
*
|
||||
* when building libpcap:
|
||||
*
|
||||
* if we're building it as a DLL, we have to declare API
|
||||
* functions with __declspec(dllexport);
|
||||
*
|
||||
* if we're building it as a static library, we don't want
|
||||
* to do so.
|
||||
*
|
||||
* when using libpcap:
|
||||
*
|
||||
* if we're using the DLL, calls to its functions are a
|
||||
* little more efficient if they're declared with
|
||||
* __declspec(dllimport);
|
||||
*
|
||||
* if we're not using the dll, we don't want to declare
|
||||
* them that way.
|
||||
*
|
||||
* So:
|
||||
*
|
||||
* if pcap_EXPORTS is defined, we define PCAP_API_DEF as
|
||||
* __declspec(dllexport);
|
||||
*
|
||||
* if PCAP_DLL is defined, we define PCAP_API_DEF as
|
||||
* __declspec(dllimport);
|
||||
*
|
||||
* otherwise, we define PCAP_API_DEF as nothing.
|
||||
*/
|
||||
#if defined(pcap_EXPORTS)
|
||||
/*
|
||||
* We're compiling libpcap, so we should export functions in our
|
||||
* API.
|
||||
*/
|
||||
#define PCAP_API_DEF __declspec(dllexport)
|
||||
#elif defined(PCAP_DLL)
|
||||
#define PCAP_API_DEF __declspec(dllimport)
|
||||
#else
|
||||
#define PCAP_API_DEF
|
||||
#endif
|
||||
#elif defined(MSDOS)
|
||||
/* XXX - does this need special treatment? */
|
||||
#define PCAP_API_DEF
|
||||
#else /* UN*X */
|
||||
#ifdef pcap_EXPORTS
|
||||
/*
|
||||
* We're compiling libpcap, so we should export functions in our API.
|
||||
* The compiler might be configured not to export functions from a
|
||||
* shared library by default, so we might have to explicitly mark
|
||||
* functions as exported.
|
||||
*/
|
||||
#if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) \
|
||||
|| PCAP_IS_AT_LEAST_XL_C_VERSION(12,0)
|
||||
/*
|
||||
* GCC 3.4 or later, or some compiler asserting compatibility with
|
||||
* GCC 3.4 or later, or XL C 13.0 or later, so we have
|
||||
* __attribute__((visibility()).
|
||||
*/
|
||||
#define PCAP_API_DEF __attribute__((visibility("default")))
|
||||
#elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
|
||||
/*
|
||||
* Sun C 5.5 or later, so we have __global.
|
||||
* (Sun C 5.9 and later also have __attribute__((visibility()),
|
||||
* but there's no reason to prefer it with Sun C.)
|
||||
*/
|
||||
#define PCAP_API_DEF __global
|
||||
#else
|
||||
/*
|
||||
* We don't have anything to say.
|
||||
*/
|
||||
#define PCAP_API_DEF
|
||||
#endif
|
||||
#else
|
||||
/*
|
||||
* We're not building libpcap.
|
||||
*/
|
||||
#define PCAP_API_DEF
|
||||
#endif
|
||||
#endif /* _WIN32/MSDOS/UN*X */
|
||||
|
||||
#define PCAP_API PCAP_API_DEF extern
|
||||
|
||||
/*
|
||||
* PCAP_NORETURN, before a function declaration, means "this function
|
||||
* never returns". (It must go before the function declaration, e.g.
|
||||
* "extern PCAP_NORETURN func(...)" rather than after the function
|
||||
* declaration, as the MSVC version has to go before the declaration.)
|
||||
*/
|
||||
#if __has_attribute(noreturn) \
|
||||
|| PCAP_IS_AT_LEAST_GNUC_VERSION(2,5) \
|
||||
|| PCAP_IS_AT_LEAST_SUNC_VERSION(5,9) \
|
||||
|| PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \
|
||||
|| PCAP_IS_AT_LEAST_HP_C_VERSION(6,10)
|
||||
/*
|
||||
* Compiler with support for __attribute((noreturn)), or GCC 2.5 and
|
||||
* later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1
|
||||
* and later (do any earlier versions of XL C support this?), or
|
||||
* HP aCC A.06.10 and later.
|
||||
*/
|
||||
#define PCAP_NORETURN __attribute((noreturn))
|
||||
#elif defined(_MSC_VER)
|
||||
/*
|
||||
* MSVC.
|
||||
*/
|
||||
#define PCAP_NORETURN __declspec(noreturn)
|
||||
#else
|
||||
#define PCAP_NORETURN
|
||||
#endif
|
||||
|
||||
/*
|
||||
* PCAP_PRINTFLIKE(x,y), after a function declaration, means "this function
|
||||
* does printf-style formatting, with the xth argument being the format
|
||||
* string and the yth argument being the first argument for the format
|
||||
* string".
|
||||
*/
|
||||
#if __has_attribute(__format__) \
|
||||
|| PCAP_IS_AT_LEAST_GNUC_VERSION(2,3) \
|
||||
|| PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \
|
||||
|| PCAP_IS_AT_LEAST_HP_C_VERSION(6,10)
|
||||
/*
|
||||
* Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1
|
||||
* and later (do any earlier versions of XL C support this?),
|
||||
* or HP aCC A.06.10 and later.
|
||||
*/
|
||||
#define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
|
||||
#else
|
||||
#define PCAP_PRINTFLIKE(x,y)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* PCAP_DEPRECATED(func, msg), after a function declaration, marks the
|
||||
* function as deprecated.
|
||||
*
|
||||
* The first argument is the name of the function; the second argument is
|
||||
* a string giving the warning message to use if the compiler supports that.
|
||||
*
|
||||
* (Thank you, Microsoft, for requiring the function name.)
|
||||
*/
|
||||
#if __has_attribute(deprecated) \
|
||||
|| PCAP_IS_AT_LEAST_GNUC_VERSION(4,5) \
|
||||
|| PCAP_IS_AT_LEAST_SUNC_VERSION(5,13)
|
||||
/*
|
||||
* Compiler that supports __has_attribute and __attribute__((deprecated)),
|
||||
* or GCC 4.5 and later, or Sun/Oracle C 12.4 (Sun C 5.13) or later.
|
||||
*
|
||||
* Those support __attribute__((deprecated(msg))) (we assume, perhaps
|
||||
* incorrectly, that anything that supports __has_attribute() is
|
||||
* recent enough to support __attribute__((deprecated(msg)))).
|
||||
*/
|
||||
#define PCAP_DEPRECATED(func, msg) __attribute__((deprecated(msg)))
|
||||
#elif PCAP_IS_AT_LEAST_GNUC_VERSION(3,1)
|
||||
/*
|
||||
* GCC 3.1 through 4.4.
|
||||
*
|
||||
* Those support __attribute__((deprecated)) but not
|
||||
* __attribute__((deprecated(msg))).
|
||||
*/
|
||||
#define PCAP_DEPRECATED(func, msg) __attribute__((deprecated))
|
||||
#elif (defined(_MSC_VER) && (_MSC_VER >= 1500)) && !defined(pcap_EXPORTS)
|
||||
/*
|
||||
* MSVC from Visual Studio 2008 or later, and we're not building
|
||||
* libpcap itself.
|
||||
*
|
||||
* If we *are* building libpcap, we don't want this, as it'll warn
|
||||
* us even if we *define* the function.
|
||||
*/
|
||||
#define PCAP_DEPRECATED(func, msg) __pragma(deprecated(func))
|
||||
#else
|
||||
#define PCAP_DEPRECATED(func, msg)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* For flagging arguments as format strings in MSVC.
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
#include <sal.h>
|
||||
#if _MSC_VER > 1400
|
||||
#define PCAP_FORMAT_STRING(p) _Printf_format_string_ p
|
||||
#else
|
||||
#define PCAP_FORMAT_STRING(p) __format_string p
|
||||
#endif
|
||||
#else
|
||||
#define PCAP_FORMAT_STRING(p) p
|
||||
#endif
|
||||
|
||||
#endif /* lib_pcap_funcattrs_h */
|
43
src/frontend/qt_sdl/pcap/ipnet.h
Normal file
43
src/frontend/qt_sdl/pcap/ipnet.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from the Stanford/CMU enet packet filter,
|
||||
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
|
||||
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
|
||||
* Berkeley Laboratory.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define IPH_AF_INET 2 /* Matches Solaris's AF_INET */
|
||||
#define IPH_AF_INET6 26 /* Matches Solaris's AF_INET6 */
|
||||
|
||||
#define IPNET_OUTBOUND 1
|
||||
#define IPNET_INBOUND 2
|
85
src/frontend/qt_sdl/pcap/namedb.h
Normal file
85
src/frontend/qt_sdl/pcap/namedb.h
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 1996
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the Computer Systems
|
||||
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_namedb_h
|
||||
#define lib_pcap_namedb_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* As returned by the pcap_next_etherent()
|
||||
* XXX this stuff doesn't belong in this interface, but this
|
||||
* library already must do name to address translation, so
|
||||
* on systems that don't have support for /etc/ethers, we
|
||||
* export these hooks since they're already being used by
|
||||
* some applications (such as tcpdump) and already being
|
||||
* marked as exported in some OSes offering libpcap (such
|
||||
* as Debian).
|
||||
*/
|
||||
struct pcap_etherent {
|
||||
u_char addr[6];
|
||||
char name[122];
|
||||
};
|
||||
#ifndef PCAP_ETHERS_FILE
|
||||
#define PCAP_ETHERS_FILE "/etc/ethers"
|
||||
#endif
|
||||
PCAP_API struct pcap_etherent *pcap_next_etherent(FILE *);
|
||||
PCAP_API u_char *pcap_ether_hostton(const char*);
|
||||
PCAP_API u_char *pcap_ether_aton(const char *);
|
||||
|
||||
PCAP_API bpf_u_int32 **pcap_nametoaddr(const char *);
|
||||
#ifdef INET6
|
||||
PCAP_API struct addrinfo *pcap_nametoaddrinfo(const char *);
|
||||
#endif
|
||||
PCAP_API bpf_u_int32 pcap_nametonetaddr(const char *);
|
||||
|
||||
PCAP_API int pcap_nametoport(const char *, int *, int *);
|
||||
PCAP_API int pcap_nametoportrange(const char *, int *, int *, int *);
|
||||
PCAP_API int pcap_nametoproto(const char *);
|
||||
PCAP_API int pcap_nametoeproto(const char *);
|
||||
PCAP_API int pcap_nametollc(const char *);
|
||||
/*
|
||||
* If a protocol is unknown, PROTO_UNDEF is returned.
|
||||
* Also, pcap_nametoport() returns the protocol along with the port number.
|
||||
* If there are ambiguous entried in /etc/services (i.e. domain
|
||||
* can be either tcp or udp) PROTO_UNDEF is returned.
|
||||
*/
|
||||
#define PROTO_UNDEF -1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
94
src/frontend/qt_sdl/pcap/nflog.h
Normal file
94
src/frontend/qt_sdl/pcap/nflog.h
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Petar Alilovic,
|
||||
* Faculty of Electrical Engineering and Computing, University of Zagreb
|
||||
* All rights reserved
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_nflog_h
|
||||
#define lib_pcap_nflog_h
|
||||
|
||||
#include <pcap/pcap-inttypes.h>
|
||||
|
||||
/*
|
||||
* Structure of an NFLOG header and TLV parts, as described at
|
||||
* http://www.tcpdump.org/linktypes/LINKTYPE_NFLOG.html
|
||||
*
|
||||
* The NFLOG header is big-endian.
|
||||
*
|
||||
* The TLV length and type are in host byte order. The value is either
|
||||
* big-endian or is an array of bytes in some externally-specified byte
|
||||
* order (text string, link-layer address, link-layer header, packet
|
||||
* data, etc.).
|
||||
*/
|
||||
typedef struct nflog_hdr {
|
||||
uint8_t nflog_family; /* address family */
|
||||
uint8_t nflog_version; /* version */
|
||||
uint16_t nflog_rid; /* resource ID */
|
||||
} nflog_hdr_t;
|
||||
|
||||
typedef struct nflog_tlv {
|
||||
uint16_t tlv_length; /* tlv length */
|
||||
uint16_t tlv_type; /* tlv type */
|
||||
/* value follows this */
|
||||
} nflog_tlv_t;
|
||||
|
||||
typedef struct nflog_packet_hdr {
|
||||
uint16_t hw_protocol; /* hw protocol */
|
||||
uint8_t hook; /* netfilter hook */
|
||||
uint8_t pad; /* padding to 32 bits */
|
||||
} nflog_packet_hdr_t;
|
||||
|
||||
typedef struct nflog_hwaddr {
|
||||
uint16_t hw_addrlen; /* address length */
|
||||
uint16_t pad; /* padding to 32-bit boundary */
|
||||
uint8_t hw_addr[8]; /* address, up to 8 bytes */
|
||||
} nflog_hwaddr_t;
|
||||
|
||||
typedef struct nflog_timestamp {
|
||||
uint64_t sec;
|
||||
uint64_t usec;
|
||||
} nflog_timestamp_t;
|
||||
|
||||
/*
|
||||
* TLV types.
|
||||
*/
|
||||
#define NFULA_PACKET_HDR 1 /* nflog_packet_hdr_t */
|
||||
#define NFULA_MARK 2 /* packet mark from skbuff */
|
||||
#define NFULA_TIMESTAMP 3 /* nflog_timestamp_t for skbuff's time stamp */
|
||||
#define NFULA_IFINDEX_INDEV 4 /* ifindex of device on which packet received (possibly bridge group) */
|
||||
#define NFULA_IFINDEX_OUTDEV 5 /* ifindex of device on which packet transmitted (possibly bridge group) */
|
||||
#define NFULA_IFINDEX_PHYSINDEV 6 /* ifindex of physical device on which packet received (not bridge group) */
|
||||
#define NFULA_IFINDEX_PHYSOUTDEV 7 /* ifindex of physical device on which packet transmitted (not bridge group) */
|
||||
#define NFULA_HWADDR 8 /* nflog_hwaddr_t for hardware address */
|
||||
#define NFULA_PAYLOAD 9 /* packet payload */
|
||||
#define NFULA_PREFIX 10 /* text string - null-terminated, count includes NUL */
|
||||
#define NFULA_UID 11 /* UID owning socket on which packet was sent/received */
|
||||
#define NFULA_SEQ 12 /* sequence number of packets on this NFLOG socket */
|
||||
#define NFULA_SEQ_GLOBAL 13 /* sequence number of pakets on all NFLOG sockets */
|
||||
#define NFULA_GID 14 /* GID owning socket on which packet was sent/received */
|
||||
#define NFULA_HWTYPE 15 /* ARPHRD_ type of skbuff's device */
|
||||
#define NFULA_HWHEADER 16 /* skbuff's MAC-layer header */
|
||||
#define NFULA_HWLEN 17 /* length of skbuff's MAC-layer header */
|
||||
|
||||
#endif
|
117
src/frontend/qt_sdl/pcap/pcap-inttypes.h
Normal file
117
src/frontend/qt_sdl/pcap/pcap-inttypes.h
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||
* Copyright (c) 2005 - 2009 CACE Technologies, Inc. Davis (California)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Politecnico di Torino nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef pcap_pcap_inttypes_h
|
||||
#define pcap_pcap_inttypes_h
|
||||
|
||||
/*
|
||||
* Get the integer types and PRi[doux]64 values from C99 <inttypes.h>
|
||||
* defined, by hook or by crook.
|
||||
*/
|
||||
#if defined(_MSC_VER)
|
||||
/*
|
||||
* Compiler is MSVC.
|
||||
*/
|
||||
#if _MSC_VER >= 1800
|
||||
/*
|
||||
* VS 2013 or newer; we have <inttypes.h>.
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
/*
|
||||
* Earlier VS; we have to define this stuff ourselves.
|
||||
*/
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef signed int int32_t;
|
||||
#ifdef _MSC_EXTENSIONS
|
||||
typedef unsigned _int64 uint64_t;
|
||||
typedef _int64 int64_t;
|
||||
#else /* _MSC_EXTENSIONS */
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef long long int64_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* These may be defined by <inttypes.h>.
|
||||
*
|
||||
* XXX - for MSVC, we always want the _MSC_EXTENSIONS versions.
|
||||
* What about other compilers? If, as the MinGW Web site says MinGW
|
||||
* does, the other compilers just use Microsoft's run-time library,
|
||||
* then they should probably use the _MSC_EXTENSIONS even if the
|
||||
* compiler doesn't define _MSC_EXTENSIONS.
|
||||
*
|
||||
* XXX - we currently aren't using any of these, but this allows
|
||||
* their use in the future.
|
||||
*/
|
||||
#ifndef PRId64
|
||||
#ifdef _MSC_EXTENSIONS
|
||||
#define PRId64 "I64d"
|
||||
#else
|
||||
#define PRId64 "lld"
|
||||
#endif
|
||||
#endif /* PRId64 */
|
||||
|
||||
#ifndef PRIo64
|
||||
#ifdef _MSC_EXTENSIONS
|
||||
#define PRIo64 "I64o"
|
||||
#else
|
||||
#define PRIo64 "llo"
|
||||
#endif
|
||||
#endif /* PRIo64 */
|
||||
|
||||
#ifndef PRIx64
|
||||
#ifdef _MSC_EXTENSIONS
|
||||
#define PRIx64 "I64x"
|
||||
#else
|
||||
#define PRIx64 "llx"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PRIu64
|
||||
#ifdef _MSC_EXTENSIONS
|
||||
#define PRIu64 "I64u"
|
||||
#else
|
||||
#define PRIu64 "llu"
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__MINGW32__) || !defined(_WIN32)
|
||||
/*
|
||||
* Compiler is MinGW or target is UN*X or MS-DOS. Just use
|
||||
* <inttypes.h>.
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#endif /* pcap/pcap-inttypes.h */
|
966
src/frontend/qt_sdl/pcap/pcap.h
Normal file
966
src/frontend/qt_sdl/pcap/pcap.h
Normal file
@ -0,0 +1,966 @@
|
||||
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
|
||||
/*
|
||||
* Copyright (c) 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the Computer Systems
|
||||
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Remote packet capture mechanisms and extensions from WinPcap:
|
||||
*
|
||||
* Copyright (c) 2002 - 2003
|
||||
* NetGroup, Politecnico di Torino (Italy)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Politecnico di Torino nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_pcap_h
|
||||
#define lib_pcap_pcap_h
|
||||
|
||||
#include <pcap/funcattrs.h>
|
||||
|
||||
#include <pcap/pcap-inttypes.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <winsock2.h> /* u_int, u_char etc. */
|
||||
#include <io.h> /* _get_osfhandle() */
|
||||
#elif defined(MSDOS)
|
||||
#include <sys/types.h> /* u_int, u_char etc. */
|
||||
#include <sys/socket.h>
|
||||
#else /* UN*X */
|
||||
#include <sys/types.h> /* u_int, u_char etc. */
|
||||
#include <sys/time.h>
|
||||
#endif /* _WIN32/MSDOS/UN*X */
|
||||
|
||||
#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
|
||||
#include <pcap/bpf.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Version number of the current version of the pcap file format.
|
||||
*
|
||||
* NOTE: this is *NOT* the version number of the libpcap library.
|
||||
* To fetch the version information for the version of libpcap
|
||||
* you're using, use pcap_lib_version().
|
||||
*/
|
||||
#define PCAP_VERSION_MAJOR 2
|
||||
#define PCAP_VERSION_MINOR 4
|
||||
|
||||
#define PCAP_ERRBUF_SIZE 256
|
||||
|
||||
/*
|
||||
* Compatibility for systems that have a bpf.h that
|
||||
* predates the bpf typedefs for 64-bit support.
|
||||
*/
|
||||
#if BPF_RELEASE - 0 < 199406
|
||||
typedef int bpf_int32;
|
||||
typedef u_int bpf_u_int32;
|
||||
#endif
|
||||
|
||||
typedef struct pcap pcap_t;
|
||||
typedef struct pcap_dumper pcap_dumper_t;
|
||||
typedef struct pcap_if pcap_if_t;
|
||||
typedef struct pcap_addr pcap_addr_t;
|
||||
|
||||
/*
|
||||
* The first record in the file contains saved values for some
|
||||
* of the flags used in the printout phases of tcpdump.
|
||||
* Many fields here are 32 bit ints so compilers won't insert unwanted
|
||||
* padding; these files need to be interchangeable across architectures.
|
||||
*
|
||||
* Do not change the layout of this structure, in any way (this includes
|
||||
* changes that only affect the length of fields in this structure).
|
||||
*
|
||||
* Also, do not change the interpretation of any of the members of this
|
||||
* structure, in any way (this includes using values other than
|
||||
* LINKTYPE_ values, as defined in "savefile.c", in the "linktype"
|
||||
* field).
|
||||
*
|
||||
* Instead:
|
||||
*
|
||||
* introduce a new structure for the new format, if the layout
|
||||
* of the structure changed;
|
||||
*
|
||||
* send mail to "tcpdump-workers@lists.tcpdump.org", requesting
|
||||
* a new magic number for your new capture file format, and, when
|
||||
* you get the new magic number, put it in "savefile.c";
|
||||
*
|
||||
* use that magic number for save files with the changed file
|
||||
* header;
|
||||
*
|
||||
* make the code in "savefile.c" capable of reading files with
|
||||
* the old file header as well as files with the new file header
|
||||
* (using the magic number to determine the header format).
|
||||
*
|
||||
* Then supply the changes by forking the branch at
|
||||
*
|
||||
* https://github.com/the-tcpdump-group/libpcap/issues
|
||||
*
|
||||
* and issuing a pull request, so that future versions of libpcap and
|
||||
* programs that use it (such as tcpdump) will be able to read your new
|
||||
* capture file format.
|
||||
*/
|
||||
struct pcap_file_header {
|
||||
bpf_u_int32 magic;
|
||||
u_short version_major;
|
||||
u_short version_minor;
|
||||
bpf_int32 thiszone; /* gmt to local correction */
|
||||
bpf_u_int32 sigfigs; /* accuracy of timestamps */
|
||||
bpf_u_int32 snaplen; /* max length saved portion of each pkt */
|
||||
bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */
|
||||
};
|
||||
|
||||
/*
|
||||
* Macros for the value returned by pcap_datalink_ext().
|
||||
*
|
||||
* If LT_FCS_LENGTH_PRESENT(x) is true, the LT_FCS_LENGTH(x) macro
|
||||
* gives the FCS length of packets in the capture.
|
||||
*/
|
||||
#define LT_FCS_LENGTH_PRESENT(x) ((x) & 0x04000000)
|
||||
#define LT_FCS_LENGTH(x) (((x) & 0xF0000000) >> 28)
|
||||
#define LT_FCS_DATALINK_EXT(x) ((((x) & 0xF) << 28) | 0x04000000)
|
||||
|
||||
typedef enum {
|
||||
PCAP_D_INOUT = 0,
|
||||
PCAP_D_IN,
|
||||
PCAP_D_OUT
|
||||
} pcap_direction_t;
|
||||
|
||||
/*
|
||||
* Generic per-packet information, as supplied by libpcap.
|
||||
*
|
||||
* The time stamp can and should be a "struct timeval", regardless of
|
||||
* whether your system supports 32-bit tv_sec in "struct timeval",
|
||||
* 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit
|
||||
* and 64-bit applications. The on-disk format of savefiles uses 32-bit
|
||||
* tv_sec (and tv_usec); this structure is irrelevant to that. 32-bit
|
||||
* and 64-bit versions of libpcap, even if they're on the same platform,
|
||||
* should supply the appropriate version of "struct timeval", even if
|
||||
* that's not what the underlying packet capture mechanism supplies.
|
||||
*/
|
||||
struct pcap_pkthdr {
|
||||
struct timeval ts; /* time stamp */
|
||||
bpf_u_int32 caplen; /* length of portion present */
|
||||
bpf_u_int32 len; /* length this packet (off wire) */
|
||||
};
|
||||
|
||||
/*
|
||||
* As returned by the pcap_stats()
|
||||
*/
|
||||
struct pcap_stat {
|
||||
u_int ps_recv; /* number of packets received */
|
||||
u_int ps_drop; /* number of packets dropped */
|
||||
u_int ps_ifdrop; /* drops by interface -- only supported on some platforms */
|
||||
#ifdef _WIN32
|
||||
u_int ps_capt; /* number of packets that reach the application */
|
||||
u_int ps_sent; /* number of packets sent by the server on the network */
|
||||
u_int ps_netdrop; /* number of packets lost on the network */
|
||||
#endif /* _WIN32 */
|
||||
};
|
||||
|
||||
#ifdef MSDOS
|
||||
/*
|
||||
* As returned by the pcap_stats_ex()
|
||||
*/
|
||||
struct pcap_stat_ex {
|
||||
u_long rx_packets; /* total packets received */
|
||||
u_long tx_packets; /* total packets transmitted */
|
||||
u_long rx_bytes; /* total bytes received */
|
||||
u_long tx_bytes; /* total bytes transmitted */
|
||||
u_long rx_errors; /* bad packets received */
|
||||
u_long tx_errors; /* packet transmit problems */
|
||||
u_long rx_dropped; /* no space in Rx buffers */
|
||||
u_long tx_dropped; /* no space available for Tx */
|
||||
u_long multicast; /* multicast packets received */
|
||||
u_long collisions;
|
||||
|
||||
/* detailed rx_errors: */
|
||||
u_long rx_length_errors;
|
||||
u_long rx_over_errors; /* receiver ring buff overflow */
|
||||
u_long rx_crc_errors; /* recv'd pkt with crc error */
|
||||
u_long rx_frame_errors; /* recv'd frame alignment error */
|
||||
u_long rx_fifo_errors; /* recv'r fifo overrun */
|
||||
u_long rx_missed_errors; /* recv'r missed packet */
|
||||
|
||||
/* detailed tx_errors */
|
||||
u_long tx_aborted_errors;
|
||||
u_long tx_carrier_errors;
|
||||
u_long tx_fifo_errors;
|
||||
u_long tx_heartbeat_errors;
|
||||
u_long tx_window_errors;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Item in a list of interfaces.
|
||||
*/
|
||||
struct pcap_if {
|
||||
struct pcap_if *next;
|
||||
char *name; /* name to hand to "pcap_open_live()" */
|
||||
char *description; /* textual description of interface, or NULL */
|
||||
struct pcap_addr *addresses;
|
||||
bpf_u_int32 flags; /* PCAP_IF_ interface flags */
|
||||
};
|
||||
|
||||
#define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */
|
||||
#define PCAP_IF_UP 0x00000002 /* interface is up */
|
||||
#define PCAP_IF_RUNNING 0x00000004 /* interface is running */
|
||||
|
||||
/*
|
||||
* Representation of an interface address.
|
||||
*/
|
||||
struct pcap_addr {
|
||||
struct pcap_addr *next;
|
||||
struct sockaddr *addr; /* address */
|
||||
struct sockaddr *netmask; /* netmask for that address */
|
||||
struct sockaddr *broadaddr; /* broadcast address for that address */
|
||||
struct sockaddr *dstaddr; /* P2P destination address for that address */
|
||||
};
|
||||
|
||||
typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
|
||||
const u_char *);
|
||||
|
||||
/*
|
||||
* Error codes for the pcap API.
|
||||
* These will all be negative, so you can check for the success or
|
||||
* failure of a call that returns these codes by checking for a
|
||||
* negative value.
|
||||
*/
|
||||
#define PCAP_ERROR -1 /* generic error code */
|
||||
#define PCAP_ERROR_BREAK -2 /* loop terminated by pcap_breakloop */
|
||||
#define PCAP_ERROR_NOT_ACTIVATED -3 /* the capture needs to be activated */
|
||||
#define PCAP_ERROR_ACTIVATED -4 /* the operation can't be performed on already activated captures */
|
||||
#define PCAP_ERROR_NO_SUCH_DEVICE -5 /* no such device exists */
|
||||
#define PCAP_ERROR_RFMON_NOTSUP -6 /* this device doesn't support rfmon (monitor) mode */
|
||||
#define PCAP_ERROR_NOT_RFMON -7 /* operation supported only in monitor mode */
|
||||
#define PCAP_ERROR_PERM_DENIED -8 /* no permission to open the device */
|
||||
#define PCAP_ERROR_IFACE_NOT_UP -9 /* interface isn't up */
|
||||
#define PCAP_ERROR_CANTSET_TSTAMP_TYPE -10 /* this device doesn't support setting the time stamp type */
|
||||
#define PCAP_ERROR_PROMISC_PERM_DENIED -11 /* you don't have permission to capture in promiscuous mode */
|
||||
#define PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -12 /* the requested time stamp precision is not supported */
|
||||
|
||||
/*
|
||||
* Warning codes for the pcap API.
|
||||
* These will all be positive and non-zero, so they won't look like
|
||||
* errors.
|
||||
*/
|
||||
#define PCAP_WARNING 1 /* generic warning code */
|
||||
#define PCAP_WARNING_PROMISC_NOTSUP 2 /* this device doesn't support promiscuous mode */
|
||||
#define PCAP_WARNING_TSTAMP_TYPE_NOTSUP 3 /* the requested time stamp type is not supported */
|
||||
|
||||
/*
|
||||
* Value to pass to pcap_compile() as the netmask if you don't know what
|
||||
* the netmask is.
|
||||
*/
|
||||
#define PCAP_NETMASK_UNKNOWN 0xffffffff
|
||||
|
||||
/*
|
||||
* We're deprecating pcap_lookupdev() for various reasons (not
|
||||
* thread-safe, can behave weirdly with WinPcap). Callers
|
||||
* should use pcap_findalldevs() and use the first device.
|
||||
*/
|
||||
PCAP_API char *pcap_lookupdev(char *)
|
||||
PCAP_DEPRECATED(pcap_lookupdev, "use 'pcap_findalldevs' and use the first device");
|
||||
|
||||
PCAP_API int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
|
||||
|
||||
PCAP_API pcap_t *pcap_create(const char *, char *);
|
||||
PCAP_API int pcap_set_snaplen(pcap_t *, int);
|
||||
PCAP_API int pcap_set_promisc(pcap_t *, int);
|
||||
PCAP_API int pcap_can_set_rfmon(pcap_t *);
|
||||
PCAP_API int pcap_set_rfmon(pcap_t *, int);
|
||||
PCAP_API int pcap_set_timeout(pcap_t *, int);
|
||||
PCAP_API int pcap_set_tstamp_type(pcap_t *, int);
|
||||
PCAP_API int pcap_set_immediate_mode(pcap_t *, int);
|
||||
PCAP_API int pcap_set_buffer_size(pcap_t *, int);
|
||||
PCAP_API int pcap_set_tstamp_precision(pcap_t *, int);
|
||||
PCAP_API int pcap_get_tstamp_precision(pcap_t *);
|
||||
PCAP_API int pcap_activate(pcap_t *);
|
||||
|
||||
PCAP_API int pcap_list_tstamp_types(pcap_t *, int **);
|
||||
PCAP_API void pcap_free_tstamp_types(int *);
|
||||
PCAP_API int pcap_tstamp_type_name_to_val(const char *);
|
||||
PCAP_API const char *pcap_tstamp_type_val_to_name(int);
|
||||
PCAP_API const char *pcap_tstamp_type_val_to_description(int);
|
||||
|
||||
#ifdef __linux__
|
||||
PCAP_API int pcap_set_protocol(pcap_t *, int);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Time stamp types.
|
||||
* Not all systems and interfaces will necessarily support all of these.
|
||||
*
|
||||
* A system that supports PCAP_TSTAMP_HOST is offering time stamps
|
||||
* provided by the host machine, rather than by the capture device,
|
||||
* but not committing to any characteristics of the time stamp;
|
||||
* it will not offer any of the PCAP_TSTAMP_HOST_ subtypes.
|
||||
*
|
||||
* PCAP_TSTAMP_HOST_LOWPREC is a time stamp, provided by the host machine,
|
||||
* that's low-precision but relatively cheap to fetch; it's normally done
|
||||
* using the system clock, so it's normally synchronized with times you'd
|
||||
* fetch from system calls.
|
||||
*
|
||||
* PCAP_TSTAMP_HOST_HIPREC is a time stamp, provided by the host machine,
|
||||
* that's high-precision; it might be more expensive to fetch. It might
|
||||
* or might not be synchronized with the system clock, and might have
|
||||
* problems with time stamps for packets received on different CPUs,
|
||||
* depending on the platform.
|
||||
*
|
||||
* PCAP_TSTAMP_ADAPTER is a high-precision time stamp supplied by the
|
||||
* capture device; it's synchronized with the system clock.
|
||||
*
|
||||
* PCAP_TSTAMP_ADAPTER_UNSYNCED is a high-precision time stamp supplied by
|
||||
* the capture device; it's not synchronized with the system clock.
|
||||
*
|
||||
* Note that time stamps synchronized with the system clock can go
|
||||
* backwards, as the system clock can go backwards. If a clock is
|
||||
* not in sync with the system clock, that could be because the
|
||||
* system clock isn't keeping accurate time, because the other
|
||||
* clock isn't keeping accurate time, or both.
|
||||
*
|
||||
* Note that host-provided time stamps generally correspond to the
|
||||
* time when the time-stamping code sees the packet; this could
|
||||
* be some unknown amount of time after the first or last bit of
|
||||
* the packet is received by the network adapter, due to batching
|
||||
* of interrupts for packet arrival, queueing delays, etc..
|
||||
*/
|
||||
#define PCAP_TSTAMP_HOST 0 /* host-provided, unknown characteristics */
|
||||
#define PCAP_TSTAMP_HOST_LOWPREC 1 /* host-provided, low precision */
|
||||
#define PCAP_TSTAMP_HOST_HIPREC 2 /* host-provided, high precision */
|
||||
#define PCAP_TSTAMP_ADAPTER 3 /* device-provided, synced with the system clock */
|
||||
#define PCAP_TSTAMP_ADAPTER_UNSYNCED 4 /* device-provided, not synced with the system clock */
|
||||
|
||||
/*
|
||||
* Time stamp resolution types.
|
||||
* Not all systems and interfaces will necessarily support all of these
|
||||
* resolutions when doing live captures; all of them can be requested
|
||||
* when reading a savefile.
|
||||
*/
|
||||
#define PCAP_TSTAMP_PRECISION_MICRO 0 /* use timestamps with microsecond precision, default */
|
||||
#define PCAP_TSTAMP_PRECISION_NANO 1 /* use timestamps with nanosecond precision */
|
||||
|
||||
PCAP_API pcap_t *pcap_open_live(const char *, int, int, int, char *);
|
||||
PCAP_API pcap_t *pcap_open_dead(int, int);
|
||||
PCAP_API pcap_t *pcap_open_dead_with_tstamp_precision(int, int, u_int);
|
||||
PCAP_API pcap_t *pcap_open_offline_with_tstamp_precision(const char *, u_int, char *);
|
||||
PCAP_API pcap_t *pcap_open_offline(const char *, char *);
|
||||
#ifdef _WIN32
|
||||
PCAP_API pcap_t *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int, char *);
|
||||
PCAP_API pcap_t *pcap_hopen_offline(intptr_t, char *);
|
||||
/*
|
||||
* If we're building libpcap, these are internal routines in savefile.c,
|
||||
* so we must not define them as macros.
|
||||
*
|
||||
* If we're not building libpcap, given that the version of the C runtime
|
||||
* with which libpcap was built might be different from the version
|
||||
* of the C runtime with which an application using libpcap was built,
|
||||
* and that a FILE structure may differ between the two versions of the
|
||||
* C runtime, calls to _fileno() must use the version of _fileno() in
|
||||
* the C runtime used to open the FILE *, not the version in the C
|
||||
* runtime with which libpcap was built. (Maybe once the Universal CRT
|
||||
* rules the world, this will cease to be a problem.)
|
||||
*/
|
||||
#ifndef BUILDING_PCAP
|
||||
#define pcap_fopen_offline_with_tstamp_precision(f,p,b) \
|
||||
pcap_hopen_offline_with_tstamp_precision(_get_osfhandle(_fileno(f)), p, b)
|
||||
#define pcap_fopen_offline(f,b) \
|
||||
pcap_hopen_offline(_get_osfhandle(_fileno(f)), b)
|
||||
#endif
|
||||
#else /*_WIN32*/
|
||||
PCAP_API pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *);
|
||||
PCAP_API pcap_t *pcap_fopen_offline(FILE *, char *);
|
||||
#endif /*_WIN32*/
|
||||
|
||||
PCAP_API void pcap_close(pcap_t *);
|
||||
PCAP_API int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
|
||||
PCAP_API int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
|
||||
PCAP_API const u_char *pcap_next(pcap_t *, struct pcap_pkthdr *);
|
||||
PCAP_API int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
|
||||
PCAP_API void pcap_breakloop(pcap_t *);
|
||||
PCAP_API int pcap_stats(pcap_t *, struct pcap_stat *);
|
||||
PCAP_API int pcap_setfilter(pcap_t *, struct bpf_program *);
|
||||
PCAP_API int pcap_setdirection(pcap_t *, pcap_direction_t);
|
||||
PCAP_API int pcap_getnonblock(pcap_t *, char *);
|
||||
PCAP_API int pcap_setnonblock(pcap_t *, int, char *);
|
||||
PCAP_API int pcap_inject(pcap_t *, const void *, size_t);
|
||||
PCAP_API int pcap_sendpacket(pcap_t *, const u_char *, int);
|
||||
PCAP_API const char *pcap_statustostr(int);
|
||||
PCAP_API const char *pcap_strerror(int);
|
||||
PCAP_API char *pcap_geterr(pcap_t *);
|
||||
PCAP_API void pcap_perror(pcap_t *, const char *);
|
||||
PCAP_API int pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
|
||||
bpf_u_int32);
|
||||
PCAP_API int pcap_compile_nopcap(int, int, struct bpf_program *,
|
||||
const char *, int, bpf_u_int32);
|
||||
PCAP_API void pcap_freecode(struct bpf_program *);
|
||||
PCAP_API int pcap_offline_filter(const struct bpf_program *,
|
||||
const struct pcap_pkthdr *, const u_char *);
|
||||
PCAP_API int pcap_datalink(pcap_t *);
|
||||
PCAP_API int pcap_datalink_ext(pcap_t *);
|
||||
PCAP_API int pcap_list_datalinks(pcap_t *, int **);
|
||||
PCAP_API int pcap_set_datalink(pcap_t *, int);
|
||||
PCAP_API void pcap_free_datalinks(int *);
|
||||
PCAP_API int pcap_datalink_name_to_val(const char *);
|
||||
PCAP_API const char *pcap_datalink_val_to_name(int);
|
||||
PCAP_API const char *pcap_datalink_val_to_description(int);
|
||||
PCAP_API int pcap_snapshot(pcap_t *);
|
||||
PCAP_API int pcap_is_swapped(pcap_t *);
|
||||
PCAP_API int pcap_major_version(pcap_t *);
|
||||
PCAP_API int pcap_minor_version(pcap_t *);
|
||||
PCAP_API int pcap_bufsize(pcap_t *);
|
||||
|
||||
/* XXX */
|
||||
PCAP_API FILE *pcap_file(pcap_t *);
|
||||
PCAP_API int pcap_fileno(pcap_t *);
|
||||
|
||||
#ifdef _WIN32
|
||||
PCAP_API int pcap_wsockinit(void);
|
||||
#endif
|
||||
|
||||
PCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
|
||||
PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
|
||||
PCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *);
|
||||
PCAP_API FILE *pcap_dump_file(pcap_dumper_t *);
|
||||
PCAP_API long pcap_dump_ftell(pcap_dumper_t *);
|
||||
PCAP_API int64_t pcap_dump_ftell64(pcap_dumper_t *);
|
||||
PCAP_API int pcap_dump_flush(pcap_dumper_t *);
|
||||
PCAP_API void pcap_dump_close(pcap_dumper_t *);
|
||||
PCAP_API void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
|
||||
|
||||
PCAP_API int pcap_findalldevs(pcap_if_t **, char *);
|
||||
PCAP_API void pcap_freealldevs(pcap_if_t *);
|
||||
|
||||
/*
|
||||
* We return a pointer to the version string, rather than exporting the
|
||||
* version string directly.
|
||||
*
|
||||
* On at least some UNIXes, if you import data from a shared library into
|
||||
* an program, the data is bound into the program binary, so if the string
|
||||
* in the version of the library with which the program was linked isn't
|
||||
* the same as the string in the version of the library with which the
|
||||
* program is being run, various undesirable things may happen (warnings,
|
||||
* the string being the one from the version of the library with which the
|
||||
* program was linked, or even weirder things, such as the string being the
|
||||
* one from the library but being truncated).
|
||||
*
|
||||
* On Windows, the string is constructed at run time.
|
||||
*/
|
||||
PCAP_API const char *pcap_lib_version(void);
|
||||
|
||||
/*
|
||||
* On at least some versions of NetBSD and QNX, we don't want to declare
|
||||
* bpf_filter() here, as it's also be declared in <net/bpf.h>, with a
|
||||
* different signature, but, on other BSD-flavored UN*Xes, it's not
|
||||
* declared in <net/bpf.h>, so we *do* want to declare it here, so it's
|
||||
* declared when we build pcap-bpf.c.
|
||||
*/
|
||||
#if !defined(__NetBSD__) && !defined(__QNX__)
|
||||
PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
|
||||
#endif
|
||||
PCAP_API int bpf_validate(const struct bpf_insn *f, int len);
|
||||
PCAP_API char *bpf_image(const struct bpf_insn *, int);
|
||||
PCAP_API void bpf_dump(const struct bpf_program *, int);
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
/*
|
||||
* Win32 definitions
|
||||
*/
|
||||
|
||||
/*!
|
||||
\brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit().
|
||||
*/
|
||||
struct pcap_send_queue
|
||||
{
|
||||
u_int maxlen; /* Maximum size of the queue, in bytes. This
|
||||
variable contains the size of the buffer field. */
|
||||
u_int len; /* Current size of the queue, in bytes. */
|
||||
char *buffer; /* Buffer containing the packets to be sent. */
|
||||
};
|
||||
|
||||
typedef struct pcap_send_queue pcap_send_queue;
|
||||
|
||||
/*!
|
||||
\brief This typedef is a support for the pcap_get_airpcap_handle() function
|
||||
*/
|
||||
#if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
|
||||
#define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
|
||||
typedef struct _AirpcapHandle *PAirpcapHandle;
|
||||
#endif
|
||||
|
||||
PCAP_API int pcap_setbuff(pcap_t *p, int dim);
|
||||
PCAP_API int pcap_setmode(pcap_t *p, int mode);
|
||||
PCAP_API int pcap_setmintocopy(pcap_t *p, int size);
|
||||
|
||||
PCAP_API HANDLE pcap_getevent(pcap_t *p);
|
||||
|
||||
PCAP_API int pcap_oid_get_request(pcap_t *, bpf_u_int32, void *, size_t *);
|
||||
PCAP_API int pcap_oid_set_request(pcap_t *, bpf_u_int32, const void *, size_t *);
|
||||
|
||||
PCAP_API pcap_send_queue* pcap_sendqueue_alloc(u_int memsize);
|
||||
|
||||
PCAP_API void pcap_sendqueue_destroy(pcap_send_queue* queue);
|
||||
|
||||
PCAP_API int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data);
|
||||
|
||||
PCAP_API u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync);
|
||||
|
||||
PCAP_API struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size);
|
||||
|
||||
PCAP_API int pcap_setuserbuffer(pcap_t *p, int size);
|
||||
|
||||
PCAP_API int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks);
|
||||
|
||||
PCAP_API int pcap_live_dump_ended(pcap_t *p, int sync);
|
||||
|
||||
PCAP_API int pcap_start_oem(char* err_str, int flags);
|
||||
|
||||
PCAP_API PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p);
|
||||
|
||||
#define MODE_CAPT 0
|
||||
#define MODE_STAT 1
|
||||
#define MODE_MON 2
|
||||
|
||||
#elif defined(MSDOS)
|
||||
|
||||
/*
|
||||
* MS-DOS definitions
|
||||
*/
|
||||
|
||||
PCAP_API int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
|
||||
PCAP_API void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
|
||||
PCAP_API u_long pcap_mac_packets (void);
|
||||
|
||||
#else /* UN*X */
|
||||
|
||||
/*
|
||||
* UN*X definitions
|
||||
*/
|
||||
|
||||
PCAP_API int pcap_get_selectable_fd(pcap_t *);
|
||||
|
||||
#endif /* _WIN32/MSDOS/UN*X */
|
||||
|
||||
/*
|
||||
* Remote capture definitions.
|
||||
*
|
||||
* These routines are only present if libpcap has been configured to
|
||||
* include remote capture support.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The maximum buffer size in which address, port, interface names are kept.
|
||||
*
|
||||
* In case the adapter name or such is larger than this value, it is truncated.
|
||||
* This is not used by the user; however it must be aware that an hostname / interface
|
||||
* name longer than this value will be truncated.
|
||||
*/
|
||||
#define PCAP_BUF_SIZE 1024
|
||||
|
||||
/*
|
||||
* The type of input source, passed to pcap_open().
|
||||
*/
|
||||
#define PCAP_SRC_FILE 2 /* local savefile */
|
||||
#define PCAP_SRC_IFLOCAL 3 /* local network interface */
|
||||
#define PCAP_SRC_IFREMOTE 4 /* interface on a remote host, using RPCAP */
|
||||
|
||||
/*
|
||||
* The formats allowed by pcap_open() are the following:
|
||||
* - file://path_and_filename [opens a local file]
|
||||
* - rpcap://devicename [opens the selected device devices available on the local host, without using the RPCAP protocol]
|
||||
* - rpcap://host/devicename [opens the selected device available on a remote host]
|
||||
* - rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP]
|
||||
* - adaptername [to open a local adapter; kept for compability, but it is strongly discouraged]
|
||||
* - (NULL) [to open the first local adapter; kept for compability, but it is strongly discouraged]
|
||||
*
|
||||
* The formats allowed by the pcap_findalldevs_ex() are the following:
|
||||
* - file://folder/ [lists all the files in the given folder]
|
||||
* - rpcap:// [lists all local adapters]
|
||||
* - rpcap://host:port/ [lists the devices available on a remote host]
|
||||
*
|
||||
* Referring to the 'host' and 'port' parameters, they can be either numeric or literal. Since
|
||||
* IPv6 is fully supported, these are the allowed formats:
|
||||
*
|
||||
* - host (literal): e.g. host.foo.bar
|
||||
* - host (numeric IPv4): e.g. 10.11.12.13
|
||||
* - host (numeric IPv4, IPv6 style): e.g. [10.11.12.13]
|
||||
* - host (numeric IPv6): e.g. [1:2:3::4]
|
||||
* - port: can be either numeric (e.g. '80') or literal (e.g. 'http')
|
||||
*
|
||||
* Here you find some allowed examples:
|
||||
* - rpcap://host.foo.bar/devicename [everything literal, no port number]
|
||||
* - rpcap://host.foo.bar:1234/devicename [everything literal, with port number]
|
||||
* - rpcap://10.11.12.13/devicename [IPv4 numeric, no port number]
|
||||
* - rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number]
|
||||
* - rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number]
|
||||
* - rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number]
|
||||
* - rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number]
|
||||
* - rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number]
|
||||
*/
|
||||
|
||||
/*
|
||||
* URL schemes for capture source.
|
||||
*/
|
||||
/*
|
||||
* This string indicates that the user wants to open a capture from a
|
||||
* local file.
|
||||
*/
|
||||
#define PCAP_SRC_FILE_STRING "file://"
|
||||
/*
|
||||
* This string indicates that the user wants to open a capture from a
|
||||
* network interface. This string does not necessarily involve the use
|
||||
* of the RPCAP protocol. If the interface required resides on the local
|
||||
* host, the RPCAP protocol is not involved and the local functions are used.
|
||||
*/
|
||||
#define PCAP_SRC_IF_STRING "rpcap://"
|
||||
|
||||
/*
|
||||
* Flags to pass to pcap_open().
|
||||
*/
|
||||
|
||||
/*
|
||||
* Specifies whether promiscuous mode is to be used.
|
||||
*/
|
||||
#define PCAP_OPENFLAG_PROMISCUOUS 0x00000001
|
||||
|
||||
/*
|
||||
* Specifies, for an RPCAP capture, whether the data transfer (in
|
||||
* case of a remote capture) has to be done with UDP protocol.
|
||||
*
|
||||
* If it is '1' if you want a UDP data connection, '0' if you want
|
||||
* a TCP data connection; control connection is always TCP-based.
|
||||
* A UDP connection is much lighter, but it does not guarantee that all
|
||||
* the captured packets arrive to the client workstation. Moreover,
|
||||
* it could be harmful in case of network congestion.
|
||||
* This flag is meaningless if the source is not a remote interface.
|
||||
* In that case, it is simply ignored.
|
||||
*/
|
||||
#define PCAP_OPENFLAG_DATATX_UDP 0x00000002
|
||||
|
||||
/*
|
||||
* Specifies wheether the remote probe will capture its own generated
|
||||
* traffic.
|
||||
*
|
||||
* In case the remote probe uses the same interface to capture traffic
|
||||
* and to send data back to the caller, the captured traffic includes
|
||||
* the RPCAP traffic as well. If this flag is turned on, the RPCAP
|
||||
* traffic is excluded from the capture, so that the trace returned
|
||||
* back to the collector is does not include this traffic.
|
||||
*
|
||||
* Has no effect on local interfaces or savefiles.
|
||||
*/
|
||||
#define PCAP_OPENFLAG_NOCAPTURE_RPCAP 0x00000004
|
||||
|
||||
/*
|
||||
* Specifies whether the local adapter will capture its own generated traffic.
|
||||
*
|
||||
* This flag tells the underlying capture driver to drop the packets
|
||||
* that were sent by itself. This is useful when building applications
|
||||
* such as bridges that should ignore the traffic they just sent.
|
||||
*
|
||||
* Supported only on Windows.
|
||||
*/
|
||||
#define PCAP_OPENFLAG_NOCAPTURE_LOCAL 0x00000008
|
||||
|
||||
/*
|
||||
* This flag configures the adapter for maximum responsiveness.
|
||||
*
|
||||
* In presence of a large value for nbytes, WinPcap waits for the arrival
|
||||
* of several packets before copying the data to the user. This guarantees
|
||||
* a low number of system calls, i.e. lower processor usage, i.e. better
|
||||
* performance, which is good for applications like sniffers. If the user
|
||||
* sets the PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will
|
||||
* copy the packets as soon as the application is ready to receive them.
|
||||
* This is suggested for real time applications (such as, for example,
|
||||
* a bridge) that need the best responsiveness.
|
||||
*
|
||||
* The equivalent with pcap_create()/pcap_activate() is "immediate mode".
|
||||
*/
|
||||
#define PCAP_OPENFLAG_MAX_RESPONSIVENESS 0x00000010
|
||||
|
||||
/*
|
||||
* Remote authentication methods.
|
||||
* These are used in the 'type' member of the pcap_rmtauth structure.
|
||||
*/
|
||||
|
||||
/*
|
||||
* NULL authentication.
|
||||
*
|
||||
* The 'NULL' authentication has to be equal to 'zero', so that old
|
||||
* applications can just put every field of struct pcap_rmtauth to zero,
|
||||
* and it does work.
|
||||
*/
|
||||
#define RPCAP_RMTAUTH_NULL 0
|
||||
/*
|
||||
* Username/password authentication.
|
||||
*
|
||||
* With this type of authentication, the RPCAP protocol will use the username/
|
||||
* password provided to authenticate the user on the remote machine. If the
|
||||
* authentication is successful (and the user has the right to open network
|
||||
* devices) the RPCAP connection will continue; otherwise it will be dropped.
|
||||
*
|
||||
* *******NOTE********: the username and password are sent over the network
|
||||
* to the capture server *IN CLEAR TEXT*. Don't use this on a network
|
||||
* that you don't completely control! (And be *really* careful in your
|
||||
* definition of "completely"!)
|
||||
*/
|
||||
#define RPCAP_RMTAUTH_PWD 1
|
||||
|
||||
/*
|
||||
* This structure keeps the information needed to autheticate the user
|
||||
* on a remote machine.
|
||||
*
|
||||
* The remote machine can either grant or refuse the access according
|
||||
* to the information provided.
|
||||
* In case the NULL authentication is required, both 'username' and
|
||||
* 'password' can be NULL pointers.
|
||||
*
|
||||
* This structure is meaningless if the source is not a remote interface;
|
||||
* in that case, the functions which requires such a structure can accept
|
||||
* a NULL pointer as well.
|
||||
*/
|
||||
struct pcap_rmtauth
|
||||
{
|
||||
/*
|
||||
* \brief Type of the authentication required.
|
||||
*
|
||||
* In order to provide maximum flexibility, we can support different types
|
||||
* of authentication based on the value of this 'type' variable. The currently
|
||||
* supported authentication methods are defined into the
|
||||
* \link remote_auth_methods Remote Authentication Methods Section\endlink.
|
||||
*/
|
||||
int type;
|
||||
/*
|
||||
* \brief Zero-terminated string containing the username that has to be
|
||||
* used on the remote machine for authentication.
|
||||
*
|
||||
* This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
|
||||
* and it can be NULL.
|
||||
*/
|
||||
char *username;
|
||||
/*
|
||||
* \brief Zero-terminated string containing the password that has to be
|
||||
* used on the remote machine for authentication.
|
||||
*
|
||||
* This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
|
||||
* and it can be NULL.
|
||||
*/
|
||||
char *password;
|
||||
};
|
||||
|
||||
/*
|
||||
* This routine can open a savefile, a local device, or a device on
|
||||
* a remote machine running an RPCAP server.
|
||||
*
|
||||
* For opening a savefile, the pcap_open_offline routines can be used,
|
||||
* and will work just as well; code using them will work on more
|
||||
* platforms than code using pcap_open() to open savefiles.
|
||||
*
|
||||
* For opening a local device, pcap_open_live() can be used; it supports
|
||||
* most of the capabilities that pcap_open() supports, and code using it
|
||||
* will work on more platforms than code using pcap_open(). pcap_create()
|
||||
* and pcap_activate() can also be used; they support all capabilities
|
||||
* that pcap_open() supports, except for the Windows-only
|
||||
* PCAP_OPENFLAG_NOCAPTURE_LOCAL, and support additional capabilities.
|
||||
*
|
||||
* For opening a remote capture, pcap_open() is currently the only
|
||||
* API available.
|
||||
*/
|
||||
PCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags,
|
||||
int read_timeout, struct pcap_rmtauth *auth, char *errbuf);
|
||||
PCAP_API int pcap_createsrcstr(char *source, int type, const char *host,
|
||||
const char *port, const char *name, char *errbuf);
|
||||
PCAP_API int pcap_parsesrcstr(const char *source, int *type, char *host,
|
||||
char *port, char *name, char *errbuf);
|
||||
|
||||
/*
|
||||
* This routine can scan a directory for savefiles, list local capture
|
||||
* devices, or list capture devices on a remote machine running an RPCAP
|
||||
* server.
|
||||
*
|
||||
* For scanning for savefiles, it can be used on both UN*X systems and
|
||||
* Windows systems; for each directory entry it sees, it tries to open
|
||||
* the file as a savefile using pcap_open_offline(), and only includes
|
||||
* it in the list of files if the open succeeds, so it filters out
|
||||
* files for which the user doesn't have read permission, as well as
|
||||
* files that aren't valid savefiles readable by libpcap.
|
||||
*
|
||||
* For listing local capture devices, it's just a wrapper around
|
||||
* pcap_findalldevs(); code using pcap_findalldevs() will work on more
|
||||
* platforms than code using pcap_findalldevs_ex().
|
||||
*
|
||||
* For listing remote capture devices, pcap_findalldevs_ex() is currently
|
||||
* the only API available.
|
||||
*/
|
||||
PCAP_API int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth,
|
||||
pcap_if_t **alldevs, char *errbuf);
|
||||
|
||||
/*
|
||||
* Sampling methods.
|
||||
*
|
||||
* These allow pcap_loop(), pcap_dispatch(), pcap_next(), and pcap_next_ex()
|
||||
* to see only a sample of packets, rather than all packets.
|
||||
*
|
||||
* Currently, they work only on Windows local captures.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Specifies that no sampling is to be done on the current capture.
|
||||
*
|
||||
* In this case, no sampling algorithms are applied to the current capture.
|
||||
*/
|
||||
#define PCAP_SAMP_NOSAMP 0
|
||||
|
||||
/*
|
||||
* Specifies that only 1 out of N packets must be returned to the user.
|
||||
*
|
||||
* In this case, the 'value' field of the 'pcap_samp' structure indicates the
|
||||
* number of packets (minus 1) that must be discarded before one packet got
|
||||
* accepted.
|
||||
* In other words, if 'value = 10', the first packet is returned to the
|
||||
* caller, while the following 9 are discarded.
|
||||
*/
|
||||
#define PCAP_SAMP_1_EVERY_N 1
|
||||
|
||||
/*
|
||||
* Specifies that we have to return 1 packet every N milliseconds.
|
||||
*
|
||||
* In this case, the 'value' field of the 'pcap_samp' structure indicates
|
||||
* the 'waiting time' in milliseconds before one packet got accepted.
|
||||
* In other words, if 'value = 10', the first packet is returned to the
|
||||
* caller; the next returned one will be the first packet that arrives
|
||||
* when 10ms have elapsed.
|
||||
*/
|
||||
#define PCAP_SAMP_FIRST_AFTER_N_MS 2
|
||||
|
||||
/*
|
||||
* This structure defines the information related to sampling.
|
||||
*
|
||||
* In case the sampling is requested, the capturing device should read
|
||||
* only a subset of the packets coming from the source. The returned packets
|
||||
* depend on the sampling parameters.
|
||||
*
|
||||
* WARNING: The sampling process is applied *after* the filtering process.
|
||||
* In other words, packets are filtered first, then the sampling process
|
||||
* selects a subset of the 'filtered' packets and it returns them to the
|
||||
* caller.
|
||||
*/
|
||||
struct pcap_samp
|
||||
{
|
||||
/*
|
||||
* Method used for sampling; see above.
|
||||
*/
|
||||
int method;
|
||||
|
||||
/*
|
||||
* This value depends on the sampling method defined.
|
||||
* For its meaning, see above.
|
||||
*/
|
||||
int value;
|
||||
};
|
||||
|
||||
/*
|
||||
* New functions.
|
||||
*/
|
||||
PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
|
||||
|
||||
/*
|
||||
* RPCAP active mode.
|
||||
*/
|
||||
|
||||
/* Maximum length of an host name (needed for the RPCAP active mode) */
|
||||
#define RPCAP_HOSTLIST_SIZE 1024
|
||||
|
||||
/*
|
||||
* Some minor differences between UN*X sockets and and Winsock sockets.
|
||||
*/
|
||||
#ifndef _WIN32
|
||||
/*!
|
||||
* \brief In Winsock, a socket handle is of type SOCKET; in UN*X, it's
|
||||
* a file descriptor, and therefore a signed integer.
|
||||
* We define SOCKET to be a signed integer on UN*X, so that it can
|
||||
* be used on both platforms.
|
||||
*/
|
||||
#define SOCKET int
|
||||
|
||||
/*!
|
||||
* \brief In Winsock, the error return if socket() fails is INVALID_SOCKET;
|
||||
* in UN*X, it's -1.
|
||||
* We define INVALID_SOCKET to be -1 on UN*X, so that it can be used on
|
||||
* both platforms.
|
||||
*/
|
||||
#define INVALID_SOCKET -1
|
||||
#endif
|
||||
|
||||
PCAP_API SOCKET pcap_remoteact_accept(const char *address, const char *port,
|
||||
const char *hostlist, char *connectinghost,
|
||||
struct pcap_rmtauth *auth, char *errbuf);
|
||||
PCAP_API int pcap_remoteact_list(char *hostlist, char sep, int size,
|
||||
char *errbuf);
|
||||
PCAP_API int pcap_remoteact_close(const char *host, char *errbuf);
|
||||
PCAP_API void pcap_remoteact_cleanup(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* lib_pcap_pcap_h */
|
131
src/frontend/qt_sdl/pcap/sll.h
Normal file
131
src/frontend/qt_sdl/pcap/sll.h
Normal file
@ -0,0 +1,131 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from the Stanford/CMU enet packet filter,
|
||||
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
|
||||
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
|
||||
* Berkeley Laboratory.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* For captures on Linux cooked sockets, we construct a fake header
|
||||
* that includes:
|
||||
*
|
||||
* a 2-byte "packet type" which is one of:
|
||||
*
|
||||
* LINUX_SLL_HOST packet was sent to us
|
||||
* LINUX_SLL_BROADCAST packet was broadcast
|
||||
* LINUX_SLL_MULTICAST packet was multicast
|
||||
* LINUX_SLL_OTHERHOST packet was sent to somebody else
|
||||
* LINUX_SLL_OUTGOING packet was sent *by* us;
|
||||
*
|
||||
* a 2-byte Ethernet protocol field;
|
||||
*
|
||||
* a 2-byte link-layer type;
|
||||
*
|
||||
* a 2-byte link-layer address length;
|
||||
*
|
||||
* an 8-byte source link-layer address, whose actual length is
|
||||
* specified by the previous value.
|
||||
*
|
||||
* All fields except for the link-layer address are in network byte order.
|
||||
*
|
||||
* DO NOT change the layout of this structure, or change any of the
|
||||
* LINUX_SLL_ values below. If you must change the link-layer header
|
||||
* for a "cooked" Linux capture, introduce a new DLT_ type (ask
|
||||
* "tcpdump-workers@lists.tcpdump.org" for one, so that you don't give it
|
||||
* a value that collides with a value already being used), and use the
|
||||
* new header in captures of that type, so that programs that can
|
||||
* handle DLT_LINUX_SLL captures will continue to handle them correctly
|
||||
* without any change, and so that capture files with different headers
|
||||
* can be told apart and programs that read them can dissect the
|
||||
* packets in them.
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_sll_h
|
||||
#define lib_pcap_sll_h
|
||||
|
||||
/*
|
||||
* A DLT_LINUX_SLL fake link-layer header.
|
||||
*/
|
||||
#define SLL_HDR_LEN 16 /* total header length */
|
||||
#define SLL_ADDRLEN 8 /* length of address field */
|
||||
|
||||
#include <pcap/pcap-inttypes.h>
|
||||
|
||||
struct sll_header {
|
||||
uint16_t sll_pkttype; /* packet type */
|
||||
uint16_t sll_hatype; /* link-layer address type */
|
||||
uint16_t sll_halen; /* link-layer address length */
|
||||
uint8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */
|
||||
uint16_t sll_protocol; /* protocol */
|
||||
};
|
||||
|
||||
/*
|
||||
* The LINUX_SLL_ values for "sll_pkttype"; these correspond to the
|
||||
* PACKET_ values on Linux, but are defined here so that they're
|
||||
* available even on systems other than Linux, and so that they
|
||||
* don't change even if the PACKET_ values change.
|
||||
*/
|
||||
#define LINUX_SLL_HOST 0
|
||||
#define LINUX_SLL_BROADCAST 1
|
||||
#define LINUX_SLL_MULTICAST 2
|
||||
#define LINUX_SLL_OTHERHOST 3
|
||||
#define LINUX_SLL_OUTGOING 4
|
||||
|
||||
/*
|
||||
* The LINUX_SLL_ values for "sll_protocol"; these correspond to the
|
||||
* ETH_P_ values on Linux, but are defined here so that they're
|
||||
* available even on systems other than Linux. We assume, for now,
|
||||
* that the ETH_P_ values won't change in Linux; if they do, then:
|
||||
*
|
||||
* if we don't translate them in "pcap-linux.c", capture files
|
||||
* won't necessarily be readable if captured on a system that
|
||||
* defines ETH_P_ values that don't match these values;
|
||||
*
|
||||
* if we do translate them in "pcap-linux.c", that makes life
|
||||
* unpleasant for the BPF code generator, as the values you test
|
||||
* for in the kernel aren't the values that you test for when
|
||||
* reading a capture file, so the fixup code run on BPF programs
|
||||
* handed to the kernel ends up having to do more work.
|
||||
*
|
||||
* Add other values here as necessary, for handling packet types that
|
||||
* might show up on non-Ethernet, non-802.x networks. (Not all the ones
|
||||
* in the Linux "if_ether.h" will, I suspect, actually show up in
|
||||
* captures.)
|
||||
*/
|
||||
#define LINUX_SLL_P_802_3 0x0001 /* Novell 802.3 frames without 802.2 LLC header */
|
||||
#define LINUX_SLL_P_802_2 0x0004 /* 802.2 frames (not D/I/X Ethernet) */
|
||||
#define LINUX_SLL_P_CAN 0x000C /* CAN frames, with SocketCAN pseudo-headers */
|
||||
#define LINUX_SLL_P_CANFD 0x000D /* CAN FD frames, with SocketCAN pseudo-headers */
|
||||
|
||||
#endif
|
143
src/frontend/qt_sdl/pcap/usb.h
Normal file
143
src/frontend/qt_sdl/pcap/usb.h
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Paolo Abeni (Italy)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Basic USB data struct
|
||||
* By Paolo Abeni <paolo.abeni@email.it>
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_usb_h
|
||||
#define lib_pcap_usb_h
|
||||
|
||||
#include <pcap/pcap-inttypes.h>
|
||||
|
||||
/*
|
||||
* possible transfer mode
|
||||
*/
|
||||
#define URB_TRANSFER_IN 0x80
|
||||
#define URB_ISOCHRONOUS 0x0
|
||||
#define URB_INTERRUPT 0x1
|
||||
#define URB_CONTROL 0x2
|
||||
#define URB_BULK 0x3
|
||||
|
||||
/*
|
||||
* possible event type
|
||||
*/
|
||||
#define URB_SUBMIT 'S'
|
||||
#define URB_COMPLETE 'C'
|
||||
#define URB_ERROR 'E'
|
||||
|
||||
/*
|
||||
* USB setup header as defined in USB specification.
|
||||
* Appears at the front of each Control S-type packet in DLT_USB captures.
|
||||
*/
|
||||
typedef struct _usb_setup {
|
||||
uint8_t bmRequestType;
|
||||
uint8_t bRequest;
|
||||
uint16_t wValue;
|
||||
uint16_t wIndex;
|
||||
uint16_t wLength;
|
||||
} pcap_usb_setup;
|
||||
|
||||
/*
|
||||
* Information from the URB for Isochronous transfers.
|
||||
*/
|
||||
typedef struct _iso_rec {
|
||||
int32_t error_count;
|
||||
int32_t numdesc;
|
||||
} iso_rec;
|
||||
|
||||
/*
|
||||
* Header prepended by linux kernel to each event.
|
||||
* Appears at the front of each packet in DLT_USB_LINUX captures.
|
||||
*/
|
||||
typedef struct _usb_header {
|
||||
uint64_t id;
|
||||
uint8_t event_type;
|
||||
uint8_t transfer_type;
|
||||
uint8_t endpoint_number;
|
||||
uint8_t device_address;
|
||||
uint16_t bus_id;
|
||||
char setup_flag;/*if !=0 the urb setup header is not present*/
|
||||
char data_flag; /*if !=0 no urb data is present*/
|
||||
int64_t ts_sec;
|
||||
int32_t ts_usec;
|
||||
int32_t status;
|
||||
uint32_t urb_len;
|
||||
uint32_t data_len; /* amount of urb data really present in this event*/
|
||||
pcap_usb_setup setup;
|
||||
} pcap_usb_header;
|
||||
|
||||
/*
|
||||
* Header prepended by linux kernel to each event for the 2.6.31
|
||||
* and later kernels; for the 2.6.21 through 2.6.30 kernels, the
|
||||
* "iso_rec" information, and the fields starting with "interval"
|
||||
* are zeroed-out padding fields.
|
||||
*
|
||||
* Appears at the front of each packet in DLT_USB_LINUX_MMAPPED captures.
|
||||
*/
|
||||
typedef struct _usb_header_mmapped {
|
||||
uint64_t id;
|
||||
uint8_t event_type;
|
||||
uint8_t transfer_type;
|
||||
uint8_t endpoint_number;
|
||||
uint8_t device_address;
|
||||
uint16_t bus_id;
|
||||
char setup_flag;/*if !=0 the urb setup header is not present*/
|
||||
char data_flag; /*if !=0 no urb data is present*/
|
||||
int64_t ts_sec;
|
||||
int32_t ts_usec;
|
||||
int32_t status;
|
||||
uint32_t urb_len;
|
||||
uint32_t data_len; /* amount of urb data really present in this event*/
|
||||
union {
|
||||
pcap_usb_setup setup;
|
||||
iso_rec iso;
|
||||
} s;
|
||||
int32_t interval; /* for Interrupt and Isochronous events */
|
||||
int32_t start_frame; /* for Isochronous events */
|
||||
uint32_t xfer_flags; /* copy of URB's transfer flags */
|
||||
uint32_t ndesc; /* number of isochronous descriptors */
|
||||
} pcap_usb_header_mmapped;
|
||||
|
||||
/*
|
||||
* Isochronous descriptors; for isochronous transfers there might be
|
||||
* one or more of these at the beginning of the packet data. The
|
||||
* number of descriptors is given by the "ndesc" field in the header;
|
||||
* as indicated, in older kernels that don't put the descriptors at
|
||||
* the beginning of the packet, that field is zeroed out, so that field
|
||||
* can be trusted even in captures from older kernels.
|
||||
*/
|
||||
typedef struct _usb_isodesc {
|
||||
int32_t status;
|
||||
uint32_t offset;
|
||||
uint32_t len;
|
||||
uint8_t pad[4];
|
||||
} usb_isodesc;
|
||||
|
||||
#endif
|
46
src/frontend/qt_sdl/pcap/vlan.h
Normal file
46
src/frontend/qt_sdl/pcap/vlan.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_vlan_h
|
||||
#define lib_pcap_vlan_h
|
||||
|
||||
#include <pcap/pcap-inttypes.h>
|
||||
|
||||
struct vlan_tag {
|
||||
uint16_t vlan_tpid; /* ETH_P_8021Q */
|
||||
uint16_t vlan_tci; /* VLAN TCI */
|
||||
};
|
||||
|
||||
#define VLAN_TAG_LEN 4
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user