Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poke1 and Peek1 #1616

Merged
merged 3 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,29 @@ enum
tic_mem*, s32 address, u8 value) \
\
\
macro(peek1, \
"peek1(addr) -> value", \
\
"This function enables you to read single-bit values from TIC's RAM.\n" \
"The address should be specified in hexadecimal format.", \
1, \
u8, \
tic_mem*, s32 address) \
\
\
macro(poke1, \
"poke1(addr value)", \
\
"This function allows you to write to the virtual RAM of TIC.\n" \
"It differs from `poke()` in that it accesses the individual bits of memory.\n" \
"Therefore, to address the highest bit of position 0x4000 you should pass 0x16000 as addr1, " \
"and to access the lowest bit (rightmost bit) you would pass 0x16007.\n" \
"The address should be specified in hexadecimal format, and values should be given in decimal.", \
2, \
void, \
tic_mem*, s32 address, u8 value) \
\
\
macro(memcpy, \
"memcpy(dest source size)", \
\
Expand Down
20 changes: 20 additions & 0 deletions src/api/js.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,26 @@ static duk_ret_t duk_poke4(duk_context* duk)
return 0;
}

static duk_ret_t duk_peek1(duk_context* duk)
{
s32 address = duk_to_int(duk, 0);

tic_mem* tic = (tic_mem*)getDukCore(duk);
duk_push_uint(duk, tic_api_peek1(tic, address));
return 1;
}

static duk_ret_t duk_poke1(duk_context* duk)
{
s32 address = duk_to_int(duk, 0);
u8 value = duk_to_int(duk, 1);

tic_mem* tic = (tic_mem*)getDukCore(duk);
tic_api_poke1(tic, address, value);

return 0;
}

static duk_ret_t duk_memcpy(duk_context* duk)
{
s32 dest = duk_to_int(duk, 0);
Expand Down
33 changes: 33 additions & 0 deletions src/api/lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,39 @@ static s32 lua_poke4(lua_State* lua)
return 0;
}

static s32 lua_peek1(lua_State* lua)
{
s32 top = lua_gettop(lua);
tic_mem* tic = (tic_mem*)getLuaCore(lua);

if(top == 1)
{
s32 address = getLuaNumber(lua, 1);
lua_pushinteger(lua, tic_api_peek1(tic, address));
return 1;
}
else luaL_error(lua, "invalid parameters, peek1(addr)\n");

return 0;
}

static s32 lua_poke1(lua_State* lua)
{
s32 top = lua_gettop(lua);
tic_mem* tic = (tic_mem*)getLuaCore(lua);

if(top == 2)
{
s32 address = getLuaNumber(lua, 1);
u8 value = getLuaNumber(lua, 2);

tic_api_poke1(tic, address, value);
}
else luaL_error(lua, "invalid parameters, poke1(addr,val)\n");

return 0;
}

static s32 lua_cls(lua_State* lua)
{
s32 top = lua_gettop(lua);
Expand Down
28 changes: 28 additions & 0 deletions src/api/squirrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,34 @@ static SQInteger squirrel_poke4(HSQUIRRELVM vm)
return 0;
}

static SQInteger squirrel_peek1(HSQUIRRELVM vm)
{
tic_mem* tic = (tic_mem*)getSquirrelCore(vm);

// check number of args
if (sq_gettop(vm) != 2)
return sq_throwerror(vm, "invalid parameters, peek4(address)");
s32 address = getSquirrelNumber(vm, 2);

sq_pushinteger(vm, tic_api_peek1(tic, address));
return 1;
}

static SQInteger squirrel_poke1(HSQUIRRELVM vm)
{
tic_mem* tic = (tic_mem*)getSquirrelCore(vm);

if (sq_gettop(vm) != 3)
return sq_throwerror( vm, "invalid parameters, poke4(address,value)" );

s32 address = getSquirrelNumber(vm, 2);
u8 value = getSquirrelNumber(vm, 3);

tic_api_poke1(tic, address, value);

return 0;
}

static SQInteger squirrel_cls(HSQUIRRELVM vm)
{
SQInteger top = sq_gettop(vm);
Expand Down
20 changes: 20 additions & 0 deletions src/api/wren.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class TIC {\n\
foreign static poke(addr, val)\n\
foreign static peek4(addr)\n\
foreign static poke4(addr, val)\n\
foreign static peek1(addr)\n\
foreign static poke1(addr, val)\n\
foreign static memcpy(dst, src, size)\n\
foreign static memset(dst, src, size)\n\
foreign static pmem(index)\n\
Expand Down Expand Up @@ -986,6 +988,24 @@ static void wren_poke4(WrenVM* vm)

tic_api_poke4(tic, address, value);
}
static void wren_peek1(WrenVM* vm)
{
tic_mem* tic = (tic_mem*)getWrenCore(vm);

s32 address = getWrenNumber(vm, 1);

wrenSetSlotDouble(vm, 0, tic_api_peek1(tic, address));
}

static void wren_poke1(WrenVM* vm)
{
tic_mem* tic = (tic_mem*)getWrenCore(vm);

s32 address = getWrenNumber(vm, 1);
u8 value = getWrenNumber(vm, 2);

tic_api_poke1(tic, address, value);
}

static void wren_memcpy(WrenVM* vm)
{
Expand Down
10 changes: 10 additions & 0 deletions src/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ void tic_api_poke4(tic_mem* memory, s32 address, u8 value)
tic_api_poke(memory, address, value, 4);
}

u8 tic_api_peek1(tic_mem* memory, s32 address)
{
return tic_api_peek(memory, address, 1);
}

void tic_api_poke1(tic_mem* memory, s32 address, u8 value)
{
tic_api_poke(memory, address, value, 1);
}

void tic_api_memcpy(tic_mem* memory, s32 dst, s32 src, s32 size)
{
tic_core* core = (tic_core*)memory;
Expand Down