example.cpp 2.31 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>
Erik Faye-Lund's avatar
Erik Faye-Lund committed
6
#include <gba_timers.h>
7

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

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

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

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

Erik Faye-Lund's avatar
Erik Faye-Lund committed
27
28
29
30
31
32
const void *mod;
GBFS_FILE const* fs;
const void *sample_bank = 0;
int curr_file = 0;
int file_count = 0;

33
34
35
void vblank()
{
	pimp_vblank();
Erik Faye-Lund's avatar
Erik Faye-Lund committed
36
37
38
	if (fade > 0) fade -= 8;
	int f = (fade * fade) >> 8;

Erik Faye-Lund's avatar
   
Erik Faye-Lund committed
39
	while (REG_VCOUNT != 0);
Erik Faye-Lund's avatar
Erik Faye-Lund committed
40
41
42
43
44

	REG_TM2CNT_L = 0;
	REG_TM2CNT_H = 0;
	REG_TM2CNT_H = TIMER_START;
//	BG_COLORS[0] = RGB8(31, 31, 0);
Erik Faye-Lund's avatar
   
Erik Faye-Lund committed
45
	pimp_frame();
Erik Faye-Lund's avatar
Erik Faye-Lund committed
46
47
48
49
50
51
52
53
54
//	BG_COLORS[0] = RGB8(0, 0, 0);
	u32 value = REG_TM2CNT_L;
	BG_COLORS[0] = RGB8(f, f, f);
	
	static int counter = 0;
	
	static int accum = 0;
//	float val = float(value) / ((1 << 24) / 60);
	accum += value;
55

Erik Faye-Lund's avatar
Erik Faye-Lund committed
56
57
58
	counter++;
	if (counter == 60)
	{
Erik Faye-Lund's avatar
Erik Faye-Lund committed
59

Erik Faye-Lund's avatar
Erik Faye-Lund committed
60
61
62
63
64
65
66
67
68
69
70
71
72
		printf("%d\n", accum);
//		printf("%d.%02d\n", int(val * 100), int(val * 100 * 100));

//		pimp_set_pos(0, 0);
		pimp_close();
		pimp_init(mod, sample_bank);

		counter = 0;
		accum = 0;
	}
	
//	printf("%d\n", value);
}
73
74
75
76
77

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

78
79
	do
	{
80
81
		mod = gbfs_get_nth_obj(fs, curr_file++, name, 0);
		if (curr_file > file_count - 1) curr_file = 0;
82
83
	}
	while (strncmp(name, "sample_bank.bin", 32) == 0);
84
85
86
	
	pimp_close();
	pimp_init(mod, sample_bank);
Erik Faye-Lund's avatar
Erik Faye-Lund committed
87
	pimp_set_callback(callback);
88
89
}

90
91
92
int main()
{
//	REG_WAITCNT = 0x46d6; // lets set some cool waitstates...
Erik Faye-Lund's avatar
   
Erik Faye-Lund committed
93
	REG_WAITCNT = 0x46da; // lets set some cool waitstates...
Jørn Nystad's avatar
Jørn Nystad committed
94

95
96
97
	InitInterrupt();
	EnableInterrupt(IE_VBL);
	consoleInit(0, 4, 0, NULL, 0, 15);
Jørn Nystad's avatar
Jørn Nystad committed
98

Erik Faye-Lund's avatar
Erik Faye-Lund committed
99
100
	BG_COLORS[0] = RGB5(0, 0, 0);
	BG_COLORS[241] = RGB5(31, 31, 31);
101
	REG_DISPCNT = MODE_0 | BG0_ON;
Erik Faye-Lund's avatar
Erik Faye-Lund committed
102
	
103
104
105
	fs = find_first_gbfs_file((void*)0x08000000);
	file_count = gbfs_count_objs(fs);
	sample_bank  = gbfs_get_obj(fs, "sample_bank.bin", 0);
106
	
107
	play_next_file();
Erik Faye-Lund's avatar
Erik Faye-Lund committed
108

Erik Faye-Lund's avatar
Erik Faye-Lund committed
109
110
	SetInterrupt(IE_VBL, vblank);
	EnableInterrupt(IE_VBL);
111
	
112
113
114
	while (1)
	{
		VBlankIntrWait();
115
		ScanKeys();
Erik Faye-Lund's avatar
Erik Faye-Lund committed
116
117
118
119
		int keys = KeysDown();
		if (keys & KEY_RIGHT) pimp_set_pos(0, pimp_get_order() + 1);
		if (keys & KEY_LEFT)  pimp_set_pos(pimp_get_row() + 8, pimp_get_order());
		if (keys & KEY_A) play_next_file();
120
	}
Jørn Nystad's avatar
Jørn Nystad committed
121

122
123
	pimp_close();
}