]> git.bts.cx Git - benzene.git/blob - src_platform/playdate/bz/resources/resource.c
Initial version
[benzene.git] / src_platform / playdate / bz / resources / resource.c
1 #include <bz/resources/resource.h>
2
3 #include <bz/memory/allocator.h>
4 #include <bz/resources/identifier.h>
5 #include <playdate/entrypoint.h>
6 #include <stdarg.h>
7
8 struct BZResource { SDFile *unused; };
9
10 BZResourceID bzResourcesOpenResource(const char *type, const char *identifierFmt, ...) {
11 bzMakeIdentifier(identifier, identifierFmt);
12 bzLog("Trying to load: %s", identifier);
13
14 BZResourceID resource = (BZResourceID)playdate->file->open(identifier, kFileRead);
15 return resource;
16 }
17
18 extern void bzResourcesCloseResource(BZResourceID resource) {
19 SDFile *handle = (SDFile *)resource;
20 playdate->file->close(handle);
21 }
22
23 size_t bzResourcesFileLength(BZResourceID resource) {
24 SDFile *handle = (SDFile *)resource;
25
26 int reset, size;
27
28 reset = playdate->file->tell(handle);
29 playdate->file->seek(handle, 0, SEEK_END);
30 size = playdate->file->tell(handle);
31 playdate->file->seek(handle, reset, SEEK_SET);
32
33 return size;
34 }
35
36 size_t bzResourcesTell(BZResourceID resource) {
37 SDFile *handle = (SDFile *)resource;
38 return playdate->file->tell(handle);
39 }
40
41 size_t bzResourcesSeek(BZResourceID resource, size_t position) {
42 SDFile *handle = (SDFile *)resource;
43 return playdate->file->seek(handle, position, SEEK_SET);
44 }
45
46 size_t bzResourcesReadBytes(BZResourceID resource, void *outputBuffer, size_t numBytes) {
47 SDFile *handle = (SDFile *)resource;
48 return playdate->file->read(handle, outputBuffer, numBytes);
49 }