-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loader.c
122 lines (103 loc) · 3.67 KB
/
Loader.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Functions that load things from the file system.
*/
#include <nds.h>
#include "Loader.h"
// Load a single 16bit image into RAM, ensuring it is visible
void loadImage(char* path, uint16_t* buffer, uint32_t size) {
int fd = open( path, O_RDONLY );
read( fd, buffer, size );
close( fd );
// Ensure alpha bit is set
for( int i = 0; i < size/2; i++ ) {
buffer[i] |= BIT(15);
}
}
// Load data into VRAM at a specified position by first loading
// it into main memory and them DMA'ing it to VRAM.
void loadVRAMIndirect(char* path, uint16_t* vramPos, uint32_t size) {
int fd = open( path, O_RDONLY );
read( fd, tempImage, size );
close( fd );
for( int i = 0; i < size/2; i++ ) {
vramPos[i] = tempImage[i];
}
}
// Load data into VRAM at a specified position by first loading
// it into main memory and them DMA'ing it to VRAM and also visibe &c &c
void loadImageVRAMIndirect(char* path, uint16_t* vramPos, uint32_t size) {
int fd = open( path, O_RDONLY );
read( fd, tempImage, size*2 );
close( fd );
for( int i = 0; i < size; i++ ) {
vramPos[i] = tempImage[i] | (tempImage[i] == 0?0:BIT(15));
}
}
// Fuck everything these functions are now anything but general
void loadImageVRAMIndirectGreen(char* path, uint16_t* vramPos, uint32_t size) {
int fd = open( path, O_RDONLY );
read( fd, tempImage, size*2 );
close( fd );
for( int i = 0; i < size; i++ ) {
vramPos[i] = tempImage[i] | ((tempImage[i]|BIT(15)) == ((31<<5)|BIT(15)) ?0:BIT(15));
}
}
// Load a single 8bit image into VRAM at a specified position by first loading
// it into main memory and them DMA'ing it to VRAM.
void load8bVRAMIndirect(char* path, uint16_t* vramPos, uint32_t size) {
int fd = open( path, O_RDONLY );
read( fd, tempImage, size );
close( fd );
for( int i = 0; i < size; i++ ) {
vramPos[i] = tempImage[i];
}
}
// Load any data into main ram.
void loadData(char* path, uint8_t* target, uint32_t size) {
int fd = open( path, O_RDONLY | O_BINARY );
read( fd, target, size );
close( fd );
}
// Load an 64x64 image into A/B OBJ RAM, return pointer.
uint16_t* loadSpriteA( char* path ) {
uint16_t* newSprite = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_256Color);
load8bVRAMIndirect( path, newSprite, 64*64*2 );
return( newSprite );
}
uint16_t* loadBmpSpriteA( char* path ) {
uint16_t* newSprite = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_Bmp);
loadImageVRAMIndirect( path, newSprite, 64*64 );
return( newSprite );
}
uint16_t* loadBmpSpriteB( char* path ) {
uint16_t* newSprite = oamAllocateGfx(&oamSub, SpriteSize_32x32, SpriteColorFormat_Bmp);
loadImageVRAMIndirect( path, newSprite, 64*64 );
return( newSprite );
}
uint16_t* loadBmpSpriteAGreen( char* path ) {
uint16_t* newSprite = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_Bmp);
loadImageVRAMIndirectGreen( path, newSprite, 64*64*2 );
return( newSprite );
}
uint16_t* loadSpriteB( char* path ) {
uint16_t* newSprite = oamAllocateGfx(&oamSub, SpriteSize_64x64, SpriteColorFormat_256Color);
load8bVRAMIndirect( path, newSprite, 64*64*2 );
return( newSprite );
}
// Same, 32x32.
uint16_t* loadSprite32A( char* path ) {
uint16_t* newSprite = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color);
load8bVRAMIndirect( path, newSprite, 32*32*2 );
return( newSprite );
}
uint16_t* loadSprite32B( char* path ) {
uint16_t* newSprite = oamAllocateGfx(&oamSub, SpriteSize_32x32, SpriteColorFormat_256Color);
load8bVRAMIndirect( path, newSprite, 32*32*2 );
return( newSprite );
}
// 16x16
uint16_t* loadSprite16A( char* path ) {
uint16_t* newSprite = oamAllocateGfx(&oamMain, SpriteSize_16x16, SpriteColorFormat_256Color);
load8bVRAMIndirect( path, newSprite, 16*16*2 );
return( newSprite );
}