Jump to content
IGNORED

POKEY 16-bit mode and other AUDCTL settings - A7800 emulation


Recommended Posts

Sounds great ... :)

 

Further documentation is needed for this setting, but I seem to have the frequencies sorted out in a manner that makes sense.

 

Next step:  sort out the $4x Reverse 16-bit setting @1.79 mhz.  I have gotten thru 75% of the 65,536 settings now, then they need to be unscrambled and tuned.   :)

 

 

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

I went back to the $4x bass @1.79 mhz for this example ... the title music from the legendary C64 and Apple II game Prince of Persia

 

Settings:

 

AUDCTL=$70

 

0 - silent

1 - $Cx (1.79 mhz, 16-bit, saw lead sounds)

2 - $4x (1.79 mhz, mod 3 bass)

3 - $Ax (standard square wave, no modulations)

 

Some notes:

 

The 16-bit channel uses two different $Cx timbres.  The first one, uses notes where (freq+1) mod 3 = 0.  These produce a slightly less bright sound, although three different timbres are randomly output, depending on system timers.  Again, the method described by Pavros earlier can stabilize this.

 

In the second half of the tune, the timbre of $Cx switches to notes where (freq+1) mod 3 <>0.  This makes the lead sound very bright, like an oboe.

 

The bass channel uses $4x, clocked at 1.79 mhz.  The bass notes are from my custom table, using (freq+4) mod 3 = 0.  The offset is different from $Cx.  This softens the bass sound a little bit but keeps that middle eastern feel.

 

The $Ax channel outputs a standard square wave, which at times doubles up the bass notes, but also plays the main melody counterpoint at the end of the song.  In the opening, the A2 note in the $4x channel is a bit flat.  This could not be avoided sadly, due to the tuning limitations in this setting, so I flattened the A3 note in the $Ax channel during that section only, to compensate.

 

Emulator notes:

 

Prosystem plays this 100% accurate to real hardware.  A7800 makes a right mess of it all.  The $Cx and $4x channels play the wrong notes and/or timbres. Only the standard $Ax channel is played correctly.

 

Binaries below, plus Altirra .wav ... real hardware tests are always appreciated.  I would love to see Prince of Persia on our beloved 7800. :)

 

 

pop-title-4000.A78 pop-title-4000.asm pop-title-4000.bin pop-title-450.A78 pop-title-450.asm pop-title-450.bin prince of persia - title theme.wav

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

Did some preliminary experiments into the $0x, $2x, and $4x settings, with the reverse-16, two-tone, and hi-pass filters.  All of these produce warbling electric guitars of varying timbres.  So more experimentation is warranted. :)

 

Meanwhile ... my task for today is to finish the $4x 1.79 reverse 16 table ... and also the $4x 1.79 two-tone table as well. 

Link to comment
Share on other sites

I am 98% done on this table.  I still need to retune everything ... a text file is attached below.

 

We are dealing with three tables:

 

Table 1:  (freq+1) mod 3 <>0  and (freq+2) mod 5 <>0

 

Table 2:  (freq+1) mod 3=0  and (freq+2) mod 5 <>0

 

Table 3:  (freq+1) mod 3 <>0  and (freq+2) mod 5=0

 

The base frequencies can be heard when the second channel frequency is set to zero.  In the case of table 3, silence is generated intermittently, depending on polycounter timers.

 

To make silence for a note rest, AUDF0=8 and AUDF1=0 ...  (freq+1) mod 3=0  and (freq+2) mod 5=0

 

The real fun happens with table 4.  The frequencies are laid out as follows:

 

(AUDF0, AUDF1, MOD) ... where the vibrato period runs from AUDF1-MOD to AUDF1+MOD 

 

I haven't determined a pattern for these yet but they undoubtedly come from the first three tables.

 

Next step is to tune these, then do a demo tune. :)

 

 

AUDCTL=$50, AUDC0=$4x by octave number.txt

  • Like 3
Link to comment
Share on other sites

The $4x reverse 16 table has been tuned and finalized ... that only took a month lol.  I am exhausted :)

 

 

Text files are in this thread.  What I have found is, the AUDF1 (second channel frequency) settings for each note correspond to my $2x triangle wave table at 1.79 mhz, although I have not yet been able to determine a pattern to the AUDF0 value.

 

I am going to attempt a demo tune with this one next ... can't wait to give this mode a spin. :)

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Next steps:

 

I have documented $Ax square wave in reverse 16-bit mode @64 KHZ.  This gives you the standard square wave table, plus duty cycle pulse notes starting at A3 and going down to about G1.

 

I am also working through $4x SKCTLS 2-tone mode.  There are at least 5 different note tables to be had here ... plus distorted guitars with a greater octave range.

 

Demos soon.

  • Like 2
Link to comment
Share on other sites

Other discoveries ... 

 

$2x in SKCTLS has not much of use other than noise, although there are some distorted square wave notes scattered throughout which may prove useful.

 

$Cx in SKCTLS produces some really fierce distortions of the standard bass notes.  :)

 

$8x SKCTLS with 9-bit poly also has some distorted guitar possibilities.

 

Will tackle these when finished with $4x SKCTLS

  • Like 3
Link to comment
Share on other sites

So ... 

 

I am going to work up an emulator test program in 7800basic.  The purpose is to step through all of the wave forms and frequencies in 16-bit AUDCTL=$50 mode.  If these can be tested against real HW we hopefully will have a good reference point. 

 

Also planned:  a test for 1.79 mhz AUDCTL=$40 8-bit modes for $2x, $cx,  and $4x.  

Edited by Synthpopalooza
  • Like 1
Link to comment
Share on other sites

I am progressing on the POKEY emulation test tool ... and have been drawn back to another topic:  $Cx bass and polycounters.  Its complicated but I think I have a grasp on it ...

 

In $Cx, there is a poly4 counter that samples bits from the following 15-bit sequence:

 

0 0 0 0 1 1 1 0 1 1 0 0 1 0 1

 

So, you deal with multiples of 3 and 5 here ...

 

For example, a frequency of 3 results in sampling bits every three steps ... this gets you one of the following:

 

1 1 1 0 0 (60% duty cycle)

 

0 1 0 0 0 (20% duty cycle)

 

1 1 0 1 0 (irregular pulse wave)

 

Which one you get depends on the current polycounter setting, that's why the timbre varies.

 

For multiples of 5:  you will get either:

 

0 1 0

 

1 1 1

 

0 0 0

 

When the bits are the same, a constant signal, silence is generated, otherwise it's a 33% duty pulse cycle.

 

For multiples of 15, the same bit is always sampled, which is always silence.

 

For the rest ... a 15-bit pattern is sounded out, which creates a stable but rougher tone.

 

By resetting polycounters before each note, you can in theory control which waves you get.  I have some ideas ... :)

  • Like 3
Link to comment
Share on other sites

So anyway, this is the code lifted from a technical doc, about how to stabilize those sounds:

 

sE10Ch1 = 14 ; it's safer to use selector values increased by 15
sE8Ch1 = 0
sE6Ch1 = 1
sE6Ch3 = 0
; begin setting channel 1 timer with 0
lda #0
sta AUDF1 ; put 0 to AUDF1
lda #$C0
sta AUDC1 ; set channel 1 volume to 0
lda tmpAudCtl
ora #$40 ; clock channel 1 with phi2/1.79MHz
sta AUDCTL
; wait at least 259 phi2 cycles so that timer counts down to 0
jsr wait260Cycles
; restore AUDCTL desired value, i.e. clock channel 1 with div28
lda tmpAudCtl
sta AUDCTL
; wait at least 112 phi2 cycles so that timer counts down to 0
jsr wait112Cycles
; now channel 1 timer is set to 0
; each div28 clock pulse loads channel 1 timer with AUDF1 = 0
; reset POKEY polynomial counters
lda #0
sta SKCTLS
; the period of resetting POKEY (SKCTL = 0) should last for
; at least 17 cycles to clear the longest 17-bit polycounter
; set AUDF1 register with selector value needed to reach desired E6
; poly4 element by channel 1
lda #sE6Ch1 ; 2 cycles
sta AUDF1 ; 4 cycles
nop ; 2 cycles
nop ; 2 cycles
nop ; 2 cycles
; finish resetting
lda #3 ; 2 cycles
sta SKCTLS ; 4 cycles
; wait for first div28 clock pulse to load timer with selector
:12 nop ; 24 cycles
; set AUDF1 register with desired frequency divisor
lda tmpAudF1
sta AUDF1
; setting AUDF1 register with desired frequency divisor must complete
; before next sampling based on selector (next loading a timer)!
; set AUDC1 register with desired volume (restore volume)
lda tmpAudC1
sta AUDC1

I am going to experiment with it, and see what happens.

  • Like 2
Link to comment
Share on other sites

OK, I have finished the first version of my POKEY emulator test tool.

 

Currently, this only covers standard 16-bit modes:

 

$Ax square wave

$Cx with mod 3 frequencies

$Cx without mod 3 frequencies

$2x

$4x with mod 3 frequencies

$4x without mod 3 frequencies

$8x with 9-bit polycounter

 

This does not render accurately in A7800.  Haven't yet figured out how to compile with POKEY @$4000 so I can't test on Prosystem.  In addition, I found another inaccuracy:  $Ax in 16-bit is normally spot on in A7800, but the very top octave (9) doesn't play those high frequencies accurately.

 

Please test this out on real hardware, and tell me if there are any mistakes.

 

Next step will be to add all the 8-bit modes (including those $Cx and $2x using 1.79 mhz, and $Ax using the 15khz bass).  Then down the line, I will go for the reverse 16, SKCTLS, and hi-pass modes as I get them documented.

 

 

pokeytool.bas pokeytool.bas.a78 pokeytool.bas.asm pokeytool.bas.bin

Edited by Synthpopalooza
  • Like 3
Link to comment
Share on other sites

A few tips on the tool:

 

The joystick selects which waveform gets played.  Using the left and right buttons will step the note up or down by a semitone.  The notes should be the same pitch for all waveforms.

 

Not all waveforms have the same range or resolution ... for example, the $4x waveforms will not play above the fifth octave.  In addition, some of the high notes get dropped in these waveforms as the frequency plays higher.  Any notes which are out of range will not get played.

 

$Cx and $4x each have two settings, one of which is for notes divisible by 3.  In addition, $Cx non mod 3 in the 8th octave has been switched to the mod 3 table for the last 6 notes, for purposes of note resolution.

 

$Ax is correct in emulation, except for the 9th octave, so this can be used as a benchmark to compare the other waveforms.

 

Most of these are correct in Prosystem, except that the high notes in $2x are not played, and the 9-bit poly is not done on $8x.  On A7800, $2x is an octave too high, and the rest are totally inaccurate.  Also the 9-bit poly is not done correctly.

  • Like 2
Link to comment
Share on other sites

$Cx mod 3 polycounters again!  :)

 

Made some discoveries ...

 

When using these in standard 8-bit mode, and the poly reset code above, the third channel will always return pattern #2.  The other two patterns will play on the other channels, dependent upon even or odd numbered frequencies.

 

I suspect this works the same in 16-bit mode... but the greater note resolution means we may have 5 total waveforms usable in $Cx ... ?

 

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

Thanks to a little bit of help from my friends here ... I've figured out how to add TIA percussion to my POKEY demos ... TIA plus POKEY is a very good substitute for the Ricoh 2AO3 (NES) or the AY chip (similar to what's in Colecovision).

 

So I will TIA up some of my old demos to test out ... ?  soon.

  • Like 1
Link to comment
Share on other sites

Another experiment ...

 

This one is actually going to hopefully appear in a game (MuddyVision's Danger Zone) and is a cover of the NES tune from Konami's Top Gun.

 

Settings:

 

AUDCTL=$10 (16-bit on 0 and 1, but with the default 64khz clock)

 

00 - $Ax (Pulse wave lead)

01 - Silent

02 - $Ax (standard square wave)

03 - $Cx (mod 3 bass)

 

 

 

There are several ways to emulate the NES pulse wave ... this particular method works for tunes which have a bit of a lower range.  By using the reverse 16-bit setting, you get a range of notes, from about C3 up to A#3, which have about a 25% duty cycle.  These are accessed by setting second channel frequency to 1.  There is also the standard 8-bit square wave table (accessed if you set the frequency on second channel to 0).  A host of lower bass frequencies can also be accessed on settings 2, 3, and 5 for second channel.

 

This is the original tune from NES Top Gun:

 

 

For this to work, I had to transpose the original music from the NES, down two semitones (G minor to F minor), which keeps the tune mostly within the C3 - A#3 range.  There is a C4 note, which I was able to steal from the standard square table without affecting the tune too much, and a lower A#2 note ... I used an A#1 note from setting 2, which also I think is barely noticeable.

 

Because I have to use a standard 64khz clock, bass must be provided using 8-bit $Cx ... I used the gentler mod 3 frequencies here so as to not overload the music.  An additional $Ax square channel provides harmonics.

 

Emulation issues:

 

This is a change ... for once, A7800 plays the tune spot on, while ProSystem has the issues ... the 16-bit channel plays in the wrong frequency and is out of tune.

 

Attached are binaries, plus a real hardware recording kindly provided by Trebor ... I am currently working up a way to add TIA percussion to this, fingers crossed.

 

 

 

 

topgun-dzone-450.A78 topgun-dzone-450.asm topgun-dzone-450.bin topgun-dzone-4000.A78 topgun-dzone-4000.asm topgun-dzone-4000.bin Top_Gun-Danger_Zone_Melody_20200522_RealHW.mp3

  • Like 3
Link to comment
Share on other sites

As I wrote. Add some drum imitation to the basses.

How do you enter the tunes m btw. ?

 

A short gen. 8 played .

Let's say in the drum interval at $08 , and in the hi hat interval at 00 for a start.

That means you have to use 3 bass instruments in RMT for example.

The generator shift will also do some influence on the  resulting bass.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...