gpu mmio write addrs have been moved around

This commit is contained in:
minjaesong
2022-04-20 10:04:30 +09:00
parent 7cddb2660e
commit 219845e565
5 changed files with 44 additions and 34 deletions

View File

@@ -167,17 +167,12 @@ From the start of the memory space:
12 bytes 12 bytes
argument for "command" (arg1: Byte, arg2: Byte) argument for "command" (arg1: Byte, arg2: Byte)
write to this address FIRST and then write to "command" to execute the command write to this address FIRST and then write to "command" to execute the command
2 bytes 1134 bytes
framebuffer scroll X
2 bytes
framebuffer scroll Y
896 bytes
horizontal scroll offset for scanlines
234 bytes
unused unused
1920 1920
mapped to font ROM mapped to font ROM
Font Mapping area holds 128 characters in consecutive order, each character is always 15 bytes. Font Mapping area holds 128 characters in consecutive order, each character is always 15 bytes.
(designer's note: it's still useful to divide the char rom to two halves, lower half being characters ROM and upper half being symbols ROM)
2 bytes 2 bytes
Cursor position in: (y*80 + x) Cursor position in: (y*80 + x)
2560 bytes 2560 bytes
@@ -316,6 +311,12 @@ MMIO
22 12 22 12
23 21 23 21
If 1 layer is used, this field will do nothing and always fall back to 0 If 1 layer is used, this field will do nothing and always fall back to 0
14..15 RW
framebuffer scroll X
16..17 RW
framebuffer scroll Y
1024..2047 RW
horizontal scroll offset for scanlines
Text-mode-font-ROM is immutable and does not belong to VRAM Text-mode-font-ROM is immutable and does not belong to VRAM
Even in the text mode framebuffer is still being drawn onto the screen, and the texts are drawn on top of it Even in the text mode framebuffer is still being drawn onto the screen, and the texts are drawn on top of it

View File

@@ -67,7 +67,6 @@ class GraphicsJSR223Delegate(val vm: VM) {
return intArrayOf(0, 0) return intArrayOf(0, 0)
} }
fun scrollFrame(xdelta: Int, ydelta: Int) { fun scrollFrame(xdelta: Int, ydelta: Int) {
getFirstGPU()?.let { getFirstGPU()?.let {
it.framebufferScrollX = (it.framebufferScrollX + xdelta) fmod it.framebuffer.width it.framebufferScrollX = (it.framebufferScrollX + xdelta) fmod it.framebuffer.width
@@ -77,20 +76,26 @@ class GraphicsJSR223Delegate(val vm: VM) {
fun setLineOffset(line: Int, offset: Int) { fun setLineOffset(line: Int, offset: Int) {
getFirstGPU()?.let { getFirstGPU()?.let {
it.poke(250900L + 2*line, offset.shr(8).toByte()) // absolutely not USHR it.scanlineOffsets[2L * line] = offset.toByte()
it.poke(250901L + 2*line, offset.toByte()) it.scanlineOffsets[2L * line + 1] = offset.shr(8).toByte() // absolutely not USHR
} }
} }
fun getLineOffset(line: Int): Int { fun getLineOffset(line: Int): Int {
getFirstGPU()?.let { getFirstGPU()?.let {
var xoff = it.peek(250900L + 2*line)!!.toUint().shl(8) or it.peek(250901L + 2*line)!!.toUint() var xoff = it.scanlineOffsets[2L * line].toUint() or it.scanlineOffsets[2L * line + 1].toUint().shl(8)
if (xoff.and(0x8000) != 0) xoff = xoff or 0xFFFF0000.toInt() if (xoff.and(0x8000) != 0) xoff = xoff or 0xFFFF0000.toInt()
return xoff return xoff
} }
return 0 return 0
} }
fun setGraphicsMode(mode: Int) {
getFirstGPU()?.mmio_write(12L, mode.toByte())
}
fun getGraphicsMode() = getFirstGPU()?.mmio_read(12L)?.toUint() ?: 0
fun getPixelDimension(): IntArray { fun getPixelDimension(): IntArray {
getFirstGPU()?.let { return intArrayOf(it.framebuffer.width, it.framebuffer.height) } getFirstGPU()?.let { return intArrayOf(it.framebuffer.width, it.framebuffer.height) }
return intArrayOf(-1, -1) return intArrayOf(-1, -1)
@@ -163,9 +168,9 @@ class GraphicsJSR223Delegate(val vm: VM) {
) )
}*/ }*/
fun setHalfrowMode(set: Boolean) { /*fun setHalfrowMode(set: Boolean) {
getFirstGPU()?.halfrowMode = set getFirstGPU()?.halfrowMode = set
} }*/
private fun GraphicsAdapter._loadSprite(spriteNum: Int, ptr: Int) { private fun GraphicsAdapter._loadSprite(spriteNum: Int, ptr: Int) {
UnsafeHelper.memcpy( UnsafeHelper.memcpy(

View File

@@ -31,7 +31,7 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) {
abstract var ttyBack: Int abstract var ttyBack: Int
abstract var ttyRawMode: Boolean abstract var ttyRawMode: Boolean
abstract var halfrowMode: Boolean // abstract var halfrowMode: Boolean
abstract fun putChar(x: Int, y: Int, text: Byte, foreColour: Byte = ttyFore.toByte(), backColour: Byte = ttyBack.toByte()) abstract fun putChar(x: Int, y: Int, text: Byte, foreColour: Byte = ttyFore.toByte(), backColour: Byte = ttyBack.toByte())

View File

@@ -77,6 +77,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
internal val textArea = UnsafeHelper.allocate(7682) internal val textArea = UnsafeHelper.allocate(7682)
internal val unusedArea = UnsafeHelper.allocate(1024) internal val unusedArea = UnsafeHelper.allocate(1024)
internal val scanlineOffsets = UnsafeHelper.allocate(1024)
protected val paletteShader = LoadShader(DRAW_SHADER_VERT, config.paletteShader) protected val paletteShader = LoadShader(DRAW_SHADER_VERT, config.paletteShader)
protected val textShader = LoadShader(DRAW_SHADER_VERT, config.fragShader) protected val textShader = LoadShader(DRAW_SHADER_VERT, config.fragShader)
@@ -118,7 +119,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
private val memTextOffset = 2L + 2560 + 2560 private val memTextOffset = 2L + 2560 + 2560
private val TEXT_AREA_SIZE = TEXT_COLS * TEXT_ROWS private val TEXT_AREA_SIZE = TEXT_COLS * TEXT_ROWS
override var halfrowMode = false // override var halfrowMode = false
override var rawCursorPos: Int override var rawCursorPos: Int
get() = textArea.getShortFree(memTextCursorPosOffset).toInt() get() = textArea.getShortFree(memTextCursorPosOffset).toInt()
@@ -132,7 +133,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
if (newx >= TEXT_COLS) { if (newx >= TEXT_COLS) {
newx = 0 newx = 0
newy += 1 + halfrowMode.toInt() newy += 1 //+ halfrowMode.toInt()
} }
else if (newx < 0) { else if (newx < 0) {
newx = 0 newx = 0
@@ -166,6 +167,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
framebuffer.fill() framebuffer.fill()
unusedArea.fillWith(0) unusedArea.fillWith(0)
scanlineOffsets.fillWith(0)
val pm = Pixmap(1, 1, Pixmap.Format.RGBA8888) val pm = Pixmap(1, 1, Pixmap.Format.RGBA8888)
pm.drawPixel(0, 0, -1) pm.drawPixel(0, 0, -1)
@@ -197,11 +199,6 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
val adi = addr.toInt() val adi = addr.toInt()
return when (addr) { return when (addr) {
in 0 until 250880 -> framebuffer.pixels.get(adi)//framebuffer.getPixel(adi % WIDTH, adi / WIDTH).toByte() in 0 until 250880 -> framebuffer.pixels.get(adi)//framebuffer.getPixel(adi % WIDTH, adi / WIDTH).toByte()
250896L -> framebufferScrollX.toByte()
250897L -> framebufferScrollX.ushr(8).toByte()
250898L -> framebufferScrollY.toByte()
250899L -> framebufferScrollY.ushr(8).toByte()
251796L -> halfrowMode.toInt().toByte()
in 252030 until 252030+1920 -> mappedFontRom[adi- 252030] in 252030 until 252030+1920 -> mappedFontRom[adi- 252030]
in 250880 until 250880+1024 -> unusedArea[addr - 250880] in 250880 until 250880+1024 -> unusedArea[addr - 250880]
in 253950 until 261632 -> textArea[addr - 253950] in 253950 until 261632 -> textArea[addr - 253950]
@@ -226,11 +223,6 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
unusedArea[addr - 250880] = byte unusedArea[addr - 250880] = byte
runCommand(byte) runCommand(byte)
} }
250896L -> framebufferScrollX = framebufferScrollX.and(0xFFFFFF00.toInt()).or(bi)
250897L -> framebufferScrollX = framebufferScrollX.and(0xFFFF00FF.toInt()).or(bi shl 8)
250898L -> framebufferScrollY = framebufferScrollY.and(0xFFFFFF00.toInt()).or(bi)
250899L -> framebufferScrollY = framebufferScrollY.and(0xFFFF00FF.toInt()).or(bi shl 8)
251796L -> halfrowMode = (bi and 1) == 1
in 252030 until 252030+1920 -> mappedFontRom[adi- 252030] = byte in 252030 until 252030+1920 -> mappedFontRom[adi- 252030] = byte
in 250880 until 250880+1024 -> unusedArea[addr - 250880] = byte in 250880 until 250880+1024 -> unusedArea[addr - 250880] = byte
in 253950 until 261632 -> textArea[addr - 253950] = byte in 253950 until 261632 -> textArea[addr - 253950] = byte
@@ -274,6 +266,12 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
11L -> sgr.bankCount.toByte() 11L -> sgr.bankCount.toByte()
12L -> graphicsMode.toByte() 12L -> graphicsMode.toByte()
13L -> layerArrangement.toByte() 13L -> layerArrangement.toByte()
14L -> framebufferScrollX.toByte()
15L -> framebufferScrollX.ushr(8).toByte()
16L -> framebufferScrollY.toByte()
17L -> framebufferScrollY.ushr(8).toByte()
in 1024L..2047L -> scanlineOffsets[addr - 1024]
in 0 until VM.MMIO_SIZE -> -1 in 0 until VM.MMIO_SIZE -> -1
else -> null else -> null
@@ -289,6 +287,13 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
10L -> { ttyBack = bi } 10L -> { ttyBack = bi }
12L -> { graphicsMode = bi } 12L -> { graphicsMode = bi }
13L -> { layerArrangement = bi } 13L -> { layerArrangement = bi }
14L -> { framebufferScrollX = framebufferScrollX.and(0xFFFFFF00.toInt()).or(bi) }
15L -> { framebufferScrollX = framebufferScrollX.and(0xFFFF00FF.toInt()).or(bi shl 8) }
16L -> { framebufferScrollY = framebufferScrollY.and(0xFFFFFF00.toInt()).or(bi) }
17L -> { framebufferScrollY = framebufferScrollY.and(0xFFFF00FF.toInt()).or(bi shl 8) }
in 1024L..2047L -> { scanlineOffsets[addr - 1024] = byte }
else -> null else -> null
} }
} }
@@ -608,7 +613,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
override fun crlf() { override fun crlf() {
val (_, y) = getCursorPos() val (_, y) = getCursorPos()
val newy = y + 1 + halfrowMode.toInt() val newy = y + 1 //+ halfrowMode.toInt()
setCursorPos(0, if (newy >= TEXT_ROWS) TEXT_ROWS - 1 else newy) setCursorPos(0, if (newy >= TEXT_ROWS) TEXT_ROWS - 1 else newy)
if (newy >= TEXT_ROWS) scrollUp(1) if (newy >= TEXT_ROWS) scrollUp(1)
} }
@@ -715,6 +720,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
chrrom0.dispose() chrrom0.dispose()
chrrom.dispose() chrrom.dispose()
unusedArea.destroy() unusedArea.destroy()
scanlineOffsets.destroy()
} }
private var textCursorBlinkTimer = 0f private var textCursorBlinkTimer = 0f
@@ -742,10 +748,9 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
if (isRefSize && graphicsMode == 1) { if (isRefSize && graphicsMode == 1) {
val layerOrder = LAYERORDERS4[layerArrangement] val layerOrder = LAYERORDERS4[layerArrangement]
for (y in 0..223) { for (y in 0..223) {
var xoff = unusedArea[20L + 2 * y].toUint().shl(8) or unusedArea[20L + 2 * y + 1].toUint() var xoff = scanlineOffsets[2L * y].toUint().shl(8) or scanlineOffsets[2L * y + 1].toUint()
if (xoff.and(0x8000) != 0) xoff = xoff or 0xFFFF0000.toInt() if (xoff.and(0x8000) != 0) xoff = xoff or 0xFFFF0000.toInt()
val xs = val xs = (0 + xoff).coerceIn(0, 279)..(279 + xoff).coerceIn(0, 279)
(0 + xoff).coerceIn(0, 279)..(279 + xoff).coerceIn(0, 279)
if (xoff in -(280 - 1) until 280) { if (xoff in -(280 - 1) until 280) {
for (x in xs) { for (x in xs) {
@@ -778,10 +783,9 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
} }
else { else {
for (y in 0 until config.height) { for (y in 0 until config.height) {
var xoff = unusedArea[20L + 2 * y].toUint().shl(8) or unusedArea[20L + 2 * y + 1].toUint() var xoff = scanlineOffsets[2L * y].toUint() or scanlineOffsets[2L * y + 1].toUint().shl(8)
if (xoff.and(0x8000) != 0) xoff = xoff or 0xFFFF0000.toInt() if (xoff.and(0x8000) != 0) xoff = xoff or 0xFFFF0000.toInt()
val xs = val xs = (0 + xoff).coerceIn(0, config.width - 1)..(config.width - 1 + xoff).coerceIn(0, config.width - 1)
(0 + xoff).coerceIn(0, config.width - 1)..(config.width - 1 + xoff).coerceIn(0, config.width - 1)
if (xoff in -(config.width - 1) until config.width) { if (xoff in -(config.width - 1) until config.width) {
for (x in xs) { for (x in xs) {

View File

@@ -31,7 +31,7 @@ class TTY(assetsRoot: String, val vm: VM) : GlassTty(TEXT_ROWS, TEXT_COLS), Peri
override var blinkCursor = true override var blinkCursor = true
override var ttyRawMode = false override var ttyRawMode = false
override var halfrowMode = false // override var halfrowMode = false
override fun getCursorPos() = rawCursorPos % TEXT_COLS to rawCursorPos / TEXT_COLS override fun getCursorPos() = rawCursorPos % TEXT_COLS to rawCursorPos / TEXT_COLS
/** /**