Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add linear/point screen filter option, add fill mode aspect 4:3 or 16:10 options #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ $(PROJECT).vpk: eboot.bin param.sfo
TEST_OUTPUT = bin/*.S out/$(PROJECT).elf out/$(PROJECT).velf bin/*.o lib/*.a lib/*.o lib/*.S # lib/Makefile
LIBS = -lvita2d -lm -lSceLibKernel_stub -lSceTouch_stub -lSceDisplay_stub -lSceGxm_stub -lSceCtrl_stub -lSceRtc_stub -lScePower_stub -lSceSysmodule_stub -lSceCommonDialog_stub -lSceAudio_stub


debugnet: CFLAGS += -DUSE_DEBUGNET -g
debugnet: LIBS := -ldebugnet -lSceNet_stub -lSceNetCtl_stub $(LIBS)
debugnet: all
Expand All @@ -36,6 +37,7 @@ eboot.bin: out/$(PROJECT).velf
vita-make-fself -s out/$(PROJECT).velf out/eboot.bin

param.sfo:
mkdir out || true
vita-mksfoex -s TITLE_ID="$(PROJECT_TITLEID)" "$(PROJECT_TITLE)" out/param.sfo

out/$(PROJECT).velf: out/$(PROJECT).elf
Expand All @@ -44,7 +46,7 @@ out/$(PROJECT).velf: out/$(PROJECT).elf

out/$(PROJECT).elf: $(HOMEBREW_OBJS)
mkdir -p out
$(CC) -Wl,-q $(LDFLAGS) $(HOMEBREW_OBJS) $(LIBS) -o $@
$(CCP) -Wl,-q $(LDFLAGS) $(HOMEBREW_OBJS) $(LIBS) -o $@

bin/%.o: src/%.c
mkdir -p bin
Expand Down
47 changes: 30 additions & 17 deletions src/PSP2.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@


#include <stdarg.h>

#include <psp2/display.h>
#include <psp2/gxm.h>
#include <psp2/kernel/sysmem.h>

#include "PSP2.h"
#include <vita2d.h>

#include "PSP.h"

#include "doomdef.h"

const unsigned char msx_font[] __attribute((aligned(4))) =
Expand Down Expand Up @@ -64,7 +62,7 @@ const unsigned char msx_font[] __attribute((aligned(4))) =
"\x70\x88\x80\x80\x88\x70\x20\x60\x90\x00\x00\x90\x90\x90\x68\x00";


vita2d_texture *pal_tex, *font_tex;
vita2d_texture *pal_tex = NULL, *font_tex = NULL;
byte *paltex_data;
uint32_t *palette_data, *font_data;

Expand Down Expand Up @@ -151,10 +149,8 @@ void ScreenFlash(uint32_t color)
sceKernelDelayThread(1000 * 100);
}

void PSP2_Video_Init(int screen_scale)
void PSP2_Video_Init(int screen_scale, boolean bilinear_enabled)
{
vita2d_init();

//ScreenFlash(RGBA8(255, 0, 0, 255));
//ScreenFlash(RGBA8(0, 255, 0, 255));
//ScreenFlash(RGBA8(0, 0, 255, 255));
Expand All @@ -165,11 +161,17 @@ void PSP2_Video_Init(int screen_scale)
{
case SCREEN_SCALE_NONE:
break;
case SCREEN_SCALE_FIT:
screen_x = 150;
case SCREEN_SCALE_FIT_4_TO_3:
screen_scale_h = (float)SCREEN_H/(float)SCREENHEIGHT;
screen_scale_w = screen_scale_h*((float)SCREENHEIGHT/(float)SCREENWIDTH)*(4.0f/3.0f);
screen_x = ((float)SCREEN_W-screen_scale_w*(float)SCREENWIDTH)/2.0f;
screen_y = 0;
break;
case SCREEN_SCALE_FIT_16_TO_10:
screen_scale_h = (float)SCREEN_H/(float)SCREENHEIGHT;
screen_scale_w = screen_scale_h*((float)SCREENHEIGHT/(float)SCREENWIDTH)*(16.0f/10.0f);
screen_x = ((float)SCREEN_W-screen_scale_w*(float)SCREENWIDTH)/2.0f;
screen_y = 0;
screen_scale_w = 2;
screen_scale_h = SCREEN_H/(float)SCREENHEIGHT;
break;
case SCREEN_SCALE_ORIG:
screen_x = 150;
Expand All @@ -184,13 +186,24 @@ void PSP2_Video_Init(int screen_scale)
screen_scale_h = SCREEN_H/(float)SCREENHEIGHT;
break;
}
if (font_tex == NULL) {
vita2d_init();
font_tex = vita2d_create_empty_texture(SCREEN_W, SCREEN_H);
font_data = (uint32_t*) vita2d_texture_get_datap(font_tex);

pal_tex = vita2d_create_empty_texture_format(SCREENWIDTH, SCREENHEIGHT, SCE_GXM_TEXTURE_FORMAT_P8_1BGR);
paltex_data = (byte*) vita2d_texture_get_datap(pal_tex);
palette_data = (uint32_t *)vita2d_texture_get_palette(pal_tex);
}

font_tex = vita2d_create_empty_texture(SCREEN_W, SCREEN_H);
font_data = (uint32_t*) vita2d_texture_get_datap(font_tex);

pal_tex = vita2d_create_empty_texture_format(SCREENWIDTH, SCREENHEIGHT, SCE_GXM_TEXTURE_FORMAT_P8_1BGR);
paltex_data = (byte*) vita2d_texture_get_datap(pal_tex);
palette_data = (uint32_t *)vita2d_texture_get_palette(pal_tex);
if (bilinear_enabled == true)
{
vita2d_texture_set_filters(pal_tex, SCE_GXM_TEXTURE_FILTER_POINT, SCE_GXM_TEXTURE_FILTER_LINEAR);
}
else
{
vita2d_texture_set_filters(pal_tex, SCE_GXM_TEXTURE_FILTER_POINT, SCE_GXM_TEXTURE_FILTER_POINT);
}
}

void PSP2_Video_FillScreen(uint32_t size)
Expand Down
17 changes: 10 additions & 7 deletions src/PSP.h → src/PSP2.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __PSP_H__
#define __PSP_H__
#ifndef __PSP2_H__
#define __PSP2_H__

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -31,8 +31,9 @@ extern "C" {

#define SCREEN_SCALE_NONE 0
#define SCREEN_SCALE_FULL 1
#define SCREEN_SCALE_FIT 2
#define SCREEN_SCALE_ORIG 3
#define SCREEN_SCALE_FIT_4_TO_3 2
#define SCREEN_SCALE_FIT_16_TO_10 3
#define SCREEN_SCALE_ORIG 4

#define RED RGBA8(255,0,0,255)
#define GREEN RGBA8(0,255,0,255)
Expand All @@ -42,8 +43,8 @@ extern "C" {

//#define sceCtrlPeekBufferPositive sceCtrlReadBufferPositive

void PSP2_Video_Init(int scr_scale);
void PSP2_Video_FillScreen();
void PSP2_Video_Init(int scr_scale, boolean bilinear_enabled);
void PSP2_Video_FillScreen(uint32_t size);
void PSP2_Video_DrawBuffer();

void font_draw_char(int x, int y, uint32_t color, char c);
Expand Down Expand Up @@ -92,9 +93,11 @@ unsigned short num2elisa(unsigned short c);
void Draw_Char_Hankaku(int x,int y,unsigned char ch,int col,int backcol,int fill);
void Draw_Char_Zenkaku(int x,int y,unsigned char u,unsigned char d,int col,int backcol,int fill);
void mh_print(int x, int y, unsigned char *str, uint32_t col, int backcol, int fill);
void pgInit();
void pgInit(int scale, boolean bilinear_enabled);
void pgScreenFrame(long mode,long frame);
void Change_Resolution();
uint32_t* PSP2_GetPalettePtr();
byte* PSP2_Video_GetVideoPtr();

#define PSP2_DIR(path) "ux0:data/" path

Expand Down
2 changes: 1 addition & 1 deletion src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int access(char *file, int mode)

#include "d_main.h"

#include "PSP.h"
#include "PSP2.h"

#define MAXPATH 0x108
char *doomwaddir;
Expand Down
61 changes: 47 additions & 14 deletions src/i_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ rcsid[] = "$Id: i_main.c,v 1.4 1997/02/03 22:45:10 b1 Exp $";

#include "m_argv.h"
#include "d_main.h"
#include "PSP.h"
#include "PSP2.h"
#include "fontb.h"

long pg_screenmode;
Expand All @@ -51,7 +51,8 @@ SceCtrlData ctl;
#define PATHLIST_H 20
#define REPEAT_TIME 0x40000
#define BUFSIZE 65536
#define DEFAULT_SCREEN_SCALE SCREEN_SCALE_FULL
#define DEFAULT_SCREEN_SCALE SCREEN_SCALE_FIT_4_TO_3
#define DEFAULT_BILINEAR_ENABLED true

dirent_t dlist[MAXDIRNUM];
int dlist_num;
Expand All @@ -66,6 +67,7 @@ int now_depth;
char buf[BUFSIZE];
int screen_res;
boolean analog_enabled;
boolean bilinear_enabled;

int debug_res = 0x0;

Expand Down Expand Up @@ -101,10 +103,12 @@ int main(int argc, char** argv)

sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);
analog_enabled = 0;

bilinear_enabled = DEFAULT_BILINEAR_ENABLED;

//SetupCallbacks();
screen_res = DEFAULT_SCREEN_SCALE;
pgInit(screen_res);
pgInit(screen_res, bilinear_enabled);
pgScreenFrame(2,0);
pgFillvram(0);

Expand Down Expand Up @@ -135,9 +139,9 @@ switch(Control()) {

}

void pgInit(int scale)
void pgInit(int scale, boolean bilinear_enabled)
{
PSP2_Video_Init(scale);
PSP2_Video_Init(scale, bilinear_enabled);

//sceDisplaySetMode(0,SCREEN_WIDTH,SCREEN_HEIGHT);
pgScreenFrame(0,0);
Expand Down Expand Up @@ -341,24 +345,37 @@ void Draw_All(void) {
switch (screen_res)
{
case SCREEN_SCALE_FULL:
mh_print(0, 500, "Screen Resolution (press select to change): Fullscreen", rgb2col(255, 255, 0), 0, 0);
mh_print(0, 450, "Screen Resolution (press select to change): Fullstretch", rgb2col(255, 255, 0), 0, 0);
break;
case SCREEN_SCALE_FIT_4_TO_3:
mh_print(0, 450, "Screen Resolution (press select to change): Fit 4:3", rgb2col(255, 255, 0), 0, 0);
break;
case SCREEN_SCALE_FIT:
mh_print(0, 500, "Screen Resolution (press select to change): Fit to Screen", rgb2col(255, 255, 0), 0, 0);
case SCREEN_SCALE_FIT_16_TO_10:
mh_print(0, 450, "Screen Resolution (press select to change): Fit 16:10", rgb2col(255, 255, 0), 0, 0);
break;
case SCREEN_SCALE_ORIG:
mh_print(0, 500, "Screen Resolution (press select to change): Original", rgb2col(255, 255, 0), 0, 0);
mh_print(0, 450, "Screen Resolution (press select to change): Original", rgb2col(255, 255, 0), 0, 0);
break;
}

//Bilinear Filtering (Image Smoothing)
if (bilinear_enabled)
{
mh_print(0, 500, "Screen Filter (press start to change): Linear", rgb2col(255, 255, 0), 0, 0);
}
else
{
mh_print(0, 500, "Screen Filter (press start to change): Point", rgb2col(255, 255, 0), 0, 0);
}

// Controller mode
if (analog_enabled)
{
mh_print(0, 450, "Controller Mode (press triangle to change): Analog Stick", rgb2col(255, 255, 0), 0, 0);
mh_print(0, 400, "Controller Mode (press triangle to change): Analog Stick", rgb2col(255, 255, 0), 0, 0);
}
else
{
mh_print(0, 450, "Controller Mode (press triangle to change): D-Pad", rgb2col(255, 255, 0), 0, 0);
mh_print(0, 400, "Controller Mode (press triangle to change): D-Pad", rgb2col(255, 255, 0), 0, 0);
}

if (dlist_num == 0)
Expand Down Expand Up @@ -505,6 +522,9 @@ int Control(void) {
if (new_pad & SCE_CTRL_TRIANGLE) {
Change_Controller_Mode();
}
if (new_pad & SCE_CTRL_START) {
Change_Filtering();
}

return 0;
}
Expand All @@ -519,16 +539,19 @@ void Change_Resolution()
switch(screen_res)
{
case SCREEN_SCALE_FULL:
screen_res = SCREEN_SCALE_FIT;
screen_res = SCREEN_SCALE_FIT_4_TO_3;
break;
case SCREEN_SCALE_FIT_4_TO_3:
screen_res = SCREEN_SCALE_FIT_16_TO_10;
break;
case SCREEN_SCALE_FIT:
case SCREEN_SCALE_FIT_16_TO_10:
screen_res = SCREEN_SCALE_ORIG;
break;
case SCREEN_SCALE_ORIG:
screen_res = SCREEN_SCALE_FULL;
break;
}
pgInit(screen_res);
pgInit(screen_res, bilinear_enabled);
}

void Change_Controller_Mode()
Expand All @@ -541,6 +564,16 @@ void Change_Controller_Mode()
I_SetControlMode(analog_enabled);
}

void Change_Filtering()
{
if (bilinear_enabled == true) {
bilinear_enabled = false;
} else {
bilinear_enabled = true;
}
pgInit(screen_res, bilinear_enabled);
}

void Vita_Audio_Thread() {
int size = 256;
int freq = 48000;
Expand Down
2 changes: 1 addition & 1 deletion src/i_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $";
#endif
#include "i_system.h"

#include "PSP.h"
#include "PSP2.h"


int mb_used = 6;
Expand Down
6 changes: 3 additions & 3 deletions src/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";

#include "doomdef.h"

#include "PSP.h"

#include "PSP2.h"

#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
Expand All @@ -54,6 +53,7 @@ int controls_set = 0;
int d_clist_start = 0;
int d_clist_curpos = 0;
boolean analog = 0;
extern bilinear_enabled;

extern SceCtrlData ctl;

Expand Down Expand Up @@ -1171,7 +1171,7 @@ void I_InitGraphics(void)
video_h = h = 200;
video_bpp = 8;

PSP2_Video_Init(SCREEN_SCALE_NONE);
PSP2_Video_Init(SCREEN_SCALE_NONE, bilinear_enabled);

screens[0] = PSP2_Video_GetVideoPtr(); //(unsigned char *) malloc(SCREENWIDTH * SCREENHEIGHT);

Expand Down