limit tickrate to half refresh rate
[d2d-md.git] / src / main.c
blob93bd4d0642766678bee0beee95307561bb076697
1 #include <genesis.h>
3 #include "spr.h"
4 #include "tiles.h"
5 #include "audio.h"
6 #include "map.h"
7 #include "thing.h"
8 #include "player.h"
9 #include "maps.h"
11 u16 g_ticker = 0;
13 static map_t maps[] = {
14 DEFINE_MAP(0, 9, 63, map_map01),
17 static void do_input(void) {
18 u16 value1 = JOY_readJoypad(JOY_1);
19 u16 value2 = JOY_readJoypad(JOY_2);
20 plr_controls(th_player[0], value1);
21 plr_controls(th_player[1], value2);
24 static inline void update_scroll(void) {
25 for (u16 i = 0; i < num_players; ++i) {
26 VDP_setHorizontalScroll(g_cam[i].planeidx, -g_cam[i].x);
27 VDP_setVerticalScroll(g_cam[i].planeidx, g_cam[i].y);
31 #pragma GCC diagnostic ignored "-Wmain"
33 int main(u16 hard_reset) {
34 if (!hard_reset)
35 SYS_hardReset();
37 SYS_disableInts();
39 VDP_setScreenWidth320();
40 VDP_setPaletteColors(0, (u16*)palette_black, 64);
42 num_players = 2;
44 spr_startup();
45 tiles_startup();
46 snd_startup();
47 map_startup();
49 map_load(maps + 0);
51 th_player[0] = thing_spawn(TH_PLAYER, 40, 480, -1, &g_things[0]);
52 th_player[1] = thing_spawn(TH_PLAYER, 40, 480, -1, &g_things[0]);
54 g_cam[0].flags = g_cam[1].flags = 1;
56 SPR_update();
57 update_scroll();
58 map_update();
59 DMA_waitCompletion();
61 SYS_enableInts();
63 snd_play_music(0);
65 while (1) {
66 do_input();
68 if (g_ticker & 1) {
69 things_think();
70 things_remove();
71 map_update();
72 things_draw();
73 SPR_update();
76 ++g_ticker;
77 SYS_doVBlankProcess();
78 update_scroll();
81 return 0;