2015-06-09 17:21:49 +00:00
|
|
|
package android.emu6502.app
|
|
|
|
|
2015-06-22 07:25:33 +00:00
|
|
|
import android.emu6502.Display
|
2015-06-12 06:26:47 +00:00
|
|
|
import android.emu6502.Emulator
|
2015-06-09 17:21:49 +00:00
|
|
|
import android.emu6502.R
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.support.design.widget.FloatingActionButton
|
2015-06-29 06:26:56 +00:00
|
|
|
import android.support.design.widget.Snackbar
|
2015-06-09 17:21:49 +00:00
|
|
|
import android.support.v7.app.ActionBar
|
|
|
|
import android.support.v7.app.AppCompatActivity
|
|
|
|
import android.support.v7.widget.Toolbar
|
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuItem
|
2015-06-22 07:25:33 +00:00
|
|
|
import android.view.View
|
2015-06-29 06:26:56 +00:00
|
|
|
import android.widget.Button
|
|
|
|
import android.widget.LinearLayout
|
2015-06-09 17:21:49 +00:00
|
|
|
import android.widget.TextView
|
|
|
|
import butterknife.bindView
|
|
|
|
|
|
|
|
public class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
val toolbar: Toolbar by bindView(R.id.toolbar)
|
|
|
|
val txtA: TextView by bindView(R.id.A)
|
|
|
|
val txtX: TextView by bindView(R.id.X)
|
|
|
|
val txtY: TextView by bindView(R.id.Y)
|
|
|
|
val txtSP: TextView by bindView(R.id.SP)
|
|
|
|
val txtPC: TextView by bindView(R.id.PC)
|
|
|
|
val txtFlags: TextView by bindView(R.id.PC)
|
2015-06-22 07:25:33 +00:00
|
|
|
val display: Display by bindView(R.id.display)
|
2015-06-12 06:26:47 +00:00
|
|
|
val txtInstructions: TextView by bindView(R.id.txtInstructions)
|
|
|
|
val fabRun: FloatingActionButton by bindView(R.id.fabRun)
|
2015-06-29 06:26:56 +00:00
|
|
|
val layoutContent: LinearLayout by bindView(R.id.layout_content)
|
|
|
|
val btnLeft: Button by bindView(R.id.arrowLeft)
|
|
|
|
val btnRight: Button by bindView(R.id.arrowRight)
|
|
|
|
val btnUp: Button by bindView(R.id.arrowUp)
|
|
|
|
val btnDown: Button by bindView(R.id.arrowDown)
|
|
|
|
|
|
|
|
private var emulator: Emulator? = null
|
2015-06-09 17:21:49 +00:00
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_main)
|
|
|
|
|
|
|
|
setSupportActionBar(toolbar)
|
|
|
|
|
|
|
|
var ab: ActionBar = getSupportActionBar()
|
|
|
|
ab.setDisplayHomeAsUpEnabled(true)
|
2015-06-12 06:26:47 +00:00
|
|
|
|
|
|
|
fabRun.setOnClickListener {
|
2015-06-22 07:25:33 +00:00
|
|
|
display.setVisibility(View.VISIBLE)
|
2015-06-29 06:26:56 +00:00
|
|
|
emulator = Emulator(display)
|
|
|
|
val emu: Emulator = emulator as Emulator
|
|
|
|
emu.assembler.assembleCode(txtInstructions.getText().toString().splitBy("\n"))
|
|
|
|
Snackbar.make(layoutContent,
|
|
|
|
"Code assembled successfully, ${emu.assembler.codeLen} bytes.",
|
|
|
|
Snackbar.LENGTH_SHORT).show()
|
|
|
|
emu.cpu.run()
|
|
|
|
}
|
|
|
|
|
|
|
|
val onClickButton = { code: Int ->
|
|
|
|
if (emulator != null) {
|
|
|
|
val emu = emulator as Emulator
|
|
|
|
emu.cpu.memory.storeKeypress(code)
|
|
|
|
}
|
2015-06-12 06:26:47 +00:00
|
|
|
}
|
2015-06-29 06:26:56 +00:00
|
|
|
btnLeft.setOnClickListener { onClickButton(0x61) }
|
|
|
|
btnRight.setOnClickListener { onClickButton(0x64) }
|
|
|
|
btnUp.setOnClickListener { onClickButton(0x77) }
|
|
|
|
btnDown.setOnClickListener { onClickButton(0x73) }
|
2015-06-09 17:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
getMenuInflater().inflate(R.menu.menu_main, menu)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
|
|
|
// Handle action bar item clicks here. The action bar will
|
|
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
|
val id = item!!.getItemId()
|
|
|
|
|
|
|
|
//noinspection SimplifiableIfStatement
|
|
|
|
if (id == R.id.action_settings) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item)
|
|
|
|
}
|
|
|
|
}
|