-
Notifications
You must be signed in to change notification settings - Fork 0
/
cga.asm
133 lines (111 loc) · 3.54 KB
/
cga.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
org 100h
%macro print_msg 1
mov ah, 9
mov dx, %1
int 21h
%endmacro
start:
mov si, 81h ; start of command line arguments
parse_arg:
call skip_space
mov al, [si] ; first character
cmp al, '1'
je text_25x80
cmp al, '2'
je text_25x40
cmp al, '3'
je graph_320x200
cmp al, '4'
je graph_320x200_p2
cmp al, '5'
je graph_640x200
exit:
mov ax,4C00h
int 21h
skip_space:
cmp byte [si], 0x20
je .skip
ret
.skip:
inc si
jmp skip_space
text_25x80:
mov si, textt ;Offset address of the register-table
mov bl, 00000001b ;80x25 text mode
mov cl, 00000000b
call crtc_prog
print_msg text_msg_25x80
jmp exit
text_25x40:
mov si, textt ;Offset address of the register-table
mov bl, 00000000b ;40x25 text mode
mov cl, 00000000b
call crtc_prog
print_msg text_msg_25x40
jmp exit
graph_320x200:
mov si, graphict ;Offset address of the register-table
mov bl, 00000010b ;Graphics mode 320x200
mov cl, 00100000b ;Color palette #1
call crtc_prog
print_msg graph_msg_320x200
jmp exit
graph_320x200_p2:
mov si, graphict ;Offset address of the register-table
mov bl, 0000010b ;Graphics mode 320x200
mov cl, 00000000b ;Color palette #2
call crtc_prog
print_msg graph_msg_320x200_p2
jmp exit
graph_640x200:
mov si, graphict ;Offset address of the register-table
mov bl, 00010000b ;Graphics mode 640x200
call crtc_prog
print_msg graph_msg_640x200
jmp exit
setmode:
mov dx, word [CONTROL_REG] ;Address of the display control register
mov al,bl
out dx,al ;Send mode to control register
ret
crtc_prog:
call setmode ;
call setcol ;Set color palette
mov cx,14 ;14 registers are set
xor bh,bh ;Start with register 0
vcp1:
lodsb ;Get register value from table
mov ah,al ;Register value to AH
mov al,bh ;Number of the register to AL
call setvk ;Transmit value to controller
inc bh ;Address next register
loop vcp1 ;Set additional registers
or bl,8 ;Bit 3 = 1: screen on
call setmode
ret ;Back to caller
setvk:
mov dx, word [ADDRESS_6845] ;Address of the index register
out dx,al ;Send number of the register
jmp short $+2 ;Short I/O pause
inc dx ;Address of the index register
mov al,ah ;Content to AL
out dx,al ;Set new content
ret ;Back to caller
setcol:
mov dx, word [CCHOICE_REG] ;Address of the color selection register
mov al,cl
out dx,al ;Output color value
ret ;Back to caller
section .data
;Custom CGA card I/O (e.g. 0x3D4 -> 0x394)
CONTROL_REG dw 0x0398 ;Control register port address
CCHOICE_REG dw 0x0399 ;Color select register port address
ADDRESS_6845 dw 0x0394 ;6845 address register
DATA_6845 dw 0x0395 ;6845 data register
graphict db 0x38,0x28,0x2D,0x0A,0x7F,0x06,0x64,0x70,0x02,0x01,0x06,0x07,0x00,0x00
textt db 0x71,0x50,0x5A,0x0A,0x1F,0x06,0x19,0x1C,0x02,0x07,0x06,0x07,0x00,0x00
text_msg_25x80 db 'Text Mode - 25x80$'
text_msg_25x40 db 'Text Mode - 25x40$'
graph_msg_320x200 db 'Graphics Mode - 320x200 (color palette #1)$'
graph_msg_320x200_p2 db 'Graphics Mode - 320x200 (color palette #2)$'
graph_msg_640x200 db 'Graphics Mode - 640x200$'