0

I have just followed the bootloader development guide on the MikeOS website, and I have understood the code so far. I am trying to add a few extra routines to the bootsector, notably changing the background colour to BIOS colour 0x1. However, the code below does not set the background to the right colour, instead it is just black. What is wrong here? (I hope my code is well commented)

    BITS 16     ; tell nasm we're working in 16 bit real mode

start:          ; entry symbol for the os          

        mov ax, 0x07C0          ; 4 kilobyte stack space set up
        add ax, 288             ; (4096+512) / 16 bytes per paragraph
        mov ss, ax              
        mov sp, 4096

        mov ax, 0x07C0          ; set data segment to where we've loaded
        mov ds, ax

        mov si, text_string     ; put our string position into SI
        call write_string       ; call our string-printing function
        call set_bg             ; call our background-setting routine

        jmp $                   ; jump here for an infinite loop

        text_string db 'Mao Mao Loader version 0.01'

write_string:                   ; output string located in si
    mov ah, 0xE                 ; the 'print char' function of int 0x10
.repeat:                
    lodsb                       ; get character from the string
    cmp al, 0                   ; check if it is zero   
    je .done                    ; if it is, jump to .done and finish the function
    int 10h                     ; call interrupt 10h    
    jmp .repeat                 ; repeat for every char in the string
.done:                  
    ret

set_bg:
    mov ah, 0x0B                ; set up function 'change bg' of int 0x10
    mov bh, 0x00                ; set up function 'change bg' of int 0x10
    mov bl, 0x1                 ; move the colour 0x1 (blue) to bl register (bl is where wikipedia tells us to store the colour)
    jmp .done                   ; jump to 'done'
.done:
    nop

    times 510-($-$$) db 0       ; pad boot sector with zeroes
    dw 0xAA55                   ; standard bootsig
    hlt

;TODO: read key pressed, change background colour and start writing kernel
Safal Aryal
  • 155
  • 1
  • 8

1 Answers1

0

set_bg:
    mov ah, 0x0B                ; set up function 'change bg' of int 0x10
    mov bh, 0x00                ; set up function 'change bg' of int 0x10
    mov bl, 0x1                 ; move the colour 0x1 (blue) to bl register 


    ; CHANGE HERE 
    int 0x10                    ; you have to call the interrupt only then it 
                                ; would come to work 


    jmp .done                   ; jump to 'done'
.done:
    nop

    times 510-($-$$) db 0       ; pad boot sector with zeroes
    dw 0xAA55                   ; standard bootsig
    hlt

;TODO: read key pressed, change background colour and start writing kernel

You have to call the 0x10 or 10h interrupt for changing the background colour.

Alex
  • 37
  • 2
  • You also need to `ret` from the `call set_bg`, not do a no-op `jmp .done` and then have execution fall into the `00 00` (`add [mem], al`) padding – Peter Cordes Jun 06 '22 at 01:13