/
main.c
79 lines (67 loc) · 1.38 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright 2014 ammianus
*/
#include <stdlib.h>
#include <math.h>
#include "types.h"
#include "32x.h"
#include "hw_32x.h"
#include "32x_images.h"
#include "game_constants.h"
#include "graphics.h"
#include "shared_objects.h"
#include "aplib_decrunch.h"
extern const char title;
extern vu16 ex;
extern char pal[], pal_end[];
unsigned short curr_buttons;
static void Flip_screen()
{
MARS_VDP_FBCTL = currentFB ^ 1;
while ((MARS_VDP_FBCTL & MARS_VDP_FS) == currentFB) ;
currentFB ^= 1;
}
/*
* Check the current SEGA Controllers for inputs, update player, direction
* , speed, and action accordingly.
*/
void handle_input()
{
curr_buttons = MARS_SYS_COMM8;
if ((curr_buttons & SEGA_CTRL_TYPE) == SEGA_CTRL_NONE)
{
curr_buttons = MARS_SYS_COMM10; // if no pad 1, try using pad 2
}
}
/*
* Starts application
*/
int main(void)
{
short x = 0, y = 0;
int i;
// Wait for the SH2 to gain access to the VDP
Hw32xInit(MARS_VDP_MODE_256, 0);
loadPalette(pal, pal_end, 0);
x = 0;
y = 0;
//game loop
while (1)
{
Flip_screen();
drawRawBackground(&title);
drawSprite(&ex, x, y, 96, 96);
if (curr_buttons & SEGA_CTRL_UP)
y-=1;
else if (curr_buttons & SEGA_CTRL_DOWN)
y+=1;
if (curr_buttons & SEGA_CTRL_LEFT)
x-=1;
else if (curr_buttons & SEGA_CTRL_RIGHT)
x+=1;
handle_input();
Update_Video();
}
HwMdClearScreen ();
return 0;
} // end of main function