this repo has no description
1// MIT License
2
3// Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com
4
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#pragma once
24
25#include <stdbool.h>
26#include <string.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <stddef.h>
30
31#include "tic.h"
32#include "api.h"
33#include "script.h"
34#include "defines.h"
35#include "tools.h"
36#include "system.h"
37#include "anim.h"
38#include "ext/png.h"
39
40#define KEYBOARD_HOLD 20
41#define KEYBOARD_PERIOD 3
42
43#ifdef BAREMETALPI
44#define TIC_LOCAL "../.tic80/"
45#else
46#define TIC_LOCAL ".local/"
47#endif
48#define TIC_LOCAL_VERSION TIC_LOCAL TIC_VERSION_HASH "/"
49#define TIC_CACHE TIC_LOCAL "cache/"
50
51#define TOOLBAR_SIZE 7
52#define STUDIO_TEXT_WIDTH (TIC_FONT_WIDTH)
53#define STUDIO_TEXT_HEIGHT (TIC_FONT_HEIGHT+1)
54#define STUDIO_TEXT_BUFFER_WIDTH (TIC80_WIDTH / STUDIO_TEXT_WIDTH)
55#define STUDIO_TEXT_BUFFER_HEIGHT (TIC80_HEIGHT / STUDIO_TEXT_HEIGHT)
56#define STUDIO_TEXT_BUFFER_SIZE (STUDIO_TEXT_BUFFER_WIDTH * STUDIO_TEXT_BUFFER_HEIGHT)
57#define STUDIO_ANIM_TIME 8
58
59#define TIC_COLOR_BG tic_color_black
60
61#define CONFIG_TIC "config.tic"
62#define CONFIG_TIC_PATH TIC_LOCAL_VERSION CONFIG_TIC
63
64#define CART_EXT ".tic"
65#define PNG_EXT ".png"
66
67#if defined(CRT_SHADER_SUPPORT)
68# define CRT_CMD_PARAM(macro) \
69 macro(crt, bool, BOOLEAN, "", "enable CRT monitor effect")
70#else
71# define CRT_CMD_PARAM(macro)
72#endif
73
74#define CMD_PARAMS_LIST(macro) \
75 macro(skip, int, BOOLEAN, "", "skip startup animation") \
76 macro(volume, s32, INTEGER, "=<int>", "global volume value [0-15]") \
77 macro(cli, int, BOOLEAN, "", "console only output") \
78 macro(fullscreen, int, BOOLEAN, "", "enable fullscreen mode") \
79 macro(vsync, int, BOOLEAN, "", "enable VSYNC") \
80 macro(soft, int, BOOLEAN, "", "use software rendering") \
81 macro(fs, char*, STRING, "=<str>", "path to the file system folder") \
82 macro(scale, s32, INTEGER, "=<int>", "main window scale") \
83 macro(cmd, char*, STRING, "=<str>", "run commands in the console") \
84 macro(keepcmd, int, BOOLEAN, "", "re-execute commands on every run") \
85 macro(version, int, BOOLEAN, "", "print program version") \
86 CRT_CMD_PARAM(macro)
87
88#define SHOW_TOOLTIP(STUDIO, FORMAT, ...) \
89do{ \
90 static const char Format[] = FORMAT; \
91 static char buf[sizeof Format]; \
92 sprintf(buf, Format, __VA_ARGS__); \
93 showTooltip(STUDIO, buf); \
94}while(0)
95
96typedef struct
97{
98 char *cart;
99#define CMD_PARAMS_DEF(name, ctype, type, post, help) ctype name;
100 CMD_PARAMS_LIST(CMD_PARAMS_DEF)
101#undef CMD_PARAMS_DEF
102
103#if defined(BUILD_EDITORS)
104 const char *codeexport;
105 const char *codeimport;
106 s32 delay;
107 s32 lowerlimit;
108 s32 upperlimit;
109 s32 battletime;
110
111 int fft;
112 int fftlist;
113 int fftcaptureplaybackdevices;
114 const char *fftdevice;
115#endif
116} StartArgs;
117
118typedef enum
119{
120 TIC_START_MODE,
121 TIC_CONSOLE_MODE,
122 TIC_RUN_MODE,
123 TIC_CODE_MODE,
124 TIC_SPRITE_MODE,
125 TIC_MAP_MODE,
126 TIC_WORLD_MODE,
127 TIC_SFX_MODE,
128 TIC_MUSIC_MODE,
129 TIC_MENU_MODE,
130 TIC_SURF_MODE,
131
132 TIC_MODES_COUNT
133} EditorMode;
134
135typedef enum
136{
137 VI_NORMAL,
138 VI_INSERT,
139 VI_SELECT,
140 VI_SEEK,
141 VI_SEEK_BACK,
142} ViMode;
143
144enum
145{
146 tic_icon_cut = 80,
147 tic_icon_copy = 81,
148 tic_icon_paste = 82,
149 tic_icon_undo = 83,
150 tic_icon_redo = 84,
151 tic_icon_bank = 85,
152 tic_icon_pin = 86,
153 tic_icon_tab = 87,
154 tic_icon_code = 88,
155 tic_icon_sprite = 89,
156 tic_icon_map = 90,
157 tic_icon_sfx = 91,
158 tic_icon_music = 92,
159 tic_icon_rec = 93,
160 tic_icon_rec2 = 94,
161 tic_icon_bookmark = 95,
162 tic_icon_shadow = 96,
163 tic_icon_shadow2 = 97,
164 tic_icon_run = 98,
165 tic_icon_hand = 99,
166 tic_icon_find = 100,
167 tic_icon_goto = 101,
168 tic_icon_outline = 102,
169 tic_icon_world = 103,
170 tic_icon_grid = 104,
171 tic_icon_down = 105,
172 tic_icon_up = 106,
173 tic_icon_fill = 107,
174 tic_icon_select = 108,
175 tic_icon_pen = 109,
176 tic_icon_tiles = 110,
177 tic_icon_sprites = 111,
178 tic_icon_left = 112,
179 tic_icon_right = 113,
180 tic_icon_piano = 114,
181 tic_icon_tracker = 115,
182 tic_icon_follow = 116,
183 tic_icon_sustain = 117,
184 tic_icon_playnow = 118,
185 tic_icon_playframe = 119,
186 tic_icon_stop = 120,
187 tic_icon_rgb = 121,
188 tic_icon_tinyleft = 122,
189 tic_icon_pos = 123,
190 tic_icon_tinyright = 124,
191 tic_icon_bigup = 125,
192 tic_icon_bigdown = 126,
193 tic_icon_bigleft = 127,
194 tic_icon_bigright = 128,
195 tic_icon_fliphorz = 129,
196 tic_icon_flipvert = 130,
197 tic_icon_rotate = 131,
198 tic_icon_erase = 132,
199 tic_icon_bigpen = 133,
200 tic_icon_bigpicker = 134,
201 tic_icon_bigselect = 135,
202 tic_icon_bigfill = 136,
203 tic_icon_loop = 137,
204};
205
206void setCursor(Studio* studio, tic_cursor id);
207
208bool checkMousePos(Studio* studio, const tic_rect* rect);
209bool checkMouseClick(Studio* studio, const tic_rect* rect, tic_mouse_btn button);
210bool checkMouseDblClick(Studio* studio, const tic_rect* rect, tic_mouse_btn button);
211bool checkMouseDown(Studio* studio, const tic_rect* rect, tic_mouse_btn button);
212
213void drawToolbar(Studio* studio, tic_mem* tic, bool bg);
214void drawBitIcon(Studio* studio, s32 id, s32 x, s32 y, u8 color);
215
216tic_cartridge* loadPngCart(png_buffer buffer);
217void studioRomLoaded(Studio* studio);
218void studioRomSaved(Studio* studio);
219void studioConfigChanged(Studio* studio);
220
221void setStudioMode(Studio* studio, EditorMode mode);
222EditorMode getStudioMode(Studio* studio);
223void exitStudio(Studio* studio);
224
225void setStudioViMode(Studio* studio, ViMode mode);
226ViMode getStudioViMode(Studio* studio);
227bool checkStudioViMode(Studio* studio, ViMode mode);
228
229void toClipboard(const void* data, s32 size, bool flip);
230bool fromClipboard(void* data, s32 size, bool flip, bool remove_white_spaces, bool sameSize);
231
232typedef enum
233{
234 TIC_CLIPBOARD_NONE,
235 TIC_CLIPBOARD_CUT,
236 TIC_CLIPBOARD_COPY,
237 TIC_CLIPBOARD_PASTE,
238} ClipboardEvent;
239
240ClipboardEvent getClipboardEvent(Studio* studio);
241
242typedef enum
243{
244 TIC_TOOLBAR_CUT,
245 TIC_TOOLBAR_COPY,
246 TIC_TOOLBAR_PASTE,
247 TIC_TOOLBAR_UNDO,
248 TIC_TOOLBAR_REDO,
249} StudioEvent;
250
251void setStudioEvent(Studio* studio, StudioEvent event);
252void showTooltip(Studio* studio, const char* text);
253
254void setSpritePixel(tic_tile* tiles, s32 x, s32 y, u8 color);
255u8 getSpritePixel(tic_tile* tiles, s32 x, s32 y);
256
257typedef void(*ConfirmCallback)(Studio* studio, bool yes, void* data);
258void confirmDialog(Studio* studio, const char** text, s32 rows, ConfirmCallback callback, void* data);
259void confirmLoadCart(Studio* studio, ConfirmCallback callback, void* data);
260
261bool studioCartChanged(Studio* studio);
262void playSystemSfx(Studio* studio, s32 id);
263
264void gotoMenu(Studio* studio);
265void gotoCode(Studio* studio);
266void gotoSurf(Studio* studio);
267
268void runGame(Studio* studio);
269void exitGame(Studio* studio);
270void resumeGame(Studio* studio);
271void saveProject(Studio* studio);
272
273tic_tiles* getBankTiles(Studio* studio);
274tic_palette* getBankPalette(Studio* studio, bool bank);
275tic_flags* getBankFlags(Studio* studio);
276tic_map* getBankMap(Studio* studio);
277
278char getKeyboardText(Studio* studio);
279bool keyWasPressed(Studio* studio, tic_key key);
280bool enterWasPressed(Studio* studio);
281bool anyKeyWasPressed(Studio* studio);
282bool ticEnterWasPressed(tic_mem* tic, s32 hold, s32 period);
283
284const StudioConfig* getConfig(Studio* studio);
285struct Start* getStartScreen(Studio* studio);
286struct Sprite* getSpriteEditor(Studio* studio);
287
288const char* studioExportMusic(Studio* studio, s32 track, s32 bank, const char* filename);
289const char* studioExportSfx(Studio* studio, s32 sfx, const char* filename);
290
291tic_mem* getMemory(Studio* studio);
292
293const char* md5str(const void* data, s32 length);
294void sfx_stop(tic_mem* tic, s32 channel);
295s32 calcWaveAnimation(tic_mem* tic, u32 index, s32 channel);
296void map2ram(tic_ram* ram, const tic_map* src);
297void tiles2ram(tic_ram* ram, const tic_tiles* src);
298void fadePalette(tic_palette* pal, s32 value);
299bool project_ext(const char* name);
300
301#if defined(BUILD_EDITORS)
302
303typedef struct
304{
305 char* exp;
306 char* imp;
307
308 struct
309 {
310 tic_code code;
311 char postag[32];
312 } last;
313
314 s32 delay;
315 s32 ticks;
316
317 struct
318 {
319 s32 lower;
320 s32 upper;
321 s32 current;
322 } limit;
323
324 struct
325 {
326 s32 started;
327 s32 time;
328 s32 left;
329
330 bool hidetime;
331 } battle;
332
333} Bytebattle;
334
335Bytebattle* getBytebattle(Studio* studio);
336
337#endif