;------------------------------------------------------------------------
;     Extended Character Set (VGA)                            release 1.0
;     Copyright (c) Ingo Eickmann, 1989                          07/09/89
;------------------------------------------------------------------------
;     Assemblieren mit MASM 5.x :                      I. Eickmann
;            MASM Zeichen2;                            Im Leuchterbruch 8
;     Getestet unter MS-DOS 3.3, Turbo Pascal V4.0     5000 K”ln 80
;------------------------------------------------------------------------
      PAGE  65,80
      TITLE Extended Character Set (VGA)

Sequencer  equ 3C4h                   ; Adresse des Sequencer
GraphicsC  equ 3CEh                   ; Adresse des Graphic Controller
Scanlines  equ 16                     ; Scanlines/Char (EGA: 14)

if1
   Port_out macro low,high            ; Index und Daten in Port dx schreiben
      mov al,low
      mov ah,high
      out dx,ax
   endm
endif

code segment word public 'CODE'       ; MS-C: Segmentname code in _TEXT „ndern
     assume cs:code

public ExtCharInit                    ; MS-C: Name in _ExtCharInit „ndern

ExtCharInit proc far
         push es
         push si
         push di
         cli                          ; Map 2 fr sequentiellen Zugriff
         mov dx,Sequencer             ; bereitstellen
         Port_out 0,1                 ; Sync. reset
         Port_out 2,100b              ; CPU beschreibt Map 2
         Port_out 3,4         ; ====>   Map Select Register: Zeichensatz B auf
                                      ; Table 1 setzen
         Port_out 4,7                 ; Sequential Addressing
         Port_out 0,3                 ; Clear Sync. reset
         sti
         mov dx,GraphicsC
         Port_out 4,10b               ; CPU liest Map 2
         Port_out 5,0                 ; Sequential Addressing
         Port_out 6,1100b             ; Miscellaneous Register
;------------------------------------------------------------------------
         mov ax,0B800h                ; Beispiel: 2. Character Set um 180ø
         mov es,ax                    ;                            gedreht
         mov bx,255*32                ;    (256 Characters - 1) * 32 Bytes
Lop2:    mov si,0
         mov di,Scanlines - 1
Lop1:    mov al,es:[si+bx]            ;    Scanline aus 1. CharSet holen
         mov cx,8                     ;    8 Bits/Byte spiegeln
Lop3:    shr al,1
         rcl ah,1
         loop Lop3
         mov es:[di+bx+4000h],ah      ;    Scanline in 2. CharSet ablegen
         inc si
         dec di
         jnl Lop1                     ;    n„chste Scanline
         sub bx,32
         jnl Lop2                     ;    n„chster Character
;------------------------------------------------------------------------
         cli                          ; Anwahl der Maps 0 und 1 im Odd/Even-
         mov dx,Sequencer             ; Mode wiederherstellen
         Port_out 0,1                 ; Sync. reset
         Port_out 2,011b              ; CPU beschreibt Map 0 and 1
         Port_out 4,11b               ; Odd/Even Addressing
         Port_out 0,3                 ; Clear Sync. reset
         sti
         mov dx,GraphicsC
         Port_out 4,0                 ; CPU liest Map 0 und 1
         Port_out 5,10h               ; Odd/Even Addressing
         Port_out 6,1110b             ; Miscellaneous Register

         mov ax,1000h                 ; Unterdrckung des Intensity-Bits
         mov bx,0712h                 ; durch Color Plane Enable Register,
         int 10h                      ; kann entfallen

         pop di
         pop si
         pop es
         ret
ExtCharInit endp

code ends
     end
