Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Sep 13, 2024
2 parents f6d3821 + 10ceb92 commit 311d7c6
Show file tree
Hide file tree
Showing 123 changed files with 365 additions and 397 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: chmod +x gradlew

- name: Build
run: ./gradlew --no-daemon :desktop:bootJar
run: ./gradlew --no-daemon :desktop:shadowJar

- name: Rename Build
if: ${{ matrix.os == 'ubuntu-latest' }}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/kotlin/br/tiagohm/nestalgia/core/Action53.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Action53(console: Console) : Mapper(console) {

companion object {

@JvmStatic private val OUTER_AND = intArrayOf(0x1FE, 0x1FC, 0x1F8, 0x1F0)
@JvmStatic private val INNER_AND = intArrayOf(0x01, 0x03, 0x07, 0x0F)
private val OUTER_AND = intArrayOf(0x1FE, 0x1FC, 0x1F8, 0x1F0)
private val INNER_AND = intArrayOf(0x01, 0x03, 0x07, 0x0F)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,17 @@ class ApuFrameCounter(private val console: Console) : MemoryHandler, Resetable,

companion object {

@JvmStatic private val STEP_CYCLES_NTSC = arrayOf(
private val STEP_CYCLES_NTSC = arrayOf(
intArrayOf(7457, 14913, 22371, 29828, 29829, 29830),
intArrayOf(7457, 14913, 22371, 29829, 37281, 37282),
)

@JvmStatic private val STEP_CYCLES_PAL = arrayOf(
private val STEP_CYCLES_PAL = arrayOf(
intArrayOf(8313, 16627, 24939, 33252, 33253, 33254),
intArrayOf(8313, 16627, 24939, 33253, 41565, 41566),
)

@JvmStatic private val FRAME_TYPE = arrayOf(
private val FRAME_TYPE = arrayOf(
arrayOf(
FrameType.QUARTER,
FrameType.HALF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ abstract class ApuLengthCounter(

companion object {

@JvmStatic protected val LC_LOOKUP_TABLE = intArrayOf(
private val LC_LOOKUP_TABLE = intArrayOf(
10, 254, 20, 2, 40, 4, 80, 6,
160, 8, 60, 10, 14, 12, 26, 14,
12, 16, 24, 18, 48, 20, 96, 22,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ class ArkanoidController(

companion object {

@JvmStatic private val SENSIBILITY_PX = intArrayOf(0, 16, 32, 64)
private val SENSIBILITY_PX = intArrayOf(0, 16, 32, 64)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package br.tiagohm.nestalgia.core

import java.io.Closeable

interface AudioDevice : Closeable {
interface AudioDevice : AutoCloseable {

fun play(buffer: ShortArray, length: Int, sampleRate: Int, stereo: Boolean)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package br.tiagohm.nestalgia.core

interface BarcodeReader {
fun interface BarcodeReader {

fun inputBarcode(barcode: Long, digitCount: Int)
}
2 changes: 1 addition & 1 deletion core/src/main/kotlin/br/tiagohm/nestalgia/core/Battery.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package br.tiagohm.nestalgia.core

interface Battery {
sealed interface Battery {

fun saveBattery()

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/br/tiagohm/nestalgia/core/Blip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Blip(private val size: Int) {
const val MIN_SAMPLE = -32768
const val BLIP_MAX_FRAME = 4000

@JvmStatic private val BL_STEP = arrayOf(
private val BL_STEP = arrayOf(
shortArrayOf(43, -115, 350, -488, 1136, -914, 5861, 21022),
shortArrayOf(44, -118, 348, -473, 1076, -799, 5274, 21001),
shortArrayOf(45, -121, 344, -454, 1011, -677, 4706, 20936),
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/br/tiagohm/nestalgia/core/Bmc11160.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Bmc11160(console: Console) : Mapper(console) {

override val chrPageSize = 0x2000

override fun initialize() {}
override fun initialize() = Unit

override fun reset(softReset: Boolean) {
writeRegister(0x8000, 0)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/br/tiagohm/nestalgia/core/Bmc235.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Bmc235(console: Console) : Mapper(console) {

companion object {

@JvmStatic private val CONFIG = arrayOf(
private val CONFIG = arrayOf(
arrayOf(intArrayOf(0x00, 0), intArrayOf(0x00, 1), intArrayOf(0x00, 1), intArrayOf(0x00, 1)),
arrayOf(intArrayOf(0x00, 0), intArrayOf(0x00, 1), intArrayOf(0x20, 0), intArrayOf(0x00, 1)),
arrayOf(intArrayOf(0x00, 0), intArrayOf(0x00, 1), intArrayOf(0x20, 0), intArrayOf(0x40, 0)),
Expand Down
64 changes: 64 additions & 0 deletions core/src/main/kotlin/br/tiagohm/nestalgia/core/Bmc60311C.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package br.tiagohm.nestalgia.core

// https://www.nesdev.org/wiki/NES_2.0_Mapper_289

class Bmc60311C(console: Console) : Mapper(console) {

private var innerPrg = 0
private var outerPrg = 0
private var mode = 0

override val prgPageSize = 0x4000

override val chrPageSize = 0x2000

override val registerStartAddress = 0x6000

override val registerEndAddress = 0xFFFF

override fun initialize() {
updateState()
selectChrPage(0, 0)
}

private fun updateState() {
val page = outerPrg or (if (mode.bit2) 0 else innerPrg)

when (mode and 0x03) {
0 -> {
// 0: NROM-128: Same inner/outer 16 KiB bank at CPU $8000-$BFFF and $C000-$FFFF
selectPrgPage(0, page)
selectPrgPage(1, page)
}
1 -> {
// 1: NROM-256: 32 kiB bank at CPU $8000-$FFFF (Selected inner/outer bank SHR 1)
selectPrgPage2x(0, page and 0xFE)
}
2 -> {
// 2: UNROM: Inner/outer bank at CPU $8000-BFFF, fixed inner bank 7 within outer bank at $C000-$FFFF
selectPrgPage(0, page)
selectPrgPage(1, outerPrg or 7)
}
}

mirroringType = if (mode.bit4) MirroringType.HORIZONTAL else MirroringType.VERTICAL
}

override fun writeRegister(addr: Int, value: Int) {
if (addr >= 0x8000) {
innerPrg = value and 0x07
updateState()
} else {
when (addr and 0xE001) {
0x6000 -> {
mode = value and 0x0F
updateState()
}
0x6001 -> {
outerPrg = value
updateState()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Bmc810544CA1(console: Console) : Mapper(console) {

override val chrPageSize = 0x2000

override fun initialize() {}
override fun initialize() = Unit

override fun reset(softReset: Boolean) {
writeRegister(0x8000, 0)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/br/tiagohm/nestalgia/core/BmcNtd03.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BmcNtd03(console: Console) : Mapper(console) {

override val chrPageSize = 0x2000

override fun initialize() {}
override fun initialize() = Unit

override fun reset(softReset: Boolean) {
writeRegister(0x8000, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ object CheatDatabase {

const val FILENAME = "CheatDB.csv"

@JvmStatic private val ENTRIES = ArrayList<CheatInfo>(16384)
@JvmStatic private val LOG = LoggerFactory.getLogger(CheatDatabase::class.java)
private val ENTRIES = ArrayList<CheatInfo>(16384)
private val LOG = LoggerFactory.getLogger(CheatDatabase::class.java)

@JvmStatic
operator fun get(crc: Long): List<CheatInfo> {
return ENTRIES.filter { it.crc == crc }
}

@JvmStatic
fun load(data: Stream<String>) {
for (line in data) {
if (line.isEmpty() || line.startsWith("#")) continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ data class CheatInfo(

companion object {

@JvmStatic
fun parse(line: String): CheatInfo? {
val parts = line.split(";")
val hash = parts[0].also { if (it.isBlank()) return null }
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/kotlin/br/tiagohm/nestalgia/core/CheatManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ class CheatManager(private val console: Console) {

private const val GAME_GENIE_LETTERS = "APZLGITYEOXUKSVN"

@JvmStatic private val GAME_GENIE_ADDRESS_BITS = intArrayOf(14, 13, 12, 19, 22, 21, 20, 7, 10, 9, 8, 15, 18, 17, 16)
@JvmStatic private val GAME_GENIE_VALUE_BITS = intArrayOf(3, 6, 5, 4, 23, 2, 1, 0)
@JvmStatic private val GAME_GENIE_VALUE_BITS_8 = intArrayOf(3, 6, 5, 4, 31, 2, 1, 0)
@JvmStatic private val GAME_GENIE_COMPARE_VALUE_BITS = intArrayOf(27, 30, 29, 28, 23, 26, 25, 24)
private val GAME_GENIE_ADDRESS_BITS = intArrayOf(14, 13, 12, 19, 22, 21, 20, 7, 10, 9, 8, 15, 18, 17, 16)
private val GAME_GENIE_VALUE_BITS = intArrayOf(3, 6, 5, 4, 23, 2, 1, 0)
private val GAME_GENIE_VALUE_BITS_8 = intArrayOf(3, 6, 5, 4, 31, 2, 1, 0)
private val GAME_GENIE_COMPARE_VALUE_BITS = intArrayOf(27, 30, 29, 28, 23, 26, 25, 24)

// PAR
@JvmStatic private val PAR_SHIFT_VALUES = intArrayOf(
private val PAR_SHIFT_VALUES = intArrayOf(
3, 13, 14, 1, 6, 9, 5, 0, 12, 7, 2, 8, 10, 11, 4, // Address
19, 21, 23, 22, 20, 17, 16, 18, // Compare
29, 31, 24, 26, 25, 30, 27, 28, // Value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package br.tiagohm.nestalgia.core

interface Clockable {
fun interface Clockable {

fun clock()
}
5 changes: 2 additions & 3 deletions core/src/main/kotlin/br/tiagohm/nestalgia/core/Console.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import br.tiagohm.nestalgia.core.EmulationFlag.*
import br.tiagohm.nestalgia.core.NotificationType.*
import br.tiagohm.nestalgia.core.Region.*
import org.slf4j.LoggerFactory
import java.io.Closeable
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
import kotlin.random.Random

class Console(@JvmField val settings: EmulationSettings = EmulationSettings()) : Battery, Resetable, Closeable, Snapshotable, Runnable {
data class Console(@JvmField val settings: EmulationSettings = EmulationSettings()) : Battery, Resetable, AutoCloseable, Snapshotable, Runnable {

private val pauseCounter = AtomicInteger(0)

Expand Down Expand Up @@ -647,6 +646,6 @@ class Console(@JvmField val settings: EmulationSettings = EmulationSettings()) :

companion object {

@JvmStatic private val LOG = LoggerFactory.getLogger(Console::class.java)
private val LOG = LoggerFactory.getLogger(Console::class.java)
}
}
11 changes: 5 additions & 6 deletions core/src/main/kotlin/br/tiagohm/nestalgia/core/ControlDevice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ abstract class ControlDevice(

open val keyboard = false

override fun reset(softReset: Boolean) {}
override fun reset(softReset: Boolean) = Unit

protected fun isCurrentPort(addr: Int): Boolean {
return port == (addr - 0x4016)
}

protected open fun refreshStateBuffer() {}
protected open fun refreshStateBuffer() = Unit

protected fun strobeOnRead() {
if (strobe) refreshStateBuffer()
Expand Down Expand Up @@ -96,9 +96,9 @@ abstract class ControlDevice(
}
}

open fun setStateFromInput() {}
open fun setStateFromInput() = Unit

open fun onAfterSetState() {}
open fun onAfterSetState() = Unit

open fun hasControllerType(type: ControllerType): Boolean {
return this.type == type
Expand Down Expand Up @@ -128,9 +128,8 @@ abstract class ControlDevice(
const val EXP_DEVICE_PORT_2 = 7
const val PORT_COUNT = 8

@JvmStatic private val LOG = LoggerFactory.getLogger(ControlDevice::class.java)
private val LOG = LoggerFactory.getLogger(ControlDevice::class.java)

@JvmStatic
internal fun swapButtons(
device1: ControlDevice, button1: ControllerButton,
device2: ControlDevice, button2: ControllerButton,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import br.tiagohm.nestalgia.core.ControlDevice.Companion.EXP_DEVICE_PORT
import br.tiagohm.nestalgia.core.ControllerType.*
import br.tiagohm.nestalgia.core.MemoryAccessType.*
import org.slf4j.LoggerFactory
import java.io.Closeable

open class ControlManager(protected val console: Console) : MemoryHandler, Resetable, Initializable, Snapshotable, Closeable {
open class ControlManager(protected val console: Console) : MemoryHandler, Resetable, Initializable, Snapshotable, AutoCloseable {

private val inputProviders = HashSet<InputProvider>()
private val inputRecorders = HashSet<InputRecorder>()
Expand Down Expand Up @@ -174,10 +173,10 @@ open class ControlManager(protected val console: Console) : MemoryHandler, Reset
pollCounter++
}

protected open fun remapControllerButtons() {}
protected open fun remapControllerButtons() = Unit

val hasKeyboard
get() = controlDevice(EXP_DEVICE_PORT)?.keyboard ?: false
get() = controlDevice(EXP_DEVICE_PORT)?.keyboard == true

open fun openBusMask(port: Int): Int {
// In the NES and Famicom, the top three (or five) bits are not driven,
Expand Down Expand Up @@ -252,6 +251,6 @@ open class ControlManager(protected val console: Console) : MemoryHandler, Reset

companion object {

@JvmStatic private val LOG = LoggerFactory.getLogger(ControlManager::class.java)
private val LOG = LoggerFactory.getLogger(ControlManager::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ abstract class ControllerHub(

companion object {

@JvmStatic private val LOG = LoggerFactory.getLogger(ControllerHub::class.java)
private val LOG = LoggerFactory.getLogger(ControllerHub::class.java)
}
}
2 changes: 1 addition & 1 deletion core/src/main/kotlin/br/tiagohm/nestalgia/core/Cpu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ class Cpu(private val console: Console) : Memory, Resetable, Initializable, Snap
const val CLOCK_RATE_PAL = 1662607
const val CLOCK_RATE_DENDY = 1773448

@JvmStatic private val ADDRESS_MODES = arrayOf(
private val ADDRESS_MODES = arrayOf(
AddressMode.IMP, AddressMode.IND_X, AddressMode.NONE, AddressMode.IND_X,
AddressMode.ZERO, AddressMode.ZERO, AddressMode.ZERO, AddressMode.ZERO,
AddressMode.IMP, AddressMode.IMM, AddressMode.ACC, AddressMode.IMM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,31 @@ class DatachBarcodeReader(console: Console) : ControlDevice(console, DATACH_BARC

companion object {

@JvmStatic private val PREFIX_PARITY_TYPE = arrayOf(
private val PREFIX_PARITY_TYPE = arrayOf(
intArrayOf(8, 8, 8, 8, 8, 8), intArrayOf(8, 8, 0, 8, 0, 0),
intArrayOf(8, 8, 0, 0, 8, 0), intArrayOf(8, 8, 0, 0, 0, 8),
intArrayOf(8, 0, 8, 8, 0, 0), intArrayOf(8, 0, 0, 8, 8, 0),
intArrayOf(8, 0, 0, 0, 8, 8), intArrayOf(8, 0, 8, 0, 8, 0),
intArrayOf(8, 0, 8, 0, 0, 8), intArrayOf(8, 0, 0, 8, 0, 8),
)

@JvmStatic private val DATA_LEFT_ODD = arrayOf(
private val DATA_LEFT_ODD = arrayOf(
intArrayOf(8, 8, 8, 0, 0, 8, 0), intArrayOf(8, 8, 0, 0, 8, 8, 0),
intArrayOf(8, 8, 0, 8, 8, 0, 0), intArrayOf(8, 0, 0, 0, 0, 8, 0),
intArrayOf(8, 0, 8, 8, 8, 0, 0), intArrayOf(8, 0, 0, 8, 8, 8, 0),
intArrayOf(8, 0, 8, 0, 0, 0, 0), intArrayOf(8, 0, 0, 0, 8, 0, 0),
intArrayOf(8, 0, 0, 8, 0, 0, 0), intArrayOf(8, 8, 8, 0, 8, 0, 0),
)

@JvmStatic private val DATA_LEFT_EVEN = arrayOf(
private val DATA_LEFT_EVEN = arrayOf(
intArrayOf(8, 0, 8, 8, 0, 0, 0), intArrayOf(8, 0, 0, 8, 8, 0, 0),
intArrayOf(8, 8, 0, 0, 8, 0, 0), intArrayOf(8, 0, 8, 8, 8, 8, 0),
intArrayOf(8, 8, 0, 0, 0, 8, 0), intArrayOf(8, 0, 0, 0, 8, 8, 0),
intArrayOf(8, 8, 8, 8, 0, 8, 0), intArrayOf(8, 8, 0, 8, 8, 8, 0),
intArrayOf(8, 8, 8, 0, 8, 8, 0), intArrayOf(8, 8, 0, 8, 0, 0, 0),
)

@JvmStatic private val DATA_RIGHT = arrayOf(
private val DATA_RIGHT = arrayOf(
intArrayOf(0, 0, 0, 8, 8, 0, 8), intArrayOf(0, 0, 8, 8, 0, 0, 8),
intArrayOf(0, 0, 8, 0, 0, 8, 8), intArrayOf(0, 8, 8, 8, 8, 0, 8),
intArrayOf(0, 8, 0, 0, 0, 8, 8), intArrayOf(0, 8, 8, 0, 0, 0, 8),
Expand Down
Loading

0 comments on commit 311d7c6

Please sign in to comment.