1
0
mirror of https://github.com/irmen/ksim65.git synced 2024-06-14 13:29:35 +00:00

c64 screen aspect ratio correction

This commit is contained in:
Irmen de Jong 2020-01-27 02:48:37 +01:00
parent 67a3131ce5
commit 0a9e8b293d
3 changed files with 19 additions and 18 deletions

View File

@ -21,7 +21,8 @@ object ScreenDefs {
const val SCREEN_HEIGHT_CHARS = 25
const val SCREEN_WIDTH = SCREEN_WIDTH_CHARS*8
const val SCREEN_HEIGHT = SCREEN_HEIGHT_CHARS*8
const val DISPLAY_PIXEL_SCALING: Double = 3.0
const val PIXEL_SCALING = 3.0
const val ASPECT_RATIO = 1.06 // c64 PAL pixels are slightly taller than wide
const val BORDER_SIZE = 24
class Palette {

View File

@ -28,8 +28,8 @@ internal class Screen(private val chargenData: ByteArray, val ram: MemoryCompone
ScreenDefs.SCREEN_HEIGHT+2*ScreenDefs.BORDER_SIZE, Transparency.OPAQUE)
fullscreenG2d = fullscreenImage.graphics as Graphics2D
val size = Dimension(fullscreenImage.width*ScreenDefs.DISPLAY_PIXEL_SCALING.toInt(),
fullscreenImage.height*ScreenDefs.DISPLAY_PIXEL_SCALING.toInt())
val size = Dimension(fullscreenImage.width*ScreenDefs.PIXEL_SCALING.toInt(),
(fullscreenImage.height*ScreenDefs.ASPECT_RATIO*ScreenDefs.PIXEL_SCALING).toInt())
minimumSize = size
maximumSize = size
preferredSize = size
@ -84,13 +84,13 @@ internal class Screen(private val chargenData: ByteArray, val ram: MemoryCompone
// scale and draw the image to the window, and simulate a slight scanline effect
windowG2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
windowG2d.drawImage(fullscreenImage, 0, 0, (fullscreenImage.width*ScreenDefs.DISPLAY_PIXEL_SCALING).toInt(),
(fullscreenImage.height*ScreenDefs.DISPLAY_PIXEL_SCALING).toInt(), null)
windowG2d.drawImage(fullscreenImage, 0, 0, (fullscreenImage.width*ScreenDefs.PIXEL_SCALING).toInt(),
(fullscreenImage.height*ScreenDefs.ASPECT_RATIO*ScreenDefs.PIXEL_SCALING).toInt(), null)
windowG2d.color = Color(0, 0, 0, 40)
windowG2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
val width = fullscreenImage.width*ScreenDefs.DISPLAY_PIXEL_SCALING.toInt()
val height = fullscreenImage.height*ScreenDefs.DISPLAY_PIXEL_SCALING.toInt()
for (y in 0 until height step ScreenDefs.DISPLAY_PIXEL_SCALING.toInt()) {
val width = fullscreenImage.width*ScreenDefs.PIXEL_SCALING.toInt()
val height = (fullscreenImage.height*ScreenDefs.ASPECT_RATIO*ScreenDefs.PIXEL_SCALING).toInt()
for (y in 0 until height step (ScreenDefs.ASPECT_RATIO*ScreenDefs.PIXEL_SCALING).toInt()) {
windowG2d.drawLine(0, y, width, y)
}
Toolkit.getDefaultToolkit().sync()

View File

@ -19,7 +19,7 @@ object ScreenDefs {
const val SCREEN_HEIGHT_CHARS = 30
const val SCREEN_WIDTH = SCREEN_WIDTH_CHARS*8
const val SCREEN_HEIGHT = SCREEN_HEIGHT_CHARS*16
const val DISPLAY_PIXEL_SCALING: Double = 1.5
const val PIXEL_SCALING = 1.5
const val BORDER_SIZE = 32
val BG_COLOR = Color(0, 10, 20)
@ -68,8 +68,8 @@ private class BitmapScreenPanel : JPanel() {
image = gd.createCompatibleImage(ScreenDefs.SCREEN_WIDTH, ScreenDefs.SCREEN_HEIGHT, Transparency.OPAQUE)
g2d = image.graphics as Graphics2D
val size = Dimension((image.width*ScreenDefs.DISPLAY_PIXEL_SCALING).toInt(),
(image.height*ScreenDefs.DISPLAY_PIXEL_SCALING).toInt())
val size = Dimension((image.width*ScreenDefs.PIXEL_SCALING).toInt(),
(image.height*ScreenDefs.PIXEL_SCALING).toInt())
minimumSize = size
maximumSize = size
preferredSize = size
@ -82,13 +82,13 @@ private class BitmapScreenPanel : JPanel() {
override fun paint(graphics: Graphics) {
val g2d = graphics as Graphics2D
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
g2d.drawImage(image, 0, 0, (image.width*ScreenDefs.DISPLAY_PIXEL_SCALING).toInt(),
(image.height*ScreenDefs.DISPLAY_PIXEL_SCALING).toInt(), null)
g2d.drawImage(image, 0, 0, (image.width*ScreenDefs.PIXEL_SCALING).toInt(),
(image.height*ScreenDefs.PIXEL_SCALING).toInt(), null)
if (cursorState) {
val scx = (cursorX*ScreenDefs.DISPLAY_PIXEL_SCALING*8).toInt()
val scy = (cursorY*ScreenDefs.DISPLAY_PIXEL_SCALING*16).toInt()
val scw = (8*ScreenDefs.DISPLAY_PIXEL_SCALING).toInt()
val sch = (16*ScreenDefs.DISPLAY_PIXEL_SCALING).toInt()
val scx = (cursorX*ScreenDefs.PIXEL_SCALING*8).toInt()
val scy = (cursorY*ScreenDefs.PIXEL_SCALING*16).toInt()
val scw = (8*ScreenDefs.PIXEL_SCALING).toInt()
val sch = (16*ScreenDefs.PIXEL_SCALING).toInt()
g2d.setXORMode(Color.CYAN)
g2d.fillRect(scx, scy, scw, sch)
g2d.setPaintMode()
@ -123,7 +123,7 @@ private class BitmapScreenPanel : JPanel() {
fun mousePixelPosition(): Point? {
val pos = mousePosition ?: return null
return Point((pos.x/ScreenDefs.DISPLAY_PIXEL_SCALING).toInt(), (pos.y/ScreenDefs.DISPLAY_PIXEL_SCALING).toInt())
return Point((pos.x/ScreenDefs.PIXEL_SCALING).toInt(), (pos.y/ScreenDefs.PIXEL_SCALING).toInt())
}
fun cursorPos(x: Int, y: Int) {