Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KEY_PRESSEDn counter to read internal key statuses. #394

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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