home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
235_01
/
direct.asm
< prev
next >
Wrap
Assembly Source File
|
1987-06-18
|
20KB
|
672 lines
PAGE 60,132
TITLE Routines to do direct screen I/O
; 011 12-Dec-86 direct.asm
; Copyright (c) 1986 by Blue Sky Software. All rights reserved.
_TEXT SEGMENT BYTE PUBLIC 'CODE'
_TEXT ENDS
CONST SEGMENT WORD PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT WORD PUBLIC 'BSS'
_BSS ENDS
_DATA SEGMENT WORD PUBLIC 'DATA'
_DATA ENDS
DGROUP GROUP CONST, _BSS, _DATA
ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
_DATA SEGMENT
EXTRN _screen:DWORD
EXTRN _cursor:DWORD
EXTRN _vid_attrib:BYTE
EXTRN _vid_snow:BYTE
boxloc dw 0 ; stores the starting offset to the dialog box
_DATA ENDS
_TEXT SEGMENT
;******************************************************************************
;
; gotorc(r,c) move 'cursor' to specified row, col
;
;******************************************************************************
PUBLIC _gotorc
_gotorc PROC NEAR
push bp
mov bp,sp
mov ax,[bp+4] ; row to ax
mov cl,5
shl ax,cl ; row * 32
mov bx,ax
shl ax,1
shl ax,1 ; row * 128
add ax,bx ; row * 160
mov bx,[bp+6] ; col to bx
shl bx,1 ; col * 2
add ax,bx ; row * 160 + col * 2 = cursor
mov WORD PTR _cursor,ax
mov sp,bp
pop bp
ret
_gotorc ENDP
;******************************************************************************
;
; disp_str(s) display a string at current location
;
;******************************************************************************
PUBLIC _disp_str
_disp_str PROC NEAR
push bp
mov bp,sp
push di
push si
mov si,[bp+4]
mov ah,_vid_attrib ; attribute byte to ah
les di,DWORD PTR _cursor ; cursor ptr to es:di
jmp SHORT tst_ch ; skip to load/test code
chloop:
IFDEF nosnow ; if adapter doesn't snow, its quick
stosw ; store char and attrib to es:[di++]
ELSE ; well, its not so quick or easy....
mov cx,1
call stvideo
ENDIF
tst_ch: lodsb ; string char to al
or al,al ; done when char = 0
jne chloop
mov WORD PTR _cursor,di ; update cursor offset
pop si
pop di
mov sp,bp
pop bp
ret
_disp_str ENDP
;******************************************************************************
;
; disp_char(ch) display a single char at current location
;
;******************************************************************************
PUBLIC _disp_char
_disp_char PROC NEAR
push bp
mov bp,sp
push di
les di,DWORD PTR _cursor ; cursor loc to es:di
mov al,[bp+4] ; get char to store in video memory
mov ah,_vid_attrib ; get video attribute
IFDEF nosnow
stosw ; store 'em and update di
ELSE
mov cx,1
call stvideo
ENDIF
mov WORD PTR _cursor,di ; update cursor offset
pop di
mov sp,bp
pop bp
ret
_disp_char ENDP
;******************************************************************************
;
; disp_rep(ch,cnt) display a single char cnt times at current location
;
;******************************************************************************
PUBLIC _disp_rep
_disp_rep PROC NEAR
push bp
mov bp,sp
push di
les di,DWORD PTR _cursor ; cursor loc to es:di
mov al,[bp+4] ; get char to store in video memory
mov ah,_vid_attrib ; get video attribute
mov cx,[bp+6] ; rep count to cx
IFDEF nosnow
rep stosw ; store 'em and update di
ELSE
call stvideo
ENDIF
mov WORD PTR _cursor,di ; update cursor offset
pop di
mov sp,bp
pop bp
ret
_disp_rep ENDP
;******************************************************************************
;
; insert_line(r,n) insert a line at row, effects n lines
;
;******************************************************************************
PUBLIC _insert_line
_insert_line PROC NEAR
push bp
mov bp,sp
push di
push si
mov bx,[bp+4] ; ( r + n - 1) * 160 - 2 =
add bx,[bp+6] ; end of new last row
dec bx
mov ax,160
imul bx
dec ax
dec ax
mov si,ax ; (but its the source for the move)
add ax,160 ; call addr of dest (where new last
mov di,ax ; line will go)
std ; to insert a row, need to go backwards
call scroll_video ; scroll the video buffer
mov al,20h ; fill the inserted line with blanks
mov ah,_vid_attrib
mov cx,80
IFDEF nosnow
rep stosw
ELSE
call stvideo
ENDIF
cld ; C expects it this way
pop si
pop di
mov sp,bp
pop bp
ret
_insert_line ENDP
;******************************************************************************
;
; delete_line(r,n) delete a line at row, effects n lines
;
;******************************************************************************
PUBLIC _delete_line
_delete_line PROC NEAR
push bp
mov bp,sp
push di
push si
mov ax,160 ; get row
imul WORD PTR [bp+4] ; turn into offset in video ram
mov di,ax
add ax,160 ; calc offset of next row
mov si,ax
call scroll_video ; scroll the video buffer
mov al,20h ; fill the last line with blanks
mov ah,_vid_attrib
mov cx,80
IFDEF nosnow
rep stosw
ELSE
call stvideo
ENDIF
pop si
pop di
mov sp,bp
pop bp
ret
_delete_line ENDP
;*****************************************************************************
;
; scroll_video support routine for insert/delete line
;
;*****************************************************************************
scroll_video PROC NEAR
mov ax,80 ; get # rows to move and
imul WORD PTR [bp+6] ; turn into # words to move
mov cx,ax
IFNDEF nosnow
mov al,_vid_snow ; movideo needs vid_snow - get it
ENDIF ; before ds gets changed
push ds ; save current ds
mov bx,WORD PTR _screen+2 ; segment address of video ram
mov ds,bx ; moving to/from video ram
mov es,bx
IFDEF nosnow
rep movsw ; scroll the data in the video buffer
ELSE
call movideo
ENDIF
pop ds ; restore ds
ret