This repository has been archived by the owner on Jan 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·207 lines (164 loc) · 5.14 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// The Main HAM Library
#include <mygba.h>
// The HEL Library
#include <hel2.h>
// Various includes
#include "header.h"
// Function: main() ======================================================================
int main()
{
// Variables
map_fragment_info_ptr bg_background;
// Initialize HAMlib
ham_Init();
// Set system prefetch
//hel_SysSetPrefetch(TRUE);
// Initialize Splash-Screen System
hel_SplashInit((void*)g_SplashScreenSystemBuffer);
// Enter bg mode 4 for the splash screen
ham_SetBgMode(4);
// Splashscreen 1
hel_Splash
(
(u16*)ResData(RES_SPLASHSCREEN_RAW), // pBitmap
(u16*)ResData(RES_SPLASHSCREEN_PAL), // pPalette
RGB(0,0,0), // InBlendColor
RGB(0,0,0), // OutBlendColor
60, // BlendDelay
2000, // DisplayDelay
500, // ContinueDelay
COMPRESSION_TYPE_NONE, // CompressionType,
0 // Flags
);
// Quit the splashscreen
hel_SplashQuit();
// Setup the background mode
ham_SetBgMode(1);
// Initialize the text display system
ham_InitText(0);
// Initialize the palettes
ham_LoadBGPal((void*)background_Palette, 256);
ham_LoadObjPal((void*)object_Palette, 256);
// Set the Text Color
ham_SetTextCol(195, 40);
// Setup the tileset for our image
ham_bg[1].ti = ham_InitTileSet((void*)background_Tiles, SIZEOF_16BIT(background_Tiles), 1, 1);
// Setup the map for our image
ham_bg[1].mi = ham_InitMapEmptySet(3,0);
bg_background = ham_InitMapFragment((void*)background_Map, 60, 20, 0, 0, 60, 20, 0);
// Copy (the whole) map to BG0 at x=0, y=0
ham_InsertMapFragment(bg_background, 1, 0, 0);
// Display the background
ham_InitBg(1, 1, 2, 1);
// Setup the array spot
array_spot = (32768 * dir_dk) + (4096 * animcnt);
// setup the initial state of the frame bits counter
frameCounter = 0;
// Setup the dk
dk = ham_CreateObj(
(void *)&dk_Bitmap[array_spot],
0,3,OBJ_MODE_NORMAL,1,0,0,0,0,0,0,dk_x,dk_y);
// Start the VBL interrupt handler
ham_StartIntHandler(INT_TYPE_VBL, (void*)&vbl_func);
while (1)
{
if (newframe)
{
// Write some stuff to the screen
ham_DrawText(1, 1, "480x160 background");
ham_DrawText(1, 2, "Arrows to scroll left-right");
ham_DrawText(1, 17, "scroll-x: %5d", map_x);
ham_DrawText(1, 18, "frame: %5d", frameCounter);
// Let the user move the map around
if (F_CTRLINPUT_RIGHT_PRESSED)
{
if (map_x < (480 - 240))
ham_SetBgXY(1, ++map_x, 0);
}
if (F_CTRLINPUT_LEFT_PRESSED)
{
if (map_x > 0)
ham_SetBgXY(1, --map_x, 0);
}
newframe = 0; // No longer a new frame
} // End of if(newframe)
} // End of while(1)
return 0;
} // End of main()
//********************** =================================================================
// Function: vbl_func()
// Purpose: VBL function
//**********************
// VBL function
void vbl_func()
{
// update background
newframe = 1;
// Copy dk sprite to hardware
ham_CopyObjToOAM();
// Process the following every VBL
query_buttons(); // Query for user input
update_dk_gfx(); // Apply dk's new graphic
update_dk_pos(); // Apply dk's new position
++frames; // Increment the frame counter
frameCounter += 4096; // increment frame bits counter
return;
} // End of vbl_func()
//****************************** =========================================================
// Function: query_buttons()
// Purpose: Query for user input
//******************************
void query_buttons()
{
// RIGHT only
if (F_CTRLINPUT_RIGHT_PRESSED)
{
if (dk_x < 176)
++dk_x;
dir_dk = ANIM_RIGHT;
return;
}
// LEFT only
if (F_CTRLINPUT_LEFT_PRESSED)
{
if (dk_x > 0)
--dk_x;
dir_dk = ANIM_LEFT;
return;
}
return;
} // End of query_buttons()
//*********************************** ====================================================
// Function: update_dk_gfx()
// Purpose: Apply dk's new graphic
//***********************************
void update_dk_gfx()
{
// We'll only update the animation every 7th frame
if (frames > 9) {
// Reset the frame counter
frames = 0;
// reset the frame bits counter
frameCounter = 0;
// Figure out where to load the image from
array_spot = (32768 * dir_dk) + (4096 * animcnt);
// Update it
ham_UpdateObjGfx(dk, (void*)&dk_Bitmap[array_spot]);
// Increment the animation counter
if (animcnt == 7)
animcnt = 0;
else
animcnt++;
}
return;
} // End of update_dk_gfx()
//************************************ ===================================================
// Function: update_dk_pos()
// Purpose: Apply dk's new position
//************************************
void update_dk_pos()
{
ham_SetObjX(dk, dk_x);
ham_SetObjY(dk, dk_y);
return;
} // End of update_dk_pos()