Compare commits
22 Commits
fa85d3cb34
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9db783b3ac | |||
| 2dcbdfa975 | |||
| 709a74a76a | |||
| b2a96309e5 | |||
| b0446f40a1 | |||
| 3b4501aaec | |||
| fca1172162 | |||
| 9d2a0801e1 | |||
| 41f539578a | |||
| dd7e3de890 | |||
| 785a51ac98 | |||
| 9ed4118250 | |||
| 5c0758354c | |||
| 3abd22f150 | |||
| cde75e2557 | |||
| 4733a66fc0 | |||
| b3f59e9175 | |||
| ffb4875605 | |||
| 50842cf9c9 | |||
| 61f3c385c0 | |||
| af3b04f0ab | |||
| b09360d7ae |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@ scr_min.c
|
|||||||
tests.lua
|
tests.lua
|
||||||
fake_editor.lua
|
fake_editor.lua
|
||||||
*.bin
|
*.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"
|
||||||
22
ascii.cpp
22
ascii.cpp
@@ -198,6 +198,8 @@ 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;
|
||||||
@@ -210,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()) {
|
||||||
@@ -254,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();
|
||||||
}
|
}
|
||||||
@@ -266,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);
|
||||||
@@ -581,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];
|
||||||
}
|
}
|
||||||
|
|||||||
1
ascii.h
1
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);
|
||||||
|
|||||||
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
|
||||||
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
|
||||||
31
game.lua
31
game.lua
@@ -1,9 +1,34 @@
|
|||||||
|
Persona = {
|
||||||
|
name = "---",
|
||||||
|
}
|
||||||
|
|
||||||
|
function Persona:SayName()
|
||||||
|
print(self.name .. " ")
|
||||||
|
end
|
||||||
|
|
||||||
|
function Persona:new(obj)
|
||||||
|
obj = obj or {}
|
||||||
|
setmetatable(obj, self)
|
||||||
|
--self.__index = self
|
||||||
|
return obj
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
setmode(0)
|
mode(0)
|
||||||
cls()
|
cls()
|
||||||
play("o4v5l1crcl4dcferl1crcl4dcgfr")
|
Persona.__index=Persona
|
||||||
|
persones={}
|
||||||
|
persones[1] = Persona:new({name="Persona1"})
|
||||||
|
persones[2] = Persona:new({name="Persona2"})
|
||||||
|
persones[3] = Persona:new({name="Persona3"})
|
||||||
|
persones[4] = Persona:new({name="Persona4"})
|
||||||
|
|
||||||
|
for i,v in ipairs(persones) do
|
||||||
|
v:SayName()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
|
|
||||||
end
|
end
|
||||||
3
lua.cpp
3
lua.cpp
@@ -417,11 +417,12 @@ bool lua_is_playing() {
|
|||||||
return lua_state == STATE_PLAYING;
|
return lua_state == STATE_PLAYING;
|
||||||
}
|
}
|
||||||
|
|
||||||
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";
|
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();
|
||||||
L = luaL_newstate();
|
L = luaL_newstate();
|
||||||
|
luaL_openlibs(L);
|
||||||
//init_exists = update_exists = false;
|
//init_exists = update_exists = false;
|
||||||
bool file_loaded = true;
|
bool file_loaded = true;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
|
|
||||||
//extern "C" {
|
//extern "C" {
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
//#include "lualib.h"
|
#include "lualib.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
//}
|
//}
|
||||||
|
|||||||
215
main.cpp
215
main.cpp
@@ -3,15 +3,41 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
std::list<std::string> code;
|
||||||
|
|
||||||
|
int current_editor = 0;
|
||||||
|
|
||||||
void init_terminal();
|
void init_terminal();
|
||||||
void do_terminal();
|
void do_terminal();
|
||||||
|
|
||||||
|
void init_code_editor();
|
||||||
|
void do_code_editor();
|
||||||
|
void save_code();
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
do_terminal();
|
if (btnp(KEY_TAB)) {
|
||||||
|
current_editor = (++current_editor)%2;
|
||||||
|
switch(current_editor) {
|
||||||
|
case 0:
|
||||||
|
init_terminal();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
init_code_editor();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch(current_editor) {
|
||||||
|
case 0:
|
||||||
|
do_terminal();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
do_code_editor();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void execute_run() {
|
void execute_run() {
|
||||||
//if (current_editor == 1) save_code();
|
if (current_editor == 1) save_code();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t get_char(uint8_t key) {
|
uint8_t get_char(uint8_t key) {
|
||||||
@@ -31,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;
|
||||||
@@ -71,3 +97,186 @@ void do_terminal() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void save_code() {
|
||||||
|
const char* file = get_filename();
|
||||||
|
FILE *f = fopen(file, "w");
|
||||||
|
for (std::list<std::string>::iterator it = code.begin(); it != code.end(); it++) {
|
||||||
|
fprintf(f, "%s\n", (*it).c_str());
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_code() {
|
||||||
|
const char* file = get_filename();
|
||||||
|
FILE *f = fopen(file, "rb");
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
long fsize = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET); /* same as rewind(f); */
|
||||||
|
char *buffer = (char*)malloc(fsize + 1);
|
||||||
|
fread(buffer, 1, fsize, f);
|
||||||
|
fclose(f);
|
||||||
|
buffer[fsize] = 0;
|
||||||
|
|
||||||
|
int start = 0;
|
||||||
|
for (int pos=0;pos<fsize;++pos) {
|
||||||
|
if (buffer[pos] == '\n') {
|
||||||
|
buffer[pos]='\0';
|
||||||
|
code.push_back(&buffer[start]);
|
||||||
|
start=pos+1;
|
||||||
|
} else if (buffer[pos] == '\r') {
|
||||||
|
buffer[pos]='\0';
|
||||||
|
code.push_back(&buffer[start]);
|
||||||
|
start=pos+1;
|
||||||
|
if (buffer[start] == '\n') {pos++; start++;}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<std::string>::iterator ls[28];
|
||||||
|
static int col = 0;
|
||||||
|
static int line = 0;
|
||||||
|
|
||||||
|
void refresh_code_editor() {
|
||||||
|
color(COLOR_WHITE, COLOR_BLUE);
|
||||||
|
cls();
|
||||||
|
//print(" File Edit Run ",0,0);
|
||||||
|
//print(" ",0,29);
|
||||||
|
std::list<std::string>::iterator it = code.begin();
|
||||||
|
int i=0;
|
||||||
|
while (it != code.end() && i<28) {
|
||||||
|
ls[i] = it;
|
||||||
|
print((*it).c_str(), 0, i);
|
||||||
|
++i; ++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_code_editor() {
|
||||||
|
mode(0);
|
||||||
|
code.clear();
|
||||||
|
load_code();
|
||||||
|
refresh_code_editor();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get_current_line() {
|
||||||
|
return *ls[line];
|
||||||
|
}
|
||||||
|
|
||||||
|
void move_cursor_up() {
|
||||||
|
if (line > 0) {
|
||||||
|
line--;
|
||||||
|
if (get_current_line().size() < col) col = get_current_line().size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void move_cursor_down() {
|
||||||
|
if (line < code.size()-1) {
|
||||||
|
line++;
|
||||||
|
if (get_current_line().size() < col) col = get_current_line().size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void move_cursor_right() {
|
||||||
|
if ( col < get_current_line().size() ) {
|
||||||
|
col++;
|
||||||
|
} else {
|
||||||
|
if (line < code.size()-1) {
|
||||||
|
col = 0;
|
||||||
|
move_cursor_down();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void move_cursor_left() {
|
||||||
|
if (col > 0) {
|
||||||
|
col--;
|
||||||
|
} else {
|
||||||
|
if (line > 0) {
|
||||||
|
move_cursor_up();
|
||||||
|
col = get_current_line().size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void move_line_end() {
|
||||||
|
col = get_current_line().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void move_line_home() {
|
||||||
|
col = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void split_line() {
|
||||||
|
std::string str = get_current_line();
|
||||||
|
*ls[line] = str.substr(col);
|
||||||
|
std::list<std::string>::iterator newline = ls[line]++;
|
||||||
|
code.insert(newline, str.substr(0, col));
|
||||||
|
|
||||||
|
line++; col=0;
|
||||||
|
refresh_code_editor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void join_lines() {
|
||||||
|
std::string str = get_current_line();
|
||||||
|
//std::list<std::string>::iterator prevline = ls[line]--;
|
||||||
|
code.erase(ls[line]);
|
||||||
|
line--;
|
||||||
|
const int line_size = (*ls[line]).size();
|
||||||
|
*ls[line] += str;
|
||||||
|
col = line_size;
|
||||||
|
refresh_code_editor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete_char() {
|
||||||
|
if (col == 0) {
|
||||||
|
if (line > 0) join_lines();
|
||||||
|
} else {
|
||||||
|
std::string str = get_current_line();
|
||||||
|
std::string a = str.substr(0,col-1);
|
||||||
|
std::string b = str.substr(col);
|
||||||
|
*ls[line] = a+b;
|
||||||
|
col--;
|
||||||
|
refresh_code_editor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void supr_char() {
|
||||||
|
if ((col == (*ls[line]).size()) && (line == code.size()-1)) return;
|
||||||
|
move_cursor_right();
|
||||||
|
delete_char();
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_char(uint8_t chr) {
|
||||||
|
std::string str = get_current_line();
|
||||||
|
std::string a = str.substr(0,col);
|
||||||
|
std::string b = str.substr(col);
|
||||||
|
std::string c = " "; c[0] = chr;
|
||||||
|
*ls[line] = a+c+b;
|
||||||
|
col++;
|
||||||
|
refresh_code_editor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_code_editor() {
|
||||||
|
const uint8_t key = whichbtn();
|
||||||
|
if (key != KEY_UNKNOWN) {
|
||||||
|
if (key == KEY_RETURN or key == KEY_KP_ENTER) {
|
||||||
|
split_line();
|
||||||
|
}
|
||||||
|
else if (key == KEY_UP) move_cursor_up();
|
||||||
|
else if (key == KEY_DOWN) move_cursor_down();
|
||||||
|
else if (key == KEY_LEFT) move_cursor_left();
|
||||||
|
else if (key == KEY_RIGHT) move_cursor_right();
|
||||||
|
else if (key == KEY_BACKSPACE) delete_char();
|
||||||
|
else if (key == KEY_DELETE) supr_char();
|
||||||
|
else if (key == KEY_END) move_line_end();
|
||||||
|
else if (key == KEY_HOME) move_line_home();
|
||||||
|
else {
|
||||||
|
uint8_t chr = get_char(key);
|
||||||
|
if (chr != 0) add_char(chr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug_set_cursor(col, line);
|
||||||
|
}
|
||||||
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>
|
||||||
@@ -5,12 +5,17 @@ function init()
|
|||||||
"\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
|
||||||
Reference in New Issue
Block a user