Add ReadRomFile

This function combines ReadRomBlocks() and RomFromBlocks() into a single
function.  The other two functions still exist.
This commit is contained in:
Zorchenhimer 2025-12-07 20:48:38 -05:00
parent cc0e79c72b
commit 172e1211c5
Signed by: Zorchenhimer
GPG Key ID: 70A1AB767AAB9C20
2 changed files with 18 additions and 14 deletions

View File

@ -32,18 +32,7 @@ func main() {
}
func run(args *Arguments) error {
file, err := os.Open(args.Input)
if err != nil {
return err
}
defer file.Close()
blocks, err := fds.ReadRom(file, filepath.Ext(args.Input) == ".fds")
if err != nil {
return err
}
rom, err := fds.RomFromBlocks(filepath.Base(args.Input), blocks)
rom, err := fds.ReadRomFile(args.Input, filepath.Ext(args.Input) == ".fds")
if err != nil {
return err
}

View File

@ -1,7 +1,7 @@
package fds
import (
//"os"
"os"
"fmt"
"io"
"bufio"
@ -11,7 +11,22 @@ import (
"github.com/sigurn/crc16"
)
func ReadRom(r io.Reader, IsFds bool) ([]DiskBlock, error) {
func ReadRomFile(filename string, IsFds bool) (*Rom, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
blocks, err := ReadRomBlocks(file, IsFds)
if err != nil {
return nil, err
}
return RomFromBlocks(filename, blocks)
}
func ReadRomBlocks(r io.Reader, IsFds bool) ([]DiskBlock, error) {
reader := bufio.NewReader(r)
magic, err := reader.Peek(4)
if err != nil {