⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c0.asm

📁 wolf3d游戏源代码!非常不错! 与大家共享! 如果大家又相关资料还请多多上传!
💻 ASM
📖 第 1 页 / 共 2 页
字号:
        NAME    c0
        PAGE    60,132
        LOCALS
;[]------------------------------------------------------------[]
;|      C0.ASM -- Start Up Code                                 |
;|                                                              |
;|      Turbo C++ Run Time Library                              |
;|                                                              |
;|      Copyright (c) 1987, 1991 by Borland International Inc.  |
;|      All Rights Reserved.                                    |
;[]------------------------------------------------------------[]

                __C0__ = 1
INCLUDE         RULES.ASI

;       Segment and Group declarations

_TEXT           SEGMENT BYTE PUBLIC 'CODE'
                ENDS
_FARDATA        SEGMENT PARA PUBLIC 'FAR_DATA'
                ENDS
_FARBSS         SEGMENT PARA PUBLIC 'FAR_BSS'
                ENDS
IFNDEF __TINY__
_OVERLAY_       SEGMENT PARA PUBLIC 'OVRINFO'
        ENDS
_1STUB_     SEGMENT PARA PUBLIC 'STUBSEG'
        ENDS
ENDIF
_DATA           SEGMENT PARA PUBLIC 'DATA'
                ENDS
_INIT_          SEGMENT WORD PUBLIC 'INITDATA'
InitStart       label byte
                ENDS
_INITEND_       SEGMENT BYTE PUBLIC 'INITDATA'
InitEnd         label byte
                ENDS
_EXIT_          SEGMENT WORD PUBLIC 'EXITDATA'
ExitStart       label byte
                ENDS
_EXITEND_       SEGMENT BYTE PUBLIC 'EXITDATA'
ExitEnd         label byte
                ENDS
_CVTSEG         SEGMENT WORD PUBLIC 'DATA'
                ENDS
_SCNSEG         SEGMENT WORD PUBLIC 'DATA'
                ENDS
IFNDEF __HUGE__
  _BSS          SEGMENT WORD PUBLIC 'BSS'
                ENDS
  _BSSEND       SEGMENT BYTE PUBLIC 'BSSEND'
                ENDS
ENDIF
IFNDEF __TINY__
  _STACK        SEGMENT STACK 'STACK'
                ENDS
ENDIF

        ASSUME  CS:_TEXT, DS:DGROUP

;       External References

extrn       _main:DIST
extrn       _exit:DIST
extrn       __exit:DIST
extrn       __nfile:word
extrn       __setupio:near          ;required!
extrn       __stklen:word
IF LDATA EQ false
extrn       __heaplen:word
ENDIF

        SUBTTL  Start Up Code
        PAGE
;/*                                                     */
;/*-----------------------------------------------------*/
;/*                                                     */
;/*     Start Up Code                                   */
;/*     -------------                                   */
;/*                                                     */
;/*-----------------------------------------------------*/
;/*                                                     */
PSPHigh         equ     00002h
PSPEnv          equ     0002ch
PSPCmd          equ     00080h

                public  __AHINCR
__AHINCR        equ     1000h
                public  __AHSHIFT
__AHSHIFT       equ     12

IFDEF   __NOFLOAT__
MINSTACK        equ     128     ; minimal stack size in words
ELSE
MINSTACK        equ     256     ; minimal stack size in words
ENDIF
;
;       At the start, DS and ES both point to the segment prefix.
;       SS points to the stack segment except in TINY model where
;       SS is equal to CS
;
_TEXT           SEGMENT
IFDEF           __TINY__
                ORG     100h
ENDIF
STARTX          PROC    NEAR
;       Save general information, such as :
;               DGROUP segment address
;               DOS version number
;               Program Segment Prefix address
;               Environment address
;               Top of far heap

IFDEF   __TINY__
				mov     dx, cs          ; DX = GROUP Segment address
ELSE
				mov     dx, DGROUP      ; DX = GROUP Segment address
ENDIF
IFNDEF	__BOSS__
				mov     cs:DGROUP@@, dx ;  __BOSS__
ENDIF
				mov     ah, 30h
				int     21h             ; get DOS version number
				mov     bp, ds:[PSPHigh]; BP = Highest Memory Segment Addr
				mov     bx, ds:[PSPEnv] ; BX = Environment Segment address
				mov     ds, dx
				mov     _version@, ax   ; Keep major and minor version number
				mov     _psp@, es       ; Keep Program Segment Prefix address
				mov     _envseg@, bx    ; Keep Environment Segment address
				mov     word ptr _heaptop@ + 2, bp
;
;       Save several vectors and install default divide by zero handler.
;
				call    SaveVectors

;===================
;
; 		IDsoft - Check to make sure that we're running on a 286 or better

				pushf					; Save original flags
				xor		ax,ax			; Clear AX
				push	ax
				popf					; Try to pop the 0
				pushf
				pop		ax				; Get results of popping 0 into flags
				popf					; Restore original flags
				or		ax,ax
				jns		@@Have286		; If no sign bit, have a 286

				mov     cx, lgth_no286MSG
				mov     dx, offset DGROUP: no286MSG
				jmp		MsgExit3

@@Have286:
;		IDsoft - End of modifications (there's also a code segment string)
;
;===================

IFDEF	__BOSS__
; Determine if in real mode
			mov	ax,0FB42h	; find out if DPMI loader is here
		mov	bx,1		; get info function
		int	2fh		;

		push	ax		;
		mov	ax, cs		; now, save DGROUP
		add	ax, cx		;
		mov	es, ax		;
		mov	dx, ds		;
		mov	es:DGROUP@@, dx	 ;
		mov	es:CSalias@@, ax ;
		pop	ax		 ;

;		cmp	ax,0001h	; if not "TRUE"
;		JNE	InRealMode

; 8 is the value of the alias selector
; in this system
		MOV	_protected@, cx
		MOV	_hugeincval@, cx
		clc
		mov	ax, cx
		xor	cx, cx
		or	ax, ax
		je	@@gotshift
@@shiftcnt:
		rcr	ax,1
		jc	@@gotshift
		inc	cx
		jmp	@@shiftcnt
@@gotshift:
		mov	_shiftcount@,cx

; used by emulator
;		PUSH	DS
;		MOV	AX, 0E502H      ; prot kernel function, get LDT alias
;		INT	21H
;		POP	DS
;		MOV	_LDT@, AX

;		cmp	_protected@,0001h	; if not "TRUE"
;		JNE	InRealMode

		.286P
IFE	LDATA					
		mov	dx, ds			;
;		LSL	AX, DX			;
;		DEC	AX			;
		MOV	AX, 0FFFEh		;
		MOV	SP, AX			;
		MOV	SS, DX			;
ENDIF						
		.8086
;		JMP	BossSkip

InRealMode	label	near

ENDIF

;       Count the number of environment variables and compute the size.
;       Each variable is ended by a 0 and a zero-length variable stops
;       the environment. The environment can NOT be greater than 32k.

                les     di, dword ptr _envLng@
                mov     ax, di
                mov     bx, ax
                mov     cx, 07FFFh      ; Environment cannot be > 32 Kbytes
                cld
@@EnvLoop:
                repnz   scasb
                jcxz    InitFailed      ; Bad environment !!!
IFDEF __BOSS__
                jmp     InitOK
InitFailed:     jmp     near ptr _abort
InitOK:
ENDIF
     
                inc     bx              ; BX = Nb environment variables
                cmp     es:[di], al
                jne     @@EnvLoop       ; Next variable ...
                or      ch, 10000000b
                neg     cx
                mov     _envLng@, cx    ; Save Environment size
                mov     cx, dPtrSize / 2
                shl     bx, cl
                add     bx, dPtrSize * 4
                and     bx, not ((dPtrSize * 4) - 1)
                mov     _envSize@, bx   ; Save Environment Variables Nb.

IFNDEF __BOSS__

;       Determine the amount of memory that we need to keep

IFDEF _DSSTACK_
                mov     dx, ds
ELSE
                mov     dx, ss
ENDIF
                sub     bp, dx          ; BP = remaining size in paragraphs
IF LDATA
                mov     di, seg __stklen
                mov     es, di
                mov     di, es:__stklen ; DI = Requested stack size
ELSE
                mov     di, __stklen    ; DI = Requested stack size
ENDIF
;
; Make sure that the requested stack size is at least MINSTACK words.
;
                cmp     di, 2*MINSTACK  ; requested stack big enough ?
                jae     AskedStackOK
                mov     di, 2*MINSTACK  ; no --> use minimal value
IF LDATA
                mov     es:__stklen, di ; override requested stack size
ELSE
                mov        __stklen, di ; override requested stack size
ENDIF

AskedStackOK    label   near
IFDEF _DSSTACK_
                add     di, offset DGROUP: edata@
                jb      InitFailed      ; DATA segment can NOT be > 64 Kbytes
ENDIF
IF LDATA EQ false
                add     di, __heaplen
                jb      InitFailed      ; DATA segment can NOT be > 64 Kbytes
ENDIF
                mov     cl, 4
                shr     di, cl          ; $$$ Do not destroy CL $$$
                inc     di              ; DI = DS size in paragraphs
                cmp     bp, di
IF LDATA EQ false
                jb      InitFailed      ; Not enough memory
                cmp     __stklen, 0
                je      ExpandDS        ; Expand DS up to 64 Kb
                cmp     __heaplen, 0
                jne     ExcessOfMemory  ; Much more available than needed
ExpandDS        label   near
                mov     di, 1000h
                cmp     bp, di
                ja      ExcessOfMemory  ; Enough to run the program
                mov     di, bp
                jmp     short ExcessOfMemory  ; Enough to run the program
ELSE
                jnb     ExcessOfMemory  ; Much more available than needed
ENDIF

;       All initialization errors arrive here

InitFailed      label   near
                jmp     near ptr _abort

;       Return to DOS the amount of memory in excess
;       Set far heap base and pointer

ExcessOfMemory  label   near
                mov     bx, di
                add     bx, dx
                mov     word ptr _heapbase@ + 2, bx
                mov     word ptr _brklvl@ + 2, bx
                mov     ax, _psp@
                sub     bx, ax          ; BX = Number of paragraphs to keep
                mov     es, ax          ; ES = Program Segment Prefix address
                mov     ah, 04Ah
                push    di              ; preserve DI
                int     021h            ; this call clobbers SI,DI,BP !!!!!!
                pop     di              ; restore  DI

                shl     di, cl          ; $$$ CX is still equal to 4 $$$

                cli                     ; req'd for pre-1983 88/86s
                mov     ss, dx          ; Set the program stack
                mov     sp, di
                sti

IFNDEF _DSSTACK_
                mov     ax, seg __stklen
                mov     es, ax
                mov     es:__stklen, di ; If separate stack segment, save size
ENDIF

ENDIF ; __BOSS__

IFNDEF  __HUGE__

;       Reset uninitialized data area

                xor     ax, ax
                mov     es, cs:DGROUP@@
                mov     di, offset DGROUP: bdata@
                mov     cx, offset DGROUP: edata@
                sub     cx, di
                cld
                rep     stosb
ENDIF

;   If default number of file handles have changed then tell DOS
                cmp     __nfile, 20
                jbe     @@NoChange

                cmp     _osmajor@, 3   ; Check for >= DOS 3.3
                jb      @@NoChange
                ja      @@DoChange
                cmp     _osminor@, 1Eh
                jb      @@NoChange
@@DoChange:
                mov     ax, 5801h      ; Set last fit allocation
                mov     bx, 2
                int     21h
                jc      @@BadInit

                mov     ah, 67h        ; Expand handle table
                mov     bx, __nfile
                int     21h
                jc      @@BadInit

                mov     ah, 48h        ; Allocate 16 bytes to find new
                mov     bx, 1          ;   top of memory address
                int     21h
                jc      @@BadInit
                inc     ax             ; Adjust address to point after block
                mov     word ptr _heaptop@ + 2, ax

                dec     ax             ; Change back and release block
                mov     es, ax
                mov     ah, 49h
                int     21h
                jc      @@BadInit

                mov     ax, 5801h      ; Set first fit allocation
                mov     bx, 0
                int     21h
                jnc     @@NoChange

@@BadInit:      jmp near ptr _abort

@@NoChange:

;       Prepare main arguments

                mov     ah, 0
                int     1ah                     ; get current BIOS time in ticks
                mov     word ptr _StartTime@,dx ; save it for clock() fn
                mov     word ptr _StartTime@+2,cx
		or	al,al			; was midnight flag set?
		jz	@@NotMidnight
		mov	ax,40h			; set BIOS midnight flag
		mov	es,ax			;  at 40:70
		mov	bx,70h
		mov	byte ptr es:[bx],1
			
@@NotMidnight:
                xor     bp,bp                   ; set BP to 0 for overlay mgr

                mov     es, cs:DGROUP@@
                mov     si,offset DGROUP:InitStart      ;si = start of table
                mov     di,offset DGROUP:InitEnd        ;di = end of table
                call    StartExit

;       ExitCode = main(argc,argv,envp);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -