Article View: rec.games.programmer
Article #734Re: fast VGA sprite routines
From: Ross Ridge
Date: Fri, 14 Aug 1992 15:10
Date: Fri, 14 Aug 1992 15:10
62 lines
2476 bytes
2476 bytes
bbs.brienv@tsoft.sf-bay.org (Brien Voorhees) writes: > > I've been working on some graphics routines for VGA mode 13h to handle >animating sprites while retaining the background and have managed to get > 'em goin' pretty fast (about 25-35 fps on a 486) but that's without >much other overhead. Once I add collision detection, sound, music, etc. >I don't think I'm going to have enough cpu time to spare. > mov cx,ywidth // Set outer loop to run <ywidth> times >rowloop: // once per row (duh) > push cx // save what row we're on > mov cx,xwidth // Set inner loop to run for each pixel on this line >subloop: // There are actually two loop instructions that goto this >label > lodsb // grab a pixel > cmp al,0 > je short itsblank // if it's 0, skip it > stosb // otherwise, write it > loop subloop > jmp short endsubloop // Jump outta' here. Don't wanna' fall thru to > // the other subloop section! >itsblank: > inc di // Keep the destination index in sync > loop subloop // Ready for the next pixel > >endsubloop: > add di,nextlineoffset // Set destination pointer to proper offset > // for beginning of next image line > pop cx // Where were we? > loop rowloop // Ready for next line loop instruction lose on '386 and better CPUs, and you're going to a bit of trouble to use them. The stosb instruction isn't much of a win either. Try this: mov dx,ywidth mov bx,xwidth loop1: mov cx,bx loop2: lodsb or al,al je skip mov [es:di],al skip: inc di dec cx bne loop2 add di,nextlineoffset dec dx bne loop1 It's probably faster on 8086's too if your sprites don't have many zero's in them. Ross Ridge -- Ross Ridge - The Great HTMU l/ // [OO][oo] ross@zooid.guild.org /()\/()/ uunet.ca!zooid!ross db //
Technical Details
Message-ID:
<1992Aug14.151042.23556@zooid.guild.org>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uunet.ca!geac!zooid!rossReferences:
<RVmgPB1w165w@tsoft.sf-bay.org>Show Full Headers
Complete Article Headers
Newsgroups: rec.games.programmer,comp.os.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uunet.ca!geac!zooid!ross From: Ross Ridge <ross@zooid.guild.org> Subject: Re: fast VGA sprite routines Organization: ZOOiD BBS Date: Fri, 14 Aug 1992 15:10:42 GMT Message-ID: <1992Aug14.151042.23556@zooid.guild.org> Followup-To: comp.os.msdos.programmer References: <RVmgPB1w165w@tsoft.sf-bay.org> Lines: 62