home *** CD-ROM | disk | FTP | other *** search
- page 55,96
- title EGAMOVE.ASM Version 1.0
- comment |
-
- This is a routine to be called from higher level
- languages (Pascal, Fortran) using the Microsoft
- parameter passing convention.
-
- The routine moves color information from a memory
- buffer(s) (pixel array) into the EGA on board memory.
- Color information for two pixels is stored in one
- byte. The upper 4 bits (upper nibble) stores info for
- the first pixel, the lower nibble stores info for the
- second pixel.
-
- Three graphics modes are supported:
-
- Mode Resolution Colors Buffer length
-
- 0DH 320x200 16 32000
- 0EH 640X200 16 64000
- 10H 640X350 16 2x56000
-
- The 640x350 graphics requires two buffers since no
- more than 65536 locations can be addressed.
-
- Pascal function has to be declared as follows:
-
- function
- egamove(mode:integer;buf1,buf2:adsmem):word;extern;
-
- Function returns 0 upon success, 1 if EGA is not
- instaled and 2 if illegal mode was specified.
-
- Upon completion of the display, procedure waits for
- ESC to be pressed. Then it resets the EGA mode to 3
- (80x25 color alpha) and exits.
-
- This routine is almost as fast for 320x200 graphics as
- simple memory moves possible on the CGA. It takes
- about 20 s to fill a 640x350 graphics screen.
-
-
- This code can be easily modified to allow access from
- other languages using different calling conventions.
-
- |
-
- .radix 16
- code segment para 'code'
- assume cs:code,ds:code
- org 100
- public egamove
- egamove proc far
- jmp begin
- masks db 80,40,20,10,8,4,2,1
- begin:
- push bp
- mov bp,sp ;allow parameter access
- mov bl,10 ;check for EGA presence
- mov ah,12
- mov cx,-1
- int 10
- cmp cx,-1 ;CX changed?
- jnz cont
- mov ax,1 ;no EGA rcode
- err_ex:
- pop bp
- ret 10d ;discard parameters
- cont:
- mov ax,[bp+14d] ;mode
- cmp ax,0dh
- jne lab1
- mov cx,8000d ;320x200 regen
- jmp set_mode
- lab1: cmp ax,0eh
- jne lab2
- mov cx,16000d ;640x200 regen
- jmp set_mode
- lab2: cmp ax,10h
- je lab3
- mov ax,2 ;illegal mode rcode
- jmp err_ex
- lab3: mov cx,14000d ;640x350 regen
- set_mode:
- int 10
- push ds ;preserve data segment
- mov ax,[bp+12d] ;1st buffer segmen
- mov ds,ax
- mov si,[bp+10d] ;1st buffer offset
- mov ax,0a000
- mov es,ax ;regen segment
- xor di,di ;regen start
- push cx ;preserve regen length
- call fill_screen
- pop cx
- cmp cx,14000d ;640x350?
- jne exit ;no, done
- mov ax,[bp+8d] ;2nd buffer segment
- mov ds,ax
- mov si,[bp+6d] ;2nd buffer offset
- call fill_screen
- exit:
- pop ds
- pop bp
- call escape_chk
- mov ax,3
- int 10 ;restore mode 3
- mov ax,0 ;no error rcode
- ret 10d ;discard parameters
- egamove endp
-
- fill_screen proc
- push bp ;preserve parameter access
- screen_loop:
- mov bx,offset masks
- mov bp,4 ; 2 pixels per byte
- pixel_loop:
- push cx
- mov ch,[si]
- mov ah,ch
- mov cl,4
- shr ah,cl ; process upper nibble
- call write_pixel
- inc bx ;next mask
- mov ah,ch
- and ah,0f ;mask upper nibble
- call write_pixel
- pop cx
- inc bx ;next mask
- inc si ;next buffer location
- dec bp
- jnz pixel_loop
- inc di ;next regen location
- loop screen_loop
- pop bp ;restore parameter access
- ret
- fill_screen endp
-
- write_pixel proc
- mov dx,3ce ; graphics controller
- mov al,8 ; force bit mask
- out dx,al
- inc dx
- mov al,cs:[bx] ; mask for the current bit
- out dx,al
- mov dx,3c4 ; EGA sequencer
- mov al,2
- out dx,al ; enable CPU write
- mov al,0f ; all maps
- inc dx
- out dx,al
- mov al,es:[di] ; latch regen byte
- xor al,al
- mov es:[di],al ; blank current color
- dec dx ; back to address register
- mov al,2
- out dx,al ; color will be output now
- inc dx
- mov al,ah ; color passed in ah
- out dx,al
- mov al,0ff
- mov es:[di],al ; only now the color appears
- ret
- write_pixel endp
-
- escape_chk proc
- key_chk:
- mov ah,0bh ;check input status
- int 21
- cmp al,0ff ;key hit?
- je esc
- jmp key_chk
- esc: mov ah,7 ;get the value
- int 21
- cmp al,27d ;is it ESC?
- jne key_chk ;if not,keep trying
- ret
- escape_chk endp
-
- code ends
- end
-