2019-05-03 18:09:53 +00:00
|
|
|
package apple2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
)
|
|
|
|
|
2019-05-03 19:45:29 +00:00
|
|
|
const (
|
2019-05-12 17:22:32 +00:00
|
|
|
hiResWidth = 280
|
2019-11-09 16:44:04 +00:00
|
|
|
hiResLineBytes = hiResWidth / 7
|
2019-05-12 17:22:32 +00:00
|
|
|
hiResHeight = 192
|
|
|
|
hiResHeightMixed = 160
|
|
|
|
hiResPage1Address = uint16(0x2000)
|
|
|
|
hiResPage2Address = uint16(0x4000)
|
2019-05-03 19:45:29 +00:00
|
|
|
)
|
|
|
|
|
2019-05-12 17:22:32 +00:00
|
|
|
func getHiResLineOffset(line int) uint16 {
|
2019-05-03 18:09:53 +00:00
|
|
|
|
|
|
|
// See "Understanding the Apple II", page 5-14
|
|
|
|
// http://www.applelogic.org/files/UNDERSTANDINGTHEAII.pdf
|
|
|
|
section := line >> 6 // Top, middle and bottom
|
2020-08-08 11:44:45 +00:00
|
|
|
outerEighth := (line >> 3) & 0x07
|
|
|
|
innerEighth := line & 0x07
|
|
|
|
return uint16(section*40 + outerEighth*0x80 + innerEighth*0x400)
|
2019-05-03 18:09:53 +00:00
|
|
|
}
|
|
|
|
|
2019-11-09 16:44:04 +00:00
|
|
|
func getHiResLine(a *Apple2, line int, isSecondPage bool, auxMem bool) []uint8 {
|
2019-05-12 17:22:32 +00:00
|
|
|
address := hiResPage1Address
|
2019-11-09 16:44:04 +00:00
|
|
|
if isSecondPage {
|
2019-05-12 17:22:32 +00:00
|
|
|
address = hiResPage2Address
|
2019-05-03 18:09:53 +00:00
|
|
|
}
|
|
|
|
|
2019-05-12 17:22:32 +00:00
|
|
|
address += getHiResLineOffset(line)
|
2019-11-09 16:44:04 +00:00
|
|
|
return a.mmu.getPhysicalMainRAM(auxMem).subRange(address, address+hiResLineBytes)
|
2019-05-03 18:09:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-08 11:44:45 +00:00
|
|
|
func snapshotHiResModeMono(a *Apple2, isSecondPage bool, light color.Color) *image.RGBA {
|
2019-05-03 18:09:53 +00:00
|
|
|
// As described in "Undertanding the Apple II", with half pixel shifts
|
2020-08-08 11:44:45 +00:00
|
|
|
size := image.Rect(0, 0, 2*hiResWidth, hiResHeight)
|
2019-05-03 18:09:53 +00:00
|
|
|
img := image.NewRGBA(size)
|
|
|
|
|
2020-08-08 11:44:45 +00:00
|
|
|
for y := 0; y < hiResHeight; y++ {
|
2019-11-09 16:44:04 +00:00
|
|
|
bytes := getHiResLine(a, y, isSecondPage, false /*auxMem*/)
|
2019-05-03 18:09:53 +00:00
|
|
|
x := 0
|
2019-05-05 11:25:45 +00:00
|
|
|
var previousColour color.Color = color.Black
|
2019-05-03 18:09:53 +00:00
|
|
|
for _, b := range bytes {
|
|
|
|
shifted := b>>7 == 1
|
|
|
|
for j := uint(0); j < 7; j++ {
|
|
|
|
bit := (b >> j) & 1
|
2019-05-05 11:25:45 +00:00
|
|
|
colour := light
|
|
|
|
if bit == 0 {
|
|
|
|
colour = color.Black
|
2019-05-03 18:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if shifted {
|
|
|
|
img.Set(x, y, previousColour)
|
|
|
|
} else {
|
|
|
|
img.Set(x, y, colour)
|
|
|
|
}
|
|
|
|
img.Set(x+1, y, colour)
|
|
|
|
previousColour = colour
|
|
|
|
x += 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return img
|
|
|
|
}
|