xref: /haiku/src/add-ons/media/plugins/ape_reader/MAClib/Tools.inc (revision b51fbe43f532ef73b4d3b772f60aace45765e54c)
1*b51fbe43SDavid McPaul;
2*b51fbe43SDavid McPaul; (C) Ururi 1999
3*b51fbe43SDavid McPaul;
4*b51fbe43SDavid McPaul
5*b51fbe43SDavid McPaulBITS 32
6*b51fbe43SDavid McPaul
7*b51fbe43SDavid McPaul%ifdef WIN32
8*b51fbe43SDavid McPaul        %define _NAMING
9*b51fbe43SDavid McPaul        %define segment_code segment .text align=32 class=CODE use32
10*b51fbe43SDavid McPaul        %define segment_data segment .data align=32 class=DATA use32
11*b51fbe43SDavid McPaul  %ifdef __BORLANDC__
12*b51fbe43SDavid McPaul        %define segment_bss  segment .data align=32 class=DATA use32
13*b51fbe43SDavid McPaul  %else
14*b51fbe43SDavid McPaul        %define segment_bss  segment .bss  align=32 class=DATA use32
15*b51fbe43SDavid McPaul  %endif
16*b51fbe43SDavid McPaul
17*b51fbe43SDavid McPaul%elifdef AOUT
18*b51fbe43SDavid McPaul        %define _NAMING
19*b51fbe43SDavid McPaul        %define segment_code segment .text
20*b51fbe43SDavid McPaul        %define segment_data segment .data
21*b51fbe43SDavid McPaul        %define segment_bss  segment .bss
22*b51fbe43SDavid McPaul
23*b51fbe43SDavid McPaul%else
24*b51fbe43SDavid McPaul        %define segment_code segment .text align=32 class=CODE use32
25*b51fbe43SDavid McPaul        %define segment_data segment .data align=32 class=DATA use32
26*b51fbe43SDavid McPaul        %define segment_bss  segment .bss  align=32 class=DATA use32
27*b51fbe43SDavid McPaul%endif
28*b51fbe43SDavid McPaul
29*b51fbe43SDavid McPaul%define pmov    movq
30*b51fbe43SDavid McPaul%define pmovd   movd
31*b51fbe43SDavid McPaul
32*b51fbe43SDavid McPaul%define pupldq  punpckldq
33*b51fbe43SDavid McPaul%define puphdq  punpckhdq
34*b51fbe43SDavid McPaul%define puplwd  punpcklwd
35*b51fbe43SDavid McPaul%define puphwd  punpckhwd
36*b51fbe43SDavid McPaul
37*b51fbe43SDavid McPaul%imacro globaldef 1
38*b51fbe43SDavid McPaul        %ifdef _NAMING
39*b51fbe43SDavid McPaul                %define %1 _%1
40*b51fbe43SDavid McPaul        %endif
41*b51fbe43SDavid McPaul        global %1
42*b51fbe43SDavid McPaul%endmacro
43*b51fbe43SDavid McPaul
44*b51fbe43SDavid McPaul%imacro externdef 1
45*b51fbe43SDavid McPaul        %ifdef _NAMING
46*b51fbe43SDavid McPaul                %define %1 _%1
47*b51fbe43SDavid McPaul        %endif
48*b51fbe43SDavid McPaul        extern %1
49*b51fbe43SDavid McPaul%endmacro
50*b51fbe43SDavid McPaul
51*b51fbe43SDavid McPaul%imacro proc 1
52*b51fbe43SDavid McPaul        %push   proc
53*b51fbe43SDavid McPaul        global  _%1
54*b51fbe43SDavid McPaul        global  %1
55*b51fbe43SDavid McPaul_%1:
56*b51fbe43SDavid McPaul%1:
57*b51fbe43SDavid McPaul        %assign %$STACK  0
58*b51fbe43SDavid McPaul        %assign %$STACKN 0
59*b51fbe43SDavid McPaul        %assign %$ARG    4
60*b51fbe43SDavid McPaul%endmacro
61*b51fbe43SDavid McPaul
62*b51fbe43SDavid McPaul%imacro endproc 0
63*b51fbe43SDavid McPaul        %ifnctx proc
64*b51fbe43SDavid McPaul                %error expected 'proc' before 'endproc'.
65*b51fbe43SDavid McPaul        %else
66*b51fbe43SDavid McPaul                %if %$STACK > 0
67*b51fbe43SDavid McPaul                        add esp, %$STACK
68*b51fbe43SDavid McPaul                %endif
69*b51fbe43SDavid McPaul
70*b51fbe43SDavid McPaul                %if %$STACK <> (-%$STACKN)
71*b51fbe43SDavid McPaul                        %error STACKLEVEL mismatch check 'local', 'alloc', 'pushd', 'popd'
72*b51fbe43SDavid McPaul                %endif
73*b51fbe43SDavid McPaul
74*b51fbe43SDavid McPaul                ret
75*b51fbe43SDavid McPaul                %pop
76*b51fbe43SDavid McPaul        %endif
77*b51fbe43SDavid McPaul%endmacro
78*b51fbe43SDavid McPaul
79*b51fbe43SDavid McPaul%idefine sp(a) esp+%$STACK+a
80*b51fbe43SDavid McPaul
81*b51fbe43SDavid McPaul%imacro arg 1
82*b51fbe43SDavid McPaul        %00     equ %$ARG
83*b51fbe43SDavid McPaul        %assign %$ARG %$ARG+%1
84*b51fbe43SDavid McPaul%endmacro
85*b51fbe43SDavid McPaul
86*b51fbe43SDavid McPaul%imacro local 1
87*b51fbe43SDavid McPaul        %assign %$STACKN %$STACKN-%1
88*b51fbe43SDavid McPaul        %00 equ %$STACKN
89*b51fbe43SDavid McPaul%endmacro
90*b51fbe43SDavid McPaul
91*b51fbe43SDavid McPaul%imacro alloc 0
92*b51fbe43SDavid McPaul        sub esp, (-%$STACKN)-%$STACK
93*b51fbe43SDavid McPaul        %assign %$STACK (-%$STACKN)
94*b51fbe43SDavid McPaul%endmacro
95*b51fbe43SDavid McPaul
96*b51fbe43SDavid McPaul%imacro pushd 1-*
97*b51fbe43SDavid McPaul        %rep %0
98*b51fbe43SDavid McPaul                push %1
99*b51fbe43SDavid McPaul                %assign %$STACK %$STACK+4
100*b51fbe43SDavid McPaul        %rotate 1
101*b51fbe43SDavid McPaul        %endrep
102*b51fbe43SDavid McPaul%endmacro
103*b51fbe43SDavid McPaul
104*b51fbe43SDavid McPaul%imacro popd 1-*
105*b51fbe43SDavid McPaul        %rep %0
106*b51fbe43SDavid McPaul        %rotate -1
107*b51fbe43SDavid McPaul                pop %1
108*b51fbe43SDavid McPaul                %assign %$STACK %$STACK-4
109*b51fbe43SDavid McPaul        %endrep
110*b51fbe43SDavid McPaul%endmacro
111*b51fbe43SDavid McPaul
112*b51fbe43SDavid McPaul%macro  algn    1
113*b51fbe43SDavid McPaul        align   16
114*b51fbe43SDavid McPaul        %rep    (65536-%1) & 15
115*b51fbe43SDavid McPaul        nop
116*b51fbe43SDavid McPaul        %endrep
117*b51fbe43SDavid McPaul%endm
118