Reputation: 89
I'm writing a NIM game in assembly 8086. It's almost finished, but there's a problem I'm facing.
I have a procedure which prints piles (each pile contains some stick(s)). It runs perfectly, except for one thing. I want to color sticks for better look. So I searched and found an interrupt for doing so: INT 10h / AH = 09h
In the description it suggests that this interrupt is used for "writing character and attribute at cursor position". However, I don't use to it to write characters, I use to set color for another interrupt. It works fine to some extent, but not always. So I wanted to know how it works, and if I'm using it the right way.
Also I found that usage here: How to print text in color with interrupts?
Here is my code for those parts:
set_color macro par ;macro to set a color for printing
pusha
mov bl, par
mov ah, 9
mov al, 0
int 10h
popa
endm
And this is where I print:
print_pile proc ;print the piles. this is where my problem lies.
pusha
mov al, nl ; print a new line
call print_ch
lea dx, top ;print top of border
call print_msg
xor si, si
mov cx, piles
xor bl, bl
pile_loop: ;print pile number
lea dx, pile_num1
call print_msg
call set_cursor
lea dx, pile_num2
call print_msg
mov temp, si
mov al, b. temp
inc al
add al, 30h
call print_ch
mov al, ' ' ;print sticks in each pile in numbers
call print_ch
mov al, '('
call print_ch
mov al, pile1[si]
add al, 30h
call print_ch
mov al, ')'
call print_ch
mov al, ' '
call print_ch
lea dx, shape
mov bl, pile1[si]
cmp bl, 0
jz no_print
print_loop: ;prints sticks in each pile using an ascii character
set_color light_red ; here i want to print abovesaid shapes in a color
call print_msg
dec bl
cmp bl, 0
jnz print_loop
no_print:
call set_cursor
inc si
dec cx
or cx, cx
jnz pile_loop
lea dx, star2
call print_msg
lea dx, top
call print_msg
popa
ret
print_pile endp
And here is an illustration of my problem:
As you can see the last pile is in two colors.
thank for your help.
PS. My complete code can be found HERE -- easier to read.
PS. I'm using emu8086, and sorry for my English.
Upvotes: 1
Views: 3167
Reputation: 14399
print_msg (DX=shape)
prints two characters via Int 21h/09
. Therefore you have to set the attributes for two characters in set_color
via Int 10h/09h
. So insert a mov cx, 2
:
set_color macro par ;macro to set a color for printing
pusha
mov bl, par
mov ah, 9
mov al, 0
mov cx, 2 ; number of times to write character
int 10h
popa
endm
Upvotes: 1