1 2 ; Public Domain 3 4 %include "lmacros3.mac" 1 <1> [list -] 14 <2> [list -] 14 <1> [list -] 5 6 numdef DOSEXIT, 0 7 numdef DOSENTRY, 0 8 numdef LARGEFILL, 0 9 numdef RELOC, 1 10 numdef BASESEGMENT, 0 11 numdef RELOCEXE, 0 12 13 14 cpu 8086 15 %if _RELOCEXE 16 %assign ORIGIN 0 17 org ORIGIN 18 addsection HEADER, start=0 19 header_start: 20 db "MZ" ; exeSignature 21 FILESIZE equ fromparas(header_size_p + BEHINDSEGMENT) 22 dw FILESIZE % 512 ; exeExtraBytes 23 dw (FILESIZE + 511) / 512 ; exePages 24 dw relocationtable.amount ; exeRelocItems 25 dw header_size_p ; exeHeaderSize 26 dw paras(512) ; exeMinAlloc 27 dw paras(512) ; exeMaxAlloc 28 dw +BEHINDSEGMENT ; exeInitSS 29 dw 512 ; exeInitSP 30 dw 0 ; exeChecksum 31 dw 0, +0 ; exeInitCSIP 32 dw relocationtable ; exeRelocTable 33 34 addsection FIRST, vstart=0 align=16 follows=HEADER 35 %elif _DOSENTRY 36 %assign ORIGIN 256 37 org ORIGIN 38 addsection FIRST, start=ORIGIN 39 %else 40 %assign ORIGIN 0 41 org ORIGIN 42 addsection FIRST, start=ORIGIN 43 %endif 44 first_start: 45 addsection SECOND, vstart=0 align=16 follows=FIRST 46 second_start: 47 addsection THIRD, vstart=0 align=16 follows=SECOND 48 third_start: 49 50 first_size equ first_end - first_start 51 endarea first, 1 52 second_size equ second_end - second_start 53 endarea second, 1 54 third_size equ third_end - third_start 55 endarea third, 1 56 %if _RELOCEXE 57 header_size equ header_end - header_start 58 endarea header, 1 59 %endif 60 61 FIRSTSEGMENT equ _BASESEGMENT + 0 62 SECONDSEGMENT equ _BASESEGMENT + paras(ORIGIN) + first_size_p 63 THIRDSEGMENT equ _BASESEGMENT + paras(ORIGIN) + first_size_p + second_size_p 64 BEHINDSEGMENT equ _BASESEGMENT + paras(ORIGIN) + first_size_p + second_size_p + third_size_p 65 66 %define RELOCATIONFROMFIRST "" 67 %define RELOCATIONFROMSECOND "" 68 %define RELOCATIONFROMTHIRD "" 69 %imacro relocation 0-1.nolist -2 70 %%reloc equ $ + %1 71 %ifidn _CURRENT_SECTION, FIRST 72 %xdefine RELOCATIONFROMFIRST RELOCATIONFROMFIRST, %%reloc, FIRSTSEGMENT 73 %elifidn _CURRENT_SECTION, SECOND 74 %xdefine RELOCATIONFROMSECOND RELOCATIONFROMSECOND, %%reloc, SECONDSEGMENT 75 %elifidn _CURRENT_SECTION, THIRD 76 %xdefine RELOCATIONFROMTHIRD RELOCATIONFROMTHIRD, %%reloc, THIRDSEGMENT 77 %else 78 %error Unknown section for relocation 79 %endif 80 %endmacro 81 82 usesection FIRST 83 start: 84 00000000 8CCA mov dx, cs 85 00000002 8EDA mov ds, dx 86 %if !_RELOCEXE && _RELOC 87 00000004 BE[4C00] mov si, relocationtable 88 00000007 B90400 mov cx, relocationtable.amount 89 0000000A E30C jcxz .noreloc 90 @@: 91 0000000C AD lodsw 92 0000000D 93 xchg bx, ax 93 0000000E AD lodsw 94 0000000F 01D0 add ax, dx 95 00000011 8EC0 mov es, ax 96 00000013 260117 add word [es:bx], dx 97 00000016 E2F4 loop @B 98 .noreloc: 99 %endif 100 101 displayfirst: 102 00000018 BE[3700] mov si, firstmsg 103 0000001B BB0700 mov bx, 7 104 0000001E B40E mov ah, 0Eh 105 00000020 A9 db __TEST_IMM16 ; (skip int 10h) 106 @@: 107 00000021 CD10 int 10h 108 00000023 AC lodsb 109 00000024 84C0 test al, al 110 00000026 75F9 jnz @B 111 112 00000028 9A[1500]1600 call SECONDSEGMENT:secondentry 113 relocation 114 115 exit: 116 %if _DOSEXIT 117 0000002D B8004C mov ax, 4C00h 118 00000030 CD21 int 21h 119 %else 120 xor ax, ax 121 int 16h 122 int 19h 123 %endif 124 125 126 bouncetothird: 127 00000032 EA[1D00]1900 jmp THIRDSEGMENT:bounced 128 relocation 129 130 131 00000037 48656C6C6F2066726F- firstmsg: asciz "Hello from first!",13,10 131 00000040 6D206669727374210D- 131 00000049 0A00 132 133 134 usesection SECOND 135 136 00000000 48656C6C6F2066726F- secondmsg: asciz "Hello from second!",13,10 136 00000009 6D207365636F6E6421- 136 00000012 0D0A00 137 138 secondentry: 139 displaysecond: 140 00000015 BE[0000] mov si, secondmsg 141 00000018 BB0700 mov bx, 7 142 0000001B B40E mov ah, 0Eh 143 0000001D A9 db __TEST_IMM16 ; (skip int 10h) 144 @@: 145 0000001E CD10 int 10h 146 00000020 2EAC cs lodsb 147 00000022 84C0 test al, al 148 00000024 75F8 jnz @B 149 150 00000026 EA[1800]1900 jmp THIRDSEGMENT:thirdentry 151 relocation 152 153 154 usesection THIRD 155 156 align 2, db 0 157 indirect_to_bounce: 158 00000000 [3200] dw bouncetothird 159 relocation 0 160 00000002 0000 dw FIRSTSEGMENT 161 162 00000004 48656C6C6F2066726F- thirdmsg: asciz "Hello from third!",13,10 162 0000000D 6D207468697264210D- 162 00000016 0A00 163 164 thirdentry: 165 00000018 2EFF2E[0000] jmp far [cs:indirect_to_bounce] 166 167 bounced: 168 displaythird: 169 0000001D BE[0400] mov si, thirdmsg 170 00000020 BB0700 mov bx, 7 171 00000023 B40E mov ah, 0Eh 172 00000025 A9 db __TEST_IMM16 ; (skip int 10h) 173 @@: 174 00000026 CD10 int 10h 175 00000028 2EAC cs lodsb 176 0000002A 84C0 test al, al 177 0000002C 75F8 jnz @B 178 179 0000002E CB retf 180 181 182 %ifn _RELOCEXE 183 usesection FIRST 184 %else 185 usesection HEADER 186 %endif 187 %if _RELOCEXE || _RELOC 188 0000004B 00 align 4, db 0 189 relocationtable: 190 .: 191 0000004C [2B00]0000[3500]00- dw RELOCATIONFROMFIRST 191 00000053 00 192 00000054 [2900]1600 dw RELOCATIONFROMSECOND 193 00000058 [0200]1900 dw RELOCATIONFROMTHIRD 194 .end: 195 .amount: equ (.end - .) / 4 196 %endif 197 %if _RELOCEXE 198 align 16 199 header_end: 200 %endif 201 202 %if _LARGEFILL 203 usesection SECOND 204 _fill fromkib(64), 0CCh, second_start 205 %endif 206 207 usesection FIRST 208 0000005C 90 align 16 209 first_end: 210 usesection SECOND 211 0000002B 90 align 16 212 second_end: 213 usesection THIRD 214 0000002F 90 align 16 215 third_end: