Skip to content

Commit

Permalink
fix: fix byte order in amsdos header.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsaxione committed Feb 25, 2019
1 parent fa9832c commit 1ebf834
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions cpc/cpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ import (

// CpcHead structure describes the Amsdos header
type CpcHead struct {
User byte
Filename [8]byte
Extension [3]byte
NotUsed [6]byte
Type byte
NotUsed2 [2]byte
Address byte
Pad byte
Size byte
Exec byte
NotUsed3 [36]byte
Size2 byte
Pad2 byte
Checksum byte
NotUsed4 [59]byte
User byte
Filename [15]byte
BlockNum byte
LastBlock byte
Type byte
Size int16
Address int16
FirstBlock byte
LogicalSize int16
Exec int16
NotUsed [0x24]byte
Size2 int16
BigLength byte
Checksum int16
NotUsed4 [0x3B]byte
}

func NewCpcHeader(f *os.File) (*CpcHead, error) {
header := &CpcHead{}
data := make([]byte, 123)
data := make([]byte, 128)
_, err := f.Read(data)
if err != nil {
return &CpcHead{}, err
Expand All @@ -42,12 +42,27 @@ func NewCpcHeader(f *os.File) (*CpcHead, error) {
return header, nil
}

func (c *CpcHead) Checksum16() uint8 {
var checksum uint8
checksum += c.User
return checksum
}

// ToString Will dislay the CpcHead structure content
func (c *CpcHead) ToString() string {
return fmt.Sprintf("User:%x\nFilename:%s\nExtension:%s\n",
return fmt.Sprintf("User:%x\nFilename:%s\nType:%d\nSize:&%.2x\nAddress of loading:&%.2x\nAddress of execution:&%.2x\nChecksum:&%.2x\n",
int(c.User),
string(c.Filename[:]),
string(c.Extension[:]))
c.Type,
c.Size2,
c.Address,
c.Exec,
c.Checksum)
}

func (c *CpcHead) PrettyPrint() {
fmt.Printf("%x", *c)
return
}

var (
Expand Down
Binary file removed m4client
Binary file not shown.

0 comments on commit 1ebf834

Please sign in to comment.