PureBasic Forum
https://www.purebasic.fr/english/

How easy is to draw Sprites on Screen in Asm?
https://www.purebasic.fr/english/viewtopic.php?f=35&t=64701
Page 1 of 1

Author:  Swos2009 [ Thu Jan 28, 2016 12:30 am ]
Post subject:  How easy is to draw Sprites on Screen in Asm?

I never done in Assembler for purebasic as I guess it quite daunting when looking at assembler code at first then become easier once I know what commands they are.

Just wondering how easy is to draw sprites on the screen in Purebasic Asm?

Author:  Keya [ Thu Jan 28, 2016 1:22 am ]
Post subject:  Re: How easy is to draw Sprites on Screen in Asm?

the short answer, from one asm newb to another (welcome to the party!), is that asm is for manipulating bits and bytes at a time, so its great for working with individual pixels but not so much things like sprites that need lots of supporting code, unless you have all the time in the world - i think the "scene" guys from the 90s had too much patience for their own good heehee :) their demos might be a good place to quench your curiosity though!

Author:  barryem [ Thu Jun 16, 2016 1:34 am ]
Post subject:  Re: How easy is to draw Sprites on Screen in Asm?

If you already know how to program in asm then ignore this but if you don't and you're thinking of learning it keep in mind that learning asm in a GUI environment is doing it the hard way. Much better to learn it in an MS-DOS emulator using some of the old, now freeware tools. Then when you feel fairly comfortable with asm try it in procedures in a PB program.

Keep in mind that I don't really know what I'm talking about. I retired over 20 years ago and I'm very out of date. But asm was my first language in the 1960's, long before computers had screens, and for the next 35 years about 1/4 to 1/3 of my programming was in asm. I'm new with PB and really don't have much GUI programming experience at all.

But I sure do recommend that if you want to learn asm you do it with the much simpler tools of a command line envoronment. By the way, that doesn't have to mean DOS. It can be any OS that gives you simple tools. It just means not having to worry about GUI elements and having the freedom to try simple things that you lose in a GUI environment. I mention DOS because I know what's available in DOS. I'd be surprised if comparable command line tools weren't available in other non-GUI environments. I just don't know what they are.

A good way to start would be with Borland's TASM in DOS. You could also use debug or even Borland's Turbo Debugger. Another good option would be A86, which also comes with a nice debugger. These are great learning tools and they're now free and easy to find with Google.

Barry

Author:  Ramihyn_ [ Thu Jun 16, 2016 2:06 am ]
Post subject:  Re: How easy is to draw Sprites on Screen in Asm?

A sprite is a rectangular box of pixels. It usually has a mask, to skip pixels where the background should be seen. Often there is one specific color reserved to avoid a mask. So the code fetches a pixelcolor and if its the special pixelcolor the "plotting" of the pixel will just be skipped and the position increased.

Make a routine which can set a pixel, set counters on the outside, calculate frame buffer offsets and line deltas (the outer loop setup) and then progress through each horizontal line. While you do that, you will realize a lot of possible optimizations. For example its terribly slow if you work on a pixel basis where the same memory adress is fetched, manipulated and written repeatedly - so you change it so each memory access happens only once and if possible, writes multiple pixels at once (as a democoder you would for example realize that a 65k color framebuffer uses 16bit per pixel and therefore you can write 2 or even 4 pixel at once with one write access (write access is the devil - they are usually what costs way more time than anything else).

Find out how to plot a point, add code for a special "mask" (traditionally the deepest black was the mask color), wrap it into a setup and inside a loop to plot X Lines of Y pixels - voila (software) sprites :) Hope that helps.

ps: clipping is a special case obviously. Once you managed to plot a sprite into the middle of the screen, you can deal with those.
pps: my description is for a traditional "scanline/spanline renderer". if you implement that, you will also have the basics for a 3d spanline renderer for different shading algorithms. A flat texture of 32x32 is basically the same like a 32x32 sprite.

Author:  Tristano [ Mon Jun 22, 2020 12:07 am ]
Post subject:  Re: How easy is to draw Sprites on Screen in Asm?

You might want to read Michael Abrash's Graphics Programming Black Book, which is a classic in the field of Assembly graphics:


The book (along with another ASM book by Abrash) was republished with the author's permission.


These are quite old books (late '90s), so some optimization techniques might no longer hold true on modern x86 processors due to hardware changes, but they are still a must-read on the topic for they contain a wealth of information and show you the method and approach used by ASM gurus.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/