Skip to content

Commit

Permalink
Merge branch 'xemu-project:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Spidy123222 authored Mar 17, 2024
2 parents 95b2495 + 14def2a commit faa75d5
Show file tree
Hide file tree
Showing 26 changed files with 963 additions and 205 deletions.
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ case "$platform" in # Adjust compilation options based on platform
CYGWIN*|MINGW*|MSYS*)
echo 'Compiling for Windows...'
sys_cflags='-Wno-error'
CFLAGS="${CFLAGS} -lIphlpapi -lCrypt32" # workaround for linking libs on mingw
opts="$opts --disable-fortify-source"
postbuild='package_windows' # set the above function to be called after build
target="qemu-system-i386w.exe"
Expand Down
41 changes: 41 additions & 0 deletions config_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ input:
port2: string
port3: string
port4: string
peripherals:
port1:
peripheral_type_0: integer
peripheral_param_0: string
peripheral_type_1: integer
peripheral_param_1: string
port2:
peripheral_type_0: integer
peripheral_param_0: string
peripheral_type_1: integer
peripheral_param_1: string
port3:
peripheral_type_0: integer
peripheral_param_0: string
peripheral_type_1: integer
peripheral_param_1: string
port4:
peripheral_type_0: integer
peripheral_param_0: string
peripheral_type_1: integer
peripheral_param_1: string
gamecontrollerdb_path: string
auto_bind:
type: bool
Expand Down Expand Up @@ -156,6 +177,26 @@ display:
auto_scale:
type: bool
default: true
debug:
video:
transparency:
type: bool
default: false
x_pos:
type: number
default: 100.0
y_pos:
type: number
default: 100.0
x_winsize:
type: number
default: 600.0
y_winsize:
type: number
default: 150.0
advanced_tree_state:
type: bool
default: false

audio:
use_dsp: bool
Expand Down
1 change: 1 addition & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pfiles = [
'controller_mask.png',
'xmu_mask.png',
'logo_sdf.png',
'xemu_64x64.png',
'abxy.ttf',
Expand Down
Binary file added data/xmu_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 23 additions & 13 deletions hw/xbox/nv2a/pgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "ui/xemu-settings.h"
#include "qemu/fast-hash.h"

const float f16_max = 511.9375f;
const float f24_max = 1.0E30;

static NV2AState *g_nv2a;
GloContext *g_nv2a_context_render;
GloContext *g_nv2a_context_display;
Expand Down Expand Up @@ -2942,6 +2945,10 @@ DEF_METHOD(NV097, SET_BEGIN_END)
glDisable(GL_CULL_FACE);
}

/* Clipping */
glEnable(GL_CLIP_DISTANCE0);
glEnable(GL_CLIP_DISTANCE1);

/* Front-face select */
glFrontFace(pg->regs[NV_PGRAPH_SETUPRASTER]
& NV_PGRAPH_SETUPRASTER_FRONTFACE
Expand Down Expand Up @@ -3493,10 +3500,6 @@ DEF_METHOD(NV097, CLEAR_SURFACE)
GLint gl_clear_stencil;
GLfloat gl_clear_depth;

/* FIXME: Put these in some lookup table */
const float f16_max = 511.9375f;
const float f24_max = 1.0E30;

switch(pg->surface_shape.zeta_format) {
case NV097_SET_SURFACE_FORMAT_ZETA_Z16: {
uint16_t z = clear_zstencil & 0xFFFF;
Expand Down Expand Up @@ -4180,8 +4183,17 @@ static void pgraph_shader_update_constants(PGRAPHState *pg,
*(float*)&pg->regs[NV_PGRAPH_FOGPARAM1]);
}

float zclip_max = *(float*)&pg->regs[NV_PGRAPH_ZCLIPMAX];
float zclip_min = *(float*)&pg->regs[NV_PGRAPH_ZCLIPMIN];
float zmax;
switch (pg->surface_shape.zeta_format) {
case NV097_SET_SURFACE_FORMAT_ZETA_Z16:
zmax = pg->surface_shape.z_format ? f16_max : (float)0xFFFF;
break;
case NV097_SET_SURFACE_FORMAT_ZETA_Z24S8:
zmax = pg->surface_shape.z_format ? f24_max : (float)0xFFFFFF;
break;
default:
assert(0);
}

if (fixed_function) {
/* update lighting constants */
Expand Down Expand Up @@ -4238,19 +4250,15 @@ static void pgraph_shader_update_constants(PGRAPHState *pg,

float m11 = 0.5 * (pg->surface_binding_dim.width/aa_width);
float m22 = -0.5 * (pg->surface_binding_dim.height/aa_height);
float m33 = zclip_max - zclip_min;
float m33 = zmax;
float m41 = *(float*)&pg->vsh_constants[NV_IGRAPH_XF_XFCTX_VPOFF][0];
float m42 = *(float*)&pg->vsh_constants[NV_IGRAPH_XF_XFCTX_VPOFF][1];
float m43 = zclip_min;
if (m33 == 0.0) {
m33 = 1.0;
}

float invViewport[16] = {
1.0/m11, 0, 0, 0,
0, 1.0/m22, 0, 0,
0, 0, 1.0/m33, 0,
-1.0+m41/m11, 1.0+m42/m22, -m43/m33, 1.0
-1.0+m41/m11, 1.0+m42/m22, 0, 1.0
};

if (binding->inv_viewport_loc != -1) {
Expand Down Expand Up @@ -4284,7 +4292,9 @@ static void pgraph_shader_update_constants(PGRAPHState *pg,
}

if (binding->clip_range_loc != -1) {
glUniform2f(binding->clip_range_loc, zclip_min, zclip_max);
float zclip_min = *(float*)&pg->regs[NV_PGRAPH_ZCLIPMIN] / zmax * 2.0 - 1.0;
float zclip_max = *(float*)&pg->regs[NV_PGRAPH_ZCLIPMAX] / zmax * 2.0 - 1.0;
glUniform4f(binding->clip_range_loc, 0, zmax, zclip_min, zclip_max);
}

/* Clipping regions */
Expand Down
9 changes: 7 additions & 2 deletions hw/xbox/nv2a/shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ static MString* generate_geometry_shader(
"void emit_vertex(int index, int _unused) {\n"
" gl_Position = gl_in[index].gl_Position;\n"
" gl_PointSize = gl_in[index].gl_PointSize;\n"
" gl_ClipDistance[0] = gl_in[index].gl_ClipDistance[0];\n"
" gl_ClipDistance[1] = gl_in[index].gl_ClipDistance[1];\n"
" vtx_inv_w = v_vtx_inv_w[index];\n"
" vtx_inv_w_flat = v_vtx_inv_w[index];\n"
" vtxD0 = v_vtxD0[index];\n"
Expand All @@ -289,6 +291,8 @@ static MString* generate_geometry_shader(
"void emit_vertex(int index, int provoking_index) {\n"
" gl_Position = gl_in[index].gl_Position;\n"
" gl_PointSize = gl_in[index].gl_PointSize;\n"
" gl_ClipDistance[0] = gl_in[index].gl_ClipDistance[0];\n"
" gl_ClipDistance[1] = gl_in[index].gl_ClipDistance[1];\n"
" vtx_inv_w = v_vtx_inv_w[index];\n"
" vtx_inv_w_flat = v_vtx_inv_w[provoking_index];\n"
" vtxD0 = v_vtxD0[provoking_index];\n"
Expand Down Expand Up @@ -784,7 +788,7 @@ static MString *generate_vertex_shader(const ShaderState *state,
MString *header = mstring_from_str(
"#version 400\n"
"\n"
"uniform vec2 clipRange;\n"
"uniform vec4 clipRange;\n"
"uniform vec2 surfaceSize;\n"
"\n"
/* All constants in 1 array declaration */
Expand Down Expand Up @@ -864,7 +868,6 @@ GLSL_DEFINE(texMat3, GLSL_C_MAT4(NV_IGRAPH_XF_XFCTX_T3MAT))

if (state->fixed_function) {
generate_fixed_function(state, header, body);

} else if (state->vertex_program) {
vsh_translate(VSH_VERSION_XVS,
(uint32_t*)state->program_data,
Expand Down Expand Up @@ -973,6 +976,8 @@ GLSL_DEFINE(texMat3, GLSL_C_MAT4(NV_IGRAPH_XF_XFCTX_T3MAT))
" vtxT3 = oT3 * vtx_inv_w;\n"
" gl_Position = oPos;\n"
" gl_PointSize = oPts.x;\n"
" gl_ClipDistance[0] = oPos.z - oPos.w*clipRange.z;\n" // Near
" gl_ClipDistance[1] = oPos.w*clipRange.w - oPos.z;\n" // Far
"\n"
"}\n",
shade_model_mult,
Expand Down
5 changes: 0 additions & 5 deletions hw/xbox/nv2a/vsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,6 @@ void vsh_translate(uint16_t version,
mstring_append(body, " oPos.z = oPos.w;\n");
}
mstring_append(body,
/* Map the clip range into clip space so z is clipped correctly.
* Note this makes the values in the depth buffer wrong. This should be
* handled with gl_ClipDistance instead, but that has performance issues
* on OS X.
*/
" if (clipRange.y != clipRange.x) {\n"
" oPos.z = (oPos.z - clipRange.x)/(0.5*(clipRange.y - clipRange.x)) - 1;\n"
" }\n"
Expand Down
70 changes: 66 additions & 4 deletions hw/xbox/nvnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
#include "hw/pci/pci.h"
#include "hw/qdev-properties.h"
#include "net/net.h"
#include "qemu/bswap.h"
#include "qemu/iov.h"
#include "migration/vmstate.h"
#include "nvnet_regs.h"

#define IOPORT_SIZE 0x8
#define MMIO_SIZE 0x400

static const uint8_t bcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

// #define DEBUG
#ifdef DEBUG
# define NVNET_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
Expand Down Expand Up @@ -432,6 +435,58 @@ static bool nvnet_is_packet_oversized(size_t size)
return size > RX_ALLOC_BUFSIZE;
}

static bool receive_filter(NvNetState *s, const uint8_t *buf, int size)
{
if (size < 6) {
return false;
}

uint32_t rctl = nvnet_get_reg(s, NvRegPacketFilterFlags, 4);
int isbcast = !memcmp(buf, bcast, sizeof bcast);

/* Broadcast */
if (isbcast) {
/* FIXME: bcast filtering */
trace_nvnet_rx_filter_bcast_match();
return true;
}

if (!(rctl & NVREG_PFF_MYADDR)) {
/* FIXME: Confirm PFF_MYADDR filters mcast */
return true;
}

/* Multicast */
uint32_t addr[2];
addr[0] = cpu_to_le32(nvnet_get_reg(s, NvRegMulticastAddrA, 4));
addr[1] = cpu_to_le32(nvnet_get_reg(s, NvRegMulticastAddrB, 4));
if (memcmp(addr, bcast, sizeof bcast)) {
uint32_t dest_addr[2];
memcpy(dest_addr, buf, 6);
dest_addr[0] &= cpu_to_le32(nvnet_get_reg(s, NvRegMulticastMaskA, 4));
dest_addr[1] &= cpu_to_le32(nvnet_get_reg(s, NvRegMulticastMaskB, 4));

if (!memcmp(dest_addr, addr, 6)) {
trace_nvnet_rx_filter_mcast_match(MAC_ARG(dest_addr));
return true;
} else {
trace_nvnet_rx_filter_mcast_mismatch(MAC_ARG(dest_addr));
}
}

/* Unicast */
addr[0] = cpu_to_le32(nvnet_get_reg(s, NvRegMacAddrA, 4));
addr[1] = cpu_to_le32(nvnet_get_reg(s, NvRegMacAddrB, 4));
if (!memcmp(buf, addr, 6)) {
trace_nvnet_rx_filter_ucast_match(MAC_ARG(buf));
return true;
} else {
trace_nvnet_rx_filter_ucast_mismatch(MAC_ARG(buf));
}

return false;
}

static ssize_t nvnet_receive_iov(NetClientState *nc,
const struct iovec *iov, int iovcnt)
{
Expand All @@ -443,10 +498,17 @@ static ssize_t nvnet_receive_iov(NetClientState *nc,
if (nvnet_is_packet_oversized(size)) {
/* Drop */
NVNET_DPRINTF("%s packet too large!\n", __func__);
trace_nvnet_rx_oversized(size);
return size;
}

iov_to_buf(iov, iovcnt, 0, s->rx_dma_buf, size);

if (!receive_filter(s, s->rx_dma_buf, size)) {
trace_nvnet_rx_filter_dropped();
return size;
}

#ifdef DEBUG
nvnet_hex_dump(s, s->rx_dma_buf, size);
#endif
Expand All @@ -472,7 +534,7 @@ static ssize_t nvnet_dma_packet_to_guest(NvNetState *s,
dma_addr_t rx_ring_addr = nvnet_get_reg(s, NvRegRxRingPhysAddr, 4);
rx_ring_addr += s->rx_ring_index * sizeof(desc);
pci_dma_read(d, rx_ring_addr, &desc, sizeof(desc));
NVNET_DPRINTF("RX: Looking at ring descriptor %d (0x%llx): ",
NVNET_DPRINTF("RX: Looking at ring descriptor %d (0x%" HWADDR_PRIx "): ",
s->rx_ring_index, rx_ring_addr);
NVNET_DPRINTF("Buffer: 0x%x, ", desc.packet_buffer);
NVNET_DPRINTF("Length: 0x%x, ", desc.length);
Expand Down Expand Up @@ -539,7 +601,7 @@ static ssize_t nvnet_dma_packet_from_guest(NvNetState *s)
dma_addr_t tx_ring_addr = nvnet_get_reg(s, NvRegTxRingPhysAddr, 4);
tx_ring_addr += s->tx_ring_index * sizeof(desc);
pci_dma_read(d, tx_ring_addr, &desc, sizeof(desc));
NVNET_DPRINTF("TX: Looking at ring desc %d (%llx): ",
NVNET_DPRINTF("TX: Looking at ring desc %d (%" HWADDR_PRIx "): ",
s->tx_ring_index, tx_ring_addr);
NVNET_DPRINTF("Buffer: 0x%x, ", desc.packet_buffer);
NVNET_DPRINTF("Length: 0x%x, ", desc.length);
Expand Down Expand Up @@ -847,7 +909,7 @@ static void nvnet_dump_ring_descriptors(NvNetState *s)
dma_addr_t tx_ring_addr = nvnet_get_reg(s, NvRegTxRingPhysAddr, 4);
tx_ring_addr += i * sizeof(desc);
pci_dma_read(d, tx_ring_addr, &desc, sizeof(desc));
NVNET_DPRINTF("TX: Dumping ring desc %d (%llx): ",
NVNET_DPRINTF("TX: Dumping ring desc %d (%" HWADDR_PRIx "): ",
i, tx_ring_addr);
NVNET_DPRINTF("Buffer: 0x%x, ", desc.packet_buffer);
NVNET_DPRINTF("Length: 0x%x, ", desc.length);
Expand All @@ -860,7 +922,7 @@ static void nvnet_dump_ring_descriptors(NvNetState *s)
dma_addr_t rx_ring_addr = nvnet_get_reg(s, NvRegRxRingPhysAddr, 4);
rx_ring_addr += i * sizeof(desc);
pci_dma_read(d, rx_ring_addr, &desc, sizeof(desc));
NVNET_DPRINTF("RX: Dumping ring desc %d (%llx): ",
NVNET_DPRINTF("RX: Dumping ring desc %d (%" HWADDR_PRIx "): ",
i, rx_ring_addr);
NVNET_DPRINTF("Buffer: 0x%x, ", desc.packet_buffer);
NVNET_DPRINTF("Length: 0x%x, ", desc.length);
Expand Down
7 changes: 7 additions & 0 deletions hw/xbox/trace-events
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ nvnet_reg_read(uint32_t addr, const char *name, unsigned int size, uint64_t val)
nvnet_reg_write(uint32_t addr, const char *name, unsigned int size, uint64_t val) "addr 0x%"PRIx32" %s size %d val 0x%"PRIx64
nvnet_io_read(uint32_t addr, unsigned int size, uint64_t val) "addr 0x%"PRIx32" size %d val 0x%"PRIx64
nvnet_io_write(uint32_t addr, unsigned int size, uint64_t val) "addr 0x%"PRIx32" size %d val 0x%"PRIx64
nvnet_rx_filter_bcast_match(void) "broadcast match"
nvnet_rx_filter_mcast_match(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5) "multicast match: %02x:%02x:%02x:%02x:%02x:%02x"
nvnet_rx_filter_mcast_mismatch(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5) "multicast mismatch: %02x:%02x:%02x:%02x:%02x:%02x"
nvnet_rx_filter_ucast_match(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5) "unicast match: %02x:%02x:%02x:%02x:%02x:%02x"
nvnet_rx_filter_ucast_mismatch(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5) "unicast mismatch: %02x:%02x:%02x:%02x:%02x:%02x"
nvnet_rx_oversized(size_t size) "Received packet dropped because it was oversized (%zu bytes)"
nvnet_rx_filter_dropped(void) "Received packet dropped by RX filter"
14 changes: 13 additions & 1 deletion scripts/download-macos-libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class LibInstaller:
DARWIN_TARGET_X64="darwin_17" # macOS 10.13
DARWIN_TARGET_ARM64="darwin_20" # macOS 11.x
DARWIN_TARGET_ARM64="darwin_21" # macOS 12.x

def __init__(self, arch):
self._queue = []
Expand All @@ -44,6 +44,18 @@ def get_latest_pkg_filename_url(self, pkg_name):
pkg_base_url = f'{MIRROR}/{pkg_name}'
pkg_list = urlopen(pkg_base_url).read().decode('utf-8')
pkgs = re.findall(pkg_name + r'[\w\.\-\_\+]*?\.' + self._darwin_target + r'\.' + self._arch + r'\.tbz2', pkg_list)

if len(pkgs) < 1:
pkgs = re.findall(pkg_name + r'[\w\.\-\_\+]*?\.darwin_any\.' + self._arch + r'\.tbz2', pkg_list)
if len(pkgs) < 1:
pkgs = re.findall(pkg_name + r'[\w\.\-\_\+]*?\.' + self._darwin_target + r'\.noarch\.tbz2', pkg_list)
if len(pkgs) < 1:
pkgs = re.findall(pkg_name + r'[\w\.\-\_\+]*?\.darwin_any\.noarch\.tbz2', pkg_list)

if len(pkgs) < 1:
print(f' [*] [ERROR] Unable to find version of {pkg_name} compatible with {self._darwin_target}.{self._arch}')
exit(1)

pkg_filename = pkgs[-1]
return pkg_filename, f'{pkg_base_url}/{pkg_filename}'

Expand Down
2 changes: 1 addition & 1 deletion softmmu/vl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2853,7 +2853,7 @@ void qemu_init(int argc, char **argv)
}

if (strlen(dvd_path) > 0) {
if (xemu_check_file(dvd_path)) {
if (xemu_check_file(dvd_path) || strcmp(dvd_path, hdd_path) == 0) {
char *msg = g_strdup_printf("Failed to open DVD image file '%s'. Please check machine settings.", dvd_path);
xemu_queue_error_message(msg);
g_free(msg);
Expand Down
2 changes: 1 addition & 1 deletion ui/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ endif
xemu_ss.add(when: 'CONFIG_LINUX', if_true: [gtk, files('xemu-os-utils-linux.c')])
xemu_ss.add(when: 'CONFIG_WIN32', if_true: files('xemu-os-utils-windows.c'))
xemu_ss.add(when: 'CONFIG_DARWIN', if_true: files('xemu-os-utils-macos.m'))
xemu_ss.add(imgui, implot, stb_image, noc, sdl, opengl, openssl, fa, fpng, json, httplib)
xemu_ss.add(imgui, implot, stb_image, noc, sdl, opengl, openssl, fa, fpng, json, httplib, fatx)

softmmu_ss.add_all(xemu_ss)

Expand Down
Loading

0 comments on commit faa75d5

Please sign in to comment.