-
Notifications
You must be signed in to change notification settings - Fork 0
/
vga_gfx_mode_unchained_step_1.asm
108 lines (88 loc) · 3.04 KB
/
vga_gfx_mode_unchained_step_1.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
; Graficky rezim karty VGA s rozlisenim 320x200 pixelu.
; Vypnuti zretezeni bitovych rovin.
;
; Tento demonstracni priklad je pouzity v serialu o programovani
; grafickych dem a her na PC v DOSu:
; https://www.root.cz/serialy/vyvoj-her-a-grafickych-dem-pro-platformu-pc/
;
; preklad pomoci:
; nasm -f bin -o vga.com vga_gfx_mode_unchained_step_1.asm
;
; nebo pouze:
; nasm -o vga.com vga_gfx_mode_unchained_step_1.asm
;-----------------------------------------------------------------------------
BITS 16 ; 16bitovy vystup pro DOS
CPU 8086 ; specifikace pouziteho instrukcniho souboru
;-----------------------------------------------------------------------------
; registry karty VGA
SEQUENCER_INDEX equ 0x3c4
SEQUENCER_DATA equ 0x3c5
CRTC_INDEX equ 0x3d4
CRTC_DATA equ 0x3d5
BITPLANE_SELECTOR equ 0x02
MEMORY_MODE_REGISTER equ 0x04 ; sekvencer
UNDERLINE_LOCATION equ 0x14 ; CRTC
MODE_CONTROL equ 0x17 ; CRTC
;-----------------------------------------------------------------------------
; ukonceni procesu a navrat do DOSu
%macro exit 0
mov ah, 0x4c
int 0x21
%endmacro
; vyprazdneni bufferu klavesnice a cekani na klavesu
%macro wait_key 0
xor ax, ax
int 0x16
%endmacro
; nastaveni grafickeho rezimu
%macro gfx_mode 1
mov ah, 0
mov al, %1
int 0x10
%endmacro
; nastaveni jednoho registru sekvenceru
%macro set_sequencer_register 2
mov dx, SEQUENCER_INDEX
mov al, %1 ; ridici registr
out dx, al
inc dx
mov al, %2 ; hodnota zapisovana do registru
out dx, al
%endmacro
; nastaveni jednoho CRTC registru
%macro set_crtc_register 2
mov dx, CRTC_INDEX
mov al, %1 ; ridici registr (CRTC)
out dx, al
inc dx
mov al, %2 ; hodnota zapisovana do registru
out dx, al
%endmacro
; vyber bitove roviny
%macro select_bitplane 1
mov al, %1 ; bitova rovina
mov dx, SEQUENCER_INDEX
mov ah, BITPLANE_SELECTOR
xchg ah, al
out dx, ax ; vyber registru sekvenceru
; a zapis masky bitovych rovin
%endmacro
;-----------------------------------------------------------------------------
org 0x100 ; zacatek kodu pro programy typu COM (vzdy se zacina na 256)
start:
gfx_mode 0x13 ; nastaveni rezimu 320x200 s 256 barvami
mov ax, 0xa000 ; video RAM v textovem rezimu
mov es, ax
mov di, 0 ; nyni ES:DI obsahuje adresu prvniho pixelu ve video RAM
mov al, 3 ; kod barvy pixelu
call fill_block
mov al, 4 ; kod barvy pixelu
call fill_block
wait_key ; cekani na klavesu
exit ; navrat do DOSu
fill_block:
mov cx, 320*200/8 ; pocet zapisovanych pixelu (pixel==bajt)
opak:
stosb ; zapis barvy pixelu
loop opak ; opakujeme CX-krat
ret ; hotovo