Skip to content

Commit

Permalink
Add more reasonable DAA pcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekkio committed Nov 21, 2022
1 parent 28147ad commit e7e8444
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- DAA pseudo op tracks data dependencies much better

## 20221116 - 2022-11-16

### Changed
Expand Down
2 changes: 1 addition & 1 deletion data/languages/sm83.sinc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ HiMem8: (imm8) is imm8 {
}

define pcodeop IME;
define pcodeop daa;
define pcodeop daaOperand;
define pcodeop halt;
define pcodeop stop;

Expand Down
9 changes: 8 additions & 1 deletion data/languages/sm83_instructions.sinc
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,14 @@
}

:DAA is op0_8=0x27 {
A = daa(A);
local op8:1 = 0;
op8 = daaOperand(A, $(C_flag), $(H_flag), $(N_flag));
local tmp:1 = A + op8;
local co:1 = carry(A, op8);
$(Z_flag) = (tmp == 0);
$(H_flag) = 0;
$(C_flag) = $(C_flag) || ((!$(N_flag)) && co);
A = tmp;
}

:CPL is op0_8=0x2f {
Expand Down
12 changes: 7 additions & 5 deletions src/test/kotlin/fi/gekkio/ghidraboy/decompiler/DecompilerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,14 @@ class DecompilerTest : IntegrationTest() {
"""
byte daa(byte value)
{
byte bVar1;
bVar1 = daa(value + 1);
if ((byte)(value + 1) == '\0') {
return bVar1;
char cVar1;
byte bVar2;
cVar1 = daaOperand(value + 1,0xfe < value,((value & 0xf) + 1 & 0x10) != 0,0);
bVar2 = value + 1 + cVar1;
if (bVar2 == 0) {
return bVar2;
}
return bVar1 + 1;
return bVar2 + 1;
}
""".trimIndent()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class MiscInstructionTest : EmuTest() {

@Test
fun `DAA`() {
emulator.registerCallOtherCallback("daa", IgnorePCode())
emulator.registerCallOtherCallback("daaOperand", IgnorePCode())
emulator.writeF(0b0000_0000u)
emulator.writeA(0x00u)
emulator.write(0x0000u, 0x27u)
emulator.step()
emulator.assertPC(0x0001u)
Expand Down

0 comments on commit e7e8444

Please sign in to comment.