Compare commits
5 Commits
806eeb04b5
...
v0.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 66bbdea85f | |||
| 1a73164990 | |||
| 290d50e32f | |||
| 963958e596 | |||
| 6131607778 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
ascii
|
||||
.vscode/*
|
||||
*.dll
|
||||
wiki/*
|
||||
|
||||
62
ascii.cpp
62
ascii.cpp
@@ -2,13 +2,13 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "lua.h"
|
||||
#include "font.c"
|
||||
#include "rom.c"
|
||||
|
||||
#define swap(a, b) {auto tmp=a;a=b;b=tmp;}
|
||||
|
||||
char lua_filename[1024];
|
||||
char window_title[256];
|
||||
uint8_t mem[2560]; //2400
|
||||
uint8_t mem[8192]; //2400
|
||||
uint8_t *char_screen = NULL;
|
||||
uint8_t *color_screen = NULL;
|
||||
uint8_t screen_width = 40;
|
||||
@@ -24,6 +24,9 @@ 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 = NULL;
|
||||
@@ -67,7 +70,7 @@ void reinit() {
|
||||
case 1:
|
||||
screen_width = 40;
|
||||
screen_height = 30;
|
||||
current_color = 0x1e;
|
||||
current_color = 0x07;
|
||||
cursor_x = 0;
|
||||
cursor_y = 0;
|
||||
char_screen = &mem[0];
|
||||
@@ -78,7 +81,7 @@ void reinit() {
|
||||
case 2:
|
||||
screen_width = 20;
|
||||
screen_height = 15;
|
||||
current_color = 0x1e;
|
||||
current_color = 0x07;
|
||||
cursor_x = 0;
|
||||
cursor_y = 0;
|
||||
char_screen = &mem[0];
|
||||
@@ -104,6 +107,10 @@ void audioCallback(void * userdata, uint8_t * stream, int 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);
|
||||
@@ -122,10 +129,11 @@ int main(int argc,char*argv[]) {
|
||||
SDL_AudioSpec audioSpec = {44100, 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_filename);
|
||||
lua_init(NULL);
|
||||
lua_call_init();
|
||||
|
||||
while(!exit) {
|
||||
@@ -192,7 +200,7 @@ int main(int argc,char*argv[]) {
|
||||
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];
|
||||
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;
|
||||
@@ -213,7 +221,7 @@ int main(int argc,char*argv[]) {
|
||||
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];
|
||||
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;
|
||||
@@ -443,30 +451,30 @@ 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) {
|
||||
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) {
|
||||
if (addr < 0xA00) {
|
||||
return mem[addr];
|
||||
} else {
|
||||
return font[addr-0xA00];
|
||||
}
|
||||
if (addr >= 0x2000) return 0;
|
||||
return mem[addr];
|
||||
}
|
||||
|
||||
void poke(uint16_t addr, uint8_t val) {
|
||||
if (addr < 0xA00) {
|
||||
mem[addr] = val;
|
||||
} else {
|
||||
font[addr-0xA00] = val;
|
||||
}
|
||||
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) {
|
||||
@@ -488,7 +496,7 @@ void setmode(const uint8_t mode) {
|
||||
}
|
||||
|
||||
void load(const char* str) {
|
||||
SDL_strlcpy(lua_filename, str, SDL_strlen(str)+1);
|
||||
if (str!=NULL) SDL_strlcpy(lua_filename, str, SDL_strlen(str)+1);
|
||||
should_reset = true;
|
||||
}
|
||||
|
||||
|
||||
1
ascii.h
1
ascii.h
@@ -166,6 +166,7 @@ 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();
|
||||
|
||||
35
game.lua
35
game.lua
@@ -1,32 +1,17 @@
|
||||
cls()
|
||||
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)
|
||||
end
|
||||
|
||||
function update()
|
||||
setmode(2)
|
||||
paper(COLOR_BLACK)
|
||||
cls()
|
||||
x = x + dx
|
||||
y = y + dy
|
||||
if x == 19 or x == 0 then
|
||||
sound(440, 50)
|
||||
dx = -dx
|
||||
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
|
||||
if y == 14 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
|
||||
35
lua.cpp
35
lua.cpp
@@ -200,6 +200,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);
|
||||
@@ -219,7 +227,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_load(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
const char* str = luaL_optstring(L, 1, NULL);
|
||||
load(str);
|
||||
return 0;
|
||||
}
|
||||
@@ -260,18 +268,30 @@ bool lua_is_playing() {
|
||||
return lua_state == STATE_PLAYING;
|
||||
}
|
||||
|
||||
const char boot[] = "function init()setmode(1)cls()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(8)print('v0.5.1',26,8)w=0 end function update()w=w+1 if w>90 then cls()load()end end";
|
||||
|
||||
void lua_init(const char* filename, const bool start_playing) {
|
||||
if (lua_state != STATE_STOPPED) lua_quit();
|
||||
L = luaL_newstate();
|
||||
init_exists = update_exists = false;
|
||||
bool file_loaded = true;
|
||||
|
||||
if (luaL_loadfile(L, filename)) {
|
||||
debug("ERROR LOADING GAME");
|
||||
debug(lua_tostring(L, -1));
|
||||
lua_pop(L,1);
|
||||
setmode(0);
|
||||
file_loaded = false;
|
||||
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");
|
||||
@@ -312,6 +332,7 @@ void lua_init(const char* filename, const bool start_playing) {
|
||||
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_setmode); lua_setglobal(L, "setmode");
|
||||
|
||||
@@ -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, 0x8F, 0xD4, 0xD6, 0x8F, 0x8F, 0x8F,
|
||||
0x8F, 0xD4, 0xD6, 0x8F, 0xD4, 0xD6, 0x8F, 0xD4, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0xD4,
|
||||
0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0xD4, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F,
|
||||
0xD4, 0x8F, 0x8F, 0xD4, 0x8F, 0x8F, 0x8F, 0x20, 0x20, 0x20, 0x8F, 0x8F,
|
||||
0xD4, 0x8F, 0x8F, 0x8F, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x8F, 0x8F, 0xD4, 0x8F,
|
||||
0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x8F, 0x20,
|
||||
0x20, 0x20, 0x8F, 0x8F, 0x8F,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