
%if 0

NASM macros to work with ported WarpLink sources
 2023 by E. C. Masloch, Public Domain

%endif

	cpu 8086

group DGROUP _DATA CONST _BSS STACK
segment _TEXT class=CODE align=2
segment _DATA class=DATA align=2
segment CONST class=DATA align=2
segment _BSS class=BSS bss align=2
segment STACK class=STACK stack align=16
segment _TEXT

%imacro .DATA 0.nolist
	segment _DATA
%endmacro
%imacro .DATA? 0.nolist
	segment _BSS
%endmacro
%imacro .CONST 0.nolist
	segment CONST
%endmacro
%imacro .CODE 0.nolist
	segment _TEXT
%endmacro


%imacro EVEN 0.nolist
 %ifidni __SECT__, [segment _BSS]
	alignb 2
 %else
	align 2, db 0
 %endif
%endmacro


%unimacro section 1+.nolist
%imacro section 1+.nolist
%defstr %%string %1
%strlen %%length %%string
%assign %%ii 1
%rep %%length
 %substr %%sub %%string %%ii
 %deftok %%token %%sub
 %ifempty %%token
  %exitrep
 %else
  %assign %%ii %%ii + 1
 %endif
%endrep
%substr %%sub %%string 1, %%ii - 1
%deftok %%token %%sub
[%?? %1]
%xdefine __SECT__ [%?? %%token]
%endmacro


%imacro LABEL 0-1+
%endmacro


%unimacro struc 1-2.nolist 0
%unimacro struc 1.nolist
%unimacro endstruc 0.nolist			; removes NASM's standard macro
%unimacro endstruc 0-1.nolist

%imacro struc 0-2.nolist ,0
    %push STRUCTURE
 %ifempty %1
        %define %$strucname %00
 %else
        %define %$strucname %1
 %endif
        [absolute %2]
        %$strucname:        ; allow definition of `.member' to work sanely
%endmacro

%imacro endstruc 0.nolist
        %{$strucname}_size equ ($-%$strucname)
    %pop
    __SECT__
%endmacro

%imacro ends 0.nolist
 %ifnempty %00
  %ifctx STRUCTURE
        %{$strucname}_size equ ($-%$strucname)
    %pop
    __SECT__
  %endif
 %endif
%endmacro

%idefine OFFSET
%idefine PTR

%imacro EXTRN 1-*.nolist
 %push
  %rep %0
   %defstr %$input %1
   %strlen %$length %$input
   %assign %$index 1
   %rep %$length
    %substr %$letter %$input %$index
    %if %$letter == ':'
     %exitrep
    %endif
    %assign %$index %$index + 1
   %endrep
   %substr %$output %$input 1, %$index - 1
   %deftok %$label %$output
	extern %$label
   %rotate 1
  %endrep
 %pop
%endmacro

%idefine PUBLIC global

%imacro PROC 0-1.nolist
%00:
 %ifnempty %1
  %ifnidni %1, NEAR
   %error Unknown keyword to PROC macro
  %endif
 %endif
%endmacro
%imacro ENDP 0.nolist
%ifidni %00, 0
%endif
%endmacro

%imacro END 0-1.nolist
%endmacro
