Skip to content

Commit

Permalink
ui: Support controller peripherals and XMU devices (xemu-project#1315)
Browse files Browse the repository at this point in the history
* Added XMU Settings to the Input Screen

* Added Peripherals to config

* Prevent overwriting existing XMUs

* Added blockdev.h to try to fix the MacOS build

* Fixed some issues that antangelo pointed out

* Moved the peripheralType and param vars into the loop

* Moved fatx.h and fatx.c to ui\thirdparty\fatx

* Added Validation for Peripheral Settings

* Fixed some nits that were pointed out

* don't pass NULL into xemu_settings_set_string

* Changes following Matt's recommendations

* Changes to XMU FilePicker

* XMU image auto-bind logic refactor

* renamed peripheralType to peripheral_type

* removed unnecessary calls to g_strdup_printf and g_free

* Cleaned up some comments, removed an unnecessary variable

* handle overwrite prompt in Windows

* Fixed some code format and style inconsistencies

* More formatting fixes

* Fixed a few memory leaks

* qemu_access: check for Read and Write access

* Run clang-format

* Remove unused xemu_new_xmu declaration

* Fix use after free in rebind code
  • Loading branch information
faha223 authored Dec 18, 2023
1 parent 800eb46 commit 03f40b1
Show file tree
Hide file tree
Showing 13 changed files with 769 additions and 142 deletions.
21 changes: 21 additions & 0 deletions config_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ input:
port2: string
port3: string
port4: string
peripherals:
port1:
peripheral_type_0: integer
peripheral_param_0: string
peripheral_type_1: integer
peripheral_param_1: string
port2:
peripheral_type_0: integer
peripheral_param_0: string
peripheral_type_1: integer
peripheral_param_1: string
port3:
peripheral_type_0: integer
peripheral_param_0: string
peripheral_type_1: integer
peripheral_param_1: string
port4:
peripheral_type_0: integer
peripheral_param_0: string
peripheral_type_1: integer
peripheral_param_1: string
gamecontrollerdb_path: string
auto_bind:
type: bool
Expand Down
1 change: 1 addition & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pfiles = [
'controller_mask.png',
'xmu_mask.png',
'logo_sdf.png',
'xemu_64x64.png',
'abxy.ttf',
Expand Down
Binary file added data/xmu_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ui/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ endif
xemu_ss.add(when: 'CONFIG_LINUX', if_true: [gtk, files('xemu-os-utils-linux.c')])
xemu_ss.add(when: 'CONFIG_WIN32', if_true: files('xemu-os-utils-windows.c'))
xemu_ss.add(when: 'CONFIG_DARWIN', if_true: files('xemu-os-utils-macos.m'))
xemu_ss.add(imgui, implot, stb_image, noc, sdl, opengl, openssl, fa, fpng, json, httplib)
xemu_ss.add(imgui, implot, stb_image, noc, sdl, opengl, openssl, fa, fpng, json, httplib, fatx)

softmmu_ss.add_all(xemu_ss)

Expand Down
51 changes: 51 additions & 0 deletions ui/thirdparty/fatx/fatx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "fatx.h"

#include "qemu/bswap.h"

#define FATX_SIGNATURE 0x58544146

// This is from libfatx
#pragma pack(1)
struct fatx_superblock {
uint32_t signature;
uint32_t volume_id;
uint32_t sectors_per_cluster;
uint32_t root_cluster;
uint16_t unknown1;
uint8_t padding[4078];
};
#pragma pack()

bool create_fatx_image(const char *filename, unsigned int size)
{
unsigned int empty_fat = cpu_to_le32(0xfffffff8);
unsigned char zero = 0;

FILE *fp = qemu_fopen(filename, "wb");
if (fp != NULL) {
struct fatx_superblock superblock;
memset(&superblock, 0xff, sizeof(struct fatx_superblock));

superblock.signature = cpu_to_le32(FATX_SIGNATURE);
superblock.sectors_per_cluster = cpu_to_le32(4);
superblock.volume_id = (uint32_t)rand();
superblock.root_cluster = cpu_to_le32(1);
superblock.unknown1 = 0;

// Write the fatx superblock.
fwrite(&superblock, sizeof(superblock), 1, fp);

// Write the FAT
fwrite(&empty_fat, sizeof(empty_fat), 1, fp);

fseek(fp, size - sizeof(unsigned char), SEEK_SET);
fwrite(&zero, sizeof(unsigned char), 1, fp);

fflush(fp);
fclose(fp);

return true;
}

return false;
}
16 changes: 16 additions & 0 deletions ui/thirdparty/fatx/fatx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef FATX_H
#define FATX_H

#include "qemu/osdep.h"

#ifdef __cplusplus
extern "C" {
#endif

bool create_fatx_image(const char *filename, unsigned int size);

#ifdef __cplusplus
}
#endif

#endif
3 changes: 3 additions & 0 deletions ui/thirdparty/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ fpng = declare_dependency(include_directories: 'fpng', link_with: libfpng)

json = declare_dependency(include_directories: 'json')
httplib = declare_dependency(include_directories: 'httplib')

libfatx = static_library('fatx', sources: 'fatx/fatx.c')
fatx = declare_dependency(include_directories: 'fatx', link_with: libfatx)
3 changes: 3 additions & 0 deletions ui/thirdparty/noc_file_dialog/noc_file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ const char *noc_file_dialog_open(int flags,
ofn.lpstrInitialDir = initialDir;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;

if (flags & NOC_FILE_DIALOG_OVERWRITE_CONFIRMATION)
ofn.Flags |= OFN_OVERWRITEPROMPT;

if (flags & NOC_FILE_DIALOG_OPEN) {
ret = GetOpenFileNameW(&ofn);
} else {
Expand Down
Loading

0 comments on commit 03f40b1

Please sign in to comment.