Canola  0.8.D001
lib/number/get_display.cc
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2011, 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #include <lib/ac/assert.h>
00019 
00020 #include <lib/number.h>
00021 
00022 
00023 display
00024 number::get_display(void)
00025     const
00026 {
00027     display result;
00028 
00029     int dec_pt = decimal;
00030     bool zero_sup = true;
00031     if (has_overflowed())
00032     {
00033         // Instruction Manual, p. 21:
00034         //
00035         // "If the number of integral digits exceeds 16, the position
00036         // of the decimal point automatically indicates the number of
00037         // integral digits that have been dropped.  (For instance, if 3
00038         // integral digits are dropped, the decimal point appears after
00039         // the third digit from the left.)  In this case, the overflow
00040         // lamp lights, but the actual position of the decimal point is
00041         // preserved within the registers."
00042         //
00043         // Note: from the LEFT
00044         //
00045         result.overflow = true;
00046         assert(decimal == 0);
00047         size_t vdc = value.get_digit_count();
00048         if (vdc >= 32)
00049             dec_pt = 0;
00050         else
00051             dec_pt = 32 - vdc;
00052 
00053         // <question>
00054         // Is zero supression active for overflowed values?  It probably
00055         // should not be, cponsidering there are valid digits to the
00056         // left of those displayed.
00057         // </question>
00058         zero_sup = false;
00059     }
00060 
00061     for (int dignum = 15; dignum >= 0; --dignum)
00062     {
00063         int n = value.get(dignum);
00064         if ((unsigned)dignum <= dec_pt)
00065             zero_sup = false;
00066         if (n != 0)
00067             zero_sup = false;
00068         display::tube_t &tube = result.tubes[dignum];
00069         if (n != 0 || !zero_sup)
00070             tube.digit = n;
00071         else
00072             tube.digit = 10;
00073         tube.dot = ((unsigned)dignum == dec_pt);
00074         tube.tick = (dignum > 0) && (((18 + dignum - decimal) % 3) == 0);
00075     }
00076     result.negative = negative;
00077     return result;
00078 }
00079 
00080 
00081 // vim: set ts=8 sw=4 et :