Permalink
Browse files

Initial commit

  • Loading branch information...
felipecsl committed Jun 9, 2015
0 parents commit 1678927978684167819ec4ac2c4f9182676863fb
Showing with 1,179 additions and 0 deletions.
  1. +18 −0 .gitignore
  2. +1 −0 app/.gitignore
  3. +36 −0 app/build.gradle
  4. +17 −0 app/proguard-rules.pro
  5. +14 −0 app/src/androidTest/java/felipecsl/com/emu6502/ApplicationTest.java
  6. +21 −0 app/src/main/AndroidManifest.xml
  7. +16 −0 app/src/main/java/android/emu6502/Emu6502Application.java
  8. +259 −0 app/src/main/kotlin/android/emu6502/Assembler.kt
  9. +56 −0 app/src/main/kotlin/android/emu6502/CPU.kt
  10. +13 −0 app/src/main/kotlin/android/emu6502/Labels.kt
  11. +13 −0 app/src/main/kotlin/android/emu6502/Memory.kt
  12. +13 −0 app/src/main/kotlin/android/emu6502/Symbols.kt
  13. +54 −0 app/src/main/kotlin/android/emu6502/app/MainActivity.kt
  14. +5 −0 app/src/main/kotlin/android/emu6502/instructions/AddressingMode.kt
  15. +55 −0 app/src/main/kotlin/android/emu6502/instructions/BaseInstruction.kt
  16. +7 −0 app/src/main/kotlin/android/emu6502/instructions/Instruction.kt
  17. +8 −0 app/src/main/kotlin/android/emu6502/instructions/ORA.kt
  18. +66 −0 app/src/main/kotlin/android/emu6502/instructions/Opcodes.kt
  19. BIN app/src/main/res/drawable-xxxhdpi/ic_play_arrow_white_48dp.png
  20. +156 −0 app/src/main/res/layout/activity_main.xml
  21. +8 −0 app/src/main/res/layout/toolbar.xml
  22. +6 −0 app/src/main/res/menu/menu_main.xml
  23. BIN app/src/main/res/mipmap-hdpi/ic_launcher.png
  24. BIN app/src/main/res/mipmap-hdpi/ic_play_arrow_white_48dp.png
  25. BIN app/src/main/res/mipmap-mdpi/ic_launcher.png
  26. BIN app/src/main/res/mipmap-xhdpi/ic_launcher.png
  27. BIN app/src/main/res/mipmap-xhdpi/ic_play_arrow_white_48dp.png
  28. BIN app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  29. BIN app/src/main/res/mipmap-xxhdpi/ic_play_arrow_white_48dp.png
  30. +6 −0 app/src/main/res/values-w820dp/dimens.xml
  31. +9 −0 app/src/main/res/values/colors.xml
  32. +7 −0 app/src/main/res/values/dimens.xml
  33. +4 −0 app/src/main/res/values/strings.xml
  34. +11 −0 app/src/main/res/values/styles.xml
  35. +21 −0 build.gradle
  36. +18 −0 gradle.properties
  37. BIN gradle/wrapper/gradle-wrapper.jar
  38. +6 −0 gradle/wrapper/gradle-wrapper.properties
  39. +164 −0 gradlew
  40. +90 −0 gradlew.bat
  41. +1 −0 settings.gradle
@@ -0,0 +1,18 @@
# ant
bin
build
gen
out
lib
# intellij
.idea
*.iml
# eclipse
.classpath
.project
.settings
.DS_Store
local.properties
.gradle
@@ -0,0 +1 @@
/build
@@ -0,0 +1,36 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "android.emu6502"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:cardview-v7:22.2.0'
compile 'org.jetbrains.kotlin:kotlin-stdlib:0.12.213'
compile "org.jetbrains.kotlin:kotlin-android-sdk-annotations:0.12.213"
compile "org.jetbrains.kotlin:kotlin-reflect:0.12.213"
compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
compile 'com.facebook.stetho:stetho:1.1.1'
}
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/felipe_lima/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
@@ -0,0 +1,14 @@
package felipecsl.com.emu6502;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.emu6502" >
<application
android:allowBackup="true"
android:name=".Emu6502Application"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".app.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
@@ -0,0 +1,16 @@
package android.emu6502;
import android.app.Application;
import com.facebook.stetho.Stetho;
public class Emu6502Application extends Application {
@Override public void onCreate() {
super.onCreate();
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
}
}
@@ -0,0 +1,259 @@
package android.emu6502
import android.emu6502.instructions.Instruction
import android.emu6502.instructions.Opcodes
import java.util.regex.Pattern
class Assembler(private var labels: Labels,
private var memory: Memory,
private var symbols: Symbols) {
private var defaultCodePC = 0
private var codeLen = 0
private var codeAssembledOK = false
private var BOOTSTRAP_ADDRESS = 0x600
fun assembleCode(lines: Array<String>): Boolean {
lines.forEach { line ->
if (!assembleLine(line)) {
return false
}
}
return true
}
private fun assembleLine(line: String): Boolean {
var input = line
var command: String
var param: String
var addr: Int
// Find command or label
if (input.matches("^\\w+:".toRegex())) {
if (line.matches("^\\w+:[\\s]*\\w+.*$".toRegex())) {
input = input.replace("^\\w+:[\\s]*(.*)$".toRegex(), "$1")
command = input.replace("^(\\w+).*$".toRegex(), "$1")
} else {
command = ""
}
} else {
command = input.replace("^(\\w+).*$".toRegex(), "$1")
}
// Nothing to do for blank lines
if (command.equals("")) {
return true
}
command = command.toUpperCase()
if (input.matches("^\\*\\s*=\\s*\$?[0-9a-f]*$".toRegex())) {
// equ spotted
param = input.replace("^\\s*\\*\\s*=\\s*".toRegex(), "")
if (param[0].equals("$")) {
param = param.replace("^\$".toRegex(), "")
addr = Integer.parseInt(param, 16)
} else {
addr = Integer.parseInt(param, 10)
}
if ((addr < 0) || (addr > 0xffff)) {
throw IllegalStateException("Unable to relocate code outside 64k memory")
}
defaultCodePC = addr
return true
}
if (input.matches("^\\w+\\s+.*?$".toRegex())) {
param = input.replace("^\\w+\\s+(.*?)".toRegex(), "$1")
} else if (input.matches("^\\w+$".toRegex())) {
param = ""
} else {
return false
}
param = param.replace("[ ]".toRegex(), "")
if (command === "DCB") {
return DCB(param)
}
val opcode = Opcodes.MAP.get(Instruction.valueOf(command))
if (opcode != null) {
if (checkImmediate(param, opcode[0])) {
return true
}
if (checkZeroPage(param, opcode[1])) {
return true
}
if (checkZeroPageX(param, opcode[2])) {
return true
}
if (checkZeroPageY(param, opcode[3])) {
return true
}
if (checkAbsolute(param, opcode[4])) {
return true
}
if (checkAbsoluteX(param, opcode[5])) {
return true
}
if (checkAbsoluteY(param, opcode[6])) {
return true
}
if (checkIndirect(param, opcode[7])) {
return true
}
if (checkIndirectX(param, opcode[8])) {
return true
}
if (checkIndirectY(param, opcode[9])) {
return true
}
if (checkSingle(param, opcode[10])) {
return true
}
if (checkBranch(param, opcode[11])) {
return true
}
}
return false
}
private fun DCB(param: String): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkBranch(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkAbsolute(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkIndirectY(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkIndirectX(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkIndirect(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkAbsoluteY(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkAbsoluteX(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkZeroPageY(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkZeroPageX(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkZeroPage(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun checkImmediate(param: String, opcode: Int): Boolean {
val pattern = Pattern.compile("^#([\\w\$]+)$")
val matcher = pattern.matcher(param)
if (matcher.find()) {
var operand = tryParseByteOperand(matcher.group(1))
if (operand >= 0) {
pushByte(opcode)
pushByte(operand)
return true
}
}
// Label lo/hi
if (param.matches("^#[<>]\\w+$".toRegex())) {
var label = param.replace("^#[<>](\\w+)$".toRegex(), "$1")
var hilo = param.replace("^#([<>]).*$".toRegex(), "$1")
pushByte(opcode)
if (labels.find(label)) {
var addr = labels.getPC(label)
when (hilo) {
">" -> {
pushByte(addr.shr(8).and(0xFF))
}
"<" -> {
pushByte(addr.and(0xFF))
}
else -> return false
}
} else {
pushByte(0x00)
return true
}
}
return false
}
// Try to parse the given parameter as a byte operand.
// Returns the (positive) value if successful, otherwise -1
private fun tryParseByteOperand(param: String): Int {
var value: Int = 0
var parameter = param;
if (parameter.matches("^\\w+$".toRegex())) {
var lookupVal = symbols.lookup(parameter) // Substitute symbol by actual value, then proceed
if (lookupVal != null) {
parameter = lookupVal
}
}
// Is it a hexadecimal operand?
var pattern = Pattern.compile("^\$([0-9a-f]{1,2})$")
var matcher = pattern.matcher(parameter)
if (matcher.find()) {
value = Integer.parseInt(matcher.group(1), 16)
} else {
// Is it a decimal operand?
pattern = Pattern.compile("^([0-9]{1,3})$")
matcher = pattern.matcher(parameter)
if (matcher.find()) {
value = Integer.parseInt(matcher.group(1), 10)
}
}
// Validate range
if (value >= 0 && value <= 0xff) {
return value
}
return -1
}
private fun pushByte(value: Int) {
memory.set(defaultCodePC, value.and(0xFF))
defaultCodePC++
codeLen++
}
private fun checkSingle(param: String, opcode: Int): Boolean {
throw UnsupportedOperationException(
"not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
Oops, something went wrong.

0 comments on commit 1678927

Please sign in to comment.