]> 4ch.mooo.com Git - 16.git/blob - 16/cawat/JABHACK.ASM
16213675c32c48376a9f30e1620b98c451dd9cb3
[16.git] / 16 / cawat / JABHACK.ASM
1 ; Catacomb Armageddon Source Code\r
2 ; Copyright (C) 1993-2014 Flat Rock Software\r
3 ;\r
4 ; This program is free software; you can redistribute it and/or modify\r
5 ; it under the terms of the GNU General Public License as published by\r
6 ; the Free Software Foundation; either version 2 of the License, or\r
7 ; (at your option) any later version.\r
8 ;\r
9 ; This program is distributed in the hope that it will be useful,\r
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12 ; GNU General Public License for more details.\r
13 ;\r
14 ; You should have received a copy of the GNU General Public License along\r
15 ; with this program; if not, write to the Free Software Foundation, Inc.,\r
16 ; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
17 \r
18 ; JABHACK.ASM\r
19 \r
20 .386C\r
21 IDEAL\r
22 MODEL   MEDIUM\r
23 \r
24 EXTRN   LDIV@:far\r
25 \r
26 ;============================================================================\r
27 \r
28 DATASEG\r
29 \r
30 EXTRN   _intaddr:word\r
31 \r
32 ;============================================================================\r
33 \r
34 CODESEG\r
35 \r
36 ;       Hacked up Juan Jimenez's code a bit to just return 386/not 386\r
37 PROC    _CheckIs386\r
38 PUBLIC  _CheckIs386\r
39 \r
40         pushf                   ; Save flag registers, we use them here\r
41         xor     ax,ax           ; Clear AX and...\r
42         push ax                 ; ...push it onto the stack\r
43         popf                    ; Pop 0 into flag registers (all bits to 0),\r
44         pushf                   ; attempting to set bits 12-15 of flags to 0's\r
45         pop     ax                      ; Recover the save flags\r
46         and     ax,08000h       ; If bits 12-15 of flags are set to\r
47         cmp     ax,08000h       ; zero then it's 8088/86 or 80188/186\r
48         jz      not386\r
49 \r
50         mov     ax,07000h       ; Try to set flag bits 12-14 to 1's\r
51         push ax                 ; Push the test value onto the stack\r
52         popf                    ; Pop it into the flag register\r
53         pushf                   ; Push it back onto the stack\r
54         pop     ax                      ; Pop it into AX for check\r
55         and     ax,07000h       ; if bits 12-14 are cleared then\r
56         jz      not386          ; the chip is an 80286\r
57 \r
58         mov     ax,1            ; We now assume it's a 80386 or better\r
59         popf\r
60         retf\r
61 \r
62 not386:\r
63         xor     ax,ax\r
64         popf\r
65         retf\r
66 \r
67         ENDP\r
68 \r
69 \r
70 PROC    _jabhack2\r
71 PUBLIC  _jabhack2\r
72 \r
73         jmp     @@skip\r
74 \r
75 @@where:\r
76         int     060h\r
77         retf\r
78 \r
79 @@skip:\r
80         push    es\r
81 \r
82         mov     ax,seg LDIV@\r
83         mov     es,ax\r
84         mov     ax,[WORD PTR @@where]\r
85         mov     [WORD FAR es:LDIV@],ax\r
86         mov     ax,[WORD PTR @@where+2]\r
87         mov     [WORD FAR es:LDIV@+2],ax\r
88 \r
89         mov     ax,offset @@jabdiv\r
90         mov     [_intaddr],ax\r
91         mov     ax,seg @@jabdiv\r
92         mov     [_intaddr+2],ax\r
93 \r
94         pop     es\r
95         retf\r
96 \r
97 @@jabdiv:\r
98         add     sp,4    ;Nuke IRET address, but leave flags\r
99         push bp\r
100         mov     bp,sp   ;Save BP, and set it equal to stack\r
101         cli\r
102 \r
103         mov     eax,[bp+8]\r
104         cdq\r
105         idiv [DWORD PTR bp+12]\r
106         mov     edx,eax\r
107         shr     edx,16\r
108 \r
109         pop     bp              ;Restore BP\r
110         popf            ;Restore flags (from INT)\r
111         retf    8       ;Return to original caller\r
112 \r
113         ENDP\r
114 \r
115         END\r