;=====BASIC OS Example =====;
;---Copyright Kris Occhipinti---;
;--License GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt --;
;--useage - 
;nasm boot.asm -f bin -o boot.bin && qemu-system-i386 -fda boot.bin

BITS 16 
start:
  ;---Commented out because it runs fine without it---;
  ;mov ax, 07C0h   ; Set up 4K stack space after this bootloader
  ;add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
  ;mov ss, ax
  ;mov sp, 4096
  mov ax, 07C0h   ; Set data segment to where we're loaded
  mov ds, ax

  ;----Print String---;
  mov si, text_string ; Put string position into SI
  call print_string ; Call our string-printing routine
  text_string db 'Welcome and Hello World!', 0; set string and end it with a '0'
  print_string: ; Routine: output string in SI to screen
  mov ah, 0Eh ; int 10h 'print char' function

.repeat:
  lodsb ; Get character from string
  cmp al, 0 ; check if 'text_string' char is zero
  je .background_colors ; If char is zero (from previous cmp), end of string go ti background_color
  int 10h ; Otherwise, print char from 'text_string'
  jmp .repeat

.background_colors:
  mov ah,0Bh;set cursor position
  ;mov bh,0 ;select page
  mov bl,20;set background color (20 is red)
  int 10h ;tell bios to execute these commands
  jmp .cursor_pointer

.cursor_pointer:
  mov ah,2h ;set the value to "ah" to move the cursor pointer
  mov dh,15 ;set row position of the cursor
  ;mov dl,0 ;set column position of the cursor
  add dl,1 ;set column position of the cursor
  int 10h ;tell bios to execute these commands
  jmp .character_read

.character_read:
  mov ah,00h ;remeber set the value to "ah" now you are going to read a keyboard input
  int 16h ;this interrupt is given to control keystrokes of keyboard
  jmp .print_input

.print_input:
  mov ah,9h ;set the value to "ah" to print one character to std out
  ;mov bl,1 ;set color of font
  inc bl ;change the color attribute of the font to be print on each key press
  mov cx,1 ;set the value how many time the character in "al" should be print
  int 10h ;tell bios to execute these commands
  jmp .cursor_pointer

.done:
  ret

times 510-($-$$) db 0 ; fill up the rest part of the boot secotr with 0 s
dw 0xAA55 ; The standard PC boot signature

