source: xtideuniversalbios/trunk/Assembly_Library/Inc/Macros.inc@ 578

Last change on this file since 578 was 566, checked in by krille_n_@…, 11 years ago

Changes to XTIDE Universal BIOS:

  • Fixed a very old bug (from r150) in IdeError.asm where GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX would return RET_HD_SEEK_FAIL instead of RET_HD_STATUSERR.
  • Optimizations and other fixes.
File size: 3.4 KB
RevLine 
[104]1; Project name : Assembly Library
2; Description : This is the place to put various generic macros.
[566]3; Should be included immediately after Emulate.inc
[110]4%ifndef MACROS_INC
5%define MACROS_INC
[104]6
7;--------------------------------------------------------------------
8; Skips the immediately following 2 byte instruction by using it
9; as an immediate value to a dummy instruction.
10; Destroys the contents of %1.
11;
12; SKIP2B
13; Parameters:
14; %1: Any 16 bit general purpose register or F for flags.
15; Returns:
16; Nothing
17; Corrupts registers:
18; %1
19;--------------------------------------------------------------------
20%macro SKIP2B 1
21 %ifidni %1, f
22 db 03Dh ; Opcode byte for CMP AX, <immed>
23 ;db 0A9h ; Alt. version TEST AX, <immed>
24 %elifidni %1, ax
25 db 0B8h ; Opcode byte for MOV AX, <immed>
26 %elifidni %1, cx
27 db 0B9h ; Opcode byte for MOV CX, <immed>
28 %elifidni %1, dx
29 db 0BAh ; Opcode byte for MOV DX, <immed>
30 %elifidni %1, bx
31 db 0BBh ; Opcode byte for MOV BX, <immed>
32 %elifidni %1, sp
33 db 0BCh ; Opcode byte for MOV SP, <immed>
34 %elifidni %1, bp
35 db 0BDh ; Opcode byte for MOV BP, <immed>
36 %elifidni %1, si
37 db 0BEh ; Opcode byte for MOV SI, <immed>
38 %elifidni %1, di
39 db 0BFh ; Opcode byte for MOV DI, <immed>
40 %else
41 %error "Invalid parameter passed to SKIP2B"
42 %endif
43%endmacro
[110]44
45
46;--------------------------------------------------------------------
[119]47; Load BDA (Bios Data Area) segment to wanted segment register.
48;
49; Use an exclamation point (!) as the third parameter when you want
50; to force the use of the register in the second parameter. This is
51; useful when that register needs to be zeroed in subsequent code or
52; when stack usage is undesirable (ie speed is critical).
53;
[258]54; The PRESERVE_FLAGS version will zero the register with a MOV instead
55; of an XOR, thus preserving the flags. It is one byte larger on
56; non-186 or higher systems.
57;
[119]58; LOAD_BDA_SEGMENT_TO
[258]59; LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO
[119]60; Parameters:
61; %1: Destination Segment Register
62; %2: Temporary WORD Register
63; %3: Can be ! or empty
64; Returns:
65; %1: BDA segment (zero)
66; Corrupts registers:
67; %2
68;--------------------------------------------------------------------
69%macro LOAD_BDA_SEGMENT_TO 2-3
70%ifndef USE_186
71 xor %2, %2
72 mov %1, %2
73%elifidn %3, !
74 xor %2, %2
75 mov %1, %2
76%else
77 push BYTE 0
78 pop %1
79%endif
80%endmacro
81
[258]82%macro LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO 2-3
83%ifndef USE_186
84 mov %2, 0
85 mov %1, %2
86%elifidn %3, !
87 mov %2, 0
88 mov %1, %2
89%else
90 push BYTE 0
91 pop %1
92%endif
93%endmacro
[119]94
[258]95
[119]96;--------------------------------------------------------------------
[110]97; eENTER_STRUCT
98; Parameters:
99; %1: Number of bytes to reserve from stack
100; Returns:
101; SS:BP: Ptr to beginning of struct reserved from stack
102; Corrupts registers:
103; FLAGS
104;--------------------------------------------------------------------
105%macro eENTER_STRUCT 1
106 push bp
107 sub sp, %1
108 mov bp, sp
109%endmacro
110
111;--------------------------------------------------------------------
112; eLEAVE_STRUCT
113; Parameters:
114; %1: Number of bytes reserved with eENTER_STRUCT
115; Returns:
116; BP: What it was before eENTER_STRUCT
117; Corrupts registers:
118; FLAGS
119;--------------------------------------------------------------------
120%macro eLEAVE_STRUCT 1
121 add sp, %1
122 pop bp
123%endmacro
124
125
126%endif ; MACROS_INC
Note: See TracBrowser for help on using the repository browser.