370 lines
5.7 KiB
NASM
370 lines
5.7 KiB
NASM
PUBLIC _enableUnchainedVGAMode
|
|
PUBLIC _enableTextMode
|
|
PUBLIC _fillScreen
|
|
PUBLIC _latchCopyCube
|
|
PUBLIC _drawColorCube
|
|
PUBLIC _writeCube
|
|
PUBLIC _paramTest
|
|
PUBLIC _keyboardPressed
|
|
PUBLIC keyboardHandler_
|
|
|
|
DISPLAY_MODE_VGA equ 13h
|
|
DISPLAY_MODE_TEXT equ 03h
|
|
|
|
VGA_SEQUENCE_CONTROLLER_INDEX equ 0x3c4
|
|
VGA_SEQUENCE_CONTROLLER_DATA equ 0x3c5
|
|
VGA_SEQUENCE_CONTROLLER_MEMORY_MODE equ 0x04
|
|
|
|
VGA_SEQUENCE_CONTROLLER_MAP_MASK_MODE equ 0x02
|
|
|
|
VGA_GRAPHICS_MODE_INDEX equ 0x3CE
|
|
VGA_GRAPHICS_MODE equ 0x05
|
|
|
|
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
|
|
|
|
.DATA
|
|
|
|
_keyboardPressed db 0
|
|
|
|
.CODE
|
|
|
|
keyboardHandler_:
|
|
cli
|
|
push eax
|
|
push ebx
|
|
|
|
in al, 0x60
|
|
mov bl, al
|
|
|
|
; acknowledge keyboard
|
|
in al, 0x61
|
|
mov ah, al
|
|
or al, 0x80
|
|
out 0x61, al
|
|
xchg ah, al
|
|
out 0x61, al
|
|
|
|
and bl,0x80
|
|
jne _keyboardHandler_notKeydown
|
|
|
|
mov [_keyboardPressed], 1
|
|
_keyboardHandler_notKeydown:
|
|
; acknowledge interrupt
|
|
mov al, 0x20
|
|
out 0x20, al
|
|
|
|
pop ebx
|
|
pop eax
|
|
sti
|
|
iretd
|
|
|
|
_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
|
|
|
|
_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
|
|
|
|
_paramTest:
|
|
push ebp
|
|
mov ebp,esp
|
|
|
|
mov eax,0
|
|
mov al, BYTE PTR [ebp+8]
|
|
|
|
mov esp,ebp
|
|
pop ebp
|
|
ret
|
|
|
|
|
|
_drawColorCube:
|
|
push ebp
|
|
mov ebp, esp
|
|
sub esp, 4 ; y
|
|
push ebx
|
|
push ecx
|
|
push edx
|
|
|
|
; write to all planes
|
|
mov dx, VGA_SEQUENCE_CONTROLLER_INDEX
|
|
mov al, VGA_SEQUENCE_CONTROLLER_MAP_MASK_MODE
|
|
mov ah, 0xf
|
|
out dx, ax
|
|
|
|
; write out host data only
|
|
mov dx, VGA_GRAPHICS_MODE_INDEX
|
|
mov al, 0x03
|
|
mov ah, 0x00
|
|
out dx, ax
|
|
|
|
; disable set/reset registers
|
|
mov al, 0x00
|
|
mov ah, 0x00
|
|
out dx, ax
|
|
|
|
mov al, 0x01
|
|
mov ah, 0x00
|
|
out dx, ax
|
|
|
|
mov DWORD PTR [ebp-4], 16 ; y
|
|
mov cx,[ebp-4]
|
|
|
|
; offset is [ebp+8]
|
|
mov bh,[ebp+12]; color
|
|
|
|
_drawColorCube_yLoop:
|
|
mov [ebp-4],cx
|
|
|
|
mov eax,[ebp-4]
|
|
dec eax
|
|
mov bl,80
|
|
mul bl
|
|
add eax,[ebp+8]
|
|
add eax,0xa0000
|
|
|
|
mov cx, 4
|
|
_drawColorCube_xLoop:
|
|
mov [eax],bh ; write color
|
|
inc eax
|
|
|
|
loop _drawColorCube_xLoop
|
|
|
|
mov cx, [ebp-4]
|
|
loop _drawColorCube_yLoop
|
|
|
|
pop edx
|
|
pop ecx
|
|
pop ebx
|
|
mov esp, ebp
|
|
pop ebp
|
|
ret
|
|
|
|
|
|
|
|
|
|
_writeCube:
|
|
push ebp
|
|
mov ebp,esp
|
|
; we need a y variable
|
|
sub esp,4
|
|
; and a current color
|
|
sub esp,4
|
|
|
|
; [ebp+8] is x offset
|
|
; [ebp+12] is data rotate
|
|
; [ebp+16] is set/reset
|
|
; [ebp+20] is enable set/reset
|
|
|
|
; enable Logical Operation and host data shifts
|
|
mov dx, VGA_GRAPHICS_MODE_INDEX
|
|
mov al, 0x03
|
|
mov ah, [ebp+12]
|
|
out dx, ax
|
|
|
|
; enable set/reset registers
|
|
mov dx, VGA_GRAPHICS_MODE_INDEX
|
|
mov al, 0x00
|
|
mov ah, [ebp+16]
|
|
out dx, ax
|
|
|
|
mov dx, VGA_GRAPHICS_MODE_INDEX
|
|
mov al, 0x01
|
|
mov ah, [ebp+20]
|
|
out dx, ax
|
|
|
|
mov DWORD PTR [ebp-8],0
|
|
mov DWORD PTR [ebp-4],16
|
|
mov cx,[ebp-4]
|
|
|
|
_writeCube_yLoop:
|
|
mov [ebp-4],cx
|
|
|
|
mov eax,[ebp-4]
|
|
dec eax
|
|
mov bl,80
|
|
mul bl
|
|
add eax,0xa0000
|
|
|
|
mov cx,16
|
|
_writeCube_xLoop:
|
|
; get the current plane
|
|
push ecx
|
|
dec cl
|
|
and cl,0x03
|
|
|
|
jne _writeCube_dontAdvanceVGA
|
|
inc eax
|
|
_writeCube_dontAdvanceVGA:
|
|
|
|
mov bl,1
|
|
sal bl,cl
|
|
pop ecx
|
|
|
|
push eax
|
|
; write to one plane
|
|
mov dx, VGA_SEQUENCE_CONTROLLER_INDEX
|
|
mov al, VGA_SEQUENCE_CONTROLLER_MAP_MASK_MODE
|
|
mov ah, bl
|
|
out dx, ax
|
|
pop eax
|
|
|
|
;mov ebx,[ebp+8]
|
|
|
|
push ecx
|
|
mov ecx,[ebp+8]
|
|
mov bl,[ebp-8]
|
|
mov BYTE PTR [eax+ecx],bl
|
|
inc bl
|
|
mov [ebp-8],bl
|
|
pop ecx
|
|
|
|
loop _writeCube_xLoop
|
|
|
|
mov cx,[ebp-4]
|
|
loop _writeCube_yLoop
|
|
|
|
mov esp,ebp
|
|
pop ebp
|
|
ret
|
|
|
|
|
|
_latchCopyCube:
|
|
push ebp
|
|
mov ebp, esp
|
|
; we need a y variable
|
|
sub esp,4 ; y
|
|
|
|
push edx
|
|
push ebx
|
|
|
|
; accept a mode
|
|
; accept a mix value
|
|
; accept an x offset
|
|
|
|
; [ebp+8] is x offset
|
|
; [ebp+12] is written value
|
|
; [ebp+16] is data rotate register
|
|
; [ebp+20] is set/reset register
|
|
; [ebp+24] is enable set/reset register
|
|
|
|
; write to all planes
|
|
mov dx, VGA_SEQUENCE_CONTROLLER_INDEX
|
|
mov al, VGA_SEQUENCE_CONTROLLER_MAP_MASK_MODE
|
|
mov ah, 0xf
|
|
out dx, ax
|
|
|
|
; enable Logical Operation and host data shifts
|
|
mov dx, VGA_GRAPHICS_MODE_INDEX
|
|
mov al, 0x03
|
|
mov ah, [ebp+16]
|
|
out dx, ax
|
|
|
|
; enable set/reset registers
|
|
mov dx, VGA_GRAPHICS_MODE_INDEX
|
|
mov al, 0x00
|
|
mov ah, [ebp+20]
|
|
out dx, ax
|
|
|
|
mov dx, VGA_GRAPHICS_MODE_INDEX
|
|
mov al, 0x01
|
|
mov ah, [ebp+24]
|
|
out dx, ax
|
|
|
|
mov dh, [ebp+12]
|
|
|
|
mov DWORD PTR [ebp-4],16 ; y
|
|
; 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 eax
|
|
dec eax ; offset by 1 for loop
|
|
; can only multiply in eax by register
|
|
mov bl,80
|
|
mul bl ; number of lines
|
|
add eax,0xa0000 ; vga base address
|
|
|
|
; keep our index handy
|
|
mov ebx, [ebp+8]
|
|
|
|
; start x loop
|
|
mov cx,4
|
|
_latchCopyCube_xLoop:
|
|
; fill latches via memory read
|
|
mov dl, BYTE PTR [eax]
|
|
|
|
; write blank
|
|
mov BYTE PTR [eax+ebx], dh
|
|
|
|
; 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
|
|
pop ebx
|
|
pop edx
|
|
mov esp,ebp
|
|
pop ebp
|
|
ret
|
|
|
|
end
|