ATA_FLOATING_BUS_TEST:
org 100h
bits 16


call clearscreen


;//Our delayed loop value. The greater this 32-bit
;//value, the less our test loop will last alive:
;//     ECX == 0x00000000 will last the most  (too much)
;//     ECX == 0x00000001 will last the least (too fast)
;;;
 mov ecx,0xFFF00000


;//Configure our segment to access screen:
;;;
 mov ax,0xB800
 mov ds,ax


;//Our screen debug output:
;;;
 mov byte[ds:0],"M";//Master Testing
 mov byte[ds:10],"S";//Slave  Testing
 mov byte[ds:20],"p";//process active (is CPU locked or active?)

 mov eax,0x3F3F3F3F
 mov dword[ds:4],eax
 mov dword[ds:14],eax



._loop:
 inc ecx      ;//Increase original ECX value from 0 to 0xFFFFFFFF
              ;//and back to 0 when overflow takes place to control
              ;//the limit of this loop.


 ;//Test the MASTER BUS to see if the
 ;//Status Register (7 + 1F0h) has the
 ;//floating value 0xFF:
 ;;;
   mov dx,0x1F7             ;//MASTER Status port
   in al,dx                 ;//Read it
   cmp al,0xFF              ;//See if floating
   je ._floatingmaster      ;//If not, do nothing here
   cmp al,0x7F              ;//See if floating
   je ._floatingmaster      ;//If not, do nothing here
   cmp al,0x00              ;//See if floating
   je ._floatingmaster      ;//If not, do nothing here
   jmp ._nofloatingmaster
    ._floatingmaster:

     inc byte[ds:1]         ;//If yes, change the color of the "M"
                            ;//(of [M]aster) whenever we read 0xFF

   ._nofloatingmaster:
   call bin2hex
   mov dword[ds:4],eax




 ;//Test the SLAVE BUS to see if the
 ;//Status Register (7 + 170h) has the
 ;//floating value 0xFF:
 ;;;
   mov dx,0x177             ;//SLAVE Status port
   in al,dx                 ;//Read it
   cmp al,0xFF              ;//See if floating
   je ._floatingslave       ;//If not, do nothing here
   cmp al,0x7F              ;//See if floating
   je ._floatingslave       ;//If not, do nothing here
   cmp al,0x00              ;//See if floating
   je ._floatingslave       ;//If not, do nothing here
   jmp ._nofloatingslave
    ._floatingslave:

     inc byte[ds:11]        ;//If yes, change the color of the "S"
                            ;//(of [S]lave) whenever we read 0xFF

   ._nofloatingslave
   call bin2hex
   mov dword[ds:14],eax



 ;//Demonstrate on screen that our program is still alive
 ;//by changing the color of the p (of "[p]rocess active")
 ;;;
  inc byte[ds:21]


jecxz ._outofloop  ;If ECX has become 0, break loop
jmp ._loop






._outofloop:
int 20h









;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;END OF main();;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;










clearscreen:
 pusha
  ;//Try to clear the screen:
  ;;;
    mov ah,6       ;//VIDEO - SCROLL UP WINDOW
    mov al,0       ;//number of lines by which to scroll up
                   ;//(00h = clear entire window)
    mov bh,0x7     ;//attribute used to write blank lines
                   ;//at bottom of window
    xor cx,cx      ;//row,column of window's upper left corner
    mov dx,0x1950  ;//80x25 ;DH,DL row,column of window's
                   ;//lower right corner
     int 10h

  ;//Set position of cursor at top of screen:
  ;;;
    mov ah,2   ;//VIDEO - SET CURSOR POSITION
    mov bh,0   ;//page number
               ;//   0-3 in modes 2&3
               ;//   0-7 in modes 0&1
               ;//   0 in graphics modes
    xor dx,dx  ;//DH,DL row (00h is top), column (00h is left)
      int 10h
 popa
ret































;Take in AL 1 value between 0 & 255 (0-FF)
;and puts the hex ASCII hex in EAX

bin2hex:
 push ebx
  and eax,11111111b

  mov ah,al

  shr al,4
  cmp al,0x09
  ja noner1
   add al,0x30
   jmp noner1_1

  noner1:
   add al,0x37

  noner1_1:



  and ah,00001111b
  cmp ah,0x09
  ja noner2
   add ah,0x30
   jmp noner2_2

  noner2:
   add ah,0x37

  noner2_2:


;  mov bl,0010011b  ;color: blue bk with aqua letter
  mov bl,00111111b

  shl ebx,8
  mov bl,ah

  shl ebx,8
;  mov bl,00010011b  ;color: blue bk with aqua letter
  mov bl,00111111b

  shl ebx,8
  mov bl,al


  mov eax,ebx


 pop ebx
ret
