summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan Smith2010-09-14 22:50:24 -0700
committerDuncan Smith2010-09-14 22:50:24 -0700
commit3759ea83b657719244d12765f5717cae576fefb5 (patch)
tree151975ce00bbcf342a20557fe4329d84fc694981
parent1f43ebf7030be20a3e559375a0ad09262ca2e1c3 (diff)
Conditional jumps work now.
Holy shit that was a hairy debug session. I have a lot to look forward to.
-rw-r--r--Makefile2
-rw-r--r--alu.asm2
-rw-r--r--flags.asm17
-rw-r--r--opcodes.asm15
-rw-r--r--testbenches/mine.z8022
5 files changed, 41 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index e5a4ad6..45601d9 100644
--- a/Makefile
+++ b/Makefile
@@ -26,5 +26,5 @@ testbenches/mine.h: testbenches/mine.bin
hexdump -v -e '12/1 "0x%02x, "' -e '"\n"' testbenches/mine.bin | sed -e 's/0x *,//g' >> testbenches/mine.h
echo '};' >> testbenches/mine.h
-testbenches/zexdoc.bin: testbenches/mine.z80
+testbenches/mine.bin: testbenches/mine.z80
spasm testbenches/mine.z80
diff --git a/alu.asm b/alu.asm
index 5eb79de..3432938 100644
--- a/alu.asm
+++ b/alu.asm
@@ -86,6 +86,6 @@ alu_cp:
move.b #1,f_tmp_byte
andi.b #%00000010,flag_valid
move.b #%00000010,flag_byte
- sub d0,d1
+ sub.b d0,d1
move sr,f_host_sr
rts
diff --git a/flags.asm b/flags.asm
index 40e2f44..0377108 100644
--- a/flags.asm
+++ b/flags.asm
@@ -44,7 +44,9 @@ F_ADD_SAVE MACRO
F_SET #%
ENDM
- ;; Normalize and return carry bit (is loaded into Z bit)
+ ;; Normalize and return inverse of emulated Carry bit (loaded
+ ;; into host zero flag)
+
;; Destroys d1
f_norm_c:
move.b flag_valid-flag_storage(a3),d1
@@ -60,7 +62,9 @@ FNC_ok:
andi.b #%00000001,d1
rts
- ;; Normalize and return zero bit (loaded into Z bit)
+ ;; Normalize and return inverse of emulated Zero bit (loaded
+ ;; into host zero flag)
+
;; Destroys d1
f_norm_z:
move.b flag_valid-flag_storage(a3),d1
@@ -72,8 +76,9 @@ FNZ_ok:
andi.b #%01000000,d1
rts
- ;; Normalize and return Parity/oVerflow bit (loaded into Z
- ;; bit)
+ ;; Normalize and return inverse of emulated Parity/oVerflow
+ ;; bit (loaded into host zero flag)
+
;; Destroys d1
f_norm_pv:
move.b flag_valid-flag_storage(a3),d1
@@ -160,7 +165,9 @@ f_cc_byte:
popm d2-d5
rts
- ;; Normalize and return Sign bit (loaded into Z bit).
+ ;; Normalize and return inverse of emulated Sign bit (loaded
+ ;; into host zero flag).
+
;; Destroys d1
f_norm_sign:
move.b flag_valid-flag_storage(a3),d1
diff --git a/opcodes.asm b/opcodes.asm
index 7568c49..b96af7b 100644
--- a/opcodes.asm
+++ b/opcodes.asm
@@ -415,7 +415,7 @@ emu_op_18:
FETCHBI d1
move.l epc,a0
bsr underef
- add.w d1,d0 ; ??? Can I avoid underef/deref cycle?
+ add.w d0,d1 ; ??? Can I avoid underef/deref cycle?
bsr deref
move.l a0,epc
DONE ;nok
@@ -479,7 +479,8 @@ emu_op_20:
;; PC <- PC+immed.b
;; No flags
bsr f_norm_z
- bne emu_op_18 ; branch taken: zero clear
+ ;; if the emulated Z flag is set, this will be clear
+ beq emu_op_18 ; branch taken: Z reset -> eq (zero set)
add.l #1,epc
DONE ;nok
@@ -674,10 +675,10 @@ emu_op_37:
;; SCF
;; Set Carry Flag
;; XXX flags are more complicated than this :(
- move.b #%00111011,flag_valid-flag_storage(a3)
+ ori.b #%00111011,flag_valid-flag_storage(a3)
move.b eaf,d1
ori.b #%00000001,d1
- andi.b #%00101001,d1
+ andi.b #%11101101,d1
or.b d1,flag_byte-flag_storage(a3)
DONE ;nok
@@ -1734,7 +1735,7 @@ F_CP_B MACRO
START
emu_op_b8:
;; CP B
- move.b ebc,d2
+ move.w ebc,d2
LOHI d2
F_CP_B d2,eaf
DONE ;nok
@@ -1748,7 +1749,7 @@ emu_op_b9:
START
emu_op_ba:
;; CP D
- move.b ede,d2
+ move.w ede,d2
LOHI d2
F_CP_B d2,eaf
DONE ;nok
@@ -1762,7 +1763,7 @@ emu_op_bb:
START
emu_op_bc:
;; CP H
- move.b ehl,d2
+ move.w ehl,d2
LOHI d2
F_CP_B d2,eaf
DONE ;nok
diff --git a/testbenches/mine.z80 b/testbenches/mine.z80
index aa33fb5..57c6998 100644
--- a/testbenches/mine.z80
+++ b/testbenches/mine.z80
@@ -3,7 +3,7 @@
.ORG 4000h
- call cond_jr ;cd
+ call cond_jr_no ;cd
halt ;76
inc8:
@@ -19,7 +19,8 @@ dec8:
dec a ;3d
ret ;c9
-cond_jr:
+ ;; Test jump-not-taken of JR [C,NC,Z]
+cond_jr_no:
ld a,01h ;3e 01
cp a ;bf
jr nz,wrong ;20 07
@@ -31,10 +32,25 @@ cond_jr:
jr nc,wrong ;30
ret ;c9
-
wrong:
jp wrong
+ ;; Test jump-taken of JR [C,NC,Z]
+cond_jr_yes:
+ ld a,01h ;3e 01
+ ld b,02h ;06 02
+ cp b ;b8
+ jr nz,right1 ;20
+ jp wrong
+right1: scf ;37
+ jr c,right2 ;38
+ jp wrong
+right2: ccf ;3f
+ jr nc,right3 ;30
+ jp wrong
+right3: ret ;c9
+
+
data8:
.db 0a5h
data16: