1 /***************************************************************************
2     OutRun Engine Entry Point.
3 
4     This is the hub of the ported OutRun code.
5 
6     Copyright Chris White.
7     See license.txt for more details.
8 ***************************************************************************/
9 
10 #pragma once
11 
12 #include "stdint.hpp"
13 #include "roms.hpp"
14 #include "globals.hpp"
15 
16 #include "video.hpp"
17 
18 #include "frontend/config.hpp"
19 
20 // Main include for Ported OutRun Code
21 #include "oaddresses.hpp"
22 #include "osprites.hpp"
23 #include "oroad.hpp"
24 #include "oinitengine.hpp"
25 #include "audio/osoundint.hpp"
26 
27 // Globals
28 enum
29 {
30 	GS_INIT = 0,				// Initalize Game
31 	GS_ATTRACT = 1,				// Attract Mode
32 	GS_INIT_BEST1 = 2,			// Load Best Outrunners
33 	GS_BEST1 = 3,				// Best Outrunners (Attract Mode)
34 	GS_INIT_LOGO = 4,			// Load Outrun Logo
35 	GS_LOGO = 5,				// Outrun Logo (Attract Mode)
36 	GS_INIT_MUSIC = 6,			// Load Music Selection Screen
37 	GS_MUSIC = 7,				// Music Selection Screen
38 	GS_INIT_GAME = 8,			// Loading In-Game
39 	GS_START1 = 9,				// Start Game, Car Driving In
40 	GS_START2 = 10,				// Start Game, Countdown
41 	GS_START3 = 11,				// Start Game, Countdown 2
42 	GS_INGAME = 12,				// Start Game, User in control
43 	GS_INIT_BONUS = 13,			// Load Bonus Points
44 	GS_BONUS = 14,				// Display Bonus Points
45 	GS_INIT_GAMEOVER = 15,	    // Load Game Over
46 	GS_GAMEOVER = 16,           // Game Over Text
47 	GS_INIT_MAP = 17,			// Load Course Map
48 	GS_MAP = 18,				// Course Map
49 	GS_INIT_BEST2 = 19,			// Load Best Outrunners
50 	GS_BEST2 = 20,			    // Best Outrunners
51 	GS_REINIT = 21,				// Reinitalize Game (after outrunners screen)
52     GS_CALIBRATE_MOTOR = 100,   // Calibrate Motors
53 };
54 
55 struct time_trial_t
56 {
57     bool enabled;             // Time Trial Mode Enabled
58     uint8_t  level;           // Time Trial Level
59     uint8_t  traffic;         // Max Traffic Level
60     uint8_t  laps;            // Total laps (maximum of 5 laps total allowed)
61     uint8_t  current_lap;     // Which lap are we currently on
62     uint16_t overtakes;       // Number of overtakes
63     uint16_t vehicle_cols;    // Number of vehicle collisions
64     uint16_t crashes;         // Number of crashes
65     uint8_t  laptimes[5][3];  // Stored lap times
66     int16_t  best_lap_counter;// Counter representing best laptime
67     uint8_t  best_lap[3];     // Stored best lap time
68     bool new_high_score;      // Has player achieved a new high score?
69 };
70 
71 // Addresses (Used to swap between original and Japanese roms)
72 struct adr_t
73 {
74     // CPU 0
75     uint32_t tiles_def_lookup;
76     uint32_t tiles_table;
77 
78     uint32_t sprite_master_table;
79     uint32_t sprite_type_table;
80     uint32_t sprite_def_props1;
81     uint32_t sprite_def_props2;
82     uint32_t sprite_cloud;
83     uint32_t sprite_minitree;
84     uint32_t sprite_grass;
85     uint32_t sprite_sand;
86     uint32_t sprite_stone;
87     uint32_t sprite_water;
88     uint32_t sprite_ferrari_frames;
89     uint32_t sprite_skid_frames;
90     uint32_t sprite_pass_frames;
91     uint32_t sprite_pass1_skidl;
92     uint32_t sprite_pass1_skidr;
93     uint32_t sprite_pass2_skidl;
94     uint32_t sprite_pass2_skidr;
95     uint32_t sprite_crash_spin1;
96     uint32_t sprite_crash_spin2;
97     uint32_t sprite_bump_data1;
98     uint32_t sprite_bump_data2;
99     uint32_t sprite_crash_man1;
100     uint32_t sprite_crash_girl1;
101     uint32_t sprite_crash_flip;
102     uint32_t sprite_crash_flip_m1;
103     uint32_t sprite_crash_flip_g1;
104     uint32_t sprite_crash_flip_m2;
105     uint32_t sprite_crash_flip_g2;
106     uint32_t sprite_crash_man2;
107     uint32_t sprite_crash_girl2;
108     uint32_t smoke_data;
109     uint32_t spray_data;
110     uint32_t shadow_data;
111     uint32_t shadow_frames;
112     uint32_t sprite_shadow_small;
113 
114     uint32_t sprite_logo_bg;
115     uint32_t sprite_logo_car;
116     uint32_t sprite_logo_bird1;
117     uint32_t sprite_logo_bird2;
118     uint32_t sprite_logo_base;
119     uint32_t sprite_logo_text;
120     uint32_t sprite_logo_palm1;
121     uint32_t sprite_logo_palm2;
122     uint32_t sprite_logo_palm3;
123 
124     uint32_t sprite_fm_left;
125     uint32_t sprite_fm_centre;
126     uint32_t sprite_fm_right;
127     uint32_t sprite_dial_left;
128     uint32_t sprite_dial_centre;
129     uint32_t sprite_dial_right;
130     uint32_t sprite_eq;
131     uint32_t sprite_radio;
132     uint32_t sprite_hand_left;
133     uint32_t sprite_hand_centre;
134     uint32_t sprite_hand_right;
135 
136     uint32_t sprite_coursemap_top;
137     uint32_t sprite_coursemap_bot;
138     uint32_t sprite_coursemap_end;
139     uint32_t sprite_minicar_right;
140     uint32_t sprite_minicar_up;
141     uint32_t sprite_minicar_down;
142 
143     uint32_t anim_seq_flag;
144     uint32_t anim_ferrari_curr;
145     uint32_t anim_ferrari_next;
146     uint32_t anim_pass1_curr;
147     uint32_t anim_pass1_next;
148     uint32_t anim_pass2_curr;
149     uint32_t anim_pass2_next;
150 
151     uint32_t anim_ferrari_frames;
152     uint32_t anim_endseq_obj1;
153     uint32_t anim_endseq_obj2;
154     uint32_t anim_endseq_obj3;
155     uint32_t anim_endseq_obj4;
156     uint32_t anim_endseq_obj5;
157     uint32_t anim_endseq_obj6;
158     uint32_t anim_endseq_obj7;
159     uint32_t anim_endseq_obj8;
160     uint32_t anim_endseq_objA;
161     uint32_t anim_endseq_objB;
162     uint32_t anim_end_table;
163 
164     uint32_t traffic_props;
165     uint32_t traffic_data;
166     uint32_t sprite_porsche;
167 
168     uint32_t sprite_coursemap;
169     uint32_t road_seg_table;
170     uint32_t road_seg_end;
171     uint32_t road_seg_split;
172 
173     // CPU 1
174     uint32_t road_height_lookup;
175 };
176 
177 class OOutputs;
178 
179 class Outrun
180 {
181 public:
182     OOutputs* outputs;
183 
184     bool freeze_timer;
185 
186     // CannonBall Game Mode
187     uint8_t cannonball_mode;
188 
189     const static uint8_t MODE_ORIGINAL = 0; // Original OutRun Mode
190     const static uint8_t MODE_TTRIAL   = 1; // Enhanced Time Trial Mode
191     const static uint8_t MODE_CONT     = 2; // Enhanced Continuous Mode
192 
193     // Max traffic level for custom modes
194     uint8_t custom_traffic;
195 
196     // Time trial data
197     time_trial_t ttrial;
198 
199     // Service Mode Toggle: Not implemented yet.
200     bool service_mode;
201 
202     // Tick Logic. Used when running at non-standard > 30 fps
203     bool tick_frame;
204 
205     // Tick Counter (always syncd to 30 fps to flash text and other stuff)
206     uint32_t tick_counter;
207 
208     // Main game state
209     int8_t game_state;
210 
211     // Address structures
212     adr_t adr;
213 
214 	Outrun();
215 	~Outrun();
216 	void init();
217     void boot();
218 	void tick(bool tick_frame);
219 	void vint();
220     void init_best_outrunners();
221     void select_course(const bool jap, const bool prototype);
222 
223 private:
224 
225     uint8_t attract_view;
226     int16_t attract_counter;
227 
228     // Car Increment Backup for attract mode
229     uint32_t car_inc_bak;
230 
231     // Debug to denote when fork has been chosen
232     int8_t fork_chosen;
233 
234 	void jump_table();
235 	void init_jump_table();
236 	void main_switch();
237     void controls();
238     bool decrement_timers();
239     void init_motor_calibration();
240     void init_attract();
241     void tick_attract();
242     void check_freeplay_start();
243 };
244 
245 extern Outrun outrun;
246