Skip to content

Commit 0b6cce2

Browse files
authored
Add version checks to KEY? and KEYENTER labels. (#535)
* MegaZeux 1.x worlds no longer send key labels except A-Z. * MegaZeux 2.00 to 2.61 worlds no longer send key labels except A-Z 1-9.
1 parent e8af759 commit 0b6cce2

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

docs/changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ GIT - MZX 2.93d
99

1010
USERS
1111

12+
+ The KEY? label is no longer sent for pre-2.62 worlds when
13+
the char pressed is outside of the A-Z 1-9 range, and is no
14+
longer sent for 1.x worlds when the char is outside of the A-Z
15+
range. (Previously checked version for the KEY counter only.)
16+
+ The KEYENTER label is no longer sent for pre-2.62 worlds.
1217
+ Software layer renderer performance enhancements for repeat
1318
colors, clipping, and unaligned renderering.
1419
+ Unaligned software layer rendering using 64-bit writes is

src/game.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -646,28 +646,27 @@ static boolean game_key(context *ctx, int *key)
646646
if(key_unicode > 0 && key_unicode < 256)
647647
key_char = key_unicode;
648648

649-
if(key_char)
649+
if(key_char > 0 && key_char < 256)
650650
{
651-
if(key_char < 256)
651+
// KEY? label and pre-2.80 KEY counter.
652+
// Values over 256 have no meaning here.
653+
key_char = toupper(key_char);
654+
655+
// 1.xx only supported A-Z. <2.60 only supported 1-9 and A-Z.
656+
// Since 2.60 magic overlaps with a lot of older games, 2.62 came out
657+
// a week after it, and this counter frequently broke old games,
658+
// apply the new behavior conservatively to >=2.62 instead.
659+
if(mzx_world->version >= V262 ||
660+
(key_char >= 'A' && key_char <= 'Z') ||
661+
(key_char >= '1' && key_char <= '9' && mzx_world->version >= V200))
652662
{
653663
// Send the KEY? label.
654-
// Values over 256 have no meaning here.
655664
keylbl[3] = key_char;
656665
send_robot_all_def(mzx_world, keylbl);
657-
}
658666

659-
// In pre-port MZX versions key was a board counter
660-
if(mzx_world->version < VERSION_PORT)
661-
{
662-
char keych = toupper(key_char);
663-
// <2.60 it only supported 1-9 and A-Z
664-
// This is difficult to version check, so apply it to <2.62
665-
if(mzx_world->version >= V262 ||
666-
(keych >= 'A' && keych <= 'Z') ||
667-
(keych >= '1' && keych <= '9'))
668-
{
669-
cur_board->last_key = keych;
670-
}
667+
// In pre-2.80 MZX versions, KEY was a board counter.
668+
if(mzx_world->version < VERSION_PORT)
669+
cur_board->last_key = key_char;
671670
}
672671
}
673672

@@ -798,7 +797,10 @@ static boolean game_key(context *ctx, int *key)
798797

799798
case IKEY_RETURN:
800799
{
801-
send_robot_all_def(mzx_world, "KeyEnter");
800+
// KeyEnter label was added in 2.60. See the KEY? comments above for
801+
// why this is being applied to >=2.62 instead of 2.60.
802+
if(mzx_world->version >= V262)
803+
send_robot_all_def(mzx_world, "KeyEnter");
802804

803805
// Ignore if this isn't a fresh press
804806
if(key_status != 1)

0 commit comments

Comments
 (0)