A friend liked this fire effect and asked if I could put some text at the
top.

I didn't write the code and don't understand much of it.

She wants to use it as a screensaver from a DOS box on a system running
XP. The text I added isn't very readable. Do I have to start with one palette
for the text, write the text and then continue. Thanks.


; fire.asm Com file
; Fire simulation, good for demos - by Tenie Remmel 6/7/2002
;
;
Model Tiny
386P

code

Org 100h

begin:
jmp start

fire db 'test$'

;************* Custom palette
Pal db 0,0,0,0,0,2,0,0,4,0,0,6,0,0,8,0,0,10,0,0,12,0,0,14
db 0,0,16,2,0,14,4,0,12,6,0,10,8,0,8,10,0,6,12,0,4,14
db 0,2,16,0,0,19,0,0,22,0,0,25,0,0,28,0,0,31,0,0,34,0,0
db 37,0,0,39,0,0,42,0,0,45,0,0,48,0,0,51,0,0,54,0,0,57
db 0,0,60,0,0,63,0,0,63,2,0,63,5,0,63,7,0,63,10,0,63,13
db 0,63,15,0,63,18,0,63,21,0,63,23,0,63,26,0,63,28,0,63
db 31,0,63,34,0,63,36,0,63,39,0,63,42,0,63,44,0,63,47,0
db 63,49,0,63,52,0,63,55,0,63,57,0,63,60,0,63,63,0,63
db 63,2,63,63,5,63,63,7,63,63,10,63,63,13,63,63,15,63
db 63,18,63,63,21,63,63,23,63,63,26,63,63,28,63,63,31
db 63,63,34,63,63,36,63,63,39,63,63,42,63,63,44,63,63
db 47,63,63,49,63,63,52,63,63,55,63,63,57,63,63,60

PalDB db 528 dup(?) ;Last part of palette
RandNum dd 0 ;Random number

start:

mov ax,13h ;Set video mode 13h
int 10h

lea dx,fire
mov ah,9
int 21h


mov dx,03D4h ;Set bigger pixels
mov ax,4209h
out dx,ax

mov di,offset PalDB ;Set last part of palette
mov al,03Fh
mov cx,528
rep stosb

mov dx,3c8h ;Set custom palette
xor al,al
out dx,al
inc dx
mov cx,768
mov si,offset Pal
rep outsb

mov ax,cs ;Get extra segments
add ax,1000h
mov fs,ax
add ax,1000h
mov gs,ax

push fs ;Clear frame 1
pop es
xor di,di
xor eax,eax
mov cx,8000
rep stosd

push gs ;Clear frame 2
pop es
xor di,di
mov cx,8000
rep stosd

MainLoop: push fs gs ;DS = frame 1
pop es ds ;ES = frame 2
mov si,321 ;SI = (1, 1), DI = (1, 0)
mov di,1 ;this makes it move up
mov cx,31678 ;CX = count

CalcLoop: mov al, ;AX = average of the four
xor ah,ah ;surrounding pixels
add al,
adc ah,0
add al,
adc ah,0
add al,
adc ah,0
shr ax,2

cmp ax,1 ;Decrement if it isn't zero
adc ax,-1

stosb ;Write pixel
inc si ;Advance pointer
dec cx ;Loop back
jnz CalcLoop

mov di,31360 ;DI = 3rd-to-last row
mov cx,320 ;320 pixels
mov eax, ;EAX = random number

RandLoop1: imul eax,69069 ;Set top row random pixel
inc eax
mov bl,ah
and bl,31
add bl,50
mov ,bl

imul eax,69069 ;Set middle row random pixel
inc eax
mov bl,ah
and bl,31
add bl,70
mov ,bl

imul eax,69069 ;Set bottom row random pixel
inc eax
mov bl,ah
and bl,31
add bl,100
mov ,bl

inc di ;Next pixel
loop RandLoop1 ;Loop back

imul eax,69069 ;CL = random value
inc eax
mov cl,al
and cx,15
mov si,31360 ;SI = 3rd-to-last row

RandLoop2: imul eax,69069 ;Get random number
inc eax
push ax ;DI = random position
xor dx,dx ;from 0 to 320
mov bx,320
div bx
mov di,dx
pop ax
add di,si
xor bl,bl ;BL = 0FFh
dec bl
mov ,bl ;Draw a 3x3 square
mov ,bl
mov ,bl
mov ,bl
mov ,bl
mov ,bl
mov ,bl
mov ,bl
mov ,bl
loop RandLoop2 ;Loop back

mov ,eax ;Save random number

push 0A000h gs ;ES = 0A000h
pop ds es ;DS = frame 2
xor si,si ;Set up for blit
mov di,10880
mov cx,8000 ;100 lines
rep movsd

push fs gs ;Swap frames
pop fs gs

mov ah,0 ; function no. for read
int 1ah ; get the time of day count
add dx,1 ; add .05 seconds (one eighteenth of a second
; delay)

mov bx,dx ; to low word and then store end of delay
; value in bx
repeat:
int 1ah ; read time again
cmp dx,bx
jne repeat

mov ah,1 ;Check for a key
int 16h

jz MainLoop ;Loop back

xor ah,ah ;Eat the key
int 16h
mov ax,3 ;Restore video mode
int 10h
mov ax,4c00h
int 21h

End begin
Posted on 2003-10-18 04:58:15 by skywalker
You can add to the end of the custom palette, that she made, an entry or two for your text color. I see she already has black, and none of her colors reaches above 63,63,63. So, you should add white (255,255,255) just before "PalDB", and make "PalDB" have 525 entries.
Before the check of the key is the place you wanna code . You'll need to have an array, that contains the text bitmaps. 7x9 pixels per char is likely to do the trick. I think you can learn how to display the text, so I'll give some advice on building the text bitmap(array). Make a win32 app, that creates a DIB (search this forum for things you don't know) and a DC for it. Make the app ask you for font (MASM32 package has one lib for it, see its code). With the selected font, draw the a-z A-Z text on the DC, in one line, the returned value is the height of the text; and check each char's length , save it to an array. In the end, make the app save the bitmap bits, the length array, and the height value in hex or BCD format in a text file. Include that file in the code you posted. The result should be like this:


TextBits db 0,1,0,1,0,0,0 , .........
TextLen db 7,5,6,10,4, .........
TextHei db 11

Thus, you can have text with beautiful font, instead of dull fixedsys. The fire algorithm will not wash-out the text in a beautiful way (it doesn't use the whole palette, so I guess it'll limit the blurred out pixels to the number of entries your friend specified), so you'll have clear, contrasting text :)

Pls, next time attach the code, instead of inserting it into the post.
Posted on 2003-10-18 09:21:13 by Ultrano
Originally posted by Ultrano
You can add to the end of the custom palette, that she made, an entry or two for your text color. I see she already has black, and none of her colors reaches above 63,63,63. So, you should add white (255,255,255) just before "PalDB", and make "PalDB" have 525 entries.
Before the check of the key is the place you wanna code . You'll need to have an array, that contains the text bitmaps. 7x9 pixels per char is likely to do the trick. I think you can learn how to display the text, so I'll give some advice on building the text bitmap(array). Make a win32 app, that creates a DIB (search this forum for things you don't know) and a DC for it. Make the app ask you for font (MASM32 package has one lib for it, see its code). With the selected font, draw the a-z A-Z text on the DC, in one line, the returned value is the height of the text; and check each char's length , save it to an array. In the end, make the app save the bitmap bits, the length array, and the height value in hex or BCD format in a text file. Include that file in the code you posted. The result should be like this:


TextBits db 0,1,0,1,0,0,0 , .........
TextLen db 7,5,6,10,4, .........
TextHei db 11


Thanks for the ideas. I look forward to the challenge. Just a few beginning questions. Will this end up being a 32 or 16 bit App.
What is a DC.

Thanks again.
Posted on 2003-10-18 17:41:33 by skywalker
The win32 app will be ... 32-bit :) . You won't run this app more than once, unless there's a problem with it.
The DOS app can be made 16-bit or 32-bit - it really doesn't matter.
Posted on 2003-10-19 00:17:36 by Ultrano
Originally posted by Ultrano
You can add to the end of the custom palette, that she made, an entry or two for your text color. I see she already has black, and none of her colors reaches above 63,63,63. So, you should add white (255,255,255) just before "PalDB", and make "PalDB" have 525 entries.
Before the check of the key is the place you wanna code . You'll need to have an array, that contains the text bitmaps. 7x9 pixels per char is likely to do the trick. I think you can learn how to display the text, so I'll give some advice on building the text bitmap(array). Make a win32 app, that creates a DIB (search this forum for things you don't know) and a DC for it. Make the app ask you for font (MASM32 package has one lib for it, see its code). With

Since the code I posted was 16 bit, it would seem logical that I don't code in win32 yet. I did search for DIB, but didn't even find full code for anything that would even compile. I have the tools to make win32 apps, but I need something that will at least get me in the ballfield. :-) Then I can work on the suggestions you gave me.
Thanks.
Posted on 2003-10-22 23:00:59 by skywalker
I'll try to make the win32 app you need
Posted on 2003-10-23 07:52:06 by Ultrano

I'll try to make the win32 app you need


Thanks, I have been downloading everything I can find on mode 13h.
One source had a palette of 765 db statements, but then had cx count of 768 which I couldn't figure out.
Posted on 2003-10-23 10:39:18 by skywalker
Here you go. The larger generated array is packed like this: every byte contains the values of 8 consecutive horisontal pixels. If you don't manage to get an idea on how to implement it, I'll post some code tomorrow. Anyway, I'll post it, but make sure you try to do it on your own.
Posted on 2003-10-23 14:13:35 by Ultrano

Here you go. The larger generated array is packed like this: every byte contains the values of 8 consecutive horisontal pixels. If you don't manage to get an idea on how to implement it, I'll post some code tomorrow. Anyway, I'll post it, but make sure you try to do it on your own.


Take your time writing the code. The code you posted writes ASCIA.txt across the destop.(in Win 98)
Posted on 2003-10-24 07:01:23 by skywalker
Yes, I did that on purpose, and if you look closer, you'll see I've put a switch (a constant) to turn this off ;).
I've been having 9 to 10 hours/day at uni during the last week, studying higher maths non-stop, I'm very tired now, and I have some special code to complete asap, so I'll post code on how to use the font in a few days. The version upped above is perfect, so you can make some effort to study and use it meanwhile. :alright:

the asci.txt does not get shown on the desktop. The array you see on the desktop is exactly what the encoded font looks like (from char 32 to 31+Chars_Num). The Asci.txt has a purpose, though - if your language has some special chars, and you'd like to actually make use of them, you should open that file with notepad or something using the font you chose, and see what the constant Chars_Num should be set to. I'm from Bulgaria, and what would make me more happy than some text is some text in my language, because it's rather rare to see it on my PC, and almost impossible under a DOS proggie. Thus, I'd increase Chars_Num to 224.
Posted on 2003-10-24 10:32:23 by Ultrano

Yes, I did that on purpose, and if you look closer, you'll see I've put a switch (a constant) to turn this off ;).
I've been having 9 to 10 hours/day at uni during the last week, studying higher maths non-stop, I'm very tired now, and I have some special code to complete asap, so I'll post code on how to use the font in a few days. The version upped above is perfect, so you can make some effort to study and use it meanwhile. :alright:

the asci.txt does not get shown on the desktop. The array you see on the desktop is exactly what the encoded font looks like (from char 32 to 31+Chars_Num). The Asci.txt has a purpose, though - if your language has some special chars, and you'd like to actually make use of them, you should open that file with notepad or something using the font you chose, and see what the constant Chars_Num should be set to. I'm from Bulgaria, and what would make me more happy than some text is some text in my language, because it's rather rare to see it on my PC, and almost impossible under a DOS proggie. Thus, I'd increase Chars_Num to 224.



What language do you speak.
I'll try to work on some text in your language. I learned Korean and German, so it shouldn't be a problem.

Couldn't find the switch you mentioned.

Have a great weekend.
Posted on 2003-11-08 22:22:59 by skywalker
My native language is Bulgarian (had mentioned it above :grin: ), but I haven't written anything in BG in this code. Here I upload the code, well commented . Follow the XASM tags ;=====[[ >>===\ and ;=======/ - they're both comments and important blocks of code.
I wrote half of the function you need to draw text, I expect you continue it - it'll be an exercise :)
Posted on 2003-11-10 14:07:14 by Ultrano
I did a font system for my DOS game I made earlier but it was horrible, all I used is a 1 or 0 font where 1 means current text color pixel is plotted at that point and 0 means nothing is plotted (position is skipped). Though that may be too simple if you want multiple colors within your fonts.
Posted on 2003-11-10 15:12:25 by x86asm
This font system does the same way :) It's been compressed 8 pixels/byte.
Posted on 2003-11-10 23:11:42 by Ultrano

My native language is Bulgarian (had mentioned it above :grin: ), but I haven't written anything in BG in this code. Here I upload the code, well commented . Follow the XASM tags ;=====[[ >>===\ and ;=======/ - they're both comments and important blocks of code.
I wrote half of the function you need to draw text, I expect you continue it - it'll be an exercise :)


;------< Switches and settings >-------------------------\
itial_Wid equ 1600 ; must be dividable by 8 ; maximum width you'd like to use for whole font
Initial_Hei equ 40 ; maximum height you'd want to use
Chars_Num equ 96 ; how many characters from the 32nd to show. ANSI that is

Ok, so the 96 represents the most common characters most people would want to write, the english
alphabet, punctuation, etc.

The FontuHontu.inc is the file with the letters,etc. that will show on the screen in my program.

Once I have learned how to modify it to show what I need, then I'll need to learn how to display
it in particular screen position.

For a future project, I'll try to learn how to print the first 32 control characters as well
as the remainder of the 256 char set. I only know how to print them using a fixed font.

I'm curious as to why the large difference between the height and width values.

Thanks.
Posted on 2003-11-11 11:29:30 by skywalker
Like I said above, and accented on in the readme.txt, that constant is what DrawOnDesktop specifies if the proggie shows what it encodes in the FontuHontu.inc . As you see that immediate result on the desktop , you see that the height is merely above 20pt, let's say you use up to 40px , and the width is great, because we're displaying all chars on one line. The font isn't fixed-width, so there are two arrays in FontuHontu, that contain widths (in bytes) of chars and offsets (in words) of these chars' bits in the compressed bitmap. The system can be simplified if each pixel took a byte, but I think small proggies need to be kept small :) . Btw, please, don't use "quote" in the board in this way- it's mainly used when you want to accent on some sentence of somebody of the many people that discuss in this topic, which is really not the case here :)
Posted on 2003-11-11 11:43:36 by Ultrano