home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1989 / 10 / grdlagen / cga.asm next >
Encoding:
Assembly Source File  |  1989-07-13  |  9.9 KB  |  329 lines

  1. ;* ------------------------------------------------------ *
  2. ;*                      CGA.ASM                           *
  3. ;*          CGA-Emulator für Herculeskarten               *
  4. ;*       (c) 1989 Peter Plucinski  &  TOOLBOX             *
  5. ;* ------------------------------------------------------ *
  6. cseg      segment 'code'
  7.           assume cs:cseg, ds:cseg;
  8.  
  9.           org 100h
  10.  
  11. LF        equ  0ah           ; Linefeed
  12. CR        equ  0dh           ; Return
  13. Equip     equ  10h           ; Equipment-Bytes
  14. Video     equ  10h           ; Video-Interrupt
  15. Boot      equ  19h           ; Bootstrap
  16. Dos       equ  21h           ; Dos-Interrupt
  17. Index     equ  3b4h          ; 6845 Index Register
  18. Mode      equ  3b8h          ; 6845 Display Mode Ctrl Port
  19. Config    equ  3bfh          ; 6845 Configuration Switch
  20.  
  21. main:     jmp init
  22.  
  23. Vec10     dd   ?             ; alter INT-10 Vektor
  24. tab       dw   offset tab200 ; 6845 Parametertabelle
  25.  
  26. ;* ------------------------------------------------------- *
  27. ;*   Neue Interrupt 10 Routine                             *
  28. ;* ------------------------------------------------------- *
  29. NewINT10: push ax            ; Register sichern
  30.           push bx            ;         "
  31.           push cx            ;         "
  32.           push dx            ;         "
  33.           push ds            ;         "
  34.           or   ah, ah        ; ah = 0 ?
  35.           jnz  OldINT        ; nein -> alte Int-Routine
  36.           cmp  al, 7         ; al >= 7 ?
  37.           jge  OldINT        ; ja -> alte Int-Routine
  38.           cmp  al, 3         ; Textmodus (0..3)?
  39.           jg   gr            ; nein -> Grafik einschalten
  40.           mov  ax, 40h       ; Equipment ändern
  41.           mov  ds, ax
  42.           or   word ptr ds:[Equip], 30h
  43.           jmp  OldINT
  44.  
  45. gr:       call graphic
  46.  
  47. OldINT:   pop  ds
  48.           pop  dx
  49.           pop  cx
  50.           pop  bx
  51.           pop  ax
  52.           jmp  cs:[Vec10]    ; alte Int-10 Routine
  53.  
  54. ;* ------------------------------------------------------- *
  55. ;*   Grafik einschalten (640*200)                          *
  56. ;* ------------------------------------------------------- *
  57. graphic:  push ds
  58.           mov  ax, 40h
  59.           mov  ds, ax
  60.           and  ds:[Equip], 0ffcfh
  61.           or   word ptr ds:[Equip], 20h
  62.           mov  ax, Mode
  63.           mov  ds:[63h], ax
  64.  
  65. ;* - 6845 neu programmieren ------------------------------ *
  66.  
  67.           mov  dx, Index
  68.           mov  bx, word ptr cs:[tab]
  69.           mov  cx, 12
  70.           mov  ah, 0
  71. InitGr:   mov  al, ah        ; al = 0..12
  72.           out  dx, al
  73.           inc  dx
  74.           mov  al, cs:[bx]
  75.           out  dx, al        ; 3b5 = 6845 Datenregister
  76.           inc  ah
  77.           inc  bx
  78.           dec  dx
  79.           loop InitGr
  80.  
  81.           mov  dx, Config    ; 6845 Konfiguration
  82.           mov  al, 3         ; Grafik, Seite 1
  83.           out  dx, al
  84.           mov  dx, Mode      ; 6845 Modus ändern
  85.           mov  al, 8ah       ; Seite 1, Bildschirm
  86.  
  87. ;* - aktivieren, Grafikmodus ----------------------------- *
  88.  
  89.           out  dx, al
  90.           pop  ds
  91.           ret
  92.  
  93. ;* ------------------------------------------------------- *
  94. ;*   6845 Parametertabelle                                 *
  95. ;* ------------------------------------------------------- *
  96.  
  97. ;* - Tabelle für 200 und 300 Zeilen ---------------------- *
  98.  
  99. tab200:   db   36h    ; Gesamtzahl der Zeichen pro Zeile-1
  100.           db   28h    ; Anzahl der sichtbaren Zeichen
  101.           db   2dh    ; Position-1 des ersten Zeichens
  102.                       ; während HSYNC
  103.           db   08h    ; Anzahl Zeichen während HSYNC
  104.           db   7fh    ; Anzahl Zeilen-1
  105.           db   1fh    ; Anzahl Zeilendurchläufe zusätzlich
  106.           db   64h    ; Anzahl der sichtbaren Zeilen
  107.           db   72h    ; Zeilennummer-1 für VSYNC
  108.           db   02h    ; (immer 2)
  109.  
  110. lines:    db   01h    ; Durchläufe/Zeile-1
  111.           db   06h    ; Cursorstart
  112.           db   07h    ; Cursorende
  113.  
  114. ;* - Tabelle für 400 Zeilen ------------------------------ *
  115.  
  116. tab400:   db   6ah, 28h, 2bh, 07h, 67h, 0ah, 64h, 67h, 01h
  117.           db   01h, 06h, 07h
  118.  
  119. EndOfResident:
  120.  
  121. ;* ------------------------------------------------------- *
  122. ;*   Initialisierung, nichtresidenter Teil                 *
  123. ;* ------------------------------------------------------- *
  124. init:                        ; alten int10 Vektor sichern
  125.           mov  ax, 3510h
  126.           int  Dos
  127.           mov  word ptr cs:[Vec10], bx
  128.           mov  word ptr cs:[Vec10+2], es
  129.  
  130. ;* - prüfen, ob bereits resident ------------------------- *
  131.  
  132.           call GraphMode     ; Grafikmodus 6 einschalten
  133.           mov  ah, 0fh       ; ist Grafik eingeschaltet?
  134.           int  Video
  135.           cmp  al, 7         ; nein, wenn al = 7
  136.           je   NotRes
  137.           mov  cs:[ResFlag], 1
  138.  
  139. NotRes:   mov  ax, 2         ; Textmodus einschalten
  140.           int  Video
  141.  
  142. ;* - Parameter prüfen ------------------------------------ *
  143.  
  144.           mov  bx, 80h
  145.           xor  ch, ch
  146.           mov  cl, cs:[bx]   ; Anzahl Parameter
  147.           jcxz NoPara        ; 0 = kein Parameter
  148.  
  149. skipsp:   inc  bx            ; Space überspringen
  150.           cmp  byte ptr cs:[bx], 20h
  151.           je   skipsp
  152.  
  153.           mov  ah, cs:[bx]   ; Parameter holen
  154.           cmp  ah, '?'       ; = '?' ?
  155.           jne  l0            ; nein -> weiter
  156.           call Help          ; Hilfe ausgeben
  157.           jmp  Exit3         ; -> Ende
  158. l0:       cmp  ah, '2'       ; = 2 ?
  159.           jne  l1            ; nein -> weiter
  160.           call Update        ; neue Werte speichern
  161.           jmp  Next          ; nächster Parameter
  162. l1:       cmp  ah, '3'       ; = 3 ?
  163.           jne  l2            ; nein -> weiter
  164.           call Ln300         ; auf 300 Zeilen umschalten
  165.           jmp  Next          ; nächsten Parameter
  166. l2:       cmp  ah, '4'       ; = 4 ?
  167.           jne  l3            ; nein -> weiter
  168.           call Ln400         ; auf 400 Zeilen umschalten
  169.           jmp  Next          ; nächsten Parameter
  170. l3:       and  ah, 0dfh      ; in Großbuchstaben umwandeln
  171.           cmp  ah, 'G'       ; = G ?
  172.           jne  Next          ; nächster Parameter
  173.           push bx            ; bx und cx sichern
  174.           push cx
  175.           call graphic       ; Hercules umprogrammieren
  176.           call graphmode     ; Grafikmodus 6 einschalten
  177.           pop  cx            ; bx und cx holen
  178.           pop  bx
  179.           jmp  Next          ; nächsten Parameter
  180.  
  181. Next:     loop skipsp        ; cl <> 0 -> weitere Parameter
  182.  
  183. NoPara:
  184. Exit1:    call StartMsg
  185.           mov  ah, cs:[ResFlag]
  186.           or   ah, ah
  187.           jnz  Exit2
  188.  
  189. ;* - neuen int10 Vektor setzen --------------------------- *
  190.  
  191.           mov  ax, 2510h
  192.           mov  dx, offset NewINT10
  193.           int  Dos
  194.  
  195. ;* - Meldung ausgeben ------------------------------------ *
  196.  
  197.           mov  dx, offset ResMsg
  198.           call PrintMsg
  199.  
  200. ;* - Programm resident machen ---------------------------- *
  201.  
  202.           mov  dx, offset EndOfResident
  203.           int  27h
  204.  
  205. Exit2:    mov  dx, offset UpMsg
  206.           call PrintMsg
  207. Exit3:    ret
  208.  
  209. ;* - Grafikmodus 6 einschalten (640*200) ----------------- *
  210.  
  211. GraphMode proc near
  212.  
  213.           mov  ax, 6
  214.           int  Video
  215.           ret
  216.  
  217. GraphMode endp
  218.  
  219. ;* - Umschalten auf 300 Zeilen --------------------------- *
  220.  
  221. Ln300     proc near
  222.           push bx            ; bx und cx sichern
  223.           push cx
  224.           mov  ax, offset tab200
  225.           mov  word ptr cs:[tab],ax
  226.  
  227.           mov  ah, 2         ; Tabelle ändern
  228.  
  229.           mov  byte ptr cs:[lines],ah
  230.  
  231. ;* - Bereich b800:4000 bis b800:7fff löschen ------------- *
  232.  
  233.           mov  cx, 4000h     ; Anzahl Bytes
  234.           mov  ax, 0bc00h    ; Startsegment
  235.           mov  es, ax
  236.           xor  ax, ax
  237.           xor  di, di
  238.           cld
  239.           rep  stosw         ; löschen
  240.           pop  cx            ; bx und cx holen
  241.           pop  bx
  242.           call Update
  243.           ret
  244.  
  245. Ln300     endp
  246.  
  247. ;* - Umschalten auf 400 Zeilen --------------------------- *
  248.  
  249. Ln400     proc near
  250.  
  251.           mov  ax, offset tab400
  252.           mov  word ptr cs:[tab],ax
  253.           call Update
  254.           ret
  255.  
  256. Ln400     endp
  257.  
  258. ;* - Werte im residenten Programm ändern ----------------- *
  259.  
  260. Update    proc near
  261.  
  262.           mov  ah, cs:[ResFlag]
  263.           or   ah, ah
  264.           jz   NoUpd
  265.           mov  ds, word ptr cs:[vec10+2]
  266.           mov  ax, word ptr cs:[tab]      ; Parametertabelle
  267.           mov  word ptr ds:[tab],ax
  268.           mov  ah, byte ptr cs:[lines]    ; Anzahl Zeilen
  269.           mov  byte ptr ds:[lines],ah
  270. NoUpd:    ret
  271.  
  272. Update    endp
  273.  
  274. ;* - Startmeldung ausgeben ------------------------------- *
  275.  
  276. StartMsg  proc near
  277.  
  278.           mov  dx, offset msg
  279.           call PrintMsg
  280.           ret
  281.  
  282. StartMsg  endp
  283.  
  284. ;* - Hilfe ausgeben -------------------------------------- *
  285.  
  286. Help      proc near
  287.  
  288.           call StartMsg
  289.           mov  dx, offset HelpMsg
  290.           call PrintMsg
  291.           ret
  292.  
  293. Help      endp
  294.  
  295. ;* - Text ausgeben, auf den dx zeigt --------------------- *
  296.  
  297. PrintMsg  proc near
  298.  
  299.           push cs
  300.           pop  ds
  301.           mov  ah, 9
  302.           int  Dos
  303.           ret
  304.  
  305. PrintMsg  endp
  306.  
  307. ResFlag   db   0
  308. msg       db   CR, LF
  309.           db   '----------------', CR, LF
  310.           db   'CGA Emulator 1.0', CR, LF
  311.           db   '----------------', CR, LF, '$'
  312.  
  313. UpMsg     db   'Emulator ist bereits installiert,', CR, LF
  314.           db   'Werte werden geaendert.', CR, LF, '$'
  315.  
  316. ResMsg    db   'Emulator ist resident installiert.', CR, LF
  317.           db   '$'
  318.  
  319. HelpMsg   db   'Optionen:  2 - 200 Zeilen', CR, LF
  320.           db   '           3 - 300 Zeilen', CR, LF
  321.           db   '           4 - 400 Zeilen', CR, LF
  322.           db   '           G - Grafik einschalten', CR, LF
  323.           db   '           ? - Hilfe', CR, LF, '$'
  324.  
  325. cseg      ends
  326.           end main
  327. ;* ------------------------------------------------------- *
  328. ;*                 Ende von CGA.ASM                        *
  329.