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

📄 dma2.asm

📁 dma编程
💻 ASM
字号:
;=========================================================;
; DMA                                            11/12/03 ;
;---------------------------------------------------------;
; DOS EXTREME OS V0.01                                    ;
; by Craig Bamford.                                       ;
;                                                         ;
; PLESAE NOTE: This DMA code, is cut & past from          ;
; "Solar OS."                                             ;
; it worked so well, i have not changed it.               ;
; Copyright (c) 2001-2003, Ontanu Bogdan Valentin         ;
; All rights are reserved.                                ;
;                                                         ;
; Sets up DMA read/write for floppy.                      ;                          
;=========================================================;

;--------------------------------------
; DMA Mode Register:  0Bh
;--------------------------------------
;        bit 7 - 6 = 00 Demand mode
;                  = 01 Signal mode
;                  = 10 Block mode
;                  = 11 Cascade mode
;
;
;        bit 5 - 4 = 0  Reserved
;
;        bit 3 - 2 = 00 Verify operation
;                  = 01 Write operation
;                  = 10 Read operation
;                  = 11 Reserved
;
;       bits 1 - 0 = 00 Select channel 0
;                  = 01 select channel 1
;                  = 10 select channel 2
;                  = 11 select channel 3
;
;       USE: Tell the DMAC what to do. Common modes are:
;
;            48h (Read operation, Signal mode)
;                Used to read data from host memory and send to whomever
;                polls it.
;
;            44h (Write operation, Signal mode)
;                Used to write data taken from a device to memory.
;

;-------------------------------------------
; location of
; low memory, non crossing of 64k boundry
; memory buffer for FDD DMA operations
;-------------------------------------------
;offset_dma2_buffer	EQU	7fffh      ;2000h



;----------------------------------------------------------------------------------
; Lookup table for DMA controller ports 
;----------------------------------------
; TODO: use this later
;----------------------------------------------------------------------------------
;		Channels:	0000  0001  0002  0003  0004  0005  0006  0007
;----------------------------------------------------------------------------------
dma_mask_ports		db	00Ah, 00Ah, 00Ah, 00Ah, 0D4h, 0D4h, 0D4h, 0D4h

dma_mode_ports		db	00Bh, 00Bh, 00Bh, 00Bh, 0D6h, 0D6h, 0D6h, 0D6h

dma_clear_ports		db	00Ch, 00Ch, 00Ch, 00Ch, 0D8h, 0D8h, 0D8h, 0D8h

dma_low_page_ports	db	087h, 083h, 081h, 082h, 08Fh, 08Bh, 089h, 08Ah
dma_high_page_ports	dw	487h, 483h, 481h, 482h, 48Fh, 48Bh, 489h, 48Ah	

dma_offset_ports	db	000h, 002h, 004h, 006h, 0C0h, 0C4h, 0C8h, 0CCh
dma_count_ports		db	001h, 003h, 005h, 007h, 0C2h, 0C6h, 0CAh, 0CEh


;============================================
; Specific setup DMA2 for floppy only
;============================================
Setup_DMA2_Read:                     
     
;-----------------------------
; mask channel 2
;-----------------------------
	mov     eax,4
	add     eax,2
	out     0Ah,al          
;------------------------------
; clear pointers
;-------------------------------
	xor	eax,eax
	out	0Ch,al                                              ; clr byte ptr

;-------------------------------
; setup mode of operation
;--------------------------------
	mov	al,44h		                                    ; read from device and WRITE to memory
	add	al,2		                                    ; add device nr
	out	0Bh,al                                              ; set mode reg

;---------------------------------------
; set page low register
;---------------------------------------
	mov	edx,081h
        mov	eax,offset_dma2_buffer 
        add     eax,[BaseAddOn]                                     ;add base to lable address
     	shr	eax,16
	;and	eax,3 
	out	dx,al                                               ; set DMA page reg
;---------------------------------
;  setup offset addr
;---------------------------------         
	mov	edx,04
	mov	eax,offset_dma2_buffer 
        add     eax,[BaseAddOn]                                     ;add base to lable address
       	and	eax,0FFFFh
	out	dx,al		                                    ; set base address low
	mov	al,ah
	out	dx,al		                                    ; set base address high
;-----------------------------
; setup length
;-----------------------------
	mov	eax,512
	dec	eax		                                    ; length-1
	mov	edx,05
	out	dx,al		                                    ; set length low
	mov	al,ah
	out	dx,al		                                    ; set length high

;-------------------------------
; unmask channel 2
;-------------------------------
	mov	al,2
	out	0Ah,al                                              ; unmask (activate) dma channel


        ret


Setup_DMA2_Write:                 
;-----------------------------
; mask channel 2
;-----------------------------
	mov     eax,4
	add     eax,2
	out     0Ah,al          
;------------------------------
; clear pointers
;-------------------------------
	xor	eax,eax
	out	0Ch,al                                              ; clr byte ptr

;-------------------------------
; setup mode of operation
;--------------------------------
	mov	al,48h		                                    ; write to device and READ from memory
	add	al,2		                                    ; add dma device nr
	out	0Bh,al                                              ; set mode reg

;---------------------------------------
; set page low register
;---------------------------------------
	mov	edx,081h
        mov	eax,offset_dma2_buffer
        add     eax,[BaseAddOn]                                     ;add base to lable address
	shr	eax,16
	and	eax,3
	out	dx,al                                               ; set DMA page reg
;---------------------------------
;  setup offset addr
;---------------------------------         
	mov	edx,04
	mov	eax,offset_dma2_buffer
        add     eax,[BaseAddOn]                                     ;add base to lable address
	and	eax,0FFFFh
	out	dx,al		                                    ; set base address low
	mov	al,ah
	out	dx,al		                                    ; set base address high
;-----------------------------
; setup length
;-----------------------------
	mov	eax,512
	dec	eax		                                    ;length-1
	mov	edx,05
	out	dx,al		                                    ; set length low
	mov	al,ah
	out	dx,al		                                    ; set length high

;-------------------------------
; unmask channel 2
;-------------------------------
	mov	al,2
	out	0Ah,al                                              ; unmask (activate) dma channel


        ret

⌨️ 快捷键说明

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