Skip to content

Commit

Permalink
Populate more entries into FCB, in preparation for file operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed Apr 14, 2024
1 parent b3b0262 commit 18bd957
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 11 deletions.
41 changes: 31 additions & 10 deletions fcb/fcb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@ import (
"strings"
)

// FCB is a placeholder struct.
// FCB is a placeholder struct which is slowly in the process of being used.
type FCB struct {
// Drive holds the drive letter for this entry.
// 0 is A, 1 is B, etc.
// Max value 15.
Drive uint8

// Name holds the name of the file
// Name holds the name of the file.
Name [8]uint8

// Type holds the suffix
// Type holds the suffix.
Type [3]uint8

// Don't yet care about the rest of the entry.
Rest [21]uint8
Ex uint8
S1 uint8
S2 uint8
RC uint8
Al [16]uint8
Cr uint8
R0 uint8
R1 uint8
R2 uint8
}

// GetName returns the name component of an FCB entry.
Expand Down Expand Up @@ -47,15 +52,23 @@ func (f *FCB) GetType() string {
}

// AsBytes returns the entry of the FCB in a format suitable
// for copying to RAM
// for copying to RAM.
func (f *FCB) AsBytes() []uint8 {

var r []uint8

r = append(r, f.Drive)
r = append(r, f.Name[:]...)
r = append(r, f.Type[:]...)
r = append(r, f.Rest[:]...)
r = append(r, f.Ex)
r = append(r, f.S1)
r = append(r, f.S2)
r = append(r, f.RC)
r = append(r, f.Al[:]...)
r = append(r, f.Cr)
r = append(r, f.R0)
r = append(r, f.R1)
r = append(r, f.R2)

return r
}
Expand Down Expand Up @@ -164,7 +177,15 @@ func FromBytes(bytes []uint8) FCB {
tmp.Drive = bytes[0]
copy(tmp.Name[:], bytes[1:])
copy(tmp.Type[:], bytes[9:])
copy(tmp.Rest[:], bytes[11:])
tmp.Ex = bytes[12]
tmp.S1 = bytes[13]
tmp.S2 = bytes[14]
tmp.RC = bytes[15]
copy(tmp.Al[:], bytes[16:])
tmp.Cr = bytes[32]
tmp.R0 = bytes[33]
tmp.R1 = bytes[34]
tmp.R2 = bytes[35]

return tmp
}
55 changes: 54 additions & 1 deletion fcb/fcb_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,59 @@
package fcb

import "testing"
import (
"fmt"
"testing"
)

func TestFCBSize(t *testing.T) {
x := FromString("blah")
b := x.AsBytes()

if len(b) != 36 {
t.Fatalf("FCB struct is %d bytes", len(b))
}
}

// Test we can convert an FCB to bytes, and back, without losing data in the round-trip.
func TestCopy(t *testing.T) {
f1 := FromString("blah")
copy(f1.Al[:], "0123456789abcdef")
f1.Ex = 'X'
f1.S1 = 'S'
f1.S2 = '?'
f1.RC = 'f'
f1.R0 = 'R'
f1.R1 = '0'
f1.R2 = '1'
b := f1.AsBytes()

f2 := FromBytes(b)
if fmt.Sprintf("%s", f2.Al) != "0123456789abcdef" {
t.Fatalf("copy failed")
}
if f2.Ex != 'X' {
t.Fatalf("copy failed")
}
if f2.S1 != 'S' {
t.Fatalf("copy failed")
}
if f2.S2 != '?' {
t.Fatalf("copy failed")
}
if f2.RC != 'f' {
t.Fatalf("copy failed")
}
if f2.R0 != 'R' {
t.Fatalf("copy failed")
}
if f2.R1 != '0' {
t.Fatalf("copy failed")
}
if f2.R2 != '1' {
t.Fatalf("copy failed")
}

}

// TestFCBFromString is a trivial test to only cover the basics right now.
func TestFCBFromString(t *testing.T) {
Expand Down

0 comments on commit 18bd957

Please sign in to comment.