home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / imdisp79.zip / DISPSUB.ASM < prev    next >
Assembly Source File  |  1992-11-29  |  15KB  |  517 lines

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