Color in win32 console.

by Michael Calkins (Login MCalkins)
ASM Forum


I did this several days ago.

This program outputs the "█" character with 16 foreground colors.

I now know how to output text, and change its color. Next: learn to locate the cursor. After that: learn to read console input. Then, I'll translate my tictactoe game to win32. :-D

Notice that the colors used by the console window aren't the same as used by the VGA mode's default palette. Run the program. Notice that the yellow is yellow. Then run qbasic in the same console window, and notice the yellow change to brown.

Even when running in a window, I can't seem to display non cp437 characters. I tried displaying the Hebrew aleph character "א", and it shows up as a question mark, even in window mode... Perhaps a font issue?


-------- t.c

#include <windows.h>
extern int asmmain();

int main()
return asmmain();

-------- m.bat

\asm\nasm -f win32 t.asm
\dev-cpp\bin\gcc t.c t.obj -o t.exe

-------- t.asm

cpu 586

extern _GetStdHandle@4
extern _WriteConsoleW@20
extern _SetConsoleTextAttribute@8
global _asmmain

section .text

push 0xfffffff5
call _GetStdHandle@4
mov [_handle],eax
push dword [_count]
push dword [_handle]
call _SetConsoleTextAttribute@8
push 0x0
push _trash
push 0x1
push _msg
push dword [_handle]
call _WriteConsoleW@20
inc dword [_count]
cmp dword [_count],0x10
jnz .lp
xor eax,eax

section .data

_handle: dd 0x0
_count: dd 0x0
_trash: dd 0x0
_msg: dw 0x2588

This message has been edited by MCalkins on Feb 7, 2011 6:42 PM

Posted on Feb 7, 2011, 6:26 PM

Respond to this message   

Return to Index

Response TitleAuthor and Date
cursor location is pretty easy.Michael Calkins on Feb 8, 3:11 PM
 ReadConsole seems a decent substitute for Line InputMichael Calkins on Feb 9, 2:20 PM
  Out of curiosity...Anonymous on Feb 11, 5:19 PM
   I've been thinking about that too. (added PS)Michael Calkins on Feb 11, 6:37 PM
    ReadConsole may not be sufficient for INKEY$, but...Anonymous on Feb 12, 8:42 AM
     Re: ReadConsole may not be sufficient for INKEY$, but...Michael Calkins on Feb 12, 7:12 PM
  I still haven't figured out how to use ld, but the Open Watcom linker is no sweat.Michael Calkins on Apr 24, 7:04 PM
   finally got ld to work, but it produced a bigger executable.Michael Calkins on Apr 26, 11:27 PM

 Copyright © 1999-2018 Network54. All rights reserved.   Terms of Use   Privacy Statement