This commit is contained in:
2021-09-14 18:35:52 +03:00
parent f052f2294e
commit d605c6a016
84 changed files with 3647 additions and 1192 deletions

Binary file not shown.

View File

@@ -1,10 +1,13 @@
;***** memory.inc ****************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Enable A20 address line *
;* ======================= *
;* *
;************************************************************ cta os */
;********************************************
; Enable A20 address line
;
; OS Development Series
;********************************************
%ifndef __A20_INC_CTA000__
%define __A20_INC_CTA000__
bits 16 ; real mode 16 bit code
@@ -53,3 +56,5 @@ a20wait2:
test al,1
jz a20wait2
ret
%endif

View File

@@ -1,39 +1,38 @@
;***** bootinfo.inc **************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Multiboot information structure *
;* =============================== *
;* *
;************************************************************ cta os */
;*******************************************************
;
; bootinfo.inc
; multiboot information structure
;
; OS Development Series
;*******************************************************
%ifndef __BOOTINFO_INC_67343546FDCC56AAB872_INCLUDED__
%define __BOOTINFO_INC_67343546FDCC56AAB872_INCLUDED__
%ifndef __BOOTINFO_INC_CTA001__
%define __BOOTINFO_INC_CTA001__
struc multiboot_info
.flags resd 1
.memoryLo resd 1
.memoryHi resd 1
.bootDevice resd 1
.cmdLine resd 1
.mods_count resd 1
.mods_addr resd 1
.syms0 resd 1
.syms1 resd 1
.syms2 resd 1
.mmap_length resd 1
.mmap_addr resd 1
.drives_length resd 1
.drives_addr resd 1
.config_table resd 1
.bootloader_name resd 1
.apm_table resd 1
.vbe_control_info resd 1
.vbe_mode_info resd 1
.vbe_mode resw 1
.vbe_interface_seg resw 1
.vbe_interface_off resw 1
.vbe_interface_len resw 1
.flags resd 1
.memoryLo resd 1
.memoryHi resd 1
.bootDevice resd 1
.cmdLine resd 1
.mods_count resd 1
.mods_addr resd 1
.syms0 resd 1
.syms1 resd 1
.syms2 resd 1
.mmap_length resd 1
.mmap_addr resd 1
.drives_length resd 1
.drives_addr resd 1
.config_table resd 1
.bootloader_name resd 1
.apm_table resd 1
.vbe_control_info resd 1
.vbe_mode_info resd 1
.vbe_mode resw 1
.vbe_interface_seg resw 1
.vbe_interface_off resw 1
.vbe_interface_len resw 1
endstruc

View File

@@ -1,9 +1,16 @@
;***** common.inc ****************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Common definitions, variables *
;* ============================= *
;* *
;************************************************************ cta os */
%ifndef _COMMON_INC_INCLUDED
%define _COMMON_INC_INCLUDED
%ifndef _COMMON_INC_CTA002__
%define _COMMON_INC_CTA002__
; where the kernel is to be loaded to in protected mode
%define IMAGE_PMODE_BASE 0x100000
%define IMAGE_PMODE_BASE 0xC0000000
; where the kernel is to be loaded to in real mode
%define IMAGE_RMODE_BASE 0x3000

View File

@@ -1,14 +1,13 @@
;***** FAT12.inc *****************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Fat12 filesystem for 3.5" floppies *
;* ================================== *
;* *
;************************************************************ cta os */
;*******************************************************
;
; Fat12.inc
; FAT12 filesystem for 3-1/2 floppies
;
; OS Development Series
;*******************************************************
%ifndef __FAT12_INC_67343546FDCC56AAB872_INCLUDED__
%define __FAT12_INC_67343546FDCC56AAB872_INCLUDED__
%ifndef __FAT12_INC_CTA003__
%define __FAT12_INC_CTA003__
bits 16

View File

@@ -1,18 +1,17 @@
;***** floppy16.inc **************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Floppy drive interface routines *
;* =============================== *
;* *
;************************************************************ cta os */
;*******************************************************
;
; Floppy16.inc
; Floppy drive interface routines
;
; OS Development Series
;*******************************************************
%ifndef __FLOPPY16_INC_67343546FDCC56AAB872_INCLUDED__
%define __FLOPPY16_INC_67343546FDCC56AAB872_INCLUDED__
%ifndef __FLOPPY16_INC_CTA004__
%define __FLOPPY16_INC_CTA004__
bits 16
bpbOEM db "My OS "
bpbOEM db "CTA OS "
bpbBytesPerSector: DW 512
bpbSectorsPerCluster: DB 1
bpbReservedSectors: DW 1
@@ -29,7 +28,7 @@ bsDriveNumber: DB 0
bsUnused: DB 0
bsExtBootSignature: DB 0x29
bsSerialNumber: DD 0xa0a1a2a3
bsVolumeLabel: DB "MOS FLOPPY "
bsVolumeLabel: DB "CTA OS "
bsFileSystem: DB "FAT12 "
datasector dw 0x0000

View File

@@ -1,14 +1,14 @@
;***** gdt.inc *******************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Global Descriptor Table routines *
;* ===================== *
;* *
;************************************************************ cta os */
;*************************************************
; Gdt.inc
; -GDT Routines
;
; OS Development Series
;*************************************************
%ifndef __GDT_INC_67343546FDCC56AAB872_INCLUDED__
%define __GDT_INC_67343546FDCC56AAB872_INCLUDED__
%ifndef __GDT_INC_CTA005__
%define __GDT_INC_CTA005__
bits 16

View File

@@ -0,0 +1,98 @@
gatherinfo:
pusha
push es
xor eax, eax
mov ebx, eax
mov ecx, eax
mov edx, eax
;Boot device
mov dword [multiboot_info_bootDevice], 0 ; drive 0
;Detect current video mode
mov ah, 0Fh
int 10h
mov byte [multiboot_info_video_mode], al
mov byte [multiboot_info_video_columns], ah
mov byte [multiboot_info_video_page], bh
;Get VESA information
xor eax, eax
xor ebx, ebx
xor edx, edx
mov dword [TemporaryStorage], vbeControllerInfo
mov ax, word [TemporaryStorage]
mov dx, word [TemporaryStorage+2]
shl ax, 1
mov es, ax
mov di, dx
mov ax, 0x4f00
int 10h
cmp ax, 0x004F
; not correct
je vesa_00_ok
mov dword [multiboot_info_vbe_control_info], 0x0 ; failure
jmp vesa_00_done
; correct
vesa_00_ok:
mov dword [multiboot_info_vbe_control_info], vbeControllerInfo ; success
vesa_00_done:
;Write VBE 2.0+ Interface pointers to 0
mov word [multiboot_info_vbe_interface_seg], 0
mov word [multiboot_info_vbe_interface_off], 0
mov word [multiboot_info_vbe_interface_len], 0
;Get VESA Current mode
mov ax, 4f03h
int 10h
cmp ax, 004fh
je vesa_01_ok
; not ok:
mov word [multiboot_info_vbe_mode], 0
jmp vesa_01_done
vesa_01_ok:
mov word [multiboot_info_vbe_mode], bx
vesa_01_done:
;Get some info about current VESA mode
xor eax, eax
mov ebx, eax
mov edx, eax
mov eax, vbeControllerInfo
push eax
and eax, 0fh
mov dx, ax
pop eax
shr eax, 4
mov es, ax
mov di, dx
mov ax, 4f01h
mov cx, [multiboot_info_vbe_mode]
int 10h
cmp ax, 004fh
je vesa_02_ok
; not ok:
mov word [multiboot_info_vbe_mode_info], 0
jmp vesa_02_done
vesa_02_ok:
mov word [multiboot_info_vbe_mode_info], vbeModeInfo
vesa_02_done:
pop es
popa
ret

View File

@@ -1,13 +1,13 @@
;***** memory.inc ****************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Basic memory routines *
;* ===================== *
;* *
;************************************************************ cta os */
;*************************************************
; Memory.inc
; -Basic memory routines
;
; OS Development Series
;*************************************************
%ifndef __MEMORY_INC_67343546FDCC56AAB872_INCLUDED__
%define __MEMORY_INC_67343546FDCC56AAB872_INCLUDED__
%ifndef __MEMORY_INC_CTA006__
%define __MEMORY_INC_CTA006__
bits 16
@@ -29,43 +29,50 @@ endstruc
;---------------------------------------------
BiosGetMemoryMap:
pushad
xor ebx, ebx
xor bp, bp ; number of entries stored here
mov edx, 'PAMS' ; 'SMAP'
xor bp, bp
mov edx, 0x0534D4150 ; Place "SMAP" into edx
mov eax, 0xe820
mov ecx, 24 ; memory map entry struct is 24 bytes
int 0x15 ; get first entry
jc .error
cmp eax, 'PAMS' ; bios returns SMAP in eax
jne .error
test ebx, ebx ; if ebx=0 then list is one entry long; bail out
je .error
jmp .start
.next_entry:
mov edx, 'PAMS' ; some bios's trash this register
mov ecx, 24 ; entry is 24 bytes
mov eax, 0xe820
int 0x15 ; get next entry
.start:
jcxz .skip_entry ; if actual returned bytes is 0, skip entry
mov [es:di + 20], dword 1 ; force a valid ACPI 3.X entry
mov ecx, 24
int 0x15
jc short .failed ; carry set on first call means "unsupported function"
mov edx, 0x0534D4150 ; Some BIOSes apparently trash this register?
cmp eax, edx ; on success, eax must have been reset to "SMAP"
jne short .failed
test ebx, ebx ; ebx = 0 implies list is only 1 entry long (worthless)
je short .failed
jmp short .jmpin
.e820lp:
mov eax, 0xe820 ; eax, ecx get trashed on every int 0x15 call
mov [es:di + 20], dword 1 ; force a valid ACPI 3.X entry
mov ecx, 24 ; ask for 24 bytes again
int 0x15
jc short .e820f ; carry set means "end of list already reached"
mov edx, 0x0534D4150 ; repair potentially trashed register
.jmpin:
jcxz .skipent ; skip any 0 length entries
cmp cl, 20 ; got a 24 byte ACPI 3.X response?
jbe short .notext
test byte [es:di + 20], 1 ; if so: is the "ignore this data" bit clear?
je short .skipent
.notext:
mov ecx, [es:di + MemoryMapEntry.length] ; get length (low dword)
test ecx, ecx ; if length is 0 skip it
jne short .good_entry
mov ecx, [es:di + MemoryMapEntry.length + 4]; get length (upper dword)
jecxz .skip_entry ; if length is 0 skip it
.good_entry:
inc bp ; increment entry count
add di, 24 ; point di to next entry in buffer
.skip_entry:
cmp ebx, 0 ; if ebx return is 0, list is done
jne .next_entry ; get next entry
jmp .done
.error:
stc
.done:
popad
mov ecx, [es:di + 8] ; get lower dword of memory region length
test ecx, ecx ; is the qword == 0?
jne short .goodent
mov ecx, [es:di + 12] ; get upper dword of memory region length
jecxz .skipent ; if length qword is 0, skip entry
.goodent:
inc bp ; got a good entry: ++count, move to next storage spot
add di, 24
.skipent:
test ebx, ebx ; if ebx resets to 0, list is complete
jne short .e820lp
.e820f:
ret ; bp=entry count
.failed:
stc ; "function unsupported" error exit
ret
;---------------------------------------------
@@ -75,21 +82,17 @@ BiosGetMemoryMap:
; ret\ bx=0 and ax= -1 on error
;---------------------------------------------
BiosGetMemorySize64MB_32Bit:
BiosGetMemorySize64MB_32bit:
push ecx
push edx
xor ecx, ecx
xor edx, edx
mov ax, 0xe881
int 0x15
mov eax, 0xe881
int 0x15
jc .error
cmp ah, 0x86 ;unsupported function
je .error
cmp ah, 0x80 ;invalid command
je .error
jcxz .use_ax ;bios may have stored it in ax,bx or cx,dx. test if cx is 0
mov ax, cx ;its not, so it should contain mem size; store it
mov bx, dx
jcxz .use_ax ;bios may have stored it in ax,bx or cx,dx. test if cx is 0
mov eax, ecx ;its not, so it should contain mem size; store it
mov ebx, edx
.use_ax:
pop edx ;mem size is in ax and bx already, return it
@@ -102,7 +105,7 @@ BiosGetMemorySize64MB_32Bit:
pop edx
pop ecx
ret
;---------------------------------------------
; Get memory size for >64M configuations
; ret\ ax=KB between 1MB and 16MB
@@ -132,8 +135,6 @@ BiosGetMemorySize64MB:
ret
.error:
mov si, msgNotSupported
call Puts16
mov ax, -1
mov bx, 0
pop edx
@@ -170,6 +171,4 @@ BiosGetExtendedMemorySize:
ret
msgNotSupported db 0x0A, 0x0D, "BiosGetMemorySize64MB: function not supported.",0x0A, 0x0D, 0x00
%endif

83
SysBoot/stage2/paging.inc Normal file
View File

@@ -0,0 +1,83 @@
;***** paging.inc ****************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Basic paging for bootloader *
;* =========================== *
;* *
;************************************************************ cta os */
%ifndef __PAGING_INC_CTA007__
%define __PAGING_INC_CTA007__
[bits 32]
%define PAGE_DIR 0x9C000 ; page directory table
%define PAGE_TABLE_0 0x9D000 ; 0th page table. Address must be 4KB aligned
%define PAGE_TABLE_768 0x9E000 ; 768th page table. Address must be 4KB aligned
%define PAGE_TABLE_ENTRIES 1024 ; each page table has 1024 entries
%define PRIV 3 ; attributes (page is present;page is writable; supervisor mode)
;****************************************
; Enable Paging
;****************************************
EnablePaging:
pusha ; save stack frame
;------------------------------------------
; idenitity map 1st page table (4MB)
;------------------------------------------
mov eax, PAGE_TABLE_0 ; first page table
mov ebx, 0x0 | PRIV ; starting physical address of page
mov ecx, PAGE_TABLE_ENTRIES ; for every page in table...
.loop:
mov dword [eax], ebx ; write the entry
add eax, 4 ; go to next page entry in table (Each entry is 4 bytes)
add ebx, 4096 ; go to next page address (Each page is 4Kb)
loop .loop ; go to next entry
;------------------------------------------
; set up the entries in the directory table
;------------------------------------------
mov eax, PAGE_TABLE_0 | PRIV ; 1st table is directory entry 0
mov dword [PAGE_DIR], eax
mov eax, PAGE_TABLE_768 | PRIV ; 768th entry in directory table
mov dword [PAGE_DIR+(768*4)], eax
;------------------------------------------
; install directory table
;------------------------------------------
mov eax, PAGE_DIR
mov cr3, eax
;------------------------------------------
; enable paging
;------------------------------------------
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
;------------------------------------------
; map the 768th table to physical addr 1MB
; the 768th table starts the 3gb virtual address
;------------------------------------------
mov eax, PAGE_TABLE_768 ; first page table
mov ebx, 0x100000 | PRIV ; starting physical address of page
mov ecx, PAGE_TABLE_ENTRIES ; for every page in table...
.loop2:
mov dword [eax], ebx ; write the entry
add eax, 4 ; go to next page entry in table (Each entry is 4 bytes)
add ebx, 4096 ; go to next page address (Each page is 4Kb)
loop .loop2 ; go to next entry
popa
ret
%endif

View File

@@ -1,12 +1,10 @@
;*******************************************************
;
; Stage2.asm
; Stage2 Bootloader
;
; OS Development Series
;*******************************************************
;***** stage2.asm ****************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Stage 2 Bootloader *
;* ================== *
;* *
;************************************************************ cta os */
bits 16
org 0x500
@@ -24,6 +22,7 @@ jmp main ; go to start
%include "common.inc"
;%include "bootinfo.inc"
%include "memory.inc"
%include "getdata.inc"
;*******************************************************
; Data Section
@@ -32,28 +31,51 @@ jmp main ; go to start
msgFailure db 0x0D, 0x0A, "FATAL ERROR: Kernel file KERNEL.CTA missing or corrupt. Press Any Key to Reboot.", 0x0D, 0x0A, 0x0A, 0x00
boot_info:
multiboot_info_flags dd 0
multiboot_info_memoryLo dd 0
multiboot_info_memoryHi dd 0
multiboot_info_bootDevice dd 0
multiboot_info_cmdLine dd 0
multiboot_info_mods_count dd 0
multiboot_info_mods_addr dd 0
multiboot_info_syms0 dd 0
multiboot_info_syms1 dd 0
multiboot_info_syms2 dd 0
multiboot_info_mmap_length dd 0
multiboot_info_mmap_addr dd 0
multiboot_info_drives_length dd 0
multiboot_info_drives_addr dd 0
multiboot_info_config_table dd 0
multiboot_info_bootloader_name dd 0
multiboot_info_apm_table dd 0
multiboot_info_vbe_control_info dd 0
multiboot_info_vbe_mode_info dw 0
multiboot_info_vbe_interface_seg dw 0
multiboot_info_vbe_interface_off dw 0
multiboot_info_vbe_interface_len dw 0
; Memory
multiboot_info_memoryLo dd 0
multiboot_info_memoryHi dd 0
; Boot device
multiboot_info_bootDevice dd 0
; Pointer to a char[] string. (not implemented)
multiboot_info_cmdLine dd 0
; Other modules loaded by bootloader. (not implemented
multiboot_info_mods_count dd 0
multiboot_info_mods_addr dd 0
; Pointer to memory map
multiboot_info_mmap_length dd 0
multiboot_info_mmap_addr dd 0
; TODO:
multiboot_info_drives_length dd 0
multiboot_info_drives_addr dd 0
; BIOS ROM config table. TODO:
multiboot_info_config_table dd 0
; CTA bootloader name
multiboot_info_bootloader_name db "CTA", 0
; TODO:
multiboot_info_apm_table dd 0
; Returns VGA current video mode info
multiboot_info_video_mode db 0
multiboot_info_video_columns db 0
multiboot_info_video_page db 0
; Returns VESA information
multiboot_info_vbe_control_info dd 0
multiboot_info_vbe_mode_info dd 0
multiboot_info_vbe_mode dw 0
multiboot_info_vbe_interface_seg dw 0
multiboot_info_vbe_interface_off dw 0
multiboot_info_vbe_interface_len dw 0
vbeControllerInfo:
vbeControllerInfo_signature dd 0 ; "VESA", taken as 4 bytes
vbeControllerInfo_version dw 0 ; 0x0300 for VBE 3.0
vbeControllerInfo_oemString dd 0 ; isa vbeFarPtr, taken as 2 shorts
vbeControllerInfo_capabilities dd 0 ; taken as 4 bytes
vbeControllerInfo_videomodes dd 0 ; isa vbeFarPtr, taken as 2 shorts
vbeControllerInfo_totalMemory dw 0 ; as # of 64k blocks
TemporaryStorage dd 0 ; temporary storage
main:
@@ -70,34 +92,48 @@ main:
mov sp, 0xFFFF
sti ; enable interrupts
mov [multiboot_info_bootDevice], dl
call _EnableA20
call InstallGDT
sti
;-------------------------------;
; Fill in the boot structure ;
;-------------------------------;
; Memory Size
xor eax, eax
xor ebx, ebx
call BiosGetMemorySize64MB
mov word [multiboot_info_memoryHi], bx
mov word [multiboot_info_memoryLo], ax
push eax
mov eax, 64
mul ebx
mov ecx, eax
pop eax
add eax, ecx
add eax, 1024 ; the routine doesnt add the KB between 0-1MB; add it
mov dword [multiboot_info_memoryHi], 0
mov dword [multiboot_info_memoryLo], eax
;Memory map
mov eax, 0x0
mov ds, ax
mov di, 0x1000
call BiosGetMemoryMap
mov dword [multiboot_info_mmap_addr], 0x1000
mov dword [multiboot_info_mmap_addr], 0x1000 ; address
xor eax, eax
mov ax, bp
mov dword [multiboot_info_mmap_length], eax
mov dword [multiboot_info_mmap_length], eax ; length
call gatherinfo
call LoadRoot
mov ebx, 0
mov ebp, IMAGE_RMODE_BASE
mov esi, ImageName
call LoadFile ; load our file
call LoadRoot
mov ebx, 0
mov ebp, IMAGE_RMODE_BASE
mov esi, ImageName
call LoadFile ; load our file
mov dword [ImageSize], ecx
cmp ax, 0
je EnterStage3
@@ -129,6 +165,8 @@ EnterStage3:
bits 32
%include "paging.inc"
BadImage db "FATAL ERROR: Kernel file KERNEL.CTA missing or corrupt. Press Any Key to Reboot.", 0
Stage3:
@@ -143,6 +181,7 @@ Stage3:
mov es, ax
mov esp, 90000h ; stack begins from 90000h
call EnablePaging
CopyImage:
mov eax, dword [ImageSize]
@@ -156,7 +195,7 @@ CopyImage:
mov ecx, eax
rep movsd ; copy image to its protected mode address
mov eax, 0x2badb002 ; multiboot specs say eax should be this
mov eax, 0xC0DEcC7A ; cta bootloader specific
mov ebx, 0
;edx=8
@@ -169,4 +208,56 @@ CopyImage:
cli
hlt
vbeModeInfo:
vbeModeInfo_attributes dw 0
vbeModeInfo_winA db 0
vbeModeInfo_winB db 0
vbeModeInfo_granularity dw 0
vbeModeInfo_winsize dw 0
vbeModeInfo_segmentA dw 0
vbeModeInfo_segmentB dw 0
vbeModeInfo_realFctPtr dd 0
vbeModeInfo_pitc dw 0 ; // bytes per scanline
vbeModeInfo_Xres dw 0
vbeModeInfo_Yres dw 0
vbeModeInfo_Wchar db 0
vbeModeInfo_Ychar db 0
vbeModeInfo_planes db 0
vbeModeInfo_bpp db 0
vbeModeInfo_banks db 0
vbeModeInfo_memory_model db 0
vbeModeInfo_bank_size db 0
vbeModeInfo_image_pages db 0
vbeModeInfo_reserved0 db 0
; VBE v1.2+
vbeModeInfo_red_mask db 0
vbeModeInfo_red_position db 0
vbeModeInfo_green_mask db 0
vbeModeInfo_green_position db 0
vbeModeInfo_blue_mask db 0
vbeModeInfo_blue_position db 0
vbeModeInfo_rsv_mask db 0
vbeModeInfo_rsv_position db 0
vbeModeInfo_directcolor_attrib db 0
; VBE v2.0+
vbeModeInfo_physbase dd 0
vbeModeInfo_start_offscreen_mem dd 0
vbeModeInfo_size_offscreen_mem dw 0
; VBE v3.0+
vbeModeInfo_bytes_per_scanline dw 0
vbeModeInfo_number_images_banked db 0
vbeModeInfo_number_images_linear db 0
vbeModeInfo_linear_red_mask db 0
vbeModeInfo_linear_red_pos db 0
vbeModeInfo_linear_green_mask db 0
vbeModeInfo_linear_green_pos db 0
vbeModeInfo_linear_blue_mask db 0
vbeModeInfo_linear_blue_pos db 0
vbeModeInfo_linear_res_mask db 0
vbeModeInfo_linear_res_pos db 0
vbeModeInfo_max_pixel_clock dd 0

View File

@@ -1,13 +1,14 @@
;***** stdio.inc *****************************************************
;* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
;* *
;* Standard Input/Output routines *
;* ============================== *
;* *
;************************************************************ cta os */
;*************************************************
; stdio.inc
; -Input/Output routines
;
; OS Development Series
;*************************************************
%ifndef __STDIO_INC_67343546FDCC56AAB872_INCLUDED__
%define __STDIO_INC_67343546FDCC56AAB872_INCLUDED__
%ifndef __STDIO_INC_CTA008__
%define __STDIO_INC_CTA008__
;==========================================================
@@ -82,15 +83,15 @@ PutINT:
; 32 Bit Protected Mode Routines
;==========================================================
bits 32
;bits 32
%define VIDMEM 0xB8000 ; video memory
%define COLS 80 ; width and height of screen
%define LINES 25
%define CHAR_ATTRIB 14 ; character attribute (White text on black background)
;%define VIDMEM 0xB8000 ; video memory
;%define COLS 80 ; width and height of screen
;%define LINES 25
;%define CHAR_ATTRIB 14 ; character attribute (White text on black background)
_CurX db 0 ; current x/y location
_CurY db 0
;_CurX db 0 ; current x/y location
;_CurY db 0
;**************************************************;
; Putch32 ()
@@ -98,56 +99,56 @@ _CurY db 0
; BL => Character to print
;**************************************************;
Putch32:
pusha
mov edi, VIDMEM
xor eax, eax ; clear eax
; y * screen width
mov ecx, COLS*2 ; Mode 7 has 2 bytes per char, so its COLS*2 bytes per line
mov al, byte [_CurY] ; get y pos
mul ecx ; multiply y*COLS
push eax ; save eax--the multiplication
;Putch32:
;
; pusha
; mov edi, VIDMEM
;
; xor eax, eax ; clear eax
;
; ; y * screen width
;
; mov ecx, COLS*2 ; Mode 7 has 2 bytes per char, so its COLS*2 bytes per line
; mov al, byte [_CurY] ; get y pos
; mul ecx ; multiply y*COLS
; push eax ; save eax--the multiplication
; now add _CurX * 2
mov al, byte [_CurX] ; multiply _CurX by 2 because it is 2 bytes per char
mov cl, 2
mul cl
pop ecx ; pop y*COLS result
add eax, ecx
; mov al, byte [_CurX] ; multiply _CurX by 2 because it is 2 bytes per char
; mov cl, 2
; mul cl
; pop ecx ; pop y*COLS result
; add eax, ecx
; add the position to draw to the base of vid memory
xor ecx, ecx
add edi, eax ; add it to the base address
; xor ecx, ecx
; add edi, eax ; add it to the base address
;
; watch for new line
cmp bl, 0x0A ; is it a newline character?
je .Row ; yep--go to next row
; cmp bl, 0x0A ; is it a newline character?
; je .Row ; yep--go to next row
;
; print the character
mov dl, bl ; Get character
mov dh, CHAR_ATTRIB ; the character attribute
mov word [edi], dx ; write to video display
; mov dl, bl ; Get character
; mov dh, CHAR_ATTRIB ; the character attribute
; mov word [edi], dx ; write to video display
;
; ; go to next location
; go to next location
; inc byte [_CurX] ; go to next character
; jmp .done ; nope, bail out
inc byte [_CurX] ; go to next character
jmp .done ; nope, bail out
;.Row:
; mov byte [_CurX], 0 ; go back to col 0
; inc byte [_CurY] ; go to next row
.Row:
mov byte [_CurX], 0 ; go back to col 0
inc byte [_CurY] ; go to next row
.done:
popa
ret
;.done:
; popa
; ret
;**************************************************;
; Puts32 ()
@@ -155,47 +156,47 @@ Putch32:
; parm\ EBX = address of string to print
;**************************************************;
Puts32:
;Puts32:
pusha
push ebx ; copy the string address
pop edi
; pusha
; push ebx ; copy the string address
; pop edi
.loop:
;.loop:
;-------------------------------;
; Get character ;
;-------------------------------;
mov bl, byte [edi] ; get next character
cmp bl, 0 ; is it 0 (Null terminator)?
je .done ; yep-bail out
; mov bl, byte [edi] ; get next character
; cmp bl, 0 ; is it 0 (Null terminator)?
; je .done ; yep-bail out
;-------------------------------;
; Print the character ;
;-------------------------------;
call Putch32 ; Nope-print it out
; call Putch32 ; Nope-print it out
;-------------------------------;
; Go to next character ;
;-------------------------------;
inc edi ; go to next character
jmp .loop
; inc edi ; go to next character
; jmp .loop
.done:
;.done:
;-------------------------------;
; Update hardware cursor ;
;-------------------------------;
mov bh, byte [_CurY] ; get current position
mov bl, byte [_CurX]
call MovCur ; update cursor
; mov bh, byte [_CurY] ; get current position
; mov bl, byte [_CurX]
; call MovCur ; update cursor
popa ; restore registers, and return
ret
; popa ; restore registers, and return
; ret
;**************************************************;
; MoveCur ()
@@ -206,74 +207,74 @@ Puts32:
bits 32
;bits 32
MovCur:
pusha
;MovCur:
; pusha
;
;-------------------------------;
; Get current position ;
;-------------------------------;
; location = _CurX + _CurY * COLS
xor eax, eax
mov ecx, COLS
mov al, bh ; get y pos
mul ecx ; multiply y*COLS
add al, bl ; Now add x
mov ebx, eax
; xor eax, eax
; mov ecx, COLS
; mov al, bh ; get y pos
; mul ecx ; multiply y*COLS
; add al, bl ; Now add x
; mov ebx, eax
;
;--------------------------------------;
; Set low byte index to VGA register ;
;--------------------------------------;
mov al, 0x0f
mov dx, 0x03D4
out dx, al
mov al, bl
mov dx, 0x03D5
out dx, al ; low byte
; mov al, 0x0f
; mov dx, 0x03D4
; out dx, al
;
; mov al, bl
; mov dx, 0x03D5
; out dx, al ; low byte
;---------------------------------------;
; Set high byte index to VGA register ;
;---------------------------------------;
xor eax, eax
; xor eax, eax
mov al, 0x0e
mov dx, 0x03D4
out dx, al
; mov al, 0x0e
; mov dx, 0x03D4
; out dx, al
mov al, bh
mov dx, 0x03D5
out dx, al ; high byte
; mov al, bh
; mov dx, 0x03D5
; out dx, al ; high byte
popa
ret
; popa
; ret
;**************************************************;
; ClrScr32 ()
; - Clears screen
;**************************************************;
bits 32
ClrScr32:
pusha
cld
mov edi, VIDMEM
mov cx, 2000
mov ah, CHAR_ATTRIB
mov al, ' '
rep stosw
mov byte [_CurX], 0
mov byte [_CurY], 0
popa
ret
;
;bits 32
;
;ClrScr32:
;
; pusha
; cld
; mov edi, VIDMEM
; mov cx, 2000
; mov ah, CHAR_ATTRIB
; mov al, ' '
; rep stosw
; mov byte [_CurX], 0
; mov byte [_CurY], 0
; popa
; ret
;**************************************************;
; GotoXY ()
@@ -282,14 +283,14 @@ ClrScr32:
; parm\ AH=Y position
;**************************************************;
bits 32
;bits 32
GotoXY:
pusha
mov [_CurX], al
mov [_CurY], ah
popa
ret
;GotoXY:
; pusha
; mov [_CurX], al
; mov [_CurY], ah
; popa
; ret
%endif ;__STDIO_INC_67343546FDCC56AAB872_INCLUDED__