aboutsummaryrefslogtreecommitdiff
path: root/examples/system/tty
diff options
context:
space:
mode:
authorJohn Wilbert M. Villamor <lameguy64@gmail.com>2020-04-24 19:01:28 +0800
committerJohn Wilbert M. Villamor <lameguy64@gmail.com>2020-04-24 19:01:28 +0800
commit1aa0e17df7c325a41de8cf8a57f52ed853f08bf3 (patch)
tree5ec7f69ca0104f2b0a41e2ee7d3cb0cf0c9c54c5 /examples/system/tty
parente82da2abe4c264d4b48a48d79cf9b8e4c4fb8ab6 (diff)
downloadpsn00bsdk-1aa0e17df7c325a41de8cf8a57f52ed853f08bf3.tar.gz
Refined toolchain instructions, organized examples, added automatic retry for CdRead(), added FIOCSCAN ioctl in psxsio TTY driver, added tty and console examples.
Diffstat (limited to 'examples/system/tty')
-rw-r--r--examples/system/tty/main.c145
-rw-r--r--examples/system/tty/makefile60
2 files changed, 205 insertions, 0 deletions
diff --git a/examples/system/tty/main.c b/examples/system/tty/main.c
new file mode 100644
index 0000000..8333746
--- /dev/null
+++ b/examples/system/tty/main.c
@@ -0,0 +1,145 @@
+/*
+ * LibPSn00b Example Programs
+ *
+ * Teletype Example
+ * 2020 Meido-Tek Productions / PSn00bSDK Project
+ *
+ * This example showcases the uses of tty through stdio facilities. If you've
+ * written text console applications before, this one is not too dissimilar to
+ * that. Escape codes for formatting and such should work as this is more
+ * dependant on the terminal program used than the PS1 console itself.
+ *
+ *
+ * Example by Lameguy64
+ *
+ * Changelog:
+ *
+ * April 23, 2020 - Initial version.
+ *
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <psxgpu.h>
+
+/* Memory viewer thing, you may use this in your own applications
+ * for testing or analysis */
+void memory_browser(unsigned int addr)
+{
+ int i,j,key;
+ unsigned char *ptr,*pptr;
+
+ while(1)
+ {
+ /* Set cursor position to top-left */
+ printf("\033[1;1H");
+ printf("MEMVIEW 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF");
+
+ ptr = (unsigned char*)addr;
+
+ /* Print contents from current location of memory */
+ for(j=0; j<23; j++)
+ {
+ printf("\n%04X: ", (unsigned int)ptr);
+ pptr = ptr;
+ for(i=0; i<16; i++)
+ {
+ printf("%02X ", *ptr);
+ ptr++;
+ }
+ printf(" ");
+ for(i=0; i<16; i++)
+ {
+ if(( *pptr < 32 ) || ( *pptr > 127 ) )
+ {
+ printf(".");
+ }
+ else
+ {
+ printf("%c", *pptr);
+ }
+ pptr++;
+ }
+ }
+
+ /* Parse input */
+ while(1)
+ {
+ key = getchar();
+ if( key == 0x1B )
+ {
+ key = getchar();
+
+ if( key == 0x5B )
+ {
+ key = getchar();
+ if( key == 0x41 ) // Up
+ {
+ addr -= 16;
+ break;
+ }
+ else if( key == 0x42 ) // Down
+ {
+ addr += 16;
+ break;
+ }
+ if( key == 0x35 ) // Page up
+ {
+ addr -= 16*23;
+ break;
+ }
+ else if( key == 0x36 ) // Page down
+ {
+ addr += 16*23;
+ break;
+ }
+ }
+ }
+
+ }
+ }
+
+}
+
+
+int main(int argc, const char *argv[])
+{
+ int i;
+ char strbuff[32];
+
+ /* Mostly to get interrupts going for this example */
+ ResetGraph( 0 );
+
+ /* Uncomment if you don't have an environment that provides tty access
+ * by default */
+ //AddSIO(115200);
+
+ /* A standby loop until 'Y' is entered */
+ while(1)
+ {
+ /* Print banner */
+ printf("Hello world!\n");
+ printf("Press 'Y' to proceed with this demonstration.\n");
+
+ /* Get input for a Y character */
+ i = getchar();
+ if( tolower(i) == 'y' )
+ break;
+ }
+
+ /* Do a classic text input prompt and display the inputted text */
+ printf("Enter a string, any string (no more than 32 characters):\n");
+ gets(strbuff);
+
+ printf("You've entered: %s\n\n", strbuff);
+
+ /* Prompt entering into the memory browser */
+ printf("Press a key to enter a memory browser demo...\n");
+ printf("Make sure your terminal or text console supports vt100 escape codes!\n");
+ getchar();
+
+ /* Start the memory browser interface */
+ memory_browser(0x80010000);
+
+ return 0;
+}
diff --git a/examples/system/tty/makefile b/examples/system/tty/makefile
new file mode 100644
index 0000000..a3884ad
--- /dev/null
+++ b/examples/system/tty/makefile
@@ -0,0 +1,60 @@
+include ../../sdk-common.mk
+
+# Project target name
+TARGET = tty.elf
+
+# Searches for C, C++ and S (assembler) files in local directory
+CFILES = $(notdir $(wildcard *.c))
+CPPFILES = $(notdir $(wildcard *.cpp))
+AFILES = $(notdir $(wildcard *.s))
+
+# Determine object files
+OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
+ $(addprefix build/,$(CPPFILES:.cpp=.o)) \
+ $(addprefix build/,$(AFILES:.s=.o))
+
+# Project specific include and library directories
+# (use -I for include dirs, -L for library dirs)
+INCLUDE +=
+LIBDIRS +=
+
+# Libraries to link
+LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc
+
+# C compiler flags
+CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
+
+# C++ compiler flags
+CPPFLAGS = $(CFLAGS) -fno-exceptions
+
+# Assembler flags
+AFLAGS = -g -msoft-float
+
+# Linker flags
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
+ -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+
+# Toolchain programs
+CC = $(PREFIX)gcc
+CXX = $(PREFIX)g++
+AS = $(PREFIX)as
+LD = $(PREFIX)ld
+
+all: $(OFILES)
+ $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
+ elf2x -q $(TARGET)
+
+build/%.o: %.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+build/%.o: %.cpp
+ @mkdir -p $(dir $@)
+ $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@
+
+build/%.o: %.s
+ @mkdir -p $(dir $@)
+ $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@
+
+clean:
+ rm -rf build $(TARGET) $(TARGET:.elf=.exe)