Bryan Posted July 6, 2014 Share Posted July 6, 2014 I'd always planned on doing my own Pac-Man adaptation but who knows when I'll get to it. For now, I thought someone might have fun with my Pokey code. This does not work correctly under emulation This is old TASM code so I apologize if the formatting is awkward This uses a 3rd voice for the triangle mode to boost the volume. I don't remember how the trick works, but I used an oscilloscope to figure it out. There is commented out code which I believe was part of 'pop' mitigation attempts. When you play a note in the triangle mode, you introduce DC offset into the output which must be managed when the note is stopped or you'll hear all kinds of clicking in the tune. This is done through: 1. ramping down the volume of channels at the end of the notes or 2. leaving those channels in a state where they produce an ultra-sonic frequency that keeps the output at the DC level until the next note. ....more effects to come.... ;Pac Man tune ;Bryan Edewaard AUDF1 .equ $D200 POT0 .equ $D200 AUDC1 .equ $D201 POT1 .equ $D201 AUDF2 .equ $D202 POT2 .equ $D202 AUDC2 .equ $D203 POT3 .equ $D203 AUDF3 .equ $D204 POT4 .equ $D204 AUDC3 .equ $D205 POT5 .equ $D205 AUDF4 .equ $D206 POT6 .equ $D206 AUDC4 .equ $D207 POT7 .equ $D207 AUDCTL .equ $D208 ALLPOT .equ $D208 STIMER .equ $D209 KBCODE .equ $D209 SKREST .equ $D20A RANDOM .equ $D20A POTGO .equ $D20B SEROUT .equ $D20D SERIN .equ $D20D IRQEN .equ $D20E IRQST .equ $D20E SKCTL .equ $D20F SKSTAT .equ $D20F time .equ $80 note1 .equ $81 period1 .equ $82 decay1 .equ $83 note2a .equ $84 note2b .equ $85 period2 .equ $86 decay2 .equ $87 sndindex1 .equ $88 sndindex2 .equ $89 ;When making a file... .ORG $9FFA ;Make room for binary header ;Set up binary header .db $FF, $FF, $00, $A0, $FF, $AF ;PacMan Music Code start lda #3 sta SKCTL lda #$00 sta AUDCTL lda #$70 sta AUDCTL sta STIMER lda $14 sta time ldy #$00 sty sndindex1 sty sndindex2 jmp playing2 playing lda $14 cmp time beq playing ;cheap VBL test sta time dec period1 bne skipnote playing2 ldy sndindex1 lda intro_ch1,y ;Get new note cmp #$FF bne playcont2 jmp endtune playcont2 sta note1 iny ldx intro_ch1,y ;Get the period lda pertab,x ;From the table sta period1 iny sty sndindex1 lda #15 sta decay1 skipnote ldx decay1 dex bpl decaycont ldx #$00 decaycont stx decay1 txa lsr a ldx note1 bne decaycont2 lda #$00 decaycont2 ora #$C0 sta AUDC4 ;Set the volume for this channel stx AUDF4 ;Lead Voice ldy sndindex2 beq playing2b dec period2 bne skipnote3 playing2b lda intro_ch2,y ;Get new note cmp #$FF beq endtune sta note2a iny lda intro_ch2,y sta note2b iny ldx intro_ch2,y ;Get the period lda pertab,x ;From the table sta period2 iny sty sndindex2 skipdown lda note2a beq silence ; ldx #$10 ; stx AUDCTL sta AUDF1 lda note2b sta AUDF3 lda #0 sta AUDF2 ldx #$AF stx AUDC1 stx AUDC2 stx AUDC3 ; ldx #$70 ; stx COLBK ; stx AUDCTL jmp playing ;back to wait loop (return) jmp skipnote3 nop nop nop nop silence ; lda #$60 ldx #$B6 stx AUDC1 stx AUDC2 stx AUDC3 ; sta AUDCTL ; ldx note2b ; stx AUDF1 ; stx AUDF3 ; ldx #$A2 volup ; stx AUDC1 ; stx AUDC2 ; stx AUDC3 ; inx ; sta WSYNC ; sta WSYNC ; cpx #$B0 ; bcc volup skipnote3 jmp playing ;back to wait loop (return) endtune lda #$00 ; sta AUDC1 ;because of Pokey's DC offset in triangle mode ; sta AUDC2 ;turning off all voices at once ; sta AUDC3 ;results in a POP! sta AUDC4 ;best method would be to turn the voices down gradually jmp endtune pertab .db $01,$02,$04,$08,$10,$20,$40,$80 ;START CHANNEL1 X3 ;Bass line (volume decay) intro_ch1 .db 63, 4, 0, 3, 42, 3, 63, 4, 0, 3, 40, 3, 60, 4, 0, 3 .db 40, 3, 60, 4, 0, 3, 42, 3, 63, 4, 0, 3, 42, 3, 63, 4 .db 0, 3, 42, 3, 42, 4, 37, 4, 33, 4, 31, 5, 255 intro_ch2 .db 34, 36, 2, 0, 0, 2, 44, 44, 2, 0, 0, 2, 41, 42, 2, 0, 0, 2 .db 45, 46, 2, 0, 0, 2, 44, 44, 2, 41, 42, 2, 0, 0, 3, 45, 46, 3 .db 0, 0, 3 .db 33, 35, 2, 0, 0, 2, 43, 43, 2, 0, 0, 2, 26, 28, 2, 0, 0, 2 .db 44, 45, 2, 0, 0, 2, 43, 43, 2, 26, 28, 2, 0, 0, 3, 44, 45, 3 .db 0, 0, 3 .db 34, 36, 2, 0, 0, 2, 44, 44, 2, 0, 0, 2, 41, 42, 2, 0, 0, 2 .db 45, 46, 2, 0, 0, 2, 44, 44, 2, 41, 42, 2, 0, 0, 3, 45, 46, 3 .db 0, 0, 3 .db 31, 33, 2, 45, 46, 2, 44, 45, 2, 0, 0, 2, 44, 45, 2, 28, 30, 2 .db 41, 42, 2, 0, 0, 2, 41, 42, 2, 26, 28, 2, 25, 27, 2, 0, 0, 2 .db 44, 44, 3, 0, 0, 2, 255, 255 ;File end .ORG $B000 .db $E2, $02, $E3, $02 .WORD (start) .END ; bry_pactune.xex a8pac.mp3 10 Quote Link to comment Share on other sites More sharing options...
Bryan Posted July 6, 2014 Author Share Posted July 6, 2014 BTW, let me know if it's playing correctly from the XEX (compared to the MP3 -which I made a long time ago). I extracted the code from my big messy Pac-project and don't have an A8 set up at the moment to test it. The next bit of code will be the death sound. Here's a comparison of the original and the Pokey version. pacdie.mp3 5 Quote Link to comment Share on other sites More sharing options...
tschak909 Posted July 6, 2014 Share Posted July 6, 2014 Holy shit! That's PERFECT! -Thom Quote Link to comment Share on other sites More sharing options...
pixelmischief Posted July 6, 2014 Share Posted July 6, 2014 It's sick how the simplest things can trigger the deepest and most complex memories and emotions. This definitely brings back some wonderful feelings. Thanks. 2 Quote Link to comment Share on other sites More sharing options...
pixelmischief Posted July 6, 2014 Share Posted July 6, 2014 Btw, the first of the two versions in PACDIE.MP3 is the vastly superior, IMHO. Quote Link to comment Share on other sites More sharing options...
Bryan Posted July 6, 2014 Author Share Posted July 6, 2014 Btw, the first of the two versions in PACDIE.MP3 is the vastly superior, IMHO. That's the arcade version (so it should be!). The 2nd one is as close as I got with Pokey. That doesn't mean it can't be improved. I created these using a sample loop on a PC and an A8 both connected to an oscilloscope. I tried to find waveforms on the A8 which approximated the arcade sounds. I also made careful note of the pitch changes in the arcade sounds to match the progression of the effects. Eventually, I'd built sounds which had the same timing and pitch and a similar timbre. It's really interesting what you can do with Pokey if you work with a scope and feed it as many nonsensical settings as you can. Eventually you find something that sounds cool that perhaps no one has ever done. The triangle effect is more complex than I originally thought and it can be tweaked beyond simply beating two HF voices off each other. Quote Link to comment Share on other sites More sharing options...
tep392 Posted July 6, 2014 Share Posted July 6, 2014 Awsome! You found the code. I'd like to try this out on my 7800 pokey dev cart. 1 Quote Link to comment Share on other sites More sharing options...
Bryan Posted July 6, 2014 Author Share Posted July 6, 2014 Awsome! You found the code. I'd like to try this out on my 7800 pokey dev cart. Yep, I decided to post it here since I thought I'd lost it forever anyway. Quote Link to comment Share on other sites More sharing options...
bfollett Posted July 6, 2014 Share Posted July 6, 2014 (edited) I just tried bry_pactune.xex in Altirra set up as both NTSC and then Pal. I wanted to see how much slower it sounded with Pal, but I was surprised to find it sounded completed messed up using the Pal configuration. Are others finding the same thing, or do I have some other setting interfering with it under Pal? Bob Edited July 6, 2014 by bfollett Quote Link to comment Share on other sites More sharing options...
atx4us Posted July 9, 2014 Share Posted July 9, 2014 I'd always planned on doing my own Pac-Man adaptation but who knows when I'll get to it. For now, I thought someone might have fun with my Pokey code. This does not work correctly under emulation This is old TASM code so I apologize if the formatting is awkward I thought that emulation has been pretty much perfected on Altirra. Does anyone know why this does not work correctly with Altirra? Quote Link to comment Share on other sites More sharing options...
pixelmischief Posted July 9, 2014 Share Posted July 9, 2014 That's the arcade version (so it should be!). The 2nd one is as close as I got with Pokey. Oh snap! Still, your version is pretty damned close considering... Quote Link to comment Share on other sites More sharing options...
Bryan Posted July 9, 2014 Author Share Posted July 9, 2014 I thought that emulation has been pretty much perfected on Altirra. Does anyone know why this does not work correctly with Altirra? Because emulating every aspect of Pokey is a daunting task. Altirra is very compatible with existing software but some of the more advanced tricks are based on the precise interaction of very high frequency waveforms and are dependent on both the precise digital and analog properties of Pokey. The way to emulate everything is to throw a lot of CPU power behind emulating the whole circuit of Pokey rather than the expected output. Quote Link to comment Share on other sites More sharing options...
Rybags Posted July 9, 2014 Share Posted July 9, 2014 Pretty sure I've said it multiple times before but these effects would be a must-add to any/all of the Pacman hacks going around. Quote Link to comment Share on other sites More sharing options...
Bryan Posted July 11, 2014 Author Share Posted July 11, 2014 Just tried the first program on a real machine and it sounds like it should. Now to get to work on the sound fx. 1 Quote Link to comment Share on other sites More sharing options...
Bryan Posted July 11, 2014 Author Share Posted July 11, 2014 I just tried bry_pactune.xex in Altirra set up as both NTSC and then Pal. I wanted to see how much slower it sounded with Pal, but I was surprised to find it sounded completed messed up using the Pal configuration. Are others finding the same thing, or do I have some other setting interfering with it under Pal? Bob It sounds worse under Altirra in PAL for me too. Has anyone run it on a PAL machine? Quote Link to comment Share on other sites More sharing options...
tep392 Posted July 11, 2014 Share Posted July 11, 2014 I ran the first program on my 7800 POKEY Dev Cart! It sounds fine but the triangle channel is too quite compared to the bass line. It's hard to hear in fact. Is there some way to boost the volume? Or do we just need to reduce the volume of the bass channel? Quote Link to comment Share on other sites More sharing options...
Bryan Posted July 11, 2014 Author Share Posted July 11, 2014 The triangle doesn't swing very far unfortunately. It's actually a wave that swings between the DC average of a square wave and the somewhat different level produced when one voice is high and another low. The trick is to find ways to push those two levels apart. Is the main voice lower on the dev cart than in the MP3? Quote Link to comment Share on other sites More sharing options...
tep392 Posted July 11, 2014 Share Posted July 11, 2014 I haven't listened to the two side by side, but it is noticeably lower. This was the same problem I ran into when I was experimenting with the technique on my 400. Maybe playing around with the volumes of the voices would help. Quote Link to comment Share on other sites More sharing options...
Bryan Posted July 11, 2014 Author Share Posted July 11, 2014 I wonder if it has to do with the way Pokey's output is connected in the 7800 cart. Perhaps the triangle doesn't work as well there. Maybe at some point you can send me a WAV or MP3 of it and I can see what it looks like. Quote Link to comment Share on other sites More sharing options...
tep392 Posted July 12, 2014 Share Posted July 12, 2014 I did a simple test trying different combinations of volumes on audc1,audc2,audc3. Two combinations gave me better volume for the triangle wave. But I need to do another test to make sure it's repeatable. What I did was try 8 combinations of $AF and $A5. These two combinations gave good results. 1) audc1=$A5, audc2=$AF, audc3=$AF 2) audc1=$AF, audc2=$A5, audc3=$AF 1 Quote Link to comment Share on other sites More sharing options...
Bryan Posted July 12, 2014 Author Share Posted July 12, 2014 I did a simple test trying different combinations of volumes on audc1,audc2,audc3. Two combinations gave me better volume for the triangle wave. But I need to do another test to make sure it's repeatable. What I did was try 8 combinations of $AF and $A5. These two combinations gave good results. 1) audc1=$A5, audc2=$AF, audc3=$AF 2) audc1=$AF, audc2=$A5, audc3=$AF Interesting. I'll be leaving for a week but when I get a little time I'll post scope captures of what it gives me. If I remember correctly, C1 and C2 are 1.8MHz & 16-bit joined. Normally, you turn off C1 in 16-bit mode, but I discovered that leaving them both on made for a louder signal (need to re-investigate why). Perhaps it's that I'm not using the 16-bit range and instead I have both channels toggling together. Channel 3 is the other Hi Freq channel needed for the phase effect that makes the triangle. Looks like C4 is 4-bit poly... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.