Page 1 of 1
Genesis programming optimisation tricks
Posted: Wed Jan 17, 2007 2:16 pm
by Stef
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
Posted: Wed Jan 17, 2007 5:05 pm
by Ketsuban
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.
Posted: Wed Jan 17, 2007 8:44 pm
by Stef
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

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

Posted: Wed Jan 17, 2007 9:18 pm
by Ketsuban
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.
with
which might not quite work as expected. =P
Posted: Thu Jan 18, 2007 9:33 am
by TmEE co.(TM)
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).
Posted: Thu Jan 18, 2007 10:49 am
by Stef
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.
Posted: Thu Jan 18, 2007 2:19 pm
by TmEE co.(TM)
My rotation stuff doesn't rotate, more like skews. It uses constants and additions. No rotation...
so TAS is not useful
Posted: Thu Jan 18, 2007 2:27 pm
by Stef
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.
Posted: Fri Jan 19, 2007 6:32 am
by TmEE co.(TM)
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.
Re: Genesis programming optimisation tricks
Posted: Fri Jan 19, 2007 10:17 pm
by cdoty
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.
Posted: Wed Feb 14, 2007 8:07 am
by Pascal
this link seems broken :
* Fast 2D rotation [+] :
http://www.cfxweb.net/modules.php?name= ... le&sid=664
Do someone got a cache copy ?
tia
Posted: Wed Feb 14, 2007 2:29 pm
by Stef
It work for me, i guess the site is now back
