Skip to content

Commit

Permalink
res parameter renamed to bits in peek()/poke() api #1475
Browse files Browse the repository at this point in the history
  • Loading branch information
nesbox committed Nov 3, 2021
1 parent 690c373 commit 2faaecb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
12 changes: 6 additions & 6 deletions src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,29 +354,29 @@ enum
\
\
macro(peek, \
"peek(addr res=8) -> value", \
"peek(addr bits=8) -> value", \
\
"This function allows to read the memory from TIC.\n" \
"It's useful to access resources created with the integrated tools like sprite, maps, sounds, " \
"cartridges data?\n" \
"Never dream to sound a sprite?\n" \
"Address are in hexadecimal format but values are decimal.\n" \
"To write to a memory address, use `poke()`.\n" \
"`res` allowed to be 1,2,4,8.", \
"`bits` allowed to be 1,2,4,8.", \
2, \
u8, \
tic_mem*, s32 address, s32 res) \
tic_mem*, s32 address, s32 bits) \
\
\
macro(poke, \
"poke(addr value res=8)", \
"poke(addr value bits=8)", \
\
"This function allows you to write a single byte to any address in TIC's RAM.\n" \
"The address should be specified in hexadecimal format, the value in decimal.\n" \
"`res` allowed to be 1,2,4,8.", \
"`bits` allowed to be 1,2,4,8.", \
3, \
void, \
tic_mem*, s32 address, u8 value, s32 res) \
tic_mem*, s32 address, u8 value, s32 bits) \
\
\
macro(peek4, \
Expand Down
8 changes: 4 additions & 4 deletions src/api/js.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,21 +497,21 @@ static duk_ret_t duk_mset(duk_context* duk)
static duk_ret_t duk_peek(duk_context* duk)
{
s32 address = duk_to_int(duk, 0);
s32 res = duk_opt_int(duk, 1, BITS_IN_BYTE);
s32 bits = duk_opt_int(duk, 1, BITS_IN_BYTE);

tic_mem* tic = (tic_mem*)getDukCore(duk);
duk_push_uint(duk, tic_api_peek(tic, address, res));
duk_push_uint(duk, tic_api_peek(tic, address, bits));
return 1;
}

static duk_ret_t duk_poke(duk_context* duk)
{
s32 address = duk_to_int(duk, 0);
u8 value = duk_to_int(duk, 1);
s32 res = duk_opt_int(duk, 2, BITS_IN_BYTE);
s32 bits = duk_opt_int(duk, 2, BITS_IN_BYTE);

tic_mem* tic = (tic_mem*)getDukCore(duk);
tic_api_poke(tic, address, value, res);
tic_api_poke(tic, address, value, bits);

return 0;
}
Expand Down
16 changes: 8 additions & 8 deletions src/api/lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ static s32 lua_peek(lua_State* lua)
if(top >= 1)
{
s32 address = getLuaNumber(lua, 1);
s32 res = BITS_IN_BYTE;
s32 bits = BITS_IN_BYTE;

if(top == 2)
res = getLuaNumber(lua, 2);
bits = getLuaNumber(lua, 2);

lua_pushinteger(lua, tic_api_peek(tic, address, res));
lua_pushinteger(lua, tic_api_peek(tic, address, bits));
return 1;
}
else luaL_error(lua, "invalid parameters, peek(addr,res)\n");
else luaL_error(lua, "invalid parameters, peek(addr,bits)\n");

return 0;
}
Expand All @@ -81,14 +81,14 @@ static s32 lua_poke(lua_State* lua)
{
s32 address = getLuaNumber(lua, 1);
u8 value = getLuaNumber(lua, 2);
s32 res = BITS_IN_BYTE;
s32 bits = BITS_IN_BYTE;

if(top == 3)
res = getLuaNumber(lua, 3);
bits = getLuaNumber(lua, 3);

tic_api_poke(tic, address, value, res);
tic_api_poke(tic, address, value, bits);
}
else luaL_error(lua, "invalid parameters, poke(addr,val,res)\n");
else luaL_error(lua, "invalid parameters, poke(addr,val,bits)\n");

return 0;
}
Expand Down
12 changes: 6 additions & 6 deletions src/api/squirrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ static SQInteger squirrel_peek(HSQUIRRELVM vm)
return sq_throwerror(vm, "invalid parameters, peek(address)");

s32 address = getSquirrelNumber(vm, 2);
s32 res = BITS_IN_BYTE;
s32 bits = BITS_IN_BYTE;

if(top == 3)
res = getSquirrelNumber(vm, 3);
bits = getSquirrelNumber(vm, 3);

sq_pushinteger(vm, tic_api_peek(tic, address, res));
sq_pushinteger(vm, tic_api_peek(tic, address, bits));
return 1;
}

Expand All @@ -145,12 +145,12 @@ static SQInteger squirrel_poke(HSQUIRRELVM vm)

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

if(top == 4)
res = getSquirrelNumber(vm, 4);
bits = getSquirrelNumber(vm, 4);

tic_api_poke(tic, address, value, res);
tic_api_poke(tic, address, value, bits);

return 0;
}
Expand Down
16 changes: 8 additions & 8 deletions src/api/wren.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class TIC {\n\
foreign static clip(x, y, w, h)\n\
foreign static peek(addr)\n\
foreign static poke(addr, val)\n\
foreign static peek(addr, res)\n\
foreign static poke(addr, val, res)\n\
foreign static peek(addr, bits)\n\
foreign static poke(addr, val, bits)\n\
foreign static peek4(addr)\n\
foreign static poke4(addr, val)\n\
foreign static memcpy(dst, src, size)\n\
Expand Down Expand Up @@ -950,12 +950,12 @@ static void wren_peek(WrenVM* vm)
tic_mem* tic = (tic_mem*)getWrenCore(vm);

s32 address = getWrenNumber(vm, 1);
s32 res = BITS_IN_BYTE;
s32 bits = BITS_IN_BYTE;

if(wrenGetSlotCount(vm) > 2)
res = getWrenNumber(vm, 2);
bits = getWrenNumber(vm, 2);

wrenSetSlotDouble(vm, 0, tic_api_peek(tic, address, res));
wrenSetSlotDouble(vm, 0, tic_api_peek(tic, address, bits));
}

static void wren_poke(WrenVM* vm)
Expand All @@ -964,11 +964,11 @@ static void wren_poke(WrenVM* vm)

s32 address = getWrenNumber(vm, 1);
u8 value = getWrenNumber(vm, 2) & 0xff;
s32 res = BITS_IN_BYTE;
s32 bits = BITS_IN_BYTE;
if(wrenGetSlotCount(vm) > 3)
res = getWrenNumber(vm, 3);
bits = getWrenNumber(vm, 3);

tic_api_poke(tic, address, value, res);
tic_api_poke(tic, address, value, bits);
}

static void wren_peek4(WrenVM* vm)
Expand Down
8 changes: 4 additions & 4 deletions src/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ static_assert(sizeof(tic_map) < 1024 * 32, "tic_map");
static_assert(sizeof(tic_vram) == TIC_VRAM_SIZE, "tic_vram");
static_assert(sizeof(tic_ram) == TIC_RAM_SIZE, "tic_ram");

u8 tic_api_peek(tic_mem* memory, s32 address, s32 res)
u8 tic_api_peek(tic_mem* memory, s32 address, s32 bits)
{
if (address < 0)
return 0;

const u8* ram = (u8*)&memory->ram;
enum{RamBits = sizeof(tic_ram) * BITS_IN_BYTE};

switch(res)
switch(bits)
{
case 1: if(address < RamBits / 1) return tic_tool_peek1(ram, address);
case 2: if(address < RamBits / 2) return tic_tool_peek2(ram, address);
Expand All @@ -61,7 +61,7 @@ u8 tic_api_peek(tic_mem* memory, s32 address, s32 res)
return 0;
}

void tic_api_poke(tic_mem* memory, s32 address, u8 value, s32 res)
void tic_api_poke(tic_mem* memory, s32 address, u8 value, s32 bits)
{
if (address < 0)
return;
Expand All @@ -70,7 +70,7 @@ void tic_api_poke(tic_mem* memory, s32 address, u8 value, s32 res)
u8* ram = (u8*)&memory->ram;
enum{RamBits = sizeof(tic_ram) * BITS_IN_BYTE};

switch(res)
switch(bits)
{
case 1: if(address < RamBits / 1) {tic_tool_poke1(ram, address, value); core->state.memmask[address >> 2] = 1;} break;
case 2: if(address < RamBits / 2) {tic_tool_poke2(ram, address, value); core->state.memmask[address >> 1] = 1;} break;
Expand Down

0 comments on commit 2faaecb

Please sign in to comment.