TITLE Color Matrix (colorMatrix.asm) Comment ! Description: Write a program that displays a series of six different characters ("A" through "F") in all possible combinations of foreground and background colors (16 x16 = 256). Create a 1-second delay between characters, making the total running time 7 seconds. The colors are numbered from 0 to 15, so you can use a nested loop to generate all possible combinations. Display your name when the program starts, and wait for the user to press the Enter key before beginning the color display. Note: calling Crlf when color is enabled can cause Windows 98 to display the remaining blanks on the same line in color. A workaround seems to be to call Gotoxy instead. Last update: 02/17/2003 ! INCLUDE Irvine32.inc DELAY_TIME = 1000 .data charVal BYTE 'A' greeting BYTE "DEMO program for Color Matrix",0dh,0ah,0 rowCol LABEL WORD column BYTE 0 row BYTE 0 .code main PROC ;-------- display opening header --------------------------- mov eax,white call SetTextColor call Clrscr mov edx,offset greeting call WriteString call WaitMsg call Clrscr ;-------- begin color display --------------------------- mov ecx,6 ; loop 6 times L0: push ecx ; save loop counter mov rowCol,0 ; initialize row/column variable mov dx,0 ; set cursor at 0,0 call Gotoxy mov eax,0 ; starting color: black on black mov ecx,16 ; 16 possible background colors L1: push ecx ; save loop counter mov dx,rowCol ; get ready for a new row call Gotoxy mov ecx,16 ; 16 possible foreground colors L2: call SetTextColor ; set the color push eax mov al,charVal ; character to be displayed call WriteChar ; write it to the console pop eax inc al ; next foreground color loop L2 ; finished with the row ; The first time this line is reached, the color byte equals 10h, ; which gives us the next background color (and resets the foreground ; to black) inc row ; go to next row pop ecx ; restore loop counter loop L1 mov eax,DELAY_TIME ; delay for a while call Delay inc charVal ; next character pop ecx ; restore loop counter loop L0 ; go to next character mov eax,lightGray ; restore screen to normal color call SetTextColor exit main ENDP END main