Skip to content

Commit

Permalink
peek and poke double words
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanizag committed Sep 6, 2021
1 parent b69cdbe commit e1ab9e0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
14 changes: 14 additions & 0 deletions acornMemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ func (m *acornMemory) pokeWord(address uint16, value uint16) {
m.Poke(address+1, uint8(value>>8))
}

func (m *acornMemory) peekDoubleWord(address uint16) uint32 {
return uint32(m.Peek(address)) +
uint32(m.Peek(address+1))<<8 +
uint32(m.Peek(address+2))<<16 +
uint32(m.Peek(address+3))<<24
}

func (m *acornMemory) pokeDoubleWord(address uint16, value uint32) {
m.Poke(address, uint8(value))
m.Poke(address+1, uint8(value>>8))
m.Poke(address+2, uint8(value>>16))
m.Poke(address+3, uint8(value>>24))
}

func (m *acornMemory) peeknbytes(address uint16, n int) uint64 {
ticks := uint64(0)
for i := n - 1; i >= 0; i-- {
Expand Down
6 changes: 3 additions & 3 deletions osArgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func execOSARGS(env *environment) {
if err != nil {
env.raiseError(errorTodo, err.Error())
} else {
env.mem.pokenbytes(uint16(x), 4, uint64(pos))
env.mem.pokeDoubleWord(uint16(x), uint32(pos))
}
env.log(fmt.Sprintf("OSARGS('Get PTR#',FILE=%v) => %v", y, pos))

case 1: // Write sequential pointer of file
pos := int64(env.mem.peeknbytes(uint16(x), 4))
pos := int64(env.mem.peekDoubleWord(uint16(x)))
_, err := file.Seek(pos, io.SeekStart)
if err != nil {
env.raiseError(errorTodo, err.Error())
Expand All @@ -65,7 +65,7 @@ func execOSARGS(env *environment) {
if err != nil {
env.raiseError(errorTodo, err.Error())
} else {
env.mem.pokenbytes(uint16(x), 4, uint64(info.Size()))
env.mem.pokeDoubleWord(uint16(x), uint32(info.Size()))
}
env.log(fmt.Sprintf("OSARGS('Get EXT#',FILE=%v)=%v", y, info.Size()))

Expand Down
16 changes: 8 additions & 8 deletions osFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func execOSFILE(env *environment) {
// See: http://beebwiki.mdfs.net/OSFILE
controlBlock := uint16(x) + uint16(y)<<8
filenameAddress := env.mem.peekWord(controlBlock)
loadAddress := uint32(env.mem.peeknbytes(controlBlock+cbLoadAddress, 4))
executionAddress := uint32(env.mem.peeknbytes(controlBlock+cbExecutionAddress, 4))
startAddress := uint32(env.mem.peeknbytes(controlBlock+cbStartAddressOrSize, 4))
endAddress := uint32(env.mem.peeknbytes(controlBlock+cbEndAddressOrAttributes, 4))
loadAddress := env.mem.peekDoubleWord(controlBlock + cbLoadAddress)
executionAddress := env.mem.peekDoubleWord(controlBlock + cbExecutionAddress)
startAddress := env.mem.peekDoubleWord(controlBlock + cbStartAddressOrSize)
endAddress := env.mem.peekDoubleWord(controlBlock + cbEndAddressOrAttributes)

filename := env.mem.getString(filenameAddress, 0x0d)

Expand All @@ -65,10 +65,10 @@ func execOSFILE(env *environment) {
*/
attr := getFileAttributes(env, filename)
if attr.fileType != osNotFound {
env.mem.pokenbytes(controlBlock+cbStartAddressOrSize, 4, uint64(attr.fileSize))
env.mem.pokeDoubleWord(controlBlock+cbStartAddressOrSize, attr.fileSize)
if attr.hasMetadata {
env.mem.pokenbytes(controlBlock+cbLoadAddress, 4, uint64(attr.loadAddress))
env.mem.pokenbytes(controlBlock+cbExecutionAddress, 4, uint64(attr.executionAddress))
env.mem.pokeDoubleWord(controlBlock+cbLoadAddress, attr.loadAddress)
env.mem.pokeDoubleWord(controlBlock+cbExecutionAddress, attr.executionAddress)
}
}
newA = attr.fileType
Expand All @@ -89,7 +89,7 @@ func execOSFILE(env *environment) {
}

attr := loadFile(env, filename, loadAddress)
env.mem.pokenbytes(controlBlock+cbStartAddressOrSize, 4, uint64(attr.fileSize))
env.mem.pokeDoubleWord(controlBlock+cbStartAddressOrSize, attr.fileSize)
newA = attr.fileType

default:
Expand Down
12 changes: 6 additions & 6 deletions osGbpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func execOSGBPB(env *environment) {

controlBlock := uint16(x) + uint16(y)<<8
handle := env.mem.Peek(controlBlock)
address := uint32(env.mem.peeknbytes(controlBlock+cbDataAddress, 4))
count := uint32(env.mem.peeknbytes(controlBlock+cbDataCount, 4))
offset := uint32(env.mem.peeknbytes(controlBlock+cbDataOffset, 4))
address := env.mem.peekDoubleWord(controlBlock + cbDataAddress)
count := env.mem.peekDoubleWord(controlBlock + cbDataCount)
offset := env.mem.peekDoubleWord(controlBlock + cbDataOffset)

error := false
file := env.getFile(handle)
Expand Down Expand Up @@ -91,9 +91,9 @@ func execOSGBPB(env *environment) {
}

// Update the file control block
env.mem.pokenbytes(controlBlock+cbDataAddress, 4, uint64(address+transferred))
env.mem.pokenbytes(controlBlock+cbDataCount, 4, uint64(count-transferred))
env.mem.pokenbytes(controlBlock+cbDataOffset, 4, uint64(offset+transferred))
env.mem.pokeDoubleWord(controlBlock+cbDataAddress, address+transferred)
env.mem.pokeDoubleWord(controlBlock+cbDataCount, count-transferred)
env.mem.pokeDoubleWord(controlBlock+cbDataOffset, offset+transferred)

newP := p
if count-transferred != 0 {
Expand Down

0 comments on commit e1ab9e0

Please sign in to comment.