Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NNametableEditor.cxx, NNametableEditor::2019::MS_PL::IRQ_crash
- //
- // Required: DirectX SDK 9.0c June
- // Windows Template Library
- //
- // TODO: Undo op in map unit
- // TODO: Nametable rorate, split
- // TODO: PNG Pixel Mapper NES Palette
- // TODO: More GPU Palette Mapper .
- // TODO: Details BUG
- // TODO: Details more.
- // TODO: C++ Dtor
- // TODO: CA65 Assembler Mapper
- #if defined (_MSC_VER)
- # pragma warning(disable:4005)
- #endif
- #include <atlbase.h>
- #include <atlcoll.h>
- #include <atlapp.h>
- #include <atlframe.h>
- #include <atlfile.h>
- #include <atlctrls.h>
- #include <atlctrlw.h>
- #include <atlctrlx.h>
- #include <atlsplit.h>
- #include <atldlgs.h>
- #include <atlscrl.h>
- #include <atlstr.h>
- #include <atlmisc.h>
- #include <atlimage.h>
- #include <d3dx9.h>
- #include <tchar.h>
- #include "resource.h"
- #include <intrin.h>
- // Embedded style list
- #if defined (_M_IX86)
- # pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
- #elif defined (_M_IA64)
- # pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
- #elif defined (_M_X64)
- # pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
- #else
- # pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
- #endif
- #if defined (_MSC_VER) || defined (__ICC) || defined (__INTEL_COMPILER) || defined (__BORLANDC__)
- # define FINLINE __forceinline
- # define SFINLINE static __forceinline
- # define typeof_noref decltype
- #
- # ifndef _WIN64
- # define _X86_32_WIN_INTEL_INLINE_ASM_SPEC
- # endif
- #endif
- #if defined (_DEBUG) || defined (DEBUG)
- # define DEBUG_OUT _tprintf
- #else
- # define DEBUG_OUT(...) ((VOID) 0)
- #endif
- #define PHOTOSHOP_COL_TOGDI16_0(col32)\
- ((WORD)(col32 >> 0 & 0xFF) >> 3) << 0\
- | ((WORD)(col32 >> 8 & 0xFF) >> 3) << 5\
- | ((WORD)(col32 >>16 & 0xFF) >> 3) << 10
- #define PHOTOSHOP_COL_TOGDI16_1(col32)\
- ((WORD)(col32 >> 16 & 0xFF) >> 3) << 0 \
- | ((WORD)(col32 >> 8 & 0xFF) >> 3) << 5\
- | ((WORD)(col32 >>0 & 0xFF) >> 3) << 10
- #define PHOTOSHOP_COL_TOGDI16\
- PHOTOSHOP_COL_TOGDI16_0
- #define CTRL_IN_KEYQUEUE()\
- (:: GetKeyState (VK_LCONTROL) & 0x8000) \
- || (:: GetKeyState (VK_RCONTROL) & 0x8000)
- // < CFileDialogFilter >==================================================
- // Not mine, see .https://www.codeproject.com/articles/3167/webcontrols/
- // License:unknown
- // Author:Rob Caldecott
- // Implementation of the CFileDialogFilter class.
- // Class to support a filter list when using the WTL CFileDialog.
- // Allows a filter string delimited with a pipe to be used (instead of a string
- // delimited with '\0')
- class CFileDialogFilter
- {
- private:
- CString m_strFilter;
- public:
- CFileDialogFilter()
- {
- }
- /// nID The ID of a resource string containing the filter
- CFileDialogFilter(UINT nID)
- {
- SetFilter(nID);
- }
- /// lpsz The filter string
- CFileDialogFilter(LPCTSTR lpsz)
- {
- SetFilter(lpsz);
- }
- ~CFileDialogFilter()
- {
- }
- inline LPCTSTR GetFilter() const { return m_strFilter; }
- inline operator LPCTSTR() const { return m_strFilter; }
- // Set the filter string to use
- // nID - The ID of a resource string containing the filter
- VOID SetFilter(UINT nID)
- {
- if (m_strFilter.LoadString(nID) && !m_strFilter.IsEmpty())
- ModifyString();
- }
- // Set the filter string to use
- // lpsz - The filter string
- VOID SetFilter(LPCTSTR lpsz)
- {
- m_strFilter = lpsz;
- if (!m_strFilter.IsEmpty())
- ModifyString();
- }
- private:
- // Replace '|' with '\0'
- VOID ModifyString(VOID)
- {
- // Get a pointer to the string buffer
- LPTSTR psz = m_strFilter.GetBuffer(0);
- // Replace '|' with '\0'
- while ((psz = _tcschr(psz, _T('|'))) != NULL)
- *psz++ = _T('\0');
- // Release buffer
- m_strFilter.ReleaseBuffer ();
- }
- };
- // < CWindowFT >====================================================
- class CWindowFT : public CWindow {
- public:
- CWindowFT(_In_opt_ HWND hWnd = NULL) throw() :
- CWindow (hWnd)
- {
- }
- int __cdecl SetWindowTextFT (LPCTSTR format, ...) {
- ATLASSERT (::IsWindow (*this));
- CString output;
- va_list va;
- va_start (va, format);
- output.FormatV (format, va);
- ::SetWindowText (this->m_hWnd, output);
- va_end (va);
- return output.GetLength ();
- }
- };
- // < CListViewCtrlTS >====================================================
- template <class T> // (T)emplate (s)elect item for listview.
- class CListViewCtrlTS : public CListViewCtrl {
- public:
- T *GetItemDataT (int index) {
- auto count = GetItemCount ();
- if (index >= 0 && index < count) {
- return reinterpret_cast<T *> (GetItemData (index));
- }
- return NULL;
- }
- T *GetItemSelectedDataT (void) {
- return GetItemDataT (GetSelectedIndex ());
- }
- BOOL SetItemDataT (int index, T *item) {
- auto count = GetItemCount ();
- if (index >= 0 && index < count) {
- SetItemData (index, reinterpret_cast<DWORD_PTR> (item));
- return TRUE;
- }
- return FALSE;
- }
- // XXX:Arg must correct.
- CString GetItemTextAMC (int index, int iSubItem) {
- auto count = GetItemCount ();
- ATLASSERT (index >= 0);
- ATLASSERT (index < count);
- CString buffer;
- auto p = buffer.GetBuffer (MAX_PATH);
- // -----------
- GetItemText (index, iSubItem, p, MAX_PATH);
- CString returnBuffer (p);
- buffer.ReleaseBuffer ();
- return returnBuffer;
- }
- CString GetSelectedItemTextAMC (int iSubItem) {
- return GetItemTextAMC (GetSelectedIndex (), iSubItem);
- }
- };
- // < CByteStream >====================================================
- class CByteStream {
- private:
- INT32 m_BufferCount;
- INT32 m_MaxCount;
- INT32 m_ReadSeek;
- INT32 m_WriteSeek;
- INT32 m_ExpandSize;
- PBYTE m_pBuffer;
- public:
- static const INT32 errors_signal = 0x80000000;
- static const INT32 errors_signal_failed = 0x80000000;
- static const INT32 errors_signal_eof = 0x80000001;
- static const INT32 errors_signal_badalloc = 0x80000002;
- CByteStream (INT32 allocRequset = -1, INT32 expandSize = 32) {
- defaultInit (allocRequset, expandSize);
- }
- ~CByteStream (void) {
- if (m_pBuffer != NULL) {
- // Release buffer
- CCRTAllocator::Free (m_pBuffer);
- }
- }
- void defaultInit (INT32 allocRequset = -1, INT32 ExpandSize = 32) {
- m_ReadSeek =
- m_WriteSeek = 0;
- m_ExpandSize = ExpandSize;
- if (allocRequset < 0) {
- m_MaxCount = 32;
- m_BufferCount = 16;
- } else {
- m_BufferCount = allocRequset;
- m_MaxCount = m_BufferCount + 15 & -16;
- }
- m_pBuffer = static_cast <PBYTE> (CCRTAllocator ::Allocate (m_MaxCount));
- ATLASSERT (m_pBuffer != NULL);
- }
- FINLINE
- INT32 getExpandSize (void) {
- return m_ExpandSize;
- }
- FINLINE
- INT32 setExpandSize (INT32 expandSize) {
- if (expandSize > 0) {
- m_ExpandSize = expandSize;
- return 0;
- } else
- return errors_signal_failed;
- }
- FINLINE
- INT32 getSize (void) {
- return m_BufferCount;
- }
- FINLINE
- INT32 getReadSeek (void) {
- return m_ReadSeek;
- }
- FINLINE
- INT32 getWriteSeek (void) {
- return m_WriteSeek;
- }
- FINLINE
- INT32 setReadSeek (INT32 readSeek = 0) {
- if (readSeek >= m_MaxCount) {
- return errors_signal_failed;
- } else {
- m_ReadSeek = readSeek;
- return 0;
- }
- }
- FINLINE
- INT32 setWriteSeek (INT32 writeSeek = 0) {
- if (writeSeek >= m_MaxCount) {
- return errors_signal_failed;
- } else {
- m_WriteSeek = writeSeek;
- return 0;
- }
- }
- FINLINE
- VOID **getBuffer (INT32 writeSeek = 0) {
- return (VOID **)& m_pBuffer;
- }
- // return read count.
- INT32 read (void *buffer, INT32 count, BOOL bSeekCursor = TRUE) {
- ATLASSERT (buffer != NULL);
- ATLASSERT (count >= 0);
- if (count == 0) {
- return 0;
- }
- if (m_ReadSeek >= m_BufferCount) {
- return errors_signal_eof;
- }
- // focus read pos pointer .
- PBYTE pReadFocus = & m_pBuffer[m_ReadSeek];
- PBYTE pReadBuffer = static_cast<PBYTE> (buffer);
- INT32 readCount = 0;
- while (count > 0 && m_ReadSeek + readCount < m_BufferCount) {
- BYTE value = pReadFocus[readCount];
- pReadBuffer[readCount] = value;
- readCount ++;
- count --;
- }
- // Adjust seek pos.
- if (bSeekCursor != FALSE) {
- m_ReadSeek += readCount;
- }
- return readCount;
- }
- INT32 writeAssert (const void *buffer, INT32 count, BOOL bSeekCursor = TRUE) {
- INT32 sig = write (buffer, count, bSeekCursor);
- ATLASSERT ((sig & CByteStream::errors_signal) == 0);
- return sig;
- }
- // return exec status
- INT32 write (const void *buffer, INT32 count, BOOL bSeekCursor = TRUE) {
- ATLASSERT (buffer != NULL);
- ATLASSERT (count >= 0);
- if (count == 0) {
- return 0;
- }
- if (m_WriteSeek + count > m_MaxCount) {
- // Alloc new buffer .
- const auto allocRequset = m_WriteSeek + count + m_ExpandSize + 31 & -32;
- void *allocHeap = CCRTAllocator::Reallocate (m_pBuffer, allocRequset);
- if (allocHeap == NULL) {
- allocHeap = CCRTAllocator ::Allocate (allocRequset);
- if (allocHeap == NULL) {
- return errors_signal_badalloc;
- }
- if (m_pBuffer != NULL) {
- // Copy content
- RtlCopyMemory (allocHeap, m_pBuffer, m_BufferCount);
- // Release old buffer
- CCRTAllocator::Free (m_pBuffer);
- } else {
- RtlZeroMemory (allocHeap, allocRequset);
- }
- }
- // Attach it
- m_pBuffer = static_cast<PBYTE> (allocHeap);
- m_MaxCount = allocRequset;
- m_BufferCount = m_WriteSeek + count;
- }
- // focus write pos pointer .
- PBYTE pWriteFocus = & m_pBuffer[m_WriteSeek];
- PBYTE pWriteBuffer = static_cast< PBYTE> (const_cast <void *> (buffer));
- INT32 writeCount = 0;
- while (count > 0) {
- PBYTE pValue = & pWriteFocus[writeCount];
- * pValue = pWriteBuffer[writeCount];
- writeCount++;
- count --;
- }
- // Adjust seek pos.
- if (bSeekCursor != FALSE) {
- m_WriteSeek += writeCount;
- }
- return 0;
- }
- INT32 writeDummyAssert (INT32 count, BOOL bSeekCursor = TRUE) {
- INT32 sig = writeDummy (count, bSeekCursor);
- ATLASSERT ((sig & CByteStream::errors_signal) == 0);
- return sig;
- }
- // return exec status
- INT32 writeDummy (INT32 count, BOOL bSeekCursor = TRUE) {
- ATLASSERT (count >= 0);
- if (count == 0) {
- return 0;
- }
- if (m_WriteSeek + count > m_MaxCount) {
- // Alloc new buffer .
- const auto allocRequset = m_WriteSeek + count + m_ExpandSize + 31 & -32;
- void *allocHeap = CCRTAllocator::Reallocate (m_pBuffer, allocRequset);
- if (allocHeap == NULL) {
- allocHeap = CCRTAllocator ::Allocate (allocRequset);
- if (allocHeap == NULL) {
- return errors_signal_badalloc;
- }
- if (m_pBuffer != NULL) {
- // Copy content
- RtlCopyMemory (allocHeap, m_pBuffer, m_BufferCount);
- // Release old buffer
- CCRTAllocator::Free (m_pBuffer);
- } else {
- RtlZeroMemory (allocHeap, allocRequset);
- }
- }
- // Attach it
- m_pBuffer = static_cast<PBYTE> (allocHeap);
- m_MaxCount = allocRequset;
- m_BufferCount = m_WriteSeek + count;
- }
- // Adjust seek pos.
- if (bSeekCursor != FALSE) {
- m_WriteSeek += count;
- }
- return 0;
- }
- INT32 fillExistBufferNoreallocAssert (const void *buffer, INT32 pos, INT32 count) {
- INT32 sig = fillExistBufferNorealloc (buffer, pos, count);
- ATLASSERT ((sig & CByteStream::errors_signal) == 0);
- return sig;
- }
- INT32 fillExistBufferNorealloc (const void *buffer, INT32 pos, INT32 count) {
- if (buffer == NULL
- || pos >= m_BufferCount
- || count < 0)
- return errors_signal_failed;
- else
- {
- auto dst = & (static_cast<PBYTE> (m_pBuffer))[pos];
- auto src = static_cast< PBYTE> (const_cast <void *> (buffer));
- auto readCount = 0;
- auto remain = m_BufferCount - pos;
- while (count > 0 && readCount < remain) {
- BYTE value = src[readCount];
- dst[readCount] = value;
- readCount ++;
- count --;
- }
- return readCount;
- }
- // Never reach here
- ATLASSERT (FALSE);
- return 0;
- }
- };
- #define WTL_WMSG_CALLBACK(MethodName)\
- LRESULT MethodName (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- #define WTL_DMSG_CALLBACK(MethodName)\
- LRESULT MethodName (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
- #define GDI_COL_TO_DRAW16 CGlobals::r32tor15_rev
- #define GDI_COL_TO_DRAW32 CGlobals::r15tor32_rev
- CAppModule _Module;
- union CPolyData64 {
- UINT64 blk;
- INT64 sblk;
- UINT32 blk32[2];
- INT32 sblk32[2];
- UINT16 blk16[4];
- INT16 sblk16[4];
- UINT8 blk8[8];
- INT8 sblk8[8];
- };
- struct CAttr {
- CAttr (VOID) {
- RtlZeroMemory (attr, sizeof (attr));
- comment = _T ("_");
- }
- BYTE attr[64];
- CString comment;
- };
- struct CPal {
- static const BYTE private_palette = 0; // private palette use in nametable/clay
- static const BYTE static_palette = private_palette + 1; // private palette use in whole map/ nametable/clay
- static const BYTE global_palette = static_palette + 1; // global palette use in all map/ nametable/clay
- CPal (BYTE source_ = private_palette):comment (_T ("-")) {
- const BYTE pal_init [] = {
- 0x0F, 0x00, 0x10, 0x30,
- 0x0F, 0x1C, 0x2B, 0x39,
- 0x0F, 0x06, 0x15, 0x36,
- 0x0C, 0x17, 0x28, 0x39 // from yychr's default palette
- };
- RtlCopyMemory (pal, pal_init, sizeof (pal_init));
- source = source_;
- }
- FINLINE
- void sourceAssert (void) {
- ATLASSERT (source == private_palette
- || source == static_palette
- || source == global_palette);
- }
- BYTE source;
- BYTE pal[16];
- CString comment;
- };
- struct CChr {
- BYTE chr[0x1000];
- CString comment;
- };
- struct CUndoMapNode {
- PWORD pTileBufL; // L source
- PBYTE pAttrBufL;
- CPoint ptStartL;
- CSize szCopyL;
- PWORD pTileBufR; // R target, first
- PBYTE pAttrBufR;
- CPoint ptStartR;
- CSize szCopyR;
- CUndoMapNode (void):
- pTileBufL (NULL),
- pAttrBufL (NULL),
- ptStartL (0, 0),
- szCopyL (0, 0),
- pTileBufR (NULL),
- pAttrBufR (NULL),
- ptStartR (0, 0),
- szCopyR (0, 0) {}
- ~CUndoMapNode (void) {
- if (pTileBufL != NULL) {
- CCRTAllocator::Free (pTileBufL);
- }
- if (pAttrBufL != NULL) {
- CCRTAllocator::Free (pAttrBufL);
- }
- if (pTileBufR != NULL) {
- CCRTAllocator::Free (pTileBufR);
- }
- if (pAttrBufR != NULL) {
- CCRTAllocator::Free (pAttrBufR);
- }
- }
- };
- struct CClayUndoNode {
- WORD tileSlot[0x400];
- BYTE attrSlot[0x40];
- CAttr *attr;
- };
- template <BOOL t_bReadWriteMap = FALSE>
- struct CNametableCell {
- WORD tileSlot[0x400]; // 0x8000 is trans pixel.
- CAtlArray <CAttr *> attrList;
- CAtlArray <CPal *> palList;
- CAtlArray <CPal *> &staticPalList; // only nametable use.
- CAtlArray <CPal *> &globalPalList;
- CAtlList <CClayUndoNode *> *undoStack;
- int undoSeek;
- CChr *chr;
- CAttr *attr;
- CPal *pal;
- INT select; // select index, < 0 no select or empty item.
- INT bank; // attr table bank.
- BOOL hackChr;
- BOOL hackAttr;
- BOOL hackPal;
- CString comment;
- struct selPaletteInfos {
- int indexInTotal;
- int indexInCurSource;
- int sizeInCurSource;
- int sizeInTotal;
- CString source; // Global | Static | Local
- CPal *pal;
- CAtlArray <CPal *> *srcPaletteSet;
- selPaletteInfos (void):
- indexInTotal (-1),
- indexInCurSource (-1),
- sizeInCurSource (-1),
- sizeInTotal (-1),
- source (_T ("_")),
- pal (NULL),
- srcPaletteSet (NULL) {}
- };
- // FIXME: adjust attr index in internal.
- void updateCacheToMain (CClayUndoNode *node) {
- ATLASSERT (node != NULL);
- auto specAttr = node->attr;
- // Copy tile id.
- memcpy (tileSlot, node->tileSlot, sizeof (tileSlot));
- // Serach list .
- for (SIZE_T it =0; it != attrList.GetCount (); it++) {
- auto p = attrList[it];
- if (p == specAttr) {
- // Adjust pos.
- // attr = specAttr;
- memcpy (specAttr->attr, node->attrSlot, sizeof (node->attrSlot));
- return ;
- }
- }
- node->attr = NULL;
- }
- // snapshot only for clay windwos.
- PVOID snapshotResume (void) {
- // Next undo list.
- if (undoStack != NULL) {
- auto count = undoStack->GetCount ();
- if (count == 0 || undoSeek == count) {
- return NULL;
- }
- ATLASSERT (undoSeek <= count);
- auto node = undoStack->GetAt (undoStack->FindIndex (undoSeek));
- ATLASSERT (node != NULL);
- undoSeek ++;
- updateCacheToMain (node);
- return node;
- }
- return NULL;
- }
- PVOID snapshotUndo (void) {
- if (undoStack != NULL) {
- auto count = undoStack->GetCount ();
- if (count <= 1 || undoSeek <= 1) {
- return NULL;
- }
- ATLASSERT (undoSeek <= count);
- auto node = undoStack->GetAt (undoStack->FindIndex (undoSeek - 2));
- ATLASSERT (node != NULL);
- undoSeek --;
- updateCacheToMain (node);
- return node;
- }
- return NULL;
- }
- void snapshotToUndoStack (void) {
- if (undoStack != NULL) {
- // For simplicity, put the entire snapshot on the stack at once
- auto newNode = new CClayUndoNode;
- // Copy tile cache.
- memcpy (newNode->tileSlot, tileSlot, sizeof (tileSlot));
- newNode->attr = attr;
- if (attr != NULL) {
- memcpy (newNode->attrSlot, attr->attr, sizeof (attr->attr));
- }
- // Clear undo pos next all node.
- int nodeNums = undoStack->GetCount ();
- if (nodeNums > 0 && undoSeek != nodeNums) {
- // Clear next node.
- auto listPollPos = undoStack->GetHeadPosition ();
- for (int it =0; it != nodeNums; it++) {
- // auto p = undoStack.Get
- auto temp_pos = listPollPos;
- auto p = undoStack->GetNext (listPollPos);
- if (undoSeek == 0 || it >= undoSeek) {
- // Remove it
- undoStack->RemoveAt (temp_pos);
- delete p; // XXX:
- }
- }
- }
- // Add new node.
- undoStack->AddTail (newNode);
- undoSeek ++;
- }
- }
- selPaletteInfos getSelectPal_b (int index) {
- int psize = static_cast <int> ( palList.GetCount ());
- int gsize = static_cast <int> ( globalPalList.GetCount ());
- int ssize ;
- int total ;
- if (t_bReadWriteMap == FALSE) {
- ssize = static_cast <int> ( staticPalList.GetCount ());
- } else {
- ssize = 0;
- }
- total = psize
- + gsize
- + ssize;
- selPaletteInfos refPal;
- refPal.sizeInTotal = total;
- if (index >= 0 && index <= total) {
- refPal.indexInTotal = index;
- if (t_bReadWriteMap == FALSE) {
- if (total != 0 && index < total) {
- if (index < gsize) {
- refPal.indexInCurSource = index;
- refPal.sizeInCurSource = index;
- refPal.source = _T ("Global");
- refPal.pal = globalPalList[index];
- refPal.srcPaletteSet = & globalPalList;
- } else {
- int rvaOffset = index - gsize;
- if (rvaOffset < ssize) {
- refPal.indexInCurSource = index - gsize;
- refPal.sizeInCurSource = ssize;
- refPal.source = _T ("Static");
- refPal.pal = staticPalList[refPal.indexInCurSource];
- refPal.srcPaletteSet = & staticPalList;
- } else {
- refPal.indexInCurSource = index - gsize - ssize;
- refPal.sizeInCurSource = psize;
- refPal.source = _T ("Local");
- refPal.pal = palList[refPal.indexInCurSource];
- refPal.srcPaletteSet = & palList;
- }
- }
- }
- } else {
- if (total != 0 && index < total) {
- if (index < gsize) {
- refPal.indexInCurSource = index;
- refPal.sizeInCurSource = gsize;
- refPal.source = _T ("Global");
- refPal.pal = globalPalList[index];
- refPal.srcPaletteSet = & globalPalList;
- } else {
- refPal.indexInCurSource = index - gsize;
- refPal.sizeInCurSource = psize;
- refPal.source = _T ("Local");
- refPal.pal = palList[refPal.indexInCurSource];
- refPal.srcPaletteSet = & palList;
- }
- }
- }
- }
- return refPal;
- }
- int getSelectPalSourceIndex (void) {
- selPaletteInfos temp = getSelectPal_b (select);
- if (temp.pal != NULL) {
- return temp.pal->source;
- }
- return -1;
- }
- CString getSelectPalSource (void) {
- selPaletteInfos temp = getSelectPal_b (select);
- if (temp.pal != NULL) {
- return temp.source;
- }
- return _T ("Null");
- }
- CPal *removePalette (int index) {
- selPaletteInfos temp = getSelectPal_b (select);
- if (temp.pal != NULL) {
- temp.srcPaletteSet->RemoveAt (temp.indexInCurSource);
- return temp.pal;
- }
- return NULL;
- }
- void setIfEmptySelect0 (void) {
- auto size = getPaletteTotal ();
- if (size == 0) {
- select = -1;
- pal = NULL;
- } else if (pal == NULL) {
- ATLASSERT (select < 0);
- pal = getSelectPal (0);
- select = 0;
- } else {
- // ATLASSERT (select >= 0);
- // Check current spec palette alive??
- for (auto it = 0; it != size; it++) {
- auto pal_temp = getSelectPal (it);
- if (pal == pal_temp) {
- select = it;
- return ;
- }
- }
- // Mismatch select.
- // Check near index
- if (select >= size) {
- select = size - 1;
- }
- pal= getSelectPal (select);
- }
- }
- void readjustPos (void) {
- auto size = getPaletteTotal ();
- if (size == 0) {
- select = -1;
- pal = NULL;
- } else if (pal == NULL) {
- ATLASSERT (select < 0);
- select = -1;
- } else {
- // ATLASSERT (select >= 0);
- // Check current spec palette alive??
- for (auto it = 0; it != size; it++) {
- auto pal_temp = getSelectPal (it);
- if (pal == pal_temp) {
- select = it;
- return ;
- }
- }
- select = -1;
- }
- }
- FINLINE
- BOOL isReadWriteMap (void) {
- return t_bReadWriteMap;
- }
- BOOL setSelectPalette (int sel_index = 0) {
- BOOL sig = FALSE;
- if (sel_index >= 0) {
- auto total = getPaletteTotal ();
- if (total != 0 && sel_index < total) {
- select = sel_index;
- pal = getSelectPal (sel_index);
- ATLASSERT (pal != NULL);
- sig = TRUE;
- }
- }
- return sig;
- }
- SIZE_T getPaletteTotal (void) {
- selPaletteInfos temp = getSelectPal_b (select);
- return static_cast <SIZE_T> ( temp.sizeInTotal);
- }
- INT getSelectPalSourceOffset (void) {
- selPaletteInfos temp = getSelectPal_b (select);
- return static_cast <SIZE_T> ( temp.indexInCurSource);
- }
- CPal *getSelectPal (INT select_) {
- selPaletteInfos temp = getSelectPal_b (select_);
- if (temp.pal != NULL) {
- return temp.pal;
- }
- return NULL;
- }
- CPal *getSelectPal (void) {
- return getSelectPal (select);
- }
- VOID fillId (WORD id) {
- for (auto it = 0; it != 0x400; it++)
- { tileSlot [it] = id;
- }
- }
- ~CNametableCell (void) {
- if (undoStack != NULL) {
- delete undoStack;
- undoStack = NULL;
- }
- // TODO:
- }
- CNametableCell (CAtlArray <CPal *> &static_palList_,
- CAtlArray <CPal *> &global_palList_,
- BOOL bAddDefaultAttr = TRUE) :
- staticPalList (static_palList_),
- globalPalList (global_palList_),
- hackChr (FALSE),
- hackAttr (FALSE),
- hackPal (FALSE),
- undoStack (NULL),
- undoSeek (0),
- chr (NULL), attr (NULL), pal (NULL), bank (0),select (-1) {
- RtlFillMemory (tileSlot, sizeof (tileSlot), 0xFF);
- attrList.RemoveAll ();
- palList.RemoveAll ();
- if (bAddDefaultAttr != FALSE) {
- attr = new CAttr;
- attrList.InsertAt (attrList.GetCount (), attr);
- }
- if (t_bReadWriteMap != FALSE) {
- undoStack = new CAtlList <CClayUndoNode *>;
- }
- }
- // Copt methiod
- VOID Copy (const CNametableCell &cObject) {
- * chr = *cObject.chr;
- attrList.RemoveAll ();
- palList.RemoveAll ();
- for (auto it = 0; it != cObject.attrList.GetCount (); it++) {
- auto p = new CAttr;
- * p = * cObject.attrList[it];
- attrList.InsertAt (attrList.GetCount (), p);
- }
- for (auto it = 0; it != cObject.palList.GetCount (); it++) {
- auto p = new CPal;
- * p = * cObject.palList[it];
- palList.InsertAt (palList.GetCount (), p);
- }
- RtlCopyMemory (tileSlot, cObject.tileSlot, sizeof (tileSlot));
- }
- };
- struct CMapUnit {
- INT height;
- INT width;
- CString comment;
- CAtlArray <CNametableCell<FALSE> *> ntList;
- CAtlArray <CPal *> staticPal;
- CAtlArray <CPal *> &globalPal;
- CAtlArray <CUndoMapNode *> undoStack;
- int undoSeek;
- CMapUnit (CAtlArray <CPal *> &globalPal__):
- globalPal (globalPal__),
- height (0),
- width (0),
- undoSeek (0)
- {}
- #if 0
- // FIXME: adjust attr index in internal.
- void updateCacheToMain (CClayUndoNode *node) {
- ATLASSERT (node != NULL);
- auto specAttr = node->attr;
- // Copy tile id.
- memcpy (tileSlot, node->tileSlot, sizeof (tileSlot));
- // Serach list .
- for (SIZE_T it =0; it != attrList.GetCount (); it++) {
- auto p = attrList[it];
- if (p == specAttr) {
- // Adjust pos.
- // attr = specAttr;
- memcpy (specAttr->attr, node->attrSlot, sizeof (node->attrSlot));
- return ;
- }
- }
- node->attr = NULL;
- }
- // snapshot only for clay windwos.
- PVOID snapshotResume (void) {
- // Next undo list.
- if (undoStack != NULL) {
- auto count = undoStack->GetCount ();
- if (count == 0 || undoSeek == count) {
- return NULL;
- }
- ATLASSERT (undoSeek <= count);
- auto node = undoStack->GetAt (undoStack->FindIndex (undoSeek));
- ATLASSERT (node != NULL);
- undoSeek ++;
- updateCacheToMain (node);
- return node;
- }
- return NULL;
- }
- PVOID snapshotUndo (void) {
- if (undoStack != NULL) {
- auto count = undoStack->GetCount ();
- if (count <= 1 || undoSeek <= 1) {
- return NULL;
- }
- ATLASSERT (undoSeek <= count);
- auto node = undoStack->GetAt (undoStack->FindIndex (undoSeek - 2));
- ATLASSERT (node != NULL);
- undoSeek --;
- updateCacheToMain (node);
- return node;
- }
- return NULL;
- }
- void snapshotToUndoStack (void) {
- if (undoStack != NULL) {
- // For simplicity, put the entire snapshot on the stack at once
- auto newNode = new CClayUndoNode;
- // Copy tile cache.
- memcpy (newNode->tileSlot, tileSlot, sizeof (tileSlot));
- newNode->attr = attr;
- if (attr != NULL) {
- memcpy (newNode->attrSlot, attr->attr, sizeof (attr->attr));
- }
- // Clear undo pos next all node.
- int nodeNums = undoStack->GetCount ();
- if (nodeNums > 0 && undoSeek != nodeNums) {
- // Clear next node.
- auto listPollPos = undoStack->GetHeadPosition ();
- for (int it =0; it != nodeNums; it++) {
- // auto p = undoStack.Get
- auto temp_pos = listPollPos;
- auto p = undoStack->GetNext (listPollPos);
- if (undoSeek == 0 || it >= undoSeek) {
- // Remove it
- undoStack->RemoveAt (temp_pos);
- delete p; // XXX:
- }
- }
- }
- // Add new node.
- undoStack->AddTail (newNode);
- undoSeek ++;
- }
- }
- void snapshotToUndoStack (int xDst, int yDst, int wDst, int hDst,
- int xSrc, int ySrc, int wSrc, int hSrc) {
- if (undoStack != NULL) {
- // For simplicity, put the entire snapshot on the stack at once
- auto newNode = new CClayUndoNode;
- // Copy tile cache.
- memcpy (newNode->tileSlot, tileSlot, sizeof (tileSlot));
- newNode->attr = attr;
- if (attr != NULL) {
- memcpy (newNode->attrSlot, attr->attr, sizeof (attr->attr));
- }
- // Clear undo pos next all node.
- int nodeNums = undoStack->GetCount ();
- if (nodeNums > 0 && undoSeek != nodeNums) {
- // Clear next node.
- auto listPollPos = undoStack->GetHeadPosition ();
- for (int it =0; it != nodeNums; it++) {
- // auto p = undoStack.Get
- auto temp_pos = listPollPos;
- auto p = undoStack->GetNext (listPollPos);
- if (undoSeek == 0 || it >= undoSeek) {
- // Remove it
- undoStack->RemoveAt (temp_pos);
- delete p; // XXX:
- }
- }
- }
- // Add new node.
- undoStack->AddTail (newNode);
- undoSeek ++;
- }
- }
- void snapshotToUndoStack (int x, int y, int w, int h) {
- // For simplicity, put the entire snapshot on the stack at once
- auto newNode = new CClayUndoNode;
- // Copy tile cache.
- memcpy (newNode->tileSlot, tileSlot, sizeof (tileSlot));
- newNode->attr = attr;
- if (attr != NULL) {
- memcpy (newNode->attrSlot, attr->attr, sizeof (attr->attr));
- }
- // Clear undo pos next all node.
- int nodeNums = undoStack->GetCount ();
- if (nodeNums > 0 && undoSeek != nodeNums) {
- // Clear next node.
- auto listPollPos = undoStack->GetHeadPosition ();
- for (int it =0; it != nodeNums; it++) {
- // auto p = undoStack.Get
- auto temp_pos = listPollPos;
- auto p = undoStack->GetNext (listPollPos);
- if (undoSeek == 0 || it >= undoSeek) {
- // Remove it
- undoStack->RemoveAt (temp_pos);
- delete p; // XXX:
- }
- }
- }
- // Add new node.
- undoStack->AddTail (newNode);
- undoSeek ++;
- }
- #endif
- VOID resetMap (SIZE_T req_w, SIZE_T req_h,
- BOOL clear_data = FALSE,
- WORD fill_id = 0x8000)
- {
- if ( (req_w != 0
- && req_h != 0)
- &&
- (height != req_w
- || width != req_h))
- {
- // Adjust size
- if (width == req_h) {
- // Same pitch
- // Only Adjust y vector.
- int rva = req_h - height;
- if (rva >0) {
- // Add vector
- for (auto j = 0; j != rva; j++) {
- for (auto i = 0; i != width; i++) {
- CNametableCell<FALSE> *chunk = new CNametableCell <FALSE> (staticPal, globalPal);
- ntList.InsertAt (ntList.GetCount (), chunk);
- }
- }
- } else {
- // Sub vector
- rva = - rva;
- for (auto j = 0; j != rva; j++) {
- for (auto i = 0; i != width; i++) {
- delete ntList.GetAt (ntList.GetCount () - 1);
- ntList.RemoveAt (ntList.GetCount () - 1);
- }
- }
- }
- } else {
- // new temp mapunit
- CAtlArray <CNametableCell<FALSE> *> ntListTemp;
- ntList.Copy (ntListTemp);
- // Allco new size.
- ntList.SetCount (0);
- for (auto j = 0; j != req_h; j++) {
- for (auto i = 0; i != req_w; i++) {
- auto p = new CNametableCell<FALSE> (staticPal, globalPal);
- ntList.InsertAt (ntList.GetCount (), p);
- // Check is old data???
- if (j < height
- && i < width)
- {
- p->Copy (* ntListTemp[j * width + i]);
- }
- }
- }
- // Release old data
- for (auto it =0; it != ntListTemp.GetCount (); it++) {
- delete ntListTemp[it];
- }
- ntListTemp.RemoveAll ();
- }
- width = req_w;
- height = req_h;
- }
- if (clear_data != FALSE) {
- for (auto it = 0; it != ntList.GetCount (); it++) {
- ntList[it]->fillId (fill_id);
- }
- }
- }
- };
- class CMemoryPaint16 {
- private:
- HGDIOBJ m_PrevBitmap;
- HDC m_MemoryDC;
- PWORD m_SurfacePtr;
- DWORD m_SurfaceWidth;
- DWORD m_SurfaceHeight;
- HWND m_AttachWindow;
- DWORD m_PitchBaseBit;
- DWORD m_Pitch;
- public:
- struct DirectWrite {
- PWORD pBits;
- DWORD Pitch16;
- DWORD Pitch;
- };
- FINLINE
- HDC& getMemoryDC (VOID) {
- return m_MemoryDC;
- }
- CMemoryPaint16 (VOID):
- m_PrevBitmap (NULL),
- m_MemoryDC (NULL),
- m_SurfacePtr (NULL),
- m_SurfaceWidth (0),
- m_SurfaceHeight (0) {}
- ~CMemoryPaint16 (VOID) { destroy (); }
- VOID destroy (VOID) {
- if (m_SurfacePtr!= NULL) {
- m_SurfacePtr = NULL;
- if (m_MemoryDC != NULL) {
- HGDIOBJ prev = SelectObject (m_MemoryDC, m_PrevBitmap);
- DeleteObject (prev);
- DeleteDC (m_MemoryDC);
- }
- }
- }
- VOID fillColor (int x_pos, int y_pos, int width , int height, WORD color) {
- PWORD vptr = & m_SurfacePtr[x_pos+y_pos*m_PitchBaseBit];
- DWORD rva = m_PitchBaseBit - width;
- DWORD wblk_8 = width >> 3;
- DWORD wmod_8 = width & 7;
- DWORD u, v;
- for (u = height; u != 0; u--) { // XXX: height must >= 0
- for (v = wblk_8; v != 0; v--) {
- vptr[0] = color;
- vptr[1] = color;
- vptr[2] = color;
- vptr[3] = color;
- vptr[4] = color;
- vptr[5] = color;
- vptr[6] = color;
- vptr[7] = color;
- vptr += 8;
- }
- for (v = wmod_8; v != 0; v--) {
- *vptr++ = color;
- }
- vptr += rva;
- }
- }
- VOID fillColor (CPoint &pt, CSize &vec, WORD color) {
- return fillColor (pt.x, pt.y, vec.cx, vec.cy, color);
- }
- VOID fillFullClient (WORD color) {
- CRect rcClient;
- :: GetClientRect (m_AttachWindow, & rcClient);
- if (rcClient.Width () > 0
- && rcClient.Height () > 0)
- {
- fillColor (rcClient.TopLeft (), rcClient.Size (), color);
- }
- }
- SFINLINE
- VOID fillColor (const CMemoryPaint16::DirectWrite &dirwrite, int x_pos, int y_pos, int width , int height, WORD color) {
- PWORD vptr = & dirwrite.pBits[x_pos+y_pos*dirwrite.Pitch16];
- DWORD rva = dirwrite.Pitch16 - width;
- DWORD wblk_8 = width >> 3;
- DWORD wmod_8 = width & 7;
- DWORD u, v;
- for (u = height; u != 0; u--) { // XXX: height must >= 0
- for (v = wblk_8; v != 0; v--) {
- vptr[0] = color;
- vptr[1] = color;
- vptr[2] = color;
- vptr[3] = color;
- vptr[4] = color;
- vptr[5] = color;
- vptr[6] = color;
- vptr[7] = color;
- vptr += 8;
- }
- for (v = wmod_8; v != 0; v--) {
- *vptr++ = color;
- }
- vptr += rva;
- }
- }
- SFINLINE
- VOID fillColor (const CMemoryPaint16::DirectWrite &dirwrite, CPoint &pt, CSize &vec, WORD color) {
- return fillColor (dirwrite, pt.x, pt.y, vec.cx, vec.cy, color);
- }
- VOID fillFullClient (const CMemoryPaint16::DirectWrite &dirwrite, WORD color) {
- CRect rcClient;
- :: GetClientRect (m_AttachWindow, & rcClient);
- if (rcClient.Width () > 0
- && rcClient.Height () > 0)
- {
- fillColor (dirwrite, rcClient.TopLeft (), rcClient.Size (), color);
- }
- }
- VOID blit (int dst_x, int dst_y, int src_x, int src_y, int width, int height) {
- HDC dc = GetDC (m_AttachWindow);
- :: BitBlt (dc, dst_x, dst_y, width, height, m_MemoryDC, src_x, src_y, SRCCOPY);
- :: ReleaseDC (m_AttachWindow, dc);
- }
- VOID blit (CPoint &dst, CPoint &src, CSize &vec) {
- blit (dst.x, dst.y, src.x, src.y, vec.cx, vec.cy);
- }
- VOID blitClientBaseALL0 (VOID) {
- CRect rcClient;
- :: GetClientRect (m_AttachWindow, & rcClient);
- if (rcClient.Width () > 0
- && rcClient.Height () > 0)
- {
- blit (CPoint (0, 0), CPoint (0, 0), rcClient.Size ());
- }
- }
- VOID blitStretch (int dst_x, int dst_y, int dst_w, int dst_h, int src_x, int src_y, int src_w, int src_h) {
- HDC dc = GetDC (m_AttachWindow);
- :: StretchBlt (dc, dst_x, dst_y, dst_w, dst_h, m_MemoryDC, src_x, src_y, src_w, src_h, SRCCOPY);
- :: ReleaseDC (m_AttachWindow, dc);
- }
- VOID blitStretch (CPoint &dst_point, CSize &dst_vec, CPoint &src_point, CSize &src_vec) {
- blitStretch (dst_point.x, dst_point.y, dst_vec.cx, dst_vec.cy,
- src_point.x, src_point.y, src_vec.cx, src_vec.cy);
- }
- VOID getBackSurface (DirectWrite &ref) {
- ref.pBits = m_SurfacePtr;
- ref.Pitch = m_Pitch;
- ref.Pitch16 = m_PitchBaseBit;
- }
- BOOL resetMemoryDC (HWND attachWindow) {
- CRect rcClient;
- ::GetClientRect (attachWindow, & rcClient);
- return resetMemoryDC (attachWindow, rcClient.Width (), rcClient.Height ());
- }
- BOOL resetMemoryDC (HWND attachWindow, int backSurfaceWidth, int backSurfaceHeight) {
- ATLASSERT (attachWindow != NULL);
- if (backSurfaceWidth <= 0) {
- backSurfaceWidth = GetSystemMetrics(SM_CXFULLSCREEN) + 32;
- }
- if (backSurfaceHeight <= 0) {
- backSurfaceHeight = GetSystemMetrics(SM_CYFULLSCREEN) + 32;
- }
- ATLASSERT (backSurfaceWidth > 0);
- ATLASSERT (backSurfaceHeight > 0);
- auto Pitch = backSurfaceWidth + 31 & -32;
- HDC dc = GetDC (attachWindow);
- HDC mdc = CreateCompatibleDC (dc);
- ATLASSERT (dc != NULL);
- ATLASSERT (mdc != NULL);
- BITMAPINFO bmpinfos;
- RtlZeroMemory (& bmpinfos, sizeof (bmpinfos));
- bmpinfos.bmiHeader.biSize = sizeof (bmpinfos);
- bmpinfos.bmiHeader.biWidth = Pitch;
- bmpinfos.bmiHeader.biHeight = -(backSurfaceHeight + 32); // see https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx
- bmpinfos.bmiHeader.biPlanes = 1;
- bmpinfos.bmiHeader.biBitCount = 16;
- bmpinfos.bmiHeader.biCompression = BI_RGB;
- PVOID pDIB;
- HBITMAP bitmap = :: CreateDIBSection (mdc, & bmpinfos,
- DIB_RGB_COLORS, (VOID* *)& pDIB, NULL, 0);
- ATLASSERT (bitmap != NULL);
- HGDIOBJ GdiObj = SelectObject (mdc, bitmap);
- ATLASSERT (GdiObj != NULL && (GdiObj != HGDI_ERROR));
- BOOL sig = ReleaseDC (attachWindow, dc);
- ATLASSERT (sig != FALSE);
- m_PrevBitmap = GdiObj;
- m_MemoryDC = mdc;
- m_SurfacePtr = (PWORD) pDIB;
- m_SurfaceWidth = backSurfaceWidth;
- m_SurfaceHeight = backSurfaceHeight;
- m_AttachWindow = attachWindow;
- m_PitchBaseBit = Pitch;
- m_Pitch = Pitch << 1;
- return TRUE;
- }
- };
- namespace CGlobals {
- CString getLastErrorString (void) {
- CString error_string;
- HRESULT error_code = AtlHresultFromLastError ();
- LPTSTR pszMsg = NULL;
- ::FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_code, 0, (LPTSTR)&pszMsg, 0, NULL);
- error_string.Format (_T("Error code: 0x%x - %s"), error_code, pszMsg);
- ::LocalFree(pszMsg);
- return error_string;
- }
- static WORD virtuanes[64];
- static WORD nesterj[64];
- static WORD nestopia[64];
- static WORD fceux[64];
- static PWORD nespal;
- static UINT64 chrmixer[256];
- // NES Final Fansty Font.
- // From The VG Resource web.
- static WORD attrFont0_x2[256]; // 16x16
- static WORD attrFont1_x2[256]; // 16x16
- static WORD attrFont2_x2[256]; // 16x16
- static WORD attrFont3_x2[256]; // 16x16
- struct TilePaste {
- WORD tileSlot[0x400];
- BYTE attrSlot[64];
- BYTE palSlot[16];
- CSize copySize;
- BOOL lock;
- CChr *chr;
- BOOL hackChr;
- BOOL hackPal;
- BOOL hackAttr;
- };
- static TilePaste pasteTile;
- static CChr *pasteChr;
- static CAttr *pasteAttr;
- static CPal *pastePal;
- SFINLINE
- BYTE getAttrBit (PBYTE attrBuffer, BYTE x, BYTE y) {
- auto xslot = x >> 2;
- auto yslot = y >> 2;
- auto attrbit = attrBuffer[(yslot << 3) + xslot];
- auto shift = (y & 2) << 1 | x & 2;
- return attrbit >> shift & 3;
- }
- SFINLINE
- VOID setAttrBit (PBYTE attrBuffer, BYTE x, BYTE y, BYTE bit) {
- auto setbit = bit & 3;
- auto xslot = x >> 2;
- auto yslot = y >> 2;
- auto &attrbit = attrBuffer[(yslot << 3) + xslot];
- auto shift = (y & 2) << 1 | x & 2;
- attrbit &= ~(3 << shift);
- attrbit |= setbit << shift;
- }
- SFINLINE
- BOOL pasteAlive (VOID) {
- return pasteTile.lock != FALSE
- && pasteTile.copySize.cx > 0
- && pasteTile.copySize.cy > 0
- && pasteTile.chr != NULL;
- }
- SFINLINE
- VOID makePasteDead (VOID) {
- pasteTile.lock = FALSE;
- pasteTile.copySize.cx = 0;
- pasteTile.copySize.cy = 0;
- pasteTile.chr = NULL;
- }
- SFINLINE
- VOID setDefaultListViewColor (CListViewCtrl &ctrl) {
- ctrl.SetBkColor (0);
- ctrl.SetTextBkColor (0);
- ctrl.SetTextColor (0xff00);
- }
- static
- VOID lockPaste (PWORD tileSlot, /* base 0, no offset */
- CPoint &ptCopyStart_,
- CSize ©Size_,
- CSize &maxRange_,
- BOOL hackChr = FALSE,
- CChr *chr = NULL,
- BOOL hackPal = FALSE,
- PBYTE palSlot = NULL,
- BOOL hackAttr = FALSE,
- PBYTE attrSlot = NULL/* base 0, no offset */)
- {
- if (copySize_.cx >= 0
- && copySize_.cy >= 0
- && chr != NULL)
- {
- pasteTile.lock = TRUE;
- pasteTile.hackChr = hackChr &&chr != NULL ;
- pasteTile.hackPal = hackPal != FALSE && palSlot != NULL;
- pasteTile.hackAttr = hackAttr != FALSE && attrSlot != NULL;
- pasteTile.copySize = copySize_;
- BYTE palT[] = {
- 0x0F, 0x00, 0x10, 0x30,
- 0x0F, 0x1C, 0x2B, 0x39,
- 0x0F, 0x06, 0x15, 0x36,
- 0x0F, 0x17, 0x28, 0x39
- };
- RtlCopyMemory (pasteTile.palSlot, palT, sizeof (pasteTile.palSlot));
- RtlZeroMemory (pasteTile.attrSlot, sizeof (pasteTile.attrSlot));
- RtlFillMemory (pasteTile.tileSlot, sizeof (pasteTile.tileSlot), 0x80);
- if (ptCopyStart_.x + pasteTile.copySize.cx > maxRange_.cx)
- pasteTile.copySize.cx = maxRange_.cx - ptCopyStart_.x ;
- if (ptCopyStart_.y + pasteTile.copySize.cy > maxRange_.cy)
- pasteTile.copySize.cy = maxRange_.cy - ptCopyStart_.y ;
- // Copy tile id.
- for (auto y = 0; y != pasteTile.copySize.cy; y++) {
- const auto y_src = y + ptCopyStart_.y;
- for (auto x = 0; x != pasteTile.copySize.cx; x++) {
- const auto x_src = x + ptCopyStart_.x;
- const auto pos = y*32+x;
- const auto dst_pos = y_src*32+x_src;
- if (tileSlot != NULL)
- pasteTile.tileSlot[pos] = tileSlot[dst_pos];
- }
- }
- // Copy palette
- if (pasteTile.hackPal != FALSE) {
- RtlCopyMemory (pasteTile.palSlot, palSlot, sizeof (pasteTile.palSlot));
- pasteTile.palSlot[12] =
- pasteTile.palSlot[8] =
- pasteTile.palSlot[4] =
- pasteTile.palSlot[0];
- }
- if (pasteTile.hackAttr != FALSE) {
- // Copy attr table
- for (auto y = 0; y != pasteTile.copySize.cy; y++) {
- const auto y_src = y + ptCopyStart_.y;
- for (auto x = 0; x != pasteTile.copySize.cx; x++) {
- const auto x_src = x + ptCopyStart_.x;
- setAttrBit (pasteTile.attrSlot, x, y,
- getAttrBit (attrSlot, x_src, y_src));
- }
- }
- }
- pasteTile.chr = chr;
- }
- }
- template <typename T>
- static VOID adjustCommentUnique (CAtlArray<T *> &list, T *add_ptr, BOOL bPushtolist = TRUE) {
- for (int it = 0; it != list.GetCount (); it++) {
- T *ptr = list[it];
- if (ptr->comment == add_ptr->comment
- && ptr != add_ptr) {
- add_ptr->comment += _T ("_");
- it = 0;
- }
- }
- if (bPushtolist != FALSE) {
- list.InsertAt (list.GetCount (), add_ptr);
- }
- }
- enum GridType {
- GRID_TYPE_FIXED = 0,
- GRID_TYPE_INTERLACING
- };
- SFINLINE
- VOID limitPoint (CPoint &point, LONG x_lim, LONG y_lim) {
- if (point.x < 0)
- point.x = 0;
- if (point.x >= x_lim)
- point.x = x_lim - 1;
- if (point.y < 0)
- point.y = 0;
- if (point.y >= y_lim)
- point.y = y_lim - 1;
- }
- SFINLINE
- VOID dividerLimitPoint (CPoint &point, int div_x, int div_y, LONG x_lim, LONG y_lim) {
- if (div_x != 0)
- point.x /= div_x;
- else
- point.x = 0;
- if (div_y != 0)
- point.y /= div_y;
- else
- point.y = 0;
- if (point.x < 0)
- point.x = 0;
- if (point.x >= x_lim)
- point.x = x_lim - 1;
- if (point.y < 0)
- point.y = 0;
- if (point.y >= y_lim)
- point.y = y_lim - 1;
- }
- SFINLINE
- VOID limitSize (CSize &size, LONG x_lim, LONG y_lim) {
- if (size.cx < 0)
- size.cx = 0;
- if (size.cx >= x_lim)
- size.cx = x_lim - 1;
- if (size.cy < 0)
- size.cy = 0;
- if (size.cy >= y_lim)
- size.cy = y_lim - 1;
- }
- SFINLINE
- VOID translateVecPointToltrb (CPoint &lefttop, CPoint &rightbottom) {
- if (lefttop.x < 0)
- lefttop.x = 0;
- if (lefttop.y < 0)
- lefttop.y = 0;
- if (rightbottom.x < 0)
- rightbottom.x = 0;
- if (rightbottom.y < 0)
- rightbottom.y = 0;
- if (lefttop.x >=rightbottom.x) {
- auto t = lefttop.x;
- lefttop.x = rightbottom.x;
- rightbottom.x = t;
- }
- if (lefttop.y >= rightbottom.y) {
- auto t = lefttop.y;
- lefttop.y = rightbottom.y;
- rightbottom.y = t;
- }
- }
- SFINLINE
- VOID translateVecPointToltrbLimitRange (CPoint &lefttop, CPoint &rightbottom, CSize range) {
- if (lefttop.x < 0)
- lefttop.x = 0;
- if (lefttop.y < 0)
- lefttop.y = 0;
- if (rightbottom.x < 0)
- rightbottom.x = 0;
- if (rightbottom.y < 0)
- rightbottom.y = 0;
- if (lefttop.x >=rightbottom.x) {
- auto t = lefttop.x;
- lefttop.x = rightbottom.x;
- rightbottom.x = t;
- }
- if (lefttop.y >= rightbottom.y) {
- auto t = lefttop.y;
- lefttop.y = rightbottom.y;
- rightbottom.y = t;
- }
- if (rightbottom.x - lefttop.x > range.cx)
- rightbottom.x = lefttop.x + range.cx ;
- if (rightbottom.y - lefttop.y > range.cy)
- rightbottom.y = lefttop.y + range.cy;
- }
- SFINLINE
- WORD r32tor15 (DWORD color) {
- BYTE c = color >> 0 & 0xFF;
- BYTE v = color >> 8 & 0xFF;
- BYTE b = color >>16 & 0xFF;
- c >>= 3;
- v >>= 3;
- b >>= 3;
- return c | v << 5 | b << 10;
- }
- SFINLINE
- WORD r32tor15_rev (DWORD color) {
- BYTE c = color >> 0 & 0xFF;
- BYTE v = color >> 8 & 0xFF;
- BYTE b = color >>16 & 0xFF;
- c >>= 3;
- v >>= 3;
- b >>= 3;
- return b | v << 5 | c << 10;
- }
- SFINLINE
- DWORD r15tor32_rev (WORD color) {
- BYTE c = color >> 0 & 0x1F;
- BYTE v = color >> 5 & 0x1F;
- BYTE b = color >>10 & 0x1F;
- c <<= 3;
- v <<= 3;
- b <<= 3;
- return b | v << 8 | c << 16;
- }
- SFINLINE
- WORD r15_rev (WORD color) {
- BYTE c = color >> 0 & 0x1F;
- BYTE v = color >> 5 & 0x1F;
- BYTE b = color >>10 & 0x1F;
- return b | v << 5 | c << 10;
- }
- SFINLINE
- WORD alpha16 (WORD tilePixel, WORD backdrop, WORD coeff1, WORD coeff2) {
- DWORD u_out;
- DWORD v_out;
- DWORD out;
- u_out = tilePixel | tilePixel << 16;
- u_out&= 0x3E07C1F;
- u_out*= coeff1;
- v_out = backdrop | backdrop << 16;
- v_out&= 0x3E07C1F;
- v_out*= coeff2;
- /* 0000 0011 1110 0000 0111 1100 0001 1111*/
- out = v_out +u_out >> 4;
- /* Check pixel saturation */
- #if 0
- if (out & 0x20)
- out |= 0x1F; /* mod:1 */
- if (out & 0x8000)
- out |= 0x7C00;/* mod:4 */
- if (out & 0x4000000)/* mod:2 */
- out |= 0x3E00000;
- #else
- out |= 0x4008020 - (out >> 5 & 0x200401);
- #endif
- out&= 0x3E07C1F;
- return out | out >> 16;
- }
- static VOID alphaClr (CMemoryPaint16::DirectWrite &dwrite,
- WORD color ,
- WORD colorAlphaCnt,
- CPoint &ptStart,
- CSize &scanLen)
- {
- const DWORD pitch_x = scanLen.cx;
- PWORD vptr_y = & dwrite.pBits[ptStart.x + ptStart.y*dwrite.Pitch16];
- for (DWORD j = 0; j != scanLen.cy; j++) {
- for (DWORD i = 0; i != scanLen.cx; i++) {
- vptr_y[i] = CGlobals::alpha16 (vptr_y[i], color, 15 - colorAlphaCnt, colorAlphaCnt);;
- }
- vptr_y += dwrite.Pitch16;
- }
- }
- static VOID drawGrid (CMemoryPaint16::DirectWrite &dwrite,
- GridType gtype,
- CPoint &ptStart,
- CSize &elemVec,
- CSize &scanLen,
- WORD color)
- {
- const DWORD pitch_y = elemVec.cy * dwrite.Pitch16;
- const DWORD pitch_x = elemVec.cx;
- PWORD vptr_y = & dwrite.pBits[ptStart.x + ptStart.y*dwrite.Pitch16];
- PWORD vptr_y2 = vptr_y;
- if(gtype == GRID_TYPE_FIXED) {
- for (DWORD j = 0; j != scanLen.cy; j++) {
- PWORD vptr_yt = vptr_y;
- PWORD vptr_x = vptr_yt;
- for (DWORD i = 0; i != scanLen.cx; i++) {
- PWORD vptr_v = vptr_x;
- PWORD vptr_v2 = vptr_x;
- for (DWORD x = 0; x != elemVec.cx; x++) {
- vptr_v[x] = color;
- }
- for (DWORD x = 0; x != elemVec.cy; x++) {
- vptr_v2[0] = color;
- vptr_v2 += dwrite.Pitch16;
- }
- vptr_x += pitch_x;
- }
- vptr_y += pitch_y;
- }
- // draw final
- PWORD vptr_t = & vptr_y2[elemVec.cy * scanLen.cy * dwrite.Pitch16];
- DWORD vec = elemVec.cx * scanLen.cx + 1;
- for (DWORD it = 0; it != vec; it++) {
- vptr_t[it] = color;
- }
- vptr_t = & vptr_y2[elemVec.cx * scanLen.cx];
- vec = elemVec.cy * scanLen.cy + 1;
- for (DWORD it = 0; it != vec; it++) {
- vptr_t[0] = color;
- vptr_t += dwrite.Pitch16;
- }
- } else if (gtype == GRID_TYPE_INTERLACING) {
- for (DWORD j = 0; j != scanLen.cy; j++) {
- PWORD vptr_yt = vptr_y;
- PWORD vptr_x = vptr_yt;
- for (DWORD i = 0; i != scanLen.cx; i++) {
- PWORD vptr_v = vptr_x;
- PWORD vptr_v2 = vptr_x;
- for (DWORD x = 0; x != elemVec.cx; x++) {
- if (x & 1)
- vptr_v[x] = color;
- }
- for (DWORD x = 0; x != elemVec.cy; x++) {
- if (x & 1)
- vptr_v2[0] = color;
- vptr_v2 += dwrite.Pitch16;
- }
- vptr_x += pitch_x;
- }
- vptr_y += pitch_y;
- }
- PWORD vptr_t = & vptr_y2[elemVec.cy * scanLen.cy * dwrite.Pitch16];
- DWORD vec = elemVec.cx * scanLen.cx + 1;
- for (DWORD it = 0; it != vec; it++) {
- if (it & 1)
- vptr_t[it] = color;
- }
- vptr_t = & vptr_y2[elemVec.cx * scanLen.cx];
- vec = elemVec.cy * scanLen.cy + 1;
- for (DWORD it = 0; it != vec; it++) {
- if (it & 1)
- vptr_t[it] = color;
- vptr_t += dwrite.Pitch16;
- }
- }
- }
- static VOID loadFontPixel (LPDIRECT3DDEVICE9 device) {
- LPDIRECT3DTEXTURE9 texture;
- HRESULT sig;
- D3DLOCKED_RECT lockrect;
- RtlZeroMemory (attrFont0_x2, sizeof (attrFont0_x2));
- RtlZeroMemory (attrFont1_x2, sizeof (attrFont1_x2));
- RtlZeroMemory (attrFont2_x2, sizeof (attrFont2_x2));
- RtlZeroMemory (attrFont3_x2, sizeof (attrFont3_x2));
- sig = D3DXCreateTextureFromResourceEx (device,
- ModuleHelper::GetResourceInstance (),
- MAKEINTRESOURCE (IDB_ATTRFONT),
- 64,
- 16,
- D3DX_DEFAULT,
- 0,
- D3DFMT_UNKNOWN,
- D3DPOOL_MANAGED,
- D3DX_DEFAULT,
- D3DX_DEFAULT,
- 0,
- NULL,
- NULL, & texture);
- ATLASSERT (SUCCEEDED (sig));
- // Make font infos.
- sig = texture->LockRect (0, & lockrect, NULL, D3DLOCK_READONLY);
- ATLASSERT (SUCCEEDED (sig));
- PDWORD lockrect_v = (PDWORD) lockrect.pBits;
- DWORD lockrect_p = lockrect.Pitch >> 2;
- for (auto i = 0; i != 16; i++) {
- auto v = & lockrect_v[i*lockrect_p];
- auto y = i << 4;
- for (auto j = 0; j != 16; j++) {
- attrFont0_x2[y+j] = r32tor15 ( v[j]);
- attrFont1_x2[y+j] = r32tor15 ( v[j+16]);
- attrFont2_x2[y+j] = r32tor15 ( v[j+32]);
- attrFont3_x2[y+j] = r32tor15 ( v[j+48]);
- }
- }
- texture->UnlockRect (0);
- texture->Release ();
- texture = NULL;
- }
- static VOID globalInit (VOID) {
- // init global nes palette
- static DWORD virtuaNESPal[] = {
- 0x007F7F7F,0x002000B0,0x002800B8,0x006010A0,
- 0x00982078,0x00B01030,0x00A03000,0x00784000,
- 0x00485800,0x00386800,0x00386C00,0x00306040,
- 0x00305080,0x00000000,0x00000000,0x00000000,
- 0x00BCBCBC,0x004060F8,0x004040FF,0x009040F0,
- 0x00D840C0,0x00D84060,0x00E05000,0x00C07000,
- 0x00888800,0x0050A000,0x0048A810,0x0048A068,
- 0x004090C0,0x00000000,0x00000000,0x00000000,
- 0x00FFFFFF,0x0060A0FF,0x005080FF,0x00A070FF,
- 0x00F060FF,0x00FF60B0,0x00FF7830,0x00FFA000,
- 0x00E8D020,0x0098E800,0x0070F040,0x0070E090,
- 0x0060D0E0,0x00606060,0x00000000,0x00000000,
- 0x00FFFFFF,0x0090D0FF,0x00A0B8FF,0x00C0B0FF,
- 0x00E0B0FF,0x00FFB8E8,0x00FFC8B8,0x00FFD8A0,
- 0x00FFF090,0x00C8F080,0x00A0F0A0,0x00A0FFC8,
- 0x00A0FFF0,0x00A0A0A0,0x00000000,0x00000000
- };
- static DWORD nesterjPal[] = {
- 0x00757575,0x00271B8F,0x000000AB,0x0047009F,
- 0x008F0077,0x00AB0013,0x00A70000,0x007F0B00,
- 0x00432F00,0x00004700,0x00005100,0x00003F17,
- 0x001B3F5F,0x00000000,0x00050505,0x00050505,
- 0x00BCBCBC,0x000073EF,0x00233BEF,0x008300F3,
- 0x00BF00BF,0x00E7005B,0x00DB2B00,0x00CD4F0F,
- 0x008B7300,0x00009700,0x0000AB00,0x0000933B,
- 0x0000838B,0x00111111,0x00090909,0x00090909,
- 0x00FFFFFF,0x003FBFFF,0x005F97FF,0x00A78BFD,
- 0x00F77BFF,0x00FF77B7,0x00FF7763,0x00FF9B3B,
- 0x00F3BF3F,0x0083D313,0x004FDF4B,0x0058F898,
- 0x0000EBDB,0x00666666,0x000D0D0D,0x000D0D0D,
- 0x00FFFFFF,0x00ABE7FF,0x00C7D7FF,0x00D7CBFF,
- 0x00FFC7FF,0x00FFC7DB,0x00FFBFB3,0x00FFDBAB,
- 0x00FFE7A3,0x00E3FFA3,0x00ABF3BF,0x00B3FFCF,
- 0x009FFFF3,0x00DDDDDD,0x00111111,0x00111111
- };
- for (auto It = 0; It != 64; It++) {
- virtuanes[It] = r32tor15 (virtuaNESPal[It]);
- nesterj[It] = r32tor15 (nesterjPal[It]);
- }
- nespal = virtuanes;
- // Make chr mixer ;
- for (WORD It = 0; It != 256; It++) {
- CPolyData64 cpd64;
- cpd64.blk8[0] = It >> 7 & 1;
- cpd64.blk8[1] = It >> 6 & 1;
- cpd64.blk8[2] = It >> 5 & 1;
- cpd64.blk8[3] = It >> 4 & 1;
- cpd64.blk8[4] = It >> 3 & 1;
- cpd64.blk8[5] = It >> 2 & 1;
- cpd64.blk8[6] = It >> 1 & 1;
- cpd64.blk8[7] = It >> 0 & 1;
- chrmixer[It] = cpd64.blk;
- }
- pasteChr = NULL;
- pasteAttr = NULL;
- pastePal = NULL;
- }
- static
- DWORD crc32_intel (DWORD init_crc, void *buffer, int len) {
- auto crc_calc = init_crc;
- if (len > 0) {
- auto crc_block4 = len >> 4;
- auto crc_block1 = len & 15;
- auto crc_ptr = (DWORD *) buffer;
- // calc align buffer
- for (auto it = 0; it != crc_block4; it++) {
- crc_calc =
- _mm_crc32_u32
- ( _mm_crc32_u32
- ( _mm_crc32_u32
- ( _mm_crc32_u32 (crc_calc,
- crc_ptr[0])
- , crc_ptr[1])
- , crc_ptr[2])
- , crc_ptr[3]);
- crc_ptr += 4;
- }
- // calc remain
- auto crc_ptr8 = (BYTE *)crc_ptr;
- for (auto it = 0; it != crc_block1; it++) {
- crc_calc = _mm_crc32_u8 (crc_calc, crc_ptr8[it]);
- }
- }
- return crc_calc;
- }
- };
- class CMainFrame : public CFrameWindowImpl<CMainFrame>
- , public CMessageFilter
- , public CIdleHandler
- {
- class CValidateALL {
- BOOL m_bValidateMain;
- HWND m_window;
- BOOL m_FlushFrame;
- CMainFrame &m_frame;
- public:
- void operator=(BOOL bFlushFrame)
- {
- m_FlushFrame = !! bFlushFrame;
- }
- void setMainValidateStatus(BOOL bValidateMain)
- {
- m_bValidateMain = !! bValidateMain;
- }
- CValidateALL (CMainFrame &hostFrame, HWND window, BOOL bFlushFrame = TRUE, BOOL bValidateMain = TRUE):
- m_FlushFrame (bFlushFrame),
- m_frame (hostFrame),
- m_bValidateMain (bValidateMain),
- m_window (window)
- {
- }
- ~CValidateALL (VOID)
- {
- if (m_FlushFrame != FALSE)
- {
- m_frame.allViewUpdate ();
- }
- if (m_window != NULL
- && m_bValidateMain != FALSE)
- {
- :: ValidateRect (m_window, NULL);
- }
- }
- };
- struct CNNEFile {
- CNNEFile (void) {
- // Same as namespace
- // Does not contain actual code and memory space
- ATLASSERT (FALSE);
- }
- // nne files 0123456789ABCDEF
- // magic number - moecmks nes-nne:char
- // files crc32 without header : dword (use _mm_crc32_u8)
- //
- // chr-chain section offset | chr number : dword | dword
- // gloabl-palette-chain section offset | palette number : dword | dword
- // clay-chain section offset| clay number : dword | dword
- // map-chain section offset | map number : dword | dword
- //
- // chr-pixel- pool section offset :dword -> per elem 4K bytes
- // attr table- pool section offset :dword -> per elem 64 bytes
- // palette- pool section offset :dword -> per elem 16 bytes
- // nametable/clay-pool section offset : dword -> per elem 2K bytes 32x32 tile word
- // string-pool section offset : dword
- //
- // gloabl-palette-chain section >========================================
- // array : comment length | offset :qword + index : qword
- // chr-chain section >========================================
- // array : comment length | offset :qword + index : qword
- // clay-chain section >=======================================
- // header -> elem offset array
- //
- // elem -> comment length | offset : qword
- // -> chr-index : qword
- // -> nametable/clay-pool index : dword
- // -> attr-count : dword
- // -> palette-count : dword
- // -> attr-select : dword (DWORD_MAX := empty)
- // -> palette-select : dword (DWORD_MAX := empty)
- // -> attr chunk set
- // |
- // -> comment length | offset : qword
- // -> attr index
- // -> pal chunk set
- // |
- // -> comment length | offset : qword
- // -> pal index
- //
- // map-chain section >=======================================
- // header -> elem offset array
- //
- // elem -> comment length | offset : qword
- // -> width : dword
- // -> height : dword
- // -> static palette -chain count: dword
- // -> static-palette -array : comment length | offset :qword + index : qword
- // |
- // -> page elem
- // | header -> page elem offset array
- // |
- // | -> chr-index : qword (DWORD_MAX := empty)
- // | -> nametable/clay-pool index : dword
- // | -> attr-count : dword
- // | -> palette-count : dword
- // | -> attr-select : dword (DWORD_MAX := empty)
- // | -> palette-select : dword (DWORD_MAX := empty)
- // | -> attr chunk set
- // |
- // |-------> comment length | offset : qword
- // |-------> attr index
- // | -> pal chunk set
- // |
- // |-------> comment length | offset : qword
- // |-------> pal index
- struct NNEHeader {
- BYTE magic[16];
- DWORD crc32_intel;
- DWORD chrChainOffset;
- DWORD chrCount;
- DWORD gPaletteCount;
- DWORD gPaletteChainOffset;
- DWORD clayChainOffset;
- DWORD clayCount;
- DWORD mapChainOffset;
- DWORD mapCount;
- DWORD attrPoolOffset;
- DWORD chrPoolOffset;
- DWORD palettePoolOffset;
- DWORD nclayPoolOffset;
- DWORD stringPoolOffset;
- };
- struct chrSectionChunk {
- DWORD commentLength;
- DWORD commentOffset;
- UINT64 chrIndex;
- };
- struct attrChunk {
- DWORD commentLength;
- DWORD commentOffset;
- UINT64 attrIndex;
- };
- struct palChunk {
- DWORD commentLength;
- DWORD commentOffset;
- UINT64 palIndex;
- };
- struct claySectionChunkHeader {
- DWORD commentLength;
- DWORD commentOffset;
- DWORD chrIndex;
- DWORD clayIndex;
- DWORD attrCount;
- DWORD paletteCount;
- DWORD attrSel;
- DWORD paletteSel;
- /* attrCount attrChunk */
- /* paletteCount palChunk */
- };
- struct claySection {
- /* NNEHeader :: clayCount offset:DWORD */
- /* NNEHeader :: clayCount claySectionChunkHeader */
- };
- struct mapSectionPageChunk {
- DWORD chrIndex;
- DWORD nametableIndex;
- DWORD attrCount;
- DWORD paletteCount;
- DWORD attrSel;
- DWORD paletteSel;
- /* attrCount attrChunk */
- /* paletteCount palChunk */
- };
- struct mapSectionChunk {
- DWORD commentLength;
- DWORD commentOffset;
- DWORD width;
- DWORD height;
- DWORD sPaletteCount;
- /* sPaletteCount palChunk */
- /* width* height mapSectionPageChunk offset */
- };
- };
- // <CViewNametablePage> =========================================
- template <BOOL t_bReadWriteMap>
- struct CViewNametablePage : public CDialogImpl<CViewNametablePage<t_bReadWriteMap>, CWindowFT>
- {
- // Some global settings.
- enum { IDD = IDD_NAMETABLE_PAGE };
- static const DWORD tileUnitSize = 16;
- static const DWORD attrUnitSize = 16;
- static const DWORD gpalUnitWidth = 19;
- static const DWORD gpalUnitHeight = 25;
- static const DWORD cpalUnitWidth = 46;
- static const DWORD cpalUnitHeight = 23;
- static const WORD meshClr = 12 | 12 << 5 | 12 << 10;
- static const WORD spalCatchClr = 0x1f << 10;
- static const WORD alphaClr = 0x7f00;
- static const WORD alphaCnt = 7;
- static const WORD attrFontclr= 0x7fff;
- static const WORD attrFontbgclr = 0;
- static const WORD spalCatchBakClr = 0x1f << 5;
- static const WORD attrSelMoveClr = 0x1f;
- static const WORD attrSelEndClr = 0x1f << 5;
- static const WORD claySelMovClr = 0x1f << 10;
- static const WORD attrMeshClr = PHOTOSHOP_COL_TOGDI16 (0xaaaaaa);
- static const WORD transShadowMark = PHOTOSHOP_COL_TOGDI16 (0xffffff);
- static const WORD transHitMark = PHOTOSHOP_COL_TOGDI16 (0xcecece);
- static const size_t MAP_CONTROL_LV_CHR = 1;
- static const size_t MAP_CONTROL_LV_ATTR = MAP_CONTROL_LV_CHR + 1;
- static const size_t MAP_CONTROL_LV_GPAL = MAP_CONTROL_LV_ATTR + 1;
- static const size_t MAP_CONTROL_LV_SPAL = MAP_CONTROL_LV_GPAL + 1;
- static const size_t MAP_CONTROL_LV_ATTRLIST = MAP_CONTROL_LV_SPAL + 1;
- static const size_t MAP_CONTROL_LV_PALLIST = MAP_CONTROL_LV_ATTRLIST + 1;
- typedef CDialogImpl<CViewNametablePage<t_bReadWriteMap>> baseClass;
- typedef CViewNametablePage thisClass;
- CMainFrame *m_atthis;
- CContainedWindowT<CListViewCtrl> m_GuiLV_Chr;
- CContainedWindowT<CListViewCtrl> m_GuiLV_Attr;
- CContainedWindowT<CListViewCtrl> m_GuiLV_GlobalPalette;
- CContainedWindowT<CListViewCtrl> m_GuiLV_SelectPalette;
- CContainedWindowT<CListViewCtrlTS<CAttr>> m_GuiLV_AttrList;
- CContainedWindowT<CListViewCtrlTS<CPal>> m_GuiLV_PalList;
- CMemoryPaint16 m_MemoryPaintChr;
- CMemoryPaint16 m_MemoryPaintAttr;
- CMemoryPaint16 m_MemoryPaintGPal;
- CMemoryPaint16 m_MemoryPaintSPal;
- CButton m_GuiGB_Chr;
- BOOL m_bClaywindow;
- BOOL m_bAttrEditMode;
- BEGIN_MSG_MAP(thisClass)
- MESSAGE_HANDLER (WM_INITDIALOG, OnCreate)
- MESSAGE_HANDLER (WM_PAINT, OnPaint)
- MESSAGE_HANDLER (WM_NCLBUTTONDBLCLK, OnChangeShowMode)
- MESSAGE_HANDLER (WM_CLOSE, OnClose)
- MESSAGE_HANDLER (WM_DESTROY, OnDestroy)
- COMMAND_ID_HANDLER (IDCK_TILEGRID, OnCheckUpdate)
- COMMAND_ID_HANDLER (IDCK_ATTRGRID, OnCheckUpdate)
- ALT_MSG_MAP(MAP_CONTROL_LV_CHR)
- MESSAGE_HANDLER (WM_LBUTTONUP, OnLButtonUpT<MAP_CONTROL_LV_CHR>)
- MESSAGE_HANDLER (WM_MOUSEMOVE, OnMouseMoveT<MAP_CONTROL_LV_CHR>)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT<MAP_CONTROL_LV_CHR>)
- MESSAGE_HANDLER (WM_RBUTTONUP, OnRButtonUpT<MAP_CONTROL_LV_CHR>)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT<MAP_CONTROL_LV_CHR>)
- ALT_MSG_MAP(MAP_CONTROL_LV_ATTR)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT<MAP_CONTROL_LV_ATTR>)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT<MAP_CONTROL_LV_ATTR>)
- MESSAGE_HANDLER (WM_MOUSEMOVE, OnMouseMoveT<MAP_CONTROL_LV_ATTR>)
- MESSAGE_HANDLER (WM_LBUTTONUP, OnLButtonUpT<MAP_CONTROL_LV_ATTR>)
- MESSAGE_HANDLER (WM_RBUTTONUP, OnRButtonUpT<MAP_CONTROL_LV_ATTR>)
- ALT_MSG_MAP(MAP_CONTROL_LV_ATTRLIST)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT<MAP_CONTROL_LV_ATTRLIST>)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT<MAP_CONTROL_LV_ATTRLIST>)
- MESSAGE_HANDLER (WM_LBUTTONDBLCLK, OnLButtonDblclk <MAP_CONTROL_LV_ATTRLIST>)
- ALT_MSG_MAP(MAP_CONTROL_LV_SPAL)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT<MAP_CONTROL_LV_SPAL>)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT<MAP_CONTROL_LV_SPAL>)
- MESSAGE_HANDLER (WM_LBUTTONUP, OnLButtonUpT<MAP_CONTROL_LV_SPAL>)
- MESSAGE_HANDLER (WM_RBUTTONUP, OnRButtonUpT<MAP_CONTROL_LV_SPAL>)
- ALT_MSG_MAP(MAP_CONTROL_LV_GPAL)
- MESSAGE_HANDLER (WM_LBUTTONUP, OnLButtonUpT<MAP_CONTROL_LV_GPAL>)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT<MAP_CONTROL_LV_GPAL>)
- MESSAGE_HANDLER (WM_RBUTTONUP, OnRButtonUpT<MAP_CONTROL_LV_GPAL>)
- ALT_MSG_MAP(MAP_CONTROL_LV_PALLIST)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT<MAP_CONTROL_LV_PALLIST>)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT<MAP_CONTROL_LV_PALLIST>)
- MESSAGE_HANDLER (WM_LBUTTONDBLCLK, OnLButtonDblclk <MAP_CONTROL_LV_PALLIST>)
- END_MSG_MAP()
- CNametableCell<t_bReadWriteMap> *m_pNametableCell;
- DWORD m_dwStateAttr; // 0: no copy 1:copy it
- // 0x8000 mask : ing...
- DWORD m_dwStateChr; // 0: no copy 1:copy it
- // 0x8000 mask : ing...
- // adjust by ptr.
- void sMutViewAttr_reset (BOOL bDeleteListViewFirst = FALSE) {
- if (bDeleteListViewFirst != FALSE) {
- m_GuiLV_Attr.DeleteAllItems ();
- }
- if (m_pNametableCell != NULL) {
- auto &attr_list = m_pNametableCell->attrList;
- auto attr_sel_t = m_pNametableCell->attr;
- m_GuiLV_Attr.DeleteAllItems ();
- for (auto it = 0; it != attr_list.GetCount (); it++) {
- auto p = attr_list[it];
- ATLASSERT (p != NULL);
- m_GuiLV_AttrList.InsertItem (it, p->comment, 0);
- m_GuiLV_AttrList.SetItemData (it, reinterpret_cast <DWORD_PTR> ( p));
- if (p== attr_sel_t) {
- m_GuiLV_AttrList.SelectItem (it);
- }
- }
- }
- }
- // adjust by ptr.
- void sMutViewPal_reset (BOOL bDeleteListViewFirst = FALSE) {
- if (bDeleteListViewFirst != FALSE) {
- m_GuiLV_PalList.DeleteAllItems ();
- }
- if (m_pNametableCell != NULL) {
- auto &pal_list = m_pNametableCell->palList;
- auto pal_sel_t = m_pNametableCell->pal;
- auto total = m_pNametableCell->getPaletteTotal ();
- m_GuiLV_PalList.DeleteAllItems ();
- for (SIZE_T it = 0; it != total; it++) {
- auto p = m_pNametableCell->getSelectPal (it);
- ATLASSERT (p != NULL);
- m_GuiLV_PalList.InsertItem (it, p->comment, p->source);
- m_GuiLV_PalList.SetItemData (it, reinterpret_cast <DWORD_PTR> ( p));
- if (p== pal_sel_t) {
- m_GuiLV_AttrList.SelectItem (it);
- }
- }
- }
- }
- void resetListViewPalette (void) {
- auto total =m_pNametableCell->getPaletteTotal ();
- m_GuiLV_PalList.DeleteAllItems ();
- if (total > 0) {
- BOOL bSelect =FALSE;
- for (typeof_noref(total) it = 0; it != total; it++) {
- auto pal = m_pNametableCell->getSelectPal (it);
- ATLASSERT (pal != NULL);
- m_GuiLV_PalList.InsertItem (it, pal->comment, pal->source); // XXX: enum series.
- m_GuiLV_PalList.SetItemDataT (it, pal);
- if (pal == m_pNametableCell->pal) {
- m_pNametableCell->select = it;
- m_GuiLV_PalList.SelectItem (it);
- bSelect = TRUE;
- }
- }
- // Item remove. select default index 0 palette.
- if (bSelect == FALSE) {
- m_GuiLV_PalList.SelectItem (0);
- m_pNametableCell->pal = m_pNametableCell->getSelectPal (0);
- m_pNametableCell->select = 0;
- }
- } else {
- m_pNametableCell->pal = NULL;
- m_pNametableCell->select = -1;
- }
- }
- BOOL alive (void) {
- return m_pNametableCell != NULL;
- }
- void setDead (void) {
- m_pNametableCell = NULL;
- }
- void setAttach (CMainFrame *attachhtis0) {
- m_atthis = attachhtis0;
- }
- VOID setNtCell (CNametableCell<t_bReadWriteMap> *cell) {
- if (cell == m_pNametableCell)
- return ;
- m_GuiLV_AttrList.DeleteAllItems ();
- m_GuiLV_PalList.DeleteAllItems ();
- m_pNametableCell = cell;
- if (cell != NULL) {
- auto &attr_list = cell->attrList;
- auto attr_sel_t = cell->attr;
- auto attr_sel = - 1;
- for (auto it = 0; it != attr_list.GetCount (); it++) {
- auto p = attr_list[it];
- if (p != NULL) {
- m_GuiLV_AttrList.InsertItem (it, p->comment, 0);
- m_GuiLV_AttrList.SetItemData (it, reinterpret_cast <DWORD_PTR> ( p));
- if (p== attr_sel_t) {
- attr_sel = it;
- }
- }
- }
- if (attr_sel >= 0) {
- m_GuiLV_AttrList.SelectItem (attr_sel);
- }
- resetListViewPalette ();
- // Update draw infos.
- UpdateInfos (TRUE);
- }
- }
- INT m_bShowMinMode; // 0:std 1:only chr 2:chr + attr 3: chr + paleetee
- PBYTE m_pTrackSPal;
- CPoint m_ptTrackChrStartZ;
- CPoint m_ptTrackAttrStart;
- CPoint m_ptTrackAttrEnd;
- CPoint m_ptTrackChrStart;
- CPoint m_ptTrackChrEnd;
- CPoint m_ptTrackerAttrStartY;
- CSize m_szTrackerAttrVectorY;
- CRect m_rcStdClient;
- CPoint m_ptTrackerChrStartY;
- CSize m_szTrackerChrVectorY;
- CPoint m_ptTrackGPal;
- CPoint m_ptTrackSPal;
- CImageListManaged m_ImgListAttr;
- CImageListManaged m_ImgListPal;
- // <CAttrSettings> =========================================
- struct CAttrSettings : public CDialogImpl<CAttrSettings>
- {
- typedef CAttrSettings thisClass;
- typedef CDialogImpl<CAttrSettings> baseClass;
- CViewNametablePage &m_attthis;
- CAttr *m_newattr;
- CAttrSettings (CViewNametablePage &psthis):
- m_attthis (psthis),
- m_newattr (NULL) {}
- enum { IDD = IDD_ATTR_LIST_SETTINGS };
- BEGIN_MSG_MAP(thisClass)
- MESSAGE_HANDLER (WM_INITDIALOG, OnCreate)
- MESSAGE_HANDLER (WM_CLOSE, OnClose)
- COMMAND_ID_HANDLER (IDBT_ATTR_RESET, OnSet)
- END_MSG_MAP()
- LRESULT OnClose (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- bHandled = FALSE;
- EndDialog (IDCANCEL);
- return 0;
- }
- LRESULT OnCreate (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- CEdit etComment = GetDlgItem (IDET_ATTRCOMMENT);
- if (m_newattr != NULL) {
- // Fill current pal infos.
- etComment.SetWindowText (m_newattr->comment);
- }
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnSet (WORD, WORD, HWND /*lParam*/, BOOL& bHandled) {
- CEdit etComment = GetDlgItem (IDET_ATTRCOMMENT);
- CButton ckFill = GetDlgItem (IDCK_ATTRFILL);
- CEdit etInitFill = GetDlgItem (IDET_INITFILL);
- CString content;
- etComment.GetWindowText (content);
- BOOL bpushnewItem = m_newattr == NULL;
- if (bpushnewItem != FALSE
- && m_newattr == NULL)
- {
- m_newattr= new CAttr;
- }
- m_newattr->comment = content;
- if (ckFill.GetCheck () == BST_CHECKED)
- {
- etInitFill.GetWindowText (content);
- int fillByte =
- _tcstol (content, NULL, 16)
- & 255;
- RtlFillMemory (m_newattr->attr, sizeof (m_newattr->attr), fillByte);
- }
- EndDialog (IDOK);
- CGlobals::adjustCommentUnique<CAttr> (m_attthis.m_pNametableCell->attrList, m_newattr, bpushnewItem);
- bHandled = FALSE;
- return 0;
- }
- INT_PTR DoModal (CAttr *attr = NULL)
- {
- m_newattr = attr;
- // Modal it.
- return baseClass::DoModal ();
- }
- };
- // <CPalSettings> =========================================
- template <BOOL t_bReadWriteMap>
- struct CPalSettings : public CDialogImpl<CPalSettings<t_bReadWriteMap>>
- {
- typedef CPalSettings thisClass;
- typedef CDialogImpl<CPalSettings<t_bReadWriteMap>> baseClass;
- CViewNametablePage &m_attchthis;
- CPal *m_attachpal;
- CPalSettings (CViewNametablePage &atthis):
- m_attchthis (atthis),
- m_attachpal (NULL) {}
- enum { IDD = IDD_PAL_LIST_SETTINGS };
- BEGIN_MSG_MAP(thisClass)
- MESSAGE_HANDLER (WM_INITDIALOG, OnCreate)
- MESSAGE_HANDLER (WM_CLOSE, OnClose)
- COMMAND_ID_HANDLER (IDBT_PAL_RESET, OnSet)
- END_MSG_MAP()
- LRESULT OnClose (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- bHandled = FALSE;
- EndDialog (IDCANCEL);
- return 0;
- }
- LRESULT OnCreate (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- CEdit etComment = GetDlgItem (IDET_PALCOMMENT);
- CButton btReset = GetDlgItem (IDBT_PAL_RESET);
- SetWindowText (_T ("palette insert"));
- btReset.SetWindowText (_T ("Insert"));
- if (t_bReadWriteMap != FALSE) {
- // Remove static palette option.
- :: EnableWindow (GetDlgItem (IDRD_PAL_STATIC), FALSE);
- }
- if (m_attachpal != NULL) {
- // Fill current pal infos.
- etComment.SetWindowText (m_attachpal->comment);
- btReset.SetWindowText (_T ("Reset"));
- SetWindowText (_T ("palette reset"));
- m_attachpal->sourceAssert ();
- if (m_attachpal->source == CPal::private_palette) {
- CheckDlgButton (IDRD_PAL_PRIVATE, BST_CHECKED);
- } else if (m_attachpal->source == CPal::static_palette){
- CheckDlgButton (IDRD_PAL_STATIC, BST_CHECKED);
- } else if (m_attachpal->source == CPal::global_palette){
- CheckDlgButton (IDRD_PAL_GLOBAL, BST_CHECKED);
- }
- } else {
- CheckDlgButton (IDRD_PAL_PRIVATE, BST_CHECKED);
- }
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnSet (WORD, WORD, HWND /*lParam*/, BOOL& bHandled) {
- CEdit etComment = GetDlgItem (IDET_PALCOMMENT);
- CString content;
- CButton ckSourcePrivate = GetDlgItem (IDRD_PAL_PRIVATE);
- CButton ckSourceStatic = GetDlgItem (IDRD_PAL_STATIC);
- CButton ckSourceGlobal = GetDlgItem (IDRD_PAL_GLOBAL);
- etComment .GetWindowText (content);
- if (m_attachpal == NULL) {
- if (ckSourcePrivate.GetCheck () == BST_CHECKED) {
- m_attachpal = new CPal (CPal::private_palette);
- CGlobals::adjustCommentUnique<CPal> (m_attchthis.m_pNametableCell->palList, m_attachpal, TRUE);
- } else if (ckSourceStatic.GetCheck () == BST_CHECKED) {
- m_attachpal = new CPal (CPal::static_palette);
- CGlobals::adjustCommentUnique<CPal> (m_attchthis.m_pNametableCell->staticPalList, m_attachpal, TRUE);
- } else if (ckSourceGlobal.GetCheck () == BST_CHECKED) {
- m_attachpal = new CPal (CPal::global_palette);
- CGlobals::adjustCommentUnique<CPal> (m_attchthis.m_pNametableCell->globalPalList, m_attachpal, TRUE);
- }
- m_attachpal->sourceAssert ();
- m_attachpal->comment = content;
- } else {
- // Adjust exist attr infos.
- m_attachpal->sourceAssert ();
- m_attachpal->comment = content;
- auto prevsource = m_attachpal->source;
- auto cursource =prevsource;
- if (ckSourcePrivate.GetCheck () == BST_CHECKED) {
- m_attachpal->source = CPal::private_palette;
- } else if (ckSourceStatic.GetCheck () == BST_CHECKED) {
- m_attachpal->source = CPal::static_palette;
- } else if (ckSourceGlobal.GetCheck () == BST_CHECKED) {
- m_attachpal->source = CPal::global_palette;
- }
- if (m_attachpal->source != prevsource) {
- // vector move.
- CAtlArray <CPal *> *palvec;
- if (prevsource == CPal::private_palette) {
- palvec = & m_attchthis.m_pNametableCell->palList;
- } else if (prevsource == CPal::static_palette) {
- palvec = & m_attchthis.m_pNametableCell->staticPalList;
- } else if (prevsource == CPal::global_palette) {
- palvec = & m_attchthis.m_pNametableCell->globalPalList;
- }
- for (auto it = 0; it != palvec->GetCount (); it++) {
- auto p = (*palvec)[it];
- if (p == m_attachpal) {
- palvec->RemoveAt (it);
- break;
- }
- }
- if (m_attachpal->source == CPal::private_palette) {
- palvec = & m_attchthis.m_pNametableCell->palList;
- } else if (m_attachpal->source == CPal::static_palette) {
- palvec = & m_attchthis.m_pNametableCell->staticPalList;
- } else if (m_attachpal->source == CPal::global_palette) {
- palvec = & m_attchthis.m_pNametableCell->globalPalList;
- }
- palvec->InsertAt (palvec->GetCount(), m_attachpal);
- }
- }
- m_attchthis.m_atthis->updateItemPalette ();
- EndDialog (IDOK);
- bHandled = FALSE;
- return 0;
- }
- INT_PTR DoModal ( CPal *pal = NULL)
- {
- m_attachpal = pal;
- // Modal it.
- return baseClass::DoModal ();
- }
- };
- CViewNametablePage (CNametableCell<t_bReadWriteMap> *nt_cell = NULL):
- m_bClaywindow (t_bReadWriteMap),
- m_bAttrEditMode (FALSE),
- m_dwStateChr (0),
- m_dwStateAttr (0),
- m_bShowMinMode (0),
- m_pNametableCell (nt_cell),
- m_pTrackSPal (NULL),
- m_GuiLV_Chr (this, MAP_CONTROL_LV_CHR),
- m_GuiLV_Attr (this, MAP_CONTROL_LV_ATTR),
- m_GuiLV_GlobalPalette (this, MAP_CONTROL_LV_GPAL),
- m_GuiLV_SelectPalette (this, MAP_CONTROL_LV_SPAL),
- m_GuiLV_AttrList (this, MAP_CONTROL_LV_ATTRLIST),
- m_GuiLV_PalList (this, MAP_CONTROL_LV_PALLIST),
- m_ptTrackGPal (0, 0),
- m_ptTrackSPal (0, 0)
- {
- }
- ~CViewNametablePage (VOID) {
- // m_GuiLV_PalList.Remov
- // m_GuiLV_PalList.SetImageList (m_ImgListPal, LVSIL_SMALL);
- // m_GuiLV_AttrList.SetImageList (m_ImgListAttr, LVSIL_SMALL);
- m_ImgListPal.RemoveAll ();
- m_ImgListAttr.RemoveAll ();
- }
- LRESULT OnChangeShowMode (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- // 0:std 1:only chr 2:chr + attr 3: chr + paleetee
- m_bShowMinMode ++;
- m_bShowMinMode &= 3;
- switch (m_bShowMinMode) {
- case 0:
- ResizeClient (m_rcStdClient.Width (), m_rcStdClient.Height (), TRUE);
- break;
- case 1:
- ResizeClient (282, 282, TRUE);
- break;
- case 2:
- ResizeClient (m_rcStdClient.Width (), 282, TRUE);
- break;
- case 3:
- ResizeClient (282, m_rcStdClient.Height (), TRUE);
- break;
- default:
- break;
- }
- return 0;
- }
- LRESULT OnCreate (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- // Subclass/Attach it
- m_GuiLV_Chr.SubclassWindow (GetDlgItem (IDLV_4KCHR));
- m_GuiLV_Attr.SubclassWindow (GetDlgItem (IDLV_ATTR));
- m_GuiLV_GlobalPalette.SubclassWindow (GetDlgItem (IDLV_GLOBAL_PALETTE));
- m_GuiLV_SelectPalette.SubclassWindow (GetDlgItem (IDLV_SELPALETTE));
- m_GuiLV_AttrList.SubclassWindow (GetDlgItem (IDLV_ATTR_LIST));
- m_GuiLV_PalList.SubclassWindow (GetDlgItem (IDLV_PAL_LIST));
- m_GuiGB_Chr.Attach (GetDlgItem (IDGB_4KCHR));
- m_MemoryPaintChr.resetMemoryDC (m_GuiLV_Chr);
- m_MemoryPaintAttr.resetMemoryDC (m_GuiLV_Attr);
- m_MemoryPaintGPal.resetMemoryDC (m_GuiLV_GlobalPalette);
- m_MemoryPaintSPal.resetMemoryDC (m_GuiLV_SelectPalette);
- CGlobals::setDefaultListViewColor (m_GuiLV_AttrList);
- CGlobals::setDefaultListViewColor (m_GuiLV_PalList);
- m_ImgListAttr.Create (16,16,ILC_COLOR24|ILC_MASK,1,0);
- m_ImgListPal.Create (16,16,ILC_COLOR24|ILC_MASK,1,0);
- m_ImgListAttr.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_ATTRLIST)));
- m_ImgListPal.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_PRIVATE_PAL)));
- m_ImgListPal.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_STATIC_PAL)));
- m_ImgListPal.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_GLOBAL_PAL)));
- // Get init view rect..
- GetClientRect (m_rcStdClient);
- m_GuiLV_PalList.SetImageList (m_ImgListPal, LVSIL_SMALL);
- m_GuiLV_AttrList.SetImageList (m_ImgListAttr, LVSIL_SMALL);
- if (t_bReadWriteMap != FALSE) {
- m_GuiGB_Chr.SetWindowText (_T ("Clay-stdmode"));
- } else {
- // Hide item .
- ::ShowWindow (GetDlgItem (IDCK_OVERWRITE_ATTR), SW_HIDE);
- ::ShowWindow (GetDlgItem (IDCK_OVERWRITE_CHR), SW_HIDE);
- ::ShowWindow (GetDlgItem (IDCK_OVERWRITE_PAL), SW_HIDE);
- }
- bHandled = FALSE;
- return 0;
- }
- VOID UpdateInfos (BOOL postToScreen = FALSE) {
- CMemoryPaint16::DirectWrite dwriteChr;
- CMemoryPaint16::DirectWrite dwriteAttr;
- CMemoryPaint16::DirectWrite dwriteGPal;
- CMemoryPaint16::DirectWrite dwriteSPal;
- m_MemoryPaintChr.getBackSurface (dwriteChr);
- m_MemoryPaintAttr.getBackSurface (dwriteAttr);
- m_MemoryPaintGPal.getBackSurface (dwriteGPal);
- m_MemoryPaintSPal.getBackSurface (dwriteSPal);
- if (m_pNametableCell == NULL) {
- // No attach item.
- m_MemoryPaintChr.fillFullClient (dwriteChr, 0);
- m_MemoryPaintAttr.fillFullClient (dwriteAttr, 0);
- m_MemoryPaintGPal.fillFullClient (dwriteGPal, 0);
- m_MemoryPaintSPal.fillFullClient (dwriteSPal, 0);
- } else {
- auto &rNamtable = *m_pNametableCell;
- if (rNamtable.chr == NULL) {
- m_MemoryPaintChr.fillFullClient (dwriteChr, 0);
- } else {
- if (t_bReadWriteMap == FALSE) {
- // Scan tiles. in chr mode (2bit + fixed palette bank)
- static const BYTE palT[] = { 0, 0 << 0, 0 << 5, 0 << 10 };
- auto pPal = palT;
- auto pChr = rNamtable.chr->chr;
- auto pGloablNESPal = CGlobals::nespal;
- if (rNamtable.pal != NULL) {
- pPal = & rNamtable.pal->pal[(rNamtable.bank & 3) * 4];
- }
- WORD palFast[] = {
- pGloablNESPal[rNamtable.pal? rNamtable.pal->pal[0] : palT[0]],
- pGloablNESPal[pPal[1]],
- pGloablNESPal[pPal[2]],
- pGloablNESPal[pPal[3]]
- };
- for (auto j = 0; j != 16; j++) {
- for (auto i = 0; i != 16; i++) {
- DWORD x_pos= i << 4;
- DWORD y_pos = j << 4;
- PWORD vramT = & dwriteChr.pBits[x_pos + y_pos *dwriteChr.Pitch16];
- PWORD vramT2 = & vramT[dwriteChr.Pitch16];
- PBYTE pChrT = pChr;
- CPolyData64 chr;
- for (DWORD v = 0; v != 8; v++) {
- chr.blk = CGlobals::chrmixer[pChrT[0]]
- | CGlobals::chrmixer[pChrT[8]] << 1;
- vramT[0] = vramT[1] =
- vramT2[0] = vramT2[1] = palFast[chr.blk8[0]];
- vramT[2] = vramT[3] =
- vramT2[2] = vramT2[3] = palFast[chr.blk8[1]];
- vramT[4] = vramT[5] =
- vramT2[4] = vramT2[5] = palFast[chr.blk8[2]];
- vramT[6] = vramT[7] =
- vramT2[6] = vramT2[7] = palFast[chr.blk8[3]];
- vramT[8] = vramT[9] =
- vramT2[8] = vramT2[9] = palFast[chr.blk8[4]];
- vramT[10] = vramT[11] =
- vramT2[10] = vramT2[11] = palFast[chr.blk8[5]];
- vramT[12] = vramT[13] =
- vramT2[12] = vramT2[13] = palFast[chr.blk8[6]];
- vramT[14] = vramT[15] =
- vramT2[14] = vramT2[15] = palFast[chr.blk8[7]];
- vramT += dwriteChr.Pitch16;
- vramT += dwriteChr.Pitch16;
- vramT2 += dwriteChr.Pitch16;
- vramT2 += dwriteChr.Pitch16;
- pChrT++;
- }
- pChr += 16;
- }
- }
- } else {
- // Scan tiles. in nes mode (2bit + attr palette bank)
- BYTE palT[] = {
- 0x0F, 0x00, 0x10, 0x30,
- 0x0F, 0x1C, 0x2B, 0x39,
- 0x0F, 0x06, 0x15, 0x36,
- 0x0C, 0x17, 0x28, 0x39
- };
- static BYTE attrT[64];
- auto pPal = palT;
- auto pAttr = attrT;
- auto pChr = rNamtable.chr->chr;
- auto &rNametableT = rNamtable.tileSlot;
- auto &rGloablNESPal = CGlobals::nespal;
- BYTE transTile[16];
- RtlZeroMemory (transTile, sizeof (transTile));
- if (rNamtable.pal != NULL) {
- RtlCopyMemory (palT, & rNamtable.pal->pal[0], sizeof (palT));
- palT[12] =
- palT[8] =
- palT[4] = palT[0];
- }
- if (rNamtable.attr != NULL) {
- pAttr = rNamtable.attr->attr;
- }
- for (auto j = 0; j != 32; j++) {
- for (auto i = 0; i != 32; i++) {
- DWORD x_pos= i << 3;
- DWORD y_pos = j << 3;
- PWORD vramT = & dwriteChr.pBits[x_pos + y_pos *dwriteChr.Pitch16];
- WORD tileSlot = rNametableT[i+ (j << 5)];
- if ( (tileSlot & 0x8000) == 0) {
- PBYTE pChrT = tileSlot & 0x8000 ? transTile : & pChr[(tileSlot & 255) << 4];
- PBYTE pBank = & palT[CGlobals::getAttrBit (pAttr, i, j) << 2];
- for (DWORD v = 0; v != 8; v++) {
- CPolyData64 chr;
- chr.blk = CGlobals::chrmixer[pChrT[0]]
- | CGlobals::chrmixer[pChrT[8]] << 1;
- vramT[0] = rGloablNESPal[pBank[chr.blk8[0]]];
- vramT[1] = rGloablNESPal[pBank[chr.blk8[1]]];
- vramT[2] = rGloablNESPal[pBank[chr.blk8[2]]];
- vramT[3] = rGloablNESPal[pBank[chr.blk8[3]]];
- vramT[4] = rGloablNESPal[pBank[chr.blk8[4]]];
- vramT[5] = rGloablNESPal[pBank[chr.blk8[5]]];
- vramT[6] = rGloablNESPal[pBank[chr.blk8[6]]];
- vramT[7] = rGloablNESPal[pBank[chr.blk8[7]]];
- vramT += dwriteChr.Pitch16;
- pChrT++;
- }
- } else {
- // Draw transparent
- WORD transMarkClr[4] = { transHitMark, transShadowMark,
- transShadowMark, transHitMark };
- for (DWORD v = 0; v != 8; v++) {
- PWORD clrVPhase = & transMarkClr[v & 2];
- vramT[0] =
- vramT[1] = clrVPhase[0];
- vramT[2] =
- vramT[3] = clrVPhase[1];
- vramT[4] =
- vramT[5] = clrVPhase[0];
- vramT[6] =
- vramT[7] = clrVPhase[1];
- vramT += dwriteChr.Pitch16;
- }
- }
- }
- }
- // Tracker movse infos...
- // FIXME: more case.
- if (CGlobals::pasteAlive () != FALSE) {
- int copy_x = CGlobals::pasteTile.copySize.cx;
- int copy_y = CGlobals::pasteTile.copySize.cy;
- int mouse_x = m_ptTrackChrStartZ.x;
- int mouse_y = m_ptTrackChrStartZ.y;
- if (mouse_x + copy_x > 32)
- copy_x = 32 - mouse_x;
- if (mouse_y + copy_y > 32)
- copy_y = 32 - mouse_y;
- auto &rNametableS = CGlobals::pasteTile.tileSlot;
- for (auto j = 0; j != copy_y; j++) {
- for (auto i = 0; i != copy_x; i++) {
- DWORD x2_pos = i + mouse_x << 3;
- DWORD y2_pos = j + mouse_y << 3;
- DWORD x_pos= i << 3;
- DWORD y_pos = j << 3;
- WORD tileSlot = rNametableS[i+ (j << 5)];
- PWORD vramT = & dwriteChr.pBits[x2_pos + y2_pos *dwriteChr.Pitch16];
- PBYTE pChrT = tileSlot & 0x8000 ? transTile : & CGlobals::pasteTile.chr->chr[(tileSlot & 255) << 4];
- if ((tileSlot & 0x8000) == 0) {
- auto pBank = & palT[CGlobals::getAttrBit (pAttr, i, j) << 2];
- for (DWORD v = 0; v != 8; v++) {
- CPolyData64 chr;
- chr.blk = CGlobals::chrmixer[pChrT[0]]
- | CGlobals::chrmixer[pChrT[8]] << 1;
- vramT[0] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[0]]], vramT[0], alphaCnt, 15 - alphaCnt);
- vramT[1] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[1]]], vramT[1], alphaCnt, 15 - alphaCnt);
- vramT[2] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[2]]], vramT[2], alphaCnt, 15 - alphaCnt);
- vramT[3] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[3]]], vramT[3], alphaCnt, 15 - alphaCnt);
- vramT[4] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[4]]], vramT[4], alphaCnt, 15 - alphaCnt);
- vramT[5] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[5]]], vramT[5], alphaCnt, 15 - alphaCnt);
- vramT[6] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[6]]], vramT[6], alphaCnt, 15 - alphaCnt);
- vramT[7] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[7]]], vramT[7], alphaCnt, 15 - alphaCnt);
- vramT += dwriteChr.Pitch16;
- pChrT++;
- }
- }
- }
- }
- }
- }
- // Check draw chr mesh
- if (CButton (GetDlgItem (IDCK_TILEGRID)).GetCheck () == BST_CHECKED) {
- if (t_bReadWriteMap != FALSE) {
- CGlobals::drawGrid (dwriteChr,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (0, 0),
- CSize (8, 8),
- CSize (32, 32),
- meshClr);
- } else {
- CGlobals::drawGrid (dwriteChr,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (0, 0),
- CSize (16, 16),
- CSize (16, 16),
- meshClr);
- }
- }
- // Check draw attr mesh
- if (CButton (GetDlgItem (IDCK_ATTRGRID)).GetCheck () == BST_CHECKED
- && t_bReadWriteMap != FALSE) {
- CGlobals::drawGrid (dwriteChr,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (0, 0),
- CSize (16, 16),
- CSize (16, 16),
- attrMeshClr);
- }
- // Tracker chr
- if (m_dwStateChr != 0)
- {
- if (t_bReadWriteMap != FALSE && m_bAttrEditMode == FALSE) {
- CGlobals::drawGrid (dwriteChr,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (m_ptTrackerChrStartY.x * 8, m_ptTrackerChrStartY.y * 8),
- CSize (m_szTrackerChrVectorY.cx * 8, m_szTrackerChrVectorY.cy * 8),
- CSize (1, 1),
- m_dwStateChr & 0x8000 ? attrSelMoveClr : attrSelEndClr );
- } else {
- CGlobals::drawGrid (dwriteChr,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (m_ptTrackerChrStartY.x * 16, m_ptTrackerChrStartY.y * 16),
- CSize (m_szTrackerChrVectorY.cx * 16, m_szTrackerChrVectorY.cy * 16),
- CSize (1, 1),
- m_dwStateChr & 0x8000 ? attrSelMoveClr : attrSelEndClr );
- }
- }
- if (CGlobals::pasteAlive () != FALSE) {
- CGlobals::drawGrid (dwriteChr,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (m_ptTrackChrStartZ.x << 3, m_ptTrackChrStartZ.y << 3),
- CSize (8, 8),
- CSize (1, 1),
- spalCatchClr);
- }
- }
- // Draw Attr table
- if (rNamtable.attr == NULL) {
- m_MemoryPaintAttr.fillFullClient (dwriteChr, 0);
- } else {
- PWORD pGloablNESPal = CGlobals::nespal;
- PBYTE pAttr = rNamtable.attr->attr;
- for (auto j = 0; j != 16; j++) {
- for (auto i = 0; i != 16; i++) {
- auto x_pos= i << 4;
- auto y_pos = j << 4;
- auto vramT = & dwriteAttr.pBits[x_pos + y_pos *dwriteAttr.Pitch16];
- auto attrX = i >> 1;
- auto attrY = j >> 1;
- auto attrByte = pAttr[attrX+(attrY<<3)];
- if (j & 1)
- if (i & 1)
- attrByte = attrByte >> 6 & 3;
- else
- attrByte = attrByte >> 4 & 3;
- else
- if (i & 1)
- attrByte = attrByte >> 2 & 3;
- else
- attrByte &= 3;
- PWORD pFontpix;
- switch (attrByte) {
- case 0: pFontpix = CGlobals::attrFont0_x2; break;
- case 1: pFontpix = CGlobals::attrFont1_x2; break;
- case 2: pFontpix = CGlobals::attrFont2_x2; break;
- case 3: pFontpix = CGlobals::attrFont3_x2; break;
- default:
- ATLASSERT (FALSE);
- break;
- }
- for (DWORD v = 0; v != 16; v++) {
- #define CHECK_SET(index)\
- vramT[index] = pFontpix[index];
- CHECK_SET (0)
- CHECK_SET (1)
- CHECK_SET (2)
- CHECK_SET (3)
- CHECK_SET (4)
- CHECK_SET (5)
- CHECK_SET (6)
- CHECK_SET (7)
- CHECK_SET (8)
- CHECK_SET (9)
- CHECK_SET (10)
- CHECK_SET (11)
- CHECK_SET (12)
- CHECK_SET (13)
- CHECK_SET (14)
- CHECK_SET (15)
- #undef CHECK_SET
- vramT += dwriteAttr.Pitch16;
- pFontpix += 16;
- }
- }
- }
- // Check draw mesh
- CGlobals::drawGrid (dwriteAttr,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (0, 0),
- CSize (16, 16),
- CSize (16, 16),
- meshClr);
- // Tracker atrtr
- if (m_dwStateAttr != 0)
- {
- CGlobals::drawGrid (dwriteAttr,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (m_ptTrackerAttrStartY.x * 16, m_ptTrackerAttrStartY.y * 16),
- CSize (m_szTrackerAttrVectorY.cx * 16, m_szTrackerAttrVectorY.cy * 16),
- CSize (1, 1),
- m_dwStateAttr & 0x8000 ? attrSelMoveClr : attrSelEndClr );
- }
- if (t_bReadWriteMap != FALSE && m_bAttrEditMode != FALSE
- && m_dwStateChr != 0) {
- CGlobals::drawGrid (dwriteAttr,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (m_ptTrackerChrStartY.x * 16, m_ptTrackerChrStartY.y * 16),
- CSize (m_szTrackerChrVectorY.cx * 16, m_szTrackerChrVectorY.cy * 16),
- CSize (1, 1),
- attrMeshClr );
- }
- }
- // Draw GPal palette
- // 16 *4 item.
- if (rNamtable.pal != NULL) {
- for (auto j = 0; j != 4; j++) {
- for (auto i = 0; i != 16; i++) {
- auto clr = CGlobals::nespal[(j<<4)+i];
- auto pix = & dwriteGPal.pBits [j*gpalUnitHeight*dwriteGPal.Pitch16+i*gpalUnitWidth];
- for (auto y = 0; y != gpalUnitHeight; y++) {
- for (auto x = 0; x != gpalUnitWidth; x++) {
- pix[x+y*dwriteGPal.Pitch16] = clr;
- }
- }
- }
- }
- // Draw SPal palette
- // 4 *4 item.
- for (auto j = 0; j != 4; j++) {
- for (auto i = 0; i != 4; i++) {
- auto clr = CGlobals::nespal[rNamtable.pal->pal[(j<<2)+i] & 0x3F];
- auto pix = & dwriteSPal.pBits [j*cpalUnitHeight*dwriteSPal.Pitch16+i*cpalUnitWidth];
- for (auto y = 0; y != cpalUnitHeight; y++) {
- for (auto x = 0; x != cpalUnitWidth; x++) {
- pix[x+y*dwriteSPal.Pitch16] = clr;
- }
- }
- }
- }
- CGlobals::drawGrid (dwriteGPal,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (0, 0),
- CSize (gpalUnitWidth, gpalUnitHeight),
- CSize (16, 4),
- meshClr);
- CGlobals::drawGrid (dwriteSPal,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (0, 0),
- CSize (cpalUnitWidth, cpalUnitHeight),
- CSize (4, 4),
- meshClr);
- CGlobals::drawGrid (dwriteSPal,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (0, (rNamtable.bank & 3) * cpalUnitHeight),
- CSize (cpalUnitWidth, cpalUnitHeight),
- CSize (4, 1),
- spalCatchBakClr);
- if (m_pTrackSPal != NULL) {
- CGlobals::drawGrid (dwriteSPal,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (m_ptTrackSPal.x * cpalUnitWidth, m_ptTrackSPal.y * cpalUnitHeight),
- CSize (cpalUnitWidth, cpalUnitHeight),
- CSize (1, 1),
- spalCatchClr);
- CGlobals::drawGrid (dwriteGPal,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (m_ptTrackGPal.x * gpalUnitWidth, m_ptTrackGPal.y * gpalUnitHeight),
- CSize (gpalUnitWidth, gpalUnitHeight),
- CSize (1, 1),
- spalCatchClr);
- }
- } else {
- m_MemoryPaintGPal.fillFullClient (dwriteGPal, 0);
- m_MemoryPaintSPal.fillFullClient (dwriteSPal, 0);
- }
- }
- m_MemoryPaintChr.blitClientBaseALL0 ();
- m_MemoryPaintAttr.blitClientBaseALL0 ();
- m_MemoryPaintGPal.blitClientBaseALL0 ();
- m_MemoryPaintSPal.blitClientBaseALL0 ();
- }
- LRESULT OnPaint (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPaintDC dc (*this);
- UpdateInfos (TRUE);
- bHandled= FALSE;
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnRButtonUpT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_ATTR:
- if (m_dwStateAttr == 1
- && m_pNametableCell != NULL
- && m_pNametableCell->attr != NULL)
- {
- for (auto j= 0; j != m_szTrackerAttrVectorY.cy; j++) {
- const auto yvec= j + m_ptTrackerAttrStartY.y << 1;
- for (auto i= 0; i != m_szTrackerAttrVectorY.cx; i++) {
- const auto xvec = i + m_ptTrackerAttrStartY.x << 1;
- CGlobals::setAttrBit (m_pNametableCell->attr->attr, xvec, yvec,
- CGlobals::getAttrBit (m_pNametableCell->attr->attr, xvec, yvec) + 1);
- }
- }
- // Exec undo status save.
- m_pNametableCell->snapshotToUndoStack ();
- }
- m_atthis->m_GuiSWin_Nesmap.nesPixelGenerator ();
- UpdateInfos (TRUE);
- bHandled = FALSE;
- break;
- case MAP_CONTROL_LV_CHR: // Case listview-chr
- if ( t_bReadWriteMap != FALSE
- && m_bAttrEditMode != FALSE
- && (m_dwStateChr & 0x7FFF) != 0)
- {
- for (auto j= 0; j != m_szTrackerChrVectorY.cy; j++) {
- const auto yvec= j + m_ptTrackerChrStartY.y << 1;
- for (auto i= 0; i != m_szTrackerChrVectorY.cx; i++) {
- const auto xvec = i + m_ptTrackerChrStartY.x << 1;
- CGlobals::setAttrBit (m_pNametableCell->attr->attr, xvec, yvec,
- CGlobals::getAttrBit (m_pNametableCell->attr->attr, xvec, yvec) + 1);
- }
- }
- // Exec undo status save.
- m_pNametableCell->snapshotToUndoStack ();
- } else if (CGlobals::pasteAlive () != FALSE) {
- CGlobals::makePasteDead ();
- m_dwStateChr = 0;
- } else if (m_pNametableCell != NULL) {
- m_pNametableCell->bank ++;
- m_pNametableCell->bank &= 3;
- }
- UpdateInfos (TRUE);
- break;
- case MAP_CONTROL_LV_SPAL: // Case select palette.
- case MAP_CONTROL_LV_GPAL:
- m_pTrackSPal = NULL; // Cancel select.
- default:
- break;
- }
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnMouseMoveT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_CHR:
- if (t_bReadWriteMap != FALSE
- && CGlobals::pasteAlive () != FALSE
- && m_bAttrEditMode == FALSE)
- {
- // in clay mode and pasting..!
- m_ptTrackChrStartZ.x = pt.x / 8;
- m_ptTrackChrStartZ.y = pt.y / 8;
- CGlobals::limitPoint (m_ptTrackChrStartZ, 32, 32);
- }
- else if (m_dwStateChr & 0x8000) {
- // Calc rect
- if (t_bReadWriteMap != FALSE && m_bAttrEditMode == FALSE) {
- pt.x /= 8;
- pt.y /= 8;
- CGlobals::limitPoint (pt, 32, 32);
- if (1/*m_bInitTrackAttr == FALSE
- || (m_ptTrackAttrEnd.x != pt.x
- || m_ptTrackAttrEnd.y != pt.y)*/)
- {
- // First refresh /or cross a unit (per 16 pixels )
- // m_bInitTrackAttr = TRUE;
- m_ptTrackChrEnd.x = pt.x ;
- m_ptTrackChrEnd.y = pt.y ;
- CPoint ptStart = m_ptTrackChrStart;
- CPoint ptEnd = m_ptTrackChrEnd;
- CGlobals::translateVecPointToltrb (ptStart, ptEnd);
- m_ptTrackerChrStartY = ptStart;
- m_szTrackerChrVectorY.cx = ptEnd.x -ptStart.x + 1;
- m_szTrackerChrVectorY.cy = ptEnd.y -ptStart.y + 1;
- }
- } else {
- pt.x /= 16;
- pt.y /= 16;
- CGlobals::limitPoint (pt, 16, 16);
- if (1/*m_bInitTrackAttr == FALSE
- || (m_ptTrackAttrEnd.x != pt.x
- || m_ptTrackAttrEnd.y != pt.y)*/)
- {
- // First refresh /or cross a unit (per 16 pixels )
- // m_bInitTrackAttr = TRUE;
- m_ptTrackChrEnd.x = pt.x ;
- m_ptTrackChrEnd.y = pt.y ;
- CPoint ptStart = m_ptTrackChrStart;
- CPoint ptEnd = m_ptTrackChrEnd;
- CGlobals::translateVecPointToltrb (ptStart, ptEnd);
- m_ptTrackerChrStartY = ptStart;
- m_szTrackerChrVectorY.cx = ptEnd.x -ptStart.x + 1;
- m_szTrackerChrVectorY.cy = ptEnd.y -ptStart.y + 1;
- }
- }
- }
- break;
- case MAP_CONTROL_LV_ATTR:
- if (m_dwStateAttr & 0x8000) {
- // Calc rect
- pt.x /= 16;
- pt.y /= 16;
- CGlobals::limitPoint (pt, 16, 16);
- if (1/*m_bInitTrackAttr == FALSE
- || (m_ptTrackAttrEnd.x != pt.x
- || m_ptTrackAttrEnd.y != pt.y)*/)
- {
- // First refresh /or cross a unit (per 16 pixels )
- // m_bInitTrackAttr = TRUE;
- m_ptTrackAttrEnd.x = pt.x ;
- m_ptTrackAttrEnd.y = pt.y ;
- CPoint ptStart = m_ptTrackAttrStart;
- CPoint ptEnd = m_ptTrackAttrEnd;
- CGlobals::translateVecPointToltrb (ptStart, ptEnd);
- m_ptTrackerAttrStartY = ptStart;
- m_szTrackerAttrVectorY.cx = ptEnd.x -ptStart.x + 1;
- m_szTrackerAttrVectorY.cy = ptEnd.y -ptStart.y + 1;
- }
- }
- bHandled = FALSE;
- break;
- case MAP_CONTROL_LV_ATTRLIST: // Case Global paleete
- m_ptTrackGPal.x = pt.x / gpalUnitWidth;
- m_ptTrackGPal.y = pt.y / gpalUnitHeight;
- CGlobals::limitPoint (m_ptTrackGPal, 16, 4);
- // Check Lock ptr.
- if (m_pTrackSPal != NULL) {
- m_pTrackSPal[0] = (BYTE)(m_ptTrackGPal.x+m_ptTrackGPal.y*16 & 0xFF);
- }
- default:
- break;
- }
- UpdateInfos (TRUE);
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnLButtonDblclk (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- CValidateALL flush (*m_atthis, *this);
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_ATTRLIST:
- if (m_GuiLV_AttrList.GetSelectedIndex () >= 0){
- auto index = m_GuiLV_AttrList.GetSelectedIndex ();
- CAttr *attr = m_GuiLV_AttrList.GetItemSelectedDataT ();
- ATLASSERT (attr != NULL);
- CAttrSettings dlgSettings (*this);
- if (dlgSettings.DoModal (attr) == IDOK) {
- // Append to new.
- //m_Attrsel = attr;
- m_GuiLV_AttrList.SetItemText (index, 0, attr->comment);
- m_atthis->setCPListViewItemWithImg <t_bReadWriteMap> ( m_pNametableCell, 3, attr->comment, 5);
- m_atthis->allViewUpdate ();
- }
- bHandled = FALSE;
- }
- break;
- case MAP_CONTROL_LV_PALLIST:
- if (m_GuiLV_PalList.GetSelectedIndex () >= 0){
- auto index = m_GuiLV_PalList.GetSelectedIndex ();
- CPal *pal = (CPal *) m_GuiLV_PalList.GetItemData (index);
- ATLASSERT (pal != NULL);
- CPalSettings<t_bReadWriteMap> dlgSettings (*this);
- if (dlgSettings.DoModal (pal) == IDOK) {
- // Append to new.
- // m_Palsel = pal;
- m_GuiLV_PalList.SetItemText (index, 0, pal->comment);
- m_atthis->allViewUpdate ();
- }
- bHandled = FALSE;
- }
- default:
- break;
- }
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnLButtonDownT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- CValidateALL flush (*m_atthis, *this);
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_ATTRLIST: // Case Global paleete , Process default message first
- m_GuiLV_AttrList.DefWindowProc (uMsg, wParam, lParam);
- if (m_GuiLV_AttrList.GetSelectedIndex () >= 0) {
- m_pNametableCell->attr = m_GuiLV_AttrList.GetItemSelectedDataT ();
- ATLASSERT (m_pNametableCell->attr != NULL);
- m_atthis->setCPListViewItemWithImg <t_bReadWriteMap> ( m_pNametableCell, 3, m_pNametableCell->attr->comment, 5);
- }
- break;
- case MAP_CONTROL_LV_PALLIST:
- // Process default message first
- m_GuiLV_PalList.DefWindowProc (uMsg, wParam, lParam);
- if (m_GuiLV_PalList.GetSelectedIndex () >= 0) {
- m_pNametableCell->pal = m_GuiLV_PalList.GetItemSelectedDataT ();
- m_pNametableCell->readjustPos ();
- ATLASSERT (m_pNametableCell->pal != NULL);
- m_atthis->setCPListViewItemWithImg <t_bReadWriteMap> ( m_pNametableCell, 2, m_pNametableCell->pal->comment, 2 + m_pNametableCell->pal->source);
- }
- break;
- case MAP_CONTROL_LV_CHR:
- if (t_bReadWriteMap != FALSE && m_bAttrEditMode == FALSE) {
- m_ptTrackChrStart.x = pt.x / 8;
- m_ptTrackChrStart.y = pt.y / 8;
- CGlobals::limitPoint (m_ptTrackChrStart, 32, 32);
- } else {
- m_ptTrackChrStart.x = pt.x / 16;
- m_ptTrackChrStart.y = pt.y / 16;
- CGlobals::limitPoint (m_ptTrackChrStart, 16, 16);
- }
- m_ptTrackChrEnd = m_ptTrackChrStart;
- m_dwStateChr = 0x8000 | 1;
- m_ptTrackerChrStartY = m_ptTrackChrStart;
- m_szTrackerChrVectorY.cx = 1;
- m_szTrackerChrVectorY.cy = 1;
- bHandled = FALSE;
- break;
- case MAP_CONTROL_LV_ATTR:
- m_ptTrackAttrStart.x = pt.x / 16;
- m_ptTrackAttrStart.y = pt.y / 16;
- CGlobals::limitPoint (m_ptTrackAttrStart, 16, 16);
- m_ptTrackAttrEnd = m_ptTrackAttrStart;
- m_dwStateAttr = 0x8000 | 1;
- m_ptTrackerAttrStartY = m_ptTrackAttrStart;
- m_szTrackerAttrVectorY.cx = 1;
- m_szTrackerAttrVectorY.cy = 1;
- bHandled = FALSE;
- break;
- case MAP_CONTROL_LV_GPAL:
- m_ptTrackGPal.x = pt.x / gpalUnitWidth;
- m_ptTrackGPal.y = pt.y / gpalUnitHeight;
- CGlobals::limitPoint (m_ptTrackSPal, 4, 4);
- break;
- case MAP_CONTROL_LV_SPAL: // Case select palette.
- // Catch select palette
- // do rect clip and lockit
- m_ptTrackSPal.x = pt.x / cpalUnitWidth;
- m_ptTrackSPal.y = pt.y / cpalUnitHeight;
- CGlobals::limitPoint (m_ptTrackSPal, 4, 4);
- // Lock ptr.
- if (m_pNametableCell != NULL
- && m_pNametableCell->pal != NULL)
- m_pTrackSPal = & m_pNametableCell->pal->pal[m_ptTrackSPal.x+m_ptTrackSPal.y*4];
- bHandled = FALSE;
- default:
- break;
- }
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnLButtonUpT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_CHR:
- if (CGlobals::pasteAlive () != FALSE
- && m_bAttrEditMode == FALSE) {
- auto copySize = CGlobals::pasteTile.copySize;
- auto mouse = m_ptTrackChrStartZ;
- auto &rNametableS = CGlobals::pasteTile.tileSlot;
- auto &rNametableT = m_pNametableCell->tileSlot;
- if (mouse.x + copySize.cx > 32)
- copySize.cx = 32 - mouse.x;
- if (mouse.y + copySize.cy > 32)
- copySize.cy = 32 - mouse.y;
- for (auto j = 0; j != copySize.cy; j++) {
- for (auto i = 0; i != copySize.cx; i++) {
- if ( (rNametableS[i+ (j << 5)] & 0x8000) == 0) {
- rNametableT[ i + mouse.x + (j + mouse.y << 5)] = rNametableS[i+ (j << 5)];
- }
- }
- }
- // Exec undo status save.
- m_pNametableCell->snapshotToUndoStack ();
- }
- else if (m_dwStateChr & 0x8000)
- {
- m_dwStateChr &= ~0x8000;
- if (t_bReadWriteMap != FALSE && m_bAttrEditMode == FALSE) {
- m_ptTrackChrEnd.x = pt.x / 8;
- m_ptTrackChrEnd.y = pt.y / 8;
- CGlobals::limitPoint (m_ptTrackChrEnd, 32, 32);
- CPoint ptStart = m_ptTrackChrStart;
- CPoint ptEnd = m_ptTrackChrEnd;
- CGlobals::translateVecPointToltrb (ptStart, ptEnd);
- m_ptTrackerChrStartY = ptStart;
- m_szTrackerChrVectorY.cx = ptEnd.x -ptStart.x + 1;
- m_szTrackerChrVectorY.cy = ptEnd.y -ptStart.y + 1;
- // Copy from clay/nametable
- if (m_pNametableCell->chr != NULL) {
- CGlobals::lockPaste (
- & m_pNametableCell->tileSlot[0],
- ptStart,
- m_szTrackerChrVectorY,
- CSize (32, 32),
- IsDlgButtonChecked (IDCK_OVERWRITE_CHR) == BST_CHECKED,
- m_pNametableCell->chr,
- IsDlgButtonChecked (IDCK_OVERWRITE_PAL) == BST_CHECKED,
- m_pNametableCell->pal != NULL ?
- m_pNametableCell->pal->pal
- : NULL,
- IsDlgButtonChecked (IDCK_OVERWRITE_ATTR) == BST_CHECKED,
- m_pNametableCell->attr != NULL ?
- m_pNametableCell->attr->attr
- : NULL);
- }
- } else {
- m_ptTrackChrEnd.x = pt.x / 16;
- m_ptTrackChrEnd.y = pt.y / 16;
- CGlobals::limitPoint (m_ptTrackChrEnd, 16, 16);
- CPoint ptStart = m_ptTrackChrStart;
- CPoint ptEnd = m_ptTrackChrEnd;
- CGlobals::translateVecPointToltrb (ptStart, ptEnd);
- m_ptTrackerChrStartY = ptStart;
- m_szTrackerChrVectorY.cx = ptEnd.x -ptStart.x + 1;
- m_szTrackerChrVectorY.cy = ptEnd.y -ptStart.y + 1;
- if (m_bAttrEditMode == FALSE) {
- // Copy from chr-
- static WORD chrTile[1024];
- RtlFillMemory (chrTile, sizeof (chrTile), 0x80);
- // init chr tiles
- for (auto y = 0; y != 16; y++) {
- for (auto x = 0; x != 16; x++) {
- chrTile[y * 32 + x] = y * 16 + x;
- }
- }
- CGlobals::lockPaste (
- & chrTile[0],
- ptStart,
- m_szTrackerChrVectorY,
- CSize (16, 16),
- IsDlgButtonChecked (IDCK_OVERWRITE_CHR) == BST_CHECKED,
- m_pNametableCell->chr,
- IsDlgButtonChecked (IDCK_OVERWRITE_PAL) == BST_CHECKED,
- m_pNametableCell->pal != NULL ?
- m_pNametableCell->pal->pal
- : NULL);
- }
- }
- }
- UpdateInfos (TRUE);
- break;
- case MAP_CONTROL_LV_ATTR:
- if (m_dwStateAttr & 0x8000)
- {
- m_dwStateAttr &= ~0x8000;
- m_ptTrackAttrEnd.x = pt.x / 16;
- m_ptTrackAttrEnd.y = pt.y / 16;
- CGlobals::limitPoint (m_ptTrackAttrEnd, 16, 16);
- CPoint ptStart = m_ptTrackAttrStart;
- CPoint ptEnd = m_ptTrackAttrEnd;
- CGlobals::translateVecPointToltrb (ptStart, ptEnd);
- m_ptTrackerAttrStartY = ptStart;
- m_szTrackerAttrVectorY.cx = ptEnd.x -ptStart.x + 1;
- m_szTrackerAttrVectorY.cy = ptEnd.y -ptStart.y + 1;
- }
- Invalidate ();
- bHandled = FALSE;
- break;
- case MAP_CONTROL_LV_ATTRLIST: // Case attr select end
- // m_bSelAttrtable = TRUE;
- break;
- case MAP_CONTROL_LV_GPAL: // Case Global paleete
- m_ptTrackGPal.x = pt.x / gpalUnitWidth;
- m_ptTrackGPal.y = pt.y / gpalUnitHeight;
- CGlobals::limitPoint (m_ptTrackGPal, 16, 4);
- // Check Lock ptr.
- if (m_pTrackSPal != NULL) {
- m_pTrackSPal[0] = (BYTE) (m_ptTrackGPal.x+m_ptTrackGPal.y*16 & 0xFF);
- m_atthis->adjustSpecPalette (m_atthis->m_ShowMap);
- m_atthis->allViewUpdate ();
- }
- Invalidate ();
- default:
- break;
- }
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnKeyUpT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CValidateALL flush (*m_atthis, *this);
- ATLASSERT (m_pNametableCell != NULL);
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_CHR:
- switch (wParam) {
- case 'Z': // Undo
- if (CTRL_IN_KEYQUEUE ()) {
- if (m_pNametableCell->snapshotUndo () != NULL) {
- int id = 0;
- }
- }
- break;
- case 'Y': // Resume
- if (CTRL_IN_KEYQUEUE ()) {
- if (m_pNametableCell->snapshotResume () != NULL) {
- int id = 0;
- }
- }
- break;
- case 96:
- case 97:
- case 98:
- case 99:
- case '0':
- case '1':
- case '2':
- case '3':
- if ( t_bReadWriteMap != FALSE
- && m_bAttrEditMode != FALSE
- && (m_dwStateChr & 0x7FFF) != 0)
- {
- const DWORD attr2bit = (wParam >= 96 && wParam <= 99)
- ? (wParam - 96 & 3)
- : (wParam - '0' & 3);
- for (auto j= 0; j != m_szTrackerChrVectorY.cy; j++) {
- const auto yvec= j + m_ptTrackerChrStartY.y << 1;
- for (auto i= 0; i != m_szTrackerChrVectorY.cx; i++) {
- const auto xvec = i + m_ptTrackerChrStartY.x << 1;
- CGlobals::setAttrBit (m_pNametableCell->attr->attr, xvec, yvec, attr2bit);
- }
- }
- // Exec undo status save.
- m_pNametableCell->snapshotToUndoStack ();
- UpdateInfos (TRUE);
- }
- break;
- case VK_RETURN:
- if (t_bReadWriteMap != FALSE) {
- m_bAttrEditMode = ! m_bAttrEditMode;
- if (m_bAttrEditMode != FALSE) {
- m_GuiGB_Chr.SetWindowText (_T ("Clay-attr mode"));
- } else {
- m_GuiGB_Chr.SetWindowText (_T ("Clay-std mode"));
- }
- m_dwStateAttr = 0;
- m_dwStateChr = 0;
- }
- break;
- case 'C':
- if (t_bReadWriteMap != FALSE
- && (m_dwStateChr != 0
- && (m_dwStateChr & 0x8000) == 0))
- {
- for (DWORD j= 0; j != m_szTrackerChrVectorY.cy; j++) {
- DWORD yvec = j + m_ptTrackerChrStartY.y;
- PWORD pByteY = & m_pNametableCell->tileSlot[yvec << 5];
- for (DWORD i= 0; i != m_szTrackerChrVectorY.cx; i++) {
- DWORD xvec = i + m_ptTrackerChrStartY.x;
- pByteY[xvec] = 0x8000;
- }
- }
- // Exec undo status save.
- m_pNametableCell->snapshotToUndoStack ();
- UpdateInfos (TRUE);
- }
- default:
- break;
- }
- break;
- case MAP_CONTROL_LV_ATTRLIST:
- switch (wParam) {
- case 'C':
- if (CTRL_IN_KEYQUEUE ()) {
- auto attr = m_GuiLV_AttrList.GetItemSelectedDataT ();
- if (attr != NULL) {
- CGlobals::pasteAttr = attr;
- m_atthis->setStatusText (4, _T ("attr cache:%s %s"), m_pNametableCell->comment, attr->comment);
- }
- }
- break;
- case 'V':
- if (CTRL_IN_KEYQUEUE ()) {
- auto attr = m_GuiLV_AttrList.GetItemSelectedDataT ();
- if (attr != NULL && CGlobals::pasteAttr != NULL) {
- RtlCopyMemory (attr->attr, CGlobals::pasteAttr->attr, sizeof (CGlobals::pasteAttr->attr));
- // Update view
- m_atthis->allViewUpdate ();
- }
- }
- break;
- case VK_INSERT:
- // Attr table insert new item.
- //
- {
- CAttrSettings dlgSettings (*this);
- if (dlgSettings.DoModal (NULL) == IDOK) {
- // Append to new.
- auto index = m_GuiLV_AttrList.InsertItem (m_GuiLV_AttrList.GetItemCount (), dlgSettings.m_newattr->comment, 0);
- ATLASSERT (index >= 0);
- m_GuiLV_AttrList.SetItemData (index, reinterpret_cast <DWORD_PTR> ( dlgSettings.m_newattr));
- if (m_pNametableCell->attr == NULL) {
- // No sel attr table pointer. set default
- m_pNametableCell->attr = dlgSettings.m_newattr;
- m_atthis->setCPListViewItemWithImg <t_bReadWriteMap> ( m_pNametableCell, 3, m_pNametableCell->attr->comment, 5);
- }
- m_atthis->m_GuiSWin_Nesmap.nesPixelGenerator ();
- }
- return 0;
- }
- break;
- case VK_DELETE:
- // Attr table delete select item.
- //
- {
- auto index = m_GuiLV_AttrList.GetSelectedIndex ();
- if (index >= 0) {
- auto *attr = m_GuiLV_AttrList.GetItemDataT (index);
- for (auto It = 0; It != m_pNametableCell->attrList .GetCount (); It++) {
- auto *temp = m_pNametableCell->attrList[It];
- if (temp == attr) {
- m_pNametableCell->attrList.RemoveAt (It);
- m_GuiLV_AttrList.DeleteItem (index);
- m_atthis->setCPListViewItemWithImg <t_bReadWriteMap> ( m_pNametableCell, 3, _T ("null"), 5);
- m_pNametableCell->attr = NULL;
- if (attr == CGlobals::pasteAttr) {
- // Remove paste object
- CGlobals::pasteAttr = NULL;
- m_atthis->setStatusText (4, _T ("attr cache:empty"));
- }
- delete temp;
- break;
- }
- }
- }
- }
- default:
- break;
- }
- bHandled = FALSE;
- break;
- case MAP_CONTROL_LV_PALLIST:
- switch (wParam) {
- case 'C':
- if (CTRL_IN_KEYQUEUE ()) {
- auto pal = m_GuiLV_PalList.GetItemSelectedDataT ();
- if (pal != NULL) {
- CGlobals::pastePal = pal;
- m_atthis->setStatusText (3, _T ("pal cache:%s %s %s"),
- m_pNametableCell->comment,
- m_pNametableCell->getSelectPalSource (), pal->comment);
- }
- }
- break;
- case 'V':
- if (CTRL_IN_KEYQUEUE ()) {
- auto pal = m_GuiLV_PalList.GetItemSelectedDataT ();
- if (pal != NULL && CGlobals::pastePal != NULL) {
- RtlCopyMemory (pal->pal, CGlobals::pastePal->pal, sizeof (CGlobals::pastePal->pal));
- // Update view
- m_atthis->allViewUpdate ();
- }
- }
- break;
- case VK_INSERT:
- {
- CPalSettings<t_bReadWriteMap> dlgSettings (*this);
- if (dlgSettings.DoModal () == IDOK) {
- resetListViewPalette ();
- m_atthis->updateCPViewListInfos<FALSE> ();
- m_atthis->allViewUpdate ();
- }
- }
- break;
- case VK_DELETE:
- {
- auto index = m_GuiLV_PalList.GetSelectedIndex ();
- if (index >= 0) {
- // Delete select palette item.
- // Check global/static palette, remove it in all view. (nt and clay)
- // Update CMainFrame::Page view
- // Update all link's nt and clay view.
- // Update NEX pixel output.
- ATLASSERT (m_pNametableCell != NULL);
- CPal *pal = m_pNametableCell->removePalette (index);
- ATLASSERT (pal != NULL);
- // Check global/static palette, remove it in all CAtlArray. (nt and clay)
- m_atthis->removeAllSpecRefMapPaletteGS (pal);
- m_atthis->updateCPViewListInfos<FALSE>();
- m_atthis->updateCPViewListInfos<TRUE> ();
- m_atthis->allViewUpdate ();
- if (pal == CGlobals::pastePal) {
- // Remove paste object
- CGlobals::pastePal = NULL;
- m_atthis->setStatusText (3, _T ("pal cache:empty"));
- }
- delete pal;
- }
- }
- default:
- break;
- }
- bHandled = FALSE;
- break;
- case MAP_CONTROL_LV_ATTR:
- switch (wParam) {
- case 'Z': // Undo
- if (CTRL_IN_KEYQUEUE ()) {
- if (m_pNametableCell->snapshotUndo () != NULL) {
- int id = 0;
- }
- }
- break;
- case 'Y': // Resume
- if (CTRL_IN_KEYQUEUE ()) {
- if (m_pNametableCell->snapshotResume () != NULL) {
- int id = 0;
- }
- }
- break;
- case 96:
- case 97:
- case 98:
- case 99:
- case '0':
- case '1':
- case '2':
- case '3':
- // Scan rect.
- if (m_dwStateAttr == 1
- && m_pNametableCell != NULL
- && m_pNametableCell->attr != NULL)
- {
- const DWORD attr2bit = (wParam >= 96 && wParam <= 99)
- ? (wParam - 96 & 3)
- : (wParam - '0' & 3);
- for (auto j= 0; j != m_szTrackerAttrVectorY.cy; j++) {
- const auto yvec= j + m_ptTrackerAttrStartY.y << 1;
- for (auto i= 0; i != m_szTrackerAttrVectorY.cx; i++) {
- const auto xvec = i + m_ptTrackerAttrStartY.x << 1;
- CGlobals::setAttrBit (m_pNametableCell->attr->attr, xvec, yvec, attr2bit);
- }
- }
- UpdateInfos (TRUE);
- m_atthis->m_GuiSWin_Nesmap.nesPixelGenerator ();
- }
- break;
- }
- default:
- break;
- }
- return 0;
- }
- LRESULT OnCheckUpdate (WORD, WORD, HWND /*lParam*/, BOOL& bHandled) {
- Invalidate (NULL);
- return 0;
- }
- LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- m_GuiLV_PalList.RemoveImageList (LVSIL_SMALL);
- m_GuiLV_AttrList.RemoveImageList (LVSIL_SMALL);
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- ShowWindow (SW_HIDE);
- bHandled = FALSE;
- return 0;
- }
- };
- static const WORD clrMeshMainOne = PHOTOSHOP_COL_TOGDI16 (0x0000cc);
- static const WORD clrMeshMainTwo = PHOTOSHOP_COL_TOGDI16 (0x00cc00);
- static const WORD clrMeshAttr = PHOTOSHOP_COL_TOGDI16 (0x555555);
- static const WORD clrMeshCatching = PHOTOSHOP_COL_TOGDI16 (0xcc0000);
- static const WORD clrMeshSet = PHOTOSHOP_COL_TOGDI16 (0xebf90a);
- static const SIZE_T MAP_CONTROL_LV_MAP = 1;
- static const SIZE_T MAP_CONTROL_LV_PAGE = MAP_CONTROL_LV_MAP + 1;
- static const SIZE_T MAP_CONTROL_LV_CHR = MAP_CONTROL_LV_PAGE + 1;
- static const SIZE_T MAP_CONTROL_LV_CLAY = MAP_CONTROL_LV_CHR + 1;
- static const SIZE_T NTPAGE_SHOW_TOG_MAX = 4;
- static const SIZE_T CLAYPAGE_SHOW_TOG_MAX = 4;
- CImageListManaged m_IconMaplist;
- CImageListManaged m_IconClaylist;
- CImageListManaged m_IconChrlist;
- CImageListManaged m_IconPagelist;
- CPoint m_ptRenderStart;
- CPoint m_ptRenderEnd;
- CPoint m_ptRenderStartY;
- CSize m_szRenderStartY;
- CPoint m_ptPastePoint;
- BOOL m_bShowGridMain;
- BOOL m_bShowGridAttr;
- // Panel bar settings
- // --------------------------------------------------------------------------------
- // Map view | Chr list | Clay list
- // ---------------| ----------------------------------------
- // Page view | real map view
- // --------------------------------------------------------------------------------
- CSplitterWindowT <true> m_SWinSplitterMain;
- CSplitterWindowT <false> m_SWinSplitterLeft;
- CSplitterWindowT <false> m_SWinSplitterRight;
- CSplitterWindowT <true> m_SWinSplitterList;
- CContainedWindowT <CListViewCtrlTS<CMapUnit>> m_GuiLV_Map;
- CContainedWindowT <CListViewCtrlTS<CNametableCell <FALSE>>> m_GuiLV_Page;
- CContainedWindowT <CListViewCtrlTS<CChr>> m_GuiLV_Chr;
- CContainedWindowT <CListViewCtrlTS<CNametableCell <TRUE>>> m_GuiLV_Clay;
- // CToolTipCtrl
- // CToolTipCtrlT
- // CToolInfo
- // CToolBarCtrlT <CWindow> m_GuiTB_main;
- // CStatusBarCtrlT <CWindow> m_GuiSB_main;
- //
- // CToolTipCtrlT
- CToolBarCtrlT <CWindow> m_GuiTB_main;
- CMenuT <true> m_GuiMenu_MapAttach;
- public:
- DECLARE_FRAME_WND_CLASS_EX(NULL, IDR_MAINFRAME, 0, -1)
- CCommandBarCtrl m_CmdBar;
- BOOL m_bShowAttrShadow;
- LPDIRECT3D9 m_Direct3D9;
- LPDIRECT3DDEVICE9 m_Direct3D9Deivce;
- LPDIRECT3DSURFACE9 m_Direct3D9Surface;
- CPoint m_Tracker;
- CMapUnit *m_ShowMap;
- INT m_ntpWindowPoll;
- DWORD m_dwStateAttr; // 0: no copy 1:copy it
- // 0x8000 mask : ing...
- DWORD m_dwStateChr; // 0: no copy 1:copy it
- // 0x8000 mask : ing...
- DWORD m_dwStateRorate; // 0: no copy 1:copy it
- // 0x4000 : action 2:raote else action 1:select rect
- // 0x8000 mask : ing...
- CPoint m_ptTrackChrStartZ;
- CPoint m_ptTrackAttrStart;
- CPoint m_ptTrackAttrEnd;
- CPoint m_ptTrackChrStart;
- CPoint m_ptTrackChrEnd;
- CPoint m_ptTrackerAttrStartY;
- CSize m_szTrackerAttrVectorY;
- CPoint m_ptTrackerChrStartY;
- CSize m_szTrackerChrVectorY;
- INT m_subFunc; // 0: paste 1:attr adjust 2: vector rorate
- CViewNametablePage<FALSE> m_ntwCell[NTPAGE_SHOW_TOG_MAX];
- CViewNametablePage<TRUE> m_ClayCell[CLAYPAGE_SHOW_TOG_MAX];
- CAtlArray <CMapUnit *> m_MapVec;
- CAtlArray <CChr *> m_ChrVec;
- CAtlArray <CNametableCell<TRUE> *> m_VnpVec;
- CAtlArray <CPal *> m_globalPal;
- template <BOOL t_bReadWriteMap>
- struct CCPObjectHelper {
- CMainFrame &m_athis;
- CCPObjectHelper (CMainFrame &ttthis___):m_athis (ttthis___) {}
- BOOL isReadWriteMap (void) {
- return t_bReadWriteMap;
- }
- CListViewCtrlTS<CNametableCell <t_bReadWriteMap>> *
- getCPListViewObject (void) {
- return t_bReadWriteMap
- ? reinterpret_cast <CListViewCtrlTS<CNametableCell <t_bReadWriteMap>> *> ( & m_athis.m_GuiLV_Clay)
- : reinterpret_cast <CListViewCtrlTS<CNametableCell <t_bReadWriteMap>> *> ( & m_athis.m_GuiLV_Page);
- }
- const SIZE_T getCellViewMax (void) {
- return t_bReadWriteMap ? CLAYPAGE_SHOW_TOG_MAX
- : NTPAGE_SHOW_TOG_MAX;
- }
- CViewNametablePage<t_bReadWriteMap> *
- getCPCellView (void) {
- return t_bReadWriteMap
- ? reinterpret_cast <CViewNametablePage<t_bReadWriteMap> *> ( m_athis.m_ClayCell)
- : reinterpret_cast <CViewNametablePage<t_bReadWriteMap> *> ( m_athis.m_ntwCell);
- }
- CAtlArray <CNametableCell<t_bReadWriteMap> *> *
- getCPArrayObject (void) {
- if (t_bReadWriteMap == FALSE) {
- if (m_athis.m_ShowMap != NULL)
- return reinterpret_cast <CAtlArray <CNametableCell<t_bReadWriteMap> *> *> (& m_athis.m_ShowMap->ntList);
- return NULL;
- } else {
- return reinterpret_cast <CAtlArray <CNametableCell<t_bReadWriteMap> *> *> (& m_athis.m_VnpVec);
- }
- // Never reach here..
- ATLASSERT (FALSE);
- return NULL;
- }
- VOID allCPCellViewSMutUpdate () {
- auto cellmax= getCellViewMax ();
- auto pAllocT = getCPCellView ();
- for (SIZE_T it = 0; it != cellmax; it++) {
- auto &refcc = pAllocT[it];
- if (refcc.alive () != FALSE) {
- refcc.sMutViewPal_reset ();
- refcc.UpdateInfos ();
- }
- }
- }
- };
- template <BOOL t_bReadWriteMap>
- CListViewCtrlTS<CNametableCell <t_bReadWriteMap>> *
- getCPListViewObject (void) {
- return t_bReadWriteMap
- ? reinterpret_cast <CListViewCtrlTS<CNametableCell <t_bReadWriteMap>> *> ( & m_GuiLV_Clay)
- : reinterpret_cast <CListViewCtrlTS<CNametableCell <t_bReadWriteMap>> *> ( & m_GuiLV_Page);
- }
- void setItem (CListViewCtrl &listview, int iIndex, int iSubIndex, CString comment) {
- listview.SetItem (iIndex, iSubIndex, LVIF_TEXT, comment, 0, 0, 0, 0);
- }
- void setItemWithImg (CListViewCtrl &listview, int iIndex, int iSubIndex, CString comment, int iImage) {
- listview.SetItem (iIndex, iSubIndex, LVIF_IMAGE | LVIF_TEXT, comment, iImage, 0, 0, 0);
- }
- template <BOOL t_bReadWriteMap>
- void setCPListViewItemWithImg (int iIndex, int iSubIndex, CString comment, int iImage) {
- setItemWithImg (*getCPListViewObject <t_bReadWriteMap> (), iIndex, iSubIndex, comment, iImage);
- }
- template <BOOL t_bReadWriteMap>
- void setCPListViewItemWithImg (CNametableCell<t_bReadWriteMap> *nt_cell, int iSubIndex, CString comment, int iImage) {
- // Serach index.
- CListViewCtrlTS<CNametableCell <t_bReadWriteMap>> *
- CPObject = getCPListViewObject <t_bReadWriteMap> ();
- int index = -1;
- for (int it =0; it != CPObject->GetItemCount (); it++) {
- auto p = CPObject->GetItemDataT (it);
- ATLASSERT (p != NULL);
- if (p == nt_cell) {
- index = it;
- break;
- }
- }
- ATLASSERT (index >= 0);
- setItemWithImg (*CPObject, index, iSubIndex, comment, iImage);
- }
- template <BOOL t_bReadWriteMap>
- VOID updateCPViewListInfos (VOID) {
- CCPObjectHelper<t_bReadWriteMap> helper (*this);
- auto &lvPage = *helper.getCPListViewObject ();
- auto arrayT = helper.getCPArrayObject ();
- if (arrayT != NULL) {
- for (SIZE_T it = 0; it != arrayT->GetCount (); it++) {
- auto nt = (*arrayT)[it];
- ATLASSERT (nt != NULL);
- lvPage.SetItem (it, 0, LVIF_IMAGE | LVIF_TEXT, nt->comment, 0, 0, 0, 0);
- lvPage.SetItem (it, 1, LVIF_IMAGE | LVIF_TEXT, nt->chr ? nt->chr->comment : _T ("null"), 1, 0, 0, 0);
- lvPage.SetItem (it, 3, LVIF_IMAGE | LVIF_TEXT, nt->attr ? nt->attr->comment : _T ("null"), 5, 0, 0, 0);
- if (nt->pal != NULL) {
- lvPage.SetItem (it, 2, LVIF_IMAGE | LVIF_TEXT, nt->pal->comment, 2 + nt->pal->source, 0, 0, 0);
- } else {
- // use old clay palette ico.
- LVITEM lvtemp;
- RtlZeroMemory (& lvtemp, sizeof (LVITEM));
- lvtemp.iItem = it;
- lvtemp.iSubItem = 2;
- lvtemp.mask = LVIF_IMAGE;
- BOOL sig = lvPage.GetItem (& lvtemp);
- ATLASSERT (sig != FALSE);
- lvPage.SetItem (it, 2, LVIF_IMAGE | LVIF_TEXT, _T ("null"), lvtemp.iImage, 0, 0, 0);
- }
- }
- }
- }
- VOID removeAllSpecRefMapPaletteGS (CPal *pal) {
- if (pal != NULL
- && m_ShowMap != NULL) {
- for (auto it =0 ; it != NTPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ntwCell[it];
- if (r.alive () != FALSE && r.m_pNametableCell != NULL) {
- for (int it =0; it != r.m_GuiLV_PalList.GetItemCount (); it++) {
- auto p = r.m_GuiLV_PalList.GetItemDataT (it);
- ATLASSERT (p != NULL);
- if (p == pal) {
- // Delete this item.
- r.m_GuiLV_PalList.DeleteItem (it);
- // Check current is select.???
- if (r.m_GuiLV_PalList.GetSelectedIndex () == it) {
- // empty it.
- r.m_GuiLV_PalList.SetItemState (it, 0, 0);
- }
- break;
- }
- }
- }
- }
- for (auto it =0 ; it != CLAYPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ClayCell[it];
- if (r.alive () != FALSE && r.m_pNametableCell != NULL) {
- for (int it =0; it != r.m_GuiLV_PalList.GetItemCount (); it++) {
- auto p = r.m_GuiLV_PalList.GetItemDataT (it);
- ATLASSERT (p != NULL);
- if (p == pal) {
- // Delete this item.
- r.m_GuiLV_PalList.DeleteItem (it);
- // Check current is select.???
- if (r.m_GuiLV_PalList.GetSelectedIndex () == it) {
- // empty it.
- r.m_GuiLV_PalList.SetItemState (it, 0, 0);
- }
- break;
- }
- }
- }
- }
- // Check nt-
- for (size_t it = 0; it != m_ShowMap->ntList.GetCount (); it++) {
- auto p = m_ShowMap->ntList[it];
- ATLASSERT (p != NULL);
- if (p->pal == pal) {
- // remove it.
- p->pal = NULL;
- p->select = -1;
- }
- }
- // Check clay-
- for (size_t it = 0; it != m_VnpVec.GetCount (); it++) {
- auto p = m_VnpVec[it];
- ATLASSERT (p != NULL);
- if (p->pal == pal) {
- // remove it.
- p->pal = NULL;
- p->select = -1;
- }
- }
- }
- }
- VOID allViewUpdate (void) {
- for (auto it =0 ; it != NTPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ntwCell[it];
- if (r.alive () != FALSE) {
- r.UpdateInfos ();
- }
- }
- for (auto it =0 ; it != CLAYPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ClayCell[it];
- if (r.alive () != FALSE) {
- r.UpdateInfos ();
- }
- }
- m_GuiSWin_Nesmap.nesPixelGenerator ();
- }
- VOID adjustSpecPalette (void) {
- for (auto it = 0; it != m_MapVec.GetCount (); it++) {
- adjustSpecPalette (m_MapVec[it]);
- }
- }
- VOID adjustSpecPalette (CMapUnit *map_unit) {
- if (map_unit != NULL) {
- for (auto it =0; it != map_unit->ntList. GetCount (); it++) {
- auto p = map_unit->ntList[it];
- p->setIfEmptySelect0 ();
- }
- }
- }
- VOID updateItemPalette (BOOL bUpdateScreen = FALSE) {
- for (auto it =0 ; it != NTPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ntwCell[it];
- if (r.alive () != FALSE)
- r.resetListViewPalette ();
- }
- for (auto it =0 ; it != CLAYPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ClayCell[it];
- if (r.alive () != FALSE)
- r.resetListViewPalette ();
- }
- if (bUpdateScreen != FALSE) {
- for (auto it =0 ; it != NTPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ntwCell[it];
- if (r.alive () != FALSE)
- r.UpdateInfos ();
- }
- for (auto it =0 ; it != CLAYPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ClayCell[it];
- if (r.alive () != FALSE)
- r.UpdateInfos ();
- }
- }
- }
- VOID allocNtpWindow (VOID) {
- for (auto it =0 ; it != NTPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ntwCell[it];
- r.setAttach (this);
- r.Create (*this);
- r.ShowWindow (SW_HIDE);
- }
- }
- VOID clearNtpWindow (VOID) {
- for (auto it =0 ; it != NTPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ntwCell[it];
- r.setNtCell (NULL);
- r.ShowWindow (SW_HIDE);
- }
- }
- CWindowFT &tryAddNtpWindow (CNametableCell<FALSE> *nt_cell) {
- for (auto it =0 ; it != NTPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ntwCell[it];
- if (r.m_pNametableCell == nt_cell) {
- r.ShowWindow (SW_HIDE);
- r.ShowWindow (SW_SHOWNORMAL);
- return r;
- }
- }
- //
- auto &r = m_ntwCell[m_ntpWindowPoll++ % NTPAGE_SHOW_TOG_MAX];
- r.setNtCell (nt_cell);
- r.ShowWindow (SW_HIDE);
- r.ShowWindow (SW_SHOWNORMAL);
- return r;
- }
- CWindowFT *tryUpdateNtpWindow (CNametableCell<FALSE> *nt_cell) {
- for (auto it =0 ; it != NTPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ntwCell[it];
- if (r.m_pNametableCell == nt_cell) {
- r.UpdateInfos ();
- return &r;
- }
- }
- return NULL;
- }
- VOID tryCloseNtpWindow (VOID) {
- for (auto it =0 ; it != NTPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ntwCell[it];
- r.ShowWindow (SW_HIDE);
- }
- }
- VOID allocClayWindow (VOID) {
- for (auto it =0 ; it != CLAYPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ClayCell[it];
- r.setAttach (this);
- r.Create (*this);
- r.ShowWindow (SW_HIDE);
- }
- }
- VOID clearClayWindow (VOID) {
- for (auto it =0 ; it != NTPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ClayCell[it];
- r.setNtCell (NULL);
- r.ShowWindow (SW_HIDE);
- }
- }
- CWindowFT &tryAddClayWindow (CNametableCell<TRUE> *nt_cell) {
- for (auto it =0 ; it != CLAYPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ClayCell[it];
- if (r.m_pNametableCell == nt_cell) {
- r.ShowWindow (SW_HIDE);
- r.ShowWindow (SW_SHOWNORMAL);
- return r;
- }
- }
- //
- auto &r = m_ClayCell[m_ntpWindowPoll++ % CLAYPAGE_SHOW_TOG_MAX];
- r.setNtCell (nt_cell);
- r.ShowWindow (SW_HIDE);
- r.ShowWindow (SW_SHOWNORMAL);
- return r;
- }
- CWindowFT *tryUpdateClayWindow (CNametableCell<TRUE> *nt_cell) {
- for (auto it =0 ; it != CLAYPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ClayCell[it];
- if (r.m_pNametableCell == nt_cell) {
- r.UpdateInfos ();
- return &r;
- }
- }
- return NULL;
- }
- VOID tryCloseClayWindow (VOID) {
- for (auto it =0 ; it != CLAYPAGE_SHOW_TOG_MAX; it++) {
- auto &r = m_ClayCell[it];
- r.ShowWindow (SW_HIDE);
- }
- }
- template <BOOL t_bAddvec>
- SFINLINE void adjustAttrVecBaseNtAddress (CNametableCell<FALSE> *nt_cell, CPoint &point, BYTE vec) {
- ATLASSERT (nt_cell != NULL);
- ATLASSERT (point.x <= 31);
- ATLASSERT (point.y <= 29);
- if (nt_cell->attr != NULL) {
- PBYTE p = nt_cell->attr ->attr;
- if (t_bAddvec != FALSE)
- CGlobals::setAttrBit (p, point.x, point.y,
- CGlobals::getAttrBit (p, point.x, point.y) + vec);
- else
- CGlobals::setAttrBit (p, point.x, point.y, vec);
- }
- }
- template <BOOL t_bAddvec>
- void adjustAttrVecBaseNtAddress (CNametableCell<FALSE> *nt_cell, CPoint &point /* base 8 */, CSize &vec /* base 8 */, BYTE pulseOrSet) {
- ATLASSERT (mapUnit != NULL);
- if (point.x < xMax
- && point.y < yMax )
- {
- // Do clip.
- if (point.x + vec.cx > 32)
- vec.cx = 32 - point.x;
- if (point.y + vec.cy > 32)
- vec.cy = 32 - point.x;
- for (auto y = 0; y < vec.cy; y+= 2) {
- const vtotal = point.y + y;
- for (auto x = 0; x < vec.cx; x+=2) {
- const htotal = point.x + x;
- adjustAttrVecBaseNtAddress <t_bAddvec> (nt_cell, CPoint (htotal, vtotal), pulseOrSet);
- }
- }
- }
- }
- template <BOOL t_bAddvec>
- void adjustAttrVecBaseNtAddress (CMapUnit *mapUnit, CPoint &point /* base 8 */, CSize &vec /* base 8 */, BYTE pulseOrSet) {
- ATLASSERT (mapUnit != NULL);
- const auto xMax = mapUnit->width << 5;
- const auto yMax = mapUnit->height * 30;
- // Check range.
- if (point.x < xMax
- && point.y < yMax )
- {
- // Do clip.
- if (point.x + vec.cx > xMax)
- vec.cx = xMax - point.x;
- if (point.y + vec.cy > yMax)
- vec.cy = yMax - point.x;
- for (auto y = 0; y < vec.cy; y+=2) {
- const auto vtotal = point.y + y;
- const auto vpage = vtotal / 30;
- const auto vmod = vtotal % 30;
- const auto vpage_y = vpage * mapUnit->width;
- for (auto x = 0; x < vec.cx; x+=2) {
- const auto htotal = point.x + x;
- const auto hpage = htotal >> 5;
- const auto hmod = htotal & 31;
- adjustAttrVecBaseNtAddress <t_bAddvec> (mapUnit->ntList[vpage_y+hpage], CPoint (hmod, vmod), pulseOrSet);
- }
- }
- }
- }
- template <BOOL t_bAddvec>
- void adjustAttrVecBaseNtAddress (CMapUnit *mapUnit, CPoint &ptStart /* base 8 */, CPoint &ptEnd /* base 8 */, BYTE pulseOrSet) {
- CPoint ptStart_ = ptStart;
- CPoint ptEnd_ = ptEnd;
- CGlobals::translateVecPointToltrb (ptStart_, ptEnd_);
- adjustAttrVecBaseNtAddress <t_bAddvec> (mapUnit, ptStart_, CSize (ptEnd_.x - ptStart_.x + 1, ptEnd_.y - ptStart_.y + 1), pulseOrSet);
- }
- // <Map scan class > =========================================
- struct CNesMapGenerator: public CScrollWindowImpl <CNesMapGenerator> {
- typedef CNesMapGenerator thisClass;
- typedef CScrollWindowImpl <CNesMapGenerator> baseClass;
- static const WORD alphaCnt = 7;
- static const WORD transShadowMark = PHOTOSHOP_COL_TOGDI16 (0xffffff);
- static const WORD transHitMark = PHOTOSHOP_COL_TOGDI16 (0xcecece);
- CMainFrame &m_attframe;
- CNesMapGenerator (CMainFrame &attframe):
- m_attframe (attframe) {}
- VOID nesPixelGenerator (VOID) {
- // tile mesh, nt mesh
- // switch, tile paste mode | attr adjust mode.
- // unto/ next
- // y - 0~29
- // x - 0~31
- D3DLOCKED_RECT vramLock;
- HRESULT sig;
- CMemoryPaint16::DirectWrite vramWrite;
- CRect rcClient;
- CMainFrame &rFrame = m_attframe;
- CPoint ptPastePoint (m_attframe.m_ptPastePoint);
- BOOL ret = GetClientRect (rcClient);
- ATLASSERT (ret != FALSE);
- CSize szDrawElem (rcClient.Width ()/ 8, rcClient.Height ()/ 8);
- // To align the attr table, I will align a 2 * 2 grid offset
- CPoint ptOffsetAlign (m_ptOffset.x & ~0x0F, m_ptOffset.y & ~0x0F);
- CPoint ptScrStart (ptOffsetAlign.x >> 3, ptOffsetAlign.y >> 3);
- // Try lock direct3d surface...
- sig = rFrame.m_Direct3D9Surface->LockRect (& vramLock, NULL, D3DLOCK_DONOTWAIT | D3DLOCK_DISCARD);
- ATLASSERT (SUCCEEDED (sig));
- vramWrite.pBits = (PWORD)vramLock.pBits;
- vramWrite.Pitch = vramLock.Pitch;
- vramWrite.Pitch16 = vramWrite.Pitch >> 1;
- if (rcClient.Width () >= 128
- && rcClient.Height () >= 128
- && IsWindowVisible () != FALSE
- && rFrame.m_ShowMap != NULL
- && ptScrStart.x < rFrame.m_ShowMap->width * 256
- && ptScrStart.y < rFrame.m_ShowMap->height * 240)
- {
- CSize szSizeMax (rFrame.m_ShowMap->width << 5, rFrame.m_ShowMap->height * 30);
- auto &rGloablNESPal = CGlobals::nespal;
- static BYTE transTile[16];
- static BYTE attrT[64];
- RtlZeroMemory (transTile, sizeof (transTile));
- // Check overflow.
- if (ptScrStart.x + szDrawElem.cx > szSizeMax.cx)
- szDrawElem.cx = szSizeMax.cx - ptScrStart.x;
- if (ptScrStart.y + szDrawElem.cy > szSizeMax.cy)
- szDrawElem.cy = szSizeMax.cy - ptScrStart.y;
- // Draw main nametable buffer
- for (auto j= 0; j != szDrawElem.cy; j++) {
- auto vi = j + ptScrStart.y;
- auto ntp_vi = vi / 30;
- auto mod_y = vi % 30;
- auto vramyT = & vramWrite.pBits[vramWrite.Pitch16 *j<<3];
- if (vi >= szSizeMax.cy) {
- break;
- }
- for (auto i= 0; i != szDrawElem.cx; i++) {
- auto hi = i + ptScrStart.x;
- auto ntp_hi = hi >> 5;
- auto mod_x = hi & 31;
- auto vramT = & vramyT[i << 3];
- if (hi >= szSizeMax.cx) {
- break;
- }
- // fetch namtpage page
- CNametableCell<FALSE> &cell = *rFrame.m_ShowMap->ntList[ntp_hi + rFrame.m_ShowMap->width * ntp_vi];
- // draw tile chunk.
- if (cell.chr != NULL) {
- BYTE palT[] = {
- 0x0F, 0x00, 0x10, 0x30,
- 0x0F, 0x1C, 0x2B, 0x39,
- 0x0F, 0x06, 0x15, 0x36,
- 0x0C, 0x17, 0x28, 0x39
- };
- auto pAttr = attrT;
- auto pPal = palT;
- if (cell.attr != NULL) {
- pAttr = cell.attr->attr;
- }
- if (cell.pal != NULL) {
- RtlCopyMemory (palT, & cell.pal->pal[0], sizeof (palT));
- palT[12] =
- palT[8] =
- palT[4] = palT[0];
- }
- WORD tileSlot = cell.tileSlot[mod_x + (mod_y << 5)];
- PBYTE chrptr;
- if (tileSlot & 0x8000) {
- // Transpant
- chrptr = transTile;
- } else {
- chrptr = & cell.chr->chr[(tileSlot & 255) * 16];
- }
- BYTE attrBank = pAttr [(mod_x >> 2) + (mod_y >> 2 << 3)];
- // calc palette bank
- PBYTE palBank;
- if (mod_y & 2)
- if (mod_x & 2)
- palBank = & pPal[attrBank >> 4 & 0x0C];
- else
- palBank = & pPal[attrBank >> 2 & 0x0C];
- else
- if (mod_x & 2)
- palBank = & pPal[attrBank << 0 & 0x0C];
- else
- palBank = & pPal[attrBank << 2 & 0x0C];
- if ((tileSlot & 0x8000) == 0) {
- for (auto vec = 0; vec != 8; vec++) {
- CPolyData64 cpd64;
- cpd64.blk = CGlobals::chrmixer[chrptr[0]];
- cpd64.blk|= CGlobals::chrmixer[chrptr[8]] << 1;
- vramT[0] = rGloablNESPal[palBank[cpd64.blk8[0]]];
- vramT[1] = rGloablNESPal[palBank[cpd64.blk8[1]]];
- vramT[2] = rGloablNESPal[palBank[cpd64.blk8[2]]];
- vramT[3] = rGloablNESPal[palBank[cpd64.blk8[3]]];
- vramT[4] = rGloablNESPal[palBank[cpd64.blk8[4]]];
- vramT[5] = rGloablNESPal[palBank[cpd64.blk8[5]]];
- vramT[6] = rGloablNESPal[palBank[cpd64.blk8[6]]];
- vramT[7] = rGloablNESPal[palBank[cpd64.blk8[7]]];
- vramT += vramWrite.Pitch16;
- chrptr++;
- }
- } else {
- // Draw transparent
- WORD transMarkClr[4] = { transHitMark, transShadowMark,
- transShadowMark, transHitMark };
- for (DWORD v = 0; v != 8; v++) {
- PWORD clrVPhase = & transMarkClr[v & 2];
- vramT[0] =
- vramT[1] = clrVPhase[0];
- vramT[2] =
- vramT[3] = clrVPhase[1];
- vramT[4] =
- vramT[5] = clrVPhase[0];
- vramT[6] =
- vramT[7] = clrVPhase[1];
- vramT += vramWrite.Pitch16;
- }
- }
- } else {
- // No chr pixel
- // draw trans
- WORD transCol;
- if (cell.pal != NULL)
- transCol = CGlobals::nespal[cell.pal->pal[0]];
- else
- transCol = CGlobals::nespal[0x0F];
- for (auto vec = 0; vec != 8; vec++) {
- vramT[0] = transCol;
- vramT[1] = transCol;
- vramT[2] = transCol;
- vramT[3] = transCol;
- vramT[4] = transCol;
- vramT[5] = transCol;
- vramT[6] = transCol;
- vramT[7] = transCol;
- vramT += vramWrite.Pitch16;
- }
- }
- }
- }
- // Draw attr table number shadow
- if (m_attframe.m_bShowAttrShadow != FALSE) {
- // Draw attr grid alpha
- for (auto j= 0; j != szDrawElem.cy; j++) {
- auto vi = j + ptScrStart.y;
- auto ntp_vi = vi / 30;
- auto mod_y = vi % 30;
- auto vramyT = & vramWrite.pBits[vramWrite.Pitch16 *j<<3];
- if (vi >= szSizeMax.cy) {
- break;
- }
- for (auto i= 0; i != szDrawElem.cx; i++) {
- auto hi = i + ptScrStart.x;
- auto ntp_hi = hi >> 5;
- auto mod_x = hi & 31;
- auto vramT = & vramyT[i << 3];
- if (hi >= szSizeMax.cx) {
- break;
- }
- // fetch namtpage page
- CNametableCell<FALSE> &cell = *rFrame.m_ShowMap->ntList[ntp_hi + rFrame.m_ShowMap->width * ntp_vi];
- // draw tile chunk.
- if (cell.chr != NULL) {
- auto pAttr = attrT;
- if (cell.attr != NULL) {
- pAttr = cell.attr->attr;
- }
- BYTE attrBank = pAttr [(mod_x >> 2) + (mod_y >> 2 << 3)];
- // calc palette bank
- BYTE attrIndex;
- if (mod_y & 2)
- if (mod_x & 2)
- attrIndex = attrBank >> 6 & 3;
- else
- attrIndex = attrBank >> 4 & 3;
- else
- if (mod_x & 2)
- attrIndex = attrBank >> 2 & 3;
- else
- attrIndex = attrBank >> 0 & 3;
- PWORD attrPtr;
- switch (attrIndex) {
- case 0: attrPtr = CGlobals::attrFont0_x2; break;
- case 1: attrPtr = CGlobals::attrFont1_x2; break;
- case 2: attrPtr = CGlobals::attrFont2_x2; break;
- case 3: attrPtr = CGlobals::attrFont3_x2; break;
- default:
- ATLASSERT (FALSE);
- break;
- }
- attrPtr = & attrPtr[ (mod_y & 1) ? 8 * 16 : 0];
- attrPtr = & attrPtr[ (mod_x & 1) ? 8 : 0];
- for (auto vec = 0; vec != 8; vec++) {
- vramT[0] = CGlobals::alpha16 ( attrPtr[0], vramT[0], alphaCnt, 15 - alphaCnt);
- vramT[1] = CGlobals::alpha16 ( attrPtr[1], vramT[1], alphaCnt, 15 - alphaCnt);
- vramT[2] = CGlobals::alpha16 ( attrPtr[2], vramT[2], alphaCnt, 15 - alphaCnt);
- vramT[3] = CGlobals::alpha16 ( attrPtr[3], vramT[3], alphaCnt, 15 - alphaCnt);
- vramT[4] = CGlobals::alpha16 ( attrPtr[4], vramT[4], alphaCnt, 15 - alphaCnt);
- vramT[5] = CGlobals::alpha16 ( attrPtr[5], vramT[5], alphaCnt, 15 - alphaCnt);
- vramT[6] = CGlobals::alpha16 ( attrPtr[6], vramT[6], alphaCnt, 15 - alphaCnt);
- vramT[7] = CGlobals::alpha16 ( attrPtr[7], vramT[7], alphaCnt, 15 - alphaCnt);
- vramT += vramWrite.Pitch16;
- attrPtr += 16;
- }
- }
- }
- }
- }
- // Draw paste infos..
- // Tracker movse infos...
- // FIXME: more case.
- CPoint ptMouse;
- :: GetCursorPos (& ptMouse);
- ScreenToClient (& ptMouse);
- auto &tilePaste = CGlobals::pasteTile;
- if (CGlobals::pasteAlive () != FALSE
- && ptMouse.x >= 0
- && ptMouse.y >= 0) {
- CSize copySize = tilePaste.copySize;
- auto &rNametableS = tilePaste.tileSlot;
- auto &palT = tilePaste.palSlot;
- auto &attrT = tilePaste.attrSlot;
- auto &chrT = tilePaste.chr->chr;
- ptMouse.x >>= 3;
- ptMouse.y >>= 3;
- for (auto j = 0; j != copySize.cy; j++) {
- for (auto i = 0; i != copySize.cx; i++) {
- DWORD x2_pos = i + ptMouse.x << 3;
- DWORD y2_pos = j + ptMouse.y << 3;
- DWORD x_pos= i << 3;
- DWORD y_pos = j << 3;
- WORD tileSlot = rNametableS[i+ (j << 5)];
- PWORD vramT = & vramWrite.pBits[x2_pos + y2_pos *vramWrite.Pitch16];
- PBYTE pChrT = tileSlot & 0x8000 ? transTile : & chrT[(tileSlot & 255) << 4];
- auto attrByte = attrT[(i >> 2)+(j >> 2<<3)];
- if (j & 2)
- if (i & 2)
- attrByte = attrByte >> 6 & 3;
- else
- attrByte = attrByte >> 4 & 3;
- else
- if (i & 2)
- attrByte = attrByte >> 2 & 3;
- else
- attrByte &= 3;
- auto pBank = & palT[attrByte << 2];
- if ((tileSlot & 0x8000) == 0) {
- for (DWORD v = 0; v != 8; v++) {
- CPolyData64 chr;
- chr.blk = CGlobals::chrmixer[pChrT[0]]
- | CGlobals::chrmixer[pChrT[8]] << 1;
- vramT[0] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[0]]], vramT[0], alphaCnt, 15 - alphaCnt);
- vramT[1] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[1]]], vramT[1], alphaCnt, 15 - alphaCnt);
- vramT[2] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[2]]], vramT[2], alphaCnt, 15 - alphaCnt);
- vramT[3] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[3]]], vramT[3], alphaCnt, 15 - alphaCnt);
- vramT[4] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[4]]], vramT[4], alphaCnt, 15 - alphaCnt);
- vramT[5] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[5]]], vramT[5], alphaCnt, 15 - alphaCnt);
- vramT[6] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[6]]], vramT[6], alphaCnt, 15 - alphaCnt);
- vramT[7] = CGlobals::alpha16 ( rGloablNESPal[pBank[chr.blk8[7]]], vramT[7], alphaCnt, 15 - alphaCnt);
- vramT += vramWrite.Pitch16;
- pChrT++;
- }
- }
- }
- }
- }
- // Draw grid attr..
- if (m_attframe.m_bShowGridAttr != FALSE) {
- CMemoryPaint16::DirectWrite vramOffset = vramWrite;
- CPoint ptStart = ptScrStart;
- CSize copySize = szDrawElem;
- // Check copy align
- if (copySize.cx & 1) {
- copySize.cx ++;
- }
- if (copySize.cy & 1) {
- copySize.cy ++;
- }
- CSize szCopy ( copySize.cx / 2, copySize.cy / 2);
- for (auto scanY = 0; scanY != szCopy.cy; scanY++) {
- for (auto scanX = 0; scanX != szCopy.cx; scanX++) {
- CGlobals::drawGrid (vramOffset,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (scanX << 4, scanY << 4),
- CSize (16, 16),
- CSize (1, 1),
- clrMeshAttr);
- }
- }
- }
- // Draw grid main...
- CPoint ptStart = ptScrStart;
- if (m_attframe.m_bShowGridMain != FALSE) {
- CSize szCopy = szDrawElem;
- szCopy.cx = szCopy.cx/ 32 + 1;
- szCopy.cy = szCopy.cy/ 30 + 1;
- const WORD mixerClr[] =
- { CMainFrame::clrMeshMainOne,
- CMainFrame::clrMeshMainTwo,
- CMainFrame::clrMeshMainTwo,
- CMainFrame::clrMeshMainOne };
- DWORD yRectPos = 0;
- for (auto scanY = 0; scanY != szCopy.cy; scanY++) {
- const WORD *mixerClrY = & mixerClr[ (ptStart.y + yRectPos) / 30 << 1 & 2];
- DWORD copyYSize;
- if ( (scanY == 0 || scanY == szCopy.cy - 1)
- && (ptStart.y % 30) != 0){
- // first/final check.. do unaign copy.
- copyYSize = scanY == 0
- ? 30 - ptStart.y % 30
- : szDrawElem.cy - yRectPos;
- if (copyYSize > 30) {
- copyYSize = 30;
- szCopy.cy ++;
- }
- } else {
- copyYSize = 30;
- }
- DWORD xRectPos = 0;
- for (auto scanX = 0; scanX != szCopy.cx; scanX++) {
- const WORD clrset = mixerClrY[ptStart.x + xRectPos >> 5 & 1];
- DWORD copyXSize;
- if ( (scanX == 0 || scanX == szCopy.cx - 1)
- && (ptStart.x % 32) != 0){
- // first/final check.. do unaign copy.
- copyXSize = scanX == 0
- ? 32 - ptStart.x % 32
- : szDrawElem.cx - xRectPos;
- if (copyXSize > 32) {
- copyXSize = 32;
- szCopy.cx ++;
- }
- } else {
- copyXSize = 32;
- }
- CGlobals::drawGrid (vramWrite,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (xRectPos << 3, yRectPos << 3),
- CSize (copyXSize * 8, copyYSize * 8),
- CSize (1, 1),
- clrset);
- xRectPos += copyXSize;
- if (xRectPos >= szDrawElem.cx) {
- break;
- }
- }
- yRectPos += copyYSize;
- if (yRectPos >= szDrawElem.cy) {
- break;
- }
- }
- }
- // x, y coord push 32 offset
- // vramWrite.pBits = & vramWrite.pBits[32+vramWrite.Pitch16*32];
- if ( m_attframe.m_subFunc == 1
- && m_attframe.m_dwStateAttr != 0)
- {
- // Max size
- // 256 x 240
- // 128 x 120
- // 16 x 15
- CPoint ptStart = m_attframe. m_ptTrackAttrStart ;
- CPoint ptEnd = m_attframe. m_ptTrackAttrEnd;
- CPoint ptScr8 ( ptOffsetAlign.x >> 3, ptOffsetAlign.y >> 3);
- CGlobals::translateVecPointToltrb (ptStart, ptEnd);
- ptStart.x >>= 3;
- ptStart.y >>= 3;
- ptEnd.x >>= 3;
- ptEnd.y >>= 3;
- CMemoryPaint16::DirectWrite vramOffset = vramWrite;
- CSize copySize;
- if (ptScr8.x & 1) vramOffset.pBits = vramOffset.pBits - 8;
- if (ptScr8.y & 1) vramOffset.pBits = vramOffset.pBits - 8 * vramOffset.Pitch16;
- if (ptStart.x & 1) ptStart.x &= ~1;
- if (ptStart.y & 1) ptStart.y &= ~1;
- if (ptEnd.x & 1) ptEnd.x &= ~1;
- if (ptEnd.y & 1) ptEnd.y &= ~1;
- copySize.cx = ptEnd.x - ptStart.x + 2<< 3;
- copySize.cy = ptEnd.y - ptStart.y + 2<< 3;
- if ( copySize.cx > 256)
- copySize.cx = 256;
- if ( copySize.cy > 240)
- copySize.cy = 240;
- if ( copySize.cx == 0)
- copySize.cx = 16;
- if ( copySize.cy == 0)
- copySize.cy = 16;
- CGlobals::drawGrid (vramOffset,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (ptStart.x << 3, ptStart.y << 3) ,
- copySize,
- CSize (1, 1),
- m_attframe.m_dwStateAttr & 0x8000
- ? CMainFrame::clrMeshCatching
- : CMainFrame::clrMeshSet);
- }
- } else {
- // fill clear color .....
- CMemoryPaint16::fillColor (vramWrite,
- CPoint (0, 0),
- rcClient.Size (), 0);
- }
- LPDIRECT3DSURFACE9 vsurf;
- sig = rFrame.m_Direct3D9Deivce->Clear (0, NULL, D3DCLEAR_TARGET, 0, 0.0, 0);
- ATLASSERT (SUCCEEDED (sig));
- sig = rFrame.m_Direct3D9Deivce->GetBackBuffer (0, 0, D3DBACKBUFFER_TYPE_MONO, & vsurf);
- ATLASSERT (SUCCEEDED (sig));
- sig = rFrame.m_Direct3D9Surface->UnlockRect ();
- ATLASSERT (SUCCEEDED (sig));
- sig = rFrame.m_Direct3D9Deivce->UpdateSurface (rFrame.m_Direct3D9Surface,
- & CRect (0, 0, szDrawElem.cx << 3, szDrawElem.cy << 3),
- vsurf,
- & CPoint (0, 0));
- ATLASSERT (SUCCEEDED (sig));
- sig = vsurf->Release ();
- ATLASSERT (SUCCEEDED (sig));
- // Copy rect to vram...
- // FIXME: Maybe the device will be lost when other programs are using the full screen Direct3D program
- sig = rFrame.m_Direct3D9Deivce->Present (
- & CRect (0, 0, rcClient.Width (), rcClient.Height ()),
- & CRect (0, 0, rcClient.Width (), rcClient.Height ()), NULL, NULL);
- ATLASSERT (SUCCEEDED (sig));
- }
- VOID DoPaint(CDCHandle dc)
- {
- // must be implemented in a derived class
- // ATLASSERT(FALSE);
- // int is = 0;
- nesPixelGenerator ();
- }
- LRESULT OnPaint (UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) {
- :: ValidateRect (*this, NULL);
- nesPixelGenerator ();
- bHandled = TRUE;
- return 0;
- }
- LRESULT OnLButtonDbclk (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- // Show spec page window.
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnLButtonUp (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- if (m_attframe.m_subFunc == 1
- && (m_attframe.m_dwStateAttr & 0x8001 ) == 0x8001) {
- m_attframe.m_dwStateAttr &= ~0x8000;
- m_attframe. m_ptTrackAttrEnd.x = pt.x ;
- m_attframe. m_ptTrackAttrEnd.y = pt.y ;
- }
- nesPixelGenerator ();
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnLButtonDown (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled) {
- bHandled = FALSE;
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- CRect rcClient;
- CMainFrame &rFrame = m_attframe;
- CPoint ptPastePoint (pt);
- CPoint ptScrStart (m_ptOffset.x & ~0x0F, m_ptOffset.y & ~0x0F);
- BOOL ret = GetClientRect (rcClient);
- ATLASSERT (ret != FALSE);
- CSize szDrawElem (rcClient.Width () >> 3, rcClient.Height () >> 3);
- if (m_attframe.m_subFunc == 0
- && CGlobals::pasteAlive () != FALSE
- && CGlobals::pasteTile.chr != NULL
- && m_attframe.m_ShowMap != NULL
- && ptPastePoint.x < rFrame.m_ShowMap->width * 256
- && ptPastePoint.y < rFrame.m_ShowMap->height * 240
- && ptScrStart.x < rFrame.m_ShowMap->width * 256
- && ptScrStart.y < rFrame.m_ShowMap->height * 240) {
- // Paste/ edit.
- // overwrite tile id, natadssa
- CSize szSizeMax (rFrame.m_ShowMap->width << 5, rFrame.m_ShowMap->height * 30);
- CSize scanVec (CGlobals::pasteTile.copySize);
- CPoint ptScroll (ptScrStart.x >> 3, ptScrStart.y >> 3);
- CPoint ptPaste (GET_X_LPARAM(lParam) >> 3, GET_Y_LPARAM(lParam) >> 3);
- // Scroll + paste point .
- CPoint ptOffsetCorrentBaseT = ptScroll + ptPaste;
- if (ptOffsetCorrentBaseT.x + scanVec.cx > szSizeMax.cx)
- scanVec.cx = szSizeMax.cx - ptOffsetCorrentBaseT.x;
- if (ptOffsetCorrentBaseT.y + scanVec.cy > szSizeMax.cy)
- scanVec.cy = szSizeMax.cy - ptOffsetCorrentBaseT.y;
- if (ptOffsetCorrentBaseT.x < szSizeMax.cx
- && ptOffsetCorrentBaseT.y < szSizeMax.cy)
- {
- auto &srcTile = CGlobals::pasteTile;
- // Adjust attr and tile id
- for (auto j = 0; j != scanVec.cy; j++) {
- auto vi = j + ptOffsetCorrentBaseT.y;
- auto ntp_vi = vi / 30;
- auto mod_y = vi % 30;
- for (auto i = 0; i != scanVec.cx; i++) {
- auto hi = i + ptOffsetCorrentBaseT.x;
- auto ntp_hi = hi >> 5;
- auto mod_x = hi & 31;
- // fetch namtpage page
- CNametableCell<FALSE> &cell = *rFrame.m_ShowMap->ntList[ntp_hi + rFrame.m_ShowMap->width * ntp_vi];
- WORD dstTileId = srcTile.tileSlot[(j << 5) + i];
- if ((dstTileId & 0x8000) == 0) {
- cell.tileSlot[(mod_y << 5) + mod_x] = dstTileId;
- if (srcTile.hackAttr != FALSE
- && cell.attr != NULL)
- {
- BYTE srcAttr = srcTile.attrSlot[(i>>2) + (j>>2<<3)];
- PBYTE dstAttr = & cell.attr->attr[(mod_x>>2) + (mod_y>>2<<3)];
- if (j & 2)
- if (i& 2) srcAttr = srcAttr >> 6 & 3;
- else srcAttr = srcAttr >> 4 & 3;
- else
- if (i& 2)srcAttr = srcAttr >> 2 & 3;
- else srcAttr = srcAttr >> 0 & 3;
- if (mod_y & 2)
- if (mod_x& 2) dstAttr[0] = dstAttr[0] & ~0xC0 | srcAttr << 6;
- else dstAttr[0] = dstAttr[0] & ~0x30 | srcAttr << 4;
- else
- if (mod_x& 2)dstAttr[0] = dstAttr[0] & ~0x0C | srcAttr << 2;
- else dstAttr[0] = dstAttr[0] & ~0x03 | srcAttr << 0;
- }
- }
- if (srcTile.hackPal != FALSE
- && cell.pal != NULL)
- {
- // TODO: more copy ..
- RtlCopyMemory (cell.pal->pal, srcTile.palSlot, sizeof (cell.pal->pal));
- }
- }
- }
- }
- } else if (m_attframe.m_subFunc == 1) {
- // Attr edit
- m_attframe. m_ptTrackAttrStart.x = pt.x ;
- m_attframe. m_ptTrackAttrStart.y = pt.y ;
- m_attframe. m_ptTrackAttrEnd = m_attframe. m_ptTrackAttrStart;
- m_attframe. m_dwStateAttr = 0x8000 | 1;
- } else if (m_attframe.m_subFunc == 2) {
- }
- nesPixelGenerator ();
- SetFocus ();
- return 0;
- }
- LRESULT OnRButtonDbclk (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- // Show spec page window.
- CRect rcClient;
- CMainFrame &rFrame = m_attframe;
- CPoint ptPastePoint (pt);
- CPoint ptScrStart (m_ptOffset.x & ~0x0F, m_ptOffset.y & ~0x0F);
- BOOL ret = GetClientRect (rcClient);
- ATLASSERT (ret != FALSE);
- CSize szDrawElem (rcClient.Width () >> 3, rcClient.Height () >> 3);
- if (m_attframe.m_subFunc == 0
- && m_attframe.m_ShowMap != NULL
- && rcClient.Width () > 0
- && rcClient.Height () > 0
- && m_attframe.m_GuiLV_Page.GetItemCount () > 0
- && ptPastePoint.x < rFrame.m_ShowMap->width * 256
- && ptPastePoint.y < rFrame.m_ShowMap->height * 240) {
- // Paste/ edit.
- // overwrite tile id, natadssa
- CSize szSizeMax (rFrame.m_ShowMap->width << 5, rFrame.m_ShowMap->height * 30);
- CSize scanVec (CGlobals::pasteTile.copySize);
- CPoint ptScroll (ptScrStart.x >> 3, ptScrStart.y >> 3);
- CPoint ptPaste (GET_X_LPARAM(lParam) >> 3, GET_Y_LPARAM(lParam) >> 3);
- // Scroll + paste point .
- CPoint ptOffsetCorrentBaseT = ptScroll + ptPaste;
- if (ptOffsetCorrentBaseT.x < szSizeMax.cx
- && ptOffsetCorrentBaseT.y < szSizeMax.cy)
- {
- auto v = ptOffsetCorrentBaseT.y / 30;
- auto h = ptOffsetCorrentBaseT.x / 32;
- // fetch namtpage page
- CNametableCell<FALSE> *nt_cell = rFrame.m_ShowMap->ntList[h + rFrame.m_ShowMap->width * v];
- ATLASSERT (nt_cell != NULL);
- m_attframe. tryAddNtpWindow (nt_cell).
- SetWindowTextFT (_T ("%s-%s"), nt_cell->comment, nt_cell->chr ? nt_cell->chr->comment : _T ("null"));
- }
- } else if (m_attframe.m_subFunc == 1) {
- // Attr edit
- } else if (m_attframe.m_subFunc == 2) {
- }
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnRButtonUp (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- if (CGlobals::pasteAlive () != FALSE) {
- CGlobals::makePasteDead ();
- }
- if (m_attframe.m_subFunc == 1
- && (m_attframe.m_dwStateAttr & 0x8001 ) == 0x0001) {
- // Adjust attr table vector .
- CPoint ptScrStart (m_ptOffset.x & ~0x0F, m_ptOffset.y & ~0x0F);
- CPoint ptStart ( (m_attframe. m_ptTrackAttrStart.x & ~7)+ (ptScrStart.x & ~7) >> 4 << 1,
- (m_attframe. m_ptTrackAttrStart.y & ~7)+ (ptScrStart.y & ~7) >> 4 << 1);
- CPoint ptEnd ( (m_attframe. m_ptTrackAttrEnd.x & ~7)+ (ptScrStart.x & ~7) >> 4 << 1,
- (m_attframe. m_ptTrackAttrEnd.y & ~7)+ (ptScrStart.y & ~7) >> 4 << 1);
- CGlobals::
- translateVecPointToltrbLimitRange
- ( ptStart, ptEnd, CSize (31, 29));
- m_attframe.adjustAttrVecBaseNtAddress<TRUE>
- (m_attframe.m_ShowMap, ptStart, ptEnd, 1);
- m_attframe.allViewUpdate ();
- }
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnRButtonDown (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnMouseMove (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- CRect rcClient;
- BOOL ret = GetClientRect (rcClient);
- ATLASSERT (ret != FALSE);
- if (rcClient.Width () >= 0
- && rcClient.Height () >= 0
- && m_attframe.m_ShowMap != 0
- /* && CGlobals::bLockPaste != FALSE */ )
- {
- CSize szDrawElem (rcClient.Width ()/ 8, rcClient.Height ()/ 8);
- CPoint ptScrStart (m_ptOffset.x & ~0x0F, m_ptOffset.y & ~0x0F);
- CSize szSizeMax (m_attframe.m_ShowMap->width * 32, m_attframe.m_ShowMap->height * 30);
- m_attframe.m_ptPastePoint.x = pt.x / 8;
- m_attframe.m_ptPastePoint.y = pt.y / 8;
- }
- if (m_attframe.m_subFunc == 1
- && (m_attframe.m_dwStateAttr & 0x8001 ) == 0x8001) {
- m_attframe. m_ptTrackAttrEnd.x = pt.x ;
- m_attframe. m_ptTrackAttrEnd.y = pt.y ;
- }
- CPoint ptStart = pt + m_ptOffset ;
- m_attframe.setStatusText (1, _T ("page-%d, %d index- %d, %d")
- , ptStart.x / 256, ptStart.y / 240
- , ptStart.x % 256 >> 3
- , ptStart.y % 240 >> 3);
- nesPixelGenerator ();
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnKeyUp (UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) {
- switch (wParam) {
- case 96:
- case 97:
- case 98:
- case 99:
- case '0':
- case '1':
- case '2':
- case '3':
- if ( m_attframe. m_subFunc == 1
- && (m_attframe.m_dwStateAttr & 0x7FFF) != 0)
- {
- CPoint ptScrStart (m_ptOffset.x & ~0x0F, m_ptOffset.y & ~0x0F);
- CPoint ptStart ( (m_attframe. m_ptTrackAttrStart.x & ~7)+ (ptScrStart.x & ~7) >> 4 << 1,
- (m_attframe. m_ptTrackAttrStart.y & ~7)+ (ptScrStart.y & ~7) >> 4 << 1);
- CPoint ptEnd ( (m_attframe. m_ptTrackAttrEnd.x & ~7)+ (ptScrStart.x & ~7) >> 4 << 1,
- (m_attframe. m_ptTrackAttrEnd.y & ~7)+ (ptScrStart.y & ~7) >> 4 << 1);
- CGlobals::
- translateVecPointToltrbLimitRange
- ( ptStart, ptEnd, CSize (31, 29));
- m_attframe.adjustAttrVecBaseNtAddress<FALSE>
- (m_attframe.m_ShowMap, ptStart, ptEnd, (wParam >= 96 && wParam <= 99)
- ? (wParam - 96 & 3)
- : (wParam - '0' & 3));
- m_attframe.allViewUpdate ();
- }
- break;
- case 'M':
- m_attframe.m_bShowAttrShadow = ! m_attframe.m_bShowAttrShadow;
- nesPixelGenerator ();
- break;
- case VK_RETURN:
- {
- m_attframe.m_subFunc ++;
- m_attframe.m_subFunc %= 2;
- m_attframe.m_dwStateAttr = 0;
- m_attframe.m_dwStateChr = 0;
- m_attframe.m_dwStateRorate = 0;
- if (m_attframe.m_subFunc == 0) {
- m_attframe.setStatusText (0, CString (_T ("map:paste mode")));
- } else {
- m_attframe.setStatusText (0, CString (_T ("map:attr mode")));
- }
- nesPixelGenerator ();
- }
- break;
- case ' ':
- {
- CPoint pt ;
- GetCursorPos (& pt);
- ScreenToClient (& pt);
- pt.x = abs (pt.x);
- pt.y = abs (pt.y);
- // Show spec page window.
- CRect rcClient;
- CMainFrame &rFrame = m_attframe;
- CPoint ptPastePoint (pt);
- CPoint ptScrStart (m_ptOffset.x & ~0x0F, m_ptOffset.y & ~0x0F);
- BOOL ret = GetClientRect (rcClient);
- ATLASSERT (ret != FALSE);
- CSize szDrawElem (rcClient.Width () >> 3, rcClient.Height () >> 3);
- if (m_attframe.m_ShowMap != NULL
- && rcClient.Width () > 0
- && rcClient.Height () > 0
- && m_attframe.m_GuiLV_Page.GetItemCount () > 0
- && ptPastePoint.x < rFrame.m_ShowMap->width * 256
- && ptPastePoint.y < rFrame.m_ShowMap->height * 240) {
- // Paste/ edit.
- // overwrite tile id, natadssa
- CSize szSizeMax (rFrame.m_ShowMap->width << 5, rFrame.m_ShowMap->height * 30);
- CSize scanVec (CGlobals::pasteTile.copySize);
- CPoint ptScroll (ptScrStart.x >> 3, ptScrStart.y >> 3);
- CPoint ptPaste (ptPastePoint.x >> 3, ptPastePoint.y >> 3);
- // Scroll + paste point .
- CPoint ptOffsetCorrentBaseT = ptScroll + ptPaste;
- if (ptOffsetCorrentBaseT.x < szSizeMax.cx
- && ptOffsetCorrentBaseT.y < szSizeMax.cy)
- {
- auto v = ptOffsetCorrentBaseT.y / 30;
- auto h = ptOffsetCorrentBaseT.x / 32;
- // fetch namtpage page
- CNametableCell<FALSE> *nt_cell = rFrame.m_ShowMap->ntList[h + rFrame.m_ShowMap->width * v];
- ATLASSERT (nt_cell != NULL);
- auto &r = m_attframe. tryAddNtpWindow (nt_cell);
- r.SetWindowTextFT (_T ("%s-%s"), nt_cell->comment, nt_cell->chr ? nt_cell->chr->comment : _T ("null"));
- }
- }
- }
- break;
- case 'Q':
- m_attframe.m_bShowGridMain = !m_attframe.m_bShowGridMain;
- nesPixelGenerator ();
- break;
- case 'Z':
- m_attframe.m_bShowGridAttr = !m_attframe.m_bShowGridAttr;
- nesPixelGenerator ();
- default:
- break;
- }
- bHandled = FALSE;
- return 0;
- }
- DECLARE_WND_CLASS (_T ("CNesmapGenerator"))
- BEGIN_MSG_MAP(thisClass)
- MESSAGE_HANDLER (WM_LBUTTONDBLCLK, OnLButtonDbclk)
- MESSAGE_HANDLER (WM_LBUTTONUP, OnLButtonUp)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDown)
- MESSAGE_HANDLER (WM_RBUTTONDBLCLK, OnRButtonDbclk)
- MESSAGE_HANDLER (WM_RBUTTONUP, OnRButtonUp)
- MESSAGE_HANDLER (WM_RBUTTONDOWN, OnRButtonDown)
- MESSAGE_HANDLER (WM_MOUSEMOVE, OnMouseMove)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUp)
- // MESSAGE_HANDLER (WM_PAINT, OnPaint)
- CHAIN_MSG_MAP(baseClass)
- END_MSG_MAP()
- } m_GuiSWin_Nesmap;
- // <CClaySettings> =========================================
- struct CClaySettings : public CDialogImpl<CClaySettings>
- {
- typedef CClaySettings thisClass;
- typedef CDialogImpl<CClaySettings> baseClass;
- CMainFrame &m_attchthis;
- CNametableCell<TRUE> *m_attachcell;
- CClaySettings (CMainFrame &atthis):
- m_attchthis (atthis),
- m_attachcell (NULL) {}
- enum { IDD = IDD_CLAY_LIST_SETTINGS };
- BEGIN_MSG_MAP(thisClass)
- MESSAGE_HANDLER (WM_INITDIALOG, OnCreate)
- MESSAGE_HANDLER (WM_CLOSE, OnClose)
- COMMAND_ID_HANDLER (IDBT_CLAY_RESET, OnSet)
- END_MSG_MAP()
- LRESULT OnClose (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- bHandled = FALSE;
- EndDialog (IDCANCEL);
- return 0;
- }
- LRESULT OnCreate (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- if (m_attachcell != NULL) {
- // Fill current pal infos.
- CWindowFT (GetDlgItem (IDET_CLAYCOMMENT))
- .SetWindowTextFT (m_attachcell->comment);
- }
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnSet (WORD, WORD, HWND /*lParam*/, BOOL& bHandled) {
- CEdit etComment = GetDlgItem (IDET_CLAYCOMMENT);
- CString content;
- BOOL bpushNewItem = m_attachcell == NULL;
- if (bpushNewItem != FALSE) {
- m_attachcell = new CNametableCell<TRUE> (
- m_attchthis.m_globalPal
- , m_attchthis.m_globalPal);
- }
- etComment .GetWindowText (content);
- m_attachcell->comment = content;
- CGlobals::adjustCommentUnique<CNametableCell<TRUE>> (m_attchthis.m_VnpVec, m_attachcell, bpushNewItem);
- EndDialog (IDOK);
- bHandled = FALSE;
- return 0;
- }
- INT_PTR DoModal ( CNametableCell<TRUE> *nt_cell = NULL)
- {
- m_attachcell = nt_cell;
- // Modal it.
- return baseClass::DoModal ();
- }
- };
- // <CMainFrame::CMapSettings Start> =========================================
- struct CMapSettings : public CDialogImpl<CMapSettings>
- {
- typedef CMapSettings thisClass;
- typedef CDialogImpl<CMapSettings> baseClass;
- CEditT<CWindowFT> m_GuiET_ReqW;
- CEditT<CWindowFT> m_GuiET_ReqH;
- CButtonT<CWindowFT> m_GuiBT_Cleardata;
- CEditT<CWindowFT> m_GuiET_Fillid;
- CEditT<CWindowFT> m_GuiET_Comment;
- CButtonT<CWindowFT> m_GuiBT_Settings;
- CMainFrame &m_attthis;
- CMapUnit *m_newmap;
- CMapSettings (CMainFrame &psthis):
- m_attthis (psthis),
- m_newmap (NULL) {}
- enum { IDD = IDD_NAMETABLE_PAGE_SETTINGS };
- BEGIN_MSG_MAP(thisClass)
- MESSAGE_HANDLER (WM_INITDIALOG, OnCreate)
- MESSAGE_HANDLER (WM_CLOSE, OnClose)
- COMMAND_ID_HANDLER (IDET_NTS_SETTINGS, OnSet)
- END_MSG_MAP()
- LRESULT OnClose (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- bHandled = FALSE;
- EndDialog (IDCANCEL);
- return 0;
- }
- LRESULT OnCreate (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- m_GuiET_ReqW.Attach (GetDlgItem (IDET_NTS_WSIZE));
- m_GuiET_ReqH.Attach (GetDlgItem (IDET_NTS_HSIZE));
- m_GuiBT_Cleardata.Attach (GetDlgItem (IDCK_NTS_CLEARDATA));
- m_GuiET_Fillid.Attach (GetDlgItem (IDET_NTS_FILL));
- m_GuiET_Comment.Attach (GetDlgItem (IDET_NTS_COMMENT));
- m_GuiBT_Settings.Attach (GetDlgItem (IDET_NTS_SETTINGS));
- if (m_newmap != NULL) {
- // Fill current pal infos.
- // etComment.SetWindowText (m_newmap->comment);
- m_GuiET_ReqW.SetWindowTextFT (_T ("%d"), m_newmap->width);
- m_GuiET_ReqH.SetWindowTextFT (_T ("%d"), m_newmap->height);
- m_GuiET_Fillid.SetWindowTextFT (_T ("8000"));
- m_GuiET_Comment.SetWindowTextFT (m_newmap->comment);
- }
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnSet (WORD, WORD, HWND /*lParam*/, BOOL& bHandled) {
- // Get dialog pos infos.
- CString string;
- auto req_w = GetDlgItemInt (IDET_NTS_WSIZE, NULL, FALSE);
- auto req_h = GetDlgItemInt (IDET_NTS_HSIZE, NULL, FALSE);
- BOOL clear = m_GuiBT_Cleardata.GetCheck () == BST_CHECKED;
- BOOL bpushnewItem = m_newmap == NULL;
- m_GuiET_Fillid.GetWindowText (string);
- WORD fillId = _tcstol (string.GetString (), NULL, 16) & 0xFFFF;
- if (req_w == 0
- || req_h == 0)
- {
- AtlMessageBox (NULL, _T ("Request w | h := 0!"), _T ("Map settings"), MB_ICONERROR);
- return 0;
- }
- #if 1
- if (req_w > 64
- || req_h > 64)
- {
- AtlMessageBox (NULL, _T ("Request w | h > 64!"), _T ("Map settings"), MB_ICONERROR);
- return 0;
- }
- #endif
- if (bpushnewItem != FALSE
- && m_newmap == NULL)
- {
- m_newmap= new CMapUnit (m_attthis.m_globalPal);
- }
- // reset map.
- m_GuiET_Comment. GetWindowText (m_newmap->comment);
- m_newmap->resetMap (req_w, req_h,
- clear, fillId);
- CGlobals::adjustCommentUnique
- (m_attthis.m_MapVec,
- m_newmap,
- bpushnewItem);
- EndDialog (IDOK);
- bHandled = FALSE;
- return 0;
- }
- INT_PTR DoModal (CMapUnit *map = NULL)
- {
- m_newmap = map;
- // Modal it.
- return baseClass::DoModal ();
- }
- };
- template <DWORD t_dwControlId>
- LRESULT OnLButtonDblclk (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_CLAY:
- {
- // Process default message first
- m_GuiLV_Clay.DefWindowProc (uMsg, wParam, lParam);
- int itemSel = m_GuiLV_Clay.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL);
- if (itemSel >= 0) {
- auto nt_cell = m_GuiLV_Clay.GetItemDataT (itemSel);
- if (nt_cell != NULL) {
- tryAddClayWindow (nt_cell).
- SetWindowTextFT (_T ("%s-%s"),
- m_GuiLV_Clay.GetItemTextAMC (itemSel, 0),
- nt_cell->chr ? nt_cell->chr->comment : _T ("null"));
- }
- }
- }
- break;
- case MAP_CONTROL_LV_PAGE:
- {
- // Process default message first
- m_GuiLV_Page.DefWindowProc (uMsg, wParam, lParam);
- int itemSel = m_GuiLV_Page.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL);
- if (itemSel >= 0) {
- auto nt_cell = m_GuiLV_Page.GetItemDataT (itemSel);
- if (nt_cell != NULL) {
- tryAddNtpWindow (nt_cell).
- SetWindowTextFT (_T ("%s-%s"),
- m_GuiLV_Page.GetItemTextAMC (itemSel, 0),
- nt_cell->chr ? nt_cell->chr->comment : _T ("null"));
- }
- }
- }
- default:
- break;
- }
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnRButtonDownT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- switch (t_dwControlId) {
- // case MAP_CONTROL_LV_MAP:
- case MAP_CONTROL_LV_PAGE:
- if (m_GuiLV_Page.GetNextItem (-1, LVNI_SELECTED) >= 0) {
- bHandled = TRUE;
- m_GuiLV_Page.ClientToScreen (& pt);
- m_GuiMenu_MapAttach.EnableMenuItem (ID_SETPAGE_SPAL, MF_ENABLED | MF_BYCOMMAND);
- m_GuiMenu_MapAttach.TrackPopupMenu (0, pt.x, pt.y, m_GuiLV_Page);
- }
- break;
- case MAP_CONTROL_LV_CLAY:
- if (m_GuiLV_Clay.GetNextItem (-1, LVNI_SELECTED) >= 0) {
- bHandled = TRUE;
- m_GuiLV_Clay.ClientToScreen (& pt);
- m_GuiMenu_MapAttach.EnableMenuItem (ID_SETPAGE_SPAL, MF_GRAYED | MF_BYCOMMAND);
- m_GuiMenu_MapAttach.TrackPopupMenu (0, pt.x, pt.y, m_GuiLV_Clay);
- }
- default:
- break;
- }
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnRButtonUpT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- switch (t_dwControlId) {
- // case MAP_CONTROL_LV_MAP:
- case MAP_CONTROL_LV_PAGE:
- bHandled = TRUE;
- default:
- break;
- }
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnLButtonDownT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_MAP:
- {
- // Process default message first
- m_GuiLV_Map.DefWindowProc (uMsg, wParam, lParam);
- auto index = m_GuiLV_Map.GetSelectedIndex ();
- auto *poldname =m_ShowMap;
- // m_GuiLV_PalList.Pro
- if (index >= 0) {
- CMapUnit *map = (CMapUnit *) m_GuiLV_Map.GetItemData (index);
- if (map != NULL) {
- m_ShowMap = map;
- // Destroy all namepage list-view's sub item
- m_GuiLV_Page.DeleteAllItems ();
- for (auto j = 0; j != map->height; j++) {
- for (auto i = 0; i != map->width; i++) {
- const auto it = j*map->width+i;
- auto nt = map->ntList[it];
- nt->comment.Format (_T ("%d-%d"), j, i);
- m_GuiLV_Page.InsertItem (it, nt->comment, 0);
- m_GuiLV_Page.SetItemData (it, reinterpret_cast <DWORD_PTR> ( nt));
- /*
- BOOL SetItem(int nItem, int nSubItem, UINT nMask, LPCTSTR lpszItem,
- int nImage, UINT nState, UINT nStateMask, LPARAM lParam)
- */
- m_GuiLV_Page.SetItem (it, 1, LVIF_IMAGE | LVIF_TEXT, nt->chr ? nt->chr->comment : _T ("null"), 1, 0, 0, 0);
- m_GuiLV_Page.SetItem (it, 2, LVIF_IMAGE | LVIF_TEXT, nt->pal ? nt->pal->comment : _T ("null"), 2 + nt->getSelectPalSourceIndex (), 0, 0, 0);
- m_GuiLV_Page.SetItem (it, 3, LVIF_IMAGE | LVIF_TEXT, nt->attr ? nt->attr->comment : _T ("null"), 5, 0, 0, 0);
- }
- }
- // reset scroll...
- m_GuiSWin_Nesmap.SetScrollPos (0, SB_VERT);
- m_GuiSWin_Nesmap.SetScrollPos (0, SB_HORZ);
- m_GuiSWin_Nesmap.SetScrollSize (map->width * 32 * 8 + 32, map->height * 30 * 8 + 32);
- m_GuiSWin_Nesmap.nesPixelGenerator ();
- }
- tryCloseNtpWindow ();
- }
- }
- default:
- break;
- }
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnKeyUpT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_CLAY:
- switch (wParam) {
- case 'P':
- if (CTRL_IN_KEYQUEUE ()) {
- auto indexChr = m_GuiLV_Chr.GetSelectedIndex ();
- auto indexClay = m_GuiLV_Clay.GetSelectedIndex ();
- if (indexChr >= 0
- && indexClay >= 0) {
- auto chr = (CChr *) m_GuiLV_Chr.GetItemData (indexChr);
- auto nt_cell = (CNametableCell<TRUE> *) m_GuiLV_Clay.GetItemData (indexClay);
- ATLASSERT (chr != NULL);
- ATLASSERT (nt_cell != NULL);
- nt_cell->chr = chr;
- m_GuiLV_Clay.SetItemText (indexClay, 1, chr->comment);
- auto p = tryUpdateClayWindow (nt_cell);
- if (p != NULL) {
- p->SetWindowTextFT (_T ("clay %s-%s"),
- m_GuiLV_Clay.GetItemTextAMC (indexChr, 0),
- nt_cell->chr ? nt_cell->chr->comment : _T ("null"));
- }
- }
- }
- break;
- case 'V':
- if (CTRL_IN_KEYQUEUE ()) {
- auto indexChr = m_GuiLV_Chr.GetSelectedIndex ();
- auto indexClay = m_GuiLV_Clay.GetSelectedIndex ();
- if (indexChr >= 0
- && indexClay >= 0) {
- auto chr = (CChr *) m_GuiLV_Chr.GetItemData (indexChr);
- auto nt_cell = (CNametableCell<TRUE> *) m_GuiLV_Clay.GetItemData (indexClay);
- ATLASSERT (chr != NULL);
- ATLASSERT (nt_cell != NULL);
- nt_cell->chr = chr;
- // m_GuiLV_Clay.SetItemText (indexClay, 1, chr->comment);
- auto p = tryUpdateClayWindow (nt_cell);
- if (p != NULL) {
- TCHAR buf[256];
- m_GuiLV_Chr.GetItemText (indexChr, 0, buf, sizeof (buf) / sizeof (buf[0]));
- p->SetWindowTextFT (_T ("clay %s-%s"), buf, nt_cell->chr ? nt_cell->chr->comment : _T ("null"));
- }
- }
- }
- break;
- case VK_RETURN:
- {
- auto index = m_GuiLV_Clay.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL);
- if (index >= 0) {
- auto clay = (CNametableCell<TRUE> *) m_GuiLV_Clay.GetItemData (index);
- ATLASSERT (clay != NULL);
- CClaySettings dlgSettings (*this);
- if (dlgSettings.DoModal (clay) == IDOK) {
- // Append to new.
- m_GuiLV_Clay.SetItemText (index, 0, clay->comment);
- }
- }
- }
- break;
- case VK_INSERT:
- {
- CClaySettings dlgSettings (*this);
- if (dlgSettings.DoModal (NULL) == IDOK) {
- // Append to new.
- auto index = m_GuiLV_Clay.InsertItem (m_GuiLV_Clay.GetItemCount (), dlgSettings.m_attachcell->comment, 0);
- ATLASSERT (index >= 0);
- m_GuiLV_Clay.SetItemData (index, reinterpret_cast <DWORD_PTR> ( dlgSettings.m_attachcell));
- }
- }
- default:
- break;
- }
- break;
- case MAP_CONTROL_LV_PAGE:
- bHandled = FALSE;
- switch (wParam) {
- case 'A': // Check select all ...
- if (CTRL_IN_KEYQUEUE ()) {
- m_GuiLV_Page.SetItemState (-1, /* LVIS_FOCUSED | */LVIS_SELECTED, /* LVIS_FOCUSED | */LVIS_SELECTED);
- }
- break;
- case 'P':
- if (CTRL_IN_KEYQUEUE ()) {
- auto indexChr = m_GuiLV_Chr.GetSelectedIndex ();
- auto indexPage = m_GuiLV_Page.GetSelectedIndex ();
- // ::TrackPopupMenu
- if (indexChr >= 0
- && indexPage >= 0) {
- auto chr = m_GuiLV_Chr.GetItemSelectedDataT ();
- ATLASSERT (chr != NULL);
- for (int it = 0; it != m_GuiLV_Page.GetItemCount (); it++) {
- auto nt_cell = m_GuiLV_Page.GetItemDataT (it);
- ATLASSERT (nt_cell != NULL);
- nt_cell->chr = chr;
- m_GuiLV_Page.SetItemText (it, 1, chr->comment);
- auto p = tryUpdateNtpWindow (nt_cell);
- if (p != NULL) {
- p->SetWindowTextFT (_T ("nt %s-%s"),
- m_GuiLV_Page.GetItemTextAMC (it, 0),
- nt_cell->chr ? nt_cell->chr->comment : _T ("null"));
- }
- }
- }
- }
- break;
- case 'V':
- if (CTRL_IN_KEYQUEUE ()) {
- auto indexChr = m_GuiLV_Chr.GetSelectedIndex ();
- auto indexPage = m_GuiLV_Page.GetSelectedIndex ();
- if (indexChr >= 0
- && indexPage >= 0) {
- auto chr = (CChr *) m_GuiLV_Chr.GetItemData (indexChr);
- auto nt_cell = (CNametableCell<FALSE> *) m_GuiLV_Page.GetItemData (indexPage);
- ATLASSERT (chr != NULL);
- ATLASSERT (nt_cell != NULL);
- nt_cell->chr = chr;
- m_GuiLV_Page.SetItemText (indexPage, 1, chr->comment);
- auto p = tryUpdateNtpWindow (nt_cell);
- if (p != NULL) {
- p->SetWindowTextFT (_T ("nt %s-%s"),
- m_GuiLV_Page.GetSelectedItemTextAMC (0),
- nt_cell->chr ? nt_cell->chr->comment : _T ("null"));
- }
- }
- }
- default:
- break;
- }
- break;
- case MAP_CONTROL_LV_CHR:
- switch (wParam) {
- case 'C': // Copy chr cache.
- if (CTRL_IN_KEYQUEUE ()) {
- auto chr = m_GuiLV_Chr.GetItemSelectedDataT ();
- if (chr != NULL) {
- CGlobals::pasteChr = chr;
- setStatusText (2, _T ("chr cache:%s"), chr->comment);
- }
- }
- break;
- case VK_DELETE:
- {
- auto index = m_GuiLV_Chr.GetSelectedIndex ();
- if (index >= 0) {
- removeChr ((CChr *) m_GuiLV_Chr.GetItemData (index));
- m_GuiLV_Chr.DeleteItem (index);
- if (m_GuiLV_Chr.GetItemCount () > 0) {
- m_GuiLV_Chr.SelectItem (0);
- }
- }
- }
- break;
- case VK_INSERT:
- {
- CChrSettings dlgSettings (*this);
- dlgSettings.DoModal (NULL);
- // Show chr infos.
- m_GuiLV_Chr.DeleteAllItems ();
- for (size_t it = 0; it != m_ChrVec.GetCount (); it++) {
- m_GuiLV_Chr.InsertItem (it, m_ChrVec[it]->comment, 0);
- m_GuiLV_Chr.SetItemData (it, reinterpret_cast <DWORD_PTR> ( m_ChrVec[it]));
- }
- }
- default:
- break;
- }
- break;
- case MAP_CONTROL_LV_MAP:
- switch (wParam) {
- case VK_INSERT:
- {
- CMapSettings dlgSettings (*this);
- if (dlgSettings.DoModal (NULL) == IDOK) {
- int index = m_GuiLV_Map.InsertItem (m_GuiLV_Map.GetItemCount (), dlgSettings.m_newmap->comment, 0);
- ATLASSERT (index >= 0);
- m_ShowMap = dlgSettings.m_newmap;
- m_GuiLV_Map.SetItemData (index, reinterpret_cast <DWORD_PTR> (m_ShowMap));
- m_GuiLV_Map.SelectItem (index);
- // TODO::::!!!!!!!!!
- // Enum list infos. show page window (case type)
- // Frisr derstroy all old window. and
- }
- }
- break;
- case VK_DECIMAL:
- break;
- }
- }
- return 0;
- }
- // <CMainFrame::CChrSettings Start> =========================================
- struct CChrSettings : public CDialogImpl<CChrSettings>
- {
- typedef CChrSettings thisClass;
- typedef CDialogImpl<CChrSettings> baseClass;
- static const WORD copying_clr = 0x1f << 5;
- static const WORD copy_clr = 0x1f;
- static const WORD paste_clr = 0x1f << 10;
- static const WORD blend_cnt = 10;
- static const SIZE_T MAP_CONTROL_LV_DRAWMAIN = 1;
- static const SIZE_T MAP_CONTROL_LV_DRAWROM = MAP_CONTROL_LV_DRAWMAIN + 1;
- static const SIZE_T MAP_CONTROL_LV_DRAWRAM = MAP_CONTROL_LV_DRAWROM + 1;
- static const SIZE_T MAP_CONTROL_LV_DRAWCHR0PIX = MAP_CONTROL_LV_DRAWRAM + 1;
- static const SIZE_T MAP_CONTROL_LV_DRAWCHR1PIX = MAP_CONTROL_LV_DRAWCHR0PIX + 1;
- static const SIZE_T MAP_CONTROL_LV_DRAWCHR2PIX = MAP_CONTROL_LV_DRAWCHR1PIX + 1;
- static const SIZE_T MAP_CONTROL_LV_DRAWCHR3PIX = MAP_CONTROL_LV_DRAWCHR2PIX + 1;
- static const SIZE_T MAP_CONTROL_LV_DRAWCHRLIST = MAP_CONTROL_LV_DRAWCHR3PIX + 1;
- WORD m_chrclr[4];
- CContainedWindowT <CListViewCtrl> m_GuiLV_Drawchr;
- CContainedWindowT <CListViewCtrl> m_GuiLV_Drawrom;
- CContainedWindowT <CListViewCtrl> m_GuiLV_Drawram;
- CContainedWindowT <CListViewCtrl> m_GuiLV_Drawchr0pix;
- CContainedWindowT <CListViewCtrl> m_GuiLV_Drawchr1pix;
- CContainedWindowT <CListViewCtrl> m_GuiLV_Drawchr2pix;
- CContainedWindowT <CListViewCtrl> m_GuiLV_Drawchr3pix;
- CContainedWindowT <CListViewCtrl> m_GuiLV_Chrlist;
- CMemoryPaint16 m_MemoryPaintChrpix0;
- CMemoryPaint16 m_MemoryPaintChrpix1;
- CMemoryPaint16 m_MemoryPaintChrpix2;
- CMemoryPaint16 m_MemoryPaintChrpix3;
- CMemoryPaint16 m_MemoryPaintDrawpreview;
- CMemoryPaint16 m_MemoryPaintRom;
- CMemoryPaint16 m_MemoryPaintRam;
- CScrollBar m_GuiSCR_VDraw;
- CEdit m_GuiET_Comment;
- CPoint m_ptDrawStart;
- CPoint m_ptDrawEnd;
- CPoint m_ptDrawDstStartY;
- CPoint m_ptDrawStartY;
- CSize m_szDrawSizeY;
- CMainFrame &m_attthis;
- CChr m_tmpchr;
- CChr *m_selchr;
- CImageListManaged m_IconChrlist;
- CChr m_copychr;
- DWORD m_dwState; // 0: no copy 1:from chr-main 2: from chr-single 4: from edit-self
- // 0x8000 mask : ing...
- CChr m_tmpchr2;
- VOID copyToCache (VOID) {
- auto sig = m_dwState & 0x7FFF;
- auto mask = m_dwState & 0x8000;
- auto &dstchr= m_copychr;
- auto pt_y = m_ptDrawStartY.y;
- auto pt_x = m_ptDrawStartY.x;
- auto ptd_y = pt_y + m_szDrawSizeY.cy;
- auto ptd_x = pt_x + m_szDrawSizeY.cx;
- auto *_pchr = & m_tmpchr;
- switch (sig) {
- case 1:
- // Show main-chr infos.
- if (m_pchrpool != NULL) {
- auto y_base = m_GuiSCR_VDraw.GetScrollPos ();
- auto align = m_align;
- int x_block_sft;
- int g_per_sft;
- int g_per_mod;
- int vec_block_sft;
- switch (align) {
- case 16:
- x_block_sft = 2;
- g_per_sft = 4;
- g_per_mod = 15;
- vec_block_sft = 12;
- break;
- case 32:
- x_block_sft = 1;
- g_per_sft = 5;
- g_per_mod = 31;
- vec_block_sft = 14;
- break;
- case 64:
- x_block_sft = 0;
- g_per_sft = 6;
- g_per_mod = 63;
- vec_block_sft = 16;
- break;
- default:
- ATLASSERT (FALSE);
- break;
- }
- for (auto j= pt_y; j != ptd_y; j++) {
- auto coo_y = j + y_base;
- auto sr_v = coo_y >> g_per_sft;
- auto sr_vt = sr_v << x_block_sft; // TODO:add+loop replace .
- auto sr_mod_y = coo_y & g_per_mod;
- auto j0 = j - pt_y << 8; // 16 tiles
- for (auto i = pt_x; i != ptd_x; i++) {
- // Cut child range
- auto sr_total = (i >> g_per_sft) + sr_vt;
- auto sr_mod_x = i & g_per_mod;
- auto p = & m_pchrpool[sr_total << vec_block_sft];
- auto chrptr = (PUINT64) & p[(sr_mod_x << 4) + ((sr_mod_y << g_per_sft) << 4)];
- auto i0 = i - pt_x << 4;
- auto dstptr = (PUINT64) & dstchr.chr[j0+i0];
- dstptr[0] = chrptr[0];
- dstptr[1] = chrptr[1];
- }
- }
- }
- break;
- case 2:
- if (m_selchr != NULL) {
- _pchr = m_selchr;
- case 4:
- for (auto j= pt_y; j != ptd_y; j++) {
- auto j0 = j - pt_y << 8; // 16 tiles
- for (auto i = pt_x; i != ptd_x; i++) {
- auto chrptr = (PUINT64) & _pchr->chr[(i << 4)+ (j << 8)];
- auto i0 = i - pt_x << 4;
- auto dstptr = (PUINT64) & dstchr.chr[j0+i0];
- dstptr[0] = chrptr[0];
- dstptr[1] = chrptr[1];
- }
- }
- }
- default:
- break;
- }
- }
- VOID UpdateInfos (BOOL bUpdatePostto = TRUE) {
- // return ;
- CMemoryPaint16::DirectWrite dwrite_chr0;
- CMemoryPaint16::DirectWrite dwrite_chr1;
- CMemoryPaint16::DirectWrite dwrite_chr2;
- CMemoryPaint16::DirectWrite dwrite_chr3;
- CMemoryPaint16::DirectWrite dwrite_main;
- CMemoryPaint16::DirectWrite dwrite_rom;
- CMemoryPaint16::DirectWrite dwrite_ram;
- m_MemoryPaintDrawpreview.getBackSurface (dwrite_main);
- m_MemoryPaintChrpix0.getBackSurface (dwrite_chr0);
- m_MemoryPaintChrpix1.getBackSurface (dwrite_chr1);
- m_MemoryPaintChrpix2.getBackSurface (dwrite_chr2);
- m_MemoryPaintChrpix3.getBackSurface (dwrite_chr3);
- m_MemoryPaintRom.getBackSurface (dwrite_rom);
- m_MemoryPaintRam.getBackSurface (dwrite_ram);
- m_MemoryPaintChrpix0.fillFullClient (dwrite_chr0, m_chrclr[0]);
- m_MemoryPaintChrpix1.fillFullClient (dwrite_chr1, m_chrclr[1]);
- m_MemoryPaintChrpix2.fillFullClient (dwrite_chr2, m_chrclr[2]);
- m_MemoryPaintChrpix3.fillFullClient (dwrite_chr3, m_chrclr[3]);
- const auto &r_pal = m_chrclr;
- // Show main-chr infos.
- if (m_pchrpool != NULL) {
- auto y_base = m_GuiSCR_VDraw.GetScrollPos ();
- auto align = m_align;
- int x_block_sft;
- int g_per_sft;
- int g_per_mod;
- int vec_block_sft;
- switch (align) {
- case 16:
- x_block_sft = 2;
- g_per_sft = 4;
- g_per_mod = 15;
- vec_block_sft = 12;
- break;
- case 32:
- x_block_sft = 1;
- g_per_sft = 5;
- g_per_mod = 31;
- vec_block_sft = 14;
- break;
- case 64:
- x_block_sft = 0;
- g_per_sft = 6;
- g_per_mod = 63;
- vec_block_sft = 16;
- break;
- default:
- ATLASSERT (FALSE);
- break;
- }
- const auto vpit = dwrite_main.Pitch16 << 3;
- for (auto j= 0; j != 64; j++) {
- auto coo_y = j + y_base;
- auto sr_v = coo_y >> g_per_sft;
- auto sr_vt = sr_v << x_block_sft; // TODO:add+loop replace .
- auto sr_mod_y = coo_y & g_per_mod;
- auto vptr_y = & dwrite_main.pBits[ j * vpit];
- for (auto i = 0; i != 64; i++) {
- // Cut child range
- auto sr_total = (i >> g_per_sft) + sr_vt;
- auto sr_mod_x = i & g_per_mod;
- auto p = & m_pchrpool[sr_total << vec_block_sft];
- auto chrptr = & p[(sr_mod_x << 4) + ((sr_mod_y << g_per_sft) << 4)];
- auto vptr = & vptr_y[i << 3];
- CPolyData64 cpd64;
- for (auto vec = 0; vec != 8; vec++) {
- cpd64.blk = CGlobals::chrmixer[chrptr[0]];
- cpd64.blk|= CGlobals::chrmixer[chrptr[8]] << 1;
- vptr[0] = r_pal[cpd64.blk8[0]];
- vptr[1] = r_pal[cpd64.blk8[1]];
- vptr[2] = r_pal[cpd64.blk8[2]];
- vptr[3] = r_pal[cpd64.blk8[3]];
- vptr[4] = r_pal[cpd64.blk8[4]];
- vptr[5] = r_pal[cpd64.blk8[5]];
- vptr[6] = r_pal[cpd64.blk8[6]];
- vptr[7] = r_pal[cpd64.blk8[7]];
- chrptr ++;
- vptr += dwrite_main.Pitch16;
- }
- }
- }
- }
- // Draw attach/temp chr pixel
- CChr *chrt[2] = { m_selchr, & m_tmpchr };
- CMemoryPaint16::DirectWrite *dwirte_gp[2] = { & dwrite_rom, & dwrite_ram};
- for (auto it = 0; it != 2; it++) {
- if (chrt[it] != NULL) {
- auto &chr = *(chrt[it]);
- auto &vram = *(dwirte_gp[it]);
- auto pChr = chr.chr;
- for (auto j = 0; j != 16; j++) {
- for (auto i = 0; i != 16; i++) {
- auto x_pos= i << 3;
- auto y_pos = j << 3;
- auto tv = & vram.pBits[x_pos + y_pos *vram.Pitch16];
- auto pChrT = pChr;
- CPolyData64 chr;
- for (auto v = 0; v != 8; v++) {
- chr.blk = CGlobals::chrmixer[pChrT[0]]
- | CGlobals::chrmixer[pChrT[8]] << 1;
- tv[0] = r_pal[chr.blk8[0]];
- tv[1] = r_pal[chr.blk8[1]];
- tv[2] = r_pal[chr.blk8[2]];
- tv[3] = r_pal[chr.blk8[3]];
- tv[4] = r_pal[chr.blk8[4]];
- tv[5] = r_pal[chr.blk8[5]];
- tv[6] = r_pal[chr.blk8[6]];
- tv[7] = r_pal[chr.blk8[7]];
- tv += vram.Pitch16;
- pChrT++;
- }
- pChr += 16;
- }
- }
- }
- }
- if (m_dwState != 0) {
- // Darw attach infos.
- CMemoryPaint16::DirectWrite *dwrite = NULL;
- if (m_dwState & 1) {
- dwrite = & dwrite_main;
- } else if (m_dwState & 2) {
- dwrite = & dwrite_rom;
- } else if (m_dwState & 4) {
- dwrite = & dwrite_ram;
- }
- if (dwrite != NULL) {
- CPoint pt = m_ptDrawDstStartY;
- CSize sz= m_szDrawSizeY;
- if (pt.x + sz.cx > 16)
- sz.cx = 16 - pt.x;
- if (pt.y + sz.cy > 16)
- sz.cy = 16 - pt.y;
- if ((m_dwState & 0x8000) == 0) {
- // draw link chr.
- auto &chr = m_copychr.chr;
- const auto &r_pal = m_chrclr;
- for (auto j = 0; j != sz.cy; j++) {
- auto coo_y = j + pt.y << 3;
- for (auto i = 0; i != sz.cx; i++) {
- auto coo_x = i + pt.x << 3;
- auto vdst = & dwrite_ram.pBits[coo_x + coo_y * dwrite_ram.Pitch16];
- auto vsrcchr = & chr [(i << 4) + (j << 8)];
- for (auto vec = 0; vec != 8; vec++) {
- CPolyData64 cpd64;
- cpd64.blk = CGlobals::chrmixer[vsrcchr[0]];
- cpd64.blk|= CGlobals::chrmixer[vsrcchr[8]] << 1;
- vdst[0] = CGlobals::alpha16 (r_pal[cpd64.blk8[0]], vdst[0], blend_cnt, 15 - blend_cnt);
- vdst[1] = CGlobals::alpha16 (r_pal[cpd64.blk8[1]], vdst[1], blend_cnt, 15 - blend_cnt);
- vdst[2] = CGlobals::alpha16 (r_pal[cpd64.blk8[2]], vdst[2], blend_cnt, 15 - blend_cnt);
- vdst[3] = CGlobals::alpha16 (r_pal[cpd64.blk8[3]], vdst[3], blend_cnt, 15 - blend_cnt);
- vdst[4] = CGlobals::alpha16 (r_pal[cpd64.blk8[4]], vdst[4], blend_cnt, 15 - blend_cnt);
- vdst[5] = CGlobals::alpha16 (r_pal[cpd64.blk8[5]], vdst[5], blend_cnt, 15 - blend_cnt);
- vdst[6] = CGlobals::alpha16 (r_pal[cpd64.blk8[6]], vdst[6], blend_cnt, 15 - blend_cnt);
- vdst[7] = CGlobals::alpha16 (r_pal[cpd64.blk8[7]], vdst[7], blend_cnt, 15 - blend_cnt);
- vdst += dwrite_ram.Pitch16;
- vsrcchr++;
- }
- }
- }
- }
- CGlobals::drawGrid (*dwrite,
- CGlobals::GRID_TYPE_FIXED,
- CPoint (m_ptDrawStartY.x << 3, m_ptDrawStartY.y << 3),
- CSize (m_szDrawSizeY.cx << 3, m_szDrawSizeY.cy << 3),
- CSize (1, 1),
- m_dwState & 0x8000 ? copying_clr : copy_clr);
- // tracker dst .
- if ((m_dwState & 0x8000) == 0) {
- pt.x <<= 3;
- pt.y <<= 3;
- sz.cx <<= 3;
- sz.cy <<= 3;
- CGlobals::drawGrid (dwrite_ram,
- CGlobals::GRID_TYPE_FIXED,
- pt,
- sz,
- CSize (1, 1),
- paste_clr);
- }
- }
- }
- m_MemoryPaintChrpix0.blitClientBaseALL0 ();
- m_MemoryPaintChrpix1.blitClientBaseALL0 ();
- m_MemoryPaintChrpix2.blitClientBaseALL0 ();
- m_MemoryPaintChrpix3.blitClientBaseALL0 ();
- m_MemoryPaintDrawpreview.blitClientBaseALL0 ();
- m_MemoryPaintRom.blitClientBaseALL0 ();
- m_MemoryPaintRam.blitClientBaseALL0 ();
- }
- // 512 * 512 pixel
- // :=
- //
- // 128 * 128 pixel := 4K
- // if <= 512 >= 512
- // other limit 256 base
- PBYTE m_pchrpool; // XXX: must align 64K chr
- INT m_64k_page;
- INT m_align;
- BOOL m_bhflip;
- BOOL m_bvflip;
- ~CChrSettings (VOID) {
- // When I use subclass to intercept control message processing inside dialog,
- // And execute the unsubclass control enddialog inside the WM_CLOSE message.
- // After the operation, the
- // ATL: object deleted before window was destroyed
- // Assertion will be triggered, but sometimes there are no exception assertions
- // I don't know what I did wrong
- // This may be a bug of WTL/ATL ??
- this->m_hWnd = NULL;
- }
- CChrSettings (CMainFrame &psthis):
- m_dwState (0),
- m_bhflip (FALSE),
- m_bvflip (FALSE),
- m_attthis (psthis),
- m_pchrpool (NULL),
- m_selchr (NULL),
- m_64k_page (0),
- m_align (16),
- m_GuiLV_Drawchr (this, MAP_CONTROL_LV_DRAWMAIN),
- m_GuiLV_Drawrom (this, MAP_CONTROL_LV_DRAWROM),
- m_GuiLV_Drawram (this, MAP_CONTROL_LV_DRAWRAM),
- m_GuiLV_Drawchr0pix (this, MAP_CONTROL_LV_DRAWCHR0PIX),
- m_GuiLV_Drawchr1pix (this, MAP_CONTROL_LV_DRAWCHR1PIX),
- m_GuiLV_Drawchr2pix (this, MAP_CONTROL_LV_DRAWCHR2PIX),
- m_GuiLV_Drawchr3pix (this, MAP_CONTROL_LV_DRAWCHR3PIX),
- m_GuiLV_Chrlist (this, MAP_CONTROL_LV_DRAWCHRLIST)
- {
- m_chrclr[0] = CGlobals::nespal[0x0F];
- m_chrclr[1] = CGlobals::nespal[0x1C];
- m_chrclr[2] = CGlobals::nespal[0x2B];
- m_chrclr[3] = CGlobals::nespal[0x39];
- m_IconChrlist.Create (16,16,ILC_COLOR24|ILC_MASK,1,0);
- m_IconChrlist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_CHR)));
- }
- enum { IDD = IDD_CHR_ADD };
- template <DWORD t_dwAlign>
- LRESULT OnAlignT (WORD, WORD, HWND /*lParam*/, BOOL& bHandled) {
- m_align = t_dwAlign;
- UpdateInfos (TRUE);
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnRButtonUpT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_DRAWMAIN:
- case MAP_CONTROL_LV_DRAWROM:
- case MAP_CONTROL_LV_DRAWRAM:
- m_dwState = 0;
- break;
- default:
- break;
- }
- UpdateInfos (TRUE);
- bHandled = FALSE;
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnLButtonDownT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_DRAWCHRLIST: // Case Global paleete
- {
- // Process default message first
- m_GuiLV_Chrlist.DefWindowProc (uMsg, wParam, lParam);
- auto index = m_GuiLV_Chrlist.GetSelectedIndex ();
- // m_GuiLV_PalList.Pro
- if (index >= 0) {
- CChr *chr = (CChr *) m_GuiLV_Chrlist.GetItemData (index);
- if (chr != NULL) {
- m_selchr = chr;
- m_GuiET_Comment.SetWindowText (chr->comment);
- }
- }
- }
- break;
- case MAP_CONTROL_LV_DRAWMAIN:
- case MAP_CONTROL_LV_DRAWROM:
- case MAP_CONTROL_LV_DRAWRAM:
- {
- // click . draw rect.
- BOOL bInitrect = TRUE;
- auto oldState = m_dwState;
- auto limsize = 16;
- m_dwState = 0x8000;
- if (t_dwControlId == MAP_CONTROL_LV_DRAWMAIN) {
- m_dwState |= 1;
- limsize = 64;
- } else if (t_dwControlId == MAP_CONTROL_LV_DRAWROM) {
- m_dwState |= 2;
- } else if (t_dwControlId == MAP_CONTROL_LV_DRAWRAM) {
- if (oldState != 0
- && (oldState & 0x8000) == 0)
- {
- // Copy paste tiles...
- // Resume old state
- auto pt_y = m_ptDrawDstStartY.y;
- auto pt_x = m_ptDrawDstStartY.x;
- auto ptd_y = pt_y + m_szDrawSizeY.cy;
- auto ptd_x = pt_x + m_szDrawSizeY.cx;
- if (ptd_y > 16)
- ptd_y = 16;
- if (ptd_x > 16)
- ptd_x = 16;
- for (auto j= pt_y; j != ptd_y; j++) {
- auto j0 = j - pt_y << 8; // 16 tiles
- for (auto i = pt_x; i != ptd_x; i++) {
- auto i0 = i - pt_x << 4;
- auto chrptr = (PUINT64) & m_copychr .chr[j0+i0];
- auto dstptr = (PUINT64) & m_tmpchr.chr[(i << 4) + (j << 8)];
- dstptr[0] = chrptr[0];
- dstptr[1] = chrptr[1];
- }
- }
- m_dwState = oldState;
- bInitrect = FALSE;
- }
- else
- {
- m_dwState |= 4;
- }
- }
- if (bInitrect != FALSE) {
- // Init rect.
- m_ptDrawStart.x = pt.x / 8;
- m_ptDrawStart.y = pt.y / 8;
- CGlobals::limitPoint (m_ptDrawStart, limsize, limsize);
- m_ptDrawEnd = m_ptDrawStart;
- m_ptDrawStartY = m_ptDrawStart;
- m_szDrawSizeY= ( 1, 1);
- }
- }
- default:
- break;
- }
- UpdateInfos (TRUE);
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnLButtonUpT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_DRAWMAIN:
- case MAP_CONTROL_LV_DRAWROM:
- case MAP_CONTROL_LV_DRAWRAM:
- if (m_dwState & 0x8000) {
- const auto limsize = t_dwControlId == MAP_CONTROL_LV_DRAWMAIN ? 64 : 16;
- pt.x /= 8;
- pt.y/= 8;
- CGlobals ::limitPoint (pt, limsize, limsize);
- m_ptDrawEnd = pt;
- if (t_dwControlId == MAP_CONTROL_LV_DRAWRAM) {
- m_ptDrawDstStartY = pt;
- }
- CPoint ptLT = m_ptDrawStart;
- CPoint ptBR = m_ptDrawEnd;
- CGlobals::translateVecPointToltrb (ptLT, ptBR);
- m_ptDrawStartY = ptLT;
- m_szDrawSizeY.cx = ptBR.x -ptLT.x + 1;
- m_szDrawSizeY.cy = ptBR.y -ptLT.y + 1;
- if (m_szDrawSizeY.cx > 16)
- m_szDrawSizeY.cx = 16;
- if (m_szDrawSizeY.cy > 16)
- m_szDrawSizeY.cy = 16;
- m_bhflip =FALSE;
- m_bvflip = FALSE;
- copyToCache ();
- m_dwState &= ~0x8000;
- }
- break;
- case MAP_CONTROL_LV_DRAWCHRLIST: // Case Global paleete
- {
- // Process default message first
- m_GuiLV_Chrlist.DefWindowProc (uMsg, wParam, lParam);
- auto index = m_GuiLV_Chrlist.GetSelectedIndex ();
- // m_GuiLV_PalList.Pro
- if (index >= 0) {
- CChr *chr = (CChr *) m_GuiLV_Chrlist.GetItemData (index);
- if (chr != NULL) {
- m_selchr = chr;
- m_GuiET_Comment.SetWindowText (chr->comment);
- }
- }
- }
- break;
- default:
- break;
- }
- UpdateInfos (TRUE);
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnMouseMoveT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPoint pt (GET_X_LPARAM(lParam),
- GET_Y_LPARAM(lParam));
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_DRAWMAIN:
- case MAP_CONTROL_LV_DRAWROM:
- case MAP_CONTROL_LV_DRAWRAM:
- if (m_dwState & 0x8000) {
- const auto limsize = t_dwControlId == MAP_CONTROL_LV_DRAWMAIN ? 64 : 16;
- pt.x /= 8;
- pt.y/= 8;
- CGlobals ::limitPoint (pt, limsize, limsize);
- m_ptDrawEnd = pt;
- CPoint ptLT = m_ptDrawStart;
- CPoint ptBR = m_ptDrawEnd;
- CGlobals::translateVecPointToltrb (ptLT, ptBR);
- m_ptDrawStartY = ptLT;
- m_szDrawSizeY.cx = ptBR.x -ptLT.x + 1;
- m_szDrawSizeY.cy = ptBR.y -ptLT.y + 1;
- if (m_szDrawSizeY.cx > 16)
- m_szDrawSizeY.cx = 16;
- if (m_szDrawSizeY.cy > 16)
- m_szDrawSizeY.cy = 16;
- } else if (m_dwState != 0 && t_dwControlId == MAP_CONTROL_LV_DRAWRAM) {
- m_ptDrawDstStartY.x = pt.x / 8;
- m_ptDrawDstStartY.y = pt.y / 8;
- CGlobals ::limitPoint (m_ptDrawDstStartY, 16, 16);
- }
- break;
- case MAP_CONTROL_LV_DRAWCHRLIST: // Case Global paleete
- {
- // Process default message first
- m_GuiLV_Chrlist.DefWindowProc (uMsg, wParam, lParam);
- auto index = m_GuiLV_Chrlist.GetSelectedIndex ();
- // m_GuiLV_PalList.Pro
- if (index >= 0) {
- CChr *chr = (CChr *) m_GuiLV_Chrlist.GetItemData (index);
- if (chr != NULL) {
- m_selchr = chr;
- m_GuiET_Comment.SetWindowText (chr->comment);
- }
- }
- }
- break;
- default:
- break;
- }
- UpdateInfos (TRUE);
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnLButtonDblclkT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- PWORD pclr = NULL;
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_DRAWCHR0PIX: pclr = & m_chrclr[0]; break;
- case MAP_CONTROL_LV_DRAWCHR1PIX: pclr = & m_chrclr[1]; break;
- case MAP_CONTROL_LV_DRAWCHR2PIX: pclr = & m_chrclr[2]; break;
- case MAP_CONTROL_LV_DRAWCHR3PIX: pclr = & m_chrclr[3]; break;
- case MAP_CONTROL_LV_DRAWCHRLIST: break;
- default:
- ATLASSERT (FALSE);
- break;
- }
- if (t_dwControlId != MAP_CONTROL_LV_DRAWCHRLIST) {
- CColorDialog coldlg (GDI_COL_TO_DRAW32 (*pclr));
- if (coldlg.DoModal () == IDOK) {
- *pclr = GDI_COL_TO_DRAW16 (coldlg.GetColor ());
- }
- }else {
- auto index = m_GuiLV_Chrlist.GetSelectedIndex ();
- // m_GuiLV_PalList.Pro
- if (index >= 0) {
- CChr *chr = (CChr *) m_GuiLV_Chrlist.GetItemData (index);
- if (chr != NULL) {
- m_selchr = chr;
- m_GuiET_Comment.SetWindowText (chr->comment);
- m_tmpchr = *chr;
- }
- }
- }
- UpdateInfos (TRUE);
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnVScroll (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- SCROLLINFO scrInfos;
- WORD scrCommand = LOWORD (wParam);
- scrInfos.fMask = SIF_ALL;
- scrInfos.cbSize = sizeof (scrInfos);
- m_GuiSCR_VDraw. GetScrollInfo (& scrInfos);
- INT vec = scrInfos.nPos;
- switch (scrCommand) {
- case SB_THUMBPOSITION:
- case SB_THUMBTRACK:
- vec = scrInfos.nTrackPos;
- break;
- case SB_LINEUP:
- vec --;
- break;
- case SB_LINEDOWN:
- vec ++;
- break;
- case SB_PAGEDOWN:
- vec += 64;
- break;
- case SB_PAGEUP:
- vec -= 64;
- break;
- case SB_TOP:
- case SB_BOTTOM:
- default:
- // ATLASSERT (FALSE);
- break;
- }
- if (vec < 0)
- vec = 0;
- if (vec+ 64 > scrInfos.nMax)
- vec = scrInfos.nMax - 64;
- m_GuiSCR_VDraw.SetScrollPos (vec);
- // Re-pos .
- UpdateInfos (TRUE);
- return 0;
- }
- template <DWORD t_dwControlId>
- LRESULT OnKeyUpT (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- switch (t_dwControlId) {
- case MAP_CONTROL_LV_DRAWRAM:
- switch (wParam) {
- case 'H': // h-swap @TODO:
- m_bhflip = !m_bhflip;
- break;
- case 'V': // v-swap @TODO:
- m_bvflip = !m_bvflip;
- break;
- case ' ': // clear all elem
- RtlZeroMemory (m_tmpchr.chr, sizeof (m_tmpchr.chr));
- break;
- default:
- break;
- }
- break;
- case MAP_CONTROL_LV_DRAWCHRLIST:
- switch (wParam) {
- case VK_DELETE:
- {
- auto index = m_GuiLV_Chrlist.GetSelectedIndex ();
- auto &vec = m_attthis.m_ChrVec;
- auto &vec2 = m_attthis.m_VnpVec;
- if (index >= 0) {
- CChr *chr = (CChr *) m_GuiLV_Chrlist.GetItemData (index);
- for (auto It = 0; It != vec.GetCount (); It++) {
- if (vec[It] == chr) {
- // delete nametable page's attach link
- for (auto Iz = 0; Iz != m_attthis.m_MapVec.GetCount (); Iz++) {
- auto &vec3 = m_attthis.m_MapVec[Iz]->ntList;
- for (auto Iq = 0; Iq != vec3.GetCount (); Iq++) {
- if (vec3[Iq]->chr == chr) {
- // empty it.
- vec3[Iq]->chr = NULL;
- }
- }
- }
- // Delete clay class.
- for (auto Iq = 0; Iq != vec2.GetCount (); Iq++) {
- if (vec2[Iq]->chr == chr) {
- // empty it.
- vec2[Iq]->chr = NULL;
- }
- }
- m_attthis.updateCPViewListInfos <TRUE> ();
- m_attthis.updateCPViewListInfos <FALSE> ();
- m_attthis.allViewUpdate ();
- m_attthis.m_ChrVec.RemoveAt (It);
- delete chr;
- m_GuiLV_Chrlist.DeleteItem (index);
- m_GuiLV_Chrlist.SelectItem (0);
- break;
- // TODO: paste object check delete
- }
- }
- }
- }
- break;
- default:
- break;
- }
- default:
- break;
- }
- UpdateInfos (TRUE);
- return 0;
- }
- BEGIN_MSG_MAP(thisClass)
- MESSAGE_HANDLER (WM_INITDIALOG, OnCreate)
- MESSAGE_HANDLER (WM_CLOSE, OnClose)
- MESSAGE_HANDLER (WM_PAINT, OnPaint)
- MESSAGE_HANDLER (WM_VSCROLL, OnVScroll)
- COMMAND_ID_HANDLER (IDBT_CHR_LOADCHR, OnLoadChr)
- COMMAND_ID_HANDLER (IDBT_CHR_ADD_NEW, OnAddChr)
- COMMAND_ID_HANDLER (IDBT_CHR_ADJUST_SEL, OnAdjustChr)
- COMMAND_ID_HANDLER (IDRD_CHR_ALIGN16, OnAlignT<16>)
- COMMAND_ID_HANDLER (IDRD_CHR_ALIGN32, OnAlignT<32>)
- COMMAND_ID_HANDLER (IDRD_CHR_ALIGN64, OnAlignT<64>)
- ALT_MSG_MAP (MAP_CONTROL_LV_DRAWMAIN)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT <MAP_CONTROL_LV_DRAWMAIN>)
- MESSAGE_HANDLER (WM_MOUSEMOVE, OnMouseMoveT <MAP_CONTROL_LV_DRAWMAIN>)
- MESSAGE_HANDLER (WM_LBUTTONUP, OnLButtonUpT <MAP_CONTROL_LV_DRAWMAIN>)
- MESSAGE_HANDLER (WM_RBUTTONUP, OnRButtonUpT <MAP_CONTROL_LV_DRAWMAIN>)
- ALT_MSG_MAP (MAP_CONTROL_LV_DRAWROM)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT <MAP_CONTROL_LV_DRAWROM>)
- MESSAGE_HANDLER (WM_MOUSEMOVE, OnMouseMoveT <MAP_CONTROL_LV_DRAWROM>)
- MESSAGE_HANDLER (WM_LBUTTONUP, OnLButtonUpT <MAP_CONTROL_LV_DRAWROM>)
- MESSAGE_HANDLER (WM_RBUTTONUP, OnRButtonUpT <MAP_CONTROL_LV_DRAWROM>)
- ALT_MSG_MAP (MAP_CONTROL_LV_DRAWRAM)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT <MAP_CONTROL_LV_DRAWRAM>)
- MESSAGE_HANDLER (WM_MOUSEMOVE, OnMouseMoveT <MAP_CONTROL_LV_DRAWRAM>)
- MESSAGE_HANDLER (WM_LBUTTONUP, OnLButtonUpT <MAP_CONTROL_LV_DRAWRAM>)
- MESSAGE_HANDLER (WM_RBUTTONUP, OnRButtonUpT <MAP_CONTROL_LV_DRAWRAM>)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT <MAP_CONTROL_LV_DRAWRAM>)
- ALT_MSG_MAP (MAP_CONTROL_LV_DRAWCHR0PIX)
- MESSAGE_HANDLER (WM_LBUTTONDBLCLK, OnLButtonDblclkT <MAP_CONTROL_LV_DRAWCHR0PIX>)
- ALT_MSG_MAP (MAP_CONTROL_LV_DRAWCHR1PIX)
- MESSAGE_HANDLER (WM_LBUTTONDBLCLK, OnLButtonDblclkT <MAP_CONTROL_LV_DRAWCHR1PIX>)
- ALT_MSG_MAP (MAP_CONTROL_LV_DRAWCHR2PIX)
- MESSAGE_HANDLER (WM_LBUTTONDBLCLK, OnLButtonDblclkT <MAP_CONTROL_LV_DRAWCHR2PIX>)
- ALT_MSG_MAP (MAP_CONTROL_LV_DRAWCHR3PIX)
- MESSAGE_HANDLER (WM_LBUTTONDBLCLK, OnLButtonDblclkT <MAP_CONTROL_LV_DRAWCHR3PIX>)
- ALT_MSG_MAP (MAP_CONTROL_LV_DRAWCHRLIST)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT <MAP_CONTROL_LV_DRAWCHRLIST>)
- MESSAGE_HANDLER (WM_LBUTTONDBLCLK, OnLButtonDblclkT <MAP_CONTROL_LV_DRAWCHRLIST>)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT <MAP_CONTROL_LV_DRAWCHRLIST>)
- END_MSG_MAP()
- LRESULT OnLoadChr (WORD, WORD, HWND /*lParam*/, BOOL& bHandled) {
- CFileDialogFilter df (_T("Chr files (*.chr; *.bin; *nes)| *.chr; *.bin; *nes"));
- CFileDialog fd_dlg ( TRUE, _T ("Open Chr..."),
- NULL, OFN_ALLOWMULTISELECT | OFN_EXPLORER,
- df,
- this->m_hWnd );
- if (fd_dlg.DoModal () == IDOK) {
- // Do stuff.
- CAtlFile fd;
- ULONGLONG fsize;
- HRESULT sig= fd.Create (fd_dlg.m_szFileName,
- GENERIC_READ,
- FILE_SHARE_READ,
- OPEN_EXISTING);
- ATLASSERT (SUCCEEDED (sig));
- sig = fd.GetSize (fsize);
- ATLASSERT (SUCCEEDED (sig));
- sig = fd.Seek (0, FILE_BEGIN);
- ATLASSERT (SUCCEEDED (sig));
- // Check is nes. skip 16 byte nes header. XXX: check too simple.
- if ( ChTraitsCRT<TCHAR>::StringFindString (fd_dlg.m_szFileName, _T (".nes")) != NULL) {
- if (fsize <= 16) {
- AtlMessageBox (*this, _T ("nes file size <= 16!"), _T ("CChrSettings"), MB_ICONERROR);
- return 0;
- }
- fsize -= 16;
- fd.Seek (16, FILE_BEGIN);
- }
- if (fsize <= 0xFFFF) {
- m_64k_page = 1;
- } else {
- m_64k_page = fsize/ 0x10000 + !! (fsize % 0x10000);
- }
- if (m_pchrpool != NULL) {
- CCRTAllocator::Free (m_pchrpool);
- }
- m_pchrpool = static_cast<PBYTE> ( CCRTAllocator ::Allocate (m_64k_page * 0x10000));
- ATLASSERT (m_pchrpool != NULL);
- sig = fd.Read (m_pchrpool, fsize);
- ATLASSERT (SUCCEEDED (sig));
- fd.Close ();
- // Reset v-scroll bar..
- // Per unit 4K ...
- if (m_64k_page <= 1) {
- m_GuiSCR_VDraw.EnableWindow (FALSE);
- } else {
- m_GuiSCR_VDraw.EnableWindow (TRUE);
- SCROLLINFO scrinfos;
- scrinfos.cbSize = sizeof (scrinfos);
- scrinfos.fMask = SIF_ALL;
- scrinfos.nMin = 0;
- scrinfos.nMax = 64 * m_64k_page /* - 1 */;
- scrinfos.nPos = 0;
- scrinfos.nPage = 64;
- m_GuiSCR_VDraw.SetScrollInfo (& scrinfos);
- }
- Invalidate (TRUE);
- }
- return 0;
- }
- LRESULT OnPaint (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- CPaintDC dc (*this);
- UpdateInfos (TRUE);
- bHandled= FALSE;
- return 0;
- }
- LRESULT OnClose (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- m_GuiLV_Drawchr.UnsubclassWindow (TRUE);
- m_GuiLV_Drawrom.UnsubclassWindow (TRUE);
- m_GuiLV_Drawram.UnsubclassWindow (TRUE);
- m_GuiLV_Drawchr0pix.UnsubclassWindow (TRUE);
- m_GuiLV_Drawchr1pix.UnsubclassWindow (TRUE);
- m_GuiLV_Drawchr2pix.UnsubclassWindow (TRUE);
- m_GuiLV_Drawchr3pix.UnsubclassWindow (TRUE);
- m_GuiLV_Chrlist.RemoveImageList (LVSIL_SMALL);
- m_GuiLV_Chrlist.UnsubclassWindow (TRUE);
- m_GuiSCR_VDraw = NULL;
- m_GuiET_Comment = NULL;
- CGlobals::pasteChr = NULL;
- m_attthis.setStatusText (2, _T ("chr cache:empty"));
- EndDialog (IDOK);
- return 0;
- }
- LRESULT OnCreate (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- m_GuiLV_Drawchr.SubclassWindow (GetDlgItem (IDLV_CHR_DRAW));
- m_GuiLV_Drawrom.SubclassWindow (GetDlgItem (IDLV_CHR_SELFEDIT));
- m_GuiLV_Drawram.SubclassWindow (GetDlgItem (IDLV_CHR_MIXER));
- m_GuiLV_Drawchr0pix.SubclassWindow (GetDlgItem (IDLV_CHR_CHR0));
- m_GuiLV_Drawchr1pix.SubclassWindow (GetDlgItem (IDLV_CHR_CHR1));
- m_GuiLV_Drawchr2pix.SubclassWindow (GetDlgItem (IDLV_CHR_CHR2));
- m_GuiLV_Drawchr3pix.SubclassWindow (GetDlgItem (IDLV_CHR_CHR3));
- m_GuiLV_Chrlist.SubclassWindow (GetDlgItem (IDLV_CHR_CHRLIST));
- m_MemoryPaintChrpix0.resetMemoryDC (m_GuiLV_Drawchr0pix);
- m_MemoryPaintChrpix1.resetMemoryDC (m_GuiLV_Drawchr1pix);
- m_MemoryPaintChrpix2.resetMemoryDC (m_GuiLV_Drawchr2pix);
- m_MemoryPaintChrpix3.resetMemoryDC (m_GuiLV_Drawchr3pix);
- m_MemoryPaintDrawpreview.resetMemoryDC (m_GuiLV_Drawchr);
- m_MemoryPaintRom.resetMemoryDC (m_GuiLV_Drawrom);
- m_MemoryPaintRam.resetMemoryDC (m_GuiLV_Drawram);
- // Insert col, desc | value
- LVCOLUMN vcl;
- RtlZeroMemory (& vcl, sizeof (vcl));
- vcl.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
- vcl.pszText = _T ("$");
- vcl.cx = 120;
- m_GuiLV_Chrlist.InsertColumn (0, & vcl);
- m_GuiSCR_VDraw.Attach (GetDlgItem (IDSR_CHR_VDRAW));
- m_GuiET_Comment.Attach (GetDlgItem (IDET_CHR_COMMENT));
- m_GuiLV_Chrlist.SetBkColor (0);
- m_GuiLV_Chrlist.SetTextBkColor (0);
- m_GuiLV_Chrlist.SetTextColor (0xff00);
- // Enum show chr list-infos.
- m_GuiLV_Chrlist.DeleteAllItems ();
- auto &r = m_attthis.m_ChrVec;
- for (int it = 0; it != r.GetCount (); it++) {
- m_GuiLV_Chrlist.InsertItem (it, r[it]->comment);
- m_GuiLV_Chrlist.SetItemData (it, reinterpret_cast <DWORD_PTR> ( r[it]));
- }
- if (m_selchr != NULL) {
- // Fill current pal infos.
- // etComment.SetWindowText (m_newmap->comment);
- CString string;
- m_GuiET_Comment.SetWindowText (m_selchr->comment);
- // Draw chr.
- }
- Invalidate (TRUE);
- CheckDlgButton (IDRD_CHR_ALIGN16, BST_CHECKED);
- m_GuiLV_Chrlist.SetImageList (m_IconChrlist, LVSIL_SMALL);
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnAdjustChr (WORD, WORD, HWND /*lParam*/, BOOL& bHandled) {
- auto index = m_GuiLV_Chrlist.GetSelectedIndex ();
- // m_GuiLV_PalList.Pro
- if (index >= 0) {
- CChr *chr = (CChr *) m_GuiLV_Chrlist.GetItemData (index);
- if (chr != NULL) {
- *chr = m_tmpchr;
- CString string;
- m_GuiET_Comment.GetWindowText (string);
- chr->comment = string;
- CGlobals::adjustCommentUnique (m_attthis.m_ChrVec, chr, FALSE);
- m_GuiLV_Chrlist.SetItemText (index, 0, chr->comment);
- }
- }
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnAddChr (WORD, WORD, HWND /*lParam*/, BOOL& bHandled) {
- auto p = new CChr;
- CString content;
- *p = m_tmpchr;
- m_GuiET_Comment.GetWindowText (content);
- p->comment = content;
- CGlobals::adjustCommentUnique (m_attthis.m_ChrVec, p, TRUE);
- auto index = m_GuiLV_Chrlist.InsertItem (
- m_GuiLV_Chrlist.GetItemCount (),
- p->comment,
- 0);
- m_GuiLV_Chrlist.SetItemData (index, reinterpret_cast <DWORD_PTR> ( p));
- bHandled = FALSE;
- return 0;
- }
- INT_PTR DoModal (CMapUnit *map = NULL)
- {
- // m_newmap = map;
- // Modal it.
- return baseClass::DoModal ();
- }
- };
- // <CMainFrame::CChrSettings End> =========================================
- ~CMainFrame(void) {
- // int intPoint = 0/0;
- //__asm ud2 bug check
- }
- CMainFrame (VOID) :
- m_bShowAttrShadow (FALSE),
- m_subFunc (0),
- m_bShowGridMain (FALSE), /* Q key switch */
- m_bShowGridAttr (FALSE), /* Z key switch */
- m_ptRenderStart (0, 0),
- m_ptRenderEnd (0, 0),
- m_ptRenderStartY (0, 0),
- m_szRenderStartY (0, 0),
- m_ptPastePoint (0, 0),
- m_ShowMap (NULL),
- m_ntpWindowPoll (0),
- m_GuiSWin_Nesmap (*this),
- m_GuiLV_Map(this, MAP_CONTROL_LV_MAP),
- m_GuiLV_Chr (this, MAP_CONTROL_LV_CHR),
- m_GuiLV_Clay (this, MAP_CONTROL_LV_CLAY),
- m_GuiLV_Page (this, MAP_CONTROL_LV_PAGE){
- m_IconMaplist.Create (16,16,ILC_COLOR24|ILC_MASK,1,0);
- m_IconClaylist.Create (16,16,ILC_COLOR24|ILC_MASK,1,0);
- m_IconChrlist.Create (16,16,ILC_COLOR24|ILC_MASK,1,0);
- m_IconPagelist.Create (16,16,ILC_COLOR24|ILC_MASK,1,0);
- // Map-list
- m_IconMaplist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_MAP)));
- // Chr-list
- m_IconChrlist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_CHR)));
- // Page-list
- m_IconPagelist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_PAGE)));
- m_IconPagelist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_CHR)));
- m_IconPagelist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_PRIVATE_PAL )));
- m_IconPagelist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_STATIC_PAL)));
- m_IconPagelist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_GLOBAL_PAL)));
- m_IconPagelist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_ATTRLIST)));
- // Clay-list
- m_IconClaylist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_CLAY)));
- m_IconClaylist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_CHR)));
- m_IconClaylist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_PRIVATE_PAL )));
- m_IconClaylist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_STATIC_PAL)));
- m_IconClaylist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_GLOBAL_PAL)));
- m_IconClaylist.AddIcon (LoadIcon (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDI_ATTRLIST)));
- }
- virtual BOOL PreTranslateMessage(MSG* pMsg)
- {
- if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
- return TRUE;
- else
- return FALSE;
- }
- virtual BOOL OnIdle()
- {
- return FALSE;
- }
- BEGIN_MSG_MAP(CMainFrame)
- MESSAGE_HANDLER (WM_DESTROY, OnDestroy)
- MESSAGE_HANDLER(WM_CREATE, OnCreate)
- COMMAND_ID_HANDLER (ID_FILE_SAVENNEPROJECT, OnSaveNNE)
- COMMAND_ID_HANDLER (IDTB_BT_SAVENNE, OnSaveNNE)
- COMMAND_ID_HANDLER (ID_FILE_LOADNNEPROJECT, OnLoadNNE)
- COMMAND_ID_HANDLER (IDTB_BT_OPENNNE, OnLoadNNE)
- COMMAND_ID_HANDLER (IDTB_BT_OUTCC65, OnOutputCC65)
- CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
- ALT_MSG_MAP (MAP_CONTROL_LV_MAP)
- MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT<MAP_CONTROL_LV_MAP>)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT<MAP_CONTROL_LV_MAP>)
- ALT_MSG_MAP (MAP_CONTROL_LV_PAGE)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT<MAP_CONTROL_LV_PAGE>)
- MESSAGE_HANDLER (WM_LBUTTONDBLCLK, OnLButtonDblclk<MAP_CONTROL_LV_PAGE>)
- MESSAGE_HANDLER (WM_RBUTTONDOWN, OnRButtonDownT<MAP_CONTROL_LV_PAGE>)
- MESSAGE_HANDLER (WM_RBUTTONUP, OnRButtonUpT<MAP_CONTROL_LV_PAGE>)
- COMMAND_ID_HANDLER (ID_SETPAGE_GPAL, (OnSetCommonPaletteT <FALSE, 0>) /* 0 := global palette settings */)
- COMMAND_ID_HANDLER (ID_SETPAGE_SPAL, (OnSetCommonPaletteT <FALSE, 1>) /* 1 := static palette settings */)
- COMMAND_ID_HANDLER (ID_SETPAGE_CHR, (OnSetCommonPaletteT <FALSE, 2>) /* 1 := chr settings */)
- ALT_MSG_MAP (MAP_CONTROL_LV_CHR)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT<MAP_CONTROL_LV_CHR>)
- ALT_MSG_MAP (MAP_CONTROL_LV_CLAY)
- // MESSAGE_HANDLER (WM_LBUTTONDOWN, OnLButtonDownT<MAP_CONTROL_LV_CLAY>)
- MESSAGE_HANDLER (WM_RBUTTONDOWN, OnRButtonDownT<MAP_CONTROL_LV_CLAY>)
- MESSAGE_HANDLER (WM_KEYUP, OnKeyUpT<MAP_CONTROL_LV_CLAY>)
- MESSAGE_HANDLER (WM_LBUTTONDBLCLK, OnLButtonDblclk<MAP_CONTROL_LV_CLAY>)
- COMMAND_ID_HANDLER (ID_SETPAGE_GPAL, (OnSetCommonPaletteT <TRUE, 0>) /* 0 := global palette settings */)
- COMMAND_ID_HANDLER (ID_SETPAGE_CHR, (OnSetCommonPaletteT <TRUE, 2>) /* 1 := chr settings */)
- END_MSG_MAP()
- SFINLINE
- HRESULT atlCreateRwOverwriteFile (CAtlFile &atlfd, CString &path) {
- return atlfd.Create (path,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS);
- }
- SFINLINE
- void atlCreateRwOverwriteFileAssert (CAtlFile &atlfd, CString &path) {
- HRESULT sig = atlCreateRwOverwriteFile (atlfd, path);
- ATLASSERT (SUCCEEDED (sig));
- }
- HRESULT writeSourcePalFiles (int outputSource, /* 0:Global 1:Static 2: local */
- CString outPathBase, /* without \ */
- int palIndex,
- CPal *pal,
- int mapIndex = -1,
- CMapUnit *map = NULL,
- CPoint *point = NULL,
- CNametableCell <FALSE> *ntCell = NULL)
- {
- HRESULT sig = 0;
- CAtlFile outInlFd;
- CAtlFile outPalFd;
- CString outInlPath = outPathBase + _T ("\\");
- CString outPalPath = outPathBase + _T ("\\");
- CStringA comment;
- :: PathRemoveBackslash (outPathBase.GetBuffer ());
- outPathBase.ReleaseBuffer ();
- // Output format.
- if (outputSource == 0) {
- outInlPath.AppendFormat (_T ("msgp%d.inl"), palIndex);
- outPalPath.AppendFormat (_T ("msgp%d.pal"), palIndex);
- comment.Append ("// --------------------------------------------------\n");
- comment.Append ("// Section:Global Palette\n");
- comment.AppendFormat (
- "// Index[Comment]:%d %s\n", palIndex, CStringA (pal->comment));
- comment.Append ("// --------------------------------------------------\n");
- comment.AppendFormat (
- "#define MSGP_%s msgp%d\n", CStringA (pal->comment), palIndex);
- comment.AppendFormat (
- "unsigned char msgp%d[16] = { \n", palIndex);
- } else if (outputSource == 1) {
- comment.Append ("// --------------------------------------------------\n");
- comment.Append ("// Section:Static Palette\n");
- comment.AppendFormat (
- "// Index[Comment]:%d %s\n", palIndex, CStringA (pal->comment));
- comment.AppendFormat (
- "// SubMapper[Comment]:%d %s\n", mapIndex, CStringA (map->comment));
- comment.Append ("// --------------------------------------------------\n");
- comment.AppendFormat (
- "#define MSSP%d_%d_%s mssp%d_%d\n", mapIndex, palIndex, CStringA (pal->comment),
- mapIndex, palIndex );
- comment.AppendFormat (
- "unsigned char mssp%d_%d[16] = { \n", mapIndex, palIndex);
- outInlPath.AppendFormat (_T ("mssp%d_%d.inl"), mapIndex, palIndex);
- outPalPath.AppendFormat (_T ("mssp%d_%d.pal"), mapIndex, palIndex);
- } else if (outputSource == 2) {
- comment.Append ("// --------------------------------------------------\n");
- comment.Append ("// Section:Local Palette\n");
- comment.AppendFormat (
- "// Index[Comment]:%d %s\n", palIndex, CStringA (pal->comment));
- comment.AppendFormat (
- "// SubMapper[Comment]:%d %s\n", mapIndex, CStringA (map->comment));
- comment.AppendFormat (
- "// SubMapper size:%d %d\n", map->width, map->height);
- comment.AppendFormat (
- "// SubMapper position:%d %d\n", point->x, point->y);
- comment.Append ("// --------------------------------------------------\n");
- comment.AppendFormat (
- "#define MSLP%d_%d_%d_%d_%s mslp%d_%d_%d_%d\n",
- mapIndex, point->x, point->y, palIndex, pal->comment,
- mapIndex, point->x, point->y, palIndex);
- comment.AppendFormat (
- "unsigned char mslp%d_%d_%d_%d[16] = { \n", mapIndex, point->x, point->y, palIndex);
- outInlPath.AppendFormat (_T ("mslp%d_%d_%d_%d.inl"), mapIndex, point->x, point->y, palIndex);
- outPalPath.AppendFormat (_T ("mslp%d_%d_%d_%d.pal"), mapIndex, point->x, point->y, palIndex);
- } else {
- ATLASSERT (FALSE);
- }
- if (FAILED (sig = outInlFd.Create (outInlPath,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return sig;
- }
- if (FAILED (sig = outPalFd.Create (outPalPath,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return sig;
- }
- for (auto count = 0;
- count != 16;
- count += 4)
- {
- PBYTE source = & pal->pal[count];
- comment.AppendFormat ("/* bank %d */ 0x%02X, 0x%02X, 0x%02X, 0x%02X",
- count >> 2, source[0] & 0x3F,
- source[1] & 0x3F,
- source[2] & 0x3F, source[3] & 0x3F);
- if (count != 12) {
- comment += ", \n";
- }
- }
- comment += "\n};";
- sig = outInlFd.Write (comment.GetString (),
- comment.GetLength ());
- ATLASSERT (SUCCEEDED (sig));
- sig = outPalFd.Write (pal->pal, 16);
- ATLASSERT (SUCCEEDED (sig));
- return sig;
- }
- HRESULT outputCC65 (CString filePath) {
- HRESULT sig = 0;
- BYTE transMapper = 0;
- PathRemoveBackslash (filePath.GetBuffer ());
- filePath.ReleaseBuffer ();
- filePath += _T ("\\");
- // Output globals.h
- CStringA globalsString(
- #include "nne_globals.string"
- );
- CStringA outputString;
- CAtlFile outGlobalsFd;
- CAtlFile outOutputFd;
- //TODO: Check
- CString nneOutputBase = filePath + _T ("NNametableEditorOutput");
- CString nneOutputCC65 = nneOutputBase + _T ("\\cc65");
- CString nneOutputCC65_chr = nneOutputBase + _T ("\\cc65\\chr");
- CString nneOutputCC65_map = nneOutputBase + _T ("\\cc65\\map");
- CString nneOutputCC65_gpal = nneOutputBase + _T ("\\cc65\\global_palette");
- CString nneOutputCA65 = nneOutputBase + _T ("\\ca65");
- CString nneOutputCA65_chr = nneOutputBase + _T ("\\ca65\\chr");
- CString nneOutputCA65_map = nneOutputBase + _T ("\\ca65\\map");
- CString nneOutputCA65_gpal = nneOutputBase + _T ("\\ca65\\global_palette");
- // Create file path...
- :: CreateDirectory (nneOutputBase, NULL);
- :: CreateDirectory (nneOutputCC65, NULL);
- :: CreateDirectory (nneOutputCC65_chr, NULL);
- :: CreateDirectory (nneOutputCC65_map, NULL);
- :: CreateDirectory (nneOutputCC65_gpal, NULL);
- :: CreateDirectory (nneOutputCA65, NULL);
- :: CreateDirectory (nneOutputCA65_chr, NULL);
- :: CreateDirectory (nneOutputCA65_map, NULL);
- :: CreateDirectory (nneOutputCA65_gpal, NULL);
- // Prepare nne_globals header.
- if (FAILED (sig = outGlobalsFd.Create (nneOutputCC65 + _T ("\\nne_globals.h"),
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return sig;
- }
- sig = outGlobalsFd.Write (globalsString.GetString (),
- globalsString.GetLength ());
- ATLASSERT (SUCCEEDED (sig));
- // Prepare nne_bg header.
- if (FAILED (sig = outOutputFd.Create (nneOutputCC65 + _T ("\\nne_bg.h"),
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return sig;
- }
- outputString.Append ("#include \"nne_globals.h\"\n\n");
- // Create sub map path...
- for (auto it = 0; it != m_GuiLV_Map.GetItemCount (); it ++) {
- CString subMapPath = nneOutputCC65_map + _T ("\\");
- subMapPath.AppendFormat (_T ("sub%d"), it);
- :: CreateDirectory (subMapPath , NULL);
- :: CreateDirectory (subMapPath , NULL);
- }
- // <Output CC65-CHR> ===============================================================================
- outputString.Append ("// <section-chr #include>\n");
- for (auto it = 0; it != m_ChrVec.GetCount (); it ++) {
- CChr *chr = m_ChrVec[it];
- CString chrInlPath = nneOutputCC65_chr + _T ("\\");
- CString chrChrPath = nneOutputCC65_chr + _T ("\\");
- chrInlPath.AppendFormat (_T ("chr%d.inl"), it);
- chrChrPath.AppendFormat (_T ("chr%d.chr"), it);
- outputString.AppendFormat ("#include \"chr/chr%d.inl\" // %s\n", it, CStringA (chr->comment));
- // Create .inl/.chr files.
- CAtlFile chrInlFd;
- CAtlFile chrFileFd;
- if (FAILED (sig = chrInlFd.Create (chrInlPath,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return sig;
- }
- if (FAILED (sig = chrFileFd.Create (chrChrPath,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return sig;
- }
- // Out chr content -comment
- CStringA comment;
- comment.Format ( "// --------------------------------------------------\n"
- "// Section:Chr \n"
- "// Index[Comment]:%d %s\n"
- "// --------------------------------------------------\n"
- "#define NNE_CHR_%s nne_chr%d\n"
- "unsigned char nne_chr%d[0x1000] = { \n",
- it, /* index */
- CStringA (chr->comment), /* comment */
- CStringA (chr->comment), /* comment */
- it, /* index */
- it /* index */);
- // Out chr content -buffer
- for (auto count = 0;
- count != 4096;
- count += 16)
- {
- PBYTE source = & chr->chr[count];
- comment.AppendFormat (" 0x%02X, 0x%02X, 0x%02X, 0x%02X,"
- " 0x%02X, 0x%02X, 0x%02X, 0x%02X,"
- " 0x%02X, 0x%02X, 0x%02X, 0x%02X,"
- " 0x%02X, 0x%02X, 0x%02X, 0x%02X",
- source[0], source[1], source[2], source[3],
- source[4], source[5], source[6], source[7],
- source[8], source[9], source[10], source[11],
- source[12], source[13], source[14], source[15]);
- if (count != 4096 - 16) {
- comment += ", \n";
- }
- }
- comment += "\n};";
- sig = chrInlFd.Write (comment.GetString (),
- comment.GetLength ());
- ATLASSERT (SUCCEEDED (sig));
- sig = chrFileFd.Write (& chr->chr[0], 4096);
- ATLASSERT (SUCCEEDED (sig));
- }
- // Output global palette...
- outputString.Append ("// <global palette #include>\n");
- for (auto it = 0; it != m_globalPal.GetCount (); it ++) {
- auto pal = m_globalPal[it];
- outputString.AppendFormat ("#include \"global_palette/msgp%d.inl\" // %s\n", it, CStringA (pal->comment));
- writeSourcePalFiles (0, nneOutputCC65_gpal, it, pal);
- }
- // Output sub map view .
- outputString.Append ("// <section-map #include>\n");
- for (auto it = 0; it != m_MapVec.GetCount (); it ++) {
- CString subMapPath = nneOutputCC65_map + _T ("\\");
- CString subMapPathSubInl = subMapPath;
- CStringA subComment;
- CAtlFile subHeader;
- subMapPath.AppendFormat (_T ("sub%d"), it);
- subMapPathSubInl.AppendFormat (_T ("sub%d.inl"), it);
- auto map = m_MapVec[it];
- ATLASSERT (map != NULL);
- outputString.AppendFormat ("#include \"map/sub%d.inl\" // %s %d %d spcount:%d\n",
- it, CStringA (map->comment), map->width, map->height,
- map->staticPal.GetCount ());
- atlCreateRwOverwriteFileAssert (subHeader, subMapPathSubInl);
- // Output sub map static palette
- subComment.AppendFormat ("// <static-palette>:%d\n", map->staticPal.GetCount ());
- auto spallist = & map->staticPal;
- for (auto q = 0; q != spallist->GetCount (); q ++) {
- auto pal = (*spallist)[q];
- subComment.AppendFormat ("#include \"sub%d/mssp%d_%d\" // %s\n", it, it, q, CStringA (pal->comment));
- writeSourcePalFiles (1, subMapPath, q, pal, it, map);
- }
- const auto pageTotal = map->width * map->height;
- for (auto q = 0; q != pageTotal; q++) {
- auto nt = map->ntList[q];
- auto x = q % map->width;
- auto y = q / map->width;
- subComment.AppendFormat ("//<nametable page>: pos: %d %d pcnt:%d acnt:%d\n",
- x, y, nt->palList.GetCount (), nt->attrList.GetCount ());
- CString ntPathBase = subMapPath + _T ("\\");
- CString ntPathInlOut = ntPathBase;
- CString ntPathNamOut = ntPathBase;
- CAtlFile ntInlFd;
- CAtlFile ntNamFd;
- subComment.AppendFormat ("#include \"sub%d/msnt%d_%d_%d.inl\"\n", it, it, x, y);
- ntPathInlOut.AppendFormat (_T ("msnt%d_%d_%d.inl"), it, x, y);
- ntPathNamOut.AppendFormat (_T ("msnt%d_%d_%d.nam"), it, x, y);
- if (FAILED (sig = ntInlFd.Create (ntPathInlOut,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return sig;
- }
- if (FAILED (sig = ntNamFd.Create (ntPathNamOut,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return sig;
- }
- // Output nametable .inl | .nam
- CStringA comment;
- CStringA indexMixerA;
- CString indexMixer;
- indexMixerA.Format ("%d_%d_%d", it, x, y);
- indexMixer.Format (_T ("%d_%d_%d"), it, x, y);
- comment.Append ("// --------------------------------------------------\n");
- comment.Append ("// Section:Namtable\n");
- comment.AppendFormat (
- "// PalCount:%d\n", nt->palList.GetCount ());
- comment.AppendFormat (
- "// AttrCount:%d\n", nt->attrList.GetCount ());
- if (nt->chr != NULL)
- comment.AppendFormat (
- "// Attach chr[Comment]:%d %s\n", forceFindIndexByComment <CChr> (
- m_ChrVec, & nt->chr->comment ),
- CStringA (nt->chr->comment));
- else
- comment.AppendFormat ("// Attach chr[Comment]:-1\n");
- comment.AppendFormat (
- "// SubMapper Index[Comment]:%d %s\n", it, CStringA (map->comment));
- comment.AppendFormat (
- "// SubMapper Size:%d %d\n", map->width, map->height);
- comment.AppendFormat (
- "// SubMapper Position:%d %d\n", x, y);
- if (nt->pal != NULL)
- comment.AppendFormat (
- "// Default use palette :%s %d %s\n", nt->getSelectPalSource (),
- nt->getSelectPalSourceOffset (), nt->pal->comment);
- else
- comment.Append ("// Default use palette :null\n");
- if (nt->attr != NULL)
- comment.AppendFormat (
- "// Default use attr table:%d %s\n", forceFindIndexByComment <CAttr> (
- nt->attrList, & nt->attr->comment ),
- CStringA (nt->attr->comment) );
- else
- comment.Append ("// Default use palette :-1\n");
- comment.Append ("// --------------------------------------------------\n");
- comment.AppendFormat (
- "#define MSNT%s msnt%s\n", indexMixerA, indexMixerA);
- comment.AppendFormat (
- "unsigned char msnt%s[0x400] = { \n", indexMixerA);
- comment.Append (" /* ----- 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F "
- "10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F */\n");
- // Output buffer ...
- for (auto count = 0;
- count != 960;
- count += 32)
- {
- PWORD source = & nt->tileSlot[count];
- comment.AppendFormat (" /* %02X */ NNE_NT_LINE(%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,"
- "%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,"
- "%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X,"
- "%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X)",
- count >> 5,
- #define TTN(index)\
- source[index] & 0x8000 ? transMapper : source[index] & 0xFF
- TTN (0), TTN (1), TTN (2), TTN (3),
- TTN (4), TTN (5), TTN (6), TTN (7),
- TTN (8), TTN (9), TTN (10), TTN (11),
- TTN (12), TTN (13), TTN (14), TTN (15),
- TTN (16), TTN (17), TTN (18), TTN (19),
- TTN (20), TTN (21), TTN (22), TTN (23),
- TTN (24), TTN (25), TTN (26), TTN (27),
- TTN (28), TTN (29), TTN (30), TTN (31) );
- #undef TTN
- if (count != 960 - 32) {
- comment += ", \n";
- }
- }
- comment += "\n};";
- sig = ntInlFd.Write (comment.GetString (),
- comment.GetLength ());
- ATLASSERT (SUCCEEDED (sig));
- for (auto it = 0; it != 960; it += 4) {
- BYTE filldw[4];
- filldw[0] = nt->tileSlot[it+0] & 0x8000 ? transMapper : nt->tileSlot[it+0] & 0xFF;
- filldw[1] = nt->tileSlot[it+1] & 0x8000 ? transMapper : nt->tileSlot[it+1] & 0xFF;
- filldw[2] = nt->tileSlot[it+2] & 0x8000 ? transMapper : nt->tileSlot[it+2] & 0xFF;
- filldw[3] = nt->tileSlot[it+3] & 0x8000 ? transMapper : nt->tileSlot[it+3] & 0xFF;
- sig = ntNamFd.Write (& filldw[0], 4);
- ATLASSERT (SUCCEEDED (sig));
- }
- // Output attr table
- for (auto z = 0; z != nt->attrList.GetCount (); z++) {
- auto attr = nt->attrList[z];
- subComment.AppendFormat ("#include \"sub%d/msat%d_%d_%d_%d.inl\" // %s\n", it, it, x, y, z, CStringA (attr->comment));
- CString ntPathBase = subMapPath + _T ("\\");
- CString attrPathInlOut = ntPathBase;
- CString attrPathAttrOut = ntPathBase;
- CAtlFile attrInlFd;
- CAtlFile attrAttrFd;
- CStringA comment;
- CStringA indexMixerA;
- CString indexMixer;
- indexMixerA.Format ("%d_%d_%d_%d", it, x, y, z);
- indexMixer.Format (_T ("%d_%d_%d_%d"), it, x, y, z);
- attrPathInlOut += _T ("msat") + indexMixer + _T (".inl");
- attrPathAttrOut += _T ("msat") + indexMixer + _T (".attr");
- if (FAILED (sig = attrInlFd.Create (attrPathInlOut,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return sig;
- }
- if (FAILED (sig = attrAttrFd.Create (attrPathAttrOut,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return sig;
- }
- comment.Append ("// --------------------------------------------------\n");
- comment.Append ("// Section:Attr table\n\n");
- comment.AppendFormat (
- "// Index[Comment]:%d %s\n", z, CStringA (attr->comment));
- comment.AppendFormat (
- "// SubMapper Index[Comment]:%d %s\n", it, CStringA (map->comment));
- comment.AppendFormat (
- "// SubMapper Size:%d %d\n\n", map->width, map->height);
- comment.AppendFormat (
- "// SubMapper Position:%d %d\n", x, y);
- comment.Append ("// --------------------------------------------------\n");
- comment.AppendFormat (
- "#define MSAT%s%s msat%s\n", indexMixerA, CStringA (attr->comment),
- indexMixerA );
- comment.AppendFormat (
- "NNE_ATTR_TABLE_INIT (msat%s,\n", indexMixerA);
- comment.Append (" /* ----- 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 */\n");
- // Output buffer ...
- for (DWORD count = 0;
- count != 16;
- count += 1)
- {
- DWORD atrSftLo = count & 1 << 2;
- DWORD atrSftHi = atrSftLo + 2;
- PBYTE atrPtr = & attr->attr[count >> 1 << 3];
- comment.AppendFormat (" /* %02d */ %d,%d,%d,%d"
- ",%d ,%d ,%d ,%d"
- " ,%d ,%d ,%d ,%d"
- " ,%d ,%d ,%d ,%d",
- count << 1,
- atrPtr[0] >> atrSftLo & 3, atrPtr[0] >> atrSftHi & 3,
- atrPtr[1] >> atrSftLo & 3, atrPtr[1] >> atrSftHi & 3,
- atrPtr[2] >> atrSftLo & 3, atrPtr[2] >> atrSftHi & 3,
- atrPtr[3] >> atrSftLo & 3, atrPtr[3] >> atrSftHi & 3,
- atrPtr[4] >> atrSftLo & 3, atrPtr[4] >> atrSftHi & 3,
- atrPtr[5] >> atrSftLo & 3, atrPtr[5] >> atrSftHi & 3,
- atrPtr[6] >> atrSftLo & 3, atrPtr[6] >> atrSftHi & 3,
- atrPtr[7] >> atrSftLo & 3, atrPtr[7] >> atrSftHi & 3);
- if (count != 16 - 1)
- comment += ", \n";
- else
- comment += ")";
- }
- sig = attrInlFd.Write (comment.GetString (),
- comment.GetLength ());
- ATLASSERT (SUCCEEDED (sig));
- sig = attrAttrFd.Write (& attr->attr[0], 64);
- ATLASSERT (SUCCEEDED (sig));
- }
- // Output local palette
- for (auto z = 0; z != nt->palList.GetCount (); z++) {
- auto pal = nt->palList[z];
- subComment.AppendFormat ("#include \"sub%d/mslp%d_%d_%d_%d.inl\"// %s\n", it, it, x, y, z, CStringA (pal->comment));
- writeSourcePalFiles (2, subMapPath, z, nt->palList[z], it, map, & CPoint (x, y), nt);
- }
- }
- sig = subHeader.Write (subComment.GetString (),
- subComment.GetLength ());
- ATLASSERT (SUCCEEDED (sig));
- }
- sig = outOutputFd.Write (outputString.GetString (),
- outputString.GetLength ());
- ATLASSERT (SUCCEEDED (sig));
- return FALSE;
- }
- HRESULT OnOutputCC65 (WORD, WORD, HWND, BOOL &bHandled) {
- CFolderDialog win32fd_dlg (*this, _T ("Output cc65 files"), BIF_USENEWUI|BIF_RETURNONLYFSDIRS);
- if (win32fd_dlg.DoModal () == IDOK) {
- outputCC65 (win32fd_dlg.m_szFolderPath);
- }
- return 0;
- }
- // <CSetPagePalette> =========================================
- template <BOOL t_bReadWriteMap, DWORD t_dwSourcePaletteType>
- struct CSetPagePalette : public CDialogImpl<CSetPagePalette<t_bReadWriteMap, t_dwSourcePaletteType>>
- {
- typedef CSetPagePalette thisClass;
- typedef CDialogImpl<CSetPagePalette<t_bReadWriteMap, t_dwSourcePaletteType>> baseClass;
- CMainFrame &m_attthis;
- CComboBox m_GuiCB_Index;
- CSetPagePalette (CMainFrame &psthis):
- m_attthis (psthis){}
- enum { IDD = IDD_SETPAGE_PALETTE };
- BEGIN_MSG_MAP(thisClass)
- MESSAGE_HANDLER (WM_INITDIALOG, OnCreate)
- MESSAGE_HANDLER (WM_CLOSE, OnClose)
- COMMAND_ID_HANDLER (IDBT_SETPAGE_PALETTE_SETTINGS, OnSettings)
- END_MSG_MAP()
- LRESULT OnSettings (WORD, WORD, HWND, BOOL& bHandled) {
- CMainFrame::CCPObjectHelper<t_bReadWriteMap> helper (m_attthis);
- auto &lvPage = *helper.getCPListViewObject ();
- auto itemSel = lvPage.GetNextItem (-1, LVNI_SELECTED);
- auto itemSetIndex = m_GuiCB_Index.GetCurSel ();
- while (itemSel >= 0) {
- auto nt = lvPage.GetItemDataT (itemSel);
- ATLASSERT (nt != NULL);
- if (t_dwSourcePaletteType == 0) {
- nt->pal = nt->globalPalList[itemSetIndex];
- nt->setIfEmptySelect0 ();
- } else if (t_dwSourcePaletteType == 1) {
- nt->pal = nt->staticPalList[itemSetIndex];
- nt->setIfEmptySelect0 ();
- } else if (t_dwSourcePaletteType == 2) {
- nt->chr = m_attthis.m_ChrVec[itemSetIndex];
- }
- // Reset text.
- lvPage.SetItem (itemSel, 1, LVIF_IMAGE | LVIF_TEXT, nt->chr ? nt->chr->comment : _T ("null"), 1, 0, 0, 0);
- lvPage.SetItem (itemSel, 2, LVIF_IMAGE | LVIF_TEXT, nt->pal ? nt->pal->comment : _T ("null"), 2 + nt->getSelectPalSourceIndex (), 0, 0, 0);
- lvPage.SetItem (itemSel, 3, LVIF_IMAGE | LVIF_TEXT, nt->attr ? nt->attr->comment : _T ("null"), 5, 0, 0, 0);
- itemSel = lvPage.GetNextItem (itemSel, LVNI_SELECTED);
- }
- helper.allCPCellViewSMutUpdate ();
- m_attthis.m_GuiSWin_Nesmap.nesPixelGenerator ();
- EndDialog (IDOK);
- return 0;
- }
- LRESULT OnClose (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- bHandled = FALSE;
- EndDialog (IDCANCEL);
- return 0;
- }
- /* t_dwSourcePaletteType 0 := global palette settings */
- /* t_dwSourcePaletteType 1 := static palette settings */
- /* t_dwSourcePaletteType 2 := chr settings */
- LRESULT OnCreate (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
- m_GuiCB_Index.Attach (GetDlgItem (IDCB_SETPAGE_PALINDEX));
- #define SPP_SETITEM_BASE(capSettingsText, attObj, errorsText, errorsCaption)\
- SetWindowText (capSettingsText);\
- \
- auto &vec = attObj;\
- \
- if (vec.GetCount () != 0) {\
- for (auto it = 0; it != vec.GetCount (); it++) {\
- CString output;\
- output.Format (_T ("%d %s"), it, vec[it]->comment);\
- m_GuiCB_Index.InsertString (it, output);\
- }\
- m_GuiCB_Index.SetCurSel (0);\
- return 0;\
- } else {\
- AtlMessageBox (*this, errorsText, errorsCaption, MB_ICONERROR);\
- EndDialog (IDCANCEL);\
- return 0;\
- }
- if (t_dwSourcePaletteType == 0) {
- SPP_SETITEM_BASE (_T ("Glabal Palette Page Settings-"), m_attthis.m_globalPal, _T ("no global palette"), _T ("CSetPagePalette"));
- } else if (t_dwSourcePaletteType == 1) {
- SPP_SETITEM_BASE (_T ("Static Palette Page Settings-"), m_attthis.m_ShowMap->staticPal, _T ("no static palette"), _T ("CSetPagePalette"));
- } else if (t_dwSourcePaletteType == 2) {
- SPP_SETITEM_BASE (_T ("Chr Page Settings-"), m_attthis.m_ChrVec, _T ("no chr"), _T ("CSetPageChr"));
- } else {
- ATLASSERT (FALSE);
- }
- #undef SPP_SETITEM_BASE
- bHandled = FALSE;
- return 0;
- }
- };
- /* t_dwSourcePaletteType 0 := global palette settings */
- /* t_dwSourcePaletteType 1 := static palette settings */
- /* t_dwSourcePaletteType 2 := chr settings */
- template <BOOL t_bReadWriteMap, DWORD t_dwSourcePaletteType> // @NEXTTASK
- HRESULT OnSetCommonPaletteT (WORD, WORD, HWND, BOOL &bHandled) {
- CSetPagePalette<t_bReadWriteMap, t_dwSourcePaletteType> (*this).DoModal ();
- return 0;
- }
- HRESULT OnLoadNNE (WORD, WORD, HWND, BOOL &bHandled) {
- CFileDialogFilter df (_T("NNE files (*.nne)| *.nne"));
- CFileDialog fd_dlg ( TRUE, _T ("Open NNE project..."),
- NULL, OFN_EXPLORER,
- df,
- this->m_hWnd );
- if (fd_dlg.DoModal () == IDOK) {
- CString errors;
- if (readNNEFile (CString (fd_dlg.m_szFileName), errors) == FALSE) {
- ///
- AtlMessageBox (NULL, errors.GetString (),
- _T ("OnLoadNNE"),
- MB_ICONERROR);
- return 0;
- }
- allViewUpdate ();
- }
- return 0;
- }
- HRESULT OnSaveNNE (WORD, WORD, HWND, BOOL &bHandled) {
- CFileDialogFilter df (_T("NNE files (*.nne)| *.nne"));
- CFileDialog fd_dlg ( FALSE, _T ("Save NNE project..."),
- NULL, OFN_EXPLORER,
- df,
- this->m_hWnd );
- if (fd_dlg.DoModal () == IDOK) {
- adjustSpecPalette ();
- if (writeNNEFile (CString (fd_dlg.m_szFileName)) == FALSE) {
- ///
- AtlMessageBox (NULL, _T ("errors- writeNNEFile"),
- _T ("OnSaveNNE"),
- MB_ICONERROR);
- return 0;
- }
- }
- return 0;
- }
- void destroyAllItem (void) {
- m_GuiLV_Chr.DeleteAllItems ();
- m_GuiLV_Clay.DeleteAllItems ();
- m_GuiLV_Map.DeleteAllItems ();
- m_GuiLV_Page.DeleteAllItems ();
- // Clear chr ...
- for (auto it = 0; it != m_ChrVec.GetCount (); it ++) {
- auto p = m_ChrVec[it];
- if (p != NULL) {
- delete p;
- }
- }
- // Clear clay
- for (auto it = 0; it != m_VnpVec.GetCount (); it ++) {
- auto p = m_VnpVec[it];
- if (p != NULL) {
- delete p;
- }
- }
- // Clear map
- for (auto it = 0; it != m_MapVec.GetCount (); it ++) {
- auto p = m_MapVec[it];
- if (p != NULL) {
- delete p;
- }
- }
- // Clear gloal palete
- for (auto it = 0; it != m_globalPal.GetCount (); it ++) {
- auto p = m_globalPal[it];
- delete p;
- }
- m_globalPal.RemoveAll ();
- m_ChrVec.RemoveAll ();
- m_VnpVec.RemoveAll ();
- m_MapVec.RemoveAll ();
- m_ShowMap = NULL;
- //Clear windows
- clearClayWindow ();
- clearNtpWindow ();
- }
- VOID removeChr (CChr *chr) {
- for (auto It = 0; It != m_ChrVec.GetCount (); It++) {
- if (m_ChrVec[It] == chr) {
- // delete nametable page's attach link
- for (auto Iz = 0; Iz != m_MapVec.GetCount (); Iz++) {
- auto &vec3 = m_MapVec[Iz]->ntList;
- for (auto Iq = 0; Iq != vec3.GetCount (); Iq++) {
- if (vec3[Iq]->chr == chr) {
- // empty it.
- vec3[Iq]->chr = NULL;
- }
- }
- }
- m_ChrVec.RemoveAt( It);
- delete chr;
- break;
- }
- }
- }
- template <typename T>
- INT32 forceFindIndexByComment (CAtlArray<T *> &vec, CString *comment) {
- ATLASSERT (comment != NULL);
- for (auto it = 0; it != vec.GetCount (); it++) {
- auto p = vec[it];
- if (p->comment == *comment) {
- return it;
- }
- }
- // Never reach here..
- ATLASSERT (FALSE);
- }
- BOOL readNNEFile (LPCTSTR filename, CString &error_) {
- // CAtlFileMapping
- CAtlFile win32fd;
- CAtlFileMapping <BYTE> win32map;
- #undef ERRORS_RET
- #undef EZ_ERRORS_RET
- #define ERRORS_RET(/* LPCTSTR */ error__)\
- do { error_ = error__ + CGlobals::getLastErrorString (); return FALSE; } while (0)
- #define EZ_ERRORS_RET(/* LPCTSTR */ error__)\
- do { error_ = error__; return FALSE; } while (0)
- #define READ_COMMENT(/* ptr source string**/loc_string, /* CString **/ pointer, mapperRef) \
- if ((mapperRef).commentLength != 0) {\
- CString tmpString ( (LPWSTR) (loc_string), \
- (mapperRef).commentLength);\
- (pointer)->comment = tmpString;\
- }
- if (FAILED (win32fd.Create (filename,
- GENERIC_READ,
- FILE_SHARE_READ,
- OPEN_EXISTING)) != FALSE) {
- ERRORS_RET (_T ("CAtlFile::Create Failed\n"));
- }
- if (FAILED (win32map.MapFile
- (win32fd, 0)) != FALSE) {
- ERRORS_RET (_T ("CAtlCAtlFileMapping <BYTE>::MapFile Failed\n"));
- }
- auto fileSize = win32map.GetMappingSize ();
- auto pBuffer = static_cast<PBYTE> (win32map.GetData ());
- if (fileSize >= sizeof (CNNEFile::NNEHeader)) {
- auto header = (CNNEFile::NNEHeader *) pBuffer;
- char magic[] = "moecmks nes-nne";
- if (strncmp ((const char *)& header->magic[0], magic, sizeof (header->magic)) == 0) {
- // Check crc32
- auto crc32 = CGlobals::crc32_intel (0,
- & pBuffer[sizeof (CNNEFile::NNEHeader)],
- fileSize - sizeof (CNNEFile::NNEHeader));
- if (crc32 == header->crc32_intel) {
- // Reset current ctx
- destroyAllItem ();
- PBYTE pRelocChrPool = & pBuffer[header->chrPoolOffset];
- PBYTE pRelocAttrPool = & pBuffer[header->attrPoolOffset];
- PBYTE pRelocPalettePool = & pBuffer[header->palettePoolOffset];
- PBYTE pRelocNametablePool = & pBuffer[header->nclayPoolOffset];
- PBYTE pRelocStringPool = & pBuffer[header->stringPoolOffset];
- // Read global palette...
- auto gpalChunkPtr = (CNNEFile::palChunk *) & pBuffer[header->gPaletteChainOffset];
- for (auto it = 0; it != header->gPaletteCount; it++) {
- auto p = new CPal (CPal::global_palette);
- auto &src_r = gpalChunkPtr[it];
- // copy pal index.
- RtlCopyMemory (p->pal, & pRelocPalettePool[src_r.palIndex << 4], 16);
- READ_COMMENT ( (& pRelocStringPool[src_r.commentOffset]), p, src_r)
- m_globalPal.InsertAt (m_globalPal.GetCount (), p);
- }
- // Read chr-chain...
- auto chrChunkPtr = (CNNEFile::chrSectionChunk *) & pBuffer[header->chrChainOffset];
- for (auto it = 0; it != header->chrCount; it++) {
- auto pMapper = & chrChunkPtr[it];
- auto p = new CChr;
- // Copy chr
- RtlCopyMemory (p->chr, & pRelocChrPool[pMapper->chrIndex * 0x1000], 0x1000);
- READ_COMMENT ( (& pRelocStringPool[pMapper->commentOffset]), p, *pMapper)
- m_ChrVec.InsertAt (m_ChrVec.GetCount (), p);
- }
- // Read clay-chain ...
- auto pClayOffset = (PDWORD) & pBuffer[header->clayChainOffset];
- for (auto it =0; it != header->clayCount; it++) {
- auto pMapperClaySecChunk =
- (CNNEFile::claySectionChunkHeader *) & pBuffer[pClayOffset[it]];
- auto pClay = new CNametableCell<TRUE> (m_globalPal, m_globalPal, FALSE);
- READ_COMMENT ( (& pRelocStringPool[pMapperClaySecChunk->commentOffset]), pClay, *pMapperClaySecChunk)
- // Copy nametable
- RtlCopyMemory (pClay->tileSlot, & pRelocNametablePool[pMapperClaySecChunk->clayIndex * 0x800], 0x800);
- // Attach chr
- pClay->chr = NULL;
- pClay->attr = NULL;
- pClay->pal = NULL;
- if (pMapperClaySecChunk->chrIndex != MAXDWORD) {
- ATLASSERT (pMapperClaySecChunk->chrIndex < m_ChrVec.GetCount ());
- pClay->chr = m_ChrVec[pMapperClaySecChunk->chrIndex ];
- }
- // Copy attr table list
- auto pAttrChunk = (CNNEFile::attrChunk *) & pBuffer[pClayOffset[it]+sizeof (CNNEFile::claySectionChunkHeader)];
- for (auto it = 0; it != pMapperClaySecChunk->attrCount; it++) {
- auto pMapperChunk = & pAttrChunk[it];
- auto pAttr = new CAttr;
- READ_COMMENT ( (& pRelocStringPool[pMapperChunk->commentOffset]), pAttr, *pMapperChunk)
- // Copy nametable
- RtlCopyMemory (pAttr->attr, & pRelocAttrPool[pMapperChunk->attrIndex * 64], 64);
- // Check select
- if (pMapperClaySecChunk->attrSel == it) {
- pClay->attr = pAttr;
- }
- pClay->attrList.InsertAt (pClay->attrList.GetCount (), pAttr);
- }
- // Copy pal list
- auto pPalChunk = (CNNEFile::palChunk *) & pAttrChunk[pMapperClaySecChunk->attrCount];
- for (auto it = 0; it != pMapperClaySecChunk->paletteCount; it++) {
- auto pMapperChunk = & pPalChunk[it];
- auto pPal = new CPal (CPal::private_palette);
- READ_COMMENT ( (& pRelocStringPool[pMapperChunk->commentOffset]), pPal, *pMapperChunk)
- // Copy nametable
- RtlCopyMemory (pPal->pal, & pRelocPalettePool[pMapperChunk->palIndex * 16], 16);
- pClay->palList.InsertAt (pClay->palList.GetCount (), pPal);
- }
- if (pMapperClaySecChunk->paletteSel >= 0) {
- pClay->setSelectPalette (pMapperClaySecChunk->paletteSel);
- }
- m_VnpVec.InsertAt (m_VnpVec.GetCount(), pClay);
- }
- // Read map-chain
- auto pMapOffset = (PDWORD) & pBuffer[header->mapChainOffset];
- for (auto it =0; it != header->mapCount; it++) {
- auto mapSpec =
- (CNNEFile::mapSectionChunk *) & pBuffer[pMapOffset[it]];
- auto map = new CMapUnit (m_globalPal);
- READ_COMMENT ( (& pRelocStringPool[mapSpec->commentOffset]), map, *mapSpec)
- map->width = mapSpec->width;
- map->height = mapSpec->height;
- // Read static palette
- auto spalChunkPtr = (CNNEFile::palChunk *) & pBuffer[pMapOffset[it] + sizeof (CNNEFile::mapSectionChunk)];
- for (auto it = 0; it != mapSpec->sPaletteCount; it++) {
- auto p = new CPal (CPal::static_palette);
- auto &src_r = spalChunkPtr[it];
- // copy pal index.
- RtlCopyMemory (p->pal, & pRelocPalettePool[src_r.palIndex << 4], 16);
- READ_COMMENT ( (& pRelocStringPool[src_r.commentOffset]), p, src_r)
- map->staticPal.InsertAt (map->staticPal.GetCount (), p);
- }
- const auto totalAllocpage = mapSpec->height * mapSpec->width;
- auto pPageOffset = (PDWORD)
- & spalChunkPtr[mapSpec->sPaletteCount];
- for (auto it = 0; it != totalAllocpage; it++) {
- auto map_page =
- (CNNEFile::mapSectionPageChunk *) & pBuffer[pPageOffset[it]];
- // Alloc new page..
- auto na_page = new CNametableCell<FALSE> (map->staticPal, m_globalPal, FALSE);
- // Copy nametable
- RtlCopyMemory (na_page->tileSlot, & pRelocNametablePool[map_page->nametableIndex * 0x800], 0x800);
- na_page->chr = NULL;
- na_page->attr = NULL;
- na_page->pal = NULL;
- // Attach chr
- if (map_page->chrIndex != MAXDWORD) {
- ATLASSERT (map_page->chrIndex < m_ChrVec.GetCount ());
- na_page->chr = m_ChrVec[map_page->chrIndex];
- }
- // Copy attr table list
- auto pAttrChunk = (CNNEFile::attrChunk *) & pBuffer[pPageOffset[it]+sizeof (CNNEFile::mapSectionPageChunk)];
- for (auto it = 0; it != map_page->attrCount; it++) {
- auto pMapperChunk = & pAttrChunk[it];
- auto pAttr = new CAttr;
- READ_COMMENT ( (& pRelocStringPool[pMapperChunk->commentOffset]), pAttr, *pMapperChunk)
- // Copy nametable
- RtlCopyMemory (pAttr->attr, & pRelocAttrPool[pMapperChunk->attrIndex * 64], 64);
- // Check select
- if (map_page->attrSel == it) {
- na_page->attr = pAttr;
- }
- na_page->attrList.InsertAt (na_page->attrList.GetCount (), pAttr);
- }
- // Copy pal list
- auto pPalChunk = (CNNEFile::palChunk *) & pAttrChunk[map_page->attrCount];
- for (auto it = 0; it != map_page->paletteCount; it++) {
- auto pMapperChunk = & pPalChunk[it];
- auto pPal = new CPal (CPal::private_palette);
- READ_COMMENT ( (& pRelocStringPool[pMapperChunk->commentOffset]), pPal, *pMapperChunk)
- // Copy nametable
- RtlCopyMemory (pPal->pal, & pRelocPalettePool[pMapperChunk->palIndex * 16], 16);
- na_page->palList.InsertAt ( na_page->palList.GetCount (), pPal);
- }
- na_page->setSelectPalette (map_page->paletteSel);
- map->ntList.InsertAt (map->ntList .GetCount (), na_page);
- }
- m_MapVec.InsertAt ( m_MapVec.GetCount (), map);
- }
- // re-build all item.
- for (auto it = 0; it != m_ChrVec.GetCount (); it++) {
- auto p = m_ChrVec[it];
- m_GuiLV_Chr.InsertItem (it, p->comment.GetLength () > 0 ? p->comment : _T (""), 0);
- m_GuiLV_Chr.SetItemData (it, reinterpret_cast <DWORD_PTR> ( p));
- }
- for (auto it = 0; it != m_VnpVec.GetCount (); it++) {
- auto p = m_VnpVec[it];
- // Set first snapshot cache.
- p->snapshotToUndoStack ();
- appendToItemToViewClayList (p);
- }
- for (auto it = 0; it != m_MapVec.GetCount (); it++) {
- auto p = m_MapVec[it];
- m_GuiLV_Map.InsertItem (it, p->comment.GetLength () > 0 ? p->comment : _T (""), 0);
- m_GuiLV_Map.SetItemData (it, reinterpret_cast <DWORD_PTR> ( p));
- }
- return TRUE;
- }
- EZ_ERRORS_RET ( _T ("crc32 mismatch !\ncorrupted or tampered"));
- }
- EZ_ERRORS_RET ( _T ("Magic header mismatch !"));
- }
- EZ_ERRORS_RET ( _T ("File too short !"));
- return FALSE;
- }
- BOOL writeNNEFile (CString &filepath) {
- CAtlFile win32fd;
- if (FAILED (win32fd.Create (filepath,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- CREATE_ALWAYS)) != FALSE) {
- return FALSE;
- }
- return writeNNEFile (win32fd);
- }
- BOOL writeNNEFile (CAtlFile &win32fd) {
- // NNE File
- CByteStream NNEFile ( 0x20000, 0x200000);
- // Buffer pool
- CByteStream chrPool (0x10000, 0x1000 * 128); // 4K chr block
- CByteStream nametablePool (0x8000, 0x800 * 128); // 2K 32x32 word tile id block
- CByteStream attrPool (0x0400, 0x0040 * 128); // 64 byte attr block
- CByteStream palPool (0x0100, 0x0010 * 128); // 16 byte pal block
- CByteStream stringPool (0x1000, 0x1000 * 32); // Chr buffer
- // NNE file header
- CNNEFile::NNEHeader header;
- RtlCopyMemory (header.magic, "moecmks nes-nne", sizeof (header.magic));
- NNEFile.writeDummyAssert (sizeof (CNNEFile::NNEHeader));
- header.gPaletteCount = m_globalPal.GetCount ();
- header.gPaletteChainOffset = NNEFile.getWriteSeek ();
- // <gloabl-palette-chain section> ===============================================
- for (auto it = 0; it != m_globalPal.GetCount (); it++)
- {
- #define APPEND_COMMENT(/*varDummyStringSpecKey*/ Object, /* CString &*/ comment)\
- do {\
- CString &commentT = comment;\
- if (commentT.GetLength () > 0) {\
- (Object).commentLength = commentT.GetLength ();\
- (Object).commentOffset = stringPool.getWriteSeek ();\
- /* Write chr buffer (UCS-2) */ \
- CStringW ucs2Buffer (commentT);\
- stringPool.writeAssert ((const void *) ucs2Buffer.GetString (), commentT.GetLength () << 1);\
- }\
- } while (0)
- auto p = m_globalPal[it];
- CNNEFile::palChunk chunk = { 0, 0, palPool.getWriteSeek () >> 4 };
- APPEND_COMMENT (chunk, p->comment);
- palPool.writeAssert (& p->pal[0], sizeof (p->pal));
- NNEFile.writeAssert (& chunk, sizeof (chunk));
- }
- header.chrChainOffset = NNEFile.getWriteSeek ();
- header.chrCount = m_ChrVec.GetCount ();
- // <chr-chain> ===============================================
- for (auto it = 0; it != m_ChrVec.GetCount (); it++) {
- CNNEFile::chrSectionChunk chunk = { 0, 0, it };
- auto chr = m_ChrVec[it];
- ATLASSERT (chr != NULL);
- APPEND_COMMENT (chunk, chr->comment);
- chrPool.writeAssert (chr->chr, 0x1000);
- NNEFile.writeAssert (& chunk, sizeof (chunk));
- }
- header.clayChainOffset = NNEFile.getWriteSeek ();
- header.clayCount = m_VnpVec.GetCount ();
- // <clay-chain> ===============================================
- DWORD ClayOffsetInFile = NNEFile.getWriteSeek ();
- // Clay chunk offset header
- NNEFile.writeDummyAssert (m_VnpVec.GetCount () * sizeof (DWORD));
- for (auto it = 0; it != m_VnpVec.GetCount (); it++) {
- // Write clay chunk offset
- DWORD clayChunkOffset = NNEFile.getWriteSeek ();
- NNEFile.fillExistBufferNoreallocAssert (& clayChunkOffset,
- ClayOffsetInFile + (it << 2), sizeof (DWORD));
- // Write clay chunk header
- DWORD chunkHeaderInFile = NNEFile.getWriteSeek ();
- NNEFile.writeDummyAssert (sizeof (CNNEFile::claySectionChunkHeader));
- auto p = m_VnpVec[it];
- CNNEFile::claySectionChunkHeader chunkHeader = {
- 0, /* commentLength */
- 0, /* commentOffset */
- MAXDWORD, /* chrIndex */
- nametablePool.getWriteSeek () >> 11, /* clayIndex */
- p->attrList.GetCount (), /* attrCount */
- p->palList.GetCount (), /* paletteCount */
- MAXDWORD, /* attr select */
- p->select
- };
- if (p->chr != NULL) {
- chunkHeader.chrIndex = forceFindIndexByComment<CChr> (m_ChrVec, & p->chr->comment);
- ATLASSERT (chunkHeader.chrIndex >= 0);
- }
- // Write attr-list
- for (auto it = 0; it != p->attrList.GetCount (); it++) {
- auto p2 = p->attrList[it];
- if ( p->attr != NULL
- && p2->comment == p->attr->comment)
- chunkHeader.attrSel = it;
- CNNEFile::attrChunk chunk = { 0, 0, attrPool.getWriteSeek () >> 6 };
- // Make attr comment
- APPEND_COMMENT (chunk, p2->comment);
- attrPool.writeAssert (p2->attr, 64);
- NNEFile.writeAssert (& chunk, sizeof (chunk));
- }
- // Write pal-list
- CByteStream palChunkSet (32, 64);
- for (auto it = 0; it != p->palList.GetCount (); it++) {
- auto p2 = p->palList[it];
- CNNEFile::palChunk chunk = { 0, 0, palPool.getWriteSeek () >> 4 };
- // Make pal comment
- APPEND_COMMENT (chunk, p2->comment);
- palPool.writeAssert (p2->pal, 16);
- NNEFile.writeAssert (& chunk, sizeof (chunk));
- }
- // Write Comment
- APPEND_COMMENT (chunkHeader, p->comment);
- // Fill header
- NNEFile.fillExistBufferNoreallocAssert (& chunkHeader,
- chunkHeaderInFile, sizeof (chunkHeader));
- // Write nametable tile id
- nametablePool.writeAssert (p->tileSlot, 0x800);
- }
- // <map-chain> ===============================================
- header.mapChainOffset = NNEFile.getWriteSeek ();
- header.mapCount = m_MapVec.GetCount ();
- DWORD MapOffsetInFile = NNEFile.getWriteSeek ();
- NNEFile.writeDummyAssert (m_MapVec.GetCount () * sizeof (DWORD));
- for (auto it = 0; it != m_MapVec.GetCount (); it++) {
- auto p = m_MapVec[it];
- ATLASSERT (p != NULL);
- // Write map-chunk offset
- DWORD mapChunkOffset = NNEFile.getWriteSeek ();
- NNEFile.fillExistBufferNoreallocAssert (& mapChunkOffset,
- MapOffsetInFile + (it << 2), sizeof (DWORD));
- // Prepare map section chunk
- CNNEFile::mapSectionChunk mapSecChunk = {
- 0, /* commentLength */
- 0, /* commentOffset */
- p->width, /* width */
- p->height, /* height */
- p->staticPal.GetCount () /* sPaletteCount */
- };
- // Make map comment
- APPEND_COMMENT (mapSecChunk, p->comment);
- // Write section chunk
- NNEFile.writeAssert (& mapSecChunk, sizeof (CNNEFile::mapSectionChunk));
- // Write static palette
- for (auto it = 0; it != p->staticPal.GetCount (); it++)
- {
- auto p2 = p->staticPal[it];
- CNNEFile::palChunk chunk = { 0, 0, palPool.getWriteSeek () >> 4 };
- APPEND_COMMENT (chunk, p2->comment);
- palPool.writeAssert (& p2->pal[0], sizeof (p2->pal));
- NNEFile.writeAssert (& chunk, sizeof (chunk));
- }
- DWORD PageOffsetInFile = NNEFile.getWriteSeek ();
- NNEFile.writeDummyAssert (p->ntList.GetCount () * sizeof (DWORD));
- for (auto it = 0; it != p->ntList.GetCount (); it++) {
- auto p2 = p->ntList[it];
- // Write page-chunk offset
- DWORD pageChunkOffset = NNEFile.getWriteSeek ();
- NNEFile.fillExistBufferNoreallocAssert (& pageChunkOffset,
- PageOffsetInFile + (it << 2), sizeof (DWORD));
- CNNEFile::mapSectionPageChunk pageChunk = {
- MAXDWORD, /* chrIndex */
- nametablePool.getWriteSeek () >> 11, /* nametableIndex */
- p2->attrList.GetCount (), /* attrCount */
- p2->palList.GetCount (), /* paletteCount */
- MAXDWORD, /* attrSel */
- p2->select /* paletteSel */
- };
- DWORD sectionPageChunkOffset = NNEFile.getWriteSeek ();
- NNEFile.writeDummyAssert (sizeof (CNNEFile::mapSectionPageChunk));
- if (p2->chr != NULL) {
- pageChunk.chrIndex = forceFindIndexByComment<CChr> (m_ChrVec, & p2->chr->comment);
- ATLASSERT (pageChunk.chrIndex >= 0);
- }
- nametablePool.writeAssert (p2->tileSlot, sizeof (p2->tileSlot));
- // Collect attr-list
- for (auto it = 0; it != p2->attrList.GetCount (); it++) {
- auto p3 = p2->attrList[it];
- if ( p2->attr != NULL
- && p3->comment == p2->attr->comment)
- pageChunk.attrSel = it;
- CNNEFile::attrChunk chunk = { 0, 0, attrPool.getWriteSeek () >> 6 };
- // Make attr comment
- APPEND_COMMENT (chunk, p3->comment);
- attrPool.writeAssert (p3->attr, 64);
- NNEFile.writeAssert (& chunk, sizeof (chunk));
- }
- // Write pal-list
- for (auto it = 0; it != p2->palList.GetCount (); it++) {
- auto p3 = p2->palList[it];
- CNNEFile::palChunk chunk = { 0, 0, palPool.getWriteSeek () >> 4 };
- // Make pal comment
- APPEND_COMMENT (chunk, p3->comment);
- palPool.writeAssert (p3->pal, 16);
- NNEFile.writeAssert (& chunk, sizeof (chunk));
- }
- // Write clay-chunk header
- NNEFile.fillExistBufferNoreallocAssert
- (& pageChunk, sectionPageChunkOffset,
- sizeof (CNNEFile::mapSectionPageChunk));
- }
- }
- // Link body and item-pool
- header.chrPoolOffset = NNEFile.getWriteSeek ();
- header.attrPoolOffset = header.chrPoolOffset + chrPool.getWriteSeek ();
- header.palettePoolOffset = header.attrPoolOffset + attrPool.getWriteSeek ();
- header.nclayPoolOffset = header.palettePoolOffset + palPool.getWriteSeek ();
- header.stringPoolOffset = header.nclayPoolOffset + nametablePool.getWriteSeek ();
- NNEFile.writeAssert (* chrPool.getBuffer (), chrPool.getWriteSeek ());
- NNEFile.writeAssert (* attrPool.getBuffer (), attrPool.getWriteSeek ());
- NNEFile.writeAssert (* palPool.getBuffer (), palPool.getWriteSeek ());
- NNEFile.writeAssert (* nametablePool.getBuffer (), nametablePool.getWriteSeek ());
- NNEFile.writeAssert (* stringPool.getBuffer (), stringPool.getWriteSeek ());
- // Calc crc32
- header.crc32_intel = CGlobals::crc32_intel (0,
- &( ( static_cast<PBYTE> ((*NNEFile.getBuffer())))[sizeof (CNNEFile::NNEHeader)])
- , NNEFile.getWriteSeek () - sizeof (CNNEFile::NNEHeader));
- NNEFile.fillExistBufferNoreallocAssert
- (& header, 0,
- sizeof (CNNEFile::NNEHeader));
- // Write file
- return SUCCEEDED ( win32fd.Write (* NNEFile.getBuffer (), NNEFile.getWriteSeek ()));
- }
- LRESULT OnCheck (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
- bHandled = FALSE;
- return 0;
- }
- LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
- {
- const DWORD splitterStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
- const DWORD splitterStyleEx = 0;
- const DWORD listListStyle = WS_VISIBLE | WS_CHILD | LVS_SINGLESEL | LVS_SHOWSELALWAYS
- | LVS_NOCOLUMNHEADER | LVS_LIST | LVS_ALIGNLEFT | WS_BORDER;
- const DWORD listReportStyle = WS_VISIBLE | WS_CHILD | LVS_SINGLESEL | LVS_SHOWSELALWAYS
- | LVS_NOCOLUMNHEADER | LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER;
- m_hWndClient = m_SWinSplitterMain.Create (*this, rcDefault, _T (""), splitterStyle, splitterStyleEx);
- m_SWinSplitterLeft.Create (m_SWinSplitterMain, rcDefault, _T (""), splitterStyle, splitterStyleEx);
- m_SWinSplitterRight.Create (m_SWinSplitterMain, rcDefault, _T (""), splitterStyle, splitterStyleEx);
- m_SWinSplitterList.Create (m_SWinSplitterRight, rcDefault, _T (""), splitterStyle, splitterStyleEx);
- m_GuiSWin_Nesmap.Create (m_SWinSplitterRight, rcDefault);
- m_GuiLV_Map.Create (this, MAP_CONTROL_LV_MAP, m_SWinSplitterLeft, rcDefault, _T (""), listListStyle | LVS_SINGLESEL);
- m_GuiLV_Page.Create (this, MAP_CONTROL_LV_PAGE, m_SWinSplitterLeft, rcDefault, _T (""), listReportStyle & ~LVS_SINGLESEL, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
- m_GuiLV_Page.SetExtendedListViewStyle (LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES /* | LVS_EX_GRIDLINES */ | m_GuiLV_Page.GetExtendedListViewStyle ());
- m_GuiLV_Chr.Create (this, MAP_CONTROL_LV_CHR, m_SWinSplitterList, rcDefault, _T (""), listListStyle | LVS_SINGLESEL);
- m_GuiLV_Clay.Create (this, MAP_CONTROL_LV_CLAY, m_SWinSplitterList, rcDefault, _T (""), listReportStyle & ~LVS_SINGLESEL);
- m_GuiLV_Clay.SetExtendedListViewStyle (LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES /* | LVS_EX_GRIDLINES */ | m_GuiLV_Page.GetExtendedListViewStyle ());
- LVCOLUMN vcl;
- RtlZeroMemory (& vcl, sizeof (vcl));
- vcl.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_IMAGE;
- vcl.cx = 72;
- m_GuiLV_Page.InsertColumn (0, & vcl);
- m_GuiLV_Clay.InsertColumn (0, & vcl);
- vcl.cx = 92;
- m_GuiLV_Page.InsertColumn (1, & vcl);
- m_GuiLV_Clay.InsertColumn (1, & vcl);
- vcl.cx = 92;
- m_GuiLV_Page.InsertColumn (2, & vcl);
- m_GuiLV_Clay.InsertColumn (2, & vcl);
- vcl.cx = 68;
- m_GuiLV_Page.InsertColumn (3, & vcl);
- m_GuiLV_Clay.InsertColumn (3, & vcl);
- m_SWinSplitterMain.SetSplitterPanes (m_SWinSplitterLeft, m_SWinSplitterRight);
- m_SWinSplitterLeft.SetSplitterPanes (m_GuiLV_Map, m_GuiLV_Page);
- m_SWinSplitterRight.SetSplitterPanes (m_SWinSplitterList, m_GuiSWin_Nesmap);
- m_SWinSplitterList.SetSplitterPanes (m_GuiLV_Chr, m_GuiLV_Clay);
- MoveWindow (0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN));
- ShowWindow (SW_MAXIMIZE);
- m_GuiSWin_Nesmap.SetScrollSize (800, 400, FALSE, true);
- m_SWinSplitterMain.SetSplitterPos (160);
- m_SWinSplitterLeft.SetSplitterPos (200);
- m_SWinSplitterRight.SetSplitterPos (200);
- m_SWinSplitterList.SetSplitterPos ((GetSystemMetrics (SM_CXSCREEN) - 160) / 2 + 20);
- CGlobals::setDefaultListViewColor (m_GuiLV_Map);
- CGlobals::setDefaultListViewColor (m_GuiLV_Page);
- CGlobals::setDefaultListViewColor (m_GuiLV_Chr);
- CGlobals::setDefaultListViewColor (m_GuiLV_Clay);
- m_GuiLV_Chr.SetImageList (m_IconChrlist, LVSIL_SMALL);
- m_GuiLV_Clay.SetImageList (m_IconClaylist, LVSIL_SMALL);
- m_GuiLV_Map.SetImageList (m_IconMaplist, LVSIL_SMALL);
- m_GuiLV_Page.SetImageList (m_IconPagelist, LVSIL_SMALL);
- allocNtpWindow ();
- allocClayWindow ();
- CreateSimpleToolBar();
- CreateSimpleStatusBar();
- // TBSTYLE_TOOLTIPS
- // CBRS_TOOLTIPS
- // CReBarCtrlT
- // CDoc
- // nes-map mode | pos infos | chr cache | palette cache | attrtable cache
- int skipBar[] = { 120, 360, 720, 960, -1 };
- :: SendMessage (m_hWndStatusBar, SB_SETPARTS, sizeof (skipBar) / sizeof (skipBar[0]), (LPARAM)& skipBar[0]);
- :: SendMessage (m_hWndStatusBar, SB_SETTEXT, 0, (LPARAM) _T ("map:paste mode"));
- :: SendMessage (m_hWndStatusBar, SB_SETTEXT, 2, (LPARAM) _T ("chr cache:"));
- :: SendMessage (m_hWndStatusBar, SB_SETTEXT, 3, (LPARAM) _T ("pal cache:"));
- :: SendMessage (m_hWndStatusBar, SB_SETTEXT, 4, (LPARAM) _T ("attr cache:"));
- //SetBarStyle
- //CToolBarCtrlT
- // Create directx device
- m_Direct3D9 = Direct3DCreate9 (D3D_SDK_VERSION);
- ATLASSERT (m_Direct3D9 != NULL);
- D3DPRESENT_PARAMETERS d3dpp;
- RtlZeroMemory (& d3dpp, sizeof (d3dpp));
- d3dpp.BackBufferFormat = D3DFMT_X1R5G5B5;
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dpp.hDeviceWindow = m_GuiSWin_Nesmap;
- d3dpp.Windowed = TRUE;
- d3dpp.BackBufferWidth = GetSystemMetrics (SM_CXSCREEN) + 320;
- d3dpp.BackBufferHeight = GetSystemMetrics (SM_CYSCREEN) + 320;
- d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; /* Disable VSync */
- CRect rc;
- GetClientRect (rc);
- auto width = rc.Width ();
- auto height = rc.Height ();
- // Create direct3d device
- HRESULT sig = m_Direct3D9->CreateDevice (0,
- D3DDEVTYPE_HAL,
- d3dpp.hDeviceWindow,
- D3DCREATE_SOFTWARE_VERTEXPROCESSING, & d3dpp, & m_Direct3D9Deivce);
- ATLASSERT (SUCCEEDED (sig));
- // Create direct3d surface (system-memory)
- sig = m_Direct3D9Deivce->CreateOffscreenPlainSurface (d3dpp.BackBufferWidth,
- d3dpp.BackBufferHeight, d3dpp.BackBufferFormat, D3DPOOL_SYSTEMMEM,
- & m_Direct3D9Surface, NULL);
- ATLASSERT (SUCCEEDED (sig));
- // CContainedWindowT
- CGlobals::globalInit ();
- CGlobals::loadFontPixel (m_Direct3D9Deivce);
- // register object for message filtering and idle updates
- CMessageLoop* pLoop = _Module.GetMessageLoop();
- ATLASSERT(pLoop != NULL);
- pLoop->AddMessageFilter(this);
- pLoop->AddIdleHandler(this);
- // Create tracker menu
- auto menuHandle = ::LoadMenu (ModuleHelper::GetResourceInstance (), MAKEINTRESOURCE (IDM_PAGETRACKER));
- m_GuiMenu_MapAttach.Attach (:: GetSubMenu (menuHandle, 0));
- return 0;
- }
- void appendToItemToViewPageList (CNametableCell<FALSE> *p) {
- int index = m_GuiLV_Page.GetItemCount ();
- if (index < 0) {
- index = 0;
- }
- // Insert, set item-0
- ATLASSERT (p != NULL);
- m_GuiLV_Page.InsertItem (index, p->comment, 0);
- resetItemToViewPageList (index, p);
- }
- void resetItemToViewPageList (int index, CNametableCell<FALSE> *p) {
- // Insert, set item-0
- ATLASSERT (p != NULL);
- // Item-0 comment.
- m_GuiLV_Page.SetItem (index, 0, LVIF_IMAGE | LVIF_TEXT, p->comment, 0, 0, 0, 0);
- // Item-1 chr.
- if (p->chr != NULL) {
- m_GuiLV_Page.SetItem (index, 1, LVIF_IMAGE | LVIF_TEXT, p->chr->comment, 1, 0, 0, 0);
- } else {
- m_GuiLV_Page.SetItem (index, 1, LVIF_IMAGE | LVIF_TEXT, _T ("null"), 1, 0, 0, 0);
- }
- // Item-2 palette.
- if (p->pal != NULL) {
- m_GuiLV_Page.SetItem (index, 2, LVIF_IMAGE | LVIF_TEXT, p->pal->comment, 2 + p->pal->source, 0, 0, 0);
- } else {
- m_GuiLV_Page.SetItem (index, 2, LVIF_IMAGE | LVIF_TEXT, _T ("null"), 2, 0, 0, 0);
- }
- // Item-3 attr
- if (p->attr != NULL) {
- m_GuiLV_Page.SetItem (index, 3, LVIF_IMAGE | LVIF_TEXT, p->attr->comment, 5, 0, 0, 0);
- } else {
- m_GuiLV_Page.SetItem (index, 3, LVIF_IMAGE | LVIF_TEXT, _T ("null"), 5, 0, 0, 0);
- }
- m_GuiLV_Page.SetItemDataT (index, p);
- }
- void appendToItemToViewClayList (CNametableCell<TRUE> *p) {
- int index = m_GuiLV_Clay.GetItemCount ();
- if (index < 0) {
- index = 0;
- }
- // Insert, set item-0
- ATLASSERT (p != NULL);
- m_GuiLV_Clay.InsertItem (index, p->comment, 0);
- resetItemToViewClayList (index, p);
- }
- void resetItemToViewClayList (int index, CNametableCell<TRUE> *p) {
- // Insert, set item-0
- ATLASSERT (p != NULL);
- // Item-0 comment.
- m_GuiLV_Clay.SetItem (index, 0, LVIF_IMAGE | LVIF_TEXT, p->comment, 0, 0, 0, 0);
- // Item-1 chr.
- if (p->chr != NULL) {
- m_GuiLV_Clay.SetItem (index, 1, LVIF_IMAGE | LVIF_TEXT, p->chr->comment, 1, 0, 0, 0);
- } else {
- m_GuiLV_Clay.SetItem (index, 1, LVIF_IMAGE | LVIF_TEXT, _T ("null"), 1, 0, 0, 0);
- }
- // Item-2 palette.
- if (p->pal != NULL) {
- m_GuiLV_Clay.SetItem (index, 2, LVIF_IMAGE | LVIF_TEXT, p->pal->comment, 2 + p->pal->source, 0, 0, 0);
- } else {
- m_GuiLV_Clay.SetItem (index, 2, LVIF_IMAGE | LVIF_TEXT, _T ("null"), 2, 0, 0, 0);
- }
- // Item-3 attr
- if (p->attr != NULL) {
- m_GuiLV_Clay.SetItem (index, 3, LVIF_IMAGE | LVIF_TEXT, p->attr->comment, 5, 0, 0, 0);
- } else {
- m_GuiLV_Clay.SetItem (index, 3, LVIF_IMAGE | LVIF_TEXT, _T ("null"), 5, 0, 0, 0);
- }
- m_GuiLV_Clay.SetItemDataT (index, p);
- }
- void __cdecl setStatusText (int bar_bank, LPCTSTR format, ...) {
- CString output;
- va_list va;
- va_start (va, format);
- output.FormatV (format, va);
- ::SendMessage (m_hWndStatusBar, SB_SETTEXT, bar_bank, (LPARAM) output.GetString ());
- va_end (va);
- }
- LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
- {
- m_GuiLV_Chr.RemoveImageList (LVSIL_SMALL);
- m_GuiLV_Clay.RemoveImageList (LVSIL_SMALL);
- m_GuiLV_Map.RemoveImageList (LVSIL_SMALL);
- m_GuiLV_Page.RemoveImageList (LVSIL_SMALL);
- // unregister message filtering and idle updates
- CMessageLoop* pLoop = _Module.GetMessageLoop();
- ATLASSERT(pLoop != NULL);
- pLoop->RemoveMessageFilter(this);
- pLoop->RemoveIdleHandler(this);
- bHandled = FALSE;
- return 1;
- }
- LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
- {
- //CAboutDlg dlg;
- //dlg.DoModal();
- return 0;
- }
- };
- int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT)
- {
- CMessageLoop theLoop;
- _Module.AddMessageLoop(&theLoop);
- CMainFrame wndMain;
- if(wndMain.CreateEx() == NULL)
- {
- ATLTRACE(_T("Main window creation failed!\n"));
- return 0;
- }
- wndMain.SetWindowText (_T ("NNametableEditor"));
- wndMain.ShowWindow(nCmdShow);
- int nRet = theLoop.Run();
- _Module.RemoveMessageLoop();
- return nRet;
- }
- int WINAPI _tWinMain (HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR lpstrCmdLine,
- int nCmdShow)
- {
- HRESULT hRes = ::CoInitialize(NULL);
- // If you are running on NT 4.0 or higher you can use the following call instead to
- // make the EXE CCRTAllocator::Free threaded. This means that calls come in on a random RPC thread.
- // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
- ATLASSERT(SUCCEEDED(hRes));
- // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
- ::DefWindowProc(NULL, 0, 0, 0L);
- AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES); // add flags to support other controls
- hRes = _Module.Init(NULL, hInstance);
- ATLASSERT(SUCCEEDED(hRes));
- int nRet = Run(lpstrCmdLine, nCmdShow);
- _Module.Term();
- ::CoUninitialize();
- return nRet;
- }
- int main (VOID) {
- HINSTANCE hInstance = GetModuleHandle (NULL);
- HINSTANCE hPrevInstance = NULL;
- LPTSTR lpCmdLine = GetCommandLine ();
- int nShowCmd = SW_SHOWNORMAL;
- return _tWinMain (hInstance,
- hPrevInstance,
- lpCmdLine,
- nShowCmd);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement