From 7ef9719cc7a14ee28f5fa64d9b97b82d0ccd0bee Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 19 May 2024 10:59:50 +0900 Subject: [PATCH] Use little_endian.h in libsys4 --- include/little_endian.h | 76 ---------------------------------------- include/vm.h | 2 +- src/audio_meta.c | 2 +- src/debug.c | 2 +- src/debugger_cmd.c | 2 +- src/debugger_scm.c | 2 +- src/hll/ACXLoader.c | 2 +- src/hll/BanMisc.c | 2 +- src/hll/ChrLoader.c | 2 +- src/hll/Data.c | 2 +- src/hll/File.c | 2 +- src/hll/File2.c | 6 ++-- src/hll/MapLoader.c | 2 +- src/hll/MsgSkip.c | 2 +- src/hll/PassRegister.c | 2 +- src/hll/Toushin3Loader.c | 2 +- src/hll/VSFile.c | 2 +- src/hll/iarray.c | 2 +- src/parts/flash.c | 2 +- src/system4.c | 2 +- src/vm.c | 2 +- 21 files changed, 22 insertions(+), 98 deletions(-) delete mode 100644 include/little_endian.h diff --git a/include/little_endian.h b/include/little_endian.h deleted file mode 100644 index 2727c26..0000000 --- a/include/little_endian.h +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright (C) 2019 Nunuhara Cabbage - * - * Based on code from xsystem35 - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#ifndef LITTLE_ENDIAN_H -#define LITTLE_ENDIAN_H - -#include - -// no need to decode on byte-addressable, little-endian arch -#if defined(__i386__) || defined(__x86_64__) -#define LittleEndian_getDW(b, i) (*((int32_t*)((uint8_t*)(b)+(i)))) -#define LittleEndian_getW(b, i) (*((int16_t*)((uint8_t*)(b)+(i)))) -#else -static inline int32_t LittleEndian_getDW(const uint8_t *b, int i) -{ - int c0, c1, c2, c3; - int d0, d1; - c0 = *(b + i + 0); - c1 = *(b + i + 1); - c2 = *(b + i + 2); - c3 = *(b + i + 3); - d0 = c0 + (c1 << 8); - d1 = c2 + (c3 << 8); - return d0 + (d1 << 16); -} - -static inline int16_t LittleEndian_getW(const uint8_t *b, int i) -{ - int c0, c1; - c0 = *(b + i + 0); - c1 = *(b + i + 1); - return c0 + (c1 << 8); -} -#endif /* defined(__i386__) || defined(__x86_64__) */ - -static inline int32_t LittleEndian_get3B(const uint8_t *b, int i) -{ - int c0, c1, c2; - c0 = *(b + i + 0); - c1 = *(b + i + 1); - c2 = *(b + i + 2); - return c0 + (c1 << 8) + (c2 << 16); -} - -static inline void LittleEndian_putDW(uint8_t *dst, int i, uint32_t dword) -{ - dst[i] = (uint8_t)(dword); - dst[i+1] = (uint8_t)(dword >> 8); - dst[i+2] = (uint8_t)(dword >> 16); - dst[i+3] = (uint8_t)(dword >> 24); -} - -static inline void LittleEndian_putW(uint8_t *dst, int i, uint16_t word) -{ - dst[i] = word & 0xFF; - dst[i+1] = word >> 8; -} - -#endif /* LITTLE_ENDIAN_H */ diff --git a/include/vm.h b/include/vm.h index 80682b5..2cfe68f 100644 --- a/include/vm.h +++ b/include/vm.h @@ -138,7 +138,7 @@ _Noreturn void vm_exit(int code); #endif #ifdef VM_PRIVATE -#include "little_endian.h" +#include "system4/little_endian.h" #include "system4/ain.h" struct function_call { diff --git a/src/audio_meta.c b/src/audio_meta.c index c494281..01cfb50 100644 --- a/src/audio_meta.c +++ b/src/audio_meta.c @@ -18,9 +18,9 @@ #include #include "system4.h" #include "system4/file.h" +#include "system4/little_endian.h" #include "mixer.h" -#include "little_endian.h" #include "xsystem4.h" #define BGI_MAX 100 diff --git a/src/debug.c b/src/debug.c index f285070..9369a01 100644 --- a/src/debug.c +++ b/src/debug.c @@ -25,6 +25,7 @@ #include "system4/dasm.h" #include "system4/hashtable.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "system4/utfsjis.h" @@ -33,7 +34,6 @@ #include "vm/page.h" #include "debugger.h" -#include "little_endian.h" #include "xsystem4.h" bool dbg_dap = false; diff --git a/src/debugger_cmd.c b/src/debugger_cmd.c index 807f2b5..a622f3b 100644 --- a/src/debugger_cmd.c +++ b/src/debugger_cmd.c @@ -26,6 +26,7 @@ #include "system4.h" #include "system4/file.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "system4/utfsjis.h" @@ -35,7 +36,6 @@ #include "scene.h" #include "debugger.h" -#include "little_endian.h" #include "xsystem4.h" struct dbg_cmd_node; diff --git a/src/debugger_scm.c b/src/debugger_scm.c index 7aa9544..2856b2e 100644 --- a/src/debugger_scm.c +++ b/src/debugger_scm.c @@ -23,6 +23,7 @@ #include "system4/ain.h" #include "system4/file.h" #include "system4/instructions.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "system4/utfsjis.h" #include "vm.h" @@ -30,7 +31,6 @@ #include "vm/page.h" #include "debugger.h" -#include "little_endian.h" struct variable { enum ain_data_type data_type; diff --git a/src/hll/ACXLoader.c b/src/hll/ACXLoader.c index f59c178..f1921b3 100644 --- a/src/hll/ACXLoader.c +++ b/src/hll/ACXLoader.c @@ -23,9 +23,9 @@ #include "system4/string.h" #include "system4/acx.h" #include "system4/file.h" +#include "system4/little_endian.h" #include "hll.h" -#include "little_endian.h" #include "vm/heap.h" #include "vm/page.h" #include "xsystem4.h" diff --git a/src/hll/BanMisc.c b/src/hll/BanMisc.c index d41780c..9f263e8 100644 --- a/src/hll/BanMisc.c +++ b/src/hll/BanMisc.c @@ -20,13 +20,13 @@ #include #include "system4/file.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "system4/mt19937int.h" #include "hll.h" #include "audio.h" #include "iarray.h" -#include "little_endian.h" #include "savedata.h" #include "vm/page.h" #include "xsystem4.h" diff --git a/src/hll/ChrLoader.c b/src/hll/ChrLoader.c index 75de88e..c71d7d2 100644 --- a/src/hll/ChrLoader.c +++ b/src/hll/ChrLoader.c @@ -25,7 +25,7 @@ #include "system4/hashtable.h" #include "system4/mt19937int.h" #include "system4/string.h" -#include "little_endian.h" +#include "system4/little_endian.h" #include "audio.h" #include "sact.h" diff --git a/src/hll/Data.c b/src/hll/Data.c index e56196b..26e941c 100644 --- a/src/hll/Data.c +++ b/src/hll/Data.c @@ -19,11 +19,11 @@ #include "system4/archive.h" #include "system4/buffer.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "hll.h" #include "asset_manager.h" -#include "little_endian.h" #include "vm/heap.h" #include "vm/page.h" #include "xsystem4.h" diff --git a/src/hll/File.c b/src/hll/File.c index e39f4b7..895cdb7 100644 --- a/src/hll/File.c +++ b/src/hll/File.c @@ -25,10 +25,10 @@ #include "system4.h" #include "system4/buffer.h" #include "system4/file.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "hll.h" -#include "little_endian.h" #include "savedata.h" #include "vm/heap.h" #include "vm/page.h" diff --git a/src/hll/File2.c b/src/hll/File2.c index f4736f6..9ce5208 100644 --- a/src/hll/File2.c +++ b/src/hll/File2.c @@ -22,9 +22,9 @@ #include "system4.h" #include "system4/file.h" +#include "system4/little_endian.h" #include "system4/string.h" -#include "little_endian.h" #include "hll.h" #include "xsystem4.h" @@ -149,7 +149,7 @@ static struct rea *rea_open(const char *path) goto err; } - uint32_t mdlf_size = LittleEndian_getDW(header, 28); + uint32_t mdlf_size = LittleEndian_getDW((uint8_t*)header, 28); rea->index_stream = inflate_stream_new(rea->fp, mdlf_size); if (!rea->index_stream) goto err; @@ -164,7 +164,7 @@ static struct rea *rea_open(const char *path) WARNING("%s: cannot find MDCD section", display_utf0(path)); goto err; } - rea->mdcd_size = LittleEndian_getDW(mdcd_header, 4); + rea->mdcd_size = LittleEndian_getDW((uint8_t*)mdcd_header, 4); rea->mdcd_offset = ftell(rea->fp); return rea; diff --git a/src/hll/MapLoader.c b/src/hll/MapLoader.c index 7f66dca..97d0c48 100644 --- a/src/hll/MapLoader.c +++ b/src/hll/MapLoader.c @@ -20,7 +20,7 @@ #include "system4/cg.h" #include "system4/file.h" #include "system4/mt19937int.h" -#include "little_endian.h" +#include "system4/little_endian.h" #include "hll.h" #include "sact.h" diff --git a/src/hll/MsgSkip.c b/src/hll/MsgSkip.c index c674d5d..bad8826 100644 --- a/src/hll/MsgSkip.c +++ b/src/hll/MsgSkip.c @@ -22,10 +22,10 @@ #include "system4.h" #include "system4/ain.h" #include "system4/file.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "system4/utfsjis.h" -#include "little_endian.h" #include "vm.h" #include "xsystem4.h" diff --git a/src/hll/PassRegister.c b/src/hll/PassRegister.c index c935a6f..4a4f99b 100644 --- a/src/hll/PassRegister.c +++ b/src/hll/PassRegister.c @@ -23,11 +23,11 @@ #include "system4.h" #include "system4/buffer.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "system4/file.h" #include "hll.h" -#include "little_endian.h" #include "xsystem4.h" /* diff --git a/src/hll/Toushin3Loader.c b/src/hll/Toushin3Loader.c index 2a12552..76aa486 100644 --- a/src/hll/Toushin3Loader.c +++ b/src/hll/Toushin3Loader.c @@ -19,7 +19,7 @@ #include #include -#include "little_endian.h" +#include "system4/little_endian.h" #include "system4/buffer.h" #include "system4/file.h" #include "system4/string.h" diff --git a/src/hll/VSFile.c b/src/hll/VSFile.c index 0800ce6..0bca5de 100644 --- a/src/hll/VSFile.c +++ b/src/hll/VSFile.c @@ -20,10 +20,10 @@ #include #include "system4/file.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "system4/utfsjis.h" -#include "little_endian.h" #include "hll.h" #include "xsystem4.h" diff --git a/src/hll/iarray.c b/src/hll/iarray.c index 4310dc1..73898a2 100644 --- a/src/hll/iarray.c +++ b/src/hll/iarray.c @@ -16,8 +16,8 @@ #include #include -#include "little_endian.h" #include "system4.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "system4/utfsjis.h" #include "vm/heap.h" diff --git a/src/parts/flash.c b/src/parts/flash.c index 910cdb8..69850dc 100644 --- a/src/parts/flash.c +++ b/src/parts/flash.c @@ -21,11 +21,11 @@ #include "system4.h" #include "system4/archive.h" #include "system4/hashtable.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "asset_manager.h" #include "audio.h" -#include "little_endian.h" #include "swf.h" #include "xsystem4.h" #include "parts.h" diff --git a/src/system4.c b/src/system4.c index cd9570f..0756517 100644 --- a/src/system4.c +++ b/src/system4.c @@ -30,6 +30,7 @@ #include "system4/file.h" #include "system4/ini.h" #include "system4/instructions.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "system4/utfsjis.h" @@ -38,7 +39,6 @@ #include "debugger.h" #include "gfx/gfx.h" #include "gfx/font.h" -#include "little_endian.h" #include "vm.h" #include "version.h" diff --git a/src/vm.c b/src/vm.c index 25fa910..125dc86 100644 --- a/src/vm.c +++ b/src/vm.c @@ -28,11 +28,11 @@ #include "system4/ain.h" #include "system4/instructions.h" #include "system4/file.h" +#include "system4/little_endian.h" #include "system4/string.h" #include "system4/utfsjis.h" #include "debugger.h" -#include "little_endian.h" #include "input.h" #include "savedata.h" #include "vm.h"