<TargetST7>
   <Defs>
      <Set Header="Target" Desc="Advanced ST7/STM8 options">
         <Section Header="Internal" Hidden="1">
            <Property Header="AssemblyFilters" Type="PT_STRING" Default="*.asm;*.st7;*.inc"/>
            <Property Header="CFilters" Type="PT_STRING" Default="*.c;*.h"/>
            <Property Header="ListingFilters" Type="PT_STRING" Default="*.lst;*.map"/>
            <Property Header="NodeASM-Ext" Type="PT_STRING" Default="asm;st7"/>
            <Property Header="NodeInc-Ext" Type="PT_STRING" Default="inc"/>
            <Property Header="NodeC-Ext" Type="PT_STRING" Default="c"/>
            <Property Header="NodeH-Ext" Type="PT_STRING" Default="h"/>
            <Property Header="NodeLib-Ext" Type="PT_STRING" Default="lib"/>
            <Property Header="NodeApp-Ext" Type="PT_STRING" Default="aof;hex;s19;bin;cos"/>
            <Property Header="HelpCHM" Type="PT_STRING" Default="ST7/RideST7.CHM"/>
         </Section>
         <Section Header="Tools" Hidden="1">
            <Property Header="Compiler" Type="PT_STRING" Default="RCST7"/>
            <Property Header="Assembler" Type="PT_STRING" Default="MAST7"/>
            <Property Header="Linker" Type="PT_STRING" Default="RLST7"/>
            <Property Header="LibraryManager" Type="PT_STRING" Default="LIBMANST7"/>
            <Property Header="Debugger" Type="PT_STRING" Default="SIM-ST7"/>
            <Property Header="Simulator" Type="PT_STRING" Default="SIM-ST7"/>
            <Property Header="Emulator" Type="PT_STRING" Default="RLINK_ST7"/>
         </Section>
         <Section Header="Directories" Hidden="1">
            <Property Header="IncDir" Type="PT_STRING" Default="$(RkitInc);$(RkitInc)\ST7"/>
            <Property Header="LibDir" Type="PT_STRING" Default="$(RkitLib)\ST7"/>
         </Section>
         <Section Header="ProcessorST7" Desc="Processor" Comment="Defines the ST7/STM8 processor options.">
            <Property Header="Processor" Desc="Device" Type="PT_HF" Pattern="ST7/HFST7.xml" Comment="Selects the appropriate ST7/STM8 derivative.">
            <![CDATA[

/* This global function loads the debug tool to use for ST7 and STM8 devices */
function Update_ST7_Debug_Tool(toolname)
  {
  Project.HideProperty("SIM-ST7","","",1);
  Project.HideProperty("RLINK_ST7","","", 1);
  Project.HideProperty("RLINK_STM8","","", 1);
  Project.HideProperty("Target","DebugST7","DebugTool_STM8", 1);
  Project.HideProperty("Target","DebugST7","DebugTool_ST7", 1);
  
  var processor  = Project.GetPropertyValue("Target", "ProcessorST7", "Processor");
  if (processor == "")
	return;
	
  var type3 = processor.substr(0,3);
  var type4 = processor.substr(0,4);
  
  if(type4 == "STM8")
    {
    if(toolname != "DebugTool_STM8")
      return;
    Project.HideProperty("Target","DebugST7","DebugTool_STM8", 0);
    }
  else
    {
    if(type3 == "ST7")
      {
      if(toolname != "DebugTool_ST7")
        return;
      Project.HideProperty("Target","DebugST7","DebugTool_ST7", 0);
      }
    else
      return;
    }
  
  var isLib = (Project.GetPropertyValue("ApplicationLib", "General", "TargetFamily") != "");
  if (isLib)
    Project.HideProperty("Target","DebugST7", "", 1);
  else
    {
    var tool    = Project.GetPropertyValue("Target", "DebugST7", toolname);

    var cfgfile = "ST7\\"+tool+".config";
    Project.UpdateCurNodeConfig("",cfgfile);
    
    var dbi        = Project.GetSelectedDBI();
    Project.WriteIniValue("Application","DebugTool",tool, dbi);
    Project.WriteIniValue("Debug","ToolName",tool, dbi);
    }
  }
/*end of function Update_ST7_Debug_Tool(toolname) */

               {
               var processor  = Project.GetPropertyValue("Target", "ProcessorST7", "Processor");
               var key        = "ST7Derivatives\\";
               var configpath = Project.ReadRegistryValue(key.concat(processor), "MicroDef");
               var isstm8     = Project.ReadIniValue( "Space", "IsSTM8", configpath );

               Project.SetPropertyValue("Target","ProcessorST7","IsSTM8", isstm8?"-P":"");       // See RLST7.config
               Project.SetPropertyValue("RCST7","Model","Mode", isstm8 ? "stm8" : "st7" );
               Project.SetPropertyValue("MAST7","Set","Mode", isstm8 ? "MODESTM8" : "" );

               var codesize   = Project.ReadIniValue("Space", "CodeSize", configpath);
               Project.SetPropertyValue("Target", "ProcessorST7", "CodeSize", codesize);

               var codestart = Project.ReadIniValue("Space", "CodeStart", configpath);
               Project.SetPropertyValue("Target", "ProcessorST7", "CodeStart", codestart);

               var ramsize    = Project.ReadIniValue("Space", "RamSize", configpath);
               Project.SetPropertyValue("Target", "ProcessorST7", "RamSize", ramsize);

               var stackstart = Project.ReadIniValue("Space", "StackStart", configpath);
               if( ( stackstart < 0x100 ) && !isstm8 )
                  {  // Ultralite0 requires the STACK0 RCST7 directive
                  Project.SetPropertyValue("RCST7", "Model", "Stack", "STACK0");
                  }
               else
                  {
                  Project.SetPropertyValue("RCST7", "Model", "Stack", "");
                  }

               var stacksize  = Project.ReadIniValue("Space", "StackSize", configpath);

               if( stacksize )
                  {
                  Project.SetPropertyValue("RLST7", "More", "StackSize", stacksize);
                  }
               else
                  // If stack size has not been found in the Sim file, set it to a default
                  {
                  if ( ramsize > 128 )
                     Project.SetPropertyValue("RLST7", "More", "StackSize", "64");
                  else
                     Project.SetPropertyValue("RLST7", "More", "StackSize", "32");
                  }

               var ramstart   = Project.ReadIniValue("Space", "RamStart", configpath);
               Project.SetPropertyValue("Target","ProcessorST7", "RamStart", ramstart);

               // Memory mapping is enabled only for test devices
               if( ( processor == "ST72-TEST" ) || ( processor == "STM8-TEST" ) )
                  {
                  Project.EnableProperty("Target","ProcessorST7","CodeSize", 1);
                  Project.EnableProperty("Target","ProcessorST7","CodeStart", 1);
                  Project.EnableProperty("Target","ProcessorST7","RamSize", 1);
                  Project.EnableProperty("Target","ProcessorST7","RamStart", 1);
                  }
               else
                  {
                  Project.EnableProperty("Target","ProcessorST7","CodeSize", 0);
                  Project.EnableProperty("Target","ProcessorST7","CodeStart", 0);
                  Project.EnableProperty("Target","ProcessorST7","RamSize", 0);
                  Project.EnableProperty("Target","ProcessorST7","RamStart", 0);
                  }

               var sciname    = Project.ReadIniValue("SCI", "SCIName",   configpath);
               Project.SetPropertyValue("Target","ProcessorST7","SCIName", sciname);

               var dbi        = Project.GetSelectedDBI();
               if (dbi != "")
                 Project.WriteIniValue("Device","Name",processor, dbi);
                 
               //STM8
               if(isstm8)
                 {
                 // Show STM8 Debug tools
                 Update_ST7_Debug_Tool("DebugTool_STM8");
                 }
               else
                 {
                 // Show ST7 Debug tools
                 Update_ST7_Debug_Tool("DebugTool_ST7");
                 }
               
               }
            ]]>
            </Property>
            <Property Header="IsSTM8" Desc="Is STM8" Type="PT_STRING" Default="" Comment="Indicates whether the derivative is an ST7 or an STM8." Hidden="1"/>
            <Property Header="CodeSize" Desc="Code size" Type="PT_STRING" Default="" Comment="Specifies the available ROM size."/>
            <Property Header="CodeStart" Desc="Code start" Type="PT_STRING" Default="" Comment="Specifies the ROM starting address."/>
            <Property Header="RamSize" Desc="Data size" Type="PT_STRING" Default="" Comment="Specifies the available RAM size."/>
            <Property Header="RamStart" Desc="Data start" Type="PT_STRING" Default="" Comment="Specifies the RAM starting address."/>
            <Property Header="SCIName" Desc="SCI name" Type="PT_STRING" Default="" Comment="[Read-only] Specifies the proper SCI peripheral family for the RCST7 applications using putchar/puts/printf functions." ReadOnly="1"/>
         </Section>
         <Section Header="ToolSetST7" Desc="Build development tools" Comment="Development tools options.">
            <Property Header="BuildToolSetST7" Desc="Build toolset" Type="PT_CHOICE" Default="ST7\\RaisonanceTools.config" Comment="Selects the tools family to be used in your project.">
               <Enum Header="Raisonance tools" Value="ST7\\RaisonanceTools.config"/>
               <![CDATA[
                  {
                  var build   = Project.GetPropertyValue("", "Build", "Exclude");
                  if(build == "")
                     Project.EnableProperty("Target", "ToolSetST7", "BuildToolSetST7", 0);
                  else
                     {
                     var tools   = Project.GetPropertyValue("Target", "ToolSetST7", "BuildToolSetST7");
                     Tools.InitTools("", tools);
                     Project.SetPropertyValue("Target","Tools","Compiler","RCST7");
                     Project.UpdateCurNodeConfig("","ST7\\RCST7.config");
                     Project.SetPropertyValue("Target","Tools","Assembler","MAST7");
                     Project.UpdateCurNodeConfig("","ST7\\MAST7.config");
                     Project.SetPropertyValue("Target","Tools","Linker","RLST7");
                     Project.UpdateCurNodeConfig("","ST7\\RLST7.config");
                     }
                  }
               ]]>
               </Property>
            <Property Header="NotAreloc" Desc="Inverted Areloc" Type="PT_STRING" Hidden="1"/>
            <Property Header="Areloc" Desc="Automatic variables relocation" Type="PT_CHOICE" Default="REM" Comment="Performs an automatic relocation (to data or page0) of each project variable.">
               <Enum Header="Inactive" Value="REM"/>
               <Enum Header="Active" Value=""/>
               <![CDATA[
                  {
                  var areloc = Project.GetPropertyValue("Target", "ToolSetST7", "Areloc");

                  // Clear the autoreloc information and delete the .areloc file if autoreloc mode not activated
                  if (areloc == "REM")
                     {
                      Project.SetPropertyValue("Target", "ToolSetST7", "NotAreloc", "");
                     }
                  else
                     {
                     Project.SetPropertyValue("Target", "ToolSetST7", "NotAreloc", "REM");
                     }
                  }
               ]]>
            </Property>
            <Property Header="OldArelocInfo" Desc="Backup for Relocation information" Type="PT_STRING" Comment="" Hidden="1"/>
            <Property Header="ArelocInfo" Desc="Relocation information to pass on the compiler's command line" Type="PT_STRING" Comment="" Hidden="1">
            <![CDATA[
               {
               var arelocinfo = Project.GetPropertyValue("Target", "ToolSetST7", "ArelocInfo" );

               //to not execute this script at default settings
               if(arelocinfo != "")
                  {
                  // if the areloc is set to inactive, remove its value
                  var areloc = Project.GetPropertyValue("Target", "ToolSetST7", "Areloc");

                  if(areloc == "REM")
                     Project.SavePropertyValue("Target", "ToolSetST7", "ArelocInfo", "");

                  }
               }
            ]]>
         </Property>
         </Section>
         <Section Header="DebugST7" Desc="Debug environment" Comment="Defines debug options.">
            <Property Header="DebugTool_ST7" Desc="Debug tool" Type="PT_CHOICE" Default="SIM-ST7" Comment="Selects the tool to be used for debugging.">
               <Enum Header="ST7 simulator" Value="SIM-ST7"/>
               <Enum Header="RLink ST7" Value="RLINK_ST7"/>
               <![CDATA[
                  {
                  var processor  = Project.GetPropertyValue("Target", "ProcessorST7", "Processor");
                  var key        = "ST7Derivatives\\";
                  var configpath = Project.ReadRegistryValue(key.concat(processor), "MicroDef");
                  var isstm8     = Project.ReadIniValue( "Space", "IsSTM8", configpath );
                  if(isstm8)
                    {
                    // Show STM8 Debug tools
                    Update_ST7_Debug_Tool("DebugTool_STM8");
                    }
                  else
                    {
                    // Show ST7 Debug tools
                    Update_ST7_Debug_Tool("DebugTool_ST7");
                    }
                  }
               ]]>
            </Property>
            <Property Header="DebugTool_STM8" Desc="Debug tool" Type="PT_CHOICE" Default="SIM-ST7" Comment="Selects the tool to be used for debugging.">
               <Enum Header="STM8 simulator" Value="SIM-ST7"/>
               <Enum Header="RLink STM8" Value="RLINK_STM8"/>
               <![CDATA[
                  {
                  var processor  = Project.GetPropertyValue("Target", "ProcessorST7", "Processor");
                  var key        = "ST7Derivatives\\";
                  var configpath = Project.ReadRegistryValue(key.concat(processor), "MicroDef");
                  var isstm8     = Project.ReadIniValue( "Space", "IsSTM8", configpath );
                  if(isstm8)
                    {
                    // Show STM8 Debug tools
                    Update_ST7_Debug_Tool("DebugTool_STM8");
                    }
                  else
                    {
                    // Show ST7 Debug tools
                    Update_ST7_Debug_Tool("DebugTool_ST7");
                    }
                  }
               ]]>
            </Property>
            <Property Header="Format" Desc="Format" Type="PT_CHOICE" Default="AOF" Comment="Selects the appropriate output file format.">
               <Enum Header="AOF" Value="AOF"/>
               <Enum Header="HEX" Value="HEX"/>
               <Enum Header="BIN" Value="BIN"/>
               <![CDATA[
                  {
                  var build   = Project.GetPropertyValue("", "Build", "Exclude");
                  if (build == "")
                     Project.EnableProperty("Target", "DebugST7", "Format", 1);
                  else
                     Project.EnableProperty("Target", "DebugST7", "Format", 0);

                  var tool  = Project.GetPropertyValue("Target", "DebugST7", "Format");
                  var dbi   = Project.GetSelectedDBI();
                  Project.WriteIniValue("Application","Format",tool, dbi);
                  }
               ]]>
               </Property>
            <Property Header="CodeOffset" Desc="Code offset" Type="PT_STRING" Default="0x0" Comment="Loads the code with an offset (for bootloading purposes).">
            <![CDATA[
                  {
                  var tool  = Project.GetPropertyValue("Target","DebugST7","CodeOffset");
                  var dbi   = Project.GetSelectedDBI();
                  Project.WriteIniValue("Application","CodeOffset",tool, dbi);
                  }
               ]]>
               </Property>
            <Property Header="Explore" Desc="Explore code" Type="PT_CHOICE" Default="No" Comment="Specifies whether the whole ROM is disassembled when Debug starts.">
               <Enum Header="Yes" Value="Yes"/>
               <Enum Header="No" Value="No"/>
               <![CDATA[
                  {
                  var explore  = Project.GetPropertyValue("Target", "DebugST7", "Explore");
                  var dbi      = Project.GetSelectedDBI();
                  Project.WriteIniValue("Debug","Explore",explore, dbi);
                  }
               ]]>
               </Property>
            <Property Header="Startup" Desc="Start mode" Type="PT_CHOICE" Default="1" Comment="Defines the initial breakpoint at startup:\n - Processor default reset address\n - main() function\n - specific symbol/address.">
               <Enum Header="Reset address" Value="0"/>
               <Enum Header="main() function entry" Value="1"/>
               <Enum Header="Specific symbol or address" Value="2"/>
               <![CDATA[
                  {
                  var startup  = Project.GetPropertyValue("Target", "DebugST7", "Startup");
                  var dbi      = Project.GetSelectedDBI();
                  Project.WriteIniValue("Debug", "Startup", startup, dbi);
                  if(startup == "2")
                     {
                     var symb = Project.GetPropertyValue("Target", "DebugST7", "StartupSymb");
                     Project.EnableProperty("Target", "DebugST7", "StartupSymb", 1);
                     Project.WriteIniValue("Debug","StartupSymb", symb, dbi);
                     }
                  else
                     Project.EnableProperty("Target", "DebugST7", "StartupSymb", 0);
                  }
               ]]>
               </Property>
            <Property Header="StartupSymb" Desc="Start symbol address" Type="PT_STRING" Default="main" Comment="Enter the initial breakpoint symbol or address." ReadOnly="1">
            <![CDATA[
                  {
                  var dbi    = Project.GetSelectedDBI();
                  var symb = Project.GetPropertyValue("Target", "DebugST7", "StartupSymb");
                  Project.WriteIniValue("Debug","StartupSymb", symb, dbi);
                  }
            ]]>
            </Property>
         </Section>
      </Set>
   </Defs>
</TargetST7>
