home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / EGAMOV.ZIP / EGAMOVE.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-05-05  |  4.9 KB  |  183 lines

  1. page 55,96
  2. title EGAMOVE.ASM Version 1.0
  3. comment |
  4.  
  5. This is a routine to be called from higher level
  6. languages (Pascal, Fortran) using the Microsoft
  7. parameter passing convention.
  8.  
  9. The routine moves color information from a memory
  10. buffer(s) (pixel array) into the EGA on board memory.
  11. Color information for two pixels is stored in one
  12. byte.  The upper 4 bits (upper nibble) stores info for
  13. the first pixel, the lower nibble stores info for the
  14. second pixel.
  15.  
  16. Three graphics modes are supported:
  17.  
  18. Mode    Resolution      Colors  Buffer length
  19.  
  20. 0DH     320x200         16      32000
  21. 0EH     640X200         16      64000
  22. 10H     640X350         16      2x56000
  23.  
  24. The 640x350 graphics requires two buffers since no
  25. more than 65536 locations can be addressed.
  26.  
  27. Pascal function has to be declared as follows:
  28.  
  29. function
  30. egamove(mode:integer;buf1,buf2:adsmem):word;extern;
  31.  
  32. Function returns 0 upon success, 1 if EGA is not
  33. instaled and 2 if illegal mode was specified.
  34.  
  35. Upon completion of the display, procedure waits for
  36. ESC to be pressed.  Then it resets the EGA mode to 3
  37. (80x25 color alpha) and exits.
  38.  
  39. This routine is almost as fast for 320x200 graphics as
  40. simple memory moves possible on the CGA.  It takes
  41. about 20 s to fill a 640x350 graphics screen.
  42.  
  43.  
  44. This code can be easily modified to allow access from
  45. other languages using different calling conventions.
  46.  
  47. |
  48.  
  49. .radix 16
  50. code segment para 'code'
  51. assume cs:code,ds:code
  52. org 100
  53. public egamove
  54. egamove proc far
  55.         jmp begin
  56. masks db 80,40,20,10,8,4,2,1
  57. begin:
  58.         push bp
  59.         mov bp,sp       ;allow parameter access
  60.         mov bl,10       ;check for EGA presence
  61.         mov ah,12
  62.         mov cx,-1
  63.         int 10
  64.         cmp cx,-1       ;CX changed?
  65.         jnz cont
  66.         mov ax,1        ;no EGA rcode
  67. err_ex:
  68.         pop bp
  69.         ret 10d         ;discard parameters
  70. cont:
  71.         mov ax,[bp+14d] ;mode
  72.         cmp ax,0dh
  73.         jne lab1
  74.         mov cx,8000d    ;320x200 regen
  75.         jmp set_mode
  76. lab1:   cmp ax,0eh
  77.         jne lab2
  78.         mov cx,16000d   ;640x200 regen
  79.         jmp set_mode
  80. lab2:   cmp ax,10h
  81.         je lab3
  82.         mov ax,2        ;illegal mode rcode
  83.         jmp err_ex
  84. lab3:   mov cx,14000d   ;640x350 regen
  85. set_mode:
  86.         int 10
  87.         push ds         ;preserve data segment
  88.         mov ax,[bp+12d] ;1st buffer segmen
  89.         mov ds,ax
  90.         mov si,[bp+10d] ;1st buffer offset
  91.         mov ax,0a000
  92.         mov es,ax       ;regen segment
  93.         xor di,di       ;regen start
  94.         push cx         ;preserve regen length
  95.         call fill_screen
  96.         pop cx
  97.         cmp cx,14000d   ;640x350?
  98.         jne exit        ;no, done
  99.         mov ax,[bp+8d]  ;2nd buffer segment
  100.         mov ds,ax
  101.         mov si,[bp+6d]  ;2nd buffer offset
  102.         call fill_screen
  103. exit:
  104.         pop ds
  105.         pop bp
  106.         call escape_chk
  107.         mov ax,3
  108.         int 10          ;restore mode 3
  109.         mov ax,0        ;no error rcode
  110.         ret 10d         ;discard parameters
  111. egamove endp
  112.  
  113. fill_screen     proc
  114.         push bp         ;preserve parameter access
  115. screen_loop:
  116.         mov bx,offset masks
  117.         mov bp,4        ; 2 pixels per byte
  118. pixel_loop:
  119.         push cx
  120.         mov ch,[si]
  121.         mov ah,ch
  122.         mov cl,4
  123.         shr ah,cl       ; process upper nibble
  124.         call write_pixel
  125.         inc bx          ;next mask
  126.         mov ah,ch
  127.         and ah,0f       ;mask upper nibble
  128.         call write_pixel
  129.         pop cx
  130.         inc bx          ;next mask
  131.         inc si          ;next buffer location
  132.         dec bp
  133.         jnz pixel_loop
  134.         inc di          ;next regen location
  135.         loop screen_loop
  136.         pop bp          ;restore parameter access
  137.         ret
  138. fill_screen endp
  139.  
  140. write_pixel proc
  141.         mov dx,3ce      ; graphics controller
  142.         mov al,8        ; force bit mask
  143.         out dx,al
  144.         inc dx
  145.         mov al,cs:[bx]  ; mask for the current bit
  146.         out dx,al
  147.         mov dx,3c4      ; EGA sequencer
  148.         mov al,2
  149.         out dx,al       ; enable CPU write
  150.         mov al,0f       ; all maps
  151.         inc dx
  152.         out dx,al
  153.         mov al,es:[di]  ; latch regen byte
  154.         xor al,al
  155.         mov es:[di],al  ; blank current color
  156.         dec dx          ; back to address register
  157.         mov al,2
  158.         out dx,al       ; color will be output now
  159.         inc dx
  160.         mov al,ah       ; color passed in ah
  161.         out dx,al
  162.         mov al,0ff
  163.         mov es:[di],al  ; only now the color appears
  164.         ret
  165. write_pixel endp
  166.  
  167. escape_chk proc
  168. key_chk:
  169.         mov ah,0bh      ;check input status
  170.         int 21
  171.         cmp al,0ff      ;key hit?
  172.         je  esc
  173.         jmp key_chk
  174. esc:    mov ah,7        ;get the value
  175.         int 21
  176.         cmp al,27d      ;is it ESC?
  177.         jne key_chk     ;if not,keep trying
  178.         ret
  179. escape_chk endp
  180.  
  181. code    ends
  182.         end
  183.