2017-09-26 08:59:34 +02:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
// Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com
|
|
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
// SOFTWARE.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ticapi.h"
|
|
|
|
#include "tools.h"
|
2018-01-10 15:11:22 +01:00
|
|
|
#include "blip_buf.h"
|
2017-09-26 08:59:34 +02:00
|
|
|
|
|
|
|
#define SFX_DEF_SPEED (1 << SFX_SPEED_BITS)
|
|
|
|
|
2018-02-05 19:55:15 +01:00
|
|
|
#define TIC_FN "TIC"
|
|
|
|
#define SCN_FN "SCN"
|
|
|
|
#define OVR_FN "OVR"
|
|
|
|
|
|
|
|
#define API_KEYWORDS {TIC_FN, SCN_FN, OVR_FN, "print", "cls", "pix", "line", "rect", "rectb", \
|
2017-12-21 08:40:56 +01:00
|
|
|
"spr", "btn", "btnp", "sfx", "map", "mget", "mset", "peek", "poke", "peek4", "poke4", \
|
|
|
|
"memcpy", "memset", "trace", "pmem", "time", "exit", "font", "mouse", "circ", "circb", "tri", "textri", \
|
2017-12-29 13:25:29 +01:00
|
|
|
"clip", "music", "sync", "reset", "key", "keyp"}
|
2017-12-21 08:40:56 +01:00
|
|
|
|
2017-09-26 08:59:34 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
s32 time; /* clock time of next delta */
|
|
|
|
s32 phase; /* position within waveform */
|
|
|
|
s32 amp; /* current amplitude in delta buffer */
|
|
|
|
}tic_sound_register_data;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
s32 tick;
|
|
|
|
tic_sfx_pos pos;
|
|
|
|
s32 index;
|
|
|
|
u16 freq;
|
|
|
|
u8 volume:4;
|
|
|
|
s8 speed:SFX_SPEED_BITS;
|
|
|
|
s32 duration;
|
|
|
|
} Channel;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
s32 l;
|
|
|
|
s32 t;
|
|
|
|
s32 r;
|
|
|
|
s32 b;
|
|
|
|
} Clip;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2017-12-27 13:47:33 +01:00
|
|
|
tic80_gamepads previous;
|
2017-09-26 08:59:34 +02:00
|
|
|
|
2017-12-27 13:47:33 +01:00
|
|
|
u32 holds[sizeof(tic80_gamepads) * BITS_IN_BYTE];
|
|
|
|
} gamepads;
|
2017-09-26 08:59:34 +02:00
|
|
|
|
2017-12-29 13:25:29 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
tic80_keyboard previous;
|
2017-12-29 15:59:07 +01:00
|
|
|
|
2018-01-03 13:52:12 +01:00
|
|
|
u32 holds[tic_keys_count];
|
2017-12-29 13:25:29 +01:00
|
|
|
} keyboard;
|
|
|
|
|
2017-09-26 08:59:34 +02:00
|
|
|
Clip clip;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2018-09-17 10:22:01 +02:00
|
|
|
tic_sound_register_data left[TIC_SOUND_CHANNELS];
|
|
|
|
tic_sound_register_data right[TIC_SOUND_CHANNELS];
|
|
|
|
} registers;
|
2017-09-26 08:59:34 +02:00
|
|
|
|
|
|
|
Channel channels[TIC_SOUND_CHANNELS];
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
s32 ticks;
|
|
|
|
Channel channels[TIC_SOUND_CHANNELS];
|
|
|
|
} music;
|
|
|
|
|
2017-12-21 08:28:14 +01:00
|
|
|
tic_tick tick;
|
2017-11-30 10:21:34 +01:00
|
|
|
tic_scanline scanline;
|
2017-11-30 11:10:20 +01:00
|
|
|
|
2017-11-30 13:51:52 +01:00
|
|
|
struct
|
|
|
|
{
|
2018-02-27 11:42:08 +01:00
|
|
|
tic_overline callback;
|
2017-11-30 13:51:52 +01:00
|
|
|
u32 palette[TIC_PALETTE_SIZE];
|
|
|
|
} ovr;
|
|
|
|
|
2017-12-01 09:25:07 +01:00
|
|
|
void (*setpix)(tic_mem* memory, s32 x, s32 y, u8 color);
|
|
|
|
u8 (*getpix)(tic_mem* memory, s32 x, s32 y);
|
2017-12-17 00:00:50 +01:00
|
|
|
void (*drawhline)(tic_mem* memory, s32 xl, s32 xr, s32 y, u8 color);
|
2017-11-30 11:10:20 +01:00
|
|
|
|
2017-12-17 20:11:01 +01:00
|
|
|
u32 synced;
|
|
|
|
|
2017-09-26 08:59:34 +02:00
|
|
|
bool initialized;
|
|
|
|
} MachineState;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
tic_mem memory; // it should be first
|
|
|
|
tic_api api;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2018-05-16 05:33:57 +02:00
|
|
|
#if defined(TIC_BUILD_WITH_LUA) || defined(TIC_BUILD_WITH_MOON) || defined(TIC_BUILD_WITH_FENNEL)
|
2018-02-16 13:43:30 +01:00
|
|
|
struct lua_State* lua;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(TIC_BUILD_WITH_JS)
|
2017-09-26 08:59:34 +02:00
|
|
|
struct duk_hthread* js;
|
2018-02-16 13:43:30 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(TIC_BUILD_WITH_WREN)
|
|
|
|
struct WrenVM* wren;
|
|
|
|
#endif
|
2018-08-02 21:06:48 +02:00
|
|
|
|
|
|
|
#if defined(TIC_BUILD_WITH_SQUIRREL)
|
|
|
|
struct SQVM* squirrel;
|
|
|
|
#endif
|
|
|
|
|
2017-09-26 08:59:34 +02:00
|
|
|
};
|
|
|
|
|
2018-09-17 10:22:01 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
blip_buffer_t* left;
|
|
|
|
blip_buffer_t* right;
|
|
|
|
} blip;
|
|
|
|
|
2017-09-26 08:59:34 +02:00
|
|
|
s32 samplerate;
|
2017-12-10 10:12:09 +01:00
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
const tic_sfx* sfx;
|
|
|
|
const tic_music* music;
|
|
|
|
} sound;
|
2017-09-26 08:59:34 +02:00
|
|
|
|
|
|
|
tic_tick_data* data;
|
|
|
|
|
|
|
|
MachineState state;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2017-11-30 14:42:06 +01:00
|
|
|
MachineState state;
|
2017-12-19 12:02:56 +01:00
|
|
|
tic_ram ram;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u64 start;
|
|
|
|
u64 paused;
|
|
|
|
} time;
|
2017-09-26 08:59:34 +02:00
|
|
|
} pause;
|
|
|
|
|
|
|
|
} tic_machine;
|
|
|
|
|
2018-08-03 23:36:53 +02:00
|
|
|
typedef s32(DrawCharFunc)(tic_mem* memory, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale, bool alt);
|
|
|
|
s32 drawText(tic_mem* memory, const char* text, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale, DrawCharFunc* func, bool alt);
|
|
|
|
s32 drawSpriteFont(tic_mem* memory, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale, bool alt);
|
|
|
|
s32 drawFixedSpriteFont(tic_mem* memory, u8 index, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale, bool alt);
|
2017-12-23 16:19:51 +01:00
|
|
|
void parseCode(const tic_script_config* config, const char* start, u8* color, const tic_code_theme* theme);
|
2017-09-26 08:59:34 +02:00
|
|
|
|
2018-08-02 21:06:48 +02:00
|
|
|
#if defined(TIC_BUILD_WITH_SQUIRREL)
|
|
|
|
const tic_script_config* getSquirrelScriptConfig();
|
|
|
|
#endif
|
|
|
|
|
2018-02-16 13:43:30 +01:00
|
|
|
#if defined(TIC_BUILD_WITH_LUA)
|
2017-12-21 08:28:14 +01:00
|
|
|
const tic_script_config* getLuaScriptConfig();
|
2018-02-16 13:43:30 +01:00
|
|
|
|
|
|
|
# if defined(TIC_BUILD_WITH_MOON)
|
2017-12-21 08:28:14 +01:00
|
|
|
const tic_script_config* getMoonScriptConfig();
|
2018-02-16 13:43:30 +01:00
|
|
|
# endif
|
|
|
|
|
2018-05-16 05:33:57 +02:00
|
|
|
# if defined(TIC_BUILD_WITH_FENNEL)
|
|
|
|
const tic_script_config* getFennelConfig();
|
|
|
|
# endif
|
|
|
|
|
2018-02-16 13:43:30 +01:00
|
|
|
#endif /* defined(TIC_BUILD_WITH_LUA) */
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(TIC_BUILD_WITH_JS)
|
2017-12-21 08:28:14 +01:00
|
|
|
const tic_script_config* getJsScriptConfig();
|
2018-02-16 13:43:30 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(TIC_BUILD_WITH_WREN)
|
2018-02-05 14:52:55 +01:00
|
|
|
const tic_script_config* getWrenScriptConfig();
|
2018-02-16 13:43:30 +01:00
|
|
|
#endif
|