no message

This commit is contained in:
BADIM-PC\Vadim 2017-12-29 18:22:21 +03:00
parent ca0a7c7167
commit 7e9cf5648f
3 changed files with 26 additions and 31 deletions

View File

@ -787,26 +787,23 @@ static s32 lua_key(lua_State* lua)
s32 top = lua_gettop(lua); s32 top = lua_gettop(lua);
tic80_input* input = &tic->ram.input;
enum{Count = COUNT_OF(input->keyboard.keys)};
if (top == 0) if (top == 0)
{ {
lua_pushboolean(lua, tic->api.key(tic, tic_key_unknown)); lua_pushinteger(lua, tic->api.key(tic, tic_key_unknown));
return 1;
} }
else if (top == 1) else if (top == 1)
{ {
tic_key key = getLuaNumber(lua, 1) + TIC_KEY_START_INDEX; tic_key key = getLuaNumber(lua, 1) + TIC_KEY_START_INDEX;
lua_pushboolean(lua, tic->api.key(tic, key)); lua_pushboolean(lua, tic->api.key(tic, key));
return 1;
} }
else luaL_error(lua, "invalid params, key [code]\n"); else
{
luaL_error(lua, "invalid params, key [code]\n");
return 0;
}
return 0; return 1;
} }
static s32 lua_keyp(lua_State* lua) static s32 lua_keyp(lua_State* lua)
@ -818,11 +815,11 @@ static s32 lua_keyp(lua_State* lua)
if (top == 0) if (top == 0)
{ {
lua_pushboolean(lua, tic->api.keyp(tic, tic_key_unknown, -1, -1)); lua_pushinteger(lua, tic->api.keyp(tic, tic_key_unknown, -1, -1));
} }
else if(top == 1) else if(top == 1)
{ {
tic_key key = getLuaNumber(lua, 1) + TIC_KEY_START_INDEX;; tic_key key = getLuaNumber(lua, 1) + TIC_KEY_START_INDEX;
lua_pushboolean(lua, tic->api.keyp(tic, key, -1, -1)); lua_pushboolean(lua, tic->api.keyp(tic, key, -1, -1));
} }

View File

@ -100,13 +100,13 @@ static inline s32 note2freq(double note)
static inline s32 freq2period(double freq) static inline s32 freq2period(double freq)
{ {
if(freq == 0.0) return MAX_PERIOD_VALUE; if(freq == 0.0) return MAX_PERIOD_VALUE;
enum {Rate = CLOCKRATE / ENVELOPE_VALUES}; enum {Rate = CLOCKRATE / ENVELOPE_VALUES};
s32 period = round((double)Rate / freq - 1.0); s32 period = round((double)Rate / freq - 1.0);
if(period < MIN_PERIOD_VALUE) return MIN_PERIOD_VALUE; if(period < MIN_PERIOD_VALUE) return MIN_PERIOD_VALUE;
if(period > MAX_PERIOD_VALUE) return MAX_PERIOD_VALUE; if(period > MAX_PERIOD_VALUE) return MAX_PERIOD_VALUE;
return period; return period;
} }
@ -933,7 +933,7 @@ static void api_tri(tic_mem* memory, s32 x1, s32 y1, s32 x2, s32 y2, s32 x3, s32
s32 xl = max(SidesBuffer.Left[y], machine->state.clip.l); s32 xl = max(SidesBuffer.Left[y], machine->state.clip.l);
s32 xr = min(SidesBuffer.Right[y]+1, machine->state.clip.r); s32 xr = min(SidesBuffer.Right[y]+1, machine->state.clip.r);
machine->state.drawhline(&machine->memory, xl, xr, y, final_color); machine->state.drawhline(&machine->memory, xl, xr, y, final_color);
} }
} }
@ -1648,19 +1648,14 @@ static u32 api_btnp(tic_mem* tic, s32 index, s32 hold, s32 period)
return ((~previous.data) & machine->memory.ram.input.gamepads.data) & (1 << index); return ((~previous.data) & machine->memory.ram.input.gamepads.data) & (1 << index);
} }
static bool api_key(tic_mem* tic, tic_key key) static u32 api_key(tic_mem* tic, tic_key key)
{ {
if(key >= TIC_KEY_START_INDEX) return key >= TIC_KEY_START_INDEX
return isKeyPressed(&tic->ram.input.keyboard, key); ? isKeyPressed(&tic->ram.input.keyboard, key)
: tic->ram.input.keyboard.data;
for(s32 i = 0; i < TIC_KEY_BUFFER; i++)
if(isKeyPressed(&tic->ram.input.keyboard, i))
return true;
return false;
} }
static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period) static u32 api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
{ {
tic_machine* machine = (tic_machine*)tic; tic_machine* machine = (tic_machine*)tic;
@ -1677,6 +1672,8 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
return !prevDown && down; return !prevDown && down;
} }
tic80_keyboard prev = {.data = 0};
for(s32 i = 0; i < TIC_KEY_BUFFER; i++) for(s32 i = 0; i < TIC_KEY_BUFFER; i++)
{ {
tic_key key = tic->ram.input.keyboard.keys[i]; tic_key key = tic->ram.input.keyboard.keys[i];
@ -1684,6 +1681,7 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
if(key) if(key)
{ {
bool wasPressed = false; bool wasPressed = false;
for(s32 p = 0; p < TIC_KEY_BUFFER; p++) for(s32 p = 0; p < TIC_KEY_BUFFER; p++)
{ {
if(machine->state.keyboard.previous.keys[p] == key) if(machine->state.keyboard.previous.keys[p] == key)
@ -1694,11 +1692,11 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
} }
if(!wasPressed) if(!wasPressed)
return true; prev.keys[i] = key;
} }
} }
return false; return prev.data;
} }

View File

@ -154,8 +154,8 @@ typedef struct
void (*resume) (tic_mem* memory); void (*resume) (tic_mem* memory);
void (*sync) (tic_mem* memory, u32 mask, s32 bank, bool toCart); void (*sync) (tic_mem* memory, u32 mask, s32 bank, bool toCart);
u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period); u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period);
bool (*key) (tic_mem* memory, tic_key key); u32 (*key) (tic_mem* memory, tic_key key);
bool (*keyp) (tic_mem* memory, tic_key key, s32 hold, s32 period); u32 (*keyp) (tic_mem* memory, tic_key key, s32 hold, s32 period);
void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette); void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette);
s32 (*save) (const tic_cartridge* rom, u8* buffer); s32 (*save) (const tic_cartridge* rom, u8* buffer);