izapple2/screen/hiRes.go

63 lines
1.6 KiB
Go
Raw Permalink Normal View History

2020-10-16 18:41:34 +00:00
package screen
2019-05-03 18:09:53 +00:00
import (
"image"
"image/color"
)
2019-05-03 19:45:29 +00:00
const (
2020-10-16 18:41:34 +00:00
hiResWidth = 280
hiResLineBytes = hiResWidth / 7
hiResHeight = 192
hiResHeightMixed = 160
2019-05-03 19:45:29 +00:00
)
2024-02-08 19:24:37 +00:00
func snapshotHiRes(vs VideoSource, isSecondPage bool, light color.Color, shiftSupported bool) *image.RGBA {
2020-10-16 18:41:34 +00:00
data := vs.GetVideoMemory(isSecondPage, false)
2024-02-08 19:24:37 +00:00
return renderHiRes(data, light, shiftSupported)
2020-10-16 18:41:34 +00:00
}
2019-05-03 18:09:53 +00:00
2020-10-16 18:41:34 +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
outerEighth := (line >> 3) & 0x07
innerEighth := line & 0x07
return uint16(section*40 + outerEighth*0x80 + innerEighth*0x400)
2019-05-03 18:09:53 +00:00
}
2024-02-08 19:24:37 +00:00
func renderHiRes(data []uint8, light color.Color, shiftSupported bool) *image.RGBA {
2019-05-03 18:09:53 +00:00
// As described in "Undertanding the Apple II", with half pixel shifts
size := image.Rect(0, 0, 2*hiResWidth, hiResHeight)
2019-05-03 18:09:53 +00:00
img := image.NewRGBA(size)
for y := 0; y < hiResHeight; y++ {
2020-10-16 18:41:34 +00:00
offset := getHiResLineOffset(y)
bytes := data[offset : offset+hiResLineBytes]
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 {
2024-02-08 19:24:37 +00:00
shifted := shiftSupported && b>>7 == 1
2019-05-03 18:09:53 +00:00
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 {
2020-11-03 17:41:10 +00:00
// "The general rule of all these HIRES interference patterns is that delayed extends
// undelayed, and undelayed cuts off delayed"
2019-05-03 18:09:53 +00:00
img.Set(x, y, previousColour)
} else {
img.Set(x, y, colour)
}
img.Set(x+1, y, colour)
previousColour = colour
x += 2
}
}
}
return img
}