From 9fcd4992410837c1f606edc94932ae27af88176d Mon Sep 17 00:00:00 2001 From: Ivan Izaguirre Date: Wed, 1 May 2019 16:54:53 +0200 Subject: [PATCH] Improved CRT sumulation. P1 phosphor green and vertical line separation. --- apple2/screen.go | 29 ++++++++++++++++++++++++++--- apple2sdl/run.go | 3 ++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/apple2/screen.go b/apple2/screen.go index 53fb968..e01c372 100644 --- a/apple2/screen.go +++ b/apple2/screen.go @@ -19,7 +19,8 @@ func Snapshot(a *Apple2) *image.RGBA { } if isTextMode { - return snapshotTextMode(a, pageIndex) + //return snapshotTextMode(a, pageIndex) + return linesSeparatedFilter(snapshotTextMode(a, pageIndex)) } else { if isHiResMode { //return snapshotHiResModeReferenceMono(a, pageIndex) @@ -52,6 +53,22 @@ func saveSnapshot(a *Apple2) { 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 +} + const ( charWidth = 7 charHeight = 8 @@ -86,6 +103,10 @@ func getTextChar(a *Apple2, col int, line int, page int) uint8 { func snapshotTextMode(a *Apple2, page int) *image.RGBA { // TODO: Missing inverse and flash modes + // Color for typical Apple ][ period green phosphor monitors + // See: https://superuser.com/questions/361297/what-colour-is-the-dark-green-on-old-fashioned-green-screen-computer-displays + p1GreenPhosphorColor := color.RGBA{65, 255, 0, 255} + width := textColumns * charWidth height := textLines * charHeight size := image.Rect(0, 0, width, height) @@ -99,9 +120,11 @@ func snapshotTextMode(a *Apple2, page int) *image.RGBA { colInChar := x % charWidth char := getTextChar(a, col, line, page) pixel := a.cg.getPixel(char, rowInChar, colInChar) - colour := color.Black + var colour color.Color if pixel { - colour = color.White + colour = p1GreenPhosphorColor + } else { + colour = color.Black } img.Set(x, y, colour) } diff --git a/apple2sdl/run.go b/apple2sdl/run.go index cec4778..be2b841 100644 --- a/apple2sdl/run.go +++ b/apple2sdl/run.go @@ -44,7 +44,8 @@ func SDLRun(a *apple2.Apple2) { img := apple2.Snapshot(a) if img != nil { - surface, err := sdl.CreateRGBSurfaceFrom(unsafe.Pointer(&img.Pix[0]), 40*7, 24*8, 32, 40*7*4, + surface, err := sdl.CreateRGBSurfaceFrom(unsafe.Pointer(&img.Pix[0]), + int32(img.Bounds().Dx()), int32(img.Bounds().Dy()), 32, 40*7*4, 0x0000ff, 0x0000ff00, 0x00ff0000, 0xff000000) // Valid for little endian. Should we reverse for big endian? // 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff)