; ASPIINFO Chris Evans 2007 

; According to the documentation in the ASPI software development kit, possible Aspi error codes are:

SS_INVALID_CMD EQU 080h 	  ;// Invalid ASPI command
SS_INVALID_HA EQU 081h 		  ;// Invalid host adapter number
SS_NO_DEVICE EQU 082h 		  ;// SCSI device not installed
SS_INVALID_SRB EQU 0E0h 	  ;// Invalid parameter set in SRB
SS_OLD_MANAGER EQU 0E1h 	  ;// ASPI manager doesn't support Windows
SS_ILLEGAL_MODE EQU 0E2h 	  ;// Unsupported Windows mode
SS_NO_ASPI EQU 0E3h 		  ;// No ASPI managers resident
SS_FAILED_INIT EQU 0E4h 	  ;// ASPI for windows failed init
SS_ASPI_IS_BUSY EQU 0E5h 	  ;// No resources available to execute cmd
SS_BUFFER_TO_BIG EQU 0E6h 	  ;// Buffer size to big to handle!
SS_MISMATCHED_COMPONENTS EQU 0E7h ;// The DLLs/EXEs of ASPI don't version check
SS_NO_ADAPTERS EQU 0E8h 	  ;// No host adapters to manage
SS_INSUFFICIENT_RESOURCES EQU E9h ;// Couldn't allocate resources needed to init
SS_ASPI_IS_SHUTDOWN EQU EAh       ;// Call came to ASPI after PROCESS_DETACH
SS_BAD_INSTALL EQU 0EBh           ;// The DLL or other components are installed wrong

; highlevel ASPI

code_seg segment

          assume cs:code_seg,ds:code_seg
          org 100h

main       proc near

entry:     jmp start  
;  
;          data area
;          
          scsicommand struc
             code     db 2
           status     db 0  
          adapter     db 0  
          reqflag     db 24  
          resrved     db 0  
           targid     db 1
          logunit     db 0
          xferlen     dw 0,0
          senslen     db 0
          dataptro    dw 0
          dataptrs    dw 0
          srbptro     dw 0
          srbptrs     dw 0
           cdblen     db ?
         hoststat     db 0
         targstat     db 0  
         postaddo     dw 0
         postadds     dw 0
         workspac     db 34 dup (?)
         
          scsicommand ends              
          SCSI db 'SCSIMGR$',0
          ASPI dw 2 dup (?)
          SRB  db 58 dup (0)
          cards db ?
          curcard db ?
          curdev db ?
          bTen db 10
          cardat db ?
          cardflag db ?
;
;          code area
;
start:     mov ax,3D00h
          lea dx,SCSI
          int 21h
          jnc haveaspi

          mov ah,09
          lea dx,nope
          int 21h
          mov ax,4C01h
          int 21h
          nope db 13,10,'No ASPI Manager Found',13,10,'$'

haveaspi:  push ax
          mov bx,ax
          mov ax,4402h
          lea dx,ASPI
          mov cx,4
          int 21h
          pop bx
          mov ah,3Eh
          int 21h

nextcard:  call callaspi
          jne btdt
          mov al,SRB[8]
          mov cards,al
          mov al,SRB[9]
          mov cardat,al
          mov si,offset SRB+10
          mov di,offset EchoBuffer
          mov cx,8
          rep movsw
          lea dx,CRLF
          mov ah,09
          int 21h

btdt:      mov si,offset SRB+26
          mov di,offset EchoBuffer
          mov cx,8
          rep movsw
          lea dx,EchoBuffer
          mov ah,09
          int 21h
          mov al,SRB[2]

          mov curcard,al
          mov curdev,0
nextdev:   call clearSRB
          mov SRB[0],1
          mov al,curcard
          mov SRB[2],al
          mov al,curdev
          mov SRB[8],al
          call callaspi
          call showdev
          inc curdev
          cmp curdev,8
          jne nextdev

          mov al,curcard
          inc al
          cmp al,cards
          je lastcard

          call clearSRB
          mov SRB[2],al
          jmp short nextcard

lastcard:  mov ax,4C00h
          int 21h

          CRLF       db 13,10
          EchoBuffer db 16 dup(?), 13, 10,'$'
          None       db 'None'
          Ctrl       db 'Card'

main       endp
          DevBuffer db 'ID #xx   Type - xxxx',13,10,'$'
showdev    proc near
          mov cardflag,0
          mov al,curdev
          cmp al,cardat
          jne adevice
          mov cardflag,1
adevice:   xor ah,ah
          div bTen
          add ax,3030h
          lea di, devbuffer[4]
          stosw
          cmp cardflag,1
          jne notcard
          lea si,Ctrl
          jmp short notnum
notcard:   cmp SRB[1],82h
          jne shownum
          lea si,None
notnum:    lea di,DevBuffer[16]
          movsw
          movsw
          jmp short nonum
shownum:   mov al,SRB[10]
          xor ah,ah
          div bTen
          add ax,3030h
          lea di,DevBuffer[16]
          stosw
          mov ax,2020h
          stosw
nonum:     mov ah,09
          lea dx,devbuffer
          int 21h
          ret
showdev    endp
callaspi   proc near

          push ds
          lea bx,SRB
          push bx
          lea bx,ASPI
          call dword ptr[bx]
          add sp,4
          cmp SRB[2],0
          ret
callaspi   endp

clearSRB   proc near
          push ax
          xor ax,ax
          lea di,SRB
          mov cx,29
          rep stosw
          pop ax
          ret
clearSRB   endp

code_seg   ends
          end entry 
