#include "cz80.h"\r
\r
#if PICODRIVE_HACKS\r
-#undef EMU_M68K\r
-#include <pico/pico_int.h>\r
+#include <pico/memory.h>\r
#endif\r
\r
#ifndef ALIGN_DATA\r
\r
for (i = 0; i < CZ80_FETCH_BANK; i++)\r
{\r
- CPU->Fetch[i] = (UINT32)cz80_bad_address;\r
+ CPU->Fetch[i] = (FPTR)cz80_bad_address;\r
#if CZ80_ENCRYPTED_ROM\r
CPU->OPFetch[i] = 0;\r
#endif\r
\r
void Cz80_Reset(cz80_struc *CPU)\r
{\r
- memset(CPU, 0, (INT32)&CPU->BasePC - (INT32)CPU);\r
+ memset(CPU, 0, (FPTR)&CPU->BasePC - (FPTR)CPU);\r
Cz80_Set_Reg(CPU, CZ80_PC, 0);\r
}\r
\r
#if PICODRIVE_HACKS\r
static inline unsigned char picodrive_read(unsigned short a)\r
{\r
- unsigned long v = z80_read_map[a >> Z80_MEM_SHIFT];\r
- if (v & 0x80000000)\r
+ uptr v = z80_read_map[a >> Z80_MEM_SHIFT];\r
+ if (map_flag_set(v))\r
return ((z80_read_f *)(v << 1))(a);\r
return *(unsigned char *)((v << 1) + a);\r
}\r
#include "cz80jmp.c"\r
#endif\r
\r
- UINT32 PC;\r
+ FPTR PC;\r
#if CZ80_ENCRYPTED_ROM\r
- INT32 OPBase;\r
+ FPTR OPBase;\r
#endif\r
UINT32 Opcode;\r
UINT32 adr = 0;\r
\r
if (state != CLEAR_LINE)\r
{\r
- UINT32 PC = CPU->PC;\r
+ FPTR PC = CPU->PC;\r
#if CZ80_ENCRYPTED_ROM\r
- INT32 OPBase = CPU->OPBase;\r
+ FPTR OPBase = CPU->OPBase;\r
#endif\r
\r
CPU->IRQLine = line;\r
\83t\83F\83b\83`\83A\83h\83\8c\83X\90Ý\92è\r
--------------------------------------------------------*/\r
\r
-void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 fetch_adr)\r
+void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, FPTR fetch_adr)\r
{\r
int i, j;\r
\r
#define INT32 signed int\r
#endif\r
\r
+#ifndef FPTR\r
+#define FPTR unsigned long\r
+#endif\r
+\r
/*************************************/\r
/* Z80 core Structures & definitions */\r
/*************************************/\r
union16 IX;\r
union16 IY;\r
union16 SP;\r
- UINT32 PC;\r
+ UINT32 unusedPC; /* left for binary compat */\r
\r
union16 BC2;\r
union16 DE2;\r
INT32 ICount;\r
INT32 ExtraCycles;\r
\r
- UINT32 BasePC;\r
- UINT32 Fetch[CZ80_FETCH_BANK];\r
+ FPTR BasePC;\r
+ FPTR PC;\r
+ FPTR Fetch[CZ80_FETCH_BANK];\r
#if CZ80_ENCRYPTED_ROM\r
- INT32 OPBase;\r
- INT32 OPFetch[CZ80_FETCH_BANK];\r
+ FPTR OPBase;\r
+ FPTR OPFetch[CZ80_FETCH_BANK];\r
#endif\r
\r
UINT8 *pzR8[8];\r
UINT32 Cz80_Get_Reg(cz80_struc *CPU, INT32 regnum);\r
void Cz80_Set_Reg(cz80_struc *CPU, INT32 regnum, UINT32 value);\r
\r
-void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 fetch_adr);\r
+void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, FPTR fetch_adr);\r
#if CZ80_ENCRYPTED_ROM\r
void Cz80_Set_Encrypt_Range(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 decrypted_rom);\r
#endif\r
OP(0x18): // JR n\r
OP_JR:\r
adr = (INT8)READ_ARG();\r
- PC += adr;\r
+ PC += (INT8)adr;\r
RET(12)\r
\r
OP(0x20): // JR NZ,n\r
unsigned short a = A; \\r
unsigned char d = D; \\r
unsigned long v = z80_write_map[a >> Z80_MEM_SHIFT]; \\r
- if (v & 0x80000000) \\r
+ if (map_flag_set(v)) \\r
((z80_write_f *)(v << 1))(a, d); \\r
else \\r
*(unsigned char *)((v << 1) + a) = d; \\r
sh2_map += SH2MAP_ADDR2OFFS(a);
p = sh2_map->addr;
- if (p & (1 << 31))
+ if (map_flag_set(p))
return ((sh2_read_handler *)(p << 1))(a, sh2->is_slave);
else
return *(u8 *)((p << 1) + ((a & sh2_map->mask) ^ 1));
sh2_map += SH2MAP_ADDR2OFFS(a);
p = sh2_map->addr;
- if (p & (1 << 31))
+ if (map_flag_set(p))
return ((sh2_read_handler *)(p << 1))(a, sh2->is_slave);
else
return *(u16 *)((p << 1) + ((a & sh2_map->mask) & ~1));
offs = SH2MAP_ADDR2OFFS(a);
sh2_map += offs;
p = sh2_map->addr;
- if (!(p & (1 << 31))) {
+ if (!map_flag_set(p)) {
// XXX: maybe 32bit access instead with ror?
u16 *pd = (u16 *)((p << 1) + ((a & sh2_map->mask) & ~1));
return (pd[0] << 16) | pd[1];
}
#define MAP_MEMORY(m) ((uptr)(m) >> 1)
-#define MAP_HANDLER(h) (((uptr)(h) >> 1) | (1 << 31))
+#define MAP_HANDLER(h) ( ((uptr)(h) >> 1) | ((uptr)1 << (sizeof(uptr) * 8 - 1)) )
static sh2_memmap sh2_read8_map[0x20], sh2_read16_map[0x20];
// for writes we are using handlers only
int reg = is_write ? ((tmpv>>4)&0x7) : (tmpv&0x7);
if (reg > 4) tr_unhandled();
if ((tmpv & 0x0f) != 0 && (tmpv & 0xf0) != 0) tr_unhandled();
- known_regs.pmac_read[is_write ? reg + 5 : reg] = pmcv;
+ if (is_write)
+ known_regs.pmac_write[reg] = pmcv;
+ else
+ known_regs.pmac_read[reg] = pmcv;
known_regb |= is_write ? (1 << (reg+25)) : (1 << (reg+20));
dirty_regb |= is_write ? (1 << (reg+25)) : (1 << (reg+20));
known_regs.emu_status &= ~SSP_PMC_SET;
#define IJind (((op>>6)&4)|(op&3))
#define GET_PC() (PC - (unsigned short *)svp->iram_rom)
-#define GET_PPC_OFFS() ((unsigned int)PC - (unsigned int)svp->iram_rom - 2)
+#define GET_PPC_OFFS() ((unsigned char *)PC - svp->iram_rom - 2)
#define SET_PC(d) PC = (unsigned short *)svp->iram_rom + d
#define REG_READ(r) (((r) <= 4) ? ssp->gr[r].h : read_handlers[r]())
for (i = start_addr >> shift; i <= end_addr >> shift; i++) {\r
map[i] = addr >> 1;\r
if (is_func)\r
- map[i] |= 1 << (sizeof(addr) * 8 - 1);\r
+ map[i] |= (uptr)1 << (sizeof(addr) * 8 - 1);\r
}\r
}\r
\r
drZ80.z80_out = z80_md_out;\r
#endif\r
#ifdef _USE_CZ80\r
- Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (UINT32)Pico.zram); // main RAM\r
- Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (UINT32)Pico.zram); // mirror\r
+ Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (FPTR)Pico.zram); // main RAM\r
+ Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (FPTR)Pico.zram); // mirror\r
Cz80_Set_INPort(&CZ80, z80_md_in);\r
Cz80_Set_OUTPort(&CZ80, z80_md_out);\r
#endif\r
extern uptr s68k_write8_map [0x1000000 >> M68K_MEM_SHIFT];
extern uptr s68k_write16_map[0x1000000 >> M68K_MEM_SHIFT];
+// top-level handlers that cores can use
+// (or alternatively build them into themselves)
+// XXX: unhandled: *16 and *32 might cross the bank boundaries
+typedef u32 (cpu68k_read_f)(u32 a);
+typedef void (cpu68k_write_f)(u32 a, u32 d);
+
+// z80
+#define Z80_MEM_SHIFT 13
+extern uptr z80_read_map [0x10000 >> Z80_MEM_SHIFT];
+extern uptr z80_write_map[0x10000 >> Z80_MEM_SHIFT];
+typedef unsigned char (z80_read_f)(unsigned short a);
+typedef void (z80_write_f)(unsigned int a, unsigned char data);
+
void z80_map_set(uptr *map, int start_addr, int end_addr,
const void *func_or_mh, int is_func);
void cpu68k_map_set(uptr *map, int start_addr, int end_addr,
void cpu68k_map_all_ram(int start_addr, int end_addr, void *ptr, int is_sub);
void m68k_map_unmap(int start_addr, int end_addr);
-// top-level handlers that cores can use
-// (or alternatively build them into themselves)
-// XXX: unhandled: *16 and *32 might cross the bank boundaries
-typedef u32 (cpu68k_read_f)(u32 a);
-typedef void (cpu68k_write_f)(u32 a, u32 d);
+#define map_flag_set(x) ((x) & ((uptr)1 << (sizeof(uptr) * 8 - 1)))
#define MAKE_68K_READ8(name, map) \
u32 name(u32 a) \
uptr v; \
a &= 0x00ffffff; \
v = map[a >> M68K_MEM_SHIFT]; \
- if (v & 0x80000000) \
+ if (map_flag_set(v)) \
return ((cpu68k_read_f *)(v << 1))(a); \
else \
return *(u8 *)((v << 1) + (a ^ 1)); \
uptr v; \
a &= 0x00fffffe; \
v = map[a >> M68K_MEM_SHIFT]; \
- if (v & 0x80000000) \
+ if (map_flag_set(v)) \
return ((cpu68k_read_f *)(v << 1))(a); \
else \
return *(u16 *)((v << 1) + a); \
a &= 0x00fffffe; \
v = map[a >> M68K_MEM_SHIFT]; \
vs = v << 1; \
- if (v & 0x80000000) { \
+ if (map_flag_set(v)) { \
d = ((cpu68k_read_f *)vs)(a) << 16; \
d |= ((cpu68k_read_f *)vs)(a + 2); \
} \
uptr v; \
a &= 0x00ffffff; \
v = map[a >> M68K_MEM_SHIFT]; \
- if (v & 0x80000000) \
+ if (map_flag_set(v)) \
((cpu68k_write_f *)(v << 1))(a, d); \
else \
*(u8 *)((v << 1) + (a ^ 1)) = d; \
uptr v; \
a &= 0x00fffffe; \
v = map[a >> M68K_MEM_SHIFT]; \
- if (v & 0x80000000) \
+ if (map_flag_set(v)) \
((cpu68k_write_f *)(v << 1))(a, d); \
else \
*(u16 *)((v << 1) + a) = d; \
a &= 0x00fffffe; \
v = map[a >> M68K_MEM_SHIFT]; \
vs = v << 1; \
- if (v & 0x80000000) { \
+ if (map_flag_set(v)) { \
((cpu68k_write_f *)vs)(a, d >> 16); \
((cpu68k_write_f *)vs)(a + 2, d); \
} \
\r
PICO_INTERNAL_ASM void memcpy16(unsigned short *dest, unsigned short *src, int count)\r
{\r
- if ((((int)dest | (int)src) & 3) == 0)\r
+ if ((((long)dest | (long)src) & 3) == 0)\r
{\r
if (count >= 32) {\r
memcpy32((int *)dest, (int *)src, count/2);\r
Pico.m.frame_count = 0;\r
\r
// clear all memory of the emulated machine\r
- memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram);\r
+ memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram);\r
\r
memset(&Pico.video,0,sizeof(Pico.video));\r
memset(&Pico.m,0,sizeof(Pico.m));\r
\r
#define cycles_68k_to_z80(x) ((x)*957 >> 11)\r
\r
-#define Z80_MEM_SHIFT 13\r
-extern unsigned long z80_read_map [0x10000 >> Z80_MEM_SHIFT];\r
-extern unsigned long z80_write_map[0x10000 >> Z80_MEM_SHIFT];\r
-typedef unsigned char (z80_read_f)(unsigned short a);\r
-typedef void (z80_write_f)(unsigned int a, unsigned char data);\r
-\r
// ----------------------- SH2 CPU -----------------------\r
\r
#include "cpu/sh2/sh2.h"\r
d &= bank_mask;
z80_map_set(z80_read_map, 0x4000, 0x7fff, Pico.rom + (d << 14), 0);
#ifdef _USE_CZ80
- Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (UINT32)Pico.rom + (d << 14));
+ Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (FPTR)Pico.rom + (d << 14));
#endif
break;
case 0x0f:
d &= bank_mask;
z80_map_set(z80_read_map, 0x8000, 0xbfff, Pico.rom + (d << 14), 0);
#ifdef _USE_CZ80
- Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (UINT32)Pico.rom + (d << 14));
+ Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (FPTR)Pico.rom + (d << 14));
#endif
break;
}
{
int s, tmp;
- memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram);
+ memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram);
memset(&Pico.video,0,sizeof(Pico.video));
memset(&Pico.m,0,sizeof(Pico.m));
Pico.m.pal = 0;
drZ80.z80_out = z80_sms_out;
#endif
#ifdef _USE_CZ80
- Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (UINT32)Pico.rom);
- Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (UINT32)Pico.zram);
- Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (UINT32)Pico.zram);
+ Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (FPTR)Pico.rom);
+ Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (FPTR)Pico.zram);
+ Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (FPTR)Pico.zram);
Cz80_Set_INPort(&CZ80, z80_sms_in);
Cz80_Set_OUTPort(&CZ80, z80_sms_out);
#endif
memset32((int *) PsndOut, 0, len); // assume PsndOut to be aligned\r
else {\r
short *out = PsndOut;\r
- if ((int)out & 2) { *out++ = 0; len--; }\r
+ if ((long)out & 2) { *out++ = 0; len--; }\r
memset32((int *) out, 0, len/2);\r
if (len & 1) out[len-1] = 0;\r
}\r
+#include <stddef.h>
#include "pico_int.h"
-#include "sound/sn76496.h"
+#include "memory.h"
-#define Z80_MEM_SHIFT 13
-
-unsigned long z80_read_map [0x10000 >> Z80_MEM_SHIFT];
-unsigned long z80_write_map[0x10000 >> Z80_MEM_SHIFT];
+uptr z80_read_map [0x10000 >> Z80_MEM_SHIFT];
+uptr z80_write_map[0x10000 >> Z80_MEM_SHIFT];
#ifdef _USE_MZ80
#elif defined(_USE_CZ80)
*(int *)data = 0x00007a43; // "Cz"
*(int *)(data+4) = Cz80_Get_Reg(&CZ80, CZ80_PC);
- memcpy(data+8, &CZ80, (INT32)&CZ80.BasePC - (INT32)&CZ80);
+ memcpy(data+8, &CZ80, offsetof(cz80_struc, BasePC));
#endif
}
}
#elif defined(_USE_CZ80)
if (*(int *)data == 0x00007a43) { // "Cz" save?
- memcpy(&CZ80, data+8, (INT32)&CZ80.BasePC - (INT32)&CZ80);
+ memcpy(&CZ80, data+8, offsetof(cz80_struc, BasePC));
Cz80_Set_Reg(&CZ80, CZ80_PC, *(int *)(data+4));
} else {
z80_reset();
#if defined(_USE_DRZ80)
sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", drZ80.Z80PC-drZ80.Z80PC_BASE, drZ80.Z80SP-drZ80.Z80SP_BASE);
#elif defined(_USE_CZ80)
- sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", CZ80.PC - CZ80.BasePC, CZ80.SP.W);
+ sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", (unsigned int)(CZ80.PC - CZ80.BasePC), CZ80.SP.W);
#endif
}
// check for both gmv and rom\r
int dummy;\r
FILE *movie_file = fopen(rom_fname, "rb");\r
- if(!movie_file) {\r
+ if (!movie_file) {\r
me_update_msg("Failed to open movie.");\r
return 0;\r
}\r
fseek(movie_file, 0, SEEK_END);\r
movie_size = ftell(movie_file);\r
fseek(movie_file, 0, SEEK_SET);\r
- if(movie_size < 64+3) {\r
+ if (movie_size < 64+3) {\r
me_update_msg("Invalid GMV file.");\r
fclose(movie_file);\r
return 0;\r
}\r
movie_data = malloc(movie_size);\r
- if(movie_data == NULL) {\r
+ if (movie_data == NULL) {\r
me_update_msg("low memory.");\r
fclose(movie_file);\r
return 0;\r
}\r
- fread(movie_data, 1, movie_size, movie_file);\r
+ dummy = fread(movie_data, 1, movie_size, movie_file);\r
fclose(movie_file);\r
if (strncmp((char *)movie_data, "Gens Movie TEST", 15) != 0) {\r
me_update_msg("Invalid GMV file.");\r
sram_size = SRam.size;\r
sram_data = SRam.data;\r
}\r
- if (!sram_data) return 0; // SRam forcefully disabled for this game\r
+ if (sram_data == NULL)\r
+ return 0; // SRam forcefully disabled for this game\r
\r
if (load)\r
{\r
sramFile = fopen(saveFname, "rb");\r
- if(!sramFile) return -1;\r
- fread(sram_data, 1, sram_size, sramFile);\r
+ if (!sramFile)\r
+ return -1;\r
+ ret = fread(sram_data, 1, sram_size, sramFile);\r
+ ret = ret > 0 ? 0 : -1;\r
fclose(sramFile);\r
if ((PicoAHW & PAHW_MCD) && (PicoOpt&POPT_EN_MCD_RAMCART))\r
memcpy32((int *)Pico_mcd->bram, (int *)sram_data, 0x2000/4);\r
lprintf("found skin.txt\n");\r
while (!feof(f))\r
{\r
- fgets(buff, sizeof(buff), f);\r
+ if (fgets(buff, sizeof(buff), f) == NULL)\r
+ break;\r
if (buff[0] == '#' || buff[0] == '/') continue; // comment\r
if (buff[0] == '\r' || buff[0] == '\n') continue; // empty line\r
if (strncmp(buff, "text_color=", 11) == 0)\r
\r
static int scandir_cmp(const void *p1, const void *p2)\r
{\r
- struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;\r
- if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);\r
- if ((*d1)->d_type == DT_DIR) return -1; // put before\r
- if ((*d2)->d_type == DT_DIR) return 1;\r
+ const struct dirent **d1 = (const struct dirent **)p1;\r
+ const struct dirent **d2 = (const struct dirent **)p2;\r
+ if ((*d1)->d_type == (*d2)->d_type)\r
+ return alphasort(d1, d2);\r
+ if ((*d1)->d_type == DT_DIR)\r
+ return -1; // put before\r
+ if ((*d2)->d_type == DT_DIR)\r
+ return 1;\r
+\r
return alphasort(d1, d2);\r
}\r
\r
fname = p+1;\r
}\r
\r
- n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);\r
+ n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp);\r
if (n < 0) {\r
lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
\r
// try root\r
- getcwd(curr_path, len);\r
- n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);\r
+ plat_get_root_dir(curr_path, len);\r
+ n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp);\r
if (n < 0) {\r
// oops, we failed\r
lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
static int in_gp2x_get_wiz_bits(void)
{
- int value = 0;
- read(gpiodev, &value, 4);
+ int r, value = 0;
+ r = read(gpiodev, &value, 4);
if (value & 0x02)
value |= 0x05;
if (value & 0x08)
if (sounddev == -1)
{
perror("open(\"/dev/dsp\")");
- return -1;
+ sounddev = open("/dev/dsp1", O_WRONLY|O_ASYNC);
+ if (sounddev == -1) {
+ perror("open(\"/dev/dsp1\")");
+ return -1;
+ }
}
// calculate buffer size. We one to fit 1 frame worth of sound data.