Move vram functions into separate file
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
%include "multiboot_header.asm"
|
%include "multiboot_header.asm"
|
||||||
|
|
||||||
%include "x86_vram.asm"
|
%include "x86_vram.asm"
|
||||||
|
|
||||||
%define stack_size 0x1000
|
%define stack_size 0x1000
|
||||||
@@ -53,56 +52,4 @@ halt:
|
|||||||
hlt
|
hlt
|
||||||
jmp halt
|
jmp halt
|
||||||
|
|
||||||
; first argument is row, 1 byte
|
%include "x86_vram_functions.asm"
|
||||||
; second argument is column, 1 byte
|
|
||||||
; third argument is cell, 2 bytes
|
|
||||||
write_to_coord:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
push edi
|
|
||||||
push ebx
|
|
||||||
|
|
||||||
; should do the same thing
|
|
||||||
;call get_vram_offset
|
|
||||||
;mov edi, eax
|
|
||||||
mov edi, X86_VRAM
|
|
||||||
mov ebx, [ebp+8]
|
|
||||||
imul ebx, X86_COLS*2
|
|
||||||
add ebx, [ebp+12]
|
|
||||||
add ebx, [ebp+12]
|
|
||||||
add edi, ebx ;edi now has effective address
|
|
||||||
|
|
||||||
mov ebx, [ebp+16] ;; load word into ebx
|
|
||||||
mov [edi], bx
|
|
||||||
|
|
||||||
pop ebx
|
|
||||||
pop edi
|
|
||||||
mov esp, ebp
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
; takes character/attribute in edi
|
|
||||||
; writes it to all cells on screen
|
|
||||||
clear:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
push edi
|
|
||||||
|
|
||||||
; movzx - move and zero-extend
|
|
||||||
; this trick lets us write half as many doublewords to vram
|
|
||||||
movzx eax, word [ebp + 8]
|
|
||||||
mov edx, eax
|
|
||||||
shl eax, 16
|
|
||||||
or eax, edx
|
|
||||||
|
|
||||||
; stosd stores eax at the address in edi (here, vram)
|
|
||||||
; and then increments edi
|
|
||||||
; rep stosd repeats stosd while ecx is nonzero
|
|
||||||
mov edi, X86_VRAM
|
|
||||||
mov ecx, X86_COLS * X86_ROWS / 2
|
|
||||||
rep stosd ; "A REP STOS instruction is the fastest way to initialize a large block of memory."
|
|
||||||
|
|
||||||
pop edi
|
|
||||||
mov esp, ebp
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|||||||
@@ -6,6 +6,14 @@ int get_vram_offset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void c_entry() {
|
void c_entry() {
|
||||||
|
/*
|
||||||
int space = 0x26 | (0xf0 << 8); //ascii ampersand white on black
|
int space = 0x26 | (0xf0 << 8); //ascii ampersand white on black
|
||||||
write_to_coord(22,70, space);
|
write_to_coord(22,70, space);
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (int i = 0; i < 26; i++) {
|
||||||
|
int space = 'a' + i | (0xf0 << 8);
|
||||||
|
write_to_coord(12, i, space);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
55
x86_vram_functions.asm
Normal file
55
x86_vram_functions.asm
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
%include "x86_vram.asm"
|
||||||
|
|
||||||
|
; first argument is row, 1 byte
|
||||||
|
; second argument is column, 1 byte
|
||||||
|
; third argument is cell, 2 bytes
|
||||||
|
write_to_coord:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
push edi
|
||||||
|
push ebx
|
||||||
|
|
||||||
|
; should do the same thing
|
||||||
|
;call get_vram_offset
|
||||||
|
;mov edi, eax
|
||||||
|
mov edi, X86_VRAM
|
||||||
|
mov ebx, [ebp+8]
|
||||||
|
imul ebx, X86_COLS*2
|
||||||
|
add ebx, [ebp+12]
|
||||||
|
add ebx, [ebp+12]
|
||||||
|
add edi, ebx ;edi now has effective address
|
||||||
|
|
||||||
|
mov ebx, [ebp+16] ;; load word into ebx
|
||||||
|
mov [edi], bx
|
||||||
|
|
||||||
|
pop ebx
|
||||||
|
pop edi
|
||||||
|
mov esp, ebp
|
||||||
|
pop ebp
|
||||||
|
ret
|
||||||
|
|
||||||
|
; takes character/attribute in edi
|
||||||
|
; writes it to all cells on screen
|
||||||
|
clear:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
push edi
|
||||||
|
|
||||||
|
; movzx - move and zero-extend
|
||||||
|
; this trick lets us write half as many doublewords to vram
|
||||||
|
movzx eax, word [ebp + 8]
|
||||||
|
mov edx, eax
|
||||||
|
shl eax, 16
|
||||||
|
or eax, edx
|
||||||
|
|
||||||
|
; stosd stores eax at the address in edi (here, vram)
|
||||||
|
; and then increments edi
|
||||||
|
; rep stosd repeats stosd while ecx is nonzero
|
||||||
|
mov edi, X86_VRAM
|
||||||
|
mov ecx, X86_COLS * X86_ROWS / 2
|
||||||
|
rep stosd ; "A REP STOS instruction is the fastest way to initialize a large block of memory."
|
||||||
|
|
||||||
|
pop edi
|
||||||
|
mov esp, ebp
|
||||||
|
pop ebp
|
||||||
|
ret
|
||||||
Reference in New Issue
Block a user