Nasm,引导加载程序切换前景色和背景色

发布于 2024-09-27 12:26:58 字数 1127 浏览 4 评论 0原文

嘿,我正在使用 nasm 虚拟机等编写引导加载程序。无论如何,我使用 vram 来显示由 s、d、f、g 键触发的背景和字体颜色变化。 S 切换字体颜色和背景颜色。我知道如何做到这一点,但我不知道正确的方法。 vram 设置为 2 个字节,第一个是字符,第二个是其属性。这些是背景颜色,然后是字符颜色。所以我需要拿走这些并切换它们。这将切换字体颜色和背景颜色。我实际上如何用代码来做到这一点?

; 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

第二个问题: 我使用这个循环来检测按键,我如何将这些按键更改为 Ctrl + 键。

.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

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

归途 2024-10-04 12:26:58

应该这样做:

    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

对于第二个,使用函数 2 for int 16h。

是的,并获取一些文档。也许您会喜欢技术:http://www.intel-assembler.it/portale/5/A-desktop-assembler-utility-program/A-desktop-assembler-utility-program.asp

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文