Browse files

Added saving / loading of the ASM buffer

  • Loading branch information...
1 parent 1988142 commit 8f8424c51e209f3891d8e3d6d436b128e9dd5655 @sticksoft committed Apr 6, 2012
Showing with 49 additions and 7 deletions.
  1. +49 −7 src/uk/co/sticksoft/adce/MainActivity.java
View
56 src/uk/co/sticksoft/adce/MainActivity.java
@@ -1,14 +1,22 @@
package uk.co.sticksoft.adce;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.util.ArrayList;
-import android.app.*;
-import android.os.*;
-import android.view.*;
-import android.view.View.*;
-import android.widget.*;
import uk.co.sticksoft.adce.asm.Assembler;
-import uk.co.sticksoft.adce.cpu.*;
+import uk.co.sticksoft.adce.cpu.CPU;
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.ScrollView;
+import android.widget.TextView;
public class MainActivity extends Activity
{
@@ -66,7 +74,7 @@ public void onClick(View v)
asmInput = new EditText(this);
asmInput.setTextSize(8);
- asmInput.setText(notchs_example_asm);
+ load();
lyt.addView(asmInput);
Button assembleButton = new Button(this);
@@ -191,13 +199,47 @@ private void stop()
startButton.setText("Start");
}
+ private void save()
+ {
+ try
+ {
+ FileOutputStream fos = openFileOutput("asm", MODE_PRIVATE);
+ fos.write(asmInput.getText().toString().getBytes());
+ fos.flush();
+ fos.close();
+ }
+ catch (Exception e) // Pokémon exceptions are evil, apparently. I think just the name is evil :s
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void load()
+ {
+ try
+ {
+ FileInputStream fis = openFileInput("asm");
+ byte[] buffer = new byte[(int) fis.getChannel().size()];
+ fis.read(buffer);
+ fis.close();
+ asmInput.setText(new String(buffer));
+ }
+ catch (Exception e) // Pokémon exceptions are evil, apparently. I think just the name is evil :s
+ {
+ asmInput.setText(notchs_example_asm);
+ e.printStackTrace();
+ }
+ }
+
private void assemble()
{
stop();
+ save();
log("Assembling...");
cpu.reset();
asmOutput.setText("");
+
ArrayList<String> messages = new ArrayList<String>();
char[] assembled = new Assembler().assemble(asmInput.getText().toString(), messages);

0 comments on commit 8f8424c

Please sign in to comment.