- 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;
|
int size;
|
||||||
char* buffer = file_getfilebuffer(file_start, size);
|
char* buffer = file_getfilebuffer(file_start, size);
|
||||||
if (luaL_loadbuffer(L, buffer, size, file_start)) {
|
if (luaL_loadbuffer(L, buffer, size, file_start)) {
|
||||||
debug("error loading game");
|
debug("LOADING ERROR:");
|
||||||
debug(lua_tostring(L, -1));
|
debug(lua_tostring(L, -1));
|
||||||
lua_pop(L,1);
|
lua_pop(L,1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
if (lua_pcall(L,0, LUA_MULTRET, 0)) {
|
if (lua_pcall(L,0, LUA_MULTRET, 0)) {
|
||||||
debug("runtime error");
|
debug("RUNTIME ERROR:");
|
||||||
debug(lua_tostring(L, -1));
|
debug(lua_tostring(L, -1));
|
||||||
lua_pop(L,1);
|
lua_pop(L,1);
|
||||||
return;
|
return;
|
||||||
@@ -945,7 +945,7 @@ void lua_call_init() {
|
|||||||
if (!init_exists) return;
|
if (!init_exists) return;
|
||||||
lua_getglobal(L, "_init");
|
lua_getglobal(L, "_init");
|
||||||
if (lua_pcall(L, 0, 0, 0)) {
|
if (lua_pcall(L, 0, 0, 0)) {
|
||||||
debug("runtime error");
|
debug("RUNTIME ERROR:");
|
||||||
debug(lua_tostring(L, -1));
|
debug(lua_tostring(L, -1));
|
||||||
lua_pop(L,1);
|
lua_pop(L,1);
|
||||||
is_playing = false;
|
is_playing = false;
|
||||||
@@ -956,7 +956,7 @@ void lua_call_update() {
|
|||||||
if (!update_exists) return;
|
if (!update_exists) return;
|
||||||
lua_getglobal(L, "_update");
|
lua_getglobal(L, "_update");
|
||||||
if (lua_pcall(L, 0, 0, 0)) {
|
if (lua_pcall(L, 0, 0, 0)) {
|
||||||
debug("runtime error");
|
debug("RUNTIME ERROR:");
|
||||||
debug(lua_tostring(L, -1));
|
debug(lua_tostring(L, -1));
|
||||||
lua_pop(L,1);
|
lua_pop(L,1);
|
||||||
is_playing = false;
|
is_playing = false;
|
||||||
|
|||||||
37
main.cpp
37
main.cpp
@@ -1,36 +1,9 @@
|
|||||||
#include "mini.h"
|
#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() {
|
void loop() {
|
||||||
if (btnp(KEY_TAB)) {
|
settrans(255);
|
||||||
current_editor = (++current_editor)%5;
|
setcolor(0,0xff0000);
|
||||||
}
|
const int w=scrw();
|
||||||
switch(current_editor) {
|
const int h=scrh();
|
||||||
case 0:
|
rect(0,0,w-1,h-1,0);
|
||||||
do_terminal();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
do_sprite_editor();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
115
mini.cpp
115
mini.cpp
@@ -43,14 +43,13 @@ namespace ds {
|
|||||||
int cam[2] = {0, 0};
|
int cam[2] = {0, 0};
|
||||||
int clip[4] = {0, 0, screen_width, screen_height};
|
int clip[4] = {0, 0, screen_width, screen_height};
|
||||||
int clp[4] = {0, 0, screen_width-1, screen_height-1};
|
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;
|
uint8_t trans = 0;
|
||||||
uint16_t fill_pattern = 0b1111111111111111;
|
uint16_t fill_pattern = 0b1111111111111111;
|
||||||
bool fill_trans = false;
|
bool fill_trans = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool should_exit = false;
|
bool should_exit = false;
|
||||||
|
bool should_quit = false;
|
||||||
SDL_Window *mini_win;
|
SDL_Window *mini_win;
|
||||||
SDL_Renderer *mini_ren;
|
SDL_Renderer *mini_ren;
|
||||||
SDL_Texture *mini_bak;
|
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"
|
char base64glyphs[193] = "/h/AqV/hhhh/GMYYMGz/t/eS33H477wsjjswY4IOPHEFFVVVAVAVAVIc+dJHMMM/h/qBgBgVqq+//eIUi/dJzhAAhzAAA/eM"
|
||||||
"AMShAAAQsjAAAwsjAAAeSzAAAcU3AAAEqRAAABVaiAAMezhAAAAAMAADH4wAASb2SAAMAttAQYcefACGOe+AAAVVAAAAbbAA";
|
"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 };
|
//Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X };
|
||||||
const Uint8 *keys;
|
const Uint8 *keys;
|
||||||
Uint8 key_just_pressed = 0;
|
Uint8 key_just_pressed = 0;
|
||||||
@@ -118,8 +111,6 @@ void reinit() {
|
|||||||
ds::cam[0] = ds::cam[1] = 0;
|
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::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;
|
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::trans=0;
|
||||||
ds::fill_pattern = 0b1111111111111111;
|
ds::fill_pattern = 0b1111111111111111;
|
||||||
ds::fill_trans = false;
|
ds::fill_trans = false;
|
||||||
@@ -142,6 +133,14 @@ void quitaudio() {
|
|||||||
JA_Quit();
|
JA_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int scrw() {
|
||||||
|
return screen_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
int scrh() {
|
||||||
|
return screen_height;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t newsurf(int w, int h) {
|
uint8_t newsurf(int w, int h) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i<10 && surfaces[i].p != NULL) ++i;
|
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;
|
surfaces[i].size = surfaces[i].w*surfaces[i].h;
|
||||||
free(buffer);
|
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;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,6 +184,11 @@ void setmap(uint8_t surface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char*argv[]){
|
int main(int argc,char*argv[]){
|
||||||
|
|
||||||
|
while (!should_quit) {
|
||||||
|
should_exit=false;
|
||||||
|
|
||||||
|
// initfont()
|
||||||
int bi = 0;
|
int bi = 0;
|
||||||
for (int ci=0; ci<96; ci+=2) {
|
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] = base64font[bi]-48+((base64font[bi+1]-48)<<6)+((base64font[bi+2]-48&7)<<12);
|
||||||
@@ -206,31 +196,10 @@ int main(int argc,char*argv[]){
|
|||||||
bi += 5;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
read_ini();
|
read_ini();
|
||||||
setdest(newsurf(screen_width, screen_height));
|
setdest(newsurf(screen_width, screen_height));
|
||||||
|
|
||||||
debug_line_size = (screen_width/4);
|
SDL_Init(SDL_INIT_EVERYTHING);
|
||||||
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(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_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);
|
mini_ren = SDL_CreateRenderer(mini_win, -1, SDL_RENDERER_PRESENTVSYNC);
|
||||||
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
|
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
|
||||||
@@ -250,7 +219,7 @@ int main(int argc,char*argv[]){
|
|||||||
key_just_pressed = 0;
|
key_just_pressed = 0;
|
||||||
mouse_wheel = 0;
|
mouse_wheel = 0;
|
||||||
while(SDL_PollEvent(&mini_eve)) {
|
while(SDL_PollEvent(&mini_eve)) {
|
||||||
if (mini_eve.type == SDL_QUIT) { should_exit=true; break; }
|
if (mini_eve.type == SDL_QUIT) { should_exit=true; should_quit=true; break; }
|
||||||
if (mini_eve.type == SDL_KEYDOWN) {
|
if (mini_eve.type == SDL_KEYDOWN) {
|
||||||
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
|
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
|
||||||
if (lua_is_playing()) {
|
if (lua_is_playing()) {
|
||||||
@@ -258,16 +227,18 @@ int main(int argc,char*argv[]){
|
|||||||
quitaudio();
|
quitaudio();
|
||||||
reinit();
|
reinit();
|
||||||
} else {
|
} else {
|
||||||
initaudio();
|
should_exit=true;
|
||||||
lua_init(lua_files);
|
//initaudio();
|
||||||
lua_call_init();
|
//lua_init(lua_files);
|
||||||
|
//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();
|
should_exit=true;
|
||||||
reinit();
|
//lua_quit();
|
||||||
initaudio();
|
//reinit();
|
||||||
lua_init(lua_files);
|
//initaudio();
|
||||||
lua_call_init();
|
//lua_init(lua_files);
|
||||||
|
//lua_call_init();
|
||||||
} else {
|
} else {
|
||||||
key_just_pressed = mini_eve.key.keysym.scancode;
|
key_just_pressed = mini_eve.key.keysym.scancode;
|
||||||
}
|
}
|
||||||
@@ -292,7 +263,14 @@ int main(int argc,char*argv[]){
|
|||||||
SDL_RenderPresent(mini_ren);
|
SDL_RenderPresent(mini_ren);
|
||||||
}
|
}
|
||||||
lua_quit();
|
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();
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -926,39 +904,14 @@ const char* tostr(int val) {
|
|||||||
return SDL_itoa(val, tostr_tmp, 10);
|
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) {
|
void debug(const char *str) {
|
||||||
const int len = SDL_strlen(str);
|
printf("%s\n",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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ascii(const char *str, uint8_t index) {
|
uint8_t ascii(const char *str, uint8_t index) {
|
||||||
return str[index];
|
return str[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char fstr[255];
|
char fstr[255];
|
||||||
|
|
||||||
void fopen(const char *filename, uint8_t mode) {
|
void fopen(const char *filename, uint8_t mode) {
|
||||||
|
|||||||
4
mini.h
4
mini.h
@@ -112,6 +112,9 @@
|
|||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
|
int scrw();
|
||||||
|
int scrh();
|
||||||
|
|
||||||
uint8_t newsurf(int w, int h);
|
uint8_t newsurf(int w, int h);
|
||||||
uint8_t loadsurf(const char* filename);
|
uint8_t loadsurf(const char* filename);
|
||||||
void freesurf(uint8_t surface);
|
void freesurf(uint8_t surface);
|
||||||
@@ -230,7 +233,6 @@ int rnd(int x);
|
|||||||
const char* tostr(int val);
|
const char* tostr(int val);
|
||||||
|
|
||||||
void debug(const char *str);
|
void debug(const char *str);
|
||||||
void pdebug();
|
|
||||||
|
|
||||||
uint8_t ascii(const char *str, uint8_t index);
|
uint8_t ascii(const char *str, uint8_t index);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user