Sprites implemented. ROM updated. minor corrections.

This commit is contained in:
2017-01-30 13:01:20 +01:00
parent 4011beaf7b
commit 0135efd688

57
vdp.cpp
View File

@@ -14,6 +14,13 @@
#define VDP_CMD_COLOR 7 #define VDP_CMD_COLOR 7
#define VDP_CMD_BORDER 8 #define VDP_CMD_BORDER 8
struct t_sprite {
Uint8 x = 0;
Uint8 y = 0;
Uint8 tile = 32;
Uint8 col = 1;
};
SDL_Window* sdlWindow = NULL; SDL_Window* sdlWindow = NULL;
SDL_Renderer* sdlRenderer = NULL; SDL_Renderer* sdlRenderer = NULL;
SDL_Texture* sdlTexture = NULL; SDL_Texture* sdlTexture = NULL;
@@ -21,6 +28,8 @@ SDL_Rect src, dst;
const Uint8* keys = nullptr; const Uint8* keys = nullptr;
Uint8 just_pressed = SDL_SCANCODE_UNKNOWN; Uint8 just_pressed = SDL_SCANCODE_UNKNOWN;
t_sprite sprites[32];
Uint8 screen_map[16 * 12]; Uint8 screen_map[16 * 12];
Uint8 screen_color[16 * 12]; Uint8 screen_color[16 * 12];
//Uint8 char_map[256 * 8]; //Uint8 char_map[256 * 8];
@@ -110,6 +119,32 @@ static void flip() {
} }
sb += 3584; //3584; sb += 3584; //3584;
} }
for (int i = 0; i < 32; i++) {
Uint8* cm = &char_map[sprites[i].tile << 3];
Uint8 x = sprites[i].x;
Uint8 y = sprites[i].y;
Uint8 col = sprites[i].col;
Uint8* sbt = &screen_buffer[((x - 8) * 4) + ((y - 8) * 128 * 4)];
for (int l = 0; l < 8; l++) {
if (y >= 8) {
if (((x+0) >= 8) && (*cm & 128)) memcpy(sbt, palette[col & 0x0F], 4); sbt += 4;
if (((x + 1) >= 8) && (*cm & 64)) memcpy(sbt, palette[col & 0x0F], 4); sbt += 4;
if (((x + 2) >= 8) && (*cm & 32)) memcpy(sbt, palette[col & 0x0F], 4); sbt += 4;
if (((x + 3) >= 8) && (*cm & 16)) memcpy(sbt, palette[col & 0x0F], 4); sbt += 4;
if (((x + 4) >= 8) && (*cm & 8)) memcpy(sbt, palette[col & 0x0F], 4); sbt += 4;
if (((x+5) >= 8) && (*cm & 4))
memcpy(sbt, palette[col & 0x0F], 4);
sbt += 4;
if (((x+6) >= 8) && (*cm & 2))
memcpy(sbt, palette[col & 0x0F], 4);
sbt += 4;
if (((x+7) >= 8) && (*cm & 1))
memcpy(sbt, palette[col & 0x0F], 4);
sbt += (512 - 32 + 4);
}
cm++; y++;
}
}
SDL_UpdateTexture(sdlTexture, NULL, screen_buffer, 128 * sizeof(Uint32)); SDL_UpdateTexture(sdlTexture, NULL, screen_buffer, 128 * sizeof(Uint32));
SDL_RenderClear(sdlRenderer); SDL_RenderClear(sdlRenderer);
SDL_RenderCopy(sdlRenderer, sdlTexture, &src, &dst); SDL_RenderCopy(sdlRenderer, sdlTexture, &src, &dst);
@@ -139,19 +174,25 @@ void vdp_cmd_out(const unsigned char& value) {
screen_color[cursor_x + (cursor_y << 4)] = data_stack[data_stack_pos - 4]; screen_color[cursor_x + (cursor_y << 4)] = data_stack[data_stack_pos - 4];
break; break;
case VDP_CMD_SETCHAR: case VDP_CMD_SETCHAR:
n = data_stack[data_stack_pos - 9]; n = data_stack[data_stack_pos - 1];
char_map[(n << 3)] = data_stack[data_stack_pos - 8]; char_map[(n << 3)] = data_stack[data_stack_pos - 2];
char_map[(n << 3) + 1] = data_stack[data_stack_pos - 7]; char_map[(n << 3) + 1] = data_stack[data_stack_pos - 3];
char_map[(n << 3) + 2] = data_stack[data_stack_pos - 6]; char_map[(n << 3) + 2] = data_stack[data_stack_pos - 4];
char_map[(n << 3) + 3] = data_stack[data_stack_pos - 5]; char_map[(n << 3) + 3] = data_stack[data_stack_pos - 5];
char_map[(n << 3) + 4] = data_stack[data_stack_pos - 4]; char_map[(n << 3) + 4] = data_stack[data_stack_pos - 6];
char_map[(n << 3) + 5] = data_stack[data_stack_pos - 3]; char_map[(n << 3) + 5] = data_stack[data_stack_pos - 7];
char_map[(n << 3) + 6] = data_stack[data_stack_pos - 2]; char_map[(n << 3) + 6] = data_stack[data_stack_pos - 8];
char_map[(n << 3) + 7] = data_stack[data_stack_pos - 1]; char_map[(n << 3) + 7] = data_stack[data_stack_pos - 9];
break; break;
case VDP_CMD_PUTSPRITE: case VDP_CMD_PUTSPRITE:
n = data_stack[data_stack_pos - 1];
sprites[n].x = data_stack[data_stack_pos - 2];
sprites[n].y = data_stack[data_stack_pos - 3];
break; break;
case VDP_CMD_SETSPRITE: case VDP_CMD_SETSPRITE:
n = data_stack[data_stack_pos - 1];
sprites[n].tile = data_stack[data_stack_pos - 2];
sprites[n].col = data_stack[data_stack_pos - 3] & 0xF;
break; break;
case VDP_CMD_FLIP: case VDP_CMD_FLIP:
flip(); break; flip(); break;