<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18975"></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=792354521-11122010><FONT color=#0000ff 
size=2 face=Arial>I was not defending the simh code, and agree that it does not 
conform.  </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=792354521-11122010><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=792354521-11122010><FONT color=#0000ff 
size=2 face=Arial>Interestingly, a version of altair_cpu.c c.a. 2003 seems to be 
more correct, so it appears that some "code cleanup" introduced this form of the 
bug at a later date.  The old code still wasn't correct, as it 
didn't clear AC if the add is NOT done...</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=792354521-11122010><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=792354521-11122010><FONT color=#0000ff 
size=2 face=Arial>Obviously this needs a regression test!</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=792354521-11122010><SPAN lang=EN>
<P><FONT size=2 face="Courier New">case 047: { /* DAA */</FONT></P>
<P><FONT size=2 face="Courier New">DAR = A & 0x0F;</FONT></P>
<P><FONT size=2 face="Courier New">if (DAR > 9 || AC > 0) {</FONT></P>
<P><FONT size=2 face="Courier New">DAR += 6;</FONT></P>
<P><FONT size=2 face="Courier New">A &= 0xF0;</FONT></P>
<P><FONT size=2 face="Courier New">A |= DAR & 0x0F;</FONT></P>
<P><FONT size=2 face="Courier New">if (DAR & 0x10)</FONT></P>
<P><FONT size=2 face="Courier New">AC = 0200000;</FONT></P>
<P><FONT size=2 face="Courier New">else</FONT></P>
<P><FONT size=2 face="Courier New">AC = 0;</FONT></P>
<P><FONT size=2 face="Courier New">}</FONT></P>
<P><FONT size=2 face="Courier New">DAR = (A >> 4) & 0x0F;</FONT></P>
<P><FONT size=2 face="Courier New">if (DAR > 9 || AC > 0) {</FONT></P>
<P><FONT size=2 face="Courier New">DAR += 6;</FONT></P>
<P><FONT size=2 face="Courier New">if (AC) DAR++;</FONT></P>
<P><FONT size=2 face="Courier New">A &= 0x0F;</FONT></P>
<P><FONT size=2 face="Courier New">A |= (DAR << 4);</FONT></P>
<P><FONT size=2 face="Courier New">}</FONT></P>
<P><FONT size=2 face="Courier New">if ((DAR << 4) & 0x100)</FONT></P>
<P><FONT size=2 face="Courier New">C = 0200000;</FONT></P>
<P><FONT size=2 face="Courier New">else</FONT></P>
<P><FONT size=2 face="Courier New">C = 0;</FONT></P>
<P><FONT size=2 face="Courier New">if (A & 0x80) {</FONT></P>
<P><FONT size=2 face="Courier New">S = 0200000;</FONT></P>
<P><FONT size=2 face="Courier New">} else {</FONT></P>
<P><FONT size=2 face="Courier New">S = 0;</FONT></P>
<P><FONT size=2 face="Courier New">}</FONT></P>
<P><FONT size=2 face="Courier New">if ((A & 0xff) == 0)</FONT></P>
<P><FONT size=2 face="Courier New">Z = 0200000;</FONT></P>
<P><FONT size=2 face="Courier New">else</FONT></P>
<P><FONT size=2 face="Courier New">Z = 0;</FONT></P>
<P><FONT size=2 face="Courier New">parity(A);</FONT></P>
<P><FONT size=2 face="Courier New">A = A & 0xFF;</FONT></P>
<P><FONT size=2 face="Courier New">break;</FONT></P>
<P><FONT size=2 face="Courier New">}</FONT></P></SPAN></SPAN></DIV><!-- Converted from text/plain format --><BR>
<P><FONT 
size=2>---------------------------------------------------------<BR>This 
communication may not represent my employer's views,<BR>if any, on the matters 
discussed.<BR> </FONT> </P>
<DIV> </DIV><BR>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> Al Williams [mailto:al.williams@awce.com] 
<BR><B>Sent:</B> Saturday, December 11, 2010 12:08<BR><B>To:</B> Timothe 
Litt<BR><B>Cc:</B> Richard Cini; simh@trailing-edge.com; Vince 
Briel<BR><B>Subject:</B> Re: [Simh] DAA Emulation<BR></FONT><BR></DIV>
<DIV></DIV>I agree with your interpretation and by that interpretation the code 
in both emulators is currently busted. In the case of SIMH adding 6 does not 
always result in a half carry. 
<DIV><BR></DIV>
<DIV>Granted if LSD is >9 it will cause AC to set. But in the case when AC is 
already set this isn't always the case. Assuming the last add was BCD you could 
have X9+Y9 = [X+Y+1]2.</DIV>
<DIV><BR></DIV>
<DIV>So the LSD is 2 and AC is set. Adding 6 gives you 8 and no half carry. So 
setting the flag every time you add 6 is incorrect.</DIV>
<DIV><BR><BR>
<DIV class=gmail_quote>On Sat, Dec 11, 2010 at 10:51 AM, Timothe Litt <SPAN 
dir=ltr><<A href="mailto:litt@ieee.org">litt@ieee.org</A>></SPAN> 
wrote:<BR>
<BLOCKQUOTE 
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" 
class=gmail_quote>
  <DIV>
  <DIV dir=ltr align=left><SPAN><FONT color=#0000ff size=2 face=Arial>According 
  to the Sep 75 Intel 8080 Microcomputer Systems manual:</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN><FONT color=#0000ff size=2 
  face=Arial></FONT></SPAN> </DIV>
  <DIV dir=ltr align=left><SPAN><FONT color=#0000ff size=2 face=Arial>P 4-3: 
  Auxiliary Carry: If the instruction caused a carry out of bit 3 and into bit 4 
  of the resulting value, the auxiliary carry is set; otherwise it is 
  reset.  This flag is affected by single precision additions, 
  subtractions, increments, decrements, comparisons and logical operations, but 
  is principally used with additions and increments preceding a DAA (Decimal 
  Adjust Accumulator) instruction.</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN><FONT color=#0000ff size=2 
  face=Arial></FONT></SPAN> </DIV>
  <DIV dir=ltr align=left><SPAN><FONT color=#0000ff size=2 face=Arial>P 4-8: DAA 
  description has the text previously cited, plus</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN>    <FONT color=#0000ff size=2 
  face=Arial>NOTE: All flags are affected</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN>    <FONT color=#0000ff size=2 
  face=Arial>Cycles: 1</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN>    <FONT color=#0000ff size=2 
  face=Arial>States: 4</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN>    <FONT color=#0000ff size=2 
  face=Arial>Flags: Z,S,P,CY,AC</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN><FONT color=#0000ff size=2 
  face=Arial></FONT></SPAN> </DIV>
  <DIV><FONT color=#0000ff size=2 face=Arial><SPAN>I read this as AC should 
  be set if the first add 6 (to the LSB of A) happened and caused a carry and 
  should be cleared otherwise.  (Only this add can cause a carry from bit 3 
  to bit 4.)</SPAN></FONT></DIV>
  <DIV><FONT color=#0000ff size=2 face=Arial></FONT></DIV>
  <DIV><FONT color=#0000ff size=2 face=Arial></FONT> </DIV>
  <DIV><FONT color=#0000ff size=2 face=Arial></FONT><BR></DIV>
  <P><FONT 
  size=2>---------------------------------------------------------<BR>This 
  communication may not represent my employer's views,<BR>if any, on the matters 
  discussed.<BR> </FONT> </P>
  <DIV> </DIV><BR>
  <DIV dir=ltr lang=en-us align=left>
  <HR>
  <FONT size=2 face=Tahoma><B>From:</B> <A 
  href="mailto:simh-bounces@trailing-edge.com" 
  target=_blank>simh-bounces@trailing-edge.com</A> [mailto:<A 
  href="mailto:simh-bounces@trailing-edge.com" 
  target=_blank>simh-bounces@trailing-edge.com</A>] <B>On Behalf Of </B>Al 
  Williams<BR><B>Sent:</B> Saturday, December 11, 2010 10:30<BR><B>To:</B> 
  Richard Cini<BR><B>Cc:</B> <A href="mailto:simh@trailing-edge.com" 
  target=_blank>simh@trailing-edge.com</A>; Vince Briel<BR><B>Subject:</B> Re: 
  [Simh] DAA Emulation<BR></FONT><BR></DIV>
  <DIV>
  <DIV></DIV>
  <DIV class=h5>
  <DIV></DIV>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" 
  target=_blank>rich.cini@verizon.net</A>></SPAN> wrote:<BR>
  <BLOCKQUOTE 
  style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" 
  class=gmail_quote>
    <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><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>
    <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></DIV></DIV></DIV></BLOCKQUOTE></DIV><BR></DIV></BODY></HTML>