Compare commits
21 Commits
0421f7f154
...
v0.6.0
| Author | SHA1 | Date | |
|---|---|---|---|
| a349cf5c0c | |||
| f889faa472 | |||
| 743fd2b8cc | |||
| 841f4f66f3 | |||
| 82bebe3eeb | |||
| c52687f0eb | |||
| 97daca8097 | |||
| 64bcedd82f | |||
| fe9f4fed9c | |||
| 56f2e202e8 | |||
| 9b1573be9d | |||
| 11bb1b5283 | |||
| acfaf873ce | |||
| be083a23e2 | |||
| 63ca77e3e6 | |||
| 3979588f85 | |||
| 1618665124 | |||
| 527ab8bf01 | |||
| 62c513db56 | |||
| e5798f4b71 | |||
| 788c5d6c6e |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,3 +3,6 @@ ascii
|
||||
.vscode/*
|
||||
*.dll
|
||||
wiki/*
|
||||
scr_min.c
|
||||
tests.lua
|
||||
fake_editor.lua
|
||||
|
||||
246
ascii.cpp
246
ascii.cpp
@@ -5,6 +5,9 @@
|
||||
#include "rom.c"
|
||||
#include "play.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#define swap(a, b) {auto tmp=a;a=b;b=tmp;}
|
||||
|
||||
#define AUDIO_NONE 0
|
||||
@@ -18,6 +21,10 @@ uint8_t *char_screen = NULL;
|
||||
uint8_t *color_screen = NULL;
|
||||
uint8_t screen_width = 40;
|
||||
uint8_t screen_height = 30;
|
||||
int v_screen_w = 640;
|
||||
int v_screen_h = 480;
|
||||
uint8_t hborder = 40;
|
||||
uint8_t vborder = 40;
|
||||
uint8_t current_color = 0x1e;
|
||||
uint8_t current_border = 0;
|
||||
uint8_t current_mode = 1;
|
||||
@@ -39,28 +46,31 @@ SDL_Texture *mini_bak = NULL;
|
||||
SDL_AudioDeviceID mini_audio_device;
|
||||
Uint32 *pixels;
|
||||
int pitch;
|
||||
Uint32 counter=0;
|
||||
|
||||
uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0000, 0x00AA00AA, 0x00AA5500, 0x00AAAAAA,
|
||||
0x00555555, 0x005555FF, 0x0055FF55, 0x0055FFFF, 0x00FF5555, 0x00FF55FF, 0x00FFFF55, 0x00FFFFFF };
|
||||
|
||||
#define debug_line_size 80
|
||||
#define debug_num_lines 30
|
||||
#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_prompt = -1;
|
||||
int debug_cursor_blink = 30;
|
||||
std::vector<std::string> cmd_list;
|
||||
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 };
|
||||
const Uint8 *keys;
|
||||
Uint8 key_just_pressed = 0;
|
||||
|
||||
int mouse_x, mouse_y, mouse_wheel;
|
||||
Uint32 mouse_buttons;
|
||||
|
||||
const char* get_filename() {
|
||||
return lua_filename;
|
||||
}
|
||||
|
||||
void reinit() {
|
||||
if (mini_bak != NULL) SDL_DestroyTexture(mini_bak);
|
||||
counter=0;
|
||||
hborder = vborder = 40;
|
||||
v_screen_w = 640; v_screen_h = 480;
|
||||
switch (current_mode) {
|
||||
case 0:
|
||||
screen_width = 80;
|
||||
@@ -98,6 +108,22 @@ void reinit() {
|
||||
//SDL_RenderSetLogicalSize(mini_ren, 160, 120);
|
||||
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 160, 120);
|
||||
break;
|
||||
case 3:
|
||||
hborder = 104;
|
||||
vborder = 88;
|
||||
v_screen_w = 512;
|
||||
v_screen_h = 384;
|
||||
screen_width = 32;
|
||||
screen_height = 24;
|
||||
current_color = 0x07;
|
||||
current_border = 0;
|
||||
cursor_x = 0;
|
||||
cursor_y = 0;
|
||||
char_screen = &mem[0];
|
||||
color_screen = &mem[1200];
|
||||
//SDL_RenderSetLogicalSize(mini_ren, 640, 480);
|
||||
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 256, 192);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,11 +171,13 @@ void romcpy() {
|
||||
SDL_memcpy(&mem[2560], rom, rom_size);
|
||||
}
|
||||
|
||||
void debug_set_prompt();
|
||||
|
||||
int main(int argc,char*argv[]) {
|
||||
SDL_strlcpy(lua_filename, "game.lua", 9);
|
||||
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);
|
||||
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640+80, 480+80, SDL_WINDOW_SHOWN);
|
||||
@@ -173,7 +201,7 @@ int main(int argc,char*argv[]) {
|
||||
while(!exit) {
|
||||
if (should_reset) {
|
||||
should_reset = false;
|
||||
setmode(1);
|
||||
mode(1);
|
||||
reinit();
|
||||
lua_init(lua_filename);
|
||||
lua_call_init();
|
||||
@@ -187,15 +215,19 @@ int main(int argc,char*argv[]) {
|
||||
if (lua_is_playing()) {
|
||||
lua_pause();
|
||||
//lua_quit();
|
||||
old_mode = current_mode;
|
||||
setmode(0);
|
||||
debug_set_prompt();
|
||||
//old_mode = current_mode;
|
||||
//setmode(0);
|
||||
} else {
|
||||
setmode(old_mode);
|
||||
//setmode(old_mode);
|
||||
lua_resume();
|
||||
//lua_init();
|
||||
//lua_quit();
|
||||
//reinit();
|
||||
//lua_init(lua_filename);
|
||||
//lua_call_init();
|
||||
}
|
||||
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F5) {
|
||||
execute_run();
|
||||
lua_quit();
|
||||
reinit();
|
||||
lua_init(lua_filename);
|
||||
@@ -209,17 +241,22 @@ int main(int argc,char*argv[]) {
|
||||
}
|
||||
}
|
||||
keys = SDL_GetKeyboardState(NULL);
|
||||
mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
mouse_x = (mouse_x-40) / (640/screen_width);
|
||||
mouse_y = (mouse_y-40) / (480/screen_height);
|
||||
int mx, my;
|
||||
mouse_buttons = SDL_GetMouseState(&mx, &my);
|
||||
if (mx>=hborder && my>=vborder && mx<(v_screen_w+hborder) && my<(v_screen_h+vborder)) {
|
||||
mouse_x = (mx-hborder) / (v_screen_w/screen_width);
|
||||
mouse_y = (my-vborder) / (v_screen_h/screen_height);
|
||||
}
|
||||
|
||||
if (lua_is_playing()) {
|
||||
lua_call_update();
|
||||
if (!lua_is_playing()) debug_set_prompt();
|
||||
} else {
|
||||
debug_cursor_blink--;
|
||||
if (debug_cursor_blink == 0) {
|
||||
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();
|
||||
}
|
||||
@@ -248,6 +285,7 @@ int main(int argc,char*argv[]) {
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
for (int y=0; y<screen_height; ++y) {
|
||||
for (int x=0; x<screen_width; ++x) {
|
||||
const uint8_t chr_color = COLSCR(x,y);
|
||||
@@ -275,10 +313,11 @@ int main(int argc,char*argv[]) {
|
||||
SDL_SetRenderDrawColor(mini_ren, (palette[current_border] >> 16)&0xff, (palette[current_border] >> 8)&0xff, palette[current_border]&0xff, 0);
|
||||
//SDL_SetRenderDrawColor(mini_ren, 255, 0, 0, 0);
|
||||
SDL_RenderClear(mini_ren);
|
||||
SDL_Rect rect = {40, 40, 640, 480};
|
||||
SDL_Rect rect = {hborder, vborder, v_screen_w, v_screen_h};
|
||||
SDL_RenderCopy(mini_ren, mini_bak, NULL, &rect);
|
||||
//SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
|
||||
SDL_RenderPresent(mini_ren);
|
||||
counter++;
|
||||
}
|
||||
lua_quit();
|
||||
SDL_Quit();
|
||||
@@ -288,12 +327,10 @@ 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] = '>';
|
||||
}
|
||||
cursor_x = cursor_y = 0;
|
||||
//if (!lua_is_playing()) {
|
||||
// debug_set_prompt()
|
||||
//}
|
||||
}
|
||||
|
||||
void ink(uint8_t value) {
|
||||
@@ -322,15 +359,22 @@ void print(const char *str, int x, int y) {
|
||||
if (x >= 0) cursor_x = min(x, screen_width-1);
|
||||
if (y >= 0) cursor_y = min(y, screen_height-1);
|
||||
int len = SDL_strlen(str);
|
||||
if ((cursor_x+len) > screen_width) len -= ((cursor_x+len) - screen_width);
|
||||
const int pos = cursor_x+cursor_y*screen_width;
|
||||
if (pos+len > screen_width*screen_height) len -= ((pos+len) - screen_width*screen_height);
|
||||
//int offset = x+y*screen_width;
|
||||
for (int i=0; i < len; ++i) {
|
||||
CHRSCR(cursor_x+i, cursor_y) = str[i];
|
||||
if (current_mode != 0) COLSCR(cursor_x+i, cursor_y) = current_color;
|
||||
char_screen[pos+i] = str[i];
|
||||
if (current_mode != 0) color_screen[pos+i] = current_color;
|
||||
//char_screen[offset+i] = str[i];
|
||||
//if (current_mode != 0) color_screen[offset+i] = current_color;
|
||||
}
|
||||
cursor_x += len;
|
||||
cursor_x = (pos+len)%screen_width;
|
||||
cursor_y = (pos+len)/screen_width;
|
||||
}
|
||||
|
||||
void crlf() {
|
||||
cursor_x=0;
|
||||
cursor_y = min(cursor_y+1, screen_height-1);
|
||||
}
|
||||
|
||||
bool btn(uint8_t i) {
|
||||
@@ -423,46 +467,66 @@ int rnd(int x) {
|
||||
srand(x);
|
||||
}*/
|
||||
|
||||
char tostr_tmp[256];
|
||||
char str_tmp[1024];
|
||||
const char* tostr(float val) {
|
||||
return SDL_itoa(val, tostr_tmp, 10);
|
||||
}
|
||||
|
||||
void debug_set_prompt() {
|
||||
debug_prompt = debug_cursor++;
|
||||
debug_text[debug_prompt] = '>';
|
||||
return SDL_itoa(val, str_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;
|
||||
debug_set_prompt();
|
||||
int total = screen_width*screen_height-screen_width;
|
||||
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_set_prompt() {
|
||||
if (debug_prompt == cursor_x+cursor_y*screen_width) return;
|
||||
if (cursor_x>0) { cursor_x=0;cursor_y++;if(cursor_y>=screen_height) debug_one_line_up(); }
|
||||
char_screen[cursor_x+cursor_y*screen_width] = '>';
|
||||
cursor_x++;
|
||||
debug_prompt = cursor_x+cursor_y*screen_width;
|
||||
}
|
||||
|
||||
void debugchr(const uint8_t chr) {
|
||||
int pos = cursor_x+cursor_y*screen_width;
|
||||
if (chr == 8) {
|
||||
if (debug_cursor>(debug_prompt+1)) {
|
||||
debug_text[debug_cursor--] = 32;
|
||||
debug_text[debug_cursor] = 32;
|
||||
if (cursor_x>1) {
|
||||
char_screen[pos++] = 32;
|
||||
char_screen[pos] = 32;
|
||||
cursor_x--;
|
||||
} else {
|
||||
play("c");
|
||||
}
|
||||
} else {
|
||||
debug_text[debug_cursor++] = chr;
|
||||
if (debug_cursor >= debug_total_size) debug_one_line_up();
|
||||
char_screen[pos] = chr;
|
||||
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 bool newline) {
|
||||
const int len = SDL_strlen(str);
|
||||
int cursor = cursor_x+cursor_y*screen_width;
|
||||
for (int i=0; i<len;++i) {
|
||||
debug_text[debug_cursor++] = str[i];
|
||||
if (debug_cursor >= debug_total_size) debug_one_line_up();
|
||||
char_screen[cursor++] = str[i];
|
||||
if (cursor >= screen_width*screen_height) 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();
|
||||
debug_set_prompt();
|
||||
if (newline) {
|
||||
cursor_x = 0;
|
||||
cursor_y = (cursor/screen_width)+1;
|
||||
if (cursor_y >= screen_height) debug_one_line_up();
|
||||
} else {
|
||||
cursor_x = cursor%screen_width;
|
||||
cursor_y = cursor/screen_width;
|
||||
}
|
||||
//debug_set_prompt();
|
||||
}
|
||||
|
||||
/*[TODEL]
|
||||
void pdebug() {
|
||||
int i=0;
|
||||
for (int y=0; y<debug_num_lines;++y) {
|
||||
@@ -472,10 +536,49 @@ void pdebug() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
int cmd_index = 0;
|
||||
void debug_get_cmd() {
|
||||
debug_text[debug_cursor] = 0;
|
||||
lua_call_cmd(&debug_text[debug_prompt+1]);
|
||||
char_screen[cursor_x+cursor_y*screen_width] = 0;
|
||||
//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;
|
||||
const char* cmd = cmd_list[cmd_list.size()-1].c_str();
|
||||
|
||||
if (cmd[0]=='r' && cmd[1]=='u' && cmd[2]=='n' && cmd[3]=='\0') {
|
||||
lua_quit();
|
||||
reinit();
|
||||
lua_init(lua_filename);
|
||||
lua_call_init();
|
||||
} else if (cmd[0]=='c' && cmd[1]=='o' && cmd[2]=='n' && cmd[3]=='t' && cmd[4]=='\0') {
|
||||
lua_resume();
|
||||
} else {
|
||||
lua_call_cmd(cmd);
|
||||
debug_set_prompt();
|
||||
}
|
||||
}
|
||||
|
||||
void get_cmd_by_index() {
|
||||
if (cmd_list.size() == 0) return;
|
||||
const char* cmd = cmd_list[cmd_list.size()-cmd_index-1].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+strlen(cmd);
|
||||
cursor_x = pos%screen_width;
|
||||
cursor_y = pos/screen_width;
|
||||
}
|
||||
void next_cmd() {
|
||||
if (cmd_index < cmd_list.size()-1) cmd_index++; else play("c");
|
||||
get_cmd_by_index();
|
||||
}
|
||||
|
||||
void prev_cmd() {
|
||||
if (cmd_index > 0) cmd_index--; else play("c");
|
||||
get_cmd_by_index();
|
||||
}
|
||||
|
||||
uint8_t ascii(const char *str, uint8_t index) {
|
||||
@@ -489,6 +592,12 @@ const char* chr(uint8_t ascii) {
|
||||
return chr_trans;
|
||||
}
|
||||
|
||||
const char* substr(const char* str, uint8_t start, uint8_t length) {
|
||||
memcpy(str_tmp, &str[start], length);
|
||||
str_tmp[length] = '\0';
|
||||
return str_tmp;
|
||||
}
|
||||
|
||||
void setchar(uint8_t index, uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7) {
|
||||
mem[MEM_CHAR_OFFSET+index*8] = b0;
|
||||
mem[MEM_CHAR_OFFSET+index*8+1] = b1;
|
||||
@@ -536,9 +645,10 @@ void play(const char* str) {
|
||||
audio_state = AUDIO_PLAY;
|
||||
}
|
||||
|
||||
void setmode(const uint8_t mode) {
|
||||
current_mode = mode;
|
||||
void mode(const uint8_t val) {
|
||||
current_mode = val;
|
||||
reinit();
|
||||
cls();
|
||||
}
|
||||
|
||||
void load(const char* str) {
|
||||
@@ -557,3 +667,29 @@ void filein(const char* str, uint16_t addr, uint16_t size) {
|
||||
fread(&mem[addr], size, 1, f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void toclipboard(const char* str) {
|
||||
SDL_SetClipboardText(str);
|
||||
}
|
||||
|
||||
const char* fromclipboard() {
|
||||
char* text = SDL_GetClipboardText();
|
||||
int len = strlen(text);
|
||||
if (len > 1023) {
|
||||
len = 27;
|
||||
SDL_memcpy(str_tmp, "ERROR! CLIPBOARD TOO LARGE", len);
|
||||
} else {
|
||||
SDL_memcpy(str_tmp, text, len);
|
||||
}
|
||||
str_tmp[len] = '\0';
|
||||
SDL_free((void*)text);
|
||||
|
||||
return str_tmp;
|
||||
}
|
||||
|
||||
uint32_t cnt() {
|
||||
return counter;
|
||||
}
|
||||
void rst() {
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
36
ascii.h
36
ascii.h
@@ -110,7 +110,27 @@
|
||||
#define KEY_RALT 230
|
||||
#define KEY_RGUI 231
|
||||
|
||||
#define COLOR_BLACK 0
|
||||
#define COLOR_BLUE 1
|
||||
#define COLOR_GREEN 2
|
||||
#define COLOR_CYAN 3
|
||||
#define COLOR_RED 4
|
||||
#define COLOR_MAGENTA 5
|
||||
#define COLOR_BROWN 6
|
||||
#define COLOR_LIGHT_GRAY 7
|
||||
#define COLOR_DARK_GRAY 8
|
||||
#define COLOR_LIGHT_BLUE 9
|
||||
#define COLOR_LIGHT_GREEN 10
|
||||
#define COLOR_LIGHT_CYAN 11
|
||||
#define COLOR_LIGHT_RED 12
|
||||
#define COLOR_LIGHT_MAGENTA 13
|
||||
#define COLOR_YELLOW 14
|
||||
#define COLOR_WHITE 15
|
||||
|
||||
void loop();
|
||||
void execute_run();
|
||||
|
||||
const char* get_filename();
|
||||
|
||||
void cls(uint8_t value=32);
|
||||
void ink(uint8_t value); // global::ink
|
||||
@@ -120,6 +140,7 @@ void color(uint8_t ink, uint8_t paper, int8_t border=-1);
|
||||
|
||||
void locate(uint8_t x, uint8_t y); // global::cursorx, global::cursory
|
||||
void print(const char *str, int x = -1, int y = -1);
|
||||
void crlf();
|
||||
|
||||
bool btn(uint8_t i);
|
||||
bool btnp(uint8_t i);
|
||||
@@ -157,12 +178,15 @@ int rnd(int x);
|
||||
const char* tostr(float val);
|
||||
|
||||
void debugchr(const uint8_t chr);
|
||||
void debug(const char *str);
|
||||
void pdebug();
|
||||
void debug(const char *str, const bool newline=true);
|
||||
//void pdebug();
|
||||
void debug_get_cmd();
|
||||
void next_cmd();
|
||||
void prev_cmd();
|
||||
|
||||
uint8_t ascii(const char *str, uint8_t index);
|
||||
const char* chr(uint8_t ascii);
|
||||
const char* substr(const char* str, uint8_t start, uint8_t length);
|
||||
|
||||
void setchar(uint8_t index, uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7);
|
||||
uint8_t peek(uint16_t addr);
|
||||
@@ -173,8 +197,14 @@ void sound(float freq, uint32_t len);
|
||||
void nosound();
|
||||
void play(const char* str);
|
||||
|
||||
void setmode(const uint8_t mode);
|
||||
void mode(const uint8_t val);
|
||||
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);
|
||||
|
||||
void toclipboard(const char* str);
|
||||
const char* fromclipboard();
|
||||
|
||||
uint32_t cnt();
|
||||
void rst();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function init()
|
||||
setmode(1)
|
||||
mode(1)
|
||||
reset()
|
||||
end
|
||||
|
||||
|
||||
38
demos/defender.lua
Normal file
38
demos/defender.lua
Normal file
@@ -0,0 +1,38 @@
|
||||
function init()
|
||||
mode(1)
|
||||
|
||||
mountains = {}
|
||||
local val = 2
|
||||
for i=0,99 do
|
||||
val = mid(1,val+rnd(3)-1,4)
|
||||
mountains[i] = val
|
||||
end
|
||||
|
||||
ox=0
|
||||
end
|
||||
|
||||
function update()
|
||||
cls()
|
||||
draw_mountains()
|
||||
|
||||
if btn(KEY_RIGHT) then ox=(ox+1)%100 end
|
||||
if btn(KEY_LEFT) then ox=(ox-1)%100 end
|
||||
end
|
||||
|
||||
function draw_mountains()
|
||||
color(COLOR_RED,COLOR_BLACK)
|
||||
for i=0,39 do
|
||||
local x=(ox+i)%100
|
||||
for j=29-mountains[x],29 do
|
||||
local chr="\143"
|
||||
if j==29-mountains[x] then
|
||||
if mountains[(x+1)%100] > mountains[x] then
|
||||
print("\214",i,j-1) --chr="\214"
|
||||
elseif mountains[(x+1)%100] < mountains[x] then
|
||||
chr="\215"
|
||||
end
|
||||
end
|
||||
print(chr,i,j)
|
||||
end
|
||||
end
|
||||
end
|
||||
53
demos/matrix.lua
Normal file
53
demos/matrix.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
--[[
|
||||
===============================
|
||||
MATRIX CODE DEMO
|
||||
by JailDoctor
|
||||
===============================
|
||||
--]]
|
||||
|
||||
function init()
|
||||
mode(1) -- fiquem el mode multicolor de 40x30 caracters
|
||||
color(0,0) -- tinta i fondo a negre
|
||||
cls() -- borrem pantalla
|
||||
|
||||
-- La tabla 'col' conté, per a cada columna de la pantalla: la coordenada 'y' actual, la llargaria 's' i la espera 'w'
|
||||
col = {}
|
||||
for i=0,39 do
|
||||
col[i] = {
|
||||
y=rnd(30), -- la coordenada y valdrà entre 0 i 29, ningún misteri...
|
||||
s=rnd(5)+2, -- la 's' valdrà entre 2 i 6. S'usarà tant per a definir la llargaria de la estela com per a especificar la velocitat
|
||||
w=1 -- 'w' es un contador de espera: Fiquem 'w' a un valor, i a cada cicle se resta 1. Quan arribe a 0 updatem la columna i se reseteja 'w' al valor anterior.
|
||||
}
|
||||
end
|
||||
|
||||
-- Omplim la tabla 'ma' amb els caracters que volem usar
|
||||
ma = {}
|
||||
for i=176,191 do ma[1+#ma] = i end
|
||||
for i=97,122 do ma[1+#ma] = i end
|
||||
|
||||
-- Omplim la pantalla de caracters aleatoris (dins de la selecció que havem deixa a la tabla 'ma').
|
||||
-- No es veuen perque havem ficat el color de tinta i fondo a negre.
|
||||
for i=0,1199 do poke(i,ma[rnd(#ma)+1]) end
|
||||
end
|
||||
|
||||
function update()
|
||||
for i=0,39 do
|
||||
col[i].w=col[i].w-1
|
||||
if col[i].w == 0 then
|
||||
col[i].w = col[i].s
|
||||
col[i].y=col[i].y+1
|
||||
if (col[i].y >= 30) then col[i].y = 0 end
|
||||
local pos = 1200+i+col[i].y*40
|
||||
poke(pos,15) pos=dec(pos)
|
||||
poke(pos,14) pos=dec(pos)
|
||||
for i=0,col[i].s do poke(pos,10) pos=dec(pos) end
|
||||
for i=0,col[i].s do poke(pos,2) pos=dec(pos) end
|
||||
for i=0,max(1,col[i].s-3) do poke(pos,8) pos=dec(pos) end
|
||||
poke(pos,0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Aquesta funció resta 40 a la adreça (per a pujar una linea). Si detecta que se'n va fora per dalt (menys de 1200), suma 1200 per a que aparega per baix
|
||||
|
||||
function dec(value) return value-40 < 1200 and value+1160 or value-40 end
|
||||
@@ -1,5 +1,5 @@
|
||||
function init()
|
||||
setmode(1)
|
||||
mode(1)
|
||||
setchar(94, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
|
||||
piano = { "_____", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^", "_____",
|
||||
"\143\143\143\154\154", " ", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^" }
|
||||
|
||||
184
demos/sokoban.lua
Normal file
184
demos/sokoban.lua
Normal file
@@ -0,0 +1,184 @@
|
||||
FLOOR = 0
|
||||
GOAL = 1
|
||||
BOX = 2
|
||||
PLAYER = 4
|
||||
WALL = 7
|
||||
|
||||
function init()
|
||||
mode(2)
|
||||
setchar(127,0xee,0xee,0xee,0x00,0xbb,0xbb,0xbb,0x00)
|
||||
setchar(16,0xff,0xc3,0xa5,0x99,0x99,0xa5,0xc3,0xff)
|
||||
menu.init()
|
||||
end
|
||||
|
||||
-- ====================================================================================================
|
||||
-- MENU (game state)
|
||||
-- ====================================================================================================
|
||||
menu={
|
||||
init = function()
|
||||
rst()
|
||||
update=menu.update
|
||||
end,
|
||||
|
||||
update = function()
|
||||
color(15,0) cls()
|
||||
ink(1) print("\x20\x20\x20\x87\x81\x87\x85\x85\x85\x87\x85\x87\x85\x87\x85\x87\x84\x20\x20\x20",0,2)
|
||||
ink(9) print("\x20\x20\x20\x83\x85\x85\x85\x8D\x81\x85\x85\x87\x84\x8D\x85\x85\x85\x20\x20\x20",0,3)
|
||||
ink(11) print("\x20\x20\x20\x83\x81\x83\x81\x81\x81\x83\x81\x83\x81\x81\x81\x81\x81\x20\x20\x20",0,4)
|
||||
ink(15*flr((cnt()%60)/30)) print("PRESS SPACE TO PLAY",1,9)
|
||||
|
||||
if btnp(KEY_SPACE) then
|
||||
level.start()
|
||||
game.init()
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
-- ====================================================================================================
|
||||
-- GAME (game state)
|
||||
-- ====================================================================================================
|
||||
game={
|
||||
init = function()
|
||||
update=game.update
|
||||
level.load()
|
||||
end,
|
||||
|
||||
update = function()
|
||||
border(0)
|
||||
color(1,0)
|
||||
cls()
|
||||
level.draw()
|
||||
|
||||
if btnp(KEY_UP) then level.try_move(0,-1)
|
||||
elseif btnp(KEY_DOWN) then level.try_move(0,1)
|
||||
elseif btnp(KEY_LEFT) then level.try_move(-1,0)
|
||||
elseif btnp(KEY_RIGHT) then level.try_move(1,0)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
-- ====================================================================================================
|
||||
-- LOADING (game state)
|
||||
-- ====================================================================================================
|
||||
loading = {
|
||||
init = function()
|
||||
border(15)
|
||||
update=loading.update
|
||||
rst()
|
||||
end,
|
||||
|
||||
update = function()
|
||||
color(15,0)
|
||||
cls()
|
||||
print("LEVEL "..num_level,6,5)
|
||||
print("GOOD JOB!",5,8)
|
||||
if (cnt()%60)<15 then print("\248",9,10)
|
||||
elseif (cnt()%60)<30 then print("\250",9,10)
|
||||
elseif (cnt()%60)<45 then print("\248",9,10)
|
||||
else print("\251",9,10) end
|
||||
if cnt()==120 then
|
||||
level.next()
|
||||
game.init()
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
-- ====================================================================================================
|
||||
-- LEVEL
|
||||
-- ====================================================================================================
|
||||
levels= {
|
||||
"####|# .#|# ###|#*@ #|# $ #|# ###|####",
|
||||
"######|# #|# #@ #|# $* #|# .* #|# #|######",
|
||||
" ####|### ####|# $ #|# # #$ #|# . .#@ #|#########",
|
||||
"########|# #|# .**$@#|# #|##### #| ####",
|
||||
" #######| # #| # .$. #|## $@$ #|# .$. #|# #|########",
|
||||
"###### #####|# ### #|# $$ #@#|# $ #... #|# ########|#####",
|
||||
"#######|# .$. #|# $.$ #|# .$. #|# $.$ #|# @ #|#######",
|
||||
"#####|#. ##|#@$$ #|## #| ## #| ##.#| ###"
|
||||
}
|
||||
|
||||
level = {
|
||||
start = function() num_level=1 end,
|
||||
next = function() num_level=num_level+1 end,
|
||||
|
||||
load = function()
|
||||
local str = levels[num_level]
|
||||
player={}
|
||||
map={}
|
||||
local pos=0
|
||||
local y,x=1,1
|
||||
local maxx=0
|
||||
map[y] = {}
|
||||
while pos<#str do
|
||||
local chr = ascii(str,pos)
|
||||
if chr == 35 then map[y][x] = WALL end
|
||||
if chr == 64 then player.x,player.y=x,y map[y][x] = FLOOR end
|
||||
if chr == 43 then player.x,player.y=x,y map[y][x] = GOAL end
|
||||
if chr == 36 then map[y][x] = BOX end
|
||||
if chr == 42 then map[y][x] = GOAL+BOX end
|
||||
if chr == 46 then map[y][x] = GOAL end
|
||||
if chr == 32 then map[y][x] = FLOOR end
|
||||
if chr == 124 then
|
||||
y=y+1
|
||||
map[y] = {}
|
||||
if maxx < x then maxx=x end
|
||||
x=0
|
||||
end
|
||||
pos=pos+1
|
||||
x=x+1
|
||||
end
|
||||
ox = flr((20-maxx)/2)
|
||||
oy = flr((15-y)/2)
|
||||
end,
|
||||
|
||||
draw = function()
|
||||
for y=1,#map do
|
||||
for x=1,#map[y] do
|
||||
if map[y][x] == WALL then color(4,0) print("\127",ox+x-1,oy+y-1)
|
||||
elseif map[y][x] == BOX then color(8,7) print("\016",ox+x-1,oy+y-1)
|
||||
elseif map[y][x] == BOX+GOAL then color(3,11) print("\016",ox+x-1,oy+y-1)
|
||||
elseif map[y][x] == GOAL then color(3,0) print("\144",ox+x-1,oy+y-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
color(15,0) print("\248",ox+player.x-1,oy+player.y-1)
|
||||
end,
|
||||
|
||||
try_move = function(x,y)
|
||||
if level.is_empty(x,y) then
|
||||
level.move_player(x,y)
|
||||
elseif level.is_box(x,y) and level.is_empty(x*2,y*2) then
|
||||
level.move_box(x,y)
|
||||
end
|
||||
end,
|
||||
|
||||
is_empty = function(x,y)
|
||||
return map[player.y+y][player.x+x] < 2
|
||||
end,
|
||||
|
||||
is_box = function(x,y)
|
||||
return map[player.y+y][player.x+x] < 4
|
||||
end,
|
||||
|
||||
move_player = function(x,y)
|
||||
player.x=player.x+x
|
||||
player.y=player.y+y
|
||||
end,
|
||||
|
||||
move_box = function(x,y)
|
||||
map[player.y+y*2][player.x+x*2] = map[player.y+y*2][player.x+x*2] + BOX
|
||||
map[player.y+y][player.x+x] = map[player.y+y][player.x+x] - BOX
|
||||
level.move_player(x,y)
|
||||
level.check_finished()
|
||||
end,
|
||||
|
||||
check_finished = function()
|
||||
for y=1,#map do
|
||||
for x=1,#map[y] do
|
||||
if map[y][x] == GOAL then return end
|
||||
end
|
||||
end
|
||||
loading.init()
|
||||
end
|
||||
}
|
||||
@@ -111,7 +111,7 @@ void print(int x, int y, const char* text, Uint8 color) {
|
||||
--]]
|
||||
|
||||
function init()
|
||||
setmode(1)
|
||||
mode(1)
|
||||
current_piece = starting[rnd(7)+1]
|
||||
next_piece = starting[rnd(7)+1]
|
||||
|
||||
|
||||
223
lua.cpp
223
lua.cpp
@@ -2,6 +2,86 @@
|
||||
#include "lua/lua.hpp"
|
||||
#include "ascii.h"
|
||||
|
||||
void reverse(char* str, int len) {
|
||||
int i = 0, j = len - 1, temp;
|
||||
while (i < j) {
|
||||
temp = str[i];
|
||||
str[i] = str[j];
|
||||
str[j] = temp;
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
}
|
||||
|
||||
int intToStr(int x, char str[], int d) {
|
||||
int i = 0;
|
||||
while (x) {
|
||||
str[i++] = (x % 10) + '0';
|
||||
x = x / 10;
|
||||
}
|
||||
|
||||
while (i < d) str[i++] = '0';
|
||||
reverse(str, i);
|
||||
str[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
int ftoa(float n, char* res, int afterpoint) {
|
||||
int ipart = (int)n;
|
||||
float fpart = n - (float)ipart;
|
||||
int i = intToStr(ipart, res, 1);
|
||||
fpart = fpart * SDL_pow(10, afterpoint);
|
||||
if (int(fpart) != 0) {
|
||||
res[i++] = '.';
|
||||
i += intToStr((int)fpart, res + i, afterpoint);
|
||||
while(res[i-1] == '0') res[--i] = '\0';
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
char tempstr[1024];
|
||||
uint16_t ts_index = 0;
|
||||
|
||||
void table_to_str(lua_State *L, int indx);
|
||||
|
||||
void value_to_str(lua_State *L, int indx) {
|
||||
if (lua_isnoneornil(L, indx)) {
|
||||
SDL_memcpy(&tempstr[ts_index], "nil", 3); ts_index+=3;
|
||||
} else if (lua_isfunction(L, indx) || lua_iscfunction(L,indx)) {
|
||||
SDL_memcpy(&tempstr[ts_index], "[function]", 10); ts_index+=10;
|
||||
} else if (lua_istable(L, indx)) {
|
||||
table_to_str(L, indx);
|
||||
} else if (lua_type(L, indx) == LUA_TNUMBER) {
|
||||
const float val = luaL_checknumber(L, indx);
|
||||
const int len = ftoa(val, &tempstr[ts_index], 4); ts_index+=len;
|
||||
} else if (lua_isboolean(L,indx)) {
|
||||
if (lua_toboolean(L, indx)) {
|
||||
SDL_memcpy(&tempstr[ts_index], "true", 4); ts_index+=4;
|
||||
} else {
|
||||
SDL_memcpy(&tempstr[ts_index], "false", 5); ts_index+=5;
|
||||
}
|
||||
} else if (lua_isstring(L,indx)) {
|
||||
const char* str = luaL_checkstring(L,indx);
|
||||
tempstr[ts_index++] = '"';
|
||||
SDL_memcpy(&tempstr[ts_index], str, strlen(str)); ts_index+=strlen(str);
|
||||
tempstr[ts_index++] = '"';
|
||||
}
|
||||
}
|
||||
|
||||
void table_to_str(lua_State *L, int indx) {
|
||||
tempstr[ts_index++] = '{';
|
||||
lua_pushnil(L);
|
||||
bool first = true;
|
||||
while (lua_next(L, indx) != 0) {
|
||||
if (first) { first=false; } else { tempstr[ts_index++] = ','; }
|
||||
value_to_str(L, lua_gettop(L)-1);
|
||||
tempstr[ts_index++] = '=';
|
||||
value_to_str(L, lua_gettop(L));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
tempstr[ts_index++] = '}';
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
static int cpp_cls(lua_State *L) {
|
||||
uint8_t color = luaL_optinteger(L, 1, 32);
|
||||
@@ -54,6 +134,11 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_crlf(lua_State *L) {
|
||||
crlf();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_btn(lua_State *L) {
|
||||
uint8_t i = luaL_checkinteger(L, 1);
|
||||
lua_pushboolean(L, btn(i));
|
||||
@@ -163,9 +248,28 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
static int cpp_tostr(lua_State *L) {
|
||||
float val = luaL_checknumber(L, 1);
|
||||
lua_pushstring(L, tostr(val));
|
||||
ts_index=0;
|
||||
value_to_str(L, 1); tempstr[ts_index] = '\0';
|
||||
lua_pushstring(L, tempstr);
|
||||
return 1;
|
||||
/*
|
||||
if (lua_isnoneornil(L,1)) {
|
||||
lua_pushstring(L, "nil");
|
||||
} else if (lua_isfunction(L,1) || lua_iscfunction(L,1)) {
|
||||
lua_pushstring(L, "[function]");
|
||||
} else if (lua_istable(L,1)) {
|
||||
lua_gettable
|
||||
lua_pushstring(L, "[function]");
|
||||
} else if (lua_isstring(L,1)) {
|
||||
lua_pushstring(L, luaL_checkstring(L,1));
|
||||
} else if (lua_isboolean(L,1)) {
|
||||
lua_pushstring(L, lua_toboolean(L, 1) ? "true" : "false");
|
||||
} else {
|
||||
const float val = luaL_checknumber(L, 1);
|
||||
lua_pushstring(L, tostr(val));
|
||||
}
|
||||
return 1;
|
||||
*/
|
||||
}
|
||||
static int cpp_ascii(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
@@ -183,6 +287,13 @@ extern "C" {
|
||||
lua_pushinteger(L, strlen(str));
|
||||
return 1;
|
||||
}
|
||||
static int cpp_substr(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
int start = luaL_checknumber(L, 2);
|
||||
int length = luaL_checknumber(L, 3);
|
||||
lua_pushstring(L, substr(str, start, length));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_setchar(lua_State *L) {
|
||||
int index = luaL_checkinteger(L, 1);
|
||||
@@ -237,9 +348,9 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_setmode(lua_State *L) {
|
||||
static int cpp_mode(lua_State *L) {
|
||||
int val = luaL_checkinteger(L, 1);
|
||||
setmode(val);
|
||||
mode(mid(0,val,3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -270,6 +381,27 @@ extern "C" {
|
||||
filein(str, addr, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_toclipboard(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
toclipboard(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_fromclipboard(lua_State *L) {
|
||||
lua_pushstring(L, fromclipboard());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_cnt(lua_State *L) {
|
||||
lua_pushinteger(L, cnt());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_rst(lua_State *L) {
|
||||
rst();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define STATE_STOPPED 0
|
||||
@@ -278,35 +410,33 @@ extern "C" {
|
||||
|
||||
lua_State *L;
|
||||
uint8_t lua_state = STATE_STOPPED;
|
||||
bool init_exists = false;
|
||||
bool update_exists = false;
|
||||
//bool init_exists = false;
|
||||
//bool update_exists = false;
|
||||
|
||||
bool lua_is_playing() {
|
||||
return lua_state == STATE_PLAYING;
|
||||
}
|
||||
|
||||
const char boot[] = "function init()setmode(1)cls()play('o5l0v5cegv4cegv3cegv2cegv1ceg')memcpy(360,4608,240)memcpy(1560,4848,240)ink(1)print('G A M E',8,16)ink(4)print('S Y S T E M',20,16)ink(7)print('mini',9,8)ink(8)print('v0.5.4',34,29)w=0 end function update()w=w+1 if w>90 then cls()load()end end";
|
||||
const char boot[] = "function init()mode(1)cls()play('o5l0v5cegv4cegv3cegv2cegv1ceg')memcpy(360,4608,240)memcpy(1560,4848,240)ink(1)print('G A M E',8,16)ink(4)print('S Y S T E M',20,16)ink(7)print('mini',9,8)ink(8)print('v0.5.4',34,29)w=0 end function update()w=w+1 if w>90 then cls()load()end end";
|
||||
|
||||
void lua_init(const char* filename, const bool start_playing) {
|
||||
if (lua_state != STATE_STOPPED) lua_quit();
|
||||
L = luaL_newstate();
|
||||
init_exists = update_exists = false;
|
||||
//init_exists = update_exists = false;
|
||||
bool file_loaded = true;
|
||||
|
||||
if (filename == NULL) {
|
||||
if (luaL_loadstring(L, boot)) {
|
||||
debug("BOOT ERROR");
|
||||
debug("BOOT ERROR:", false);
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
setmode(0);
|
||||
file_loaded = false;
|
||||
}
|
||||
} else {
|
||||
if (luaL_loadfile(L, filename)) {
|
||||
debug("ERROR LOADING GAME");
|
||||
debug("ERROR LOADING GAME:",false);
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
setmode(0);
|
||||
file_loaded = false;
|
||||
}
|
||||
}
|
||||
@@ -319,6 +449,7 @@ void lua_init(const char* filename, const bool start_playing) {
|
||||
|
||||
lua_pushcfunction(L,cpp_locate); lua_setglobal(L, "locate");
|
||||
lua_pushcfunction(L,cpp_print); lua_setglobal(L, "print");
|
||||
lua_pushcfunction(L,cpp_crlf); lua_setglobal(L, "crlf");
|
||||
|
||||
lua_pushcfunction(L,cpp_btn); lua_setglobal(L, "btn");
|
||||
lua_pushcfunction(L,cpp_btnp); lua_setglobal(L, "btnp");
|
||||
@@ -346,6 +477,7 @@ void lua_init(const char* filename, const bool start_playing) {
|
||||
lua_pushcfunction(L,cpp_ascii); lua_setglobal(L, "ascii");
|
||||
lua_pushcfunction(L,cpp_chr); lua_setglobal(L, "chr");
|
||||
lua_pushcfunction(L,cpp_strlen); lua_setglobal(L, "strlen");
|
||||
lua_pushcfunction(L,cpp_substr); lua_setglobal(L, "substr");
|
||||
|
||||
lua_pushcfunction(L,cpp_setchar); lua_setglobal(L, "setchar");
|
||||
lua_pushcfunction(L,cpp_peek); lua_setglobal(L, "peek");
|
||||
@@ -354,12 +486,17 @@ void lua_init(const char* filename, const bool start_playing) {
|
||||
lua_pushcfunction(L,cpp_sound); lua_setglobal(L, "sound");
|
||||
lua_pushcfunction(L,cpp_nosound); lua_setglobal(L, "nosound");
|
||||
lua_pushcfunction(L,cpp_play); lua_setglobal(L, "play");
|
||||
lua_pushcfunction(L,cpp_setmode); lua_setglobal(L, "setmode");
|
||||
lua_pushcfunction(L,cpp_mode); lua_setglobal(L, "mode");
|
||||
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_pushcfunction(L,cpp_toclipboard); lua_setglobal(L, "toclipboard");
|
||||
lua_pushcfunction(L,cpp_fromclipboard); lua_setglobal(L, "fromclipboard");
|
||||
|
||||
lua_pushcfunction(L,cpp_cnt); lua_setglobal(L, "cnt");
|
||||
lua_pushcfunction(L,cpp_rst); lua_setglobal(L, "rst");
|
||||
|
||||
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
|
||||
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");
|
||||
@@ -489,13 +626,13 @@ void lua_init(const char* filename, const bool start_playing) {
|
||||
if (!file_loaded) return;
|
||||
|
||||
if (lua_pcall(L,0, LUA_MULTRET, 0)) {
|
||||
debug("RUNTIME ERROR");
|
||||
debug("RUNTIME ERROR:", false);
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
setmode(0);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
lua_getglobal(L, "init");
|
||||
if (lua_isfunction(L,-1)) init_exists = true;
|
||||
lua_pop(L,1);
|
||||
@@ -503,41 +640,55 @@ void lua_init(const char* filename, const bool start_playing) {
|
||||
lua_getglobal(L, "update");
|
||||
if (lua_isfunction(L,-1)) update_exists = true;
|
||||
lua_pop(L,1);
|
||||
|
||||
*/
|
||||
lua_state = start_playing ? STATE_PLAYING : STATE_PAUSED;
|
||||
}
|
||||
|
||||
void lua_call_cmd(const char* str) {
|
||||
if (luaL_dostring(L, str)) {
|
||||
debug(" ");
|
||||
debug("ERROR");
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
if (str[0]=='?') {
|
||||
const int size = strlen(str)+14;
|
||||
char* cmd = (char*)malloc(size);
|
||||
memcpy(cmd, "print(tostr(", 12);
|
||||
memcpy(&cmd[12], &str[1], strlen(str)-1);
|
||||
cmd[size-1]='\0';
|
||||
cmd[size-3]=cmd[size-2]=')';
|
||||
if (luaL_dostring(L, cmd)) {
|
||||
debug("ERROR:",false);
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
}
|
||||
} else {
|
||||
if (luaL_dostring(L, str)) {
|
||||
debug("ERROR:",false);
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
}
|
||||
}
|
||||
debug(" ");
|
||||
}
|
||||
|
||||
void lua_call_init() {
|
||||
if (!init_exists) return;
|
||||
lua_getglobal(L, "init");
|
||||
if (lua_pcall(L, 0, 0, 0)) {
|
||||
debug("RUNTIME ERROR");
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
setmode(0);
|
||||
lua_state = STATE_STOPPED;
|
||||
if (lua_isfunction(L,-1)) {
|
||||
if (lua_pcall(L, 0, 0, 0)) {
|
||||
debug("RUNTIME ERROR:",false);
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
lua_state = STATE_STOPPED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lua_call_update() {
|
||||
if (!update_exists) return;
|
||||
lua_getglobal(L, "update");
|
||||
if (lua_pcall(L, 0, 0, 0)) {
|
||||
debug("RUNTIME ERROR");
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
setmode(0);
|
||||
lua_state = STATE_STOPPED;
|
||||
if (lua_isfunction(L,-1)) {
|
||||
if (lua_pcall(L, 0, 0, 0)) {
|
||||
debug("RUNTIME ERROR:",false);
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
lua_state = STATE_STOPPED;
|
||||
}
|
||||
} else {
|
||||
lua_state = STATE_PAUSED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
116
main.cpp
116
main.cpp
@@ -1,57 +1,73 @@
|
||||
#include "ascii.h"
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
int current_editor = 0;
|
||||
|
||||
void do_terminal() {
|
||||
SDL_Keymod mods = SDL_GetModState();
|
||||
const uint8_t key = whichbtn();
|
||||
if (key != KEY_UNKNOWN) {
|
||||
if (key < 30) {
|
||||
if ((mods & KMOD_SHIFT) || (mods & KMOD_CAPS)) {
|
||||
debugchr(key+61);
|
||||
} else {
|
||||
debugchr(key+93);
|
||||
}
|
||||
}
|
||||
//else if (key < 39) debugchr(key+19);
|
||||
else if (key == KEY_0) { if (mods & KMOD_SHIFT) { debugchr('='); } else { debugchr('0'); } }
|
||||
else if (key == KEY_1) { if (mods & KMOD_SHIFT) { debugchr('!'); } else if (mods & KMOD_RALT) { debugchr('|'); } else { debugchr('1'); } }
|
||||
else if (key == KEY_2) { if (mods & KMOD_SHIFT) { debugchr('"'); } else if (mods & KMOD_RALT) { debugchr('@'); } else { debugchr('2'); } }
|
||||
else if (key == KEY_3) { if (mods & KMOD_SHIFT) { debugchr(144); } else if (mods & KMOD_RALT) { debugchr('#'); } else { debugchr('3'); } }
|
||||
else if (key == KEY_4) { if (mods & KMOD_SHIFT) { debugchr('$'); } else if (mods & KMOD_RALT) { debugchr('~'); } else { debugchr('4'); } }
|
||||
else if (key == KEY_5) { if (mods & KMOD_SHIFT) { debugchr('%'); } else if (mods & KMOD_RALT) { debugchr(180); } else { debugchr('5'); } }
|
||||
else if (key == KEY_6) { if (mods & KMOD_SHIFT) { debugchr('&'); } else if (mods & KMOD_RALT) { debugchr(173); } else { debugchr('6'); } }
|
||||
else if (key == KEY_7) { if (mods & KMOD_SHIFT) { debugchr('/'); } else { debugchr('7'); } }
|
||||
else if (key == KEY_8) { if (mods & KMOD_SHIFT) { debugchr('('); } else { debugchr('8'); } }
|
||||
else if (key == KEY_9) { if (mods & KMOD_SHIFT) { debugchr(')'); } else { debugchr('9'); } }
|
||||
else if (key == KEY_RETURN) debug_get_cmd();
|
||||
else if (key == KEY_SPACE) debugchr(32);
|
||||
else if (key == KEY_BACKSPACE) debugchr(8);
|
||||
else if (key == KEY_MINUS) { if (mods & KMOD_SHIFT) { debugchr('?'); } else { debugchr('\''); } }
|
||||
else if (key == KEY_EQUALS) { if (mods & KMOD_SHIFT) { debugchr(174); } else { debugchr(175); } }
|
||||
else if (key == KEY_COMMA) { if (mods & KMOD_SHIFT) { debugchr(';'); } else { debugchr(','); } }
|
||||
else if (key == KEY_PERIOD) { if (mods & KMOD_SHIFT) { debugchr(':'); } else { debugchr('.'); } }
|
||||
else if (key == KEY_SLASH) { if (mods & KMOD_SHIFT) { debugchr('_'); } else { debugchr('-'); } }
|
||||
else if (key == KEY_LEFTBRACKET) { if (mods & KMOD_SHIFT) { debugchr(160); } else if (mods & KMOD_RALT) { debugchr('['); } else { debugchr(96); } }
|
||||
else if (key == KEY_RIGHTBRACKET) { if (mods & KMOD_SHIFT) { debugchr('*'); } else if (mods & KMOD_RALT) { debugchr(']'); } else { debugchr('+'); } }
|
||||
}
|
||||
//cls(0);
|
||||
pdebug();
|
||||
}
|
||||
void init_terminal();
|
||||
void do_terminal();
|
||||
|
||||
void loop() {
|
||||
do_terminal();
|
||||
/*
|
||||
if (btnp(KEY_TAB)) {
|
||||
current_editor = (++current_editor)%5;
|
||||
}
|
||||
|
||||
void execute_run() {
|
||||
//if (current_editor == 1) save_code();
|
||||
}
|
||||
|
||||
uint8_t get_char(uint8_t key) {
|
||||
SDL_Keymod mods = SDL_GetModState();
|
||||
if (key != KEY_UNKNOWN) {
|
||||
if (key < 30) {
|
||||
if ((mods & KMOD_SHIFT) || (mods & KMOD_CAPS)) {
|
||||
return key+61;
|
||||
} else {
|
||||
return key+93;
|
||||
}
|
||||
}
|
||||
else if (key == KEY_0) { if (mods & KMOD_SHIFT) { return '='; } else { return '0'; } }
|
||||
else if (key == KEY_1) { if (mods & KMOD_SHIFT) { return '!'; } else if (mods & KMOD_RALT) { return '|'; } else { return '1'; } }
|
||||
else if (key == KEY_2) { if (mods & KMOD_SHIFT) { return '"'; } else if (mods & KMOD_RALT) { return '@'; } else { return '2'; } }
|
||||
else if (key == KEY_3) { if (mods & KMOD_SHIFT) { return 144; } else if (mods & KMOD_RALT) { return '#'; } else { return '3'; } }
|
||||
else if (key == KEY_4) { if (mods & KMOD_SHIFT) { return '$'; } else if (mods & KMOD_RALT) { return '~'; } else { return '4'; } }
|
||||
else if (key == KEY_5) { if (mods & KMOD_SHIFT) { return '%'; } else if (mods & KMOD_RALT) { return 180; } else { return '5'; } }
|
||||
else if (key == KEY_6) { if (mods & KMOD_SHIFT) { return '&'; } else if (mods & KMOD_RALT) { return 173; } else { return '6'; } }
|
||||
else if (key == KEY_7) { if (mods & KMOD_SHIFT) { return '/'; } else { return '7'; } }
|
||||
else if (key == KEY_8) { if (mods & KMOD_SHIFT) { return '('; } else { return '8'; } }
|
||||
else if (key == KEY_9) { if (mods & KMOD_SHIFT) { return ')'; } else { return '9'; } }
|
||||
else if (key == KEY_SPACE) return 32;
|
||||
else if (key == KEY_MINUS) { if (mods & KMOD_SHIFT) { return '?'; } else { return '\''; } }
|
||||
else if (key == KEY_EQUALS) { if (mods & KMOD_SHIFT) { return 174; } else { return 175; } }
|
||||
else if (key == KEY_COMMA) { if (mods & KMOD_SHIFT) { return ';'; } else { return ','; } }
|
||||
else if (key == KEY_PERIOD) { if (mods & KMOD_SHIFT) { return ':'; } else { return '.'; } }
|
||||
else if (key == KEY_SLASH) { if (mods & KMOD_SHIFT) { return '_'; } else { return '-'; } }
|
||||
else if (key == KEY_LEFTBRACKET) { if (mods & KMOD_SHIFT) { return 160; } else if (mods & KMOD_RALT) { return '['; } else { return 96; } }
|
||||
else if (key == KEY_RIGHTBRACKET) { if (mods & KMOD_SHIFT) { return '*'; } else if (mods & KMOD_RALT) { return ']'; } else { return '+'; } }
|
||||
else if (key == KEY_APOSTROPHE) { if (mods & KMOD_SHIFT) { return 162; } else if (mods & KMOD_RALT) { return '{'; } else { return 161; } }
|
||||
else if (key == KEY_BACKSLASH) { if (mods & KMOD_SHIFT) { return 'C'; } else if (mods & KMOD_RALT) { return '}'; } else { return 'c'; } }
|
||||
else if (key == KEY_GRAVE) { if (mods & KMOD_SHIFT) { return '>'; } else { return '<'; } }
|
||||
else if (key == KEY_NONUSBACKSLASH) { if (mods & KMOD_SHIFT) { return 164; } else if (mods & KMOD_RALT) { return '\\'; } else { return 163; } }
|
||||
else return 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
switch(current_editor) {
|
||||
case 0:
|
||||
do_terminal();
|
||||
break;
|
||||
case 1:
|
||||
do_sprite_editor();
|
||||
break;
|
||||
}
|
||||
|
||||
void init_terminal() {
|
||||
mode(0);
|
||||
cls();
|
||||
}
|
||||
|
||||
void do_terminal() {
|
||||
//SDL_Keymod mods = SDL_GetModState();
|
||||
const uint8_t key = whichbtn();
|
||||
if (key != KEY_UNKNOWN) {
|
||||
if (key == KEY_RETURN or key == KEY_KP_ENTER) debug_get_cmd();
|
||||
else if (key == KEY_UP) next_cmd();
|
||||
else if (key == KEY_DOWN) prev_cmd();
|
||||
else if (key == KEY_BACKSPACE) debugchr(8);
|
||||
else {
|
||||
uint8_t chr = get_char(key);
|
||||
if (chr != 0) debugchr(chr);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
65
tools/fontedit.lua
Normal file
65
tools/fontedit.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
function init()
|
||||
mode(1)
|
||||
sel = 127
|
||||
end
|
||||
|
||||
clicked=false
|
||||
mx,my=0,0
|
||||
function update()
|
||||
color(0,7)
|
||||
cls()
|
||||
|
||||
color(8,0)
|
||||
for y=0,15 do
|
||||
for x=0,15 do
|
||||
print(chr(x+y*16),x+1,y+1)
|
||||
end
|
||||
end
|
||||
poke(1200+((sel%16)+1+(flr(sel/16)+1)*40),15)
|
||||
|
||||
drawchar(sel,19,1)
|
||||
|
||||
if mousebutton(1) then
|
||||
if mousex()>=1 and mousey()>=1 and mousex()<=16 and mousey()<=16 then
|
||||
sel = mousex()-1+(mousey()-1)*16
|
||||
elseif mousex()>=19 and mousey()>=1 and mousex()<=26 and mousey()<=8 then
|
||||
if not clicked or mousex()~=mx or mousey()~=my then
|
||||
clicked,mx,my=true,mousex(),mousey()
|
||||
local pos = 2560+sel*8+(mousey()-1)
|
||||
local bit = 1 << (7-(mousex()-19))
|
||||
local value = peek(pos)
|
||||
poke(pos, value ~ bit)
|
||||
end
|
||||
end
|
||||
else
|
||||
clicked = false
|
||||
end
|
||||
|
||||
if btnp(KEY_S) then
|
||||
local pos = 2560+sel*8
|
||||
local string = "setchar("..sel..","..peek(pos)..","..peek(pos+1)..","..peek(pos+2)..","..peek(pos+3)..","..peek(pos+4)..","..peek(pos+5)..","..peek(pos+6)..","..peek(pos+7)..")"
|
||||
toclipboard(string)
|
||||
end
|
||||
|
||||
ink(4)
|
||||
print("\143",mousex(), mousey())
|
||||
end
|
||||
|
||||
function drawchar(char,x,y)
|
||||
color(15,0)
|
||||
local pos = 2560+char*8
|
||||
for i=1,8 do
|
||||
local val = peek(pos)
|
||||
print(" ",x,y)
|
||||
if val&1==1 then print("\143",x+7,y) end
|
||||
if val&2==2 then print("\143",x+6,y) end
|
||||
if val&4==4 then print("\143",x+5,y) end
|
||||
if val&8==8 then print("\143",x+4,y) end
|
||||
if val&16==16 then print("\143",x+3,y) end
|
||||
if val&32==32 then print("\143",x+2,y) end
|
||||
if val&64==64 then print("\143",x+1,y) end
|
||||
if val&128==128 then print("\143",x,y) end
|
||||
y=y+1
|
||||
pos=pos+1
|
||||
end
|
||||
end
|
||||
@@ -1,13 +1,11 @@
|
||||
ind = 22
|
||||
function init()
|
||||
setmode(2)
|
||||
mode(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
|
||||
@@ -76,10 +74,17 @@ function draw_map()
|
||||
map[mx+my*20] = sel_chr
|
||||
col[mx+my*20] = sel_col
|
||||
end
|
||||
if mousebutton(3) then
|
||||
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
|
||||
if btnp(KEY_UP) then for i=20,299 do map[i-20]=map[i]col[i-20]=col[i] end end
|
||||
if btnp(KEY_DOWN) then for i=279,0,-1 do map[i+20]=map[i]col[i+20]=col[i] end end
|
||||
if btnp(KEY_LEFT) then for i=0,298 do map[i]=map[i+1]col[i]=col[i+1] end end
|
||||
if btnp(KEY_RIGHT) then for i=299,1,-1 do map[i]=map[i-1]col[i]=col[i-1] end end
|
||||
|
||||
blink = blink - 1
|
||||
if blink < 30 then
|
||||
@@ -88,4 +93,15 @@ function draw_map()
|
||||
local c = peek(300+(mx+my*20))
|
||||
poke(300+(mx+my*20), c~0xff)
|
||||
end
|
||||
|
||||
if btn(KEY_S) then
|
||||
fileout("map.bin", 0, 600);
|
||||
elseif btn(KEY_L) then
|
||||
filein("map.bin", 0, 600);
|
||||
for i=0,299 do
|
||||
map[i] = peek(i)
|
||||
col[i] = peek(300+i)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function init()
|
||||
setmode(1)
|
||||
mode(1)
|
||||
setchar(94, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
|
||||
piano = { "_____", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^", "_____",
|
||||
"\143\143\143\154\154", " ", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^" }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
ind = 22
|
||||
function init()
|
||||
setmode(1)
|
||||
mode(1)
|
||||
map = {}
|
||||
col = {}
|
||||
for i=0,1199 do
|
||||
@@ -85,6 +85,11 @@ function draw_map()
|
||||
sel_col = peek(1200+mx+my*40)
|
||||
end
|
||||
|
||||
if btnp(KEY_UP) then for i=40,1199 do map[i-40]=map[i]col[i-40]=col[i] end end
|
||||
if btnp(KEY_DOWN) then for i=1159,0,-1 do map[i+40]=map[i]col[i+40]=col[i] end end
|
||||
if btnp(KEY_LEFT) then for i=0,1198 do map[i]=map[i+1]col[i]=col[i+1] end end
|
||||
if btnp(KEY_RIGHT) then for i=1199,1,-1 do map[i]=map[i-1]col[i]=col[i-1] end end
|
||||
|
||||
blink = blink - 1
|
||||
if blink < 30 then
|
||||
if blink==0 then blink = 60 end
|
||||
|
||||
84
tools/spritedit.lua
Normal file
84
tools/spritedit.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
function init()
|
||||
ink_color = 15
|
||||
paper_color = 0
|
||||
setchar(0,0xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff)
|
||||
sprite={0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03}
|
||||
end
|
||||
|
||||
function update()
|
||||
color(15,1)
|
||||
cls()
|
||||
color(ink_color,paper_color)
|
||||
drawbigspr(sprite,1,1)
|
||||
drawspr(sprite,65)
|
||||
print("AB",18,1) print("CD",18,2)
|
||||
|
||||
for i=0,15 do
|
||||
color(0,i)
|
||||
poke(721+i,0) poke(1921+i,i<<4)
|
||||
poke(761+i,0) poke(1961+i,i<<4)
|
||||
end
|
||||
|
||||
poke(1921+ink_color, peek(1921+ink_color)+4)
|
||||
poke(1961+paper_color, peek(1961+paper_color)+4)
|
||||
|
||||
if mousebutton(1) and mousex()>=1 and mousey()>=18 and mousex()<=16 and mousey()<=19 then
|
||||
if mousey()==18 then
|
||||
ink_color = mousex()-1
|
||||
else
|
||||
paper_color = mousex()-1
|
||||
end
|
||||
end
|
||||
|
||||
handlesprmouse()
|
||||
end
|
||||
|
||||
mousepressed = false
|
||||
mousepos = {x=-1,y=-1}
|
||||
function handlesprmouse()
|
||||
local mx,my=mousex(),mousey()
|
||||
if mx>=1 and my>=1 and mx<=16 and my<=16 then
|
||||
if mousebutton(1) then
|
||||
if (not mousepressed or (mousepos.x ~= mx or mousepos.y ~= my)) then
|
||||
mousepressed = true mousepos.x = mx mousepos.y = my
|
||||
local quadrant = flr((mx-1)/8)+flr((my-1)/8)*2
|
||||
local x=(mx-1)%8
|
||||
local y=(my-1)%8
|
||||
local val = sprite[quadrant*8+y+1]
|
||||
val = val ~ (1<<(7-x))
|
||||
sprite[quadrant*8+y+1] = val
|
||||
end
|
||||
else
|
||||
mousepressed = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function drawbigspr(spr,x,y)
|
||||
drawbigsprchr(spr,0,x,y)
|
||||
drawbigsprchr(spr,1,x+8,y)
|
||||
drawbigsprchr(spr,2,x,y+8)
|
||||
drawbigsprchr(spr,3,x+8,y+8)
|
||||
end
|
||||
|
||||
function drawbigsprchr(spr,chr,x,y)
|
||||
local pos = 1+chr*8
|
||||
for i=1,8 do
|
||||
local val = spr[pos]
|
||||
print(" ",x,y)
|
||||
if val&1==1 then print("\143",x+7,y) end
|
||||
if val&2==2 then print("\143",x+6,y) end
|
||||
if val&4==4 then print("\143",x+5,y) end
|
||||
if val&8==8 then print("\143",x+4,y) end
|
||||
if val&16==16 then print("\143",x+3,y) end
|
||||
if val&32==32 then print("\143",x+2,y) end
|
||||
if val&64==64 then print("\143",x+1,y) end
|
||||
if val&128==128 then print("\143",x,y) end
|
||||
y=y+1
|
||||
pos=pos+1
|
||||
end
|
||||
end
|
||||
|
||||
function drawspr(spr,chr)
|
||||
for i=0,31 do poke(i+2560+chr*8,spr[i+1]) end
|
||||
end
|
||||
11
tweetcarts/matrix.lua
Normal file
11
tweetcarts/matrix.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
q=1200
|
||||
h={}for i=0,q do poke(i,rnd(99))end
|
||||
function t(a)poke(q+p,a)p=(p-40)%q end
|
||||
function update()srand(1)for i=0,39 do
|
||||
h[i]=(h[i] or rnd(30))+(1/(rnd(5)+2))p=i+(flr(h[i])%30)*40
|
||||
t(15)t(14)
|
||||
for j=0,5 do t(10)end
|
||||
for j=0,5 do t(2)end
|
||||
t(8)t(0)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user