|
|
@ -29,6 +29,8 @@ |
|
|
|
xor ax, ax |
|
|
|
mov cx, 4 |
|
|
|
rep stosw |
|
|
|
|
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
%endmacro |
|
|
|
|
|
|
|
%macro GDT_ENTRY 6 ; address base limit type privilege bits32 |
|
|
@ -57,8 +59,13 @@ |
|
|
|
mov WORD [es:(address + 2)], base_0_15 |
|
|
|
mov WORD [es:(address + 4)], base_16_23 | (access << 8) |
|
|
|
mov WORD [es:(address + 6)], limit_16_19 | (flags << 4) | (base_24_31 << 8) |
|
|
|
|
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
%endmacro |
|
|
|
|
|
|
|
%define IOKeyData 0x60 |
|
|
|
%define InKeyStatus 0x64 |
|
|
|
%define OutKeyCommand 0x64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -192,20 +199,10 @@ Go32Bit: |
|
|
|
%assign GDT_COUNT 0 |
|
|
|
|
|
|
|
GDT_NULL_ENTRY 0 |
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
|
|
|
|
GDT_ENTRY (GDT_CodeSegIndex*8), 0x00000000, 0xffffffff, CodeRead, 0, 1 |
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
|
|
|
|
GDT_ENTRY (GDT_DataSegIndex*8), 0x00000000, 0xffffffff, DataMutable, 0, 1 |
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
|
|
|
|
GDT_ENTRY (GDT_CodeSeg16Index*8), 0x00000000, 0xffffffff, CodeRead, 0, 0 |
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
|
|
|
|
GDT_ENTRY (GDT_DataSeg16Index*8), 0x00000000, 0xffffffff, DataMutable, 0, 0 |
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
|
|
|
|
cli |
|
|
|
lgdt [GDT_Record] |
|
|
|
|
|
|
@ -251,104 +248,97 @@ ProtectedModeBaby: |
|
|
|
mov gs, ax |
|
|
|
|
|
|
|
; Setup stack |
|
|
|
mov esp, 0x800000 |
|
|
|
mov esp, 0x8000000 |
|
|
|
mov ebp, esp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DrawStuff: |
|
|
|
mov ecx, 0 |
|
|
|
mov edx, 0 |
|
|
|
xor ecx, ecx |
|
|
|
xor edx, edx |
|
|
|
lea edi, [VIDEO] |
|
|
|
mov al, '@' |
|
|
|
DrawBG: |
|
|
|
|
|
|
|
mov ebp, dword [Zoom] |
|
|
|
sar ebp, 9 |
|
|
|
jnz .DrawLoop |
|
|
|
|
|
|
|
mov ebp, 0x7fffffff |
|
|
|
|
|
|
|
.DrawLoop: |
|
|
|
mov eax, [Px] |
|
|
|
shr eax, 4 |
|
|
|
add eax, ecx |
|
|
|
imul eax, eax |
|
|
|
|
|
|
|
mov ebx, [Py] |
|
|
|
shr ebx, 4 |
|
|
|
add ebx, edx |
|
|
|
imul ebx, ebx |
|
|
|
|
|
|
|
add eax, ebx |
|
|
|
|
|
|
|
; eax now = x^2 + y^2 |
|
|
|
|
|
|
|
mov ebx, [Zoom] |
|
|
|
sar ebx, 8 |
|
|
|
imul eax, ebx |
|
|
|
|
|
|
|
mov ebx, [ColorOffset] |
|
|
|
shr ebx, 8 |
|
|
|
mov bh, bl |
|
|
|
add ax, bx |
|
|
|
and ah, 0x7f |
|
|
|
mov ebx, eax |
|
|
|
|
|
|
|
; mov bh, al |
|
|
|
mov eax, [Py] |
|
|
|
shr eax, 4 |
|
|
|
add eax, edx |
|
|
|
add eax, edx |
|
|
|
imul eax, eax |
|
|
|
|
|
|
|
stosw |
|
|
|
add ebx, eax |
|
|
|
|
|
|
|
; sar ebx, 8 |
|
|
|
mov eax, [ColorOffset] |
|
|
|
push edx |
|
|
|
xor edx, edx |
|
|
|
idiv ebp |
|
|
|
pop edx |
|
|
|
|
|
|
|
; mov ebp, eax |
|
|
|
; mov bl, (0xda - 0xb3) |
|
|
|
; div byte bl |
|
|
|
; mov bl, ah |
|
|
|
; add bl, 0xb3 |
|
|
|
; mov eax, ebp |
|
|
|
xchg eax, ebx |
|
|
|
|
|
|
|
; mov al, bl |
|
|
|
; push eax |
|
|
|
; push edx |
|
|
|
; rdtsc |
|
|
|
; mov ebx, eax |
|
|
|
; shr ebx, 26 |
|
|
|
; pop edx |
|
|
|
; pop eax |
|
|
|
add ax, bx |
|
|
|
|
|
|
|
mov al, ah |
|
|
|
|
|
|
|
stosw |
|
|
|
|
|
|
|
inc ecx |
|
|
|
cmp ecx, 80 |
|
|
|
jne DrawBG |
|
|
|
jne .DrawLoop |
|
|
|
|
|
|
|
mov ecx, 0 |
|
|
|
xor ecx, ecx |
|
|
|
inc edx |
|
|
|
cmp edx, 24 |
|
|
|
jne DrawBG |
|
|
|
cmp edx, 25-1 |
|
|
|
jne .DrawLoop |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteProtectedModeString: |
|
|
|
cld |
|
|
|
|
|
|
|
xor eax, eax |
|
|
|
|
|
|
|
in al, 0x60 ; Get the scan code from the keyboard |
|
|
|
; mov byte [0x98765], al |
|
|
|
; cmp al, 0x01 |
|
|
|
; je .ThereWasNothing |
|
|
|
; cmp al, 0x2A ; Left Shift Make |
|
|
|
; je .ThereWasNothing |
|
|
|
; cmp al, 0x36 ; Right Shift Make |
|
|
|
; je .ThereWasNothing |
|
|
|
; cmp al, 0xAA ; Left Shift Break |
|
|
|
; je .ThereWasNothing |
|
|
|
; cmp al, 0xB6 ; Right Shift Break |
|
|
|
; je .ThereWasNothing |
|
|
|
cmp al, 0x01 |
|
|
|
je .KeyEscape |
|
|
|
cmp al, 0x4b; left |
|
|
|
in al, IOKeyData ; Get the scan code from the keyboard |
|
|
|
|
|
|
|
test al, 0x80 |
|
|
|
jnz .ThereWasNothing |
|
|
|
|
|
|
|
cmp al, 75; left |
|
|
|
je .KeyLeft |
|
|
|
cmp al, 0x48; up |
|
|
|
|
|
|
|
cmp al, 72; up |
|
|
|
je .KeyUp |
|
|
|
cmp al, 0x50; right |
|
|
|
|
|
|
|
cmp al, 80; right |
|
|
|
je .KeyDown |
|
|
|
cmp al, 0x4d; down |
|
|
|
|
|
|
|
cmp al, 77; down |
|
|
|
je .KeyRight |
|
|
|
cmp al, 0x33; < |
|
|
|
|
|
|
|
cmp al, 51; < |
|
|
|
je .KeyLess |
|
|
|
cmp al, 0x34; > |
|
|
|
|
|
|
|
cmp al, 52; > |
|
|
|
je .KeyGreater |
|
|
|
; test al, 0x80 |
|
|
|
; je .ThereWasSomething |
|
|
|
|
|
|
|
cmp al, 1 ; Escape |
|
|
|
je .KeyEscape |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.ThereWasNothing: |
|
|
|
mov [Key], byte ' ' |
|
|
|
jmp .PrintKeyLegend |
|
|
@ -381,6 +371,9 @@ WriteProtectedModeString: |
|
|
|
.KeyGreater: |
|
|
|
mov [Key], byte '>' |
|
|
|
add [Zoom], dword 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.PrintKeyLegend: |
|
|
|
lea esi, [ThereWasSomethingStr] |
|
|
|
|
|
|
@ -397,23 +390,26 @@ WriteProtectedModeString: |
|
|
|
.break_print_loop: |
|
|
|
|
|
|
|
lea edi, [VIDEO + (80*24 + 1)*2] |
|
|
|
mov ecx, 40 |
|
|
|
push edi |
|
|
|
mov ecx, 34 |
|
|
|
xor eax, eax |
|
|
|
rep stosw |
|
|
|
lea edi, [VIDEO + (80*24 + 1)*2] |
|
|
|
rep stosd |
|
|
|
pop edi |
|
|
|
|
|
|
|
mov eax, dword [Px] |
|
|
|
sar eax, 4 |
|
|
|
call StringifyEax10 |
|
|
|
call IntToString |
|
|
|
|
|
|
|
lea edi, [VIDEO + (80*24 + 11)*2] |
|
|
|
add edi, 12*2 |
|
|
|
|
|
|
|
mov eax, dword [Py] |
|
|
|
sar eax, 4 |
|
|
|
call StringifyEax10 |
|
|
|
call IntToString |
|
|
|
|
|
|
|
lea edi, [VIDEO + (80*24 + 21)*2] |
|
|
|
mov eax, dword [Zoom] |
|
|
|
sar eax, 8 |
|
|
|
call StringifyEax10 |
|
|
|
add edi, 12*2 |
|
|
|
mov eax, [Zoom] |
|
|
|
sar eax, 9 |
|
|
|
call IntToString |
|
|
|
|
|
|
|
add [ColorOffset], dword 1 |
|
|
|
|
|
|
@ -424,7 +420,7 @@ HALT: |
|
|
|
jmp HALT |
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
StringifyEax10: |
|
|
|
IntToString: |
|
|
|
; Puts the stringified version of eax on the stack |
|
|
|
; IN: eax = number to write |
|
|
|
; IN: edi = base of where to write string |
|
|
@ -452,8 +448,19 @@ StringifyEax10: |
|
|
|
mov byte [.buffer + ecx], dl |
|
|
|
jmp .loop_divide |
|
|
|
.break_loop_divide: |
|
|
|
; dec ecx |
|
|
|
|
|
|
|
add edi, 20 |
|
|
|
|
|
|
|
test ecx, ecx |
|
|
|
jnz .NotZero |
|
|
|
|
|
|
|
mov ax, (0x0f << 8) | '0' |
|
|
|
stosw |
|
|
|
popad |
|
|
|
ret |
|
|
|
|
|
|
|
.NotZero: |
|
|
|
|
|
|
|
sub edi, ecx |
|
|
|
sub edi, ecx |
|
|
|
|
|
|
@ -482,7 +489,7 @@ StringifyEax10: |
|
|
|
; ------------------------------------------------------------------------------ |
|
|
|
Reboot: |
|
|
|
in al, 0x64 |
|
|
|
test al, 00000010b ; Wait for an empty Input Buffer |
|
|
|
test al, 0x2 ; Wait for an empty Input Buffer |
|
|
|
jne Reboot |
|
|
|
mov al, 0xFE |
|
|
|
out 0x64, al ; Send the reboot call to the keyboard controller |
|
|
@ -496,6 +503,6 @@ Reboot: |
|
|
|
Key: db " ' ", 0 |
|
|
|
Px: dd 0 |
|
|
|
Py: dd 0 |
|
|
|
ColorOffset: dw 0 |
|
|
|
Zoom: dw 1 |
|
|
|
ColorOffset: dd 0 |
|
|
|
Zoom: dd (4<<9) |
|
|
|
align 512 |