OSDN Git Service

got 8086 port of wolf3d to work and sod to work
[proj16/16.git] / 16 / WOLFSRC / JABHACK.ASM
1 ; JABHACK.ASM\r
2 \r
3 .386C\r
4 IDEAL\r
5 MODEL   MEDIUM\r
6 \r
7 EXTRN   LDIV@:far\r
8 \r
9 ;============================================================================\r
10 \r
11 DATASEG\r
12 \r
13 EXTRN   _intaddr:word\r
14 \r
15 ;============================================================================\r
16 \r
17 CODESEG\r
18 \r
19 ;       Hacked up Juan Jimenez's code a bit to just return 386/not 386\r
20 PROC    _CheckIs386\r
21 PUBLIC  _CheckIs386\r
22 \r
23         pushf                   ; Save flag registers, we use them here\r
24         xor     ax,ax           ; Clear AX and...\r
25         push ax                 ; ...push it onto the stack\r
26         popf                    ; Pop 0 into flag registers (all bits to 0),\r
27         pushf                   ; attempting to set bits 12-15 of flags to 0's\r
28         pop     ax                      ; Recover the save flags\r
29         and     ax,08000h       ; If bits 12-15 of flags are set to\r
30         cmp     ax,08000h       ; zero then it's 8088/86 or 80188/186\r
31         jz      not386\r
32 \r
33         mov     ax,07000h       ; Try to set flag bits 12-14 to 1's\r
34         push ax                 ; Push the test value onto the stack\r
35         popf                    ; Pop it into the flag register\r
36         pushf                   ; Push it back onto the stack\r
37         pop     ax                      ; Pop it into AX for check\r
38         and     ax,07000h       ; if bits 12-14 are cleared then\r
39         jz      not386          ; the chip is an 80286\r
40 \r
41         mov     ax,1            ; We now assume it's a 80386 or better\r
42         popf\r
43         retf\r
44 \r
45 not386:\r
46         xor     ax,ax\r
47         popf\r
48         retf\r
49 \r
50         ENDP\r
51 \r
52 \r
53 PROC    _jabhack2\r
54 PUBLIC  _jabhack2\r
55 \r
56         jmp     @@skip\r
57 \r
58 @@where:\r
59         int     060h\r
60         retf\r
61 \r
62 @@skip:\r
63         push    es\r
64 \r
65         mov     ax,seg LDIV@\r
66         mov     es,ax\r
67         mov     ax,[WORD PTR @@where]\r
68         mov     [WORD FAR es:LDIV@],ax\r
69         mov     ax,[WORD PTR @@where+2]\r
70         mov     [WORD FAR es:LDIV@+2],ax\r
71 \r
72         mov     ax,offset @@jabdiv\r
73         mov     [_intaddr],ax\r
74         mov     ax,seg @@jabdiv\r
75         mov     [_intaddr+2],ax\r
76 \r
77         pop     es\r
78         retf\r
79 \r
80 @@jabdiv:\r
81         add     sp,4    ;Nuke IRET address, but leave flags\r
82         push bp\r
83         mov     bp,sp   ;Save BP, and set it equal to stack\r
84         cli\r
85 \r
86         mov     eax,[bp+8]\r
87         cdq\r
88         idiv [DWORD PTR bp+12]\r
89         mov     edx,eax\r
90         ;begin 8086 hack\r
91         ;shr    edx,16\r
92         push cx\r
93         mov cl,16\r
94         shr     edx,cl\r
95         pop cx\r
96         ;end 8086 hack\r
97         pop     bp              ;Restore BP\r
98         popf            ;Restore flags (from INT)\r
99         retf    8       ;Return to original caller\r
100 \r
101         ENDP\r
102 \r
103         END\r