Skip to content

Commit

Permalink
Attempt 8x16 sprite sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Leslie committed Oct 2, 2019
1 parent 494d928 commit 27cc6fc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
6 changes: 3 additions & 3 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "cpu.h"
#include "mem.h"

#define TILE_WIDTH 128
#define TILE_HEIGHT 128
#define TILE_WIDTH 256
#define TILE_HEIGHT 96

typedef struct {
SDL_Window *window;
Expand Down Expand Up @@ -271,7 +271,7 @@ void display_init(){
exit(1);
}
atexit(SDL_Quit);
//display_create_window(tile_window, "tile map", TILE_WIDTH, TILE_HEIGHT);
display_create_window(tile_window, "tile map", TILE_WIDTH, TILE_HEIGHT);
//display_create_window(disp_mem_window, "display memory map", TILE_WIDTH, TILE_HEIGHT);
display_create_window(window, "lgb", WIDTH, HEIGHT);
display.exit = 0;
Expand Down
55 changes: 32 additions & 23 deletions gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,12 @@ u8 gpu_get_scroll_y(){
}

void gpu_set_window_x(const u8 value){
printf("This game is using the window\n");
gpu->window_x = value;
}
u8 gpu_get_window_x(){
return gpu->window_x;
}
void gpu_set_window_y(const u8 value){
printf("This game is using the window\n");
gpu->window_y = value;
}
u8 gpu_get_window_y(){
Expand Down Expand Up @@ -268,36 +266,46 @@ static void render_scan(){
if(gpu->sprite_display_enable){
for(int i = 0; i < NUM_SPRITES; i++){
Sprite *sprite = &gpu->sprites[i];
if(sprite->y <= gpu->line && (sprite->y + 8) > gpu->line){
printf("rendering sprite %d tile %d x %d y %d gpu line %d\n",
i, sprite->tile, sprite->x, sprite->y, gpu->line);
if(sprite->y <= gpu->line &&
((!gpu->sprite_size && (sprite->y + 8) > gpu->line) ||
(gpu->sprite_size && (sprite->y + 16) > gpu->line)))
{
u8 *tilerow;
if(sprite->yflip) {
if(gpu->sprite_size)
{
if(15 - (gpu->line - sprite->y) < 8)
tilerow = gpu->tiles[sprite->tile]
[15 - (gpu->line - sprite->y)];
else
tilerow = gpu->tiles[sprite->tile + 1]
[7 - (gpu->line - sprite->y)];
}

else
tilerow = gpu->tiles[sprite->tile]
[7 - (gpu->line - sprite->y)];
} else {
if(gpu->sprite_size && gpu->line - sprite->y > 7 )
tilerow = gpu->tiles[sprite->tile + 1][gpu->line - sprite->y - 8];
else
tilerow = gpu->tiles[sprite->tile][gpu->line - sprite->y];
}
}

u8 *palette = sprite->palette ? gpu->object_palette1_colours :
gpu->object_palette0_colours;
gpu->object_palette0_colours;

for(int x = 0; x < 8; x++){
if ((sprite->x + x) >= 0 && (sprite->x + x) < WIDTH
// Check it's not transparent
/* Disable check for now to debug */
/*palette[tilerow[sprite->xflip ? (7 - x) : x]] &&*/
&& (sprite->prio || !gpu->scanrow[sprite->x + x]))
{
gpu->frame_buffer[gpu->line][sprite->x + x] =
palette[tilerow[sprite->xflip ? (7 - x) : x]];
}
}
}
/* else
printf("Not rendering sprite %d tile %d x %d y %d gpu line %d\n",
i, sprite->tile, sprite->x, sprite->y, gpu->line);*/
}
for(int x = 0; x < 8; x++){
if ((sprite->x + x) >= 0 && (sprite->x + x) < WIDTH &&
palette[tilerow[sprite->xflip ? (7 - x) : x]] &&
(sprite->prio || !gpu->scanrow[sprite->x + x]))
{
gpu->frame_buffer[gpu->line][sprite->x + x] =
palette[tilerow[sprite->xflip ? (7 - x) : x]];
}
}
}
}
}
}

Expand All @@ -310,6 +318,7 @@ static void swap_buffers(){
}
if(gpu->lcd_display_enable)
display_redraw();
#define SLEEP
#ifdef SLEEP
/* Sleep until the frame time is finished */
struct timespec frame_end_time;
Expand Down

0 comments on commit 27cc6fc

Please sign in to comment.