Ejemplo n.º 1
0
void
PSG_Write (int data)
{
  if (GYM_Dumping)
    Update_GYM_Dump ((unsigned char) 3, (unsigned char) data,
		     (unsigned char) 0);

  if (data & 0x80)
    {
      PSG.Current_Register = (data & 0x70) >> 4;
      PSG.Current_Channel = PSG.Current_Register >> 1;

      data &= 0x0F;

      PSG.Register[PSG.Current_Register] =
	(PSG.Register[PSG.Current_Register] & 0x3F0) | data;

      if (PSG.Current_Register & 1)
	{
	  // Volume

	  PSG_Special_Update ();

	  PSG.Volume[PSG.Current_Channel] = PSG_Volume_Table[data];

	  PSG_DEBUG_2 ("channel %d    volume = %.8X\n", PSG.Current_Channel,
		       PSG.Volume[PSG.Current_Channel]);
	}
      else
	{
	  // Frequency

	  PSG_Special_Update ();

	  if (PSG.Current_Channel != 3)
	    {
	      // Normal channel

	      PSG.CntStep[PSG.Current_Channel] =
		PSG_Step_Table[PSG.Register[PSG.Current_Register]];

	      if ((PSG.Current_Channel == 2) && ((PSG.Register[6] & 3) == 3))
		{
		  PSG.CntStep[3] = PSG.CntStep[2] >> 1;
		}

	      PSG_DEBUG_2 ("channel %d    step = %.8X\n", PSG.Current_Channel,
			   PSG.CntStep[PSG.Current_Channel]);
	    }
Ejemplo n.º 2
0
static inline int T_gens_do_MD_frame(void)
{
	int *buf[2];
	int HInt_Counter;
	
	// Set the number of visible lines.
	VDP_SET_VISIBLE_LINES();
	
	YM_Buf[0] = PSG_Buf[0] = Seg_L;
	YM_Buf[1] = PSG_Buf[1] = Seg_R;
	YM_Len = PSG_Len = 0;
	
	Cycles_M68K = Cycles_Z80 = 0;
	Last_BUS_REQ_Cnt = -1000;
	main68k_tripOdometer();
	mdZ80_clear_odo(&M_Z80);
	
	// Raise the MDP_EVENT_PRE_FRAME event.
	EventMgr::RaiseEvent(MDP_EVENT_PRE_FRAME, NULL);
	
	VRam_Flag = 1;
	
	VDP_Status &= 0xFFF7;		// Clear V Blank
	if (VDP_Reg.Set4 & 0x2)
		VDP_Status ^= 0x0010;
	
	HInt_Counter = VDP_Reg.H_Int;	// Hint_Counter = step H interrupt
	
	for (VDP_Current_Line = 0;
	     VDP_Current_Line < VDP_Num_Vis_Lines;
	     VDP_Current_Line++)
	{
		buf[0] = Seg_L + Sound_Extrapol[VDP_Current_Line][0];
		buf[1] = Seg_R + Sound_Extrapol[VDP_Current_Line][0];
		YM2612_DacAndTimers_Update(buf, Sound_Extrapol[VDP_Current_Line][1]);
		YM_Len += Sound_Extrapol[VDP_Current_Line][1];
		PSG_Len += Sound_Extrapol[VDP_Current_Line][1];
		
		Fix_Controllers();
		Cycles_M68K += CPL_M68K;
		Cycles_Z80 += CPL_Z80;
		if (DMAT_Length)
			main68k_addCycles(Update_DMA());
		
		VDP_Status |= 0x0004;	// HBlank = 1
		main68k_exec (Cycles_M68K - 404);
		VDP_Status &= 0xFFFB;	// HBlank = 0
		
		if (--HInt_Counter < 0)
		{
			HInt_Counter = VDP_Reg.H_Int;
			VDP_Int |= 0x4;
			VDP_Update_IRQ_Line();
		}
		
		if (VDP)
		{
			// VDP needs to be updated.
			Render_Line();
		}
		
		main68k_exec(Cycles_M68K);
		Z80_EXEC(0);
	}
	
	buf[0] = Seg_L + Sound_Extrapol[VDP_Current_Line][0];
	buf[1] = Seg_R + Sound_Extrapol[VDP_Current_Line][0];
	YM2612_DacAndTimers_Update (buf, Sound_Extrapol[VDP_Current_Line][1]);
	YM_Len += Sound_Extrapol[VDP_Current_Line][1];
	PSG_Len += Sound_Extrapol[VDP_Current_Line][1];
	
	Fix_Controllers();
	Cycles_M68K += CPL_M68K;
	Cycles_Z80 += CPL_Z80;
	if (DMAT_Length)
		main68k_addCycles(Update_DMA());
	
	if (--HInt_Counter < 0)
	{
		VDP_Int |= 0x4;
		VDP_Update_IRQ_Line();
	}
	
	CONGRATULATIONS_PRECHECK;
	VDP_Status |= 0x000C;		// VBlank = 1 et HBlank = 1 (retour de balayage vertical en cours)
	main68k_exec(Cycles_M68K - 360);
	Z80_EXEC(168);
	CONGRATULATIONS_POSTCHECK;
	
	VDP_Status &= 0xFFFB;		// HBlank = 0
	VDP_Status |= 0x0080;		// V Int happened
	
	VDP_Int |= 0x8;
	VDP_Update_IRQ_Line();
	mdZ80_interrupt(&M_Z80, 0xFF);
	
	main68k_exec(Cycles_M68K);
	Z80_EXEC(0);
	
	for (VDP_Current_Line++;
	     VDP_Current_Line < VDP_Num_Lines;
	     VDP_Current_Line++)
	{
		buf[0] = Seg_L + Sound_Extrapol[VDP_Current_Line][0];
		buf[1] = Seg_R + Sound_Extrapol[VDP_Current_Line][0];
		YM2612_DacAndTimers_Update (buf, Sound_Extrapol[VDP_Current_Line][1]);
		YM_Len += Sound_Extrapol[VDP_Current_Line][1];
		PSG_Len += Sound_Extrapol[VDP_Current_Line][1];
		
		Fix_Controllers();
		Cycles_M68K += CPL_M68K;
		Cycles_Z80 += CPL_Z80;
		if (DMAT_Length)
			main68k_addCycles(Update_DMA());
		
		VDP_Status |= 0x0004;	// HBlank = 1
		main68k_exec(Cycles_M68K - 404);
		VDP_Status &= 0xFFFB;	// HBlank = 0
		
		main68k_exec(Cycles_M68K);
		Z80_EXEC(0);
	}
	
	PSG_Special_Update();
	YM2612_Special_Update();
	
	// If WAV or GYM is being dumped, update the WAV or GYM.
	// TODO: VGM dumping
	if (WAV_Dumping)
		wav_dump_update();
	if (GYM_Dumping)
		gym_dump_update(0, 0, 0);
	
	// Raise the MDP_EVENT_POST_FRAME event.
	mdp_event_post_frame_t post_frame;
	if (bppMD == 32)
		post_frame.md_screen = &MD_Screen32[8];
	else
		post_frame.md_screen = &MD_Screen[8];
	post_frame.width = (vdp_isH40() ? 320 : 256);
	post_frame.height = VDP_Num_Vis_Lines;
	post_frame.pitch = 336;
	post_frame.bpp = bppMD;
	
	EventMgr::RaiseEvent(MDP_EVENT_POST_FRAME, &post_frame);
	
	return 1;
}