aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Isom <kyle@tyrfingr.is>2014-01-29 14:20:33 -0700
committerKyle Isom <kyle@tyrfingr.is>2014-01-29 14:20:33 -0700
commit4c3f4858de323f983628a9889fac1fe09de70c2a (patch)
treeea18db6339027536ce3e5fcd04beda44c56b2242
parent8e4a7fab6904a33371393f0fd5fbde9570f8ee57 (diff)
downloadk6502-4c3f4858de323f983628a9889fac1fe09de70c2a.tar.gz
k6502-4c3f4858de323f983628a9889fac1fe09de70c2a.tar.bz2
k6502-4c3f4858de323f983628a9889fac1fe09de70c2a.zip
Add (playerless) snake example
-rw-r--r--src/easy6502.cc96
1 files changed, 84 insertions, 12 deletions
diff --git a/src/easy6502.cc b/src/easy6502.cc
index 3f93c53..50a205b 100644
--- a/src/easy6502.cc
+++ b/src/easy6502.cc
@@ -14,9 +14,16 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-// This is a test of instructions from http://skilldrick.github.io/easy6502/index.html.
-// As this library isn't an assembler, it won't assemble the files; I'm
-// to check some of the expected behaviours from the emulator.
+/*
+ * This is a test of programs from
+ * http://skilldrick.github.io/easy6502/index.html.
+ *
+ * As this library isn't an assembler, it won't assemble the files; I'm
+ * to check some of the expected behaviours from the emulator. Some of
+ * the examples had to be changed, as this test CPU uses only 1K of RAM,
+ * with a starting PC 0f $0300; the easy6502 VM has much more memory and
+ * uses a starting PC of $0600.
+ */
#include <iomanip>
#include <iostream>
@@ -35,6 +42,7 @@ void test7(void);
void test8(void);
void test9(void);
void test10(void);
+void test11(void);
static void
@@ -220,17 +228,81 @@ test10()
}
+void
+test11()
+{
+ // This test requires more memory and a different PC to
+ // avoid having to rewrite large swaths of 6502 for this test.
+ std::cerr << "\nStarting test 11\n";
+ std::cerr << "\t(Player-less snake)\n";
+
+ unsigned char program[] = {
+ 0x20, 0x06, 0x06, 0x20, 0x38, 0x06, 0x20, 0x0d,
+ 0x06, 0x20, 0x2a,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, 0x06, 0x4c,
+ 0x35, 0x07, 0x60, 0xa6, 0x03, 0xca, 0x8a, 0xb5,
+ 0x10, 0x95, 0x12, 0xca, 0x10, 0xf9, 0xa5, 0x02,
+ 0x4a, 0xb0, 0x09, 0x4a, 0xb0, 0x19, 0x4a, 0xb0,
+ 0x1f, 0x4a, 0xb0, 0x2f, 0xa5, 0x10, 0x38, 0xe9,
+ 0x20, 0x85, 0x10, 0x90, 0x01, 0x60, 0xc6, 0x11,
+ 0xa9, 0x01, 0xc5, 0x11, 0xf0, 0x28, 0x60, 0xe6,
+ 0x10, 0xa9, 0x1f, 0x24, 0x10, 0xf0, 0x1f, 0x60,
+ 0xa5, 0x10, 0x18, 0x69, 0x20, 0x85, 0x10, 0xb0,
+ 0x01, 0x60, 0xe6, 0x11, 0xa9, 0x06, 0xc5, 0x11,
+ 0xf0, 0x0c, 0x60, 0xc6, 0x10, 0xa5, 0x10, 0x29,
+ 0x1f, 0xc9, 0x1f, 0xf0, 0x01, 0x60, 0x4c, 0x35,
+ 0x07, 0xa0, 0x00, 0xa5, 0xfe, 0x91, 0x00, 0x60,
+ 0xa2, 0x00, 0xa9, 0x01, 0x81, 0x10, 0xa6, 0x03,
+ 0xa9, 0x00, 0x81, 0x10, 0x60, 0xa2, 0x00, 0xea,
+ 0xea, 0xca, 0xd0, 0xfb, 0x60,
+ };
+ CPU cpu(0x800);
+ std::cerr << "\nPROGRAM:\n";
+ dump_program(program, 0x134);
+ std::cerr << std::endl;
+
+ cpu.load(program, 0x600, 0x134);
+ cpu.start_pc(0x600);
+
+ cpu.run(true);
+ cpu.dump_memory();
+ cpu.dump_registers();
+}
+
+
int
main(void)
{
- // test1();
- // test2();
- // test3();
- // test4();
- // test5();
- // test6();
- // test7();
- // test8();
- // test9();
+ test1();
+ test2();
+ test3();
+ test4();
+ test5();
+ test6();
+ test7();
+ test8();
+ test9();
test10();
+ test11();
}