home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tasm / ibios.mac < prev    next >
Text File  |  1988-08-28  |  13KB  |  500 lines

  1.  
  2. ;   FILENAME: IBIOS.MAC
  3. ;
  4. ;   Copyright (c) 1988 by Borland International, Inc.
  5. ;
  6. ;   DESCRIPTION: This include file contains various macros that may
  7. ;   be used to communicate with the IBM-PC's BIOS. This include file uses
  8. ;   Ideal mode syntax. For documentation on the macros in this file see the
  9. ;   file BIOSMAC.DOC.
  10. ;
  11. ;   NOTE: In order to use this macro file you must also include the files
  12. ;   IMACROS.MAC and BIOS.EQU in your module.
  13.  
  14.  
  15.  
  16. macro   CallBIOS    Interrupt, Service
  17.     macro   ErrMsg
  18.         display "Caller must provide Interrupt and Service parameters to CallBIOS."
  19.         err
  20.     endm
  21.  
  22.     ifb <Interrupt>
  23.         ErrMsg
  24.     else
  25.         ifb <Service>
  26.             ErrMsg
  27.         else
  28.             mov     ah, Service         ; Select the service
  29.             int     Interrupt           ; Do the interrupt
  30.         endif
  31.     endif
  32. endm
  33.  
  34.  
  35. macro   LoadBH  Value
  36.     ifb <Value>
  37.         xor     bh, bh
  38.     else
  39.         ifidni  <bh>, <Value>
  40.             ; Do nothing
  41.         else
  42.             mov     bh, Value
  43.         endif
  44.     endif
  45. endm
  46.  
  47.  
  48. macro   GotoXY  Row, Column, Page
  49.     macro   ErrMsg
  50.         display "The caller must provide the row and column parameters to GotoXY."
  51.         err
  52.     endm
  53.  
  54.     ifb <Row>
  55.         ErrMsg
  56.     else
  57.         ifb <Column>
  58.             ErrMsg
  59.         else
  60.             LoadBH  <Page>
  61.             mov     dh, Row
  62.             mov     dl, Column
  63.             CallBIOS    <VIDEO_SERVICE>, <INT10_SET_CURSOR_POS>
  64.         endif
  65.     endif
  66. endm
  67.  
  68. macro   WhereXY Page
  69.     LoadBH  <Page>
  70.     CallBIOS    <VIDEO_SERVICE>, <INT10_READ_CURSOR>
  71. endm
  72.  
  73.  
  74. macro   GetVideoMode
  75.     CallBIOS    <VIDEO_SERVICE>, <INT10_GET_MODE>
  76. endm
  77.  
  78. macro   ScrollUp    LineCount, Attrib, x1, y1, x2, y2
  79.     macro   ErrMsg1
  80.         display "Caller must provide LineCount and Attribute parameters to ScrollUp."
  81.         err
  82.     endm
  83.  
  84.     macro   ErrMsg2
  85.         display "Must provide all coordinate parameters to ScrollUp macro."
  86.         err
  87.     endm
  88.  
  89.     ifb <LineCount>
  90.         ErrMsg1
  91.     else
  92.         mov     al, LineCount
  93.         ifb <Attrib>
  94.             ErrMsg1
  95.         else
  96.             LoadBH  <Attrib>
  97.         endif
  98.         ifb <x1>
  99.             mov     ch, 0               ; Use default screen coordinates
  100.             mov     cl, 0
  101.             mov     dh, 79d
  102.             ScreenRows                  ; Get current number of rows
  103.             mov     dl, al
  104.         else
  105.             ifb <y1>
  106.                 ErrMsg2
  107.             else
  108.                 ifb <x2>
  109.                     ErrMsg2
  110.                 else
  111.                     ifb <y2>
  112.                         ErrMsg2
  113.                     else                ; All the parameters were provided
  114.                         mov     ch, x1  ; Define screen area to scroll.
  115.                         mov     cl, y1
  116.                         mov     dh, y2
  117.                         mov     dl, x2
  118.                     endif
  119.                 endif
  120.             endif
  121.         endif
  122.         CallBIOS    <VIDEO_SERVICE>, <INT10_SCROLL_UP>
  123.     endif
  124. endm
  125.  
  126. macro   ScrollDown    LineCount, Attrib, x1, y1, x2, y2
  127.     macro   ErrMsg1
  128.         display "Caller must provide LineCount and Attribute parameters to ScrollDown."
  129.         err
  130.     endm
  131.  
  132.     macro   ErrMsg2
  133.         display "Must provide all coordinate parameters to ScrollDown macro."
  134.         err
  135.     endm
  136.  
  137.     ifb <LineCount>
  138.         ErrMsg1
  139.     else
  140.         mov     al, LineCount
  141.         ifb <Attrib>
  142.             ErrMsg1
  143.         else
  144.             LoadBH  <Attrib>
  145.         endif
  146.         ifb <x1>
  147.             mov     ch, 0               ; Use default screen coordinates
  148.             mov     cl, 0
  149.             mov     dh, 79d
  150.             ScreenRows                  ; Get current number of rows
  151.             mov     dl, al
  152.         else
  153.             ifb <y1>
  154.                 ErrMsg2
  155.             else
  156.                 ifb <x2>
  157.                     ErrMsg2
  158.                 else
  159.                     ifb <y2>
  160.                         ErrMsg2
  161.                     else                ; All the parameters were provided
  162.                         mov     ch, x1  ; Define screen area to scroll.
  163.                         mov     cl, y1
  164.                         mov     dh, y2
  165.                         mov     dl, x2
  166.                     endif
  167.                 endif
  168.             endif
  169.         endif
  170.         CallBIOS    <VIDEO_SERVICE>, <INT10_SCROLL_DOWN>
  171.     endif
  172. endm
  173.  
  174. macro SetVideoMode  Mode
  175.     ifb <Mode>
  176.         display "Caller must provide Mode parameter to SetVideoMode."
  177.         err
  178.     else
  179.         ifidni  <al>, <Mode>
  180.             ; Do nothing
  181.         else
  182.             mov     al, Mode
  183.         endif
  184.         CallBIOS    <VIDEO_SERVICE>, <INT10_SET_MODE>
  185.     endif
  186. endm
  187.  
  188. macro   SetCursorShape  Starting, Ending
  189.     ifb <Starting>
  190.         display "You must specify the Starting and Ending parameters to the"
  191.         display "call to SetCursorShape."
  192.         err
  193.     endif
  194.     ifb <Ending>
  195.         display "You must supply the Ending scan line parameter to the call"
  196.         display "to SetCursorShape."
  197.         err
  198.     endif
  199.     ifidni  <ch>, <Starting>
  200.         ; Do nothing
  201.     else
  202.         mov     ch, Starting                ; Store starting scan line
  203.     endif
  204.     ifidni  <cl>, <Ending>
  205.         ; Do nothing
  206.     else
  207.         mov     cl, Ending                  ; Store ending scan line
  208.     endif
  209.     CallBIOS    <VIDEO_SERVICE>, <INT10_SET_CURSOR_SHAPE>
  210. endm
  211.  
  212. macro   GetCursorShape
  213.     WhereXY                 ; Get cursor position and shape
  214. endm
  215.  
  216. macro   GetLightPenPos
  217.     CallBIOS    <VIDEO_SERVICE>, <INT10_READ_LIGHT_PEN>
  218. endm
  219.  
  220. macro   SetDisplayPage  Page
  221.     ifb <Page>
  222.         xor     al, al      ; Use default video page of 0
  223.     else
  224.         ifidni  <al>, <Page>
  225.             ; Do nothing
  226.         else
  227.             mov     al, Page
  228.         endif
  229.     endif
  230.     CallBIOS    <VIDEO_SERVICE>, <INT10_SELECT_DISPLAY_PAGE>
  231. endm
  232.  
  233. macro   GetCharAttr Page
  234.     LoadBH  <Page>
  235.     CallBIOS    <VIDEO_SERVICE>, <INT10_READ_ATTR_CHAR>
  236. endm
  237.  
  238. macro   PutCharAttr Character, Attribute, Count, Page
  239.     macro   ErrMsg
  240.         display "You must provide character/attribute and count parameters to PutCharAttr."
  241.         err
  242.     endm
  243.  
  244.     ifb <Character>
  245.         ErrMsg
  246.     else
  247.         ifb <Attribute>
  248.             ErrMsg
  249.         else
  250.             ifb <Count>
  251.                 ErrMsg
  252.             else
  253.                 LoadBH  <Page>
  254.                 mov     bl, Attribute
  255.                 mov     al, Character
  256.                 mov     cx, Count
  257.                 CallBIOS    <VIDEO_SERVICE>, <INT10_WRITE_ATTR_CHAR>
  258.             endif
  259.         endif
  260.     endif
  261. endm
  262.  
  263. macro   PutChar Character, Count, Page, Color
  264.     macro   ErrMsg
  265.         display "You must provide character and count parameters to PutChar."
  266.         err
  267.     endm
  268.  
  269.     ifb <Character>
  270.         ErrMsg
  271.     else
  272.         ifb <Count>
  273.             ErrMsg
  274.         else
  275.             LoadBH  <Page>
  276.             ifb <Color>             ; Determine the attribute
  277.                 GetCharAttr <bh>
  278.                 mov     bl, ah
  279.             else
  280.                 mov     bl, Color
  281.             endif
  282.             mov     al, Character
  283.             mov     cx, Count
  284.             CallBIOS    <VIDEO_SERVICE>, <INT10_WRITE_CHAR>
  285.         endif
  286.     endif
  287. endm
  288.  
  289. macro   SetColorPalette Entry, Color
  290.     macro   ErrMsg
  291.         display "You must provide Entry and Color parameters to SetColorPalette."
  292.         err
  293.     endm
  294.  
  295.     ifb <Entry>
  296.         ErrMsg
  297.     else
  298.         ifb <Color>
  299.             ErrMsg
  300.         else
  301.             LoadBH  <Entry>
  302.             mov     bl, Color
  303.             CallBIOS    <VIDEO_SERVICE>, <INT10_SET_COLOR_PALETTE>
  304.         endif
  305.     endif
  306. endm
  307.  
  308. macro   PutPixel    X, Y, Color
  309.     macro   ErrMsg
  310.         display "You must provide coordinate and color parameters to PutPixel."
  311.         err
  312.     endm
  313.  
  314.     ifb <X>
  315.         ErrMsg
  316.     else
  317.         ifb <Y>
  318.             ErrMsg
  319.         else
  320.             ifb <Color>
  321.                 ErrMsg
  322.             else
  323.                 mov     al, Color
  324.                 mov     cx, X
  325.                 mov     dx, Y
  326.                 CallBIOS    <VIDEO_SERVICE>, <INT10_WRITE_PIXEL>
  327.             endif
  328.         endif
  329.     endif
  330. endm
  331.  
  332. macro   GetPixel    X, Y
  333.     macro   ErrMsg
  334.         display "You must provide coordinate parameters to GetPixel."
  335.         err
  336.     endm
  337.  
  338.     ifb <X>
  339.         ErrMsg
  340.     else
  341.         ifb <Y>
  342.             ErrMsg
  343.         else
  344.             mov     cx, X
  345.             mov     dx, Y
  346.             CallBIOS    <VIDEO_SERVICE>, <INT10_READ_PIXEL>
  347.         endif
  348.     endif
  349. endm
  350.  
  351. macro   PutTTY  Character, Page, Color
  352.     macro   ErrMsg
  353.         display "You must provide character, page and color parameters to PutTTY."
  354.         err
  355.     endm
  356.  
  357.     ifb <Character>
  358.         ErrMsg
  359.     else
  360.         ifb <Page>
  361.             ErrMsg
  362.         else
  363.             ifnb <Color>
  364.                 mov     bl, Color
  365.             else
  366.                 mov     al, Character
  367.                 LoadBH  <Page>
  368.                 CallBIOS    <VIDEO_SERVICE>, <INT10_WRITE_TTY>
  369.             endif
  370.         endif
  371.     endif
  372. endm
  373.  
  374. macro   SetPaletteRegs    SubService, IndexIntensity, Color, ListSeg, ListOfs
  375.     local   RegToSet, BlinkIntensity, ListAddr, DoCall
  376.  
  377.     macro   ErrMsg
  378.         display "You must provide the SubService, IndexIntensity, Color and"
  379.         display "address parameters to SetPaletteRegs."
  380.         err
  381.     endm
  382.  
  383.     ifb <SubService>
  384.         ErrMsg
  385.     else
  386.         ifb <IndexIntensity>
  387.             ErrMsg
  388.         else
  389.             ifb <Color>
  390.                 ErrMsg
  391.             else
  392.                 ifb <ListSeg>
  393.                     ErrMsg
  394.                 else
  395.                     ifb <ListOfs>
  396.                         ErrMsg
  397.                     else
  398.                         mov     al, SubService  ; Indicate palette service
  399.                         mov     bh, Color       ; Store color
  400.                         cmp     al, 00h         ; If al = 0 we are setting
  401.                                                 ; a palette register
  402.                         jne     short ListAddr
  403.  
  404.                         ; Indicate which palette register
  405.  
  406.                         mov     bl, IndexIntensity
  407.                         jmp     short DoCall
  408.                     ListAddr:
  409.                         cmp     al, 02h ; If al = 2 we have a pointer to
  410.                                         ;a list
  411.                         jne     short BlinkIntensity
  412.                         LoadSegment <es>, <ListSeg>
  413.                         mov     dx, ListOfs
  414.                         jmp     short DoCall
  415.                     BlinkIntensity: ; Indicate blinking or intensity
  416.                         mov     bl, IndexIntensity
  417.                     DoCall:
  418.                         CallBIOS    <VIDEO_SERVICE>, <INT10_SET_PALETTE_REGS>
  419.                     endif
  420.                 endif
  421.             endif
  422.         endif
  423.     endif
  424. endm
  425.  
  426. macro   PutString   Mode, X, Y, StringSeg, StringOfs, Length, Page, Attribute
  427.     local   DoCall
  428.  
  429.     macro   ErrMsg
  430.         display "Call to PutString requires appropriate parameters."
  431.         err
  432.     endm
  433.  
  434.     ifb <Mode>                      ; Verify that parameters were provided
  435.         ErrMsg
  436.     else
  437.         ifb <X>
  438.             ErrMsg
  439.         else
  440.             ifb <Y>
  441.                 ErrMsg
  442.             else
  443.                 ifb <StringSeg>
  444.                     ErrMsg
  445.                 else
  446.                     ifb <StringOfs>
  447.                         ErrMsg
  448.                     else
  449.                         ifb  <Length>
  450.                             ErrMsg
  451.                         else
  452.                             ifb <Page>  ; Neither Page or Attribute are
  453.                                         ; provided
  454.                                 xor     bh, bh  ; Use default page of 0
  455.  
  456.                                 ; Using mode 2 or 3
  457.  
  458.                             else
  459.                                 ifnb <Attribute>
  460.  
  461.                                     ; Using Mode 0 or 1
  462.  
  463.                                     mov     bl, Attribute
  464.                                 endif
  465.                                 mov     bh, Page
  466.                             endif
  467.                             mov     cx, Length
  468.                             mov     dh, Y
  469.                             mov     dl, X
  470.                             LoadSegment <es>, <StringSeg>
  471.                             mov     bp, StringOfs
  472.                             mov     al, Mode
  473.                             CallBIOS    <VIDEO_SERVICE>, <INT10_WRITE_STRING>
  474.                         endif
  475.                     endif
  476.                 endif
  477.             endif
  478.         endif
  479.     endif
  480. endm
  481.  
  482. macro   ScreenRows
  483.     mov     dl, 25d                 ; Assume 25 lines
  484.     mov     al, 30h
  485.     CallBIOS    <VIDEO_SERVICE>, <INT10_FONT_SIZE>
  486. endm
  487.  
  488. macro   GetChar
  489.     CallBIOS    <KEYBOARD_SERVICE>, <INT16_READ_CHAR>
  490. endm
  491.  
  492. macro   GetKbdStatus
  493.     CallBIOS    <KEYBOARD_SERVICE>, <INT16_KBD_STATUS>
  494. endm
  495.  
  496. macro   GetKbdFlags
  497.     CallBIOS    <KEYBOARD_SERVICE>, <INT16_KBD_FLAGS>
  498. endm
  499.  
  500.