2021-07-08 05:37:18 +00:00
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
#include "util.h"
|
|
|
|
#include "user.h"
|
|
|
|
#include "cart.h"
|
|
|
|
|
|
|
|
Cart* create_cart(char* name) {
|
|
|
|
char path[64] = {0};
|
|
|
|
char file[64] = {0};
|
|
|
|
Cart* cart;
|
|
|
|
char* cart_data;
|
|
|
|
|
|
|
|
scat(path, "carts/");
|
|
|
|
scat(path, name);
|
|
|
|
scpy(path, file, 64);
|
|
|
|
ccat(file, '/');
|
|
|
|
scat(file, name);
|
|
|
|
scat(file, ".rom");
|
|
|
|
|
|
|
|
cart_data = read_bytes(file);
|
|
|
|
if (cart_data != nil) {
|
|
|
|
cart = (Cart*)malloc(sizeof(Cart));
|
|
|
|
scpy(name, cart->name, 32);
|
|
|
|
cart->rom = cart_data;
|
|
|
|
|
|
|
|
scpy(path, file, 64);
|
|
|
|
scat(file, "/data/sprites");
|
|
|
|
cart->sprite_data = read_bytes(file);
|
|
|
|
scpy(path, file, 64);
|
|
|
|
scat(file, "/data/text");
|
|
|
|
cart->txt_data = read_bytes(file);
|
|
|
|
scpy(path, file, 64);
|
|
|
|
scat(file, "/data/audio");
|
|
|
|
cart->audio_data = read_bytes(file);
|
|
|
|
|
|
|
|
return cart;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
Cart* find_cart(UserInfo* table, char* name) {
|
|
|
|
UserInfo* u = table;
|
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < 64; i++) {
|
2021-07-10 06:46:04 +00:00
|
|
|
if (slen(u->name) > 0 && u->cart != nil && scmp(u->cart->name, name))
|
2021-07-08 05:37:18 +00:00
|
|
|
return u->cart;
|
|
|
|
u++;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint count_carts(UserInfo* table, char* name) {
|
|
|
|
UserInfo* u = table;
|
|
|
|
uint i, j;
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < 64; i++) {
|
2021-07-10 06:46:04 +00:00
|
|
|
if (slen(u->name) > 0 && u->cart != nil && scmp(u->cart->name, name))
|
2021-07-08 05:37:18 +00:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_cart(Cart* self) {
|
|
|
|
if (self != nil) {
|
|
|
|
free(self->rom);
|
|
|
|
if (self->sprite_data != nil)
|
|
|
|
free(self->sprite_data);
|
|
|
|
if (self->audio_data != nil)
|
|
|
|
free(self->audio_data);
|
|
|
|
if (self->txt_data != nil)
|
|
|
|
free(self->txt_data);
|
|
|
|
|
|
|
|
free(self);
|
|
|
|
self = nil;
|
|
|
|
}
|
|
|
|
}
|