Use ioutil.ReadFile()

This commit is contained in:
Ivan Izaguirre 2019-05-15 16:01:04 +02:00
parent 9fa6b4d1c0
commit 51c7a8cb57
4 changed files with 14 additions and 64 deletions

View File

@ -1,10 +1,9 @@
package apple2
import (
"bufio"
"fmt"
"go6502/core6502"
"os"
"io/ioutil"
"time"
)
@ -185,24 +184,14 @@ func (a *Apple2) releaseFastMode() {
}
func (a *Apple2) loadRom(filename string) {
f, err := os.Open(filename)
bytes, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
defer f.Close()
stats, statsErr := f.Stat()
if statsErr != nil {
panic(err)
}
size := stats.Size()
size := len(bytes)
if size != apple2RomSize && size != apple2eRomSize {
panic("Rom size not supported")
}
bytes := make([]byte, size)
buf := bufio.NewReader(f)
buf.Read(bytes)
romStart := 0
if size == apple2eRomSize {

View File

@ -1,9 +1,6 @@
package apple2
import (
"bufio"
"os"
)
import "io/ioutil"
/*
https://applesaucefdc.com/woz/reference2/
@ -141,29 +138,19 @@ func newCardDisk2(filename string) *cardDisk2 {
}
func loadCardRom(filename string) []memoryPage {
f, err := os.Open(filename)
bytes, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
defer f.Close()
stats, statsErr := f.Stat()
if statsErr != nil {
panic(err)
}
size := stats.Size()
bytes := make([]byte, size)
buf := bufio.NewReader(f)
buf.Read(bytes)
size := len(bytes)
pages := size / 256
if (size % 256) > 0 {
pages++
}
rom := make([]romPage, pages)
for i := int64(0); i < size; i++ {
for i := 0; i < size; i++ {
rom[i>>8].burn(uint8(i), bytes[i])
}

View File

@ -1,9 +1,8 @@
package apple2
import (
"bufio"
"fmt"
"os"
"io/ioutil"
)
/*
@ -28,24 +27,15 @@ func NewCharacterGenerator(filename string) *CharacterGenerator {
}
func (cg *CharacterGenerator) load(filename string) {
f, err := os.Open(filename)
bytes, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
defer f.Close()
stats, statsErr := f.Stat()
if statsErr != nil {
panic(err)
}
size := stats.Size()
size := len(bytes)
if size != rev7CharGenSize {
panic("Character ROM size not supported")
}
cg.data = make([]uint8, size)
buf := bufio.NewReader(f)
buf.Read(cg.data)
cg.data = bytes
}
func (cg *CharacterGenerator) getPixel(char uint8, row int, column int) bool {

View File

@ -1,9 +1,6 @@
package core6502
import (
"bufio"
"os"
)
import "io/ioutil"
// Memory represents the addressable space of the processor
type Memory interface {
@ -19,7 +16,7 @@ func getZeroPageWord(m Memory, address uint8) uint16 {
return uint16(m.Peek(uint16(address))) + 0x100*uint16(m.Peek(uint16(address+1)))
}
// FlatMemory puts RAM on the 64Kb addeessable by the processor
// FlatMemory puts RAM on the 64Kb addressable by the processor
type FlatMemory struct {
data [65536]uint8
}
@ -35,23 +32,10 @@ func (m *FlatMemory) Poke(address uint16, value uint8) {
}
func (m *FlatMemory) loadBinary(filename string) {
// Load file
f, err := os.Open(filename)
bytes, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
defer f.Close()
stats, statsErr := f.Stat()
if statsErr != nil {
panic(err)
}
size := stats.Size()
bytes := make([]byte, size)
buf := bufio.NewReader(f)
buf.Read(bytes)
for i, v := range bytes {
m.Poke(uint16(i), uint8(v))