[FEAT] memcpy

[CHANGE] New default color 0x0f
This commit is contained in:
2021-12-08 07:34:54 +01:00
parent 963958e596
commit 290d50e32f
3 changed files with 18 additions and 2 deletions

View File

@@ -67,7 +67,7 @@ void reinit() {
case 1: case 1:
screen_width = 40; screen_width = 40;
screen_height = 30; screen_height = 30;
current_color = 0x1e; current_color = 0x07;
cursor_x = 0; cursor_x = 0;
cursor_y = 0; cursor_y = 0;
char_screen = &mem[0]; char_screen = &mem[0];
@@ -78,7 +78,7 @@ void reinit() {
case 2: case 2:
screen_width = 20; screen_width = 20;
screen_height = 15; screen_height = 15;
current_color = 0x1e; current_color = 0x07;
cursor_x = 0; cursor_x = 0;
cursor_y = 0; cursor_y = 0;
char_screen = &mem[0]; char_screen = &mem[0];
@@ -469,6 +469,12 @@ void poke(uint16_t addr, uint8_t val) {
} }
} }
void memcpy(uint16_t dst, uint16_t src, uint16_t size) {
if (dst <= src) return;
if (src+size>=dst) return;
SDL_memcpy(&mem[dst], &mem[src], size);
}
void sound(float freq, uint32_t len) { void sound(float freq, uint32_t len) {
// [TODO] // [TODO]
audio_len = len*44.1f; audio_len = len*44.1f;

View File

@@ -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); 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); uint8_t peek(uint16_t addr);
void poke(uint16_t addr, uint8_t val); 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 sound(float freq, uint32_t len);
void nosound(); void nosound();

View File

@@ -200,6 +200,14 @@ extern "C" {
return 0; 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) { static int cpp_sound(lua_State *L) {
float freq = luaL_checknumber(L, 1); float freq = luaL_checknumber(L, 1);
int len = luaL_checkinteger(L, 2); int len = luaL_checkinteger(L, 2);
@@ -312,6 +320,7 @@ void lua_init(const char* filename, const bool start_playing) {
lua_pushcfunction(L,cpp_setchar); lua_setglobal(L, "setchar"); lua_pushcfunction(L,cpp_setchar); lua_setglobal(L, "setchar");
lua_pushcfunction(L,cpp_peek); lua_setglobal(L, "peek"); lua_pushcfunction(L,cpp_peek); lua_setglobal(L, "peek");
lua_pushcfunction(L,cpp_poke); lua_setglobal(L, "poke"); 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_sound); lua_setglobal(L, "sound");
lua_pushcfunction(L,cpp_nosound); lua_setglobal(L, "nosound"); lua_pushcfunction(L,cpp_nosound); lua_setglobal(L, "nosound");
lua_pushcfunction(L,cpp_setmode); lua_setglobal(L, "setmode"); lua_pushcfunction(L,cpp_setmode); lua_setglobal(L, "setmode");