From dcf5d1b938bf397c4829f389bd9633451da07edd Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Sat, 10 Feb 2024 16:38:03 +0100 Subject: [PATCH] Code format (#14) * Format Quaesar specific code * Format checker * Fixed missed file --- .github/workflows/format_check.yml | 31 ++ src/.clang-format | 113 +++++++ src/ahidsound.h | 8 +- src/ahidsound_new.h | 6 +- src/avioutput.h | 6 +- src/dummy.cpp | 461 +++++++++++++++-------------- src/file_system.cpp | 124 ++++---- src/filepaths.cpp | 20 +- src/gfx.cpp | 21 +- src/gui.cpp | 48 ++- src/hardfile_host.cpp | 401 ++++++++++++------------- src/input.cpp | 36 +-- src/machdep/m68k.cpp | 145 +++++---- src/machdep/m68k.h | 148 ++++----- src/machdep/maccess.h | 122 ++++---- src/mman.cpp | 224 +++++++------- src/quaesar.cpp | 29 +- src/rp.h | 71 +++-- src/sounddep/sound.cpp | 8 +- src/sounddep/sound.h | 106 +++---- src/sysconfig.h | 180 ++++++----- src/target.h | 15 +- src/thread.cpp | 129 ++++---- src/threaddep/thread.h | 15 +- src/time.cpp | 25 +- src/unicode.cpp | 38 +-- src/winuae_compat.h | 20 +- 27 files changed, 1319 insertions(+), 1231 deletions(-) create mode 100644 .github/workflows/format_check.yml create mode 100644 src/.clang-format diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml new file mode 100644 index 000000000..329422916 --- /dev/null +++ b/.github/workflows/format_check.yml @@ -0,0 +1,31 @@ +name: Clang Format Check + +on: [push, pull_request] + +jobs: + format: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for all tags and branches + + - name: Install clang-format + run: sudo apt-get install -y clang-format + + - name: Check code formatting + run: | + cd src + # Find all C/C++ files, format them and check for differences + find . -regex '.*\.\(cpp\|hpp\|c\|h\)' | while read file; do + clang-format -style=file "$file" | diff -u "$file" - + if [ $? -ne 0 ]; then + echo "::error file=$file::File is not formatted correctly" + FORMAT_STATUS=1 + fi + done + # Fail the job if any files were not formatted correctly + if [ $FORMAT_STATUS -ne 0 ]; then + exit 1 + fi diff --git a/src/.clang-format b/src/.clang-format new file mode 100644 index 000000000..d8908bff2 --- /dev/null +++ b/src/.clang-format @@ -0,0 +1,113 @@ +--- +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^' + Priority: 2 + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +IncludeIsMainRegex: '([-_](test|unittest))?$' +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PenaltyBreakAssignment: 4 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +TabWidth: 4 +UseTab: Never +... + diff --git a/src/ahidsound.h b/src/ahidsound.h index 931b8e943..8ad3a6175 100644 --- a/src/ahidsound.h +++ b/src/ahidsound.h @@ -1,8 +1,8 @@ extern void ahi_updatesound(int force); -extern uae_u32 REGPARAM2 ahi_demux (TrapContext*); -extern int ahi_open_sound (void); -extern void ahi_close_sound (void); -extern void ahi_finish_sound_buffer (void); +extern uae_u32 REGPARAM2 ahi_demux(TrapContext*); +extern int ahi_open_sound(void); +extern void ahi_close_sound(void); +extern void ahi_finish_sound_buffer(void); extern int ahi_on; extern int ahi_pollrate; \ No newline at end of file diff --git a/src/ahidsound_new.h b/src/ahidsound_new.h index a76414a35..c41ee289d 100644 --- a/src/ahidsound_new.h +++ b/src/ahidsound_new.h @@ -1,3 +1,3 @@ -extern void init_ahi_v2 (void); -extern void free_ahi_v2 (void); -extern void ahi2_pause_sound (int); +extern void init_ahi_v2(void); +extern void free_ahi_v2(void); +extern void ahi2_pause_sound(int); diff --git a/src/avioutput.h b/src/avioutput.h index bf9713b56..53b1b5771 100644 --- a/src/avioutput.h +++ b/src/avioutput.h @@ -21,7 +21,7 @@ extern TCHAR avioutput_filename_auto[MAX_DPATH]; extern TCHAR avioutput_filename_inuse[MAX_DPATH]; extern void AVIOutput_Toggle(int mode, bool immediate); -extern bool AVIOutput_WriteAudio(uae_u8 *sndbuffer, int sndbufsize); +extern bool AVIOutput_WriteAudio(uae_u8* sndbuffer, int sndbufsize); extern int AVIOutput_ChooseAudioCodec(HWND hwnd, TCHAR*, int); extern int AVIOutput_GetAudioCodec(TCHAR*, int); extern int AVIOutput_ChooseVideoCodec(HWND hwnd, TCHAR*, int); @@ -31,11 +31,11 @@ extern void AVIOutput_End(void); extern void AVIOutput_Begin(bool); extern void AVIOutput_Release(void); extern void AVIOutput_Initialize(void); -extern void AVIOutput_RGBinfo(int,int,int,int,int,int,int,int); +extern void AVIOutput_RGBinfo(int, int, int, int, int, int, int, int); extern void AVIOutput_GetSettings(void); extern void AVIOutput_SetSettings(void); -extern void Screenshot_RGBinfo(int,int,int,int,int,int,int,int); +extern void Screenshot_RGBinfo(int, int, int, int, int, int, int, int); #define AVIAUDIO_AVI 1 #define AVIAUDIO_WAV 2 diff --git a/src/dummy.cpp b/src/dummy.cpp index ecb52925f..2c98c6e50 100644 --- a/src/dummy.cpp +++ b/src/dummy.cpp @@ -1,8 +1,10 @@ -#include -#include +// clang-format off #include +#include +#include #include +// Order of these includes is important :( #include #include "sysconfig.h" #include "sysdeps.h" @@ -50,11 +52,12 @@ #include "fpp.h" #include "xwin.h" #include +// clang-format on int avioutput_enabled = 0; bool beamracer_debug = false; int volatile bsd_int_requested = 0; -int busywait = 0; +int busywait = 0; int key_swap_hack = 0; int seriallog = 0; int log_vsync, debug_vsync_min_delay, debug_vsync_forced_delay; @@ -68,13 +71,13 @@ uae_u32 redc[3 * 256], grec[3 * 256], bluc[3 * 256]; uae_u8* start_pc_p = nullptr; uae_u32 start_pc = 0; -uae_u8 *cubo_nvram = nullptr; +uae_u8* cubo_nvram = nullptr; int dos_errno(void) { return errno; } -void pausevideograb(int) { +void pausevideograb(int) { UNIMPLEMENTED(); } @@ -105,7 +108,7 @@ void setmouseactive(int, int) { UNIMPLEMENTED(); } -void screenshot(int monid, int,int) { +void screenshot(int monid, int, int) { UNIMPLEMENTED(); } @@ -116,7 +119,7 @@ int same_aname(const TCHAR* an1, const TCHAR* an2) { int input_get_default_keyboard(int i) { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); return 0; } @@ -129,8 +132,8 @@ uae_s64 getsetpositionvideograb(uae_s64 framepos) { static int dummy_init(void) { return 1; //*((volatile int*)0) = 0; - //UNIMPLEMENTED(); - //return 0; // Return 0 for success, -1 for failure + // UNIMPLEMENTED(); + // return 0; // Return 0 for success, -1 for failure } // Dummy closing function @@ -141,7 +144,7 @@ static void dummy_close(void) { // Dummy function to acquire an input device static int dummy_acquire(int device_id, int exclusive) { UNIMPLEMENTED(); - return 0; // Return 0 for success, -1 for failure + return 0; // Return 0 for success, -1 for failure } // Dummy function to release/unacquire an input device @@ -151,12 +154,12 @@ static void dummy_unacquire(int device_id) { // Dummy function to read input from the device static void dummy_read(void) { - //printf("Reading input from device\n"); + // printf("Reading input from device\n"); } // Dummy function to get the number of input devices static int dummy_get_num(void) { - //TRACE(); + // TRACE(); return 0; } @@ -175,13 +178,13 @@ static TCHAR* dummy_get_uniquename(int device_id) { // Dummy function to get the number of widgets (input elements) in an input device static int dummy_get_widget_num(int device_id) { UNIMPLEMENTED(); - return 4; // Return the number of widgets + return 4; // Return the number of widgets } // Dummy function to get the type and name of a widget static int dummy_get_widget_type(int device_id, int widget_id, TCHAR* widget_name, uae_u32* widget_type) { UNIMPLEMENTED(); - return 0; // Return 0 for success, -1 for failure + return 0; // Return 0 for success, -1 for failure } // Dummy function to get the first widget (input element) in an input device @@ -192,64 +195,34 @@ static int dummy_get_widget_first(int device_id, int widget_type) { // Dummy function to get the flags of an input device int dummy_get_flags(int device_id) { - return 0; // Return flags (if any) for the input device + return 0; // Return flags (if any) for the input device } struct inputdevice_functions inputdevicefunc_mouse = { - dummy_init, - dummy_close, - dummy_acquire, - dummy_unacquire, - dummy_read, - dummy_get_num, - dummy_get_friendlyname, - dummy_get_uniquename, - dummy_get_widget_num, - dummy_get_widget_type, - dummy_get_widget_first, - dummy_get_flags -}; + dummy_init, dummy_close, dummy_acquire, dummy_unacquire, + dummy_read, dummy_get_num, dummy_get_friendlyname, dummy_get_uniquename, + dummy_get_widget_num, dummy_get_widget_type, dummy_get_widget_first, dummy_get_flags}; struct inputdevice_functions inputdevicefunc_keyboard = { - dummy_init, - dummy_close, - dummy_acquire, - dummy_unacquire, - dummy_read, - dummy_get_num, - dummy_get_friendlyname, - dummy_get_uniquename, - dummy_get_widget_num, - dummy_get_widget_type, - dummy_get_widget_first, - dummy_get_flags -}; + dummy_init, dummy_close, dummy_acquire, dummy_unacquire, + dummy_read, dummy_get_num, dummy_get_friendlyname, dummy_get_uniquename, + dummy_get_widget_num, dummy_get_widget_type, dummy_get_widget_first, dummy_get_flags}; struct inputdevice_functions inputdevicefunc_joystick = { - dummy_init, - dummy_close, - dummy_acquire, - dummy_unacquire, - dummy_read, - dummy_get_num, - dummy_get_friendlyname, - dummy_get_uniquename, - dummy_get_widget_num, - dummy_get_widget_type, - dummy_get_widget_first, - dummy_get_flags -}; + dummy_init, dummy_close, dummy_acquire, dummy_unacquire, + dummy_read, dummy_get_num, dummy_get_friendlyname, dummy_get_uniquename, + dummy_get_widget_num, dummy_get_widget_type, dummy_get_widget_first, dummy_get_flags}; const TCHAR* my_getfilepart(const TCHAR* filename) { - const TCHAR *p; + const TCHAR* p; - p = strrchr(filename, '\\'); - if (p) - return p + 1; - p = strrchr(filename, '/'); - if (p) - return p + 1; - return filename; + p = strrchr(filename, '\\'); + if (p) + return p + 1; + p = strrchr(filename, '/'); + if (p) + return p + 1; + return filename; } void fetch_statefilepath(TCHAR* out, int size) { @@ -276,8 +249,8 @@ void toggle_fullscreen(int monid, int) { const TCHAR* target_get_display_name(int, bool) { TRACE(); return "Amiga"; - //UNIMPLEMENTED(); - //return nullptr; + // UNIMPLEMENTED(); + // return nullptr; } extern int target_get_display(const TCHAR*) { @@ -299,17 +272,18 @@ int my_truncate(const TCHAR* name, uae_u64 len) { return 0; } -bool my_issamepath(const TCHAR* path1, const TCHAR *path2) { +bool my_issamepath(const TCHAR* path1, const TCHAR* path2) { UNIMPLEMENTED(); return false; } -int input_get_default_joystick (struct uae_input_device *uid, int i, int port, int af, int mode, bool gp, bool joymouseswap) { +int input_get_default_joystick(struct uae_input_device* uid, int i, int port, int af, int mode, bool gp, + bool joymouseswap) { UNIMPLEMENTED(); return 0; } -bool get_plugin_path (TCHAR *out, int len, const TCHAR *path) { +bool get_plugin_path(TCHAR* out, int len, const TCHAR* path) { TRACE(); return false; } @@ -322,13 +296,12 @@ void fixtrailing(TCHAR* p) { UNIMPLEMENTED(); } - int uae_slirp_redir(int is_udp, int host_port, struct in_addr guest_addr, int guest_port) { UNIMPLEMENTED(); return 0; } -int translate_message(int msg, TCHAR* out) { +int translate_message(int msg, TCHAR* out) { UNIMPLEMENTED(); return 0; } @@ -347,7 +320,6 @@ void refreshtitle() { UNIMPLEMENTED(); } - bool my_utime(const TCHAR* name, struct mytimeval* tv) { UNIMPLEMENTED(); return false; @@ -368,7 +340,7 @@ void masoboshi_ncr9x_scsi_put(unsigned int, unsigned int, int) { } struct autoconfig_info; - + bool isa_expansion_init(autoconfig_info*) { UNIMPLEMENTED(); return false; @@ -376,10 +348,10 @@ bool isa_expansion_init(autoconfig_info*) { uae_u32 gfxboard_get_romtype(rtgboardconfig*) { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); return 0; } - + void getpathpart(char*, int, char const*) { UNIMPLEMENTED(); } @@ -389,13 +361,13 @@ uae_u8* save_log(int, size_t*) { return nullptr; } -int my_unlink (const TCHAR* name, bool dontrecycle) { +int my_unlink(const TCHAR* name, bool dontrecycle) { UNIMPLEMENTED(); return 0; } struct fs_usage; - + int get_fs_usage(char const*, char const*, fs_usage*) { UNIMPLEMENTED(); return 0; @@ -419,27 +391,27 @@ void cpuboard_ncr720_io_bput(unsigned int, unsigned int) { UNIMPLEMENTED(); } -void cpuboard_setboard(struct uae_prefs *p, int type, int subtype) { +void cpuboard_setboard(struct uae_prefs* p, int type, int subtype) { UNIMPLEMENTED(); } -int cpuboard_memorytype(struct uae_prefs *p) { +int cpuboard_memorytype(struct uae_prefs* p) { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); return 0; } -bool cpuboard_fc_check(uaecptr addr, uae_u32 *v, int size, bool write) { +bool cpuboard_fc_check(uaecptr addr, uae_u32* v, int size, bool write) { UNIMPLEMENTED(); return false; } -int fsdb_name_invalid_dir (a_inode *, const TCHAR *n) { +int fsdb_name_invalid_dir(a_inode*, const TCHAR* n) { UNIMPLEMENTED(); return 0; } -int fsdb_mode_supported (const a_inode *) { +int fsdb_mode_supported(const a_inode*) { UNIMPLEMENTED(); return 0; } @@ -467,7 +439,7 @@ int a2386_init(autoconfig_info*) { } */ -void a4000t_add_scsi_unit (int ch, struct uaedev_config_info *ci, struct romconfig *rc) { +void a4000t_add_scsi_unit(int ch, struct uaedev_config_info* ci, struct romconfig* rc) { UNIMPLEMENTED(); } @@ -522,7 +494,7 @@ bool ariadne2_init(autoconfig_info*) { } bool audio_is_pull_event() { - //TRACE(); + // TRACE(); return false; } @@ -561,7 +533,7 @@ addrbank* cd32_fmv_init(autoconfig_info*) { void cd32_fmv_set_sync(float, float) { TRACE(); - //return 0; + // return 0; } void cdtv_add_scsi_unit(int, uaedev_config_info*, romconfig*) { @@ -759,7 +731,7 @@ void driveclick_fdrawcmd_seek(int, int) { void driveclick_fdrawcmd_vsync() { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); } int driveclick_loadresource(drvsample*, int) { @@ -807,7 +779,7 @@ uae_u32 emulib_target_getcpurate(unsigned int, unsigned int*) { void ethernet_reset() { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); } void fastlane_add_scsi_unit(int, uaedev_config_info*, romconfig*) { @@ -837,7 +809,7 @@ void fetch_videopath(char*, int) { #ifndef _WIN32 // TODO: Investigate why this is present in filesys.o void filesys_addexternals() { - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); } #endif @@ -854,7 +826,7 @@ void fpux_restore(int*) { } bool frame_drawn(int) { - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); TRACE(); return true; } @@ -924,42 +896,41 @@ int graphics_init(bool) { int amiga_width = 754; int amiga_height = 576; int depth = 32; - + struct vidbuf_description* avidinfo = &adisplays[0].gfxvidinfo; - avidinfo->drawbuffer.inwidth = avidinfo->drawbuffer.outwidth = amiga_width; - avidinfo->drawbuffer.inheight = avidinfo->drawbuffer.outheight = amiga_height; + avidinfo->drawbuffer.inwidth = avidinfo->drawbuffer.outwidth = amiga_width; + avidinfo->drawbuffer.inheight = avidinfo->drawbuffer.outheight = amiga_height; int pitch = amiga_width * depth >> 3; - avidinfo->drawbuffer.pixbytes = depth >> 3; - avidinfo->drawbuffer.bufmem = NULL; - avidinfo->drawbuffer.linemem = NULL; - avidinfo->drawbuffer.rowbytes = pitch; + avidinfo->drawbuffer.pixbytes = depth >> 3; + avidinfo->drawbuffer.bufmem = NULL; + avidinfo->drawbuffer.linemem = NULL; + avidinfo->drawbuffer.rowbytes = pitch; struct vidbuffer* buf = &avidinfo->drawbuffer; int width = 754; int height = 576; - buf->monitor_id = 0; - buf->pixbytes = (depth + 7) / 8; - buf->width_allocated = (width + 7) & ~7; - buf->height_allocated = height; + buf->monitor_id = 0; + buf->pixbytes = (depth + 7) / 8; + buf->width_allocated = (width + 7) & ~7; + buf->height_allocated = height; - int w = buf->width_allocated; - int h = buf->height_allocated; - int size = (w * 2) * (h * 2) * buf->pixbytes; - buf->rowbytes = w * 2 * buf->pixbytes; - buf->realbufmem = xcalloc(uae_u8, size); - buf->bufmem_allocated = buf->bufmem = buf->realbufmem + (h / 2) * buf->rowbytes + (w / 2) * buf->pixbytes; - buf->bufmemend = buf->realbufmem + size - buf->rowbytes; - buf->bufmem_lockable = true; + int w = buf->width_allocated; + int h = buf->height_allocated; + int size = (w * 2) * (h * 2) * buf->pixbytes; + buf->rowbytes = w * 2 * buf->pixbytes; + buf->realbufmem = xcalloc(uae_u8, size); + buf->bufmem_allocated = buf->bufmem = buf->realbufmem + (h / 2) * buf->rowbytes + (w / 2) * buf->pixbytes; + buf->bufmemend = buf->realbufmem + size - buf->rowbytes; + buf->bufmem_lockable = true; // Create a window - s_window = SDL_CreateWindow("Quaesar", - SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - width, height, SDL_WINDOW_RESIZABLE); + s_window = SDL_CreateWindow("Quaesar", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, + SDL_WINDOW_RESIZABLE); if (!s_window) { SDL_Log("Could not create window: %s", SDL_GetError()); @@ -976,7 +947,8 @@ int graphics_init(bool) { return 0; } - s_texture = SDL_CreateTexture(s_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, amiga_width, amiga_height); + s_texture = + SDL_CreateTexture(s_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, amiga_width, amiga_height); if (!s_texture) { SDL_Log("Could not create texture: %s", SDL_GetError()); @@ -1004,7 +976,6 @@ bool render_screen(int monid, int, bool) { return true; } - void unlockscr(struct vidbuffer* vb_in, int y_start, int y_end) { SDL_Event e; @@ -1016,19 +987,20 @@ void unlockscr(struct vidbuffer* vb_in, int y_start, int y_end) { while (SDL_PollEvent(&e) != 0) { // User requests quit switch (e.type) { - case SDL_QUIT: // User closes the window - quit_program == UAE_QUIT; + case SDL_QUIT: // User closes the window + quit_program == UAE_QUIT; // TODO: Fix me exit(0); break; - case SDL_KEYDOWN: // User presses a key - if (e.key.keysym.sym == SDLK_ESCAPE) { // If the key is ESC - quit_program == UAE_QUIT; + case SDL_KEYDOWN: // User presses a key + if (e.key.keysym.sym == SDLK_ESCAPE) { // If the key is ESC + quit_program == UAE_QUIT; exit(0); // TODO: Fix me } break; - default: break; + default: + break; } } @@ -1080,14 +1052,13 @@ void unlockscr(struct vidbuffer* vb_in, int y_start, int y_end) { new_width = (int)(window_height * image_aspect); } - SDL_Rect rect = { (window_width - new_width) / 2, (window_height - new_height) / 2, new_width, new_height }; + SDL_Rect rect = {(window_width - new_width) / 2, (window_height - new_height) / 2, new_width, new_height}; SDL_RenderClear(s_renderer); SDL_RenderCopy(s_renderer, s_texture, NULL, &rect); SDL_RenderPresent(s_renderer); } - void graphics_leave() { UNIMPLEMENTED(); } @@ -1098,7 +1069,7 @@ void graphics_reset(bool) { int graphics_setup() { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); return 1; } @@ -1119,11 +1090,11 @@ bool hydra_init(autoconfig_info*) { void init_fpucw_x87_80() { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); } void initparallel() { - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); } int init_sound() { @@ -1162,7 +1133,7 @@ bool lanrover_init(autoconfig_info*) { void logging_init() { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); return; } @@ -1172,7 +1143,7 @@ void machdep_free() { int machdep_init() { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); return 1; } @@ -1476,7 +1447,7 @@ void setup_brkhandler() { int setup_sound() { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); return 0; } @@ -1537,7 +1508,8 @@ void squirrel_add_scsi_unit(int, uaedev_config_info*, romconfig*) { UNIMPLEMENTED(); } -void statusline_render(int, unsigned char*, int, int, int, int, unsigned int*, unsigned int*, unsigned int*, unsigned int*) { +void statusline_render(int, unsigned char*, int, int, int, int, unsigned int*, unsigned int*, unsigned int*, + unsigned int*) { TRACE(); } @@ -1570,7 +1542,7 @@ int target_checkcapslock(int, int*) { void target_fixup_options(uae_prefs*) { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); } float target_getcurrentvblankrate(int) { @@ -1638,7 +1610,7 @@ void target_run() { void target_save_options(zfile*, uae_prefs*) { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); } void tekmagic_add_scsi_unit(int, uaedev_config_info*, romconfig*) { @@ -1755,7 +1727,7 @@ void warpengine_add_scsi_unit(int, uaedev_config_info*, romconfig*) { void x86_bridge_sync_change() { TRACE(); - //return 0; + // return 0; } void x86_doirq(unsigned char) { @@ -1876,7 +1848,7 @@ int fsdb_fill_file_attrs(a_inode_struct*, a_inode_struct*) { uae_u32 getlocaltime() { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); return 0; } @@ -1894,7 +1866,7 @@ const TCHAR* gfxboard_get_configname(int) { int gfxboard_get_configtype(rtgboardconfig*) { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); return 0; } @@ -1972,7 +1944,7 @@ uae_u8* restore_cdtv(unsigned char*) { void resume_sound() { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); } uae_u8* save_cdtv_dmac(size_t*, uae_u8*) { @@ -2021,12 +1993,12 @@ void squirrel_ncr9x_scsi_put(unsigned int, unsigned int, int) { } void target_cpu_speed() { - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); } void target_default_options(uae_prefs*, int) { TRACE(); - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); } static int old_w = -1; @@ -2080,7 +2052,7 @@ int uaeser_write(void*, unsigned char*, unsigned int) { } int audio_is_pull() { - //TRACE(); + // TRACE(); return 0; } @@ -2162,8 +2134,10 @@ static int dummy_stop_func(int deviceID) { return 0; } -static int dummy_play_func(int deviceID, int track, int index, int flags, play_status_callback status_callback, play_subchannel_callback subchannel_callback) { - printf("Dummy play_func called with deviceID: %d, track: %d, index: %d, flags: %d\n", deviceID, track, index, flags); +static int dummy_play_func(int deviceID, int track, int index, int flags, play_status_callback status_callback, + play_subchannel_callback subchannel_callback) { + printf("Dummy play_func called with deviceID: %d, track: %d, index: %d, flags: %d\n", deviceID, track, index, + flags); return 0; } @@ -2188,7 +2162,8 @@ static int dummy_read_func(int deviceID, uae_u8* buffer, int size, int flags) { } static int dummy_rawread_func(int deviceID, uae_u8* buffer, int size, int subcode, int flags, uae_u32 offset) { - printf("Dummy rawread_func called with deviceID: %d, size: %d, subcode: %d, flags: %d, offset: %u\n", deviceID, size, subcode, flags, offset); + printf("Dummy rawread_func called with deviceID: %d, size: %d, subcode: %d, flags: %d, offset: %u\n", deviceID, + size, subcode, flags, offset); return 0; } @@ -2212,60 +2187,97 @@ int dummy_scsiemu_func(int deviceID, uae_u8* data) { return 0; } -struct device_functions devicefunc_cdimage = { - _T("DummyDevice"), - dummy_open_bus_func, dummy_close_bus_func, dummy_open_device_func, dummy_close_device_func, dummy_info_device_func, - dummy_execscsicmd_out_func, dummy_execscsicmd_in_func, dummy_execscsicmd_direct_func, dummy_pause_func, dummy_stop_func, - dummy_play_func, dummy_volume_func, dummy_qcode_func, dummy_toc_func, dummy_read_func, - dummy_rawread_func, dummy_write_func, dummy_isatapi_func, dummy_ismedia_func, dummy_scsiemu_func -}; - -struct device_functions devicefunc_scsi_ioctl = { - _T("IOCTL"), - dummy_open_bus_func, dummy_close_bus_func, dummy_open_device_func, dummy_close_device_func, dummy_info_device_func, - dummy_execscsicmd_out_func, dummy_execscsicmd_in_func, dummy_execscsicmd_direct_func, dummy_pause_func, dummy_stop_func, - dummy_play_func, dummy_volume_func, dummy_qcode_func, dummy_toc_func, dummy_read_func, - dummy_rawread_func, dummy_write_func, dummy_isatapi_func, dummy_ismedia_func, dummy_scsiemu_func -}; - -struct device_functions devicefunc_scsi_spti = { - _T("IOCTL"), - dummy_open_bus_func, dummy_close_bus_func, dummy_open_device_func, dummy_close_device_func, dummy_info_device_func, - dummy_execscsicmd_out_func, dummy_execscsicmd_in_func, dummy_execscsicmd_direct_func, dummy_pause_func, dummy_stop_func, - dummy_play_func, dummy_volume_func, dummy_qcode_func, dummy_toc_func, dummy_read_func, - dummy_rawread_func, dummy_write_func, dummy_isatapi_func, dummy_ismedia_func, dummy_scsiemu_func -}; - -const TCHAR* specialmonitorconfignames[] = { - _T("none"), - NULL -}; +struct device_functions devicefunc_cdimage = {_T("DummyDevice"), + dummy_open_bus_func, + dummy_close_bus_func, + dummy_open_device_func, + dummy_close_device_func, + dummy_info_device_func, + dummy_execscsicmd_out_func, + dummy_execscsicmd_in_func, + dummy_execscsicmd_direct_func, + dummy_pause_func, + dummy_stop_func, + dummy_play_func, + dummy_volume_func, + dummy_qcode_func, + dummy_toc_func, + dummy_read_func, + dummy_rawread_func, + dummy_write_func, + dummy_isatapi_func, + dummy_ismedia_func, + dummy_scsiemu_func}; + +struct device_functions devicefunc_scsi_ioctl = {_T("IOCTL"), + dummy_open_bus_func, + dummy_close_bus_func, + dummy_open_device_func, + dummy_close_device_func, + dummy_info_device_func, + dummy_execscsicmd_out_func, + dummy_execscsicmd_in_func, + dummy_execscsicmd_direct_func, + dummy_pause_func, + dummy_stop_func, + dummy_play_func, + dummy_volume_func, + dummy_qcode_func, + dummy_toc_func, + dummy_read_func, + dummy_rawread_func, + dummy_write_func, + dummy_isatapi_func, + dummy_ismedia_func, + dummy_scsiemu_func}; + +struct device_functions devicefunc_scsi_spti = {_T("IOCTL"), + dummy_open_bus_func, + dummy_close_bus_func, + dummy_open_device_func, + dummy_close_device_func, + dummy_info_device_func, + dummy_execscsicmd_out_func, + dummy_execscsicmd_in_func, + dummy_execscsicmd_direct_func, + dummy_pause_func, + dummy_stop_func, + dummy_play_func, + dummy_volume_func, + dummy_qcode_func, + dummy_toc_func, + dummy_read_func, + dummy_rawread_func, + dummy_write_func, + dummy_isatapi_func, + dummy_ismedia_func, + dummy_scsiemu_func}; + +const TCHAR* specialmonitorconfignames[] = {_T("none"), NULL}; TCHAR avioutput_filename_gui[MAX_DPATH]; void* pushall_call_handler = nullptr; - #ifdef _WIN32 -void gettimeofday (struct timeval *tv, void *blah) -{ +void gettimeofday(struct timeval* tv, void* blah) { #if 1 - struct timeb time; + struct timeb time; - ftime (&time); + ftime(&time); - tv->tv_sec = (long)time.time; - tv->tv_usec = time.millitm * 1000; + tv->tv_sec = (long)time.time; + tv->tv_usec = time.millitm * 1000; #else - SYSTEMTIME st; - FILETIME ft; - uae_u64 v, sec; - GetSystemTime (&st); - SystemTimeToFileTime (&st, &ft); - v = (ft.dwHighDateTime << 32) | ft.dwLowDateTime; - v /= 10; - sec = v / 1000000; - tv->tv_usec = (unsigned long)(v - (sec * 1000000)); - tv->tv_sec = (unsigned long)(sec - 11644463600); + SYSTEMTIME st; + FILETIME ft; + uae_u64 v, sec; + GetSystemTime(&st); + SystemTimeToFileTime(&st, &ft); + v = (ft.dwHighDateTime << 32) | ft.dwLowDateTime; + v /= 10; + sec = v / 1000000; + tv->tv_usec = (unsigned long)(v - (sec * 1000000)); + tv->tv_sec = (unsigned long)(sec - 11644463600); #endif } #endif @@ -2279,67 +2291,64 @@ void update_memdump(uae_u32) { } // dummy write_log -void write_log (const char *format, ...) -{ - va_list parms; +void write_log(const char* format, ...) { + va_list parms; - va_start (parms, format); - vprintf (format, parms); - va_end (parms); + va_start(parms, format); + vprintf(format, parms); + va_end(parms); } // dummy write_log void write_dlog(const char* format, ...) { - va_list parms; + va_list parms; - va_start (parms, format); - vprintf (format, parms); - va_end (parms); + va_start(parms, format); + vprintf(format, parms); + va_end(parms); } -void console_out_f (const TCHAR * format, ...) -{ - va_list parms; +void console_out_f(const TCHAR* format, ...) { + va_list parms; - va_start (parms, format); - vprintf (format, parms); - va_end (parms); + va_start(parms, format); + vprintf(format, parms); + va_end(parms); } -void console_out (const TCHAR *txt) -{ - console_out_f("%s", txt); +void console_out(const TCHAR* txt) { + console_out_f("%s", txt); } -TCHAR *buf_out(TCHAR *buffer, int *bufsize, const TCHAR *format, ...) -{ - int count; - va_list parms; - va_start (parms, format); +TCHAR* buf_out(TCHAR* buffer, int* bufsize, const TCHAR* format, ...) { + int count; + va_list parms; + va_start(parms, format); - if (buffer == NULL) - return 0; - count = _vsntprintf(buffer, (*bufsize) - 1, format, parms); - va_end (parms); - *bufsize -= uaetcslen(buffer); - return buffer + uaetcslen(buffer); + if (buffer == NULL) + return 0; + count = _vsntprintf(buffer, (*bufsize) - 1, format, parms); + va_end(parms); + *bufsize -= uaetcslen(buffer); + return buffer + uaetcslen(buffer); } -static TCHAR *console_buffer; +static TCHAR* console_buffer; static int console_buffer_size; TCHAR* setconsolemode(TCHAR* buffer, int maxlen) { - TCHAR *ret = NULL; - if (buffer) { - console_buffer = buffer; - console_buffer_size = maxlen; - } else { - ret = console_buffer; - console_buffer = NULL; - } - return ret; + TCHAR* ret = NULL; + if (buffer) { + console_buffer = buffer; + console_buffer_size = maxlen; + } else { + ret = console_buffer; + console_buffer = NULL; + } + return ret; } // dummy win support for blkdev.cpp -int GetDriveType(TCHAR* vol) { return 0;} - +int GetDriveType(TCHAR* vol) { + return 0; +} diff --git a/src/file_system.cpp b/src/file_system.cpp index 1abbad04d..90c3849d5 100644 --- a/src/file_system.cpp +++ b/src/file_system.cpp @@ -8,30 +8,29 @@ int pause_emulation = 0; int my_existsdir(const TCHAR* directoryPath) { struct stat st; - + if (stat(directoryPath, &st) == 0) { if (S_ISDIR(st.st_mode)) { return 1; - } - } + } + } - return 0; + return 0; } #ifdef _WIN32 #include -int my_existsfile (const TCHAR *name) -{ - DWORD attr; - - attr = GetFileAttributes (name); - if (attr == INVALID_FILE_ATTRIBUTES) - return 0; - if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) - return 1; - return 0; +int my_existsfile(const TCHAR* name) { + DWORD attr; + + attr = GetFileAttributes(name); + if (attr == INVALID_FILE_ATTRIBUTES) + return 0; + if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) + return 1; + return 0; } #else @@ -50,58 +49,56 @@ int isprinter() { return 0; } -void to_lower(TCHAR *s, int len) { +void to_lower(TCHAR* s, int len) { for (int i = 0; i < len; i++) { s[i] = tolower(s[i]); } } - -TCHAR* utf8u (const char *s) -{ - if (s == NULL) return NULL; - return ua (s); +TCHAR* utf8u(const char* s) { + if (s == NULL) + return NULL; + return ua(s); } -char* uutf8 (const TCHAR *s) -{ - if (s == NULL) return NULL; - return ua (s); +char* uutf8(const TCHAR* s) { + if (s == NULL) + return NULL; + return ua(s); } /* TCHAR *au_copy (TCHAR *dst, int maxlen, const char *src) { - // this should match the WinUAE au_copy behavior, where either the - // entire string is copied (and null-terminated), or the result is - // an empty string - if (uae_tcslcpy (dst, src, maxlen) >= maxlen) { - dst[0] = '\0'; - } - return dst; + // this should match the WinUAE au_copy behavior, where either the + // entire string is copied (and null-terminated), or the result is + // an empty string + if (uae_tcslcpy (dst, src, maxlen) >= maxlen) { + dst[0] = '\0'; + } + return dst; } char *ua_copy (char *dst, int maxlen, const TCHAR *src) { - return au_copy (dst, maxlen, src); + return au_copy (dst, maxlen, src); } */ -TCHAR *my_strdup_ansi (const char *src) -{ - return strdup (src); +TCHAR* my_strdup_ansi(const char* src) { + return strdup(src); } #define NO_TRANSLATION -TCHAR *au_fs (const char *src) { +TCHAR* au_fs(const char* src) { #ifdef NO_TRANSLATION - if (src == NULL) return NULL; + if (src == NULL) + return NULL; return strdup(src); #else gsize read, written; - gchar *result = g_convert(src, -1, "UTF-8", - "ISO-8859-1", &read, &written, NULL); + gchar* result = g_convert(src, -1, "UTF-8", "ISO-8859-1", &read, &written, NULL); if (result == NULL) { write_log("WARNING: au_fs_copy failed to convert string %s", src); return strdup(""); @@ -110,9 +107,10 @@ TCHAR *au_fs (const char *src) { #endif } -char *ua_fs (const TCHAR *s, int defchar) { +char* ua_fs(const TCHAR* s, int defchar) { #ifdef NO_TRANSLATION - if (s == NULL) return NULL; + if (s == NULL) + return NULL; return strdup(s); #else // we convert from fs-uae's internal encoding (UTF-8) to latin-1 here, @@ -124,29 +122,27 @@ char *ua_fs (const TCHAR *s, int defchar) { } gsize read, written; - gchar *result = g_convert_with_fallback(s, -1, "ISO-8859-1", - "UTF-8", def, &read, &written, NULL); + gchar* result = g_convert_with_fallback(s, -1, "ISO-8859-1", "UTF-8", def, &read, &written, NULL); if (result == NULL) { write_log("WARNING: ua_fs failed to convert string %s", s); return strdup(""); } // duplicate with libc malloc - char *result_malloced = strdup(result); + char* result_malloced = strdup(result); free(result); return result_malloced; #endif } -TCHAR *au_fs_copy (TCHAR *dst, int maxlen, const char *src) { +TCHAR* au_fs_copy(TCHAR* dst, int maxlen, const char* src) { #ifdef NO_TRANSLATION dst[0] = 0; strncpy(dst, src, maxlen); return dst; #else gsize read, written; - gchar *result = g_convert(src, -1, "UTF-8", - "ISO-8859-1", &read, &written, NULL); + gchar* result = g_convert(src, -1, "UTF-8", "ISO-8859-1", &read, &written, NULL); if (result == NULL) { write_log("WARNING: au_fs_copy failed to convert string %s", src); dst[0] = '\0'; @@ -159,7 +155,7 @@ TCHAR *au_fs_copy (TCHAR *dst, int maxlen, const char *src) { #endif } -char *ua_fs_copy (char *dst, int maxlen, const TCHAR *src, int defchar) { +char* ua_fs_copy(char* dst, int maxlen, const TCHAR* src, int defchar) { #ifdef NO_TRANSLATION dst[0] = 0; strncpy(dst, src, maxlen); @@ -171,8 +167,7 @@ char *ua_fs_copy (char *dst, int maxlen, const TCHAR *src, int defchar) { } gsize read, written; - gchar *result = g_convert_with_fallback(src, -1, "ISO-8859-1", - "UTF-8", def, &read, &written, NULL); + gchar* result = g_convert_with_fallback(src, -1, "ISO-8859-1", "UTF-8", def, &read, &written, NULL); if (result == NULL) { write_log("WARNING: ua_fs_copy failed to convert string %s", src); dst[0] = '\0'; @@ -185,20 +180,19 @@ char *ua_fs_copy (char *dst, int maxlen, const TCHAR *src, int defchar) { #endif } - TCHAR* target_expand_environment(const TCHAR* path, TCHAR* out, int maxlen) { - if (!path) - return NULL; - if (out == NULL) { - return strdup(path); - } else { - _tcscpy(out, path); - return out; - } + if (!path) + return NULL; + if (out == NULL) { + return strdup(path); + } else { + _tcscpy(out, path); + return out; + } } -bool my_stat (const TCHAR* name, struct mystat* ms) { - //UNIMPLEMENTED(); +bool my_stat(const TCHAR* name, struct mystat* ms) { + // UNIMPLEMENTED(); return true; } @@ -230,10 +224,9 @@ int hdf_write_target(struct hardfiledata* hfd, void* buffer, uae_u64 offset, int struct my_opendir_s* my_opendir(const TCHAR* name) { UNIMPLEMENTED(); - return nullptr; + return nullptr; } - struct a_inode_struct; int fsdb_set_file_attrs(a_inode_struct* aino) { @@ -250,8 +243,3 @@ void fetch_configurationpath(TCHAR* out, int size) { out[1] = _T('.'); out[2] = 0; } - - - - - diff --git a/src/filepaths.cpp b/src/filepaths.cpp index d3807e815..604848d9b 100644 --- a/src/filepaths.cpp +++ b/src/filepaths.cpp @@ -4,14 +4,12 @@ int relativepaths = 0; // convert path to absolute or relative -void fullpath(TCHAR *path, int size, bool userelative) -{ - // FIXME: forward/backslash fix needed - if (path[0] == 0 || (path[0] == '\\' && path[1] == '\\') || - path[0] == ':') { - return; - } - /* : is supposed to mean same as :\ */ +void fullpath(TCHAR* path, int size, bool userelative) { + // FIXME: forward/backslash fix needed + if (path[0] == 0 || (path[0] == '\\' && path[1] == '\\') || path[0] == ':') { + return; + } + /* : is supposed to mean same as :\ */ #if 0 if (path[0] == 0 || (path[0] == '\\' && path[1] == '\\') || path[0] == ':') return; @@ -69,8 +67,6 @@ done:; } // convert path to absolute or relative -void fullpath (TCHAR *path, int size) -{ - fullpath(path, size, relativepaths); +void fullpath(TCHAR* path, int size) { + fullpath(path, size, relativepaths); } - diff --git a/src/gfx.cpp b/src/gfx.cpp index 0969fb71f..169183a5e 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1,12 +1,15 @@ -#include -#include #include +#include +#include #include + +// clang-format off #include "sysconfig.h" #include "sysdeps.h" #include "options.h" #include "inputdevice.h" #include "uae/slirp.h" +// clang-format on // needed by custom.cpp int vsync_activeheight, vsync_totalheight; @@ -27,14 +30,15 @@ int target_get_display_scanline(int displayindex) { return 0; } -void target_spin(int cycles) { } +void target_spin(int cycles) { +} -void gui_message(const char *format, ...) { - va_list parms; +void gui_message(const char* format, ...) { + va_list parms; - va_start (parms, format); - vprintf (format, parms); - va_end (parms); + va_start(parms, format); + vprintf(format, parms); + va_end(parms); } int lockscr() { @@ -50,4 +54,3 @@ int lockscr(struct vidbuffer*, bool, bool, bool) { TRACE(); return 1; } - diff --git a/src/gui.cpp b/src/gui.cpp index 16cf55670..0d66f0b17 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -1,67 +1,53 @@ #include "gui.h" -#include "threaddep/thread.h" #include +#include "threaddep/thread.h" -int gui_init (void) { +int gui_init(void) { return 0; } -int gui_update (void) { +int gui_update(void) { return 0; } -void gui_exit (void) { - +void gui_exit(void) { } -void gui_led (int, int, int) { - +void gui_led(int, int, int) { } -void gui_handle_events (void) { - +void gui_handle_events(void) { } -void gui_filename (int, const TCHAR *) { - +void gui_filename(int, const TCHAR*) { } -void gui_fps (int fps, int idle, int color) { - +void gui_fps(int fps, int idle, int color) { } -void gui_changesettings (void) { - +void gui_changesettings(void) { } -void gui_lock (void) { - +void gui_lock(void) { } -void gui_unlock (void) { - +void gui_unlock(void) { } -void gui_flicker_led (int, int, int) { - +void gui_flicker_led(int, int, int) { } -void gui_disk_image_change (int, const TCHAR *, bool writeprotected) { - +void gui_disk_image_change(int, const TCHAR*, bool writeprotected) { } -void gui_display (int shortcut) { - +void gui_display(int shortcut) { } -void gui_gameport_button_change (int port, int button, int onoff) { - +void gui_gameport_button_change(int port, int button, int onoff) { } -void gui_gameport_axis_change (int port, int axis, int state, int max) { - +void gui_gameport_axis_change(int port, int axis, int state, int max) { } -void notify_user (int msg) { +void notify_user(int msg) { printf("notify_user: %d\n", msg); } - diff --git a/src/hardfile_host.cpp b/src/hardfile_host.cpp index d4984a09e..daf829be1 100644 --- a/src/hardfile_host.cpp +++ b/src/hardfile_host.cpp @@ -1,50 +1,56 @@ /** - * UAE - The Un*x Amiga Emulator - * - * Hardfile emulation for *nix systems - * - * Copyright 2003-2006 Richard Drummond - * Copyright 2008-2010 Mustafa TUFAN - * Based on hardfile_win32.c - */ + * UAE - The Un*x Amiga Emulator + * + * Hardfile emulation for *nix systems + * + * Copyright 2003-2006 Richard Drummond + * Copyright 2008-2010 Mustafa TUFAN + * Based on hardfile_win32.c + */ #include "sysconfig.h" #include "sysdeps.h" +// clang-format off #include "options.h" #include "filesys.h" #include "zfile.h" #include "uae/io.h" #include "uae/log.h" +// clang-format on #ifdef MACOSX -#include #include +#include #endif #ifdef OPENBSD -#include +#include #include #include #include -#include +#include #endif #define hfd_log write_log static int g_debug = 0; -//#define HDF_DEBUG -#ifdef HDF_DEBUG -#define DEBUG_LOG write_log ( "%s: ", __func__); write_log +// #define HDF_DEBUG +#ifdef HDF_DEBUG +#define DEBUG_LOG \ + write_log("%s: ", __func__); \ + write_log #else -#define DEBUG_LOG(...) do ; while(0) +#define DEBUG_LOG(...) \ + do \ + ; \ + while (0) #endif -struct hardfilehandle -{ +struct hardfilehandle { int zfile; - struct zfile *zf; - FILE *h; + struct zfile* zf; + FILE* h; }; struct uae_driveinfo { @@ -73,67 +79,64 @@ struct uae_driveinfo { #define CACHE_FLUSH_TIME 5 /* safety check: only accept drives that: -* - contain RDSK in block 0 -* - block 0 is zeroed -*/ + * - contain RDSK in block 0 + * - block 0 is zeroed + */ int harddrive_dangerous, do_rdbdump; static struct uae_driveinfo uae_drives[MAX_FILESYSTEM_UNITS]; -static void rdbdump (FILE *h, uae_u64 offset, uae_u8 *buf, int blocksize) -{ +static void rdbdump(FILE* h, uae_u64 offset, uae_u8* buf, int blocksize) { static int cnt = 1; int i, blocks; char name[100]; - FILE *f; + FILE* f; blocks = (buf[132] << 24) | (buf[133] << 16) | (buf[134] << 8) | (buf[135] << 0); if (blocks < 0 || blocks > 100000) return; - _stprintf (name, "rdb_dump_%d.rdb", cnt); - f = uae_tfopen (name, "wb"); + _stprintf(name, "rdb_dump_%d.rdb", cnt); + f = uae_tfopen(name, "wb"); if (!f) return; for (i = 0; i <= blocks; i++) { - if (fseeko64 (h, offset, SEEK_SET) != 0) + if (fseeko64(h, offset, SEEK_SET) != 0) break; - int outlen = fread (buf, 1, blocksize, h); + int outlen = fread(buf, 1, blocksize, h); if (outlen != blocksize) { - write_log("rdbdump: warning: read %d bytes (not blocksize %d)\n", - outlen, blocksize); + write_log("rdbdump: warning: read %d bytes (not blocksize %d)\n", outlen, blocksize); } - fwrite (buf, 1, blocksize, f); + fwrite(buf, 1, blocksize, f); offset += blocksize; } - fclose (f); + fclose(f); cnt++; } -//static int ismounted (int hd) -//FIXME: -static int ismounted (FILE* f) { +// static int ismounted (int hd) +// FIXME: +static int ismounted(FILE* f) { STUB(""); int mounted; - //mounted = 1; + // mounted = 1; mounted = 0; return mounted; } #define CA "Commodore\0Amiga\0" -static int safetycheck (FILE *h, const char *name, uae_u64 offset, uae_u8 *buf, int blocksize) -{ +static int safetycheck(FILE* h, const char* name, uae_u64 offset, uae_u8* buf, int blocksize) { int i, j, blocks = 63, empty = 1; long outlen; for (j = 0; j < blocks; j++) { - if (fseeko64 (h, offset, SEEK_SET) != 0) { - write_log ("hd ignored, SetFilePointer failed, error %d\n", errno); + if (fseeko64(h, offset, SEEK_SET) != 0) { + write_log("hd ignored, SetFilePointer failed, error %d\n", errno); return 1; } - memset (buf, 0xaa, blocksize); - outlen = fread (buf, 1, blocksize, h); + memset(buf, 0xaa, blocksize); + outlen = fread(buf, 1, blocksize, h); if (outlen != blocksize) { - write_log ("hd ignored, read error %d!\n", errno); + write_log("hd ignored, read error %d!\n", errno); return 2; } if (j == 0 && offset > 0) @@ -141,19 +144,19 @@ static int safetycheck (FILE *h, const char *name, uae_u64 offset, uae_u8 *buf, if (j == 0 && buf[0] == 0x39 && buf[1] == 0x10 && buf[2] == 0xd3 && buf[3] == 0x12) { // ADIDE "CPRM" hidden block.. if (do_rdbdump) - rdbdump (h, offset, buf, blocksize); - write_log ("hd accepted (adide rdb detected at block %d)\n", j); + rdbdump(h, offset, buf, blocksize); + write_log("hd accepted (adide rdb detected at block %d)\n", j); return -3; } - if (!memcmp (buf, "RDSK", 4) || !memcmp (buf, "DRKS", 4)) { + if (!memcmp(buf, "RDSK", 4) || !memcmp(buf, "DRKS", 4)) { if (do_rdbdump) - rdbdump (h, offset, buf, blocksize); - write_log ("hd accepted (rdb detected at block %d)\n", j); + rdbdump(h, offset, buf, blocksize); + write_log("hd accepted (rdb detected at block %d)\n", j); return -1; } - if (!memcmp (buf + 2, "CIS@", 4) && !memcmp (buf + 16, CA, strlen (CA))) { - write_log ("hd accepted (PCMCIA RAM)\n"); + if (!memcmp(buf + 2, "CIS@", 4) && !memcmp(buf + 16, CA, strlen(CA))) { + write_log("hd accepted (PCMCIA RAM)\n"); return -2; } if (j == 0) { @@ -166,21 +169,21 @@ static int safetycheck (FILE *h, const char *name, uae_u64 offset, uae_u8 *buf, } if (!empty) { int mounted; - mounted = ismounted (h); + mounted = ismounted(h); if (!mounted) { - write_log ("hd accepted, not empty and not mounted in Windows\n"); + write_log("hd accepted, not empty and not mounted in Windows\n"); return -8; } if (mounted < 0) { - write_log ("hd ignored, NTFS partitions\n"); + write_log("hd ignored, NTFS partitions\n"); return 0; } if (harddrive_dangerous == 0x1234dead) return -6; - write_log ("hd ignored, not empty and no RDB detected or Windows mounted\n"); + write_log("hd ignored, not empty and no RDB detected or Windows mounted\n"); return 0; } - write_log ("hd accepted (empty)\n"); + write_log("hd accepted (empty)\n"); return -9; } @@ -193,25 +196,23 @@ static void trim (TCHAR *s) } */ -static int isharddrive (const TCHAR *name) -{ +static int isharddrive(const TCHAR* name) { int i; - for (i = 0; i < hdf_getnumharddrives (); i++) { - if (!_tcscmp (uae_drives[i].device_name, name)) + for (i = 0; i < hdf_getnumharddrives(); i++) { + if (!_tcscmp(uae_drives[i].device_name, name)) return i; } return -1; } -static const char *hdz[] = { "hdz", "zip", "rar", "7z", NULL }; +static const char* hdz[] = {"hdz", "zip", "rar", "7z", NULL}; -int hdf_open_target (struct hardfiledata *hfd, const char *pname) -{ - FILE *h = INVALID_HANDLE_VALUE; +int hdf_open_target(struct hardfiledata* hfd, const char* pname) { + FILE* h = INVALID_HANDLE_VALUE; int i; - struct uae_driveinfo *udi; - char *name = strdup (pname); + struct uae_driveinfo* udi; + char* name = strdup(pname); if (getenv("FS_DEBUG_HDF")) { g_debug = 1; @@ -222,21 +223,21 @@ int hdf_open_target (struct hardfiledata *hfd, const char *pname) hfd->flags = 0; hfd->drive_empty = 0; - hdf_close (hfd); - hfd->cache = (uae_u8*)xmalloc (uae_u8, CACHE_SIZE); + hdf_close(hfd); + hfd->cache = (uae_u8*)xmalloc(uae_u8, CACHE_SIZE); hfd->cache_valid = 0; hfd->virtual_size = 0; hfd->virtual_rdb = NULL; if (!hfd->cache) { - write_log ("VirtualAlloc(%d) failed, error %d\n", CACHE_SIZE, errno); + write_log("VirtualAlloc(%d) failed, error %d\n", CACHE_SIZE, errno); goto end; } - hfd->handle = xcalloc (struct hardfilehandle, 1); + hfd->handle = xcalloc(struct hardfilehandle, 1); hfd->handle->h = INVALID_HANDLE_VALUE; - hfd_log ("hfd open: '%s'\n", name); - if (_tcslen (name) > 4 && !_tcsncmp (name,"HD_", 3)) { - hdf_init_target (); - i = isharddrive (name); + hfd_log("hfd open: '%s'\n", name); + if (_tcslen(name) > 4 && !_tcsncmp(name, "HD_", 3)) { + hdf_init_target(); + i = isharddrive(name); if (i >= 0) { udi = &uae_drives[i]; hfd->flags = HFD_FLAGS_REALDRIVE; @@ -244,58 +245,58 @@ int hdf_open_target (struct hardfiledata *hfd, const char *pname) hfd->drive_empty = -1; if (udi->readonly) hfd->ci.readonly = 1; - h = uae_tfopen (udi->device_path, hfd->ci.readonly ? "rb" : "r+b"); + h = uae_tfopen(udi->device_path, hfd->ci.readonly ? "rb" : "r+b"); hfd->handle->h = h; if (h == INVALID_HANDLE_VALUE) goto end; - _tcsncpy (hfd->vendor_id, udi->vendor_id, 8); - _tcsncpy (hfd->product_id, udi->product_id, 16); - _tcsncpy (hfd->product_rev, udi->product_rev, 4); + _tcsncpy(hfd->vendor_id, udi->vendor_id, 8); + _tcsncpy(hfd->product_id, udi->product_id, 16); + _tcsncpy(hfd->product_rev, udi->product_rev, 4); hfd->offset = udi->offset; hfd->physsize = hfd->virtsize = udi->size; hfd->ci.blocksize = udi->bytespersector; if (hfd->offset == 0 && !hfd->drive_empty) { - int sf = safetycheck (hfd->handle->h, udi->device_path, 0, hfd->cache, hfd->ci.blocksize); + int sf = safetycheck(hfd->handle->h, udi->device_path, 0, hfd->cache, hfd->ci.blocksize); if (sf > 0) goto end; if (sf == 0 && !hfd->ci.readonly && harddrive_dangerous != 0x1234dead) { - write_log ("'%s' forced read-only, safetycheck enabled\n", udi->device_path); + write_log("'%s' forced read-only, safetycheck enabled\n", udi->device_path); hfd->dangerous = 1; // clear GENERIC_WRITE - fclose (h); - h = uae_tfopen (udi->device_path, "r+b"); + fclose(h); + h = uae_tfopen(udi->device_path, "r+b"); hfd->handle->h = h; if (h == INVALID_HANDLE_VALUE) goto end; } } hfd->handle_valid = HDF_HANDLE_LINUX; - hfd->emptyname = strdup (name); + hfd->emptyname = strdup(name); } else { hfd->flags = HFD_FLAGS_REALDRIVE; hfd->drive_empty = -1; - hfd->emptyname = strdup (name); + hfd->emptyname = strdup(name); } } else { int zmode = 0; - char *ext = _tcsrchr (name, '.'); + char* ext = _tcsrchr(name, '.'); if (ext != NULL) { ext++; for (i = 0; hdz[i]; i++) { - if (!_tcsicmp (ext, hdz[i])) + if (!_tcsicmp(ext, hdz[i])) zmode = 1; } } - h = uae_tfopen (name, hfd->ci.readonly ? "rb" : "r+b"); + h = uae_tfopen(name, hfd->ci.readonly ? "rb" : "r+b"); if (h == INVALID_HANDLE_VALUE) goto end; hfd->handle->h = h; - i = _tcslen (name) - 1; + i = _tcslen(name) - 1; while (i >= 0) { if ((i > 0 && (name[i - 1] == '/' || name[i - 1] == '\\')) || i == 0) { - _tcscpy (hfd->vendor_id, "UAE"); - _tcsncpy (hfd->product_id, name + i, 15); - _tcscpy (hfd->product_rev, "0.3"); + _tcscpy(hfd->vendor_id, "UAE"); + _tcsncpy(hfd->product_id, name + i, 15); + _tcscpy(hfd->product_rev, "0.3"); break; } i--; @@ -308,7 +309,7 @@ int hdf_open_target (struct hardfiledata *hfd, const char *pname) #if defined(MACOSX) || defined(OPENBSD) // check type of file struct stat st; - ret = stat(name,&st); + ret = stat(name, &st); if (ret) { write_log("osx: can't stat '%s'\n", name); goto end; @@ -322,19 +323,19 @@ int hdf_open_target (struct hardfiledata *hfd, const char *pname) // get number of blocks ret = ioctl(fh, DKIOCGETBLOCKCOUNT, &block_count); if (ret) { - write_log("osx: can't get block count of '%s' (%d)\n", - name, fh); + write_log("osx: can't get block count of '%s' (%d)\n", name, fh); goto end; } // get block size ret = ioctl(fh, DKIOCGETBLOCKSIZE, &block_size); if (ret) { - write_log("osx: can't get block size of '%s' (%d)\n", - name, fh); + write_log("osx: can't get block size of '%s' (%d)\n", name, fh); goto end; } - write_log("osx: found raw device: block_size=%u " - "block_count=%llu\n", block_size, block_count); + write_log( + "osx: found raw device: block_size=%u " + "block_count=%llu\n", + block_size, block_count); low = block_size * block_count; #elif defined(OPENBSD) struct disklabel label; @@ -348,14 +349,14 @@ int hdf_open_target (struct hardfiledata *hfd, const char *pname) write_log("openbsd: total bytes: %llu\n", low); #endif } -#endif // OPENBSD || MACOSX +#endif // OPENBSD || MACOSX if (low == -1) { // assuming regular file; seek to end and ftell - ret = fseeko64 (h, 0, SEEK_END); + ret = fseeko64(h, 0, SEEK_END); if (ret) goto end; - low = ftello64 (h); + low = ftello64(h); if (low == -1) goto end; } @@ -363,39 +364,37 @@ int hdf_open_target (struct hardfiledata *hfd, const char *pname) low &= ~(hfd->ci.blocksize - 1); hfd->physsize = hfd->virtsize = low; if (g_debug) { - write_log("set physsize = virtsize = %lld (low)\n", - hfd->virtsize); + write_log("set physsize = virtsize = %lld (low)\n", hfd->virtsize); } hfd->handle_valid = HDF_HANDLE_LINUX; if (hfd->physsize < 64 * 1024 * 1024 && zmode) { - write_log ("HDF '%s' re-opened in zfile-mode\n", name); - fclose (h); + write_log("HDF '%s' re-opened in zfile-mode\n", name); + fclose(h); hfd->handle->h = INVALID_HANDLE_VALUE; hfd->handle->zf = zfile_fopen(name, hfd->ci.readonly ? "rb" : "r+b", ZFD_NORMAL); hfd->handle->zfile = 1; if (!h) goto end; - zfile_fseek (hfd->handle->zf, 0, SEEK_END); - hfd->physsize = hfd->virtsize = zfile_ftell (hfd->handle->zf); + zfile_fseek(hfd->handle->zf, 0, SEEK_END); + hfd->physsize = hfd->virtsize = zfile_ftell(hfd->handle->zf); if (g_debug) { - write_log("set physsize = virtsize = %lld\n", - hfd->virtsize); + write_log("set physsize = virtsize = %lld\n", hfd->virtsize); } - zfile_fseek (hfd->handle->zf, 0, SEEK_SET); + zfile_fseek(hfd->handle->zf, 0, SEEK_SET); hfd->handle_valid = HDF_HANDLE_ZFILE; } } else { - write_log ("HDF '%s' failed to open. error = %d\n", name, errno); + write_log("HDF '%s' failed to open. error = %d\n", name, errno); } } if (hfd->handle_valid || hfd->drive_empty) { - hfd_log ("HDF '%s' opened, size=%dK mode=%d empty=%d\n", - name, (int) (hfd->physsize / 1024), hfd->handle_valid, hfd->drive_empty); + hfd_log("HDF '%s' opened, size=%dK mode=%d empty=%d\n", name, (int)(hfd->physsize / 1024), hfd->handle_valid, + hfd->drive_empty); return 1; } end: - hdf_close (hfd); - xfree (name); + hdf_close(hfd); + xfree(name); return 0; } @@ -414,20 +413,20 @@ static void freehandle (struct hardfilehandle *h) } */ -void hdf_close_target (struct hardfiledata *hfd) { +void hdf_close_target(struct hardfiledata* hfd) { write_log("hdf_close_target\n"); if (hfd->handle && hfd->handle->h) { write_log("closing file handle %p\n", hfd->handle->h); fclose(hfd->handle->h); } - //freehandle (hfd->handle); - xfree (hfd->handle); - xfree (hfd->emptyname); + // freehandle (hfd->handle); + xfree(hfd->handle); + xfree(hfd->emptyname); hfd->emptyname = NULL; hfd->handle = NULL; hfd->handle_valid = 0; if (hfd->cache) - xfree (hfd->cache); + xfree(hfd->cache); xfree(hfd->virtual_rdb); hfd->virtual_rdb = 0; hfd->virtual_size = 0; @@ -437,79 +436,78 @@ void hdf_close_target (struct hardfiledata *hfd) { hfd->dangerous = 0; } -int hdf_dup_target (struct hardfiledata *dhfd, const struct hardfiledata *shfd) -{ +int hdf_dup_target(struct hardfiledata* dhfd, const struct hardfiledata* shfd) { if (!shfd->handle_valid) return 0; return 0; } -static int hdf_seek (struct hardfiledata *hfd, uae_u64 offset) -{ +static int hdf_seek(struct hardfiledata* hfd, uae_u64 offset) { size_t ret; if (hfd->handle_valid == 0) { - gui_message ("hd: hdf handle is not valid. bug."); + gui_message("hd: hdf handle is not valid. bug."); abort(); } if (offset >= hfd->physsize - hfd->virtual_size) { - gui_message ("hd: tried to seek out of bounds! (0x%llx >= 0x%llx)\n", offset, hfd->physsize); - abort (); + gui_message("hd: tried to seek out of bounds! (0x%llx >= 0x%llx)\n", offset, hfd->physsize); + abort(); } offset += hfd->offset; if (offset & (hfd->ci.blocksize - 1)) { - gui_message ("hd: poscheck failed, offset=0x%llx not aligned to blocksize=%d! (0x%llx & 0x%04.4x = 0x%04.4x)\n", - offset, hfd->ci.blocksize, offset, hfd->ci.blocksize, offset & (hfd->ci.blocksize - 1)); - abort (); + gui_message("hd: poscheck failed, offset=0x%llx not aligned to blocksize=%d! (0x%llx & 0x%04.4x = 0x%04.4x)\n", + offset, hfd->ci.blocksize, offset, hfd->ci.blocksize, offset & (hfd->ci.blocksize - 1)); + abort(); } if (hfd->handle_valid == HDF_HANDLE_LINUX) { - ret = fseeko64 (hfd->handle->h, offset, SEEK_SET); + ret = fseeko64(hfd->handle->h, offset, SEEK_SET); if (ret) { write_log("hdf_seek failed\n"); return -1; } } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { - zfile_fseek (hfd->handle->zf, (long)offset, SEEK_SET); + zfile_fseek(hfd->handle->zf, (long)offset, SEEK_SET); } return 0; } -static void poscheck (struct hardfiledata *hfd, int len) -{ +static void poscheck(struct hardfiledata* hfd, int len) { int ret; uae_u64 pos = 0; if (hfd->handle_valid == HDF_HANDLE_LINUX) { - ret = fseeko64 (hfd->handle->h, 0, SEEK_CUR); + ret = fseeko64(hfd->handle->h, 0, SEEK_CUR); if (ret) { - gui_message ("hd: poscheck failed. seek failure, ret %d", ret); - abort (); + gui_message("hd: poscheck failed. seek failure, ret %d", ret); + abort(); } - pos = ftello64 (hfd->handle->h); + pos = ftello64(hfd->handle->h); } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { - pos = zfile_ftell (hfd->handle->zf); + pos = zfile_ftell(hfd->handle->zf); } if (len < 0) { - gui_message ("hd: poscheck failed, negative length! (%d)", len); - abort (); + gui_message("hd: poscheck failed, negative length! (%d)", len); + abort(); } if (pos < hfd->offset) { - gui_message ("hd: poscheck failed, offset out of bounds! (0x%llx < 0x%llx)", pos, hfd->offset); - abort (); + gui_message("hd: poscheck failed, offset out of bounds! (0x%llx < 0x%llx)", pos, hfd->offset); + abort(); } - if (pos >= hfd->offset + hfd->physsize - hfd->virtual_size || pos >= hfd->offset + hfd->physsize + len - hfd->virtual_size) { - gui_message ("hd: poscheck failed, offset out of bounds! (0x%llx >= 0x%llx, LEN=%d)", pos, hfd->offset + hfd->physsize, len); - abort (); + if (pos >= hfd->offset + hfd->physsize - hfd->virtual_size || + pos >= hfd->offset + hfd->physsize + len - hfd->virtual_size) { + gui_message("hd: poscheck failed, offset out of bounds! (0x%llx >= 0x%llx, LEN=%d)", pos, + hfd->offset + hfd->physsize, len); + abort(); } if (pos & (hfd->ci.blocksize - 1)) { - gui_message ("hd: poscheck failed, offset not aligned to blocksize! (0x%llx & 0x%04.4x = 0x%04.4x\n", pos, hfd->ci.blocksize, pos & hfd->ci.blocksize); - abort (); + gui_message("hd: poscheck failed, offset not aligned to blocksize! (0x%llx & 0x%04.4x = 0x%04.4x\n", pos, + hfd->ci.blocksize, pos & hfd->ci.blocksize); + abort(); } } -static int isincache (struct hardfiledata *hfd, uae_u64 offset, int len) -{ +static int isincache(struct hardfiledata* hfd, uae_u64 offset, int len) { if (!hfd->cache_valid) return -1; if (offset >= hfd->cache_offset && offset + len <= hfd->cache_offset + CACHE_SIZE) @@ -533,46 +531,44 @@ void hfd_flush_cache (struct hardfiledata *hfd, int now) } #endif -static int hdf_read_2 (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) -{ +static int hdf_read_2(struct hardfiledata* hfd, void* buffer, uae_u64 offset, int len) { long outlen = 0; int coffset; if (offset == 0) hfd->cache_valid = 0; - coffset = isincache (hfd, offset, len); + coffset = isincache(hfd, offset, len); if (coffset >= 0) { - memcpy (buffer, hfd->cache + coffset, len); + memcpy(buffer, hfd->cache + coffset, len); return len; } hfd->cache_offset = offset; if (offset + CACHE_SIZE > hfd->offset + (hfd->physsize - hfd->virtual_size)) hfd->cache_offset = hfd->offset + (hfd->physsize - hfd->virtual_size) - CACHE_SIZE; - hdf_seek (hfd, hfd->cache_offset); - poscheck (hfd, CACHE_SIZE); + hdf_seek(hfd, hfd->cache_offset); + poscheck(hfd, CACHE_SIZE); if (hfd->handle_valid == HDF_HANDLE_LINUX) - outlen = fread (hfd->cache, 1, CACHE_SIZE, hfd->handle->h); + outlen = fread(hfd->cache, 1, CACHE_SIZE, hfd->handle->h); else if (hfd->handle_valid == HDF_HANDLE_ZFILE) - outlen = zfile_fread (hfd->cache, 1, CACHE_SIZE, hfd->handle->zf); + outlen = zfile_fread(hfd->cache, 1, CACHE_SIZE, hfd->handle->zf); hfd->cache_valid = 0; if (outlen != CACHE_SIZE) return 0; hfd->cache_valid = 1; - coffset = isincache (hfd, offset, len); + coffset = isincache(hfd, offset, len); if (coffset >= 0) { - memcpy (buffer, hfd->cache + coffset, len); + memcpy(buffer, hfd->cache + coffset, len); return len; } - write_log ("hdf_read: cache bug! offset=0x%llx len=%d\n", offset, len); + write_log("hdf_read: cache bug! offset=0x%llx len=%d\n", offset, len); hfd->cache_valid = 0; return 0; } // TODO: Implement error handling -int hdf_read_target (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len, uae_u32* error) -{ +int hdf_read_target(struct hardfiledata* hfd, void* buffer, uae_u64 offset, int len, uae_u32* error) { int got = 0; - uae_u8 *p = (uae_u8*)buffer; + uae_u8* p = (uae_u8*)buffer; if (hfd->drive_empty) return 0; @@ -581,18 +577,18 @@ int hdf_read_target (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int int ret = 0; if (hfd->physsize < CACHE_SIZE) { hfd->cache_valid = 0; - hdf_seek (hfd, offset); - poscheck (hfd, len); + hdf_seek(hfd, offset); + poscheck(hfd, len); if (hfd->handle_valid == HDF_HANDLE_LINUX) { - ret = fread (hfd->cache, 1, len, hfd->handle->h); - memcpy (buffer, hfd->cache, ret); + ret = fread(hfd->cache, 1, len, hfd->handle->h); + memcpy(buffer, hfd->cache, ret); } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { - ret = zfile_fread (buffer, 1, len, hfd->handle->zf); + ret = zfile_fread(buffer, 1, len, hfd->handle->zf); } maxlen = len; } else { maxlen = len > CACHE_SIZE ? CACHE_SIZE : len; - ret = hdf_read_2 (hfd, p, offset, maxlen); + ret = hdf_read_2(hfd, p, offset, maxlen); } got += ret; if (ret != maxlen) @@ -604,8 +600,7 @@ int hdf_read_target (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int return got; } -static int hdf_write_2 (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) -{ +static int hdf_write_2(struct hardfiledata* hfd, void* buffer, uae_u64 offset, int len) { int outlen = 0; if (hfd->ci.readonly) { @@ -621,44 +616,41 @@ static int hdf_write_2 (struct hardfiledata *hfd, void *buffer, uae_u64 offset, return 0; } hfd->cache_valid = 0; - hdf_seek (hfd, offset); - poscheck (hfd, len); - memcpy (hfd->cache, buffer, len); + hdf_seek(hfd, offset); + poscheck(hfd, len); + memcpy(hfd->cache, buffer, len); if (hfd->handle_valid == HDF_HANDLE_LINUX) { - outlen = fwrite (hfd->cache, 1, len, hfd->handle->h); - //fflush(hfd->handle->h); + outlen = fwrite(hfd->cache, 1, len, hfd->handle->h); + // fflush(hfd->handle->h); if (g_debug) { - write_log("wrote %u bytes (wanted %d) at offset %llx\n", outlen, - len, offset); + write_log("wrote %u bytes (wanted %d) at offset %llx\n", outlen, len, offset); } - const TCHAR *name = hfd->emptyname == NULL ? _T("") : hfd->emptyname; + const TCHAR* name = hfd->emptyname == NULL ? _T("") : hfd->emptyname; if (offset == 0) { long outlen2; - uae_u8 *tmp; + uae_u8* tmp; int tmplen = 512; - tmp = (uae_u8*)xmalloc (uae_u8, tmplen); + tmp = (uae_u8*)xmalloc(uae_u8, tmplen); if (tmp) { - memset (tmp, 0xa1, tmplen); - hdf_seek (hfd, offset); - outlen2 = fread (tmp, 1, tmplen, hfd->handle->h); - if (memcmp (hfd->cache, tmp, tmplen) != 0 || outlen != len) - gui_message (_T("\"%s\"\n\nblock zero write failed!"), name); - xfree (tmp); + memset(tmp, 0xa1, tmplen); + hdf_seek(hfd, offset); + outlen2 = fread(tmp, 1, tmplen, hfd->handle->h); + if (memcmp(hfd->cache, tmp, tmplen) != 0 || outlen != len) + gui_message(_T("\"%s\"\n\nblock zero write failed!"), name); + xfree(tmp); } } } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { - outlen = zfile_fwrite (hfd->cache, 1, len, hfd->handle->zf); + outlen = zfile_fwrite(hfd->cache, 1, len, hfd->handle->zf); } return outlen; } -int hdf_write_target (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) -{ +int hdf_write_target(struct hardfiledata* hfd, void* buffer, uae_u64 offset, int len) { int got = 0; - uae_u8 *p = (uae_u8*)buffer; + uae_u8* p = (uae_u8*)buffer; if (g_debug) { - write_log("hdf_write_target off %llx len %d virtual size %lld\n", - offset, len, hfd->virtual_size); + write_log("hdf_write_target off %llx len %d virtual size %lld\n", offset, len, hfd->virtual_size); } if (hfd->drive_empty) { if (g_debug) { @@ -668,7 +660,7 @@ int hdf_write_target (struct hardfiledata *hfd, void *buffer, uae_u64 offset, in } while (len > 0) { int maxlen = len > CACHE_SIZE ? CACHE_SIZE : len; - int ret = hdf_write_2 (hfd, p, offset, maxlen); + int ret = hdf_write_2(hfd, p, offset, maxlen); if (ret < 0) return ret; got += ret; @@ -681,8 +673,7 @@ int hdf_write_target (struct hardfiledata *hfd, void *buffer, uae_u64 offset, in return got; } -int hdf_resize_target(struct hardfiledata *hfd, uae_u64 newsize) -{ +int hdf_resize_target(struct hardfiledata* hfd, uae_u64 newsize) { if (newsize < hfd->physsize) { uae_log("hdf_resize_target: truncation not implemented\n"); return 0; @@ -697,8 +688,10 @@ int hdf_resize_target(struct hardfiledata *hfd, uae_u64 newsize) return 0; } if (fwrite("", 1, 1, hfd->handle->h) != 1) { - uae_log("hdf_resize_target: failed to write byte at position " - "%lld errno %d\n", newsize - 1, errno); + uae_log( + "hdf_resize_target: failed to write byte at position " + "%lld errno %d\n", + newsize - 1, errno); return 0; } uae_log("hdf_resize_target: %lld -> %lld\n", hfd->physsize, newsize); @@ -708,8 +701,7 @@ int hdf_resize_target(struct hardfiledata *hfd, uae_u64 newsize) static int num_drives; -static int hdf_init2 (int force) -{ +static int hdf_init2(int force) { static int done; if (done && !force) @@ -719,12 +711,11 @@ static int hdf_init2 (int force) return num_drives; } -int hdf_init_target (void) { - return hdf_init2 (0); +int hdf_init_target(void) { + return hdf_init2(0); } -int hdf_getnumharddrives (void) -{ +int hdf_getnumharddrives(void) { return num_drives; } diff --git a/src/input.cpp b/src/input.cpp index bb35b4455..4bae0576f 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1,39 +1,27 @@ -#include -#include #include +#include +#include #include +// clang-format off #include "sysconfig.h" #include "sysdeps.h" #include "options.h" #include "inputdevice.h" +// clang-format on static struct uae_input_device_kbr_default keytrans_amiga[] = { - { INPUTEVENT_KEY_CAPS_LOCK, { { INPUTEVENT_KEY_CAPS_LOCK, ID_FLAG_TOGGLE } } }, - { -1, { { 0 } } } -}; + {INPUTEVENT_KEY_CAPS_LOCK, {{INPUTEVENT_KEY_CAPS_LOCK, ID_FLAG_TOGGLE}}}, {-1, {{0}}}}; -static struct uae_input_device_kbr_default *keytrans[] = { - keytrans_amiga, - keytrans_amiga, - keytrans_amiga, +static struct uae_input_device_kbr_default* keytrans[] = { + keytrans_amiga, + keytrans_amiga, + keytrans_amiga, }; -static int kb_none[] = { -1 }; +static int kb_none[] = {-1}; -static int* kbmaps[] = { - kb_none, - kb_none, - kb_none, - kb_none, - kb_none, - kb_none, - kb_none, - kb_none, - kb_none, - kb_none -}; +static int* kbmaps[] = {kb_none, kb_none, kb_none, kb_none, kb_none, kb_none, kb_none, kb_none, kb_none, kb_none}; void keyboard_settrans() { - inputdevice_setkeytranslation(keytrans, kbmaps); + inputdevice_setkeytranslation(keytrans, kbmaps); } - diff --git a/src/machdep/m68k.cpp b/src/machdep/m68k.cpp index ecf0041b2..272435ff6 100644 --- a/src/machdep/m68k.cpp +++ b/src/machdep/m68k.cpp @@ -1,7 +1,8 @@ - +// clang-format off #include "sysconfig.h" #include "sysdeps.h" #include "m68k.h" +// clang-format on /* * Test CCR condition @@ -9,37 +10,56 @@ #ifndef SAHF_SETO_PROFITABLE -int cctrue(int cc) -{ +int cctrue(int cc) { uae_u32 cznv = (uae_u32)regflags.cznv; switch (cc) { - case 0: return 1; /* T */ - case 1: return 0; /* F */ - case 2: return (cznv & (FLAGVAL_C | FLAGVAL_Z)) == 0; /* !CFLG && !ZFLG HI */ - case 3: return (cznv & (FLAGVAL_C | FLAGVAL_Z)) != 0; /* CFLG || ZFLG LS */ - case 4: return (cznv & FLAGVAL_C) == 0; /* !CFLG CC */ - case 5: return (cznv & FLAGVAL_C) != 0; /* CFLG CS */ - case 6: return (cznv & FLAGVAL_Z) == 0; /* !ZFLG NE */ - case 7: return (cznv & FLAGVAL_Z) != 0; /* ZFLG EQ */ - case 8: return (cznv & FLAGVAL_V) == 0; /* !VFLG VC */ - case 9: return (cznv & FLAGVAL_V) != 0; /* VFLG VS */ - case 10: return (cznv & FLAGVAL_N) == 0; /* !NFLG PL */ - case 11: return (cznv & FLAGVAL_N) != 0; /* NFLG MI */ + case 0: + return 1; /* T */ + case 1: + return 0; /* F */ + case 2: + return (cznv & (FLAGVAL_C | FLAGVAL_Z)) == 0; /* !CFLG && !ZFLG HI */ + case 3: + return (cznv & (FLAGVAL_C | FLAGVAL_Z)) != 0; /* CFLG || ZFLG LS */ + case 4: + return (cznv & FLAGVAL_C) == 0; /* !CFLG CC */ + case 5: + return (cznv & FLAGVAL_C) != 0; /* CFLG CS */ + case 6: + return (cznv & FLAGVAL_Z) == 0; /* !ZFLG NE */ + case 7: + return (cznv & FLAGVAL_Z) != 0; /* ZFLG EQ */ + case 8: + return (cznv & FLAGVAL_V) == 0; /* !VFLG VC */ + case 9: + return (cznv & FLAGVAL_V) != 0; /* VFLG VS */ + case 10: + return (cznv & FLAGVAL_N) == 0; /* !NFLG PL */ + case 11: + return (cznv & FLAGVAL_N) != 0; /* NFLG MI */ #if FLAGBIT_N > FLAGBIT_V - case 12: return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & FLAGVAL_N) == 0; /* NFLG == VFLG GE */ - case 13: return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & FLAGVAL_N) != 0; /* NFLG != VFLG LT */ - case 14: cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* !ZFLG && (NFLG == VFLG) GT */ - return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & (FLAGVAL_N | FLAGVAL_Z)) == 0; - case 15: cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* ZFLG || (NFLG != VFLG) LE */ - return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & (FLAGVAL_N | FLAGVAL_Z)) != 0; + case 12: + return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & FLAGVAL_N) == 0; /* NFLG == VFLG GE */ + case 13: + return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & FLAGVAL_N) != 0; /* NFLG != VFLG LT */ + case 14: + cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* !ZFLG && (NFLG == VFLG) GT */ + return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & (FLAGVAL_N | FLAGVAL_Z)) == 0; + case 15: + cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* ZFLG || (NFLG != VFLG) LE */ + return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & (FLAGVAL_N | FLAGVAL_Z)) != 0; #else - case 12: return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & FLAGVAL_V) == 0; /* NFLG == VFLG GE */ - case 13: return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & FLAGVAL_V) != 0; /* NFLG != VFLG LT */ - case 14: cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* !ZFLG && (NFLG == VFLG) GT */ - return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & (FLAGVAL_V | FLAGVAL_Z)) == 0; - case 15: cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* ZFLG || (NFLG != VFLG) LE */ - return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & (FLAGVAL_V | FLAGVAL_Z)) != 0; + case 12: + return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & FLAGVAL_V) == 0; /* NFLG == VFLG GE */ + case 13: + return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & FLAGVAL_V) != 0; /* NFLG != VFLG LT */ + case 14: + cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* !ZFLG && (NFLG == VFLG) GT */ + return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & (FLAGVAL_V | FLAGVAL_Z)) == 0; + case 15: + cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* ZFLG || (NFLG != VFLG) LE */ + return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & (FLAGVAL_V | FLAGVAL_Z)) != 0; #endif } return 0; @@ -47,37 +67,56 @@ int cctrue(int cc) #else /* !SAHF_SETO_PROFITABLE */ -int cctrue(int cc) -{ +int cctrue(int cc) { uae_u32 cznv = regflags.cznv; switch (cc) { - case 0: return 1; /* T */ - case 1: return 0; /* F */ - case 2: return (cznv & (FLAGVAL_C | FLAGVAL_Z)) == 0; /* !CFLG && !ZFLG HI */ - case 3: return (cznv & (FLAGVAL_C | FLAGVAL_Z)) != 0; /* CFLG || ZFLG LS */ - case 4: return (cznv & FLAGVAL_C) == 0; /* !CFLG CC */ - case 5: return (cznv & FLAGVAL_C) != 0; /* CFLG CS */ - case 6: return (cznv & FLAGVAL_Z) == 0; /* !ZFLG NE */ - case 7: return (cznv & FLAGVAL_Z) != 0; /* ZFLG EQ */ - case 8: return (cznv & FLAGVAL_V) == 0; /* !VFLG VC */ - case 9: return (cznv & FLAGVAL_V) != 0; /* VFLG VS */ - case 10: return (cznv & FLAGVAL_N) == 0; /* !NFLG PL */ - case 11: return (cznv & FLAGVAL_N) != 0; /* NFLG MI */ + case 0: + return 1; /* T */ + case 1: + return 0; /* F */ + case 2: + return (cznv & (FLAGVAL_C | FLAGVAL_Z)) == 0; /* !CFLG && !ZFLG HI */ + case 3: + return (cznv & (FLAGVAL_C | FLAGVAL_Z)) != 0; /* CFLG || ZFLG LS */ + case 4: + return (cznv & FLAGVAL_C) == 0; /* !CFLG CC */ + case 5: + return (cznv & FLAGVAL_C) != 0; /* CFLG CS */ + case 6: + return (cznv & FLAGVAL_Z) == 0; /* !ZFLG NE */ + case 7: + return (cznv & FLAGVAL_Z) != 0; /* ZFLG EQ */ + case 8: + return (cznv & FLAGVAL_V) == 0; /* !VFLG VC */ + case 9: + return (cznv & FLAGVAL_V) != 0; /* VFLG VS */ + case 10: + return (cznv & FLAGVAL_N) == 0; /* !NFLG PL */ + case 11: + return (cznv & FLAGVAL_N) != 0; /* NFLG MI */ #if FLAGBIT_N > FLAGBIT_V - case 12: return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & FLAGVAL_N) == 0; /* NFLG == VFLG GE */ - case 13: return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & FLAGVAL_N) != 0; /* NFLG != VFLG LT */ - case 14: cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* !ZFLG && (NFLG == VFLG) GT */ - return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & (FLAGVAL_N | FLAGVAL_Z)) == 0; - case 15: cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* ZFLG || (NFLG != VFLG) LE */ - return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & (FLAGVAL_N | FLAGVAL_Z)) != 0; + case 12: + return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & FLAGVAL_N) == 0; /* NFLG == VFLG GE */ + case 13: + return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & FLAGVAL_N) != 0; /* NFLG != VFLG LT */ + case 14: + cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* !ZFLG && (NFLG == VFLG) GT */ + return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & (FLAGVAL_N | FLAGVAL_Z)) == 0; + case 15: + cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* ZFLG || (NFLG != VFLG) LE */ + return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & (FLAGVAL_N | FLAGVAL_Z)) != 0; #else - case 12: return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & FLAGVAL_V) == 0; /* NFLG == VFLG GE */ - case 13: return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & FLAGVAL_V) != 0; /* NFLG != VFLG LT */ - case 14: cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* !ZFLG && (NFLG == VFLG) GT */ - return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & (FLAGVAL_V | FLAGVAL_Z)) == 0; - case 15: cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* ZFLG || (NFLG != VFLG) LE */ - return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & (FLAGVAL_V | FLAGVAL_Z)) != 0; + case 12: + return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & FLAGVAL_V) == 0; /* NFLG == VFLG GE */ + case 13: + return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & FLAGVAL_V) != 0; /* NFLG != VFLG LT */ + case 14: + cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* !ZFLG && (NFLG == VFLG) GT */ + return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & (FLAGVAL_V | FLAGVAL_Z)) == 0; + case 15: + cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V); /* ZFLG || (NFLG != VFLG) LE */ + return (((cznv << (FLAGBIT_V - FLAGBIT_N)) ^ cznv) & (FLAGVAL_V | FLAGVAL_Z)) != 0; #endif } return 0; diff --git a/src/machdep/m68k.h b/src/machdep/m68k.h index cea10e77c..a88d6127f 100644 --- a/src/machdep/m68k.h +++ b/src/machdep/m68k.h @@ -1,15 +1,15 @@ /* - * UAE - The Un*x Amiga Emulator - * - * MC68000 emulation - machine dependent bits - * - * Copyright 1996 Bernd Schmidt - * Copyright 2004-2005 Richard Drummond - */ - - /* - * Machine dependent structure for holding the 68k CCR flags - */ + * UAE - The Un*x Amiga Emulator + * + * MC68000 emulation - machine dependent bits + * + * Copyright 1996 Bernd Schmidt + * Copyright 2004-2005 Richard Drummond + */ + +/* + * Machine dependent structure for holding the 68k CCR flags + */ extern int cctrue(int cc); @@ -37,42 +37,42 @@ extern struct flag_struct regflags; * SZxxxxxC xxxxVxxx xxxxxxxxx xxxxxxxxx */ -#define FLAGBIT_N 7 -#define FLAGBIT_Z 6 -#define FLAGBIT_C 0 -#define FLAGBIT_V 11 -#define FLAGBIT_X 0 - -#define FLAGVAL_N (1 << FLAGBIT_N) -#define FLAGVAL_Z (1 << FLAGBIT_Z) -#define FLAGVAL_C (1 << FLAGBIT_C) -#define FLAGVAL_V (1 << FLAGBIT_V) -#define FLAGVAL_X (1 << FLAGBIT_X) - -#define SET_ZFLG(y) (regflags.cznv = (regflags.cznv & ~FLAGVAL_Z) | (((y) & 1) << FLAGBIT_Z)) -#define SET_CFLG(y) (regflags.cznv = (regflags.cznv & ~FLAGVAL_C) | (((y) & 1) << FLAGBIT_C)) -#define SET_VFLG(y) (regflags.cznv = (regflags.cznv & ~FLAGVAL_V) | (((y) & 1) << FLAGBIT_V)) -#define SET_NFLG(y) (regflags.cznv = (regflags.cznv & ~FLAGVAL_N) | (((y) & 1) << FLAGBIT_N)) -#define SET_XFLG(y) (regflags.x = ((y) & 1) << FLAGBIT_X) - -#define GET_ZFLG() ((regflags.cznv >> FLAGBIT_Z) & 1) -#define GET_CFLG() ((regflags.cznv >> FLAGBIT_C) & 1) -#define GET_VFLG() ((regflags.cznv >> FLAGBIT_V) & 1) -#define GET_NFLG() ((regflags.cznv >> FLAGBIT_N) & 1) -#define GET_XFLG() ((regflags.x >> FLAGBIT_X) & 1) - -#define CLEAR_CZNV() (regflags.cznv = 0) -#define GET_CZNV() (regflags.cznv) -#define IOR_CZNV(X) (regflags.cznv |= (X)) -#define SET_CZNV(X) (regflags.cznv = (X)) - -#define COPY_CARRY() (regflags.x = regflags.cznv >> (FLAGBIT_C - FLAGBIT_X)) +#define FLAGBIT_N 7 +#define FLAGBIT_Z 6 +#define FLAGBIT_C 0 +#define FLAGBIT_V 11 +#define FLAGBIT_X 0 + +#define FLAGVAL_N (1 << FLAGBIT_N) +#define FLAGVAL_Z (1 << FLAGBIT_Z) +#define FLAGVAL_C (1 << FLAGBIT_C) +#define FLAGVAL_V (1 << FLAGBIT_V) +#define FLAGVAL_X (1 << FLAGBIT_X) + +#define SET_ZFLG(y) (regflags.cznv = (regflags.cznv & ~FLAGVAL_Z) | (((y)&1) << FLAGBIT_Z)) +#define SET_CFLG(y) (regflags.cznv = (regflags.cznv & ~FLAGVAL_C) | (((y)&1) << FLAGBIT_C)) +#define SET_VFLG(y) (regflags.cznv = (regflags.cznv & ~FLAGVAL_V) | (((y)&1) << FLAGBIT_V)) +#define SET_NFLG(y) (regflags.cznv = (regflags.cznv & ~FLAGVAL_N) | (((y)&1) << FLAGBIT_N)) +#define SET_XFLG(y) (regflags.x = ((y)&1) << FLAGBIT_X) + +#define GET_ZFLG() ((regflags.cznv >> FLAGBIT_Z) & 1) +#define GET_CFLG() ((regflags.cznv >> FLAGBIT_C) & 1) +#define GET_VFLG() ((regflags.cznv >> FLAGBIT_V) & 1) +#define GET_NFLG() ((regflags.cznv >> FLAGBIT_N) & 1) +#define GET_XFLG() ((regflags.x >> FLAGBIT_X) & 1) + +#define CLEAR_CZNV() (regflags.cznv = 0) +#define GET_CZNV() (regflags.cznv) +#define IOR_CZNV(X) (regflags.cznv |= (X)) +#define SET_CZNV(X) (regflags.cznv = (X)) + +#define COPY_CARRY() (regflags.x = regflags.cznv >> (FLAGBIT_C - FLAGBIT_X)) #else /* !SAHF_SETO_PROFITABLE */ - /* - * Machine dependent structure for holding the 68k CCR flags - */ +/* + * Machine dependent structure for holding the 68k CCR flags + */ struct flag_struct { uae_u32 cznv; uae_u32 x; @@ -94,35 +94,35 @@ extern struct flag_struct regflags; * xxxxxxxV NZxxxxxC xxxxxxxxx xxxxxxxxx */ -#define FLAGBIT_N 15 -#define FLAGBIT_Z 14 -#define FLAGBIT_C 8 -#define FLAGBIT_V 0 -#define FLAGBIT_X 0 /* must be in position 0 for duplicate_carry() to work */ - -#define FLAGVAL_N (1 << FLAGBIT_N) -#define FLAGVAL_Z (1 << FLAGBIT_Z) -#define FLAGVAL_C (1 << FLAGBIT_C) -#define FLAGVAL_V (1 << FLAGBIT_V) -#define FLAGVAL_X (1 << FLAGBIT_X) - -#define SET_ZFLG(y) (regflags.cznv = (((uae_u32)regflags.cznv) & ~FLAGVAL_Z) | (((y) & 1) << FLAGBIT_Z)) -#define SET_CFLG(y) (regflags.cznv = (((uae_u32)regflags.cznv) & ~FLAGVAL_C) | (((y) & 1) << FLAGBIT_C)) -#define SET_VFLG(y) (regflags.cznv = (((uae_u32)regflags.cznv) & ~FLAGVAL_V) | (((y) & 1) << FLAGBIT_V)) -#define SET_NFLG(y) (regflags.cznv = (((uae_u32)regflags.cznv) & ~FLAGVAL_N) | (((y) & 1) << FLAGBIT_N)) -#define SET_XFLG(y) (regflags.x = ((y) & 1) << FLAGBIT_X) - -#define GET_ZFLG() ((regflags.cznv >> FLAGBIT_Z) & 1) -#define GET_CFLG() ((regflags.cznv >> FLAGBIT_C) & 1) -#define GET_VFLG() ((regflags.cznv >> FLAGBIT_V) & 1) -#define GET_NFLG() ((regflags.cznv >> FLAGBIT_N) & 1) -#define GET_XFLG() ((regflags.x >> FLAGBIT_X) & 1) - -#define CLEAR_CZNV() (regflags.cznv = 0) -#define GET_CZNV() (regflags.cznv) -#define IOR_CZNV(X) (regflags.cznv |= (X)) -#define SET_CZNV(X) (regflags.cznv = (X)) - -#define COPY_CARRY() (regflags.x = regflags.cznv >> (FLAGBIT_C - FLAGBIT_X)) +#define FLAGBIT_N 15 +#define FLAGBIT_Z 14 +#define FLAGBIT_C 8 +#define FLAGBIT_V 0 +#define FLAGBIT_X 0 /* must be in position 0 for duplicate_carry() to work */ + +#define FLAGVAL_N (1 << FLAGBIT_N) +#define FLAGVAL_Z (1 << FLAGBIT_Z) +#define FLAGVAL_C (1 << FLAGBIT_C) +#define FLAGVAL_V (1 << FLAGBIT_V) +#define FLAGVAL_X (1 << FLAGBIT_X) + +#define SET_ZFLG(y) (regflags.cznv = (((uae_u32)regflags.cznv) & ~FLAGVAL_Z) | (((y)&1) << FLAGBIT_Z)) +#define SET_CFLG(y) (regflags.cznv = (((uae_u32)regflags.cznv) & ~FLAGVAL_C) | (((y)&1) << FLAGBIT_C)) +#define SET_VFLG(y) (regflags.cznv = (((uae_u32)regflags.cznv) & ~FLAGVAL_V) | (((y)&1) << FLAGBIT_V)) +#define SET_NFLG(y) (regflags.cznv = (((uae_u32)regflags.cznv) & ~FLAGVAL_N) | (((y)&1) << FLAGBIT_N)) +#define SET_XFLG(y) (regflags.x = ((y)&1) << FLAGBIT_X) + +#define GET_ZFLG() ((regflags.cznv >> FLAGBIT_Z) & 1) +#define GET_CFLG() ((regflags.cznv >> FLAGBIT_C) & 1) +#define GET_VFLG() ((regflags.cznv >> FLAGBIT_V) & 1) +#define GET_NFLG() ((regflags.cznv >> FLAGBIT_N) & 1) +#define GET_XFLG() ((regflags.x >> FLAGBIT_X) & 1) + +#define CLEAR_CZNV() (regflags.cznv = 0) +#define GET_CZNV() (regflags.cznv) +#define IOR_CZNV(X) (regflags.cznv |= (X)) +#define SET_CZNV(X) (regflags.cznv = (X)) + +#define COPY_CARRY() (regflags.x = regflags.cznv >> (FLAGBIT_C - FLAGBIT_X)) #endif diff --git a/src/machdep/maccess.h b/src/machdep/maccess.h index 91bb9d3a4..f5b698c03 100644 --- a/src/machdep/maccess.h +++ b/src/machdep/maccess.h @@ -3,13 +3,13 @@ #include - /* - * UAE - The Un*x Amiga Emulator - * - * Memory access functions - * - * Copyright 1996 Bernd Schmidt - */ +/* + * UAE - The Un*x Amiga Emulator + * + * Memory access functions + * + * Copyright 1996 Bernd Schmidt + */ #ifdef CPU_64_BIT #define ALIGN_POINTER_TO32(p) ((~(uae_u64)(p)) & 3) @@ -17,64 +17,53 @@ #define ALIGN_POINTER_TO32(p) ((~(uae_u32)(p)) & 3) #endif -#define do_get_mem_byte(a) ((uae_u32)*(uae_u8 *)(a)) -STATIC_INLINE void do_put_mem_byte(uae_u8 *a, uae_u8 v) -{ - *a = v; +#define do_get_mem_byte(a) ((uae_u32) * (uae_u8*)(a)) +STATIC_INLINE void do_put_mem_byte(uae_u8* a, uae_u8 v) { + *a = v; } #ifdef _WIN32 #include -STATIC_INLINE uae_u64 do_get_mem_quad(uae_u64 *a) -{ - return _load_be_u64(a); +STATIC_INLINE uae_u64 do_get_mem_quad(uae_u64* a) { + return _load_be_u64(a); } -STATIC_INLINE uae_u32 do_get_mem_long(uae_u32 *a) -{ - return _load_be_u32(a); +STATIC_INLINE uae_u32 do_get_mem_long(uae_u32* a) { + return _load_be_u32(a); } -STATIC_INLINE uae_u16 do_get_mem_word(uae_u16 *a) -{ - return _load_be_u16(a); +STATIC_INLINE uae_u16 do_get_mem_word(uae_u16* a) { + return _load_be_u16(a); } -STATIC_INLINE void do_put_mem_quad(uae_u64 *a, uae_u64 v) -{ - _store_be_u64(a, v); +STATIC_INLINE void do_put_mem_quad(uae_u64* a, uae_u64 v) { + _store_be_u64(a, v); } -STATIC_INLINE void do_put_mem_long(uae_u32 *a, uae_u32 v) -{ - _store_be_u32(a, v); +STATIC_INLINE void do_put_mem_long(uae_u32* a, uae_u32 v) { + _store_be_u32(a, v); } -STATIC_INLINE void do_put_mem_word(uae_u16 *a, uae_u16 v) -{ - _store_be_u16(a, v); +STATIC_INLINE void do_put_mem_word(uae_u16* a, uae_u16 v) { + _store_be_u16(a, v); } -STATIC_INLINE uae_u64 do_byteswap_64(uae_u64 v) -{ - return _byteswap_uint64(v); +STATIC_INLINE uae_u64 do_byteswap_64(uae_u64 v) { + return _byteswap_uint64(v); } -STATIC_INLINE uae_u32 do_byteswap_32(uae_u32 v) -{ - return _byteswap_ulong(v); +STATIC_INLINE uae_u32 do_byteswap_32(uae_u32 v) { + return _byteswap_ulong(v); } -STATIC_INLINE uae_u16 do_byteswap_16(uae_u16 v) -{ - return _byteswap_ushort(v); +STATIC_INLINE uae_u16 do_byteswap_16(uae_u16 v) { + return _byteswap_ushort(v); } -STATIC_INLINE uae_u32 do_get_mem_word_unswapped(uae_u16* a) -{ - return *a; +STATIC_INLINE uae_u32 do_get_mem_word_unswapped(uae_u16* a) { + return *a; } #else @@ -89,59 +78,48 @@ STATIC_INLINE uae_u32 do_get_mem_word_unswapped(uae_u16* a) #include #endif -STATIC_INLINE uae_u64 do_get_mem_quad(uae_u64 *a) -{ - return bswap_64(*a); +STATIC_INLINE uae_u64 do_get_mem_quad(uae_u64* a) { + return bswap_64(*a); } -STATIC_INLINE uae_u32 do_get_mem_long(uae_u32 *a) -{ - return bswap_32(*a); +STATIC_INLINE uae_u32 do_get_mem_long(uae_u32* a) { + return bswap_32(*a); } -STATIC_INLINE uae_u16 do_get_mem_word(uae_u16 *a) -{ - return bswap_16(*a); +STATIC_INLINE uae_u16 do_get_mem_word(uae_u16* a) { + return bswap_16(*a); } -STATIC_INLINE void do_put_mem_quad(uae_u64 *a, uae_u64 v) -{ - *a = bswap_64(v); +STATIC_INLINE void do_put_mem_quad(uae_u64* a, uae_u64 v) { + *a = bswap_64(v); } -STATIC_INLINE void do_put_mem_long(uae_u32 *a, uae_u32 v) -{ - *a = bswap_32(v); +STATIC_INLINE void do_put_mem_long(uae_u32* a, uae_u32 v) { + *a = bswap_32(v); } -STATIC_INLINE void do_put_mem_word(uae_u16 *a, uae_u16 v) -{ - *a = bswap_16(v); +STATIC_INLINE void do_put_mem_word(uae_u16* a, uae_u16 v) { + *a = bswap_16(v); } -STATIC_INLINE uae_u64 do_byteswap_64(uae_u64 v) -{ - return bswap_64(v); +STATIC_INLINE uae_u64 do_byteswap_64(uae_u64 v) { + return bswap_64(v); } -STATIC_INLINE uae_u32 do_byteswap_32(uae_u32 v) -{ - return bswap_32(v); +STATIC_INLINE uae_u32 do_byteswap_32(uae_u32 v) { + return bswap_32(v); } -STATIC_INLINE uae_u16 do_byteswap_16(uae_u16 v) -{ - return bswap_16(v); +STATIC_INLINE uae_u16 do_byteswap_16(uae_u16 v) { + return bswap_16(v); } -STATIC_INLINE uae_u32 do_get_mem_word_unswapped(uae_u16 *a) -{ - return *a; +STATIC_INLINE uae_u32 do_get_mem_word_unswapped(uae_u16* a) { + return *a; } #endif - #define call_mem_get_func(func, addr) ((*func)(addr)) #define call_mem_put_func(func, addr, v) ((*func)(addr, v)) diff --git a/src/mman.cpp b/src/mman.cpp index ab0a699ba..fac4706e1 100644 --- a/src/mman.cpp +++ b/src/mman.cpp @@ -1,3 +1,4 @@ +// clang-format off #include "sysconfig.h" #include "sysdeps.h" #include "uae/memory.h" @@ -9,14 +10,15 @@ #include "cpuboard.h" #include "rommgr.h" #include "newcpu.h" +// clang-format on #ifdef __x86_64__ static int os_64bit = 1; -typedef uint64_t ULONG_PTR; +typedef uint64_t ULONG_PTR; #else static int os_64bit = 0; #ifndef _WIN32 - typedef uint32_t ULONG_PTR; +typedef uint32_t ULONG_PTR; #endif #endif @@ -30,33 +32,32 @@ static int os_64bit = 0; #endif #include -#define MEM_COMMIT 0x00001000 -#define MEM_RESERVE 0x00002000 -#define MEM_DECOMMIT 0x4000 -#define MEM_RELEASE 0x8000 -#define MEM_WRITE_WATCH 0x00200000 -#define MEM_TOP_DOWN 0x00100000 +#define MEM_COMMIT 0x00001000 +#define MEM_RESERVE 0x00002000 +#define MEM_DECOMMIT 0x4000 +#define MEM_RELEASE 0x8000 +#define MEM_WRITE_WATCH 0x00200000 +#define MEM_TOP_DOWN 0x00100000 -#define PAGE_NOACCESS 0x01 +#define PAGE_NOACCESS 0x01 #define PAGE_EXECUTE_READWRITE 0x40 -#define PAGE_READONLY 0x02 -#define PAGE_READWRITE 0x04 +#define PAGE_READONLY 0x02 +#define PAGE_READWRITE 0x04 -typedef void * PVOID; -typedef void * LPVOID; +typedef void* PVOID; +typedef void* LPVOID; typedef size_t SIZE_T; #undef ULONG typedef uint32_t ULONG; -typedef ULONG_PTR *PULONG_PTR; -typedef ULONG *PULONG; +typedef ULONG_PTR* PULONG_PTR; +typedef ULONG* PULONG; typedef struct { - int dwPageSize; + int dwPageSize; } SYSTEM_INFO; -static void GetSystemInfo(SYSTEM_INFO *si) -{ - si->dwPageSize = sysconf(_SC_PAGESIZE); +static void GetSystemInfo(SYSTEM_INFO* si) { + si->dwPageSize = sysconf(_SC_PAGESIZE); } #define USE_MMAP @@ -67,99 +68,89 @@ static void GetSystemInfo(SYSTEM_INFO *si) #endif #endif -static void *VirtualAlloc(void *lpAddress, size_t dwSize, int flAllocationType, - int flProtect) -{ - write_log("- VirtualAlloc addr=%p size=%zu type=%d prot=%d\n", - lpAddress, dwSize, flAllocationType, flProtect); - if (flAllocationType & MEM_RESERVE) { - write_log(" MEM_RESERVE\n"); - } - if (flAllocationType & MEM_COMMIT) { - write_log(" MEM_COMMIT\n"); - } - - int prot = 0; - if (flProtect == PAGE_READWRITE) { - write_log(" PAGE_READWRITE\n"); - prot = UAE_VM_READ_WRITE; - } else if (flProtect == PAGE_READONLY) { - write_log(" PAGE_READONLY\n"); - prot = UAE_VM_READ; - } else if (flProtect == PAGE_EXECUTE_READWRITE) { - write_log(" PAGE_EXECUTE_READWRITE\n"); - prot = UAE_VM_READ_WRITE_EXECUTE; - } else { - write_log(" WARNING: unknown protection\n"); - } - - void *address = NULL; - - if (flAllocationType == MEM_COMMIT && lpAddress == NULL) { - write_log("NATMEM: Allocated non-reserved memory size %zu\n", dwSize); - void *memory = uae_vm_alloc(dwSize, 0, UAE_VM_READ_WRITE); - if (memory == NULL) { - write_log("memory allocated failed errno %d\n", errno); - } - return memory; - } - - if (flAllocationType & MEM_RESERVE) { - address = uae_vm_reserve(dwSize, 0); - } else { - address = lpAddress; - } - - if (flAllocationType & MEM_COMMIT) { - write_log("commit prot=%d\n", prot); - uae_vm_commit(address, dwSize, prot); - } - - return address; +static void* VirtualAlloc(void* lpAddress, size_t dwSize, int flAllocationType, int flProtect) { + write_log("- VirtualAlloc addr=%p size=%zu type=%d prot=%d\n", lpAddress, dwSize, flAllocationType, flProtect); + if (flAllocationType & MEM_RESERVE) { + write_log(" MEM_RESERVE\n"); + } + if (flAllocationType & MEM_COMMIT) { + write_log(" MEM_COMMIT\n"); + } + + int prot = 0; + if (flProtect == PAGE_READWRITE) { + write_log(" PAGE_READWRITE\n"); + prot = UAE_VM_READ_WRITE; + } else if (flProtect == PAGE_READONLY) { + write_log(" PAGE_READONLY\n"); + prot = UAE_VM_READ; + } else if (flProtect == PAGE_EXECUTE_READWRITE) { + write_log(" PAGE_EXECUTE_READWRITE\n"); + prot = UAE_VM_READ_WRITE_EXECUTE; + } else { + write_log(" WARNING: unknown protection\n"); + } + + void* address = NULL; + + if (flAllocationType == MEM_COMMIT && lpAddress == NULL) { + write_log("NATMEM: Allocated non-reserved memory size %zu\n", dwSize); + void* memory = uae_vm_alloc(dwSize, 0, UAE_VM_READ_WRITE); + if (memory == NULL) { + write_log("memory allocated failed errno %d\n", errno); + } + return memory; + } + + if (flAllocationType & MEM_RESERVE) { + address = uae_vm_reserve(dwSize, 0); + } else { + address = lpAddress; + } + + if (flAllocationType & MEM_COMMIT) { + write_log("commit prot=%d\n", prot); + uae_vm_commit(address, dwSize, prot); + } + + return address; } -static int VirtualProtect(void *lpAddress, int dwSize, int flNewProtect, - unsigned int *lpflOldProtect) -{ - write_log("- VirtualProtect addr=%p size=%d prot=%d\n", - lpAddress, dwSize, flNewProtect); - int prot = 0; - if (flNewProtect == PAGE_READWRITE) { - write_log(" PAGE_READWRITE\n"); - prot = UAE_VM_READ_WRITE; - } else if (flNewProtect == PAGE_READONLY) { - write_log(" PAGE_READONLY\n"); - prot = UAE_VM_READ; - } else { - write_log(" -- unknown protection --\n"); - } - if (uae_vm_protect(lpAddress, dwSize, prot) == 0) { - write_log("mprotect failed errno %d\n", errno); - return 0; - } - return 1; +static int VirtualProtect(void* lpAddress, int dwSize, int flNewProtect, unsigned int* lpflOldProtect) { + write_log("- VirtualProtect addr=%p size=%d prot=%d\n", lpAddress, dwSize, flNewProtect); + int prot = 0; + if (flNewProtect == PAGE_READWRITE) { + write_log(" PAGE_READWRITE\n"); + prot = UAE_VM_READ_WRITE; + } else if (flNewProtect == PAGE_READONLY) { + write_log(" PAGE_READONLY\n"); + prot = UAE_VM_READ; + } else { + write_log(" -- unknown protection --\n"); + } + if (uae_vm_protect(lpAddress, dwSize, prot) == 0) { + write_log("mprotect failed errno %d\n", errno); + return 0; + } + return 1; } -static bool VirtualFree(void *lpAddress, size_t dwSize, int dwFreeType) -{ - int result = 0; - if (dwFreeType == MEM_DECOMMIT) { - return uae_vm_decommit(lpAddress, dwSize); - } - else if (dwFreeType == MEM_RELEASE) { - return uae_vm_free(lpAddress, dwSize); - } - return 0; +static bool VirtualFree(void* lpAddress, size_t dwSize, int dwFreeType) { + int result = 0; + if (dwFreeType == MEM_DECOMMIT) { + return uae_vm_decommit(lpAddress, dwSize); + } else if (dwFreeType == MEM_RELEASE) { + return uae_vm_free(lpAddress, dwSize); + } + return 0; } -static int GetLastError() -{ - return errno; +static int GetLastError() { + return errno; } -static int my_getpagesize (void) -{ - return uae_vm_page_size(); +static int my_getpagesize(void) { + return uae_vm_page_size(); } #define getpagesize my_getpagesize @@ -168,26 +159,15 @@ static int my_getpagesize (void) typedef uint32_t UINT; typedef uint32_t DWORD; -typedef DWORD *LPDWORD; - -UINT GetWriteWatch( - DWORD dwFlags, - PVOID lpBaseAddress, - SIZE_T dwRegionSize, - PVOID *lpAddresses, - ULONG_PTR *lpdwCount, - LPDWORD lpdwGranularity -) -{ - return 0; +typedef DWORD* LPDWORD; + +UINT GetWriteWatch(DWORD dwFlags, PVOID lpBaseAddress, SIZE_T dwRegionSize, PVOID* lpAddresses, ULONG_PTR* lpdwCount, + LPDWORD lpdwGranularity) { + return 0; } -UINT ResetWriteWatch( - LPVOID lpBaseAddress, - SIZE_T dwRegionSize -) -{ - return 0; +UINT ResetWriteWatch(LPVOID lpBaseAddress, SIZE_T dwRegionSize) { + return 0; } #endif /* !WIN32 */ diff --git a/src/quaesar.cpp b/src/quaesar.cpp index 03b0c2f2d..dd01f3b36 100644 --- a/src/quaesar.cpp +++ b/src/quaesar.cpp @@ -1,6 +1,7 @@ -#include #include +#include +// clang-format off #include "sysconfig.h" #include "sysdeps.h" #include "uae/time.h" @@ -8,6 +9,7 @@ #include "parse_options.h" #include "options.h" #include +// clang-format on // WTF SDL! #undef main @@ -20,35 +22,34 @@ int main(int argc, char** argv) { syncbase = 1000000; Options options; - CLI::App app {"Quaesar"}; + CLI::App app{"Quaesar"}; app.add_option("input", options.input, "Executable or image file (adf, dms)")->check(CLI::ExistingFile); app.add_option("-k,--kickstart", options.kickstart, "Path to the kickstart ROM")->check(CLI::ExistingFile); CLI11_PARSE(app, argc, argv); - + keyboard_settrans(); - default_prefs(&currprefs, true, 0); - fixup_prefs(&currprefs, true); + default_prefs(&currprefs, true, 0); + fixup_prefs(&currprefs, true); - strcpy(currprefs.floppyslots[0].df, options.input.c_str()); + strcpy(currprefs.floppyslots[0].df, options.input.c_str()); // Most compatible mode currprefs.cpu_cycle_exact = 1; currprefs.cpu_memory_cycle_exact = 1; currprefs.blitter_cycle_exact = 1; - currprefs.turbo_emulation = 0; + currprefs.turbo_emulation = 0; strcpy(currprefs.romfile, options.kickstart.c_str()); - // Initialize SDL - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - SDL_Log("Unable to initialize SDL: %s", SDL_GetError()); - return 1; - } + // Initialize SDL + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + SDL_Log("Unable to initialize SDL: %s", SDL_GetError()); + return 1; + } real_main(argc, argv); - return 0; + return 0; } - diff --git a/src/rp.h b/src/rp.h index be86d77bd..203e1513a 100644 --- a/src/rp.h +++ b/src/rp.h @@ -1,23 +1,23 @@ -extern HRESULT rp_init (void); -extern void rp_free (void); -extern int rp_close (void); -extern void rp_fixup_options (struct uae_prefs*); -extern void rp_pause (int paused); -extern void rp_activate (WPARAM, LPARAM); -extern void rp_mouse_capture (int); -extern void rp_mouse_magic (int); -extern void rp_turbo_cpu (int); -extern void rp_turbo_floppy (int); -extern void rp_set_hwnd (HWND); -extern void rp_set_hwnd_delayed (void); -extern void rp_set_enabledisable (int); -extern int rp_checkesc (int, int, int); -extern int rp_isactive (void); -extern void rp_vsync (void); -extern HWND rp_getparent (void); -extern void rp_rtg_switch (void); -extern void rp_screenmode_changed (void); +extern HRESULT rp_init(void); +extern void rp_free(void); +extern int rp_close(void); +extern void rp_fixup_options(struct uae_prefs*); +extern void rp_pause(int paused); +extern void rp_activate(WPARAM, LPARAM); +extern void rp_mouse_capture(int); +extern void rp_mouse_magic(int); +extern void rp_turbo_cpu(int); +extern void rp_turbo_floppy(int); +extern void rp_set_hwnd(HWND); +extern void rp_set_hwnd_delayed(void); +extern void rp_set_enabledisable(int); +extern int rp_checkesc(int, int, int); +extern int rp_isactive(void); +extern void rp_vsync(void); +extern HWND rp_getparent(void); +extern void rp_rtg_switch(void); +extern void rp_screenmode_changed(void); extern void rp_keymap(TrapContext*, uaecptr, uae_u32); extern USHORT rp_rawbuttons(LPARAM lParam, USHORT usButtonFlags); extern bool rp_mouseevent(int x, int y, int buttons, int buttonmask); @@ -31,9 +31,9 @@ extern bool rp_ismodem(void); extern void rp_writemodem(uae_u8); extern void rp_modemstate(int); extern void rp_writemodemstatus(bool, bool, bool, bool); -extern void rp_readmodemstatus(bool*,bool*,bool*,bool*); +extern void rp_readmodemstatus(bool*, bool*, bool*, bool*); -extern TCHAR *rp_param; +extern TCHAR* rp_param; extern int rp_rpescapekey; extern int rp_rpescapeholdtime; extern int rp_screenmode; @@ -42,20 +42,19 @@ extern int rp_printer; extern int rp_modem; extern int log_rp; -extern void rp_input_change (int num); -extern void rp_disk_image_change (int num, const TCHAR *name, bool writeprotected); -extern void rp_harddrive_image_change (int num, bool readonly, const TCHAR *name); -extern void rp_cd_image_change (int num, const TCHAR *name); +extern void rp_input_change(int num); +extern void rp_disk_image_change(int num, const TCHAR* name, bool writeprotected); +extern void rp_harddrive_image_change(int num, bool readonly, const TCHAR* name); +extern void rp_cd_image_change(int num, const TCHAR* name); -extern void rp_update_gameport (int port, int mask, int onoff); -extern void rp_update_volume (struct uae_prefs*); -extern void rp_update_leds (int, int, int, int); -extern void rp_floppy_track (int floppy, int track); -extern void rp_hd_activity (int, int, int); -extern void rp_cd_activity (int, int); - -void rp_floppy_device_enable (int num, bool enabled); -void rp_hd_device_enable (int num, bool enabled); -void rp_cd_device_enable (int num, bool enabled); -void rp_enumdevices (void); +extern void rp_update_gameport(int port, int mask, int onoff); +extern void rp_update_volume(struct uae_prefs*); +extern void rp_update_leds(int, int, int, int); +extern void rp_floppy_track(int floppy, int track); +extern void rp_hd_activity(int, int, int); +extern void rp_cd_activity(int, int); +void rp_floppy_device_enable(int num, bool enabled); +void rp_hd_device_enable(int num, bool enabled); +void rp_cd_device_enable(int num, bool enabled); +void rp_enumdevices(void); diff --git a/src/sounddep/sound.cpp b/src/sounddep/sound.cpp index e7d6853d4..05584ff3b 100644 --- a/src/sounddep/sound.cpp +++ b/src/sounddep/sound.cpp @@ -1,17 +1,19 @@ +// clang-format off #include "sysconfig.h" #include "sysdeps.h" #include "audio.h" +// clang-format on #define SND_MAX_BUFFER 65536 uae_u16 paula_sndbuffer[SND_MAX_BUFFER]; -uae_u16 *paula_sndbufpt; +uae_u16* paula_sndbufpt; int paula_sndbufsize = 0; int active_sound_stereo; bool audio_finish_pull(void) { - //UNIMPLEMENTED(); + // UNIMPLEMENTED(); return false; } @@ -22,7 +24,7 @@ void sound_volume(int) { void set_volume(int, int) { UNIMPLEMENTED(); } - + void master_sound_volume(int) { UNIMPLEMENTED(); } diff --git a/src/sounddep/sound.h b/src/sounddep/sound.h index 384f6f0a1..73036299c 100644 --- a/src/sounddep/sound.h +++ b/src/sounddep/sound.h @@ -1,63 +1,61 @@ /* -* UAE - The Un*x Amiga Emulator -* -* Support for Linux/USS sound -* -* Copyright 1997 Bernd Schmidt -*/ + * UAE - The Un*x Amiga Emulator + * + * Support for Linux/USS sound + * + * Copyright 1997 Bernd Schmidt + */ #define SOUNDSTUFF 1 extern uae_u16 paula_sndbuffer[]; -extern uae_u16 *paula_sndbufpt; +extern uae_u16* paula_sndbufpt; extern int paula_sndbufsize; -extern void finish_sound_buffer (void); -extern void restart_sound_buffer (void); -extern void pause_sound_buffer (void); -extern int init_sound (void); -extern void close_sound (void); -extern int setup_sound (void); -extern void resume_sound (void); -extern void pause_sound (void); -extern void reset_sound (void); -extern bool sound_paused (void); -extern void sound_setadjust (float); -extern int enumerate_sound_devices (void); -extern void sound_mute (int); -extern void sound_volume (int); -extern void set_volume (int, int); -extern void master_sound_volume (int); +extern void finish_sound_buffer(void); +extern void restart_sound_buffer(void); +extern void pause_sound_buffer(void); +extern int init_sound(void); +extern void close_sound(void); +extern int setup_sound(void); +extern void resume_sound(void); +extern void pause_sound(void); +extern void reset_sound(void); +extern bool sound_paused(void); +extern void sound_setadjust(float); +extern int enumerate_sound_devices(void); +extern void sound_mute(int); +extern void sound_volume(int); +extern void set_volume(int, int); +extern void master_sound_volume(int); struct sound_dp; -struct sound_data -{ - int waiting_for_buffer; - int deactive; - int devicetype; - int obtainedfreq; - int paused; - int mute; - int channels; - int freq; - int samplesize; - int sndbufsize; - int sndbufframes; - int softvolume; - struct sound_dp *data; - int index; - bool reset; - int resetcnt; - int resetframe; - int resetframecnt; +struct sound_data { + int waiting_for_buffer; + int deactive; + int devicetype; + int obtainedfreq; + int paused; + int mute; + int channels; + int freq; + int samplesize; + int sndbufsize; + int sndbufframes; + int softvolume; + struct sound_dp* data; + int index; + bool reset; + int resetcnt; + int resetframe; + int resetframecnt; }; - -int open_sound_device (struct sound_data *sd, int index, int exclusive, int bufsize, int freq, int channels); -void close_sound_device (struct sound_data *sd); -void pause_sound_device (struct sound_data *sd); -void resume_sound_device (struct sound_data *sd); -void set_volume_sound_device (struct sound_data *sd, int volume, int mute); +int open_sound_device(struct sound_data* sd, int index, int exclusive, int bufsize, int freq, int channels); +void close_sound_device(struct sound_data* sd); +void pause_sound_device(struct sound_data* sd); +void resume_sound_device(struct sound_data* sd); +void set_volume_sound_device(struct sound_data* sd, int volume, int mute); #if SOUNDSTUFF > 0 extern int outputsample, doublesample; @@ -65,7 +63,11 @@ extern int outputsample, doublesample; extern int active_sound_stereo; -#define PUT_SOUND_WORD(b) do { *(uae_u16 *)paula_sndbufpt = b; paula_sndbufpt = (uae_u16 *)(((uae_u8 *)paula_sndbufpt) + 2); } while (0) +#define PUT_SOUND_WORD(b) \ + do { \ + *(uae_u16*)paula_sndbufpt = b; \ + paula_sndbufpt = (uae_u16*)(((uae_u8*)paula_sndbufpt) + 2); \ + } while (0) #define PUT_SOUND_WORD_MONO(b) PUT_SOUND_WORD(b) #define SOUND16_BASE_VAL 0 #define SOUND8_BASE_VAL 128 @@ -84,8 +86,8 @@ extern int active_sound_stereo; #define FILTER_SOUND_TYPE_A1200 1 struct dsaudiomodes { - int ch; - DWORD ksmode; + int ch; + DWORD ksmode; }; extern int sounddrivermask; diff --git a/src/sysconfig.h b/src/sysconfig.h index 7eee8de0b..c227b1679 100644 --- a/src/sysconfig.h +++ b/src/sysconfig.h @@ -1,7 +1,7 @@ #ifndef WINUAE_SYSCONFIG_H #define WINUAE_SYSCONFIG_H -//#include +// #include #ifdef _WIN32 #define ftello64 _ftelli64 @@ -12,23 +12,23 @@ #include "winuae_compat.h" #endif -#pragma warning (disable : 4761) -#pragma warning (disable : 4996) -#pragma warning (disable : 4018) +#pragma warning(disable : 4761) +#pragma warning(disable : 4996) +#pragma warning(disable : 4018) -#define DIRECTINPUT_VERSION 0x0800 +#define DIRECTINPUT_VERSION 0x0800 #define DIRECT3D_VERSION 0x0900 #define SUPPORT_THREADS #define MAX_DPATH 1000 #define DRIVESOUND -//#define GFXFILTER +// #define GFXFILTER #if defined(_M_ARM64) || defined(_M_ARM64EC) || defined(__aarch64__) #define __arm__ #define MSVC_LONG_DOUBLE #else // #define X86_MSVC_ASSEMBLY -//#define OPTIMIZED_FLAGS +// #define OPTIMIZED_FLAGS #define MSVC_LONG_DOUBLE #ifndef __i386__ #define __i386__ @@ -41,96 +41,95 @@ #ifndef UAE_MINI #if !defined(_M_ARM64) && !defined(_M_ARM64EC) -//#define JIT /* JIT compiler support */ -//#define USE_JIT_FPU +// #define JIT /* JIT compiler support */ +// #define USE_JIT_FPU #endif #define DEBUGGER -//#define GDBSERVER +// #define GDBSERVER #define FILESYS /* filesys emulation */ #define UAE_FILESYS_THREADS #define AUTOCONFIG /* autoconfig support, fast ram, harddrives etc.. */ -//#define NOFLAGS_SUPPORT_GENCPU +// #define NOFLAGS_SUPPORT_GENCPU #define NOFLAGS_SUPPORT_GENCOMP -//#define HAVE_GET_WORD_UNSWAPPED +// #define HAVE_GET_WORD_UNSWAPPED #define NATMEM_OFFSET natmem_offset #define USE_NORMAL_CALLING_CONVENTION 0 #define USE_X86_FPUCW 1 -//#define WINDDK /* Windows DDK available, keyboard leds and harddrive support */ -//#define CATWEASEL /* Catweasel MK2/3 support */ -#define AHI /* AHI sound emulation */ -#define ENFORCER /* UAE Enforcer */ +// #define WINDDK /* Windows DDK available, keyboard leds and harddrive support */ +// #define CATWEASEL /* Catweasel MK2/3 support */ +#define AHI /* AHI sound emulation */ +#define ENFORCER /* UAE Enforcer */ #define ECS_DENISE /* ECS DENISE new features */ -#define AGA /* AGA chipset emulation (ECS_DENISE must be enabled) */ -#define CD32 /* CD32 emulation */ -#define CDTV /* CDTV emulation */ -//#define D3D /* D3D display filter support */ -#define PARALLEL_PORT /* parallel port emulation */ +#define AGA /* AGA chipset emulation (ECS_DENISE must be enabled) */ +#define CD32 /* CD32 emulation */ +#define CDTV /* CDTV emulation */ +// #define D3D /* D3D display filter support */ +#define PARALLEL_PORT /* parallel port emulation */ #define PARALLEL_DIRECT /* direct parallel port emulation */ -//#define SERIAL_PORT /* serial port emulation */ +// #define SERIAL_PORT /* serial port emulation */ #define SERIAL_ENET /* serial port UDP transport */ -//#define SCSIEMU /* uaescsi.device emulation */ -//#define UAESERIAL /* uaeserial.device emulation */ +// #define SCSIEMU /* uaescsi.device emulation */ +// #define UAESERIAL /* uaeserial.device emulation */ #define FPUEMU /* FPU emulation */ #define FPU_UAE -#define MMUEMU /* Aranym 68040 MMU */ -#define FULLMMU /* Aranym 68040 MMU */ -#define CPUEMU_0 /* generic 680x0 emulation */ -#define CPUEMU_11 /* 68000/68010 prefetch emulation */ -#define CPUEMU_13 /* 68000/68010 cycle-exact cpu&blitter */ -#define CPUEMU_20 /* 68020 prefetch */ -#define CPUEMU_21 /* 68020 "cycle-exact" + blitter */ -#define CPUEMU_22 /* 68030 prefetch */ -#define CPUEMU_23 /* 68030 "cycle-exact" + blitter */ -#define CPUEMU_24 /* 68060 "cycle-exact" + blitter */ -#define CPUEMU_25 /* 68040 "cycle-exact" + blitter */ -#define CPUEMU_31 /* Aranym 68040 MMU */ -#define CPUEMU_32 /* Previous 68030 MMU */ -#define CPUEMU_33 /* 68060 MMU */ -#define CPUEMU_34 /* 68030 MMU + cache */ -#define CPUEMU_35 /* 68030 MMU + cache + CE */ -#define CPUEMU_40 /* generic 680x0 with JIT direct memory access */ -#define CPUEMU_50 /* generic 680x0 with indirect memory access */ +#define MMUEMU /* Aranym 68040 MMU */ +#define FULLMMU /* Aranym 68040 MMU */ +#define CPUEMU_0 /* generic 680x0 emulation */ +#define CPUEMU_11 /* 68000/68010 prefetch emulation */ +#define CPUEMU_13 /* 68000/68010 cycle-exact cpu&blitter */ +#define CPUEMU_20 /* 68020 prefetch */ +#define CPUEMU_21 /* 68020 "cycle-exact" + blitter */ +#define CPUEMU_22 /* 68030 prefetch */ +#define CPUEMU_23 /* 68030 "cycle-exact" + blitter */ +#define CPUEMU_24 /* 68060 "cycle-exact" + blitter */ +#define CPUEMU_25 /* 68040 "cycle-exact" + blitter */ +#define CPUEMU_31 /* Aranym 68040 MMU */ +#define CPUEMU_32 /* Previous 68030 MMU */ +#define CPUEMU_33 /* 68060 MMU */ +#define CPUEMU_34 /* 68030 MMU + cache */ +#define CPUEMU_35 /* 68030 MMU + cache + CE */ +#define CPUEMU_40 /* generic 680x0 with JIT direct memory access */ +#define CPUEMU_50 /* generic 680x0 with indirect memory access */ #define ACTION_REPLAY /* Action Replay 1/2/3 support */ -//#define PICASSO96 /* Picasso96 display card emulation */ -//#define UAEGFX_INTERNAL /* built-in libs:picasso96/uaegfx.card */ -//#define BSDSOCKET /* bsdsocket.library emulation */ -// #define CAPS /* CAPS-image support */ -//#define SCP /* SuperCardPro */ -#define FDI2RAW /* FDI 1.0 and 2.x image support */ +// #define PICASSO96 /* Picasso96 display card emulation */ +// #define UAEGFX_INTERNAL /* built-in libs:picasso96/uaegfx.card */ +// #define BSDSOCKET /* bsdsocket.library emulation */ +// #define CAPS /* CAPS-image support */ +// #define SCP /* SuperCardPro */ +#define FDI2RAW /* FDI 1.0 and 2.x image support */ #define AVIOUTPUT /* Avioutput support */ -//#define PROWIZARD /* Pro-Wizard module ripper */ -//#define ARCADIA /* Arcadia arcade system */ -//#define ARCHIVEACCESS /* ArchiveAccess decompression library */ -//#define LOGITECHLCD /* Logitech G15 LCD */ +// #define PROWIZARD /* Pro-Wizard module ripper */ +// #define ARCADIA /* Arcadia arcade system */ +// #define ARCHIVEACCESS /* ArchiveAccess decompression library */ +// #define LOGITECHLCD /* Logitech G15 LCD */ #define SAVESTATE /* State file support */ -//#define A2091 /* A590/A2091 SCSI */ -//#define A2065 /* A2065 Ethernet card */ -//#define GFXBOARD /* Hardware graphics board */ -//#define NCR /* A4000T/A4091, 53C710/53C770 SCSI */ -//#define NCR9X /* 53C9X SCSI */ -//#define SANA2 /* SANA2 network driver */ -//#define AMAX /* A-Max ROM adapater emulation */ -//#define RETROPLATFORM /* Cloanto RetroPlayer support */ -//#define WITH_CHD -// #define WITH_LUA /* lua scripting */ +// #define A2091 /* A590/A2091 SCSI */ +// #define A2065 /* A2065 Ethernet card */ +// #define GFXBOARD /* Hardware graphics board */ +// #define NCR /* A4000T/A4091, 53C710/53C770 SCSI */ +// #define NCR9X /* 53C9X SCSI */ +// #define SANA2 /* SANA2 network driver */ +// #define AMAX /* A-Max ROM adapater emulation */ +// #define RETROPLATFORM /* Cloanto RetroPlayer support */ +// #define WITH_CHD +// #define WITH_LUA /* lua scripting */ #define WITH_UAENATIVE #define WITH_SLIRP #define WITH_BUILTIN_SLIRP #define WITH_TABLETLIBRARY // #define WITH_UAENET_PCAP -//#define WITH_PPC -//#define WITH_QEMU_CPU +// #define WITH_PPC +// #define WITH_QEMU_CPU #define WITH_TOCCATA -//#define WITH_PCI -//#define WITH_X86 +// #define WITH_PCI +// #define WITH_X86 #define WITH_THREADED_CPU #define WITH_SOFTFLOAT -//#define FLOPPYBRIDGE -//#define WITH_MIDIEMU +// #define FLOPPYBRIDGE +// #define WITH_MIDIEMU #define WITH_DSP -//#define WITH_DRACO - +// #define WITH_DRACO #else @@ -148,19 +147,18 @@ #define CPUEMU_13 #define CPUEMU_11 - #endif #define WITH_SCSI_IOCTL #define WITH_SCSI_SPTI -//#define A_ZIP -//#define A_RAR -//#define A_7Z -//#define A_LHA -//#define A_LZX -//#define A_DMS -//#define A_WRP +// #define A_ZIP +// #define A_RAR +// #define A_7Z +// #define A_LHA +// #define A_LZX +// #define A_DMS +// #define A_WRP #ifndef PATH_MAX #define PATH_MAX MAX_DPATH @@ -175,8 +173,8 @@ #ifdef _DEBUG #define _CRTDBG_MAP_ALLOC -#include #include +#include #endif #include @@ -346,7 +344,7 @@ typedef long uae_atomic; #define SIZEOF_LONG 8 /* The number of bytes in a long long. */ -//#define SIZEOF_LONG_LONG 8 +// #define SIZEOF_LONG_LONG 8 /* The number of bytes in a short. */ #define SIZEOF_SHORT 2 @@ -356,7 +354,7 @@ typedef long uae_atomic; #define HAVE_ISNAN #undef HAVE_ISINF -//#define isnan _isnan +// #define isnan _isnan #ifndef LT_MODULE_EXT #define LT_MODULE_EXT _T(".dll") @@ -585,7 +583,7 @@ typedef long uae_atomic; /* Define if you have the header file. */ #ifndef _WIN32 -//#define HAVE_SYS_UTIME_H 1 +// #define HAVE_SYS_UTIME_H 1 #define HAVE_UTIME_H 1 #endif @@ -605,7 +603,7 @@ typedef long uae_atomic; /* #undef HAVE_UTIME_H */ /* Define if you have the header file. */ -//#define HAVE_WINDOWS_H 1 +// #define HAVE_WINDOWS_H 1 #define FSDB_DIR_SEPARATOR '\\' #define FSDB_DIR_SEPARATOR_S _T("\\") @@ -613,15 +611,15 @@ typedef long uae_atomic; /* Define to 1 if `S_un' is a member of `struct in_addr'. */ // #define HAVE_STRUCT_IN_ADDR_S_UN 1 -#define UNIMPLEMENTED() \ - do { \ +#define UNIMPLEMENTED() \ + do { \ fprintf(stderr, "Function '%s' is unimplemented. Exiting...\n", __func__); \ - exit(EXIT_FAILURE); \ - } while (0) - - -//#define TRACE() do { printf("%s\n", __func__); } while (0) -#define TRACE() do { } while (0) + exit(EXIT_FAILURE); \ + } while (0) +// #define TRACE() do { printf("%s\n", __func__); } while (0) +#define TRACE() \ + do { \ + } while (0) #endif /* WINUAE_SYSCONFIG_H */ diff --git a/src/target.h b/src/target.h index f21cd2cfe..e1ba7ea42 100644 --- a/src/target.h +++ b/src/target.h @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Target specific stuff, Win32 version - * - * Copyright 1997 Mathias Ortmann - */ +/* + * UAE - The Un*x Amiga Emulator + * + * Target specific stuff, Win32 version + * + * Copyright 1997 Mathias Ortmann + */ #ifdef _WIN32_WCE #define TARGET_NAME "WinCE" @@ -20,4 +20,3 @@ #define NO_MAIN_IN_MAIN_C #define OPTIONSFILENAME _T("default.uae") - diff --git a/src/thread.cpp b/src/thread.cpp index 6fb9e9912..a0fbe9062 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -1,16 +1,18 @@ +// clang-format off #include -#include "uae/inline.h" +#include #include #include "sysconfig.h" -#include #include "sysdeps.h" +#include "uae/inline.h" #include "threaddep/thread.h" +// clang-format on void uae_sem_destroy(uae_sem_t* sem) { - if (*sem) { - SDL_DestroySemaphore((SDL_sem*)sem); - *sem = nullptr; - } + if (*sem) { + SDL_DestroySemaphore((SDL_sem*)sem); + *sem = nullptr; + } } int uae_sem_trywait(uae_sem_t* sem) { @@ -35,11 +37,11 @@ void uae_sem_wait(uae_sem_t* sem) { } void uae_sem_init(uae_sem_t* sem, int manual_reset, int initial_state) { - if (*sem) { - SDL_SemPost((SDL_sem*)sem); - } else { - *sem = (uae_sem_t*)SDL_CreateSemaphore(initial_state); - } + if (*sem) { + SDL_SemPost((SDL_sem*)sem); + } else { + *sem = (uae_sem_t*)SDL_CreateSemaphore(initial_state); + } } // This is needed because SDL runner excepts a function to return 0 but the uae code uses void @@ -54,104 +56,97 @@ static int thread_runner_wrapper(void* arg) { return 0; } -int uae_start_thread(const TCHAR* name, void (*fn)(void *), void *arg, uae_thread_id* tid) { - int result = 1; - if (name != nullptr) { - write_log("uae_start_thread \"%s\" function at %p arg %p\n", name, fn, arg); - } else { - name = "StartThread"; - } +int uae_start_thread(const TCHAR* name, void (*fn)(void*), void* arg, uae_thread_id* tid) { + int result = 1; + if (name != nullptr) { + write_log("uae_start_thread \"%s\" function at %p arg %p\n", name, fn, arg); + } else { + name = "StartThread"; + } // This will leak, but hopefully isn't a big deal - uae_thread_params* params = (uae_thread_params*)malloc(sizeof(uae_thread_params)); - params->f = fn; - params->arg = arg; - - SDL_Thread* thread = SDL_CreateThread(thread_runner_wrapper, name, params); - if (thread == nullptr) { - printf("ERROR creating thread, %s\n", SDL_GetError()); - result = 0; - } + uae_thread_params* params = (uae_thread_params*)malloc(sizeof(uae_thread_params)); + params->f = fn; + params->arg = arg; + + SDL_Thread* thread = SDL_CreateThread(thread_runner_wrapper, name, params); + if (thread == nullptr) { + printf("ERROR creating thread, %s\n", SDL_GetError()); + result = 0; + } - if (tid) { - *tid = thread; - } + if (tid) { + *tid = thread; + } - return result; + return result; } int uae_start_thread_fast(void (*fn)(void*), void* arg, uae_thread_id* tid) { - return uae_start_thread(NULL, fn, arg, tid); + return uae_start_thread(NULL, fn, arg, tid); } -void uae_end_thread(uae_thread_id *thread) { - /* -#ifdef _WIN32 - TerminateThread(SDL_GetThreadID(t), 0); -#end -#ifdef __linux - pthread_kill(SDL_GetThreadID(t), 0); -#endif -*/ +void uae_end_thread(uae_thread_id* thread) { + /* + #ifdef _WIN32 + TerminateThread(SDL_GetThreadID(t), 0); + #end + #ifdef __linux + pthread_kill(SDL_GetThreadID(t), 0); + #endif + */ } void uae_set_thread_priority(uae_thread_id*, int) { // it seems that the thread priority input is always // set to 1 so we assume that the priority is always - SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); + SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); } uae_thread_id uae_thread_get_id(void) { - return (uae_thread_id)SDL_GetThreadID(nullptr); + return (uae_thread_id)SDL_GetThreadID(nullptr); } - #ifdef _WIN32 -uae_atomic atomic_and(volatile uae_atomic *p, uae_u32 v) -{ - return _InterlockedAnd(p, v); +uae_atomic atomic_and(volatile uae_atomic* p, uae_u32 v) { + return _InterlockedAnd(p, v); } -uae_atomic atomic_or(volatile uae_atomic *p, uae_u32 v) -{ - return _InterlockedOr(p, v); +uae_atomic atomic_or(volatile uae_atomic* p, uae_u32 v) { + return _InterlockedOr(p, v); } -void atomic_set(volatile uae_atomic *p, uae_u32 v) -{ +void atomic_set(volatile uae_atomic* p, uae_u32 v) { } -uae_atomic atomic_inc(volatile uae_atomic *p) -{ - return _InterlockedIncrement(p); +uae_atomic atomic_inc(volatile uae_atomic* p) { + return _InterlockedIncrement(p); } -uae_atomic atomic_dec(volatile uae_atomic *p) -{ - return _InterlockedDecrement(p); +uae_atomic atomic_dec(volatile uae_atomic* p) { + return _InterlockedDecrement(p); } -uae_u32 atomic_bit_test_and_reset(volatile uae_atomic *p, uae_u32 v) -{ - return _interlockedbittestandreset(p, v); +uae_u32 atomic_bit_test_and_reset(volatile uae_atomic* p, uae_u32 v) { + return _interlockedbittestandreset(p, v); } #else -uae_atomic atomic_and(volatile uae_atomic * p, uae_u32 v) { +uae_atomic atomic_and(volatile uae_atomic* p, uae_u32 v) { return __atomic_and_fetch(p, v, __ATOMIC_SEQ_CST); } -uae_atomic atomic_or(volatile uae_atomic * p, uae_u32 v) { +uae_atomic atomic_or(volatile uae_atomic* p, uae_u32 v) { return __atomic_or_fetch(p, v, __ATOMIC_SEQ_CST); } -uae_atomic atomic_inc(volatile uae_atomic * p) { +uae_atomic atomic_inc(volatile uae_atomic* p) { return __atomic_add_fetch(p, 1, __ATOMIC_SEQ_CST); } -uae_atomic atomic_dec(volatile uae_atomic * p) { +uae_atomic atomic_dec(volatile uae_atomic* p) { return __atomic_sub_fetch(p, 1, __ATOMIC_SEQ_CST); } -uae_u32 atomic_bit_test_and_reset(volatile uae_atomic * p, uae_u32 v) { +uae_u32 atomic_bit_test_and_reset(volatile uae_atomic* p, uae_u32 v) { uae_u32 mask = (1 << v); uae_u32 res = __atomic_fetch_and(p, ~mask, __ATOMIC_SEQ_CST); return (res & mask); @@ -165,5 +160,5 @@ void atomic_set(volatile uae_atomic* p, uae_u32 v) { int sleep_millis(int ms) { SDL_Delay(ms); - return 1; + return 1; } diff --git a/src/threaddep/thread.h b/src/threaddep/thread.h index 532493d88..e81bd0eae 100644 --- a/src/threaddep/thread.h +++ b/src/threaddep/thread.h @@ -9,18 +9,17 @@ extern int uae_sem_trywait(uae_sem_t*); extern int uae_sem_trywait_delay(uae_sem_t*, int); extern void uae_sem_post(uae_sem_t*); extern void uae_sem_unpost(uae_sem_t*); -extern void uae_sem_wait(uae_sem_t*t); +extern void uae_sem_wait(uae_sem_t* t); extern void uae_sem_init(uae_sem_t*, int manual_reset, int initial_state); -extern int uae_start_thread(const TCHAR *name, void (*f)(void *), void *arg, uae_thread_id *thread); -extern int uae_start_thread_fast(void (*f)(void *), void *arg, uae_thread_id *thread); -extern void uae_end_thread(uae_thread_id *thread); -extern void uae_set_thread_priority(uae_thread_id *, int); +extern int uae_start_thread(const TCHAR* name, void (*f)(void*), void* arg, uae_thread_id* thread); +extern int uae_start_thread_fast(void (*f)(void*), void* arg, uae_thread_id* thread); +extern void uae_end_thread(uae_thread_id* thread); +extern void uae_set_thread_priority(uae_thread_id*, int); extern uae_thread_id uae_thread_get_id(void); -//#include "commpipe.h" +// #include "commpipe.h" -inline void uae_wait_thread(uae_thread_id tid) -{ +inline void uae_wait_thread(uae_thread_id tid) { // WaitForSingleObject (tid, INFINITE); // CloseHandle (tid); } diff --git a/src/time.cpp b/src/time.cpp index b1c5971b2..289681259 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -1,6 +1,6 @@ +#include "uae/time.h" #include #include "sysdeps.h" -#include "uae/time.h" static int64_t uae_time_epoch; @@ -22,22 +22,21 @@ static int64_t time_us() { } uae_time_t uae_time(void) { - int64_t t = time_us() - uae_time_epoch; - // Will overflow in 49.71 days. Whether that is a problem depends on usage. - // Should go through all old uses of read_processor_time / uae_time and - // make sure to use overflow-safe code or move to 64-bit timestamps. - return (uae_time_t) t; + int64_t t = time_us() - uae_time_epoch; + // Will overflow in 49.71 days. Whether that is a problem depends on usage. + // Should go through all old uses of read_processor_time / uae_time and + // make sure to use overflow-safe code or move to 64-bit timestamps. + return (uae_time_t)t; } int64_t uae_time_us(void) { - // We subtrach epoch here so that this function uses the same epoch as - // the 32-bit uae_time legacy function. Maybe not necessary. - return time_us() - uae_time_epoch; + // We subtrach epoch here so that this function uses the same epoch as + // the 32-bit uae_time legacy function. Maybe not necessary. + return time_us() - uae_time_epoch; } void uae_time_init() { - if (uae_time_epoch == 0) { - uae_time_epoch = uae_time_us(); - } + if (uae_time_epoch == 0) { + uae_time_epoch = uae_time_us(); + } } - diff --git a/src/unicode.cpp b/src/unicode.cpp index aea4ed655..d2198bfda 100644 --- a/src/unicode.cpp +++ b/src/unicode.cpp @@ -6,28 +6,24 @@ #include "options.h" -char *ua (const char *s) -{ - return strdup(s); +char* ua(const char* s) { + return strdup(s); } -char *au (const char *s) -{ - return strdup(s); +char* au(const char* s) { + return strdup(s); } -char *ua_copy (char *dst, int maxlen, const TCHAR *src) -{ - strncpy(dst, src, maxlen); - dst[maxlen-1] = 0; - return dst; +char* ua_copy(char* dst, int maxlen, const TCHAR* src) { + strncpy(dst, src, maxlen); + dst[maxlen - 1] = 0; + return dst; } -TCHAR *au_copy (TCHAR *dst, int maxlen, const char *src) -{ - strncpy(dst, src, maxlen); - dst[maxlen-1] = 0; - return dst; +TCHAR* au_copy(TCHAR* dst, int maxlen, const char* src) { + strncpy(dst, src, maxlen); + dst[maxlen - 1] = 0; + return dst; } #if 0 @@ -373,11 +369,9 @@ void to_upper(TCHAR *s, int len) #endif -int uaestrlen(const char* s) -{ - return (int)strlen(s); +int uaestrlen(const char* s) { + return (int)strlen(s); } -int uaetcslen(const TCHAR* s) -{ - return (int)_tcslen(s); +int uaetcslen(const TCHAR* s) { + return (int)_tcslen(s); } diff --git a/src/winuae_compat.h b/src/winuae_compat.h index 72a8396dd..8e42f8a47 100644 --- a/src/winuae_compat.h +++ b/src/winuae_compat.h @@ -1,10 +1,8 @@ #ifndef UAE_OD_FS_WINUAE_COMPAT_H #define UAE_OD_FS_WINUAE_COMPAT_H - #ifdef WINDOWS - // Include windef.h now to get RECT and DWORD defined (and not collide with // later includes of windows.h @@ -20,7 +18,7 @@ #define _tfopen fopen #define uae_tfopen fopen -#ifdef __APPLE__ +#ifdef __APPLE__ #define _ftelli64 ftell #define _fseeki64 fseek #else @@ -38,8 +36,8 @@ #define _wunlink unlink -//#define _timezone timezone -//#define _daylight daylight +// #define _timezone timezone +// #define _daylight daylight #ifdef WINDOWS #else @@ -66,7 +64,7 @@ extern int _daylight; #define ULONG unsigned long #endif -//typedef unsigned int UAE_DWORD; +// typedef unsigned int UAE_DWORD; typedef unsigned int DWORD; typedef struct tagRECT { @@ -76,12 +74,12 @@ typedef struct tagRECT { int bottom; } RECT, *PRECT, *PPRECT; -//#ifndef WINDOWS -//#define DWORD UAE_DWORD -//#define RECT UAE_RECT -//#endif +// #ifndef WINDOWS +// #define DWORD UAE_DWORD +// #define RECT UAE_RECT +// #endif #endif // #define STATIC_INLINE static inline -#endif // UAE_OD_FS_WINUAE_COMPAT_H +#endif // UAE_OD_FS_WINUAE_COMPAT_H