Add the 0x05 block type; Remove --extract from fdslist

- Block type 0x05 is some weird test pattern thing???
- Removed --extract from the fdslist utility
This commit is contained in:
Zorchenhimer 2025-12-12 23:37:13 -05:00
parent ccdb696c2d
commit c2a6fc7fa3
Signed by: Zorchenhimer
GPG Key ID: 70A1AB767AAB9C20
3 changed files with 67 additions and 26 deletions

View File

@ -2,6 +2,7 @@ package fds
import ( import (
"fmt" "fmt"
"strings"
) )
type BlockType byte type BlockType byte
@ -11,6 +12,7 @@ const (
BtFileAmount BlockType = 0x02 BtFileAmount BlockType = 0x02
BtFileHeader BlockType = 0x03 BtFileHeader BlockType = 0x03
BtFileData BlockType = 0x04 BtFileData BlockType = 0x04
BtTest BlockType = 0x05
) )
func (bt BlockType) String() string { func (bt BlockType) String() string {
@ -192,3 +194,20 @@ func (b *BlockFileData) Type() BlockType {
func (b *BlockFileData) String() string { func (b *BlockFileData) String() string {
return "BlockFileData" return "BlockFileData"
} }
type BlockTest struct {
Raw []byte
}
func (b *BlockTest) Type() BlockType {
return BtTest
}
func (b *BlockTest) String() string {
bytes := []string{}
for _, byt := range b.Raw {
bytes = append(bytes, fmt.Sprintf("$%02X", byt))
}
return fmt.Sprintf("BlockTest Raw:[%s]", strings.Join(bytes, " "))
}

View File

@ -3,10 +3,6 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
//"encoding/binary"
//"bufio"
//"bytes"
//"io"
"path/filepath" "path/filepath"
"github.com/alexflint/go-arg" "github.com/alexflint/go-arg"
@ -16,7 +12,8 @@ import (
type Arguments struct { type Arguments struct {
Input string `arg:"positional,required"` Input string `arg:"positional,required"`
Extract string `arg:"--extract" help:"Extract files to the given directory"`
Blocks bool `arg:"--blocks"`
} }
@ -32,6 +29,25 @@ func main() {
} }
func run(args *Arguments) error { func run(args *Arguments) error {
if args.Blocks {
file, err := os.Open(args.Input)
if err != nil {
return err
}
defer file.Close()
blocks, err := fds.ReadRomBlocks(file, filepath.Ext(args.Input) == ".fds")
if err != nil {
return err
}
for _, block := range blocks {
fmt.Println(block.String())
}
return nil
}
rom, err := fds.ReadRomFile(args.Input) rom, err := fds.ReadRomFile(args.Input)
if err != nil { if err != nil {
return err return err
@ -39,26 +55,6 @@ func run(args *Arguments) error {
fmt.Println(rom.Info()) fmt.Println(rom.Info())
if args.Extract != "" {
err = os.MkdirAll(args.Extract, 0775)
if err != nil {
return err
}
num := 0
for _, side := range rom.Sides {
sideName := fmt.Sprintf("Side%d", side.Header.PhysicalSide)
for _, file := range side.Files {
fileName := filepath.Join(args.Extract, fmt.Sprintf("%03d_%s_%02d_%02X", num, sideName, file.Number, file.Id))
err := os.WriteFile(fileName, file.Data, 0664)
if err != nil {
return err
}
num++
}
}
}
return nil return nil
} }

View File

@ -52,6 +52,7 @@ func ReadBlocks(r io.Reader, IsFds bool) ([]DiskBlock, error) {
reader := bufio.NewReader(r) reader := bufio.NewReader(r)
outerLoop:
for { for {
raw, err := reader.Peek(1) raw, err := reader.Peek(1)
if err != nil { if err != nil {
@ -79,6 +80,31 @@ func ReadBlocks(r io.Reader, IsFds bool) ([]DiskBlock, error) {
// variable length // variable length
readLen = dataSize+3 readLen = dataSize+3
case 0x05: // some weird test block??
reader.Discard(1)
bt := &BlockTest{}
for {
b, err := reader.ReadByte()
if err != nil {
if err == io.EOF {
blocks = append(blocks, bt)
break outerLoop
}
return blocks, fmt.Errorf("error reading 0x05 block type: %w", err)
}
switch b {
case 0x6D, 0xB6, 0xDB:
bt.Raw = append(bt.Raw, b)
continue
case 0x00:
blocks = append(blocks, bt)
continue outerLoop
}
return blocks, fmt.Errorf("Read unknown byte in 0x05 block: 0x%02X", b)
}
case 0x00: case 0x00:
reader.Discard(1) reader.Discard(1)
continue continue
@ -144,9 +170,9 @@ func ReadBlocks(r io.Reader, IsFds bool) ([]DiskBlock, error) {
db.Data = buf[1:readLen] db.Data = buf[1:readLen]
//fmt.Println("len(db.Data)", len(db.Data)) //fmt.Println("len(db.Data)", len(db.Data))
block = db block = db
//fmt.Printf("Block:%#v\n", block)
} }
//fmt.Printf("Block:%s\n", block.String())
blocks = append(blocks, block) blocks = append(blocks, block)
} }