example.cpp 1.61 KB
Newer Older
1
2
3
4
#include <gba_console.h>
#include <gba_video.h>
#include <gba_interrupt.h>
#include <gba_systemcalls.h>
5
#include <gba_input.h>
6

Erik Faye-Lund's avatar
Erik Faye-Lund committed
7
8
9
10
#ifndef REG_WAITCNT
#define REG_WAITCNT (*(vu16*)(REG_BASE + 0x0204))
#endif

11
12
#include <stdio.h>
#include <assert.h>
13
#include <string.h>
14

15
#include "../include/pimpmobile.h"
Erik Faye-Lund's avatar
Erik Faye-Lund committed
16
#include "../src/pimp_mixer.h"
17
#include "../src/config.h"
18
#include "gbfs.h"
19

Erik Faye-Lund's avatar
Erik Faye-Lund committed
20
21
22
23
24
25
int fade = 0;
void callback(int a, int b)
{
	fade = 255;
}

26
27
28
void vblank()
{
	pimp_vblank();
Erik Faye-Lund's avatar
Erik Faye-Lund committed
29
30
31
32
33
	if (fade > 0) fade -= 8;
	int f = (fade * fade) >> 8;

	BG_COLORS[0] = RGB8(f, f, f);
	
Erik Faye-Lund's avatar
   
Erik Faye-Lund committed
34
35
	while (REG_VCOUNT != 0);
	pimp_frame();
36
37
}

Erik Faye-Lund's avatar
Erik Faye-Lund committed
38

39
40
41
42
43
44
45
46
47
48
GBFS_FILE const* fs;
const void *sample_bank = 0;
int curr_file = 0;
int file_count = 0;

void play_next_file()
{
	static char name[32];
	const void *mod;

49
50
	do
	{
51
52
		mod = gbfs_get_nth_obj(fs, curr_file++, name, 0);
		if (curr_file > file_count - 1) curr_file = 0;
53
54
	}
	while (strncmp(name, "sample_bank.bin", 32) == 0);
55
56
57
58
59
	
	pimp_close();
	pimp_init(mod, sample_bank);
}

60
61
62
int main()
{
//	REG_WAITCNT = 0x46d6; // lets set some cool waitstates...
Erik Faye-Lund's avatar
   
Erik Faye-Lund committed
63
	REG_WAITCNT = 0x46da; // lets set some cool waitstates...
Jørn Nystad's avatar
Jørn Nystad committed
64

65
66
67
	InitInterrupt();
	EnableInterrupt(IE_VBL);
	consoleInit(0, 4, 0, NULL, 0, 15);
Jørn Nystad's avatar
Jørn Nystad committed
68

Erik Faye-Lund's avatar
Erik Faye-Lund committed
69
70
	BG_COLORS[0] = RGB5(0, 0, 0);
	BG_COLORS[241] = RGB5(31, 31, 31);
71
	REG_DISPCNT = MODE_0 | BG0_ON;
Erik Faye-Lund's avatar
Erik Faye-Lund committed
72
	
73
74
75
	fs = find_first_gbfs_file((void*)0x08000000);
	file_count = gbfs_count_objs(fs);
	sample_bank  = gbfs_get_obj(fs, "sample_bank.bin", 0);
76
	
Erik Faye-Lund's avatar
Erik Faye-Lund committed
77
	pimp_set_callback(callback);
78
	play_next_file();
Erik Faye-Lund's avatar
Erik Faye-Lund committed
79

Erik Faye-Lund's avatar
Erik Faye-Lund committed
80
81
	SetInterrupt(IE_VBL, vblank);
	EnableInterrupt(IE_VBL);
82
	
83
84
85
	while (1)
	{
		VBlankIntrWait();
86
87
		ScanKeys();
		if (KeysDown() & KEY_A) play_next_file();
88
	}
Jørn Nystad's avatar
Jørn Nystad committed
89

90
91
	pimp_close();
}