vga-logic-processor-examples/vga.asm

137 lines
2.3 KiB
NASM
Raw Normal View History

2024-03-19 12:18:55 +00:00
PUBLIC _enableUnchainedVGAMode
PUBLIC _enableTextMode
2024-03-20 02:08:42 +00:00
PUBLIC _fillScreen
PUBLIC _latchCopyCube
2024-03-19 12:18:55 +00:00
DISPLAY_MODE_VGA equ 13h
DISPLAY_MODE_TEXT equ 03h
VGA_SEQUENCE_CONTROLLER_INDEX equ 0x3c4
2024-03-20 02:08:42 +00:00
VGA_SEQUENCE_CONTROLLER_DATA equ 0x3c5
2024-03-19 12:18:55 +00:00
VGA_SEQUENCE_CONTROLLER_MEMORY_MODE equ 0x04
2024-03-20 02:08:42 +00:00
VGA_SEQUENCE_CONTROLLER_MAP_MASK_MODE equ 0x02
VGA_GRAPHICS_MODE_INDEX equ 0x3CE
VGA_GRAPHICS_MODE equ 0x05
2024-03-19 12:18:55 +00:00
VGA_CRT_CONTROLLER_INDEX equ 0x03d4
VGA_CRT_CONTROLLER_DATA equ 0x03d5
VGA_CRT_CONTROLLER_UNDERLINE_LOC equ 0x14
VGA_CRT_CONTROLLER_MODE_CONTROL equ 0x17
.386
.model flat,c
.CODE
_enableUnchainedVGAMode:
mov ax,0x0013;
int 0x10
mov dx, VGA_SEQUENCE_CONTROLLER_INDEX
mov al, VGA_SEQUENCE_CONTROLLER_MEMORY_MODE
mov ah, 0x06
out dx, ax
mov dx, VGA_CRT_CONTROLLER_INDEX
mov al, VGA_CRT_CONTROLLER_MODE_CONTROL
mov ah, 0xe3
out dx, ax
mov dx, VGA_CRT_CONTROLLER_INDEX
mov al, VGA_CRT_CONTROLLER_UNDERLINE_LOC
mov ah, 0x00
out dx, ax
ret
_enableTextMode:
mov ah,0h
mov al,DISPLAY_MODE_TEXT
int 10h
ret
2024-03-20 02:08:42 +00:00
_fillScreen:
push ebp
mov ebp, esp
; set all bitplanes
mov dx, VGA_SEQUENCE_CONTROLLER_INDEX
mov al, 0x02
mov ah, 0fh
out dx, ax
mov al, [ebp+8] ; requested color
mov cx, 16000 ; loop index
mov ebx, 0xa0000
_fillScreen_loop:
mov BYTE PTR [ebx], al
inc ebx
loop _fillScreen_loop
mov esp,ebp
pop ebp
ret
_latchCopyCube:
push ebp
mov ebp,esp
; we need an x and y variable
sub esp,4 ; y
; enable latch reads
mov dx, VGA_SEQUENCE_CONTROLLER_INDEX
mov al, VGA_SEQUENCE_CONTROLLER_MAP_MASK_MODE
mov ah, 0xf
out dx, ax
mov dx, VGA_GRAPHICS_MODE_INDEX
mov al, 0x08
mov ah, 0x00
out dx, ax
mov DWORD PTR [ebp-4],16
; read across the cube, should take 4 * 16 reads
mov cx,[ebp-4]
_latchCopyCube_yLoop:
mov [ebp-4],cx ; put y back in loop
mov eax,[ebp-4] ; put y in ax
dec eax ; offset by 1 for loop
; can only multiply in ax
mov bl,80
mul bl ; number of lines
add eax,0xa0000 ; vga base address
; start x loop
mov cx,4
_latchCopyCube_xLoop:
; fill latches
mov bl, BYTE PTR [eax]
; write blank
mov [eax+12],0
; increment vga pointer
inc eax
; loop until x is 0
loop _latchCopyCube_xLoop
; restore y for looping
mov cx,[ebp-4]
; loop until y is 0
loop _latchCopyCube_yLoop
; put things back
mov esp,ebp
pop ebp
ret
2024-03-19 12:18:55 +00:00
end