home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / OS2ASM.ZIP / BIOS.ASM next >
Assembly Source File  |  1991-06-27  |  6KB  |  243 lines

  1. ;_ bios.asm   Tue Mar 20 1990   Modified by: Walter Bright */
  2. ; These functions are not available under OS/2
  3. ; DOS386 support added by G. Eric Engstrom
  4.  
  5. include    macros.asm
  6.  
  7. DISKINFO STRUC
  8.     drive        DW    ?
  9.     head        DW    ?
  10.     track        DW    ?
  11.     sector        DW    ?
  12.     nsectors    DW    ?
  13.     buffer        DD    ?
  14. DISKINFO ENDS
  15.  
  16.     begcode    bios
  17.  
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ; Access BIOS keyboard function
  20. ;    #include <bios.h>
  21. ;    int _bios_keybrd(int flag);
  22. ;    int bioskey(int flag);        /* both are the same routine    */
  23. ; Usage:
  24. ;    flag = 0    Return ascii value in low byte, scan code in high byte
  25. ;         = 1    Return 0 if no key is available else return ascii
  26. ;            value in low byte and scan code in high byte. Key is
  27. ;            left unread in BIOS
  28. ;            A -1 returned means that a ^C was read by the BIOS
  29. ;            (^C is turned into 0 by the BIOS, we turn it into
  30. ;             -1 to distinguish it from the no-key-available case)
  31. ;         = 2    Return shift status, bits are:
  32. ;            0x01    Right shift key is down
  33. ;            0x02    Left shift key is down
  34. ;            0x04    Ctrl key is down
  35. ;            0x08    Alt key is down
  36. ;            0x10    Scroll Lock is toggled
  37. ;            0x20    Num Lock is toggled
  38. ;            0x40    Caps Lock is toggled
  39. ;            0x80    Ins is toggled
  40. ;            Other bits are undefined
  41.  
  42.     public    _bioskey
  43. _bioskey:
  44.  
  45.     c_public _bios_keybrd
  46. func    _bios_keybrd
  47.     push    EBP
  48.     mov    EBP,ESP
  49.     mov    AH,P[EBP]
  50.     int    16h
  51.     jnz    K1
  52.     ; ZF == 1
  53.     _ifs    <byte ptr P[EBP]> ne 1, K2
  54.     clr    EAX        ;if flag is 1 and Z was set
  55.     jmp    short K2
  56. K1:    ; ZF == 0
  57.     _ifs    <byte ptr P[EBP]> ne 1, K2
  58.     or    AX,AX
  59.     jnz    K2
  60.     mov    EAX,-1        ;if flag is 1 and Z was clear, but key to return was 0, then return -1
  61. K2:    pop    EBP
  62.     ret
  63. c_endp    _bios_keybrd
  64.  
  65.  
  66. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  67. ; Access BIOS equipment list function
  68. ;    #include <bios.h>
  69. ;    unsigned _bios_equiplist(void);
  70. ; Usage:
  71. ;    returns the bios equipment list in AX
  72. ;
  73. ;    bit 0            1if any diskettes
  74. ;    bit 1            Not used (set to 0)
  75. ;    bits 2 & 3        System board RAM: 11 = 64k (normal)
  76. ;    bits 4 & 5        Initial video mode 10 = color, 11 = mono, 01 = 40col
  77. ;    bits 6 & 7        Number of disk drives -1
  78. ;    bit 8            DMA chip (0 = installed)
  79. ;    bits 9,10 & 11    Number of serial ports
  80. ;    bit 12            Game adaptor (1 = installed)
  81. ;    bit 13            Serial printer installed (=1) PC jnr only.
  82. ;    bits 14 & 15    Number of printers installed
  83. ;
  84.     c_public _bios_equiplist
  85. func _bios_equiplist
  86.     clr    EAX
  87.     int    11h
  88.     ret
  89. c_endp    _bios_equiplist
  90.  
  91. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  92. ; Access BIOS memory size function
  93. ;    #include <bios.h>
  94. ;    unsigned _bios_memsize(void)
  95. ; Usage:
  96. ;    returns the memory size in kilobytes
  97. ;    in AX
  98. ;    
  99.     c_public _bios_memsize
  100. func    _bios_memsize
  101.     clr    EAX
  102.     int    12h
  103.     ret
  104. c_endp    _bios_memsize
  105.  
  106.  
  107. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  108. ; Access BIOS printer functions
  109. ;    #include <bios.h>
  110. ;    int _bios_printer(unsigned service, unsigned printer, unsigned data)
  111. ; Usage:
  112. ;    service = 0    write the low order byte of data to the printer which
  113. ;            was specified in the printer argument.
  114. ;            returns the printer status thus
  115. ;            0x01    Printer timed out
  116. ;            0x02    Not used
  117. ;            0x04    Not used
  118. ;            0x08    I/O error
  119. ;            0x10    Printer selected
  120. ;            0x20    Out of paper
  121. ;            0x40    Acknowledge
  122. ;            0x80    Printer not busy
  123. ;    service = 1    Intialize the selected printer. The data argument is
  124. ;                ignored. The status is return as above.
  125. ;    service = 2    Returns the printer status as defined above
  126. ;    
  127.     c_public _bios_printer
  128. func    _bios_printer
  129.     push    EBP
  130.     mov    EBP,ESP
  131.     uses    <EDX>
  132.     mov    AH,P[EBP]
  133.     mov    DX,P+4[EBP]
  134.     mov    AL,P+8[EBP]
  135.     int    17h
  136.     mov    AL,AH        ;return status byte in AL
  137.     clr    AH
  138.     unuse    <EDX>
  139.     pop    EBP
  140.     ret
  141.  
  142. c_endp    _bios_printer
  143.  
  144. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  145. ; Access BIOS serial comms functions
  146. ;    #include <bios.h>
  147. ;    int _bios_serialcom(unsigned service, unsigned port, unsigned data)
  148. ; Usage:
  149. ;    service = 0    Sets the data port up as specified in the data argument    
  150. ;    service = 1    Transmits the data character over the port
  151. ;    service = 2    Accepts a charcter from the serial port
  152. ;    service = 3 Returns the current status of the selected serial port
  153.     c_public _bios_serialcom
  154. func    _bios_serialcom
  155.     push    EBP
  156.     mov    EBP,ESP
  157.     uses    <EDX>
  158.     mov    AH,P[EBP]
  159.     mov    DX,P+4[EBP]
  160.     mov    AL,P+8[EBP]
  161.     int    14h
  162.     unuse    <EDX>
  163.     pop    EBP
  164.     ret
  165.  
  166. c_endp _bios_serialcom
  167.  
  168. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  169. ; Access BIOS time of day functions
  170. ;    #include <bios.h>
  171. ;    int _bios_timeofday(int service, long *timeval)
  172. ; Usage:
  173. ;    service = 0    copies the current value of the clock count
  174. ;                to the location that timeval points to.
  175. ;    service = 1    sets the current value of the system clock 
  176. ;                to that in the location pointed to by timeval.
  177.     c_public _bios_timeofday
  178. func    _bios_timeofday
  179.     push    EBP
  180.     mov    EBP,ESP
  181.     uses    <EBX,ECX,EDX>
  182.     mov    AH,P[EBP]
  183.     mov    EBX,P+4[EBP]
  184.     _ifs    AH ne 1,T1
  185.       mov      DX,[EBX]
  186.       mov      CX,[EBX+2]
  187.       int      01Ah
  188.       jmps      T3
  189. T1:    int    01Ah
  190.     mov    [EBX],DX
  191.     mov    [EBX+2],CX
  192.  
  193. T3:    unuse    <EDX,ECX,EBX>
  194. T2:    pop    EBP
  195.     ret
  196. c_endp    _bios_timeofday
  197.  
  198. if 0    ;_bios_disk is currently not supported in either Pharlap or X386
  199.  
  200. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  201. ; Access BIOS disk (int 0x13)  functions
  202. ;    #include <bios.h>
  203. ;    int _bios_disk(int service, struct diskinfo_t *diskinfo)
  204. ; Usage:
  205. ;    service = 0    reset the disk system
  206. ;    service = 1    get diskette status                    
  207. ;    service = 2    read diskette sectors                    
  208. ;    service = 3    write diskette sectors                    
  209. ;    service = 4    verify diskette sectors                    
  210. ;    service = 5    format diskette sectors                    
  211.     c_public _bios_disk
  212. func    _bios_disk
  213.     push    EBP
  214.     mov    EBP,ESP
  215.     uses    <EBX,ECX,EDX>
  216.     mov    EBX,P+4[EBP]
  217.     mov    DL,byte ptr drive[EBX]
  218.     mov    DH,byte ptr head[EBX]
  219.     mov    CL,byte ptr sector[EBX]
  220.     mov    CH,byte ptr track[EBX]
  221.     mov    AL,byte ptr nsectors[EBX]
  222.     mov    EBX,buffer[EBX]
  223.     mov    AH,P[EBP]
  224.     int    13h
  225.     jc    D1        ;error (error code is in AH)
  226.     _ifs    <byte ptr P[EBP]> e 0, D1
  227.     _ifs    <byte ptr P[EBP]> e 1, D2
  228.     _ifs    <byte ptr P[EBP]> ne 5, D3
  229. D1:    clr    AL
  230.     jmp    short D3
  231.  
  232. D2:    xchg    AH,AL        ;put status bits in AH, 0 in AL
  233.  
  234. D3:    unuse    <EDX,ECX,EBX>
  235.     jmp    T2
  236. c_endp    _bios_disk
  237.  
  238. endif
  239.  
  240.     endcode bios
  241.  
  242.     end
  243.