Working on the terminal...

This commit is contained in:
2021-12-05 10:16:37 +01:00
parent 9e547e7292
commit fe9220bb39
6 changed files with 99 additions and 28 deletions

View File

@@ -38,6 +38,7 @@ uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0
#define debug_total_size 2400 //debug_line_size*debug_num_lines
char debug_text[debug_total_size];
int debug_cursor = 0;
int debug_prompt = 0;
int debug_cursor_blink = 30;
//Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X };
@@ -53,12 +54,12 @@ void reinit() {
case 0:
screen_width = 80;
screen_height = 30;
current_color = 0x1e;
current_color = 0x19;
cursor_x = 0;
cursor_y = 0;
char_screen = &mem[0];
color_screen = &mem[1200];
SDL_RenderSetLogicalSize(mini_ren, 640, 480);
//SDL_RenderSetLogicalSize(mini_ren, 640, 480);
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 640, 240);
break;
case 1:
@@ -69,7 +70,7 @@ void reinit() {
cursor_y = 0;
char_screen = &mem[0];
color_screen = &mem[1200];
SDL_RenderSetLogicalSize(mini_ren, 320, 240);
//SDL_RenderSetLogicalSize(mini_ren, 320, 240);
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 240);
break;
case 2:
@@ -80,7 +81,7 @@ void reinit() {
cursor_y = 0;
char_screen = &mem[0];
color_screen = &mem[300];
SDL_RenderSetLogicalSize(mini_ren, 160, 120);
//SDL_RenderSetLogicalSize(mini_ren, 160, 120);
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 160, 120);
break;
}
@@ -104,7 +105,7 @@ int main(int argc,char*argv[]) {
for (int i=0; i<debug_total_size;++i) debug_text[i] = 32;
SDL_Init(49);
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640+80, 480+80, SDL_WINDOW_SHOWN);
mini_ren = SDL_CreateRenderer(mini_win, -1, SDL_RENDERER_PRESENTVSYNC);
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
//SDL_RenderSetLogicalSize(mini_ren, 320, 240);
@@ -129,12 +130,14 @@ int main(int argc,char*argv[]) {
if (mini_eve.type == SDL_KEYDOWN) {
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
if (lua_is_playing()) {
lua_quit();
lua_pause();
//lua_quit();
setmode(0);
} else {
setmode(1);
lua_init();
lua_call_init();
lua_resume();
//lua_init();
//lua_call_init();
}
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F5) {
lua_quit();
@@ -212,7 +215,12 @@ int main(int argc,char*argv[]) {
//for (int i=0;i<screen_surface->size;++i) pixels[i] = palette[screen_surface->p[i]];
SDL_UnlockTexture(mini_bak);
SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
SDL_SetRenderDrawColor(mini_ren, (palette[9] >> 16)&0xff, (palette[9] >> 8)&0xff, palette[9]&0xff, 0);
//SDL_SetRenderDrawColor(mini_ren, 255, 0, 0, 0);
SDL_RenderClear(mini_ren);
SDL_Rect rect = {40, 40, 640, 480};
SDL_RenderCopy(mini_ren, mini_bak, NULL, &rect);
//SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
SDL_RenderPresent(mini_ren);
}
lua_quit();
@@ -348,16 +356,24 @@ const char* tostr(int val) {
return SDL_itoa(val, tostr_tmp, 10);
}
void debug_set_prompt() {
debug_prompt = debug_cursor++;
debug_text[debug_prompt] = '>';
}
void debug_one_line_up() {
for (int i=0; i<debug_total_size-debug_line_size;++i) debug_text[i] = debug_text[i+debug_line_size];
for (int i=debug_total_size-debug_line_size; i<debug_total_size;++i) debug_text[i] = 32;
debug_cursor = debug_total_size-debug_line_size;
debug_set_prompt();
}
void debugchr(const uint8_t chr) {
if (chr == 8) {
debug_text[debug_cursor--] = 32;
debug_text[debug_cursor] = 32;
if (debug_cursor>(debug_prompt+1)) {
debug_text[debug_cursor--] = 32;
debug_text[debug_cursor] = 32;
}
} else {
debug_text[debug_cursor++] = chr;
if (debug_cursor >= debug_total_size) debug_one_line_up();
@@ -372,6 +388,7 @@ void debug(const char *str) {
}
debug_cursor = (int(debug_cursor/debug_line_size)+1)*debug_line_size;
if (debug_cursor >= debug_total_size) debug_one_line_up();
debug_set_prompt();
}
void pdebug() {
@@ -384,6 +401,11 @@ void pdebug() {
}
}
void debug_get_cmd() {
debug_text[debug_cursor] = 0;
lua_call_cmd(&debug_text[debug_prompt+1]);
}
uint8_t ascii(const char *str, uint8_t index) {
return str[index];
}