a working internet modem that only reads

This commit is contained in:
minjaesong
2022-09-22 16:26:04 +09:00
parent cab2699794
commit e905b3ace8
16 changed files with 367 additions and 34 deletions

View File

@@ -334,6 +334,18 @@ Array.prototype.tail = function() {
Array.prototype.init = function() {
return this.slice(0, this.length - 1)
}
String.prototype.head = function() {
return this[0]
}
String.prototype.last = function() {
return this[this.length - 1]
}
String.prototype.tail = function() {
return this.substring(1)
}
String.prototype.init = function() {
return this.substring(0, this.length - 1)
}
Array.prototype.shuffle = function() {
let counter = this.length;

View File

@@ -8,19 +8,18 @@ for (let y = 0; y < 40; y++) {
for (let x = 0; x < 30; x++) {
let octet = imageBits[y * 30 + x]
for (let i = 0; i < 8; i++) {
graphics.plotPixel(8*x + i, y+8, ((octet >>> (7 - i)) & 1 != 0) ? 255 : 239)
graphics.plotPixel(120 + 8*x + i, 36 + y, ((octet >>> (7 - i)) & 1 != 0) ? 255 : 239)
}
}
}
con.move(8,1+(40-t.length>>1))
con.move(13,1+(80-t.length>>1))
print(t)
// wait arbitrary time
for (let b=0;b<sys.maxmem()*10;b++) {
sys.poke(0,(Math.random()*255)|0)
sys.poke(0,0)
}
con.clear()
graphics.clearPixels(255)
let tmr = sys.nanoTime();
while (sys.nanoTime() - tmr < 2147483648) sys.spin();
// clear screen
graphics.clearPixels(255);con.color_pair(239,255);
con.clear();con.move(1,1);
///////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,3 @@
let f = files.open("CON")
f.swrite("Hello, world! I'm just writing to a file named 'CON'\n")
f.close()

View File

@@ -0,0 +1,10 @@
let fout = files.open("FBIPF")
let fin = files.open(_G.shell.resolvePathInput(exec_args[1]).full)
let ipfRead = fin.bread()
println(`Input file: ${ipfRead.length} bytes`)
fout.bwrite(ipfRead)
fin.close()
fout.close()

View File

@@ -0,0 +1,17 @@
let f = files.open("RND")
let mlen = 512
let m = sys.malloc(mlen)
println(f.driverID)
println(`Ptr: ${m}`)
f.pread(m, mlen, 0)
f.close()
for (let i = 0; i < mlen; i++) {
print(sys.peek(m+i).toString(16).padStart(2,'0'))
print(' ')
}
println()
sys.free(m)

20
assets/disk0/fstest.js Normal file
View File

@@ -0,0 +1,20 @@
let f = files.open("A:/tvdos/bin")
//f.driveLetter = "Z"
println(`File path: ${f.path}`)
println(`FS driver: ${f.driverID}`)
println(`DrvLetter: ${f.driveLetter}`)
println(`Parent: ${f.parentPath}`)
println(`Size: ${f.size}`)
println(`List of files:`)
let ls = f.list()
ls.forEach(it=>{
println(`${it.path}\t${it.name}\t${it.size}`)
})
println(`Size again: ${f.size}`)

9
assets/disk0/memtest.js Normal file
View File

@@ -0,0 +1,9 @@
let ptr1 = sys.malloc(1024)
let ptr2 = sys.malloc(4321)
println(`ptr: ${ptr1} ${ptr2}; used mem: ${sys.getUsedMem()}`)
println(`freeing ptr1`)
sys.free(ptr1)
println(`used mem now: ${sys.getUsedMem()}`)
println(`freeing ptr2`)
sys.free(ptr2)
println(`used mem now: ${sys.getUsedMem()}`)

11
assets/disk0/nettest.js Normal file
View File

@@ -0,0 +1,11 @@
let url="http://localhost/testnet/test.txt"
let file = files.open("B:\\"+url)
if (!file.exists) {
printerrln("No such URL: "+url)
return 1
}
let text = file.sread()
println(text)

View File

@@ -36,11 +36,38 @@ const _TVDOS = {};
_TVDOS.VERSION = "1.0";
_TVDOS.DRIVES = {}; // Object where key-value pair is <drive-letter> : [serial-port, drive-number]
_TVDOS.DRIVEFS = {}; // filesystem driver for the drive letter
_TVDOS.DRIVEINFO = {};
// actually figure out the drive letter association
// Drive A is always the device we're currently on
_TVDOS.DRIVES["A"] = _BIOS.FIRST_BOOTABLE_PORT
_TVDOS.DRIVEFS["A"] = "SERIAL"
//TODO
_TVDOS.DRIVEINFO["A"] = {
name: com.sendMessageGetBytes(_BIOS.FIRST_BOOTABLE_PORT[0], "DEVNAM\x17").init(),
type: com.sendMessageGetBytes(_BIOS.FIRST_BOOTABLE_PORT[0], "DEVTYP\x17").substring(0,4)
}
// probe filesystem devices
let devnameToDriver = {"PRNT":"LP","STOR":"SERIAL","COMM":"COM","HTTP":"NET"}
let currentDriveLetter = ["A","B","C","D"]
for (let portNo = 1; portNo < 4; portNo++) {
if (com.areYouThere(portNo)) {
com.sendMessage(portNo, "DEVRST\x17")
sys.spin()
let devname = com.sendMessageGetBytes(portNo, "DEVTYP\x17").substring(0,4)
let driver = devnameToDriver[devname]
serial.println(`port: ${portNo}, devname: ${devname} ${com.sendMessageGetBytes(portNo, "DEVNAM\x17")}`)
if (driver) {
let dlet = currentDriveLetter[portNo]
_TVDOS.DRIVEFS[dlet] = driver
_TVDOS.DRIVES[dlet] = [portNo, 1]
_TVDOS.DRIVEINFO[dlet] = {
name: com.sendMessageGetBytes(portNo, "DEVNAM\x17").init(),
type: devname
}
}
}
}
_TVDOS.DRV = {}
@@ -590,6 +617,40 @@ Object.freeze(_TVDOS.DRV.FS.DEVFBIPF)
///////////////////////////////////////////////////////////////////////////////
_TVDOS.DRV.FS.NET = {}
_TVDOS.DRV.FS.NET.sread = (fd) => {
let port = _TVDOS.DRV.FS.SERIAL._toPorts(fd.driveLetter)
let url = fd.path.substring(fd.path.indexOf("\\")+1).replaceAll("\\","/")
serial.println("NETFILE GET " + url)
com.sendMessage(port[0], "GET " + url)
com.waitUntilReady(port[0])
return com.pullMessage(port[0])
}
_TVDOS.DRV.FS.NET.flush = () => {}
_TVDOS.DRV.FS.NET.close = () => {}
_TVDOS.DRV.FS.NET.isDirectory = () => false
_TVDOS.DRV.FS.NET.listFiles = () => undefined
_TVDOS.DRV.FS.NET.touch = () => {}
_TVDOS.DRV.FS.NET.mkDir = () => {}
_TVDOS.DRV.FS.NET.mkFile = () => {}
_TVDOS.DRV.FS.NET.remove = () => {}
_TVDOS.DRV.FS.NET.exists = (fd) => {
let port = _TVDOS.DRV.FS.SERIAL._toPorts(fd.driveLetter)
let url = fd.path.substring(fd.path.indexOf("\\")+1).replaceAll("\\","/")
com.sendMessage(port[0], "GET " + url)
com.waitUntilReady(port[0])
return (0 == com.getStatusCode(port[0]))
}
///////////////////////////////////////////////////////////////////////////////
// Legacy Serial filesystem, !!pending for removal!!

View File

@@ -0,0 +1,5 @@
Object.entries(_TVDOS.DRIVES).forEach(it=>{
let [letter, [port, drivenum]] = it
let dinfo = _TVDOS.DRIVEINFO[letter]
println(`${letter}: COM${port+1},${drivenum} (${dinfo.name}-${dinfo.type})`)
})