page 66,132 ; PC VIDEO INITIALIZATION PROGRAM ; Last changed 6-5-85 by Don Tarbell. ; ; COLOR Mode Equates: ; PCVCSEG EQU 0B800h ; Memory segment base PCVCOLP EQU 03D0h ; Base port address PCVCCUR EQU 0607h ; Cursor raster limits (underline) ; 0007h ; (block cursor) ; ; MONOCHROME Mode Equates: ; PCVMSEG EQU 0B000h ; Memory segment base PCVMONP EQU 03B0h ; Base port address PCVMCUR EQU 0B0Ch ; Cursor raster lines (under line) ; (block cursor) ; ; PC Video Relative I/O Port Offset Equates: ; PCVBANK EQU 00h ; Bank select register output port PCVFLIP EQU 01h ; Base address switch flip reg. output port PCV6845A EQU 04h ; Register address port of 6845 CRT Ctlr PCV6845D EQU 05h ; Register data input/output port of 6845 PCVMASTR EQU 08h ; Master Display Mode latch output port PCVBGRND EQU 09h ; Backround Color latch output port PCVSTATUS EQU 0ah ; Status Buffer input port PCVLPCLR EQU 0bh ; Clear Light Pen / Keyboard status/data ; regs and Keyboard Clock Ttl reg output PCVLPSET EQU 0ch ; Set Ready Flag / Keyboard Data input port ; ; Input Status Port (PCVSTATUS) bit definitions. ; VRT EQU 1000b ; Vertical retrace bit LPEN_SW EQU 0100b ; Light Pen Switch activated bit LPEN_RDY EQU 0010b ; Light Pen / keyboard data byte ready bit HRT EQU 0001b ; Horizontal retrace (display enable) bit ; ; Priority Interrupt Controller Equates: ; MASTER_PIC_0 EQU 50h ; System support I master PIC port #0 MASTER_PIC_1 EQU 51h ; System support I master PIC port #1 SEOI EQU 01100000b ; Specific End of Interrupt ; ; ASCII Control Character Equates: ; ETX EQU 03h ; Control-C for system restart X_ON EQU 11h ; XON/ DC1 control code. X_OFF EQU 13h ; XOFF/?DC3 control code DEL EQU 7fh ; Delete ; ; Common Equates: ; BLANK EQU 0720h ; Initial Space character/attribute PCVHIGH EQU 25 ; CRT screen height in rows ; ; 6845 CRT Video Controller Configuration Data Tables: ; CCURLX EQU PCVCCUR shr 8 ; Upper byte of color cursor limit CCURLZ EQU PCVCCUR and 0FFh ; lower byte of color cursor limit MCURLX EQU PCVMCUR shr 8 ; Upper byte of mono cursor limit MCURLZ EQU PCVMCUR and 0FFh ; lower byte of mono cursor limit ; ;======================================================================= stack segment para stack 'stack' db 10 dup('stack ') stack ends ; ;======================================================================= workarea segment page public 'data' ; ; Init String: Mode: Description: Adaptor Type: ; COLOR_ALPHA_80 label byte ; Color 80 column Color DW BLANK, 0029h ; Fill char, Backgrnd/Master Mode Regs DB 71h, 50h, 5ah, 0ah ; Horizontal Total, Disp, Sync, Width DB 1fh, 06h, 19h, 1ch ; Vertical Total, Adjust, Disp, Sync DB 01, 07h,CCURLX,CCURLZ ; Scan Mode, Max Line, Cursor Start/End DB 00h, 00h, 00h, 00h ; Start addr(H/L), Cursor addr(H/L) ; MONO_ALPHA_BW_80 label byte ; B/W 80 column Monochrome DW BLANK, 002dh DB 61h, 50h, 52h, 0fh, 19h, 06h, 19h, 19h DB 02h, 0dh,MCURLX,MCURLZ,00h, 00h, 00h, 00h ; color_alpha_40 label byte ; color 40 column color dw blank, 0028h db 38h, 28h, 2bh, 0ah, 1fh, 06h, 19h, 1ch db 02h, 07h,ccurlx,ccurlz,00h, 00h, 00h, 00h ; color_graph_320 label byte ; color 320 x 320 color dw 0000h, 000ah db 38h, 28h, 2bh, 0ah, 7fh, 06h, 64h, 70h db 02h, 01h, 26h, 07h, 00h, 00h, 00h, 00h ; color_graph_bw_320 label byte dw 0000h, 200eh db 38h, 28h, 2bh, 0ah, 7fh, 06h, 64h, 70h db 02h, 01h, 26h, 07h, 00h, 00h, 00h, 00h ; color_graph_bw_640 label byte dw 0000h, 071eh db 38h, 28h, 2bh, 0ah, 7fh, 06h, 64h, 70h db 02h, 01h, 26h, 07h, 00h, 00h, 00h, 00h ; mono_graph_bw_320 label byte ; b/w 320 x 200 monochrome dw 0000h, 200eh db 30h, 28h, 29h, 0fh, 7fh, 06h, 64h, 70h db 02h, 01h, 2bh, 0ch, 00h, 00h, 00h, 00h ; ;======================================================================= ; ; ********************************** ; * VIDEO DISPLAY OUTPUT * ; * VARIABLE STORAGE AREA * ; ********************************** ; ; PCV_SEG DW 0 ; Base segment of screen memory PCVPORT DW 0 ; Base address of current I/O port ; PCVSAVE DW 0 ; Hold cursor coordinates save storage CURSOR DW 0 ; Current cursor "Y,X" position CURSROW DW 0 ; Display limits for current cursor SCREEN label word ; Current screen dimensions HSCREEN DB 80 ; Screen width VSCREEN DB PCVHIGH ; Screen height MODEREG DB 0 ; Current mode register value COLSREG DB 0 ; Current palette register value PCVATTR DB 0 ; Current character attributes PCVMODE DB 03h ; Line wrap on, cursor on workarea ends ; ;======================================================================= cseg segment para public 'code' assume cs:cseg, ds:workarea, ss:stack, es:nothing ; ; PC Video Display Output Initialization Routine: ; pcvinit proc far push ds ; save return segment. mov ax,0 ; put zero onto stack. push ax mov ax,workarea mov ds,ax ; ds = workarea segment. MOV SI,offset mono_alpha_bw_80 mov ax,pcvmseg ; mono base segment. mov dx,pcvmonp ; mono base port. CALL pcvini1 ; Perform color init sequence mov cx,40h ; es = 40h. mov es,cx mov bx,74h ; place for segment. mov es:[bx],ax mov bx,76h ; place for port. mov es:[bx],dx mov bx,19h ; bx = 19h (vtype address). mov al,5 ; al bits set for both monitor and terminal. mov es:[bx],al ; set vtype. ret pcvinit endp ; ; Set up Initial Video Memory and Port Values: ; ;Entry: AX = Base segment of PC Video display memory, ; DX = Base address I/O port for Pc Video board, ; SI = Pointer to video initialization data string. ; pcvini1 proc near push ax ; sve segment. push dx ; save port. PUSH ES ; Save entering extra segment MOV PCVPORT,DX ; Save base port address for reference MOV PCV_SEG,AX ; Save base segment for video display MOV ES,AX ; Update extra to new video memory seg CALL BEAMOFF ; Turn off video display at vert sync CLD ; All string operations in forward dir LODSW ; Get fill word from init string MOV PCVATTR,AH ; Update Attribute byte for scrolling MOV CX,8192 ; Fill entire size of screen (8K words) MOV DI,0 ; Start at first location REP STOSW ; INit video display with fill words POP ES ; Restore entering extra segment CALL VSYNC ; Sync up new timing chain to vert sync LODSW ; Get master mode, color select values PUSH SI ; Save 6845 reg value string pointer ADD DX,PCVMASTR ; Advance to master mode control port PUSH AX ; Save mode, color select values AND AX,11101111b ; Start with video enable bit off OUT DX,AL ; In new master mode(Relative Port #8) ; Starting 6845 reg number in @AH@ = 0 MOV CX,16 ; 16 registers in controller to load SUB DX,(PCVMASTR-PCV6845A) ; Get 6845 Adr (Relative Port #4) PCVINI2: MOV AL,AH OUT DX,AL ; Set up reg number via address port INC DX ; Point to 6845 data (relative port #5) LODSB ; Get data for CRT controller register OUT DX,AL ; Send data byte to 6845 DEC DX ; Point back to register address port INC AH ; NExt register number to load LOOP PCVINI2 ; loop until all 16 registers set up POP AX ; Recover master mode, color select ADD DX,(PCVMASTR-PCV6845A) ; Point to master mode ctl port OUT DX,AL ; Set it up (relative port #8) MOV MODEREG,AL ; Save a copy of the mode control INC DX ; Point to background color reg port MOV AL,AH ; Get the color selection OUT DX,AL ; Setup color select (relative port #9) MOV COLSREG,AL ; Sve a copy of the color selection POP SI ; Recover 6845 reg value string pointer MOV CL,1[SI] ; Get horizontal chars displayed count MOV CH,PCVHIGH ; Get predetermined viertical line count IF (PCVHIGH eq 0) MOV CH,6(SI) ; Get vertical lines displayed count ENDIF MOV SCREEN,CX ; Save current active dimensions MOV AL,15[SI] ; Get specifie dcursor starting address MOV AH,14[SI] DIV CL ; Divide by screen width to get "X,Y" XCHG AH,AL ; Row number in "AH", column in "AL" MOV CURSOR,AX ; Update cursor position storage MOV AL,1[SI] ; Get cursor end line number MOV AH,10[SI] ; Get cursor start line number MOV CURSROW,AX ; Update storage to match SUB AX,AX ; Show successful return flags pop dx ; restore port. pop ax ; restore segment. RET pcvini1 endp ; ;========================================================================= ; ; Disable the video beam (blank entire screen). ; beamoff proc near PUSH AX PUSH DX ; Save entering registers CALL VSYNC ; Wait for vertical sync pulse to occur MOV AL,MODEREG ; Get current (old) master mode control AND AL,11101111b ; reset mode with video enable bit off BEAMCHG: MOV DX,PCVPORT ; Point to master mode control port ADD DX,PCVMASTR OUT DX,AL ; Set up new value (relative port #8) POP DX POP AX ; Recover entering registers RET beamoff endp ; ;======================================================================== ; ; Wait for Vertical Sync Pulse from video controller. ; vsync proc near PUSH AX PUSH CX PUSH DX MOV DX,PCVPORT ; Point to video status port address ADD DX,PCVSTATUS ; (relative port #10) MOV CX,-1 ; Init timeout counter VSYNC0: CALL VSYNC3 ; Delay and test status of vert sync LOOPNZ VSYNC0 ; Loop until absent (pulse start) JCXZ VSYNC2 ; Abort if timeout encountered MOV CX,-1 ; Init timeout counter. VSYNC1: CALL VSYNC3 ; delay and test status of vert sync LOOPZ VSYNC1 ; loop until vertical sync occurs VSYNC2: POP DX POP CX POP AX RET vsync endp ; vsync3 proc near PUSH AX POP AX ; Delay for CPU timeout IN AL,DX ; Get status of video board TEST AL,VRT ; Test for vertical sync pulse RET vsync3 endp cseg ends end pcvinit