From 6df757098380fd9450e6e74cbac2bdb69db843bb Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Mon, 23 Oct 2023 23:21:10 +1100 Subject: Add 3-arg parsing into windows build Pretty scuffed, but it works... the loading is especially bad but it's not that much better than linux, except linux we can easily check argc and at least give usage then. Testing each arg seems to work ok for now though lol --- pasmgen-win.asm | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pasmgen-win.asm b/pasmgen-win.asm index c65c47b..927f9b7 100644 --- a/pasmgen-win.asm +++ b/pasmgen-win.asm @@ -7,6 +7,43 @@ section '.text' code readable executable entry main main: + invoke GetCommandLine + +argparse: +.skipexe: + cmp byte [rax], 0 + je defaultargs + + cmp byte [rax], ' ' + je .pastexe + inc rax + jmp .skipexe +.pastexe: + ;; load arg1 + ;; FIXME: at least on my system, there's 2 more spaces (needs more testing if consistent) + mov r8, [rax+2] + and r8, 0xFF + test r8, r8 + jz fail + sub r8, 48 + + ;; load arg2 + mov r9, [rax+4] + and r9, 0xFF + test r9, r9 + jz fail + sub r9, 48 + + ;; load arg3 + mov r10, [rax+6] + and r10, 0xFF + test r10, r10 + jz fail + sub r10, 48 + + jmp generate + +defaultargs: mov r8, qword 3 mov r9, qword 2 mov r10, qword 3 @@ -18,6 +55,11 @@ ok: invoke WriteConsole, rax, out_buf, rsi, 0, 0 invoke ExitProcess, 0 +fail: + invoke GetStdHandle, STD_OUTPUT_HANDLE + invoke WriteConsole, rax, usage, usage_len, 0, 0 + invoke ExitProcess, 1 + include 'pasmgen.inc' -- cgit