Feature/keyboard input (#33)
* Adds basic keyboard handling, palette fading
This commit is contained in:
parent
716c65807d
commit
ecc435ef8e
|
@ -479,8 +479,9 @@ smk smk_open_file(const char* filename, const unsigned char mode)
|
|||
|
||||
if (!(fp = fopen(filename,"rb")))
|
||||
{
|
||||
fprintf(stderr,"libsmacker::smk_open_file(%s,%u) - ERROR: could not open file (errno: %d)\n",filename,mode,errno);
|
||||
perror ("\tError reported was");
|
||||
// JeffH commented out error messages
|
||||
// fprintf(stderr,"libsmacker::smk_open_file(%s,%u) - ERROR: could not open file (errno: %d)\n",filename,mode,errno);
|
||||
// perror ("\tError reported was");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,12 +60,10 @@ br_pixelmap* BrPixelmapMatch(br_pixelmap* src, br_uint_8 match_type) {
|
|||
}
|
||||
|
||||
//((br_device_pixelmap*)src)->dispatch->_match((br_device_pixelmap*)src, (br_device_pixelmap**)&new, &tv[0]);
|
||||
LOG_DEBUG("new1 %p, %p\n", new, &new);
|
||||
if (_M_br_device_pixelmap_mem_match((br_device_pixelmap*)src, (br_device_pixelmap**)&new, &tv[0]) != 0) {
|
||||
LOG_WARN("_M_br_device_pixelmap_mem_match returned error");
|
||||
return NULL;
|
||||
}
|
||||
LOG_DEBUG("new %p, %d\n", new, new->width);
|
||||
return new;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ void PlaySmackerFile(char* pSmack_name) {
|
|||
|
||||
smk_first(s);
|
||||
do {
|
||||
char* pal = smk_get_palette(s);
|
||||
const unsigned char* pal = smk_get_palette(s);
|
||||
for (i = 1; i < 256; i++) {
|
||||
r = pal[(i * 3)];
|
||||
g = pal[(i * 3) + 1];
|
||||
|
@ -102,7 +102,7 @@ void PlaySmackerFile(char* pSmack_name) {
|
|||
DRSetPalette(gCurrent_palette);
|
||||
EnsurePaletteUp();
|
||||
|
||||
char* frame = smk_get_video(s);
|
||||
const unsigned char* frame = smk_get_video(s);
|
||||
for (i = 0; i < h; i++) {
|
||||
for (j = 0; j < w; j++) {
|
||||
dest_pix[(i * gBack_screen->row_bytes) + j] = frame[i * w + j];
|
||||
|
@ -110,9 +110,9 @@ void PlaySmackerFile(char* pSmack_name) {
|
|||
}
|
||||
PDScreenBufferSwap(0);
|
||||
|
||||
// if (AnyKeyDown() || EitherMouseButtonDown()) {
|
||||
// break;
|
||||
// }
|
||||
if (AnyKeyDown() || EitherMouseButtonDown()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// wait until its time for the next frame
|
||||
nanosleep(&ts, &ts);
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
#include "init.h"
|
||||
#include "loading.h"
|
||||
#include "pc-dos/dossys.h"
|
||||
#include "sound.h"
|
||||
#include "utility.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
@ -808,24 +810,70 @@ void Darken(tU8* pPtr, unsigned int pDarken_amount) {
|
|||
void SetFadedPalette(int pDegree) {
|
||||
int j;
|
||||
br_pixelmap* the_palette;
|
||||
char* the_pixels;
|
||||
NOT_IMPLEMENTED();
|
||||
unsigned char* the_pixels; //JeffH added unsigned
|
||||
LOG_TRACE10("(%d)", pDegree);
|
||||
|
||||
memcpy(gScratch_pixels, gCurrent_palette->pixels, 0x400u);
|
||||
the_pixels = (unsigned char*)gScratch_pixels;
|
||||
|
||||
for (j = 0; j < 1024; j += 4) {
|
||||
the_pixels[j] = (pDegree * the_pixels[j]) / 256;
|
||||
the_pixels[j + 1] = (pDegree * the_pixels[j + 1]) / 256;
|
||||
the_pixels[j + 2] = (pDegree * the_pixels[j + 2]) / 256;
|
||||
the_pixels[j + 3] = (pDegree * the_pixels[j + 3]) / 256;
|
||||
}
|
||||
((int32_t*)gScratch_palette->pixels)[0] = 0;
|
||||
if (!gFaded_palette) {
|
||||
PDSetPalette(gScratch_palette);
|
||||
}
|
||||
gPalette_munged |= gScratch_palette != gRender_palette;
|
||||
}
|
||||
|
||||
// Offset: 20396
|
||||
// Size: 147
|
||||
void FadePaletteDown() {
|
||||
int i;
|
||||
int start_time;
|
||||
int the_time;
|
||||
LOG_WARN("todo");
|
||||
|
||||
if (!gFaded_palette) {
|
||||
gFaded_palette = 1;
|
||||
MungeEngineNoise();
|
||||
gFaded_palette = 0;
|
||||
start_time = PDGetTotalTime();
|
||||
while (1) {
|
||||
the_time = PDGetTotalTime() - start_time;
|
||||
if (the_time >= 500) {
|
||||
break;
|
||||
}
|
||||
i = 256 - ((the_time * 256) / 500);
|
||||
SetFadedPalette(i);
|
||||
}
|
||||
SetFadedPalette(0);
|
||||
gFaded_palette = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Offset: 20544
|
||||
// Size: 116
|
||||
void FadePaletteUp() {
|
||||
int i;
|
||||
int start_time;
|
||||
int the_time;
|
||||
LOG_WARN("todo");
|
||||
|
||||
if (gFaded_palette) {
|
||||
gFaded_palette = 0;
|
||||
start_time = PDGetTotalTime();
|
||||
while (1) {
|
||||
the_time = PDGetTotalTime() - start_time;
|
||||
if (the_time >= 500) {
|
||||
break;
|
||||
}
|
||||
i = (the_time * 256) / 500;
|
||||
SetFadedPalette(i);
|
||||
}
|
||||
DRSetPalette2(gCurrent_palette, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Offset: 20660
|
||||
|
@ -851,7 +899,9 @@ void SplashScreenWith(char* pPixmap_name) {
|
|||
// Offset: 21060
|
||||
// Size: 48
|
||||
void EnsurePaletteUp() {
|
||||
//LOG_WARN("todo");
|
||||
if (gFaded_palette) {
|
||||
FadePaletteUp();
|
||||
}
|
||||
}
|
||||
|
||||
// Offset: 21108
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "input.h"
|
||||
|
||||
#include "common/globvars.h"
|
||||
#include "pc-dos/dossys.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -7,12 +8,12 @@ tJoy_array gJoy_array;
|
|||
tKey_array gKey_array;
|
||||
int gKey_poll_counter;
|
||||
tRolling_letter* gRolling_letters;
|
||||
tU32 gLast_poll_keys;
|
||||
tU32 gLast_poll_keys = 0;
|
||||
int gCurrent_cursor;
|
||||
int gCurrent_position;
|
||||
int gInsert_mode;
|
||||
int gLetter_x_coords[15];
|
||||
int gEdge_trigger_mode;
|
||||
int gEdge_trigger_mode = 0;
|
||||
int gVisible_length;
|
||||
int gLetter_y_coords[15];
|
||||
int gThe_key;
|
||||
|
@ -36,25 +37,40 @@ void SetJoystickArrays(int* pKeys, int pMark) {
|
|||
static tS32 old_joy1Y;
|
||||
static tS32 old_joy2X;
|
||||
static tS32 old_joy2Y;
|
||||
NOT_IMPLEMENTED();
|
||||
}
|
||||
|
||||
// Offset: 996
|
||||
// Size: 82
|
||||
void PollKeys() {
|
||||
NOT_IMPLEMENTED();
|
||||
gKey_poll_counter++;
|
||||
PDSetKeyArray(gKey_array, gKey_poll_counter);
|
||||
SetJoystickArrays(gKey_array, gKey_poll_counter);
|
||||
gLast_poll_keys = PDGetTotalTime();
|
||||
}
|
||||
|
||||
// Offset: 1080
|
||||
// Size: 127
|
||||
void CyclePollKeys() {
|
||||
NOT_IMPLEMENTED();
|
||||
int i;
|
||||
for (i = 0; i < 123; i++) {
|
||||
|
||||
if (gKey_array[i] > gKey_poll_counter) {
|
||||
gKey_array[i] = 0;
|
||||
if (i > 115) {
|
||||
// TOOD: this does _something_, but we cannot figure out what..
|
||||
// eax+1361D4h = -1
|
||||
// gFonts[20].width_table[v1 + 141] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
gKey_poll_counter = 0;
|
||||
}
|
||||
|
||||
// Offset: 1208
|
||||
// Size: 116
|
||||
void ResetPollKeys() {
|
||||
NOT_IMPLEMENTED();
|
||||
memset(gKey_array, 0, sizeof(gKey_array));
|
||||
memset(gJoy_array, 0, sizeof(gJoy_array));
|
||||
}
|
||||
|
||||
// Offset: 1324
|
||||
|
@ -75,7 +91,36 @@ int EitherMouseButtonDown() {
|
|||
// EAX: pKey_index
|
||||
tKey_down_result PDKeyDown2(int pKey_index) {
|
||||
tU32 the_time;
|
||||
NOT_IMPLEMENTED();
|
||||
if (/*!s3_timer_started_maybe[0] ||*/ (PDGetTotalTime() - gLast_poll_keys) > 500) {
|
||||
ResetPollKeys();
|
||||
CyclePollKeys();
|
||||
PollKeys();
|
||||
}
|
||||
|
||||
if (!gEdge_trigger_mode) {
|
||||
return gKey_array[pKey_index];
|
||||
}
|
||||
the_time = PDGetTotalTime();
|
||||
if (gKey_array[pKey_index]) {
|
||||
if (pKey_index == gLast_key_down) {
|
||||
if ((the_time - gLast_key_down_time) < 300) {
|
||||
return tKey_down_still;
|
||||
} else {
|
||||
gLast_key_down_time = the_time;
|
||||
return tKey_down_repeat;
|
||||
}
|
||||
} else {
|
||||
gLast_key_down_time = the_time;
|
||||
gLast_key_down = pKey_index;
|
||||
return tKey_down_yes;
|
||||
}
|
||||
} else {
|
||||
if (pKey_index == gLast_key_down) {
|
||||
gLast_key_down_time = gKey_array[pKey_index];
|
||||
gLast_key_down = -1;
|
||||
}
|
||||
return tKey_down_no;
|
||||
}
|
||||
}
|
||||
|
||||
// Offset: 1700
|
||||
|
@ -101,7 +146,36 @@ int PDKeyDown3(int pKey_index) {
|
|||
int PDAnyKeyDown() {
|
||||
int i;
|
||||
tKey_down_result result;
|
||||
return 0;
|
||||
|
||||
if (/*!s3_timer_started_maybe[0] ||*/ (PDGetTotalTime() - gLast_poll_keys) > 500) {
|
||||
ResetPollKeys();
|
||||
CyclePollKeys();
|
||||
PollKeys();
|
||||
}
|
||||
for (i = 122; i >= 0; i--) {
|
||||
if (gKey_array[i]) {
|
||||
if (!gEdge_trigger_mode) {
|
||||
return i;
|
||||
}
|
||||
result = PDKeyDown2(i);
|
||||
switch (result) {
|
||||
case tKey_down_no:
|
||||
case tKey_down_still:
|
||||
return -1;
|
||||
case tKey_down_yes:
|
||||
case tKey_down_repeat:
|
||||
return i;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gEdge_trigger_mode) {
|
||||
gLast_key_down = -1;
|
||||
gLast_key_down_time = 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Offset: 2160
|
||||
|
@ -127,13 +201,13 @@ tU32* KevKeyService() {
|
|||
static tU32 return_val[2];
|
||||
tU32 keys;
|
||||
|
||||
keys = gLast_key_down;
|
||||
keys = gKeys_pressed;
|
||||
//printf("key: %d, %lx, %lx\n", sizeof(long), keys, code2);
|
||||
return_val[0] = 0;
|
||||
return_val[1] = 0;
|
||||
|
||||
if (keys < 0x6B) {
|
||||
last_single_key = gLast_key_down;
|
||||
last_single_key = gKeys_pressed;
|
||||
} else {
|
||||
if (keys > 0x6b00) {
|
||||
sum = 0;
|
||||
|
|
|
@ -287,7 +287,7 @@ void MungeEngineNoise() {
|
|||
int stop_all;
|
||||
int type_of_engine_noise;
|
||||
tS3_sound_id engine_noise;
|
||||
NOT_IMPLEMENTED();
|
||||
LOG_WARN("skipping");
|
||||
}
|
||||
|
||||
// Offset: 5716
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "dossys.h"
|
||||
|
||||
#include "brender.h"
|
||||
#include "common/car.h"
|
||||
#include "common/errors.h"
|
||||
|
@ -10,6 +9,7 @@
|
|||
#include "common/main.h"
|
||||
#include "common/sound.h"
|
||||
#include "common/utility.h"
|
||||
#include "harness.h"
|
||||
#include "watcom_functions.h"
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
|
@ -52,6 +52,8 @@ int gReal_back_screen_locked;
|
|||
void (*gPrev_keyboard_handler)();
|
||||
tU8 gScan_code[123][2];
|
||||
|
||||
const double NANOSECONDS_TO_MILLISECONDS = 1.0 / 1000000.0;
|
||||
|
||||
int _unittest_do_not_exit = 0;
|
||||
char* _unittest_last_fatal_error;
|
||||
|
||||
|
@ -68,7 +70,7 @@ void KeyboardHandler() {
|
|||
// Size: 71
|
||||
// EAX: pScan_code
|
||||
int KeyDown(tU8 pScan_code) {
|
||||
NOT_IMPLEMENTED();
|
||||
return Harness_Hook_KeyDown(pScan_code);
|
||||
}
|
||||
|
||||
// Offset: 364
|
||||
|
@ -83,6 +85,8 @@ void KeyTranslation(tU8 pKey_index, tU8 pScan_code_1, tU8 pScan_code_2) {
|
|||
// Offset: 436
|
||||
// Size: 1897
|
||||
void KeyBegin() {
|
||||
|
||||
Harness_Hook_KeyBegin();
|
||||
// int v0; // edx@0
|
||||
// int v1; // ST00_4@1
|
||||
// __int16 v2; // dx@1
|
||||
|
@ -222,7 +226,17 @@ void PDSetKeyArray(int* pKeys, int pMark) {
|
|||
int i;
|
||||
tS32 joyX;
|
||||
tS32 joyY;
|
||||
NOT_IMPLEMENTED();
|
||||
LOG_TRACE10("(%p, %d)", pKeys, pMark);
|
||||
|
||||
gKeys_pressed = 0;
|
||||
for (i = 0; i < 123; i++) {
|
||||
if (KeyDown(gScan_code[i][0]) || KeyDown(gScan_code[i][1])) {
|
||||
gKeys_pressed = (gKeys_pressed << 8) + i + 1;
|
||||
pKeys[i] = pMark;
|
||||
} else if (pKeys[i] == pMark) {
|
||||
pKeys[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Offset: 2612
|
||||
|
@ -486,11 +500,8 @@ void PDBuildAppPath(char* pThe_path) {
|
|||
int pos;
|
||||
|
||||
getcwd(pThe_path, 256);
|
||||
pos = strlen(pThe_path);
|
||||
pThe_path[pos] = '/'; // original: pThe_path[pos] = '\\';
|
||||
pThe_path[pos + 1] = 0;
|
||||
strcat(pThe_path, "/"); // original: pThe_path[pos] = '\\';
|
||||
strcpy(gNetwork_profile_fname, pThe_path);
|
||||
pos = strlen(gNetwork_profile_fname);
|
||||
strcat(gNetwork_profile_fname, "NETWORK.INI");
|
||||
}
|
||||
|
||||
|
@ -579,7 +590,7 @@ void PDGetMousePosition(int* pX_coord, int* pY_coord) {
|
|||
int PDGetTotalTime() {
|
||||
struct timespec spec;
|
||||
clock_gettime(CLOCK_MONOTONIC, &spec);
|
||||
return spec.tv_sec * 1000 + spec.tv_nsec / 1000;
|
||||
return spec.tv_sec * 1000 + spec.tv_nsec / 1000000;
|
||||
}
|
||||
|
||||
// Offset: 6312
|
||||
|
@ -901,8 +912,6 @@ int PDCheckDriveExists2(char* pThe_path, char* pFile_name, tU32 pMin_size) {
|
|||
// <<
|
||||
|
||||
stat_failed = stat(the_path, &buf);
|
||||
LOG_DEBUG("path: %d, %s, %d", stat_failed, the_path, buf.st_size);
|
||||
|
||||
return !stat_failed && buf.st_size >= pMin_size;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
BUILD_DIR ?= ./build
|
||||
SRC_DIR ?= .
|
||||
BR_SRC_DIR ?= ../BRSRC13
|
||||
DR_SRC_DIR ?= ../DETHRACE
|
||||
SDL_CLFAGS = `sdl2-config --cflags`
|
||||
|
||||
SRCS := $(shell find $(SRC_DIR) -name "*.c")
|
||||
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
|
||||
DEPS := $(OBJS:.o=.d)
|
||||
|
||||
INC_DIRS := $(shell find $(SRC_DIR) -type d) $(BR_SRC_DIR)
|
||||
INC_DIRS := $(shell find $(SRC_DIR) -type d) $(BR_SRC_DIR) $(DR_SRC_DIR)
|
||||
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
||||
|
||||
CFLAGS ?= $(INC_FLAGS) $(SDL_CLFAGS) -g -Wno-return-type -Wno-missing-declarations -Werror=implicit-function-declaration
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include "harness.h"
|
||||
#include "input/keyboard.h"
|
||||
#include "stack_trace_handler.h"
|
||||
|
||||
SDL_Window* window;
|
||||
|
@ -8,6 +9,9 @@ renderer* current_renderer;
|
|||
br_pixelmap* palette;
|
||||
uint32_t* screen_buffer;
|
||||
|
||||
br_pixelmap* last_dst = NULL;
|
||||
br_pixelmap* last_src = NULL;
|
||||
|
||||
void Harness_Init(char* name, renderer* renderer) {
|
||||
install_signal_handler(name);
|
||||
current_renderer = renderer;
|
||||
|
@ -38,6 +42,11 @@ void Harness_RunWindowLoop(harness_game_func* game_func, void* arg) {
|
|||
while (keep_pumping) {
|
||||
if (SDL_WaitEvent(&event)) {
|
||||
switch (event.type) {
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
Keyboard_HandleEvent(&event.key);
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
keep_pumping = 0;
|
||||
}
|
||||
|
@ -50,7 +59,7 @@ void Harness_Hook_DOSGfxBegin() {
|
|||
current_renderer->activate(window);
|
||||
}
|
||||
|
||||
void Harness_Hook_BrPixelmapDoubleBuffer(br_pixelmap* dst, br_pixelmap* src) {
|
||||
void Harness_RenderScreen(br_pixelmap* dst, br_pixelmap* src) {
|
||||
uint8_t palette_index = 0;
|
||||
int inc = 0;
|
||||
uint8_t* data = src->pixels;
|
||||
|
@ -78,6 +87,23 @@ void Harness_Hook_BrPixelmapDoubleBuffer(br_pixelmap* dst, br_pixelmap* src) {
|
|||
}
|
||||
current_renderer->doubleBuffer(screen_buffer, window);
|
||||
}
|
||||
|
||||
void Harness_Hook_BrPixelmapDoubleBuffer(br_pixelmap* dst, br_pixelmap* src) {
|
||||
last_dst = dst;
|
||||
last_src = src;
|
||||
Harness_RenderScreen(dst, src);
|
||||
}
|
||||
void Harness_Hook_BrDevPaletteSetOld(br_pixelmap* pm) {
|
||||
palette = pm;
|
||||
if (last_dst && last_src) {
|
||||
Harness_RenderScreen(last_dst, last_src);
|
||||
}
|
||||
}
|
||||
|
||||
void Harness_Hook_KeyBegin() {
|
||||
Keyboard_Init();
|
||||
}
|
||||
|
||||
int Harness_Hook_KeyDown(unsigned char pScan_code) {
|
||||
return Keyboard_IsKeyDown(pScan_code);
|
||||
}
|
|
@ -22,4 +22,7 @@ void Harness_Hook_DOSGfxBegin();
|
|||
void Harness_Hook_BrDevPaletteSetOld(br_pixelmap* pm);
|
||||
void Harness_Hook_BrPixelmapDoubleBuffer(br_pixelmap* dst, br_pixelmap* src);
|
||||
|
||||
void Harness_Hook_KeyBegin();
|
||||
int Harness_Hook_KeyDown(unsigned char pScan_code);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,146 @@
|
|||
#include "dr_types.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "keyboard.h"
|
||||
|
||||
extern tU8 gScan_code[123][2];
|
||||
|
||||
uint8_t sdl_key_state[123];
|
||||
|
||||
// Errol's keymap
|
||||
int keymap[123] = {
|
||||
SDL_SCANCODE_LSHIFT,
|
||||
SDL_SCANCODE_LALT,
|
||||
SDL_SCANCODE_LCTRL,
|
||||
-1,
|
||||
SDL_SCANCODE_CAPSLOCK,
|
||||
|
||||
SDL_SCANCODE_RSHIFT,
|
||||
SDL_SCANCODE_RALT,
|
||||
SDL_SCANCODE_RCTRL,
|
||||
SDL_SCANCODE_LSHIFT,
|
||||
SDL_SCANCODE_LALT,
|
||||
SDL_SCANCODE_LCTRL,
|
||||
|
||||
SDL_SCANCODE_0,
|
||||
SDL_SCANCODE_1,
|
||||
SDL_SCANCODE_2,
|
||||
SDL_SCANCODE_3,
|
||||
SDL_SCANCODE_4,
|
||||
SDL_SCANCODE_5,
|
||||
SDL_SCANCODE_6,
|
||||
SDL_SCANCODE_7,
|
||||
SDL_SCANCODE_8,
|
||||
SDL_SCANCODE_9,
|
||||
SDL_SCANCODE_A,
|
||||
SDL_SCANCODE_B,
|
||||
SDL_SCANCODE_C,
|
||||
SDL_SCANCODE_D,
|
||||
SDL_SCANCODE_E,
|
||||
SDL_SCANCODE_F,
|
||||
SDL_SCANCODE_G,
|
||||
SDL_SCANCODE_H,
|
||||
SDL_SCANCODE_I,
|
||||
SDL_SCANCODE_J,
|
||||
SDL_SCANCODE_K,
|
||||
SDL_SCANCODE_L,
|
||||
SDL_SCANCODE_M,
|
||||
SDL_SCANCODE_N,
|
||||
SDL_SCANCODE_O,
|
||||
SDL_SCANCODE_P,
|
||||
SDL_SCANCODE_Q,
|
||||
SDL_SCANCODE_R,
|
||||
SDL_SCANCODE_S,
|
||||
SDL_SCANCODE_T,
|
||||
SDL_SCANCODE_U,
|
||||
SDL_SCANCODE_V,
|
||||
SDL_SCANCODE_W,
|
||||
SDL_SCANCODE_X,
|
||||
SDL_SCANCODE_Y,
|
||||
SDL_SCANCODE_Z,
|
||||
|
||||
SDL_SCANCODE_GRAVE,
|
||||
SDL_SCANCODE_MINUS,
|
||||
SDL_SCANCODE_EQUALS,
|
||||
SDL_SCANCODE_BACKSPACE,
|
||||
SDL_SCANCODE_RETURN,
|
||||
SDL_SCANCODE_KP_ENTER,
|
||||
SDL_SCANCODE_TAB,
|
||||
SDL_SCANCODE_KP_DIVIDE,
|
||||
SDL_SCANCODE_SLASH,
|
||||
SDL_SCANCODE_SEMICOLON,
|
||||
SDL_SCANCODE_APOSTROPHE,
|
||||
SDL_SCANCODE_PERIOD,
|
||||
SDL_SCANCODE_COMMA,
|
||||
SDL_SCANCODE_LEFTBRACKET,
|
||||
SDL_SCANCODE_RIGHTBRACKET,
|
||||
-1,
|
||||
SDL_SCANCODE_ESCAPE,
|
||||
SDL_SCANCODE_INSERT,
|
||||
SDL_SCANCODE_DELETE,
|
||||
SDL_SCANCODE_HOME,
|
||||
SDL_SCANCODE_END,
|
||||
SDL_SCANCODE_PAGEUP,
|
||||
SDL_SCANCODE_PAGEDOWN,
|
||||
SDL_SCANCODE_LEFT,
|
||||
SDL_SCANCODE_RIGHT,
|
||||
SDL_SCANCODE_UP,
|
||||
SDL_SCANCODE_DOWN,
|
||||
-1,
|
||||
SDL_SCANCODE_KP_DIVIDE,
|
||||
SDL_SCANCODE_KP_MULTIPLY,
|
||||
SDL_SCANCODE_KP_MINUS,
|
||||
SDL_SCANCODE_KP_PLUS,
|
||||
SDL_SCANCODE_KP_PERIOD,
|
||||
SDL_SCANCODE_KP_EQUALS,
|
||||
SDL_SCANCODE_KP_0,
|
||||
SDL_SCANCODE_KP_1,
|
||||
SDL_SCANCODE_KP_2,
|
||||
SDL_SCANCODE_KP_3,
|
||||
SDL_SCANCODE_KP_4,
|
||||
SDL_SCANCODE_KP_5,
|
||||
SDL_SCANCODE_KP_6,
|
||||
SDL_SCANCODE_KP_7,
|
||||
SDL_SCANCODE_KP_8,
|
||||
SDL_SCANCODE_KP_9,
|
||||
SDL_SCANCODE_F1,
|
||||
SDL_SCANCODE_F2,
|
||||
SDL_SCANCODE_F3,
|
||||
SDL_SCANCODE_F4,
|
||||
SDL_SCANCODE_F5,
|
||||
SDL_SCANCODE_F6,
|
||||
SDL_SCANCODE_F7,
|
||||
SDL_SCANCODE_F8,
|
||||
SDL_SCANCODE_F9,
|
||||
SDL_SCANCODE_F10,
|
||||
SDL_SCANCODE_F11,
|
||||
SDL_SCANCODE_F12,
|
||||
SDL_SCANCODE_PRINTSCREEN,
|
||||
-1,
|
||||
SDL_SCANCODE_PAUSE,
|
||||
SDL_SCANCODE_SPACE
|
||||
};
|
||||
|
||||
void Keyboard_Init() {
|
||||
int i;
|
||||
for (i = 0; i < 123; i++) {
|
||||
gScan_code[i][0] = keymap[i];
|
||||
//gScan_code[i][1] = keymap[i];
|
||||
}
|
||||
}
|
||||
|
||||
int Keyboard_IsKeyDown(unsigned char scan_code) {
|
||||
return sdl_key_state[scan_code];
|
||||
}
|
||||
|
||||
void Keyboard_HandleEvent(SDL_KeyboardEvent* key) {
|
||||
if (key->keysym.scancode < 0 || key->keysym.scancode > 122) {
|
||||
LOG_WARN("unexpected scan code %d", key->keysym.scancode);
|
||||
return;
|
||||
}
|
||||
if (key->type == SDL_KEYDOWN) {
|
||||
sdl_key_state[key->keysym.scancode] = 1;
|
||||
} else {
|
||||
sdl_key_state[key->keysym.scancode] = 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef HARNESS_KEYBOARD_H
|
||||
#define HARNESS_KEYBOARD_H
|
||||
|
||||
void Keyboard_Init();
|
||||
void Keyboard_HandleEvent(SDL_KeyboardEvent* key);
|
||||
int Keyboard_IsKeyDown(unsigned char scan_code);
|
||||
|
||||
#endif
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "common/controls.h"
|
||||
#include "common/errors.h"
|
||||
#include "common/globvars.h"
|
||||
#include "common/input.h"
|
||||
#include "common/loading.h"
|
||||
#include "common/utility.h"
|
||||
|
@ -16,13 +17,13 @@ void test_controls_CheckKevKeys() {
|
|||
char* input = "spamfritters";
|
||||
tU32* result;
|
||||
for (i = 0; i < strlen(input); i++) {
|
||||
gLast_key_down = input[i] - 75; // 0x1e;
|
||||
gKeys_pressed = input[i] - 75; // 0x1e;
|
||||
result = KevKeyService();
|
||||
gLast_key_down = 0;
|
||||
gKeys_pressed = 0;
|
||||
result = KevKeyService();
|
||||
}
|
||||
sleep(1);
|
||||
gLast_key_down = 0;
|
||||
sleep(2);
|
||||
gKeys_pressed = 0;
|
||||
|
||||
CheckKevKeys();
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "tests.h"
|
||||
|
||||
#include "common/globvars.h"
|
||||
#include "common/input.h"
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
@ -9,13 +10,13 @@ void test_input_KevKeyService() {
|
|||
char* input = "iwanttofiddle";
|
||||
tU32* result;
|
||||
for (i = 0; i < strlen(input); i++) {
|
||||
gLast_key_down = input[i] - 75;
|
||||
gKeys_pressed = input[i] - 75;
|
||||
result = KevKeyService();
|
||||
gLast_key_down = 0;
|
||||
gKeys_pressed = 0;
|
||||
result = KevKeyService();
|
||||
}
|
||||
sleep(1);
|
||||
gLast_key_down = 0;
|
||||
sleep(2);
|
||||
gKeys_pressed = 0;
|
||||
result = KevKeyService();
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(0x33f75455, result[0]);
|
||||
|
|
Loading…
Reference in New Issue