1
0
mirror of https://github.com/irmen/ksim65.git synced 2024-06-13 22:29:29 +00:00

optimizing a little bit more

This commit is contained in:
Irmen de Jong 2019-10-04 20:39:57 +02:00
parent b299880428
commit 708fc865a1
8 changed files with 36 additions and 39 deletions

View File

@ -54,6 +54,7 @@ class Cia(val number: Int, startAddress: Address, endAddress: Address) : MemMapp
}
}
private var totalCycles = 0
private var tod = TimeOfDay()
private var timerAset = 0
private var timerBset = 0
@ -69,7 +70,13 @@ class Cia(val number: Int, startAddress: Address, endAddress: Address) : MemMapp
}
override fun clock() {
tod.update()
totalCycles++
if(totalCycles % 20000 == 0) {
// TOD resolution is 0.1 second, no need to update it in every cycle
tod.update()
}
if(ramBuffer[0x0e].toInt() and 1 != 0) {
timerAactual--
if(timerAactual<0)
@ -232,19 +239,9 @@ class Cia(val number: Int, startAddress: Address, endAddress: Address) : MemMapp
tod.start()
(tod.tenths and 0x0f).toShort()
}
0x09 -> {
toBCD(tod.seconds)
}
0x0a -> {
toBCD(tod.minutes)
}
0x0b -> {
val hours = toBCD(tod.hours)
if (tod.hours >= 12)
(hours.toInt() or 0x10000000).toShort()
else
hours
}
0x09 -> toBCD(tod.seconds)
0x0a -> toBCD(tod.minutes)
0x0b -> toBCD(tod.hours)
else -> ramBuffer[register]
}
}
@ -301,8 +298,6 @@ class Cia(val number: Int, startAddress: Address, endAddress: Address) : MemMapp
0x0b -> {
tod.stop()
tod.hours = fromBCD(data)
if (data >= 12)
tod.hours = tod.hours or 0b10000000
}
// the timer A and B control registers are simply provided by the rambuffer for now.
}
@ -323,7 +318,7 @@ class Cia(val number: Int, startAddress: Address, endAddress: Address) : MemMapp
}
// to avoid some 'stuck' keys, if we receive a shift/control/alt RELEASE, we wipe the keyboard buffer
// (this can happen becase we're changing the keycode for some pressed keys below,
// (this can happen because we're changing the keycode for some pressed keys below,
// and a released key doesn't always match the pressed keycode anymore then)
if (event.id == KeyEvent.KEY_RELEASED && event.keyCode in listOf(
KeyEvent.VK_SHIFT,

View File

@ -43,7 +43,6 @@ object ScreenDefs {
private class BitmapScreenPanel(val chargenData: ByteArray, val ram: MemoryComponent) : JPanel() {
private val fullscreenImage: VolatileImage
private val fullscreenG2d: Graphics2D
private val normalCharacters = loadCharacters(false)
@ -183,9 +182,9 @@ class MainC64Window(
requestFocusInWindow()
}
fun start() {
// repaint the screen's back buffer ~60 times per second
val repaintTimer = Timer(1000 / 60) {
fun start(updateRate: Int) {
// repaint the screen's back buffer
val repaintTimer = Timer(1000 / updateRate) {
repaint()
}
repaintTimer.initialDelay = 0

View File

@ -59,7 +59,7 @@ class C64Machine(title: String) : IVirtualMachine {
debugWindow.setLocation(hostDisplay.location.x + hostDisplay.width, hostDisplay.location.y)
debugWindow.isVisible = true
hostDisplay.isVisible = true
hostDisplay.start()
hostDisplay.start(30)
}
fun breakpointKernelLoad(cpu: Cpu6502, pc: Address): Cpu6502.BreakpointResultAction {

View File

@ -382,10 +382,10 @@ class MainWindow(title: String) : JFrame(title), KeyListener, MouseInputListener
requestFocusInWindow()
}
fun start() {
// repaint the screen's back buffer ~60 times per second
fun start(updateRate: Int) {
// repaint the screen's back buffer
var cursorBlink = 0L
val repaintTimer = javax.swing.Timer(1000 / 60) {
val repaintTimer = javax.swing.Timer(1000 / updateRate) {
repaint()
if(it.`when` - cursorBlink > 200L) {
cursorBlink = it.`when`

View File

@ -37,7 +37,7 @@ class EhBasicMachine(title: String) {
bus.reset()
hostDisplay.isVisible = true
hostDisplay.start()
hostDisplay.start(30)
}
private fun step() {

View File

@ -49,7 +49,7 @@ class VirtualMachine(title: String) : IVirtualMachine {
debugWindow.isVisible = true
hostDisplay.isVisible = true
hostDisplay.start()
hostDisplay.start(30)
}
override fun getZeroAndStackPages(): Array<UByte> = ram.getPages(0, 2)

View File

@ -333,7 +333,8 @@ open class Cpu6502 : BusComponent() {
}
/**
* Process once clock cycle in the cpu
* Process once clock cycle in the cpu.
* Use this if goal is cycle-perfect emulation.
*/
override fun clock() {
if (instrCycles == 0) {
@ -395,12 +396,15 @@ open class Cpu6502 : BusComponent() {
}
/**
* Execute one single complete instruction
* Execute one single complete instruction.
* Use this when the goal is emulation performance and not a cycle perfect system.
*/
open fun step() {
while (instrCycles > 0) clock()
totalCycles += instrCycles
instrCycles = 0
clock()
while (instrCycles > 0) clock()
totalCycles += instrCycles
instrCycles = 0
}
fun nmi() {

View File

@ -26,6 +26,7 @@ class Cpu65C02 : Cpu6502() {
/**
* Process once clock cycle in the cpu
* Use this if goal is cycle-perfect emulation.
*/
override fun clock() {
when (waiting) {
@ -47,18 +48,16 @@ class Cpu65C02 : Cpu6502() {
}
/**
* Execute one single complete instruction
* Execute one single complete instruction.
* Use this when the goal is emulation performance and not a cycle perfect system.
*/
override fun step() {
totalCycles += instrCycles
instrCycles = 0
if (waiting == Wait.Normal) {
while (instrCycles > 0) clock()
clock()
if (waiting == Wait.Normal)
while (instrCycles > 0) clock()
else {
totalCycles += instrCycles
instrCycles = 0
}
totalCycles += instrCycles
instrCycles = 0
}
}