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

Last change on this file was 602, checked in by krille_n_, 5 years ago

Changes:

  • SerDrive: Fixed a bug that prevented use of 3.5" 720 KB floppy disk images.
  • Also added support for Microsoft DMF (Distribution Media Format) floppy disk images.
  • XTIDECFG / Library: Minor size optimizations. Added a new macro (SKIP1B) as part of that.
  • BIOS: A small size optimization (2 bytes) to MODULE_8BIT_IDE_ADVANCED that is enabled only when USE_NEC_V is defined.
File size: 4.9 KB
Line 
1; Project name  :   Assembly Library
2; Description   :   This is the place to put various generic macros.
3;                   Should be included immediately after Emulate.inc
4%ifndef MACROS_INC
5%define MACROS_INC
6
7
8;--------------------------------------------------------------------
9; Skips the immediately following 1 byte instruction by using it
10; as an immediate value to a dummy instruction.
11; Destroys the contents of %1.
12;
13; SKIP1B
14;   Parameters:
15;       %1:     Any 8 bit general purpose register or F for flags.
16;   Returns:
17;       Nothing
18;   Corrupts registers:
19;       %1
20;--------------------------------------------------------------------
21%macro SKIP1B 1.nolist
22    %ifidni     %1, f
23        db  03Ch                    ; Opcode byte for CMP AL, <immed>
24        ;db 0A8h                    ; Alt. version TEST AL, <immed>
25    %elifidni   %1, al
26        db  0B0h                    ; Opcode byte for MOV AL, <immed>
27    %elifidni   %1, ah
28        db  0B4h                    ; Opcode byte for MOV AH, <immed>
29    %elifidni   %1, bl
30        db  0B3h                    ; Opcode byte for MOV BL, <immed>
31    %elifidni   %1, bh
32        db  0B7h                    ; Opcode byte for MOV BH, <immed>
33    %elifidni   %1, cl
34        db  0B1h                    ; Opcode byte for MOV CL, <immed>
35    %elifidni   %1, ch
36        db  0B5h                    ; Opcode byte for MOV CH, <immed>
37    %elifidni   %1, dl
38        db  0B2h                    ; Opcode byte for MOV DL, <immed>
39    %elifidni   %1, dh
40        db  0B6h                    ; Opcode byte for MOV DH, <immed>
41    %else
42        %error "Invalid parameter passed to SKIP1B"
43    %endif
44%endmacro
45
46;--------------------------------------------------------------------
47; Skips the immediately following 2 byte instruction by using it
48; as an immediate value to a dummy instruction.
49; Destroys the contents of %1.
50;
51; SKIP2B
52;   Parameters:
53;       %1:     Any 16 bit general purpose register or F for flags.
54;   Returns:
55;       Nothing
56;   Corrupts registers:
57;       %1
58;--------------------------------------------------------------------
59%macro SKIP2B 1.nolist
60    %ifidni     %1, f
61        db  03Dh                    ; Opcode byte for CMP AX, <immed>
62        ;db 0A9h                    ; Alt. version TEST AX, <immed>
63    %elifidni   %1, ax
64        db  0B8h                    ; Opcode byte for MOV AX, <immed>
65    %elifidni   %1, cx
66        db  0B9h                    ; Opcode byte for MOV CX, <immed>
67    %elifidni   %1, dx
68        db  0BAh                    ; Opcode byte for MOV DX, <immed>
69    %elifidni   %1, bx
70        db  0BBh                    ; Opcode byte for MOV BX, <immed>
71    %elifidni   %1, sp
72        db  0BCh                    ; Opcode byte for MOV SP, <immed>
73    %elifidni   %1, bp
74        db  0BDh                    ; Opcode byte for MOV BP, <immed>
75    %elifidni   %1, si
76        db  0BEh                    ; Opcode byte for MOV SI, <immed>
77    %elifidni   %1, di
78        db  0BFh                    ; Opcode byte for MOV DI, <immed>
79    %else
80        %error "Invalid parameter passed to SKIP2B"
81    %endif
82%endmacro
83
84
85;--------------------------------------------------------------------
86; Load BDA (Bios Data Area) segment to wanted segment register.
87;
88; Use an exclamation point (!) as the third parameter when you want
89; to force the use of the register in the second parameter. This is
90; useful when that register needs to be zeroed in subsequent code or
91; when stack usage is undesirable (ie speed is critical).
92;
93; The PRESERVE_FLAGS version will zero the register with a MOV instead
94; of an XOR, thus preserving the flags.  It is one byte larger on
95; non-186 or higher systems.
96;
97; LOAD_BDA_SEGMENT_TO
98; LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO
99;   Parameters:
100;       %1:     Destination Segment Register
101;       %2:     Temporary WORD Register
102;       %3:     Can be ! or empty
103;   Returns:
104;       %1:     BDA segment (zero)
105;   Corrupts registers:
106;       %2
107;--------------------------------------------------------------------
108%macro LOAD_BDA_SEGMENT_TO 2-3
109%ifndef USE_186
110    xor     %2, %2
111    mov     %1, %2
112%elifidn %3, !
113    xor     %2, %2
114    mov     %1, %2
115%else
116    push    BYTE 0
117    pop     %1
118%endif
119%endmacro
120
121%macro LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO 2-3
122%ifndef USE_186
123    mov     %2, 0
124    mov     %1, %2
125%elifidn %3, !
126    mov     %2, 0
127    mov     %1, %2
128%else
129    push    BYTE 0
130    pop     %1
131%endif
132%endmacro
133
134
135;--------------------------------------------------------------------
136; eENTER_STRUCT
137;   Parameters:
138;       %1:     Number of bytes to reserve from stack
139;   Returns:
140;       SS:BP:  Ptr to beginning of struct reserved from stack
141;   Corrupts registers:
142;       FLAGS
143;--------------------------------------------------------------------
144%macro eENTER_STRUCT 1
145    push    bp
146    sub     sp, %1
147    mov     bp, sp
148%endmacro
149
150;--------------------------------------------------------------------
151; eLEAVE_STRUCT
152;   Parameters:
153;       %1:     Number of bytes reserved with eENTER_STRUCT
154;   Returns:
155;       BP:     What it was before eENTER_STRUCT
156;   Corrupts registers:
157;       FLAGS
158;--------------------------------------------------------------------
159%macro eLEAVE_STRUCT 1
160    add     sp, %1
161    pop     bp
162%endmacro
163
164
165;--------------------------------------------------------------------
166; Small delay between I/O port accesses if needed.
167;
168; IO_DELAY
169;   Parameters:
170;       Nothing
171;   Returns:
172;       Nothing
173;   Corrupts registers:
174;       Nothing
175;--------------------------------------------------------------------
176%macro IO_DELAY 0
177    jmp     SHORT %%ClearPrefetchQueue
178%%ClearPrefetchQueue:
179%endmacro
180
181
182%endif ; MACROS_INC
Note: See TracBrowser for help on using the repository browser.