From c2a6fc7fa37b52065f458921b633a46563377214 Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Fri, 12 Dec 2025 23:37:13 -0500 Subject: [PATCH] Add the 0x05 block type; Remove --extract from fdslist - Block type 0x05 is some weird test pattern thing??? - Removed --extract from the fdslist utility --- blocks.go | 19 +++++++++++++++++++ cmd/fdslist.go | 46 +++++++++++++++++++++------------------------- reader.go | 28 +++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 26 deletions(-) diff --git a/blocks.go b/blocks.go index 0a79104..379399e 100644 --- a/blocks.go +++ b/blocks.go @@ -2,6 +2,7 @@ package fds import ( "fmt" + "strings" ) type BlockType byte @@ -11,6 +12,7 @@ const ( BtFileAmount BlockType = 0x02 BtFileHeader BlockType = 0x03 BtFileData BlockType = 0x04 + BtTest BlockType = 0x05 ) func (bt BlockType) String() string { @@ -192,3 +194,20 @@ func (b *BlockFileData) Type() BlockType { func (b *BlockFileData) String() string { 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, " ")) +} + diff --git a/cmd/fdslist.go b/cmd/fdslist.go index 7e25e1d..a208c5d 100644 --- a/cmd/fdslist.go +++ b/cmd/fdslist.go @@ -3,10 +3,6 @@ package main import ( "fmt" "os" - //"encoding/binary" - //"bufio" - //"bytes" - //"io" "path/filepath" "github.com/alexflint/go-arg" @@ -16,7 +12,8 @@ import ( type Arguments struct { 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 { + 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) if err != nil { return err @@ -39,26 +55,6 @@ func run(args *Arguments) error { 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 } diff --git a/reader.go b/reader.go index a03186a..55e6e3b 100644 --- a/reader.go +++ b/reader.go @@ -52,6 +52,7 @@ func ReadBlocks(r io.Reader, IsFds bool) ([]DiskBlock, error) { reader := bufio.NewReader(r) + outerLoop: for { raw, err := reader.Peek(1) if err != nil { @@ -79,6 +80,31 @@ func ReadBlocks(r io.Reader, IsFds bool) ([]DiskBlock, error) { // variable length 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: reader.Discard(1) continue @@ -144,9 +170,9 @@ func ReadBlocks(r io.Reader, IsFds bool) ([]DiskBlock, error) { db.Data = buf[1:readLen] //fmt.Println("len(db.Data)", len(db.Data)) block = db - //fmt.Printf("Block:%#v\n", block) } + //fmt.Printf("Block:%s\n", block.String()) blocks = append(blocks, block) }