example.cpp 1.46 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
16
#include "../include/pimpmobile.h"
#include "../src/mixer.h"
17
#include "../src/config.h"
18
#include "gbfs.h"
19
20
21
22
23
24
25
26

void vblank()
{
	pimp_vblank();
	while (REG_VCOUNT != 0);
	pimp_frame();
}

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;

	do {
		mod = gbfs_get_nth_obj(fs, curr_file++, name, 0);
		iprintf("'%s\n'", name);
		if (curr_file > file_count - 1) curr_file = 0;
	} while (strncmp(name, "sample_bank.bin", 32) == 0);
	
	pimp_close();
	pimp_init(mod, sample_bank);
}

47
48
49
50
int main()
{
//	REG_WAITCNT = 0x46d6; // lets set some cool waitstates...
	REG_WAITCNT = 0x46da; // lets set some cool waitstates...
Jørn Nystad's avatar
Jørn Nystad committed
51

52
53
54
	InitInterrupt();
	EnableInterrupt(IE_VBL);
	consoleInit(0, 4, 0, NULL, 0, 15);
Jørn Nystad's avatar
Jørn Nystad committed
55

Erik Faye-Lund's avatar
Erik Faye-Lund committed
56
57
	BG_COLORS[0] = RGB5(0, 0, 0);
	BG_COLORS[241] = RGB5(31, 31, 31);
58
	REG_DISPCNT = MODE_0 | BG0_ON;
Erik Faye-Lund's avatar
Erik Faye-Lund committed
59
	
60
61
62
63
	fs = find_first_gbfs_file((void*)0x08000000);
	file_count = gbfs_count_objs(fs);

	sample_bank  = gbfs_get_obj(fs, "sample_bank.bin", 0);
64
	
65
	play_next_file();
Erik Faye-Lund's avatar
Erik Faye-Lund committed
66

Erik Faye-Lund's avatar
Erik Faye-Lund committed
67
68
	SetInterrupt(IE_VBL, vblank);
	EnableInterrupt(IE_VBL);
69
	
70
71
72
	while (1)
	{
		VBlankIntrWait();
73
74
		ScanKeys();
		if (KeysDown() & KEY_A) play_next_file();
75
	}
Jørn Nystad's avatar
Jørn Nystad committed
76

77
78
	pimp_close();
}