It is currently Mon Nov 30, 2020 6:12 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How easy is to draw Sprites on Screen in Asm?
PostPosted: Thu Jan 28, 2016 12:30 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Nov 08, 2008 8:19 pm
Posts: 109
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: How easy is to draw Sprites on Screen in Asm?
PostPosted: Thu Jan 28, 2016 1:22 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1672
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!

_________________
Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,
it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.


Top
 Profile  
Reply with quote  
 Post subject: Re: How easy is to draw Sprites on Screen in Asm?
PostPosted: Thu Jun 16, 2016 1:34 am 
Offline
User
User

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


Top
 Profile  
Reply with quote  
 Post subject: Re: How easy is to draw Sprites on Screen in Asm?
PostPosted: Thu Jun 16, 2016 2:06 am 
Offline
Enthusiast
Enthusiast

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


Top
 Profile  
Reply with quote  
 Post subject: Re: How easy is to draw Sprites on Screen in Asm?
PostPosted: Mon Jun 22, 2020 12:07 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Nov 26, 2015 6:52 pm
Posts: 189
Location: Italy
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:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye