@@ -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