Minor code cleanup

This commit is contained in:
Felipe Lima 2017-03-07 21:59:13 -08:00
parent 51ac3e8f59
commit 0fea092675
4 changed files with 6 additions and 10 deletions

View File

@ -31,9 +31,7 @@ class Assembler(private var memory: Memory, private val symbols: Symbols) {
private fun preprocess(lines: List<String>): List<String> { private fun preprocess(lines: List<String>): List<String> {
val pattern = Pattern.compile("^define\\s+(\\w+)\\s+(\\S+)", Pattern.CASE_INSENSITIVE) val pattern = Pattern.compile("^define\\s+(\\w+)\\s+(\\S+)", Pattern.CASE_INSENSITIVE)
val sanitizedLines = lines.map { sanitize(it) } val sanitizedLines = lines.map { sanitize(it) }
sanitizedLines sanitizedLines
.map { pattern.matcher(it) } .map { pattern.matcher(it) }
.filter { it.find() } .filter { it.find() }
@ -316,7 +314,7 @@ class Assembler(private var memory: Memory, private val symbols: Symbols) {
val label = param.replace("^#[<>](\\w+)$".toRegex(), "$1") val label = param.replace("^#[<>](\\w+)$".toRegex(), "$1")
val hilo = param.replace("^#([<>]).*$".toRegex(), "$1") val hilo = param.replace("^#([<>]).*$".toRegex(), "$1")
pushByte(opcode) pushByte(opcode)
val addr = labels.get(label) val addr = labels[label]
if (addr != -1) { if (addr != -1) {
when (hilo) { when (hilo) {
">" -> { ">" -> {
@ -375,7 +373,7 @@ class Assembler(private var memory: Memory, private val symbols: Symbols) {
var parameter = param var parameter = param
if (parameter.matches("^\\w+$".toRegex())) { if (parameter.matches("^\\w+$".toRegex())) {
val lookupVal = symbols.get(parameter) // Substitute symbol by actual value, then proceed val lookupVal = symbols[parameter] // Substitute symbol by actual value, then proceed
if (lookupVal != null) { if (lookupVal != null) {
parameter = lookupVal parameter = lookupVal
} }

View File

@ -23,7 +23,7 @@ open class Display(context: Context, attrs: AttributeSet) : View(context, attrs)
private var listener: Callbacks? = null private var listener: Callbacks? = null
fun setOnDisplayCallback(callback: Callbacks) { fun setOnDisplayCallback(callback: Callbacks) {
listener = callback; listener = callback
} }
open fun updatePixel(addr: Int, value: Int) { open fun updatePixel(addr: Int, value: Int) {
@ -37,8 +37,8 @@ open class Display(context: Context, attrs: AttributeSet) : View(context, attrs)
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
val pixelSizeX = getWidth() / numX val pixelSizeX = width / numX
val pixelSizeY = getHeight() / numX val pixelSizeY = height / numX
matrix.forEachIndexed { i, _ -> matrix.forEachIndexed { i, _ ->
matrix[i].forEachIndexed { j, _ -> matrix[i].forEachIndexed { j, _ ->

View File

@ -30,7 +30,6 @@ class Memory(private val display: Display) {
var i = 0 var i = 0
var n: Int var n: Int
val dump = StringBuilder() val dump = StringBuilder()
while (i < length) { while (i < length) {
if (i.and(15) == 0) { if (i.and(15) == 0) {
if (i > 0) { if (i > 0) {

View File

@ -2,5 +2,4 @@ package android.emu6502.instructions
import java.util.* import java.util.*
class Symbols : HashMap<String, String>() { class Symbols : HashMap<String, String>()
}