HOW to set background and text colour using masm32?ANY suggestion?

Started by goo5257, September 11, 2008, 01:41:28 AM

Previous topic - Next topic

Neil

That code won't assemble because I think the eax register is being overwritten by invoke :(

BlackVortex

Quote from: Neil on September 14, 2008, 09:19:39 AM
That code won't assemble because I think the eax register is being overwritten by invoke :(
Hah, use another register/address

Neil

This version assembles OK, but doesn't appear to do anything ::)

SetCellColor proc fore:DWORD,back:DWORD,x:DWORD,y:DWORD

    LOCAL hOutPut:DWORD
    LOCAL noc    :DWORD
    LOCAL coord  :DWORD
   
    invoke GetStdHandle,STD_OUTPUT_HANDLE
    mov hOutPut, eax
    mov   edx,back
    shl   edx,4
    or    edx,fore
    mov  ecx, x
    mov  eax, y
    shl  eax, 16
    mov  ax, cx
    mov coord,eax
    mov ecx,1
    invoke FillConsoleOutputAttribute,hOutPut,edx,ecx,coord,ADDR noc
    ret

SetCellColor endp

Neil

It works, I got the parameters mixed up in the call :green
Any advice on improving it be be welcome.

herge


Hi ALL:


; TEXTCOL.ASM 9:12:44 PM Saturday, September 13, 2008
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
    first dd 0
    public szPrim
    szPrim  db 16 dup(?),0
    db 0
    CRLF    db 13,10
    db 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
SetTextColor proc fore:DWORD,back:DWORD

    LOCAL hStdOut:DWORD
    invoke GetStdHandle,STD_OUTPUT_HANDLE
    mov   hStdOut,eax
    mov   eax,back
    shl   eax,4
    or    eax,fore
    invoke SetConsoleTextAttribute,hStdOut,eax
    ret
   
SetTextColor endp
  public start

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    mov     eax, 15
    mov     ebx, 1
    mov     ecx, 14
@@:
    push    eax
    push    ebx
    push    ecx
    mov     first, eax    
    invoke SetTextColor, eax, ebx
    print "XXXXXXX "
    invoke crt__ultoa, first, addr szPrim , 10
    invoke StdOut, addr szPrim
    print " "
    invoke crt__ultoa, ebx, addr szPrim , 10
    invoke StdOut, addr szPrim

    invoke SetTextColor, 7, 0
    invoke StdOut, addr CRLF
    pop     ecx
    pop     ebx
    pop     eax
    dec     eax
    inc     ebx
    dec     ecx
    jnz     @B
    invoke SetTextColor, 7, 0
    inkey
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


When the foreground colour equals background colour
you can Not see your output thats why you don't see
line 8.

Regards herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

Neil

Thanks herge, I've got it sorted now & it works OK. I use it to highlight a character in the edit part of a program, instead of using a flashing cursor.

herge


Hi Neil:


    invoke SetTextColor, eax, ebx
    print "XXXXXXX "
    .if first == 8
    invoke SetTextColor, 15, 1
    .endif


If you want too see 8's you have to
do a little cheating and change text
colour attributes.

enjoy.

regards herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

Neil

I've added in another parameter to make the proc more versatile, n has been added which is the number of character positions in which the attributes are changed, this can be from 1 until the end of a row. If a block of characters need to be changed then the proc can be called in a loop changing the row (x) parameter each pass through. Remember, only the attributes are changed.

SetCellColor proc fore:DWORD,back:DWORD,x:DWORD,y:DWORD,n:DWORD

    LOCAL hOutPut:DWORD
    LOCAL noc    :DWORD
    LOCAL cord  :DWORD
   
    invoke GetStdHandle,STD_OUTPUT_HANDLE
    mov hOutPut, eax
    mov   edx,back
    shl   edx,4
    or    edx,fore
    mov  ecx, x
    mov  eax, y
    shl  eax, 16
    mov  ax, cx
    mov cord,eax
    mov ecx,n
    invoke FillConsoleOutputAttribute,hOutPut,edx,ecx,cord,ADDR noc
    ret

SetCellColor endp