Skip to content

Commit

Permalink
Fix imagemagick color conversion
Browse files Browse the repository at this point in the history
Move TAB to INS key
Maks shift key consistend between keyboards
Fix temp/lock screen updates for alt keyboard
Update color scheme to be more "2010's Nintendo"
Simplify special key state management.
Update the software decoder to work with the new renderer.
Move the shader into the rendering directory.
  • Loading branch information
zoeyjodon committed May 23, 2024
1 parent 91fa2ad commit 9e2d5d2
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 99 deletions.
Binary file modified 3ds/gfx/keyboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 3ds/gfx/keyboard_alt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed 3ds/gfx/keyboard_caps.png
Binary file not shown.
Binary file added 3ds/gfx/keyboard_lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed 3ds/gfx/keyboard_shift.png
Binary file not shown.
Binary file added 3ds/gfx/keyboard_temp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ $(OUTPUT).elf : $(OFILES)
%.bgr: %.png
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@convert $< -channel B -separate $< -channel G -separate $< -channel R -separate -channel RGB -combine -rotate 90 $@
@convert $< -colorspace RGB -rotate 90 $@

#---------------------------------------------------------------------------------
.PRECIOUS : %.t3x
Expand Down
130 changes: 89 additions & 41 deletions src/input/n3ds/KeyboardTouchHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
#include "N3dsTouchscreenInput.hpp"
#include "keyboard_alt_bgr.h"
#include "keyboard_bgr.h"
#include "keyboard_caps_bgr.h"
#include "keyboard_shift_bgr.h"
#include "keyboard_lock_bgr.h"
#include "keyboard_temp_bgr.h"
#include <Limelight.h>
#include <cstring>

const static int KEY_PX_SIZE = 3;

KeyboardTouchHandler::KeyboardTouchHandler()
: selected_keycodes(&default_keycodes) {
handle_default();
Expand All @@ -39,43 +41,70 @@ void KeyboardTouchHandler::set_screen(const uint8_t *bgr_buffer, int bgr_size) {
gfxScreenSwapBuffers(GFX_BOTTOM, false);
}

void KeyboardTouchHandler::reset_shift_state() {
shift_active = false;
caps_active = false;
// TODO: Add function to change a single key.
// Changing the whole section doesn't work for the alt keyboard.
void KeyboardTouchHandler::set_screen_key(KeyInfo &key_info) {
u8 *gfxbtmadr = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);

const uint8_t *bgr_buffer;
switch (key_info.state) {
case (KEY_TEMPORARY):
bgr_buffer = keyboard_temp_bgr;
break;
case (KEY_LOCKED):
bgr_buffer = keyboard_lock_bgr;
break;
default:
bgr_buffer = keyboard_bgr;
break;
}

for (int x = key_info.min_x; x < key_info.max_x; x++) {
int bgr_offset =
((GSP_SCREEN_WIDTH * x) + (GSP_SCREEN_WIDTH - key_info.max_y)) *
KEY_PX_SIZE;
int bgr_size = (key_info.max_y - key_info.min_y) * KEY_PX_SIZE;
memcpy(gfxbtmadr + bgr_offset, bgr_buffer + bgr_offset, bgr_size);
}

gfxFlushBuffers();
gfxScreenSwapBuffers(GFX_BOTTOM, false);
}

void KeyboardTouchHandler::handle_default() {
set_screen(keyboard_bgr, keyboard_bgr_size);
selected_keycodes = &default_keycodes;
reset_shift_state();
alt_keyboard_active = false;
set_screen_key(shift_info);
set_screen_key(ctrl_info);
set_screen_key(alt_info);
}

void KeyboardTouchHandler::handle_shift() {
if (caps_active) {
handle_default();
} else if (shift_active) {
handle_caps();
} else {
set_screen(keyboard_shift_bgr, keyboard_shift_bgr_size);
shift_active = true;
void KeyboardTouchHandler::cycle_key_state(KeyInfo &key_info) {
switch (key_info.state) {
case (KEY_TEMPORARY):
key_info.state = KEY_LOCKED;
break;
case (KEY_LOCKED):
key_info.state = KEY_DISABLED;
break;
default:
key_info.state = KEY_TEMPORARY;
break;
}
set_screen_key(key_info);
}

void KeyboardTouchHandler::handle_caps() {
set_screen(keyboard_caps_bgr, keyboard_caps_bgr_size);
reset_shift_state();
caps_active = true;
}

void KeyboardTouchHandler::handle_alt() {
if (alt_active) {
void KeyboardTouchHandler::handle_alt_keyboard() {
if (alt_keyboard_active) {
handle_default();
alt_active = false;
} else {
set_screen(keyboard_alt_bgr, keyboard_alt_bgr_size);
selected_keycodes = &alt_keycodes;
reset_shift_state();
alt_active = true;
alt_keyboard_active = true;
set_screen_key(shift_info);
set_screen_key(ctrl_info);
set_screen_key(alt_info);
}
}

Expand All @@ -98,22 +127,31 @@ keycode_info KeyboardTouchHandler::get_keycode(touchPosition touch) {
return {-1, false};
}

int KeyboardTouchHandler::get_key_mod() {
int modifiers = 0;
modifiers |=
(shift_info.state != KEY_DISABLED || active_keycode.require_shift)
? MODIFIER_SHIFT
: 0;
modifiers |= (ctrl_info.state != KEY_DISABLED) ? MODIFIER_CTRL : 0;
modifiers |= (alt_info.state != KEY_DISABLED) ? MODIFIER_ALT : 0;
return modifiers;
}

void KeyboardTouchHandler::_handle_touch_down(touchPosition touch) {
active_keycode = get_keycode(touch);
if (active_keycode.code == KEYBOARD_SWITCH_KC) {
handle_alt();
handle_alt_keyboard();
} else if (active_keycode.code > KEYBOARD_SWITCH_KC) {
if (active_keycode.code == SHIFT_KC) {
handle_shift();
active_keycode = {-1, false};
} else {
int modifiers =
(shift_active || caps_active || active_keycode.require_shift)
? MODIFIER_SHIFT
: 0;
LiSendKeyboardEvent(active_keycode.code, KEY_ACTION_DOWN,
modifiers);
cycle_key_state(shift_info);
} else if (active_keycode.code == CTRL_KC) {
cycle_key_state(ctrl_info);
} else if (active_keycode.code == ALT_KC) {
cycle_key_state(alt_info);
}
int modifiers = get_key_mod();
LiSendKeyboardEvent(active_keycode.code, KEY_ACTION_DOWN, modifiers);
}
}

Expand All @@ -122,13 +160,23 @@ void KeyboardTouchHandler::_handle_touch_up(touchPosition touch) {
return;
}

int modifiers =
(shift_active || caps_active || active_keycode.require_shift)
? MODIFIER_SHIFT
: 0;
int modifiers = get_key_mod();
LiSendKeyboardEvent(active_keycode.code, KEY_ACTION_UP, modifiers);
if (shift_active) {
handle_default();

if (active_keycode.code != SHIFT_KC && active_keycode.code != CTRL_KC &&
active_keycode.code != ALT_KC) {
if (shift_info.state == KEY_TEMPORARY) {
shift_info.state = KEY_DISABLED;
set_screen_key(shift_info);
}
if (ctrl_info.state == KEY_TEMPORARY) {
ctrl_info.state = KEY_DISABLED;
set_screen_key(ctrl_info);
}
if (alt_info.state == KEY_TEMPORARY) {
alt_info.state = KEY_DISABLED;
set_screen_key(alt_info);
}
}
active_keycode = {-1, false};
}
Expand Down
24 changes: 17 additions & 7 deletions src/input/n3ds/N3dsTouchscreenInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ class MouseTouchHandler : public TouchHandlerBase {
int previous_y = 0;
};

enum KeyState { KEY_DISABLED, KEY_TEMPORARY, KEY_LOCKED };
struct KeyInfo {
KeyState state = KEY_DISABLED;
int min_x;
int max_x;
int min_y;
int max_y;
};

class KeyboardTouchHandler : public TouchHandlerBase {
public:
KeyboardTouchHandler();
Expand All @@ -90,19 +99,20 @@ class KeyboardTouchHandler : public TouchHandlerBase {
void _handle_touch_up(touchPosition touch);
void _handle_touch_hold(touchPosition touch);

void reset_shift_state();
keycode_info get_keycode(touchPosition touch);
void set_screen(const uint8_t *bgr_buffer, int bgr_size);
void set_screen_key(KeyInfo &key_info);
void handle_default();
void handle_shift();
void handle_caps();
void handle_alt();
void cycle_key_state(KeyInfo &key_info);
void handle_alt_keyboard();
int get_key_mod();

private:
keycode_info active_keycode{-1, false};
bool alt_active = false;
bool shift_active = false;
bool caps_active = false;
KeyInfo shift_info = {KEY_DISABLED, 0, 48, 136, 169};
KeyInfo ctrl_info = {KEY_DISABLED, 64, 127, 0, 37};
KeyInfo alt_info = {KEY_DISABLED, 128, 192, 0, 37};
bool alt_keyboard_active = false;
std::map<int, keycode_info> *selected_keycodes = nullptr;
};

Expand Down
95 changes: 48 additions & 47 deletions src/input/n3ds/keycode_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ struct keycode_info {

const short KEYBOARD_SWITCH_KC = 0;
const short SHIFT_KC = 0xA0;
const short CAPS_KC = 0x14;
const short CTRL_KC = 0xA2;
const short ALT_KC = 0xA4;
static std::map<int, keycode_info> default_keycodes{
{0, {0x1B, false}}, // VK_ESCAPE
{1, {0xA2, false}}, // VK_CONTROL Left control
{2, {0xA4, false}}, // VK_ALT Left alt
{3, {0x2D, false}}, // VK_INSERT
{1, {CTRL_KC, false}}, // VK_CONTROL Left control
{2, {ALT_KC, false}}, // VK_ALT Left alt
{3, {0x09, false}}, // VK_TAB
{4, {0x2E, false}}, // VK_DELETE
{5, {0x31, false}}, // VK_1
{6, {0x32, false}}, // VK_2
Expand Down Expand Up @@ -146,49 +147,49 @@ static std::map<int, keycode_info> default_keycodes{
};

static std::map<int, keycode_info> alt_keycodes{
{0, {0x1B, false}}, // VK_ESCAPE
{1, {0xA2, false}}, // VK_CONTROL Left control
{2, {0xA4, false}}, // VK_ALT Left alt
{3, {0x2D, false}}, // VK_INSERT
{4, {0x2E, false}}, // VK_DELETE
{5, {0x70, false}}, // VK_F1
{6, {0x71, false}}, // VK_F2
{7, {0x72, false}}, // VK_F3
{8, {0x73, false}}, // VK_F4
{9, {0x74, false}}, // VK_F5
{10, {0x75, false}}, // VK_F6
{11, {0x76, false}}, // VK_F7
{12, {0x77, false}}, // VK_F8
{13, {0x78, false}}, // VK_F9
{14, {0x79, false}}, // VK_F10
{15, {0x6A, false}}, // VK_KPASTERISK
{16, {0xC0, false}}, // VK_GRAVE Note: can be ` OR ~
{17, {0xDE, false}}, // VK_APOSTROPHE Note: can be ' OR "
{18, {0xDE, true}}, // VK_APOSTROPHE Note: can be ' OR "
{19, {0xBA, true}}, // VK_SEMICOLON Note: can be ; or :
{20, {0xBA, false}}, // VK_SEMICOLON Note: can be ; or :
{21, {0x36, true}}, // VK_6 Note: use shift to make this char?
{22, {0xBF, false}}, // VK_SLASH Note: can be / or ?
{23, {0xDC, false}}, // VK_BACK_SLASH Note: can be \ or |
{24, {0xDC, true}}, // VK_BACK_SLASH Note: can be \ or |
{25, {0xDB, false}}, // VK_BRACELEFT Note: can be [ or {
{26, {0xDD, false}}, // VK_BRACERIGHT Note: can be ] or }
{27, {0xDB, true}}, // VK_BRACELEFT Note: can be [ or {
{28, {0xDD, true}}, // VK_BRACERIGHT Note: can be ] or }
{29, {0xBC, true}}, // VK_OEM_102 Note: can be , or <
{30, {0xBE, true}}, // VK_OEM_102 Note: can be . or >
{31, {0x39, true}}, // VK_9 Note: can be 9 or (
{32, {0x30, true}}, // VK_0 Note: can be 0 or )
{33, {0xC0, true}}, // VK_GRAVE Note: can be ` OR ~
{34, {0x09, false}}, // VK_TAB
{35, {0x34, true}}, // VK_4 Note: can be 4 OR $
{36, {0xBF, true}}, // VK_SLASH Note: can be / or ?
{37, {0x31, true}}, // VK_1 Note: can be 1 OR !
{38, {0x37, true}}, // VK_7 Note: can be 7 OR &
{39, {0x32, true}}, // VK_2 Note: can be 2 OR @
{40, {0x33, true}}, // VK_3 Note: can be 3 or #
{41, {0x35, true}}, // VK_5 Note: can be 5 or %
{42, {0x08, false}}, // VK_BACK_SPACE
{0, {0x1B, false}}, // VK_ESCAPE
{1, {CTRL_KC, false}}, // VK_CONTROL Left control
{2, {ALT_KC, false}}, // VK_ALT Left alt
{3, {0x09, false}}, // VK_TAB
{4, {0x2E, false}}, // VK_DELETE
{5, {0x70, false}}, // VK_F1
{6, {0x71, false}}, // VK_F2
{7, {0x72, false}}, // VK_F3
{8, {0x73, false}}, // VK_F4
{9, {0x74, false}}, // VK_F5
{10, {0x75, false}}, // VK_F6
{11, {0x76, false}}, // VK_F7
{12, {0x77, false}}, // VK_F8
{13, {0x78, false}}, // VK_F9
{14, {0x79, false}}, // VK_F10
{15, {0x6A, false}}, // VK_KPASTERISK
{16, {0xC0, false}}, // VK_GRAVE Note: can be ` OR ~
{17, {0xDE, false}}, // VK_APOSTROPHE Note: can be ' OR "
{18, {0xDE, true}}, // VK_APOSTROPHE Note: can be ' OR "
{19, {0xBA, true}}, // VK_SEMICOLON Note: can be ; or :
{20, {0xBA, false}}, // VK_SEMICOLON Note: can be ; or :
{21, {0x36, true}}, // VK_6 Note: use shift to make this char?
{22, {0xBF, false}}, // VK_SLASH Note: can be / or ?
{23, {0xDC, false}}, // VK_BACK_SLASH Note: can be \ or |
{24, {0xDC, true}}, // VK_BACK_SLASH Note: can be \ or |
{25, {0xDB, false}}, // VK_BRACELEFT Note: can be [ or {
{26, {0xDD, false}}, // VK_BRACERIGHT Note: can be ] or }
{27, {0xDB, true}}, // VK_BRACELEFT Note: can be [ or {
{28, {0xDD, true}}, // VK_BRACERIGHT Note: can be ] or }
{29, {0xBC, true}}, // VK_OEM_102 Note: can be , or <
{30, {0xBE, true}}, // VK_OEM_102 Note: can be . or >
{31, {0x39, true}}, // VK_9 Note: can be 9 or (
{32, {0x30, true}}, // VK_0 Note: can be 0 or )
{33, {0xC0, true}}, // VK_GRAVE Note: can be ` OR ~
{34, {SHIFT_KC, false}}, // VK_SHIFT Left shift
{35, {0x34, true}}, // VK_4 Note: can be 4 OR $
{36, {0xBF, true}}, // VK_SLASH Note: can be / or ?
{37, {0x31, true}}, // VK_1 Note: can be 1 OR !
{38, {0x37, true}}, // VK_7 Note: can be 7 OR &
{39, {0x32, true}}, // VK_2 Note: can be 2 OR @
{40, {0x33, true}}, // VK_3 Note: can be 3 or #
{41, {0x35, true}}, // VK_5 Note: can be 5 or %
{42, {0x08, false}}, // VK_BACK_SPACE
{43, {KEYBOARD_SWITCH_KC, false}}, // Special key -- keyboard switch
{44, {0x5B, false}}, // KEY_LEFTMETA
{45, {0x20, false}}, // VK_SPACE
Expand Down
4 changes: 2 additions & 2 deletions src/video/n3ds/N3dsRendererBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ void N3dsRendererBase::write_px_to_framebuffer_gpu(uint8_t *__restrict source) {
3); \
}

float sw = image_width / 1024.0f;
float sh = image_height / 512.0f;
float sw = image_width / ((float)MOON_CTR_VIDEO_TEX_W);
float sh = image_height / ((float)MOON_CTR_VIDEO_TEX_H);

// float hw = 2.0f / surface_height;
float hh = 2.0f / surface_width;
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion src/video/n3ds_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ static inline int write_yuv_to_framebuffer(const u8 **source, int width,
goto y2ru_failed;
}

status = Y2RU_SetReceiving(rgb_img_buffer, width * height * px_size, 8, 0);
status = Y2RU_SetReceiving(
rgb_img_buffer, MOON_CTR_VIDEO_TEX_W * MOON_CTR_VIDEO_TEX_H * px_size,
width * px_size, (MOON_CTR_VIDEO_TEX_W - width) * px_size);
if (status) {
fprintf(stderr, "Y2RU_SetReceiving failed\n");
goto y2ru_failed;
Expand Down

0 comments on commit 9e2d5d2

Please sign in to comment.