Compare commits

..

11 Commits

Author SHA1 Message Date
minjaesong
6623ff62bc hopper moved to its own repo. hopper now actually installs/removes 2026-05-23 22:41:37 +09:00
minjaesong
3c43aa8aa6 ow fucc 2026-05-23 19:29:34 +09:00
minjaesong
848ee491d1 hopper: actually using remote mirror 2026-05-23 19:27:34 +09:00
minjaesong
eddd65fa13 taud: more interpolation 2026-05-23 19:03:53 +09:00
minjaesong
1e2814af87 more convenient internet accessing using net.mjs 2026-05-23 19:03:41 +09:00
minjaesong
61a721d628 LFS upgrade 2026-05-23 18:02:09 +09:00
minjaesong
9723c33dfc playtaud tweaks 2026-05-22 12:35:02 +09:00
minjaesong
065e586cd6 taud player with visualiser 2026-05-22 05:23:14 +09:00
minjaesong
83d9cde0bd taut typesetter is now tvdos package 2026-05-22 01:37:24 +09:00
minjaesong
0b82d4b32c more hopper stuffs 2026-05-21 23:59:16 +09:00
minjaesong
277693989b hopper stuffs 2026-05-21 17:40:22 +09:00
35 changed files with 3053 additions and 348 deletions

12
.gitignore vendored
View File

@@ -62,11 +62,15 @@ tsvmman.pdf
*.ilg
*.ind
assets/disk0/tvdos/bin/tautfont.png
video_encoder/*
.idea/vcs.xml
# in-dev stuffs
assets/disk0/home/basic/*
assets/disk0/movtestimg/*.jpg
assets/disk0/*.mov
assets/diskMediabin/*
video_encoder/*
assets/disk0/tvdos/bin/tautfont.png
assets/disk0/hopper/*

View File

@@ -116,6 +116,16 @@ Use the build scripts in `buildapp/`:
- `My_BASIC_Programs/`: Example BASIC programs for testing
- TVDOS filesystem uses custom format with specialised drivers
### TSVM JavaScript Source Encoding
**Do not normalise `\uXXXX` or `\xXX` escapes in .js / .mjs files that run inside
TSVM.** TSVM's character set is not Unicode, and the JS string literal parser
behaves differently for raw bytes vs. escape sequences. Both forms appear in
existing code intentionally — leave each one as-is. When writing new content,
prefer raw UTF-8 characters in string literals (e.g. write the character `ù`
directly, rather than a `\uXXXX`-style escape) unless you are matching a
pattern already established in the surrounding code.
## Videotron2K
The Videotron2K is a specialised video display controller with:

View File

@@ -0,0 +1,5 @@
[EXEC_FUNS]
nes,A:/home/tvnes/tvnes.js {0}
[COL_HL_EXT]
nes,156

View File

@@ -1,6 +0,0 @@
/**
* Hopper is a package manager for TSVM
* Created by CuriousTorvald on 2026-04-16
*/
println("Hopper - Package manager for TSVM")

View File

@@ -1,11 +1,13 @@
let url="http:localhost/testnet/test.txt"
/*let url="https:raw.githubusercontent.com/curioustorvald/hopper-mirror/refs/heads/master/aa.hop.per"
let file = files.open("B:\\"+url)
if (!file.exists) {
printerrln("No such URL: "+url)
return 1
}
}*/
let text = file.sread()
let net = require("A:/tvdos/include/net.mjs")
let text = net.fetchText("https://raw.githubusercontent.com/curioustorvald/hopper-mirror/refs/heads/master/aa.hop.per")
if (text === null) { printerrln("No such URL"); return 1 }
println(text)

View File

@@ -55,10 +55,12 @@ class PmemFSfile {
// string representation (preferable)
if (typeof bytes === 'string' || bytes instanceof String) {
this.data = bytes
this.length = bytes.length
}
// Javascript array OR JVM byte[]
else if (Array.isArray(bytes) || bytes.toString().startsWith("[B")) {
this.bdata = bytes[i]
this.bdata = bytes
this.length = bytes.length
}
else {
throw Error("Invalid type for directory")
@@ -76,10 +78,10 @@ class PmemFSfile {
dataAsBytes() {
if (this.bdata !== undefined) return this.bdata
this.bdata = new Int8Array(this.data.length)
this.bdata = new Uint8Array(this.data.length)
for (let i = 0; i < this.data.length; i++) {
let p = this.data.charCodeAt(i)
this.bdata[i] = (p > 127) ? p - 255 : p
this.bdata[i] = p
}
return this.bdata
}
@@ -164,16 +166,16 @@ class TVDOSFileDescriptor {
constructor(path0, driverID) {
if (path0.startsWith("$")) {
let path1 = path0.substring(3)
let slashPos = path1.indexOf("/")
let path1 = path0.replaceAll("/", "\\").substring(3)
let slashPos = path1.indexOf("\\")
let devName = path1.substring(0, (slashPos < 0) ? path1.length : slashPos)
if (!files.reservedNames.includes(devName)) {
throw Error(`${devName} is not a valid device file`)
}
this._driveLetter = undefined
this._path = path0
this._driveLetter = '$'
this._path = '\\' + path1
this._driverID = `DEV${devName}`
this._driver = _TVDOS.DRV.FS[`DEV${devName}`] // can't just put `driverID` here
}
@@ -939,8 +941,9 @@ _TVDOS.DRV.FS.DEVTMP.bread = (fd) => {
_TVDOS.DRV.FS.DEVTMP.pread = (fd, ptr, count, offset) => {
if (_TVDOS.TMPFS[fd.path] === undefined) throw Error(`No such file: ${fd.fullPath}`)
let str = _TVDOS.TMPFS[fd.path].dataAsString()
for (let i = 0; i < count - (offset || 0); i++) {
sys.poke(ptr + i, String.charCodeAt(i + (offset || 0)))
let off = offset || 0
for (let i = 0; i < count; i++) {
sys.poke(ptr + i, str.charCodeAt(off + i))
}
}
@@ -988,6 +991,7 @@ _TVDOS.DRV.FS.DEVTMP.remove = (fd) => {
return true
}
_TVDOS.DRV.FS.DEVTMP.exists = (fd) => (_TVDOS.TMPFS[fd.path] !== undefined)
_TVDOS.DRV.FS.DEVTMP.getFileLen = (fd) => (_TVDOS.TMPFS[fd.path].length)
Object.freeze(_TVDOS.DRV.FS.DEVTMP)

View File

@@ -77,56 +77,31 @@ function printmotd() {
let motd = motdFile.sread().trim()
let width = con.getmaxyx()[1]
let ts = require("typesetter")
if (goFancy) {
let margin = 4
let internalWidth = width - 2*margin
let textWidth = internalWidth - 2 // one space of padding inside each ribbon edge
con.color_pair(255,253) // white text, transparent back (initial ribbon)
let [cy, cx] = con.getyx()
con.mvaddch(cy, 4, 16);con.curs_right();print(' ')
const PCX_INIT = margin - 2
let tcnt = 0
let pcx = PCX_INIT
con.color_pair(240,253) // black text, white back (first line of text)
while (tcnt <= motd.length) {
let char = motd.charAt(tcnt)
if (char != '\n') {
// prevent the line starting from ' '
if (pcx != PCX_INIT || char != ' ') {
print(motd.charAt(tcnt))
}
pcx += 1
}
if ('\n' == char || pcx % internalWidth == 0 && pcx != 0 || tcnt == motd.length) {
// current line ending
let [_, ncx] = con.getyx()
for (let k = 0; k < width - margin - ncx + 1; k++) print(' ')
con.color_pair(255,253) // white text, transparent back
con.addch(17);println()
if (tcnt == motd.length) break
// next line header
let [ncy, __] = con.getyx()
con.color_pair(255,253) // white text, transparent back
con.mvaddch(ncy, 4, 16);con.curs_right();print(' ');con.color_pair(240,253) // black text, white back (subsequent lines of the text)
pcx = PCX_INIT
}
tcnt += 1
}
let lines = ts.typeset(motd, textWidth)
lines.forEach(line => {
let [cy, _cx] = con.getyx()
con.color_pair(255,253) // ribbon edge: white text, transparent back
con.mvaddch(cy, margin, 16); con.curs_right()
print(' ')
con.color_pair(240,253) // body: black text, white back
print(line)
con.color_pair(255,253)
print(' ')
con.addch(17); println()
})
con.reset_graphics()
}
else {
println()
println(motd)
let lines = ts.typeset(motd, width)
lines.forEach(line => println(line))
}
println()

View File

@@ -0,0 +1,956 @@
/**
* Hopper is a package manager for TVDOS
* Created by CuriousTorvald on 2026-04-16
*/
const SYSTEM_PACKEAGE_DEF_DIR = "A:/tvdos/hopper"
const USER_BASE_DIR = "A:/hopper"
const USER_PACKAGE_DEF_DIR = `${USER_BASE_DIR}/manifests`
const USER_PACKAGE_BIN_DIR = `${USER_BASE_DIR}/bin`
const USER_PACKAGE_INCLUDE_DIR = `${USER_BASE_DIR}/include`
const MANIFEST_EXT = "hop.per"
const MIRROR_LIST_PATH = `${SYSTEM_PACKEAGE_DEF_DIR}/mirrors.list`
const net = require("A:/tvdos/include/net.mjs")
// SYNOPSIS
// hopper {search,se} [--provides, --requires, --description, --author] query
//// default searches from ProperName
// hopper {install,in} query [-v version]
// hopper {remove,rm} query
// ============================================================
// Manifest parsing
// ============================================================
function splitList(s) {
if (!s) return []
return s.split(";").map(it => it.trim()).filter(it => it.length > 0)
}
function parseManifest(text) {
const m = {}
text.split("\n").forEach(rawLine => {
const line = rawLine.replace(/\r$/, "")
if (line.length === 0) return
const idx = line.indexOf(":")
if (idx < 0) return
const key = line.substring(0, idx).trim()
const value = line.substring(idx + 1).trim()
m[key] = value
})
return m
}
function readManifestFile(path) {
const f = files.open(path)
if (!f.exists || f.isDirectory) return undefined
const m = parseManifest(f.sread())
m._manifestPath = path
return m
}
function _listManifestsFrom(dirPath, origin) {
const dir = files.open(dirPath)
if (!dir.exists || !dir.isDirectory) return []
const out = []
dir.list().forEach(entry => {
if (entry.isDirectory) return
if (!entry.name.toLowerCase().endsWith(MANIFEST_EXT)) return
const m = readManifestFile(entry.fullPath)
if (m !== undefined) {
m._origin = origin
out.push(m)
}
})
return out
}
// System packages (shipped with TVDOS) live in SYSTEM_PACKAGE_DEF_DIR
// and are read-only as far as hopper is concerned. User packages,
// installed by `hopper install`, live under USER_PACKAGE_DEF_DIR. The
// resolver treats both as "installed", but the install/remove paths
// refuse to modify anything tagged `_origin === "system"`.
function listInstalledManifests() {
return _listManifestsFrom(SYSTEM_PACKEAGE_DEF_DIR, "system")
.concat(_listManifestsFrom(USER_PACKAGE_DEF_DIR, "user"))
}
function findInstalledManifest(name) {
// Prefer user-installed copy when a system package with the same name
// also exists -- but that combination is normally refused at install.
const userDirect = `${USER_PACKAGE_DEF_DIR}/${name}.${MANIFEST_EXT}`
let m = readManifestFile(userDirect)
if (m !== undefined) { m._origin = "user"; return m }
const sysDirect = `${SYSTEM_PACKEAGE_DEF_DIR}/${name}.${MANIFEST_EXT}`
m = readManifestFile(sysDirect)
if (m !== undefined) { m._origin = "system"; return m }
const all = listInstalledManifests()
for (let i = 0; i < all.length; i++) {
if ((all[i].HopperPackageName || "") === name) return all[i]
}
return undefined
}
// Yes/no prompt. Empty input falls back to `defaultYes`.
function confirm(prompt, defaultYes) {
const hint = defaultYes ? "[Y/n]" : "[y/N]"
print(`${prompt} ${hint} `)
const ans = (read() || "").trim().toLowerCase()
if (ans === "") return !!defaultYes
return ans === "y" || ans === "yes"
}
// ============================================================
// Install layout helpers
// ============================================================
//
// User-installed packages live under `A:/hopper/`. Files are routed
// by extension: `.mjs` includes go under `include/`, everything else
// (`.js`, `.alias`, `.lfs`, data blobs, ...) lands in `bin/`. The
// downloaded manifest is saved under `manifests/` with a
// `SystemPackagePath` field appended that lists the resulting paths.
// Strip query/fragment and take the last `/`-separated component of `url`.
function urlBasename(url) {
let s = String(url || "")
const qm = s.indexOf("?"); if (qm >= 0) s = s.substring(0, qm)
const hash = s.indexOf("#"); if (hash >= 0) s = s.substring(0, hash)
const slash = s.lastIndexOf("/")
return (slash < 0) ? s : s.substring(slash + 1)
}
function routeForBasename(name) {
return (String(name || "").toLowerCase().endsWith(".mjs"))
? USER_PACKAGE_INCLUDE_DIR
: USER_PACKAGE_BIN_DIR
}
// Convert a USER_BASE_DIR-relative absolute path ("A:/hopper/bin/foo.js")
// into its declarable form ("/hopper/bin/foo.js"), matching the
// `SystemPackagePath` convention used by the system manifests.
function declarablePath(absPath) {
let p = String(absPath || "").replace(/\\/g, "/")
if (/^[A-Za-z]:/.test(p)) p = p.substring(2)
return p
}
// Parse PackageFileList (semicolon-separated full URLs) into a list of
// download descriptors: { url, basename, localPath }.
function parsePackageFileList(s) {
const out = []
splitList(s || "").forEach(url => {
const base = urlBasename(url)
if (base.length === 0) return
const dir = routeForBasename(base)
out.push({ url: url, basename: base, localPath: `${dir}/${base}` })
})
return out
}
function ensureUserDirs() {
[USER_BASE_DIR, USER_PACKAGE_BIN_DIR, USER_PACKAGE_INCLUDE_DIR, USER_PACKAGE_DEF_DIR].forEach(p => {
const d = files.open(p)
if (!d.exists) d.mkDir()
})
}
// Re-emit a parsed manifest, preserving insertion order, dropping
// internal `_*` keys, and replacing any pre-existing SystemPackagePath
// with the locally-computed one so the field always reflects what is
// actually on disk.
function serializeManifest(manifestObj, installedPathStr) {
const lines = []
Object.keys(manifestObj).forEach(k => {
if (k.length > 0 && k[0] === "_") return
if (k === "SystemPackagePath") return
lines.push(`${k}:${manifestObj[k]}`)
})
lines.push(`SystemPackagePath:${installedPathStr}`)
return lines.join("\n") + "\n"
}
// Delete every file declared in `manifest.SystemPackagePath` plus the
// manifest file itself. Wildcards are expanded via `expandSystemPath`.
function deleteInstalledFiles(manifest) {
const removed = []
splitList(manifest.SystemPackagePath || "").forEach(p => {
expandSystemPath(p).forEach(abs => {
const fd = files.open(abs)
if (!fd.exists) return
try { fd.remove(); removed.push(abs) }
catch (e) { printerrln(` ! failed to remove ${abs}: ${e}`) }
})
})
if (manifest._manifestPath) {
const mfd = files.open(manifest._manifestPath)
if (mfd.exists) {
try { mfd.remove(); removed.push(manifest._manifestPath) }
catch (e) { printerrln(` ! failed to remove ${manifest._manifestPath}: ${e}`) }
}
}
return removed
}
// ============================================================
// SemVer (strict X.Y.Z) and constraint matching
// ============================================================
//
// Versions are strict Semantic Versioning: three non-negative integer
// components MAJOR.MINOR.PATCH. No pre-release / build metadata.
//
// Constraint grammar (intentionally small, expandable later):
// * any version
// X.* major X, any minor/patch
// X.Y.* major X, minor Y, any patch
// X.Y.Z exact
// ^X.Y.Z >= X.Y.Z and < (X+1).0.0 (major-compatible)
// ~X.Y.Z >= X.Y.Z and < X.(Y+1).0 (minor-compatible)
// >=X.Y.Z / >X.Y.Z / <=X.Y.Z / <X.Y.Z / =X.Y.Z
//
// Multiple comma-separated constraints are AND-ed: "^1.2.0,<1.5.0".
function parseVersion(v) {
const m = String(v || "0.0.0").trim().match(/^(\d+)\.(\d+)\.(\d+)$/)
if (!m) return [0, 0, 0]
return [parseInt(m[1], 10), parseInt(m[2], 10), parseInt(m[3], 10)]
}
function compareVersion(a, b) {
const A = parseVersion(a), B = parseVersion(b)
for (let i = 0; i < 3; i++) {
if (A[i] !== B[i]) return (A[i] < B[i]) ? -1 : 1
}
return 0
}
function _matchSingleConstraint(version, c) {
c = c.trim()
if (c === "" || c === "*") return true
// Operator form: ^, ~, >=, <=, >, <, =
let opMatch = c.match(/^(\^|~|>=|<=|>|<|=)\s*(\d+\.\d+\.\d+)$/)
if (opMatch) {
const op = opMatch[1]
const target = opMatch[2]
const cmp = compareVersion(version, target)
const [tM, tm] = parseVersion(target)
switch (op) {
case "=": return cmp === 0
case ">": return cmp > 0
case ">=": return cmp >= 0
case "<": return cmp < 0
case "<=": return cmp <= 0
case "^": return cmp >= 0 && compareVersion(version, `${tM + 1}.0.0`) < 0
case "~": return cmp >= 0 && compareVersion(version, `${tM}.${tm + 1}.0`) < 0
}
}
// Wildcard form: X.*, X.Y.*, X.x, X.Y.x, or exact X.Y.Z
const parts = c.split(".")
const vparts = parseVersion(version)
for (let i = 0; i < parts.length && i < 3; i++) {
if (parts[i] === "*" || parts[i] === "x" || parts[i] === "X") return true
const expected = parseInt(parts[i], 10)
if (isNaN(expected) || vparts[i] !== expected) return false
}
// All listed parts matched literally; remaining parts (if any) must be 0
for (let i = parts.length; i < 3; i++) {
if (vparts[i] !== 0) return false
}
return true
}
function satisfies(version, constraint) {
if (!constraint) return true
return constraint.split(",").every(c => _matchSingleConstraint(version, c))
}
function parseRequires(s) {
const out = []
splitList(s || "").forEach(entry => {
// "<name>" or "<name> <constraint>"
const idx = entry.search(/\s+/)
if (idx < 0) {
out.push({ name: entry, constraint: "*" })
} else {
out.push({ name: entry.substring(0, idx), constraint: entry.substring(idx + 1).trim() })
}
})
return out
}
// HopperProvides entries are "<name>" or "<name> <version>". A bare name
// falls back to the package's own HopperPackageVersion — the same idea
// as RPM's `Provides: aalib = 1.2.0` (where the package's real name and
// version may differ from the virtual identity it exposes).
function parseProvides(s, fallbackVersion) {
const out = []
splitList(s || "").forEach(entry => {
const idx = entry.search(/\s+/)
if (idx < 0) {
out.push({ name: entry, version: fallbackVersion })
} else {
const v = entry.substring(idx + 1).trim()
out.push({ name: entry.substring(0, idx), version: v || fallbackVersion })
}
})
return out
}
// Look up the version a candidate exposes for `name`. If `name` matches
// the package's own name (or isn't declared in HopperProvides at all),
// returns the package's own version.
function providedVersionOf(candidate, name) {
if (candidate.provides) {
for (let i = 0; i < candidate.provides.length; i++) {
if (candidate.provides[i].name === name) return candidate.provides[i].version
}
}
return candidate.version
}
// ============================================================
// Candidate index (installed + upstream)
// ============================================================
function _manifestToCandidate(m, source) {
const name = m.HopperPackageName || ""
const version = m.HopperPackageVersion || "0.0.0"
const provides = parseProvides(m.HopperProvides || "", version)
// Every package implicitly provides itself at its own version. Only
// synthesise this when the manifest didn't declare it explicitly.
if (name && !provides.some(p => p.name === name)) {
provides.unshift({ name: name, version: version })
}
return {
name: name,
version: version,
requires: parseRequires(m.HopperRequires || ""),
provides: provides,
source: source, // "installed" | "upstream"
manifest: m
}
}
// Returns map: packageName -> array<Candidate>
function buildCandidateIndex() {
const idx = new Map()
function add(c) {
if (!idx.has(c.name)) idx.set(c.name, [])
// De-dupe (name+version+source)
const arr = idx.get(c.name)
if (arr.some(x => x.version === c.version && x.source === c.source)) return
arr.push(c)
}
listInstalledManifests().forEach(m => add(_manifestToCandidate(m, "installed")))
fetchRemoteCandidates().forEach(m => add(_manifestToCandidate(m, "upstream")))
return idx
}
// Anything that satisfies a requirement on `name`: a package whose own
// HopperPackageName matches OR whose HopperProvides declares `name`.
// Each candidate now carries `provides` as {name, version} pairs; the
// package's own (name, version) is always present (see
// _manifestToCandidate), so a single pass over `provides` is enough.
function findProviders(idx, name) {
const out = []
const seen = new Set()
idx.forEach(candidates => {
candidates.forEach(c => {
if (seen.has(c)) return
if (c.provides.some(p => p.name === name)) {
out.push(c)
seen.add(c)
}
})
})
return out
}
// Sort: installed first (no churn), then highest version, then upstream order.
function sortCandidates(cands) {
return cands.slice().sort((a, b) => {
if (a.source !== b.source) return (a.source === "installed") ? -1 : 1
return -compareVersion(a.version, b.version)
})
}
// ============================================================
// Resolver (snapshot-based backtracking; precursor to a SAT solver)
// ============================================================
//
// State: chosen :: Map<packageName, Candidate>
// At every choice point we snapshot the whole map so that backtracking
// also undoes any transitive picks. The candidate ordering encodes the
// preference policy:
//
// 1. Keep installed if it satisfies the constraint.
// 2. Otherwise pick the newest upstream version that satisfies.
// 3. If newer versions cause downstream conflicts, walk older versions
// (downgrade) until either something fits or candidates are exhausted.
//
// The structure is intentionally close to DPLL: each "decision" is the
// candidate we assign to a variable, and "unit propagation" is the
// recursive resolve() call over each requirement. Replacing this with
// clause learning / a watched-literals scheme later would be local.
function resolveAll(idx, requirements) {
const chosen = new Map()
const issues = []
function snapshot() { return new Map(chosen) }
function restore(snap) { chosen.clear(); snap.forEach((v, k) => chosen.set(k, v)) }
function _resolve(reqName, constraint, trail) {
const existing = chosen.get(reqName)
if (existing !== undefined) {
const v = providedVersionOf(existing, reqName)
return satisfies(v, constraint)
? { ok: true }
: { ok: false, reason: `${reqName} pinned to ${v}, but ${trail.join(" -> ")} requires ${constraint}` }
}
const providers = findProviders(idx, reqName)
if (providers.length === 0) {
return { ok: false, reason: `no package provides "${reqName}" (required by ${trail.join(" -> ") || "<root>"})` }
}
// Satisfaction checks the virtual version the candidate exposes
// for `reqName` (HopperProvides), not necessarily the package's
// own HopperPackageVersion.
const matching = sortCandidates(providers.filter(c => satisfies(providedVersionOf(c, reqName), constraint)))
if (matching.length === 0) {
const versions = providers.map(p => `${providedVersionOf(p, reqName)}[${p.source}]`).join(", ")
return { ok: false, reason: `no version of "${reqName}" satisfies ${constraint} (available: ${versions})` }
}
let lastReason = null
for (let i = 0; i < matching.length; i++) {
const cand = matching[i]
const snap = snapshot()
chosen.set(cand.name, cand)
let allOk = true
const subTrail = trail.concat([`${cand.name}@${cand.version}`])
for (let j = 0; j < cand.requires.length; j++) {
const req = cand.requires[j]
const r = _resolve(req.name, req.constraint, subTrail)
if (!r.ok) {
allOk = false
lastReason = r.reason
break
}
}
if (allOk) return { ok: true }
restore(snap)
}
return { ok: false, reason: lastReason || `no working candidate for "${reqName}"` }
}
requirements.forEach(req => {
const r = _resolve(req.name, req.constraint, [])
if (!r.ok) issues.push(r.reason)
})
return { chosen, issues }
}
// Compare resolved assignment against currently-installed state.
function classifyPlan(idx, chosen) {
const installedByName = new Map()
listInstalledManifests().forEach(m => installedByName.set(m.HopperPackageName, m))
const actions = []
chosen.forEach((cand, name) => {
const inst = installedByName.get(name)
if (cand.source === "installed") {
actions.push({ action: "keep", name, version: cand.version })
}
else if (inst === undefined) {
actions.push({ action: "install", name, version: cand.version })
}
else {
const cmp = compareVersion(cand.version, inst.HopperPackageVersion)
if (cmp > 0) actions.push({ action: "upgrade", name, from: inst.HopperPackageVersion, to: cand.version })
else if (cmp < 0) actions.push({ action: "downgrade", name, from: inst.HopperPackageVersion, to: cand.version })
else actions.push({ action: "reinstall", name, version: cand.version })
}
})
return actions
}
function printPlan(actions, target) {
const changing = actions.filter(a => a.action !== "keep")
if (changing.length === 0) {
println(`Nothing to do: ${target} is already installed and satisfied.`)
return
}
println("Plan:")
changing.forEach(a => {
switch (a.action) {
case "install": println(` + install ${a.name} ${a.version}`); break
case "upgrade": println(` ^ upgrade ${a.name} ${a.from} -> ${a.to}`); break
case "downgrade": println(` v downgrade ${a.name} ${a.from} -> ${a.to}`); break
case "reinstall": println(` = reinstall ${a.name} ${a.version}`); break
}
})
}
// ============================================================
// Remote mirrors
// ============================================================
//
// `mirrors.list` lives next to the installed package manifests.
// Each non-empty, non-`#` line is the URL prefix of a Hopper mirror.
// The mirror MUST expose `<prefix>mirror_manifest` (key:value pairs
// describing the mirror) and `<prefix>filelist` (CSV with rows of
// `packagename,version,hoppermanifest-filename`).
//
// Trailing slash on the prefix is optional and will be added if missing.
function loadMirrorList() {
const f = files.open(MIRROR_LIST_PATH)
if (!f.exists || f.isDirectory) return []
return f.sread().split("\n")
.map(line => line.replace(/\r$/, "").trim())
.filter(line => line.length > 0 && line[0] !== "#")
.map(line => line.endsWith("/") ? line : (line + "/"))
}
function parseFileList(text) {
const out = []
text.split("\n").forEach(raw => {
const line = raw.replace(/\r$/, "").trim()
if (line.length === 0 || line[0] === "#") return
const parts = line.split(",")
if (parts.length < 3) return
out.push({
name: parts[0].trim(),
version: parts[1].trim(),
file: parts[2].trim(),
})
})
return out
}
function fetchManifestsFromMirror(prefix) {
const mfText = net.fetchText(prefix + "mirror_manifest")
if (mfText === null) {
printerrln(` ! could not reach mirror: ${prefix}`)
return []
}
const mirror = parseManifest(mfText)
const mirrorName = mirror.HopperMirrorName || prefix
const flText = net.fetchText(prefix + "filelist")
if (flText === null) {
printerrln(` ! mirror "${mirrorName}" has no filelist`)
return []
}
const out = []
parseFileList(flText).forEach(entry => {
const manifestText = net.fetchText(prefix + entry.file)
if (manifestText === null) {
printerrln(` ! mirror "${mirrorName}" missing ${entry.file}`)
return
}
const m = parseManifest(manifestText)
m._mirrorName = mirrorName
m._mirrorPrefix = prefix
m._manifestUrl = prefix + entry.file
out.push(m)
})
return out
}
// Per-invocation memoisation. Search and install both pull the same
// data; we only want to hit the network once per `hopper ...` call.
let _remoteCache = null
function fetchRemoteCandidates() {
if (_remoteCache !== null) return _remoteCache
const mirrors = loadMirrorList()
if (mirrors.length === 0) {
_remoteCache = []
return _remoteCache
}
if (!net.isAvailable()) {
printerrln("Warning: no HTTP modem attached; remote mirrors will be skipped.")
_remoteCache = []
return _remoteCache
}
const out = []
mirrors.forEach(prefix => {
fetchManifestsFromMirror(prefix).forEach(m => out.push(m))
})
_remoteCache = out
return _remoteCache
}
// ============================================================
// Search
// ============================================================
function fieldCandidates(manifest, field) {
switch (field) {
case "provides": return splitList(manifest.HopperProvides || "")
case "requires": return splitList(manifest.HopperRequires || "")
case "description": return [manifest.ProperDescription || ""]
case "author": return [manifest.ProperAuthor || ""]
default: return [manifest.ProperName || "", manifest.HopperPackageName || ""]
}
}
function matchesQuery(manifest, field, query) {
const q = query.toLowerCase()
return fieldCandidates(manifest, field).some(c => c.toLowerCase().indexOf(q) >= 0)
}
function printSearchResult(m, origin) {
const name = m.ProperName || m.HopperPackageName || "(unnamed)"
const ver = m.HopperPackageVersion || "?"
println(` [${origin}] ${name} -- ${m.HopperPackageName} ${ver}`)
if (m.ProperDescription) println(` ${m.ProperDescription}`)
}
function cmdSearch(args) {
let field = "name"
let query = undefined
for (let i = 0; i < args.length; i++) {
const a = args[i]
if (a === "--provides") field = "provides"
else if (a === "--requires") field = "requires"
else if (a === "--description") field = "description"
else if (a === "--author") field = "author"
else if (a.startsWith("--")) { printerrln(`Unknown option: ${a}`); return 1 }
else query = a
}
if (query === undefined) {
printerrln("Usage: hopper search [--provides|--requires|--description|--author] <query>")
return 1
}
println(`Searching installed packages in ${SYSTEM_PACKEAGE_DEF_DIR} ...`)
const sysHits = listInstalledManifests().filter(m => matchesQuery(m, field, query))
if (sysHits.length === 0) println(" (no matches)")
else sysHits.forEach(m => printSearchResult(m, "installed"))
println("")
println("Searching remote mirrors ...")
const remote = fetchRemoteCandidates()
if (remote.length === 0) {
println(" (no mirrors configured or reachable)")
}
else {
const netHits = remote.filter(m => matchesQuery(m, field, query))
if (netHits.length === 0) println(" (no matches)")
else netHits.forEach(m => printSearchResult(m, m._mirrorName || "remote"))
}
return 0
}
// ============================================================
// Install
// ============================================================
//
// Each upstream manifest declares its payload via `PackageFileList`,
// a semicolon-separated list of full URLs. Hopper fetches each URL and
// drops the result in /hopper/bin (default) or /hopper/include (.mjs).
// The locally-saved manifest gets a `SystemPackagePath` field appended
// listing the resulting absolute paths, which is what `cmdRemove` later
// walks to clean up.
function _installOne(action, candidate) {
const m = candidate.manifest
const files_ = parsePackageFileList(m.PackageFileList)
if (files_.length === 0) {
printerrln(` ! ${candidate.name}: upstream manifest has no PackageFileList; cannot install`)
return false
}
// Fetch first, write second: a single 404 should not leave a
// half-installed package behind.
const fetched = []
for (let i = 0; i < files_.length; i++) {
const f = files_[i]
println(` fetch ${f.url}`)
const body = net.fetchText(f.url)
if (body === null || body === undefined) {
printerrln(` ! failed to fetch ${f.url}`)
return false
}
fetched.push({ entry: f, body: body })
}
// If we are replacing an existing user-installed copy, remove its
// old files first so a renamed payload doesn't leave orphans.
if (action !== "install") {
const oldManifestPath = `${USER_PACKAGE_DEF_DIR}/${candidate.name}.${MANIFEST_EXT}`
const old = readManifestFile(oldManifestPath)
if (old !== undefined) {
splitList(old.SystemPackagePath || "").forEach(p => {
expandSystemPath(p).forEach(abs => {
const fd = files.open(abs)
if (fd.exists) {
try { fd.remove() }
catch (e) { printerrln(` ! could not remove old ${abs}: ${e}`) }
}
})
})
}
}
// Write payload files.
fetched.forEach(item => {
const fd = files.open(item.entry.localPath)
if (!fd.exists) fd.mkFile()
fd.swrite(item.body)
println(` write ${item.entry.localPath}`)
})
// Save the manifest with SystemPackagePath appended.
const sysPath = fetched.map(item => declarablePath(item.entry.localPath)).join(";")
const manifestPath = `${USER_PACKAGE_DEF_DIR}/${candidate.name}.${MANIFEST_EXT}`
const mfd = files.open(manifestPath)
if (!mfd.exists) mfd.mkFile()
mfd.swrite(serializeManifest(m, sysPath))
println(` write ${manifestPath}`)
return true
}
function cmdInstall(args) {
let query = undefined
let version = undefined
for (let i = 0; i < args.length; i++) {
if (args[i] === "-v") { version = args[i + 1]; i++ }
else if (args[i].startsWith("--")) { printerrln(`Unknown option: ${args[i]}`); return 1 }
else query = args[i]
}
if (query === undefined) {
printerrln("Usage: hopper install <package> [-v <version>]")
return 1
}
const targetConstraint = version || "*"
const verSuffix = (targetConstraint !== "*") ? ` (${targetConstraint})` : ""
println(`Resolving ${query}${verSuffix} ...`)
const idx = buildCandidateIndex()
// Sanity check: target must exist in the index (installed or upstream).
if (findProviders(idx, query).length === 0) {
printerrln(`Error: package "${query}" not found (not on upstream, not installed).`)
return 4
}
// Seed order matters: the target goes FIRST so its (possibly tight)
// constraints can drive upgrades of dependencies. The installed-set
// requirements follow at "*" so the resolver still has to keep them
// alive (preferring installed candidates when their version still fits,
// otherwise upgrading or downgrading them).
const seed = [{ name: query, constraint: targetConstraint }]
listInstalledManifests().forEach(m => {
if (m.HopperPackageName === query) return
seed.push({ name: m.HopperPackageName, constraint: "*" })
})
const { chosen, issues } = resolveAll(idx, seed)
if (issues.length > 0) {
printerrln("Resolution failed:")
issues.forEach(reason => printerrln(` - ${reason}`))
printerrln("")
printerrln("No solution found -- not installable.")
return 3
}
const plan = classifyPlan(idx, chosen)
printPlan(plan, query)
const changing = plan.filter(a => a.action !== "keep")
if (changing.length === 0) return 0
// Pre-flight: refuse to clobber system packages, and require every
// upstream candidate to actually carry a payload list.
const blockers = []
changing.forEach(a => {
const cand = chosen.get(a.name)
const inst = findInstalledManifest(a.name)
if (inst && inst._origin === "system") {
blockers.push(`${a.name}: cannot ${a.action} -- a system package with that name is already installed`)
}
if (cand && cand.source === "upstream" && !(cand.manifest.PackageFileList && cand.manifest.PackageFileList.length > 0)) {
blockers.push(`${a.name}: upstream manifest declares no PackageFileList`)
}
})
if (blockers.length > 0) {
printerrln("Cannot proceed:")
blockers.forEach(b => printerrln(` - ${b}`))
return 5
}
if (!net.isAvailable()) {
printerrln("No HTTP modem attached; cannot fetch package files.")
return 6
}
println("")
if (!confirm("Proceed with installation?", true)) {
println("Aborted.")
return 0
}
ensureUserDirs()
let failed = 0
for (let i = 0; i < changing.length; i++) {
const a = changing[i]
const cand = chosen.get(a.name)
if (a.action === "install" || a.action === "reinstall") {
println(`${a.action} ${a.name} ${a.version}`)
} else {
println(`${a.action} ${a.name} ${a.from} -> ${a.to}`)
}
if (!_installOne(a.action, cand)) {
failed++
printerrln(` ! ${a.name}: aborted`)
break
}
}
if (failed > 0) {
printerrln(`${failed} package(s) failed to install.`)
return 7
}
println("Done.")
return 0
}
// ============================================================
// Remove
// ============================================================
// Convert a SystemPackagePath entry (e.g. "/tvdos/bin/taut*") into a
// concrete list of files on the A: drive. Supports a simple '*' wildcard
// in the filename component.
function expandSystemPath(pattern) {
const sysDrive = "A:"
if (pattern.indexOf("*") < 0) {
return [`${sysDrive}${pattern}`]
}
const fwd = pattern.lastIndexOf("/")
const bck = pattern.lastIndexOf("\\")
const lastSep = Math.max(fwd, bck)
const dirPart = (lastSep < 0) ? "" : pattern.substring(0, lastSep)
const namePart = (lastSep < 0) ? pattern : pattern.substring(lastSep + 1)
const dir = files.open(`${sysDrive}${dirPart}/`)
if (!dir.exists || !dir.isDirectory) return []
const escaped = namePart.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")
const re = new RegExp(`^${escaped}$`, "i")
const out = []
dir.list().forEach(entry => {
if (entry.isDirectory) return
if (re.test(entry.name)) out.push(entry.fullPath)
})
return out
}
function cmdRemove(args) {
const query = args[0]
if (query === undefined) {
printerrln("Usage: hopper remove <package>")
return 1
}
const m = findInstalledManifest(query)
if (m === undefined) {
printerrln(`Package not installed: ${query}`)
return 2
}
if (m._origin === "system") {
printerrln(`Cannot remove ${query}: it is a system package.`)
return 6
}
const name = m.ProperName || m.HopperPackageName || query
const ver = m.HopperPackageVersion || "?"
println(`Preparing removal of ${name} (${m.HopperPackageName} ${ver}) ...`)
const paths = splitList(m.SystemPackagePath || "")
println("")
println("The following files will be deleted:")
if (paths.length === 0) {
println(" (manifest declares no files)")
}
paths.forEach(p => {
const expanded = expandSystemPath(p)
if (expanded.length === 0) {
println(` (no match on disk) ${p}`)
}
else {
expanded.forEach(e => println(` ${e}`))
}
})
println(` ${m._manifestPath}`)
println("")
if (!confirm("Proceed with removal?", false)) {
println("Aborted.")
return 0
}
const removed = deleteInstalledFiles(m)
removed.forEach(p => println(` removed ${p}`))
if (removed.length === 0) println(" (nothing was removed)")
return 0
}
// ============================================================
// Dispatch
// ============================================================
function printUsage() {
println("Hopper - Package manager for TVDOS")
println("")
println("Usage:")
println(" hopper {search,se} [--provides|--requires|--description|--author] <query>")
println(" hopper {install,in} <package> [-v <version>]")
println(" hopper {remove,rm} <package>")
}
const _hopperArgs = (typeof exec_args !== "undefined" && exec_args) ? exec_args.slice(1) : []
const _hopperCmd = _hopperArgs[0]
const _hopperRest = _hopperArgs.slice(1)
switch (_hopperCmd) {
case "search":
case "se":
return cmdSearch(_hopperRest)
case "install":
case "in":
return cmdInstall(_hopperRest)
case "remove":
case "rm":
return cmdRemove(_hopperRest)
case undefined:
printUsage()
return 0
default:
printerrln(`Unknown command: ${_hopperCmd}`)
printUsage()
return 1
}

View File

@@ -15,7 +15,10 @@ Uint16 Encoding
10 00 : UTF-8
10 01 : UTF-16BE
10 02 : UTF-16LE
Byte[5] Padding
Byte Flags
0b 0000 000r
r: path is relative
Bytes[4] Reserved
# FileBlocks
Uint8 File type (only 1 is used)
@@ -28,27 +31,36 @@ instead of compressing individual files)
function printUsage() {
println(`Collects files under a directory into a single archive.
Usage: lfs [-c/-x/-t] dest.lfs path\\to\\source
Usage: lfs [-c/-x/-t] [-r] dest.lfs path\\to\\source
To collect a directory into myarchive.lfs:
lfs -c myarchive.lfs path\\to\\directory
To collect a directory into myarchive.lfs, using relative path:
lfs -c -r myarchive.lfs path\\to\\directory
To extract an archive to path\\to\\my\\files:
lfs -x myarchive.lfs path\\to\\my\\files
To list the collected files:
lfs -t myarchive.lfs`)
}
let option = exec_args[1]
const lfsPath = exec_args[2]
const dirPath = exec_args[3]
let option = undefined
let useRelative = false
const positional = []
for (let i = 1; i < exec_args.length; i++) {
const a = exec_args[i]
if (a === undefined) continue
const au = a.toUpperCase()
if (au === "-C" || au === "-X" || au === "-T") option = au
else if (au === "-R") useRelative = true
else positional.push(a)
}
const lfsPath = positional[0]
const dirPath = positional[1]
if (option === undefined || lfsPath === undefined || option.toUpperCase() != "-T" && dirPath === undefined) {
if (option === undefined || lfsPath === undefined || (option != "-T" && dirPath === undefined)) {
printUsage()
return 0
}
option = option.toUpperCase()
function recurseDir(file, action) {
if (!file.isDirectory) {
@@ -76,13 +88,14 @@ if ("-C" == option) {
return 1
}
let out = "TVDOSLFS\x01\x00\x00\x00\x00\x00\x00\x00"
const flagsByte = useRelative ? 0x01 : 0x00
let out = "TVDOSLFS\x01\x00\x00" + String.fromCharCode(flagsByte) + "\x00\x00\x00\x00"
const rootDirPathLen = rootDir.fullPath.length
recurseDir(rootDir, file=>{
let f = files.open(file.fullPath)
let flen = f.size
let fname = file.fullPath.substring(rootDirPathLen + 1)
let fname = useRelative ? file.fullPath.substring(rootDirPathLen + 1) : file.fullPath
let plen = fname.length
out += "\x01" + String.fromCharCode(
@@ -116,6 +129,8 @@ else if ("-T" == option || "-X" == option) {
return 2
}
const archiveRelative = (bytes.charCodeAt(11) & 0x01) !== 0
if ("-X" == option && !rootDir.exists) {
rootDir.mkDir()
}
@@ -132,9 +147,12 @@ else if ("-T" == option || "-X" == option) {
if ("-X" == option) {
let filebytes = bytes.substring(curs, curs + filelen)
let outfile = files.open(`${rootDir.fullPath}\\${path}`)
// Fully qualified paths (e.g. "A:\foo\bar.txt") get their drive prefix
// stripped so the archive contents re-root under the destination dir.
let subPath = archiveRelative ? path : path.replace(/^[A-Za-z]:[\\\/]?/, "")
let outfile = files.open(`${rootDir.fullPath}\\${subPath}`)
mkDirs(files.open(`${rootDir.driveLetter}:${files.open(`${rootDir.fullPath}\\${path}`).parentPath}`))
mkDirs(files.open(`${outfile.driveLetter}:${outfile.parentPath}`))
outfile.mkFile()
outfile.swrite(filebytes)
}

File diff suppressed because it is too large Load Diff

View File

@@ -2297,7 +2297,7 @@ function ordersInput(wo, event) {
// PATTERN EDITOR PANEL
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Returns the visual width of a TSVM string (handles „Nnu escape sequences)
// Returns the visual width of a TSVM string (handles \u0084Nnu escape sequences)
function visWidth(s) {
let w = 0, i = 0
while (i < s.length) {
@@ -3781,7 +3781,6 @@ function openFlagsPopup() {
while (!done) {
input.withEvent(ev => {
if (ev[0] !== 'key_down') return
if (1 !== ev[2]) return
const ks = ev[1]
if (eventJustReceived) { eventJustReceived = false; return }

View File

@@ -1,6 +1,8 @@
if (!_G.TAUT) _G.TAUT = {};
let help = {}
let ts = require("typesetter")
////////////////////////////////////////////////////////////////////////////////////////////////////
/*
@@ -90,7 +92,7 @@ Timeline has two distinct modes: view and edit mode. Two modes are toggled using
&bul;<b>W</b>&mdot;<b>E</b>&mdot;<b>R</b> : <O>toggles timeline view mode. W-most detailed, R-most abridged</O>
&bul;<b>n</b> : <O>toggles soloing of the selected voice</O>
&bul;<b>m</b> : <O>toggles muting of the selected voice</O>
&bul;<b>[</b>&mdot;<b>]</b> : <O>changes tick rate of playhead</O>
&bul;<b>[</b>&mdot;<b>]</b> : <O>changes tick rate of playhead</O>
<b>&nbsp;EDIT MODE</b>
<b>\u00B7${'\u00B8'.repeat(9)}\u00B9</b>
@@ -143,259 +145,12 @@ Mixer flags define how should the mixer behave.
// assemble help text pieces to complete help message
const SCRW = con.getmaxyx()[1]
const HRULE = '\u00B4\u00B5'.repeat((_G.TAUT.HELPMSG_WIDTH) >>> 1) + '\n'
// Display-command palette. taut.js's popup uses (HELP_COL_TEXT on background) as the
// default colour pair, so embedded `\x1B[38;5;Nm` codes switch foreground only.
const HELP_COL_TEXT = 239 // popup body default (== colWHITE)
const HELP_COL_EMPH = 230 // <b>...</b> highlight (== colVoiceHdr)
const HELP_COL_BRAND = 211 // first half of "Microtone"
const HELP_COL_BRAND_DIM = 239 // second half of "Microtone"
const fgEsc = (n) => `\x1B[38;5;${n}m`
const ESC_DEFAULT = fgEsc(HELP_COL_TEXT)
const ESC_EMPH = fgEsc(HELP_COL_EMPH)
const MICROTONE = `${fgEsc(HELP_COL_BRAND)}Micro${fgEsc(HELP_COL_BRAND_DIM)}tone${ESC_DEFAULT}`
// Replace &xxx; entities with their final printable representations.
function expandEntities(s) {
return s
.replaceAll('&microtone;', MICROTONE)
.replaceAll('&bul;', '\u00F9')
.replaceAll('&ddot;', '\u008419u')
.replaceAll('&mdot;', '\u00FA')
.replaceAll('&updn;', '\u008418u')
.replaceAll('&udlr;', '\u008428u\u008429u')
.replaceAll('&keyoffsym;', '\u00A0\u00B1\u00B1\u00A1')
.replaceAll('&notecutsym;', '\u00A4\u00A4\u00A4\u00A4')
.replaceAll('&nbsp;', '\u007F')
.replaceAll('&shy;', '')
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replaceAll('&demisharp;', '\u0080\u0081')
.replaceAll('&sharp;', '\u0082\u0083')
.replaceAll('&sesquisharp;', '\u0084132u\u0085')
.replaceAll('&doublesharp;', '\u0086\u0087')
.replaceAll('&triplesharp;', '\u0088\u0089')
.replaceAll('&quadsharp;', '\u008A\u008B')
.replaceAll('&demiflat;', '\u008C\u008D')
.replaceAll('&flat;', '\u008E\u008F')
.replaceAll('&sesquiflat;', '\u0090\u0091')
.replaceAll('&doubleflat;', '\u0092\u0093')
.replaceAll('&tripleflat;', '\u0094\u0095')
.replaceAll('&quadflat;', '\u0096\u0097')
.replaceAll('&accuptick;', '\u009A')
.replaceAll('&accdntick;', '\u009B')
.replaceAll('&accupup;', '\u009C')
.replaceAll('&accdndn;', '\u009D')
}
// Tokenise a (post-entity-expansion) line. Returns an array of:
// {type:'word', text:String, w:int} - non-breakable run of visible chars (may carry ANSI escapes)
// {type:'sp'} - a single soft space (eligible for break/expansion)
// {type:'anchor', open:Boolean} - <o>/</o> markers (zero width)
//
// Width accounting:
// - ANSI escapes (`\x1B[...m`) : 0 visible chars
// - TSVM unicode escapes (`„..u`) : 1 visible char
// - non-breaking space ( ) : 1 visible char (consumed as part of a word)
// - soft hyphen (­) : dropped (not implemented as a break point)
// - everything else : 1 visible char
function tokenise(line) {
const tokens = []
let buf = ''
let bufW = 0
let i = 0
const flushWord = () => {
if (buf.length > 0) {
tokens.push({type: 'word', text: buf, w: bufW})
buf = ''
bufW = 0
}
}
while (i < line.length) {
// inline tags (case-sensitive for <b>, case-insensitive for <o>)
if (line.slice(i, i + 3) === '<b>') { buf += ESC_EMPH; i += 3; continue }
if (line.slice(i, i + 4) === '</b>') { buf += ESC_DEFAULT; i += 4; continue }
const head3 = line.slice(i, i + 3).toLowerCase()
const head4 = line.slice(i, i + 4).toLowerCase()
if (head3 === '<o>') { flushWord(); tokens.push({type: 'anchor', open: true}); i += 3; continue }
if (head4 === '</o>') { flushWord(); tokens.push({type: 'anchor', open: false}); i += 4; continue }
const c = line[i]
const cc = line.charCodeAt(i)
if (cc === 0x1B) {
// pre-existing ANSI escape - copy verbatim, zero visible width
const m = line.indexOf('m', i)
const end = (m < 0) ? line.length : m + 1
buf += line.slice(i, end)
i = end
}
else if (cc === 0x84) {
// TSVM „<digits>u escape - copy verbatim, one visible char
const u = line.indexOf('u', i)
const end = (u < 0) ? line.length : u + 1
buf += line.slice(i, end)
bufW += 1
i = end
}
else if (c === ' ') {
flushWord()
tokens.push({type: 'sp'})
i += 1
}
else if (cc === 0x00AD) {
// soft hyphen: drop (no break-point handling for now)
i += 1
}
else {
buf += c
bufW += 1
i += 1
}
}
flushWord()
return tokens
}
// Build wrapped lines from a token stream then format each one according to alignment.
// Returns an array of strings, each exactly `width` visible chars wide (padded with
// trailing spaces) so the caller can blit them without further math.
function wrapAndAlign(tokens, width, alignment) {
const lines = [] // each: {tokens, indent, contentW}
let curTokens = []
let curW = 0
let curIndent = 0
let nextIndent = 0 // indent the *next* flushed line should use
const flushLine = () => {
// strip trailing soft spaces
while (curTokens.length > 0 && curTokens[curTokens.length - 1].type === 'sp') {
curTokens.pop()
curW -= 1
}
lines.push({tokens: curTokens, indent: curIndent, contentW: curW})
curTokens = []
curW = 0
curIndent = nextIndent
}
for (const tok of tokens) {
if (tok.type === 'anchor') {
// anchor opens at the current visible column (accounting for indent)
if (tok.open) nextIndent = curIndent + curW
else nextIndent = 0
continue
}
if (tok.type === 'sp') {
// ignore leading soft spaces on a fresh line
if (curW === 0) continue
// hard wrap if the line is already at the right edge
if (curIndent + curW + 1 > width) { flushLine(); continue }
curTokens.push(tok)
curW += 1
continue
}
// word
const tw = tok.w
if (curIndent + curW + tw > width) {
flushLine()
// word too wide for the wrapped line: emit it on its own row (possibly clipped by terminal)
if (curIndent + tw > width) {
curTokens.push(tok)
curW += tw
flushLine()
continue
}
}
curTokens.push(tok)
curW += tw
}
if (curTokens.length > 0 || lines.length === 0) flushLine()
return lines.map((line, i) => formatLine(line, width, alignment, i === lines.length - 1))
}
function formatLine(line, totalWidth, alignment, isLast) {
if (line.tokens.length === 0) return ' '.repeat(totalWidth)
const indent = ' '.repeat(line.indent)
const remaining = totalWidth - line.indent - line.contentW
const pad = (n) => (n > 0) ? ' '.repeat(n) : ''
const flatText = () => line.tokens.map(t => (t.type === 'sp') ? ' ' : t.text).join('')
if (alignment === 'c') {
const left = remaining >> 1
return indent + pad(left) + flatText() + pad(remaining - left)
}
if (alignment === 'r') return indent + pad(remaining) + flatText()
if (alignment === 'l') return indent + flatText() + pad(remaining)
// justified: only expand spaces when there's slack and we're not on the
// last (or single) wrapped line
if (isLast || remaining <= 0) return indent + flatText() + pad(remaining)
const spaceCount = line.tokens.reduce((n, t) => n + (t.type === 'sp' ? 1 : 0), 0)
if (spaceCount === 0) return indent + flatText() + pad(remaining)
const baseExtra = (remaining / spaceCount) | 0
let leftover = remaining - baseExtra * spaceCount
let out = indent
for (const tok of line.tokens) {
if (tok.type === 'sp') {
const extra = baseExtra + (leftover > 0 ? 1 : 0)
if (leftover > 0) leftover -= 1
out += ' '.repeat(1 + extra)
} else {
out += tok.text
}
}
return out
}
// Process a single source line: peel a leading <c>/<r>/<l> alignment tag (if present),
// strip its matching close tag, then tokenise + wrap.
function typesetSourceLine(line, width) {
if (line.length === 0) return [' '.repeat(width)]
let alignment = 'j' // justified default
const startMatch = line.match(/^<([crl])>/i)
if (startMatch) {
alignment = startMatch[1].toLowerCase()
line = line.slice(startMatch[0].length)
const closeRe = new RegExp(`</${alignment}>$`, 'i')
line = line.replace(closeRe, '')
}
const tokens = tokenise(line)
return wrapAndAlign(tokens, width, alignment)
}
function typesetText(text, width) {
text = expandEntities(text)
const out = []
for (const srcLine of text.split('\n')) {
for (const outLine of typesetSourceLine(srcLine, width)) out.push(outLine)
}
return out
}
function typeset(text, customWidth) {
let typesetWidth = customWidth
if (typesetWidth === undefined) typesetWidth = _G.TAUT.HELPMSG_WIDTH
if (typesetWidth === undefined) {
const currentPosX = con.getyx()[1] // 1-indexed
typesetWidth = SCRW - currentPosX + 1
}
return typesetText(text, typesetWidth)
// taut.js's popup uses (HELP_COL_TEXT on background) as the default colour pair.
// The shared typesetter module owns the palette and the markup expander.
function typeset(text) {
return ts.typeset(text, _G.TAUT.HELPMSG_WIDTH)
}
let helpMessages = [ // index: taut.js PANEL_NAMES
@@ -410,7 +165,7 @@ let helpMessages = [ // index: taut.js PANEL_NAMES
help.MSG_BY_TABS = helpMessages.map(it => typeset(it))
help.typeset = typeset
help.COL_TEXT = HELP_COL_TEXT
help.COL_EMPH = HELP_COL_EMPH
help.COL_TEXT = ts.COL_TEXT
help.COL_EMPH = ts.COL_EMPH
if (!_G.TAUT.HELPMSG) _G.TAUT.HELPMSG=help;

View File

@@ -66,7 +66,7 @@ const EXEC_FUNS = {
"txt": (f) => _G.shell.execute(`less "${f}"`),
"md": (f) => _G.shell.execute(`less "${f}"`),
"log": (f) => _G.shell.execute(`less "${f}"`),
"taud": (f) => _G.shell.execute(`microtone "${f}"`),
"taud": (f) => _G.shell.execute(`playtaud "${f}"`),
}
function makeExecFun(template) {

View File

@@ -0,0 +1,11 @@
HopperManifestVersion:1
HopperPackageName:getopt
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:getopt;
HopperRequires:
ProperName:getopt.js
ProperAuthor:David Pacheco
ProperDescription:node.js implementation of POSIX getopt() (and then some)
Licence:MIT
SystemPackagePath:/tvdos/include/getopt.mjs

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:libfs
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:libfs;
HopperRequires:tvdos 1.*;
ProperName:LibFS
ProperAuthor:CuriousTorvald
ProperDescription:NodeJS-compatible Filesystem module for TVDOS
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/include/fs.mjs

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:libgl
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:libgl;
HopperRequires:
ProperName:LibGL
ProperAuthor:CuriousTorvald
ProperDescription:TVDOS Graphics Library
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/include/gl.mjs

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:libpcm
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:libpcm;
HopperRequires:
ProperName:LibPCM
ProperAuthor:CuriousTorvald
ProperDescription:PCM decoder for TSVM
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/include/pcm.mjs

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:libpsg
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:libpsg;
HopperRequires:
ProperName:LibPSG
ProperAuthor:CuriousTorvald
ProperDescription:Programmable sound generator library for TSVM
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/include/psg.mjs

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:libseqread
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:libseqread;
HopperRequires:tvdos 1.*;
ProperName:LibSeqread
ProperAuthor:CuriousTorvald
ProperDescription:Sequentially read files from disk drive
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/include/seqread.mjs;/tvdos/include/seqreadtape.mjs

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:libtaud
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:libtaud;
HopperRequires:tvdos 1.*;
ProperName:LibTaud
ProperAuthor:CuriousTorvald
ProperDescription:Helper functions for interaction between Taud format and TSVM Tracker
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/include/taud.mjs

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:libterranbasic
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:libterranbasic;
HopperRequires:
ProperName:LibTerranBasic
ProperAuthor:CuriousTorvald
ProperDescription:Terran BASIC runtime helper for compiled programs
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/include/tbas.mjs

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:microtone
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:microtone;
HopperRequires:tvdos 1.*;wintex 1.*;libtaud 1.*;libgl 1.*
ProperName:Microtone
ProperAuthor:CuriousTorvald
ProperDescription:Microtonal tracker for TSVM
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/bin/microtone.alias;/tvdos/bin/taut*

View File

@@ -0,0 +1,17 @@
# Hopper Mirror List
#
# One mirror per non-empty, non-comment line.
# Each entry is the remote URL prefix from which Hopper can fetch
# <prefix>mirror_manifest
# <prefix>filelist
# <prefix><package>.hop.per (one per row of filelist)
#
# `mirror_manifest` declares HopperMirrorName, HopperMirrorMaintainer
# and HopperMirrorRemotePrefix; `filelist` is CSV of
# packagename,version,hoppermanifest-filename
#
# Lines starting with `#` and empty lines are ignored.
# A trailing slash on the prefix is optional; Hopper will add one
# if missing.
https://raw.githubusercontent.com/curioustorvald/hopper-mirror/refs/heads/master/

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:textedit
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:edit;
HopperRequires:tvdos 1.*
ProperName:edit.js
ProperAuthor:CuriousTorvald
ProperDescription:TVDOS default text editor
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/bin/edit.js

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:tvdos
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:tvdos;
HopperRequires:
ProperName:TVDOS
ProperAuthor:CuriousTorvald
ProperDescription:TSVM Disk Operating System
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/TVDOS.SYS;/tvdos/hyve.SYS;/tvdos/HSDPADRV.SYS;/tvdos/bin/command.js;/tvdos/sbin/sysctl.js;/tvdos/include/font.mjs;/tvdos/include/keysym.mjs;/tvdos/include/mload.mjs;/tvdos/include/playgui.mjs;/tvdos/include/typesetter.mjs

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:wintex
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:wintex;
HopperRequires:
ProperName:WinTex
ProperAuthor:CuriousTorvald
ProperDescription:TUI window management and renderer
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/include/wintex.mjs

View File

@@ -0,0 +1,12 @@
HopperManifestVersion:1
HopperPackageName:zfm
HopperPackageVersion:1.0.0
HopperPackageMaintainer:CuriousTorvald
HopperProvides:zfm;
HopperRequires:tvdos 1.*;wintex 1.*
ProperName:ZFM
ProperAuthor:CuriousTorvald
ProperDescription:Z File Manager - Dual-panel file manager for TVDOS
Licence:MIT
SupportMe:https://github.com/sponsors/curioustorvald/
SystemPackagePath:/tvdos/bin/zfm*

View File

@@ -0,0 +1,171 @@
/*
* lfs.mjs — programmatic extractor for TVDOS Linear File Strip archives.
*
* let lfs = require("A:/tvdos/include/lfs.mjs")
*
* // Pull one entry out:
* let fd = lfs.extractOne("A:/path/archive.lfs", "wanted.bin")
* // → file descriptor for $:/TMP/<random>/wanted.bin
*
* // Unpack the whole archive:
* let dir = lfs.extractAll("A:/path/archive.lfs")
* // → directory descriptor for $:/TMP/<random>/
*
* Both functions accept an `autoDecompress` boolean (default true). When
* a payload's first four bytes match the gzip (1F 8B 08 xx) or zstd
* (28 B5 2F FD) magic, the payload is inflated through gzip.decomp()
* before being written. The check is done on the payload bytes — the
* archived filename is irrelevant.
*
* Both functions require a relative-path archive (one produced by
* `lfs -c -r`); fully qualified archives carry drive letters that would
* not make sense rerooted under $:/TMP.
*/
const TMP_ROOT = "$:/TMP"
const HASH_ALPHABET = "YBNDRFG8EJKMCPQXOTLVWIS2A345H769"
const HASH_LEN = 32
const LFS_HEADER = "TVDOSLFS\x01"
const LFS_HEADER_LEN = 16
const LFS_FLAG_RELATIVE = 0x01
function _makeHash(n) {
let s = ""
const m = HASH_ALPHABET.length
for (let i = 0; i < n; i++) s += HASH_ALPHABET[Math.floor(Math.random() * m)]
return s
}
function _isCompressed(s) {
if (s.length < 4) return false
const b0 = s.charCodeAt(0), b1 = s.charCodeAt(1)
const b2 = s.charCodeAt(2), b3 = s.charCodeAt(3)
if (b0 === 0x1f && b1 === 0x8b && b2 === 0x08) return true // gzip
if (b0 === 0x28 && b1 === 0xb5 && b2 === 0x2f && b3 === 0xfd) return true // zstd
return false
}
function _decompress(payload) {
// gzip.decomp transparently handles both gzip and zstd; returns Java byte[].
return btostr(gzip.decomp(payload))
}
function _readArchive(lfsPath) {
const fd = files.open(lfsPath)
if (!fd.exists) throw new Error("LFS archive not found: " + lfsPath)
if (fd.isDirectory) throw new Error("LFS archive is a directory: " + lfsPath)
const bytes = fd.sread()
try { fd.close() } catch (_) {}
if (bytes.substring(0, LFS_HEADER.length) !== LFS_HEADER)
throw new Error("Not an LFS archive: " + lfsPath)
const flags = bytes.charCodeAt(11)
if ((flags & LFS_FLAG_RELATIVE) === 0)
throw new Error("LFS archive does not use relative paths: " + lfsPath)
return bytes
}
function _allocTmpDir() {
const path = TMP_ROOT + "/" + _makeHash(HASH_LEN)
const dir = files.open(path)
dir.mkDir()
return { fd: dir, path: path }
}
function _normPath(p) {
return p.replace(/\//g, "\\")
}
function _writeFile(destDirPath, archivePath, payload) {
const parts = _normPath(archivePath).split("\\").filter(p => p.length > 0)
if (parts.length === 0) return null
const leaf = parts.pop()
let curPath = destDirPath
for (let i = 0; i < parts.length; i++) {
curPath = curPath + "/" + parts[i]
const cur = files.open(curPath)
if (!cur.exists) cur.mkDir()
}
const outfile = files.open(curPath + "/" + leaf)
if (!outfile.exists) outfile.mkFile()
outfile.swrite(payload)
return outfile
}
function extractOne(lfsPath, filename, autoDecompress) {
if (autoDecompress === undefined) autoDecompress = true
if (filename === undefined || filename === null || filename === "")
throw new Error("filename is required")
const bytes = _readArchive(lfsPath)
const needle = _normPath(filename)
let curs = LFS_HEADER_LEN
while (curs < bytes.length) {
const fileType = bytes.charCodeAt(curs)
const pathlen = (bytes.charCodeAt(curs+1) << 8) | bytes.charCodeAt(curs+2)
curs += 3
const path = bytes.substring(curs, curs + pathlen)
curs += pathlen
const filelen = (bytes.charCodeAt(curs) << 24)
| (bytes.charCodeAt(curs+1) << 16)
| (bytes.charCodeAt(curs+2) << 8)
| bytes.charCodeAt(curs+3)
curs += 4
if (_normPath(path) === needle) {
let payload = bytes.substring(curs, curs + filelen)
if (autoDecompress && _isCompressed(payload)) payload = _decompress(payload)
const dest = _allocTmpDir()
const leaf = needle.split("\\").pop()
const outfile = files.open(dest.path + "/" + leaf)
if (!outfile.exists) outfile.mkFile()
outfile.swrite(payload)
return outfile
}
curs += filelen
}
throw new Error("File not found in archive: " + filename)
}
function extractAll(lfsPath, autoDecompress) {
if (autoDecompress === undefined) autoDecompress = true
const bytes = _readArchive(lfsPath)
const dest = _allocTmpDir()
let curs = LFS_HEADER_LEN
while (curs < bytes.length) {
const fileType = bytes.charCodeAt(curs)
const pathlen = (bytes.charCodeAt(curs+1) << 8) | bytes.charCodeAt(curs+2)
curs += 3
const path = bytes.substring(curs, curs + pathlen)
curs += pathlen
const filelen = (bytes.charCodeAt(curs) << 24)
| (bytes.charCodeAt(curs+1) << 16)
| (bytes.charCodeAt(curs+2) << 8)
| bytes.charCodeAt(curs+3)
curs += 4
let payload = bytes.substring(curs, curs + filelen)
if (autoDecompress && _isCompressed(payload)) payload = _decompress(payload)
_writeFile(dest.path, path, payload)
curs += filelen
}
return dest.fd
}
exports = { extractOne, extractAll }

View File

@@ -0,0 +1,123 @@
/*
* net.mjs — Internet text-fetch helper for TVDOS
*
* Wraps the HttpModem peripheral (driven by `_TVDOS.DRV.FS.NET`, see
* TVDOS.SYS:1001-1034) behind a small, regular-URL-friendly API. The
* helper looks up whichever drive letter the boot probe assigned to the
* HTTP modem and translates ordinary URLs (`https://host/path`) into the
* scheme-without-double-slash form (`https:host/path`) that the modem
* expects on the wire.
*
* Usage
* -----
* let net = require("A:/tvdos/include/net.mjs")
*
* if (!net.isAvailable())
* printerrln("No HTTP modem attached")
*
* let body = net.fetchText("https://example.com/index.html")
* if (body === null) printerrln("Fetch failed")
* else println(body)
*/
let _cachedDrive = null
/** Scan TVDOS drive table for an HTTP-typed device. Returns the drive
* letter (e.g. "B") or null. */
function _findHttpDrive() {
if (typeof _TVDOS === 'undefined' || !_TVDOS.DRIVEINFO) return null
if (_cachedDrive !== null && _TVDOS.DRIVEINFO[_cachedDrive] &&
_TVDOS.DRIVEINFO[_cachedDrive].type === 'HTTP')
return _cachedDrive
for (let letter in _TVDOS.DRIVEINFO) {
let info = _TVDOS.DRIVEINFO[letter]
if (info && info.type === 'HTTP') {
_cachedDrive = letter
return letter
}
}
return null
}
/** Convert a regular URL into the form the HTTP modem accepts:
* - strip the `//` between scheme and authority
* - drop any URL fragment
* - assume `https` when no scheme is provided
*/
function _normaliseUrl(url) {
if (typeof url !== 'string')
throw new TypeError("url must be a string")
let s = url.trim()
if (s.length === 0) throw new Error("url is empty")
// Drop fragment — the modem speaks to the server, # is client-side.
let hash = s.indexOf('#')
if (hash >= 0) s = s.substring(0, hash)
// scheme://host/path → scheme:host/path
let m = s.match(/^([a-zA-Z][a-zA-Z0-9+.\-]*):\/\/(.*)$/)
if (m) return m[1].toLowerCase() + ':' + m[2]
// Already in scheme:host/path form (the modem's native shape)
if (/^[a-zA-Z][a-zA-Z0-9+.\-]*:[^/]/.test(s)) return s
// No scheme — default to https
if (!/^[a-zA-Z][a-zA-Z0-9+.\-]*:/.test(s))
return 'https:' + s.replace(/^\/\//, '')
return s
}
let net = {}
/** Returns the drive letter currently bound to the HTTP modem, or null
* when no such device is attached. */
net.getHttpDrive = function () {
return _findHttpDrive()
}
/** True iff an HTTP modem is reachable through TVDOS. */
net.isAvailable = function () {
return _findHttpDrive() !== null
}
/** Translate a URL into the `<drive>:\<modem-url>` form that
* `files.open()` would route through `_TVDOS.DRV.FS.NET`. Useful when
* another component wants the descriptor directly. Throws if no HTTP
* modem is attached. */
net.toModemPath = function (url) {
let drive = _findHttpDrive()
if (drive === null) throw new Error("No HTTP modem device is attached")
return drive + ':\\' + _normaliseUrl(url)
}
/** Open a TVDOS file descriptor backed by the HTTP modem for the given
* URL. The descriptor's sread()/bread() trigger the actual fetch.
* Throws if no HTTP modem is attached. */
net.open = function (url) {
return files.open(net.toModemPath(url))
}
/** Fetch the body of `url` as a string. Returns the response text on
* success, or null when the modem reports a non-zero status (bad URL,
* I/O error, etc.). Throws if no HTTP modem is attached. */
net.fetchText = function (url) {
let fd = net.open(url)
let text = fd.sread()
try { fd.close() } catch (_) {}
return (text === undefined) ? null : text
}
/** Like fetchText, but throws an Error instead of returning null on
* fetch failure. */
net.fetchTextOrThrow = function (url) {
let body = net.fetchText(url)
if (body === null) throw new Error("Failed to fetch URL: " + url)
return body
}
exports = net

View File

@@ -0,0 +1,331 @@
/*
* typesetter.mjs - Rich-text typesetter for TVDOS console output.
*
* Wraps and aligns text using a tiny markup language. Originally lifted
* out of taut_helpmsg.js so other tools (motd, help popups, ...) can
* share the same formatter.
*
* Markup
* ------
* <b>...</b> emphasised foreground colour
* <c>...</c> centre-align this source line
* <r>...</r> right-align this source line
* <l>...</l> left-align this source line
* <o>...</o> virtual typesetting box. Left anchor is the cursor
* column at the open tag, right anchor is the wrap edge.
* default alignment is fully justified (override per-call via opts).
*
* Entities
* --------
* &microtone; "Microtone" wordmark
* &bul; &ddot; &mdot; bullet glyphs
* &updn; &udlr; arrow glyphs
* &keyoffsym; &notecutsym;
* &demisharp; &sharp; &sesquisharp; &doublesharp; &triplesharp; &quadsharp;
* &demiflat; &flat; &sesquiflat; &doubleflat; &tripleflat; &quadflat;
* &accuptick; &accdntick; &accupup; &accdndn;
* &nbsp; non-breaking space
* &shy; soft hyphen (currently dropped)
* &lt; &gt; literal angle brackets
*
* Usage
* -----
* let ts = require("typesetter")
* let lines = ts.typeset(text, width) // array of width-wide strings
* let lines = ts.typeset(text) // width = rest of current row
* let lines = ts.typeset(text, width, { defaultAlign: 'l' })
*/
///////////////////////////////////////////////////////////////////////////////
// Palette / ANSI helpers
///////////////////////////////////////////////////////////////////////////////
const COL_TEXT = 239 // popup body default (== colWHITE)
const COL_EMPH = 230 // <b>...</b> highlight (== colVoiceHdr)
const COL_BRAND = 211 // first half of "Microtone"
const COL_BRAND_DIM = 239 // second half of "Microtone"
const fgEsc = (n) => `\x1B[38;5;${n}m`
const ESC_DEFAULT = fgEsc(COL_TEXT)
const ESC_EMPH = fgEsc(COL_EMPH)
const MICROTONE = `${fgEsc(COL_BRAND)}Micro${fgEsc(COL_BRAND_DIM)}tone${ESC_DEFAULT}`
///////////////////////////////////////////////////////////////////////////////
// Entity expansion
///////////////////////////////////////////////////////////////////////////////
// Replace &xxx; entities with their final printable representations.
function expandEntities(s) {
return s
.replaceAll('&microtone;', MICROTONE)
.replaceAll('&bul;', '\u00F9')
.replaceAll('&ddot;', '\u008419u')
.replaceAll('&mdot;', '\u00FA')
.replaceAll('&updn;', '\u008418u')
.replaceAll('&udlr;', '\u008428u\u008429u')
.replaceAll('&keyoffsym;', '\u00A0\u00B1\u00B1\u00A1')
.replaceAll('&notecutsym;', '\u00A4\u00A4\u00A4\u00A4')
.replaceAll('&nbsp;', '\u007F')
.replaceAll('&shy;', '')
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replaceAll('&demisharp;', '\u0080\u0081')
.replaceAll('&sharp;', '\u0082\u0083')
.replaceAll('&sesquisharp;', '\u0084132u\u0085')
.replaceAll('&doublesharp;', '\u0086\u0087')
.replaceAll('&triplesharp;', '\u0088\u0089')
.replaceAll('&quadsharp;', '\u008A\u008B')
.replaceAll('&demiflat;', '\u008C\u008D')
.replaceAll('&flat;', '\u008E\u008F')
.replaceAll('&sesquiflat;', '\u0090\u0091')
.replaceAll('&doubleflat;', '\u0092\u0093')
.replaceAll('&tripleflat;', '\u0094\u0095')
.replaceAll('&quadflat;', '\u0096\u0097')
.replaceAll('&accuptick;', '\u009A')
.replaceAll('&accdntick;', '\u009B')
.replaceAll('&accupup;', '\u009C')
.replaceAll('&accdndn;', '\u009D')
}
///////////////////////////////////////////////////////////////////////////////
// Tokeniser
///////////////////////////////////////////////////////////////////////////////
// Tokenise a (post-entity-expansion) line. Returns an array of:
// {type:'word', text:String, w:int} - non-breakable run of visible chars (may carry ANSI escapes)
// {type:'sp'} - a single soft space (eligible for break/expansion)
// {type:'anchor', open:Boolean} - <o>/</o> markers (zero width)
//
// Width accounting:
// - ANSI escapes (`\x1B[...m`) : 0 visible chars
// - TSVM unicode escapes (`\u0084..u`) : 1 visible char
// - non-breaking space (\u007F) : 1 visible char (consumed as part of a word)
// - soft hyphen (\u00AD) : dropped (not implemented as a break point)
// - everything else : 1 visible char
function tokenise(line) {
const tokens = []
let buf = ''
let bufW = 0
let i = 0
const flushWord = () => {
if (buf.length > 0) {
tokens.push({type: 'word', text: buf, w: bufW})
buf = ''
bufW = 0
}
}
while (i < line.length) {
// inline tags (case-sensitive for <b>, case-insensitive for <o>)
if (line.slice(i, i + 3) === '<b>') { buf += ESC_EMPH; i += 3; continue }
if (line.slice(i, i + 4) === '</b>') { buf += ESC_DEFAULT; i += 4; continue }
const head3 = line.slice(i, i + 3).toLowerCase()
const head4 = line.slice(i, i + 4).toLowerCase()
if (head3 === '<o>') { flushWord(); tokens.push({type: 'anchor', open: true}); i += 3; continue }
if (head4 === '</o>') { flushWord(); tokens.push({type: 'anchor', open: false}); i += 4; continue }
const c = line[i]
const cc = line.charCodeAt(i)
if (cc === 0x1B) {
// pre-existing ANSI escape - copy verbatim, zero visible width
const m = line.indexOf('m', i)
const end = (m < 0) ? line.length : m + 1
buf += line.slice(i, end)
i = end
}
else if (cc === 0x84) {
// TSVM \u0084<digits>u escape - copy verbatim, one visible char
const u = line.indexOf('u', i)
const end = (u < 0) ? line.length : u + 1
buf += line.slice(i, end)
bufW += 1
i = end
}
else if (c === ' ') {
flushWord()
tokens.push({type: 'sp'})
i += 1
}
else if (cc === 0x00AD) {
// soft hyphen: drop (no break-point handling for now)
i += 1
}
else {
buf += c
bufW += 1
i += 1
}
}
flushWord()
return tokens
}
///////////////////////////////////////////////////////////////////////////////
// Line builder
///////////////////////////////////////////////////////////////////////////////
// Build wrapped lines from a token stream then format each one according to alignment.
// Returns an array of strings, each exactly `width` visible chars wide (padded with
// trailing spaces) so the caller can blit them without further math.
function wrapAndAlign(tokens, width, alignment) {
const lines = [] // each: {tokens, indent, contentW}
let curTokens = []
let curW = 0
let curIndent = 0
let nextIndent = 0 // indent the *next* flushed line should use
const flushLine = () => {
// strip trailing soft spaces
while (curTokens.length > 0 && curTokens[curTokens.length - 1].type === 'sp') {
curTokens.pop()
curW -= 1
}
lines.push({tokens: curTokens, indent: curIndent, contentW: curW})
curTokens = []
curW = 0
curIndent = nextIndent
}
for (const tok of tokens) {
if (tok.type === 'anchor') {
// anchor opens at the current visible column (accounting for indent)
if (tok.open) nextIndent = curIndent + curW
else nextIndent = 0
continue
}
if (tok.type === 'sp') {
// ignore leading soft spaces on a fresh line
if (curW === 0) continue
// hard wrap if the line is already at the right edge
if (curIndent + curW + 1 > width) { flushLine(); continue }
curTokens.push(tok)
curW += 1
continue
}
// word
const tw = tok.w
if (curIndent + curW + tw > width) {
flushLine()
// word too wide for the wrapped line: emit it on its own row (possibly clipped by terminal)
if (curIndent + tw > width) {
curTokens.push(tok)
curW += tw
flushLine()
continue
}
}
curTokens.push(tok)
curW += tw
}
if (curTokens.length > 0 || lines.length === 0) flushLine()
return lines.map((line, i) => formatLine(line, width, alignment, i === lines.length - 1))
}
function formatLine(line, totalWidth, alignment, isLast) {
if (line.tokens.length === 0) return ' '.repeat(totalWidth)
const indent = ' '.repeat(line.indent)
const remaining = totalWidth - line.indent - line.contentW
const pad = (n) => (n > 0) ? ' '.repeat(n) : ''
const flatText = () => line.tokens.map(t => (t.type === 'sp') ? ' ' : t.text).join('')
if (alignment === 'c') {
const left = remaining >> 1
return indent + pad(left) + flatText() + pad(remaining - left)
}
if (alignment === 'r') return indent + pad(remaining) + flatText()
if (alignment === 'l') return indent + flatText() + pad(remaining)
// justified: only expand spaces when there's slack and we're not on the
// last (or single) wrapped line
if (isLast || remaining <= 0) return indent + flatText() + pad(remaining)
const spaceCount = line.tokens.reduce((n, t) => n + (t.type === 'sp' ? 1 : 0), 0)
if (spaceCount === 0) return indent + flatText() + pad(remaining)
const baseExtra = (remaining / spaceCount) | 0
let leftover = remaining - baseExtra * spaceCount
let out = indent
for (const tok of line.tokens) {
if (tok.type === 'sp') {
const extra = baseExtra + (leftover > 0 ? 1 : 0)
if (leftover > 0) leftover -= 1
out += ' '.repeat(1 + extra)
} else {
out += tok.text
}
}
return out
}
// Process a single source line: peel a leading <c>/<r>/<l> alignment tag (if present),
// strip its matching close tag, then tokenise + wrap.
function typesetSourceLine(line, width, defaultAlign) {
if (line.length === 0) return [' '.repeat(width)]
let alignment = defaultAlign || 'j' // justified default
const startMatch = line.match(/^<([crl])>/i)
if (startMatch) {
alignment = startMatch[1].toLowerCase()
line = line.slice(startMatch[0].length)
const closeRe = new RegExp(`</${alignment}>$`, 'i')
line = line.replace(closeRe, '')
}
const tokens = tokenise(line)
return wrapAndAlign(tokens, width, alignment)
}
function typesetText(text, width, defaultAlign) {
text = expandEntities(text)
const out = []
for (const srcLine of text.split('\n')) {
for (const outLine of typesetSourceLine(srcLine, width, defaultAlign)) out.push(outLine)
}
return out
}
// Convenience entry: `typeset(text)` defaults the wrap width to "rest of current row".
// `opts` may be `{ defaultAlign: 'l' | 'c' | 'r' | 'j' }`.
function typeset(text, customWidth, opts) {
let typesetWidth = customWidth
if (typesetWidth === undefined) {
const SCRW = con.getmaxyx()[1]
const currentPosX = con.getyx()[1] // 1-indexed
typesetWidth = SCRW - currentPosX + 1
}
let defaultAlign = (opts && opts.defaultAlign) || 'j'
return typesetText(text, typesetWidth, defaultAlign)
}
///////////////////////////////////////////////////////////////////////////////
// Module exports
///////////////////////////////////////////////////////////////////////////////
exports = {
typeset,
typesetText,
typesetSourceLine,
tokenise,
expandEntities,
fgEsc,
COL_TEXT,
COL_EMPH,
COL_BRAND,
COL_BRAND_DIM,
ESC_DEFAULT,
ESC_EMPH,
MICROTONE,
}

View File

@@ -2649,7 +2649,7 @@ Endianness: Little
Uint8 Flags for Global Behaviour (effect symbol '1')
0b 000 rrr ff
ff: tone mode (0: linear pitch slides, 1: Amiga period slides, 2: linear-frequency slides, 3: reserved)
rrr: interpolation mode (0: default, 1: none, 2: Amiga 500, 3: Amiga 1200, 4: SNES 4-tap Gaussian, 5: preserve delta modulation)
rrr: interpolation mode (0: default, 1: none, 2: Amiga 500, 3: Amiga 1200, 4: SNES 4-tap Gaussian, 5: NES DPCM simulation)
Uint8 Song global volume
* ImpulseTracker has range of 0..128; multiply by (255/128) then round to int
Uint8 Song mixing volume

View File

@@ -134,6 +134,28 @@ class AudioJSR223Delegate(private val vm: VM) {
} else v.channelPan.coerceIn(0, 255)
}
/** Whether the voice slot is currently sounding (i.e. owns an active sample). Mirrors
* `Voice.active` which is the source of truth for "is this voice contributing to the mix
* right now". Visualisers should treat this as the authoritative on/off bit. */
fun getVoiceActive(playhead: Int, voice: Int): Boolean =
getPlayhead(playhead)?.trackerState?.voices?.getOrNull(voice.coerceIn(0, 19))?.active == true
/** Live noteVal (0..65535, 4096-TET) of the foreground voice — the value the mixer is using
* *right now* including any in-flight vibrato / arpeggio / portamento delta. Returns 0 for
* inactive voices. */
fun getVoiceNote(playhead: Int, voice: Int): Int {
val v = getPlayhead(playhead)?.trackerState?.voices?.getOrNull(voice.coerceIn(0, 19)) ?: return 0
if (!v.active) return 0
return v.noteVal and 0xFFFF
}
/** Instrument id (0..255) currently bound to the voice slot, or 0 if the voice is inactive. */
fun getVoiceInstrument(playhead: Int, voice: Int): Int {
val v = getPlayhead(playhead)?.trackerState?.voices?.getOrNull(voice.coerceIn(0, 19)) ?: return 0
if (!v.active) return 0
return v.instrumentId and 0xFF
}
/** Set the starting row for the next play call, resetting per-row timing and silencing active voices. */
fun setTrackerRow(playhead: Int, row: Int) {
getPlayhead(playhead)?.trackerState?.let { ts ->

View File

@@ -305,7 +305,6 @@ class VMJSR223Delegate(private val vm: VM) {
fun sleep(time: Long) {
vm.isIdle.set(true)
Thread.sleep(time)
Thread.sleep(4L)
}
fun waitForMemChg(addr: Int, andMask: Int, xorMask: Int) {

View File

@@ -166,15 +166,19 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
const val SAMPLE_BIN_TOTAL: Long = SAMPLE_BANK_SIZE * SAMPLE_BANK_COUNT
const val SAMPLE_BANK_MASK: Int = SAMPLE_BANK_COUNT - 1
// Interpolation modes (TAUD_NOTE_EFFECTS.md §1, bits 2-3 of global behaviour flags).
// Interpolation modes (TAUD_NOTE_EFFECTS.md §1, bits 2-4 of global behaviour flags).
// 0 = default (Fast Sinc, 16-tap windowed sinc), 1 = none (zero-order hold),
// 2 = Amiga 500 (ZOH + A500 1-pole LPF), 3 = Amiga 1200 (ZOH + A1200 LPF — bypassed).
// 2 = Amiga 500 (ZOH + A500 1-pole LPF), 3 = Amiga 1200 (ZOH + A1200 LPF — bypassed),
// 4 = SNES 4-tap gaussian (BRR-style, preserves the int16 mid-sum overflow quirk),
// 5 = NES 2A03 DPCM (1-bit sigma-delta on a 7-bit ±2-stepping counter).
// Amiga modes additionally apply a 2-pole Sallen-Key "LED" LPF when ts.ledFilterOn,
// which is toggled by S $0000 / S $0100 (TAUD_NOTE_EFFECTS.md §"S $0x00").
const val INTERP_DEFAULT = 0
const val INTERP_NONE = 1
const val INTERP_A500 = 2
const val INTERP_A1200 = 3
const val INTERP_DEFAULT = 0
const val INTERP_NONE = 1
const val INTERP_A500 = 2
const val INTERP_A1200 = 3
const val INTERP_SNES = 4
const val INTERP_NES_DPCM = 5
// Fast Sinc — 6-tap windowed sinc with 1024 sub-sample positions.
// Mirrors MilkyTracker's MIXER_SINCTABLE (ResamplerSinc.h: WIDTH=8, 1024-step table,
@@ -207,6 +211,49 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
return SINC_TABLE[idx] * (1.0 - f) + SINC_TABLE[idx + 1] * f
}
// SNES BRR 4-tap gaussian table (512 entries, monotonically rising 0x000..0x519).
// Mirrors xander-haj/z3c snes/dsp.c gaussValues[]. The DSP indexes this table with
// four phases derived from an 8-bit fractional offset: gauss[offset] (newest tap),
// gauss[0x100+offset] (olds — peaks near the playhead), gauss[0x1ff-offset] (olders —
// contains the peak value 0x519), and gauss[0xff-offset] (oldest). Coefficients sum
// to ~2049 at every phase, so the SNES DSP right-shifts the sum by 1 after a
// deliberate int16 wrap-around on the partial sum (audible as the famous
// "SNES gauss overflow chirp" on loud samples — preserved here for authenticity).
private val SNES_GAUSS = intArrayOf(
0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000,
0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x002, 0x002, 0x002, 0x002, 0x002,
0x002, 0x002, 0x003, 0x003, 0x003, 0x003, 0x003, 0x004, 0x004, 0x004, 0x004, 0x004, 0x005, 0x005, 0x005, 0x005,
0x006, 0x006, 0x006, 0x006, 0x007, 0x007, 0x007, 0x008, 0x008, 0x008, 0x009, 0x009, 0x009, 0x00A, 0x00A, 0x00A,
0x00B, 0x00B, 0x00B, 0x00C, 0x00C, 0x00D, 0x00D, 0x00E, 0x00E, 0x00F, 0x00F, 0x00F, 0x010, 0x010, 0x011, 0x011,
0x012, 0x013, 0x013, 0x014, 0x014, 0x015, 0x015, 0x016, 0x017, 0x017, 0x018, 0x018, 0x019, 0x01A, 0x01B, 0x01B,
0x01C, 0x01D, 0x01D, 0x01E, 0x01F, 0x020, 0x020, 0x021, 0x022, 0x023, 0x024, 0x024, 0x025, 0x026, 0x027, 0x028,
0x029, 0x02A, 0x02B, 0x02C, 0x02D, 0x02E, 0x02F, 0x030, 0x031, 0x032, 0x033, 0x034, 0x035, 0x036, 0x037, 0x038,
0x03A, 0x03B, 0x03C, 0x03D, 0x03E, 0x040, 0x041, 0x042, 0x043, 0x045, 0x046, 0x047, 0x049, 0x04A, 0x04C, 0x04D,
0x04E, 0x050, 0x051, 0x053, 0x054, 0x056, 0x057, 0x059, 0x05A, 0x05C, 0x05E, 0x05F, 0x061, 0x063, 0x064, 0x066,
0x068, 0x06A, 0x06B, 0x06D, 0x06F, 0x071, 0x073, 0x075, 0x076, 0x078, 0x07A, 0x07C, 0x07E, 0x080, 0x082, 0x084,
0x086, 0x089, 0x08B, 0x08D, 0x08F, 0x091, 0x093, 0x096, 0x098, 0x09A, 0x09C, 0x09F, 0x0A1, 0x0A3, 0x0A6, 0x0A8,
0x0AB, 0x0AD, 0x0AF, 0x0B2, 0x0B4, 0x0B7, 0x0BA, 0x0BC, 0x0BF, 0x0C1, 0x0C4, 0x0C7, 0x0C9, 0x0CC, 0x0CF, 0x0D2,
0x0D4, 0x0D7, 0x0DA, 0x0DD, 0x0E0, 0x0E3, 0x0E6, 0x0E9, 0x0EC, 0x0EF, 0x0F2, 0x0F5, 0x0F8, 0x0FB, 0x0FE, 0x101,
0x104, 0x107, 0x10B, 0x10E, 0x111, 0x114, 0x118, 0x11B, 0x11E, 0x122, 0x125, 0x129, 0x12C, 0x130, 0x133, 0x137,
0x13A, 0x13E, 0x141, 0x145, 0x148, 0x14C, 0x150, 0x153, 0x157, 0x15B, 0x15F, 0x162, 0x166, 0x16A, 0x16E, 0x172,
0x176, 0x17A, 0x17D, 0x181, 0x185, 0x189, 0x18D, 0x191, 0x195, 0x19A, 0x19E, 0x1A2, 0x1A6, 0x1AA, 0x1AE, 0x1B2,
0x1B7, 0x1BB, 0x1BF, 0x1C3, 0x1C8, 0x1CC, 0x1D0, 0x1D5, 0x1D9, 0x1DD, 0x1E2, 0x1E6, 0x1EB, 0x1EF, 0x1F3, 0x1F8,
0x1FC, 0x201, 0x205, 0x20A, 0x20F, 0x213, 0x218, 0x21C, 0x221, 0x226, 0x22A, 0x22F, 0x233, 0x238, 0x23D, 0x241,
0x246, 0x24B, 0x250, 0x254, 0x259, 0x25E, 0x263, 0x267, 0x26C, 0x271, 0x276, 0x27B, 0x280, 0x284, 0x289, 0x28E,
0x293, 0x298, 0x29D, 0x2A2, 0x2A6, 0x2AB, 0x2B0, 0x2B5, 0x2BA, 0x2BF, 0x2C4, 0x2C9, 0x2CE, 0x2D3, 0x2D8, 0x2DC,
0x2E1, 0x2E6, 0x2EB, 0x2F0, 0x2F5, 0x2FA, 0x2FF, 0x304, 0x309, 0x30E, 0x313, 0x318, 0x31D, 0x322, 0x326, 0x32B,
0x330, 0x335, 0x33A, 0x33F, 0x344, 0x349, 0x34E, 0x353, 0x357, 0x35C, 0x361, 0x366, 0x36B, 0x370, 0x374, 0x379,
0x37E, 0x383, 0x388, 0x38C, 0x391, 0x396, 0x39B, 0x39F, 0x3A4, 0x3A9, 0x3AD, 0x3B2, 0x3B7, 0x3BB, 0x3C0, 0x3C5,
0x3C9, 0x3CE, 0x3D2, 0x3D7, 0x3DC, 0x3E0, 0x3E5, 0x3E9, 0x3ED, 0x3F2, 0x3F6, 0x3FB, 0x3FF, 0x403, 0x408, 0x40C,
0x410, 0x415, 0x419, 0x41D, 0x421, 0x425, 0x42A, 0x42E, 0x432, 0x436, 0x43A, 0x43E, 0x442, 0x446, 0x44A, 0x44E,
0x452, 0x455, 0x459, 0x45D, 0x461, 0x465, 0x468, 0x46C, 0x470, 0x473, 0x477, 0x47A, 0x47E, 0x481, 0x485, 0x488,
0x48C, 0x48F, 0x492, 0x496, 0x499, 0x49C, 0x49F, 0x4A2, 0x4A6, 0x4A9, 0x4AC, 0x4AF, 0x4B2, 0x4B5, 0x4B7, 0x4BA,
0x4BD, 0x4C0, 0x4C3, 0x4C5, 0x4C8, 0x4CB, 0x4CD, 0x4D0, 0x4D2, 0x4D5, 0x4D7, 0x4D9, 0x4DC, 0x4DE, 0x4E0, 0x4E3,
0x4E5, 0x4E7, 0x4E9, 0x4EB, 0x4ED, 0x4EF, 0x4F1, 0x4F3, 0x4F5, 0x4F6, 0x4F8, 0x4FA, 0x4FB, 0x4FD, 0x4FF, 0x500,
0x502, 0x503, 0x504, 0x506, 0x507, 0x508, 0x50A, 0x50B, 0x50C, 0x50D, 0x50E, 0x50F, 0x510, 0x511, 0x511, 0x512,
0x513, 0x514, 0x514, 0x515, 0x516, 0x516, 0x517, 0x517, 0x517, 0x518, 0x518, 0x518, 0x518, 0x518, 0x519, 0x519
)
// Amiga filter coefficients (precomputed at SAMPLING_RATE = 32 kHz, see pt2_paula.c
// and pt2_rcfilters.c). All filters operate on the post-mix stereo bus per playhead.
//
@@ -1766,9 +1813,11 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
val frac = voice.samplePos - i0.toDouble()
// Interpolation:
// INTERP_DEFAULT (0): 16-tap windowed sinc (Fast Sinc; MilkyTracker MIXER_SINCTABLE)
// INTERP_NONE (1): nearest-neighbour
// INTERP_DEFAULT (0): 6-tap windowed sinc (Fast Sinc; MilkyTracker MIXER_SINCTABLE)
// INTERP_NONE (1): zero-order hold
// INTERP_A500/A1200 (2/3): zero-order hold per Paula; LPF applied at mix stage
// INTERP_SNES (4): SNES BRR 4-tap gaussian
// INTERP_NES_DPCM (5): NES 2A03 DMC 1-bit sigma-delta playback simulation
// Edge clamping: out-of-range taps are clipped to sample bounds (acceptable smear
// at sample edges; matches MilkyTracker's outSideLoop fallback).
val sample: Double = when (interpMode) {
@@ -1781,6 +1830,54 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
}
acc
}
INTERP_SNES -> {
// Four taps centred between samples i0 and i0+1, indexed in SNES naming:
// oldests = sample at i0 - 1, olders = i0, olds = i0 + 1, news = i0 + 2.
// Promote each [-1, 1] sample to signed 16-bit, run the canonical BRR
// formula in integer arithmetic, then map (out >> 1) back to [-1, 1].
// The (out & 0xffff) → int16 cast after the third tap reproduces the
// SNES hardware mid-sum overflow (the famous gauss "chirp").
val oldest = (readSamplePoint(inst, i0 - 1, sampleLen, binMax) * 32767.0).toInt()
val olders = (readSamplePoint(inst, i0, sampleLen, binMax) * 32767.0).toInt()
val olds = (readSamplePoint(inst, i0 + 1, sampleLen, binMax) * 32767.0).toInt()
val news = (readSamplePoint(inst, i0 + 2, sampleLen, binMax) * 32767.0).toInt()
val offset = (frac * 256.0).toInt().coerceIn(0, 255)
var out = (SNES_GAUSS[0xff - offset] * oldest) shr 10
out += (SNES_GAUSS[0x1ff - offset] * olders) shr 10
out += (SNES_GAUSS[0x100 + offset] * olds) shr 10
out = out.toShort().toInt()
out += (SNES_GAUSS[offset] * news) shr 10
out = out.coerceIn(-32768, 32767)
(out shr 1) / 16384.0
}
INTERP_NES_DPCM -> {
// NES 2A03 DMC (Delta Modulation Channel) playback simulation. The DMC
// is a 1-bit sigma-delta DAC: each clock reads one bit and slews a 7-bit
// output counter (0..127) by ±2, clamped at the rails. Here the bitstream
// is synthesised on the fly by comparing each ZOH-fetched sample against
// the counter, then applying canonical DMC update rules (NESdev wiki
// "APU DMC"):
// target > counter ∧ counter ≤ 125 : counter += 2
// target < counter ∧ counter ≥ 2 : counter -= 2
// else : silent clip at the rail
// The DMC clock is locked to the host sample rate (32 kHz, just below
// NTSC DMC rate $F = 33144 Hz); the ±2-per-tick slew-rate limit gives
// DPCM its signature — slow / quiet signals reconstruct cleanly, fast
// transients break into triangle-flank crunch. The 7-bit counter further
// imposes 64 effective output levels (only even values are reachable from
// a mid-rail seed), reproducing DMC's coarse quantisation. Per-voice
// counter persists across samples and is reseeded to mid-rail on note
// trigger (see triggerNote).
val target = readSamplePoint(inst, i0, sampleLen, binMax)
val targetLevel = ((target + 1.0) * 63.5).toInt().coerceIn(0, 127)
when {
targetLevel > voice.nesDpcmCounter && voice.nesDpcmCounter <= 125 ->
voice.nesDpcmCounter += 2
targetLevel < voice.nesDpcmCounter && voice.nesDpcmCounter >= 2 ->
voice.nesDpcmCounter -= 2
}
(voice.nesDpcmCounter - 63.5) / 63.5
}
INTERP_NONE, INTERP_A500, INTERP_A1200 ->
// Paula-style ZOH — emit the integer-indexed sample byte without
// sub-sample fade. Aliasing is removed by the post-mix Amiga LPFs.
@@ -1926,6 +2023,10 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
// Auto-vibrato sweep ramp restarts on every fresh trigger.
voice.autoVibPhase = 0
voice.autoVibTicksSinceTrigger = 0
// Reseed the NES DPCM sigma-delta counter to mid-rail so the first
// output sample after key-on doesn't carry the previous note's residual
// DC slew (relevant only when interpolationMode == INTERP_NES_DPCM).
voice.nesDpcmCounter = 63
// Funk repeat (S$Fx): PT2 resets n_wavestart to n_loopstart on every fresh
// note trigger (pt2_replayer.c:1094, 1100). funkSpeed and funkAccumulator
// persist across notes, matching PT2.
@@ -3582,6 +3683,13 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
var autoVibPhase = 0 // 8-bit phase counter
var autoVibTicksSinceTrigger = 0 // for sweep ramp-up
// NES 2A03 DMC counter for INTERP_NES_DPCM (interpolation mode 5).
// 7-bit unsigned (0..127), slews ±2 per output sample as the sigma-delta
// bitstream is generated on the fly. Seeded to mid-rail (63) on every
// fresh trigger so the first sample doesn't have to slew ~30 ticks up
// from 0 to reach a typical instrument's DC level.
var nesDpcmCounter = 63
// Filter / cutoff state — drives the per-voice IT-compatible 2-pole resonant LPF.
// Convention: 255 = filter off (matches IT's high-bit-clear sentinel);
// 0..254 = active range mirroring IT 0..127 at double resolution.
@@ -3747,8 +3855,9 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
// 3 = reserved
var toneMode = 0
// Interpolation mode (TAUD_NOTE_EFFECTS.md §1, bits 2-3 of global behaviour flags).
// 0=Fast Sinc default, 1=none, 2=Amiga 500, 3=Amiga 1200. See AudioAdapter.INTERP_*.
// Interpolation mode (TAUD_NOTE_EFFECTS.md §1, bits 2-4 of global behaviour flags).
// 0=Fast Sinc default, 1=none, 2=Amiga 500, 3=Amiga 1200, 4=SNES 4-tap gaussian,
// 5=NES 2A03 DPCM simulation. See AudioAdapter.INTERP_*.
var interpolationMode = INTERP_DEFAULT
// Amiga "LED" 2-pole LPF on/off (S $0000 = on, S $0100 = off; PT E00/E01).
// Only applies when interpolationMode is INTERP_A500 or INTERP_A1200.
@@ -3812,7 +3921,7 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
fun updateTrackerGlobalBehaviour(flags: Int) {
trackerState?.let { ts ->
ts.toneMode = flags and 3
ts.interpolationMode = (flags ushr 2) and 3
ts.interpolationMode = (flags ushr 2) and 7
}
}
@@ -3912,7 +4021,7 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
ts.sexWinningChannel = -1
ts.finePatternDelayExtra = 0
ts.toneMode = initialGlobalFlags and 3
ts.interpolationMode = (initialGlobalFlags ushr 2) and 3
ts.interpolationMode = (initialGlobalFlags ushr 2) and 7
ts.ledFilterOn = false
ts.amigaLPStateL = 0.0; ts.amigaLPStateR = 0.0
ts.amigaLEDStateL.fill(0.0); ts.amigaLEDStateR.fill(0.0)
@@ -3973,6 +4082,7 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
it.filterY1 = 0.0; it.filterY2 = 0.0
it.filterCutoffCached = -1; it.filterResonanceCached = -1
it.currentCutoff = 0xFF; it.currentResonance = 0xFF
it.nesDpcmCounter = 63
}
ts.backgroundVoices.clear()
// Funk repeat (S$Fx): drop every per-instrument inversion mask so that

View File

@@ -22,7 +22,7 @@ import java.net.URL
*/
class HttpModem(private val vm: VM, private val artificialDelayBlockSize: Int = 1024, private val artificialDelayWaitTime: Int = -1) : BlockTransferInterface(false, true) {
private val DBGPRN = true
private val DBGPRN = false
private fun printdbg(msg: Any) {
if (DBGPRN) println("[WgetModem] $msg")