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

📄 dosintrf.asm

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com )
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;as published by the Free Software Foundation; either
;version 2 of the License, or (at your option) any later
;version.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

%include "macros.mac"

EXTSYM dssel, selcA000, selcB800, selc0040, previdmode, DosExit, ZFileSystemInit
EXTSYM getcmdline,GUIRestoreVars,getcfg,obtaindir,ConvertJoyMap,tparms
EXTSYM preparedir,getblaster,Force8b,SBHDMA
EXTSYM ccmdline
EXTSYM InitDir,InitDrive
EXTSYM DOScreatenewcfg,ExecGUISaveVars
EXTSYM allocptr
EXTSYM FPUCopy
EXTSYM ZOpenFile,ZOpenMode,CurrentHandle,ZFileSeek,ZOpenFileName,ZFileSeekMode
EXTSYM ZFileSeekPos,ZFileSeekHandle
EXTSYM ZFileWriteHandle,ZFileWriteSize,ZFileWriteBlock,ZFileWrite
EXTSYM ZFileReadHandle,ZFileReadSize,ZFileReadBlock,ZFileRead
EXTSYM ZFileDelFName,ZFileDelete
EXTSYM ZCloseFileHandle,ZCloseFile
EXTSYM ZFileTellHandle,ZFileTell
EXTSYM GetTime
EXTSYM GetDate
EXTSYM ZFFTimeFName,ZFTime,ZFDate,ZFileGetFTime
EXTSYM pressed
EXTSYM ZFileMKDir,ZFileCHDir,ZFileRMDir,CHPath,MKPath,RMPath
EXTSYM ZFileGetDir,DriveNumber,DirName
EXTSYM DTALoc,DTALocPos,ZFileFindATTRIB,ZFileFindFirst,ZFileFindNext,ZFileFindPATH
EXTSYM oldhand9s,oldhand9o,interror,oldhand8s,oldhand8o,oldhandSBs,oldhandSBo
EXTSYM NoSoundReinit,soundon,DSPDisable,SBInt,NoSoundReinit,PICMaskP,SBIrq
EXTSYM SBHandler,InitSB,handler8h,handler9h,init60hz,Interror,init18_2hz,DeInitSPC
EXTSYM GUIinit36_4hz,GUIoldhand9s,GUIoldhand9o,GUIoldhand8s,GUIoldhand8o
EXTSYM GUIhandler9h,GUIhandler8h,GUIinit18_2hz
EXTSYM dosmakepal
EXTSYM doschangepal
EXTSYM dosinitvideo, dosinitvideo2
EXTSYM DosDrawScreen,dosvidpastecopyscr,cvidmode,vidbuffer,GUICPC,DosDrawScreenB
EXTSYM DOSClearScreen
EXTSYM DosUpdateDevices
EXTSYM DOSJoyRead
EXTSYM pl1contrl,pl2contrl,pl3contrl,pl4contrl,pl5contrl
EXTSYM BufferSizeW,BufferSizeB,ProcessSoundBuffer
EXTSYM TCPIPPortNum
;    EXTSYM InitTCP
;    EXTSYM StartServer
;    EXTSYM InitTCP
EXTSYM GUINetTextk2
;    EXTSYM ConnectServer
;    EXTSYM SendData
;    EXTSYM GetData
;    EXTSYM DeInitTCP
;    EXTSYM StopServer
;    EXTSYM Disconnect








; NOTE: For timing, Game60hzcall should be called at 50hz or 60hz (depending
;   on romispal) after a call to InitPreGame and before DeInitPostGame are
;   made.  GUI36hzcall should be called at 36hz after a call GUIInit and
;   before GUIDeInit.



SECTION .data
NEWSYM OSPort, db 0      ; 0 = DOS (C), 1 = DOS (ASM), 2 = Linux, 3 = Win95
SECTION .text

NEWSYM StartUp
    mov    ax,901h             ;enable interrupts
    int    31h
    mov ax,ds
    mov [dssel],ax
    mov bx,0A000h
    call findselec
    mov [selcA000],ax
    mov bx,0B800h
    call findselec
    mov [selcB800],ax
    mov bx,0040h
    call findselec
    mov [selc0040],ax
    ; get previous video mode
    xor ecx,ecx
    push es
    mov ax,[selc0040]
    mov es,ax
    mov al,[es:49h]
    mov [previdmode],al
    pop es

    ; Get base address
    mov ax,ds
    mov bx,ax
    mov eax,0006h
    int 31h
    jc .FatalError
    mov [ZSNESBase+2],cx                ; These variables are used for
    mov [ZSNESBase],dx                  ; memory allocation so they can be
.FatalError                             ; ignored for non-DOS ports
    call ZFileSystemInit
    ret

; SystemInit - Initialize all Joystick stuff, load in all configuration data,
;   parse commandline data, obtain current directory (One time initialization)
NEWSYM SystemInit
    ; Be sure to set SBHDMA to a value other than 0 if 16bit sound exists
    push es
    call getcmdline

    ; Get and set the initial directory
    mov ebx,InitDir
    mov edx,InitDrive
    call Get_Dir
    mov dl,[InitDrive]
    mov ebx,InitDir
    call Change_Dir

    call GUIRestoreVars                 ; Load GUI stuff
    call getcfg                         ; Load cfg stuff
    call obtaindir                      ; Get Save/Init Directories
    call ConvertJoyMap                  ; Mini joystick init
    call ccmdline
    call tparms
    call preparedir
    call getblaster                     ; get set blaster environment
    cmp byte[Force8b],1
    jne .noforce8b
    mov byte[SBHDMA],0
.noforce8b
    pop es
    ret

; Configuration save re-routing functions.  You can comment these out
;   for debugging purposes or change it if you're using a different
;   configuration format
NEWSYM createnewcfg
    call DOScreatenewcfg
    ret
NEWSYM GUISaveVars
    call ExecGUISaveVars
    ret

; Allocate memory - see allocptr in ui.asm for details on what to allocate
NEWSYM allocmem
    call allocptr
    ret

; Find Selector - DOS only
findselec:
    mov ax, 2
    int 31h
    jnc .proceed
    mov edx, .noselector
    call PrintStr
    jmp DosExit
.proceed
    ret
.noselector db 'Cannot find selector!',10,13,0

NEWSYM PrintChar
    ; print character at dl, push all modified registers
    push eax
    mov ah,02h
    int 21h
    pop eax
    ret

NEWSYM PrintStr          ; Print ASCIIZ string
.next
    mov al,[edx]
    or al,al
    jz .finish
    push edx
    mov dl,al
    mov ah,02h
    int 21h
    pop edx
    inc edx
    jmp .next
.finish
    ret

NEWSYM WaitForKey       ; Wait for a key to be pressed
    mov ah,7
    int 21h
    ; return key in al
    ret

NEWSYM OSExit
    jmp DosExit

NEWSYM MMXCheck
    ; Check for cpu that doesn't support CPUID
    mov edx,cpuidfname
    call Open_File
    jc .skipcheck
    mov bx,ax
    call Close_File
    jmp .nommx2
.skipcheck

    ; Create file
    mov edx,cpuidfname
    call Create_File
    mov bx,ax
    call Close_File

    mov edx,cpuidtext
    call PrintStr

    ; MMX support
    mov byte[FPUCopy],0
    mov eax,1
    CPUID

    push edx
    mov edx,cpuidtext2
    call PrintStr
    pop edx

    test edx,1 << 23
    jz .nommx
    mov byte[FPUCopy],2
    mov edx,YesMMX
    call PrintStr
.nommx
    ; Delete file
    mov edx,cpuidfname
    call Delete_File
.nommx2
    ret

NEWSYM Open_File
    pushad
    mov dword[ZOpenMode],0
    mov dword[ZOpenFileName],edx
    call ZOpenFile
    cmp eax,0FFFFFFFFh
    je .error
    mov dword[ZFileSeekMode],0
    mov dword[ZFileSeekPos],0
    mov dword[ZFileSeekHandle],0
    mov bx,[CurrentHandle]
    dec bx
    mov word[ZFileSeekHandle],bx
    call ZFileSeek
    popad
    mov ax,[CurrentHandle]
    dec ax
    clc
    ret
.error
    popad
    stc
    ret
    mov ax,3D00h
    int 21h
    ; return ax = file handle, carry = error
    ret

NEWSYM Open_File_Write
    pushad
    mov dword[ZOpenMode],2
    mov dword[ZOpenFileName],edx
    call ZOpenFile
    cmp eax,0FFFFFFFFh
    je .error
    mov dword[ZFileSeekMode],0
    mov dword[ZFileSeekPos],0
    mov dword[ZFileSeekHandle],0
    mov bx,[CurrentHandle]
    dec bx
    mov word[ZFileSeekHandle],bx
    call ZFileSeek
    popad
    mov ax,[CurrentHandle]
    dec ax
    clc
    ret
.error
    popad
    stc
    ret
    mov ax,3D01h
    int 21h
    ; return ax = file handle, carry = error
    ret

NEWSYM Create_File
    pushad
    mov dword[ZOpenMode],1
    mov dword[ZOpenFileName],edx
    call ZOpenFile
    cmp eax,0FFFFFFFFh
    je .error
    popad
    mov ax,[CurrentHandle]
    dec ax
    clc
    ret
.error
    popad
    stc
    ret
    mov ah,3Ch
    mov cx,0
    int 21h
    ; return ax = file handle
    ret

NEWSYM Write_File
    mov dword[ZFileWriteHandle],0
    mov [ZFileWriteHandle],bx
    mov [ZFileWriteSize],ecx
    mov [ZFileWriteBlock],edx
    pushad
    call ZFileWrite
    cmp eax,0FFFFFFFFh
    je .fail
    popad
    mov eax,1
    clc
    ret
.fail
    popad
    mov eax,0
    stc
    ret
    mov ah,40h
    int 21h
    ret

NEWSYM Read_File
    mov dword[ZFileReadHandle],0
    mov [ZFileReadHandle],bx
    mov [ZFileReadSize],ecx
    mov [ZFileReadBlock],edx
    pushad
    call ZFileRead
    mov [TempVarSeek],eax
    popad
    mov eax,[TempVarSeek]
    clc
    ret
    mov ah,3Fh
    int 21h
    ret

NEWSYM Delete_File
    mov [ZFileDelFName],edx
    pushad
    call ZFileDelete
    popad
    ret
    mov ah,41h
    int 21h
    ret

NEWSYM Close_File
    mov dword[ZCloseFileHandle],0
    mov [ZCloseFileHandle],bx
    pushad
    call ZCloseFile
    popad
    clc
    ret
    mov ah,3Eh
    int 21h
    ret

NEWSYM File_Seek
    mov word[ZFileSeekPos+2],cx
    mov word[ZFileSeekPos],dx
    mov dword[ZFileSeekMode],0
    mov dword[ZFileSeekHandle],0
    mov word[ZFileSeekHandle],bx
    pushad
    call ZFileSeek
    popad
    mov ax,dx
    mov dx,cx
    ret
    ; seek to cx:dx from 0 position, return carry as error
    mov ax,4200h
    int 21h
    ret

NEWSYM File_Seek_End
    mov word[ZFileSeekPos+2],cx
    mov word[ZFileSeekPos],dx
    mov dword[ZFileSeekHandle],0
    mov word[ZFileSeekHandle],bx
    mov dword[ZFileSeekMode],1
    mov dword[ZFileTellHandle],0
    mov word[ZFileTellHandle],bx
    pushad
    call ZFileSeek
    call ZFileTell
    mov [TempVarSeek],eax
    popad
    mov ax,[TempVarSeek]
    mov dx,[TempVarSeek+2]
    clc
    ret
    ; seek to cx:dx from end position, and return file location in dx:ax
    mov ax,4202h
    int 21h
    ret

NEWSYM Get_Time
    pushad
    call GetTime
    mov [TempVarSeek],eax
    popad
    mov eax,[TempVarSeek]
    ret
NEWSYM Get_TimeDate
    pushad
    call GetDate
    mov [TempVarSeek],eax
    popad
    mov eax,[TempVarSeek]
    ret

NEWSYM Get_Date
    ; dl = day, dh = month, cx = year
    mov ah,2Ah
    int 21h
    ret

NEWSYM Get_File_Date
    mov [ZFFTimeFName],edx
    pushad
    call ZFileGetFTime
    popad
    mov dx,[ZFDate]
    mov cx,[ZFTime]
    ret
    ; return packed date in dx:cx
    mov ah,57h
    mov al,00h
    int 21h
    ret

%macro PressConv 3
    cmp byte[pressed+%1],0
    je %%nopr
    test byte[prval],%2
    jnz %%prskip
    or byte[prval],%2
    mov byte[prres],%3
;    mov al,0FFh
    jmp .done
    jmp %%prskip
%%nopr
    and byte[prval],%2^0FFh
%%prskip
%endmacro

;SECTION .data
;NEWSYM prval, db 0
;NEWSYM prres, db 0
;SECTION .text

NEWSYM Check_Key
;    xor al,al
;    PressConv 75,01h,75
;    PressConv 77,02h,77
;    PressConv 80,04h,80
;    PressConv 72,08h,72
;    PressConv 1,80h,27
;.done
;    ret
    ; returns 0 if there are no keys in the keyboard buffer, 0xFF otherwise
    mov ah,0Bh
    int 21h
    ret

NEWSYM Get_Key
;    mov al,[prres]
;    ret
    ; wait if there are no keys in buffer, then return key in al
    ; for extended keys, return a 0, then the extended key afterwards
    mov ah,07h
    int 21h
    ret

;    mov dl,[SRAMDrive]
;    mov ebx,SRAMDir
;    call Change_Dir

NEWSYM Change_Drive
    ; change to drive in dl (0 = A, 1 = B, etc.)
    mov ah,0Eh
    int 21h
    ret

NEWSYM Change_Single_Dir
    mov [CHPath],edx
    pushad
    call ZFileCHDir
    or eax,eax
    jnz .notokay
    popad
    clc
    ret
.notokay
    popad
    stc
    ret
    ; Dir in edx, return error in carry flag
    mov ah,3Bh
    int 21h
    ret

NEWSYM Create_Dir
    ; change to dir in edx
    mov [MKPath],edx
    pushad
    call ZFileMKDir
    or eax,eax
    jnz .notokay
    popad
    clc
    ret
.notokay
    popad
    stc
    ret
    mov ah,39h
    int 21h
    ret

NEWSYM Remove_Dir
    ; remove dir in edx
    mov [RMPath],edx
    pushad
    call ZFileRMDir
    or eax,eax
    jnz .notokay
    popad
    clc
    ret
.notokay
    popad
    stc
    ret
    mov ah,3Ah
    int 21h
    ret

;    mov dl,[LoadDrive]
;    mov ebx,LoadDir
;    call Change_Dir
NEWSYM Change_Dir
    pushad
    mov ah,0Eh
    int 21h
;    jc .fail
    mov dword[CHPath],gotoroot
    call ZFileCHDir
    or eax,eax
    jnz .fail
    popad
    mov [CHPath],ebx
    cmp byte[ebx],0
    je .nocdir
    pushad
    call ZFileCHDir
    or eax,eax
    jnz .fail
    popad
.nocdir
    clc
    ret
.fail
    popad
    stc
    ret

    ; dl = drive, ebx = dir
    push ebx
    mov ah,0Eh
    int 21h
    mov ah,3Bh
    mov edx,gotoroot
    int 21h
    pop ebx
    mov edx,ebx
    cmp byte[edx],0

⌨️ 快捷键说明

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