- new debug system
This commit is contained in:
8
lua.cpp
8
lua.cpp
@@ -914,14 +914,14 @@ void lua_init(char* filenames) {
|
||||
int size;
|
||||
char* buffer = file_getfilebuffer(file_start, size);
|
||||
if (luaL_loadbuffer(L, buffer, size, file_start)) {
|
||||
debug("error loading game");
|
||||
debug("LOADING ERROR:");
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
return;
|
||||
}
|
||||
free(buffer);
|
||||
if (lua_pcall(L,0, LUA_MULTRET, 0)) {
|
||||
debug("runtime error");
|
||||
debug("RUNTIME ERROR:");
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
return;
|
||||
@@ -945,7 +945,7 @@ void lua_call_init() {
|
||||
if (!init_exists) return;
|
||||
lua_getglobal(L, "_init");
|
||||
if (lua_pcall(L, 0, 0, 0)) {
|
||||
debug("runtime error");
|
||||
debug("RUNTIME ERROR:");
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
is_playing = false;
|
||||
@@ -956,7 +956,7 @@ void lua_call_update() {
|
||||
if (!update_exists) return;
|
||||
lua_getglobal(L, "_update");
|
||||
if (lua_pcall(L, 0, 0, 0)) {
|
||||
debug("runtime error");
|
||||
debug("RUNTIME ERROR:");
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
is_playing = false;
|
||||
|
||||
37
main.cpp
37
main.cpp
@@ -1,36 +1,9 @@
|
||||
#include "mini.h"
|
||||
|
||||
int current_editor = 0;
|
||||
|
||||
void do_terminal() {
|
||||
cls(0);
|
||||
pdebug();
|
||||
}
|
||||
|
||||
void do_sprite_editor() {
|
||||
cls(14);
|
||||
//palt(0, false);
|
||||
rectfill(0, 0, 160, 7, 2);
|
||||
rectfill(0, 115, 160, 119, 2);
|
||||
sspr(0, 0, 128, 32, 0, 83);
|
||||
sspr(0, 0, 8, 8, 8, 16, 64, 64);
|
||||
rect(8, 16, 72, 80, 0);
|
||||
spr(17, mousex(), mousey());
|
||||
if (mbtn(1) && mousex()>=8 && mousey()>=8 && mousex()<72 && mousey()<72) {
|
||||
sset((mousex()-8)/8, (mousey()-16)/8);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (btnp(KEY_TAB)) {
|
||||
current_editor = (++current_editor)%5;
|
||||
}
|
||||
switch(current_editor) {
|
||||
case 0:
|
||||
do_terminal();
|
||||
break;
|
||||
case 1:
|
||||
do_sprite_editor();
|
||||
break;
|
||||
}
|
||||
settrans(255);
|
||||
setcolor(0,0xff0000);
|
||||
const int w=scrw();
|
||||
const int h=scrh();
|
||||
rect(0,0,w-1,h-1,0);
|
||||
}
|
||||
213
mini.cpp
213
mini.cpp
@@ -43,14 +43,13 @@ namespace ds {
|
||||
int cam[2] = {0, 0};
|
||||
int clip[4] = {0, 0, screen_width, screen_height};
|
||||
int clp[4] = {0, 0, screen_width-1, screen_height-1};
|
||||
//uint8_t draw_palette[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
//uint8_t screen_palette[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
uint8_t trans = 0;
|
||||
uint16_t fill_pattern = 0b1111111111111111;
|
||||
bool fill_trans = false;
|
||||
}
|
||||
|
||||
bool should_exit = false;
|
||||
bool should_quit = false;
|
||||
SDL_Window *mini_win;
|
||||
SDL_Renderer *mini_ren;
|
||||
SDL_Texture *mini_bak;
|
||||
@@ -70,12 +69,6 @@ uint16_t font[96];
|
||||
char base64glyphs[193] = "/h/AqV/hhhh/GMYYMGz/t/eS33H477wsjjswY4IOPHEFFVVVAVAVAVIc+dJHMMM/h/qBgBgVqq+//eIUi/dJzhAAhzAAA/eM"
|
||||
"AMShAAAQsjAAAwsjAAAeSzAAAcU3AAAEqRAAABVaiAAMezhAAAAAMAADH4wAASb2SAAMAttAQYcefACGOe+AAAVVAAAAbbAA";
|
||||
|
||||
int debug_line_size = (screen_width/4);
|
||||
int debug_num_lines = (screen_height/6);
|
||||
int debug_total_size = debug_line_size*debug_num_lines;
|
||||
char *debug_text = NULL;
|
||||
int debug_cursor = 0;
|
||||
|
||||
//Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X };
|
||||
const Uint8 *keys;
|
||||
Uint8 key_just_pressed = 0;
|
||||
@@ -118,8 +111,6 @@ void reinit() {
|
||||
ds::cam[0] = ds::cam[1] = 0;
|
||||
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width; ds::clip[3] = screen_height;
|
||||
ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width-1; ds::clp[3] = screen_height-1;
|
||||
//for(int i=0;i<16;++i)ds::draw_palette[i]=i;
|
||||
//for(int i=0;i<16;++i)ds::screen_palette[i]=i;
|
||||
ds::trans=0;
|
||||
ds::fill_pattern = 0b1111111111111111;
|
||||
ds::fill_trans = false;
|
||||
@@ -142,6 +133,14 @@ void quitaudio() {
|
||||
JA_Quit();
|
||||
}
|
||||
|
||||
int scrw() {
|
||||
return screen_width;
|
||||
}
|
||||
|
||||
int scrh() {
|
||||
return screen_height;
|
||||
}
|
||||
|
||||
uint8_t newsurf(int w, int h) {
|
||||
int i = 0;
|
||||
while (i<10 && surfaces[i].p != NULL) ++i;
|
||||
@@ -164,20 +163,6 @@ uint8_t loadsurf(const char* filename) {
|
||||
surfaces[i].size = surfaces[i].w*surfaces[i].h;
|
||||
free(buffer);
|
||||
|
||||
/*
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if (f) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
long size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
uint8_t *buffer = (uint8_t*)malloc(size);
|
||||
fread(buffer, size, 1, f);
|
||||
fclose(f);
|
||||
surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h);
|
||||
surfaces[i].size = surfaces[i].w*surfaces[i].h;
|
||||
free(buffer);
|
||||
}
|
||||
*/
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -199,100 +184,93 @@ void setmap(uint8_t surface) {
|
||||
}
|
||||
|
||||
int main(int argc,char*argv[]){
|
||||
int bi = 0;
|
||||
for (int ci=0; ci<96; ci+=2) {
|
||||
font[ci] = base64font[bi]-48+((base64font[bi+1]-48)<<6)+((base64font[bi+2]-48&7)<<12);
|
||||
font[ci+1] = ((base64font[bi+2]-48)>>3)+((base64font[bi+3]-48)<<3)+((base64font[bi+4]-48)<<9);
|
||||
bi += 5;
|
||||
}
|
||||
|
||||
/*FILE *f = fopen("sprites.bmp", "rb");
|
||||
if (f) {
|
||||
uint8_t buffer[SPRITES_SIZE_BYTES/2];
|
||||
fseek(f, 118, SEEK_SET);
|
||||
fread(buffer, SPRITES_SIZE_BYTES/2, 1, f);
|
||||
fclose(f);
|
||||
for (int y=0; y<SPRITES_HEIGHT; ++y) {
|
||||
for (int x=0; x<(SPRITES_WIDTH/2); ++x) {
|
||||
SPRITES(x*2, SPRITES_WIDTH-1-y) = buffer[x+y*(SPRITES_WIDTH/2)] >> 4;
|
||||
SPRITES(x*2+1, SPRITES_WIDTH-1-y) = buffer[x+y*(SPRITES_WIDTH/2)] & 0xf;
|
||||
}
|
||||
while (!should_quit) {
|
||||
should_exit=false;
|
||||
|
||||
// initfont()
|
||||
int bi = 0;
|
||||
for (int ci=0; ci<96; ci+=2) {
|
||||
font[ci] = base64font[bi]-48+((base64font[bi+1]-48)<<6)+((base64font[bi+2]-48&7)<<12);
|
||||
font[ci+1] = ((base64font[bi+2]-48)>>3)+((base64font[bi+3]-48)<<3)+((base64font[bi+4]-48)<<9);
|
||||
bi += 5;
|
||||
}
|
||||
}*/
|
||||
|
||||
read_ini();
|
||||
setdest(newsurf(screen_width, screen_height));
|
||||
read_ini();
|
||||
setdest(newsurf(screen_width, screen_height));
|
||||
|
||||
debug_line_size = (screen_width/4);
|
||||
debug_num_lines = (screen_height/6);
|
||||
debug_total_size = debug_line_size*debug_num_lines;
|
||||
if (debug_text != NULL) free(debug_text);
|
||||
debug_text = (char*)malloc(debug_total_size);
|
||||
for (int i=0; i<debug_total_size;++i) debug_text[i] = 32;
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width*screen_zoom, screen_height*screen_zoom, 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, screen_width, screen_height);
|
||||
SDL_ShowCursor(show_cursor);
|
||||
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||
|
||||
SDL_Init(49);
|
||||
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width*screen_zoom, screen_height*screen_zoom, 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, screen_width, screen_height);
|
||||
SDL_ShowCursor(show_cursor);
|
||||
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||
SDL_Event mini_eve;
|
||||
|
||||
SDL_Event mini_eve;
|
||||
reinit();
|
||||
initaudio();
|
||||
debug("MINI SYSTEM BOOTING...");
|
||||
lua_init(lua_files);
|
||||
lua_call_init();
|
||||
|
||||
reinit();
|
||||
initaudio();
|
||||
debug("MINI SYSTEM BOOTING...");
|
||||
lua_init(lua_files);
|
||||
lua_call_init();
|
||||
|
||||
while(!should_exit) {
|
||||
key_just_pressed = 0;
|
||||
mouse_wheel = 0;
|
||||
while(SDL_PollEvent(&mini_eve)) {
|
||||
if (mini_eve.type == SDL_QUIT) { should_exit=true; break; }
|
||||
if (mini_eve.type == SDL_KEYDOWN) {
|
||||
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
|
||||
if (lua_is_playing()) {
|
||||
lua_quit();
|
||||
quitaudio();
|
||||
reinit();
|
||||
while(!should_exit) {
|
||||
key_just_pressed = 0;
|
||||
mouse_wheel = 0;
|
||||
while(SDL_PollEvent(&mini_eve)) {
|
||||
if (mini_eve.type == SDL_QUIT) { should_exit=true; should_quit=true; break; }
|
||||
if (mini_eve.type == SDL_KEYDOWN) {
|
||||
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
|
||||
if (lua_is_playing()) {
|
||||
lua_quit();
|
||||
quitaudio();
|
||||
reinit();
|
||||
} else {
|
||||
should_exit=true;
|
||||
//initaudio();
|
||||
//lua_init(lua_files);
|
||||
//lua_call_init();
|
||||
}
|
||||
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F5) {
|
||||
should_exit=true;
|
||||
//lua_quit();
|
||||
//reinit();
|
||||
//initaudio();
|
||||
//lua_init(lua_files);
|
||||
//lua_call_init();
|
||||
} else {
|
||||
initaudio();
|
||||
lua_init(lua_files);
|
||||
lua_call_init();
|
||||
key_just_pressed = mini_eve.key.keysym.scancode;
|
||||
}
|
||||
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F5) {
|
||||
lua_quit();
|
||||
reinit();
|
||||
initaudio();
|
||||
lua_init(lua_files);
|
||||
lua_call_init();
|
||||
} else {
|
||||
key_just_pressed = mini_eve.key.keysym.scancode;
|
||||
}
|
||||
if (mini_eve.type == SDL_MOUSEWHEEL) {
|
||||
mouse_wheel = mini_eve.wheel.y;
|
||||
}
|
||||
}
|
||||
if (mini_eve.type == SDL_MOUSEWHEEL) {
|
||||
mouse_wheel = mini_eve.wheel.y;
|
||||
}
|
||||
}
|
||||
keys = SDL_GetKeyboardState(NULL);
|
||||
mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
mouse_x /= screen_zoom; mouse_y /= screen_zoom;
|
||||
keys = SDL_GetKeyboardState(NULL);
|
||||
mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
mouse_x /= screen_zoom; mouse_y /= screen_zoom;
|
||||
|
||||
if (lua_is_playing()) {
|
||||
lua_call_update();
|
||||
} else {
|
||||
loop();
|
||||
if (lua_is_playing()) {
|
||||
lua_call_update();
|
||||
} else {
|
||||
loop();
|
||||
}
|
||||
SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch);
|
||||
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_RenderPresent(mini_ren);
|
||||
}
|
||||
SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch);
|
||||
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_RenderPresent(mini_ren);
|
||||
lua_quit();
|
||||
quitaudio();
|
||||
for (int i=0;i<10;++i) freesurf(i);
|
||||
SDL_DestroyTexture(mini_bak);
|
||||
SDL_DestroyRenderer(mini_ren);
|
||||
SDL_DestroyWindow(mini_win);
|
||||
SDL_Quit();
|
||||
}
|
||||
lua_quit();
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -926,39 +904,14 @@ const char* tostr(int val) {
|
||||
return SDL_itoa(val, tostr_tmp, 10);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void debug(const char *str) {
|
||||
const int len = SDL_strlen(str);
|
||||
for (int i=0; i<len;++i) {
|
||||
debug_text[debug_cursor++] = str[i];
|
||||
if (debug_cursor >= debug_total_size) debug_one_line_up();
|
||||
}
|
||||
debug_cursor = (int(debug_cursor/debug_line_size)+1)*debug_line_size;
|
||||
if (debug_cursor >= debug_total_size) debug_one_line_up();
|
||||
}
|
||||
|
||||
void pdebug() {
|
||||
palette[0]=0x00000000;
|
||||
palette[1]=0x0000ff00;
|
||||
color(1);
|
||||
int i=0;
|
||||
for (int y=0; y<debug_num_lines;++y) {
|
||||
for (int x=0; x<debug_line_size;++x) {
|
||||
print_char(debug_text[i++], x*4, y*6);
|
||||
}
|
||||
}
|
||||
printf("%s\n",str);
|
||||
}
|
||||
|
||||
uint8_t ascii(const char *str, uint8_t index) {
|
||||
return str[index];
|
||||
}
|
||||
|
||||
|
||||
char fstr[255];
|
||||
|
||||
void fopen(const char *filename, uint8_t mode) {
|
||||
|
||||
4
mini.h
4
mini.h
@@ -112,6 +112,9 @@
|
||||
|
||||
void loop();
|
||||
|
||||
int scrw();
|
||||
int scrh();
|
||||
|
||||
uint8_t newsurf(int w, int h);
|
||||
uint8_t loadsurf(const char* filename);
|
||||
void freesurf(uint8_t surface);
|
||||
@@ -230,7 +233,6 @@ int rnd(int x);
|
||||
const char* tostr(int val);
|
||||
|
||||
void debug(const char *str);
|
||||
void pdebug();
|
||||
|
||||
uint8_t ascii(const char *str, uint8_t index);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user