Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jul 8, 2018
1 parent edd812e commit 8051303
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,8 @@ class InstructionInterpreter(val s: CpuState) : InstructionEvaluator<CpuState>()

val vfpuContext = VfpuContext()

inline fun CpuState.setVD_(
//inline // @TODO: kotlin-native bug: https://github.com/JetBrains/kotlin-native/issues/1777
fun CpuState.setVD_(
destSize: Int = IR.one_two,
prefixes: Boolean = false,
callback: VfpuContext.(i: Int) -> Float
Expand All @@ -1117,7 +1118,8 @@ class InstructionInterpreter(val s: CpuState) : InstructionEvaluator<CpuState>()
consumePrefixes(prefixes)
}

inline fun CpuState.setVDI_(
//inline // @TODO: kotlin-native bug: https://github.com/JetBrains/kotlin-native/issues/1777
fun CpuState.setVDI_(
destSize: Int = IR.one_two,
prefixes: Boolean = false,
callback: VfpuContext.(i: Int) -> Int
Expand All @@ -1128,7 +1130,8 @@ class InstructionInterpreter(val s: CpuState) : InstructionEvaluator<CpuState>()
consumePrefixes(prefixes)
}

inline fun CpuState.setVD_VS(
//inline // @TODO: kotlin-native bug: https://github.com/JetBrains/kotlin-native/issues/1777
fun CpuState.setVD_VS(
destSize: Int = IR.one_two,
srcSize: Int = IR.one_two,
prefixes: Boolean = false,
Expand All @@ -1141,7 +1144,8 @@ class InstructionInterpreter(val s: CpuState) : InstructionEvaluator<CpuState>()
consumePrefixes(prefixes)
}

inline fun CpuState.setVDI_VS(
//inline // @TODO: kotlin-native bug: https://github.com/JetBrains/kotlin-native/issues/1777
fun CpuState.setVDI_VS(
destSize: Int = IR.one_two,
srcSize: Int = IR.one_two,
prefixes: Boolean = false,
Expand All @@ -1154,7 +1158,8 @@ class InstructionInterpreter(val s: CpuState) : InstructionEvaluator<CpuState>()
consumePrefixes(prefixes)
}

inline fun CpuState.setVD_VDVS(
//inline // @TODO: kotlin-native bug: https://github.com/JetBrains/kotlin-native/issues/1777
fun CpuState.setVD_VDVS(
destSize: Int = IR.one_two,
srcSize: Int = IR.one_two,
prefixes: Boolean = false,
Expand All @@ -1168,22 +1173,26 @@ class InstructionInterpreter(val s: CpuState) : InstructionEvaluator<CpuState>()
consumePrefixes(prefixes)
}

inline fun CpuState.setVD_VSVT(
//inline // @TODO: kotlin-native bug: https://github.com/JetBrains/kotlin-native/issues/1777
fun CpuState.setVD_VSVT(
destSize: Int = IR.one_two,
srcSize: Int = IR.one_two,
targetSize: Int = srcSize,
prefixes: Boolean = false,
callback: VfpuContext.(i: Int) -> Float
) = vfpuContext.run {
vfpuContext.vdSize = destSize
readVs(size = srcSize, prefixes = prefixes)
readVt(size = targetSize, prefixes = prefixes)
for (n in 0 until destSize) vd[n] = callback(vfpuContext, n)
writeVd(size = destSize, prefixes = prefixes)
consumePrefixes(prefixes)
) {
vfpuContext.run {
vfpuContext.vdSize = destSize
readVs(size = srcSize, prefixes = prefixes)
readVt(size = targetSize, prefixes = prefixes)
for (n in 0 until destSize) vd[n] = callback(vfpuContext, n)
writeVd(size = destSize, prefixes = prefixes)
consumePrefixes(prefixes)
}
}

inline fun CpuState.setVDI_VSVT(
//inline // @TODO: kotlin-native bug: https://github.com/JetBrains/kotlin-native/issues/1777
fun CpuState.setVDI_VSVT(
destSize: Int = IR.one_two,
srcSize: Int = IR.one_two,
targetSize: Int = srcSize,
Expand All @@ -1198,7 +1207,8 @@ class InstructionInterpreter(val s: CpuState) : InstructionEvaluator<CpuState>()
consumePrefixes(prefixes)
}

inline fun CpuState._VSVT(
//inline // @TODO: kotlin-native bug: https://github.com/JetBrains/kotlin-native/issues/1777
fun CpuState._VSVT(
destSize: Int = IR.one_two,
srcSize: Int = IR.one_two,
targetSize: Int = srcSize,
Expand Down
42 changes: 42 additions & 0 deletions kpspemu/common/src/com/soywiz/kpspemu/ge/GeEnums.kt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ object PspRGBA_5551 : ColorFormat16(), ColorFormatBase by ColorFormatBase.Mixin(
//override fun getA(v: Int): Int = if (v.extractScaledFFDefault(15, 1, default = 0xFF) == 0) 0xFF else 0x00
}

// @TODO: kotlin-native bug: https://github.com/JetBrains/kotlin-native/issues/1779
/*
enum class PixelFormat(
override val id: Int,
val bytesPerPixel: Double,
Expand Down Expand Up @@ -254,3 +256,43 @@ enum class PixelFormat(
companion object : IdEnum.SmallCompanion<PixelFormat>(values())
}
*/

enum class PixelFormat(
override val id: Int,
val bytesPerPixel: Double,
val isRgba: Boolean = false,
val isPalette: Boolean = false,
val colorBits: Int = 0,
val paletteBits: Int = 0,
val dxtVersion: Int = 0,
val isCompressed: Boolean = false
) : IdEnum {
RGBA_5650(0, 2.0, true, false, 16, 0, 0, false),
RGBA_5551(1, 2.0, true, false, 16, 0, 0, false),
RGBA_4444(2, 2.0, true, false, 16, 0, 0, false),
RGBA_8888(3, 4.0, true, false, 32, 0, 0, false),
PALETTE_T4(4, 0.5, false, true, 0, 4, 0, false),
PALETTE_T8(5, 1.0, false, true, 0, 8, 0, false),
PALETTE_T16(6, 2.0, false, true, 0, 16, 0, false),
PALETTE_T32(7, 4.0, false, true, 0, 32, 0, false),
COMPRESSED_DXT1(8, 0.5, false, false, 0, 0, 1, true),
COMPRESSED_DXT3(9, 1.0, false, false, 0, 0, 3, true),
COMPRESSED_DXT5(10, 1.0, false, false, 0, 0, 5, true);

val bitsPerPixel get() = (bytesPerPixel * 8).toInt()

val requireClut: Boolean get() = isPalette
fun getSizeInBytes(count: Int): Int = (bytesPerPixel * count).toInt()

val colorFormat: ColorFormat?
get() = when (this) {
RGBA_5650 -> PspRGB_565
RGBA_5551 -> PspRGBA_5551
RGBA_4444 -> com.soywiz.korim.color.RGBA_4444
RGBA_8888 -> com.soywiz.korim.color.RGBA
else -> null
}

companion object : IdEnum.SmallCompanion<PixelFormat>(values())
}

0 comments on commit 8051303

Please sign in to comment.