diff --git a/ascii.cpp b/ascii.cpp index 3cacda2..165d26c 100644 --- a/ascii.cpp +++ b/ascii.cpp @@ -246,6 +246,12 @@ int main(int argc,char*argv[]) { void cls(uint8_t value) { SDL_memset(char_screen, value, 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] = '>'; + } } void ink(uint8_t value) { @@ -371,7 +377,7 @@ int rnd(int x) { }*/ char tostr_tmp[256]; -const char* tostr(int val) { +const char* tostr(float val) { return SDL_itoa(val, tostr_tmp, 10); } @@ -484,4 +490,16 @@ void setmode(const uint8_t mode) { void load(const char* str) { SDL_strlcpy(lua_filename, str, SDL_strlen(str)+1); should_reset = true; -} \ No newline at end of file +} + +void fileout(const char* str, uint16_t addr, uint16_t size) { + FILE* f = fopen(str, "wb"); + fwrite(&mem[addr], size, 1, f); + fclose(f); +} + +void filein(const char* str, uint16_t addr, uint16_t size) { + FILE* f = fopen(str, "rb"); + fread(&mem[addr], size, 1, f); + fclose(f); +} diff --git a/ascii.h b/ascii.h index 0173705..93e5add 100644 --- a/ascii.h +++ b/ascii.h @@ -153,7 +153,7 @@ float min(float x, float y); int rnd(int x); //void srand(int x); -const char* tostr(int val); +const char* tostr(float val); void debugchr(const uint8_t chr); void debug(const char *str); @@ -172,3 +172,6 @@ void nosound(); void setmode(const uint8_t mode); void load(const char* str); + +void fileout(const char* str, uint16_t addr, uint16_t size); +void filein(const char* str, uint16_t addr, uint16_t size); diff --git a/lua.cpp b/lua.cpp index d59da84..e52d9b6 100644 --- a/lua.cpp +++ b/lua.cpp @@ -152,7 +152,7 @@ extern "C" { return 0; } static int cpp_tostr(lua_State *L) { - int val = luaL_checknumber(L, 1); + float val = luaL_checknumber(L, 1); lua_pushstring(L, tostr(val)); return 1; } @@ -223,6 +223,28 @@ extern "C" { load(str); return 0; } + + static int cpp_log(lua_State *L) { + const char* str = luaL_checkstring(L, 1); + debug(str); + return 0; + } + + static int cpp_fileout(lua_State *L) { + const char* str = luaL_checkstring(L, 1); + const uint16_t addr = luaL_checknumber(L, 2); + const uint16_t size = luaL_checknumber(L, 3); + fileout(str, addr, size); + return 0; + } + + static int cpp_filein(lua_State *L) { + const char* str = luaL_checkstring(L, 1); + const uint16_t addr = luaL_checknumber(L, 2); + const uint16_t size = luaL_checknumber(L, 3); + filein(str, addr, size); + return 0; + } } #define STATE_STOPPED 0 @@ -294,6 +316,10 @@ void lua_init(const char* filename, const bool start_playing) { lua_pushcfunction(L,cpp_nosound); lua_setglobal(L, "nosound"); lua_pushcfunction(L,cpp_setmode); lua_setglobal(L, "setmode"); lua_pushcfunction(L,cpp_load); lua_setglobal(L, "load"); + lua_pushcfunction(L,cpp_log); lua_setglobal(L, "log"); + + lua_pushcfunction(L,cpp_fileout); lua_setglobal(L, "fileout"); + lua_pushcfunction(L,cpp_filein); lua_setglobal(L, "filein"); lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN"); lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A"); diff --git a/main.cpp b/main.cpp index 9e76b4d..36f600d 100644 --- a/main.cpp +++ b/main.cpp @@ -33,7 +33,7 @@ void do_terminal() { else if (key == KEY_PERIOD) { if (mods & KMOD_SHIFT) { debugchr(':'); } else { debugchr('.'); } } else if (key == KEY_SLASH) { if (mods & KMOD_SHIFT) { debugchr('_'); } else { debugchr('-'); } } } - cls(0); + //cls(0); pdebug(); } diff --git a/mapedit.lua b/mapedit.lua index cd64289..ec9f54c 100644 --- a/mapedit.lua +++ b/mapedit.lua @@ -2,23 +2,90 @@ ind = 22 function init() setmode(2) map = {} + col = {} for i=0,299 do map[i] = 32 + col[i] = 0x0f end map[ind] = 65 + sel_col = 0x0f + sel_chr = 65 end +blink=30 + function update() if btn(KEY_TAB) then - for i=0,255 do - poke(i, i) - poke(300+i, 0x0f) - end - local mx, my = mousex(), mousey() - poke(300+(mx+my*20), 0x4e) + draw_picker() + update_picker() else - for i=0,299 do - poke(i, map[i]) + draw_map() + --update_map() + end +end + +function draw_picker() + for i=0,255 do + poke(i, i) + poke(300+i, sel_col) + end + for i=0,15 do + poke(580+i, i<<4) + poke(560+i, i<<4) + poke(280+i, 32) + poke(260+i, 32) + end + poke(580, 15) poke(560, 15) + poke(260+(sel_col&0xf), 203) + poke(280+(sel_col>>4), 203) + local mx, my = mousex(), mousey() + + if my<13 then + poke(300+(mx+my*20), 0x4e) + print(mx+my*20, 16, 13) + elseif my>=13 then + poke(mx+my*20, 144) + end +end + +function update_picker() + local mx, my = mousex(), mousey() + if mousebutton(1) then + if my<13 then + sel_chr = mx+my*20 + else + if mx < 16 then + if my == 13 then + sel_col = (sel_col & 0xf0) + mx + else + sel_col = (sel_col & 0x0f) + (mx << 4) + end + end end end end + +function draw_map() + for i=0,299 do + poke(i, map[i]) + poke(300+i, col[i]) + end + + local mx, my = mousex(), mousey() + if mousebutton(1) then + map[mx+my*20] = sel_chr + col[mx+my*20] = sel_col + end + if btn(KEY_SPACE) then + sel_chr = peek(mx+my*20) + sel_col = peek(300+mx+my*20) + end + + blink = blink - 1 + if blink < 30 then + if blink==0 then blink = 60 end + local mx, my = mousex(), mousey() + local c = peek(300+(mx+my*20)) + poke(300+(mx+my*20), c~0xff) + end +end diff --git a/scr_min.bin b/scr_min.bin new file mode 100644 index 0000000..3524d6c --- /dev/null +++ b/scr_min.bin @@ -0,0 +1 @@ + ֏֏֏֏֏ ԏԏ ԏԏ ԏ ԏ ֏ԏԏ ԏԏԏԏԏ xxxxxxxxxxxxxxxx   \ No newline at end of file diff --git a/scredit.lua b/scredit.lua new file mode 100644 index 0000000..6161af7 --- /dev/null +++ b/scredit.lua @@ -0,0 +1,106 @@ +ind = 22 +function init() + setmode(1) + map = {} + col = {} + for i=0,1199 do + map[i] = 32 + col[i] = 0x0f + end + map[ind] = 65 + sel_col = 0x0f + sel_chr = 65 +end + +blink=30 + +function update() + if btn(KEY_TAB) then + draw_picker() + update_picker() + else + draw_map() + --update_map() + end +end + +function draw_picker() + for y=0,15 do + for x=0,15 do + poke(x+y*40, x+y*16) + poke(1200+x+y*40, sel_col) + end + end + for i=0,15 do + poke(1840+i, i<<4) + poke(1880+i, i<<4) + poke(640+i, 32) + poke(680+i, 32) + end + poke(1840, 15) poke(1880, 15) + poke(640+(sel_col&0xf), 203) + poke(680+(sel_col>>4), 203) + local mx, my = mousex(), mousey() + + if mx<16 then + if my<16 then + poke(1200+(mx+my*40), 0x4e) + print(mx+my*40, 16, 13) + elseif my>=16 then + poke(mx+my*40, 144) + end + end +end + +function update_picker() + local mx, my = mousex(), mousey() + if mousebutton(1) then + if mx<16 then + if my<16 then + sel_chr = mx+my*16 + else + if my == 16 then + sel_col = (sel_col & 0xf0) + mx + elseif my == 17 then + sel_col = (sel_col & 0x0f) + (mx << 4) + end + end + end + end +end + +function draw_map() + for i=0,1199 do + poke(i, map[i]) + poke(1200+i, col[i]) + end + + local mx, my = mousex(), mousey() + if mousebutton(1) then + map[mx+my*40] = sel_chr + col[mx+my*40] = sel_col + end + if btn(KEY_SPACE) then + sel_chr = peek(mx+my*40) + sel_col = peek(1200+mx+my*40) + end + + blink = blink - 1 + if blink < 30 then + if blink==0 then blink = 60 end + local mx, my = mousex(), mousey() + local c = peek(1200+(mx+my*40)) + poke(1200+(mx+my*40), c~0xff) + end + + if btn(KEY_S) then + fileout("scr.bin", 0, 2400); + elseif btn(KEY_L) then + filein("scr.bin", 0, 2400); + for i=0,1199 do + map[i] = peek(i) + col[i] = peek(1200+i) + end + + end +end