Previous 199869 Revisions Next

r25468 Monday 30th September, 2013 at 23:14:38 UTC by Michael Zapf
CPUs now utilizing split addressing (setaddress ... read/write)
[src/emu/cpu/tms9900]tms9900.c tms9900.h tms9980a.c tms9995.c tms9995.h

trunk/src/emu/cpu/tms9900/tms9980a.c
r25467r25468
147147void tms9980a_device::mem_read()
148148{
149149   UINT8 value;
150   if (m_lowbyte)
150   switch (m_mem_phase)
151151   {
152   case 1:
153      m_pass = 4;         // make the CPU visit this method more than once
154      m_dbin_line(ASSERT_LINE);
155      m_prgspace->set_address(m_address & m_prgaddr_mask & ~1);
156      if (VERBOSE>7) LOG("tms9980a: set address bus %04x\n", m_address & m_prgaddr_mask & ~1);
157      m_check_ready = true;
158      break;
159   case 2:
160      // Sample the value on the data bus (high byte)
161      value = m_prgspace->read_byte(m_address & m_prgaddr_mask & ~1);
162      if (VERBOSE>7) LOG("tms9980a: memory read high byte %04x -> %02x\n", m_address & m_prgaddr_mask & ~1, value);
163      m_current_value = (value << 8) & 0xff00;
164      break;
165   case 3:
166      m_prgspace->set_address((m_address & m_prgaddr_mask) | 1);
167      if (VERBOSE>7) LOG("tms9980a: set address bus %04x\n", (m_address & m_prgaddr_mask) | 1);
168      break;
169   case 4:
170      // Sample the value on the data bus (low byte)
152171      value = m_prgspace->read_byte((m_address & m_prgaddr_mask) | 1);
153172      m_current_value = m_current_value | (value & 0x00ff);
154      if (VERBOSE>7) LOG("tms9980a: memory read low byte %04x -> complete word %04x\n", (m_address & m_prgaddr_mask) | 1, m_current_value);
155      m_lowbyte = false;
173      if (VERBOSE>7) LOG("tms9980a: memory read low byte %04x -> %02x -> complete word %04x\n", (m_address & m_prgaddr_mask) | 1, value, m_current_value);
174      break;
156175   }
157   else
158   {
159      value = m_prgspace->read_byte(m_address & 0x3ffe);
160      if (VERBOSE>7) LOG("tms9980a: memory read high byte %04x -> %02x\n", m_address & m_prgaddr_mask, value);
161      m_current_value = (value << 8) & 0xff00;
162      m_lowbyte = true;
163      m_pass = 2;         // make the CPU visit this method once more
164   }
165   pulse_clock(2);
166   m_check_ready = true;
176   pulse_clock(1);
177   m_mem_phase = (m_mem_phase % 4) +1;
167178}
168179
180
169181void tms9980a_device::mem_write()
170182{
171   if (m_lowbyte)
183   switch (m_mem_phase)
172184   {
173      m_prgspace->write_byte((m_address & 0x3ffe) | 1, m_current_value & 0xff);
174      if (VERBOSE>7) LOG("tms9980a: memory write low byte %04x <- %02x\n", (m_address & m_prgaddr_mask) | 1, m_current_value & 0xff);
175      m_lowbyte = false;
185   case 1:
186      m_pass = 4;         // make the CPU visit this method once more
187      m_dbin_line(CLEAR_LINE);
188      m_prgspace->set_address(m_address & m_prgaddr_mask & ~1);
189      if (VERBOSE>7) LOG("tms9980a: set address bus %04x\n", m_address & m_prgaddr_mask & ~1);
190      m_prgspace->write_byte(m_address & 0x3ffe & ~1, (m_current_value >> 8)&0xff);
191      if (VERBOSE>7) LOG("tms9980a: memory write high byte %04x <- %02x\n", m_address & m_prgaddr_mask & ~1, (m_current_value >> 8)&0xff);
192      m_check_ready = true;
193      break;
194   case 2:
195      // no action here, just wait for READY
196      break;
197   case 3:
198      m_prgspace->set_address((m_address & m_prgaddr_mask) | 1);
199      if (VERBOSE>7) LOG("tms9980a: set address bus %04x\n", (m_address & m_prgaddr_mask) | 1);
200      m_prgspace->write_byte((m_address & m_prgaddr_mask) | 1, m_current_value & 0xff);
201      if (VERBOSE>7) LOG("tms9980a: memory write low byte %04x <- %02x\n", (m_address & m_prgaddr_mask) | 1,  m_current_value & 0xff);
202      break;
203   case 4:
204      // no action here, just wait for READY
205      break;
176206   }
177   else
178   {
179      m_prgspace->write_byte(m_address & 0x3ffe, (m_current_value >> 8)&0xff);
180      if (VERBOSE>7) LOG("tms9980a: memory write high byte %04x <- %02x\n", m_address & m_prgaddr_mask, (m_current_value >> 8)&0xff);
181      m_lowbyte = true;
182      m_pass = 2;         // make the CPU visit this method once more
183   }
184   pulse_clock(2);
185   m_check_ready = true;
207   pulse_clock(1);
208   m_mem_phase = (m_mem_phase % 4) +1;
186209}
187210
188211void tms9980a_device::acquire_instruction()
189212{
190   if (!m_lowbyte)
213   if (m_mem_phase == 1)
191214   {
192215      m_iaq_line(ASSERT_LINE);
193216      m_address = PC;
194217      m_first_cycle = m_icount;
195      mem_read();
196218   }
197   else
219   mem_read();
220
221   if (m_mem_phase == 1)  // changed by mem_read and wrapped
198222   {
199      mem_read();
200223      decode(m_current_value);
201224      if (VERBOSE>3) LOG("tms9980a: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC);
202225      debugger_instruction_hook(this, PC);
r25467r25468
205228   // IAQ will be cleared in the main loop
206229}
207230
231
232
208233/**************************************************************************/
209234UINT32 tms9980a_device::execute_min_cycles() const
210235{
trunk/src/emu/cpu/tms9900/tms9995.c
r25467r25468
158158   m_external_operation.resolve(conf->external_callback, *this);
159159   m_iaq_line.resolve(conf->iaq_line, *this);
160160   m_clock_out_line.resolve(conf->clock_out, *this);
161   m_wait_line.resolve(conf->wait_line, *this);
162161   m_holda_line.resolve(conf->holda_line, *this);
162   m_dbin_line.resolve(conf->dbin_line, *this);
163163
164164   m_mp9537 = (conf->mode==NO_INTERNAL_RAM);
165165   m_check_overflow = (conf->overflow==OVERFLOW_INT);
r25467r25468
10861086   do
10871087   {
10881088      // Normal operation
1089      if (m_check_ready && m_ready_state == false)
1089      if (m_check_ready && m_ready == false)
10901090      {
10911091         // We are in a wait state
1092         set_wait_state(true);
10931092         if (VERBOSE>2) LOG("tms9995: wait state\n");
10941093         // The clock output should be used to change the state of an outer
10951094         // device which operates the READY line
r25467r25468
11051104         }
11061105         else
11071106         {
1108            set_wait_state(false);
11091107            set_hold_state(false);
11101108
11111109            m_check_ready = false;
r25467r25468
11891187   for (int i=0; i < count; i++)
11901188   {
11911189      m_clock_out_line(ASSERT_LINE);
1190      m_ready = m_ready_bufd && !m_request_auto_wait_state;                // get the latched READY state
11921191      m_clock_out_line(CLEAR_LINE);
11931192      m_icount--;                         // This is the only location where we count down the cycles.
1194      if (VERBOSE>7) LOG("tms9995: pulse_clock\n");
1193      if (VERBOSE>7)
1194      {
1195         if (m_check_ready) LOG("tms9995: pulse_clock, READY=%d, auto_wait=%d\n", m_ready_bufd? 1:0, m_auto_wait? 1:0);
1196         else LOG("tms9995: pulse_clock\n");
1197      }
1198      m_request_auto_wait_state = false;
11951199      if (m_flag[0] == false && m_flag[1] == true) trigger_decrementer();
11961200   }
11971201}
r25467r25468
12101214}
12111215
12121216/*
1213    Signal READY to the CPU. When cleared, the CPU enters wait states.
1217    Signal READY to the CPU. When cleared, the CPU enters wait states. This
1218    becomes effective on a clock pulse.
12141219*/
12151220void tms9995_device::set_ready(int state)
12161221{
1217   if (VERBOSE>5) LOG("tms9995: set READY = %d\n", state);
1218   m_ready_state = (state==ASSERT_LINE);
1222   m_ready_bufd = (state==ASSERT_LINE);
1223   if (VERBOSE>7) LOG("tms9995: set READY = %d\n", m_ready_bufd? 1 : 0);
12191224}
12201225
12211226/*
r25467r25468
12271232   // And don't forget that prefetch is a 2-pass operation, so this method
12281233   // will be called a second time. Only when the lowbyte has been fetched,
12291234   // continue with the next step
1230   if (!m_lowbyte) command_completed();
1235   if (m_mem_phase==1) command_completed();
12311236}
12321237
12331238/*
1234    Enter or leave the wait state. We only operate the WAIT line when there is a change.
1235*/
1236inline void tms9995_device::set_wait_state(bool state)
1237{
1238   if (m_wait_state != state) m_wait_line(state? ASSERT_LINE : CLEAR_LINE);
1239   m_wait_state = state;
1240}
1241
1242/*
12431239    Enter or leave the hold state. We only operate the HOLDA line when there is a change.
12441240*/
12451241inline void tms9995_device::set_hold_state(bool state)
r25467r25468
13071303   bool check_int = (m_instruction->command != XOP && m_instruction->command != BLWP);
13081304   int intmask = ST & 0x000f;
13091305
1310   if (m_lowbyte)
1306   if (m_mem_phase == 1)
13111307   {
1312      prefetch_and_decode();
1313      return;
1314   }
1315
1316   // Check interrupt lines
1317   if (m_nmi_active)
1318   {
1319      if (VERBOSE>7) LOG("tms9995: Checking interrupts ... NMI active\n");
1320      m_int_pending |= PENDING_NMI;
1321      m_idle_state = false;
1322      PC = (PC + 2) & 0xfffe;     // we have not prefetched the next instruction
1323   }
1324   else
1325   {
1326      m_int_pending = 0;
1327
1328      if (m_int1_active && intmask >= 1 && check_int) m_int_pending |= PENDING_LEVEL1;
1329      if (m_int_overflow && intmask >= 2 && check_int) m_int_pending |= PENDING_OVERFLOW;
1330      if (m_int_decrementer && intmask >= 3 && check_int) m_int_pending |= PENDING_DECR;
1331      if (m_int4_active && intmask >= 4 && check_int) m_int_pending |= PENDING_LEVEL4;
1332
1333      if (m_int_pending!=0)
1308      // Check interrupt lines
1309      if (m_nmi_active)
13341310      {
1335         if (m_idle_state)
1336         {
1337            m_idle_state = false;
1338            if (VERBOSE>7) LOG("tms9995: Interrupt occured, terminate IDLE state\n");
1339         }
1340         PC = PC + 2;        // PC must be advanced (see flow chart), but no prefetch
1341         if (VERBOSE>7) LOG("tms9995: Interrupts pending; no prefetch; advance PC to %04x\n", PC);
1311         if (VERBOSE>7) LOG("tms9995: Checking interrupts ... NMI active\n");
1312         m_int_pending |= PENDING_NMI;
1313         m_idle_state = false;
1314         PC = (PC + 2) & 0xfffe;     // we have not prefetched the next instruction
1315         return;
13421316      }
13431317      else
13441318      {
1345         if (VERBOSE>7) LOG("tms9995: Checking interrupts ... none pending\n");
1346         // No pending interrupts
1347         if (check_idle && m_idle_state)
1319         m_int_pending = 0;
1320
1321         if (m_int1_active && intmask >= 1 && check_int) m_int_pending |= PENDING_LEVEL1;
1322         if (m_int_overflow && intmask >= 2 && check_int) m_int_pending |= PENDING_OVERFLOW;
1323         if (m_int_decrementer && intmask >= 3 && check_int) m_int_pending |= PENDING_DECR;
1324         if (m_int4_active && intmask >= 4 && check_int) m_int_pending |= PENDING_LEVEL4;
1325
1326         if (m_int_pending!=0)
13481327         {
1349            if (VERBOSE>7) LOG("tms9995: IDLE state\n");
1350            // We are IDLE, stay in the loop and do not advance the PC
1351            m_pass = 2;
1352            pulse_clock(1);
1328            if (m_idle_state)
1329            {
1330               m_idle_state = false;
1331               if (VERBOSE>7) LOG("tms9995: Interrupt occured, terminate IDLE state\n");
1332            }
1333            PC = PC + 2;        // PC must be advanced (see flow chart), but no prefetch
1334            if (VERBOSE>7) LOG("tms9995: Interrupts pending; no prefetch; advance PC to %04x\n", PC);
1335            return;
13531336         }
13541337         else
13551338         {
1356            prefetch_and_decode();
1339            if (VERBOSE>7) LOG("tms9995: Checking interrupts ... none pending\n");
1340            // No pending interrupts
1341            if (check_idle && m_idle_state)
1342            {
1343               if (VERBOSE>7) LOG("tms9995: IDLE state\n");
1344               // We are IDLE, stay in the loop and do not advance the PC
1345               m_pass = 2;
1346               pulse_clock(1);
1347               return;
1348            }
13571349         }
13581350      }
13591351   }
1352
1353   // We reach this point in phase 1 if there is no interrupt and in all other phases
1354   prefetch_and_decode();
13601355}
13611356
13621357/*
r25467r25468
13671362*/
13681363void tms9995_device::prefetch_and_decode()
13691364{
1370   if (m_lowbyte)
1365   if (m_mem_phase==1)
13711366   {
1372      // Second pass for getting the instruction
1373      if (VERBOSE>6) LOG("tms9995: Prefetch memory access (second pass)\n");
1374      word_read();
1375      decode(m_current_value);            // This is for free; in reality it is in parallel with the next memory operation
1376      m_address = m_address_copy;     // restore m_address
1377      m_current_value = m_value_copy; // restore m_current_value
1378      PC = (PC + 2) & 0xfffe;     // advance PC
1379      m_iaq_line(CLEAR_LINE);
1380      if (VERBOSE>5) LOG("tms9995: ++++ Prefetch done ++++\n");
1381      m_lowbyte = false;
1382   }
1383   else
1384   {
13851367      // Fetch next instruction
13861368      // Save these values; they have been computed during the current instruction execution
13871369      m_address_copy = m_address;
13881370      m_value_copy = m_current_value;
1389
13901371      m_iaq_line(ASSERT_LINE);
1391
13921372      m_address = PC;
1393
13941373      if (VERBOSE>5) LOG("tms9995: **** Prefetching new instruction at %04x ****\n", PC);
1374   }
13951375
1396      m_lowbyte = false;  // for mem_read
1397      word_read();            // this is where the clock pulses occur
1376   word_read();
13981377
1399      if (!m_lowbyte)
1400      {
1401         // Only if we got the word in one pass
1402         decode(m_current_value);    // This is for free; in reality it is in parallel with the next memory operation
1403
1404         m_address = m_address_copy;         // restore m_address
1405         m_current_value = m_value_copy;     // restore m_current_value
1406         PC = (PC + 2) & 0xfffe;     // advance PC
1407
1408         m_iaq_line(CLEAR_LINE);
1409      }
1378   if (m_mem_phase==1)
1379   {
1380      // We're back in phase 1, i.e. the whole prefetch is done
1381      decode(m_current_value);    // This is for free; in reality it is in parallel with the next memory operation
1382      m_address = m_address_copy;     // restore m_address
1383      m_current_value = m_value_copy; // restore m_current_value
1384      PC = (PC + 2) & 0xfffe;     // advance PC
1385      m_iaq_line(CLEAR_LINE);
1386      if (VERBOSE>5) LOG("tms9995: ++++ Prefetch done ++++\n");
14101387   }
14111388}
14121389
r25467r25468
14471424   // Pseudo state at the end of the current instruction cycle sequence
14481425   if (VERBOSE>4)
14491426   {
1450      LOG("tms9995: +++++ Instruction %04x (%s) completed +++++\n", m_instruction->IR, opname[m_instruction->command]);
1427      LOG("tms9995: +++++ Instruction %04x (%s) completed", m_instruction->IR, opname[m_instruction->command]);
14511428      int cycles =  m_first_cycle - m_icount;
14521429      // Avoid nonsense values due to expired and resumed main loop
1453      if (cycles > 0 && cycles < 10000) LOG("tms9995: Consumed %d cycles\n", cycles);
1430      if (cycles > 0 && cycles < 10000) LOG(", consumed %d cycles", cycles);
1431      LOG(" +++++\n");
14541432   }
14551433
14561434   if (m_int_pending != 0)
r25467r25468
14841462
14851463      m_nmi_state = false;
14861464      m_hold_state = false;
1487      m_wait_state = false;
1488      m_lowbyte = false;
1465      m_mem_phase = 1;
14891466      m_check_hold = false;
14901467      m_word_access = false;
14911468      m_int4_active = false;
r25467r25468
15001477
15011478      // The auto-wait state generation is turned on when the READY line is cleared
15021479      // on RESET.
1503      m_auto_wait_state = !m_ready_state;
1504      if (VERBOSE>0) LOG("tms9995: RESET; automatic wait state creation is %s\n", m_auto_wait_state? "enabled":"disabled");
1505      m_ready_state = true;
1480      m_auto_wait = !m_ready_bufd;
1481      if (VERBOSE>0) LOG("tms9995: RESET; automatic wait state creation is %s\n", m_auto_wait? "enabled":"disabled");
1482      // We reset the READY flag, or the CPU will not start
1483      m_ready_bufd = true;
15061484   }
15071485   else
15081486   {
r25467r25468
15741552   m_instruction->byteop = false;
15751553   m_instruction->command = INTR;
15761554   m_pass = m_reset? 1 : 2;
1555   m_from_reset = m_reset;
15771556
15781557   if (m_reset)
15791558   {
r25467r25468
16041583void tms9995_device::mem_read()
16051584{
16061585   // First determine whether the memory is inside the CPU
1607   // On-chip memory is F000 ... F0F9, F0FC-FFF9 = off-chip, FFFA/B = Decrementer
1586   // On-chip memory is F000 ... F0F9, F0FA-FFF9 = off-chip, FFFA/B = Decrementer
16081587   // FFFC-FFFF = NMI vector (on-chip)
16091588   // There is a variant of the TMS9995 with no on-chip RAM which was used
16101589   // for the TI-99/8 (9537).
r25467r25468
16411620   }
16421621   else
16431622   {
1644      // This is a off-chip access
1623      // This is an off-chip access
16451624      m_check_ready = true;
1646      if (m_lowbyte)
1625      UINT8 value;
1626      UINT16 address = m_address;
1627
1628      switch (m_mem_phase)
16471629      {
1648         // This is always the odd address
1649         // With the OR we can ensure that we do not skip to an even address
1650         // when we try to read a word from an odd address
1651         m_current_value |= m_prgspace->read_byte(m_address | 0x0001);
1652         m_lowbyte = false;
1653         if (VERBOSE>3) LOG("tms9995: read external memory, second pass (address %04x, complete word = %04x)\n", m_address | 1, m_current_value);
1654         m_check_hold = true;
1655      }
1656      else
1657      {
1658         UINT16 address = m_address;
1630      case 1:
1631         // Set address
1632         // If this is a word access, 4 passes, else 2 passes
1633         m_dbin_line(ASSERT_LINE);
16591634         if (m_word_access || !m_instruction->byteop)
16601635         {
1661            // We have to come here a second time; do not advance the MPC
1662            // if the address value is even
1663            m_lowbyte = true;
1664            m_pass = 2;
1636            m_pass = 4;
1637            // For word accesses, we always start at the even address
16651638            address &= 0xfffe;
1666            m_check_hold = false;
16671639         }
1668         m_current_value = m_prgspace->read_byte(address) << 8;
1669         if (VERBOSE>3)
1670         {
1671            if (m_pass==2) LOG("tms9995: read external memory, first pass (address %04x, value %02x)\n", address, (m_current_value>>8)&0xff);
1672            else LOG("tms9995: read external memory (single pass), address %04x, value=%04x)\n", address, m_current_value);
1673         }
1640         else m_pass = 2;
1641
1642         m_check_hold = false;
1643         if (VERBOSE>7) LOG("tms9995: set address bus %04x\n", m_address & ~1);
1644         m_prgspace->set_address(address);
1645         m_request_auto_wait_state = m_auto_wait;
1646         break;
1647      case 2:
1648         // Sample the value on the data bus (high byte)
1649         if (m_word_access || !m_instruction->byteop) address &= 0xfffe;
1650         value = m_prgspace->read_byte(address);
1651         if (VERBOSE>7) LOG("tms9995: memory read byte %04x -> %02x\n", m_address & ~1, value);
1652         m_current_value = (value << 8) & 0xff00;
1653         break;
1654      case 3:
1655         // Set address + 1 (unless byte command)
1656         if (VERBOSE>7) LOG("tms9995: set address bus %04x\n", m_address | 1);
1657         m_prgspace->set_address(m_address | 1);
1658         break;
1659      case 4:
1660         // Read low byte
1661         value = m_prgspace->read_byte(m_address | 1);
1662         m_current_value |= value;
1663         if (VERBOSE>3) LOG("tms9995: memory read byte %04x -> %02x, complete word = %04x\n", m_address | 1, value, m_current_value);
1664         m_check_hold = true;
1665         break;
16741666      }
1675      if (m_auto_wait_state)
1676      {
1677         if (VERBOSE>7) LOG("tms9995: Next pulse is auto wait\n");
1678         pulse_clock(1);
1679      }
1667
1668      m_mem_phase = (m_mem_phase % 4) +1;
1669
1670      // Reset to 1 when we are done
1671      if (m_pass==1) m_mem_phase = 1;
16801672   }
16811673   pulse_clock(1);
16821674}
r25467r25468
17381730      pulse_clock(1);
17391731      return;
17401732   }
1741
17421733   bool onchip = (((m_address & 0xff00)==0xf000 && (m_address < 0xf0fc)) || ((m_address & 0xfffc)==0xfffc)) && !m_mp9537;
17431734
17441735   if (onchip)
r25467r25468
17531744   }
17541745   else
17551746   {
1747      // This is an off-chip access
17561748      m_check_ready = true;
1749      UINT16 address = m_address;
1750      switch (m_mem_phase)
1751      {
1752      case 1:
1753         // Set address
1754         // If this is a word access, 4 passes, else 2 passes
1755         m_dbin_line(CLEAR_LINE);
17571756
1758      if (m_lowbyte)
1759      {
1760         // see above in mem_read
1761         m_prgspace->write_byte(m_address | 0x0001, m_current_value & 0xff);
1762         m_lowbyte = false;
1763         if (VERBOSE>3) LOG("tms9995: write second pass (address %04x, value %02x)\n", m_address | 0x0001, m_current_value & 0xff);
1764         m_check_hold = true;
1765      }
1766      else
1767      {
1768         UINT16 address = m_address;
17691757         if (m_word_access || !m_instruction->byteop)
17701758         {
1771            // We have to come here a second time; do not advance the MPC
1772            // if the address value is even
1773            m_lowbyte = true;
1774            m_pass = 2;
1759            m_pass = 4;
17751760            address &= 0xfffe;
1776            m_check_hold = false;
17771761         }
1778         if (VERBOSE>3)
1779         {
1780            if (m_pass==2) LOG("tms9995: write external memory, first pass (address %04x, value %02x)\n", address, (m_current_value>>8)&0xff);
1781            else LOG("tms9995: write external memory (single pass), address %04x, value=%02x\n", address, (m_current_value>>8)&0xff);
1782         }
1783         m_prgspace->write_byte(address, (m_current_value >> 8)& 0xff);
1762         else m_pass = 2;
1763
1764         m_check_hold = false;
1765         if (VERBOSE>7) LOG("tms9995: set address bus %04x\n", address);
1766         m_prgspace->set_address(address);
1767         if (VERBOSE>7) LOG("tms9995: memory write byte %04x <- %02x\n", address, (m_current_value >> 8)&0xff);
1768         m_prgspace->write_byte(address, (m_current_value >> 8)&0xff);
1769         break;
1770
1771      case 2:
1772         // no action here, just wait for READY
1773         break;
1774      case 3:
1775         // Set address + 1 (unless byte command)
1776         if (VERBOSE>7) LOG("tms9995: set address bus %04x\n", m_address | 1);
1777         m_prgspace->set_address(m_address | 1);
1778         if (VERBOSE>7) LOG("tms9995: memory write byte %04x <- %02x\n", m_address | 1, m_current_value & 0xff);
1779         m_prgspace->write_byte(m_address | 1, m_current_value & 0xff);
1780         break;
1781      case 4:
1782         // no action here, just wait for READY
1783         m_check_hold = true;
1784         break;
17841785      }
17851786
1786      if (m_auto_wait_state)
1787      {
1788         if (VERBOSE>7) LOG("tms9995: Next pulse is auto wait\n");
1789         pulse_clock(1);
1790      }
1787      m_mem_phase = (m_mem_phase % 4) +1;
1788
1789      // Reset to 1 when we are done
1790      if (m_pass==1) m_mem_phase = 1;
17911791   }
17921792   pulse_clock(1);
17931793}
r25467r25468
20722072   }
20732073
20742074   m_get_destination = true;
2075   m_lowbyte = false;
2075   m_mem_phase = 1;
20762076   m_address_add = 0;
20772077   MPC--;      // will be increased in the mail loop
20782078   if (VERBOSE>8) LOG("tms9995: *** Operand address derivation; address=%04x; index=%d\n", m_address, MPC+1);
r25467r25468
20872087   m_address_saved = m_current_value;  // need a special return so we do not lose the value
20882088   m_current_value += m_instruction->byteop? 1 : 2;
20892089   m_address = (WP + (m_regnumber<<1)) & 0xffff;
2090   m_lowbyte = false;
2090   m_mem_phase = 1;
20912091   pulse_clock(1);
20922092}
20932093
r25467r25468
21012101   m_address_add = m_current_value;
21022102   m_address = PC;
21032103   PC = (PC + 2) & 0xfffe;
2104   m_lowbyte = false;
2104   m_mem_phase = 1;
21052105   pulse_clock(1);
21062106}
21072107
r25467r25468
21122112   m_address = PC;
21132113   m_source_value = m_current_value;       // needed for AI, ANDI, ORI
21142114   PC = (PC + 2) & 0xfffe;
2115   m_lowbyte = false;
2115   m_mem_phase = 1;
21162116}
21172117
21182118/**************************************************************************
r25467r25468
32273227
32283228      if (((m_int_pending & PENDING_MID)!=0) && m_nmi_active)
32293229      {
3230         if (VERBOSE>5) LOG("tms9995: interrupt service (5): NMI active after context switch\n");
3230         if (VERBOSE>5) LOG("tms9995: interrupt service (6): NMI active after context switch\n");
32313231         m_int_pending &= ~PENDING_MID;
32323232         m_address = 0xfffc;
32333233         m_intmask = 0;
r25467r25468
32353235      }
32363236      else
32373237      {
3238         if (m_reset)
3238         if (m_from_reset)
32393239         {
3240            if (VERBOSE>5) LOG("tms9995: interrupt service (5): RESET completed\n");
3240            if (VERBOSE>5) LOG("tms9995: interrupt service (6): RESET completed\n");
32413241            // We came from the RESET interrupt
3242            m_reset = false;
3242            m_from_reset = false;
32433243            ST &= 0x01ff;
32443244            m_mid_flag = false;
32453245            // FLAG0 and FLAG1 are also set to zero after RESET ([1], sect. 2.3.1.2.2)
trunk/src/emu/cpu/tms9900/tms9900.c
r25467r25468
177177   m_clock_out_line.resolve(conf->clock_out, *this);
178178   m_wait_line.resolve(conf->wait_line, *this);
179179   m_holda_line.resolve(conf->holda_line, *this);
180   m_dbin_line.resolve(conf->dbin_line, *this);        // we need this for the set_address operation
180181
181182   // set our instruction counter
182183   m_icountptr = &m_icount;
r25467r25468
202203void tms99xx_device::device_stop()
203204{
204205   int k = 0;
205   if (VERBOSE>8) LOG("tms99xx: Deleting lookup tables\n");
206   if (VERBOSE>3) LOG("tms99xx: Deleting lookup tables\n");
206207   while (m_lotables[k]!=NULL) delete[] m_lotables[k++];
207208}
208209
r25467r25468
11221123            m_program[MPC] != MEMORY_READ && m_program[MPC] != MEMORY_WRITE &&
11231124            m_program[MPC] != REG_READ && m_program[MPC] != REG_WRITE)))
11241125         {
1125            if (VERBOSE>5) LOG("tms99xx: hold state\n");
1126            if (VERBOSE>2) LOG("tms99xx: hold state\n");
11261127            if (!m_hold_acknowledged) acknowledge_hold();
11271128            pulse_clock(1);
11281129         }
11291130         else
11301131         {
11311132            // Normal operation
1132            if (m_check_ready && m_ready_state == false)
1133            if (m_check_ready && m_ready == false)
11331134            {
11341135               // We are in a wait state
11351136               set_wait_state(true);
1136               if (VERBOSE>5) LOG("tms99xx: wait state\n");
1137               if (VERBOSE>2) LOG("tms99xx: wait state\n");
11371138               // The clock output should be used to change the state of an outer
11381139               // device which operates the READY line
11391140               pulse_clock(1);
r25467r25468
11571158               {
11581159                  m_pass = 1;
11591160                  MPC++;
1161                  m_mem_phase = 1;
11601162                  m_iaq_line(CLEAR_LINE);
11611163               }
11621164            }
r25467r25468
12141216   m_command = INTR;
12151217   m_idle_state = false;
12161218   m_external_operation(IDLE_OP, 0);
1217   m_lowbyte = false;
12181219
12191220   m_state = 0;
12201221
1222   m_dbin_line(ASSERT_LINE);
1223
12211224   // If reset, we just start with execution, otherwise we put the MPC
12221225   // on the first microinstruction, which also means that the main loop shall
12231226   // leave it where it is. So we pretend we have another pass to do.
r25467r25468
12271230   {
12281231      m_irq_level = RESET_INT;
12291232
1230      m_ready_state = true;
1233      m_ready_bufd = true;
1234      m_ready = true;
12311235      m_load_state = false;
12321236      m_hold_state = false;
12331237      m_hold_acknowledged = false;
12341238      m_wait_state = false;
12351239      IR = 0;
12361240      ST = 0;
1241      m_mem_phase = 1;
12371242
12381243      m_reset = false;
12391244   }
r25467r25468
12511256   for (int i=0; i < count; i++)
12521257   {
12531258      m_clock_out_line(ASSERT_LINE);
1259      m_ready = m_ready_bufd;              // get the latched READY state
12541260      m_clock_out_line(CLEAR_LINE);
12551261      m_icount--;                         // This is the only location where we count down the cycles.
1256      if (VERBOSE>7) LOG("tms99xx: pulse_clock\n");
1262      if (VERBOSE>7)
1263      {
1264         if (m_check_ready) LOG("tms99xx: pulse_clock, READY=%d\n", m_ready? 1:0);
1265         else LOG("tms99xx: pulse_clock\n");
1266      }
12571267   }
12581268}
12591269
r25467r25468
12801290}
12811291
12821292/*
1283    Signal READY to the CPU. When cleared, the CPU enters wait states.
1293    Signal READY to the CPU. When cleared, the CPU enters wait states. This
1294    becomes effective on a clock pulse.
12841295*/
12851296void tms99xx_device::set_ready(int state)
12861297{
1287   m_ready_state = (state==ASSERT_LINE);
1298   m_ready_bufd = (state==ASSERT_LINE);
12881299}
12891300
12901301void tms99xx_device::abort_operation()
r25467r25468
13441355      m_program = decoded->prog;
13451356      MPC = -1;
13461357      m_command = decoded->id;
1347      if (VERBOSE>7) LOG("tms99xx: Command decoded as id %d, %s, base opcode %04x\n", m_command, opname[m_command], decoded->opcode);
1358      if (VERBOSE>8) LOG("tms99xx: Command decoded as id %d, %s, base opcode %04x\n", m_command, opname[m_command], decoded->opcode);
13481359      // Byte operations are either format 1 with the byte flag set
13491360      // or format 4 (CRU multi bit operations) with 1-8 bits to transfer.
13501361      m_byteop = ((decoded->format==1 && ((IR & 0x1000)!=0))
r25467r25468
13601371
13611372void tms99xx_device::acquire_instruction()
13621373{
1363   m_iaq_line(ASSERT_LINE);
1364   m_address = PC;
1365   m_first_cycle = m_icount;
1374   if (m_mem_phase == 1)
1375   {
1376      m_iaq_line(ASSERT_LINE);
1377      m_address = PC;
1378      m_first_cycle = m_icount;
1379   }
1380
13661381   mem_read();
1367   decode(m_current_value);
1368   if (VERBOSE>3) LOG("tms99xx: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC);
1369   debugger_instruction_hook(this, PC);
1370   PC = (PC + 2) & 0xfffe & m_prgaddr_mask;
1371   // IAQ will be cleared in the main loop
1382
1383   if (m_mem_phase == 1)
1384   {
1385      decode(m_current_value);
1386      if (VERBOSE>3) LOG("tms99xx: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC);
1387      debugger_instruction_hook(this, PC);
1388      PC = (PC + 2) & 0xfffe & m_prgaddr_mask;
1389      // IAQ will be cleared in the main loop
1390   }
13721391}
13731392
13741393/*
1375    Memory read:
1376    1) Pulse clock (done above)
1377    2) Set address (we also get the value right here)
1378    3) Pulse clock
1379    4) If READY=L (WAIT=H, GOTO 3) else (WAIT=L, STOP)
1380
1394    Memory read
13811395    Clock cycles: 2 + W, W = number of wait states
13821396*/
13831397void tms99xx_device::mem_read()
13841398{
1385   // The following line will be taken out of this method and
1386   // be executed at an earlier microprogram clock tick
13871399   // After set_address, any device attached to the address bus may pull down
13881400   // READY in order to put the CPU into wait state before the read_word
13891401   // operation will be performed
13901402   // set_address and read_word should pass the same address as argument
1391   m_prgspace->set_address(m_address & m_prgaddr_mask & 0xfffe);
1403   if (m_mem_phase==1)
1404   {
1405      m_dbin_line(ASSERT_LINE);
1406      m_prgspace->set_address(m_address & m_prgaddr_mask & 0xfffe);
1407      m_check_ready = true;
1408      m_mem_phase = 2;
1409      m_pass = 2;
1410      if (VERBOSE>7) LOG("tms99xx: set address bus %04x\n", m_address);
13921411
1393   m_current_value = m_prgspace->read_word(m_address & m_prgaddr_mask & 0xfffe);
1394   pulse_clock(2);
1395   m_check_ready = true;
1396   if (VERBOSE>7) LOG("tms99xx: memory read %04x -> %04x\n", m_address, m_current_value);
1412      pulse_clock(1); // Concludes the first cycle
1413      // If READY has been found to be low, the CPU will now stay in the wait state loop
1414   }
1415   else
1416   {
1417      // Second phase (after READY was raised again)
1418      m_current_value = m_prgspace->read_word(m_address & m_prgaddr_mask & 0xfffe);
1419      pulse_clock(1);
1420      m_dbin_line(CLEAR_LINE);
1421      m_mem_phase = 1;        // reset to phase 1
1422      if (VERBOSE>7) LOG("tms99xx: memory read %04x -> %04x\n", m_address, m_current_value);
1423   }
13971424}
13981425
13991426void tms99xx_device::mem_write()
14001427{
1401   // see mem_read
1402   m_prgspace->set_address(m_address & m_prgaddr_mask & 0xfffe);
1403
1404   m_prgspace->write_word(m_address & m_prgaddr_mask & 0xfffe, m_current_value);
1405   pulse_clock(2);
1406   m_check_ready = true;
1407   if (VERBOSE>7) LOG("tms99xx: memory write %04x <- %04x\n", m_address, m_current_value);
1428   if (m_mem_phase==1)
1429   {
1430      m_dbin_line(CLEAR_LINE);
1431      // When writing, the data bus is asserted immediately after the address bus
1432      if (VERBOSE>7) LOG("tms99xx: set address bus %04x\n", m_address);
1433      m_prgspace->set_address(m_address & m_prgaddr_mask & 0xfffe);
1434      if (VERBOSE>7) LOG("tms99xx: memory write %04x <- %04x\n", m_address, m_current_value);
1435      m_prgspace->write_word(m_address & m_prgaddr_mask & 0xfffe, m_current_value);
1436      m_check_ready = true;
1437      m_mem_phase = 2;
1438      m_pass = 2;
1439      pulse_clock(1);
1440   }
1441   else
1442   {
1443      // Second phase (we arrive here when the wait states are over)
1444      pulse_clock(1);
1445   }
14081446}
14091447
14101448void tms99xx_device::register_read()
14111449{
14121450   // Need to set m_address for F1/F3 (we don't know what the data_derive did)
1413   m_address = WP + (m_regnumber<<1);
1451   if (m_mem_phase==1)
1452   {
1453      m_address = WP + (m_regnumber<<1);
1454   }
1455
14141456   mem_read();
1415   m_check_ready = true;
1416   m_register_contents = m_current_value;
1457
1458   if (m_mem_phase==1)
1459   {
1460      m_register_contents = m_current_value;
1461   }
14171462}
14181463
14191464/*
14201465    Memory write:
1421    1) Pulse clock
1422    2) Set address and write (as in the real system)
1423    3) Pulse clock
1424    4) If READY=L (WAIT=H, GOTO 3) else (WAIT=L, STOP)
14251466
14261467    Clock cycles: 2 + W, W = number of wait states
14271468*/
14281469void tms99xx_device::register_write()
14291470{
1471   // This will be called twice; m_pass is set by the embedded mem_write
14301472   UINT16 addr_save = m_address;
14311473   m_address = (WP + (m_regnumber<<1)) & m_prgaddr_mask & 0xfffe;
14321474   mem_write();
1433   m_check_ready = true;
14341475   m_address = addr_save;
14351476}
14361477
r25467r25468
15301571   // Pseudo state at the end of the current instruction cycle sequence
15311572   if (VERBOSE>4)
15321573   {
1533      LOG("tms99xx: +++++ Instruction %04x (%s) completed +++++\n", IR, opname[m_command]);
1574      LOG("tms99xx: +++++ Instruction %04x (%s) completed", IR, opname[m_command]);
15341575      int cycles =  m_first_cycle - m_icount;
15351576      // Avoid nonsense values due to expired and resumed main loop
1536      if (cycles > 0 && cycles < 10000) LOG("tms99xx: Consumed %d cycles\n", cycles);
1577      if (cycles > 0 && cycles < 10000) LOG(", consumed %d cycles", cycles);
1578      LOG(" +++++\n");
15371579   }
15381580   m_program = NULL;
1539   m_lowbyte = false;
15401581}
15411582
15421583/*
trunk/src/emu/cpu/tms9900/tms9995.h
r25467r25468
6565   devcb_write8        external_callback;
6666   devcb_write_line    iaq_line;
6767   devcb_write_line    clock_out;
68   devcb_write_line    wait_line;
6968   devcb_write_line    holda_line;
69   devcb_write_line    dbin_line;
7070   int                 mode;
7171   int                 overflow;
7272};
r25467r25468
151151   bool    m_idle_state;
152152   bool    m_nmi_state;
153153   bool    m_irq_state;
154   bool    m_ready_state;
155   bool    m_wait_state;
156154   bool    m_hold_state;
157155
156   // READY handling. The READY line is operated before the clock
157   // pulse falls. As the ready line is only set once in this emulation we
158   // keep the level in a buffer (like a latch)
159   bool    m_ready_bufd;   // buffered state
160   bool    m_ready;        // sampled value
161
158162   // Auto-wait state generation
159   bool    m_auto_wait_state;
163   bool    m_request_auto_wait_state;
164   bool    m_auto_wait;
160165
161166   // Cycle counter
162167   int     m_icount;
163168
164   // The next memory access will address the low byte
165   bool    m_lowbyte;
169   // Phase of the memory access
170   int     m_mem_phase;
166171
167172   // Check the READY line?
168173   bool    m_check_ready;
r25467r25468
195200   bool    m_int_overflow;
196201
197202   bool    m_reset;
203   bool    m_from_reset;
198204   bool    m_mid_flag;
199205
200206   // Flag field
r25467r25468
213219   // Issue clock pulses. The TMS9995 uses one (output) clock cycle per machine cycle.
214220   inline void pulse_clock(int count);
215221
216   // Signal the wait state via the external line
217   inline void set_wait_state(bool state);
218
219   // Signal the wait state via the external line
222   // Signal the hold state via the external line
220223   inline void set_hold_state(bool state);
221224
222225   // Only used for the DIV(S) operations. It seems sufficient to let the
r25467r25468
434437   // Clock output.
435438   devcb_resolved_write_line   m_clock_out_line;
436439
437   // Wait output. When asserted (high), the CPU is in a wait state.
438   devcb_resolved_write_line   m_wait_line;
439
440440   // Asserted when the CPU is in a HOLD state
441441   devcb_resolved_write_line   m_holda_line;
442
443   // DBIN line. When asserted (high), the CPU has disabled the data bus output buffers.
444   devcb_resolved_write_line   m_dbin_line;
442445};
443446
444447// device type definition
trunk/src/emu/cpu/tms9900/tms9900.h
r25467r25468
117117   devcb_write_line    clock_out;
118118   devcb_write_line    wait_line;
119119   devcb_write_line    holda_line;
120   devcb_write_line    dbin_line;
120121};
121122
122123#define TMS99xx_CONFIG(name) \
r25467r25468
208209   // Data bus width. Needed for TMS9980.
209210   int     m_databus_width;
210211
211   // Needed for TMS9980
212   bool    m_lowbyte;
213
214212   // Check the READY line?
215213   bool    m_check_ready;
216214
215   // Phase of the memory access
216   int     m_mem_phase;
217
217218   // Max address
218219   const UINT16  m_prgaddr_mask;
219220   const UINT16  m_cruaddr_mask;
r25467r25468
238239   // Get the value of the interrupt level lines
239240   devcb_resolved_read8    m_get_intlevel;
240241
242   // DBIN line. When asserted (high), the CPU has disabled the data bus output buffers.
243   devcb_resolved_write_line   m_dbin_line;
244
241245private:
242246   // Indicates if this is a byte-oriented command
243247   inline bool     byte_operation();
244248
245249   // Processor states
246250   bool    m_idle_state;
247   bool    m_ready_state;
251
252   // READY handling. The READY line is operated before the phi1 clock
253   // pulse rises. As the ready line is only set once in this emulation we
254   // keep the level in a buffer (like a latch)
255   bool    m_ready_bufd;   // buffered state
256   bool    m_ready;        // sampled value
257
248258   bool    m_wait_state;
249259   bool    m_hold_state;
250260

Previous 199869 Revisions Next


© 1997-2024 The MAME Team