summaryrefslogtreecommitdiff
path: root/toolbox/toolbox.go
diff options
context:
space:
mode:
Diffstat (limited to 'toolbox/toolbox.go')
-rw-r--r--toolbox/toolbox.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/toolbox/toolbox.go b/toolbox/toolbox.go
new file mode 100644
index 0000000..535fe9f
--- /dev/null
+++ b/toolbox/toolbox.go
@@ -0,0 +1,68 @@
+// SPDX-FileCopyrightText: 2026 Terin Stock <terinjokes@gmail.com>
+// SPDX-License-Identifier: EUPL-1.2
+
+package toolbox
+
+import (
+ "strings"
+)
+
+const (
+ TOOLBOX_COUNT_CDS = 0xDA
+ TOOLBOX_LIST_CDS = 0xD7
+ TOOLBOX_SET_NEXT_CD = 0xD8
+ TOOLBOX_LIST_DEVICES = 0xD9
+)
+
+// FileType represents the type of file in a [FileEntry].
+type FileType uint8
+
+const (
+ File FileType = iota
+ Directory
+)
+
+// DeviceType represents the type of emulated device.
+type DeviceType uint8
+
+const (
+ Fixed DeviceType = iota
+ Removeable
+ Optical
+ Floppy14MB
+ MO
+ Sequential
+ Network
+ Zip100
+
+ None DeviceType = 0xFF
+)
+
+// FileEntry describes each file recognized by the ODE as
+// emulatable media.
+type FileEntry [40]byte
+
+// Index is the file's index, to be used with [Device.SetCDByIndex].
+func (e *FileEntry) Index() int {
+ return int(e[0])
+}
+
+// FileType returns the entry's file type.
+func (e *FileEntry) FileType() FileType {
+ return FileType(e[1])
+}
+
+// Name is the entry's name, truncated to 32 characters.
+func (e *FileEntry) Name() string {
+ str := string(e[2:35])
+ idx := strings.IndexByte(str, 0)
+ if idx < 0 {
+ idx = 33
+ }
+ return str[:idx]
+}
+
+// Size returns the size of the entry in bytes.
+func (e *FileEntry) Size() uint64 {
+ return uint64(e[36])<<24 | uint64(e[37])<<16 | uint64(e[38])<<8 | uint64(e[39])
+}