问题
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.
Here is my code:
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
回答1:
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
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
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)
I want to change the leds color from (0-7) using the user option,
The usual way would be to simply redraw the whole colored tile using the attribute set up in the BH
register.
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
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
来源:https://stackoverflow.com/questions/62611845/change-the-color-with-the-user-option