1 |
nishi |
1 |
/*
|
|
|
2 |
* Troy's TMS9918 Emulator - Core interface
|
|
|
3 |
*
|
|
|
4 |
* Copyright (c) 2021 Troy Schrapel
|
|
|
5 |
*
|
|
|
6 |
* This code is licensed under the MIT license
|
|
|
7 |
*
|
|
|
8 |
* https://github.com/visrealm/vrEmuTms9918
|
|
|
9 |
*
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
#ifndef _VR_EMU_TMS9918_H_
|
|
|
13 |
#define _VR_EMU_TMS9918_H_
|
|
|
14 |
|
|
|
15 |
/* ------------------------------------------------------------------
|
|
|
16 |
* LINKAGE MODES:
|
|
|
17 |
*
|
|
|
18 |
* Default (nothing defined): When your executable is using vrEmuTms9918 as a DLL
|
|
|
19 |
* VR_6502_EMU_COMPILING_DLL: When compiling vrEmuTms9918 as a DLL
|
|
|
20 |
* VR_6502_EMU_STATIC: When linking vrEmu6502 statically in your executable
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
#if __EMSCRIPTEN__
|
|
|
24 |
#include <emscripten.h>
|
|
|
25 |
#ifdef __cplusplus
|
|
|
26 |
#define VR_EMU_TMS9918_DLLEXPORT EMSCRIPTEN_KEEPALIVE extern "C"
|
|
|
27 |
#define VR_EMU_TMS9918_DLLEXPORT_CONST extern "C"
|
|
|
28 |
#else
|
|
|
29 |
#define VR_EMU_TMS9918_DLLEXPORT EMSCRIPTEN_KEEPALIVE extern
|
|
|
30 |
#define VR_EMU_TMS9918_DLLEXPORT_CONST extern
|
|
|
31 |
#endif
|
|
|
32 |
#elif VR_TMS9918_EMU_COMPILING_DLL
|
|
|
33 |
#define VR_EMU_TMS9918_DLLEXPORT __declspec(dllexport)
|
|
|
34 |
#elif defined WIN32 && !defined VR_EMU_TMS9918_STATIC
|
|
|
35 |
#define VR_EMU_TMS9918_DLLEXPORT
|
|
|
36 |
#else
|
|
|
37 |
#ifdef __cplusplus
|
|
|
38 |
#define VR_EMU_TMS9918_DLLEXPORT extern "C"
|
|
|
39 |
#else
|
|
|
40 |
#define VR_EMU_TMS9918_DLLEXPORT extern
|
|
|
41 |
#endif
|
|
|
42 |
#endif
|
|
|
43 |
|
|
|
44 |
#ifndef VR_EMU_TMS9918_DLLEXPORT_CONST
|
|
|
45 |
#define VR_EMU_TMS9918_DLLEXPORT_CONST VR_EMU_TMS9918_DLLEXPORT
|
|
|
46 |
#endif
|
|
|
47 |
|
|
|
48 |
#include <stdint.h>
|
|
|
49 |
#include <stdbool.h>
|
|
|
50 |
|
|
|
51 |
/* PRIVATE DATA STRUCTURE
|
|
|
52 |
* ---------------------------------------- */
|
|
|
53 |
struct vrEmuTMS9918_s;
|
|
|
54 |
typedef struct vrEmuTMS9918_s VrEmuTms9918;
|
|
|
55 |
|
|
|
56 |
typedef enum {
|
|
|
57 |
TMS_MODE_GRAPHICS_I,
|
|
|
58 |
TMS_MODE_GRAPHICS_II,
|
|
|
59 |
TMS_MODE_TEXT,
|
|
|
60 |
TMS_MODE_MULTICOLOR,
|
|
|
61 |
} vrEmuTms9918Mode;
|
|
|
62 |
|
|
|
63 |
typedef enum {
|
|
|
64 |
TMS_TRANSPARENT = 0,
|
|
|
65 |
TMS_BLACK,
|
|
|
66 |
TMS_MED_GREEN,
|
|
|
67 |
TMS_LT_GREEN,
|
|
|
68 |
TMS_DK_BLUE,
|
|
|
69 |
TMS_LT_BLUE,
|
|
|
70 |
TMS_DK_RED,
|
|
|
71 |
TMS_CYAN,
|
|
|
72 |
TMS_MED_RED,
|
|
|
73 |
TMS_LT_RED,
|
|
|
74 |
TMS_DK_YELLOW,
|
|
|
75 |
TMS_LT_YELLOW,
|
|
|
76 |
TMS_DK_GREEN,
|
|
|
77 |
TMS_MAGENTA,
|
|
|
78 |
TMS_GREY,
|
|
|
79 |
TMS_WHITE,
|
|
|
80 |
} vrEmuTms9918Color;
|
|
|
81 |
|
|
|
82 |
typedef enum {
|
|
|
83 |
TMS_REG_0 = 0,
|
|
|
84 |
TMS_REG_1,
|
|
|
85 |
TMS_REG_2,
|
|
|
86 |
TMS_REG_3,
|
|
|
87 |
TMS_REG_4,
|
|
|
88 |
TMS_REG_5,
|
|
|
89 |
TMS_REG_6,
|
|
|
90 |
TMS_REG_7,
|
|
|
91 |
TMS_NUM_REGISTERS,
|
|
|
92 |
TMS_REG_NAME_TABLE = TMS_REG_2,
|
|
|
93 |
TMS_REG_COLOR_TABLE = TMS_REG_3,
|
|
|
94 |
TMS_REG_PATTERN_TABLE = TMS_REG_4,
|
|
|
95 |
TMS_REG_SPRITE_ATTR_TABLE = TMS_REG_5,
|
|
|
96 |
TMS_REG_SPRITE_PATT_TABLE = TMS_REG_6,
|
|
|
97 |
TMS_REG_FG_BG_COLOR = TMS_REG_7,
|
|
|
98 |
} vrEmuTms9918Register;
|
|
|
99 |
|
|
|
100 |
#define TMS9918_PIXELS_X 256
|
|
|
101 |
#define TMS9918_PIXELS_Y 192
|
|
|
102 |
|
|
|
103 |
/* PUBLIC INTERFACE
|
|
|
104 |
* ---------------------------------------- */
|
|
|
105 |
|
|
|
106 |
/* Function: vrEmuTms9918New
|
|
|
107 |
* --------------------
|
|
|
108 |
* create a new TMS9918
|
|
|
109 |
*/
|
|
|
110 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
111 |
VrEmuTms9918* vrEmuTms9918New();
|
|
|
112 |
|
|
|
113 |
/* Function: vrEmuTms9918Reset
|
|
|
114 |
* --------------------
|
|
|
115 |
* reset the new TMS9918
|
|
|
116 |
*/
|
|
|
117 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
118 |
void vrEmuTms9918Reset(VrEmuTms9918* tms9918);
|
|
|
119 |
|
|
|
120 |
/* Function: vrEmuTms9918Destroy
|
|
|
121 |
* --------------------
|
|
|
122 |
* destroy a TMS9918
|
|
|
123 |
*
|
|
|
124 |
* tms9918: tms9918 object to destroy / clean up
|
|
|
125 |
*/
|
|
|
126 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
127 |
void vrEmuTms9918Destroy(VrEmuTms9918* tms9918);
|
|
|
128 |
|
|
|
129 |
/* Function: vrEmuTms9918WriteAddr
|
|
|
130 |
* --------------------
|
|
|
131 |
* write an address (mode = 1) to the tms9918
|
|
|
132 |
*
|
|
|
133 |
* uint8_t: the data (DB0 -> DB7) to send
|
|
|
134 |
*/
|
|
|
135 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
136 |
void vrEmuTms9918WriteAddr(VrEmuTms9918* tms9918, uint8_t data);
|
|
|
137 |
|
|
|
138 |
/* Function: vrEmuTms9918WriteData
|
|
|
139 |
* --------------------
|
|
|
140 |
* write data (mode = 0) to the tms9918
|
|
|
141 |
*
|
|
|
142 |
* uint8_t: the data (DB0 -> DB7) to send
|
|
|
143 |
*/
|
|
|
144 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
145 |
void vrEmuTms9918WriteData(VrEmuTms9918* tms9918, uint8_t data);
|
|
|
146 |
|
|
|
147 |
/* Function: vrEmuTms9918ReadStatus
|
|
|
148 |
* --------------------
|
|
|
149 |
* read from the status register
|
|
|
150 |
*/
|
|
|
151 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
152 |
uint8_t vrEmuTms9918ReadStatus(VrEmuTms9918* tms9918);
|
|
|
153 |
|
|
|
154 |
/* Function: vrEmuTms9918ReadData
|
|
|
155 |
* --------------------
|
|
|
156 |
* read data (mode = 0) from the tms9918
|
|
|
157 |
*/
|
|
|
158 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
159 |
uint8_t vrEmuTms9918ReadData(VrEmuTms9918* tms9918);
|
|
|
160 |
|
|
|
161 |
/* Function: vrEmuTms9918ReadDataNoInc
|
|
|
162 |
* --------------------
|
|
|
163 |
* read data (mode = 0) from the tms9918
|
|
|
164 |
* don't increment the address pointer
|
|
|
165 |
*/
|
|
|
166 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
167 |
uint8_t vrEmuTms9918ReadDataNoInc(VrEmuTms9918* tms9918);
|
|
|
168 |
|
|
|
169 |
/* Function: vrEmuTms9918ScanLine
|
|
|
170 |
* ----------------------------------------
|
|
|
171 |
* generate a scanline
|
|
|
172 |
*
|
|
|
173 |
* pixels to be filled with TMS9918 color palette indexes (vrEmuTms9918Color)
|
|
|
174 |
*/
|
|
|
175 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
176 |
void vrEmuTms9918ScanLine(VrEmuTms9918* tms9918, uint8_t y, uint8_t pixels[TMS9918_PIXELS_X]);
|
|
|
177 |
|
|
|
178 |
/* Function: vrEmuTms9918RegValue
|
|
|
179 |
* ----------------------------------------
|
|
|
180 |
* return a reigister value
|
|
|
181 |
*/
|
|
|
182 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
183 |
uint8_t vrEmuTms9918RegValue(VrEmuTms9918* tms9918, vrEmuTms9918Register reg);
|
|
|
184 |
|
|
|
185 |
/* Function: vrEmuTms9918WriteRegValue
|
|
|
186 |
* ----------------------------------------
|
|
|
187 |
* write a reigister value
|
|
|
188 |
*/
|
|
|
189 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
190 |
void vrEmuTms9918WriteRegValue(VrEmuTms9918* tms9918, vrEmuTms9918Register reg, uint8_t value);
|
|
|
191 |
|
|
|
192 |
/* Function: vrEmuTms9918VramValue
|
|
|
193 |
* ----------------------------------------
|
|
|
194 |
* return a value from vram
|
|
|
195 |
*/
|
|
|
196 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
197 |
uint8_t vrEmuTms9918VramValue(VrEmuTms9918* tms9918, uint16_t addr);
|
|
|
198 |
|
|
|
199 |
/* Function: vrEmuTms9918DisplayEnabled
|
|
|
200 |
* --------------------
|
|
|
201 |
* check BLANK flag
|
|
|
202 |
*/
|
|
|
203 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
204 |
bool vrEmuTms9918DisplayEnabled(VrEmuTms9918* tms9918);
|
|
|
205 |
|
|
|
206 |
/* Function: vrEmuTms9918DisplayMode
|
|
|
207 |
* --------------------
|
|
|
208 |
* current display mode
|
|
|
209 |
*/
|
|
|
210 |
VR_EMU_TMS9918_DLLEXPORT
|
|
|
211 |
vrEmuTms9918Mode vrEmuTms9918DisplayMode(VrEmuTms9918* tms9918);
|
|
|
212 |
|
|
|
213 |
#endif // _VR_EMU_TMS9918_H_
|