mirror of
https://github.com/Alvin-Zilverstand/bob16.git
synced 2026-11-24 21:23:01 +01:00
stuff
This commit is contained in:
1 parent
96cd1ac97d
commit
6dfe517094
33 files changed
+9970
-3177
No files matched your search
+102
-7
@@ -8,9 +8,17 @@ void file_snapshot(int operation) {
|
||||
descriptor[0] = (int)file_names; descriptor[1] = (int)file_lengths;
|
||||
descriptor[2] = (int)file_kinds; descriptor[3] = (int)file_used;
|
||||
result = bob_snapshot(descriptor, operation);
|
||||
#ifdef BOBC_WIDE
|
||||
if (result == -1) println("Storage unavailable. Check bob-files.b32 location/permissions (or BOB16_STORAGE).");
|
||||
#else
|
||||
if (result == -1) println("Storage unavailable. Check bob-files.b16 location/permissions (or BOB16_STORAGE).");
|
||||
#endif
|
||||
else if (result < 0) println("Invalid saved files; RAM files unchanged.");
|
||||
#ifdef BOBC_WIDE
|
||||
else if (operation == 0) println("Files saved to bob-files.b32 (or BOB16_STORAGE).");
|
||||
#else
|
||||
else if (operation == 0) println("Files saved to bob-files.b16 (or BOB16_STORAGE).");
|
||||
#endif
|
||||
else {
|
||||
println("Files restored; previous RAM files replaced.");
|
||||
if (result == 1) println("Kernel changed: old programs omitted. Compile restored C sources again.");
|
||||
@@ -20,7 +28,16 @@ void file_snapshot(int operation) {
|
||||
char *file_name(int slot) { return file_names + slot * NAME_WORDS; }
|
||||
/* The upper 4096 words are reserved for file contents, above the kernel stack.
|
||||
Supervised programs cannot write this region. */
|
||||
int *file_content(int slot) { return (int *)0xf000 + slot * FILE_WORDS; }
|
||||
int *file_content(int slot) {
|
||||
#ifdef BOBC_WIDE
|
||||
int i; int offset;
|
||||
offset = 0;
|
||||
for (i = 0; i < slot; i++) if (file_used[i]) offset += file_lengths[i] + 1;
|
||||
return (int *)0xf000 + offset;
|
||||
#else
|
||||
return (int *)0xf000 + slot * FILE_WORDS;
|
||||
#endif
|
||||
}
|
||||
int file_find(char *name) {
|
||||
int i;
|
||||
for (i = 0; i < FILE_COUNT; i++)
|
||||
@@ -44,16 +61,79 @@ int file_slot(char *name) {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int file_write(char *name, int *data, int length, int kind) {
|
||||
int file_prepare_native(char *name) {
|
||||
int i; int count; int length;
|
||||
length = strlen(name);
|
||||
if (!length || length >= NAME_WORDS || file_find(name) >= 0) return -1;
|
||||
for (i = 0; i < length; i++) if (name[i] < 33 || name[i] > 126) return -1;
|
||||
count = 0;
|
||||
for (i = 0; i < FILE_COUNT; i++) if (file_used[i]) {
|
||||
if (i != count) {
|
||||
memcpy(file_name(count), file_name(i), NAME_WORDS);
|
||||
file_lengths[count] = file_lengths[i]; file_kinds[count] = file_kinds[i]; file_used[count] = 1;
|
||||
file_used[i] = 0;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
if (count == FILE_COUNT) return -1;
|
||||
memset(file_name(count), 0, NAME_WORDS); memcpy(file_name(count), name, length);
|
||||
file_lengths[count] = 0; file_kinds[count] = 3; file_used[count] = 1;
|
||||
return count;
|
||||
}
|
||||
int file_write(char *name, void *data, int length, int kind) {
|
||||
#ifdef BOBC_WIDE
|
||||
int slot; int i; int used; int available; int targetOffset; int sourceSlot;
|
||||
if (length < 0 || length >= FILE_WORDS || (!kind && length >= TEXT_WORDS)) return -1;
|
||||
if (!kind) for (i = 0; i < length; i++) if (!((int *)data)[i] || ((int *)data)[i] > 255) return -1;
|
||||
int oldSlot = file_find(name);
|
||||
slot = file_slot(name);
|
||||
if (slot < 0) return -1;
|
||||
sourceSlot = -1;
|
||||
for (i = 0; i < FILE_COUNT; i++) if (file_used[i] && data == file_content(i)) sourceSlot = i;
|
||||
used = 0;
|
||||
for (i = 0; i < FILE_COUNT; i++) if (file_used[i] && i != slot) used += file_lengths[i] + 1;
|
||||
available = FILE_WORDS - used;
|
||||
if (length + 1 > available) {
|
||||
if (oldSlot < 0) { file_used[slot] = 0; file_lengths[slot] = 0; file_kinds[slot] = 0; memset(file_name(slot), 0, NAME_WORDS); }
|
||||
return -1;
|
||||
}
|
||||
if (sourceSlot == slot) return slot;
|
||||
/* Compact first so variable-sized files never leave unusable gaps. */
|
||||
for (i = 0; i < FILE_COUNT; i++) if (file_used[i] && i != slot) {
|
||||
int *source; int *destination; int j;
|
||||
source = (int *)0xf000; destination = (int *)0xf000;
|
||||
for (j = 0; j < i; j++) if (file_used[j] && j != slot) destination += file_lengths[j] + 1;
|
||||
for (j = 0; j < i; j++) if (file_used[j]) source += file_lengths[j] + 1;
|
||||
if (source != destination && destination < source)
|
||||
for (j = 0; j <= file_lengths[i]; j++) destination[j] = source[j];
|
||||
}
|
||||
/* Insert the rewritten target at its slot-ordered offset. */
|
||||
targetOffset = 0;
|
||||
for (i = 0; i < slot; i++) if (file_used[i] && i != slot) targetOffset += file_lengths[i] + 1;
|
||||
{ int total = 0;
|
||||
for (i = 0; i < FILE_COUNT; i++) if (file_used[i] && i != slot) total += file_lengths[i] + 1;
|
||||
for (i = total - 1; i >= targetOffset; i--) ((int *)0xf000)[i + length + 1] = ((int *)0xf000)[i];
|
||||
if (sourceSlot >= 0) {
|
||||
int sourceOffset = 0;
|
||||
for (i = 0; i < sourceSlot; i++) if (file_used[i] && i != slot) sourceOffset += file_lengths[i] + 1;
|
||||
if (sourceSlot > slot) sourceOffset += length + 1;
|
||||
data = (int *)0xf000 + sourceOffset;
|
||||
}
|
||||
memcpy((int *)0xf000 + targetOffset, data, length);
|
||||
((int *)0xf000)[targetOffset + length] = 0;
|
||||
file_lengths[slot] = length; file_kinds[slot] = kind;
|
||||
}
|
||||
return slot;
|
||||
#else
|
||||
int slot;
|
||||
if (length < 0 || length >= FILE_WORDS) return -1;
|
||||
slot = file_slot(name);
|
||||
if (slot < 0) return -1;
|
||||
memcpy(file_content(slot), data, length);
|
||||
file_content(slot)[length] = 0;
|
||||
file_lengths[slot] = length;
|
||||
file_kinds[slot] = kind;
|
||||
file_lengths[slot] = length; file_kinds[slot] = kind;
|
||||
return slot;
|
||||
#endif
|
||||
}
|
||||
void file_list(void) {
|
||||
int i; int count;
|
||||
@@ -61,13 +141,19 @@ void file_list(void) {
|
||||
for (i = 0; i < FILE_COUNT; i++) {
|
||||
if (file_used[i]) {
|
||||
print(file_name(i)); print(" "); print_dec(file_lengths[i]);
|
||||
if (file_kinds[i]) println(" words (program)");
|
||||
if (file_kinds[i] == 3) println(" words (native bob32 image)");
|
||||
else if (file_kinds[i]) println(" words (program)");
|
||||
else println(" chars (text)");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (!count) println("No files.");
|
||||
print("Used "); print_dec(count); println("/8 slots; limit 511 words per file. delete frees a slot.");
|
||||
print("Used "); print_dec(count);
|
||||
#ifdef BOBC_WIDE
|
||||
println("/8 slots; shared 4096-word storage. Text/resident files max 511; native apps use remaining space.");
|
||||
#else
|
||||
println("/8 slots; limit 511 words per file. delete frees a slot.");
|
||||
#endif
|
||||
}
|
||||
void file_manage(char *operation, char *name, char *destination) {
|
||||
int slot; int target;
|
||||
@@ -75,9 +161,18 @@ void file_manage(char *operation, char *name, char *destination) {
|
||||
slot = file_find(name);
|
||||
if (slot < 0) { println("File not found. Use ls to see names."); return; }
|
||||
if (strcmp(operation, "delete") == 0) {
|
||||
#ifdef BOBC_WIDE
|
||||
int sourceOffset; int destinationOffset; int i; int j;
|
||||
sourceOffset = 0; destinationOffset = 0;
|
||||
for (i = 0; i < FILE_COUNT; i++) if (file_used[i]) {
|
||||
if (i == slot) { sourceOffset += file_lengths[i] + 1; continue; }
|
||||
if (sourceOffset != destinationOffset)
|
||||
for (j = 0; j <= file_lengths[i]; j++) ((int *)0xf000)[destinationOffset + j] = ((int *)0xf000)[sourceOffset + j];
|
||||
sourceOffset += file_lengths[i] + 1; destinationOffset += file_lengths[i] + 1;
|
||||
}
|
||||
#endif
|
||||
file_used[slot] = 0; file_lengths[slot] = 0; file_kinds[slot] = 0;
|
||||
memset(file_name(slot), 0, NAME_WORDS);
|
||||
memset(file_content(slot), 0, FILE_WORDS);
|
||||
println("Deleted."); return;
|
||||
}
|
||||
if (!*destination || strlen(destination) >= NAME_WORDS) {
|
||||
|
||||
Reference in new issue
Block a user