Previous 15994 Revisions Next

r4556 Saturday 25th April, 2009 at 16:37:35 UTC by Wilbert Pol
TLCS-900/H cpu core fixes:
- Reimplemented hdma
- Fixed bugs in the EX (mem), R instructions.
[src/emu/cpu/tlcs900]900tbl.c tlcs900.c

src/emu/cpu/tlcs900/tlcs900.c
r4555r4556
352352#include "900tbl.c"
353353
354354
355INLINE void tlcs900_process_hdma( tlcs900_state *cpustate, int channel, int vector )
355#define NUM_MASKABLE_IRQS   22
356static const struct {
357   UINT8 reg;
358   UINT8 iff;
359   UINT8 vector;
360} irq_vector_map[NUM_MASKABLE_IRQS] =
356361{
357   if ( vector == ( cpustate->reg[0x7c + channel] & 0x1f ) )
362   { INTETC32, 0x80, 0x80 },   /* INTTC3 */
363   { INTETC32, 0x08, 0x7c },   /* INTTC2 */
364   { INTETC10, 0x80, 0x78 },   /* INTTC1 */
365   { INTETC10, 0x08, 0x74 },   /* INTTC0 */
366   { INTE0AD, 0x80, 0x70 },   /* INTAD */
367   { INTES1, 0x80, 0x6c },      /* INTTX1 */
368   { INTES1, 0x08, 0x68 },      /* INTRX1 */
369   { INTES0, 0x80, 0x64 },      /* INTTX0 */
370   { INTES0, 0x08, 0x60 },      /* INTRX0 */
371   { INTET76, 0x80, 0x5c },   /* INTTR7 */
372   { INTET76, 0x08, 0x58 },   /* INTTR6 */
373   { INTET54, 0x80, 0x54 },   /* INTTR5 */
374   { INTET54, 0x08, 0x50 },   /* INTTR4 */
375   { INTET32, 0x80, 0x4c },   /* INTT3 */
376   { INTET32, 0x08, 0x48 },   /* INTT2 */
377   { INTET10, 0x80, 0x44 },   /* INTT1 */
378   { INTET10, 0x08, 0x40 },   /* INTT0 */
379                        /* 0x3c - reserved */
380   { INTE67, 0x80, 0x38 },      /* INT7 */
381   { INTE67, 0x08, 0x34 },      /* INT6 */
382   { INTE45, 0x80, 0x30 },      /* INT5 */
383   { INTE45, 0x08, 0x2c },      /* INT4 */
384   { INTE0AD, 0x08, 0x28 }      /* INT0 */
385};
386
387
388INLINE int tlcs900_process_hdma( tlcs900_state *cpustate, int channel )
389{
390   UINT8 vector = ( cpustate->reg[0x7c + channel] & 0x1f ) << 2;
391
392   /* Check if any HDMA actions should be performed */
393   if ( vector >= 0x28 && vector != 0x3C && vector < 0x74 )
358394   {
359      switch( cpustate->dmam[channel].b.l & 0x1f )
360      {
361      case 0x00:
362         WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) );
363         cpustate->dmad[channel].d += 1;
364         cpustate->cycles += 8;
365         break;
366      case 0x01:
367         WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
368         cpustate->dmad[channel].d += 2;
369         cpustate->cycles += 8;
370         break;
371      case 0x02:
372         WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) );
373         cpustate->dmad[channel].d += 4;
374         cpustate->cycles += 12;
375         break;
376      case 0x04:
377         WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) );
378         cpustate->dmad[channel].d -= 1;
379         cpustate->cycles += 8;
380         break;
381      case 0x05:
382         WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
383         cpustate->dmad[channel].d -= 2;
384         cpustate->cycles += 8;
385         break;
386      case 0x06:
387         WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) );
388         cpustate->dmad[channel].d -= 4;
389         cpustate->cycles += 12;
390         break;
391      case 0x08:
392         WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) );
393         cpustate->dmas[channel].d += 1;
394         cpustate->cycles += 8;
395         break;
396      case 0x09:
397         WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
398         cpustate->dmas[channel].d += 2;
399         cpustate->cycles += 8;
400         break;
401      case 0x0a:
402         WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) );
403         cpustate->dmas[channel].d += 4;
404         cpustate->cycles += 12;
405         break;
406      case 0x0c:
407         WRMEM( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
408         cpustate->dmas[channel].d -= 1;
409         cpustate->cycles += 8;
410         break;
411      case 0x0d:
412         WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
413         cpustate->dmas[channel].d -= 2;
414         cpustate->cycles += 8;
415         break;
416      case 0x0e:
417         WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) );
418         cpustate->dmas[channel].d -= 4;
419         cpustate->cycles += 12;
420         break;
421      case 0x10:
422         WRMEM( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
423         cpustate->cycles += 8;
424         break;
425      case 0x11:
426         WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
427         cpustate->cycles += 8;
428         break;
429      case 0x12:
430         WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) );
431         cpustate->cycles += 12;
432         break;
433      case 0x14:
434         cpustate->dmas[channel].d += 1;
435         cpustate->cycles += 5;
436         break;
437      }
395      int irq = 0;
438396
439      cpustate->dmac[channel].w.l -= 1;
397      while( irq < NUM_MASKABLE_IRQS && irq_vector_map[irq].vector != vector )
398         irq++;
440399
441      if ( cpustate->dmac[channel].w.l == 0 )
400      /* Check if our interrupt flip-flop is set */
401      if ( irq < NUM_MASKABLE_IRQS && cpustate->reg[irq_vector_map[irq].reg] & irq_vector_map[irq].iff )
442402      {
443         cpustate->reg[0x7c + channel] = 0;
444         switch( channel )
403         switch( cpustate->dmam[channel].b.l & 0x1f )
445404         {
446         case 0:
447            cpustate->reg[INTETC10] |= 0x08;
405         case 0x00:
406            WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) );
407            cpustate->dmad[channel].d += 1;
408            cpustate->cycles += 8;
448409            break;
449         case 1:
450            cpustate->reg[INTETC10] |= 0x80;
410         case 0x01:
411            WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
412            cpustate->dmad[channel].d += 2;
413            cpustate->cycles += 8;
451414            break;
452         case 2:
453            cpustate->reg[INTETC32] |= 0x08;
415         case 0x02:
416            WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) );
417            cpustate->dmad[channel].d += 4;
418            cpustate->cycles += 12;
454419            break;
455         case 3:
456            cpustate->reg[INTETC32] |= 0x80;
420         case 0x04:
421            WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) );
422            cpustate->dmad[channel].d -= 1;
423            cpustate->cycles += 8;
457424            break;
425         case 0x05:
426            WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
427            cpustate->dmad[channel].d -= 2;
428            cpustate->cycles += 8;
429            break;
430         case 0x06:
431            WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) );
432            cpustate->dmad[channel].d -= 4;
433            cpustate->cycles += 12;
434            break;
435         case 0x08:
436            WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) );
437            cpustate->dmas[channel].d += 1;
438            cpustate->cycles += 8;
439            break;
440         case 0x09:
441            WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
442            cpustate->dmas[channel].d += 2;
443            cpustate->cycles += 8;
444            break;
445         case 0x0a:
446            WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) );
447            cpustate->dmas[channel].d += 4;
448            cpustate->cycles += 12;
449            break;
450         case 0x0c:
451            WRMEM( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
452            cpustate->dmas[channel].d -= 1;
453            cpustate->cycles += 8;
454            break;
455         case 0x0d:
456            WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
457            cpustate->dmas[channel].d -= 2;
458            cpustate->cycles += 8;
459            break;
460         case 0x0e:
461            WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) );
462            cpustate->dmas[channel].d -= 4;
463            cpustate->cycles += 12;
464            break;
465         case 0x10:
466            WRMEM( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
467            cpustate->cycles += 8;
468            break;
469         case 0x11:
470            WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) );
471            cpustate->cycles += 8;
472            break;
473         case 0x12:
474            WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) );
475            cpustate->cycles += 12;
476            break;
477         case 0x14:
478            cpustate->dmas[channel].d += 1;
479            cpustate->cycles += 5;
480            break;
458481         }
482
483         cpustate->dmac[channel].w.l -= 1;
484
485         if ( cpustate->dmac[channel].w.l == 0 )
486         {
487            cpustate->reg[0x7c + channel] = 0;
488            switch( channel )
489            {
490            case 0:
491               cpustate->reg[INTETC10] |= 0x08;
492               break;
493            case 1:
494               cpustate->reg[INTETC10] |= 0x80;
495               break;
496            case 2:
497               cpustate->reg[INTETC32] |= 0x08;
498               break;
499            case 3:
500               cpustate->reg[INTETC32] |= 0x80;
501               break;
502            }
503         }
504
505         /* Clear the interrupt flip-flop */
506         cpustate->reg[irq_vector_map[irq].reg] &= ~irq_vector_map[irq].iff;
507
508         return 1;
459509      }
460510   }
511   return 0;
461512}
462513
463514
515INLINE void tlcs900_check_hdma( tlcs900_state *cpustate )
516{
517   /* HDMA can only be performed if interrupts are allowed */
518   if ( ( cpustate->sr.b.h & 0x70 ) != 0x70 )
519   {
520      if ( ! tlcs900_process_hdma( cpustate, 0 ) )
521      {
522         if ( ! tlcs900_process_hdma( cpustate, 1 ) )
523         {
524            if ( ! tlcs900_process_hdma( cpustate, 2 ) )
525            {
526               tlcs900_process_hdma( cpustate, 3 );
527            }
528         }
529      }
530   }
531}
532
533
464534INLINE void tlcs900_check_irqs( tlcs900_state *cpustate )
465535{
466#define NUM_MASKABLE_IRQS   22
467   static const struct {
468      UINT8 reg;
469      UINT8 iff;
470      UINT8 vector;
471   } irq_vector_map[NUM_MASKABLE_IRQS] =
472   {
473      { INTETC32, 0x80, 0x80 },   /* INTTC3 */
474      { INTETC32, 0x08, 0x7c },   /* INTTC2 */
475      { INTETC10, 0x80, 0x78 },   /* INTTC1 */
476      { INTETC10, 0x08, 0x74 },   /* INTTC0 */
477      { INTE0AD, 0x80, 0x70 },   /* INTAD */
478      { INTES1, 0x80, 0x6c },      /* INTTX1 */
479      { INTES1, 0x08, 0x68 },      /* INTRX1 */
480      { INTES0, 0x80, 0x64 },      /* INTTX0 */
481      { INTES0, 0x08, 0x60 },      /* INTRX0 */
482      { INTET76, 0x80, 0x5c },   /* INTTR7 */
483      { INTET76, 0x08, 0x58 },   /* INTTR6 */
484      { INTET54, 0x80, 0x54 },   /* INTTR5 */
485      { INTET54, 0x08, 0x50 },   /* INTTR4 */
486      { INTET32, 0x80, 0x4c },   /* INTT3 */
487      { INTET32, 0x08, 0x48 },   /* INTT2 */
488      { INTET10, 0x80, 0x44 },   /* INTT1 */
489      { INTET10, 0x08, 0x40 },   /* INTT0 */
490                           /* 0x3c - reserved */
491      { INTE67, 0x80, 0x38 },      /* INT7 */
492      { INTE67, 0x08, 0x34 },      /* INT6 */
493      { INTE45, 0x80, 0x30 },      /* INT5 */
494      { INTE45, 0x08, 0x2c },      /* INT4 */
495      { INTE0AD, 0x08, 0x28 }      /* INT0 */
496   };
497536   int irq_vectors[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 };
537   int level = 0;
498538   int irq = -1;
499539   int i;
500540
r4555r4556
538578      if ( irq_vectors[i] >= 0 )
539579      {
540580         irq = irq_vectors[i];
581         level = i + 1;
541582      }
542583   }
543584
r4555r4556
550591      WRMEML( cpustate->xssp.d, cpustate->pc.d );
551592      cpustate->xssp.d -= 2;
552593      WRMEMW( cpustate->xssp.d, cpustate->sr.w.l );
594
595      /* Mask off any lower priority interrupts  */
596      cpustate->sr.b.h = ( cpustate->sr.b.h & 0x8f ) | ( level << 4 );
597
553598      cpustate->pc.d = RDMEML( 0xffff00 + vector );
554599      cpustate->cycles += 18;
555600
r4555r4556
557602
558603      /* Clear taken IRQ */
559604      cpustate->reg[ irq_vector_map[irq].reg ] &= ~ irq_vector_map[irq].iff;
560
561      /* Check if any HDMA actions should be performed */
562      if ( vector >= 0x28 && vector != 0x3C && vector < 0x74 )
563      {
564         tlcs900_process_hdma( cpustate, 0, vector >> 2 );
565         tlcs900_process_hdma( cpustate, 1, vector >> 2 );
566         tlcs900_process_hdma( cpustate, 2, vector >> 2 );
567         tlcs900_process_hdma( cpustate, 3, vector >> 2 );
568      }
569605   }
570606}
571607
r4555r4556
678714
679715      for( ; cpustate->timer_change[0] > 0; cpustate->timer_change[0]-- )
680716      {
717//printf("timer0 = %02x, TREG0 = %02x\n", cpustate->timer[0], cpustate->reg[TREG0] );
681718         cpustate->timer[0] += 1;
682719         if ( cpustate->timer[0] == cpustate->reg[TREG0] )
683720         {
r4555r4556
856893
857894      tlcs900_handle_timers( cpustate );
858895
896      tlcs900_check_hdma( cpustate );
897
859898      cpustate->icount -= cpustate->cycles;
860899   } while ( cpustate->icount > 0 );
861900
src/emu/cpu/tlcs900/900tbl.c
r4555r4556
19001900
19011901static void _DB(tlcs900_state *cpustate)
19021902{
1903   logerror("%08x: invalid or illegal instruction\n", cpustate->pc.d );
19031904}
19041905
19051906
r4555r4556
20552056{
20562057   UINT8   i = RDMEM( cpustate->ea1.d );
20572058
2058   WRMEM( cpustate->ea1.d, *cpustate->p1_reg8 );
2059   *cpustate->p1_reg8 = i;
2059   WRMEM( cpustate->ea1.d, *cpustate->p2_reg8 );
2060   *cpustate->p2_reg8 = i;
20602061}
20612062
20622063
r4555r4556
20732074{
20742075   UINT16   i = RDMEMW( cpustate->ea1.d );
20752076
2076   WRMEMW( cpustate->ea1.d, *cpustate->p1_reg16 );
2077   *cpustate->p1_reg16 = i;
2077   WRMEMW( cpustate->ea1.d, *cpustate->p2_reg16 );
2078   *cpustate->p2_reg16 = i;
20782079}
20792080
20802081
r4555r4556
28852886static void _POPWSR(tlcs900_state *cpustate)
28862887{
28872888   _POPWR( cpustate );
2888   cpustate->regbank = cpustate->sr.b.h & 0x07;
2889   cpustate->regbank = cpustate->sr.b.h & 0x03;
28892890   cpustate->check_irqs = 1;
28902891}
28912892

Previous 15994 Revisions Next


© 1998-2018 The MESS Team