Skip to content

Commit

Permalink
Merge remote-tracking branch 'irixxxx/master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Sep 6, 2024
2 parents 479f120 + 1b31b84 commit 6508730
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 9 deletions.
4 changes: 3 additions & 1 deletion pico/cart.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ void PicoCartUnload(void)
static unsigned int rom_crc32(int size)
{
unsigned int crc;
elprintf(EL_STATUS, "caclulating CRC32..");
elprintf(EL_STATUS, "calculating CRC32..");
if (size <= 0 || size > Pico.romsize) size = Pico.romsize;

// have to unbyteswap for calculation..
Expand Down Expand Up @@ -1140,6 +1140,8 @@ static void parse_carthw(const char *carthw_cfg, int *fill_sram,
PicoIn.AHW = PAHW_PICO;
else if (strcmp(p, "prot") == 0)
carthw_sprot_startup();
else if (strcmp(p, "flash") == 0)
carthw_flash_startup();
else if (strcmp(p, "ssf2_mapper") == 0)
carthw_ssf2_startup();
else if (strcmp(p, "x_in_1_mapper") == 0)
Expand Down
17 changes: 16 additions & 1 deletion pico/carthw.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# svp - Sega Virtua Processor
# pico - Sega Pico (not really cart hw, but convenient to support here)
# prot - simple copy protection devices in unlicensed cartridges (see prot. below)
# flash - protection through reading the flash chip ID
#
# cartridge properties (prop = ...):
# no_sram - don't emulate sram/EEPROM even if ROM headers tell it's there
Expand Down Expand Up @@ -129,6 +130,11 @@ check_str = 0x150, "STAR ODYSSEY"
hw = sf004_mapper
sram_range = 0x200000,0x207fff

# Escape 2042, reads flash ID for protection
[Escape 2042]
check_str = 0x120, "Escape 2042"
hw = flash

# detect *_in_1 based on first game and if it's larger than it should be,
# as some dumps look like to be incomplete.
# This will also pick overdumps, but those should still work with the mapper applied.
Expand Down Expand Up @@ -534,13 +540,22 @@ prot_ro_value16 = 0x400002,-2,0x0f00
prot_ro_value16 = 0x400004,-2,0xaa00
prot_ro_value16 = 0x400006,-2,0xf000

[16 Tiles Mahjong 1+2 (Unl)] # Zhang majiang
[16 Tiles Mahjong 1+2 (Unl)] # Shi liu zhang majiang
check_str = 0xfe, "WISEGAME IS TRADE MARKER"
hw = prot
prot_ro_value16 = 0x400002,-2,0xaa00
prot_ro_value16 = 0x400004,-2,0xc900
prot_ro_value16 = 0x400006,-2,0xf000

[13 Tiles Mahjong] # Shi san zhang majiang
check_str = 0x104, " "
check_crc32 = 0x83397760
hw = prot
prot_ro_value16 = 0x400000,-2,0x6300
prot_ro_value16 = 0x400002,-2,0x9800
prot_ro_value16 = 0x400004,-2,0xaa00
prot_ro_value16 = 0x400006,-2,0xf000

[Super Poker (Unl)] # Chaoji puke
check_csum = 0xffff
check_crc32 = 0xdd02797c
Expand Down
36 changes: 36 additions & 0 deletions pico/carthw/carthw.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,42 @@ void carthw_sf004_startup(void)
carthw_chunks = carthw_sf00x_state;
}

/* Simple protection through reading flash ID */
static int flash_writecount;

static carthw_state_chunk carthw_flash_state[] =
{
{ CHUNK_CARTHW, sizeof(flash_writecount), &flash_writecount },
{ 0, 0, NULL }
};

static u32 PicoRead16_flash(u32 a) { return (a&6) ? 0x2257 : 0x0020; }

static void PicoWrite16_flash(u32 a, u32 d)
{
int banksz = (1<<M68K_MEM_SHIFT)-1;
switch (++flash_writecount) {
case 3: cpu68k_map_set(m68k_read16_map, 0, banksz, PicoRead16_flash, 1);
break;
case 4: cpu68k_map_read_mem(0, banksz, Pico.rom, 0);
flash_writecount = 0;
break;
}
}

static void carthw_flash_mem_setup(void)
{
cpu68k_map_set(m68k_write16_map, 0, 0x7fffff, PicoWrite16_flash, 1);
}

void carthw_flash_startup(void)
{
elprintf(EL_STATUS, "Flash prot emu startup");

PicoCartMemSetup = carthw_flash_mem_setup;
carthw_chunks = carthw_flash_state;
}

/* Simple unlicensed ROM protection emulation */
static struct {
u32 addr;
Expand Down
1 change: 1 addition & 0 deletions pico/carthw/carthw.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void carthw_sf001_startup(void);
void carthw_sf002_startup(void);
void carthw_sf004_startup(void);

void carthw_flash_startup(void);
void carthw_sprot_startup(void);
void carthw_sprot_new_location(unsigned int a,
unsigned int mask, unsigned short val, int is_ro);
Expand Down
12 changes: 11 additions & 1 deletion pico/carthw_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ static const char builtin_carthw_cfg[] =
"hw=sf004_mapper\n"
"sram_range=0x200000,0x207fff\n"
"[]\n"
"check_str=0x120,\"Escape 2042\"\n"
"hw=flash\n"
"[]\n"
"check_str=0x120,\"FLICKY\"\n"
"check_size_gt=0x020000\n"
"hw=x_in_1_mapper\n"
Expand Down Expand Up @@ -99,7 +102,6 @@ static const char builtin_carthw_cfg[] =
"hw=radica_mapper\n"
"[]\n"
"check_str=0x150,\"STREET FIGHTER\"\n"
"check_str=0x161,\"SPECIAL CHAMPION EDITION\"\n"
"check_size_gt=0x300000\n"
"hw=radica_mapper\n"
"[]\n"
Expand Down Expand Up @@ -400,6 +402,14 @@ static const char builtin_carthw_cfg[] =
"prot_ro_value16=0x400004,-2,0xc900\n"
"prot_ro_value16=0x400006,-2,0xf000\n"
"[]\n"
"check_str=0x104,\" \"\n"
"check_crc32=0x83397760\n"
"hw=prot\n"
"prot_ro_value16=0x400000,-2,0x6300\n"
"prot_ro_value16=0x400002,-2,0x9800\n"
"prot_ro_value16=0x400004,-2,0xaa00\n"
"prot_ro_value16=0x400006,-2,0xf000\n"
"[]\n"
"check_csum=0xffff\n"
"check_crc32=0xdd02797c\n"
"hw=prot\n"
Expand Down
19 changes: 13 additions & 6 deletions pico/pico_cmn.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ static int SekSyncM68k(int once)
// accessing the main bus. Account for these by shortening the time
// the 68K CPU runs.
int z80_buscyc = Pico.t.z80_buscycles >> (~Pico.m.scanline & 1);
if (z80_buscyc <= cyc_do)
SekExecM68k(cyc_do - z80_buscyc);
else
z80_buscyc = cyc_do;
// NB the Z80 isn't fast enough to steal more than half the bandwidth.
// the fastest would be POP cc which takes 10+~3.3*2 z-cyc (~35 cyc) for a
// 16 bit value, but 68k is only blocked for ~16 cyc for the 2 bus cycles.
if (z80_buscyc > cyc_do/2)
z80_buscyc = cyc_do/2;
SekExecM68k(cyc_do - z80_buscyc);
Pico.t.m68c_cnt += z80_buscyc;
Pico.t.z80_buscycles -= z80_buscyc;
if (once) break;
Expand Down Expand Up @@ -244,9 +246,14 @@ static int PicoFrameHints(void)
pv->pending_ints |= 0x20;

if (pv->reg[1] & 0x20) {
if (Pico.t.m68c_cnt - Pico.t.m68c_aim < 60) // CPU blocked?
SekExecM68k(11); // HACK
// as per https://gendev.spritesmind.net/forum/viewtopic.php?t=2202, IRQ
// is usually sampled after operand reading, so the next instruction will
// be executed before the IRQ is taken.
if (Pico.t.m68c_cnt - Pico.t.m68c_aim < 40) // CPU blocked?
SekExecM68k(4);
elprintf(EL_INTS, "vint: @ %06x [%u]", SekPc, SekCyclesDone());
// TODO: IRQ usually sampled after operand reading, so insn can't turn it
// off? single exception is MOVE.L which samples IRQ after the 1st write?
SekInterrupt(6);
}

Expand Down
1 change: 1 addition & 0 deletions platform/libretro/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#if defined(RENDER_GSKIT_PS2)
#include <malloc.h>
#include <kernel.h>
#include "libretro-common/include/libretro_gskit_ps2.h"
#include "ps2/asm.h"
#else
Expand Down

0 comments on commit 6508730

Please sign in to comment.