I
I
Ivan Chetchasov2022-04-12 09:16:30
assembler
Ivan Chetchasov, 2022-04-12 09:16:30

Why video mode initialization doesn't work and how to fix it?

I'm writing a mini OS in assembler and I've run into a problem: the OS can't switch video mode. That is, I excite int 0x10with axequal to 0x0003, but this does not help.

Edit: the switch happens once, but after it it is not possible to display the text.

The code:

basic

org 0x7C00

xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7C00
cld

call video_tinit

push boot_msg
call video_tprint

mov al, (KERNELEND-KERNEL)/512       ; sectors to read
mov bx, 0x7E00     ; destination
mov cx, 0x0002     ; cylinder:sector
xor dh, dh
call boot_disk_driver_disk_read

mov ax, 0x7E0
mov ds, ax
mov es, ax
mov sp, 0x7E00
jmp 0x07E0:0x0000

include "att2\files\drivers\boot\disk.asm"
include "att2\files\drivers\boot\video.asm"

boot_msg db 'R-OS bootloader', 0x00

times 510-$+$$ db 0x00
dw 0xAA55

KERNEL:

; Set up graphical video system

call video_tinit

; Write string into screen

push print_string

call video_tprint

; Halt the processor

hlt
nop
jmp $-2



KERNELDATA:

print_string db "Horay! OS booted successful! Press [Enter] to continue", 0x00

include "att2/files/drivers/kernel/bits16/video.asm"
include "att2/files/drivers/kernel/bits16/builtin.asm"


times 0x10000-$+$$ db 0x00

KERNELEND:

times 0x100000-$+$$ db 0x00


video driver

macro pass {}

video_tinit:
video_tclear:
    mov ax, 0x0003
    int 0x10
    ret

; regs used: si, dx, cx
video_tprint:
    pop si
    video_tprint_loop:
        lodsb
        test al, al
        jz video_tprint_ret
        mov dl, 0xA0
        cmp al, dl
        je video_tprint_newline
        jmp video_tprint_loop
        pass
    video_tprint_ret:
        ret
    video_tprint_newline:
        mov ah, 0x03
        int 0x10
        mov cx, 321
        xor dh, dh
        sub cx, dx
        mov al, ' '
        mov ah, 0x0E
        video_tprint_newline_loop:
            int 0x10
            loop video_tprint_newline_loop
            pass
        jmp video_tprint_loop
        pass
    pass

pass это просто дурная привычка, прошу не обращать на них внимание.

HDD driver

boot_disk_driver_disk_read:
    pusha
    mov si, 0x05
boot_disk_driver_disk_read_top:
    mov ah, 0x02
    int 0x13
    jnc boot_disk_driver_disk_read_end
    mov ah, 0x00
    int 0x13
    dec si
    jnz boot_disk_driver_disk_read_top
    jmp boot_disk_driver_disk_read_fatal
boot_disk_driver_disk_read_end:
    popa
    ret

boot_disk_driver_disk_read_msg db 'Disk read error!', 0x00
boot_disk_driver_disk_read_fatal:
    mov bh, 0x00
    mov ah, 0x0E
    mov si, boot_disk_driver_disk_read_msg
    lodsb
boot_disk_driver_disk_read_next:
    int 0x10
    lodsb
    cmp al, 0x00
    jne boot_disk_driver_disk_read_next

    cli
    hlt
    jmp $-2
    
boot_disk_driver_disk_write:
    pusha
mov si, 0x05
boot_disk_driver_disk_write_top:
    mov ah, 0x03
    int 0x13
    jnc boot_disk_driver_disk_write_end
    mov ah, 0x00
    int 0x13
    dec si
    jnz boot_disk_driver_disk_write_top
    jmp boot_disk_driver_disk_write_fatal
boot_disk_driver_disk_write_end:
    popa
    ret

boot_disk_driver_disk_write_msg db 'Disk write error!', 0x00
boot_disk_driver_disk_write_fatal:
    mov bh, 0x00
    mov ah, 0x0E
    mov si, boot_disk_driver_disk_write_msg
    lodsb
boot_disk_driver_disk_write_next:
    int 0x10
    lodsb
    cmp al, 0x00
    jne boot_disk_driver_disk_write_next

    cli
    hlt
    jmp $-2

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question