Index: Makefile
===================================================================
RCS file: /cvsroot/nouveau/renouveau/Makefile,v
retrieving revision 1.13
diff -u -r1.13 Makefile
--- Makefile	2 Jun 2006 22:42:02 -0000	1.13
+++ Makefile	12 Jun 2006 11:31:05 -0000
@@ -2,8 +2,8 @@
 CFLAGS=-g -Wall `sdl-config --cflags`
 LDFLAGS=-lGL `sdl-config --libs`
 
-SOURCES=cmds.c re.c disasm_vp.c disasm_fp.c object.c texture.c tests.c main.c NVCtrl.c misc.c
-HEADERS=cmds.h re.h nv_hw.h nv40_reg.h
+SOURCES=re.c disasm_vp.c disasm_fp.c texture.c tests.c main.c NVCtrl.c misc.c objects.c
+HEADERS=re.h nv_hw.h nv40_reg.h objects.c
 
 all: dep $(TARGET) disasm_vp
 
Index: disasm_fp.c
===================================================================
RCS file: /cvsroot/nouveau/renouveau/disasm_fp.c,v
retrieving revision 1.4
diff -u -r1.4 disasm_fp.c
--- disasm_fp.c	27 May 2006 20:05:32 -0000	1.4
+++ disasm_fp.c	12 Jun 2006 11:31:05 -0000
@@ -1,6 +1,6 @@
 #include <stdio.h>
 #include "re.h"
-#include "cmds.h"
+#include "nv40_reg.h"
 
 extern unsigned int *framebuffer;
 
Index: disasm_vp.c
===================================================================
RCS file: /cvsroot/nouveau/renouveau/disasm_vp.c,v
retrieving revision 1.7
diff -u -r1.7 disasm_vp.c
--- disasm_vp.c	29 May 2006 02:27:58 -0000	1.7
+++ disasm_vp.c	12 Jun 2006 11:31:06 -0000
@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include "cmds.h"
+#include "nv40_reg.h"
 
 static int data_id = 0;
 
Index: nv_hw.h
===================================================================
RCS file: /cvsroot/nouveau/renouveau/nv_hw.h,v
retrieving revision 1.3
diff -u -r1.3 nv_hw.h
--- nv_hw.h	21 May 2006 19:24:55 -0000	1.3
+++ nv_hw.h	12 Jun 2006 11:31:06 -0000
@@ -1,10 +1,18 @@
 
-#define NV04 0x01
-#define NV10 0x02
-#define NV15 0x04
-#define NV20 0x08
-#define NV30 0x10
-#define NV40 0x20
-#define G70  0x40
+#define NV03 0x01
+#define NV04 0x02
+#define NV10 0x04
+#define NV15 0x08
+#define NV20 0x10
+#define NV30 0x20
+#define NV40 0x40
+#define G70  0x80
 
+#define ENGINE_SW	0
+#define ENGINE_GRAPHICS	1
+#define ENGINE_DVD	2
+
+
+#define NV_PRAMIN                                       0x00700000
+#define NV_PFIFO_RAMHT                                  0x00002210
 
Index: nv_objects.h
===================================================================
RCS file: nv_objects.h
diff -N nv_objects.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ nv_objects.h	12 Jun 2006 11:31:06 -0000
@@ -0,0 +1,34 @@
+#define NV04_DX5_TEXTURED_TRIANGLE			0x00000054
+
+#define NV04_DX5_TEXTURED_TRIANGLE_NOTIFY		0x00000180
+#define NV04_DX5_TEXTURED_TRIANGLE_DMA_1		0x00000184
+#define NV04_DX5_TEXTURED_TRIANGLE_DMA_2		0x00000188
+#define NV04_DX5_TEXTURED_TRIANGLE_SURFACE		0x00000188
+
+#define NV04_DX5_TEXTURED_TRIANGLE_COLOR_KEY		0x00000300
+#define NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_OFFSET	0x00000304
+#define NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_FORMAT	0x00000308
+#define NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_FILTER	0x0000030C
+#define NV04_DX5_TEXTURED_TRIANGLE_BLEND		0x00000310
+#define NV04_DX5_TEXTURED_TRIANGLE_CONTROL		0x00000314
+#define NV04_DX5_TEXTURED_TRIANGLE_FOG_COLOR		0x00000318
+
+
+#define NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SX(i)	(0x00000400 + 0x20 * i)
+#define NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SY(i)	(0x00000404 + 0x20 * i)
+#define NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SZ(i)	(0x00000408 + 0x20 * i)
+#define NV04_DX5_TEXTURED_TRIANGLE_INV_W(i)		(0x0000040C + 0x20 * i)
+#define NV04_DX5_TEXTURED_TRIANGLE_COLOR(i)		(0x00000410 + 0x20 * i)
+#define NV04_DX5_TEXTURED_TRIANGLE_SPECULAR(i)		(0x00000414 + 0x20 * i)
+#define NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_S(i)		(0x00000418 + 0x20 * i)
+#define NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_T(i)		(0x0000041C + 0x20 * i)
+
+#define NV04_DX5_TEXTURED_TRIANGLE_DRAW			0x00000600
+#define NV04_DX5_TEXTURED_TRIANGLE_DRAW_V0		  3:0
+#define NV04_DX5_TEXTURED_TRIANGLE_DRAW_V1		  7:4
+#define NV04_DX5_TEXTURED_TRIANGLE_DRAW_V2		 11:8
+#define NV04_DX5_TEXTURED_TRIANGLE_DRAW_V3		15:12
+#define NV04_DX5_TEXTURED_TRIANGLE_DRAW_V4		19:16
+#define NV04_DX5_TEXTURED_TRIANGLE_DRAW_V5		23:20
+
+#define NV04_CONTEXT_SURFACES_3D			0x00000053
Index: object.c
===================================================================
RCS file: object.c
diff -N object.c
--- object.c	20 May 2006 02:04:01 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,17 +0,0 @@
-#include <stdio.h>
-#include "re.h"
-
-extern unsigned int* all_regs;
-
-void lookup_object(unsigned int cmd, unsigned int id)
-{
-	printf("setting up channel with hash %x ",id);
-	// right now we brute-force the hash table. we could be a lot smarter 
-	// if we really knew what we're doing but that one is more robust
-	int i;
-	for(i=0x00700000;i<0x00700000+0x000fffff;i+=4)
-		if (all_regs[i/4]==id)
-			printf("hash found at 0x%x object is 0x%x ",i,all_regs[i/4+1]);
-
-}
-
Index: objects.c
===================================================================
RCS file: objects.c
diff -N objects.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ objects.c	12 Jun 2006 11:31:06 -0000
@@ -0,0 +1,291 @@
+#ifndef MMTRACE
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include "re.h"
+#define message(fmt, ...)	printf(fmt "\n", ##__VA_ARGS__)
+#else
+#include "mmtrace.h"
+#include "mt_nvidia.h"
+#endif
+
+#include "nv_hw.h"
+#include "nv_objects.h"
+#include "objects.h"
+
+const char* print_format(unsigned int value, void*format) {
+	static char buf[128];
+	snprintf(buf, sizeof(buf), format?format:"%x", value);
+	return buf;
+}
+
+const char* print_float(unsigned int value, void*format) {
+	static char buf[128];
+	snprintf(buf, sizeof(buf), format?format:"%f", (double)*(float*)&value);
+	return buf;
+}
+
+#define __(a)	a, # a
+#define PRINT_BITFIELD(bf, func, data)	{0?bf, 1?bf, func, data}
+#define PRINT_FP32	{0, 31, &print_float, NULL}
+#define PRINT_X32	{0, 31, &print_format, "0x%x"}
+
+// temporary
+#define PRINT_OBJECT	{0, 31, &print_format, "object %08x"}
+
+static const object_store nv_objects[0x100] = {
+	[NV04_DX5_TEXTURED_TRIANGLE] = {__(NV04_DX5_TEXTURED_TRIANGLE),{
+		{__(NV04_DX5_TEXTURED_TRIANGLE_NOTIFY),		{PRINT_OBJECT,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_DMA_1),		{PRINT_OBJECT,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_DMA_2),		{PRINT_OBJECT,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_SURFACE),	{PRINT_OBJECT,	{}} },
+
+		{__(NV04_DX5_TEXTURED_TRIANGLE_COLOR_KEY),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_OFFSET),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_FORMAT),	{		{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_FILTER),	{		{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_BLEND),		{		{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_CONTROL),	{		{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_FOG_COLOR),	{PRINT_X32,	{}} },
+
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SX(0)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SY(0)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SZ(0)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_INV_W(0)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_COLOR(0)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_SPECULAR(0)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_S(0)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_T(0)),	{PRINT_FP32,	{}} },
+
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SX(1)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SY(1)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SZ(1)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_INV_W(1)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_COLOR(1)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_SPECULAR(1)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_S(1)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_T(1)),	{PRINT_FP32,	{}} },
+
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SX(2)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SY(2)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SZ(2)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_INV_W(2)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_COLOR(2)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_SPECULAR(2)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_S(2)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_T(2)),	{PRINT_FP32,	{}} },
+
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SX(3)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SY(3)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SZ(3)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_INV_W(3)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_COLOR(3)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_SPECULAR(3)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_S(3)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_T(3)),	{PRINT_FP32,	{}} },
+
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SX(4)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SY(4)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SZ(4)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_INV_W(4)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_COLOR(4)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_SPECULAR(4)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_S(4)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_T(4)),	{PRINT_FP32,	{}} },
+
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SX(5)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SY(5)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TLVERTEX_SZ(5)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_INV_W(5)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_COLOR(5)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_SPECULAR(5)),	{PRINT_X32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_S(5)),	{PRINT_FP32,	{}} },
+		{__(NV04_DX5_TEXTURED_TRIANGLE_TEXTURE_T(5)),	{PRINT_FP32,	{}} },
+
+		{__(NV04_DX5_TEXTURED_TRIANGLE_DRAW), {
+				PRINT_BITFIELD(NV04_DX5_TEXTURED_TRIANGLE_DRAW_V0, print_format, "%d"),
+				PRINT_BITFIELD(NV04_DX5_TEXTURED_TRIANGLE_DRAW_V1, print_format, "%d"),
+				PRINT_BITFIELD(NV04_DX5_TEXTURED_TRIANGLE_DRAW_V2, print_format, "%d"),
+				PRINT_BITFIELD(NV04_DX5_TEXTURED_TRIANGLE_DRAW_V3, print_format, "%d"),
+				PRINT_BITFIELD(NV04_DX5_TEXTURED_TRIANGLE_DRAW_V4, print_format, "%d"),
+				PRINT_BITFIELD(NV04_DX5_TEXTURED_TRIANGLE_DRAW_V5, print_format, "%d"),
+									      	{}} },
+		{}},
+	},
+
+	[NV04_CONTEXT_SURFACES_3D] = {__(NV04_CONTEXT_SURFACES_3D), {
+		{}},
+	},
+};
+
+// XXX
+// Warning! this will work only for >= NV04!
+unsigned int find_object_type(unsigned int name) {
+	unsigned int htval = all_regs[NV_PFIFO_RAMHT/4];
+
+	unsigned int ht_base;
+	unsigned int ht_size;
+	unsigned int ht_bits;
+//	unsigned int ht_search;
+
+
+	if (card_family == NV03) {
+		ht_base = 0x1000 * ((htval >> 12) & 0x0f);
+		ht_size = 0x1000 << ((htval >> 16) & 0x03);
+		ht_bits = ((htval >> 16) & 0x03) + 9;
+	} else {
+		ht_base = 0x1000 * ((htval >> 4) & 0x1f);
+		ht_size = 0x1000 << ((htval >> 16) & 0x03);
+		ht_bits = ((htval >> 16) & 0x03) + 9;
+//		ht_search = 0x10 << ((htval >> 24) & 0x03);
+	}
+
+	unsigned int hash = 0, ohash;
+	unsigned int context;
+	unsigned int instanceMem;
+	unsigned int type;
+
+	int i;
+	unsigned int temp;
+
+	message("Searching for object %08x", name);
+
+	temp = name;
+	for (i = 32; i > 0; i -= ht_bits) {
+		hash ^= (temp & ((1 << ht_bits) - 1));
+		temp >>= ht_bits;
+	}
+//	hash ^= chid << (ht_bits - 4);
+	hash <<= 3;
+	ohash = hash;
+
+	message("Object hash is %08x", hash);
+
+	int chan;
+	int found = 0;
+
+	// FIXME: I really dunno the number of channels
+	for (chan = 0; chan < 32; chan++) {
+		temp = hash ^ (chan << (ht_bits - 4 + 3));
+		if (all_regs[(NV_PRAMIN + ht_base + temp) / 4] == name) {
+			message("Channel is %d", chan);
+			hash = temp;
+			found = 1;
+			break;
+		}
+	}
+
+	if (found == 0) {
+		message("Object not found at expected place. bruteforcing the table. PLEASE REPORT!");
+		// brute force hash!
+		for(i=0x00700000 + ht_base ;i<0x00700000+ht_base + ht_size; i+=4) {
+			if (all_regs[i/4] == name) {
+				hash = i - 0x00700000 - ht_base;
+				found = 1;
+				break;
+			}
+		}
+	}
+
+	if (found == 0) {
+		message("Object not found in hash table! REPORT ASAP!!!!");
+		return 0;
+	}
+	
+	message("Object found at %08x, %08x", hash, hash ^ ohash);
+
+	context = all_regs[(NV_PRAMIN + ht_base + hash + 4) / 4];
+	message("Context is %08x", context);
+
+	instanceMem = context & 0xffff;
+
+	// engine
+	int engine;
+
+	switch (card_family) {
+		case NV03:
+			engine = (context >> 23) & 1;
+			break;
+		case NV04:
+		case NV10:
+		case NV20:
+		case NV30:
+			engine = (context >> 16) & 0x3;
+			break;
+		case NV40:
+		case G70:
+			engine = (context >> 20) & 0x3;
+			break;
+	}
+	if (engine != ENGINE_GRAPHICS) {
+		message("Can't decode objects with this context!");
+
+		type = (name & 0xff00) >> 8;
+	} else {
+		type = all_regs[(NV_PRAMIN + (instanceMem << 4) + 0 * 4)/4] & 0xff;
+	}
+
+	for (i = 0; i < 4; i++) {
+		message("InstanceMem[%d] = %08x", i, all_regs[(NV_PRAMIN + (instanceMem << 4)  + i * 4)/4]);
+	}
+
+	return type;
+}
+
+char *format_load(int object_type, int offset, unsigned int value) {
+	static char buf[BUFSIZ];
+	int pos = 0;
+	const object_store *obj;
+	const object_field_store *field;
+
+	assert(object_type < sizeof(nv_objects)/sizeof(object_store));
+
+	obj = &nv_objects[object_type];
+
+	field = &obj->fields[0];
+
+	while (field->name != NULL) {
+		if (field->offset == offset) {
+			break;
+		}
+
+		field ++;
+	}
+
+	if (field->name == NULL) {
+		if (obj->name == NULL) {
+			memset(buf+pos, ' ', 20); pos += 20;
+			pos += snprintf(buf+pos, BUFSIZ-pos, "NvType0%03x", object_type);
+		} else {
+			pos += snprintf(buf+pos, BUFSIZ-pos, "%30s", obj->name);
+		}
+		memset(buf+pos, ' ', 6); pos += 6;
+
+		pos += snprintf(buf+pos, BUFSIZ-pos, "[0x%04x/4] = ", offset);
+	} else {
+		pos += snprintf(buf+pos, BUFSIZ-pos, "%45s = ", obj->name);
+	}
+
+	data_print_store* dp = &field->data[0];
+
+	if (dp[0].func == NULL) {
+		dp = user_data_print;
+	}
+
+	int i;
+	for (i = 0; dp[i].func != NULL; i++) {
+		if (i != 0) {
+			strncpy(buf+pos, " | ", 3);
+			pos += 3;
+		}
+		const char *str = dp[i].func(
+				(value >> dp[i].lowbit) & (0xFFFFFFFF >> (31-dp[i].highbit + dp[i].lowbit)),
+				dp[i].data);
+
+		strncpy(buf+pos, str, BUFSIZ-pos);
+		pos += strlen(str);
+	}
+
+	return buf;
+}
+
Index: objects.h
===================================================================
RCS file: objects.h
diff -N objects.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ objects.h	12 Jun 2006 11:31:06 -0000
@@ -0,0 +1,38 @@
+typedef const char* (*PrintFunc)(unsigned int value, void*data);
+const char* print_format(unsigned int value, void*format);
+const char* print_float(unsigned int value, void*format);
+
+typedef struct {
+	unsigned int id;
+	const char* name;
+} data_store;
+
+typedef struct {
+	int lowbit;
+	int highbit;
+
+	PrintFunc func;
+	void *data;
+} data_print_store;
+
+typedef struct {
+	unsigned int offset;
+	const char* name;
+
+	// max 32 bits, so max 32 subfields
+	data_print_store data[32];
+} object_field_store;
+
+typedef struct {
+	unsigned int id;
+	const char *name;
+
+	// You can freely increase this array size, if it's full
+	object_field_store fields[100];
+} object_store;
+
+unsigned int find_object_type(unsigned int name);
+char *format_load(int object_type, int offset, unsigned int value);
+
+//required to be defined elesewhere:
+extern data_print_store user_data_print[];
Index: re.c
===================================================================
RCS file: /cvsroot/nouveau/renouveau/re.c,v
retrieving revision 1.39
diff -u -r1.39 re.c
--- re.c	5 Jun 2006 21:34:24 -0000	1.39
+++ re.c	12 Jun 2006 11:31:07 -0000
@@ -1,5 +1,4 @@
 #include "re.h"
-#include "cmds.h"
 #include "nv_hw.h"
 #include <unistd.h>
 #include <stdlib.h>
@@ -12,6 +11,7 @@
 #include <SDL/SDL_syswm.h>
 #include "NVCtrl.h"
 #include "NVCtrlLib.h"
+#include "objects.h"
 
 #define MAPFILE "maplist.txt"
 
@@ -46,12 +46,6 @@
 }
 dmarec;
 
-typedef struct config_s
-{
-	int print_format;
-} 
-config_t;
-
 static mapping mappings[100];
 #define MAX_DMARECS 100
 static dmarec  dmarecs[MAX_DMARECS];
@@ -60,8 +54,6 @@
 
 static int init_ok=0;
 
-static config_t config;
-
 #if 0
 static long agp_base = 0xf0000000;
 static long agp_size = 128*1024*1024;
@@ -107,12 +99,17 @@
 	printf("\t-b\t\t\tPrint \"after\" values as bit pattern\n");
 }
 
+#define MAXPRINT 10
+data_print_store user_data_print[MAXPRINT];
+
 void parse_opts(int argc, char **argv)
 {
 	int c;
+	int i;
+
+	memset(user_data_print, 0, sizeof(data_print_store)*MAXPRINT);
+	int cur_pr = 0;
 
-	memset(&config, 0, sizeof(config_t));
-	
 	while ((c = getopt(argc, argv, "hfiscb")) != -1) {
 		switch (c) {
 			case '?':
@@ -122,21 +119,56 @@
 				print_usage(argv[0]);
 				exit(0);
 			case 'f':
-				config.print_format = config.print_format|PRINT_FP32;
+				user_data_print[cur_pr].lowbit = 0;
+				user_data_print[cur_pr].highbit = 31;
+				user_data_print[cur_pr].func = print_float;
+				user_data_print[cur_pr].data = "%f";
+				cur_pr++;
 				break;
 			case 'i':
-				config.print_format = config.print_format|PRINT_INTEGER;
+				user_data_print[cur_pr].lowbit = 0;
+				user_data_print[cur_pr].highbit = 31;
+				user_data_print[cur_pr].func = print_format;
+				user_data_print[cur_pr].data = "%d";
+				cur_pr++;
 				break;
 			case 's':
-				config.print_format = config.print_format|PRINT_16_BITS_INTEGER;
+				user_data_print[cur_pr].lowbit = 0;
+				user_data_print[cur_pr].highbit = 15;
+				user_data_print[cur_pr].func = print_format;
+				user_data_print[cur_pr].data = "%d";
+				cur_pr++;
+				user_data_print[cur_pr].lowbit = 16;
+				user_data_print[cur_pr].highbit = 31;
+				user_data_print[cur_pr].func = print_format;
+				user_data_print[cur_pr].data = "%d";
+				cur_pr++;
+//				config.print_format = config.print_format|PRINT_16_BITS_INTEGER;
 				break;
 			case 'c':
-				config.print_format = config.print_format|PRINT_8_BITS_INTEGER;
+				for (i = 0; i < 4; i++) {
+					user_data_print[cur_pr].lowbit = 0 + 8*i;
+					user_data_print[cur_pr].highbit = 7 + 8*i;
+					user_data_print[cur_pr].func = print_format;
+					user_data_print[cur_pr].data = "%d";
+					cur_pr++;
+				}
 				break;
 			case 'b':
-				config.print_format = config.print_format|PRINT_BIT_PATTERN;
+#warning FIXME
+//				config.print_format = config.print_format|PRINT_BIT_PATTERN;
+				break;
 		}
 	}
+
+	if (cur_pr == 0) {
+		user_data_print[cur_pr].lowbit = 0;
+		user_data_print[cur_pr].highbit = 31;
+		user_data_print[cur_pr].func = print_format;
+		user_data_print[cur_pr].data = "0x%08x";
+		cur_pr++;
+	}
+
 }
 
 static int must_ignore(int r)
@@ -194,18 +226,22 @@
 	// first, figure out the physical adress for the regs
 	char s[1024];
 	#define TMPFILE "regtmp.txt"
-	sprintf(s,"cat /proc/bus/pci/devices |grep nvidia |tail -1 > "TMPFILE);
+	sprintf(s,"cat /proc/bus/pci/devices |grep nvidia |head -1 > "TMPFILE);
 	system(s);
 	FILE* f=fopen(TMPFILE,"r");
 	fgets(s,1024,f);
 	unsigned phys_addr,card_id,dum;
-	int ok=(sscanf(s,"%hx %x %x %x",&dum, &card_id, &dum, &phys_addr) == 4);
+	int ok=(sscanf(s,"%x %x %x %x",&dum, &card_id, &dum, &phys_addr) == 4);
 	fclose(f);
 	system("rm -f "TMPFILE);
 	// now we can map it
 	int fd;
 	fd=open("/dev/nvidia0",O_RDWR);
 	all_regs=mmap(NULL, ALL_REGS_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, phys_addr);
+	if (all_regs == MAP_FAILED) {
+		perror("mmap");
+		exit(1);
+	}
 	close(fd);
 	// now figure out the card family
 	switch(card_id&0x0FF0)
@@ -342,7 +378,7 @@
 		system(s);
 		f = fopen(TMPFILE, "r");
 		fgets(s, 1024, f);
-		ok = (sscanf(s, "%x %x %x %x %x %x %x %x %x %x %x",
+		ok = (sscanf(s, "%x %x %x %lx %x %x %x %x %x %x %lx",
 				&dum, &dum, &dum,
 				&agp_base,
 				&dum, &dum, &dum, &dum, &dum, &dum,
@@ -351,7 +387,7 @@
 		system("rm -f "TMPFILE);
 		if (ok) {
 			agp_base &= ~8; // wtf is this?
-			printf("AGP aperture @ 0x%X, %dMB\n", agp_base, agp_size/1024/1024);
+			printf("AGP aperture @ 0x%lX, %ldMB\n", agp_base, agp_size/1024/1024);
 		} else {
 			agp_base = agp_size = 0;
 			printf("Couldn't determine address of AGP aperture\n");
@@ -428,98 +464,6 @@
     printf("%x   0x%.8x   0x%.8x   ", n, before, after);
 }
 
-void print_formated_fifo (int n, int before, int after, unsigned int cmd)
-{
-    int print = cmd_format(cmd);
-    printf("%x   0x%.8x   0x%.8x  ", n, before, after);
-
-    if (print)
-    {
-        if (print&PRINT_USER && config.print_format)
-            print = config.print_format;
-
-        if (print&PRINT_FP32)
-            printf("(FP32: %f)  ", *(float *) &after);
-        if (print&PRINT_INTEGER)
-            printf("(INTEGER: %d)  ", after);
-        if (print&PRINT_8_BITS_INTEGER)
-        {
-            unsigned int first = (after&0xff000000)>>24;
-            unsigned int second = (after&0x00ff0000)>>16;
-            unsigned int third = (after&0x0000ff00)>>8;
-            unsigned int fourth = (after&0x000000ff);
-            printf("(8 BITS INTEGER: %i | %i | %i | %i)  ", first, second, third, fourth);
-        }
-        if (print&PRINT_16_BITS_INTEGER)
-        {
-            unsigned int first = (after&0xffff0000)>>16;
-            unsigned int second = (after&0x0000ffff);
-            printf("(16 BITS INTEGER: %i | %i)  ", first, second);
-        }
-        if (print&PRINT_MACRO)
-        {
-            const char* name = data_name(cmd, after);
-            if (name)
-                printf("(MACRO: %s)  ", name);
-            else
-                printf("(MACRO: not found)  ");
-        }
-        if (print&PRINT_MACRO16)
-        {
-            const char* name = data_name(cmd, ((unsigned)after)>>16);
-            if (name)
-                printf("(MACRO16: %s | ", name);
-            else
-                printf("(MACRO16: not found | ");
-            name = data_name(cmd, after&0xffff);
-            if (name)
-                printf("%s)  ", name);
-            else
-                printf("not found)  ");
-        }
-        if (print&PRINT_FUNC)
-        {
-            PrintFunc func = data_func(cmd, after);
-            if (func) {
-                printf("(FUNC: ");
-                (func)(cmd, after);
-                printf(")  ");
-            } else {
-                printf("(FUNC: not found)  ");
-            }   
-        }
-		if (print & PRINT_BIT_PATTERN)
-		{
-			printf("(BITS: %s)  ", bit_pattern(after));
-		}
-        if (print&PRINT_VERTEX)
-        {
-            printf("(VERTEX ATTRIBUTE: ");
-            switch (after&0xf) {
-                case 2:
-                    printf("float, ");
-                    break;
-                case 4:
-                    printf("unsigned byte, ");
-                    break;
-                case 16:
-                    printf("float, ");
-                    break;
-                default:
-                    printf("unknow : %d, ", after&0xf);
-            }
-            printf("%d fields", (after>>4) & 0xf);
-            if (after&0xff00) {
-                if (after&0x300)
-                    printf(", stride : %d", (after>>8)&0xff);
-                else
-                    printf(", stride : 4*%d", ((after>>8)&0xff)>>2);
-            }
-            printf(")  ");
-        }
-    }
-}
-
 int smart_zero_remover(unsigned int value)
 {
     static int count = 0;
@@ -566,7 +510,7 @@
 	{
 		if (allregmapping_before[j]!=allregmapping_after[j])
 		{
-			printf("Changed reg 0x%.8x from 0x%.8x to 0x%.8x\n",ALLREG_START+(j<<2),allregmapping_before[j],allregmapping_after[j]);
+			printf("Changed reg 0x%.8x from 0x%.8lx to 0x%.8lx\n",ALLREG_START+(j<<2),allregmapping_before[j],allregmapping_after[j]);
 		}
 	}
 }
@@ -589,11 +533,25 @@
 	}
 }
 
+
+typedef struct {
+	unsigned int name;
+	unsigned int type;
+} fifo_descriptor;
+
+static fifo_descriptor fifo_channels[8];
+
+static void set_subchannel(int channel, unsigned int name) {
+	printf("mapped subchannel %d to %08x\n", channel, name);
+	fifo_channels[channel].name = name;
+	fifo_channels[channel].type = find_object_type(name);
+}
+
 void dump_after()
 {
 	int i,j;
-        unsigned int size, channel, cmd;
-        const char *name;
+        unsigned int size, channel, offset;
+//        const char *name;
         
 	// dump each mapping to its buffer
 	i=0;
@@ -666,6 +624,18 @@
 			{
 				printf("Changed from %d to %d   (%d words   %d bytes)\n",changed_from,changed_to,(changed_to-changed_from),(changed_to-changed_from)*4);
 
+				j = 0;
+				while (j < changed_from) {
+					size = (mappings[i].after[j] & 0x1ffc0000) >> 18;
+					channel = (mappings[i].after[j] & 0x0000e000) >> 13;
+					offset = mappings[i].after[j] & ~(size << 18 | channel << 13);
+					if (offset == 0 && size > 0) {
+						set_subchannel(channel, mappings[i].after[j+1]);
+					}
+
+					j += size + 1;
+				}
+
 				size = 0;
 				for(j=changed_from;j<changed_to || size;j++)
 				{
@@ -699,23 +669,27 @@
 							}
 							else
 							{
-								size = (mappings[i].after[j] & 0x0fff0000) >> 18;
-								channel = (mappings[i].after[j] & 0x00003000) >> 13;
-								cmd = mappings[i].after[j] & ~(size << 18 | channel << 13);
-								name = cmd_name(cmd);
-								printf("{size: 0x%x   channel: 0x%x   cmd: ", size, channel);
-								if (!name) printf("0x%.8x", cmd);
-								else printf("%s", name);
-								printf("}\n");
+								size = (mappings[i].after[j] & 0x1ffc0000) >> 18;
+								channel = (mappings[i].after[j] & 0x0000e000) >> 13;
+								offset = mappings[i].after[j] & ~(size << 18 | channel << 13);
+								printf("          {size: 0x%x   channel: 0x%x   obj: %08x}\n", size, channel, fifo_channels[channel].name);
 							}
 						}
 						else
 						{
-							print_formated_fifo(j, mappings[i].before[j], mappings[i].after[j], cmd);
+							if (offset == 0) {
+								set_subchannel(channel, mappings[i].after[j]);
+							}
+
+							print_fifo(j, mappings[i].before[j], mappings[i].after[j]);
+							if (offset != 0) {
+								printf(format_load(fifo_channels[channel].type, offset, mappings[i].after[j]));
+							}
 							printf("\n");
 							size--;
+							offset += 4;
 
-							int n;
+/*							int n;
 							if (cmd == MEMFORMAT_OFFSET_IN && size==7) {
 								for (n=0;(dmarecs[n].to != 0 && dmarecs[n].from != 0 && n<MAX_DMARECS);n++){}
 
@@ -734,6 +708,7 @@
 									}
 								}
 							}
+							*/
 
 						}
 					}
Index: re.h
===================================================================
RCS file: /cvsroot/nouveau/renouveau/re.h,v
retrieving revision 1.5
diff -u -r1.5 re.h
--- re.h	1 Jun 2006 21:16:39 -0000	1.5
+++ re.h	12 Jun 2006 11:31:07 -0000
@@ -11,6 +11,7 @@
 void disasm_fp(int addr);
 
 extern unsigned int card_family;
+extern unsigned int* all_regs;
 
 #endif
 
Index: texture.c
===================================================================
RCS file: /cvsroot/nouveau/renouveau/texture.c,v
retrieving revision 1.2
diff -u -r1.2 texture.c
--- texture.c	28 May 2006 10:19:01 -0000	1.2
+++ texture.c	12 Jun 2006 11:31:08 -0000
@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include "cmds.h"
+#include "nv40_reg.h"
 
 static int texop_id = 0;
 
