minor fixes

This commit is contained in:
2026-03-19 18:48:58 +01:00
parent b1fc23ab5a
commit 1a6a008331
2 changed files with 23 additions and 1 deletions

View File

@@ -215,6 +215,25 @@ nn_Exit ne_fsState_handler(nn_FilesystemRequest *req) {
} }
fwrite(req->strarg1, sizeof(char), req->strarg1len, f); fwrite(req->strarg1, sizeof(char), req->strarg1len, f);
return NN_OK; return NN_OK;
case NN_FS_SEEK:
if(req->fd < 0 || req->fd >= NN_MAX_OPENFILES) {
nn_setError(C, "bad file descriptor");
return NN_EBADCALL;
}
f = state->files[req->fd];
if(f == NULL) {
nn_setError(C, "bad file descriptor");
return NN_EBADCALL;
}
int whence = SEEK_SET;
if(req->whence == NN_SEEK_CUR) {
whence = SEEK_CUR;
} else if(req->whence == NN_SEEK_END) {
whence = SEEK_END;
}
fseek(f, req->off, whence);
req->off = ftell(f);
return NN_OK;
case NN_FS_OPENDIR: case NN_FS_OPENDIR:
ne_fsState_truepath(state, truepath, req->strarg1); ne_fsState_truepath(state, truepath, req->strarg1);
state->dir = ne_opendir(truepath); state->dir = ne_opendir(truepath);

View File

@@ -3006,10 +3006,13 @@ typedef struct nn_DriveState {
} nn_DriveState; } nn_DriveState;
void nn_drive_seekPenalty(nn_Computer *C, size_t lastSector, size_t newSector, const nn_Drive *drive) { 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;
size_t maxSectors = drive->capacity / drive->sectorSize; size_t maxSectors = drive->capacity / drive->sectorSize;
size_t sectorsPerPlatter = maxSectors / drive->platterCount; size_t sectorsPerPlatter = maxSectors / drive->platterCount;
// RPM over the number of sectors, over 60 seconds. // RPM over the number of sectors, over 60 seconds.
double latencyPerSector = (double)drive->rpm / maxSectors / 60; double latencyPerSector = 1.0 / ((double)drive->rpm / 60 * maxSectors);
// magic // magic
lastSector %= sectorsPerPlatter; lastSector %= sectorsPerPlatter;