/
op_06.cpp
371 lines (336 loc) · 8.31 KB
/
op_06.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/* ReC98
* -----
* Code segment #6 of TH02's OP.EXE
*/
extern "C" {
#include "th02/th02.h"
#include "x86real.h"
#include "master.hpp"
#include "libs/kaja/kaja.h"
#include "th01/math/polar.hpp"
#include "th02/math/vector.hpp"
#include "th02/hardware/frmdelay.h"
#include "th02/hardware/input.hpp"
#include "th02/formats/pi.h"
#include "th02/snd/snd.h"
#define TRACK_COUNT sizeof(MUSIC_FILES) / sizeof(MUSIC_FILES[0])
#define SEL_QUIT TRACK_COUNT + 1
#define MUSIC_POLYGONS 16
const char *MUSIC_TITLES[] = {
"NO.1 東方封魔録 ~浄土曼荼羅",
"NO.2 博麗 ~Eastern Wind ",
"NO.3 End of Daylight ",
"NO.4 幻夢界 ",
"NO.5 ひもろぎ、むらさきにもえ",
"NO.6 東方封魔録 ~幽幻乱舞",
"NO.7 She's in a temper!! ",
"NO.8 やみのちから ",
"NO.9 死を賭して ",
"NO.10 恋色マジック ",
"NO.11 Complete Darkness ",
"NO.12 遠野の森 ",
"NO.13 昔話わんだーらんど ",
"NO.14 エキストララブ ",
"NO.15 戦車むすめのみるゆめ ",
" ",
" Quit "
};
const char *MUSIC_FILES[] = {
"op.m",
"stage0.m",
"stage1.m",
"stage2.m",
"stage3.m",
"stage4.m",
"boss1.m",
"boss4.m",
"boss2.m",
"boss3.m",
"mima.m",
"end1.m",
"ending.m",
"stage5.m",
"boss5.m"
};
// Polygon state
char initialized = 0;
screen_point_t points[10];
screen_point_t pos[MUSIC_POLYGONS];
point_t move_speed[MUSIC_POLYGONS];
char angle[MUSIC_POLYGONS];
char rot_speed[MUSIC_POLYGONS];
unsigned char music_sel;
page_t music_page;
dots8_t *screen_back_B;
Planar<dots8_t far *> cmt_back;
void pascal near draw_track(unsigned char sel, unsigned char color)
{
page_t other_page = (1 - music_page);
graph_accesspage(other_page);
graph_putsa_fx(
16, ((sel + 6) * GLYPH_H), (color | FX_WEIGHT_BOLD), MUSIC_TITLES[sel]
);
graph_accesspage(music_page);
graph_putsa_fx(
16, ((sel + 6) * GLYPH_H), (color | FX_WEIGHT_BOLD), MUSIC_TITLES[sel]
);
}
void pascal near draw_tracks(unsigned char sel)
{
int i;
for(i = 0; i < sizeof(MUSIC_TITLES) / sizeof(MUSIC_TITLES[0]); i++) {
draw_track(i, i == sel ? 15 : 3);
}
}
void pascal near screen_back_B_snap(void)
{
int p;
screen_back_B = HMem<dots8_t>::allocbyte(PLANE_SIZE);
PLANE_DWORD_BLIT(screen_back_B, VRAM_PLANE_B);
}
void pascal near screen_back_B_free(void)
{
HMem<dots8_t>::free(screen_back_B);
}
void pascal near screen_back_B_put(void)
{
int p;
PLANE_DWORD_BLIT(VRAM_PLANE_B, screen_back_B);
}
void pascal near polygon_build(
screen_point_t near *pts,
screen_x_t x,
screen_y_t y,
int rad,
int npoint,
char angle
)
{
int i;
y >>= 4;
for(i = 0; i < npoint; i++) {
unsigned char point_angle = ((i << 8) / npoint) + angle;
pts[i].x = polar_x_fast(x, rad, point_angle);
pts[i].y = polar_y_fast(y, rad, point_angle);
}
pts[i].x = pts[0].x;
pts[i].y = pts[0].y;
}
void pascal near polygons_update_and_render(void)
{
#define VERTICES(i) (i / 4) + 3
#define POLYGON_INIT_PART2 \
if(move_speed[i].x == 0) { \
move_speed[i].x = 1; \
} \
move_speed[i].y = ((rand() & 3) << 4) + 32; \
angle[i] = rand(); \
rot_speed[i] = 0x04 - (rand() & 0x07); \
if(rot_speed[i] == 0) { \
rot_speed[i] = 0x04; \
}
int i;
if(!initialized) {
for(i = 0; i < MUSIC_POLYGONS; i++) {
pos[i].x = rand() % 640;
pos[i].y = rand() % (400 * 16);
move_speed[i].x = 4 - (rand() & 7);
POLYGON_INIT_PART2;
}
initialized = 1;
}
for(i = 0; i < MUSIC_POLYGONS; i++) {
polygon_build(
points, pos[i].x, pos[i].y,
((i & 3) << 4) + 64, VERTICES(i), angle[i]
);
pos[i].x += move_speed[i].x;
pos[i].y += move_speed[i].y;
angle[i] += rot_speed[i];
if(pos[i].x <= 0 || pos[i].x >= 639) {
move_speed[i].x *= -1;
}
if(pos[i].y >= (400 * 20)) {
pos[i].x = rand() % 640;
pos[i].y = -1600;
move_speed[i].x = 8 - (rand() & 15);
POLYGON_INIT_PART2;
}
grcg_polygon_c(reinterpret_cast<Point *>(points), VERTICES(i));
}
}
void pascal near music_flip(void)
{
screen_back_B_put();
grcg_setcolor(GC_RMW | GC_B, 15);
polygons_update_and_render();
grcg_off();
graph_showpage(music_page);
music_page = 1 - music_page;
graph_accesspage(music_page);
frame_delay(1);
}
#define CMT_BACK_BLIT(dst, dp, src, sp) \
ps = 0; \
for(y = 64; y < 80; y++) { \
for(x = 160; x < 480; x += (4 * BYTE_DOTS)) { \
pd = vram_offset_shift(x, y); \
*(long*)(dst[PL_B] + (dp)) = *(long*)(src[PL_B] + (sp)); \
*(long*)(dst[PL_R] + (dp)) = *(long*)(src[PL_R] + (sp)); \
*(long*)(dst[PL_G] + (dp)) = *(long*)(src[PL_G] + (sp)); \
*(long*)(dst[PL_E] + (dp)) = *(long*)(src[PL_E] + (sp)); \
ps += 4; \
} \
} \
for(y = 80; y < 384; y++) { \
for(x = 304; x < 624; x += (4 * BYTE_DOTS)) { \
pd = vram_offset_shift(x, y); \
*(long*)(dst[PL_B] + (dp)) = *(long*)(src[PL_B] + (sp)); \
*(long*)(dst[PL_R] + (dp)) = *(long*)(src[PL_R] + (sp)); \
*(long*)(dst[PL_G] + (dp)) = *(long*)(src[PL_G] + (sp)); \
*(long*)(dst[PL_E] + (dp)) = *(long*)(src[PL_E] + (sp)); \
ps += 4; \
} \
}
void pascal near cmt_back_snap(void)
{
vram_offset_t ps;
screen_x_t x;
vram_offset_t pd;
screen_y_t y;
int i;
for(i = 0; i < PLANE_COUNT; i++) {
cmt_back[i] = HMem<dots8_t>::allocbyte(
(304 * (320 / BYTE_DOTS)) + (16 * (320 / BYTE_DOTS))
);
}
CMT_BACK_BLIT(cmt_back, ps, VRAM_PLANE, pd);
}
#include "th02/music/cmt_load.c"
void pascal near cmt_back_free(void)
{
HMem<dots8_t>::free(cmt_back.B);
HMem<dots8_t>::free(cmt_back.R);
HMem<dots8_t>::free(cmt_back.G);
HMem<dots8_t>::free(cmt_back.E);
}
void pascal near cmt_back_put(void)
{
vram_offset_t ps;
screen_x_t x;
vram_offset_t pd;
screen_y_t y;
CMT_BACK_BLIT(VRAM_PLANE, pd, cmt_back, ps);
}
void pascal near draw_cmt(int track)
{
int line;
int p;
music_cmt_load(track);
screen_back_B_put();
cmt_back_put();
graph_putsa_fx(160, 64, (15 | FX_WEIGHT_HEAVY), music_cmt[0]);
for(line = 1; line < MUSIC_CMT_LINE_COUNT; line++) {
graph_putsa_fx(
304, ((line + 4) * GLYPH_H), (13 | FX_WEIGHT_HEAVY), music_cmt[line]
);
}
PLANE_DWORD_BLIT(screen_back_B, VRAM_PLANE_B);
}
void pascal musicroom(void)
{
static unsigned char track_playing = 0;
music_page = 1;
palette_black();
graph_showpage(0);
graph_accesspage(0);
graph_clear();
graph_accesspage(1);
pi_load_put_8_free(0, "op3.pi");
music_sel = track_playing;
draw_tracks(music_sel);
graph_copy_page(0);
graph_accesspage(1);
graph_showpage(0);
screen_back_B_snap();
cmt_back_snap();
graph_accesspage(1); draw_cmt(track_playing);
graph_accesspage(0); draw_cmt(track_playing);
palette_100();
do {
input_sense();
if(key_det) {
music_flip();
continue;
}
controls:
input_sense();
if(key_det & INPUT_UP) {
draw_track(music_sel, 3);
if(music_sel > 0) {
music_sel--;
} else {
music_sel = SEL_QUIT;
}
if(music_sel == TRACK_COUNT) {
music_sel--;
}
draw_track(music_sel, 15);
}
if(key_det & INPUT_DOWN) {
draw_track(music_sel, 3);
if(music_sel < SEL_QUIT) {
music_sel++;
} else {
music_sel = 0;
}
if(music_sel == TRACK_COUNT) {
music_sel++;
}
draw_track(music_sel, 15);
}
if(key_det & INPUT_SHOT || key_det & INPUT_OK) {
if(music_sel != SEL_QUIT) {
bool midi_active = snd_midi_active;
snd_midi_active = snd_midi_possible;
snd_load(MUSIC_FILES[music_sel], SND_LOAD_SONG);
snd_midi_active = 0;
snd_load(MUSIC_FILES[music_sel], SND_LOAD_SONG);
snd_midi_active = midi_active;
snd_kaja_func(KAJA_SONG_PLAY, 0);
track_playing = music_sel;
draw_cmt(music_sel);
music_flip();
draw_cmt(music_sel);
} else {
break;
}
}
if(key_det & INPUT_CANCEL) {
break;
}
if(!key_det) {
music_flip();
goto controls;
}
} while(1);
while(1) {
input_sense();
if(key_det) {
music_flip();
} else {
break;
}
};
screen_back_B_free();
cmt_back_free();
graph_showpage(0);
graph_accesspage(0);
graph_clear();
graph_accesspage(1);
pi_load_put_8_free(0, "op2.pi");
palette_entry_rgb_show("op.rgb");
graph_copy_page(0);
graph_accesspage(0);
}
}