assembler latch copying

This commit is contained in:
John Bintz 2024-03-19 22:08:42 -04:00
parent 9ec9389bdf
commit 9b0d260d5d
3 changed files with 119 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.o *.o
*.err *.err
*.exe *.exe
.ccls-cache/

30
main.c
View File

@ -3,9 +3,26 @@
extern void __cdecl enableUnchainedVGAMode(); extern void __cdecl enableUnchainedVGAMode();
extern void __cdecl enableTextMode(); extern void __cdecl enableTextMode();
extern void __cdecl fillScreen(int);
extern void __cdecl latchCopyCube();
char far *VGA = (char*)0xA0000; char far *VGA = (char*)0xA0000;
#define PLANE_WIDTH (320 / 4)
void populateExampleCube(void) {
int y, x;
outp(0x3c4, 0x02);
for (y = 0; y < 15; ++y) {
for (x = 0; x < 15; ++x) {
outp(0x3c5, 1 << (x % 4));
VGA[y * PLANE_WIDTH + x / 4] = y * 16 + x;
}
}
}
int main(void) { int main(void) {
// activate unchained vga mode // activate unchained vga mode
// set up 8 very clear colors // set up 8 very clear colors
@ -19,6 +36,15 @@ int main(void) {
enableUnchainedVGAMode(); enableUnchainedVGAMode();
fillScreen(0);
populateExampleCube();
latchCopyCube();
delay(2000);
/*
outp(0x3c4, 0x02); outp(0x3c4, 0x02);
for (i = 0; i < 200; ++i) { for (i = 0; i < 200; ++i) {
@ -28,7 +54,9 @@ int main(void) {
} }
} }
delay(5000); */
//delay(3000);
enableTextMode(); enableTextMode();
} }

90
vga.asm
View File

@ -1,13 +1,20 @@
PUBLIC _enableUnchainedVGAMode PUBLIC _enableUnchainedVGAMode
PUBLIC _enableTextMode PUBLIC _enableTextMode
PUBLIC _fillScreen
PUBLIC _latchCopyCube
DISPLAY_MODE_VGA equ 13h DISPLAY_MODE_VGA equ 13h
DISPLAY_MODE_TEXT equ 03h DISPLAY_MODE_TEXT equ 03h
VGA_SEQUENCE_CONTROLLER_INDEX equ 0x3c4 VGA_SEQUENCE_CONTROLLER_INDEX equ 0x3c4
VGA_SEQUENCE_CONTROLLER_DATA equ 0x3c5h VGA_SEQUENCE_CONTROLLER_DATA equ 0x3c5
VGA_SEQUENCE_CONTROLLER_MEMORY_MODE equ 0x04 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_INDEX equ 0x03d4
VGA_CRT_CONTROLLER_DATA equ 0x03d5 VGA_CRT_CONTROLLER_DATA equ 0x03d5
VGA_CRT_CONTROLLER_UNDERLINE_LOC equ 0x14 VGA_CRT_CONTROLLER_UNDERLINE_LOC equ 0x14
@ -45,4 +52,85 @@ _enableTextMode:
int 10h int 10h
ret 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
_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
end end