Palette register address in Dungeon Master and CSB

GFA, ASM, STOS, ...

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

gothmog
Atari freak
Atari freak
Posts: 54
Joined: Thu Apr 01, 2004 5:23 pm

Palette register address in Dungeon Master and CSB

Postby gothmog » Thu Aug 01, 2013 7:52 pm

I have a technical question for Atari gurus regarding the address of the color palette registers used in Dungeon Master and its sequel Chaos Strikes Back.

First some background. Both games use a trick to use more than 16 colors on screen: the top and the bottom of the screen are drawn with one color palette and the middle of the screen (containing the dungeon view) is drawn using another color palette. This allows to manage various levels of brightness in the dungeon view while not changing the colors of the interface on top and bottom.

The trick works this way: when a vertical blank interrupt occurs, the palette for the top and bottom is configured in the video registers. Timer B is also programmed to trigger an horizontal blank interrupt on line 31.
When this hblank interrupt occurs on line 31, the palette is replaced by the palette for the dungeon view. Timer B is programmed again to trigger an interrupt on line 170.
When this second interrupt occurs, the palette is again replaced by the palette for the top/bottom of the screen.
In this way, the palette is set twice each time the screen is refreshed (60 times per second for NTSC, 50 times per second for PAL).

In Dungeon Master, the color palette is set using the base register address 0x00FF8240.
In Chaos Strikes Back, the color palette is set using the base register address 0xFFFF8240.

What difference does that make?
From what I have read here and there, this makes no difference on early Atari ST computers because the 68000 processor only has a 24 bit address bus so the high order byte is simply ignored.
On later machines like TT or Falcon, the 68030 does have a 32 bit address bus. However I have found contradictory information about which address would be the "correct" one to use on these platforms for accessing the palette registers. Maybe both would work.


Can someone enlighten me? Did they make this change in CSB to fix some issue present in DM with some Atari computer models? If so, what is the exact issue? Or maybe this change they made in CSB has no real purpose?

Please also note that both DM and CSB also include another separate function to set color palettes (used when the dungeon view is no visible, on the main screen or the credits), and in both games it uses the address 0xFFFF8240.

Thanks for your help!

User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 1772
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Palette register address in Dungeon Master and CSB

Postby Cyprian » Thu Aug 01, 2013 8:26 pm

gothmog wrote:In Dungeon Master, the color palette is set using the base register address 0x00FF8240.
In Chaos Strikes Back, the color palette is set using the base register address 0xFFFF8240.

What difference does that make?
From what I have read here and there, this makes no difference on early Atari ST computers because the 68000 processor only has a 24 bit address bus so the high order byte is simply ignored.
On later machines like TT or Falcon, the 68030 does have a 32 bit address bus. However I have found contradictory information about which address would be the "correct" one to use on these platforms for accessing the palette registers. Maybe both would work.

in ST, TT and Falcon the hardware registers are mapped to two memory regions 0xFFFFXXXX and 0x00FFXXXX, therefore there is no difference between using 0x00FF8240 and 0xFFFF8240 - both addresses refers to the same Color Register
Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.appspot.com/

Dio
Captain Atari
Captain Atari
Posts: 451
Joined: Thu Feb 28, 2008 3:51 pm

Re: Palette register address in Dungeon Master and CSB

Postby Dio » Thu Aug 01, 2013 10:29 pm

It uses fewer CPU cycles to use $FFFF8240, because that address can be accessed using absolute word addressing rather than absolute long.

So in a typical palette-setting routine:

Code: Select all

lea source, a0
lea $FFFF8240.w,a1 / lea $FF8240,a1
move.l (a0)+,(a1)+ ; x8

The absolute word version is 2 bytes and 4 cycles shorter. Not much, but every little helps. Someone probably missed this case in DM, and spotted it when working on CSB, and made the tweak.

gothmog
Atari freak
Atari freak
Posts: 54
Joined: Thu Apr 01, 2004 5:23 pm

Re: Palette register address in Dungeon Master and CSB

Postby gothmog » Fri Aug 02, 2013 4:51 am

Thanks for your replies

In fact both games load the palette data into the 8 data registers and then use a movem.l instruction:
movem.l D0-D7,0x00FF8240 (DM)
movem.l D0-D7,0xFFFF8240 (CSB)

so they did not make this change for the performance reason you mention.


If both addresses are equivalent, then I really wonder why they made this change...

User avatar
Anima
Atari Super Hero
Atari Super Hero
Posts: 667
Joined: Fri Mar 06, 2009 9:43 am
Contact:

Re: Palette register address in Dungeon Master and CSB

Postby Anima » Fri Aug 02, 2013 5:21 am

gothmog wrote:Thanks for your replies

In fact both games load the palette data into the 8 data registers and then use a movem.l instruction:
movem.l D0-D7,0x00FF8240 (DM)
movem.l D0-D7,0xFFFF8240 (CSB)

so they did not make this change for the performance reason you mention.


If both addresses are equivalent, then I really wonder why they made this change...


Well, I think the reason for this change was to finally use the "correct" address in CSB in their code. Probably they have been urged to do the change for compatibility reasons. However, in respect to this early coding behavior Atari was forced to map these hardware registers just below the 16 MB (maximum 24 bit addressing range) on the Falcon to avoid breaking the ST compatibility too much and so that's reason why you can only use 14 MB on that machine.

Cheers
Sascha

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Palette register address in Dungeon Master and CSB

Postby AtariZoll » Fri Aug 02, 2013 7:31 am

In fact, both addresses are OK, even on Falcon and TT - because PMMU will map $FF8240 correctly (after TOS started). Of course, $FFFF8240 is more compatible, and will work fine on TT (where we have real 32bit addr. bus) even without PMMU. All this is not much relevant for game using TOS, but by some with direct HW access, autoboot, $FFFF8240 is right way if want to work on TT. And may save few bytes in code too.
It is other story that DM and CSB, original floppies fail on Falcon, TT because of copy protection :D
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 1772
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Palette register address in Dungeon Master and CSB

Postby Cyprian » Fri Aug 02, 2013 7:39 am

AtariZoll wrote:In fact, both addresses are OK, even on Falcon and TT - because PMMU will map $FF8240 correctly (after TOS started). Of course, $FFFF8240 is more compatible, and will work fine on TT (where we have real 32bit addr. bus) even without PMMU.

that mapping is done on hardware not PMMU level, therefore both adresses are always valid $00FF8240 $FFFF8240. Someone from EmuTOS has done several tests with and without PMMU and confirmed that.
Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.appspot.com/

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Palette register address in Dungeon Master and CSB

Postby AtariZoll » Fri Aug 02, 2013 7:51 am

That contradicts with some sources. And PMMU emulation is still not good in Hatari.
It is not only palette register what is mapped, but whole peripheral address area $FF8000-$FFFFFF. Well, possible in HW too, for sure, but not typical for Atari :D
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 1772
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Palette register address in Dungeon Master and CSB

Postby Cyprian » Fri Aug 02, 2013 8:20 am

as far as I remember those test were done on real TT and Falcon. If needed we can do some tests on my TT (after my vacation 19th of august)
Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.appspot.com/

gothmog
Atari freak
Atari freak
Posts: 54
Joined: Thu Apr 01, 2004 5:23 pm

Re: Palette register address in Dungeon Master and CSB

Postby gothmog » Fri Aug 02, 2013 5:06 pm

PMMU will map $FF8240 correctly (after TOS started)


What does "After TOS started" mean? Going to the desktop?
DM and CSB start from a bootable floppy disk and the desktop is never seen. They even use some memory usually reserved by GEM to store as much data as possible in RAM.
Has "TOS started" before a floppy boots?
If not, then maybe this is the reason for the change: if TOS has not started when the game runs then the 24 bit address $00FF8240 is not mapped to $FFFF8240 and without the change the game would fail to switch color palettes.

What is the issue with the copy protection on TT/Falcon ? Both games access the FDC directly for copy protection, does it work differently in these computers?

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Palette register address in Dungeon Master and CSB

Postby AtariZoll » Sat Aug 03, 2013 7:24 am

I meant under TOS started point where floppy boot happens. At that moment PMMU is set correctly, there is table at $700. So floppy autoboot or executing AUTO folder will be with proper mapping of I/O addresses for PMMU. So, even games not using TOS calls (may) use regular PMMU setting (and I don't think that there is much, or even any game dealing with PMMU on TT).

Copy protection is actually XBIOS call based, I know direct FDC access only in Chaos Strikes Back Utility floppy (when hint is asked) - and I know what talking. The` reason why it fails on 68030 is tricky, anti-hacker code. Game starts actually (if solve boot with ST low res), but will crash, freeze on later stages when harder protection activates.
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

Dio
Captain Atari
Captain Atari
Posts: 451
Joined: Thu Feb 28, 2008 3:51 pm

Re: Palette register address in Dungeon Master and CSB

Postby Dio » Sun Aug 04, 2013 10:25 am

I'm fairly sure there is direct FDC access in Dungeon Master, at least, IIRC to read a $F7 sector hidden on track 1 or the bad bits in one of the other sectors. It's done in a fairly well obfuscated manner though, as are all DM's and CSB's protection checks. But I may have misremembered...

gothmog
Atari freak
Atari freak
Posts: 54
Joined: Thu Apr 01, 2004 5:23 pm

Re: Palette register address in Dungeon Master and CSB

Postby gothmog » Sun Aug 04, 2013 10:42 am

You're right Dio, DM & CSB use both XBIOS calls (Floprd) and direct FDC access for the copy protection checks. Such direct FDC access is even found in code hidden as a graphic in the graphics.dat file.


As a conclusion, it seems that using 0x00FF8240 or 0xFFFF8240 makes no difference at as both addresses are equivalent on ST and one is redirected to the other on TT and Falcon, be it at the hardware level or programmed by default in the PMMU.

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Palette register address in Dungeon Master and CSB

Postby AtariZoll » Sun Aug 04, 2013 12:21 pm

Dio wrote:I'm fairly sure there is direct FDC access in Dungeon Master, at least, IIRC to read a $F7 sector hidden on track 1 or the bad bits in one of the other sectors. It's done in a fairly well obfuscated manner though, as are all DM's and CSB's protection checks. But I may have misremembered...


I cracked self CSB and DM - and those cracks are based on mapping XBIOS calls, where I supply to game what expects (want source ?) . And it works 100% well. Played game many times thoroughly. For instance you can read sector #F7 well via XBIOS 8 call. Bad bits (flakey) are handled simply by comparing multiple reads of sector 6, and if result is same always, it is copy. And my version of CSB Utility disk has no direct FDC too - it is present only in latest version (2.1), at hint Oracle. What is tricky is hiding of those XBIOS calls. And there is lot of checksums and other anti-hack stuff.
In case of DM: I have no it's original, but I did not see any direct FDC in latest version's Pasti image.
Of course, you are welcome to prove that you are right - please give those direct FDC parts ...
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

gothmog
Atari freak
Atari freak
Posts: 54
Joined: Thu Apr 01, 2004 5:23 pm

Re: Palette register address in Dungeon Master and CSB

Postby gothmog » Sun Aug 04, 2013 12:49 pm

Direct FDC use:

When you save the game, the save function contains code to check copy protection sector #7 containing the fuzzy bits (it is not sector 6).
In DM, this check is performed by reading the sector twice with XBIOS calls to floprd.
In CSB, this check is performed by using custom code, it does NOT use XBIOS calls to floprd. There is indeed one read of sector 6 (useless) using XBIOS floprd, right before the actual copy protection checks, but it has no use for the copy protection.

Some accesses to sector 247 are done with floprd, and others are done using another custom routine.

Also there is hidden code in graphics.dat that uses direct FDC access to read sector #7 and not XBIOS calls (in item #538). See this code here: http://dmweb.free.fr/?q=node/1494#toc20

If you have a disassembly of the game, look for this instruction: movea.w #0x8606,A1
You should find one in a routine to read sector 247 (both DM & CSB) and one in the save game function (CSB only, not in DM).

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Palette register address in Dungeon Master and CSB

Postby AtariZoll » Sun Aug 04, 2013 1:17 pm

It would be good to give exact game version infos. I did not see those code parts, and if they are present, they were not called from some reason . Maybe because some patches done against checksums or like.
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

gothmog
Atari freak
Atari freak
Posts: 54
Joined: Thu Apr 01, 2004 5:23 pm

Re: Palette register address in Dungeon Master and CSB

Postby gothmog » Sun Aug 04, 2013 1:40 pm

What I wrote applies to all known original versions of DM and CSB, available as PASTI images here:
http://dmweb.free.fr/files/DM-Game-AtariST-PASTI.rar
http://dmweb.free.fr/files/CSB-Game-AtariST-PASTI.rar


Social Media

     

Return to “Coding”

Who is online

Users browsing this forum: No registered users and 3 guests