diff --git a/.idea/cody_history.xml b/.idea/cody_history.xml
new file mode 100644
index 0000000..dfd1d5e
--- /dev/null
+++ b/.idea/cody_history.xml
@@ -0,0 +1,133 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/AppLoader.xml b/.idea/runConfigurations/AppLoader.xml
new file mode 100644
index 0000000..6389b7f
--- /dev/null
+++ b/.idea/runConfigurations/AppLoader.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/TerranBASIC.xml b/.idea/runConfigurations/TerranBASIC.xml
new file mode 100644
index 0000000..a21d936
--- /dev/null
+++ b/.idea/runConfigurations/TerranBASIC.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/TsvmEmulator.xml b/.idea/runConfigurations/TsvmEmulator.xml
new file mode 100644
index 0000000..629868f
--- /dev/null
+++ b/.idea/runConfigurations/TsvmEmulator.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/terranmon.txt b/terranmon.txt
index 3967d80..a14e2a5 100644
--- a/terranmon.txt
+++ b/terranmon.txt
@@ -2002,8 +2002,8 @@ Instrument bin: Registry for 256 instruments, formatted as:
Uint16 Loop Start (can be smaller than Play Start)
Uint16 Loop End
Bit32 Flags
- 0b h000 00pp
- h: sample pointer high bit
+ 0b hhhh 00pp
+ h: sample pointer high bit (only the lowest bit is used, keep upper 3 bits unset)
pp: loop mode. 0-no loop, 1-loop, 2-backandforth, 3-oneshot (ignores note length unless overridden by other notes)
Bit16x24 Volume envelopes
Byte 1: Volume
diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/AudioAdapter.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/AudioAdapter.kt
index 0b88296..95ef4bb 100644
--- a/tsvm_core/src/net/torvald/tsvm/peripheral/AudioAdapter.kt
+++ b/tsvm_core/src/net/torvald/tsvm/peripheral/AudioAdapter.kt
@@ -1465,7 +1465,7 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
data class TaudInstVolEnv(var volume: Int, var offset: ThreeFiveMiniUfloat)
data class TaudInst(
- var samplePtr: Int, // 17-bit number
+ var samplePtr: Int, // 20-bit number
var sampleLength: Int,
var samplingRate: Int,
var samplePlayStart: Int,
@@ -1496,8 +1496,8 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
10 -> sampleLoopEnd.toByte()
11 -> sampleLoopEnd.ushr(8).toByte()
- 12 -> (samplePtr.ushr(16).and(1).shl(7) or loopMode.and(3)).toByte()
- 13,14,15 -> -1
+ 12 -> (samplePtr.ushr(16).and(15).shl(4) or loopMode.and(3)).toByte()
+ 13,14,15 -> 0
in 16..63 step 2 -> envelopes[(offset - 16) / 2].volume.toByte()
in 17..63 step 2 -> envelopes[(offset - 17) / 2].offset.index.toByte()
else -> throw InternalError("Bad offset $offset")
@@ -1523,7 +1523,7 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
11 -> { sampleLoopEnd = (sampleLoopEnd and 0x00ff) or (byte shl 8) }
12 -> {
- samplePtr = if (byte and 0b1000_0000 != 0) samplePtr or 0x10000
+ samplePtr = if (byte and 0b1111_0000 != 0) samplePtr or ((byte ushr 4) shl 16)
else samplePtr and 0x0ffff
loopMode = byte and 3
}