From d45dad482dc19b31a2e37c9e30fd70eddaf10b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=AFl=20Dogru?= Date: Fri, 22 May 2026 14:30:47 +0100 Subject: [PATCH] Add ng-input.h with edge-detect helpers around bios_p1current/change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three static inline helpers (ng_p1_held / pressed / released) wrap the standard BIOS input convention so it's named in one place. Signed-off-by: Ismaïl Dogru --- include/ngdevkit/ng-input.h | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 include/ngdevkit/ng-input.h diff --git a/include/ngdevkit/ng-input.h b/include/ngdevkit/ng-input.h new file mode 100644 index 0000000..1807a05 --- /dev/null +++ b/include/ngdevkit/ng-input.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2026 Ismaïl Dogru + * This file is part of ngdevkit + * + * ngdevkit is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ngdevkit is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ngdevkit. If not, see . + */ + +#ifndef __NGDEVKIT_NG_INPUT_H__ +#define __NGDEVKIT_NG_INPUT_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/// True while any bit in mask is currently held on player 1 +static inline u8 ng_p1_held(u8 mask) +{ + return (bios_p1current & mask) != 0; +} + +/// True on the single frame any bit in mask transitions released -> held +static inline u8 ng_p1_pressed(u8 mask) +{ + return (bios_p1current & ~bios_p1previous & mask) != 0; +} + +/// True on the single frame any bit in mask transitions held -> released +static inline u8 ng_p1_released(u8 mask) +{ + return (bios_p1previous & ~bios_p1current & mask) != 0; +} + +#ifdef __cplusplus +} +#endif + +#endif /* __NGDEVKIT_NG_INPUT_H__ */