-
Notifications
You must be signed in to change notification settings - Fork 0
/
myFunc.c
171 lines (140 loc) · 2.61 KB
/
myFunc.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
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
#include "myFunc.h"
#include <AgbMemoryMap.h>
#include <AgbSystemCall.h>
#include "data.h"
// define data----------------------------------
// extern data----------------------------------
// function's prototype-------------------------
static void mf_clearBg2(void);
// global data----------------------------------
// static variable------------------------------
static u8 key_rapid[4];
// const data-----------------------------------
// Reads key input
void mf_readKey()
{
u16 ReadData=(*(vu16 *)REG_KEYINPUT ^ 0xffff);
key.Trg=ReadData & (ReadData ^ key.Cont); // Trigger input
key.Cont=ReadData; // Continuous input
}
// Rapid key input
void mf_rapidKey(void)
{
u16 mask;
u8 i;
for(i=0;i<4;i++) {
mask=0x0001<<(i+4);
if(key.Cont & mask) {
key_rapid[i]++;
if(key_rapid[i]==20) {
key.Trg|=mask;
key_rapid[i]=15;
}
}
else
key_rapid[i]=0;
}
}
void mf_clearGame(u16 pos)
{
u8 x;
u16 *bg;
bg=Bg0Bak+pos;
for(x=0;x<8;x++)
*bg++=0x142;
}
void mf_drawBg2_title(void)
{
u8 i;
u16 charNo;
vu16 *bg;
mf_clearBg2();
bg=(vu16 *)(BG_VRAM+0x1000);
charNo=0x2143;
for(i=0;i<4;i++)
*bg++=charNo++;
for(i=0;i<5;i++)
*bg++=charNo;
charNo=(charNo-1) | 0x400;
for(i=0;i<4;i++)
*bg++=charNo--;
}
void mf_drawBg2_search(u8 len)
{
u8 i;
vu16 *bg;
mf_clearBg2();
bg=(vu16 *)(BG_VRAM+0x1000);
for(i=0;i<len;i++) {
bg[32*1]=0x113;
bg[32*0]=0x113;
bg++;
}
}
static void mf_clearBg2(void)
{
u8 i;
vu16 *bg;
bg=(vu16 *)(BG_VRAM+0x1000);
for(i=0;i<0x40;i++)
*bg++=0;
}
// 1 byte character string data display (single characters in 0x00 to 0xff are character strings drawn with 1 byte)
u16 *mf_drawString(u16 pos,u16 color,const u8 *str)
{
u16 *dst;
dst=Bg0Bak+pos;
while(*str)
*dst++=(u16)*str++ | color << 12;
return dst;
}
// Clears rectangle BG
void mf_clearRect(u16 topPos,u8 height,u8 width)
{
u8 i,j;
u16 *leftTop;
for(i=0;i<height;i++) {
leftTop=Bg0Bak+topPos+(i<<5);
for(j=0;j<width;j++)
*leftTop++=0x0020;
}
}
// 3 second wait
void mf_wait3sec(void)
{
u8 i;
for(i=0;i<3*60;i++)
VBlankIntrWait();
}
void mf_winInit(void)
{
*(vu16 *)REG_WIN0H=0xff;
*(vu16 *)REG_WIN0V=0xff;
*(vu16 *)REG_WIN0=0x3f;
*(vu16 *)REG_WINOUT=0;
*(vu16 *)REG_BLDCNT=0x2857;
*(vu16 *)REG_BLDALPHA=0x1f00;
}
void mf_winFade(u8 dir)
{
u16 i;
u16 val;
if(dir==0)
*(vu16 *)REG_DISPCNT&=0xfbff;
i=0;
while(i<=0x10) {
VBlankIntrWait();
if(i==0x10)
val=0;
else {
//val=0x10-i;
val=(~i & 0xf)+1;
}
if(dir)
*(vu16 *)REG_BLDALPHA=val<<8 | i;
else
*(vu16 *)REG_BLDALPHA=val | i<<8;
i++;
VBlankIntrWait();
}
}