mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
improved way of initialising vms at (re)launch
This commit is contained in:
@@ -38,8 +38,8 @@ if (statusCode != 0) {
|
||||
|
||||
|
||||
let readCount = 0
|
||||
function readBytes(length) {
|
||||
let ptr = sys.malloc(length)
|
||||
function readBytes(length, ptrToDecode) {
|
||||
let ptr = (ptrToDecode === undefined) ? sys.malloc(length) : ptrToDecode
|
||||
let requiredBlocks = Math.floor((readCount + length) / 4096) - Math.floor(readCount / 4096)
|
||||
|
||||
let completedReads = 0
|
||||
@@ -108,6 +108,8 @@ audio.setMasterVolume(0, 255)
|
||||
// FIXME: when a playback was interrupted using SHIFT-CTRL-T-R, then re-tried, the ghost from the previous run
|
||||
// briefly manifests, even if you're queueing only once
|
||||
|
||||
const decodePtr = sys.malloc(BLOCK_SIZE)
|
||||
|
||||
while (sampleSize > 0) {
|
||||
let queueSize = audio.getPosition(0)
|
||||
|
||||
@@ -123,14 +125,13 @@ while (sampleSize > 0) {
|
||||
// upload four samples for lag-safely
|
||||
for (let repeat = QUEUE_MAX - queueSize; repeat > 0; repeat--) {
|
||||
let readLength = (sampleSize < BLOCK_SIZE) ? sampleSize : BLOCK_SIZE
|
||||
let samples = readBytes(readLength)
|
||||
let samples = readBytes(readLength, decodePtr)
|
||||
|
||||
audio.putPcmDataByPtr(samples, readLength, 0)
|
||||
audio.setSampleUploadLength(0, readLength)
|
||||
audio.startSampleUpload(0)
|
||||
|
||||
sampleSize -= readLength
|
||||
sys.free(samples)
|
||||
|
||||
if (repeat > 1) sys.sleep(10)
|
||||
}
|
||||
@@ -145,3 +146,4 @@ while (sampleSize > 0) {
|
||||
}
|
||||
|
||||
audio.stop(0) // this shouldn't be necessary, it should stop automatically
|
||||
sys.free(samples)
|
||||
|
||||
@@ -1094,7 +1094,7 @@ var execApp = (cmdsrc, args, appname) => {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Boot script
|
||||
serial.println("TVDOS.SYS initialised, running boot script...");
|
||||
serial.println(`TVDOS.SYS initialised on VM ${sys.getVmId()}, running boot script...`);
|
||||
var _G = {};
|
||||
let cmdfile = files.open("A:/tvdos/bin/command.js")
|
||||
eval(`var _AUTOEXEC=function(exec_args){${cmdfile.sread()}\n};` +
|
||||
|
||||
@@ -74,36 +74,6 @@ for (let f = 1; ; f++) {
|
||||
// insert sync packet
|
||||
if (f > 1) appendToOutfile(syncPacket)
|
||||
|
||||
// insert video frame
|
||||
if (f <= TOTAL_FRAMES) {
|
||||
let fname = PATHFUN(f)
|
||||
let framefile = files.open(_G.shell.resolvePathInput(fname).full)
|
||||
let fileLen = framefile.size
|
||||
framefile.pread(infile, fileLen)
|
||||
|
||||
|
||||
let [_1, _2, channels, _3] = graphics.decodeImageTo(infile, fileLen, imagearea)
|
||||
|
||||
print(`Frame ${f}/${TOTAL_FRAMES} (Ch: ${channels}) ->`)
|
||||
|
||||
// graphics.imageToDisplayableFormat(imagearea, decodearea, 560, 448, 3, 1)
|
||||
ipfFun(imagearea, ipfarea, WIDTH, HEIGHT, channels, false, f)
|
||||
|
||||
let gzlen = gzip.compFromTo(ipfarea, FBUF_SIZE, gzippedImage)
|
||||
|
||||
let frameSize = [
|
||||
(gzlen >>> 0) & 255,
|
||||
(gzlen >>> 8) & 255,
|
||||
(gzlen >>> 16) & 255,
|
||||
(gzlen >>> 24) & 255
|
||||
]
|
||||
|
||||
appendToOutfile(packetType)
|
||||
appendToOutfile(frameSize)
|
||||
appendToOutfilePtr(gzippedImage, gzlen)
|
||||
|
||||
print(` ${gzlen} bytes\n`)
|
||||
}
|
||||
// insert audio track, if any
|
||||
if (audioRemaining > 0) {
|
||||
|
||||
@@ -136,6 +106,36 @@ for (let f = 1; ; f++) {
|
||||
audioRemaining -= actualBytesToRead
|
||||
}
|
||||
}
|
||||
// insert video frame
|
||||
if (f <= TOTAL_FRAMES) {
|
||||
let fname = PATHFUN(f)
|
||||
let framefile = files.open(_G.shell.resolvePathInput(fname).full)
|
||||
let fileLen = framefile.size
|
||||
framefile.pread(infile, fileLen)
|
||||
|
||||
|
||||
let [_1, _2, channels, _3] = graphics.decodeImageTo(infile, fileLen, imagearea)
|
||||
|
||||
print(`Frame ${f}/${TOTAL_FRAMES} (Ch: ${channels}) ->`)
|
||||
|
||||
// graphics.imageToDisplayableFormat(imagearea, decodearea, 560, 448, 3, 1)
|
||||
ipfFun(imagearea, ipfarea, WIDTH, HEIGHT, channels, false, f)
|
||||
|
||||
let gzlen = gzip.compFromTo(ipfarea, FBUF_SIZE, gzippedImage)
|
||||
|
||||
let frameSize = [
|
||||
(gzlen >>> 0) & 255,
|
||||
(gzlen >>> 8) & 255,
|
||||
(gzlen >>> 16) & 255,
|
||||
(gzlen >>> 24) & 255
|
||||
]
|
||||
|
||||
appendToOutfile(packetType)
|
||||
appendToOutfile(frameSize)
|
||||
appendToOutfilePtr(gzippedImage, gzlen)
|
||||
|
||||
print(` ${gzlen} bytes\n`)
|
||||
}
|
||||
|
||||
// if there is no video and audio remaining, exit the loop
|
||||
if (f > TOTAL_FRAMES && audioRemaining <= 0) break
|
||||
|
||||
@@ -29,8 +29,8 @@ con.clear(); con.curs_set(0)
|
||||
|
||||
let readCount = 0
|
||||
|
||||
function readBytes(length) {
|
||||
let ptr = sys.malloc(length)
|
||||
function readBytes(length, ptrToDecode) {
|
||||
let ptr = (ptrToDecode === undefined) ? sys.malloc(length) : ptrToDecode
|
||||
let requiredBlocks = Math.floor((readCount + length) / 4096) - Math.floor(readCount / 4096)
|
||||
|
||||
let completedReads = 0
|
||||
@@ -156,8 +156,8 @@ let ipfbuf = sys.malloc(FBUF_SIZE)
|
||||
graphics.setGraphicsMode(4)
|
||||
|
||||
let startTime = sys.nanoTime()
|
||||
|
||||
let framesRead = 0
|
||||
let audioFired = false
|
||||
|
||||
audio.resetParams(0)
|
||||
audio.purgeQueue(0)
|
||||
@@ -182,6 +182,8 @@ while (readCount < FILE_LENGTH) {
|
||||
|
||||
let packetType = readShort()
|
||||
|
||||
// ideally, first two packets will be audio packets
|
||||
|
||||
// sync packets
|
||||
if (65535 == packetType) {
|
||||
frameUnit -= 1
|
||||
@@ -204,6 +206,12 @@ while (readCount < FILE_LENGTH) {
|
||||
if (frameUnit == 1) {
|
||||
gzip.decompFromTo(gzippedPtr, payloadLen, ipfbuf) // should return FBUF_SIZE
|
||||
decodefun(ipfbuf, -1048577, -1310721, width, height, (packetType & 255) == 5)
|
||||
|
||||
// defer audio playback until a first frame is sent
|
||||
if (!audioFired) {
|
||||
audio.play(0)
|
||||
audioFired = true
|
||||
}
|
||||
}
|
||||
|
||||
sys.free(gzippedPtr)
|
||||
@@ -221,7 +229,6 @@ while (readCount < FILE_LENGTH) {
|
||||
audio.putPcmDataByPtr(samples, readLength, 0)
|
||||
audio.setSampleUploadLength(0, readLength)
|
||||
audio.startSampleUpload(0)
|
||||
audio.play(0)
|
||||
|
||||
sys.free(samples)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user