Skip to content

Commit

Permalink
feat: disk.lib, wmemory.lib, fix monitor.lib, window.asm
Browse files Browse the repository at this point in the history
  • Loading branch information
pablogeokar committed Jan 3, 2025
1 parent 0596e02 commit d5eb5ce
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 38 deletions.
Binary file modified disk.img
Binary file not shown.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Esse comando cria um arquivo chamado disk.img com espaço suficiente para armaze
dd if=/dev/zero of=disk.img bs=512 count=2880
dd if=bin/boot.bin of=disk.img bs=512 count=1 conv=notrunc
dd if=bin/kernel.bin of=disk.img bs=512 seek=1 conv=notrunc
dd if=bin/window.bin of=disk.img bs=512 seek=2 conv=notrunc
```

### 2.3 Gerando a imagem ISO (opcional, utilizar Se quiser testar usando VirtualBox )
Expand Down
50 changes: 50 additions & 0 deletions src/hardware/disk.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
;==============================================
; KiddieOS - Disk/Memory Library Routines
; Author: Francis
; Version 1.0.0
;==============================================

%IFNDEF __DISK_LIB__
%DEFINE __DISK_LIB__

;----------------------------------------------
; Disk & Memory Configurations
;______________________________________________
SegmentAddr dw 0000h ; Segment Address
OffsetAddr dw 0000h ; Offset Address
Sector db 0 ; Sector
Track db 0 ; Track
Head db 0 ; Head
Drive db 0 ; Driver
NumSectors db 0 ; Number of Sectors

Reader db 02h ; Reader
Writer db 03h ; Writer

SectorPerTrack db 0 ; Sector per Track
TrackPerHead db 0 ; Track per Head
;______________________________________________

;----------------------------------------------
; Routine Library
ReadDisk:
mov ah, byte [Reader] ; Move the value of Reader to AH
call DiskOperation ; Call the interrupt 13h

WriteDisk:
mov ah, byte [Writer] ; Move the value of Writer to AH
call DiskOperation ; Call the interrupt 13h

DiskOperation:
mov al, byte [NumSectors] ; Move the value of NumSectors to AL
mov ch, byte [Track] ; Move the value of Track to CH
mov cl, byte [Sector] ; Move the value of Sector to CL
mov dh, byte [Head] ; Move the value of Head to DH
mov dl, byte [Drive] ; Move the value of Drive to DLM
mov bx, word [SegmentAddr] ; Move the value of SegmentAddr to BX ES:BX
mov es, bx ; Move the value of BX to ES
mov bx, word [OffsetAddr] ; Move the value of OffsetAddr to BX
int 13h ; Call the interrupt 13h
ret ; Return from the routine
;----------------------------------------------
%ENDIF
61 changes: 24 additions & 37 deletions src/hardware/monitor.lib
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,9 @@ NameSystem db "KiddieOS", 0 ; System Name
;----------------------------------------------

;----------------------------------------------
; Monitor & Windows Configurations
; Monitor Configurations
;______________________________________________
Window_Bar dw 3000h ; Window Bar
Window_Width dw 3001h ; Window Width
Window_Height dw 3003h ; Window Height
Window_PositionX dw 3005h ; Window Position X
Window_PositionY dw 3007h ; Window Position Y
Window_Bar_Color dw 300Ah ; Window Bar Color
Window_Back_Color dw 300Bh ; Window Background Color
ButtonClose dw 300Ch ; Button Close
ButtonMaximize dw 300Dh ; Button Maximize
ButtonMinimize dw 300Eh ; Button Minimize
StateWindowBar dw 0000h ; State Window Bar

Count dw 0000h ; Count

BackWidth dw 0000h ; Background Width
Expand All @@ -36,7 +26,6 @@ Pagination db 0 ; Pagination
CursorX db 15 ; Cursor X
CursorY db 12 ; Cursor Y
State db 0 ; State

;----------------------------------------------

;----------------------------------------------
Expand All @@ -62,18 +51,18 @@ DrawPixelConfig:
mov dx, 0 ; Y
ret

;Pinta o fundo da tela
; DrawBackground:
; int 10h ; Call BIOS
; inc cx ; Incrementa X
; cmp cx, word[BackWidth] ; Compara X com a largura
; jne DrawBackground ; Se não for igual, pinta o fundo
; mov cx, 0 ; Reseta X
; inc dx ; Incrementa Y
; cmp dx, word[BackHeight] ; Compara Y com a altura
; jne DrawBackground ; Se não for igual, pinta o fundo
; mov dx, 0 ; Reseta Y
; ret
; Pinta o fundo da tela
DrawBackground:
int 10h ; Call BIOS
inc cx ; Incrementa X
cmp cx, word[BackWidth] ; Compara X com a largura
jne DrawBackground ; Se não for igual, pinta o fundo
mov cx, 0 ; Reseta X
inc dx ; Incrementa Y
cmp dx, word[BackHeight] ; Compara Y com a altura
jne DrawBackground ; Se não for igual, pinta o fundo
mov dx, 0 ; Reseta Y
ret

; Exibe a string na tela
PrintString:
Expand Down Expand Up @@ -102,7 +91,7 @@ ret

; Efeito para a mensagem inicial do sistema (logo)
EffectInit:
mov bl, 0 ; Cor do texto inicial (preto) - antes estava iniciando na cor 44
mov bl, 44 ; Cor do texto inicial
start:
mov dh, [CursorY] ; Move o cursor para a posição Y
mov dl, [CursorX] ; Move o cursor para a posição X
Expand All @@ -118,7 +107,7 @@ EffectInit:
popa ; o comando popa restaura todos os registradores de propósito geral da pilha (junção de pop+a de all)
inc bl ; Incrementa BL
call Waiting ; Chama a sub-rotina Waiting
cmp bl, 255 ; Compara BL com 255
cmp bl, 50 ; Compara BL com 255
jne start ; Se BL for diferente de 50, pula para start
pusha ; o comando pusha salva todos os registradores de propósito geral na pilha (junção de push+a de all)
mov bl, 1 ; Move 1 para BL
Expand All @@ -129,15 +118,15 @@ EffectInit:
popa ; o comando popa restaura todos os registradores de propósito geral da pilha (junção de pop+a de all)
dec bl ; Decrementa BL
call Waiting ; Chama a sub-rotina Waiting
cmp bl, 0 ; Compara BL com 0
cmp bl, 44 ; Compara BL com 44
jne start ; Se BL for diferente de 0, pula para start
pusha ; o comando pusha salva todos os registradores de propósito geral na pilha (junção de push+a de all)
mov bl, 0 ; Move 0 para BL
mov byte[State], bl ; Move BL para State
mov bx, [Count] ; Move o contador para BX
inc bx ; Incrementa BX
mov word[Count], bx ; Move BX para Count
cmp bx, 50 ; Compara BX com 5000 (o número 5000 possui 2bytes) na máquina virtual podemos usar 50 ao invés de 5000 porque a máquina virtual é mais lenta
cmp bx, 10 ; contador de 10 vezes
jne ReturnLoop ; Se BX for diferente de 5000, pula para ReturnLoop
jmp ReturnProg ; Pula para ReturnProg
ReturnLoop:
Expand All @@ -151,13 +140,11 @@ ret
; cria um efeito de espera contando até 50000
Waiting:
pusha ; o comando pusha salva todos os registradores de propósito geral na pilha (junção de push+a de all)
mov bx, 0 ; Move 0 para BX
time:
inc bx ; Incrementa BX
cmp bx, 500 ; Compara BX com 50000 podemos usar 500 ao invés de 50000 porque a máquina virtual é mais lenta
jne time ; Se BX for diferente de 50000, pula para time
popa ; o comando popa restaura todos os registradores de propósito geral da pilha (junção de pop+a de all)
ret ; Retorna para o ponto de chamada

mov ah, 86h ; Função 86h da interrupção 15h: Esperar
mov cx, 0002h ; Contador -> 150 milisegundos -> 150000 em hexadecimal -> 0002h:49F0h
mov dx, 49F0h ; Contador
int 15h ; Chama a interrupção 15h para esperar
popa ; o comando popa restaura todos os registradores de propósito geral da pilha (junção de pop+a de all)
ret ; Retorna para o ponto de chamada
;----------------------------------------------
%ENDIF
38 changes: 38 additions & 0 deletions src/hardware/wmemory.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;==============================================
; KiddieOS - Memory Library Routines
; Author: Francis
; Version 1.0.0
;==============================================

%IFNDEF __WMEMORY_LIB__
%DEFINE __WMEMORY_LIB__

;----------------------------------------------
; Memory & Windows Configurations
;______________________________________________
%DEFINE WindowAddress 0800h:0500h ; Window Address

%DEFINE Window_Bar 3000h ; Window Bar
%DEFINE Window_Width 3001h ; Window Width
%DEFINE Window_Height 3003h ; Window Height
%DEFINE Window_PositionX 3005h ; Window Position X
%DEFINE Window_PositionY 3007h ; Window Position Y
%DEFINE Window_Bar_Color 300Ah ; Window Bar Color
%DEFINE Window_Back_Color 300Bh ; Window Background Color
%DEFINE ButtonClose 300Ch ; Button Close
%DEFINE ButtonMaximize 300Dh ; Button Maximize
%DEFINE ButtonMinimize 300Eh ; Button Minimize

M_InitialPositionX dw 0000h ; Initial Position X
M_InitialPositionY dw 0000h ; Initial Position Y
StateWindowBar dw 0000h ; State Window Bar
SavePositionX dw 0000h ; Save Position X
SavePositionY dw 0000h ; Save Position Y
SaveWidth dw 0000h ; Save Width
SaveHeight dw 0000h ; Save Height
;----------------------------------------------




%ENDIF
17 changes: 16 additions & 1 deletion src/kernel.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ jmp OSMain ; Pula para a sub-rotina OSMain

;--------------------------------------------------------
; Directives and inclusions
%INCLUDE "src/hardware/wmemory.lib"
%INCLUDE "src/hardware/monitor.lib"
%INCLUDE "src/hardware/disk.lib"

;-------------------------------------------------------

;-------------------------------------------------------
Expand All @@ -14,8 +17,9 @@ OSMain:
call ConfigSegment ; Chama a sub-rotina ConfigSegment para configurar os segmentos
call ConfigStack ; Chama a sub-rotina ConfigStack para configurar a pilha
call VGA.SetVideoMode ; Chama a sub-rotina VGA.SetVideoMode para configurar o modo de vídeo
;call DrawBackground ; Chama a sub-rotina DrawBackground para pintar o fundo da tela
call DrawBackground ; Chama a sub-rotina DrawBackground para pintar o fundo da tela
call EffectInit ; Chama a sub-rotina EffectInit para inicializar os efeitos
call GraficInterface ; Chama a sub-rotina GraficInterface para exibir a interface gráfica

jmp END ; Pula para a sub-rotina END
;-------------------------------------------------------
Expand All @@ -33,6 +37,17 @@ ConfigStack:
mov sp, 03FEh ; Configura o ponteiro de pilha (SP) com o valor 0x03FE
ret ; Retorna da sub-rotina

GraficInterface:
mov byte[Sector], 3 ; Move o valor 1 para Sector
mov byte[Drive], 80h ; Move o valor 80h para Drive 1o disco a ser lido, 81h para o segundo disco
mov byte[NumSectors], 1 ; Move o valor 1 para NumSectors
mov word[SegmentAddr], 0800h ; Move o valor 0x0800 para SegmentAddr
mov word[OffsetAddr], 0500h ; Move o valor 0x0500 para OffsetAddr
call ReadDisk ; Chama a sub-rotina ReadDisk para ler o disco
call WindowAddress ; Chama a sub-rotina WindowAddress para definir a janela de texto lembrando que está no endereço 0800:0500
ret ; Retorna da sub-rotina

END:
mov ah, 0000h ; Move o valor 0x00 para AH
int 16h ; Chama a interrupção 16h
Expand Down
41 changes: 41 additions & 0 deletions src/window.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[BITS 16]
[ORG 0500h]

pusha
call DefineWindow
popa
jmp ReturnKernel

DefineWindow:
mov ah, 0Ch ; Função 0Ch da interrupção 10h: Definir janela de texto
mov al, 55 ; Cor do pixel superior esquerdo
mov cx, 50 ; Coluna do pixel superior esquerdo
mov dx, 50 ; Linha do pixel superior esquerdo
jmp Window

Window:
LineUp:
int 10h ; Chama a interrupção 10h para mover o cursor
inc cx ; Incrementa CX - coluna
cmp cx, 100 ; Compara CX com 100
jne LineUp ; Se CX for diferente de 100, pula para LineUp
LineRight:
int 10h ; Chama a interrupção 10h para mover o cursor
inc dx ; Incrementa DX - linha
cmp dx, 100 ; Compara DX com 100
jne LineRight ; Se DX for diferente de 100, pula para LineRight
LineDown:
int 10h ; Chama a interrupção 10h para mover o cursor
dec cx ; Decrementa CX - coluna
cmp cx, 50 ; Compara CX com 50
jne LineDown ; Se CX for diferente de 50, pula para LineDown
LineLeft:
int 10h ; Chama a interrupção 10h para mover o cursor
dec dx ; Decrementa DX - linha
cmp dx, 50 ; Compara DX com 50
jne LineLeft ; Se DX for diferente de 50, pula para LineLeft
ret ; Retorna da sub-rotina


ReturnKernel:
ret

0 comments on commit d5eb5ce

Please sign in to comment.