Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apu: Add VP debug output #28

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ set -x # Print commands from now on
--target-list=i386-softmmu \
--enable-sdl \
--with-sdlabi=2.0 \
--audio-drv-list=alsa \
--disable-curl \
--disable-vnc \
--disable-docs \
Expand Down
76 changes: 49 additions & 27 deletions hw/xbox/mcpx_apu.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* QEMU MCPX Audio Processing Unit implementation
* QEMU MCPX APU implementation
*
* Copyright (c) 2012 espes
* Copyright (c) 2018-2019 Jannik Vogel
Expand Down Expand Up @@ -29,6 +29,12 @@
#define NUM_SAMPLES_PER_FRAME 32
JayFoxRox marked this conversation as resolved.
Show resolved Hide resolved
#define NUM_MIXBINS 32

#include "mcpx_apu_debug.h"

#if PLAYBACK_VP_BINS_MASK > 0
# include "audio/audio.h"
#endif

#include "hw/xbox/mcpx_apu.h"

#define NV_PAPU_ISTS 0x00001000
Expand Down Expand Up @@ -181,16 +187,6 @@ static const struct {
(v) |= ((val) << ctz32(mask)) & (mask); \
} while (0)

// #define MCPX_DEBUG
#ifdef MCPX_DEBUG
# define MCPX_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
#else
# define MCPX_DPRINTF(format, ...) do { } while (0)
#endif

/* More debug functionality */
#define GENERATE_MIXBIN_BEEP 0

typedef struct MCPXAPUState {
PCIDevice dev;

Expand Down Expand Up @@ -225,11 +221,28 @@ typedef struct MCPXAPUState {

uint32_t regs[0x20000];

/* Debug features */

#if PLAYBACK_VP_BINS_MASK > 0
QEMUSoundCard card;
#endif

#if PLAYBACK_VP_BINS_MASK > 0
SWVoiceOut *vp_bins_out;
#endif
#if DUMP_VP_BINS_MASK > 0
FILE *vp_bin_files[NUM_MIXBINS];
#endif

} MCPXAPUState;

#define MCPX_APU_DEVICE(obj) \
OBJECT_CHECK(MCPXAPUState, (obj), "mcpx-apu")

//FIXME: This is a hack, we already include the header above
// This file should be linked through Makefile.objs
#include "mcpx_apu_debug.c"

static uint32_t voice_get_mask(MCPXAPUState *d,
unsigned int voice_handle,
hwaddr offset,
Expand Down Expand Up @@ -262,11 +275,11 @@ static void update_irq(MCPXAPUState *d)
& d->regs[NV_PAPU_IEN])) {

d->regs[NV_PAPU_ISTS] |= NV_PAPU_ISTS_GINTSTS;
MCPX_DPRINTF("mcpx irq raise\n");
MCPX_APU_DPRINTF("mcpx irq raise\n");
JayFoxRox marked this conversation as resolved.
Show resolved Hide resolved
pci_irq_assert(&d->dev);
} else {
d->regs[NV_PAPU_ISTS] &= ~NV_PAPU_ISTS_GINTSTS;
MCPX_DPRINTF("mcpx irq lower\n");
MCPX_APU_DPRINTF("mcpx irq lower\n");
pci_irq_deassert(&d->dev);
}
}
Expand All @@ -288,7 +301,7 @@ static uint64_t mcpx_apu_read(void *opaque,
break;
}

MCPX_DPRINTF("mcpx apu: read [0x%llx] -> 0x%llx\n", addr, r);
MCPX_APU_DPRINTF("mcpx apu: read [0x%llx] -> 0x%llx\n", addr, r);
return r;
}

Expand All @@ -297,7 +310,7 @@ static void mcpx_apu_write(void *opaque, hwaddr addr,
{
MCPXAPUState *d = opaque;

MCPX_DPRINTF("mcpx apu: [0x%llx] = 0x%llx\n", addr, val);
MCPX_APU_DPRINTF("mcpx apu: [0x%llx] = 0x%llx\n", addr, val);

switch (addr) {
case NV_PAPU_ISTS:
Expand Down Expand Up @@ -338,7 +351,7 @@ static const MemoryRegionOps mcpx_apu_mmio_ops = {
static void fe_method(MCPXAPUState *d,
uint32_t method, uint32_t argument)
{
MCPX_DPRINTF("mcpx fe_method 0x%x 0x%x\n", method, argument);
MCPX_APU_DPRINTF("mcpx fe_method 0x%x 0x%x\n", method, argument);

//assert((d->regs[NV_PAPU_FECTL] & NV_PAPU_FECTL_FEMETHMODE) == 0);

Expand Down Expand Up @@ -422,7 +435,7 @@ static void fe_method(MCPXAPUState *d,
static uint64_t vp_read(void *opaque,
hwaddr addr, unsigned int size)
{
MCPX_DPRINTF("mcpx apu VP: read [0x%llx]\n", addr);
MCPX_APU_DPRINTF("mcpx apu VP: read [0x%llx]\n", addr);
switch (addr) {
case NV1BA0_PIO_FREE:
/* we don't simulate the queue for now,
Expand All @@ -439,7 +452,7 @@ static void vp_write(void *opaque, hwaddr addr,
{
MCPXAPUState *d = opaque;

MCPX_DPRINTF("mcpx apu VP: [0x%llx] = 0x%llx\n", addr, val);
MCPX_APU_DPRINTF("mcpx apu VP: [0x%llx] = 0x%llx\n", addr, val);

switch (addr) {
case NV1BA0_PIO_SET_ANTECEDENT_VOICE:
Expand Down Expand Up @@ -540,7 +553,7 @@ static uint32_t circular_scatter_gather_rw(MCPXAPUState *d,
bytes_to_copy = len;
}

MCPX_DPRINTF("circular scatter gather %s in range 0x%x - 0x%x at 0x%x of length 0x%x / 0x%lx bytes\n",
MCPX_APU_DPRINTF("circular scatter gather %s in range 0x%x - 0x%x at 0x%x of length 0x%x / 0x%lx bytes\n",
dir ? "write" : "read", base, end, cur, bytes_to_copy, len);

assert((cur >= base) && ((cur + bytes_to_copy) <= end));
Expand Down Expand Up @@ -685,7 +698,7 @@ static uint64_t gp_read(void *opaque,
r = d->gp.regs[addr];
break;
}
MCPX_DPRINTF("mcpx apu GP: read [0x%llx] -> 0x%llx\n", addr, r);
MCPX_APU_DPRINTF("mcpx apu GP: read [0x%llx] -> 0x%llx\n", addr, r);
return r;
}

Expand All @@ -697,7 +710,7 @@ static void gp_write(void *opaque, hwaddr addr,
assert(size == 4);
assert(addr % 4 == 0);

MCPX_DPRINTF("mcpx apu GP: [0x%llx] = 0x%llx\n", addr, val);
MCPX_APU_DPRINTF("mcpx apu GP: [0x%llx] = 0x%llx\n", addr, val);

switch (addr) {
case NV_PAPU_GPXMEM ... NV_PAPU_GPXMEM + 0x1000 * 4 - 1: {
Expand Down Expand Up @@ -766,7 +779,7 @@ static uint64_t ep_read(void *opaque,
r = d->ep.regs[addr];
break;
}
MCPX_DPRINTF("mcpx apu EP: read [0x%llx] -> 0x%llx\n", addr, r);
MCPX_APU_DPRINTF("mcpx apu EP: read [0x%llx] -> 0x%llx\n", addr, r);
return r;
}

Expand All @@ -778,7 +791,7 @@ static void ep_write(void *opaque, hwaddr addr,
assert(size == 4);
assert(addr % 4 == 0);

MCPX_DPRINTF("mcpx apu EP: [0x%llx] = 0x%llx\n", addr, val);
MCPX_APU_DPRINTF("mcpx apu EP: [0x%llx] = 0x%llx\n", addr, val);

switch (addr) {
case NV_PAPU_EPXMEM ... NV_PAPU_EPXMEM + 0xC00 * 4 - 1: {
Expand Down Expand Up @@ -827,7 +840,7 @@ static void se_frame(void *opaque)
int sample;

timer_mod(d->se.frame_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 10);
MCPX_DPRINTF("mcpx frame ping\n");
MCPX_APU_DPRINTF("mcpx frame ping\n");

/* Buffer for all mixbins for this frame */
int32_t mixbins[NUM_MIXBINS][NUM_SAMPLES_PER_FRAME] = { 0 };
Expand All @@ -841,20 +854,20 @@ static void se_frame(void *opaque)
next = voice_list_regs[list].next;

d->regs[current] = d->regs[top];
MCPX_DPRINTF("list %d current voice %d\n", list, d->regs[current]);
MCPX_APU_DPRINTF("list %d current voice %d\n", list, d->regs[current]);
while (d->regs[current] != 0xFFFF) {
d->regs[next] = voice_get_mask(d, d->regs[current],
NV_PAVS_VOICE_TAR_PITCH_LINK,
NV_PAVS_VOICE_TAR_PITCH_LINK_NEXT_VOICE_HANDLE);
if (!voice_get_mask(d, d->regs[current],
NV_PAVS_VOICE_PAR_STATE,
NV_PAVS_VOICE_PAR_STATE_ACTIVE_VOICE)) {
MCPX_DPRINTF("voice %d not active...!\n", d->regs[current]);
MCPX_APU_DPRINTF("voice %d not active...!\n", d->regs[current]);
fe_method(d, SE2FE_IDLE_VOICE, d->regs[current]);
} else {
process_voice(d, mixbins, d->regs[current]);
}
MCPX_DPRINTF("next voice %d\n", d->regs[next]);
MCPX_APU_DPRINTF("next voice %d\n", d->regs[next]);
d->regs[current] = d->regs[next];
}
}
Expand All @@ -874,6 +887,10 @@ static void se_frame(void *opaque)
}
#endif

#if (PLAYBACK_VP_BINS_MASK > 0) || (DUMP_VP_BINS_MASK > 0)
debug_vp_bins(d, mixbins);
#endif

/* Write VP results to the GP DSP MIXBUF */
for (mixbin = 0; mixbin < NUM_MIXBINS; mixbin++) {
for (sample = 0; sample < NUM_SAMPLES_PER_FRAME; sample++) {
Expand Down Expand Up @@ -927,6 +944,11 @@ static void mcpx_apu_realize(PCIDevice *dev, Error **errp)
d->se.frame_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, se_frame, d);
d->gp.dsp = dsp_init(d, gp_scratch_rw, gp_fifo_rw);
d->ep.dsp = dsp_init(d, ep_scratch_rw, ep_fifo_rw);

#if (PLAYBACK_VP_BINS_MASK > 0) || (DUMP_VP_BINS_MASK > 0)
/* Set up debuging */
initialize_audio_debugger(d);
#endif
}

static void mcpx_apu_class_init(ObjectClass *klass, void *data)
Expand Down
2 changes: 1 addition & 1 deletion hw/xbox/mcpx_apu.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* QEMU Geforce NV2A implementation
* QEMU MCPX APU implementation
*
* Copyright (c) 2018 Jannik Vogel
*
Expand Down
104 changes: 104 additions & 0 deletions hw/xbox/mcpx_apu_debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* QEMU MCPX APU debug helpers
*
* Copyright (c) 2019 Jannik Vogel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#include "mcpx_apu_debug.h"

#include <stddef.h>
#include <stdio.h>
#include "qemu/osdep.h"

#if PLAYBACK_VP_BINS_MASK > 0
# include "audio/audio.h"
#endif

#if PLAYBACK_VP_BINS_MASK > 0
static void vp_bins_out_callback(void *opaque, int free)
{
printf("VP bins host buffer ran out, %d free bytes\n", free);
}
#endif

#if (PLAYBACK_VP_BINS_MASK > 0) || (DUMP_VP_BINS_MASK > 0)
void debug_vp_bins(MCPXAPUState *d,
int32_t mixbin[NUM_MIXBINS][NUM_SAMPLES_PER_FRAME])
{

#if DUMP_VP_BINS_MASK > 0
MCPX_APU_DPRINTF("mcpx frame ping\n");
for (int i = 0; i < NUM_MIXBINS; i++) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C99 not allowed

if (d->vp_bin_files[i] == NULL) {
continue;
}
fwrite(&mixbin[i][0], 1, sizeof(mixbin[i]), d->vp_bin_files[i]);
}
#endif

#if PLAYBACK_VP_BINS_MASK > 0
/* Output will be S32 mono; mix this now */
int32_t mixed[NUM_SAMPLES_PER_FRAME] = { 0 };
for (int i = 0; i < NUM_MIXBINS; i++) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C99 not allowed

if (PLAYBACK_VP_BINS_MASK & (1 << i)) {
for (int j = 0; j < NUM_SAMPLES_PER_FRAME; j++) {
mixed[j] += mixbin[i][j] << 8;
}
}
}

/* Write frame to audio output */
int n = AUD_write(d->vp_bins_out, mixed, sizeof(mixed));
if (n < sizeof(mixed)) {
printf("VP bins host buffer overrun\n");
}
#endif

}
#endif

#if (PLAYBACK_VP_BINS_MASK > 0) || (DUMP_VP_BINS_MASK > 0)
void initialize_audio_debugger(MCPXAPUState *d)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style is <object>_<verb>; also init?

{

#if PLAYBACK_VP_BINS_MASK > 0
AUD_register_card("MCPX APU", &d->card);
#endif

#if DUMP_VP_BINS_MASK > 0
for (unsigned int i = 0; i < NUM_MIXBINS; i++) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C99 not allowed

if (DUMP_VP_BINS_MASK & (1 << i)) {
char path[32];
sprintf(path, "vp-bin-%d.bin", i);
d->vp_bin_files[i] = fopen(path, "wb");
} else {
d->vp_bin_files[i] = NULL;
}
}
#endif

#if PLAYBACK_VP_BINS_MASK > 0
struct audsettings vp_bins_as = { 48000, 1, AUD_FMT_S32, 0 };
d->vp_bins_out = AUD_open_out(&d->card,
d->vp_bins_out,
"mcpx-apu.vp_bins", d,
vp_bins_out_callback,
&vp_bins_as);
// AUD_set_active_out(d->vp_bins_out, 1); //FIXME: Why does this hang GTK UI?
#endif

}
#endif
38 changes: 38 additions & 0 deletions hw/xbox/mcpx_apu_debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* QEMU MCPX APU debug helpers
*
* Copyright (c) 2012 espes
* Copyright (c) 2019 Jannik Vogel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#ifndef HW_MCPX_APU_DEBUG_H
#define HW_MCPX_APU_DEBUG_H

// #define DEBUG_MCPX_APU
#ifdef DEBUG_MCPX_APU
# define MCPX_APU_DPRINTF(format, ...) printf("mcpx-apu: " format, ## __VA_ARGS__)
#else
# define MCPX_APU_DPRINTF(format, ...) do { } while (0)
#endif

/* Generate a tone in the MIXBIN for every channel */
#define GENERATE_MIXBIN_BEEP 0

/* Debug feature to enable VP audio output for debugging */
#define PLAYBACK_VP_BINS_MASK 0x00000001 /* 32-bits, 1 bit per bin */
#define DUMP_VP_BINS_MASK 0x00000001 /* 32-bits, 1 bit per bin */

#endif