How easy is to draw Sprites on Screen in Asm?

Bare metal programming in PureBasic, for experienced users
Swos2009
Enthusiast
Enthusiast
Posts: 112
Joined: Sat Nov 08, 2008 8:19 pm

How easy is to draw Sprites on Screen in Asm?

Post by Swos2009 »

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?
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: How easy is to draw Sprites on Screen in Asm?

Post by Keya »

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!
barryem
User
User
Posts: 19
Joined: Mon Jan 27, 2014 2:40 am

Re: How easy is to draw Sprites on Screen in Asm?

Post by barryem »

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
Ramihyn_
Enthusiast
Enthusiast
Posts: 314
Joined: Fri Feb 24, 2006 9:40 am

Re: How easy is to draw Sprites on Screen in Asm?

Post by Ramihyn_ »

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.
User avatar
Tristano
Enthusiast
Enthusiast
Posts: 190
Joined: Thu Nov 26, 2015 6:52 pm
Location: Italy
Contact:

Re: How easy is to draw Sprites on Screen in Asm?

Post by Tristano »

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.
The PureBASIC Archives: FOSS Resources:
User avatar
tj1010
Enthusiast
Enthusiast
Posts: 621
Joined: Mon Feb 25, 2013 5:51 pm
Location: US or Estonia
Contact:

Re: How easy is to draw Sprites on Screen in Asm?

Post by tj1010 »

In "Real Mode" of any x86 CPU it's amazingly simple with some BIOS setup. Under a kernel you can call sub-system API, or reverse engineer GPU interface. I hear reverse engineering GPU stuff is extremely hard; at least when you go to do 3D pipeline stuff..
The truth hurts.
Post Reply