much more stuff

This commit is contained in:
John Bintz 2024-03-20 19:19:49 -04:00
parent 4f85bd4b1b
commit 77c162002b
2 changed files with 222 additions and 47 deletions

90
main.c
View File

@ -1,15 +1,33 @@
#include <stdio.h> #include <stdio.h>
#include <i86.h> #include <i86.h>
#include <conio.h> #include <conio.h>
#include <dos.h>
extern void __cdecl enableUnchainedVGAMode(); extern void __cdecl enableUnchainedVGAMode();
extern void __cdecl enableTextMode(); extern void __cdecl enableTextMode();
extern void __cdecl fillScreen(int); extern void __cdecl fillScreen(int);
extern void __cdecl latchCopyCube(char offset, int writtenValue, int writeMode); extern void __cdecl latchCopyCube(
char offset,
int writtenValue,
int writeMode,
int setResetRegister,
int enableSetResetRegister
);
extern void __cdecl writeCube(
char offset,
int writeMode,
int setResetRegister,
int enableSetResetRegister
);
extern void __cdecl drawColorCube(
char offset,
int color
);
extern int __cdecl paramTest(int wow); extern int __cdecl paramTest(int wow);
extern void __cdecl far interrupt keyboardHandler(); extern void far interrupt keyboardHandler();
extern char keyboardPressed; extern char keyboardPressed;
extern char lastScancode;
char far *VGA = (char*)0xA0000; char far *VGA = (char*)0xA0000;
@ -44,52 +62,42 @@ int main(void) {
int9Save = _dos_getvect(9); int9Save = _dos_getvect(9);
_dos_setvect(9, keyboardHandler); _dos_setvect(9, keyboardHandler);
printf("%p\n", keyboardHandler);
while (keyboardPressed == 0) {
printf("%d\n", keyboardPressed);
}
printf("wow\n");
delay(200);
_dos_setvect(9, int9Save);
return 0;
enableUnchainedVGAMode(); enableUnchainedVGAMode();
outp(0x3c8, 255);
outp(0x3c9, 63);
outp(0x3c9, 63);
outp(0x3c9, 63);
fillScreen(0); fillScreen(0);
populateExampleCube();
latchCopyCube(8, 0, 0x00);
latchCopyCube(12, 127, 0x00);
latchCopyCube(16, 0, 0x08);
latchCopyCube(20, 127, 0x08);
latchCopyCube(24, 0, 0x10);
latchCopyCube(28, 127, 0x10);
latchCopyCube(32, 0, 0x18);
latchCopyCube(36, 127, 0x18);
while (keyboardPressed == 0) {
delay(1);
}
/* /*
populateExampleCube();
outp(0x3c4, 0x02); latchCopyCube(8, 0, 0x00, 0, 0);
latchCopyCube(12, 127, 0x00, 0, 0);
for (i = 0; i < 200; ++i) { latchCopyCube(16, 0, 0x08, 0, 0);
for (j = 0; j < 4; ++j) { latchCopyCube(20, 127, 0x08, 0, 0);
outp(0x3c5, 1 << j); latchCopyCube(24, 0, 0x10, 0, 0);
VGA[i] = j + 1; latchCopyCube(28, 127, 0x10, 0, 0);
} latchCopyCube(32, 0, 0x18, 0, 0);
} latchCopyCube(36, 127, 0x18, 0, 0);
latchCopyCube(40, 0, 0x18 + 0x04, 0, 0);
latchCopyCube(44, 127, 0x18 + 0x04, 0, 0);
latchCopyCube(64, 0, 0x10, 7, 7);
latchCopyCube(68, 0, 0x10, 7, 0);
latchCopyCube(72, 0, 0x10, 0, 7);
*/ */
//delay(3000); writeCube(0, 0x10, 0, 0);
writeCube(4, 0x10, 7, 0);
writeCube(8, 0x10, 7, 7);
writeCube(12, 0x10, 0, 7);
while (keyboardPressed == 0);
_dos_setvect(9, int9Save);
enableTextMode(); enableTextMode();
return 0;
} }

179
vga.asm
View File

@ -2,9 +2,11 @@ PUBLIC _enableUnchainedVGAMode
PUBLIC _enableTextMode PUBLIC _enableTextMode
PUBLIC _fillScreen PUBLIC _fillScreen
PUBLIC _latchCopyCube PUBLIC _latchCopyCube
PUBLIC _drawColorCube
PUBLIC _writeCube
PUBLIC _paramTest PUBLIC _paramTest
PUBLIC _keyboardPressed PUBLIC _keyboardPressed
PUBLIC _keyboardHandler PUBLIC keyboardHandler_
DISPLAY_MODE_VGA equ 13h DISPLAY_MODE_VGA equ 13h
DISPLAY_MODE_TEXT equ 03h DISPLAY_MODE_TEXT equ 03h
@ -28,11 +30,11 @@ VGA_CRT_CONTROLLER_MODE_CONTROL equ 0x17
.DATA .DATA
_keyboardPressed dd 0 _keyboardPressed db 0
.CODE .CODE
_keyboardHandler: keyboardHandler_:
cli cli
push eax push eax
push ebx push ebx
@ -124,10 +126,162 @@ _paramTest:
pop ebp pop ebp
ret ret
_latchCopyCube:
_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 push ebp
mov ebp,esp mov ebp,esp
; we need a y variable ; 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 sub esp,4 ; y
push edx push edx
@ -140,19 +294,32 @@ _latchCopyCube:
; [ebp+8] is x offset ; [ebp+8] is x offset
; [ebp+12] is written value ; [ebp+12] is written value
; [ebp+16] is data rotate register ; [ebp+16] is data rotate register
; [ebp+20] is set/reset register
; [ebp+24] is enable set/reset register
; enable latch reads on all planes ; write to all planes
mov dx, VGA_SEQUENCE_CONTROLLER_INDEX mov dx, VGA_SEQUENCE_CONTROLLER_INDEX
mov al, VGA_SEQUENCE_CONTROLLER_MAP_MASK_MODE mov al, VGA_SEQUENCE_CONTROLLER_MAP_MASK_MODE
mov ah, 0xf mov ah, 0xf
out dx, ax out dx, ax
; enable OR writes ; enable Logical Operation and host data shifts
mov dx, VGA_GRAPHICS_MODE_INDEX mov dx, VGA_GRAPHICS_MODE_INDEX
mov al, 0x03 mov al, 0x03
mov ah, [ebp+16] mov ah, [ebp+16]
out dx, ax 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 dh, [ebp+12]
mov DWORD PTR [ebp-4],16 ; y mov DWORD PTR [ebp-4],16 ; y