Use little_endian.h in libsys4

This commit is contained in:
kichikuou
2024-05-19 10:59:50 +09:00
parent f47e5e5a82
commit 7ef9719cc7
21 changed files with 22 additions and 98 deletions
-76
View File
@@ -1,76 +0,0 @@
/* Copyright (C) 2019 Nunuhara Cabbage <nunuhara@haniwa.technology>
*
* Based on code from xsystem35
* Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
* 1998- <masaki-c@is.aist-nara.ac.jp>
*
* 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 <http://gnu.org/licenses/>.
*/
#ifndef LITTLE_ENDIAN_H
#define LITTLE_ENDIAN_H
#include <stdint.h>
// 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 */
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -18,9 +18,9 @@
#include <stdlib.h>
#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
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -20,13 +20,13 @@
#include <zlib.h>
#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"
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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"
+3 -3
View File
@@ -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;
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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"
/*
+1 -1
View File
@@ -19,7 +19,7 @@
#include <string.h>
#include <zlib.h>
#include "little_endian.h"
#include "system4/little_endian.h"
#include "system4/buffer.h"
#include "system4/file.h"
#include "system4/string.h"
+1 -1
View File
@@ -20,10 +20,10 @@
#include <errno.h>
#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"
+1 -1
View File
@@ -16,8 +16,8 @@
#include <stdlib.h>
#include <assert.h>
#include "little_endian.h"
#include "system4.h"
#include "system4/little_endian.h"
#include "system4/string.h"
#include "system4/utfsjis.h"
#include "vm/heap.h"
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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"