2005-04-17 02:20:36 +04:00
/ * video. S
*
* Display a d a p t e r & v i d e o m o d e s e t u p , v e r s i o n 2 . 1 3 ( 1 4 - M a y - 9 9 )
*
* Copyright ( C ) 1 9 9 5 - - 1 9 9 8 M a r t i n M a r e s < m j @ucw.cz>
* Based o n t h e o r i g i n a l s e t u p . S c o d e ( C ) L i n u s T o r v a l d s a n d M a t s A n d e r s o n
*
* Rewritten t o u s e G N U ' a s ' b y C h r i s N o e < s t i k e r @northlink.com> May 1999
*
* For f u r t h e r i n f o r m a t i o n , l o o k a t D o c u m e n t a t i o n / s v g a . t x t .
*
* /
/* Enable autodetection of SVGA adapters and modes. */
# undef C O N F I G _ V I D E O _ S V G A
/* Enable autodetection of VESA modes */
# define C O N F I G _ V I D E O _ V E S A
/* Enable compacting of mode table */
# define C O N F I G _ V I D E O _ C O M P A C T
/* Retain screen contents when switching modes */
# define C O N F I G _ V I D E O _ R E T A I N
/* Enable local mode list */
# undef C O N F I G _ V I D E O _ L O C A L
/* Force 400 scan lines for standard modes (hack to fix bad BIOS behaviour */
# undef C O N F I G _ V I D E O _ 4 0 0 _ H A C K
/* Hack that lets you force specific BIOS mode ID and specific dimensions */
# undef C O N F I G _ V I D E O _ G F X _ H A C K
# define V I D E O _ G F X _ B I O S _ A X 0 x4 f02 / * 8 0 0 x60 0 o n T h i n k P a d * /
# define V I D E O _ G F X _ B I O S _ B X 0 x01 0 2
# define V I D E O _ G F X _ D U M M Y _ R E S O L U T I O N 0 x64 2 5 / * 1 0 0 x37 * /
/ * This c o d e u s e s a n e x t e n d e d s e t o f v i d e o m o d e n u m b e r s . T h e s e i n c l u d e :
* Aliases f o r s t a n d a r d m o d e s
* NORMAL_ V G A ( - 1 )
* EXTENDED_ V G A ( - 2 )
* ASK_ V G A ( - 3 )
* Video m o d e s n u m b e r e d b y m e n u p o s i t i o n - - N O T R E C O M M E N D E D b e c a u s e o f l a c k
* of c o m p a t i b i l i t y w h e n e x t e n d i n g t h e t a b l e . T h e s e a r e b e t w e e n 0 x00 a n d 0 x f f .
* /
# define V I D E O _ F I R S T _ M E N U 0 x00 0 0
/* Standard BIOS video modes (BIOS number + 0x0100) */
# define V I D E O _ F I R S T _ B I O S 0 x01 0 0
/* VESA BIOS video modes (VESA number + 0x0200) */
# define V I D E O _ F I R S T _ V E S A 0 x02 0 0
/* Video7 special modes (BIOS number + 0x0900) */
# define V I D E O _ F I R S T _ V 7 0 x09 0 0
/* Special video modes */
# define V I D E O _ F I R S T _ S P E C I A L 0 x0 f00
# define V I D E O _ 8 0 x25 0 x0 f00
# define V I D E O _ 8 P O I N T 0 x0 f01
# define V I D E O _ 8 0 x43 0 x0 f02
# define V I D E O _ 8 0 x28 0 x0 f03
# define V I D E O _ C U R R E N T _ M O D E 0 x0 f04
# define V I D E O _ 8 0 x30 0 x0 f05
# define V I D E O _ 8 0 x34 0 x0 f06
# define V I D E O _ 8 0 x60 0 x0 f07
# define V I D E O _ G F X _ H A C K 0 x0 f08
# define V I D E O _ L A S T _ S P E C I A L 0 x0 f09
/* Video modes given by resolution */
# define V I D E O _ F I R S T _ R E S O L U T I O N 0 x10 0 0
/* The "recalculate timings" flag */
# define V I D E O _ R E C A L C 0 x80 0 0
/* Positions of various video parameters passed to the kernel */
/* (see also include/linux/tty.h) */
# define P A R A M _ C U R S O R _ P O S 0 x00
# define P A R A M _ V I D E O _ P A G E 0 x04
# define P A R A M _ V I D E O _ M O D E 0 x06
# define P A R A M _ V I D E O _ C O L S 0 x07
# define P A R A M _ V I D E O _ E G A _ B X 0 x0 a
# define P A R A M _ V I D E O _ L I N E S 0 x0 e
# define P A R A M _ H A V E _ V G A 0 x0 f
# define P A R A M _ F O N T _ P O I N T S 0 x10
# define P A R A M _ L F B _ W I D T H 0 x12
# define P A R A M _ L F B _ H E I G H T 0 x14
# define P A R A M _ L F B _ D E P T H 0 x16
# define P A R A M _ L F B _ B A S E 0 x18
# define P A R A M _ L F B _ S I Z E 0 x1 c
# define P A R A M _ L F B _ L I N E L E N G T H 0 x24
# define P A R A M _ L F B _ C O L O R S 0 x26
# define P A R A M _ V E S A P M _ S E G 0 x2 e
# define P A R A M _ V E S A P M _ O F F 0 x30
# define P A R A M _ L F B _ P A G E S 0 x32
# define P A R A M _ V E S A _ A T T R I B 0 x34
2006-04-11 09:55:48 +04:00
# define P A R A M _ C A P A B I L I T I E S 0 x36
2005-04-17 02:20:36 +04:00
/* Define DO_STORE according to CONFIG_VIDEO_RETAIN */
# ifdef C O N F I G _ V I D E O _ R E T A I N
# define D O _ S T O R E c a l l s t o r e _ s c r e e n
# else
# define D O _ S T O R E
# endif / * C O N F I G _ V I D E O _ R E T A I N * /
# This i s t h e m a i n e n t r y p o i n t c a l l e d b y s e t u p . S
# % ds * m u s t * b e p o i n t i n g t o t h e b o o t s e c t o r
video : pushw % d s # W e u s e d i f f e r e n t s e g m e n t s
pushw % d s # F S c o n t a i n s o r i g i n a l D S
popw % f s
pushw % c s # D S i s e q u a l t o C S
popw % d s
pushw % c s # E S i s e q u a l t o C S
popw % e s
xorw % a x , % a x
movw % a x , % g s # G S i s z e r o
cld
call b a s i c _ d e t e c t # B a s i c a d a p t e r t y p e t e s t i n g ( E G A / V G A / M D A / C G A )
# ifdef C O N F I G _ V I D E O _ S E L E C T
movw % f s : ( 0 x01 f a ) , % a x # U s e r s e l e c t e d v i d e o m o d e
cmpw $ A S K _ V G A , % a x # B r i n g u p t h e m e n u
jz v i d2
call m o d e _ s e t # S e t t h e m o d e
jc v i d1
leaw b a d m d t , % s i # I n v a l i d m o d e I D
call p r t s t r
vid2 : call m o d e _ m e n u
vid1 :
# ifdef C O N F I G _ V I D E O _ R E T A I N
call r e s t o r e _ s c r e e n # R e s t o r e s c r e e n c o n t e n t s
# endif / * C O N F I G _ V I D E O _ R E T A I N * /
call s t o r e _ e d i d
# endif / * C O N F I G _ V I D E O _ S E L E C T * /
call m o d e _ p a r a m s # S t o r e m o d e p a r a m e t e r s
popw % d s # R e s t o r e o r i g i n a l D S
ret
# Detect i f w e h a v e C G A , M D A , E G A o r V G A a n d p a s s i t t o t h e k e r n e l .
basic_detect :
movb $ 0 , % f s : ( P A R A M _ H A V E _ V G A )
movb $ 0 x12 , % a h # C h e c k E G A / V G A
movb $ 0 x10 , % b l
int $ 0 x10
movw % b x , % f s : ( P A R A M _ V I D E O _ E G A _ B X ) # I d e n t i f i e s E G A t o t h e k e r n e l
cmpb $ 0 x10 , % b l # N o , i t ' s a C G A / M D A / H G A c a r d .
je b a s r e t
incb a d a p t e r
movw $ 0 x1 a00 , % a x # C h e c k E G A o r V G A ?
int $ 0 x10
cmpb $ 0 x1 a , % a l # 1 a m e a n s V G A . . .
jne b a s r e t # a n y t h i n g e l s e i s E G A .
incb % f s : ( P A R A M _ H A V E _ V G A ) # W e ' v e d e t e c t e d a V G A
incb a d a p t e r
basret : ret
# Store t h e v i d e o m o d e p a r a m e t e r s f o r l a t e r u s a g e b y t h e k e r n e l .
# This i s d o n e b y a s k i n g t h e B I O S e x c e p t f o r t h e r o w s / c o l u m n s
# parameters i n t h e d e f a u l t 8 0 x25 m o d e - - t h e s e a r e s e t d i r e c t l y ,
# because s o m e v e r y o b s c u r e B I O S e s s u p p l y i n s a n e v a l u e s .
mode_params :
# ifdef C O N F I G _ V I D E O _ S E L E C T
cmpb $ 0 , g r a p h i c _ m o d e
jnz m o p a r _ g r
# endif
movb $ 0 x03 , % a h # R e a d c u r s o r p o s i t i o n
xorb % b h , % b h
int $ 0 x10
movw % d x , % f s : ( P A R A M _ C U R S O R _ P O S )
movb $ 0 x0 f , % a h # R e a d p a g e / m o d e / w i d t h
int $ 0 x10
movw % b x , % f s : ( P A R A M _ V I D E O _ P A G E )
movw % a x , % f s : ( P A R A M _ V I D E O _ M O D E ) # V i d e o m o d e a n d s c r e e n w i d t h
cmpb $ 0 x7 , % a l # M D A / H G A = > s e g m e n t d i f f e r s
jnz m o p a r0
movw $ 0 x b00 0 , v i d e o _ s e g m e n t
mopar0 : movw % g s : ( 0 x48 5 ) , % a x # F o n t s i z e
movw % a x , % f s : ( P A R A M _ F O N T _ P O I N T S ) # ( v a l i d o n l y o n E G A / V G A )
movw f o r c e _ s i z e , % a x # F o r c e d s i z e ?
orw % a x , % a x
jz m o p a r1
movb % a h , % f s : ( P A R A M _ V I D E O _ C O L S )
movb % a l , % f s : ( P A R A M _ V I D E O _ L I N E S )
ret
mopar1 : movb $ 2 5 , % a l
cmpb $ 0 , a d a p t e r # I f w e a r e o n C G A / M D A / H G A , t h e
jz m o p a r2 # s c r e e n m u s t h a v e 25 l i n e s .
movb % g s : ( 0 x48 4 ) , % a l # O n E G A / V G A , u s e t h e E G A + B I O S
incb % a l # l o c a t i o n o f m a x l i n e s .
mopar2 : movb % a l , % f s : ( P A R A M _ V I D E O _ L I N E S )
ret
# ifdef C O N F I G _ V I D E O _ S E L E C T
# Fetching o f V E S A f r a m e b u f f e r p a r a m e t e r s
mopar_gr :
leaw m o d e l i s t + 1 0 2 4 , % d i
movb $ 0 x23 , % f s : ( P A R A M _ H A V E _ V G A )
movw 1 6 ( % d i ) , % a x
movw % a x , % f s : ( P A R A M _ L F B _ L I N E L E N G T H )
movw 1 8 ( % d i ) , % a x
movw % a x , % f s : ( P A R A M _ L F B _ W I D T H )
movw 2 0 ( % d i ) , % a x
movw % a x , % f s : ( P A R A M _ L F B _ H E I G H T )
movb 2 5 ( % d i ) , % a l
movb $ 0 , % a h
movw % a x , % f s : ( P A R A M _ L F B _ D E P T H )
movb 2 9 ( % d i ) , % a l
movb $ 0 , % a h
movw % a x , % f s : ( P A R A M _ L F B _ P A G E S )
movl 4 0 ( % d i ) , % e a x
movl % e a x , % f s : ( P A R A M _ L F B _ B A S E )
movl 3 1 ( % d i ) , % e a x
movl % e a x , % f s : ( P A R A M _ L F B _ C O L O R S )
movl 3 5 ( % d i ) , % e a x
movl % e a x , % f s : ( P A R A M _ L F B _ C O L O R S + 4 )
movw 0 ( % d i ) , % a x
movw % a x , % f s : ( P A R A M _ V E S A _ A T T R I B )
# get v i d e o m e m s i z e
leaw m o d e l i s t + 1 0 2 4 , % d i
movw $ 0 x4 f00 , % a x
int $ 0 x10
xorl % e a x , % e a x
movw 1 8 ( % d i ) , % a x
movl % e a x , % f s : ( P A R A M _ L F B _ S I Z E )
2006-04-11 09:55:48 +04:00
# store m o d e c a p a b i l i t i e s
movl 1 0 ( % d i ) , % e a x
movl % e a x , % f s : ( P A R A M _ C A P A B I L I T I E S )
2005-04-17 02:20:36 +04:00
# switching t h e D A C t o 8 - b i t i s f o r < = 8 b p p o n l y
movw % f s : ( P A R A M _ L F B _ D E P T H ) , % a x
cmpw $ 8 , % a x
jg d a c _ d o n e
# get D A C s w i t c h i n g c a p a b i l i t y
xorl % e a x , % e a x
movb 1 0 ( % d i ) , % a l
testb $ 1 , % a l
jz d a c _ s e t
# attempt t o s w i t c h D A C t o 8 - b i t
movw $ 0 x4 f08 , % a x
movw $ 0 x08 0 0 , % b x
int $ 0 x10
cmpw $ 0 x00 4 f , % a x
jne d a c _ s e t
movb % b h , d a c _ s i z e # s t o r e a c t u a l D A C s i z e
dac_set :
# set c o l o r s i z e t o D A C s i z e
movb d a c _ s i z e , % a l
movb % a l , % f s : ( P A R A M _ L F B _ C O L O R S + 0 )
movb % a l , % f s : ( P A R A M _ L F B _ C O L O R S + 2 )
movb % a l , % f s : ( P A R A M _ L F B _ C O L O R S + 4 )
movb % a l , % f s : ( P A R A M _ L F B _ C O L O R S + 6 )
# set c o l o r o f f s e t s t o 0
movb $ 0 , % f s : ( P A R A M _ L F B _ C O L O R S + 1 )
movb $ 0 , % f s : ( P A R A M _ L F B _ C O L O R S + 3 )
movb $ 0 , % f s : ( P A R A M _ L F B _ C O L O R S + 5 )
movb $ 0 , % f s : ( P A R A M _ L F B _ C O L O R S + 7 )
dac_done :
# get p r o t e c t e d m o d e i n t e r f a c e i n f o r m a t i o n s
movw $ 0 x4 f0 a , % a x
xorw % b x , % b x
xorw % d i , % d i
int $ 0 x10
cmp $ 0 x00 4 f , % a x
jnz n o _ p m
movw % e s , % f s : ( P A R A M _ V E S A P M _ S E G )
movw % d i , % f s : ( P A R A M _ V E S A P M _ O F F )
no_pm : ret
# The v i d e o m o d e m e n u
mode_menu :
leaw k e y m s g , % s i # " Return/Space/Timeout " m e s s a g e
call p r t s t r
call f l u s h
nokey : call g e t k t
cmpb $ 0 x0 d , % a l # E N T E R ?
je l i s t m # y e s - m a n u a l m o d e s e l e c t i o n
cmpb $ 0 x20 , % a l # S P A C E ?
je d e f m d1 # n o - r e p e a t
call b e e p
jmp n o k e y
defmd1 : ret # N o m o d e c h o s e n ? D e f a u l t 80 x25
listm : call m o d e _ t a b l e # L i s t m o d e t a b l e
listm0 : leaw n a m e _ b a n n , % s i # P r i n t a d a p t e r n a m e
call p r t s t r
movw c a r d _ n a m e , % s i
orw % s i , % s i
jnz a n 2
movb a d a p t e r , % a l
leaw o l d _ n a m e , % s i
orb % a l , % a l
jz a n 1
leaw e g a _ n a m e , % s i
decb % a l
jz a n 1
leaw v g a _ n a m e , % s i
jmp a n 1
an2 : call p r t s t r
leaw s v g a _ n a m e , % s i
an1 : call p r t s t r
leaw l i s t h d r , % s i # T a b l e h e a d e r
call p r t s t r
movb $ 0 x30 , % d l # D L h o l d s m o d e n u m b e r
leaw m o d e l i s t , % s i
lm1 : cmpw $ A S K _ V G A , ( % s i ) # E n d ?
jz l m 2
movb % d l , % a l # M e n u s e l e c t i o n n u m b e r
call p r t c h r
call p r t s p2
lodsw
call p r t h w # M o d e I D
call p r t s p2
movb 0 x1 ( % s i ) , % a l
call p r t d e c # R o w s
movb $ 0 x78 , % a l # t h e l e t t e r ' x '
call p r t c h r
lodsw
call p r t d e c # C o l u m n s
movb $ 0 x0 d , % a l # N e w l i n e
call p r t c h r
movb $ 0 x0 a , % a l
call p r t c h r
incb % d l # N e x t c h a r a c t e r
cmpb $ 0 x3 a , % d l
jnz l m 1
movb $ 0 x61 , % d l
jmp l m 1
lm2 : leaw p r o m p t , % s i # M o d e p r o m p t
call p r t s t r
leaw e d i t _ b u f , % d i # E d i t o r b u f f e r
lm3 : call g e t k e y
cmpb $ 0 x0 d , % a l # E n t e r ?
jz l m e n t
cmpb $ 0 x08 , % a l # B a c k s p a c e ?
jz l m b s
cmpb $ 0 x20 , % a l # P r i n t a b l e ?
jc l m 3
cmpw $ e d i t _ b u f + 4 , % d i # E n o u g h s p a c e ?
jz l m 3
stosb
call p r t c h r
jmp l m 3
lmbs : cmpw $ e d i t _ b u f , % d i # B a c k s p a c e
jz l m 3
decw % d i
movb $ 0 x08 , % a l
call p r t c h r
call p r t s p c
movb $ 0 x08 , % a l
call p r t c h r
jmp l m 3
lment : movb $ 0 , ( % d i )
leaw c r l f t , % s i
call p r t s t r
leaw e d i t _ b u f , % s i
cmpb $ 0 , ( % s i ) # E m p t y s t r i n g = d e f a u l t m o d e
jz l m d e f
cmpb $ 0 , 1 ( % s i ) # O n e c h a r a c t e r = m e n u s e l e c t i o n
jz m n u s e l
cmpw $ 0 x63 7 3 , ( % s i ) # " scan " = > m o d e s c a n n i n g
jnz l m h x
cmpw $ 0 x6 e 6 1 , 2 ( % s i )
jz l m s c a n
lmhx : xorw % b x , % b x # E l s e = > m o d e I D i n h e x
lmhex : lodsb
orb % a l , % a l
jz l m u s e 1
subb $ 0 x30 , % a l
jc l m b a d
cmpb $ 1 0 , % a l
jc l m h x1
subb $ 7 , % a l
andb $ 0 x d f , % a l
cmpb $ 1 0 , % a l
jc l m b a d
cmpb $ 1 6 , % a l
jnc l m b a d
lmhx1 : shlw $ 4 , % b x
orb % a l , % b l
jmp l m h e x
lmuse1 : movw % b x , % a x
jmp l m u s e
mnusel : lodsb # M e n u s e l e c t i o n
xorb % a h , % a h
subb $ 0 x30 , % a l
jc l m b a d
cmpb $ 1 0 , % a l
jc l m u s e
cmpb $ 0 x61 - 0 x30 , % a l
jc l m b a d
subb $ 0 x61 - 0 x30 - 1 0 , % a l
cmpb $ 3 6 , % a l
jnc l m b a d
lmuse : call m o d e _ s e t
jc l m d e f
lmbad : leaw u n k n t , % s i
call p r t s t r
jmp l m 2
lmscan : cmpb $ 0 , a d a p t e r # S c a n n i n g o n l y o n E G A / V G A
jz l m b a d
movw $ 0 , m t _ e n d # S c a n n i n g o f m o d e s i s
movb $ 1 , s c a n n i n g # d o n e a s n e w a u t o d e t e c t i o n .
call m o d e _ t a b l e
jmp l i s t m 0
lmdef : ret
# Additional p a r t s o f m o d e _ s e t . . . ( r e l a t i v e j u m p s , y o u k n o w )
setv7 : # Video7 e x t e n d e d m o d e s
DO_ S T O R E
subb $ V I D E O _ F I R S T _ V 7 > > 8 , % b h
movw $ 0 x6 f05 , % a x
int $ 0 x10
stc
ret
_setrec : jmp s e t r e c # U g l y . . .
_set_80x25 : jmp s e t _ 8 0 x25
# Aliases f o r b a c k w a r d c o m p a t i b i l i t y .
setalias :
movw $ V I D E O _ 8 0 x25 , % a x
incw % b x
jz m o d e _ s e t
movb $ V I D E O _ 8 P O I N T - V I D E O _ F I R S T _ S P E C I A L , % a l
incw % b x
jnz s e t b a d # F a l l - t h r o u g h !
# Setting o f u s e r m o d e ( A X =mode I D ) = > C F =success
mode_set :
movw % a x , % f s : ( 0 x01 f a ) # S t o r e m o d e f o r u s e i n a c p i _ w a k e u p . S
movw % a x , % b x
cmpb $ 0 x f f , % a h
jz s e t a l i a s
testb $ V I D E O _ R E C A L C > > 8 , % a h
jnz _ s e t r e c
cmpb $ V I D E O _ F I R S T _ R E S O L U T I O N > > 8 , % a h
jnc s e t r e s
cmpb $ V I D E O _ F I R S T _ S P E C I A L > > 8 , % a h
jz s e t s p c
cmpb $ V I D E O _ F I R S T _ V 7 > > 8 , % a h
jz s e t v7
cmpb $ V I D E O _ F I R S T _ V E S A > > 8 , % a h
jnc c h e c k _ v e s a
orb % a h , % a h
jz s e t m e n u
decb % a h
jz s e t b i o s
setbad : clc
movb $ 0 , d o _ r e s t o r e # T h e s c r e e n n e e d n ' t b e r e s t o r e d
ret
setvesa :
DO_ S T O R E
subb $ V I D E O _ F I R S T _ V E S A > > 8 , % b h
movw $ 0 x4 f02 , % a x # V E S A B I O S m o d e s e t c a l l
int $ 0 x10
cmpw $ 0 x00 4 f , % a x # A L = 4 f i f i m p l e m e n t e d
jnz s e t b a d # A H = 0 i f O K
stc
ret
setbios :
DO_ S T O R E
int $ 0 x10 # S t a n d a r d B I O S m o d e s e t c a l l
pushw % b x
movb $ 0 x0 f , % a h # C h e c k i f r e a l l y s e t
int $ 0 x10
popw % b x
cmpb % b l , % a l
jnz s e t b a d
stc
ret
setspc : xorb % b h , % b h # S e t s p e c i a l m o d e
cmpb $ V I D E O _ L A S T _ S P E C I A L - V I D E O _ F I R S T _ S P E C I A L , % b l
jnc s e t b a d
addw % b x , % b x
jmp * s p e c _ i n i t s ( % b x )
setmenu :
orb % a l , % a l # 80 x25 i s a n e x c e p t i o n
jz _ s e t _ 8 0 x25
pushw % b x # S e t m o d e c h o s e n f r o m m e n u
call m o d e _ t a b l e # B u i l d t h e m o d e t a b l e
popw % a x
shlw $ 2 , % a x
addw % a x , % s i
cmpw % d i , % s i
jnc s e t b a d
movw ( % s i ) , % a x # F e t c h m o d e I D
_m_s : jmp m o d e _ s e t
setres : pushw % b x # S e t m o d e c h o s e n b y r e s o l u t i o n
call m o d e _ t a b l e
popw % b x
xchgb % b l , % b h
setr1 : lodsw
cmpw $ A S K _ V G A , % a x # E n d o f t h e l i s t ?
jz s e t b a d
lodsw
cmpw % b x , % a x
jnz s e t r1
movw - 4 ( % s i ) , % a x # F e t c h m o d e I D
jmp _ m _ s
check_vesa :
leaw m o d e l i s t + 1 0 2 4 , % d i
subb $ V I D E O _ F I R S T _ V E S A > > 8 , % b h
movw % b x , % c x # G e t m o d e i n f o r m a t i o n s t r u c t u r e
movw $ 0 x4 f01 , % a x
int $ 0 x10
addb $ V I D E O _ F I R S T _ V E S A > > 8 , % b h
cmpw $ 0 x00 4 f , % a x
jnz s e t b a d
movb ( % d i ) , % a l # C h e c k c a p a b i l i t i e s .
andb $ 0 x19 , % a l
cmpb $ 0 x09 , % a l
jz s e t v e s a # T h i s i s a t e x t m o d e
movb ( % d i ) , % a l # C h e c k c a p a b i l i t i e s .
andb $ 0 x99 , % a l
cmpb $ 0 x99 , % a l
jnz _ s e t b a d # D o h ! N o l i n e a r f r a m e b u f f e r .
subb $ V I D E O _ F I R S T _ V E S A > > 8 , % b h
orw $ 0 x40 0 0 , % b x # U s e l i n e a r f r a m e b u f f e r
movw $ 0 x4 f02 , % a x # V E S A B I O S m o d e s e t c a l l
int $ 0 x10
cmpw $ 0 x00 4 f , % a x # A L = 4 f i f i m p l e m e n t e d
jnz _ s e t b a d # A H = 0 i f O K
movb $ 1 , g r a p h i c _ m o d e # f l a g g r a p h i c m o d e
movb $ 0 , d o _ r e s t o r e # n o s c r e e n r e s t o r e
stc
ret
_setbad : jmp s e t b a d # U g l y . . .
# Recalculate v e r t i c a l d i s p l a y e n d r e g i s t e r s - - t h i s f i x e s v a r i o u s
# inconsistencies o f e x t e n d e d m o d e s o n m a n y a d a p t e r s . C a l l e d w h e n
# the V I D E O _ R E C A L C f l a g i s s e t i n t h e m o d e I D .
setrec : subb $ V I D E O _ R E C A L C > > 8 , % a h # S e t t h e b a s e m o d e
call m o d e _ s e t
jnc r c t 3
movw % g s : ( 0 x48 5 ) , % a x # F o n t s i z e i n p i x e l s
movb % g s : ( 0 x48 4 ) , % b l # N u m b e r o f r o w s
incb % b l
mulb % b l # N u m b e r o f v i s i b l e
decw % a x # s c a n l i n e s - 1
movw $ 0 x3 d4 , % d x
movw % a x , % b x
movb $ 0 x12 , % a l # L o w e r 8 b i t s
movb % b l , % a h
outw % a x , % d x
movb $ 0 x07 , % a l # B i t s 8 a n d 9 i n t h e o v e r f l o w r e g i s t e r
call i n i d x
xchgb % a l , % a h
andb $ 0 x b d , % a h
shrb % b h
jnc r c t 1
orb $ 0 x02 , % a h
rct1 : shrb % b h
jnc r c t 2
orb $ 0 x40 , % a h
rct2 : movb $ 0 x07 , % a l
outw % a x , % d x
stc
rct3 : ret
# Table o f r o u t i n e s f o r s e t t i n g o f t h e s p e c i a l m o d e s .
spec_inits :
.word set_80x25
.word set_8pixel
.word set_80x43
.word set_80x28
.word set_current
.word set_80x30
.word set_80x34
.word set_80x60
.word set_gfx
# Set t h e 8 0 x25 m o d e . I f a l r e a d y s e t , d o n o t h i n g .
set_80x25 :
movw $ 0 x50 1 9 , f o r c e _ s i z e # O v e r r i d e p o s s i b l y b r o k e n B I O S
use_80x25 :
# ifdef C O N F I G _ V I D E O _ 4 0 0 _ H A C K
movw $ 0 x12 0 2 , % a x # F o r c e 400 s c a n l i n e s
movb $ 0 x30 , % b l
int $ 0 x10
# else
movb $ 0 x0 f , % a h # G e t c u r r e n t m o d e I D
int $ 0 x10
cmpw $ 0 x50 0 7 , % a x # M o d e 7 ( 8 0 x25 m o n o ) i s t h e o n l y o n e a v a i l a b l e
jz s t 8 0 # o n C G A / M D A / H G A a n d i s a l s o a v a i l a b l e o n E G A M
cmpw $ 0 x50 0 3 , % a x # U n k n o w n m o d e , f o r c e 80 x25 c o l o r
jnz f o r c e 3
st80 : cmpb $ 0 , a d a p t e r # C G A / M D A / H G A = > m o d e 3 / 7 i s a l w a y s 8 0 x25
jz s e t 8 0
movb % g s : ( 0 x04 8 4 ) , % a l # T h i s i s E G A + - - b e w a r e o f 80 x50 e t c .
orb % a l , % a l # S o m e b u g g y B I O S ' e s s e t 0 r o w s
jz s e t 8 0
cmpb $ 2 4 , % a l # I t ' s h o p e f u l l y c o r r e c t
jz s e t 8 0
# endif / * C O N F I G _ V I D E O _ 4 0 0 _ H A C K * /
force3 : DO_ S T O R E
movw $ 0 x00 0 3 , % a x # F o r c e d s e t
int $ 0 x10
set80 : stc
ret
# Set t h e 8 0 x50 / 8 0 x43 8 - p i x e l m o d e . S i m p l e B I O S c a l l s .
set_8pixel :
DO_ S T O R E
call u s e _ 8 0 x25 # T h e b a s e i s 80 x25
set_8pt :
movw $ 0 x11 1 2 , % a x # U s e 8 x8 f o n t
xorb % b l , % b l
int $ 0 x10
movw $ 0 x12 0 0 , % a x # U s e a l t e r n a t e p r i n t s c r e e n
movb $ 0 x20 , % b l
int $ 0 x10
movw $ 0 x12 0 1 , % a x # T u r n o f f c u r s o r e m u l a t i o n
movb $ 0 x34 , % b l
int $ 0 x10
movb $ 0 x01 , % a h # D e f i n e c u r s o r s c a n l i n e s 6 - 7
movw $ 0 x06 0 7 , % c x
int $ 0 x10
set_current :
stc
ret
# Set t h e 8 0 x28 m o d e . T h i s m o d e w o r k s o n a l l V G A ' s , b e c a u s e i t ' s a s t a n d a r d
# 8 0 x2 5 m o d e w i t h 1 4 - p o i n t f o n t s i n s t e a d o f 1 6 - p o i n t .
set_80x28 :
DO_ S T O R E
call u s e _ 8 0 x25 # T h e b a s e i s 80 x25
set14 : movw $ 0 x11 1 1 , % a x # U s e 9 x14 f o n t
xorb % b l , % b l
int $ 0 x10
movb $ 0 x01 , % a h # D e f i n e c u r s o r s c a n l i n e s 11 - 1 2
movw $ 0 x0 b0 c , % c x
int $ 0 x10
stc
ret
# Set t h e 8 0 x43 m o d e . T h i s m o d e i s w o r k s o n a l l V G A ' s .
# It' s a 3 5 0 - s c a n l i n e m o d e w i t h 8 - p i x e l f o n t .
set_80x43 :
DO_ S T O R E
movw $ 0 x12 0 1 , % a x # S e t 350 s c a n s
movb $ 0 x30 , % b l
int $ 0 x10
movw $ 0 x00 0 3 , % a x # R e s e t v i d e o m o d e
int $ 0 x10
jmp s e t _ 8 p t # U s e 8 - p i x e l f o n t
# Set t h e 8 0 x30 m o d e ( a l l V G A ' s ) . 4 8 0 s c a n l i n e s , 1 6 - p i x e l f o n t .
set_80x30 :
call u s e _ 8 0 x25 # S t a r t w i t h r e a l 80 x25
DO_ S T O R E
movw $ 0 x3 c c , % d x # G e t C R T C p o r t
inb % d x , % a l
movb $ 0 x d4 , % d l
rorb % a l # M o n o o r c o l o r ?
jc s e t 4 8 a
movb $ 0 x b4 , % d l
set48a : movw $ 0 x0 c11 , % a x # V e r t i c a l s y n c e n d ( a l s o u n l o c k s C R 0 - 7 )
call o u t i d x
movw $ 0 x0 b06 , % a x # V e r t i c a l t o t a l
call o u t i d x
movw $ 0 x3 e 0 7 , % a x # ( V e r t i c a l ) o v e r f l o w
call o u t i d x
movw $ 0 x e a10 , % a x # V e r t i c a l s y n c s t a r t
call o u t i d x
movw $ 0 x d f12 , % a x # V e r t i c a l d i s p l a y e n d
call o u t i d x
movw $ 0 x e 7 1 5 , % a x # V e r t i c a l b l a n k s t a r t
call o u t i d x
movw $ 0 x04 1 6 , % a x # V e r t i c a l b l a n k e n d
call o u t i d x
pushw % d x
movb $ 0 x c c , % d l # M i s c o u t p u t r e g i s t e r ( r e a d )
inb % d x , % a l
movb $ 0 x c2 , % d l # ( w r i t e )
andb $ 0 x0 d , % a l # P r e s e r v e c l o c k s e l e c t b i t s a n d c o l o r b i t
orb $ 0 x e 2 , % a l # S e t c o r r e c t s y n c p o l a r i t y
outb % a l , % d x
popw % d x
movw $ 0 x50 1 e , f o r c e _ s i z e
stc # T h a t ' s a l l .
ret
# Set t h e 8 0 x34 m o d e ( a l l V G A ' s ) . 4 8 0 s c a n s , 1 4 - p i x e l f o n t .
set_80x34 :
call s e t _ 8 0 x30 # S e t 480 s c a n s
call s e t 1 4 # A n d 14 - p t f o n t
movw $ 0 x d b12 , % a x # V G A v e r t i c a l d i s p l a y e n d
movw $ 0 x50 2 2 , f o r c e _ s i z e
setvde : call o u t i d x
stc
ret
# Set t h e 8 0 x60 m o d e ( a l l V G A ' s ) . 4 8 0 s c a n s , 8 - p i x e l f o n t .
set_80x60 :
call s e t _ 8 0 x30 # S e t 480 s c a n s
call s e t _ 8 p t # A n d 8 - p t f o n t
movw $ 0 x d f12 , % a x # V G A v e r t i c a l d i s p l a y e n d
movw $ 0 x50 3 c , f o r c e _ s i z e
jmp s e t v d e
# Special h a c k f o r T h i n k P a d g r a p h i c s
set_gfx :
# ifdef C O N F I G _ V I D E O _ G F X _ H A C K
movw $ V I D E O _ G F X _ B I O S _ A X , % a x
movw $ V I D E O _ G F X _ B I O S _ B X , % b x
int $ 0 x10
movw $ V I D E O _ G F X _ D U M M Y _ R E S O L U T I O N , f o r c e _ s i z e
stc
# endif
ret
# ifdef C O N F I G _ V I D E O _ R E T A I N
# Store s c r e e n c o n t e n t s t o t e m p o r a r y b u f f e r .
store_screen :
cmpb $ 0 , d o _ r e s t o r e # A l r e a d y s t o r e d ?
jnz s t s r
testb $ C A N _ U S E _ H E A P , l o a d f l a g s # H a v e w e s p a c e f o r s t o r i n g ?
jz s t s r
pushw % a x
pushw % b x
pushw f o r c e _ s i z e # D o n ' t f o r c e s p e c i f i c s i z e
movw $ 0 , f o r c e _ s i z e
call m o d e _ p a r a m s # O b t a i n p a r a m s o f c u r r e n t m o d e
popw f o r c e _ s i z e
movb % f s : ( P A R A M _ V I D E O _ L I N E S ) , % a h
movb % f s : ( P A R A M _ V I D E O _ C O L S ) , % a l
movw % a x , % b x # B X = d i m e n s i o n s
mulb % a h
movw % a x , % c x # C X = n u m b e r o f c h a r a c t e r s
addw % a x , % a x # C a l c u l a t e i m a g e s i z e
addw $ m o d e l i s t + 1 0 2 4 + 4 , % a x
cmpw h e a p _ e n d _ p t r , % a x
jnc s t s1 # U n f o r t u n a t e l y , o u t o f m e m o r y
movw % f s : ( P A R A M _ C U R S O R _ P O S ) , % a x # S t o r e m o d e p a r a m s
leaw m o d e l i s t + 1 0 2 4 , % d i
stosw
movw % b x , % a x
stosw
pushw % d s # S t o r e t h e s c r e e n
movw v i d e o _ s e g m e n t , % d s
xorw % s i , % s i
rep
movsw
popw % d s
incb d o _ r e s t o r e # S c r e e n w i l l b e r e s t o r e d l a t e r
sts1 : popw % b x
popw % a x
stsr : ret
# Restore s c r e e n c o n t e n t s f r o m t e m p o r a r y b u f f e r .
restore_screen :
cmpb $ 0 , d o _ r e s t o r e # H a s t h e s c r e e n b e e n s t o r e d ?
jz r e s1
call m o d e _ p a r a m s # G e t p a r a m e t e r s o f c u r r e n t m o d e
movb % f s : ( P A R A M _ V I D E O _ L I N E S ) , % c l
movb % f s : ( P A R A M _ V I D E O _ C O L S ) , % c h
leaw m o d e l i s t + 1 0 2 4 , % s i # S c r e e n b u f f e r
lodsw # S e t c u r s o r p o s i t i o n
movw % a x , % d x
cmpb % c l , % d h
jc r e s2
movb % c l , % d h
decb % d h
res2 : cmpb % c h , % d l
jc r e s3
movb % c h , % d l
decb % d l
res3 : movb $ 0 x02 , % a h
movb $ 0 x00 , % b h
int $ 0 x10
lodsw # D i s p l a y s i z e
movb % a h , % d l # D L = n u m b e r o f l i n e s
movb $ 0 , % a h # B X = p h y s . l e n g t h o f o r i g . l i n e
movw % a x , % b x
cmpb % c l , % d l # T o o m a n y ?
jc r e s4
pushw % a x
movb % d l , % a l
subb % c l , % a l
mulb % b l
addw % a x , % s i
addw % a x , % s i
popw % a x
movb % c l , % d l
res4 : cmpb % c h , % a l # T o o w i d e ?
jc r e s5
movb % c h , % a l # A X = w i d t h o f s r c . l i n e
res5 : movb $ 0 , % c l
xchgb % c h , % c l
movw % c x , % b p # B P = w i d t h o f d e s t . l i n e
pushw % e s
movw v i d e o _ s e g m e n t , % e s
xorw % d i , % d i # M o v e t h e d a t a
addw % b x , % b x # C o n v e r t B X a n d B P t o _ b y t e s _
addw % b p , % b p
res6 : pushw % s i
pushw % d i
movw % a x , % c x
rep
movsw
popw % d i
popw % s i
addw % b p , % d i
addw % b x , % s i
decb % d l
jnz r e s6
popw % e s # D o n e
res1 : ret
# endif / * C O N F I G _ V I D E O _ R E T A I N * /
# Write t o i n d e x e d V G A r e g i s t e r ( A L =index , A H =data , D X =index r e g . p o r t )
outidx : outb % a l , % d x
pushw % a x
movb % a h , % a l
incw % d x
outb % a l , % d x
decw % d x
popw % a x
ret
# Build t h e t a b l e o f v i d e o m o d e s ( s t o r e d a f t e r t h e s e t u p . S c o d e a t t h e
# ` modelist' l a b e l . E a c h v i d e o m o d e r e c o r d l o o k s l i k e :
# .word MODE- I D ( o u r s p e c i a l m o d e I D ( s e e a b o v e ) )
# .byte rows ( number o f r o w s )
# .byte columns ( number o f c o l u m n s )
# Returns a d d r e s s o f t h e e n d o f t h e t a b l e i n D I , t h e e n d i s m a r k e d
# with a A S K _ V G A I D .
mode_table :
movw m t _ e n d , % d i # A l r e a d y f i l l e d ?
orw % d i , % d i
jnz m t a b1 x
leaw m o d e l i s t , % d i # S t o r e s t a n d a r d m o d e s :
movl $ V I D E O _ 8 0 x25 + 0 x50 1 9 0 0 0 0 , % e a x # T h e 80 x25 m o d e ( A L L )
stosl
movb a d a p t e r , % a l # C G A / M D A / H G A - - n o m o r e m o d e s
orb % a l , % a l
jz m t a b e
decb % a l
jnz m t a b v
movl $ V I D E O _ 8 P O I N T + 0 x50 2 b00 0 0 , % e a x # T h e 80 x43 E G A m o d e
stosl
jmp m t a b e
mtab1x : jmp m t a b1
mtabv : leaw v g a _ m o d e s , % s i # A l l m o d e s f o r s t d V G A
movw $ v g a _ m o d e s _ e n d - v g a _ m o d e s , % c x
rep # I ' m u n a b l e t o u s e m o v s w a s I d o n ' t k n o w h o w t o s t o r e a h a l f
movsb # o f t h e e x p r e s s i o n a b o v e t o c x w i t h o u t u s i n g e x p l i c i t s h r .
cmpb $ 0 , s c a n n i n g # M o d e s c a n r e q u e s t e d ?
jz m s c a n 1
call m o d e _ s c a n
mscan1 :
# ifdef C O N F I G _ V I D E O _ L O C A L
call l o c a l _ m o d e s
# endif / * C O N F I G _ V I D E O _ L O C A L * /
# ifdef C O N F I G _ V I D E O _ V E S A
call v e s a _ m o d e s # D e t e c t V E S A V G A m o d e s
# endif / * C O N F I G _ V I D E O _ V E S A * /
# ifdef C O N F I G _ V I D E O _ S V G A
cmpb $ 0 , s c a n n i n g # B y p a s s w h e n s c a n n i n g
jnz m s c a n 2
call s v g a _ m o d e s # D e t e c t S V G A c a r d s & m o d e s
mscan2 :
# endif / * C O N F I G _ V I D E O _ S V G A * /
mtabe :
# ifdef C O N F I G _ V I D E O _ C O M P A C T
leaw m o d e l i s t , % s i
movw % d i , % d x
movw % s i , % d i
cmt1 : cmpw % d x , % s i # S c a n a l l m o d e s
jz c m t 2
leaw m o d e l i s t , % b x # F i n d i n p r e v i o u s e n t r i e s
movw 2 ( % s i ) , % c x
cmt3 : cmpw % b x , % s i
jz c m t 4
cmpw 2 ( % b x ) , % c x # F o u n d = > d o n ' t c o p y t h i s e n t r y
jz c m t 5
addw $ 4 , % b x
jmp c m t 3
cmt4 : movsl # C o p y e n t r y
jmp c m t 1
cmt5 : addw $ 4 , % s i # S k i p e n t r y
jmp c m t 1
cmt2 :
# endif / * C O N F I G _ V I D E O _ C O M P A C T * /
movw $ A S K _ V G A , ( % d i ) # E n d m a r k e r
movw % d i , m t _ e n d
mtab1 : leaw m o d e l i s t , % s i # S I = m o d e l i s t , D I = l i s t e n d
ret0 : ret
# Modes u s a b l e o n a l l s t a n d a r d V G A s
vga_modes :
.word VIDEO_8POINT
.word 0x5032 # 8 0 x5 0
.word VIDEO_80x43
.word 0x502b # 8 0 x4 3
.word VIDEO_80x28
.word 0x501c # 8 0 x2 8
.word VIDEO_80x30
.word 0x501e # 8 0 x3 0
.word VIDEO_80x34
.word 0x5022 # 8 0 x3 4
.word VIDEO_80x60
.word 0x503c # 8 0 x6 0
# ifdef C O N F I G _ V I D E O _ G F X _ H A C K
.word VIDEO_GFX_HACK
.word VIDEO_GFX_DUMMY_RESOLUTION
# endif
vga_modes_end :
# Detect V E S A m o d e s .
# ifdef C O N F I G _ V I D E O _ V E S A
vesa_modes :
cmpb $ 2 , a d a p t e r # V G A o n l y
jnz r e t 0
movw % d i , % b p # B P = o r i g i n a l m o d e t a b l e e n d
addw $ 0 x20 0 , % d i # B u f f e r s p a c e
movw $ 0 x4 f00 , % a x # V E S A G e t c a r d i n f o c a l l
int $ 0 x10
movw % b p , % d i
cmpw $ 0 x00 4 f , % a x # S u c c e s s f u l ?
jnz r e t 0
cmpw $ 0 x45 5 6 , 0 x20 0 ( % d i )
jnz r e t 0
cmpw $ 0 x41 5 3 , 0 x20 2 ( % d i )
jnz r e t 0
movw $ v e s a _ n a m e , c a r d _ n a m e # S e t n a m e t o " VESA VGA "
pushw % g s
lgsw 0 x20 e ( % d i ) , % s i # G S : S I = m o d e l i s t
movw $ 1 2 8 , % c x # I t e r a t i o n l i m i t
vesa1 :
# gas v e r s i o n 2 . 9 . 1 , u s i n g B F D v e r s i o n 2 . 9 . 1 . 0 . 2 3 b u g g e r s t h e n e x t i n s t .
# XXX : lodsw % g s : ( % s i ) , % a x # G e t n e x t m o d e i n t h e l i s t
gs; lodsw
cmpw $ 0 x f f f f , % a x # E n d o f t h e t a b l e ?
jz v e s a r
cmpw $ 0 x00 8 0 , % a x # C h e c k v a l i d i t y o f m o d e I D
jc v e s a2
orb % a h , % a h # V a l i d I D s : 0x0000 - 0 x00 7 f / 0 x01 0 0 - 0 x07 f f
jz v e s a n # C e r t a i n B I O S e s r e p o r t 0x80 - 0 x f f !
cmpw $ 0 x08 0 0 , % a x
jnc v e s a e
vesa2 : pushw % c x
movw % a x , % c x # G e t m o d e i n f o r m a t i o n s t r u c t u r e
movw $ 0 x4 f01 , % a x
int $ 0 x10
movw % c x , % b x # B X = m o d e n u m b e r
addb $ V I D E O _ F I R S T _ V E S A > > 8 , % b h
popw % c x
cmpw $ 0 x00 4 f , % a x
jnz v e s a n # D o n ' t r e p o r t e r r o r s ( b u g g y B I O S E S )
movb ( % d i ) , % a l # C h e c k c a p a b i l i t i e s . W e r e q u i r e
andb $ 0 x19 , % a l # a c o l o r t e x t m o d e .
cmpb $ 0 x09 , % a l
jnz v e s a n
cmpw $ 0 x b80 0 , 8 ( % d i ) # S t a n d a r d v i d e o m e m o r y a d d r e s s r e q u i r e d
jnz v e s a n
testb $ 2 , ( % d i ) # M o d e c h a r a c t e r i s t i c s s u p p l i e d ?
movw % b x , ( % d i ) # S t o r e m o d e n u m b e r
jz v e s a3
xorw % d x , % d x
movw 0 x12 ( % d i ) , % b x # W i d t h
orb % b h , % b h
jnz v e s a n
movb % b l , 0 x3 ( % d i )
movw 0 x14 ( % d i ) , % a x # H e i g h t
orb % a h , % a h
jnz v e s a n
movb % a l , 2 ( % d i )
mulb % b l
cmpw $ 8 1 9 3 , % a x # S m a l l e n o u g h f o r L i n u x c o n s o l e d r i v e r ?
jnc v e s a n
jmp v e s a o k
vesa3 : subw $ 0 x81 0 8 , % b x # T h i s m o d e h a s n o d e t a i l e d i n f o s p e c i f i e d ,
jc v e s a n # s o i t m u s t b e a s t a n d a r d V E S A m o d e .
cmpw $ 5 , % b x
jnc v e s a n
movw v e s a _ t e x t _ m o d e _ t a b l e ( % b x ) , % a x
movw % a x , 2 ( % d i )
vesaok : addw $ 4 , % d i # T h e m o d e i s v a l i d . S t o r e i t .
vesan : loop v e s a1 # N e x t m o d e . L i m i t e x c e e d e d = > e r r o r
vesae : leaw v e s a e r , % s i
call p r t s t r
movw % b p , % d i # D i s c a r d a l r e a d y f o u n d m o d e s .
vesar : popw % g s
ret
# Dimensions o f s t a n d a r d V E S A t e x t m o d e s
vesa_text_mode_table :
.byte 6 0 , 8 0 # 0 1 0 8
.byte 2 5 , 1 3 2 # 0 1 0 9
.byte 4 3 , 1 3 2 # 0 1 0 A
.byte 5 0 , 1 3 2 # 0 1 0 B
.byte 6 0 , 1 3 2 # 0 1 0 C
# endif / * C O N F I G _ V I D E O _ V E S A * /
# Scan f o r v i d e o m o d e s . A b i t d i r t y , b u t s h o u l d w o r k .
mode_scan :
movw $ 0 x01 0 0 , % c x # S t a r t w i t h m o d e 0
scm1 : movb $ 0 , % a h # T e s t t h e m o d e
movb % c l , % a l
int $ 0 x10
movb $ 0 x0 f , % a h
int $ 0 x10
cmpb % c l , % a l
jnz s c m 2 # M o d e n o t s e t
movw $ 0 x3 c0 , % d x # T e s t i f i t ' s a t e x t m o d e
movb $ 0 x10 , % a l # M o d e b i t s
call i n i d x
andb $ 0 x03 , % a l
jnz s c m 2
movb $ 0 x c e , % d l # A n o t h e r s e t o f m o d e b i t s
movb $ 0 x06 , % a l
call i n i d x
shrb % a l
jc s c m 2
movb $ 0 x d4 , % d l # C u r s o r l o c a t i o n
movb $ 0 x0 f , % a l
call i n i d x
orb % a l , % a l
jnz s c m 2
movw % c x , % a x # O k , s t o r e t h e m o d e
stosw
movb % g s : ( 0 x48 4 ) , % a l # N u m b e r o f r o w s
incb % a l
stosb
movw % g s : ( 0 x44 a ) , % a x # N u m b e r o f c o l u m n s
stosb
scm2 : incb % c l
jns s c m 1
movw $ 0 x00 0 3 , % a x # R e t u r n b a c k t o m o d e 3
int $ 0 x10
ret
tstidx : outw % a x , % d x # O U T D X , A X a n d i n i d x
inidx : outb % a l , % d x # R e a d f r o m i n d e x e d V G A r e g i s t e r
incw % d x # A L = i n d e x , D X = i n d e x r e g p o r t - > A L = d a t a
inb % d x , % a l
decw % d x
ret
# Try t o d e t e c t t y p e o f S V G A c a r d a n d s u p p l y ( u s u a l l y a p p r o x i m a t e ) v i d e o
# mode t a b l e f o r i t .
# ifdef C O N F I G _ V I D E O _ S V G A
svga_modes :
leaw s v g a _ t a b l e , % s i # T e s t a l l k n o w n S V G A a d a p t e r s
dosvga : lodsw
movw % a x , % b p # D e f a u l t m o d e t a b l e
orw % a x , % a x
jz d i d s v1
lodsw # P o i n t e r t o t e s t r o u t i n e
pushw % s i
pushw % d i
pushw % e s
movw $ 0 x c00 0 , % b x
movw % b x , % e s
call * % a x # C a l l t e s t r o u t i n e
popw % e s
popw % d i
popw % s i
orw % b p , % b p
jz d o s v g a
movw % b p , % s i # F o u n d , c o p y t h e m o d e s
movb s v g a _ p r e f i x , % a h
cpsvga : lodsb
orb % a l , % a l
jz d i d s v
stosw
movsw
jmp c p s v g a
didsv : movw % s i , c a r d _ n a m e # S t o r e p o i n t e r t o c a r d n a m e
didsv1 : ret
# Table o f a l l k n o w n S V G A c a r d s . F o r e a c h c a r d , w e s t o r e a p o i n t e r t o
# a t a b l e o f v i d e o m o d e s s u p p o r t e d b y t h e c a r d a n d a p o i n t e r t o a r o u t i n e
# used f o r t e s t i n g o f p r e s e n c e o f t h e c a r d . T h e v i d e o m o d e t a b l e i s a l w a y s
# followed b y t h e n a m e o f t h e c a r d o r t h e c h i p s e t .
svga_table :
.word ati_ m d , a t i _ t e s t
.word oak_ m d , o a k _ t e s t
.word paradise_ m d , p a r a d i s e _ t e s t
.word realtek_ m d , r e a l t e k _ t e s t
.word s3 _ m d , s3 _ t e s t
.word chips_ m d , c h i p s _ t e s t
.word video7 _ m d , v i d e o 7 _ t e s t
.word cirrus5 _ m d , c i r r u s5 _ t e s t
.word cirrus6 _ m d , c i r r u s6 _ t e s t
.word cirrus1 _ m d , c i r r u s1 _ t e s t
.word ahead_ m d , a h e a d _ t e s t
.word everex_ m d , e v e r e x _ t e s t
.word genoa_ m d , g e n o a _ t e s t
.word trident_ m d , t r i d e n t _ t e s t
.word tseng_ m d , t s e n g _ t e s t
.word 0
# Test r o u t i n e s a n d m o d e t a b l e s :
# S3 - T h e t e s t a l g o r i t h m w a s t a k e n f r o m t h e S u p e r P r o b e p a c k a g e
# for X F r e e 8 6 1 . 2 . 1 . R e p o r t b u g s t o C h r i s t o p h . N i e m a n n @linux.org
s3_test :
movw $ 0 x0 f35 , % c x # w e s t o r e s o m e c o n s t a n t s i n c l / c h
movw $ 0 x03 d4 , % d x
movb $ 0 x38 , % a l
call i n i d x
movb % a l , % b h # s t o r e c u r r e n t C R T - r e g i s t e r 0x38
movw $ 0 x00 3 8 , % a x
call o u t i d x # d i s a b l e w r i t i n g t o s p e c i a l r e g s
movb % c l , % a l # c h e c k w h e t h e r w e c a n w r i t e s p e c i a l r e g 0x35
call i n i d x
movb % a l , % b l # s a v e t h e c u r r e n t v a l u e o f C R T r e g 0x35
andb $ 0 x f0 , % a l # c l e a r b i t s 0 - 3
movb % a l , % a h
movb % c l , % a l # a n d w r i t e i t t o C R T r e g 0x35
call o u t i d x
call i n i d x # n o w r e a d i t b a c k
andb % c h , % a l # c l e a r t h e u p p e r 4 b i t s
jz s3 _ 2 # t h e f i r s t t e s t f a i l e d . B u t w e h a v e a
movb % b l , % a h # s e c o n d c h a n c e
movb % c l , % a l
call o u t i d x
jmp s3 _ 1 # d o t h e o t h e r t e s t s
s3_2 : movw % c x , % a x # l o a d a h w i t h 0xf a n d a l w i t h 0 x35
orb % b l , % a h # s e t t h e u p p e r 4 b i t s o f a h w i t h t h e o r i g v a l u e
call o u t i d x # w r i t e . . .
call i n i d x # . . . a n d r e r e a d
andb % c l , % a l # t u r n o f f t h e u p p e r 4 b i t s
pushw % a x
movb % b l , % a h # r e s t o r e o l d v a l u e i n r e g i s t e r 0x35
movb % c l , % a l
call o u t i d x
popw % a x
cmpb % c h , % a l # s e t t i n g l o w e r 4 b i t s w a s s u c c e s s f u l = > b a d
je n o _ s3 # w r i t i n g i s a l l o w e d = > t h i s i s n o t a n S 3
s3_1 : movw $ 0 x48 3 8 , % a x # a l l o w w r i t i n g t o s p e c i a l r e g s b y p u t t i n g
call o u t i d x # m a g i c n u m b e r i n t o C R T - r e g i s t e r 0x38
movb % c l , % a l # c h e c k w h e t h e r w e c a n w r i t e s p e c i a l r e g 0x35
call i n i d x
movb % a l , % b l
andb $ 0 x f0 , % a l
movb % a l , % a h
movb % c l , % a l
call o u t i d x
call i n i d x
andb % c h , % a l
jnz n o _ s3 # n o , w e c a n ' t w r i t e = > n o S 3
movw % c x , % a x
orb % b l , % a h
call o u t i d x
call i n i d x
andb % c h , % a l
pushw % a x
movb % b l , % a h # r e s t o r e o l d v a l u e i n r e g i s t e r 0x35
movb % c l , % a l
call o u t i d x
popw % a x
cmpb % c h , % a l
jne n o _ s31 # w r i t i n g n o t p o s s i b l e = > n o S 3
movb $ 0 x30 , % a l
call i n i d x # n o w g e t t h e S 3 i d . . .
leaw i d S 3 , % d i
movw $ 0 x10 , % c x
repne
scasb
je n o _ s31
movb % b h , % a h
movb $ 0 x38 , % a l
jmp s3 r e s t
no_s3 : movb $ 0 x35 , % a l # r e s t o r e C R T r e g i s t e r 0x35
movb % b l , % a h
call o u t i d x
no_s31 : xorw % b p , % b p # D e t e c t i o n f a i l e d
s3rest : movb % b h , % a h
movb $ 0 x38 , % a l # r e s t o r e o l d v a l u e o f C R T r e g i s t e r 0x38
jmp o u t i d x
idS3 : .byte 0x81 , 0 x8 2 , 0 x90 , 0 x91 , 0 x92 , 0 x93 , 0 x94 , 0 x95
.byte 0 xa0 , 0 x a1 , 0 x a2 , 0 x a3 , 0 x a4 , 0 x a5 , 0 x a8 , 0 x b0
s3_md : .byte 0x54 , 0 x2 b , 0 x84
.byte 0 x5 5 , 0 x19 , 0 x84
.byte 0
.ascii " S3 "
.byte 0
# ATI c a r d s .
ati_test :
leaw i d a t i , % s i
movw $ 0 x31 , % d i
movw $ 0 x09 , % c x
repe
cmpsb
je a t i o k
xorw % b p , % b p
atiok : ret
idati : .ascii " 761295520 "
ati_md : .byte 0x23 , 0 x1 9 , 0 x84
.byte 0 x3 3 , 0 x2 c , 0 x84
.byte 0 x2 2 , 0 x1 e , 0 x64
.byte 0 x2 1 , 0 x19 , 0 x64
.byte 0 x5 8 , 0 x21 , 0 x50
.byte 0 x5 b , 0 x1 e , 0 x50
.byte 0
.ascii " ATI"
.byte 0
# AHEAD
ahead_test :
movw $ 0 x20 0 f , % a x
movw $ 0 x3 c e , % d x
outw % a x , % d x
incw % d x
inb % d x , % a l
cmpb $ 0 x20 , % a l
je i s a h e d
cmpb $ 0 x21 , % a l
je i s a h e d
xorw % b p , % b p
isahed : ret
ahead_md :
.byte 0 x2 2 , 0 x2 c , 0 x84
.byte 0 x2 3 , 0 x19 , 0 x84
.byte 0 x2 4 , 0 x1 c , 0 x84
.byte 0 x2 f , 0 x32 , 0 x a0
.byte 0 x3 2 , 0 x22 , 0 x50
.byte 0 x3 4 , 0 x42 , 0 x50
.byte 0
.ascii " Ahead"
.byte 0
# Chips & T e c h .
chips_test :
movw $ 0 x3 c3 , % d x
inb % d x , % a l
orb $ 0 x10 , % a l
outb % a l , % d x
movw $ 0 x10 4 , % d x
inb % d x , % a l
movb % a l , % b l
movw $ 0 x3 c3 , % d x
inb % d x , % a l
andb $ 0 x e f , % a l
outb % a l , % d x
cmpb $ 0 x a5 , % b l
je c a n t o k
xorw % b p , % b p
cantok : ret
chips_md :
.byte 0 x6 0 , 0 x19 , 0 x84
.byte 0 x6 1 , 0 x32 , 0 x84
.byte 0
.ascii " Chips & T e c h n o l o g i e s "
.byte 0
# Cirrus L o g i c 5 X 0
cirrus1_test :
movw $ 0 x3 d4 , % d x
movb $ 0 x0 c , % a l
outb % a l , % d x
incw % d x
inb % d x , % a l
movb % a l , % b l
xorb % a l , % a l
outb % a l , % d x
decw % d x
movb $ 0 x1 f , % a l
outb % a l , % d x
incw % d x
inb % d x , % a l
movb % a l , % b h
xorb % a h , % a h
shlb $ 4 , % a l
movw % a x , % c x
movb % b h , % a l
shrb $ 4 , % a l
addw % a x , % c x
shlw $ 8 , % c x
addw $ 6 , % c x
movw % c x , % a x
movw $ 0 x3 c4 , % d x
outw % a x , % d x
incw % d x
inb % d x , % a l
andb % a l , % a l
jnz n o c i r r
movb % b h , % a l
outb % a l , % d x
inb % d x , % a l
cmpb $ 0 x01 , % a l
je i s c i r r
nocirr : xorw % b p , % b p
iscirr : movw $ 0 x3 d4 , % d x
movb % b l , % a l
xorb % a h , % a h
shlw $ 8 , % a x
addw $ 0 x0 c , % a x
outw % a x , % d x
ret
cirrus1_md :
.byte 0 x1 f , 0 x19 , 0 x84
.byte 0 x2 0 , 0 x2 c , 0 x84
.byte 0 x2 2 , 0 x1 e , 0 x84
.byte 0 x3 1 , 0 x25 , 0 x64
.byte 0
.ascii " Cirrus L o g i c 5 X 0 "
.byte 0
# Cirrus L o g i c 5 4 X X
cirrus5_test :
movw $ 0 x3 c4 , % d x
movb $ 6 , % a l
call i n i d x
movb % a l , % b l # B L = b a c k u p
movw $ 6 , % a x
call t s t i d x
cmpb $ 0 x0 f , % a l
jne c5 f a i l
movw $ 0 x12 0 6 , % a x
call t s t i d x
cmpb $ 0 x12 , % a l
jne c5 f a i l
movb $ 0 x1 e , % a l
call i n i d x
movb % a l , % b h
movb % b h , % a h
andb $ 0 x c0 , % a h
movb $ 0 x1 e , % a l
call t s t i d x
andb $ 0 x3 f , % a l
jne c5 x x
movb $ 0 x1 e , % a l
movb % b h , % a h
orb $ 0 x3 f , % a h
call t s t i d x
xorb $ 0 x3 f , % a l
andb $ 0 x3 f , % a l
c5xx : pushf
movb $ 0 x1 e , % a l
movb % b h , % a h
outw % a x , % d x
popf
je c5 d o n e
c5fail : xorw % b p , % b p
c5done : movb $ 6 , % a l
movb % b l , % a h
outw % a x , % d x
ret
cirrus5_md :
.byte 0 x1 4 , 0 x19 , 0 x84
.byte 0 x5 4 , 0 x2 b , 0 x84
.byte 0
.ascii " Cirrus L o g i c 5 4 X X "
.byte 0
# Cirrus L o g i c 6 4 X X - - n o k n o w n e x t r a m o d e s , b u t m u s t b e i d e n t i f i e d , b e c a u s e
# it' s m i s i d e n t i f i e d b y t h e A h e a d t e s t .
cirrus6_test :
movw $ 0 x3 c e , % d x
movb $ 0 x0 a , % a l
call i n i d x
movb % a l , % b l # B L = b a c k u p
movw $ 0 x c e 0 a , % a x
call t s t i d x
orb % a l , % a l
jne c2 f a i l
movw $ 0 x e c0 a , % a x
call t s t i d x
cmpb $ 0 x01 , % a l
jne c2 f a i l
movb $ 0 x a a , % a l
call i n i d x # 4 X , 5 X , 7 X a n d 8 X a r e v a l i d 6 4 X X c h i p I D ' s .
shrb $ 4 , % a l
subb $ 4 , % a l
jz c6 d o n e
decb % a l
jz c6 d o n e
subb $ 2 , % a l
jz c6 d o n e
decb % a l
jz c6 d o n e
c2fail : xorw % b p , % b p
c6done : movb $ 0 x0 a , % a l
movb % b l , % a h
outw % a x , % d x
ret
cirrus6_md :
.byte 0
.ascii " Cirrus L o g i c 6 4 X X "
.byte 0
# Everex / T r i d e n t
everex_test :
movw $ 0 x70 0 0 , % a x
xorw % b x , % b x
int $ 0 x10
cmpb $ 0 x70 , % a l
jne n o e v r x
shrw $ 4 , % d x
cmpw $ 0 x67 8 , % d x
je e v t r i d
cmpw $ 0 x23 6 , % d x
jne e v r x o k
evtrid : leaw t r i d e n t _ m d , % b p
evrxok : ret
noevrx : xorw % b p , % b p
ret
everex_md :
.byte 0 x0 3 , 0 x22 , 0 x50
.byte 0 x0 4 , 0 x3 c , 0 x50
.byte 0 x0 7 , 0 x2 b , 0 x64
.byte 0 x0 8 , 0 x4 b , 0 x64
.byte 0 x0 a , 0 x19 , 0 x84
.byte 0 x0 b , 0 x2 c , 0 x84
.byte 0 x1 6 , 0 x1 e , 0 x50
.byte 0 x1 8 , 0 x1 b , 0 x64
.byte 0 x2 1 , 0 x40 , 0 x a0
.byte 0 x4 0 , 0 x1 e , 0 x84
.byte 0
.ascii " Everex/ T r i d e n t "
.byte 0
# Genoa.
genoa_test :
leaw i d g e n o a , % s i # C h e c k G e n o a ' c l u e s '
xorw % a x , % a x
movb % e s : ( 0 x37 ) , % a l
movw % a x , % d i
movw $ 0 x04 , % c x
decw % s i
decw % d i
l1 : incw % s i
incw % d i
movb ( % s i ) , % a l
testb % a l , % a l
jz l 2
cmpb % e s : ( % d i ) , % a l
l2 : loope l 1
orw % c x , % c x
je i s g e n
xorw % b p , % b p
isgen : ret
idgenoa : .byte 0x77 , 0 x0 0 , 0 x99 , 0 x66
genoa_md :
.byte 0 x5 8 , 0 x20 , 0 x50
.byte 0 x5 a , 0 x2 a , 0 x64
.byte 0 x6 0 , 0 x19 , 0 x84
.byte 0 x6 1 , 0 x1 d , 0 x84
.byte 0 x6 2 , 0 x20 , 0 x84
.byte 0 x6 3 , 0 x2 c , 0 x84
.byte 0 x6 4 , 0 x3 c , 0 x84
.byte 0 x6 b , 0 x4 f , 0 x64
.byte 0 x7 2 , 0 x3 c , 0 x50
.byte 0 x7 4 , 0 x42 , 0 x50
.byte 0 x7 8 , 0 x4 b , 0 x64
.byte 0
.ascii " Genoa"
.byte 0
# OAK
oak_test :
leaw i d o a k v g a , % s i
movw $ 0 x08 , % d i
movw $ 0 x08 , % c x
repe
cmpsb
je i s o a k
xorw % b p , % b p
isoak : ret
idoakvga : .ascii " OAK VGA "
oak_md : .byte 0x4e , 0 x3 c , 0 x50
.byte 0 x4 f , 0 x3 c , 0 x84
.byte 0 x5 0 , 0 x19 , 0 x84
.byte 0 x5 1 , 0 x2 b , 0 x84
.byte 0
.ascii " OAK"
.byte 0
# WD P a r a d i s e .
paradise_test :
leaw i d p a r a d i s e , % s i
movw $ 0 x7 d , % d i
movw $ 0 x04 , % c x
repe
cmpsb
je i s p a r a
xorw % b p , % b p
ispara : ret
idparadise : .ascii " VGA= "
paradise_md :
.byte 0 x4 1 , 0 x22 , 0 x50
.byte 0 x4 7 , 0 x1 c , 0 x84
.byte 0 x5 5 , 0 x19 , 0 x84
.byte 0 x5 4 , 0 x2 c , 0 x84
.byte 0
.ascii " Paradise"
.byte 0
# Trident.
trident_test :
movw $ 0 x3 c4 , % d x
movb $ 0 x0 e , % a l
outb % a l , % d x
incw % d x
inb % d x , % a l
xchgb % a l , % a h
xorb % a l , % a l
outb % a l , % d x
inb % d x , % a l
xchgb % a h , % a l
movb % a l , % b l # S t r a n g e t h i n g . . . i n t h e b o o k t h i s w a s n ' t
andb $ 0 x02 , % b l # n e c e s s a r y b u t i t w o r k e d o n m y c a r d w h i c h
jz s e t b2 # i s a t r i d e n t . W i t h o u t i t t h e s c r e e n g o e s
# blurred . . .
andb $ 0 x f d , % a l
jmp c l r b2
setb2 : orb $ 0 x02 , % a l
clrb2 : outb % a l , % d x
andb $ 0 x0 f , % a h
cmpb $ 0 x02 , % a h
je i s t r i d
xorw % b p , % b p
istrid : ret
trident_md :
.byte 0 x5 0 , 0 x1 e , 0 x50
.byte 0 x5 1 , 0 x2 b , 0 x50
.byte 0 x5 2 , 0 x3 c , 0 x50
.byte 0 x5 7 , 0 x19 , 0 x84
.byte 0 x5 8 , 0 x1 e , 0 x84
.byte 0 x5 9 , 0 x2 b , 0 x84
.byte 0 x5 a , 0 x3 c , 0 x84
.byte 0
.ascii " Trident"
.byte 0
# Tseng.
tseng_test :
movw $ 0 x3 c d , % d x
inb % d x , % a l # C o u l d t h i n g s b e t h i s s i m p l e ! : - )
movb % a l , % b l
movb $ 0 x55 , % a l
outb % a l , % d x
inb % d x , % a l
movb % a l , % a h
movb % b l , % a l
outb % a l , % d x
cmpb $ 0 x55 , % a h
je i s t s e n
isnot : xorw % b p , % b p
istsen : ret
tseng_md :
.byte 0 x2 6 , 0 x3 c , 0 x50
.byte 0 x2 a , 0 x28 , 0 x64
.byte 0 x2 3 , 0 x19 , 0 x84
.byte 0 x2 4 , 0 x1 c , 0 x84
.byte 0 x2 2 , 0 x2 c , 0 x84
.byte 0 x2 1 , 0 x3 c , 0 x84
.byte 0
.ascii " Tseng"
.byte 0
# Video7 .
video7_test :
movw $ 0 x3 c c , % d x
inb % d x , % a l
movw $ 0 x3 b4 , % d x
andb $ 0 x01 , % a l
jz e v e n 7
movw $ 0 x3 d4 , % d x
even7 : movb $ 0 x0 c , % a l
outb % a l , % d x
incw % d x
inb % d x , % a l
movb % a l , % b l
movb $ 0 x55 , % a l
outb % a l , % d x
inb % d x , % a l
decw % d x
movb $ 0 x1 f , % a l
outb % a l , % d x
incw % d x
inb % d x , % a l
movb % a l , % b h
decw % d x
movb $ 0 x0 c , % a l
outb % a l , % d x
incw % d x
movb % b l , % a l
outb % a l , % d x
movb $ 0 x55 , % a l
xorb $ 0 x e a , % a l
cmpb % b h , % a l
jne i s n o t
movb $ V I D E O _ F I R S T _ V 7 > > 8 , s v g a _ p r e f i x # U s e s p e c i a l m o d e s w i t c h i n g
ret
video7_md :
.byte 0 x4 0 , 0 x2 b , 0 x50
.byte 0 x4 3 , 0 x3 c , 0 x50
.byte 0 x4 4 , 0 x3 c , 0 x64
.byte 0 x4 1 , 0 x19 , 0 x84
.byte 0 x4 2 , 0 x2 c , 0 x84
.byte 0 x4 5 , 0 x1 c , 0 x84
.byte 0
.ascii " Video 7 "
.byte 0
# Realtek V G A
realtek_test :
leaw i d r t v g a , % s i
movw $ 0 x45 , % d i
movw $ 0 x0 b , % c x
repe
cmpsb
je i s r t
xorw % b p , % b p
isrt : ret
idrtvga : .ascii " REALTEK VGA "
realtek_md :
.byte 0 x1 a , 0 x3 c , 0 x50
.byte 0 x1 b , 0 x19 , 0 x84
.byte 0 x1 c , 0 x1 e , 0 x84
.byte 0 x1 d , 0 x2 b , 0 x84
.byte 0 x1 e , 0 x3 c , 0 x84
.byte 0
.ascii " REALTEK"
.byte 0
# endif / * C O N F I G _ V I D E O _ S V G A * /
# User- d e f i n e d l o c a l m o d e t a b l e ( V G A o n l y )
# ifdef C O N F I G _ V I D E O _ L O C A L
local_modes :
leaw l o c a l _ m o d e _ t a b l e , % s i
locm1 : lodsw
orw % a x , % a x
jz l o c m 2
stosw
movsw
jmp l o c m 1
locm2 : ret
# This i s t h e t a b l e o f l o c a l v i d e o m o d e s w h i c h c a n b e s u p p l i e d m a n u a l l y
# by t h e u s e r . E a c h e n t r y c o n s i s t s o f m o d e I D ( w o r d ) a n d d i m e n s i o n s
# ( byte f o r c o l u m n c o u n t a n d a n o t h e r b y t e f o r r o w c o u n t ) . T h e s e m o d e s
# are p l a c e d b e f o r e a l l S V G A a n d V E S A m o d e s a n d o v e r r i d e t h e m i f t a b l e
# compacting i s e n a b l e d . T h e t a b l e m u s t e n d w i t h a z e r o w o r d f o l l o w e d
# by N U L - t e r m i n a t e d v i d e o a d a p t e r n a m e .
local_mode_table :
.word 0x0100 # Example : 4 0 x2 5
.byte 2 5 , 4 0
.word 0
.ascii " Local"
.byte 0
# endif / * C O N F I G _ V I D E O _ L O C A L * /
# Read a k e y a n d r e t u r n t h e A S C I I c o d e i n a l , s c a n c o d e i n a h
getkey : xorb % a h , % a h
int $ 0 x16
ret
# Read a k e y w i t h a t i m e o u t o f 3 0 s e c o n d s .
# The h a r d w a r e c l o c k i s u s e d t o g e t t h e t i m e .
getkt : call g e t t i m e
addb $ 3 0 , % a l # W a i t 30 s e c o n d s
cmpb $ 6 0 , % a l
jl l m i n u t e
subb $ 6 0 , % a l
lminute :
movb % a l , % c l
again : movb $ 0 x01 , % a h
int $ 0 x16
jnz g e t k e y # k e y p r e s s e d , s o g e t i t
call g e t t i m e
cmpb % c l , % a l
jne a g a i n
movb $ 0 x20 , % a l # t i m e o u t , r e t u r n ` s p a c e '
ret
# Flush t h e k e y b o a r d b u f f e r
flush : movb $ 0 x01 , % a h
int $ 0 x16
jz e m p t y
xorb % a h , % a h
int $ 0 x16
jmp f l u s h
empty : ret
# Print h e x a d e c i m a l n u m b e r .
prthw : pushw % a x
movb % a h , % a l
call p r t h b
popw % a x
prthb : pushw % a x
shrb $ 4 , % a l
call p r t h n
popw % a x
andb $ 0 x0 f , % a l
prthn : cmpb $ 0 x0 a , % a l
jc p r t h1
addb $ 0 x07 , % a l
prth1 : addb $ 0 x30 , % a l
jmp p r t c h r
# Print d e c i m a l n u m b e r i n a l
prtdec : pushw % a x
pushw % c x
xorb % a h , % a h
movb $ 0 x0 a , % c l
idivb % c l
cmpb $ 0 x09 , % a l
jbe l t 1 0 0
call p r t d e c
jmp s k i p10
lt100 : addb $ 0 x30 , % a l
call p r t c h r
skip10 : movb % a h , % a l
addb $ 0 x30 , % a l
call p r t c h r
popw % c x
popw % a x
ret
store_edid :
2006-06-26 11:26:37 +04:00
# ifdef C O N F I G _ F I R M W A R E _ E D I D
2005-05-06 03:16:15 +04:00
pushw % e s # j u s t s a v e a l l r e g i s t e r s
pushw % a x
2005-04-17 02:20:36 +04:00
pushw % b x
pushw % c x
pushw % d x
pushw % d i
2005-05-06 03:16:15 +04:00
pushw % f s
2005-04-17 02:20:36 +04:00
popw % e s
movl $ 0 x13 1 3 1 3 1 3 , % e a x # m e m s e t b l o c k w i t h 0x13
movw $ 3 2 , % c x
movw $ 0 x14 0 , % d i
cld
2005-05-06 03:16:15 +04:00
rep
stosl
2005-04-17 02:20:36 +04:00
2006-06-26 11:26:37 +04:00
pushw % e s # s a v e E S
xorw % d i , % d i # R e p o r t C a p a b i l i t y
pushw % d i
popw % e s # E S : D I m u s t b e 0 : 0
movw $ 0 x4 f15 , % a x
xorw % b x , % b x
xorw % c x , % c x
int $ 0 x10
popw % e s # r e s t o r e E S
cmpb $ 0 x00 , % a h # c a l l s u c c e s s f u l
jne n o _ e d i d
cmpb $ 0 x4 f , % a l # f u n c t i o n s u p p o r t e d
jne n o _ e d i d
2005-05-06 03:16:15 +04:00
movw $ 0 x4 f15 , % a x # d o V B E / D D C
2005-04-17 02:20:36 +04:00
movw $ 0 x01 , % b x
movw $ 0 x00 , % c x
2005-09-10 00:04:34 +04:00
movw $ 0 x00 , % d x
2005-04-17 02:20:36 +04:00
movw $ 0 x14 0 , % d i
2005-05-06 03:16:15 +04:00
int $ 0 x10
2005-04-17 02:20:36 +04:00
2006-06-26 11:26:37 +04:00
no_edid :
2005-05-06 03:16:15 +04:00
popw % d i # r e s t o r e a l l r e g i s t e r s
2005-04-17 02:20:36 +04:00
popw % d x
popw % c x
popw % b x
popw % a x
2005-05-06 03:16:15 +04:00
popw % e s
2006-03-27 13:17:29 +04:00
# endif
2005-04-17 02:20:36 +04:00
ret
# VIDEO_ S E L E C T - o n l y v a r i a b l e s
mt_end : .word 0 # End o f v i d e o m o d e t a b l e i f b u i l t
edit_buf : .space 6 # Line e d i t o r b u f f e r
card_name : .word 0 # Pointer t o a d a p t e r n a m e
scanning : .byte 0 # Performing m o d e s c a n
do_restore : .byte 0 # Screen c o n t e n t s a l t e r e d d u r i n g m o d e c h a n g e
svga_prefix : .byte V I D E O _ F I R S T _ B I O S > > 8 # Default p r e f i x f o r B I O S m o d e s
graphic_mode : .byte 0 # Graphic m o d e w i t h a l i n e a r f r a m e b u f f e r
dac_size : .byte 6 # DAC b i t d e p t h
# Status m e s s a g e s
keymsg : .ascii " Press <RETURN> to see video modes available, "
.ascii " < SPACE> t o c o n t i n u e o r w a i t 3 0 s e c s "
.byte 0 x0 d , 0 x0 a , 0
listhdr : .byte 0x0d , 0 x0 a
.ascii " Mode : COLSxROWS : "
crlft : .byte 0x0d , 0 x0 a , 0
prompt : .byte 0x0d , 0 x0 a
.asciz " Enter m o d e n u m b e r o r ` s c a n ' : "
unknt : .asciz " Unknown mode ID. Try again. "
badmdt : .ascii " You passed an undefined mode number. "
.byte 0 x0 d , 0 x0 a , 0
vesaer : .ascii " Error: Scanning of VESA modes failed. Please "
.ascii " report t o < m j @ucw.cz>."
.byte 0 x0 d , 0 x0 a , 0
old_name : .asciz " CGA/MDA/HGA "
ega_name : .asciz " EGA "
svga_name : .ascii " "
vga_name : .asciz " VGA "
vesa_name : .asciz " VESA "
name_bann : .asciz " Video adapter: "
# endif / * C O N F I G _ V I D E O _ S E L E C T * /
# Other v a r i a b l e s :
adapter : .byte 0 # Video a d a p t e r : 0 =CGA / M D A / H G A ,1 =EGA ,2 =VGA
video_segment : .word 0xb800 # Video m e m o r y s e g m e n t
force_size : .word 0 # Use t h i s s i z e i n s t e a d o f t h e o n e i n B I O S v a r s