Skip to content

Commit f870e2d

Browse files
authored
libpacket2 with VU support (#149)
* 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()
1 parent 3c4e3ef commit f870e2d

File tree

21 files changed

+2445
-1
lines changed

21 files changed

+2445
-1
lines changed

ee/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

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

ee/dma/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
EE_OBJS = dma.o erl-support.o
1010

11+
EE_INCS := $(EE_INCS) -I$(PS2SDKSRC)/ee/packet2/include
12+
1113
include $(PS2SDKSRC)/Defs.make
1214
include $(PS2SDKSRC)/ee/Rules.lib.make
1315
include $(PS2SDKSRC)/ee/Rules.make

ee/dma/include/dma.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define __DMA_H__
1818

1919
#include <tamtypes.h>
20+
#include <packet2_types.h>
2021

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

54+
/**
55+
* Send packet2.
56+
* Type chain/normal is choosen from packet2_t.
57+
* @param packet2 Pointer to packet.
58+
* @param channel DMA channel.
59+
* @param flush_cache Should be cache flushed before send?
60+
*/
61+
void dma_channel_send_packet2(packet2_t *packet2, int channel, u8 flush_cache);
62+
5363
/** Send a dmachain to the specified dma channel. */
5464
int dma_channel_send_chain(int channel, void *data, int qwc, int flags, int spr);
5565

ee/dma/src/dma.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,33 @@ int dma_channel_wait(int channel, int timeout)
154154

155155
}
156156

157+
void dma_channel_send_packet2(packet2_t *packet2, int channel, u8 flush_cache)
158+
{
159+
// dma_channel_send_chain does NOT flush all data that is "source chained"
160+
if (packet2->mode == P2_MODE_CHAIN)
161+
{
162+
// "dma_channel_send_normal always flushes the data cache"
163+
if (flush_cache)
164+
FlushCache(0);
165+
dma_channel_send_chain(
166+
channel,
167+
(void *)((u32)packet2->base & 0x0FFFFFFF),
168+
0,
169+
packet2->tte ? DMA_FLAG_TRANSFERTAG : 0,
170+
0);
171+
}
172+
else
173+
{
174+
dma_channel_send_normal(
175+
channel,
176+
(void *)((u32)packet2->base & 0x0FFFFFFF), // make ptr normal
177+
((u32)packet2->next - (u32)packet2->base) >> 4, // length in qwords
178+
0,
179+
0);
180+
}
181+
}
182+
183+
157184
int dma_channel_send_chain(int channel, void *data, int data_size, int flags, int spr)
158185
{
159186

ee/draw/include/draw3d.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@
3535
((u64)GIF_REG_ST) << 4 | \
3636
((u64)GIF_REG_XYZ2) << 8
3737

38+
/**
39+
* Sandro:
40+
* Similar to DRAW_STQ_REGLIST, but order of ST and RGBAQ is swapped.
41+
* Needed for REGLIST mode which is used mostly in VU1, because of nature of 128bit registers.
42+
* Without that, texture perspective correction will not work.
43+
* Bad example:
44+
* 1. RGBA -> RGBAQ (q was not set!)
45+
* 2. STQ -> ST
46+
* 3. XYZ2
47+
* Good example:
48+
* 1. STQ -> ST
49+
* 2. RGBA -> RGBAQ (q grabbed from STQ)
50+
* 3. XYZ2
51+
* For more details, please check:
52+
* EE_Overview_Manual.pdf - 3.3 Data transfer to GS
53+
* GS_Users_Manual.pdf - 3.4.10 Perspective correction
54+
*/
55+
#define DRAW_STQ2_REGLIST \
56+
((u64)GIF_REG_ST) << 0 | \
57+
((u64)GIF_REG_RGBAQ) << 4 | \
58+
((u64)GIF_REG_XYZ2) << 8
59+
3860
#ifdef __cplusplus
3961
extern "C" {
4062
#endif

ee/draw/samples/vu1/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# _____ ___ ____ ___ ____
2+
# ____| | ____| | | |____|
3+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
4+
#-----------------------------------------------------------------------
5+
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
6+
# Licenced under Academic Free License version 2.0
7+
# Review ps2sdk README & LICENSE files for further details.
8+
9+
SAMPLE_DIR = draw/vu1
10+
11+
include $(PS2SDKSRC)/Defs.make
12+
include $(PS2SDKSRC)/samples/Rules.samples
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# _____ ___ ____ ___ ____
2+
# ____| | ____| | | |____|
3+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
4+
#-----------------------------------------------------------------------
5+
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
6+
# Licenced under Academic Free License version 2.0
7+
# Review ps2sdk README & LICENSE files for further details.
8+
9+
EE_BIN = vu1.elf
10+
EE_OBJS = micro_programs/draw_3D.o \
11+
main.o
12+
EE_LIBS = -ldraw -lgraph -lmath3d -lpacket2 -ldma
13+
EE_DVP = dvp-as
14+
#EE_VCL = vcl
15+
16+
all: zbyszek.c $(EE_BIN)
17+
$(EE_STRIP) --strip-all $(EE_BIN)
18+
19+
# Original VCL tool preferred.
20+
# It can be runned on WSL, but with some tricky commands:
21+
# https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520
22+
#%.vsm: %.vcl
23+
# $(EE_VCL) $< >> $@
24+
25+
%.o: %.vsm
26+
$(EE_DVP) $< -o $@
27+
28+
zbyszek.c:
29+
bin2c zbyszek.raw zbyszek.c zbyszek
30+
31+
clean:
32+
rm -f $(EE_BIN) $(EE_OBJS) zbyszek.c
33+
34+
run: $(EE_BIN)
35+
ps2client execee host:$(EE_BIN)
36+
37+
reset:
38+
ps2client reset
39+
40+
include $(PS2SDK)/samples/Makefile.pref
41+
include $(PS2SDK)/samples/Makefile.eeglobal

0 commit comments

Comments
 (0)