[net.micro.pc] Writing to EGA screen memory: Example!

kreek@rocky2.UUCP (Biochemical Endocrinology) (07/10/86)

===============================================
Recently, I asked for help on writing directly to the EGA screen
memory.  I got excellent help from Peter Wu in Wisconsin.  I
just thought I would post my sample program that I was able to
write as a result of Peter's help.  It is a demonstration of how
to address bytes in the EGA's memory.  If you want to address
pixels, you have to mask the bits in these bytes.

This program draws an abstract pattern on the screen that is
somewhat reminiscent of bathroom tiles.  It does so in the fastest
screen access method possible.

I wrote this program in order to demonstrate how clumsy it is
to access the screen memory.  Ideally, the memory should be
accessed so that one address location corresponds to one pixel
containing four bits (for 16 colors).  Unfortunately, I found
this is not the case with the EGA, as is shown in the program.
Writing a pixel with a given color involves programming several
ports and masking of bits within the individual address of the
screen memory, so you end up with five to ten instructions
instead of just one or two.

Interestingly, IBM uses about 30 instructions to write a pixel
for their service 12 (dec) of interrupt 10 (hex).

Does anyone know of a graphics board that is organized truly
sequentially, as described in my ideal?

Henrik Albeck
--
UUCP:
     seismo|
    philabs|
       phri| -> cmcl2!rna!rocky2!kreek
    harvard|
      ihnp4|

ARPANET:        kreek@rockefeller.arpa
BITNET:         KREEK@ROCKVAX
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	pat8.asm
#	pat8.uu
# This archive created: Wed Jul  9 18:39:39 1986
export PATH; PATH=/bin:$PATH
if test -f 'pat8.asm'
then
	echo shar: will not over-write existing file "'pat8.asm'"
else
cat << \SHAR_EOF > 'pat8.asm'
TITLE   PATTERN #8             7-5-86   [7-5-86] 
; Henrik Albeck
; Rockefeller University
; New York City
; (212) 570-8248
; UUCP:
;      seismo|
;     philabs|
;        phri| -> cmcl2!rna!rocky2!kreek
;     harvard|
;       ihnp4|
; 
; ARPANET:        kreek@rockefeller.arpa
; BITNET:         KREEK@ROCKVAX

PROGNAM SEGMENT 
        ASSUME  CS:PROGNAM

MAIN    PROC  FAR

        START:

        loop_num               equ      28000

        reg_adres_port         equ      3c4h

        mask_port              equ      3c5h

        mask_reg_num           equ      2

        video_seg              equ      0a000h


        ;SET UP STACK FOR RETURN
        PUSH DS                    ;SAVE OLD DATA SEGMENT
        SUB AX,AX                  ;PUT ZERO IN AX
        PUSH AX                    ;SAVE IT ON STACK

        ;SET DS REGISTER TO CURRENT DATA SEGMENT
        MOV   AX,video_seg         ;SET VIDEO SEGMENT, STARTS
        MOV   DS,AX                ;AT A000

        ;------------------  SET VIDEO MODE  ----------------------;
        MOV   AH,0H                ;SERVICE 0 OF INT10
        MOV   AL,10H               ;MODE 10H = 640 x 350 PIXEL, 16 COLORS
        INT   10H                  ;DO THE VIDEO INTERRUPT
        ;------------------  END SET VIDEO MODE  ------------------; 

        MOV   AL,mask_reg_num      ;SELECT REGISTER 2 OF PORT 3C5
        MOV   DX,reg_adres_port    ;BY PUTTING 2 IN PORT 3C4
        OUT   DX,AL                ;REG. 2 OF PORT 3C5 IS MASKING REGISTER 

        MOV   CX,loop_num          ;NUMBER OF LOOPS
        MOV   DX,mask_port         ;SELECTING THE MASKING PORT

FILL_SCREEN:                       ;START FILL SCREEN LOOP

        MOV   BX,CX                ;PUT LOOP COUNTER IN BX FOR ADDRESSING

        MOV   AL,CH                ;USE CH AS COLOR MASKER 
        MUL   CL                   ;MULTIPLY TO MAKE EXCITING PATTERN
        AND   AL,CL                ;AND AND IT TOO, FOR MORE EXCITEMENT
        OUT   DX,AL                ;OUT RESULT FOR MASKING AT PORT 3C5

        PUSH  DX                   ;SAVE MASKING PORT ADDRESS 
        MOV   DX,0FFFFH            ;MOVE PIXELS INTO DX
        MOV   [BX],DX              ;OUTPUT TO SCREEN
        POP   DX                   ;GET PORT ADDRESS BACK IN DX
        LOOP  FILL_SCREEN          ;END OF SCREEN FILLING LOOP


        RET                        ;RETURN TO OPERATING SYSTEM ( DOS )

MAIN    ENDP                            
                                   
PROGNAM ENDS  

        END   START
SHAR_EOF
if test 2516 -ne "`wc -c < 'pat8.asm'`"
then
	echo shar: error transmitting "'pat8.asm'" '(should have been 2516 characters)'
fi
fi # end of overwriting check
if test -f 'pat8.uu'
then
	echo shar: will not over-write existing file "'pat8.uu'"
else
cat << \SHAR_EOF > 'pat8.uu'
begin 644 pat8.exe
M35HN  (    @    __\     XVX     '@    $                     
M                                                            
M                                                            
M                                                            
M                                                            
M                                                            
M                                                            
M                                                            
M                                                            
M                                                            
M                                                            
M                       >*\!0N "@CMBT + 0S1"P KK$ ^ZY8&VZQ0.+
2V8K%]N$BP>Y2NO__B1=:XN[+
 
end
SHAR_EOF
if test 795 -ne "`wc -c < 'pat8.uu'`"
then
	echo shar: error transmitting "'pat8.uu'" '(should have been 795 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0