Compare commits

..

2 Commits

Author SHA1 Message Date
6f2fc627be new fancy macros to make it nicer to call functions 2025-09-07 13:16:37 -04:00
20c715fadd update notes on unreal entry 2025-09-07 13:15:40 -04:00
2 changed files with 78 additions and 1 deletions

View File

@@ -39,6 +39,80 @@
%endmacro
%endif
; __CDECL16_ARGS nargs
; Creates %$arg1 .. %$argN as [bp+4], [bp+6], ...
; for use inside of function bodies
;
%ifnmacro __CDECL16_ARGS
%macro __CDECL16_ARGS 1
%assign %$__i 1
%rep %1
%xdefine %$arg%$__i [bp + 4 + 2*(%$__i-1)]
%assign %$__i %$__i + 1
%endrep
%endmacro
%endif
; __CDECL16_PUSH a,b,c ==> push c / push b / push a
; handles pushing values to the stack in the correct order
%ifnmacro __CDECL16_PUSH
%macro __CDECL16_PUSH 1-*
%assign %$__i %0
%rep %0
push %[%$__i]
%assign %$__i %$__i - 1
%endrep
%endmacro
%endif
; __CDECL16_CALL func, nargs ; adds sp by nargs*2 after call
; adds up word pushes to restore stack frame
; WARNING: if you push a dword it will only count 2, use __CDECL16_CALL_SIZED
%ifnmacro __CDECL16_CALL
%macro __CDECL16_CALL 2
call %1
add sp, %2*2
%endmacro
%endif
; __CDECL16_CALL_SIZED func, size1[, size2 ...] ; sizes in BYTES
; if you *need* to pass dword sized args in 16-bit mode, use this to properly
; count the stack frame to restore later!
%ifnmacro __CDECL16_CALL_SIZED
%macro __CDECL16_CALL_SIZED 2-*
call %1
%assign %$__sum 0
%assign %$__i 2
%rep %0-1
%assign %$__sum %$__sum + %[%$__i]
%assign %$__i %$__i + 1
%endrep
add sp, %$__sum
%endmacro
%endif
; __CDECL16_INVOKE func, arg1[, arg2 ...]
; pushes args right-to-left, calls, then add sp by (#args)*2
; !!! warning for word sized args only !!!
%ifnmacro __CDECL16_INVOKE
%macro __CDECL16_INVOKE 1-*
%assign %$__argc %0-1
%if %$__argc > 0
; push args right-to-left
%assign %$__i %0
%rep %$__argc
push %[%$__i]
%assign %$__i %$__i - 1
%endrep
call %1
add sp, %$__argc*2
%else
call %1
%endif
%endmacro
%endif
%ifnmacro __CDECL16_CALLER_SAVE
%macro __CDECL16_CALLER_SAVE 0
push ax

View File

@@ -171,7 +171,10 @@ main:
call GetMemoryMap
print_string MemoryMap_OK_info
; enter unreal mode (16 bit code, 32 bit flat memory model)
; enter unreal mode (enter PM w/ 16 bit code, 32 bit flat memory model & return to real)
; ds, es will be set to the 64KiB STAGE2_SEGMENT, fs/gs will be flat/huge memory (4GiB)
; use __REFLAT macros to re-flat ds/es for easy transfers to >1MiB
; NOTE: if you modify a segment register you will need to re-unreal it
call EnterUnrealMode
print_string UnrealMode_OK_info