@@ -31,9 +31,9 @@ CompilerLabel s_systemLabels[] =
3131 CompilerLabel (" vic.sprite2X" , 0xd004 ), CompilerLabel (" vic.sprite2Y" , 0xd005 ), CompilerLabel (" vic.sprite3X" , 0xd006 ), CompilerLabel (" vic.sprite3Y" , 0xd007 ),
3232 CompilerLabel (" vic.sprite4X" , 0xd008 ), CompilerLabel (" vic.sprite4Y" , 0xd009 ), CompilerLabel (" vic.sprite5X" , 0xd00a ), CompilerLabel (" vic.sprite5Y" , 0xd00b ),
3333 CompilerLabel (" vic.sprite6X" , 0xd00c ), CompilerLabel (" vic.sprite6Y" , 0xd00d ), CompilerLabel (" vic.sprite7X" , 0xd00e ), CompilerLabel (" vic.sprite7Y" , 0xd00f ),
34- CompilerLabel (" vic.spriteXMSB" , 0xd010 ), CompilerLabel (" vic.control1" , 0xd011 ), CompilerLabel (" vic.rasterCounter" , 0xd012 ), CompilerLabel (" vic.lightPenX" , 0xd013 ),
35- CompilerLabel (" vic.lightPenY" , 0xd014 ), CompilerLabel (" vic.spriteEnable" , 0xd015 ), CompilerLabel (" vic.control2" , 0xd016 ), CompilerLabel (" vic.spriteYSize" , 0xd017 ),
36- CompilerLabel (" vic.memoryPointer" , 0xd018 ), CompilerLabel (" vic.interruptRegister " , 0xd019 ), CompilerLabel (" vic.interruptEnable " , 0xd01a ), CompilerLabel (" vic.spritePriority" , 0xd01b ),
34+ CompilerLabel (" vic.spriteXMSB" , 0xd010 ), CompilerLabel (" vic.control1" , gHELP_VIC_CONTROL1 , 0xd011 ), CompilerLabel (" vic.rasterCounter" , 0xd012 ), CompilerLabel (" vic.lightPenX" , 0xd013 ),
35+ CompilerLabel (" vic.lightPenY" , 0xd014 ), CompilerLabel (" vic.spriteEnable" , 0xd015 ), CompilerLabel (" vic.control2" , gHELP_VIC_CONTROL2 , 0xd016 ), CompilerLabel (" vic.spriteYSize" , 0xd017 ),
36+ CompilerLabel (" vic.memoryPointer" , gHELP_VIC_SCRMEM , 0xd018 ), CompilerLabel (" vic.intRegister " , gHELP_VIC_IRQREQ , 0xd019 ), CompilerLabel (" vic.intEnable " , gHELP_VIC_INTENA , 0xd01a ), CompilerLabel (" vic.spritePriority" , 0xd01b ),
3737 CompilerLabel (" vic.spriteMulticolor" , 0xd01c ), CompilerLabel (" vic.spriteXSize" , 0xd01d ), CompilerLabel (" vic.spriteToSpriteCollision" , 0xd01e ), CompilerLabel (" vic.spriteToDataCollision" , 0xd01f ),
3838 CompilerLabel (" vic.borderColor" , 0xd020 ), CompilerLabel (" vic.backgroundColor0" , 0xd021 ), CompilerLabel (" vic.backgroundColor1" , 0xd022 ), CompilerLabel (" vic.backgroundColor2" , 0xd023 ),
3939 CompilerLabel (" vic.backgroundColor3" , 0xd024 ), CompilerLabel (" vic.spriteMulticolor0" , 0xd025 ), CompilerLabel (" vic.spriteMulticolor1" , 0xd026 ), CompilerLabel (" vic.sprite0Color" , 0xd027 ),
@@ -1555,6 +1555,19 @@ bool CompilerSourceInfo::DoesLabelExist(const char* label)
15551555 return false ;
15561556}
15571557
1558+ int CompilerSourceInfo::FindLineByAddress (u32 address)
1559+ {
1560+ for (auto l : m_lines)
1561+ {
1562+ if ((address >= l->memAddr ) && (address < l->memAddr + l->data .size ()))
1563+ {
1564+ return l->lineNmbr ;
1565+ }
1566+ }
1567+ return -1 ;
1568+ }
1569+
1570+
15581571void CompilerSourceInfo::ClearVisuals ()
15591572{
15601573 for (auto l : m_lines)
@@ -1851,6 +1864,68 @@ void Compiler::AddLabelsContaining(CompilerSourceInfo* si, vector<CompilerLabel*
18511864 }
18521865}
18531866
1867+ void Compiler::AddLabelsMatchingValue (CompilerSourceInfo* si, vector<CompilerLabel*>& labels, double value)
1868+ {
1869+ for (int i = 0 ; i < sizeof (s_systemLabels) / sizeof (CompilerLabel); i++)
1870+ {
1871+ auto l = &s_systemLabels[i];
1872+ if (l->m_value == value)
1873+ {
1874+ if (std::find (labels.begin (), labels.end (), l) == labels.end ())
1875+ {
1876+ labels.push_back (l);
1877+ }
1878+ }
1879+ }
1880+
1881+ if (si)
1882+ {
1883+ for (auto l : si->m_labels )
1884+ {
1885+ if (l->m_value == value)
1886+ {
1887+ if (std::find (labels.begin (), labels.end (), l) == labels.end ())
1888+ {
1889+ labels.push_back (l);
1890+ }
1891+ }
1892+ }
1893+ }
1894+ }
1895+
1896+ CompilerLabel* Compiler::FindMatchingLabel (CompilerSourceInfo *si, const string& token)
1897+ {
1898+ for (int i = 0 ; i < sizeof (s_systemLabels) / sizeof (CompilerLabel); i++)
1899+ {
1900+ auto l = &s_systemLabels[i];
1901+ if (StrEqual (l->m_name , token))
1902+ {
1903+ return l;
1904+ }
1905+ }
1906+
1907+ for (auto l : si->m_labels )
1908+ {
1909+ if (StrEqual (l->m_name , token))
1910+ {
1911+ return l;
1912+ }
1913+ }
1914+ return nullptr ;
1915+ }
1916+
1917+ CommandHelp* Compiler::FindMatchingCommand (const string& token)
1918+ {
1919+ CommandHelp* cmd = gHELP_CMD ;
1920+ while (cmd->name )
1921+ {
1922+ if (StrEqual (token, cmd->name ))
1923+ return cmd;
1924+ cmd++;
1925+ }
1926+ return nullptr ;
1927+ }
1928+
18541929void Compiler::AddCommandsContaining (vector<CommandHelp*>& commands, const string& token)
18551930{
18561931 CommandHelp* cmd = gHELP_CMD ;
@@ -1872,60 +1947,148 @@ void Compiler::LogContextualHelp(SourceFile* sf, int line)
18721947{
18731948 auto lw = gApp ->GetLogWindow ();
18741949 auto si = sf->GetLines ()[line];
1875- auto & tokens = si->GetTokens ();
1950+ auto ci = sf->GetCompileInfo ();
1951+ CompilerLineInfo* li = 0 ;
1952+ if (ci && ci->m_lines .size () > line)
1953+ li = ci->m_lines [line];
18761954
1877- int tokenIdx = 0 ;
1878- int colorToggle = 0 ;
1955+ if (li && !li->error )
1956+ {
1957+ lw->ClearLog (LogWindow::LF_InstructionHelp);
1958+ switch (li->type )
1959+ {
1960+ case LT_BasicStartup:
1961+ case LT_GenerateBytes:
1962+ case LT_GenerateWords:
1963+ case LT_DataBytes:
1964+ case LT_DataWords:
1965+ case LT_Include:
1966+ {
1967+ auto cmd = FindMatchingCommand (si->GetTokens ()[0 ]);
1968+ if (cmd)
1969+ {
1970+ lw->LogText (LogWindow::LF_InstructionHelp, cmd->help , -1 , 1 );
1971+ if (cmd->detail1 )
1972+ lw->LogText (LogWindow::LF_InstructionHelp, cmd->detail1 , -1 , 1 );
1973+ if (cmd->detail2 )
1974+ lw->LogText (LogWindow::LF_InstructionHelp, cmd->detail2 , -1 , 1 );
1975+ }
1976+ }
1977+ break ;
1978+
1979+ case LT_Variable:
1980+ case LT_Label:
1981+ {
1982+ auto l = FindMatchingLabel (ci, li->label );
1983+ if (l)
1984+ {
1985+ if (l->m_value >= 0 && abs (fmod (l->m_value , 1.0 )) < 0.0000001 && abs (l->m_value ) < 1000000000 .0f )
1986+ lw->LogText (LogWindow::LF_InstructionHelp, FormatString (" %s : $%x %d" , l->m_name .c_str (), (u32 )l->m_value , (int )(l->m_value )), l->m_lineNmbr , 1 );
1987+ else
1988+ lw->LogText (LogWindow::LF_InstructionHelp, FormatString (" %s : %1.2f" , l->m_name .c_str (), l->m_value ), l->m_lineNmbr , 1 );
1989+ if (l->m_help )
1990+ lw->LogTextArray (LogWindow::LF_InstructionHelp, l->m_help , 1 );
1991+ }
1992+ }
1993+ break ;
18791994
1880- vector<CompilerLabel*> labels;
1881- vector<CommandHelp*> commands;
1995+ case LT_Instruction:
1996+ {
1997+ auto cmd = FindMatchingCommand (s_opcodes[li->opcode ].name );
1998+ if (cmd)
1999+ {
2000+ lw->LogText (LogWindow::LF_InstructionHelp, cmd->help , -1 , 1 );
2001+ if (cmd->detail1 )
2002+ lw->LogText (LogWindow::LF_InstructionHelp, cmd->detail1 , -1 , 1 );
2003+ if (cmd->detail2 )
2004+ lw->LogText (LogWindow::LF_InstructionHelp, cmd->detail2 , -1 , 1 );
2005+ }
18822006
1883- auto cs = sf->GetCompileInfo ();
1884- while (tokenIdx < tokens.size ())
2007+ // find possible labels
2008+ if (gAddressingModeSize [s_opcodes[li->opcode ].addressMode ] > 1 )
2009+ {
2010+ vector<CompilerLabel*> labels;
2011+ double val = (double )li->operand ;
2012+ if (s_opcodes[li->opcode ].addressMode == AM_Relative)
2013+ val = (double )(li->memAddr + li->operand + 2 );
2014+
2015+ AddLabelsMatchingValue (ci, labels, val);
2016+ int colorToggle = 0 ;
2017+ for (auto l : labels)
2018+ {
2019+ if (l->m_value >= 0 && abs (fmod (l->m_value , 1.0 )) < 0.0000001 && abs (l->m_value ) < 1000000000 .0f )
2020+ lw->LogText (LogWindow::LF_InstructionHelp, FormatString (" %s : $%x %d" , l->m_name .c_str (), (u32 )l->m_value , (int )(l->m_value )), l->m_lineNmbr , 1 + colorToggle);
2021+ else
2022+ lw->LogText (LogWindow::LF_InstructionHelp, FormatString (" %s : %1.2f" , l->m_name .c_str (), l->m_value ), l->m_lineNmbr , 1 + colorToggle);
2023+ if (labels.size () == 1 && l->m_help )
2024+ lw->LogTextArray (LogWindow::LF_InstructionHelp, l->m_help , 1 + colorToggle);
2025+
2026+ colorToggle = 1 - colorToggle;
2027+ }
2028+ }
2029+ }
2030+ break ;
2031+ }
2032+ }
2033+ else
18852034 {
1886- auto & token = tokens[tokenIdx++];
1887- if (token.empty () || token[0 ] == ' ' || token[0 ] == ' \t ' )
1888- continue ;
2035+ auto & tokens = si->GetTokens ();
2036+
2037+ int tokenIdx = 0 ;
2038+ int colorToggle = 0 ;
18892039
1890- if (token == " $" || token == " %" )
2040+ vector<CompilerLabel*> labels;
2041+ vector<CommandHelp*> commands;
2042+
2043+ auto cs = sf->GetCompileInfo ();
2044+ while (tokenIdx < tokens.size ())
18912045 {
1892- tokenIdx++;
1893- continue ;
1894- }
2046+ auto & token = tokens[ tokenIdx++] ;
2047+ if (token. empty () || token[ 0 ] == ' ' || token[ 0 ] == ' \t ' )
2048+ continue ;
18952049
1896- if (token[0 ] >= ' 0' && token[0 ] <= ' 9' )
1897- continue ;
2050+ if (token == " $" || token == " %" )
2051+ {
2052+ tokenIdx++;
2053+ continue ;
2054+ }
18982055
1899- AddLabelsContaining (cs, labels, token);
1900- AddCommandsContaining (commands, token) ;
1901- }
1902-
1903- lw-> ClearLog (LogWindow::LF_InstructionHelp );
1904- if (!labels. empty ())
1905- {
1906- lw->LogText (LogWindow::LF_InstructionHelp, " Suggested Labels: " );
1907- for ( auto l : labels)
2056+ if (token[ 0 ] >= ' 0 ' && token[ 0 ] <= ' 9 ' )
2057+ continue ;
2058+
2059+ AddLabelsContaining (cs, labels, token);
2060+ AddCommandsContaining (commands, token );
2061+ }
2062+
2063+ lw->ClearLog (LogWindow::LF_InstructionHelp);
2064+ if (! labels. empty () )
19082065 {
1909- if (l->m_value >= 0 && abs (fmod (l->m_value , 1.0 )) < 0.0000001 && abs (l->m_value ) < 1000000000 .0f )
1910- lw->LogText (LogWindow::LF_InstructionHelp, FormatString (" %s : $%x %d" , l->m_name .c_str (), (u32 )l->m_value , (int )(l->m_value )), l->m_lineNmbr , 1 + colorToggle);
1911- else
1912- lw->LogText (LogWindow::LF_InstructionHelp, FormatString (" %s : %1.2f" , l->m_name .c_str (), l->m_value ), l->m_lineNmbr , 1 + colorToggle);
2066+ lw->LogText (LogWindow::LF_InstructionHelp, " Suggested Labels:" );
2067+ for (auto l : labels)
2068+ {
2069+ if (l->m_value >= 0 && abs (fmod (l->m_value , 1.0 )) < 0.0000001 && abs (l->m_value ) < 1000000000 .0f )
2070+ lw->LogText (LogWindow::LF_InstructionHelp, FormatString (" %s : $%x %d" , l->m_name .c_str (), (u32 )l->m_value , (int )(l->m_value )), l->m_lineNmbr , 1 + colorToggle);
2071+ else
2072+ lw->LogText (LogWindow::LF_InstructionHelp, FormatString (" %s : %1.2f" , l->m_name .c_str (), l->m_value ), l->m_lineNmbr , 1 + colorToggle);
2073+ if (labels.size () == 1 && l->m_help )
2074+ lw->LogTextArray (LogWindow::LF_InstructionHelp, l->m_help , 1 + colorToggle);
19132075
1914- colorToggle = 1 - colorToggle;
2076+ colorToggle = 1 - colorToggle;
2077+ }
19152078 }
1916- }
1917- if (!commands.empty ())
1918- {
1919- lw->LogText (LogWindow::LF_InstructionHelp, " Suggested Commands:" );
1920- colorToggle = 0 ;
1921- for (auto c : commands)
2079+ if (!commands.empty ())
19222080 {
1923- lw->LogText (LogWindow::LF_InstructionHelp, c->help , -1 , 1 + colorToggle);
1924- if (c->detail1 )
1925- lw->LogText (LogWindow::LF_InstructionHelp, c->detail1 , -1 , 1 + colorToggle);
1926- if (c->detail2 )
1927- lw->LogText (LogWindow::LF_InstructionHelp, c->detail2 , -1 , 1 + colorToggle);
1928- colorToggle = 1 - colorToggle;
2081+ lw->LogText (LogWindow::LF_InstructionHelp, " Suggested Commands:" );
2082+ colorToggle = 0 ;
2083+ for (auto c : commands)
2084+ {
2085+ lw->LogText (LogWindow::LF_InstructionHelp, c->help , -1 , 1 + colorToggle);
2086+ if (c->detail1 )
2087+ lw->LogText (LogWindow::LF_InstructionHelp, c->detail1 , -1 , 1 + colorToggle);
2088+ if (c->detail2 )
2089+ lw->LogText (LogWindow::LF_InstructionHelp, c->detail2 , -1 , 1 + colorToggle);
2090+ colorToggle = 1 - colorToggle;
2091+ }
19292092 }
19302093 }
19312094}
0 commit comments