Previous 199869 Revisions Next

r33175 Monday 3rd November, 2014 at 19:35:23 UTC by Ryan Holtz
n64: Abort MIPS timeslice when unhalting RSP. Fixes many RSP tests. [MooglyGuy]
[src/mame/machine]n64.c

trunk/src/mame/machine/n64.c
r241686r241687
267267      pif_ram[0x27] = 0x3f;
268268      cic_type=6;
269269   }
270   else
271   {
272      //printf("Unknown BootCode Checksum %08X%08X\n", (UINT32)(boot_checksum>>32),(UINT32)(boot_checksum));
273   }
274270}
275271
276272// Memory Interface (MI)
r241686r241687
312308         break;
313309   }
314310
315   //printf("mi_reg_r %08x = %08x\n", offset * 4, ret); fflush(stdout);
316311   return ret;
317312}
318313
319314WRITE32_MEMBER( n64_periphs::mi_reg_w )
320315{
321   //printf("mi_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); fflush(stdout);
322316   switch (offset)
323317   {
324318      case 0x00/4:        // MI_INIT_MODE_REG
r241686r241687
409403{
410404   if (mi_intr_mask & mi_interrupt)
411405   {
412      //printf("Asserting IRQ, %02x : %02x\n", mi_intr_mask, mi_interrupt); fflush(stdout);
413406      machine().device("maincpu")->execute().set_input_line(INPUT_LINE_IRQ0, ASSERT_LINE);
414407   }
415408   else
416409   {
417      //printf("Deasserting IRQ, %02x : %02x\n", mi_intr_mask, mi_interrupt); fflush(stdout);
418410      machine().device("maincpu")->execute().set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
419411   }
420412}
r241686r241687
466458      case 0x0014/4:
467459         for(i = 0x20; i < (0x20 + data); i++)
468460         {
469            //printf( "%c", is64_buffer[i] );
470461            if(is64_buffer[i] == 0x0a)
471462            {
472               //printf( "%c", 0x0d );
463               printf( "%c", 0x0d );
473464            }
474465            is64_buffer[i] = 0;
475466         }
r241686r241687
511502
512503READ32_MEMBER( n64_periphs::rdram_reg_r )
513504{
514   //printf("rdram_reg_r %08x = %08x\n", offset * 4, rdram_regs[offset]); fflush(stdout);
515505   if(offset > 0x24/4)
516506   {
517507      logerror("rdram_reg_r: %08X, %08X at %08X\n", offset, mem_mask, maincpu->safe_pc());
r241686r241687
522512
523513WRITE32_MEMBER( n64_periphs::rdram_reg_w )
524514{
525   //printf("rdram_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); fflush(stdout);
526515   if(offset > 0x24/4)
527516   {
528517      logerror("rdram_reg_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, maincpu->safe_pc());
r241686r241687
542531      length = (length + 7) & ~7;
543532   }
544533
545   //printf("Length %08x Skip %08x Count %08x\n", length, sp_dma_skip, sp_dma_count); fflush(stdout);
546534   if (sp_mem_addr & 0x3)
547535   {
548536      sp_mem_addr = sp_mem_addr & ~3;
r241686r241687
554542
555543   if ((sp_mem_addr & 0xfff) + (length) > 0x1000)
556544   {
557      //printf("sp_dma: dma out of memory area: %08X, %08X, %08X\n", sp_mem_addr, sp_dram_addr, length);
558      //fatalerror("sp_dma: dma out of memory area: %08X, %08X\n", sp_mem_addr, length);
559545      length = 0x1000 - (sp_mem_addr & 0xfff);
560546   }
561547
r241686r241687
602588
603589WRITE32_MEMBER(n64_periphs::sp_set_status)
604590{
605   //printf("sp_set_status: %08x\n", data);
606591   if (data & 0x1)
607592   {
608593      rspcpu->execute().set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
r241686r241687
638623         break;
639624
640625      case 0x10/4:        // SP_STATUS_REG
641         //machine().scheduler().synchronize();
642         //machine().scheduler().boost_interleave(attotime::from_msec(1), attotime::from_msec(m));
643626         ret = rspcpu->state().state_int(RSP_SR);
644627         break;
645628
r241686r241687
652635         break;
653636
654637      case 0x1c/4:        // SP_SEMAPHORE_REG
655         //machine().scheduler().boost_interleave(attotime::from_usec(1), attotime::from_usec(1));
656638         machine().device("maincpu")->execute().yield();
657639         if( sp_semaphore )
658640         {
r241686r241687
660642         }
661643         else
662644         {
663            //printf("Semaphore is now acquired, returning 0\n");
664645            sp_semaphore = 1;
665646            ret = 0;
666647         }
r241686r241687
718699         break;
719700   }
720701
721   //printf("%08x sp_reg_r %08x = %08x\n", (UINT32)maincpu->state().state_int(MIPS3_PC), offset * 4, ret); fflush(stdout);
722702   return ret;
723703}
724704
725705
726706WRITE32_MEMBER(n64_periphs::sp_reg_w )
727707{
728   //printf("%08x sp_reg_w %08x %08x %08x\n", (UINT32)maincpu->state().state_int(MIPS3_PC), offset * 4, data, mem_mask); fflush(stdout);
729
730708   if ((offset & 0x10000) == 0)
731709   {
732710      switch (offset & 0xffff)
r241686r241687
758736            UINT32 oldstatus = rspcpu->state().state_int(RSP_SR);
759737            UINT32 newstatus = oldstatus;
760738
761            // printf( "RSP_STATUS_REG Write; %08x\n", data );
762739            if (data & 0x00000001)      // clear halt
763740            {
764741               rspcpu->execute().set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
765742               newstatus &= ~RSP_STATUS_HALT;
766               //printf("***SP HALT CLR***\n"); fflush(stdout);
743               machine().scheduler().abort_timeslice();
744               machine().scheduler().boost_interleave(attotime::zero, attotime::from_usec(100));
767745            }
768746            if (data & 0x00000002)      // set halt
769747            {
770748               rspcpu->execute().set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
771749               newstatus |= RSP_STATUS_HALT;
772               //printf("***SP HALT SET***\n"); fflush(stdout);
773750            }
774751            if (data & 0x00000004)
775752            {
776753               newstatus &= ~RSP_STATUS_BROKE;
777               //printf("***SP BROKE CLR***\n"); fflush(stdout);
778754            }
779755            if (data & 0x00000008)      // clear interrupt
780756            {
781               //printf("***SP INT CLR***\n"); fflush(stdout);
782757               clear_rcp_interrupt(SP_INTERRUPT);
783758            }
784759            if (data & 0x00000010)      // set interrupt
785760            {
786               //printf("***SP INT SET***\n"); fflush(stdout);
787761               signal_rcp_interrupt(SP_INTERRUPT);
788762            }
789763            if (data & 0x00000020)
790764            {
791765               newstatus &= ~RSP_STATUS_SSTEP;
792               //printf("***SP SSTEP CLR***\n"); fflush(stdout);
793766            }
794767            if (data & 0x00000040)
795768            {
796769               newstatus |= RSP_STATUS_SSTEP;  // set single step
797               //printf("***SP SSTEP SET***\n"); fflush(stdout);
798770               if(!(oldstatus & (RSP_STATUS_BROKE | RSP_STATUS_HALT)))
799771               {
800772                  rspcpu->state().set_state_int(RSP_STEPCNT, 1 );
r241686r241687
804776            if (data & 0x00000080)
805777            {
806778               newstatus &= ~RSP_STATUS_INTR_BREAK;    // clear interrupt on break
807               //printf("***SP INTRBRK CLR***\n"); fflush(stdout);
808779            }
809780            if (data & 0x00000100)
810781            {
811782               newstatus |= RSP_STATUS_INTR_BREAK;     // set interrupt on break
812               //printf("***SP INTRBRK SET***\n"); fflush(stdout);
813783            }
814784            if (data & 0x00000200)
815785            {
816786               newstatus &= ~RSP_STATUS_SIGNAL0;       // clear signal 0
817               //printf("***SP YIELD CLR***\n"); fflush(stdout);
818787            }
819788            if (data & 0x00000400)
820789            {
821790               newstatus |= RSP_STATUS_SIGNAL0;        // set signal 0
822               //printf("***SP YIELD SET***\n"); fflush(stdout);
823791            }
824792            if (data & 0x00000800)
825793            {
826794               newstatus &= ~RSP_STATUS_SIGNAL1;       // clear signal 1
827               //printf("***SP YIELDED CLR***\n"); fflush(stdout);
828795            }
829796            if (data & 0x00001000)
830797            {
831798               newstatus |= RSP_STATUS_SIGNAL1;        // set signal 1
832               //printf("***SP YIELDED SET***\n"); fflush(stdout);
833799            }
834800            if (data & 0x00002000)
835801            {
836802               newstatus &= ~RSP_STATUS_SIGNAL2 ;      // clear signal 2
837               //printf("***SP TASKDONE CLR***\n"); fflush(stdout);
838803            }
839804            if (data & 0x00004000)
840805            {
841806               newstatus |= RSP_STATUS_SIGNAL2;        // set signal 2
842               //printf("***SP TASKDONE SET***\n"); fflush(stdout);
843807            }
844808            if (data & 0x00008000)
845809            {
846810               newstatus &= ~RSP_STATUS_SIGNAL3;       // clear signal 3
847               //printf("***SP SIG3 CLR***\n"); fflush(stdout);
848811            }
849812            if (data & 0x00010000)
850813            {
851814               newstatus |= RSP_STATUS_SIGNAL3;        // set signal 3
852               //printf("***SP SIG3 SET***\n"); fflush(stdout);
853815            }
854816            if (data & 0x00020000)
855817            {
856818               newstatus &= ~RSP_STATUS_SIGNAL4;       // clear signal 4
857               //printf("***SP SIG4 CLR***\n"); fflush(stdout);
858819            }
859820            if (data & 0x00040000)
860821            {
861822               newstatus |= RSP_STATUS_SIGNAL4;        // set signal 4
862               //printf("***SP SIG4 SET***\n"); fflush(stdout);
863823            }
864824            if (data & 0x00080000)
865825            {
866826               newstatus &= ~RSP_STATUS_SIGNAL5;       // clear signal 5
867               //printf("***SP SIG5 CLR***\n"); fflush(stdout);
868827            }
869828            if (data & 0x00100000)
870829            {
871830               newstatus |= RSP_STATUS_SIGNAL5;        // set signal 5
872               //printf("***SP SIG5 SET***\n"); fflush(stdout);
873831            }
874832            if (data & 0x00200000)
875833            {
876834               newstatus &= ~RSP_STATUS_SIGNAL6;       // clear signal 6
877               //printf("***SP SIG6 CLR***\n"); fflush(stdout);
878835            }
879836            if (data & 0x00400000)
880837            {
881838               newstatus |= RSP_STATUS_SIGNAL6;        // set signal 6
882               //printf("***SP SIG6 SET***\n"); fflush(stdout);
883839            }
884840            if (data & 0x00800000)
885841            {
886842               newstatus &= ~RSP_STATUS_SIGNAL7;       // clear signal 7
887               //printf("***SP SIG7 CLR***\n"); fflush(stdout);
888843            }
889844            if (data & 0x01000000)
890845            {
891846               newstatus |= RSP_STATUS_SIGNAL7;        // set signal 7
892               //printf("***SP SIG7 SET***\n"); fflush(stdout);
893847            }
894848            rspcpu->state().set_state_int(RSP_SR, newstatus);
895849            break;
896850         }
897851
898852         case 0x1c/4:        // SP_SEMAPHORE_REG
899            //machine().scheduler().boost_interleave(attotime::from_usec(1), attotime::from_usec(1));
900            //printf("Semaphore is being released\n");
901853            if(data == 0)
902854            {
903855               sp_semaphore = 0;
r241686r241687
976928         break;
977929   }
978930
979   //printf("%08x dp_reg_r %08x = %08x\n", (UINT32)space.machine().device("rsp")->state().state_int(RSP_PC), offset, ret); fflush(stdout);
980931   return ret;
981932}
982933
r241686r241687
984935{
985936   n64_state *state = space.machine().driver_data<n64_state>();
986937
987   //printf("%08x dp_reg_w %08x %08x %08x\n", (UINT32)space.machine().device("rsp")->state().state_int(RSP_PC), offset, data, mem_mask); fflush(stdout);
988938   switch (offset)
989939   {
990940      case 0x00/4:        // DP_START_REG
r241686r241687
993943         break;
994944
995945      case 0x04/4:        // DP_END_REG
996         //printf("dp_end_reg %08x\n", data);
997946         state->m_rdp->SetEndReg(data);
998947         g_profiler.start(PROFILER_USER1);
999948         state->m_rdp->ProcessList();
r241686r241687
1042991   int y_end = (vi_vstart & 0x000003ff) / 2;
1043992   int width = ((vi_xscale & 0x00000fff) * (x_end - x_start)) / 0x400;
1044993   int height = ((vi_yscale & 0x00000fff) * (y_end - y_start)) / 0x400;
1045   //printf("%04x | %02x | ", vi_xscale >> 16, vi_burst & 0x000000ff);
994
1046995   rectangle visarea = m_screen->visible_area();
1047996   attoseconds_t period = m_screen->frame_period().attoseconds;
1048997
r241686r241687
10701019
10711020   visarea.max_x = width - 1;
10721021   visarea.max_y = height - 1;
1073   //printf("Reconfig %d, %d (%d - %d), %08x, %08x, %08x, %08x, %08x\n", width, height, x_start, x_end, vi_width, vi_xscale, vi_hsync, vi_hstart, vi_burst);
10741022   m_screen->configure(width, 525, visarea, period);
10751023}
10761024
r241686r241687
11401088         break;
11411089   }
11421090
1143   //printf("vi_reg_r %08x = %08x\n", offset * 4, ret);
11441091   return ret;
11451092}
11461093
11471094WRITE32_MEMBER( n64_periphs::vi_reg_w )
11481095{
1149   //printf("vi_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask);
11501096   n64_state *state = machine().driver_data<n64_state>();
11511097
11521098   switch (offset)
r241686r241687
13791325         break;
13801326   }
13811327
1382   //printf("ai_reg_r %08x = %08x\n", offset * 4, ret);
13831328   return ret;
13841329}
13851330
13861331WRITE32_MEMBER( n64_periphs::ai_reg_w )
13871332{
1388   //printf("ai_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask);
13891333   switch (offset)
13901334   {
13911335      case 0x00/4:        // AI_DRAM_ADDR_REG
r241686r241687
14081352      case 0x10/4:        // AI_DACRATE_REG
14091353         ai_dacrate = data & 0x3fff;
14101354         dmadac_set_frequency(&ai_dac[0], 2, (double)DACRATE_NTSC / (double)(ai_dacrate+1));
1411         //printf( "frequency: %f\n", (double)DACRATE_NTSC / (double)(ai_dacrate+1) );
14121355         dmadac_enable(&ai_dac[0], 2, 1);
14131356         break;
14141357
r241686r241687
14551398      cart_addr &= ((machine().root_device().memregion("user2")->bytes() >> 1) - 1);
14561399   }
14571400
1458   //printf("%08x Cart, %08x Dram\n", cart_addr << 1, dram_addr << 1); fflush(stdout);
1459
14601401   if(pi_dma_dir == 1)
14611402   {
14621403      UINT32 dma_length = pi_wr_len + 1;
r241686r241687
15581499         break;
15591500   }
15601501
1561   //printf("pi_reg_r %08x = %08x\n", offset * 4, ret);
15621502   return ret;
15631503}
15641504
15651505WRITE32_MEMBER( n64_periphs::pi_reg_w )
15661506{
1567   //printf("pi_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); fflush(stdout);
15681507   switch (offset)
15691508   {
15701509      case 0x00/4:        // PI_DRAM_ADDR_REG
r241686r241687
15861525         pi_status |= 1;
15871526
15881527         attotime dma_period = attotime::from_hz(93750000) * (int)((float)(pi_rd_len + 1) * 5.08f); // Measured as between 2.53 cycles per byte and 2.55 cycles per byte
1589         //printf("want read dma in %d\n", (pi_rd_len + 1));
15901528         pi_dma_timer->adjust(dma_period);
15911529         //pi_dma_tick();
15921530         break;
r241686r241687
15991537         pi_status |= 1;
16001538
16011539         attotime dma_period = attotime::from_hz(93750000) * (int)((float)(pi_wr_len + 1) * 5.08f); // Measured as between 2.53 cycles per byte and 2.55 cycles per byte
1602         //printf("want write dma in %d\n", (pi_wr_len + 1));
16031540         pi_dma_timer->adjust(dma_period);
16041541
16051542         //pi_dma_tick();
r241686r241687
16581595
16591596READ32_MEMBER( n64_periphs::ri_reg_r )
16601597{
1661   //printf("ri_reg_r %08x = %08x\n", offset * 4, ri_regs[offset]);
16621598   if(offset > 0x1c/4)
16631599   {
16641600      logerror("ri_reg_r: %08X, %08X at %08X\n", offset, mem_mask, maincpu->safe_pc());
r241686r241687
16691605
16701606WRITE32_MEMBER( n64_periphs::ri_reg_w )
16711607{
1672   //printf("ri_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask);
16731608   if(offset > 0x1c/4)
16741609   {
16751610      logerror("ri_reg_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, maincpu->safe_pc());
r241686r241687
17321667      case 0x00:      // Read status
17331668      case 0xff:      // Reset
17341669      {
1735         if(command == 0)
1736         {
1737            //printf("Read status\n");
1738         }
1739         else
1740         {
1741            //printf("Reset\n");
1742         }
17431670         switch (channel)
17441671         {
17451672            case 0:
17461673            case 1:
17471674            {
1748               //printf("Read controller %d status\n", channel + 1);
1675               // Read status
17491676               rdata[0] = 0x05;
17501677               rdata[1] = 0x00;
17511678               rdata[2] = 0x01;
r241686r241687
17541681            case 2:
17551682            case 3:
17561683            {
1757               //printf("Read controller %d status (NC)\n", channel + 1);
1758               // not connected
1684               // Read status (unconnected)
17591685               return 1;
17601686            }
17611687            case 4:
17621688            {
1763               //printf("Read EEPROM status\n");
1689               // Read EEPROM status
17641690               rdata[0] = 0x00;
17651691               rdata[1] = 0x80;
17661692               rdata[2] = 0x00;
r241686r241687
17911717
17921718         switch (channel)
17931719         {
1794            case 0: //p1 inputs
1795            case 1: //p2 inputs
1720            case 0: // P1 Inputs
1721            case 1: // P2 Inputs
17961722            {
1797               //printf("Read p%d inputs\n", channel + 1);
17981723               buttons = machine().root_device().ioport(portnames[(channel*3) + 0])->read();
17991724               x = machine().root_device().ioport(portnames[(channel*3) + 1])->read() - 128;
18001725               y = machine().root_device().ioport(portnames[(channel*3) + 2])->read() - 128;
r241686r241687
18081733            case 2:
18091734            case 3:
18101735            {
1811               //printf("Controller %d not connected\n", channel + 1);
1812               // not connected
1736               // P3/P4 Inputs (not connected)
18131737               return 1;
18141738            }
18151739         }
r241686r241687
18241748         address = (sdata[1] << 8) | (sdata[2]);
18251749         address &= ~0x1f;
18261750
1827         ////printf("Read mempak at %04x\n", address);
1828
18291751         if(address == 0x8000)
18301752         {
18311753            for(int i = 0; i < rlength-1; i++)
r241686r241687
18541776         UINT32 address = (sdata[1] << 8) | (sdata[2]);
18551777         address &= ~0x1f;
18561778
1857         ////printf("Write mempak at %04x\n", address);
1858         if (address >= 0x8000)
1779         if (address < 0x8000)
18591780         {
1860         }
1861         else
1862         {
18631781            for(int i = 3; i < slength; i++)
18641782            {
18651783               m_save_data.mempak[channel & 1][address++] = sdata[i];
r241686r241687
18851803
18861804         UINT16 block_offset = sdata[1] * 8;
18871805
1888         //printf("Read EEPROM at %04x\n", block_offset);
1889
18901806         for(int i=0; i < 8; i++)
18911807         {
18921808            rdata[i] = m_save_data.eeprom[block_offset+i];
r241686r241687
19091825
19101826         UINT16 block_offset = sdata[1] * 8;
19111827
1912         //printf("Write EEPROM at %04x\n", block_offset);
1913
19141828         for(int i = 0; i < 8; i++)
19151829         {
19161830            m_save_data.eeprom[block_offset+i] = sdata[2+i];
r241686r241687
19211835
19221836      case 0x06:      // Read RTC Status
19231837      {
1924         //printf("Read RTC Status\n");
19251838         rdata[0] = 0x00;
19261839         rdata[1] = 0x10;
19271840         rdata[2] = 0x00;
r241686r241687
19331846         switch(sdata[1])
19341847         {
19351848            case 0:
1936               //printf("Read RTC Block Header\n");
19371849               rdata[0] = 0x00;
19381850               rdata[1] = 0x02;
19391851               rdata[8] = 0x00;
r241686r241687
19541866               rdata[6] = convert_to_bcd(systime.local_time.year % 100); // Year
19551867               rdata[7] = convert_to_bcd(systime.local_time.year / 100); // Century
19561868               rdata[8] = 0x00;
1957               //printf("Read RTC Time\n");
19581869               return 0;
19591870         }
19601871         return 1;
r241686r241687
19821893      while(cmd_ptr < 0x3f && !end)
19831894      {
19841895         INT8 bytes_to_send = (INT8)pif_cmd[cmd_ptr++];
1985         //printf("bytes to send: 0x%02x\n", bytes_to_send);
19861896
19871897         if (bytes_to_send == -2)
19881898         {
19891899            end = 1;
1990            //printf("end\n");
19911900         }
19921901         else if (bytes_to_send < 0)
19931902         {
1994            //printf("do nothing\n");
19951903            // do nothing
19961904         }
19971905         else
r241686r241687
20021910               UINT8 send_buffer[0x40];
20031911
20041912               INT8 bytes_to_recv = pif_cmd[cmd_ptr++];
2005               //printf("bytes to receive: 0x%02x\n", bytes_to_recv);
20061913
20071914               if (bytes_to_recv == -2)
20081915               {
r241686r241687
20151922               }
20161923
20171924               int res = pif_channel_handle_command(channel, bytes_to_send, send_buffer, bytes_to_recv, recv_buffer);
2018               //printf("result: %d\n", res);
20191925
20201926               if (res == 0)
20211927               {
2022                  //printf("cmd_ptr (%d) + bytes_to_recv (%d) = %d\n", cmd_ptr, bytes_to_recv, cmd_ptr + bytes_to_recv);
20231928                  if (cmd_ptr + bytes_to_recv > 0x3f)
20241929                  {
20251930                     fatalerror("cmd_ptr overflow\n");
r241686r241687
21102015         ret = si_status;
21112016   }
21122017
2113   //printf("si_reg_r %08x = %08x\n", offset * 4, ret); fflush(stdout);
21142018   return ret;
21152019}
21162020
21172021WRITE32_MEMBER( n64_periphs::si_reg_w )
21182022{
2119   //printf("si_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); fflush(stdout);
21202023   switch (offset)
21212024   {
21222025      case 0x00/4:        // SI_DRAM_ADDR_REG
r241686r241687
23962299      return;
23972300
23982301   device_image_interface *image = dynamic_cast<device_image_interface *>(periphs->m_nvram_image);
2399   //printf("Saving stuff\n");
2302
24002303   UINT8 data[0x30800];
24012304   memcpy(data, n64_sram, 0x20000);
24022305   memcpy(data + 0x20000, periphs->m_save_data.eeprom, 0x800);


Previous 199869 Revisions Next


© 1997-2024 The MAME Team