From 9b0d260d5decdfd43d050e55f21c38d284a7e4ac Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 19 Mar 2024 22:08:42 -0400 Subject: [PATCH] assembler latch copying --- .gitignore | 1 + main.c | 30 +++++++++++++++++- vga.asm | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 4b6b859..d16db97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.o *.err *.exe +.ccls-cache/ diff --git a/main.c b/main.c index f8e5b8f..58702b4 100644 --- a/main.c +++ b/main.c @@ -3,9 +3,26 @@ extern void __cdecl enableUnchainedVGAMode(); extern void __cdecl enableTextMode(); +extern void __cdecl fillScreen(int); +extern void __cdecl latchCopyCube(); 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) { // activate unchained vga mode // set up 8 very clear colors @@ -19,6 +36,15 @@ int main(void) { enableUnchainedVGAMode(); + fillScreen(0); + + populateExampleCube(); + latchCopyCube(); + + delay(2000); + + /* + outp(0x3c4, 0x02); for (i = 0; i < 200; ++i) { @@ -28,7 +54,9 @@ int main(void) { } } - delay(5000); + */ + + //delay(3000); enableTextMode(); } diff --git a/vga.asm b/vga.asm index 88c8ae7..cee73f5 100644 --- a/vga.asm +++ b/vga.asm @@ -1,13 +1,20 @@ PUBLIC _enableUnchainedVGAMode PUBLIC _enableTextMode +PUBLIC _fillScreen +PUBLIC _latchCopyCube DISPLAY_MODE_VGA equ 13h DISPLAY_MODE_TEXT equ 03h 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_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 @@ -45,4 +52,85 @@ _enableTextMode: 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 + +_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