Previous 199869 Revisions Next

r29473 Wednesday 9th April, 2014 at 00:08:21 UTC by hap
rewrote bcd_add/sub according to official doc
[src/emu/cpu/tms7000]tms7000.c tms7000.h tms70op.inc

trunk/src/emu/cpu/tms7000/tms7000.c
r29472r29473
5757
5858
5959static ADDRESS_MAP_START(tms7000_mem, AS_PROGRAM, 8, tms7000_device )
60   AM_RANGE(0x0000, 0x007f)    AM_READWRITE(tms7000_internal_r, tms7000_internal_w) /* tms7000 internal RAM */
61   AM_RANGE(0x0080, 0x00ff)    AM_NOP                      /* reserved */
62   AM_RANGE(0x0100, 0x01ff)    AM_READWRITE(tms70x0_pf_r, tms70x0_pf_w)             /* tms7000 internal I/O ports */
60   AM_RANGE(0x0000, 0x007f) AM_READWRITE(tms7000_internal_r, tms7000_internal_w) /* tms7000 internal RAM */
61   AM_RANGE(0x0080, 0x00ff) AM_NOP                                               /* reserved */
62   AM_RANGE(0x0100, 0x01ff) AM_READWRITE(tms70x0_pf_r, tms70x0_pf_w)             /* tms7000 internal I/O ports */
6363ADDRESS_MAP_END
6464
6565
r29472r29473
133133   return result | RM((mAddr+1)&0xffff);
134134}
135135
136UINT16 tms7000_device::RRF16( UINT32 mAddr )    /*Read register file (16 bit) */
136UINT16 tms7000_device::RRF16( UINT32 mAddr ) /* Read register file (16 bit) */
137137{
138138   PAIR result;
139139   result.b.h = RM((mAddr-1)&0xffff);
r29472r29473
141141   return result.w.l;
142142}
143143
144void tms7000_device::WRF16( UINT32 mAddr, PAIR p ) /*Write register file (16 bit) */
144void tms7000_device::WRF16( UINT32 mAddr, PAIR p ) /* Write register file (16 bit) */
145145{
146146   WM( (mAddr-1)&0xffff, p.b.h );
147147   WM( mAddr, p.b.l );
r29472r29473
527527}
528528
529529// BCD arthrimetic handling
530UINT16 tms7000_device::bcd_add( UINT16 a, UINT16 b )
530static const UINT8 lut_bcd_out[6] = { 0x00, 0x06, 0x00, 0x66, 0x60, 0x66 };
531
532inline UINT8 tms7000_device::bcd_add( UINT8 a, UINT8 b, UINT8 c )
531533{
532   UINT16  t1,t2,t3,t4,t5,t6;
534   c = (c != 0) ? 1 : 0;
533535
534   /* Sure it is a lot of code, but it works! */
535   t1 = a + 0x0666;
536   t2 = t1 + b;
537   t3 = t1 ^ b;
538   t4 = t2 ^ t3;
539   t5 = ~t4 & 0x1110;
540   t6 = (t5 >> 2) | (t5 >> 3);
541   return t2-t6;
536   UINT8 h1 = a >> 4 & 0xf;
537   UINT8 l1 = a >> 0 & 0xf;
538   UINT8 h2 = b >> 4 & 0xf;
539   UINT8 l2 = b >> 0 & 0xf;
540   
541   // compute bcd constant
542   UINT8 d = ((l1 + l2 + c) < 10) ? 0 : 1;
543   if ((h1 + h2) == 9)
544      d |= 2;
545   else if ((h1 + h2) > 9)
546      d |= 4;
547   
548   UINT8 ret = a + b + c + lut_bcd_out[d];
549   
550   CLR_NZC;
551   SET_N8(ret);
552   SET_Z8(ret);
553   
554   if (d > 2)
555      pSR |= SR_C;
556   
557   return ret;
542558}
543559
544UINT16 tms7000_device::bcd_tencomp( UINT16 a )
560inline UINT8 tms7000_device::bcd_sub( UINT8 a, UINT8 b, UINT8 c )
545561{
546   UINT16  t1,t2,t3,t4,t5,t6;
562   c = (c != 0) ? 0 : 1;
547563
548   t1 = 0xffff - a;
549   t2 = -a;
550   t3 = t1 ^ 0x0001;
551   t4 = t2 ^ t3;
552   t5 = ~t4 & 0x1110;
553   t6 = (t5 >> 2)|(t5>>3);
554   return t2-t6;
555}
564   UINT8 h1 = a >> 4 & 0xf;
565   UINT8 l1 = a >> 0 & 0xf;
566   UINT8 h2 = b >> 4 & 0xf;
567   UINT8 l2 = b >> 0 & 0xf;
556568
557/*
558    Compute difference a-b???
559*/
560UINT16 tms7000_device::bcd_sub( UINT16 a, UINT16 b)
561{
562   //return bcd_tencomp(b) - bcd_tencomp(a);
563   return bcd_add(a, bcd_tencomp(b) & 0xff);
569   // compute bcd constant
570   UINT8 d = ((l1 - c) >= l2) ? 0 : 1;
571   if (h1 == h2)
572      d |= 2;
573   else if (h1 < h2)
574      d |= 4;
575
576   UINT8 ret = a - b - c - lut_bcd_out[d];
577   
578   CLR_NZC;
579   SET_N8(ret);
580   SET_Z8(ret);
581   
582   if (d > 2)
583      pSR |= SR_C;
584   
585   return ret;
564586}
565587
566588WRITE8_MEMBER( tms7000_device::tms7000_internal_w )
trunk/src/emu/cpu/tms7000/tms7000.h
r29472r29473
9292   static const opcode_func s_opfn_exl[0x100];
9393   const opcode_func *m_opcode;
9494
95   static UINT16 bcd_add( UINT16 a, UINT16 b );
96   static UINT16 bcd_tencomp( UINT16 a );
97   static UINT16 bcd_sub( UINT16 a, UINT16 b);
95   inline UINT8 bcd_add( UINT8 a, UINT8 b, UINT8 c );
96   inline UINT8 bcd_sub( UINT8 a, UINT8 b, UINT8 c );
9897
99   PAIR        m_pc;         /* Program counter */
100   UINT8       m_sp;     /* Stack Pointer */
101   UINT8       m_sr;     /* Status Register */
102   UINT8       m_irq_state[3];   /* State of the three IRQs */
103   UINT8       m_rf[0x80];   /* Register file (SJE) */
104   UINT8       m_pf[0x100];  /* Perpherial file */
105   address_space *m_program;
106   direct_read_data *m_direct;
107   address_space *m_io;
98   PAIR        m_pc;               /* Program counter */
99   UINT8       m_sp;               /* Stack Pointer */
100   UINT8       m_sr;               /* Status Register */
101   UINT8       m_irq_state[3];     /* State of the three IRQs */
102   UINT8       m_rf[0x80];         /* Register file (SJE) */
103   UINT8       m_pf[0x100];        /* Perpherial file */
104
108105   int         m_icount;
109106   int         m_div_by_16_trigger;
110107   int         m_cycles_per_INT2;
111108   UINT8       m_t1_capture_latch; /* Timer 1 capture latch */
112   INT8        m_t1_prescaler;   /* Timer 1 prescaler (5 bits) */
113   INT16       m_t1_decrementer; /* Timer 1 decrementer (8 bits) */
114   UINT8       m_idle_state; /* Set after the execution of an idle instruction */
109   INT8        m_t1_prescaler;     /* Timer 1 prescaler (5 bits) */
110   INT16       m_t1_decrementer;   /* Timer 1 decrementer (8 bits) */
111   UINT8       m_idle_state;       /* Set after the execution of an idle instruction */
115112
113   address_space *m_program;
114   direct_read_data *m_direct;
115   address_space *m_io;
116
116117   inline UINT16 RM16( UINT32 mAddr );
117118   inline UINT16 RRF16( UINT32 mAddr );
118119   inline void WRF16( UINT32 mAddr, PAIR p );
120
119121   void tms7000_check_IRQ_lines();
120122   void tms7000_do_interrupt( UINT16 address, UINT8 line );
121123   void illegal();
r29472r29473
348350   void xorp_b2p();
349351   void xorp_i2p();
350352   void tms7000_service_timer1();
351
352353};
353354
354355
trunk/src/emu/cpu/tms7000/tms70op.inc
r29472r29473
12921292
12931293void tms7000_device::dac_b2a()
12941294{
1295   UINT16  t;
1295   WRA(bcd_add(RDA, RDB, pSR & SR_C));
12961296
1297   t = bcd_add( RDA, RDB );
1298
1299   if (pSR & SR_C)
1300      t = bcd_add( t, 1 );
1301
1302   WRA(t);
1303
1304   CLR_NZC;
1305   SET_C8(t);
1306   SET_N8(t);
1307   SET_Z8(t);
1308
13091297   m_icount -= 7;
13101298}
13111299
13121300void tms7000_device::dac_r2a()
13131301{
1314   UINT8   r;
1315   UINT16  t;
1316
1302   UINT8 r;
13171303   IMMBYTE(r);
13181304
1319   t = bcd_add( RDA, RM(r) );
1305   WRA(bcd_add(RDA, RM(r), pSR & SR_C));
13201306
1321   if (pSR & SR_C)
1322      t = bcd_add( t, 1 );
1323
1324   WRA(t);
1325
1326   CLR_NZC;
1327   SET_C8(t);
1328   SET_N8(t);
1329   SET_Z8(t);
1330
13311307   m_icount -= 10;
13321308}
13331309
13341310void tms7000_device::dac_r2b()
13351311{
1336   UINT8   r;
1337   UINT16  t;
1338
1312   UINT8 r;
13391313   IMMBYTE(r);
13401314
1341   t = bcd_add( RDB, RM(r) );
1315   WRB(bcd_add(RDB, RM(r), pSR & SR_C));
13421316
1343   if (pSR & SR_C)
1344      t = bcd_add( t, 1 );
1345
1346   WRB(t);
1347
1348   CLR_NZC;
1349   SET_C8(t);
1350   SET_N8(t);
1351   SET_Z8(t);
1352
13531317   m_icount -= 10;
13541318}
13551319
13561320void tms7000_device::dac_r2r()
13571321{
1358   UINT8   r,s;
1359   UINT16  t;
1360
1322   UINT8 s, r;
13611323   IMMBYTE(s);
13621324   IMMBYTE(r);
13631325
1364   t = bcd_add( RM(s), RM(r) );
1326   WM(r, bcd_add(RM(s), RM(r), pSR & SR_C));
13651327
1366   if (pSR & SR_C)
1367      t = bcd_add( t, 1 );
1368
1369   WM(r,t);
1370
1371   CLR_NZC;
1372   SET_C8(t);
1373   SET_N8(t);
1374   SET_Z8(t);
1375
13761328   m_icount -= 12;
13771329}
13781330
13791331void tms7000_device::dac_i2a()
13801332{
1381   UINT8   i;
1382   UINT16  t;
1383
1333   UINT8 i;
13841334   IMMBYTE(i);
13851335
1386   t = bcd_add( i, RDA );
1336   WRA(bcd_add(i, RDA, pSR & SR_C));
13871337
1388   if (pSR & SR_C)
1389      t = bcd_add( t, 1 );
1390
1391   WRA(t);
1392
1393   CLR_NZC;
1394   SET_C8(t);
1395   SET_N8(t);
1396   SET_Z8(t);
1397
13981338   m_icount -= 9;
13991339}
14001340
14011341void tms7000_device::dac_i2b()
14021342{
1403   UINT8   i;
1404   UINT16  t;
1405
1343   UINT8 i;
14061344   IMMBYTE(i);
14071345
1408   t = bcd_add( i, RDB );
1346   WRB(bcd_add(i, RDB, pSR & SR_C));
14091347
1410   if (pSR & SR_C)
1411      t = bcd_add( t, 1 );
1412
1413   WRB(t);
1414
1415   CLR_NZC;
1416   SET_C8(t);
1417   SET_N8(t);
1418   SET_Z8(t);
1419
14201348   m_icount -= 9;
14211349}
14221350
14231351void tms7000_device::dac_i2r()
14241352{
1425   UINT8   i,r;
1426   UINT16  t;
1427
1353   UINT8 i, r;
14281354   IMMBYTE(i);
14291355   IMMBYTE(r);
14301356
1431   t = bcd_add( i, RM(r) );
1357   WM(r, bcd_add(i, RM(r), pSR & SR_C));
14321358
1433   if (pSR & SR_C)
1434      t = bcd_add( t, 1 );
1435
1436   WM(r,t);
1437
1438   CLR_NZC;
1439   SET_C8(t);
1440   SET_N8(t);
1441   SET_Z8(t);
1442
14431359   m_icount -= 11;
14441360}
14451361
r29472r29473
16421558
16431559void tms7000_device::dsb_b2a()
16441560{
1645   UINT16  t;
1561   WRA(bcd_sub(RDA, RDB, pSR & SR_C));
16461562
1647   t = bcd_sub( RDA, RDB );
1648
1649   if( !(pSR & SR_C) )
1650      t = bcd_sub( t, 1 );
1651
1652   WRA(t);
1653
1654   CLR_NZC;
1655   SET_C8(~t);
1656   SET_N8(t);
1657   SET_Z8(t);
1658
16591563   m_icount -= 7;
16601564}
16611565
16621566void tms7000_device::dsb_r2a()
16631567{
1664   UINT8   r;
1665   UINT16  t;
1666
1568   UINT8 r;
16671569   IMMBYTE(r);
16681570
1669   t = bcd_sub( RDA, RM(r) );
1571   WRA(bcd_sub(RDA, RM(r), pSR & SR_C));
16701572
1671   if( !(pSR & SR_C) )
1672      t = bcd_sub( t, 1 );
1673
1674   WRA(t);
1675
1676   CLR_NZC;
1677   SET_C8(~t);
1678   SET_N8(t);
1679   SET_Z8(t);
1680
16811573   m_icount -= 10;
16821574}
16831575
16841576void tms7000_device::dsb_r2b()
16851577{
1686   UINT8   r;
1687   UINT16  t;
1688
1578   UINT8 r;
16891579   IMMBYTE(r);
16901580
1691   t = bcd_sub( RDB, RM(r) );
1581   WRB(bcd_sub(RDB, RM(r), pSR & SR_C));
16921582
1693   if( !(pSR & SR_C) )
1694      t = bcd_sub( t, 1 );
1695
1696   WRB(t);
1697
1698   CLR_NZC;
1699   SET_C8(~t);
1700   SET_N8(t);
1701   SET_Z8(t);
1702
17031583   m_icount -= 10;
17041584}
17051585
17061586void tms7000_device::dsb_r2r()
17071587{
1708   UINT8   r,s;
1709   UINT16  t;
1710
1588   UINT8 s, r;
17111589   IMMBYTE(s);
17121590   IMMBYTE(r);
17131591
1714   t = bcd_sub( RM(s), RM(r) );
1592   WM(r, bcd_sub(RM(s), RM(r), pSR & SR_C));
17151593
1716   if( !(pSR & SR_C) )
1717      t = bcd_sub( t, 1 );
1718
1719   WM(r,t);
1720
1721   CLR_NZC;
1722   SET_C8(~t);
1723   SET_N8(t);
1724   SET_Z8(t);
1725
17261594   m_icount -= 12;
17271595}
17281596
17291597void tms7000_device::dsb_i2a()
17301598{
1731   UINT8   i;
1732   UINT16  t;
1733
1599   UINT8 i;
17341600   IMMBYTE(i);
17351601
1736   t = bcd_sub( RDA, i );
1602   WRA(bcd_sub(RDA, i, pSR & SR_C));
17371603
1738   if( !(pSR & SR_C) )
1739      t = bcd_sub( t, 1 );
1740
1741   WRA(t);
1742
1743   CLR_NZC;
1744   SET_C8(~t);
1745   SET_N8(t);
1746   SET_Z8(t);
1747
17481604   m_icount -= 9;
17491605}
17501606
17511607void tms7000_device::dsb_i2b()
17521608{
1753   UINT8   i;
1754   UINT16  t;
1755
1609   UINT8 i;
17561610   IMMBYTE(i);
17571611
1758   t = bcd_sub( RDB, i );
1612   WRB(bcd_sub(RDB, i, pSR & SR_C));
17591613
1760   if( !(pSR & SR_C) )
1761      t = bcd_sub( t, 1 );
1762
1763   WRB(t);
1764
1765   CLR_NZC;
1766   SET_C8(~t);
1767   SET_N8(t);
1768   SET_Z8(t);
1769
17701614   m_icount -= 9;
17711615}
17721616
17731617void tms7000_device::dsb_i2r()
17741618{
1775   UINT8   r,i;
1776   UINT16  t;
1777
1619   UINT8 i, r;
17781620   IMMBYTE(i);
17791621   IMMBYTE(r);
17801622
1781   t = bcd_sub( RM(r), i );
1623   WM(r, bcd_sub(RM(r), i, pSR & SR_C));
17821624
1783   if( !(pSR & SR_C) )
1784      t = bcd_sub( t, 1 );
1785
1786   WM(r,t);
1787
1788   CLR_NZC;
1789   SET_C8(~t);
1790   SET_N8(t);
1791   SET_Z8(t);
1792
17931625   m_icount -= 11;
17941626}
17951627

Previous 199869 Revisions Next


© 1997-2024 The MAME Team