@@ -172,14 +172,22 @@ void gif_handle_tag(struct ps2_gif* gif, uint128_t data) {
172172 gif -> tag .reg = data .u64 [1 ];
173173 gif -> tag .index = 0 ;
174174
175+ if (gif -> tag .nregs == 0 )
176+ gif -> tag .nregs = 16 ;
177+
175178 switch (gif -> tag .fmt ) {
176- case 0 :
179+ case 0 : {
180+ gif -> tag .remaining = gif -> tag .nregs * gif -> tag .nloop ;
181+ gif -> tag .qwc = gif -> tag .nloop * gif -> tag .nregs ;
182+ } break ;
177183 case 1 : {
178184 gif -> tag .remaining = gif -> tag .nregs * gif -> tag .nloop ;
185+ gif -> tag .qwc = (gif -> tag .nloop * gif -> tag .nregs + 1 ) / 2 ;
179186 } break ;
180187 case 2 :
181188 case 3 : {
182189 gif -> tag .remaining = gif -> tag .nloop ;
190+ gif -> tag .qwc = gif -> tag .nloop ;
183191 } break ;
184192 }
185193
@@ -227,8 +235,9 @@ void gif_handle_packed(struct ps2_gif* gif, uint128_t data) {
227235 default : printf ("gif: PACKED format for reg %d unimplemented\n" , r ); exit (1 ); break ;
228236 }
229237
230- // Note: This handles odd NREGS*NLOOP case
231- if (gif -> tag .index == gif -> tag .remaining ) {
238+ gif -> tag .qwc -- ;
239+
240+ if (gif -> tag .qwc == 0 ) {
232241 gif -> state = GIF_STATE_RECV_TAG ;
233242
234243 return ;
@@ -267,11 +276,13 @@ void gif_handle_reglist(struct ps2_gif* gif, uint128_t data) {
267276 if (gif -> tag .index == gif -> tag .remaining ) {
268277 gif -> state = GIF_STATE_RECV_TAG ;
269278
270- return ;
279+ break ;
271280 }
272281 }
273282
274- if (gif -> tag .index == gif -> tag .remaining ) {
283+ gif -> tag .qwc -- ;
284+
285+ if (gif -> tag .qwc == 0 ) {
275286 gif -> state = GIF_STATE_RECV_TAG ;
276287
277288 return ;
@@ -282,13 +293,11 @@ void gif_handle_image(struct ps2_gif* gif, uint128_t data) {
282293 ps2_gs_write_internal (gif -> gs , GS_HWREG , data .u64 [0 ]);
283294 ps2_gs_write_internal (gif -> gs , GS_HWREG , data .u64 [1 ]);
284295
285- ++ gif -> tag .index ;
296+ gif -> tag .qwc -- ;
286297
287- if (gif -> tag .index == gif -> tag . remaining ) {
298+ if (gif -> tag .qwc == 0 ) {
288299 gif -> state = GIF_STATE_RECV_TAG ;
289300 }
290-
291- return ;
292301}
293302
294303void ps2_gif_write128 (struct ps2_gif * gif , uint32_t addr , uint128_t data ) {
@@ -301,7 +310,7 @@ void ps2_gif_write128(struct ps2_gif* gif, uint32_t addr, uint128_t data) {
301310 return ;
302311 }
303312
304- if (gif -> tag .index != gif -> tag . remaining ) {
313+ if (gif -> tag .qwc ) {
305314 switch (gif -> tag .fmt ) {
306315 case 0 : gif_handle_packed (gif , data ); return ;
307316 case 1 : gif_handle_reglist (gif , data ); return ;
0 commit comments