-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loader.c
75 lines (63 loc) · 2.12 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
/**
* 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 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* 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 );
}