Skip to content

Commit

Permalink
libpacket2 with VU support (#149)
Browse files Browse the repository at this point in the history
* added VU1 support!

* small fixes

* fixed documentation

* added packet2 structs and enums

* added packet2 send wrapper in libdma

* fixed enums, added tte

* added chain functions

* added unpack modes to types

* added vif related functions

* removed unecessary comment

* changed naming convention

* changed naming convention

* fixed include dependency

* added packet2

* moved vu1 class from libdraw to sample

* implemented packet2 in sample

* refactored vu1.c to libvu

* moved vif_added_bytes to packet2

* fixed flush cache bug

* refactored libvu

* fixed spaces

* small naming fix

* added channel choice in upload_program()

* naming fixes + wait gif tag

* small upgrade to start program

* removed unecessary flush

* refactored to one create() func

* moved vu stuff from libvu to libpacket2

* fixed typo

* -_vu_unpack_add*, refactored _vu to _helpers

* comments fix

* changed helpers to utils

* added print(), fixed bug in add()

* added offset, double buffer to open_unpack()

* moved func upload_program() added "utils_"

* +print_qw(), changed packet2_add()

* added some warning in comment

* changed offset to dest_address, fixed counting bug

* refactored sample

* dma wait() before send()
  • Loading branch information
h4570 committed Nov 24, 2020
1 parent 3c4e3ef commit f870e2d
Show file tree
Hide file tree
Showing 21 changed files with 2,445 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ee/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

SUBDIRS = erl kernel kernel-nopatch libc rpc debug \
eedebug sbv dma graph math3d \
packet draw erl-loader mpeg libgs \
packet packet2 draw erl-loader mpeg libgs \
libvux font input inputx network iopreboot \
elf-loader

Expand Down
2 changes: 2 additions & 0 deletions ee/dma/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

EE_OBJS = dma.o erl-support.o

EE_INCS := $(EE_INCS) -I$(PS2SDKSRC)/ee/packet2/include

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/ee/Rules.lib.make
include $(PS2SDKSRC)/ee/Rules.make
Expand Down
10 changes: 10 additions & 0 deletions ee/dma/include/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define __DMA_H__

#include <tamtypes.h>
#include <packet2_types.h>

#define DMA_CHANNEL_VIF0 0x00
#define DMA_CHANNEL_VIF1 0x01
Expand Down Expand Up @@ -50,6 +51,15 @@ void dma_wait_fast(void);
/** Wait until the specified dma channel is ready. */
int dma_channel_wait(int channel, int timeout);

/**
* Send packet2.
* Type chain/normal is choosen from packet2_t.
* @param packet2 Pointer to packet.
* @param channel DMA channel.
* @param flush_cache Should be cache flushed before send?
*/
void dma_channel_send_packet2(packet2_t *packet2, int channel, u8 flush_cache);

/** Send a dmachain to the specified dma channel. */
int dma_channel_send_chain(int channel, void *data, int qwc, int flags, int spr);

Expand Down
27 changes: 27 additions & 0 deletions ee/dma/src/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,33 @@ int dma_channel_wait(int channel, int timeout)

}

void dma_channel_send_packet2(packet2_t *packet2, int channel, u8 flush_cache)
{
// dma_channel_send_chain does NOT flush all data that is "source chained"
if (packet2->mode == P2_MODE_CHAIN)
{
// "dma_channel_send_normal always flushes the data cache"
if (flush_cache)
FlushCache(0);
dma_channel_send_chain(
channel,
(void *)((u32)packet2->base & 0x0FFFFFFF),
0,
packet2->tte ? DMA_FLAG_TRANSFERTAG : 0,
0);
}
else
{
dma_channel_send_normal(
channel,
(void *)((u32)packet2->base & 0x0FFFFFFF), // make ptr normal
((u32)packet2->next - (u32)packet2->base) >> 4, // length in qwords
0,
0);
}
}


int dma_channel_send_chain(int channel, void *data, int data_size, int flags, int spr)
{

Expand Down
22 changes: 22 additions & 0 deletions ee/draw/include/draw3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@
((u64)GIF_REG_ST) << 4 | \
((u64)GIF_REG_XYZ2) << 8

/**
* Sandro:
* Similar to DRAW_STQ_REGLIST, but order of ST and RGBAQ is swapped.
* Needed for REGLIST mode which is used mostly in VU1, because of nature of 128bit registers.
* Without that, texture perspective correction will not work.
* Bad example:
* 1. RGBA -> RGBAQ (q was not set!)
* 2. STQ -> ST
* 3. XYZ2
* Good example:
* 1. STQ -> ST
* 2. RGBA -> RGBAQ (q grabbed from STQ)
* 3. XYZ2
* For more details, please check:
* EE_Overview_Manual.pdf - 3.3 Data transfer to GS
* GS_Users_Manual.pdf - 3.4.10 Perspective correction
*/
#define DRAW_STQ2_REGLIST \
((u64)GIF_REG_ST) << 0 | \
((u64)GIF_REG_RGBAQ) << 4 | \
((u64)GIF_REG_XYZ2) << 8

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
12 changes: 12 additions & 0 deletions ee/draw/samples/vu1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

SAMPLE_DIR = draw/vu1

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/samples/Rules.samples
41 changes: 41 additions & 0 deletions ee/draw/samples/vu1/Makefile.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

EE_BIN = vu1.elf
EE_OBJS = micro_programs/draw_3D.o \
main.o
EE_LIBS = -ldraw -lgraph -lmath3d -lpacket2 -ldma
EE_DVP = dvp-as
#EE_VCL = vcl

all: zbyszek.c $(EE_BIN)
$(EE_STRIP) --strip-all $(EE_BIN)

# Original VCL tool preferred.
# It can be runned on WSL, but with some tricky commands:
# https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520
#%.vsm: %.vcl
# $(EE_VCL) $< >> $@

%.o: %.vsm
$(EE_DVP) $< -o $@

zbyszek.c:
bin2c zbyszek.raw zbyszek.c zbyszek

clean:
rm -f $(EE_BIN) $(EE_OBJS) zbyszek.c

run: $(EE_BIN)
ps2client execee host:$(EE_BIN)

reset:
ps2client reset

include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
Loading

1 comment on commit f870e2d

@badekk
Copy link

@badekk badekk commented on f870e2d Jun 5, 2022

Choose a reason for hiding this comment

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

Looks good ;D

Please sign in to comment.