mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-12 07:44:03 +09:00
basic:SAVE function, filesystem:write
This commit is contained in:
21
assets/bios/basicbios.js
Normal file
21
assets/bios/basicbios.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
println("Main RAM:"+(system.maxmem() >> 10)+" KBytes");
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// probe bootable device
|
||||||
|
|
||||||
|
var _BIOS = {};
|
||||||
|
|
||||||
|
// Syntax: [Port, Drive-number]
|
||||||
|
// Port #0-3: Serial port 1-4
|
||||||
|
// #4+ : Left for future extension
|
||||||
|
// Drive-number always starts at 1
|
||||||
|
_BIOS.FIRST_BOOTABLE_PORT = [0,1]; // ah screw it
|
||||||
|
|
||||||
|
Object.freeze(_BIOS);
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// load a BASIC rom
|
||||||
|
sys.mapRom(1);
|
||||||
|
eval("let _appStub=function(exec_args){"+sys.romReadAll()+"};_appStub;")();
|
||||||
3
assets/rmaze.bas
Normal file
3
assets/rmaze.bas
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
1 rem RANDOM MAZE
|
||||||
|
10 print(chr$(47+round(rnd(1))*45);)
|
||||||
|
20 goto 10
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -70,11 +70,23 @@ filesystem.readAll = function(driveLetter) {
|
|||||||
throw Error("File not opened");
|
throw Error("File not opened");
|
||||||
}
|
}
|
||||||
if (response < 0 || response >= 128) {
|
if (response < 0 || response >= 128) {
|
||||||
let status = com.getDeviceStatus(port[0]);
|
throw Error("Reading a file failed with "+response);
|
||||||
throw Error("Reading a file failed with "+response+": "+status.message);
|
|
||||||
}
|
}
|
||||||
return com.pullMessage(port[0]);
|
return com.pullMessage(port[0]);
|
||||||
};
|
};
|
||||||
|
filesystem.write = function(driveLetter, string) {
|
||||||
|
let port = filesystem._toPorts(driveLetter);
|
||||||
|
com.sendMessage(port[0], "WRITE"+string.length);
|
||||||
|
let response = com.getStatusCode(port[0]);
|
||||||
|
if (135 == response) {
|
||||||
|
throw Error("File not opened");
|
||||||
|
}
|
||||||
|
if (response < 0 || response >= 128) {
|
||||||
|
throw Error("Writing a file failed with "+response);
|
||||||
|
}
|
||||||
|
com.sendMessage(port[0], string);
|
||||||
|
filesystem._flush(port[0]); filesystem._close(port[0]);
|
||||||
|
};
|
||||||
filesystem.isDirectory = function(driveLetter) {
|
filesystem.isDirectory = function(driveLetter) {
|
||||||
let port = filesystem._toPorts(driveLetter);
|
let port = filesystem._toPorts(driveLetter);
|
||||||
com.sendMessage(port[0], "LISTFILES");
|
com.sendMessage(port[0], "LISTFILES");
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
|
import net.torvald.tsvm.peripheral.BasicBios;
|
||||||
|
import net.torvald.tsvm.peripheral.BasicRom;
|
||||||
import net.torvald.tsvm.peripheral.GenericBios;
|
import net.torvald.tsvm.peripheral.GenericBios;
|
||||||
|
import net.torvald.tsvm.peripheral.VMProgramRom;
|
||||||
|
|
||||||
public class AppLoader {
|
public class AppLoader {
|
||||||
|
|
||||||
@@ -27,7 +30,8 @@ public class AppLoader {
|
|||||||
|
|
||||||
|
|
||||||
// val vm = VM(64.kB(), TheRealWorld(), arrayOf(GenericBios))
|
// val vm = VM(64.kB(), TheRealWorld(), arrayOf(GenericBios))
|
||||||
VM vm = new VM(64 << 10, new TheRealWorld(), new GenericBios[]{GenericBios.INSTANCE});
|
//VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{GenericBios.INSTANCE});
|
||||||
|
VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{BasicBios.INSTANCE, BasicRom.INSTANCE});
|
||||||
new LwjglApplication(new VMGUI(vm, appConfig), appConfig);
|
new LwjglApplication(new VMGUI(vm, appConfig), appConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ class VMGUI(val vm: VM, val appConfig: LwjglApplicationConfiguration) : Applicat
|
|||||||
|
|
||||||
lateinit var memvwr: Memvwr
|
lateinit var memvwr: Memvwr
|
||||||
|
|
||||||
|
val usememvwr = false
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
super.create()
|
super.create()
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ class VMGUI(val vm: VM, val appConfig: LwjglApplicationConfiguration) : Applicat
|
|||||||
vm.getErrorStream = { gpu.getErrorStream() }
|
vm.getErrorStream = { gpu.getErrorStream() }
|
||||||
vm.getInputStream = { gpu.getInputStream() }
|
vm.getInputStream = { gpu.getInputStream() }
|
||||||
|
|
||||||
memvwr = Memvwr(vm)
|
if (usememvwr) memvwr = Memvwr(vm)
|
||||||
|
|
||||||
|
|
||||||
vmRunner = VMRunnerFactory(vm, "js")
|
vmRunner = VMRunnerFactory(vm, "js")
|
||||||
@@ -67,7 +69,7 @@ class VMGUI(val vm: VM, val appConfig: LwjglApplicationConfiguration) : Applicat
|
|||||||
override fun render() {
|
override fun render() {
|
||||||
Gdx.graphics.setTitle("${AppLoader.appTitle} $EMDASH F: ${Gdx.graphics.framesPerSecond}")
|
Gdx.graphics.setTitle("${AppLoader.appTitle} $EMDASH F: ${Gdx.graphics.framesPerSecond}")
|
||||||
|
|
||||||
memvwr.update()
|
if (usememvwr) memvwr.update()
|
||||||
|
|
||||||
super.render()
|
super.render()
|
||||||
|
|
||||||
|
|||||||
@@ -373,10 +373,6 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath:
|
|||||||
statusCode = STATE_CODE_OPERATION_NOT_PERMITTED
|
statusCode = STATE_CODE_OPERATION_NOT_PERMITTED
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!file.canWrite()) {
|
|
||||||
statusCode = STATE_CODE_READ_ONLY
|
|
||||||
return
|
|
||||||
}
|
|
||||||
writeMode = true
|
writeMode = true
|
||||||
writeModeLength = inputString.substring(5, inputString.length).toInt()
|
writeModeLength = inputString.substring(5, inputString.length).toInt()
|
||||||
statusCode = STATE_CODE_STANDBY
|
statusCode = STATE_CODE_STANDBY
|
||||||
|
|||||||
@@ -27,5 +27,43 @@ object GenericBios : VMProgramRom {
|
|||||||
contents.toString(VM.CHARSET)
|
contents.toString(VM.CHARSET)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun get(addr: Int): Byte = contents[addr]
|
||||||
|
}
|
||||||
|
|
||||||
|
object BasicBios : VMProgramRom {
|
||||||
|
private val contents: ByteArray
|
||||||
|
|
||||||
|
init {
|
||||||
|
val bytes = File("./assets/bios/basicbios.js").readBytes()
|
||||||
|
contents = bytes.sliceArray(0 until minOf(65536, bytes.size))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun readAll(): String {
|
||||||
|
// check if bios is compressed in gzip
|
||||||
|
return if (contents.startsWith(GZIP_HEADER))
|
||||||
|
CompressorDelegate.decomp(contents).toString(VM.CHARSET)
|
||||||
|
else
|
||||||
|
contents.toString(VM.CHARSET)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun get(addr: Int): Byte = contents[addr]
|
||||||
|
}
|
||||||
|
|
||||||
|
object BasicRom : VMProgramRom {
|
||||||
|
private val contents: ByteArray
|
||||||
|
|
||||||
|
init {
|
||||||
|
val bytes = File("./assets/tbas/basic.js").readBytes()
|
||||||
|
contents = bytes.sliceArray(0 until minOf(65536, bytes.size))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun readAll(): String {
|
||||||
|
// check if bios is compressed in gzip
|
||||||
|
return if (contents.startsWith(GZIP_HEADER))
|
||||||
|
CompressorDelegate.decomp(contents).toString(VM.CHARSET)
|
||||||
|
else
|
||||||
|
contents.toString(VM.CHARSET)
|
||||||
|
}
|
||||||
|
|
||||||
override fun get(addr: Int): Byte = contents[addr]
|
override fun get(addr: Int): Byte = contents[addr]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user