开发者

Nasm, bootloader switching foreground and background colors

开发者 https://www.devze.com 2023-01-20 08:40 出处:网络
Hey some im writing a bootloader using nasm a virtual machine ect. Anyhow, im using vram to display background and font color changes triggered by keys s, d, f, g. S switches the color of the font wit

Hey some im writing a bootloader using nasm a virtual machine ect. Anyhow, im using vram to display background and font color changes triggered by keys s, d, f, g. S switches the color of the font with the background color. I know how this can be done but i do not know the proper way. vram is setup as so 2 bytes the first is the character, the second is its attributes. These are background then character color. So i need to take these and switch them. That would switch the font color and the background color. How do i actually do it with code?

; s key
;///////////////////////////////////////////////////////////
.s:
mov bx,0xb800       ;direct video memory access 0xB8000
mov es,bx
xor bx,bx       ;es:bx : 0xb8000
mov dh,0        ;row from 0 to 24
mov dl,0        ;col from 0 to 79


    .loops1:
inc bx
mov byte [es:bx], 0ah   ;attribute 
inc bx

inc dl
cmp dl,开发者_开发百科80       ;col 0-79
jne .loops1
mov dl,0
inc dh
cmp dh,25       ;row 0-24
jne .loops1 
jmp .kbin

Second question: Im using this loop to detect key's how could i change these keys to Ctrl + key.

.kbin:
 mov ah,10h  ;Read from keyboard
                ;ah scan code, al ascii char
 int 16h
 cmp al, 53h   ;uppercase s
 je .s

 cmp al, 73h   ;lowercase s
 je .s

 cmp al, 44h   ;uppercase d
 je .d

 cmp al, 64h   ;lowercase d
 je .d

 cmp al, 46h   ;uppercase f
 je .f

 cmp al, 66h   ;lowercase f
 je .f

 cmp al, 47h   ;uppercase g
 je .g

 cmp al, 67h   ;lowercase g
 je .g

 jmp .kbin

Thank you.


This should do it:

    mov ax, 0xb800
    mov es, ax
    mov ds, ax ; both pointing at vram area
    xor si, si
    xor di, di
    mov cx, num_chars
loop1:
    movsw // reads a word from ds:si into ax
    rol ax, 8 // switches the bytes in ax
    stosw // puts the word back
    dec cx
    jne loop1

For the second, use function 2 for int 16h.

Yeah, and get some documentation. Maybe you'll like Tech: http://www.intel-assembler.it/portale/5/A-desktop-assembler-utility-program/A-desktop-assembler-utility-program.asp

0

精彩评论

暂无评论...
验证码 换一张
取 消