Compare commits
30 Commits
56f2e202e8
...
v0.6.1
| Author | SHA1 | Date | |
|---|---|---|---|
| b2a96309e5 | |||
| b0446f40a1 | |||
| 3b4501aaec | |||
| fca1172162 | |||
| 9d2a0801e1 | |||
| 41f539578a | |||
| dd7e3de890 | |||
| 785a51ac98 | |||
| 9ed4118250 | |||
| 5c0758354c | |||
| 3abd22f150 | |||
| cde75e2557 | |||
| 4733a66fc0 | |||
| b3f59e9175 | |||
| ffb4875605 | |||
| 50842cf9c9 | |||
| 61f3c385c0 | |||
| af3b04f0ab | |||
| b09360d7ae | |||
| fa85d3cb34 | |||
| 3dfa177cd2 | |||
| a349cf5c0c | |||
| f889faa472 | |||
| 743fd2b8cc | |||
| 841f4f66f3 | |||
| 82bebe3eeb | |||
| c52687f0eb | |||
| 97daca8097 | |||
| 64bcedd82f | |||
| fe9f4fed9c |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -3,3 +3,8 @@ ascii
|
|||||||
.vscode/*
|
.vscode/*
|
||||||
*.dll
|
*.dll
|
||||||
wiki/*
|
wiki/*
|
||||||
|
scr_min.c
|
||||||
|
tests.lua
|
||||||
|
fake_editor.lua
|
||||||
|
*.bin
|
||||||
|
bin/*
|
||||||
27
Makefile
Normal file
27
Makefile
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
executable = ascii
|
||||||
|
source = *.cpp ./lua/*.c
|
||||||
|
|
||||||
|
windows:
|
||||||
|
@echo off
|
||||||
|
g++ $(source) -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lmingw32 -lSDL2main -lSDL2 -mwindows -o "$(executable).exe"
|
||||||
|
strip -s -R .comment -R .gnu.version --strip-unneeded "$(executable).exe"
|
||||||
|
|
||||||
|
windows_debug:
|
||||||
|
@echo off
|
||||||
|
g++ $(source) -D DEBUG -g -Wall -Os -lmingw32 -lSDL2main -lSDL2 -o "$(executable)_debug.exe"
|
||||||
|
|
||||||
|
macos:
|
||||||
|
clang++ $(source) -Wall -Os -std=c++11 -ffunction-sections -fdata-sections -lSDL2 -o "$(executable)"
|
||||||
|
|
||||||
|
macos_debug:
|
||||||
|
clang++ $(source) -D DEBUG -g -Wall -Os -std=c++11 -ffunction-sections -fdata-sections -lSDL2 -o "$(executable)_debug"
|
||||||
|
|
||||||
|
macos_bundle:
|
||||||
|
clang++ $(source) -D MACOS_BUNDLE -Wall -Os -std=c++11 -framework SDL2 -F /Library/Frameworks -ffunction-sections -fdata-sections -o mini_bundle -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
|
||||||
|
|
||||||
|
linux:
|
||||||
|
g++ $(source) -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lSDL2 -o "$(executable)"
|
||||||
|
strip -s -R .comment -R .gnu.version --strip-unneeded "$(executable)"
|
||||||
|
|
||||||
|
linux_debug:
|
||||||
|
g++ $(source) -D DEBUG -g -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lSDL2 -o "$(executable)_debug"
|
||||||
75
ascii.cpp
75
ascii.cpp
@@ -21,6 +21,10 @@ uint8_t *char_screen = NULL;
|
|||||||
uint8_t *color_screen = NULL;
|
uint8_t *color_screen = NULL;
|
||||||
uint8_t screen_width = 40;
|
uint8_t screen_width = 40;
|
||||||
uint8_t screen_height = 30;
|
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_color = 0x1e;
|
||||||
uint8_t current_border = 0;
|
uint8_t current_border = 0;
|
||||||
uint8_t current_mode = 1;
|
uint8_t current_mode = 1;
|
||||||
@@ -42,6 +46,7 @@ SDL_Texture *mini_bak = NULL;
|
|||||||
SDL_AudioDeviceID mini_audio_device;
|
SDL_AudioDeviceID mini_audio_device;
|
||||||
Uint32 *pixels;
|
Uint32 *pixels;
|
||||||
int pitch;
|
int pitch;
|
||||||
|
Uint32 counter=0;
|
||||||
|
|
||||||
uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0000, 0x00AA00AA, 0x00AA5500, 0x00AAAAAA,
|
uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0000, 0x00AA00AA, 0x00AA5500, 0x00AAAAAA,
|
||||||
0x00555555, 0x005555FF, 0x0055FF55, 0x0055FFFF, 0x00FF5555, 0x00FF55FF, 0x00FFFF55, 0x00FFFFFF };
|
0x00555555, 0x005555FF, 0x0055FF55, 0x0055FFFF, 0x00FF5555, 0x00FF55FF, 0x00FFFF55, 0x00FFFFFF };
|
||||||
@@ -63,6 +68,9 @@ const char* get_filename() {
|
|||||||
|
|
||||||
void reinit() {
|
void reinit() {
|
||||||
if (mini_bak != NULL) SDL_DestroyTexture(mini_bak);
|
if (mini_bak != NULL) SDL_DestroyTexture(mini_bak);
|
||||||
|
counter=0;
|
||||||
|
hborder = vborder = 40;
|
||||||
|
v_screen_w = 640; v_screen_h = 480;
|
||||||
switch (current_mode) {
|
switch (current_mode) {
|
||||||
case 0:
|
case 0:
|
||||||
screen_width = 80;
|
screen_width = 80;
|
||||||
@@ -100,17 +108,21 @@ void reinit() {
|
|||||||
//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);
|
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 160, 120);
|
||||||
break;
|
break;
|
||||||
case 3: // SUPERSECRET MODE FOR THE EDITOR!!!
|
case 3:
|
||||||
screen_width = 80;
|
hborder = 104;
|
||||||
screen_height = 30;
|
vborder = 88;
|
||||||
current_color = 0x1f;
|
v_screen_w = 512;
|
||||||
current_border = 9;
|
v_screen_h = 384;
|
||||||
|
screen_width = 32;
|
||||||
|
screen_height = 24;
|
||||||
|
current_color = 0x07;
|
||||||
|
current_border = 0;
|
||||||
cursor_x = 0;
|
cursor_x = 0;
|
||||||
cursor_y = 0;
|
cursor_y = 0;
|
||||||
char_screen = &mem[0];
|
char_screen = &mem[0];
|
||||||
color_screen = &mem[0x1200];
|
color_screen = &mem[768];
|
||||||
//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);
|
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 256, 192);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,10 +198,12 @@ int main(int argc,char*argv[]) {
|
|||||||
lua_init(NULL);
|
lua_init(NULL);
|
||||||
lua_call_init();
|
lua_call_init();
|
||||||
|
|
||||||
|
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||||
|
|
||||||
while(!exit) {
|
while(!exit) {
|
||||||
if (should_reset) {
|
if (should_reset) {
|
||||||
should_reset = false;
|
should_reset = false;
|
||||||
setmode(1);
|
mode(1);
|
||||||
reinit();
|
reinit();
|
||||||
lua_init(lua_filename);
|
lua_init(lua_filename);
|
||||||
lua_call_init();
|
lua_call_init();
|
||||||
@@ -198,6 +212,12 @@ int main(int argc,char*argv[]) {
|
|||||||
mouse_wheel = 0;
|
mouse_wheel = 0;
|
||||||
while(SDL_PollEvent(&mini_eve)) {
|
while(SDL_PollEvent(&mini_eve)) {
|
||||||
if (mini_eve.type == SDL_QUIT) { exit=true; break; }
|
if (mini_eve.type == SDL_QUIT) { exit=true; break; }
|
||||||
|
if (mini_eve.type == SDL_DROPFILE) {
|
||||||
|
char* dropped_filedir = mini_eve.drop.file;
|
||||||
|
load(dropped_filedir);
|
||||||
|
//SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_INFORMATION, "File dropped on window", dropped_filedir, mini_win );
|
||||||
|
SDL_free(dropped_filedir);
|
||||||
|
}
|
||||||
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()) {
|
||||||
@@ -229,9 +249,12 @@ int main(int argc,char*argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
keys = SDL_GetKeyboardState(NULL);
|
keys = SDL_GetKeyboardState(NULL);
|
||||||
mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
|
int mx, my;
|
||||||
mouse_x = (mouse_x-40) / (640/screen_width);
|
mouse_buttons = SDL_GetMouseState(&mx, &my);
|
||||||
mouse_y = (mouse_y-40) / (480/screen_height);
|
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()) {
|
if (lua_is_playing()) {
|
||||||
lua_call_update();
|
lua_call_update();
|
||||||
@@ -239,9 +262,9 @@ int main(int argc,char*argv[]) {
|
|||||||
} else {
|
} else {
|
||||||
debug_cursor_blink--;
|
debug_cursor_blink--;
|
||||||
if (debug_cursor_blink == 0) {
|
if (debug_cursor_blink == 0) {
|
||||||
debug_cursor_blink = 30;
|
debug_cursor_blink = 60;
|
||||||
const int pos = cursor_x+cursor_y*screen_width;
|
const int pos = cursor_x+cursor_y*screen_width;
|
||||||
char_screen[pos] = char_screen[pos]==32 ? 95 : 32;
|
//char_screen[pos] = char_screen[pos]==32 ? 95 : 32;
|
||||||
}
|
}
|
||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
@@ -251,7 +274,10 @@ int main(int argc,char*argv[]) {
|
|||||||
case 0:
|
case 0:
|
||||||
for (int y=0; y<screen_height; ++y) {
|
for (int y=0; y<screen_height; ++y) {
|
||||||
for (int x=0; x<screen_width; ++x) {
|
for (int x=0; x<screen_width; ++x) {
|
||||||
const uint8_t chr_color = current_color; //COLSCR(x,y);
|
uint8_t chr_color = current_color; //COLSCR(x,y);
|
||||||
|
if ((debug_cursor_blink<30)&&(cursor_x==x)&&(cursor_y==y)) {
|
||||||
|
chr_color = (chr_color>>4)+((chr_color&0x0f)<<4);
|
||||||
|
}
|
||||||
const uint32_t ink_color = palette[chr_color & 0x0f];
|
const uint32_t ink_color = palette[chr_color & 0x0f];
|
||||||
const uint32_t paper_color = palette[chr_color >> 4];
|
const uint32_t paper_color = palette[chr_color >> 4];
|
||||||
const uint8_t chr = CHRSCR(x,y);
|
const uint8_t chr = CHRSCR(x,y);
|
||||||
@@ -298,10 +324,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, (palette[current_border] >> 16)&0xff, (palette[current_border] >> 8)&0xff, palette[current_border]&0xff, 0);
|
||||||
//SDL_SetRenderDrawColor(mini_ren, 255, 0, 0, 0);
|
//SDL_SetRenderDrawColor(mini_ren, 255, 0, 0, 0);
|
||||||
SDL_RenderClear(mini_ren);
|
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, &rect);
|
||||||
//SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
|
//SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
|
||||||
SDL_RenderPresent(mini_ren);
|
SDL_RenderPresent(mini_ren);
|
||||||
|
counter++;
|
||||||
}
|
}
|
||||||
lua_quit();
|
lua_quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
@@ -565,6 +592,11 @@ void prev_cmd() {
|
|||||||
get_cmd_by_index();
|
get_cmd_by_index();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void debug_set_cursor(uint8_t x, uint8_t y) {
|
||||||
|
cursor_x = x;
|
||||||
|
cursor_y = y;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t ascii(const char *str, uint8_t index) {
|
uint8_t ascii(const char *str, uint8_t index) {
|
||||||
return str[index];
|
return str[index];
|
||||||
}
|
}
|
||||||
@@ -629,8 +661,8 @@ void play(const char* str) {
|
|||||||
audio_state = AUDIO_PLAY;
|
audio_state = AUDIO_PLAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setmode(const uint8_t mode) {
|
void mode(const uint8_t val) {
|
||||||
current_mode = mode;
|
current_mode = val;
|
||||||
reinit();
|
reinit();
|
||||||
cls();
|
cls();
|
||||||
}
|
}
|
||||||
@@ -669,4 +701,11 @@ const char* fromclipboard() {
|
|||||||
SDL_free((void*)text);
|
SDL_free((void*)text);
|
||||||
|
|
||||||
return str_tmp;
|
return str_tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t cnt() {
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
void rst() {
|
||||||
|
counter = 0;
|
||||||
|
}
|
||||||
|
|||||||
8
ascii.h
8
ascii.h
@@ -183,6 +183,7 @@ void debug(const char *str, const bool newline=true);
|
|||||||
void debug_get_cmd();
|
void debug_get_cmd();
|
||||||
void next_cmd();
|
void next_cmd();
|
||||||
void prev_cmd();
|
void prev_cmd();
|
||||||
|
void debug_set_cursor(uint8_t x, uint8_t y);
|
||||||
|
|
||||||
uint8_t ascii(const char *str, uint8_t index);
|
uint8_t ascii(const char *str, uint8_t index);
|
||||||
const char* chr(uint8_t ascii);
|
const char* chr(uint8_t ascii);
|
||||||
@@ -197,11 +198,14 @@ void sound(float freq, uint32_t len);
|
|||||||
void nosound();
|
void nosound();
|
||||||
void play(const char* str);
|
void play(const char* str);
|
||||||
|
|
||||||
void setmode(const uint8_t mode);
|
void mode(const uint8_t val);
|
||||||
void load(const char* str);
|
void load(const char* str);
|
||||||
|
|
||||||
void fileout(const char* str, uint16_t addr, uint16_t size);
|
void fileout(const char* str, uint16_t addr, uint16_t size);
|
||||||
void filein(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);
|
void toclipboard(const char* str);
|
||||||
const char* fromclipboard();
|
const char* fromclipboard();
|
||||||
|
|
||||||
|
uint32_t cnt();
|
||||||
|
void rst();
|
||||||
|
|||||||
BIN
chuleta_font.png
Normal file
BIN
chuleta_font.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
@@ -1,5 +1,5 @@
|
|||||||
function init()
|
function init()
|
||||||
setmode(1)
|
mode(1)
|
||||||
reset()
|
reset()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
function init()
|
function init()
|
||||||
setmode(1)
|
mode(1)
|
||||||
|
|
||||||
mountains = {}
|
mountains = {}
|
||||||
local val = 2
|
local val = 2
|
||||||
114
demos/lorenrunner.lua
Normal file
114
demos/lorenrunner.lua
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
score=0
|
||||||
|
lives=5
|
||||||
|
level=1
|
||||||
|
tresors=0
|
||||||
|
player = {x=0,y=0,oldtile=32,falling=false}
|
||||||
|
malos = {
|
||||||
|
{x=0,y=0},
|
||||||
|
{x=0,y=0},
|
||||||
|
{x=0,y=0}
|
||||||
|
}
|
||||||
|
eixida={x=0,y=0}
|
||||||
|
|
||||||
|
function init()
|
||||||
|
mode(2)
|
||||||
|
setchar(33,223,223,223,0,253,253,253,0)
|
||||||
|
setchar(34,255,255,255,255,255,255,255,0)
|
||||||
|
setchar(35,195,255,195,195,195,255,195,195)
|
||||||
|
setchar(36,195,243,195,195,195,207,195,195)
|
||||||
|
setchar(37,0,255,0,0,0,0,0,0)
|
||||||
|
setchar(38,0,0,0,126,66,66,126,0)
|
||||||
|
|
||||||
|
filein("level1.bin",0,600)
|
||||||
|
|
||||||
|
tresors=0
|
||||||
|
player.oldtile=32
|
||||||
|
local m=1
|
||||||
|
for i=0,299 do
|
||||||
|
if peek(i) == 248 then
|
||||||
|
poke(i,32)
|
||||||
|
player.x=i%20
|
||||||
|
player.y=flr(i/20)
|
||||||
|
elseif peek(i) == 249 then
|
||||||
|
poke(i,32)
|
||||||
|
poke(300+i, 0x0f)
|
||||||
|
malos[m].x=i%20
|
||||||
|
malos[m].y=flr(i/20)
|
||||||
|
elseif peek(i) == 36 then
|
||||||
|
poke(i,32)
|
||||||
|
poke(300+i, 0x0f)
|
||||||
|
eixida.x=i%20
|
||||||
|
eixida.y=flr(i/20)
|
||||||
|
elseif peek(i) == 38 then
|
||||||
|
tresors=tresors+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ink(COLOR_YELLOW) print("000000",7,14)
|
||||||
|
|
||||||
|
-- anem a contar els tresors que hi ha, per a saber quan es deu activar l'escala de eixida
|
||||||
|
end
|
||||||
|
|
||||||
|
function update()
|
||||||
|
if not player.falling then
|
||||||
|
if btnp(KEY_LEFT) and player.x>0 and peek(player.x-1+player.y*20)~=33 then
|
||||||
|
poke(player.x+player.y*20, player.oldtile)
|
||||||
|
player.x=player.x-1
|
||||||
|
player.oldtile = peek(player.x+player.y*20)
|
||||||
|
check_tresors()
|
||||||
|
elseif btnp(KEY_RIGHT) and player.x<19 and peek(player.x+1+player.y*20)~=33 then
|
||||||
|
poke(player.x+player.y*20, player.oldtile)
|
||||||
|
player.x=player.x+1
|
||||||
|
player.oldtile = peek(player.x+player.y*20)
|
||||||
|
check_tresors()
|
||||||
|
elseif btnp(KEY_UP) and player.oldtile==35 then
|
||||||
|
if player.y>0 then
|
||||||
|
poke(player.x+player.y*20, player.oldtile)
|
||||||
|
player.y=player.y-1
|
||||||
|
player.oldtile = peek(player.x+player.y*20)
|
||||||
|
else
|
||||||
|
-- endgame. Ja vorem, ara que faça el init de nou i au
|
||||||
|
init()
|
||||||
|
end
|
||||||
|
elseif btnp(KEY_DOWN) and (peek(player.x+(player.y+1)*20) == 35 or player.oldtile==37) then
|
||||||
|
poke(player.x+player.y*20, player.oldtile)
|
||||||
|
player.y=player.y+1
|
||||||
|
player.oldtile = peek(player.x+player.y*20)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if cnt()%5 == 0 then
|
||||||
|
if player.oldtile~=37 and (peek(player.x+(player.y+1)*20)==32 or peek(player.x+(player.y+1)*20)==38 or peek(player.x+(player.y+1)*20)==37) then
|
||||||
|
player.falling = true
|
||||||
|
poke(player.x+player.y*20, player.oldtile)
|
||||||
|
player.y=player.y+1
|
||||||
|
player.oldtile = peek(player.x+player.y*20)
|
||||||
|
check_tresors()
|
||||||
|
else
|
||||||
|
player.falling=false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
poke(player.x+player.y*20, 248)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function check_tresors()
|
||||||
|
if player.oldtile==38 then
|
||||||
|
player.oldtile=32
|
||||||
|
update_score(100)
|
||||||
|
poke(300+player.x+player.y*20, 0x0f)
|
||||||
|
tresors=tresors-1
|
||||||
|
if tresors==0 then
|
||||||
|
for i=eixida.y,0,-1 do
|
||||||
|
poke(eixida.x+i*20,35)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function update_score(points)
|
||||||
|
score=score+points
|
||||||
|
local str= ""..score
|
||||||
|
while #str < 6 do str = "0"..str end
|
||||||
|
ink(COLOR_YELLOW) print(str,7,14)
|
||||||
|
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
|
||||||
161
demos/old_sokoban.lua
Normal file
161
demos/old_sokoban.lua
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
FLOOR = 0
|
||||||
|
GOAL = 1
|
||||||
|
BOX = 2
|
||||||
|
PLAYER = 4
|
||||||
|
WALL = 7
|
||||||
|
|
||||||
|
function init()
|
||||||
|
mode(2)
|
||||||
|
level=1
|
||||||
|
player={}
|
||||||
|
menu.init()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ====================================================================================================
|
||||||
|
-- MENU (game state)
|
||||||
|
-- ====================================================================================================
|
||||||
|
blink=0
|
||||||
|
|
||||||
|
menu={
|
||||||
|
init = function()
|
||||||
|
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((blink%60)/30)) print("PRESS SPACE TO PLAY",1,9)
|
||||||
|
blink=blink+1
|
||||||
|
|
||||||
|
if btnp(KEY_SPACE) then
|
||||||
|
level=1
|
||||||
|
game.init()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
-- ====================================================================================================
|
||||||
|
-- GAME (game state)
|
||||||
|
-- ====================================================================================================
|
||||||
|
game={
|
||||||
|
init = function()
|
||||||
|
update=game.update
|
||||||
|
level.load_from_string("####|# .#|# ###|#*@ #|# $ #|# ###|####")
|
||||||
|
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
|
||||||
|
wait=120
|
||||||
|
end
|
||||||
|
|
||||||
|
function inbetween_update()
|
||||||
|
color(15,0)
|
||||||
|
cls()
|
||||||
|
print("LEVEL "..level,6,6)
|
||||||
|
print("GOOD JOB!",4,8)
|
||||||
|
wait=wait-1
|
||||||
|
if wait==0 then
|
||||||
|
level=level+1
|
||||||
|
game_init()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
function level_load_from_string(str)
|
||||||
|
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
|
||||||
|
|
||||||
|
function level_draw()
|
||||||
|
for y=1,#map do
|
||||||
|
for x=1,#map[y] do
|
||||||
|
if map[y][x] == WALL then color(4,15) print("\127",ox+x-1,oy+y-1)
|
||||||
|
elseif map[y][x] == BOX then color(0,6) print("\016",ox+x-1,oy+y-1)
|
||||||
|
elseif map[y][x] == BOX+GOAL then color(0,4) print("\016",ox+x-1,oy+y-1)
|
||||||
|
elseif map[y][x] == GOAL then color(4,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
|
||||||
|
|
||||||
|
function try_move(x,y)
|
||||||
|
if is_empty(x,y) then
|
||||||
|
move_player(x,y)
|
||||||
|
elseif is_box(x,y) and is_empty(x*2,y*2) then
|
||||||
|
move_box(x,y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function is_empty(x,y)
|
||||||
|
return map[player.y+y][player.x+x] < 2
|
||||||
|
end
|
||||||
|
|
||||||
|
function is_box(x,y)
|
||||||
|
return map[player.y+y][player.x+x] < 4
|
||||||
|
end
|
||||||
|
|
||||||
|
function move_player(x,y)
|
||||||
|
player.x=player.x+x
|
||||||
|
player.y=player.y+y
|
||||||
|
end
|
||||||
|
|
||||||
|
function move_box(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
|
||||||
|
move_player(x,y)
|
||||||
|
check_finished()
|
||||||
|
end
|
||||||
|
|
||||||
|
function check_finished()
|
||||||
|
for y=1,#map do
|
||||||
|
for x=1,#map[y] do
|
||||||
|
if map[y][x] == GOAL then return end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
inbetween_init()
|
||||||
|
end
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
function init()
|
function init()
|
||||||
setmode(1)
|
mode(1)
|
||||||
setchar(94, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
|
setchar(94, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
|
||||||
piano = { "_____", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^", "_____",
|
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", "^^^^^" }
|
"\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()
|
function init()
|
||||||
setmode(1)
|
mode(1)
|
||||||
current_piece = starting[rnd(7)+1]
|
current_piece = starting[rnd(7)+1]
|
||||||
next_piece = starting[rnd(7)+1]
|
next_piece = starting[rnd(7)+1]
|
||||||
|
|
||||||
|
|||||||
9
game.lua
9
game.lua
@@ -1,9 +0,0 @@
|
|||||||
function init()
|
|
||||||
setmode(0)
|
|
||||||
cls()
|
|
||||||
play("o4v5l1crcl4dcferl1crcl4dcgfr")
|
|
||||||
end
|
|
||||||
|
|
||||||
function update()
|
|
||||||
|
|
||||||
end
|
|
||||||
20
game.lua
Symbolic link
20
game.lua
Symbolic link
@@ -0,0 +1,20 @@
|
|||||||
|
function init()
|
||||||
|
mode(0)
|
||||||
|
cls()
|
||||||
|
play("o4v5l1crcl4dcferl1crcl4dcgfr")
|
||||||
|
end
|
||||||
|
|
||||||
|
function update()
|
||||||
|
cls()
|
||||||
|
locate(0,0)
|
||||||
|
if mousebutton(1) then
|
||||||
|
print("Has pulsat el boto esquerre")
|
||||||
|
elseif mousebutton(2) then
|
||||||
|
print("Has pulsat el boto del mig")
|
||||||
|
elseif mousebutton(3) then
|
||||||
|
print("Has pulsat el boto dret")
|
||||||
|
else
|
||||||
|
print("No has pulsat cap boto")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
21
lua.cpp
21
lua.cpp
@@ -348,9 +348,9 @@ extern "C" {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cpp_setmode(lua_State *L) {
|
static int cpp_mode(lua_State *L) {
|
||||||
int val = luaL_checkinteger(L, 1);
|
int val = luaL_checkinteger(L, 1);
|
||||||
setmode(mid(0,val,3));
|
mode(mid(0,val,3));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,6 +392,16 @@ extern "C" {
|
|||||||
lua_pushstring(L, fromclipboard());
|
lua_pushstring(L, fromclipboard());
|
||||||
return 1;
|
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
|
#define STATE_STOPPED 0
|
||||||
@@ -407,7 +417,7 @@ bool lua_is_playing() {
|
|||||||
return lua_state == STATE_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.6.1',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) {
|
void lua_init(const char* filename, const bool start_playing) {
|
||||||
if (lua_state != STATE_STOPPED) lua_quit();
|
if (lua_state != STATE_STOPPED) lua_quit();
|
||||||
@@ -476,7 +486,7 @@ void lua_init(const char* filename, const bool start_playing) {
|
|||||||
lua_pushcfunction(L,cpp_sound); lua_setglobal(L, "sound");
|
lua_pushcfunction(L,cpp_sound); lua_setglobal(L, "sound");
|
||||||
lua_pushcfunction(L,cpp_nosound); lua_setglobal(L, "nosound");
|
lua_pushcfunction(L,cpp_nosound); lua_setglobal(L, "nosound");
|
||||||
lua_pushcfunction(L,cpp_play); lua_setglobal(L, "play");
|
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_load); lua_setglobal(L, "load");
|
||||||
lua_pushcfunction(L,cpp_log); lua_setglobal(L, "log");
|
lua_pushcfunction(L,cpp_log); lua_setglobal(L, "log");
|
||||||
|
|
||||||
@@ -485,6 +495,9 @@ void lua_init(const char* filename, const bool start_playing) {
|
|||||||
lua_pushcfunction(L,cpp_toclipboard); lua_setglobal(L, "toclipboard");
|
lua_pushcfunction(L,cpp_toclipboard); lua_setglobal(L, "toclipboard");
|
||||||
lua_pushcfunction(L,cpp_fromclipboard); lua_setglobal(L, "fromclipboard");
|
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, 0); lua_setglobal(L, "KEY_UNKNOWN");
|
||||||
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");
|
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");
|
||||||
lua_pushinteger(L, 5); lua_setglobal(L, "KEY_B");
|
lua_pushinteger(L, 5); lua_setglobal(L, "KEY_B");
|
||||||
|
|||||||
160
main.cpp
160
main.cpp
@@ -57,7 +57,7 @@ uint8_t get_char(uint8_t key) {
|
|||||||
else if (key == KEY_4) { if (mods & KMOD_SHIFT) { return '$'; } else if (mods & KMOD_RALT) { return '~'; } else { return '4'; } }
|
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_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_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_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_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_9) { if (mods & KMOD_SHIFT) { return ')'; } else { return '9'; } }
|
||||||
else if (key == KEY_SPACE) return 32;
|
else if (key == KEY_SPACE) return 32;
|
||||||
@@ -79,7 +79,7 @@ uint8_t get_char(uint8_t key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_terminal() {
|
void init_terminal() {
|
||||||
setmode(0);
|
mode(0);
|
||||||
cls();
|
cls();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,139 +138,23 @@ void load_code() {
|
|||||||
std::list<std::string>::iterator ls[28];
|
std::list<std::string>::iterator ls[28];
|
||||||
static int col = 0;
|
static int col = 0;
|
||||||
static int line = 0;
|
static int line = 0;
|
||||||
bool cursor_inverted = false;
|
|
||||||
int blink_wait = 30;
|
|
||||||
|
|
||||||
#define PARSER_NOTHING 0
|
|
||||||
#define PARSER_NUMBER 1
|
|
||||||
#define PARSER_IDENTIFIER 2
|
|
||||||
#define PARSER_STRING 3
|
|
||||||
#define PARSER_COMMENT 4
|
|
||||||
#define PARSER_FUNCTION 5
|
|
||||||
|
|
||||||
uint16_t parser_offset = 0;
|
|
||||||
uint8_t parser_pos = 0;
|
|
||||||
uint8_t parser_start=0;
|
|
||||||
void parser_setup(uint16_t address) {
|
|
||||||
parser_offset = address;
|
|
||||||
parser_pos = 0;
|
|
||||||
parser_start = 0;
|
|
||||||
}
|
|
||||||
const uint8_t parser_get_char(uint8_t offset=0) {
|
|
||||||
if ((parser_pos+offset) >= 80) return 0;
|
|
||||||
return peek(parser_offset+parser_pos+offset);
|
|
||||||
}
|
|
||||||
char alpha[80] = "";
|
|
||||||
uint8_t alpha_pos = 0;
|
|
||||||
void parser_next(const bool keep=false) {
|
|
||||||
if (keep) { alpha[alpha_pos++] = parser_get_char(); alpha[alpha_pos]=0; } else { alpha[0]=alpha_pos=0; }
|
|
||||||
if (parser_pos < 80) parser_pos++;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ISZERO (parser_get_char()=='0')
|
|
||||||
#define ISX (parser_get_char()=='z' || parser_get_char()=='Z')
|
|
||||||
#define ISDIGIT (parser_get_char()>='0' && parser_get_char() <='9')
|
|
||||||
#define WILLBEDIGIT (parser_get_char(1)>='0' && parser_get_char(1) <='9')
|
|
||||||
#define ISPOINT (parser_get_char()=='.')
|
|
||||||
#define ISALPHA (parser_get_char()>='_' || (parser_get_char()>='a' && parser_get_char()<='z') || (parser_get_char()>='A' && parser_get_char()<='Z'))
|
|
||||||
#define ISQUOTES (parser_get_char()=='"' || parser_get_char()=='\'')
|
|
||||||
#define ISMINUS (parser_get_char()=='-')
|
|
||||||
#define WILLBEMINUS (parser_get_char(1)=='-')
|
|
||||||
#define ISPAREN (parser_get_char()=='(')
|
|
||||||
#define ENDED (parser_get_char()==0)
|
|
||||||
|
|
||||||
const char* keywords[] = { "and", "break", "do", "else", "elseif", "end", "false", "for", "function", "goto", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while" };
|
|
||||||
|
|
||||||
const bool is_keyword() {
|
|
||||||
for (int i=0;i<22;++i) if (strcmp(alpha, keywords[i]) == 0) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void parser_do_color(uint8_t type) {
|
|
||||||
uint8_t color = COLOR_WHITE;
|
|
||||||
switch (type) {
|
|
||||||
case PARSER_NUMBER: color = COLOR_LIGHT_GREEN; break;
|
|
||||||
case PARSER_COMMENT: color = COLOR_LIGHT_GRAY; break;
|
|
||||||
case PARSER_STRING: color = COLOR_RED; break;
|
|
||||||
case PARSER_IDENTIFIER: if (is_keyword()) color = COLOR_MAGENTA; break;
|
|
||||||
case PARSER_FUNCTION: color = COLOR_YELLOW; break;
|
|
||||||
};
|
|
||||||
color = (color&0x0f)+(0x10);
|
|
||||||
for (int i=parser_start;i<parser_pos;++i) poke(0x1200+parser_offset+i, color);
|
|
||||||
parser_start = parser_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
void refresh_line_color(uint8_t line) {
|
|
||||||
parser_setup(80*(line+1));
|
|
||||||
while (!ENDED) {
|
|
||||||
uint8_t result = PARSER_NOTHING;
|
|
||||||
if (ISZERO) {
|
|
||||||
result=PARSER_NUMBER; parser_next();
|
|
||||||
if (ISX) {
|
|
||||||
if (WILLBEDIGIT) {
|
|
||||||
parser_next();
|
|
||||||
while (ISDIGIT) parser_next();
|
|
||||||
}
|
|
||||||
} else if (ISDIGIT) {
|
|
||||||
while (ISDIGIT) parser_next();
|
|
||||||
if (ISPOINT) {
|
|
||||||
parser_next();
|
|
||||||
while (ISDIGIT) parser_next();
|
|
||||||
}
|
|
||||||
} else if (ISPOINT) {
|
|
||||||
parser_next();
|
|
||||||
while (ISDIGIT) parser_next();
|
|
||||||
}
|
|
||||||
} else if (ISDIGIT) {
|
|
||||||
result = PARSER_NUMBER;
|
|
||||||
while (ISDIGIT) parser_next();
|
|
||||||
if (ISPOINT) {
|
|
||||||
parser_next();
|
|
||||||
while (ISDIGIT) parser_next();
|
|
||||||
}
|
|
||||||
} else if (ISALPHA) {
|
|
||||||
result = PARSER_IDENTIFIER;
|
|
||||||
while (ISALPHA || ISDIGIT) parser_next(true);
|
|
||||||
if (ISPAREN) result = PARSER_FUNCTION;
|
|
||||||
} else if (ISQUOTES) {
|
|
||||||
result = PARSER_STRING; parser_next();
|
|
||||||
while (!ISQUOTES && !ENDED) parser_next();
|
|
||||||
parser_next();
|
|
||||||
} else if (ISMINUS) {
|
|
||||||
if (WILLBEMINUS) {
|
|
||||||
result = PARSER_COMMENT;
|
|
||||||
while (!ENDED) parser_next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result == PARSER_NOTHING) parser_next();
|
|
||||||
parser_do_color(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void refresh_color_highlight() {
|
|
||||||
cursor_inverted = false;
|
|
||||||
for (int i=0;i<28;++i) refresh_line_color(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void refresh_code_editor() {
|
void refresh_code_editor() {
|
||||||
color(COLOR_WHITE, COLOR_BLUE);
|
color(COLOR_WHITE, COLOR_BLUE);
|
||||||
cls();
|
cls();
|
||||||
color(COLOR_BLACK, COLOR_LIGHT_GRAY);
|
//print(" File Edit Run ",0,0);
|
||||||
print(" File Edit Run ",0,0);
|
//print(" ",0,29);
|
||||||
print(" ",0,29);
|
|
||||||
color(COLOR_WHITE, COLOR_BLUE);
|
|
||||||
std::list<std::string>::iterator it = code.begin();
|
std::list<std::string>::iterator it = code.begin();
|
||||||
int i=0;
|
int i=0;
|
||||||
while (it != code.end() && i<28) {
|
while (it != code.end() && i<28) {
|
||||||
ls[i] = it;
|
ls[i] = it;
|
||||||
print((*it).c_str(), 0, i+1);
|
print((*it).c_str(), 0, i);
|
||||||
++i; ++it;
|
++i; ++it;
|
||||||
}
|
}
|
||||||
refresh_color_highlight();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_code_editor() {
|
void init_code_editor() {
|
||||||
setmode(3);
|
mode(0);
|
||||||
code.clear();
|
code.clear();
|
||||||
load_code();
|
load_code();
|
||||||
refresh_code_editor();
|
refresh_code_editor();
|
||||||
@@ -280,36 +164,23 @@ std::string get_current_line() {
|
|||||||
return *ls[line];
|
return *ls[line];
|
||||||
}
|
}
|
||||||
|
|
||||||
void invert_cursor() {
|
|
||||||
cursor_inverted = !cursor_inverted;
|
|
||||||
uint16_t pos = 0x1200 + col + (line+1)*80;
|
|
||||||
uint8_t col = peek(pos);
|
|
||||||
poke(pos, ((col >> 4) & 0x0f) + ((col << 4) & 0xf0) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void move_cursor_up() {
|
void move_cursor_up() {
|
||||||
if (line > 0) {
|
if (line > 0) {
|
||||||
if (cursor_inverted) invert_cursor();
|
|
||||||
line--;
|
line--;
|
||||||
if (get_current_line().size() < col) col = get_current_line().size();
|
if (get_current_line().size() < col) col = get_current_line().size();
|
||||||
blink_wait=1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_cursor_down() {
|
void move_cursor_down() {
|
||||||
if (line < code.size()-1) {
|
if (line < code.size()-1) {
|
||||||
if (cursor_inverted) invert_cursor();
|
|
||||||
line++;
|
line++;
|
||||||
if (get_current_line().size() < col) col = get_current_line().size();
|
if (get_current_line().size() < col) col = get_current_line().size();
|
||||||
blink_wait=1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_cursor_right() {
|
void move_cursor_right() {
|
||||||
if ( col < get_current_line().size() ) {
|
if ( col < get_current_line().size() ) {
|
||||||
if (cursor_inverted) invert_cursor();
|
|
||||||
col++;
|
col++;
|
||||||
blink_wait=1;
|
|
||||||
} else {
|
} else {
|
||||||
if (line < code.size()-1) {
|
if (line < code.size()-1) {
|
||||||
col = 0;
|
col = 0;
|
||||||
@@ -320,9 +191,7 @@ void move_cursor_right() {
|
|||||||
|
|
||||||
void move_cursor_left() {
|
void move_cursor_left() {
|
||||||
if (col > 0) {
|
if (col > 0) {
|
||||||
if (cursor_inverted) invert_cursor();
|
|
||||||
col--;
|
col--;
|
||||||
blink_wait=1;
|
|
||||||
} else {
|
} else {
|
||||||
if (line > 0) {
|
if (line > 0) {
|
||||||
move_cursor_up();
|
move_cursor_up();
|
||||||
@@ -332,15 +201,11 @@ void move_cursor_left() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void move_line_end() {
|
void move_line_end() {
|
||||||
if (cursor_inverted) invert_cursor();
|
|
||||||
col = get_current_line().size();
|
col = get_current_line().size();
|
||||||
blink_wait=1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_line_home() {
|
void move_line_home() {
|
||||||
if (cursor_inverted) invert_cursor();
|
|
||||||
col = 0;
|
col = 0;
|
||||||
blink_wait=1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void split_line() {
|
void split_line() {
|
||||||
@@ -349,14 +214,11 @@ void split_line() {
|
|||||||
std::list<std::string>::iterator newline = ls[line]++;
|
std::list<std::string>::iterator newline = ls[line]++;
|
||||||
code.insert(newline, str.substr(0, col));
|
code.insert(newline, str.substr(0, col));
|
||||||
|
|
||||||
if (cursor_inverted) invert_cursor();
|
|
||||||
line++; col=0;
|
line++; col=0;
|
||||||
blink_wait=1;
|
|
||||||
refresh_code_editor();
|
refresh_code_editor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void join_lines() {
|
void join_lines() {
|
||||||
if (cursor_inverted) invert_cursor();
|
|
||||||
std::string str = get_current_line();
|
std::string str = get_current_line();
|
||||||
//std::list<std::string>::iterator prevline = ls[line]--;
|
//std::list<std::string>::iterator prevline = ls[line]--;
|
||||||
code.erase(ls[line]);
|
code.erase(ls[line]);
|
||||||
@@ -364,7 +226,6 @@ void join_lines() {
|
|||||||
const int line_size = (*ls[line]).size();
|
const int line_size = (*ls[line]).size();
|
||||||
*ls[line] += str;
|
*ls[line] += str;
|
||||||
col = line_size;
|
col = line_size;
|
||||||
blink_wait=1;
|
|
||||||
refresh_code_editor();
|
refresh_code_editor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,13 +233,11 @@ void delete_char() {
|
|||||||
if (col == 0) {
|
if (col == 0) {
|
||||||
if (line > 0) join_lines();
|
if (line > 0) join_lines();
|
||||||
} else {
|
} else {
|
||||||
if (cursor_inverted) invert_cursor();
|
|
||||||
std::string str = get_current_line();
|
std::string str = get_current_line();
|
||||||
std::string a = str.substr(0,col-1);
|
std::string a = str.substr(0,col-1);
|
||||||
std::string b = str.substr(col);
|
std::string b = str.substr(col);
|
||||||
*ls[line] = a+b;
|
*ls[line] = a+b;
|
||||||
col--;
|
col--;
|
||||||
blink_wait=1;
|
|
||||||
refresh_code_editor();
|
refresh_code_editor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,7 +255,6 @@ void add_char(uint8_t chr) {
|
|||||||
std::string c = " "; c[0] = chr;
|
std::string c = " "; c[0] = chr;
|
||||||
*ls[line] = a+c+b;
|
*ls[line] = a+c+b;
|
||||||
col++;
|
col++;
|
||||||
blink_wait=1;
|
|
||||||
refresh_code_editor();
|
refresh_code_editor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,9 +278,5 @@ void do_code_editor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blink_wait--;
|
debug_set_cursor(col, line);
|
||||||
if (blink_wait == 0) {
|
|
||||||
blink_wait = 30;
|
|
||||||
invert_cursor();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
1
scr.bin
Normal file
1
scr.bin
Normal file
@@ -0,0 +1 @@
|
|||||||
|
֏<><D68F><EFBFBD><EFBFBD>֏<EFBFBD><D68F><EFBFBD><EFBFBD>֏<EFBFBD><D68F><EFBFBD><EFBFBD>֏<EFBFBD>֏<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԏ<EFBFBD><D48F><EFBFBD><EFBFBD>ԏ<EFBFBD><D48F><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԏ<EFBFBD>ԏ<EFBFBD><D48F> <20><>ԏ<EFBFBD><D48F> <20><>ԏ<EFBFBD><D48F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֏<EFBFBD><D68F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԏ<EFBFBD>ԏ<EFBFBD><D48F><EFBFBD><EFBFBD><EFBFBD> <20><>ԏ<EFBFBD>ԏ<EFBFBD><D48F><EFBFBD><EFBFBD>ԏ<EFBFBD><D48F><EFBFBD><EFBFBD>ԏ<EFBFBD>ԏ<EFBFBD><D48F> G A M E S Y S T E M <07><07><07><01><07>x<08><><EFBFBD>xxxx<07>x<0F><><EFBFBD>xxxxxx<0F>xxx<07>x<0C> <0F>
|
||||||
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()
|
function init()
|
||||||
setmode(2)
|
mode(2)
|
||||||
map = {}
|
map = {}
|
||||||
col = {}
|
col = {}
|
||||||
for i=0,299 do
|
for i=0,299 do
|
||||||
map[i] = 32
|
map[i] = 32
|
||||||
col[i] = 0x0f
|
col[i] = 0x0f
|
||||||
end
|
end
|
||||||
map[ind] = 65
|
|
||||||
sel_col = 0x0f
|
sel_col = 0x0f
|
||||||
sel_chr = 65
|
sel_chr = 65
|
||||||
end
|
end
|
||||||
@@ -76,10 +74,17 @@ function draw_map()
|
|||||||
map[mx+my*20] = sel_chr
|
map[mx+my*20] = sel_chr
|
||||||
col[mx+my*20] = sel_col
|
col[mx+my*20] = sel_col
|
||||||
end
|
end
|
||||||
|
if mousebutton(3) then
|
||||||
|
col[mx+my*20] = sel_col
|
||||||
|
end
|
||||||
if btn(KEY_SPACE) then
|
if btn(KEY_SPACE) then
|
||||||
sel_chr = peek(mx+my*20)
|
sel_chr = peek(mx+my*20)
|
||||||
sel_col = peek(300+mx+my*20)
|
sel_col = peek(300+mx+my*20)
|
||||||
end
|
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
|
blink = blink - 1
|
||||||
if blink < 30 then
|
if blink < 30 then
|
||||||
@@ -88,4 +93,15 @@ function draw_map()
|
|||||||
local c = peek(300+(mx+my*20))
|
local c = peek(300+(mx+my*20))
|
||||||
poke(300+(mx+my*20), c~0xff)
|
poke(300+(mx+my*20), c~0xff)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
101
tools/music.lua
101
tools/music.lua
@@ -1,16 +1,21 @@
|
|||||||
function init()
|
function init()
|
||||||
setmode(1)
|
mode(1)
|
||||||
setchar(94, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
|
setchar(94, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
|
||||||
piano = { "_____", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^", "_____",
|
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", "^^^^^" }
|
"\143\143\143\154\154", " ", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^" }
|
||||||
notes = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B "}
|
notes = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B "}
|
||||||
pnotes = {"c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"}
|
pnotes = {"c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"}
|
||||||
|
vcolor = { 1, 9, 5, 4, 6, 12, 14, 15}
|
||||||
|
|
||||||
piano_pos=18
|
piano_pos=18
|
||||||
mousewait=0
|
mousewait=0
|
||||||
compas = 0
|
compas = 0
|
||||||
compasos = {}
|
compasos = {}
|
||||||
|
volumens = {}
|
||||||
|
volum = 4
|
||||||
|
tempo = 4
|
||||||
for i=0,1279 do compasos[i] = 108 end
|
for i=0,1279 do compasos[i] = 108 end
|
||||||
|
for i=0,1279 do volumens[i] = 4 end
|
||||||
compasos[0] = 49
|
compasos[0] = 49
|
||||||
compasos[1] = 49
|
compasos[1] = 49
|
||||||
compasos[2] = 49
|
compasos[2] = 49
|
||||||
@@ -20,6 +25,8 @@ function init()
|
|||||||
compasos[10] = 50
|
compasos[10] = 50
|
||||||
|
|
||||||
old_mouse_x,old_mouse_y = 0,0
|
old_mouse_x,old_mouse_y = 0,0
|
||||||
|
message_count = 255
|
||||||
|
message_text = " HOLA"
|
||||||
end
|
end
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
@@ -72,7 +79,7 @@ function update()
|
|||||||
color(COLOR_BLACK, COLOR_LIGHT_GRAY+flr(oct%2))
|
color(COLOR_BLACK, COLOR_LIGHT_GRAY+flr(oct%2))
|
||||||
print("\003",7+i,10+11-(n-piano_pos))
|
print("\003",7+i,10+11-(n-piano_pos))
|
||||||
end
|
end
|
||||||
color(COLOR_BLACK,COLOR_LIGHT_RED)
|
color(COLOR_BLACK,vcolor[volumens[(compas*32)+i]])
|
||||||
if i==31 or compasos[(compas*32)+i+1]~=n then
|
if i==31 or compasos[(compas*32)+i+1]~=n then
|
||||||
print("\003",8+i,10+11-(n-piano_pos))
|
print("\003",8+i,10+11-(n-piano_pos))
|
||||||
else
|
else
|
||||||
@@ -83,10 +90,11 @@ function update()
|
|||||||
|
|
||||||
if mousex()>=8 and mousey()>=10 and mousey()<=21 then
|
if mousex()>=8 and mousey()>=10 and mousey()<=21 then
|
||||||
if mousebutton(1) then
|
if mousebutton(1) then
|
||||||
|
volumens[(compas*32)+mousex()-8] = volum
|
||||||
compasos[(compas*32)+mousex()-8] = piano_pos+11-(mousey()-10)
|
compasos[(compas*32)+mousex()-8] = piano_pos+11-(mousey()-10)
|
||||||
if old_mouse_x ~= mousex() or old_mouse_y ~= mousey() then
|
if old_mouse_x ~= mousex() or old_mouse_y ~= mousey() then
|
||||||
local note = piano_pos+11-(mousey()-10)
|
local note = piano_pos+11-(mousey()-10)
|
||||||
play("l4o"..tostr(note/12)..pnotes[(note%12)+1])
|
play("l4v"..volum.."o"..tostr(note/12)..pnotes[(note%12)+1])
|
||||||
end
|
end
|
||||||
old_mouse_x,old_mouse_y = mousex(),mousey()
|
old_mouse_x,old_mouse_y = mousex(),mousey()
|
||||||
else
|
else
|
||||||
@@ -105,16 +113,64 @@ function update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
color(15,0)print("\143",0,0)
|
if btn(KEY_LCTRL) and btnp(KEY_S) then
|
||||||
color(14,0)print("\143",1,0)
|
local song = prepare_song(true)
|
||||||
color(12,0)print("\143",2,0)
|
toclipboard(song)
|
||||||
color(6,0)print("\143",3,0)
|
show_message("SAVED TO CLIPBOARD")
|
||||||
color(4,0)print("\143",4,0)
|
end
|
||||||
color(5,4)print("\143",5,0)
|
|
||||||
color(9,0)print("\143",6,0)
|
|
||||||
color(1,0)print("\143",7,0)
|
|
||||||
color(0,0)print("\143",8,0)
|
|
||||||
|
|
||||||
|
-- if btn(KEY_LSHIFT) and btnp(KEY_L) then
|
||||||
|
-- local song = prepare_song(true)
|
||||||
|
-- toclipboard(song)
|
||||||
|
-- show_message("SAVED TO CLIPBOARD")
|
||||||
|
-- end
|
||||||
|
|
||||||
|
color(15,0)print("VOLUM:",0,0)
|
||||||
|
color(1,0)print("\143",0,1)
|
||||||
|
color(9,0)print("\143",1,1)
|
||||||
|
color(5,4)print("\143",2,1)
|
||||||
|
color(4,0)print("\143",3,1)
|
||||||
|
color(6,0)print("\143",4,1)
|
||||||
|
color(12,0)print("\143",5,1)
|
||||||
|
color(14,0)print("\143",6,1)
|
||||||
|
color(15,0)print("\143",7,1)
|
||||||
|
color(15,0)print("\244",volum-1,2)
|
||||||
|
|
||||||
|
if mousex()<8 and mousey()==1 and mousebutton(1) then
|
||||||
|
volum = mousex()+1
|
||||||
|
end
|
||||||
|
|
||||||
|
if not mousedown and mousex()==20 and mousey()==1 and mousebutton(1) and tempo > 0 then
|
||||||
|
tempo = tempo - 1
|
||||||
|
mousedown = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if not mousedown and mousex()==24 and mousey()==1 and mousebutton(1) and tempo < 9 then
|
||||||
|
tempo = tempo + 1
|
||||||
|
mousedown = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if mousedown and not mousebutton(1) then
|
||||||
|
mousedown = false
|
||||||
|
end
|
||||||
|
|
||||||
|
color(15,0)print("TEMPO",20,0)
|
||||||
|
print("\247 0 \246",20,1)
|
||||||
|
print(tostr(tempo),22,1)
|
||||||
|
|
||||||
|
if message_count > 0 then
|
||||||
|
message_color = 15
|
||||||
|
if message_count < 18 then
|
||||||
|
message_color = message_count>>1
|
||||||
|
end
|
||||||
|
color(message_color,0)print(message_text,0,26)
|
||||||
|
message_count = message_count - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function show_message(text)
|
||||||
|
message_count = 255
|
||||||
|
message_text = text
|
||||||
end
|
end
|
||||||
|
|
||||||
function search_song_end()
|
function search_song_end()
|
||||||
@@ -124,6 +180,12 @@ function search_song_end()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function play_song(entire_song)
|
function play_song(entire_song)
|
||||||
|
local song = prepare_song(entire_song)
|
||||||
|
log(song)
|
||||||
|
play(song)
|
||||||
|
end
|
||||||
|
|
||||||
|
function prepare_song(entire_song)
|
||||||
entire_song = entire_song or false
|
entire_song = entire_song or false
|
||||||
local note_size = {1,2,3,4,6,8,12,16,24,32}
|
local note_size = {1,2,3,4,6,8,12,16,24,32}
|
||||||
local note_names = {"c","c#","d", "d#","e","f","f#","g","g#","a","a#","b"}
|
local note_names = {"c","c#","d", "d#","e","f","f#","g","g#","a","a#","b"}
|
||||||
@@ -131,10 +193,15 @@ function play_song(entire_song)
|
|||||||
|
|
||||||
local current_note = 255
|
local current_note = 255
|
||||||
local current_octave = 4
|
local current_octave = 4
|
||||||
|
local current_volume = 4
|
||||||
|
|
||||||
local p=compas*32
|
local p=compas*32
|
||||||
local ends=32+compas*32
|
local ends=32+compas*32
|
||||||
|
|
||||||
|
if tempo ~= 4 then
|
||||||
|
song = "t"..tostr(tempo)
|
||||||
|
end
|
||||||
|
|
||||||
if entire_song then
|
if entire_song then
|
||||||
p=0
|
p=0
|
||||||
ends=search_song_end()
|
ends=search_song_end()
|
||||||
@@ -142,8 +209,12 @@ function play_song(entire_song)
|
|||||||
|
|
||||||
while p<ends do
|
while p<ends do
|
||||||
current_note = compasos[p]
|
current_note = compasos[p]
|
||||||
|
if volumens[p] ~= current_volume then
|
||||||
|
current_volume = volumens[p]
|
||||||
|
song=song.."v"..tostr(current_volume)
|
||||||
|
end
|
||||||
local d=0
|
local d=0
|
||||||
while d<32 and current_note == compasos[p] do d=d+1 p=p+1 end
|
while d<32 and current_note == compasos[p] and current_volume == volumens[p] do d=d+1 p=p+1 end
|
||||||
local o = flr(current_note/12)
|
local o = flr(current_note/12)
|
||||||
if o<9 and current_octave~=o then
|
if o<9 and current_octave~=o then
|
||||||
current_octave=o
|
current_octave=o
|
||||||
@@ -167,6 +238,6 @@ function play_song(entire_song)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
log(song)
|
|
||||||
play(song)
|
return song
|
||||||
end
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
ind = 22
|
ind = 22
|
||||||
function init()
|
function init()
|
||||||
setmode(1)
|
mode(1)
|
||||||
map = {}
|
map = {}
|
||||||
col = {}
|
col = {}
|
||||||
for i=0,1199 do
|
for i=0,1199 do
|
||||||
@@ -85,6 +85,11 @@ function draw_map()
|
|||||||
sel_col = peek(1200+mx+my*40)
|
sel_col = peek(1200+mx+my*40)
|
||||||
end
|
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
|
blink = blink - 1
|
||||||
if blink < 30 then
|
if blink < 30 then
|
||||||
if blink==0 then blink = 60 end
|
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