Some useful tricks for game programming

All 680x0 related coding posts in this section please.

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

mcoder
Atari maniac
Atari maniac
Posts: 90
Joined: Thu Oct 04, 2007 6:42 pm
Location: France

Some useful tricks for game programming

Post by mcoder »

I'll try to give you some hints before I completely forget them.

The first trick is how to implement a scoring routine.

First, you MUST not use integer scorings, since it requires a lot of divisions to get the decimal decomposition.
Instead, I use BCD.

To add a value to the score:

Code: Select all

lea score+4, a0
lea value+4, a1
sub d0,d0 ; to clear the carry
abcd -(a1), -(a0)
abcd -(a1), -(a0)
abcd -(a1), -(a0)
abcd -(a1), -(a0)
Now, the carry is set to 1 if the score overflows.

How to convert this to decimal ?
Very simple:

Code: Select all

lea digits, a0 ;8 bytes
move.l score, d0
move.l d0, d1
and.l #$F0F0F0F0, d0
eor.l d0,d1
lsr.l #4, d1
;if your character set is ASCII, add the 2 following lines:
;add.l #$30303030, d0
;add.l #$30303030, d1
movep.l d0,0(a0)
movep.l d1,1(a0)
Now, a0 contains the score.
It's the only usage I ever found to the abcd instruction !!!

I hope the above routines are accurate, since I'm doing this from memory (after 15 years without reading 68000).

JC
Last edited by mcoder on Mon Oct 08, 2007 9:46 am, edited 2 times in total.
mcoder
Atari maniac
Atari maniac
Posts: 90
Joined: Thu Oct 04, 2007 6:42 pm
Location: France

Post by mcoder »

Second article: how to shift sprites in realtime.

This time, I'll explain a technique that completely outperforms the lame 4 planes shifter:

Code: Select all

moveq #0,d0
moveq #0,d1
moveq #0,d2
moveq #0,d3
move (a0)+, d0
move (a0)+, d1
move (a0)+, d2
move (a0)+, d3
lsr.l d7,d0
lsr.l d7,d1
lsr.l d7,d2
lsr.l d7,d3
used in probably 100% of the Atari ST games ! (and a lot of demos).

The trick is to realize that you can shift 2 planes with only one register, thus you need 2 registers to shift 4 planes:

Code: Select all

move.l (a0)+, d0
move.l (a0)+, d1
rol.l d7, d0
rol.l d7, d1
Ok, now you have to do some swapping, to get the correct masks.
We'll assume, we use d7=4

Code: Select all

move.l (a0)+, d0
move.l (a0)+, d1
rol.l #4, d0
rol.l #4, d1
move.l d0, d2
move.l d1, d3
and.l #$000F000F, d0
and.l #$000F000F, d1
eor.l d0, d2
eor.l d1, d3
swap d0
swap d1

Now, I think you got the idea.
I'll publish the source code of my routines if somebody is interested.

JC
Last edited by mcoder on Mon Oct 08, 2007 9:46 am, edited 1 time in total.
mcoder
Atari maniac
Atari maniac
Posts: 90
Joined: Thu Oct 04, 2007 6:42 pm
Location: France

Post by mcoder »

Third article: how to use one more register.

When you are in supervisor mode, you can use the usp register, to save any register:

Code: Select all

move.l a0, usp

Code: Select all

move.l usp, a0
It's very useful if you need to store a pointer.

Now, suppose you want to copy a large block.
The 'normal' trick is:

Code: Select all

movem.l (a0), d0-d7/a2-a6
movem.l d0-d7/a2-a6, (a1)
It is possible to use the a7 register as follows:

- first, add a trap that allows to pass in supervisor mode (I use the ILLEGAL function). I have not the code here, but your trap should be something like:

Code: Select all

move.l (a7), a0
addq #2, a0
jmp (a0)
- then, you switch to user mode:

Code: Select all

and #$DFFF, SR ;($2000 is supervisor)
now, you can use the a7 register without problem, since it's the USP register:

Code: Select all

movem.l (a0), d0-d7/a2-a7
movem.l d0-d7/a2-a7, (a1)
It saves 7% of CPU time.
For example, Nick of TCB didn't use this trick in his megadister screen.

Of course, you cannot use a function like JSR, but you can use pea or push something on the stack, if you put the stack where you want.
For example, you can fill the screen by using a stack pointing at the end of the screen.

JC
User avatar
Zorro 2
Administrator
Administrator
Posts: 2305
Joined: Tue May 21, 2002 12:44 pm
Location: Grenoble (38) - France
Contact:

Post by Zorro 2 »

Very interesting tricks mister MCoder.

Thanks for the explanations !

For our users, can you send some exemples ?

I feel you're motivated to write some articles in 68K, you can use the AL-Wiki for that. (If you want of course...)

Once again, thanks to post on this forum. C'est sympa :wink:
.~^ Member of NoExtra Team :: Member of HMD :: Pouet :: DemoZoo :: GitHub ^~.
User avatar
Desty
Atari God
Atari God
Posts: 1988
Joined: Thu Apr 01, 2004 2:36 pm
Location: 53 21N 6 18W
Contact:

Post by Desty »

This is interesting stuff, thanks... How about coding a new demo to demo these techniques?
tá'n poc ar buile!
mcoder
Atari maniac
Atari maniac
Posts: 90
Joined: Thu Oct 04, 2007 6:42 pm
Location: France

Post by mcoder »

Desty wrote:This is interesting stuff, thanks... How about coding a new demo to demo these techniques?
As precised in the title, these are techniques useful for game programming.
BTW, I'm sorry, but I don't intend to code any more in 68000.
The reason is that I have a lot of other active projects (I'm a contest organizer now -recmath.org-, and I run several distributed projects).

As Freddo suggested, I'll try to enter these tricks on the wiki, since I collected a large list of useful tricks, and it would be too bad that they are lost forever.

An 'obvious' trick, that is not so obvious:

Code: Select all

move.l d0,d1
and #$F,d1
can be replaced by:

Code: Select all

moveq #$F,d1
and d0,d1
It's faster and shorter.
Works also for masks like $FFF0 (moveq #-16), etc...

I'll also publish the source code of our 3D demos.
One is the official 3D demo (a version which appeared in the European Demos), but the other one is a 3D engine for games. It includes 16 colors rendering, with very fast routines. These have been coded by Algernon, Ziggy Stardust, myself and Zarathustra (who helped optimizing some parts).

JC
User avatar
Zorro 2
Administrator
Administrator
Posts: 2305
Joined: Tue May 21, 2002 12:44 pm
Location: Grenoble (38) - France
Contact:

Post by Zorro 2 »

mcoder wrote:As Freddo suggested, I'll try to enter these tricks on the wiki, since I collected a large list of useful tricks, and it would be too bad that they are lost forever.
Thanks to keep our time to do that ! Don't hesitate to ask mister MugUk to help you.
mcoder wrote:I'll also publish the source code of our 3D demos.
One is the official 3D demo (a version which appeared in the European Demos), but the other one is a 3D engine for games. It includes 16 colors rendering, with very fast routines. These have been coded by Algernon, Ziggy Stardust, myself and Zarathustra (who helped optimizing some parts).
You can find a lots of codes on my website, if you haven't place to put anywhere on the web, I can publish them on it...
.~^ Member of NoExtra Team :: Member of HMD :: Pouet :: DemoZoo :: GitHub ^~.
User avatar
dma
Atari God
Atari God
Posts: 1217
Joined: Wed Nov 20, 2002 11:22 pm
Location: France
Contact:

Post by dma »

mcoder wrote:One is the official 3D demo (a version which appeared in the European Demos), but the other one is a 3D engine for games. It includes 16 colors rendering, with very fast routines. These have been coded by Algernon, Ziggy Stardust, myself and Zarathustra (who helped optimizing some parts).
Wow, sweet. :)
User avatar
Zorro 2
Administrator
Administrator
Posts: 2305
Joined: Tue May 21, 2002 12:44 pm
Location: Grenoble (38) - France
Contact:

Post by Zorro 2 »

dma wrote:
mcoder wrote:One is the official 3D demo (a version which appeared in the European Demos), but the other one is a 3D engine for games. It includes 16 colors rendering, with very fast routines. These have been coded by Algernon, Ziggy Stardust, myself and Zarathustra (who helped optimizing some parts).
Wow, sweet. :)
Yep Dma, remember Chuck talking about this... particulary 3d routs from Ziggy.
.~^ Member of NoExtra Team :: Member of HMD :: Pouet :: DemoZoo :: GitHub ^~.
User avatar
Marakatti
Atari God
Atari God
Posts: 1412
Joined: Sat Jun 18, 2005 9:58 am
Location: Finland
Contact:

Post by Marakatti »

mcoder wrote:One is the official 3D demo (a version which appeared in the European Demos
A bit offtopic but the Mega Tridi is really the best 3D demo I've ever seen up to date. I remember when we first saw it and the thing with bouncing ball inside zoomed to the screen we yelled "come on come on come on... poo, it really came! How they could make it this BIG!" Our jaws really dropped.

I remember recording the demo to the VHS and lent it to my Amiga-friends at school. After that I never heard that ST was a lame machine from their mouths :)

My favourite is the bending tube that walks around on the screen not to mention the last space station... Why didn't we have Frontier with these routs... Just amazing!
-------------< Member of Atarimania >-----------
-< ST / STe / Falcon030 / TT030 archiver >-
-------------> www.atarimania.com <-------------
mcoder
Atari maniac
Atari maniac
Posts: 90
Joined: Thu Oct 04, 2007 6:42 pm
Location: France

Post by mcoder »

Marakatti wrote:I remember recording the demo to the VHS and lent it to my Amiga-friends at school. After that I never heard that ST was a lame machine from their mouths :)
Yes, the Atari ST was a good machine, but the Amiga was better.
It was only because there was a tough competition between ST and Amiga coders that we got these beautiful demos.

I'll tell you the story behind this demo, since it's a nice story.

First, my story on the ST (I had a story on the Oric before, but I guess it's off topic): in 1987, I was a game programmer for Titus, and I had to go to the army (yes, I'm more than 40 now), and I did my military service in a city called Metz.
Here, I discovered a small shop selling Amigas, and among the frequent users, there were several guys who wrote one of the very first Amiga demo: The Wild Copper Demo. I don't know if you remember, but it was very nice at this moment.
This was a shock for me, since I was one of the very best technical coder at Titus (doing all the asm coding on the 68000), but I didn't know this world.
When I returned from my service, I contacted a guy who has a nice collection of C64 demos, and I discovered this world on the C64. C64 demos were much impressive than Amiga's.
I decided to code a screen with the guy, and we released my first demo under the name "Magnum Force". The screen is ugly, but the code was very technical (it was a big scroller).
Sorry, but I don't remember his name, even though he contacted me recently. Sorry !!!

After that, I encountered 2 guys, with whom I coded the first french fullscreen (I cracked the big demo), and all the screen was moving.
I don't remember the name of our group, but I did all the work (later, one of the guys became a game programmer).

Dissatisfied with Titus, I quit and started coding with one of my friends in order to create our company.
After one year, we abandoned this project, and I found a work at Ocean France, where I had to finish Ivanhoe.
I discovered that the Amiga coders were not very strong, because they had almost everything with their hardware, contrary on the ST, where you had to code all the graphics (requiring most of the CPU) by hand, thus requiring to optimize all the logic.

I bought an Amiga and discovered the last demos, and was not really impressed, since I was pretty sure to be able to recode them on the ST.
So, I took the task to recode the most impressive ones (my only criterion is that it would need to be very challenging and technical).

At this moment, I encountered the first ST groups, and was invited to the Transbeauce demo.
I sympathized with the organizers and I ended up by writing the intro/menu/loader/reset demo of the Transbeauce.
At this party, I encountered Ziggy Stardust (Vincent Penné).
Realizing that I could never work alone on a 3D demo, I decided to create a team to build a 3D demo and also a 3D engine for a game (since I'm a game programmer).
In the team, we were: Algernon (Claude Levastre, being the brother of one of the Ocean graphists) and Ziggy Stardust.
Zarathustra (Pascal de France) joined briefly, but since he was pretty lazy (I think he never released a screen), we stopped inviting him.

Ziggy and I developed simultaneously a 3D demo, while Algernon concentrated on the 16 colors routines.
We were able to have a small cube at the beginning of our work, and we got a large cube when we released the demo.
The whole process took one year and a half !

My version was presented first in England, by Illegal, whom I gave a disk to show the screen (subsequently, I got a thank in a Lost Boys demo).
The announcement of our achievement was merely to show to TCB that we succeeded in writing a 50Hz 3D demo, which seemed impossible before !

Finally, Ziggy added so much features (spheres, etc...), that we used his code to release the 3D demo (I merely added a 3D scroller, but all the code was from Ziggy, with the help of our dream team).
My code was a little bit faster than Ziggy's, but Ziggy really does know how to make a show !

The fact that the circle zooms perfectly is a lucky coincidence !

Marakatti wrote: My favourite is the bending tube that walks around on the screen not to mention the last space station... Why didn't we have Frontier with these routs... Just amazing!
Yes, these objects were from Gudul (torn revolution objects).
You cannot write a game with the routines, since we are limited to 4 colors, and the palette is dynamically reassigned at each frame.

Anyway, we succeeded perhaps the most technical software-only demo.

For example, we build the projection matrix without mul/div, and determining if a polygon is visible is done without mul/div in 75% of cases !

JC
User avatar
alexh
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3066
Joined: Wed Oct 20, 2004 1:52 pm
Location: UK - Oxford
Contact:

Post by alexh »

Marakatti wrote:Mega Tridi is really the best 3D demo I've ever seen up to date.
I think Mega Tridi is amazingly good, especially as it is all real time, no precalc.

But the best looking Atari 3D demo has to be STNICCC2k 3D demo from Leonard of Oxygene.

He cheats though, If you read the comments, all the geometry is precalculated and streamed off the disk.

But if you read the credits mcoder did the packer!
simonsunnyboy
Moderator
Moderator
Posts: 5726
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Post by simonsunnyboy »

Good demos are all about cheating :>
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
User avatar
Brume
Red eyes
Red eyes
Posts: 4276
Joined: Mon Apr 22, 2002 10:16 am
Location: France
Contact:

Post by Brume »

mcoder wrote:After that, I encountered 2 guys, with whom I coded the first french fullscreen (I cracked the big demo), and all the screen was moving.
I don't remember the name of our group, but I did all the work (later, one of the guys became a game programmer).
Wasn't the group named The Starfires?
One of your screens 'Genius has no border' was included in the hoby one megademo by The Voyagers.
Looking for a CosmosEx unit for Falcon...
mcoder
Atari maniac
Atari maniac
Posts: 90
Joined: Thu Oct 04, 2007 6:42 pm
Location: France

Post by mcoder »

Brume wrote:
mcoder wrote:After that, I encountered 2 guys, with whom I coded the first french fullscreen (I cracked the big demo), and all the screen was moving.
I don't remember the name of our group, but I did all the work (later, one of the guys became a game programmer).
Wasn't the group named The Starfires?
One of your screens 'Genius has no border' was included in the hoby one megademo by The Voyagers.
Bingo !

I just retrieved its source code, but the fullscreen doesn't work with Steem
User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 3175
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Post by Cyprian »

alexh wrote:
Marakatti wrote:Mega Tridi is really the best 3D demo I've ever seen up to date.
I think Mega Tridi is amazingly good, especially as it is all real time, no precalc.
I love this screen! IMO this is the best part of European Demos :)
earx
Captain Atari
Captain Atari
Posts: 353
Joined: Wed Aug 27, 2003 7:09 am

Post by earx »

the overlanders 3d is very good. i think it's only topped in demo land by the synergy demo (all 1 VBL: the pacman shape is just fornicating amazing there), but synergy made a mistake by wanting everything 1 VBL in my eyes, limiting the complexity of the scenes more than the overlanders screen.

i guess overlanders (ziggy) pioneered the delta polygon technique?
earx
Captain Atari
Captain Atari
Posts: 353
Joined: Wed Aug 27, 2003 7:09 am

Post by earx »

btw, i didn't spot the overscan in the overlanders 3d? i could swear it was in there somewhere, my memory must be rusty..
User avatar
Marakatti
Atari God
Atari God
Posts: 1412
Joined: Sat Jun 18, 2005 9:58 am
Location: Finland
Contact:

Post by Marakatti »

earx wrote:btw, i didn't spot the overscan in the overlanders 3d? i could swear it was in there somewhere, my memory must be rusty..
Wasn't it in the Froggies Over The Fence demo?
-------------< Member of Atarimania >-----------
-< ST / STe / Falcon030 / TT030 archiver >-
-------------> www.atarimania.com <-------------
earx
Captain Atari
Captain Atari
Posts: 353
Joined: Wed Aug 27, 2003 7:09 am

Post by earx »

indeed, that's the one! thanks. =)
mcoder
Atari maniac
Atari maniac
Posts: 90
Joined: Thu Oct 04, 2007 6:42 pm
Location: France

Post by mcoder »

earx wrote:i guess overlanders (ziggy) pioneered the delta polygon technique?
No, we didn't use delta polygons !

JC
earx
Captain Atari
Captain Atari
Posts: 353
Joined: Wed Aug 27, 2003 7:09 am

Post by earx »

No, we didn't use delta polygons !
congrats on the fast filling, then :)
User avatar
leonard
Moderator
Moderator
Posts: 681
Joined: Thu May 23, 2002 10:48 pm
Contact:

Post by leonard »

Hi MCoder ! Glad to see you there !

About 3d demo: it's no doubt european's 3d screen is very impressive, and it was the first one!

Btw technically speaking Equinox's routs were faster almost at the same period (2 or 4bitplan routines)

And last but nor least, to me the best 3d technical demo is the 3d screen by Rapido (Synergy). Very impressive, especially the last part (3d dots) which use a very, very fast real time 3d transform!

Arnaud
Leonard/OXYGENE.
mcoder
Atari maniac
Atari maniac
Posts: 90
Joined: Thu Oct 04, 2007 6:42 pm
Location: France

Post by mcoder »

Hi Arnaud !
leonard wrote: Btw technically speaking Equinox's routs were faster almost at the same period (2 or 4bitplan routines)
Well, let's describe the chronology:

1. somewhere in 1989-1990: an Amiga group released the first 3D demo in 50 fps (I'm not sure which group, maybe SpreadPoint)
2. a few weeks later, I got this demo, and fell instantly in love with it
3. as usual, I tried to convert it to the ST, and I discover that the Amiga version uses blitter filling :?
4. I started then to write code to display a 3D cube on my ST, but the cube was quite small after a few weeks
5. I realized then that I needed new ideas, and thus I recruit Ziggy and Algernon, with the goal of writing a 3D game (thus no precomputation)
6. a few months later, we integrate Zarathustra, but due to a leaked 16 colors demo (I guess with the Brainstorm group, who were writing the official demo for Atari), he's kicked out of our group :(
7. several weeks later, we give a demo (my version) to Illegal, so he could show it at a party in England, and I got a greeting from The Lost Boys, who saw our preview.
8. meanwhile, Ziggy writes a sphere and ellipse routine, in a few days (!)
9. later, we heard that Equinox got the demo (Illegal was their good friend)
10. after that, there were rumors that TCB would release a 3D demo, so we started to code as crazies to release this screen (we worked 1 year and a half on it, and didn't want to lose the first posting place !)
11. the screen is released in the European Demos, and we can start to breathe, we were the first ! I guess the screen was pretty much a shock for both ST and Amiga users, due to the amount of work we spent.
12. although we concentrated on the 16 colors routines, nothing is released with that, and our game is cancelled.
13. a few months later, Equinox released their screen, so I rewrote my plane filler (unreleased version, but Mr Bee got all my sources and I hope he released some screens), and I quit the demo-scene. Ziggy released the fullscreen 3D demo timer.
14. TCB released their 3D demos several months later, but I don't remember the screen, it may not have been very impressive
15. Algernon worked more and more on the 3D, and coded Darkstone for Delphine, which is the only game I played from them !

So, you see that we had to urge to release this demo, since there were so many leaks.
As our main goal was to ultimately write a game, we didn't even think about delta-animation, neither logs instead of muls.

So, yes, if another group would have released a 3D screen, we would have easily improved the routines !
leonard wrote: And last but nor least, to me the best 3d technical demo is the 3d screen by Rapido (Synergy). Very impressive, especially the last part (3d dots) which use a very, very fast real time 3d transform!
Yes, I saw that right now.
It's a nice demo, but a little bit long (and yes, their display routines are very fast).
It should have been impressive at that time, but now, it's quite outdated.

JC
C-Rem
Captain Atari
Captain Atari
Posts: 395
Joined: Wed May 01, 2002 6:45 pm

plop

Post by C-Rem »

Time to work on a new one ;)

we're all waiting for a #1 3D demo !!
Post Reply

Return to “680x0”