Yeah I've read the docs, but even what you pasted in doesn't directly answer the question: What is the state of the AC flag after a DAA? So I think the code correctly implements the additions you mentioned. But I think we all 3 disagree on the AC flag code. Notice I didn't copy the whole function in either case, so the handling of the MSD is "not shown".<div>

<br></div><div><br><div><br><br><div class="gmail_quote">On Sat, Dec 11, 2010 at 8:16 AM, Richard Cini <span dir="ltr"><<a href="mailto:rich.cini@verizon.net">rich.cini@verizon.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">





<div>
<font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size:11pt">Al --<br>
<br>
    Thanks a lot for the email. I’m sure you looked at this, but I pulled the Intel 8080 Users Manual and under DAA, it says the following (snipping a bit):<br>
<br>
    The 8-bit number in the accumulator is adjusted to form two 4-bit [BCD] digits by the following process:<br>
<br>
        (1) If the value of the least significant 4 bits is greater than 9 <b>or </b>if the AC flag is set, 6 is added to the accumulator.<br>
        (2) if the value of the most significant 4 bits is <b>now </b>greater than 9 <b>or </b>if the CY flag is set, 6 is added to the most significant 4 bits of the accumulator.<br>
<br>
    Based on this, I would say that the second part of the test in the Altair32 code is wrong. Further, it looks like the SIMH code may be wrong as well because it doesn’t test the CY flag in the second test.<br>
<br>
    As far as the register display, I’ll make that change — oddly no one has ever reported it.<br>
<br>
    Thanks again for locating this bug.<br>
<br>
Rich<br><font color="#888888">
<br>
--<br>
Rich Cini<br>
Collector of Classic Computers<br>
Build Master and lead engineer, Altair32 Emulator<br>
<a href="http://www.altair32.com" target="_blank">http://www.altair32.com</a><br>
<a href="http://www.classiccmp.org/cini" target="_blank">http://www.classiccmp.org/cini</a></font><div><div></div><div class="h5"><br>
<br>
<br>
<br>
On 12/11/10 1:32 AM, "Al Williams" <<a href="http://al.williams@awce.com" target="_blank">al.williams@awce.com</a>> wrote:<br>
<br>
</div></div></span></font><div><div></div><div class="h5"><blockquote><font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size:11pt">Hi Rich and Bob,<br>
<br>
I've been doing some work on Vince Briel's excellent AVR emulation of the 8080 and while rewriting DAA I came across what I think to be a harmless bug but thought you might want to comment on it.<br>
<br>
>From what I can glean DAA effects all flags including half carry. And I _think_ that half carry occurs from the +6 (if it happens at all). So if you don't adjust the LSD you get AC=0. If you add 6 then if adding the 6 gives you a carry out of Bit 3 you get AC set. Note that the carry might ripple so that's NOT to say Bit 4 is necessarily 1.<br>


<br>
Here's part of Altair32's code:<br>
<br>
static void daa ( OP_ARG_U ) <br>
{<br>
// Decimal Adjust Accumulator<br>
// DAA:: A=BCD format<br>
// Flags: SZAPC<br>
// *****<br>
<br>
register /* FJS */ word tmp = ACCUM;<br>
<br>
if ( (( tmp & 0x0f ) > 0x09 ) || ( FLAGS & AC_FLAG ))<br>
tmp += 0x06;<br>
<br>
if (tmp > 0x0f)<br>
FLAGS |= AC_FLAG; // if adjusted LSB > 0xf, set AC<br>
else<br>
FLAGS &= ~AC_FLAG; // else clear SC <br>
<br>
<br>
So since tmp is not masked off, any value >0xF gets AC set even if no carry or add occurred! In other words, pretend the value of ACCUM is 90 (and thus temp is 90) with AC=0. The first if does not fire. The second if does and AC gets set. That's got to be wrong. Granted, who checks AC after DAA? But still.... <br>


<br>
<br>
So why copy Bob? Well... I think SIMH has a similar but different problem. Here's a snip from the DAA code:<br>
<br>
/*opcode=0x27*/<br>
static void i86op_daa(PC_ENV *m)<br>
{<br>
   uint16 dbyte;<br>
   dbyte = m->R_AL;<br>
   if (ACCESS_FLAG(m,F_AF)|| (dbyte&0xf) > 9)<br>
     {<br>
    dbyte += 6;<br>
    if (dbyte&0x100)<br>
      SET_FLAG(m, F_CF);<br>
    SET_FLAG(m, F_AF);<br>
     }<br>
   else<br>
<br>
<br>
Here we add 6 to dbyte and then AC is always set. If no +6 then AC is cleared. This COULD be correct behavior, but I can't find any reference material that says it is. In any event, SIMH and Altair32 are doing something different here, so they both can't be right. Meanwhile I have my own version of DAA in AVR assembler that I will spare you unless you ask. The only real silicon I have even close to operational at the moment is a Z80 and not only is it not operational, the DAA is one place where it is a lot different so I don't trust the result there.<br>


<br>
Oh. One other note about Altair32. In the debugger, the A and FLAGS display is swapped in the debug console window. The Register display up top left is ok though. I bet you've heard that one before.<br>
<br>
If either of you can show documentation on the AC flag after DAA or point to a real piece of silicon's behavior I'd like to know so I can fix the DAA code in the Briel emulator to match. Otherwise, I thought you'd like to know about this bug even though it is pretty innocuous as far as I can tell.<br>


<br>
<br>
Al Williams<br>
<a href="http://www.ddj.com/embedded" target="_blank">http://www.ddj.com/embedded</a> (among others)<br>
<br>
<br>
<br>
<br>
</span></font></blockquote>
</div></div></div>


</blockquote></div><br></div></div>