-
Notifications
You must be signed in to change notification settings - Fork 22
/
video.asm
38 lines (36 loc) · 1.28 KB
/
video.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
; the VGA hardware is always in one of two states:
; * refresh, where the screen gets redrawn.
; This is the state the VGA is in most of the time.
; * retrace, a relatively short period when the electron gun is returning to
; the top left of the screen, from where it will begin drawing the
; next frame to the monitor. Ideally, we write the next frame to
; the video memory entirely during retrace, so each refresh is
; only drawing one full frame
; The following procedure waits until the *next* retrace period begins.
; First it waits until the end of the current retrace, if we're in one
; (if we're in refresh this part of the procedure does nothing)
; Then it waits for the end of refresh.
WaitFrame: PUSH DX
; port 0x03DA contains VGA status
MOV DX, 0x03DA
.waitRetrace: IN AL, DX ; read from status port
; bit 3 will be on if we're in retrace
TEST AL, 0x08 ; are we in retrace?
JNZ .waitRetrace
.endRefresh: IN AL, DX
TEST AL, 0x08 ; are we in refresh?
JZ .endRefresh
POP DX
RET
; NOTE: makes ES point to video memory!
InitVideo: ; set video mode 0x13
MOV AX, 0x13
INT 0x10
; make ES point to the VGA memory
MOV AX, 0xA000
MOV ES, AX
RET
RestoreVideo: ; return to text mode 0x03
MOV AX, 0x03
INT 0x10
RET