Genesis programming optimisation tricks

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Genesis programming optimisation tricks

Post by Stef » Wed Jan 17, 2007 2:16 pm

I renamed the topic since my stuff doesn't only cover the 68000 CPU.
So here's the topic where we will concentrate all interesting tricks, optimisations, tweaks, cheats... for get the best from the genesis hardware :)

General

* Fast multiplication with log2 method (Z80 asm sources included) [++] :
http://www.devrs.com/gb/files/logmult.txt

* Fast 2D rotation [+] :
http://www.cfxweb.net/modules.php?name= ... le&sid=664


68000 assembly programming

* The most interesting part for me "Instead of Use ... Use ... Save x cycles, x bytes" [+++] :
http://www.mactech.com/articles/mactech ... index.html

* 68000 Tricks and traps [+] :
http://linux.cis.monroeccc.edu/~paulrsm ... ick68k.htm

* Fast 3D Transform for 68000 (very specific) [+] :
http://www.catalase.com/optrot3d.htm
Last edited by Stef on Wed Jan 17, 2007 8:39 pm, edited 2 times in total.

Ketsuban
Interested
Posts: 25
Joined: Wed Jan 17, 2007 11:37 am
Location: United Kingdom of Great Boredom

Post by Ketsuban » Wed Jan 17, 2007 5:05 pm

I think I know what you're talking about, and I'd advise a degree of caution. Some of the optimisations in the document may not be very helpful for the Megadrive, since (according to Wikipedia) the Megadrive's implementation of TAS is "broken" - it does not write to memory. (The Megadrive 3 had a "working" implementation of TAS, causing a few games to break.)

First post here, by the way, so hi from the UK.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Jan 17, 2007 8:44 pm

Quickman wrote:I think I know what you're talking about, and I'd advise a degree of caution. Some of the optimisations in the document may not be very helpful for the Megadrive, since (according to Wikipedia) the Megadrive's implementation of TAS is "broken" - it does not write to memory. (The Megadrive 3 had a "working" implementation of TAS, causing a few games to break.)

First post here, by the way, so hi from the UK.
Welcome Quickman :D
We're always happy to see some new guys here :)

I know about TAS instruction which actually can't lock the BUS on genesis hardware. I crushed it to get Gargoyles working correctly on Gens...
Seems you have a good knowledge of the genesis hardware, we need guys like you :p

The links i posted doesn't rely specifically on TAS instruction but on some general 68000 optimisations and even some more globals ones ;)

Ketsuban
Interested
Posts: 25
Joined: Wed Jan 17, 2007 11:37 am
Location: United Kingdom of Great Boredom

Post by Ketsuban » Wed Jan 17, 2007 9:18 pm

I have a moderately good knowledge, but it's fairly incomplete.

I was actually thinking of the optimisation document on TµEE's website, which suggests replacing e.g.

Code: Select all

bset #7,dN
beq ???
with

Code: Select all

tas dN
bpl ???
which might not quite work as expected. =P

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Thu Jan 18, 2007 9:33 am

Yesterday I just read about TAS instruction, I read that it is good for multi CPU systems, but I didn't quite get it. what does it really do ? From that Wiki article I read that it wouldn't work on real HW.

Anyway I did quite fast 2D rotation in QB using only cos/sin table and additions, no muls/divs or any other slow stuff. It can be optimized a lot if I use fixed point instead float (I did as simple as possible to demonstrate stuff to my brother). If anyone wants, I can upload the code. I'm not very sure, but it had a flaw in it (did it quite some time ago).
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Jan 18, 2007 10:49 am

2D rotation algo without any multiplications or divisions is always interesting :)
Does the rotation was accurate ?

About TAS instruction, actually this one handle semaphore for ressource acces.
It tests the bit 7 of a byte (memory or register). This bit should indicate if a ressource is free (0) or not (1).
- If the resource is not free (bit 7 = 1) then TAS do nothing.
- If the resource is free (bit 7 = 0), TAS instruction put it as no more free (set bit 7 to 1) then locks the BUS to access resource.

In multi CPU system, this prevent another CPU to access the protected resource at the same time.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Thu Jan 18, 2007 2:19 pm

My rotation stuff doesn't rotate, more like skews. It uses constants and additions. No rotation...

so TAS is not useful
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Jan 18, 2007 2:27 pm

ok.

TAS is just usefull in register use on genesis.
This instruction only takes 4 cycles and do the following basic instruction :
- test bit 7 (Z flag modified)
- set bit 7 if it was cleared.

It can be usefull but pretty difficult to place afaik.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Fri Jan 19, 2007 6:32 am

TAS is pretty hard to put somewhere, I guess Sonic3 would have used it: bit7 indicates quite some in the SRAM (I did some hacking on it) but I guess they(Sonic team) couldn't make any good use of TAS.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

cdoty
Very interested
Posts: 117
Joined: Wed Nov 29, 2006 2:54 pm
Location: Houston, TX
Contact:

Re: Genesis programming optimisation tricks

Post by cdoty » Fri Jan 19, 2007 10:17 pm

Stef wrote:* 68000 Tricks and traps [+] :
http://linux.cis.monroeccc.edu/~paulrsm ... ick68k.htm
I've seen the 'Fast subroutine calls' optimization used in many arcade games. I always wondered why they did that way. Makes sense now! :)

I though maybe they were trying to obfuscate the code or something.

Pascal
Very interested
Posts: 200
Joined: Wed Nov 29, 2006 11:29 am
Location: Belgium
Contact:

Post by Pascal » Wed Feb 14, 2007 8:07 am

this link seems broken :

* Fast 2D rotation [+] :
http://www.cfxweb.net/modules.php?name= ... le&sid=664


Do someone got a cache copy ?

tia

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Feb 14, 2007 2:29 pm

Pascal wrote:this link seems broken :

* Fast 2D rotation [+] :
http://www.cfxweb.net/modules.php?name= ... le&sid=664


Do someone got a cache copy ?

tia
It work for me, i guess the site is now back :)

Post Reply