다마고치 연구소 한국어판 소스 공개
This commit is contained in:
commit
db23855630
661 files changed
+503597
No files matched your search
@@ -0,0 +1,41 @@
|
||||
# PokeMiniEmu
|
||||
|
||||
The Pokemon mini on the Tamagotchi Paradise, as a further program of the Paramix menu.
|
||||
No game and no BIOS here: bring your own games (.min). Without an own BIOS the free BIOS of PokeMini runs.
|
||||
|
||||
- `src/core`: PokeMini by JustBurn (GPL 3 or later, `LICENSE_pokemini`), libretro version, commit 132111b. Taken:
|
||||
the CPU (MinxCPU*), PRC (picture chip), LCD, timers, IRQ, I/O (keys, EEPROM, RTC), sound registers, Hardware.c,
|
||||
FreeBIOS. `pm_glue.c` replaces PokeMini.c and PMCommon.c (no files, no colour PRC, no multicart): create, reset, the
|
||||
cartridge in the flash window (`pm_set_rom`), the clock (`pm_set_time`), the state in a buffer (`pm_state_save`,
|
||||
`pm_state_load`, PokeMini's sections without the colour part). Changes in the core files are marked "PokeMiniEmu":
|
||||
`MinxLCD.c` without Video.h, `Hardware.c` with `PM_SYNCCYCLES` and `PM_FASTLCD`, `MinxAudio.c` with `pm_audio_now`.
|
||||
- `src/stub`: the few C library headers the core needs, and a small memory stream.
|
||||
- `src/app/main.c`: the Paradise program (PRAM, about 62 KB). Settings block "PMXP" at 0x140: game, length, save
|
||||
(64 KB: 4 KB settings of the device, 8 KB EEPROM, the state up to 36 KB, an own BIOS at +0xC000), flags (bit 0
|
||||
English, bit 1 wheel the other way round, bit 2 own BIOS), name, keys (12 x u16, see below), place of the BIOS.
|
||||
- Screen: 96 x 64 to 128 x 85 from y 21 (3 dots to 4: a, (a+2b)/3, (2b+c)/3, c, both ways). PM_FASTLCD: the program
|
||||
reads the LCD memory itself for every second frame and mixes it with the frame before (dot on in one of the two:
|
||||
grey), the core's per-dot buffers and the analog decay are left out (18 % of the time). The contrast of the game
|
||||
sets the two shades.
|
||||
- Keys: `keys[i]` are Pokemon mini buttons (1 A, 2 B, 4 C, 8 up, 16 down, 32 left, 64 right, 128 power, 256 shake)
|
||||
for the Paradise input i: 0 A, 1 B, 2 C, 3 wheel press, 4 wheel up, 5 wheel down, 6 A+C, 7 B+C, 8 A+B. Default: A
|
||||
left, B = B, C right, wheel press = A, wheel up/down, A+C = C, A+B shake. Fixed: A+B+C settings (power, colour,
|
||||
sound, light, dim, screen off, restart game, language); wheel held 2 s = save and back to the Paradise.
|
||||
- Sound: timer 3 of the Pokemon mini drives its piezo; its frequency (and silence at volume 0 or a pulse of 0 or
|
||||
100 %) goes to the Paradise's buzzer once per frame.
|
||||
- Save: the EEPROM goes to the flash 3 s after the game wrote it (1 s without a key), when the screen goes off and on
|
||||
leaving. On leaving the whole state too (`emu/src/emu/pstate.h`), read once at the next start.
|
||||
- Clock: a new start sets the Pokemon mini's clock from the Paradise's time (the games still ask for their own time
|
||||
once). The seconds counter keeps running while the game waits (settings, screen off, back in the Paradise): the
|
||||
seconds of the Paradise's counter are added when it goes on.
|
||||
- Speed (Unicorn simulation, 96 MHz): all 13 tried games at full speed (72 frames a second), 3 to 10 ms per frame.
|
||||
|
||||
Build: `sh src/app/build.sh` (clang, lld) gives `pm.bin`.
|
||||
Test: `python3 test/mkimg.py pm.bin game.min img.bin [flags] [bios.min]` then
|
||||
`python3 test/devpm.py src/app/pm.elf img.bin <ms>` (KEYS="t:mask,...", SHOTS="t,...", OUT=dir); `test/prof.py`
|
||||
counts instructions per function.
|
||||
|
||||
Author: mameise
|
||||
|
||||
No session (1.7.3 test7, switch SESS_FLAG): flags bit 12 set by the Studio ("Remember where you left off" off): leaving writes
|
||||
no state, a start drops an old one; only the game's own save (cartridge RAM or EEPROM) is kept.
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
# Build PokeMiniEmu for the Paradise (clang/lld, Cortex-M3). Output: ../../pm.bin
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
E=../../../emu/src/emu
|
||||
C=../core
|
||||
CF="--target=thumbv7m-none-eabi -mcpu=cortex-m3 -mthumb -ffreestanding -nostdlib -fno-common -Wall -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-parentheses -Wno-dangling-else -fno-builtin-memset -ffunction-sections -isystem ../stub -I$C -DPERFORMANCE -DPM_SYNCCYCLES=64 -DPM_FASTLCD -DPM_HEAP=0x7400 -DFAST_LCD -DEXIT_KEY -DLCD_FASTCLK -DTONE_FIX -DHW_TONE_RESTART -DBL_SLEEP -DPARA_BACK -DPARA_MB_KEEP -DBL_PWM -DBL_MR3RST -DTONE_SAFE -DGPLAY -DSESS_FLAG $XCF"
|
||||
O=""
|
||||
for f in main.c $C/*.c $E/hw.c $E/flash.c $E/libc.c; do
|
||||
n=$(basename $f .c); OPT=-Os
|
||||
case $n in MinxCPU*|Hardware|MinxPRC|MinxTimers|MinxIRQ) OPT=-O2;; esac
|
||||
clang $CF $OPT -c $f -o $n.o; O="$O $n.o"; done
|
||||
ld.lld -T link.ld --gc-sections --no-rosegment $O -o pm.elf
|
||||
llvm-objcopy -O binary -j .text -j .data -j .init pm.elf pm.bin
|
||||
cp pm.bin ../../pm.bin; rm -f *.o pm.bin; [ -n "$KEEPELF" ] || rm -f pm.elf; ls -l ../../pm.bin
|
||||
@@ -0,0 +1,99 @@
|
||||
/* generated by gen/font.py: custom 5x7 font */
|
||||
static const unsigned char g_font[96][7]={
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x04,0x04,0x04,0x04,0x04,0x00,0x04},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x19,0x19,0x02,0x04,0x08,0x13,0x13},
|
||||
{0x0c,0x12,0x14,0x08,0x15,0x12,0x0d},
|
||||
{0x04,0x04,0x08,0x00,0x00,0x00,0x00},
|
||||
{0x02,0x04,0x08,0x08,0x08,0x04,0x02},
|
||||
{0x08,0x04,0x02,0x02,0x02,0x04,0x08},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x04,0x04,0x1f,0x04,0x04,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x0c,0x04,0x08},
|
||||
{0x00,0x00,0x00,0x1f,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x0c,0x0c},
|
||||
{0x01,0x01,0x02,0x04,0x08,0x10,0x10},
|
||||
{0x0e,0x11,0x13,0x15,0x19,0x11,0x0e},
|
||||
{0x04,0x0c,0x04,0x04,0x04,0x04,0x0e},
|
||||
{0x0e,0x11,0x01,0x02,0x04,0x08,0x1f},
|
||||
{0x1e,0x01,0x01,0x0e,0x01,0x01,0x1e},
|
||||
{0x02,0x06,0x0a,0x12,0x1f,0x02,0x02},
|
||||
{0x1f,0x10,0x1e,0x01,0x01,0x11,0x0e},
|
||||
{0x0e,0x10,0x10,0x1e,0x11,0x11,0x0e},
|
||||
{0x1f,0x01,0x02,0x04,0x08,0x08,0x08},
|
||||
{0x0e,0x11,0x11,0x0e,0x11,0x11,0x0e},
|
||||
{0x0e,0x11,0x11,0x0f,0x01,0x01,0x0e},
|
||||
{0x00,0x04,0x04,0x00,0x04,0x04,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x02,0x04,0x08,0x10,0x08,0x04,0x02},
|
||||
{0x00,0x00,0x1f,0x00,0x1f,0x00,0x00},
|
||||
{0x08,0x04,0x02,0x01,0x02,0x04,0x08},
|
||||
{0x0e,0x11,0x01,0x02,0x04,0x00,0x04},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x0e,0x11,0x11,0x1f,0x11,0x11,0x11},
|
||||
{0x1e,0x11,0x11,0x1e,0x11,0x11,0x1e},
|
||||
{0x0e,0x11,0x10,0x10,0x10,0x11,0x0e},
|
||||
{0x1e,0x11,0x11,0x11,0x11,0x11,0x1e},
|
||||
{0x1f,0x10,0x10,0x1e,0x10,0x10,0x1f},
|
||||
{0x1f,0x10,0x10,0x1e,0x10,0x10,0x10},
|
||||
{0x0e,0x11,0x10,0x17,0x11,0x11,0x0f},
|
||||
{0x11,0x11,0x11,0x1f,0x11,0x11,0x11},
|
||||
{0x0e,0x04,0x04,0x04,0x04,0x04,0x0e},
|
||||
{0x07,0x02,0x02,0x02,0x02,0x12,0x0c},
|
||||
{0x11,0x12,0x14,0x18,0x14,0x12,0x11},
|
||||
{0x10,0x10,0x10,0x10,0x10,0x10,0x1f},
|
||||
{0x11,0x1b,0x15,0x15,0x11,0x11,0x11},
|
||||
{0x11,0x19,0x15,0x13,0x11,0x11,0x11},
|
||||
{0x0e,0x11,0x11,0x11,0x11,0x11,0x0e},
|
||||
{0x1e,0x11,0x11,0x1e,0x10,0x10,0x10},
|
||||
{0x0e,0x11,0x11,0x11,0x15,0x12,0x0d},
|
||||
{0x1e,0x11,0x11,0x1e,0x14,0x12,0x11},
|
||||
{0x0f,0x10,0x10,0x0e,0x01,0x01,0x1e},
|
||||
{0x1f,0x04,0x04,0x04,0x04,0x04,0x04},
|
||||
{0x11,0x11,0x11,0x11,0x11,0x11,0x0e},
|
||||
{0x11,0x11,0x11,0x11,0x11,0x0a,0x04},
|
||||
{0x11,0x11,0x11,0x15,0x15,0x15,0x0a},
|
||||
{0x11,0x11,0x0a,0x04,0x0a,0x11,0x11},
|
||||
{0x11,0x11,0x0a,0x04,0x04,0x04,0x04},
|
||||
{0x1f,0x01,0x02,0x04,0x08,0x10,0x1f},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x11,0x0a,0x04,0x0a,0x11},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x11,0x0e,0x11,0x1f,0x11,0x11,0x11},
|
||||
{0x11,0x0e,0x11,0x11,0x11,0x11,0x0e},
|
||||
{0x11,0x00,0x11,0x11,0x11,0x11,0x0e},
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
ENTRY(Reset_Handler)
|
||||
MEMORY {
|
||||
PRAM (rwx) : ORIGIN = 0x00000000, LENGTH = 0x10000
|
||||
SRAM (rw) : ORIGIN = 0x18000000, LENGTH = 0x1F000
|
||||
}
|
||||
SECTIONS {
|
||||
.text : {
|
||||
KEEP(*(.vectors))
|
||||
KEEP(*(.pmxcfg))
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
. = ALIGN(4);
|
||||
__pdata_start = .;
|
||||
} > PRAM
|
||||
.bss (NOLOAD) : { __bss_start = .; *(.bss*) *(COMMON) . = ALIGN(4); __bss_end = .; } > SRAM
|
||||
/* mutable data in SRAM (initial values in PRAM, copied at startup), as in TamaEmu */
|
||||
.data : { __data_start = .; *(.data*) . = ALIGN(4); __data_end = .; } > SRAM AT > PRAM
|
||||
__data_load = LOADADDR(.data);
|
||||
.init : { . = ALIGN(4); KEEP(*(.initcode)) KEEP(*(.initdata*)) KEEP(*(.initcode_z)) . = ALIGN(4); __prog_end = .; } > PRAM
|
||||
ASSERT(__prog_end <= 0x10000, "program too big for PRAM")
|
||||
ASSERT(__bss_end <= 0x1801F000, "RAM full")
|
||||
/DISCARD/ : { *(.comment) *(.ARM.*) *(.note*) }
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
/* PokeMiniEmu: the Pokemon mini on the Tamagotchi Paradise. Core: PokeMini by JustBurn (GPL 3 or later), see ../core.
|
||||
* Started from the Paramix menu like the other further programs. Bring your own games (.min); the BIOS is the free one
|
||||
* of PokeMini unless the Studio put your own in.
|
||||
* Screen: 96 x 64 grown to 128 x 85 (3 dots to 4, mixed), with the grey shades of the real LCD (the core's analog LCD).
|
||||
* Keys: set in the Studio (tab Pokemon mini), stored in the settings block. A+B+C together: settings (also POWER and
|
||||
* sound); wheel held 2 s: save and back to the Paradise. Sound: the Paradise's buzzer plays the Pokemon mini's tone.
|
||||
* Save: the EEPROM (the games' saves) goes to the flash a few seconds after the game wrote it, and on leaving; on
|
||||
* leaving the whole state too, the next start continues there.
|
||||
* Author: mameise */
|
||||
#include "../../../emu/src/emu/hw.h"
|
||||
#include "../../../emu/src/emu/exitkey.h"
|
||||
#include "../../../emu/src/emu/flash.h"
|
||||
#define PARA_ATTR
|
||||
#include "../../../emu/src/emu/paraclock.h"
|
||||
#ifdef PARA_BACK
|
||||
#include "../../../emu/src/emu/paraback.h"
|
||||
#ifdef GPLAY
|
||||
#define GP_POINTS
|
||||
#include "../../../emu/src/emu/gplay.h"
|
||||
#endif
|
||||
#endif
|
||||
#include "PokeMini.h"
|
||||
#include "Hardware.h"
|
||||
#include "font.h"
|
||||
typedef int s32;
|
||||
|
||||
/* ---- settings block at 0x140, filled in by the Studio ----
|
||||
* keys[i]: Pokemon mini buttons (bit 0 A, 1 B, 2 C, 3 UP, 4 DOWN, 5 LEFT, 6 RIGHT, 7 POWER, 8 SHAKE) for the Paradise
|
||||
* input i: 0 A, 1 B, 2 C, 3 wheel press, 4 wheel up, 5 wheel down, 6 A+C, 7 B+C, 8 A+B.
|
||||
* flags: bit 0 English, bit 1 wheel the other way round, bit 2 own BIOS at bios_off.
|
||||
* save_off: 4 KB settings of the device, 8 KB EEPROM, then the state (up to 36 KB). */
|
||||
#define NIN 9
|
||||
typedef struct { u32 magic, version, rom_off, rom_len, save_off, flags; char name[16]; u16 keys[12]; u32 bios_off; } PmCfg;
|
||||
#define PM_MAGIC 0x50584D50u /* "PMXP" */
|
||||
__attribute__((section(".pmxcfg"), used))
|
||||
volatile const PmCfg g_cfg = { PM_MAGIC, 1, 0, 0, 0, 0, {0}, { 0x020, 0x002, 0x040, 0x001, 0x008, 0x010, 0x004, 0x000, 0x100 }, 0 };
|
||||
#define SETTINGS (g_cfg.save_off)
|
||||
#define EEP_AT (g_cfg.save_off + 0x1000u)
|
||||
#define STATE_AT (g_cfg.save_off + 0x3000u)
|
||||
#define STATE_MAX 0x9000u
|
||||
#define STATE_N 0x7400u
|
||||
#define XIP_BASE_REG REG(0x4002F004u)
|
||||
#define XIP_CTRL_REG REG(0x4002F000u)
|
||||
#define ROMWIN ((const u8 *)0x10000000u)
|
||||
void pm_set_rom(const uint8_t *rom, uint32_t len);
|
||||
void pm_set_time(int y, int mo, int d, int h, int mi, int s);
|
||||
uint32_t pm_state_save(uint8_t *buf, uint32_t size);
|
||||
int pm_state_load(uint8_t *buf, uint32_t size);
|
||||
void pm_audio_now(int *hz, int *vol);
|
||||
extern int PokeMini_EEPROMWritten;
|
||||
|
||||
/* ---- time: SysTick 1 ms; the wheel's encoder is read here too ---- */
|
||||
static volatile u32 g_ms;
|
||||
static volatile s32 g_enc_acc; static u32 g_enc_last;
|
||||
static const signed char QD[16] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 };
|
||||
#define GPIO2 0x4001A000u
|
||||
#define SYST_CSR REG(0xE000E010u)
|
||||
#define SYST_RVR REG(0xE000E014u)
|
||||
#define SYST_CVR REG(0xE000E018u)
|
||||
#define CORE_HZ 96000000u
|
||||
__attribute__((used)) void systick_c(void)
|
||||
{
|
||||
g_ms++;
|
||||
u32 n = REG(GPIO2) & 3u;
|
||||
if (n != g_enc_last) { g_enc_acc += QD[(g_enc_last << 2) | n]; g_enc_last = n; }
|
||||
}
|
||||
__attribute__((naked)) void SysTick_Handler(void) { __asm__ volatile("b systick_c\n"); }
|
||||
void abort(void) { for (;;) hw_wdt_feed(); }
|
||||
|
||||
/* ---- settings on the device ---- */
|
||||
typedef struct { u8 magic[4]; u8 pal, dim, lang, dimto, off, r0, skip, mute; } PmSet; /* mute: 0 = sound on */
|
||||
static PmSet g_set = { {'P','M','S','1'}, 0, 7, 0, 6, 3, 0x80, 0, 0 };
|
||||
/* light to dark: grey green (as the real LCD), grey, yellow, blue */
|
||||
static const u16 PAL[4][2] = { { 0xB6B1u, 0x1903u }, { 0xE71Cu, 0x10A2u }, { 0xFFF4u, 0x2100u }, { 0xDF5Fu, 0x0846u } };
|
||||
static const char *const PAL_NM[2][4] = { { "LCD", "GRAU", "GELB", "BLAU" }, { "LCD", "GREY", "YELLOW", "BLUE" } };
|
||||
#define T_N 7
|
||||
static const u32 T_MS[T_N] = { 10000u, 20000u, 30000u, 60000u, 120000u, 300000u, 600000u };
|
||||
static const char *const T_NM[2][T_N + 1] = { { "10 S", "20 S", "30 S", "1 MIN", "2 MIN", "5 MIN", "10 MIN", "NIE" }, { "10 S", "20 S", "30 S", "1 MIN", "2 MIN", "5 MIN", "10 MIN", "NEVER" } };
|
||||
#define LV_N 11
|
||||
#define DIM2_N 10
|
||||
static const u8 LV_PCT[LV_N] = { 100u, 5u, 10u, 20u, 30u, 40u, 50u, 60u, 70u, 80u, 90u };
|
||||
static const u8 DIM2_PCT[DIM2_N] = { 1u, 2u, 3u, 5u, 10u, 15u, 20u, 30u, 40u, 50u };
|
||||
static int en(void) { return g_set.lang ? g_set.lang == 2u : (int)(g_cfg.flags & 1u); }
|
||||
static u16 BG, INK, OFF;
|
||||
static u16 g_lut[256]; /* LCD intensity (0 light .. 255 dark) to colour */
|
||||
static int g_dimmed, g_redraw;
|
||||
static u16 mix(u16 a, u16 b, int p, int q) /* a + (b - a) * p / q */
|
||||
{
|
||||
int r = (a >> 11) + (((b >> 11) - (a >> 11)) * p) / q, g = ((a >> 5) & 63) + ((((b >> 5) & 63) - ((a >> 5) & 63)) * p) / q;
|
||||
int bl = (a & 31) + (((b & 31) - (a & 31)) * p) / q;
|
||||
return (u16)((r << 11) | (g << 5) | bl);
|
||||
}
|
||||
static void colours(void)
|
||||
{
|
||||
const u16 *p = PAL[g_set.pal & 3u];
|
||||
for (int v = 0; v < 256; v++) g_lut[v] = mix(p[0], p[1], v, 255);
|
||||
BG = p[0]; INK = p[1]; OFF = g_lut[150];
|
||||
#ifdef BL_PWM
|
||||
{ u32 l = LV_PCT[(g_set.r0 & 15u) % LV_N], d = DIM2_PCT[g_set.dimto % DIM2_N];
|
||||
hw_bl_set(g_dimmed ? (d < l ? d : l) : l); }
|
||||
#endif
|
||||
g_redraw = 1;
|
||||
}
|
||||
static u8 g_sec[0x1000] __attribute__((aligned(4)));
|
||||
static void set_load(void)
|
||||
{
|
||||
const volatile u8 *p = XIP_PTR(SETTINGS); PmSet t; u8 *d = (u8 *)&t;
|
||||
for (u32 i = 0; i < sizeof t; i++) d[i] = p[i];
|
||||
if (t.magic[0] == 'P' && t.magic[1] == 'M' && t.magic[2] == 'S' && t.magic[3] == '1' && t.pal < 4u && t.dim <= T_N && t.off <= T_N && t.lang < 3u) g_set = t;
|
||||
colours();
|
||||
}
|
||||
static void set_store(void)
|
||||
{
|
||||
for (u32 i = 0; i < sizeof g_sec; i++) g_sec[i] = 0xFF;
|
||||
const u8 *s = (const u8 *)&g_set; for (u32 i = 0; i < sizeof g_set; i++) g_sec[i] = s[i];
|
||||
flash_update4k(SETTINGS, g_sec);
|
||||
}
|
||||
|
||||
/* ---- EEPROM (the games' saves, 8 KB) ---- */
|
||||
static u32 g_tone_now;
|
||||
static void tone(u32 hz) { if (hz != g_tone_now) { if (hz && g_tone_now) hw_tone(0); g_tone_now = hz; hw_tone(hz); } }
|
||||
static void eep_load(void)
|
||||
{
|
||||
const volatile u8 *p = XIP_PTR(EEP_AT); int any = 0;
|
||||
for (u32 i = 0; i < 0x2000u; i++) { u8 v = p[i]; EEPROM[i] = v; if (v != 0xFF) any = 1; }
|
||||
(void)any; /* a fresh area (all 0xFF) is a fresh EEPROM, as PokeMini formats it */
|
||||
}
|
||||
static void eep_store(void)
|
||||
{
|
||||
for (u32 o = 0; o < 0x2000u; o += 0x1000u) {
|
||||
for (u32 i = 0; i < 0x1000u; i++) g_sec[i] = EEPROM[o + i];
|
||||
tone(0); flash_update4k(EEP_AT + o, g_sec);
|
||||
}
|
||||
PokeMini_EEPROMWritten = 0;
|
||||
}
|
||||
|
||||
/* ---- screen: 96 x 64 to 128 x 85 (3 dots to 4: a, (a+2b)/3, (2b+c)/3, c), from y 21 ---- */
|
||||
#define OY 21
|
||||
#define OH 85
|
||||
static u8 g_fb[OH][128] __attribute__((aligned(4))); /* intensity 0..255 */
|
||||
static u16 g_row[128] __attribute__((aligned(4)));
|
||||
static int g_dirty_lo = OH, g_dirty_hi = -1;
|
||||
static u8 g_hl[3][128]; /* the three source rows of a group, grown across */
|
||||
static void grow_row(const u8 *s, u8 *d)
|
||||
{
|
||||
for (int k = 0; k < 32; k++, s += 3, d += 4) {
|
||||
u32 a = s[0], b = s[1], c = s[2];
|
||||
d[0] = (u8)a; d[1] = (u8)((a + 2u * b) / 3u); d[2] = (u8)((2u * b + c) / 3u); d[3] = (u8)c;
|
||||
}
|
||||
}
|
||||
static void out_row(int r, const u8 *v)
|
||||
{
|
||||
if (r >= OH) return;
|
||||
u32 *f = (u32 *)g_fb[r], d = 0; const u32 *w = (const u32 *)v;
|
||||
for (int x = 0; x < 32; x++) { d |= f[x] ^ w[x]; f[x] = w[x]; }
|
||||
if (d) { if (r < g_dirty_lo) g_dirty_lo = r; if (r > g_dirty_hi) g_dirty_hi = r; }
|
||||
}
|
||||
#ifdef PM_FASTLCD
|
||||
/* the LCD memory (8 pages of 96 columns, one bit per dot) of the frame before the shown one: dots on in one of the two
|
||||
* frames are grey (games make their grey by switching dots every frame) */
|
||||
static u8 g_prev[8 * 96], g_src[96 * 64] __attribute__((aligned(4)));
|
||||
static void lcd_snap(void) { for (int p = 0; p < 8; p++) for (int x = 0; x < 96; x++) g_prev[p * 96 + x] = LCDData[p * 256 + x]; }
|
||||
static void lcd_mix(void)
|
||||
{
|
||||
if (!MinxLCD.DisplayOn) { for (int i = 0; i < 96 * 64; i++) g_src[i] = 0; return; }
|
||||
u8 lv[3]; int p0 = MinxLCD.Pixel0Intensity, p1 = MinxLCD.Pixel1Intensity;
|
||||
lv[0] = (u8)p0; lv[1] = (u8)((p0 + p1) / 2); lv[2] = (u8)p1;
|
||||
u32 inv = MinxLCD.InvAllPix & 1u, set = MinxLCD.SetAllPix & 1u;
|
||||
for (int y = 0; y < 64; y++) {
|
||||
int yp = (y + MinxLCD.StartLine) & 63; if (MinxLCD.RowOrder) yp = 63 - yp;
|
||||
const u8 *c = LCDData + (yp >> 3) * 256, *q = g_prev + (yp >> 3) * 96; u32 sh = (u32)yp & 7u; u8 *d = g_src + y * 96;
|
||||
for (int x = 0; x < 96; x++) { u32 a = (((c[x] >> sh) & 1u) ^ inv) | set, b = (((q[x] >> sh) & 1u) ^ inv) | set; d[x] = lv[a + b]; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
static void frame_grow(void)
|
||||
{
|
||||
#ifdef PM_FASTLCD
|
||||
const u8 *src = g_src;
|
||||
#else
|
||||
const u8 *src = LCDPixelsA;
|
||||
#endif
|
||||
static u8 t[128] __attribute__((aligned(4)));
|
||||
for (int g = 0; g < 22; g++) { /* rows 3g..3g+2 to 4g..4g+3 (the last group has row 63 only) */
|
||||
int n = g < 21 ? 3 : 1;
|
||||
for (int i = 0; i < n; i++) grow_row(src + (3 * g + i) * 96, g_hl[i]);
|
||||
out_row(4 * g, g_hl[0]);
|
||||
if (n < 3) break;
|
||||
for (int x = 0; x < 128; x++) t[x] = (u8)((g_hl[0][x] + 2u * g_hl[1][x]) / 3u);
|
||||
out_row(4 * g + 1, t);
|
||||
for (int x = 0; x < 128; x++) t[x] = (u8)((2u * g_hl[1][x] + g_hl[2][x]) / 3u);
|
||||
out_row(4 * g + 2, t);
|
||||
out_row(4 * g + 3, g_hl[2]);
|
||||
}
|
||||
}
|
||||
static void push(int all)
|
||||
{
|
||||
if (g_redraw) { g_redraw = 0; all = 1; }
|
||||
int lo = all ? 0 : g_dirty_lo, hi = all ? OH - 1 : g_dirty_hi;
|
||||
if (all) { /* the bars */
|
||||
for (int x = 0; x < 128; x++) g_row[x] = BG;
|
||||
hw_px_begin(0, 0, 128, OY); for (int y = 0; y < OY; y++) hw_px_row(g_row, 128); hw_px_end();
|
||||
hw_px_begin(0, OY + OH, 128, 128); for (int y = OY + OH; y < 128; y++) hw_px_row(g_row, 128); hw_px_end();
|
||||
}
|
||||
if (lo > hi) return;
|
||||
hw_px_begin(0, (u32)(OY + lo), 128, (u32)(OY + hi + 1));
|
||||
for (int y = lo; y <= hi; y++) { const u8 *f = g_fb[y]; for (int x = 0; x < 128; x++) g_row[x] = g_lut[f[x]]; hw_px_row(g_row, 128); }
|
||||
hw_px_end();
|
||||
g_dirty_lo = OH; g_dirty_hi = -1;
|
||||
}
|
||||
|
||||
/* ---- the settings menu (A+B+C): A next line, B change, C close ---- */
|
||||
static int g_menu, g_msel, g_mtop;
|
||||
static void text(int x, int y, const char *s, u16 col, u16 *row, int ry)
|
||||
{
|
||||
for (; *s; s++, x += 6) {
|
||||
int c = (unsigned char)*s; if (c >= 97 && c <= 122) c -= 32; c = (c < 32 || c > 127) ? 0 : c - 32;
|
||||
if (ry < y || ry >= y + 7) continue;
|
||||
u8 bits = g_font[c][ry - y];
|
||||
for (int k = 0; k < 5; k++) if ((bits & (0x10 >> k)) && x + k >= 0 && x + k < 128) row[x + k] = col;
|
||||
}
|
||||
}
|
||||
enum { M_POW, M_PAL, M_SND, M_LIGHT, M_DIM, M_DIMTO, M_OFF, M_RESET, M_LANG, M_N };
|
||||
static u32 g_power_until; /* menu line POWER: pressed for 200 ms after the menu closes */
|
||||
static int g_items[M_N], g_nitems;
|
||||
static void menu_items(void)
|
||||
{
|
||||
g_nitems = 0;
|
||||
for (int k = 0; k < M_N; k++) { if (k == M_DIMTO && g_set.dim >= T_N) continue; g_items[g_nitems++] = k; }
|
||||
if (g_msel >= g_nitems) g_msel = g_nitems - 1;
|
||||
}
|
||||
static void pct(char *o, int v) { int n = 0; if (v >= 100) o[n++] = '1'; if (v >= 10) o[n++] = (char)('0' + (v / 10) % 10); o[n++] = (char)('0' + v % 10); o[n++] = '%'; o[n] = 0; }
|
||||
static int g_reset_ask;
|
||||
static void menu_line(int it, const char **a, char *b)
|
||||
{
|
||||
int e = en(); const char *v = 0; b[0] = 0;
|
||||
switch (it) {
|
||||
case M_POW: *a = e ? "PRESS POWER" : "POWER DRUECKEN"; v = "B"; break;
|
||||
case M_PAL: *a = e ? "COLOUR" : "FARBE"; v = PAL_NM[e][g_set.pal & 3u]; break;
|
||||
case M_SND: *a = e ? "SOUND" : "TON"; v = g_set.mute ? (e ? "OFF" : "AUS") : (e ? "ON" : "AN"); break;
|
||||
case M_LIGHT: *a = e ? "LIGHT" : "LICHT"; pct(b, LV_PCT[(g_set.r0 & 15u) % LV_N]); break;
|
||||
case M_DIM: *a = e ? "DIM AFTER" : "DIMMEN NACH"; v = T_NM[e][g_set.dim <= T_N ? g_set.dim : T_N]; break;
|
||||
case M_DIMTO: *a = e ? "DIM TO" : "DIMMEN AUF"; pct(b, DIM2_PCT[g_set.dimto % DIM2_N]); break;
|
||||
case M_OFF: *a = e ? "SCREEN OFF" : "BILD AUS NACH"; v = T_NM[e][g_set.off <= T_N ? g_set.off : T_N]; break;
|
||||
case M_RESET: *a = e ? "RESTART GAME" : "SPIEL NEU"; v = g_reset_ask ? (e ? "SURE? B" : "SICHER? B") : ""; break;
|
||||
default: *a = e ? "LANGUAGE" : "SPRACHE"; v = e ? "ENGLISH" : "DEUTSCH"; break;
|
||||
}
|
||||
if (v) { int n = 0; while (v[n] && n < 11) { b[n] = v[n]; n++; } b[n] = 0; }
|
||||
}
|
||||
#define ROWS 9
|
||||
static void menu_draw(void)
|
||||
{
|
||||
if (g_msel < g_mtop) g_mtop = g_msel;
|
||||
if (g_msel >= g_mtop + ROWS) g_mtop = g_msel - ROWS + 1;
|
||||
hw_px_begin(0, 0, 128, 128);
|
||||
for (int y = 0; y < 128; y++) {
|
||||
for (int x = 0; x < 128; x++) g_row[x] = BG;
|
||||
text(4, 3, en() ? "SETTINGS" : "EINSTELLUNGEN", INK, g_row, y);
|
||||
if (y == 12) for (int x = 0; x < 128; x++) g_row[x] = OFF;
|
||||
for (int k = 0; k < ROWS && g_mtop + k < g_nitems; k++) {
|
||||
int i = g_mtop + k, ly = 16 + k * 11; const char *a; char b[12]; menu_line(g_items[i], &a, b);
|
||||
if (i == g_msel && y >= ly - 2 && y < ly + 9) for (int x = 0; x < 128; x++) g_row[x] = INK;
|
||||
u16 c = i == g_msel ? BG : INK;
|
||||
text(4, ly, a, c, g_row, y); int w = 0; while (b[w]) w++; text(124 - w * 6, ly, b, c, g_row, y);
|
||||
}
|
||||
text(4, 118, en() ? "A NEXT B SET C OK" : "A ZEILE B SETZEN C OK", OFF, g_row, y);
|
||||
hw_px_row(g_row, 128);
|
||||
}
|
||||
hw_px_end();
|
||||
}
|
||||
static int g_set_dirty;
|
||||
static void pm_fresh(void);
|
||||
static void pause_end(void);
|
||||
static void menu_close(void) { pause_end(); g_menu = 0; g_reset_ask = 0; if (g_set_dirty) { set_store(); g_set_dirty = 0; } push(1); }
|
||||
static void menu_key(u32 k)
|
||||
{
|
||||
if (k & BTN_A) { g_msel = (g_msel + 1) % g_nitems; g_reset_ask = 0; }
|
||||
if (k & BTN_B) {
|
||||
switch (g_items[g_msel]) {
|
||||
case M_POW: g_power_until = g_ms + 200u; menu_close(); return;
|
||||
case M_PAL: g_set.pal = (u8)((g_set.pal + 1u) & 3u); break;
|
||||
case M_SND: g_set.mute ^= 1u; break;
|
||||
case M_LIGHT: g_set.r0 = (u8)(0x80u | (((g_set.r0 & 15u) + 1u) % LV_N)); break;
|
||||
case M_DIM: g_set.dim = (u8)((g_set.dim + 1u) % (T_N + 1u)); if (g_set.dim < T_N && g_set.off < T_N && g_set.off <= g_set.dim) g_set.off = (u8)(g_set.dim + 1u); break;
|
||||
case M_DIMTO: g_set.dimto = (u8)((g_set.dimto + 1u) % DIM2_N); break;
|
||||
case M_OFF: do g_set.off = (u8)((g_set.off + 1u) % (T_N + 1u)); while (g_set.off < T_N && g_set.dim < T_N && g_set.off <= g_set.dim); break;
|
||||
case M_RESET: if (g_reset_ask) { g_reset_ask = 0; pm_fresh(); menu_close(); return; } g_reset_ask = 1; break;
|
||||
default: g_set.lang = (u8)(en() ? 1u : 2u); break;
|
||||
}
|
||||
if (g_items[g_msel] != M_RESET && g_items[g_msel] != M_POW) g_set_dirty = 1;
|
||||
colours(); menu_items();
|
||||
}
|
||||
if (k & BTN_C) { menu_close(); return; }
|
||||
menu_draw();
|
||||
}
|
||||
static void message(const char *a, const char *b)
|
||||
{
|
||||
hw_px_begin(0, 0, 128, 128);
|
||||
for (int y = 0; y < 128; y++) { for (int x = 0; x < 128; x++) g_row[x] = BG; text(4, 50, a, INK, g_row, y); text(4, 62, b, INK, g_row, y); hw_px_row(g_row, 128); }
|
||||
hw_px_end();
|
||||
}
|
||||
|
||||
/* ---- keys: the Paradise inputs to the Pokemon mini's buttons (map from the Studio) ---- */
|
||||
static u32 g_wheel_until[2]; /* wheel up / down held until (ms) */
|
||||
static u32 pm_keys(u32 b, u32 now)
|
||||
{
|
||||
u32 in = 0;
|
||||
int ac = (b & (BTN_A | BTN_C)) == (BTN_A | BTN_C), bc = (b & (BTN_B | BTN_C)) == (BTN_B | BTN_C), ab = (b & (BTN_A | BTN_B)) == (BTN_A | BTN_B);
|
||||
u32 used = 0; /* a pair held: its two keys count as the pair only (if the pair has a meaning) */
|
||||
if (ac && g_cfg.keys[6]) { in |= 1u << 6; used |= BTN_A | BTN_C; }
|
||||
if (bc && g_cfg.keys[7]) { in |= 1u << 7; used |= BTN_B | BTN_C; }
|
||||
if (ab && g_cfg.keys[8]) { in |= 1u << 8; used |= BTN_A | BTN_B; }
|
||||
u32 r = b & ~used;
|
||||
if (r & BTN_A) in |= 1u; if (r & BTN_B) in |= 2u; if (r & BTN_C) in |= 4u; if (b & BTN_WHEEL) in |= 8u;
|
||||
if ((s32)(g_wheel_until[0] - now) > 0) in |= 16u;
|
||||
if ((s32)(g_wheel_until[1] - now) > 0) in |= 32u;
|
||||
u32 pm = 0;
|
||||
for (int i = 0; i < NIN; i++) if (in & (1u << i)) pm |= g_cfg.keys[i];
|
||||
if ((s32)(g_power_until - now) > 0) pm |= 0x80u;
|
||||
return pm;
|
||||
}
|
||||
static u32 g_pm_keys;
|
||||
static void keys_set(u32 k)
|
||||
{
|
||||
u32 ch = k ^ g_pm_keys; if (!ch) return;
|
||||
for (int i = 0; i < 9; i++) if (ch & (1u << i)) MinxIO_Keypad((u8)(MINX_KEY_A + i), (k >> i) & 1u); /* A, B, C, up, down, left, right, power, shake */
|
||||
g_pm_keys = k;
|
||||
}
|
||||
|
||||
/* ---- the clock of the game from the Paradise's ---- */
|
||||
static u32 g_para;
|
||||
static void time_from_para(void)
|
||||
{
|
||||
if (!g_para) return;
|
||||
u32 s = g_para, days = s / 86400u, rem = s % 86400u;
|
||||
s32 z = (s32)days + 719468, era = z / 146097; u32 doe = (u32)(z - era * 146097);
|
||||
u32 yoe = (doe - doe / 1460u + doe / 36524u - doe / 146096u) / 365u; s32 y = (s32)yoe + era * 400;
|
||||
u32 doy = doe - (365u * yoe + yoe / 4u - yoe / 100u), mp = (5u * doy + 2u) / 153u, d = doy - (153u * mp + 2u) / 5u + 1u, m = mp < 10u ? mp + 3u : mp - 9u;
|
||||
if (m <= 2u) y++;
|
||||
pm_set_time((int)y, (int)m, (int)d, (int)(rem / 3600u), (int)(rem / 60u % 60u), (int)(rem % 60u));
|
||||
}
|
||||
static void bios_load(void)
|
||||
{
|
||||
if ((g_cfg.flags & 4u) && g_cfg.bios_off) { const volatile u8 *p = XIP_PTR(g_cfg.bios_off); for (u32 i = 0; i < 4096u; i++) PM_BIOS[i] = p[i]; PokeMini_FreeBIOS = 0; }
|
||||
else PokeMini_LoadFreeBIOS();
|
||||
}
|
||||
/* the game anew (settings menu RESTART GAME): the EEPROM stays */
|
||||
static void pm_fresh(void) { keys_set(0); PokeMini_Reset(1); time_from_para(); }
|
||||
|
||||
/* ---- the Pokemon mini's clock (its seconds counter) keeps running while the game waits (settings, screen off, back
|
||||
* in the Paradise): the seconds of the Paradise's counter (it runs always) are added when the game goes on ---- */
|
||||
#define PARA_SECS REG(0x45000304u)
|
||||
static u32 g_pause_cnt;
|
||||
static void rtc_add(u32 secs) { if (secs && secs < 400u * 86400u && (PMR_SEC_CTRL & 1u)) MinxTimers.SecTimerCnt = (MinxTimers.SecTimerCnt + secs) & 0xFFFFFFu; }
|
||||
static void pause_begin(void) { if (!g_pause_cnt) g_pause_cnt = PARA_SECS | 0x80000000u; }
|
||||
static void pause_end(void) { if (g_pause_cnt) { rtc_add((PARA_SECS - g_pause_cnt) & 0x7FFFFFFFu); g_pause_cnt = 0; } }
|
||||
|
||||
/* ---- the whole state on leaving (wheel held), read once at the next start ---- */
|
||||
#include "../../../emu/src/emu/pstate.h"
|
||||
#ifdef SESS_FLAG
|
||||
#define NOSESS ((g_cfg.flags & 0x1000u) != 0u) /* 1.7.3 test7: the Studio's "remember on leaving" off: only the game's own save */
|
||||
#else
|
||||
#define NOSESS 0
|
||||
#endif
|
||||
static u8 g_st[STATE_N] __attribute__((aligned(4)));
|
||||
static int g_running;
|
||||
static u32 st_tag(void) { return 0x504D0001u ^ (u32)STATE_N ^ g_cfg.rom_len ^ (u32)&PM_RAM ^ (u32)PokeMini_EmulateFrame; }
|
||||
static u32 g_st_cnt; /* the Paradise's seconds counter when the state was stored */
|
||||
static void state_store(void)
|
||||
{
|
||||
if (!g_running) return;
|
||||
pause_end();
|
||||
for (u32 i = 0; i < STATE_N; i++) g_st[i] = 0;
|
||||
if (!pm_state_save(g_st, STATE_N)) return;
|
||||
g_st_cnt = PARA_SECS;
|
||||
StPart pt[2] = { { g_st, STATE_N }, { &g_st_cnt, 4 } };
|
||||
st_store(STATE_AT, STATE_MAX, st_tag(), pt, 2, g_sec);
|
||||
}
|
||||
static int state_load(void)
|
||||
{
|
||||
if (NOSESS) { st_drop(STATE_AT); return 0; }
|
||||
StPart pt[2] = { { g_st, STATE_N }, { &g_st_cnt, 4 } };
|
||||
int ok = st_load(STATE_AT, STATE_MAX, st_tag(), pt, 2) && pm_state_load(g_st, STATE_N);
|
||||
st_drop(STATE_AT);
|
||||
if (ok) rtc_add(PARA_SECS - g_st_cnt); /* the time away */
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* ---- leaving ---- */
|
||||
static void leave(void)
|
||||
{
|
||||
tone(0); hw_tone(0);
|
||||
if (g_set_dirty) set_store();
|
||||
REG(0x20000FF8u) = 0;
|
||||
REG(0x20000FFCu) = 0x4C584D50u; /* "PMXL": back on purpose, the autostart stays off */
|
||||
if (g_running && !NOSESS) { message(en() ? "SAVING" : "SPEICHERN", ""); state_store(); }
|
||||
if (PokeMini_EEPROMWritten) eep_store();
|
||||
#ifdef PARA_BACK
|
||||
#ifdef GPLAY
|
||||
para_points((uint8_t *)g_sec); /* play time to Tamapoints */
|
||||
#endif
|
||||
para_back_fix(g_sec);
|
||||
#endif
|
||||
hw_bl_pwm_off();
|
||||
for (u32 t = 0; hw_buttons() && t < 20000000u; t++) if ((t & 0xFFFFu) == 0) hw_wdt_feed();
|
||||
XIP_BASE_REG = 0x60011000u; XIP_CTRL_REG = 3u;
|
||||
hw_back_to_paradise();
|
||||
}
|
||||
|
||||
__attribute__((used)) volatile u32 g_pmst[4]; /* frames run, frames pushed, frames dropped, last frame in ms (for the tests) */
|
||||
extern u32 __bss_start, __bss_end;
|
||||
void Reset_Handler(void)
|
||||
{
|
||||
__asm__ volatile("cpsid i");
|
||||
u32 cnt = REG(0x45000304u), para = para_clock(cnt, 0, 0x1F000u, 0, 0);
|
||||
if (!para) para = para_mailbox(cnt);
|
||||
#ifdef PARA_FLASH
|
||||
if (!para) para = para_flash(cnt);
|
||||
#endif
|
||||
#ifdef PARA_BACK
|
||||
para_leave_mark(cnt, para);
|
||||
#endif
|
||||
__asm__ volatile("" ::: "memory");
|
||||
for (u32 *p = &__bss_start; p < &__bss_end; p++) *p = 0;
|
||||
{ extern u32 __data_start, __data_end, __data_load;
|
||||
const u32 *src = &__data_load; for (u32 *p = &__data_start; p < &__data_end; p++) *p = *src++; }
|
||||
g_para = para;
|
||||
hw_init();
|
||||
hw_tone(0);
|
||||
XIP_BASE_REG = 0x60000000u | g_cfg.rom_off; /* the game in the cached window from 0x10000000 */
|
||||
XIP_CTRL_REG = 3u;
|
||||
REG(GPIO2 + 0x04) &= ~3u; g_enc_last = REG(GPIO2) & 3u;
|
||||
set_load();
|
||||
if (!PokeMini_Create(0, 0)) { message("NO MEMORY", ""); for (u32 t = 0; t < 30000000u; t++) if ((t & 0xFFFFu) == 0) hw_wdt_feed(); leave(); }
|
||||
PokeMini_LCDMode = LCDMODE_ANALOG;
|
||||
bios_load();
|
||||
pm_set_rom(ROMWIN, g_cfg.rom_len);
|
||||
eep_load();
|
||||
PokeMini_Reset(1);
|
||||
if (!state_load()) time_from_para();
|
||||
PokeMini_EEPROMWritten = 0;
|
||||
g_running = 1;
|
||||
push(1);
|
||||
SYST_RVR = CORE_HZ / 1000u - 1u; SYST_CVR = 0; SYST_CSR = 7;
|
||||
__asm__ volatile("cpsie i");
|
||||
|
||||
u32 last_in = g_ms, wheel_ms = 0, eep_ms = 0, next_us = 0, last_push = g_ms, mk0 = 0, t_us0 = g_ms;
|
||||
int bl = 1, lock = 1, menu_lock = 0, drawn = 0;
|
||||
for (;;) {
|
||||
hw_wdt_feed();
|
||||
u32 now = g_ms;
|
||||
u32 b = hw_buttons();
|
||||
if (lock) { if (b) b = 0; else lock = 0; }
|
||||
/* wheel steps: one step = 4 phases; each step holds up or down for 150 ms */
|
||||
{ s32 a = g_enc_acc;
|
||||
if (a >= 4 || a <= -4) {
|
||||
__asm__ volatile("cpsid i"); g_enc_acc -= a >= 4 ? 4 : -4; __asm__ volatile("cpsie i");
|
||||
int up = (a > 0) ^ ((g_cfg.flags & 2u) != 0);
|
||||
u32 *u = &g_wheel_until[up ? 0 : 1]; *u = ((s32)(*u - now) > 0 ? *u : now) + 150u;
|
||||
last_in = now;
|
||||
if (g_menu) { g_msel = up ? (g_msel + g_nitems - 1) % g_nitems : (g_msel + 1) % g_nitems; menu_draw(); }
|
||||
} }
|
||||
if (b) {
|
||||
last_in = now;
|
||||
if (!bl || g_dimmed) { /* the key only wakes */
|
||||
bl = 1; hw_backlight(1); pause_end(); if (g_dimmed) { g_dimmed = 0; colours(); }
|
||||
if (g_menu) menu_draw(); else push(1);
|
||||
while (hw_buttons()) hw_wdt_feed();
|
||||
t_us0 = g_ms; next_us = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* wheel held 2 s: save and back */
|
||||
if (b & BTN_WHEEL) { if (!wheel_ms) wheel_ms = now ? now : 1; else if (EXIT_NOW(now - wheel_ms, 2000u)) leave(); } else wheel_ms = 0;
|
||||
/* A+B+C: settings */
|
||||
if ((b & (BTN_A | BTN_B | BTN_C)) == (BTN_A | BTN_B | BTN_C) && !g_menu && !menu_lock) {
|
||||
tone(0); keys_set(0); pause_begin(); g_menu = 1; menu_lock = 1; g_msel = 1; g_mtop = 0; menu_items(); menu_draw(); mk0 = BTN_A | BTN_B | BTN_C;
|
||||
}
|
||||
if (!(b & (BTN_A | BTN_B | BTN_C))) menu_lock = 0;
|
||||
if (g_menu) {
|
||||
u32 k = b & (BTN_A | BTN_B | BTN_C), nk = k & ~mk0; mk0 = k; if (nk) menu_key(nk);
|
||||
t_us0 = g_ms; next_us = 0;
|
||||
__asm__ volatile("wfi");
|
||||
continue;
|
||||
}
|
||||
if (!bl) { tone(0); t_us0 = g_ms; next_us = 0; __asm__ volatile("wfi"); continue; } /* screen off: the game waits (battery) */
|
||||
keys_set(pm_keys(b, now));
|
||||
/* one Pokemon mini frame every 1/72 s (13889 us) */
|
||||
u32 el_us = (now - t_us0) * 1000u;
|
||||
if ((s32)(el_us - next_us) >= 0) {
|
||||
if ((s32)(el_us - next_us) > 100000) { g_pmst[2] += (el_us - next_us) / 13889u; next_us = el_us; } /* too far behind: drop the time */
|
||||
u32 t0 = g_ms;
|
||||
PokeMini_EmulateFrame();
|
||||
g_pmst[0]++; g_pmst[3] = g_ms - t0;
|
||||
next_us += 13889u;
|
||||
if (next_us > 1000000000u) { t_us0 += next_us / 1000u; next_us %= 1000u; }
|
||||
{ int hz = 0, vol = 0; pm_audio_now(&hz, &vol); tone(!g_set.mute && vol && hz >= 40 && hz <= 12000 ? (u32)hz : 0u); }
|
||||
drawn ^= 1;
|
||||
#ifdef PM_FASTLCD
|
||||
if (!drawn) lcd_snap();
|
||||
else if (now - last_push >= 25u) { last_push = now; lcd_mix(); frame_grow(); push(0); g_pmst[1]++; }
|
||||
#else
|
||||
if (drawn && now - last_push >= 25u) { last_push = now; frame_grow(); push(0); g_pmst[1]++; }
|
||||
#endif
|
||||
}
|
||||
if (PokeMini_EEPROMWritten && !eep_ms) eep_ms = now ? now : 1;
|
||||
if (eep_ms && now - eep_ms > 3000u && now - last_in > 1000u) { eep_ms = 0; eep_store(); }
|
||||
if (bl && !g_dimmed && g_set.dim < T_N && now - last_in > T_MS[g_set.dim]) { g_dimmed = 1; colours(); push(1); }
|
||||
if (bl && g_set.off < T_N && now - last_in > T_MS[g_set.off]) { bl = 0; tone(0); hw_backlight(0); pause_begin(); if (PokeMini_EEPROMWritten) { eep_ms = 0; eep_store(); } }
|
||||
if ((s32)(next_us - (g_ms - t_us0) * 1000u) > 0) __asm__ volatile("wfi");
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((naked)) static void Default_Handler(void) { __asm__ volatile("1: b 1b\n"); }
|
||||
__attribute__((naked)) static void Irq_Off(void) { __asm__ volatile("cpsid i\n bx lr\n"); }
|
||||
__attribute__((section(".vectors"), used))
|
||||
const void *const g_vectors[16 + 64] = { (void *)0x18020000u, (void *)Reset_Handler,
|
||||
[2 ... 10] = (void *)Default_Handler, [11] = (void *)Irq_Off, [12 ... 13] = (void *)Default_Handler, [14] = (void *)Irq_Off,
|
||||
[15] = (void *)SysTick_Handler, [16 ... 79] = (void *)Irq_Off };
|
||||
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PokeMini.h"
|
||||
|
||||
/* Emulate 1 frame, return cycles ran */
|
||||
static int PokeMini_EmulateFrameRun;
|
||||
|
||||
int PokeMini_EmulateFrame(void)
|
||||
{
|
||||
int lcylc = 0;
|
||||
int synccylc = PM_SYNCCYCLES;
|
||||
|
||||
PokeMini_EmulateFrameRun = 1;
|
||||
|
||||
if (RequireSoundSync) {
|
||||
while (PokeMini_EmulateFrameRun) {
|
||||
PokeHWCycles = 0;
|
||||
while (PokeHWCycles < synccylc) {
|
||||
if (StallCPU) PokeHWCycles += StallCycles;
|
||||
else PokeHWCycles += MinxCPU_Exec();
|
||||
}
|
||||
MinxTimers_Sync();
|
||||
MinxPRC_Sync();
|
||||
MinxAudio_Sync();
|
||||
lcylc += PokeHWCycles;
|
||||
}
|
||||
} else {
|
||||
while (PokeMini_EmulateFrameRun) {
|
||||
PokeHWCycles = 0;
|
||||
while (PokeHWCycles < synccylc) {
|
||||
if (StallCPU) PokeHWCycles += StallCycles;
|
||||
else PokeHWCycles += MinxCPU_Exec();
|
||||
}
|
||||
MinxTimers_Sync();
|
||||
MinxPRC_Sync();
|
||||
lcylc += PokeHWCycles;
|
||||
}
|
||||
}
|
||||
|
||||
return lcylc;
|
||||
}
|
||||
|
||||
// -------------------
|
||||
// Internal Processing
|
||||
// -------------------
|
||||
|
||||
uint8_t MinxCPU_OnRead(int cpu, uint32_t addr)
|
||||
{
|
||||
#ifdef PERFORMANCE
|
||||
if (addr >= 0x2100) {
|
||||
// ROM Read (ROM Cartridge)
|
||||
if (PM_ROM) return PM_ROM[addr & PM_ROM_Mask];
|
||||
#else
|
||||
if (addr >= 0x200000) {
|
||||
// Open bus
|
||||
return MinxCPU.IR;
|
||||
} else if (addr >= 0x2100) {
|
||||
// ROM Read (Multicard)
|
||||
return MulticartRead(addr);
|
||||
#endif
|
||||
} else if (addr >= 0x2000) {
|
||||
// I/O Read
|
||||
uint8_t reg = (uint8_t)addr;
|
||||
switch(reg) {
|
||||
// Misc interface
|
||||
case 0x00: // System Control 1
|
||||
return PMR_SYS_CTRL1;
|
||||
case 0x01: // System Control 2
|
||||
return PMR_SYS_CTRL2;
|
||||
case 0x02: // System Control 3
|
||||
return PMR_SYS_CTRL3;
|
||||
|
||||
// IRQ interface
|
||||
case 0x20: case 0x21: case 0x22: case 0x23:
|
||||
case 0x24: case 0x25: case 0x26: case 0x27:
|
||||
case 0x28: case 0x29: case 0x2A:
|
||||
return MinxIRQ_ReadReg(cpu, reg);
|
||||
|
||||
// Timers interface
|
||||
case 0x08: case 0x09: case 0x0A: case 0x0B:
|
||||
case 0x18: case 0x19: case 0x1A: case 0x1B:
|
||||
case 0x1C: case 0x1D: case 0x1E: case 0x1F:
|
||||
case 0x30: case 0x31: case 0x32: case 0x33:
|
||||
case 0x34: case 0x35: case 0x36: case 0x37:
|
||||
case 0x38: case 0x39: case 0x3A: case 0x3B:
|
||||
case 0x3C: case 0x3D: case 0x3E: case 0x3F:
|
||||
case 0x40: case 0x41:
|
||||
case 0x48: case 0x49: case 0x4A: case 0x4B:
|
||||
case 0x4C: case 0x4D: case 0x4E: case 0x4F:
|
||||
return MinxTimers_ReadReg(reg);
|
||||
|
||||
// Parallel I/O interface & Power
|
||||
case 0x10:
|
||||
case 0x44: case 0x45: case 0x46: case 0x47:
|
||||
case 0x50: case 0x51: case 0x52: case 0x53:
|
||||
case 0x54: case 0x55:
|
||||
case 0x60: case 0x61: case 0x62:
|
||||
return MinxIO_ReadReg(cpu, reg);
|
||||
|
||||
// Program Rendering Chip interface
|
||||
case 0x80: case 0x81: case 0x82: case 0x83:
|
||||
case 0x84: case 0x85: case 0x86: case 0x87:
|
||||
case 0x88: case 0x89: case 0x8A: case 0x8B:
|
||||
case 0x8C: case 0x8D: case 0x8E: case 0x8F:
|
||||
return MinxPRC_ReadReg(reg);
|
||||
|
||||
// Color PRC interface
|
||||
case 0xF0: case 0xF1: case 0xF2: case 0xF3:
|
||||
case 0xF4: case 0xF5: case 0xF6: case 0xF7:
|
||||
return MinxColorPRC_ReadReg(cpu, reg);
|
||||
|
||||
// LCD interface
|
||||
case 0xFE: case 0xFF:
|
||||
return MinxLCD_ReadReg(cpu, reg);
|
||||
|
||||
// Audio interface
|
||||
case 0x70: case 0x71:
|
||||
return MinxAudio_ReadReg(reg);
|
||||
|
||||
// Open bus
|
||||
default:
|
||||
return MinxCPU.IR;
|
||||
}
|
||||
} else if (addr >= 0x1000) {
|
||||
// RAM Read
|
||||
return PM_RAM[addr-0x1000];
|
||||
} else {
|
||||
// BIOS Read
|
||||
return PM_BIOS[addr];
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
void MinxCPU_OnWrite(int cpu, uint32_t addr, uint8_t data)
|
||||
{
|
||||
#ifdef PERFORMANCE
|
||||
if (addr >= 0x2100) {
|
||||
// Do nothing...
|
||||
#else
|
||||
if (addr >= 0x200000) {
|
||||
// Open bus
|
||||
} else if (addr >= 0x2100) {
|
||||
// ROM Write
|
||||
MulticartWrite(addr, data);
|
||||
#endif
|
||||
return;
|
||||
} else if (addr >= 0x2000) {
|
||||
// I/O Write
|
||||
uint8_t reg = (uint8_t)addr;
|
||||
switch(reg) {
|
||||
// Misc interface
|
||||
case 0x00: // System Control 1
|
||||
PMR_SYS_CTRL1 = data;
|
||||
return;
|
||||
case 0x01: // System Control 2
|
||||
PMR_SYS_CTRL2 = data;
|
||||
return;
|
||||
case 0x02: // System Control 3
|
||||
PMR_SYS_CTRL3 = data;
|
||||
return;
|
||||
|
||||
// IRQ interface
|
||||
case 0x20: case 0x21: case 0x22: case 0x23:
|
||||
case 0x24: case 0x25: case 0x26: case 0x27:
|
||||
case 0x28: case 0x29: case 0x2A:
|
||||
MinxIRQ_WriteReg(cpu, reg, data);
|
||||
return;
|
||||
|
||||
// Timers interface
|
||||
case 0x08: case 0x09: case 0x0A: case 0x0B:
|
||||
case 0x18: case 0x19: case 0x1A: case 0x1B:
|
||||
case 0x1C: case 0x1D: case 0x1E: case 0x1F:
|
||||
case 0x30: case 0x31: case 0x32: case 0x33:
|
||||
case 0x34: case 0x35: case 0x36: case 0x37:
|
||||
case 0x38: case 0x39: case 0x3A: case 0x3B:
|
||||
case 0x3C: case 0x3D: case 0x3E: case 0x3F:
|
||||
case 0x40: case 0x41:
|
||||
case 0x48: case 0x49: case 0x4A: case 0x4B:
|
||||
case 0x4C: case 0x4D: case 0x4E: case 0x4F:
|
||||
MinxTimers_WriteReg(reg, data);
|
||||
return;
|
||||
|
||||
// Parallel I/O interface & Power
|
||||
case 0x10:
|
||||
case 0x44: case 0x45: case 0x46: case 0x47:
|
||||
case 0x50: case 0x51: case 0x52: case 0x53:
|
||||
case 0x54: case 0x55:
|
||||
case 0x60: case 0x61: case 0x62:
|
||||
MinxIO_WriteReg(cpu, reg, data);
|
||||
return;
|
||||
|
||||
// Program Rendering Chip interface
|
||||
case 0x80: case 0x81: case 0x82: case 0x83:
|
||||
case 0x84: case 0x85: case 0x86: case 0x87:
|
||||
case 0x88: case 0x89: case 0x8A:
|
||||
MinxPRC_WriteReg(reg, data);
|
||||
return;
|
||||
|
||||
// Color PRC interface
|
||||
case 0xF0: case 0xF1: case 0xF2: case 0xF3:
|
||||
case 0xF4: case 0xF5: case 0xF6: case 0xF7:
|
||||
MinxColorPRC_WriteReg(reg, data);
|
||||
return;
|
||||
|
||||
// LCD interface
|
||||
case 0xFE: case 0xFF:
|
||||
MinxLCD_WriteReg(cpu, reg, data);
|
||||
return;
|
||||
|
||||
// Audio interface
|
||||
case 0x70: case 0x71:
|
||||
MinxAudio_WriteReg(reg, data);
|
||||
return;
|
||||
}
|
||||
} else if (addr >= 0x1300) {
|
||||
// RAM Write
|
||||
PM_RAM[addr-0x1000] = data;
|
||||
return;
|
||||
} else if (addr >= 0x1000) {
|
||||
// RAM Write / FrameBuffer
|
||||
PM_RAM[addr-0x1000] = data;
|
||||
if (PRCColorMap) MinxColorPRC_WriteFramebuffer(addr-0x1000, data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxCPU_OnIRQHandle(uint8_t cpuflag, uint8_t shift_u)
|
||||
{
|
||||
// Disable or enable master interrupt and check for interrupts
|
||||
if (shift_u) {
|
||||
MinxIRQ_MasterIRQ = 0;
|
||||
} else {
|
||||
if ((cpuflag & 0xC0) == 0xC0) MinxIRQ_MasterIRQ = 0;
|
||||
else {
|
||||
MinxIRQ_MasterIRQ = 1;
|
||||
MinxIRQ_Process();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MinxCPU_OnIRQAct(uint8_t intr)
|
||||
{
|
||||
// Set and process interrupt
|
||||
MinxIRQ_SetIRQ(intr);
|
||||
}
|
||||
|
||||
void MinxIRQ_OnIRQ(uint8_t intr)
|
||||
{
|
||||
// From IRQ module, call the CPU interrupt
|
||||
MinxCPU_CallIRQ(intr << 1);
|
||||
}
|
||||
|
||||
void MinxPRC_On72HzRefresh(int prcrender)
|
||||
{
|
||||
// Frame rendered
|
||||
#ifdef PM_FASTLCD
|
||||
/* PokeMiniEmu: the Paradise program reads the LCD memory itself, only for the frames it shows (and mixes two
|
||||
* frames for the grey shades); the per-dot buffers and the decay are left out (they took about 18 % of the time) */
|
||||
(void)prcrender; LCDDirty = 0;
|
||||
#else
|
||||
if ((PokeMini_LCDMode == LCDMODE_3SHADES) && (prcrender)) memcpy(LCDPixelsA, LCDPixelsD, 96*64);
|
||||
if (LCDDirty) MinxLCD_Render();
|
||||
if (PokeMini_LCDMode == LCDMODE_ANALOG) MinxLCD_DecayRefresh();
|
||||
#endif
|
||||
PokeMini_EmulateFrameRun = 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HARDWARE_EMU
|
||||
#define HARDWARE_EMU
|
||||
|
||||
/* Emulate 1 frame, return cycles ran */
|
||||
int PokeMini_EmulateFrame(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2014 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IO_MAP_H
|
||||
#define IO_MAP_H
|
||||
|
||||
#include "PokeMini.h"
|
||||
|
||||
// Pokemon-Mini I/O Registers
|
||||
#define PM_IO (&PM_RAM[0x1000])
|
||||
|
||||
#define PMR_SYS_CTRL1 (PM_RAM[0x1000])
|
||||
#define PMR_SYS_CTRL2 (PM_RAM[0x1001])
|
||||
#define PMR_SYS_CTRL3 (PM_RAM[0x1002])
|
||||
|
||||
#define PMR_SEC_CTRL (PM_RAM[0x1008])
|
||||
#define PMR_SEC_CNT_LO (PM_RAM[0x1009])
|
||||
#define PMR_SEC_CNT_MID (PM_RAM[0x100A])
|
||||
#define PMR_SEC_CNT_HI (PM_RAM[0x100B])
|
||||
|
||||
#define PMR_SYS_BATT (PM_RAM[0x1010])
|
||||
|
||||
#define PMR_TMR1_SCALE (PM_RAM[0x1018])
|
||||
#define PMR_TMR1_ENA_OSC (PM_RAM[0x1019])
|
||||
#define PMR_TMR1_OSC (PM_RAM[0x1019])
|
||||
#define PMR_TMR2_SCALE (PM_RAM[0x101A])
|
||||
#define PMR_TMR2_OSC (PM_RAM[0x101B])
|
||||
#define PMR_TMR3_SCALE (PM_RAM[0x101C])
|
||||
#define PMR_TMR3_OSC (PM_RAM[0x101D])
|
||||
|
||||
#define PMR_IRQ_PRI1 (PM_RAM[0x1020])
|
||||
#define PMR_IRQ_PRI2 (PM_RAM[0x1021])
|
||||
#define PMR_IRQ_PRI3 (PM_RAM[0x1022])
|
||||
#define PMR_IRQ_ENA1 (PM_RAM[0x1023])
|
||||
#define PMR_IRQ_ENA2 (PM_RAM[0x1024])
|
||||
#define PMR_IRQ_ENA3 (PM_RAM[0x1025])
|
||||
#define PMR_IRQ_ENA4 (PM_RAM[0x1026])
|
||||
#define PMR_IRQ_ACT1 (PM_RAM[0x1027])
|
||||
#define PMR_IRQ_ACT2 (PM_RAM[0x1028])
|
||||
#define PMR_IRQ_ACT3 (PM_RAM[0x1029])
|
||||
#define PMR_IRQ_ACT4 (PM_RAM[0x102A])
|
||||
|
||||
#define PMR_TMR1_CTRL_L (PM_RAM[0x1030])
|
||||
#define PMR_TMR1_CTRL_H (PM_RAM[0x1031])
|
||||
#define PMR_TMR1_PRE_L (PM_RAM[0x1032])
|
||||
#define PMR_TMR1_PRE_H (PM_RAM[0x1033])
|
||||
#define PMR_TMR1_PVT_L (PM_RAM[0x1034])
|
||||
#define PMR_TMR1_PVT_H (PM_RAM[0x1035])
|
||||
#define PMR_TMR1_CNT_L (PM_RAM[0x1036])
|
||||
#define PMR_TMR1_CNT_H (PM_RAM[0x1037])
|
||||
|
||||
#define PMR_TMR2_CTRL_L (PM_RAM[0x1038])
|
||||
#define PMR_TMR2_CTRL_H (PM_RAM[0x1039])
|
||||
#define PMR_TMR2_PRE_L (PM_RAM[0x103A])
|
||||
#define PMR_TMR2_PRE_H (PM_RAM[0x103B])
|
||||
#define PMR_TMR2_PVT_L (PM_RAM[0x103C])
|
||||
#define PMR_TMR2_PVT_H (PM_RAM[0x103D])
|
||||
#define PMR_TMR2_CNT_L (PM_RAM[0x103E])
|
||||
#define PMR_TMR2_CNT_H (PM_RAM[0x103F])
|
||||
|
||||
#define PMR_TMR256_CTRL (PM_RAM[0x1040])
|
||||
#define PMR_TMR256_CNT (PM_RAM[0x1041])
|
||||
|
||||
#define PMR_REG_44 (PM_RAM[0x1044])
|
||||
#define PMR_REG_45 (PM_RAM[0x1045])
|
||||
#define PMR_REG_46 (PM_RAM[0x1046])
|
||||
#define PMR_REG_47 (PM_RAM[0x1047])
|
||||
|
||||
#define PMR_TMR3_CTRL_L (PM_RAM[0x1048])
|
||||
#define PMR_TMR3_CTRL_H (PM_RAM[0x1049])
|
||||
#define PMR_TMR3_PRE_L (PM_RAM[0x104A])
|
||||
#define PMR_TMR3_PRE_H (PM_RAM[0x104B])
|
||||
#define PMR_TMR3_PVT_L (PM_RAM[0x104C])
|
||||
#define PMR_TMR3_PVT_H (PM_RAM[0x104D])
|
||||
#define PMR_TMR3_CNT_L (PM_RAM[0x104E])
|
||||
#define PMR_TMR3_CNT_H (PM_RAM[0x104F])
|
||||
|
||||
#define PMR_REG_50 (PM_RAM[0x1050])
|
||||
#define PMR_REG_51 (PM_RAM[0x1051])
|
||||
#define PMR_KEY_PAD (PM_RAM[0x1052])
|
||||
#define PMR_REG_53 (PM_RAM[0x1053])
|
||||
#define PMR_REG_54 (PM_RAM[0x1054])
|
||||
#define PMR_REG_55 (PM_RAM[0x1055])
|
||||
|
||||
#define PMR_IO_DIR (PM_RAM[0x1060])
|
||||
#define PMR_IO_DATA (PM_RAM[0x1061])
|
||||
#define PMR_REG_62 (PM_RAM[0x1062])
|
||||
|
||||
#define PMR_AUD_CTRL (PM_RAM[0x1070])
|
||||
#define PMR_AUD_VOL (PM_RAM[0x1071])
|
||||
|
||||
#define PMR_PRC_MODE (PM_RAM[0x1080])
|
||||
#define PMR_PRC_RATE (PM_RAM[0x1081])
|
||||
#define PMR_PRC_MAP_LO (PM_RAM[0x1082])
|
||||
#define PMR_PRC_MAP_MID (PM_RAM[0x1083])
|
||||
#define PMR_PRC_MAP_HI (PM_RAM[0x1084])
|
||||
#define PMR_PRC_SCROLL_Y (PM_RAM[0x1085])
|
||||
#define PMR_PRC_SCROLL_X (PM_RAM[0x1086])
|
||||
#define PMR_PRC_SPR_LO (PM_RAM[0x1087])
|
||||
#define PMR_PRC_SPR_MID (PM_RAM[0x1088])
|
||||
#define PMR_PRC_SPR_HI (PM_RAM[0x1089])
|
||||
#define PMR_PRC_CNT (PM_RAM[0x108A])
|
||||
|
||||
#define PMR_LCD_CTRL (PM_RAM[0x10FE])
|
||||
#define PMR_LCD_DATA (PM_RAM[0x10FF])
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2014 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
@@ -0,0 +1,472 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <retro_inline.h>
|
||||
#include "PokeMini.h"
|
||||
|
||||
TMinxAudio MinxAudio;
|
||||
int AudioEnabled = 0;
|
||||
int SoundEngine = MINX_AUDIO_DISABLED;
|
||||
int PiezoFilter = 0;
|
||||
int RequireSoundSync = 0;
|
||||
int16_t *MinxAudio_FIFO = NULL;
|
||||
volatile int MinxAudio_ReadPtr = 0;
|
||||
volatile int MinxAudio_WritePtr = 0;
|
||||
int MinxAudio_FIFOSize = 0;
|
||||
int MinxAudio_FIFOMask = 0;
|
||||
int MinxAudio_FIFOThreshold = 0;
|
||||
int16_t (*MinxAudio_AudioProcess)(void) = NULL;
|
||||
|
||||
// Timers counting frequency table
|
||||
const uint32_t MinxAudio_CountFreq[32] = {
|
||||
// Osci1 disabled
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
// Osci1 Enabled
|
||||
(4000000/2), (4000000/8), (4000000/32), (4000000/64),
|
||||
(4000000/128), (4000000/256), (4000000/1024), (4000000/4096),
|
||||
// Osci2 disabled
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
// Osci2 Enabled
|
||||
(32768/1), (32768/2), (32768/4), (32768/8),
|
||||
(32768/16), (32768/32), (32768/64), (32768/128)
|
||||
};
|
||||
|
||||
//
|
||||
// FIFO I/O
|
||||
//
|
||||
|
||||
static INLINE int MinxAudio_iSamplesInBuffer(void)
|
||||
{
|
||||
if (MinxAudio_WritePtr > MinxAudio_ReadPtr)
|
||||
return MinxAudio_WritePtr - MinxAudio_ReadPtr;
|
||||
return (MinxAudio_FIFOSize - MinxAudio_ReadPtr) + MinxAudio_WritePtr;
|
||||
}
|
||||
|
||||
static INLINE void MinxAudio_FIFOWrite(int16_t data)
|
||||
{
|
||||
if (MinxAudio_iSamplesInBuffer() < MinxAudio_FIFOSize) {
|
||||
MinxAudio_FIFO[MinxAudio_WritePtr] = data;
|
||||
MinxAudio_WritePtr = (MinxAudio_WritePtr + 1) & MinxAudio_FIFOMask;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE int16_t MinxAudio_FIFORead(void)
|
||||
{
|
||||
if (MinxAudio_iSamplesInBuffer() > 0)
|
||||
{
|
||||
int16_t data = MinxAudio_FIFO[MinxAudio_ReadPtr];
|
||||
MinxAudio_ReadPtr = (MinxAudio_ReadPtr + 1) & MinxAudio_FIFOMask;
|
||||
return data;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
|
||||
int MinxAudio_Create(int audioenable, int fifosize)
|
||||
{
|
||||
// Init variables
|
||||
AudioEnabled = audioenable;
|
||||
SoundEngine = MINX_AUDIO_DISABLED;
|
||||
RequireSoundSync = 0;
|
||||
|
||||
// Reset
|
||||
MinxAudio_Reset(1);
|
||||
|
||||
// Init FIFO if audio enabled
|
||||
MinxAudio_ReadPtr = 0;
|
||||
MinxAudio_WritePtr = 0;
|
||||
if (fifosize)
|
||||
{
|
||||
MinxAudio_FIFOMask = GetMultiple2Mask(fifosize);
|
||||
MinxAudio_FIFOSize = MinxAudio_FIFOMask + 1;
|
||||
MinxAudio_FIFOThreshold = (fifosize * 3) >> 2; // ... at 3 / 4
|
||||
}
|
||||
else
|
||||
{
|
||||
MinxAudio_FIFOMask = 0;
|
||||
MinxAudio_FIFOSize = 0;
|
||||
MinxAudio_FIFOThreshold = 0;
|
||||
}
|
||||
if ((audioenable) && (fifosize))
|
||||
{
|
||||
MinxAudio_FIFO = (int16_t *)malloc(MinxAudio_FIFOSize*2);
|
||||
if (!MinxAudio_FIFO) return 0;
|
||||
memset(MinxAudio_FIFO, 0, MinxAudio_FIFOSize*2);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MinxAudio_Destroy(void)
|
||||
{
|
||||
if (MinxAudio_FIFO) {
|
||||
free(MinxAudio_FIFO);
|
||||
MinxAudio_FIFO = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxAudio_Reset(int hardreset)
|
||||
{
|
||||
// Initialize State
|
||||
memset((void *)&MinxAudio, 0, sizeof(TMinxAudio));
|
||||
}
|
||||
|
||||
int MinxAudio_LoadStateStream(memstream_t *stream, uint32_t bsize)
|
||||
{
|
||||
POKELOADSS_START(32);
|
||||
POKELOADSS_STREAM_32(MinxAudio.AudioCCnt);
|
||||
POKELOADSS_STREAM_32(MinxAudio.AudioSCnt);
|
||||
POKELOADSS_STREAM_16(MinxAudio.Volume);
|
||||
POKELOADSS_STREAM_16(MinxAudio.PWMMul);
|
||||
POKELOADSS_STREAM_X(20);
|
||||
POKELOADSS_END(32);
|
||||
}
|
||||
|
||||
int MinxAudio_SaveStateStream(memstream_t *stream)
|
||||
{
|
||||
POKESAVESS_STREAM_START(32);
|
||||
POKESAVESS_STREAM_32(MinxAudio.AudioCCnt);
|
||||
POKESAVESS_STREAM_32(MinxAudio.AudioSCnt);
|
||||
POKESAVESS_STREAM_16(MinxAudio.Volume);
|
||||
POKESAVESS_STREAM_16(MinxAudio.PWMMul);
|
||||
POKESAVESS_STREAM_X(20);
|
||||
POKESAVESS_END(32);
|
||||
}
|
||||
|
||||
static int16_t MinxAudio_AudioProcessDirectPWM(void)
|
||||
{
|
||||
uint32_t Pwm = 0;
|
||||
uint16_t TmrCnt = (MinxTimers.Tmr3CntA >> 24) | ((MinxTimers.Tmr3CntB >> 24) << 8);
|
||||
uint16_t TmrPre = (MinxTimers.Tmr3PreA >> 24) | ((MinxTimers.Tmr3PreB >> 24) << 8);
|
||||
|
||||
// Affect sound based of PWM
|
||||
if (TmrPre)
|
||||
Pwm = MinxTimers.Timer3Piv * MINX_AUDIO_PWM_RAG / TmrPre;
|
||||
if (Pwm > MINX_AUDIO_PWM_RAG)
|
||||
Pwm = MINX_AUDIO_PWM_RAG-1; // Avoid clipping
|
||||
if (TmrPre < 128)
|
||||
TmrCnt = 0; // Avoid high hizz
|
||||
|
||||
// Output
|
||||
if (TmrCnt <= MinxTimers.Timer3Piv)
|
||||
return MinxAudio.Volume + Pwm * MinxAudio.PWMMul;
|
||||
return MINX_AUDIO_SILENCE + Pwm * MinxAudio.PWMMul;
|
||||
}
|
||||
|
||||
|
||||
void MinxAudio_ChangeEngine(int engine)
|
||||
{
|
||||
if (PokeMini_Flags & POKEMINI_GENSOUND)
|
||||
engine = engine ? 1 : 0;
|
||||
SoundEngine = engine;
|
||||
switch (engine) {
|
||||
case MINX_AUDIO_DIRECTPWM:
|
||||
RequireSoundSync = 1;
|
||||
MinxAudio_AudioProcess = MinxAudio_AudioProcessDirectPWM;
|
||||
break;
|
||||
case MINX_AUDIO_GENERATED:
|
||||
default:
|
||||
RequireSoundSync = 0;
|
||||
MinxAudio_AudioProcess = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxAudio_ChangeFilter(int piezo)
|
||||
{
|
||||
PiezoFilter = piezo;
|
||||
}
|
||||
|
||||
void MinxAudio_Sync(void)
|
||||
{
|
||||
// Process single audio sample
|
||||
MinxAudio.AudioCCnt += MINX_AUDIOINC * PokeHWCycles;
|
||||
if (MinxAudio.AudioCCnt >= 0x01000000)
|
||||
{
|
||||
MinxAudio.AudioCCnt -= 0x01000000;
|
||||
if (MinxAudio_AudioProcess)
|
||||
{
|
||||
if (PiezoFilter)
|
||||
MinxAudio_FIFOWrite(MinxAudio_PiezoFilter(MinxAudio_AudioProcess()));
|
||||
else
|
||||
MinxAudio_FIFOWrite(MinxAudio_AudioProcess());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MinxAudio_ReadReg(uint8_t reg)
|
||||
{
|
||||
// 0x70 to 0x71
|
||||
switch(reg)
|
||||
{
|
||||
case 0x70: // Unknown Audio Control
|
||||
return PMR_AUD_CTRL & 0x07;
|
||||
case 0x71: // Audio Volume Control
|
||||
return PMR_AUD_VOL & 0x07;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MinxAudio_WriteReg(uint8_t reg, uint8_t val)
|
||||
{
|
||||
/* 0x70 to 0x71 */
|
||||
switch(reg)
|
||||
{
|
||||
case 0x70: /* Unknown Audio Control */
|
||||
PMR_AUD_CTRL = val & 0x07;
|
||||
break;
|
||||
case 0x71: /* Audio Volume Control */
|
||||
PMR_AUD_VOL = val & 0x07;
|
||||
break;
|
||||
}
|
||||
|
||||
// Calculate volume
|
||||
if (PMR_AUD_CTRL & 0x03) {
|
||||
// Mute audio
|
||||
MinxAudio.Volume = 0;
|
||||
} else {
|
||||
switch (PMR_AUD_VOL & 3) {
|
||||
case 0:
|
||||
// 0% Sound
|
||||
MinxAudio.Volume = MINX_AUDIO_SILENCE;
|
||||
MinxAudio.PWMMul = 0;
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
// 50% Sound
|
||||
MinxAudio.Volume = MINX_AUDIO_MED_VOL;
|
||||
MinxAudio.PWMMul = 1;
|
||||
break;
|
||||
case 3:
|
||||
// 100% Sound
|
||||
MinxAudio.Volume = MINX_AUDIO_MAX_VOL;
|
||||
MinxAudio.PWMMul = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get emulated frequency and pulsewidth
|
||||
// Sound_Frequency is in Hz
|
||||
// Pulse_Width is between 0 to 4095 (0% to ~99.99%)
|
||||
static void MinxAudio_GetEmulated(int *Sound_Frequency, int *Pulse_Width)
|
||||
{
|
||||
int Preset_Value, Sound_Pivot;
|
||||
// Calculate timer 3 frequency
|
||||
int Timer3_Frequency = MinxAudio_CountFreq[(PMR_TMR3_SCALE & 0xF) | ((PMR_TMR3_OSC & 0x01) << 4)];
|
||||
if (!(PMR_TMR3_CTRL_L & 0x04))
|
||||
Timer3_Frequency = 0;
|
||||
if (PMR_TMR3_OSC & 0x01)
|
||||
{
|
||||
// Osci2
|
||||
if (!MinxTimers.TmrXEna2)
|
||||
Timer3_Frequency = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Osci1
|
||||
if (!MinxTimers.TmrXEna1)
|
||||
Timer3_Frequency = 0;
|
||||
}
|
||||
|
||||
if (Timer3_Frequency)
|
||||
{
|
||||
// Calculate preset value
|
||||
Preset_Value = (MinxTimers.Tmr3PreA >> 24) + ((MinxTimers.Tmr3PreB >> 24) << 8);
|
||||
|
||||
// Calculate sound frequency
|
||||
*Sound_Frequency = Timer3_Frequency / (Preset_Value + 1);
|
||||
|
||||
// ... and pulse width
|
||||
if (Preset_Value)
|
||||
{
|
||||
Sound_Pivot = (int)MinxTimers.Timer3Piv;
|
||||
*Pulse_Width = 4095 - (Sound_Pivot * 4096 / Preset_Value);
|
||||
if (*Pulse_Width < 0)
|
||||
*Pulse_Width = 0;
|
||||
} else *Pulse_Width = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*Sound_Frequency = 0;
|
||||
*Pulse_Width = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int16_t MinxAudio_PiezoFilter(int32_t Sample)
|
||||
{
|
||||
int32_t HP_pCoeff = 40960;
|
||||
int32_t LP_pCoeff = 4096;
|
||||
int32_t LP_nCoeff = (65535 - LP_pCoeff);
|
||||
static int32_t HPSamples[4], LPSamples[4];
|
||||
int32_t TmpSamples[4];
|
||||
|
||||
// High pass to simulate a piezo crystal speaker
|
||||
TmpSamples[0] = Sample;
|
||||
TmpSamples[1] = (HP_pCoeff * (TmpSamples[0] + HPSamples[1] - HPSamples[0])) >> 16;
|
||||
TmpSamples[2] = (HP_pCoeff * (TmpSamples[1] + HPSamples[2] - HPSamples[1])) >> 16;
|
||||
TmpSamples[3] = (HP_pCoeff * (TmpSamples[2] + HPSamples[3] - HPSamples[2])) >> 16;
|
||||
memcpy(HPSamples, TmpSamples, sizeof(HPSamples));
|
||||
|
||||
// Amplify by 4
|
||||
Sample = TmpSamples[3] << 2;
|
||||
if (Sample < -32768)
|
||||
Sample = -32768;
|
||||
else if (Sample > 32767)
|
||||
Sample = 32767;
|
||||
|
||||
// Low pass to kill the spikes in sound
|
||||
LPSamples[0] = Sample;
|
||||
LPSamples[1] = (LPSamples[1] * LP_pCoeff + LPSamples[0] * LP_nCoeff) >> 16;
|
||||
LPSamples[2] = (LPSamples[2] * LP_pCoeff + LPSamples[1] * LP_nCoeff) >> 16;
|
||||
LPSamples[3] = (LPSamples[3] * LP_pCoeff + LPSamples[2] * LP_nCoeff) >> 16;
|
||||
|
||||
// Amplify by 2, clamp and output
|
||||
Sample = LPSamples[3] << 1;
|
||||
if (Sample < -32768)
|
||||
return -32768;
|
||||
if (Sample > 32767)
|
||||
return 32767;
|
||||
return Sample;
|
||||
}
|
||||
|
||||
// This doesn't require audio to be created:
|
||||
static void MinxAudio_GenerateEmulatedS16(
|
||||
int16_t *soundout, int numsamples, int channels)
|
||||
{
|
||||
int i, j, Sound_Frequency, Pulse_Width;
|
||||
if (numsamples <= 0)
|
||||
return;
|
||||
MinxAudio_GetEmulated(&Sound_Frequency, &Pulse_Width);
|
||||
if (channels == 1)
|
||||
{
|
||||
for (i=0; i<numsamples; i++)
|
||||
{
|
||||
if ((Sound_Frequency >= 50) && (Sound_Frequency < 20000))
|
||||
{
|
||||
MinxAudio.AudioSCnt += Sound_Frequency * MINX_AUDIOCONV;
|
||||
if ((MinxAudio.AudioSCnt & 0xFFF00000) >= (Pulse_Width << 20))
|
||||
*soundout++ = PiezoFilter ? MinxAudio_PiezoFilter(MinxAudio.Volume) : MinxAudio.Volume;
|
||||
else
|
||||
*soundout++ = PiezoFilter ? MinxAudio_PiezoFilter(MINX_AUDIO_SILENCE) : 0;
|
||||
}
|
||||
else
|
||||
*soundout++ = PiezoFilter ? MinxAudio_PiezoFilter(MINX_AUDIO_SILENCE) : 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<numsamples; i++)
|
||||
{
|
||||
if ((Sound_Frequency >= 50) && (Sound_Frequency < 20000))
|
||||
{
|
||||
MinxAudio.AudioSCnt += Sound_Frequency * MINX_AUDIOCONV;
|
||||
if ((MinxAudio.AudioSCnt & 0xFFF00000) >= (Pulse_Width << 20))
|
||||
{
|
||||
if (PiezoFilter)
|
||||
{
|
||||
for (j=0; j<channels; j++) *soundout++ = MinxAudio_PiezoFilter(MinxAudio.Volume);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j=0; j<channels; j++) *soundout++ = MinxAudio.Volume;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PiezoFilter)
|
||||
{
|
||||
for (j=0; j<channels; j++) *soundout++ = MinxAudio_PiezoFilter(MINX_AUDIO_SILENCE);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j=0; j<channels; j++) *soundout++ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PiezoFilter)
|
||||
{
|
||||
for (j=0; j<channels; j++) *soundout++ = MinxAudio_PiezoFilter(MINX_AUDIO_SILENCE);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j=0; j<channels; j++) *soundout++ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MinxAudio_GetSamplesS16Ch(int16_t *soundout,
|
||||
int numsamples, int channels)
|
||||
{
|
||||
int j;
|
||||
if (SoundEngine == MINX_AUDIO_GENERATED)
|
||||
{
|
||||
MinxAudio_GenerateEmulatedS16(soundout, numsamples, channels);
|
||||
return;
|
||||
}
|
||||
if (channels == 1)
|
||||
{
|
||||
if (AudioEnabled && SoundEngine)
|
||||
{
|
||||
while (numsamples--)
|
||||
*soundout++ = MinxAudio_FIFORead();
|
||||
}
|
||||
else
|
||||
{
|
||||
while (numsamples--)
|
||||
*soundout++ = 0x0000;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AudioEnabled && SoundEngine)
|
||||
{
|
||||
while (numsamples--)
|
||||
{
|
||||
int16_t sample = MinxAudio_FIFORead();
|
||||
for (j=0; j<channels; j++)
|
||||
*soundout++ = sample;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (numsamples--)
|
||||
for (j=0; j<channels; j++)
|
||||
*soundout++ = 0x0000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* PokeMiniEmu: the sound for the Paradise's buzzer: frequency in Hz (0 = silent) and loudness 0..3 */
|
||||
void pm_audio_now(int *hz, int *vol)
|
||||
{
|
||||
int f = 0, pw = 0;
|
||||
MinxAudio_GetEmulated(&f, &pw);
|
||||
*vol = (PMR_AUD_CTRL & 0x03) ? 0 : (PMR_AUD_VOL & 3);
|
||||
*hz = (pw <= 0 || pw >= 4095) ? 0 : f;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MINXHW_AUDIO
|
||||
#define MINXHW_AUDIO
|
||||
|
||||
#include "MinxTimers.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <streams/memory_stream.h>
|
||||
|
||||
typedef struct {
|
||||
// Internal processing
|
||||
int32_t AudioCCnt; // Audio cycle counter 8.24 (Needs signed)
|
||||
uint32_t AudioSCnt; // Audio sample counter 8.24 (Needs unsigned)
|
||||
int16_t Volume; // Volume (S16 sample)
|
||||
int16_t PWMMul; // PWM Multiplication
|
||||
} TMinxAudio;
|
||||
|
||||
// Export Audio state
|
||||
extern TMinxAudio MinxAudio;
|
||||
|
||||
// Audio enabled
|
||||
extern int AudioEnabled;
|
||||
|
||||
// Sound engine
|
||||
extern int SoundEngine;
|
||||
|
||||
// Piezo Filter
|
||||
extern int PiezoFilter;
|
||||
|
||||
// Require sound sync
|
||||
extern int RequireSoundSync;
|
||||
|
||||
|
||||
enum {
|
||||
MINX_AUDIO_DISABLED = 0, // Disabled
|
||||
MINX_AUDIO_GENERATED, // Generated (Doesn't require sync)
|
||||
MINX_AUDIO_DIRECTPWM // Direct from Timer 3 with PWM support
|
||||
};
|
||||
|
||||
enum {
|
||||
MINX_AUDIO_SILENCE = 0x0000,
|
||||
MINX_AUDIO_MED_VOL = 0x2000,
|
||||
MINX_AUDIO_MAX_VOL = 0x4000,
|
||||
MINX_AUDIO_PWM_RAG = 0x1FFF // Max + Pwm*2 must not be over 0x7FFF
|
||||
};
|
||||
|
||||
#ifndef MINX_AUDIOFREQ
|
||||
#define MINX_AUDIOFREQ (44100)
|
||||
#endif
|
||||
|
||||
// Aproximate value of 1 sample per cycle at 44100Hz (16M / ( 4M / 44K ))
|
||||
#ifndef MINX_AUDIOINC
|
||||
#define MINX_AUDIOINC (184969)
|
||||
#endif
|
||||
|
||||
// Conversion for the generator counter
|
||||
#define MINX_AUDIOCONV (2147483647/(MINX_AUDIOFREQ)*2)
|
||||
|
||||
int MinxAudio_Create(int audioenable, int fifosize);
|
||||
|
||||
void MinxAudio_Destroy(void);
|
||||
|
||||
void MinxAudio_Reset(int hardreset);
|
||||
|
||||
int MinxAudio_LoadStateStream(memstream_t *stream, uint32_t bsize);
|
||||
|
||||
int MinxAudio_SaveStateStream(memstream_t *stream);
|
||||
|
||||
void MinxAudio_ChangeEngine(int engine);
|
||||
|
||||
void MinxAudio_ChangeFilter(int piezo);
|
||||
|
||||
void MinxAudio_Sync(void);
|
||||
|
||||
uint8_t MinxAudio_ReadReg(uint8_t reg);
|
||||
|
||||
void MinxAudio_WriteReg(uint8_t reg, uint8_t val);
|
||||
|
||||
int16_t MinxAudio_PiezoFilter(int32_t Sample);
|
||||
|
||||
void MinxAudio_GetSamplesS16Ch(int16_t *soundout, int numsamples, int channels);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2012 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PokeMini.h"
|
||||
|
||||
TMinxCPU MinxCPU;
|
||||
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
|
||||
int MinxCPU_Create(void)
|
||||
{
|
||||
// Init variables
|
||||
MinxCPU.BA.D = 0;
|
||||
MinxCPU.HL.D = 0;
|
||||
MinxCPU.X.D = 0;
|
||||
MinxCPU.Y.D = 0;
|
||||
MinxCPU.SP.D = 0;
|
||||
MinxCPU.PC.D = 0;
|
||||
MinxCPU.N.D = 0;
|
||||
MinxCPU.E = 0;
|
||||
MinxCPU.F = 0xC0;
|
||||
Set_U(0);
|
||||
MinxCPU.Status = MINX_STATUS_NORMAL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MinxCPU_Destroy(void)
|
||||
{
|
||||
// Nothing...
|
||||
}
|
||||
|
||||
// Reset core, call it after OnRead/OnWrite point to the right BIOS
|
||||
void MinxCPU_Reset(int hardreset)
|
||||
{
|
||||
MinxCPU.Status = MINX_STATUS_NORMAL;
|
||||
MinxCPU.PC.W.L = ReadMem16(hardreset ? 0 : 2);
|
||||
MinxCPU.E = 0x1F;
|
||||
MinxCPU.F = 0xC0;
|
||||
Set_U(0);
|
||||
MinxCPU_OnIRQHandle(MinxCPU.F, MinxCPU.Shift_U);
|
||||
}
|
||||
|
||||
// Load State from stream
|
||||
int MinxCPU_LoadStateStream(memstream_t *stream, uint32_t bsize)
|
||||
{
|
||||
POKELOADSS_START(64);
|
||||
POKELOADSS_STREAM_32(MinxCPU.BA.D);
|
||||
POKELOADSS_STREAM_32(MinxCPU.HL.D);
|
||||
POKELOADSS_STREAM_32(MinxCPU.X.D);
|
||||
POKELOADSS_STREAM_32(MinxCPU.Y.D);
|
||||
POKELOADSS_STREAM_32(MinxCPU.SP.D);
|
||||
POKELOADSS_STREAM_32(MinxCPU.PC.D);
|
||||
POKELOADSS_STREAM_32(MinxCPU.N.D);
|
||||
POKELOADSS_STREAM_8(MinxCPU.U1);
|
||||
POKELOADSS_STREAM_8(MinxCPU.U2);
|
||||
POKELOADSS_STREAM_8(MinxCPU.F);
|
||||
POKELOADSS_STREAM_8(MinxCPU.E);
|
||||
POKELOADSS_STREAM_8(MinxCPU.IR);
|
||||
POKELOADSS_STREAM_8(MinxCPU.Shift_U);
|
||||
POKELOADSS_STREAM_8(MinxCPU.Status);
|
||||
POKELOADSS_STREAM_8(MinxCPU.IRQ_Vector);
|
||||
POKELOADSS_STREAM_A(MinxCPU.Reserved, 28);
|
||||
POKELOADSS_END(64);
|
||||
}
|
||||
|
||||
// Save State to stream
|
||||
int MinxCPU_SaveStateStream(memstream_t *stream)
|
||||
{
|
||||
POKESAVESS_STREAM_START(64);
|
||||
POKESAVESS_STREAM_32(MinxCPU.BA.D);
|
||||
POKESAVESS_STREAM_32(MinxCPU.HL.D);
|
||||
POKESAVESS_STREAM_32(MinxCPU.X.D);
|
||||
POKESAVESS_STREAM_32(MinxCPU.Y.D);
|
||||
POKESAVESS_STREAM_32(MinxCPU.SP.D);
|
||||
POKESAVESS_STREAM_32(MinxCPU.PC.D);
|
||||
POKESAVESS_STREAM_32(MinxCPU.N.D);
|
||||
POKESAVESS_STREAM_8(MinxCPU.U1);
|
||||
POKESAVESS_STREAM_8(MinxCPU.U2);
|
||||
POKESAVESS_STREAM_8(MinxCPU.F);
|
||||
POKESAVESS_STREAM_8(MinxCPU.E);
|
||||
POKESAVESS_STREAM_8(MinxCPU.IR);
|
||||
POKESAVESS_STREAM_8(MinxCPU.Shift_U);
|
||||
POKESAVESS_STREAM_8(MinxCPU.Status);
|
||||
POKESAVESS_STREAM_8(MinxCPU.IRQ_Vector);
|
||||
POKESAVESS_STREAM_A(MinxCPU.Reserved, 28);
|
||||
POKESAVESS_END(64);
|
||||
}
|
||||
|
||||
// Force call Interrupt by the address
|
||||
int MinxCPU_CallIRQ(uint8_t addr)
|
||||
{
|
||||
if (MinxCPU.Status == MINX_STATUS_IRQ) return 0;
|
||||
MinxCPU.Status = MINX_STATUS_IRQ;
|
||||
MinxCPU.IRQ_Vector = addr;
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,695 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2012 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MINXCPU_CORE
|
||||
#define MINXCPU_CORE
|
||||
|
||||
#include <stdint.h>
|
||||
#include <retro_inline.h>
|
||||
#include <streams/memory_stream.h>
|
||||
|
||||
/* For some reason, '_BIG_ENDIAN' is always defined when
|
||||
* building for 3DS/Switch with devkitarm/a64... */
|
||||
#if defined (_BIG_ENDIAN) && !defined (_3DS) && !defined(HAVE_LIBNX)
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t X;
|
||||
uint8_t I;
|
||||
uint8_t H;
|
||||
uint8_t L;
|
||||
} B;
|
||||
struct {
|
||||
uint16_t H;
|
||||
uint16_t L;
|
||||
} W;
|
||||
uint32_t D;
|
||||
} MinxRegx;
|
||||
|
||||
#else
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t L;
|
||||
uint8_t H;
|
||||
uint8_t I;
|
||||
uint8_t X;
|
||||
} B;
|
||||
struct {
|
||||
uint16_t L;
|
||||
uint16_t H;
|
||||
} W;
|
||||
uint32_t D;
|
||||
} MinxRegx;
|
||||
|
||||
#endif
|
||||
|
||||
#define MINX_FLAG_ZERO 0x01
|
||||
#define MINX_FLAG_CARRY 0x02
|
||||
#define MINX_FLAG_OVERFLOW 0x04
|
||||
#define MINX_FLAG_SIGN 0x08
|
||||
#define MINX_FLAG_BCD 0x10
|
||||
#define MINX_FLAG_NIBBLE 0x20
|
||||
#define MINX_FLAG_INTFLG 0x40
|
||||
#define MINX_FLAG_INTOFF 0x80
|
||||
|
||||
#define MINX_FLAG_SAVE_NUL 0xF0
|
||||
#define MINX_FLAG_SAVE_O 0xF4
|
||||
#define MINX_FLAG_SAVE_CO 0xF6
|
||||
#define MINX_FLAG_SAVE_COS 0xFE
|
||||
|
||||
// Status reasons
|
||||
enum {
|
||||
MINX_STATUS_NORMAL = 0, // Normal operation
|
||||
MINX_STATUS_HALT = 1, // CPU during HALT
|
||||
MINX_STATUS_STOP = 2, // CPU during STOP
|
||||
MINX_STATUS_IRQ = 3 // Delay caused by hardware IRQ
|
||||
};
|
||||
|
||||
// Signed 8-Bits to 16-Bits converter
|
||||
static INLINE uint16_t S8_TO_16(int8_t a)
|
||||
{
|
||||
return (a & 0x80) ? (0xFF00 | a) : a;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
// Registers
|
||||
MinxRegx BA; // Registers A, B
|
||||
MinxRegx HL; // Registers L, H, I
|
||||
MinxRegx X; // Registers X, XI
|
||||
MinxRegx Y; // Registers Y, YI
|
||||
MinxRegx SP; // Register SP
|
||||
MinxRegx PC; // Registers PC, V
|
||||
MinxRegx N; // for [N+#nn], I is written here too
|
||||
uint8_t U1; // V Shadow 1
|
||||
uint8_t U2; // V Shadow 2
|
||||
uint8_t F; // Flags
|
||||
uint8_t E; // Exception
|
||||
uint8_t IR; // Last Instruction Register (for open-bus)
|
||||
uint8_t Shift_U; // Shift U, set to 2 when: U modify, branch, return
|
||||
uint8_t Status; // CPU Status (0 = Normal, 1 = Halt, 2 = Stoped, 3 = IRQ)
|
||||
uint8_t IRQ_Vector; // IRQ Vector when Status is IRQ
|
||||
uint8_t Reserved[28]; // Reserved bytes
|
||||
} TMinxCPU;
|
||||
|
||||
// CPU registers
|
||||
extern TMinxCPU MinxCPU;
|
||||
|
||||
// Callbacks (Must be coded by the user)
|
||||
uint8_t MinxCPU_OnRead(int cpu, uint32_t addr);
|
||||
void MinxCPU_OnWrite(int cpu, uint32_t addr, uint8_t data);
|
||||
void MinxCPU_OnIRQHandle(uint8_t flag, uint8_t shift_u);
|
||||
void MinxCPU_OnIRQAct(uint8_t intr);
|
||||
|
||||
// Functions
|
||||
int MinxCPU_Create(void); // Create MinxCPU
|
||||
void MinxCPU_Destroy(void); // Destroy MinxCPU
|
||||
void MinxCPU_Reset(int hardreset); // Reset CPU
|
||||
int MinxCPU_LoadStateStream(memstream_t *stream, uint32_t bsize); // Load State from stream
|
||||
int MinxCPU_SaveStateStream(memstream_t *stream); // Save State to stream
|
||||
int MinxCPU_Exec(void); // Execute 1 CPU instruction
|
||||
int MinxCPU_CallIRQ(uint8_t IRQ); // Call an IRQ
|
||||
|
||||
// Helpers
|
||||
static INLINE uint16_t ReadMem16(uint32_t addr)
|
||||
{
|
||||
return MinxCPU_OnRead(1, addr) + (MinxCPU_OnRead(1, addr+1) << 8);
|
||||
}
|
||||
|
||||
static INLINE void WriteMem16(uint32_t addr, uint16_t data)
|
||||
{
|
||||
MinxCPU_OnWrite(1, addr, (uint8_t)data);
|
||||
MinxCPU_OnWrite(1, addr+1, data >> 8);
|
||||
}
|
||||
|
||||
static INLINE uint8_t Fetch8(void)
|
||||
{
|
||||
if (MinxCPU.PC.W.L & 0x8000) {
|
||||
// Banked area
|
||||
MinxCPU.IR = MinxCPU_OnRead(1, (MinxCPU.PC.W.L++ & 0x7FFF) | (MinxCPU.PC.B.I << 15));
|
||||
} else {
|
||||
// Unbanked area
|
||||
MinxCPU.IR = MinxCPU_OnRead(1, MinxCPU.PC.W.L++);
|
||||
}
|
||||
return MinxCPU.IR;
|
||||
}
|
||||
|
||||
static INLINE uint16_t Fetch16(void)
|
||||
{
|
||||
uint8_t LB = Fetch8();
|
||||
return (Fetch8() << 8) | LB;
|
||||
}
|
||||
|
||||
static INLINE void Set_U(uint8_t val)
|
||||
{
|
||||
if (val != MinxCPU.U2) MinxCPU.Shift_U = 2;
|
||||
MinxCPU.U1 = val;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU_OnIRQHandle(MinxCPU.F, MinxCPU.Shift_U);
|
||||
}
|
||||
|
||||
// Instruction exec. prototypes
|
||||
|
||||
int MinxCPU_ExecCE(void);
|
||||
int MinxCPU_ExecCF(void);
|
||||
int MinxCPU_ExecSPCE(void);
|
||||
int MinxCPU_ExecSPCF(void);
|
||||
|
||||
// Instructions Macros
|
||||
|
||||
static INLINE uint8_t ADD8(uint8_t A, uint8_t B)
|
||||
{
|
||||
register uint8_t RES;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
switch (MinxCPU.F & 0x30) {
|
||||
case 0x00: // Normal
|
||||
RES = A + B;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES < A) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x80) != 0) && (((A ^ B) & 0x80) == 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 128) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return RES & 0xFF;
|
||||
case 0x10: // BCD
|
||||
if ((uint8_t)((A & 15) + (B & 15)) >= 10) {
|
||||
RES = A + B + 6;
|
||||
} else {
|
||||
RES = A + B;
|
||||
}
|
||||
if (RES >= 0xA0) RES += 0x60;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES < A) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
return RES & 0xFF;
|
||||
case 0x20: // Nibble
|
||||
RES = (A & 15) + (B & 15);
|
||||
if ((RES & 15) == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES >= 16) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x8) != 0) && (((A ^ B) & 0x8) == 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 8) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return RES & 0x0F;
|
||||
default: // BCD and Nibble
|
||||
if ((uint8_t)((A & 15) + (B & 15)) >= 10) {
|
||||
RES = (A & 15) + (B & 15) + 6;
|
||||
} else {
|
||||
RES = (A & 15) + (B & 15);
|
||||
}
|
||||
if ((RES & 15) == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES >= 16) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
return RES & 0x0F;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE uint16_t ADD16(uint16_t A, uint16_t B)
|
||||
{
|
||||
register uint16_t RES;
|
||||
RES = A + B;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES < A) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x8000) != 0) && (((A ^ B) & 0x8000) == 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 0x8000) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return (uint16_t)RES;
|
||||
}
|
||||
|
||||
static INLINE uint8_t ADC8(uint8_t A, uint8_t B)
|
||||
{
|
||||
register uint8_t RES;
|
||||
register uint8_t CARRY = (MinxCPU.F & MINX_FLAG_CARRY) ? 1 : 0;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
switch (MinxCPU.F & 0x30) {
|
||||
case 0x00: // Normal
|
||||
RES = A + B + CARRY;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES < A) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x80) != 0) && (((A ^ B) & 0x80) == 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 128) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return RES & 0xFF;
|
||||
case 0x10: // BCD
|
||||
if ((uint8_t)((A & 15) + (B & 15) + CARRY) >= 10) {
|
||||
RES = A + B + CARRY + 6;
|
||||
} else {
|
||||
RES = A + B + CARRY;
|
||||
}
|
||||
if (RES >= 0xA0) RES += 0x60;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES < A) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
return RES & 0xFF;
|
||||
case 0x20: // Nibble
|
||||
RES = (A & 15) + (B & 15) + CARRY;
|
||||
if ((RES & 15) == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES >= 16) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x8) != 0) && (((A ^ B) & 0x8) == 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 8) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return RES & 0x0F;
|
||||
default: // BCD and Nibble
|
||||
if ((uint8_t)((A & 15) + (B & 15) + CARRY) >= 10) {
|
||||
RES = (A & 15) + (B & 15) + CARRY + 6;
|
||||
} else {
|
||||
RES = (A & 15) + (B & 15) + CARRY;
|
||||
}
|
||||
if ((RES & 15) == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES >= 16) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
return RES & 0x0F;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE uint16_t ADC16(uint16_t A, uint16_t B)
|
||||
{
|
||||
register uint16_t RES;
|
||||
RES = A + B + ((MinxCPU.F & MINX_FLAG_CARRY) ? 1 : 0);
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES < A) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x8000) != 0) && (((A ^ B) & 0x8000) == 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 0x8000) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return (uint16_t)RES;
|
||||
}
|
||||
|
||||
static INLINE uint8_t SUB8(uint8_t A, uint8_t B)
|
||||
{
|
||||
register uint8_t RES;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
switch (MinxCPU.F & 0x30) {
|
||||
case 0x00: // Normal
|
||||
RES = A - B;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A < B) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x80) != 0) && (((A ^ B) & 0x80) != 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 128) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return RES & 0xFF;
|
||||
case 0x10: // BCD
|
||||
if ((uint8_t)((A & 15) - (B & 15)) >= 10) {
|
||||
RES = A - B - 6;
|
||||
} else {
|
||||
RES = A - B;
|
||||
}
|
||||
if (RES >= 0xA0) RES -= 0x60;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A < B) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
return RES & 0xFF;
|
||||
case 0x20: // Nibble
|
||||
RES = (A & 15) - (B & 15);
|
||||
if ((RES & 15) == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES >= 16) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x8) != 0) && (((A ^ B) & 0x8) != 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 8) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return RES & 0x0F;
|
||||
default: // BCD and Nibble
|
||||
if ((uint8_t)((A & 15) - (B & 15)) >= 10) {
|
||||
RES = (A & 15) - (B & 15) - 6;
|
||||
} else {
|
||||
RES = (A & 15) - (B & 15);
|
||||
}
|
||||
if ((RES & 15) == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES >= 16) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
return RES & 0x0F;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE uint16_t SUB16(uint16_t A, uint16_t B)
|
||||
{
|
||||
register uint16_t RES;
|
||||
RES = A - B;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A < B) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x8000) != 0) && (((A ^ B) & 0x8000) != 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 0x8000) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return (uint16_t)RES;
|
||||
}
|
||||
|
||||
static INLINE uint8_t SBC8(uint8_t A, uint8_t B)
|
||||
{
|
||||
register uint8_t RES;
|
||||
register uint8_t CARRY = (MinxCPU.F & MINX_FLAG_CARRY) ? 1 : 0;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
switch (MinxCPU.F & 0x30) {
|
||||
case 0x00: // Normal
|
||||
RES = A - B - CARRY;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A < B) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x80) != 0) && (((A ^ B) & 0x80) != 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 128) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return RES & 0xFF;
|
||||
case 0x10: // BCD
|
||||
if ((uint8_t)((A & 15) - (B & 15) - CARRY) >= 10) {
|
||||
RES = A - B - CARRY - 6;
|
||||
} else {
|
||||
RES = A - B - CARRY;
|
||||
}
|
||||
if (RES >= 0xA0) RES -= 0x60;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A < B) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
return RES & 0xFF;
|
||||
case 0x20: // Nibble
|
||||
RES = (A & 15) - (B & 15) - CARRY;
|
||||
if ((RES & 15) == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES >= 16) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x8) != 0) && (((A ^ B) & 0x8) != 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 8) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return RES & 0x0F;
|
||||
default: // BCD and Nibble
|
||||
if ((uint8_t)((A & 15) - (B & 15) - CARRY) >= 10) {
|
||||
RES = (A & 15) - (B & 15) - CARRY - 6;
|
||||
} else {
|
||||
RES = (A & 15) - (B & 15) - CARRY;
|
||||
}
|
||||
if ((RES & 15) == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (RES >= 16) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
return RES & 0x0F;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE uint16_t SBC16(uint16_t A, uint16_t B)
|
||||
{
|
||||
register uint16_t RES;
|
||||
RES = A - B - ((MinxCPU.F & MINX_FLAG_CARRY) ? 1 : 0);
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
if (RES == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A < B) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((((A ^ RES) & 0x8000) != 0) && (((A ^ B) & 0x8000) != 0)) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (RES & 0x8000) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return (uint16_t)RES;
|
||||
}
|
||||
|
||||
static INLINE uint8_t AND8(uint8_t A, uint8_t B)
|
||||
{
|
||||
A &= B;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_CO;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 128) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t OR8(uint8_t A, uint8_t B)
|
||||
{
|
||||
A |= B;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_CO;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 128) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t XOR8(uint8_t A, uint8_t B)
|
||||
{
|
||||
A ^= B;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_CO;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 128) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t INC8(uint8_t A)
|
||||
{
|
||||
A++;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_COS;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint16_t INC16(uint16_t A)
|
||||
{
|
||||
A++;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_COS;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t DEC8(uint8_t A)
|
||||
{
|
||||
A--;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_COS;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint16_t DEC16(uint16_t A)
|
||||
{
|
||||
A--;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_COS;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE void PUSH(uint8_t A)
|
||||
{
|
||||
MinxCPU.SP.W.L--;
|
||||
MinxCPU_OnWrite(1, MinxCPU.SP.D, A);
|
||||
}
|
||||
|
||||
static INLINE uint8_t POP(void)
|
||||
{
|
||||
register uint8_t data;
|
||||
data = MinxCPU_OnRead(1, MinxCPU.SP.D);
|
||||
MinxCPU.SP.W.L++;
|
||||
return data;
|
||||
}
|
||||
|
||||
static INLINE void CALLS(uint16_t OFFSET)
|
||||
{
|
||||
PUSH(MinxCPU.PC.B.I);
|
||||
PUSH(MinxCPU.PC.B.H);
|
||||
PUSH(MinxCPU.PC.B.L);
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = MinxCPU.PC.W.L + OFFSET - 1;
|
||||
}
|
||||
|
||||
static INLINE void JMPS(uint16_t OFFSET)
|
||||
{
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = MinxCPU.PC.W.L + OFFSET - 1;
|
||||
}
|
||||
|
||||
static INLINE void CALLU(uint16_t ADDR)
|
||||
{
|
||||
PUSH(MinxCPU.PC.B.I);
|
||||
PUSH(MinxCPU.PC.B.H);
|
||||
PUSH(MinxCPU.PC.B.L);
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = ADDR;
|
||||
}
|
||||
|
||||
static INLINE void JMPU(uint16_t ADDR)
|
||||
{
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = ADDR;
|
||||
}
|
||||
|
||||
static INLINE void JDBNZ(uint16_t OFFSET)
|
||||
{
|
||||
MinxCPU.BA.B.H = DEC8(MinxCPU.BA.B.H);
|
||||
if (MinxCPU.BA.B.H != 0) {
|
||||
JMPS(OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE uint8_t SWAP(uint8_t A)
|
||||
{
|
||||
return (A << 4) | (A >> 4);
|
||||
}
|
||||
|
||||
static INLINE void RET(void)
|
||||
{
|
||||
MinxCPU.PC.B.L = POP();
|
||||
MinxCPU.PC.B.H = POP();
|
||||
MinxCPU.PC.B.I = POP();
|
||||
Set_U(MinxCPU.PC.B.I);
|
||||
}
|
||||
|
||||
static INLINE void RETI(void)
|
||||
{
|
||||
MinxCPU.F = POP();
|
||||
MinxCPU.PC.B.L = POP();
|
||||
MinxCPU.PC.B.H = POP();
|
||||
MinxCPU.PC.B.I = POP();
|
||||
Set_U(MinxCPU.PC.B.I);
|
||||
MinxCPU_OnIRQHandle(MinxCPU.F, MinxCPU.Shift_U);
|
||||
}
|
||||
|
||||
static INLINE void CALLX(uint16_t ADDR)
|
||||
{
|
||||
PUSH(MinxCPU.PC.B.I);
|
||||
PUSH(MinxCPU.PC.B.H);
|
||||
PUSH(MinxCPU.PC.B.L);
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = ReadMem16((MinxCPU.HL.B.I << 16) + ADDR);
|
||||
}
|
||||
|
||||
static INLINE void CALLI(uint16_t ADDR)
|
||||
{
|
||||
PUSH(MinxCPU.PC.B.I);
|
||||
PUSH(MinxCPU.PC.B.H);
|
||||
PUSH(MinxCPU.PC.B.L);
|
||||
PUSH(MinxCPU.F);
|
||||
MinxCPU.F |= 0xC0;
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = ReadMem16(ADDR);
|
||||
MinxCPU_OnIRQHandle(MinxCPU.F, MinxCPU.Shift_U);
|
||||
}
|
||||
|
||||
static INLINE void JMPI(uint16_t ADDR)
|
||||
{
|
||||
PUSH(MinxCPU.F);
|
||||
MinxCPU.F |= 0xC0;
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = ReadMem16(ADDR);
|
||||
MinxCPU_OnIRQHandle(MinxCPU.F, MinxCPU.Shift_U);
|
||||
}
|
||||
|
||||
static INLINE uint8_t SAL(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((!(A & 0x40)) != (!(A & 0x80))) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
A = A << 1;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t SHL(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = A << 1;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t SAR(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
if (A & 0x01) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = (A & 0x80) | (A >> 1);
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t SHR(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x01) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = A >> 1;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t ROLC(uint8_t A)
|
||||
{
|
||||
register uint8_t CARRY = (MinxCPU.F & MINX_FLAG_CARRY) ? 1 : 0;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = (A << 1) | CARRY;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t ROL(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = (A << 1) | (A >> 7);
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t RORC(uint8_t A)
|
||||
{
|
||||
register uint8_t CARRY = (MinxCPU.F & MINX_FLAG_CARRY) ? 0x80 : 0x00;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x01) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = (A >> 1) | CARRY;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t ROR(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x01) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = (A >> 1) | (A << 7);
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t NOT(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_CO;
|
||||
A = A ^ 0xFF;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t NEG(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
A = -A;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO; else MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if (A == 0x80) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE void HALT(void)
|
||||
{
|
||||
MinxCPU.Status = MINX_STATUS_HALT;
|
||||
}
|
||||
|
||||
static INLINE void STOP(void)
|
||||
{
|
||||
MinxCPU.Status = MINX_STATUS_STOP;
|
||||
}
|
||||
|
||||
static INLINE void MUL(void)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
MinxCPU.HL.W.L = (uint16_t)MinxCPU.HL.B.L * (uint16_t)MinxCPU.BA.B.L;
|
||||
if (MinxCPU.HL.W.L == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (MinxCPU.HL.W.L & 0x8000) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
}
|
||||
|
||||
static INLINE void DIV(void)
|
||||
{
|
||||
uint16_t RES;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
if (MinxCPU.BA.B.L == 0)
|
||||
return;
|
||||
RES = MinxCPU.HL.W.L / MinxCPU.BA.B.L;
|
||||
if (RES < 256) {
|
||||
MinxCPU.HL.B.H = MinxCPU.HL.W.L % MinxCPU.BA.B.L;
|
||||
MinxCPU.HL.B.L = (uint8_t)RES;
|
||||
if (MinxCPU.HL.B.L == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
if (MinxCPU.HL.B.L & 0x80) MinxCPU.F |= MINX_FLAG_SIGN;
|
||||
} else MinxCPU.F |= (MINX_FLAG_OVERFLOW | MINX_FLAG_SIGN);
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,779 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2012 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Note: Any write to MinxCPU.HL.B.I needs to be reflected into MinxCPU.N.B.I
|
||||
|
||||
#include "MinxCPU.h"
|
||||
|
||||
int MinxCPU_ExecCF(void)
|
||||
{
|
||||
uint8_t I8A;
|
||||
uint16_t I16;
|
||||
|
||||
// Read IR
|
||||
MinxCPU.IR = Fetch8();
|
||||
|
||||
// Process instruction
|
||||
switch(MinxCPU.IR) {
|
||||
case 0x00: // ADD BA, BA
|
||||
MinxCPU.BA.W.L = ADD16(MinxCPU.BA.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x01: // ADD BA, HL
|
||||
MinxCPU.BA.W.L = ADD16(MinxCPU.BA.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x02: // ADD BA, X
|
||||
MinxCPU.BA.W.L = ADD16(MinxCPU.BA.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x03: // ADD BA, Y
|
||||
MinxCPU.BA.W.L = ADD16(MinxCPU.BA.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x04: // ADC BA, BA
|
||||
MinxCPU.BA.W.L = ADC16(MinxCPU.BA.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x05: // ADC BA, HL
|
||||
MinxCPU.BA.W.L = ADC16(MinxCPU.BA.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x06: // ADC BA, X
|
||||
MinxCPU.BA.W.L = ADC16(MinxCPU.BA.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x07: // ADC BA, Y
|
||||
MinxCPU.BA.W.L = ADC16(MinxCPU.BA.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x08: // SUB BA, BA
|
||||
MinxCPU.BA.W.L = SUB16(MinxCPU.BA.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x09: // SUB BA, HL
|
||||
MinxCPU.BA.W.L = SUB16(MinxCPU.BA.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x0A: // SUB BA, X
|
||||
MinxCPU.BA.W.L = SUB16(MinxCPU.BA.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x0B: // SUB BA, Y
|
||||
MinxCPU.BA.W.L = SUB16(MinxCPU.BA.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x0C: // SBC BA, BA
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x0D: // SBC BA, HL
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x0E: // SBC BA, X
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x0F: // SBC BA, Y
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x10: // *ADD BA, BA
|
||||
MinxCPU.BA.W.L = ADD16(MinxCPU.BA.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x11: // *ADD BA, HL
|
||||
MinxCPU.BA.W.L = ADD16(MinxCPU.BA.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x12: // *ADD BA, X
|
||||
MinxCPU.BA.W.L = ADD16(MinxCPU.BA.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x13: // *ADD BA, Y
|
||||
MinxCPU.BA.W.L = ADD16(MinxCPU.BA.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x14: // *ADC BA, BA
|
||||
MinxCPU.BA.W.L = ADC16(MinxCPU.BA.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x15: // *ADC BA, HL
|
||||
MinxCPU.BA.W.L = ADC16(MinxCPU.BA.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x16: // *ADC BA, X
|
||||
MinxCPU.BA.W.L = ADC16(MinxCPU.BA.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x17: // *ADC BA, Y
|
||||
MinxCPU.BA.W.L = ADC16(MinxCPU.BA.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x18: // CMP BA, BA
|
||||
SUB16(MinxCPU.BA.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x19: // CMP BA, HL
|
||||
SUB16(MinxCPU.BA.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x1A: // CMP BA, X
|
||||
SUB16(MinxCPU.BA.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x1B: // CMP BA, Y
|
||||
SUB16(MinxCPU.BA.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x1C: // *SBC BA, BA
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x1D: // *SBC BA, HL
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x1E: // *SBC BA, X
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x1F: // *SBC BA, Y
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x20: // ADD HL, BA
|
||||
MinxCPU.HL.W.L = ADD16(MinxCPU.HL.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x21: // ADD HL, HL
|
||||
MinxCPU.HL.W.L = ADD16(MinxCPU.HL.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x22: // ADD HL, X
|
||||
MinxCPU.HL.W.L = ADD16(MinxCPU.HL.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x23: // ADD HL, Y
|
||||
MinxCPU.HL.W.L = ADD16(MinxCPU.HL.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x24: // ADC HL, BA
|
||||
MinxCPU.HL.W.L = ADC16(MinxCPU.HL.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x25: // ADC HL, HL
|
||||
MinxCPU.HL.W.L = ADC16(MinxCPU.HL.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x26: // ADC HL, X
|
||||
MinxCPU.HL.W.L = ADC16(MinxCPU.HL.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x27: // ADC HL, Y
|
||||
MinxCPU.HL.W.L = ADC16(MinxCPU.HL.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x28: // SUB HL, BA
|
||||
MinxCPU.HL.W.L = SUB16(MinxCPU.HL.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x29: // SUB HL, HL
|
||||
MinxCPU.HL.W.L = SUB16(MinxCPU.HL.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x2A: // SUB HL, X
|
||||
MinxCPU.HL.W.L = SUB16(MinxCPU.HL.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x2B: // SUB HL, Y
|
||||
MinxCPU.HL.W.L = SUB16(MinxCPU.HL.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x2C: // SBC HL, BA
|
||||
MinxCPU.HL.W.L = SBC16(MinxCPU.HL.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x2D: // SBC HL, HL
|
||||
MinxCPU.HL.W.L = SBC16(MinxCPU.HL.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x2E: // SBC HL, X
|
||||
MinxCPU.HL.W.L = SBC16(MinxCPU.HL.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x2F: // SBC HL, Y
|
||||
MinxCPU.HL.W.L = SBC16(MinxCPU.HL.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x30: // *ADD HL, BA
|
||||
MinxCPU.HL.W.L = ADD16(MinxCPU.HL.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x31: // *ADD BA, HL
|
||||
MinxCPU.HL.W.L = ADD16(MinxCPU.HL.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x32: // *ADD BA, X
|
||||
MinxCPU.HL.W.L = ADD16(MinxCPU.HL.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x33: // *ADD BA, Y
|
||||
MinxCPU.HL.W.L = ADD16(MinxCPU.HL.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x34: // *ADC HL, BA
|
||||
MinxCPU.HL.W.L = ADC16(MinxCPU.HL.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x35: // *ADC HL, HL
|
||||
MinxCPU.HL.W.L = ADC16(MinxCPU.HL.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x36: // *ADC HL, X
|
||||
MinxCPU.HL.W.L = ADC16(MinxCPU.HL.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x37: // *ADC HL, Y
|
||||
MinxCPU.HL.W.L = ADC16(MinxCPU.HL.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x38: // CMP HL, BA
|
||||
SUB16(MinxCPU.HL.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x39: // CMP HL, HL
|
||||
SUB16(MinxCPU.HL.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x3A: // CMP HL, X
|
||||
SUB16(MinxCPU.HL.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x3B: // CMP HL, Y
|
||||
SUB16(MinxCPU.HL.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x3C: // *SBC BA, BA
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x3D: // *SBC BA, HL
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x3E: // *SBC BA, X
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x3F: // *SBC BA, Y
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, MinxCPU.Y.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x40: // ADD X, BA
|
||||
MinxCPU.X.W.L = ADD16(MinxCPU.X.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x41: // ADD X, HL
|
||||
MinxCPU.X.W.L = ADD16(MinxCPU.X.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x42: // ADD Y, BA
|
||||
MinxCPU.Y.W.L = ADD16(MinxCPU.Y.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x43: // ADD Y, HL
|
||||
MinxCPU.Y.W.L = ADD16(MinxCPU.Y.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x44: // ADD SP, BA
|
||||
MinxCPU.SP.W.L = ADD16(MinxCPU.SP.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x45: // ADD SP, HL
|
||||
MinxCPU.SP.W.L = ADD16(MinxCPU.SP.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x46: // CRASH
|
||||
case 0x47: // CRASH
|
||||
return 16;
|
||||
|
||||
case 0x48: // SUB X, BA
|
||||
MinxCPU.X.W.L = SUB16(MinxCPU.X.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x49: // SUB X, HL
|
||||
MinxCPU.X.W.L = SUB16(MinxCPU.X.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x4A: // SUB Y, BA
|
||||
MinxCPU.Y.W.L = SUB16(MinxCPU.Y.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x4B: // SUB Y, HL
|
||||
MinxCPU.Y.W.L = SUB16(MinxCPU.Y.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x4C: // SUB SP, BA
|
||||
MinxCPU.SP.W.L = SUB16(MinxCPU.SP.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x4D: // SUB SP, HL
|
||||
MinxCPU.SP.W.L = SUB16(MinxCPU.SP.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x4E: // CRASH
|
||||
case 0x4F: // CRASH
|
||||
return 16;
|
||||
|
||||
case 0x50: // *ADD X, BA
|
||||
MinxCPU.X.W.L = ADD16(MinxCPU.X.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x51: // *ADD X, HL
|
||||
MinxCPU.X.W.L = ADD16(MinxCPU.X.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x52: // *ADD Y, BA
|
||||
MinxCPU.Y.W.L = ADD16(MinxCPU.Y.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x53: // *ADD Y, HL
|
||||
MinxCPU.Y.W.L = ADD16(MinxCPU.Y.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x54: // *ADD SP, BA
|
||||
MinxCPU.SP.W.L = ADD16(MinxCPU.SP.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x55: // *ADD SP, HL
|
||||
MinxCPU.SP.W.L = ADD16(MinxCPU.SP.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x56: // CRASH
|
||||
case 0x57: // CRASH
|
||||
return 16;
|
||||
|
||||
case 0x58: // *SUB X, BA
|
||||
MinxCPU.X.W.L = SUB16(MinxCPU.X.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x59: // *SUB X, HL
|
||||
MinxCPU.X.W.L = SUB16(MinxCPU.X.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x5A: // *SUB Y, BA
|
||||
MinxCPU.Y.W.L = SUB16(MinxCPU.Y.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x5B: // *SUB Y, HL
|
||||
MinxCPU.Y.W.L = SUB16(MinxCPU.Y.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x5C: // CMP SP, BA
|
||||
SUB16(MinxCPU.SP.W.L, MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x5D: // CMP SP, HL
|
||||
SUB16(MinxCPU.SP.W.L, MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x5E: // CRASH
|
||||
case 0x5F: // CRASH
|
||||
return 16;
|
||||
|
||||
case 0x60: // ADC BA, #nnnn
|
||||
I16 = Fetch16();
|
||||
MinxCPU.BA.W.L = ADC16(MinxCPU.BA.W.L, I16);
|
||||
return 16;
|
||||
case 0x61: // ADC HL, #nnnn
|
||||
I16 = Fetch16();
|
||||
MinxCPU.HL.W.L = ADC16(MinxCPU.HL.W.L, I16);
|
||||
return 16;
|
||||
case 0x62: // SBC BA, #nnnn
|
||||
I16 = Fetch16();
|
||||
MinxCPU.BA.W.L = SBC16(MinxCPU.BA.W.L, I16);
|
||||
return 16;
|
||||
case 0x63: // SBC HL, #nnnn
|
||||
I16 = Fetch16();
|
||||
MinxCPU.HL.W.L = SBC16(MinxCPU.HL.W.L, I16);
|
||||
return 16;
|
||||
|
||||
case 0x64: // UNSTABLE
|
||||
case 0x65: // UNSTABLE
|
||||
case 0x66: // UNSTABLE
|
||||
case 0x67: // UNSTABLE
|
||||
return 16;
|
||||
|
||||
case 0x68: // ADD SP, #nnnn
|
||||
I16 = Fetch16();
|
||||
MinxCPU.SP.W.L = ADD16(MinxCPU.SP.W.L, I16);
|
||||
return 16;
|
||||
|
||||
case 0x6A: // SUB SP, #nnnn
|
||||
I16 = Fetch16();
|
||||
MinxCPU.SP.W.L = SUB16(MinxCPU.SP.W.L, I16);
|
||||
return 16;
|
||||
case 0x69: // UNSTABLE
|
||||
case 0x6B: // UNSTABLE
|
||||
case 0x6D: // UNSTABLE
|
||||
case 0x6F: // UNSTABLE
|
||||
return 16;
|
||||
|
||||
case 0x6C: // CMP SP, #nnnn
|
||||
I16 = Fetch16();
|
||||
SUB16(MinxCPU.SP.W.L, I16);
|
||||
return 16;
|
||||
|
||||
case 0x6E: // MOV SP, #nnnn
|
||||
I16 = Fetch16();
|
||||
MinxCPU.SP.W.L = I16;
|
||||
return 16;
|
||||
|
||||
case 0x70: // MOV BA, [SP+#ss]
|
||||
I8A = Fetch8();
|
||||
I16 = MinxCPU.SP.W.L + S8_TO_16(I8A);
|
||||
MinxCPU.BA.B.L = MinxCPU_OnRead(1, I16++);
|
||||
MinxCPU.BA.B.H = MinxCPU_OnRead(1, I16);
|
||||
return 24;
|
||||
case 0x71: // MOV HL, [SP+#ss]
|
||||
I8A = Fetch8();
|
||||
I16 = MinxCPU.SP.W.L + S8_TO_16(I8A);
|
||||
MinxCPU.HL.B.L = MinxCPU_OnRead(1, I16++);
|
||||
MinxCPU.HL.B.H = MinxCPU_OnRead(1, I16);
|
||||
return 24;
|
||||
case 0x72: // MOV X, [SP+#ss]
|
||||
I8A = Fetch8();
|
||||
I16 = MinxCPU.SP.W.L + S8_TO_16(I8A);
|
||||
MinxCPU.X.B.L = MinxCPU_OnRead(1, I16++);
|
||||
MinxCPU.X.B.H = MinxCPU_OnRead(1, I16);
|
||||
return 24;
|
||||
case 0x73: // MOV Y, [SP+#ss]
|
||||
I8A = Fetch8();
|
||||
I16 = MinxCPU.SP.W.L + S8_TO_16(I8A);
|
||||
MinxCPU.Y.B.L = MinxCPU_OnRead(1, I16++);
|
||||
MinxCPU.Y.B.H = MinxCPU_OnRead(1, I16);
|
||||
return 24;
|
||||
|
||||
case 0x74: // MOV [SP+#ss], BA
|
||||
I8A = Fetch8();
|
||||
I16 = MinxCPU.SP.W.L + S8_TO_16(I8A);
|
||||
MinxCPU_OnWrite(1, I16++, MinxCPU.BA.B.L);
|
||||
MinxCPU_OnWrite(1, I16, MinxCPU.BA.B.H);
|
||||
return 24;
|
||||
case 0x75: // MOV [SP+#ss], HL
|
||||
I8A = Fetch8();
|
||||
I16 = MinxCPU.SP.W.L + S8_TO_16(I8A);
|
||||
MinxCPU_OnWrite(1, I16++, MinxCPU.HL.B.L);
|
||||
MinxCPU_OnWrite(1, I16, MinxCPU.HL.B.H);
|
||||
return 24;
|
||||
case 0x76: // MOV [SP+#ss], X
|
||||
I8A = Fetch8();
|
||||
I16 = MinxCPU.SP.W.L + S8_TO_16(I8A);
|
||||
MinxCPU_OnWrite(1, I16++, MinxCPU.X.B.L);
|
||||
MinxCPU_OnWrite(1, I16, MinxCPU.X.B.H);
|
||||
return 24;
|
||||
case 0x77: // MOV [SP+#ss], Y
|
||||
I8A = Fetch8();
|
||||
I16 = MinxCPU.SP.W.L + S8_TO_16(I8A);
|
||||
MinxCPU_OnWrite(1, I16++, MinxCPU.Y.B.L);
|
||||
MinxCPU_OnWrite(1, I16, MinxCPU.Y.B.H);
|
||||
return 24;
|
||||
|
||||
case 0x78: // MOV SP, [#nnnn]
|
||||
I16 = Fetch16();
|
||||
MinxCPU.SP.B.L = MinxCPU_OnRead(1, (MinxCPU.HL.B.I << 16) | I16++);
|
||||
MinxCPU.SP.B.H = MinxCPU_OnRead(1, (MinxCPU.HL.B.I << 16) | I16);
|
||||
return 24;
|
||||
|
||||
case 0x79: // ??? #nn
|
||||
case 0x7A: // ??? #nn
|
||||
case 0x7B: // ??? #nn
|
||||
return MinxCPU_ExecSPCF();
|
||||
|
||||
case 0x7C: // MOV [#nnnn], SP
|
||||
I16 = Fetch16();
|
||||
MinxCPU_OnWrite(1, (MinxCPU.HL.B.I << 16) | I16++, MinxCPU.SP.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.HL.B.I << 16) | I16, MinxCPU.SP.B.H);
|
||||
return 24;
|
||||
|
||||
case 0x7D: case 0x7E: case 0x7F: // ??? #nn
|
||||
case 0x80: case 0x81: case 0x82: case 0x83:
|
||||
case 0x84: case 0x85: case 0x86: case 0x87:
|
||||
case 0x88: case 0x89: case 0x8A: case 0x8B:
|
||||
case 0x8C: case 0x8D: case 0x8E: case 0x8F:
|
||||
case 0x90: case 0x91: case 0x92: case 0x93:
|
||||
case 0x94: case 0x95: case 0x96: case 0x97:
|
||||
case 0x98: case 0x99: case 0x9A: case 0x9B:
|
||||
case 0x9C: case 0x9D: case 0x9E: case 0x9F:
|
||||
case 0xA0: case 0xA1: case 0xA2: case 0xA3:
|
||||
case 0xA4: case 0xA5: case 0xA6: case 0xA7:
|
||||
case 0xA8: case 0xA9: case 0xAA: case 0xAB:
|
||||
case 0xAC: case 0xAD: case 0xAE: case 0xAF:
|
||||
return MinxCPU_ExecSPCF();
|
||||
|
||||
case 0xB0: // PUSH A
|
||||
PUSH(MinxCPU.BA.B.L);
|
||||
return 12;
|
||||
case 0xB1: // PUSH B
|
||||
PUSH(MinxCPU.BA.B.H);
|
||||
return 12;
|
||||
case 0xB2: // PUSH L
|
||||
PUSH(MinxCPU.HL.B.L);
|
||||
return 12;
|
||||
case 0xB3: // PUSH H
|
||||
PUSH(MinxCPU.HL.B.H);
|
||||
return 12;
|
||||
|
||||
case 0xB4: // POP A
|
||||
MinxCPU.BA.B.L = POP();
|
||||
return 12;
|
||||
case 0xB5: // POP B
|
||||
MinxCPU.BA.B.H = POP();
|
||||
return 12;
|
||||
case 0xB6: // POP L
|
||||
MinxCPU.HL.B.L = POP();
|
||||
return 12;
|
||||
case 0xB7: // POP H
|
||||
MinxCPU.HL.B.H = POP();
|
||||
return 12;
|
||||
case 0xB8: // PUSHA
|
||||
PUSH(MinxCPU.BA.B.H);
|
||||
PUSH(MinxCPU.BA.B.L);
|
||||
PUSH(MinxCPU.HL.B.H);
|
||||
PUSH(MinxCPU.HL.B.L);
|
||||
PUSH(MinxCPU.X.B.H);
|
||||
PUSH(MinxCPU.X.B.L);
|
||||
PUSH(MinxCPU.Y.B.H);
|
||||
PUSH(MinxCPU.Y.B.L);
|
||||
PUSH(MinxCPU.N.B.H);
|
||||
return 48;
|
||||
case 0xB9: // PUSHAX
|
||||
PUSH(MinxCPU.BA.B.H);
|
||||
PUSH(MinxCPU.BA.B.L);
|
||||
PUSH(MinxCPU.HL.B.H);
|
||||
PUSH(MinxCPU.HL.B.L);
|
||||
PUSH(MinxCPU.X.B.H);
|
||||
PUSH(MinxCPU.X.B.L);
|
||||
PUSH(MinxCPU.Y.B.H);
|
||||
PUSH(MinxCPU.Y.B.L);
|
||||
PUSH(MinxCPU.N.B.H);
|
||||
PUSH(MinxCPU.HL.B.I);
|
||||
PUSH(MinxCPU.X.B.I);
|
||||
PUSH(MinxCPU.Y.B.I);
|
||||
return 60;
|
||||
|
||||
case 0xBA: case 0xBB: // ??? #n
|
||||
return MinxCPU_ExecSPCF();
|
||||
|
||||
case 0xBC: // POPA
|
||||
MinxCPU.N.B.H = POP();
|
||||
MinxCPU.Y.B.L = POP();
|
||||
MinxCPU.Y.B.H = POP();
|
||||
MinxCPU.X.B.L = POP();
|
||||
MinxCPU.X.B.H = POP();
|
||||
MinxCPU.HL.B.L = POP();
|
||||
MinxCPU.HL.B.H = POP();
|
||||
MinxCPU.BA.B.L = POP();
|
||||
MinxCPU.BA.B.H = POP();
|
||||
return 44;
|
||||
|
||||
case 0xBD: // POPAX
|
||||
MinxCPU.Y.B.I = POP();
|
||||
MinxCPU.X.B.I = POP();
|
||||
MinxCPU.HL.B.I = POP();
|
||||
MinxCPU.N.B.I = MinxCPU.HL.B.I;
|
||||
MinxCPU.N.B.H = POP();
|
||||
MinxCPU.Y.B.L = POP();
|
||||
MinxCPU.Y.B.H = POP();
|
||||
MinxCPU.X.B.L = POP();
|
||||
MinxCPU.X.B.H = POP();
|
||||
MinxCPU.HL.B.L = POP();
|
||||
MinxCPU.HL.B.H = POP();
|
||||
MinxCPU.BA.B.L = POP();
|
||||
MinxCPU.BA.B.H = POP();
|
||||
return 56;
|
||||
|
||||
case 0xBE: case 0xBF: // ??? #n
|
||||
return MinxCPU_ExecSPCF();
|
||||
|
||||
case 0xC0: // MOV BA, [HL]
|
||||
I16 = MinxCPU.HL.W.L;
|
||||
MinxCPU.BA.B.L = MinxCPU_OnRead(1, (MinxCPU.HL.B.I << 16) | I16++);
|
||||
MinxCPU.BA.B.H = MinxCPU_OnRead(1, (MinxCPU.HL.B.I << 16) | I16);
|
||||
return 20;
|
||||
case 0xC1: // MOV HL, [HL]
|
||||
I16 = MinxCPU.HL.W.L;
|
||||
MinxCPU.HL.B.L = MinxCPU_OnRead(1, (MinxCPU.HL.B.I << 16) | I16++);
|
||||
MinxCPU.HL.B.H = MinxCPU_OnRead(1, (MinxCPU.HL.B.I << 16) | I16);
|
||||
return 20;
|
||||
case 0xC2: // MOV X, [HL]
|
||||
I16 = MinxCPU.HL.W.L;
|
||||
MinxCPU.X.B.L = MinxCPU_OnRead(1, (MinxCPU.HL.B.I << 16) | I16++);
|
||||
MinxCPU.X.B.H = MinxCPU_OnRead(1, (MinxCPU.HL.B.I << 16) | I16);
|
||||
return 20;
|
||||
case 0xC3: // MOV Y, [HL]
|
||||
I16 = MinxCPU.HL.W.L;
|
||||
MinxCPU.Y.B.L = MinxCPU_OnRead(1, (MinxCPU.HL.B.I << 16) | I16++);
|
||||
MinxCPU.Y.B.H = MinxCPU_OnRead(1, (MinxCPU.HL.B.I << 16) | I16);
|
||||
return 20;
|
||||
|
||||
case 0xC4: // MOV [HL], BA
|
||||
I16 = MinxCPU.HL.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.HL.B.I << 16) | I16++, MinxCPU.BA.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.HL.B.I << 16) | I16, MinxCPU.BA.B.H);
|
||||
return 20;
|
||||
case 0xC5: // MOV [HL], HL
|
||||
I16 = MinxCPU.HL.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.HL.B.I << 16) | I16++, MinxCPU.HL.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.HL.B.I << 16) | I16, MinxCPU.HL.B.H);
|
||||
return 20;
|
||||
case 0xC6: // MOV [HL], X
|
||||
I16 = MinxCPU.HL.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.HL.B.I << 16) | I16++, MinxCPU.X.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.HL.B.I << 16) | I16, MinxCPU.X.B.H);
|
||||
return 20;
|
||||
case 0xC7: // MOV [HL], Y
|
||||
I16 = MinxCPU.HL.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.HL.B.I << 16) | I16++, MinxCPU.Y.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.HL.B.I << 16) | I16, MinxCPU.Y.B.H);
|
||||
return 20;
|
||||
|
||||
case 0xC8: case 0xC9: case 0xCA: case 0xCB: // MOV B, V
|
||||
case 0xCC: case 0xCD: case 0xCE: case 0xCF:
|
||||
MinxCPU.BA.B.H = MinxCPU.PC.B.I;
|
||||
return 12;
|
||||
|
||||
case 0xD0: // MOV BA, [X]
|
||||
I16 = MinxCPU.X.W.L;
|
||||
MinxCPU.BA.B.L = MinxCPU_OnRead(1, (MinxCPU.X.B.I << 16) | I16++);
|
||||
MinxCPU.BA.B.H = MinxCPU_OnRead(1, (MinxCPU.X.B.I << 16) | I16);
|
||||
return 20;
|
||||
case 0xD1: // MOV HL, [X]
|
||||
I16 = MinxCPU.X.W.L;
|
||||
MinxCPU.HL.B.L = MinxCPU_OnRead(1, (MinxCPU.X.B.I << 16) | I16++);
|
||||
MinxCPU.HL.B.H = MinxCPU_OnRead(1, (MinxCPU.X.B.I << 16) | I16);
|
||||
return 20;
|
||||
case 0xD2: // MOV X, [X]
|
||||
I16 = MinxCPU.X.W.L;
|
||||
MinxCPU.X.B.L = MinxCPU_OnRead(1, (MinxCPU.X.B.I << 16) | I16++);
|
||||
MinxCPU.X.B.H = MinxCPU_OnRead(1, (MinxCPU.X.B.I << 16) | I16);
|
||||
return 20;
|
||||
case 0xD3: // MOV Y, [X]
|
||||
I16 = MinxCPU.X.W.L;
|
||||
MinxCPU.Y.B.L = MinxCPU_OnRead(1, (MinxCPU.X.B.I << 16) | I16++);
|
||||
MinxCPU.Y.B.H = MinxCPU_OnRead(1, (MinxCPU.X.B.I << 16) | I16);
|
||||
return 20;
|
||||
|
||||
case 0xD4: // MOV [X], BA
|
||||
I16 = MinxCPU.X.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.X.B.I << 16) | I16++, MinxCPU.BA.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.X.B.I << 16) | I16, MinxCPU.BA.B.H);
|
||||
return 20;
|
||||
case 0xD5: // MOV [X], HL
|
||||
I16 = MinxCPU.X.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.X.B.I << 16) | I16++, MinxCPU.HL.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.X.B.I << 16) | I16, MinxCPU.HL.B.H);
|
||||
return 20;
|
||||
case 0xD6: // MOV [X], X
|
||||
I16 = MinxCPU.X.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.X.B.I << 16) | I16++, MinxCPU.X.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.X.B.I << 16) | I16, MinxCPU.X.B.H);
|
||||
return 20;
|
||||
case 0xD7: // MOV [X], Y
|
||||
I16 = MinxCPU.X.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.X.B.I << 16) | I16++, MinxCPU.Y.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.X.B.I << 16) | I16, MinxCPU.Y.B.H);
|
||||
return 20;
|
||||
|
||||
case 0xD8: // MOV BA, [Y]
|
||||
I16 = MinxCPU.Y.W.L;
|
||||
MinxCPU.BA.B.L = MinxCPU_OnRead(1, (MinxCPU.Y.B.I << 16) | I16++);
|
||||
MinxCPU.BA.B.H = MinxCPU_OnRead(1, (MinxCPU.Y.B.I << 16) | I16);
|
||||
return 20;
|
||||
case 0xD9: // MOV HL, [Y]
|
||||
I16 = MinxCPU.Y.W.L;
|
||||
MinxCPU.HL.B.L = MinxCPU_OnRead(1, (MinxCPU.Y.B.I << 16) | I16++);
|
||||
MinxCPU.HL.B.H = MinxCPU_OnRead(1, (MinxCPU.Y.B.I << 16) | I16);
|
||||
return 20;
|
||||
case 0xDA: // MOV X, [Y]
|
||||
I16 = MinxCPU.Y.W.L;
|
||||
MinxCPU.X.B.L = MinxCPU_OnRead(1, (MinxCPU.Y.B.I << 16) | I16++);
|
||||
MinxCPU.X.B.H = MinxCPU_OnRead(1, (MinxCPU.Y.B.I << 16) | I16);
|
||||
return 20;
|
||||
case 0xDB: // MOV Y, [Y]
|
||||
I16 = MinxCPU.Y.W.L;
|
||||
MinxCPU.Y.B.L = MinxCPU_OnRead(1, (MinxCPU.Y.B.I << 16) | I16++);
|
||||
MinxCPU.Y.B.H = MinxCPU_OnRead(1, (MinxCPU.Y.B.I << 16) | I16);
|
||||
return 20;
|
||||
|
||||
case 0xDC: // MOV [Y], BA
|
||||
I16 = MinxCPU.Y.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.Y.B.I << 16) | I16++, MinxCPU.BA.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.Y.B.I << 16) | I16, MinxCPU.BA.B.H);
|
||||
return 20;
|
||||
case 0xDD: // MOV [Y], HL
|
||||
I16 = MinxCPU.Y.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.Y.B.I << 16) | I16++, MinxCPU.HL.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.Y.B.I << 16) | I16, MinxCPU.HL.B.H);
|
||||
return 20;
|
||||
case 0xDE: // MOV [Y], X
|
||||
I16 = MinxCPU.Y.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.Y.B.I << 16) | I16++, MinxCPU.X.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.Y.B.I << 16) | I16, MinxCPU.X.B.H);
|
||||
return 20;
|
||||
case 0xDF: // MOV [Y], Y
|
||||
I16 = MinxCPU.Y.W.L;
|
||||
MinxCPU_OnWrite(1, (MinxCPU.Y.B.I << 16) | I16++, MinxCPU.Y.B.L);
|
||||
MinxCPU_OnWrite(1, (MinxCPU.Y.B.I << 16) | I16, MinxCPU.Y.B.H);
|
||||
return 20;
|
||||
|
||||
case 0xE0: // MOV BA, BA
|
||||
return 8;
|
||||
case 0xE1: // MOV BA, HL
|
||||
MinxCPU.BA.W.L = MinxCPU.HL.W.L;
|
||||
return 8;
|
||||
case 0xE2: // MOV BA, X
|
||||
MinxCPU.BA.W.L = MinxCPU.X.W.L;
|
||||
return 8;
|
||||
case 0xE3: // MOV BA, Y
|
||||
MinxCPU.BA.W.L = MinxCPU.Y.W.L;
|
||||
return 8;
|
||||
|
||||
case 0xE4: // MOV HL, BA
|
||||
MinxCPU.HL.W.L = MinxCPU.BA.W.L;
|
||||
return 8;
|
||||
case 0xE5: // MOV HL, HL
|
||||
return 8;
|
||||
case 0xE6: // MOV HL, X
|
||||
MinxCPU.HL.W.L = MinxCPU.X.W.L;
|
||||
return 8;
|
||||
case 0xE7: // MOV HL, Y
|
||||
MinxCPU.HL.W.L = MinxCPU.Y.W.L;
|
||||
return 8;
|
||||
|
||||
case 0xE8: // MOV X, BA
|
||||
MinxCPU.X.W.L = MinxCPU.BA.W.L;
|
||||
return 8;
|
||||
case 0xE9: // MOV X, HL
|
||||
MinxCPU.X.W.L = MinxCPU.HL.W.L;
|
||||
return 8;
|
||||
case 0xEA: // MOV X, X
|
||||
return 8;
|
||||
case 0xEB: // MOV X, Y
|
||||
MinxCPU.X.W.L = MinxCPU.Y.W.L;
|
||||
return 8;
|
||||
|
||||
case 0xEC: // MOV Y, BA
|
||||
MinxCPU.Y.W.L = MinxCPU.BA.W.L;
|
||||
return 8;
|
||||
case 0xED: // MOV Y, HL
|
||||
MinxCPU.Y.W.L = MinxCPU.HL.W.L;
|
||||
return 8;
|
||||
case 0xEE: // MOV Y, X
|
||||
MinxCPU.Y.W.L = MinxCPU.X.W.L;
|
||||
return 8;
|
||||
case 0xEF: // MOV Y, Y
|
||||
return 8;
|
||||
|
||||
case 0xF0: // MOV SP, BA
|
||||
MinxCPU.SP.W.L = MinxCPU.BA.W.L;
|
||||
return 8;
|
||||
case 0xF1: // MOV SP, HL
|
||||
MinxCPU.SP.W.L = MinxCPU.HL.W.L;
|
||||
return 8;
|
||||
case 0xF2: // MOV SP, X
|
||||
MinxCPU.SP.W.L = MinxCPU.X.W.L;
|
||||
return 8;
|
||||
case 0xF3: // MOV SP, Y
|
||||
MinxCPU.SP.W.L = MinxCPU.Y.W.L;
|
||||
return 8;
|
||||
|
||||
case 0xF4: // MOV HL, SP
|
||||
MinxCPU.HL.W.L = MinxCPU.SP.W.L;
|
||||
return 8;
|
||||
case 0xF5: // MOV HL, PC
|
||||
MinxCPU.HL.W.L = MinxCPU.PC.W.L;
|
||||
return 8;
|
||||
case 0xF6: // ??? X
|
||||
MinxCPU.X.B.H = MinxCPU.PC.B.I;
|
||||
return 12;
|
||||
case 0xF7: // ??? Y
|
||||
MinxCPU.Y.B.H = MinxCPU.PC.B.I;
|
||||
return 12;
|
||||
|
||||
case 0xF8: // MOV BA, SP
|
||||
MinxCPU.BA.W.L = MinxCPU.SP.W.L;
|
||||
return 8;
|
||||
case 0xF9: // MOV BA, PC
|
||||
MinxCPU.BA.W.L = MinxCPU.PC.W.L;
|
||||
return 8;
|
||||
|
||||
case 0xFA: // MOV X, SP
|
||||
MinxCPU.X.W.L = MinxCPU.SP.W.L;
|
||||
return 8;
|
||||
|
||||
case 0xFB: // NOTHING
|
||||
case 0xFC: // NOTHING
|
||||
return 12;
|
||||
case 0xFD: // MOV A, E
|
||||
MinxCPU.BA.B.L = MinxCPU.E;
|
||||
return 12;
|
||||
|
||||
case 0xFE: // MOV Y, SP
|
||||
MinxCPU.Y.W.L = MinxCPU.SP.W.L;
|
||||
return 8;
|
||||
|
||||
case 0xFF: // NOTHING
|
||||
return 64;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 4;
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2012 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "MinxCPU.h"
|
||||
|
||||
int MinxCPU_ExecSPCE(void)
|
||||
{
|
||||
// Read IR
|
||||
MinxCPU.IR = Fetch8();
|
||||
|
||||
return 64;
|
||||
}
|
||||
|
||||
int MinxCPU_ExecSPCF(void)
|
||||
{
|
||||
// Read IR
|
||||
MinxCPU.IR = Fetch8();
|
||||
|
||||
// Process instruction
|
||||
switch(MinxCPU.IR) {
|
||||
case 0x00: case 0x01: case 0x02: case 0x03: // Decrement BA
|
||||
MinxCPU.BA.W.L = DEC16(MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x04: case 0x05: case 0x06: case 0x07: // Decrement BA if Carry = 0
|
||||
if (!(MinxCPU.F & MINX_FLAG_CARRY)) MinxCPU.BA.W.L = DEC16(MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x08: case 0x09: case 0x0A: case 0x0B: // Increment BA
|
||||
MinxCPU.BA.W.L = INC16(MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x0C: case 0x0D: case 0x0E: case 0x0F: // Increment BA if Carry = 0
|
||||
if (!(MinxCPU.F & MINX_FLAG_CARRY)) MinxCPU.BA.W.L = INC16(MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x10: case 0x11: case 0x12: case 0x13: // Decrement BA
|
||||
MinxCPU.BA.W.L = DEC16(MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x14: case 0x15: case 0x16: case 0x17: // Decrement BA if Carry = 0
|
||||
if (!(MinxCPU.F & MINX_FLAG_CARRY)) MinxCPU.BA.W.L = DEC16(MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x18: case 0x19: case 0x1A: case 0x1B: // Increment BA (Doesn't save result!!)
|
||||
INC16(MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
case 0x1C: case 0x1D: case 0x1E: case 0x1F: // Increment BA if Carry = 0
|
||||
if (!(MinxCPU.F & MINX_FLAG_CARRY)) MinxCPU.BA.W.L = INC16(MinxCPU.BA.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x20: case 0x21: case 0x22: case 0x23: // Decrement HL
|
||||
MinxCPU.HL.W.L = DEC16(MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x24: case 0x25: case 0x26: case 0x27: // Decrement HL if Carry = 0
|
||||
if (!(MinxCPU.F & MINX_FLAG_CARRY)) MinxCPU.HL.W.L = DEC16(MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x28: case 0x29: case 0x2A: case 0x2B: // Increment HL
|
||||
MinxCPU.HL.W.L = INC16(MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x2C: case 0x2D: case 0x2E: case 0x2F: // Increment HL if Carry = 0
|
||||
if (!(MinxCPU.F & MINX_FLAG_CARRY)) MinxCPU.HL.W.L = INC16(MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x30: case 0x31: case 0x32: case 0x33: // Decrement HL
|
||||
MinxCPU.HL.W.L = DEC16(MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x34: case 0x35: case 0x36: case 0x37: // Decrement HL if Carry = 0
|
||||
if (!(MinxCPU.F & MINX_FLAG_CARRY)) MinxCPU.HL.W.L = DEC16(MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x38: case 0x39: case 0x3A: case 0x3B: // Increment HL (Doesn't save result!!)
|
||||
INC16(MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
case 0x3C: case 0x3D: case 0x3E: case 0x3F: // Increment HL if Carry = 0
|
||||
if (!(MinxCPU.F & MINX_FLAG_CARRY)) MinxCPU.HL.W.L = INC16(MinxCPU.HL.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x40: case 0x41: // Decrement X
|
||||
MinxCPU.X.W.L = DEC16(MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x42: case 0x43: // Decrement Y
|
||||
MinxCPU.X.W.L = DEC16(MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x44: case 0x45: // Decrement SP
|
||||
MinxCPU.SP.W.L = DEC16(MinxCPU.SP.W.L);
|
||||
return 16;
|
||||
case 0x46: case 0x47: // CRASH
|
||||
return 16;
|
||||
|
||||
case 0x48: case 0x49: // Increment X
|
||||
MinxCPU.X.W.L = INC16(MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x4A: case 0x4B: // Increment Y
|
||||
MinxCPU.X.W.L = INC16(MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x4C: case 0x4D: // Increment SP
|
||||
MinxCPU.SP.W.L = INC16(MinxCPU.SP.W.L);
|
||||
return 16;
|
||||
case 0x4E: case 0x4F: // CRASH
|
||||
case 0x56: case 0x57: // CRASH
|
||||
case 0x5E: case 0x5F: // CRASH
|
||||
case 0x60: case 0x61: case 0x62: case 0x63: // CRASH
|
||||
case 0x64: case 0x65: case 0x66: case 0x67:
|
||||
case 0x68: case 0x69: case 0x6A: case 0x6B:
|
||||
case 0x6C: case 0x6D: case 0x6E: case 0x6F:
|
||||
return 16;
|
||||
|
||||
case 0x50: case 0x51: // Decrement X
|
||||
MinxCPU.X.W.L = DEC16(MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x52: case 0x53: // Decrement Y
|
||||
MinxCPU.X.W.L = DEC16(MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x54: case 0x55: // Decrement SP
|
||||
MinxCPU.SP.W.L = DEC16(MinxCPU.SP.W.L);
|
||||
return 16;
|
||||
|
||||
case 0x58: case 0x59: // Increment X
|
||||
MinxCPU.X.W.L = INC16(MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x5A: case 0x5B: // Increment Y
|
||||
MinxCPU.X.W.L = INC16(MinxCPU.X.W.L);
|
||||
return 16;
|
||||
case 0x5C: case 0x5D: // Increment SP
|
||||
MinxCPU.SP.W.L = INC16(MinxCPU.SP.W.L);
|
||||
return 16;
|
||||
|
||||
|
||||
case 0x70: // BA = (0x4D << 8) | V
|
||||
MinxCPU.BA.W.L = 0x4D00 | MinxCPU.PC.B.I;
|
||||
return 24;
|
||||
case 0x71: // HL = (0x4D << 8) | V
|
||||
MinxCPU.HL.W.L = 0x4D00 | MinxCPU.PC.B.I;
|
||||
return 24;
|
||||
case 0x72: // X = (0x4D << 8) | V
|
||||
MinxCPU.X.W.L = 0x4D00 | MinxCPU.PC.B.I;
|
||||
return 24;
|
||||
case 0x73: // Y = (0x4D << 8) | V
|
||||
MinxCPU.Y.W.L = 0x4D00 | MinxCPU.PC.B.I;
|
||||
return 24;
|
||||
|
||||
case 0x74: case 0x75: case 0x76: case 0x77: // NOTHING
|
||||
return 24;
|
||||
|
||||
case 0x78: case 0x79: case 0x7A: case 0x7B: // CRASH
|
||||
case 0x7C: case 0x7D: case 0x7E: case 0x7F:
|
||||
case 0x80: case 0x81: case 0x82: case 0x83:
|
||||
case 0x84: case 0x85: case 0x86: case 0x87:
|
||||
case 0x88: case 0x89: case 0x8A: case 0x8B:
|
||||
case 0x8C: case 0x8D: case 0x8E: case 0x8F:
|
||||
case 0x90: case 0x91: case 0x92: case 0x93:
|
||||
case 0x94: case 0x95: case 0x96: case 0x97:
|
||||
case 0x98: case 0x99: case 0x9A: case 0x9B:
|
||||
case 0x9C: case 0x9D: case 0x9E: case 0x9F:
|
||||
case 0xA0: case 0xA1: case 0xA2: case 0xA3:
|
||||
case 0xA4: case 0xA5: case 0xA6: case 0xA7:
|
||||
case 0xA8: case 0xA9: case 0xAA: case 0xAB:
|
||||
case 0xAC: case 0xAD: case 0xAE: case 0xAF:
|
||||
return 24;
|
||||
|
||||
case 0xB0: case 0xB1: case 0xB2: case 0xB3: // NOTHING
|
||||
return 12;
|
||||
|
||||
case 0xB4: case 0xB5: case 0xB6: case 0xB7: // CRASH
|
||||
case 0xB8: case 0xB9: case 0xBA: case 0xBB:
|
||||
case 0xBC: case 0xBD: case 0xBE: case 0xBF:
|
||||
return 12;
|
||||
|
||||
case 0xC0: // BA = (0x20 << 8) | V
|
||||
MinxCPU.BA.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
case 0xC1: // HL = (0x20 << 8) | V
|
||||
MinxCPU.HL.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
case 0xC2: // X = (0x20 << 8) | V
|
||||
MinxCPU.X.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
case 0xC3: // Y = (0x20 << 8) | V
|
||||
MinxCPU.Y.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
|
||||
case 0xC4: case 0xC5: case 0xC6: case 0xC7: // NOTHING
|
||||
return 20;
|
||||
|
||||
case 0xC8: case 0xC9: case 0xCA: case 0xCB: // CRASH
|
||||
case 0xCC: case 0xCD: case 0xCE: case 0xCF:
|
||||
return 20;
|
||||
|
||||
case 0xD0: // BA = (0x20 << 8) | V
|
||||
MinxCPU.BA.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
case 0xD1: // HL = (0x20 << 8) | V
|
||||
MinxCPU.HL.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
case 0xD2: // X = (0x20 << 8) | V
|
||||
MinxCPU.X.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
case 0xD3: // Y = (0x00 << 8) | V ? (EH!?)
|
||||
MinxCPU.Y.W.L = 0x0000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
|
||||
case 0xD4: case 0xD5: case 0xD6: case 0xD7: // NOTHING
|
||||
return 20;
|
||||
|
||||
case 0xD8: // BA = (0x20 << 8) | V
|
||||
MinxCPU.BA.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
case 0xD9: // HL = (0x20 << 8) | V
|
||||
MinxCPU.HL.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
case 0xDA: // X = (0x20 << 8) | V
|
||||
MinxCPU.X.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
case 0xDB: // Y = (0x20 << 8) | V
|
||||
MinxCPU.Y.W.L = 0x2000 | MinxCPU.PC.B.I;
|
||||
return 20;
|
||||
|
||||
case 0xDC: case 0xDD: case 0xDE: case 0xDF: // NOTHING
|
||||
return 20;
|
||||
|
||||
case 0xE0: case 0xE1: case 0xE2: case 0xE3: // CRASH
|
||||
case 0xE4: case 0xE5: case 0xE6: case 0xE7:
|
||||
case 0xE8: case 0xE9: case 0xEA: case 0xEB:
|
||||
case 0xEC: case 0xED: case 0xEE: case 0xEF:
|
||||
case 0xF0: case 0xF1: case 0xF2: case 0xF3:
|
||||
case 0xF4: case 0xF5: case 0xF6: case 0xF7:
|
||||
case 0xF8: case 0xF9: case 0xFA: case 0xFB:
|
||||
case 0xFC: case 0xFD: case 0xFE: case 0xFF:
|
||||
return 24;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 64;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,734 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MINXCPU_CORE
|
||||
#define MINXCPU_CORE
|
||||
|
||||
#include <stdint.h>
|
||||
#include <retro_inline.h>
|
||||
|
||||
/* For some reason, '_BIG_ENDIAN' is always defined when
|
||||
* building for 3DS/Switch with devkitarm/a64... */
|
||||
#if defined (_BIG_ENDIAN) && !defined (_3DS) && !defined(HAVE_LIBNX)
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t X;
|
||||
uint8_t I;
|
||||
uint8_t H;
|
||||
uint8_t L;
|
||||
} B;
|
||||
struct {
|
||||
uint16_t H;
|
||||
uint16_t L;
|
||||
} W;
|
||||
uint32_t D;
|
||||
} MinxRegx;
|
||||
|
||||
#else
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t L;
|
||||
uint8_t H;
|
||||
uint8_t I;
|
||||
uint8_t X;
|
||||
} B;
|
||||
struct {
|
||||
uint16_t L;
|
||||
uint16_t H;
|
||||
} W;
|
||||
uint32_t D;
|
||||
} MinxRegx;
|
||||
|
||||
#endif
|
||||
|
||||
#define MINX_FLAG_ZERO 0x01
|
||||
#define MINX_FLAG_CARRY 0x02
|
||||
#define MINX_FLAG_OVERFLOW 0x04
|
||||
#define MINX_FLAG_SIGN 0x08
|
||||
#define MINX_FLAG_BCD 0x10
|
||||
#define MINX_FLAG_NIBBLE 0x20
|
||||
#define MINX_FLAG_INTFLG 0x40
|
||||
#define MINX_FLAG_INTOFF 0x80
|
||||
|
||||
#define MINX_FLAG_SIGN_S4 0
|
||||
#define MINX_FLAG_OVER_S4 1
|
||||
#define MINX_FLAG_SIGN_S8 4
|
||||
#define MINX_FLAG_OVER_S8 5
|
||||
#define MINX_FLAG_SIGN_S16 12
|
||||
#define MINX_FLAG_OVER_S16 13
|
||||
|
||||
#define MINX_FLAG_SAVE_NUL 0xF0
|
||||
#define MINX_FLAG_SAVE_O 0xF4
|
||||
#define MINX_FLAG_SAVE_CO 0xF6
|
||||
#define MINX_FLAG_SAVE_COS 0xFE
|
||||
|
||||
// Status reasons
|
||||
enum {
|
||||
MINX_STATUS_NORMAL = 0, // Normal operation
|
||||
MINX_STATUS_HALT = 1, // CPU during HALT
|
||||
MINX_STATUS_STOP = 2, // CPU during STOP
|
||||
MINX_STATUS_IRQ = 3 // Delay caused by hardware IRQ
|
||||
};
|
||||
|
||||
// Signed 8-Bits to 16-Bits converter
|
||||
static INLINE uint16_t S8_TO_16(int8_t a)
|
||||
{
|
||||
return (a & 0x80) ? (0xFF00 | a) : a;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
// Registers
|
||||
MinxRegx BA; // Registers A, B
|
||||
MinxRegx HL; // Registers L, H, I
|
||||
MinxRegx X; // Registers X, XI
|
||||
MinxRegx Y; // Registers Y, YI
|
||||
MinxRegx SP; // Register SP
|
||||
MinxRegx PC; // Registers PC, V
|
||||
MinxRegx N; // for [N+#nn], I is written here too
|
||||
uint8_t U1; // V Shadow 1
|
||||
uint8_t U2; // V Shadow 2
|
||||
uint8_t F; // Flags
|
||||
uint8_t E; // Exception
|
||||
uint8_t IR; // Last Instruction Register (for open-bus)
|
||||
uint8_t Shift_U; // Shift U, set to 2 when: U modify, branch, return
|
||||
uint8_t Status; // CPU Status (0 = Normal, 1 = Halt, 2 = Stoped, 3 = IRQ)
|
||||
uint8_t IRQ_Vector; // IRQ Vector when Status is IRQ
|
||||
uint8_t Reserved[28]; // Reserved bytes
|
||||
} TMinxCPU;
|
||||
|
||||
// CPU registers
|
||||
extern TMinxCPU MinxCPU;
|
||||
|
||||
// Callbacks (Must be coded by the user)
|
||||
uint8_t MinxCPU_OnRead(int cpu, uint32_t addr);
|
||||
void MinxCPU_OnWrite(int cpu, uint32_t addr, uint8_t data);
|
||||
void MinxCPU_OnIRQHandle(uint8_t flag, uint8_t shift_u);
|
||||
void MinxCPU_OnIRQAct(uint8_t intr);
|
||||
|
||||
// Functions
|
||||
int MinxCPU_Create(void); // Create MinxCPU
|
||||
void MinxCPU_Destroy(void); // Destroy MinxCPU
|
||||
void MinxCPU_Reset(int hardreset); // Reset CPU
|
||||
int MinxCPU_Exec(void); // Execute 1 CPU instruction
|
||||
int MinxCPU_CallIRQ(uint8_t IRQ); // Call an IRQ
|
||||
|
||||
// Helpers
|
||||
static INLINE uint16_t ReadMem16(uint32_t addr)
|
||||
{
|
||||
return MinxCPU_OnRead(1, addr) + (MinxCPU_OnRead(1, addr+1) << 8);
|
||||
}
|
||||
|
||||
static INLINE void WriteMem16(uint32_t addr, uint16_t data)
|
||||
{
|
||||
MinxCPU_OnWrite(1, addr, (uint8_t)data);
|
||||
MinxCPU_OnWrite(1, addr+1, data >> 8);
|
||||
}
|
||||
|
||||
static INLINE uint8_t Fetch8(void)
|
||||
{
|
||||
if (MinxCPU.PC.W.L & 0x8000) {
|
||||
// Banked area
|
||||
MinxCPU.IR = MinxCPU_OnRead(1, (MinxCPU.PC.W.L++ & 0x7FFF) | (MinxCPU.PC.B.I << 15));
|
||||
} else {
|
||||
// Unbanked area
|
||||
MinxCPU.IR = MinxCPU_OnRead(1, MinxCPU.PC.W.L++);
|
||||
}
|
||||
return MinxCPU.IR;
|
||||
}
|
||||
|
||||
static INLINE uint16_t Fetch16(void)
|
||||
{
|
||||
uint8_t LB = Fetch8();
|
||||
return (Fetch8() << 8) | LB;
|
||||
}
|
||||
|
||||
static INLINE void Set_U(uint8_t val)
|
||||
{
|
||||
if (val != MinxCPU.U2) MinxCPU.Shift_U = 2;
|
||||
MinxCPU.U1 = val;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU_OnIRQHandle(MinxCPU.F, MinxCPU.Shift_U);
|
||||
}
|
||||
|
||||
// Instruction exec. prototypes
|
||||
|
||||
int MinxCPU_ExecCE(void);
|
||||
int MinxCPU_ExecCF(void);
|
||||
int MinxCPU_ExecSPCE(void);
|
||||
int MinxCPU_ExecSPCF(void);
|
||||
|
||||
// Instructions Macros
|
||||
|
||||
static INLINE uint8_t ADD8(uint8_t A, uint8_t B)
|
||||
{
|
||||
register uint8_t RES;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
switch (MinxCPU.F & 0x30) {
|
||||
case 0x00: // Normal
|
||||
RES = A + B;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES < A) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B ^ 0x80) & 0x80) >> MINX_FLAG_OVER_S8) | // Overflow
|
||||
((RES & 0x80) >> MINX_FLAG_SIGN_S8); // Sign
|
||||
return RES & 0xFF;
|
||||
case 0x10: // BCD
|
||||
if ((uint8_t)((A & 15) + (B & 15)) >= 10) {
|
||||
RES = A + B + 6;
|
||||
} else {
|
||||
RES = A + B;
|
||||
}
|
||||
if (RES >= 0xA0) RES += 0x60;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES < A) ? MINX_FLAG_CARRY : 0); // Carry
|
||||
return RES & 0xFF;
|
||||
case 0x20: // Nibble
|
||||
RES = (A & 15) + (B & 15);
|
||||
MinxCPU.F |=
|
||||
(((RES & 15) == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES >= 16) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B ^ 0x08) & 0x08) >> MINX_FLAG_OVER_S4) | // Overflow
|
||||
((RES & 0x08) >> MINX_FLAG_SIGN_S4); // Sign
|
||||
return RES & 0x0F;
|
||||
default: // BCD and Nibble
|
||||
if ((uint8_t)((A & 15) + (B & 15)) >= 10) {
|
||||
RES = (A & 15) + (B & 15) + 6;
|
||||
} else {
|
||||
RES = (A & 15) + (B & 15);
|
||||
}
|
||||
MinxCPU.F |=
|
||||
(((RES & 15) == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES >= 16) ? MINX_FLAG_CARRY : 0); // Carry
|
||||
return RES & 0x0F;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE uint16_t ADD16(uint16_t A, uint16_t B)
|
||||
{
|
||||
register uint16_t RES;
|
||||
RES = A + B;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES < A) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B ^ 0x8000) & 0x8000) >> MINX_FLAG_OVER_S16) | // Overflow
|
||||
((RES & 0x8000) >> MINX_FLAG_SIGN_S16); // Sign
|
||||
return (uint16_t)RES;
|
||||
}
|
||||
|
||||
static INLINE uint8_t ADC8(uint8_t A, uint8_t B)
|
||||
{
|
||||
register uint8_t RES;
|
||||
register uint8_t CARRY = (MinxCPU.F & MINX_FLAG_CARRY) ? 1 : 0;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
switch (MinxCPU.F & 0x30) {
|
||||
case 0x00: // Normal
|
||||
RES = A + B + CARRY;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES < A) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B ^ 0x80) & 0x80) >> MINX_FLAG_OVER_S8) | // Overflow
|
||||
((RES & 0x80) >> MINX_FLAG_SIGN_S8); // Sign
|
||||
return RES & 0xFF;
|
||||
case 0x10: // BCD
|
||||
if ((uint8_t)((A & 15) + (B & 15) + CARRY) >= 10) {
|
||||
RES = A + B + CARRY + 6;
|
||||
} else {
|
||||
RES = A + B + CARRY;
|
||||
}
|
||||
if (RES >= 0xA0) RES += 0x60;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES < A) ? MINX_FLAG_CARRY : 0); // Carry
|
||||
return RES & 0xFF;
|
||||
case 0x20: // Nibble
|
||||
RES = (A & 15) + (B & 15) + CARRY;
|
||||
MinxCPU.F |=
|
||||
(((RES & 15) == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES >= 16) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B ^ 0x08) & 0x08) >> MINX_FLAG_OVER_S4) | // Overflow
|
||||
((RES & 0x08) >> MINX_FLAG_SIGN_S4); // Sign
|
||||
return RES & 0x0F;
|
||||
default: // BCD and Nibble
|
||||
if ((uint8_t)((A & 15) + (B & 15) + CARRY) >= 10) {
|
||||
RES = (A & 15) + (B & 15) + CARRY + 6;
|
||||
} else {
|
||||
RES = (A & 15) + (B & 15) + CARRY;
|
||||
}
|
||||
MinxCPU.F |=
|
||||
(((RES & 15) == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES >= 16) ? MINX_FLAG_CARRY : 0); // Carry
|
||||
return RES & 0x0F;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE uint16_t ADC16(uint16_t A, uint16_t B)
|
||||
{
|
||||
register uint16_t RES;
|
||||
RES = A + B + ((MinxCPU.F & MINX_FLAG_CARRY) ? 1 : 0);
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES < A) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B ^ 0x8000) & 0x8000) >> MINX_FLAG_OVER_S16) | // Overflow
|
||||
((RES & 0x8000) >> MINX_FLAG_SIGN_S16); // Sign
|
||||
return (uint16_t)RES;
|
||||
}
|
||||
|
||||
static INLINE uint8_t SUB8(uint8_t A, uint8_t B)
|
||||
{
|
||||
register uint8_t RES;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
switch (MinxCPU.F & 0x30) {
|
||||
case 0x00: // Normal
|
||||
RES = A - B;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((A < B) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B) & 0x80) >> MINX_FLAG_OVER_S8) | // Overflow
|
||||
((RES & 0x80) >> MINX_FLAG_SIGN_S8); // Sign
|
||||
return RES & 0xFF;
|
||||
case 0x10: // BCD
|
||||
if ((uint8_t)((A & 15) - (B & 15)) >= 10) {
|
||||
RES = A - B - 6;
|
||||
} else {
|
||||
RES = A - B;
|
||||
}
|
||||
if (RES >= 0xA0) RES -= 0x60;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((A < B) ? MINX_FLAG_CARRY : 0); // Carry
|
||||
return RES & 0xFF;
|
||||
case 0x20: // Nibble
|
||||
RES = (A & 15) - (B & 15);
|
||||
MinxCPU.F |=
|
||||
(((RES & 15) == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES >= 16) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B) & 0x08) >> MINX_FLAG_OVER_S4) | // Overflow
|
||||
((RES & 0x08) >> MINX_FLAG_SIGN_S4); // Sign
|
||||
return RES & 0x0F;
|
||||
default: // BCD and Nibble
|
||||
if ((uint8_t)((A & 15) - (B & 15)) >= 10) {
|
||||
RES = (A & 15) - (B & 15) - 6;
|
||||
} else {
|
||||
RES = (A & 15) - (B & 15);
|
||||
}
|
||||
MinxCPU.F |=
|
||||
(((RES & 15) == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES >= 16) ? MINX_FLAG_CARRY : 0); // Carry
|
||||
return RES & 0x0F;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE uint16_t SUB16(uint16_t A, uint16_t B)
|
||||
{
|
||||
register uint16_t RES;
|
||||
RES = A - B;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((A < B) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B) & 0x8000) >> MINX_FLAG_OVER_S16) | // Overflow
|
||||
((RES & 0x8000) >> MINX_FLAG_SIGN_S16); // Sign
|
||||
return (uint16_t)RES;
|
||||
}
|
||||
|
||||
static INLINE uint8_t SBC8(uint8_t A, uint8_t B)
|
||||
{
|
||||
register uint8_t RES;
|
||||
register uint8_t CARRY = (MinxCPU.F & MINX_FLAG_CARRY) ? 1 : 0;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
switch (MinxCPU.F & 0x30) {
|
||||
case 0x00: // Normal
|
||||
RES = A - B - CARRY;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((A < B) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B) & 0x80) >> MINX_FLAG_OVER_S8) | // Overflow
|
||||
((RES & 0x80) >> MINX_FLAG_SIGN_S8); // Sign
|
||||
return RES & 0xFF;
|
||||
case 0x10: // BCD
|
||||
if ((uint8_t)((A & 15) - (B & 15) - CARRY) >= 10) {
|
||||
RES = A - B - CARRY - 6;
|
||||
} else {
|
||||
RES = A - B - CARRY;
|
||||
}
|
||||
if (RES >= 0xA0) RES -= 0x60;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((A < B) ? MINX_FLAG_CARRY : 0); // Carry
|
||||
return RES & 0xFF;
|
||||
case 0x20: // Nibble
|
||||
RES = (A & 15) - (B & 15) - CARRY;
|
||||
MinxCPU.F |=
|
||||
(((RES & 15) == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES >= 16) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B) & 0x08) >> MINX_FLAG_OVER_S4) | // Overflow
|
||||
((RES & 0x08) >> MINX_FLAG_SIGN_S4); // Sign
|
||||
return RES & 0x0F;
|
||||
default: // BCD and Nibble
|
||||
if ((uint8_t)((A & 15) - (B & 15) - CARRY) >= 10) {
|
||||
RES = (A & 15) - (B & 15) - CARRY - 6;
|
||||
} else {
|
||||
RES = (A & 15) - (B & 15) - CARRY;
|
||||
}
|
||||
MinxCPU.F |=
|
||||
(((RES & 15) == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((RES >= 16) ? MINX_FLAG_CARRY : 0); // Carry
|
||||
return RES & 0x0F;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE uint16_t SBC16(uint16_t A, uint16_t B)
|
||||
{
|
||||
register uint16_t RES;
|
||||
RES = A - B - ((MinxCPU.F & MINX_FLAG_CARRY) ? 1 : 0);
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
MinxCPU.F |=
|
||||
((RES == 0) ? MINX_FLAG_ZERO : 0) | // Zero
|
||||
((A < B) ? MINX_FLAG_CARRY : 0) | // Carry
|
||||
(((A ^ RES) & (A ^ B) & 0x8000) >> MINX_FLAG_OVER_S16) | // Overflow
|
||||
((RES & 0x8000) >> MINX_FLAG_SIGN_S16); // Sign
|
||||
return (uint16_t)RES;
|
||||
}
|
||||
|
||||
static INLINE uint8_t AND8(uint8_t A, uint8_t B)
|
||||
{
|
||||
A &= B;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_CO;
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t OR8(uint8_t A, uint8_t B)
|
||||
{
|
||||
A |= B;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_CO;
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t XOR8(uint8_t A, uint8_t B)
|
||||
{
|
||||
A ^= B;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_CO;
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t INC8(uint8_t A)
|
||||
{
|
||||
A++;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_COS;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint16_t INC16(uint16_t A)
|
||||
{
|
||||
A++;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_COS;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t DEC8(uint8_t A)
|
||||
{
|
||||
A--;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_COS;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint16_t DEC16(uint16_t A)
|
||||
{
|
||||
A--;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_COS;
|
||||
if (A == 0) MinxCPU.F |= MINX_FLAG_ZERO;
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE void PUSH(uint8_t A)
|
||||
{
|
||||
MinxCPU.SP.W.L--;
|
||||
MinxCPU_OnWrite(1, MinxCPU.SP.D, A);
|
||||
}
|
||||
|
||||
static INLINE uint8_t POP(void)
|
||||
{
|
||||
register uint8_t data;
|
||||
data = MinxCPU_OnRead(1, MinxCPU.SP.D);
|
||||
MinxCPU.SP.W.L++;
|
||||
return data;
|
||||
}
|
||||
|
||||
static INLINE void CALLS(uint16_t OFFSET)
|
||||
{
|
||||
PUSH(MinxCPU.PC.B.I);
|
||||
PUSH(MinxCPU.PC.B.H);
|
||||
PUSH(MinxCPU.PC.B.L);
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = MinxCPU.PC.W.L + OFFSET - 1;
|
||||
}
|
||||
|
||||
static INLINE void JMPS(uint16_t OFFSET)
|
||||
{
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = MinxCPU.PC.W.L + OFFSET - 1;
|
||||
}
|
||||
|
||||
static INLINE void CALLU(uint16_t ADDR)
|
||||
{
|
||||
PUSH(MinxCPU.PC.B.I);
|
||||
PUSH(MinxCPU.PC.B.H);
|
||||
PUSH(MinxCPU.PC.B.L);
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = ADDR;
|
||||
}
|
||||
|
||||
static INLINE void JMPU(uint16_t ADDR)
|
||||
{
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = ADDR;
|
||||
}
|
||||
|
||||
static INLINE void JDBNZ(uint16_t OFFSET)
|
||||
{
|
||||
MinxCPU.BA.B.H = DEC8(MinxCPU.BA.B.H);
|
||||
if (MinxCPU.BA.B.H != 0) {
|
||||
JMPS(OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE uint8_t SWAP(uint8_t A)
|
||||
{
|
||||
return (A << 4) | (A >> 4);
|
||||
}
|
||||
|
||||
static INLINE void RET(void)
|
||||
{
|
||||
MinxCPU.PC.B.L = POP();
|
||||
MinxCPU.PC.B.H = POP();
|
||||
MinxCPU.PC.B.I = POP();
|
||||
Set_U(MinxCPU.PC.B.I);
|
||||
}
|
||||
|
||||
static INLINE void RETI(void)
|
||||
{
|
||||
MinxCPU.F = POP();
|
||||
MinxCPU.PC.B.L = POP();
|
||||
MinxCPU.PC.B.H = POP();
|
||||
MinxCPU.PC.B.I = POP();
|
||||
Set_U(MinxCPU.PC.B.I);
|
||||
MinxCPU_OnIRQHandle(MinxCPU.F, MinxCPU.Shift_U);
|
||||
}
|
||||
|
||||
static INLINE void CALLX(uint16_t ADDR)
|
||||
{
|
||||
PUSH(MinxCPU.PC.B.I);
|
||||
PUSH(MinxCPU.PC.B.H);
|
||||
PUSH(MinxCPU.PC.B.L);
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = ReadMem16((MinxCPU.HL.B.I << 16) + ADDR);
|
||||
}
|
||||
|
||||
static INLINE void CALLI(uint16_t ADDR)
|
||||
{
|
||||
PUSH(MinxCPU.PC.B.I);
|
||||
PUSH(MinxCPU.PC.B.H);
|
||||
PUSH(MinxCPU.PC.B.L);
|
||||
PUSH(MinxCPU.F);
|
||||
MinxCPU.F |= 0xC0;
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = ReadMem16(ADDR);
|
||||
MinxCPU_OnIRQHandle(MinxCPU.F, MinxCPU.Shift_U);
|
||||
}
|
||||
|
||||
static INLINE void JMPI(uint16_t ADDR)
|
||||
{
|
||||
PUSH(MinxCPU.F);
|
||||
MinxCPU.F |= 0xC0;
|
||||
MinxCPU.PC.B.I = MinxCPU.U1;
|
||||
MinxCPU.U2 = MinxCPU.U1;
|
||||
MinxCPU.PC.W.L = ReadMem16(ADDR);
|
||||
MinxCPU_OnIRQHandle(MinxCPU.F, MinxCPU.Shift_U);
|
||||
}
|
||||
|
||||
static INLINE uint8_t SAL(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
if ((!(A & 0x40)) != (!(A & 0x80))) MinxCPU.F |= MINX_FLAG_OVERFLOW;
|
||||
A = A << 1;
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t SHL(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = A << 1;
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t SAR(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
if (A & 0x01) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = (A & 0x80) | (A >> 1);
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t SHR(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x01) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = A >> 1;
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t ROLC(uint8_t A)
|
||||
{
|
||||
register uint8_t CARRY = (MinxCPU.F & MINX_FLAG_CARRY) ? 1 : 0;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = (A << 1) | CARRY;
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t ROL(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x80) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = (A << 1) | (A >> 7);
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t RORC(uint8_t A)
|
||||
{
|
||||
register uint8_t CARRY = (MinxCPU.F & MINX_FLAG_CARRY) ? 0x80 : 0x00;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x01) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = (A >> 1) | CARRY;
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t ROR(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_O;
|
||||
if (A & 0x01) MinxCPU.F |= MINX_FLAG_CARRY;
|
||||
A = (A >> 1) | (A << 7);
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t NOT(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_CO;
|
||||
A = A ^ 0xFF;
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE uint8_t NEG(uint8_t A)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
A = -A;
|
||||
MinxCPU.F |=
|
||||
((A == 0) ? MINX_FLAG_ZERO : MINX_FLAG_CARRY) |
|
||||
((A == 0x80) ? MINX_FLAG_OVERFLOW : 0) |
|
||||
((A & 0x80) >> MINX_FLAG_SIGN_S8);
|
||||
return A;
|
||||
}
|
||||
|
||||
static INLINE void HALT(void)
|
||||
{
|
||||
MinxCPU.Status = MINX_STATUS_HALT;
|
||||
}
|
||||
|
||||
static INLINE void STOP(void)
|
||||
{
|
||||
MinxCPU.Status = MINX_STATUS_STOP;
|
||||
}
|
||||
|
||||
static INLINE void MUL(void)
|
||||
{
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
MinxCPU.HL.W.L = (uint16_t)MinxCPU.HL.B.L * (uint16_t)MinxCPU.BA.B.L;
|
||||
MinxCPU.F |=
|
||||
((MinxCPU.HL.W.L == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((MinxCPU.HL.W.L & 0x8000) ? MINX_FLAG_SIGN : 0);
|
||||
}
|
||||
|
||||
static INLINE void DIV(void)
|
||||
{
|
||||
uint16_t RES;
|
||||
MinxCPU.F &= MINX_FLAG_SAVE_NUL;
|
||||
if (MinxCPU.BA.B.L == 0)
|
||||
return;
|
||||
RES = MinxCPU.HL.W.L / MinxCPU.BA.B.L;
|
||||
if (RES < 256) {
|
||||
MinxCPU.HL.B.H = MinxCPU.HL.W.L % MinxCPU.BA.B.L;
|
||||
MinxCPU.HL.B.L = (uint8_t)RES;
|
||||
MinxCPU.F |=
|
||||
((MinxCPU.HL.B.L == 0) ? MINX_FLAG_ZERO : 0) |
|
||||
((MinxCPU.HL.B.L & 0x80) ? MINX_FLAG_SIGN : 0);
|
||||
} else MinxCPU.F |= MINX_FLAG_OVERFLOW | MINX_FLAG_SIGN;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2012 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MINXHW_COLORPRC
|
||||
#define MINXHW_COLORPRC
|
||||
|
||||
#include <stdint.h>
|
||||
#include <streams/memory_stream.h>
|
||||
|
||||
typedef struct {
|
||||
uint16_t UnlockCode;
|
||||
uint8_t Unlocked;
|
||||
uint8_t Access;
|
||||
uint8_t Modes;
|
||||
uint8_t ActivePage;
|
||||
uint16_t Address;
|
||||
uint8_t LNColor0;
|
||||
uint8_t HNColor0;
|
||||
uint8_t LNColor1;
|
||||
uint8_t HNColor1;
|
||||
} TMinxColorPRC;
|
||||
|
||||
// Export PRC state
|
||||
extern TMinxColorPRC MinxColorPRC;
|
||||
|
||||
// For Unofficial Color Pokemon-Mini
|
||||
extern int PRCColorEnable;
|
||||
extern uint8_t *PRCColorPixels;
|
||||
extern uint8_t *PRCColorPixelsOld;
|
||||
extern uint8_t *PRCColorMap;
|
||||
extern unsigned int PRCColorOffset;
|
||||
extern uint8_t *PRCColorTop;
|
||||
extern uint8_t PRCColorFlags;
|
||||
extern const uint8_t PRCStaticColorMap[8];
|
||||
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
|
||||
int MinxColorPRC_Create(void);
|
||||
|
||||
void MinxColorPRC_Destroy(void);
|
||||
|
||||
void MinxColorPRC_Reset(int hardreset);
|
||||
|
||||
int MinxColorPRC_LoadStateStream(memstream_t *stream, uint32_t bsize);
|
||||
|
||||
int MinxColorPRC_SaveStateStream(memstream_t *stream);
|
||||
|
||||
uint8_t MinxColorPRC_ReadReg(int cpu, uint8_t reg);
|
||||
|
||||
void MinxColorPRC_WriteReg(uint8_t reg, uint8_t val);
|
||||
|
||||
void MinxColorPRC_WriteFramebuffer(uint16_t addr, uint8_t data);
|
||||
|
||||
void MinxColorPRC_WriteLCD(uint16_t addr, uint8_t data);
|
||||
|
||||
//
|
||||
// Internals
|
||||
//
|
||||
|
||||
void MinxColorPRC_WriteCtrl(uint8_t val);
|
||||
|
||||
void MinxPRC_Render_Color8(void);
|
||||
|
||||
void MinxPRC_Render_Color4(void);
|
||||
|
||||
void MinxPRC_NoRender_Color(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,401 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2012 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PokeMini.h"
|
||||
|
||||
TMinxIO MinxIO;
|
||||
uint8_t *EEPROM = NULL;
|
||||
int PokeMini_Rumbling = 0;
|
||||
int PokeMini_RumblingLatch = 0;
|
||||
int PokeMini_EEPROMWritten = 0;
|
||||
int PokeMini_BatteryStatus = 0; // 0 = Full, 1 = Low
|
||||
int PokeMini_ShockKey = 0;
|
||||
|
||||
uint8_t MinxIO_IODataRead(void);
|
||||
void MinxIO_IODataWrite(void);
|
||||
void MinxIO_EEPROM_WEvent(uint8_t bits);
|
||||
int MinxIO_EEPROM_REvent(void);
|
||||
void MinxIO_EEPROM_Write(uint8_t data);
|
||||
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
|
||||
int MinxIO_Create(void)
|
||||
{
|
||||
// Create EEPROM memory & format it
|
||||
EEPROM = (uint8_t *)malloc(8192);
|
||||
if (!EEPROM) return 0;
|
||||
MinxIO_FormatEEPROM();
|
||||
|
||||
// Reset
|
||||
MinxIO_Reset(1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MinxIO_Destroy(void)
|
||||
{
|
||||
if (EEPROM) {
|
||||
free(EEPROM);
|
||||
EEPROM = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxIO_Reset(int hardreset)
|
||||
{
|
||||
// Initialize State
|
||||
memset(&MinxIO, 0, sizeof(TMinxIO));
|
||||
PokeMini_Rumbling = 0;
|
||||
PokeMini_RumblingLatch = 0;
|
||||
PokeMini_ShockKey = 0;
|
||||
|
||||
// Init variables
|
||||
PMR_KEY_PAD = 0xFF;
|
||||
MinxIO.ListenState = MINX_EEPROM_IDLE;
|
||||
MinxIO.OperState = MINX_EEPROM_DEVICE;
|
||||
|
||||
// Restore battery status
|
||||
MinxIO_BatteryLow(PokeMini_BatteryStatus);
|
||||
}
|
||||
|
||||
int MinxIO_LoadStateStream(memstream_t *stream, uint32_t bsize)
|
||||
{
|
||||
POKELOADSS_START(32+8192);
|
||||
PokeMini_Rumbling = 0;
|
||||
PokeMini_RumblingLatch = 0;
|
||||
PokeMini_EEPROMWritten = 1;
|
||||
POKELOADSS_STREAM_8(MinxIO.EEPLastPins);
|
||||
POKELOADSS_STREAM_8(MinxIO.ListenState);
|
||||
POKELOADSS_STREAM_8(MinxIO.OperState);
|
||||
POKELOADSS_STREAM_8(MinxIO.EEPData);
|
||||
POKELOADSS_STREAM_32(MinxIO.EEPBit);
|
||||
POKELOADSS_STREAM_16(MinxIO.EEPAddress);
|
||||
POKELOADSS_STREAM_X(22);
|
||||
POKELOADSS_STREAM_A(EEPROM, 8192);
|
||||
POKELOADSS_END(32+8192);
|
||||
}
|
||||
|
||||
int MinxIO_SaveStateStream(memstream_t *stream)
|
||||
{
|
||||
POKESAVESS_STREAM_START(32+8192);
|
||||
POKESAVESS_STREAM_8(MinxIO.EEPLastPins);
|
||||
POKESAVESS_STREAM_8(MinxIO.ListenState);
|
||||
POKESAVESS_STREAM_8(MinxIO.OperState);
|
||||
POKESAVESS_STREAM_8(MinxIO.EEPData);
|
||||
POKESAVESS_STREAM_32(MinxIO.EEPBit);
|
||||
POKESAVESS_STREAM_16(MinxIO.EEPAddress);
|
||||
POKESAVESS_STREAM_X(22);
|
||||
POKESAVESS_STREAM_A(EEPROM, 8192);
|
||||
POKESAVESS_END(32+8192);
|
||||
}
|
||||
|
||||
int MinxIO_FormatEEPROM(void)
|
||||
{
|
||||
if (!EEPROM) return 0;
|
||||
memset(EEPROM, 0xFF, 8192);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MinxIO_Keypad(uint8_t key, int pressed)
|
||||
{
|
||||
if (!EEPROM) return;
|
||||
switch (key) {
|
||||
case MINX_KEY_A: // Key A
|
||||
if (pressed) {
|
||||
if (!(PMR_KEY_PAD & 0x01)) return;
|
||||
MinxCPU_OnIRQAct(MINX_INTR_1C);
|
||||
PMR_KEY_PAD &= ~0x01;
|
||||
} else PMR_KEY_PAD |= 0x01;
|
||||
break;
|
||||
case MINX_KEY_B: // Key B
|
||||
if (pressed) {
|
||||
if (!(PMR_KEY_PAD & 0x02)) return;
|
||||
MinxCPU_OnIRQAct(MINX_INTR_1B);
|
||||
PMR_KEY_PAD &= ~0x02;
|
||||
} else PMR_KEY_PAD |= 0x02;
|
||||
break;
|
||||
case MINX_KEY_C: // Key C
|
||||
if (pressed) {
|
||||
if (!(PMR_KEY_PAD & 0x04)) return;
|
||||
MinxCPU_OnIRQAct(MINX_INTR_1A);
|
||||
PMR_KEY_PAD &= ~0x04;
|
||||
} else PMR_KEY_PAD |= 0x04;
|
||||
break;
|
||||
case MINX_KEY_UP: // Dpad Up
|
||||
if (pressed) {
|
||||
if (!(PMR_KEY_PAD & 0x08)) return;
|
||||
MinxCPU_OnIRQAct(MINX_INTR_19);
|
||||
PMR_KEY_PAD &= ~0x08;
|
||||
} else PMR_KEY_PAD |= 0x08;
|
||||
break;
|
||||
case MINX_KEY_DOWN: // Dpad Down
|
||||
if (pressed) {
|
||||
if (!(PMR_KEY_PAD & 0x10)) return;
|
||||
MinxCPU_OnIRQAct(MINX_INTR_18);
|
||||
PMR_KEY_PAD &= ~0x10;
|
||||
} else PMR_KEY_PAD |= 0x10;
|
||||
break;
|
||||
case MINX_KEY_LEFT: // Dpad Left
|
||||
if (pressed) {
|
||||
if (!(PMR_KEY_PAD & 0x20)) return;
|
||||
MinxCPU_OnIRQAct(MINX_INTR_17);
|
||||
PMR_KEY_PAD &= ~0x20;
|
||||
} else PMR_KEY_PAD |= 0x20;
|
||||
break;
|
||||
case MINX_KEY_RIGHT: // Dpad Right
|
||||
if (pressed) {
|
||||
if (!(PMR_KEY_PAD & 0x40)) return;
|
||||
MinxCPU_OnIRQAct(MINX_INTR_16);
|
||||
PMR_KEY_PAD &= ~0x40;
|
||||
} else PMR_KEY_PAD |= 0x40;
|
||||
break;
|
||||
case MINX_KEY_POWER: // Power key
|
||||
if (pressed) {
|
||||
if (!(PMR_KEY_PAD & 0x80)) return;
|
||||
MinxCPU_OnIRQAct(MINX_INTR_15);
|
||||
PMR_KEY_PAD &= ~0x80;
|
||||
} else PMR_KEY_PAD |= 0x80;
|
||||
break;
|
||||
case MINX_KEY_SHOCK: // Shock key
|
||||
if (!PokeMini_ShockKey && pressed) {
|
||||
MinxCPU_OnIRQAct(MINX_INTR_10);
|
||||
}
|
||||
PokeMini_ShockKey = pressed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxIO_BatteryLow(int low)
|
||||
{
|
||||
PokeMini_BatteryStatus = low;
|
||||
if (low) PMR_SYS_BATT |= 0x20;
|
||||
else PMR_SYS_BATT &= 0x1F;
|
||||
}
|
||||
|
||||
void MinxIO_SetTimeStamp(uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec)
|
||||
{
|
||||
uint8_t checksum;
|
||||
if (!EEPROM) return;
|
||||
checksum = year + month + day + hour + min + sec;
|
||||
PMR_SYS_CTRL3 |= 0x02;
|
||||
EEPROM[0x1FF6] = 0x00;
|
||||
EEPROM[0x1FF7] = 0x00;
|
||||
EEPROM[0x1FF8] = 0x00;
|
||||
EEPROM[0x1FF9] = year;
|
||||
EEPROM[0x1FFA] = month;
|
||||
EEPROM[0x1FFB] = day;
|
||||
EEPROM[0x1FFC] = hour;
|
||||
EEPROM[0x1FFD] = min;
|
||||
EEPROM[0x1FFE] = sec;
|
||||
EEPROM[0x1FFF] = checksum;
|
||||
}
|
||||
|
||||
uint8_t MinxIO_ReadReg(int cpu, uint8_t reg)
|
||||
{
|
||||
// 0x10, 0x52, 0x60 to 0x62
|
||||
switch(reg) {
|
||||
case 0x10: // Low Battery
|
||||
return PMR_SYS_BATT;
|
||||
case 0x44: // Unknown
|
||||
return PMR_REG_44;
|
||||
case 0x45: // Unknown
|
||||
return PMR_REG_45;
|
||||
case 0x46: // Unknown
|
||||
return PMR_REG_46;
|
||||
case 0x47: // Unknown
|
||||
return PMR_REG_47;
|
||||
case 0x50: // Unknown (related to power management?)
|
||||
return PMR_REG_50;
|
||||
case 0x51: // Unknown (related to power management?)
|
||||
return PMR_REG_51;
|
||||
case 0x52: // Keypad
|
||||
return PMR_KEY_PAD;
|
||||
case 0x53: // Unknown
|
||||
return PMR_REG_53;
|
||||
case 0x54: // Unknown
|
||||
return PMR_REG_54;
|
||||
case 0x55: // Unknown
|
||||
return PMR_REG_55;
|
||||
case 0x60: // I/O Direction Select ( 0 = Input, 1 = Output )
|
||||
return PMR_IO_DIR;
|
||||
case 0x61: // I/O Data Register
|
||||
return MinxIO_IODataRead();
|
||||
case 0x62: // Unknown
|
||||
return PMR_REG_62;
|
||||
default: // Unused
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MinxIO_WriteReg(int cpu, uint8_t reg, uint8_t val)
|
||||
{
|
||||
// 0x10, 0x52, 0x60 to 0x62
|
||||
switch(reg) {
|
||||
case 0x10: // Low Battery
|
||||
PMR_SYS_BATT = (PMR_SYS_BATT & 0x20) | (val & 0x1F);
|
||||
break;
|
||||
case 0x44: // Unknown
|
||||
PMR_REG_44 = val & 0xF7;
|
||||
break;
|
||||
case 0x45: // Unknown
|
||||
PMR_REG_45 = val & 0x0F;
|
||||
break;
|
||||
case 0x46: // Unknown
|
||||
PMR_REG_46 = val;
|
||||
break;
|
||||
case 0x47: // Unknown
|
||||
PMR_REG_47 = val & 0x0F;
|
||||
break;
|
||||
case 0x50: // Unknown (related to power management?)
|
||||
PMR_REG_50 = val;
|
||||
break;
|
||||
case 0x51: // Unknown (related to power management?)
|
||||
PMR_REG_51 = val & 0x03;
|
||||
break;
|
||||
case 0x52: // Keypad
|
||||
break;
|
||||
case 0x53: // Unknown
|
||||
PMR_REG_53 = 0x00;
|
||||
/* TODO/FIXME - is fallthrough intentional ?*/
|
||||
case 0x54: // Unknown
|
||||
PMR_REG_54 = val & 0x77;
|
||||
/* TODO/FIXME - is fallthrough intentional ?*/
|
||||
case 0x55: // Unknown
|
||||
PMR_REG_55 = val & 0x07;
|
||||
/* TODO/FIXME - is fallthrough intentional ?*/
|
||||
case 0x60: // I/O Direction Select ( 0 = Input, 1 = Output )
|
||||
PMR_IO_DIR = val;
|
||||
MinxIO_IODataWrite();
|
||||
break;
|
||||
case 0x61: // I/O Data Register
|
||||
PMR_IO_DATA = val;
|
||||
MinxIO_IODataWrite();
|
||||
break;
|
||||
case 0x62: // Unknown
|
||||
PMR_REG_62 = val & 0xF0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Internal
|
||||
//
|
||||
|
||||
uint8_t MinxIO_IODataRead(void)
|
||||
{
|
||||
/* Update all I/Os */
|
||||
uint8_t Input = MinxIO_EEPROM_REvent() ? MINX_EEPROM_DAT : 0;
|
||||
|
||||
return (PMR_IO_DATA & PMR_IO_DIR) | (Input & ~PMR_IO_DIR);
|
||||
}
|
||||
|
||||
void MinxIO_IODataWrite(void)
|
||||
{
|
||||
uint8_t Output = (MINX_IO_PULL_UPS & ~PMR_IO_DIR) | (PMR_IO_DATA & PMR_IO_DIR);
|
||||
|
||||
// Update all I/Os
|
||||
PokeMini_Rumbling = Output & 0x10;
|
||||
if (PokeMini_Rumbling) PokeMini_RumblingLatch = 1;
|
||||
MinxIO_EEPROM_WEvent(Output);
|
||||
}
|
||||
|
||||
void MinxIO_EEPROM_WEvent(uint8_t bits)
|
||||
{
|
||||
uint8_t rise = bits & ~MinxIO.EEPLastPins;
|
||||
uint8_t fall = ~bits & MinxIO.EEPLastPins;
|
||||
MinxIO.EEPLastPins = bits;
|
||||
|
||||
// "Start" Command
|
||||
if ((fall & MINX_EEPROM_DAT) && (bits & MINX_EEPROM_CLK)) {
|
||||
MinxIO.ListenState = MINX_EEPROM_LISTEN;
|
||||
MinxIO.OperState = MINX_EEPROM_DEVICE;
|
||||
MinxIO.EEPBit = 8;
|
||||
MinxIO.EEPData = 0x00;
|
||||
return;
|
||||
}
|
||||
|
||||
// "Stop" Command
|
||||
if ((rise & MINX_EEPROM_DAT) && (bits & MINX_EEPROM_CLK)) {
|
||||
MinxIO.ListenState = MINX_EEPROM_IDLE;
|
||||
return;
|
||||
}
|
||||
|
||||
// If it's Idle, there's nothing to do...
|
||||
if (MinxIO.ListenState == MINX_EEPROM_IDLE) return;
|
||||
|
||||
// Process each bit on clock rise
|
||||
if (rise & MINX_EEPROM_CLK) {
|
||||
int dat = (bits & MINX_EEPROM_DAT) ? 1 : 0;
|
||||
if (MinxIO.EEPBit < 0) {
|
||||
MinxIO_EEPROM_Write(MinxIO.EEPData);
|
||||
MinxIO.EEPBit = 8;
|
||||
MinxIO.EEPData = 0x00;
|
||||
} else MinxIO.EEPData = (MinxIO.EEPData << 1) | dat;
|
||||
} else if (fall & MINX_EEPROM_CLK) {
|
||||
MinxIO.EEPBit = MinxIO.EEPBit - 1;
|
||||
}
|
||||
}
|
||||
|
||||
int MinxIO_EEPROM_REvent(void)
|
||||
{
|
||||
int valid = (MinxIO.EEPBit >= 0) && (MinxIO.EEPBit < 8);
|
||||
|
||||
// If it's Idle, return high...
|
||||
if (MinxIO.ListenState == MINX_EEPROM_IDLE)
|
||||
return 1;
|
||||
|
||||
// Process read
|
||||
if (MinxIO.OperState == MINX_EEPROM_RBYTE)
|
||||
{
|
||||
if (valid)
|
||||
return (EEPROM[MinxIO.EEPAddress & 0x1FFF] >> MinxIO.EEPBit) & 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
void MinxIO_EEPROM_Write(uint8_t data)
|
||||
{
|
||||
switch (MinxIO.OperState) {
|
||||
case MINX_EEPROM_DEVICE:
|
||||
// EEPROM Device
|
||||
if ((data & 0xF0) == 0xA0)
|
||||
MinxIO.OperState = data & 0x01 ? MINX_EEPROM_RBYTE : MINX_EEPROM_ADDRHI;
|
||||
break;
|
||||
case MINX_EEPROM_ADDRHI:
|
||||
MinxIO.EEPAddress = (MinxIO.EEPAddress & 0x00FF) | (data << 8);
|
||||
MinxIO.OperState = MINX_EEPROM_ADDRLO;
|
||||
break;
|
||||
case MINX_EEPROM_ADDRLO:
|
||||
MinxIO.EEPAddress = (MinxIO.EEPAddress & 0xFF00) | data;
|
||||
MinxIO.OperState = MINX_EEPROM_WBYTE;
|
||||
break;
|
||||
case MINX_EEPROM_WBYTE:
|
||||
PokeMini_EEPROMWritten = 1;
|
||||
EEPROM[MinxIO.EEPAddress & 0x1FFF] = data;
|
||||
MinxIO.EEPAddress++;
|
||||
break;
|
||||
case MINX_EEPROM_RBYTE:
|
||||
MinxIO.EEPAddress++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2012 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MINXHW_IO
|
||||
#define MINXHW_IO
|
||||
|
||||
#include <stdint.h>
|
||||
#include <streams/memory_stream.h>
|
||||
|
||||
typedef struct {
|
||||
// Internal processing
|
||||
uint8_t EEPLastPins;
|
||||
uint8_t ListenState;
|
||||
uint8_t OperState;
|
||||
uint8_t EEPData;
|
||||
int32_t EEPBit;
|
||||
uint16_t EEPAddress;
|
||||
} TMinxIO;
|
||||
|
||||
// Export IO state
|
||||
extern TMinxIO MinxIO;
|
||||
|
||||
// EEPROM Data
|
||||
extern uint8_t *EEPROM;
|
||||
|
||||
// Rumbling & EEPROM written state
|
||||
extern int PokeMini_Rumbling;
|
||||
extern int PokeMini_RumblingLatch;
|
||||
extern int PokeMini_EEPROMWritten;
|
||||
extern int PokeMini_BatteryStatus; // 0 = Full, 1 = Low
|
||||
|
||||
enum {
|
||||
// EEPROM Listen State
|
||||
MINX_EEPROM_IDLE = 0, // Idle
|
||||
MINX_EEPROM_LISTEN = 1, // Listening
|
||||
|
||||
// EEPROM Data State
|
||||
MINX_EEPROM_DEVICE = 0, // Device ID
|
||||
MINX_EEPROM_ADDRHI = 1, // High Address Byte
|
||||
MINX_EEPROM_ADDRLO = 2, // Low Address Byte
|
||||
MINX_EEPROM_WBYTE = 3, // Write Byte
|
||||
MINX_EEPROM_RBYTE = 4, // Read Byte
|
||||
|
||||
// Keypad
|
||||
MINX_KEY_NONE = 0,
|
||||
MINX_KEY_A = 1,
|
||||
MINX_KEY_B = 2,
|
||||
MINX_KEY_C = 3,
|
||||
MINX_KEY_UP = 4,
|
||||
MINX_KEY_DOWN = 5,
|
||||
MINX_KEY_LEFT = 6,
|
||||
MINX_KEY_RIGHT = 7,
|
||||
MINX_KEY_POWER = 8,
|
||||
MINX_KEY_SHOCK = 9 // Not real key, reserved for handling key event
|
||||
};
|
||||
|
||||
// Interrupt table
|
||||
enum {
|
||||
MINX_INTR_0F = 0x0F, // IR Receiver
|
||||
MINX_INTR_10 = 0x10, // Shock Sensor
|
||||
MINX_INTR_15 = 0x15, // A key
|
||||
MINX_INTR_16 = 0x16, // B key
|
||||
MINX_INTR_17 = 0x17, // C key
|
||||
MINX_INTR_18 = 0x18, // Up key
|
||||
MINX_INTR_19 = 0x19, // Down key
|
||||
MINX_INTR_1A = 0x1A, // Left key
|
||||
MINX_INTR_1B = 0x1B, // Right key
|
||||
MINX_INTR_1C = 0x1C // Power key
|
||||
};
|
||||
|
||||
#define MINX_IO_PULL_UPS 0x40 // Pull-up when direction create a Z
|
||||
|
||||
#define MINX_EEPROM_DAT 0x04
|
||||
#define MINX_EEPROM_CLK 0x08
|
||||
|
||||
|
||||
int MinxIO_Create(void);
|
||||
|
||||
void MinxIO_Destroy(void);
|
||||
|
||||
void MinxIO_Reset(int hardreset);
|
||||
|
||||
int MinxIO_LoadStateStream(memstream_t *stream, uint32_t bsize);
|
||||
|
||||
int MinxIO_SaveStateStream(memstream_t *stream);
|
||||
|
||||
int MinxIO_FormatEEPROM(void);
|
||||
|
||||
void MinxIO_Keypad(uint8_t key, int pressed);
|
||||
|
||||
void MinxIO_BatteryLow(int low);
|
||||
|
||||
void MinxIO_SetTimeStamp(uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec);
|
||||
|
||||
uint8_t MinxIO_ReadReg(int cpu, uint8_t reg);
|
||||
|
||||
void MinxIO_WriteReg(int cpu, uint8_t reg, uint8_t val);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2012 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PokeMini.h"
|
||||
|
||||
int MinxIRQ_MasterIRQ = 0;
|
||||
|
||||
void MinxIRQ_Process(void);
|
||||
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
|
||||
int MinxIRQ_Create(void)
|
||||
{
|
||||
// Reset
|
||||
MinxIRQ_Reset(1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MinxIRQ_Destroy(void)
|
||||
{
|
||||
}
|
||||
|
||||
void MinxIRQ_Reset(int hardreset)
|
||||
{
|
||||
// Master IRQ enable
|
||||
MinxIRQ_MasterIRQ = 1;
|
||||
PMR_IRQ_ACT1 = 0x00;
|
||||
PMR_IRQ_ACT2 = 0x00;
|
||||
PMR_IRQ_ACT3 = 0x00;
|
||||
PMR_IRQ_ACT4 = 0x00;
|
||||
}
|
||||
|
||||
int MinxIRQ_LoadStateStream(memstream_t *stream, uint32_t bsize)
|
||||
{
|
||||
POKELOADSS_START(1);
|
||||
POKELOADSS_STREAM_8(MinxIRQ_MasterIRQ);
|
||||
POKELOADSS_END(1);
|
||||
}
|
||||
|
||||
int MinxIRQ_SaveStateStream(memstream_t *stream)
|
||||
{
|
||||
POKESAVESS_STREAM_START(1);
|
||||
POKESAVESS_STREAM_8(MinxIRQ_MasterIRQ);
|
||||
POKESAVESS_END(1);
|
||||
}
|
||||
|
||||
void MinxIRQ_SetIRQ(uint8_t intr)
|
||||
{
|
||||
switch(intr) {
|
||||
case 0x03: // PRC Copy Complete
|
||||
PMR_IRQ_ACT1 |= 0x80;
|
||||
break;
|
||||
case 0x04: // PRC Frame Divider Overflow
|
||||
PMR_IRQ_ACT1 |= 0x40;
|
||||
break;
|
||||
case 0x05: // Timer 2-B Underflow
|
||||
PMR_IRQ_ACT1 |= 0x20;
|
||||
break;
|
||||
case 0x06: // Timer 2-A Underflow (8-Bits only)
|
||||
PMR_IRQ_ACT1 |= 0x10;
|
||||
break;
|
||||
case 0x07: // Timer 1-B Underflow
|
||||
PMR_IRQ_ACT1 |= 0x08;
|
||||
break;
|
||||
case 0x08: // Timer 1-A Underflow (8-Bits only)
|
||||
PMR_IRQ_ACT1 |= 0x04;
|
||||
break;
|
||||
case 0x09: // Timer 3 Underflow
|
||||
PMR_IRQ_ACT1 |= 0x02;
|
||||
break;
|
||||
case 0x0A: // Timer 3 Pivot
|
||||
PMR_IRQ_ACT1 |= 0x01;
|
||||
break;
|
||||
case 0x0B: // 32 Hz
|
||||
PMR_IRQ_ACT2 |= 0x20;
|
||||
break;
|
||||
case 0x0C: // 8 Hz
|
||||
PMR_IRQ_ACT2 |= 0x10;
|
||||
break;
|
||||
case 0x0D: // 2 Hz
|
||||
PMR_IRQ_ACT2 |= 0x08;
|
||||
break;
|
||||
case 0x0E: // 1 Hz
|
||||
PMR_IRQ_ACT2 |= 0x04;
|
||||
break;
|
||||
case 0x0F: // IR Receiver
|
||||
PMR_IRQ_ACT4 |= 0x80;
|
||||
break;
|
||||
case 0x10: // Shock Sensor
|
||||
PMR_IRQ_ACT4 |= 0x40;
|
||||
break;
|
||||
case 0x13: // Cartridge Ejected
|
||||
PMR_IRQ_ACT2 |= 0x02;
|
||||
break;
|
||||
case 0x14: // Cartridge IRQ
|
||||
PMR_IRQ_ACT2 |= 0x01;
|
||||
break;
|
||||
case 0x15: // Power Key
|
||||
PMR_IRQ_ACT3 |= 0x80;
|
||||
break;
|
||||
case 0x16: // Right Key
|
||||
PMR_IRQ_ACT3 |= 0x40;
|
||||
break;
|
||||
case 0x17: // Left Key
|
||||
PMR_IRQ_ACT3 |= 0x20;
|
||||
break;
|
||||
case 0x18: // Down Key
|
||||
PMR_IRQ_ACT3 |= 0x10;
|
||||
break;
|
||||
case 0x19: // Up Key
|
||||
PMR_IRQ_ACT3 |= 0x08;
|
||||
break;
|
||||
case 0x1A: // C Key
|
||||
PMR_IRQ_ACT3 |= 0x04;
|
||||
break;
|
||||
case 0x1B: // B Key
|
||||
PMR_IRQ_ACT3 |= 0x02;
|
||||
break;
|
||||
case 0x1C: // A Key
|
||||
PMR_IRQ_ACT3 |= 0x01;
|
||||
break;
|
||||
}
|
||||
MinxIRQ_Process();
|
||||
}
|
||||
|
||||
uint8_t MinxIRQ_ReadReg(int cpu, uint8_t reg)
|
||||
{
|
||||
// 0x20 to 0x2A
|
||||
switch(reg) {
|
||||
case 0x20: // IRQ Priority 1
|
||||
return PMR_IRQ_PRI1;
|
||||
case 0x21: // IRQ Priority 2
|
||||
return PMR_IRQ_PRI2;
|
||||
case 0x22: // IRQ Priority 3
|
||||
return PMR_IRQ_PRI3 & 0x03;
|
||||
case 0x23: // IRQ Enable 1
|
||||
return PMR_IRQ_ENA1;
|
||||
case 0x24: // IRQ Enable 2
|
||||
return PMR_IRQ_ENA2 & 0x3F;
|
||||
case 0x25: // IRQ Enable 3
|
||||
return PMR_IRQ_ENA3;
|
||||
case 0x26: // IRQ Enable 4
|
||||
return PMR_IRQ_ENA4 & 0xF7;
|
||||
case 0x27: // IRQ Active 1
|
||||
return PMR_IRQ_ACT1;
|
||||
case 0x28: // IRQ Active 2
|
||||
return PMR_IRQ_ACT2 & 0x3F;
|
||||
case 0x29: // IRQ Active 3
|
||||
return PMR_IRQ_ACT3;
|
||||
case 0x2A: // IRQ Active 4
|
||||
return PMR_IRQ_ACT4 & 0xF7;
|
||||
default: // Unused
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxIRQ_WriteReg(int cpu, uint8_t reg, uint8_t val)
|
||||
{
|
||||
// 0x20 to 0x2A
|
||||
switch(reg) {
|
||||
case 0x20: // IRQ Priority 1
|
||||
PMR_IRQ_PRI1 = val;
|
||||
MinxIRQ_Process();
|
||||
return;
|
||||
case 0x21: // IRQ Priority 2
|
||||
PMR_IRQ_PRI2 = val;
|
||||
MinxIRQ_Process();
|
||||
return;
|
||||
case 0x22: // IRQ Priority 3
|
||||
PMR_IRQ_PRI3 = val;
|
||||
MinxIRQ_Process();
|
||||
return;
|
||||
case 0x23: // IRQ Enable 1
|
||||
PMR_IRQ_ENA1 = val;
|
||||
MinxIRQ_Process();
|
||||
return;
|
||||
case 0x24: // IRQ Enable 2
|
||||
PMR_IRQ_ENA2 = val & 0x3F;
|
||||
MinxIRQ_Process();
|
||||
return;
|
||||
case 0x25: // IRQ Enable 3
|
||||
PMR_IRQ_ENA3 = val;
|
||||
MinxIRQ_Process();
|
||||
return;
|
||||
case 0x26: // IRQ Enable 4
|
||||
PMR_IRQ_ENA4 = val & 0xF7;
|
||||
MinxIRQ_Process();
|
||||
return;
|
||||
case 0x27: // IRQ Active 1
|
||||
if (cpu) PMR_IRQ_ACT1 &= ~val;
|
||||
else PMR_IRQ_ACT1 = val;
|
||||
return;
|
||||
case 0x28: // IRQ Active 2
|
||||
if (cpu) PMR_IRQ_ACT2 &= ~val;
|
||||
else PMR_IRQ_ACT2 = val & 0x3F;
|
||||
return;
|
||||
case 0x29: // IRQ Active 3
|
||||
if (cpu) PMR_IRQ_ACT3 &= ~val;
|
||||
else PMR_IRQ_ACT3 = val;
|
||||
return;
|
||||
case 0x2A: // IRQ Active 4
|
||||
if (cpu) PMR_IRQ_ACT4 &= ~val;
|
||||
else PMR_IRQ_ACT4 = val & 0xF7;
|
||||
return;
|
||||
default: // Unused
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxIRQ_Process(void)
|
||||
{
|
||||
// TODO! Need to emulate the priority system... bah...
|
||||
if (!MinxIRQ_MasterIRQ) return;
|
||||
|
||||
if (PMR_IRQ_PRI1 & 0xC0) {
|
||||
if ((PMR_IRQ_ENA1 & 0x80) && (PMR_IRQ_ACT1 & 0x80)) { MinxIRQ_OnIRQ(0x03); return; }
|
||||
if ((PMR_IRQ_ENA1 & 0x40) && (PMR_IRQ_ACT1 & 0x40)) { MinxIRQ_OnIRQ(0x04); return; }
|
||||
}
|
||||
if (PMR_IRQ_PRI1 & 0x30) {
|
||||
if ((PMR_IRQ_ENA1 & 0x20) && (PMR_IRQ_ACT1 & 0x20)) { MinxIRQ_OnIRQ(0x05); return; }
|
||||
if ((PMR_IRQ_ENA1 & 0x10) && (PMR_IRQ_ACT1 & 0x10)) { MinxIRQ_OnIRQ(0x06); return; }
|
||||
}
|
||||
if (PMR_IRQ_PRI1 & 0x0C) {
|
||||
if ((PMR_IRQ_ENA1 & 0x08) && (PMR_IRQ_ACT1 & 0x08)) { MinxIRQ_OnIRQ(0x07); return; }
|
||||
if ((PMR_IRQ_ENA1 & 0x04) && (PMR_IRQ_ACT1 & 0x04)) { MinxIRQ_OnIRQ(0x08); return; }
|
||||
}
|
||||
if (PMR_IRQ_PRI1 & 0x03) {
|
||||
if ((PMR_IRQ_ENA1 & 0x02) && (PMR_IRQ_ACT1 & 0x02)) { MinxIRQ_OnIRQ(0x09); return; }
|
||||
if ((PMR_IRQ_ENA1 & 0x01) && (PMR_IRQ_ACT1 & 0x01)) { MinxIRQ_OnIRQ(0x0A); return; }
|
||||
}
|
||||
if (PMR_IRQ_PRI2 & 0xC0) {
|
||||
if ((PMR_IRQ_ENA2 & 0x20) && (PMR_IRQ_ACT2 & 0x20)) { MinxIRQ_OnIRQ(0x0B); return; }
|
||||
if ((PMR_IRQ_ENA2 & 0x10) && (PMR_IRQ_ACT2 & 0x10)) { MinxIRQ_OnIRQ(0x0C); return; }
|
||||
if ((PMR_IRQ_ENA2 & 0x08) && (PMR_IRQ_ACT2 & 0x08)) { MinxIRQ_OnIRQ(0x0D); return; }
|
||||
if ((PMR_IRQ_ENA2 & 0x04) && (PMR_IRQ_ACT2 & 0x04)) { MinxIRQ_OnIRQ(0x0E); return; }
|
||||
}
|
||||
if (PMR_IRQ_PRI3 & 0x03) {
|
||||
if ((PMR_IRQ_ENA4 & 0x80) && (PMR_IRQ_ACT4 & 0x80)) { MinxIRQ_OnIRQ(0x0F); return; }
|
||||
if ((PMR_IRQ_ENA4 & 0x40) && (PMR_IRQ_ACT4 & 0x40)) { MinxIRQ_OnIRQ(0x10); return; }
|
||||
}
|
||||
if (PMR_IRQ_PRI2 & 0x30) {
|
||||
if ((PMR_IRQ_ENA2 & 0x02) && (PMR_IRQ_ACT2 & 0x02)) { MinxIRQ_OnIRQ(0x13); return; }
|
||||
if ((PMR_IRQ_ENA2 & 0x01) && (PMR_IRQ_ACT2 & 0x01)) { MinxIRQ_OnIRQ(0x14); return; }
|
||||
}
|
||||
if (PMR_IRQ_PRI2 & 0x0C) {
|
||||
if ((PMR_IRQ_ENA3 & 0x80) && (PMR_IRQ_ACT3 & 0x80)) { MinxIRQ_OnIRQ(0x15); return; }
|
||||
if ((PMR_IRQ_ENA3 & 0x40) && (PMR_IRQ_ACT3 & 0x40)) { MinxIRQ_OnIRQ(0x16); return; }
|
||||
if ((PMR_IRQ_ENA3 & 0x20) && (PMR_IRQ_ACT3 & 0x20)) { MinxIRQ_OnIRQ(0x17); return; }
|
||||
if ((PMR_IRQ_ENA3 & 0x10) && (PMR_IRQ_ACT3 & 0x10)) { MinxIRQ_OnIRQ(0x18); return; }
|
||||
if ((PMR_IRQ_ENA3 & 0x08) && (PMR_IRQ_ACT3 & 0x08)) { MinxIRQ_OnIRQ(0x19); return; }
|
||||
if ((PMR_IRQ_ENA3 & 0x04) && (PMR_IRQ_ACT3 & 0x04)) { MinxIRQ_OnIRQ(0x1A); return; }
|
||||
if ((PMR_IRQ_ENA3 & 0x02) && (PMR_IRQ_ACT3 & 0x02)) { MinxIRQ_OnIRQ(0x1B); return; }
|
||||
if ((PMR_IRQ_ENA3 & 0x01) && (PMR_IRQ_ACT3 & 0x01)) { MinxIRQ_OnIRQ(0x1C); return; }
|
||||
}
|
||||
if (PMR_IRQ_PRI2 & 0x03) {
|
||||
if ((PMR_IRQ_ENA4 & 0x04) && (PMR_IRQ_ACT4 & 0x04)) { MinxIRQ_OnIRQ(0x1D); return; }
|
||||
if ((PMR_IRQ_ENA4 & 0x02) && (PMR_IRQ_ACT4 & 0x02)) { MinxIRQ_OnIRQ(0x1E); return; }
|
||||
if ((PMR_IRQ_ENA4 & 0x01) && (PMR_IRQ_ACT4 & 0x01)) { MinxIRQ_OnIRQ(0x1F); return; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2012 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MINXHW_IRQ
|
||||
#define MINXHW_IRQ
|
||||
|
||||
#include <stdint.h>
|
||||
#include <streams/memory_stream.h>
|
||||
|
||||
// Master IRQ enable
|
||||
extern int MinxIRQ_MasterIRQ;
|
||||
|
||||
|
||||
int MinxIRQ_Create(void);
|
||||
|
||||
void MinxIRQ_Destroy(void);
|
||||
|
||||
void MinxIRQ_Reset(int hardreset);
|
||||
|
||||
int MinxIRQ_LoadStateStream(memstream_t *stream, uint32_t bsize);
|
||||
|
||||
int MinxIRQ_SaveStateStream(memstream_t *stream);
|
||||
|
||||
void MinxIRQ_SetIRQ(uint8_t intr);
|
||||
|
||||
uint8_t MinxIRQ_ReadReg(int cpu, uint8_t reg);
|
||||
|
||||
void MinxIRQ_WriteReg(int cpu, uint8_t reg, uint8_t val);
|
||||
|
||||
void MinxIRQ_Process(void);
|
||||
|
||||
//
|
||||
// Callbacks (Written by the user)
|
||||
//
|
||||
|
||||
void MinxIRQ_OnIRQ(uint8_t intr);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,612 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2014 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PokeMini.h"
|
||||
/* PokeMiniEmu: Video.h left out (no host video); its Interpolate8 here */
|
||||
static INLINE int Interpolate8(int a, int b, int pos)
|
||||
{
|
||||
return ((255 - pos) * a + pos * b) >> 8;
|
||||
}
|
||||
|
||||
TMinxLCD MinxLCD;
|
||||
int LCDDirty = 0;
|
||||
uint8_t *LCDData = NULL;
|
||||
uint8_t *LCDPixelsD = NULL;
|
||||
uint8_t *LCDPixelsA = NULL;
|
||||
uint8_t *LCDPixelsAS = NULL;
|
||||
|
||||
const int LCDDirtyPixels[4] = {
|
||||
4, // LCDMODE_ANALOG
|
||||
2, // LCDMODE_3SHADES
|
||||
1, // LCDMODE_2SHADES
|
||||
2 // LCDMODE_COLORS
|
||||
};
|
||||
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
|
||||
int MinxLCD_Create(void)
|
||||
{
|
||||
// Create LCD memory
|
||||
LCDData = (uint8_t *)malloc(256*9);
|
||||
if (!LCDData) return 0;
|
||||
LCDPixelsD = (uint8_t *)malloc(96*64);
|
||||
if (!LCDPixelsD) return 0;
|
||||
LCDPixelsA = (uint8_t *)malloc(96*64*2);
|
||||
if (!LCDPixelsA) return 0;
|
||||
LCDPixelsAS = (uint8_t *)LCDPixelsA + 96*64;
|
||||
|
||||
// Reset
|
||||
MinxLCD_Reset(1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MinxLCD_Destroy(void)
|
||||
{
|
||||
if (LCDData) {
|
||||
free(LCDData);
|
||||
LCDData = NULL;
|
||||
}
|
||||
if (LCDPixelsD) {
|
||||
free(LCDPixelsD);
|
||||
LCDPixelsD = NULL;
|
||||
}
|
||||
if (LCDPixelsA) {
|
||||
free(LCDPixelsA);
|
||||
LCDPixelsA = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxLCD_Reset(int hardreset)
|
||||
{
|
||||
// Clean up memory
|
||||
memset(LCDData, 0x00, 256*9);
|
||||
memset(LCDPixelsD, 0x00, 96*64);
|
||||
memset(LCDPixelsA, 0x00, 96*64*2);
|
||||
|
||||
// Initialize State
|
||||
memset((void *)&MinxLCD, 0, sizeof(TMinxLCD));
|
||||
|
||||
// Initialize variables
|
||||
MinxLCD_SetContrast(0x1F);
|
||||
}
|
||||
|
||||
int MinxLCD_LoadStateStream(memstream_t *stream, uint32_t bsize)
|
||||
{
|
||||
POKELOADSS_START(256*9 + 96*64 + 96*64 + 64);
|
||||
POKELOADSS_STREAM_A(LCDData, 256*9);
|
||||
POKELOADSS_STREAM_A(LCDPixelsD, 96*64);
|
||||
POKELOADSS_STREAM_A(LCDPixelsA, 96*64);
|
||||
POKELOADSS_STREAM_32(MinxLCD.Pixel0Intensity);
|
||||
POKELOADSS_STREAM_32(MinxLCD.Pixel1Intensity);
|
||||
POKELOADSS_STREAM_8(MinxLCD.Column);
|
||||
POKELOADSS_STREAM_8(MinxLCD.StartLine);
|
||||
POKELOADSS_STREAM_8(MinxLCD.SetContrast);
|
||||
POKELOADSS_STREAM_8(MinxLCD.Contrast);
|
||||
POKELOADSS_STREAM_8(MinxLCD.SegmentDir);
|
||||
POKELOADSS_STREAM_8(MinxLCD.MaxContrast);
|
||||
POKELOADSS_STREAM_8(MinxLCD.SetAllPix);
|
||||
POKELOADSS_STREAM_8(MinxLCD.InvAllPix);
|
||||
POKELOADSS_STREAM_8(MinxLCD.DisplayOn);
|
||||
POKELOADSS_STREAM_8(MinxLCD.Page);
|
||||
POKELOADSS_STREAM_8(MinxLCD.RowOrder);
|
||||
POKELOADSS_STREAM_8(MinxLCD.ReadModifyMode);
|
||||
POKELOADSS_STREAM_8(MinxLCD.RequireDummyR);
|
||||
POKELOADSS_STREAM_8(MinxLCD.RMWColumn);
|
||||
POKELOADSS_STREAM_X(42);
|
||||
POKELOADSS_END(256*9 + 96*64 + 96*64 + 64);
|
||||
}
|
||||
|
||||
int MinxLCD_SaveStateStream(memstream_t *stream)
|
||||
{
|
||||
POKESAVESS_STREAM_START(256*9 + 96*64 + 96*64 + 64);
|
||||
POKESAVESS_STREAM_A(LCDData, 256*9);
|
||||
POKESAVESS_STREAM_A(LCDPixelsD, 96*64);
|
||||
POKESAVESS_STREAM_A(LCDPixelsA, 96*64);
|
||||
POKESAVESS_STREAM_32(MinxLCD.Pixel0Intensity);
|
||||
POKESAVESS_STREAM_32(MinxLCD.Pixel1Intensity);
|
||||
POKESAVESS_STREAM_8(MinxLCD.Column);
|
||||
POKESAVESS_STREAM_8(MinxLCD.StartLine);
|
||||
POKESAVESS_STREAM_8(MinxLCD.SetContrast);
|
||||
POKESAVESS_STREAM_8(MinxLCD.Contrast);
|
||||
POKESAVESS_STREAM_8(MinxLCD.SegmentDir);
|
||||
POKESAVESS_STREAM_8(MinxLCD.MaxContrast);
|
||||
POKESAVESS_STREAM_8(MinxLCD.SetAllPix);
|
||||
POKESAVESS_STREAM_8(MinxLCD.InvAllPix);
|
||||
POKESAVESS_STREAM_8(MinxLCD.DisplayOn);
|
||||
POKESAVESS_STREAM_8(MinxLCD.Page);
|
||||
POKESAVESS_STREAM_8(MinxLCD.RowOrder);
|
||||
POKESAVESS_STREAM_8(MinxLCD.ReadModifyMode);
|
||||
POKESAVESS_STREAM_8(MinxLCD.RequireDummyR);
|
||||
POKESAVESS_STREAM_8(MinxLCD.RMWColumn);
|
||||
POKESAVESS_STREAM_X(42);
|
||||
POKESAVESS_END(256*9 + 96*64 + 96*64 + 64);
|
||||
}
|
||||
|
||||
uint8_t MinxLCD_ReadReg(int cpu, uint8_t reg)
|
||||
{
|
||||
// 0xFE to 0xFF
|
||||
switch(reg) {
|
||||
case 0xFE: // Read from LCD with Control Activated
|
||||
return MinxLCD_LCDReadCtrl(cpu);
|
||||
case 0xFF: // Read from LCD with Control Desactivated
|
||||
return MinxLCD_LCDRead(cpu);
|
||||
default: // Unused
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxLCD_WriteReg(int cpu, uint8_t reg, uint8_t val)
|
||||
{
|
||||
// 0xFE to 0xFF
|
||||
switch(reg) {
|
||||
case 0xFE: // Write to LCD with Control Activated
|
||||
MinxLCD_LCDWriteCtrl(val);
|
||||
return;
|
||||
case 0xFF: // Write to LCD with Control Desactivated
|
||||
MinxLCD_LCDWrite(val);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#define DECAY_A_OFF 64
|
||||
#define DECAY_ARISE 50
|
||||
#define DECAY_AFALL 30
|
||||
#define DECAY_L_OFF 16
|
||||
#define DECAY_LRISE 4
|
||||
#define DECAY_LFALL 2
|
||||
|
||||
void MinxLCD_DecayRefreshOld(void)
|
||||
{
|
||||
int i, amt;
|
||||
if (MinxLCD.DisplayOn) {
|
||||
for (i=0; i<96*64; i++) {
|
||||
if (LCDPixelsD[i]) {
|
||||
amt = Interpolate8(LCDPixelsA[i], MinxLCD.Pixel1Intensity, DECAY_ARISE) + DECAY_LRISE;
|
||||
if (amt > MinxLCD.Pixel1Intensity) amt = MinxLCD.Pixel1Intensity;
|
||||
} else {
|
||||
amt = Interpolate8(LCDPixelsA[i], MinxLCD.Pixel0Intensity, DECAY_AFALL) - DECAY_LFALL;
|
||||
if (amt < MinxLCD.Pixel0Intensity) amt = MinxLCD.Pixel0Intensity;
|
||||
}
|
||||
LCDPixelsA[i] = amt;
|
||||
}
|
||||
} else {
|
||||
for (i=0; i<96*64; i++) {
|
||||
amt = Interpolate8(LCDPixelsA[i], 0, DECAY_A_OFF) - DECAY_L_OFF;
|
||||
if (amt < MinxLCD.Pixel0Intensity) amt = MinxLCD.Pixel0Intensity;
|
||||
LCDPixelsA[i] = amt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const uint8_t BitsActives[256] = {
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
|
||||
};
|
||||
|
||||
void MinxLCD_DecayRefresh(void)
|
||||
{
|
||||
int i, level;
|
||||
uint8_t sh;
|
||||
// This is tuned for 5 shades
|
||||
if (MinxLCD.DisplayOn) {
|
||||
for (i=0; i<96*64; i++) {
|
||||
sh = (LCDPixelsD[i] ? 0x08 : 0x00) | (LCDPixelsAS[i] >> 1);
|
||||
LCDPixelsAS[i] = sh;
|
||||
level = BitsActives[sh];
|
||||
LCDPixelsA[i] = (MinxLCD.Pixel0Intensity * (4 - level) + MinxLCD.Pixel1Intensity * level) >> 2;
|
||||
}
|
||||
} else {
|
||||
for (i=0; i<96*64; i++) {
|
||||
sh = (LCDPixelsAS[i] >> 1);
|
||||
LCDPixelsAS[i] = sh;
|
||||
level = BitsActives[sh];
|
||||
LCDPixelsA[i] = (MinxLCD.Pixel0Intensity * (4 - level) + MinxLCD.Pixel1Intensity * level) >> 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MinxLCD_Render(void)
|
||||
{
|
||||
uint8_t pixel;
|
||||
int xC, yC, yP;
|
||||
|
||||
if (MinxLCD.DisplayOn) {
|
||||
for (yC=0; yC<64; yC++) {
|
||||
yP = (yC + MinxLCD.StartLine) & 63;
|
||||
if (MinxLCD.RowOrder) yP = 63 - yP;
|
||||
for (xC=0; xC<96; xC++) {
|
||||
pixel = (LCDData[((yP >> 3) * 256) + xC] >> (yP & 7)) & 1;
|
||||
LCDPixelsD[(yC * 96) + xC] = (pixel ^ MinxLCD.InvAllPix) | MinxLCD.SetAllPix;
|
||||
}
|
||||
}
|
||||
} else for (yC=0; yC<96*64; yC++) LCDPixelsD[yC] = 0;
|
||||
}
|
||||
|
||||
uint8_t MinxLCD_LCDReadCtrl(int cpu)
|
||||
{
|
||||
uint8_t data;
|
||||
if (MinxLCD.SetContrast) {
|
||||
MinxLCD.SetContrast = 0;
|
||||
// Contrast query, cause incorrect value?
|
||||
MinxLCD_SetContrast(0x3F);
|
||||
data = 0;
|
||||
} else {
|
||||
// Get status
|
||||
data = 0x40 | (MinxLCD.DisplayOn ? 0x20 : 0x00);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
uint8_t MinxLCD_LCDRead(int cpu)
|
||||
{
|
||||
static uint8_t data = 0x40;
|
||||
if (MinxLCD.SetContrast) {
|
||||
MinxLCD.SetContrast = 0;
|
||||
// Contrast query, cause incorrect value?
|
||||
MinxLCD_SetContrast(0x3F);
|
||||
data = 0;
|
||||
} else {
|
||||
// Get pixel
|
||||
if (!MinxLCD.RequireDummyR && cpu) {
|
||||
if (MinxLCD.SegmentDir) {
|
||||
data = LCDData[131 - MinxLCD.Column + (MinxLCD.Page << 8)];
|
||||
} else {
|
||||
data = LCDData[MinxLCD.Column + (MinxLCD.Page << 8)];
|
||||
}
|
||||
if (MinxLCD.Page >= 8) data &= 0x01;
|
||||
if (!MinxLCD.ReadModifyMode) {
|
||||
MinxLCD.Column++;
|
||||
if (MinxLCD.Column > 131) MinxLCD.Column = 131;
|
||||
MinxLCD.RequireDummyR = 1;
|
||||
}
|
||||
} else MinxLCD.RequireDummyR = 0;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void MinxLCD_LCDWriteCtrl(uint8_t data)
|
||||
{
|
||||
if (MinxLCD.SetContrast) {
|
||||
MinxLCD.SetContrast = 0;
|
||||
MinxLCD_SetContrast(data & 0x3F);
|
||||
return;
|
||||
}
|
||||
switch(data) {
|
||||
case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
|
||||
case 0x08: case 0x09: case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x0E: case 0x0F:
|
||||
if (!MinxLCD.ReadModifyMode) {
|
||||
MinxLCD.Column = (MinxLCD.Column & 0xF0) | (data & 0x0F);
|
||||
MinxLCD.RequireDummyR = 1;
|
||||
}
|
||||
return;
|
||||
case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
|
||||
case 0x18: case 0x19: case 0x1A: case 0x1B: case 0x1C: case 0x1D: case 0x1E: case 0x1F:
|
||||
if (!MinxLCD.ReadModifyMode) {
|
||||
MinxLCD.Column = (MinxLCD.Column & 0x0F) | ((data & 0x0F) << 4);
|
||||
MinxLCD.RequireDummyR = 1;
|
||||
}
|
||||
return;
|
||||
case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
|
||||
// Do nothing?
|
||||
return;
|
||||
case 0x28: case 0x29: case 0x2A: case 0x2B: case 0x2C: case 0x2D: case 0x2E: case 0x2F:
|
||||
// Modify LCD voltage? (2F Default)
|
||||
// 0x28 = Blank
|
||||
// 0x29 = Blank
|
||||
// 0x2A = Blue screen then blank
|
||||
// 0x2B = Blank
|
||||
// 0x2C = Blank
|
||||
// 0x2D = Blank
|
||||
// 0x2E = Blue screen (overpower?)
|
||||
// 0x2F = Normal
|
||||
// User shouldn't mess with this ones as may damage the LCD
|
||||
return;
|
||||
case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
|
||||
case 0x38: case 0x39: case 0x3A: case 0x3B: case 0x3C: case 0x3D: case 0x3E: case 0x3F:
|
||||
// Do nothing?
|
||||
return;
|
||||
case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47:
|
||||
case 0x48: case 0x49: case 0x4A: case 0x4B: case 0x4C: case 0x4D: case 0x4E: case 0x4F:
|
||||
case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57:
|
||||
case 0x58: case 0x59: case 0x5A: case 0x5B: case 0x5C: case 0x5D: case 0x5E: case 0x5F:
|
||||
case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67:
|
||||
case 0x68: case 0x69: case 0x6A: case 0x6B: case 0x6C: case 0x6D: case 0x6E: case 0x6F:
|
||||
case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77:
|
||||
case 0x78: case 0x79: case 0x7A: case 0x7B: case 0x7C: case 0x7D: case 0x7E: case 0x7F:
|
||||
// Set starting LCD scanline (cause warp around)
|
||||
MinxLCD.StartLine = data - 0x40;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0x80:
|
||||
// Do nothing?
|
||||
return;
|
||||
case 0x81:
|
||||
// Set contrast at the next write
|
||||
MinxLCD.SetContrast = 1;
|
||||
return;
|
||||
case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87:
|
||||
case 0x88: case 0x89: case 0x8A: case 0x8B: case 0x8C: case 0x8D: case 0x8E: case 0x8F:
|
||||
case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97:
|
||||
case 0x98: case 0x99: case 0x9A: case 0x9B: case 0x9C: case 0x9D: case 0x9E: case 0x9F:
|
||||
// Do nothing?
|
||||
return;
|
||||
case 0xA0:
|
||||
// Segment Driver Direction Select: Normal
|
||||
MinxLCD.SegmentDir = 0;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0xA1:
|
||||
// Segment Driver Direction Select: Reverse
|
||||
MinxLCD.SegmentDir = 1;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0xA2:
|
||||
// Max Contrast: Disable
|
||||
MinxLCD.MaxContrast = 0;
|
||||
MinxLCD_SetContrast(MinxLCD.Contrast);
|
||||
return;
|
||||
case 0xA3:
|
||||
// Max Contrast: Enable
|
||||
MinxLCD.MaxContrast = 1;
|
||||
MinxLCD_SetContrast(MinxLCD.Contrast);
|
||||
return;
|
||||
case 0xA4:
|
||||
// Set All Pixels: Disable
|
||||
MinxLCD.SetAllPix = 0;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0xA5:
|
||||
// Set All Pixels: Enable
|
||||
MinxLCD.SetAllPix = 1;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0xA6:
|
||||
// Invert All Pixels: Disable
|
||||
MinxLCD.InvAllPix = 0;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0xA7:
|
||||
// Invert All Pixels: Enable
|
||||
MinxLCD.InvAllPix = 1;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0xA8: case 0xA9: case 0xAA: case 0xAB:
|
||||
// Do nothing!?
|
||||
return;
|
||||
case 0xAC: case 0xAD:
|
||||
// User shouldn't mess with this ones as may damage the LCD
|
||||
return;
|
||||
case 0xAE:
|
||||
// Display Off
|
||||
MinxLCD.DisplayOn = 0;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0xAF:
|
||||
// Display On
|
||||
MinxLCD.DisplayOn = 1;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0xB0: case 0xB1: case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: case 0xB7:
|
||||
case 0xB8:
|
||||
// Set page (0-8, each page is 8px high)
|
||||
MinxLCD.Page = data & 15;
|
||||
return;
|
||||
case 0xB9: case 0xBA: case 0xBB: case 0xBC: case 0xBD: case 0xBE: case 0xBF:
|
||||
// uh... do nothing?
|
||||
return;
|
||||
case 0xC0: case 0xC1: case 0xC2: case 0xC3: case 0xC4: case 0xC5: case 0xC6: case 0xC7:
|
||||
// Display rows from top to bottom as 0 to 63
|
||||
MinxLCD.RowOrder = 0;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0xC8: case 0xC9: case 0xCA: case 0xCB: case 0xCC: case 0xCD: case 0xCE: case 0xCF:
|
||||
// Display rows from top to bottom as 63 to 0
|
||||
MinxLCD.RowOrder = 1;
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
return;
|
||||
case 0xD0: case 0xD1: case 0xD2: case 0xD3: case 0xD4: case 0xD5: case 0xD6: case 0xD7:
|
||||
case 0xD8: case 0xD9: case 0xDA: case 0xDB: case 0xDC: case 0xDD: case 0xDE: case 0xDF:
|
||||
// Do nothing?
|
||||
return;
|
||||
case 0xE0:
|
||||
// Start "Read Modify Write"
|
||||
MinxLCD.ReadModifyMode = 1;
|
||||
MinxLCD.RMWColumn = MinxLCD.Column;
|
||||
return;
|
||||
case 0xE2:
|
||||
// Reset
|
||||
MinxLCD.SetContrast = 0;
|
||||
MinxLCD_SetContrast(0x20);
|
||||
MinxLCD.Column = 0;
|
||||
MinxLCD.StartLine = 0;
|
||||
MinxLCD.SegmentDir = 0;
|
||||
MinxLCD.MaxContrast = 0;
|
||||
MinxLCD.SetAllPix = 0;
|
||||
MinxLCD.InvAllPix = 0;
|
||||
MinxLCD.DisplayOn = 0;
|
||||
MinxLCD.Page = 0;
|
||||
MinxLCD.RowOrder = 0;
|
||||
MinxLCD.ReadModifyMode = 0;
|
||||
MinxLCD.RequireDummyR = 1;
|
||||
MinxLCD.RMWColumn = 0;
|
||||
return;
|
||||
case 0xE3:
|
||||
// No operation
|
||||
return;
|
||||
case 0xEE:
|
||||
// End "Read Modify Write"
|
||||
MinxLCD.ReadModifyMode = 0;
|
||||
MinxLCD.Column = MinxLCD.RMWColumn;
|
||||
return;
|
||||
case 0xE1: case 0xE4: case 0xE5: case 0xE6: case 0xE7:
|
||||
case 0xE8: case 0xE9: case 0xEA: case 0xEB: case 0xEC: case 0xED: case 0xEF:
|
||||
// User shouldn't mess with this ones as may damage the LCD
|
||||
return;
|
||||
case 0xF0: case 0xF1: case 0xF2: case 0xF3: case 0xF4: case 0xF5: case 0xF6: case 0xF7:
|
||||
// 0xF1 and 0xF5 freeze LCD and cause malfunction (need to power off the device to restore)
|
||||
// User shouldn't mess with this ones as may damage the LCD
|
||||
return;
|
||||
case 0xF8: case 0xF9: case 0xFA: case 0xFB: case 0xFC: case 0xFD: case 0xFE: case 0xFF:
|
||||
// Contrast voltage control, FC = Default
|
||||
// User shouldn't mess with this ones as may damage the LCD
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxLCD_LCDWrite(uint8_t data)
|
||||
{
|
||||
int addr;
|
||||
if (MinxLCD.SetContrast) {
|
||||
MinxLCD.SetContrast = 0;
|
||||
// Set contrast
|
||||
MinxLCD_SetContrast(data & 0x3F);
|
||||
} else {
|
||||
// Set pixel
|
||||
if (MinxLCD.SegmentDir) {
|
||||
addr = 131 - MinxLCD.Column + (MinxLCD.Page << 8);
|
||||
} else {
|
||||
addr = MinxLCD.Column + (MinxLCD.Page << 8);
|
||||
}
|
||||
LCDData[addr] = data;
|
||||
if (PRCColorMap) MinxColorPRC_WriteLCD(addr, data);
|
||||
MinxLCD.Column++;
|
||||
if (MinxLCD.Column > 131) MinxLCD.Column = 131;
|
||||
MinxLCD.RequireDummyR = 1;
|
||||
LCDDirty = LCDDirtyPixels[PokeMini_LCDMode];
|
||||
}
|
||||
}
|
||||
|
||||
void MinxLCD_LCDWritefb(uint8_t *fb)
|
||||
{
|
||||
int i;
|
||||
uint8_t *dst = (uint8_t *)LCDData, pages = 8;
|
||||
if (MinxLCD.SegmentDir) {
|
||||
while (pages--) {
|
||||
for (i=0; i<96; i++) dst[131-i] = fb[i];
|
||||
dst += 256; fb += 96;
|
||||
}
|
||||
} else {
|
||||
while (pages--) {
|
||||
memcpy(dst, fb, 96);
|
||||
dst += 256; fb += 96;
|
||||
}
|
||||
}
|
||||
MinxLCD.Page = 7;
|
||||
MinxLCD.Column = 96;
|
||||
MinxLCD.RequireDummyR = 1;
|
||||
MinxLCD.ReadModifyMode = 0;
|
||||
LCDDirty = LCDDirtyPixels[PokeMini_LCDMode];
|
||||
}
|
||||
|
||||
// Contrast level on light and dark pixel
|
||||
const uint8_t MinxLCD_ContrastLvl[64][2] = {
|
||||
{ 0, 4}, // 0 (0x00)
|
||||
{ 0, 4}, // 1 (0x01)
|
||||
{ 0, 4}, // 2 (0x02)
|
||||
{ 0, 4}, // 3 (0x03)
|
||||
{ 0, 6}, // 4 (0x04)
|
||||
{ 0, 11}, // 5 (0x05)
|
||||
{ 0, 17}, // 6 (0x06)
|
||||
{ 0, 24}, // 7 (0x07)
|
||||
{ 0, 31}, // 8 (0x08)
|
||||
{ 0, 40}, // 9 (0x09)
|
||||
{ 0, 48}, // 10 (0x0A)
|
||||
{ 0, 57}, // 11 (0x0B)
|
||||
{ 0, 67}, // 12 (0x0C)
|
||||
{ 0, 77}, // 13 (0x0D)
|
||||
{ 0, 88}, // 14 (0x0E)
|
||||
{ 0, 99}, // 15 (0x0F)
|
||||
{ 0, 110}, // 16 (0x10)
|
||||
{ 0, 122}, // 17 (0x11)
|
||||
{ 0, 133}, // 18 (0x12)
|
||||
{ 0, 146}, // 19 (0x13)
|
||||
{ 0, 158}, // 20 (0x14)
|
||||
{ 0, 171}, // 21 (0x15)
|
||||
{ 0, 184}, // 22 (0x16)
|
||||
{ 0, 198}, // 23 (0x17)
|
||||
{ 0, 212}, // 24 (0x18)
|
||||
{ 0, 226}, // 25 (0x19)
|
||||
{ 0, 240}, // 26 (0x1A)
|
||||
{ 0, 255}, // 27 (0x1B)
|
||||
{ 2, 255}, // 28 (0x1C)
|
||||
{ 5, 255}, // 29 (0x1D)
|
||||
{ 10, 255}, // 30 (0x1E)
|
||||
{ 15, 255}, // 31 (0x1F)
|
||||
{ 21, 255}, // 32 (0x20)
|
||||
{ 27, 255}, // 33 (0x21)
|
||||
{ 34, 255}, // 34 (0x22)
|
||||
{ 41, 255}, // 35 (0x23)
|
||||
{ 48, 255}, // 36 (0x24)
|
||||
{ 56, 255}, // 37 (0x25)
|
||||
{ 64, 255}, // 38 (0x26)
|
||||
{ 73, 255}, // 39 (0x27)
|
||||
{ 81, 255}, // 40 (0x28)
|
||||
{ 90, 255}, // 41 (0x29)
|
||||
{100, 255}, // 42 (0x2A)
|
||||
{109, 255}, // 43 (0x2B)
|
||||
{119, 255}, // 44 (0x2C)
|
||||
{129, 255}, // 45 (0x2D)
|
||||
{139, 255}, // 46 (0x2E)
|
||||
{149, 255}, // 47 (0x2F)
|
||||
{160, 255}, // 48 (0x30)
|
||||
{171, 255}, // 49 (0x31)
|
||||
{182, 255}, // 50 (0x32)
|
||||
{193, 255}, // 51 (0x33)
|
||||
{204, 255}, // 52 (0x34)
|
||||
{216, 255}, // 53 (0x35)
|
||||
{228, 255}, // 54 (0x36)
|
||||
{240, 255}, // 55 (0x37)
|
||||
{240, 255}, // 56 (0x38)
|
||||
{240, 255}, // 57 (0x39)
|
||||
{240, 255}, // 58 (0x3A)
|
||||
{240, 255}, // 59 (0x3B)
|
||||
{240, 255}, // 60 (0x3C)
|
||||
{240, 255}, // 61 (0x3D)
|
||||
{240, 255}, // 62 (0x3E)
|
||||
{240, 255}, // 63 (0x3F)
|
||||
};
|
||||
|
||||
void MinxLCD_SetContrast(uint8_t value)
|
||||
{
|
||||
MinxLCD.Contrast = value & 0x3F;
|
||||
if (MinxLCD.MaxContrast) {
|
||||
MinxLCD.Pixel0Intensity = 240;
|
||||
MinxLCD.Pixel1Intensity = 255;
|
||||
} else {
|
||||
MinxLCD.Pixel0Intensity = MinxLCD_ContrastLvl[MinxLCD.Contrast][0];
|
||||
MinxLCD.Pixel1Intensity = MinxLCD_ContrastLvl[MinxLCD.Contrast][1];
|
||||
}
|
||||
LCDDirty = MINX_DIRTYSCR;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MINXHW_LCD
|
||||
#define MINXHW_LCD
|
||||
|
||||
#include <stdint.h>
|
||||
#include <streams/memory_stream.h>
|
||||
|
||||
typedef struct {
|
||||
// Internal processing
|
||||
int32_t Pixel0Intensity; // Pixel 0 Intensity
|
||||
int32_t Pixel1Intensity; // Pixel 1 Intensity
|
||||
uint8_t Column; // Column
|
||||
uint8_t StartLine; // Start line
|
||||
uint8_t SetContrast; // Set contrast
|
||||
uint8_t Contrast; // Contrast level
|
||||
uint8_t SegmentDir; // Segment Driver Direction Select
|
||||
uint8_t MaxContrast; // Max Contrast
|
||||
uint8_t SetAllPix; // Set All Pixels
|
||||
uint8_t InvAllPix; // Invert All Pixels
|
||||
uint8_t DisplayOn; // Display On
|
||||
uint8_t Page; // Page
|
||||
uint8_t RowOrder; // 0 = Top to bottom, 1 = Bottom to top
|
||||
uint8_t ReadModifyMode; // Read Modify Write mode
|
||||
uint8_t RequireDummyR; // Require Dummy Read
|
||||
uint8_t RMWColumn; // Column when Read Modify Write started
|
||||
} TMinxLCD;
|
||||
|
||||
#ifndef MINX_DIRTYPIX
|
||||
#define MINX_DIRTYPIX 4
|
||||
#endif
|
||||
|
||||
#ifndef MINX_DIRTYSCR
|
||||
#define MINX_DIRTYSCR 4
|
||||
#endif
|
||||
|
||||
// Export LCD state
|
||||
extern TMinxLCD MinxLCD;
|
||||
|
||||
// LCD dirty status (1+ = graphics changed)
|
||||
extern int LCDDirty;
|
||||
|
||||
// LCD Data (132 x 65 x 1bpp), Pitch of 256 bytes
|
||||
extern uint8_t *LCDData;
|
||||
|
||||
// LCD Pixels Digital (96 x 64, 0 or 1)
|
||||
extern uint8_t *LCDPixelsD;
|
||||
|
||||
// LCD Pixels Analog (96 x 64, 0 to 255)
|
||||
extern uint8_t *LCDPixelsA;
|
||||
|
||||
|
||||
int MinxLCD_Create(void);
|
||||
|
||||
void MinxLCD_Destroy(void);
|
||||
|
||||
void MinxLCD_Reset(int hardreset);
|
||||
|
||||
int MinxLCD_LoadStateStream(memstream_t *stream, uint32_t bsize);
|
||||
|
||||
int MinxLCD_SaveStateStream(memstream_t *stream);
|
||||
|
||||
uint8_t MinxLCD_ReadReg(int cpu, uint8_t reg);
|
||||
|
||||
void MinxLCD_WriteReg(int cpu, uint8_t reg, uint8_t val);
|
||||
|
||||
void MinxLCD_DecayRefresh(void);
|
||||
|
||||
void MinxLCD_Render(void);
|
||||
|
||||
uint8_t MinxLCD_LCDReadCtrl(int cpu);
|
||||
|
||||
uint8_t MinxLCD_LCDRead(int cpu);
|
||||
|
||||
void MinxLCD_LCDWriteCtrl(uint8_t data);
|
||||
|
||||
void MinxLCD_LCDWrite(uint8_t data);
|
||||
|
||||
void MinxLCD_LCDWritefb(uint8_t *fb);
|
||||
|
||||
void MinxLCD_SetContrast(uint8_t value);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,407 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <retro_inline.h>
|
||||
#include "PokeMini.h"
|
||||
|
||||
TMinxPRC MinxPRC;
|
||||
int PRCAllowStall = 1; // Allow stall CPU?
|
||||
int StallCPU = 0; // Stall CPU output flag
|
||||
int PRCRenderBD = 0; // Render backdrop? (Background overrides backdrop)
|
||||
int PRCRenderBG = 1; // Render background?
|
||||
int PRCRenderSpr = 1; // Render sprites?
|
||||
|
||||
const uint8_t PRCInvertBit[256] = { // Invert Bit table
|
||||
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
||||
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
|
||||
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
||||
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
|
||||
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
|
||||
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
||||
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
|
||||
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
|
||||
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
||||
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
|
||||
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
|
||||
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
||||
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
|
||||
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
|
||||
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
||||
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
||||
};
|
||||
|
||||
#ifdef PERFORMANCE
|
||||
int StallCycles = 64; // Stall CPU cycles
|
||||
#else
|
||||
int StallCycles = 32; // Stall CPU cycles
|
||||
#endif
|
||||
|
||||
TMinxPRC_Render MinxPRC_Render = MinxPRC_Render_Mono;
|
||||
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
|
||||
int MinxPRC_Create(void)
|
||||
{
|
||||
// Reset
|
||||
MinxPRC_Reset(1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MinxPRC_Destroy(void)
|
||||
{
|
||||
}
|
||||
|
||||
void MinxPRC_Reset(int hardreset)
|
||||
{
|
||||
// Initialize State
|
||||
memset((void *)&MinxPRC, 0, sizeof(TMinxPRC));
|
||||
|
||||
// Initialize variables
|
||||
StallCPU = 0;
|
||||
MinxPRC.PRCRateMatch = 0x10;
|
||||
}
|
||||
|
||||
int MinxPRC_LoadStateStream(memstream_t *stream, uint32_t bsize)
|
||||
{
|
||||
POKELOADSS_START(1+32);
|
||||
POKELOADSS_STREAM_8(StallCPU);
|
||||
POKELOADSS_STREAM_32(MinxPRC.PRCCnt);
|
||||
POKELOADSS_STREAM_32(MinxPRC.PRCBGBase);
|
||||
POKELOADSS_STREAM_32(MinxPRC.PRCSprBase);
|
||||
POKELOADSS_STREAM_8(MinxPRC.PRCMode);
|
||||
POKELOADSS_STREAM_8(MinxPRC.PRCRateMatch);
|
||||
POKELOADSS_STREAM_8(MinxPRC.PRCMapPX);
|
||||
POKELOADSS_STREAM_8(MinxPRC.PRCMapPY);
|
||||
POKELOADSS_STREAM_8(MinxPRC.PRCMapTW);
|
||||
POKELOADSS_STREAM_8(MinxPRC.PRCMapTH);
|
||||
POKELOADSS_STREAM_8(MinxPRC.PRCState);
|
||||
POKELOADSS_STREAM_X(13);
|
||||
POKELOADSS_END(1+32);
|
||||
}
|
||||
|
||||
int MinxPRC_SaveStateStream(memstream_t *stream)
|
||||
{
|
||||
POKESAVESS_STREAM_START(1+32);
|
||||
POKESAVESS_STREAM_8(StallCPU);
|
||||
POKESAVESS_STREAM_32(MinxPRC.PRCCnt);
|
||||
POKESAVESS_STREAM_32(MinxPRC.PRCBGBase);
|
||||
POKESAVESS_STREAM_32(MinxPRC.PRCSprBase);
|
||||
POKESAVESS_STREAM_8(MinxPRC.PRCMode);
|
||||
POKESAVESS_STREAM_8(MinxPRC.PRCRateMatch);
|
||||
POKESAVESS_STREAM_8(MinxPRC.PRCMapPX);
|
||||
POKESAVESS_STREAM_8(MinxPRC.PRCMapPY);
|
||||
POKESAVESS_STREAM_8(MinxPRC.PRCMapTW);
|
||||
POKESAVESS_STREAM_8(MinxPRC.PRCMapTH);
|
||||
POKESAVESS_STREAM_8(MinxPRC.PRCState);
|
||||
POKESAVESS_STREAM_X(13);
|
||||
POKESAVESS_END(1+32);
|
||||
}
|
||||
|
||||
void MinxPRC_Sync(void)
|
||||
{
|
||||
// Process PRC Counter
|
||||
MinxPRC.PRCCnt += MINX_PRCTIMERINC * PokeHWCycles;
|
||||
if ((PMR_PRC_RATE & 0xF0) >= MinxPRC.PRCRateMatch) {
|
||||
// Active frame
|
||||
if (MinxPRC.PRCCnt < 0x18000000) {
|
||||
// CPU Time
|
||||
MinxPRC.PRCState = 0;
|
||||
} else if ((MinxPRC.PRCCnt & 0xFF000000) == 0x18000000) {
|
||||
// PRC BG&SPR Trigger
|
||||
if (MinxPRC.PRCState == 1) return;
|
||||
if (MinxPRC.PRCMode == 2) {
|
||||
if (PRCAllowStall) StallCPU = 1;
|
||||
MinxPRC_Render();
|
||||
MinxPRC.PRCState = 1;
|
||||
} else if (PRCColorMap) MinxPRC_NoRender_Color();
|
||||
} else if ((MinxPRC.PRCCnt & 0xFF000000) == 0x39000000) {
|
||||
// PRC Copy Trigger
|
||||
if (MinxPRC.PRCState == 2) return;
|
||||
if (MinxPRC.PRCMode) {
|
||||
if (PRCAllowStall) StallCPU = 1;
|
||||
MinxPRC_CopyToLCD();
|
||||
MinxCPU_OnIRQAct(MINX_INTR_03);
|
||||
MinxPRC.PRCState = 2;
|
||||
}
|
||||
} else if (MinxPRC.PRCCnt >= 0x42000000) {
|
||||
// End-of-frame
|
||||
StallCPU = 0;
|
||||
PMR_PRC_RATE &= 0x0F;
|
||||
MinxPRC.PRCCnt = 0x01000000;
|
||||
MinxCPU_OnIRQAct(MINX_INTR_04);
|
||||
MinxPRC_On72HzRefresh(1);
|
||||
}
|
||||
} else {
|
||||
// Non-active frame
|
||||
if (MinxPRC.PRCCnt >= 0x42000000) {
|
||||
PMR_PRC_RATE += 0x10;
|
||||
MinxPRC.PRCCnt = 0x01000000;
|
||||
MinxPRC_On72HzRefresh(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MinxPRC_ReadReg(uint8_t reg)
|
||||
{
|
||||
// 0x80 to 0x8F
|
||||
switch(reg) {
|
||||
case 0x80: // PRC Stage Control
|
||||
return PMR_PRC_MODE & 0x3F;
|
||||
case 0x81: // PRC Rate Control
|
||||
return PMR_PRC_RATE;
|
||||
case 0x82: // PRC Map Tile Base (Lo)
|
||||
return PMR_PRC_MAP_LO & 0xF8;
|
||||
case 0x83: // PRC Map Tile Base (Med)
|
||||
return PMR_PRC_MAP_MID;
|
||||
case 0x84: // PRC Map Tile Base (Hi)
|
||||
return PMR_PRC_MAP_HI & 0x1F;
|
||||
case 0x85: // PRC Map Vertical Scroll
|
||||
return PMR_PRC_SCROLL_Y & 0x7F;
|
||||
case 0x86: // PRC Map Horizontal Scroll
|
||||
return PMR_PRC_SCROLL_X & 0x7F;
|
||||
case 0x87: // PRC Map Sprite Base (Lo)
|
||||
return PMR_PRC_SPR_LO & 0xC0;
|
||||
case 0x88: // PRC Map Sprite Base (Med)
|
||||
return PMR_PRC_SPR_MID;
|
||||
case 0x89: // PRC Map Sprite Base (Hi)
|
||||
return PMR_PRC_SPR_HI & 0x1F;
|
||||
case 0x8A: // PRC Counter
|
||||
return MinxPRC.PRCCnt >> 24;
|
||||
default: // Unused
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void MinxPRC_WriteReg(uint8_t reg, uint8_t val)
|
||||
{
|
||||
// 0x80 to 0x8F
|
||||
switch(reg) {
|
||||
case 0x80: // PRC Stage Control
|
||||
PMR_PRC_MODE = val & 0x3F;
|
||||
if (val & 0x08) {
|
||||
MinxPRC.PRCMode = (val & 0x06) ? 2 : 1;
|
||||
} else MinxPRC.PRCMode = 0;
|
||||
switch (val & 0x30) {
|
||||
case 0x00: MinxPRC.PRCMapTW = 12; MinxPRC.PRCMapTH = 16; break;
|
||||
case 0x10: MinxPRC.PRCMapTW = 16; MinxPRC.PRCMapTH = 12; break;
|
||||
case 0x20: MinxPRC.PRCMapTW = 24; MinxPRC.PRCMapTH = 8; break;
|
||||
case 0x30: MinxPRC.PRCMapTW = 24; MinxPRC.PRCMapTH = 16; break;
|
||||
}
|
||||
return;
|
||||
case 0x81: // PRC Rate Control
|
||||
if ((PMR_PRC_RATE & 0x0E) != (val & 0x0E)) PMR_PRC_RATE = (val & 0x0F);
|
||||
else PMR_PRC_RATE = (PMR_PRC_RATE & 0xF0) | (val & 0x0F);
|
||||
switch (val & 0x0E) {
|
||||
case 0x00: MinxPRC.PRCRateMatch = 0x20; break; // Rate /3
|
||||
case 0x02: MinxPRC.PRCRateMatch = 0x50; break; // Rate /6
|
||||
case 0x04: MinxPRC.PRCRateMatch = 0x80; break; // Rate /9
|
||||
case 0x06: MinxPRC.PRCRateMatch = 0xB0; break; // Rate /12
|
||||
case 0x08: MinxPRC.PRCRateMatch = 0x10; break; // Rate /2
|
||||
case 0x0A: MinxPRC.PRCRateMatch = 0x30; break; // Rate /4
|
||||
case 0x0C: MinxPRC.PRCRateMatch = 0x50; break; // Rate /6
|
||||
case 0x0E: MinxPRC.PRCRateMatch = 0x70; break; // Rate /8
|
||||
}
|
||||
return;
|
||||
case 0x82: // PRC Map Tile Base Low
|
||||
PMR_PRC_MAP_LO = val & 0xF8;
|
||||
MinxPRC.PRCBGBase = (MinxPRC.PRCBGBase & 0x1FFF00) | PMR_PRC_MAP_LO;
|
||||
return;
|
||||
case 0x83: // PRC Map Tile Base Middle
|
||||
PMR_PRC_MAP_MID = val;
|
||||
MinxPRC.PRCBGBase = (MinxPRC.PRCBGBase & 0x1F00F8) | (PMR_PRC_MAP_MID << 8);
|
||||
return;
|
||||
case 0x84: // PRC Map Tile Base High
|
||||
PMR_PRC_MAP_HI = val & 0x1F;
|
||||
MinxPRC.PRCBGBase = (MinxPRC.PRCBGBase & 0x00FFF8) | (PMR_PRC_MAP_HI << 16);
|
||||
return;
|
||||
case 0x85: // PRC Map Vertical Scroll
|
||||
PMR_PRC_SCROLL_Y = val & 0x7F;
|
||||
if (PMR_PRC_SCROLL_Y <= (MinxPRC.PRCMapTH*8-64)) MinxPRC.PRCMapPY = PMR_PRC_SCROLL_Y;
|
||||
return;
|
||||
case 0x86: // PRC Map Horizontal Scroll
|
||||
PMR_PRC_SCROLL_X = val & 0x7F;
|
||||
if (PMR_PRC_SCROLL_X <= (MinxPRC.PRCMapTW*8-96)) MinxPRC.PRCMapPX = PMR_PRC_SCROLL_X;
|
||||
return;
|
||||
case 0x87: // PRC Sprite Tile Base Low
|
||||
PMR_PRC_SPR_LO = val & 0xC0;
|
||||
MinxPRC.PRCSprBase = (MinxPRC.PRCSprBase & 0x1FFF00) | PMR_PRC_SPR_LO;
|
||||
return;
|
||||
case 0x88: // PRC Sprite Tile Base Middle
|
||||
PMR_PRC_SPR_MID = val;
|
||||
MinxPRC.PRCSprBase = (MinxPRC.PRCSprBase & 0x1F00C0) | (PMR_PRC_SPR_MID << 8);
|
||||
return;
|
||||
case 0x89: // PRC Sprite Tile Base High
|
||||
PMR_PRC_SPR_HI = val & 0x1F;
|
||||
MinxPRC.PRCSprBase = (MinxPRC.PRCSprBase & 0x00FFC0) | (PMR_PRC_SPR_HI << 16);
|
||||
return;
|
||||
case 0x8A: // PRC Counter
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Default PRC Rendering
|
||||
//
|
||||
|
||||
static INLINE void MinxPRC_DrawSprite8x8_Mono(uint8_t cfg, int X, int Y, int DrawT, int MaskT)
|
||||
{
|
||||
int xC, xP, vaddr;
|
||||
uint8_t vdata, sdata, smask;
|
||||
uint8_t data;
|
||||
|
||||
// No point to proceed if it's offscreen
|
||||
if ((X < -7) || (X >= 96)) return;
|
||||
if ((Y < -7) || (Y >= 64)) return;
|
||||
|
||||
// Pre calculate
|
||||
vaddr = 0x1000 + ((Y >> 3) * 96) + X;
|
||||
|
||||
// Process top columns
|
||||
if (Y >= 0) {
|
||||
for (xC=0; xC<8; xC++) {
|
||||
if ((X >= 0) && (X < 96)) {
|
||||
xP = (cfg & 0x01) ? (7 - xC) : xC;
|
||||
|
||||
vdata = MinxPRC_OnRead(0, vaddr + xC);
|
||||
sdata = MinxPRC_OnRead(0, MinxPRC.PRCSprBase + (DrawT * 8) + xP);
|
||||
smask = MinxPRC_OnRead(0, MinxPRC.PRCSprBase + (MaskT * 8) + xP);
|
||||
|
||||
if (cfg & 0x02) {
|
||||
sdata = PRCInvertBit[sdata];
|
||||
smask = PRCInvertBit[smask];
|
||||
}
|
||||
if (cfg & 0x04) sdata = ~sdata;
|
||||
|
||||
data = vdata & ((smask << (Y & 7)) | (0xFF >> (8 - (Y & 7))));
|
||||
data |= (sdata & ~smask) << (Y & 7);
|
||||
|
||||
MinxPRC_OnWrite(0, vaddr + xC, data);
|
||||
}
|
||||
X++;
|
||||
}
|
||||
X -= 8;
|
||||
}
|
||||
|
||||
// Calculate new vaddr;
|
||||
vaddr += 96;
|
||||
|
||||
// Process bottom columns
|
||||
if ((Y < 56) && (Y & 7)) {
|
||||
for (xC=0; xC<8; xC++) {
|
||||
if ((X >= 0) && (X < 96)) {
|
||||
xP = (cfg & 0x01) ? (7 - xC) : xC;
|
||||
|
||||
vdata = MinxPRC_OnRead(0, vaddr + xC);
|
||||
sdata = MinxPRC_OnRead(0, MinxPRC.PRCSprBase + (DrawT * 8) + xP);
|
||||
smask = MinxPRC_OnRead(0, MinxPRC.PRCSprBase + (MaskT * 8) + xP);
|
||||
|
||||
if (cfg & 0x02) {
|
||||
sdata = PRCInvertBit[sdata];
|
||||
smask = PRCInvertBit[smask];
|
||||
}
|
||||
if (cfg & 0x04) sdata = ~sdata;
|
||||
|
||||
data = vdata & ((smask >> (8-(Y & 7))) | (0xFF << (Y & 7)));
|
||||
data |= (sdata & ~smask) >> (8-(Y & 7));
|
||||
|
||||
MinxPRC_OnWrite(0, vaddr + xC, data);
|
||||
}
|
||||
X++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MinxPRC_Render_Mono(void)
|
||||
{
|
||||
int xC, yC, tx, ty, ltileidxaddr, tileidxaddr, outaddr;
|
||||
int tiletopaddr = 0, tilebotaddr = 0;
|
||||
uint8_t data;
|
||||
|
||||
int SprTB, SprAddr;
|
||||
int SprX, SprY, SprC;
|
||||
int SprFX, SprFY;
|
||||
|
||||
if (PRCRenderBD) {
|
||||
for (xC=0x1000; xC<0x1300; xC++) MinxPRC_OnWrite(0, xC, 0x00);
|
||||
}
|
||||
|
||||
if ((PRCRenderBG) && (PMR_PRC_MODE & 0x02)) {
|
||||
outaddr = 0x1000;
|
||||
ltileidxaddr = -1;
|
||||
for (yC=0; yC<8; yC++) {
|
||||
ty = (yC << 3) + MinxPRC.PRCMapPY;
|
||||
for (xC=0; xC<96; xC++) {
|
||||
tx = xC + MinxPRC.PRCMapPX;
|
||||
tileidxaddr = 0x1360 + (ty >> 3) * MinxPRC.PRCMapTW + (tx >> 3);
|
||||
|
||||
// Read tile index
|
||||
if (ltileidxaddr != tileidxaddr) {
|
||||
tiletopaddr = MinxPRC.PRCBGBase + (MinxPRC_OnRead(0, tileidxaddr) * 8);
|
||||
tilebotaddr = MinxPRC.PRCBGBase + (MinxPRC_OnRead(0, tileidxaddr + MinxPRC.PRCMapTW) * 8);
|
||||
ltileidxaddr = tileidxaddr;
|
||||
}
|
||||
|
||||
// Read tile data
|
||||
data = (MinxPRC_OnRead(0, tiletopaddr + (tx & 7)) >> (ty & 7))
|
||||
| (MinxPRC_OnRead(0, tilebotaddr + (tx & 7)) << (8 - (ty & 7)));
|
||||
|
||||
// Write to VRAM
|
||||
MinxPRC_OnWrite(0, outaddr++, (PMR_PRC_MODE & 0x01) ? ~data : data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((PRCRenderSpr) && (PMR_PRC_MODE & 0x04)) {
|
||||
SprAddr = 0x1300 + (24 * 4);
|
||||
do {
|
||||
SprC = MinxPRC_OnRead(0, --SprAddr);
|
||||
SprTB = MinxPRC_OnRead(0, --SprAddr) * 8;
|
||||
SprY = (MinxPRC_OnRead(0, --SprAddr) & 0x7F) - 16;
|
||||
SprX = (MinxPRC_OnRead(0, --SprAddr) & 0x7F) - 16;
|
||||
if (SprC & 0x08) {
|
||||
SprFX = SprC & 0x01 ? 8 : 0;
|
||||
SprFY = SprC & 0x02 ? 8 : 0;
|
||||
MinxPRC_DrawSprite8x8_Mono(SprC, SprX + SprFX, SprY + SprFY, SprTB+2, SprTB);
|
||||
MinxPRC_DrawSprite8x8_Mono(SprC, SprX + SprFX, SprY + 8 - SprFY, SprTB+3, SprTB+1);
|
||||
MinxPRC_DrawSprite8x8_Mono(SprC, SprX + 8 - SprFX, SprY + SprFY, SprTB+6, SprTB+4);
|
||||
MinxPRC_DrawSprite8x8_Mono(SprC, SprX + 8 - SprFX, SprY + 8 - SprFY, SprTB+7, SprTB+5);
|
||||
}
|
||||
} while (SprAddr > 0x1300);
|
||||
}
|
||||
}
|
||||
|
||||
void MinxPRC_CopyToLCD(void)
|
||||
{
|
||||
MinxLCD_LCDWritefb(MinxPRC_LCDfb);
|
||||
/*
|
||||
// Can't be used with the new color mode support for LCD
|
||||
int i, j;
|
||||
MinxLCD_LCDWriteCtrl(0xEE);
|
||||
for (i=0; i<8; i++) {
|
||||
MinxLCD_LCDWriteCtrl(0xB0 + i);
|
||||
MinxLCD_LCDWriteCtrl(0x00);
|
||||
MinxLCD_LCDWriteCtrl(0x10);
|
||||
for (j=0; j<96; j++) {
|
||||
MinxLCD_LCDWrite(MinxPRC_OnRead(0, 0x1000 + (i * 96) + j));
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MINXHW_PRC
|
||||
#define MINXHW_PRC
|
||||
|
||||
#include <stdint.h>
|
||||
#include <streams/memory_stream.h>
|
||||
|
||||
typedef struct {
|
||||
// Internal processing
|
||||
int32_t PRCCnt; // PRC Counter 8.24 (Need signed)
|
||||
uint32_t PRCBGBase; // PRC Map Tile Base
|
||||
uint32_t PRCSprBase; // PRC Sprite Base
|
||||
uint8_t PRCMode; // PRC Mode (0 = Off, 1 = Copy, 3 = BG+Spr+Copy)
|
||||
uint8_t PRCRateMatch; // PRC Rate Match
|
||||
uint8_t PRCMapPX; // PRC Map X (Pixels)
|
||||
uint8_t PRCMapPY; // PRC Map Y (Pixels)
|
||||
uint8_t PRCMapTW; // PRC Map Width (Tiles)
|
||||
uint8_t PRCMapTH; // PRC Map Height (Tiles)
|
||||
uint8_t PRCState; // PRC State
|
||||
} TMinxPRC;
|
||||
|
||||
typedef void (*TMinxPRC_Render)(void);
|
||||
|
||||
// Export PRC state
|
||||
extern TMinxPRC MinxPRC;
|
||||
|
||||
// Invert bit table
|
||||
extern const uint8_t PRCInvertBit[256];
|
||||
|
||||
// Stall CPU
|
||||
extern int PRCAllowStall;
|
||||
extern int StallCPU;
|
||||
extern int StallCycles;
|
||||
|
||||
// Render backdrop? (Background overrides backdrop)
|
||||
extern int PRCRenderBD;
|
||||
// Render background?
|
||||
extern int PRCRenderBG;
|
||||
// Render sprites?
|
||||
extern int PRCRenderSpr;
|
||||
|
||||
// Render callback
|
||||
extern TMinxPRC_Render MinxPRC_Render;
|
||||
|
||||
enum {
|
||||
MINX_INTR_03 = 0x03, // PRC Copy Complete
|
||||
MINX_INTR_04 = 0x04 // PRC Frame Divider Overflow
|
||||
};
|
||||
|
||||
// Aproximate value of PRC Timer (~4678 Hz) (16M / ( 4M / 855 ))
|
||||
#define MINX_PRCTIMERINC (16777216/855)
|
||||
|
||||
|
||||
int MinxPRC_Create(void);
|
||||
|
||||
void MinxPRC_Destroy(void);
|
||||
|
||||
void MinxPRC_Reset(int hardreset);
|
||||
|
||||
int MinxPRC_LoadStateStream(memstream_t *stream, uint32_t bsize);
|
||||
|
||||
int MinxPRC_SaveStateStream(memstream_t *stream);
|
||||
|
||||
void MinxPRC_Sync(void);
|
||||
|
||||
uint8_t MinxPRC_ReadReg(uint8_t reg);
|
||||
|
||||
void MinxPRC_WriteReg(uint8_t reg, uint8_t val);
|
||||
|
||||
//
|
||||
// Internals
|
||||
//
|
||||
|
||||
void MinxPRC_Render_Mono(void);
|
||||
|
||||
void MinxPRC_CopyToLCD(void);
|
||||
|
||||
//
|
||||
// Callbacks (Written by the user)
|
||||
//
|
||||
|
||||
void MinxPRC_On72HzRefresh(int render);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,691 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PokeMini.h"
|
||||
|
||||
TMinxTimers MinxTimers;
|
||||
|
||||
// Calculate decrease on oscillator 1
|
||||
const uint32_t MinxTimers_CalculateDecOsc1[16] = {
|
||||
// Osci1 disabled
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
// Osci1 Enabled
|
||||
(16777216/2), // 2000000 Hz
|
||||
(16777216/8), // 500000 Hz
|
||||
(16777216/32), // 125000 Hz
|
||||
(16777216/64), // 62500 Hz
|
||||
(16777216/128), // 31250 Hz
|
||||
(16777216/256), // 15625 Hz
|
||||
(16777216/1024), // 3906.25 Hz
|
||||
(16777216/4096), // 976.5625 Hz
|
||||
};
|
||||
|
||||
// Calculate decrease on oscillator 2
|
||||
const uint32_t MinxTimers_CalculateDecOsc2[16] = {
|
||||
// Osci2 disabled
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
// Osci2 Enabled (Aproximate values)
|
||||
(16777216/122), // 32768 Hz
|
||||
(16777216/244), // 16384 Hz
|
||||
(16777216/488), // 8192 Hz
|
||||
(16777216/977), // 4096 Hz
|
||||
(16777216/1953), // 2048 Hz
|
||||
(16777216/3906), // 1024 Hz
|
||||
(16777216/7812), // 512 Hz
|
||||
(16777216/15625) // 256 Hz
|
||||
};
|
||||
|
||||
// Timers counting frequency table
|
||||
const uint32_t MinxTimers_CountFreq[32] = {
|
||||
// Osci1 disabled
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
// Osci1 Enabled
|
||||
(4000000/2), (4000000/8), (4000000/32), (4000000/64),
|
||||
(4000000/128), (4000000/256), (4000000/1024), (4000000/4096),
|
||||
// Osci2 disabled
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
// Osci2 Enabled
|
||||
(32768/1), (32768/2), (32768/4), (32768/8),
|
||||
(32768/16), (32768/32), (32768/64), (32768/128)
|
||||
};
|
||||
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
|
||||
int MinxTimers_Create(void)
|
||||
{
|
||||
// Reset
|
||||
memset((void *)&MinxTimers, 0, sizeof(TMinxTimers));
|
||||
MinxTimers_Reset(1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MinxTimers_Destroy(void)
|
||||
{
|
||||
}
|
||||
|
||||
void MinxTimers_Reset(int hardreset)
|
||||
{
|
||||
if (hardreset) {
|
||||
// Init state
|
||||
memset((void *)&MinxTimers, 0, sizeof(TMinxTimers));
|
||||
}
|
||||
|
||||
// Init variables
|
||||
MinxTimers.Tmr1PreA = 0xFFFFFFFF;
|
||||
MinxTimers.Tmr1PreB = 0xFFFFFFFF;
|
||||
MinxTimers.Tmr2PreA = 0xFFFFFFFF;
|
||||
MinxTimers.Tmr2PreB = 0xFFFFFFFF;
|
||||
MinxTimers.Tmr3PreA = 0xFFFFFFFF;
|
||||
MinxTimers.Tmr3PreB = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
int MinxTimers_LoadStateStream(memstream_t *stream, uint32_t bsize)
|
||||
{
|
||||
POKELOADSS_START(128);
|
||||
POKELOADSS_STREAM_32(MinxTimers.SecTimerCnt);
|
||||
POKELOADSS_STREAM_32(MinxTimers.TmrSecs);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr1DecA);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr1DecB);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr1CntA);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr1CntB);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr1PreA);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr1PreB);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr2DecA);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr2DecB);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr2CntA);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr2CntB);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr2PreA);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr2PreB);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr3DecA);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr3DecB);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr3CntA);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr3CntB);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr3PreA);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr3PreB);
|
||||
POKELOADSS_STREAM_32(MinxTimers.Tmr8Cnt);
|
||||
POKELOADSS_STREAM_32(MinxTimers.PRCCnt);
|
||||
POKELOADSS_STREAM_16(MinxTimers.Tmr3Cnt16.W);
|
||||
POKELOADSS_STREAM_16(MinxTimers.Timer3Piv);
|
||||
POKELOADSS_STREAM_8(MinxTimers.TmrXEna2);
|
||||
POKELOADSS_STREAM_8(MinxTimers.TmrXEna1);
|
||||
POKELOADSS_STREAM_X(34);
|
||||
MinxTimers.Tmr1WMode = PMR_TMR1_CTRL_L & 0x80;
|
||||
MinxTimers.Tmr1LEna = PMR_TMR1_CTRL_L & 0x04;
|
||||
MinxTimers.Tmr1HEna = PMR_TMR1_CTRL_H & 0x04;
|
||||
MinxTimers.Tmr2WMode = PMR_TMR2_CTRL_L & 0x80;
|
||||
MinxTimers.Tmr2LEna = PMR_TMR2_CTRL_L & 0x04;
|
||||
MinxTimers.Tmr2HEna = PMR_TMR2_CTRL_H & 0x04;
|
||||
MinxTimers.Tmr3WMode = PMR_TMR3_CTRL_L & 0x80;
|
||||
MinxTimers.Tmr3LEna = PMR_TMR3_CTRL_L & 0x04;
|
||||
MinxTimers.Tmr3HEna = PMR_TMR3_CTRL_H & 0x04;
|
||||
POKELOADSS_END(128);
|
||||
}
|
||||
|
||||
int MinxTimers_SaveStateStream(memstream_t *stream)
|
||||
{
|
||||
POKESAVESS_STREAM_START(128);
|
||||
POKESAVESS_STREAM_32(MinxTimers.SecTimerCnt);
|
||||
POKESAVESS_STREAM_32(MinxTimers.TmrSecs);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr1DecA);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr1DecB);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr1CntA);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr1CntB);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr1PreA);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr1PreB);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr2DecA);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr2DecB);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr2CntA);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr2CntB);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr2PreA);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr2PreB);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr3DecA);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr3DecB);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr3CntA);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr3CntB);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr3PreA);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr3PreB);
|
||||
POKESAVESS_STREAM_32(MinxTimers.Tmr8Cnt);
|
||||
POKESAVESS_STREAM_32(MinxTimers.PRCCnt);
|
||||
POKESAVESS_STREAM_16(MinxTimers.Tmr3Cnt16.W);
|
||||
POKESAVESS_STREAM_16(MinxTimers.Timer3Piv);
|
||||
POKESAVESS_STREAM_8(MinxTimers.TmrXEna2);
|
||||
POKESAVESS_STREAM_8(MinxTimers.TmrXEna1);
|
||||
POKESAVESS_STREAM_X(34);
|
||||
POKESAVESS_END(128);
|
||||
}
|
||||
|
||||
void MinxTimers_Sync(void)
|
||||
{
|
||||
register uint32_t PreCount;
|
||||
|
||||
// Process 256Hz Timer (Increment)
|
||||
if (PMR_TMR256_CTRL) {
|
||||
PreCount = MinxTimers.Tmr8Cnt;
|
||||
MinxTimers.Tmr8Cnt += MINX_TIMER256INC * PokeHWCycles;
|
||||
if ((PreCount & 0x08000000) ^ (MinxTimers.Tmr8Cnt & 0x08000000)) {
|
||||
// 32Hz
|
||||
MinxCPU_OnIRQAct(MINX_INTR_0B);
|
||||
}
|
||||
if ((PreCount & 0x20000000) ^ (MinxTimers.Tmr8Cnt & 0x20000000)) {
|
||||
// 8Hz
|
||||
MinxCPU_OnIRQAct(MINX_INTR_0C);
|
||||
}
|
||||
if ((PreCount & 0x80000000) ^ (MinxTimers.Tmr8Cnt & 0x80000000)) {
|
||||
// 2Hz
|
||||
MinxCPU_OnIRQAct(MINX_INTR_0D);
|
||||
}
|
||||
if (PreCount > MinxTimers.Tmr8Cnt) {
|
||||
// 1Hz
|
||||
MinxCPU_OnIRQAct(MINX_INTR_0E);
|
||||
}
|
||||
}
|
||||
|
||||
// Process Second Timer (Increment)
|
||||
if (PMR_SEC_CTRL) {
|
||||
MinxTimers.TmrSecs += PokeHWCycles;
|
||||
if (MinxTimers.TmrSecs >= 4000000) {
|
||||
MinxTimers.SecTimerCnt++;
|
||||
MinxTimers.TmrSecs -= 4000000;
|
||||
}
|
||||
}
|
||||
|
||||
// Process Timer 1 (Decrement)
|
||||
if (MinxTimers.Tmr1WMode) {
|
||||
// 1x 16-Bits Timer
|
||||
if (MinxTimers.Tmr1LEna) {
|
||||
PreCount = MinxTimers.Tmr1CntA;
|
||||
MinxTimers.Tmr1CntA -= MinxTimers.Tmr1DecA * PokeHWCycles;
|
||||
if (PreCount < MinxTimers.Tmr1CntA) {
|
||||
PreCount = MinxTimers.Tmr1CntB;
|
||||
MinxTimers.Tmr1CntB -= 0x01000000;
|
||||
if (PreCount < MinxTimers.Tmr1CntB) {
|
||||
MinxTimers.Tmr1CntA = MinxTimers.Tmr1PreA;
|
||||
MinxTimers.Tmr1CntB = MinxTimers.Tmr1PreB;
|
||||
// IRQ Timer 1-Hi underflow
|
||||
MinxCPU_OnIRQAct(MINX_INTR_07);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 2x 8-Bits Timers
|
||||
if (MinxTimers.Tmr1LEna) {
|
||||
// Timer Lo
|
||||
PreCount = MinxTimers.Tmr1CntA;
|
||||
MinxTimers.Tmr1CntA -= MinxTimers.Tmr1DecA * PokeHWCycles;
|
||||
if (PreCount < MinxTimers.Tmr1CntA) {
|
||||
MinxTimers.Tmr1CntA = MinxTimers.Tmr1PreA;
|
||||
// IRQ Timer 1-Lo underflow
|
||||
MinxCPU_OnIRQAct(MINX_INTR_08);
|
||||
}
|
||||
}
|
||||
if (MinxTimers.Tmr1HEna) {
|
||||
// Timer Hi
|
||||
PreCount = MinxTimers.Tmr1CntB;
|
||||
MinxTimers.Tmr1CntB -= MinxTimers.Tmr1DecB * PokeHWCycles;
|
||||
if (PreCount < MinxTimers.Tmr1CntB) {
|
||||
MinxTimers.Tmr1CntB = MinxTimers.Tmr1PreB;
|
||||
// IRQ Timer 1-Hi underflow
|
||||
MinxCPU_OnIRQAct(MINX_INTR_07);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process Timer 2 (Decrement)
|
||||
if (MinxTimers.Tmr2WMode) {
|
||||
// 1x 16-Bits Timer
|
||||
if (MinxTimers.Tmr2LEna) {
|
||||
PreCount = MinxTimers.Tmr2CntA;
|
||||
MinxTimers.Tmr2CntA -= MinxTimers.Tmr2DecA * PokeHWCycles;
|
||||
if (PreCount < MinxTimers.Tmr2CntA) {
|
||||
PreCount = MinxTimers.Tmr2CntB;
|
||||
MinxTimers.Tmr2CntB -= 0x01000000;
|
||||
if (PreCount < MinxTimers.Tmr2CntB) {
|
||||
MinxTimers.Tmr2CntA = MinxTimers.Tmr2PreA;
|
||||
MinxTimers.Tmr2CntB = MinxTimers.Tmr2PreB;
|
||||
// IRQ Timer 2-Hi underflow
|
||||
MinxCPU_OnIRQAct(MINX_INTR_05);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 2x 8-Bits Timers
|
||||
if (MinxTimers.Tmr2LEna) {
|
||||
// Timer Lo
|
||||
PreCount = MinxTimers.Tmr2CntA;
|
||||
MinxTimers.Tmr2CntA -= MinxTimers.Tmr2DecA * PokeHWCycles;
|
||||
if (PreCount < MinxTimers.Tmr2CntA) {
|
||||
MinxTimers.Tmr2CntA = MinxTimers.Tmr2PreA;
|
||||
// IRQ Timer 2-Lo underflow
|
||||
MinxCPU_OnIRQAct(MINX_INTR_06);
|
||||
}
|
||||
}
|
||||
if (MinxTimers.Tmr2HEna) {
|
||||
// Timer Hi
|
||||
PreCount = MinxTimers.Tmr2CntB;
|
||||
MinxTimers.Tmr2CntB -= MinxTimers.Tmr2DecB * PokeHWCycles;
|
||||
if (PreCount < MinxTimers.Tmr2CntB) {
|
||||
MinxTimers.Tmr2CntB = MinxTimers.Tmr2PreB;
|
||||
// IRQ Timer 2-Hi underflow
|
||||
MinxCPU_OnIRQAct(MINX_INTR_05);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process Timer 3 (Decrement)
|
||||
if (MinxTimers.Tmr3WMode) {
|
||||
// 1x 16-Bits Timer
|
||||
if (MinxTimers.Tmr3LEna) {
|
||||
PreCount = MinxTimers.Tmr3CntA;
|
||||
MinxTimers.Tmr3CntA -= MinxTimers.Tmr3DecA * PokeHWCycles;
|
||||
if (PreCount < MinxTimers.Tmr3CntA) {
|
||||
PreCount = MinxTimers.Tmr3CntB;
|
||||
MinxTimers.Tmr3CntB -= 0x01000000;
|
||||
if (PreCount < MinxTimers.Tmr3CntB) {
|
||||
MinxTimers.Tmr3CntA = MinxTimers.Tmr3PreA;
|
||||
MinxTimers.Tmr3CntB = MinxTimers.Tmr3PreB;
|
||||
// IRQ Timer 3 underflow
|
||||
MinxCPU_OnIRQAct(MINX_INTR_09);
|
||||
}
|
||||
MinxTimers.Tmr3Cnt16.B.H = MinxTimers.Tmr3CntB >> 24;
|
||||
}
|
||||
// Check pivot
|
||||
PreCount = MinxTimers.Tmr3Cnt16.W;
|
||||
MinxTimers.Tmr3Cnt16.B.L = MinxTimers.Tmr3CntA >> 24;
|
||||
if ((PreCount > MinxTimers.Timer3Piv) && (MinxTimers.Tmr3Cnt16.W <= MinxTimers.Timer3Piv)) {
|
||||
// IRQ Timer 3 Pivot
|
||||
MinxCPU_OnIRQAct(MINX_INTR_0A);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 2x 8-Bits Timers
|
||||
if (MinxTimers.Tmr3LEna) {
|
||||
// Timer Lo
|
||||
PreCount = MinxTimers.Tmr3CntA;
|
||||
MinxTimers.Tmr3CntA -= MinxTimers.Tmr3DecA * PokeHWCycles; // Osci2
|
||||
if (PreCount < MinxTimers.Tmr3CntA) {
|
||||
MinxTimers.Tmr3CntA = MinxTimers.Tmr3PreA;
|
||||
}
|
||||
MinxTimers.Tmr3Cnt16.B.L = MinxTimers.Tmr3CntA >> 24;
|
||||
}
|
||||
if (MinxTimers.Tmr3HEna) {
|
||||
// Timer Hi
|
||||
PreCount = MinxTimers.Tmr3CntB;
|
||||
MinxTimers.Tmr3CntB -= MinxTimers.Tmr3DecB * PokeHWCycles; // Osci2
|
||||
if (PreCount < MinxTimers.Tmr3CntB) {
|
||||
MinxTimers.Tmr3CntB = MinxTimers.Tmr3PreB;
|
||||
// IRQ Timer 3 underflow
|
||||
MinxCPU_OnIRQAct(MINX_INTR_09);
|
||||
}
|
||||
// Check pivot
|
||||
PreCount = MinxTimers.Tmr3Cnt16.W;
|
||||
MinxTimers.Tmr3Cnt16.B.H = MinxTimers.Tmr3CntB >> 24;
|
||||
if ((PreCount > MinxTimers.Timer3Piv) && (MinxTimers.Tmr3Cnt16.W <= MinxTimers.Timer3Piv)) {
|
||||
// IRQ Timer 3 Pivot
|
||||
MinxCPU_OnIRQAct(MINX_INTR_0A);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MinxTimers_ReadReg(uint8_t reg)
|
||||
{
|
||||
// 0x08 to 0x0F, 0x18 to 0x1F, 0x30 to 0x41, 0x48 to 0x4F
|
||||
switch(reg) {
|
||||
case 0x08: // Second Counter Control
|
||||
return PMR_SEC_CTRL & 0x01;
|
||||
case 0x09: // Second Counter Low
|
||||
return (uint8_t)MinxTimers.SecTimerCnt;
|
||||
case 0x0A: // Second Counter Med
|
||||
return (uint8_t)(MinxTimers.SecTimerCnt >> 8);
|
||||
case 0x0B: // Second Counter High
|
||||
return (uint8_t)(MinxTimers.SecTimerCnt >> 16);
|
||||
case 0x18: // Timer 1 Prescaler
|
||||
return PMR_TMR1_SCALE;
|
||||
case 0x19: // Timer 1 Osc. Select + Osc. Enable
|
||||
return PMR_TMR1_ENA_OSC & 0x33;
|
||||
case 0x1A: // Timer 2 Prescaler
|
||||
return PMR_TMR2_SCALE;
|
||||
case 0x1B: // Timer 2 Osc. Select
|
||||
return PMR_TMR2_OSC & 0x03;
|
||||
case 0x1C: // Timer 3 Prescaler
|
||||
return PMR_TMR3_SCALE;
|
||||
case 0x1D: // Timer 3 Osc. Select
|
||||
return PMR_TMR3_OSC & 0x03;
|
||||
case 0x30: // Timer 1 Control A
|
||||
if (PMR_TMR1_CTRL_L & 0x80) {
|
||||
return PMR_TMR1_CTRL_L & 0x85; // 16-Bits
|
||||
} else {
|
||||
return PMR_TMR1_CTRL_L & 0x0D; // 8-Bits Mode
|
||||
}
|
||||
case 0x31: // Timer 1 Control B
|
||||
if (PMR_TMR1_CTRL_L & 0x80) {
|
||||
return PMR_TMR1_CTRL_H & 0x08; // 16-Bits Mode
|
||||
} else {
|
||||
return PMR_TMR1_CTRL_H & 0x0D; // 8-Bits Mode
|
||||
}
|
||||
case 0x32: // Timer 1 Preset A
|
||||
return (uint8_t)(MinxTimers.Tmr1PreA >> 24);
|
||||
case 0x33: // Timer 1 Preset B
|
||||
return (uint8_t)(MinxTimers.Tmr1PreB >> 24);
|
||||
case 0x34: // Timer 1 Pivot A
|
||||
return PMR_TMR1_PVT_L;
|
||||
case 0x35: // Timer 1 Pivot B
|
||||
return PMR_TMR1_PVT_H;
|
||||
case 0x36: // Timer 1 Count A
|
||||
return (uint8_t)(MinxTimers.Tmr1CntA >> 24);
|
||||
case 0x37: // Timer 1 Count B
|
||||
return (uint8_t)(MinxTimers.Tmr1CntB >> 24);
|
||||
case 0x38: // Timer 2 Control A
|
||||
if (PMR_TMR2_CTRL_L & 0x80) {
|
||||
return PMR_TMR2_CTRL_L & 0x85; // 16-Bits
|
||||
} else {
|
||||
return PMR_TMR2_CTRL_L & 0x0D; // 8-Bits Mode
|
||||
}
|
||||
case 0x39: // Timer 2 Control B
|
||||
if (PMR_TMR2_CTRL_L & 0x80) {
|
||||
return PMR_TMR2_CTRL_H & 0x08; // 16-Bits Mode
|
||||
} else {
|
||||
return PMR_TMR2_CTRL_H & 0x0D; // 8-Bits Mode
|
||||
}
|
||||
case 0x3A: // Timer 2 Preset A
|
||||
return (uint8_t)(MinxTimers.Tmr2PreA >> 24);
|
||||
case 0x3B: // Timer 2 Preset B
|
||||
return (uint8_t)(MinxTimers.Tmr2PreB >> 24);
|
||||
case 0x3C: // Timer 2 Pivot A
|
||||
return PMR_TMR2_PVT_L;
|
||||
case 0x3D: // Timer 2 Pivot B
|
||||
return PMR_TMR2_PVT_H;
|
||||
case 0x3E: // Timer 2 Count A
|
||||
return (uint8_t)(MinxTimers.Tmr2CntA >> 24);
|
||||
case 0x3F: // Timer 2 Count B
|
||||
return (uint8_t)(MinxTimers.Tmr2CntB >> 24);
|
||||
case 0x40: // 256 Hz Timer Control
|
||||
return PMR_TMR256_CTRL;
|
||||
case 0x41: // 256 Hz Timer Counter
|
||||
return MinxTimers.Tmr8Cnt >> 24;
|
||||
case 0x48: // Timer 3 Control A
|
||||
if (PMR_TMR3_CTRL_L & 0x80) {
|
||||
return PMR_TMR3_CTRL_L & 0x85; // 16-Bits
|
||||
} else {
|
||||
return PMR_TMR3_CTRL_L & 0x0D; // 8-Bits Mode
|
||||
}
|
||||
case 0x49: // Timer 3 Control B
|
||||
if (PMR_TMR3_CTRL_L & 0x80) {
|
||||
return PMR_TMR3_CTRL_H & 0x08; // 16-Bits Mode
|
||||
} else {
|
||||
return PMR_TMR3_CTRL_H & 0x0D; // 8-Bits Mode
|
||||
}
|
||||
case 0x4A: // Timer 3 Preset A
|
||||
return (uint8_t)(MinxTimers.Tmr3PreA >> 24);
|
||||
case 0x4B: // Timer 3 Preset B
|
||||
return (uint8_t)(MinxTimers.Tmr3PreB >> 24);
|
||||
case 0x4C: // Timer 3 Pivot A
|
||||
return (uint8_t)MinxTimers.Timer3Piv;
|
||||
case 0x4D: // Timer 3 Pivot B
|
||||
return (uint8_t)(MinxTimers.Timer3Piv >> 8);
|
||||
case 0x4E: // Timer 3 Count A
|
||||
return (uint8_t)(MinxTimers.Tmr3CntA >> 24);
|
||||
case 0x4F: // Timer 3 Count B
|
||||
return (uint8_t)(MinxTimers.Tmr3CntB >> 24);
|
||||
default: // Unused
|
||||
return reg;
|
||||
}
|
||||
}
|
||||
|
||||
#define MinxTimers_UpdateScalarTimer1() { \
|
||||
if (PMR_TMR1_ENA_OSC & 0x01) { \
|
||||
if (MinxTimers.TmrXEna2) MinxTimers.Tmr1DecA = MinxTimers_CalculateDecOsc2[(PMR_TMR1_SCALE & 0xF)]; \
|
||||
else MinxTimers.Tmr1DecA = 0; \
|
||||
} else { \
|
||||
if (MinxTimers.TmrXEna1) MinxTimers.Tmr1DecA = MinxTimers_CalculateDecOsc1[(PMR_TMR1_SCALE & 0xF)]; \
|
||||
else MinxTimers.Tmr1DecA = 0; \
|
||||
} \
|
||||
if (PMR_TMR1_ENA_OSC & 0x02) { \
|
||||
if (MinxTimers.TmrXEna2) MinxTimers.Tmr1DecB = MinxTimers_CalculateDecOsc2[((PMR_TMR1_SCALE >> 4) & 0xF)]; \
|
||||
else MinxTimers.Tmr1DecB = 0; \
|
||||
} else { \
|
||||
if (MinxTimers.TmrXEna1) MinxTimers.Tmr1DecB = MinxTimers_CalculateDecOsc1[((PMR_TMR1_SCALE >> 4) & 0xF)]; \
|
||||
else MinxTimers.Tmr1DecB = 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define MinxTimers_UpdateScalarTimer2() { \
|
||||
if (PMR_TMR2_OSC & 0x01) { \
|
||||
if (MinxTimers.TmrXEna2) MinxTimers.Tmr2DecA = MinxTimers_CalculateDecOsc2[(PMR_TMR2_SCALE & 0xF)]; \
|
||||
else MinxTimers.Tmr2DecA = 0; \
|
||||
} else { \
|
||||
if (MinxTimers.TmrXEna1) MinxTimers.Tmr2DecA = MinxTimers_CalculateDecOsc1[(PMR_TMR2_SCALE & 0xF)]; \
|
||||
else MinxTimers.Tmr2DecA = 0; \
|
||||
} \
|
||||
if (PMR_TMR2_OSC & 0x02) { \
|
||||
if (MinxTimers.TmrXEna2) MinxTimers.Tmr2DecB = MinxTimers_CalculateDecOsc2[((PMR_TMR2_SCALE >> 4) & 0xF)]; \
|
||||
else MinxTimers.Tmr2DecB = 0; \
|
||||
} else { \
|
||||
if (MinxTimers.TmrXEna1) MinxTimers.Tmr2DecB = MinxTimers_CalculateDecOsc1[((PMR_TMR2_SCALE >> 4) & 0xF)]; \
|
||||
else MinxTimers.Tmr2DecB = 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define MinxTimers_UpdateScalarTimer3() { \
|
||||
if (PMR_TMR3_OSC & 0x01) { \
|
||||
if (MinxTimers.TmrXEna2) MinxTimers.Tmr3DecA = MinxTimers_CalculateDecOsc2[(PMR_TMR3_SCALE & 0xF)]; \
|
||||
else MinxTimers.Tmr3DecA = 0; \
|
||||
} else { \
|
||||
if (MinxTimers.TmrXEna1) MinxTimers.Tmr3DecA = MinxTimers_CalculateDecOsc1[(PMR_TMR3_SCALE & 0xF)]; \
|
||||
else MinxTimers.Tmr3DecA = 0; \
|
||||
} \
|
||||
if (PMR_TMR3_OSC & 0x02) { \
|
||||
if (MinxTimers.TmrXEna2) MinxTimers.Tmr3DecB = MinxTimers_CalculateDecOsc2[((PMR_TMR3_SCALE >> 4) & 0xF)]; \
|
||||
else MinxTimers.Tmr3DecB = 0; \
|
||||
} else { \
|
||||
if (MinxTimers.TmrXEna1) MinxTimers.Tmr3DecB = MinxTimers_CalculateDecOsc1[((PMR_TMR3_SCALE >> 4) & 0xF)]; \
|
||||
else MinxTimers.Tmr3DecB = 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
void MinxTimers_WriteReg(unsigned char reg, unsigned char val)
|
||||
{
|
||||
// 0x08 to 0x0F, 0x18 to 0x1F, 0x30 to 0x41, 0x48 to 0x4F
|
||||
switch(reg) {
|
||||
case 0x08: // Second Counter Control
|
||||
if (val & 0x02) MinxTimers.SecTimerCnt = 0x000000;
|
||||
PMR_SEC_CTRL = val & 0x01;
|
||||
return;
|
||||
case 0x09: // Second Counter Low
|
||||
case 0x0A: // Second Counter Med
|
||||
case 0x0B: // Second Counter High
|
||||
return;
|
||||
case 0x18: // Timer 1 Prescaler
|
||||
PMR_TMR1_SCALE = val;
|
||||
MinxTimers_UpdateScalarTimer1();
|
||||
return;
|
||||
case 0x19: // Timer 1 Osc. Select + Osc. Enable
|
||||
PMR_TMR1_ENA_OSC = val & 0x33;
|
||||
MinxTimers.TmrXEna2 = val & 0x10;
|
||||
MinxTimers.TmrXEna1 = val & 0x20;
|
||||
MinxTimers_UpdateScalarTimer1();
|
||||
MinxTimers_UpdateScalarTimer2(); // Because of the TmrXEna#
|
||||
MinxTimers_UpdateScalarTimer3(); // Because of the TmrXEna#
|
||||
return;
|
||||
case 0x1A: // Timer 2 Prescaler
|
||||
PMR_TMR2_SCALE = val;
|
||||
MinxTimers_UpdateScalarTimer2();
|
||||
return;
|
||||
case 0x1B: // Timer 2 Osc. Select
|
||||
PMR_TMR2_OSC = val & 0x03;
|
||||
MinxTimers_UpdateScalarTimer2();
|
||||
return;
|
||||
case 0x1C: // Timer 3 Prescaler
|
||||
PMR_TMR3_SCALE = val;
|
||||
MinxTimers_UpdateScalarTimer3();
|
||||
return;
|
||||
case 0x1D: // Timer 3 Osc. Select
|
||||
PMR_TMR3_OSC = val & 0x03;
|
||||
MinxTimers_UpdateScalarTimer3();
|
||||
return;
|
||||
case 0x30: // Timer 1 Control A
|
||||
PMR_TMR1_CTRL_L = val & 0x8D;
|
||||
MinxTimers.Tmr1LEna = val & 0x04;
|
||||
if (PMR_TMR1_CTRL_L & 0x80) {
|
||||
// 16-Bits
|
||||
MinxTimers.Tmr1WMode = 1;
|
||||
if (val & 0x02) {
|
||||
MinxTimers.Tmr1CntA = MinxTimers.Tmr1PreA;
|
||||
MinxTimers.Tmr1CntB = MinxTimers.Tmr1PreB;
|
||||
}
|
||||
} else {
|
||||
// 8-Bits
|
||||
MinxTimers.Tmr1WMode = 0;
|
||||
if (val & 0x02) {
|
||||
MinxTimers.Tmr1CntA = MinxTimers.Tmr1PreA;
|
||||
}
|
||||
}
|
||||
return;
|
||||
case 0x31: // Timer 1 Control B
|
||||
PMR_TMR1_CTRL_H = val & 0x0D;
|
||||
MinxTimers.Tmr1HEna = val & 0x04;
|
||||
if (PMR_TMR1_CTRL_L & 0x80) {
|
||||
// 16-Bits, unused
|
||||
} else {
|
||||
// 8-Bits
|
||||
if (val & 0x02) {
|
||||
MinxTimers.Tmr1CntB = MinxTimers.Tmr1PreB;
|
||||
}
|
||||
}
|
||||
return;
|
||||
case 0x32: // Timer 1 Preset A
|
||||
MinxTimers.Tmr1PreA = val << 24;
|
||||
return;
|
||||
case 0x33: // Timer 1 Preset B
|
||||
MinxTimers.Tmr1PreB = val << 24;
|
||||
return;
|
||||
case 0x34: // Timer 1 Pivot A
|
||||
PMR_TMR1_PVT_L = val;
|
||||
return;
|
||||
case 0x35: // Timer 1 Pivot B
|
||||
PMR_TMR1_PVT_H = val;
|
||||
return;
|
||||
case 0x36: // Timer 1 Count A
|
||||
return;
|
||||
case 0x37: // Timer 1 Count B
|
||||
return;
|
||||
case 0x38: // Timer 2 Control A
|
||||
PMR_TMR2_CTRL_L = val & 0x8D;
|
||||
MinxTimers.Tmr2LEna = val & 0x04;
|
||||
if (PMR_TMR2_CTRL_L & 0x80) {
|
||||
// 16-Bits
|
||||
MinxTimers.Tmr2WMode = 1;
|
||||
if (val & 0x02) {
|
||||
MinxTimers.Tmr2CntA = MinxTimers.Tmr2PreA;
|
||||
MinxTimers.Tmr2CntB = MinxTimers.Tmr2PreB;
|
||||
}
|
||||
} else {
|
||||
// 8-Bits
|
||||
MinxTimers.Tmr2WMode = 0;
|
||||
if (val & 0x02) {
|
||||
MinxTimers.Tmr2CntA = MinxTimers.Tmr2PreA;
|
||||
}
|
||||
}
|
||||
return;
|
||||
case 0x39: // Timer 2 Control B
|
||||
PMR_TMR2_CTRL_H = val & 0x0D;
|
||||
MinxTimers.Tmr2HEna = val & 0x04;
|
||||
if (PMR_TMR2_CTRL_L & 0x80) {
|
||||
// 16-Bits, unused
|
||||
} else {
|
||||
// 8-Bits
|
||||
if (val & 0x02) {
|
||||
MinxTimers.Tmr2CntB = MinxTimers.Tmr2PreB;
|
||||
}
|
||||
}
|
||||
return;
|
||||
case 0x3A: // Timer 2 Preset A
|
||||
MinxTimers.Tmr2PreA = val << 24;
|
||||
return;
|
||||
case 0x3B: // Timer 2 Preset B
|
||||
MinxTimers.Tmr2PreB = val << 24;
|
||||
return;
|
||||
case 0x3C: // Timer 2 Pivot A
|
||||
PMR_TMR2_PVT_L = val;
|
||||
return;
|
||||
case 0x3D: // Timer 2 Pivot B
|
||||
PMR_TMR2_PVT_H = val;
|
||||
return;
|
||||
case 0x3E: // Timer 2 Count A
|
||||
return;
|
||||
case 0x3F: // Timer 2 Count B
|
||||
return;
|
||||
case 0x40: // 256 Hz Timer Control
|
||||
PMR_TMR256_CTRL = val & 0x01;
|
||||
if (val & 0x02) {
|
||||
MinxTimers.Tmr8Cnt = 0;
|
||||
}
|
||||
return;
|
||||
case 0x41: // 256 Hz Timer Counter
|
||||
return;
|
||||
case 0x48: // Timer 3 Control A
|
||||
PMR_TMR3_CTRL_L = val & 0x8D;
|
||||
MinxTimers.Tmr3LEna = val & 0x04;
|
||||
if (PMR_TMR3_CTRL_L & 0x80) {
|
||||
// 16-Bits
|
||||
MinxTimers.Tmr3WMode = 1;
|
||||
if (val & 0x02) {
|
||||
MinxTimers.Tmr3CntA = MinxTimers.Tmr3PreA;
|
||||
MinxTimers.Tmr3CntB = MinxTimers.Tmr3PreB;
|
||||
}
|
||||
} else {
|
||||
// 8-Bits
|
||||
MinxTimers.Tmr3WMode = 0;
|
||||
if (val & 0x02) {
|
||||
MinxTimers.Tmr3CntA = MinxTimers.Tmr3PreA;
|
||||
}
|
||||
}
|
||||
return;
|
||||
case 0x49: // Timer 3 Control B
|
||||
PMR_TMR3_CTRL_H = val & 0x0D;
|
||||
MinxTimers.Tmr3HEna = val & 0x04;
|
||||
if (PMR_TMR3_CTRL_L & 0x80) {
|
||||
// 16-Bits, unused
|
||||
} else {
|
||||
// 8-Bits
|
||||
if (val & 0x02) {
|
||||
MinxTimers.Tmr3CntB = MinxTimers.Tmr3PreB;
|
||||
}
|
||||
}
|
||||
return;
|
||||
case 0x4A: // Timer 3 Preset A
|
||||
MinxTimers.Tmr3PreA = val << 24;
|
||||
return;
|
||||
case 0x4B: // Timer 3 Preset B
|
||||
MinxTimers.Tmr3PreB = val << 24;
|
||||
return;
|
||||
case 0x4C: // Timer 3 Pivot A
|
||||
MinxTimers.Timer3Piv = (MinxTimers.Timer3Piv & 0xFF00) | val;
|
||||
return;
|
||||
case 0x4D: // Timer 3 Pivot B
|
||||
MinxTimers.Timer3Piv = (MinxTimers.Timer3Piv & 0x00FF) | (val << 8);
|
||||
return;
|
||||
case 0x4E: // Timer 3 Count A
|
||||
return;
|
||||
case 0x4F: // Timer 3 Count B
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MINXHW_TIMERS
|
||||
#define MINXHW_TIMERS
|
||||
|
||||
#include <stdint.h>
|
||||
#include <streams/memory_stream.h>
|
||||
|
||||
/* For some reason, '_BIG_ENDIAN' is always defined when
|
||||
* building for 3DS/Switch with devkitarm/a64... */
|
||||
#if defined (_BIG_ENDIAN) && !defined (_3DS) && !defined(HAVE_LIBNX)
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t H;
|
||||
uint8_t L;
|
||||
} B;
|
||||
uint16_t W;
|
||||
} MinxWord;
|
||||
|
||||
#else
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t L;
|
||||
uint8_t H;
|
||||
} B;
|
||||
uint16_t W;
|
||||
} MinxWord;
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
// Internal processing
|
||||
uint32_t SecTimerCnt; // Second Timer Counter
|
||||
int32_t TmrSecs; // Second Timer Fraction (Cycles, needs signed)
|
||||
uint32_t Tmr1DecA; // Timer 1-Lo Decrement 8.24
|
||||
uint32_t Tmr1DecB; // Timer 1-Hi Decrement 8.24
|
||||
uint32_t Tmr1CntA; // Timer 1-Lo Counter 8.24
|
||||
uint32_t Tmr1CntB; // Timer 1-Hi Counter 8.24
|
||||
uint32_t Tmr1PreA; // Timer 1-Lo Preset 8.24
|
||||
uint32_t Tmr1PreB; // Timer 1-Hi Preset 8.24
|
||||
uint32_t Tmr2DecA; // Timer 2-Lo Decrement 8.24
|
||||
uint32_t Tmr2DecB; // Timer 2-Hi Decrement 8.24
|
||||
uint32_t Tmr2CntA; // Timer 2-Lo Counter 8.24
|
||||
uint32_t Tmr2CntB; // Timer 2-Hi Counter 8.24
|
||||
uint32_t Tmr2PreA; // Timer 2-Lo Preset 8.24
|
||||
uint32_t Tmr2PreB; // Timer 2-Hi Preset 8.24
|
||||
uint32_t Tmr3DecA; // Timer 3-Lo Decrement 8.24
|
||||
uint32_t Tmr3DecB; // Timer 3-Hi Decrement 8.24
|
||||
uint32_t Tmr3CntA; // Timer 3-Lo Counter 8.24
|
||||
uint32_t Tmr3CntB; // Timer 3-Hi Counter 8.24
|
||||
uint32_t Tmr3PreA; // Timer 3-Lo Preset 8.24
|
||||
uint32_t Tmr3PreB; // Timer 3-Hi Preset 8.24
|
||||
uint32_t Tmr8Cnt; // 256Hz Timer Counter 8.24
|
||||
uint32_t PRCCnt; // PRC Counter 8.24
|
||||
MinxWord Tmr3Cnt16; // Timer 3 16-Bits count
|
||||
uint16_t Timer3Piv; // Timer 3 Pivot
|
||||
uint8_t TmrXEna2; // Oscillator 2 Enabled
|
||||
uint8_t TmrXEna1; // Oscillator 1 Enabled
|
||||
// Performance cache
|
||||
int Tmr1WMode; // Timer 1 16-bits mode
|
||||
int Tmr1LEna; // Timer 1 low enable
|
||||
int Tmr1HEna; // Timer 1 high enable
|
||||
int Tmr2WMode; // Timer 2 16-bits mode
|
||||
int Tmr2LEna; // Timer 2 low enable
|
||||
int Tmr2HEna; // Timer 2 high enable
|
||||
int Tmr3WMode; // Timer 3 16-bits mode
|
||||
int Tmr3LEna; // Timer 3 low enable
|
||||
int Tmr3HEna; // Timer 3 high enable
|
||||
} TMinxTimers;
|
||||
|
||||
// Export Timers state
|
||||
extern TMinxTimers MinxTimers;
|
||||
|
||||
// Interrupt table
|
||||
enum {
|
||||
MINX_INTR_05 = 0x05, // Timer 2-B Underflow
|
||||
MINX_INTR_06 = 0x06, // Timer 2-A Underflow (8-Bits only)
|
||||
MINX_INTR_07 = 0x07, // Timer 1-B Underflow
|
||||
MINX_INTR_08 = 0x08, // Timer 1-A Underflow (8-Bits only)
|
||||
MINX_INTR_09 = 0x09, // Timer 3 Underflow
|
||||
MINX_INTR_0A = 0x0A, // Timer 3 Pivot
|
||||
MINX_INTR_0B = 0x0B, // 32 Hz
|
||||
MINX_INTR_0C = 0x0C, // 8 Hz
|
||||
MINX_INTR_0D = 0x0D, // 2 Hz
|
||||
MINX_INTR_0E = 0x0E // 1 Hz
|
||||
};
|
||||
|
||||
#define MINX_TIMER256INC (16777216/15625) // Aproximate value of 256Hz Timer (256 Hz)
|
||||
|
||||
// Timers counting frequency table
|
||||
extern const uint32_t MinxTimers_CountFreq[32];
|
||||
|
||||
int MinxTimers_Create(void);
|
||||
|
||||
void MinxTimers_Destroy(void);
|
||||
|
||||
void MinxTimers_Reset(int hardreset);
|
||||
|
||||
int MinxTimers_LoadStateStream(memstream_t *stream, uint32_t bsize);
|
||||
|
||||
int MinxTimers_SaveStateStream(memstream_t *stream);
|
||||
|
||||
void MinxTimers_Sync(void);
|
||||
|
||||
uint8_t MinxTimers_ReadReg(uint8_t reg);
|
||||
|
||||
void MinxTimers_WriteReg(unsigned char reg, unsigned char val);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2012 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef POKEMINI_MULTICART
|
||||
#define POKEMINI_MULTICART
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint8_t (*TMulticartRead)(uint32_t addr);
|
||||
typedef void (*TMulticartWrite)(uint32_t addr, uint8_t data);
|
||||
|
||||
// Multicart read/write
|
||||
extern TMulticartRead MulticartRead;
|
||||
extern TMulticartWrite MulticartWrite;
|
||||
|
||||
// Multicart state
|
||||
extern int PM_MM_Type;
|
||||
extern int PM_MM_Dirty;
|
||||
extern int PM_MM_BusCycle;
|
||||
extern int PM_MM_GetID;
|
||||
extern int PM_MM_Bypass;
|
||||
extern int PM_MM_Command;
|
||||
extern uint32_t PM_MM_Offset;
|
||||
|
||||
// For misc information
|
||||
extern uint32_t PM_MM_LastErase_Start;
|
||||
extern uint32_t PM_MM_LastErase_End;
|
||||
extern uint32_t PM_MM_LastProg;
|
||||
|
||||
// Set multicart
|
||||
void NewMulticart(void);
|
||||
void SetMulticart(int type);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2014 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PMCOMMON_H
|
||||
#define PMCOMMON_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <retro_inline.h>
|
||||
|
||||
// Temporary variable length
|
||||
// Minimum is 128
|
||||
// Recommended is 256
|
||||
#ifndef PMTMPV
|
||||
#define PMTMPV 512
|
||||
#endif
|
||||
|
||||
// Return true if the string is valid and non-empty
|
||||
int StringIsSet(char *str);
|
||||
|
||||
// Get multiple of 2 (Mask)
|
||||
int GetMultiple2Mask(int input);
|
||||
|
||||
// Check if file exist
|
||||
int FileExist(const char *filename);
|
||||
|
||||
// Directories
|
||||
void PokeMini_InitDirs(char *argv0, char *exec);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009-2015 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef POKEMINI_EMU
|
||||
#define POKEMINI_EMU
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <retro_inline.h>
|
||||
#include <streams/memory_stream.h>
|
||||
|
||||
// Common functions
|
||||
#include "PMCommon.h"
|
||||
|
||||
// Configuration Flags
|
||||
// Generated sound only
|
||||
#define POKEMINI_GENSOUND 0x02
|
||||
|
||||
extern int PokeMini_FreeBIOS; // Using freebios?
|
||||
extern int PokeMini_Flags; // Configuration flags
|
||||
extern int PokeMini_Rumbling; // Pokemon-Mini is rumbling
|
||||
extern uint8_t PM_BIOS[]; // Pokemon-Mini BIOS ($000000 to $000FFF, 4096)
|
||||
extern uint8_t PM_RAM[]; // Pokemon-Mini RAM ($001000 to $002100, 4096 + 256)
|
||||
extern uint8_t *PM_ROM; // Pokemon-Mini ROM ($002100 to $1FFFFF, Up to 2MB)
|
||||
extern int PM_ROM_Alloc; // Pokemon-Mini ROM Allocated on memory?
|
||||
extern int PM_ROM_Size; // Pokemon-Mini ROM Size
|
||||
extern int PM_ROM_Mask; // Pokemon-Mini ROM Mask
|
||||
extern int PokeMini_LCDMode; // LCD Mode
|
||||
extern int PokeMini_ColorFormat; // Color Format (0 = 8x8, 1 = 4x4)
|
||||
extern int PokeMini_HostBattStatus; // Host battery status
|
||||
|
||||
// Number of cycles to process on hardware
|
||||
extern int PokeHWCycles;
|
||||
|
||||
|
||||
enum {
|
||||
LCDMODE_ANALOG = 0,
|
||||
LCDMODE_3SHADES,
|
||||
LCDMODE_2SHADES,
|
||||
LCDMODE_COLORS
|
||||
};
|
||||
|
||||
// Include Interfaces
|
||||
#include "IOMap.h"
|
||||
#include "MinxCPU.h"
|
||||
#include "MinxTimers.h"
|
||||
#include "MinxIO.h"
|
||||
#include "MinxIRQ.h"
|
||||
#include "MinxPRC.h"
|
||||
#include "MinxColorPRC.h"
|
||||
#include "MinxLCD.h"
|
||||
#include "MinxAudio.h"
|
||||
#include "Multicart.h"
|
||||
|
||||
// PRC Read/Write
|
||||
#ifdef PERFORMANCE
|
||||
|
||||
static INLINE uint8_t MinxPRC_OnRead(int cpu, uint32_t addr)
|
||||
{
|
||||
if (addr >= 0x2100) {
|
||||
// ROM Read
|
||||
if (PM_ROM) return PM_ROM[addr & PM_ROM_Mask];
|
||||
} else if (addr >= 0x2000) {
|
||||
// I/O Read (Unused)
|
||||
return 0xFF;
|
||||
} else if (addr >= 0x1000) {
|
||||
// RAM Read
|
||||
return PM_RAM[addr-0x1000];
|
||||
} else {
|
||||
// BIOS Read
|
||||
return PM_BIOS[addr];
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
static INLINE void MinxPRC_OnWrite(int cpu, uint32_t addr, uint8_t data)
|
||||
{
|
||||
// RAM Write
|
||||
if ((addr >= 0x1000) && (addr < 0x2000))
|
||||
PM_RAM[addr-0x1000] = data;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "Multicart.h"
|
||||
|
||||
#define MinxPRC_OnRead MinxCPU_OnRead
|
||||
#define MinxPRC_OnWrite MinxCPU_OnWrite
|
||||
|
||||
#endif
|
||||
|
||||
// LCD Framebuffer
|
||||
#define MinxPRC_LCDfb PM_RAM
|
||||
|
||||
// Load state safe variables
|
||||
#define POKELOADSS_START(size)\
|
||||
uint32_t rsize = 0;\
|
||||
uint32_t tmp32;\
|
||||
uint16_t tmp16;\
|
||||
if (size != bsize) return 0;\
|
||||
{ tmp32 = 0; tmp16 = 0; }
|
||||
|
||||
// -- Stream versions START
|
||||
#define POKELOADSS_STREAM_32(var) {\
|
||||
rsize += (uint32_t)memstream_read(stream, (void *)&tmp32, 4);\
|
||||
var = tmp32;\
|
||||
}
|
||||
|
||||
#define POKELOADSS_STREAM_16(var) {\
|
||||
rsize += (uint32_t)memstream_read(stream, (void *)&tmp16, 2);\
|
||||
var = tmp16;\
|
||||
}
|
||||
|
||||
#define POKELOADSS_STREAM_8(var) {\
|
||||
rsize += (uint32_t)memstream_read(stream, (void *)&var, 1);\
|
||||
}
|
||||
|
||||
#define POKELOADSS_STREAM_A(array, size) {\
|
||||
rsize += (uint32_t)memstream_read(stream, (void *)array, size);\
|
||||
}
|
||||
|
||||
#define POKE_SEEK_CUR 1
|
||||
|
||||
#define POKELOADSS_STREAM_X(size) {\
|
||||
rsize += memstream_seek(stream, size, POKE_SEEK_CUR) ? 0 : size;\
|
||||
}
|
||||
// -- Stream versions End
|
||||
|
||||
#define POKELOADSS_END(size) {\
|
||||
tmp32 = 0; tmp16 = 0;\
|
||||
return (rsize == size) + tmp32 + (uint32_t)tmp16;\
|
||||
}
|
||||
|
||||
// -- Stream versions START
|
||||
#define POKESAVESS_STREAM_START(size)\
|
||||
uint32_t wsize = 0;\
|
||||
uint32_t tmp32 = size;\
|
||||
uint16_t tmp16;\
|
||||
if (memstream_write(stream, (void *)&tmp32, 4) != 4) return 0;\
|
||||
{ tmp32 = 0; tmp16 = 0; }
|
||||
|
||||
#define POKESAVESS_STREAM_32(var) {\
|
||||
tmp32 = (uint32_t)var;\
|
||||
wsize += (uint32_t)memstream_write(stream, (void *)&tmp32, 4);\
|
||||
}
|
||||
|
||||
#define POKESAVESS_STREAM_16(var) {\
|
||||
tmp16 = (uint16_t)var;\
|
||||
wsize += (uint32_t)memstream_write(stream, (void *)&tmp16, 2);\
|
||||
}
|
||||
|
||||
#define POKESAVESS_STREAM_8(var) {\
|
||||
wsize += (uint32_t)memstream_write(stream, (void *)&var, 1);\
|
||||
}
|
||||
|
||||
#define POKESAVESS_STREAM_A(array, size) {\
|
||||
wsize += (uint32_t)memstream_write(stream, (void *)array, size);\
|
||||
}
|
||||
|
||||
#define POKESAVESS_STREAM_X(size) {\
|
||||
tmp16 = 0;\
|
||||
for (tmp32=0; tmp32<(uint32_t)size; tmp32++) {\
|
||||
wsize += (uint32_t)memstream_write(stream, (void *)&tmp16, 1);\
|
||||
}\
|
||||
}
|
||||
// -- Stream versions End
|
||||
|
||||
#define POKESAVESS_END(size) {\
|
||||
tmp32 = 0; tmp16 = 0;\
|
||||
return (wsize == size) + tmp32 + (uint32_t)tmp16;\
|
||||
}
|
||||
|
||||
// Stream I/O
|
||||
typedef int TPokeMini_StreamIO(void *data, int size, void *ptr);
|
||||
|
||||
// Create emulator and all interfaces
|
||||
int PokeMini_Create(int flags, int soundfifo);
|
||||
|
||||
// Destroy emulator and all interfaces
|
||||
void PokeMini_Destroy(void);
|
||||
|
||||
// Apply changes from command lines
|
||||
void PokeMini_ApplyChanges(void);
|
||||
|
||||
// Low power battery emulation
|
||||
void PokeMini_LowPower(int enable);
|
||||
|
||||
// Set LCD mode
|
||||
void PokeMini_SetLCDMode(int mode);
|
||||
|
||||
// Generate rumble offset
|
||||
int PokeMini_GenRumbleOffset(int pitch);
|
||||
|
||||
// Load BIOS file
|
||||
int PokeMini_LoadBIOSFile(const char *filename);
|
||||
|
||||
// Load FreeBIOS
|
||||
int PokeMini_LoadFreeBIOS(void);
|
||||
|
||||
// Check if file exist
|
||||
int PokeMini_FileExist(const char *filename);
|
||||
|
||||
// New MIN ROM
|
||||
int PokeMini_NewMIN(uint32_t size);
|
||||
|
||||
// Synchronize host time
|
||||
int PokeMini_SyncHostTime(void);
|
||||
|
||||
// Load EEPROM data
|
||||
int PokeMini_LoadEEPROMFile(const char *filename);
|
||||
|
||||
// Save EEPROM data
|
||||
int PokeMini_SaveEEPROMFile(const char *filename);
|
||||
|
||||
// Load emulator state from memory stream
|
||||
int PokeMini_LoadSSStream(uint8_t *buffer, uint64_t size);
|
||||
|
||||
// Save emulator state to memory stream
|
||||
int PokeMini_SaveSSStream(uint8_t *buffer, uint64_t size);
|
||||
|
||||
// Reset CPU
|
||||
void PokeMini_Reset(int hardreset);
|
||||
|
||||
// Internals, do not call directly!
|
||||
void PokeMini_FreeColorInfo(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,259 @@
|
||||
const unsigned char FreeBIOS[] =
|
||||
{
|
||||
0x9A,0x00,0xAB,0x00,0xAB,0x00,0x2F,0x02,0x41,0x02,0x53,0x02,0x65,0x02,0x77,0x02,
|
||||
0x89,0x02,0x9B,0x02,0xAD,0x02,0xBF,0x02,0xD1,0x02,0xE3,0x02,0xF5,0x02,0x07,0x03,
|
||||
0x19,0x03,0xAB,0x00,0xAB,0x00,0x60,0x04,0x2B,0x03,0xF1,0x03,0x3D,0x03,0x4F,0x03,
|
||||
0x61,0x03,0x73,0x03,0x85,0x03,0x97,0x03,0xA9,0x03,0xBB,0x03,0xCD,0x03,0xDF,0x03,
|
||||
0xF1,0xFF,0x9E,0x04,0x60,0x04,0x60,0x04,0xE4,0x04,0x60,0x04,0x0D,0x05,0x24,0x05,
|
||||
0x45,0x05,0x4C,0x05,0x5D,0x05,0x7C,0x05,0x92,0x05,0x9F,0x05,0xBB,0x05,0x60,0x04,
|
||||
0x60,0x04,0x60,0x04,0x60,0x04,0x60,0x04,0x60,0x04,0x60,0x04,0x60,0x04,0x60,0x04,
|
||||
0x60,0x04,0xD6,0x05,0xE3,0x05,0x60,0x04,0x60,0x04,0xF0,0x05,0x00,0x06,0x66,0x06,
|
||||
0x7A,0x06,0x8A,0x06,0x60,0x04,0x60,0x04,0x60,0x04,0x60,0x04,0x60,0x04,0x60,0x04,
|
||||
0x60,0x04,0x60,0x04,0x60,0x04,0x00,0x00,0x98,0x06,0xB4,0x20,0x38,0xCE,0xCD,0xDD,
|
||||
0x08,0x02,0xD9,0x08,0x01,0xDD,0x00,0x7C,0xDD,0x02,0x00,0x9F,0xC0,0xB4,0x20,0x38,
|
||||
0xCE,0xCD,0xCE,0xCE,0xCE,0xCF,0xCF,0x6E,0x00,0x20,0xDD,0x80,0x00,0xCE,0xC4,0x01,
|
||||
0xF3,0x01,0x00,0xD9,0x00,0x03,0xD9,0x01,0x30,0xD9,0x02,0xC0,0xF2,0xE1,0x00,0xC6,
|
||||
0xA0,0x06,0xBE,0x82,0x20,0x79,0x84,0x79,0x85,0x79,0x86,0x79,0x87,0x79,0x88,0x79,
|
||||
0x89,0x38,0xC6,0x00,0x10,0x60,0x92,0xD6,0x00,0x20,0xEF,0xF9,0xFF,0xF2,0x05,0x01,
|
||||
0xDD,0xFE,0xAF,0xF2,0x1D,0x01,0xD9,0x80,0x0A,0xD9,0x81,0x01,0xDC,0x10,0x20,0xEF,
|
||||
0x40,0x00,0xF2,0x2F,0x00,0xEF,0x3A,0x00,0x38,0xDD,0x80,0x00,0xDD,0x81,0x07,0x78,
|
||||
0x82,0x78,0x83,0xD8,0x01,0xEF,0xC6,0x00,0x10,0x60,0x92,0xD6,0x00,0x20,0xEF,0xF9,
|
||||
0xFF,0xC4,0x00,0x00,0xCF,0xE4,0xCF,0xE8,0xCF,0xEC,0x4C,0x52,0xB0,0xFF,0x9C,0xC0,
|
||||
0xF3,0xD0,0x1F,0xCE,0xD0,0x00,0x21,0x32,0x4D,0xF8,0xCE,0xD0,0x01,0x21,0x32,0x4E,
|
||||
0xF8,0xB1,0x03,0xA0,0xB0,0x01,0xC6,0x7D,0x13,0xB1,0x03,0xF2,0x51,0x00,0xC6,0x88,
|
||||
0x13,0xB1,0x04,0xF2,0x49,0x00,0xDC,0x10,0x20,0xEE,0x0B,0x00,0xC6,0x94,0x13,0xB0,
|
||||
0x08,0xB1,0x04,0xF2,0x39,0x00,0xF2,0xCB,0xFF,0xEE,0x0B,0x00,0xC6,0xA0,0x13,0xB0,
|
||||
0x0C,0xB1,0x04,0xF2,0x29,0x00,0xF2,0x2C,0x00,0xC6,0x94,0x13,0xB0,0x00,0xB1,0x04,
|
||||
0xF2,0x17,0x00,0xF2,0x1F,0x00,0xA8,0xF5,0xBB,0xC6,0xA0,0x13,0xB0,0x00,0xB1,0x04,
|
||||
0xF2,0x07,0x00,0xF2,0x0F,0x00,0xF3,0x6A,0xFF,0x60,0x92,0xF5,0xFD,0xF8,0x60,0x92,
|
||||
0x80,0xF5,0xFC,0xF8,0xB0,0xFF,0xB1,0xFF,0xF5,0xFF,0x88,0xEF,0xF9,0xFF,0xF8,0xB1,
|
||||
0x00,0xDD,0x10,0x08,0xD8,0x19,0xCF,0x79,0x20,0xDD,0x21,0x30,0xDD,0x22,0x02,0x79,
|
||||
0x23,0xDD,0x24,0x02,0x79,0x25,0x79,0x26,0x79,0x40,0x79,0x44,0xDD,0x50,0xFF,0x79,
|
||||
0x51,0x79,0x54,0x79,0x55,0xD9,0x60,0x0C,0xD8,0x61,0xFB,0xD9,0x61,0x08,0xD9,0x61,
|
||||
0x04,0xDD,0x61,0x20,0xDD,0x60,0x32,0x79,0x62,0x79,0x70,0x79,0x71,0xDD,0xFE,0x81,
|
||||
0xDD,0xFE,0x1F,0xF8,0xA1,0xC5,0xFE,0x20,0xB5,0xE3,0xB5,0xA4,0xB5,0xAD,0xB5,0x00,
|
||||
0xB5,0x10,0xB5,0xEE,0xB5,0x40,0xB5,0xA2,0xB5,0xA0,0xB5,0xC0,0xB5,0xA6,0xB5,0x2F,
|
||||
0xA9,0xF8,0xC5,0xFE,0x20,0xB5,0xE3,0xB3,0xB0,0x6B,0xB5,0x00,0xB5,0x10,0xB1,0x60,
|
||||
0x91,0xDD,0xFF,0x00,0xF5,0xFC,0x99,0x83,0xCE,0xBE,0xB8,0xEF,0xEC,0xFF,0xF8,0xA5,
|
||||
0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0x00,0x02,0xAC,0xAD,0xF3,0xC8,
|
||||
0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0xEE,0x01,0xAC,0xAD,
|
||||
0xF3,0xBC,0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0xDC,0x01,
|
||||
0xAC,0xAD,0xF3,0xB0,0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,
|
||||
0xCA,0x01,0xAC,0xAD,0xF3,0xA4,0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,
|
||||
0x20,0xEA,0xB8,0x01,0xAC,0xAD,0xF3,0x98,0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,
|
||||
0xDC,0x01,0x20,0xEA,0xA6,0x01,0xAC,0xAD,0xF3,0x8C,0x1E,0xA5,0xA4,0xCE,0xC5,0x00,
|
||||
0xB4,0x20,0xDC,0x01,0x20,0xEA,0x94,0x01,0xAC,0xAD,0xF3,0x80,0x1E,0xA5,0xA4,0xCE,
|
||||
0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0x82,0x01,0xAC,0xAD,0xF3,0x74,0x1E,0xA5,
|
||||
0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0x70,0x01,0xAC,0xAD,0xF3,0x68,
|
||||
0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0x5E,0x01,0xAC,0xAD,
|
||||
0xF3,0x5C,0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0x4C,0x01,
|
||||
0xAC,0xAD,0xF3,0x50,0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,
|
||||
0x3A,0x01,0xAC,0xAD,0xF3,0x44,0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,
|
||||
0x20,0xEA,0x28,0x01,0xAC,0xAD,0xF3,0x38,0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,
|
||||
0xDC,0x01,0x20,0xEA,0x16,0x01,0xAC,0xAD,0xF3,0x2C,0x1E,0xA5,0xA4,0xCE,0xC5,0x00,
|
||||
0xB4,0x20,0xDC,0x01,0x20,0xEA,0x04,0x01,0xAC,0xAD,0xF3,0x62,0x1E,0xA5,0xA4,0xCE,
|
||||
0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0xF2,0x00,0xAC,0xAD,0xF3,0x14,0x1E,0xA5,
|
||||
0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0xE0,0x00,0xAC,0xAD,0xF3,0x08,
|
||||
0x1E,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0xCE,0x00,0xAC,0xAD,
|
||||
0xF3,0xFC,0x1D,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0xBC,0x00,
|
||||
0xAC,0xAD,0xF3,0xF0,0x1D,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,
|
||||
0xAA,0x00,0xAC,0xAD,0xF3,0xE4,0x1D,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,
|
||||
0x20,0xEA,0x98,0x00,0xAC,0xAD,0xF3,0xD8,0x1D,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,
|
||||
0xDC,0x01,0x20,0xEA,0x86,0x00,0xAC,0xAD,0xF3,0xCC,0x1D,0xA5,0xA4,0xCE,0xC5,0x00,
|
||||
0xB4,0x20,0xDC,0x01,0x20,0xEA,0x74,0x00,0xAC,0xAD,0xF3,0xC0,0x1D,0xA5,0xA4,0xCE,
|
||||
0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0x62,0x00,0xAC,0xAD,0xF3,0xB4,0x1D,0xA5,
|
||||
0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEA,0x50,0x00,0xAC,0xAD,0xF3,0xA8,
|
||||
0x1D,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x01,0x20,0xEF,0x2A,0x00,0xDC,0x01,
|
||||
0x10,0xEF,0xA8,0xFC,0xDC,0x71,0x04,0xEE,0x0D,0x00,0xDC,0x02,0x40,0xEE,0x07,0x00,
|
||||
0xD8,0x71,0xFB,0xD9,0x02,0x80,0xDC,0x01,0x80,0xEE,0x11,0x00,0xDC,0x02,0x20,0xEF,
|
||||
0x14,0x00,0xAC,0xAD,0xF3,0xD7,0x1B,0xAC,0xAD,0xF3,0x31,0x1D,0xD9,0x01,0x20,0xDC,
|
||||
0x02,0x20,0xEF,0xF3,0xFF,0xDD,0x29,0x80,0xAC,0xAD,0xF9,0xDC,0x71,0x04,0xEE,0x0D,
|
||||
0x00,0xDC,0x02,0x40,0xEE,0x07,0x00,0xD8,0x71,0xFB,0xD9,0x02,0x80,0xDC,0x01,0x80,
|
||||
0xEE,0x0A,0x00,0xCF,0x68,0x03,0x00,0xAC,0xAD,0xF3,0xA2,0x1B,0xD9,0x01,0x20,0xF8,
|
||||
0xF9,0xD8,0x80,0xF7,0xDD,0xFE,0xAE,0xDD,0xFE,0xAC,0xDD,0xFE,0x28,0xDD,0xFE,0xA5,
|
||||
0xD8,0x02,0xE3,0xD8,0x81,0xFE,0xD9,0x02,0x01,0xD9,0x24,0x02,0xD9,0x21,0x30,0xD8,
|
||||
0x01,0xDF,0xD8,0x02,0xE3,0xA7,0x9F,0x80,0xCE,0xAE,0xAF,0xD9,0x02,0x10,0xD9,0x81,
|
||||
0x01,0xF2,0x61,0xFD,0xDD,0xFE,0xAF,0xD8,0x02,0xDF,0xD9,0x00,0x03,0xF8,0xA5,0xA4,
|
||||
0x9F,0xC0,0xCE,0xC5,0x00,0xB4,0x20,0x4C,0x80,0x44,0x21,0x22,0x0C,0xA0,0x4C,0x23,
|
||||
0x44,0x24,0xA0,0x4C,0x25,0x44,0x26,0xA0,0xDD,0x23,0x00,0xDD,0x24,0x00,0xDD,0x25,
|
||||
0x80,0xDD,0x26,0x00,0xD9,0x21,0x0C,0xDD,0x29,0x80,0xDD,0x80,0x00,0xF2,0x92,0xFF,
|
||||
0xA8,0x79,0x25,0x78,0x26,0xA8,0x79,0x23,0x78,0x24,0xA8,0x79,0x80,0x22,0xF3,0x78,
|
||||
0x21,0xAC,0xAD,0xF9,0x9F,0xC0,0xCF,0x6E,0x00,0x20,0xCE,0xC5,0x00,0xB4,0x20,0xF2,
|
||||
0xBE,0xFC,0xDD,0x23,0x00,0xDD,0x24,0x00,0xDD,0x25,0x80,0xDD,0x26,0x00,0xDD,0x29,
|
||||
0x80,0xDD,0x80,0x00,0xDD,0x21,0x0C,0xF2,0x58,0xFF,0xF3,0x9F,0xFB,0xAF,0xA5,0xA1,
|
||||
0xCE,0xC5,0x00,0xC5,0x00,0x20,0xCE,0x84,0xCE,0x84,0xCE,0x25,0x03,0xCE,0x2C,0xA9,
|
||||
0xAD,0xF3,0x23,0x00,0xF2,0x27,0x00,0xAF,0xA7,0xEE,0x0A,0x00,0x32,0x3F,0xEE,0x0D,
|
||||
0x00,0x80,0xF3,0x0C,0x00,0x28,0xEE,0x05,0x00,0x88,0xF3,0x04,0x00,0xB0,0xFF,0xF9,
|
||||
0xF2,0xCC,0xFF,0x38,0xF9,0xAF,0xF2,0x05,0x00,0xF3,0x13,0x00,0xAF,0xA5,0xA4,0xCE,
|
||||
0xC5,0x00,0xB4,0x20,0x44,0x00,0xCE,0x8C,0xCE,0x8C,0xAC,0xAD,0xF8,0xAF,0xA5,0xA4,
|
||||
0xCE,0xC5,0x00,0xB4,0x20,0x48,0xDC,0x80,0x08,0xA7,0xD8,0x80,0xF7,0xDD,0xFE,0x81,
|
||||
0x79,0xFE,0xAF,0xEE,0x04,0x00,0xD9,0x80,0x08,0xAC,0xAD,0xF8,0xA5,0xA4,0xCE,0xC5,
|
||||
0x00,0xB4,0x20,0xF2,0x6F,0xFC,0xDD,0xFE,0xAF,0xD9,0x80,0x04,0xD9,0x81,0x01,0xAC,
|
||||
0xAD,0xF9,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xF2,0x59,0xFC,0xAC,0xAD,0xF9,0xA5,
|
||||
0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xD8,0x80,0xF7,0xDD,0xFE,0xAE,0xDD,0xFE,0xAC,0xDD,
|
||||
0xFE,0x28,0xDD,0xFE,0xA5,0xD8,0x81,0xFE,0xAC,0xAD,0xF9,0xA5,0xA4,0xCE,0xC5,0x00,
|
||||
0xB4,0x20,0x9F,0xC0,0xDC,0x01,0x80,0xEF,0x0A,0x00,0xD9,0x01,0x80,0xD9,0x01,0x40,
|
||||
0xD8,0x01,0xDF,0xAC,0xAD,0xF9,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xD8,0x00,0xFC,
|
||||
0xAC,0xAD,0xF9,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xD9,0x00,0x03,0xAC,0xAD,0xF9,
|
||||
0xAF,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xDC,0x53,0x02,0x9E,0x01,0xAC,0xAD,0xF8,
|
||||
0xA5,0xA4,0xCE,0xC5,0x00,0xB4,0x20,0xA6,0xA2,0xA3,0xA1,0xCF,0xB1,0x9F,0xC0,0x46,
|
||||
0x96,0x01,0xCE,0xC1,0xEE,0x0E,0x00,0xC2,0x0A,0x00,0x5E,0x9A,0x56,0x9A,0xA1,0x4E,
|
||||
0x9A,0xF3,0x04,0x00,0xC2,0x07,0x00,0xA0,0x4E,0x9A,0x46,0x9A,0x5E,0x9A,0x56,0x9A,
|
||||
0xCE,0xCF,0xCF,0xED,0x46,0x9A,0x5E,0x9A,0x56,0xCE,0xCE,0xCF,0xE9,0xD9,0x02,0x80,
|
||||
0xB6,0xFF,0xD9,0x02,0x80,0x47,0xD9,0x02,0x80,0x31,0xA8,0xCE,0xC3,0xEE,0x0A,0x00,
|
||||
0xAF,0x51,0xA8,0x58,0x41,0xA7,0xF2,0x0B,0x00,0xA8,0x22,0x01,0xA9,0xAB,0xAA,0xAE,
|
||||
0xAC,0xAD,0xF9,0xCE,0xCC,0xF4,0xA5,0xA1,0xCE,0xC5,0x00,0xC5,0x81,0x20,0xCE,0x25,
|
||||
0xF1,0x22,0x07,0xCE,0x84,0xCE,0x2C,0xA9,0xAD,0xF9,0xA5,0xA4,0xCE,0xC5,0x00,0xB4,
|
||||
0x20,0x44,0x81,0xCE,0x8C,0x22,0x07,0xAC,0xAD,0xF9,0xAF,0xA5,0xA4,0xCE,0xC5,0x00,
|
||||
0xB4,0x20,0xDC,0x01,0x08,0xAC,0xAD,0xF8,0xB7,0x02,0xF5,0xFF,0xB7,0x00,0xF9,0xFF,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x04,0x82,0xE1,0xE1,0x31,0x31,
|
||||
0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x31,0xE1,0xE1,0x82,0x06,0xFA,0x04,0xF8,0x00,
|
||||
0xFE,0x82,0xEA,0x3A,0xFE,0x82,0xEA,0x96,0xFC,0xC7,0xAA,0xBB,0xFF,0xC7,0xAA,0xBA,
|
||||
0xFE,0x82,0xAA,0xD6,0xFE,0x8A,0xFE,0xC6,0xBB,0xC7,0xFD,0xB6,0xAB,0xAB,0xDA,0x7E,
|
||||
0x7C,0x7C,0x40,0x40,0x00,0x38,0x7C,0x44,0x7C,0x38,0x00,0x3C,0x7C,0x20,0x7C,0x3C,
|
||||
0x00,0x00,0x7C,0x7C,0x7C,0x74,0x6C,0x54,0x64,0x44,0x44,0x44,0x44,0x6C,0x38,0x00,
|
||||
0x7C,0x7C,0x08,0x10,0x7C,0x7C,0x00,0x38,0x7C,0x44,0x7C,0x38,0x00,0x00,0x00,0x38,
|
||||
0x44,0x44,0x00,0x78,0x14,0x14,0x78,0x00,0x7C,0x14,0x14,0x68,0x00,0x04,0x7C,0x04,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0x20,0x20,0x20,0x20,0x46,0x72,0x65,0x65,0x77,0x61,0x72,0x65,0x20,0x20,0x20,0x20,
|
||||
0x50,0x6F,0x6B,0x65,0x6D,0x6F,0x6E,0x4D,0x69,0x6E,0x69,0x20,0x42,0x49,0x4F,0x53,
|
||||
0x20,0x20,0x56,0x65,0x72,0x73,0x69,0x6F,0x6E,0x20,0x20,0x31,0x2E,0x33,0x20,0x20,
|
||||
0x20,0x62,0x79,0x20,0x54,0x65,0x61,0x6D,0x20,0x50,0x6F,0x6B,0x65,0x6D,0x65,0x20,
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
PokeMini - Pokémon-Mini Emulator
|
||||
Copyright (C) 2009 JustBurn
|
||||
|
||||
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 3 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://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FREEBIOS_H
|
||||
#define FREEBIOS_H
|
||||
|
||||
// Free BIOS (4KB)
|
||||
extern const unsigned char FreeBIOS[];
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,132 @@
|
||||
/* PokeMiniEmu: what PokeMini.c, PMCommon.c and the colour PRC give the core, cut down for the Paradise (no files,
|
||||
* no colour, no multicart). The cartridge is read straight from the cached flash window (PM_ROM points there).
|
||||
* Based on PokeMini by JustBurn (GPL 3 or later), see LICENSE_pokemini. Author of the changes: mameise */
|
||||
#include "PokeMini.h"
|
||||
#include "freebios.h"
|
||||
#include <string.h>
|
||||
|
||||
int PokeMini_FreeBIOS = 0, PokeMini_Flags = 0, PokeMini_LCDMode = LCDMODE_ANALOG, PokeMini_ColorFormat = 0, PokeMini_HostBattStatus = 0;
|
||||
uint8_t PM_BIOS[4096];
|
||||
uint8_t PM_RAM[8192];
|
||||
uint8_t *PM_ROM;
|
||||
int PM_ROM_Alloc, PM_ROM_Size, PM_ROM_Mask;
|
||||
int PokeHWCycles;
|
||||
|
||||
static const uint8_t PM_IO_INIT[256] = {
|
||||
0x7F, 0x20, 0x5C, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
|
||||
0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
|
||||
0x00, 0x30, 0x02, 0x00, 0x02, 0x00, 0x00, 0x40, 0x00, 0xC0, 0x40, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF,
|
||||
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF,
|
||||
0xFF, 0x00, 0xFF, 0x00, 0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0x32, 0x64, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x40, 0xFF };
|
||||
|
||||
/* ---- memory: a small heap for the core's buffers (EEPROM, LCD) ---- */
|
||||
#ifndef PM_HEAP
|
||||
#define PM_HEAP 0x5C00
|
||||
#endif
|
||||
static uint8_t g_heap[PM_HEAP] __attribute__((aligned(8)));
|
||||
static uint32_t g_heap_n;
|
||||
#ifndef PM_HOST
|
||||
void *malloc(size_t n) { n = (n + 7u) & ~7u; if (g_heap_n + n > sizeof g_heap) return 0; void *p = g_heap + g_heap_n; g_heap_n += n; return p; }
|
||||
void free(void *p) { (void)p; }
|
||||
#endif
|
||||
|
||||
int GetMultiple2Mask(int input)
|
||||
{
|
||||
if (input) input--;
|
||||
input |= input >> 1; input |= input >> 2; input |= input >> 4; input |= input >> 8; input |= input >> 16;
|
||||
return input;
|
||||
}
|
||||
|
||||
/* ---- the colour PRC is not there ---- */
|
||||
int PRCColorEnable; uint8_t *PRCColorPixels, *PRCColorPixelsOld, *PRCColorMap, *PRCColorTop; unsigned int PRCColorOffset; uint8_t PRCColorFlags;
|
||||
int MinxColorPRC_Create(void) { return 1; }
|
||||
void MinxColorPRC_Reset(int hardreset) { (void)hardreset; }
|
||||
uint8_t MinxColorPRC_ReadReg(int cpu, uint8_t reg) { (void)cpu; (void)reg; return 0xFF; }
|
||||
void MinxColorPRC_WriteReg(uint8_t reg, uint8_t val) { (void)reg; (void)val; }
|
||||
void MinxColorPRC_WriteFramebuffer(uint16_t addr, uint8_t data) { (void)addr; (void)data; }
|
||||
void MinxColorPRC_WriteLCD(uint16_t addr, uint8_t data) { (void)addr; (void)data; }
|
||||
void MinxPRC_NoRender_Color(void) {}
|
||||
|
||||
/* ---- the Pokemon mini ---- */
|
||||
int PokeMini_Create(int flags, int soundfifo)
|
||||
{
|
||||
(void)soundfifo;
|
||||
g_heap_n = 0;
|
||||
memset(PM_BIOS, 0xFF, 4096); memset(PM_RAM, 0xFF, 8192);
|
||||
PM_ROM_Mask = 0x1FFF; PM_ROM_Size = 0x2000; PM_ROM = PM_RAM;
|
||||
memcpy(PM_IO, PM_IO_INIT, 256);
|
||||
if (!MinxCPU_Create() || !MinxTimers_Create() || !MinxIO_Create() || !MinxIRQ_Create() || !MinxPRC_Create() || !MinxLCD_Create() || !MinxAudio_Create(0, 0)) return 0;
|
||||
PokeMini_Flags = flags;
|
||||
return 1;
|
||||
}
|
||||
int PokeMini_LoadFreeBIOS(void) { PokeMini_FreeBIOS = 1; memcpy(PM_BIOS, FreeBIOS, 4096); return 1; }
|
||||
/* the cartridge in the flash window: size rounded up to a power of two (reads behind it repeat the start) */
|
||||
void pm_set_rom(const uint8_t *rom, uint32_t len) { PM_ROM = (uint8_t *)rom; PM_ROM_Mask = GetMultiple2Mask((int)len); PM_ROM_Size = PM_ROM_Mask + 1; }
|
||||
void PokeMini_Reset(int hardreset)
|
||||
{
|
||||
if (hardreset) { memset(PM_RAM, 0xFF, 8192); memcpy(PM_IO, PM_IO_INIT, 256); }
|
||||
MinxTimers_Reset(hardreset); MinxIRQ_Reset(hardreset); MinxIO_Reset(hardreset); MinxPRC_Reset(hardreset);
|
||||
MinxLCD_Reset(hardreset); MinxAudio_Reset(hardreset); MinxCPU_Reset(hardreset);
|
||||
}
|
||||
/* the clock of the game from the Paradise's (the BIOS then skips asking for the time) */
|
||||
void pm_set_time(int y, int mo, int d, int h, int mi, int s)
|
||||
{
|
||||
MinxIO_SetTimeStamp((uint8_t)(y % 100), (uint8_t)mo, (uint8_t)d, (uint8_t)h, (uint8_t)mi, (uint8_t)s);
|
||||
PMR_SEC_CTRL = 0x01; MinxTimers.SecTimerCnt = 0;
|
||||
}
|
||||
|
||||
/* ---- the state in a buffer (as PokeMini's state files, without the colour part) ---- */
|
||||
uint64_t memstream_read(memstream_t *s, void *d, uint64_t n) { if (s->pos + n > s->size) n = s->size - s->pos; memcpy(d, s->buf + s->pos, (size_t)n); s->pos += (uint32_t)n; return n; }
|
||||
uint64_t memstream_write(memstream_t *s, const void *d, uint64_t n) { if (s->pos + n > s->size) n = s->size - s->pos; memcpy(s->buf + s->pos, d, (size_t)n); s->pos += (uint32_t)n; return n; }
|
||||
int64_t memstream_seek(memstream_t *s, int64_t off, int whence) { int64_t p = whence == 1 ? s->pos + off : off; if (p < 0 || p > s->size) return -1; s->pos = (uint32_t)p; return 0; }
|
||||
uint64_t memstream_pos(memstream_t *s) { return s->pos; }
|
||||
#define PM_STATE_ID 0x31534D50u /* "PMS1" */
|
||||
static void tag(memstream_t *s, const char *t) { memstream_write(s, t, 4); }
|
||||
uint32_t pm_state_save(uint8_t *buf, uint32_t size)
|
||||
{
|
||||
memstream_t s = { buf, size, 0 }; uint32_t v = PM_STATE_ID, n;
|
||||
memstream_write(&s, &v, 4);
|
||||
tag(&s, "RAM-"); n = 0x1000; memstream_write(&s, &n, 4); memstream_write(&s, PM_RAM, 0x1000);
|
||||
tag(&s, "REG-"); n = 256; memstream_write(&s, &n, 4); memstream_write(&s, PM_IO, 256);
|
||||
tag(&s, "CPU-"); MinxCPU_SaveStateStream(&s);
|
||||
tag(&s, "IRQ-"); MinxIRQ_SaveStateStream(&s);
|
||||
tag(&s, "TMR-"); MinxTimers_SaveStateStream(&s);
|
||||
tag(&s, "PIO-"); MinxIO_SaveStateStream(&s);
|
||||
tag(&s, "PRC-"); MinxPRC_SaveStateStream(&s);
|
||||
tag(&s, "LCD-"); MinxLCD_SaveStateStream(&s);
|
||||
tag(&s, "AUD-"); MinxAudio_SaveStateStream(&s);
|
||||
tag(&s, "END-"); n = 0; memstream_write(&s, &n, 4);
|
||||
return s.pos < size ? s.pos : 0; /* 0: did not fit */
|
||||
}
|
||||
int pm_state_load(uint8_t *buf, uint32_t size)
|
||||
{
|
||||
memstream_t s = { buf, size, 0 }; uint32_t v = 0, n; char t[4];
|
||||
if (memstream_read(&s, &v, 4) != 4 || v != PM_STATE_ID) return 0;
|
||||
for (;;) {
|
||||
if (memstream_read(&s, t, 4) != 4 || memstream_read(&s, &n, 4) != 4) return 0;
|
||||
int ok = 1;
|
||||
if (!memcmp(t, "RAM-", 4)) ok = n == 0x1000 && memstream_read(&s, PM_RAM, 0x1000) == 0x1000;
|
||||
else if (!memcmp(t, "REG-", 4)) ok = n == 256 && memstream_read(&s, PM_IO, 256) == 256;
|
||||
else if (!memcmp(t, "CPU-", 4)) ok = MinxCPU_LoadStateStream(&s, n);
|
||||
else if (!memcmp(t, "IRQ-", 4)) ok = MinxIRQ_LoadStateStream(&s, n);
|
||||
else if (!memcmp(t, "TMR-", 4)) ok = MinxTimers_LoadStateStream(&s, n);
|
||||
else if (!memcmp(t, "PIO-", 4)) ok = MinxIO_LoadStateStream(&s, n);
|
||||
else if (!memcmp(t, "PRC-", 4)) ok = MinxPRC_LoadStateStream(&s, n);
|
||||
else if (!memcmp(t, "LCD-", 4)) ok = MinxLCD_LoadStateStream(&s, n);
|
||||
else if (!memcmp(t, "AUD-", 4)) ok = MinxAudio_LoadStateStream(&s, n);
|
||||
else if (!memcmp(t, "END-", 4)) return 1;
|
||||
else ok = memstream_seek(&s, n, 1) == 0;
|
||||
if (!ok) return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#ifndef INLINE
|
||||
#define INLINE inline
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
/* PokeMiniEmu: the few C library parts the PokeMini core needs (no C library on the Paradise) */
|
||||
#ifndef PM_STDLIB_H
|
||||
#define PM_STDLIB_H
|
||||
#include <stddef.h>
|
||||
void *malloc(size_t n);
|
||||
void free(void *p);
|
||||
static inline int abs(int x) { return x < 0 ? -x : x; }
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
/* PokeMiniEmu: a small memory stream for the core's state (replaces libretro-common's) */
|
||||
#ifndef PM_MEMSTREAM_H
|
||||
#define PM_MEMSTREAM_H
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
typedef struct memstream { uint8_t *buf; uint32_t size, pos; } memstream_t;
|
||||
uint64_t memstream_read(memstream_t *s, void *d, uint64_t n);
|
||||
uint64_t memstream_write(memstream_t *s, const void *d, uint64_t n);
|
||||
int64_t memstream_seek(memstream_t *s, int64_t off, int whence);
|
||||
uint64_t memstream_pos(memstream_t *s);
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef PM_STRING_H
|
||||
#define PM_STRING_H
|
||||
#include <stddef.h>
|
||||
void *memcpy(void *d, const void *s, size_t n);
|
||||
void *memset(void *d, int c, size_t n);
|
||||
void *memmove(void *d, const void *s, size_t n);
|
||||
int memcmp(const void *a, const void *b, size_t n);
|
||||
size_t strlen(const char *s);
|
||||
#endif
|
||||
@@ -0,0 +1,181 @@
|
||||
# PokeMiniEmu (pm.bin) in Unicorn, as devt7.py: hardware calls caught, the screen into a picture.
|
||||
# into a picture, the SysTick is advanced every RT instructions (96 MHz Cortex-M3 ~ RT per ms).
|
||||
# python3 devv3.py <v3.elf> <image with v3.bin at APPOFF> <ms> [KEYS="t:mask,..."] [SHOTS="t,t,..."] [OUT=dir]
|
||||
import sys, struct, subprocess, os
|
||||
from unicorn import *
|
||||
from unicorn.arm_const import *
|
||||
elf, img, total_ms = sys.argv[1], sys.argv[2], int(sys.argv[3])
|
||||
RT = int(os.environ.get('RT', '64000')) # instructions per millisecond (96 MHz, ~1.5 cycles each)
|
||||
out = os.environ.get('OUT', '.')
|
||||
syms = {}
|
||||
for l in subprocess.run(['llvm-nm', elf], capture_output=True, text=True).stdout.splitlines():
|
||||
p = l.split()
|
||||
if len(p) == 3: syms[p[2]] = int(p[0], 16)
|
||||
fl = bytearray(open(img, 'rb').read())
|
||||
u = Uc(UC_ARCH_ARM, UC_MODE_THUMB | UC_MODE_MCLASS)
|
||||
u.ctl_set_cpu_model(UC_CPU_ARM_CORTEX_M4)
|
||||
APPOFF = int(os.environ.get('APPOFF', '0xA0000'), 16) # program image (1.6.0: more programs elsewhere)
|
||||
u.mem_map(0, 0x10000); u.mem_write(0, bytes(fl[APPOFF:APPOFF + 0x10000]))
|
||||
u.mem_map(0x18000000, 0x20000); u.mem_map(0x20000000, 0x1000)
|
||||
u.mem_map(0x10000000, 0x100000)
|
||||
u.mem_map(0x60000000, 0x1000000); u.mem_write(0x60000000, bytes(fl))
|
||||
u.mem_map(0x40000000, 0x100000); u.mem_map(0x45000000, 0x1000); u.mem_map(0xE000E000, 0x1000); u.mem_map(0xE0001000, 0x1000) # DWT (CYCCNT reads 0 here)
|
||||
u.mem_write(0x4000B014, struct.pack('<I', 0x60)) # 1.6.9 T7_LINK: UART1 LSR, sender empty (nothing received)
|
||||
cfg = APPOFF + 0x140
|
||||
rom_off = struct.unpack_from('<I', fl, cfg + 8)[0]
|
||||
u.mem_write(0x10000000, bytes(fl[rom_off:rom_off + 0x100000]))
|
||||
XIPN = [0]
|
||||
def _xipw(uc, acc, a, sz, v, ud): # 1.7.2 GB_PAGES: the window follows its base register
|
||||
o = v - 0x60000000
|
||||
if 0 <= o < 0x1000000: uc.mem_write(0x10000000, bytes(fl[o:o + 0x100000]).ljust(0x100000, b'\xff')); XIPN[0] += 1
|
||||
u.hook_add(UC_HOOK_MEM_WRITE, _xipw, begin=0x4002F004, end=0x4002F007)
|
||||
import atexit; atexit.register(lambda: print('window moves', XIPN[0]))
|
||||
WH = [] # WHEEL='t:steps,...' (+ one way, - the other): the encoder phases at GPIO2
|
||||
for p in os.environ.get('WHEEL', '').split(','):
|
||||
if ':' in p: t, n = p.split(':'); WH.append([float(t), int(n)])
|
||||
state_enc = {'ph': 0, 'q': []}
|
||||
GRAY = [0, 1, 3, 2]
|
||||
fb = [[0] * 128 for _ in range(128)]
|
||||
rect = {'x0': 0, 'x1': 0, 'y': 0, 'x': 0}
|
||||
KS = []
|
||||
for p in os.environ.get('KEYS', '').split(','):
|
||||
if ':' in p: t, m = p.split(':'); KS.append((float(t), int(m)))
|
||||
SH = [float(x) for x in os.environ.get('SHOTS', '').split(',') if x]
|
||||
state = {'ms': 0, 'tone': [], 'left': 0, 'flashw': 0}
|
||||
def keys():
|
||||
m = 0
|
||||
for t, v in KS:
|
||||
if state['ms'] / 1000.0 >= t: m = v
|
||||
return m
|
||||
def ret(uc, v=None):
|
||||
if v is not None: uc.reg_write(UC_ARM_REG_R0, v)
|
||||
uc.reg_write(UC_ARM_REG_PC, uc.reg_read(UC_ARM_REG_LR) | 1)
|
||||
def h_begin(uc, *a):
|
||||
x0, y0, x1, y1 = (uc.reg_read(r) for r in (UC_ARM_REG_R0, UC_ARM_REG_R1, UC_ARM_REG_R2, UC_ARM_REG_R3))
|
||||
rect.update(x0=x0, x1=x1, y=y0, x=x0); ret(uc)
|
||||
def h_row(uc, *a):
|
||||
p, n = uc.reg_read(UC_ARM_REG_R0), uc.reg_read(UC_ARM_REG_R1)
|
||||
d = struct.unpack('<%dH' % n, uc.mem_read(p, 2 * n))
|
||||
for v in d:
|
||||
if rect['y'] < 128 and rect['x'] < 128: fb[rect['y']][rect['x']] = v
|
||||
rect['x'] += 1
|
||||
if rect['x'] >= rect['x1']: rect['x'] = rect['x0']; rect['y'] += 1
|
||||
ret(uc)
|
||||
def h_tone(uc, *a): state['tone'].append((state['ms'], uc.reg_read(UC_ARM_REG_R0))); ret(uc)
|
||||
def h_btn(uc, *a): ret(uc, keys())
|
||||
def h_prog(uc, *a):
|
||||
ad, src = uc.reg_read(UC_ARM_REG_R0), uc.reg_read(UC_ARM_REG_R1)
|
||||
d = bytes(uc.mem_read(src, 0x1000)); a = ad & 0xFFFFFF
|
||||
uc.mem_write(0x60000000 + a, d); fl[a:a + 0x1000] = d; state['flashw'] += 1; ret(uc)
|
||||
def h_erase(uc, *a):
|
||||
a = uc.reg_read(UC_ARM_REG_R0) & 0xFFFFFF
|
||||
uc.mem_write(0x60000000 + a, b'\xff' * 0x1000); fl[a:a + 0x1000] = b'\xff' * 0x1000; ret(uc)
|
||||
def h_back(uc, *a): state['back'] = 1; uc.emu_stop()
|
||||
def h_nop(uc, *a): ret(uc)
|
||||
H = {'hw_px_begin': h_begin, 'hw_px_row': h_row, 'hw_px_end': h_nop, 'hw_tone': h_tone, 'hw_buttons': h_btn,
|
||||
'flash_prog4k': h_prog, 'flash_erase4k': h_erase, 'hw_back_to_paradise': h_back, 'hw_init': h_nop,
|
||||
'hw_backlight': h_nop, 'hw_bl_pwm_off': h_nop, 'hw_wdt_feed': h_nop}
|
||||
for n, f in H.items():
|
||||
a = syms[n] & ~1
|
||||
u.hook_add(UC_HOOK_CODE, (lambda f: lambda uc, ad, sz, ud: f(uc))(f), begin=a, end=a)
|
||||
import builtins
|
||||
if hasattr(builtins, '__gbprof'): u.hook_add(UC_HOOK_BLOCK, builtins.__gbprof[0])
|
||||
if os.environ.get('CACHESIM'): # test38: the I-cache of the flash window (16 KB, 32-byte lines, WAYS ways, LRU): misses per frame
|
||||
_ways = int(os.environ.get('WAYS', '4')); _sets = 16384 // 32 // _ways
|
||||
_cs = [[] for _ in range(_sets)]; state['miss'] = 0; state['acc'] = 0
|
||||
def _cr(uc, acc, a, sz, v, ud):
|
||||
state['acc'] += 1
|
||||
ln = (a - 0x10000000) >> 5; s = _cs[ln % _sets]
|
||||
if ln in s: s.remove(ln); s.append(ln); return
|
||||
state['miss'] += 1; s.append(ln)
|
||||
if len(s) > _ways: s.pop(0)
|
||||
u.hook_add(UC_HOOK_MEM_READ, _cr, begin=0x10000000, end=0x100FFFFF)
|
||||
def bad(uc, access, addr, size, value, ud):
|
||||
print('unmapped', access, hex(addr), 'pc', hex(uc.reg_read(UC_ARM_REG_PC))); return False
|
||||
u.hook_add(UC_HOOK_MEM_UNMAPPED, bad)
|
||||
# 1.6.9 test22 CLK_ECO: the AHB prescaler at 0x45000010 slows the core: RT >> sh instructions per ms
|
||||
state['sh'] = 0; state['shms'] = [0, 0, 0, 0]
|
||||
def _ahb(uc, acc, a, sz, v, ud):
|
||||
state['sh'] = v & 7
|
||||
if os.environ.get('ECOLOG'): print('AHB', v & 7, 'at ms', state['ms'])
|
||||
u.hook_add(UC_HOOK_MEM_WRITE, _ahb, begin=0x45000010, end=0x45000013)
|
||||
if os.environ.get('MEMW'):
|
||||
_mw = int(os.environ['MEMW'], 16)
|
||||
u.hook_add(UC_HOOK_MEM_WRITE, lambda uc, acc, a, sz, v, ud: print('W %08x = %08x at ms %d' % (a, v, state['ms'])), begin=_mw, end=_mw + 0x3F)
|
||||
def shot(name):
|
||||
from PIL import Image
|
||||
im = Image.new('RGB', (128, 128))
|
||||
for y in range(128):
|
||||
for x in range(128):
|
||||
v = fb[y][x]; im.putpixel((x, y), (((v >> 11) & 31) << 3, ((v >> 5) & 63) << 2, (v & 31) << 3))
|
||||
im.save(os.path.join(out, name))
|
||||
if os.environ.get('PMB'): # test: the Paradise's time in the mailbox (seconds since 1970, local)
|
||||
_t = int(os.environ['PMB']); _c = int(os.environ.get('RTC0', '5000'))
|
||||
u.mem_write(0x20000FC0, struct.pack('<IIII', 0x4B4C4350, _t, _c, (~_t) & 0xFFFFFFFF))
|
||||
# 1.6.11 test2 GB_LINK: two of these joined by pipes, one exchange per ms (LINKW: pipe to write, LINKR: pipe to read)
|
||||
LK = {'tx': bytearray(), 'n0': 0}
|
||||
if os.environ.get('LINKW'):
|
||||
def _uw(uc, acc, a, sz, v, ud):
|
||||
LK['n0'] += 1
|
||||
if LK['n0'] > 1: LK['tx'].append(v & 0xFF) # the first is the baud divisor
|
||||
u.hook_add(UC_HOOK_MEM_WRITE, _uw, begin=0x4000B000, end=0x4000B000)
|
||||
LK['w'] = os.fdopen(os.open(os.environ['LINKW'], os.O_RDWR), 'wb', buffering=0); LK['r'] = os.fdopen(os.open(os.environ['LINKR'], os.O_RDWR), 'rb', buffering=0) # (O_RDWR: no wait for the other end)
|
||||
def link_ms():
|
||||
d = bytes(LK['tx']); LK['tx'] = bytearray()
|
||||
LK['w'].write(struct.pack('<H', len(d)) + d)
|
||||
h = LK['r'].read(2)
|
||||
while len(h) < 2: h += LK['r'].read(2 - len(h))
|
||||
n = struct.unpack('<H', h)[0]; got = b''
|
||||
while len(got) < n: got += LK['r'].read(n - len(got))
|
||||
if got:
|
||||
a = syms['g_pl']; rt = u.mem_read(a + 257, 1)[0]
|
||||
for b in got: u.mem_write(a + rt, bytes([b])); rt = (rt + 1) & 0xFF
|
||||
u.mem_write(a + 257, bytes([rt]))
|
||||
sp, rst = struct.unpack('<II', bytes(u.mem_read(0, 8)))
|
||||
u.reg_write(UC_ARM_REG_SP, sp)
|
||||
pc = rst; gms = syms['g_ms']; rtc0 = int(os.environ.get('RTC0', '5000'))
|
||||
emu_ms_sym = None
|
||||
si = 0
|
||||
while state['ms'] < total_ms and 'back' not in state:
|
||||
u.mem_write(0x45000304, struct.pack('<I', rtc0 + state['ms'] // 1000))
|
||||
try:
|
||||
u.emu_start(pc | 1, 0xFFFFFFF0, count=max(1, RT >> state['sh'])); state['shms'][min(state['sh'], 3)] += 1
|
||||
except UcError as ex:
|
||||
print('error', ex, hex(u.reg_read(UC_ARM_REG_PC))); break
|
||||
pc = u.reg_read(UC_ARM_REG_PC)
|
||||
state['ms'] += 1
|
||||
if 'w' in LK: link_ms()
|
||||
v = struct.unpack('<I', u.mem_read(gms, 4))[0]; u.mem_write(gms, struct.pack('<I', v + 1))
|
||||
# 1.6.9 test13 T7_KEYQ: the GPIO as the keys say (pressed = 0) and the tick's press counter
|
||||
km = keys(); u.mem_write(0x40018000, struct.pack('<I', 0xFFFFFFFF & ~(((km & 1) << 9) | ((km & 2) << 10) | ((km & 4) << 8) | ((km & 8) << 5))))
|
||||
if 'g_kin' in syms:
|
||||
e = km & ~state.get('kprev', 0) & 7; state['kprev'] = km
|
||||
u.mem_write(syms['g_kprev'], bytes([km & 7]))
|
||||
for i in range(3):
|
||||
if e & (1 << i): a = syms['g_kin'] + i; u.mem_write(a, bytes([(u.mem_read(a, 1)[0] + 1) & 0xFF]))
|
||||
for w in WH:
|
||||
if w[1] and state['ms'] / 1000.0 >= w[0]:
|
||||
d = 1 if w[1] > 0 else -1; state_enc['ph'] = (state_enc['ph'] + d) % 4; w[0] += 0.004 if (state_enc['ph'] % 4) else 0.02
|
||||
if state_enc['ph'] == 0: w[1] -= d
|
||||
u.mem_write(0x4001A000, struct.pack('<I', GRAY[state_enc['ph']]))
|
||||
for pk in os.environ.get('POKE', '').split(','): # test: 'ms:symbol+off:byte' written once
|
||||
if pk.count(':') == 2 and int(pk.split(':')[0]) == state['ms']:
|
||||
_t, _a, _v = pk.split(':'); _n, _o = (_a.split('+') + ['0'])[:2]; u.mem_write(syms[_n] + int(_o, 0), bytes([int(_v, 0)]))
|
||||
if os.environ.get('DROPLOG') and 'g_v3st' in syms:
|
||||
_d = struct.unpack('<I', u.mem_read(syms['g_v3st'] + 4, 4))[0]
|
||||
if _d != state.get('drop', 0): print('drop', _d - state.get('drop', 0), 'at ms', state['ms'], 'sh', state['sh']); state['drop'] = _d
|
||||
if si < len(SH) and state['ms'] >= SH[si] * 1000: shot('shot_%02d.png' % si); si += 1
|
||||
if 'miss' in state and state['ms'] % 1000 == 0:
|
||||
_f = struct.unpack('<I', u.mem_read(syms['g_pmst'], 4))[0]; _df = max(1, _f - state.get('f0', 0))
|
||||
print('s %2d frames %3d misses/frame %6.0f reads/frame %7.0f' % (state['ms'] // 1000, _df, state['miss'] / _df, state['acc'] / _df))
|
||||
state['f0'] = _f; state['miss'] = 0; state['acc'] = 0
|
||||
st = struct.unpack('<4I', bytes(u.mem_read(syms['g_pmst'], 16)))
|
||||
print('frames run', st[0], 'drawn', st[1], 'dropped', st[2], 'last frame ms', st[3])
|
||||
(os.environ.get('TONES') and print('tones:', state['tone']));print('ms', state['ms'], 'tones', len(state['tone']), 'flash writes', state['flashw'], 'back' if 'back' in state else '', 'pc', hex(pc))
|
||||
print('ms per clock step (96, 48, 24, 12 MHz):', state['shms'])
|
||||
open(os.path.join(out, 'flash_after.bin'), 'wb').write(fl)
|
||||
shot('shot_end.png')
|
||||
for _d in os.environ.get('DUMP', '').split(','): # test: 'symbol+off:len' printed at the end
|
||||
if ':' in _d:
|
||||
_a, _l = _d.split(':'); _n, _o = (_a.split('+') + ['0'])[:2]
|
||||
print('DUMP', _d, bytes(u.mem_read(syms[_n] + int(_o, 0), int(_l, 0))).hex())
|
||||
@@ -0,0 +1,15 @@
|
||||
# test image: pm.bin at 0xA0000 with its settings block, the game at 0x200000, the saves at 0x300000 (64 KB)
|
||||
# python3 mkimg.py pm.bin game.min out.bin [flags] [bios.min]
|
||||
import sys, struct
|
||||
app, rom, out = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
fl = bytearray(b'\xff' * 0x400000)
|
||||
a = open(app, 'rb').read(); r = open(rom, 'rb').read()
|
||||
fl[0xA0000:0xA0000 + len(a)] = a; fl[0x200000:0x200000 + len(r)] = r
|
||||
flags = int(sys.argv[4]) if len(sys.argv) > 4 else 0
|
||||
bios = 0
|
||||
if len(sys.argv) > 5: b = open(sys.argv[5], 'rb').read(); fl[0x310000:0x310000 + len(b)] = b; bios = 0x310000; flags |= 4
|
||||
c = 0xA0000 + 0x140
|
||||
struct.pack_into('<6I16s', fl, c, 0x50584D50, 1, 0x200000, len(r), 0x300000, flags, b'POKEMON MINI')
|
||||
struct.pack_into('<12H', fl, c + 40, 0x020, 0x002, 0x040, 0x001, 0x008, 0x010, 0x004, 0x000, 0x100, 0, 0, 0)
|
||||
struct.pack_into('<I', fl, c + 64, bios)
|
||||
open(out, 'wb').write(fl)
|
||||
@@ -0,0 +1,19 @@
|
||||
# count instructions per function (PROF=1 in devgb): exec devgb with a block hook
|
||||
import os, sys, subprocess, bisect, collections
|
||||
elf = sys.argv[1]
|
||||
fs = []
|
||||
for l in subprocess.run(['llvm-nm', '-S', '--size-sort', elf], capture_output=True, text=True).stdout.splitlines():
|
||||
p = l.split()
|
||||
if len(p) == 4 and p[2] in 'tT': fs.append((int(p[0], 16) & ~1, int(p[1], 16), p[3]))
|
||||
fs.sort(); starts = [f[0] for f in fs]
|
||||
cnt = collections.Counter()
|
||||
def blk(uc, addr, size, ud):
|
||||
i = bisect.bisect_right(starts, addr) - 1
|
||||
if i >= 0 and addr < fs[i][0] + fs[i][1]: cnt[fs[i][2]] += size // 2
|
||||
else: cnt['?'] += size // 2
|
||||
import builtins
|
||||
builtins.__gbprof = (blk, cnt)
|
||||
|
||||
exec(open(os.path.join(os.path.dirname(__file__), 'devpm.py')).read())
|
||||
tot = sum(cnt.values())
|
||||
for n, c in cnt.most_common(25): print('%6.2f%% %s' % (100 * c / tot, n))
|
||||
Reference in new issue
Block a user