126 lines
3.1 KiB
C
126 lines
3.1 KiB
C
|
#include <stdbool.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <time.h>
|
||
|
|
||
|
#include <sys/ksys.h>
|
||
|
|
||
|
#include "misc.h"
|
||
|
#include "graphics.h"
|
||
|
#include "distance_meter.h"
|
||
|
#include "cloud.h"
|
||
|
#include "obstacle.h"
|
||
|
#include "horizon_line.h"
|
||
|
#include "trex.h"
|
||
|
#include "runner.h"
|
||
|
|
||
|
#pragma warning(disable:4996)
|
||
|
|
||
|
uint8_t keyboard_layout[128];
|
||
|
|
||
|
int main(int argc, char* args[]) {
|
||
|
srand((unsigned int)time(NULL)); // Seed the random number generator
|
||
|
|
||
|
graphicsInit();
|
||
|
|
||
|
runnerInit();
|
||
|
|
||
|
_ksys_debug_puts("3333333");
|
||
|
_ksys_debug_puts("xABCDEFuuit56\n\n");
|
||
|
|
||
|
_ksys_set_event_mask(0xC0000027); // !
|
||
|
_ksys_set_key_input_mode(KSYS_KEY_INPUT_MODE_SCANC);
|
||
|
_ksys_keyboard_layout(KSYS_KEYBOARD_LAYOUT_NORMAL, keyboard_layout);
|
||
|
|
||
|
uint32_t kos_event;
|
||
|
int ext_code = 0;
|
||
|
uint8_t old_mode = 0;
|
||
|
|
||
|
bool quit = false;
|
||
|
while (quit == false) {
|
||
|
int frameStartTime = getTimeStamp();
|
||
|
//printf("frameStartTime = %d\n", frameStartTime);
|
||
|
kos_event = _ksys_check_event();
|
||
|
switch (kos_event) {
|
||
|
case KSYS_EVENT_BUTTON:
|
||
|
switch (_ksys_get_button()){
|
||
|
case 1:
|
||
|
quit = true;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
break;
|
||
|
case KSYS_EVENT_KEY:
|
||
|
{
|
||
|
ksys_oskey_t key = _ksys_get_key();
|
||
|
uint8_t scancode = key.code;
|
||
|
if (scancode == 0xE0 || scancode == 0xE1) {
|
||
|
ext_code = scancode;
|
||
|
break;
|
||
|
}
|
||
|
if (ext_code == 0xE1 && (scancode & 0x7F) == 0x1D) {
|
||
|
break;
|
||
|
}
|
||
|
if (ext_code == 0xE1 && scancode == 0xC5) {
|
||
|
ext_code = 0;
|
||
|
break;
|
||
|
}
|
||
|
uint8_t code = keyboard_layout[scancode & 0x7F];
|
||
|
|
||
|
if (ext_code == 0xE0) {
|
||
|
code -= 96;
|
||
|
}
|
||
|
ext_code = 0;
|
||
|
|
||
|
if (scancode < 128) { // KEYDOWN
|
||
|
//debug_printf("Keydown: key = 0x%x, scancode = 0x%x, code = 0x%x (%u) state = 0x%x\n", key.val, scancode, code, code, key.state);
|
||
|
runnerOnKeyDown(code);
|
||
|
} else { // KEYUP
|
||
|
//debug_printf("Keyup: key = 0x%x, scancode = 0x%x, code = 0x%x (%u) state = 0x%x\n", key.val, scancode, code, code, key.state);
|
||
|
runnerOnKeyUp(code);
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
// case SDL_KEYDOWN:
|
||
|
// //printf("DOWN%d ", event.key.keysym.sym & 0xFF);
|
||
|
// runnerOnKeyDown(event.key.keysym.sym & 0xFF);
|
||
|
// break;
|
||
|
// case SDL_KEYUP:
|
||
|
// //printf("UP%d ", event.key.keysym.sym & 0xFF);
|
||
|
// runnerOnKeyUp(event.key.keysym.sym & 0xFF);
|
||
|
// break;
|
||
|
case KSYS_EVENT_REDRAW:
|
||
|
graphicsRender();
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
if (runner.nextUpdateScheduled) {
|
||
|
//printf("runner update! %u\n", getTimeStamp());
|
||
|
runnerUpdate();
|
||
|
}
|
||
|
else {
|
||
|
if (runner.skipUpdateNow) {
|
||
|
//printf("Skipped one update\n");
|
||
|
runner.nextUpdateScheduled = true;
|
||
|
runner.skipUpdateNow = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int frameTime = getTimeStamp() - frameStartTime;
|
||
|
#define FRAME_TIME 20 //16
|
||
|
// debug_printf("frameTime = %d\n", frameTime);
|
||
|
if (frameTime < FRAME_TIME) { // 1000ms/60frames = 16.(6)
|
||
|
// printf("frameTime = %d\n", frameTime);
|
||
|
graphicsDelay(FRAME_TIME - frameTime);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
graphicsDestroy();
|
||
|
|
||
|
return 0;
|
||
|
}
|