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

📄 usb4dos.asm

📁 usb for dos 适合开发人员学习和借鉴
💻 ASM
字号:

true        equ  1
false       equ  0
max_f_size  equ  16384      ; max size of 'devnums.bin' file
dn_line_s   equ  48         ; 48 bytes per line

code            segment byte public
                assume  cs:code, ds:code
		org	100h
usb4dos proc    far
start:          jmp     initialize
usblib      db  'USB_ASPI$',0
include         toolbox.asm
                _compile
initialize:
        call cs:main
exitptr:
        call dosexit
        int 20h 
usb4dos endp



;Vendor_N     db  ' - '
;             dup dn_line_s,0
;Device_N     db  ' - '
;             dup dn_line_s,0
devfile      db  'devnums.bin',0
;fram_l_ptr   dup 4,0      ; physical dword pointer to 1024 byte frame

code            ends

ProgramEnd      EQU $-01h

		end	start

buffer       dup 32768,?    ; multi-use buffer
;                33222222  22221111  11111100  00000000
;                10987654  32109876  54321098  76543210
stand_req_id db  00000000b,00000000b,00000000b,00000001b
             db  00001001b,10000000b,00000000b,00000000b
             db  00000000b,11100000b,00000001b,00101101b
             dw  00h,00h

get_dev_dis  db  80h         ; [bmRequest type] device->host, standard, device
             db  06h         ; [bRequest]       GET_DESCRIPTOR
             dw  01h         ; [wValue]         device
             dw  00h         ; [wIndex]         zero
             dw  08h         ; [wLength]        8 bytes

;                33222222  22221111  11111100  00000000
;                10987654  32109876  54321098  76543210
stand_req_in db  00000000b,00000000b,00000000b,00000001b
             db  00001001b,10000000b,00000111b,11111111b
             db  11111111b,11101000b,00000001b,01101001b
             dw  00h,00h

        mov  word ptr dev_index,00h
FindUSBL:
                call FindUSB               
                or   ah,ah                   ; if ah = !0, then no more
                jnz  short exit_ptr        
; if IOAddr < 100h then write to port + 20h = 120h ???
usb_get_next:
           inc  word dev_index          ;
           jmp  short FindUSBL          ; continue on to next device

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; finds a USB card/hub on given PCI index
; on entry:
;  dev_index = index
; on exit:
;  ah = 00h if card found
FindUSB    proc near uses bx cx dx si di

FindUSB    endp


usb_get_int_num proc near uses
           ret
usb_get_int_num endp
;function USBGetInterruptNumber(Var IntNo:word;Var active:boolean):boolean;
;var okay:boolean;
;    command:longint;
;    command2:longint;
;begin
;  okay:=false;
;  active:=false;
;  if isadetected then
;      if readPCIRegisterDWord($60,ISABusNumber,ISAFunctionNumber,command) then
;        begin
;          intno:=command shr 24;
;          active:=intno and 128=0;
;          intno:=intno and 15;
;          okay:=true;
;        end;
;   USBGetInterruptNumber:=okay;
;end;


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; on entry
;  dx = io starting address
; on exit
;  ax = USB status register contents
get_status_reg proc near uses dx
           inc  dx
           inc  dx                      ; USB status register (base+02)
           in   ax,dx                   ;  word sized
           and  ax,0000000001111111b    ; bits 15-6 reserved
           ret                          
get_status_reg endp

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; on entry
;  dx = io starting address (base)
;  ax = value to write
; on exit
;  nothing
w_status_reg proc near uses dx          ;
           inc  dx                      ; USB status register (base+02)
           inc  dx                      ;
           out  dx,ax                   ; word sized
           ret                          ;
w_status_reg endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;  opens 'devnums.bin' and finds a line starting with 'V xxxx'
;   where xxxx = VendorID.
;  once found, copys the string found after 'V xxxx ' to Vendor_N+3
;   then continues to find 'D xxxx ' where xxxx = DeviceID.
;  if 'V xxxx' found before device number is found, then error.
;  if number is found, then copies to Device_N+3
dev_names  proc near uses all es

           push cs                      ; make sure es = cs
           pop  es                      ;

           mov  ax,3D00h                ; open for read only
           mov  dx,offset devfile       ;
           int  21h                     ;
           jc   short dev_names_d       ;
           mov  bx,ax                   ;
           mov  ah,3Fh                  ; read from file
           mov  dx,offset buffer        ;
           mov  cx,max_f_size           ;
           int  21h                     ;
           jc   short dev_names_d       ;
           mov  ah,3Eh                  ; close the file
           int  21h                     ;

           mov  si,offset buffer        ;
dev_names_l:                            ;
           mov  al,[si]                 ;
           or   al,al                   ; if null found, then end of file
           je   short dev_names_d       ;
           cmp  al,'V'                  ;
           je   short dev_names_v       ;
dev_names_n:
           add  si,dn_line_s            ; length of each line
           jmp  short dev_names_l       ;
dev_names_v:
           mov  ax,[si+1]               ; get vendor id number
           cmp  ax,VendorID             ;
           jne  short dev_names_n       ;
           mov  di,(Vendor_N+3)         ;
           add  si,03                   ;
dev_n_v_l: lodsb                        ;
           stosb                        ;
           or   al,al                   ;
           jnz  short dev_n_v_l         ;

dev_names_l1:
           mov  al,[si]                 ;
           or   al,al                   ; if null found, then end of file
           je   short dev_names_d       ;
           cmp  al,'V'                  ; if 'V' found then no more devices
           je   short dev_names_d       ;   for this vendor
           cmp  al,'D'                  ;
           je   short dev_names_e       ;
dev_names_n1:                           ;
           add  si,dn_line_s            ; length of each line
           jmp  short dev_names_l1      ;
dev_names_e:
           mov  ax,[si+1]               ; get device id number
           cmp  ax,DeviceID             ;
           jne  short dev_names_n1      ;
           mov  di,(Device_N+3)         ;
           add  si,03                   ;
dev_n_v_l1:                             ;
           lodsb                        ;
           stosb                        ;
           or   al,al                   ;
           jnz  short dev_n_v_l1        ;
dev_names_d:
           ret
dev_names  endp

⌨️ 快捷键说明

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