Example #1
0
void PEFile::GetRelocs(TUint *aReloc, TUint *aRelocSection, TInt /*aNumberOfRelocs*/)
//
// load the relocs from the reloc section into relocation and relocsection arrays
//
	{

	TUint *relocation=aReloc;
	TUint *relocsection=aRelocSection;
	char *aRelocData=iSectionData[KRelocSection];

	TUint16 *relocs=(TUint16 *)aRelocData;
	TInt relocsize=iSectionHeader[KRelocSection]->Misc.VirtualSize;
	TUint offset;
	TUint page;
	TInt i=0;

	TUint *rrelocs=(TUint *)aRelocData;
	TUint ssize=relocsize;
	if (!gLittleEndian) ByteSwap(rrelocs, ssize);

	while (relocsize>0)
		{
		page=*(TUint *)relocs;
		relocs+=2;
		TInt size=*(TUint *)relocs;
		if (size==0)
			break;
		relocsize-=size;
		relocs+=2;
		size-=8;
		while (size>0)
			{
			offset=*relocs++;
			TInt type=offset&0xf000;
			if (type==0x3000)
				{
				TUint va=page+(offset&0xfff);

				// va is the address requiring relocation, so it must be in a section and can't have been offset
				TInt section=FindSectionByVa(va+iLinkedBase);
				if (section==KTextSection || section==KConstSection || section==KDataSection || section==KCrtSection)
					{
					relocsection[i]=section;
					relocation[i++]=va;
					}
				}
			size-=2;
			}
		}

	if (!gLittleEndian) ByteSwap(rrelocs, ssize);
	}
Example #2
0
/*******************************************************************************
* Function Name  : Setup0_Process
* Description    : Get the device request data and dispatch to individual process.
* Input          : None.
* Output         : None.
* Return         : Post0_Process.
*******************************************************************************/
uint8_t Setup0_Process(void)
{

  union
  {
    uint8_t* b;
    uint16_t* w;
  } pBuf;

#ifdef STM32F10X_CL
  USB_OTG_EP *ep;
  uint16_t offset = 0;
 
  ep = PCD_GetOutEP(ENDP0);
  pBuf.b = ep->xfer_buff;
  
  OTGD_FS_EP0StartXfer(ep);
#else  
  uint16_t offset = 1;
  
  pBuf.b = PMAAddr + (uint8_t *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */
#endif /* STM32F10X_CL */

  if (pInformation->ControlState != PAUSE)
  {
    pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
    pInformation->USBbRequest = *pBuf.b++; /* bRequest */
    pBuf.w += offset;  /* word not accessed because of 32 bits addressing */
    pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
    pBuf.w += offset;  /* word not accessed because of 32 bits addressing */
    pInformation->USBwIndex  = ByteSwap(*pBuf.w++); /* wIndex */
    pBuf.w += offset;  /* word not accessed because of 32 bits addressing */
    pInformation->USBwLength = *pBuf.w; /* wLength */
  }

  pInformation->ControlState = SETTING_UP;
  if (pInformation->USBwLength == 0)
  {
    /* Setup with no data stage */
    NoData_Setup0();
  }
  else
  {
    /* Setup with data stage */
    Data_Setup0();
  }
  return Post0_Process();
}
Example #3
0
int main(int argc, char **argv)
{
    Stopif(argc < 2, "Supply bignum value in argv[1]!\n");

    slre_cap SlreCaps[3];
    u8 InputBuffer[128];

    i32 MatchedStringLength = slre_match("((\\d|[a-f])*)",
                                         argv[1],
                                         strlen(argv[1]),
                                         SlreCaps,
                                         ARRAY_LENGTH(SlreCaps),
                                         SLRE_IGNORE_CASE);
    if (MatchedStringLength > 0)
    {
        Stopif(SlreCaps[0].len % 2, "Invalid hex digit match!\n");

        HexStringToByteArray(InputBuffer, (char *)SlreCaps[0].ptr, SlreCaps[0].len);

        u32 InputBuffLengthBytes = MatchedStringLength/2;
        ByteSwap(InputBuffer, InputBuffLengthBytes);

        for (u32 ArrayIndex = 0;
             ArrayIndex < InputBuffLengthBytes;
             ++ArrayIndex)
        {
            printf("0x%02x, ", InputBuffer[ArrayIndex]);
        }

        printf("\n");
    }
}
Example #4
0
static inline void ByteSwapShortBuffer(WCHAR *buffer,int len)
{
    int i;
    uint16_t *sb=reinterpret_cast<uint16_t*>(buffer);
    for(i=0;i<len;i++)
        sb[i]=ByteSwap(sb[i]);
}
Example #5
0
	void SendObject(connection & s, amf3object & object)
	{
		try
		{
			if (serverstatus == 0)
				return;
			char buffer[15000];
			int length = 0;
			amf3writer * writer;

			writer = new amf3writer(buffer+4);

			writer->Write(object);

			(*(int*)buffer) = length = writer->position;
			ByteSwap(*(int*)buffer);

			s.write(buffer, length+4);
			delete writer;
		}
		catch (std::exception& e)
		{
			std::cerr << "exception: " << __FILE__ << " @ " << __LINE__ << "\n";
			std::cerr << e.what() << "\n";
		}

	}
Example #6
0
/* LITTLE ENDIAN での書き出しを行う。もとのメモリ内容は保存しておく。 */
int xfwrite_LE(void *p, int size, int num, FILE *fp){
	int block;
	void *tmp;

#ifndef WORDS_LITTLEENDIAN
	tmp = malloc( size*num );
	if( ! tmp )  {
		ErrMsg( "* malloc error in xfwrite\n" );
		restart(1);
	}
	memcpy( tmp, p, size*num );
	ByteSwap( tmp, size, num );
#else
/* BIG_ENDIAN */
	tmp = p;
#endif

	block = fwrite( tmp, size, num, fp);

#ifndef WORDS_LITTLEENDIAN
	free( tmp );
#endif

	return block;
}
Example #7
0
void connection::handle_read_header(const asio::error_code& e,
	std::size_t bytes_transferred)
{
	if (!e)
	{
		if (bytes_transferred == 4)
		{
			if (!memcmp(buffer_.data(), "<c", 2) || !memcmp(buffer_.data(), "<p", 2))
			{
				asio::async_write(socket_, asio::buffer("<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"21-60000\" /></cross-domain-policy>\0"),
					boost::bind(&connection::handle_write, shared_from_this(),
					asio::placeholders::error));
				asio::async_read(socket_, asio::buffer(buffer_, size), boost::bind(&connection::handle_read_header, shared_from_this(),
					asio::placeholders::error,
					asio::placeholders::bytes_transferred));
			}
			else
			{
				size = *(int32_t*)buffer_.data();
				ByteSwap(size);

				asio::async_read(socket_, asio::buffer(buffer_, size), boost::bind(&connection::handle_read, shared_from_this(),
					asio::placeholders::error,
					asio::placeholders::bytes_transferred));
			}
		}
	}
	else if (e != asio::error::operation_aborted)
	{
		server.stop(shared_from_this());
		return;
	}

}
Example #8
0
TInt PEFile::NumberOfImports() const
//
// Count the total number of imports for this image
//
	{
	
//	if (gX86imp)
//		return gX86num_imp_dlls;
	char *importData=iSectionData[KImportSection];
	PIMAGE_SECTION_HEADER importHeader=iSectionHeader[KImportSection];
	if (importData==NULL)
		return 0;
	TInt n=0;
	TUint *src=(TUint *)importData;
	while (*src)
		{
		TUint vaoffset=src[4];
		if (!gLittleEndian) ByteSwap(vaoffset);
		TUint offset=vaoffset-importHeader->VirtualAddress; // find the offset into the section of import addr table
		TUint *p=(TUint *)(importData+offset);
		while (*p++)
			n++;
		src+=5; // sizeof pe import block/4
		}
	return n;
	}
Example #9
0
void connection::handle_read_header(const boost::system::error_code& e,
									std::size_t bytes_transferred)
{
	if (!e)
	{
		if (bytes_transferred == 4)
		{
			size = *(int32_t*)buffer_.data();
			ByteSwap(size);

			if ((size < 4) || (size >= MAXPACKETSIZE))
			{
				server.consoleLogger->information(Poco::format("Did not receive proper amount of bytes : sent: %?d - ip:%s", size, address));
				server.stop(shared_from_this());
				return;
			}

			boost::asio::async_read(socket_, boost::asio::buffer(buffer_, size), boost::bind(&connection::handle_read, shared_from_this(),
				boost::asio::placeholders::error,
				boost::asio::placeholders::bytes_transferred));
		}
	}
	else if (e != boost::asio::error::operation_aborted)
	{
		server.stop(shared_from_this());
		return;
	}

}
Example #10
0
int GetDSPResponse(int dspnum, int n, unsigned short *data)
{
    /* read a response to a programming command */
    unsigned short resp[MAX_PACKET_SIZE];
    int size, dsize, readsize;
    int error = 0, done = 0;
    int ntries = 10;

    size = 2 * sizeof(unsigned short);
    dsize = n * sizeof(unsigned short);

    while (!done) {
	if (ntries > 0) {
	    readsize = read(client_message[dspnum].fd, resp, MAX_PACKET_SIZE * 
		    sizeof(short)); 
	    ByteSwap(resp, MAX_PACKET_SIZE);
	}
	else {
	    //sprintf(tmpstring, "Error: no response from DSP %d, resending\n", 
//		    dspnum);
//	    DisplayStatusMessage(tmpstring);
	    return 0;
	}

	/* check for status codes */
	if ((readsize > 0) && (resp[0] > sysinfo.ndsps)) {
	    done = 1;
	    /* this is not a left over data packet, so parse it */
	    if (resp[0] != DEVICE_CONTROL_ADDR) {
		fprintf(stderr, "Error writing to dsp %d: bad PortID %u\n", 
			dspnum, resp[0]);
		error = 1;
	    }
	    if (resp[1] != 1) {
		if (resp[1] == 3) {
		    fprintf(stderr, "Error writing to dsp: bad address\n");
		    return 0;
		}
		else if (resp[1] == 5) {
		    fprintf(stderr, "Error writing to dsp: unsupported command\n");
		    return 0;
		}
	    }
	}
	else if (readsize <= 0) {
	    sprintf(tmpstring, "Warning, no response from DSP %d", dspnum);
	    DisplayStatusMessage(tmpstring);
	    ntries--;
	}
    }
    /* copy the data if it is available */
    if (n) {
	fprintf(stderr, "read data, %d\n", resp[2]);
	memcpy(data, resp + 2, readsize - size);
    }
    return 1;
}
Example #11
0
int ImagerDoc::copy(void * in)
{
      memcpy(&Spcid, in, BLOCK0_BSZ );

#ifdef _LSBF_
    ByteSwap();
#endif

      return(TRUE);
}
Example #12
0
	bool Read(T& data)
	{
		void* readData = ReadBytes(sizeof(T));
		data = *static_cast<T*>(readData);
		if (GetLocalEndianess() != m_endianMode)
		{
			ByteSwap(&data, sizeof(T));
		}
		return true;
	}
void DrawSelectedVertices(GFXVertex *pavVertices, GFXColor *pacolColors, INDEX ctVertices)
{
  gfxEnableDepthBias();
  // for each vertex
  for(INDEX ivx=0;ivx<ctVertices;ivx++) {
    GFXVertex &vtx = pavVertices[ivx];
    GFXColor  &col = pacolColors[ivx];
    // draw vertex
    _pdp->DrawPoint3D(FLOAT3D(vtx.x,vtx.y,vtx.z),ByteSwap(col.ul.abgr),3);
  }
  gfxDisableDepthBias();
}
Example #14
0
int xfread_LE(void *p, int size, int num, FILE *fp)
{
	int block;

	block = fread( p, size, num, fp);

#ifndef WORDS_LITTLEENDIAN
	ByteSwap( p, size, block);
#endif /* !BIG_ENDIAN */

	return block;
}
Example #15
0
static void AddEarthJoker68k(void)
{
   // Init tc0220ioc emulation
   // ------------------------

   tc0220ioc.RAM  = RAM_INPUT;
   tc0220ioc.ctrl = 0;		//TC0220_STOPCPU;
   reset_tc0220ioc();

   // Init tc0002obj emulation
   // ------------------------

   tc0002obj.RAM	= RAM_OBJECT;
   if (romset==3) {
     tc0002obj.ofs_x	= 0;
     tc0002obj.ofs_y	= -8;
   }
   else {
     tc0002obj.ofs_x	= -8;
     tc0002obj.ofs_y	= 0;
   }

   // Init tc0100scn emulation
   // ------------------------

   setup_asuka_layers(RAM_VIDEO,RAM_SCROLL,GFX_FG0,17,8,&RAM[0x1B010]);

   ByteSwap(ROM,0x100000);
   ByteSwap(RAM,0x20000);

   AddMemFetch(0x000000, 0x0FFFFF, ROM+0x000000-0x000000);	// 68000 ROM
   AddMemFetch(-1, -1, NULL);

   if (romset==3)
     MemoryMap_Eto();
   else
     MemoryMap_EarthJoker();

   AddInitMemory();	// Set Starscream mem pointers...
}
Example #16
0
/*******************************************************************************
* Function Name  : Setup0_Process
* Description    : Get the device request data and dispatch to individual process.
* Input          : None.
* Output         : None.
* Return         : Post0_Process.
*******************************************************************************/
uint8_t Setup0_Process(void) {
	union {
		uint8_t* b;
		uint16_t* w;
	} pBuf;
	uint16_t offset = 1;

	pBuf.b = PMAAddr + (uint8_t *)(GetEPRxAddr(ENDP0) * 2);
	// *2 for 32 bits addr
	if (pInformation->ControlState != PAUSE) {
		pInformation->USBbmRequestType = *pBuf.b++;
		// bmRequestType
		pInformation->USBbRequest = *pBuf.b++;
		// bRequest
		pBuf.w += offset;
		// word not accessed because of 32 bits addressing
		pInformation->USBwValue = ByteSwap(*pBuf.w++);
		// wValue
		pBuf.w += offset;
		// word not accessed because of 32 bits addressing
		pInformation->USBwIndex  = ByteSwap(*pBuf.w++);
		// wIndex
		pBuf.w += offset;
		// word not accessed because of 32 bits addressing
		pInformation->USBwLength = *pBuf.w;
		// wLength
	}
	pInformation->ControlState = SETTING_UP;
	if (pInformation->USBwLength == 0) {
		// Setup with no data stage
		NoData_Setup0();
	} else {
		// Setup with data stage
		Data_Setup0();
	}

	return Post0_Process();
}
Example #17
0
/*******************************************************************************
* Function Name  : Setup0_Process
* Description    : Get the device request data and dispatch to individual process.
* Input          : None.
* Output         : None.
* Return         : Post0_Process.
*******************************************************************************/
u8 Setup0_Process(void)
{

  union
  {
    u8* b;
    u16* w;
  } pBuf;

  pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */

  if (pInformation->ControlState != PAUSE)
  {
    pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
    pInformation->USBbRequest = *pBuf.b++; /* bRequest */
    pBuf.w++;  /* word not accessed because of 32 bits addressing */
    pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
    pBuf.w++;  /* word not accessed because of 32 bits addressing */
    pInformation->USBwIndex  = ByteSwap(*pBuf.w++); /* wIndex */
    pBuf.w++;  /* word not accessed because of 32 bits addressing */
    pInformation->USBwLength = *pBuf.w; /* wLength */
  }

  pInformation->ControlState = SETTING_UP;
  if (pInformation->USBwLength == 0)
  {
    /* Setup with no data stage */
    NoData_Setup0();
  }
  else
  {
    /* Setup with data stage */
    Data_Setup0();
  }
  return Post0_Process();
}
// special write chunk function (no length or data)
bool RIFFWAVEChunk::WriteChunk(EnhancedFile *file)
{
  uint32_t data[] = {id};
  bool success = false;

  // treat ID  as big-endian
  ByteSwap(data[0], SWAP_FOR_BE);

  if (file->fwrite(data, NUMBEROF(data), sizeof(data[0])) > 0)
  {
    datapos = file->ftell();
    success = true;
  }

  return success;
}
Example #19
0
/*
 =======================================================================================================================
    Read ROM Header information into the int_entry, return ROM size
 =======================================================================================================================
 */
long __cdecl ReadRomHeader(	char		*rompath, INI_ENTRY	*ini_entry)
{
	/*~~~~~~~~~~~~~~~~~~~~~~*/
	uint8		buffer[0x100];
	long int	filesize;
	FILE		*fp;
	/*~~~~~~~~~~~~~~~~~~~~~~*/

	fp = fopen(rompath, "rb");
	if(fp != NULL)
	{
		/* Get file size */
		fseek(fp, 0, SEEK_END);
		filesize = ftell(fp);

		/* pad with zeros to fill the displacement */
		if(filesize & 0xFFFF) filesize = filesize + (0x10000 - (filesize & 0xFFFF));
		fseek(fp, 0, SEEK_SET); /* set pointer to beginning of file */

		fread(buffer, sizeof(uint8), 0x40, fp);
		if(ByteSwap(0x40, buffer) == TRUE)
		{
			strncpy((char*)ini_entry->Game_Name, (const char*)(buffer + 0x20), 0x14);
			SwapRomName((unsigned char*)ini_entry->Game_Name);

			/* SwapRomHeader(buffer); */
			ini_entry->crc1 = *((uint32 *) (buffer + 0x10));
			ini_entry->crc2 = *((uint32 *) (buffer + 0x14));
			ini_entry->countrycode = buffer[0x3D];

			/* ini_entry->countrycode = buffer[0x3E]; */
			fclose(fp);
			return filesize;
		}
		else
		{
			/* This file is not a ROM file, skipped */
			fclose(fp);
			return 0;
		}
	}
	else
	{
		/* Cannot open this file, skipped it */
		return 0;
	}
}
Example #20
0
uint8_t compassRead(int16_t *data)
{ int ii;
  int16_t buf[4]; uint8_t *tt=(uint8_t *) &buf[0];

  // data are LSB first no need for byte swap
  gyroRead(tt); for(ii=0;ii<3;ii++) data[ii]=buf[ii];
  
  #ifdef LSM303D
	  accRead(tt); for(ii=0;ii<3;ii++) data[3+ii]=buf[ii];
	  magRead(tt); for(ii=0;ii<3;ii++) data[6+ii]=buf[ii];
	  tempRead(tt); data[9]=buf[0];
  #else
	  accRead(tt); for(ii=0;ii<3;ii++) data[3+ii]=buf[ii]>>4;
	  magRead(tt); for(ii=0;ii<3;ii++) data[6+ii]=ByteSwap(buf[ii]);//(int16_t)(tt[jj++]<<8 | tt[jj++]);
	  tempRead(tt); data[9]=ByteSwap(buf[0])>>4;// ((int16_t)(tt[0]<<8 | tt[1]))>>4;
  #endif
  //
  return 1;
}
Example #21
0
	void SendObject(uint s, amf3object & object)
	{
		if (serverstatus == 0)
			return;
		if ((s == 0) || (m_clients[s]))
			return;
		char buffer[15000];
		int length = 0;
		amf3writer * writer;

		writer = new amf3writer(buffer+4);

		writer->Write(object);

		(*(int*)buffer) = length = writer->position;
		ByteSwap(*(int*)buffer);

		m_clients[s]->socket->write(buffer, length+4);
		delete writer;
	}
Example #22
0
std::vector<asio::const_buffer> reply::to_buffers()
{
    std::vector<asio::const_buffer> buffers;
    for (std::size_t i = 0; i < objects.size(); ++i)
    {
        amf3writer * writer;

        //TODO: use boost buffer object instead?
        char tbuff[15000];
        int length = 0;
        writer = new amf3writer(tbuff+4);

        writer->Write(objects[i]);

        (*(int*)tbuff) = length = writer->position;
        ByteSwap(*(int*)tbuff);

        buffers.push_back(asio::buffer(tbuff, length+4));
        delete writer;
    }
    return buffers;
}
Example #23
0
int bcf_file::read(void *buffer, unsigned int len, size_t size)
{
	int ret;

	if (is_BGZF)
	{
		ret = gzread(gzfile_in, buffer, size*len);
		ret = (ret == (int)(len*size) );
	}
	else
	{
		file_in->read((char*)buffer, size*len);
		ret = !file_in->eof();
	}

	if ((big_endian) && (size > 1)) // Note: don't both swapping character arrays - BCF is defined as little endian.
	{
		unsigned int ui;
		for (ui=0; ui<len; ui++)
			ByteSwap((unsigned char *)buffer+(size*ui), size);
	}
	return ret;
}
Example #24
0
bool ATAManager::GetDeviceInformation(ushort controller, uchar device, DeviceInfo &devInfo)
{
	AutoDisable	lock;	// disable ints
	uchar		statusReg;
	
	MemSet(&devInfo, 0, sizeof(DeviceInfo)); // just zero it out
		
	// delay for 400ns
	ATADriver::Delay400ns(controller);
	
	// check the status register
	statusReg = inb(controller | ATADriver::ALT_STATUS_REG);
	
	// if we get 0xFF from the status register then no controller :-(
	if(statusReg == 0xFF)
		return false;
	
// 	DEBUG("*** START (%x) ***\n", statusReg);
	
	// wait for the drive to not be busy
	do { statusReg = inb(controller | ATADriver::ALT_STATUS_REG); }
	while(statusReg & ATADriver::BUSY);
	
// 	DEBUG("STATUS REG: %x\n", statusReg);
	
	asm("cli");	// clear interrupts
	
	// wait for the drive to be ready
	do { statusReg = inb(controller | ATADriver::ALT_STATUS_REG); }
	while(!(statusReg & ATADriver::DRIVE_READY));
	
// 	DEBUG("STATUS REG: %x\n", statusReg);
	
	// select the device
	outb(controller | ATADriver::DRIVE_HEAD_REG, device);
	
	// send the "IDENTIFY DRIVE" command
	outb(controller | ATADriver::COMMAND_REG, ATADriver::IDENT_DEV);
	
	asm("sti");	// enable interrupts
	
// 	DEBUG("SENT COMMAND\n");
	
	// INT HAPPENS HERE
	
	// wait for the driver to not be busy
	do { statusReg = inb(controller | ATADriver::ALT_STATUS_REG); }
	while(statusReg & ATADriver::BUSY);
	
// 	DEBUG("STATUS REG: %x\n", statusReg);
	
	asm("cli");	// clear interrupts
	
	// poll to see if the drive is ready
	do { statusReg = inb(controller | ATADriver::ALT_STATUS_REG); }
	while(!(statusReg & ATADriver::DRIVE_READY) && (statusReg & ATADriver::DATA_READY));
	
// 	DEBUG("STATUS REG: %x\n", statusReg);
	
	ushort	tmpBuf[256];
	
	// getting an error probably means we're dealing with ATAPI
	if(statusReg & ATADriver::ERROR)
	{
// 		DEBUG("GOT AN ERROR\n");
		
		uchar cl, ch;
		
		// read in cylinder high & low to check for ATAPI
		cl = inb(controller | ATADriver::CYLINDER_LOW_REG);
		ch = inb(controller | ATADriver::CYLINDER_HIGH_REG);
		
// 		DEBUG("LOW 0x%x == 0x14 && HIGH 0x%x == 0xeb\n", cl, ch);
		
 		if(cl == 0x14 && ch == 0xeb)	// we have a packet device
		{
			// perform a software reset
			ATADriver::ResetController(controller);
		}
			
		else	// some other error
			PANIC("Unknown error identifying drives", false);
		
		//
		// Reset this device
		//
			
		// wait for the drive to not be busy
/*		do { statusReg = inb(controller | ATADriver::ALT_STATUS_REG); }
		while(statusReg & ATADriver::BUSY);

		asm("cli");
		
		// wait for the drive to be ready
		do { statusReg = inb(controller | ATADriver::ALT_STATUS_REG); }
		while(!(statusReg & ATADriver::DRIVE_READY));

		// select the device
		outb(controller | ATADriver::DRIVE_HEAD_REG, device);
		
		// send the "RESET DEVICE" command
		outb(controller | ATADriver::COMMAND_REG, ATADriver::RESET_DEVICE);
		
		asm("sti");
		
		// wait for the drive to not be busy
		do { statusReg = inb(controller | ATADriver::ALT_STATUS_REG); }
		while(statusReg & ATADriver::BUSY);
		
		statusReg = inb(controller | ATADriver::STATUS_REG);
		
		printf("STATUS: %x\n", statusReg);		
*/	
		return(false);
	}
	
// 	DEBUG("READING DATA\n");
	
	// it is 256 words (ushort) or 512 bytes (uchar)
	insw(controller | ATADriver::DATA_REG, tmpBuf, 256);
	
	// read the primary status register once
	inb(controller | ATADriver::STATUS_REG);
	
	// fill in the info for the drive
	devInfo.ATAPI_dev = tmpBuf[0] & 0x8000;
	devInfo.numLogCylinders = tmpBuf[1];
	devInfo.numLogHeads = tmpBuf[3];
	devInfo.numSecPreTrack = tmpBuf[6];
	
	MemCopy(devInfo.serialNumber, &tmpBuf[10], sizeof(devInfo.serialNumber));
	MemCopy(devInfo.firmwareVersion, &tmpBuf[23], sizeof(devInfo.firmwareVersion));
	MemCopy(devInfo.modelNumber, &tmpBuf[27], sizeof(devInfo.modelNumber));

	// need to byte swap the model number
	ByteSwap(devInfo.modelNumber, sizeof(devInfo.modelNumber));
	
	devInfo.maxSectorsForMultiple = tmpBuf[47] & 0x00FF;
	devInfo.numCurLogCylinders = tmpBuf[54];
	devInfo.numCurLogHeads = tmpBuf[55];
	devInfo.numCurLogSectorsPerTrack = tmpBuf[56];
	
	MemCopy(&devInfo.curCapacityInSectors, &tmpBuf[57], sizeof(devInfo.curCapacityInSectors));
	
	devInfo.curNumSectorsForMultiple = tmpBuf[59] & 0x00FF;
	
	MemCopy(&devInfo.totalAddressableSectors, &tmpBuf[60], sizeof(devInfo.totalAddressableSectors));

	devInfo.ATAVersion = tmpBuf[80];
	
	return(true);	
}
Example #25
0
static void SPARCPreprocHook( dis_handle *h, void *d, dis_dec_ins *ins )
{
    ByteSwap( h, d, ins );
}
Example #26
0
static void load_darius2(void)
{
   int ta,tb,tc,td;
   UINT8 *TMP;

   setup_z80_frame(CPU_Z80_0,CPU_FRAME_MHz(8,60));
   romset = 1;

   if(!(TMP=AllocateMem(0x80000))) return;
   if(!(GFX=AllocateMem(0x400000))) return;

   GFX_BG0 = GFX+0x000000;
   GFX_SPR = GFX+0x200000;

   tb=0;
   if(!load_rom("c07-03.12", TMP, 0x80000)) return;		// 8x8 BACKGROUND TILES
   for(ta=0;ta<0x80000;ta+=2){
      GFX[tb+1]=TMP[ta+1]&15;
      GFX[tb+0]=TMP[ta+1]>>4;
      GFX[tb+3]=TMP[ta+0]&15;
      GFX[tb+2]=TMP[ta+0]>>4;
      tb+=4;
   }
   if(!load_rom("c07-04.11", TMP, 0x80000)) return;
   for(ta=0;ta<0x80000;ta+=2){
      GFX[tb+1]=TMP[ta+1]&15;
      GFX[tb+0]=TMP[ta+1]>>4;
      GFX[tb+3]=TMP[ta+0]&15;
      GFX[tb+2]=TMP[ta+0]>>4;
      tb+=4;
   }
   if(!load_rom("c07-01", TMP, 0x80000)) return;		// 16x16 SPRITES
   for(ta=0;ta<0x80000;ta+=0){
      for(td=0;td<2;td++){
      tc=TMP[ta++];
      GFX[tb+3]=(((tc&0x80)>>7)<<1);
      GFX[tb+2]=(((tc&0x40)>>6)<<1);
      GFX[tb+1]=(((tc&0x20)>>5)<<1);
      GFX[tb+0]=(((tc&0x10)>>4)<<1);
      GFX[tb+3]|=(((tc&0x08)>>3)<<0);
      GFX[tb+2]|=(((tc&0x04)>>2)<<0);
      GFX[tb+1]|=(((tc&0x02)>>1)<<0);
      GFX[tb+0]|=(((tc&0x01)>>0)<<0);
      tc=TMP[ta++];
      GFX[tb+3]|=(((tc&0x80)>>7)<<3);
      GFX[tb+2]|=(((tc&0x40)>>6)<<3);
      GFX[tb+1]|=(((tc&0x20)>>5)<<3);
      GFX[tb+0]|=(((tc&0x10)>>4)<<3);
      GFX[tb+3]|=(((tc&0x08)>>3)<<2);
      GFX[tb+2]|=(((tc&0x04)>>2)<<2);
      GFX[tb+1]|=(((tc&0x02)>>1)<<2);
      GFX[tb+0]|=(((tc&0x01)>>0)<<2);
      tb+=4;
      }
      tb+=8;
      if((tb&0x7F)==0){tb-=0x78;}
      else{if((tb&0x7F)==8){tb-=8;}}
   }
   if(!load_rom("c07-02", TMP, 0x80000)) return;		// 16x16 SPRITES
   for(ta=0;ta<0x80000;ta+=0){
      for(td=0;td<2;td++){
      tc=TMP[ta++];
      GFX[tb+3]=(((tc&0x80)>>7)<<1);
      GFX[tb+2]=(((tc&0x40)>>6)<<1);
      GFX[tb+1]=(((tc&0x20)>>5)<<1);
      GFX[tb+0]=(((tc&0x10)>>4)<<1);
      GFX[tb+3]|=(((tc&0x08)>>3)<<0);
      GFX[tb+2]|=(((tc&0x04)>>2)<<0);
      GFX[tb+1]|=(((tc&0x02)>>1)<<0);
      GFX[tb+0]|=(((tc&0x01)>>0)<<0);
      tc=TMP[ta++];
      GFX[tb+3]|=(((tc&0x80)>>7)<<3);
      GFX[tb+2]|=(((tc&0x40)>>6)<<3);
      GFX[tb+1]|=(((tc&0x20)>>5)<<3);
      GFX[tb+0]|=(((tc&0x10)>>4)<<3);
      GFX[tb+3]|=(((tc&0x08)>>3)<<2);
      GFX[tb+2]|=(((tc&0x04)>>2)<<2);
      GFX[tb+1]|=(((tc&0x02)>>1)<<2);
      GFX[tb+0]|=(((tc&0x01)>>0)<<2);
      tb+=4;
      }
      tb+=8;
      if((tb&0x7F)==0){tb-=0x78;}
      else{if((tb&0x7F)==8){tb-=8;}}
   }

   FreeMem(TMP);

   RAMSize=0xA0000+0x20000;

   if(!(ROM=AllocateMem(0x120000))) return;
   if(!(RAM=AllocateMem(RAMSize))) return;

   if(!load_rom("c07-32-1", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta]=RAM[ta];
   }
   if(!load_rom("c07-29-1", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+1]=RAM[ta];
   }
   if(!load_rom("c07-31-1", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0x20000]=RAM[ta];
   }
   if(!load_rom("c07-30-1", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0x20001]=RAM[ta];
   }

   //if(!load_rom("c07-09.bin", ROM+0x40000, 0x80000)) return;
   //ByteSwap(ROM+0x40000,0x80000);
   if(!load_rom("c07-27", RAM, 0x20000)) return;
   for(ta=0;ta<0x20000;ta++){
      ROM[ta+ta+0x40000]=RAM[ta];
   }
   if(!load_rom("c07-25", RAM, 0x20000)) return;
   for(ta=0;ta<0x20000;ta++){
      ROM[ta+ta+0x40001]=RAM[ta];
   }
   if(!load_rom("c07-26", RAM, 0x20000)) return;
   for(ta=0;ta<0x20000;ta++){
      ROM[ta+ta+0x80000]=RAM[ta];
   }
   if(!load_rom("c07-24", RAM, 0x20000)) return;
   for(ta=0;ta<0x20000;ta++){
      ROM[ta+ta+0x80001]=RAM[ta];
   }

   if(!load_rom("c07-35-1", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0xC0000]=RAM[ta];
   }
   if(!load_rom("c07-38-1", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0xC0001]=RAM[ta];
   }
   if(!load_rom("c07-34-1", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0xE0000]=RAM[ta];
   }
   if(!load_rom("c07-37-1", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0xE0001]=RAM[ta];
   }
   if(!load_rom("c07-33-1", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0x100000]=RAM[ta];
   }
   if(!load_rom("c07-36-1", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0x100001]=RAM[ta];
   }

   /*-----[Sound Setup]-----*/

   Z80ROM=RAM+0xA0000;
   if(!load_rom("c07-28", Z80ROM, 0x20000)) return;		// Z80 SOUND ROM

   AddTaitoYM2610(0x0247, 0x01C7, 0x20000);

   /*-----------------------*/

   ROM[0x10F4]=0x60;	// Fix Main Checksum
   ROM[0x1172]=0x60;	// Fix Sub Checksum/communication problem

   ROM[0x11E4]=0x4E;	// jmp $300
   ROM[0x11E5]=0xF9;
   ROM[0x11E6]=0x00;
   ROM[0x11E7]=0x00;
   ROM[0x11E8]=0x03;
   ROM[0x11E9]=0x00;

   ROM[0x0300]=0x52;	// addq #1,$C10A0
   ROM[0x0301]=0x79;
   ROM[0x0302]=0x00;
   ROM[0x0303]=0x0C;
   ROM[0x0304]=0x10;
   ROM[0x0305]=0xA0;

   ROM[0x0306]=0x13;	// move.b #$00,$AA0000
   ROM[0x0307]=0xFC;	// Speed Hack
   ROM[0x0308]=0x00;
   ROM[0x0309]=0x00;
   ROM[0x030A]=0x00;
   ROM[0x030B]=0xAA;
   ROM[0x030C]=0x00;
   ROM[0x030D]=0x00;

   ROM[0x030E]=0x60;
   ROM[0x030F]=0x100-16;

   ROM[0xC0932]=0x60;	// Fix Sub Checksum

   ROM[0xC097E]=0x4E;	// jmp $300
   ROM[0xC097F]=0xF9;
   ROM[0xC0980]=0x00;
   ROM[0xC0981]=0x00;
   ROM[0xC0982]=0x03;
   ROM[0xC0983]=0x00;

   ROM[0xC0300]=0x52;	// addq #1,$C10A0
   ROM[0xC0301]=0x79;
   ROM[0xC0302]=0x00;
   ROM[0xC0303]=0x08;
   ROM[0xC0304]=0x0C;
   ROM[0xC0305]=0x94;

   ROM[0xC0306]=0x13;	// move.b #$00,$AA0000
   ROM[0xC0307]=0xFC;	// Speed Hack
   ROM[0xC0308]=0x00;
   ROM[0xC0309]=0x00;
   ROM[0xC030A]=0x00;
   ROM[0xC030B]=0xAA;
   ROM[0xC030C]=0x00;
   ROM[0xC030D]=0x00;

   ROM[0xC030E]=0x60;
   ROM[0xC030F]=0x100-16;

   memset(RAM+0x00000,0x00,0xA0000);

   GFX_FG0    = RAM+0x64000;
   RAM_INPUT  = RAM+0x3B000;

   tc0100scn[0].RAM     = RAM+0x21000-0x6000;
   tc0100scn[0].GFX_FG0 = GFX_FG0;

   init_tc0100scn(0);

   GFX_BG0_SOLID = make_solid_mask_8x8  (GFX_BG0, 0x8000);
   init_tile_cachex4();
   GFX_SPR_SOLID = make_solid_mask_16x16(GFX_SPR, 0x2000);

   tc0110pcr_init_typeb(RAM+0x38000, 1, 0);
   tc0110pcr_init_typeb_2(RAM+0x39000, 1, 0);
   tc0110pcr_init_typeb_3(RAM+0x3A000, 1, 0);

   set_colour_mapper(&col_map_xbbb_bbgg_gggr_rrrr);
   InitPaletteMap(RAM+0x38000, 0x80, 0x10, 0x8000);

   // Init tc0220ioc emulation
   // ------------------------

   tc0220ioc.RAM  = RAM_INPUT;
   tc0220ioc.ctrl = 0;		//TC0220_STOPCPU;
   reset_tc0220ioc();

   memset(RAM_INPUT,0x00,0x20);

/*
 *  StarScream Stuff follows
 */

   ByteSwap(ROM,0x120000);
   ByteSwap(RAM,0x60000);

   AddMemFetch(0x000000, 0x0BFFFF, ROM+0x000000-0x000000);	// 68000 ROM
   AddMemFetch(-1, -1, NULL);

   AddReadByte(0x000000, 0x0BFFFF, NULL, ROM+0x000000);			// 68000 ROM
   AddReadByte(0x0C0000, 0x0CFFFF, NULL, RAM+0x000000);			// MAIN RAM
   AddReadByte(0x240000, 0x24FFFF, NULL, RAM+0x024000);			// COMMON RAM
   AddReadByte(0x260000, 0x263FFF, NULL, RAM+0x034000);			// OBJECT RAM
   AddReadByte(0x280000, 0x293FFF, NULL, RAM+0x010000);			// SCREEN RAM
   AddReadByte(0x200000, 0x200003, tc0220ioc_rb_port, NULL);		// INPUT
   AddReadByte(0x000000, 0xFFFFFF, DefBadReadByte, NULL);		// <Bad Reads>
   AddReadByte(-1, -1, NULL, NULL);

   AddReadWord(0x000000, 0x0BFFFF, NULL, ROM+0x000000);			// 68000 ROM
   AddReadWord(0x0C0000, 0x0CFFFF, NULL, RAM+0x000000);			// MAIN RAM
   AddReadWord(0x240000, 0x24FFFF, NULL, RAM+0x024000);			// COMMON RAM
   AddReadWord(0x260000, 0x263FFF, NULL, RAM+0x034000);			// OBJECT RAM
   AddReadWord(0x280000, 0x293FFF, NULL, RAM+0x010000);			// SCREEN RAM
   AddReadWord(0x340000, 0x340007, tc0110pcr_rw, NULL);			// COLOR RAM SCREEN A
   AddReadWord(0x350000, 0x350007, tc0110pcr_rw_2, NULL);		// COLOR RAM SCREEN B
   AddReadWord(0x360000, 0x360007, tc0110pcr_rw_3, NULL);		// COLOR RAM SCREEN C
   AddReadWord(0x200000, 0x200003, tc0220ioc_rw_port, NULL);		// INPUT
   AddReadWord(0x2C0000, 0x2D3FFF, NULL, RAM+0x050000);			// CUSTOM2
   AddReadWord(0x300000, 0x313FFF, NULL, RAM+0x064000);			// CUSTOM3
   AddReadWord(0x220000, 0x220003, tc0140syt_read_main_68k, NULL);	// SOUND
   AddReadWord(0x000000, 0xFFFFFF, DefBadReadWord, NULL);		// <Bad Reads>
   AddReadWord(-1, -1, NULL, NULL);

   AddWriteByte(0x0C0000, 0x0CFFFF, NULL, RAM+0x000000);		// MAIN RAM
   AddWriteByte(0x240000, 0x24FFFF, NULL, RAM+0x024000);		// COMMON RAM
   AddWriteByte(0x260000, 0x263FFF, NULL, RAM+0x034000);		// OBJECT RAM
   AddWriteByte(0x280000, 0x290FFF, NULL, RAM+0x010000);		// SCREEN RAM
   AddWriteByte(0x291000, 0x291FFF, tc0100scn_0_gfx_fg0_wb, NULL);	// FG0 GFX RAM
   AddWriteByte(0x292000, 0x293FFF, NULL, RAM+0x022000);		// FG0 RAM
   AddWriteByte(0x200000, 0x200003, tc0220ioc_wb_port, NULL);		// INPUT
   AddWriteByte(0xAA0000, 0xAA0001, Stop68000, NULL);			// Trap Idle 68000
   AddWriteByte(0x000000, 0xFFFFFF, DefBadWriteByte, NULL);		// <Bad Writes>
   AddWriteByte(-1, -1, NULL, NULL);

   AddWriteWord(0x0C0000, 0x0CFFFF, NULL, RAM+0x000000);		// MAIN RAM
   AddWriteWord(0x240000, 0x24FFFF, NULL, RAM+0x024000);		// COMMON RAM
   AddWriteWord(0x260000, 0x263FFF, NULL, RAM+0x034000);		// OBJECT RAM
   AddWriteWord(0x280000, 0x290FFF, NULL, RAM+0x010000);		// SCREEN RAM
   AddWriteWord(0x291000, 0x291FFF, tc0100scn_0_gfx_fg0_ww, NULL);	// FG0 GFX RAM
   AddWriteWord(0x292000, 0x293FFF, NULL, RAM+0x022000);		// FG0 RAM
   AddWriteWord(0x340000, 0x340007, tc0110pcr_ww, NULL);		// COLOR RAM SCREEN A
   AddWriteWord(0x350000, 0x350007, tc0110pcr_ww_2, NULL);		// COLOR RAM SCREEN B
   AddWriteWord(0x360000, 0x360007, tc0110pcr_ww_3, NULL);		// COLOR RAM SCREEN C
   AddWriteWord(0x200000, 0x200003, tc0220ioc_ww_port, NULL);		// INPUT
   AddWriteWord(0x2A0000, 0x2A000F, NULL, RAM+0x03B100);		// SCROLL A
   AddWriteWord(0x2E0000, 0x2E000F, NULL, RAM+0x03B200);		// SCROLL B
   AddWriteWord(0x320000, 0x32000F, NULL, RAM+0x03B300);		// SCROLL C
   AddWriteWord(0x2C0000, 0x2D3FFF, NULL, RAM+0x050000);		// CUSTOM2
   AddWriteWord(0x300000, 0x313FFF, NULL, RAM+0x064000);		// CUSTOM3
   AddWriteWord(0x220000, 0x220003, tc0140syt_write_main_68k, NULL);	// SOUND
   AddWriteWord(0x000000, 0xFFFFFF, DefBadWriteWord, NULL);		// <Bad Writes>
   AddWriteWord(-1, -1, NULL, NULL);

   AddInitMemory();	// Set Starscream mem pointers...


   AddMemFetchMC68000B(0x000000, 0x05FFFF, ROM+0x0C0000-0x000000);	// 68000 ROM
   AddMemFetchMC68000B(-1, -1, NULL);

   AddReadByteMC68000B(0x000000, 0x05FFFF, NULL, ROM+0x0C0000);			// 68000 ROM
   AddReadByteMC68000B(0x080000, 0x08FFFF, NULL, RAM+0x040000);			// SUB LOCAL RAM
   AddReadByteMC68000B(0x240000, 0x24FFFF, NULL, RAM+0x024000);			// COMMON RAM
   AddReadByteMC68000B(0x260000, 0x263FFF, NULL, RAM+0x034000);			// OBJECT RAM
   AddReadByteMC68000B(0x280000, 0x293FFF, NULL, RAM+0x010000);			// SCREEN RAM
   AddReadByteMC68000B(0x200000, 0x200003, tc0220ioc_rb_port, NULL);		// INPUT
   AddReadByteMC68000B(0x000000, 0xFFFFFF, DefBadReadByte, NULL);		// <Bad Reads>
   AddReadByteMC68000B(-1, -1, NULL, NULL);

   AddReadWordMC68000B(0x000000, 0x05FFFF, NULL, ROM+0x0C0000);			// 68000 ROM
   AddReadWordMC68000B(0x080000, 0x08FFFF, NULL, RAM+0x040000);			// SUB LOCAL RAM
   AddReadWordMC68000B(0x240000, 0x24FFFF, NULL, RAM+0x024000);			// COMMON RAM
   AddReadWordMC68000B(0x260000, 0x263FFF, NULL, RAM+0x034000);			// OBJECT RAM
   AddReadWordMC68000B(0x280000, 0x293FFF, NULL, RAM+0x010000);			// SCREEN RAM
   AddReadWordMC68000B(0x340000, 0x340007, tc0110pcr_rw, NULL);			// COLOR RAM SCREEN A
   AddReadWordMC68000B(0x350000, 0x350007, tc0110pcr_rw_2, NULL);		// COLOR RAM SCREEN B
   AddReadWordMC68000B(0x360000, 0x360007, tc0110pcr_rw_3, NULL);		// COLOR RAM SCREEN C
   AddReadWordMC68000B(0x200000, 0x200003, tc0220ioc_rw_port, NULL);		// INPUT
   AddReadWordMC68000B(0x000000, 0xFFFFFF, DefBadReadWord, NULL);		// <Bad Reads>
   AddReadWordMC68000B(-1, -1, NULL, NULL);

   AddWriteByteMC68000B(0x080000, 0x08FFFF, NULL, RAM+0x040000);		// SUB LOCAL RAM
   AddWriteByteMC68000B(0x240000, 0x24FFFF, NULL, RAM+0x024000);		// COMMON RAM
   AddWriteByteMC68000B(0x260000, 0x263FFF, NULL, RAM+0x034000);		// OBJECT RAM
   AddWriteByteMC68000B(0x280000, 0x290FFF, NULL, RAM+0x010000);		// SCREEN RAM
   AddWriteByteMC68000B(0x291000, 0x291FFF, tc0100scn_0_gfx_fg0_wb, NULL);	// FG0 GFX RAM
   AddWriteByteMC68000B(0x292000, 0x293FFF, NULL, RAM+0x022000);		// FG0 RAM
   AddWriteByteMC68000B(0x200000, 0x200003, tc0220ioc_wb_port, NULL);		// INPUT
   AddWriteByteMC68000B(0xAA0000, 0xAA0001, Stop68000, NULL);			// Trap Idle 68000
   AddWriteByteMC68000B(0x000000, 0xFFFFFF, DefBadWriteByte, NULL);		// <Bad Writes>
   AddWriteByteMC68000B(-1, -1, NULL, NULL);

   AddWriteWordMC68000B(0x080000, 0x08FFFF, NULL, RAM+0x040000);		// SUB LOCAL RAM
   AddWriteWordMC68000B(0x240000, 0x24FFFF, NULL, RAM+0x024000);		// COMMON RAM
   AddWriteWordMC68000B(0x260000, 0x263FFF, NULL, RAM+0x034000);		// OBJECT RAM
   AddWriteWordMC68000B(0x280000, 0x290FFF, NULL, RAM+0x010000);		// SCREEN RAM
   AddWriteWordMC68000B(0x291000, 0x291FFF, tc0100scn_0_gfx_fg0_ww, NULL);	// FG0 GFX RAM
   AddWriteWordMC68000B(0x292000, 0x293FFF, NULL, RAM+0x022000);		// FG0 RAM
   AddWriteWordMC68000B(0x340000, 0x340007, tc0110pcr_ww, NULL);		// COLOR RAM SCREEN A
   AddWriteWordMC68000B(0x350000, 0x350007, tc0110pcr_ww_2, NULL);		// COLOR RAM SCREEN B
   AddWriteWordMC68000B(0x360000, 0x360007, tc0110pcr_ww_3, NULL);		// COLOR RAM SCREEN C
   AddWriteWordMC68000B(0x200000, 0x200003, tc0220ioc_ww_port, NULL);		// INPUT
   AddWriteWordMC68000B(0x000000, 0xFFFFFF, DefBadWriteWord, NULL);		// <Bad Writes>
   AddWriteWordMC68000B(-1, -1, NULL, NULL);

   AddInitMemoryMC68000B();	// Set Starscream mem pointers...
}
Example #27
0
static void load_ninjaw(void)
{
   int ta,tb,tc,td;
   UINT8 *TMP;

   setup_z80_frame(CPU_Z80_0,CPU_FRAME_MHz(4.5,60));
   romset = 0;

   if(!(TMP=AllocateMem(0x80000))) return;
   if(!(GFX=AllocateMem(0x600000))) return;

   GFX_BG0 = GFX+0x000000;
   GFX_SPR = GFX+0x200000;

   tb=0;
   if(!load_rom("b31-01.23", TMP, 0x80000)) return;		// 8x8 BACKGROUND TILES
   for(ta=0;ta<0x80000;ta+=2){
      GFX[tb+1]=TMP[ta+1]&15;
      GFX[tb+0]=TMP[ta+1]>>4;
      GFX[tb+3]=TMP[ta+0]&15;
      GFX[tb+2]=TMP[ta+0]>>4;
      tb+=4;
   }
   if(!load_rom("b31-02.24", TMP, 0x80000)) return;
   for(ta=0;ta<0x80000;ta+=2){
      GFX[tb+1]=TMP[ta+1]&15;
      GFX[tb+0]=TMP[ta+1]>>4;
      GFX[tb+3]=TMP[ta+0]&15;
      GFX[tb+2]=TMP[ta+0]>>4;
      tb+=4;
   }
   if(!load_rom("b31-07.176", TMP, 0x80000)) return;		// 16x16 SPRITES
   for(ta=0;ta<0x80000;ta+=0){
      for(td=0;td<2;td++){
      tc=TMP[ta++];
      GFX[tb+3]=(((tc&0x80)>>7)<<1);
      GFX[tb+2]=(((tc&0x40)>>6)<<1);
      GFX[tb+1]=(((tc&0x20)>>5)<<1);
      GFX[tb+0]=(((tc&0x10)>>4)<<1);
      GFX[tb+3]|=(((tc&0x08)>>3)<<0);
      GFX[tb+2]|=(((tc&0x04)>>2)<<0);
      GFX[tb+1]|=(((tc&0x02)>>1)<<0);
      GFX[tb+0]|=(((tc&0x01)>>0)<<0);
      tc=TMP[ta++];
      GFX[tb+3]|=(((tc&0x80)>>7)<<3);
      GFX[tb+2]|=(((tc&0x40)>>6)<<3);
      GFX[tb+1]|=(((tc&0x20)>>5)<<3);
      GFX[tb+0]|=(((tc&0x10)>>4)<<3);
      GFX[tb+3]|=(((tc&0x08)>>3)<<2);
      GFX[tb+2]|=(((tc&0x04)>>2)<<2);
      GFX[tb+1]|=(((tc&0x02)>>1)<<2);
      GFX[tb+0]|=(((tc&0x01)>>0)<<2);
      tb+=4;
      }
      tb+=8;
      if((tb&0x7F)==0){tb-=0x78;}
      else{if((tb&0x7F)==8){tb-=8;}}
   }
   if(!load_rom("b31-06.175", TMP, 0x80000)) return;		// 16x16 SPRITES
   for(ta=0;ta<0x80000;ta+=0){
      for(td=0;td<2;td++){
      tc=TMP[ta++];
      GFX[tb+3]=(((tc&0x80)>>7)<<1);
      GFX[tb+2]=(((tc&0x40)>>6)<<1);
      GFX[tb+1]=(((tc&0x20)>>5)<<1);
      GFX[tb+0]=(((tc&0x10)>>4)<<1);
      GFX[tb+3]|=(((tc&0x08)>>3)<<0);
      GFX[tb+2]|=(((tc&0x04)>>2)<<0);
      GFX[tb+1]|=(((tc&0x02)>>1)<<0);
      GFX[tb+0]|=(((tc&0x01)>>0)<<0);
      tc=TMP[ta++];
      GFX[tb+3]|=(((tc&0x80)>>7)<<3);
      GFX[tb+2]|=(((tc&0x40)>>6)<<3);
      GFX[tb+1]|=(((tc&0x20)>>5)<<3);
      GFX[tb+0]|=(((tc&0x10)>>4)<<3);
      GFX[tb+3]|=(((tc&0x08)>>3)<<2);
      GFX[tb+2]|=(((tc&0x04)>>2)<<2);
      GFX[tb+1]|=(((tc&0x02)>>1)<<2);
      GFX[tb+0]|=(((tc&0x01)>>0)<<2);
      tb+=4;
      }
      tb+=8;
      if((tb&0x7F)==0){tb-=0x78;}
      else{if((tb&0x7F)==8){tb-=8;}}
   }
   if(!load_rom("b31-05.174", TMP, 0x80000)) return;		// 16x16 SPRITES
   for(ta=0;ta<0x80000;ta+=0){
      for(td=0;td<2;td++){
      tc=TMP[ta++];
      GFX[tb+3]=(((tc&0x80)>>7)<<1);
      GFX[tb+2]=(((tc&0x40)>>6)<<1);
      GFX[tb+1]=(((tc&0x20)>>5)<<1);
      GFX[tb+0]=(((tc&0x10)>>4)<<1);
      GFX[tb+3]|=(((tc&0x08)>>3)<<0);
      GFX[tb+2]|=(((tc&0x04)>>2)<<0);
      GFX[tb+1]|=(((tc&0x02)>>1)<<0);
      GFX[tb+0]|=(((tc&0x01)>>0)<<0);
      tc=TMP[ta++];
      GFX[tb+3]|=(((tc&0x80)>>7)<<3);
      GFX[tb+2]|=(((tc&0x40)>>6)<<3);
      GFX[tb+1]|=(((tc&0x20)>>5)<<3);
      GFX[tb+0]|=(((tc&0x10)>>4)<<3);
      GFX[tb+3]|=(((tc&0x08)>>3)<<2);
      GFX[tb+2]|=(((tc&0x04)>>2)<<2);
      GFX[tb+1]|=(((tc&0x02)>>1)<<2);
      GFX[tb+0]|=(((tc&0x01)>>0)<<2);
      tb+=4;
      }
      tb+=8;
      if((tb&0x7F)==0){tb-=0x78;}
      else{if((tb&0x7F)==8){tb-=8;}}
   }
   if(!load_rom("b31-04.173", TMP, 0x80000)) return;		// 16x16 SPRITES
   for(ta=0;ta<0x80000;ta+=0){
      for(td=0;td<2;td++){
      tc=TMP[ta++];
      GFX[tb+3]=(((tc&0x80)>>7)<<1);
      GFX[tb+2]=(((tc&0x40)>>6)<<1);
      GFX[tb+1]=(((tc&0x20)>>5)<<1);
      GFX[tb+0]=(((tc&0x10)>>4)<<1);
      GFX[tb+3]|=(((tc&0x08)>>3)<<0);
      GFX[tb+2]|=(((tc&0x04)>>2)<<0);
      GFX[tb+1]|=(((tc&0x02)>>1)<<0);
      GFX[tb+0]|=(((tc&0x01)>>0)<<0);
      tc=TMP[ta++];
      GFX[tb+3]|=(((tc&0x80)>>7)<<3);
      GFX[tb+2]|=(((tc&0x40)>>6)<<3);
      GFX[tb+1]|=(((tc&0x20)>>5)<<3);
      GFX[tb+0]|=(((tc&0x10)>>4)<<3);
      GFX[tb+3]|=(((tc&0x08)>>3)<<2);
      GFX[tb+2]|=(((tc&0x04)>>2)<<2);
      GFX[tb+1]|=(((tc&0x02)>>1)<<2);
      GFX[tb+0]|=(((tc&0x01)>>0)<<2);
      tb+=4;
      }
      tb+=8;
      if((tb&0x7F)==0){tb-=0x78;}
      else{if((tb&0x7F)==8){tb-=8;}}
   }

   FreeMem(TMP);

   RAMSize=0xA0000;

   if(!(ROM=AllocateMem(0x120000))) return;
   if(!(RAM=AllocateMem(RAMSize))) return;

   RAM2=RAM+0x40000;

   if(!load_rom_index(13, RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta]=RAM[ta];
   }
   if(!load_rom_index(14, RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+1]=RAM[ta];
   }
   if(!load_rom("b31_29.34", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0x20000]=RAM[ta];
   }
   if(!load_rom("b31_27.31", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0x20001]=RAM[ta];
   }
   if(!load_rom("b31_41.5", RAM, 0x20000)) return;
   for(ta=0;ta<0x20000;ta++){
      ROM[ta+ta+0x40000]=RAM[ta];
   }
   if(!load_rom("b31_39.2", RAM, 0x20000)) return;
   for(ta=0;ta<0x20000;ta++){
      ROM[ta+ta+0x40001]=RAM[ta];
   }
   if(!load_rom("b31_40.6", RAM, 0x20000)) return;
   for(ta=0;ta<0x20000;ta++){
      ROM[ta+ta+0x80000]=RAM[ta];
   }
   if(!load_rom("b31_38.3", RAM, 0x20000)) return;
   for(ta=0;ta<0x20000;ta++){
      ROM[ta+ta+0x80001]=RAM[ta];
   }

   if(!load_rom("b31_33.87", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0xC0000]=RAM[ta];
   }
   if(!load_rom("b31_36.97", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0xC0001]=RAM[ta];
   }
   if(!load_rom("b31_32.86", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0xE0000]=RAM[ta];
   }
   if(!load_rom("b31_35.96", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0xE0001]=RAM[ta];
   }
   if(!load_rom("b31_31.85", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0x100000]=RAM[ta];
   }
   if(!load_rom("b31_34.95", RAM, 0x10000)) return;
   for(ta=0;ta<0x10000;ta++){
      ROM[ta+ta+0x100001]=RAM[ta];
   }

   /*-----[Sound Setup]-----*/

   Z80ROM=RAM+0x80000;
   if(!load_rom("b31_37.11", Z80ROM, 0x20000)) return;		// Z80 SOUND ROM

   AddTaitoYM2610(0x0345, 0x02B7, 0x20000);

   /*-----------------------*/

   // This one avoids to send an explicit start command to the 2nd 68k (cpua_w)
   // this is used only at start of the game, so it's easier to just disable it
   ROM[0x199C]=0x4E;	// Fix small 68000 communication problem
   ROM[0x199D]=0x71;

   ROM[0x07BA]=0x13;		// move.b #$00,$AA0000
   ROM[0x07BB]=0xFC;		// Speed Hack
   ROM[0x07BC]=0x00;
   ROM[0x07BD]=0x00;
   ROM[0x07BE]=0x00;
   ROM[0x07BF]=0xAA;
   ROM[0x07C0]=0x00;
   ROM[0x07C1]=0x00;

   ROM[0x07C2]=0x60;
   ROM[0x07C3]=0xE2;

   ROM[0xC07A6]=0x13;		// move.b #$00,$AA0000
   ROM[0xC07A7]=0xFC;		// Speed Hack
   ROM[0xC07A8]=0x00;
   ROM[0xC07A9]=0x00;
   ROM[0xC07AA]=0x00;
   ROM[0xC07AB]=0xAA;
   ROM[0xC07AC]=0x00;
   ROM[0xC07AD]=0x00;

   ROM[0xC07AE]=0x60;
   ROM[0xC07AF]=0xEE;
   // WriteWord68k(&ROM[0xc0ad4],0x4e71); // fast start, don't wait for the other

   memset(RAM+0x00000,0x00,0x80000);

   GFX_FG0    = RAM+0x64000;
   RAM_INPUT  = RAM+0x3B000;

   tc0100scn[0].RAM     = RAM+0x21000-0x6000;
   tc0100scn[0].GFX_FG0 = GFX_FG0;

   init_tc0100scn(0);
   tc0100scn_0_copy_gfx_fg0(ROM+0x22000, 0x1000);

   GFX_BG0_SOLID = make_solid_mask_8x8  (GFX_BG0, 0x8000);
   init_tile_cachex4();
   GFX_SPR_SOLID = make_solid_mask_16x16(GFX_SPR, 0x4000);

   tc0110pcr_init_typeb(RAM+0x38000, 1, 0);
   tc0110pcr_init_typeb_2(RAM+0x39000, 1, 0);
   tc0110pcr_init_typeb_3(RAM+0x3A000, 1, 0);

   set_colour_mapper(&col_map_xbbb_bbgg_gggr_rrrr);
   InitPaletteMap(RAM+0x38000, 0x100, 0x10, 0x8000);

   // Init tc0220ioc emulation
   // ------------------------

   tc0220ioc.RAM  = RAM_INPUT;
   tc0220ioc.ctrl = 0;		//TC0220_STOPCPU;
   reset_tc0220ioc();

   memset(RAM_INPUT,0x00,0x20);

/*
 *  StarScream Stuff follows
 */

   ByteSwap(ROM,0x120000);
   ByteSwap(RAM,0x50000);

   AddMemFetch(0x000000, 0x0BFFFF, ROM+0x000000-0x000000);	// 68000 ROM
   AddMemFetch(-1, -1, NULL);

   AddReadByte(0x000000, 0x0BFFFF, NULL, ROM+0x000000);			// 68000 ROM
   AddReadByte(0x0C0000, 0x0CFFFF, NULL, RAM+0x000000);			// MAIN RAM
   AddReadByte(0x240000, 0x24FFFF, NULL, RAM+0x024000);			// COMMON RAM
   AddReadByte(0x260000, 0x263FFF, NULL, RAM+0x034000);			// OBJECT RAM
   AddReadByte(0x280000, 0x293FFF, NULL, RAM+0x010000);			// SCREEN RAM
   AddReadByte(0x200000, 0x200003, tc0220ioc_rb_port, NULL);		// INPUT
   AddReadByte(0x000000, 0xFFFFFF, DefBadReadByte, NULL);		// <Bad Reads>
   AddReadByte(-1, -1, NULL, NULL);

   AddReadWord(0x000000, 0x0BFFFF, NULL, ROM+0x000000);			// 68000 ROM
   AddReadWord(0x0C0000, 0x0CFFFF, NULL, RAM+0x000000);			// MAIN RAM
   AddReadWord(0x240000, 0x24FFFF, NULL, RAM+0x024000);			// COMMON RAM
   AddReadWord(0x260000, 0x263FFF, NULL, RAM+0x034000);			// OBJECT RAM
   AddReadWord(0x280000, 0x293FFF, NULL, RAM+0x010000);			// SCREEN RAM
   AddReadWord(0x340000, 0x340007, tc0110pcr_rw, NULL);			// COLOR RAM SCREEN A
   AddReadWord(0x350000, 0x350007, tc0110pcr_rw_2, NULL);		// COLOR RAM SCREEN B
   AddReadWord(0x360000, 0x360007, tc0110pcr_rw_3, NULL);		// COLOR RAM SCREEN C
   AddReadWord(0x200000, 0x200003, tc0220ioc_rw_port, NULL);		// INPUT
   AddReadWord(0x220000, 0x220003, tc0140syt_read_main_68k, NULL);	// SOUND COMM
   AddReadWord(0x000000, 0xFFFFFF, DefBadReadWord, NULL);		// <Bad Reads>
   AddReadWord(-1, -1, NULL, NULL);

   AddWriteByte(0x0C0000, 0x0CFFFF, NULL, RAM+0x000000);		// MAIN RAM
   AddWriteByte(0x240000, 0x24FFFF, NULL, RAM+0x024000);		// COMMON RAM
   AddWriteByte(0x260000, 0x263FFF, NULL, RAM+0x034000);		// OBJECT RAM
   AddWriteByte(0x280000, 0x293FFF, NULL, RAM+0x010000);		// SCREEN RAM
   AddWriteByte(0x200000, 0x200003, tc0220ioc_wb_port, NULL);		// INPUT
   AddWriteByte(0xAA0000, 0xAA0001, Stop68000, NULL);			// Trap Idle 68000
   AddWriteByte(0x000000, 0xFFFFFF, DefBadWriteByte, NULL);		// <Bad Writes>
   AddWriteByte(-1, -1, NULL, NULL);

   AddWriteWord(0x0C0000, 0x0CFFFF, NULL, RAM+0x000000);		// MAIN RAM
   AddWriteWord(0x240000, 0x24FFFF, NULL, RAM+0x024000);		// COMMON RAM
   AddWriteWord(0x260000, 0x263FFF, NULL, RAM+0x034000);		// OBJECT RAM
   AddWriteWord(0x280000, 0x293FFF, NULL, RAM+0x010000);		// SCREEN RAM
   AddWriteWord(0x340000, 0x340007, tc0110pcr_ww, NULL);		// COLOR RAM SCREEN A
   AddWriteWord(0x350000, 0x350007, tc0110pcr_ww_2, NULL);		// COLOR RAM SCREEN B
   AddWriteWord(0x360000, 0x360007, tc0110pcr_ww_3, NULL);		// COLOR RAM SCREEN C
   AddWriteWord(0x200000, 0x200003, tc0220ioc_ww_port, NULL);		// INPUT
   AddWriteWord(0x2A0000, 0x2A000F, NULL, RAM+0x03B100);		// SCROLL A
   AddWriteWord(0x2E0000, 0x2E000F, NULL, RAM+0x03B200);		// SCROLL B
   AddWriteWord(0x320000, 0x32000F, NULL, RAM+0x03B300);		// SCROLL C
   AddWriteWord(0x220000, 0x220003, tc0140syt_write_main_68k, NULL);	// SOUND COMM
   AddWriteWord(0x000000, 0xFFFFFF, DefBadWriteWord, NULL);		// <Bad Writes>
   AddWriteWord(-1, -1, NULL, NULL);

   AddInitMemory();	// Set Starscream mem pointers...


   AddMemFetchMC68000B(0x000000, 0x05FFFF, ROM+0x0C0000-0x000000);	// 68000 ROM
   AddMemFetchMC68000B(-1, -1, NULL);

   AddReadByteMC68000B(0x000000, 0x05FFFF, NULL, ROM+0x0C0000);			// 68000 ROM
   AddReadByteMC68000B(0x080000, 0x08FFFF, NULL, RAM2+0x000000);		// SUB LOCAL RAM
   AddReadByteMC68000B(0x240000, 0x24FFFF, NULL, RAM+0x024000);			// COMMON RAM
   AddReadByteMC68000B(0x260000, 0x263FFF, NULL, RAM+0x034000);			// OBJECT RAM
   AddReadByteMC68000B(0x280000, 0x293FFF, NULL, RAM+0x010000);			// SCREEN RAM
   AddReadByteMC68000B(0x200000, 0x200003, tc0220ioc_rb_port, NULL);		// INPUT
   AddReadByteMC68000B(0x000000, 0xFFFFFF, DefBadReadByte, NULL);		// <Bad Reads>
   AddReadByteMC68000B(-1, -1, NULL, NULL);

   AddReadWordMC68000B(0x000000, 0x05FFFF, NULL, ROM+0x0C0000);			// 68000 ROM
   AddReadWordMC68000B(0x080000, 0x08FFFF, NULL, RAM2+0x000000);		// SUB LOCAL RAM
   AddReadWordMC68000B(0x240000, 0x24FFFF, NULL, RAM+0x024000);			// COMMON RAM
   AddReadWordMC68000B(0x260000, 0x263FFF, NULL, RAM+0x034000);			// OBJECT RAM
   AddReadWordMC68000B(0x280000, 0x293FFF, NULL, RAM+0x010000);			// SCREEN RAM
   AddReadWordMC68000B(0x340000, 0x340007, tc0110pcr_rw, NULL);			// COLOR RAM SCREEN A
   AddReadWordMC68000B(0x350000, 0x350007, tc0110pcr_rw_2, NULL);		// COLOR RAM SCREEN B
   AddReadWordMC68000B(0x360000, 0x360007, tc0110pcr_rw_3, NULL);		// COLOR RAM SCREEN C
   AddReadWordMC68000B(0x200000, 0x200003, tc0220ioc_rw_port, NULL);		// INPUT
   AddReadWordMC68000B(0x000000, 0xFFFFFF, DefBadReadWord, NULL);		// <Bad Reads>
   AddReadWordMC68000B(-1, -1, NULL, NULL);

   AddWriteByteMC68000B(0x080000, 0x08FFFF, NULL, RAM2+0x000000);		// SUB LOCAL RAM
   AddWriteByteMC68000B(0x240000, 0x24FFFF, NULL, RAM+0x024000);		// COMMON RAM
   AddWriteByteMC68000B(0x260000, 0x263FFF, NULL, RAM+0x034000);		// OBJECT RAM
   AddWriteByteMC68000B(0x280000, 0x293FFF, NULL, RAM+0x010000);		// SCREEN RAM
   AddWriteByteMC68000B(0x200000, 0x200003, tc0220ioc_wb_port, NULL);		// INPUT
   AddWriteByteMC68000B(0xAA0000, 0xAA0001, Stop68000, NULL);			// Trap Idle 68000
   AddWriteByteMC68000B(0x000000, 0xFFFFFF, DefBadWriteByte, NULL);		// <Bad Writes>
   AddWriteByteMC68000B(-1, -1, NULL, NULL);

   AddWriteWordMC68000B(0x080000, 0x08FFFF, NULL, RAM2+0x000000);		// SUB LOCAL RAM
   AddWriteWordMC68000B(0x240000, 0x24FFFF, NULL, RAM+0x024000);		// COMMON RAM
   AddWriteWordMC68000B(0x260000, 0x263FFF, NULL, RAM+0x034000);		// OBJECT RAM
   AddWriteWordMC68000B(0x280000, 0x293FFF, NULL, RAM+0x010000);		// SCREEN RAM
   AddWriteWordMC68000B(0x340000, 0x340007, tc0110pcr_ww, NULL);		// COLOR RAM SCREEN A
   AddWriteWordMC68000B(0x350000, 0x350007, tc0110pcr_ww_2, NULL);		// COLOR RAM SCREEN B
   AddWriteWordMC68000B(0x360000, 0x360007, tc0110pcr_ww_3, NULL);		// COLOR RAM SCREEN C
   AddWriteWordMC68000B(0x200000, 0x200003, tc0220ioc_ww_port, NULL);		// INPUT
   AddWriteWordMC68000B(0x000000, 0xFFFFFF, DefBadWriteWord, NULL);		// <Bad Writes>
   AddWriteWordMC68000B(-1, -1, NULL, NULL);

   AddInitMemoryMC68000B();	// Set Starscream mem pointers...
}
Example #28
0
// Calculate lightning for given model
void shaCalculateLight(void)
{
  // if full bright
  if(shaGetFlags()&BASE_FULL_BRIGHT) {
    GFXColor colLight = _colConstant;
    GFXColor colAmbient;
    GFXColor colConstant;
    // is over brightning enabled
    if(shaOverBrightningEnabled()) {
      colAmbient = 0x7F7F7FFF;
    } else {
      colAmbient = 0xFFFFFFFF;
    }
    colConstant.MultiplyRGBA(colLight,colAmbient);
    shaSetConstantColor(ByteSwap(colConstant.abgr));
    // no vertex colors
    return;
  }

  ASSERT(_paNormals!=NULL);
  _acolVtxColors.PopAll();
  _acolVtxColors.Push(_ctVertices);

  GFXColor colModel   = (GFXColor)_colModel;   // Model color
  GFXColor &colAmbient = (GFXColor)_colAmbient; // Ambient color
  GFXColor &colLight   = (GFXColor)_colLight;   // Light color
  GFXColor &colSurface = (GFXColor)_colConstant; // shader color

  colModel.MultiplyRGBA(colModel,colSurface);

  UBYTE ubColShift = 8;
  SLONG slar = colAmbient.r;
  SLONG slag = colAmbient.g;
  SLONG slab = colAmbient.b;

  if(shaOverBrightningEnabled()) {
    slar = ClampUp(slar,127L);
    slag = ClampUp(slag,127L);
    slab = ClampUp(slab,127L);
    ubColShift = 8;
  } else {
    slar*=2;
    slag*=2;
    slab*=2;
    ubColShift = 7;
  }

  // for each vertex color
  for(INDEX ivx=0;ivx<_ctVertices;ivx++) {
    // calculate vertex light
    FLOAT3D &vNorm = FLOAT3D(_paNormals[ivx].nx,_paNormals[ivx].ny,_paNormals[ivx].nz);
    FLOAT fDot = vNorm % _vLightDir;
    fDot = Clamp(fDot,0.0f,1.0f);
    SLONG slDot = NormFloatToByte(fDot);

    _acolVtxColors[ivx].r = ClampUp(colModel.r * (slar + ((colLight.r * slDot)>>ubColShift))>>8,255L);
    _acolVtxColors[ivx].g = ClampUp(colModel.g * (slag + ((colLight.g * slDot)>>ubColShift))>>8,255L);
    _acolVtxColors[ivx].b = ClampUp(colModel.b * (slab + ((colLight.b * slDot)>>ubColShift))>>8,255L);
    _acolVtxColors[ivx].a = colModel.a;//slDot;
  }
  // Set current vertex color array 
  _pcolVtxColors = &_acolVtxColors[0];
}
Example #29
0
static void load_rastan(void)
{
   RAMSize=0x20000+0x10000;

   if(!(RAM=AllocateMem(RAMSize))) return;

   /*-----[Sound Setup]-----*/

   Z80ROM=RAM+0x20000;
   if(!(PCMROM=AllocateMem(0x10000))) return;

   if(!load_rom("ic49_19.bin", Z80ROM, 0x10000)) return;		// Z80 SOUND ROM
   if(!load_rom("ic76_20.bin", PCMROM, 0x10000)) return;

   AddTaitoYM2151(0x01C0, 0x01AB, 0x10000, (UINT8 *) Rastan_M5205_W, NULL);

   msm5205_interface.rom[0] = PCMROM;
   msm5205_interface.romsize[0] = 0x10000;
   msm5205_interface.updatemode = MSM5205_MONO;

   /*-----------------------*/

   memset(RAM+0x00000,0x00,0x20000);

   RAM[0x1A007]=0x9F;			// !! Vital !!

   RAM_VIDEO  = RAM+0x08000;
   RAM_SCROLL = RAM+0x1B080;
   RAM_OBJECT = RAM+0x18000;

   set_colour_mapper(&col_map_xbbb_bbgg_gggr_rrrr);
   InitPaletteMap(RAM+0x4000, 0x100, 0x10, 0x8000);

   // 68000 Speed Hack
   // ----------------

   if(is_current_game("rastan"))
   {
      WriteLong68k(&ROM[0x00146],0x4E714E71);	//	nop
      WriteLong68k(&ROM[0x3B08C],0x13FC0000);	//	move.b	#$00,$AA0000
      WriteLong68k(&ROM[0x3B090],0x00AA0000);	//
      WriteWord68k(&ROM[0x3B094],0x4E71);	//	nop
   }
   if(is_current_game("rastsaga"))
   {
      WriteLong68k(&ROM[0x3B088],0x13FC0000);	//	move.b	#$00,$AA0000
      WriteLong68k(&ROM[0x3B08C],0x00AA0000);	//
      WriteWord68k(&ROM[0x3B090],0x4E71);	//	nop
   }

   // Init tc0100scn emulation
   // ------------------------

   tc0100scn[0].layer[0].RAM    =RAM_VIDEO+0x0000;
   tc0100scn[0].layer[0].SCR    =RAM_SCROLL+0;
   tc0100scn[0].layer[0].type   =0;
   tc0100scn[0].layer[0].bmp_x  =32;
   tc0100scn[0].layer[0].bmp_y  =32;
   tc0100scn[0].layer[0].bmp_w  =320;
   tc0100scn[0].layer[0].bmp_h  =240;
// Mapper disabled
   tc0100scn[0].layer[0].tile_mask=0x3FFF;
   tc0100scn[0].layer[0].scr_x  =16;
   tc0100scn[0].layer[0].scr_y  =8;

   tc0100scn[0].layer[1].RAM    =RAM_VIDEO+0x8000;
   tc0100scn[0].layer[1].SCR    =RAM_SCROLL+2;
   tc0100scn[0].layer[1].type   =0;
   tc0100scn[0].layer[1].bmp_x  =32;
   tc0100scn[0].layer[1].bmp_y  =32;
   tc0100scn[0].layer[1].bmp_w  =320;
   tc0100scn[0].layer[1].bmp_h  =240;
// Mapper disabled
   tc0100scn[0].layer[1].tile_mask=0x3FFF;
   tc0100scn[0].layer[1].scr_x  =16;
   tc0100scn[0].layer[1].scr_y  =8;

   tc0100scn[0].RAM     = RAM_VIDEO;
   init_tc0100scn(0);

   // Init tc0002obj emulation
   // ------------------------

   tc0002obj.RAM        = RAM_OBJECT;
   tc0002obj.GFX        = NULL;
   tc0002obj.bmp_x      = 32;
   tc0002obj.bmp_y      = 32;
   tc0002obj.bmp_w      = 320;
   tc0002obj.bmp_h      = 240;
// Mapper disabled
   tc0002obj.tile_mask  = 0x0FFF;
   tc0002obj.ofs_x      = 0;
   tc0002obj.ofs_y      = -8;

/*
 *  StarScream Stuff follows
 */

   ByteSwap(ROM,0x60000);
   ByteSwap(RAM,0x1B100);

   AddMemFetch(0x000000, 0x05FFFF, ROM+0x000000-0x000000);	// 68000 ROM
   AddMemFetch(-1, -1, NULL);

   AddReadByte(0x000000, 0x05FFFF, NULL, ROM+0x000000);			// 68000 ROM
   AddReadByte(0x10C000, 0x10FFFF, NULL, RAM+0x000000);			// 68000 RAM
   AddReadByte(0xC00000, 0xC0FFFF, NULL, RAM_VIDEO);
   AddReadByte(0xD00000, 0xD01FFF, NULL, RAM+0x018000);
   AddReadByte(0x200000, 0x203FFF, NULL, RAM+0x004000);
   AddReadByte(0x390000, 0x390FFF, NULL, RAM+0x01A000);			// INPUT
   AddReadByte(0x350000, 0x35000F, NULL, RAM+0x01B010);
   AddReadByte(0x380000, 0x380001, NULL, RAM+0x01B00A);
   AddReadByte(0x3C0000, 0x3C0001, NULL, RAM+0x01B020);
   AddReadByte(0x3E0000, 0x3E0003, tc0140syt_read_main_68k, NULL);
   AddReadByte(-1, -1, NULL, NULL);

   AddReadWord(0x000000, 0x05FFFF, NULL, ROM+0x000000);			// 68000 ROM
   AddReadWord(0x10C000, 0x10FFFF, NULL, RAM+0x000000);			// 68000 RAM
   AddReadWord(0xC00000, 0xC0FFFF, NULL, RAM_VIDEO);
   AddReadWord(0xD00000, 0xD01FFF, NULL, RAM+0x018000);
   AddReadWord(0x200000, 0x203FFF, NULL, RAM+0x004000);
   AddReadWord(0x390000, 0x390FFF, NULL, RAM+0x01A000);			// INPUT
   AddReadWord(0x350000, 0x35000F, NULL, RAM+0x01B010);
   AddReadWord(0x380000, 0x380001, NULL, RAM+0x01B00A);
   AddReadWord(0x3C0000, 0x3C0001, NULL, RAM+0x01B020);
   AddReadWord(0x3E0000, 0x3E0003, NULL, RAM+0x01B00C);
   AddReadWord(-1, -1, NULL, NULL);

   AddWriteByte(0x10C000, 0x10FFFF, NULL, RAM+0x000000);		// 68000 RAM
   AddWriteByte(0xC00000, 0xC0FFFF, NULL, RAM_VIDEO);
   AddWriteByte(0xD00000, 0xD01FFF, NULL, RAM+0x018000);
   AddWriteByte(0x200000, 0x203FFF, NULL, RAM+0x004000);
   AddWriteByte(0xC20000, 0xC20003, NULL, RAM_SCROLL+6);                // SCROLL Y
   AddWriteByte(0xC40000, 0xC40003, NULL, RAM_SCROLL+0);                // SCROLL X
   AddWriteByte(0xC50000, 0xC50001, NULL, RAM_SCROLL+14);               // CTRL
   AddWriteByte(0x350000, 0x35000F, NULL, RAM+0x01B010);
   AddWriteByte(0x380000, 0x380001, NULL, RAM+0x01B00A);
   AddWriteByte(0x390000, 0x390FFF, NULL, RAM+0x01A000);		// INPUT
   AddWriteByte(0x3C0000, 0x3C0001, NULL, RAM+0x01B020);
   AddWriteByte(0x3E0000, 0x3E0003, tc0140syt_write_main_68k, NULL);
   AddWriteByte(0xAA0000, 0xAA0001, Stop68000, NULL);			// Trap Idle 68000
   AddWriteByte(-1, -1, NULL, NULL);

   AddWriteWord(0x10C000, 0x10FFFF, NULL, RAM+0x000000);		// 68000 RAM
   AddWriteWord(0xC00000, 0xC0FFFF, NULL, RAM_VIDEO);
   AddWriteWord(0xD00000, 0xD01FFF, NULL, RAM+0x018000);
   AddWriteWord(0x200000, 0x203FFF, NULL, RAM+0x004000);
   AddWriteWord(0xC20000, 0xC20003, NULL, RAM_SCROLL+6);                // SCROLL Y
   AddWriteWord(0xC40000, 0xC40003, NULL, RAM_SCROLL+0);                // SCROLL X
   AddWriteWord(0xC50000, 0xC50001, NULL, RAM_SCROLL+14);               // CTRL
   AddWriteWord(0x350000, 0x35000F, NULL, RAM+0x01B010);
   AddWriteWord(0x380000, 0x380001, NULL, RAM+0x01B00A);
   AddWriteWord(0x390000, 0x390FFF, NULL, RAM+0x01A000);		// INPUT
   AddWriteWord(0x3C0000, 0x3C0001, NULL, RAM+0x01B020);
   AddWriteWord(0x3E0000, 0x3E0003, NULL, RAM+0x01B00C);
   AddWriteWord(-1, -1, NULL, NULL);

   AddInitMemory();	// Set Starscream mem pointers...
}
Example #30
0
static void load_masterw(void)
{
   int ta,tb,tc;

   RAMSize=0x38000;

   if(!(RAM=AllocateMem(0x80000))) return;
   if(!(GFX=AllocateMem(0x240000))) return;

   GFX_BG0 = GFX+0x000000;
   GFX_BG2 = GFX+0x200000;

   if(!load_rom("mow-m01.rom", RAM, 0x80000)) return;
   tb=0x200000;
   for(ta=0;ta<0x10000;ta+=2){
      tc=RAM[ta+1];
      GFX[tb+0]=((tc&0x80)>>7)<<0;
      GFX[tb+1]=((tc&0x40)>>6)<<0;
      GFX[tb+2]=((tc&0x20)>>5)<<0;
      GFX[tb+3]=((tc&0x10)>>4)<<0;
      GFX[tb+4]=((tc&0x08)>>3)<<0;
      GFX[tb+5]=((tc&0x04)>>2)<<0;
      GFX[tb+6]=((tc&0x02)>>1)<<0;
      GFX[tb+7]=((tc&0x01)>>0)<<0;
      tc=RAM[ta];
      GFX[tb+0]|=((tc&0x80)>>7)<<1;
      GFX[tb+1]|=((tc&0x40)>>6)<<1;
      GFX[tb+2]|=((tc&0x20)>>5)<<1;
      GFX[tb+3]|=((tc&0x10)>>4)<<1;
      GFX[tb+4]|=((tc&0x08)>>3)<<1;
      GFX[tb+5]|=((tc&0x04)>>2)<<1;
      GFX[tb+6]|=((tc&0x02)>>1)<<1;
      GFX[tb+7]|=((tc&0x01)>>0)<<1;
      tb+=8;
   }
   tb=0;
   for(ta=0;ta<0x80000;ta+=2){
      tc=RAM[ta+1];
      GFX[tb+0]=((tc&0x80)>>7)<<0;
      GFX[tb+1]=((tc&0x40)>>6)<<0;
      GFX[tb+2]=((tc&0x20)>>5)<<0;
      GFX[tb+3]=((tc&0x10)>>4)<<0;
      GFX[tb+4]=((tc&0x08)>>3)<<0;
      GFX[tb+5]=((tc&0x04)>>2)<<0;
      GFX[tb+6]=((tc&0x02)>>1)<<0;
      GFX[tb+7]=((tc&0x01)>>0)<<0;
      tc=RAM[ta];
      GFX[tb+0]|=((tc&0x80)>>7)<<1;
      GFX[tb+1]|=((tc&0x40)>>6)<<1;
      GFX[tb+2]|=((tc&0x20)>>5)<<1;
      GFX[tb+3]|=((tc&0x10)>>4)<<1;
      GFX[tb+4]|=((tc&0x08)>>3)<<1;
      GFX[tb+5]|=((tc&0x04)>>2)<<1;
      GFX[tb+6]|=((tc&0x02)>>1)<<1;
      GFX[tb+7]|=((tc&0x01)>>0)<<1;
      tb+=16;
      if((tb&0x7F)==0){tb-=0x78;}
      else{if((tb&0x7F)==8){tb-=0x08;}}
   }

   if(!load_rom("mow-m02.rom", RAM, 0x80000)) return;
   tb=0x200000;
   for(ta=0;ta<0x10000;ta+=2){
      tc=RAM[ta+1];
      GFX[tb+0]|=((tc&0x80)>>7)<<2;
      GFX[tb+1]|=((tc&0x40)>>6)<<2;
      GFX[tb+2]|=((tc&0x20)>>5)<<2;
      GFX[tb+3]|=((tc&0x10)>>4)<<2;
      GFX[tb+4]|=((tc&0x08)>>3)<<2;
      GFX[tb+5]|=((tc&0x04)>>2)<<2;
      GFX[tb+6]|=((tc&0x02)>>1)<<2;
      GFX[tb+7]|=((tc&0x01)>>0)<<2;
      tc=RAM[ta];
      GFX[tb+0]|=((tc&0x80)>>7)<<3;
      GFX[tb+1]|=((tc&0x40)>>6)<<3;
      GFX[tb+2]|=((tc&0x20)>>5)<<3;
      GFX[tb+3]|=((tc&0x10)>>4)<<3;
      GFX[tb+4]|=((tc&0x08)>>3)<<3;
      GFX[tb+5]|=((tc&0x04)>>2)<<3;
      GFX[tb+6]|=((tc&0x02)>>1)<<3;
      GFX[tb+7]|=((tc&0x01)>>0)<<3;
      tb+=8;
   }
   tb=0;
   for(ta=0;ta<0x80000;ta+=2){
      tc=RAM[ta+1];
      GFX[tb+0]|=((tc&0x80)>>7)<<2;
      GFX[tb+1]|=((tc&0x40)>>6)<<2;
      GFX[tb+2]|=((tc&0x20)>>5)<<2;
      GFX[tb+3]|=((tc&0x10)>>4)<<2;
      GFX[tb+4]|=((tc&0x08)>>3)<<2;
      GFX[tb+5]|=((tc&0x04)>>2)<<2;
      GFX[tb+6]|=((tc&0x02)>>1)<<2;
      GFX[tb+7]|=((tc&0x01)>>0)<<2;
      tc=RAM[ta];
      GFX[tb+0]|=((tc&0x80)>>7)<<3;
      GFX[tb+1]|=((tc&0x40)>>6)<<3;
      GFX[tb+2]|=((tc&0x20)>>5)<<3;
      GFX[tb+3]|=((tc&0x10)>>4)<<3;
      GFX[tb+4]|=((tc&0x08)>>3)<<3;
      GFX[tb+5]|=((tc&0x04)>>2)<<3;
      GFX[tb+6]|=((tc&0x02)>>1)<<3;
      GFX[tb+7]|=((tc&0x01)>>0)<<3;
      tb+=16;
      if((tb&0x7F)==0){tb-=0x78;}
      else{if((tb&0x7F)==8){tb-=0x08;}}
   }

   Rotate16x16(GFX_BG0,0x2000);
   Flip16x16_X(GFX_BG0,0x2000);
   Rotate8x8  (GFX_BG2,0x1000);
   Flip8x8_X  (GFX_BG2,0x1000);

   /*-----[Sound Setup]-----*/

   Z80ROM=RAM+0x28000;
   if(!load_rom("b72-07.rom", Z80ROM, 0x10000)) return;	// Z80 SOUND ROM

   AddTaitoYM2203(0x02CB, 0x025C, 0x10000, NULL, 0x00000);

   /*-----------------------*/

   memset(RAM+0x00000,0x00,0x28000);

   RAM_INPUT  = RAM+0x25100;
   RAM_VIDEO  = RAM+0x04000;
   RAM_COLOUR = RAM+0x24000;

   GFX_BG0_SOLID = make_solid_mask_16x16(GFX_BG0, 0x2000);
   GFX_BG2_SOLID = make_solid_mask_8x8  (GFX_BG2, 0x1000);

   InitPaletteMap(RAM_COLOUR, 0x40, 0x10, 0x1000);

   set_colour_mapper(&col_map_rrrr_gggg_bbbb_xxxx);

   WriteLong68k(&ROM[0x0742],0x13FC0000);	// move.b #$00,$AA0000
   WriteLong68k(&ROM[0x0746],0x00AA0000);
   WriteWord68k(&ROM[0x074A],0x4E71);		// nop

   // Init tc0220ioc emulation
   // ------------------------

   tc0220ioc.RAM  = input_buffer;
   tc0220ioc.ctrl = 0;		//TC0220_STOPCPU;
   reset_tc0220ioc();

   // Init tc0180vcu emulation
   // ------------------------

   tc0180vcu.RAM	= RAM_VIDEO;
   tc0180vcu.RAM_2	= RAM_VIDEO+0x18000;
   tc0180vcu.GFX_BG0	= GFX_BG0;
   tc0180vcu.GFX_BG0_MSK= GFX_BG0_SOLID;
   tc0180vcu.GFX_BG2	= GFX_BG2;
   tc0180vcu.GFX_BG2_MSK= GFX_BG2_SOLID;
   tc0180vcu.tile_mask	= 0x1FFF;
   tc0180vcu.bmp_x	= 32;
   tc0180vcu.bmp_y	= 32;
   tc0180vcu.bmp_w	= 224;
   tc0180vcu.bmp_h	= 320;
   tc0180vcu.scr_x	= 16;
   tc0180vcu.scr_y	= 0;

   vcu_make_col_bankmap(0x10,0x30,0x20,0x10,0x00);

/*
 *  StarScream Stuff follows
 */

   ByteSwap(ROM,0x80000);
   ByteSwap(RAM,0x25000);

   AddMemFetch(0x000000, 0x07FFFF, ROM+0x000000-0x000000);	// 68000 ROM
   AddMemFetch(-1, -1, NULL);

   AddReadByte(0x000000, 0x07FFFF, NULL, ROM+0x000000);			// 68000 ROM
   AddReadByte(0x200000, 0x203FFF, NULL, RAM+0x000000);			// 68000 RAM
   AddReadByte(0x400000, 0x41FFFF, NULL, RAM_VIDEO);			// SCREEN RAM
   AddReadByte(0x600000, 0x600FFF, NULL, RAM_COLOUR);			// COLOR RAM
   AddReadByte(0x800000, 0x800003, tc0220ioc_rb_port, NULL);		// INPUT
   AddReadByte(0xA00000, 0xA00003, tc0140syt_read_main_68k, NULL);	// SOUND
   AddReadByte(0x000000, 0xFFFFFF, DefBadReadByte, NULL);		// <Bad Reads>
   AddReadByte(-1, -1, NULL, NULL);

   AddReadWord(0x000000, 0x07FFFF, NULL, ROM+0x000000);			// 68000 ROM
   AddReadWord(0x200000, 0x203FFF, NULL, RAM+0x000000);			// 68000 RAM
   AddReadWord(0x400000, 0x41FFFF, NULL, RAM_VIDEO);			// SCREEN RAM
   AddReadWord(0x600000, 0x600FFF, NULL, RAM_COLOUR);			// COLOR RAM
   AddReadWord(0x800000, 0x800003, tc0220ioc_rw_port, NULL);		// INPUT
   AddReadWord(0x000000, 0xFFFFFF, DefBadReadWord, NULL);		// <Bad Reads>
   AddReadWord(-1, -1,NULL, NULL);

   AddWriteByte(0x200000, 0x203FFF, NULL, RAM+0x000000);		// 68000 RAM
   AddWriteByte(0x400000, 0x41FFFF, NULL, RAM_VIDEO);			// SCREEN RAM
   AddWriteByte(0x600000, 0x600FFF, NULL, RAM_COLOUR);			// COLOR RAM
   AddWriteByte(0x800000, 0x800003, tc0220ioc_wb_port, NULL);		// INPUT
   AddWriteByte(0xA00000, 0xA00003, tc0140syt_write_main_68k, NULL);	// SOUND
   AddWriteByte(0xAA0000, 0xAA0001, Stop68000, NULL);			// Trap Idle 68000
   AddWriteByte(0x000000, 0xFFFFFF, DefBadWriteByte, NULL);		// <Bad Writes>
   AddWriteByte(-1, -1, NULL, NULL);

   AddWriteWord(0x200000, 0x203FFF, NULL, RAM+0x000000);		// 68000 RAM
   AddWriteWord(0x400000, 0x41FFFF, NULL, RAM_VIDEO);			// SCREEN RAM
   AddWriteWord(0x600000, 0x600FFF, NULL, RAM_COLOUR);			// COLOR RAM
   AddWriteWord(0x800000, 0x800003, tc0220ioc_ww_port, NULL);		// INPUT
   AddWriteWord(0x000000, 0xFFFFFF, DefBadWriteWord, NULL);		// <Bad Writes>
   AddWriteWord(-1, -1, NULL, NULL);

   AddInitMemory();	// Set Starscream mem pointers...
}