Debian Codegraph @

pacman.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*------------------------------------------------------------------------------
2 pacman.c
3
4 A Pacman clone written in C99 using the sokol headers for platform
5 abstraction.
6
7 The git repository is here:
8
9 https://github.com/floooh/pacman.c
10
11 A WASM version running in browsers can be found here:
12
13 https://floooh.github.io/pacman.c/pacman.html
14
15 Some basic concepts and ideas are worth explaining upfront:
16
17 The game code structure is a bit "radical" and sometimes goes against
18 what is considered good practice for medium and large code bases. This is
19 fine because this is a small game written by a single person. Small
20 code bases written by small teams allow a different organizational
21 approach than large code bases written by large teams.
22
23 Here are some of those "extremist" methods used in this tiny project:
24
25 Instead of artificially splitting the code into many small source files,
26 everything is in a single source file readable from top to bottom.
27
28 Instead of data-encapsulation and -hiding, all data lives in a single,
29 global, nested data structure (this isn't actually as radical and
30 experimental as it sounds, I've been using this approach for quite a
31 while now for all my hobby code). An interesting side effect of this
32 upfront-defined static memory layout is that there are no dynamic
33 allocations in the entire game code (only a handful allocations during
34 initialization of the Sokol headers).
35
36 Instead of "wasting" time thinking too much about high-level abstractions
37 and reusability, the code has been written in a fairly adhoc-manner "from
38 start to finish", solving problems as they showed up in the most direct
39 way possible. When parts of the code became too entangled I tried to step
40 back a bit, take a pause and come back later with a better idea how to
41 rewrite those parts in a more straightforward manner. Of course
42 "straightforward" and "readability" are in the eye of the beholder.
43
44 The actual gameplay code (Pacman and ghost behaviours) has been
45 implemented after the "Pacman Dossier" by Jamey Pittman (a PDF copy has
46 been included in the project), but there are some minor differences to a
47 Pacman arcade machine emulator, some intended, some not
48 (https://floooh.github.io/tiny8bit/pacman.html):
49
50 - The attract mode animation in the intro screen is missing (where
51 Pacman is chased by ghosts, eats a pill and then hunts the ghost).
52 - Likewise, the 'interlude' animation between levels is missing.
53 - Various difficulty-related differences in later maps are ignored
54 (such a faster movement speed, smaller dot-counter-limits for ghosts etc)
55
56 The rendering and audio code resembles the original Pacman arcade machine
57 hardware:
58
59 - the tile and sprite pixel data, hardware color palette data and
60 sound wavetable data is taken directly from embedded arcade machine
61 ROM dumps
62 - background tiles are rendered from two 28x36 byte buffers (one for
63 tile-codes, the other for color-codes), this is similar to an actual
64 arcade machine, with the only difference that the tile- and color-buffer
65 has a straightforward linear memory layout
66 - background tile rendering is done with dynamically uploaded vertex
67 data (two triangles per tile), with color-palette decoding done in
68 the pixel shader
69 - up to 8 16x16 sprites are rendered as vertex quads, with the same
70 color palette decoding happening in the pixel shader as for background
71 tiles.
72 - audio output works through an actual Namco WSG emulator which generates
73 sound samples for 3 hardware voices from a 20-bit frequency counter,
74 4-bit volume and 3-bit wave type (for 8 wavetables made of 32 sample
75 values each stored in a ROM dump)
76 - sound effects are implemented by writing new values to the hardware
77 voice 'registers' once per 60Hz tick, this can happen in two ways:
78 - as 'procedural' sound effects, where a callback function computes
79 the new voice register values
80 - or via 'register dump' playback, where the voice register values
81 have been captured at 60Hz frequency from an actual Pacman arcade
82 emulator
83 Only two sound effects are register dumps: the little music track at
84 the start of a game, and the sound effect when Pacman dies. All other
85 effects are simple procedural effects.
86
87 The only concept worth explaining in the gameplay code is how timing
88 and 'asynchronous actions' work:
89
90 The entire gameplay logic is driven by a global 60 Hz game tick which is
91 counting upward.
92
93 Gameplay actions are initiated by a combination of 'time triggers' and a simple
94 vocabulary to initialize and test trigger conditions. This time trigger system
95 is an extremely simple replacement for more powerful event systems in
96 'proper' game engines.
97
98 Here are some pseudo-code examples how time triggers can be used (unrelated
99 to Pacman):
100
101 To immediately trigger an action in one place of the code, and 'realize'
102 this action in one or several other places:
103
104 // if a monster has been eaten, trigger the 'monster eaten' action:
105 if (monster_eaten()) {
106 start(&state.game.monster_eaten);
107 }
108
109 // ...somewhere else, we might increase the score if a monster has been eaten:
110 if (now(state.game.monster_eaten)) {
111 state.game.score += 10;
112 }
113
114 // ...and yet somewhere else in the code, we might want to play a sound effect
115 if (now(state.game.monster_eaten)) {
116 // play sound effect...
117 }
118
119 We can also start actions in the future, which allows to batch multiple
120 followup-actions in one place:
121
122 // start fading out now, after one second (60 ticks) start a new
123 // game round, and fade in, after another second when fadein has
124 // finished, start the actual game loop
125 start(&state.gfx.fadeout);
126 start_after(&state.game.started, 60);
127 start_after(&state.gfx.fadein, 60);
128 start_after(&state.game.gameloop_started, 2*60);
129
130 As mentioned above, there's a whole little function vocabulary built around
131 time triggers, but those are hopefully all self-explanatory.
132 */
133 #include "sokol_app.h"
134 #include "sokol_gfx.h"
135 #include "sokol_audio.h"
136 #include "sokol_log.h"
137 #include "sokol_glue.h"
138 #include <assert.h>
139 #include <string.h> // memset()
140 #include <stdlib.h> // abs()
141
142 // config defines and global constants
143 #define AUDIO_VOLUME (0.5f)
144 #define DBG_SKIP_INTRO (0) // set to (1) to skip intro
145 #define DBG_SKIP_PRELUDE (0) // set to (1) to skip game prelude
146 #define DBG_START_ROUND (0) // set to any starting round <=255
147 #define DBG_MARKERS (0) // set to (1) to show debug markers
148 #define DBG_ESCAPE (0) // set to (1) to leave game loop with Esc
149 #define DBG_DOUBLE_SPEED (0) // set to (1) to speed up game (useful with godmode)
150 #define DBG_GODMODE (0) // set to (1) to disable dying
151
152 // NOTE: DO NOT CHANGE THESE DEFINES TO AN ENUM
153 // gcc-13 will turn the backing type into an unsigned integer which then
154 // causes all sorts of trouble further down
155
156 // tick duration in nanoseconds
157 #if DBG_DOUBLE_SPEED
158 #define TICK_DURATION_NS (8333333)
159 #else
160 #define TICK_DURATION_NS (16666666)
161 #endif
162 #define TICK_TOLERANCE_NS (1000000) // per-frame tolerance in nanoseconds
163 #define NUM_VOICES (3) // number of sound voices
164 #define NUM_SOUNDS (3) // max number of sounds effects that can be active at a time
165 #define NUM_SAMPLES (128) // max number of audio samples in local sample buffer
166 #define DISABLED_TICKS (0xFFFFFFFF) // magic tick value for a disabled timer
167 #define TILE_WIDTH (8) // width and height of a background tile in pixels
168 #define TILE_HEIGHT (8)
169 #define SPRITE_WIDTH (16) // width and height of a sprite in pixels
170 #define SPRITE_HEIGHT (16)
171 #define DISPLAY_TILES_X (28) // tile buffer width and height
172 #define DISPLAY_TILES_Y (36)
173 #define DISPLAY_PIXELS_X (DISPLAY_TILES_X * TILE_WIDTH)
174 #define DISPLAY_PIXELS_Y (DISPLAY_TILES_Y * TILE_HEIGHT)
175 #define NUM_SPRITES (8)
176 #define NUM_DEBUG_MARKERS (16)
177 #define TILE_TEXTURE_WIDTH (256 * TILE_WIDTH)
178 #define TILE_TEXTURE_HEIGHT (TILE_HEIGHT + SPRITE_HEIGHT)
179 #define MAX_VERTICES (((DISPLAY_TILES_X * DISPLAY_TILES_Y) + NUM_SPRITES + NUM_DEBUG_MARKERS) * 6)
180 #define FADE_TICKS (30) // duration of fade-in/out
181 #define NUM_LIVES (3)
182 #define NUM_STATUS_FRUITS (7) // max number of displayed fruits at bottom right
183 #define NUM_DOTS (244) // 240 small dots + 4 pills
184 #define NUM_PILLS (4) // number of energizer pills on playfield
185 #define ANTEPORTAS_X (14*TILE_WIDTH) // pixel position of the ghost house enter/leave point
186 #define ANTEPORTAS_Y (14*TILE_HEIGHT + TILE_HEIGHT/2)
187 #define GHOST_EATEN_FREEZE_TICKS (60) // number of ticks the game freezes after Pacman eats a ghost
188 #define PACMAN_EATEN_TICKS (60) // number of ticks to freeze game when Pacman is eaten
189 #define PACMAN_DEATH_TICKS (150) // number of ticks to show the Pacman death sequence before starting new round
190 #define GAMEOVER_TICKS (3*60) // number of ticks the game over message is shown
191 #define ROUNDWON_TICKS (4*60) // number of ticks to wait after a round was won
192 #define FRUITACTIVE_TICKS (10*60) // number of ticks a bonus fruit is shown
193
194 /* common tile, sprite and color codes, these are the same as on the Pacman
195 arcade machine and extracted by looking at memory locations of a Pacman emulator
196 */
197 enum {
198 TILE_SPACE = 0x40,
199 TILE_DOT = 0x10,
200 TILE_PILL = 0x14,
201 TILE_GHOST = 0xB0,
202 TILE_LIFE = 0x20, // 0x20..0x23
203 TILE_CHERRIES = 0x90, // 0x90..0x93
204 TILE_STRAWBERRY = 0x94, // 0x94..0x97
205 TILE_PEACH = 0x98, // 0x98..0x9B
206 TILE_BELL = 0x9C, // 0x9C..0x9F
207 TILE_APPLE = 0xA0, // 0xA0..0xA3
208 TILE_GRAPES = 0xA4, // 0xA4..0xA7
209 TILE_GALAXIAN = 0xA8, // 0xA8..0xAB
210 TILE_KEY = 0xAC, // 0xAC..0xAF
211 TILE_DOOR = 0xCF, // the ghost-house door
212
213 SPRITETILE_INVISIBLE = 30,
214 SPRITETILE_SCORE_200 = 40,
215 SPRITETILE_SCORE_400 = 41,
216 SPRITETILE_SCORE_800 = 42,
217 SPRITETILE_SCORE_1600 = 43,
218 SPRITETILE_CHERRIES = 0,
219 SPRITETILE_STRAWBERRY = 1,
220 SPRITETILE_PEACH = 2,
221 SPRITETILE_BELL = 3,
222 SPRITETILE_APPLE = 4,
223 SPRITETILE_GRAPES = 5,
224 SPRITETILE_GALAXIAN = 6,
225 SPRITETILE_KEY = 7,
226 SPRITETILE_PACMAN_CLOSED_MOUTH = 48,
227
228 COLOR_BLANK = 0x00,
229 COLOR_DEFAULT = 0x0F,
230 COLOR_DOT = 0x10,
231 COLOR_PACMAN = 0x09,
232 COLOR_BLINKY = 0x01,
233 COLOR_PINKY = 0x03,
234 COLOR_INKY = 0x05,
235 COLOR_CLYDE = 0x07,
236 COLOR_FRIGHTENED = 0x11,
237 COLOR_FRIGHTENED_BLINKING = 0x12,
238 COLOR_GHOST_SCORE = 0x18,
239 COLOR_EYES = 0x19,
240 COLOR_CHERRIES = 0x14,
241 COLOR_STRAWBERRY = 0x0F,
242 COLOR_PEACH = 0x15,
243 COLOR_BELL = 0x16,
244 COLOR_APPLE = 0x14,
245 COLOR_GRAPES = 0x17,
246 COLOR_GALAXIAN = 0x09,
247 COLOR_KEY = 0x16,
248 COLOR_WHITE_BORDER = 0x1F,
249 COLOR_FRUIT_SCORE = 0x03,
250 };
251
252 // the top-level game states (intro => game => intro)
253 typedef enum {
254 GAMESTATE_INTRO,
255 GAMESTATE_GAME,
256 } gamestate_t;
257
258 // directions NOTE: bit0==0: horizontal movement, bit0==1: vertical movement
259 typedef enum {
260 DIR_RIGHT, // 000
261 DIR_DOWN, // 001
262 DIR_LEFT, // 010
263 DIR_UP, // 011
264 NUM_DIRS
265 } dir_t;
266
267 // bonus fruit types
268 typedef enum {
269 FRUIT_NONE,
270 FRUIT_CHERRIES,
271 FRUIT_STRAWBERRY,
272 FRUIT_PEACH,
273 FRUIT_APPLE,
274 FRUIT_GRAPES,
275 FRUIT_GALAXIAN,
276 FRUIT_BELL,
277 FRUIT_KEY,
278 NUM_FRUITS
279 } fruit_t;
280
281 // sprite 'hardware' indices
282 typedef enum {
283 SPRITE_PACMAN,
284 SPRITE_BLINKY,
285 SPRITE_PINKY,
286 SPRITE_INKY,
287 SPRITE_CLYDE,
288 SPRITE_FRUIT,
289 } sprite_index_t;
290
291 // ghost types
292 typedef enum {
293 GHOSTTYPE_BLINKY,
294 GHOSTTYPE_PINKY,
295 GHOSTTYPE_INKY,
296 GHOSTTYPE_CLYDE,
297 NUM_GHOSTS
298 } ghosttype_t;
299
300 // ghost AI states
301 typedef enum {
302 GHOSTSTATE_NONE,
303 GHOSTSTATE_CHASE, // currently chasing Pacman
304 GHOSTSTATE_SCATTER, // currently heading to the corner scatter targets
305 GHOSTSTATE_FRIGHTENED, // frightened after Pacman has eaten an energizer pill
306 GHOSTSTATE_EYES, // eaten by Pacman and heading back to the ghost house
307 GHOSTSTATE_HOUSE, // currently inside the ghost house
308 GHOSTSTATE_LEAVEHOUSE, // currently leaving the ghost house
309 GHOSTSTATE_ENTERHOUSE // currently entering the ghost house
310 } ghoststate_t;
311
312 // reasons why game loop is frozen
313 typedef enum {
314 FREEZETYPE_PRELUDE = (1<<0), // game prelude is active (with the game start tune playing)
315 FREEZETYPE_READY = (1<<1), // READY! phase is active (at start of a new game round)
316 FREEZETYPE_EAT_GHOST = (1<<2), // Pacman has eaten a ghost
317 FREEZETYPE_DEAD = (1<<3), // Pacman was eaten by a ghost
318 FREEZETYPE_WON = (1<<4), // game round was won by eating all dots
319 } freezetype_t;
320
321 // a trigger holds a specific game-tick when an action should be started
322 typedef struct {
323 uint32_t tick;
324 } trigger_t;
325
326 // a 2D integer vector (used both for pixel- and tile-coordinates)
327 typedef struct {
328 int16_t x;
329 int16_t y;
330 } int2_t;
331
332 // common state for pacman and ghosts
333 typedef struct {
334 dir_t dir; // current movement direction
335 int2_t pos; // position of sprite center in pixel coords
336 uint32_t anim_tick; // incremented when actor moved in current tick
337 } actor_t;
338
339 // ghost AI state
340 typedef struct {
341 actor_t actor;
342 ghosttype_t type;
343 dir_t next_dir; // ghost AI looks ahead one tile when deciding movement direction
344 int2_t target_pos; // current target position in tile coordinates
345 ghoststate_t state;
346 trigger_t frightened; // game tick when frightened mode was entered
347 trigger_t eaten; // game tick when eaten by Pacman
348 uint16_t dot_counter; // used to decide when to leave the ghost house
349 uint16_t dot_limit;
350 } ghost_t;
351
352 // pacman state
353 typedef struct {
354 actor_t actor;
355 } pacman_t;
356
357 // the tile- and sprite-renderer's vertex structure
358 typedef struct {
359 float x, y; // screen coords [0..1]
360 float u, v; // tile texture coords
361 uint32_t attr; // x: color code, y: opacity (opacity only used for fade effect)
362 } vertex_t;
363
364 // sprite state
365 typedef struct {
366 bool enabled; // if false sprite is deactivated
367 uint8_t tile, color; // sprite-tile number (0..63), color code
368 bool flipx, flipy; // horizontal/vertical flip
369 int2_t pos; // pixel position of the sprite's top-left corner
370 } sprite_t;
371
372 // debug visualization markers (see DBG_MARKERS)
373 typedef struct {
374 bool enabled;
375 uint8_t tile, color; // tile and color code
376 int2_t tile_pos;
377 } debugmarker_t;
378
379 // callback function prototype for procedural sounds
380 typedef void (*sound_func_t)(int sound_slot);
381
382 // a sound effect description used as param for snd_start()
383 typedef struct {
384 sound_func_t func; // callback function (if procedural sound)
385 const uint32_t* ptr; // pointer to register dump data (if a register-dump sound)
386 uint32_t size; // byte size of register dump data
387 bool voice[3]; // true to activate voice
388 } sound_desc_t;
389
390 // a sound 'hardware' voice
391 typedef struct {
392 uint32_t counter; // 20-bit counter, top 5 bits are index into wavetable ROM
393 uint32_t frequency; // 20-bit frequency (added to counter at 96kHz)
394 uint8_t waveform; // 3-bit waveform index
395 uint8_t volume; // 4-bit volume
396 float sample_acc; // current float sample accumulator
397 float sample_div; // current float sample divisor
398 } voice_t;
399
400 // flags for sound_t.flags
401 typedef enum {
402 SOUNDFLAG_VOICE0 = (1<<0),
403 SOUNDFLAG_VOICE1 = (1<<1),
404 SOUNDFLAG_VOICE2 = (1<<2),
405 SOUNDFLAG_ALL_VOICES = (1<<0)|(1<<1)|(1<<2)
406 } soundflag_t;
407
408 // a currently playing sound effect
409 typedef struct {
410 uint32_t cur_tick; // current tick counter
411 sound_func_t func; // optional function pointer for prodecural sounds
412 uint32_t num_ticks; // length of register dump sound effect in 60Hz ticks
413 uint32_t stride; // number of uint32_t values per tick (only for register dump effects)
414 const uint32_t* data; // 3 * num_ticks register dump values
415 uint8_t flags; // combination of soundflag_t (active voices)
416 } sound_t;
417
418 // all state is in a single nested struct
419 static struct {
420
421 gamestate_t gamestate; // the current gamestate (intro => game => intro)
422
423 struct {
424 uint32_t tick; // the central game tick, this drives the whole game
425 uint64_t laptime_store; // helper variable to measure frame duration
426 int32_t tick_accum; // helper variable to decouple ticks from frame rate
427 } timing;
428
429 // intro state
430 struct {
431 trigger_t started; // tick when intro-state was started
432 } intro;
433
434 // game state
435 struct {
436 uint32_t xorshift; // current xorshift random-number-generator state
437 uint32_t hiscore; // hiscore / 10
438 trigger_t started;
439 trigger_t ready_started;
440 trigger_t round_started;
441 trigger_t round_won;
442 trigger_t game_over;
443 trigger_t dot_eaten; // last time Pacman ate a dot
444 trigger_t pill_eaten; // last time Pacman ate a pill
445 trigger_t ghost_eaten; // last time Pacman ate a ghost
446 trigger_t pacman_eaten; // last time Pacman was eaten by a ghost
447 trigger_t fruit_eaten; // last time Pacman has eaten the bonus fruit
448 trigger_t force_leave_house; // starts when a dot is eaten
449 trigger_t fruit_active; // starts when bonus fruit is shown
450 uint8_t freeze; // combination of FREEZETYPE_* flags
451 uint8_t round; // current game round, 0, 1, 2...
452 uint32_t score; // score / 10
453 int8_t num_lives;
454 uint8_t num_ghosts_eaten; // number of ghosts easten with current pill
455 uint8_t num_dots_eaten; // if == NUM_DOTS, Pacman wins the round
456 bool global_dot_counter_active; // set to true when Pacman loses a life
457 uint8_t global_dot_counter; // the global dot counter for the ghost-house-logic
458 ghost_t ghost[NUM_GHOSTS];
459 pacman_t pacman;
460 fruit_t active_fruit;
461 } game;
462
463 // the current input state
464 struct {
465 bool enabled;
466 bool up;
467 bool down;
468 bool left;
469 bool right;
470 bool esc; // only for debugging (see DBG_ESCACPE)
471 bool anykey;
472 } input;
473
474 // the audio subsystem is essentially a Namco arcade board sound emulator
475 struct {
476 voice_t voice[NUM_VOICES];
477 sound_t sound[NUM_SOUNDS];
478 int32_t voice_tick_accum;
479 int32_t voice_tick_period;
480 int32_t sample_duration_ns;
481 int32_t sample_accum;
482 uint32_t num_samples;
483 float sample_buffer[NUM_SAMPLES];
484 } audio;
485
486 // the gfx subsystem implements a simple tile+sprite renderer
487 struct {
488 // fade-in/out timers and current value
489 trigger_t fadein;
490 trigger_t fadeout;
491 uint8_t fade;
492
493 // the 36x28 tile framebuffer
494 uint8_t video_ram[DISPLAY_TILES_Y][DISPLAY_TILES_X]; // tile codes
495 uint8_t color_ram[DISPLAY_TILES_Y][DISPLAY_TILES_X]; // color codes
496
497 // up to 8 sprites
498 sprite_t sprite[NUM_SPRITES];
499
500 // up to 16 debug markers
501 debugmarker_t debug_marker[NUM_DEBUG_MARKERS];
502
503 // sokol-gfx resources
504 sg_pass_action pass_action;
505 struct {
506 sg_buffer vbuf;
507 sg_image tile_img;
508 sg_image palette_img;
509 sg_image render_target;
510 sg_sampler sampler;
511 sg_pipeline pip;
512 sg_attachments attachments;
513 } offscreen;
514 struct {
515 sg_buffer quad_vbuf;
516 sg_pipeline pip;
517 sg_sampler sampler;
518 } display;
519
520 // intermediate vertex buffer for tile- and sprite-rendering
521 int num_vertices;
522 vertex_t vertices[MAX_VERTICES];
523
524 // scratch-buffer for tile-decoding (only happens once)
525 uint8_t tile_pixels[TILE_TEXTURE_HEIGHT][TILE_TEXTURE_WIDTH];
526
527 // scratch buffer for the color palette
528 uint32_t color_palette[256];
529 } gfx;
530 } state;
531
532 // scatter target positions (in tile coords)
533 static const int2_t ghost_scatter_targets[NUM_GHOSTS] = {
534 { 25, 0 }, { 2, 0 }, { 27, 34 }, { 0, 34 }
535 };
536
537 // starting positions for ghosts (pixel coords)
538 static const int2_t ghost_starting_pos[NUM_GHOSTS] = {
539 { 14*8, 14*8 + 4 },
540 { 14*8, 17*8 + 4 },
541 { 12*8, 17*8 + 4 },
542 { 16*8, 17*8 + 4 },
543 };
544
545 // target positions for ghost entering the ghost house (pixel coords)
546 static const int2_t ghost_house_target_pos[NUM_GHOSTS] = {
547 { 14*8, 17*8 + 4 },
548 { 14*8, 17*8 + 4 },
549 { 12*8, 17*8 + 4 },
550 { 16*8, 17*8 + 4 },
551 };
552
553 // fruit tiles, sprite tiles and colors
554 static const uint8_t fruit_tiles_colors[NUM_FRUITS][3] = {
555 { 0, 0, 0 }, // FRUIT_NONE
556 { TILE_CHERRIES, SPRITETILE_CHERRIES, COLOR_CHERRIES },
557 { TILE_STRAWBERRY, SPRITETILE_STRAWBERRY, COLOR_STRAWBERRY },
558 { TILE_PEACH, SPRITETILE_PEACH, COLOR_PEACH },
559 { TILE_APPLE, SPRITETILE_APPLE, COLOR_APPLE },
560 { TILE_GRAPES, SPRITETILE_GRAPES, COLOR_GRAPES },
561 { TILE_GALAXIAN, SPRITETILE_GALAXIAN, COLOR_GALAXIAN },
562 { TILE_BELL, SPRITETILE_BELL, COLOR_BELL },
563 { TILE_KEY, SPRITETILE_KEY, COLOR_KEY }
564 };
565
566 // the tiles for displaying the bonus-fruit-score, this is a number built from 4 tiles
567 static const uint8_t fruit_score_tiles[NUM_FRUITS][4] = {
568 { 0x40, 0x40, 0x40, 0x40 }, // FRUIT_NONE
569 { 0x40, 0x81, 0x85, 0x40 }, // FRUIT_CHERRIES: 100
570 { 0x40, 0x82, 0x85, 0x40 }, // FRUIT_STRAWBERRY: 300
571 { 0x40, 0x83, 0x85, 0x40 }, // FRUIT_PEACH: 500
572 { 0x40, 0x84, 0x85, 0x40 }, // FRUIT_APPLE: 700
573 { 0x40, 0x86, 0x8D, 0x8E }, // FRUIT_GRAPES: 1000
574 { 0x87, 0x88, 0x8D, 0x8E }, // FRUIT_GALAXIAN: 2000
575 { 0x89, 0x8A, 0x8D, 0x8E }, // FRUIT_BELL: 3000
576 { 0x8B, 0x8C, 0x8D, 0x8E }, // FRUIT_KEY: 5000
577 };
578
579 // level specifications (see pacman_dossier.pdf)
580 typedef struct {
581 fruit_t bonus_fruit;
582 uint16_t bonus_score;
583 uint16_t fright_ticks;
584 // FIXME: the various Pacman and ghost speeds
585 } levelspec_t;
586
587 enum {
588 MAX_LEVELSPEC = 21,
589 };
590 static const levelspec_t levelspec_table[MAX_LEVELSPEC] = {
591 { FRUIT_CHERRIES, 10, 6*60, },
592 { FRUIT_STRAWBERRY, 30, 5*60, },
593 { FRUIT_PEACH, 50, 4*60, },
594 { FRUIT_PEACH, 50, 3*60, },
595 { FRUIT_APPLE, 70, 2*60, },
596 { FRUIT_APPLE, 70, 5*60, },
597 { FRUIT_GRAPES, 100, 2*60, },
598 { FRUIT_GRAPES, 100, 2*60, },
599 { FRUIT_GALAXIAN, 200, 1*60, },
600 { FRUIT_GALAXIAN, 200, 5*60, },
601 { FRUIT_BELL, 300, 2*60, },
602 { FRUIT_BELL, 300, 1*60, },
603 { FRUIT_KEY, 500, 1*60, },
604 { FRUIT_KEY, 500, 3*60, },
605 { FRUIT_KEY, 500, 1*60, },
606 { FRUIT_KEY, 500, 1*60, },
607 { FRUIT_KEY, 500, 1, },
608 { FRUIT_KEY, 500, 1*60, },
609 { FRUIT_KEY, 500, 1, },
610 { FRUIT_KEY, 500, 1, },
611 { FRUIT_KEY, 500, 1, },
612 // from here on repeating
613 };
614
615 // forward-declared sound-effect register dumps (recorded from Pacman arcade emulator)
616 static const uint32_t snd_dump_prelude[490];
617 static const uint32_t snd_dump_dead[90];
618
619 // procedural sound effect callbacks
620 static void snd_func_eatdot1(int slot);
621 static void snd_func_eatdot2(int slot);
622 static void snd_func_eatghost(int slot);
623 static void snd_func_eatfruit(int slot);
624 static void snd_func_weeooh(int slot);
625 static void snd_func_frightened(int slot);
626
627 // sound effect description structs
628 static const sound_desc_t snd_prelude = {
629 .ptr = snd_dump_prelude,
630 .size = sizeof(snd_dump_prelude),
631 .voice = { true, true, false }
632 };
633
634 static const sound_desc_t snd_dead = {
635 .ptr = snd_dump_dead,
636 .size = sizeof(snd_dump_dead),
637 .voice = { false, false, true }
638 };
639
640 static const sound_desc_t snd_eatdot1 = {
641 .func = snd_func_eatdot1,
642 .voice = { false, false, true }
643 };
644
645 static const sound_desc_t snd_eatdot2 = {
646 .func = snd_func_eatdot2,
647 .voice = { false, false, true }
648 };
649
650 static const sound_desc_t snd_eatghost = {
651 .func = snd_func_eatghost,
652 .voice = { false, false, true }
653 };
654
655 static const sound_desc_t snd_eatfruit = {
656 .func = snd_func_eatfruit,
657 .voice = { false, false, true }
658 };
659
660 static const sound_desc_t snd_weeooh = {
661 .func = snd_func_weeooh,
662 .voice = { false, true, false }
663 };
664
665 static const sound_desc_t snd_frightened = {
666 .func = snd_func_frightened,
667 .voice = { false, true, false }
668 };
669
670 // forward declarations
671 static void init(void);
672 static void frame(void);
673 static void cleanup(void);
674 static void input(const sapp_event*);
675
676 static void start(trigger_t* t);
677 static bool now(trigger_t t);
678
679 static void intro_tick(void);
680 static void game_tick(void);
681
682 static void input_enable(void);
683 static void input_disable(void);
684
685 static void gfx_init(void);
686 static void gfx_shutdown(void);
687 static void gfx_fade(void);
688 static void gfx_draw(void);
689
690 static void snd_init(void);
691 static void snd_shutdown(void);
692 static void snd_tick(void); // called per game tick
693 static void snd_frame(int32_t frame_time_ns); // called per frame
694 static void snd_clear(void);
695 static void snd_start(int sound_slot, const sound_desc_t* snd);
696 static void snd_stop(int sound_slot);
697
698 // forward-declared ROM dumps
699 static const uint8_t rom_tiles[4096];
700 static const uint8_t rom_sprites[4096];
701 static const uint8_t rom_hwcolors[32];
702 static const uint8_t rom_palette[256];
703 static const uint8_t rom_wavetable[256];
704
705 /*== APPLICATION ENTRY AND CALLBACKS =========================================*/
706 sapp_desc sokol_main(int argc, char* argv[]) {
707 (void)argc; (void)argv;
708 return (sapp_desc) {
709 .init_cb = init,
710 .frame_cb = frame,
711 .cleanup_cb = cleanup,
712 .event_cb = input,
713 .width = DISPLAY_TILES_X * TILE_WIDTH * 2,
714 .height = DISPLAY_TILES_Y * TILE_HEIGHT * 2,
715 .window_title = "pacman.c",
716 .logger.func = slog_func,
717 };
718 }
719
720 static void init(void) {
721 gfx_init();
722 snd_init();
723
724 // start into intro screen
725 #if DBG_SKIP_INTRO
726 start(&state.game.started);
727 #else
728 start(&state.intro.started);
729 #endif
730 }
731
732 static void frame(void) {
733
734 // run the game at a fixed tick rate regardless of frame rate
735 uint32_t frame_time_ns = (uint32_t) (sapp_frame_duration() * 1000000000.0);
736 // clamp max frame time (so the timing isn't messed up when stopping in the debugger)
737 if (frame_time_ns > 33333333) {
738 frame_time_ns = 33333333;
739 }
740 state.timing.tick_accum += frame_time_ns;
741 while (state.timing.tick_accum > -TICK_TOLERANCE_NS) {
742 state.timing.tick_accum -= TICK_DURATION_NS;
743 state.timing.tick++;
744
745 // call per-tick sound function (updates sound 'registers' with current sound effect values)
746 snd_tick();
747
748 // check for game state change
749 if (now(state.intro.started)) {
750 state.gamestate = GAMESTATE_INTRO;
751 }
752 if (now(state.game.started)) {
753 state.gamestate = GAMESTATE_GAME;
754 }
755
756 // call the top-level game state update function
757 switch (state.gamestate) {
758 case GAMESTATE_INTRO:
759 intro_tick();
760 break;
761 case GAMESTATE_GAME:
762 game_tick();
763 break;
764 }
765 }
766 gfx_draw();
767 snd_frame(frame_time_ns);
768 }
769
770 static void input(const sapp_event* ev) {
771 if (state.input.enabled) {
772 if ((ev->type == SAPP_EVENTTYPE_KEY_DOWN) || (ev->type == SAPP_EVENTTYPE_KEY_UP)) {
773 bool btn_down = ev->type == SAPP_EVENTTYPE_KEY_DOWN;
774 switch (ev->key_code) {
775 case SAPP_KEYCODE_UP:
776 case SAPP_KEYCODE_W:
777 state.input.up = state.input.anykey = btn_down;
778 break;
779 case SAPP_KEYCODE_DOWN:
780 case SAPP_KEYCODE_S:
781 state.input.down = state.input.anykey = btn_down;
782 break;
783 case SAPP_KEYCODE_LEFT:
784 case SAPP_KEYCODE_A:
785 state.input.left = state.input.anykey = btn_down;
786 break;
787 case SAPP_KEYCODE_RIGHT:
788 case SAPP_KEYCODE_D:
789 state.input.right = state.input.anykey = btn_down;
790 break;
•791 case SAPP_KEYCODE_F:
792 if (btn_down) {
793 sapp_toggle_fullscreen();
794 }
795 break;
796 case SAPP_KEYCODE_ESCAPE:
797 state.input.esc = state.input.anykey = btn_down;
798 break;
799 default:
800 state.input.anykey = btn_down;
801 break;
802 }
803 }
804 }
805 }
806
807 static void cleanup(void) {
808 snd_shutdown();
809 gfx_shutdown();
810 }
811
812 /*== GRAB BAG OF HELPER FUNCTIONS ============================================*/
813
814 // xorshift random number generator
815 static uint32_t xorshift32(void) {
816 uint32_t x = state.game.xorshift;
817 x ^= x<<13;
818 x ^= x>>17;
819 x ^= x<<5;
820 return state.game.xorshift = x;
821 }
822 // get level spec for a game round
823 static levelspec_t levelspec(int round) {
824 assert(round >= 0);
825 if (round >= MAX_LEVELSPEC) {
826 round = MAX_LEVELSPEC-1;
827 }
828 return levelspec_table[round];
829 }
830
831 // set time trigger to the next game tick
832 static void start(trigger_t* t) {
833 t->tick = state.timing.tick + 1;
834 }
835
836 // set time trigger to a future tick
837 static void start_after(trigger_t* t, uint32_t ticks) {
838 t->tick = state.timing.tick + ticks;
839 }
840
841 // deactivate a time trigger
842 static void disable(trigger_t* t) {
843 t->tick = DISABLED_TICKS;
844 }
845
846 // return a disabled time trigger
847 static trigger_t disabled_timer(void) {
848 return (trigger_t) { .tick = DISABLED_TICKS };
849 }
850
851 // check if a time trigger is triggered
852 static bool now(trigger_t t) {
853 return t.tick == state.timing.tick;
854 }
855
856 // return the number of ticks since a time trigger was triggered
857 static uint32_t since(trigger_t t) {
858 if (state.timing.tick >= t.tick) {
859 return state.timing.tick - t.tick;
860 }
861 else {
862 return DISABLED_TICKS;
863 }
864 }
865
866 // check if a time trigger is between begin and end tick
867 static bool between(trigger_t t, uint32_t begin, uint32_t end) {
868 assert(begin < end);
869 if (t.tick != DISABLED_TICKS) {
870 uint32_t ticks = since(t);
871 return (ticks >= begin) && (ticks < end);
872 }
873 else {
874 return false;
875 }
876 }
877
878 // check if a time trigger was triggered exactly N ticks ago
879 static bool after_once(trigger_t t, uint32_t ticks) {
880 return since(t) == ticks;
881 }
882
883 // check if a time trigger was triggered more than N ticks ago
884 static bool after(trigger_t t, uint32_t ticks) {
885 uint32_t s = since(t);
886 if (s != DISABLED_TICKS) {
887 return s >= ticks;
888 }
889 else {
890 return false;
891 }
892 }
893
894 // same as between(t, 0, ticks)
895 static bool before(trigger_t t, uint32_t ticks) {
896 uint32_t s = since(t);
897 if (s != DISABLED_TICKS) {
898 return s < ticks;
899 }
900 else {
901 return false;
902 }
903 }
904
905 // clear input state and disable input
906 static void input_disable(void) {
907 memset(&state.input, 0, sizeof(state.input));
908 }
909
910 // enable input again
911 static void input_enable(void) {
912 state.input.enabled = true;
913 }
914
915 // get the current input as dir_t
916 static dir_t input_dir(dir_t default_dir) {
917 if (state.input.up) {
918 return DIR_UP;
919 }
920 else if (state.input.down) {
921 return DIR_DOWN;
922 }
923 else if (state.input.right) {
924 return DIR_RIGHT;
925 }
926 else if (state.input.left) {
927 return DIR_LEFT;
928 }
929 else {
930 return default_dir;
931 }
932 }
933
934 // shortcut to create an int2_t
935 static int2_t i2(int16_t x, int16_t y) {
936 return (int2_t) { x, y };
937 }
938
939 // add two int2_t
940 static int2_t add_i2(int2_t v0, int2_t v1) {
941 return (int2_t) { v0.x+v1.x, v0.y+v1.y };
942 }
943
944 // subtract two int2_t
945 static int2_t sub_i2(int2_t v0, int2_t v1) {
946 return (int2_t) { v0.x-v1.x, v0.y-v1.y };
947 }
948
949 // multiply int2_t with scalar
950 static int2_t mul_i2(int2_t v, int16_t s) {
951 return (int2_t) { v.x*s, v.y*s };
952 }
953
954 // squared-distance between two int2_t
955 static int32_t squared_distance_i2(int2_t v0, int2_t v1) {
956 int2_t d = { v1.x - v0.x, v1.y - v0.y };
957 return d.x * d.x + d.y * d.y;
958 }
959
960 // check if two int2_t are equal
961 static bool equal_i2(int2_t v0, int2_t v1) {
962 return (v0.x == v1.x) && (v0.y == v1.y);
963 }
964
965 // check if two int2_t are nearly equal
966 static bool nearequal_i2(int2_t v0, int2_t v1, int16_t tolerance) {
967 return (abs(v1.x - v0.x) <= tolerance) && (abs(v1.y - v0.y) <= tolerance);
968 }
969
970 // convert an actor pos (origin at center) to sprite pos (origin top left)
971 static int2_t actor_to_sprite_pos(int2_t pos) {
972 return i2(pos.x - SPRITE_WIDTH/2, pos.y - SPRITE_HEIGHT/2);
973 }
974
975 // compute the distance of a pixel coordinate to the next tile midpoint
976 int2_t dist_to_tile_mid(int2_t pos) {
977 return i2((TILE_WIDTH/2) - pos.x % TILE_WIDTH, (TILE_HEIGHT/2) - pos.y % TILE_HEIGHT);
978 }
979
980 // clear tile and color buffer
981 static void vid_clear(uint8_t tile_code, uint8_t color_code) {
982 memset(&state.gfx.video_ram, tile_code, sizeof(state.gfx.video_ram));
983 memset(&state.gfx.color_ram, color_code, sizeof(state.gfx.color_ram));
984 }
985
986 // clear the playfield's rectangle in the color buffer
987 static void vid_color_playfield(uint8_t color_code) {
988 for (int y = 3; y < DISPLAY_TILES_Y-2; y++) {
989 for (int x = 0; x < DISPLAY_TILES_X; x++) {
990 state.gfx.color_ram[y][x] = color_code;
991 }
992 }
993 }
994
995 // check if a tile position is valid
996 static bool valid_tile_pos(int2_t tile_pos) {
997 return ((tile_pos.x >= 0) && (tile_pos.x < DISPLAY_TILES_X) && (tile_pos.y >= 0) && (tile_pos.y < DISPLAY_TILES_Y));
998 }
999
1000 // put a color into the color buffer
1001 static void vid_color(int2_t tile_pos, uint8_t color_code) {
1002 assert(valid_tile_pos(tile_pos));
1003 state.gfx.color_ram[tile_pos.y][tile_pos.x] = color_code;
1004 }
1005
1006 // put a tile into the tile buffer
1007 static void vid_tile(int2_t tile_pos, uint8_t tile_code) {
1008 assert(valid_tile_pos(tile_pos));
1009 state.gfx.video_ram[tile_pos.y][tile_pos.x] = tile_code;
1010 }
1011
1012 // put a colored tile into the tile and color buffers
1013 static void vid_color_tile(int2_t tile_pos, uint8_t color_code, uint8_t tile_code) {
1014 assert(valid_tile_pos(tile_pos));
1015 state.gfx.video_ram[tile_pos.y][tile_pos.x] = tile_code;
1016 state.gfx.color_ram[tile_pos.y][tile_pos.x] = color_code;
1017 }
1018
1019 // translate ASCII char into "NAMCO char"
1020 static char conv_char(char c) {
1021 switch (c) {
1022 case ' ': c = 0x40; break;
1023 case '/': c = 58; break;
1024 case '-': c = 59; break;
1025 case '\"': c = 38; break;
1026 case '!': c = 'Z'+1; break;
1027 default: break;
1028 }
1029 return c;
1030 }
1031
1032 // put colored char into tile+color buffers
1033 static void vid_color_char(int2_t tile_pos, uint8_t color_code, char chr) {
1034 assert(valid_tile_pos(tile_pos));
1035 state.gfx.video_ram[tile_pos.y][tile_pos.x] = conv_char(chr);
1036 state.gfx.color_ram[tile_pos.y][tile_pos.x] = color_code;
1037 }
1038
1039 // put char into tile buffer
1040 static void vid_char(int2_t tile_pos, char chr) {
1041 assert(valid_tile_pos(tile_pos));
1042 state.gfx.video_ram[tile_pos.y][tile_pos.x] = conv_char(chr);
1043 }
1044
1045 // put colored text into the tile+color buffers
1046 static void vid_color_text(int2_t tile_pos, uint8_t color_code, const char* text) {
1047 assert(valid_tile_pos(tile_pos));
1048 uint8_t chr;
1049 while ((chr = (uint8_t) *text++)) {
1050 if (tile_pos.x < DISPLAY_TILES_X) {
1051 vid_color_char(tile_pos, color_code, chr);
1052 tile_pos.x++;
1053 }
1054 else {
1055 break;
1056 }
1057 }
1058 }
1059
1060 // put text into the tile buffer
1061 static void vid_text(int2_t tile_pos, const char* text) {
1062 assert(valid_tile_pos(tile_pos));
1063 uint8_t chr;
1064 while ((chr = (uint8_t) *text++)) {
1065 if (tile_pos.x < DISPLAY_TILES_X) {
1066 vid_char(tile_pos, chr);
1067 tile_pos.x++;
1068 }
1069 else {
1070 break;
1071 }
1072 }
1073 }
1074
1075 /* print colored score number into tile+color buffers from right to left(!),
1076 scores are /10, the last printed number is always 0,
1077 a zero-score will print as '00' (this is the same as on
1078 the Pacman arcade machine)
1079 */
1080 static void vid_color_score(int2_t tile_pos, uint8_t color_code, uint32_t score) {
1081 vid_color_char(tile_pos, color_code, '0');
1082 tile_pos.x--;
1083 for (int digit = 0; digit < 8; digit++) {
1084 char chr = (score % 10) + '0';
1085 if (valid_tile_pos(tile_pos)) {
1086 vid_color_char(tile_pos, color_code, chr);
1087 tile_pos.x--;
1088 score /= 10;
1089 if (0 == score) {
1090 break;
1091 }
1092 }
1093 }
1094 }
1095
1096 /* draw a colored tile-quad arranged as:
1097 |t+1|t+0|
1098 |t+3|t+2|
1099
1100 This is (for instance) used to render the current "lives" and fruit
1101 symbols at the lower border.
1102 */
1103 static void vid_draw_tile_quad(int2_t tile_pos, uint8_t color_code, uint8_t tile_code) {
1104 for (int yy=0; yy<2; yy++) {
1105 for (int xx=0; xx<2; xx++) {
1106 uint8_t t = tile_code + yy*2 + (1-xx);
1107 vid_color_tile(i2(xx + tile_pos.x, yy + tile_pos.y), color_code, t);
1108 }
1109 }
1110 }
1111
1112 // draw the fruit bonus score tiles (when Pacman has eaten the bonus fruit)
1113 static void vid_fruit_score(fruit_t fruit_type) {
1114 assert((fruit_type >= 0) && (fruit_type < NUM_FRUITS));
1115 uint8_t color_code = (fruit_type == FRUIT_NONE) ? COLOR_DOT : COLOR_FRUIT_SCORE;
1116 for (int i = 0; i < 4; i++) {
1117 vid_color_tile(i2(12+i, 20), color_code, fruit_score_tiles[fruit_type][i]);
1118 }
1119 }
1120
1121 // disable and clear all sprites
1122 static void spr_clear(void) {
1123 memset(&state.gfx.sprite, 0, sizeof(state.gfx.sprite));
1124 }
1125
1126 // get pointer to pacman sprite
1127 static sprite_t* spr_pacman(void) {
1128 return &state.gfx.sprite[SPRITE_PACMAN];
1129 }
1130
1131 // get pointer to ghost sprite
1132 static sprite_t* spr_ghost(ghosttype_t type) {
1133 assert((type >= 0) && (type < NUM_GHOSTS));
1134 return &state.gfx.sprite[SPRITE_BLINKY + type];
1135 }
1136
1137 // get pointer to fruit sprite
1138 static sprite_t* spr_fruit(void) {
1139 return &state.gfx.sprite[SPRITE_FRUIT];
1140 }
1141
1142 // set sprite to animated Pacman
1143 static void spr_anim_pacman(dir_t dir, uint32_t tick) {
1144 // animation frames for horizontal and vertical movement
1145 static const uint8_t tiles[2][4] = {
1146 { 44, 46, 48, 46 }, // horizontal (needs flipx)
1147 { 45, 47, 48, 47 } // vertical (needs flipy)
1148 };
1149 sprite_t* spr = spr_pacman();
1150 uint32_t phase = (tick / 2) & 3;
1151 spr->tile = tiles[dir & 1][phase];
1152 spr->color = COLOR_PACMAN;
1153 spr->flipx = (dir == DIR_LEFT);
1154 spr->flipy = (dir == DIR_UP);
1155 }
1156
1157 // set sprite to Pacman's death sequence
1158 static void spr_anim_pacman_death(uint32_t tick) {
1159 // the death animation tile sequence starts at sprite tile number 52 and ends at 63
1160 sprite_t* spr = spr_pacman();
1161 uint32_t tile = 52 + (tick / 8);
1162 if (tile > 63) {
1163 tile = 63;
1164 }
1165 spr->tile = tile;
1166 spr->flipx = spr->flipy = false;
1167 }
1168
1169 // set sprite to animated ghost
1170 static void spr_anim_ghost(ghosttype_t ghost_type, dir_t dir, uint32_t tick) {
1171 assert((dir >= 0) && (dir < NUM_DIRS));
1172 static const uint8_t tiles[4][2] = {
1173 { 32, 33 }, // right
1174 { 34, 35 }, // down
1175 { 36, 37 }, // left
1176 { 38, 39 }, // up
1177 };
1178 uint32_t phase = (tick / 8) & 1;
1179 sprite_t* spr = spr_ghost(ghost_type);
1180 spr->tile = tiles[dir][phase];
1181 spr->color = COLOR_BLINKY + 2*ghost_type;
1182 spr->flipx = false;
1183 spr->flipy = false;
1184 }
1185
1186 // set sprite to frightened ghost
1187 static void spr_anim_ghost_frightened(ghosttype_t ghost_type, uint32_t tick) {
1188 static const uint8_t tiles[2] = { 28, 29 };
1189 uint32_t phase = (tick / 4) & 1;
1190 sprite_t* spr = spr_ghost(ghost_type);
1191 spr->tile = tiles[phase];
1192 if (tick > (uint32_t)(levelspec(state.game.round).fright_ticks - 60)) {
1193 // towards end of frightening period, start blinking
1194 spr->color = (tick & 0x10) ? COLOR_FRIGHTENED : COLOR_FRIGHTENED_BLINKING;
1195 }
1196 else {
1197 spr->color = COLOR_FRIGHTENED;
1198 }
1199 spr->flipx = false;
1200 spr->flipy = false;
1201 }
1202
1203 /* set sprite to ghost eyes, these are the normal ghost sprite
1204 images but with a different color code which makes
1205 only the eyes visible
1206 */
1207 static void spr_anim_ghost_eyes(ghosttype_t ghost_type, dir_t dir) {
1208 assert((dir >= 0) && (dir < NUM_DIRS));
1209 static const uint8_t tiles[NUM_DIRS] = { 32, 34, 36, 38 };
1210 sprite_t* spr = spr_ghost(ghost_type);
1211 spr->tile = tiles[dir];
1212 spr->color = COLOR_EYES;
1213 spr->flipx = false;
1214 spr->flipy = false;
1215 }
1216
1217 // convert pixel position to tile position
1218 static int2_t pixel_to_tile_pos(int2_t pix_pos) {
1219 return i2(pix_pos.x / TILE_WIDTH, pix_pos.y / TILE_HEIGHT);
1220 }
1221
1222 // clamp tile pos to valid playfield coords
1223 static int2_t clamped_tile_pos(int2_t tile_pos) {
1224 int2_t res = tile_pos;
1225 if (res.x < 0) {
1226 res.x = 0;
1227 }
1228 else if (res.x >= DISPLAY_TILES_X) {
1229 res.x = DISPLAY_TILES_X - 1;
1230 }
1231 if (res.y < 3) {
1232 res.y = 3;
1233 }
1234 else if (res.y >= (DISPLAY_TILES_Y-2)) {
1235 res.y = DISPLAY_TILES_Y - 3;
1236 }
1237 return res;
1238 }
1239
1240 // convert a direction to a movement vector
1241 static int2_t dir_to_vec(dir_t dir) {
1242 assert((dir >= 0) && (dir < NUM_DIRS));
1243 static const int2_t dir_map[NUM_DIRS] = { { +1, 0 }, { 0, +1 }, { -1, 0 }, { 0, -1 } };
1244 return dir_map[dir];
1245 }
1246
1247 // return the reverse direction
1248 static dir_t reverse_dir(dir_t dir) {
1249 switch (dir) {
1250 case DIR_RIGHT: return DIR_LEFT;
1251 case DIR_DOWN: return DIR_UP;
1252 case DIR_LEFT: return DIR_RIGHT;
1253 default: return DIR_DOWN;
1254 }
1255 }
1256
1257 // return tile code at tile position
1258 static uint8_t tile_code_at(int2_t tile_pos) {
1259 assert((tile_pos.x >= 0) && (tile_pos.x < DISPLAY_TILES_X));
1260 assert((tile_pos.y >= 0) && (tile_pos.y < DISPLAY_TILES_Y));
1261 return state.gfx.video_ram[tile_pos.y][tile_pos.x];
1262 }
1263
1264 // check if a tile position contains a blocking tile (walls and ghost house door)
1265 static bool is_blocking_tile(int2_t tile_pos) {
1266 return tile_code_at(tile_pos) >= 0xC0;
1267 }
1268
1269 // check if a tile position contains a dot tile
1270 static bool is_dot(int2_t tile_pos) {
1271 return tile_code_at(tile_pos) == TILE_DOT;
1272 }
1273
1274 // check if a tile position contains a pill tile
1275 static bool is_pill(int2_t tile_pos) {
1276 return tile_code_at(tile_pos) == TILE_PILL;
1277 }
1278
1279 // check if a tile position is in the teleport tunnel
1280 static bool is_tunnel(int2_t tile_pos) {
1281 return (tile_pos.y == 17) && ((tile_pos.x <= 5) || (tile_pos.x >= 22));
1282 }
1283
1284 // check if a position is in the ghost's red zone, where upward movement is forbidden
1285 // (see Pacman Dossier "Areas To Exploit")
1286 static bool is_redzone(int2_t tile_pos) {
1287 return ((tile_pos.x >= 11) && (tile_pos.x <= 16) && ((tile_pos.y == 14) || (tile_pos.y == 26)));
1288 }
1289
1290 // test if movement from a pixel position in a wanted direction is possible,
1291 // allow_cornering is Pacman's feature to take a diagonal shortcut around corners
1292 static bool can_move(int2_t pos, dir_t wanted_dir, bool allow_cornering) {
1293 const int2_t dir_vec = dir_to_vec(wanted_dir);
1294 const int2_t dist_mid = dist_to_tile_mid(pos);
1295
1296 // distance to midpoint in move direction and perpendicular direction
1297 int16_t move_dist_mid, perp_dist_mid;
1298 if (dir_vec.y != 0) {
1299 move_dist_mid = dist_mid.y;
1300 perp_dist_mid = dist_mid.x;
1301 }
1302 else {
1303 move_dist_mid = dist_mid.x;
1304 perp_dist_mid = dist_mid.y;
1305 }
1306
1307 // look one tile ahead in movement direction
1308 const int2_t tile_pos = pixel_to_tile_pos(pos);
1309 const int2_t check_pos = clamped_tile_pos(add_i2(tile_pos, dir_vec));
1310 const bool is_blocked = is_blocking_tile(check_pos);
1311 if ((!allow_cornering && (0 != perp_dist_mid)) || (is_blocked && (0 == move_dist_mid))) {
1312 // way is blocked
1313 return false;
1314 }
1315 else {
1316 // way is free
1317 return true;
1318 }
1319 }
1320
1321 // compute a new pixel position along a direction (without blocking check!)
1322 static int2_t move(int2_t pos, dir_t dir, bool allow_cornering) {
1323 const int2_t dir_vec = dir_to_vec(dir);
1324 pos = add_i2(pos, dir_vec);
1325
1326 // if cornering is allowed, drag the position towards the center-line
1327 if (allow_cornering) {
1328 const int2_t dist_mid = dist_to_tile_mid(pos);
1329 if (dir_vec.x != 0) {
1330 if (dist_mid.y < 0) { pos.y--; }
1331 else if (dist_mid.y > 0) { pos.y++; }
1332 }
1333 else if (dir_vec.y != 0) {
1334 if (dist_mid.x < 0) { pos.x--; }
1335 else if (dist_mid.x > 0) { pos.x++; }
1336 }
1337 }
1338
1339 // wrap x-position around (only possible in the teleport-tunnel)
1340 if (pos.x < 0) {
1341 pos.x = DISPLAY_PIXELS_X - 1;
1342 }
1343 else if (pos.x >= DISPLAY_PIXELS_X) {
1344 pos.x = 0;
1345 }
1346 return pos;
1347 }
1348
1349 // set a debug marker
1350 #if DBG_MARKERS
1351 static void dbg_marker(int index, int2_t tile_pos, uint8_t tile_code, uint8_t color_code) {
1352 assert((index >= 0) && (index < NUM_DEBUG_MARKERS));
1353 state.gfx.debug_marker[index] = (debugmarker_t) {
1354 .enabled = true,
1355 .tile = tile_code,
1356 .color = color_code,
1357 .tile_pos = clamped_tile_pos(tile_pos)
1358 };
1359 }
1360 #endif
1361
1362 /*== GAMEPLAY CODE ===========================================================*/
1363
1364 // initialize the playfield tiles
1365 static void game_init_playfield(void) {
1366 vid_color_playfield(COLOR_DOT);
1367 // decode the playfield from an ASCII map into tiles codes
1368 static const char* tiles =
1369 //0123456789012345678901234567
1370 "0UUUUUUUUUUUU45UUUUUUUUUUUU1" // 3
1371 "L............rl............R" // 4
1372 "L.ebbf.ebbbf.rl.ebbbf.ebbf.R" // 5
1373 "LPr l.r l.rl.r l.r lPR" // 6
1374 "L.guuh.guuuh.gh.guuuh.guuh.R" // 7
1375 "L..........................R" // 8
1376 "L.ebbf.ef.ebbbbbbf.ef.ebbf.R" // 9
1377 "L.guuh.rl.guuyxuuh.rl.guuh.R" // 10
1378 "L......rl....rl....rl......R" // 11
1379 "2BBBBf.rzbbf rl ebbwl.eBBBB3" // 12
1380 " L.rxuuh gh guuyl.R " // 13
1381 " L.rl rl.R " // 14
1382 " L.rl mjs--tjn rl.R " // 15
1383 "UUUUUh.gh i q gh.gUUUUU" // 16
1384 " . i q . " // 17
1385 "BBBBBf.ef i q ef.eBBBBB" // 18
1386 " L.rl okkkkkkp rl.R " // 19
1387 " L.rl rl.R " // 20
1388 " L.rl ebbbbbbf rl.R " // 21
1389 "0UUUUh.gh guuyxuuh gh.gUUUU1" // 22
1390 "L............rl............R" // 23
1391 "L.ebbf.ebbbf.rl.ebbbf.ebbf.R" // 24
1392 "L.guyl.guuuh.gh.guuuh.rxuh.R" // 25
1393 "LP..rl....... .......rl..PR" // 26
1394 "6bf.rl.ef.ebbbbbbf.ef.rl.eb8" // 27
1395 "7uh.gh.rl.guuyxuuh.rl.gh.gu9" // 28
1396 "L......rl....rl....rl......R" // 29
1397 "L.ebbbbwzbbf.rl.ebbwzbbbbf.R" // 30
1398 "L.guuuuuuuuh.gh.guuuuuuuuh.R" // 31
1399 "L..........................R" // 32
1400 "2BBBBBBBBBBBBBBBBBBBBBBBBBB3"; // 33
1401 //0123456789012345678901234567
1402 uint8_t t[128];
1403 for (int i = 0; i < 128; i++) { t[i]=TILE_DOT; }
1404 t[' ']=0x40; t['0']=0xD1; t['1']=0xD0; t['2']=0xD5; t['3']=0xD4; t['4']=0xFB;
1405 t['5']=0xFA; t['6']=0xD7; t['7']=0xD9; t['8']=0xD6; t['9']=0xD8; t['U']=0xDB;
1406 t['L']=0xD3; t['R']=0xD2; t['B']=0xDC; t['b']=0xDF; t['e']=0xE7; t['f']=0xE6;
1407 t['g']=0xEB; t['h']=0xEA; t['l']=0xE8; t['r']=0xE9; t['u']=0xE5; t['w']=0xF5;
1408 t['x']=0xF2; t['y']=0xF3; t['z']=0xF4; t['m']=0xED; t['n']=0xEC; t['o']=0xEF;
1409 t['p']=0xEE; t['j']=0xDD; t['i']=0xD2; t['k']=0xDB; t['q']=0xD3; t['s']=0xF1;
1410 t['t']=0xF0; t['-']=TILE_DOOR; t['P']=TILE_PILL;
1411 for (int y = 3, i = 0; y <= 33; y++) {
1412 for (int x = 0; x < 28; x++, i++) {
1413 state.gfx.video_ram[y][x] = t[tiles[i] & 127];
1414 }
1415 }
1416 // ghost house gate colors
1417 vid_color(i2(13,15), 0x18);
1418 vid_color(i2(14,15), 0x18);
1419 }
1420
1421 // disable all game loop timers
1422 static void game_disable_timers(void) {
1423 disable(&state.game.round_won);
1424 disable(&state.game.game_over);
1425 disable(&state.game.dot_eaten);
1426 disable(&state.game.pill_eaten);
1427 disable(&state.game.ghost_eaten);
1428 disable(&state.game.pacman_eaten);
1429 disable(&state.game.fruit_eaten);
1430 disable(&state.game.force_leave_house);
1431 disable(&state.game.fruit_active);
1432 }
1433
1434 // one-time init at start of game state
1435 static void game_init(void) {
1436 input_enable();
1437 game_disable_timers();
1438 state.game.round = DBG_START_ROUND;
1439 state.game.freeze = FREEZETYPE_PRELUDE;
1440 state.game.num_lives = NUM_LIVES;
1441 state.game.global_dot_counter_active = false;
1442 state.game.global_dot_counter = 0;
1443 state.game.num_dots_eaten = 0;
1444 state.game.score = 0;
1445
1446 // draw the playfield and PLAYER ONE READY! message
1447 vid_clear(TILE_SPACE, COLOR_DOT);
1448 vid_color_text(i2(9,0), COLOR_DEFAULT, "HIGH SCORE");
1449 game_init_playfield();
1450 vid_color_text(i2(9,14), 0x5, "PLAYER ONE");
1451 vid_color_text(i2(11, 20), 0x9, "READY!");
1452 }
1453
1454 // setup state at start of a game round
1455 static void game_round_init(void) {
1456 spr_clear();
1457
1458 // clear the "PLAYER ONE" text
1459 vid_color_text(i2(9,14), 0x10, " ");
1460
1461 /* if a new round was started because Pacman has "won" (eaten all dots),
1462 redraw the playfield and reset the global dot counter
1463 */
1464 if (state.game.num_dots_eaten == NUM_DOTS) {
1465 state.game.round++;
1466 state.game.num_dots_eaten = 0;
1467 game_init_playfield();
1468 state.game.global_dot_counter_active = false;
1469 }
1470 else {
1471 /* if the previous round was lost, use the global dot counter
1472 to detect when ghosts should leave the ghost house instead
1473 of the per-ghost dot counter
1474 */
1475 if (state.game.num_lives != NUM_LIVES) {
1476 state.game.global_dot_counter_active = true;
1477 state.game.global_dot_counter = 0;
1478 }
1479 state.game.num_lives--;
1480 }
1481 assert(state.game.num_lives >= 0);
1482
1483 state.game.active_fruit = FRUIT_NONE;
1484 state.game.freeze = FREEZETYPE_READY;
1485 state.game.xorshift = 0x12345678; // random-number-generator seed
1486 state.game.num_ghosts_eaten = 0;
1487 game_disable_timers();
1488
1489 vid_color_text(i2(11, 20), 0x9, "READY!");
1490
1491 // the force-house timer forces ghosts out of the house if Pacman isn't
1492 // eating dots for a while
1493 start(&state.game.force_leave_house);
1494
1495 // Pacman starts running to the left
1496 state.game.pacman = (pacman_t) {
1497 .actor = {
1498 .dir = DIR_LEFT,
1499 .pos = { 14*8, 26*8+4 },
1500 },
1501 };
1502 state.gfx.sprite[SPRITE_PACMAN] = (sprite_t) { .enabled = true, .color = COLOR_PACMAN };
1503
1504 // Blinky starts outside the ghost house, looking to the left, and in scatter mode
1505 state.game.ghost[GHOSTTYPE_BLINKY] = (ghost_t) {
1506 .actor = {
1507 .dir = DIR_LEFT,
1508 .pos = ghost_starting_pos[GHOSTTYPE_BLINKY],
1509 },
1510 .type = GHOSTTYPE_BLINKY,
1511 .next_dir = DIR_LEFT,
1512 .state = GHOSTSTATE_SCATTER,
1513 .frightened = disabled_timer(),
1514 .eaten = disabled_timer(),
1515 .dot_counter = 0,
1516 .dot_limit = 0
1517 };
1518 state.gfx.sprite[SPRITE_BLINKY] = (sprite_t) { .enabled = true, .color = COLOR_BLINKY };
1519
1520 // Pinky starts in the middle slot of the ghost house, moving down
1521 state.game.ghost[GHOSTTYPE_PINKY] = (ghost_t) {
1522 .actor = {
1523 .dir = DIR_DOWN,
1524 .pos = ghost_starting_pos[GHOSTTYPE_PINKY],
1525 },
1526 .type = GHOSTTYPE_PINKY,
1527 .next_dir = DIR_DOWN,
1528 .state = GHOSTSTATE_HOUSE,
1529 .frightened = disabled_timer(),
1530 .eaten = disabled_timer(),
1531 .dot_counter = 0,
1532 .dot_limit = 0
1533 };
1534 state.gfx.sprite[SPRITE_PINKY] = (sprite_t) { .enabled = true, .color = COLOR_PINKY };
1535
1536 // Inky starts in the left slot of the ghost house moving up
1537 state.game.ghost[GHOSTTYPE_INKY] = (ghost_t) {
1538 .actor = {
1539 .dir = DIR_UP,
1540 .pos = ghost_starting_pos[GHOSTTYPE_INKY],
1541 },
1542 .type = GHOSTTYPE_INKY,
1543 .next_dir = DIR_UP,
1544 .state = GHOSTSTATE_HOUSE,
1545 .frightened = disabled_timer(),
1546 .eaten = disabled_timer(),
1547 .dot_counter = 0,
1548 // FIXME: needs to be adjusted by current round!
1549 .dot_limit = 30
1550 };
1551 state.gfx.sprite[SPRITE_INKY] = (sprite_t) { .enabled = true, .color = COLOR_INKY };
1552
1553 // Clyde starts in the right slot of the ghost house, moving up
1554 state.game.ghost[GHOSTTYPE_CLYDE] = (ghost_t) {
1555 .actor = {
1556 .dir = DIR_UP,
1557 .pos = ghost_starting_pos[GHOSTTYPE_CLYDE],
1558 },
1559 .type = GHOSTTYPE_CLYDE,
1560 .next_dir = DIR_UP,
1561 .state = GHOSTSTATE_HOUSE,
1562 .frightened = disabled_timer(),
1563 .eaten = disabled_timer(),
1564 .dot_counter = 0,
1565 // FIXME: needs to be adjusted by current round!
1566 .dot_limit = 60,
1567 };
1568 state.gfx.sprite[SPRITE_CLYDE] = (sprite_t) { .enabled = true, .color = COLOR_CLYDE };
1569 }
1570
1571 // update dynamic background tiles
1572 static void game_update_tiles(void) {
1573 // print score and hiscore
1574 vid_color_score(i2(6,1), COLOR_DEFAULT, state.game.score);
1575 if (state.game.hiscore > 0) {
1576 vid_color_score(i2(16,1), COLOR_DEFAULT, state.game.hiscore);
1577 }
1578
1579 // update the energizer pill colors (blinking/non-blinking)
1580 static const int2_t pill_pos[NUM_PILLS] = { { 1, 6 }, { 26, 6 }, { 1, 26 }, { 26, 26 } };
1581 for (int i = 0; i < NUM_PILLS; i++) {
1582 if (state.game.freeze) {
1583 vid_color(pill_pos[i], COLOR_DOT);
1584 }
1585 else {
1586 vid_color(pill_pos[i], (state.timing.tick & 0x8) ? 0x10:0);
1587 }
1588 }
1589
1590 // clear the fruit-eaten score after Pacman has eaten a bonus fruit
1591 if (after_once(state.game.fruit_eaten, 2*60)) {
1592 vid_fruit_score(FRUIT_NONE);
1593 }
1594
1595 // remaining lives at bottom left screen
1596 for (int i = 0; i < NUM_LIVES; i++) {
1597 uint8_t color = (i < state.game.num_lives) ? COLOR_PACMAN : 0;
1598 vid_draw_tile_quad(i2(2+2*i,34), color, TILE_LIFE);
1599 }
1600
1601 // bonus fruit list in bottom-right corner
1602 {
1603 int16_t x = 24;
1604 for (int i = ((int)state.game.round - NUM_STATUS_FRUITS + 1); i <= (int)state.game.round; i++) {
1605 if (i >= 0) {
1606 fruit_t fruit = levelspec(i).bonus_fruit;
1607 uint8_t tile_code = fruit_tiles_colors[fruit][0];
1608 uint8_t color_code = fruit_tiles_colors[fruit][2];
1609 vid_draw_tile_quad(i2(x,34), color_code, tile_code);
1610 x -= 2;
1611 }
1612 }
1613 }
1614
1615 // if game round was won, render the entire playfield as blinking blue/white
1616 if (after(state.game.round_won, 1*60)) {
1617 if (since(state.game.round_won) & 0x10) {
1618 vid_color_playfield(COLOR_DOT);
1619 }
1620 else {
1621 vid_color_playfield(COLOR_WHITE_BORDER);
1622 }
1623 }
1624 }
1625
1626 // this function takes care of updating all sprite images during gameplay
1627 static void game_update_sprites(void) {
1628 // update Pacman sprite
1629 {
1630 sprite_t* spr = spr_pacman();
1631 if (spr->enabled) {
1632 const actor_t* actor = &state.game.pacman.actor;
1633 spr->pos = actor_to_sprite_pos(actor->pos);
1634 if (state.game.freeze & FREEZETYPE_EAT_GHOST) {
1635 // hide Pacman shortly after he's eaten a ghost (via an invisible Sprite tile)
1636 spr->tile = SPRITETILE_INVISIBLE;
1637 }
1638 else if (state.game.freeze & (FREEZETYPE_PRELUDE|FREEZETYPE_READY)) {
1639 // special case game frozen at start of round, show Pacman with 'closed mouth'
1640 spr->tile = SPRITETILE_PACMAN_CLOSED_MOUTH;
1641 }
1642 else if (state.game.freeze & FREEZETYPE_DEAD) {
1643 // play the Pacman-death-animation after a short pause
1644 if (after(state.game.pacman_eaten, PACMAN_EATEN_TICKS)) {
1645 spr_anim_pacman_death(since(state.game.pacman_eaten) - PACMAN_EATEN_TICKS);
1646 }
1647 }
1648 else {
1649 // regular Pacman animation
1650 spr_anim_pacman(actor->dir, actor->anim_tick);
1651 }
1652 }
1653 }
1654
1655 // update ghost sprites
1656 for (int i = 0; i < NUM_GHOSTS; i++) {
1657 sprite_t* sprite = spr_ghost(i);
1658 if (sprite->enabled) {
1659 const ghost_t* ghost = &state.game.ghost[i];
1660 sprite->pos = actor_to_sprite_pos(ghost->actor.pos);
1661 // if Pacman has just died, hide ghosts
1662 if (state.game.freeze & FREEZETYPE_DEAD) {
1663 if (after(state.game.pacman_eaten, PACMAN_EATEN_TICKS)) {
1664 sprite->tile = SPRITETILE_INVISIBLE;
1665 }
1666 }
1667 // if Pacman has won the round, hide ghosts
1668 else if (state.game.freeze & FREEZETYPE_WON) {
1669 sprite->tile = SPRITETILE_INVISIBLE;
1670 }
1671 else switch (ghost->state) {
1672 case GHOSTSTATE_EYES:
1673 if (before(ghost->eaten, GHOST_EATEN_FREEZE_TICKS)) {
1674 // if the ghost was *just* eaten by Pacman, the ghost's sprite
1675 // is replaced with a score number for a short time
1676 // (200 for the first ghost, followed by 400, 800 and 1600)
1677 sprite->tile = SPRITETILE_SCORE_200 + state.game.num_ghosts_eaten - 1;
1678 sprite->color = COLOR_GHOST_SCORE;
1679 }
1680 else {
1681 // afterwards, the ghost's eyes are shown, heading back to the ghost house
1682 spr_anim_ghost_eyes(i, ghost->next_dir);
1683 }
1684 break;
1685 case GHOSTSTATE_ENTERHOUSE:
1686 // ...still show the ghost eyes while entering the ghost house
1687 spr_anim_ghost_eyes(i, ghost->actor.dir);
1688 break;
1689 case GHOSTSTATE_FRIGHTENED:
1690 // when inside the ghost house, show the normal ghost images
1691 // (FIXME: ghost's inside the ghost house also show the
1692 // frightened appearance when Pacman has eaten an energizer pill)
1693 spr_anim_ghost_frightened(i, since(ghost->frightened));
1694 break;
1695 default:
1696 // show the regular ghost sprite image, the ghost's
1697 // 'next_dir' is used to visualize the direction the ghost
1698 // is heading to, this has the effect that ghosts already look
1699 // into the direction they will move into one tile ahead
1700 spr_anim_ghost(i, ghost->next_dir, ghost->actor.anim_tick);
1701 break;
1702 }
1703 }
1704 }
1705
1706 // hide or display the currently active bonus fruit
1707 if (state.game.active_fruit == FRUIT_NONE) {
1708 spr_fruit()->enabled = false;
1709 }
1710 else {
1711 sprite_t* spr = spr_fruit();
1712 spr->enabled = true;
1713 spr->pos = i2(13 * TILE_WIDTH, 19 * TILE_HEIGHT + TILE_HEIGHT/2);
1714 spr->tile = fruit_tiles_colors[state.game.active_fruit][1];
1715 spr->color = fruit_tiles_colors[state.game.active_fruit][2];
1716 }
1717 }
1718
1719 // return true if Pacman should move in this tick, when eating dots, Pacman
1720 // is slightly slower than ghosts, otherwise slightly faster
1721 static bool game_pacman_should_move(void) {
1722 if (now(state.game.dot_eaten)) {
1723 // eating a dot causes Pacman to stop for 1 tick
1724 return false;
1725 }
1726 else if (since(state.game.pill_eaten) < 3) {
1727 // eating an energizer pill causes Pacman to stop for 3 ticks
1728 return false;
1729 }
1730 else {
1731 return 0 != (state.timing.tick % 8);
1732 }
1733 }
1734
1735 // return number of pixels a ghost should move this tick, this can't be a simple
1736 // move/don't move boolean return value, because ghosts in eye state move faster
1737 // than one pixel per tick
1738 static int game_ghost_speed(const ghost_t* ghost) {
1739 assert(ghost);
1740 switch (ghost->state) {
1741 case GHOSTSTATE_HOUSE:
1742 case GHOSTSTATE_LEAVEHOUSE:
1743 // inside house at half speed (estimated)
1744 return state.timing.tick & 1;
1745 case GHOSTSTATE_FRIGHTENED:
1746 // move at 50% speed when frightened
1747 return state.timing.tick & 1;
1748 case GHOSTSTATE_EYES:
1749 case GHOSTSTATE_ENTERHOUSE:
1750 // estimated 1.5x when in eye state, Pacman Dossier is silent on this
1751 return (state.timing.tick & 1) ? 1 : 2;
1752 default:
1753 if (is_tunnel(pixel_to_tile_pos(ghost->actor.pos))) {
1754 // move drastically slower when inside tunnel
1755 return ((state.timing.tick * 2) % 4) ? 1 : 0;
1756 }
1757 else {
1758 // otherwise move just a bit slower than Pacman
1759 return (state.timing.tick % 7) ? 1 : 0;
1760 }
1761 }
1762 }
1763
1764 // return the current global scatter or chase phase
1765 static ghoststate_t game_scatter_chase_phase(void) {
1766 uint32_t t = since(state.game.round_started);
1767 if (t < 7*60) return GHOSTSTATE_SCATTER;
1768 else if (t < 27*60) return GHOSTSTATE_CHASE;
1769 else if (t < 34*60) return GHOSTSTATE_SCATTER;
1770 else if (t < 54*60) return GHOSTSTATE_CHASE;
1771 else if (t < 59*60) return GHOSTSTATE_SCATTER;
1772 else if (t < 79*60) return GHOSTSTATE_CHASE;
1773 else if (t < 84*60) return GHOSTSTATE_SCATTER;
1774 else return GHOSTSTATE_CHASE;
1775 }
1776
1777 // this function takes care of switching ghosts into a new state, this is one
1778 // of two important functions of the ghost AI (the other being the target selection
1779 // function below)
1780 static void game_update_ghost_state(ghost_t* ghost) {
1781 assert(ghost);
1782 ghoststate_t new_state = ghost->state;
1783 switch (ghost->state) {
1784 case GHOSTSTATE_EYES:
1785 // When in eye state (heading back to the ghost house), check if the
1786 // target position in front of the ghost house has been reached, then
1787 // switch into ENTERHOUSE state. Since ghosts in eye state move faster
1788 // than one pixel per tick, do a fuzzy comparison with the target pos
1789 if (nearequal_i2(ghost->actor.pos, i2(ANTEPORTAS_X, ANTEPORTAS_Y), 1)) {
1790 new_state = GHOSTSTATE_ENTERHOUSE;
1791 }
1792 break;
1793 case GHOSTSTATE_ENTERHOUSE:
1794 // Ghosts that enter the ghost house during the gameplay loop immediately
1795 // leave the house again after reaching their target position inside the house.
1796 if (nearequal_i2(ghost->actor.pos, ghost_house_target_pos[ghost->type], 1)) {
1797 new_state = GHOSTSTATE_LEAVEHOUSE;
1798 }
1799 break;
1800 case GHOSTSTATE_HOUSE:
1801 // Ghosts only remain in the "house state" after a new game round
1802 // has been started. The conditions when ghosts leave the house
1803 // are a bit complicated, best to check the Pacman Dossier for the details.
1804 if (after_once(state.game.force_leave_house, 4*60)) {
1805 // if Pacman hasn't eaten dots for 4 seconds, the next ghost
1806 // is forced out of the house
1807 // FIXME: time is reduced to 3 seconds after round 5
1808 new_state = GHOSTSTATE_LEAVEHOUSE;
1809 start(&state.game.force_leave_house);
1810 }
1811 else if (state.game.global_dot_counter_active) {
1812 // if Pacman has lost a life this round, the global dot counter is used
1813 if ((ghost->type == GHOSTTYPE_PINKY) && (state.game.global_dot_counter == 7)) {
1814 new_state = GHOSTSTATE_LEAVEHOUSE;
1815 }
1816 else if ((ghost->type == GHOSTTYPE_INKY) && (state.game.global_dot_counter == 17)) {
1817 new_state = GHOSTSTATE_LEAVEHOUSE;
1818 }
1819 else if ((ghost->type == GHOSTTYPE_CLYDE) && (state.game.global_dot_counter == 32)) {
1820 new_state = GHOSTSTATE_LEAVEHOUSE;
1821 // NOTE that global dot counter is deactivated if (and only if) Clyde
1822 // is in the house and the dot counter reaches 32
1823 state.game.global_dot_counter_active = false;
1824 }
1825 }
1826 else if (ghost->dot_counter == ghost->dot_limit) {
1827 // in the normal case, check the ghost's personal dot counter
1828 new_state = GHOSTSTATE_LEAVEHOUSE;
1829 }
1830 break;
1831 case GHOSTSTATE_LEAVEHOUSE:
1832 // ghosts immediately switch to scatter mode after leaving the ghost house
1833 if (ghost->actor.pos.y == ANTEPORTAS_Y) {
1834 new_state = GHOSTSTATE_SCATTER;
1835 }
1836 break;
1837 default:
1838 // switch between frightened, scatter and chase mode
1839 if (before(ghost->frightened, levelspec(state.game.round).fright_ticks)) {
1840 new_state = GHOSTSTATE_FRIGHTENED;
1841 }
1842 else {
1843 new_state = game_scatter_chase_phase();
1844 }
1845 }
1846 // handle state transitions
1847 if (new_state != ghost->state) {
1848 switch (ghost->state) {
1849 case GHOSTSTATE_LEAVEHOUSE:
1850 // after leaving the ghost house, head to the left
1851 ghost->next_dir = ghost->actor.dir = DIR_LEFT;
1852 break;
1853 case GHOSTSTATE_ENTERHOUSE:
1854 // a ghost that was eaten is immune to frighten until Pacman eats enother pill
1855 disable(&ghost->frightened);
1856 break;
1857 case GHOSTSTATE_FRIGHTENED:
1858 // don't reverse direction when leaving frightened state
1859 break;
1860 case GHOSTSTATE_SCATTER:
1861 case GHOSTSTATE_CHASE:
1862 // any transition from scatter and chase mode causes a reversal of direction
1863 ghost->next_dir = reverse_dir(ghost->actor.dir);
1864 break;
1865 default:
1866 break;
1867 }
1868 ghost->state = new_state;
1869 }
1870 }
1871
1872 // update the ghost's target position, this is the other important function
1873 // of the ghost's AI
1874 static void game_update_ghost_target(ghost_t* ghost) {
1875 assert(ghost);
1876 int2_t pos = ghost->target_pos;
1877 switch (ghost->state) {
1878 case GHOSTSTATE_SCATTER:
1879 // when in scatter mode, each ghost heads to its own scatter
1880 // target position in the playfield corners
1881 assert((ghost->type >= 0) && (ghost->type < NUM_GHOSTS));
1882 pos = ghost_scatter_targets[ghost->type];
1883 break;
1884 case GHOSTSTATE_CHASE:
1885 // when in chase mode, each ghost has its own particular
1886 // chase behaviour (see the Pacman Dossier for details)
1887 {
1888 const actor_t* pm = &state.game.pacman.actor;
1889 const int2_t pm_pos = pixel_to_tile_pos(pm->pos);
1890 const int2_t pm_dir = dir_to_vec(pm->dir);
1891 switch (ghost->type) {
1892 case GHOSTTYPE_BLINKY:
1893 // Blinky directly chases Pacman
1894 pos = pm_pos;
1895 break;
1896 case GHOSTTYPE_PINKY:
1897 // Pinky target is 4 tiles ahead of Pacman
1898 // FIXME: does not reproduce 'diagonal overflow'
1899 pos = add_i2(pm_pos, mul_i2(pm_dir, 4));
1900 break;
1901 case GHOSTTYPE_INKY:
1902 // Inky targets an extrapolated pos along a line two tiles
1903 // ahead of Pacman through Blinky
1904 {
1905 const int2_t blinky_pos = pixel_to_tile_pos(state.game.ghost[GHOSTTYPE_BLINKY].actor.pos);
1906 const int2_t p = add_i2(pm_pos, mul_i2(pm_dir, 2));
1907 const int2_t d = sub_i2(p, blinky_pos);
1908 pos = add_i2(blinky_pos, mul_i2(d, 2));
1909 }
1910 break;
1911 case GHOSTTYPE_CLYDE:
1912 // if Clyde is far away from Pacman, he chases Pacman,
1913 // but if close he moves towards the scatter target
1914 if (squared_distance_i2(pixel_to_tile_pos(ghost->actor.pos), pm_pos) > 64) {
1915 pos = pm_pos;
1916 }
1917 else {
1918 pos = ghost_scatter_targets[GHOSTTYPE_CLYDE];
1919 }
1920 break;
1921 default:
1922 break;
1923 }
1924 }
1925 break;
1926 case GHOSTSTATE_FRIGHTENED:
1927 // in frightened state just select a random target position
1928 // this has the effect that ghosts in frightened state
1929 // move in a random direction at each intersection
1930 pos = i2(xorshift32() % DISPLAY_TILES_X, xorshift32() % DISPLAY_TILES_Y);
1931 break;
1932 case GHOSTSTATE_EYES:
1933 // move towards the ghost house door
1934 pos = i2(13, 14);
1935 break;
1936 default:
1937 break;
1938 }
1939 ghost->target_pos = pos;
1940 }
1941
1942 // compute the next ghost direction, return true if resulting movement
1943 // should always happen regardless of current ghost position or blocking
1944 // tiles (this special case is used for movement inside the ghost house)
1945 static bool game_update_ghost_dir(ghost_t* ghost) {
1946 assert(ghost);
1947 // inside ghost-house, just move up and down
1948 if (ghost->state == GHOSTSTATE_HOUSE) {
1949 if (ghost->actor.pos.y <= 17*TILE_HEIGHT) {
1950 ghost->next_dir = DIR_DOWN;
1951 }
1952 else if (ghost->actor.pos.y >= 18*TILE_HEIGHT) {
1953 ghost->next_dir = DIR_UP;
1954 }
1955 ghost->actor.dir = ghost->next_dir;
1956 // force movement
1957 return true;
1958 }
1959 // navigate the ghost out of the ghost house
1960 else if (ghost->state == GHOSTSTATE_LEAVEHOUSE) {
1961 const int2_t pos = ghost->actor.pos;
1962 if (pos.x == ANTEPORTAS_X) {
1963 if (pos.y > ANTEPORTAS_Y) {
1964 ghost->next_dir = DIR_UP;
1965 }
1966 }
1967 else {
1968 const int16_t mid_y = 17*TILE_HEIGHT + TILE_HEIGHT/2;
1969 if (pos.y > mid_y) {
1970 ghost->next_dir = DIR_UP;
1971 }
1972 else if (pos.y < mid_y) {
1973 ghost->next_dir = DIR_DOWN;
1974 }
1975 else {
1976 ghost->next_dir = (pos.x > ANTEPORTAS_X) ? DIR_LEFT:DIR_RIGHT;
1977 }
1978 }
1979 ghost->actor.dir = ghost->next_dir;
1980 return true;
1981 }
1982 // navigate towards the ghost house target pos
1983 else if (ghost->state == GHOSTSTATE_ENTERHOUSE) {
1984 const int2_t pos = ghost->actor.pos;
1985 const int2_t tile_pos = pixel_to_tile_pos(pos);
1986 const int2_t tgt_pos = ghost_house_target_pos[ghost->type];
1987 if (tile_pos.y == 14) {
1988 if (pos.x != ANTEPORTAS_X) {
1989 ghost->next_dir = (pos.x < ANTEPORTAS_X) ? DIR_RIGHT:DIR_LEFT;
1990 }
1991 else {
1992 ghost->next_dir = DIR_DOWN;
1993 }
1994 }
1995 else if (pos.y == tgt_pos.y) {
1996 ghost->next_dir = (pos.x < tgt_pos.x) ? DIR_RIGHT:DIR_LEFT;
1997 }
1998 ghost->actor.dir = ghost->next_dir;
1999 return true;
2000 }
2001 // scatter/chase/frightened: just head towards the current target point
2002 else {
2003 // only compute new direction when currently at midpoint of tile
2004 const int2_t dist_to_mid = dist_to_tile_mid(ghost->actor.pos);
2005 if ((dist_to_mid.x == 0) && (dist_to_mid.y == 0)) {
2006 // new direction is the previously computed next-direction
2007 ghost->actor.dir = ghost->next_dir;
2008
2009 // compute new next-direction
2010 const int2_t dir_vec = dir_to_vec(ghost->actor.dir);
2011 const int2_t lookahead_pos = add_i2(pixel_to_tile_pos(ghost->actor.pos), dir_vec);
2012
2013 // try each direction and take the one that moves closest to the target
2014 const dir_t dirs[NUM_DIRS] = { DIR_UP, DIR_LEFT, DIR_DOWN, DIR_RIGHT };
2015 int min_dist = 100000;
2016 int dist = 0;
2017 for (int i = 0; i < NUM_DIRS; i++) {
2018 const dir_t dir = dirs[i];
2019 // if ghost is in one of the two 'red zones', forbid upward movement
2020 // (see Pacman Dossier "Areas To Exploit")
2021 if (is_redzone(lookahead_pos) && (dir == DIR_UP) && (ghost->state != GHOSTSTATE_EYES)) {
2022 continue;
2023 }
2024 const dir_t revdir = reverse_dir(dir);
2025 const int2_t test_pos = clamped_tile_pos(add_i2(lookahead_pos, dir_to_vec(dir)));
2026 if ((revdir != ghost->actor.dir) && !is_blocking_tile(test_pos)) {
2027 if ((dist = squared_distance_i2(test_pos, ghost->target_pos)) < min_dist) {
2028 min_dist = dist;
2029 ghost->next_dir = dir;
2030 }
2031 }
2032 }
2033 }
2034 return false;
2035 }
2036 }
2037
2038 /* Update the dot counters used to decide whether ghosts must leave the house.
2039
2040 This is called each time Pacman eats a dot.
2041
2042 Each ghost has a dot limit which is reset at the start of a round. Each time
2043 Pacman eats a dot, the highest priority ghost in the ghost house counts
2044 down its dot counter.
2045
2046 When the ghost's dot counter reaches zero the ghost leaves the house
2047 and the next highest-priority dot counter starts counting.
2048
2049 If a life is lost, the personal dot counters are deactivated and instead
2050 a global dot counter is used.
2051
2052 If pacman doesn't eat dots for a while, the next ghost is forced out of the
2053 house using a timer.
2054 */
2055 static void game_update_ghosthouse_dot_counters(void) {
2056 // if the new round was started because Pacman lost a life, use the global
2057 // dot counter (this mode will be deactivated again after all ghosts left the
2058 // house)
2059 if (state.game.global_dot_counter_active) {
2060 state.game.global_dot_counter++;
2061 }
2062 else {
2063 // otherwise each ghost has his own personal dot counter to decide
2064 // when to leave the ghost house
2065 for (int i = 0; i < NUM_GHOSTS; i++) {
2066 if (state.game.ghost[i].dot_counter < state.game.ghost[i].dot_limit) {
2067 state.game.ghost[i].dot_counter++;
2068 break;
2069 }
2070 }
2071 }
2072 }
2073
2074 // called when a dot or pill has been eaten, checks if a round has been won
2075 // (all dots and pills eaten), whether to show the bonus fruit, and finally
2076 // plays the dot-eaten sound effect
2077 static void game_update_dots_eaten(void) {
2078 state.game.num_dots_eaten++;
2079 if (state.game.num_dots_eaten == NUM_DOTS) {
2080 // all dots eaten, round won
2081 start(&state.game.round_won);
2082 snd_clear();
2083 }
2084 else if ((state.game.num_dots_eaten == 70) || (state.game.num_dots_eaten == 170)) {
2085 // at 70 and 170 dots, show the bonus fruit
2086 start(&state.game.fruit_active);
2087 }
2088
2089 // play alternating crunch sound effect when a dot has been eaten
2090 if (state.game.num_dots_eaten & 1) {
2091 snd_start(2, &snd_eatdot1);
2092 }
2093 else {
2094 snd_start(2, &snd_eatdot2);
2095 }
2096 }
2097
2098 // the central Pacman and ghost behaviour function, called once per game tick
2099 static void game_update_actors(void) {
2100 // Pacman "AI"
2101 if (game_pacman_should_move()) {
2102 // move Pacman with cornering allowed
2103 actor_t* actor = &state.game.pacman.actor;
2104 const dir_t wanted_dir = input_dir(actor->dir);
2105 const bool allow_cornering = true;
2106 // look ahead to check if the wanted direction is blocked
2107 if (can_move(actor->pos, wanted_dir, allow_cornering)) {
2108 actor->dir = wanted_dir;
2109 }
2110 // move into the selected direction
2111 if (can_move(actor->pos, actor->dir, allow_cornering)) {
2112 actor->pos = move(actor->pos, actor->dir, allow_cornering);
2113 actor->anim_tick++;
2114 }
2115 // eat dot or energizer pill?
2116 const int2_t tile_pos = pixel_to_tile_pos(actor->pos);
2117 if (is_dot(tile_pos)) {
2118 vid_tile(tile_pos, TILE_SPACE);
2119 state.game.score += 1;
2120 start(&state.game.dot_eaten);
2121 start(&state.game.force_leave_house);
2122 game_update_dots_eaten();
2123 game_update_ghosthouse_dot_counters();
2124 }
2125 if (is_pill(tile_pos)) {
2126 vid_tile(tile_pos, TILE_SPACE);
2127 state.game.score += 5;
2128 game_update_dots_eaten();
2129 start(&state.game.pill_eaten);
2130 state.game.num_ghosts_eaten = 0;
2131 for (int i = 0; i < NUM_GHOSTS; i++) {
2132 start(&state.game.ghost[i].frightened);
2133 }
2134 snd_start(1, &snd_frightened);
2135 }
2136 // check if Pacman eats the bonus fruit
2137 if (state.game.active_fruit != FRUIT_NONE) {
2138 const int2_t test_pos = pixel_to_tile_pos(add_i2(actor->pos, i2(TILE_WIDTH/2, 0)));
2139 if (equal_i2(test_pos, i2(14, 20))) {
2140 start(&state.game.fruit_eaten);
2141 uint32_t score = levelspec(state.game.round).bonus_score;
2142 state.game.score += score;
2143 vid_fruit_score(state.game.active_fruit);
2144 state.game.active_fruit = FRUIT_NONE;
2145 snd_start(2, &snd_eatfruit);
2146 }
2147 }
2148 // check if Pacman collides with any ghost
2149 for (int i = 0; i < NUM_GHOSTS; i++) {
2150 ghost_t* ghost = &state.game.ghost[i];
2151 const int2_t ghost_tile_pos = pixel_to_tile_pos(ghost->actor.pos);
2152 if (equal_i2(tile_pos, ghost_tile_pos)) {
2153 if (ghost->state == GHOSTSTATE_FRIGHTENED) {
2154 // Pacman eats a frightened ghost
2155 ghost->state = GHOSTSTATE_EYES;
2156 start(&ghost->eaten);
2157 start(&state.game.ghost_eaten);
2158 state.game.num_ghosts_eaten++;
2159 // increase score by 20, 40, 80, 160
2160 state.game.score += 10 * (1<<state.game.num_ghosts_eaten);
2161 state.game.freeze |= FREEZETYPE_EAT_GHOST;
2162 snd_start(2, &snd_eatghost);
2163 }
2164 else if ((ghost->state == GHOSTSTATE_CHASE) || (ghost->state == GHOSTSTATE_SCATTER)) {
2165 // otherwise, ghost eats Pacman, Pacman loses a life
2166 #if !DBG_GODMODE
2167 snd_clear();
2168 start(&state.game.pacman_eaten);
2169 state.game.freeze |= FREEZETYPE_DEAD;
2170 // if Pacman has any lives left start a new round, otherwise start the game-over sequence
2171 if (state.game.num_lives > 0) {
2172 start_after(&state.game.ready_started, PACMAN_EATEN_TICKS+PACMAN_DEATH_TICKS);
2173 }
2174 else {
2175 start_after(&state.game.game_over, PACMAN_EATEN_TICKS+PACMAN_DEATH_TICKS);
2176 }
2177 #endif
2178 }
2179 }
2180 }
2181 }
2182
2183 // Ghost "AIs"
2184 for (int ghost_index = 0; ghost_index < NUM_GHOSTS; ghost_index++) {
2185 ghost_t* ghost = &state.game.ghost[ghost_index];
2186 // handle ghost-state transitions
2187 game_update_ghost_state(ghost);
2188 // update the ghost's target position
2189 game_update_ghost_target(ghost);
2190 // finally, move the ghost towards the current target position
2191 const int num_move_ticks = game_ghost_speed(ghost);
2192 for (int i = 0; i < num_move_ticks; i++) {
2193 bool force_move = game_update_ghost_dir(ghost);
2194 actor_t* actor = &ghost->actor;
2195 const bool allow_cornering = false;
2196 if (force_move || can_move(actor->pos, actor->dir, allow_cornering)) {
2197 actor->pos = move(actor->pos, actor->dir, allow_cornering);
2198 actor->anim_tick++;
2199 }
2200 }
2201 }
2202 }
2203
2204 // the central game tick function, called at 60 Hz
2205 static void game_tick(void) {
2206 // debug: skip prelude
2207 #if DBG_SKIP_PRELUDE
2208 const int prelude_ticks_per_sec = 1;
2209 #else
2210 const int prelude_ticks_per_sec = 60;
2211 #endif
2212
2213 // initialize game state once
2214 if (now(state.game.started)) {
2215 start(&state.gfx.fadein);
2216 start_after(&state.game.ready_started, 2*prelude_ticks_per_sec);
2217 snd_start(0, &snd_prelude);
2218 game_init();
2219 }
2220 // initialize new round (each time Pacman looses a life), make actors visible, remove "PLAYER ONE", start a new life
2221 if (now(state.game.ready_started)) {
2222 game_round_init();
2223 // after 2 seconds start the interactive game loop
2224 start_after(&state.game.round_started, 2*60+10);
2225 }
2226 if (now(state.game.round_started)) {
2227 state.game.freeze &= ~FREEZETYPE_READY;
2228 // clear the 'READY!' message
2229 vid_color_text(i2(11,20), 0x10, " ");
2230 snd_start(1, &snd_weeooh);
2231 }
2232
2233 // activate/deactivate bonus fruit
2234 if (now(state.game.fruit_active)) {
2235 state.game.active_fruit = levelspec(state.game.round).bonus_fruit;
2236 }
2237 else if (after_once(state.game.fruit_active, FRUITACTIVE_TICKS)) {
2238 state.game.active_fruit = FRUIT_NONE;
2239 }
2240
2241 // stop frightened sound and start weeooh sound
2242 if (after_once(state.game.pill_eaten, levelspec(state.game.round).fright_ticks)) {
2243 snd_start(1, &snd_weeooh);
2244 }
2245
2246 // if game is frozen because Pacman ate a ghost, unfreeze after a while
2247 if (state.game.freeze & FREEZETYPE_EAT_GHOST) {
2248 if (after_once(state.game.ghost_eaten, GHOST_EATEN_FREEZE_TICKS)) {
2249 state.game.freeze &= ~FREEZETYPE_EAT_GHOST;
2250 }
2251 }
2252
2253 // play pacman-death sound
2254 if (after_once(state.game.pacman_eaten, PACMAN_EATEN_TICKS)) {
2255 snd_start(2, &snd_dead);
2256 }
2257
2258 // the actually important part: update Pacman and ghosts, update dynamic
2259 // background tiles, and update the sprite images
2260 if (!state.game.freeze) {
2261 game_update_actors();
2262 }
2263 game_update_tiles();
2264 game_update_sprites();
2265
2266 // update hiscore
2267 if (state.game.score > state.game.hiscore) {
2268 state.game.hiscore = state.game.score;
2269 }
2270
2271 // check for end-round condition
2272 if (now(state.game.round_won)) {
2273 state.game.freeze |= FREEZETYPE_WON;
2274 start_after(&state.game.ready_started, ROUNDWON_TICKS);
2275 }
2276 if (now(state.game.game_over)) {
2277 // display game over string
2278 vid_color_text(i2(9,20), 0x01, "GAME OVER");
2279 input_disable();
2280 start_after(&state.gfx.fadeout, GAMEOVER_TICKS);
2281 start_after(&state.intro.started, GAMEOVER_TICKS+FADE_TICKS);
2282 }
2283
2284 #if DBG_ESCAPE
2285 if (state.input.esc) {
2286 input_disable();
2287 start(&state.gfx.fadeout);
2288 start_after(&state.intro.started, FADE_TICKS);
2289 }
2290 #endif
2291
2292 #if DBG_MARKERS
2293 // visualize current ghost targets
2294 for (int i = 0; i < NUM_GHOSTS; i++) {
2295 const ghost_t* ghost = &state.game.ghost[i];
2296 uint8_t tile = 'X';
2297 switch (ghost->state) {
2298 case GHOSTSTATE_NONE: tile = 'N'; break;
2299 case GHOSTSTATE_CHASE: tile = 'C'; break;
2300 case GHOSTSTATE_SCATTER: tile = 'S'; break;
2301 case GHOSTSTATE_FRIGHTENED: tile = 'F'; break;
2302 case GHOSTSTATE_EYES: tile = 'E'; break;
2303 case GHOSTSTATE_HOUSE: tile = 'H'; break;
2304 case GHOSTSTATE_LEAVEHOUSE: tile = 'L'; break;
2305 case GHOSTSTATE_ENTERHOUSE: tile = 'E'; break;
2306 }
2307 dbg_marker(i, state.game.ghost[i].target_pos, tile, COLOR_BLINKY+2*i);
2308 }
2309 #endif
2310 }
2311
2312 /*== INTRO GAMESTATE CODE ====================================================*/
2313
2314 static void intro_tick(void) {
2315
2316 // on intro-state enter, enable input and draw any initial text
2317 if (now(state.intro.started)) {
2318 snd_clear();
2319 spr_clear();
2320 start(&state.gfx.fadein);
2321 input_enable();
2322 vid_clear(TILE_SPACE, COLOR_DEFAULT);
2323 vid_text(i2(3,0), "1UP HIGH SCORE 2UP");
2324 vid_color_score(i2(6,1), COLOR_DEFAULT, 0);
2325 if (state.game.hiscore > 0) {
2326 vid_color_score(i2(16,1), COLOR_DEFAULT, state.game.hiscore);
2327 }
2328 vid_text(i2(7,5), "CHARACTER / NICKNAME");
2329 vid_text(i2(3,35), "CREDIT 0");
2330 }
2331
2332 // draw the animated 'ghost image.. name.. nickname' lines
2333 uint32_t delay = 30;
2334 const char* names[] = { "-SHADOW", "-SPEEDY", "-BASHFUL", "-POKEY" };
2335 const char* nicknames[] = { "BLINKY", "PINKY", "INKY", "CLYDE" };
2336 for (int i = 0; i < 4; i++) {
2337 const uint8_t color = 2*i + 1;
2338 const uint8_t y = 3*i + 6;
2339 // 2*3 ghost image created from tiles (no sprite!)
2340 delay += 30;
2341 if (after_once(state.intro.started, delay)) {
2342 vid_color_tile(i2(4,y+0), color, TILE_GHOST+0); vid_color_tile(i2(5,y+0), color, TILE_GHOST+1);
2343 vid_color_tile(i2(4,y+1), color, TILE_GHOST+2); vid_color_tile(i2(5,y+1), color, TILE_GHOST+3);
2344 vid_color_tile(i2(4,y+2), color, TILE_GHOST+4); vid_color_tile(i2(5,y+2), color, TILE_GHOST+5);
2345 }
2346 // after 1 second, the name of the ghost
2347 delay += 60;
2348 if (after_once(state.intro.started, delay)) {
2349 vid_color_text(i2(7,y+1), color, names[i]);
2350 }
2351 // after 0.5 seconds, the nickname of the ghost
2352 delay += 30;
2353 if (after_once(state.intro.started, delay)) {
2354 vid_color_text(i2(17,y+1), color, nicknames[i]);
2355 }
2356 }
2357
2358 // . 10 PTS
2359 // O 50 PTS
2360 delay += 60;
2361 if (after_once(state.intro.started, delay)) {
2362 vid_color_tile(i2(10,24), COLOR_DOT, TILE_DOT);
2363 vid_text(i2(12,24), "10 \x5D\x5E\x5F");
2364 vid_color_tile(i2(10,26), COLOR_DOT, TILE_PILL);
2365 vid_text(i2(12,26), "50 \x5D\x5E\x5F");
2366 }
2367
2368 // blinking "press any key" text
2369 delay += 60;
2370 if (after(state.intro.started, delay)) {
2371 if (since(state.intro.started) & 0x20) {
2372 vid_color_text(i2(3,31), 3, " ");
2373 }
2374 else {
2375 vid_color_text(i2(3,31), 3, "PRESS ANY KEY TO START!");
2376 }
2377 }
2378
2379 // FIXME: animated chase sequence
2380
2381 // if a key is pressed, advance to game state
2382 if (state.input.anykey) {
2383 input_disable();
2384 start(&state.gfx.fadeout);
2385 start_after(&state.game.started, FADE_TICKS);
2386 }
2387 }
2388
2389 /*== GFX SUBSYSTEM ===========================================================*/
2390
2391 /* create all sokol-gfx resources */
2392 static void gfx_create_resources(void) {
2393 // pass action for clearing the background to black
2394 state.gfx.pass_action = (sg_pass_action) {
2395 .colors[0] = { .load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.0f, 0.0f, 0.0f, 1.0f } }
2396 };
2397
2398 // create a dynamic vertex buffer for the tile and sprite quads
2399 state.gfx.offscreen.vbuf = sg_make_buffer(&(sg_buffer_desc){
2400 .type = SG_BUFFERTYPE_VERTEXBUFFER,
2401 .usage = SG_USAGE_STREAM,
2402 .size = sizeof(state.gfx.vertices),
2403 });
2404
2405 // create a simple quad vertex buffer for rendering the offscreen render target to the display
2406 float quad_verts[]= { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f };
2407 state.gfx.display.quad_vbuf = sg_make_buffer(&(sg_buffer_desc){
2408 .data = SG_RANGE(quad_verts)
2409 });
2410
2411 // shader sources for all platforms (FIXME: should we use precompiled shader blobs instead?)
2412 const char* offscreen_vs_src = 0;
2413 const char* offscreen_fs_src = 0;
2414 const char* display_vs_src = 0;
2415 const char* display_fs_src = 0;
2416 switch (sg_query_backend()) {
2417 case SG_BACKEND_METAL_MACOS:
2418 offscreen_vs_src =
2419 "#include <metal_stdlib>\n"
2420 "using namespace metal;\n"
2421 "struct vs_in {\n"
2422 " float4 pos [[attribute(0)]];\n"
2423 " float2 uv [[attribute(1)]];\n"
2424 " float4 data [[attribute(2)]];\n"
2425 "};\n"
2426 "struct vs_out {\n"
2427 " float4 pos [[position]];\n"
2428 " float2 uv;\n"
2429 " float4 data;\n"
2430 "};\n"
2431 "vertex vs_out _main(vs_in in [[stage_in]]) {\n"
2432 " vs_out out;\n"
2433 " out.pos = float4((in.pos.xy - 0.5) * float2(2.0, -2.0), 0.5, 1.0);\n"
2434 " out.uv = in.uv;"
2435 " out.data = in.data;\n"
2436 " return out;\n"
2437 "}\n";
2438 offscreen_fs_src =
2439 "#include <metal_stdlib>\n"
2440 "using namespace metal;\n"
2441 "struct ps_in {\n"
2442 " float2 uv;\n"
2443 " float4 data;\n"
2444 "};\n"
2445 "fragment float4 _main(ps_in in [[stage_in]],\n"
2446 " texture2d<float> tile_tex [[texture(0)]],\n"
2447 " texture2d<float> pal_tex [[texture(1)]],\n"
2448 " sampler tile_smp [[sampler(0)]],\n"
2449 " sampler pal_smp [[sampler(1)]])\n"
2450 "{\n"
2451 " float color_code = in.data.x;\n" // (0..31) / 255
2452 " float tile_color = tile_tex.sample(tile_smp, in.uv).x;\n" // (0..3) / 255
2453 " float2 pal_uv = float2(color_code * 4 + tile_color, 0);\n"
2454 " float4 color = pal_tex.sample(pal_smp, pal_uv) * float4(1, 1, 1, in.data.y);\n"
2455 " return color;\n"
2456 "}\n";
2457 display_vs_src =
2458 "#include <metal_stdlib>\n"
2459 "using namespace metal;\n"
2460 "struct vs_in {\n"
2461 " float4 pos [[attribute(0)]];\n"
2462 "};\n"
2463 "struct vs_out {\n"
2464 " float4 pos [[position]];\n"
2465 " float2 uv;\n"
2466 "};\n"
2467 "vertex vs_out _main(vs_in in[[stage_in]]) {\n"
2468 " vs_out out;\n"
2469 " out.pos = float4((in.pos.xy - 0.5) * float2(2.0, -2.0), 0.0, 1.0);\n"
2470 " out.uv = in.pos.xy;\n"
2471 " return out;\n"
2472 "}\n";
2473 display_fs_src =
2474 "#include <metal_stdlib>\n"
2475 "using namespace metal;\n"
2476 "struct ps_in {\n"
2477 " float2 uv;\n"
2478 "};\n"
2479 "fragment float4 _main(ps_in in [[stage_in]],\n"
2480 " texture2d<float> tex [[texture(0)]],\n"
2481 " sampler smp [[sampler(0)]])\n"
2482 "{\n"
2483 " return tex.sample(smp, in.uv);\n"
2484 "}\n";
2485 break;
2486 case SG_BACKEND_D3D11:
2487 offscreen_vs_src =
2488 "struct vs_in {\n"
2489 " float4 pos: POSITION;\n"
2490 " float2 uv: TEXCOORD0;\n"
2491 " float4 data: TEXCOORD1;\n"
2492 "};\n"
2493 "struct vs_out {\n"
2494 " float2 uv: UV;\n"
2495 " float4 data: DATA;\n"
2496 " float4 pos: SV_Position;\n"
2497 "};\n"
2498 "vs_out main(vs_in inp) {\n"
2499 " vs_out outp;"
2500 " outp.pos = float4(inp.pos.xy * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);\n"
2501 " outp.uv = inp.uv;"
2502 " outp.data = inp.data;\n"
2503 " return outp;\n"
2504 "}\n";
2505 offscreen_fs_src =
2506 "Texture2D<float4> tile_tex: register(t0);\n"
2507 "Texture2D<float4> pal_tex: register(t1);\n"
2508 "sampler tile_smp: register(s0);\n"
2509 "sampler pal_smp: register(s1);\n"
2510 "float4 main(float2 uv: UV, float4 data: DATA): SV_Target0 {\n"
2511 " float color_code = data.x;\n"
2512 " float tile_color = tile_tex.Sample(tile_smp, uv).x;\n"
2513 " float2 pal_uv = float2(color_code * 4 + tile_color, 0);\n"
2514 " float4 color = pal_tex.Sample(pal_smp, pal_uv) * float4(1, 1, 1, data.y);\n"
2515 " return color;\n"
2516 "}\n";
2517 display_vs_src =
2518 "struct vs_out {\n"
2519 " float2 uv: UV;\n"
2520 " float4 pos: SV_Position;\n"
2521 "};\n"
2522 "vs_out main(float4 pos: POSITION) {\n"
2523 " vs_out outp;\n"
2524 " outp.pos = float4((pos.xy - 0.5) * float2(2.0, -2.0), 0.0, 1.0);\n"
2525 " outp.uv = pos.xy;\n"
2526 " return outp;\n"
2527 "}\n";
2528 display_fs_src =
2529 "Texture2D<float4> tex: register(t0);\n"
2530 "sampler smp: register(s0);\n"
2531 "float4 main(float2 uv: UV): SV_Target0 {\n"
2532 " return tex.Sample(smp, uv);\n"
2533 "}\n";
2534 break;
2535 case SG_BACKEND_GLCORE:
2536 offscreen_vs_src =
2537 "#version 410\n"
2538 "layout(location=0) in vec4 pos;\n"
2539 "layout(location=1) in vec2 uv_in;\n"
2540 "layout(location=2) in vec4 data_in;\n"
2541 "out vec2 uv;\n"
2542 "out vec4 data;\n"
2543 "void main() {\n"
2544 " gl_Position = vec4((pos.xy - 0.5) * vec2(2.0, -2.0), 0.5, 1.0);\n"
2545 " uv = uv_in;"
2546 " data = data_in;\n"
2547 "}\n";
2548 offscreen_fs_src =
2549 "#version 410\n"
2550 "uniform sampler2D tile_tex;\n"
2551 "uniform sampler2D pal_tex;\n"
2552 "in vec2 uv;\n"
2553 "in vec4 data;\n"
2554 "out vec4 frag_color;\n"
2555 "void main() {\n"
2556 " float color_code = data.x;\n"
2557 " float tile_color = texture(tile_tex, uv).x;\n"
2558 " vec2 pal_uv = vec2(color_code * 4 + tile_color, 0);\n"
2559 " frag_color = texture(pal_tex, pal_uv) * vec4(1, 1, 1, data.y);\n"
2560 "}\n";
2561 display_vs_src =
2562 "#version 410\n"
2563 "layout(location=0) in vec4 pos;\n"
2564 "out vec2 uv;\n"
2565 "void main() {\n"
2566 " gl_Position = vec4((pos.xy - 0.5) * 2.0, 0.0, 1.0);\n"
2567 " uv = pos.xy;\n"
2568 "}\n";
2569 display_fs_src =
2570 "#version 410\n"
2571 "uniform sampler2D tex;\n"
2572 "in vec2 uv;\n"
2573 "out vec4 frag_color;\n"
2574 "void main() {\n"
2575 " frag_color = texture(tex, uv);\n"
2576 "}\n";
2577 break;
2578 case SG_BACKEND_GLES3:
2579 offscreen_vs_src =
2580 "attribute vec4 pos;\n"
2581 "attribute vec2 uv_in;\n"
2582 "attribute vec4 data_in;\n"
2583 "varying vec2 uv;\n"
2584 "varying vec4 data;\n"
2585 "void main() {\n"
2586 " gl_Position = vec4((pos.xy - 0.5) * vec2(2.0, -2.0), 0.5, 1.0);\n"
2587 " uv = uv_in;"
2588 " data = data_in;\n"
2589 "}\n";
2590 offscreen_fs_src =
2591 "precision mediump float;\n"
2592 "uniform sampler2D tile_tex;\n"
2593 "uniform sampler2D pal_tex;\n"
2594 "varying vec2 uv;\n"
2595 "varying vec4 data;\n"
2596 "void main() {\n"
2597 " float color_code = data.x;\n"
2598 " float tile_color = texture2D(tile_tex, uv).x;\n"
2599 " vec2 pal_uv = vec2(color_code * 4.0 + tile_color, 0.0);\n"
2600 " gl_FragColor = texture2D(pal_tex, pal_uv) * vec4(1.0, 1.0, 1.0, data.y);\n"
2601 "}\n";
2602 display_vs_src =
2603 "attribute vec4 pos;\n"
2604 "varying vec2 uv;\n"
2605 "void main() {\n"
2606 " gl_Position = vec4((pos.xy - 0.5) * 2.0, 0.0, 1.0);\n"
2607 " uv = pos.xy;\n"
2608 "}\n";
2609 display_fs_src =
2610 "precision mediump float;\n"
2611 "uniform sampler2D tex;\n"
2612 "varying vec2 uv;\n"
2613 "void main() {\n"
2614 " gl_FragColor = texture2D(tex, uv);\n"
2615 "}\n";
2616 break;
2617 default:
2618 assert(false);
2619 }
2620
2621 // create pipeline and shader object for rendering into offscreen render target
2622 state.gfx.offscreen.pip = sg_make_pipeline(&(sg_pipeline_desc){
2623 .shader = sg_make_shader(&(sg_shader_desc){
2624 .attrs = {
2625 [0] = { .name="pos", .sem_name="POSITION" },
2626 [1] = { .name="uv_in", .sem_name="TEXCOORD", .sem_index=0 },
2627 [2] = { .name="data_in", .sem_name="TEXCOORD", .sem_index=1 },
2628 },
2629 .vs.source = offscreen_vs_src,
2630 .fs = {
2631 .images = {
2632 [0] = { .used = true },
2633 [1] = { .used = true },
2634 },
2635 .samplers = {
2636 [0] = { .used = true },
2637 [1] = { .used = true },
2638 },
2639 .image_sampler_pairs = {
2640 [0] = { .used = true, .image_slot = 0, .sampler_slot = 0, .glsl_name = "tile_tex" },
2641 [1] = { .used = true, .image_slot = 1, .sampler_slot = 1, .glsl_name = "pal_tex" },
2642 },
2643 .source = offscreen_fs_src
2644 }
2645 }),
2646 .layout = {
2647 .attrs = {
2648 [0].format = SG_VERTEXFORMAT_FLOAT2,
2649 [1].format = SG_VERTEXFORMAT_FLOAT2,
2650 [2].format = SG_VERTEXFORMAT_UBYTE4N,
2651 }
2652 },
2653 .depth.pixel_format = SG_PIXELFORMAT_NONE,
2654 .colors[0] = {
2655 .pixel_format = SG_PIXELFORMAT_RGBA8,
2656 .blend = {
2657 .enabled = true,
2658 .src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA,
2659 .dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
2660 }
2661 }
2662 });
2663
2664 // create pipeline and shader for rendering into display
2665 state.gfx.display.pip = sg_make_pipeline(&(sg_pipeline_desc){
2666 .shader = sg_make_shader(&(sg_shader_desc){
2667 .attrs[0] = { .name="pos", .sem_name="POSITION" },
2668 .vs.source = display_vs_src,
2669 .fs = {
2670 .images[0].used = true,
2671 .samplers[0].used = true,
2672 .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0, .glsl_name = "tex" },
2673 .source = display_fs_src
2674 }
2675 }),
2676 .layout.attrs[0].format = SG_VERTEXFORMAT_FLOAT2,
2677 .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP
2678 });
2679
2680 // create a render target image with a fixed upscale ratio
2681 state.gfx.offscreen.render_target = sg_make_image(&(sg_image_desc){
2682 .render_target = true,
2683 .width = DISPLAY_PIXELS_X * 2,
2684 .height = DISPLAY_PIXELS_Y * 2,
2685 .pixel_format = SG_PIXELFORMAT_RGBA8,
2686 });
2687
2688 // create an sampler to render the offscreen render target with linear upscale filtering
2689 state.gfx.display.sampler = sg_make_sampler(&(sg_sampler_desc){
2690 .min_filter = SG_FILTER_LINEAR,
2691 .mag_filter = SG_FILTER_LINEAR,
2692 .wrap_u = SG_WRAP_CLAMP_TO_EDGE,
2693 .wrap_v = SG_WRAP_CLAMP_TO_EDGE,
2694 });
2695
2696 // pass object for rendering into the offscreen render target
2697 state.gfx.offscreen.attachments = sg_make_attachments(&(sg_attachments_desc){
2698 .colors[0].image = state.gfx.offscreen.render_target
2699 });
2700
2701 // create the 'tile-ROM-texture'
2702 state.gfx.offscreen.tile_img = sg_make_image(&(sg_image_desc){
2703 .width = TILE_TEXTURE_WIDTH,
2704 .height = TILE_TEXTURE_HEIGHT,
2705 .pixel_format = SG_PIXELFORMAT_R8,
2706 .data.subimage[0][0] = SG_RANGE(state.gfx.tile_pixels)
2707 });
2708
2709 // create the palette texture
2710 state.gfx.offscreen.palette_img = sg_make_image(&(sg_image_desc){
2711 .width = 256,
2712 .height = 1,
2713 .pixel_format = SG_PIXELFORMAT_RGBA8,
2714 .data.subimage[0][0] = SG_RANGE(state.gfx.color_palette)
2715 });
2716
2717 // create a sampler with nearest filtering for the offscreen pass
2718 state.gfx.offscreen.sampler = sg_make_sampler(&(sg_sampler_desc){
2719 .min_filter = SG_FILTER_NEAREST,
2720 .mag_filter = SG_FILTER_NEAREST,
2721 .wrap_u = SG_WRAP_CLAMP_TO_EDGE,
2722 .wrap_v = SG_WRAP_CLAMP_TO_EDGE,
2723 });
2724 }
2725
2726 /*
2727 8x4 tile decoder (taken from: https://github.com/floooh/chips/blob/master/systems/namco.h)
2728
2729 This decodes 2-bit-per-pixel tile data from Pacman ROM dumps into
2730 8-bit-per-pixel texture data (without doing the RGB palette lookup,
2731 this happens during rendering in the pixel shader).
2732
2733 The Pacman ROM tile layout isn't exactly strightforward, both 8x8 tiles
2734 and 16x16 sprites are built from 8x4 pixel blocks layed out linearly
2735 in memory, and to add to the confusion, since Pacman is an arcade machine
2736 with the display 90 degree rotated, all the ROM tile data is counter-rotated.
2737
2738 Tile decoding only happens once at startup from ROM dumps into a texture.
2739 */
2740 static inline void gfx_decode_tile_8x4(
2741 uint32_t tex_x,
2742 uint32_t tex_y,
2743 const uint8_t* tile_base,
2744 uint32_t tile_stride,
2745 uint32_t tile_offset,
2746 uint8_t tile_code)
2747 {
2748 for (uint32_t tx = 0; tx < TILE_WIDTH; tx++) {
2749 uint32_t ti = tile_code * tile_stride + tile_offset + (7 - tx);
2750 for (uint32_t ty = 0; ty < (TILE_HEIGHT/2); ty++) {
2751 uint8_t p_hi = (tile_base[ti] >> (7 - ty)) & 1;
2752 uint8_t p_lo = (tile_base[ti] >> (3 - ty)) & 1;
2753 uint8_t p = (p_hi << 1) | p_lo;
2754 state.gfx.tile_pixels[tex_y + ty][tex_x + tx] = p;
2755 }
2756 }
2757 }
2758
2759 // decode an 8x8 tile into the tile texture's upper half
2760 static inline void gfx_decode_tile(uint8_t tile_code) {
2761 uint32_t x = tile_code * TILE_WIDTH;
2762 uint32_t y0 = 0;
2763 uint32_t y1 = y0 + (TILE_HEIGHT / 2);
2764 gfx_decode_tile_8x4(x, y0, rom_tiles, 16, 8, tile_code);
2765 gfx_decode_tile_8x4(x, y1, rom_tiles, 16, 0, tile_code);
2766 }
2767
2768 // decode a 16x16 sprite into the tile texture's lower half
2769 static inline void gfx_decode_sprite(uint8_t sprite_code) {
2770 uint32_t x0 = sprite_code * SPRITE_WIDTH;
2771 uint32_t x1 = x0 + TILE_WIDTH;
2772 uint32_t y0 = TILE_HEIGHT;
2773 uint32_t y1 = y0 + (TILE_HEIGHT / 2);
2774 uint32_t y2 = y1 + (TILE_HEIGHT / 2);
2775 uint32_t y3 = y2 + (TILE_HEIGHT / 2);
2776 gfx_decode_tile_8x4(x0, y0, rom_sprites, 64, 40, sprite_code);
2777 gfx_decode_tile_8x4(x1, y0, rom_sprites, 64, 8, sprite_code);
2778 gfx_decode_tile_8x4(x0, y1, rom_sprites, 64, 48, sprite_code);
2779 gfx_decode_tile_8x4(x1, y1, rom_sprites, 64, 16, sprite_code);
2780 gfx_decode_tile_8x4(x0, y2, rom_sprites, 64, 56, sprite_code);
2781 gfx_decode_tile_8x4(x1, y2, rom_sprites, 64, 24, sprite_code);
2782 gfx_decode_tile_8x4(x0, y3, rom_sprites, 64, 32, sprite_code);
2783 gfx_decode_tile_8x4(x1, y3, rom_sprites, 64, 0, sprite_code);
2784 }
2785
2786 // decode the Pacman tile- and sprite-ROM-dumps into a 8bpp texture
2787 static void gfx_decode_tiles(void) {
2788 for (uint32_t tile_code = 0; tile_code < 256; tile_code++) {
2789 gfx_decode_tile(tile_code);
2790 }
2791 for (uint32_t sprite_code = 0; sprite_code < 64; sprite_code++) {
2792 gfx_decode_sprite(sprite_code);
2793 }
2794 // write a special opaque 16x16 block which will be used for the fade-effect
2795 for (uint32_t y = TILE_HEIGHT; y < TILE_TEXTURE_HEIGHT; y++) {
2796 for (uint32_t x = 64*SPRITE_WIDTH; x < 65*SPRITE_WIDTH; x++) {
2797 state.gfx.tile_pixels[y][x] = 1;
2798 }
2799 }
2800 }
2801
2802 /* decode the Pacman color palette into a palette texture, on the original
2803 hardware, color lookup happens in two steps, first through 256-entry
2804 palette which indirects into a 32-entry hardware-color palette
2805 (of which only 16 entries are used on the Pacman hardware)
2806 */
2807 static void gfx_decode_color_palette(void) {
2808 uint32_t hw_colors[32];
2809 for (int i = 0; i < 32; i++) {
2810 /*
2811 Each color ROM entry describes an RGB color in 1 byte:
2812
2813 | 7| 6| 5| 4| 3| 2| 1| 0|
2814 |B1|B0|G2|G1|G0|R2|R1|R0|
2815
2816 Intensities are: 0x97 + 0x47 + 0x21
2817 */
2818 uint8_t rgb = rom_hwcolors[i];
2819 uint8_t r = ((rgb>>0)&1) * 0x21 + ((rgb>>1)&1) * 0x47 + ((rgb>>2)&1) * 0x97;
2820 uint8_t g = ((rgb>>3)&1) * 0x21 + ((rgb>>4)&1) * 0x47 + ((rgb>>5)&1) * 0x97;
2821 uint8_t b = ((rgb>>6)&1) * 0x47 + ((rgb>>7)&1) * 0x97;
2822 hw_colors[i] = 0xFF000000 | (b<<16) | (g<<8) | r;
2823 }
2824 for (int i = 0; i < 256; i++) {
2825 state.gfx.color_palette[i] = hw_colors[rom_palette[i] & 0xF];
2826 // first color in each color block is transparent
2827 if ((i & 3) == 0) {
2828 state.gfx.color_palette[i] &= 0x00FFFFFF;
2829 }
2830 }
2831 }
2832
2833 static void gfx_init(void) {
2834 sg_setup(&(sg_desc){
2835 // reduce pool allocation size to what's actually needed
2836 .buffer_pool_size = 2,
2837 .image_pool_size = 3,
2838 .shader_pool_size = 2,
2839 .pipeline_pool_size = 2,
2840 .attachments_pool_size = 1,
2841 .environment = sglue_environment(),
2842 .logger.func = slog_func,
2843 });
2844 disable(&state.gfx.fadein);
2845 disable(&state.gfx.fadeout);
2846 state.gfx.fade = 0xFF;
2847 spr_clear();
2848 gfx_decode_tiles();
2849 gfx_decode_color_palette();
2850 gfx_create_resources();
2851 }
2852
2853 static void gfx_shutdown(void) {
2854 sg_shutdown();
2855 }
2856
2857 static void gfx_add_vertex(float x, float y, float u, float v, uint8_t color_code, uint8_t opacity) {
2858 assert(state.gfx.num_vertices < MAX_VERTICES);
2859 vertex_t* vtx = &state.gfx.vertices[state.gfx.num_vertices++];
2860 vtx->x = x;
2861 vtx->y = y;
2862 vtx->u = u;
2863 vtx->v = v;
2864 vtx->attr = (opacity<<8) | color_code;
2865 }
2866
2867 static void gfx_add_tile_vertices(uint32_t tx, uint32_t ty, uint8_t tile_code, uint8_t color_code) {
2868 assert((tx < DISPLAY_TILES_X) && (ty < DISPLAY_TILES_Y));
2869 const float dx = 1.0f / DISPLAY_TILES_X;
2870 const float dy = 1.0f / DISPLAY_TILES_Y;
2871 const float du = (float)TILE_WIDTH / TILE_TEXTURE_WIDTH;
2872 const float dv = (float)TILE_HEIGHT / TILE_TEXTURE_HEIGHT;
2873
2874 const float x0 = tx * dx;
2875 const float x1 = x0 + dx;
2876 const float y0 = ty * dy;
2877 const float y1 = y0 + dy;
2878 const float u0 = tile_code * du;
2879 const float u1 = u0 + du;
2880 const float v0 = 0.0f;
2881 const float v1 = dv;
2882 /*
2883 x0,y0
2884 +-----+
2885 | * |
2886 | * |
2887 +-----+
2888 x1,y1
2889 */
2890 gfx_add_vertex(x0, y0, u0, v0, color_code, 0xFF);
2891 gfx_add_vertex(x1, y0, u1, v0, color_code, 0xFF);
2892 gfx_add_vertex(x1, y1, u1, v1, color_code, 0xFF);
2893 gfx_add_vertex(x0, y0, u0, v0, color_code, 0xFF);
2894 gfx_add_vertex(x1, y1, u1, v1, color_code, 0xFF);
2895 gfx_add_vertex(x0, y1, u0, v1, color_code, 0xFF);
2896 }
2897
2898 static void gfx_add_playfield_vertices(void) {
2899 for (uint32_t ty = 0; ty < DISPLAY_TILES_Y; ty++) {
2900 for (uint32_t tx = 0; tx < DISPLAY_TILES_X; tx++) {
2901 const uint8_t tile_code = state.gfx.video_ram[ty][tx];
2902 const uint8_t color_code = state.gfx.color_ram[ty][tx] & 0x1F;
2903 gfx_add_tile_vertices(tx, ty, tile_code, color_code);
2904 }
2905 }
2906 }
2907
2908 static void gfx_add_debugmarker_vertices(void) {
2909 for (int i = 0; i < NUM_DEBUG_MARKERS; i++) {
2910 const debugmarker_t* dbg = &state.gfx.debug_marker[i];
2911 if (dbg->enabled) {
2912 gfx_add_tile_vertices(dbg->tile_pos.x, dbg->tile_pos.y, dbg->tile, dbg->color);
2913 }
2914 }
2915 }
2916
2917 static void gfx_add_sprite_vertices(void) {
2918 const float dx = 1.0f / DISPLAY_PIXELS_X;
2919 const float dy = 1.0f / DISPLAY_PIXELS_Y;
2920 const float du = (float)SPRITE_WIDTH / TILE_TEXTURE_WIDTH;
2921 const float dv = (float)SPRITE_HEIGHT / TILE_TEXTURE_HEIGHT;
2922 for (int i = 0; i < NUM_SPRITES; i++) {
2923 const sprite_t* spr = &state.gfx.sprite[i];
2924 if (spr->enabled) {
2925 float x0, x1, y0, y1;
2926 if (spr->flipx) {
2927 x1 = spr->pos.x * dx;
2928 x0 = x1 + dx * SPRITE_WIDTH;
2929 }
2930 else {
2931 x0 = spr->pos.x * dx;
2932 x1 = x0 + dx * SPRITE_WIDTH;
2933 }
2934 if (spr->flipy) {
2935 y1 = spr->pos.y * dy;
2936 y0 = y1 + dy * SPRITE_HEIGHT;
2937 }
2938 else {
2939 y0 = spr->pos.y * dy;
2940 y1 = y0 + dy * SPRITE_HEIGHT;
2941 }
2942 const float u0 = spr->tile * du;
2943 const float u1 = u0 + du;
2944 const float v0 = ((float)TILE_HEIGHT / TILE_TEXTURE_HEIGHT);
2945 const float v1 = v0 + dv;
2946 const uint8_t color = spr->color;
2947 gfx_add_vertex(x0, y0, u0, v0, color, 0xFF);
2948 gfx_add_vertex(x1, y0, u1, v0, color, 0xFF);
2949 gfx_add_vertex(x1, y1, u1, v1, color, 0xFF);
2950 gfx_add_vertex(x0, y0, u0, v0, color, 0xFF);
2951 gfx_add_vertex(x1, y1, u1, v1, color, 0xFF);
2952 gfx_add_vertex(x0, y1, u0, v1, color, 0xFF);
2953 }
2954 }
2955 }
2956
2957 static void gfx_add_fade_vertices(void) {
2958 // sprite tile 64 is a special 16x16 opaque block
2959 const float du = (float)SPRITE_WIDTH / TILE_TEXTURE_WIDTH;
2960 const float dv = (float)SPRITE_HEIGHT / TILE_TEXTURE_HEIGHT;
2961 const float u0 = 64 * du;
2962 const float u1 = u0 + du;
2963 const float v0 = (float)TILE_HEIGHT / TILE_TEXTURE_HEIGHT;
2964 const float v1 = v0 + dv;
2965
2966 const uint8_t fade = state.gfx.fade;
2967 gfx_add_vertex(0.0f, 0.0f, u0, v0, 0, fade);
2968 gfx_add_vertex(1.0f, 0.0f, u1, v0, 0, fade);
2969 gfx_add_vertex(1.0f, 1.0f, u1, v1, 0, fade);
2970 gfx_add_vertex(0.0f, 0.0f, u0, v0, 0, fade);
2971 gfx_add_vertex(1.0f, 1.0f, u1, v1, 0, fade);
2972 gfx_add_vertex(0.0f, 1.0f, u0, v1, 0, fade);
2973 }
2974
2975 // adjust the viewport so that the aspect ratio is always correct
2976 static void gfx_adjust_viewport(int canvas_width, int canvas_height) {
2977 const float canvas_aspect = (float)canvas_width / (float)canvas_height;
2978 const float playfield_aspect = (float)DISPLAY_TILES_X / (float)DISPLAY_TILES_Y;
2979 int vp_x, vp_y, vp_w, vp_h;
2980 const int border = 10;
2981 if (playfield_aspect < canvas_aspect) {
2982 vp_y = border;
2983 vp_h = canvas_height - 2*border;
2984 vp_w = (int)(canvas_height * playfield_aspect - 2*border);
2985 vp_x = (canvas_width - vp_w) / 2;
2986 }
2987 else {
2988 vp_x = border;
2989 vp_w = canvas_width - 2*border;
2990 vp_h = (int)(canvas_width / playfield_aspect - 2*border);
2991 vp_y = (canvas_height - vp_h) / 2;
2992 }
2993 sg_apply_viewport(vp_x, vp_y, vp_w, vp_h, true);
2994 }
2995
2996 // handle fadein/fadeout
2997 static void gfx_fade(void) {
2998 if (between(state.gfx.fadein, 0, FADE_TICKS)) {
2999 float t = (float)since(state.gfx.fadein) / FADE_TICKS;
3000 state.gfx.fade = (uint8_t) (255.0f * (1.0f - t));
3001 }
3002 if (after_once(state.gfx.fadein, FADE_TICKS)) {
3003 state.gfx.fade = 0;
3004 }
3005 if (between(state.gfx.fadeout, 0, FADE_TICKS)) {
3006 float t = (float)since(state.gfx.fadeout) / FADE_TICKS;
3007 state.gfx.fade = (uint8_t) (255.0f * t);
3008 }
3009 if (after_once(state.gfx.fadeout, FADE_TICKS)) {
3010 state.gfx.fade = 255;
3011 }
3012 }
3013
3014 static void gfx_draw(void) {
3015 // handle fade in/out
3016 gfx_fade();
3017
3018 // update the playfield and sprite vertex buffer
3019 state.gfx.num_vertices = 0;
3020 gfx_add_playfield_vertices();
3021 gfx_add_sprite_vertices();
3022 gfx_add_debugmarker_vertices();
3023 if (state.gfx.fade > 0) {
3024 gfx_add_fade_vertices();
3025 }
3026 assert(state.gfx.num_vertices <= MAX_VERTICES);
3027 sg_update_buffer(state.gfx.offscreen.vbuf, &(sg_range){ .ptr=state.gfx.vertices, .size=state.gfx.num_vertices * sizeof(vertex_t) });
3028
3029 // render tiles and sprites into offscreen render target
3030 sg_begin_pass(&(sg_pass){ .action = state.gfx.pass_action, .attachments = state.gfx.offscreen.attachments });
3031 sg_apply_pipeline(state.gfx.offscreen.pip);
3032 sg_apply_bindings(&(sg_bindings){
3033 .vertex_buffers[0] = state.gfx.offscreen.vbuf,
3034 .fs = {
3035 .images = {
3036 [0] = state.gfx.offscreen.tile_img,
3037 [1] = state.gfx.offscreen.palette_img,
3038 },
3039 .samplers[0] = state.gfx.offscreen.sampler,
3040 .samplers[1] = state.gfx.offscreen.sampler,
3041 }
3042 });
3043 sg_draw(0, state.gfx.num_vertices, 1);
3044 sg_end_pass();
3045
3046 // upscale-render the offscreen render target into the display framebuffer
3047 const int canvas_width = sapp_width();
3048 const int canvas_height = sapp_height();
3049 sg_begin_pass(&(sg_pass){ .action = state.gfx.pass_action, .swapchain = sglue_swapchain() });
3050 gfx_adjust_viewport(canvas_width, canvas_height);
3051 sg_apply_pipeline(state.gfx.display.pip);
3052 sg_apply_bindings(&(sg_bindings){
3053 .vertex_buffers[0] = state.gfx.display.quad_vbuf,
3054 .fs = {
3055 .images[0] = state.gfx.offscreen.render_target,
3056 .samplers[0] = state.gfx.display.sampler,
3057 }
3058 });
3059 sg_draw(0, 4, 1);
3060 sg_end_pass();
3061 sg_commit();
3062 }
3063
3064 /*== AUDIO SUBSYSTEM =========================================================*/
3065 static void snd_init(void) {
3066 saudio_setup(&(saudio_desc){
3067 .logger.func = slog_func,
3068 });
3069
3070 // compute sample duration in nanoseconds
3071 int32_t samples_per_sec = saudio_sample_rate();
3072 state.audio.sample_duration_ns = 1000000000 / samples_per_sec;
3073
3074 /* compute number of 96kHz ticks per sample tick (the Namco sound generator
3075 runs at 96kHz), times 1000 for increased precision
3076 */
3077 state.audio.voice_tick_period = 96000000 / samples_per_sec;
3078 }
3079
3080 static void snd_shutdown(void) {
3081 saudio_shutdown();
3082 }
3083
3084 // the snd_voice_tick() function updates the Namco sound generator and must be called with 96 kHz
3085 static void snd_voice_tick(void) {
3086 for (int i = 0; i < NUM_VOICES; i++) {
3087 voice_t* voice = &state.audio.voice[i];
3088 voice->counter += voice->frequency;
3089 /* lookup current 4-bit sample from the waveform number and the
3090 topmost 5 bits of the 20-bit sample counter
3091 */
3092 uint32_t wave_index = ((voice->waveform<<5) | ((voice->counter>>15) & 0x1F)) & 0xFF;
3093 int sample = (((int)(rom_wavetable[wave_index] & 0xF)) - 8) * voice->volume;
3094 voice->sample_acc += (float)sample; // sample is (-8..+7 wavetable value) * 16 (volume)
3095 voice->sample_div += 128.0f;
3096 }
3097 }
3098
3099 // the snd_sample_tick() function must be called with sample frequency (e.g. 44.1kHz)
3100 static void snd_sample_tick(void) {
3101 float sm = 0.0f;
3102 for (int i = 0; i < NUM_VOICES; i++) {
3103 voice_t* voice = &state.audio.voice[i];
3104 if (voice->sample_div > 0.0f) {
3105 sm += voice->sample_acc / voice->sample_div;
3106 voice->sample_acc = voice->sample_div = 0.0f;
3107 }
3108 }
3109 state.audio.sample_buffer[state.audio.num_samples++] = sm * 0.333333f * AUDIO_VOLUME;
3110 if (state.audio.num_samples == NUM_SAMPLES) {
3111 saudio_push(state.audio.sample_buffer, state.audio.num_samples);
3112 state.audio.num_samples = 0;
3113 }
3114 }
3115
3116 // the sound subsystem's per-frame function
3117 static void snd_frame(int32_t frame_time_ns) {
3118 // for each sample to generate...
3119 state.audio.sample_accum -= frame_time_ns;
3120 while (state.audio.sample_accum < 0) {
3121 state.audio.sample_accum += state.audio.sample_duration_ns;
3122 // tick the sound generator at 96 KHz
3123 state.audio.voice_tick_accum -= state.audio.voice_tick_period;
3124 while (state.audio.voice_tick_accum < 0) {
3125 state.audio.voice_tick_accum += 1000;
3126 snd_voice_tick();
3127 }
3128 // generate a new sample, and push out to sokol-audio when local sample buffer full
3129 snd_sample_tick();
3130 }
3131 }
3132
3133 /* The sound system's 60 Hz tick function (called from game tick).
3134 Updates the sound 'hardware registers' for all active sound effects.
3135 */
3136 static void snd_tick(void) {
3137 // for each active sound effect...
3138 for (int sound_slot = 0; sound_slot < NUM_SOUNDS; sound_slot++) {
3139 sound_t* snd = &state.audio.sound[sound_slot];
3140 if (snd->func) {
3141 // procedural sound effect
3142 snd->func(sound_slot);
3143 }
3144 else if (snd->flags & SOUNDFLAG_ALL_VOICES) {
3145 // register-dump sound effect
3146 assert(snd->data);
3147 if (snd->cur_tick == snd->num_ticks) {
3148 snd_stop(sound_slot);
3149 continue;
3150 }
3151
3152 // decode register dump values into voice 'registers'
3153 const uint32_t* cur_ptr = &snd->data[snd->cur_tick * snd->stride];
3154 for (int i = 0; i < NUM_VOICES; i++) {
3155 if (snd->flags & (1<<i)) {
3156 voice_t* voice = &state.audio.voice[i];
3157 uint32_t val = *cur_ptr++;
3158 // 20 bits frequency
3159 voice->frequency = val & ((1<<20)-1);
3160 // 3 bits waveform
3161 voice->waveform = (val>>24) & 7;
3162 // 4 bits volume
3163 voice->volume = (val>>28) & 0xF;
3164 }
3165 }
3166 }
3167 snd->cur_tick++;
3168 }
3169 }
3170
3171 // clear all active sound effects and start outputting silence
3172 static void snd_clear(void) {
3173 memset(&state.audio.voice, 0, sizeof(state.audio.voice));
3174 memset(&state.audio.sound, 0, sizeof(state.audio.sound));
3175 }
3176
3177 // start a sound effect
3178 static void snd_start(int slot, const sound_desc_t* desc) {
3179 assert((slot >= 0) && (slot < NUM_SOUNDS));
3180 assert(desc);
3181 assert((desc->ptr && desc->size) || desc->func);
3182
3183 sound_t* snd = &state.audio.sound[slot];
3184 *snd = (sound_t) { 0 };
3185 int num_voices = 0;
3186 for (int i = 0; i < NUM_VOICES; i++) {
3187 if (desc->voice[i]) {
3188 snd->flags |= (1<<i);
3189 num_voices++;
3190 }
3191 }
3192 if (desc->func) {
3193 // procedural sounds only need a callback function
3194 snd->func = desc->func;
3195 }
3196 else {
3197 assert(num_voices > 0);
3198 assert((desc->size % (num_voices*sizeof(uint32_t))) == 0);
3199 snd->stride = num_voices;
3200 snd->num_ticks = desc->size / (snd->stride*sizeof(uint32_t));
3201 snd->data = desc->ptr;
3202 }
3203 }
3204
3205 // stop a sound effect
3206 static void snd_stop(int slot) {
3207 assert((slot >= 0) && (slot < NUM_SOUNDS));
3208
3209 // silence the sound's output voices
3210 for (int i = 0; i < NUM_VOICES; i++) {
3211 if (state.audio.sound[slot].flags & (1<<i)) {
3212 state.audio.voice[i] = (voice_t) { 0 };
3213 }
3214 }
3215
3216 // clear the sound slot
3217 state.audio.sound[slot] = (sound_t) { 0 };
3218 }
3219
3220 // procedural sound effects
3221 static void snd_func_eatdot1(int slot) {
3222 assert((slot >= 0) && (slot < NUM_SOUNDS));
3223 const sound_t* snd = &state.audio.sound[slot];
3224 voice_t* voice = &state.audio.voice[2];
3225 if (snd->cur_tick == 0) {
3226 voice->volume = 12;
3227 voice->waveform = 2;
3228 voice->frequency = 0x1500;
3229 }
3230 else if (snd->cur_tick == 5) {
3231 snd_stop(slot);
3232 }
3233 else {
3234 voice->frequency -= 0x0300;
3235 }
3236 }
3237
3238 static void snd_func_eatdot2(int slot) {
3239 assert((slot >= 0) && (slot < NUM_SOUNDS));
3240 const sound_t* snd = &state.audio.sound[slot];
3241 voice_t* voice = &state.audio.voice[2];
3242 if (snd->cur_tick == 0) {
3243 voice->volume = 12;
3244 voice->waveform = 2;
3245 voice->frequency = 0x0700;
3246 }
3247 else if (snd->cur_tick == 5) {
3248 snd_stop(slot);
3249 }
3250 else {
3251 voice->frequency += 0x300;
3252 }
3253 }
3254
3255 static void snd_func_eatghost(int slot) {
3256 assert((slot >= 0) && (slot < NUM_SOUNDS));
3257 const sound_t* snd = &state.audio.sound[slot];
3258 voice_t* voice = &state.audio.voice[2];
3259 if (snd->cur_tick == 0) {
3260 voice->volume = 12;
3261 voice->waveform = 5;
3262 voice->frequency = 0;
3263 }
3264 else if (snd->cur_tick == 32) {
3265 snd_stop(slot);
3266 }
3267 else {
3268 voice->frequency += 0x20;
3269 }
3270 }
3271
3272 static void snd_func_eatfruit(int slot) {
3273 assert((slot >= 0) && (slot < NUM_SOUNDS));
3274 const sound_t* snd = &state.audio.sound[slot];
3275 voice_t* voice = &state.audio.voice[2];
3276 if (snd->cur_tick == 0) {
3277 voice->volume = 15;
3278 voice->waveform = 6;
3279 voice->frequency = 0x1600;
3280 }
3281 else if (snd->cur_tick == 23) {
3282 snd_stop(slot);
3283 }
3284 else if (snd->cur_tick < 11) {
3285 voice->frequency -= 0x200;
3286 }
3287 else {
3288 voice->frequency += 0x0200;
3289 }
3290 }
3291
3292 static void snd_func_weeooh(int slot) {
3293 assert((slot >= 0) && (slot < NUM_SOUNDS));
3294 const sound_t* snd = &state.audio.sound[slot];
3295 voice_t* voice = &state.audio.voice[1];
3296 if (snd->cur_tick == 0) {
3297 voice->volume = 6;
3298 voice->waveform = 6;
3299 voice->frequency = 0x1000;
3300 }
3301 else if ((snd->cur_tick % 24) < 12) {
3302 voice->frequency += 0x0200;
3303 }
3304 else {
3305 voice->frequency -= 0x0200;
3306 }
3307 }
3308
3309 static void snd_func_frightened(int slot) {
3310 assert((slot >= 0) && (slot < NUM_SOUNDS));
3311 const sound_t* snd = &state.audio.sound[slot];
3312 voice_t* voice = &state.audio.voice[1];
3313 if (snd->cur_tick == 0) {
3314 voice->volume = 10;
3315 voice->waveform = 4;
3316 voice->frequency = 0x0180;
3317 }
3318 else if ((snd->cur_tick % 8) == 0) {
3319 voice->frequency = 0x0180;
3320 }
3321 else {
3322 voice->frequency += 0x180;
3323 }
3324 }
3325
3326 /*== EMBEDDED DATA ===========================================================*/
3327
3328 // Pacman sprite ROM dump
3329 static const uint8_t rom_tiles[4096] = {
3330 0xcc, 0xee, 0x11, 0x11, 0x33, 0xee, 0xcc, 0x0, 0x11, 0x33, 0x66, 0x44, 0x44, 0x33, 0x11, 0x0,
3331 0x11, 0x11, 0xff, 0xff, 0x11, 0x11, 0x0, 0x0, 0x0, 0x0, 0x77, 0x77, 0x22, 0x0, 0x0, 0x0,
3332 0x11, 0x99, 0xdd, 0xdd, 0xff, 0x77, 0x33, 0x0, 0x33, 0x77, 0x55, 0x44, 0x44, 0x66, 0x22, 0x0,
3333 0x66, 0xff, 0x99, 0x99, 0x99, 0x33, 0x22, 0x0, 0x44, 0x66, 0x77, 0x55, 0x44, 0x44, 0x0, 0x0,
3334 0x44, 0xff, 0xff, 0x44, 0x44, 0xcc, 0xcc, 0x0, 0x0, 0x77, 0x77, 0x66, 0x33, 0x11, 0x0, 0x0,
3335 0xee, 0xff, 0x11, 0x11, 0x11, 0x33, 0x22, 0x0, 0x0, 0x55, 0x55, 0x55, 0x55, 0x77, 0x77, 0x0,
3336 0x66, 0xff, 0x99, 0x99, 0x99, 0xff, 0xee, 0x0, 0x0, 0x44, 0x44, 0x44, 0x66, 0x33, 0x11, 0x0,
3337 0x0, 0x0, 0x88, 0xff, 0x77, 0x0, 0x0, 0x0, 0x66, 0x77, 0x55, 0x44, 0x44, 0x66, 0x66, 0x0,
3338 0x66, 0x77, 0xdd, 0xdd, 0x99, 0x99, 0x66, 0x0, 0x0, 0x33, 0x44, 0x44, 0x55, 0x77, 0x33, 0x0,
3339 0xcc, 0xee, 0xbb, 0x99, 0x99, 0x99, 0x0, 0x0, 0x33, 0x77, 0x44, 0x44, 0x44, 0x77, 0x33, 0x0,
3340 0xff, 0xff, 0x44, 0x44, 0x44, 0xff, 0xff, 0x0, 0x11, 0x33, 0x66, 0x44, 0x66, 0x33, 0x11, 0x0,
3341 0x66, 0xff, 0x99, 0x99, 0x99, 0xff, 0xff, 0x0, 0x33, 0x77, 0x44, 0x44, 0x44, 0x77, 0x77, 0x0,
3342 0x22, 0x33, 0x11, 0x11, 0x33, 0xee, 0xcc, 0x0, 0x22, 0x66, 0x44, 0x44, 0x66, 0x33, 0x11, 0x0,
3343 0xcc, 0xee, 0x33, 0x11, 0x11, 0xff, 0xff, 0x0, 0x11, 0x33, 0x66, 0x44, 0x44, 0x77, 0x77, 0x0,
3344 0x11, 0x99, 0x99, 0x99, 0xff, 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x0,
3369 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xee, 0xdd, 0x0, 0xee, 0xdd, 0x0, 0x0,
3370 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0x77, 0xff, 0xcc, 0xcc, 0xcc, 0xcc, 0xff, 0xff,
3371 0xbb, 0xbb, 0xbb, 0xbb, 0xff, 0xff, 0x0, 0x0, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0x11, 0x0, 0x0,
3372 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0xcc, 0xcc, 0xff, 0xff, 0x0, 0x0, 0x77, 0xff,
3373 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x77, 0xff, 0xcc, 0xcc, 0xff, 0xff,
3374 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xff, 0xee, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xff, 0x77,
3375 0x33, 0x33, 0x33, 0x33, 0xff, 0xee, 0x0, 0x0, 0xcc, 0xcc, 0xcc, 0xcc, 0xff, 0x77, 0x0, 0x0,
3376 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xee, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x77, 0xff,
3377 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
3378 0x88, 0xcc, 0x22, 0x22, 0x66, 0xcc, 0x88, 0x0, 0x33, 0x77, 0xcc, 0x88, 0x88, 0x77, 0x33, 0x0,
3379 0x22, 0x22, 0xee, 0xee, 0x22, 0x22, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0x44, 0x0, 0x0, 0x0,
3380 0x22, 0x22, 0xaa, 0xaa, 0xee, 0xee, 0x66, 0x0, 0x66, 0xff, 0xbb, 0x99, 0x99, 0xcc, 0x44, 0x0,
3381 0xcc, 0xee, 0x22, 0x22, 0x22, 0x66, 0x44, 0x0, 0x88, 0xdd, 0xff, 0xbb, 0x99, 0x88, 0x0, 0x0,
3382 0x88, 0xee, 0xee, 0x88, 0x88, 0x88, 0x88, 0x0, 0x0, 0xff, 0xff, 0xcc, 0x66, 0x33, 0x11, 0x0,
3383 0xcc, 0xee, 0x22, 0x22, 0x22, 0x66, 0x44, 0x0, 0x11, 0xbb, 0xaa, 0xaa, 0xaa, 0xee, 0xee, 0x0,
3384 0xcc, 0xee, 0x22, 0x22, 0x22, 0xee, 0xcc, 0x0, 0x0, 0x99, 0x99, 0x99, 0xdd, 0x77, 0x33, 0x0,
3385 0x0, 0x0, 0x0, 0xee, 0xee, 0x0, 0x0, 0x0, 0xcc, 0xee, 0xbb, 0x99, 0x88, 0xcc, 0xcc, 0x0,
3386 0xcc, 0xee, 0xaa, 0xaa, 0x22, 0x22, 0xcc, 0x0, 0x0, 0x66, 0x99, 0x99, 0xbb, 0xff, 0x66, 0x0,
3387 0x88, 0xcc, 0x66, 0x22, 0x22, 0x22, 0x0, 0x0, 0x77, 0xff, 0x99, 0x99, 0x99, 0xff, 0x66, 0x0,
3388 0x0, 0x0, 0x0, 0x0, 0x88, 0x44, 0x22, 0x0, 0x88, 0x44, 0x22, 0x11, 0x0, 0x0, 0x0, 0x0,
3389 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x11, 0x11, 0x11, 0x0, 0x0, 0x0,
3390 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
3391 0xff, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
3392 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0xff,
3393 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff,
3394 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
3395 0xee, 0xee, 0x88, 0x88, 0x88, 0xee, 0xee, 0x0, 0x33, 0x77, 0xcc, 0x88, 0xcc, 0x77, 0x33, 0x0,
3396 0xcc, 0xee, 0x22, 0x22, 0x22, 0xee, 0xee, 0x0, 0x66, 0xff, 0x99, 0x99, 0x99, 0xff, 0xff, 0x0,
3397 0x44, 0x66, 0x22, 0x22, 0x66, 0xcc, 0x88, 0x0, 0x44, 0xcc, 0x88, 0x88, 0xcc, 0x77, 0x33, 0x0,
3398 0x88, 0xcc, 0x66, 0x22, 0x22, 0xee, 0xee, 0x0, 0x33, 0x77, 0xcc, 0x88, 0x88, 0xff, 0xff, 0x0,
3399 0x22, 0x22, 0x22, 0x22, 0xee, 0xee, 0x0, 0x0, 0x88, 0x99, 0x99, 0x99, 0xff, 0xff, 0x0, 0x0,
3400 0x0, 0x0, 0x0, 0x0, 0x0, 0xee, 0xee, 0x0, 0x88, 0x99, 0x99, 0x99, 0x99, 0xff, 0xff, 0x0,
3401 0xee, 0xee, 0x22, 0x22, 0x66, 0xcc, 0x88, 0x0, 0x99, 0x99, 0x99, 0x88, 0xcc, 0x77, 0x33, 0x0,
3402 0xee, 0xee, 0x0, 0x0, 0x0, 0xee, 0xee, 0x0, 0xff, 0xff, 0x11, 0x11, 0x11, 0xff, 0xff, 0x0,
3403 0x22, 0x22, 0xee, 0xee, 0x22, 0x22, 0x0, 0x0, 0x88, 0x88, 0xff, 0xff, 0x88, 0x88, 0x0, 0x0,
3404 0xcc, 0xee, 0x22, 0x22, 0x22, 0x66, 0x44, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
3405 0x22, 0x66, 0xee, 0xcc, 0x88, 0xee, 0xee, 0x0, 0x88, 0xcc, 0x66, 0x33, 0x11, 0xff, 0xff, 0x0,
3406 0x22, 0x22, 0x22, 0x22, 0xee, 0xee, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0,
3407 0xee, 0xee, 0x0, 0x88, 0x0, 0xee, 0xee, 0x0, 0xff, 0xff, 0x77, 0x33, 0x77, 0xff, 0xff, 0x0,
3408 0xee, 0xee, 0xcc, 0x88, 0x0, 0xee, 0xee, 0x0, 0xff, 0xff, 0x11, 0x33, 0x77, 0xff, 0xff, 0x0,
3409 0xcc, 0xee, 0x22, 0x22, 0x22, 0xee, 0xcc, 0x0, 0x77, 0xff, 0x88, 0x88, 0x88, 0xff, 0x77, 0x0,
3410 0x0, 0x88, 0x88, 0x88, 0x88, 0xee, 0xee, 0x0, 0x77, 0xff, 0x88, 0x88, 0x88, 0xff, 0xff, 0x0,
3411 0xaa, 0xcc, 0xee, 0xaa, 0x22, 0xee, 0xcc, 0x0, 0x77, 0xff, 0x88, 0x88, 0x88, 0xff, 0x77, 0x0,
3412 0x22, 0x66, 0xee, 0xcc, 0x88, 0xee, 0xee, 0x0, 0x77, 0xff, 0x99, 0x88, 0x88, 0xff, 0xff, 0x0,
3413 0xcc, 0xee, 0x22, 0x22, 0x22, 0x66, 0x44, 0x0, 0x0, 0x55, 0xdd, 0x99, 0x99, 0xff, 0x66, 0x0,
3414 0x0, 0x0, 0xee, 0xee, 0x0, 0x0, 0x0, 0x0, 0x88, 0x88, 0xff, 0xff, 0x88, 0x88, 0x0, 0x0,
3415 0xcc, 0xee, 0x22, 0x22, 0x22, 0xee, 0xcc, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0xff, 0xff, 0x0,
3416 0x0, 0x88, 0xcc, 0xee, 0xcc, 0x88, 0x0, 0x0, 0xff, 0xff, 0x11, 0x0, 0x11, 0xff, 0xff, 0x0,
3417 0xee, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0xee, 0x0, 0xff, 0xff, 0x11, 0x33, 0x11, 0xff, 0xff, 0x0,
3418 0x66, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0x66, 0x0, 0xcc, 0xee, 0x77, 0x33, 0x77, 0xee, 0xcc, 0x0,
3419 0x0, 0x0, 0xee, 0xee, 0x0, 0x0, 0x0, 0x0, 0xee, 0xff, 0x11, 0x11, 0xff, 0xee, 0x0, 0x0,
3420 0x22, 0x22, 0x22, 0xaa, 0xee, 0xee, 0x66, 0x0, 0xcc, 0xee, 0xff, 0xbb, 0x99, 0x88, 0x88, 0x0,
3421 0x0, 0x0, 0x0, 0x0, 0x88, 0x22, 0x0, 0x0, 0x0, 0xcc, 0xee, 0xff, 0x33, 0x0, 0x0, 0x0,
3422 0xcc, 0x22, 0x11, 0x55, 0x55, 0x99, 0x22, 0xcc, 0x33, 0x44, 0x88, 0xaa, 0xaa, 0x99, 0x44, 0x33,
3423 0x0, 0x0, 0x0, 0x0, 0x88, 0x88, 0x88, 0xee, 0x22, 0x22, 0x0, 0x11, 0x22, 0x22, 0x22, 0x33,
3424 0xaa, 0xaa, 0xaa, 0x22, 0x0, 0x0, 0x0, 0xee, 0x22, 0x22, 0x22, 0x11, 0x0, 0x22, 0x22, 0x33,
3425 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x22,
3426 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
3427 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
3428 0x33, 0x77, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x33, 0x33, 0x33, 0x33, 0x0,
3429 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0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
3721 0x0, 0xcc, 0xee, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0x0, 0x0, 0x0, 0x11, 0x33, 0x33, 0x77, 0x77,
3722 0x0, 0x11, 0xbc, 0x3c, 0xf, 0x8f, 0xff, 0xff, 0x0, 0xff, 0xff, 0x7f, 0x7f, 0xff, 0xff, 0xff,
3723 0xee, 0xcc, 0x88, 0xcc, 0xee, 0xee, 0xcc, 0x0, 0x77, 0x77, 0x33, 0x33, 0x11, 0x0, 0x0, 0x0,
3724 0xbc, 0x3c, 0xf, 0x8f, 0xff, 0xff, 0x11, 0x0, 0xff, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x0,
3725 0x0, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0xee, 0x88, 0x0, 0x0, 0x0, 0x11, 0x33, 0x33, 0x77, 0x77,
3726 0x0, 0x11, 0xff, 0xcf, 0x8f, 0x8f, 0xcf, 0xff, 0x0, 0xff, 0xff, 0x7f, 0xf3, 0xf3, 0x7f, 0xff,
3727 0x88, 0xee, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0x0, 0x77, 0x77, 0x33, 0x33, 0x11, 0x0, 0x0, 0x0,
3728 0xff, 0xcf, 0x8f, 0x8f, 0xcf, 0xff, 0x11, 0x0, 0xff, 0x7f, 0xf3, 0xf3, 0x7f, 0xff, 0xff, 0x0,
3729 0x0, 0xcc, 0xee, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0x0, 0x0, 0x0, 0x11, 0x33, 0x33, 0x77, 0x77,
3730 0x0, 0x11, 0xff, 0xcf, 0x8f, 0x8f, 0xcf, 0xff, 0x0, 0xff, 0xff, 0x7f, 0xf3, 0xf3, 0x7f, 0xff,
3731 0xee, 0xcc, 0x88, 0xcc, 0xee, 0xee, 0xcc, 0x0, 0x77, 0x77, 0x33, 0x33, 0x11, 0x0, 0x0, 0x0,
3732 0xff, 0xcf, 0x8f, 0x8f, 0xcf, 0xff, 0x11, 0x0, 0xff, 0x7f, 0xf3, 0xf3, 0x7f, 0xff, 0xff, 0x0,
3733 0x0, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0xee, 0x88, 0x0, 0x0, 0x0, 0x11, 0x33, 0x33, 0x77, 0x77,
3734 0x0, 0x11, 0xff, 0xff, 0x8f, 0xf, 0x3c, 0xbc, 0x0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0xff,
3735 0x88, 0xee, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0x0, 0x77, 0x77, 0x33, 0x33, 0x11, 0x0, 0x0, 0x0,
3736 0xff, 0xff, 0x8f, 0xf, 0x3c, 0xbc, 0x11, 0x0, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0xff, 0xff, 0x0,
3737 0x0, 0xcc, 0xee, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0x0, 0x0, 0x0, 0x11, 0x33, 0x33, 0x77, 0x77,
3738 0x0, 0x11, 0xff, 0xff, 0x8f, 0xf, 0x3c, 0xbc, 0x0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0xff,
3739 0xee, 0xcc, 0x88, 0xcc, 0xee, 0xee, 0xcc, 0x0, 0x77, 0x77, 0x33, 0x33, 0x11, 0x0, 0x0, 0x0,
3740 0xff, 0xff, 0x8f, 0xf, 0x3c, 0xbc, 0x11, 0x0, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0xff, 0xff, 0x0,
3741 0x0, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0xee, 0x88, 0x0, 0x0, 0x0, 0x1, 0x30, 0x30, 0x67, 0x77,
3742 0x0, 0x11, 0xff, 0x3f, 0x1f, 0x1f, 0x3f, 0xff, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3743 0x88, 0xee, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0x0, 0x77, 0x67, 0x30, 0x30, 0x1, 0x0, 0x0, 0x0,
3744 0xff, 0x3f, 0x1f, 0x1f, 0x3f, 0xff, 0x11, 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xcc, 0x0,
3769 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x11, 0x33, 0x33, 0x77, 0x77,
3770 0x0, 0x0, 0x77, 0xff, 0xff, 0xff, 0xee, 0xcc, 0x0, 0x0, 0xcc, 0xcc, 0x88, 0x0, 0x0, 0x0,
3771 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x77, 0x77, 0x77, 0x33, 0x33, 0x11, 0x0, 0x0,
3772 0x88, 0xcc, 0xee, 0xff, 0xff, 0xff, 0x77, 0x0, 0x0, 0x0, 0x0, 0x0, 0x88, 0xcc, 0xcc, 0x0,
3773 0x0, 0x0, 0x0, 0x0, 0x88, 0x88, 0xcc, 0xcc, 0x0, 0x0, 0x0, 0x11, 0x33, 0x33, 0x77, 0x77,
3774 0x0, 0x0, 0x0, 0x88, 0x88, 0xcc, 0xcc, 0xcc, 0x0, 0x0, 0x0, 0x33, 0x33, 0x77, 0x77, 0x77,
3775 0xcc, 0xcc, 0xcc, 0x88, 0x88, 0x0, 0x0, 0x0, 0x77, 0x77, 0x77, 0x33, 0x33, 0x11, 0x0, 0x0,
3776 0xee, 0xee, 0xee, 0xff, 0xff, 0xff, 0x77, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0x0,
3777 0x0, 0x0, 0x0, 0x0, 0x88, 0x88, 0x0, 0x0, 0x0, 0x0, 0x0, 0x11, 0x33, 0x33, 0x77, 0x77,
3778 0x0, 0x0, 0x77, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0xcc, 0xff, 0xff, 0xff, 0xee, 0x0,
3779 0x0, 0x0, 0x0, 0x88, 0x88, 0x0, 0x0, 0x0, 0x77, 0x77, 0x77, 0x33, 0x33, 0x11, 0x0, 0x0,
3780 0xcc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x0, 0x0, 0x0, 0xee, 0xff, 0xff, 0xff, 0xcc, 0x0,
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, 0x0,
3793 0x0, 0x60, 0x60, 0xe0, 0xe0, 0xe8, 0xcc, 0x88, 0x0, 0x0, 0x0, 0x11, 0x23, 0x23, 0x77, 0x77,
3794 0x0, 0x11, 0xff, 0x1d, 0xc, 0xf, 0x1f, 0xff, 0x0, 0x0, 0xf0, 0xf8, 0xfd, 0xff, 0xff, 0xff,
3795 0x88, 0xee, 0xee, 0xcc, 0x88, 0xcc, 0xee, 0x0, 0x77, 0x77, 0x23, 0x23, 0x11, 0x0, 0x0, 0x0,
3796 0xff, 0x1d, 0xc, 0xf, 0x1f, 0xff, 0x11, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0,
3797 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x11, 0x11, 0x0, 0x0, 0x0, 0x0,
3798 0x0, 0x0, 0xff, 0xff, 0xff, 0x77, 0x33, 0x11, 0x0, 0x0, 0x0, 0xcc, 0xee, 0xee, 0xff, 0xff,
3799 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x11, 0x11, 0x0,
3800 0x0, 0x11, 0x33, 0x77, 0xff, 0xff, 0xff, 0x0, 0xff, 0xff, 0xff, 0xee, 0xee, 0xcc, 0x0, 0x0,
3801 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
3802 0x0, 0x77, 0xff, 0x77, 0x77, 0x33, 0x11, 0x11, 0x0, 0x0, 0xcc, 0xee, 0xee, 0xff, 0xff, 0xff,
3803 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
3804 0x0, 0x11, 0x11, 0x33, 0x77, 0x77, 0xff, 0x77, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee, 0xcc, 0x0,
3805 0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0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
3888 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
3889 };
3890
3891 /*== SOUND EFFECT REGISTER DUMPS =============================================*/
3892
3893 /*
3894 Each line is a 'register dump' for one 60Hz tick. Each 32-bit number
3895 encodes the per-voice values for frequency, waveform and volume:
3896
3897 31 0 bit
3898 |vvvv-www----ffffffffffffffffffff|
3899 | | |
3900 | | +-- 20 bits frequency
3901 | +-- 3 bits waveform
3902 +-- 4 bits volume
3903 */
3904 static const uint32_t snd_dump_prelude[490] = {
3905 0xE20002E0, 0xF0001700,
3906 0xD20002E0, 0xF0001700,
3907 0xC20002E0, 0xF0001700,
3908 0xB20002E0, 0xF0001700,
3909 0xA20002E0, 0xF0000000,
3910 0x920002E0, 0xF0000000,
3911 0x820002E0, 0xF0000000,
3912 0x720002E0, 0xF0000000,
3913 0x620002E0, 0xF0002E00,
3914 0x520002E0, 0xF0002E00,
3915 0x420002E0, 0xF0002E00,
3916 0x320002E0, 0xF0002E00,
3917 0x220002E0, 0xF0000000,
3918 0x120002E0, 0xF0000000,
3919 0x020002E0, 0xF0000000,
3920 0xE2000000, 0xF0002280,
3921 0xD2000000, 0xF0002280,
3922 0xC2000000, 0xF0002280,
3923 0xB2000000, 0xF0002280,
3924 0xA2000000, 0xF0000000,
3925 0x92000000, 0xF0000000,
3926 0x82000000, 0xF0000000,
3927 0x72000000, 0xF0000000,
3928 0xE2000450, 0xF0001D00,
3929 0xD2000450, 0xF0001D00,
3930 0xC2000450, 0xF0001D00,
3931 0xB2000450, 0xF0001D00,
3932 0xA2000450, 0xF0000000,
3933 0x92000450, 0xF0000000,
3934 0x82000450, 0xF0000000,
3935 0x72000450, 0xF0000000,
3936 0xE20002E0, 0xF0002E00,
3937 0xD20002E0, 0xF0002E00,
3938 0xC20002E0, 0xF0002E00,
3939 0xB20002E0, 0xF0002E00,
3940 0xA20002E0, 0xF0002280,
3941 0x920002E0, 0xF0002280,
3942 0x820002E0, 0xF0002280,
3943 0x720002E0, 0xF0002280,
3944 0x620002E0, 0xF0000000,
3945 0x520002E0, 0xF0000000,
3946 0x420002E0, 0xF0000000,
3947 0x320002E0, 0xF0000000,
3948 0x220002E0, 0xF0000000,
3949 0x120002E0, 0xF0000000,
3950 0x020002E0, 0xF0000000,
3951 0xE2000000, 0xF0001D00,
3952 0xD2000000, 0xF0001D00,
3953 0xC2000000, 0xF0001D00,
3954 0xB2000000, 0xF0001D00,
3955 0xA2000000, 0xF0001D00,
3956 0x92000000, 0xF0001D00,
3957 0x82000000, 0xF0001D00,
3958 0x72000000, 0xF0001D00,
3959 0xE2000450, 0xF0000000,
3960 0xD2000450, 0xF0000000,
3961 0xC2000450, 0xF0000000,
3962 0xB2000450, 0xF0000000,
3963 0xA2000450, 0xF0000000,
3964 0x92000450, 0xF0000000,
3965 0x82000450, 0xF0000000,
3966 0x72000450, 0xF0000000,
3967 0xE2000308, 0xF0001840,
3968 0xD2000308, 0xF0001840,
3969 0xC2000308, 0xF0001840,
3970 0xB2000308, 0xF0001840,
3971 0xA2000308, 0xF0000000,
3972 0x92000308, 0xF0000000,
3973 0x82000308, 0xF0000000,
3974 0x72000308, 0xF0000000,
3975 0x62000308, 0xF00030C0,
3976 0x52000308, 0xF00030C0,
3977 0x42000308, 0xF00030C0,
3978 0x32000308, 0xF00030C0,
3979 0x22000308, 0xF0000000,
3980 0x12000308, 0xF0000000,
3981 0x02000308, 0xF0000000,
3982 0xE2000000, 0xF0002480,
3983 0xD2000000, 0xF0002480,
3984 0xC2000000, 0xF0002480,
3985 0xB2000000, 0xF0002480,
3986 0xA2000000, 0xF0000000,
3987 0x92000000, 0xF0000000,
3988 0x82000000, 0xF0000000,
3989 0x72000000, 0xF0000000,
3990 0xE2000490, 0xF0001EC0,
3991 0xD2000490, 0xF0001EC0,
3992 0xC2000490, 0xF0001EC0,
3993 0xB2000490, 0xF0001EC0,
3994 0xA2000490, 0xF0000000,
3995 0x92000490, 0xF0000000,
3996 0x82000490, 0xF0000000,
3997 0x72000490, 0xF0000000,
3998 0xE2000308, 0xF00030C0,
3999 0xD2000308, 0xF00030C0,
4000 0xC2000308, 0xF00030C0,
4001 0xB2000308, 0xF00030C0,
4002 0xA2000308, 0xF0002480,
4003 0x92000308, 0xF0002480,
4004 0x82000308, 0xF0002480,
4005 0x72000308, 0xF0002480,
4006 0x62000308, 0xF0000000,
4007 0x52000308, 0xF0000000,
4008 0x42000308, 0xF0000000,
4009 0x32000308, 0xF0000000,
4010 0x22000308, 0xF0000000,
4011 0x12000308, 0xF0000000,
4012 0x02000308, 0xF0000000,
4013 0xE2000000, 0xF0001EC0,
4014 0xD2000000, 0xF0001EC0,
4015 0xC2000000, 0xF0001EC0,
4016 0xB2000000, 0xF0001EC0,
4017 0xA2000000, 0xF0001EC0,
4018 0x92000000, 0xF0001EC0,
4019 0x82000000, 0xF0001EC0,
4020 0x72000000, 0xF0001EC0,
4021 0xE2000490, 0xF0000000,
4022 0xD2000490, 0xF0000000,
4023 0xC2000490, 0xF0000000,
4024 0xB2000490, 0xF0000000,
4025 0xA2000490, 0xF0000000,
4026 0x92000490, 0xF0000000,
4027 0x82000490, 0xF0000000,
4028 0x72000490, 0xF0000000,
4029 0xE20002E0, 0xF0001700,
4030 0xD20002E0, 0xF0001700,
4031 0xC20002E0, 0xF0001700,
4032 0xB20002E0, 0xF0001700,
4033 0xA20002E0, 0xF0000000,
4034 0x920002E0, 0xF0000000,
4035 0x820002E0, 0xF0000000,
4036 0x720002E0, 0xF0000000,
4037 0x620002E0, 0xF0002E00,
4038 0x520002E0, 0xF0002E00,
4039 0x420002E0, 0xF0002E00,
4040 0x320002E0, 0xF0002E00,
4041 0x220002E0, 0xF0000000,
4042 0x120002E0, 0xF0000000,
4043 0x020002E0, 0xF0000000,
4044 0xE2000000, 0xF0002280,
4045 0xD2000000, 0xF0002280,
4046 0xC2000000, 0xF0002280,
4047 0xB2000000, 0xF0002280,
4048 0xA2000000, 0xF0000000,
4049 0x92000000, 0xF0000000,
4050 0x82000000, 0xF0000000,
4051 0x72000000, 0xF0000000,
4052 0xE2000450, 0xF0001D00,
4053 0xD2000450, 0xF0001D00,
4054 0xC2000450, 0xF0001D00,
4055 0xB2000450, 0xF0001D00,
4056 0xA2000450, 0xF0000000,
4057 0x92000450, 0xF0000000,
4058 0x82000450, 0xF0000000,
4059 0x72000450, 0xF0000000,
4060 0xE20002E0, 0xF0002E00,
4061 0xD20002E0, 0xF0002E00,
4062 0xC20002E0, 0xF0002E00,
4063 0xB20002E0, 0xF0002E00,
4064 0xA20002E0, 0xF0002280,
4065 0x920002E0, 0xF0002280,
4066 0x820002E0, 0xF0002280,
4067 0x720002E0, 0xF0002280,
4068 0x620002E0, 0xF0000000,
4069 0x520002E0, 0xF0000000,
4070 0x420002E0, 0xF0000000,
4071 0x320002E0, 0xF0000000,
4072 0x220002E0, 0xF0000000,
4073 0x120002E0, 0xF0000000,
4074 0x020002E0, 0xF0000000,
4075 0xE2000000, 0xF0001D00,
4076 0xD2000000, 0xF0001D00,
4077 0xC2000000, 0xF0001D00,
4078 0xB2000000, 0xF0001D00,
4079 0xA2000000, 0xF0001D00,
4080 0x92000000, 0xF0001D00,
4081 0x82000000, 0xF0001D00,
4082 0x72000000, 0xF0001D00,
4083 0xE2000450, 0xF0000000,
4084 0xD2000450, 0xF0000000,
4085 0xC2000450, 0xF0000000,
4086 0xB2000450, 0xF0000000,
4087 0xA2000450, 0xF0000000,
4088 0x92000450, 0xF0000000,
4089 0x82000450, 0xF0000000,
4090 0x72000450, 0xF0000000,
4091 0xE2000450, 0xF0001B40,
4092 0xD2000450, 0xF0001B40,
4093 0xC2000450, 0xF0001B40,
4094 0xB2000450, 0xF0001B40,
4095 0xA2000450, 0xF0001D00,
4096 0x92000450, 0xF0001D00,
4097 0x82000450, 0xF0001D00,
4098 0x72000450, 0xF0001D00,
4099 0x62000450, 0xF0001EC0,
4100 0x52000450, 0xF0001EC0,
4101 0x42000450, 0xF0001EC0,
4102 0x32000450, 0xF0001EC0,
4103 0x22000450, 0xF0000000,
4104 0x12000450, 0xF0000000,
4105 0x02000450, 0xF0000000,
4106 0xE20004D0, 0xF0001EC0,
4107 0xD20004D0, 0xF0001EC0,
4108 0xC20004D0, 0xF0001EC0,
4109 0xB20004D0, 0xF0001EC0,
4110 0xA20004D0, 0xF0002080,
4111 0x920004D0, 0xF0002080,
4112 0x820004D0, 0xF0002080,
4113 0x720004D0, 0xF0002080,
4114 0x620004D0, 0xF0002280,
4115 0x520004D0, 0xF0002280,
4116 0x420004D0, 0xF0002280,
4117 0x320004D0, 0xF0002280,
4118 0x220004D0, 0xF0000000,
4119 0x120004D0, 0xF0000000,
4120 0x020004D0, 0xF0000000,
4121 0xE2000568, 0xF0002280,
4122 0xD2000568, 0xF0002280,
4123 0xC2000568, 0xF0002280,
4124 0xB2000568, 0xF0002280,
4125 0xA2000568, 0xF0002480,
4126 0x92000568, 0xF0002480,
4127 0x82000568, 0xF0002480,
4128 0x72000568, 0xF0002480,
4129 0x62000568, 0xF0002680,
4130 0x52000568, 0xF0002680,
4131 0x42000568, 0xF0002680,
4132 0x32000568, 0xF0002680,
4133 0x22000568, 0xF0000000,
4134 0x12000568, 0xF0000000,
4135 0x02000568, 0xF0000000,
4136 0xE20005C0, 0xF0002E00,
4137 0xD20005C0, 0xF0002E00,
4138 0xC20005C0, 0xF0002E00,
4139 0xB20005C0, 0xF0002E00,
4140 0xA20005C0, 0xF0002E00,
4141 0x920005C0, 0xF0002E00,
4142 0x820005C0, 0xF0002E00,
4143 0x720005C0, 0xF0002E00,
4144 0x620005C0, 0x00000E80,
4145 0x520005C0, 0x00000E80,
4146 0x420005C0, 0x00000E80,
4147 0x320005C0, 0x00000E80,
4148 0x220005C0, 0x00000E80,
4149 0x120005C0, 0x00000E80,
4150 };
4151
4152 static const uint32_t snd_dump_dead[90] = {
4153 0xF1001F00,
4154 0xF1001E00,
4155 0xF1001D00,
4156 0xF1001C00,
4157 0xF1001B00,
4158 0xF1001C00,
4159 0xF1001D00,
4160 0xF1001E00,
4161 0xF1001F00,
4162 0xF1002000,
4163 0xF1002100,
4164 0xE1001D00,
4165 0xE1001C00,
4166 0xE1001B00,
4167 0xE1001A00,
4168 0xE1001900,
4169 0xE1001800,
4170 0xE1001900,
4171 0xE1001A00,
4172 0xE1001B00,
4173 0xE1001C00,
4174 0xE1001D00,
4175 0xE1001E00,
4176 0xD1001B00,
4177 0xD1001A00,
4178 0xD1001900,
4179 0xD1001800,
4180 0xD1001700,
4181 0xD1001600,
4182 0xD1001700,
4183 0xD1001800,
4184 0xD1001900,
4185 0xD1001A00,
4186 0xD1001B00,
4187 0xD1001C00,
4188 0xC1001900,
4189 0xC1001800,
4190 0xC1001700,
4191 0xC1001600,
4192 0xC1001500,
4193 0xC1001400,
4194 0xC1001500,
4195 0xC1001600,
4196 0xC1001700,
4197 0xC1001800,
4198 0xC1001900,
4199 0xC1001A00,
4200 0xB1001700,
4201 0xB1001600,
4202 0xB1001500,
4203 0xB1001400,
4204 0xB1001300,
4205 0xB1001200,
4206 0xB1001300,
4207 0xB1001400,
4208 0xB1001500,
4209 0xB1001600,
4210 0xB1001700,
4211 0xB1001800,
4212 0xA1001500,
4213 0xA1001400,
4214 0xA1001300,
4215 0xA1001200,
4216 0xA1001100,
4217 0xA1001000,
4218 0xA1001100,
4219 0xA1001200,
4220 0x80000800,
4221 0x80001000,
4222 0x80001800,
4223 0x80002000,
4224 0x80002800,
4225 0x80003000,
4226 0x80003800,
4227 0x80004000,
4228 0x80004800,
4229 0x80005000,
4230 0x80005800,
4231 0x00000000,
4232 0x80000800,
4233 0x80001000,
4234 0x80001800,
4235 0x80002000,
4236 0x80002800,
4237 0x80003000,
4238 0x80003800,
4239 0x80004000,
4240 0x80004800,
4241 0x80005000,
4242 0x80005800,
4243 };