mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-11 07:14:04 +09:00
fix: RGB upload function broken for non-native size
This commit is contained in:
@@ -112,7 +112,8 @@ if (fullFilePathStr.startsWith('$:/TAPE') || fullFilePathStr.startsWith('$:\\TAP
|
|||||||
|
|
||||||
con.clear()
|
con.clear()
|
||||||
con.curs_set(0)
|
con.curs_set(0)
|
||||||
graphics.setGraphicsMode(5) // 32-bit colour mode
|
graphics.setGraphicsMode(4) // initially set to 4bpp mode
|
||||||
|
graphics.setGraphicsMode(5) // set to 8bpp mode. If GPU don't support it, mode will remain to 4
|
||||||
graphics.clearPixels(0)
|
graphics.clearPixels(0)
|
||||||
graphics.clearPixels2(0)
|
graphics.clearPixels2(0)
|
||||||
graphics.clearPixels3(0)
|
graphics.clearPixels3(0)
|
||||||
@@ -394,31 +395,27 @@ let decodeTime = 0
|
|||||||
let uploadTime = 0
|
let uploadTime = 0
|
||||||
let biasTime = 0
|
let biasTime = 0
|
||||||
|
|
||||||
|
const nativeWidth = graphics.getPixelDimension()[0]
|
||||||
|
const nativeHeight = graphics.getPixelDimension()[1]
|
||||||
const BIAS_LIGHTING_MIN = 1.0 / 16.0
|
const BIAS_LIGHTING_MIN = 1.0 / 16.0
|
||||||
let oldBgcol = [BIAS_LIGHTING_MIN, BIAS_LIGHTING_MIN, BIAS_LIGHTING_MIN]
|
let oldBgcol = [BIAS_LIGHTING_MIN, BIAS_LIGHTING_MIN, BIAS_LIGHTING_MIN]
|
||||||
|
|
||||||
let notifHidden = false
|
let notifHidden = false
|
||||||
|
|
||||||
function getRGBfromScr(x, y) {
|
function getRGBfromScr(x, y) {
|
||||||
if (gpuGraphicsMode == 4) {
|
let offset = y * WIDTH + x
|
||||||
let offset = y * WIDTH + x
|
let fb1 = sys.peek(-1048577 - offset)
|
||||||
let rg = sys.peek(-1048577 - offset)
|
let fb2 = sys.peek(-1310721 - offset)
|
||||||
let ba = sys.peek(-1310721 - offset)
|
let fb3 = sys.peek(-1310721 - (262144 * (gpuGraphicsMode - 4)) - offset)
|
||||||
return [(rg >>> 4) / 15.0, (rg & 15) / 15.0, (ba >>> 4) / 15.0]
|
|
||||||
}
|
if (gpuGraphicsMode == 4)
|
||||||
else if (gpuGraphicsMode == 5) {
|
return [(fb1 >>> 4) / 15.0, (fb1 & 15) / 15.0, (fb2 >>> 4) / 15.0]
|
||||||
let offset = y * WIDTH + x
|
else
|
||||||
let r = sys.peek(-1048577 - offset)
|
return [fb1 / 255.0, fb2 / 255.0, fb3 / 255.0]
|
||||||
let g = sys.peek(-1310721 - offset)
|
|
||||||
let b = sys.peek(-1572865 - offset)
|
|
||||||
return [r / 255.0, g / 255.0, b / 255.0]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBiasLighting() {
|
function setBiasLighting() {
|
||||||
let samples = []
|
let samples = []
|
||||||
let nativeWidth = graphics.getPixelDimension()[0]
|
|
||||||
let nativeHeight = graphics.getPixelDimension()[1]
|
|
||||||
let width = header.width; let height = header.height
|
let width = header.width; let height = header.height
|
||||||
|
|
||||||
let offsetX = Math.floor((nativeWidth - width) / 2)
|
let offsetX = Math.floor((nativeWidth - width) / 2)
|
||||||
|
|||||||
@@ -1477,28 +1477,24 @@ class GraphicsJSR223Delegate(private val vm: VM) {
|
|||||||
// Get native resolution
|
// Get native resolution
|
||||||
val nativeWidth = gpu.config.width
|
val nativeWidth = gpu.config.width
|
||||||
val nativeHeight = gpu.config.height
|
val nativeHeight = gpu.config.height
|
||||||
val totalNativePixels = (nativeWidth * nativeHeight)
|
val totalNativePixels = nativeWidth * nativeHeight
|
||||||
val totalVideoPixels = width * height
|
val totalVideoPixels = width * height
|
||||||
|
|
||||||
val chunkSize = 32768
|
val chunkSize = width
|
||||||
val rgbBulkBuffer = ByteArray(chunkSize * 3)
|
val rgbBulkBuffer = ByteArray(chunkSize * 3)
|
||||||
val rgChunk = ByteArray(chunkSize)
|
val rgChunk = ByteArray(chunkSize)
|
||||||
val baChunk = ByteArray(chunkSize)
|
val baChunk = ByteArray(chunkSize)
|
||||||
val rChunk = ByteArray(chunkSize)
|
val rChunk = ByteArray(chunkSize)
|
||||||
val gChunk = ByteArray(chunkSize)
|
val gChunk = ByteArray(chunkSize)
|
||||||
val bChunk = ByteArray(chunkSize)
|
val bChunk = ByteArray(chunkSize)
|
||||||
val aChunk = ByteArray(chunkSize); aChunk.fill(-1)
|
val aChunk = ByteArray(chunkSize)
|
||||||
var pixelsProcessed = 0
|
var pixelsProcessed = 0
|
||||||
|
|
||||||
// Helper function to write chunks to framebuffer (shared between native size and resize paths)
|
// Helper function to write chunks to framebuffer (shared between native size and resize paths)
|
||||||
fun writeChunksToFramebuffer(
|
fun writeChunksToFramebuffer(pixelsInChunk: Int, startX: Int = 0, startY: Int = 0) {
|
||||||
pixelsInChunk: Int,
|
|
||||||
rgChunk: ByteArray, baChunk: ByteArray,
|
|
||||||
rChunk: ByteArray, gChunk: ByteArray, bChunk: ByteArray, aChunk: ByteArray
|
|
||||||
) {
|
|
||||||
val pixelIndex = pixelsProcessed
|
val pixelIndex = pixelsProcessed
|
||||||
val videoY = pixelIndex / width
|
val videoY = (pixelIndex / width) + startY
|
||||||
val videoX = pixelIndex % width
|
val videoX = (pixelIndex % width) + startX
|
||||||
val nativePos = videoY * nativeWidth + videoX
|
val nativePos = videoY * nativeWidth + videoX
|
||||||
if (graphicsMode == 4) {
|
if (graphicsMode == 4) {
|
||||||
UnsafeHelper.memcpyRaw(
|
UnsafeHelper.memcpyRaw(
|
||||||
@@ -1510,7 +1506,7 @@ class GraphicsJSR223Delegate(private val vm: VM) {
|
|||||||
null, gpu.framebuffer2!!.ptr + nativePos, pixelsInChunk.toLong()
|
null, gpu.framebuffer2!!.ptr + nativePos, pixelsInChunk.toLong()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else if (graphicsMode == 5) {
|
else {
|
||||||
UnsafeHelper.memcpyRaw(
|
UnsafeHelper.memcpyRaw(
|
||||||
rChunk, UnsafeHelper.getArrayOffset(rChunk),
|
rChunk, UnsafeHelper.getArrayOffset(rChunk),
|
||||||
null, gpu.framebuffer.ptr + nativePos, pixelsInChunk.toLong()
|
null, gpu.framebuffer.ptr + nativePos, pixelsInChunk.toLong()
|
||||||
@@ -1532,7 +1528,7 @@ class GraphicsJSR223Delegate(private val vm: VM) {
|
|||||||
pixelsProcessed += pixelsInChunk
|
pixelsProcessed += pixelsInChunk
|
||||||
}
|
}
|
||||||
|
|
||||||
fun writeToChunk(r: Int, g: Int, b: Int, videoX: Int, videoY: Int, i: Int) {
|
fun writeToChunk(r: Int, g: Int, b: Int, videoX: Int, videoY: Int, i: Int, coordInVideoFrame: Boolean = true) {
|
||||||
if (graphicsMode == 4) {
|
if (graphicsMode == 4) {
|
||||||
// Apply Bayer dithering and convert to 4-bit
|
// Apply Bayer dithering and convert to 4-bit
|
||||||
val r4 = ditherValue(r, videoX, videoY, frameCount)
|
val r4 = ditherValue(r, videoX, videoY, frameCount)
|
||||||
@@ -1541,13 +1537,14 @@ class GraphicsJSR223Delegate(private val vm: VM) {
|
|||||||
|
|
||||||
// Pack RGB values and store in chunk arrays for batch processing
|
// Pack RGB values and store in chunk arrays for batch processing
|
||||||
rgChunk[i] = ((r4 shl 4) or g4).toByte()
|
rgChunk[i] = ((r4 shl 4) or g4).toByte()
|
||||||
baChunk[i] = ((b4 shl 4) or 15).toByte()
|
baChunk[i] = ((b4 shl 4) or coordInVideoFrame.toInt().times(15)).toByte()
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (graphicsMode == 5) {
|
else {
|
||||||
rChunk[i] = r.toByte()
|
rChunk[i] = r.toByte()
|
||||||
gChunk[i] = g.toByte()
|
gChunk[i] = g.toByte()
|
||||||
bChunk[i] = b.toByte()
|
bChunk[i] = b.toByte()
|
||||||
|
aChunk[i] = coordInVideoFrame.toInt().times(255).toByte()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1574,7 +1571,7 @@ class GraphicsJSR223Delegate(private val vm: VM) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write chunks to framebuffer
|
// Write chunks to framebuffer
|
||||||
writeChunksToFramebuffer(pixelsInChunk, rgChunk, baChunk, rChunk, gChunk, bChunk, aChunk)
|
writeChunksToFramebuffer(pixelsInChunk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (resizeToFull && (width / 2 != nativeWidth / 2 || height / 2 != nativeHeight / 2)) {
|
else if (resizeToFull && (width / 2 != nativeWidth / 2 || height / 2 != nativeHeight / 2)) {
|
||||||
@@ -1605,7 +1602,7 @@ class GraphicsJSR223Delegate(private val vm: VM) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write chunks to framebuffer
|
// Write chunks to framebuffer
|
||||||
writeChunksToFramebuffer(pixelsInChunk, rgChunk, baChunk, rChunk, gChunk, bChunk, aChunk)
|
writeChunksToFramebuffer(pixelsInChunk)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Optimised centering logic with bulk memory operations
|
// Optimised centering logic with bulk memory operations
|
||||||
@@ -1633,18 +1630,17 @@ class GraphicsJSR223Delegate(private val vm: VM) {
|
|||||||
if (nativeX !in 0 until nativeWidth || nativeY !in 0 until nativeHeight) {
|
if (nativeX !in 0 until nativeWidth || nativeY !in 0 until nativeHeight) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read RGB values from bulk buffer
|
|
||||||
val rgbIndex = i * 3
|
|
||||||
val r = rgbBulkBuffer[rgbIndex].toUint()
|
|
||||||
val g = rgbBulkBuffer[rgbIndex + 1].toUint()
|
|
||||||
val b = rgbBulkBuffer[rgbIndex + 2].toUint()
|
|
||||||
|
|
||||||
writeToChunk(r, g, b, videoX, videoY, i)
|
// Read RGB values from bulk buffer
|
||||||
|
val r = rgbBulkBuffer[i*3].toUint()
|
||||||
|
val g = rgbBulkBuffer[i*3 + 1].toUint()
|
||||||
|
val b = rgbBulkBuffer[i*3 + 2].toUint()
|
||||||
|
|
||||||
|
writeToChunk(r, g, b, nativeX, nativeY, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write chunks to framebuffer
|
// Write chunks to framebuffer
|
||||||
writeChunksToFramebuffer(pixelsInChunk, rgChunk, baChunk, rChunk, gChunk, bChunk, aChunk)
|
writeChunksToFramebuffer(pixelsInChunk, offsetX, offsetY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user