home *** CD-ROM | disk | FTP | other *** search
/ GRIPS 2: Government Rast…rocessing Software & Data / GRIPS_2.cdr / dos / imdisp / source / dispsub.asm < prev    next >
Encoding:
Assembly Source File  |  1990-04-20  |  14.7 KB  |  512 lines

  1.         TITLE   dispsub
  2.  
  3. ;   Assembly language subroutines for DISPDRIV module.
  4.  
  5.  
  6. DISPSUB_TEXT   SEGMENT  BYTE PUBLIC 'CODE'
  7. DISPSUB_TEXT   ENDS
  8. DISPSUB_DATA   SEGMENT  WORD PUBLIC 'DATA'
  9. DISPSUB_DATA   ENDS
  10. CONST          SEGMENT  WORD PUBLIC 'CONST'
  11. CONST          ENDS
  12. _BSS           SEGMENT  WORD PUBLIC 'BSS'
  13. _BSS           ENDS
  14. DGROUP  GROUP   CONST,  _BSS,   DISPSUB_DATA
  15.         ASSUME  CS: DISPSUB_TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  16. DISPSUB_DATA   SEGMENT
  17. DISPSUB_DATA   ENDS
  18.  
  19. DISPSUB_TEXT   SEGMENT
  20.  
  21. ; EgaRegs is the address of what would be the beginning of a complete set
  22. ; of register tables.  Since we are only using one particular mode, we don't
  23. ; allocate the entire set, but adjust EgaRegs backwards by the appropriate
  24. ; amount.  (Note that the offset of EgaRegs may actually be a negative
  25. ; number.  This does not cause any problem.)
  26.  
  27. EgaRegs equ     $-(40h*18)
  28.  
  29. ; Columns, rows, pixels, page size
  30.         db      80, 36, 14
  31.         dw      0B400h
  32.  
  33. ; Sequencer registers
  34.         db      01h, 0Fh, 00h, 06h
  35.  
  36. ; Miscellaneous output register
  37.         db      0ABh
  38.  
  39. ; CRTC parameters
  40.         db      64h, 4Fh, 53h, 21h, 53h, 00h, 0F0h, 1Fh, 8 dup (00h)
  41.         db      0E0h, 2Ch, 0DFh, 28h, 0Fh, 0E1h, 0Ch, 0E3h, 0FFh
  42.  
  43. ; Attribute registers
  44.         db      00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
  45.         db      38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
  46.         db      01h, 00h, 0Fh, 00h
  47.  
  48. ; Graphics controller registers
  49.         db      00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh
  50.  
  51.         PUBLIC  _putmem
  52. _putmem PROC FAR
  53.         push    bp
  54.         mov     bp,sp
  55.  
  56. ;       segment = 4
  57. ;       offset = 6
  58. ;       value = 8
  59.  
  60.         mov     es, [bp+6]      ;segment
  61.         mov     bx,[bp+8]       ;offset
  62.         mov     ax,[bp+10]       ;value
  63.         mov     es:[bx],al
  64.  
  65.         mov     sp,bp
  66.         pop     bp
  67.         ret
  68.  
  69. _putmem ENDP
  70.  
  71.  
  72.  
  73.         PUBLIC  _getmem
  74. _getmem PROC FAR
  75.         push    bp
  76.         mov     bp,sp
  77.  
  78. ;       segment = 4
  79. ;       offset = 6
  80.  
  81.         mov     es, [bp+6]      ;segment
  82.         mov     bx,[bp+8]       ;offset
  83.         mov     al,es:[bx]
  84.         sub     ah,ah
  85.  
  86.         mov     sp,bp
  87.         pop     bp
  88.         ret
  89.  
  90. _getmem ENDP
  91.  
  92.  
  93. ;  int  WritePixelEGA (line, samp, DN);
  94. ;
  95. ;  WritePixelEGA displays a pixel on the EGA screen at the desired location.
  96. ;
  97. ;   Parameters:
  98. ;     line       the line to display the pixel at (starts at 1)
  99. ;     samp       the sample to display the pixel at (starts at 1)
  100. ;     DN         the DN to write
  101. ;
  102. ;   Registers:
  103. ;     DI      pointer to video memory (ES segment used)
  104. ;     BL      bit mask used to load pixels to bitplanes
  105. ;
  106. ;       line   = BP+6
  107. ;       sample = BP+8
  108. ;       DN     = BP+10
  109.  
  110.         PUBLIC  _WritePixelEGA
  111. _WritePixelEGA  PROC FAR
  112.  
  113.         PUSH    BP
  114.         MOV     BP, SP
  115.         PUSH    DI
  116.  
  117.                                 ; Calculate the starting address in memory
  118.                                 ; address := 80*(line-1) + (samp-1) shr 3;
  119.         MOV     AX, [BP+6]            ; get line parameter
  120.         DEC     AX                    ;  convert to start at 0 system
  121.         JL      CLIP                  ;  Abort if out of range
  122.         CMP     AX, 479               ;  EGA480
  123.         JG      CLIP
  124.         MOV     DI, AX
  125.         SHL     DI, 1                 ;  multiply by 80
  126.         SHL     DI, 1
  127.         ADD     DI, AX
  128.         SHL     DI, 1
  129.         SHL     DI, 1
  130.         SHL     DI, 1
  131.         SHL     DI, 1
  132.         MOV     AX, [BP+8]            ; get samp parameter
  133.         DEC     AX                    ;  convert to start at 0 system
  134.         JL      CLIP                  ;  Abort if out of range
  135.         CMP     AX, 639
  136.         JG      CLIP
  137.         SHR     AX, 1                 ;  divide it by 8
  138.         SHR     AX, 1
  139.         SHR     AX, 1
  140.         ADD     DI, AX                ; calculate the final memory offset
  141.                                       ;   and put in the video pointer
  142.  
  143.                                 ; Select Write Mode 2
  144.         MOV     DX, 3CEH
  145.         MOV     AL, 5
  146.         OUT     DX, AL
  147.         MOV     DX, 3CFH
  148.         MOV     AL, 2
  149.         OUT     DX, AL
  150.  
  151.  
  152.         MOV     AX, 0A000H            ; ES = EGA buffer segment address
  153.         MOV     ES, AX
  154.  
  155.                                 ; Initialize bit mask
  156.                                 ;   mask = 0x80 >> ((samp-1) & 7);
  157.         MOV     CX, [BP+8]            ; get samp parameter
  158.         DEC     CX
  159.         AND     CX, 7
  160.         MOV     BL, 80H               ; shift bit over to start at the
  161.         SHR     BL, CL                ;  right pixel
  162.  
  163.         MOV     DX, 3CEH
  164.         MOV     AL, 8                 ; Load the bit mask
  165.         OUT     DX, AL
  166.         MOV     DX, 3CFH
  167.         MOV     AL, BL
  168.         OUT     DX, AL
  169.  
  170.         MOV     AL, ES:[DI]           ; Latch the bytes from each bitplane
  171.         MOV     AX, [BP+10]            ; Get the pixel value
  172.         MOV     ES:[DI], AL           ; Write the bytes back to the bitplanes
  173.  
  174.  
  175.  
  176.                                 ; Restore Write Mode 0
  177.         MOV     DX, 3CEH
  178.         MOV     AL, 5
  179.         OUT     DX, AL
  180.         MOV     DX, 3CFH
  181.         MOV     AL, 0
  182.         OUT     DX, AL
  183.  
  184.                                 ; Restore default bit mask
  185.         MOV     DX, 3CEH
  186.         MOV     AL, 8
  187.         OUT     DX, AL
  188.         MOV     DX, 3CFH
  189.         MOV     AL, 0FFH
  190.         OUT     DX, AL
  191.  
  192.  
  193. CLIP:
  194.         POP     DI
  195.         MOV     SP,BP
  196.         POP     BP
  197.         RET
  198.  
  199. _WritePixelEGA  ENDP
  200.  
  201.  
  202. ;  int  DisplayLineEGA (buffer, line, samp, ns);
  203. ;
  204. ;   DisplayLineEGA displays a line of pixels in a buffer on the EGA screen
  205. ;  at the desired location.
  206. ;
  207. ;   Parameters:
  208. ;     buffer     the buffer of bytes containing the pixels (nibbles) to
  209. ;                    be displayed
  210. ;     line       the line to display the pixels at (starts at 1)
  211. ;     samp       the sample to display the first pixel at (starts at 1)
  212. ;     ns         the number of samples to display
  213. ;
  214. ;   Registers:
  215. ;     DI      pointer to video memory (ES segment used)
  216. ;     SI      pointer to pixel buffer (DS segment used)
  217. ;     BL      bit mask used to load pixels to bitplanes
  218. ;     CX      sample counter
  219. ;
  220. ;       buffer = 6
  221. ;       line   = 8
  222. ;       samp   = 10
  223. ;       ns     = 12
  224.  
  225.         PUBLIC  _DisplayLineEGA
  226. _DisplayLineEGA PROC FAR
  227.  
  228.         PUSH    BP
  229.         MOV     BP, SP
  230.         PUSH    DS
  231.         PUSH    DI
  232.         PUSH    SI
  233.  
  234.         MOV     AX, [BP+6]            ; get segment of buffer
  235.         MOV     DS, AX
  236.         MOV     SI, [BP+8]            ; get offset of buffer
  237.  
  238.                                 ; Calculate the starting address in memory
  239.                                 ; address := 80*(line-1) + (samp-1) shr 3;
  240.         MOV     AX, [BP+10]            ; get line parameter
  241.         DEC     AX                    ;  convert to start at 0 system
  242.         MOV     DX, 80                ;  multiplying line by 80
  243.         MUL     DX                    ;
  244.         MOV     DX, [BP+12]            ; get samp parameter
  245.         DEC     DX                    ;  convert to start at 0 system
  246.         SHR     DX, 1                 ;  divide it by 8
  247.         SHR     DX, 1
  248.         SHR     DX, 1
  249.         ADD     AX, DX                ; calculate the final memory offset
  250.         MOV     DI, AX                ;   and put in the video pointer
  251.  
  252.         MOV     AX, 0A000H            ; ES = EGA buffer segment address
  253.         MOV     ES, AX
  254.  
  255.                                 ; Select Write Mode 2
  256.         MOV     DX, 3CEH
  257.         MOV     AL, 5
  258.         OUT     DX, AL
  259.         MOV     DX, 3CFH
  260.         MOV     AL, 2
  261.         OUT     DX, AL
  262.  
  263.                                 ; Initialize bit mask
  264.                                 ;   mask := $80 shr ((samp-1) and 7);
  265.         MOV     CX, [BP+12]            ; get samp parameter
  266.         DEC     CX
  267.         AND     CX, 7
  268.         MOV     BL, 80H               ; shift bit over to start at the
  269.         SHR     BL, CL                ;  right pixel
  270.  
  271.  
  272.         MOV     CX, [BP+14]            ; Start loop counter with ns  parameter
  273.         MOV     DX, 3CEH              ; point DX to the right port
  274.  
  275. SAMPLOOP:
  276.         MOV     AL, 8                 ; Load the bit mask
  277.         OUT     DX, AL
  278.         INC     DX
  279.         MOV     AL, BL
  280.         OUT     DX, AL
  281.         DEC     DX
  282.  
  283.         MOV     AL, ES:[DI]           ; Latch the bytes from each bitplane
  284.         MOV     AL, [SI]              ; Get the nibble from the linebuf
  285.         MOV     ES:[DI], AL           ; Write the bytes back to the bitplanes
  286.  
  287.         SHR     BL, 1                 ; shift the bit over in the bit mask
  288.         JNC     ENDLOOP
  289.                                       ; if the bit fell out the other end
  290.         MOV     BL, 80H               ;   then move to the next byte in
  291.         INC     DI                    ;   video memory
  292.  
  293. ENDLOOP:
  294.         INC     SI                    ; point to the next pixel
  295.         LOOP    SAMPLOOP              ; loop until all pixels are done
  296.  
  297.  
  298.                                 ; Restore Write Mode 0
  299.         MOV     DX, 3CEH
  300.         MOV     AL, 5
  301.         OUT     DX, AL
  302.         MOV     DX, 3CFH
  303.         MOV     AL, 0
  304.         OUT     DX, AL
  305.  
  306.                                 ; Restore default bit mask
  307.         MOV     DX, 3CEH
  308.         MOV     AL, 8
  309.         OUT     DX, AL
  310.         MOV     DX, 3CFH
  311.         MOV     AL, 0FFH
  312.         OUT     DX, AL
  313.  
  314.  
  315.         POP     SI
  316.         POP     DI
  317.         POP     DS
  318.         MOV     SP,BP
  319.         POP     BP
  320.         RET
  321.  
  322. _DisplayLineEGA ENDP
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330. ;  int ClearDisplayEGA (DN,dispnl);
  331. ;
  332. ;   ClearDisplayEGA sets the whole EGA screen to the DN pixel value
  333. ;
  334. ;   Parameters:
  335. ;      DN        the pixel value to set the screen to
  336. ;
  337. ;   Registers:
  338. ;     DI      pointer to video memory (ES segment used)
  339. ;
  340. ;
  341. ;       DN = 6
  342.  
  343.         PUBLIC  _ClearDisplayEGA
  344. _ClearDisplayEGA        PROC FAR
  345.  
  346.         PUSH    BP
  347.         MOV     BP, SP
  348.         PUSH    DI
  349.  
  350.         MOV     AX, 0A000H            ; ES = EGA buffer segment address
  351.         MOV     ES, AX
  352.  
  353.                                 ; Select Write Mode 2
  354.         MOV     DX, 3CEH
  355.         MOV     AL, 5
  356.         OUT     DX, AL
  357.         MOV     DX, 3CFH
  358.         MOV     AL, 2
  359.         OUT     DX, AL
  360.  
  361.                                 ; Set bit mask to all bits on
  362.         MOV     DX, 3CEH
  363.         MOV     AL, 8
  364.         OUT     DX, AL
  365.         MOV     DX, 3CFH
  366.         MOV     AL, 0FFH
  367.         OUT     DX, AL
  368.  
  369.         MOV     AL, [BP+6]            ; Get the pixel value
  370.         MOV     DI, 0                 ; Start at beginning of video memory
  371.         mov     si, [BP+8]
  372.         cmp     si,350                ; check for 350 or 480 line display
  373.         jne     BYTE480
  374. BYTELOOP:
  375.         MOV     BL, ES:[DI]           ; Latch the bytes from each bitplane
  376.         MOV     ES:[DI], AL           ; Write the bytes back to the bitplanes
  377.         INC     DI                    ; point to the next byte
  378.         CMP     DI, 28000             ; how many lines to clear
  379.         JNZ     BYTELOOP              ; loop until whole screen cleared
  380.         jmp     RESTORE
  381.  
  382. BYTE480:
  383.         MOV     BL, ES:[DI]           ; Latch the bytes from each bitplane
  384.         MOV     ES:[DI], AL           ; Write the bytes back to the bitplanes
  385.         INC     DI                    ; point to the next byte
  386.         CMP     DI, 38400             ; how many lines to clear
  387.         JNZ     BYTE480               ; loop until whole screen cleared
  388.  
  389. RESTORE:
  390.                                 ; Restore Write Mode 0
  391.         MOV     DX, 3CEH
  392.         MOV     AL, 5
  393.         OUT     DX, AL
  394.         MOV     DX, 3CFH
  395.         MOV     AL, 0
  396.         OUT     DX, AL
  397.  
  398.         POP     DI
  399.         MOV     SP,BP
  400.         POP     BP
  401.         RET
  402.  
  403. _ClearDisplayEGA        ENDP
  404.  
  405.  
  406.  
  407.  
  408.  
  409.         PUBLIC  _PGAsend
  410. _PGAsend        PROC FAR
  411. ;       command = 6
  412. ;       len     = 8
  413.  
  414.         PUSH    BP
  415.         MOV     BP, SP
  416.         PUSH    SI
  417.  
  418.         MOV     AX, 0C600H
  419.         MOV     ES, AX
  420.         MOV     CX, [BP+8]          ; put len in CX
  421.         MOV     SI, [BP+6]          ; get command array address in SI
  422. WAIT1:
  423.         MOV     BL, ES:[0300H]      ; OutWritePtr
  424.         MOV     AL, ES:[0301H]      ; OutReadPtr
  425.         SUB     AL, BL
  426.         DEC     AL                  ; calculate numbytes
  427.         CMP     AL, CL              ;  and compare it with len
  428.         JB      WAIT1               ; wait until there's room in buffer
  429.         SUB     BH, BH
  430. OUTLOOP:
  431.         MOV     AL, [SI]            ; get the command byte
  432.         MOV     ES:[BX], AL         ; send it to the PGA
  433.         INC     SI                  ; point to next command byte
  434.         INC     BL                  ; increment the OutWritePtr
  435.         LOOP    OUTLOOP             ; loop until done all bytes
  436.  
  437.         MOV     ES:[0300H], BL      ; save the OutWritePtr
  438.  
  439.         POP     SI
  440.         MOV     SP, BP
  441.         POP     BP
  442.         RET
  443. _PGAsend        ENDP
  444.  
  445. ; Set640x480 puts an EGA card with a 24mhz feature adapter into 640x480
  446. ; graphics mode.  Once the card in in the mode, pixels may be written using
  447. ; conventional EGA programming techniques.  The only difference is there are
  448. ; more scan lines.  (And there is only a single display page, not two.)
  449.  
  450. ; The 24mhz feature adapter was described in the September 16, 1986 PC
  451. ; Magazine, page 298.
  452.  
  453. SaveTable       equ     04A8h
  454. SaveTableLen    equ     7               ; Number of DWORDs in SaveTable
  455.  
  456.         PUBLIC  _EGAinit
  457. _EGAinit        PROC FAR
  458.  
  459.         push    ds
  460.         push    es
  461.         push    ax
  462.         push    bx
  463.         push    cx
  464.  
  465.         xor     ax, ax
  466.         mov     es, ax
  467.  
  468.         lds     bx, es:SaveTable        ; Get old save table
  469.  
  470.         push    ds                      ; Stash away for when we return
  471.         push    bx
  472.  
  473.         mov     cx, SaveTableLen*2
  474.         add     bx, SaveTableLen*4
  475. SavePush:                               ; Make a copy of save table on stack
  476.         dec     bx
  477.         dec     bx
  478.         push    [bx]
  479.         loop    SavePush
  480.         mov     bx, sp
  481.  
  482.         mov     ss:[bx], offset EgaRegs ; Point to our register set
  483.         mov     ss:[bx+2], cs
  484.  
  485.         CLI
  486.         mov     es:SaveTable, bx        ; Make our copy the active one
  487.         mov     es:SaveTable+2, ss
  488.         STI
  489.  
  490.         mov     ax,0010h                ; Set 640x480 color graphics
  491.         int     10h
  492.  
  493.         CLI
  494.         add     sp, SaveTableLen*4      ; Deallocate our copy from stack
  495.         pop     es:SaveTable
  496.         pop     es:SaveTable+2          ; Restore original save table
  497.         STI
  498.  
  499.         pop     cx
  500.         pop     bx
  501.         pop     ax
  502.         pop     es
  503.         pop     ds
  504.  
  505.         ret
  506.  
  507. _EGAinit        ENDP
  508.  
  509.  
  510. DISPSUB_TEXT   ENDS
  511. END
  512.