Skip to content

Commit a5d18d6

Browse files
authored
Explain the DAA instruction algorithm (#1564)
1 parent a27f704 commit a5d18d6

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

man/gbz80.7

+66-4
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,66 @@ Flags:
554554
1
555555
.El
556556
.Ss DAA
557-
Decimal Adjust Accumulator to get a correct BCD representation after an arithmetic instruction.
557+
Decimal Adjust Accumulator.
558+
.Pp
559+
Designed to be used after performing an arithmetic instruction
560+
.Pq Sy ADD , ADC , SUB , SBC
561+
whose inputs were in Binary-Coded Decimal (BCD), adjusting the result to likewise be in BCD.
562+
.Pp
563+
The exact behavior of this instruction is as follows:
564+
.Bl -tag -width Ds -offset indent
565+
.It If the subtract flag Sy N No is set:
566+
.Bl -enum -compact
567+
.It
568+
Initialize the adjustment to 0.
569+
.It
570+
If the half-carry flag
571+
.Sy H
572+
is set, then add
573+
.Ad $6
574+
to the adjustment.
575+
.It
576+
If the carry flag is set, then add
577+
.Ad $60
578+
to the adjustment.
579+
.It
580+
Subtract the adjustment from
581+
.Sy A .
582+
.It
583+
Set the carry flag if borrow (i.e. if adjustment >
584+
.Sy A ) .
585+
.El
586+
.It If the subtract flag Sy N No is not set:
587+
.Bl -enum -compact
588+
.It
589+
Initialize the adjustment to 0.
590+
.It
591+
If the half-carry flag
592+
.Sy H
593+
is set or
594+
.Sy A
595+
&
596+
.Ad $F
597+
>
598+
.Ad $9 ,
599+
then add
600+
.Ad $6
601+
to the adjustment.
602+
.It
603+
If the carry flag is set or
604+
.Sy A
605+
>
606+
.Ad $9F ,
607+
then add
608+
.Ad $60
609+
to the adjustment.
610+
.It
611+
Add the adjustment to
612+
.Sy A .
613+
.It
614+
Set the carry flag if overflow from bit 7.
615+
.El
616+
.El
558617
.Pp
559618
Cycles: 1
560619
.Pp
@@ -1072,11 +1131,14 @@ Bytes: 3
10721131
Flags: None affected.
10731132
.Ss LD [n16],SP
10741133
Store
1075-
.Sy SP & $FF
1134+
.Sy SP
1135+
&
1136+
.Ad $FF
10761137
at address
10771138
.Ar n16
10781139
and
1079-
.Sy SP >> 8
1140+
.Sy SP
1141+
>> 8
10801142
at address
10811143
.Ar n16
10821144
+ 1.
@@ -1859,7 +1921,7 @@ Set if result is 0.
18591921
.It Sy H
18601922
Set if borrow from bit 4.
18611923
.It Sy C
1862-
Set if borrow (set if
1924+
Set if borrow (i.e. if
18631925
.Ar r8
18641926
>
18651927
.Sy A ) .

0 commit comments

Comments
 (0)