flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Compiling .ASM-source directly into a .TGA image with fasm!!

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
This is just another example that demonstrates the power of FASM's synax!
It is really outstanding. (well, that's nothing new...)

Take it as a dedictation.

Shocked
The source won't compile to an executable, but rather DIRECTLY to an 8-bit paletted Targa-image! => so, don't run the generated output!

It works with 64bit fixed point integer arithmetics. And since it uses numerical constants/repeats from the fasm syntax, it is
_REALLY SLOW Razz _, but it works.

I don't know any other assembler/compiler capable of doing such things!


EDIT2: re-updated version that uses the "as" directive to specify the output file extension.


EDIT: updated version with "break" directive to speed up the inner-most loop.

Code:
; DON'T _RUN_ this file, just COMPILE it and view it with any
; image program that supports 8-bit paletted TGA-images (many does).

; usage: "fasm mandeldb.asm"

format  binary as ".tga"

; Some basic image properties. Feel free to modify
Width  equ 120
Height       equ 120
IterLim equ 256
Prec      equ 29; don't set above 29 nor to low, else image may be scrambled

; TGA-header: 8-bit paletted image
dw 256,1
db 0,0,1,24
dw 0,0,Width,Height
db 8,8

; palette: 256*3bytes (RGB)
repeat 256
 db (%+54h) and 0FFh
 db (%+0A9h) and 0FFh
 db % - 1
end repeat

; actual image (Mandelbrot fractal)
PrecScale = 1 shl (Prec-1)

StepR = (5 shl (Prec-1) +Width       shr 1) / Width; = 2.5/Width
StepI = (5 shl (Prec-1) +Height shr 1) / Height; = 3/Height

PosI = -5 shl (Prec-2); = -1.25
repeat Height
 PosR = -2 shl Prec; = -2
 repeat Width
  R = PosR
  I = PosI
  RR = (PosR*PosR) shr Prec
  II = (PosI*PosI) shr Prec

  Color = IterLim - 1; Color is also the current iteration number
  repeat IterLim
   if (RR + II) > 4 shl Prec
    break
   end if
   Tmp = (RR - II) + PosR
   I = (R*I) / PrecScale + PosI
   R = Tmp
   RR = (Tmp*Tmp) shr Prec
   II = (I*I) shr Prec
   Color = Color - 1; discounting Color
  end repeat
  if Color < 0
   Color = 0
  end if
  db Color

  PosR = PosR + StepR
 end repeat
 PosI = PosI + StepI
end repeat
    


Old version (you should specify "fasm mandeldb.asm mandeldb.tga", else the file extension will confuse lamish image programs Wink ) :

Code:
; DON'T _RUN_ this file, just COMPILE it and view it with any
; image program that supports 8-bit paletted TGA-images (many does).

; usage: "FASM MANDELDB.ASM MANDELDB.TGA"
; better keep the ".TGA"-extension, else this might confuse some lamish
; image programs.

; Some basic image properties. Feel free to modify
Width  equ 120
Height       equ 120
IterLim equ 256
Prec      equ 29; don't set above 29 nor to low, else image may be scrambled

; TGA-header: 8-bit paletted image
dw 256,1
db 0,0,1,24
dw 0,0,Width,Height
db 8,8

; palette: 256*3bytes (RGB)
repeat 256
 db (%+54h) and 0FFh
 db (%+0A9h) and 0FFh
 db % - 1
end repeat

; actual image (Mandelbrot fractal)
PrecScale = 1 shl (Prec-1)

StepR = (5 shl (Prec-1) +Width       shr 1) / Width; = 2.5/Width
StepI = (5 shl (Prec-1) +Height shr 1) / Height; = 3/Height

PosI = -5 shl (Prec-2); = -1.25
repeat Height
 PosR = -2 shl Prec; = -2
 repeat Width
  R = PosR
  I = PosI
  RR = (PosR*PosR) shr Prec
  II = (PosI*PosI) shr Prec

  Color = IterLim - 1; Color is also the current iteration number
  repeat IterLim
   if (RR + II) < 4 shl Prec
    Tmp = (RR - II) + PosR
    I = (R*I) / PrecScale + PosI
    R = Tmp
    RR = (Tmp*Tmp) shr Prec
    II = (I*I) shr Prec
    Color = Color - 1; discounting Color
   end if
  end repeat
  if Color < 0
   Color = 0
  end if
  db Color

  PosR = PosR + StepR
 end repeat
 PosI = PosI + StepI
end repeat
    

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||


Last edited by MCD on 13 Aug 2008, 15:58; edited 4 times in total
Post 15 Sep 2004, 14:50
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Nice !
Smile
8.4 seconds 1 passes 15186 bytes
here it is in jpg


Description:
Filesize: 17.79 KB
Viewed: 19866 Time(s)

asmtga.jpg


Post 15 Sep 2004, 14:59
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1095
Location: Poland
cool Wink I remember sometime ago similar examples were posted, they were generating BMP files...
Post 15 Sep 2004, 15:02
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
Jep, it's just genious, this little Fasm example.
I'm so fond of it although I hasn't coded fasm.

IT IS 100000* better than TASM/MASM.

A lopng time ago, I used a TASM version which was even unable to compile "pop ds". Smile Smile Wink
Post 15 Sep 2004, 15:24
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Hy again here are my test results:

; Some basic image properties. Feel free to modify (786 bytes header)
; tests in real time, Celeron II @ 933Mhz (600), 103MHz Bus, FSB, 16+16K L1, 256k L2:
; 20x20 : 0.2s 2000 pixels per sec 1186 bytes
; 40x40 : 0.9s 1777.77 pixels per sec 2386 bytes
; 80x80 : 3.6s 1777.77 pixels per sec 7186 bytes
; default 120x120 : 8.2s 1756.09 pixels per sec 15186 bytes
; 160x160 : 14.7s 1741.49 pixels per sec 26386 bytes
; 200x200 : 23.1s 1731.60 pixels per sec 40786 bytes
; 280x280 : 44.9s 1746.10 pixels per sec 79186 bytes
; 800x800 : 366.7s 1745.30 pixels per sec 640786 bytes
; 1200x1200 : 831.3s 1732.23 pixels per sec 1440786 bytes

MATRIX
Post 15 Sep 2004, 16:21
View user's profile Send private message Visit poster's website Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
Thes 2 examples were posted to HEAP earlier, but now they aren't available.

I think they might be interesting too, so I repost them.

Author is Black Mirror from wasm.ru


Description:
Download
Filename: fractal.zip
Filesize: 885 Bytes
Downloaded: 733 Time(s)

Description:
Download
Filename: image.zip
Filesize: 1.08 KB
Downloaded: 736 Time(s)

Post 15 Sep 2004, 22:51
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1046
Location: Michigan, USA
Hi MCD, very nice example,
I get 5 seconds compile on a 2.7ghz celeron using fasmw 1.55,
useing 120x120 image
20.5 seconds for a 320x200 image
Hope you make some more in the future.
MadMatt
Post 15 Sep 2004, 23:13
View user's profile Send private message Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
Well, mostly code real programs, but this was just a nice change from daily work.

Has anyone an idea how to speed up the compilation process?
I already stripped out the roundings at divisions and I don't see any further possibility to optimize this.
Post 17 Sep 2004, 13:14
View user's profile Send private message Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
decard wrote:
cool Wink I remember sometime ago similar examples were posted, they were generating BMP files...

I'm not sure if I ever posted it, but I made a xpm using fasm, nothing fancy, just a "wee, I'm having fun"-thing.
I wonder if there's anyother assemlber that can do these nice tricks :)

(posting from elinks (text mode browser) due to xorg uppgrades in progress)

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 18 Sep 2004, 18:53
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1095
Location: Poland
I remember that you posted it sometime ago Smile

Does anybody still have those examples of generating BMP files? (I remebmer that they were from wasm.ru). I have deleted them Sad
Post 18 Sep 2004, 21:08
View user's profile Send private message Visit poster's website Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
decard, aren't they attached above?Wink
Post 19 Sep 2004, 02:38
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1095
Location: Poland
LOL, sorry, that's because I'm usually clicking on "view latest post" icon Smile Thanks Very Happy
Post 19 Sep 2004, 06:34
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
Okay folks! Since many users around here like those kind of experimental stuff, I've decided to start another mind-blasting experiment.

HERE IT IS:
Code:
; This example will compile(!) to a beat-sound using data defining directives
;and thus it doesn't need to be run. Furthermore,

; DON'T _RUN_ this file, just COMPILE it and listen to it with any
; sound program that supports 16-bit 11025Hz mono WAV-sounds (many does).

; usage: "FASM BEAT.ASM BEAT.WAV"
; better keep the ".WAV"-extension, else this might confuse some lamish
; sound programs.

Prec        equ 24;change with care!
Length      equ 2205;length in samples = 0.2 seconds

;If you change Lambda, then you must change CoLambda accordingly!
Lambda     = 140000h; = 5/64
CoLambda = 16725938; = SqRt( 1 - Lambda*Lambda )

;Setting these values to high/low can quickly result in
;"value out of range" errors!
Reverb        = 0FFB000h
CoReverb = 1000014h

;Better keep the following values
PrecDiv = 1 shl Prec
WordDiv = 1 shl (Prec-15);used to normalize to +-2^15

;PCM-wave file header
;comment these lines out if you prefer a RAW file
db    'RIFF'
dd  (Length shl 1) + 36
db       'WAVEfmt '
dw      10h,0,1,1
db 11h,2Bh,0,0,22h,56h
dw       0,2,10h
db   'data'
dd  (Length shl 1)

;Initiating robber and prey variables
A = 0 shl Prec
B = 1 shl Prec

;Main fluctuating growth model calculation loop
repeat Length
 ;This could be optimized by implementing a "sar" operator into Fasm
 Tmp = ( A*CoLambda + B*Lambda )/PrecDiv
 B   = ( B*CoLambda - A*Lambda )/PrecDiv
 A = Tmp
 dw (A/WordDiv)
 Lambda   = (  Lambda *   Reverb) shr Prec
 CoLambda = (CoLambda * CoReverb) shr Prec
end repeat
    


I know that this kind of stuff uses mathematical difficult stuff. But if you don't know how it works, ask me, but please, try to be specific.
(DOn't blame me if my math-vocabulary is not always correct 'cause english is not my language of birth) Wink

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 22 Sep 2004, 18:46
View user's profile Send private message Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
And for all those who really like fractal images, here is a complete collection of my best images. Although they are much smaller than the originally PNGs (about 5-22Mb PNG per image Shocked ~ 20MEGAPIXELS), the archive is still _CHUNKY_ Rolling Eyes (sorry old modems) not to degrade quality too much (1Mpixel per image).

If someone whiches, I could give him the originals...

They were all created with FractInt 20.0 ans UltraFractal 3, so I could pass you the parameters/formulas too.

Don't mind me, but for the TrueColor ones, I prefer using the LWF-format
(Lura Wave format) which is already supported many image programs or plugged in(Photoshop, IrfanView, XnView, PainShopPro...) not to break compatibility, but for better image quality!

Crying or Very sad Crying or Very sad Crying or Very sad
Sorry folks! but I must interrupt this post because it seems to be impossible to upload this 6.27MB archive here.
=>Privalov, is there a file size limitation? How could I upload this file, HELP!

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 22 Sep 2004, 19:14
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1095
Location: Poland
If you want, you can send it on my email (mtymek _@_ decard.net) and I will upload this archive on my website (I can keep it here for some time).
Post 22 Sep 2004, 19:52
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
Has anyone tried my Beat already?
Post 22 Sep 2004, 20:33
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
MCD wrote:
And for all those who really like fractal images, here is a complete collection of my best images. Although they are much smaller than the originally PNGs (about 5-22Mb PNG per image Shocked ~ 20MEGAPIXELS), the archive is still _CHUNKY_ Rolling Eyes (sorry old modems) not to degrade quality too much (1Mpixel per image).

If someone whiches, I could give him the originals...

They were all created with FractInt 20.0 ans UltraFractal 3, so I could pass you the parameters/formulas too.

Don't mind me, but for the TrueColor ones, I prefer using the LWF-format
(Lura Wave format) which is already supported many image programs or plugged in(Photoshop, IrfanView, XnView, PainShopPro...) not to break compatibility, but for better image quality!

Crying or Very sad Crying or Very sad Crying or Very sad
Sorry folks! but I must interrupt this post because it seems to be impossible to upload this 6.27MB archive here.
=>Privalov, is there a file size limitation? How could I upload this file, HELP!


Why do you do such a thing?
you can make a few hundred byte com file which zooms as further as you wanna zoom in to the fractal land. real-time

and you shouldn't upload big files, just make a free website or something like bravesnet.com , monkeymanv2.com, 250free.com , khsv.tk , web1000.com , free.hostdepartment.com ... and then give a link instead

MATRIX
Post 22 Sep 2004, 22:29
View user's profile Send private message Visit poster's website Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
MCM, yeah, just tried it -- rather cool Very Happy (works (as expected) flaw less in linux as well Smile)
Post 23 Sep 2004, 21:51
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
you continue to amaze, MCM Wink
the beat generator works as you said it would.. and with such little code

well done Cool
Post 24 Sep 2004, 10:09
View user's profile Send private message Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
Well, there are dozens of similar things I _COULD_ do, but don't have time/nerve starting it. If someone whiches any further Fasm-experiments,

just write it here/post me a PM.

I should really stop this kind of fancy, but I have lots of maths/physics stuff I would really like to try with Fasm.

You can really get addicted to this kind of semi-Nonsense. Help me!

Just a thing: my nick is MCD which means Mad Computer Doggy Laughing (MCM? MGM? Confused )
Post 14 Oct 2004, 17:44
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.