cleanup: remove cpu ctrl files, move tests
[gpsp.git] / gp2x / test / align_test.c
diff --git a/gp2x/test/align_test.c b/gp2x/test/align_test.c
new file mode 100644 (file)
index 0000000..b7b3512
--- /dev/null
@@ -0,0 +1,48 @@
+// Betting on GCC aligning this for efficiency.\r
+#include <stdio.h>\r
+\r
+int main()\r
+{\r
+  unsigned short int read_16 = 0xF1F2;\r
+  unsigned int read_32 = 0xF1F2F3F4;\r
+\r
+  unsigned short int write_16 = 0xF00D;\r
+  unsigned int write_32 = 0xF00DFEED;\r
+  // 16bit unsigned reads, we expect 0xF1F2 and 0xF20000F1\r
+  fprintf(stderr, "%04x %04x\n",\r
+   *((unsigned short int *)((char *)&read_16)),\r
+   *((unsigned short int *)((char *)&read_16 + 1)));\r
+\r
+  // 16bit signed reads, we expect 0xFFFFF1F2 and 0xFFFFFFF1\r
+  fprintf(stderr, "%04x %04x\n",\r
+   *((short int *)((char *)&read_16)),\r
+   *((short int *)((char *)&read_16 + 1)));\r
+\r
+  // 32bit reads, we expect 0xF1F2F3F4, 0xF4F1F2F3, 0xF3F4F1F2,\r
+  // and 0xF2F3F4F1\r
+\r
+  fprintf(stderr, "%08x %08x %08x %08x\n",\r
+   *((int *)((char *)&read_32)),\r
+   *((int *)((char *)&read_32 + 1)),\r
+   *((int *)((char *)&read_32 + 2)),\r
+   *((int *)((char *)&read_32 + 3)));\r
+\r
+  // 16bit writes, we expect write_16 to remain 0xF00D\r
+\r
+  *((short int *)((char *)&write_16)) = 0xF00D;\r
+  *((short int *)((char *)&write_16) + 1) = 0xF00D;\r
+\r
+  fprintf(stderr, "%04x\n", write_16);\r
+\r
+  // 32bit writes, we expect write_32 to remain 0xF00DFEED\r
+\r
+  *((int *)((char *)&write_16)) = 0xF00DFEED;\r
+  *((int *)((char *)&write_16) + 1) = 0xF00DFEED;\r
+  *((int *)((char *)&write_16) + 2) = 0xF00DFEED;\r
+  *((int *)((char *)&write_16) + 3) = 0xF00DFEED;\r
+\r
+  fprintf(stderr, "%08x\n", write_32);\r
+\r
+  return 0;\r
+}\r
+\r