This repository has been archived by the owner on Nov 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f87f832
commit 84adb9e
Showing
6 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
|
||
set(CMAKE_SYSTEM_NAME "Generic") | ||
set(CMAKE_C_COMPILER "arm-vita-eabi-gcc") | ||
set(CMAKE_CXX_COMPILER "arm-vita-eabi-g++") | ||
|
||
project(SharedFb-sample) | ||
add_subdirectory(gxminternalforvsh) | ||
|
||
set(CMAKE_C_FLAGS "-Wl,-q -O3 -std=c99") | ||
|
||
add_executable(${PROJECT_NAME}.elf | ||
src/main.c | ||
src/graphics.c | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME}.elf | ||
SceDisplay_stub | ||
SceAppMgr_stub | ||
SceGxm_stub | ||
SceGxm_stub_weak | ||
) | ||
|
||
add_custom_target(${PROJECT_NAME}.vpk ALL | ||
COMMAND vita-elf-create ${PROJECT_NAME}.elf ${PROJECT_NAME}.velf | ||
COMMAND vita-make-fself ${PROJECT_NAME}.velf eboot.bin | ||
COMMAND vita-mksfoex -s TITLE_ID=SHAREDFBT "${PROJECT_NAME}" param.sfo | ||
COMMAND vita-pack-vpk -s param.sfo -b eboot.bin ${PROJECT_NAME}.vpk | ||
) | ||
add_dependencies(${PROJECT_NAME}.vpk ${PROJECT_NAME}.elf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
set(LIB "SceGxm_stub_weak") | ||
set(LIB_FILE "lib${LIB}.a") | ||
set(LIB_YAML "${CMAKE_CURRENT_SOURCE_DIR}/SceGxm.yml") | ||
set(LIB_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/stubs") | ||
|
||
add_custom_target("${LIB}.target" | ||
DEPENDS "${LIB_FILE}" | ||
) | ||
|
||
add_custom_command( | ||
OUTPUT "${LIB_FILE}" | ||
DEPENDS "${LIB_YAML}" | ||
COMMAND vita-libs-gen "${LIB_YAML}" "${LIB_BUILD_DIR}" | ||
COMMAND make -C "${LIB_BUILD_DIR}" | ||
COMMAND mv "${LIB_BUILD_DIR}/libSceGxm_stub_weak.a" "${LIB_FILE}" | ||
) | ||
|
||
add_library("${LIB}" STATIC IMPORTED GLOBAL) | ||
|
||
add_dependencies("${LIB}" "${LIB}.target") | ||
|
||
set_target_properties("${LIB}" PROPERTIES | ||
IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${LIB_FILE}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: 2 | ||
firmware: 3.60 | ||
modules: | ||
SceGxm: | ||
nid: 0x0D0AA0CB | ||
libraries: | ||
SceGxmInternalForVsh: | ||
kernel: false | ||
nid: 0xC98AEB79 | ||
functions: | ||
SceGxmInternalForVsh_A04F5FAC: 0xA04F5FAC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include <string.h> | ||
|
||
#include <psp2/gxm.h> | ||
#include <psp2/appmgr.h> | ||
|
||
#include "graphics.h" | ||
|
||
static SceUID shfb_id; | ||
static SceSharedFbInfo info; | ||
static int oy = 0; | ||
static int size = 0; | ||
static int color = 0xff00ff00; | ||
|
||
static void* bufferData[2]; | ||
static int bufferIndex = 0; | ||
|
||
// | ||
int initGraphics() | ||
{ | ||
//Initialize GXM | ||
SceGxmInitializeParams gxm_init_params_internal; | ||
memset(&gxm_init_params_internal, 0, sizeof(gxm_init_params_internal)); | ||
gxm_init_params_internal.flags = 0x0A; //Flag to disable callback? | ||
gxm_init_params_internal.displayQueueMaxPendingCount = MAX_PENDING_SWAPS; | ||
//Since we use sharedfb, callback is not required | ||
gxm_init_params_internal.parameterBufferSize = 0x200000; | ||
|
||
int ret = SceGxmInternalForVsh_A04F5FAC(&gxm_init_params_internal); | ||
if (ret < 0) | ||
color = 0xff000ff0; | ||
|
||
//Wait for sharedfb to be ready | ||
while (1){ | ||
shfb_id = _sceSharedFbOpen(1, 0x03600000); | ||
memset(&info, 0, sizeof(info)); | ||
sceSharedFbGetInfo(shfb_id, &info); | ||
if (info.curbuf == 1) | ||
sceSharedFbClose(shfb_id); | ||
else | ||
break; | ||
} | ||
|
||
bufferData[0] = info.base1; //Additional cdram can be mapped using sceGxmMapMemory | ||
bufferData[1] = info.base2; | ||
|
||
return 0; | ||
} | ||
|
||
/* Draw Display */ | ||
int drawDisplay() | ||
{ | ||
//Get buffer state | ||
memset(&info, 0, sizeof(info)); | ||
sceSharedFbGetInfo(shfb_id, &info); | ||
|
||
if (info.curbuf == 1) | ||
bufferIndex = 0; | ||
else | ||
bufferIndex = 1; | ||
|
||
//Draw animation | ||
drawObject(bufferData[bufferIndex], 480, oy, size, color); | ||
if (oy < 400) | ||
oy = oy + 1; | ||
else | ||
oy = 0; | ||
if (size < 100) | ||
size = size + 1; | ||
else | ||
size = 0; | ||
|
||
//Set new buffer | ||
info.base2 = bufferData[bufferIndex]; | ||
|
||
sceSharedFbBegin(shfb_id, &info); | ||
sceSharedFbEnd(shfb_id); | ||
|
||
return 0; | ||
} | ||
|
||
void drawObject(void *address, const int x, const int y, const int halfSize, const int color) | ||
{ | ||
int i = 0, j = 0; | ||
int *pixel; | ||
pixel = address; | ||
|
||
for (i = -halfSize; i < halfSize; i++) { | ||
for (j = -halfSize; j < halfSize; j++) { | ||
if (0 <= (x + i) && (x + i) < DISPLAY_STRIDE_IN_PIXELS && 0 <= (y + j) && (y + j) < DISPLAY_HEIGHT) { | ||
pixel[(x + i) + DISPLAY_STRIDE_IN_PIXELS * (y + j)] = color; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#define DISPLAY_WIDTH 960 | ||
#define DISPLAY_HEIGHT 544 | ||
#define DISPLAY_STRIDE_IN_PIXELS 960 | ||
#define MAX_PENDING_SWAPS 1 | ||
|
||
typedef struct SceSharedFbInfo { // size is 0x58 | ||
void* base1; // cdram base | ||
int unk_04; | ||
void* base2; // cdram base | ||
int unk_0C; | ||
void *unk_10; | ||
int unk_14; | ||
int unk_18; | ||
int unk_1C; | ||
int unk_20; | ||
int unk_24; // 960 | ||
int unk_28; // 960 | ||
int unk_2C; // 544 | ||
int unk_30; | ||
int curbuf; | ||
int unk_38; | ||
int unk_3C; | ||
int unk_40; | ||
int unk_44; | ||
int unk_48; | ||
int unk_4C; | ||
int unk_50; | ||
int unk_54; | ||
} SceSharedFbInfo; | ||
|
||
//sceGxmInitializeInternalForVsh | ||
extern int SceGxmInternalForVsh_A04F5FAC(const SceGxmInitializeParams *); | ||
|
||
//Init GXM, SharedFb | ||
int initGraphics( void ); | ||
|
||
//Draw display | ||
int drawDisplay(); | ||
|
||
//Draw object | ||
void drawObject(void *address, const int x, const int y, const int halfSize, const int color); | ||
|
||
//SharedFb | ||
SceUID _sceSharedFbOpen(int a1, int sysver); | ||
int sceSharedFbClose(SceUID shared_fb_id); | ||
int sceSharedFbBegin(SceUID shared_fb_id, SceSharedFbInfo *info); | ||
int sceSharedFbEnd(SceUID shared_fb_id); | ||
int sceSharedFbGetInfo(SceUID shared_fb_id, SceSharedFbInfo *info); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <psp2/gxt.h> | ||
|
||
#include "graphics.h" | ||
|
||
int main( void ) | ||
{ | ||
initGraphics(); | ||
|
||
while (1) { | ||
drawDisplay(); | ||
} | ||
|
||
return 0; | ||
} |