2019-04-21 19:04:02 +00:00
|
|
|
package apple2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
"image/png"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2019-05-02 10:21:07 +00:00
|
|
|
/*
|
|
|
|
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)
|
2019-04-27 22:13:34 +00:00
|
|
|
// 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 {
|
2019-05-01 14:54:53 +00:00
|
|
|
//return snapshotTextMode(a, pageIndex)
|
|
|
|
return linesSeparatedFilter(snapshotTextMode(a, pageIndex))
|
2019-04-26 16:08:30 +00:00
|
|
|
} else {
|
|
|
|
if isHiResMode {
|
2019-04-27 22:13:34 +00:00
|
|
|
//return snapshotHiResModeReferenceMono(a, pageIndex)
|
2019-05-03 16:19:57 +00:00
|
|
|
//return linesSeparatedFilter(snapshotHiResModeMonoShift(a, pageIndex))
|
2019-05-03 18:01:23 +00:00
|
|
|
return linesSeparatedFilter(filterNTSCColorMoving(false, snapshotHiResModeMonoShift(a, pageIndex)))
|
|
|
|
//return linesSeparatedFilter(filterNTSCColorStatic(snapshotHiResModeMonoShift(a, pageIndex)))
|
2019-05-03 16:19:57 +00:00
|
|
|
|
2019-05-02 10:21:07 +00:00
|
|
|
//return snapshotHiResModeReferenceColor(a, pageIndex)
|
2019-04-27 22:13:34 +00:00
|
|
|
//return snapshotHiResModeReferenceColorSolid(a, pageIndex)
|
2019-04-26 16:08:30 +00:00
|
|
|
} else {
|
2019-04-27 22:13:34 +00:00
|
|
|
// 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
|
|
|
|
2019-04-27 22:13:34 +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)
|
|
|
|
}
|
|
|
|
|
2019-05-01 14:54:53 +00:00
|
|
|
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
|
|
|
|
}
|