small rework
This commit is contained in:
@@ -394,14 +394,6 @@ int main(int argc, char **argv) {
|
||||
tickDelay = atof(getenv("NN_TICKDELAY"));
|
||||
}
|
||||
|
||||
const char *driveData = "error('unmanaged drive')";
|
||||
nn_VDrive vdrive = {
|
||||
.data = driveData,
|
||||
.datalen = strlen(driveData),
|
||||
.label = "",
|
||||
.labellen = 0,
|
||||
};
|
||||
|
||||
struct {int key; nn_codepoint unicode;} keybuf[512];
|
||||
memset(keybuf, 0, sizeof(keybuf));
|
||||
size_t keycap = sizeof(keybuf) / sizeof(keybuf[0]);
|
||||
|
||||
@@ -496,6 +496,7 @@ typedef struct ncl_DriveState {
|
||||
nn_Context *ctx;
|
||||
nn_Lock *lock;
|
||||
nn_Drive conf;
|
||||
ncl_VFS vfs;
|
||||
bool isReadonly;
|
||||
size_t usage;
|
||||
size_t lastSector;
|
||||
@@ -508,10 +509,14 @@ typedef struct ncl_EEState {
|
||||
nn_Context *ctx;
|
||||
nn_Lock *lock;
|
||||
nn_EEPROM conf;
|
||||
ncl_VFS vfs;
|
||||
bool isReadonly;
|
||||
size_t usage;
|
||||
char *codepath;
|
||||
char *datapath;
|
||||
// stored data buffer
|
||||
char *data;
|
||||
// the data length
|
||||
size_t datalen;
|
||||
char label[NN_MAX_LABEL];
|
||||
size_t labellen;
|
||||
} ncl_EEState;
|
||||
@@ -919,7 +924,7 @@ nn_Component *ncl_createFilesystem(nn_Universe *universe, const char *address, c
|
||||
}
|
||||
|
||||
nn_Component *ncl_createDrive(nn_Universe *universe, const char *address, const char *path, const nn_Drive *drive, bool isReadonly);
|
||||
nn_Component *ncl_createEEPROM(nn_Universe *universe, const char *address, const char *codepath, const char *datapath, bool isReadonly);
|
||||
nn_Component *ncl_createEEPROM(nn_Universe *universe, const char *address, const char *path, bool isReadonly);
|
||||
|
||||
ncl_VFS ncl_setVFS(nn_Component *component, ncl_VFS vfs);
|
||||
|
||||
@@ -1275,7 +1280,6 @@ void ncl_statComponent(nn_Component *component, ncl_ComponentStat *stat) {
|
||||
memcpy(stat->label, ee->label, stat->labellen);
|
||||
stat->eeprom.conf = &ee->conf;
|
||||
stat->eeprom.codepath = ee->codepath;
|
||||
stat->eeprom.datapath = ee->datapath;
|
||||
nn_unlock(ee->ctx, ee->lock);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#define NCL_GPU "ncl-gpu"
|
||||
#define NCL_SCREEN "ncl-screen"
|
||||
|
||||
#define NCL_TMPEEPROM "ncl-tmpeeprom"
|
||||
#define NCL_TMPFS "ncl-tmpfs"
|
||||
#define NCL_TMPDRIVE "ncl-tmpdrive"
|
||||
|
||||
// Default file cost.
|
||||
// This is for a normal HDD/floppy.
|
||||
#define NCL_FILECOST_DEFAULT 512
|
||||
@@ -191,7 +195,28 @@ size_t ncl_setLabel(nn_Component *c, const char *label, size_t len);
|
||||
|
||||
nn_Component *ncl_createFilesystem(nn_Universe *universe, const char *address, const char *path, const nn_Filesystem *fs, bool isReadonly);
|
||||
nn_Component *ncl_createDrive(nn_Universe *universe, const char *address, const char *path, const nn_Drive *drive, bool isReadonly);
|
||||
nn_Component *ncl_createEEPROM(nn_Universe *universe, const char *address, const char *codepath, const char *datapath, bool isReadonly);
|
||||
// data is stored interally
|
||||
nn_Component *ncl_createEEPROM(nn_Universe *universe, const char *address, const char *path, bool isReadonly);
|
||||
|
||||
#define NCL_VFS_NAMEMAX 32
|
||||
|
||||
// Creates a tmpfs.
|
||||
// This component is mostly treated like a normal filesystem,
|
||||
// except you obviously cannot bind a tmpfs to it.
|
||||
// Do note, it is illegal to mix encoded state between normal filesystem
|
||||
// and tmpfs.
|
||||
nn_Component *ncl_createTmpFS(nn_Universe *universe, const nn_Filesystem *fs);
|
||||
|
||||
// creates a temporary EEPROM, with some initial code
|
||||
// the data is stored internally
|
||||
nn_Component *ncl_createTmpEEPROM(nn_Universe *universe, const nn_EEPROM *eeprom, const char *code, size_t codelen);
|
||||
|
||||
// creates a temporary drive, with some initial data
|
||||
nn_Component *ncl_createTmpDrive(nn_Universe *universe, const nn_EEPROM *eeprom, const char *data, size_t datalen);
|
||||
|
||||
// Gets the VFS bound to a filesystem, drive or eeprom.
|
||||
// Returns the default FS if the component is not recognized.
|
||||
ncl_VFS ncl_getVFS(nn_Component *component);
|
||||
|
||||
// Sets the VFS bound to a filesystem, drive or eeprom.
|
||||
// This determines the filesystem the operations are run in.
|
||||
@@ -236,7 +261,6 @@ typedef struct ncl_ComponentStat {
|
||||
size_t codeUsed;
|
||||
size_t dataUsed;
|
||||
const char *codepath;
|
||||
const char *datapath;
|
||||
} eeprom;
|
||||
struct {
|
||||
const nn_Filesystem *conf;
|
||||
|
||||
@@ -3754,8 +3754,6 @@ nn_Component *nn_createFilesystem(nn_Universe *universe, const char *address, co
|
||||
return c;
|
||||
}
|
||||
|
||||
nn_Component *nn_createVFilesystem(nn_Universe *universe, const char *address, const nn_VFilesystem *vfs, const nn_Filesystem *fs);
|
||||
|
||||
static void nn_drive_seekPenalty(nn_Computer *C, size_t lastSector, size_t newSector, const nn_Drive *drive) {
|
||||
// Check if SSD
|
||||
if(drive->rpm == 0) return;
|
||||
@@ -3785,6 +3783,7 @@ typedef enum nn_DrvNum {
|
||||
NN_DRVNUM_GETCAPACITY,
|
||||
NN_DRVNUM_GETSECTORSIZE,
|
||||
NN_DRVNUM_GETPLATTERCOUNT,
|
||||
NN_DRVNUM_ISRO,
|
||||
NN_DRVNUM_GETLABEL,
|
||||
NN_DRVNUM_SETLABEL,
|
||||
NN_DRVNUM_READSECTOR,
|
||||
@@ -3829,8 +3828,14 @@ nn_Component *nn_createDrive(nn_Universe *universe, const char *address, const n
|
||||
[NN_DRVNUM_GETCAPACITY] = {"getCapacity", "function(): integer - Get drive capacity", NN_DIRECT},
|
||||
[NN_DRVNUM_GETSECTORSIZE] = {"getSectorSize", "function(): integer - Get sector size", NN_DIRECT},
|
||||
[NN_DRVNUM_GETPLATTERCOUNT] = {"getPlatterCount", "function(): integer - Get number of platters on this drive", NN_DIRECT},
|
||||
[NN_DRVNUM_ISRO] = {"isReadOnly", "function(): boolean - Get whether the drive is read-only", NN_DIRECT},
|
||||
[NN_DRVNUM_GETLABEL] = {"getLabel", "function(): string? - Get drive label", NN_DIRECT},
|
||||
[NN_DRVNUM_SETLABEL] = {"setLabel", "function(label: string?): string - Set drive label", NN_DIRECT},
|
||||
[NN_DRVNUM_SETLABEL] = {"setLabel", "function(label: string?): string - Set drive label", NN_INDIRECT},
|
||||
[NN_DRVNUM_READSECTOR] = {"readSector", "function(sector: integer): string - Read a sector from the drive", NN_DIRECT},
|
||||
[NN_DRVNUM_WRITESECTOR] = {"writeSector", "function(sector: integer): boolean - Read a sector from the drive", NN_DIRECT},
|
||||
[NN_DRVNUM_READBYTE] = {"readByte", "function(byte: integer): integer - Read a single signed byte", NN_DIRECT},
|
||||
[NN_DRVNUM_READUBYTE] = {"readUByte", "function(byte: integer): integer - Read a single unsigned byte", NN_DIRECT},
|
||||
[NN_DRVNUM_WRITEBYTE] = {"writeByte", "function(byte: integer, value: integer): boolean - Write a single byte", NN_DIRECT},
|
||||
};
|
||||
nn_Exit e = nn_setComponentMethodsArray(c, methods, NN_DRVNUM_COUNT);
|
||||
if(e) {
|
||||
@@ -3852,8 +3857,6 @@ nn_Component *nn_createDrive(nn_Universe *universe, const char *address, const n
|
||||
return c;
|
||||
}
|
||||
|
||||
nn_Component *nn_createVDrive(nn_Universe *universe, const char *address, const nn_VDrive *vdrive, const nn_Drive *drive);
|
||||
|
||||
typedef struct nn_ScreenState {
|
||||
nn_Context *ctx;
|
||||
nn_ScreenConfig scrconf;
|
||||
|
||||
@@ -1039,44 +1039,7 @@ extern const nn_Filesystem nn_defaultFloppy;
|
||||
// a generic tmpfs
|
||||
extern const nn_Filesystem nn_defaultTmpFS;
|
||||
|
||||
typedef struct nn_VFileNode {
|
||||
// the name of the node.
|
||||
// This is the raw name, do not append / to directories.
|
||||
const char *name;
|
||||
// if NULL, the node is a directory.
|
||||
const char *data;
|
||||
union {
|
||||
// for files, how much of data to read.
|
||||
size_t dataLen;
|
||||
// for directories, the amount of entries encoded afterwards.
|
||||
// Do note that entry encoding is recursive, so for example
|
||||
// a(1) b(2) c("hi") d("there"), means directory a/ has a directory b/ which has 2 files, c and d,
|
||||
// even though a's entry count is 1.
|
||||
size_t entryCount;
|
||||
};
|
||||
} nn_VFileNode;
|
||||
|
||||
typedef struct nn_VFilesystem {
|
||||
const char *label;
|
||||
size_t labellen;
|
||||
bool isReadOnly;
|
||||
// cost of a file entry when computed the spaceUsed
|
||||
size_t fileCost;
|
||||
// The maximum amount of directory entries. This is used to pre-allocate an array.
|
||||
// It also helps against memory hogging attacks.
|
||||
size_t maxDirEntries;
|
||||
// the maximum amount of nodes the filesystem can have. This is also used to pre-allocate an array.
|
||||
size_t maxNodeCount;
|
||||
// used to compute lastModified. This, together with the context's time procedure, is used to compute the timestamp.
|
||||
// It must be a UNIX timestamp, else you'll get weird results.
|
||||
size_t creationTime;
|
||||
size_t rootNodeCount;
|
||||
// the flat array of the filesystem. See nn_VFileNode for details.
|
||||
nn_VFileNode *image;
|
||||
} nn_VFilesystem;
|
||||
|
||||
nn_Component *nn_createFilesystem(nn_Universe *universe, const char *address, const nn_Filesystem *fs, void *state, nn_FSHandler *handler);
|
||||
nn_Component *nn_createVFilesystem(nn_Universe *universe, const char *address, const nn_VFilesystem *vfs, const nn_Filesystem *fs);
|
||||
|
||||
// Drive class
|
||||
|
||||
@@ -1118,15 +1081,6 @@ typedef struct nn_Drive {
|
||||
double dataEnergyCost;
|
||||
} nn_Drive;
|
||||
|
||||
typedef struct nn_VDrive {
|
||||
// initial label
|
||||
const char *label;
|
||||
size_t labellen;
|
||||
// initial data
|
||||
const char *data;
|
||||
size_t datalen;
|
||||
} nn_VDrive;
|
||||
|
||||
extern const nn_Drive nn_defaultDrives[4];
|
||||
extern const nn_Drive nn_floppyDrive;
|
||||
|
||||
@@ -1191,7 +1145,6 @@ typedef struct nn_DriveRequest {
|
||||
typedef nn_Exit (nn_DriveHandler)(nn_DriveRequest *request);
|
||||
|
||||
nn_Component *nn_createDrive(nn_Universe *universe, const char *address, const nn_Drive *drive, void *state, nn_DriveHandler *handler);
|
||||
nn_Component *nn_createVDrive(nn_Universe *universe, const char *address, const nn_VDrive *vdrive, const nn_Drive *drive);
|
||||
|
||||
// Screen class
|
||||
|
||||
|
||||
Reference in New Issue
Block a user