private GR.Memory.ByteBuffer TestCompile(string Source, string BASICDialectName, ushort StartAddress) { var parser = CreateParser(BASICDialectName); RetroDevStudio.Parser.CompileConfig config = new RetroDevStudio.Parser.CompileConfig(); config.OutputFile = "test.prg"; config.TargetType = RetroDevStudio.Types.CompileTargetType.PRG; config.StartAddress = StartAddress; bool parseResult = parser.Parse(Source, null, config, null); if (!parseResult) { Debug.Log("Testassemble failed:"); foreach (var msg in parser.Messages.Values) { Debug.Log(msg.Message); } } Assert.IsTrue(parser.Assemble(config)); return(parser.AssembledOutput.Assembly); }
public void TestEncodeToLabelsNoStripSpaces() { string source = @"10 PRINT ""HALLO"" 20 GOTO 10"; var parser = CreateParser("BASIC V2"); parser.Settings.StripSpaces = false; RetroDevStudio.Parser.CompileConfig config = new RetroDevStudio.Parser.CompileConfig(); config.OutputFile = "test.prg"; config.TargetType = RetroDevStudio.Types.CompileTargetType.PRG; config.Assembler = RetroDevStudio.Types.AssemblerType.C64_STUDIO; Assert.IsTrue(parser.Parse(source, null, config, null)); string encoded = parser.EncodeToLabels(); Assert.AreEqual(@" LABEL10 PRINT ""HALLO"" GOTO LABEL10 ", encoded); }
public void TestRenumberWithStatementAfterGotoGosub() { string source = @"10 ONXGOSUB100,400,700:GOTO2000 100PRINTA 400 PRINTB 700 PRINTC 2000 PRINTD"; var parser = CreateParser("BASIC V2"); RetroDevStudio.Parser.CompileConfig config = new RetroDevStudio.Parser.CompileConfig(); config.OutputFile = "test.prg"; config.TargetType = RetroDevStudio.Types.CompileTargetType.PRG; config.Assembler = RetroDevStudio.Types.AssemblerType.C64_STUDIO; Assert.IsTrue(parser.Parse(source, null, config, null)); string result = parser.Renumber(10, 3, 0, 64000); Assert.AreEqual(@"10 ONXGOSUB13,16,19:GOTO22 13PRINTA 16 PRINTB 19 PRINTC 22 PRINTD", result); }
protected override bool ProcessTask() { if ((m_Document.Type != ProjectElement.ElementType.ASM_SOURCE) && (m_Document.Type != ProjectElement.ElementType.BASIC_SOURCE)) { return(true); } if (m_Document.Type == ProjectElement.ElementType.ASM_SOURCE) { Parser.ASMFileParser parser = new Parser.ASMFileParser(); var compileConfig = new RetroDevStudio.Parser.CompileConfig(); if (m_Document.Element != null) { compileConfig.Assembler = m_Document.Element.AssemblerType; } string sourceCode = ""; if (m_Document.BaseDoc != null) { sourceCode = ((SourceASMEx)m_Document.BaseDoc).editSource.Text; } parser.ParseFile(m_Document.FullPath, sourceCode, m_Configuration, compileConfig, null); if ((compileConfig.Assembler != RetroDevStudio.Types.AssemblerType.AUTO) && (m_Document.BaseDoc != null) && (m_Document.Element != null)) { if (m_Document.Element.AssemblerType != compileConfig.Assembler) { m_Document.Element.AssemblerType = compileConfig.Assembler; m_Document.BaseDoc.SetModified(); } } if (m_Document.BaseDoc != null) { ((SourceASMEx)m_Document.BaseDoc).SetLineInfos(parser.ASMFileInfo); } var knownTokens = parser.KnownTokens(); GR.Collections.MultiMap <string, SymbolInfo> knownTokenInfos = parser.KnownTokenInfo(); m_Document.SetASMFileInfo(parser.ASMFileInfo, knownTokens, knownTokenInfos); } else if (m_Document.Type == ProjectElement.ElementType.BASIC_SOURCE) { Parser.ParserBase parser = Core.DetermineParser(m_Document); ((Parser.BasicFileParser)parser).SetBasicDialect(((Parser.BasicFileParser)parser).Settings.BASICDialect); if (m_Document.BaseDoc != null) { ((Parser.BasicFileParser)parser).Settings.UpperCaseMode = !((SourceBasicEx)m_Document.BaseDoc).m_LowerCaseMode; } var compileConfig = new RetroDevStudio.Parser.CompileConfig(); if (m_Document.Element != null) { compileConfig.Assembler = m_Document.Element.AssemblerType; } string sourceCode = ""; if (m_Document.BaseDoc != null) { sourceCode = ((SourceBasicEx)m_Document.BaseDoc).editSource.Text; } parser.ParseFile(m_Document.FullPath, sourceCode, m_Configuration, compileConfig, null); } var task = new Tasks.TaskUpdateKeywords(m_Document.BaseDoc); task.Core = Core; task.RunTask(); return(true); }
public void TestNoVirtualSectionAt840() { string source = @"!to ""lady-bug.prg"",cbm *=$0801 : !BASIC ; Basiczeile erzeugen BLOCK = 33 ; Spriteblock -> Block*64 = Spritedaten MATRIX = $0400 ; Bildschirmspeicher POINTER_0 = MATRIX+$03F8 ; Spritepointer SEI ; IRQ sperren LDA #$B0 ; X-Koordinate STA $D000 ; Sprite 0 LDA #$81 ; Y-Koordinate STA $D001 ; Sprite 0 LDA #BLOCK ; Spriteblock STA POINTER_0 ; Spritepointer 0 LDA #%00000001 ; Sprite Nr. 0 STA $D015 ; Sprite-DMA Register - JMP - ; Warten !FILL $19,$EA ; Code bis $083E bis 083F = Kein Sprite *=BLOCK*64 ; Adresse der Spritedaten -> Ballon !BYTE %00000011,%11111000,%00000000 !BYTE %00001111,%11111110,%00000000 !BYTE %00011111,%11111111,%00000000 !BYTE %00011111,%00111111,%00000000 !BYTE %00111110,%11001111,%10000000 !BYTE %00111110,%11111111,%10000000 !BYTE %00111110,%11001111,%10000000 !BYTE %00011111,%00111111,%00000000 !BYTE %00011111,%11111111,%00000000 !BYTE %00011111,%11111111,%00000000 !BYTE %00010111,%11111101,%00000000 !BYTE %00001011,%11111010,%00000000 !BYTE %00001001,%11110010,%00000000 !BYTE %00000100,%11100100,%00000000 !BYTE %00000100,%11100100,%00000000 !BYTE %00000010,%01001000,%00000000 !BYTE %00000010,%01001000,%00000000 !BYTE %00000001,%11110000,%00000000 !BYTE %00000001,%11110000,%00000000 !BYTE %00000001,%11110000,%00000000 !BYTE %00000000,%11100000,%00000000 !BYTE $00"; RetroDevStudio.Parser.ASMFileParser parser = new RetroDevStudio.Parser.ASMFileParser(); parser.SetAssemblerType(RetroDevStudio.Types.AssemblerType.C64_STUDIO); RetroDevStudio.Parser.CompileConfig config = new RetroDevStudio.Parser.CompileConfig(); config.OutputFile = "test.prg"; config.Assembler = RetroDevStudio.Types.AssemblerType.C64_STUDIO; Assert.IsTrue(parser.Parse(source, null, config, null)); Assert.IsTrue(parser.Assemble(config)); var assembly = parser.AssembledOutput; Assert.AreEqual("01080B080A009E3230363100000078A9B08D00D0A9818D01D0A9218DF807A9018D15D04C2208EAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEA000003F8000FFE001FFF001F3F003ECF803EFF803ECF801F3F001FFF001FFF0017FD000BFA0009F20004E40004E40002480002480001F00001F00001F00000E00000", assembly.Assembly.ToString()); }
public RetroDevStudio.Parser.CompileConfig CheckParams(string[] Args, out string AdditionalDefines, out bool ShowNoWarnings, out List <string> WarningsToIgnore) { RetroDevStudio.Parser.CompileConfig config = null; AdditionalDefines = null; ShowNoWarnings = false; WarningsToIgnore = new List <string>(); if (Args.Length == 0) { WriteHelp(); return(config); } if (!_Args.CheckParameters(Args)) { WriteHelp(); return(config); } if ((_Args.IsParameterSet("V")) || (_Args.IsParameterSet("-VERSION"))) { Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Console.WriteLine($"C64Ass Assembler V{version}"); return(null); } // last arg is filename? if (_Args.UnknownArgumentCount() < 1) { // last arg should be file name! WriteHelp(); return(config); } config = new RetroDevStudio.Parser.CompileConfig(); config.InputFile = _Args.UnknownArgument(_Args.UnknownArgumentCount() - 1); if (_Args.IsParameterSet("O")) { config.OutputFile = _Args.Parameter("O"); } if (_Args.IsParameterSet("OUTFILE")) { config.OutputFile = _Args.Parameter("OUTFILE"); } if (_Args.IsParameterSet("L")) { config.LabelDumpFile = _Args.Parameter("L"); } if (_Args.IsParameterSet("-LABELDUMP")) { config.LabelDumpFile = _Args.Parameter("LABELDUMP"); } if (_Args.IsParameterSet("LIB")) { config.LibraryFiles = _Args.Parameter("LIB").Split(',').ToList(); } if (_Args.IsParameterSet("LIBRARY")) { config.LibraryFiles = _Args.Parameter("LIBRARY").Split(',').ToList(); } if (_Args.IsParameterSet("N")) { ShowNoWarnings = true; } if (_Args.IsParameterSet("-NOWARNINGS")) { ShowNoWarnings = true; } if (_Args.IsParameterSet("I")) { ParseWarnings(WarningsToIgnore, _Args.Parameter("I")); } if (_Args.IsParameterSet("-IGNORE")) { ParseWarnings(WarningsToIgnore, _Args.Parameter("-IGNORE")); } config.AutoTruncateLiteralValues = _Args.IsParameterSet("-AUTOTRUNCATELITERALS"); for (int i = 0; i < _Args.UnknownArgumentCount() - 1; ++i) { var curArg = _Args.UnknownArgument(i).ToUpper(); if ((curArg == "-D") || (curArg == "--DEFINE")) { if (i + 1 >= _Args.UnknownArgumentCount() - 1) { // no argument for define WriteHelp(); return(null); } AdditionalDefines += _Args.UnknownArgument(i + 1) + "\r\n"; ++i; } else { Console.WriteLine("Unsupported argument: " + _Args.UnknownArgument(i)); WriteHelp(); return(null); } } if ((_Args.IsParameterSet("F")) || (_Args.IsParameterSet("-FORMAT"))) { string outputFormat = _Args.IsParameterSet("F") ? _Args.Parameter("F") : _Args.Parameter("-FORMAT"); if (string.Compare(outputFormat, "PLAIN", true) == 0) { config.TargetType = RetroDevStudio.Types.CompileTargetType.PLAIN; } else if (string.Compare(outputFormat, "CBM", true) == 0) { config.TargetType = RetroDevStudio.Types.CompileTargetType.PRG; } else if (string.Compare(outputFormat, "D64", true) == 0) { config.TargetType = RetroDevStudio.Types.CompileTargetType.D64; } } if (_Args.IsParameterSet("-SETPC")) { int startPC = GR.Convert.ToI32(_Args.Parameter("-SETPC")); if ((startPC >= 0) && (startPC < 65536)) { config.StartAddress = startPC; } } return(config); }
public void TestC64StudioPseudoOpMacroAndSourceInfo1() { string source = @" !to ""macro_macro.prg"",cbm ;* = $1000 ;MACRO_START !macro fill5bytes v1,v2,v3,v4,v5 lda #v1 sta 1024 lda #v2 sta 1025 lda #v3 sta 1026 lda #v4 sta 1027 lda #v5 sta 1028 !end ;MACRO_END ;!if ( MACRO_START != MACRO_END ) { ;!error Macro has size! ;} * = $2000 lda #$01 sta 53281 CALLEDLED_MACRO +fill5bytes 10,20,30,40,50 CALLEDLED_MACRO_END inc 53280 +fill5bytes 1,2,3,4,5 rts"; RetroDevStudio.Parser.ASMFileParser parser = new RetroDevStudio.Parser.ASMFileParser(); parser.SetAssemblerType(RetroDevStudio.Types.AssemblerType.C64_STUDIO); RetroDevStudio.Parser.CompileConfig config = new RetroDevStudio.Parser.CompileConfig(); config.OutputFile = "test.prg"; config.TargetType = RetroDevStudio.Types.CompileTargetType.PRG; config.Assembler = RetroDevStudio.Types.AssemblerType.C64_STUDIO; Assert.IsTrue(parser.Parse(source, null, config, null)); Assert.IsTrue(parser.Assemble(config)); var assembly = parser.AssembledOutput; string file; int lineIndex; parser.ASMFileInfo.DocumentAndLineFromAddress(0x2000, out file, out lineIndex); Assert.IsTrue(parser.ASMFileInfo.Labels.ContainsKey("CALLEDLED_MACRO")); Assert.IsTrue(parser.ASMFileInfo.Labels.ContainsKey("CALLEDLED_MACRO_END")); Assert.AreEqual(28, lineIndex); var label = parser.ASMFileInfo.Labels["CALLEDLED_MACRO"]; var label2 = parser.ASMFileInfo.Labels["CALLEDLED_MACRO_END"]; Assert.AreEqual(30, label.LocalLineIndex); Assert.AreEqual(32, label2.LocalLineIndex); Assert.AreEqual(0x2005, label.AddressOrValue); Assert.AreEqual(0x201e, label2.AddressOrValue); var tokenInfo = parser.ASMFileInfo.TokenInfoFromName("CALLEDLED_MACRO", "", ""); Assert.IsNotNull(tokenInfo); Assert.AreEqual(30, tokenInfo.LocalLineIndex); tokenInfo = parser.ASMFileInfo.TokenInfoFromName("CALLEDLED_MACRO_END", "", ""); Assert.IsNotNull(tokenInfo); Assert.AreEqual(32, tokenInfo.LocalLineIndex); }