summaryrefslogtreecommitdiff
path: root/arm9/source/devices
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2024-12-16 14:52:54 +1300
committerBen Bridle <ben@derelict.engineering>2024-12-16 14:52:54 +1300
commit0d9978228b9226d16ba8272a03dd7e6c9ad83b3d (patch)
tree442ce8a1d37f2f9a0e9e655d3250849e874c2d41 /arm9/source/devices
parentdbe8171815ea3b51c3ac87dae1996ae0d8f6eb04 (diff)
downloadbedrock-nds-0d9978228b9226d16ba8272a03dd7e6c9ad83b3d.zip
Implement a toggleable keyboard on the lower screen
Diffstat (limited to 'arm9/source/devices')
-rw-r--r--arm9/source/devices/input.c5
-rw-r--r--arm9/source/devices/input.h17
-rw-r--r--arm9/source/devices/local.c11
-rw-r--r--arm9/source/devices/local.h4
-rw-r--r--arm9/source/devices/screen.c16
-rw-r--r--arm9/source/devices/screen.h1
6 files changed, 48 insertions, 6 deletions
diff --git a/arm9/source/devices/input.c b/arm9/source/devices/input.c
index a39f448..e5ac5be 100644
--- a/arm9/source/devices/input.c
+++ b/arm9/source/devices/input.c
@@ -2,6 +2,11 @@
#include "../bang.h"
#include "input.h"
+void inp_receive_byte(InputDevice *inp, u8 byte) {
+ cb_write_byte(&inp->keybuffer, byte);
+ inp->wake = true;
+}
+
// Read gamepad state into an input device.
void inp_read_gamepad(InputDevice *inp) {
u32 held = keysHeld();
diff --git a/arm9/source/devices/input.h b/arm9/source/devices/input.h
index e62bdd3..4f91ed5 100644
--- a/arm9/source/devices/input.h
+++ b/arm9/source/devices/input.h
@@ -1,15 +1,20 @@
+#include <nds.h>
+#include "../types/circbuf.h"
+
#ifndef INPUT_H_
#define INPUT_H_
typedef struct {
- bool pointer; // pointer active
- bool keyboard; // keyboard active
- u16 x,y; // pointer position
- u8 navigation; // navigation state
- u8 gamepad; // gamepad state
- bool wake; // wake flag
+ bool pointer; // pointer active
+ bool keyboard; // keyboard active
+ CircBuf keybuffer; // queued keypresses
+ u16 x,y; // pointer position
+ u8 navigation; // navigation state
+ u8 gamepad; // gamepad state
+ bool wake; // wake flag
} InputDevice;
+ void inp_receive_byte(InputDevice *inp, u8 byte);
void inp_read_gamepad(InputDevice *inp);
void inp_read_navigation(InputDevice *inp);
void inp_read_touch(InputDevice *inp);
diff --git a/arm9/source/devices/local.c b/arm9/source/devices/local.c
index e69de29..e13a1f8 100644
--- a/arm9/source/devices/local.c
+++ b/arm9/source/devices/local.c
@@ -0,0 +1,11 @@
+#include "../main.h"
+#include "local.h"
+
+void std_write(u8 byte) {
+ if (byte) {
+ receive_keyboard_byte(byte);
+ } else {
+ close_keyboard();
+
+ }
+}
diff --git a/arm9/source/devices/local.h b/arm9/source/devices/local.h
index bf1393c..979f5ce 100644
--- a/arm9/source/devices/local.h
+++ b/arm9/source/devices/local.h
@@ -1,4 +1,8 @@
+#include <nds.h>
+
#ifndef LOCAL_H_
#define LOCAL_H_
+ void std_write(u8 byte);
+
#endif
diff --git a/arm9/source/devices/screen.c b/arm9/source/devices/screen.c
index e394b55..698b754 100644
--- a/arm9/source/devices/screen.c
+++ b/arm9/source/devices/screen.c
@@ -36,12 +36,28 @@ Screen scr_sub = {
.palv = BG_PALETTE_SUB,
};
+// TODO: Make an enum thing for main/sub, combine these functions
void scr_make_main(ScreenDevice *scr) {
scr->nds = &scr_main;
+ for (int i=0; i<16; i++) {
+ scr->nds->pal[i] = scr->palette[i];
+ }
+ scr->wake = true;
}
void scr_make_sub(ScreenDevice *scr) {
scr->nds = &scr_sub;
+ for (int i=0; i<16; i++) {
+ scr->nds->pal[i] = scr->palette[i];
+ }
+ scr->wake = true;
+}
+
+void scr_unmake(ScreenDevice *scr) {
+ if (scr->nds) {
+ black_screen(scr->nds);
+ scr->nds = NULL;
+ }
}
void init_screens(void) {
diff --git a/arm9/source/devices/screen.h b/arm9/source/devices/screen.h
index 3e75334..1ff58e5 100644
--- a/arm9/source/devices/screen.h
+++ b/arm9/source/devices/screen.h
@@ -46,6 +46,7 @@
void init_screens(void);
void scr_make_main(ScreenDevice *scr);
void scr_make_sub(ScreenDevice *scr);
+ void scr_unmake(ScreenDevice *scr);
void set_palette_high(ScreenDevice *scr, u8 high);
void set_palette_low(ScreenDevice *scr, u8 low);