Linux: Try adding AltGr support

This commit is contained in:
UnknownShadow200 2024-05-19 08:14:00 +10:00
parent 9d7bde7218
commit b24e2cb56b
3 changed files with 143 additions and 61 deletions

View File

@ -3,8 +3,6 @@
#include "_GraphicsBase.h" #include "_GraphicsBase.h"
#include "Errors.h" #include "Errors.h"
#include "Window.h" #include "Window.h"
#include <assert.h>
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <yaul.h> #include <yaul.h>
@ -22,9 +20,7 @@
#define PRIMITIVE_DRAW_MODE_GOURAUD_HALF_TRANS (7) #define PRIMITIVE_DRAW_MODE_GOURAUD_HALF_TRANS (7)
#define PRIMITIVE_DRAW_MODE_COUNT (8) #define PRIMITIVE_DRAW_MODE_COUNT (8)
#define PRIMITIVE_COLOR RGB1555(1, 31, 0, 31) #define CMDS_COUNT 400
#define CMDS_COUNT 400
static PackedCol clear_color; static PackedCol clear_color;
static vdp1_cmdt_t cmdts_all[CMDS_COUNT]; static vdp1_cmdt_t cmdts_all[CMDS_COUNT];
@ -36,14 +32,13 @@ static vdp1_cmdt_t* NextPrimitive(void) {
return &cmdts_all[cmdts_count++]; return &cmdts_all[cmdts_count++];
} }
static vdp1_cmdt_draw_mode_t _primitive_draw_mode = { static const vdp1_cmdt_draw_mode_t color_draw_mode = {
.raw = 0x0000 .raw = 0x0000
}; };
static const vdp1_cmdt_draw_mode_t texture_draw_mode = {
.cc_mode = PRIMITIVE_DRAW_MODE_GOURAUD_SHADING
};
static int16_vec2_t clear_points[4];
// TODO: how to use VDP1 erase ??
static void UpdateVDP1Env(void) { static void UpdateVDP1Env(void) {
vdp1_env_t env; vdp1_env_t env;
vdp1_env_default_init(&env); vdp1_env_default_init(&env);
@ -56,19 +51,21 @@ static void UpdateVDP1Env(void) {
vdp1_env_set(&env); vdp1_env_set(&env);
} }
// TODO: should be SCREEN_WIDTH/2 instead ? static void CalcGouraudColours(void) {
static void _primitive_init(void) { for (int i = 0; i < 1024; i++)
clear_points[0].x = 0; {
clear_points[0].y = SCREEN_WIDTH - 1; // 1024 = 10 bits, divided into RRR GGGG BBB
int r_idx = (i & 0x007) >> 0, R = r_idx << (5 - 3);
clear_points[1].x = SCREEN_WIDTH - 1; int g_idx = (i & 0x078) >> 3, G = g_idx << (5 - 4);
clear_points[1].y = SCREEN_HEIGHT - 1; int b_idx = (i & 0x380) >> 7, B = b_idx << (5 - 3);
rgb1555_t gouraud = RGB1555(1, R, G, B);
clear_points[2].x = SCREEN_HEIGHT - 1;
clear_points[2].y = 0; vdp1_gouraud_table_t* cur = &_vdp1_vram_partitions.gouraud_base[i];
cur->colors[0] = gouraud;
clear_points[3].x = 0; cur->colors[1] = gouraud;
clear_points[3].y = 0; cur->colors[2] = gouraud;
cur->colors[3] = gouraud;
}
} }
static GfxResourceID white_square; static GfxResourceID white_square;
@ -96,7 +93,7 @@ void Gfx_Create(void) {
vdp2_sprite_priority_set(0, 6); vdp2_sprite_priority_set(0, 6);
UpdateVDP1Env(); UpdateVDP1Env();
_primitive_init(); CalcGouraudColours();
} }
Gfx.MinTexWidth = 8; Gfx.MinTexWidth = 8;
@ -130,6 +127,7 @@ static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8
{ {
cc_uint8* color = (cc_uint8*)&src[x]; cc_uint8* color = (cc_uint8*)&src[x];
dst[x] = BGRA8_to_SATURN(color); dst[x] = BGRA8_to_SATURN(color);
dst[x] = 0xFEEE;
} }
} }
@ -335,7 +333,32 @@ static void Transform(Vec3* result, struct VertexTextured* a, const struct Matri
result->z = (z/w) * 1024; result->z = (z/w) * 1024;
} }
#define IsPointCulled(vec) vec.x < -10000 || vec.x > 10000 || vec.y < -10000 || vec.y > 10000 || vec.z < 0 || vec.z > 1024 #define IsPointCulled(vec) vec.x < -2048 || vec.x > 2048 || vec.y < -2048 || vec.y > 2048 || vec.z < 0 || vec.z > 1024
static void DrawColouredQuads2D(int verticesCount, int startVertex) {
for (int i = 0; i < verticesCount; i += 4)
{
struct VertexColoured* v = (struct VertexColoured*)gfx_vertices + startVertex + i;
int16_vec2_t points[4];
points[0].x = (int)v[0].x - SCREEN_WIDTH / 2; points[0].y = (int)v[0].y - SCREEN_HEIGHT / 2;
points[1].x = (int)v[1].x - SCREEN_WIDTH / 2; points[1].y = (int)v[1].y - SCREEN_HEIGHT / 2;
points[2].x = (int)v[2].x - SCREEN_WIDTH / 2; points[2].y = (int)v[2].y - SCREEN_HEIGHT / 2;
points[3].x = (int)v[3].x - SCREEN_WIDTH / 2; points[3].y = (int)v[3].y - SCREEN_HEIGHT / 2;
int R = PackedCol_R(v->Col);
int G = PackedCol_G(v->Col);
int B = PackedCol_B(v->Col);
vdp1_cmdt_t* cmd;
cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3));
vdp1_cmdt_draw_mode_set(cmd, color_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);
}
}
static void DrawTexturedQuads2D(int verticesCount, int startVertex) { static void DrawTexturedQuads2D(int verticesCount, int startVertex) {
for (int i = 0; i < verticesCount; i += 4) for (int i = 0; i < verticesCount; i += 4)
@ -357,7 +380,50 @@ static void DrawTexturedQuads2D(int verticesCount, int startVertex) {
cmd = NextPrimitive(); cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd); vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3)); vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3));
vdp1_cmdt_draw_mode_set(cmd, _primitive_draw_mode); vdp1_cmdt_draw_mode_set(cmd, color_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);
/*cmd = NextPrimitive();
vdp1_cmdt_distorted_sprite_set(cmd);
vdp1_cmdt_char_size_set(cmd, 8, 8);
vdp1_cmdt_char_base_set(cmd, (vdp1_vram_t)_vdp1_vram_partitions.texture_base);
vdp1_cmdt_draw_mode_set(cmd, texture_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);*/
}
}
static void DrawColouredQuads3D(int verticesCount, int startVertex) {
for (int i = 0; i < verticesCount; i += 4)
{
struct VertexColoured* v = (struct VertexColoured*)gfx_vertices + startVertex + i;
Vec3 coords[4];
Transform(&coords[0], &v[0], &mvp);
Transform(&coords[1], &v[1], &mvp);
Transform(&coords[2], &v[2], &mvp);
Transform(&coords[3], &v[3], &mvp);
int16_vec2_t points[4];
points[0].x = coords[0].x; points[0].y = coords[0].y;
points[1].x = coords[1].x; points[1].y = coords[1].y;
points[2].x = coords[2].x; points[2].y = coords[2].y;
points[3].x = coords[3].x; points[3].y = coords[3].y;
if (IsPointCulled(coords[0])) continue;
if (IsPointCulled(coords[1])) continue;
if (IsPointCulled(coords[2])) continue;
if (IsPointCulled(coords[3])) continue;
int R = PackedCol_R(v->Col);
int G = PackedCol_G(v->Col);
int B = PackedCol_B(v->Col);
vdp1_cmdt_t* cmd;
cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3));
vdp1_cmdt_draw_mode_set(cmd, color_draw_mode);
vdp1_cmdt_vtx_set(cmd, points); vdp1_cmdt_vtx_set(cmd, points);
} }
} }
@ -393,25 +459,36 @@ static void DrawTexturedQuads3D(int verticesCount, int startVertex) {
cmd = NextPrimitive(); cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd); vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3)); vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3));
vdp1_cmdt_draw_mode_set(cmd, _primitive_draw_mode); vdp1_cmdt_draw_mode_set(cmd, color_draw_mode);
vdp1_cmdt_vtx_set(cmd, points); vdp1_cmdt_vtx_set(cmd, points);
/*cmd = NextPrimitive();
vdp1_cmdt_distorted_sprite_set(cmd);
vdp1_cmdt_char_size_set(cmd, 8, 8);
vdp1_cmdt_char_base_set(cmd, (vdp1_vram_t)_vdp1_vram_partitions.texture_base);
vdp1_cmdt_draw_mode_set(cmd, texture_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);*/
} }
} }
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) { void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
if (gfx_rendering2D && gfx_format == VERTEX_FORMAT_TEXTURED) { if (gfx_rendering2D) {
DrawTexturedQuads2D(verticesCount, startVertex); if (gfx_format == VERTEX_FORMAT_TEXTURED) {
} else if (gfx_format == VERTEX_FORMAT_TEXTURED) { DrawTexturedQuads2D(verticesCount, startVertex);
DrawTexturedQuads3D(verticesCount, startVertex); } else {
DrawColouredQuads2D(verticesCount, startVertex);
}
} else {
if (gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads3D(verticesCount, startVertex);
} else {
DrawColouredQuads3D(verticesCount, startVertex);
}
} }
} }
void Gfx_DrawVb_IndexedTris(int verticesCount) { void Gfx_DrawVb_IndexedTris(int verticesCount) {
if (gfx_rendering2D && gfx_format == VERTEX_FORMAT_TEXTURED) { Gfx_DrawVb_IndexedTris_Range(verticesCount, 0);
DrawTexturedQuads2D(verticesCount, 0);
} else if (gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads3D(verticesCount, 0);
}
} }
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) { void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
@ -446,16 +523,6 @@ void Gfx_BeginFrame(void) {
cmd = NextPrimitive(); cmd = NextPrimitive();
vdp1_cmdt_local_coord_set(cmd); vdp1_cmdt_local_coord_set(cmd);
vdp1_cmdt_vtx_local_coord_set(cmd, local_coord_center); vdp1_cmdt_vtx_local_coord_set(cmd, local_coord_center);
int R = PackedCol_R(clear_color);
int G = PackedCol_G(clear_color);
int B = PackedCol_B(clear_color);
cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3)); // TODO VDP1 erase
vdp1_cmdt_draw_mode_set(cmd, _primitive_draw_mode);
vdp1_cmdt_vtx_set(cmd, clear_points);
} }
void Gfx_EndFrame(void) { void Gfx_EndFrame(void) {

View File

@ -83,9 +83,13 @@ static const cc_uint8 key_map[] = {
/* D8 */ 0, 0, 0, CCKEY_LBRACKET, CCKEY_BACKSLASH, CCKEY_RBRACKET, CCKEY_QUOTE, 0, /* D8 */ 0, 0, 0, CCKEY_LBRACKET, CCKEY_BACKSLASH, CCKEY_RBRACKET, CCKEY_QUOTE, 0,
}; };
static int MapNativeKey(WPARAM key, LPARAM meta) { static int MapNativeKey(WPARAM vk_key, LPARAM meta) {
LPARAM ext = meta & (1UL << 24); LPARAM ext = meta & (1UL << 24);
switch (key) LPARAM scancode = (meta >> 16) & 0xFF;
int key;
if (ext) scancode |= 0xE000;
switch (vk_key)
{ {
case VK_CONTROL: case VK_CONTROL:
return ext ? CCKEY_RCTRL : CCKEY_LCTRL; return ext ? CCKEY_RCTRL : CCKEY_LCTRL;
@ -93,9 +97,11 @@ static int MapNativeKey(WPARAM key, LPARAM meta) {
return ext ? CCKEY_RALT : CCKEY_LALT; return ext ? CCKEY_RALT : CCKEY_LALT;
case VK_RETURN: case VK_RETURN:
return ext ? CCKEY_KP_ENTER : CCKEY_ENTER; return ext ? CCKEY_KP_ENTER : CCKEY_ENTER;
default:
return key < Array_Elems(key_map) ? key_map[key] : 0;
} }
key = vk_key < Array_Elems(key_map) ? key_map[vk_key] : 0;
if (!key) Platform_Log2("Unknown key: %x, %x", &vk_key, &scancode);
return key;
} }
static void RefreshWindowBounds(void) { static void RefreshWindowBounds(void) {
@ -256,7 +262,6 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
} else { } else {
key = MapNativeKey(wParam, lParam); key = MapNativeKey(wParam, lParam);
if (key) Input_Set(key, pressed); if (key) Input_Set(key, pressed);
else Platform_Log1("Unknown key: %x", &wParam);
} }
return 0; return 0;
} break; } break;

View File

@ -183,21 +183,31 @@ static int MapNativeKey(KeySym key, unsigned int state) {
case XK_KP_Page_Up: return CCKEY_KP9; case XK_KP_Page_Up: return CCKEY_KP9;
case XK_KP_Delete: return CCKEY_KP_DECIMAL; case XK_KP_Delete: return CCKEY_KP_DECIMAL;
case XK_KP_Enter: return CCKEY_KP_ENTER; case XK_KP_Enter: return CCKEY_KP_ENTER;
case XK_ISO_Level3_Shift: return CCKEY_RALT; /* AltGr mode switch on some European keyboard layouts */
} }
return INPUT_NONE; return INPUT_NONE;
} }
/* NOTE: This may not be entirely accurate, because user can configure keycode mappings */ /* NOTE: This may not be entirely accurate, because user can configure keycode mappings */
static const cc_uint8 keycodeMap[136] = { static const cc_uint8 keycodeMap[136] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, CCKEY_ESCAPE, '1', '2', '3', '4', '5', '6', /* 00 */ 0, 0, 0, 0, 0, 0, 0, 0,
'7', '8', '9', '0', CCKEY_MINUS, CCKEY_EQUALS, CCKEY_BACKSPACE, CCKEY_TAB, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 08 */ 0, CCKEY_ESCAPE, '1', '2', '3', '4', '5', '6',
'O', 'P', CCKEY_LBRACKET, CCKEY_RBRACKET, CCKEY_ENTER, CCKEY_LCTRL, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', CCKEY_SEMICOLON, /* 10 */ '7', '8', '9', '0', CCKEY_MINUS, CCKEY_EQUALS, CCKEY_BACKSPACE, CCKEY_TAB,
CCKEY_QUOTE, CCKEY_TILDE, CCKEY_LSHIFT, CCKEY_BACKSLASH, 'Z', 'X', 'C', 'V', 'B', 'N', 'M', CCKEY_PERIOD, CCKEY_COMMA, CCKEY_SLASH, CCKEY_RSHIFT, CCKEY_KP_MULTIPLY, /* 18 */ 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
CCKEY_LALT, CCKEY_SPACE, CCKEY_CAPSLOCK, CCKEY_F1, CCKEY_F2, CCKEY_F3, CCKEY_F4, CCKEY_F5, CCKEY_F6, CCKEY_F7, CCKEY_F8, CCKEY_F9, CCKEY_F10, CCKEY_NUMLOCK, CCKEY_SCROLLLOCK, CCKEY_KP7, /* 20 */ 'O', 'P', CCKEY_LBRACKET, CCKEY_RBRACKET, CCKEY_ENTER, CCKEY_LCTRL, 'A', 'S',
CCKEY_KP8, CCKEY_KP9, CCKEY_KP_MINUS, CCKEY_KP4, CCKEY_KP5, CCKEY_KP6, CCKEY_KP_PLUS, CCKEY_KP1, CCKEY_KP2, CCKEY_KP3, CCKEY_KP0, CCKEY_KP_DECIMAL, 0, 0, 0, CCKEY_F11, /* 28 */ 'D', 'F', 'G', 'H', 'J', 'K', 'L', CCKEY_SEMICOLON,
CCKEY_F12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 30 */ CCKEY_QUOTE, CCKEY_TILDE, CCKEY_LSHIFT, CCKEY_BACKSLASH, 'Z', 'X', 'C', 'V',
CCKEY_RALT, CCKEY_RCTRL, CCKEY_HOME, CCKEY_UP, CCKEY_PAGEUP, CCKEY_LEFT, CCKEY_RIGHT, CCKEY_END, CCKEY_DOWN, CCKEY_PAGEDOWN, CCKEY_INSERT, CCKEY_DELETE, 0, 0, 0, 0, /* 38 */ 'B', 'N', 'M', CCKEY_PERIOD, CCKEY_COMMA, CCKEY_SLASH, CCKEY_RSHIFT, CCKEY_KP_MULTIPLY,
0, 0, 0, CCKEY_PAUSE, 0, 0, 0, 0, 0, CCKEY_LWIN, 0, CCKEY_RWIN /* 40 */ CCKEY_LALT, CCKEY_SPACE, CCKEY_CAPSLOCK, CCKEY_F1, CCKEY_F2, CCKEY_F3, CCKEY_F4, CCKEY_F5,
/* 48 */ CCKEY_F6, CCKEY_F7, CCKEY_F8, CCKEY_F9, CCKEY_F10, CCKEY_NUMLOCK, CCKEY_SCROLLLOCK, CCKEY_KP7,
/* 50 */ CCKEY_KP8, CCKEY_KP9, CCKEY_KP_MINUS, CCKEY_KP4, CCKEY_KP5, CCKEY_KP6, CCKEY_KP_PLUS, CCKEY_KP1,
/* 58 */ CCKEY_KP2, CCKEY_KP3, CCKEY_KP0, CCKEY_KP_DECIMAL, 0, 0, 0, CCKEY_F11,
/* 60 */ CCKEY_F12, 0, 0, 0, 0, 0, 0, 0,
/* 68 */ 0, 0, 0, 0, CCKEY_RALT, CCKEY_RCTRL, CCKEY_HOME, CCKEY_UP,
/* 70 */ CCKEY_PAGEUP, CCKEY_LEFT, CCKEY_RIGHT, CCKEY_END, CCKEY_DOWN, CCKEY_PAGEDOWN, CCKEY_INSERT, CCKEY_DELETE,
/* 78 */ 0, 0, 0, 0, 0, 0, 0, CCKEY_PAUSE,
/* 80 */ 0, 0, 0, 0, 0, CCKEY_LWIN, 0, CCKEY_RWIN
}; };
static int MapNativeKeycode(unsigned int keycode) { static int MapNativeKeycode(unsigned int keycode) {