Permalink
Browse files

Add psvDebug, Ctrl, Touch samples (#5)

* Fix invalid build.sh directory

The net/http sample were not built since the net/ directory were mistaken for a sample directory

* Update and move build_all instruction into the README

* Move shared function into a common folder

* Rename psvDebugScreen* header file to debugScreen

* Rewrite debugScreen.h function to match libC prototypes

* Add basic psvDebugScreenPrintf sample

* add VT100 support and demo

* Unify Makefiles

* Add Ctrl Sample

* Add touch sample

* Add RTC sample
  • Loading branch information...
1 parent a2c2822 commit 19f7f0dda2b86fcbb72e5ebb9ac15bec7275db95 @yne yne committed with xyzz Aug 18, 2016
View
@@ -1,13 +1,32 @@
# vitasdk code samples
-Every directory contains a single sample. To build all samples, add the toolchain `bin/` directory to your `$PATH`, then run `./build.sh`. To clean all samples, run `./clean.sh`. To build a single sample, `cd` to its directory and type `make`.
+## Prerequisites
-Always use the `*_debug.bat` (e.g. `run_homebrew_unity_debug.bat`) launcher to get debug output from Vita.
+In order to build a vita sample, you need to add the toolchain `bin/` directory to your `$PATH`.
-## List of samples
+## Building
-* `hello_world`: A minimal Makefile-based C project
-* `hello_cpp_world`: A minimal Makefile-based C++ project
+Every samples directories should contains a README file and a Makefile.
+To build a sample, place yourself into this directory and use the `make` command to build it.
+
+## Running
+
+To run a sample:
+- send the generated `.vpk` to your vita :
+ - start an FTP server on your vita (for example with VitaShell by pressing the select button)
+ - upload the vpk to the vita using Curl (for example `curl -T *.vpk ftp://192.168.12.34:1337/ux0:/`)
+ - if curl return `fatal: No names found, cannot describe anything` it mean that you are trying to overwrite a folder with a file, add a `/` to the end of your url to explain that you want to upload IN this folder
+- install the .vpk on your vita using a vpk installer (for example using the VitaShell by pressing the X button on the .vpk)
+- this will create a new folder in the `ux0:/app/` folder (it name depend on the .vpk)
+- for further upload, you can directly skip the .vpk upload/install part, and directly re-install your binary (eboot.bin) inside the created /app/ folder
+
+## Building everything
+
+Use the following command to build every samples
+
+```
+for f in */Makefile; do make -C ${f%/*} all; done
+```
## Notes
- icon0.png, startup.png and bg.png must be using indexed palettes.
View
@@ -1,9 +0,0 @@
-#!/bin/bash
-set -e
-
-for directory in */; do
- echo "Build '$directory'"
- cd $directory
- make
- cd ..
-done
View
@@ -1,9 +0,0 @@
-#!/bin/bash
-set -e
-
-for directory in */; do
- echo "Clean '$directory'"
- cd $directory
- make clean
- cd ..
-done
View
@@ -0,0 +1,168 @@
+#ifndef DEBUG_SCREEN_H
+#define DEBUG_SCREEN_H
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <inttypes.h>
+
+#include <psp2/display.h>
+#include <psp2/kernel/sysmem.h>
+#include <psp2/kernel/threadmgr.h>
+
+#include <debugScreenFont.c>
+
+#define SCREEN_WIDTH (960)
+#define SCREEN_HEIGHT (544)
+#define SCREEN_FB_WIDTH (960)
+#define SCREEN_FB_SIZE (2 * 1024 * 1024)
+#define SCREEN_FB_ALIGN (256 * 1024)
+#define SCREEN_GLYPH_W (8)
+#define SCREEN_GLYPH_H (8)
+
+#define COLOR_BLACK 0xFF000000
+#define COLOR_RED 0xFF0000FF
+#define COLOR_BLUE 0xFF00FF00
+#define COLOR_YELLOW 0xFF00FFFF
+#define COLOR_GREEN 0xFFFF0000
+#define COLOR_MAGENTA 0xFFFF00FF
+#define COLOR_CYAN 0xFFFFFF00
+#define COLOR_WHITE 0xFFFFFFFF
+#define COLOR_GREY 0xFF808080
+#define COLOR_DEFAULT_FG COLOR_WHITE
+#define COLOR_DEFAULT_BG COLOR_BLACK
+
+static int psvDebugScreenMutex; /*< avoid race condition when outputing strings */
+static uint32_t psvDebugScreenCoordX = 0;
+static uint32_t psvDebugScreenCoordY = 0;
+static uint32_t psvDebugScreenColorFg = COLOR_DEFAULT_FG;
+static uint32_t psvDebugScreenColorBg = COLOR_DEFAULT_BG;
+static SceDisplayFrameBuf psvDebugScreenFrameBuf = {
+ sizeof(SceDisplayFrameBuf), NULL, SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
+
+uint32_t psvDebugScreenSetFgColor(uint32_t color) {
+ uint32_t prev_color = psvDebugScreenColorFg;
+ psvDebugScreenColorFg = color;
+ return prev_color;
+}
+
+uint32_t psvDebugScreenSetBgColor(uint32_t color) {
+ uint32_t prev_color = psvDebugScreenColorBg;
+ psvDebugScreenColorBg = color;
+ return prev_color;
+}
+
+static size_t psvDebugScreenEscape(const char *str){
+ int i,j, p=0, params[8]={};
+ for(i=0; i<8 && str[i]!='\0'; i++){
+ if(str[i] >= '0' && str[i] <= '9'){
+ params[p]=(params[p]*10) + (str[i] - '0');
+ }else if(str[i] == ';'){
+ p++;
+ }else if(str[i] == 'f' || str[i] == 'H'){
+ psvDebugScreenCoordX = params[0] * SCREEN_GLYPH_W;
+ psvDebugScreenCoordY = params[1] * SCREEN_GLYPH_H;
+ break;
+ }else if (str[i] == 'm'){
+ for(j=0; j<=p; j++){
+ switch(params[j]/10){/*bold,dim,underline,blink,invert,hidden => unsupported yet */
+ #define BIT2BYTE(bit) ( ((!!(bit&4))<<23) | ((!!(bit&2))<<15) | ((!!(bit&1))<<7) )
+ case 0:psvDebugScreenSetFgColor(COLOR_DEFAULT_FG);psvDebugScreenSetBgColor(COLOR_DEFAULT_BG);break;
+ case 3:psvDebugScreenSetFgColor(BIT2BYTE(params[j]%10));break;
+ case 9:psvDebugScreenSetFgColor(BIT2BYTE(params[j]%10) | 0x7F7F7F7F);break;
+ case 4:psvDebugScreenSetBgColor(BIT2BYTE(params[j]%10));break;
+ case 10:psvDebugScreenSetBgColor(BIT2BYTE(params[j]%10) | 0x7F7F7F7F);break;
+ #undef BIT2BYTE
+ }
+ }
+ break;
+ }
+ }
+ return i;
+}
+
+int psvDebugScreenInit() {
+ psvDebugScreenMutex = sceKernelCreateMutex("log_mutex", 0, 0, NULL);
+ SceUID displayblock = sceKernelAllocMemBlock("display", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, SCREEN_FB_SIZE, NULL);
+ sceKernelGetMemBlockBase(displayblock, (void**)&psvDebugScreenFrameBuf.base);
+
+ SceDisplayFrameBuf framebuf = {
+ .size = sizeof(framebuf),
+ .base = psvDebugScreenFrameBuf.base,
+ .pitch = SCREEN_WIDTH,
+ .pixelformat = SCE_DISPLAY_PIXELFORMAT_A8B8G8R8,
+ .width = SCREEN_WIDTH,
+ .height = SCREEN_HEIGHT,
+ };
+
+ return sceDisplaySetFrameBuf(&framebuf, SCE_DISPLAY_SETBUF_NEXTFRAME);
+}
+
+void psvDebugScreenClear(int bg_color){
+ psvDebugScreenCoordX = psvDebugScreenCoordY = 0;
+ int i;
+ for(i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) {
+ ((uint32_t*)psvDebugScreenFrameBuf.base)[i] = bg_color;
+ }
+}
+
+int psvDebugScreenPuts(const char * text){
+ int c, i, j, l;
+ uint8_t *font;
+ uint32_t *vram_ptr;
+ uint32_t *vram;
+
+ sceKernelLockMutex(psvDebugScreenMutex, 1, NULL);
+
+ for (c = 0; text[c] != '\0' ; c++) {
+ if (psvDebugScreenCoordX + 8 > SCREEN_WIDTH) {
+ psvDebugScreenCoordY += SCREEN_GLYPH_H;
+ psvDebugScreenCoordX = 0;
+ }
+ if (psvDebugScreenCoordY + 8 > SCREEN_HEIGHT) {
+ psvDebugScreenClear(psvDebugScreenColorBg);
+ }
+ if (text[c] == '\n') {
+ psvDebugScreenCoordX = 0;
+ psvDebugScreenCoordY += SCREEN_GLYPH_H;
+ continue;
+ } else if (text[c] == '\r') {
+ psvDebugScreenCoordX = 0;
+ continue;
+ } else if ((text[c] == '\e') && (text[c+1] == '[')) { /* escape code (change color, position ...) */
+ c+=psvDebugScreenEscape(text+2)+2;
+ continue;
+ }
+
+ vram = ((uint32_t*)psvDebugScreenFrameBuf.base) + psvDebugScreenCoordX + psvDebugScreenCoordY * SCREEN_FB_WIDTH;
+
+ font = &psvDebugScreenFont[ (int)text[c] * 8];
+ for (i = l = 0; i < SCREEN_GLYPH_W; i++, l += SCREEN_GLYPH_W, font++) {
+ vram_ptr = vram;
+ for (j = 0; j < SCREEN_GLYPH_W; j++) {
+ if ((*font & (128 >> j))) *vram_ptr = psvDebugScreenColorFg;
+ else *vram_ptr = psvDebugScreenColorBg;
+ vram_ptr++;
+ }
+ vram += SCREEN_FB_WIDTH;
+ }
+ psvDebugScreenCoordX += SCREEN_GLYPH_W;
+ }
+
+ sceKernelUnlockMutex(psvDebugScreenMutex, 1);
+ return c;
+}
+
+int psvDebugScreenPrintf(const char *format, ...) {
+ char buf[512];
+
+ va_list opt;
+ va_start(opt, format);
+ int ret = vsnprintf(buf, sizeof(buf), format, opt);
+ psvDebugScreenPuts(buf);
+ va_end(opt);
+
+ return ret;
+}
+
+#endif
@@ -12,7 +12,7 @@
* $Id: font.c 540 2005-07-08 19:35:10Z warren $
*/
-unsigned char msx[]=
+unsigned char psvDebugScreenFont[]=
"\x00\x00\x00\x00\x00\x00\x00\x00\x3c\x42\xa5\x81\xa5\x99\x42\x3c"
"\x3c\x7e\xdb\xff\xff\xdb\x66\x3c\x6c\xfe\xfe\xfe\x7c\x38\x10\x00"
"\x10\x38\x7c\xfe\x7c\x38\x10\x00\x10\x38\x54\xfe\x54\x10\x38\x00"
View
@@ -0,0 +1,55 @@
+PHONY := all package clean
+rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
+
+CC := arm-vita-eabi-gcc
+CXX := arm-vita-eabi-g++
+STRIP := arm-vita-eabi-strip
+
+PROJECT_TITLE := VitaSDK sample
+PROJECT_TITLEID := VSDK00001
+
+PROJECT := vita_sample
+CXXFLAGS += -std=c++11 -I../common
+CFLAGS += -I../common
+
+LIBS := -lSceDisplay_stub -lSceCtrl_stub
+
+SRC_C :=$(call rwildcard, src/, *.c)
+SRC_CPP :=$(call rwildcard, src/, *.cpp)
+
+OBJ_DIRS := $(addprefix out/, $(dir $(SRC_C:src/%.c=%.o))) $(addprefix out/, $(dir $(SRC_CPP:src/%.cpp=%.o)))
+OBJS := $(addprefix out/, $(SRC_C:src/%.c=%.o)) $(addprefix out/, $(SRC_CPP:src/%.cpp=%.o))
+
+
+all: package
+
+package: $(PROJECT).vpk
+
+$(PROJECT).vpk: eboot.bin param.sfo
+ vita-pack-vpk -s param.sfo -b eboot.bin $(PROJECT).vpk
+
+eboot.bin: $(PROJECT).velf
+ vita-make-fself $(PROJECT).velf eboot.bin
+
+param.sfo:
+ vita-mksfoex -s TITLE_ID="$(PROJECT_TITLEID)" "$(PROJECT_TITLE)" param.sfo
+
+$(PROJECT).velf: $(PROJECT).elf
+ $(STRIP) -g $<
+ vita-elf-create $< $@
+
+$(PROJECT).elf: $(OBJS)
+ $(CXX) -Wl,-q $(CFLAGS) -o $@ $^ $(LIBS)
+
+$(OBJ_DIRS):
+ mkdir -p $@
+
+out/%.o : src/%.cpp | $(OBJ_DIRS)
+ arm-vita-eabi-g++ -c $(CXXFLAGS) -o $@ $<
+
+out/%.o : src/%.c | $(OBJ_DIRS)
+ arm-vita-eabi-g++ -c $(CFLAGS) -o $@ $<
+
+clean:
+ rm -f $(PROJECT).velf $(PROJECT).elf $(PROJECT).vpk param.sfo eboot.bin $(OBJS)
+ rm -r $(abspath $(OBJ_DIRS))
View
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <psp2/kernel/processmgr.h>
+#include <psp2/ctrl.h>
+
+#include "debugScreen.h"
+
+#define printf psvDebugScreenPrintf
+
+int main(int argc, char *argv[]) {
+ psvDebugScreenInit();
+ printf("input test\n");
+ printf("press Select+Start+L+R to stop\n");
+ /* to enable analog sampling */
+ sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);
+
+ SceCtrlData ctrl;
+ const char* btn_label[]={"SELECT ","","","START ",
+ "UP ","RIGHT ","DOWN ","LEFT ","L ","R ","","",
+ "TRIANGLE ","CIRCLE ","CROSS ","SQUARE "};
+ do{
+ sceCtrlPeekBufferPositive(0, &ctrl, 1);
+ printf("Buttons:%08X == ", ctrl.buttons);
+ int i;
+ for(i=0; i < sizeof(btn_label)/sizeof(*btn_label); i++){
+ printf("\e[9%im%s",(ctrl.buttons & (1<<i)) ? 7 : 0, btn_label[i]);
+ }
+ printf("\e[m Stick:[%3i:%3i][%3i:%3i]\r", ctrl.lx,ctrl.ly, ctrl.rx,ctrl.ry);
+ }while(ctrl.buttons != (SCE_CTRL_START | SCE_CTRL_SELECT | SCE_CTRL_LTRIGGER | SCE_CTRL_RTRIGGER) );
+ sceKernelExitProcess(0);
+ return 0;
+}
View
@@ -0,0 +1,55 @@
+PHONY := all package clean
+rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
+
+CC := arm-vita-eabi-gcc
+CXX := arm-vita-eabi-g++
+STRIP := arm-vita-eabi-strip
+
+PROJECT_TITLE := VitaSDK sample
+PROJECT_TITLEID := VSDK00001
+
+PROJECT := vita_sample
+CXXFLAGS += -std=c++11 -I../common
+CFLAGS += -I../common
+
+LIBS := -lSceDisplay_stub
+
+SRC_C :=$(call rwildcard, src/, *.c)
+SRC_CPP :=$(call rwildcard, src/, *.cpp)
+
+OBJ_DIRS := $(addprefix out/, $(dir $(SRC_C:src/%.c=%.o))) $(addprefix out/, $(dir $(SRC_CPP:src/%.cpp=%.o)))
+OBJS := $(addprefix out/, $(SRC_C:src/%.c=%.o)) $(addprefix out/, $(SRC_CPP:src/%.cpp=%.o))
+
+
+all: package
+
+package: $(PROJECT).vpk
+
+$(PROJECT).vpk: eboot.bin param.sfo
+ vita-pack-vpk -s param.sfo -b eboot.bin $(PROJECT).vpk
+
+eboot.bin: $(PROJECT).velf
+ vita-make-fself $(PROJECT).velf eboot.bin
+
+param.sfo:
+ vita-mksfoex -s TITLE_ID="$(PROJECT_TITLEID)" "$(PROJECT_TITLE)" param.sfo
+
+$(PROJECT).velf: $(PROJECT).elf
+ $(STRIP) -g $<
+ vita-elf-create $< $@
+
+$(PROJECT).elf: $(OBJS)
+ $(CXX) -Wl,-q $(CFLAGS) -o $@ $^ $(LIBS)
+
+$(OBJ_DIRS):
+ mkdir -p $@
+
+out/%.o : src/%.cpp | $(OBJ_DIRS)
+ arm-vita-eabi-g++ -c $(CXXFLAGS) -o $@ $<
+
+out/%.o : src/%.c | $(OBJ_DIRS)
+ arm-vita-eabi-g++ -c $(CFLAGS) -o $@ $<
+
+clean:
+ rm -f $(PROJECT).velf $(PROJECT).elf $(PROJECT).vpk param.sfo eboot.bin $(OBJS)
+ rm -r $(abspath $(OBJ_DIRS))
Oops, something went wrong.

0 comments on commit 19f7f0d

Please sign in to comment.