mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
dithering of the image displaying
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -87,8 +87,8 @@ internal class UnsafePtr(pointer: Long, allocSize: Long) {
|
||||
//// You may break the glass and use this tool when some fucking incomprehensible bugs ("vittujen vitun bugit")
|
||||
//// appear (e.g. getting garbage values when it fucking shouldn't)
|
||||
|
||||
//assert(!destroyed) { throw NullPointerException("The pointer is already destroyed ($this)") }
|
||||
//if (index !in 0 until size) throw IndexOutOfBoundsException("Index: $index; alloc size: $size")
|
||||
assert(!destroyed) { throw NullPointerException("The pointer is already destroyed ($this)") }
|
||||
if (index !in 0 until size) throw IndexOutOfBoundsException("Index: $index; alloc size: $size")
|
||||
}
|
||||
|
||||
operator fun get(index: Long): Byte {
|
||||
@@ -101,37 +101,60 @@ internal class UnsafePtr(pointer: Long, allocSize: Long) {
|
||||
UnsafeHelper.unsafe.putByte(ptr + index, value)
|
||||
}
|
||||
|
||||
// NOTE: get/set multibyte values are NOT BYTE-ALIGNED!
|
||||
|
||||
fun getFloat(index: Long): Float {
|
||||
fun getFloatFree(index: Long): Float {
|
||||
checkNullPtr(index)
|
||||
return UnsafeHelper.unsafe.getFloat(ptr + index)
|
||||
}
|
||||
fun getFloat(unit: Long): Float {
|
||||
checkNullPtr(unit * 4L)
|
||||
return UnsafeHelper.unsafe.getFloat(ptr + (unit * 4L))
|
||||
}
|
||||
|
||||
fun getInt(index: Long): Int {
|
||||
fun getIntFree(index: Long): Int {
|
||||
checkNullPtr(index)
|
||||
return UnsafeHelper.unsafe.getInt(ptr + index)
|
||||
}
|
||||
fun getInt(unit: Long): Int {
|
||||
checkNullPtr(unit * 4L)
|
||||
return UnsafeHelper.unsafe.getInt(ptr + (unit * 4L))
|
||||
}
|
||||
|
||||
fun getShort(index: Long): Short {
|
||||
fun getShortFree(index: Long): Short {
|
||||
checkNullPtr(index)
|
||||
return UnsafeHelper.unsafe.getShort(ptr + index)
|
||||
}
|
||||
fun getShort(unit: Long): Short {
|
||||
checkNullPtr(unit * 2L)
|
||||
return UnsafeHelper.unsafe.getShort(ptr + (unit * 2L))
|
||||
}
|
||||
|
||||
fun setFloat(index: Long, value: Float) {
|
||||
fun setFloatFree(index: Long, value: Float) {
|
||||
checkNullPtr(index)
|
||||
UnsafeHelper.unsafe.putFloat(ptr + index, value)
|
||||
}
|
||||
fun setFloat(unit: Long, value: Float) {
|
||||
checkNullPtr(unit * 4L)
|
||||
UnsafeHelper.unsafe.putFloat(ptr + (unit * 4L), value)
|
||||
}
|
||||
|
||||
fun setInt(index: Long, value: Int) {
|
||||
fun setIntFree(index: Long, value: Int) {
|
||||
checkNullPtr(index)
|
||||
UnsafeHelper.unsafe.putInt(ptr + index, value)
|
||||
}
|
||||
fun setInt(unit: Long, value: Int) {
|
||||
checkNullPtr(unit * 4L)
|
||||
UnsafeHelper.unsafe.putInt(ptr + (unit * 4L), value)
|
||||
}
|
||||
|
||||
fun setShort(index: Long, value: Short) {
|
||||
fun setShortFree(index: Long, value: Short) {
|
||||
checkNullPtr(index)
|
||||
UnsafeHelper.unsafe.putShort(ptr + index, value)
|
||||
}
|
||||
fun setShortUnit(unit: Long, value: Short) {
|
||||
checkNullPtr(unit * 2L)
|
||||
UnsafeHelper.unsafe.putShort(ptr + (unit * 2L), value)
|
||||
}
|
||||
|
||||
fun fillWith(byte: Byte) {
|
||||
UnsafeHelper.unsafe.setMemory(ptr, size, byte)
|
||||
|
||||
@@ -118,8 +118,8 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
|
||||
override var halfrowMode = false
|
||||
|
||||
override var rawCursorPos: Int
|
||||
get() = textArea.getShort(memTextCursorPosOffset).toInt()
|
||||
set(value) { textArea.setShort(memTextCursorPosOffset, value.toShort()) }
|
||||
get() = textArea.getShortFree(memTextCursorPosOffset).toInt()
|
||||
set(value) { textArea.setShortFree(memTextCursorPosOffset, value.toShort()) }
|
||||
|
||||
override fun getCursorPos() = rawCursorPos % TEXT_COLS to rawCursorPos / TEXT_COLS
|
||||
|
||||
@@ -451,11 +451,11 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
|
||||
val foreBits = ttyFore or ttyFore.shl(8) or ttyFore.shl(16) or ttyFore.shl(24)
|
||||
val backBits = ttyBack or ttyBack.shl(8) or ttyBack.shl(16) or ttyBack.shl(24)
|
||||
for (i in 0 until TEXT_COLS * TEXT_ROWS step 4) {
|
||||
textArea.setInt(memTextForeOffset + i, foreBits)
|
||||
textArea.setInt(memTextBackOffset + i, backBits)
|
||||
textArea.setInt(memTextOffset + i, 0)
|
||||
textArea.setIntFree(memTextForeOffset + i, foreBits)
|
||||
textArea.setIntFree(memTextBackOffset + i, backBits)
|
||||
textArea.setIntFree(memTextOffset + i, 0)
|
||||
}
|
||||
textArea.setShort(memTextCursorPosOffset, 0)
|
||||
textArea.setShortFree(memTextCursorPosOffset, 0)
|
||||
}
|
||||
else -> TODO()
|
||||
}
|
||||
@@ -1754,7 +1754,16 @@ void main() {
|
||||
)
|
||||
|
||||
val DEFAULT_PALETTE_NUMBERS = DEFAULT_PALETTE.map { // [[r,g,b,a], [r,g,b,a], [r,g,b,a], ...]
|
||||
intArrayOf(it.ushr(24).and(255), it.ushr(16).and(255), it.ushr(9).and(255), it.and(255))
|
||||
intArrayOf(it.ushr(24).and(255), it.ushr(16).and(255), it.ushr(8).and(255), it.and(255))
|
||||
}
|
||||
|
||||
val DEFAULT_PALETTE_NUMBERS_FLOAT = DEFAULT_PALETTE.map { // [[r,g,b,a], [r,g,b,a], [r,g,b,a], ...]
|
||||
floatArrayOf(
|
||||
it.ushr(24).and(255).div(255f),
|
||||
it.ushr(16).and(255).div(255f),
|
||||
it.ushr(8).and(255).div(255f),
|
||||
it.and(255).div(255f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user