protected override void OnLoad( EventArgs e ) { String exePath = Path.GetDirectoryName( Assembly.GetExecutingAssembly().GetName().CodeBase ); if ( exePath.StartsWith( "file:\\" ) ) exePath = exePath.Substring( 6 ); myCharacterSet = new Texture2D( new Bitmap( exePath + Path.DirectorySeparatorChar + "charset.png" ) ); myDefaultCharSet = new ushort[ 256 ]; for ( int i = 0; i < 127; ++i ) { for ( int w = 0; w < 2; ++w ) { ushort word = 0x0000; for ( int j = 0; j < 16; ++j ) { int x = ( ( i & 0xf ) << 2 ) + ( w << 1 ) + ( j >> 3 ); int y = ( ( i >> 4 ) << 3 ) + ( j & 7 ); if ( myCharacterSet.GetPixel( x, y ).R >= 128 ) word |= (ushort) ( 1 << ( 15 - j ) ); } myDefaultCharSet[ ( i << 1 ) + w ] = word; } } myCharShader = new CharacterShader( myCharacterSet, Width, Height ); myCharMap = new Character[ VideoBufferLength ]; for ( int i = 0; i < VideoBufferLength; ++i ) { myCharMap[ i ] = new Character( Scale ); myCharMap[ i ].Position = new Vector2( ( i % Columns + 2 ) * 4 * Scale, ( i / Columns + 1 ) * 8 * Scale ); myCharMap[ i ].Value = 0x0000; } CPU.MemoryChanged += delegate( object sender, MemoryChangedEventArgs me ) { if ( myDumping ) return; if ( VideoBufferLoc != 0 && me.Location >= VideoBufferLoc && me.Location < VideoBufferLoc + VideoBufferLength ) { int index = me.Location - VideoBufferLoc; myCharMap[ index ].Value = me.Value; } else if ( CharacterSetLoc != 0 && me.Location >= CharacterSetLoc && me.Location < CharacterSetLoc + 256 ) { int index = me.Location - CharacterSetLoc; int x = ( index % 32 ) * 2; int y = ( index / 32 ) * 8; ushort val = me.Value; for ( int i = 0; i < 16; ++i ) { if ( ( ( val >> i ) & 1 ) == 1 ) myCharacterSet.SetPixel( x + 1 - i / 8, y + i % 8, Color.White ); else myCharacterSet.SetPixel( x + 1 - i / 8, y + i % 8, Color.Black ); } } }; Ready = true; }
public virtual void Render( CharacterShader shader ) { if ( VertsChanged ) { myVertices = FindVerts(); VertsChanged = false; } shader.Render( myVertices ); }