home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / grafik / qbherc / herc.asm next >
Encoding:
Assembly Source File  |  1987-07-09  |  5.2 KB  |  243 lines

  1.     Page    ,132
  2.     
  3. ;    HERCULES (r) graphic support for QuickBASIC
  4. ;        Code by Jeff Sumberg, Ringwood NJ (July 1987)
  5.  
  6. ; To use these routines, either place the HERC.OBJ file into a user library
  7. ; using the Buildlib utility supplied with QuickBASIC or Link HERC.OBJ into
  8. ; your compiled code (BRUN or BCOM).
  9.  
  10. ; To call from a QuickBASIC program there are three entry points into this
  11. ; program:
  12.  
  13. ;    Call Graphic            Puts adapter card into Hercules
  14. ;                    graphic mode with page 0 enabled,
  15. ;                    in 'Half' mode (upper page is mapped 
  16. ;                    off)
  17.  
  18. ;    Call TextMode            Puts adapter card back into text mode
  19.  
  20. ;    Call Plot(Row,Col,Dot)        Used to place dots (Pixels) on the
  21. ;                    screen. Row (X) is the horizontal
  22. ;                    axis and is from 0 to 719. Col (Y)
  23. ;                    is the vertical axis and is from
  24. ;                    0 to 347. Dot is either a 0 or a 1
  25. ;                    and causes a pixel to appear (1) or
  26. ;                    disappear (0).
  27.  
  28. ;    All values in the calls MUST be INTEGER.
  29. ;    Page 1 is not supported.
  30.  
  31. ;    Example:
  32.  
  33. ;        Call Graphic            go into graphics mode
  34. ;        For X% = 0 to 200
  35. ;            Call Plot(X%,X%,1%)    Plot 0,0 to 200,200
  36. ;        Next X%
  37. ;        Do
  38. ;        Loop While Inkey$ = ""        wait for a key to be hit
  39. ;        Call TextMode            return to text mode
  40.  
  41. ; These routines are placed into the Public Domain, and I want nothing
  42. ; in return for their use. I also accept no responsibilty as to their
  43. ; use, misure, or inability to do as explained above. They worked for
  44. ; me, they should do the same for you. They were tried using a Leading
  45. ; Edge model D, and a ZuckerBoard Hercules clone card.
  46.  
  47. ; Hercules is a trademark of Hercules Computer Technology, Inc.
  48. ; QuickBASIC is a trademark of Microsoft, Inc.
  49.  
  50. ; Assembled using Microsoft's Macro Assembler, Version 4
  51.  
  52.     Public    Graphic,TextMode,Plot
  53. ;    Ports
  54.  
  55. Index    equ    03B4h
  56. Cntrl    equ    03B8h
  57.  
  58. ;    Control Codes
  59.  
  60. Scrn_on    equ    8
  61. Grph    equ    2
  62. Text    equ    20h
  63.  
  64. Pstack    Struc
  65.     DW    ?        ;BP
  66.     DW    ?        ;Roff
  67.     DW    ?        ;Rseg
  68. Light    DW    ?        ;Dot value
  69. Yloc    DW    ?        ;Vertical axis
  70. Xloc    DW    ?        ;Horizontal Axis
  71. Pstack    Ends
  72.  
  73. Xdata    Segment    Public    'Data'        ;Define the Data Segment
  74.  
  75. Gtable    DB    35h,2Dh,2Eh,07h
  76.     DB    5Bh,02H,57h,57h
  77.     DB    02h,03h,00h,00h
  78.     
  79. Ttable    DB    61h,50h,52h,0Fh
  80.     DB    19h,06h,19h,19h
  81.     DB    02h,0Dh,0Bh,0Ch
  82.     
  83. Xdata    Ends
  84.  
  85. Dgroup    Group    Xdata            ;Group our data seg in with QB's
  86.  
  87. Xcode    Segment    Public    'Code'
  88.     Assume    CS:Xcode, DS:Dgroup
  89.     
  90. Graphic    Proc    Far
  91.  
  92.     Push    ES
  93.     mov    al,1
  94.     mov    dx,3BFh        ;configuration switch register
  95.     out    dx,al        ;Set to half mode, enable graphics mode
  96.     Mov    al,Grph
  97.     Mov    si,Offset Dgroup:Gtable
  98.     Mov    bx,0
  99.     Mov    cx,4000h
  100.     Call    Setmd
  101.     Pop    es
  102.     Ret
  103.  
  104. Graphic    Endp
  105.  
  106. TextMode    Proc    Far
  107.  
  108.     Push    es
  109.     Mov    al,Text
  110.     Mov    si,Offset Dgroup:Ttable
  111.     Mov    bx,720h
  112.     Mov    cx,2000
  113.     Call    Setmd
  114.     Pop    es
  115.     Ret
  116.     
  117. TextMode    endp
  118.  
  119. Setmd    Proc    Near
  120.  
  121. ; Sets mode to graphics or text
  122. ; depending on AL
  123. ; SI = parameter table
  124. ; CX = number of words to be cleared
  125. ; BX = blank value
  126.  
  127.     Push    ds
  128.     Push    es
  129.     Push    ax
  130.     Push    bx
  131.     Push    cx
  132.  
  133. ; change mode but without scrn_on
  134.  
  135.     Mov    dx,cntrl
  136.     Out    dx,al
  137.     
  138. ; Init 6845
  139.  
  140.     mov    ax,ds
  141.     mov    es,ax
  142.     mov    dx,index
  143.     mov    cx,12
  144.     xor    ah,ah
  145. parms:    mov    al,ah
  146.     out    dx,al
  147.     inc    dx
  148.     lodsb
  149.     out    dx,al
  150.     inc    ah
  151.     dec    dx
  152.     loop    parms
  153.     pop    cx
  154.     mov    ax,0B000h
  155.     cld
  156.     mov    es,ax
  157.     xor    di,di
  158.     pop    ax
  159. rep    stosw
  160.  
  161. ; scrn_on, page 0
  162.  
  163.     mov    dx,cntrl
  164.     pop    ax
  165.     add    al,scrn_on
  166.     out    dx,al
  167.     pop    es
  168.     pop    ds
  169.     ret
  170. Setmd    endp
  171.  
  172. ; Dot plotting routines:
  173.  
  174. ; X/Y memory location is found by:
  175.  
  176. ; ((2000h * (Y Mod 4) + (90 * (y/4)) + (x / 8))
  177.  
  178. Plot    Proc    Far
  179.  
  180.     Push    bp        ;Save Qbasics BP pointer
  181.     mov    bp,sp        ;take a copy of the stack pointer
  182.     mov    ax,0B000h    ;Segment of graphics page ZERO
  183.     mov    es,ax        ;that goes to the extra segment reg
  184.     mov    bx,[bp].Yloc    ;pick up from the stack
  185.     mov    ax,[bx]        ;the Y value 
  186.     cmp    ax,347
  187.     jg    Exit
  188.     mov    bl,4
  189.     div    bl        ;divide it by 4
  190.     mov    cl,al        ;Quotient (Used in next step)
  191.     mov    al,ah        ;remainder (Mod 4 part)
  192.     cbw            ;convert remainder to a word
  193.     mov    dx,2000h
  194.     mul    dx        ;multiply remainder times 2000h
  195.     mov    si,ax        ; SI = 2000h * (Y Mod 4)
  196.     
  197.     mov    al,cl        ;Quotient from above
  198.     cbw            ;convert to a word
  199.     mov    dx,90
  200.     mul    dx        ;multiply times 90
  201.     mov    di,ax        ; DI = 90 * (Y / 4)
  202.     
  203.     mov    bx,[bp].Xloc    ;Pick up from the stack
  204.     mov    ax,[bx]        ;the X value 
  205.     cmp    ax,719
  206.     jg    exit
  207.     mov    bl,8
  208.     div    bl        ;divide it by 8
  209.     mov    cl,ah        ;save remainder (X Mod 8 part for below)
  210.     cbw            ; AX = X / 8
  211.     Add    ax,di        ;add all the results together to get
  212.     Add    ax,si        ;the final memory offset
  213.     mov    di,ax        ; DI = Offset into display page
  214.     
  215. ; Find the bit: 2 ^ (7 - (X mod 8))
  216.  
  217.     mov    ah,cl        ;get X Mod 8 (from abobe)
  218.     mov    al,7
  219.     sub    al,ah        ; 7-(X Mod 8) gives us the
  220.     mov    cl,al        ;shift count to the proper bit
  221.     mov    al,1        ;This is the starting bit mask to rotate
  222.     sal    al,cl        ;bit position in AL is the one to alter
  223.     mov    bx,[bp].Light    ;Get from the stack the parammeter that
  224.     mov    bx,[bx]        ;tells us if we turn on or off the bit
  225.     mov    ah,es:[di]    ;get screen memory byte
  226.     test    bl,1        ;test for turn bit on
  227.     jz    bit0        ;turn off if zero
  228.     or    ah,al        ;add the bit
  229.     jmp    fini        ;done
  230.  
  231. bit0:    not    al        ;flip the bits for turn off
  232.     and    ah,al        ;turn off the bit
  233.  
  234. fini:    mov    es:[di],ah    ;put back
  235. exit:    Pop    BP        ;restore Qbasic's original BP value
  236.     Ret    6        ;do a FAR return chucking 3 values on stack
  237.     
  238. Plot    EndP
  239.  
  240. Xcode    ends
  241.  
  242.     end
  243.