no message

This commit is contained in:
BADIM-PC\Vadim 2017-11-30 15:51:52 +03:00
parent c69d36abb7
commit a2e97b018a
8 changed files with 63 additions and 83 deletions

View File

@ -715,6 +715,7 @@ static const struct{duk_c_function func; s32 params;} ApiFunc[] =
{
{NULL, 0},
{NULL, 1},
{NULL, 0},
{duk_print, 6},
{duk_cls, 1},
{duk_pix, 3},
@ -831,5 +832,19 @@ void callJavascriptScanline(tic_mem* memory, s32 row)
void callJavascriptOverlap(tic_mem* memory)
{
tic_machine* machine = (tic_machine*)memory;
duk_context* duk = machine->js;
const char* OvrFunc = ApiKeywords[2];
if(duk_get_global_string(duk, OvrFunc))
{
if(duk_pcall(duk, 0) != 0)
{
machine->data->error(machine->data->data, duk_safe_to_string(duk, -1));
duk_pop(duk);
}
else duk_pop(duk);
}
else duk_pop(duk);
}

View File

@ -1052,7 +1052,7 @@ static void setloaded(lua_State* l, char* name)
static const char* const ApiKeywords[] = API_KEYWORDS;
static const lua_CFunction ApiFunc[] =
{
NULL, NULL, lua_print, lua_cls, lua_pix, lua_line, lua_rect,
NULL, NULL, NULL, lua_print, lua_cls, lua_pix, lua_line, lua_rect,
lua_rectb, lua_spr, lua_btn, lua_btnp, lua_sfx, lua_map, lua_mget,
lua_mset, lua_peek, lua_poke, lua_peek4, lua_poke4, lua_memcpy,
lua_memset, lua_trace, lua_pmem, lua_time, lua_exit, lua_font, lua_mouse,
@ -1254,9 +1254,9 @@ void callLuaOverlap(tic_mem* memory)
if (lua)
{
static const char* OverlapFunc = "overlap";
const char* OvrFunc = ApiKeywords[2];
lua_getglobal(lua, OverlapFunc);
lua_getglobal(lua, OvrFunc);
if(lua_isfunction(lua, -1))
{
if(lua_pcall(lua, 0, 0, 0) != LUA_OK)

View File

@ -84,9 +84,13 @@ typedef struct
tic_scanline scanline;
tic_overlap overlap;
struct
{
tic_overlap callback;
u32 palette[TIC_PALETTE_SIZE];
} ovr;
void (*pixel)(tic_mem* memory, s32 x, s32 y, u8 color);
u32 overlapPalette[TIC_PALETTE_SIZE];
bool initialized;
} MachineState;

View File

@ -1406,29 +1406,6 @@ static void saveProject()
else showPopupMessage("SAVE ERROR :(");
}
static u32* srcPaletteBlit(const u8* src)
{
static u32 pal[TIC_PALETTE_SIZE] = {0};
memset(pal, 0xff, sizeof pal);
u8* dst = (u8*)pal;
const u8* end = src + sizeof(tic_palette);
enum{RGB = sizeof(tic_rgb)};
for(; src != end; dst++, src+=RGB)
for(s32 j = 0; j < RGB; j++)
*dst++ = *(src+(RGB-1)-j);
return pal;
}
static u32* paletteBlit()
{
return srcPaletteBlit(studio.tic->ram.vram.palette.data);
}
static void screen2buffer(u32* buffer, const u32* pixels, SDL_Rect rect)
{
pixels += rect.y * TIC80_FULLWIDTH;
@ -1824,7 +1801,7 @@ static void transparentBlit(u32* out, s32 pitch)
{
const u8* in = studio.tic->ram.vram.screen.data;
const u8* end = in + sizeof(studio.tic->ram.vram.screen);
const u32* pal = srcPaletteBlit(studio.tic->config.palette.data);
const u32* pal = tic_palette_blit(&studio.tic->config.palette);
const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH);
s32 col = 0;
@ -1901,7 +1878,7 @@ static void recordFrame(u32* pixels)
if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2)
{
const u32* pal = srcPaletteBlit(studio.tic->config.palette.data);
const u32* pal = tic_palette_blit(&studio.tic->config.palette);
drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]);
}
@ -2009,7 +1986,7 @@ static void blitCursor(const u8* in)
{
const u8* end = in + sizeof(tic_tile);
const u32* pal = paletteBlit();
const u32* pal = tic_palette_blit(&studio.tic->ram.vram.palette);
u32* out = pixels;
while(in != end)
@ -2321,7 +2298,7 @@ static void setWindowIcon()
u32* pixels = SDL_malloc(Size * Size * sizeof(u32));
const u32* pal = srcPaletteBlit(studio.tic->config.palette.data);
const u32* pal = tic_palette_blit(&studio.tic->config.palette);
for(s32 j = 0, index = 0; j < Size; j++)
for(s32 i = 0; i < Size; i++, index++)

View File

@ -154,14 +154,14 @@ static void dmaPixel(tic_mem* tic, s32 x, s32 y, u8 color)
tic_tool_poke4(tic->ram.vram.screen.data, y * TIC80_WIDTH + x, tic_tool_peek4(tic->ram.vram.mapping, color & 0xf));
}
static void overlapPixel(tic_mem* tic, s32 x, s32 y, u8 color)
static void ovrPixel(tic_mem* tic, s32 x, s32 y, u8 color)
{
tic_machine* machine = (tic_machine*)tic;
enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2};
enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2};
tic->screen[x + y * TIC80_FULLWIDTH + (Left + Top * TIC80_FULLWIDTH)] = machine->state.overlapPalette[tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)];
tic->screen[x + y * TIC80_FULLWIDTH + (Left + Top * TIC80_FULLWIDTH)] = machine->state.ovr.palette[tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)];
}
static void setPixel(tic_machine* machine, s32 x, s32 y, u8 color)
@ -445,7 +445,7 @@ static void api_reset(tic_mem* memory)
tic_machine* machine = (tic_machine*)memory;
machine->state.initialized = false;
machine->state.scanline = NULL;
machine->state.overlap = NULL;
machine->state.ovr.callback = NULL;
machine->state.pixel = dmaPixel;
@ -1207,25 +1207,8 @@ static void api_tick_end(tic_mem* memory)
blip_end_frame(machine->blip, EndTime);
blip_read_samples(machine->blip, machine->memory.samples.buffer, machine->samplerate / TIC_FRAMERATE);
machine->state.pixel = overlapPixel;
// temporary palette blit
{
u32* pal = machine->state.overlapPalette;
const u8* src = memory->cart.palette.data;
memset(pal, 0xff, TIC_PALETTE_SIZE);
u8* dst = (u8*)pal;
const u8* end = src + sizeof(tic_palette);
enum{RGB = sizeof(tic_rgb)};
for(; src != end; dst++, src+=RGB)
for(s32 j = 0; j < RGB; j++)
*dst++ = *(src+(RGB-1)-j);
}
machine->state.pixel = ovrPixel;
memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.palette), sizeof machine->state.ovr.palette);
}
@ -1468,7 +1451,7 @@ static void api_tick(tic_mem* memory, tic_tick_data* data)
if(done)
{
machine->state.scanline = memory->script == tic_script_js ? callJavascriptScanline : callLuaScanline;
machine->state.overlap = memory->script == tic_script_js ? callJavascriptOverlap : callLuaOverlap;
machine->state.ovr.callback = memory->script == tic_script_js ? callJavascriptOverlap : callLuaOverlap;
machine->state.initialized = true;
}
else return;
@ -1493,7 +1476,7 @@ static void api_overlap(tic_mem* memory)
tic_machine* machine = (tic_machine*)memory;
if(machine->state.initialized)
machine->state.overlap(memory);
machine->state.ovr.callback(memory);
}
static double api_time(tic_mem* memory)
@ -1507,7 +1490,7 @@ static void api_sync(tic_mem* tic, bool toCart)
if(toCart)
{
memcpy(&tic->cart.gfx, &tic->ram.gfx, sizeof tic->cart.gfx);
memcpy(&tic->cart.sound, &tic->ram.sound, sizeof tic->cart.sound);
memcpy(&tic->cart.sound, &tic->ram.sound, sizeof tic->cart.sound);
}
else
{
@ -1674,35 +1657,15 @@ static inline void memset4(void *dst, u32 val, u32 dwords)
#endif
}
static u32* paletteBlit(tic_mem* tic)
{
static u32 pal[TIC_PALETTE_SIZE] = {0};
const u8* src = tic->ram.vram.palette.data;
memset(pal, 0xff, sizeof pal);
u8* dst = (u8*)pal;
const u8* end = src + sizeof(tic_palette);
enum{RGB = sizeof(tic_rgb)};
for(; src != end; dst++, src+=RGB)
for(s32 j = 0; j < RGB; j++)
*dst++ = *(src+(RGB-1)-j);
return pal;
}
static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap)
{
u32* out = tic->screen;
const u32* pal = paletteBlit(tic);
const u32* pal = tic_palette_blit(&tic->ram.vram.palette);
if(scanline)
{
scanline(tic, 0);
pal = paletteBlit(tic);
pal = tic_palette_blit(&tic->ram.vram.palette);
}
enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2, Bottom = Top};
@ -1766,7 +1729,7 @@ static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap)
if(scanline && (r < TIC80_HEIGHT-1))
{
scanline(tic, r+1);
pal = paletteBlit(tic);
pal = tic_palette_blit(&tic->ram.vram.palette);
}
}

View File

@ -109,7 +109,7 @@
#define SFX_NOTES {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"}
#define API_KEYWORDS {"TIC", "scanline", "print", "cls", "pix", "line", "rect", "rectb", \
#define API_KEYWORDS {"TIC", "scanline", "OVR", "print", "cls", "pix", "line", "rect", "rectb", \
"spr", "btn", "btnp", "sfx", "map", "mget", "mset", "peek", "poke", "peek4", "poke4", \
"memcpy", "memset", "trace", "pmem", "time", "exit", "font", "mouse", "circ", "circb", "tri", "textri", \
"clip", "music", "sync"}

View File

@ -85,3 +85,23 @@ u32 tic_tool_find_closest_color(const tic_rgb* palette, const tic_rgb* color)
return closetColor;
}
u32* tic_palette_blit(const tic_palette* srcpal)
{
static u32 pal[TIC_PALETTE_SIZE] = {0};
const u8* src = srcpal->data;
memset(pal, 0xff, sizeof pal);
u8* dst = (u8*)pal;
const u8* end = src + sizeof(tic_palette);
enum{RGB = sizeof(tic_rgb)};
for(; src != end; dst++, src+=RGB)
for(s32 j = 0; j < RGB; j++)
*dst++ = *(src+(RGB-1)-j);
return pal;
}

View File

@ -50,4 +50,5 @@ inline u8 tic_tool_peek4(const void* addr, u32 index)
bool tic_tool_parse_note(const char* noteStr, s32* note, s32* octave);
s32 tic_tool_get_pattern_id(const tic_track* track, s32 frame, s32 channel);
void tic_tool_set_pattern_id(tic_track* track, s32 frame, s32 channel, s32 id);
u32 tic_tool_find_closest_color(const tic_rgb* palette, const tic_rgb* color);
u32 tic_tool_find_closest_color(const tic_rgb* palette, const tic_rgb* color);
u32* tic_palette_blit(const tic_palette* src);