New console system WIP
This commit is contained in:
127
ascii.cpp
127
ascii.cpp
@@ -5,6 +5,9 @@
|
|||||||
#include "rom.c"
|
#include "rom.c"
|
||||||
#include "play.h"
|
#include "play.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#define swap(a, b) {auto tmp=a;a=b;b=tmp;}
|
#define swap(a, b) {auto tmp=a;a=b;b=tmp;}
|
||||||
|
|
||||||
#define AUDIO_NONE 0
|
#define AUDIO_NONE 0
|
||||||
@@ -43,13 +46,14 @@ int pitch;
|
|||||||
uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0000, 0x00AA00AA, 0x00AA5500, 0x00AAAAAA,
|
uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0000, 0x00AA00AA, 0x00AA5500, 0x00AAAAAA,
|
||||||
0x00555555, 0x005555FF, 0x0055FF55, 0x0055FFFF, 0x00FF5555, 0x00FF55FF, 0x00FFFF55, 0x00FFFFFF };
|
0x00555555, 0x005555FF, 0x0055FF55, 0x0055FFFF, 0x00FF5555, 0x00FF55FF, 0x00FFFF55, 0x00FFFFFF };
|
||||||
|
|
||||||
#define debug_line_size 80
|
//[TODEL]#define debug_line_size 80
|
||||||
#define debug_num_lines 30
|
//#define debug_num_lines 30
|
||||||
#define debug_total_size 2400 //debug_line_size*debug_num_lines
|
//#define debug_total_size 2400 //debug_line_size*debug_num_lines
|
||||||
char debug_text[debug_total_size];
|
//char debug_text[debug_total_size];
|
||||||
int debug_cursor = 0;
|
//int debug_cursor = 0;
|
||||||
int debug_prompt = 0;
|
int debug_prompt = -1;
|
||||||
int debug_cursor_blink = 30;
|
int debug_cursor_blink = 30;
|
||||||
|
std::vector<std::string> cmd_list;
|
||||||
bool should_reset = false;
|
bool should_reset = false;
|
||||||
|
|
||||||
//Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X };
|
//Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X };
|
||||||
@@ -145,11 +149,13 @@ void romcpy() {
|
|||||||
SDL_memcpy(&mem[2560], rom, rom_size);
|
SDL_memcpy(&mem[2560], rom, rom_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void debug_set_prompt();
|
||||||
|
|
||||||
int main(int argc,char*argv[]) {
|
int main(int argc,char*argv[]) {
|
||||||
SDL_strlcpy(lua_filename, "game.lua", 9);
|
SDL_strlcpy(lua_filename, "game.lua", 9);
|
||||||
if (argc > 1) SDL_strlcpy(lua_filename, argv[1], 1023);
|
if (argc > 1) SDL_strlcpy(lua_filename, argv[1], 1023);
|
||||||
|
|
||||||
for (int i=0; i<debug_total_size;++i) debug_text[i] = 32;
|
//[TODEL]for (int i=0; i<debug_total_size;++i) debug_text[i] = 32;
|
||||||
|
|
||||||
SDL_Init(49);
|
SDL_Init(49);
|
||||||
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640+80, 480+80, SDL_WINDOW_SHOWN);
|
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640+80, 480+80, SDL_WINDOW_SHOWN);
|
||||||
@@ -187,13 +193,16 @@ int main(int argc,char*argv[]) {
|
|||||||
if (lua_is_playing()) {
|
if (lua_is_playing()) {
|
||||||
lua_pause();
|
lua_pause();
|
||||||
//lua_quit();
|
//lua_quit();
|
||||||
old_mode = current_mode;
|
debug_set_prompt();
|
||||||
setmode(0);
|
//old_mode = current_mode;
|
||||||
|
//setmode(0);
|
||||||
} else {
|
} else {
|
||||||
setmode(old_mode);
|
//setmode(old_mode);
|
||||||
lua_resume();
|
//lua_resume();
|
||||||
//lua_init();
|
lua_quit();
|
||||||
//lua_call_init();
|
reinit();
|
||||||
|
lua_init(lua_filename);
|
||||||
|
lua_call_init();
|
||||||
}
|
}
|
||||||
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F5) {
|
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F5) {
|
||||||
lua_quit();
|
lua_quit();
|
||||||
@@ -219,7 +228,8 @@ int main(int argc,char*argv[]) {
|
|||||||
debug_cursor_blink--;
|
debug_cursor_blink--;
|
||||||
if (debug_cursor_blink == 0) {
|
if (debug_cursor_blink == 0) {
|
||||||
debug_cursor_blink = 30;
|
debug_cursor_blink = 30;
|
||||||
debug_text[debug_cursor] = debug_text[debug_cursor]==32 ? 95 : 32;
|
const int pos = cursor_x+cursor_y*screen_width;
|
||||||
|
char_screen[pos] = char_screen[pos]==32 ? 95 : 32;
|
||||||
}
|
}
|
||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
@@ -288,13 +298,11 @@ int main(int argc,char*argv[]) {
|
|||||||
void cls(uint8_t value) {
|
void cls(uint8_t value) {
|
||||||
SDL_memset(char_screen, value, screen_width*screen_height);
|
SDL_memset(char_screen, value, screen_width*screen_height);
|
||||||
if (current_mode != 0) SDL_memset(color_screen, current_color, screen_width*screen_height);
|
if (current_mode != 0) SDL_memset(color_screen, current_color, screen_width*screen_height);
|
||||||
if (!lua_is_playing()) {
|
|
||||||
SDL_memset(debug_text, 32, debug_total_size);
|
|
||||||
debug_cursor = 1;
|
|
||||||
debug_prompt = 0;
|
|
||||||
debug_text[debug_prompt] = '>';
|
|
||||||
}
|
|
||||||
cursor_x = cursor_y = 0;
|
cursor_x = cursor_y = 0;
|
||||||
|
if (!lua_is_playing()) {
|
||||||
|
char_screen[0] = '>';
|
||||||
|
cursor_x=1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ink(uint8_t value) {
|
void ink(uint8_t value) {
|
||||||
@@ -436,41 +444,54 @@ const char* tostr(float val) {
|
|||||||
return SDL_itoa(val, str_tmp, 10);
|
return SDL_itoa(val, str_tmp, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_set_prompt() {
|
void debug_one_line_up() {
|
||||||
debug_prompt = debug_cursor++;
|
int total = screen_width*screen_height-screen_width;
|
||||||
debug_text[debug_prompt] = '>';
|
for (int i=0; i<total;++i) char_screen[i] = char_screen[i+screen_width];
|
||||||
|
for (int i=total; i<screen_width*screen_height;++i) char_screen[i] = 32;
|
||||||
|
cursor_y = screen_height-1;
|
||||||
|
//debug_set_prompt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_one_line_up() {
|
void debug_set_prompt() {
|
||||||
for (int i=0; i<debug_total_size-debug_line_size;++i) debug_text[i] = debug_text[i+debug_line_size];
|
if (debug_prompt == cursor_x+cursor_y*screen_width) return;
|
||||||
for (int i=debug_total_size-debug_line_size; i<debug_total_size;++i) debug_text[i] = 32;
|
if (cursor_x>0) { cursor_x=0;cursor_y++;if(cursor_y>=screen_height) debug_one_line_up(); }
|
||||||
debug_cursor = debug_total_size-debug_line_size;
|
char_screen[cursor_x+cursor_y*screen_width] = '>';
|
||||||
debug_set_prompt();
|
cursor_x++;
|
||||||
|
debug_prompt = cursor_x+cursor_y*screen_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void debugchr(const uint8_t chr) {
|
void debugchr(const uint8_t chr) {
|
||||||
|
int pos = cursor_x+cursor_y*screen_width;
|
||||||
if (chr == 8) {
|
if (chr == 8) {
|
||||||
if (debug_cursor>(debug_prompt+1)) {
|
if (cursor_x>1) {
|
||||||
debug_text[debug_cursor--] = 32;
|
char_screen[pos++] = 32;
|
||||||
debug_text[debug_cursor] = 32;
|
char_screen[pos] = 32;
|
||||||
|
cursor_x--;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug_text[debug_cursor++] = chr;
|
char_screen[pos] = chr;
|
||||||
if (debug_cursor >= debug_total_size) debug_one_line_up();
|
cursor_x++;
|
||||||
|
if (cursor_x >= screen_width) {
|
||||||
|
cursor_x=0; cursor_y++;
|
||||||
|
if (cursor_y >= screen_height) debug_one_line_up();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug(const char *str) {
|
void debug(const char *str) {
|
||||||
const int len = SDL_strlen(str);
|
const int len = SDL_strlen(str);
|
||||||
|
int cursor = cursor_x+cursor_y*screen_width;
|
||||||
for (int i=0; i<len;++i) {
|
for (int i=0; i<len;++i) {
|
||||||
debug_text[debug_cursor++] = str[i];
|
char_screen[cursor++] = str[i];
|
||||||
if (debug_cursor >= debug_total_size) debug_one_line_up();
|
if (cursor >= screen_width*screen_height) debug_one_line_up();
|
||||||
}
|
}
|
||||||
debug_cursor = (int(debug_cursor/debug_line_size)+1)*debug_line_size;
|
cursor_x = 0;
|
||||||
if (debug_cursor >= debug_total_size) debug_one_line_up();
|
cursor_y = (cursor/screen_width)+1;
|
||||||
debug_set_prompt();
|
if (cursor_y >= screen_height) debug_one_line_up();
|
||||||
|
//debug_set_prompt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*[TODEL]
|
||||||
void pdebug() {
|
void pdebug() {
|
||||||
int i=0;
|
int i=0;
|
||||||
for (int y=0; y<debug_num_lines;++y) {
|
for (int y=0; y<debug_num_lines;++y) {
|
||||||
@@ -480,10 +501,34 @@ void pdebug() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
int cmd_index = 0;
|
||||||
void debug_get_cmd() {
|
void debug_get_cmd() {
|
||||||
debug_text[debug_cursor] = 0;
|
char_screen[cursor_x+cursor_y*screen_width] = 0;
|
||||||
lua_call_cmd(&debug_text[debug_prompt+1]);
|
//char *tmp = (char*)&char_screen[1+cursor_y*screen_width];
|
||||||
|
char *tmp = (char*)&char_screen[debug_prompt];
|
||||||
|
cmd_list.push_back(tmp);
|
||||||
|
char_screen[cursor_x+cursor_y*screen_width] = 32;
|
||||||
|
cursor_x=0;cursor_y++;if(cursor_y>=screen_height)debug_one_line_up();
|
||||||
|
cmd_index=0;
|
||||||
|
lua_call_cmd(cmd_list[cmd_list.size()-1].c_str());
|
||||||
|
//if ((cursor_y>0) || (cursor_x>0)) { cursor_x=0;cursor_y++;if(cursor_y>=screen_height)debug_one_line_up(); }
|
||||||
|
debug_set_prompt();
|
||||||
|
}
|
||||||
|
|
||||||
|
void next_cmd() {
|
||||||
|
if (cmd_index < cmd_list.size()) cmd_index++;
|
||||||
|
const char* cmd = cmd_list[cmd_list.size()-cmd_index].c_str();
|
||||||
|
int pos = cursor_x+cursor_y*screen_width;
|
||||||
|
for (int i=debug_prompt;i<=pos;++i) char_screen[i] = 32;
|
||||||
|
SDL_memcpy(&char_screen[debug_prompt], cmd, strlen(cmd));
|
||||||
|
pos += debug_prompt;
|
||||||
|
cursor_x = pos%screen_width;
|
||||||
|
cursor_y = pos/screen_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
void prev_cmd() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ascii(const char *str, uint8_t index) {
|
uint8_t ascii(const char *str, uint8_t index) {
|
||||||
|
|||||||
4
ascii.h
4
ascii.h
@@ -159,8 +159,10 @@ const char* tostr(float val);
|
|||||||
|
|
||||||
void debugchr(const uint8_t chr);
|
void debugchr(const uint8_t chr);
|
||||||
void debug(const char *str);
|
void debug(const char *str);
|
||||||
void pdebug();
|
//void pdebug();
|
||||||
void debug_get_cmd();
|
void debug_get_cmd();
|
||||||
|
void next_cmd();
|
||||||
|
void prev_cmd();
|
||||||
|
|
||||||
uint8_t ascii(const char *str, uint8_t index);
|
uint8_t ascii(const char *str, uint8_t index);
|
||||||
const char* chr(uint8_t ascii);
|
const char* chr(uint8_t ascii);
|
||||||
|
|||||||
4
lua.cpp
4
lua.cpp
@@ -635,12 +635,12 @@ void lua_init(const char* filename, const bool start_playing) {
|
|||||||
|
|
||||||
void lua_call_cmd(const char* str) {
|
void lua_call_cmd(const char* str) {
|
||||||
if (luaL_dostring(L, str)) {
|
if (luaL_dostring(L, str)) {
|
||||||
debug(" ");
|
//debug(" ");
|
||||||
debug("ERROR");
|
debug("ERROR");
|
||||||
debug(lua_tostring(L, -1));
|
debug(lua_tostring(L, -1));
|
||||||
lua_pop(L,1);
|
lua_pop(L,1);
|
||||||
}
|
}
|
||||||
debug(" ");
|
//debug(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void lua_call_init() {
|
void lua_call_init() {
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -36,7 +36,7 @@ void do_terminal() {
|
|||||||
else if (key == KEY_RIGHTBRACKET) { if (mods & KMOD_SHIFT) { debugchr('*'); } else if (mods & KMOD_RALT) { debugchr(']'); } else { debugchr('+'); } }
|
else if (key == KEY_RIGHTBRACKET) { if (mods & KMOD_SHIFT) { debugchr('*'); } else if (mods & KMOD_RALT) { debugchr(']'); } else { debugchr('+'); } }
|
||||||
}
|
}
|
||||||
//cls(0);
|
//cls(0);
|
||||||
pdebug();
|
//pdebug();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user