izapple2/apple2/screen.go

82 lines
1.9 KiB
Go
Raw Normal View History

2019-04-21 19:04:02 +00:00
package apple2
import (
"fmt"
"image"
"image/color"
"image/png"
"os"
)
/*
References:
- "Understanding the Apple II", http://www.applelogic.org/files/UNDERSTANDINGTHEAII.pdf
- "Apple II Reference Manual"
- "More Colors for your Apple", https://archive.org/details/byte-magazine-1979-06/page/n61
*/
2019-04-21 22:18:14 +00:00
// Snapshot the currently visible screen
func Snapshot(a *Apple2) *image.RGBA {
2019-04-26 16:08:30 +00:00
isTextMode := a.io.isSoftSwitchActive(ioFlagText)
isHiResMode := a.io.isSoftSwitchActive(ioFlagHiRes)
// Todo: isMixMode
2019-04-21 19:04:02 +00:00
pageIndex := 0
if a.io.isSoftSwitchActive(ioFlagSecondPage) {
pageIndex = 1
}
2019-04-26 16:08:30 +00:00
if isTextMode {
//return snapshotTextMode(a, pageIndex)
return linesSeparatedFilter(snapshotTextMode(a, pageIndex))
2019-04-26 16:08:30 +00:00
} else {
if isHiResMode {
//return snapshotHiResModeReferenceMono(a, pageIndex)
//return linesSeparatedFilter(snapshotHiResModeMonoShift(a, pageIndex))
return linesSeparatedFilter(filterNTSCColorMoving(false, snapshotHiResModeMonoShift(a, pageIndex)))
//return linesSeparatedFilter(filterNTSCColorStatic(snapshotHiResModeMonoShift(a, pageIndex)))
//return snapshotHiResModeReferenceColor(a, pageIndex)
//return snapshotHiResModeReferenceColorSolid(a, pageIndex)
2019-04-26 16:08:30 +00:00
} else {
// Lo res mode not supported
2019-04-26 16:08:30 +00:00
}
2019-04-21 19:04:02 +00:00
}
2019-04-26 16:08:30 +00:00
//fmt.Printf("g: %v, h: %v\n", isTextMode, isHiResMode)
2019-04-21 19:04:02 +00:00
return nil
//panic("Screen mode not supported")
}
func saveSnapshot(a *Apple2) {
2019-04-21 22:18:14 +00:00
img := Snapshot(a)
2019-04-21 19:04:02 +00:00
if img == nil {
return
}
f, err := os.Create("snapshot.png")
if err != nil {
panic(err)
}
defer f.Close()
fmt.Println("Saving snapshot")
png.Encode(f, img)
}
func linesSeparatedFilter(in *image.RGBA) *image.RGBA {
b := in.Bounds()
size := image.Rect(0, 0, b.Dx(), 4*b.Dy())
out := image.NewRGBA(size)
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
c := in.At(x, y)
out.Set(x, 4*y, c)
out.Set(x, 4*y+1, c)
out.Set(x, 4*y+2, c)
out.Set(x, 4*y+3, color.Black)
}
}
return out
}