TIC-80-guile/src/machine.h

164 lines
3.9 KiB
C
Raw Normal View History

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)
#define API_KEYWORDS {"TIC", "SCN", "OVR", "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
{
tic80_gamepads previous;
2017-09-26 08:59:34 +02: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
u32 holds[tic_keys_count];
2017-12-29 13:25:29 +01:00
} keyboard;
2017-09-26 08:59:34 +02:00
Clip clip;
tic_sound_register_data registers[TIC_SOUND_CHANNELS];
Channel channels[TIC_SOUND_CHANNELS];
struct
{
enum
{
MusicStop = 0,
MusicPlayFrame,
MusicPlay,
} play;
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
{
tic_overlap callback;
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
{
struct duk_hthread* js;
struct lua_State* lua;
2018-02-05 14:52:55 +01:00
struct WrenVM* wren;
2017-09-26 08:59:34 +02:00
};
blip_buffer_t* blip;
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
{
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;
typedef s32(DrawCharFunc)(tic_mem* memory, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale);
s32 drawText(tic_mem* memory, const char* text, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale, DrawCharFunc* func);
s32 drawSpriteFont(tic_mem* memory, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale);
s32 drawFixedSpriteFont(tic_mem* memory, u8 index, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale);
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
2017-12-21 08:28:14 +01:00
const tic_script_config* getLuaScriptConfig();
const tic_script_config* getMoonScriptConfig();
const tic_script_config* getJsScriptConfig();
2018-02-05 14:52:55 +01:00
const tic_script_config* getWrenScriptConfig();