mirror of
https://github.com/tjboldt/ProDOS-Utilities.git
synced 2024-11-28 12:51:35 +00:00
39 lines
975 B
Go
39 lines
975 B
Go
// Copyright Terence J. Boldt (c)2021-2023
|
|
// Use of this source code is governed by an MIT
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// This file provides access to read and write
|
|
// blocks on a ProDOS drive image
|
|
|
|
package prodos
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
// ReadBlock reads a block from a ProDOS volume into a byte array
|
|
func ReadBlock(reader io.ReaderAt, block int) ([]byte, error) {
|
|
buffer := make([]byte, 512)
|
|
|
|
_, err := reader.ReadAt(buffer, int64(block)*512)
|
|
if err != nil {
|
|
errString := fmt.Sprintf("failed to read block %04X: %s", block, err.Error())
|
|
err = errors.New(errString)
|
|
}
|
|
|
|
return buffer, err
|
|
}
|
|
|
|
// WriteBlock writes a block to a ProDOS volume from a byte array
|
|
func WriteBlock(writer io.WriterAt, block int, buffer []byte) error {
|
|
_, err := writer.WriteAt(buffer, int64(block)*512)
|
|
if err != nil {
|
|
errString := fmt.Sprintf("failed to write block %04X: %s", block, err.Error())
|
|
err = errors.New(errString)
|
|
}
|
|
|
|
return err
|
|
}
|