home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / PCHCFUNC.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-06-29  |  5.9 KB  |  237 lines

  1. ; pchcfunc.asm
  2. ;
  3. ; 11/10/88 by Ted
  4. ;
  5. ; Low Level RAM functions for Cscape Hercules Graphics support
  6. ;
  7. ; Copyright (c) 1988, 1989 Oakland Group Inc.
  8. ; ALL RIGHTS RESERVED
  9. ;
  10. ; This file contains the low level routines used by display code
  11. ; to talk to the Hercules Display Card
  12. ;
  13. ;------------------------REVISION HISTORY--------------------------------------;
  14. ;
  15. ;------------------------------------------------------------------------------;
  16. include    PCDECL.MAC
  17.  
  18. DOS_DATA_PAGE    equ    40h
  19. ADDR_6845        equ    63h
  20.  
  21. DSEG
  22.  
  23. crtcparms label word
  24.     db 00h, 35h
  25.     db 01h, 2Dh
  26.     db 02h, 2Eh
  27.     db 03h, 07h
  28.  
  29.     db 04h, 5Bh
  30.     db 05h, 02h
  31.     db 06h, 57h
  32.     db 07h, 57h
  33.  
  34.     db 09h, 03h
  35.  
  36. CRTCPARMSLEN    equ ($-crtcparms)/2
  37. ;---------
  38. BIOSDATAOFFS    equ 49h
  39.  
  40. biosdata label byte
  41.     db 7            ; crt_mode
  42.     dw 80            ; crt_cols
  43.     dw 8000h        ; crt_len
  44.     dw 0            ; crt_start
  45.     dw 8 dup(0)        ; cursor_posn
  46.     dw 0            ; cursor_mode
  47.     db 0            ; active_page
  48.     dw 3B4h            ; addr_6845
  49.     db 0Ah            ; crt_mode_set (val for 6845 mode control register)
  50.     db 0            ; crt_palette (unused)
  51.  
  52. BIOSDATALEN        equ $-biosdata
  53.  
  54. ENDDS
  55. ;------------------------------------------------------------------------------;
  56. retrace_wait macro                ;wait for video retrace
  57.     local L01, L02, L03            ;uses dx for crt port address, trashes al
  58.                                 ; leaves interrupts disabled
  59. L01:
  60.     in al, dx            ; wait for start of retrace
  61.     test al, 80h
  62.     jnz L01
  63. L02:
  64.     in al, dx            ; wait for end of retrace
  65.     test al, 80h
  66.     jz L02
  67.  
  68.     cli
  69. L03:
  70.     in al, dx            ; wait for start of retrace
  71.     test al, 80h
  72.     jnz L03
  73. endm
  74. ;------------------------------------------------------------------------------;
  75.     PSEG
  76. ;------------------------------------------------------------------------------;
  77. ; boolean herc_present();
  78. ;------------------------
  79. pubproc DIGPRIV    herc_present
  80.     mov dx, 03BAh        ; dx = crt status port
  81.     xor bl, bl            ; clear counter
  82.     in al, dx            ; first reading
  83.     and al, 80h            ; clear all but high bit
  84.     mov ah, al            ; save value in ah
  85.  
  86.     mov cx, 8000h        ; test this many times
  87. testchange:
  88.     in al, dx            ; get second reading
  89.     and al, 80h            ; clear all but high bit
  90.     cmp al, ah            ; if no change, keep testing
  91.     je nochange
  92.     inc bl                ; wait for 25 positives
  93.     cmp bl, 25
  94.     ja gotit            ; got 25 positives; quit
  95. nochange:
  96.     loop testchange
  97.     mov ax, 0            ; didn't get 25 out of 8000h; fail
  98.     jmp short endtest
  99. gotit:
  100.     mov ax, 1
  101. endtest:
  102.     ret
  103. endproc herc_present
  104. ;------------------------------------------------------------------------------;
  105. ;/*
  106. ;    Returns the approximate number of video lines the Herc is currently
  107. ;    displaying. For herc modes, the possible targets are:
  108. ;    7D0h - 80x25 text
  109. ;    DB6h - 90x39 text
  110. ;    DC0h - 80x44 text
  111. ;    F4Bh - 720x348 graphics
  112. ;*/
  113. ; int herc_getlines();
  114. ;------------------------
  115. pubproc DIGPRIV    herc_getlines
  116. ;---------
  117. ; reset light pen latch
  118.     mov dx, 03BBh        ; dx = light pen reset port
  119.     out dx, al            ; clear the latch (al don't care)
  120.  
  121. ; wait for start of next retrace
  122.     dec dx                ; dx = 03BAh (crt status port)
  123.     retrace_wait
  124.  
  125. ; latch the current crtc address counter in the light pen registers
  126.     dec dx                ; dx = 03B9h (latch load port)
  127.     out dx, al
  128.     sti
  129.  
  130. ; return the value in the light pen registers
  131.     mov dx, 03B4h        ; dx = crtc address port
  132.     mov al, 10h            ; al = light pen high register index
  133.     out dx, al
  134.     inc dx
  135.     in al, dx            ; read the register
  136.     mov ah, al
  137.     dec dx
  138.     mov al, 11h            ; al = light pen low register index
  139.     out dx, al
  140.     inc dx
  141.     in al, dx            ; read the register
  142.  
  143. ;---------
  144. ; ax now has the current light pen latch value, i.e. the value of the
  145. ; crtc address counter at start of vertical retrace.
  146.     ret
  147. endproc herc_getlines
  148. ;------------------------------------------------------------------------------;
  149. ; void herc_setgmode(int hpage);
  150. ;------------------------
  151. pubproc DIGPRIV    herc_setgmode <hpage>
  152.     push bp
  153.     mov bp,sp
  154.     pushm <ds, es, di, si>
  155. ;---------
  156.     mov bx, 0A01h    ; mode control bit for page 0, config switch bit for page 0
  157.     mov cl, 6        ; set vidmode 6 for page 0
  158.     cmp word ptr [bp].hpage, 0
  159.     jz page0
  160.     mov bx, 8A03h    ; mode control bit for page 1, config switch bit for page 1
  161.     mov cl, 5        ; set vidmode 5 for page 1
  162. page0:
  163.  
  164. ; update bios data area
  165.     mov ax, DOS_DATA_PAGE
  166.     mov es, ax
  167.     mov di, BIOSDATAOFFS
  168.  
  169. IF FAR_DATA
  170.     mov ax, seg DGROUP:biosdata
  171.     mov ds, ax
  172. ENDIF
  173.     mov si, offset DGROUP:biosdata
  174.     mov ds:[si], cl    ; poke the vidmode: 6 for page 0, 5 for page 1
  175.     mov cx, BIOSDATALEN
  176.     rep movsb
  177.  
  178. ; set configuration switch
  179.     mov dx, 3BFh    ; dx = configuration switch port
  180.     mov al, bl        ; al bit 0 = 1 means enable graphics
  181.     out dx, al        ; al bit 1 = 0 means only use first 32k of video buffer
  182.  
  183. ; blank the screen while programming crtc
  184.     mov dx, 3B8h    ; dx = mode control register
  185.     xor al, al        ; al bit 3 = 0 means disable video signal
  186.     out dx, al        ; blank the screen
  187.  
  188. ; program the crtc
  189.     sub dl, 4        ; dx = 3B4h = crtc index register
  190.     mov si, offset DGROUP:crtcparms
  191.     mov cx, CRTCPARMSLEN
  192. putout:
  193.     lodsw
  194.     out dx, ax
  195.     loop putout
  196.  
  197. ; wipe video buffer
  198.     mov ax, 0B000h
  199.     cmp word ptr [bp].hpage, 0
  200.     jz wpage0
  201.     mov ax, 0B800h
  202. wpage0:
  203.     mov es, ax
  204.     mov ax, 0
  205.     mov di, 0
  206.     mov cx, 4000h
  207.     rep stosw
  208.  
  209. ; set graphics mode
  210.     add dl, 4        ; dx = 3B8h = mode control register
  211.     mov al, bh        ; bit3 = 1 means enable video, bit1 = 1 means graphics mode
  212.     out dx, al        ; bit7 = 1 means page 1
  213.  
  214. ;---------
  215.     popm <si, di, es, ds>
  216.     pop    bp
  217.     ret
  218. endproc herc_setgmode
  219. ;------------------------------------------------------------------------------;
  220. ; void herc_settmode();
  221. ;------------------------
  222. pubproc DIGPRIV    herc_settmode
  223.     mov ax, 0007h
  224.     int 10h
  225.  
  226. ; set configuration switch
  227.     mov dx, 3BFh    ; dx = configuration switch port
  228.     mov al, 0        ; al bit 0 = 0 means disable graphics
  229.     out dx, al        ; al bit 1 = 0 means disable second graphics page
  230.     ret
  231. endproc herc_settmode
  232. ;------------------------------------------------------------------------------;
  233.     ENDPS
  234.     end
  235. ;------------------------------------------------------------------------------;
  236.  
  237.