1

As a learning exercise I am writing my own bootloader, however when I boot it on qemu I get the expected output, but when I burn the bootloader on a USB the rectangle does not appear. I have tried a few things and sometimes the word World does not appear (for example if the rectangle is too low).

The code is the following, could anybody help?

bits 16

_main:
    mov ax, 07C0h
    add ax, 288
    mov ss, ax              ; ss = stack space
    mov sp, 4096            ; sp = stack pointer

    mov ax, 07C0h
    mov ds, ax              ; ds = data segment

    mov ah, 00h             ; set video mode to graphical
    mov al, 13h             ; 13h - graphical mode, 40x25. 256 colors.;320x200 pixels. 1 page.

    int 10h                 ; call


    call print_pixel

    call print_text

    call draw_square


    ;cli ; stop execution
    ;hlt
    jmp $

print_pixel:

    ; drawing random pixels

    mov ah, 0Ch             ; change color for a single pixel

    mov al, 0000b           ; color
    mov bh, 0               ; page number
    mov cx, 30              ; x
    mov dx, 100             ; y

    int 10h                 ; paint 1st pixel

.repeat:

    inc al                  ; change color
    inc cx                  ; go one pixel right
    inc dx                  ; go one pixel down

    int 10h                 ; paint

    cmp al, 1111b
    je .done                ; last color was painted

    jmp .repeat

.done:   
    ret

draw_square:

    mov ah, 0Ch             ; change color for a single pixel

    mov al, 0ah           ; color
    mov bh, 0               ; page number
    mov cx, 80             ; x
    mov dx, 30             ; y

.row:

    int 10h                 ; paint

    inc cx                  ; go one pixel right

    cmp cx, 96          ; 16 px width
    je .nextrow             ; paint next row


    jmp .row

.nextrow:

    mov cx, 80
    inc dx                  ; go one pixel down

    cmp dx, 62             ;32 px high
    je .done

    jmp .row


.done:   
    ret


print_text:

    mov ax, 7c0h        ; beginning of the code
    mov es, ax
    mov bp, msg
    mov ah,13h          ; function 13 - write string
    mov al,01h          ; attrib in bl, move cursor
    mov bl,0bh          ; attribute - magenta
    mov bh, 0
    mov cx,5           ; length of string
    mov dh,1            ; row to put string
    mov dl,4            ; column to put string
    int 10h             ; call BIOS service
    ret

msg: db "World"

times 510 - ($ - $$) db 0   ; padding with 0 at the end
dw 0xAA55                   ; PC boot signature

enter image description here

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Gef
  • 73
  • 8
  • 1
    I would first check this question and the answer out: https://stackoverflow.com/questions/47277702/custom-bootloader-booted-via-usb-drive-produces-incorrect-output-on-some-compute .You may need a BIOS Parameter Block to prevent the BIOS overwriting part of your code and data when using USB FDD emulation. – Michael Petch Mar 06 '19 at 05:25
  • Wow, thank you very much! That indeed fixed the issue! – Gef Mar 06 '19 at 05:58
  • As Michael pointed out, the solution is in https://stackoverflow.com/questions/47277702/custom-bootloader-booted-via-usb-drive-produces-incorrect-output-on-some-compute – Gef Mar 06 '19 at 06:00

0 Answers0