Title Write your name in color (colorName.asm) Comment ! For 60 points: This program writes a person's name on the screen, using color characters. The color of each character should be chosen randomly. Color values can be 01h through FFh. For 72 points (90%): The characters must fly toward the middle of the screen from the right side of the screen, using enough of a delay so their motion can be seen. The user can halt the program any time by pressing any key. For 80 points (100%): The characters fly toward the middle of the screen from the top and bottom, in alternating sequence. The user can halt the program any time by pressing any key. ! INCLUDE Irvine16.inc .data StartColumn = 20 myName BYTE "Your name goes here",0 count = ($ - myName) waitMessage BYTE "Press any key...",0 cursorLoc LABEL WORD column DB 20 row DB 11 .code main proc mov ax,@data ; init data segment mov ds,ax call Randomize call Clrscr call EasyCredit call WaitForKey call BetterCredit call WaitForKey call FullCredit call WaitForKey exit main endp WaitForKey proc mov dx,1800h call Gotoxy mov dx,offset waitMessage call Writestring mov ah,1 ; wait for key int 21h call Clrscr ret WaitForKey endp ;---------------------------------------------- EasyCredit proc ; Partial credit solution ;---------------------------------------------- mov column,StartColumn mov dx,cursorLoc call Gotoxy mov cx,count mov si,OFFSET myName L1: mov al,[si] call WriteCharRandColor call AdvanceCursor inc si Loop L1 ret EasyCredit endp ;---------------------------------------------- BetterCredit proc ; Almost full credit solution ;---------------------------------------------- mov column,StartColumn mov cx,count mov si,OFFSET myName L1: mov ah,11h ; key waiting? int 16h jnz Quit2 mov al,[si] mov dx,cursorLoc call FlyCharacterTo inc si inc column Loop L1 Quit2: ret BetterCredit ENDP ;---------------------------------------------- FullCredit PROC ; Full credit solution ; Requires conditional jumps from Chapter 6. ;---------------------------------------------- TopRow = 0 BottomRow = 24 mov column,StartColumn mov cx,count / 2 mov si,OFFSET myName L1: mov ah,11h ; key waiting? int 16h jnz Quit push cx ; must be after JNZ! ; fly character from the top row mov al,[si] mov ch,TopRow mov cl,column mov dh,row mov dl,column call FlyCharacter inc si inc column ; fly character from the bottom row mov al,[si] mov ch,BottomRow ; this line mov cl,column mov dh,row mov dl,column call FlyCharacter inc si inc column pop cx Loop L1 Quit: ret FullCredit ENDP ;---------------------------------------------------- FlyCharacter PROC ; ; "Fly a character from the right side of the screen ; to a target location. The color will be random. ; Recevies: AL = character ; CH,CL = row,col of starting location ; DH,DL = row,col of target location ; Returns: nothing ; Calls: WriteCharColor ;---------------------------------------------------- .data startPos DW ? targetRow DB ? targetCol DB ? .code pusha mov startPos,cx mov targetRow,dh ; save target row mov targetCol,dl ; save target column mov dx,startPos call Gotoxy call ChooseRandomColor ; color in BL .WHILE dh < row call WriteSpace ; erase current character call Gotoxy ; locate cursor call WriteCharOneColor ; draw char in AL push eax mov eax,100 call Delay pop eax inc dh ; next row .ENDW .WHILE dh >= row call WriteSpace ; erase current character call Gotoxy ; locate cursor call WriteCharOneColor ; draw char in AL push eax mov eax,100 call Delay pop eax dec dh ; next row .ENDW popa ret FlyCharacter ENDP ;---------------------------------------------------- FlyCharacterTo PROC ; ; "Fly a character from the right side of the screen ; to a target location. The color will be random. ; Recevies: AL = character ; DH,DL = row,col of target location ; Returns: nothing ; Calls: WriteCharColor ;---------------------------------------------------- .data targetColumn DB ? .code pusha mov targetColumn,dl ; save target column mov dl,79 ; rightmost screen column call Gotoxy ; cx = (79 - targetColumn) mov cx,79 sub cl,targetColumn ; loop counter call ChooseRandomColor ; color in BL L1: call WriteSpace ; erase current character call Gotoxy ; locate cursor call WriteCharOneColor ; draw char in AL call Delay dec dl ; back up one column Loop L1 popa ret FlyCharacterTo ENDP ;------------------------------------------------ ChooseRandomColor PROC ; Return random color in BL. Keep background black ;------------------------------------------------ push ax mov eax,0Fh ; choose random color call RandomRange ; { 0..0E } inc al ; { 1..0F } mov bl,al ; attribute byte in BL pop ax ret ChooseRandomColor ENDP ;------------------------------------------------ WriteSpace PROC ; Write a single space character ;------------------------------------------------ pusha mov ah,9 ; function 9 mov al,' ' mov bh,0 ; video page mov bl,7 ; normal attribute mov cx,1 ; repetition factor int 10h popa ret WriteSpace ENDP ;---------------------------------------------------- WriteCharOneColor PROC ; ; Write a single character in color ; Receives: AL = character, BL = color ; Returns: nothing ;---------------------------------------------------- pusha mov ah,9 ; function 9 mov bh,0 ; video page mov cx,1 ; repetition factor int 10h popa ret WriteCharOneColor ENDP ;---------------------------------------------------- WriteCharRandColor PROC ; ; Write a single character in a random color. ; Receives: AL = character ; Returns: nothing ;---------------------------------------------------- pusha call ChooseRandomColor ; color in BL mov ah,9 ; function 9 mov bh,0 ; video page mov cx,1 ; repetition factor int 10h popa ret WriteCharRandColor ENDP ;---------------------------------------------------- AdvanceCursor PROC ; ; Advance cursor to next column ; Receives: nothing. Returns: nothing ;---------------------------------------------------- pusha mov ah,3 ; get cursor position mov bh,0 int 10h inc dl ; increment column mov ah,2 ; set cursor position int 10h popa ret AdvanceCursor ENDP end main