使用用户选项更改颜色 [英] Change the color with the user option

查看:106
本文介绍了使用用户选项更改颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用程序集emu8086在我的项目中工作,我已经做了很多事情: 现在,我正在努力放置用户选择的选项.我想使用用户选项将LED的颜色从(0-7)更改,我已经做了很多事情,但我不明白如果用户同时选择1和2,我将如何更改颜色. leds)需要更改为蓝色,并且对于所有颜色,我都需要验证用户选项.

I'm working in my project with assembly emu8086 and I've done a lot of things: Now I'm struggling to put the option selected by the user. I want to change the leds color from (0-7) using the user option, I've already done a lot of things I only dont understand how I'll do this to change the color, if the user select 1 both squares(leds) need to change to blue and this for all the colors, I need to verify the user option.

这是我的代码:

title    ac-cores-mov-cursor.asm - desenha poligno colorido em modo texto
         org  100h           ; directiva para definição do enderço da 1ª instrução
; definição de constantes     

inicio:  jmp  princ          ; etiqueta e instrução de 'salto' para procedimento
  


;____________________Menu_cores___________________________
menucores    db   '1 black',0ah,0Dh
         db   '2 blue',0ah,0Dh
         db   '3 green',0ah,0Dh
         db   '4 cyan ',0ah,0Dh
         db   '5 red',0ah,0Dh
         db   '6 magenta',0ah,0Dh
         db   '7 brown',0ah,0Dh
         db   '8 light gray',0ah,0Dh  
         db "Please select a choice(1-8):",13,10,   '$'    
                                                   
                                                   
                                                   
                                                   
menu    db  '1 Todos os leds ligados',0ah,0Dh        ;leva ao menu cores para escolher a cor 
        db  '2 Combinaçao(0,2,4,6)',0ah,0Dh          ;leva ao menu cores para escolher a cor dos leds 0 2 4 6 
        db  '3 Combinaçao(1,3,5,7)',0ah,0Dh          ;leva ao menu cores para escolher a cor dos leds 1 3 5 7
        db "Please select a choice(1-8):",13,10,   '$'  
         
         
;____________________Menu_principal___________________________         
menuprincipal db   '1 Todos os leds desligados',0ah,0Dh   ; retorna os leds todos com a cor preta
              db   '2 Cor dos leds ',0ah,0Dh               ; leva para o menu cores
              db "Please select a choice(1-2):",13,10,   '$'      ;opçao escolhida
                                
                                
         
; definição de variáveis            
         
esqlin   db   15            ; linha do vértice superior esquerdo
esqcol   db   10              ; coluna do vértice superior esquerdo  


largura  db   2             ; largura do fundo
altura   db   2              ; altura do fundo   

texlin   db   17             ; linha do texto
texcol   db   12              ; coluna do texto 
colincio db   2
 
enter    db   0Ah,0Dh,'$'
fundo    db   'Cor fundo (0-9,A-F) ', '$'
texto    db   'Cor texto (0-9,A-F) ', '$'
corfund  db   0              ; 0-15 (decimal), 0-F (hexadecimal)
cortext  db   4             ; 0-15 (decimal), 0-F (hexadecimal)
frase1    db   'LED1', '$'  
corft    db   0Fh    

 



;___________________________START___________________________
verificacao:



princ    proc near           ; início do procedimento principal
         lea  dx, menucores      ; escrever string
         mov  ah, 09h 
         int  21h         
                  
                  
; define cor do texto e cor do fundo do ecrã         
         mov  corft, 24h  
         mov  bh, corft

         

                
         mov  ch, esqlin     ; vértice superior esquerdo - linha
         mov  cl, esqcol     ; vértice superior esquerdo - coluna
         mov  dh, esqlin         
         add  dh, altura     ; vértice inferior direito - linha 
         dec  dh
         mov  dl, esqcol     
         add  dl, largura    ; vértice inferior direito - coluna
         dec  dl 
         mov  ah, 06h         
         int  10h
                    
             

                

                     
                     
; instruções para terminar o programa
         mov  ax, 4c00h
         int  21h

princ    endp           ; fim do procedimento principal

; define cor do texto e cor do fundo do ecrã         
         mov  bh, 218        ; 218(16*13+10) = DAh: D - cor fundo, A - cor texto
         mov  al, 01h        ; nº linhas scroll
         mov  ch, 0          ; vértice superior esquerdo - linha
         mov  cl, 0          ; vértice superior esquerdo - coluna
         mov  dh, 0          ; vértice inferior direito - linha
         mov  dl, 46         ; vértice inferior direito - coluna
         mov  ah, 06h        ; scroll uma linha (al)=1
         int  10h

         mov  al, corfund
         mov  bh, 16         ; 16 = 2^4
         mov  ah, 0
         mul  bh             ; 16*corfund
         add  al, cortext    ; = corfund*16 + cortext

推荐答案

我需要验证用户选项.

I need to verify the user option.

要求用户按一个键并验证其是否有效.

Ask the user to press a key and verify if it was valid.

Again:
    mov ah, 00h    ; BIOS.GetKeyboardKey
    int 16h        ; -> AX
    cmp al, "0"
    jb  Again
    cmp al, "7"
    ja  Again

用户在此处进行了0到7的有效选择.现在,将此选择转换为背景色.记住输入仍然是字符!转换后,将其放入属性字节的高半字节,以用于输出到屏幕.

Here the user has made a valid selection from 0 to 7. Now turn this choice into a background color. Remember the input is still a character! Once converted, you put it into the high nibble of the attribute byte to be used for outputting to the screen.

    sub al, "0"    ; Convert from character to value (*)
    mov cl, 4
    shl al, cl     ; Shift into high nibble (background color)
    add al, 15     ; Add in low nibble (foreground color)
    mov bh, al

您的屏幕截图使用红色文本颜色,但是如果用户选择红色backgroundcolor,那将使文本消失.因此,我建议您使用BrightWhite(15)作为前景色.
(*)在这种特殊情况下可以省略(因为随之而来的是左移)

Your screenshot uses the red text color, but that would make the text disappear if the user selected the red backgroundcolor. That's why I suggest you use BrightWhite (15) as your foreground color.
(*) can be omitted in this particular case (because of the shift left that follows)

我想使用用户选项将LED的颜色从(0-7)更改

I want to change the leds color from (0-7) using the user option,

通常的方法是使用BH寄存器中设置的属性简单地重绘整个彩色图块.

The usual way would be to simply redraw the whole colored tile using the attribute set up in the BH register.

首先,您需要使用BIOS.ScrollWindowUp AL=0来清除磁贴!

First you clear the tile using BIOS.ScrollWindowUp with AL=0 !

    FirstButtonCol    db 10
    FirstButtonRow    db 15
    FirstButtonWidth  db 10
    FirstButtonHeight db 3
    frase1            db 'LED1', '$'

    ...

    mov  ch, FirstButtonRow
    mov  cl, FirstButtonCol
    mov  dh, ch
    add  dh, FirstButtonHeight
    dec  dh
    mov  dl, cl
    add  dl, FirstButtonWidth
    dec  dl 
    mov  ax, 0600h     ; BIOS.ScrollWindowUp AL=0
    int  10h

然后将光标置于按钮上方并写上标签"LED1"

Then you position the cursor over the button and write the label "LED1"

    lea  si, [frase1]
    mov  cx, 1         ; ReplicationCount
    mov  bh, 0         ; DisplayPage
    mov  dl, FirstButtonCol
    mov  dh, FirstButtonRow
    add  dx, 0102h
NextChar:
    mov  ah, 02h       ; BIOS.SetCursor
    int  10h
    mov  al, [si]
    mov  ah, 0Ah       ; BIOS.WriteCharacter
    int  10h
    inc  dl            ; Next column
    inc  si            ; Next char
    cmp  byte [si], "$"
    jne  NextChar

这篇关于使用用户选项更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆