home *** CD-ROM | disk | FTP | other *** search
- ; The code in PUTCHAR is modified from the Robert Wilton book pgs. 288-292.
-
- BytesPerLine = 80 ; (or 40 in 320x200 16-color mode)
- RMWbits = 00h ; Read-Modify-Write bits
- OriginOffset = 0
- VideoBufferSeg = 0a000h
-
- .model tpascal
-
- .data
- extrn fonttable : dword
- extrn chahgt : byte
- CTimer DW ?
-
- .code
-
- putchar proc far argc:word,argx:word,argy:word,fgd:byte,bkg:byte
- public putchar
-
- push ds
- push si
- push es
- push di
-
-
- ; set up character definition table addressing
-
- mov ax,@data
- mov ds,ax
- xor cx,cx
- mov cl,ds:chahgt ; number of pixel rows in char
- les di,ds:fonttable
- mov ax,argc ; al := character code
- mul cl ; ax := offset into char def table
- ; (points * char code)
- add di,ax ; di := addr of char def
- ; es:di = char pattern
-
- ; calculate first pixel address
-
- mov ax,argy ; ax := y
- mul cl
- mov dx,BytesPerLine
- mul dx
- mov si,argx ; bx := x
- add si,ax ; si := video buffer offset
- mov ax,VideoBufferSeg
- mov ds,ax ; ds:si -> video buffer
-
- ; set up graphics controller registers
-
- mov dx,3ceh ; graphics controller address reg port
-
- mov ax,0a05h ; al := mode register number
- ; ah := write mode 2 (bits 0-1)
- ; read mode 1 (bit 4)
- out dx,ax
-
- xor ah,ah ; ah := read-modify-write bits
- mov al,3 ; al := data rotate/function select reg
- out dx,ax
-
- mov ax,0007 ; ah := color don't care bits
- ; al := color don't care reg number
- out dx,ax ; "don't care" for all bit planes
-
- ; select output routine depending on whether character is byte-aligned
-
- mov bl,fgd ; bl := foreground pixel value
- mov bh,bkg ; bh := background pixel value
-
- mov al,8 ; al := bit mask register number
-
- wrtcl10p: mov ah,es:[di] ; ah := pattern for next row of pixels
-
- out dx,ax ; update bit mask register
- and [si],bl ; update foreground pixels
-
- not ah ; create mask for background
- out dx,ax ; update bit mask register
- and [si],bh ; update background pixels
-
- inc di ; es:di -> next byte in char def table
- add si,BytesPerLine ; increment to next line in video buffer
- loop wrtcl10p
-
- ; restore default graphics controller registers
-
- mov ax,0ff08h ; default bit mask
- out dx,ax
-
- mov ax,0005 ; default mode register
- out dx,ax
-
- mov ax,0003 ; default data rotate/function select
- out dx,ax
-
- mov ax,0f07h ; default color don't care
- out dx,ax
-
- pop di
- pop es
- pop si
- pop ds
-
- ret
-
- putchar endp
-
-
- ScrollUp PROC FAR x:word,y:word,len:word,dep:word
- PUBLIC ScrollUp
-
- push di
- push si
- push ds
-
- ; calculate first pixel address
-
- mov ax,@data
- mov ds,ax
- xor ch,ch
- mov cl,ds:ChaHgt
-
- mov ax,argy ; ax := y
- mul cl
- mov dx,BytesPerLine
- mul dx
- mov si,argx ; bx := x
- add si,ax ; si := video buffer offset
- mov ax,VideoBufferSeg
- mov es,ax ; es:si -> write to
-
- mov ax,cx ; AX = char height
- mov dx,BytesPerLine
- mul dx
- mov di,si
- add di,ax ; DI := Read from offset
-
- ; set up graphics controller registers
-
- mov dx,3ceh
- mov ax,0105h
- out dx,ax
-
- ; routine for byte aligned characters
-
- xor ah,ah
- mov al,ds:ChaHgt
- mov bx,dep ; set depth of scroll
- mul bx ; AX = number of pixel lines to move
- xor dx,dx ; DX = 0
-
- L10: push si ; save write to pointer
- push di ; save read from pointer
- mov cx,len ; set length of line
-
- L11: jcxz short Lexit1
- mov bh,es:[di] ; read byte
- mov es:[si],bh
- inc di
- inc si
- dec cx
- jmp short L11
-
- Lexit1: pop di
- pop si
- add si,BytesPerLine
- add di,BytesPerLine
- dec ax
- cmp ax,dx
- jnz short L10
-
- ; restore default graphics controller registers
-
- mov ax,0ff08h
- out dx,ax
- mov ax,0005
- out dx,ax
- mov ax,0003
- out dx,ax
- mov ax,0f07h
- out dx,ax
- pop ds
- pop si
- pop di
- ret
-
- ScrollUp ENDP
-
- ScrollDown PROC FAR x:word,y:word,len:word,dep:word
- PUBLIC ScrollDown
-
- push di
- push si
- push ds
-
- ; calculate first pixel address
-
- mov ax,@data
- mov ds,ax
- xor ch,ch
- mov cl,ds:ChaHgt
-
- mov ax,y ; ax := y
- mov bx,dep ; bx = depth
- add ax,bx ; ax = ax + bx
- mul cl ; convert text to graph
- dec ax ; back off 1 line
- mov dx,BytesPerLine
- mul dx
- mov si,argx ; bx := x
- add si,ax ; si := video buffer offset
- mov ax,VideoBufferSeg
- mov es,ax ; es:si -> write to
-
- mov ax,cx ; AX = char height
- mov dx,BytesPerLine
- mul dx
- mov di,si
- sub di,ax ; DI := Read from offset
-
- ; set up graphics controller registers
-
- mov dx,3ceh
- mov ax,0105h
- out dx,ax
-
- ; routine for byte aligned characters
-
- xor ah,ah
- mov al,ds:ChaHgt
- mov bx,dep ; set depth of scroll
- mul bx ; AX = number of pixel lines to move
- xor dx,dx ; DX = 0
-
- L20: push si ; save write to pointer
- push di ; save read from pointer
- mov cx,len ; set length of line
-
- L21: jcxz short Lexit2
- mov bh,es:[di] ; read byte
- mov es:[si],bh
- inc di
- inc si
- dec cx
- jmp short L21
-
- Lexit2: pop di
- pop si
- sub si,BytesPerLine
- sub di,BytesPerLine
- dec ax
- cmp ax,dx
- jnz short L20
-
- ; restore default graphics controller registers
-
- mov ax,0ff08h
- out dx,ax
- mov ax,0005
- out dx,ax
- mov ax,0003
- out dx,ax
- mov ax,0f07h
- out dx,ax
- pop ds
- pop si
- pop di
- ret
-
- ScrollDown ENDP
-
- ;
- ; The code for NoSound,Sound, and Delay is taken from the CRT unit for
- ; Turbo Pascal V5.0
-
- NoSound proc far
- public NoSound
-
- in AL,061h
- and AL,+252
- out 061h,AL
- ret
- NoSound endp
-
- Sound proc far hz:word
- public Sound
-
- mov BX,hz
- mov AX,+13533
- mov DX,+18
- cmp DX,BX
- jnb so1
- div BX
- mov BX,AX
- in AL,061h
- test AL,+3
- jnz so2
- or AL,+3
- out 061h,AL
- mov AL,+182
- out 043h,AL
- so1: mov AL,BL
- out 042h,AL
- mov AL,BH
- out 042h,AL
- so2: ret
- Sound endp
-
- DELAY PROC FAR
- PUBLIC DELAY
- De0: MOV BX,SP
- MOV DX,SS:[BX+4]
- OR DX,DX
- JZ De1
- XOR DI,DI
- MOV ES,DI
- MOV AL,ES:[DI]
- MOV BX,[CTimer]
- De3: MOV CX,BX
- call De2
- DEC DX
- JNZ De3
- De1: RETF +2
- De2: CMP AL,ES:[DI]
- JNZ De4
- LOOP De2
- De4: retn
- DELAY ENDP
-
- InitCTimer proc far
- public InitCTimer
-
- mov ax,40h
- mov es,ax
- mov di,6ch ; es:[di] =
- mov al,es:[di] ; timer ticks since midnight
- IC0: cmp al,es:[di]
- je IC0
- mov al,es:[di]
- mov cx,0FFFFh
- call De2
- mov ax,0037h
- xchg cx,ax
- not ax
- xor dx,dx
- div cx
- mov [CTimer],ax
- ret
- InitCTimer endp
-
- end