Skip to content

Commit

Permalink
Changed instance decoration text, updated README.md, added COMPILEGUI…
Browse files Browse the repository at this point in the history
…DE.md with demonstration.gif, updated demo.png, optimized compilation
  • Loading branch information
Fodor Levente committed Feb 1, 2021
1 parent efc9cd9 commit 7c4968d
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 54 deletions.
104 changes: 104 additions & 0 deletions COMPILEGUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Manually compiling UBB NASM projects

Everything should be in the same directory for the
sake of simplicity in this case

You should create a script which you can then
run any time, without having to scroll through command
history or retype anything

![demonstration](https://raw.githubusercontent.com/FLevent29/UBB-NASM-Runner/master/demonstration.gif)

## Compile single file project

```batch
@echo off
.\nasm.exe -f win32 example.asm
if %errorlevel% equ 0 (
.\nlink.exe example.obj -lio -o example.exe
if %errorlevel% equ 0 (
.\example.exe
)
)
echo.
echo.
pause
```

- `@echo off` keeps the console clean


- `.\nasm.exe -f win32 example.asm` compiles `example.asm` into `example.obj`
`-f win32` is for format Win32 (i386)
More details [here](https://nasm.us/doc/nasmdoc2.html)


- `%errorlevel%` is the last exit code, so if `nasm.exe`
failed with errors, the script stops, this way it doesn't
compile with the older object file, or if only the linker
fails then it won't run the older executable


- `.\nlink.exe example.obj -lio -o example.exe` creates the
executable from `example.obj` and `io.lib`
`-lio` is required for `%include 'io.inc'` to work
`-lmio` for `'mio.inc'`
`-o example.exe` is the output path/name, if you omit this,
then it defaults to `a.exe`


- Finally, if everything is **OK** so far, we run the executable
`.\example.exe`


- `echo.` just prints a new line


- `pause` is for keeping the console from closing, but
it might be annoying if you run the script from
a terminal directly, in that case it should be left out

## Compile multiple file project

Say you want to compile `STRPELDA.asm`, like in the demo image
you might've seen

It has the following includes :

```assembly
%include 'IOSTR.inc'
%include 'STRINGS.inc'
%include 'IONUM.inc'
```

These all have their `.asm` counterparts that need to be
compiled and those `.asm` files have their own includes,
some are shared, like `IOSTR.inc` both in `STRPELDA.asm`
and `IONUM.asm`

You probably get the idea from this code snippet :

```batch
@echo off
.\nasm.exe -f win32 IOSTR.asm
.\nasm.exe -f win32 STRINGS.asm
.\nasm.exe -f win32 IONUM.asm
.\nasm.exe -f win32 STRPELDA.asm
if %errorlevel% equ 0 (
.\nlink.exe STRPELDA.obj IOSTR.obj STRINGS.obj IONUM.obj -lmio -o STRPELDA.exe
if %errorlevel% equ 0 (
.\STRPELDA.exe
)
)
echo.
echo.
pause
```
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This program compiles and runs and tests assembly project files **at the press of a single button**,
instead of having to struggle with all those pesky terminal commands.

> :warning:**NOTE** You'll need to know how to compile / link / run a project for **exams** manually,
> so make sure you'll know how to do it by then
> :warning:**NOTE** You'll most probably be tasked to compile / link / run a project for **exams _manually_**,
> [here's some help with that](COMPILEGUIDE.md)
![demo](https://raw.githubusercontent.com/FLevent29/UBB-NASM-Runner/master/demo.png)

Expand Down Expand Up @@ -61,8 +61,8 @@ Execute it with a terminal, like [Windows Terminal](https://github.com/microsoft
or through file explorer.
> :warning:**NOTE** Once you start `UBB-NASM-Runner` it will ask you
> if you want your project files moved into `\projects` folder or `\ `
> (you probably keep them in `\ ` either way)
> if you want your project files moved into `\projects` folder or ` \ ` 
> (you probably keep them in ` \ ` either way)
> These are your two options, because of how `nasm.exe` handles
> paths, it cannot escape spaces for include files, so
> if you had your projects and it's include files in
Expand Down
2 changes: 1 addition & 1 deletion UBB-NASM-Runner/AppRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using System.Threading.Tasks;

// NOTE: nasm.exe, ld.exe, nlink.exe and projects created by them can't have their stdio redirected,
// NOTE: nasm.exe, nlink.exe and projects created by them can't have their stdio redirected,
// at least not from .NET, and so we cannot manipulate any of those, the way they handle their io
// is a bit of a mystery to me
namespace UBB_NASM_Runner
Expand Down
18 changes: 3 additions & 15 deletions UBB-NASM-Runner/Presenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,7 @@ private static async Task<int> CompileApp(string filePath) {
return 1;
}

if (exitCode.Equals(0)) {
string exeBinPath = Path.Combine(Model.BinPath, GetFileNameWithExeExtension(filePath)),
exeCompiledPath = Path.Combine(Model.CompiledPath, GetFileNameWithExeExtension(filePath));
if (File.Exists(exeBinPath)) {
if (File.Exists(exeCompiledPath)) {
File.Delete(exeCompiledPath);
}

File.Move(exeBinPath, exeCompiledPath);
}
}

// Delete all created object files
// Delete all created object files, should I though?
foreach (var file in filesToDelete.Where(File.Exists)) {
File.Delete(file);
}
Expand All @@ -454,9 +442,9 @@ private static async Task<int> CompileApp(string filePath) {

private static async Task<int> LinkApp(string filePath, string argumentLibType) {
try {
// Run Nlink, it doesn't escape spaces within quotation marks in arguments
// Run Nlink
var args = $"{GetFileNameWithObjExtension(filePath)} {argumentLibType} " +
$"-o {GetFileNameWithExeExtension(filePath)}";
$"-o \"{Path.Combine(Model.CompiledPath, GetFileNameWithExeExtension(filePath))}\"";
return await AppRunner.StartConsoleApp(Model.NLinkPath,args);
}
catch (Exception exception) {
Expand Down
68 changes: 34 additions & 34 deletions UBB-NASM-Runner/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ internal static class View
public static readonly string Nl = Environment.NewLine;
private static uint _lengthOfControls;

private static readonly string[] ErrorMessages = {
"She sells seashells by the seashore.",

$"How much wood would a woodchuck chuck if a woodchuck could chuck wood?{Nl}" +
$"He would chuck, he would, as much as he could, and chuck as much wood{Nl}" +
"as a woodchuck would if a woodchuck could chuck wood.",

$"If you must cross a course cross cow across a crowded cow crossing,{Nl}" +
"cross the cross coarse cow across the crowded cow crossing carefully.",

"Which witch switched the Swiss wristwatches?",

$"To begin to toboggan first buy a toboggan, but don't buy too big a toboggan.{Nl}" +
"Too big a toboggan is too big a toboggan to buy to begin to toboggan."
};

public static string GetRandomErrorMessage() {
return ErrorMessages[new Random().Next(ErrorMessages.Length)];
}
// private static readonly string[] ErrorMessages = {
// "She sells seashells by the seashore.",
//
// $"How much wood would a woodchuck chuck if a woodchuck could chuck wood?{Nl}" +
// $"He would chuck, he would, as much as he could, and chuck as much wood{Nl}" +
// "as a woodchuck would if a woodchuck could chuck wood.",
//
// $"If you must cross a course cross cow across a crowded cow crossing,{Nl}" +
// "cross the cross coarse cow across the crowded cow crossing carefully.",
//
// "Which witch switched the Swiss wristwatches?",
//
// $"To begin to toboggan first buy a toboggan, but don't buy too big a toboggan.{Nl}" +
// "Too big a toboggan is too big a toboggan to buy to begin to toboggan."
// };

// public static string GetRandomErrorMessage() {
// return ErrorMessages[new Random().Next(ErrorMessages.Length)];
// }

// For future if emoji use is planned
// Console.OutputEncoding = System.Text.Encoding.UTF8; will be required
public static bool ConsoleSupportsUnicode() {
var cursorLeft = Console.CursorLeft;
Console.Write("✅");
var leftAdvance = Console.CursorLeft - cursorLeft;
Console.Write(string.Concat(Enumerable.Repeat("\b \b", leftAdvance)));
return leftAdvance != 1;
}
// public static bool ConsoleSupportsUnicode() {
// var cursorLeft = Console.CursorLeft;
// Console.Write("✅");
// var leftAdvance = Console.CursorLeft - cursorLeft;
// Console.Write(string.Concat(Enumerable.Repeat("\b \b", leftAdvance)));
// return leftAdvance != 1;
// }

public static void SetTitle(string title) {
if (!title.Equals(string.Empty)) {
Expand Down Expand Up @@ -76,11 +76,11 @@ private static void SetCursorLeftmost() {
Console.SetCursorPosition(0, Console.CursorTop);
}

public static void MoveCursorUp(uint amount = 1) {
private static void MoveCursorUp(uint amount = 1) {
Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - (int) amount);
}

public static void ScrollDown() {
private static void ScrollDown() {
CursorVisibility(false);
Console.Write(string.Concat(Enumerable.Repeat(Nl, Console.WindowHeight - 2)));
Console.SetCursorPosition(0, Console.CursorTop - Console.WindowHeight + 2);
Expand Down Expand Up @@ -195,17 +195,17 @@ public static void PrintNewInstanceDecoration(uint counter = 0, string middleTex

if (!middleText.Equals(string.Empty)) {
finalMidText = counter switch {
0 => $" <{middleText}> ",
1 => $" {middleText} <{counter}> ",
_ => $" <{counter}> "
0 => $"{middleText}",
1 => $"{middleText} {counter}",
_ => $"{counter}"
};
}
else {
finalMidText = " +++ ";
finalMidText = " ¡!¡ ";
}

// -==: EXAMPLE <4> :==-
finalMidText = $"-==:{finalMidText}:==-";
// «« EXAMPLE 1 »»
finalMidText = $"«« {finalMidText} »»";

var count = Console.WindowWidth / 2 - finalMidText.Length / 2;
if (count > 0) {
Expand Down
Binary file removed binary-standalone/UBB-NASM-Runner.exe
Binary file not shown.
Binary file removed binary/UBB-NASM-Runner.exe
Binary file not shown.
Binary file modified demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demonstration.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7c4968d

Please sign in to comment.