home *** CD-ROM | disk | FTP | other *** search
- ;
- ; sc_drive.asm
- ;
- ; Purpose: Screen handling primitives.
- ;
- ; Blackstar C Function Libarary
- ; (c) Copyright 1985,1989 Sterling Castle Software
- ;
-
- include model
- include blackstr.mac
-
-
- ;-------------------------------------
- ; equates for bios interface.
- ;-------------------------------------
- ;
- ; the interrupt and codes for the screen interface interrupt.
-
- video equ 10h ;interrupt for dealing with screen
-
- mode equ 0 ;code for setting new screen mode
- curtype equ 1 ;code for setting new cursor type
- setcur equ 2 ;code for addressing cursor
- readcur equ 3 ;code for reading cursor location
- pageud equ 5 ;code for changing text page
- scrollup equ 6 ;code to scroll screen up
- scrolldn equ 7 ;code to scroll screen down
- readch equ 8 ;code to read a character from screen
- writeca equ 9 ;code to write char and attributes
- writech equ 10 ;code to write character only
- setpal equ 11 ;code to set new setpal or border
- wdot equ 12 ;code to write a dot
- rdot equ 13 ;code to read a dot
- wtty equ 14 ;code to write as if teletype
- state equ 15 ;code to find current screen status
-
- bwstat equ 03bah ;B/W status port
- clstat equ 03dah ;Color status port
- crt_cols equ 80
- crt_rows equ 25
-
- NOADP equ 0ffh ;no adapter present
- MONADP equ 01 ;monochrome adapter
- CGAADP equ 02 ;cga adapter
- EGAADP equ 04 ;ega adapter
-
-
- dseg 'DATA'
-
- ;-------------------------------------------
- ; external variables used from C program
- ;----------------------------------------------
-
- public _sc_attr_,_sc_cols_,_sc_rows_,_sc_adpt_
- public _sc_mem_, _sc_mode_,_sc_page_,_sc_col_,_sc_row_
- public _sc_colr_,_sc_adp_, _sc_ega_, _sc_mem_
- public _colst_, _colen_, _rowst_, _rowen_
-
- ifdef asm_386
- alias colst_,dword
- _colst_ dd 0 ;starting column
- alias colen_,dword
- _colen_ dd 0 ;ending column
- alias rowst_,dword
- _rowst_ dd 0 ;starting row
- alias rowen_,dword
- _rowen_ dd 0 ;ending row
-
- alias sc_cols_,dword
- _sc_cols_ dd 0 ;# columns
- alias sc_col_,dword
- _sc_col_ dd 0 ;current column
- alias sc_attr_,byte
- _sc_attr_ db 7 ;current attributes for screen
- alias sc_adp_,byte
- _sc_adp_ db 255 ;monitor type 0-BW,1-CGA,2-EGA
- alias sc_ega_,byte
- _sc_ega_ db 0 ;EGA switch setting
- alias sc_colr_,byte
- _sc_colr_ db 0 ;EGA color bit
- alias sc_mem_,byte
- _sc_mem_ db 0 ;EGA memory size in k's
- alias sc_row_,dword
- _sc_row_ dd 0 ;current row
- alias sc_rows_,dword
- _sc_rows_ dd 0 ;# rows
- alias sc_page_,dword
- _sc_page_ dd 0 ;current page
- alias sc_mode_,dword
- _sc_mode_ dd 0 ;current mode
- else
- alias colst_,word
- _colst_ dw 0 ;starting column
- alias colen_,word
- _colen_ dw 0 ;ending column
- alias rowst_,word
- _rowst_ dw 0 ;starting row
- alias rowen_,word
- _rowen_ dw 0 ;ending row
-
- alias sc_cols_,word
- _sc_cols_ dw 0 ;# columns
- alias sc_col_,word
- _sc_col_ dw 0 ;current column
- alias sc_attr_,byte
- _sc_attr_ db 7 ;current attributes for screen
- alias sc_adp_,byte
- _sc_adp_ db 255 ;monitor type 0-BW,1-CGA,2-EGA
- alias sc_ega_,byte
- _sc_ega_ db 0 ;EGA switch setting
- alias sc_colr_,byte
- _sc_colr_ db 0 ;EGA color bit
- alias sc_mem_,byte
- _sc_mem_ db 0 ;EGA memory size in k's
- alias sc_row_,word
- _sc_row_ dw 0 ;current row
- alias sc_rows_,word
- _sc_rows_ dw 0 ;# rows
- alias sc_page_,word
- _sc_page_ dw 0 ;current page
- alias sc_mode_,word
- _sc_mode_ dw 0 ;current mode
- endif
-
- enddseg
-
-
- cseg sc_gmod_
-
- ;-----------------------
- ; sc_gmod_ get the current screen mode
- ;-----------------------
- ; Usage: mode = sc_gmod_();
- ;
- ; int sc_gmod_(void);
-
- public sc_gmod_
-
- sc_gmod_ proc
- prolog
-
- ; First, determine the type of adapter present if it has not
- ; already been determined. (MONO,CGA, or EGA)
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov al,sc_adp_ ;get crt adapter type
- cmp al,NOADP ;already determined?
- jne getstate ;if so, just get current values
-
- mov ax,1200h ;EGA alternate select
- mov bl,10h ;put in bogus values for color
- mov bh,0ffh ; and memory bytes
- int 10h ;do BIOS call for alternate
- mov sc_colr_,bh ;save EGA color bit
- mov sc_ega_,cl ;save EGA switch
- mov sc_mem_,bl ;save screen memory size
-
- cmp bh,1 ;0 - color, 1 - mono
- je monotest
-
- cmp bl,03h
- jg monotest
-
- mov al,EGAADP ;ega adapter is present
- mov sc_adp_,al
- jmp getstate
-
- monotest:
- mov edx,03b4h ;crt test for mono adapter
- push edx
-
- ifdef Large_code
- push cs
- endif
-
- call _sc_adpt_
- add esp,Word_size ;adjust stack
- mov sc_adp_,MONADP ;indicate monochrome
- mov sc_mem_,16 ;16k
- cmp eax,1
- je getstate
-
- mov edx,03d4h ;CGA adapter?
- push edx
-
- ifdef Large_code
- push cs
- endif
-
- call _sc_adpt_
- add esp,Word_size ;adjust stack
- mov sc_adp_,CGAADP ;it's a cga
- cmp al,0
- mov sc_mem_,16 ;16k
- jne getstate ;it's a CGA
-
- mov sc_adp_,NOADP ;no adapter
-
- ; Now, get the adapter settings.
-
- getstate:
- mov ah,state ;command for bdos
- int video ;do bios interrupt
- mov cl,bh ;page to ecx
- mov ch,0
- mov bl,ah ;columns to ebx
- mov bh,0
- mov ah,0 ;mode to eax
- mov _sc_cols_,ebx ;save columns per line
- mov _sc_mode_,eax ;and mode
- mov _sc_page_,ecx ;and page
- mov _sc_rows_,crt_rows;
-
- ifdef Large_code
- push cs
- endif
-
- call sc_cget_
-
- gmod_x: ;exit
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_gmod_ endp
-
-
- ;------------------------
- ; sc_smod_ set a new screen mode
- ;------------------------
- ; Usage: sc_smod(newmode);
- ;
- ; int sc_smod(int newmode);
-
- public sc_smod_
-
- sc_smod_ proc
- parm386<<newmode,dword>>
- parm86<<newmode,word>>
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov al,sc_adp_ ;get crt adapter type
- cmp al,NOADP ;already determined?
- jne modset ;else find out
-
- ifdef Large_code
- push cs
- endif
-
- call sc_gmod_ ;get adapter mode
-
- modset: mov eax,newmode ;al,newmode
- mov ah,mode ;set mode command
- int video ;set new mode
-
- ifdef Large_code
- push cs
- endif
-
- call sc_gmod_ ;remember new values
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_smod_ endp
-
-
- ;----------------------
- ; sc_sattr_ set character attribute
- ;----------------------
- ; Usage: sc_sattr_(attr)
- ;
- ; int sc_sattr_(int attr);
-
- public sc_sattr_
-
- sc_sattr_ proc
- parm386<<attr,dword>>
- parm86<<attr,word>>
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov eax,attr ;get attribute
- mov _sc_attr_,al
-
- epilog
- sc_sattr_ endp
-
-
- ;---------------------
- ; sc_font_ set new character font
- ;---------------------
- ; Usage: sc_font_(fonts);
- ;
- ; int sc_font_(struct FONT *fonts);
-
- public sc_font_
-
- sc_font_ proc
- parms<<fonts,ptr>>
- prolog
- push es ;save es - we'll use it
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- loadptr les,edi,fonts ;FONT structure
- mov ah,011h ;load font command
- mov al,[edi] ;type
- mov ecx,[edi+1] ;count of characters
- mov ebx,[edi+3] ;block,bytes/character
- mov edx,[edi+5] ;offset to table
- mov ebp,[edi+7] ;address of table
-
- ifdef Large_data
- mov si,[edi+7] ;segment
- push si
- pop es ;es:ebp points to table
- else
- push ds
- pop es ;use current segment
- endif
-
- int 10h ;do interrupt
- mov eax,1130h ;now get rows
- int 10h
- mov dh,0
- mov sc_rows_,edx ;# rows per screen
- pop es ;restore es
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_font_ endp
-
-
- ;---------------------
- ; _sc_adpt_ test display adapter
- ;---------------------
- ; Usage: _sc_adpt_(addr);
- ;
- ; int _sc_adpt_(int addr);
-
- public _sc_adpt_
-
- _sc_adpt_ proc
- parm386<<addr,dword>>
- parm86<<addr,word>>
- prolog
-
- mov edx,addr ;get mem address
- mov al,0fh ;mov cursor
- out dx,al
- inc dx
- in al,dx ;save old
- mov bh,al
- mov al,5ah ;mov cursor
- out dx,al
- jmp $+2 ;kill some time
- jmp $+2
- jmp $+2
- in al,dx ;where is it now?
- cmp al,5ah ;same place
- mov al,bh ;restore old
- out dx,al
- jne fail
-
- mov eax,1 ;true
- jmp adpt_x
-
- fail: xor eax,eax
-
- adpt_x: epilog
- _sc_adpt_ endp
-
-
- ;----------------------
- ; _sc_s7bit_ set bit 7 character attribute
- ;----------------------
- ; Usage: sc_s7bit_(TRUE/FALSE);
- ;
- ; int sc_s7bit_(int flag);
-
- public sc_s7bit_
-
- sc_s7bit_ proc
- parm386<<flag,dword>>
- parm86<<flag,word>>
- prolog
-
- mov eax,1003h ;int 10 with ah=3
- mov ebx,flag ;get attribute
- int video
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_s7bit_ endp
-
-
- ;------------------------
- ; sc_cget_ get current cursor location
- ;------------------------
- ; Usage: sc_cget_();
- ;
- ; int sc_cget_(void);
-
- public sc_cget_
-
- sc_cget_ proc
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov ah,readcur ;command to read cursor
- mov ebx,_sc_page_ ;from current page
- int video ;bios
- mov cl,dh ;row to ecx
- mov ch,0
- mov dh,0 ;column in edx
- mov _sc_col_,edx ;update globals
- mov _sc_row_,ecx
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_cget_ endp
-
-
- ;------------------------
- ; sc_cset_ sets cursor at any location.
- ;------------------------
- ; Usage: sc_cset(new_col,new_row)
- ;
- ; int sc_cset(int new_col, int new_row);
-
- public sc_cset_
-
- sc_cset_ proc ; move cursor to x,y
- parm386<<new_col,dword>,<new_row,dword>>
- parm86<<new_col,word>,<new_row,word>>
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov edx,new_col ; column
- mov eax,new_row ; row
- mov _sc_col_,edx ; update global
- mov _sc_row_,eax ; update row global
- mov dh,al
- mov ebx,_sc_page_ ; set page
- mov bh,bl ; to bh
- mov ah,setcur ; set cursor location
- int video ; call bios
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_cset_ endp
-
-
- ;-----------------------
- ; _sc_swup_ Scroll the screen up. The window is scrolled
- ;----------------------- up nline lines. A zero nline will clear the
- ; window. Top left screen in 0,0.
- ;
- ; Usage: sc_swup_(nline,fromrow,fromcol,torow,tocol)
-
- public sc_swup_
-
- sc_swup_ proc
- parm386<<nline,dword>,<fromrow,dword>,<fromcol,dword>,<torow,dword>,<tocol,dword>>
- parm86<<nline,word>,<fromrow,word>,<fromcol,word>,<torow,word>,<tocol,word>>
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov eax,fromrow ;starting row
- mov ch,al
- mov eax,fromcol ;starting column
- mov cl,al
- mov eax,torow ;ending row
- mov dh,al
- mov eax,tocol ;ending column
- mov dl,al
- mov bh,_sc_attr_ ;current attribute
- mov eax,nline ;number of lines
- mov ah,scrollup
- int video ;do the scroll
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_swup_ endp
-
-
- ;----------------------
- ; sc_swdn_ scroll the screen down. the window is scrolled
- ;---------------------- down nline lines. A zero nline will clear the
- ; window. Top left of the screen in 0,0.
- ;
- ; Usage: sc_swdn_(nline,fromrow,fromcol,torow,tocol);
-
- public sc_swdn_
-
- sc_swdn_ proc
- parm386<<nmline,dword>,<frmrow,dword>,<frmcol,dword>,<trow,dword>,<tcol,dword>>
- parm86<<nmline,word>,<frmrow,word>,<frmcol,word>,<trow,word>,<tcol,word>>
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov eax,frmrow ;starting row
- mov ch,al
- mov eax,frmcol ;starting column
- mov cl,al
- mov eax,trow ;ending row
- mov dh,al
- mov eax,tcol ;ending column
- mov dl,al
- mov bh,_sc_attr_ ;current attribute
- mov eax,nmline ;number of lines
- mov ah,scrolldn
- int video ;do the scroll
-
- epilog
- sc_swdn_ endp
-
-
- ;---------------------
- ; _sc_csof_ turn cursor off.
- ;---------------------
- ; Usage: sc_csof_();
- ;
- ; int sc_csof_(void);
-
- public sc_csof_
-
- sc_csof_ proc
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- cmp _sc_mode_,4 ;see if graphics
- jc text_coff
- cmp _sc_mode_,7
- jnz no_cur
-
- text_coff:
- mov ecx,0f00h ;should turn cursor off
- new_cur:
- mov ah,curtype ;set a new cursor type
- int video
-
- no_cur:
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_csof_ endp
-
-
-
- ;-----------------------
- ; sc_cson_ turn cursor back on.
- ;-----------------------
- ; Usage: sc_cson_();
- ;
- ; int sc_cson_(void);
- public sc_cson_
-
- sc_cson_ proc
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov ecx,0c0dh ;assume monocrome
- cmp _sc_mode_,7 ;true is mono
- jz new_c ;set it
- mov ecx,0607h ;assume color card in text mode
- cmp _sc_mode_,4 ;color text is 0 to 3
- jc new_c
- jmp sc_csx
-
- new_c: mov ah,curtype ;set a new cursor type
- int video
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- sc_csx: epilog
- sc_cson_ endp
-
-
- ;------------------
- ; sc_getc_ screen input (read character from the screen).
- ;------------------
- ; Usage: character = sc_getc();
- ;
- ; int sc_cgetc(void);
-
- public sc_getc_
-
- sc_getc_ proc
- prolog
-
- mov bh,0 ;only read from page 0
- mov ah,readch ;code to read a character
- int video ;al is letter, ah=attributes
- or al,al ;zero returned instead of blank in graphics mode
- jnz ret_ch
- mov al,' '
-
- ret_ch: mov ah,0 ;kill the attributes
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_getc_ endp
-
-
- ;-------------------
- ; sc_putc_ output char & attribute
- ;-------------------
- ; Usage: sc_putc_(char)
- ;
- ; int sc_putc_(char c);
-
- public sc_putc_
-
- sc_putc_ proc
- parms<<c,byte>>
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov al,c ;get character
- mov ecx,1 ;number of chars to write
- mov ebx,_sc_page_ ;write to page
- mov bh,bl
- mov bl,_sc_attr_ ;attribute
- mov ah,writeca ;write char & attr command
- int video ;do it
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_putc_ endp
-
-
- ;------------------
- ; sc_gwin_ get screen windo to buffer
- ;------------------
- ; Usage: character = sc_gwin(page,buff);
- ;
- ; int sc_gwin(int page, char *buff);
-
- public sc_gwin_
-
- sc_gwin_ proc
- parm386<<pg,dword>,<buff,ptr>>
- parm86<<pg,word>,<buff,ptr>>
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- push es ;save es for segment
- mov edx,_rowst_ ;rows to edx
- loadptr les,edi,buff ;buffer pointer
- mov ebx,pg ;read from page
- xchg bh,bl ;***********
-
- gwin1: mov ecx,_colst_ ;columns to ecx
-
- gwin2: push edx
- mov dh,dl ;set dh,dl to row,col
- mov dl,cl ;columns to dl for curset
- mov ah,02
- int video ;do interrupt for curset
- pop edx
- mov ah,readch ;code to read a character
- int video ;al is letter, ah=attributes
- mov es:[edi],eax ;store char and attr
- inc edi ;next buffer location
- inc edi
- inc ecx ;next column
- cmp ecx,_colen_
- jle gwin2
-
- inc edx ;next row
- cmp edx,_rowen_ ;last row?
- jle gwin1
-
- pop es ;restore segment pointer
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_gwin_ endp
-
-
- ;------------------
- ; _sc_pwin_ put buffer to screen windo
- ;------------------
- ; Usage: character = sc_pwin(page,buff);
- ;
- ; int sc_pwin(int page, char *buff);
-
- public sc_pwin_
-
- sc_pwin_ proc
- parm386<<pge,dword>,<buff1,ptr>>
- parm86<<pge,word>,<buff1,ptr>>
- prolog
- push es ;save es for segment
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov edx,_rowst_ ;rows to edx
- loadptr les,edi,buff1 ;buffer pointer
- mov ebx,pge ;write to page
- xchg bh,bl ;*************
-
- pwin1: mov ecx,_colst_ ;columns to ecx
-
- pwin2: push edx
- mov dh,dl ;set dh,dl to row,col
- mov dl,cl ;columns to dl for curset
- mov ah,02
- int video ;set cursor
- pop edx
- mov eax,es:[edi] ;get attr/char
- mov bl,ah ;attribute to bl
- push ecx ;save column count
- mov ecx,1 ;write one char
- mov ah,writeca ;code to read a character
- int video ;al is letter, ah=attributes
- pop ecx ;restore col count
- inc edi ;next buffer location
- inc edi
- inc ecx ;next column
- cmp ecx,_colen_
- jle pwin2
-
- inc edx ;next row
- cmp edx,_rowen_ ;last row?
- jle pwin1
-
- pop es ;restore segment pointer
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- sc_pwin_ endp
-
- endcseg sc_gmod_
- end
-
-