Skip to content

Instantly share code, notes, and snippets.

@jgamble
Created January 27, 2023 03:39
Show Gist options
  • Select an option

  • Save jgamble/9d3603c92402858d193203770a5603e7 to your computer and use it in GitHub Desktop.

Select an option

Save jgamble/9d3603c92402858d193203770a5603e7 to your computer and use it in GitHub Desktop.
Very old code from 1987. Switch the Hercules Graphics Card (see https://en.wikipedia.org/wiki/Hercules_Graphics_Card) to graphics mode or text mode.
; HERCMODE -- Mode switch for Hercules Graphics board.
; Copied from the Hercules owner's manual, edition 2.1, pg 20.
;
; port address
index equ 03b4h
cntrl equ 03b8h
;
; control codes
scrn_on equ 8
grph equ 2
text equ 20h
;
xdata segment public 'data'
;
gtable db 35h, 2dh, 2eh, 07h
db 5bh, 02h, 57h, 57h
db 02h, 03h, 00h, 00h
;
ttable db 61h, 50h, 52h, 0fh
db 19h, 06h, 19h, 19h
db 02h, 0dh, 0bh, 0ch
xdata ends
;
xcode segment public 'code'
assume cs:xcode, ds:xdata
;
; GRAPHICS MODE -- program the 6845 CRT controller for the 720 x 348
; graphics mode. The active page for both writein and display is set
; to the default value of page 0.
;
; ON ENTRY: no parameters
;
public hgmode
hgmode proc far
push es
push ds
mov ax, xdata
mov ds, ax
mov al, grph
lea si, gtable
mov bx, 0
mov cx, 4000h
call setmd
pop ds
pop es
ret
hgmode endp
;
; TEXT MODE -- programs the 6845 and CRT control register to produce
; text mode.
;
; ON ENTRY: no parameters.
;
public htmode
htmode proc far
push es
push ds
mov ax, xdata
mov ds, ax
mov al, text
lea si, ttable
mov bx, 720h
mov cx, 2000h ; NOTE: In the manual the 'h' was
; missing.
call setmd
pop ds
pop es
ret
htmode endp
;
; sets mode to graphis or text depending on al.
; si = parameter table
; cx = number of words to be cleared
; bx = blank value
;
setmd proc near
push ds
push es
push ax
push bx
push cx
;
; change mode but without scrn_on
mov dx, cntrl
out dx, al
;
; initialize the 6845.
;
mov ax, ds
mov es, ax ; also point es:si to
; parameter table.
mov dx, index
mov cx, 12 ; 12 parameters to be output
xor ah, ah ; starting from reg.0.
;
parms: mov al, ah
out dx, al ; output register number.
inc dx
lodsb
out dx, al ; output data
inc ah ; next value
dec dx
loop parms
;
pop cx ; clear the buffer.
mov ax, 0b000h
cld
mov es, ax
xor di, di
pop ax
rep stosw
;
; scrn_on, page 0.
;
mov dx, cntrl
pop ax
add al, scrn_on
out dx, al
pop es
pop ds
ret
setmd endp
xcode ends
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment