home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / grafik / crtgraph / crtg.asm < prev    next >
Encoding:
Assembly Source File  |  1991-04-03  |  10.1 KB  |  354 lines

  1. ; The code in PUTCHAR is modified from the Robert Wilton book pgs. 288-292.
  2.  
  3. BytesPerLine    =       80                ; (or 40 in 320x200 16-color mode)
  4. RMWbits         =       00h               ; Read-Modify-Write bits
  5. OriginOffset    =       0
  6. VideoBufferSeg  =       0a000h
  7.  
  8.         .model tpascal
  9.  
  10.         .data
  11.         extrn    fonttable : dword
  12.                 extrn   chahgt    : byte
  13. CTimer          DW      ?
  14.  
  15.         .code
  16.  
  17. putchar            proc    far argc:word,argx:word,argy:word,fgd:byte,bkg:byte
  18.         public    putchar
  19.  
  20.         push    ds
  21.         push    si
  22.         push    es
  23.         push    di
  24.  
  25.  
  26. ; set up character definition table addressing
  27.  
  28.                 mov     ax,@data
  29.                 mov     ds,ax
  30.         xor    cx,cx
  31.         mov    cl,ds:chahgt    ; number of pixel rows in char
  32.         les    di,ds:fonttable
  33.         mov    ax,argc     ; al := character code
  34.         mul    cl        ; ax := offset into char def table
  35.                     ;  (points * char code)
  36.         add    di,ax        ; di := addr of char def
  37.                                         ; es:di = char pattern
  38.  
  39. ; calculate first pixel address
  40.  
  41.         mov    ax,argy     ; ax := y
  42.                 mul     cl
  43.                 mov     dx,BytesPerLine
  44.                 mul     dx
  45.         mov    si,argx     ; bx := x
  46.                 add     si,ax           ; si := video buffer offset
  47.                 mov     ax,VideoBufferSeg
  48.                 mov     ds,ax        ; ds:si -> video buffer
  49.  
  50. ; set up graphics controller registers
  51.  
  52.         mov    dx,3ceh     ; graphics controller address reg port
  53.  
  54.         mov    ax,0a05h    ; al :=  mode register number
  55.                     ; ah :=  write mode 2 (bits 0-1)
  56.                     ;     read mode 1 (bit 4)
  57.         out    dx,ax
  58.  
  59.         xor    ah,ah           ; ah := read-modify-write bits
  60.         mov    al,3        ; al := data rotate/function select reg
  61.         out    dx,ax
  62.  
  63.         mov    ax,0007     ; ah := color don't care bits
  64.                     ; al := color don't care reg number
  65.         out    dx,ax        ; "don't care" for all bit planes
  66.  
  67. ; select output routine depending on whether character is byte-aligned
  68.  
  69.         mov    bl,fgd          ; bl := foreground pixel value
  70.                 mov     bh,bkg          ; bh := background pixel value
  71.  
  72.         mov    al,8        ; al := bit mask register number
  73.  
  74. wrtcl10p:    mov    ah,es:[di]    ; ah := pattern for next row of pixels
  75.  
  76.             out    dx,ax        ; update bit mask register
  77.         and    [si],bl     ; update foreground pixels
  78.  
  79.                 not     ah              ; create mask for background
  80.                 out     dx,ax           ; update bit mask register
  81.                 and     [si],bh         ; update background pixels
  82.  
  83.         inc    di        ; es:di -> next byte in char def table
  84.         add    si,BytesPerLine ; increment to next line in video buffer
  85.         loop    wrtcl10p
  86.  
  87. ; restore default graphics controller registers
  88.  
  89.             mov    ax,0ff08h    ; default bit mask
  90.         out    dx,ax
  91.  
  92.         mov    ax,0005     ; default mode register
  93.         out    dx,ax
  94.  
  95.         mov    ax,0003     ; default data rotate/function select
  96.         out    dx,ax
  97.  
  98.         mov    ax,0f07h    ; default color don't care
  99.         out    dx,ax
  100.  
  101.         pop    di
  102.         pop    es
  103.         pop    si
  104.         pop    ds
  105.  
  106.         ret
  107.  
  108. putchar         endp
  109.  
  110.  
  111. ScrollUp        PROC FAR x:word,y:word,len:word,dep:word
  112.                 PUBLIC ScrollUp
  113.  
  114.                 push    di
  115.                 push    si
  116.                 push    ds
  117.  
  118. ; calculate first pixel address
  119.  
  120.                 mov     ax,@data
  121.                 mov     ds,ax
  122.                 xor     ch,ch
  123.                 mov     cl,ds:ChaHgt
  124.  
  125.         mov    ax,argy     ; ax := y
  126.                 mul     cl
  127.                 mov     dx,BytesPerLine
  128.                 mul     dx
  129.         mov    si,argx     ; bx := x
  130.                 add     si,ax           ; si := video buffer offset
  131.                 mov     ax,VideoBufferSeg
  132.                 mov     es,ax        ; es:si -> write to
  133.  
  134.                 mov     ax,cx           ; AX = char height
  135.                 mov     dx,BytesPerLine
  136.                 mul     dx
  137.                 mov     di,si
  138.                 add     di,ax             ; DI := Read from offset
  139.  
  140. ; set up graphics controller registers
  141.  
  142.                 mov     dx,3ceh
  143.                 mov     ax,0105h
  144.                 out     dx,ax
  145.  
  146. ; routine for byte aligned characters
  147.  
  148.                 xor     ah,ah
  149.                 mov     al,ds:ChaHgt
  150.                 mov     bx,dep            ; set depth of scroll
  151.                 mul     bx                ; AX = number of pixel lines to move
  152.                 xor     dx,dx             ; DX = 0
  153.  
  154. L10:            push    si                ; save write to pointer
  155.                 push    di                ; save read from pointer
  156.                 mov     cx,len            ; set length of line
  157.  
  158. L11:            jcxz    short Lexit1
  159.                 mov     bh,es:[di]        ; read byte
  160.                 mov     es:[si],bh
  161.                 inc     di
  162.                 inc     si
  163.                 dec     cx
  164.                 jmp     short L11
  165.  
  166. Lexit1:         pop     di
  167.                 pop     si
  168.                 add     si,BytesPerLine
  169.                 add     di,BytesPerLine
  170.                 dec     ax
  171.                 cmp     ax,dx
  172.                 jnz     short L10
  173.  
  174. ; restore default graphics controller registers
  175.  
  176.                 mov     ax,0ff08h
  177.                 out     dx,ax
  178.                 mov     ax,0005
  179.                 out     dx,ax
  180.                 mov     ax,0003
  181.                 out     dx,ax
  182.                 mov     ax,0f07h
  183.                 out     dx,ax
  184.                 pop     ds
  185.                 pop     si
  186.                 pop     di
  187.                 ret
  188.  
  189. ScrollUp        ENDP
  190.  
  191. ScrollDown      PROC FAR x:word,y:word,len:word,dep:word
  192.                 PUBLIC ScrollDown
  193.  
  194.                 push    di
  195.                 push    si
  196.                 push    ds
  197.  
  198. ; calculate first pixel address
  199.  
  200.                 mov     ax,@data
  201.                 mov     ds,ax
  202.                 xor     ch,ch
  203.                 mov     cl,ds:ChaHgt
  204.  
  205.         mov    ax,y              ; ax := y
  206.                 mov     bx,dep            ; bx = depth
  207.                 add     ax,bx             ; ax = ax + bx
  208.                 mul     cl                ; convert text to graph
  209.                 dec     ax                ; back off 1 line
  210.                 mov     dx,BytesPerLine
  211.                 mul     dx
  212.         mov    si,argx     ; bx := x
  213.                 add     si,ax           ; si := video buffer offset
  214.                 mov     ax,VideoBufferSeg
  215.                 mov     es,ax        ; es:si -> write to
  216.  
  217.                 mov     ax,cx           ; AX = char height
  218.                 mov     dx,BytesPerLine
  219.                 mul     dx
  220.                 mov     di,si
  221.                 sub     di,ax             ; DI := Read from offset
  222.  
  223. ; set up graphics controller registers
  224.  
  225.                 mov     dx,3ceh
  226.                 mov     ax,0105h
  227.                 out     dx,ax
  228.  
  229. ; routine for byte aligned characters
  230.  
  231.                 xor     ah,ah
  232.                 mov     al,ds:ChaHgt
  233.                 mov     bx,dep            ; set depth of scroll
  234.                 mul     bx                ; AX = number of pixel lines to move
  235.                 xor     dx,dx             ; DX = 0
  236.  
  237. L20:            push    si                ; save write to pointer
  238.                 push    di                ; save read from pointer
  239.                 mov     cx,len            ; set length of line
  240.  
  241. L21:            jcxz    short Lexit2
  242.                 mov     bh,es:[di]        ; read byte
  243.                 mov     es:[si],bh
  244.                 inc     di
  245.                 inc     si
  246.                 dec     cx
  247.                 jmp     short L21
  248.  
  249. Lexit2:         pop     di
  250.                 pop     si
  251.                 sub     si,BytesPerLine
  252.                 sub     di,BytesPerLine
  253.                 dec     ax
  254.                 cmp     ax,dx
  255.                 jnz     short L20
  256.  
  257. ; restore default graphics controller registers
  258.  
  259.                 mov     ax,0ff08h
  260.                 out     dx,ax
  261.                 mov     ax,0005
  262.                 out     dx,ax
  263.                 mov     ax,0003
  264.                 out     dx,ax
  265.                 mov     ax,0f07h
  266.                 out     dx,ax
  267.                 pop     ds
  268.                 pop     si
  269.                 pop     di
  270.                 ret
  271.  
  272. ScrollDown      ENDP
  273.  
  274. ;
  275. ; The code for NoSound,Sound, and Delay is taken from the CRT unit for
  276. ; Turbo Pascal V5.0
  277.  
  278. NoSound         proc far
  279.                 public  NoSound
  280.  
  281.                 in      AL,061h
  282.                 and     AL,+252
  283.                 out     061h,AL
  284.                 ret
  285. NoSound         endp
  286.  
  287. Sound           proc far hz:word
  288.                 public  Sound
  289.  
  290.                 mov     BX,hz
  291.                 mov     AX,+13533
  292.                 mov     DX,+18
  293.                 cmp     DX,BX
  294.                 jnb     so1
  295.                 div     BX
  296.                 mov     BX,AX
  297.                 in      AL,061h
  298.                 test    AL,+3
  299.                 jnz     so2
  300.                 or      AL,+3
  301.                 out     061h,AL
  302.                 mov     AL,+182
  303.                 out     043h,AL
  304. so1:            mov     AL,BL
  305.                 out     042h,AL
  306.                 mov     AL,BH
  307.                 out     042h,AL
  308. so2:            ret
  309. Sound           endp
  310.  
  311. DELAY           PROC    FAR
  312.                 PUBLIC  DELAY
  313. De0:            MOV     BX,SP
  314.                 MOV     DX,SS:[BX+4]
  315.                 OR      DX,DX
  316.                 JZ      De1
  317.                 XOR     DI,DI
  318.                 MOV     ES,DI
  319.                 MOV     AL,ES:[DI]
  320.                 MOV     BX,[CTimer]
  321. De3:            MOV     CX,BX
  322.                 call    De2
  323.                 DEC     DX
  324.                 JNZ     De3
  325. De1:            RETF    +2
  326. De2:            CMP     AL,ES:[DI]
  327.                 JNZ     De4
  328.                 LOOP    De2
  329. De4:            retn
  330. DELAY           ENDP
  331.  
  332. InitCTimer      proc far
  333.                 public InitCTimer
  334.  
  335.                 mov     ax,40h
  336.                 mov     es,ax
  337.                 mov     di,6ch      ; es:[di] =
  338.                 mov     al,es:[di]  ; timer ticks since midnight
  339. IC0:            cmp     al,es:[di]
  340.                 je      IC0
  341.                 mov     al,es:[di]
  342.                 mov     cx,0FFFFh
  343.                 call    De2
  344.                 mov     ax,0037h
  345.                 xchg    cx,ax
  346.                 not     ax
  347.                 xor     dx,dx
  348.                 div     cx
  349.                 mov     [CTimer],ax
  350.                 ret
  351. InitCTimer      endp
  352.  
  353.                 end
  354.