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

📄 pcic.asm

📁 CF卡读卡程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:

PowerUpSocket5V:
	mov     al, PowerRegister5V

PowerUpSocketNow:
	inc     dx
	out     dx, al

	mov     cx, PowerUpDelay
PowerUpSocketDelay:
	loop    short PowerUpSocketDelay

	;sti

	pop     bp
	ret
_PowerUpSocket  endp

;****************************************************************************
;* _ReadySocket
;*
;* FUNCTION:
;*      Return the status of the socket.
;*
;* INPUTS:
;*      None
;*
;* GLOBALS:
;*      None
;*
;* FORMAT:
;*      int _ReadySocket(VOID)
;*
;* RETURNS:
;*      Socket status value, hardware-dependent
;****************************************************************************
_ReadySocket    proc    near
	push    bp
	mov     bp,sp

	;---------------------------------------------------------------;
	; Return the ready value for the socket.                        ;
	;---------------------------------------------------------------;
	;cli

	mov     al, StatusRegister
	mov     dx, SocketRegisterPort
	out     dx, al

	inc     dx
	in      al, dx

	and     ax, StatusRegisterReady

	;sti

	pop     bp
	ret
_ReadySocket    endp

;****************************************************************************
;* _ResetSocket
;*
;* FUNCTION:
;*      Reset the socket hardware.
;*
;* INPUTS:
;*      None
;*
;* GLOBALS:
;*      None
;*
;* FORMAT:
;*      void _ResetSocket(VOID)
;*
;* RETURNS:
;*      None
;****************************************************************************
_ResetSocket    proc    near

	push    bp
	mov     bp,sp

	;---------------------------------------------------------------;
	; Wiggle the reset bit in the socket.                           ;
	;---------------------------------------------------------------;
	;cli

	mov     al, ControlRegister
	mov     dx, SocketRegisterPort
	out     dx, al

	inc     dx
	in      al, dx
	and     al, 0FFh-ControlRegisterReset
	out     dx, al

	;---------------------------------------------------------------;
	; Delay the appropriate amount for the socket.                  ;
	;---------------------------------------------------------------;
	mov     cx, ResetDelay
ResetSocketDelay:
	loop    ResetSocketDelay

	or      al, ControlRegisterReset
	out     dx, al

	;sti

	pop     bp
	ret
_ResetSocket    endp

;****************************************************************************
;* _SlideMemoryWindow
;*
;* FUNCTION:
;*      Select the flash card address to be mapped into system memory.
;*
;* INPUTS:
;*      CardAddress - to map into system memory
;*
;* GLOBALS:
;*      LastWindowAddress - updated with currently mapped address
;*
;* FORMAT:
;*      void _SlideMemoryWindow(dword CardAddress)
;*
;* RETURNS:
;*      ErrorNone       requested memory was successfully mapped
;*      ErrorParam      requested memory was beyond card's range
;****************************************************************************
_SlideMemoryWindow proc    near
	push    bp
	mov     bp,sp

	push    bx
	push    cx
	push    dx

	;---------------------------------------------------------------;
	; Verify that the address parameter is within the card's range. ;
	; Ver65                                                         ;
	;---------------------------------------------------------------;
	mov     ax, [bp+6]              ; requested address
	mov     dx, [bp+4]
	mov     bx, DGROUP:_FTLTablePtr  ; Ver67

	cmp     bx, 0                   ; Ver67 if card size not yet known
	je      SlideParamOK

	sub     dx, [bx].MediaSize.Lo   ; minus card size
	sbb     ax, [bx].MediaSize.Hi
	jbe     SlideParamOK            ; <= 0

	mov     ax, ErrorParam          ; means error
	jmp     SlideWindowReturn

SlideParamOK:
	;cli

	;---------------------------------------------------------------;
	; Put the 32-bit card address into a 4K value.                  ;
	;---------------------------------------------------------------;
	mov     bx, word ptr [bp+6]
	mov     cl, 4
	shl     bx, cl

	mov     ax, word ptr [bp+4]
	mov     cl, 12
	shr     ax, cl

	or      bx, ax

	;---------------------------------------------------------------;
	; If already mapped at this address, save time and return now.  ;
	;---------------------------------------------------------------;
	mov     ax, ErrorNone
	cmp     bx, DGROUP:LastWindowAddress
	je      SlideWindowReturn
	mov     DGROUP:LastWindowAddress, bx

	;---------------------------------------------------------------;
	; Map in the card address through the sliding memory window.    ;
	;---------------------------------------------------------------;
	sub     bx, MemoryWindowAddress
	and     bx, MemoryWindowMask

	mov     dx, SocketRegisterPort
	mov     al, MemoryLowRegister
	out     dx, al

	inc     dx
	mov     al, bl
	out     dx, al

	dec     dx
	mov     al, MemoryHighRegister
	out     dx, al

	inc     dx
	mov     al, bh
	out     dx, al

	mov     ax, ErrorNone

SlideWindowReturn:
	;---------------------------------------------------------------;
	; Pop regs, restore stack, and return.                          ;
	;---------------------------------------------------------------;
	;sti

	pop     dx
	pop     cx
	pop     bx

	mov     sp,bp
	pop     bp
	ret
_SlideMemoryWindow endp

;****************************************************************************
;* _WindowSetup
;*
;* FUNCTION:
;*      Initialize the hardware memory window, through which the flash card
;*      will be accessed.
;*
;* INPUTS:
;*      None
;*
;* GLOBALS:
;*      None
;*
;* FORMAT:
;*      void _WindowSetup(VOID)
;*
;* RETURNS:
;*      None
;****************************************************************************
_WindowSetup proc    near
	push    bp
	mov     bp,sp

	;---------------------------------------------------------------;
	; Open a sliding memory window at the requested system memory   ;
	; location "MemoryWindowAddress".                               ;
	;---------------------------------------------------------------;
	;cli

	mov     dx, SocketRegisterPort
	mov     al, StartLowRegister
	out     dx, al

	inc     dx
	mov     al, MemoryWindowAddress
	out     dx, al

	dec     dx
	mov     al, StartHighRegister
	out     dx, al

	inc     dx
	mov     al, StartHighRegister16bit
	out     dx, al

	dec     dx
	mov     al, StopLowRegister
	out     dx, al

	inc     dx
	mov     al, MemoryWindowAddress
	out     dx, al

	dec     dx
	mov     al, StopHighRegister
	out     dx, al

	inc     dx
	mov     al, StopHighRegisterNoWait
	out     dx, al

	dec     dx
	mov     al, WindowRegister
	out     dx, al

	inc     dx
	mov     al, WindowRegisterDecode12+WindowRegisterEnable0
	out     dx, al

	;sti

	pop     bp
	ret
_WindowSetup endp

_TEXT    ends

	;---------------------------------------------------------------;
	; Routines for others to call.                                  ;
	;---------------------------------------------------------------;
	public  _SlideMemoryWindow
	public  _WindowSetup
	public  _ResetSocket
	public  _ReadySocket
	public  _PowerUpSocket
	public  _PowerDownSocket

	;---------------------------------------------------------------;
	; Low level routines and data which are outside this routine.   ;
	;---------------------------------------------------------------;
	extrn   Save16bits:word                 ; Ver65
	extrn   _FTLTablePtr:word                ; Ver67

	end

⌨️ 快捷键说明

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