// ******************************************************************************************************************** // AnyASM Sample - The assembled version of "Display Text File.AnyScript" // Opens the "Test.txt" file and outputs it to the screen // Created: 2007-02-15 // Last Modified: 2007-04-07 // by Mark Ormston Region Code //ProcInt Main() { Function Main() Format C, Returns ProcInt; VarLocal String @@LocalTempString; //UProcInt filepnt; VarLocal UProcInt @filepnt; //String currentline; VarLocal String @currentline; // Check if the file exists //If (!System.FileExists("Test.txt")) { RegisterLocal ProcInt RegA; // Allocate a local register named RegA Call System.FileExists@StringMem(&@@Const_String0), RegA; Test RegA; ClearRegisters RegA; // Let the assembler know that we no longer need RegA JumpIf True, @@Label_Main_0; //Print("Unable to locate the Test.txt file."); Call Base.Print@StringMem(&@@Const_String1); //Return 0; Return 0; //} @@Label_Main_0: // Attempt to open the file //If (!(filepnt = System.FileOpen("Test.txt", SYSTEM_FILEOPEN_READ))) { RegisterLocal ProcInt RegA; // Allocate a local register named RegA Call System.FileOpen@StringMem(&@@Const_String0, SYSTEM_FILEOPEN_READ), RegA; Move @filepnt, RegA; Test RegA; ClearRegisters RegA; // Let the assembler know that we no longer need RegA JumpIf True, @@Label_Main_1; //Print("Unable to open the Test.txt file."); Call Base.Print@StringMem(&@@Const_String2); //Return 0; Return 0; //} @@Label_Main_1: // Read through the file and output the data //While (!System.FileEOF(filepnt)) { @@Label_Main_2: RegisterLocal ProcInt RegA; // Allocate a local register named RegA Call System.FileEOF(@filepnt), RegA; Test RegA; ClearRegisters RegA; // Let the assembler know that we no longer need RegA JumpIf True, @@Label_Main_3; // Read in a line //currentline = System.FileReadLine(filepnt); Call System.FileReadLine(@filepnt), @currentline; // Print it to the screen // Use flags, bit 0, which means to try to line wrap cleanly //Print(currentline + "\n", 0x01); Call Strings.Set(@@LocalTempString, @@currentline); Call Strings.Append@StringMem(@@LocalTempString, &@@Const_String3); Call Base.Print(@@LocalTempString, 0x01); //} Jump @@Label_Main_2; @@Label_Main_3: // Close the file //System.FileClose(filepnt); Call System.FileClose(@filepnt); //} // Main EndFunction; Region Constants VarConstant StringMem @@Const_String0 = "Test.txt"; VarConstant StringMem @@Const_String1 = "Unable to locate the Test.txt file."; VarConstant StringMem @@Const_String2 = "Unable to open the Test.txt file."; VarConstant StringMem @@Const_String3 = STRINGLITERAL_NEWLINE;