Jump to content
IGNORED

Sound effects on Atari 8-bit machines


H4plo

Recommended Posts

Hi all,

 

I am porting my game Tenebra (https://h4plo.itch.io/tenebra) to Atari 8-bit. I'm trying to add sound effects, but for the life of me I can't get any sound generated, no matter what I do.

I have verified that sounds works in the emulator (Altirra) by playing a couple of games.

 

I think I must be missing some initialisation steps, because even this code doesn't give me any sound: https://www.chibiakumas.com/6502/platform3.php#LessonP23

 

Can anyone give me an assembly listing that generates a short beep (any channels, any frequency, noise/square wave)? I just need a starting point that works, because I must be misunderstanding something. Thanks in advance!

Edited by H4plo
  • Like 2
Link to comment
Share on other sites

No sound occurring can often be that Pokey isn't properly initialized.

Sound initialization - store 00 in D200 thru D208, store 03 in D20F.

 

The simplest sound, a pure tone.  Store E0 in D200 (freq), store A8 in D201 (control/volume) - store 00 in D201 to stop.

For a full Pokey Init, store 00 in D200 through D20F.  Then 03 in D20F and C0 in D20E (to enable key/Break IRQs)

Link to comment
Share on other sites

You should get simple tones in the A8 by writing to audio channel 1 at $D200 and $D201 (AUDF1 and AUDC1). 

 

Just try:

  lda #$80     ; Frequency
  sta $D200    ; AUDF1
  lda #$A0+$08  ; Distortion+Volume
  sta $D201    ; AUDC1

 

Use even numbers only for distortion.

 

Initialize as Rybags said.

 

 

 

Edited by vitoco
Link to comment
Share on other sites

Simple assembler program, I used in a disk copy program, just wrapped it in a loop with a small delay

 

    org $2000
z    sound
    ldy #0
    ldx #20
loop dey
    bne loop
    dex
    bne loop
    jmp z


SOUND    .proc
         LDA #0
         STA SOUTEMP
         LDA #$69
         STA $D201
SO       LDA SOUTEMP
         STA $D200
         INC SOUTEMP
         BEQ SOUOUT
         LDX #0
SO1      DEX 
         BNE SO1
         BEQ SO
SOUOUT   LDA #0
         STA $D201
         RTS 
SOUTEMP    .byte 0
         .endp

Link to comment
Share on other sites

Thank you all! After initialising Pokey as Rybags suggested, all my various attempts at making a noise started working. The thing is that all the code and references I had found on the net assumed that the ROM or Basic had performed the necessary initialisations, so they didn't mention anything about it. I am running Altirra with "NoKernel" ROM and with the interrupts disabled.

 

Now the next challenge is figuring out the keyboard scanning with no ROM and no interrupts.

 

Thanks again!

Link to comment
Share on other sites

18 hours ago, H4plo said:

Thank you all! After initialising Pokey as Rybags suggested, all my various attempts at making a noise started working. The thing is that all the code and references I had found on the net assumed that the ROM or Basic had performed the necessary initialisations, so they didn't mention anything about it. I am running Altirra with "NoKernel" ROM and with the interrupts disabled.

 

Now the next challenge is figuring out the keyboard scanning with no ROM and no interrupts.

That's an odd configuration to be testing against. The NoKernel ROM in Altirra is an OS ROM that literally prints a message saying that you have no OS ROM and then halts, so you know what happened. Practically the only way you can get it these days is to delete an OS ROM image that's still registered, and it doesn't boot any disks or carts so it's not meant to run any software.

Link to comment
Share on other sites

Keyscan is automatic by Pokey if it's enabled (which it normally is)

 

To get it going the OS generally fills D200-D20F with 00.   Then set SKCTL to 03 and IRQEN to C0.

Note it's not needed to have the keyboard IRQ active for keyscan to work.

Although keyscan is automatic there's still some complexity in processing it, mainly due to debounce and auto-repeat.

But if you're just doing a game or something that can do without repeat you can process the keys yourself.

There's bits in SKSTAT that reflect key down condition which you could test during VBlank.

When a key is registered you generally compare it to the previous keypress and ignore it if it's the same code within 3 frames which handles the debounce.

 

But as phaeron says, you're generally better off using an OS.   A cartridge image can be a handy way to do a program that gets control early, but autoboot Xex in most emulators will load a binary file without needing a Dos or menu loaded first.

Link to comment
Share on other sites

7 hours ago, phaeron said:

That's an odd configuration to be testing against. The NoKernel ROM in Altirra is an OS ROM that literally prints a message saying that you have no OS ROM and then halts, so you know what happened. Practically the only way you can get it these days is to delete an OS ROM image that's still registered, and it doesn't boot any disks or carts so it's not meant to run any software.

 

Thanks. I just wanted to make sure my code didn't depend on any ROM initialisation or services, or interrupts. Also, I am new to the Atari 8-bit scene and thought there might be people who have their emulators set up in the NoKernel mode and play the games by using the XEX autoboot feature, therefore I wanted to be certain that I was initialising everything properly.

I have also tested my game with various ROMs and configurations to make sure nothing was amiss.

 

2 hours ago, Rybags said:

Keyscan is automatic by Pokey if it's enabled (which it normally is)

 

To get it going the OS generally fills D200-D20F with 00.   Then set SKCTL to 03 and IRQEN to C0.

Note it's not needed to have the keyboard IRQ active for keyscan to work.

Although keyscan is automatic there's still some complexity in processing it, mainly due to debounce and auto-repeat.

But if you're just doing a game or something that can do without repeat you can process the keys yourself.

There's bits in SKSTAT that reflect key down condition which you could test during VBlank.

When a key is registered you generally compare it to the previous keypress and ignore it if it's the same code within 3 frames which handles the debounce.

 

But as phaeron says, you're generally better off using an OS.   A cartridge image can be a handy way to do a program that gets control early, but autoboot Xex in most emulators will load a binary file without needing a Dos or menu loaded first.

 

Yes, I only needed to detect a couple of simple keypresses. I managed it by inspecting $DF09.

 

Thanks again everyone for your help.

Edited by H4plo
  • Like 1
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...