2009-05-21 17:48:31 +02:00
|
|
|
/* gameplaySP
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Exophase <exophase@gmail.com>
|
|
|
|
*
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMMON_H
|
|
|
|
#define COMMON_H
|
|
|
|
|
|
|
|
#define ror(dest, value, shift) \
|
2021-08-24 19:55:37 +02:00
|
|
|
dest = ((value) >> (shift)) | ((value) << (32 - (shift))) \
|
2009-05-21 17:48:31 +02:00
|
|
|
|
2021-08-27 21:38:38 +02:00
|
|
|
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
|
|
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
|
|
|
|
2014-07-14 04:54:52 +02:00
|
|
|
#if defined(_WIN32)
|
2011-09-07 22:45:45 +02:00
|
|
|
#define PATH_SEPARATOR "\\"
|
|
|
|
#define PATH_SEPARATOR_CHAR '\\'
|
|
|
|
#else
|
|
|
|
#define PATH_SEPARATOR "/"
|
|
|
|
#define PATH_SEPARATOR_CHAR '/'
|
|
|
|
#endif
|
|
|
|
|
2021-03-17 21:05:49 +01:00
|
|
|
/* On x86 we pass arguments via registers instead of stack */
|
2021-03-06 21:15:22 +01:00
|
|
|
#ifdef X86_ARCH
|
|
|
|
#define function_cc __attribute__((regparm(2)))
|
|
|
|
#else
|
|
|
|
#define function_cc
|
|
|
|
#endif
|
|
|
|
|
2009-05-21 17:48:31 +02:00
|
|
|
#ifdef ARM_ARCH
|
|
|
|
|
2014-07-14 04:54:52 +02:00
|
|
|
#define _BSD_SOURCE // sync
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/time.h>
|
2009-05-21 17:48:31 +02:00
|
|
|
|
|
|
|
#endif /* ARM_ARCH */
|
|
|
|
|
|
|
|
// Huge thanks to pollux for the heads up on using native file I/O
|
|
|
|
// functions on PSP for vastly improved memstick performance.
|
|
|
|
|
2019-09-19 18:48:21 +02:00
|
|
|
#ifdef PSP
|
2009-05-21 17:48:31 +02:00
|
|
|
#include <pspkernel.h>
|
|
|
|
#include <pspdebug.h>
|
|
|
|
#include <pspctrl.h>
|
|
|
|
#include <pspgu.h>
|
|
|
|
#include <pspaudio.h>
|
|
|
|
#include <pspaudiolib.h>
|
|
|
|
#include <psprtc.h>
|
|
|
|
#include <time.h>
|
2014-12-09 00:17:28 +01:00
|
|
|
#else
|
2009-05-21 17:48:31 +02:00
|
|
|
typedef unsigned char u8;
|
|
|
|
typedef signed char s8;
|
|
|
|
typedef unsigned short int u16;
|
|
|
|
typedef signed short int s16;
|
2011-09-02 23:58:39 +02:00
|
|
|
typedef unsigned int u32;
|
|
|
|
typedef signed int s32;
|
2009-05-21 17:48:31 +02:00
|
|
|
typedef unsigned long long int u64;
|
|
|
|
typedef signed long long int s64;
|
2021-03-17 21:05:49 +01:00
|
|
|
#endif
|
2009-05-21 17:48:31 +02:00
|
|
|
|
2023-08-31 00:26:42 +02:00
|
|
|
#if defined(USE_XBGR1555_FORMAT)
|
2021-07-07 00:51:29 +02:00
|
|
|
#define convert_palette(value) \
|
2021-08-24 17:15:27 +02:00
|
|
|
(value & 0x7FFF)
|
2023-12-13 07:47:11 +01:00
|
|
|
#elif defined(USE_RGBA5551_FORMAT)
|
|
|
|
#define convert_palette(value) \
|
|
|
|
(((value & 0x1F) << 11) | ((value & 0x03E0) << 1) | ((value & 0x7C00) >> 9) | 1)
|
2021-03-17 21:05:49 +01:00
|
|
|
#else
|
2021-03-10 18:39:43 +01:00
|
|
|
#define convert_palette(value) \
|
2021-11-13 00:52:21 +01:00
|
|
|
(((value & 0x1F) << 11) | ((value & 0x03E0) << 1) | ((value >> 10) & 0x1F))
|
2009-05-21 17:48:31 +02:00
|
|
|
#endif
|
|
|
|
|
2019-09-19 18:48:21 +02:00
|
|
|
#define GBA_SCREEN_WIDTH (240)
|
|
|
|
#define GBA_SCREEN_HEIGHT (160)
|
|
|
|
#define GBA_SCREEN_PITCH (240)
|
|
|
|
|
2023-08-18 03:30:14 +02:00
|
|
|
// The buffer is 16 bit color depth.
|
|
|
|
// We reserve extra memory at the end for extra effects (winobj rendering).
|
2023-07-28 19:35:33 +02:00
|
|
|
#define GBA_SCREEN_BUFFER_SIZE \
|
|
|
|
(GBA_SCREEN_PITCH * (GBA_SCREEN_HEIGHT + 1) * sizeof(uint16_t))
|
|
|
|
|
2009-05-21 17:48:31 +02:00
|
|
|
|
|
|
|
typedef u32 fixed16_16;
|
2011-09-06 19:18:34 +02:00
|
|
|
typedef u32 fixed8_24;
|
2009-05-21 17:48:31 +02:00
|
|
|
|
|
|
|
#define float_to_fp16_16(value) \
|
|
|
|
(fixed16_16)((value) * 65536.0) \
|
|
|
|
|
|
|
|
#define fp16_16_to_float(value) \
|
|
|
|
(float)((value) / 65536.0) \
|
|
|
|
|
|
|
|
#define u32_to_fp16_16(value) \
|
|
|
|
((value) << 16) \
|
|
|
|
|
|
|
|
#define fp16_16_to_u32(value) \
|
|
|
|
((value) >> 16) \
|
|
|
|
|
|
|
|
#define fp16_16_fractional_part(value) \
|
|
|
|
((value) & 0xFFFF) \
|
|
|
|
|
2011-09-06 19:18:34 +02:00
|
|
|
#define float_to_fp8_24(value) \
|
|
|
|
(fixed8_24)((value) * 16777216.0) \
|
|
|
|
|
|
|
|
#define fp8_24_fractional_part(value) \
|
|
|
|
((value) & 0xFFFFFF) \
|
|
|
|
|
2009-05-21 17:48:31 +02:00
|
|
|
#define fixed_div(numerator, denominator, bits) \
|
|
|
|
(((numerator * (1 << bits)) + (denominator / 2)) / denominator) \
|
|
|
|
|
|
|
|
#define address8(base, offset) \
|
|
|
|
*((u8 *)((u8 *)base + (offset))) \
|
|
|
|
|
|
|
|
#define address16(base, offset) \
|
|
|
|
*((u16 *)((u8 *)base + (offset))) \
|
|
|
|
|
|
|
|
#define address32(base, offset) \
|
|
|
|
*((u32 *)((u8 *)base + (offset))) \
|
|
|
|
|
2021-06-27 01:16:28 +02:00
|
|
|
#define eswap8(value) (value)
|
|
|
|
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
|
|
#define eswap16(value) __builtin_bswap16(value)
|
|
|
|
#define eswap32(value) __builtin_bswap32(value)
|
|
|
|
#else
|
|
|
|
#define eswap16(value) (value)
|
|
|
|
#define eswap32(value) (value)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define readaddress8(base, offset) eswap8( address8( base, offset))
|
|
|
|
#define readaddress16(base, offset) eswap16(address16(base, offset))
|
|
|
|
#define readaddress32(base, offset) eswap32(address32(base, offset))
|
|
|
|
|
|
|
|
#define read_ioreg(regnum) (eswap16(io_registers[(regnum)]))
|
|
|
|
#define write_ioreg(regnum, val) io_registers[(regnum)] = eswap16(val)
|
2023-04-19 23:22:18 +02:00
|
|
|
#define read_ioreg32(regnum) (read_ioreg(regnum) | (read_ioreg((regnum)+1) << 16))
|
2021-06-27 01:16:28 +02:00
|
|
|
|
2021-08-21 18:10:12 +02:00
|
|
|
#define read_dmareg(regnum, dmachan) (eswap16(io_registers[(regnum) + (dmachan) * 6]))
|
|
|
|
#define write_dmareg(regnum, dmachan, val) io_registers[(regnum) + (dmachan) * 6] = eswap16(val)
|
|
|
|
|
2009-05-21 17:48:31 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "cpu.h"
|
2014-12-10 01:03:14 +01:00
|
|
|
#include "gba_memory.h"
|
2021-08-24 17:15:27 +02:00
|
|
|
#include "savestate.h"
|
2009-05-21 17:48:31 +02:00
|
|
|
#include "video.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "cheats.h"
|
|
|
|
|
|
|
|
#endif
|