home *** CD-ROM | disk | FTP | other *** search
/ 100 af Verdens Bedste Spil / 100Spil.iso / dos / wolf3d / source / wolfsrc.1 / C0.ASM < prev    next >
Assembly Source File  |  1993-02-04  |  28KB  |  842 lines

  1.         NAME    c0
  2.         PAGE    60,132
  3.         LOCALS
  4. ;[]------------------------------------------------------------[]
  5. ;|      C0.ASM -- Start Up Code                                 |
  6. ;|                                                              |
  7. ;|      Turbo C++ Run Time Library                              |
  8. ;|                                                              |
  9. ;|      Copyright (c) 1987, 1991 by Borland International Inc.  |
  10. ;|      All Rights Reserved.                                    |
  11. ;[]------------------------------------------------------------[]
  12.  
  13.                 __C0__ = 1
  14. INCLUDE         RULES.ASI
  15.  
  16. ;       Segment and Group declarations
  17.  
  18. _TEXT           SEGMENT BYTE PUBLIC 'CODE'
  19.                 ENDS
  20. _FARDATA        SEGMENT PARA PUBLIC 'FAR_DATA'
  21.                 ENDS
  22. _FARBSS         SEGMENT PARA PUBLIC 'FAR_BSS'
  23.                 ENDS
  24. IFNDEF __TINY__
  25. _OVERLAY_       SEGMENT PARA PUBLIC 'OVRINFO'
  26.         ENDS
  27. _1STUB_     SEGMENT PARA PUBLIC 'STUBSEG'
  28.         ENDS
  29. ENDIF
  30. _DATA           SEGMENT PARA PUBLIC 'DATA'
  31.                 ENDS
  32. _INIT_          SEGMENT WORD PUBLIC 'INITDATA'
  33. InitStart       label byte
  34.                 ENDS
  35. _INITEND_       SEGMENT BYTE PUBLIC 'INITDATA'
  36. InitEnd         label byte
  37.                 ENDS
  38. _EXIT_          SEGMENT WORD PUBLIC 'EXITDATA'
  39. ExitStart       label byte
  40.                 ENDS
  41. _EXITEND_       SEGMENT BYTE PUBLIC 'EXITDATA'
  42. ExitEnd         label byte
  43.                 ENDS
  44. _CVTSEG         SEGMENT WORD PUBLIC 'DATA'
  45.                 ENDS
  46. _SCNSEG         SEGMENT WORD PUBLIC 'DATA'
  47.                 ENDS
  48. IFNDEF __HUGE__
  49.   _BSS          SEGMENT WORD PUBLIC 'BSS'
  50.                 ENDS
  51.   _BSSEND       SEGMENT BYTE PUBLIC 'BSSEND'
  52.                 ENDS
  53. ENDIF
  54. IFNDEF __TINY__
  55.   _STACK        SEGMENT STACK 'STACK'
  56.                 ENDS
  57. ENDIF
  58.  
  59.         ASSUME  CS:_TEXT, DS:DGROUP
  60.  
  61. ;       External References
  62.  
  63. extrn       _main:DIST
  64. extrn       _exit:DIST
  65. extrn       __exit:DIST
  66. extrn       __nfile:word
  67. extrn       __setupio:near          ;required!
  68. extrn       __stklen:word
  69. IF LDATA EQ false
  70. extrn       __heaplen:word
  71. ENDIF
  72.  
  73.         SUBTTL  Start Up Code
  74.         PAGE
  75. ;/*                                                     */
  76. ;/*-----------------------------------------------------*/
  77. ;/*                                                     */
  78. ;/*     Start Up Code                                   */
  79. ;/*     -------------                                   */
  80. ;/*                                                     */
  81. ;/*-----------------------------------------------------*/
  82. ;/*                                                     */
  83. PSPHigh         equ     00002h
  84. PSPEnv          equ     0002ch
  85. PSPCmd          equ     00080h
  86.  
  87.                 public  __AHINCR
  88. __AHINCR        equ     1000h
  89.                 public  __AHSHIFT
  90. __AHSHIFT       equ     12
  91.  
  92. IFDEF   __NOFLOAT__
  93. MINSTACK        equ     128     ; minimal stack size in words
  94. ELSE
  95. MINSTACK        equ     256     ; minimal stack size in words
  96. ENDIF
  97. ;
  98. ;       At the start, DS and ES both point to the segment prefix.
  99. ;       SS points to the stack segment except in TINY model where
  100. ;       SS is equal to CS
  101. ;
  102. _TEXT           SEGMENT
  103. IFDEF           __TINY__
  104.                 ORG     100h
  105. ENDIF
  106. STARTX          PROC    NEAR
  107. ;       Save general information, such as :
  108. ;               DGROUP segment address
  109. ;               DOS version number
  110. ;               Program Segment Prefix address
  111. ;               Environment address
  112. ;               Top of far heap
  113.  
  114. IFDEF   __TINY__
  115.                 mov     dx, cs          ; DX = GROUP Segment address
  116. ELSE
  117.                 mov     dx, DGROUP      ; DX = GROUP Segment address
  118. ENDIF
  119. IFNDEF    __BOSS__
  120.                 mov     cs:DGROUP@@, dx ;  __BOSS__
  121. ENDIF
  122.                 mov     ah, 30h
  123.                 int     21h             ; get DOS version number
  124.                 mov     bp, ds:[PSPHigh]; BP = Highest Memory Segment Addr
  125.                 mov     bx, ds:[PSPEnv] ; BX = Environment Segment address
  126.                 mov     ds, dx
  127.                 mov     _version@, ax   ; Keep major and minor version number
  128.                 mov     _psp@, es       ; Keep Program Segment Prefix address
  129.                 mov     _envseg@, bx    ; Keep Environment Segment address
  130.                 mov     word ptr _heaptop@ + 2, bp
  131. ;
  132. ;       Save several vectors and install default divide by zero handler.
  133. ;
  134.                 call    SaveVectors
  135.  
  136. ;===================
  137. ;
  138. ;         IDsoft - Check to make sure that we're running on a 286 or better
  139.  
  140.                 pushf                    ; Save original flags
  141.                 xor        ax,ax            ; Clear AX
  142.                 push    ax
  143.                 popf                    ; Try to pop the 0
  144.                 pushf
  145.                 pop        ax                ; Get results of popping 0 into flags
  146.                 popf                    ; Restore original flags
  147.                 or        ax,ax
  148.                 jns        @@Have286        ; If no sign bit, have a 286
  149.  
  150.                 mov     cx, lgth_no286MSG
  151.                 mov     dx, offset DGROUP: no286MSG
  152.                 jmp        MsgExit3
  153.  
  154. @@Have286:
  155. ;        IDsoft - End of modifications (there's also a code segment string)
  156. ;
  157. ;===================
  158.  
  159. IFDEF    __BOSS__
  160. ; Determine if in real mode
  161.             mov    ax,0FB42h    ; find out if DPMI loader is here
  162.         mov    bx,1        ; get info function
  163.         int    2fh        ;
  164.  
  165.         push    ax        ;
  166.         mov    ax, cs        ; now, save DGROUP
  167.         add    ax, cx        ;
  168.         mov    es, ax        ;
  169.         mov    dx, ds        ;
  170.         mov    es:DGROUP@@, dx     ;
  171.         mov    es:CSalias@@, ax ;
  172.         pop    ax         ;
  173.  
  174. ;        cmp    ax,0001h    ; if not "TRUE"
  175. ;        JNE    InRealMode
  176.  
  177. ; 8 is the value of the alias selector
  178. ; in this system
  179.         MOV    _protected@, cx
  180.         MOV    _hugeincval@, cx
  181.         clc
  182.         mov    ax, cx
  183.         xor    cx, cx
  184.         or    ax, ax
  185.         je    @@gotshift
  186. @@shiftcnt:
  187.         rcr    ax,1
  188.         jc    @@gotshift
  189.         inc    cx
  190.         jmp    @@shiftcnt
  191. @@gotshift:
  192.         mov    _shiftcount@,cx
  193.  
  194. ; used by emulator
  195. ;        PUSH    DS
  196. ;        MOV    AX, 0E502H      ; prot kernel function, get LDT alias
  197. ;        INT    21H
  198. ;        POP    DS
  199. ;        MOV    _LDT@, AX
  200.  
  201. ;        cmp    _protected@,0001h    ; if not "TRUE"
  202. ;        JNE    InRealMode
  203.  
  204.         .286P
  205. IFE    LDATA                    
  206.         mov    dx, ds            ;
  207. ;        LSL    AX, DX            ;
  208. ;        DEC    AX            ;
  209.         MOV    AX, 0FFFEh        ;
  210.         MOV    SP, AX            ;
  211.         MOV    SS, DX            ;
  212. ENDIF                        
  213.         .8086
  214. ;        JMP    BossSkip
  215.  
  216. InRealMode    label    near
  217.  
  218. ENDIF
  219.  
  220. ;       Count the number of environment variables and compute the size.
  221. ;       Each variable is ended by a 0 and a zero-length variable stops
  222. ;       the environment. The environment can NOT be greater than 32k.
  223.  
  224.                 les     di, dword ptr _envLng@
  225.                 mov     ax, di
  226.                 mov     bx, ax
  227.                 mov     cx, 07FFFh      ; Environment cannot be > 32 Kbytes
  228.                 cld
  229. @@EnvLoop:
  230.                 repnz   scasb
  231.                 jcxz    InitFailed      ; Bad environment !!!
  232. IFDEF __BOSS__
  233.                 jmp     InitOK
  234. InitFailed:     jmp     near ptr _abort
  235. InitOK:
  236. ENDIF
  237.      
  238.                 inc     bx              ; BX = Nb environment variables
  239.                 cmp     es:[di], al
  240.                 jne     @@EnvLoop       ; Next variable ...
  241.                 or      ch, 10000000b
  242.                 neg     cx
  243.                 mov     _envLng@, cx    ; Save Environment size
  244.                 mov     cx, dPtrSize / 2
  245.                 shl     bx, cl
  246.                 add     bx, dPtrSize * 4
  247.                 and     bx, not ((dPtrSize * 4) - 1)
  248.                 mov     _envSize@, bx   ; Save Environment Variables Nb.
  249.  
  250. IFNDEF __BOSS__
  251.  
  252. ;       Determine the amount of memory that we need to keep
  253.  
  254. IFDEF _DSSTACK_
  255.                 mov     dx, ds
  256. ELSE
  257.                 mov     dx, ss
  258. ENDIF
  259.                 sub     bp, dx          ; BP = remaining size in paragraphs
  260. IF LDATA
  261.                 mov     di, seg __stklen
  262.                 mov     es, di
  263.                 mov     di, es:__stklen ; DI = Requested stack size
  264. ELSE
  265.                 mov     di, __stklen    ; DI = Requested stack size
  266. ENDIF
  267. ;
  268. ; Make sure that the requested stack size is at least MINSTACK words.
  269. ;
  270.                 cmp     di, 2*MINSTACK  ; requested stack big enough ?
  271.                 jae     AskedStackOK
  272.                 mov     di, 2*MINSTACK  ; no --> use minimal value
  273. IF LDATA
  274.                 mov     es:__stklen, di ; override requested stack size
  275. ELSE
  276.                 mov        __stklen, di ; override requested stack size
  277. ENDIF
  278.  
  279. AskedStackOK    label   near
  280. IFDEF _DSSTACK_
  281.                 add     di, offset DGROUP: edata@
  282.                 jb      InitFailed      ; DATA segment can NOT be > 64 Kbytes
  283. ENDIF
  284. IF LDATA EQ false
  285.                 add     di, __heaplen
  286.                 jb      InitFailed      ; DATA segment can NOT be > 64 Kbytes
  287. ENDIF
  288.                 mov     cl, 4
  289.                 shr     di, cl          ; $$$ Do not destroy CL $$$
  290.                 inc     di              ; DI = DS size in paragraphs
  291.                 cmp     bp, di
  292. IF LDATA EQ false
  293.                 jb      InitFailed      ; Not enough memory
  294.                 cmp     __stklen, 0
  295.                 je      ExpandDS        ; Expand DS up to 64 Kb
  296.                 cmp     __heaplen, 0
  297.                 jne     ExcessOfMemory  ; Much more available than needed
  298. ExpandDS        label   near
  299.                 mov     di, 1000h
  300.                 cmp     bp, di
  301.                 ja      ExcessOfMemory  ; Enough to run the program
  302.                 mov     di, bp
  303.                 jmp     short ExcessOfMemory  ; Enough to run the program
  304. ELSE
  305.                 jnb     ExcessOfMemory  ; Much more available than needed
  306. ENDIF
  307.  
  308. ;       All initialization errors arrive here
  309.  
  310. InitFailed      label   near
  311.                 jmp     near ptr _abort
  312.  
  313. ;       Return to DOS the amount of memory in excess
  314. ;       Set far heap base and pointer
  315.  
  316. ExcessOfMemory  label   near
  317.                 mov     bx, di
  318.                 add     bx, dx
  319.                 mov     word ptr _heapbase@ + 2, bx
  320.                 mov     word ptr _brklvl@ + 2, bx
  321.                 mov     ax, _psp@
  322.                 sub     bx, ax          ; BX = Number of paragraphs to keep
  323.                 mov     es, ax          ; ES = Program Segment Prefix address
  324.                 mov     ah, 04Ah
  325.                 push    di              ; preserve DI
  326.                 int     021h            ; this call clobbers SI,DI,BP !!!!!!
  327.                 pop     di              ; restore  DI
  328.  
  329.                 shl     di, cl          ; $$$ CX is still equal to 4 $$$
  330.  
  331.                 cli                     ; req'd for pre-1983 88/86s
  332.                 mov     ss, dx          ; Set the program stack
  333.                 mov     sp, di
  334.                 sti
  335.  
  336. IFNDEF _DSSTACK_
  337.                 mov     ax, seg __stklen
  338.                 mov     es, ax
  339.                 mov     es:__stklen, di ; If separate stack segment, save size
  340. ENDIF
  341.  
  342. ENDIF ; __BOSS__
  343.  
  344. IFNDEF  __HUGE__
  345.  
  346. ;       Reset uninitialized data area
  347.  
  348.                 xor     ax, ax
  349.                 mov     es, cs:DGROUP@@
  350.                 mov     di, offset DGROUP: bdata@
  351.                 mov     cx, offset DGROUP: edata@
  352.                 sub     cx, di
  353.                 cld
  354.                 rep     stosb
  355. ENDIF
  356.  
  357. ;   If default number of file handles have changed then tell DOS
  358.                 cmp     __nfile, 20
  359.                 jbe     @@NoChange
  360.  
  361.                 cmp     _osmajor@, 3   ; Check for >= DOS 3.3
  362.                 jb      @@NoChange
  363.                 ja      @@DoChange
  364.                 cmp     _osminor@, 1Eh
  365.                 jb      @@NoChange
  366. @@DoChange:
  367.                 mov     ax, 5801h      ; Set last fit allocation
  368.                 mov     bx, 2
  369.                 int     21h
  370.                 jc      @@BadInit
  371.  
  372.                 mov     ah, 67h        ; Expand handle table
  373.                 mov     bx, __nfile
  374.                 int     21h
  375.                 jc      @@BadInit
  376.  
  377.                 mov     ah, 48h        ; Allocate 16 bytes to find new
  378.                 mov     bx, 1          ;   top of memory address
  379.                 int     21h
  380.                 jc      @@BadInit
  381.                 inc     ax             ; Adjust address to point after block
  382.                 mov     word ptr _heaptop@ + 2, ax
  383.  
  384.                 dec     ax             ; Change back and release block
  385.                 mov     es, ax
  386.                 mov     ah, 49h
  387.                 int     21h
  388.                 jc      @@BadInit
  389.  
  390.                 mov     ax, 5801h      ; Set first fit allocation
  391.                 mov     bx, 0
  392.                 int     21h
  393.                 jnc     @@NoChange
  394.  
  395. @@BadInit:      jmp near ptr _abort
  396.  
  397. @@NoChange:
  398.  
  399. ;       Prepare main arguments
  400.  
  401.                 mov     ah, 0
  402.                 int     1ah                     ; get current BIOS time in ticks
  403.                 mov     word ptr _StartTime@,dx ; save it for clock() fn
  404.                 mov     word ptr _StartTime@+2,cx
  405.         or    al,al            ; was midnight flag set?
  406.         jz    @@NotMidnight
  407.         mov    ax,40h            ; set BIOS midnight flag
  408.         mov    es,ax            ;  at 40:70
  409.         mov    bx,70h
  410.         mov    byte ptr es:[bx],1
  411.             
  412. @@NotMidnight:
  413.                 xor     bp,bp                   ; set BP to 0 for overlay mgr
  414.  
  415.                 mov     es, cs:DGROUP@@
  416.                 mov     si,offset DGROUP:InitStart      ;si = start of table
  417.                 mov     di,offset DGROUP:InitEnd        ;di = end of table
  418.                 call    StartExit
  419.  
  420. ;       ExitCode = main(argc,argv,envp);
  421.  
  422. IF      LDATA
  423.                 push    word ptr __C0environ+2
  424.                 push    word ptr __C0environ
  425.                 push    word ptr __C0argv+2
  426.                 push    word ptr __C0argv
  427. ELSE
  428.                 push    word ptr __C0environ
  429.                 push    word ptr __C0argv
  430. ENDIF
  431.                 push    __C0argc
  432.                 call    _main
  433.  
  434. ;       Flush and close streams and files
  435.  
  436.                 push    ax
  437.                 call    _exit
  438.  
  439. ;---------------------------------------------------------------------------
  440. ;       _cleanup()      call all #pragma exit cleanup routines.
  441. ;       _checknull()    check for null pointer zapping copyright message
  442. ;       _terminate(int) exit program with error code
  443. ;
  444. ;       These functions are called by exit(), _exit(), _cexit(),
  445. ;       and _c_exit().
  446. ;---------------------------------------------------------------------------
  447.  
  448. ;       Call cleanup routines
  449.  
  450. __cleanup       PROC    DIST
  451.                 PUBLIC  __cleanup
  452.  
  453.                 mov     es, cs:DGROUP@@
  454.                 push    si
  455.                 push    di
  456.                 mov     si,offset DGROUP:ExitStart
  457.                 mov     di,offset DGROUP:ExitEnd
  458.                 call    StartExit
  459.                 pop     di
  460.                 pop     si
  461.                 ret
  462. __cleanup       ENDP
  463.  
  464. ;       Check for null pointers before exit
  465.  
  466. __checknull     PROC    DIST
  467.                 PUBLIC  __checknull
  468.  
  469. IF      LDATA EQ false
  470.   IFNDEF  __TINY__
  471.                 push    si
  472.                 push    di
  473.                 mov     es, cs:DGROUP@@
  474.                 xor     ax, ax
  475.                 mov     si, ax
  476.                 mov     cx, lgth_CopyRight
  477. ComputeChecksum label   near
  478.                 add     al, es:[si]
  479.                 adc     ah, 0
  480.                 inc     si
  481.                 loop    ComputeChecksum
  482.                 sub     ax, CheckSum
  483.                 jz      @@SumOk
  484.                 mov     cx, lgth_NullCheck
  485.                 mov     dx, offset DGROUP: NullCheck
  486.                 call    ErrorDisplay
  487. @@SumOK:        pop     di
  488.                 pop     si
  489.   ENDIF
  490. ENDIF
  491.                 ret
  492. __checknull     ENDP
  493.  
  494. ;       Exit to DOS
  495.  
  496. __terminate     PROC    DIST
  497.                 PUBLIC  __terminate
  498.                 mov     bp,sp
  499.                 mov     ah,4Ch
  500.                 mov     al,[bp+cPtrSize]
  501.                 int     21h                     ; Exit to DOS
  502. __terminate     ENDP
  503.  
  504. STARTX          ENDP
  505.  
  506.         SUBTTL  Vector save/restore & default Zero divide routines
  507.         PAGE
  508. ;[]------------------------------------------------------------[]
  509. ;|                                                              |
  510. ;| Interrupt Save/Restore routines and default divide by zero   |
  511. ;| handler.                                                     |
  512. ;|                                                              |
  513. ;[]------------------------------------------------------------[]
  514.  
  515. ZeroDivision    PROC    FAR
  516.                 mov     cx, lgth_ZeroDivMSG
  517.                 mov     dx, offset DGROUP: ZeroDivMSG
  518.                 jmp     MsgExit3
  519. ZeroDivision    ENDP
  520.  
  521. ;--------------------------------------------------------------------------
  522. ;       savevectors()
  523. ;
  524. ;       Save vectors for 0, 4, 5 & 6 interrupts.  This is for extended
  525. ;       signal()/raise() support as the signal functions can steal these
  526. ;       vectors during runtime.
  527. ;--------------------------------------------------------------------------
  528. SaveVectors     PROC    NEAR
  529.                 push    ds
  530. ; Save INT 0
  531.                 mov     ax, 3500h
  532.                 int     021h
  533.                 mov     word ptr _Int0Vector@, bx
  534.                 mov     word ptr _Int0Vector@+2, es
  535. ; Save INT 4
  536.                 mov     ax, 3504h
  537.                 int     021h
  538.                 mov     word ptr _Int4Vector@, bx
  539.                 mov     word ptr _Int4Vector@+2, es
  540. ; Save INT 5
  541.                 mov     ax, 3505h
  542.                 int     021h
  543.                 mov     word ptr _Int5Vector@, bx
  544.                 mov     word ptr _Int5Vector@+2, es
  545. ; Save INT 6
  546.                 mov     ax, 3506h
  547.                 int     021h
  548.                 mov     word ptr _Int6Vector@, bx
  549.                 mov     word ptr _Int6Vector@+2, es
  550. ;
  551. ;       Install default divide by zero handler.
  552. ;
  553.                 mov     ax, 2500h
  554.                 mov     dx, cs
  555.                 mov     ds, dx
  556.                 mov     dx, offset ZeroDivision
  557.                 int     21h
  558.  
  559.                 pop     ds
  560.                 ret
  561. SaveVectors     ENDP
  562.  
  563. ;--------------------------------------------------------------------------
  564. ;       _restorezero() puts back all the vectors that SaveVectors took.
  565. ;
  566. ;NOTE : TSRs must BE AWARE that signal() functions which take these 
  567. ;       vectors will be deactivated if the keep() function is executed.
  568. ;       If a TSR wants to use the signal functions when it is active it 
  569. ;       will have to save/restore these vectors itself when activated and
  570. ;       deactivated.
  571. ;--------------------------------------------------------------------------
  572. __restorezero   PROC    DIST
  573.                 PUBLIC  __restorezero
  574. IFDEF   __HUGE__
  575.                 push    ds
  576.                 mov     ds, cs: DGROUP@@
  577. ENDIF
  578.                 push    ds
  579.                 mov     ax, 2500h
  580.                 lds     dx, _Int0Vector@
  581.                 int     21h
  582.                 pop     ds
  583.  
  584.                 push    ds
  585.                 mov     ax, 2504h
  586.                 lds     dx, _Int4Vector@
  587.                 int     21h
  588.                 pop     ds
  589.  
  590.                 push    ds
  591.                 mov     ax, 2505h
  592.                 lds     dx, _Int5Vector@
  593.                 int     21h
  594.                 pop     ds
  595.  
  596. IFNDEF   __HUGE__
  597.                 push    ds
  598. ENDIF
  599.                 mov     ax, 2506h
  600.                 lds     dx, _Int6Vector@
  601.                 int     21h
  602.                 pop     ds
  603.  
  604.                 ret
  605.                 ENDP
  606.  
  607. ;------------------------------------------------------------------
  608. ;  Loop through a startup/exit (SE) table, 
  609. ;  calling functions in order of priority.
  610. ;  ES:SI is assumed to point to the beginning of the SE table
  611. ;  ES:DI is assumed to point to the end of the SE table
  612. ;  First 64 priorities are reserved by Borland
  613. ;------------------------------------------------------------------
  614. PNEAR           EQU     0
  615. PFAR            EQU     1
  616. NOTUSED         EQU     0ffh
  617.  
  618. SE              STRUC
  619. calltype        db      ?                       ; 0=near,1=far,ff=not used
  620. priority        db      ?                       ; 0=highest,ff=lowest
  621. addrlow         dw      ?
  622. addrhigh        dw      ?
  623. SE              ENDS
  624.  
  625. StartExit       proc near
  626. @@Start:        cmp     si,offset DGROUP:InitStart      ; startup or exit?
  627.                 je      @@StartLow              ; it's startup
  628.                 xor     ah,ah                   ; start with high priority
  629.                 jmp     short @@SaveEnd
  630. @@StartLow:     mov     ah,0ffh                 ;start with lowest priority
  631. @@SaveEnd:      mov     dx,di                   ;set sentinel to end of table
  632.                 mov     bx,si                   ;bx = start of table
  633.  
  634. @@TopOfTable:   cmp     bx,di                   ;and the end of the table?
  635.                 je      @@EndOfTable            ;yes, exit the loop
  636.                 cmp     es:[bx.calltype],NOTUSED;check the call type
  637.                 je      @@Next
  638.                 cmp     si,offset DGROUP:InitStart      ; startup or exit?
  639.                 je      @@CompareHigh           ; it's startup
  640.                 cmp     ah,es:[bx.priority]     ; it's exit
  641.                 jmp     short @@CheckPrior      ; if priority too low, skip
  642. @@CompareHigh:  cmp     es:[bx.priority],ah     ;check the priority
  643. @@CheckPrior:   ja      @@Next                  ;too high?  skip
  644.                 mov     ah,es:[bx.priority]     ;keep priority
  645.                 mov     dx,bx                   ;keep index in dx
  646. @@Next:         add     bx,SIZE SE              ;bx = next item in table
  647.                 jmp     @@TopOfTable
  648.  
  649. @@EndOfTable:   cmp     dx,di                   ;did we exhaust the table?
  650.                 je      @@Done                  ;yes, quit
  651.                 mov     bx,dx                   ;bx = highest priority item
  652.                 cmp     es:[bx.calltype],PNEAR  ;is it near or far?
  653.                 mov     es:[bx.calltype],NOTUSED;wipe the call type
  654.                 push    es                      ;save es
  655.                 je      @@NearCall
  656.  
  657. @@FarCall:      call    DWORD PTR es:[bx.addrlow]
  658.                 pop     es                      ;restore es
  659.                 jmp     short @@Start
  660.  
  661. @@NearCall:     call    WORD PTR es:[bx.addrlow]
  662.                 pop     es                      ;restore es
  663.                 jmp     short @@Start
  664.  
  665. @@Done:         ret
  666.                 endp
  667.  
  668. ;------------------------------------------------------------------
  669.  
  670. ErrorDisplay    PROC    NEAR
  671.                 mov     ah, 040h
  672.                 mov     bx, 2
  673.                 int     021h
  674.                 ret
  675. ErrorDisplay    ENDP
  676.  
  677. _abort          PROC    DIST
  678.                 PUBLIC  _abort
  679.                 mov     cx, lgth_abortMSG
  680.                 mov     dx, offset DGROUP: abortMSG
  681. MsgExit3        label   near
  682.                 mov     ds, cs: DGROUP@@
  683.                 call    ErrorDisplay
  684. CallExit3       label   near
  685.                 mov     ax, 3
  686.                 push    ax
  687.                 call    __exit           ; _exit(3);
  688.                 ENDP
  689.  
  690. ; The DGROUP@ variable is used to reload DS with DGROUP
  691.  
  692. PubSym@         DGROUP@, <dw    ?>, __PASCAL__
  693.  
  694. IFDEF    __BOSS__
  695. PubSym@        CSalias@,<dw    ?>, __PASCAL__
  696. ENDIF
  697.  
  698.  
  699. ; __MMODEL is used to determine the memory model or the default
  700. ; pointer types at run time.
  701.  
  702.                 public __MMODEL
  703. __MMODEL        dw      MMODEL
  704.  
  705. _TEXT           ENDS
  706.  
  707.                 SUBTTL  Start Up Data Area
  708.                 PAGE
  709. ;[]------------------------------------------------------------[]
  710. ;|      Start Up Data Area                                      |
  711. ;|                                                              |
  712. ;|      WARNING         Do not move any variables in the data   |
  713. ;|                      segment unless you're absolutely sure   |
  714. ;|                      that it does not matter.                |
  715. ;[]------------------------------------------------------------[]
  716.  
  717. _DATA           SEGMENT
  718.  
  719. ;       Magic symbol used by the debug info to locate the data segment
  720.                 public DATASEG@
  721. DATASEG@        label   byte
  722.  
  723. ;       The CopyRight string must NOT be moved or changed without
  724. ;       changing the null pointer check logic
  725.  
  726. CopyRight       db      4 dup(0)
  727.                 db      'Borland C++ - Copyright 1991 Borland Intl.',0
  728. lgth_CopyRight  equ     $ - CopyRight
  729.  
  730. IF      LDATA EQ false
  731. IFNDEF  __TINY__
  732. CheckSum        equ     00D5Ch
  733. NullCheck       db      'Null pointer assignment', 13, 10
  734. lgth_NullCheck  equ     $ - NullCheck
  735. ENDIF
  736. ENDIF
  737.  
  738. ZeroDivMSG      db      'Divide error', 13, 10
  739. lgth_ZeroDivMSG equ     $ - ZeroDivMSG
  740.  
  741. abortMSG        db      'Abnormal program termination', 13, 10
  742. lgth_abortMSG   equ     $ - abortMSG
  743.  
  744. ; JAB - Added string for no 286
  745. no286MSG        db        'Sorry, this program requires a 286 or better.', 13, 10
  746. lgth_no286MSG    equ        $ - no286MSG
  747. ; JAB - End of modifications
  748.  
  749. ;
  750. ;                       Interrupt vector save areas
  751. ;       
  752. ;       Interrupt vectors 0,4,5 & 6 are saved at startup and then restored
  753. ;       when the program terminates.  The signal/raise functions might
  754. ;       steal these vectors during execution.
  755. ;
  756. ;       Note: These vectors save area must not be altered 
  757. ;             without changing the save/restore logic.
  758. ;
  759. PubSym@         _Int0Vector     <dd     0>,             __CDECL__
  760. PubSym@         _Int4Vector     <dd     0>,             __CDECL__
  761. PubSym@         _Int5Vector     <dd     0>,             __CDECL__
  762. PubSym@         _Int6Vector     <dd     0>,             __CDECL__
  763. ;
  764. ;                       Miscellaneous variables
  765. ;       
  766. PubSym@         _C0argc,        <dw     0>,             __CDECL__
  767. dPtrPub@        _C0argv,        0,                      __CDECL__
  768. dPtrPub@        _C0environ,     0,                      __CDECL__
  769. PubSym@         _envLng,        <dw     0>,             __CDECL__
  770. PubSym@         _envseg,        <dw     0>,             __CDECL__
  771. PubSym@         _envSize,       <dw     0>,             __CDECL__
  772. PubSym@         _psp,           <dw     0>,             __CDECL__
  773. PubSym@         _version,       <label word>,           __CDECL__
  774. PubSym@         _osversion,     <label word>,           __CDECL__
  775. PubSym@         _osmajor,       <db     0>,             __CDECL__
  776. PubSym@         _osminor,       <db     0>,             __CDECL__
  777. PubSym@         errno,          <dw     0>,             __CDECL__
  778. PubSym@         _StartTime,     <dw   0,0>,             __CDECL__
  779.  
  780.  
  781. IFDEF __BOSS__
  782. PubSym@        _protected    <dw    0>,        __CDECL__
  783. PubSym@     _shiftcount,    <dw    12>,        __CDECL__
  784. PubSym@     _hugeincval,    <dw    1000h>,        __CDECL__
  785. ENDIF
  786.  
  787. ;       Memory management variables
  788.  
  789. IF      LDATA EQ false
  790. PubSym@         __heapbase,     <dw   DGROUP:edata@>,   __CDECL__
  791. ENDIF
  792. IFNDEF __HUGE__
  793. PubSym@         __brklvl,       <dw   DGROUP:edata@>,   __CDECL__
  794. ENDIF
  795. PubSym@         _heapbase,      <dd   0>,       __CDECL__
  796. PubSym@         _brklvl,        <dd   0>,       __CDECL__
  797. PubSym@         _heaptop,       <dd   0>,       __CDECL__
  798.  
  799. ;       If stack in DS and Large data model then override location of __emu
  800.  
  801. IFDEF   _DSSTACK_
  802. IF      LDATA
  803. public  __emu
  804. __emu   db      044h    DUP (0)
  805.         db      0CCh    DUP (?)
  806. ENDIF
  807. ENDIF
  808.  
  809. _DATA           ENDS
  810.  
  811.  
  812. _CVTSEG         SEGMENT
  813. PubSym@         _RealCvtVector, <label  word>,  __CDECL__
  814.                 ENDS
  815.  
  816. _SCNSEG         SEGMENT
  817. PubSym@         _ScanTodVector,  <label word>,  __CDECL__
  818.                 ENDS
  819.  
  820. IFNDEF __HUGE__
  821. _BSS            SEGMENT
  822. bdata@          label   byte
  823.                 ENDS
  824.  
  825. _BSSEND         SEGMENT
  826. edata@          label   byte
  827.                 ENDS
  828. ENDIF
  829.  
  830. IFNDEF __TINY__
  831. _STACK          SEGMENT
  832. IFDEF __BOSS__
  833.     IF LDATA
  834.                 db      1400h dup(?)
  835.     ENDIF
  836. ELSE
  837.                 db      128 dup(?)               ;minimum stack size
  838. ENDIF  ; __BOSS__
  839.                 ENDS
  840. ENDIF  ; __TINY__
  841.                 END     STARTX
  842.