
;--------------------------------------------------------------------------------------------------
;                            LOADING ROUTINE
;--------------------------------------------------------------------------------------------------

ASSUME CS:CODE

DES0    EQU  0417H                    ; CHECKS FOR ALT KEY PRESSED
DES1    EQU  0449H                    ; STORES MODE SELECTION INFO
DES2    EQU  0489H                    ; STORES INFO ABOUT THE ACTIVE CHARACTER SET
DES3    EQU  0463H                    ; STORES MONO/COLOR MODE INFO (03B4/03D4 REG.)
DES4    EQU  0462H                    ; STORES SETTINGS OF THE ACTIVE SCREEN PAGE
DES5    EQU  0487H                    ; STORES MODE OF DISPLAY (MONO/COLOR)

CODE SEGMENT

VECSTO1   DD   1 DUP(0)               ; POINTS TO LOCATION USED TO STORE INT VECTOR 09H VALUES
VECSTO3   DD   1 DUP(0)               ; POINTS TO LOCATION USED TO STORE INT VECTOR 10H VALUES
ID1       DW   1 DUP(0)               ; STORES VGA CONTROLLER IDENTIFICATION NUMBER
MMST DB 2 DUP(?)                      ; USED TO STORE SEGMENT OF PSP
CSEG DB 2 DUP(?)                      ; USED TO STORE SEGMENT VALUE OF PREVIOUSLY INSTALLED TSR

START:

        CALL NEWSUB                   ; CHECK FOR COMMAND LINE ARGUMENT 
	                                 ; & UNLOADING OF THE TSR
        JNZ  LOC1                     ; MODE NORMAL ON NO ZERO              
        JMP  LOC2                     ; IF IN TV MODE, DISPLAY AND TERMINATE
LOC1:
        MOV AL,09H                    ; GET INTERRUPT VECTOR FOR INT 09H
        CALL SR3                      ; CALL SUBROUTINE TO GET INTERRUPT VECTOR
        MOV CS:WORD PTR VECSTO1,BX    ; STORE INT VECTOR 09H IN LOCATIONS POINTED BY
	                                 ; VECSTO1 AND VECSTO1+2 
        MOV CS:WORD PTR VECSTO1+2,ES                          
        MOV AL,10H                    ; GET INTERRUPT VECTOR FOR INT 10
        CALL SR3                      ; CALL SUBROUTINE TO GET INTERRUPT VECTOR
        MOV CS:WORD PTR VECSTO3,BX    ; STORE INT VECTOR 10H IN LOCATIONS POINTED BY 
	                                 ; VECSTO3 AND VECSTO3+2 
        MOV CS:WORD PTR VECSTO3+2,ES                          
        MOV AX,CS                              
        MOV DS,AX                     ; DS INITIALISED WITH CS       
        MOV AX,0C000H                 ; LOAD ES WITH START OF VGA BIOS
        MOV ES,AX
        MOV SI,OFFSET MALLOC0         ; SI INITIALISED TO LOCATION POINTED BY MALLOC0 
	                                 ; TO SELECT DIFFERENT VGA CONTROLLERS 
        MOV CX,0007                   ; NO. OF TYPES OF CONTROLLERS
LOC9:
        PUSH SI                       ; SAVE SI AND CX ON STACK
        PUSH CX
        MOV SI,[SI]
        MOV CX,[SI]
        MOV BX,[SI+2]
        ADD SI,03
        CALL SR4                      ; CALL ROUTINE FOR CONTROLLER IDENTIFICATION
                                      ; CHECK FOR MATCH
        JNZ  LOC5                     ; POP SI AND CX IF MATCH NOT FOUND         
        MOV CS:WORD PTR ID1,BX        ; IDENTIFICATION FOR CHIP. WHERE ID1 GIVES 
	                                 ; CONTROLLER NUMBER
LOC5:
        POP CX                                 
        POP SI                              
        CMP CS:WORD PTR ID1,00        ; ANY MATCH FOUND ?
        JNZ LOC8                      ; IF YES JUMP OUT TO CHECK FOR PARTICULAR CHIP DETAILS
        ADD SI,02                     ; IF NO LOOP AGAIN.
        LOOP LOC9
        JMP SHORT LOC10

LOC8:   CMP CS:WORD PTR ID1,01        ; IS IT TSENG LAB CHIP ?
        JNZ LOC11                               
        CALL SR5                      ; THEN CALL ROUTINE TO VERIFY VERSION NUMBER
        JMP SHORT LOC10
LOC11:  CMP CS:WORD PTR ID1,03        ; IS IT TRIDENT CHIP ?
        JNZ LOC10
        CALL SR6                      ; THEN VERIFY VERSION NUMBER. (TRIDENT < 3 OR >= 3)
LOC10:
        MOV DX,OFFSET ISR9            ; ADDRESS OF INTERRUPT HANDLER
        MOV AL,09H                    ; SET INTERRUPT VECTOR FOR 09
        CALL SR9                      ; CALL ROUTINE TO SET INT VECTOR
        MOV DX,OFFSET ISR10           ; ADDRESS OF INTERRUPT HANDLER
        MOV AL,10H                    ; SET INTERRUPT VECTOR 10
        CALL SR9                      ; CALL ROUTINE TO SET INT VECTOR
        CALL SR10                     ; DISPLAY STRING 
        MOV DX,0240H                  ; MEMORY TO BE RESERVED FOR TSR.
        MOV AH,31H                    ; TERMINATE AND STAY RESIDENT.
        INT 21H                       ; TRANSFER CONTROL TO DOS
LOC2:
        CALL SR10                     ; IF ALREADY IN TV MODE DISPLAY STRING
        MOV AH,4CH                    ; FUNCTION TO TERMINATE PROCESS           
        INT 21H                       ; TERMINATE PROCESS.                

;--------------------------------------------------------------------------------------------------
;  ROUTINE FOR CHECKING COMMAND TAIL (PSP) AND PROCEEDING FOR PAL OR
;  NTSC OR UNLOADING OF TSR
;--------------------------------------------------------------------------------------------------

NEWSUB PROC NEAR
       TAIL   EQU  80H                ; OFFSET OF COMMANDTAIL SEGMENT

       MOV AL,10H                     
       CALL SR2                       ; GET SEGMENT OF INT 10 & CHECK IF TSR IS ALREADY LOADED
       JNZ XX                         
       MOV WORD PTR CSEG,ES           ; STORE SEGMENT OF INT 10 IN CSEG IF TSR IS ALREADY LOADED
XX:
       MOV WORD PTR MMST,DS           ; STORE SEGMENT OF PSP IN MMST
       MOV DI,TAIL
       MOV AH,[DI]
       CMP AH,03                      ; CHECK FOR LENGTH 
       JNE ERDISP                     ; LENGTH IF NOT 3, DISPLAY ERROR MESSAGE

       INC DI
       MOV AH,[DI]
       CMP AH,20H                     ; CHECK FOR SPACE
       JNE ERDISP

       INC DI
       MOV AH,[DI]
       CMP AH,2DH                     ; CHECK FOR '-'
       JNE ERDISP
PROCE:
       INC DI
       MOV AH,[DI]
       OR AH,20H                      ; CHECK FOR LETTER P OR p
       CMP AH,70H
       JE PAL                         ; IF P PROCEED FOR PAL CODES

       CMP AH,6EH                     ; CHECK FOR LETTER N OR n
       JE NTSC                        ; IF N PROCCED FOR NTSC CODES

       CMP AH,75H                     ; CHECK FOR U OR u
       JE ULOAD                       ; IF U CHECK FOR UNLOADING THE TSR

ERDISP:
        MOV DX,OFFSET MESG            ; ERROR MESSAGE TO DISPLAY WHEN INPUT GIVEN IN THE
        JMP EXIT                      ; COMMAND LINE IS NOT OK!..
        MESG DB 'ILLEGAL INPUT $'

PAL:    MOV SI,OFFSET PALCODE         ; STARTING ADDRESS OF THE PAL CODE
        JMP COP

NTSC:   MOV SI,OFFSET NTSCODE         ; STARTING ADDRESS OF THE NTSC CODE

COP:    MOV AX,CS
        CMP WORD PTR CSEG, 00H
        JZ ESCAPE                     ; INCASE TSR IS LOADED ALREADY, USE THE
        MOV AX,WORD PTR CSEG          ; PREVIOUS SEGMENT VALUE
ESCAPE: MOV DS,AX
        MOV ES,AX                     ; COPY PAL/NTSC CODES TO THE STARTING LOCATION 
        MOV DI,OFFSET TRI2_78         ; TRI2_78 AND PROCEED TILL 315 BYTES ARE COPIED (ie.,013BH)
        MOV CX,013BH
        REP MOVSB
        JMP SR1                       ; CHECK FOR CURRENT MODE TV/NORMAL AND PROCEED WITH
	                                 ; LOADING ROUTINE
ULOAD:
        MOV AL,10H                    ; CHECK FOR INT VECTORS 10H & 09H, IF TSR FOUND ALREADY
        CALL SR2                      ; LOADED PROCEED WITH UNLOADING TSR ROUTINE, ELSE IF
        JNZ ABC                       ; ERROR FOUND IN VECTORS DISPLAY ERROR MESSAGE
        MOV AL,09H
        CALL SR2
        JZ CONTIN
        JMP VECERR

ABC:    MOV AL,09H
        CALL SR2
        JZ VECERR
        JMP NLOD                      ; IF VECTORS ARE NOT MATCHING WITH PREVIOUSLY LOADED 
	                                 ; VECTORS, DISPLAY MESSAGE INDICATING TSR ALREADY 
							   ; UNLOADED

CONTIN:  MOV ES,WORD PTR CSEG         ; CHECK FOR MODE (TV/NORMAL)
         CMP ES:WORD PTR ID3,00H      ; IF IN TV MODE, DISPLAY MESSAGE STATING UNLOADING
         JNZ UNMON                    ; NOT POSSIBLE IN TV MODE

         MOV DX,ES:WORD PTR VECSTO1
         MOV DS,ES:WORD PTR VECSTO1+2 ; RESTORE INT VECTOR 09H
         MOV AL,09H
         MOV AH,25H
         INT 21H

         MOV DX,ES:WORD PTR VECSTO3
         MOV DS,ES:WORD PTR VECSTO3+2 ; RESTORE INT VECTOR 10H
         MOV AL,10H
         MOV AH,25H
         INT 21H

         MOV AX,ES
         MOV DS,AX                    ; GET PREVIOUS CODE SEGMENT
         MOV ES,DS:WORD PTR MMST      ; GET PREVIOUS PSP SEGMENT

         MOV AX,ES
         MOV BX,AX
         MOV AX,ES:[2CH]              ; RELEASE ENVIRONMENT MEMORY
         MOV ES,AX
         MOV AH,49H
         INT 21H

         MOV AX,BX
         MOV ES,AX
         MOV AH,49H                   ; RELEASE PROGRAM MEMORY
         INT 21H

         JB ERROR                     ; IF MEM. IS NOT RELEASED, DISPLAY ERROR MESSAGE
         JMP SUCC                     ; ELSE DISPLAY TSR SUCCESSFULLY UNLOADED MESSAGE

VECERR:  MOV DX,OFFSET VERR
         JMP EXIT
         VERR DB 'ERROR, VECTORS ARE NOT OK!.. $'

UNMON:   MOV DX,OFFSET MON
         JMP EXIT
         MON DB 'UNLOADING CAN BE POSSIBLE ONLY IN MONITOR MODE..$'

NLOD:   MOV DX,OFFSET UNLOD
         JMP EXIT
         UNLOD DB 'TSR NOT LOADED!..       $'

ERROR:   MOV DX, OFFSET ERR
         JMP EXIT
         ERR DB 'ERROR ENCOUNTERED IN UNLOADING.. $'

SUCC:    MOV DX,OFFSET DISPLAY

EXIT:    MOV AX,CS
         MOV DS,AX               
         MOV AH,09H                   ; DISPLAY SPECIFIED MESSAGE & EXIT TO DOS
         INT 21H
         MOV AX,4C00H
         INT 21H
         DISPLAY DB 'TSR SUCCESSFULLY UNLOADED.. $'
         RET
NEWSUB ENDP

;--------------------------------------------------------------------------------------------------
;   GET INT VECTORS AND CHECK FOR TV/NORMAL MODE
;--------------------------------------------------------------------------------------------------

SR1 PROC NEAR
        MOV AL,10H                    ; GET INTERRUPT VECTOR FOR INT 10 
        CALL SR2                      ; CHECK FOR MODE [TV OR NORMAL]
        JZ LOC4                                          
        MOV AL,09H                    ; IF IN NORMAL CHECK INTERRUPT VECTOR
        CALL SR2                      ; FOR INT 9 FOR MODE
        JZ LOC4                       ; ZERO FLAG SET IF IN TV MODE
LOC4:
        RET
SR1 ENDP

SR2 PROC NEAR
	                                   
        CALL  SR3                    ; GET INTERRUPT VECTOR
        CMP ES:BYTE PTR [BX-03],42H  ; CHECK IF IT PERTAINS TO TV MODE -B
        JNZ LOC3                             
        CMP ES:BYTE PTR [BX-02],50H  ; -P
        JNZ LOC3
        CMP ES:BYTE PTR [BX-01],4CH  ; -L RETURNS WITH ZERO FLAG SET
LOC3:
        RET      		            ; IF IN TV MODE
SR2 ENDP

;--------------------------------------------------------------------------------------------------
; SUBROUTINE TO GET INTERRUPT VECTOR
;--------------------------------------------------------------------------------------------------

SR3 PROC NEAR
	                                   
        MOV AH,35H                  ; FUNCTION CALL TO GET INTERRUPT VECTOR
        INT 21H                     
                                    ; RETURN IN ES:BX      
        RET

SR3 ENDP

;--------------------------------------------------------------------------------------------------
; SUBROUTINE TO SET INTERRUPT VECTOR
;--------------------------------------------------------------------------------------------------

SR9 PROC NEAR
	                                   
        PUSH CS                     ; LOAD CS INTO DS                        
        POP DS                                 
        MOV AH,25H                  ; SET INTERRUPT VECTOR               
        INT 21H                     ; ASK DOS TO GET INT VECTOR                
        RET
SR9 ENDP

;--------------------------------------------------------------------------------------------------
; MEMORY ALLOCATIONS WHERE ADDRESS OF DIFFERENT VGA CONTROLLERS, THEIR LENGTH ETC 
; IS STORED
;--------------------------------------------------------------------------------------------------

MALLOC0      DW   TSEN,TRID,PARAD,WEST,OAK,REAL,CIR   ; THE SUPPORTED CONTROLLERS

TSEN  DW  0005H,0001H                ; NUMBER OF SUCCEEDING IDENTIFICATION BYTES, BX VALUE
      DB  74H,73H,65H,6EH,67H                         
	 
TRID  DW  0007H,0003H
      DB  74H,72H,69H,64H,65H,6EH,74H
	 
PARAD DW  0008H,0005H
      DB  70H,61H,72H,61H,64H,69H,73H,65H
	 
WEST  DW  0007H,0005H
      DB	77H,65H,73H,74H,65H,72H,6EH
	 
OAK   DW  0003H,0006H
      DB  6FH,61H,6BH
	 
REAL  DW  0007H,0007H	 
      DB  72H,65H,61H,6CH,74H,65H,6BH  
             
CIR   DW  0006H,0008H
      DB  63H,69H,72H,72H,75H,73H

;--------------------------------------------------------------------------------------------------
; CONTROLLER TYPE IDENTIFICATION ROUTINE.  AT ENTRY DS=CS AND ES=C000
;--------------------------------------------------------------------------------------------------

SR4 PROC NEAR
        XOR DI,DI                   ; MAKE DI ZERO
        PUSH BX                     ; SAVE BX ON STACK   
        MOV BX,CX                   ; LOAD BX WITH CONTENTS OF CX BEFORE THE CALL
LOC08:          
        PUSH SI
        MOV CX,BX 
LOC6:                             
        MOV AL,ES:[DI]              ; GET BYTE FROM C000
        INC DI                                 
        OR AL,20H                   ; MODIFY IT FOR LOWERCASE,UPPER CASE
        INC SI                                 
        CMP AL,[SI]                 ; COMPARE IT WITH OUR DATA     
        LOOPZ LOC6           
        POP SI                                 
        JCXZ LOC7                               
        CMP DI,00FFH                ; HAS COMPARISON CHECKED FOR FOR 256 BYTES
        JBE LOC08                               
LOC7:
        POP BX                      ; ZERO FLAG SET IF MATCH IS THERE. 
        RET
SR4 ENDP

;--------------------------------------------------------------------------------------------------
; ROUTINE FOR VERSIONS OF TSENG LAB CHIP
;--------------------------------------------------------------------------------------------------

SR5 PROC NEAR
	                                   
        MOV DX,03CCH                ; PORT ADDRESS IN DX                          
        IN AL,DX                    ; INPUT A BYTE FROM SPECIFIED PORT            
        MOV DX,03D4H            
        TEST AL,01H
        JNZ LOC12
        MOV DX,03B4H
LOC12:
        MOV AL,33H
        CALL SR8                    ; CALL ROUTINE TO OUTPUT AL TO DX
                                    ; AND INPUT AH TO DX+1.
        PUSH AX                                 
        XOR AH,0FH                  ; INVERT LAST FOUR BITS OF AH
        MOV BX,AX                              
        CALL SR7                               
        CALL SR8                               
        MOV CS:WORD PTR ID1,0001               
        CMP AH,BH                              
        JNZ LOC13                               
        MOV CS:WORD PTR ID1,0002               
LOC13:
        POP AX                                 
        CALL SR7                               
        RET
SR5 ENDP

;--------------------------------------------------------------------------------------------------
; ROUTINE FOR VERSIONS OF TRIDENT CHIP
;--------------------------------------------------------------------------------------------------

SR6 PROC NEAR
	                                   
        MOV DX,03C4H                ; PORT ADDRESS IN DX
        MOV AL,0BH                  ; GET VERSION NUMBER.
        CALL SR8                    ; CALL ROUTINE TO OUTPUT AL TO PORT DX
                                    ; AND INPUT AH TO PORT DX+1
        MOV CS:WORD PTR ID1,0003    ; FOR VERSIONS LESS THAN OR
        CMP AH,03                   ; EQUAL TO 2.
        JB LOC14                               
        MOV CS:WORD PTR ID1,0004    ; FOR VERSIONS > 2   
LOC14:
        RET

SR6 ENDP

;--------------------------------------------------------------------------------------------------
; ROUTINE TO OUTPUT AX TO DX AND DX+1.
;--------------------------------------------------------------------------------------------------

SR7 PROC NEAR

        OUT DX,AL                   ; OUTPUT AL TO PORT DX.
        INC DX                                 
        XCHG AL,AH                  ; OUTPUT AH TO PORT DX+1.     
        OUT DX,AL                              
        XCHG AL,AH                  ; DX AND AX ARE UNCHANGED.   
        DEC DX                                 
        RET
SR7 ENDP

;--------------------------------------------------------------------------------------------------
; ROUTINE TO OUTPUT AL TO DX AND INPUT DX+1 TO AH.
;--------------------------------------------------------------------------------------------------

SR8 PROC NEAR	                                   
        OUT DX,AL                   ; OUTPUT AL TO PORT DX
        INC DX                                 
        MOV AH,AL                        
        IN AL,DX                    ; INPUT DX+1 TO AH  
        DEC DX                                 
        XCHG AL,AH                  ; DX AND AL ARE UNCHANGED.
        RET
SR8 ENDP

;--------------------------------------------------------------------------------------------------
; DISPLAY STRING
;--------------------------------------------------------------------------------------------------

SR10 PROC NEAR
	                                   
        MOV AX,0003H                ; SET VIDEO MODE TO 03 WHICH IS COLOR TEXT MODE                       
        INT 10H                                 
        MOV DX,0000                 ; STARTING CURSOR POSITION (ROW,COLUMN)      
        MOV BX,0007H                ; BH ACTIVE DISPLAY PAGE   
				                ; BL STRING ATTRIBUTE	
        MOV CX,CS:WORD PTR DISP     ; CX LENGTH OF CHARACTER STRING  
        MOV AX,CS                              
        MOV ES,AX  
        MOV BP,OFFSET MALLOC1       ; ES:BP STARTING ADDRESS OF STRING TO BE 
			                     ; DISPLAYED
        MOV AX,1301H                ; WRITE CHARACTER STRING. 
        INT 10H                               
        RET

SR10 ENDP

;--------------------------------------------------------------------------------------------------
; MEMORY ALLOCATION TO TABLE OF CHARACTER CODES USED FOR DISPLAY
;--------------------------------------------------------------------------------------------------	 

MALLOC1  DB   0C9H,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH
             DB   0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH
             DB   0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0BBH
             DB   0AH,0DH,0BAH,20H,20H,20H,42H,50H,4CH,20H,53H,59H,53H,54H,45H
             DB   4DH,53H,20H,26H,20H,50H,52H,4FH,4AH,45H,43H,54H,53H,20H,4CH
             DB   54H,44H,2EH,2CH,20H,20H,20H,20H,0BAH,0AH,0DH,0BAH,56H,47H
             DB   41H,2DH,54H,56H,28H,4EH,54H,53H,43H,2FH,50H,41H,4CH,29H,20H
             DB   54H,53H,52H,20H,44H,72H,69H,76H,65H,72H,20H,56H,65H,72H,20H
             DB   31H,2EH,30H,0BAH,0AH,0DH,0BAH,43H,6FH,6DH,6DH,61H,6EH,64H
             DB   20H,4CH,69H,6EH,65H,20H,4FH,70H,74H,69H,6FH,6EH,73H,20H,3AH
             DB   20H,20H,20H,20H,20H,20H,20H,20H,20H,20H,20H,20H,20H,0BAH,0AH
             DB   0DH,0BAH,20H,20H,31H,29H,20H,54H,56H,20H,2DH,50H,20H,1AH,20H
             DB   50H,41H,4CH,20H,20H,20H,32H,29H,20H,54H,56H,20H,2DH,4EH,20H
             DB   1AH,20H,4EH,54H,53H,43H,20H,0BAH,0AH,0DH,0BAH,20H,20H,20H,20H
             DB   20H,20H,20H,20H,20H,33H,29H,20H,54H,56H,20H,2DH,55H,20H,1AH
             DB   20H,55H,4EH,4CH,4FH,41H,44H,20H,20H,20H,20H,20H,20H,20H,20H
             DB   20H,0BAH,0AH,0DH,0BAH,4DH,6FH,64H,65H,20H,53H,77H,69H,74H
             DB   63H,68H,20H,48H,6FH,74H,20H,4BH,65H,79H,20H,3AH,20H,41H
             DB   4CH,54H,5FH,42H,41H,43H,4BH,53H,50H,41H,43H,45H,0BAH,0AH,0DH
             DB   0BAH,55H,74H,69H,6CH,69H,74H,79H,20H,48H,6FH,74H,20H,4BH
             DB   65H,79H,73H,20H,3AH,20H,20H,20H,20H,20H,20H,20H,20H,20H,20H
             DB   20H,20H,20H,20H,20H,20H,20H,0BAH,0AH,0DH,0BAH,20H,20H,53H
             DB   63H,72H,65H,65H,6EH,20H,53H,68H,69H,66H,74H,20H,55H,70H
             DB   20H,20H,20H,20H,20H,2DH,2DH,10H,20H,20H,41H,4CH,54H,5FH,55H
             DB   20H,20H,20H,0BAH,0AH,0DH,0BAH,20H,20H,53H,63H,72H,65H,65H
             DB   6EH,20H,53H,68H,69H,66H,74H,20H,44H,6FH,77H,6EH,20H,20H,20H
             DB   2DH,2DH,10H,20H,20H,41H,4CH,54H,5FH,44H,20H,20H,20H,0BAH,0AH
             DB   0DH,0BAH,20H,20H,53H,63H,72H,65H,65H,6EH,20H,53H,68H,69H,66H
             DB   74H,20H,4CH,65H,66H,74H,20H,20H,20H,2DH,2DH,10H,20H,20H,41H
             DB   4CH,54H,5FH,4CH,20H,20H,20H,0BAH,0AH,0DH,0BAH,20H,20H,53H
             DB   63H,72H,65H,65H,6EH,20H,53H,68H,69H,66H,74H,20H,52H,69H,67H
             DB   68H,74H,20H,20H,2DH,2DH,10H,20H,20H,41H,4CH,54H,5FH,52H,20H
             DB   20H,20H,0BAH,0AH,0DH,0C8H
             DB   0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH
             DB   0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH
             DB   0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0CDH,0BCH
             DB   0AH,0DH
DISP         DW   01FBH             ; LENGTH OF CHARACTER STRING
WORD1        DW   1 DUP(0)          ; USED AS SEGMENT VALUE FOR DES0
ID3          DB   1 DUP(0)          ; CONTAINS 00H IN NORMAL MODE AND 01H IN TV MODE
ID4          DB   1 DUP(0)          ; SETS TO 1 FOR MODES 0FH,10H,11H,12H,5CH,5DH
ID2          DB   1 DUP(0)          ; SETS TO 1 WHEN INT 10H IS BEING EXECUTED
ID7          DB   1 DUP(0)          
ID6          DB   1 DUP(0)          ; SETS TO 1 WHEN WRITE TTY IS BEING EXECUTED 
EX           DB   42H,50H,4CH       ; CODES FOR CHARACTERS BPL

;--------------------------------------------------------------------------------------------------
;                            RESIDENT ROUTINE
;--------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------
; ROUTINE FOR INT 10
;--------------------------------------------------------------------------------------------------

ISR10 PROC FAR

        CMP AH,00                   ; CHECK FOR FUNCTION 0
        JZ LOC15                    ; IF DETECTED PROCEED
        JMP LOC16                   ; OTHERWISE CHECK FOR OTHER FUNCTIONS
LOC15:
        INC CS:BYTE PTR ID2         ; SET IDENTIFIER FOR EXECUTION OF INT 10H
        CMP CS:BYTE PTR ID3,00      ; IS IT IN TV MODE ?
        JZ LOC17                    ; IF NO EXECUTE NORMAL INT 10 ROUTINE
        MOV CS:BYTE PTR ID4,00      ;SET IDENTIFIER FOR INTERLACE
        MOV CS:WORD PTR MALLOC12A,00      ; SET HRETRACE COUNT TO 0000
        MOV CS:WORD PTR MALLOC12B,00      ; SET VRETRACE COUNT TO 0000
        PUSH BX
        PUSH AX                                 
        AND AL,7FH                  ; REMOVE THE MSB IF ANY.       
        CMP AL,13H                  ; IS IT MODE 13  ?
        JZ LOC18                    ; IF NOT IS IT LESS THAN 0F ?     
        CMP AL,0FH                              
        JB LOC18                               
        MOV CS:BYTE PTR ID4,01      ; IF NOT SET INTERLACE IDENTIFIER.
LOC18:
        CMP AL,03H                  ; IS MODE LESS THAN 3?    
        JA LOC19                 
        MOV AX,1200H                ; IF SO SET SCAN LINE TO 200 
        MOV BL,30H                              
        PUSHF	                                   
        CALL CS:VECSTO3
LOC19:
        POP AX                                 
        POP BX                                 
LOC17:
        PUSHF	                                   
        CALL CS:VECSTO3             ; SET TO NORMAL MODE
        CMP CS:BYTE PTR ID3,00      ; CHECK FOR DESIRED MODE
        JZ LOC20                               
        CALL SR11                   ; SET TO TV MODE IF [03B6] IS '1'
        DEC CS:BYTE PTR ID2        
        IRET
LOC20:
        DEC CS:BYTE PTR ID2         ; RETURN IF NORMAL MODE
        IRET

LOC16:	                                   
        CMP AH,01                   ; CHECK FOR FUNCTION 01
        JNZ LOC21                   ; OTHERWISE BRANCH.    
        CMP CS:BYTE PTR ID3,00      ; JUMP OUT IF NORMAL MODE IS DESIRED
        JZ LOC21                         
        CALL SR12                   ; FOR TV MODE.       
        IRET
LOC21:  CMP  AH,0EH                 ; CHECK FOR FUNCTION 0E   
        JNZ LOC22                   ; OTHERWISE BRANCH.   
        MOV CS:BYTE PTR ID6,01      ; FOR WRITE TTY FUNCTION SET IDENTIFIER AND GO
            				      ; IN THE NORMAL PATH.       
        PUSHF	                                   
        CALL CS:VECSTO3                         
        MOV CS:BYTE PTR ID6,00      ; RESET IDENTIFIER BEFORE
        IRET                        ; RETURN.
LOC22:
        CMP AH,0BH                  ; CHECK FOR FUNCTION 0B
        JZ LOC23                               
        CMP AH,10H                  ; OTHERWISE CHECK FOR FUNCTION 10
        JZ LOC23                               
        CMP AH,11H                  ; OTHERWISE CHECK FOR FUNCTION 11
        JZ LOC23                               
        CMP AH,12H                  ; OTHERWISE CHECK FOR FUNCTION 12
        JNZ LOC24                               
LOC23:
        INC CS:BYTE PTR ID7         ; SET IDENTIFIER BEFORE EXECUTING NORMAL INT 10 ROUTINE
        PUSHF	                                   
        CALL CS:VECSTO3                         
        DEC CS:BYTE PTR ID7         ; RESET IDENTIFIER.
        IRET
LOC24:
        PUSHF	                     ; EXECUTE NORMAL INT 10 ROUTINE. 
        CALL CS:VECSTO3                         
        IRET
ISR10 ENDP

SR12    PROC  NEAR
        PUSH DS                                 
        PUSH DX                                 
        PUSH CX                                 
        PUSH AX                                 
        MOV DS,CS:WORD PTR WORD1    ; DS = 0000 
        MOV DX,DS:WORD PTR DES3     ; IS IT COLOR OR MONOCHROME? 
        MOV AL,0AH                              
        CMP CH,1EH                  ; IF CURSOR POSITION IS HIGH   
        JBE LOC25                   ; SET IT TO REFERENCE VALUE.
        MOV CX,1E00H                            
        JMP SHORT LOC26                               
LOC25:  TEST DS:BYTE PTR DES0,80H   ; IS INSERT MODE ON ?
        MOV CX,0607H                ; SET CURSOR VALUE FOR NORMAL MODE.
        JZ LOC26                     
        MOV CX,0007                 ; SET CURSOR VALUE FOR INSERT MODE.
LOC26:  MOV AH,CH                   ; SET CURSOR REGISTERS.
        CALL SR7                               
        INC AL                                 
        MOV AH,CL                              
        CALL SR7                               
        POP AX                                 
        POP CX                                 
        POP DX                                 
        POP DS                                 
        RET
SR12 ENDP

;--------------------------------------------------------------------------------------------------
; ROUTINE TO SELECT A PARTICULAR VGA CONTROLLER DEPENDING ON THE CONTROLLER NO. STORED IN ID1 AND
; PROCEED WITH THE SELECTED ONE TO CHANGE MODE
;--------------------------------------------------------------------------------------------------
          
SR11  PROC  NEAR

         CLI            	           ; DISABLE INTERRUPT
         PUSH ES                                 
         PUSH DS                                 
         PUSH DI                                 
         PUSH DX                                 
         PUSH BX                                 
         PUSH AX                                 
         XOR AX,AX                              
         MOV DS,AX                  ; SET DS TO 0000             
         MOV AX,CS                              
         MOV ES,AX                  ; SET ES WITH DS            
         AND DS:BYTE PTR DES0,7FH   ; SET INSERT MODE OFF. 
         MOV AL,DS:[DES1]           ; GET MODE INFO.
         XOR AH,AH                              
         MOV BX,AX                  ; MOVE IT TO BX.    
         CMP AL,07H                 ; IS IT MODE 7 ?    
         JZ LOC27                   ; IF SO JUMP OUT.
         MOV DI,CS:WORD PTR ID1     ; GET THE NUMBER IDENTIFYING THE CONTROLLER.
         SHL DI,1                   ; MULTIPLY BY 2.   
         CALL SR13                  ; SET ATTRIBUTE ADDRESS REGISTER
         CALL CS:[DI+OFFSET MALLOC2]  ; GET INTO THE CORRECT MODE
		                          ; CHANGING ROUTINE.
         CALL SR14                  ; PROTECT ATTRIBUTE REGISTERS. 
LOC27:
         POP AX                                 
         POP BX                                 
         POP DX                                 
         POP DI                                 
         POP DS                                 
         POP ES                                 
         STI	                     ; RESTORE AND RETURN.
         RET
SR11 ENDP

MALLOC2   DW    SR18,SR19,SR20,SR21,SR22,SR23,SR24,SR25,SR26  ; NAMES OF ROUTINES FOR DIFFERENT
                                                              ; VGA CONTROLLERS
          
;--------------------------------------------------------------------------------------------------
; SELECTS PROPER DI FOR THE SELECTED MODE
;--------------------------------------------------------------------------------------------------

SR15 PROC NEAR

        XOR AH,AH                              
        MOV DI,OFFSET TRI2_78       ; DI POINTING TO STARTING ADDRESS OF 
        MOV BX,000FH                ; PAL/NTSC CODES            
        MUL BX                                 
        ADD DI,AX                              
        RET

SR15    ENDP        

;--------------------------------------------------------------------------------------------------
; THIS ROUTINE CHANGES THE APPLICABLE CRT REGISTERS TO TV VALUES.     
; (00H,01H,02H,03H,04H,05H,06H,07H,09H,10H,11H,12H,13H,15H,16H)
;--------------------------------------------------------------------------------------------------

SR16  PROC  NEAR

        MOV DX,DS:[DES3]            ; DES3(ie., 0463) CONTIAINS MONO OR COLOR
                                    ; MODE INFORMATION (03B4 OR 03D4 CRTC REG.)
        MOV AX,0011H                            
        CALL SR7
        MOV BX,0700H                            
        CALL SR17                               
        MOV BX,0909H                            
        CALL SR17                               
        MOV BX,1310H                         
        CALL SR17                               
        MOV BX,1615H                            
        CALL SR17                               
        RET
SR16 ENDP

;--------------------------------------------------------------------------------------------------
; THIS ROUTINE CHANGES CRT REGISTER VALUES.  BL CONTAINS STARTING REGISTER. BH CONTAINS 
; ENDING REGISTER.  DI CONTAINS POINTER TO STARTING VALUE.  DX CONTAINS 03B4 OR 03D4.
;--------------------------------------------------------------------------------------------------

SR17 PROC NEAR

LOC68:  MOV AL,BL                              
        MOV AH,ES:[DI]                            
        INC DI                                 
        CALL SR7                               
        INC BL                                 
        CMP BL,BH                              
        JBE LOC68                               
        RET

SR17 ENDP

;--------------------------------------------------------------------------------------------------
; THIS ROUTINE IS FOR TRIDENT CHIP VERSION LESS THAN 3.
;--------------------------------------------------------------------------------------------------

SR21 PROC NEAR

        CMP DS:BYTE PTR DES1,13H
        JBE LOC41                               
        JMP LOC42                   ; RETURN IF MODE IS ABOVE 13  
LOC41:  MOV AL,CS:[BX+OFFSET MALLOC6]  ; GET DI FOR SELECTED MODE 
        CALL SR15                               
        MOV DX,03C4H                ; RESET THE SEQUENCER SYNCHRONOUSLY & HALT
        MOV AX,0100H                        
        CALL SR7                               
        MOV AX,0901H                ; 8 DOT CLOCKS AND DIVIDE BY 2 DOT CLOCK
        CALL SR7                             
        MOV DX,03CCH                ; SET CLOCK TO BE 28.322 Mhz 
        IN AL,DX                              
        AND AL,23H                               
        OR AL,04H                              
        MOV DX,03C2H                            
        OUT DX,AL                              
        MOV DX,03C4H                ; ALLOW SEQUENCER TO RUN
        MOV AX,0300H                            
        CALL SR7                               
        CALL SR16                   ; CHANGE CONTROLLER REGISTER VALUES
        CMP CS:BYTE PTR ID4,00                 
        JZ LOC42                    ; NO INTERLACE FOR MODES OTHER THAN 0FH,10H,11H,12H
        MOV AL,1EH                         
        CALL SR8                               
        OR AH,04H                              
        CALL SR7                               
LOC42:  RET
SR21  ENDP

MALLOC6   DB  00H,00H,01H,01H,02H,02H,03H,00H,00H,00H,00H,00H,00H,04H,05H,06H,06H,07H,07H,08H

;--------------------------------------------------------------------------------------------------
;THIS ROUTINE IS FOR TRIDENT CHIP WITH VERSION 3 OR MORE.
;--------------------------------------------------------------------------------------------------

SR22  PROC NEAR
        MOV DI,OFFSET MODE_5C                            
        CMP DS:BYTE PTR DES1,5CH    ; SET DI FOR MODE 5C
        JZ LOC43                               
        MOV DI,OFFSET MODE_5D                            
        CMP DS:BYTE PTR DES1,5DH    ; SET DI FOR MODE 5D 
        JZ LOC43                               
        CMP DS:BYTE PTR DES1,13H
        JBE LOC44                               
        JMP LOC45                   ; RETURN IF MODE IS NEITHER,5C OR 5D 
                                    ; OR NOT LESS THAN OR EQUAL TO 13.
LOC44:  MOV AL,CS:[BX+OFFSET MALLOC7]                       
        CALL SR15                   ; GET DI FOR SELECTED MODE
LOC43:  MOV DX,03C4H                            
        MOV AX,0100H                ; RESET THE SEQUENCER AND HALT. 
        CALL SR7                               
        CMP DS:BYTE PTR DES1,13H
        JNB LOC46                               
        MOV AX,0901H                ; SET THE CLOCKING MODE REGISTER FOR 
				                ; DIVIDE BY 2 ALSO IN ADDITION TO 8
				                ; DOT CLOCKS FOR MODES 00,01,04,05,0D
        CALL SR7                               
        CMP DS:BYTE PTR DES1,01H                 
        JBE LOC47                               
        CMP DS:BYTE PTR DES1,04H                 
        JB LOC48                               
        CMP DS:BYTE PTR DES1,05H                 
        JBE LOC47                               
        CMP DS:BYTE PTR DES1,0DH                 
        JZ LOC47                               
        JMP SHORT LOC48                               

LOC46:  MOV AX,0101H                ; SET CLOCKING MODE REGISTER TO 8
        CALL SR7                    ; DOT CLOCKS FOR MODE 13 AND ABOVE.   
LOC47:  MOV AL,0DH                  ; FOR MODES OTHER THAN 02,03,06,0E   
        CALL SR8                    ; 0F,10,11,12 DIVIDE THE CLOCK 
        OR AH,02H                   ; ADDITIONALLY BY 2.               
        CALL SR7                               
LOC48:  MOV AL,2BH                  ; SET SAME CLOCK FOR MODES 5C AND 5D. 
        CMP DS:BYTE PTR DES1,13H                 
        JA LOC49                               
        MOV DX,03CCH                ; FOR MODES 13 AND BELOW SET CLOCK AS 28.322 Mhz
        IN AL,DX                    
        AND AL,23H                              
        OR AL,04H                              
LOC49:  MOV DX,03C2H                ; CHANGE CLOCK FREQ.
        OUT DX,AL                              
        MOV DX,03C4H                ; ALLOW SEQUENCER TO RUN.
        MOV AX,0300H                            
        CALL SR7                               
        CALL SR16                   ; SET CONTROLLER REGISTER VALUES. 
        CMP CS:BYTE PTR ID4,00H
        JZ LOC45                    ; FOR MODES OTHER THAN 0FH,10H,11H,12H RETURN.
        MOV AL,1EH                  ; SET INTERLACE FOR APPLICABLE MODES 
        CALL SR8                               
        OR AH,04H                              
        CALL SR7                               
LOC45:  RET
SR22   ENDP

MALLOC7  DB   09H,09H,01H,01H,0AH,0AH,03H,00H,00H,01H,00H,00H,00H,0BH,05H,06H,06H,07H,07H,08H

;--------------------------------------------------------------------------------------------------
;   ROUTINE FOR REALTEK CHIP
;--------------------------------------------------------------------------------------------------

SR25   PROC   NEAR

        CMP DS:BYTE PTR DES1,13H                 
        JBE LOC62                               
        JMP LOC61                               

LOC62:  MOV AL,CS:[BX+OFFSET MALLOC10]                       
        CALL SR15                               
        MOV DX,03C4H                            
        MOV AX,0100H                            
        CALL SR7                               
        CMP DS:BYTE PTR DES1,13H                 
        JZ LOC60                               
        MOV AX,0901H                            
        CALL SR7                               
        CMP DS:BYTE PTR DES1,01                 
        JBE LOC59                               
        CMP DS:BYTE PTR DES1,04H
        JB LOC58                               
        CMP DS:BYTE PTR DES1,05H
        JBE LOC59                               
        CMP DS:BYTE PTR DES1,0DH                 
        JZ LOC59             
        JMP SHORT LOC58                               

LOC60:  MOV AX,0101H                            
        CALL SR7                               
LOC59:  MOV DX,03CEH                            
        MOV AL,0BH                              
        CALL SR8                               
        OR AH,02H                              
        CALL SR7                               
LOC58:  MOV DX,03CCH                            
        IN AL,DX                              
        AND AL,23H                              
        OR AL,04H                              
        MOV DX,03C2H                            
        OUT DX,AL                              
        MOV DX,03C4H                            
        MOV AX,0300H                            
        CALL SR7                               
        CALL SR16                               
LOC61:  RET
SR25 ENDP

MALLOC10  DB  09H,09H,01H,01H,0AH,0AH,03H,00H,00H,01H,00H,00H,00H,0BH,05H,06H,06H,07H,07H,08H

;--------------------------------------------------------------------------------------------------
;     ROUTINE FOR  TSENGLAB SET 1
;--------------------------------------------------------------------------------------------------

SR19 PROC NEAR

        MOV DI,OFFSET MODE_2E
        CMP DS:BYTE PTR DES1,2EH
        JZ LOC33                               
        CMP DS:BYTE PTR DES1,13H                 
        JBE LOC32
        JMP LOC29                               

LOC32:  MOV AL,CS:[BX+OFFSET MALLOC4]                       
        CALL SR15                           
LOC33:  MOV DX,03C4H
        MOV AX,0100H                            
        CALL SR7                               
        CMP DS:BYTE PTR DES1,13H                 
        JNB LOC31                               
        MOV AX,0901H                  
        CALL SR7                               
        JMP SHORT LOC30                               

LOC31:  MOV DX,DS:[DES3]                          
        MOV AL,11H                              
        CALL SR8                               
        AND AH,7FH                              
        CALL SR7                               
        MOV DX,03C4H      
        MOV AL,07H                              
        CALL SR8                               
        OR AH,40H                              
        CALL SR7                               
        MOV AX,0101H                            
        CALL SR7        
                       
LOC30:  MOV DX,03CCH
        IN AL,DX                              
        AND AL,23H                              
        OR AL,04H                              
        MOV DX,03C2H
        OUT DX,AL                              
        MOV DX,03C4H
        MOV AX,0300H
        CALL SR7                               
        CALL SR16   
        CMP CS:BYTE PTR ID4,00                 
        JZ LOC29
        MOV AL,25H                              
        CALL SR8                               
        OR AH,80H
        CALL SR7 
LOC29:  RET
SR19 ENDP

MALLOC4     DB  00H,00H,01H,01H,02H,02H,03H,00H,00H,00H,00H,00H,00H,04H,05H,0CH,0CH,0DH,0DH,08H

;--------------------------------------------------------------------------------------------------
;   ROUTINE FOR TSENGLAB SET 2
;--------------------------------------------------------------------------------------------------

SR20 PROC NEAR
        MOV DI,OFFSET MD_2E                   
        CMP DS:BYTE PTR DES1,2EH
        JZ LOC34                               
        CMP DS:BYTE PTR DES1,13H                 
        JBE LOC35                               
        JMP LOC36                               
LOC35:  MOV AL,CS:[BX+OFFSET MALLOC5]                       
        CALL SR15                               
LOC34:
        MOV DX,03C4H                            
        MOV AX,0100H                            
        CALL SR7                               
        CMP DS:BYTE PTR DES1,13H
        JNB LOC37                               
        MOV AX,0901H
        CMP DS:BYTE PTR DES1,06H
        JNZ LOC38                               
        MOV AX,0D01H
LOC38:  CALL SR7                               
        JMP SHORT LOC39                               
LOC37:  MOV AX,0101H
        CALL SR7                               
        MOV AL,03H                              
        MOV DX,03BFH                            
        OUT DX,AL                              
        MOV AL,0A0H                              
        MOV DX,03D8H                          
        OUT DX,AL                              
        MOV DX,03C4H                            
        MOV AL,07H                              
        CALL SR8                               
        OR AH,0C0H                              
        CALL SR7                               
LOC39:  MOV DX,03CCH                            
        IN AL,DX
        AND AL,23H                              
        OR AL,04H                              
        MOV DX,03C2H                            
        OUT DX,AL                              
        MOV DX,03C4H                            
        MOV AX,0300H                            
        CALL SR7                               
        CALL SR16                               
        CMP DS:BYTE PTR DES1,06H
        JNZ LOC40                            
        MOV AX,1413H
        CALL SR7                               
LOC40:  CMP CS:BYTE PTR ID4,00                 
        JZ LOC36                               
        MOV AX,8035H                            
        CALL SR7                               
LOC36:  RET
SR20  ENDP

MALLOC5    DB   00H,00H,01H,01H,02H,02H,03H,00H,00H,00H,00H,00H,00H,04H,05H,0EH,0EH,0FH,0FH,08H

;--------------------------------------------------------------------------------------------------
;   ROUTINE FOR CIRRUS CHIP
;--------------------------------------------------------------------------------------------------

SR26 PROC NEAR
        CMP DS:BYTE PTR DES1,13H                 
        JBE LOC63                               
        JMP LOC64                               

LOC63:  MOV AL,CS:[BX+OFFSET MALLOC11]                       
        CALL SR15                               
        MOV DX,03C4H                            
        MOV AX,0100H                            
        CALL SR7                               
        MOV AX,0901H                            
        CALL SR7                               
        MOV DX,03CCH                            
        IN AL,DX                              
        AND AL,23H                              
        MOV DX,03C2H                            
        CMP DS:BYTE PTR DES1,01H                 
        JBE LOC65                               
        CMP DS:BYTE PTR DES1,04H                 
        JB LOC66                               
        CMP DS:BYTE PTR DES1,05H                 
        JBE LOC65                               
        CMP DS:BYTE PTR DES1,0DH                
        JNZ LOC66                               
LOC65:  OUT DX,AL                              
        MOV DX,03C4H                            
        MOV AL,0A4H                              
        CALL SR8                               
        AND AH,0E3H                              
        CALL SR7                               
        JMP SHORT LOC67                               

LOC66:  OR AL,04H                              
        OUT DX,AL                              
LOC67:  MOV DX,03C4H                            
        MOV AX,0300H                            
        CALL SR7                               
        CALL SR16                               
LOC64:  RET
SR26 ENDP

MALLOC11   DB   09H,09H,01H,01H,0AH,0AH,03H,00H,00H,01H,00H,00H,00H,0BH,05H,06H,06H,07H,07H,08H

;--------------------------------------------------------------------------------------------------
; ROUTINE FOR PARADISE/WESTERN CHIP
;--------------------------------------------------------------------------------------------------

SR23 PROC NEAR
        CMP DS:BYTE PTR DES1,13H
        JBE LOC51                               
        JMP LOC50

LOC51:  MOV AL,CS:[BX+OFFSET MALLOC8]                       
        CALL SR15                               
        MOV DX,03C4H                            
        MOV AX,0100H                            
        CALL SR7                               
        MOV AX,0901H                            
        CALL SR7                               
        MOV DX,03CCH                            
        IN AL,DX                              
        AND AL,23H                              
        OR AL,04H                              
        MOV DX,03C2H                            
        OUT DX,AL                              
        MOV DX,03C4H                            
        MOV AX,0300H
        CALL SR7                               
        CALL SR16                               
        CMP CS:BYTE PTR ID4,00H
        JZ LOC50                               
        MOV AX,252CH
        CALL SR7                               
        MOV AX,242DH
        CALL SR7                               
LOC50:  RET
SR23 ENDP

MALLOC8   DB 00H,00H,01H,01H,02H,02H,03H,00H,00H,00H,00H,00H,00H,04H,05H,0CH,0CH,0DH,0DH,08H

;--------------------------------------------------------------------------------------------------
;  ROUTINE FOR OAK CHIP
;--------------------------------------------------------------------------------------------------

SR24  PROC  NEAR

        MOV DI,OFFSET MODE_53                            
        CMP DS:BYTE PTR DES1,53H        
        JZ LOC57                               
        CMP DS:BYTE PTR DES1,13H                 
        JBE LOC56                               
        JMP LOC52                               

LOC56:  MOV AL,CS:[BX+OFFSET MALLOC9]                       
        CALL SR15                               
LOC57:  MOV DX,03C4H                            
        MOV AX,0100H                            
        CALL SR7                               
        MOV AX,0901H                            
        CALL SR7                               
        MOV DX,03CCH                            
        IN AL,DX                              
        AND AL,23H                              
        MOV DX,03C2H                            
        CMP DS:BYTE PTR DES1,01H
        JBE LOC55                               
        CMP DS:BYTE PTR DES1,04H
        JB LOC54                               
        CMP DS:BYTE PTR DES1,05H                 
        JBE LOC55                               
        CMP DS:BYTE PTR DES1,0DH
        JNZ LOC54                               
LOC55:  OUT DX,AL                              
        MOV DX,03DEH                            
        MOV AL,0DH                              
        CALL SR8                               
        OR AH,20H                              
        CALL SR7                               
        JMP SHORT LOC53                               

LOC54:  OR AL,04H                              
        OUT DX,AL                              
LOC53:  MOV DX,03C4H                            
        MOV AX,0300H
        CALL SR7                               
        CALL SR16                               
        CMP CS:BYTE PTR ID4,00                 
        JZ LOC52                               
        MOV DX,03DEH                            
        MOV AX,8014H                            
        CALL SR7                               
        MOV AX,2F15H
        CALL SR7                               
LOC52:  RET
SR24   ENDP

MALLOC9   DB   09H,09H,01H,01H,0AH,0AH,03H,00H,00H,01H,00H,00H,00H,0BH,05H,0CH,0CH,0DH,0DH,08H

;--------------------------------------------------------------------------------------------------
; THIS ROUTINE IS FOR A VGA CHIP OTHER THAN THOSE PERMITTED. NO INTERLACE.
;--------------------------------------------------------------------------------------------------

SR18 PROC NEAR

        CMP DS:BYTE PTR DES1,13H                 
        JA LOC28                    ; NO ACTION FOR MODES ABOVE 13
        MOV AL,CS:[BX+MALLOC3]      ; SET DI FOR SELECTED MODE
        CALL SR15                               
        MOV DX,03C4H                ; RESET SEQUENCER SYNCHRONOUSLY & HALT
        MOV AX,0100H                 
        CALL SR7                               
        MOV AX,0901H                ; 8 DOT CLOCKS AND DOT CLOCK DIVIDED BY 2
                                              
        CALL SR7                               
        MOV DX,03CCH                ; SET CLOCK TO BE 28.322 Mhz 
        IN AL,DX                              
        AND AL,23H                              
        OR AL,04H                              
        MOV DX,03C2H                            
        OUT DX,AL                              
        MOV DX,03C4H                ; ALLOW SEQUENCER TO RUN 
        MOV AX,0300H                            
        CALL SR7                               
        CALL SR16                   ; CHANGE CONTROLLER REGISTER VALUES
LOC28:  RET                                   
SR18 ENDP

MALLOC3       DB     00H,00H,01H,01H,02H,02H,03H,00H,00H,00H,00H,00H,00H,04H,05H,06H,06H,07H,07H,08H

;--------------------------------------------------------------------------------------------------
; SET ATTRIBUTE ADDRESS REGISTER TO 20.  PROTECT THESE REGISTERS.
;--------------------------------------------------------------------------------------------------
	                                   
SR14 PROC NEAR								
        MOV DX,03DAH                            
        IN AL,DX                              
        MOV DX,03BAH                ; READING SETS ATTRIBUTE ADDRESS REGISTER
        IN AL,DX        
        MOV DX,03C0H                            
        MOV AL,20H                              
        OUT DX,AL                              
        RET
SR14 ENDP

;--------------------------------------------------------------------------------------------------
; SET ATTRIBUTE ADDRESS REGISTER TO 00.  REMOVE THE PROTECTION.
;--------------------------------------------------------------------------------------------------

SR13 PROC NEAR	                                   
        MOV DX,03DAH                            
        IN AL,DX                              
        MOV DX,03BAH                ; READING SETS ATTRIBUTE ADDRESS REGISTER
        IN AL,DX                  
        MOV DX,03C0H                            
        MOV AL,00H                              
        OUT DX,AL                              
        RET
SR13 ENDP

;--------------------------------------------------------------------------------------------------
; SET ID3 TO 1 AFTER DISABLING INTERRUPT. TV MODE REPRESENTATION.
;--------------------------------------------------------------------------------------------------
	                         
SR27 PROC NEAR
  
        CLI	                                   
        MOV CS:BYTE PTR ID3,01H
        STI	                                   
        RET
SR27 ENDP

;--------------------------------------------------------------------------------------------------
; SET ID3 TO 0 AND SET TO 400 LINES. NON TV MODE REPRESENTATION.
;--------------------------------------------------------------------------------------------------

SR28 PROC NEAR
        CLI	                                   
        MOV CS:BYTE PTR ID3,00                 
        STI	                                   
        MOV AX,1202H                ; SET TO 400 LINE MODES.
        MOV BL,30H                              
        PUSHF	                                   
        CALL CS:VECSTO3                         
        RET
SR28 ENDP
MALLOC12    DB 1 DUP(0)             ; SETS TO 1 WHEN INT 09H IS BEING EXECUTED
MALLOC12A   DB 2 DUP(0)             ; STORES HRETRACE COUNT
MALLOC12B   DB 2 DUP(0)             ; STORES VRETRACE COUNT
EXALLOC     DB 42H,50H,4CH          ; CODES FOR BPL

;--------------------------------------------------------------------------------------------------
;INT 9 MODIFIED FOR TV CONVERSION.
;--------------------------------------------------------------------------------------------------

ISR9 PROC FAR
        PUSH	DS                                 
        MOV	DS,CS:WORD PTR WORD1 ; SET DS TO 0000 
        TEST	DS:BYTE PTR DES0,08H ; IS ALT  KEY PRESSED ?
        POP	DS                                 
        JNZ	LOC69                               
LOC70:  JMP	CS:VECSTO1           ; IF NO EXECUTE NORMAL INT9 ROUTINE

LOC69:  CMP	CS:BYTE PTR ID2,00   ; ID2=1 IF INT 10 IS BEING EXECUTED
        JNZ	LOC70                            
        CMP	CS:BYTE PTR ID6,00   ; ID6=1 IF WRITE TTY OF INT 10H IS BEING EXECUTED
        JNZ	LOC70                             
        TEST	CS:BYTE PTR MALLOC12,0FFH ; MALLOC12=1 IF INT 9 IS BEING EXECUTED
        JNZ	LOC70                              
        PUSH	BX                                 
        PUSH	AX                                 
        IN	AL,60H               ; IS BACK SPACE KEY PRESSED ?
        CMP	AL,0EH                              
        JZ	LOC71                               
        XOR	BX,BX                              
        CMP	AL,16H               ; IS 'U' KEY PRESSED ?  
        JZ	LOC72                   
        INC	BX                                 
        CMP	AL,20H               ; IS 'D' KEY PRESSED ? 
        JZ	LOC72                           
        INC	BX                                 
        CMP	AL,26H               ; IS 'L' KEY PRESSED ? 
        JZ	LOC72                               
        INC	BX                                 
        CMP	AL,13H               ; IS 'R' KEY PRESSED? 
        JZ	LOC72                         
LOC73:  POP	AX                                 
        POP	BX                                 
        JMP	LOC70                    
LOC72:
;--------------------------------------------------------------------------------------------------
; ROUTINE TO SHIFT THE SCREEN UP/DOWN/LEFT/RIGHT DEPENDING ON THE KEY PRESSED 
;--------------------------------------------------------------------------------------------------
        TEST	CS:BYTE PTR ID3,0FFH ; NO ACTIVITY IN NORMAL MODE
        JZ	LOC73                               
        CALL	SR30                               
        MOV	CS:BYTE PTR MALLOC12,01H   ; IDENTIFICATION FOR BACKSPACE OR OTHER U,D,L,R,
                                          ; KEY INFO GOING ON.
        PUSH	DS                                 
        PUSH	DX                                 
        PUSH	CX                                 
        MOV	DS,CS:WORD PTR WORD1       ; SET DS TO 0000.     
        MOV	DX,DS:[DES3]                          
        MOV	CX,0001H
        TEST	BX,0001H                            
        JZ	LOC74                               
        NEG	CX                   ; NEGATE CX TO BX NOT EQUAL TO 0 OR 2 
LOC74:  CALL	SR29                 ; UNLOCK CRTC REGISTERS.      
        SHL	BX,1                 ; MULTIPLY CONTENTS OF BX BY 2 FOR ADDRESS MODIFICATION
        CALL	CS:[BX+OFFSET MALLOC13]   ; PROCEEDS WITH SCREEN SHIFT  UP/DOWN ROUTINE
	                                    ; OR LEFT/RIGHT ROUTINE                          
        MOV	CS:BYTE PTR MALLOC12,00H  ; RESET FLAG FOR COMPLETION OF ACTIVITY
        POP	CX                               
        POP	DX                                 
        POP	DS                                 
        POP	AX                                 
        POP	BX                                 
        IRET    
	         
MALLOC13       DW   SR32,SR32,SR33,SR33  ; SR32 --> UP/DOWN SCREEN SHIFT ROUTINE
                                         ; SR33 --> LEFT/RIGHT SCREEN SHIFT ROUTINE

LOC71:
;--------------------------------------------------------------------------------------------------
;ROUTINE FOR ALT_BACKSPACE
;--------------------------------------------------------------------------------------------------

        MOV	CS:BYTE PTR MALLOC12,01H  ; SET IDENTIFICATION FOR INT 09 ACTIVITY GOING ON
        CALL	SR30                               
        PUSH	ES                                 
        PUSH	DS                                 
        PUSH	SI                                 
        PUSH	DI                                 
        PUSH	DX                                 
        PUSH	CX                                 
        MOV	AX,CS                              
        MOV	ES,AX                              
        MOV	DX,OFFSET MEMVAR          ; SAVE MOUSE DRIVER STATE.
        MOV	AX,0016H                            
        INT    33H                                 
        XOR	CS:BYTE PTR ID3,01H                 
        CMP	CS:BYTE PTR ID3,00H                 
        JZ	LOC76                               
        CALL	SR27                      ; SET ID3 TO 1. TV STATE.
        JMP SHORT LOC77                               

LOC76:  CALL	SR28                      ; SET ID3 TO 0. NORMAL STATE.
LOC77:  XOR	AX,AX                              
        MOV	DS,AX                     ; DS SET TO 0000   
        MOV	SI,044EH                            
        MOV	AX,CS                     ; ES SET TO DS                  
        MOV	ES,AX                              
        MOV	DI,OFFSET MALLOC14 
        MOV	CX,0012H                  ; STORE 18 BYTES AT LOCATION POINTED BY MALLOC14 
                                             
        REPZ	 MOVSB                    
                                           
        MOV	SI,DES4                  ; STORE CURRENT VIDEO PAGE     
        MOVSB	                                   
        MOV	SI,DES5                  ; STORE MODE OF DISPLAY/COLOR OR MONO
        MOVSB	                                   
        MOV	DX,DS:[DES3]             ; CRTC REG 03B4 OR 03D4 (MONO/COLOR)
        MOV	AL,0EH                   ; STORE CURSOR LOCATION HIGH
        CALL	SR8                               
        MOV     CS:WORD PTR IDE1,AX     ; INFORMATION AT IDE1 ALONG WITH INDEX
        MOV	AL,0FH
        CALL	SR8                      ; STORE CURSOR LOCATION LOW INFORMATION
        MOV	CS:WORD PTR IDE2,AX      ; AT IDE2 ALONG WITH INDEX       
        MOV	AL,18H                              
        CALL	SR8                      ; STORE LINE COMPARE REGISTER INFORMATION
        MOV	CS:WORD PTR IDE3,AX      ; AT IDE3 ALONG WITH INDEX
        MOV	AL,DS:[DES2]                          
        AND	AL,08H                              
        PUSH	AX                       
        OR	DS:BYTE PTR DES2,08H                 
        MOV	AL,DS:[DES1]             ; DO NOT CLEAR THE BUFFER WHEN CHANGING THE MODE
        OR	AL,80H                   
        XOR	AH,AH                              
        INT	10H                                 
        POP	AX                                 
        AND	DS:BYTE PTR DES2,0F7H    ; RESTORE THE CONTENTS OF DES2
        OR      DS:BYTE PTR DES2,AL                   
        MOV	DX,DS:[DES3]                          
        MOV	AX,CS:WORD PTR IDE3      ; RESTORE LINE COMPARE REGISTER.
        CALL	SR7                               
        MOV	AX,CS:WORD PTR IDE2      ; RESTORE CURSOR LOCATION HIGH.
        CALL	SR7                               
        MOV	AX,CS:WORD PTR IDE1      ; RESTORE CURSOR LOCATION LOW.
        CALL	SR7                                
LOC96:  MOV	AX,CS                    ; RESTORE PREVIOUSLY STORED VALUES.
        MOV	DS,AX                              
        MOV	SI,OFFSET MALLOC14
        XOR	AX,AX                              
        MOV	ES,AX                              
        MOV	DI,044EH                 
        MOV	CX,0012H                            
        REPZ	MOVSB                                   
        MOV	DI,0462H                            
        MOVSB	                                   
        MOV	DI,0487H
        MOVSB	                                   
LOC94:  MOV	AX,CS                              
        MOV	ES,AX                              
        MOV	DX,OFFSET MEMVAR         ; RESTORE MOUSE DRIVER STATE.
        MOV	AX,0017H                            
        INT	33H                                 
        MOV	CS:BYTE PTR MALLOC12,00                 
LOC95:  POP	CX                                 
        POP	DX                                 
        POP	DI                                 
        POP	SI                                 
        POP	DS                                 
        POP	ES                                 
        POP	AX                                 
        POP	BX                                 
        IRET
ISR9 ENDP

MALLOC14   DB    20 DUP(0)
IDE1       DW    1 DUP(0)
IDE2       DW    1 DUP(0)
IDE3       DW    1 DUP(0)
MALLOC     DB    4 DUP(0)

SR30 PROC NEAR

        IN AL,61H                              
        MOV AH,AL                              
        OR AL,80H                              
        OUT 61H,AL                              
        XCHG AL,AH                              
        OUT 61H,AL                              
        MOV AL,20H                              
        OUT 20H,AL                              

        RET
SR30 ENDP

;--------------------------------------------------------------------------------------------------
;   ENABLE CRTC REGISTERS.
;--------------------------------------------------------------------------------------------------

SR29 PROC NEAR	                                   
        MOV	AL,11H
        CALL	SR8                               
        AND	AH,7FH                   ; ENABLE CRTC REGISTERS.
        CALL	SR7                               
        MOV	AL,03H                   ; SET MSB OF 3C5.03 TO 1.     
        CALL	SR8                               
        OR	AH,80H                              
        CALL	SR7                               
        RET
SR29 ENDP

;--------------------------------------------------------------------------------------------------
;   DISABLE CRTC REGISTERS.
;--------------------------------------------------------------------------------------------------

SR31 PROC NEAR
        MOV	AL,11H                              
        CALL	SR8                               
        OR	AH,80H                   ; SET MSB OF 3C5.11 TO 1
        CALL	SR7                               
        RET
SR31 ENDP

;--------------------------------------------------------------------------------------------------
; ROUTINE FOR UP/DOWN SHIFTING OF SCREEN.
;--------------------------------------------------------------------------------------------------
	            
SR32 PROC NEAR			                         
        MOV	AL,10H                              
        CALL	SR8                               
        XOR	BH,BH                    ; SAVE CONTENTS OF V RETRACE.
        MOV	BL,AH                    ; START REGISTER IN BL.
                                        ; MSB'S ARE IN OVERFLOW REGISTER. 
        MOV	AL,07H                              
        CALL	SR8                               
        TEST	AH,04H                              
        JZ	LOC78                               
        OR	BH,10H                              
LOC78:  TEST	AH,80H                              
        JZ	LOC79                               
        OR	BH,20H                   ; SAVE THE MOST SIGNIFICANT 2 BITS IN BH.
LOC79:  ADD	BX,CX                    ; MODIFY THE CONTENTS.
        AND	AH,7BH                              
        TEST	BH,20H                              
        JZ	LOC80                               
        OR	AH,80H                              
LOC80:  TEST	BH,10H                              
        JZ	LOC81                               
        OR	AH,04H                   ; COLLECT THE MSB'S IN AH.        
LOC81:  OR	CX,CX                    ; TOP OR BOTTOM.    
        JS	LOC82                               
        TEST	CS:WORD PTR MALLOC12B,8000H    ; CHECK MSB OF MALLOC12B FOR 0
        JZ	LOC83                    ; IF SO CHECK FOR LIMIT.
                                        ; OTHERWISE MODIFY.
        ADD	CS:WORD PTR MALLOC12B,CX                          
        JMP     SHORT LOC84                              
                
LOC83:  CMP	CS:WORD PTR MALLOC12B,20H      ; +20 IS THE POSITIVE LIMIT
        JA	LOC85
        ADD	CS:WORD PTR MALLOC12B,CX       ; OTHERWISE INCREMENT.
        JMP     SHORT LOC84                               
                

                        	            ;CHECK FOR MSB OF MALLOC12 FOR NOT_ZERO
LOC82:  TEST	CS:WORD PTR MALLOC12B,8000H    ; IF YES CHECK FOR LIMIT.       
        JNZ	LOC86                               
        ADD	CS:WORD PTR MALLOC12B,CX       ; OTHER WISE MODIFY.
        JMP	SHORT LOC84                               


LOC86:  CMP	CS:WORD PTR MALLOC12B,-0BH     ; -0B IS THE NEGATIVE LIMIT
        JB	LOC85                          ; OTHERWISE MODIFY.
        ADD	CS:WORD PTR MALLOC12B,CX                          
LOC84:  CALL	SR7                            ; SEND MODIFIED BITS TO OVERFLOW REGISTER
        MOV	AL,10H                              
        MOV	AH,BL                          ; MODIFY BITS OF V RETRACE START REGISTER
        CALL	SR7                           
LOC85:  RET
SR32 ENDP

;--------------------------------------------------------------------------------------------------
; ROUTINE  FOR LEFT/RIGHT SCREEN SHIFT
;--------------------------------------------------------------------------------------------------

SR33 PROC NEAR	                                   
        MOV	AL,04H                              
        CALL	SR8                               
        XOR	BH,BH                              
        MOV	BL,AH                              
        ADD	BX,CX                              
        MOV	AH,BL                              
        OR	CX,CX                              
        JS	LOC87                       
        TEST	CS:WORD PTR MALLOC12A,8000H               
        JZ	LOC88                              
        ADD	CS:WORD PTR MALLOC12A,CX                          
        JMP    SHORT LOC89                               
LOC88:  CMP	CS:WORD PTR MALLOC12A,08H           ;LIMITS.
        JA	LOC90                               
        ADD	CS:WORD PTR MALLOC12A,CX                          
        JMP    SHORT LOC89                               
LOC87:  TEST	CS:WORD PTR MALLOC12A,8000H               
        JNZ	LOC91                               
        ADD	CS:WORD PTR MALLOC12A,CX                          
        JMP	SHORT LOC89                               
LOC91:  CMP	CS:WORD PTR MALLOC12A,-05H          ;LIMITS.       
        JB	LOC90                               
        ADD	CS:WORD PTR MALLOC12A,CX                          
LOC89:  CALL	SR7                               
LOC90:  RET
SR33 ENDP

TRI2_78  DB  6BH,27H,28H,8EH,5BH,83H,04H,11H,47H,0E1H,19H,0C7H,14H,0DEH,0EBH
TRI2_23  DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,47H,0E1H,19H,0C7H,28H,0DEH,0EBH
TSE_45   DB  6BH,27H,28H,8EH,5BH,83H,04H,11H,41H,0E1H,19H,0C7H,14H,0DEH,0EBH
TRI2_6   DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,41H,0E1H,19H,0C7H,28H,0DEH,0EBH
TSE_0D   DB  6BH,27H,28H,8EH,5BH,83H,04H,11H,40H,0E1H,19H,0C7H,14H,0DEH,0EBH
TRI2_0E  DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0E1H,19H,0C7H,28H,0DEH,0EBH
TRI2_F   DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0D4H,1CH,0AEH,50H,0CEH,0DEH
TRI2_11  DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0F5H,1DH,0EFH,50H,0F3H,02H
TRI2_13  DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0E1H,99H,0C7H,28H,0DEH,0EBH
TRI2_01  DB  33H,27H,28H,95H,2FH,0B3H,04H,11H,47H,0E1H,0BH,0C7H,14H,0D2H,0DEH
TRI2_45  DB  33H,27H,28H,95H,2FH,93H,04H,11H,41H,0E1H,0BH,0C7H,14H,0D2H,0DEH
TRI2_0D  DB  33H,27H,28H,95H,2FH,93H,04H,11H,40H,0E1H,0BH,0C7H,14H,0D2H,0DEH
PARAD_10 DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0D4H,1CH,0AEH,28H,0CEH,0DEH
PARAD_11 DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0FAH,12H,0EFH,28H,0F5H,04H
TSE2_10  DB  6BH,4FH,50H,8EH,5BH,83H,04H,0FFH,40H,0D4H,1CH,0AEH,28H,0FFH,0FFH
TSE2_11  DB  6BH,4FH,50H,8EH,5BH,83H,04H,0FFH,40H,0FAH,12H,0EFH,28H,0F5H,0FFH
MODE_2E  DB  6CH,4FH,50H,8EH,5BH,83H,36H,1DH,40H,0FFH,01H,0EFH,28H,0F6H,01H
MD_2E    DB  6CH,4FH,50H,8EH,5BH,83H,48H,3EH,40H,0EBH,0CH,0DFH,50H,0E7H,04H
MODE_5C  DB  0C3H,9FH,0A1H,8CH,0A6H,94H,04H,11H,40H,0E1H,0BH,0C7H,0A0H,0DEH,0EBH
MODE_5D  DB 0C3H,9FH,0A1H,8CH,0A6H,94H,04H,11H,40H,0F5H,1DH,0EFH,0A0H,0F3H,02H
MODE_53  DB  6BH,4FH,50H,8EH,5AH,83H,36H,1DH,40H,0FH,17H,0EFH,28H,0F6H,01

;--------------------------------------------------------------------------------------------------
; CODES FOR DIFFERENT MODES OF NTSC TV
;--------------------------------------------------------------------------------------------------

NTSCODE  DB  6BH,27H,28H,8EH,5BH,83H,04H,11H,47H,0E1H,19H,0C7H,14H,0DEH,0EBH
         DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,47H,0E1H,19H,0C7H,28H,0DEH,0EBH
         DB  6BH,27H,28H,8EH,5BH,83H,04H,11H,41H,0E1H,19H,0C7H,14H,0DEH,0EBH
         DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,41H,0E1H,19H,0C7H,28H,0DEH,0EBH
         DB  6BH,27H,28H,8EH,5BH,83H,04H,11H,40H,0E1H,19H,0C7H,14H,0DEH,0EBH
         DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0E1H,19H,0C7H,28H,0DEH,0EBH
         DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0D4H,1CH,0AEH,50H,0CEH,0DEH
         DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0F5H,1DH,0EFH,50H,0F3H,02H
         DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0E1H,99H,0C7H,28H,0DEH,0EBH
         DB  33H,27H,28H,95H,2FH,0B3H,04H,11H,47H,0E1H,0BH,0C7H,14H,0D2H,0DEH
         DB  33H,27H,28H,95H,2FH,93H,04H,11H,41H,0E1H,0BH,0C7H,14H,0D2H,0DEH
         DB  33H,27H,28H,95H,2FH,93H,04H,11H,40H,0E1H,0BH,0C7H,14H,0D2H,0DEH
         DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0D4H,1CH,0AEH,28H,0CEH,0DEH
         DB  6BH,4FH,50H,8EH,5BH,83H,04H,11H,40H,0FAH,12H,0EFH,28H,0F5H,04H
         DB  6BH,4FH,50H,8EH,5BH,83H,04H,0FFH,40H,0D4H,1CH,0AEH,28H,0FFH,0FFH
         DB  6BH,4FH,50H,8EH,5BH,83H,04H,0FFH,40H,0FAH,12H,0EFH,28H,0F5H,0FFH
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,1DH,40H,0FFH,01H,0EFH,28H,0F6H,01H
         DB  6CH,4FH,50H,8EH,5BH,83H,48H,3EH,40H,0EBH,0CH,0DFH,50H,0E7H,04H
         DB  0C3H,9FH,0A1H,8CH,0A6H,94H,04H,11H,40H,0E1H,0BH,0C7H,0A0H,0DEH,0EBH
         DB 0C3H,9FH,0A1H,8CH,0A6H,94H,04H,11H,40H,0F5H,1DH,0EFH,0A0H,0F3H,02H
         DB  6BH,4FH,50H,8EH,5AH,83H,36H,1DH,40H,0FH,17H,0EFH,28H,0F6H,01

;--------------------------------------------------------------------------------------------------
; CODES FOR DIFFERENT MODES OF PAL TV
;--------------------------------------------------------------------------------------------------

PALCODE DB  6CH,27H,28H,8EH,5BH,83H,36H,11H,47H,0FBH,13H,0C7H,14H,0F8H,5
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,11H,47H,0FBH,13H,0C7H,28H,0F8H,5
         DB  6CH,27H,28H,8EH,5BH,83H,36H,11H,41H,0FBH,13H,0C7H,14H,0F8H,5
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,11H,41H,0FBH,13H,0C7H,28H,0F8H,5
         DB  6CH,27H,28H,8EH,5BH,83H,36H,11H,40H,0FBH,13H,0C7H,14H,0F8H,5
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,11H,40H,0FBH,13H,0C7H,28H,0F8H,5
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,11H,40H,0F1H,19H,0AEH,50H,0EBH,0FBH
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,1DH,40H,0FH,17H,0EFH,50H,0AH,19H
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,11H,40H,0FBH,93H,0C7H,28H,0F8H,5
         DB  34H,27H,28H,95H,2FH,0B3H,36H,11H,47H,0FBH,5,0C7H,14H,0DAH,0E6H
         DB  34H,27H,28H,95H,2FH,93H,36H,11H,41H,0FBH,5,0C7H,14H,0DAH,0E6H
         DB  34H,27H,28H,95H,2FH,93H,36H,11H,40H,0FBH,5,0C7H,14H,0DAH,0E6H
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,11H,40H,0F1H,19H,0AEH,28H,0EBH,0FBH
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,1DH,40H,0FH,17H,0EFH,28H,0AH,19H
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,1DH,40H,0F1H,19H,0AEH,28H,0B3H,7
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,1DH,40H,0FH,17H,0EFH,28H,0AH,4
         DB  6CH,4FH,50H,8EH,5BH,83H,36H,1DH,40H,0FFH,1,0EFH,28H,0F6H,1
         DB  6CH,4FH,50H,8EH,5BH,83H,48H,3EH,40H,0EBH,0CH,0DFH,50H,0E7H,4
         DB  0C6H,9FH,0A1H,8CH,0A6H,94H,36H,11H,40H,0FDH,07H,0C7H,0A0H,0CFH,0DBH
         DB  0C6H,9FH,0A1H,8CH,0A6H,94H,36H,15H,40H,10H,08H,0EFH,0A0H,0F6H,1
         DB  6BH,4FH,50H,8EH,5AH,83H,36H,1DH,40H,0FH,17H,0EFH,28H,0F6H,1

MEMVAR DW 400 DUP(0)
CODE ENDS
END START
         

   
  