furnace/src/main.cpp

73 lines
1.3 KiB
C++
Raw Normal View History

#include <stdio.h>
#include <mutex>
#include "ta-log.h"
#include "engine/engine.h"
2021-05-28 08:05:37 +00:00
#define DIV_VERSION "dev6"
2021-05-12 22:27:48 +00:00
DivEngine e;
std::mutex m;
int main(int argc, char** argv) {
if (argc<2) {
logI("usage: %s file\n",argv[0]);
return 1;
}
2021-05-13 08:22:57 +00:00
logI("Furnace version " DIV_VERSION ".\n");
logI("loading module...\n");
FILE* f=fopen(argv[1],"rb");
if (f==NULL) {
perror("error");
return 1;
}
if (fseek(f,0,SEEK_END)<0) {
perror("size error");
fclose(f);
return 1;
}
ssize_t len=ftell(f);
if (len==0x7fffffffffffffff) {
perror("could not get file length");
fclose(f);
return 1;
}
if (len<1) {
if (len==0) {
printf("that file is empty!\n");
} else {
perror("tell error");
}
fclose(f);
return 1;
}
unsigned char* file=new unsigned char[len];
if (fseek(f,0,SEEK_SET)<0) {
perror("size error");
fclose(f);
return 1;
}
if (fread(file,1,(size_t)len,f)!=(size_t)len) {
perror("read error");
fclose(f);
return 1;
}
fclose(f);
if (!e.load((void*)file,(size_t)len)) {
logE("could not open file!\n");
return 1;
}
if (!e.init()) {
logE("could not initialize engine!\n");
return 1;
}
logI("loaded! :o\n");
while (true) {
logI("locking...\n");
e.play();
m.lock();
m.lock();
}
return 0;
}