diff options
| author | Astrid Smith | 2010-09-14 22:50:24 -0700 |
|---|---|---|
| committer | Astrid Smith | 2010-09-14 22:50:24 -0700 |
| commit | d0d96373296052894cea14a7802521cc551219a8 (patch) | |
| tree | 67b419152b78fad316c8b42459b02923f0d4a6a4 | |
| parent | 2fffd745741cdefa133837a40d3672894f610e81 (diff) | |
Conditional jumps work now.
Holy shit that was a hairy debug session. I have a lot to look
forward to.
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | alu.asm | 2 | ||||
| -rw-r--r-- | flags.asm | 17 | ||||
| -rw-r--r-- | opcodes.asm | 15 | ||||
| -rw-r--r-- | testbenches/mine.z80 | 22 |
5 files changed, 41 insertions, 17 deletions
@@ -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 @@ -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 @@ -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: |
