mirror of
https://github.com/felipecsl/6502Android.git
synced 2025-01-04 14:33:00 +00:00
Code cleanup
This commit is contained in:
parent
67bc8d3084
commit
6706d4e774
@ -7,7 +7,6 @@ import java.util.regex.Pattern
|
||||
|
||||
class Assembler(private var memory: Memory, private val symbols: Symbols) {
|
||||
var codeLen = 0
|
||||
val BOOTSTRAP_ADDRESS = 0x600
|
||||
var defaultCodePC = BOOTSTRAP_ADDRESS
|
||||
private var labels = Labels(this, symbols)
|
||||
|
||||
@ -35,7 +34,7 @@ class Assembler(private var memory: Memory, private val symbols: Symbols) {
|
||||
sanitizedLines
|
||||
.map { pattern.matcher(it) }
|
||||
.filter { it.find() }
|
||||
.forEach { symbols.put(it.group(1), sanitize(it.group(2))) }
|
||||
.forEach { symbols[it.group(1)] = sanitize(it.group(2)) }
|
||||
|
||||
return sanitizedLines.filterNot { pattern.matcher(it).find() }
|
||||
}
|
||||
@ -85,10 +84,10 @@ class Assembler(private var memory: Memory, private val symbols: Symbols) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (input.matches("^\\w+\\s+.*?$".toRegex())) {
|
||||
param = input.replace("^\\w+\\s+(.*?)".toRegex(), "$1")
|
||||
param = if (input.matches("^\\w+\\s+.*?$".toRegex())) {
|
||||
input.replace("^\\w+\\s+(.*?)".toRegex(), "$1")
|
||||
} else if (input.matches("^\\w+$".toRegex())) {
|
||||
param = ""
|
||||
""
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
@ -419,4 +418,8 @@ class Assembler(private var memory: Memory, private val symbols: Symbols) {
|
||||
pushByte(opcode)
|
||||
return true
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val BOOTSTRAP_ADDRESS = 0x600
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import android.view.View
|
||||
open class Display(context: Context, attrs: AttributeSet) : View(context, attrs) {
|
||||
private val numX = 32
|
||||
private val numY = 32
|
||||
private val matrix = Array(numX, { IntArray(numY) })
|
||||
private val matrix = Array(numX) { IntArray(numY) }
|
||||
|
||||
private val palette = arrayOf(
|
||||
"#000000", "#ffffff", "#880000", "#aaffee",
|
||||
|
@ -13,41 +13,35 @@ import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.toolbar.*
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
private var emulator: Emulator? = null
|
||||
private lateinit var emulator: Emulator
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
setSupportActionBar(toolbar)
|
||||
val ab: ActionBar = supportActionBar!!
|
||||
ab.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
val actionBar: ActionBar = supportActionBar!!
|
||||
actionBar.setDisplayHomeAsUpEnabled(true)
|
||||
fabRun.setOnClickListener {
|
||||
display_wrapper.visibility = View.VISIBLE
|
||||
emulator = Emulator(display)
|
||||
val emu: Emulator = emulator as Emulator
|
||||
emu.assembler.assembleCode(txtInstructions.text.toString().split("\n"))
|
||||
emulator.assembler.assembleCode(txtInstructions.text.toString().split("\n"))
|
||||
Snackbar.make(layout_content,
|
||||
"Code assembled successfully, ${emu.assembler.codeLen} bytes.",
|
||||
"Code assembled successfully, ${emulator.assembler.codeLen} bytes.",
|
||||
Snackbar.LENGTH_SHORT).show()
|
||||
emu.cpu.run()
|
||||
emulator.cpu.run()
|
||||
}
|
||||
|
||||
btnReset.setOnClickListener {
|
||||
val emu: Emulator = emulator as Emulator
|
||||
emu.reset()
|
||||
emulator.reset()
|
||||
}
|
||||
|
||||
val onClickButton = { code: Int ->
|
||||
if (emulator != null) {
|
||||
val emu = emulator as Emulator
|
||||
emu.cpu.memory.storeKeypress(code)
|
||||
}
|
||||
emulator.cpu.memory.storeKeypress(code)
|
||||
}
|
||||
arrowLeft.setOnClickListener { onClickButton(0x61) }
|
||||
arrowLeft.setOnClickListener { onClickButton(0x61) }
|
||||
arrowRight.setOnClickListener { onClickButton(0x64) }
|
||||
arrowUp.setOnClickListener { onClickButton(0x77) }
|
||||
arrowDown.setOnClickListener { onClickButton(0x73) }
|
||||
arrowUp.setOnClickListener { onClickButton(0x77) }
|
||||
arrowDown.setOnClickListener { onClickButton(0x73) }
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user