summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile15
-rw-r--r--README.markdown15
-rw-r--r--debug.c9
-rw-r--r--main.s91
-rw-r--r--memory.s91
-rw-r--r--opcodes.s.m429
-rw-r--r--test.s16
-rw-r--r--unittest.c11
-rw-r--r--unittest.h0
9 files changed, 176 insertions, 101 deletions
diff --git a/Makefile b/Makefile
index 8031a8d..5f5bb83 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
# these files are written as .s
-ASM_FILES=alu.s flags.s ports.s main.s
+ASM_FILES=alu.s flags.s ports.s main.s memory.s
# these files are written as .s.m4 and then preprocessed to .s
M4_ASM_OUTPUT=opcodes.s interrupts.s
@@ -24,26 +24,28 @@ BINS_DEBUG=z680d.dbg
OBJ_DEBUG=z680d.89z
OBJ=z680k.89z
+OBJ_TEST=z680test.89z
+
# executables to build for the host platform
NATIVE_OBJ=packager
# this is the Sierra linker from the TI Flash Studio SDK. It works
# quite well under Wine, and is a purely command-line tool.
LINKER=wine ~/.wine/drive_c/SIERRA/BIN/link68.exe
-LINKERFLAGS=
+LINKERFLAGS=-m -r
# the gnu cross-assembler
GAS=/opt/gcc4ti/bin/as
GASFLAGS=--register-prefix-optional
# flags for the tigcc cross-compiler
-TIGCCFLAGS_DEBUG=--debug -WA,-l$(LISTING_DEBUG)
+TIGCCFLAGS_DEBUG=--debug -WA,-l$(LISTING_DEBUG) -Wa,-ahls
TIGCCFLAGS=-falign-functions=4 -ffunction-sections -fdata-sections -Wall -Wextra -Wwrite-strings -Wa,$(GASFLAGS)
# flags for the native C compiler
CFLAGS=-Wall -ltifiles
-.PHONY: clean debug
+.PHONY: clean debug test
all: $(OBJ) $(NATIVE_OBJ)
@@ -52,12 +54,17 @@ clean:
debug: $(OBJ_DEBUG)
+test: $(OBJ_TEST)
+
$(OBJ): $(O_FILES)
$(LINKER) $(LINKERFLAGS) $(O_FILES) -o $(OBJ)
$(OBJ_DEBUG): $(ASM_FILES) $(M4_ASM_OUTPUT) $(C_FILES) $(MADE_FILES) $(C_HEADERS)
tigcc $(TIGCCFLAGS) $(TIGCCFLAGS_DEBUG) $(ASM) $(C_FILES) -o $(OBJ_DEBUG)
+$(OBJ_TEST): unittest.c unittest.h $(M4_ASM_OUTPUT)
+ tigcc $(TIGCCFLAGS) $(TIGCCFLAGS_DEBUG) -Wa,--defsym,TEST=1 unittest.c test.s -o $(OBJ_TEST)
+
# use the host system's native gcc for this
# utility to turn a romdump into a set of image files
packager: packager.c
diff --git a/README.markdown b/README.markdown
index 9e120d2..aa2629c 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,14 +1,17 @@
z680k: z80 emulator for 68k calculators
=======================================
- 666 888 000 k k
-zzzz 6 8 8 0 0 k k
- z 6666 888 0 0 0 kk
- z 6 6 8 8 0 0 k k
-zzzz 666 888 000 k k
+
+ 666 888 000 k k
+ zzzz 6 8 8 0 0 k k
+ z 6666 888 0 0 0 kk
+ z 6 6 8 8 0 0 k k
+ zzzz 666 888 000 k k
Astrid Smith
Project started: 2010-06-06
-GPL
+
+This software package is licensed under the terms of the GNU General
+Public License version 3.0, or (at your option) any later version.
The intent of this project is to provide a fast and correct TI-83+
emulator to run on the TI-89. Once that is done, perhaps I will
diff --git a/debug.c b/debug.c
index b98e4f6..ae760a9 100644
--- a/debug.c
+++ b/debug.c
@@ -6,9 +6,16 @@
* GPL
*/
-#include <stdio.h>
+//#include <stdio.h>
+
+short putchar(short c)
+{
+ return c;
+}
+
void char_draw(char c)
{
putchar((short)c);
}
+
diff --git a/main.s b/main.s
index fe7ba7f..ad78bfd 100644
--- a/main.s
+++ b/main.s
@@ -83,96 +83,7 @@ emu_teardown:
rts
-|| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-|| _ __ ___ ___ _ __ ___ ___ _ __ _ _ |||||||||||||||||||||||||||
-|| | '_ ` _ \ / _ \ '_ ` _ \ / _ \| '__| | | | \\\\\\\\\\\\\\\\\\\\\\\\\\\
-|| | | | | | | __/ | | | | | (_) | | | |_| | |||||||||||||||||||||||||||
-|| |_| |_| |_|\___|_| |_| |_|\___/|_| \__, | ///////////////////////////
-|| of the virtual type |___/ |||||||||||||||||||||||||||
-|| =============================================JJJJJJJJJJJJJJJJJJJJJJJJJJJ
-
- || Take a virtual address in d1 and dereference it. Returns the
- || host address in a0. Destroys a0, d0.
-deref: | 76 cycles + 18 cycles for bsr
- | 20 bytes to inline, saves 34 cycles per call
- move.w d1,d0
- andi.w #0x3FFF,d0
- movea.w d0,a0
- move.w d1,d0
- andi.w #0xC000,d0 | Can cut this out by pre-masking the table.
- rol.w #4,d0
- adda.l deref_table(pc,d0.w),a0
- rts
-
-.even
-.data
-deref_table:
-mem_page_0: .long 0 | bank 0 / 0x0000
-mem_page_1: .long 0 | bank 1 / 0x4000
-mem_page_2: .long 0 | bank 2 / 0x8000
-mem_page_3: .long 0 | bank 3 / 0xc000
-
-.xdef mem_page_0
-.xdef mem_page_1
-.xdef mem_page_2
-.xdef mem_page_3
-
-mem_page_loc_0: .byte 0
-mem_page_loc_1: .byte 0
-mem_page_loc_2: .byte 0
-mem_page_loc_3: .byte 0
-
-.xdef mem_page_loc_0
-.xdef mem_page_loc_1
-.xdef mem_page_loc_2
-.xdef mem_page_loc_3
-
-pages: .long 0
-
-.xdef pages
-
-.text
-
- || Take a physical address in a0 and turn it into a virtual
- || address in d0
- || Destroys d0
-| XXX AFAICS, a1 is currently a scratch address register, so you can load deref_table in it, and then save some space:
-| But you may wish to use it for other purposes in the future, so you needn't integrate that immediately.
-
- || Guessing this is 300 cycles.
-underef:
- move.l d2,-(a7)
- lea deref_table(pc),a1
- move.l a0,d0
- clr.w d2
- sub.l (a1)+,d0
- bmi.s underef_not0
- cmpi.l #0x4000,d0
- bmi.s underef_thatsit
-underef_not0:
- move.l a0,d0
- move.w #0x4000,d2
- sub.l (a1)+,d0
- bmi.s underef_not1
- cmpi.l #0x4000,d0
- bmi.s underef_thatsit
-underef_not1:
- move.l a0,d0
- move.w #0x8000,d2
- sub.l (a1)+,d0
- bmi.s underef_not2
- cmpi.l #0x4000,d0
- bmi.s underef_thatsit
-underef_not2:
- move.w #0xc000,d2
- suba.l (a1)+,a0
- || if that fails too, well shit man!
- moveq #0,d0
-underef_thatsit:
- add.w d2,d0
- move.l (a7)+,d2
- rts
-
+.include "memory.s"
|| =========================================================================
|| instruction instruction instruction ================================
diff --git a/memory.s b/memory.s
new file mode 100644
index 0000000..f53bdbe
--- /dev/null
+++ b/memory.s
@@ -0,0 +1,91 @@
+|| -*- gas -*-
+
+|| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+|| _ __ ___ ___ _ __ ___ ___ _ __ _ _ |||||||||||||||||||||||||||
+|| | '_ ` _ \ / _ \ '_ ` _ \ / _ \| '__| | | | \\\\\\\\\\\\\\\\\\\\\\\\\\\
+|| | | | | | | __/ | | | | | (_) | | | |_| | |||||||||||||||||||||||||||
+|| |_| |_| |_|\___|_| |_| |_|\___/|_| \__, | ///////////////////////////
+|| of the virtual type |___/ |||||||||||||||||||||||||||
+|| =============================================JJJJJJJJJJJJJJJJJJJJJJJJJJJ
+
+ || Take a virtual address in d1 and dereference it. Returns the
+ || host address in a0. Destroys a0, d0.
+deref: | 76 cycles + 18 cycles for bsr
+ | 20 bytes to inline, saves 34 cycles per call
+ move.w d1,d0
+ andi.w #0x3FFF,d0
+ movea.w d0,a0
+ move.w d1,d0
+ andi.w #0xC000,d0 | Can cut this out by pre-masking the table.
+ rol.w #4,d0
+ adda.l deref_table(pc,d0.w),a0 | TODO gas doesn't like this
+ rts
+
+.even
+.bss
+deref_table:
+mem_page_0: .long 0 | bank 0 / 0x0000
+mem_page_1: .long 0 | bank 1 / 0x4000
+mem_page_2: .long 0 | bank 2 / 0x8000
+mem_page_3: .long 0 | bank 3 / 0xc000
+
+.xdef mem_page_0
+.xdef mem_page_1
+.xdef mem_page_2
+.xdef mem_page_3
+
+mem_page_loc_0: .byte 0
+mem_page_loc_1: .byte 0
+mem_page_loc_2: .byte 0
+mem_page_loc_3: .byte 0
+
+.xdef mem_page_loc_0
+.xdef mem_page_loc_1
+.xdef mem_page_loc_2
+.xdef mem_page_loc_3
+
+pages: .long 0
+
+.xdef pages
+
+.text
+
+ || Take a physical address in a0 and turn it into a virtual
+ || address in d0
+ || Destroys d0, a1
+| XXX AFAICS, a1 is currently a scratch address register, so you can load deref_table in it, and then save some space:
+| But you may wish to use it for other purposes in the future, so you needn't integrate that immediately.
+
+ || Guessing this is 300 cycles.
+underef:
+ move.l d2,-(a7)
+ lea deref_table(pc),a1
+ move.l a0,d0
+ clr.w d2
+ sub.l (a1)+,d0
+ bmi.s underef_not0
+ cmpi.l #0x4000,d0
+ bmi.s underef_thatsit
+underef_not0:
+ move.l a0,d0
+ move.w #0x4000,d2
+ sub.l (a1)+,d0
+ bmi.s underef_not1
+ cmpi.l #0x4000,d0
+ bmi.s underef_thatsit
+underef_not1:
+ move.l a0,d0
+ move.w #0x8000,d2
+ sub.l (a1)+,d0
+ bmi.s underef_not2
+ cmpi.l #0x4000,d0
+ bmi.s underef_thatsit
+underef_not2:
+ move.w #0xc000,d2
+ suba.l (a1)+,a0
+ || if that fails too, well shit man!
+ moveq #0,d0
+underef_thatsit:
+ add.w d2,d0
+ move.l (a7)+,d2
+ rts
diff --git a/opcodes.s.m4 b/opcodes.s.m4
index d4a9564..efd583a 100644
--- a/opcodes.s.m4
+++ b/opcodes.s.m4
@@ -98,6 +98,8 @@
|| To align opcode routines.
.set _align,0
+.ifndef TEST
+
.macro start
.org emu_plain_op+_align
.set _align,_align+0x100 | opcode routine length
@@ -128,6 +130,24 @@
.org emu_plain_op+_align+0x4A
.endm
+.else
+.macro START
+.endm
+.macro START_DD
+.endm
+.macro START_CB
+.endm
+.macro START_DDCB
+.endm
+.macro START_FD
+.endm
+.macro START_FDCB
+.endm
+.macro START_ED
+.endm
+
+.endif
+
|| LOHI/HILO are hideously slow for instructions used often.
|| Consider interleaving registers instead:
||
@@ -197,6 +217,7 @@
|| lookup table
+.ifndef TEST
|| This is run at the end of every instruction routine.
done:
clr.w d0 | 4 cycles / 2 bytes
@@ -215,6 +236,14 @@ done:
jmp 0(a5,d0.w) |14 cycles / 4 bytes
.endm
+.else
+done: rts
+
+.macro DONE
+ rts
+.endm
+.endif
+
|| Timing correction for more precise emulation
||
|| \1 is number of tstates the current instruction should take
diff --git a/test.s b/test.s
new file mode 100644
index 0000000..251728e
--- /dev/null
+++ b/test.s
@@ -0,0 +1,16 @@
+.xdef _ti89
+.include "./tios.inc"
+.include "global.inc"
+.include "memory.s"
+.include "ports_test.s"
+.include "flags.s"
+.include "alu.s"
+.include "interrupts.s"
+.include "opcodes.s"
+
+
+emu_op_undo_cb:
+emu_op_undo_dd:
+emu_op_undo_ed:
+emu_op_undo_fd:
+ rts
diff --git a/unittest.c b/unittest.c
new file mode 100644
index 0000000..fe58d3d
--- /dev/null
+++ b/unittest.c
@@ -0,0 +1,11 @@
+/* Unit tests and test harness for 680 project.
+ *
+ * Copyright 2011, Astrid Smith
+ * GPL
+ */
+
+#include <default.h>
+
+void _main(void) {
+
+}
diff --git a/unittest.h b/unittest.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/unittest.h