-
Notifications
You must be signed in to change notification settings - Fork 1
/
graph.c
99 lines (83 loc) · 1.91 KB
/
graph.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
#include <string.h>
#include "snesc.h"
#include "mem.h"
void snesc_vblank(void);
void enablescreen(void)
{
poke(0x2105, 9); // BG mode 1
poke(0x2109, 4); // BG3 map location
poke(0x210b, 1); // BG1/2 tiles location
poke(0x210c, 2); // BG3/4 tiles location
poke(0x212c, 0x15); // enable BG1, BG3, OBJ display
poke(0x2100, 0x80); // force blank
snesc_vblank(); // flush pending DMA jobs before turning on screen
poke(0x2100, 0xf); // turn on screen, full brightness
}
void screenmode(unsigned char m)
{
poke(0x2105, m);
}
void waitforvsync(void)
{
snesc_timer_enabled |= 1;
snesc_timers[0] = 0;
while(!snesc_timers[0])
{
}
}
void delay(unsigned int d)
{
snesc_timer_enabled |= 1;
snesc_timers[0] = 0;
while(snesc_timers[0] < d)
{
}
}
void setpalette(unsigned char* pal)
{
memcpy(snesc_palette, pal, 0x200);
snesc_do_copy |= 0x40;
}
void setsprite(unsigned int s, unsigned char x, unsigned char y, unsigned char t, unsigned char p)
{
struct oam_table1* spr = &snesc_oam_table1[s];
spr->x = x;
spr->y = y;
spr->t = t;
spr->p = p;
snesc_do_copy |= 0x80;
}
void sync(unsigned int d)
{
while(snesc_timers[0] < d)
{
}
}
void resettimer()
{
snesc_timer_enabled |= 1;
snesc_timers[0] = 0;
}
void settiles(unsigned int b, unsigned char* p1, unsigned int size)
{
unsigned int idx = snesc_do_copy & 0x3f;
struct dma_transfer* tr = &snesc_dma_transfers[idx];
/* tile data */
tr->src.ptr = p1;
tr->src.c.type = 0; /* src.ptr and type overlap, so type must be set after */
tr->dest = (b + 1) << 12;
tr->size = size;
/* signal the NMI to copy data to VRAM */
snesc_do_copy++;
}
void setmap(unsigned int b, unsigned char* p1)
{
struct dma_transfer* tr = &snesc_dma_transfers[snesc_do_copy & 0x3f];
/* tile data */
tr->src.ptr = p1;
tr->src.c.type = 0;
tr->dest = b << 10;
tr->size = 0x800;
/* signal the NMI to copy data to VRAM */
snesc_do_copy++;
}