Пример #1
0
		cstring Mapper105::CartSwitches::GetValueName(uint dip,uint value) const
		{
			NST_ASSERT( dip < 2 );

			if (dip == 0)
			{
				NST_ASSERT( value < 16 );

				switch (value)
				{
					case 0x0: return "5.001";
					case 0x1: return "5.316";
					case 0x2: return "5.629";
					case 0x3: return "5.942";
					case 0x4: return "6.254";
					case 0x5: return "6.567";
					case 0x6: return "6.880";
					case 0x7: return "7.193";
					case 0x8: return "7.505";
					case 0x9: return "7.818";
					case 0xA: return "8.131";
					case 0xB: return "8.444";
					case 0xC: return "8.756";
					case 0xD: return "9.070";
					case 0xE: return "9.318";
					case 0xF: return "9.695";

					NST_UNREACHABLE
				}
			}
Пример #2
0
				cstring Standard::CartSwitches::GetValueName(uint dip,uint value) const
				{
					NST_ASSERT( dip < 2 );

					if (dip == 0)
					{
						NST_ASSERT( value < 4 );
						return (value == 0) ? "1" : (value == 1) ? "2" : (value == 2) ? "3" : "4";
					}
					else
					{
						NST_ASSERT( value < 3 );
						return (value == 0) ? "Off" : (value == 1) ? "Controlled" : "On";
					}
				}
		LRESULT CALLBACK Instance::Global::Hooks::CBTProc(const int nCode,const WPARAM wParam,const LPARAM lParam)
		{
			NST_COMPILE_ASSERT( HCBT_CREATEWND >= 0 && HCBT_DESTROYWND >= 0 );

			switch (nCode)
			{
				case HCBT_CREATEWND:

					NST_ASSERT( lParam );

					if (const CREATESTRUCT* const createStruct = reinterpret_cast<const CBT_CREATEWND*>(lParam)->lpcs)
					{
						NST_VERIFY( wParam );
						global.hooks.OnCreate( *createStruct, reinterpret_cast<HWND>(wParam) );
					}

					return 0;

				case HCBT_DESTROYWND:

					NST_VERIFY( wParam );

					if (wParam)
						global.hooks.OnDestroy( reinterpret_cast<HWND>(wParam) );

					return 0;
			}

			return nCode < 0 ? ::CallNextHookEx( global.hooks.handle, nCode, wParam, lParam ) : 0;
		}
		void Instance::Global::Hooks::OnDestroy(HWND const hWnd)
		{
			NST_ASSERT( hWnd );

			Children::Iterator const child = children.Find( hWnd );

			if (child)
			{
				Events::Signal( EVENT_SYSTEM_BUSY );
			}
			else if (window != hWnd)
			{
				return;
			}

			{
				const Events::WindowDestroyParam param = { hWnd };
				Events::Signal( EVENT_WINDOW_DESTROY, &param );
			}

			if (child)
				children.Erase( child );
			else
				window = NULL;
		}
Пример #5
0
			uint AdapterFour::Peek(const uint line)
			{
				NST_ASSERT( line < 2 );

				if (type == Api::Input::ADAPTER_NES)
				{
					const uint index = count[line];

					if (index < 20)
					{
						count[line] += increaser;

						if (index < 16)
						{
							return devices[line + (index < 8 ? 0 : 2)]->Peek( line );
						}
						else if (index >= 18)
						{
							return (index - 18) ^ line;
						}
					}

					return 0;
				}
				else
				{
					return
					(
						(devices[line+0]->Peek( line ) << 0 & 0x1) |
						(devices[line+2]->Peek( line ) << 1 & 0x2)
					);
				}
			}
Пример #6
0
		bool File::Load(const Type type,Vector<byte>& vector,const dword maxsize) const
		{
			NST_ASSERT( maxsize );

			bool matched = true;

			{
				Api::User::FileData file;
				Api::User::fileIoCallback( static_cast<Api::User::File>(type), file );

				if (Api::User::FileData::size_type filesize = file.size())
				{
					if (filesize > maxsize)
					{
						filesize = maxsize;
						matched = false;
					}

					vector.Resize( filesize );
					std::memcpy( vector.Begin(), &file.front(), filesize );
				}
				else
				{
					vector.Destroy();
					return true;
				}
			}

			buffer.Load( vector.Begin(), vector.Size() );

			return matched;
		}
Пример #7
0
		Result Patcher::Test(const Block* const blocks,const uint numBlocks) const
		{
			NST_ASSERT( blocks || !numBlocks );

			if (numBlocks > 1)
			{
				Vector<byte> buffer;

				try
				{
					dword size = 0;

					for (uint i=0; i < numBlocks; ++i)
						size += blocks[i].size;

					buffer.Reserve( size );
				}
				catch (...)
				{
					return RESULT_ERR_OUT_OF_MEMORY;
				}

				for (uint i=0; i < numBlocks; ++i)
					buffer.Append( blocks[i].data, blocks[i].size );

				return Test( buffer.Begin(), buffer.Size() );
			}
			else
			{
				return Test( blocks ? blocks->data : NULL, blocks ? blocks->size : 0 );
			}
		}
Пример #8
0
				uint Standard::CartSwitches::GetValue(uint dip) const
				{
					NST_ASSERT( dip < 2 );

					if (dip == 0)
						return data >> 6;
					else
						return data & DIPSWITCH_NMT;
Пример #9
0
			Device& AdapterTwo::Connect(uint port,Device& device)
			{
				NST_ASSERT( port < 2 );

				Device& old = *devices[port];
				devices[port] = &device;

				return old;
			}
Пример #10
0
			void ListView::ColumnsProxy::Insert(const uint index,wcstring const text) const
			{
				NST_ASSERT( text );

				LVCOLUMN lvColumn;

				lvColumn.mask = LVCF_FMT|LVCF_TEXT;
				lvColumn.fmt = LVCFMT_LEFT;
				lvColumn.pszText = const_cast<wchar_t*>( text );

				ListView_InsertColumn( control, index, &lvColumn );
			}
Пример #11
0
			Saver& Saver::End()
			{
				NST_ASSERT( chunks.Size() > 1 );

				const dword written = chunks.Pop();
				chunks.Back() += 4 + 4 + written;

				stream.Seek( -idword(written + 4) );
				stream.Write32( written );
				stream.Seek( written );

				return *this;
			}
Пример #12
0
			void NotificationHandler::OnNotify(Param& param)
			{
				NST_ASSERT( param.lParam );

				const NMHDR& nmhdr = *reinterpret_cast<const NMHDR*>(param.lParam);

				if (control == nmhdr.idFrom)
				{
					Items::iterator it(items.find( nmhdr.code ));

					if (it != items.end())
						it->second( nmhdr );
				}
			}
		void Configuration::Node::CheckReference(wcstring const key) const
		{
			NST_ASSERT( key );

			if (map.empty())
			{
				if (*key && !referenced)
					Io::Log() << "Configuration: warning, unused/invalid parameter: \"" << key << "\"\r\n";
			}
			else for (Map::const_iterator it(map.begin()), end(map.end()); it != end; ++it)
			{
				it->second.CheckReference( it->first.Ptr() );
			}
		}
Пример #14
0
			void Renderer::FilterNtsc::BlitType(const Input& input,const Output& output,uint phase) const
			{
				NST_ASSERT( phase < 3 );
				
				const uint bgcolor = this->bgColor;
				const Input::Pixel* NST_RESTRICT src = input.pixels;
				Pixel* NST_RESTRICT dst = static_cast<Pixel*>(output.pixels);
				const long pad = output.pitch - (NTSC_WIDTH-7) * sizeof(Pixel);

				phase &= lut.noFieldMerging;

				for (uint y=HEIGHT; y; --y)
				{
					NES_NTSC_BEGIN_ROW( &lut, phase, bgcolor, bgcolor, *src++ );

					for (const Input::Pixel* const end=src+(NTSC_WIDTH/7*3-3); src != end; src += 3, dst += 7)
					{
						NES_NTSC_COLOR_IN( 0, src[0] );
						NES_NTSC_RGB_OUT( 0, dst[0], BITS );
						NES_NTSC_RGB_OUT( 1, dst[1], BITS );

						NES_NTSC_COLOR_IN( 1, src[1] );
						NES_NTSC_RGB_OUT( 2, dst[2], BITS );
						NES_NTSC_RGB_OUT( 3, dst[3], BITS );

						NES_NTSC_COLOR_IN( 2, src[2] );
						NES_NTSC_RGB_OUT( 4, dst[4], BITS );
						NES_NTSC_RGB_OUT( 5, dst[5], BITS );
						NES_NTSC_RGB_OUT( 6, dst[6], BITS );
					}

					NES_NTSC_COLOR_IN( 0, bgcolor );
					NES_NTSC_RGB_OUT( 0, dst[0], BITS );
					NES_NTSC_RGB_OUT( 1, dst[1], BITS );

					NES_NTSC_COLOR_IN( 1, bgcolor );
					NES_NTSC_RGB_OUT( 2, dst[2], BITS );
					NES_NTSC_RGB_OUT( 3, dst[3], BITS );

					NES_NTSC_COLOR_IN( 2, bgcolor );
					NES_NTSC_RGB_OUT( 4, dst[4], BITS );
					NES_NTSC_RGB_OUT( 5, dst[5], BITS );
					NES_NTSC_RGB_OUT( 6, dst[6], BITS );

					dst = reinterpret_cast<Pixel*>(reinterpret_cast<byte*>(dst) + pad);

					phase = (phase + 1) % 3;
				}
			}
Пример #15
0
		cstring DirectSound::Update
		(
			const uint deviceId,
			const uint rate,
			const uint bits,
			const Channels channels,
			const uint latency,
			const Pool pool,
			const bool globalFocus
		)
		{
			NST_ASSERT( deviceId < adapters.list.size() );

			if (device.id != deviceId || !device)
			{
				device.id = deviceId;

				Destroy();

				if (FAILED(::DirectSoundCreate8( &adapters.list[device.id].guid, &device, NULL )))
					return "DirectSoundCreate8()";

				Io::Log() << "DirectSound: creating device #" << device.id << "\r\n";

				device.priority = SUCCEEDED(device->SetCooperativeLevel( device.hWnd, DSSCL_PRIORITY ));
				device.buggy = adapters.list[device.id].buggy;

				if (!device.priority)
				{
					Io::Log() << "DirectSound: warning, IDirectSound8::SetCooperativeLevel( DSSCL_PRIORITY ) failed! Retrying with DSSCL_NORMAL..\r\n";

					if (FAILED(device->SetCooperativeLevel( device.hWnd, DSSCL_NORMAL )))
					{
						device.Release();
						return "IDirectSound8::SetCooperativeLevel()";
					}
				}
			}

			if (cstring errMsg = buffer.Update( **device, device.priority, rate, bits, channels, latency, pool, globalFocus ))
			{
				Destroy();
				return errMsg;
			}

			return NULL;
		}
		void Instance::Global::Hooks::OnCreate(const CREATESTRUCT& createStruct,HWND const hWnd)
		{
			NST_ASSERT( hWnd );

			if (window == createStruct.hwndParent || !window)
			{
				{
					static const wchar_t menuClassName[] = L"#32768"; // documented on MSDN

					enum
					{
						MAX_LENGTH = NST_MAX( sizeof(array(appClassName)) - 1,
                                     NST_MAX( sizeof(array(STATUSCLASSNAME)) - 1, sizeof(array(menuClassName)) - 1 ))
					};

					String::Stack<MAX_LENGTH,wchar_t> name;
					name.ShrinkTo( ::GetClassName( hWnd, name.Ptr(), MAX_LENGTH+1 ) );

					if (name.Equal( menuClassName ) || name.Equal( STATUSCLASSNAME ) || name.Equal( L"IME" ))
						return;

					if (window)
					{
						children.PushBack( hWnd );
						Events::Signal( EVENT_SYSTEM_BUSY );
					}
					else if (name.Equal( appClassName ))
					{
						window = hWnd;
					}
					else
					{
						return;
					}
				}

				const Events::WindowCreateParam param =
				{
					hWnd,
					createStruct.cx > 0 ? createStruct.cx : 0,
					createStruct.cy > 0 ? createStruct.cy : 0
				};

				Events::Signal( EVENT_WINDOW_CREATE, &param );
			}
		}
		void Configuration::Node::Save(Xml::Node node,wcstring const key) const
		{
			NST_ASSERT( node && (!key || *key) );

			if (map.empty())
			{
				if (key)
					node.AddChild( key, string.Ptr() );
			}
			else
			{
				if (key)
					node = node.AddChild( key );

				for (Map::const_iterator it(map.begin()), end(map.end()); it != end; ++it)
					it->second.Save( node, it->first.Ptr() );
			}
		}
		bool Input::Commands::ForcePoll()
		{
			NST_ASSERT( keys.Size() );

			Keys::Iterator it = keys.Begin();
			Keys::ConstIterator const end = keys.End();

			do
			{
				if (it->GetToggle( it->prev ))
				{
					window.PostCommand( it->cmd );
					return true;
				}
			}
			while (++it != end);

			return false;
		}
Пример #19
0
		bool Time::Set(wcstring const path)
		{
			NST_ASSERT( path && *path );

			WIN32_FILE_ATTRIBUTE_DATA data;
			SYSTEMTIME system, local;

			if
			(
				!::GetFileAttributesEx( path, GetFileExInfoStandard, &data ) ||
				!::FileTimeToSystemTime( &data.ftLastWriteTime, &system ) ||
				!::SystemTimeToTzSpecificLocalTime( NULL, &system, &local )
			)
				return false;

			SetLocal( &local );

			return true;
		}
		int Launcher::List::Files::Strings::Find(const GenericString needle) const
		{
			wcstring it = container.Ptr();
			wcstring const end = it + container.Length();
			NST_ASSERT( *(end-1) == '\0' );

			do
			{
				const GenericString string( it );

				if (needle == string)
					return it - container.Ptr();

				it += string.Length() + 1;
			}
			while (it != end);

			return -1;
		}
Пример #21
0
			dword ReadChecksum(const uint type,const uint index,Context::Rom& rom)
			{
				NST_ASSERT( type < 2 && index < 16 );

				for (dword crc=stream.Read32(), i=0; i < 8; ++i)
				{
					uint c = crc >> (i*4) & 0xF;
					rom.crc[i] = (c < 0xA ? '0' + c : 'A' + (c - 0xA) );
				}

				Log() << "Unif: "
                      << (type ? "CHR-ROM " : "PRG-ROM ")
                      << char(index < 10 ? index + '0' : index-10 + 'A')
                      << " CRC: "
                      << rom.crc
                      << NST_LINEBREAK;

				return 4;
			}
Пример #22
0
			void ListView::Item::TextProxy::GetText(Buffer& buffer) const
			{
				NST_ASSERT( buffer.Empty() );

				LVITEM lvItem;
				lvItem.iSubItem = index;

				do
				{
					buffer.Resize( buffer.Length() + BLOCK_SIZE );

					lvItem.cchTextMax = buffer.Length() + 1;
					lvItem.pszText = buffer.Ptr();

					lvItem.cchTextMax = item.control.Send( LVM_GETITEMTEXT, item.index, &lvItem );
				}
				while (*(buffer.Ptr() + buffer.Length()));

				buffer.ShrinkTo( lvItem.cchTextMax );
			}
Пример #23
0
			NES_HOOK(FamilyKeyboard::DataRecorder,Tape)
			{
				for (const qaword next = qaword(cpu.GetCycles()) * multiplier; cycles < next; cycles += clock)
				{
					if (status == PLAYING)
					{
						if (pos < stream.Size())
						{
							const uint data = stream[pos++];

							if (data >= 0x8C)
							{
								in = 0x2;
							}
							else if (data <= 0x74)
							{
								in = 0x0;
							}
						}
						else
						{
							Stop( false );
							break;
						}
					}
					else
					{
						NST_ASSERT( status == RECORDING );

						if (stream.Size() < MAX_LENGTH)
						{
							stream.Append( (out & 0x7) == 0x7 ? 0x90 : 0x70 );
						}
						else
						{
							Stop( false );
							break;
						}
					}
				}
			}
Пример #24
0
				static void WINAPIV Run(void* data)
				{
					const Entry local( *static_cast<Entry*>(data) );

					NST_ASSERT( local.hEnter && local.hExit );

					if (local.priority)
						::SetThreadPriority( ::GetCurrentThread(), local.priority );

					::SetEvent( local.hEnter );

					try
					{
						local.callback( local.terminator );
					}
					catch (...)
					{
					}

					::SetEvent( local.hExit );
				}
Пример #25
0
			dword ReadRom(const uint type,const uint index,dword length,Context::Rom* const roms)
			{
				NST_ASSERT( type < 2 && index < 16 );

				Log() << "Unif: "
                      << (type ? "CHR-ROM " : "PRG-ROM ")
                      << char(index < 10 ? index + '0' : index-10 + 'A')
                      << " size: "
                      << (length / SIZE_1K)
                      << "k" NST_LINEBREAK;

				dword available = 0;

				for (uint i=0; i < 16; ++i)
					available += roms[i].data.Size();

				available = MAX_ROM_SIZE - available;
				NST_VERIFY( length <= available );

				if (length > available)
				{
					roms[index].truncated = length - available;
					length = available;

					Log() << "Unif: warning, "
                          << (type ? "CHR-ROM " : "PRG-ROM ")
                          << char(index < 10 ? index + '0' : index-10 + 'A')
                          << " truncated to: "
                          << (length / SIZE_1K)
                          << "k" NST_LINEBREAK;
				}

				if (length)
				{
					roms[index].data.Set( length );
					stream.Read( roms[index].data.Mem(), length );
				}

				return length;
			}
Пример #26
0
void Datach::Reader::SaveState(State::Saver& state,const dword baseChunk) const
{
    if (Reader::IsTransferring())
    {
        NST_ASSERT( cycles != Cpu::CYCLE_MAX );

        state.Begin( baseChunk );

        state.Begin( AsciiId<'P','T','R'>::V ).Write8( stream - data ).End();
        state.Begin( AsciiId<'D','A','T'>::V ).Compress( data ).End();

        uint next;

        if (cycles > cpu.GetCycles())
            next = (cycles - cpu.GetCycles()) / cpu.GetClock();
        else
            next = 0;

        state.Begin( AsciiId<'C','Y','C'>::V ).Write16( next ).End();

        state.End();
    }
}
Пример #27
0
			Device& AdapterTwo::GetDevice(uint port) const
			{
				NST_ASSERT( port < 2 );
				return *devices[port];
			}
Пример #28
0
			Device& AdapterFour::GetDevice(uint port) const
			{
				NST_ASSERT( port < 4 );
				return *devices[port];
			}
Пример #29
0
			uint AdapterTwo::Peek(uint line)
			{
				NST_ASSERT( line < 2 );
				return devices[line]->Peek( line );
			}
Пример #30
0
				static uint GetLightMap(uint pixel)
				{
					NST_ASSERT( pixel < Video::Screen::PALETTE );
					return lightMap[pixel];
				}