Compare commits
3 Commits
a21b66f12a
...
0482467037
| Author | SHA1 | Date | |
|---|---|---|---|
| 0482467037 | |||
| 280ca2ceca | |||
| 72412a01bd |
46
ascii.cpp
46
ascii.cpp
@@ -14,6 +14,9 @@ uint8_t screen_height = 30;
|
|||||||
uint8_t current_color = 0x1e;
|
uint8_t current_color = 0x1e;
|
||||||
uint8_t cursor_x = 0;
|
uint8_t cursor_x = 0;
|
||||||
uint8_t cursor_y = 0;
|
uint8_t cursor_y = 0;
|
||||||
|
bool sounding = false;
|
||||||
|
int audio_freq = 0;
|
||||||
|
uint32_t audio_len = 0;
|
||||||
|
|
||||||
#define CHRSCR(x, y) char_screen[x+y*screen_width]
|
#define CHRSCR(x, y) char_screen[x+y*screen_width]
|
||||||
#define COLSCR(x, y) color_screen[x+y*screen_width]
|
#define COLSCR(x, y) color_screen[x+y*screen_width]
|
||||||
@@ -21,6 +24,7 @@ uint8_t cursor_y = 0;
|
|||||||
SDL_Window *mini_win;
|
SDL_Window *mini_win;
|
||||||
SDL_Renderer *mini_ren;
|
SDL_Renderer *mini_ren;
|
||||||
SDL_Texture *mini_bak;
|
SDL_Texture *mini_bak;
|
||||||
|
SDL_AudioDeviceID mini_audio_device;
|
||||||
Uint32 *pixels;
|
Uint32 *pixels;
|
||||||
int pitch;
|
int pitch;
|
||||||
|
|
||||||
@@ -48,6 +52,19 @@ void reinit() {
|
|||||||
cursor_y = 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;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc,char*argv[]) {
|
int main(int argc,char*argv[]) {
|
||||||
|
|
||||||
for (int i=0; i<debug_total_size;++i) debug_text[i] = 32;
|
for (int i=0; i<debug_total_size;++i) debug_text[i] = 32;
|
||||||
@@ -61,6 +78,10 @@ int main(int argc,char*argv[]) {
|
|||||||
bool exit = false;
|
bool exit = false;
|
||||||
SDL_Event mini_eve;
|
SDL_Event mini_eve;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
reinit();
|
reinit();
|
||||||
debug("ASCII SYSTEM BOOTING...");
|
debug("ASCII SYSTEM BOOTING...");
|
||||||
lua_init();
|
lua_init();
|
||||||
@@ -106,8 +127,9 @@ int main(int argc,char*argv[]) {
|
|||||||
|
|
||||||
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 uint32_t ink_color = palette[current_color & 0x0f];
|
const uint8_t chr_color = COLSCR(x,y);
|
||||||
const uint32_t paper_color = palette[current_color >> 4];
|
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);
|
const uint8_t chr = CHRSCR(x,y);
|
||||||
for (int l=0; l<8; ++l) {
|
for (int l=0; l<8; ++l) {
|
||||||
const uint8_t line = font[chr*8+l];
|
const uint8_t line = font[chr*8+l];
|
||||||
@@ -156,8 +178,8 @@ void locate(uint8_t x, uint8_t y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void print(const char *str, int x, int y) {
|
void print(const char *str, int x, int y) {
|
||||||
if (x > 0) cursor_x = min(x, screen_width-1);
|
if (x >= 0) cursor_x = min(x, screen_width-1);
|
||||||
if (y > 0) cursor_y = min(y, screen_height-1);
|
if (y >= 0) cursor_y = min(y, screen_height-1);
|
||||||
int len = SDL_strlen(str);
|
int len = SDL_strlen(str);
|
||||||
if ((cursor_x+len) > screen_width) len -= ((cursor_x+len) - screen_width);
|
if ((cursor_x+len) > screen_width) len -= ((cursor_x+len) - screen_width);
|
||||||
for (int i=0; i < len; ++i) {
|
for (int i=0; i < len; ++i) {
|
||||||
@@ -286,7 +308,14 @@ uint8_t ascii(const char *str, uint8_t index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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) {
|
||||||
// [TODO]
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t peek(uint16_t addr) {
|
uint8_t peek(uint16_t addr) {
|
||||||
@@ -300,8 +329,13 @@ void poke(uint16_t addr, uint8_t val) {
|
|||||||
|
|
||||||
void sound(float freq, uint32_t len) {
|
void sound(float freq, uint32_t len) {
|
||||||
// [TODO]
|
// [TODO]
|
||||||
|
audio_len = len*44.1f;
|
||||||
|
audio_freq = 44100.0f/freq/2.0f;
|
||||||
|
sounding = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nosound() {
|
void nosound() {
|
||||||
// [TODO]
|
//SDL_PauseAudioDevice(mini_audio_device, 1);
|
||||||
|
audio_len = 0;
|
||||||
|
sounding = false;
|
||||||
}
|
}
|
||||||
|
|||||||
15
game.lua
15
game.lua
@@ -2,18 +2,29 @@ function init()
|
|||||||
x, y, dx, dy = 0, 0, 1, 1
|
x, y, dx, dy = 0, 0, 1, 1
|
||||||
paper(COLOR_BLACK)
|
paper(COLOR_BLACK)
|
||||||
ink(COLOR_RED)
|
ink(COLOR_RED)
|
||||||
|
setchar(224, 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0x18)
|
||||||
end
|
end
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
|
paper(COLOR_BLACK)
|
||||||
cls()
|
cls()
|
||||||
x = x + dx
|
x = x + dx
|
||||||
y = y + dy
|
y = y + dy
|
||||||
if x == 39 or x == 0 then
|
if x == 39 or x == 0 then
|
||||||
|
sound(440, 50)
|
||||||
dx = -dx
|
dx = -dx
|
||||||
end
|
end
|
||||||
if y == 29 or y == 0 then
|
if y == 29 or y == 0 then
|
||||||
|
sound(880, 50)
|
||||||
dy = -dy
|
dy = -dy
|
||||||
end
|
end
|
||||||
locate(x, y)
|
locate(2, 2)
|
||||||
print("\224")
|
paper(COLOR_GREEN)
|
||||||
|
ink(COLOR_BLACK)
|
||||||
|
print("HOLA!")
|
||||||
|
|
||||||
|
--locate(x, y)
|
||||||
|
ink(COLOR_RED)
|
||||||
|
paper(COLOR_YELLOW)
|
||||||
|
print("\224", x, y)
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user