The content in this section is relatively simple. It is similar to the content in the previous two sections. I will make a short speech.
Open Super Mario 1, select tool-> viewer-> color disk Viewer
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/193143N06-0.png "title =" Capture. PNG "alt =" 224132897.png"/>
The class related to the color disk viewer is CPaletteView, where the file is located:
Source Files/PaletteView. cpp Header Files/PaletteView. h
The object m_PaletteView of this class is declared in the CMainFrame class.
CPaletteView: Create ()
BOOL CPaletteView::Create( HWND hWndParent ){ HWND hWnd = CreateWindowEx( WS_EX_TOOLWINDOW, VIRTUANES_WNDCLASS, "PaletteView", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWndParent, NULL, CApp::GetInstance(), (LPVOID)this ); if( !hWnd ) { DEBUGOUT( "CreateWindow faild.\n" ); return FALSE; } m_hWnd = hWnd; // ::ZeroMemory( &m_BitmapHdr, sizeof(m_BitmapHdr) ); m_BitmapHdr.bih.biSize = sizeof(BITMAPINFOHEADER); m_BitmapHdr.bih.biWidth = 256; m_BitmapHdr.bih.biHeight = -32; m_BitmapHdr.bih.biPlanes = 1; m_BitmapHdr.bih.biBitCount = 8; m_BitmapHdr.bih.biCompression = BI_RGB; m_BitmapHdr.bih.biClrUsed = 32; DirectDraw.GetPaletteData( m_Palette ); for( INT y = 0; y < 32; y++ ) { for( INT x = 0; x < 256; x++ ) { m_lpPattern[x+y*256] = (y>>4)*0x10+(x>>4); } } return TRUE;}
The color palette displays 32 colors, the Top 16 colors are the background color palette, And the next 16 colors are the genie color palette. One color occupies 16*16 small blocks, so the size of the displayed bitmap is 256*32.
Row 32-36 this dual loop is to fill the 16*16 small square, from left to right, from top to bottom, in order to fill 0, 1, 2, 3... 31 index color. That is, the color of the color palette is displayed in order.
CPaletteView: OnTimer ()
WNDMSG CPaletteView::OnTimer( WNDMSGPARAM ){ if( !Emu.IsRunning() ) return TRUE; for( INT i = 0; i < 16; i++ ) { m_BitmapHdr.rgb[i] = m_Palette[BGPAL[i]]; m_BitmapHdr.rgb[i+16] = m_Palette[SPPAL[i]]; } RECT rc; ::GetClientRect( hWnd, &rc ); HDC hDC = ::GetDC( hWnd ); ::StretchDIBits( hDC, 0, 0, rc.right - rc.left, rc.bottom - rc.top, 0, 0, 256, 32, m_lpPattern, (BITMAPINFO*)&m_BitmapHdr, DIB_RGB_COLORS, SRCCOPY ); ::ReleaseDC( hWnd, hDC ); return TRUE;}
There is nothing to say about this part.
Let me talk something that doesn't matter. Line 5-8 if someone cannot understand it, it is recommended to search "bitmap structure" on the Internet for a better understanding.
Split line ------------------------------------------------------------
This is the end of this blog article.
You can try again later!
First of all, I wish you a happy National Day.
Secondly, my previous blog titled mongoanes. v0.97 source code exploration <3> the scroll viewer was edited and selected as a recommendation blog post ). Thanks for editing!
Of course, I also know that this series of blog posts won't interest many people. The reason is that I am not ashamed to write it ). Secondly, this NES game was a thing of the last century. Now, some people are studying it, mostly because of their feelings. However, I still hope that I can stick to writing it until I fully understand the mysteries of it. To be as interested in NES as I do, and to be able to do anything for myself in the future, let's take a look at it.
This article from the "Three Take Tiger" blog, please be sure to keep this source http://darhx.blog.51cto.com/7920146/1304059