izapple2/characterGenerator.go

83 lines
1.7 KiB
Go
Raw Normal View History

2019-04-21 16:18:43 +00:00
package apple2
import (
"fmt"
)
/*
See:
hhttps://mirrors.apple2.org.za/Apple%20II%20Documentation%20Project/Companies/Apple/Documentation/Apple%20Technical%20Information%20Library/a2til041.txt
*/
// CharacterGenerator represents the ROM wth the characters bitmaps
type CharacterGenerator struct {
data []uint8
}
const (
rev7CharGenSize = 2048
)
// NewCharacterGenerator instantiates a new Character Generator with the rom on the file given
func NewCharacterGenerator(filename string) *CharacterGenerator {
var cg CharacterGenerator
cg.load(filename)
return &cg
}
func (cg *CharacterGenerator) load(filename string) {
bytes := loadResource(filename)
2019-05-15 14:01:04 +00:00
size := len(bytes)
2019-04-21 16:18:43 +00:00
if size != rev7CharGenSize {
panic("Character ROM size not supported")
}
2019-05-15 14:01:04 +00:00
cg.data = bytes
2019-04-21 16:18:43 +00:00
}
2019-04-21 19:04:02 +00:00
func (cg *CharacterGenerator) getPixel(char uint8, row int, column int) bool {
bits := cg.data[int(char)*8+row]
bit := bits >> (uint(6 - column)) & 1
return bit == 1
}
func (cg *CharacterGenerator) dumpCharFast(char uint8) {
2019-04-21 16:18:43 +00:00
base := int(char) * 8
fmt.Printf("Char: %v\n---------\n", char)
for i := 0; i < 8; i++ {
fmt.Print("|")
b := cg.data[base+i]
for j := 6; j >= 0; j-- {
if (b>>uint(j))&1 == 1 {
fmt.Print("#")
} else {
fmt.Print(" ")
}
}
fmt.Println("|")
}
fmt.Println("---------")
}
2019-04-21 19:04:02 +00:00
func (cg *CharacterGenerator) dumpChar(char uint8) {
fmt.Printf("Char: %v\n---------\n", char)
for row := 0; row < 8; row++ {
fmt.Print("|")
for col := 0; col < 7; col++ {
if cg.getPixel(char, row, col) {
fmt.Print("#")
} else {
fmt.Print(" ")
}
}
fmt.Println("|")
}
fmt.Println("---------")
}
// Dump to sdtout all the character maps
2019-04-21 16:18:43 +00:00
func (cg *CharacterGenerator) Dump() {
for i := 0; i < 256; i++ {
cg.dumpChar(uint8(i))
}
}