Sonic and Sega Retro Message Board: Chaotix 1207 discussion - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
  • 13 Pages +
  • ◄ First
  • 11
  • 12
  • 13
    Locked
    Locked Forum

Chaotix 1207 discussion

#181 User is offline evilhamwizard 

Posted 14 May 2014 - 10:16 AM

  • Posts: 1158
  • Joined: 16-June 04
  • Gender:Male
  • Wiki edits:109
Ugh bumping. It's been a long time since this all happened. Feels almost like yesterday.

I wanted to see what was going on with the audio. Still unclear as to why it's producing the sound exactly (even though drx mentioned it on the first page), I decided to disassemble the sound driver (z80) based on the great disassembly ValleyBell did on the final (U) version.

You can download the IDB database and an asm output for both here (you need IDA Pro 6.1 to open the database):

http://www.mediafire...disassembly.zip

Note though, my disassembly is pretty much poo because I'm still pretty much an amateur at IDA Pro. So aesthetics aside, the sound driver used in this prototype is almost identical to the final version but there are some differences. I believe all the subroutines are there, but some instructions were added to a handful of them for the final version. Another oddity, which might be due to my inability to use IDA Pro, I think the instructions that reference data locations that come mostly after all the code are all pointing the the wrong locations. Also note that I have no knowledge of the Z80 or how the sound drivers in these games actually work. I really just wanted to mention this just in case someone might want to take a crack at it. If this has any impact on the audio issue, I don't know, but it's a start at least.

Here are some differences I noticed:
1.) At 0x38, "VInt" is missing instructions that loads 0 to register 'a' and adds $80 to 'a' in a loop. The prototype just disables interrupts and calls "ProcessSndQueue" and "sub_A4" right away before returning.
2.) As stated somewhere before, there's a string from the sound driver programmer in every version. The final version however, is truncated possibly due to the added instructions mentioned before. The prototype has the full string - "casablanca version by MILPO". Nothing seems to reference this string AFAIK.
3.) At 0x204, the disassembly for the final version notes that "ex af, af'" is dead code. This code doesn't exist in the prototype, but space for it does exist. I added the line back manually in my database, but note that it wasn't there originally.
4.) At 0x4C1, the final compares $2A with the accumulator and the following instruction jumps to PlayBGM ($00-$29 for a total of 41 music tracks?), while at 0x4C3 if compares $6F with the accumulator and the following instruction jumps to PlaySFX ($2A-$6E for a total of 68 sound effects?). The prototype is slightly different in this regard - the prototype compares $29 instead of $2A making for a possible total of 40 music tracks while also comparing $69 instead of $6F for a total of 63 sound effects if my math is correct.
5.) At 0x500, the beginning of PlayBGM is different. At the start of the label, the final ORs with the accumulator 'a' and returns 'z' (zero flag) and finally decrements the accumulator 'a' before the first "ex af, af'" instruction. The prototype just decrements the accumulator and returns 'm' before the first "ex af, af'" instruction.
6.) At 0x60F, the instruction subtracts $2A in the final and $29 in the prototype from the accumulator, related to sound effects.
7.) At 0x814(final)/0x813(proto), "PauseAudio" doesn't return in the prototype but does in the final. The Final calls sub_E58 after calling "PSGSilenceAll", which does something. The prototype makes no such call after "PSGSilenceAll". The equivalent subroutine to sub_E58 is sub_E53 in the prototype.
8.) Under "ProcessSndQueue", the final does this:

RAM:0885                 jp      m, ShiftSoundQueue ; Jump (conditional & unconditional)
RAM:0888                 sub     2Ah ; '*'       ; Subtract from A
RAM:088A                 jr      c, ShiftSoundQueue ; Jump relative (conditional & unconditional)



While the prototype does this:

ROM:0880                 sub     28h ; '('       ; Subtract from A
ROM:0882                 jp      c, ShiftSoundQueue ; Jump (conditional & unconditional)
ROM:0885                 sub     1               ; Subtract from A



That's pretty much all there is as far as code changes go. I didn't look through the data that comes after all this though.

#182 User is offline ValleyBell 

Posted 22 May 2014 - 04:09 AM

  • Posts: 204
  • Joined: 08-September 10
  • Gender:Male
  • Project:researching SMPS sound drivers
  • Wiki edits:10
I relabelled the Chaotix disassembly a while ago so that it uses the same labels and names as all the other disassemblies I did. You can download the "new" disassembly here.
It also includes a Chaotix 1207 with the new labels, a Sonic Crackers disassembly and a disassembly of the Chaotix PWM driver. The offsets of this one are wrong though, I'm working on redoing that one.

So let's list the changes:
1. Beta:
VInt:
		di
		call	DoSoundQueue
		call	UpdateAll
		ret

Final:
VInt:
		di
		call	loc_3C
loc_3C:					; DATA XREF: RAM:loc_40w
		ld	a, 0
		add	a, 80h
loc_40:
		ld	(loc_3C+1), a
		jr	nc, locret_4B
		call	DoSoundQueue
		call	UpdateAll
locret_4B:				; CODE XREF: RAM:0043j
		ret

I haven't check this in the PAL version yet, but I assume the added code is responsible for the PAL tempo fix.

2. I have nothing to add here.

3. The dead code exists in almost all SMPS Z80 drivers. That includes the Chatoix beta. The Z80 instruction " ex af, af' " has the code byte 08. (In IDA, click on the "db 8" and press 'C' to turn it into code.)

4. Beta:
PlaySoundID:				; CODE XREF: UpdateAll+9p
		ld	a, (byte_1C09)	; read Sound ID
		cp	29h
		jp	c, PlayMusic	; 00-28	- Music
		cp	69h
		jp	c, PlaySFX	; 29-68	- SFX

Final:
PlaySoundID:				; CODE XREF: UpdateAll+9p
		ld	a, (byte_1C09)	; read Sound ID
		cp	2Ah
		jp	c, PlayMusic	; 00-29	- Music
		cp	6Fh
		jp	c, PlaySFX	; 2A-6E	- SFX

I think the comments make it obvious what they changed - they added 1 song and 5 SFX.

5. Beta:
PlayMusic:				; CODE XREF: PlaySoundID+5j
		dec	a
		ret	m

Final:
PlayMusic:				; CODE XREF: PlaySoundID+5j
		or	a
		ret	z
		dec	a

The code does exactly the same in both versions. I have no idea why they changed it. It makes sure that Sound ID 00 does nothing. (The Beta code would also do nothing for 81-FF, but PlayMusic is never called for these IDs.)

6. Beta:
PlaySFX:				; CODE XREF: PlaySoundID+Aj
	...
		ex	af, af'
		sub	29h		; Sound	ID -> SFX Index
		ex	af, af'

Final:
PlaySFX:				; CODE XREF: PlaySoundID+Aj
	...
		ex	af, af'
		sub	2Ah		; Sound	ID -> SFX Index
		ex	af, af'


7. Beta:
SilenceAll:				; CODE XREF: DoPause+Ej
		call	PSGSilenceAll
		push	bc

Final:
SilenceAll:				; CODE XREF: DoPause+Ej
		call	PSGSilenceAll
		call	SendPSGState
		push	bc

In the beta, the PSGSilenceAll has no effect, because all PSG commands are stored in a buffer. The added instruction in the final makes sure that the PSG commands are sent to the chip and all PSG notes are stopped.
The added "ret" instruction at the end of the DoPause routine is a small optimization. In the beta it just falls through to the next code and executes PSGSilenceAll again.

8. Beta:
DoSoundQueue:				; CODE XREF: RAM:0039p
	...
		sub	28h
		jp	c, DequeueSound
		sub	1	; Here it effectively did "sub 29h

Final:
DoSoundQueue:				; CODE XREF: RAM:0039p
	...
		jp	m, DequeueSound	; jump if 80-FF
		sub	2Ah
		jr	c, DequeueSound

In the final, it makes sure that sound commands (FadeOutMusic, StopAllSound, etc., they have the IDs E0-FF) are ignored by the sound priority system. The beta only ignores songs.

The data for modulation envelopes and PSG instruments is the same.

btw: Most of the information in the wiki about changed songs between the 1207 beta and the final version of Chaotix is wrong. There are 3 songs with major differences. I'll just quote my .txt file:
- The intro of "Oriental Legend" is a lot longer than in the final.
- "Decision" is split into 2 parts in the final. In this beta it just loops once and finishes then.
- In the final, "This Horizon" has an additional intro that is missing here.
- All other songs either match exactly or have a slightly higher PSG 3 volume.


The actual issue with the sound is caused by the PWM driver. So far I was able to port the beta PWM driver to Chaotix final (after fixing some offsets). Considering how it sounds I assume that it is unable to play "silence" correctly.


The Chaotix sound driver is pretty much the same as the one in Sonic Crackers, just without the DAC channel and with 4 additional PWM channels.
This post has been edited by ValleyBell: 22 May 2014 - 04:44 AM

  • 13 Pages +
  • ◄ First
  • 11
  • 12
  • 13
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users