summaryrefslogtreecommitdiff
path: root/examples/memview
diff options
context:
space:
mode:
authorXavi Del Campo <xavi.dcr@tutanota.com>2020-01-31 10:32:23 +0100
committerXavi Del Campo <xavi.dcr@tutanota.com>2020-01-31 10:32:23 +0100
commit7c24e9a9b02b04dcaf9507acb94091ea70a2c02d (patch)
treec28d0748652ad4b4222309e46e6cfc82c0906220 /examples/memview
parenta2b7b6bb1cc2f4a3258b7b2dbc92399d151f864d (diff)
downloadpsxsdk-7c24e9a9b02b04dcaf9507acb94091ea70a2c02d.tar.gz
Imported pristine psxsdk-20190410 from official repo
Diffstat (limited to 'examples/memview')
-rw-r--r--examples/memview/Makefile7
-rw-r--r--examples/memview/memview.c249
-rw-r--r--examples/memview/memview.txt70
3 files changed, 326 insertions, 0 deletions
diff --git a/examples/memview/Makefile b/examples/memview/Makefile
new file mode 100644
index 0000000..55f05eb
--- /dev/null
+++ b/examples/memview/Makefile
@@ -0,0 +1,7 @@
+PROJNAME = memview
+
+include ../project.mk
+
+$(PROJNAME)_extra:
+
+$(PROJNAME)_clean_extra:
diff --git a/examples/memview/memview.c b/examples/memview/memview.c
new file mode 100644
index 0000000..bf2e04a
--- /dev/null
+++ b/examples/memview/memview.c
@@ -0,0 +1,249 @@
+/**
+ * PlayStation Memory Viewer
+ * by Giuseppe Gatta a.k.a. nextvolume
+ *
+ * PSXSDK Example - released to the Public Domain
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <psx.h>
+
+unsigned int cur_addr = 0x80000000;
+unsigned int prim_list[0x20000];
+
+int display_is_old = 1;
+volatile int should_read_pad = 1;
+
+void pshex_vblank_handler()
+{
+ should_read_pad = 1;
+}
+
+int main()
+{
+ unsigned short padbuf;
+ int y, f, x, x1;
+ int highres_mode=0;
+ int srp=0;
+ int wasup=0, wasdown=0, wasleft=0, wasright=0, wasl1=0, wasr1=0,
+ wasl2=0;
+ int wascross=0, wascircle=0, wasstart=0,wasselect=0;
+ unsigned int go_address = 0x80000000;
+ int go_pos = 0;
+ GsRectangle pshex_rect;
+
+
+ PSX_InitEx(0);
+
+ GsInit();
+ GsClearMem();
+
+ GsSetVideoMode(640, 240, VMODE_PAL);
+ GsSetList(prim_list);
+ GsSetDispEnvSimple(0, 0);
+ GsSetDrawEnvSimple(0, 0, 640, 240);
+ GsLoadFont(768, 0, 768, 256);
+
+ SetVBlankHandler(pshex_vblank_handler);
+
+ GsPrintFont(16, 16, "PAL/NTSC SELECTION");
+ GsPrintFont(16, 32, "X - PAL");
+ GsPrintFont(16, 40, "O - NTSC");
+ GsDrawList();
+ while(GsIsDrawing());
+
+ while(1)
+ {
+ if(should_read_pad)
+ {
+ PSX_ReadPad(&padbuf, NULL);
+
+ if((padbuf & PAD_CROSS))
+ {
+ GsSetVideoModeEx(640, 480, VMODE_PAL, 0, 1, 0);
+ wascross=1;
+ break;
+ }
+
+ if((padbuf & PAD_CIRCLE))
+ {
+ GsSetVideoModeEx(640, 480, VMODE_NTSC, 0, 1, 0);
+ wascircle=1;
+ break;
+ }
+
+ should_read_pad=0;
+ }
+ }
+
+ GsSetDrawEnvSimple(0, (GsScreenM==VMODE_PAL?8:0), 640, 480);
+
+ while(1)
+ {
+ if(display_is_old)
+ {
+ GsSortCls(0, 0, 255);
+
+ for(y = 0; y < (highres_mode?58:28); y++)
+ {
+ f = GsPrintFont(24, y*8, "%08x", cur_addr + (y*0x10));
+ x1 = prfont_get_fx(f) + 16;
+
+ for(x = 0; x < 16; x++)
+ {
+ if(( (x&3) == 0) && x>0)
+ x1+=16;
+
+ f = GsPrintFont(x1, y*8, "%02x", *((unsigned char*)(cur_addr + (y*0x10) + x)));
+ x1 = prfont_get_fx(f) + 8;
+ }
+
+ x1+=8;
+
+ for(x=0;x<16;x++)
+ {
+ GsPrintFont(x1, y*8, "%c", *((unsigned char*)(cur_addr + (y*0x10) + x)));
+ x1+=8;
+ }
+ }
+
+ pshex_rect.x = (go_pos * 8)+24;
+ pshex_rect.y = highres_mode?472:232;
+ pshex_rect.r = 255;
+ pshex_rect.g = 69;
+ pshex_rect.b = 0;
+ pshex_rect.attribute = 0;
+ pshex_rect.w = 8;
+ pshex_rect.h = 8;
+ GsSortRectangle(&pshex_rect);
+
+ GsPrintFont(24, highres_mode?472:232, "%08X", go_address);
+
+ GsDrawList();
+ while(GsIsDrawing());
+ display_is_old = 0;
+ }
+
+ if(should_read_pad)
+ {
+ PSX_ReadPad(&padbuf, NULL);
+
+ if((padbuf & PAD_UP) && !wasup)
+ {
+ cur_addr -= 0x10;
+ display_is_old = 1;
+ wasup = 1;
+ }
+
+ if((padbuf & PAD_DOWN) && !wasdown)
+ {
+ cur_addr += 0x10;
+ display_is_old = 1;
+ wasdown = 1;
+ }
+
+ if((padbuf & PAD_LEFT) && !wasleft)
+ {
+ cur_addr -= 0x100;
+ display_is_old = 1;
+ wasleft=1;
+ }
+
+ if((padbuf & PAD_RIGHT) && !wasright)
+ {
+ cur_addr += 0x100;
+ display_is_old = 1;
+ wasright=1;
+ }
+
+ if((padbuf & PAD_L1) && !wasl1)
+ {
+ if(go_pos>0)go_pos--;
+ display_is_old = 1;
+ wasl1=1;
+ }
+
+ if((padbuf & PAD_R1) && !wasr1)
+ {
+ if(go_pos<7)go_pos++;
+ display_is_old = 1;
+ wasr1=1;
+ }
+
+ if((padbuf & PAD_L2) && !wasl2)
+ {
+ go_pos = 0;
+ wasl2 = 1;
+ }
+
+ if((padbuf & PAD_CROSS) && !wascross)
+ {
+ if(((go_address >> ((7-go_pos)<<2))&0xf) < 0xf)
+ go_address += 1 << ((7-go_pos)<<2);
+
+ display_is_old = 1;
+ wascross=1;
+ }
+
+ if((padbuf & PAD_CIRCLE) && !wascircle)
+ {
+ if(((go_address >> ((7-go_pos)<<2))&0xf) > 0)
+ go_address -= 1 << ((7-go_pos)<<2);
+
+ display_is_old = 1;
+ wascircle = 1;
+ }
+
+ if((padbuf & PAD_START) && !wasstart)
+ {
+ cur_addr = go_address;
+ display_is_old = 1;
+ wasstart=1;
+ }
+
+ if((padbuf & PAD_SELECT) && !wasselect)
+ {
+ highres_mode = !highres_mode;
+
+ GsSortCls(0,0,255);
+ GsDrawList();
+ while(GsIsDrawing());
+
+ if(highres_mode)
+ {
+ GsSetVideoModeEx(640, 480, GsScreenM, 0, 1, 0);
+ GsSetDrawEnvSimple(0, (GsScreenM==VMODE_PAL)?8:0, 640, 480);
+ }
+ else
+ {
+ GsSetVideoMode(640, 240, GsScreenM);
+ GsSetDrawEnvSimple(0, (GsScreenM==VMODE_PAL)?8:0, 640, 240);
+ }
+
+ display_is_old = 1;
+ wasselect = 1;
+ }
+
+ if(!(padbuf & PAD_UP) || srp==5)wasup=0;
+ if(!(padbuf & PAD_DOWN) || srp==5)wasdown=0;
+ if(!(padbuf & PAD_LEFT) || srp==5)wasleft=0;
+ if(!(padbuf & PAD_RIGHT) || srp==5)wasright=0;
+ if(!(padbuf & PAD_L1))wasl1=0;
+ if(!(padbuf & PAD_R1))wasr1=0;
+ if(!(padbuf & PAD_L2))wasl2=0;
+ if(!(padbuf & PAD_CROSS) || srp==5)wascross=0;
+ if(!(padbuf & PAD_CIRCLE) || srp==5)wascircle=0;
+ if(!(padbuf & PAD_START)) wasstart=0;
+ if(!(padbuf & PAD_SELECT)) wasselect=0;
+
+ should_read_pad = 0;
+ srp++;
+ if(srp > 5) srp=0;
+ }
+ }
+}
+
+//AAAAAAAA 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF abcd
diff --git a/examples/memview/memview.txt b/examples/memview/memview.txt
new file mode 100644
index 0000000..dd21b57
--- /dev/null
+++ b/examples/memview/memview.txt
@@ -0,0 +1,70 @@
+This is a simple memory viewer for the PlayStation.
+It shows you what is contained at the desired memory addresses in a way similar to that of hex editors.
+
+Obviously it is not as straigthforward to use as similar programs for general purpose computers because the PlayStation lacks a keyboard.
+Also, *remember* that reading certain memory areas will crash the PlayStation hardware, and if that happens the only thing you can do is to reset the console.
+See "Surefire Areas" below for areas which surely won't crash your hardware.
+
+At start, the memory viewer will begin viewing memory at 0x80000000 (start of RAM),
+the resolution will be 640x240 (low-res) and the Go-Address will be 0x80000000.
+
+Terms:
+Go-Address The address that will be used for the
+ "jump-to address" operation
+
+Control:
+UP Decrease current address by 0x10
+DOWN Increase current address by 0x10
+LEFT Decrease current address by 0x100
+RIGHT Increase current address by 0x100
+
+L1 Move to previous location in Go-Address
+R1 Move to next location in Go-Address
+L2 Move to first location in Go-Address
+CROSS Increase nibble at current Go-Address location
+CIRCLE Decrease nibble at current Go-Address location
+
+START Jump to Go-Address,
+ i.e. make the Go-Address the current address
+
+SELECT Switch between hi-res and low-res mode
+ Hi-res mode: 640x480
+ Low-res mode: 640x240 (default)
+
+Surefire areas:
+0x80000000-0x801fffff PlayStation RAM (2 megabytes)
+0xbfc00000-0xbfc7ffff PlayStation BIOS ROM (512 kilobytes)
+
+Example of setting a Go-Address and jumping:
+
+Imagine that the current go-address is 0x80000000 and we want to jump to 0xC001D00D.
+NOTE: A nibble is 4-bits long, and each digit in a hexadecimal number is a nibble.
+
+- Move to the first location in Go-Address -> L2
+- Increase the nibble at current Go-Address location until it is 0xC
+ -> as its current value is 0x8, due to the current go-address being 0x80000000,
+ press CROSS 4 times
+ >> after this operation, the current address is 0xC0000000
+- Move to the next location in Go-Address -> R1
+- The nibble at this location is already 0x0, so move to the next location -> R1
+ >> after this operation, the current address is 0xC0000000
+- The nibble at this location is already 0x0, so move to the next location -> R1
+ >> after this operation, the current address is 0xC0000000
+- Increase the nibble at current Go-Address location until it is 0x1
+ -> as its current value is 0x0, press CROSS once
+ >> after this operation, the current address will be 0xC0010000
+- Move to the next location in Go-Address -> R1
+- Increase the nibble at current Go-Address location until it is 0xD
+ -> as its current value is 0x0, press CROSS 13 times
+ >> after this operation, the current address will be 0xC001D000
+- Move to the next location in Go-Address -> R1
+- The nibble at this location is already 0x0, so move to the next location -> R1
+ >> after this operation, the current address is 0xC001D000
+- The nibble at this location is already 0x0, so move to the next location -> R1
+ >> after this operation, the current address is 0xC001D000
+- Increase the nibble at current Go-Address location until it is 0xD
+ -> as its current value is 0x0, press CROSS 13 times
+ >> after this operation, the current address will be 0xC001D00D
+- Jump to Go-Address -> START
+ >> The current address is now 0xC001D00D
+