Skip to content

Commit

Permalink
Add KEY_PRESSEDn counter to read internal key statuses. (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceLR authored Dec 7, 2023
1 parent 8b8e31d commit d185dfc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ USERS
+ Added an experimental Dreamcast port (asie, Lachesis).
+ Added an experimental MS-DOS 32-bit port based on DJGPP
(Mr_Alert, asie, Lachesis).
+ Added the new counter KEY_PRESSEDn to read internal keycode
statuses. This is like KEYn, but KEY_PRESSEDn accepts internal
keycodes instead of PC XT keycodes. KEY_PRESSEDn will return
1 if the key is currently pressed, or 0 if it is not pressed.
+ Added the new counter DATE_WEEKDAY containing the number of
the current day of the week, where 0=Sunday, 1=Monday,
2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday.
Expand Down
1 change: 1 addition & 0 deletions docs/counter_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ name r/w g/n/f/b i
"KEY" r b *
"KEY_CODE" r b *
"KEY_PRESSED" r b *
"KEY_PRESSEDn" r b *
"KEY_RELEASE" r b *
"KEYn" r b *
"LASTXPOS" r w n *
Expand Down
8 changes: 8 additions & 0 deletions src/counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,13 @@ static int key_release_read(struct world *mzx_world,
return get_last_key_released(keycode_pc_xt);
}

static int key_pressedn_read(struct world *mzx_world,
const struct function_counter *counter, const char *name, int id)
{
int key_num = strtol(name + 11, NULL, 10);
return get_key_status(keycode_internal, key_num) > 0;
}

static int joyn_read(struct world *mzx_world,
const struct function_counter *counter, const char *name, int id)
{
Expand Down Expand Up @@ -2662,6 +2669,7 @@ static const struct function_counter builtin_counters[] =
{ "key!", V269, keyn_read, NULL },
{ "key_code", V269, key_code_read, NULL },
{ "key_pressed", V260, key_pressed_read, NULL },
{ "key_pressed!", V293, key_pressedn_read, NULL },
{ "key_release", V269, key_release_read, NULL },
{ "lava_walk", V260, lava_walk_read, lava_walk_write },
{ "load_bc?", V270, load_bc_read, NULL },
Expand Down

0 comments on commit d185dfc

Please sign in to comment.