mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
improve input handling
This commit is contained in:
parent
be7867d875
commit
531a8f3883
12 changed files with 170 additions and 108 deletions
132
pico/memory.c
132
pico/memory.c
|
@ -186,62 +186,119 @@ void cyclone_crashed(u32 pc, struct Cyclone *context)
|
|||
// -----------------------------------------------------------------
|
||||
// memmap helpers
|
||||
|
||||
#ifndef _ASM_MEMORY_C
|
||||
static
|
||||
#endif
|
||||
int PadRead(int i)
|
||||
static u32 read_pad_3btn(int i, u32 out_bits)
|
||||
{
|
||||
int pad,value,data_reg;
|
||||
pad=~PicoPadInt[i]; // Get inverse of pad MXYZ SACB RLDU
|
||||
data_reg=Pico.ioports[i+1];
|
||||
u32 pad = ~PicoPadInt[i]; // Get inverse of pad MXYZ SACB RLDU
|
||||
u32 value;
|
||||
|
||||
// orr the bits, which are set as output
|
||||
value = data_reg&(Pico.ioports[i+4]|0x80);
|
||||
if (out_bits & 0x40) // TH
|
||||
value = pad & 0x3f; // ?1CB RLDU
|
||||
else
|
||||
value = ((pad & 0xc0) >> 2) | (pad & 3); // ?0SA 00DU
|
||||
|
||||
if (PicoOpt & POPT_6BTN_PAD)
|
||||
{
|
||||
int phase = Pico.m.padTHPhase[i];
|
||||
|
||||
if(phase == 2 && !(data_reg&0x40)) { // TH
|
||||
value|=(pad&0xc0)>>2; // ?0SA 0000
|
||||
return value;
|
||||
} else if(phase == 3) {
|
||||
if(data_reg&0x40)
|
||||
value|=(pad&0x30)|((pad>>8)&0xf); // ?1CB MXYZ
|
||||
else
|
||||
value|=((pad&0xc0)>>2)|0x0f; // ?0SA 1111
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
if(data_reg&0x40) // TH
|
||||
value|=(pad&0x3f); // ?1CB RLDU
|
||||
else value|=((pad&0xc0)>>2)|(pad&3); // ?0SA 00DU
|
||||
|
||||
return value; // will mirror later
|
||||
value |= out_bits & 0x40;
|
||||
return value;
|
||||
}
|
||||
|
||||
#ifndef _ASM_MEMORY_C
|
||||
static u32 read_pad_6btn(int i, u32 out_bits)
|
||||
{
|
||||
u32 pad = ~PicoPadInt[i]; // Get inverse of pad MXYZ SACB RLDU
|
||||
int phase = Pico.m.padTHPhase[i];
|
||||
u32 value;
|
||||
|
||||
static u32 io_ports_read(u32 a)
|
||||
if (phase == 2 && !(out_bits & 0x40)) {
|
||||
value = (pad & 0xc0) >> 2; // ?0SA 0000
|
||||
goto out;
|
||||
}
|
||||
else if(phase == 3) {
|
||||
if (out_bits & 0x40)
|
||||
return (pad & 0x30) | ((pad >> 8) & 0xf); // ?1CB MXYZ
|
||||
else
|
||||
return ((pad & 0xc0) >> 2) | 0x0f; // ?0SA 1111
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (out_bits & 0x40) // TH
|
||||
value = pad & 0x3f; // ?1CB RLDU
|
||||
else
|
||||
value = ((pad & 0xc0) >> 2) | (pad & 3); // ?0SA 00DU
|
||||
|
||||
out:
|
||||
value |= out_bits & 0x40;
|
||||
return value;
|
||||
}
|
||||
|
||||
static u32 read_nothing(int i, u32 out_bits)
|
||||
{
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
typedef u32 (port_read_func)(int index, u32 out_bits);
|
||||
|
||||
static port_read_func *port_readers[3] = {
|
||||
read_pad_3btn,
|
||||
read_pad_3btn,
|
||||
read_nothing
|
||||
};
|
||||
|
||||
static NOINLINE u32 port_read(int i)
|
||||
{
|
||||
u32 data_reg = Pico.ioports[i + 1];
|
||||
u32 ctrl_reg = Pico.ioports[i + 4] | 0x80;
|
||||
u32 in, out;
|
||||
|
||||
out = data_reg & ctrl_reg;
|
||||
out |= 0x7f & ~ctrl_reg; // pull-ups
|
||||
|
||||
in = port_readers[i](i, out);
|
||||
|
||||
return (in & ~ctrl_reg) | (data_reg & ctrl_reg);
|
||||
}
|
||||
|
||||
void PicoSetInputDevice(int port, enum input_device device)
|
||||
{
|
||||
port_read_func *func;
|
||||
|
||||
if (port < 0 || port > 2)
|
||||
return;
|
||||
|
||||
switch (device) {
|
||||
case PICO_INPUT_PAD_3BTN:
|
||||
func = read_pad_3btn;
|
||||
break;
|
||||
|
||||
case PICO_INPUT_PAD_6BTN:
|
||||
func = read_pad_6btn;
|
||||
break;
|
||||
|
||||
default:
|
||||
func = read_nothing;
|
||||
break;
|
||||
}
|
||||
|
||||
port_readers[port] = func;
|
||||
}
|
||||
|
||||
NOINLINE u32 io_ports_read(u32 a)
|
||||
{
|
||||
u32 d;
|
||||
a = (a>>1) & 0xf;
|
||||
switch (a) {
|
||||
case 0: d = Pico.m.hardware; break; // Hardware value (Version register)
|
||||
case 1: d = PadRead(0); break;
|
||||
case 2: d = PadRead(1); break;
|
||||
case 1: d = port_read(0); break;
|
||||
case 2: d = port_read(1); break;
|
||||
case 3: d = port_read(2); break;
|
||||
default: d = Pico.ioports[a]; break; // IO ports can be used as RAM
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
static void NOINLINE io_ports_write(u32 a, u32 d)
|
||||
NOINLINE void io_ports_write(u32 a, u32 d)
|
||||
{
|
||||
a = (a>>1) & 0xf;
|
||||
|
||||
// 6 button gamepad: if TH went from 0 to 1, gamepad changes state
|
||||
if (1 <= a && a <= 2 && (PicoOpt & POPT_6BTN_PAD))
|
||||
if (1 <= a && a <= 2)
|
||||
{
|
||||
Pico.m.padDelay[a - 1] = 0;
|
||||
if (!(Pico.ioports[a] & 0x40) && (d & 0x40))
|
||||
|
@ -252,8 +309,6 @@ static void NOINLINE io_ports_write(u32 a, u32 d)
|
|||
Pico.ioports[a] = d;
|
||||
}
|
||||
|
||||
#endif // _ASM_MEMORY_C
|
||||
|
||||
void NOINLINE ctl_write_z80busreq(u32 d)
|
||||
{
|
||||
d&=1; d^=1;
|
||||
|
@ -1177,3 +1232,4 @@ static void z80_mem_setup(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
// vim:shiftwidth=2:ts=2:expandtab
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
.equ SRR_MAPPED, (1 << 0)
|
||||
.equ SRR_READONLY, (1 << 1)
|
||||
.equ SRF_EEPROM, (1 << 1)
|
||||
.equ POPT_6BTN_PAD, (1 << 5)
|
||||
.equ POPT_EN_32X, (1 << 20)
|
||||
|
||||
.text
|
||||
|
@ -67,24 +66,7 @@ m_read8_eeprom:
|
|||
PicoRead8_io: @ u32 a, u32 d
|
||||
bic r2, r0, #0x001f @ most commonly we get i/o port read,
|
||||
cmp r2, #0xa10000 @ so check for it first
|
||||
bne m_read8_not_io
|
||||
|
||||
m_read8_misc_io:
|
||||
ands r0, r0, #0x1e
|
||||
beq m_read8_misc_hwreg
|
||||
cmp r0, #4
|
||||
movlt r0, #0
|
||||
moveq r0, #1
|
||||
ble PadRead
|
||||
ldr r3, =(Pico+0x22000)
|
||||
mov r0, r0, lsr #1 @ other IO ports (Pico.ioports[a])
|
||||
ldrb r0, [r3, r0]
|
||||
bx lr
|
||||
|
||||
m_read8_misc_hwreg:
|
||||
ldr r3, =(Pico+0x22200)
|
||||
ldrb r0, [r3, #0x0f] @ Pico.m.hardware
|
||||
bx lr
|
||||
beq io_ports_read
|
||||
|
||||
m_read8_not_io:
|
||||
and r2, r0, #0xfc00
|
||||
|
@ -161,7 +143,7 @@ PicoRead16_io: @ u32 a, u32 d
|
|||
cmp r2, #0xa10000 @ so check for it first
|
||||
bne m_read16_not_io
|
||||
stmfd sp!,{lr}
|
||||
bl m_read8_misc_io @ same as read8
|
||||
bl io_ports_read @ same as read8
|
||||
orr r0, r0, r0, lsl #8 @ only has bytes mirrored
|
||||
ldmfd sp!,{pc}
|
||||
|
||||
|
@ -201,37 +183,7 @@ PicoWrite8_io: @ u32 a, u32 d
|
|||
bic r2, r0, #0x1e @ most commonly we get i/o port write,
|
||||
eor r2, r2, #0xa10000 @ so check for it first
|
||||
eors r2, r2, #1
|
||||
bne m_write8_not_io
|
||||
|
||||
m_write8_io:
|
||||
ldr r2, =PicoOpt
|
||||
and r0, r0, #0x1e
|
||||
ldr r2, [r2]
|
||||
ldr r3, =(Pico+0x22000) @ Pico.ioports
|
||||
tst r2, #POPT_6BTN_PAD
|
||||
beq m_write8_io_done
|
||||
cmp r0, #2
|
||||
cmpne r0, #4
|
||||
bne m_write8_io_done @ not likely to happen
|
||||
add r2, r3, #0x200 @ Pico+0x22200
|
||||
mov r12,#0
|
||||
cmp r0, #2
|
||||
streqb r12,[r2,#0x18]
|
||||
strneb r12,[r2,#0x19] @ Pico.m.padDelay[i] = 0
|
||||
tst r1, #0x40 @ TH
|
||||
beq m_write8_io_done
|
||||
ldrb r12,[r3, r0, lsr #1]
|
||||
tst r12,#0x40
|
||||
bne m_write8_io_done
|
||||
cmp r0, #2
|
||||
ldreqb r12,[r2,#0x0a]
|
||||
ldrneb r12,[r2,#0x0b] @ Pico.m.padTHPhase
|
||||
add r12,r12,#1
|
||||
streqb r12,[r2,#0x0a]
|
||||
strneb r12,[r2,#0x0b] @ Pico.m.padTHPhase
|
||||
m_write8_io_done:
|
||||
strb r1, [r3, r0, lsr #1]
|
||||
bx lr
|
||||
beq io_ports_write
|
||||
|
||||
m_write8_not_io:
|
||||
tst r0, #1
|
||||
|
@ -270,7 +222,7 @@ m_write8_not_sreg:
|
|||
PicoWrite16_io: @ u32 a, u32 d
|
||||
bic r2, r0, #0x1f @ most commonly we get i/o port write,
|
||||
cmp r2, #0xa10000 @ so check for it first
|
||||
beq m_write8_io
|
||||
beq io_ports_write
|
||||
|
||||
m_write16_not_io:
|
||||
and r2, r0, #0xff00
|
||||
|
|
|
@ -70,6 +70,9 @@ void PicoPower(void)
|
|||
Pico.video.pending_ints=0;
|
||||
z80_reset();
|
||||
|
||||
// my MD1 VA6 console has this in IO
|
||||
Pico.ioports[1] = Pico.ioports[2] = Pico.ioports[3] = 0xff;
|
||||
|
||||
// default VDP register values (based on Fusion)
|
||||
Pico.video.reg[0] = Pico.video.reg[1] = 0x04;
|
||||
Pico.video.reg[0xc] = 0x81;
|
||||
|
|
10
pico/pico.h
10
pico/pico.h
|
@ -52,7 +52,7 @@ extern void *p32x_bios_g, *p32x_bios_m, *p32x_bios_s;
|
|||
#define POPT_EN_Z80 (1<< 2)
|
||||
#define POPT_EN_STEREO (1<< 3)
|
||||
#define POPT_ALT_RENDERER (1<< 4) // 00 00x0
|
||||
#define POPT_6BTN_PAD (1<< 5)
|
||||
// unused (1<< 5)
|
||||
// unused (1<< 6)
|
||||
#define POPT_ACC_SPRITES (1<< 7)
|
||||
#define POPT_DIS_32C_BORDER (1<< 8) // 00 0x00
|
||||
|
@ -248,6 +248,14 @@ int PicoCdCheck(const char *fname_in, int *pregion);
|
|||
|
||||
extern unsigned char media_id_header[0x100];
|
||||
|
||||
// memory.c
|
||||
enum input_device {
|
||||
PICO_INPUT_NOTHING,
|
||||
PICO_INPUT_PAD_3BTN,
|
||||
PICO_INPUT_PAD_6BTN,
|
||||
};
|
||||
void PicoSetInputDevice(int port, enum input_device device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // End of extern "C"
|
||||
#endif
|
||||
|
|
|
@ -14,11 +14,10 @@
|
|||
#define CYCLES_S68K_ASD 241
|
||||
|
||||
// pad delay (for 6 button pads)
|
||||
#define PAD_DELAY \
|
||||
if (PicoOpt&POPT_6BTN_PAD) { \
|
||||
if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
|
||||
if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
|
||||
}
|
||||
#define PAD_DELAY() { \
|
||||
if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
|
||||
if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
|
||||
}
|
||||
|
||||
// CPUS_RUN
|
||||
#ifndef CPUS_RUN
|
||||
|
@ -114,7 +113,7 @@ static int PicoFrameHints(void)
|
|||
Pico.video.status|=0x200;
|
||||
}
|
||||
|
||||
PAD_DELAY
|
||||
PAD_DELAY();
|
||||
#ifdef PICO_CD
|
||||
check_cd_dma();
|
||||
#endif
|
||||
|
@ -187,7 +186,7 @@ static int PicoFrameHints(void)
|
|||
Pico.video.status|=0x200;
|
||||
|
||||
memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
|
||||
PAD_DELAY
|
||||
PAD_DELAY();
|
||||
#ifdef PICO_CD
|
||||
check_cd_dma();
|
||||
#endif
|
||||
|
@ -257,7 +256,7 @@ static int PicoFrameHints(void)
|
|||
pv->v_counter = (pv->v_counter << 1) | 1;
|
||||
pv->v_counter &= 0xff;
|
||||
|
||||
PAD_DELAY
|
||||
PAD_DELAY();
|
||||
#ifdef PICO_CD
|
||||
check_cd_dma();
|
||||
#endif
|
||||
|
|
|
@ -598,7 +598,6 @@ unsigned int PicoRead8_io(unsigned int a);
|
|||
unsigned int PicoRead16_io(unsigned int a);
|
||||
void PicoWrite8_io(unsigned int a, unsigned int d);
|
||||
void PicoWrite16_io(unsigned int a, unsigned int d);
|
||||
void p32x_dreq1_trigger(void);
|
||||
|
||||
// pico/memory.c
|
||||
PICO_INTERNAL void PicoMemSetupPico(void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue