2023-12-09 19:15:54 +01:00
|
|
|
/**************************************************************
|
|
|
|
_ __ _ _
|
|
|
|
_ __ ___| |_ _ __ ___ / _| ___ _ __| |_| |__
|
|
|
|
| '__/ _ \ __| '__/ _ \| |_ / _ \| '__| __| '_ \
|
|
|
|
| | | __/ |_| | | (_) | _| (_) | | | |_| | | |
|
|
|
|
|_| \___|\__|_| \___/|_| \___/|_| \__|_| |_|
|
|
|
|
for nga
|
|
|
|
|
|
|
|
(c) Charles Childers, Luke Parrish, Marc Simpsonn,
|
|
|
|
Jay Skeer, Kenneth Keating
|
|
|
|
|
|
|
|
**************************************************************/
|
|
|
|
|
2023-12-11 00:38:07 +01:00
|
|
|
V read_block(NgaState *vm) {
|
|
|
|
CELL buffer = stack_pop(vm);
|
|
|
|
CELL block = stack_pop(vm);
|
2023-12-09 19:15:54 +01:00
|
|
|
int32_t m[1024];
|
2023-12-11 00:38:07 +01:00
|
|
|
int fp = open(vm->BlockFile, O_RDONLY, 0666);
|
|
|
|
lseek(fp, 4096 * block, SEEK_SET);
|
|
|
|
read(fp, m, 4096);
|
|
|
|
for (int i = 0; i < 1024; i++) {
|
|
|
|
vm->memory[buffer + i] = (CELL)m[i];
|
2023-12-09 19:15:54 +01:00
|
|
|
}
|
2023-12-11 00:38:07 +01:00
|
|
|
close(fp);
|
|
|
|
}
|
2023-12-09 19:15:54 +01:00
|
|
|
|
2023-12-11 00:38:07 +01:00
|
|
|
V write_block(NgaState *vm) {
|
|
|
|
CELL buffer = stack_pop(vm);
|
|
|
|
CELL block = stack_pop(vm);
|
|
|
|
int32_t m[1024];
|
|
|
|
int fp = open(vm->BlockFile, O_WRONLY, 0666);
|
|
|
|
lseek(fp, 4096 * block, SEEK_SET);
|
|
|
|
for (int i = 0; i < 1024; i++) {
|
|
|
|
m[i] = (int32_t)vm->memory[buffer + i];
|
2023-12-09 19:15:54 +01:00
|
|
|
}
|
2023-12-11 00:38:07 +01:00
|
|
|
write(fp, m, 4096);
|
|
|
|
close(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
V set_block_file(NgaState *vm) {
|
|
|
|
CELL buffer = stack_pop(vm);
|
|
|
|
strlcpy(vm->BlockFile, string_extract(vm, buffer), 1024);
|
|
|
|
}
|
2023-12-09 19:15:54 +01:00
|
|
|
|
2023-12-11 00:38:07 +01:00
|
|
|
V io_blocks(NgaState *vm) {
|
|
|
|
switch (stack_pop(vm)) {
|
|
|
|
case 0: read_block(vm); break;
|
|
|
|
case 1: write_block(vm); break;
|
|
|
|
case 2: set_block_file(vm); break;
|
2023-12-09 19:15:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-11 00:38:07 +01:00
|
|
|
V query_blocks(NgaState *vm) {
|
2023-12-09 19:15:54 +01:00
|
|
|
stack_push(vm, 0);
|
|
|
|
stack_push(vm, DEVICE_BLOCKS);
|
|
|
|
}
|