Skip to content

Commit 922c335

Browse files
committed
core, add internal pad and mouse data to io save state
1 parent 4a52114 commit 922c335

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

pico/memory.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,13 @@ int io_ports_pack(void *buf, size_t size)
618618
for (i = 0; i < ARRAY_SIZE(Pico.m.padDelay); i++)
619619
save_u8_(buf, &b, Pico.m.padDelay[i]);
620620
for (i = 0; i < ARRAY_SIZE(padTHLatency); i++) {
621-
save_u32(buf, &b, padTHLatency[i]);
622-
save_u32(buf, &b, padTLLatency[i]);
621+
save_s32(buf, &b, padTHLatency[i]);
622+
save_s32(buf, &b, padTLLatency[i]);
623623
}
624+
for (i = 0; i < 4; i++)
625+
save_u16(buf, &b, PicoIn.padInt[i]);
626+
for (i = 0; i < 4; i++)
627+
save_s32(buf, &b, PicoIn.mouseInt[i]);
624628
assert(b <= size);
625629
return b;
626630
}
@@ -634,9 +638,13 @@ void io_ports_unpack(const void *buf, size_t size)
634638
for (i = 0; i < ARRAY_SIZE(Pico.m.padDelay); i++)
635639
Pico.m.padDelay[i] = load_u8_(buf, &b);
636640
for (i = 0; i < ARRAY_SIZE(padTHLatency); i++) {
637-
padTHLatency[i] = load_u32(buf, &b);
638-
padTLLatency[i] = load_u32(buf, &b);
641+
padTHLatency[i] = load_s32(buf, &b);
642+
padTLLatency[i] = load_s32(buf, &b);
639643
}
644+
for (i = 0; i < 4; i++)
645+
PicoIn.padInt[i] = load_u16(buf, &b);
646+
for (i = 0; i < 4; i++)
647+
PicoIn.mouseInt[i] = load_s32(buf, &b);
640648
assert(b <= size);
641649
}
642650

pico/pico.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,18 @@ typedef struct PicoInterface
109109
{
110110
unsigned int opt; // POPT_* bitfield
111111

112-
unsigned short pad[4]; // Joypads, format is MXYZ SACB RLDU
113-
unsigned short padInt[4]; // internal copy
114-
unsigned short AHW; // active addon hardware: PAHW_* bitfield
112+
unsigned short pad[4]; // Joypads, format is MXYZ SACB RLDU
113+
unsigned short padInt[4]; // internal copy
114+
unsigned short AHW; // active addon hardware: PAHW_* bitfield
115+
116+
unsigned short kbd; // SC-3000 or Pico Keyboard
117+
int mouse[4]; // x,y mouse coordinates
118+
int mouseInt[4]; // internal copy
119+
120+
unsigned short quirks; // game-specific quirks: PQUIRK_*
121+
unsigned short overclockM68k; // overclock the emulated 68k, in %
122+
123+
unsigned short filter; // softscale filter type
115124

116125
unsigned short skipFrame; // skip rendering frame, but still do sound (if enabled) and emulation stuff
117126
unsigned short regionOverride; // override the region detection 0: auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe
@@ -120,11 +129,6 @@ typedef struct PicoInterface
120129
unsigned int mapper; // mapper selection for SMS, 0 = auto
121130
unsigned int tmsPalette; // palette used by SMS in TMS graphic modes
122131

123-
unsigned short quirks; // game-specific quirks: PQUIRK_*
124-
unsigned short overclockM68k; // overclock the emulated 68k, in %
125-
126-
unsigned short filter; // softscale filter type
127-
128132
int sndRate; // rate in Hz
129133
int sndFilterAlpha; // Low pass sound filter alpha (Q16)
130134
short *sndOut; // PCM output buffer
@@ -134,10 +138,6 @@ typedef struct PicoInterface
134138

135139
void (*mcdTrayOpen)(void);
136140
void (*mcdTrayClose)(void);
137-
138-
int mouse[4]; // x,y mouse coordinates
139-
int mouseInt[4]; // internal copy
140-
unsigned int kbd; // SC-3000 or Pico Keyboard
141141
} PicoInterface;
142142

143143
extern PicoInterface PicoIn;

pico/state.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ static inline void save_u32(u8 *buf, size_t *b, u32 u)
4646
buf[(*b)++] = u >> 24;
4747
}
4848

49+
static inline void save_s32(u8 *buf, size_t *b, s32 s)
50+
{
51+
buf[(*b)++] = s;
52+
buf[(*b)++] = s >> 8;
53+
buf[(*b)++] = s >> 16;
54+
buf[(*b)++] = s >> 24;
55+
}
56+
4957
static inline u8 load_u8_(const u8 *buf, size_t *b)
5058
{
5159
return buf[(*b)++];
@@ -76,3 +84,10 @@ static inline u32 load_u32(const u8 *buf, size_t *b)
7684
(*b) += 4;
7785
return r;
7886
}
87+
88+
static inline s32 load_s32(const u8 *buf, size_t *b)
89+
{
90+
s32 r = (buf[*b + 3] << 24) | (buf[*b + 2] << 16) | (buf[*b + 1] << 8) | buf[*b];
91+
(*b) += 4;
92+
return r;
93+
}

0 commit comments

Comments
 (0)