Skip to content

Commit 56c6a2c

Browse files
committed
Minor WinUAE merges
1 parent bc607fe commit 56c6a2c

File tree

4 files changed

+163
-89
lines changed

4 files changed

+163
-89
lines changed

src/cia.cpp

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ static unsigned int ciabpra;
6262

6363
static unsigned long ciaala, ciaalb, ciabla, ciablb;
6464
static int ciaatodon, ciabtodon;
65-
static unsigned int ciaapra, ciaaprb, ciaadra, ciaadrb, ciaasdr, ciaasdr_cnt;
66-
static unsigned int ciabprb, ciabdra, ciabdrb, ciabsdr, ciabsdr_cnt;
65+
static unsigned int ciaapra, ciaaprb, ciaadra, ciaadrb, ciaasdr, ciaasdr_buf, ciaasdr_load, ciaasdr_cnt;
66+
static unsigned int ciabprb, ciabdra, ciabdrb, ciabsdr, ciabsdr_buf, ciabsdr_load, ciabsdr_cnt;
6767
static int div10;
6868
static int kbstate, kblostsynccnt;
6969
static uae_u8 kbcode;
@@ -191,6 +191,7 @@ static int CIA_update_check (void)
191191
div10 = ccount % DIV10;
192192

193193
/* CIA A timers */
194+
// A INMODE=0
194195
if ((ciaacra & 0x21) == 0x01) {
195196
bool check = true;
196197
unsigned long int cc = ciaclocks;
@@ -205,9 +206,20 @@ static int CIA_update_check (void)
205206
}
206207
if (check) {
207208
if ((ciaata + 1) == cc) {
208-
if ((ciaacra & 0x48) == 0x40 && ciaasdr_cnt > 0 && --ciaasdr_cnt == 0)
209+
// SP in output mode (data sent can be ignored)
210+
if ((ciaacra & 0x48) == 0x40 && ciaasdr_cnt > 0) {
211+
ciaasdr_cnt--;
212+
if (ciaasdr_cnt == 0) {
209213
asp = 1;
214+
if (ciaasdr_load) {
215+
ciaasdr_load = 0;
216+
ciaasdr_buf = ciaasdr;
217+
ciaasdr_cnt = 8 * 2;
218+
}
219+
}
220+
}
210221
aovfla = 1;
222+
// B INMODE=10 or 11
211223
if ((ciaacrb & 0x61) == 0x41 || (ciaacrb & 0x61) == 0x61) {
212224
if (ciaatb-- == 0)
213225
aovflb = 1;
@@ -216,6 +228,7 @@ static int CIA_update_check (void)
216228
ciaata -= cc;
217229
}
218230
}
231+
// A INMODE=00
219232
if ((ciaacrb & 0x61) == 0x01) {
220233
bool check = true;
221234
unsigned long int cc = ciaclocks;
@@ -236,6 +249,7 @@ static int CIA_update_check (void)
236249
}
237250

238251
/* CIA B timers */
252+
// A INMODE=0
239253
if ((ciabcra & 0x21) == 0x01) {
240254
bool check = true;
241255
unsigned long int cc = ciaclocks;
@@ -250,9 +264,23 @@ static int CIA_update_check (void)
250264
}
251265
if (check) {
252266
if ((ciabta + 1) == cc) {
253-
if ((ciabcra & 0x48) == 0x40 && ciabsdr_cnt > 0 && --ciabsdr_cnt == 0)
267+
// SP in output mode
268+
if ((ciabcra & 0x48) == 0x40 && ciabsdr_cnt > 0) {
269+
ciaasdr_cnt--;
270+
if (!(ciaasdr_cnt & 1)) {
271+
ciabsdr_buf <<= 1;
272+
}
273+
if (ciabsdr_cnt == 0) {
254274
bsp = 1;
275+
if (ciabsdr_load) {
276+
ciabsdr_load = 0;
277+
ciabsdr_buf = ciabsdr;
278+
ciabsdr_cnt = 8 * 2;
279+
}
280+
}
281+
}
255282
bovfla = 1;
283+
// B INMODE=10 or 11
256284
if ((ciabcrb & 0x61) == 0x41 || (ciabcrb & 0x61) == 0x61) {
257285
if (ciabtb-- == 0)
258286
bovflb = 1;
@@ -261,6 +289,7 @@ static int CIA_update_check (void)
261289
ciabta -= cc;
262290
}
263291
}
292+
// B INMODE=00
264293
if ((ciabcrb & 0x61) == 0x01) {
265294
bool check = true;
266295
unsigned long int cc = ciaclocks;
@@ -623,6 +652,7 @@ STATIC_INLINE void check_led (void)
623652
static void bfe001_change (void)
624653
{
625654
uae_u8 v = ciaapra;
655+
v |= ~ciaadra; /* output is high when pin's direction is input */
626656
check_led ();
627657
if (currprefs.cs_ciaoverlay && (v & 1) != oldovl) {
628658
oldovl = v & 1;
@@ -663,17 +693,22 @@ static uae_u8 ReadCIAA (unsigned int addr, uae_u32 *flags)
663693
}
664694
case 1:
665695
tmp = handle_parport_joystick (0, ciaaprb, ciaadrb);
696+
// PBON
666697
if (ciaacrb & 2) {
667698
int pb7 = 0;
668-
if (ciaacrb & 4)
699+
// OUTMODE
700+
if (ciaacrb & 4) {
669701
pb7 = ciaacrb & 1;
702+
}
670703
tmp &= ~0x80;
671704
tmp |= pb7 ? 0x80 : 00;
672705
}
673706
if (ciaacra & 2) {
674707
int pb6 = 0;
675-
if (ciaacra & 4)
708+
// OUTMODE
709+
if (ciaacra & 4) {
676710
pb6 = ciaacra & 1;
711+
}
677712
tmp &= ~0x40;
678713
tmp |= pb6 ? 0x40 : 00;
679714
}
@@ -752,13 +787,15 @@ static uae_u8 ReadCIAB (unsigned int addr, uae_u32 *flags)
752787
return tmp;
753788
case 1:
754789
tmp = ciabprb;
790+
// A PBON
755791
if (ciabcrb & 2) {
756792
int pb7 = 0;
757793
if (ciabcrb & 4)
758794
pb7 = ciabcrb & 1;
759795
tmp &= ~0x80;
760796
tmp |= pb7 ? 0x80 : 00;
761797
}
798+
// B PBON
762799
if (ciabcra & 2) {
763800
int pb6 = 0;
764801
if (ciabcra & 4)
@@ -965,6 +1002,25 @@ static void WriteCIAB (uae_u16 addr, uae_u8 val, uae_u32 *flags)
9651002
case 1:
9661003
*flags |= 2;
9671004
ciabprb = val;
1005+
// PBON overrides PB6 and PB7
1006+
if (ciabcrb & 2) {
1007+
int pb7 = 0;
1008+
// OUTMODE
1009+
if (ciabcrb & 4) {
1010+
pb7 = ciabcrb & 1;
1011+
}
1012+
val &= ~0x80;
1013+
val |= pb7 ? 0x80 : 00;
1014+
}
1015+
if (ciabcra & 2) {
1016+
int pb6 = 0;
1017+
// OUTMODE
1018+
if (ciabcra & 4) {
1019+
pb6 = ciabcra & 1;
1020+
}
1021+
val &= ~0x40;
1022+
val |= pb6 ? 0x40 : 00;
1023+
}
9681024
DISK_select(val);
9691025
break;
9701026
case 2:
@@ -1098,10 +1154,9 @@ void CIA_reset(void)
10981154
ciaaalarm = ciabalarm = 0;
10991155
ciabpra = 0x8C; ciabdra = 0;
11001156
div10 = 0;
1101-
ciaasdr_cnt = 0; ciaasdr = 0;
1102-
ciabsdr_cnt = 0; ciabsdr = 0;
1157+
ciaasdr_cnt = 0; ciaasdr = 0; ciaasdr_load = 0;
1158+
ciabsdr_cnt = 0; ciabsdr = 0; ciabsdr_buf = 0; ciabsdr_load = 0;
11031159
ciaata_passed = ciaatb_passed = ciabta_passed = ciabtb_passed = 0;
1104-
ciaatol = ciabtol = ciaaprb = ciaadrb = ciabprb = ciabdrb = 0;
11051160
CIA_calctimers();
11061161
DISK_select_set(ciabprb);
11071162
}
@@ -1678,9 +1733,14 @@ uae_u8 *save_cia (int num, int *len, uae_u8 *dstptr)
16781733
b |= ciabtodon ? 2 : 0;
16791734
else
16801735
b |= ciaatodon ? 2 : 0; /* TOD stopped? */
1736+
if (num)
1737+
b |= ciabsdr_load ? 4 : 0;
1738+
else
1739+
b |= ciaasdr_load ? 2 : 0; /* TOD stopped? */
16811740
save_u8 (b);
16821741
save_u8 (num ? div10 / CYCLE_UNIT : 0);
16831742
save_u8 (num ? ciabsdr_cnt : ciaasdr_cnt);
1743+
save_u8(num ? ciabsdr_buf : ciaasdr_buf);
16841744
*len = dst - dstbak;
16851745
return dstbak;
16861746
}

src/inputdevice.cpp

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@ void tablet_lightpen(int tx, int ty, int tmaxx, int tmaxy, int touch, int button
23632363
}
23642364

23652365
if (touch >= 0)
2366-
lightpen_active = true;
2366+
lightpen_active |= 1;
23672367

23682368
if (touch > 0 && devid >= 0) {
23692369
setmousebuttonstate (devid, 0, 1);
@@ -2374,7 +2374,7 @@ void tablet_lightpen(int tx, int ty, int tmaxx, int tmaxy, int touch, int button
23742374

23752375
end:
23762376
if (lightpen_active) {
2377-
lightpen_active = false;
2377+
lightpen_active &= ~1;
23782378
if (devid >= 0)
23792379
setmousebuttonstate (devid, 0, 0);
23802380
}
@@ -3020,12 +3020,13 @@ static void charge_cap (int joy, int idx, int charge)
30203020
pot_cap[joy][idx] = 511;
30213021
}
30223022

3023-
static void cap_check (void)
3023+
static void cap_check(bool hsync)
30243024
{
30253025
int joy, i;
30263026

30273027
for (joy = 0; joy < 2; joy++) {
30283028
for (i = 0; i < 2; i++) {
3029+
bool cancharge = true;
30293030
int charge = 0, dong, joypot;
30303031
uae_u16 pdir = 0x0200 << (joy * 4 + i * 2); /* output enable */
30313032
uae_u16 pdat = 0x0100 << (joy * 4 + i * 2); /* data */
@@ -3060,13 +3061,14 @@ static void cap_check (void)
30603061
charge = 1; // slow charge via pull-up resistor
30613062
//}
30623063
if (!(potgo_value & pdir)) { // input?
3063-
if (pot_dat_act[joy][i])
3064+
if (pot_dat_act[joy][i] && hsync)
30643065
pot_dat[joy][i]++;
30653066
/* first 7 or 8 lines after potgo has been started = discharge cap */
30663067
if (pot_dat_act[joy][i] == 1) {
30673068
if (pot_dat[joy][i] < (currprefs.ntscmode ? POTDAT_DELAY_NTSC : POTDAT_DELAY_PAL)) {
30683069
charge = -2; /* fast discharge delay */
3069-
} else {
3070+
cancharge = hsync;
3071+
} else {
30703072
pot_dat_act[joy][i] = 2;
30713073
pot_dat[joy][i] = 0;
30723074
}
@@ -3075,13 +3077,24 @@ static void cap_check (void)
30753077
if (pot_dat_act[joy][i] == 2 && pot_cap[joy][i] >= joypot)
30763078
pot_dat_act[joy][i] = 0;
30773079
} else {
3078-
if (analog_port[joy][i] && pot_dat_act[joy][i] == 2 && pot_cap[joy][i] >= joypot)
3079-
pot_dat_act[joy][i] = 0;
3080-
if ((digital_port[joy][i] || mouse_port[joy]) && pot_dat_act[joy][i] == 2) {
3081-
if (pot_cap[joy][i] >= 10 && !isbutton)
3080+
if (analog_port[joy][i] && pot_dat_act[joy][i] == 2 && pot_cap[joy][i] >= joypot)
30823081
pot_dat_act[joy][i] = 0;
3082+
if ((digital_port[joy][i] || mouse_port[joy]) && pot_dat_act[joy][i] == 2) {
3083+
if (pot_cap[joy][i] >= 10 && !isbutton)
3084+
pot_dat_act[joy][i] = 0;
3085+
}
3086+
}
3087+
// CD32 pad 3rd button line floating: 2-button mode
3088+
if (cd32_pad_enabled[joy] && i == 0) {
3089+
if (charge == 0)
3090+
charge = 2;
30833091
}
3092+
// CD32 pad in 2-button mode: blue button is internally pulled up
3093+
if (cd32_pad_enabled[joy] && !cd32padmode(joy) && i == 1) {
3094+
if (charge == 0)
3095+
charge = 2;
30843096
}
3097+
30853098
} else { // output?
30863099
charge = (potgo_value & pdat) ? 2 : -2; /* fast (dis)charge if output */
30873100
if (potgo_value & pdat)
@@ -3099,43 +3112,39 @@ static void cap_check (void)
30993112
charge = 2;
31003113
}
31013114

3102-
// CD32 pad in 2-button mode: blue button is not floating
3103-
if (cd32_pad_enabled[joy] && !cd32padmode(joy) && i == 1) {
3104-
if (charge == 0)
3105-
charge = 2;
3106-
}
3107-
31083115
if (dong < 0 && charge == 0) {
31093116

31103117
if (lightpen_port[joy])
31113118
charge = 2;
3112-
3113-
/* official Commodore mouse has pull-up resistors in button lines
3114-
* NOTE: 3rd party mice may not have pullups! */
3119+
3120+
/* official Commodore mouse has pull-up resistors in button lines
3121+
* NOTE: 3rd party mice may not have pullups! */
31153122
if (is_mouse_pullup (joy) && mouse_port[joy] && digital_port[joy][i])
3116-
charge = 2;
3123+
charge = 2;
31173124

3118-
/* emulate pullup resistor if button mapped because there too many broken
3119-
* programs that read second button in input-mode (and most 2+ button pads have
3120-
* pullups)
3121-
*/
3122-
if (is_joystick_pullup (joy) && digital_port[joy][i])
3123-
charge = 2;
3125+
/* emulate pullup resistor if button mapped because there too many broken
3126+
* programs that read second button in input-mode (and most 2+ button pads have
3127+
* pullups)
3128+
*/
3129+
if (is_joystick_pullup (joy) && digital_port[joy][i])
3130+
charge = 2;
31243131
}
31253132

3126-
charge_cap (joy, i, charge);
3133+
if (cancharge) {
3134+
charge_cap(joy, i, charge);
3135+
}
31273136
}
31283137
}
31293138
}
31303139

31313140

31323141
uae_u8 handle_joystick_buttons (uae_u8 pra, uae_u8 dra)
31333142
{
3134-
uae_u8 but = 0;
3143+
uae_u8 but = 0;
31353144
int i;
31363145

31373146
maybe_read_input();
3138-
cap_check ();
3147+
cap_check(false);
31393148
for (i = 0; i < 2; i++) {
31403149
int mask = 0x40 << i;
31413150
if (cd32_pad_enabled[i]) {
@@ -3173,7 +3182,7 @@ void handle_cd32_joystick_cia (uae_u8 pra, uae_u8 dra)
31733182
int i;
31743183

31753184
maybe_read_input();
3176-
cap_check ();
3185+
cap_check(false);
31773186
for (i = 0; i < 2; i++) {
31783187
uae_u8 but = 0x40 << i;
31793188
if (cd32padmode(i)) {
@@ -3194,7 +3203,7 @@ static uae_u16 handle_joystick_potgor (uae_u16 potgor)
31943203
{
31953204
int i;
31963205

3197-
cap_check ();
3206+
cap_check(false);
31983207
for (i = 0; i < 2; i++) {
31993208
uae_u16 p9dir = 0x0800 << (i * 4); /* output enable P9 */
32003209
uae_u16 p9dat = 0x0400 << (i * 4); /* data P9 */
@@ -3500,7 +3509,7 @@ int handle_custom_event (const TCHAR *custom, int append)
35003509

35013510
void inputdevice_hsync(bool forceread)
35023511
{
3503-
cap_check ();
3512+
cap_check(true);
35043513

35053514
#ifdef CATWEASEL
35063515
catweasel_hsync ();
@@ -4231,13 +4240,14 @@ static int handle_input_event2(int nr, int state, int max, int flags, int extra)
42314240
{
42324241
int unit = (ie->data & 1) ? 1 : 0;
42334242
int lpnum = ie->unit - 5;
4234-
if (lightpen_active <= 0) {
4235-
lightpen_x[0] = vidinfo->outbuffer->outwidth / 2;
4236-
lightpen_y[0] = vidinfo->outbuffer->outheight / 2;
4237-
lightpen_x[1] = -1;
4238-
lightpen_y[1] = -1;
4243+
if (!(lightpen_active & (1 << lpnum))) {
4244+
if (!state) {
4245+
break;
4246+
}
4247+
lightpen_x[lpnum] = vidinfo->outbuffer->outwidth / 2;
4248+
lightpen_y[lpnum] = vidinfo->outbuffer->outheight / 2;
4249+
lightpen_active |= 1 << lpnum;
42394250
}
4240-
lightpen_active = true;
42414251
lightpen_enabled = true;
42424252
if (flags & HANDLE_IE_FLAG_ABSOLUTE) {
42434253
lastmxy_abs[lpnum][unit] = extra;
@@ -5400,8 +5410,7 @@ static void scanevents (struct uae_prefs *p)
54005410
#ifndef AMIBERRY
54015411
lightpen_enabled = false;
54025412
lightpen_enabled2 = false;
5403-
if (lightpen_active > 0)
5404-
lightpen_active = -1;
5413+
lightpen_active = 0;
54055414
#endif
54065415
for (i = 0; i < MAX_INPUT_DEVICES; i++) {
54075416
use_joysticks[i] = 0;

0 commit comments

Comments
 (0)