-
Notifications
You must be signed in to change notification settings - Fork 3
/
platform_n64.c
84 lines (62 loc) · 2.19 KB
/
platform_n64.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
#include "platform.h"
#include <memory.h>
volatile int N64_FRAME = 0;
uint32_t RSP_OVL_ID = 0;
DEFINE_RSP_UCODE(rsp_video);
uint8_t keystate[256];
extern char end __attribute__((section (".data")));
static void vblank_handler(void) {
N64_FRAME++;
}
void plat_init(int audiofreq, int fps) {
#ifdef __LIBDRAGON_DEBUG_H
debug_init_isviewer();
debug_init_usblog();
#endif
debugf("MVS64\n");
register_VI_handler(vblank_handler);
char *heap_top = (char*)0x80000000 + get_memory_size() - 0x10000;
char *heap_end = &end;
debugf("heap [%p - %p = %d]\n", heap_top, heap_end, heap_top-heap_end);
controller_init();
// NOTE: there seems to be a bug in libdragon display library when ANTIALIAS_OFF
// is used. Some RDP register is not configured correctly and the display is
// corrupted on NTSC consoles.
display_init(RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE);
dfs_init(DFS_DEFAULT_LOCATION);
rdpq_init();
// rdpq_debug_start();
// Register our custom RSP overlay into the RSP queue engine
RSP_OVL_ID = rspq_overlay_register(&rsp_video);
}
int plat_poll(void) {
controller_scan();
struct controller_data ckeys = get_keys_pressed();
memset(keystate, 0, sizeof(keystate));
if (ckeys.c[0].up) { keystate[PLAT_KEY_P1_UP] = 1; }
if (ckeys.c[0].down) { keystate[PLAT_KEY_P1_DOWN] = 1; }
if (ckeys.c[0].left) { keystate[PLAT_KEY_P1_LEFT] = 1; }
if (ckeys.c[0].right) { keystate[PLAT_KEY_P1_RIGHT] = 1; }
if (ckeys.c[0].A) { keystate[PLAT_KEY_P1_A] = 1; }
if (ckeys.c[0].B) { keystate[PLAT_KEY_P1_B] = 1; }
if (ckeys.c[0].C_down) { keystate[PLAT_KEY_P1_C] = 1; }
if (ckeys.c[0].C_right) { keystate[PLAT_KEY_P1_D] = 1; }
if (ckeys.c[0].start) { keystate[PLAT_KEY_P1_START] = 1; }
return 1;
}
void plat_enable_video(int enable) {
}
void plat_save_screenshot(const char *fn) {
}
uint8_t *g_screen_ptr;
int g_screen_pitch;
void plat_beginframe(void) {
surface_t *rdp_disp = display_get();
g_screen_ptr = rdp_disp->buffer;
g_screen_pitch = 320*2;
rdpq_attach(rdp_disp, NULL);
rdpq_set_scissor(0, 0, 320, 224);
}
void plat_endframe(void) {
rdpq_detach_show();
}