randyrossi / bmc64

A bare metal Commodore 64 emulator for the Raspberry Pi with true 50hz/60hz smooth scrolling, low input latency and better audio/video sync.
GNU General Public License v3.0
473 stars 56 forks source link

pi0 no audio on gpio with custom build #179

Open benmcevoy opened 3 years ago

benmcevoy commented 3 years ago

hi, struggling to try and get audio from the gpio12/13 i have set define USE_PWM_AUDIO_ON_ZERO in sysconfig.h and built (on the 3.6 branch) but not having any luck. does anyone know if this works at all? has anyone had any success? i've tried setting audio_out=analog in the machines.txt, no joy any advice would be fantastic! thanks

CemTezcan commented 3 years ago

Also related #132

randyrossi commented 3 years ago

Try commenting out the call to SetupGPIO in ViceScreenApp::Initialize to see if the init is interfering with circle's init of those pins? I think the code assumes it's going to use those pins for itself.

benmcevoy commented 3 years ago

Thanks, still no luck. I have tried with a couple of different pi0's, different cables etc. sound is working on HDMI with BMC64, sound is working on gpio12/13 with Combian. I have also tried with SetupGPIO commented out. I tried the circle samples directly, which "run" OK, but no sound on GPIO, but I am probably doing something wrong there... it's been over 20 years since I last used C :) I'll keep trying with the circle samples, to see if I can rule that out. EDIT - sample 12-pwmsound works fine using https://github.com/rsta2/circle/tree/master/sample/12-pwmsound Currently can't get that to build using the version of circle in BMC64, I'll keep pecking away at it.

I'm NOT saying it doesn't work, it's more likely I am making some mistakes. If anyone can get it to work I'd love to hear about it, as I prefer BMC64 over Combian any day :)

I'll switch to Combian for now so my little project can end, and keep playing with circle and see what happens.

Thanks again. Feel free to close this issue.

benmcevoy commented 3 years ago

I found a couple of things that might be causing the issues I am having:

I do not know if this is relevant: - enable_gpio_outputs might be prevent output on the GPIO? I forced it high. https://github.com/randyrossi/bmc64/blob/master/viceoptions.cpp#L97

Looking at the circle sample - they use CPWMSoundBaseDevice, whereas BMC uses ViceSoundBaseDevice https://github.com/randyrossi/bmc64/blob/master/vicesoundbasedevice.h#L50

I tried having ViceSoundBaseDevice inherit from CPWMSoundBaseDevice, and managed to get that to build. C64 starts up but when the sound starts it freezes. I am totally hacking this up, so I am not surprised. I tried passing the interrupt that the existing device used, but I am not very sure what I am doing.

I do feel that CPWMSoundBaseDevice is probably the issue, but perhaps wiser minds could advise?

Cheers!

benmcevoy commented 1 year ago

I had some free time and had another look at this. I can derive from CPWMSoundBaseDevice and even get some sound out of it (buzzing as it crashes :). However after a couple of calls to GetChunk it crashes:

Drive 8: RESET. 00:00:05.92 BM: CKernel::circle_boot_complete calling ViceSound::Initialize 00:00:05.92 BM: ViceSound::GetChunk 1024 00:00:05.93 BM: ViceSound::GetChunk 1024 00:00:05.93 BM: CKernel::circle_boot_complete after ViceSound::Initialize 00:00:05.94 pwmsoundbasedevice.cpp(415): stack[11] is 0x23C2E8 00:00:05.94 pwmsoundbasedevice.cpp(415): stack[12] is 0x23C32C 00:00:05.94 pwmsoundbasedevice.cpp(415): stack[15] is 0x2413E0 00:00:05.94 pwmsoundbasedevice.cpp(415): stack[19] is 0x2414A4 00:00:05.94 pwmsoundbasedevice.cpp(415): stack[29] is 0x2414EC 00:00:05.94 pwmsoundbasedevice.cpp(415): stack[31] is 0x2408EC 00:00:05.94 pwmsoundbasedevice.cpp(415): assertion failed: nIntStatus & nIntMask

I believe (but not really sure) that the PWM IRQ is being clobbered by vchiq I cannot remove vchiq as it is used by the graphics system framebuffer.

If I remove the vchiqdevice from viceapp and vicesound the system crashes immediately as it constructs viceapp/kernel

logger: Circle 40 started on Raspberry Pi Zero except: stack[5] is 0x223278 except: stack[7] is 0x2272CC except: stack[9] is 0x2225A0 except: stack[11] is 0x1F7C04 except: stack[23] is 0x22D6C4 except: stack[27] is 0x237DF4 except: stack[29] is 0x238E3C except: stack[31] is 0x233D60 except: stack[33] is 0x23055C except: stack[47] is 0x2303E4 except: stack[51] is 0xD38C except: stack[57] is 0xBDB4 except: stack[63] is 0xC034 except: Data abort (PC 0x22733C, FSR 0x5, FAR 0xEA08DA28, SP 0x2022C00, LR 0x227338, PSR 0xA00F011F)

After all this I am giving up on this as too hard (for me) :(

I am not sure it is worth the effort either, as you lose or mess up GPIO support and hardware accelerated graphics.

I am thinking it is much easier to just buy an HDMI audio extractor :)

It was a fun problem.

there is a slightly related issue in the circle repo that suggest some combinations of devices/features may not work. but this is from 2015 so may not be relevant anymore.

https://github.com/rsta2/circle/issues/5

Anyway, love your work! keep it up.