Exemple #1
0
int CShaderInterface::AddShader( const std::string& vertProg, const std::string& pixelProg )
{
	if( vertProg.length() <= 0 || pixelProg.length() <= 0 )
		return INVALID_HANDLE;

	int slot = FindEmptySlot( *m_vShaderResources );
	CShaderObject* fx = new CShaderObject;
	if( !fx->Load( vertProg.c_str(), pixelProg.c_str() ) )
	{
		delete fx;
		return INVALID_HANDLE;
	}

	if( slot != INVALID_HANDLE )
	{
		m_vShaderResources->at( slot ) = fx;
		++m_nShaders;
		return slot;
	}

	else
	{
		m_vShaderResources->push_back( fx );
		++m_nShaders;
		return m_vShaderResources->size() - 1;
	}
}
/******************************************************************************
 * @brief  Add key to the report buffer
 *   Checks the buffer to see if there's space and adds a new key
 *
 * @param keyvalue value of key being added to buffer
 * @return  TRUE_t if added, FALSE_t if buffer full
 *****************************************************************************/
tBool TI_USBKBD_Report_Addkey( key_t keyvalue )
{
    uint8_t s;

    // Run this in case they key is already in buffer
    TI_USBKBD_Report_Removekey(keyvalue);

    // Check if this is a modifier
    if ((keyvalue & 0xF0) == 0xE0)
    {
        Report_buff.Buff[MODIFIER_OFFSET] |= (1<<(keyvalue & 0x0F));
        Report_buff.Update = TRUE_t;
        return TRUE_t;
    }
    else
    {
        // This is an element array
        if (FindEmptySlot(&s) == TRUE_t)
        {
            // Write key in buffer
            Report_buff.Buff[s] = keyvalue;
            // Clear emptyslot bit
            Report_buff.EmptySlots.byte &= ~(1<<s);
            Report_buff.Update = TRUE_t;
            return TRUE_t;
        }
        else
            return FALSE_t;
    }

}
INT_PTR CALLBACK DiskInfoDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	static int slot;
	TFlashHeader *headers, *header;
	uint8_t *buf, *slotbuf, *ptr;
	int i, bufsize, binsize;
	uint8_t diskid[4];

	switch (message)
	{
	case WM_INITDIALOG:
		slot = lParam;
		DisplayDiskInfo(hDlg, slot);
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_ADDEXISTINGSAVEBUTTON:
			return (INT_PTR)TRUE;

		case IDC_ADDBLANKSAVEBUTTON:

			SetWindowText(GetDlgItem(hDlg, IDC_DISKINFO), "Please wait...");
			headers = fdsemu->dev->FlashUtil->GetHeaders();

			//read entire slot
			fdsemu->ReadFlash(slot, &buf, &bufsize);

			//eat up the lead-in
			ptr = buf;
			while (*ptr == 0) {
				ptr++;
			}

			//acquire disk id
			memcpy(diskid, ptr + 17, 4);

			//free slot buffer
			free(buf);

			//create save disk for this game
			CreateSaveDisk(diskid, &buf, &bufsize);
			slotbuf = (uint8_t*)malloc(0x10000);
			memset(slotbuf, 0, 0x10000);
			binsize = gameDoctor_to_bin(slotbuf + 256, buf, 0x10000 - 256);

			//free buf, not needed anymore
			free(buf);

			//find an empty slot
			i = FindEmptySlot();

			//no slots
			if (i == -1) {
				break;
			}

			header = (TFlashHeader*)slotbuf;

			//flags for save disk (type=savedisk, ownerid/nextid is valid
			header->flags = 0x20 | 3;
			header->ownerid = slot;
			header->nextid = slot;
			header->size = MIN(bufsize, 0x10000 - 256);

			fdsemu->WriteFlashRaw(i * 0x10000,slotbuf,0x10000);

			header = &headers[slot];

			//make sure it doesnt already has a save disk
			if ((header->flags & 0x10) == 0) {

				//read entire slot
				fdsemu->ReadFlashRaw(slot * 0x10000, &buf, 0x10000);

				//get pointer to header information
				header = (TFlashHeader*)buf;

				//set save disk flag
				header->flags |= 0x10;

				//set saveid index
				header->saveid = i;

				//erase first disk slot
				fdsemu->dev->Flash->EraseSlot(slot);

				//write data back with changed header
				fdsemu->WriteFlashRaw(slot * 0x10000, buf, 0x10000);

				//free slot buffer
				free(buf);
			}
			fdsemu->dev->FlashUtil->ReadHeaders();
			DisplayDiskInfo(hDlg, slot);

			return (INT_PTR)TRUE;
		case IDC_REMOVESAVEBUTTON:

			SetWindowText(GetDlgItem(hDlg, IDC_DISKINFO), "Please wait...");
			headers = fdsemu->dev->FlashUtil->GetHeaders();
			header = &headers[slot];

			//make sure it already has a save disk
			if (header->flags & 0x10) {

				//read entire slot
				fdsemu->ReadFlashRaw(slot * 0x10000, &buf, 0x10000);

				//get pointer to header information
				header = (TFlashHeader*)buf;

				//clear save disk flag
				header->flags &= ~0x10;

				//erase save disk
				fdsemu->dev->Flash->EraseSlot(header->saveid);

				//clear saveid index
				header->saveid = 0;

				//erase first disk slot
				fdsemu->dev->Flash->EraseSlot(slot);

				//write data back with changed header
				fdsemu->WriteFlashRaw(slot * 0x10000, buf, 0x10000);

				//free slot buffer
				free(buf);

				fdsemu->dev->FlashUtil->ReadHeaders();
				DisplayDiskInfo(hDlg, slot);
			}
			return (INT_PTR)TRUE;

		case IDC_SAVESAVEBUTTON:
			headers = fdsemu->dev->FlashUtil->GetHeaders();
			header = &headers[slot];

			//make sure it already has a save disk
			if (header->flags & 0x10) {
				SaveDiskImage(hDlg, header->saveid);
			}
			return (INT_PTR)TRUE;
		case IDOK:
		case IDCANCEL:
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}