diff options
author | gameblabla | 2020-10-16 03:17:52 +0000 |
---|---|---|
committer | GitHub | 2020-10-16 03:17:52 +0000 |
commit | 9ea18f315c385ec85cb28d44659b45589cfc9ac0 (patch) | |
tree | 3661b6ec35f5900070acebc38fd975fb5f9cf84b | |
parent | 1a51fa791356b52a88e8ae0e6941034b23cd354f (diff) | |
parent | 94b1765da3dd2b5121650e99e194020fb3c5b4b6 (diff) | |
download | snesemu-9ea18f315c385ec85cb28d44659b45589cfc9ac0.tar.gz snesemu-9ea18f315c385ec85cb28d44659b45589cfc9ac0.tar.bz2 snesemu-9ea18f315c385ec85cb28d44659b45589cfc9ac0.zip |
Merge pull request #1 from m45t3r/master
I am merging this because it has the new color opts
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.miyoo | 73 | ||||
-rw-r--r-- | shell/input/sdl/input.c | 8 | ||||
-rw-r--r-- | shell/menu/menu.c | 128 | ||||
-rw-r--r-- | shell/video/sdl/video_blit.c | 38 | ||||
-rw-r--r-- | source/gfx.c | 81 | ||||
-rw-r--r-- | source/gfx.h | 60 | ||||
-rw-r--r-- | source/pixform.h | 109 | ||||
-rw-r--r-- | source/port.h | 4 |
9 files changed, 201 insertions, 301 deletions
@@ -14,3 +14,4 @@ expsfc.* EXPSFC/ *.so PocketSNES +snes9x diff --git a/Makefile.miyoo b/Makefile.miyoo new file mode 100644 index 0000000..eb5d62a --- /dev/null +++ b/Makefile.miyoo @@ -0,0 +1,73 @@ +GIT_VERSION := "$(shell git describe --abbrev=7 --dirty --always)" + +PRGNAME = snes9x + +VIDEO_BACKEND = sdl +INPUT_BACKEND = sdl +SOUND_BACKEND = alsa + +PREFIX = arm-linux + +# define regarding OS, which compiler to use +CC = $(PREFIX)-gcc +STRIP = $(PREFIX)-strip +AS = $(PREFIX)-as +GASM = $(PREFIX)-g++ + +SYSROOT := $(shell $(CC) --print-sysroot) +SDL_CFLAGS := $(shell $(SYSROOT)/usr/bin/sdl-config --cflags) +SDL_LIBS := $(shell $(SYSROOT)/usr/bin/sdl-config --libs) + +# change compilation / linking flag options +CFLAGS = -DLSB_FIRST -DFAST_ALIGNED_LSB_WORD_ACCESS -I. -Ilibretro-common/include -Isrc -DINLINE="inline" -DRIGHTSHIFT_IS_SAR +CFLAGS += -Isource -I./shell/emu -I./shell/scalers -I./shell/emu -I./shell/audio -I./shell/menu -I./shell/video/sdl -I./shell/input -Ishell/headers + +CFLAGS += -Ofast -fsingle-precision-constant -fno-PIC -flto +ifndef PROFILE +CFLAGS += -falign-functions=1 -falign-jumps=1 -falign-loops=1 -falign-labels=1 +endif +CFLAGS += -DNDEBUG -DLAGFIX -DFRAMESKIP -DGIT_VERSION=\"$(GIT_VERSION)\" -fno-builtin -fno-exceptions -ffunction-sections -std=gnu99 +CFLAGS += -Wall -Wextra -pedantic -Wno-implicit-function-declaration -Wno-implicit-fallthrough -Wno-sign-compare -Wno-unused-variable -Wno-unused-function -Wno-uninitialized -Wno-strict-aliasing -Wno-overflow -fno-strict-overflow + +ifeq ($(PROFILE), YES) +CFLAGS += -fprofile-generate=./profile +else ifeq ($(PROFILE), APPLY) +CFLAGS += -fprofile-use -fprofile-dir=./profile -fbranch-probabilities +endif + +LDFLAGS = -lc -lgcc -lm $(SDL_LIBS) -no-pie -Wl,--as-needed -Wl,--gc-sections -s -flto +ifeq ($(SOUND_BACKEND), portaudio) +LDFLAGS += -lasound -lportaudio +endif +ifeq ($(SOUND_BACKEND), libao) +LDFLAGS += -lao +endif +ifeq ($(SOUND_BACKEND), alsa) +LDFLAGS += -lasound +endif +ifeq ($(SOUND_BACKEND), pulse) +LDFLAGS += -lpulse -lpulse-simple +endif + +ifeq ($(PROFILE), YES) +LDFLAGS += -lgcov +endif + +# Files to be compiled +SRCDIR = ./source ./shell/emu ./shell/scalers ./shell/audio/$(SOUND_BACKEND) ./shell/menu ./shell/video/$(VIDEO_BACKEND) ./shell/input/$(INPUT_BACKEND) ./shell/other +VPATH = $(SRCDIR) +SRC_C = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.c)) +SRC_CP = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.cpp)) +OBJ_C = $(notdir $(patsubst %.c, %.o, $(SRC_C))) +OBJ_CP = $(notdir $(patsubst %.cpp, %.o, $(SRC_CP))) +OBJS = $(OBJ_C) $(OBJ_CP) + +# Rules to make executable +$(PRGNAME): $(OBJS) + $(CC) $(CFLAGS) -o $(PRGNAME) $^ $(LDFLAGS) + +$(OBJ_C) : %.o : %.c + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f $(PRGNAME)$(EXESUFFIX) *.o diff --git a/shell/input/sdl/input.c b/shell/input/sdl/input.c index d47b889..b26af1f 100644 --- a/shell/input/sdl/input.c +++ b/shell/input/sdl/input.c @@ -50,9 +50,9 @@ uint32_t S9xReadJoypad(int32_t port) int32_t i; uint32_t joypad = 0; - + keystate = SDL_GetKeyState(NULL); - + SDL_PollEvent(&event); CASE(option.config_buttons[0][10], SNES_START_MASK); @@ -67,8 +67,8 @@ uint32_t S9xReadJoypad(int32_t port) CASE(option.config_buttons[0][1], SNES_RIGHT_MASK); CASE(option.config_buttons[0][2], SNES_DOWN_MASK); CASE(option.config_buttons[0][3], SNES_LEFT_MASK); - - if (keystate[SDLK_END]) emulator_state = 1; + + if (keystate[option.config_buttons[0][12]]) emulator_state = 1; return joypad; } diff --git a/shell/menu/menu.c b/shell/menu/menu.c index a8f5950..9eb2d2d 100644 --- a/shell/menu/menu.c +++ b/shell/menu/menu.c @@ -76,22 +76,24 @@ static void config_load() else { /* Default mapping for Horizontal */ - option.config_buttons[0][0] = 273; - option.config_buttons[0][1] = 275; - option.config_buttons[0][2] = 274; - option.config_buttons[0][3] = 276; - - option.config_buttons[0][4] = 306; - option.config_buttons[0][5] = 308; - option.config_buttons[0][6] = 304; - option.config_buttons[0][7] = 32; - - option.config_buttons[0][8] = 9; - option.config_buttons[0][9] = 8; - - option.config_buttons[0][10] = 13; - option.config_buttons[0][11] = 27; - + option.config_buttons[0][0] = 273; // UP + option.config_buttons[0][1] = 275; // RIGHT + option.config_buttons[0][2] = 274; // DOWN + option.config_buttons[0][3] = 276; // LEFT + + option.config_buttons[0][4] = 308; // A + option.config_buttons[0][5] = 306; // B + option.config_buttons[0][6] = 304; // X + option.config_buttons[0][7] = 32; // Y + + option.config_buttons[0][8] = 9; // L + option.config_buttons[0][9] = 8; // R + + option.config_buttons[0][10] = 13; // START + option.config_buttons[0][11] = 27; // SELECT + + option.config_buttons[0][12] = 305; // MENU + option.fullscreen = 1; } } @@ -101,7 +103,7 @@ static void config_save() FILE* fp; char config_path[512]; snprintf(config_path, sizeof(config_path), "%s/%s.cfg", conf_path, GameName_emu); - + fp = fopen(config_path, "wb"); if (fp) { @@ -184,7 +186,7 @@ static const char* Return_Text_Button(uint32_t button) case 0: return "..."; break; - } + } } static void Input_Remapping() @@ -195,12 +197,12 @@ static void Input_Remapping() int32_t currentselection = 1; int32_t exit_input = 0; uint32_t exit_map = 0; - + while(!exit_input) { pressed = 0; SDL_FillRect( backbuffer, NULL, 0 ); - + while (SDL_PollEvent(&Event)) { if (Event.type == SDL_KEYDOWN) @@ -262,7 +264,7 @@ static void Input_Remapping() SDL_FillRect( backbuffer, NULL, 0 ); print_string("Please press button for mapping", TextWhite, TextBlue, 37, 108, backbuffer->pixels); bitmap_scale(0,0,320,240,sdl_screen->w,sdl_screen->h,320,0,(uint16_t* restrict)backbuffer->pixels,(uint16_t* restrict)sdl_screen->pixels); - + while (SDL_PollEvent(&Event)) { if (Event.type == SDL_KEYDOWN) @@ -279,67 +281,67 @@ static void Input_Remapping() break; } } - + if (currentselection > 12) currentselection = 12; if (controls_chosen == 0) print_string("Player 1", TextWhite, 0, 100, 10, backbuffer->pixels); else print_string("Player 2", TextWhite, 0, 100, 10, backbuffer->pixels); - + print_string("Press [A] to map to a button", TextWhite, TextBlue, 50, 210, backbuffer->pixels); print_string("Press [B] to Exit", TextWhite, TextBlue, 85, 225, backbuffer->pixels); - + snprintf(text, sizeof(text), "UP : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][0])); if (currentselection == 1) print_string(text, TextRed, 0, 5, 25+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 25+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "DOWN : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][1])); if (currentselection == 2) print_string(text, TextRed, 0, 5, 45+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 45+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "LEFT : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][2])); if (currentselection == 3) print_string(text, TextRed, 0, 5, 65+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 65+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "RIGHT: %s\n", Return_Text_Button(option.config_buttons[controls_chosen][3])); if (currentselection == 4) print_string(text, TextRed, 0, 5, 85+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 85+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "A : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][4])); if (currentselection == 5) print_string(text, TextRed, 0, 5, 105+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 105+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "B : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][5])); if (currentselection == 6) print_string(text, TextRed, 0, 5, 125+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 125+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "X : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][6])); if (currentselection == 7) print_string(text, TextRed, 0, 5, 145+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 145+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "Y : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][7])); if (currentselection == 8) print_string(text, TextRed, 0, 5, 165+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 165+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "L : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][8])); if (currentselection == 9) print_string(text, TextRed, 0, 5, 185+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 185+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "R : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][9])); if (currentselection == 10) print_string(text, TextRed, 0, 165, 25+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 165, 25+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "START : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][10])); if (currentselection == 11) print_string(text, TextRed, 0, 165, 45+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 165, 45+2, backbuffer->pixels); - + snprintf(text, sizeof(text), "SELECT : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][11])); if (currentselection == 12) print_string(text, TextRed, 0, 165, 65+2, backbuffer->pixels); else print_string(text, TextWhite, 0, 165, 65+2, backbuffer->pixels); - + bitmap_scale(0,0,320,240,sdl_screen->w,sdl_screen->h,320,0,(uint16_t* restrict)backbuffer->pixels,(uint16_t* restrict)sdl_screen->pixels); SDL_Flip(sdl_screen); } - + config_save(); } @@ -350,34 +352,34 @@ void Menu() int16_t currentselection = 1; SDL_Rect dstRect; SDL_Event Event; - + Set_Video_Menu(); - + /* Save sram settings each time we bring up the menu */ SRAM_Menu(0); RTC_Menu(0); - + while (((currentselection != 1) && (currentselection != 6)) || (!pressed)) { pressed = 0; - + SDL_FillRect( backbuffer, NULL, 0 ); print_string("SNESEmu - Built on " __DATE__, TextWhite, 0, 5, 15, backbuffer->pixels); - + if (currentselection == 1) print_string("Continue", TextRed, 0, 5, 45, backbuffer->pixels); else print_string("Continue", TextWhite, 0, 5, 45, backbuffer->pixels); - + snprintf(text, sizeof(text), "Load State %d", save_slot); - + if (currentselection == 2) print_string(text, TextRed, 0, 5, 65, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 65, backbuffer->pixels); - + snprintf(text, sizeof(text), "Save State %d", save_slot); - + if (currentselection == 3) print_string(text, TextRed, 0, 5, 85, backbuffer->pixels); else print_string(text, TextWhite, 0, 5, 85, backbuffer->pixels); - + if (currentselection == 4) { switch(option.fullscreen) @@ -417,7 +419,7 @@ void Menu() if (currentselection == 5) print_string("Input remapping", TextRed, 0, 5, 125, backbuffer->pixels); else print_string("Input remapping", TextWhite, 0, 5, 125, backbuffer->pixels); - + if (currentselection == 6) print_string("Quit", TextRed, 0, 5, 145, backbuffer->pixels); else print_string("Quit", TextWhite, 0, 5, 145, backbuffer->pixels); @@ -519,19 +521,19 @@ void Menu() bitmap_scale(0,0,320,240,sdl_screen->w,sdl_screen->h,320,0,(uint16_t* restrict)backbuffer->pixels,(uint16_t* restrict)sdl_screen->pixels); SDL_Flip(sdl_screen); } - + SDL_FillRect(sdl_screen, NULL, 0); SDL_Flip(sdl_screen); #ifdef SDL_TRIPLEBUF SDL_FillRect(sdl_screen, NULL, 0); SDL_Flip(sdl_screen); #endif - + if (currentselection == 6) { exit_snes = 1; } - + /* Switch back to emulator core */ emulator_state = 0; Set_Video_InGame(); @@ -547,51 +549,51 @@ static void Cleanup(void) // Deinitialize audio and video output Audio_Close(); - + SDL_Quit(); } void Init_Configuration() { snprintf(home_path, sizeof(home_path), "%s/.snesemu", getenv("HOME")); - + snprintf(conf_path, sizeof(conf_path), "%s/conf", home_path); snprintf(save_path, sizeof(save_path), "%s/sstates", home_path); snprintf(sram_path, sizeof(sram_path), "%s/sram", home_path); snprintf(rtc_path, sizeof(sram_path), "%s/rtc", home_path); - - /* We check first if folder does not exist. + + /* We check first if folder does not exist. * Let's only try to create it if so in order to decrease boot times. * */ - + if (access( home_path, F_OK ) == -1) - { + { mkdir(home_path, 0755); } - + if (access( save_path, F_OK ) == -1) { mkdir(save_path, 0755); } - + if (access( conf_path, F_OK ) == -1) { mkdir(conf_path, 0755); } - + if (access( sram_path, F_OK ) == -1) { mkdir(sram_path, 0755); } - + if (access( rtc_path, F_OK ) == -1) { mkdir(rtc_path, 0755); } - + /* Load sram file if it exists */ SRAM_Menu(1); RTC_Menu(1); - + config_load(); } diff --git a/shell/video/sdl/video_blit.c b/shell/video/sdl/video_blit.c index fef7033..b4a6bbe 100644 --- a/shell/video/sdl/video_blit.c +++ b/shell/video/sdl/video_blit.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - + #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -51,11 +51,11 @@ uint32_t* Draw_to_Virtual_Screen; void Init_Video() { SDL_Init( SDL_INIT_VIDEO ); - + SDL_ShowCursor(0); - - sdl_screen = SDL_SetVideoMode(HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, SDL_HWSURFACE); - + + sdl_screen = SDL_SetVideoMode(0, 0, 16, SDL_HWSURFACE); + backbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 240, 16, 0,0,0,0); Set_Video_InGame(); @@ -63,30 +63,10 @@ void Init_Video() void Set_Video_Menu() { - /*if (sdl_screen->w != HOST_WIDTH_RESOLUTION) - { - sdl_screen = SDL_SetVideoMode(HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, SDL_HWSURFACE); - }*/ } void Set_Video_InGame() { - /*switch(option.fullscreen) - { - // Native - #ifdef SUPPORT_NATIVE_RESOLUTION - case 0: - if (sdl_screen->w != INTERNAL_WSWAN_WIDTH) sdl_screen = SDL_SetVideoMode(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, 16, SDL_HWSURFACE); - Draw_to_Virtual_Screen = sdl_screen->pixels; - width_of_surface = sdl_screen->w; - break; - #endif - default: - if (sdl_screen->w != HOST_WIDTH_RESOLUTION) sdl_screen = SDL_SetVideoMode(HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, SDL_HWSURFACE); - Draw_to_Virtual_Screen = wswan_vs->pixels; - width_of_surface = INTERNAL_WSWAN_WIDTH; - break; - }*/ } void Video_Close() @@ -106,9 +86,9 @@ void Update_Video_Ingame() uint32_t *s, *d; uint32_t h, w; uint8_t PAL = !!(Memory.FillRAM[0x2133] & 4); - + SDL_LockSurface(sdl_screen); - + switch(option.fullscreen) { case 0: @@ -126,7 +106,7 @@ void Update_Video_Ingame() break; } //bitmap_scale(0, 0, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, sdl_screen->w, sdl_screen->h, SNES_WIDTH*2, 0, GFX.Screen, sdl_screen->pixels); - - SDL_UnlockSurface(sdl_screen); + + SDL_UnlockSurface(sdl_screen); SDL_Flip(sdl_screen); } diff --git a/source/gfx.c b/source/gfx.c index 00fb4d1..3508011 100644 --- a/source/gfx.c +++ b/source/gfx.c @@ -226,81 +226,12 @@ bool S9xInitGFX(void) GFX.PPLx2 = GFX.Pitch; S9xFixColourBrightness(); - if (!(GFX.X2 = (uint16_t*) malloc(sizeof(uint16_t) * 0x10000))) - return false; - - if (!(GFX.ZERO_OR_X2 = (uint16_t*) malloc(sizeof(uint16_t) * 0x10000)) || !(GFX.ZERO = (uint16_t*) malloc(sizeof(uint16_t) * 0x10000))) + if (!(GFX.ZERO = (uint16_t*) malloc(sizeof(uint16_t) * 0x10000))) { - if (GFX.ZERO_OR_X2) - { - free(GFX.ZERO_OR_X2); - GFX.ZERO_OR_X2 = NULL; - } - if (GFX.X2) - { - free(GFX.X2); - GFX.X2 = NULL; - } return false; } - /* Build a lookup table that multiplies a packed RGB value by 2 with - * saturation. */ - for (r = 0; r <= MAX_RED; r++) - { - uint32_t r2 = r << 1; - if (r2 > MAX_RED) - r2 = MAX_RED; - for (g = 0; g <= MAX_GREEN; g++) - { - uint32_t g2 = g << 1; - if (g2 > MAX_GREEN) - g2 = MAX_GREEN; - for (b = 0; b <= MAX_BLUE; b++) - { - uint32_t b2 = b << 1; - if (b2 > MAX_BLUE) - b2 = MAX_BLUE; - GFX.X2 [BUILD_PIXEL2(r, g, b)] = BUILD_PIXEL2(r2, g2, b2); - GFX.X2 [BUILD_PIXEL2(r, g, b) & ~ALPHA_BITS_MASK] = BUILD_PIXEL2(r2, g2, b2); - } - } - } memset(GFX.ZERO, 0, 0x10000 * sizeof(uint16_t)); - memset(GFX.ZERO_OR_X2, 0, 0x10000 * sizeof(uint16_t)); - /* Build a lookup table that if the top bit of the color value is zero - * then the value is zero, otherwise multiply the value by 2. Used by - * the color subtraction code. */ - for (r = 0; r <= MAX_RED; r++) - { - uint32_t r2 = r; - if ((r2 & 0x10) == 0) - r2 = 0; - else - r2 = (r2 << 1) & MAX_RED; - - for (g = 0; g <= MAX_GREEN; g++) - { - uint32_t g2 = g; - if ((g2 & GREEN_HI_BIT) == 0) - g2 = 0; - else - g2 = (g2 << 1) & MAX_GREEN; - - for (b = 0; b <= MAX_BLUE; b++) - { - uint32_t b2 = b; - if ((b2 & 0x10) == 0) - b2 = 0; - else - b2 = (b2 << 1) & MAX_BLUE; - - GFX.ZERO_OR_X2 [BUILD_PIXEL2(r, g, b)] = BUILD_PIXEL2(r2, g2, b2); - GFX.ZERO_OR_X2 [BUILD_PIXEL2(r, g, b) & ~ALPHA_BITS_MASK] = BUILD_PIXEL2(MAX(1, r2), MAX(1, g2), MAX(1, b2)); - } - } - } - /* Build a lookup table that if the top bit of the color value is zero * then the value is zero, otherwise its just the value. */ for (r = 0; r <= MAX_RED; r++) @@ -337,16 +268,6 @@ bool S9xInitGFX(void) void S9xDeinitGFX(void) { /* Free any memory allocated in S9xInitGFX */ - if (GFX.X2) - { - free(GFX.X2); - GFX.X2 = NULL; - } - if (GFX.ZERO_OR_X2) - { - free(GFX.ZERO_OR_X2); - GFX.ZERO_OR_X2 = NULL; - } if (GFX.ZERO) { free(GFX.ZERO); diff --git a/source/gfx.h b/source/gfx.h index 582f7c2..fc4806b 100644 --- a/source/gfx.h +++ b/source/gfx.h @@ -33,8 +33,6 @@ typedef struct uint32_t Pitch; int32_t Delta; - uint16_t* X2; - uint16_t* ZERO_OR_X2; uint16_t* ZERO; uint32_t RealPitch; /* True pitch of Screen buffer. */ uint32_t Pitch2; /* Same as RealPitch except while using speed up hack for Glide. */ @@ -148,28 +146,50 @@ extern uint8_t mul_brightness [16][32]; static INLINE uint16_t COLOR_ADD(uint16_t C1, uint16_t C2) { - if (C1 == 0) - return C2; - else if (C2 == 0) - return C1; - else - return GFX.X2[(((C1 & RGB_REMOVE_LOW_BITS_MASK) + (C2 & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + (C1 & C2 & RGB_LOW_BITS_MASK)] | ((C1 ^ C2) & RGB_LOW_BITS_MASK); + const int RED_MASK = 0x1F << RED_SHIFT_BITS; + const int GREEN_MASK = 0x1F << GREEN_SHIFT_BITS; + const int BLUE_MASK = 0x1F; + + int rb = C1 & (RED_MASK | BLUE_MASK); + rb += C2 & (RED_MASK | BLUE_MASK); + int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0)); + int g = (C1 & (GREEN_MASK)) + (C2 & (GREEN_MASK)); + int rgbsaturate = (((g & (0x20 << GREEN_SHIFT_BITS)) | rbcarry) >> 5) * 0x1f; + uint16_t retval = (rb & (RED_MASK | BLUE_MASK)) | (g & GREEN_MASK) | rgbsaturate; +#if GREEN_SHIFT_BITS == 6 + retval |= (retval & 0x0400) >> 5; +#endif + + return retval; +} + +static INLINE uint16_t COLOR_ADD1_2(uint16_t C1, uint16_t C2) +{ + return ((((((C1)&RGB_REMOVE_LOW_BITS_MASK) + ((C2)&RGB_REMOVE_LOW_BITS_MASK)) >> 1) + + ((C1) & (C2)&RGB_LOW_BITS_MASK)) | + ALPHA_BITS_MASK); } -#define COLOR_ADD1_2(C1, C2) \ -(((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \ - ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \ - (((C1) & (C2) & RGB_LOW_BITS_MASK) | ALPHA_BITS_MASK)) +static INLINE uint16_t COLOR_SUB(uint16_t C1, uint16_t C2) +{ + int rb1 = (C1 & (THIRD_COLOR_MASK | FIRST_COLOR_MASK)) | ((0x20 << 0) | (0x20 << RED_SHIFT_BITS)); + int rb2 = C2 & (THIRD_COLOR_MASK | FIRST_COLOR_MASK); + int rb = rb1 - rb2; + int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0)); + int g = ((C1 & (SECOND_COLOR_MASK)) | (0x20 << GREEN_SHIFT_BITS)) - (C2 & (SECOND_COLOR_MASK)); + int rgbsaturate = (((g & (0x20 << GREEN_SHIFT_BITS)) | rbcarry) >> 5) * 0x1f; + uint16_t retval = ((rb & (THIRD_COLOR_MASK | FIRST_COLOR_MASK)) | (g & SECOND_COLOR_MASK)) & rgbsaturate; +#if GREEN_SHIFT_BITS == 6 + retval |= (retval & 0x0400) >> 5; +#endif -#define COLOR_SUB(C1, C2) \ -(GFX.ZERO_OR_X2 [(((C1) | RGB_HI_BITS_MASKx2) - \ - ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1] + \ - ((C1) & RGB_LOW_BITS_MASK) - \ - ((C2) & RGB_LOW_BITS_MASK)) + return retval; +} -#define COLOR_SUB1_2(C1, C2) \ -GFX.ZERO [(((C1) | RGB_HI_BITS_MASKx2) - \ - ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1] +static INLINE uint16_t COLOR_SUB1_2(uint16_t C1, uint16_t C2) +{ + return GFX.ZERO[(((C1) | RGB_HI_BITS_MASKx2) - ((C2)&RGB_REMOVE_LOW_BITS_MASK)) >> 1]; +} typedef void (*NormalTileRenderer)(uint32_t Tile, int32_t Offset, uint32_t StartLine, uint32_t LineCount); typedef void (*ClippedTileRenderer)(uint32_t Tile, int32_t Offset, uint32_t StartPixel, uint32_t Width, uint32_t StartLine, uint32_t LineCount); diff --git a/source/pixform.h b/source/pixform.h index f9c075c..4a61ae2 100644 --- a/source/pixform.h +++ b/source/pixform.h @@ -12,6 +12,8 @@ #define MAX_RED_RGB565 31 #define MAX_GREEN_RGB565 63 #define MAX_BLUE_RGB565 31 +#define RED_SHIFT_BITS_RGB565 11 +#define GREEN_SHIFT_BITS_RGB565 6 #define RED_LOW_BIT_MASK_RGB565 0x0800 #define GREEN_LOW_BIT_MASK_RGB565 0x0020 #define BLUE_LOW_BIT_MASK_RGB565 0x0001 @@ -32,6 +34,8 @@ #define MAX_RED_RGB555 31 #define MAX_GREEN_RGB555 31 #define MAX_BLUE_RGB555 31 +#define RED_SHIFT_BITS_RGB555 10 +#define GREEN_SHIFT_BITS_RGB555 5 #define RED_LOW_BIT_MASK_RGB555 0x0400 #define GREEN_LOW_BIT_MASK_RGB555 0x0020 #define BLUE_LOW_BIT_MASK_RGB555 0x0001 @@ -43,107 +47,6 @@ #define THIRD_COLOR_MASK_RGB555 0x001F #define ALPHA_BITS_MASK_RGB555 0x0000 -/* BGR565 format */ -#define BUILD_PIXEL_BGR565(R,G,B) (((int32_t) (B) << 11) | ((int32_t) (G) << 6) | (int32_t) (R)) -#define BUILD_PIXEL2_BGR565(R,G,B) (((int32_t) (B) << 11) | ((int32_t) (G) << 5) | (int32_t) (R)) -#define DECOMPOSE_PIXEL_BGR565(PIX,R,G,B) {(B) = (PIX) >> 11; (G) = ((PIX) >> 6) & 0x1f; (R) = (PIX) & 0x1f; } -#define SPARE_RGB_BIT_MASK_BGR565 (1 << 5) - -#define MAX_RED_BGR565 31 -#define MAX_GREEN_BGR565 63 -#define MAX_BLUE_BGR565 31 -#define RED_LOW_BIT_MASK_BGR565 0x0001 -#define GREEN_LOW_BIT_MASK_BGR565 0x0040 -#define BLUE_LOW_BIT_MASK_BGR565 0x0800 -#define RED_HI_BIT_MASK_BGR565 0x0010 -#define GREEN_HI_BIT_MASK_BGR565 0x0400 -#define BLUE_HI_BIT_MASK_BGR565 0x8000 -#define FIRST_COLOR_MASK_BGR565 0xF800 -#define SECOND_COLOR_MASK_BGR565 0x07E0 -#define THIRD_COLOR_MASK_BGR565 0x001F -#define ALPHA_BITS_MASK_BGR565 0x0000 - -/* BGR555 format */ -#define BUILD_PIXEL_BGR555(R,G,B) (((int32_t) (B) << 10) | ((int32_t) (G) << 5) | (int32_t) (R)) -#define BUILD_PIXEL2_BGR555(R,G,B) (((int32_t) (B) << 10) | ((int32_t) (G) << 5) | (int32_t) (R)) -#define DECOMPOSE_PIXEL_BGR555(PIX,R,G,B) {(B) = (PIX) >> 10; (G) = ((PIX) >> 5) & 0x1f; (R) = (PIX) & 0x1f; } -#define SPARE_RGB_BIT_MASK_BGR555 (1 << 15) - -#define MAX_RED_BGR555 31 -#define MAX_GREEN_BGR555 31 -#define MAX_BLUE_BGR555 31 -#define RED_LOW_BIT_MASK_BGR555 0x0001 -#define GREEN_LOW_BIT_MASK_BGR555 0x0020 -#define BLUE_LOW_BIT_MASK_BGR555 0x0400 -#define RED_HI_BIT_MASK_BGR555 0x0010 -#define GREEN_HI_BIT_MASK_BGR555 0x0200 -#define BLUE_HI_BIT_MASK_BGR555 0x4000 -#define FIRST_COLOR_MASK_BGR555 0x7C00 -#define SECOND_COLOR_MASK_BGR555 0x03E0 -#define THIRD_COLOR_MASK_BGR555 0x001F -#define ALPHA_BITS_MASK_BGR555 0x0000 - -/* GBR565 format */ -#define BUILD_PIXEL_GBR565(R,G,B) (((int32_t) (G) << 11) | ((int32_t) (B) << 6) | (int32_t) (R)) -#define BUILD_PIXEL2_GBR565(R,G,B) (((int32_t) (G) << 11) | ((int32_t) (B) << 5) | (int32_t) (R)) -#define DECOMPOSE_PIXEL_GBR565(PIX,R,G,B) {(G) = (PIX) >> 11; (B) = ((PIX) >> 6) & 0x1f; (R) = (PIX) & 0x1f; } -#define SPARE_RGB_BIT_MASK_GBR565 (1 << 5) - -#define MAX_RED_GBR565 31 -#define MAX_BLUE_GBR565 63 -#define MAX_GREEN_GBR565 31 -#define RED_LOW_BIT_MASK_GBR565 0x0001 -#define BLUE_LOW_BIT_MASK_GBR565 0x0040 -#define GREEN_LOW_BIT_MASK_GBR565 0x0800 -#define RED_HI_BIT_MASK_GBR565 0x0010 -#define BLUE_HI_BIT_MASK_GBR565 0x0400 -#define GREEN_HI_BIT_MASK_GBR565 0x8000 -#define FIRST_COLOR_MASK_GBR565 0xF800 -#define SECOND_COLOR_MASK_GBR565 0x07E0 -#define THIRD_COLOR_MASK_GBR565 0x001F -#define ALPHA_BITS_MASK_GBR565 0x0000 - -/* GBR555 format */ -#define BUILD_PIXEL_GBR555(R,G,B) (((int32_t) (G) << 10) | ((int32_t) (B) << 5) | (int32_t) (R)) -#define BUILD_PIXEL2_GBR555(R,G,B) (((int32_t) (G) << 10) | ((int32_t) (B) << 5) | (int32_t) (R)) -#define DECOMPOSE_PIXEL_GBR555(PIX,R,G,B) {(G) = (PIX) >> 10; (B) = ((PIX) >> 5) & 0x1f; (R) = (PIX) & 0x1f; } -#define SPARE_RGB_BIT_MASK_GBR555 (1 << 15) - -#define MAX_RED_GBR555 31 -#define MAX_BLUE_GBR555 31 -#define MAX_GREEN_GBR555 31 -#define RED_LOW_BIT_MASK_GBR555 0x0001 -#define BLUE_LOW_BIT_MASK_GBR555 0x0020 -#define GREEN_LOW_BIT_MASK_GBR555 0x0400 -#define RED_HI_BIT_MASK_GBR555 0x0010 -#define BLUE_HI_BIT_MASK_GBR555 0x0200 -#define GREEN_HI_BIT_MASK_GBR555 0x4000 -#define FIRST_COLOR_MASK_GBR555 0x7C00 -#define SECOND_COLOR_MASK_GBR555 0x03E0 -#define THIRD_COLOR_MASK_GBR555 0x001F -#define ALPHA_BITS_MASK_GBR555 0x0000 - -/* RGB5551 format */ -#define BUILD_PIXEL_RGB5551(R,G,B) (((int32_t) (R) << 11) | ((int32_t) (G) << 6) | (int32_t) ((B) << 1) | 1) -#define BUILD_PIXEL2_RGB5551(R,G,B) (((int32_t) (R) << 11) | ((int32_t) (G) << 6) | (int32_t) ((B) << 1) | 1) -#define DECOMPOSE_PIXEL_RGB5551(PIX,R,G,B) {(R) = (PIX) >> 11; (G) = ((PIX) >> 6) & 0x1f; (B) = ((PIX) >> 1) & 0x1f; } -#define SPARE_RGB_BIT_MASK_RGB5551 (1) - -#define MAX_RED_RGB5551 31 -#define MAX_GREEN_RGB5551 31 -#define MAX_BLUE_RGB5551 31 -#define RED_LOW_BIT_MASK_RGB5551 0x0800 -#define GREEN_LOW_BIT_MASK_RGB5551 0x0040 -#define BLUE_LOW_BIT_MASK_RGB5551 0x0002 -#define RED_HI_BIT_MASK_RGB5551 0x8000 -#define GREEN_HI_BIT_MASK_RGB5551 0x0400 -#define BLUE_HI_BIT_MASK_RGB5551 0x0020 -#define FIRST_COLOR_MASK_RGB5551 0xf800 -#define SECOND_COLOR_MASK_RGB5551 0x07c0 -#define THIRD_COLOR_MASK_RGB5551 0x003e -#define ALPHA_BITS_MASK_RGB5551 0x0001 - - #define CONCAT(X,Y) X##Y /* C pre-processor needs a two stage macro define to enable it to concat @@ -159,6 +62,8 @@ #define MAX_RED_D(F) CONCAT(MAX_RED_,F) #define MAX_BLUE_D(F) CONCAT(MAX_BLUE_,F) #define MAX_GREEN_D(F) CONCAT(MAX_GREEN_,F) +#define RED_SHIFT_BITS_D(F) CONCAT(RED_SHIFT_BITS_, F) +#define GREEN_SHIFT_BITS_D(F) CONCAT(GREEN_SHIFT_BITS_, F) #define RED_LOW_BIT_MASK_D(F) CONCAT(RED_LOW_BIT_MASK_,F) #define BLUE_LOW_BIT_MASK_D(F) CONCAT(BLUE_LOW_BIT_MASK_,F) #define GREEN_LOW_BIT_MASK_D(F) CONCAT(GREEN_LOW_BIT_MASK_,F) @@ -173,6 +78,8 @@ #define MAX_RED MAX_RED_D(PIXEL_FORMAT) #define MAX_BLUE MAX_BLUE_D(PIXEL_FORMAT) #define MAX_GREEN MAX_GREEN_D(PIXEL_FORMAT) +#define RED_SHIFT_BITS RED_SHIFT_BITS_D(PIXEL_FORMAT) +#define GREEN_SHIFT_BITS GREEN_SHIFT_BITS_D(PIXEL_FORMAT) #define RED_LOW_BIT_MASK RED_LOW_BIT_MASK_D(PIXEL_FORMAT) #define BLUE_LOW_BIT_MASK BLUE_LOW_BIT_MASK_D(PIXEL_FORMAT) #define GREEN_LOW_BIT_MASK GREEN_LOW_BIT_MASK_D(PIXEL_FORMAT) diff --git a/source/port.h b/source/port.h index 06c5f5e..6c3425c 100644 --- a/source/port.h +++ b/source/port.h @@ -14,11 +14,7 @@ #include <sys/types.h> #include <retro_inline.h> -#ifdef PSP -#define PIXEL_FORMAT BGR555 -#else #define PIXEL_FORMAT RGB565 -#endif /* The above is used to disable the 16-bit graphics mode checks sprinkled * throughout the code, if the pixel format is always 16-bit. */ |