OVERLAP mode renamed to OVERLINE

also, TIC uses palette from VRAM instead cart palette in OVR
This commit is contained in:
BADIM-PC\Vadim 2018-02-27 13:42:08 +03:00
parent 57624e3c77
commit 96e2c19a5f
12 changed files with 74 additions and 58 deletions

View File

@ -915,7 +915,7 @@ static void callJavascriptScanline(tic_mem* memory, s32 row, void* data)
callJavascriptScanlineName(memory, row, data, "scanline"); callJavascriptScanlineName(memory, row, data, "scanline");
} }
static void callJavascriptOverlap(tic_mem* memory, void* data) static void callJavascriptOverline(tic_mem* memory, void* data)
{ {
tic_machine* machine = (tic_machine*)memory; tic_machine* machine = (tic_machine*)memory;
duk_context* duk = machine->js; duk_context* duk = machine->js;
@ -1007,7 +1007,7 @@ static const tic_script_config JsSyntaxConfig =
.close = closeJavascript, .close = closeJavascript,
.tick = callJavascriptTick, .tick = callJavascriptTick,
.scanline = callJavascriptScanline, .scanline = callJavascriptScanline,
.overlap = callJavascriptOverlap, .overline = callJavascriptOverline,
.getOutline = getJsOutline, .getOutline = getJsOutline,
.parse = parseCode, .parse = parseCode,

View File

@ -1307,7 +1307,7 @@ static void callLuaScanline(tic_mem* memory, s32 row, void* data)
callLuaScanlineName(memory, row, data, "scanline"); callLuaScanlineName(memory, row, data, "scanline");
} }
static void callLuaOverlap(tic_mem* memory, void* data) static void callLuaOverline(tic_mem* memory, void* data)
{ {
tic_machine* machine = (tic_machine*)memory; tic_machine* machine = (tic_machine*)memory;
lua_State* lua = machine->lua; lua_State* lua = machine->lua;
@ -1403,7 +1403,7 @@ static const tic_script_config LuaSyntaxConfig =
.close = closeLua, .close = closeLua,
.tick = callLuaTick, .tick = callLuaTick,
.scanline = callLuaScanline, .scanline = callLuaScanline,
.overlap = callLuaOverlap, .overline = callLuaOverline,
.getOutline = getLuaOutline, .getOutline = getLuaOutline,
.parse = parseCode, .parse = parseCode,
@ -1588,7 +1588,7 @@ static const tic_script_config MoonSyntaxConfig =
.close = closeLua, .close = closeLua,
.tick = callLuaTick, .tick = callLuaTick,
.scanline = callLuaScanline, .scanline = callLuaScanline,
.overlap = callLuaOverlap, .overline = callLuaOverline,
.getOutline = getMoonOutline, .getOutline = getMoonOutline,
.parse = parseCode, .parse = parseCode,

View File

@ -103,7 +103,7 @@ typedef struct
struct struct
{ {
tic_overlap callback; tic_overline callback;
u32 palette[TIC_PALETTE_SIZE]; u32 palette[TIC_PALETTE_SIZE];
} ovr; } ovr;

View File

@ -142,6 +142,12 @@ static s32 drawGridButton(Map* map, s32 x, s32 y)
return x; return x;
} }
static bool sheetVisible(Map* map)
{
tic_mem* tic = map->tic;
return tic->api.key(tic, tic_key_shift) || map->sheet.show;
}
static s32 drawSheetButton(Map* map, s32 x, s32 y) static s32 drawSheetButton(Map* map, s32 x, s32 y)
{ {
static const u8 DownIcon[] = static const u8 DownIcon[] =
@ -186,7 +192,7 @@ static s32 drawSheetButton(Map* map, s32 x, s32 y)
} }
} }
drawBitIcon(rect.x, rect.y, map->sheet.show ? UpIcon : DownIcon, over ? (tic_color_dark_gray) : (tic_color_light_blue)); drawBitIcon(rect.x, rect.y, sheetVisible(map) ? UpIcon : DownIcon, over ? (tic_color_dark_gray) : (tic_color_light_blue));
return x; return x;
} }
@ -291,7 +297,7 @@ static void drawTileIndex(Map* map, s32 x, s32 y)
{ {
s32 index = -1; s32 index = -1;
if(map->sheet.show) if(sheetVisible(map))
{ {
tic_rect rect = {TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; tic_rect rect = {TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE};
@ -344,7 +350,7 @@ static void drawMapToolbar(Map* map, s32 x, s32 y)
static void drawSheet(Map* map, s32 x, s32 y) static void drawSheet(Map* map, s32 x, s32 y)
{ {
if(!map->sheet.show)return; if(!sheetVisible(map))return;
tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE};
@ -353,7 +359,7 @@ static void drawSheet(Map* map, s32 x, s32 y)
static void drawSheetOvr(Map* map, s32 x, s32 y) static void drawSheetOvr(Map* map, s32 x, s32 y)
{ {
if(!map->sheet.show)return; if(!sheetVisible(map))return;
tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE};
@ -879,7 +885,7 @@ static void drawMapOvr(Map* map)
tic->api.line(tic, TIC80_WIDTH - screenScrollX, 0, TIC80_WIDTH - screenScrollX, TIC80_HEIGHT, (tic_color_gray)); tic->api.line(tic, TIC80_WIDTH - screenScrollX, 0, TIC80_WIDTH - screenScrollX, TIC80_HEIGHT, (tic_color_gray));
} }
if(!map->sheet.show && checkMousePos(&rect)) if(!sheetVisible(map) && checkMousePos(&rect))
{ {
if(tic->api.key(tic, tic_key_space)) if(tic->api.key(tic, tic_key_space))
{ {
@ -1009,9 +1015,6 @@ static void processKeyboard(Map* map)
if(tic->ram.input.keyboard.data == 0) return; if(tic->ram.input.keyboard.data == 0) return;
map->sheet.show = false;
bool shift = tic->api.key(tic, tic_key_shift);
bool ctrl = tic->api.key(tic, tic_key_ctrl); bool ctrl = tic->api.key(tic, tic_key_ctrl);
switch(getClipboardEvent()) switch(getClipboardEvent())
@ -1038,9 +1041,6 @@ static void processKeyboard(Map* map)
else if(keyWasPressed(tic_key_grave)) map->canvas.grid = !map->canvas.grid; else if(keyWasPressed(tic_key_grave)) map->canvas.grid = !map->canvas.grid;
} }
if(shift)
map->sheet.show = true;
enum{Step = 1}; enum{Step = 1};
if(tic->api.key(tic, tic_key_up)) map->scroll.y -= Step; if(tic->api.key(tic, tic_key_up)) map->scroll.y -= Step;
@ -1083,11 +1083,17 @@ static void onStudioEvent(Map* map, StudioEvent event)
} }
} }
static void overlap(tic_mem* tic, void* data) static void scanline(tic_mem* tic, s32 row, void* data)
{
if(row == 0)
memcpy(tic->ram.vram.palette.data, tic->config.palette.data, sizeof(tic_palette));
}
static void overline(tic_mem* tic, void* data)
{ {
Map* map = (Map*)data; Map* map = (Map*)data;
tic->api.clip(tic, 0, TOOLBAR_SIZE, TIC80_WIDTH - (map->sheet.show ? TIC_SPRITESHEET_SIZE+2 : 0), TIC80_HEIGHT - TOOLBAR_SIZE); tic->api.clip(tic, 0, TOOLBAR_SIZE, TIC80_WIDTH - (sheetVisible(map) ? TIC_SPRITESHEET_SIZE+2 : 0), TIC80_HEIGHT - TOOLBAR_SIZE);
drawMapOvr(map); drawMapOvr(map);
tic->api.clip(tic, 0, 0, TIC80_WIDTH, TIC80_HEIGHT); tic->api.clip(tic, 0, 0, TIC80_WIDTH, TIC80_HEIGHT);
drawSheetOvr(map, TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE); drawSheetOvr(map, TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE);
@ -1134,7 +1140,8 @@ void initMap(Map* map, tic_mem* tic, tic_map* src)
}, },
.history = history_create(src, sizeof(tic_map)), .history = history_create(src, sizeof(tic_map)),
.event = onStudioEvent, .event = onStudioEvent,
.overlap = overlap, .overline = overline,
.scanline = scanline,
}; };
normalizeMap(&map->scroll.x, &map->scroll.y); normalizeMap(&map->scroll.x, &map->scroll.y);

View File

@ -80,9 +80,10 @@ struct Map
struct History* history; struct History* history;
void(*tick)(Map*); void (*tick)(Map*);
void(*event)(Map*, StudioEvent); void (*event)(Map*, StudioEvent);
void(*overlap)(tic_mem* tic, void* data); void (*scanline)(tic_mem* tic, s32 row, void* data);
void (*overline)(tic_mem* tic, void* data);
}; };
void initMap(Map*, tic_mem*, tic_map* src); void initMap(Map*, tic_mem*, tic_map* src);

View File

@ -1625,7 +1625,13 @@ static void onStudioEvent(Sprite* sprite, StudioEvent event)
} }
} }
static void overlap(tic_mem* tic, void* data) static void scanline(tic_mem* tic, s32 row, void* data)
{
if(row == 0)
memcpy(tic->ram.vram.palette.data, tic->config.palette.data, sizeof(tic_palette));
}
static void overline(tic_mem* tic, void* data)
{ {
Sprite* sprite = (Sprite*)data; Sprite* sprite = (Sprite*)data;
@ -1666,6 +1672,7 @@ void initSprite(Sprite* sprite, tic_mem* tic, tic_tiles* src)
.mode = SPRITE_DRAW_MODE, .mode = SPRITE_DRAW_MODE,
.history = history_create(src, TIC_SPRITES * sizeof(tic_tile)), .history = history_create(src, TIC_SPRITES * sizeof(tic_tile)),
.event = onStudioEvent, .event = onStudioEvent,
.overlap = overlap, .overline = overline,
.scanline = scanline,
}; };
} }

View File

@ -63,7 +63,8 @@ struct Sprite
void (*tick)(Sprite*); void (*tick)(Sprite*);
void (*event)(Sprite*, StudioEvent); void (*event)(Sprite*, StudioEvent);
void (*overlap)(tic_mem* tic, void* data); void (*scanline)(tic_mem* tic, s32 row, void* data);
void (*overline)(tic_mem* tic, void* data);
}; };
void initSprite(Sprite*, tic_mem*, tic_tiles* src); void initSprite(Sprite*, tic_mem*, tic_tiles* src);

View File

@ -1208,7 +1208,7 @@ static void setCoverImage()
{ {
enum {Pitch = TIC80_FULLWIDTH*sizeof(u32)}; enum {Pitch = TIC80_FULLWIDTH*sizeof(u32)};
tic->api.blit(tic, tic->api.scanline, tic->api.overlap, NULL); tic->api.blit(tic, tic->api.scanline, tic->api.overline, NULL);
u32* buffer = malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)); u32* buffer = malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32));
@ -1515,11 +1515,6 @@ static void recordFrame(u32* pixels)
} }
} }
static void useSystemPalette()
{
memcpy(impl.studio.tic->ram.vram.palette.data, impl.studio.tic->config.palette.data, sizeof(tic_palette));
}
static void drawPopup() static void drawPopup()
{ {
if(impl.popup.counter > 0) if(impl.popup.counter > 0)
@ -1622,9 +1617,6 @@ static void renderStudio()
memset(tic->ram.registers, 0, sizeof tic->ram.registers); memset(tic->ram.registers, 0, sizeof tic->ram.registers);
impl.studio.tic->api.tick_end(impl.studio.tic); impl.studio.tic->api.tick_end(impl.studio.tic);
if(impl.mode != TIC_RUN_MODE)
useSystemPalette();
} }
static void updateSystemFont() static void updateSystemFont()
@ -1735,34 +1727,38 @@ static void studioTick()
{ {
tic_scanline scanline = NULL; tic_scanline scanline = NULL;
tic_overlap overlap = NULL; tic_overline overline = NULL;
void* data = NULL; void* data = NULL;
switch(impl.mode) switch(impl.mode)
{ {
case TIC_RUN_MODE: case TIC_RUN_MODE:
scanline = tic->api.scanline; scanline = tic->api.scanline;
overlap = tic->api.overlap; overline = tic->api.overline;
break; break;
case TIC_SPRITE_MODE: case TIC_SPRITE_MODE:
{ {
Sprite* sprite = impl.editor[impl.bank.index.sprites].sprite; Sprite* sprite = impl.editor[impl.bank.index.sprites].sprite;
overlap = sprite->overlap; overline = sprite->overline;
scanline = sprite->scanline;
data = sprite; data = sprite;
memcpy(&tic->ram.vram.palette, &tic->cart.palette, sizeof(tic_palette));
} }
break; break;
case TIC_MAP_MODE: case TIC_MAP_MODE:
{ {
Map* map = impl.editor[impl.bank.index.map].map; Map* map = impl.editor[impl.bank.index.map].map;
overlap = map->overlap; overline = map->overline;
data = map; data = map;
memcpy(&tic->ram.vram.palette, &tic->cart.palette, sizeof(tic_palette));
} }
break; break;
default: default:
memcpy(&tic->ram.vram.palette, &tic->config.palette, sizeof(tic_palette));
break; break;
} }
tic->api.blit(tic, scanline, overlap, data); tic->api.blit(tic, scanline, overline, data);
recordFrame(tic->screen); recordFrame(tic->screen);
drawDesyncLabel(tic->screen); drawDesyncLabel(tic->screen);

View File

@ -1393,7 +1393,6 @@ static void api_tick_end(tic_mem* memory)
machine->state.setpix = setPixelOvr; machine->state.setpix = setPixelOvr;
machine->state.getpix = getPixelOvr; machine->state.getpix = getPixelOvr;
machine->state.drawhline = drawHLineOvr; machine->state.drawhline = drawHLineOvr;
memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.palette), sizeof machine->state.ovr.palette);
} }
@ -1667,7 +1666,7 @@ static void api_tick(tic_mem* tic, tic_tick_data* data)
{ {
machine->state.tick = config->tick; machine->state.tick = config->tick;
machine->state.scanline = config->scanline; machine->state.scanline = config->scanline;
machine->state.ovr.callback = config->overlap; machine->state.ovr.callback = config->overline;
machine->state.initialized = true; machine->state.initialized = true;
} }
@ -1686,7 +1685,7 @@ static void api_scanline(tic_mem* memory, s32 row, void* data)
machine->state.scanline(memory, row, data); machine->state.scanline(memory, row, data);
} }
static void api_overlap(tic_mem* memory, void* data) static void api_overline(tic_mem* memory, void* data)
{ {
tic_machine* machine = (tic_machine*)memory; tic_machine* machine = (tic_machine*)memory;
@ -1910,10 +1909,15 @@ static inline void memset4(void *dst, u32 val, u32 dwords)
#endif #endif
} }
static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap, void* data) static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overline overline, void* data)
{ {
const u32* pal = tic_palette_blit(&tic->ram.vram.palette); const u32* pal = tic_palette_blit(&tic->ram.vram.palette);
{
tic_machine* machine = (tic_machine*)tic;
memcpy(machine->state.ovr.palette, pal, sizeof machine->state.ovr.palette);
}
if(scanline) if(scanline)
{ {
scanline(tic, 0, data); scanline(tic, 0, data);
@ -1954,8 +1958,8 @@ static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap, v
memset4(&out[(TIC80_FULLHEIGHT-Bottom) * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], TIC80_FULLWIDTH*Bottom); memset4(&out[(TIC80_FULLHEIGHT-Bottom) * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], TIC80_FULLWIDTH*Bottom);
if(overlap) if(overline)
overlap(tic, data); overline(tic, data);
} }
static void initApi(tic_api* api) static void initApi(tic_api* api)
@ -1992,7 +1996,7 @@ static void initApi(tic_api* api)
INIT_API(time); INIT_API(time);
INIT_API(tick); INIT_API(tick);
INIT_API(scanline); INIT_API(scanline);
INIT_API(overlap); INIT_API(overline);
INIT_API(reset); INIT_API(reset);
INIT_API(pause); INIT_API(pause);
INIT_API(resume); INIT_API(resume);

View File

@ -124,7 +124,7 @@ TIC80_API void tic80_tick(tic80* tic, tic80_input input)
tic80->memory->api.tick(tic80->memory, &tic80->tickData); tic80->memory->api.tick(tic80->memory, &tic80->tickData);
tic80->memory->api.tick_end(tic80->memory); tic80->memory->api.tick_end(tic80->memory);
tic80->memory->api.blit(tic80->memory, tic80->memory->api.scanline, tic80->memory->api.overlap, NULL); tic80->memory->api.blit(tic80->memory, tic80->memory->api.scanline, tic80->memory->api.overline, NULL);
TickCounter++; TickCounter++;
} }

View File

@ -68,7 +68,7 @@ typedef struct
typedef struct tic_mem tic_mem; typedef struct tic_mem tic_mem;
typedef void(*tic_tick)(tic_mem* memory); typedef void(*tic_tick)(tic_mem* memory);
typedef void(*tic_scanline)(tic_mem* memory, s32 row, void* data); typedef void(*tic_scanline)(tic_mem* memory, s32 row, void* data);
typedef void(*tic_overlap)(tic_mem* memory, void* data); typedef void(*tic_overline)(tic_mem* memory, void* data);
typedef struct typedef struct
{ {
@ -99,7 +99,7 @@ struct tic_script_config
tic_tick tick; tic_tick tick;
tic_scanline scanline; tic_scanline scanline;
tic_overlap overlap; tic_overline overline;
}; };
const tic_outline_item* (*getOutline)(const char* code, s32* size); const tic_outline_item* (*getOutline)(const char* code, s32* size);
@ -150,7 +150,7 @@ typedef struct
double (*time) (tic_mem* memory); double (*time) (tic_mem* memory);
void (*tick) (tic_mem* memory, tic_tick_data* data); void (*tick) (tic_mem* memory, tic_tick_data* data);
void (*scanline) (tic_mem* memory, s32 row, void* data); void (*scanline) (tic_mem* memory, s32 row, void* data);
void (*overlap) (tic_mem* memory, void* data); void (*overline) (tic_mem* memory, void* data);
void (*reset) (tic_mem* memory); void (*reset) (tic_mem* memory);
void (*pause) (tic_mem* memory); void (*pause) (tic_mem* memory);
void (*resume) (tic_mem* memory); void (*resume) (tic_mem* memory);
@ -164,7 +164,7 @@ typedef struct
void (*tick_start) (tic_mem* memory, const tic_sfx* sfx, const tic_music* music); void (*tick_start) (tic_mem* memory, const tic_sfx* sfx, const tic_music* music);
void (*tick_end) (tic_mem* memory); void (*tick_end) (tic_mem* memory);
void (*blit) (tic_mem* tic, tic_scanline scanline, tic_overlap overlap, void* data); void (*blit) (tic_mem* tic, tic_scanline scanline, tic_overline overline, void* data);
const tic_script_config* (*get_script_config)(tic_mem* memory); const tic_script_config* (*get_script_config)(tic_mem* memory);
} tic_api; } tic_api;

View File

@ -36,7 +36,7 @@ static WrenHandle* game_class;
static WrenHandle* new_handle; static WrenHandle* new_handle;
static WrenHandle* update_handle; static WrenHandle* update_handle;
static WrenHandle* scanline_handle; static WrenHandle* scanline_handle;
static WrenHandle* overlap_handle; static WrenHandle* overline_handle;
static bool loaded = false; static bool loaded = false;
@ -199,7 +199,7 @@ static void closeWren(tic_mem* tic)
wrenReleaseHandle(machine->wren, new_handle); wrenReleaseHandle(machine->wren, new_handle);
wrenReleaseHandle(machine->wren, update_handle); wrenReleaseHandle(machine->wren, update_handle);
wrenReleaseHandle(machine->wren, scanline_handle); wrenReleaseHandle(machine->wren, scanline_handle);
wrenReleaseHandle(machine->wren, overlap_handle); wrenReleaseHandle(machine->wren, overline_handle);
if (game_class != NULL) { if (game_class != NULL) {
wrenReleaseHandle(machine->wren, game_class); wrenReleaseHandle(machine->wren, game_class);
} }
@ -1263,7 +1263,7 @@ static bool initWren(tic_mem* tic, const char* code)
new_handle = wrenMakeCallHandle(vm, "new()"); new_handle = wrenMakeCallHandle(vm, "new()");
update_handle = wrenMakeCallHandle(vm, TIC_FN "()"); update_handle = wrenMakeCallHandle(vm, TIC_FN "()");
scanline_handle = wrenMakeCallHandle(vm, SCN_FN "(_)"); scanline_handle = wrenMakeCallHandle(vm, SCN_FN "(_)");
overlap_handle = wrenMakeCallHandle(vm, OVR_FN "()"); overline_handle = wrenMakeCallHandle(vm, OVR_FN "()");
// create game class // create game class
if (game_class) if (game_class)
@ -1313,7 +1313,7 @@ static void callWrenScanline(tic_mem* memory, s32 row, void* data)
} }
} }
static void callWrenOverlap(tic_mem* memory, void* data) static void callWrenOverline(tic_mem* memory, void* data)
{ {
tic_machine* machine = (tic_machine*)memory; tic_machine* machine = (tic_machine*)memory;
WrenVM* vm = machine->wren; WrenVM* vm = machine->wren;
@ -1322,7 +1322,7 @@ static void callWrenOverlap(tic_mem* memory, void* data)
{ {
wrenEnsureSlots(vm, 1); wrenEnsureSlots(vm, 1);
wrenSetSlotHandle(vm, 0, game_class); wrenSetSlotHandle(vm, 0, game_class);
wrenCall(vm, overlap_handle); wrenCall(vm, overline_handle);
} }
} }
@ -1350,7 +1350,7 @@ static const tic_script_config WrenSyntaxConfig =
.close = closeWren, .close = closeWren,
.tick = callWrenTick, .tick = callWrenTick,
.scanline = callWrenScanline, .scanline = callWrenScanline,
.overlap = callWrenOverlap, .overline = callWrenOverline,
.getOutline = getWrenOutline, .getOutline = getWrenOutline,
.parse = parseCode, .parse = parseCode,