Skip to content

Commit

Permalink
[#40] Track Map: General improvements and bugfixes (Part 3: "God mode…
Browse files Browse the repository at this point in the history
…" to manually make sectors non-readable for debugging purposes)
  • Loading branch information
tomas-nestorovic committed Feb 15, 2020
1 parent a97704a commit 97cb021
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
75 changes: 51 additions & 24 deletions Main/src/ViewTrackMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ON_WM_CREATE()
ON_WM_VSCROLL()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_DESTROY()
ON_MESSAGE(WM_TRACK_SCANNED,__drawTrack__)
ON_COMMAND_RANGE(ID_TRACKMAP_STATUS,ID_TRACKMAP_BAD_DATA,__changeDisplayType__)
Expand Down Expand Up @@ -309,47 +310,73 @@
return 0;
}

afx_msg void CTrackMapView::OnMouseMove(UINT nFlags,CPoint point){
// cursor moved over this view
bool CTrackMapView::__getPhysicalAddressFromPoint__(POINT point,TPhysicalAddress &rOutChs,BYTE &rnOutSectorsToSkip){
// True <=> given actual scroll position, the Point falls into a Sector, otherwise False
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
point.y-=TRACK0_Y;
const PCImage image=IMAGE;
if (point.y>=0 && point.y<image->GetTrackCount()*TRACK_HEIGHT){
if (point.y>=0 && point.y<IMAGE->GetTrackCount()*TRACK_HEIGHT){
// cursor over a Track
const TTrack track=point.y/TRACK_HEIGHT;
const THead nSides=__getNumberOfFormattedSidesInImage__(image);
const THead nSides=__getNumberOfFormattedSidesInImage__(IMAGE);
point.x-=SECTOR1_X;
const div_t d=div((int)track,nSides);
TSectorId bufferId[(TSector)-1],*pId=bufferId;
WORD bufferLength[(TSector)-1],*pLength=bufferLength;
TSector nSectors=image->ScanTrack( d.quot, d.rem, bufferId, bufferLength );
CDos::TSectorStatus statuses[(TSector)-1],*pStatus=statuses;
DOS->GetSectorStatuses( d.quot, d.rem, nSectors, bufferId, statuses );
for( int xL=0,xR=0; nSectors--; pStatus++,pId++ ){
TSector nSectors=IMAGE->ScanTrack( d.quot, d.rem, bufferId, bufferLength );
for( int xL=0,xR=0; nSectors--; pId++ ){
xR+=*pLength++>>zoomLengthFactor;
if (point.x>=xL && point.x<=xR){
// cursor over a Sector
TCHAR buf[40];
::wsprintf(buf,_T("Tr%d, %s: "),track,(LPCTSTR)pId->ToString());
switch (*pStatus){
case CDos::TSectorStatus::SYSTEM : ::lstrcat(buf,_T("System")); break;
case CDos::TSectorStatus::UNAVAILABLE: ::lstrcat(buf,_T("Unavailable")); break;
case CDos::TSectorStatus::SKIPPED : ::lstrcat(buf,_T("Skipped")); break;
case CDos::TSectorStatus::BAD : ::lstrcat(buf,_T("Bad")); break;
case CDos::TSectorStatus::OCCUPIED : ::lstrcat(buf,_T("Occupied")); break;
case CDos::TSectorStatus::RESERVED : ::lstrcat(buf,_T("Reserved")); break;
case CDos::TSectorStatus::EMPTY : ::lstrcat(buf,_T("Empty")); break;
default : ::lstrcat(buf,_T("Unknown")); break;
}
CMainWindow::__setStatusBarText__(buf);
return;
rOutChs.cylinder=d.quot, rOutChs.head=d.rem;
rOutChs.sectorId=*pId;
rnOutSectorsToSkip=pId-bufferId;
return true;
}
xL=xR+=SECTOR_MARGIN;
}
}
__updateStatusBarIfCursorOutsideAnySector__();
return false;
}

afx_msg void CTrackMapView::OnMouseMove(UINT nFlags,CPoint point){
// cursor moved over this view
TPhysicalAddress chs; BYTE nSectorsToSkip;
if (__getPhysicalAddressFromPoint__(point,chs,nSectorsToSkip)){
// cursor over a Sector
TCHAR buf[40];
::wsprintf( buf, _T("Tr%d, %s: "), chs.GetTrackNumber(__getNumberOfFormattedSidesInImage__(IMAGE)), (LPCTSTR)chs.sectorId.ToString() );
CDos::TSectorStatus status;
DOS->GetSectorStatuses( chs.cylinder, chs.head, 1, &chs.sectorId, &status );
switch (status){
case CDos::TSectorStatus::SYSTEM : ::lstrcat(buf,_T("System")); break;
case CDos::TSectorStatus::UNAVAILABLE: ::lstrcat(buf,_T("Unavailable")); break;
case CDos::TSectorStatus::SKIPPED : ::lstrcat(buf,_T("Skipped")); break;
case CDos::TSectorStatus::BAD : ::lstrcat(buf,_T("Bad")); break;
case CDos::TSectorStatus::OCCUPIED : ::lstrcat(buf,_T("Occupied")); break;
case CDos::TSectorStatus::RESERVED : ::lstrcat(buf,_T("Reserved")); break;
case CDos::TSectorStatus::EMPTY : ::lstrcat(buf,_T("Empty")); break;
default : ::lstrcat(buf,_T("Unknown")); break;
}
CMainWindow::__setStatusBarText__(buf);
}else
__updateStatusBarIfCursorOutsideAnySector__();
}

afx_msg void CTrackMapView::OnLButtonUp(UINT nFlags,CPoint point){
// left mouse button released
if (app.IsInGodMode() && !IMAGE->IsWriteProtected()){
TPhysicalAddress chs; BYTE nSectorsToSkip;
if (__getPhysicalAddressFromPoint__(point,chs,nSectorsToSkip))
// cursor over a Sector
if (Utils::QuestionYesNo(_T("Make this sector unreadable?"),MB_DEFBUTTON1)){
WORD w;
IMAGE->GetSectorData( chs, nSectorsToSkip, false, &w, &TFdcStatus() );
IMAGE->MarkSectorAsDirty( chs, nSectorsToSkip, &TFdcStatus::SectorNotFound );
Invalidate();
}
}
}

afx_msg void CTrackMapView::OnDestroy(){
Expand Down
2 changes: 2 additions & 0 deletions Main/src/ViewTrackMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
void OnPrepareDC(CDC *pDC,CPrintInfo *pInfo=nullptr) override;
void OnDraw(CDC *pDC) override;
void PostNcDestroy() override;
bool __getPhysicalAddressFromPoint__(POINT point,TPhysicalAddress &rOutChs,BYTE &rnOutSectorsToSkip);
void __updateStatusBarIfCursorOutsideAnySector__() const;
afx_msg int OnCreate(LPCREATESTRUCT lpcs);
afx_msg void OnMouseMove(UINT nFlags,CPoint point);
afx_msg void OnLButtonUp(UINT nFlags,CPoint point);
afx_msg void OnDestroy();
afx_msg LRESULT __drawTrack__(WPARAM wParam,LPARAM lParam);
afx_msg void __changeDisplayType__(UINT id);
Expand Down
7 changes: 6 additions & 1 deletion Main/src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

BOOL CRideApp::InitInstance(){
// application initialization
if (!CWinApp::InitInstance())
if (!__super::InitInstance())
return FALSE;
// - creating/allocating resources
//nop
Expand Down Expand Up @@ -203,6 +203,7 @@
app.WriteProfileInt( INI_GENERAL, INI_CRASHED, nAppsRunning ); // assumption (the app has crashed)
#endif
// - parsing the command line
godMode=!::lstrcmpi( __targv[__argc-1], _T("--godmode") );
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (cmdInfo.m_nShellCommand==CCommandLineInfo::FileNew) // instead of displaying the "New image" dialog ...
Expand All @@ -227,6 +228,10 @@
return CWinApp::ExitInstance();
}

bool CRideApp::IsInGodMode() const{
// True <=> the application has been launched with the "--godmode" parameter, otherwise False
return godMode;
}

afx_msg void CRideApp::__createNewImage__(){
// initiates creation of new Image
Expand Down
3 changes: 3 additions & 0 deletions Main/src/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

class CRideApp sealed:public CWinApp{
DECLARE_MESSAGE_MAP()
private:
bool godMode;
public:
class CRecentFileListEx sealed:public CRecentFileList{
CDos::PCProperties openWith[ID_FILE_MRU_LAST+1-ID_FILE_MRU_FIRST];
Expand All @@ -27,6 +29,7 @@
CDocument *OpenDocumentFile(LPCTSTR lpszFileName) override;
void OnFileOpen(); // public wrapper
CRecentFileListEx *GetRecentFileList() const;
bool IsInGodMode() const;
#if _MFC_VER>=0x0A00
afx_msg void OnOpenRecentFile(UINT nID);
#else
Expand Down

0 comments on commit 97cb021

Please sign in to comment.