home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / PCHCFUNC.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-02-03  |  5.9 KB  |  238 lines

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