20 Commits

Author SHA1 Message Date
376c15c272 v0.5.4
[FEAT] Border
[FEAT] Color accepts a third optional parameter for border
2021-12-10 19:32:05 +01:00
f21f199917 [FEAT] Brackets enabled in console 2021-12-10 19:26:46 +01:00
12383f9309 [FEAT] Pong & Breakout included 2021-12-10 08:18:02 +01:00
d101da4a43 [BUG] volume, octave & tempo not reseting 2021-12-09 17:12:32 +01:00
d811790f66 [BUG] Versión not updated 2021-12-08 13:15:42 +01:00
77f31587f6 v0.5.2:
[FEAT] play(str)
[FEAT] Chime on boot
[FEAT] simple song example on 'game.lua'
2021-12-08 12:39:15 +01:00
66bbdea85f [BUG] memcpy minor bug
[FEAT] boot sequence
2021-12-08 09:18:42 +01:00
1a73164990 [CHANGE] Nou model de memòria 2021-12-08 07:47:39 +01:00
290d50e32f [FEAT] memcpy
[CHANGE] New default color 0x0f
2021-12-08 07:34:54 +01:00
963958e596 Merge branch 'master' of https://gitea.sustancia.synology.me/JailDoctor/ascii 2021-12-08 07:11:58 +01:00
806eeb04b5 Working on boot logo 2021-12-08 07:10:06 +01:00
6131607778 canvi de comp 2021-12-07 12:44:15 +01:00
21052edd3d [FEAT] Peek & Poke
[BUG] Mode not restored after ESC
2021-12-06 12:23:36 +01:00
69976ee9f6 [BUG]Mouse coordinates where incorrect 2021-12-05 20:26:22 +01:00
cf608cea78 Still working on the console... 2021-12-05 16:34:05 +01:00
fe9220bb39 Working on the terminal... 2021-12-05 10:16:37 +01:00
9e547e7292 algun fallo raro? 2021-12-04 17:45:46 +01:00
528261395b Working on console interaction... 2021-12-04 14:52:15 +01:00
8f06ad8dab [BUG] No compila en MacOS 2021-12-04 14:21:46 +01:00
7552136845 [FEAT] All screen modes implemented 2021-12-04 10:52:08 +01:00
15 changed files with 1027 additions and 121 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
ascii
.vscode/*
*.dll
wiki/*

358
ascii.cpp
View File

@@ -2,28 +2,40 @@
#include <stdio.h>
#include <string.h>
#include "lua.h"
#include "font.c"
#include "rom.c"
#include "play.h"
#define swap(a, b) {auto tmp=a;a=b;b=tmp;}
#define AUDIO_NONE 0
#define AUDIO_SOUND 1
#define AUDIO_PLAY 2
char lua_filename[1024];
char window_title[256];
uint8_t char_screen[1200];
uint8_t color_screen[1200];
uint8_t mem[8192]; //2400
uint8_t *char_screen = NULL;
uint8_t *color_screen = NULL;
uint8_t screen_width = 40;
uint8_t screen_height = 30;
uint8_t current_color = 0x1e;
uint8_t current_border = 0;
uint8_t current_mode = 1;
uint8_t cursor_x = 0;
uint8_t cursor_y = 0;
bool sounding = false;
uint8_t audio_state = AUDIO_NONE;
int audio_freq = 0;
uint32_t audio_len = 0;
#define CHRSCR(x, y) char_screen[x+y*screen_width]
#define COLSCR(x, y) color_screen[x+y*screen_width]
#define MEM_CHAR_OFFSET 2560
#define MEM_BOOT_OFFSET 4608
SDL_Window *mini_win;
SDL_Renderer *mini_ren;
SDL_Texture *mini_bak;
SDL_Texture *mini_bak = NULL;
SDL_AudioDeviceID mini_audio_device;
Uint32 *pixels;
int pitch;
@@ -31,11 +43,14 @@ int pitch;
uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0000, 0x00AA00AA, 0x00AA5500, 0x00AAAAAA,
0x00555555, 0x005555FF, 0x0055FF55, 0x0055FFFF, 0x00FF5555, 0x00FF55FF, 0x00FFFF55, 0x00FFFFFF };
#define debug_line_size 40
#define debug_line_size 80
#define debug_num_lines 30
#define debug_total_size 1200 //debug_line_size*debug_num_lines
#define debug_total_size 2400 //debug_line_size*debug_num_lines
char debug_text[debug_total_size];
int debug_cursor = 0;
int debug_prompt = 0;
int debug_cursor_blink = 30;
bool should_reset = false;
//Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X };
const Uint8 *keys;
@@ -45,49 +60,124 @@ int mouse_x, mouse_y, mouse_wheel;
Uint32 mouse_buttons;
void reinit() {
screen_width = 40;
screen_height = 30;
current_color = 0x1e;
cursor_x = 0;
cursor_y = 0;
}
void audioCallback(void * userdata, uint8_t * stream, int len) {
//if (audio_len <= 0) nosound();
static int period=0;
static int v = 16;
SDL_memset(stream, 0, len);
const int flen = min(audio_len, len);
audio_len -= flen;
for (int i=0; i<flen; ++i) {
stream[i] = v;
period++; if (period>=audio_freq) {period = 0; v=-v;}
if (mini_bak != NULL) SDL_DestroyTexture(mini_bak);
switch (current_mode) {
case 0:
screen_width = 80;
screen_height = 30;
current_color = 0x07;
current_border = 0;
cursor_x = 0;
cursor_y = 0;
char_screen = &mem[0];
color_screen = &mem[1200];
//SDL_RenderSetLogicalSize(mini_ren, 640, 480);
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 640, 240);
break;
case 1:
screen_width = 40;
screen_height = 30;
current_color = 0x07;
current_border = 0;
cursor_x = 0;
cursor_y = 0;
char_screen = &mem[0];
color_screen = &mem[1200];
//SDL_RenderSetLogicalSize(mini_ren, 320, 240);
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 240);
break;
case 2:
screen_width = 20;
screen_height = 15;
current_color = 0x07;
current_border = 0;
cursor_x = 0;
cursor_y = 0;
char_screen = &mem[0];
color_screen = &mem[300];
//SDL_RenderSetLogicalSize(mini_ren, 160, 120);
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 160, 120);
break;
}
}
static Uint8* play_pos;
static Uint32 play_len;
static Uint8 play_buffer[132300];
void audioCallback(void * userdata, uint8_t * stream, int len) {
if (audio_state == AUDIO_SOUND) {
if (audio_len <= 0) audio_state = AUDIO_NONE;
static int period=0;
static int v = 16;
SDL_memset(stream, 0, len);
const int flen = min(audio_len, len);
audio_len -= flen;
for (int i=0; i<flen; ++i) {
stream[i] = v;
period++; if (period>=audio_freq) {period = 0; v=-v;}
}
} else if (audio_state == AUDIO_PLAY) {
while( len > 0 ) {
while( play_len == 0 ) {
play_len = interpret_next_token(play_buffer);
if (play_len == -1) { audio_state=AUDIO_NONE; SDL_memset( stream, 0, len ); return; }
play_pos = play_buffer;
}
const int actual_len = ( len > play_len ? play_len : len );
//SDL_memset( stream, 0, actual_len );
//SDL_MixAudio( stream, audio_pos, actual_len, SDL_MIX_MAXVOLUME );
SDL_memcpy(stream, play_pos, actual_len);
stream += actual_len;
play_pos += actual_len;
play_len -= actual_len;
len -= actual_len;
}
} else {
SDL_memset(stream, 0, len);
}
}
uint8_t old_mode = 0;
void romcpy() {
SDL_memcpy(&mem[2560], rom, rom_size);
}
int main(int argc,char*argv[]) {
SDL_strlcpy(lua_filename, "game.lua", 9);
if (argc > 1) SDL_strlcpy(lua_filename, argv[1], 1023);
for (int i=0; i<debug_total_size;++i) debug_text[i] = 32;
SDL_Init(49);
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640+80, 480+80, SDL_WINDOW_SHOWN);
mini_ren = SDL_CreateRenderer(mini_win, -1, SDL_RENDERER_PRESENTVSYNC);
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
SDL_RenderSetLogicalSize(mini_ren, 320, 240);
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 240);
//SDL_RenderSetLogicalSize(mini_ren, 320, 240);
//mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 240);
bool exit = false;
SDL_Event mini_eve;
SDL_AudioSpec audioSpec{44100, AUDIO_S8, 1, 0, 512, 0, 0, audioCallback, NULL};
SDL_AudioSpec audioSpec = {22050, AUDIO_S8, 1, 0, 512, 0, 0, audioCallback, NULL};
mini_audio_device = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
SDL_PauseAudioDevice(mini_audio_device, 0);
romcpy();
reinit();
debug("ASCII SYSTEM BOOTING...");
lua_init();
lua_init(NULL);
lua_call_init();
while(!exit) {
if (should_reset) {
should_reset = false;
setmode(1);
reinit();
lua_init(lua_filename);
lua_call_init();
}
key_just_pressed = 0;
mouse_wheel = 0;
while(SDL_PollEvent(&mini_eve)) {
@@ -95,16 +185,20 @@ int main(int argc,char*argv[]) {
if (mini_eve.type == SDL_KEYDOWN) {
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
if (lua_is_playing()) {
lua_quit();
reinit();
lua_pause();
//lua_quit();
old_mode = current_mode;
setmode(0);
} else {
lua_init();
lua_call_init();
setmode(old_mode);
lua_resume();
//lua_init();
//lua_call_init();
}
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F5) {
lua_quit();
reinit();
lua_init();
lua_init(lua_filename);
lua_call_init();
} else {
key_just_pressed = mini_eve.key.keysym.scancode;
@@ -116,38 +210,74 @@ int main(int argc,char*argv[]) {
}
keys = SDL_GetKeyboardState(NULL);
mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
mouse_x /= 4; mouse_y /= 4;
mouse_x = (mouse_x-40) / (640/screen_width);
mouse_y = (mouse_y-40) / (480/screen_height);
if (lua_is_playing()) {
lua_call_update();
} else {
debug_cursor_blink--;
if (debug_cursor_blink == 0) {
debug_cursor_blink = 30;
debug_text[debug_cursor] = debug_text[debug_cursor]==32 ? 95 : 32;
}
loop();
}
SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch);
for (int y=0; y<screen_height; ++y) {
for (int x=0; x<screen_width; ++x) {
const uint8_t chr_color = COLSCR(x,y);
const uint32_t ink_color = palette[chr_color & 0x0f];
const uint32_t paper_color = palette[chr_color >> 4];
const uint8_t chr = CHRSCR(x,y);
for (int l=0; l<8; ++l) {
const uint8_t line = font[chr*8+l];
for (int b=0; b<8; ++b) {
if ((line >> (7-b)) & 0x01) {
pixels[b+(x*8)+((y*8)+l)*(screen_width*8)] = ink_color;
} else {
pixels[b+(x*8)+((y*8)+l)*(screen_width*8)] = paper_color;
switch (current_mode) {
case 0:
for (int y=0; y<screen_height; ++y) {
for (int x=0; x<screen_width; ++x) {
const uint8_t chr_color = current_color; //COLSCR(x,y);
const uint32_t ink_color = palette[chr_color & 0x0f];
const uint32_t paper_color = palette[chr_color >> 4];
const uint8_t chr = CHRSCR(x,y);
for (int l=0; l<8; ++l) {
const uint8_t line = mem[MEM_CHAR_OFFSET+chr*8+l];
for (int b=0; b<8; ++b) {
if ((line >> (7-b)) & 0x01) {
pixels[b+(x*8)+((y*8)+l)*(screen_width*8)] = ink_color;
} else {
pixels[b+(x*8)+((y*8)+l)*(screen_width*8)] = paper_color;
}
}
}
}
}
}
break;
case 1:
case 2:
for (int y=0; y<screen_height; ++y) {
for (int x=0; x<screen_width; ++x) {
const uint8_t chr_color = COLSCR(x,y);
const uint32_t ink_color = palette[chr_color & 0x0f];
const uint32_t paper_color = palette[chr_color >> 4];
const uint8_t chr = CHRSCR(x,y);
for (int l=0; l<8; ++l) {
const uint8_t line = mem[MEM_CHAR_OFFSET+chr*8+l];
for (int b=0; b<8; ++b) {
if ((line >> (7-b)) & 0x01) {
pixels[b+(x*8)+((y*8)+l)*(screen_width*8)] = ink_color;
} else {
pixels[b+(x*8)+((y*8)+l)*(screen_width*8)] = paper_color;
}
}
}
}
}
break;
}
//for (int i=0;i<screen_surface->size;++i) pixels[i] = palette[screen_surface->p[i]];
SDL_UnlockTexture(mini_bak);
SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
SDL_SetRenderDrawColor(mini_ren, (palette[current_border] >> 16)&0xff, (palette[current_border] >> 8)&0xff, palette[current_border]&0xff, 0);
//SDL_SetRenderDrawColor(mini_ren, 255, 0, 0, 0);
SDL_RenderClear(mini_ren);
SDL_Rect rect = {40, 40, 640, 480};
SDL_RenderCopy(mini_ren, mini_bak, NULL, &rect);
//SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
SDL_RenderPresent(mini_ren);
}
lua_quit();
@@ -157,7 +287,13 @@ int main(int argc,char*argv[]) {
void cls(uint8_t value) {
SDL_memset(char_screen, value, screen_width*screen_height);
SDL_memset(color_screen, current_color, screen_width*screen_height);
if (current_mode != 0) SDL_memset(color_screen, current_color, screen_width*screen_height);
if (!lua_is_playing()) {
SDL_memset(debug_text, 32, debug_total_size);
debug_cursor = 1;
debug_prompt = 0;
debug_text[debug_prompt] = '>';
}
}
void ink(uint8_t value) {
@@ -168,8 +304,13 @@ void paper(uint8_t value) {
current_color = (current_color & 0x0f) + (value << 4);
}
void color(uint8_t ink, uint8_t paper) {
void border(uint8_t value) {
current_border = value & 0xf;
}
void color(uint8_t ink, uint8_t paper, int8_t border) {
current_color = (ink & 0x0f) + (paper << 4);
if (border >= 0) current_border = border & 0xf;
}
void locate(uint8_t x, uint8_t y) {
@@ -182,10 +323,14 @@ void print(const char *str, int x, int y) {
if (y >= 0) cursor_y = min(y, screen_height-1);
int len = SDL_strlen(str);
if ((cursor_x+len) > screen_width) len -= ((cursor_x+len) - screen_width);
//int offset = x+y*screen_width;
for (int i=0; i < len; ++i) {
CHRSCR(cursor_x+i, cursor_y) = str[i];
COLSCR(cursor_x+i, cursor_y) = current_color;
if (current_mode != 0) COLSCR(cursor_x+i, cursor_y) = current_color;
//char_screen[offset+i] = str[i];
//if (current_mode != 0) color_screen[offset+i] = current_color;
}
cursor_x += len;
}
bool btn(uint8_t i) {
@@ -196,6 +341,10 @@ bool btnp(uint8_t i) {
return key_just_pressed == i;
}
uint8_t whichbtn() {
return key_just_pressed;
}
int mousex() {
return mouse_x;
}
@@ -229,6 +378,7 @@ float sgn(float x) {
}
#ifndef __LINUX__
#ifndef __APPLE__
float ceil(float x) {
return SDL_ceilf(x);
@@ -250,6 +400,7 @@ float sqrt(float x) {
return SDL_sqrtf(x);
}
#endif
#endif
float max(float x, float y) {
@@ -273,14 +424,32 @@ int rnd(int x) {
}*/
char tostr_tmp[256];
const char* tostr(int val) {
const char* tostr(float val) {
return SDL_itoa(val, tostr_tmp, 10);
}
void debug_set_prompt() {
debug_prompt = debug_cursor++;
debug_text[debug_prompt] = '>';
}
void debug_one_line_up() {
for (int i=0; i<debug_total_size-debug_line_size;++i) debug_text[i] = debug_text[i+debug_line_size];
for (int i=debug_total_size-debug_line_size; i<debug_total_size;++i) debug_text[i] = 32;
debug_cursor = debug_total_size-debug_line_size;
debug_set_prompt();
}
void debugchr(const uint8_t chr) {
if (chr == 8) {
if (debug_cursor>(debug_prompt+1)) {
debug_text[debug_cursor--] = 32;
debug_text[debug_cursor] = 32;
}
} else {
debug_text[debug_cursor++] = chr;
if (debug_cursor >= debug_total_size) debug_one_line_up();
}
}
void debug(const char *str) {
@@ -291,6 +460,7 @@ void debug(const char *str) {
}
debug_cursor = (int(debug_cursor/debug_line_size)+1)*debug_line_size;
if (debug_cursor >= debug_total_size) debug_one_line_up();
debug_set_prompt();
}
void pdebug() {
@@ -298,44 +468,92 @@ void pdebug() {
for (int y=0; y<debug_num_lines;++y) {
for (int x=0; x<debug_line_size;++x) {
CHRSCR(x, y) = debug_text[i++];
COLSCR(x, y) = 0x1e;
//COLSCR(x, y) = 0x1e;
}
}
}
void debug_get_cmd() {
debug_text[debug_cursor] = 0;
lua_call_cmd(&debug_text[debug_prompt+1]);
}
uint8_t ascii(const char *str, uint8_t index) {
return str[index];
}
char chr_trans[2] = "X";
const char* chr(uint8_t ascii) {
uint8_t* peiv = (uint8_t*)chr_trans;
*peiv = ascii;
return chr_trans;
}
void setchar(uint8_t index, uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7) {
font[index*8] = b0;
font[index*8+1] = b1;
font[index*8+2] = b2;
font[index*8+3] = b3;
font[index*8+4] = b4;
font[index*8+5] = b5;
font[index*8+6] = b6;
font[index*8+7] = b7;
mem[MEM_CHAR_OFFSET+index*8] = b0;
mem[MEM_CHAR_OFFSET+index*8+1] = b1;
mem[MEM_CHAR_OFFSET+index*8+2] = b2;
mem[MEM_CHAR_OFFSET+index*8+3] = b3;
mem[MEM_CHAR_OFFSET+index*8+4] = b4;
mem[MEM_CHAR_OFFSET+index*8+5] = b5;
mem[MEM_CHAR_OFFSET+index*8+6] = b6;
mem[MEM_CHAR_OFFSET+index*8+7] = b7;
}
uint8_t peek(uint16_t addr) {
// [TODO]
return 0;
if (addr >= 0x2000) return 0;
return mem[addr];
}
void poke(uint16_t addr, uint8_t val) {
// [TODO]
if (addr >= 0x2000) return;
mem[addr] = val;
}
void memcpy(uint16_t dst, uint16_t src, uint16_t size) {
if ((dst<=src) && (dst+size>=src)) return;
if ((dst>=src) && (src+size>=dst)) return;
SDL_memcpy(&mem[dst], &mem[src], size);
}
void sound(float freq, uint32_t len) {
// [TODO]
audio_len = len*44.1f;
audio_freq = 44100.0f/freq/2.0f;
sounding = true;
audio_freq = 22050.0f/freq/2.0f;
audio_state = AUDIO_SOUND;
}
void nosound() {
//SDL_PauseAudioDevice(mini_audio_device, 1);
audio_len = 0;
sounding = false;
audio_state = AUDIO_NONE;
}
void play(const char* str) {
play_pos = play_buffer;
play_len = 0;
play_init(str);
audio_state = AUDIO_PLAY;
}
void setmode(const uint8_t mode) {
current_mode = mode;
reinit();
}
void load(const char* str) {
if (str!=NULL) SDL_strlcpy(lua_filename, str, SDL_strlen(str)+1);
should_reset = true;
}
void fileout(const char* str, uint16_t addr, uint16_t size) {
FILE* f = fopen(str, "wb");
fwrite(&mem[addr], size, 1, f);
fclose(f);
}
void filein(const char* str, uint16_t addr, uint16_t size) {
FILE* f = fopen(str, "rb");
fread(&mem[addr], size, 1, f);
fclose(f);
}

19
ascii.h
View File

@@ -115,13 +115,15 @@ void loop();
void cls(uint8_t value=32);
void ink(uint8_t value); // global::ink
void paper(uint8_t value); // global::paper
void color(uint8_t ink, uint8_t paper);
void border(uint8_t value);
void color(uint8_t ink, uint8_t paper, int8_t border=-1);
void locate(uint8_t x, uint8_t y); // global::cursorx, global::cursory
void print(const char *str, int x = -1, int y = -1);
bool btn(uint8_t i);
bool btnp(uint8_t i);
uint8_t whichbtn();
int mousex();
int mousey();
@@ -136,12 +138,14 @@ float flr(float x);
float sgn(float x);
#ifndef __LINUX__
#ifndef __APPLE__
float ceil(float x);
float sin(float x);
float cos(float x);
float atan2(float dx, float dy);
float sqrt(float x);
#endif
#endif
float max(float x, float y);
float mid(float x, float y, float z);
@@ -150,16 +154,27 @@ float min(float x, float y);
int rnd(int x);
//void srand(int x);
const char* tostr(int val);
const char* tostr(float val);
void debugchr(const uint8_t chr);
void debug(const char *str);
void pdebug();
void debug_get_cmd();
uint8_t ascii(const char *str, uint8_t index);
const char* chr(uint8_t ascii);
void setchar(uint8_t index, uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7);
uint8_t peek(uint16_t addr);
void poke(uint16_t addr, uint8_t val);
void memcpy(uint16_t dst, uint16_t src, uint16_t size);
void sound(float freq, uint32_t len);
void nosound();
void play(const char* str);
void setmode(const uint8_t mode);
void load(const char* str);
void fileout(const char* str, uint16_t addr, uint16_t size);
void filein(const char* str, uint16_t addr, uint16_t size);

94
breakout.lua Normal file
View File

@@ -0,0 +1,94 @@
function init()
setmode(1)
reset()
end
function reset()
bx,by=20,28
dx,dy=-1+rnd(1)*2,-1
px=18
wait=1
speed=6
bricks = {}
for i=0,35 do bricks[i]=COLOR_RED end
for i=36,71 do bricks[i]=COLOR_BROWN end
for i=72,107 do bricks[i]=COLOR_GREEN end
for i=108,143 do bricks[i]=COLOR_YELLOW end
end
function update()
-- move ball
wait=wait-1
if wait==0 then
wait=speed
bx=bx+dx
by=by+dy
if speed<6 then
if bx==2 or bx==37 then dx=-dx play("o3l0c") end
if by<9 then
local index=flr(bx/2)-1+(by-1)*18
if bricks[index]~=COLOR_BLACK then
play("o5l0c")
bricks[index]=COLOR_BLACK
dy=-dy
else
if by==1 then dy=-dy play("o3l0c") end
end
end
if by==28 and bx>=px and bx<=px+4 then
play("o4l0c")
dy=-dy
end
if by==29 then
play("l0o3bagfedc")
reset()
end
else
if bx==2 or bx==37 then dx=-dx end
if by==9 or by==29 then dy=-dy end
end
end
-- move paddle
if btn(KEY_LEFT) and px>2 then px=px-1 end
if btn(KEY_RIGHT) and px<34 then px=px+1 end
-- clear screen
paper(COLOR_BLACK)
cls()
-- draw white border
ink(COLOR_WHITE)
print("\150\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\156",1,0)
for i=1,29 do
print("\149",1,i)
print("\149",38,i)
end
-- draw bricks
for i=0,143 do
color(0,bricks[i])
print("\095\003",2+2*(i%18),1+flr(i/18))
end
--draw ball
color(COLOR_WHITE,COLOR_BLACK)
print("\233",bx,by)
-- draw paddle
ink(COLOR_LIGHT_BLUE)
for i=0,3 do print("\131",px+i,29) end
if speed==6 then
ink(rnd(16))
print("BREAKOUT",16,13)
ink(COLOR_WHITE)
print("Press '1' to play EASY",9,18)
print("Press '2' to play NORMAL",8,20)
print("Press '3' to play HARD",9,22)
if btn(KEY_1) then reset() speed=4 end
if btn(KEY_2) then reset() speed=3 end
if btn(KEY_3) then reset() speed=2 end
end
end

View File

@@ -1,30 +1,9 @@
function init()
x, y, dx, dy = 0, 0, 1, 1
paper(COLOR_BLACK)
ink(COLOR_RED)
setchar(224, 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0x18)
setmode(0)
cls()
play("o4v5l1crcl4dcferl1crcl4dcgfr")
end
function update()
paper(COLOR_BLACK)
cls()
x = x + dx
y = y + dy
if x == 39 or x == 0 then
sound(440, 50)
dx = -dx
end
if y == 29 or y == 0 then
sound(880, 50)
dy = -dy
end
locate(2, 2)
paper(COLOR_GREEN)
ink(COLOR_BLACK)
print("HOLA!")
--locate(x, y)
ink(COLOR_RED)
paper(COLOR_YELLOW)
print("\224", x, y)
end

158
lua.cpp
View File

@@ -21,10 +21,21 @@ extern "C" {
return 0;
}
static int cpp_border(lua_State *L) {
uint8_t val = luaL_checkinteger(L, 1);
border(val);
return 0;
}
static int cpp_color(lua_State *L) {
uint8_t ink = luaL_checkinteger(L, 1);
uint8_t paper = luaL_checkinteger(L, 2);
color(ink, paper);
if (lua_gettop(L) > 2) {
uint8_t border = luaL_checkinteger(L, 3);
color(ink, paper, border);
} else {
color(ink, paper);
}
return 0;
}
@@ -152,7 +163,7 @@ extern "C" {
return 0;
}
static int cpp_tostr(lua_State *L) {
int val = luaL_checknumber(L, 1);
float val = luaL_checknumber(L, 1);
lua_pushstring(L, tostr(val));
return 1;
}
@@ -162,12 +173,17 @@ extern "C" {
lua_pushinteger(L, ascii(str, index));
return 1;
}
static int cpp_chr(lua_State *L) {
int val = luaL_checkinteger(L, 1);
lua_pushstring(L, chr(val));
return 1;
}
static int cpp_strlen(lua_State *L) {
const char* str = luaL_checkstring(L, 1);
lua_pushinteger(L, strlen(str));
return 1;
}
static int cpp_setchar(lua_State *L) {
int index = luaL_checkinteger(L, 1);
int b0 = luaL_checkinteger(L, 2);
@@ -195,6 +211,14 @@ extern "C" {
return 0;
}
static int cpp_memcpy(lua_State *L) {
int dst = luaL_checkinteger(L, 1);
int src = luaL_checkinteger(L, 2);
int size = luaL_checkinteger(L, 3);
memcpy(dst, src, size);
return 0;
}
static int cpp_sound(lua_State *L) {
float freq = luaL_checknumber(L, 1);
int len = luaL_checkinteger(L, 2);
@@ -206,30 +230,91 @@ extern "C" {
nosound();
return 0;
}
static int cpp_play(lua_State *L) {
const char* str = luaL_optstring(L, 1, NULL);
play(str);
return 0;
}
static int cpp_setmode(lua_State *L) {
int val = luaL_checkinteger(L, 1);
setmode(val);
return 0;
}
static int cpp_load(lua_State *L) {
const char* str = luaL_optstring(L, 1, NULL);
load(str);
return 0;
}
static int cpp_log(lua_State *L) {
const char* str = luaL_checkstring(L, 1);
debug(str);
return 0;
}
static int cpp_fileout(lua_State *L) {
const char* str = luaL_checkstring(L, 1);
const uint16_t addr = luaL_checknumber(L, 2);
const uint16_t size = luaL_checknumber(L, 3);
fileout(str, addr, size);
return 0;
}
static int cpp_filein(lua_State *L) {
const char* str = luaL_checkstring(L, 1);
const uint16_t addr = luaL_checknumber(L, 2);
const uint16_t size = luaL_checknumber(L, 3);
filein(str, addr, size);
return 0;
}
}
#define STATE_STOPPED 0
#define STATE_PAUSED 1
#define STATE_PLAYING 2
lua_State *L;
bool is_playing = false;
uint8_t lua_state = STATE_STOPPED;
bool init_exists = false;
bool update_exists = false;
bool lua_is_playing() {
return is_playing;
return lua_state == STATE_PLAYING;
}
void lua_init() {
L = luaL_newstate();
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";
if (luaL_loadfile(L, "game.lua")) {
debug("error loading game");
debug(lua_tostring(L, -1));
lua_pop(L,1);
return;
void lua_init(const char* filename, const bool start_playing) {
if (lua_state != STATE_STOPPED) lua_quit();
L = luaL_newstate();
init_exists = update_exists = false;
bool file_loaded = true;
if (filename == NULL) {
if (luaL_loadstring(L, boot)) {
debug("BOOT ERROR");
debug(lua_tostring(L, -1));
lua_pop(L,1);
setmode(0);
file_loaded = false;
}
} else {
if (luaL_loadfile(L, filename)) {
debug("ERROR LOADING GAME");
debug(lua_tostring(L, -1));
lua_pop(L,1);
setmode(0);
file_loaded = false;
}
}
lua_pushcfunction(L,cpp_cls); lua_setglobal(L, "cls");
lua_pushcfunction(L,cpp_ink); lua_setglobal(L, "ink");
lua_pushcfunction(L,cpp_paper); lua_setglobal(L, "paper");
lua_pushcfunction(L,cpp_border); lua_setglobal(L, "border");
lua_pushcfunction(L,cpp_color); lua_setglobal(L, "color");
lua_pushcfunction(L,cpp_locate); lua_setglobal(L, "locate");
@@ -254,17 +339,27 @@ void lua_init() {
lua_pushcfunction(L,cpp_max); lua_setglobal(L, "max");
lua_pushcfunction(L,cpp_mid); lua_setglobal(L, "mid");
lua_pushcfunction(L,cpp_min); lua_setglobal(L, "min");
lua_pushcfunction(L,cpp_rnd); lua_setglobal(L, "rnd");
lua_pushcfunction(L,cpp_srand); lua_setglobal(L, "srand");
lua_pushcfunction(L,cpp_tostr); lua_setglobal(L, "tostr");
lua_pushcfunction(L,cpp_ascii); lua_setglobal(L, "ascii");
lua_pushcfunction(L,cpp_chr); lua_setglobal(L, "chr");
lua_pushcfunction(L,cpp_strlen); lua_setglobal(L, "strlen");
lua_pushcfunction(L,cpp_setchar); lua_setglobal(L, "setchar");
lua_pushcfunction(L,cpp_peek); lua_setglobal(L, "peek");
lua_pushcfunction(L,cpp_poke); lua_setglobal(L, "poke");
lua_pushcfunction(L,cpp_memcpy); lua_setglobal(L, "memcpy");
lua_pushcfunction(L,cpp_sound); lua_setglobal(L, "sound");
lua_pushcfunction(L,cpp_nosound); lua_setglobal(L, "nosound");
lua_pushcfunction(L,cpp_play); lua_setglobal(L, "play");
lua_pushcfunction(L,cpp_setmode); lua_setglobal(L, "setmode");
lua_pushcfunction(L,cpp_load); lua_setglobal(L, "load");
lua_pushcfunction(L,cpp_log); lua_setglobal(L, "log");
lua_pushcfunction(L,cpp_fileout); lua_setglobal(L, "fileout");
lua_pushcfunction(L,cpp_filein); lua_setglobal(L, "filein");
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");
@@ -391,10 +486,13 @@ void lua_init() {
lua_pushinteger(L, 14); lua_setglobal(L, "COLOR_YELLOW");
lua_pushinteger(L, 15); lua_setglobal(L, "COLOR_WHITE");
if (!file_loaded) return;
if (lua_pcall(L,0, LUA_MULTRET, 0)) {
debug("runtime error");
debug("RUNTIME ERROR");
debug(lua_tostring(L, -1));
lua_pop(L,1);
setmode(0);
return;
}
@@ -406,17 +504,28 @@ void lua_init() {
if (lua_isfunction(L,-1)) update_exists = true;
lua_pop(L,1);
is_playing = true;
lua_state = start_playing ? STATE_PLAYING : STATE_PAUSED;
}
void lua_call_cmd(const char* str) {
if (luaL_dostring(L, str)) {
debug(" ");
debug("ERROR");
debug(lua_tostring(L, -1));
lua_pop(L,1);
}
debug(" ");
}
void lua_call_init() {
if (!init_exists) return;
lua_getglobal(L, "init");
if (lua_pcall(L, 0, 0, 0)) {
debug("runtime error");
debug("RUNTIME ERROR");
debug(lua_tostring(L, -1));
lua_pop(L,1);
is_playing = false;
setmode(0);
lua_state = STATE_STOPPED;
}
}
@@ -424,15 +533,24 @@ void lua_call_update() {
if (!update_exists) return;
lua_getglobal(L, "update");
if (lua_pcall(L, 0, 0, 0)) {
debug("runtime error");
debug("RUNTIME ERROR");
debug(lua_tostring(L, -1));
lua_pop(L,1);
is_playing = false;
setmode(0);
lua_state = STATE_STOPPED;
}
}
void lua_quit() {
if (!is_playing) return;
is_playing = false;
if (lua_state == STATE_STOPPED) return;
lua_state = STATE_STOPPED;
lua_close(L);
}
void lua_pause() {
lua_state = STATE_PAUSED;
}
void lua_resume() {
lua_state = STATE_PLAYING;
}

5
lua.h
View File

@@ -1,7 +1,10 @@
#pragma once
bool lua_is_playing();
void lua_init();
void lua_init(const char* filename, const bool start_playing=true);
void lua_call_init();
void lua_call_update();
void lua_call_cmd(const char* str);
void lua_quit();
void lua_pause();
void lua_resume();

View File

@@ -3,7 +3,39 @@
int current_editor = 0;
void do_terminal() {
cls(0);
SDL_Keymod mods = SDL_GetModState();
const uint8_t key = whichbtn();
if (key != KEY_UNKNOWN) {
if (key < 30) {
if ((mods & KMOD_SHIFT) || (mods & KMOD_CAPS)) {
debugchr(key+61);
} else {
debugchr(key+93);
}
}
//else if (key < 39) debugchr(key+19);
else if (key == KEY_0) { if (mods & KMOD_SHIFT) { debugchr('='); } else { debugchr('0'); } }
else if (key == KEY_1) { if (mods & KMOD_SHIFT) { debugchr('!'); } else if (mods & KMOD_RALT) { debugchr('|'); } else { debugchr('1'); } }
else if (key == KEY_2) { if (mods & KMOD_SHIFT) { debugchr('"'); } else if (mods & KMOD_RALT) { debugchr('@'); } else { debugchr('2'); } }
else if (key == KEY_3) { if (mods & KMOD_SHIFT) { debugchr(144); } else if (mods & KMOD_RALT) { debugchr('#'); } else { debugchr('3'); } }
else if (key == KEY_4) { if (mods & KMOD_SHIFT) { debugchr('$'); } else if (mods & KMOD_RALT) { debugchr('~'); } else { debugchr('4'); } }
else if (key == KEY_5) { if (mods & KMOD_SHIFT) { debugchr('%'); } else if (mods & KMOD_RALT) { debugchr(180); } else { debugchr('5'); } }
else if (key == KEY_6) { if (mods & KMOD_SHIFT) { debugchr('&'); } else if (mods & KMOD_RALT) { debugchr(173); } else { debugchr('6'); } }
else if (key == KEY_7) { if (mods & KMOD_SHIFT) { debugchr('/'); } else { debugchr('7'); } }
else if (key == KEY_8) { if (mods & KMOD_SHIFT) { debugchr('('); } else { debugchr('8'); } }
else if (key == KEY_9) { if (mods & KMOD_SHIFT) { debugchr(')'); } else { debugchr('9'); } }
else if (key == KEY_RETURN) debug_get_cmd();
else if (key == KEY_SPACE) debugchr(32);
else if (key == KEY_BACKSPACE) debugchr(8);
else if (key == KEY_MINUS) { if (mods & KMOD_SHIFT) { debugchr('?'); } else { debugchr('\''); } }
else if (key == KEY_EQUALS) { if (mods & KMOD_SHIFT) { debugchr(174); } else { debugchr(175); } }
else if (key == KEY_COMMA) { if (mods & KMOD_SHIFT) { debugchr(';'); } else { debugchr(','); } }
else if (key == KEY_PERIOD) { if (mods & KMOD_SHIFT) { debugchr(':'); } else { debugchr('.'); } }
else if (key == KEY_SLASH) { if (mods & KMOD_SHIFT) { debugchr('_'); } else { debugchr('-'); } }
else if (key == KEY_LEFTBRACKET) { if (mods & KMOD_SHIFT) { debugchr(160); } else if (mods & KMOD_RALT) { debugchr('['); } else { debugchr(96); } }
else if (key == KEY_RIGHTBRACKET) { if (mods & KMOD_SHIFT) { debugchr('*'); } else if (mods & KMOD_RALT) { debugchr(']'); } else { debugchr('+'); } }
}
//cls(0);
pdebug();
}

91
mapedit.lua Normal file
View File

@@ -0,0 +1,91 @@
ind = 22
function init()
setmode(2)
map = {}
col = {}
for i=0,299 do
map[i] = 32
col[i] = 0x0f
end
map[ind] = 65
sel_col = 0x0f
sel_chr = 65
end
blink=30
function update()
if btn(KEY_TAB) then
draw_picker()
update_picker()
else
draw_map()
--update_map()
end
end
function draw_picker()
for i=0,255 do
poke(i, i)
poke(300+i, sel_col)
end
for i=0,15 do
poke(580+i, i<<4)
poke(560+i, i<<4)
poke(280+i, 32)
poke(260+i, 32)
end
poke(580, 15) poke(560, 15)
poke(260+(sel_col&0xf), 203)
poke(280+(sel_col>>4), 203)
local mx, my = mousex(), mousey()
if my<13 then
poke(300+(mx+my*20), 0x4e)
print(mx+my*20, 16, 13)
elseif my>=13 then
poke(mx+my*20, 144)
end
end
function update_picker()
local mx, my = mousex(), mousey()
if mousebutton(1) then
if my<13 then
sel_chr = mx+my*20
else
if mx < 16 then
if my == 13 then
sel_col = (sel_col & 0xf0) + mx
else
sel_col = (sel_col & 0x0f) + (mx << 4)
end
end
end
end
end
function draw_map()
for i=0,299 do
poke(i, map[i])
poke(300+i, col[i])
end
local mx, my = mousex(), mousey()
if mousebutton(1) then
map[mx+my*20] = sel_chr
col[mx+my*20] = sel_col
end
if btn(KEY_SPACE) then
sel_chr = peek(mx+my*20)
sel_col = peek(300+mx+my*20)
end
blink = blink - 1
if blink < 30 then
if blink==0 then blink = 60 end
local mx, my = mousex(), mousey()
local c = peek(300+(mx+my*20))
poke(300+(mx+my*20), c~0xff)
end
end

84
play.cpp Normal file
View File

@@ -0,0 +1,84 @@
#include "play.h"
#include <stdlib.h>
#include <string.h>
const static uint16_t lengths[10] = { 313, 625, 938, 1250, 1875, 2500, 3750, 5000, 7500, 10000 };
const static uint16_t tempos[10] = { 13230, 8820, 6615, 5292, 4410, 3780, 3308, 2940, 2646, 2406 };
const float periods[108] = { 1348.49207, 1272.80688, 1201.37, 1133.94214, 1070.29871, 1010.22772, 953.527893, 900.010376, 849.496887, 801.818176, 756.815613, 714.338745, 674.246033, 636.403564, 600.684875, 566.971069, 535.149475, 505.11377, 476.763947, 450.005249, 424.748352, 400.909088, 378.407806, 357.169373, 337.123016, 318.201782, 300.342438, 283.485535, 267.574738, 252.556885, 238.381973, 225.002625, 212.374176, 200.454544, 189.203888, 178.584702, 168.561508, 159.100876, 150.171234, 141.742767, 133.787354, 126.278458, 119.190987, 112.501305, 106.187096, 100.227272, 94.6019516, 89.2923508, 84.2807541, 79.5504379, 75.0856171, 70.8713837, 66.8936768, 63.139225, 59.5954933, 56.2506561, 53.0935478, 50.113636, 47.3009758, 44.6461754, 42.140377, 39.775219, 37.5428085, 35.4356918, 33.4468384, 31.5696125, 29.7977467, 28.1253281, 26.5467739, 25.056818, 23.650486, 22.3230877, 21.0701885, 19.8876095, 18.7714043, 17.7178459, 16.7234192, 15.7848072, 14.8988733, 14.0626631, 13.273387, 12.528409, 11.8252439, 11.1615429, 10.5350943, 9.94380569, 9.38570118, 8.85892296, 8.36171055, 7.89240265, 7.44943666, 7.03133202, 6.636693, 6.2642045, 5.91262197, 5.58077145, 5.26754713, 4.97190285, 4.69285059, 4.42946148, 4.18085527, 3.94620132, 3.72471833, 3.51566601, 3.3183465, 3.13210225, 2.95631051, 2.7903862 };
static float default_length = 0.25f;
static uint8_t volume = 64;
static uint8_t octave = 4;
static uint32_t tempo = 44100;
static char* song_ptr = NULL;
static char* song = NULL;
uint32_t interpret_note(uint8_t* buffer, const char note, const char param ) {
const uint32_t length = ( param == -1 ? default_length : ((float)lengths[param])/10000.0f ) * tempo;
if( note == 100 ) { memset( buffer, 0, length ); return length; }
const uint16_t period = periods[note + octave*12];
for( int i = 0; i < length; i++ ) buffer[i] = ( (i % period) < (period >> 1) ? volume : -volume );
return length;
}
void play_init(const char* new_song) {
volume=64;
octave=4;
tempo=44100;
if (song != NULL) free(song);
song = (char*)malloc( strlen( new_song ) + 1 );
strcpy( song, new_song );
song_ptr = song;
}
int32_t interpret_next_token(uint8_t* buffer) {
char** token = &song_ptr;
char note = 0;
char param = -1;
switch( **token ) {
case 'b': note += 2;
case 'a': note += 2;
case 'g': note += 2;
case 'f': note += 1;
case 'e': note += 2;
case 'd': note += 2;
case 'c':
param = *++*token;
if( param == '#' || param == '+' ) { note++; param = *++*token; } else if( param == '-' ) { note--; param = *++*token; }
if( param >= 48 && param <= 57 ) { param -= 48; ++*token; } else { param = -1; }
return interpret_note( buffer, note, param );
case 'r':
param = *++*token;
if( param >= 48 && param <= 57 ) { param -= 48; ++*token; } else { param = -1; }
return interpret_note( buffer, 100, param );
case 'o':
param = *++*token;
if( param >= 48 && param <= 57 ) { octave = (param - 48) % 8; ++*token; }
return 0;
case '>':
octave = (octave+1) % 8; ++*token;
return 0;
case '<':
octave = (octave-1) % 8; ++*token;
return 0;
case 'l':
param = *++*token;
if( param >= 48 && param <= 57 ) { default_length = ((float)lengths[param - 48])/10000.0f; ++*token; }
return 0;
case 'v':
param = *++*token;
if( param >= 48 && param <= 57 ) { volume = (param - 48) << 4; ++*token; }
return 0;
case 't':
param = *++*token;
if( param >= 48 && param <= 57 ) { tempo = tempos[param - 48] * 10; ++*token; }
return 0;
case '\0':
return -1;
default:
++*token;
return 0;
};
}

6
play.h Normal file
View File

@@ -0,0 +1,6 @@
#pragma once
#include <stdint.h>
void play_init(const char* new_song);
int32_t interpret_next_token(uint8_t* buffer);

115
pong.lua Normal file
View File

@@ -0,0 +1,115 @@
function init()
-- mode 1: 40x30 characters
setmode(1)
-- prepare everything for the match
reset_match()
p1,p2=0,0 -- reset scores
end
function update()
cls()
-- ball movement
-- 'wait' is a counter to skip some cycles before moving the ball, so it starts slower
-- 'speed' defines how many cycles to skip. Every 5 hits to the paddles 'speed' goes down by 1, effectively increasing the ball's speed
-- 'speed' is reset every point
wait=wait-1
if wait==0 then
wait=speed
-- move ball
bx=bx+dx
by=by+dy
-- if ball hits top or down walls, bounce
if by==0 or by==29 then
dy=-dy
if playing then play("a") end -- if we are not playing, be quiet
end
-- during a match, paddles bounce the ball and left and right walls award points
-- but before or after a match the ball just bounces around
if playing then
-- if ball hits left or right ball, reset the ball and award a point to the opposing paddle
if bx==0 then p2=p2+1 reset_ball() end
if bx==39 then p1=p1+1 reset_ball() end
-- if ball hits paddle, bounce
if (bx==1 and by>=y1 and by<=y1+4) or (bx==38 and by>=y2 and by<=y2+4) then
play("c")
dx=-dx
-- also, increase hits. Every 5 hits the ball will speed up (only if it's not already as fast as possible)
hits=hits+1
if (hits%5 == 0) and (speed>0) then speed=speed-1 end
end
else
-- when not playing, just bounce freely
if bx==0 or bx==39 then dx=-dx end
end
end
-- player 1 controls
if btn(KEY_Q) and y1>0 then y1=y1-1 end
if btn(KEY_A) and y1<25 then y1=y1+1 end
-- player 2 controls
if btn(KEY_UP) and y2>0 then y2=y2-1 end
if btn(KEY_DOWN) and y2<25 then y2=y2+1 end
-- draw net
if playing then for i=0,29 do print("\145",20,i) end end
-- draw score
print(p1,18,3)
print(p2,22,3)
-- draw ball
print("\143",flr(bx),flr(by))
-- draw paddles
for i=0,4 do
print("\143",1,y1+i)
print("\143",38,y2+i)
end
if not playing then
-- while not playing show the messages
if p1==10 then print("PLAYER 1 WINS!", 14, 8)
elseif p2==10 then print("PLAYER 2 WINS!", 14, 8)
else print("PONG!", 18, 10) end
print("Press SPACE to play", 11, 20)
if btn(KEY_SPACE) then
start_match()
end
end
end
function start_match()
playing=true
p1,p2=0,0 -- reset scores
end
function reset_match()
play("l2drl2d#l4e>l2crr<e>crr<l4e>crrrl2r cl4dl2d#l4el2cl4del2r<b>l4dl2rl4crrrl2r< drl2d#l4e>l2crr<e>crr<l4e>crrrl2r< l2argl4f#l2a>l4cl2errdl4cl2<al4>drrrl2r< l2drl2d#l4e>l2crr<e>crr<l4e>crrrl2r cl4dl2d#l4el2cl4del2r<b>l4dl2rl4crrrl2r<")
playing=false
bx,by=20,15 -- init ball's position
dx,dy=1,1 -- init ball's direction
y1,y2=14,14 -- init paddle's y coordinate
wait=1 -- reset wait counter
speed=4 -- reset speed
hits=0 -- reset hits counter
end
function reset_ball()
play("l0o3bagfedc") -- play sad tune
bx,by=20,15 -- reset ball's position
speed=4 -- reset speed
hits=0 -- reset hits counter
dx=-dx -- invert x direction
-- si algu arriba a 10, la partida acaba
if p1==10 or p2==10 then
playing=false
play("o5l1crl0ergrl4o6c")
end
end

View File

@@ -1,6 +1,8 @@
#pragma once
unsigned char font[2048] = {
const int rom_size = 2528;
unsigned char rom[rom_size] = {
0xFF, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xFF, 0xFF, 0xC0, 0xC0, 0xC0,
0xC0, 0xC0, 0xC0, 0xC0, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xFF,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFF, 0x0C, 0x18, 0x30, 0x7E,
@@ -171,5 +173,46 @@ unsigned char font[2048] = {
0x90, 0x28, 0x24, 0x22, 0x38, 0x38, 0x90, 0x7C, 0x12, 0x28, 0x48, 0x88,
0x00, 0x3C, 0x18, 0x3C, 0x3C, 0x3C, 0x18, 0x00, 0x3C, 0xFF, 0xFF, 0x18,
0x0C, 0x18, 0x30, 0x18, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18,
0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00
0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00,
// BOOT LOGO
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xD6, 0x8F, 0x8F, 0x8F,
0x8F, 0xD4, 0xD6, 0x8F, 0x8F, 0x8F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FBFBD><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> <07><07><07><01><07>x<08><><EFBFBD>xxxx<07>x<0F><><EFBFBD>xxxxxx<0F>xxx<07>x <0C> 

106
scredit.lua Normal file
View File

@@ -0,0 +1,106 @@
ind = 22
function init()
setmode(1)
map = {}
col = {}
for i=0,1199 do
map[i] = 32
col[i] = 0x0f
end
map[ind] = 65
sel_col = 0x0f
sel_chr = 65
end
blink=30
function update()
if btn(KEY_TAB) then
draw_picker()
update_picker()
else
draw_map()
--update_map()
end
end
function draw_picker()
for y=0,15 do
for x=0,15 do
poke(x+y*40, x+y*16)
poke(1200+x+y*40, sel_col)
end
end
for i=0,15 do
poke(1840+i, i<<4)
poke(1880+i, i<<4)
poke(640+i, 32)
poke(680+i, 32)
end
poke(1840, 15) poke(1880, 15)
poke(640+(sel_col&0xf), 203)
poke(680+(sel_col>>4), 203)
local mx, my = mousex(), mousey()
if mx<16 then
if my<16 then
poke(1200+(mx+my*40), 0x4e)
print(mx+my*40, 16, 13)
elseif my>=16 then
poke(mx+my*40, 144)
end
end
end
function update_picker()
local mx, my = mousex(), mousey()
if mousebutton(1) then
if mx<16 then
if my<16 then
sel_chr = mx+my*16
else
if my == 16 then
sel_col = (sel_col & 0xf0) + mx
elseif my == 17 then
sel_col = (sel_col & 0x0f) + (mx << 4)
end
end
end
end
end
function draw_map()
for i=0,1199 do
poke(i, map[i])
poke(1200+i, col[i])
end
local mx, my = mousex(), mousey()
if mousebutton(1) then
map[mx+my*40] = sel_chr
col[mx+my*40] = sel_col
end
if btn(KEY_SPACE) then
sel_chr = peek(mx+my*40)
sel_col = peek(1200+mx+my*40)
end
blink = blink - 1
if blink < 30 then
if blink==0 then blink = 60 end
local mx, my = mousex(), mousey()
local c = peek(1200+(mx+my*40))
poke(1200+(mx+my*40), c~0xff)
end
if btn(KEY_S) then
fileout("scr.bin", 0, 2400);
elseif btn(KEY_L) then
filein("scr.bin", 0, 2400);
for i=0,1199 do
map[i] = peek(i)
col[i] = peek(1200+i)
end
end
end