home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / wasm202.zip / BIOS.MAC next >
Text File  |  1986-11-23  |  21KB  |  526 lines

  1.  List-
  2.  
  3. ;============================================================================;
  4. ;                           Bios Macro Interface                             ;
  5. ;                                                                            ;
  6. ; The following macros provide an interface with the basic input/output      ;
  7. ; system (BIOS).  Routines are provided here for accessing the keyboard,     ;
  8. ; screen, and printer.                                                       ;
  9. ;                                                                            ;
  10. ; Parameters may be passed as registers, memory operands, and immediate      ;
  11. ; data.  BP should never be used to pass parameters.  Each macro describes   ;
  12. ; its own parameters.  Only the segement registers are guaranteed to be      ;
  13. ; preserved.  The macros do not check to see if their arguments are valid.   ;
  14. ;                                                                            ;
  15. ; These macros require the macro definition IF_EXIST, found in MISC.MAC.     ;
  16. ;                                                                            ;
  17. ; The direct use of the BIOS provides more control over i/o fuctions and     ;
  18. ; usually a faster response time.  Some functions cannot be carried out      ;
  19. ; without using the BIOS.  But note that a program that uses the BIOS may    ;
  20. ; not be compatible with all computers now or in the future.  It's usually   ;
  21. ; better, where possible, to use operating system (DOS) calls.  The file     ;
  22. ; DOS.MAC provides similar routines using DOS.                               ;
  23. ;                                                                            ;
  24. ; The defined macros are:                                                    ;
  25. ;                                                                            ;
  26. ; BIOS_KEYBOARD_INPUT   input a keystroke (1)                                ;
  27. ; BIOS_KEYBOARD_STATUS  return the keyboard status (1)                       ;
  28. ; BIOS_SHIFT_STATUS     return the keyboard shift status                     ;
  29. ; BIOS_BELL             sound the speaker (1)                                ;
  30. ; BIOS_CLEAR_SCREEN     clear the screen and home the cursor (2)             ;
  31. ; BIOS_VIDEO            return the present video state                       ;
  32. ; BIOS_VIDEO_MODE       set the video mode (2)                               ;
  33. ; BIOS_PAGE             set the active display page                          ;
  34. ; BIOS_CURSOR_SHAPE     set the cursor shape                                 ;
  35. ; BIOS_CURSOR_MOVE      move the cursor (2)                                  ;
  36. ; BIOS_CURSOR_POSITION  return the cursor position  (2)                      ;
  37. ; BIOS_DISPLAY          display a character (1)                              ;
  38. ; BIOS_TYPE             type a character (1)                                 ;
  39. ; BIOS_SCROLL           scroll a display window                              ;
  40. ; BIOS_PRINTER_STATUS   return the printer status                            ;
  41. ; BIOS_PRINTER_RESET    reset the printer                                    ;
  42. ;                                                                            ;
  43. ; (1) Function can be implemented directly through DOS.                      ;
  44. ; (2) Function can be implemented through DOS via ANSI escape sequences.     ;
  45. ;============================================================================;
  46.  
  47. ;===============================================;
  48. ;              Bios_Keyboard_Input              ;
  49. ;                                               ;
  50. ; Return the next key in keyboard beffer. If    ;
  51. ; none available, wait for one. AL returns the  ;
  52. ; ASCII code and AH returns the keyboard scan   ;
  53. ; code.                                         ;
  54. ;                                               ;
  55. ; ASCII - optional storage for the ASCII code   ;
  56. ;   returned: 8 bit register or memory.         ;
  57. ; SCAN - optional storage for the scan code     ;
  58. ;   returned: 8 bit register or memory.         ;
  59. ;===============================================;
  60.  
  61. Bios_Keyboard_Input Macro Ascii, Scan
  62.  Sub Ah, Ah             ;function number
  63.  Int 16h                ;execute
  64.  If_Exist Ascii
  65.   Mov Ascii, Al         ;save ascii code
  66.  Endif
  67.  If_Exist Scan
  68.   Mov Scan, Ah          ;save scan code
  69.  Endif
  70.  Endm
  71.  
  72. ;===============================================;
  73. ;              Bios_Keyboard_Status             ;
  74. ;                                               ;
  75. ; Return the keyboard status. Zero flag is set  ;
  76. ; if there are no characters waiting, otherwise ;
  77. ; the zero flag is cleared and AL returns the   ;
  78. ; ASCII code and AH returns the keyboard scan   ;
  79. ; code of the key that is waiting (without      ;
  80. ; removing it from the buffer).                 ;
  81. ;                                               ;
  82. ; ASCII - optional storage for the ASCII code   ;
  83. ;   of next key in buffer: 8 bit register or    ;
  84. ;   memory.                                     ;
  85. ; SCAN - optional storage for the scan code     ;
  86. ;   or next key in buffer: 8 bit register or    ;
  87. ;   memory.                                     ;
  88. ;===============================================;
  89.  
  90. Bios_Keyboard_Status Macro Ascii, Scan
  91.  Mov Ah, 1              ;function number
  92.  Int 16h                ;execute
  93.  If_Exist Ascii
  94.   Mov Ascii, Al         ;save ascii code
  95.  Endif
  96.  If_Exist Scan
  97.   Mov Scan, Ah          ;save scan code
  98.  Endif
  99.  Endm
  100.  
  101. ;===============================================;
  102. ;                Bios_Shift_Status              ;
  103. ;                                               ;
  104. ; Return the present keyboard shift status. AL  ;
  105. ; returns the status.                           ;
  106. ;                                               ;
  107. ; STATUS - optional storage for the shift       ;
  108. ;   status: 16 bit register or memory.          ;
  109. ;===============================================;
  110.  
  111. Bios_Shift_Status Macro Status
  112.  Mov Ah, 2              ;function number
  113.  Int 16h                ;execute
  114.  If_Exist Status
  115.   Mov Status, Al        ;store shift status
  116.  Endif
  117.  Endm
  118.  
  119. ;===============================================;
  120. ;                    Bios_Bell                  ;
  121. ;                                               ;
  122. ; Sound the speaker. Prints a byte 7 with the   ;
  123. ; bios teletype function.                       ;
  124. ;===============================================;
  125.  
  126. Bios_Bell Macro
  127.  Bios_Type 7            ;teletype ascii 7
  128.  Endm
  129.  
  130. ;===============================================;
  131. ;                Bios_Clear_Screen              ;
  132. ;                                               ;
  133. ; Clear the active screen, move the cursor to   ;
  134. ; the upper left corner, and return information ;
  135. ; about the present video setup.                ;
  136. ;                                               ;
  137. ; ATTRIBUTE - optional attribute to be used in  ;
  138. ;   cleared screen: 8 bit register or immediate ;
  139. ;   data.                                       ;
  140. ; MODE - optional storage for the video mode:   ;
  141. ;   8 bit register or memory.                   ;
  142. ; COLUMNS - optional storage for the number of  ;
  143. ;   columns: 8 bit register or memory.          ;
  144. ; PAGE - optional storage for the active page:  ;
  145. ;   8 bit register or memory.                   ;
  146. ;                                               ;
  147. ; If attribute is not specified, the "normal"   ;
  148. ; attribute of 07H will be used.                ;
  149. ;===============================================;
  150.  
  151. Bios_Clear_Screen Macro Attribute, Mode, Columns, Page
  152.  Bios_Video Mode, Columns, Page ;set video info and get columns
  153.  Push Bx
  154.  If_Exist Attribute
  155.   Bios_Scroll 0, 0, 24, Ah, 0, Attribute ;clear screen
  156.  Else
  157.   Bios_Scroll 0, 0, 24, Ah, 0, 07h ;clear screen
  158.  Endif
  159.  Pop Bx
  160.  Bios_Cursor_Move 0, 0, Bh      ;move cursor home
  161.  Endm
  162.  
  163. ;===============================================;
  164. ;                  Bios_Video                   ;
  165. ;                                               ;
  166. ; Bios video state.  AL returns video mode, AH  ;
  167. ; number of screen columns, and BH active page. ;
  168. ;                                               ;
  169. ; MODE - optional storage for the video mode:   ;
  170. ;   8 bit register or memory.                   ;
  171. ; COLUMNS - optional storage for the number of  ;
  172. ;   columns: 8 bit register or memory.          ;
  173. ; PAGE - optional storage for the active page:  ;
  174. ;   8 bit register or memory.                   ;
  175. ;===============================================;
  176.  
  177. Bios_Video Macro Mode, Columns, Page
  178.  Mov Ah, 15             ;function number
  179.  Int 10h                ;execute
  180.  If_Exist Mode
  181.   Mov Mode, Al          ;save mode
  182.  Endif
  183.  If_Exist Columns
  184.   Mov Columns, Ah       ;save columns
  185.  Endif
  186.  If_Exist Page
  187.   Mov Page, Bh          ;save page
  188.  Endif
  189.  Endm
  190.  
  191. ;===============================================;
  192. ;                Bios_Video_Mode                ;
  193. ;                                               ;
  194. ; Set video mode.                               ;
  195. ;                                               ;
  196. ; MODE - video mode to set: 8 bit operand.      ;
  197. ;===============================================;
  198.  
  199. Bios_Video_Mode Macro Mode
  200.  Mov Al, Mode           ;set mode
  201.  Sub Ah, Ah             ;function number
  202.  Int 10h                ;execute
  203.  Endm
  204.  
  205. ;===============================================;
  206. ;                   Bios_Page                   ;
  207. ;                                               ;
  208. ; Set active display page.  Monochrome adapter  ;
  209. ; has only one page (0). CGA and EGA vary       ;
  210. ; according to mode. The present active page    ;
  211. ; can be found with BIO_VIDEO.                  ;
  212. ;                                               ;
  213. ; PAGE - display page to activate: 8 bit        ;
  214. ; operand.                                      ;
  215. ;===============================================;
  216.  
  217. Bios_Page Macro Page
  218.  Mov Al, Page           ;page
  219.  Mov Ah, 5              ;function number
  220.  Int 10h                ;execute
  221.  Endm
  222.  
  223. ;===============================================;
  224. ;                 Bios_Cursor_Kill              ;
  225. ;                                               ;
  226. ; Try to make the cursor disappear by moving it ;
  227. ; off the screen.                               ;
  228. ;===============================================;
  229.  
  230. Bios_Cursor_Kill Macro
  231.  Bios_Cursor_Move 255, 255, 0
  232.  Endm
  233.  
  234. ;===============================================;
  235. ;               Bios_Cursor_Shape               ;
  236. ;                                               ;
  237. ; Set the shape of the cursor. A monochrome     ;
  238. ; adapter cursor has 14 scan lines (0 to 13)    ;
  239. ; and CGA has 8 (0 to 7).                       ;
  240. ;                                               ;
  241. ; START - starting scan line number: 8 bit      ;
  242. ;   register or immediate data.                 ;
  243. ; END - ending scan line number: 8 bit register ;
  244. ;   or immediate data.                          ;
  245. ;===============================================;
  246.  
  247. Bios_Cursor_Shape Macro Start, End
  248.  Push Cx                ;parameters on stack
  249.  Mov Bp, Sp
  250.  Mov Byte [Bp+1], Start ;starting line
  251.  Mov Byte [Bp], End     ;finishing line
  252.  Pop Cx                 ;restore parameters
  253.  Mov Ah,1               ;function number
  254.  Int 10h                ;execute
  255.  Endm
  256.  
  257. ;===============================================;
  258. ;                Bios_Cursor_Move               ;
  259. ;                                               ;
  260. ; Move the cursor.                              ;
  261. ;                                               ;
  262. ; ROW - row position: 8 bit register or         ;
  263. ;   immediate data.                             ;
  264. ; COLUMN - column position: 8 bit register or   ;
  265. ;   immediate data.                             ;
  266. ; PAGE - display page (must be zero in graphics ;
  267. ;   mode): 8 bit register or immediate data.    ;
  268. ;                                               ;
  269. ; A cursor position is maintained for each      ;
  270. ; display page. If a page is not specified,     ;
  271. ; the routine will get the active page via a    ;
  272. ; BIOS_VIDEO call. The first row or column is   ;
  273. ; zero.                                         ;
  274. ;===============================================;
  275.  
  276. Bios_Cursor_Move Macro Row, Column, Page
  277.  Push Bx
  278.  Push Dx
  279.  Mov Bp, Sp
  280.  Mov Byte [Bp+1], Row   ;row
  281.  Mov Byte [Bp], Column  ;column
  282.  If_Exist Page
  283.   Mov Byte [Bp+3], Page ;page
  284.  Else
  285.   Push Ax
  286.   Push Bx
  287.   Push Cx
  288.   Push Dx
  289.   Push Di
  290.   Push Si
  291.   Push Bp
  292.   Bios_Video            ;get page
  293.   Pop Bp
  294.   Mov [Bp+3], Bh        ;set page
  295.   Pop Si
  296.   Pop Di
  297.   Pop Dx
  298.   Pop Cx
  299.   Pop Bx
  300.   Pop Ax
  301.  Endif
  302.  Pop Dx
  303.  Pop Bx                 ;restore parameters
  304.  Mov Ah,2               ;function number
  305.  Int 10h                ;execute
  306.  Endm
  307.  
  308. ;===============================================;
  309. ;              Bios_Cursor_Position             ;
  310. ;                                               ;
  311. ; Return the present cursor position.           ;
  312. ;                                               ;
  313. ; ROW - optional storage for the row: 8 bit     ;
  314. ;   register or memory.                         ;
  315. ; COLUMN - optional storage for the column: 8   ;
  316. ;   bit register or memory.                     ;
  317. ; PAGE - display page (must be zero in graphics ;
  318. ;   mode): 8 bit register or immediate data.    ;
  319. ;                                               ;
  320. ; A cursor position is maintained for each      ;
  321. ; display page. If a page is not specified,     ;
  322. ; the routine will get the active page via a    ;
  323. ; BIOS_VIDEO call. The first row or column is   ;
  324. ; considered zero.                              ;
  325. ;===============================================;
  326.  
  327. Bios_Cursor_Position Macro Row, Column, Page
  328.  If_Exist Page
  329.   Mov Bh, Page          ;set page
  330.  Else
  331.   Bios_Video            ;get page (returns in BH)
  332.  Endif
  333.  Mov Ah, 3              ;function number
  334.  Int 10h                ;execute
  335.  If_Exist Row
  336.   Mov Row, Dh           ;save row
  337.  Endif
  338.  If_Exist Column
  339.   Mov Column, Dl        ;save column
  340.  Endif
  341.  Endm
  342.  
  343. ;===============================================;
  344. ;                  Bios_Display                 ;
  345. ;                                               ;
  346. ; Bios character display. The cursor is not     ;
  347. ; moved and no interpretation takes place.      ;
  348. ;                                               ;
  349. ; CHAR - character to display: 8 bit register   ;
  350. ;   or immediate data.                          ;
  351. ; COLOR - optional attribute to display the     ;
  352. ;   character with: 8 bit register or immediate ;
  353. ;   data.                                       ;
  354. ; COUNT - optional number of characters to      ;
  355. ;   display: 8 bit register or immediate data.  ;
  356. ; PAGE - optional page number in which to       ;
  357. ;   display characters: 8 bit register or       ;
  358. ;   immediate data.                             ;
  359. ;                                               ;
  360. ; If a page is not specified, the routine will  ;
  361. ; get the page via a BIOS_VIDEO call.           ;
  362. ;===============================================;
  363.  
  364. Bios_Display Macro Char, Color, Count, Page
  365.  Push Ax
  366.  Push Bx
  367.  Push Cx                ;parameters on stack
  368.  Mov Bp, Sp
  369.  Mov Byte [Bp+4], Char  ;character to display
  370.  If_Exist Color
  371.   Mov Byte [Bp+2], Color ;attribute
  372.  Endif
  373.  If_Exist Page
  374.   Mov Byte [Bp+3], Page ;page
  375.  Else
  376.   Push Ax               ;save all regs, might be needed
  377.   Push Bx
  378.   Push Cx
  379.   Push Dx
  380.   Push Di
  381.   Push Si
  382.   Push Bp
  383.   Bios_Video            ;get page
  384.   Pop Bp
  385.   Mov [Bp+3], Bh        ;set page
  386.   Pop Si
  387.   Pop Di
  388.   Pop Dx
  389.   Pop Cx
  390.   Pop Bx
  391.   Pop Ax
  392.  Endif
  393.  If_Exist Count
  394.   If Size(Count) And Size(Ax)
  395.    Mov Word [Bp], Count ;set count
  396.   Else
  397.    Mov Byte [Bp], Count ;set low count byte
  398.    Mov Byte [Bp+1], 0   ;high byte 0
  399.   Endif
  400.  Else
  401.   Mov Word [Bp], 1      ;no count, set to one
  402.  Endif
  403.  Pop Cx
  404.  Pop Bx
  405.  Pop Ax                 ;restore parameters
  406.  If_Exist Color
  407.   Mov Ah, 9             ;display with attribute
  408.  Else
  409.   Mov Ah, 10            ;display without attribute
  410.  Endif
  411.  Int 10h                ;execute
  412.  Endm
  413.  
  414. ;===============================================;
  415. ;                   Bios_Type                   ;
  416. ;                                               ;
  417. ; Bios teletype. Cursor is moved and CR, LF,    ;
  418. ; BS, and BEL are interpreted.                  ;
  419. ;                                               ;
  420. ; CHAR - character to display: 8 bit register   ;
  421. ;   or immdiate data.                           ;
  422. ; COLOR - foreground color (valid only in       ;
  423. ;   graphics mode): 8 bit register or immediate ;
  424. ;   data.                                       ;
  425. ;===============================================;
  426.  
  427. Bios_Type Macro Char, Color
  428.  Push Ax                ;parameters on stack
  429.  Mov Bp, Sp
  430.  Mov Byte [Bp], Char    ;character to display
  431.  If_Exist Color
  432.   Mov Bl, Color         ;set color
  433.  Endif
  434.  Pop Ax                 ;restore parameters
  435.  Mov Ah, 14             ;function number
  436.  Int 10h                ;execute
  437.  Endm
  438.  
  439. ;===============================================;
  440. ;                   Bios_Scroll                 ;
  441. ;                                               ;
  442. ; Clear or scroll a display window up. A scroll ;
  443. ; of zero clears window.                        ;
  444. ;                                               ;
  445. ; START_ROW - upper left row coordinate: 8 bit  ;
  446. ;   register or immediate data.                 ;
  447. ; START_COL - upper left column coordinate: 8   ;
  448. ;   bit register or immediate data.             ;
  449. ; END_ROW - lower right row coordinate: 8 bit   ;
  450. ;   register or immediate data.                 ;
  451. ; END_COL - lower right column coordinate: 8    ;
  452. ;   bit register or immediate data.             ;
  453. ; LINES - number of lines to scroll up (zero if ;
  454. ;   clear window): 8 bit register or immediate  ;
  455. ;   data.                                       ;
  456. ; ATTRIBUTE - attribute to use in blanked       ;
  457. ;   areas: 8 bit register or immediate data.    ;
  458. ;                                               ;
  459. ; The first row or column is zero.              ;
  460. ;===============================================;
  461.  
  462. Bios_Scroll Macro Start_Row, Start_Col, End_Row, End_Col, Lines, Attribute
  463.  Push Ax                ;parameters on stack
  464.  Push Cx
  465.  Push Dx
  466.  Mov Bp, Sp
  467.  Mov Byte [Bp+3], Start_Row ;upper left row
  468.  Mov Byte [Bp+2], Start_Col ;upper left column
  469.  Mov Byte [Bp+1], End_Row ;lower right row
  470.  Mov Byte [Bp], End_Col ;lower right column
  471.  Mov Byte [Bp+4], Lines ;lines to scroll
  472.  Mov Byte [Bp+5], Attribute ;attribute to use in blanks
  473.  Pop Dx
  474.  Pop Cx
  475.  Pop Ax
  476.  Mov Bh, Ah             ;set attibute register
  477.  Mov Ah, 6              ;function number
  478.  Int 10h                ;execute
  479.  Endm
  480.  
  481. ;===============================================;
  482. ;               Bios_Printer_Status             ;
  483. ;                                               ;
  484. ; Return the status of a parallel printer. AH   ;
  485. ; returns status.                               ;
  486. ;                                               ;
  487. ; PRINTER - printer number: 16 bit operand.     ;
  488. ; STATUS - optional storage for printer status: ;
  489. ;   8 bit register or memory.                   ;
  490. ;                                               ;
  491. ; The printers are numbered 0 to 2.             ;
  492. ;===============================================;
  493.  
  494. Bios_Printer_Status Macro Printer, Status
  495.  Mov Dx, Printer        ;set printer number
  496.  Mov Ah, 2              ;function number
  497.  Int 17h                ;execute
  498.  If_Exist Status
  499.   Mov Status, Ah        ;store status
  500.  Endif
  501.  Endm
  502.  
  503. ;===============================================;
  504. ;               Bios_Printer_Reset              ;
  505. ;                                               ;
  506. ; Initialize a parallel printer port. AH        ;
  507. ; returns status.                               ;
  508. ;                                               ;
  509. ; PRINTER - printer number to initialize: 16    ;
  510. ;   bit operand.                                ;
  511. ; STATUS - optional storage for printer status: ;
  512. ;   8 bit register or memory.                   ;
  513. ;                                               ;
  514. ; The printers are numbered 0 to 2.             ;
  515. ;===============================================;
  516.  
  517. Bios_Printer_Reset Macro Printer, Status
  518.  Mov Dx, Printer        ;set printer number
  519.  Mov Ah, 1              ;function number
  520.  Int 17h                ;execute
  521.  If_Exist Status
  522.   Mov Status, Ah        ;store status
  523.  Endif
  524.  Endm
  525.  
  526.