#include //#define STB_IMAGE_IMPLEMENTATION //#include "stb_image.h" #include #include "font.h" #define VDP_CMD_LOCATE 0 #define VDP_CMD_PRINT 1 #define VDP_CMD_PUTCHAR 2 #define VDP_CMD_SETCHAR 3 #define VDP_CMD_PUTSPRITE 4 #define VDP_CMD_SETSPRITE 5 #define VDP_CMD_FLIP 6 #define VDP_CMD_COLOR 7 #define VDP_CMD_BORDER 8 SDL_Window* sdlWindow = NULL; SDL_Renderer* sdlRenderer = NULL; SDL_Texture* sdlTexture = NULL; SDL_Rect src, dst; const Uint8* keys = nullptr; Uint8 just_pressed = SDL_SCANCODE_UNKNOWN; Uint8 screen_map[16 * 12]; Uint8 screen_color[16 * 12]; //Uint8 char_map[256 * 8]; Uint8 screen_buffer[128 * 96 * 4]; static Uint8 cursor_x = 0; static Uint8 cursor_y = 0; static Uint8 color = 0x24; static Uint8 border = 0x02; static Uint8 data_stack[256]; static int data_stack_pos = 0; static Uint8 palette[16][4] = { { 255, 0, 0, 255 }, { 255, 0, 255, 0 }, { 255, 255, 0, 0 }, { 255, 255, 0, 255 }, { 255, 0, 255, 255 }, { 255, 255, 255, 0 }, { 255, 255, 255, 255 }, { 255, 0, 0, 0 }, { 255, 0, 0, 128 }, { 255, 0, 128, 0 }, { 255, 128, 0, 0 }, { 255, 128, 0, 128 }, { 255, 0, 128, 128 }, { 255, 128, 128, 0 }, { 255, 128, 128, 128 }, { 255, 0, 0, 0 }, }; void vdp_init() { SDL_Init(SDL_INIT_EVERYTHING); sdlWindow = SDL_CreateWindow("PaCo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 608, 480, SDL_WINDOW_SHOWN); sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_PRESENTVSYNC); //SDL_SetRenderDrawBlendMode(sdlRenderer, SDL_BLENDMODE_BLEND); SDL_RenderSetLogicalSize(sdlRenderer, 152, 120); //jtexture texture = (jtexture)malloc(sizeof(jtexture_t)); //FILE* f = fopen("font.png", "rb"); //if (!f) { error = 2; return; } //int c; //int size = 128; //Uint8* buffer = stbi_load_from_file(f, &size, &size, &c, 4); sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, 128, 128); //SDL_UpdateTexture(sdlTexture, NULL, buffer, 128 * sizeof(Uint32)); //SDL_SetTextureBlendMode(sdlTexture, SDL_BLENDMODE_BLEND); //stbi_image_free(buffer); //fclose(f); src.x = src.y = 0; dst.x = dst.y = 12; src.w = dst.w = 128; src.h = dst.h = 96; } void vdp_quit() { SDL_DestroyTexture(sdlTexture); SDL_DestroyRenderer(sdlRenderer); SDL_DestroyWindow(sdlWindow); SDL_Quit(); } static void flip() { Uint8* sb = screen_buffer; Uint8* sm = screen_map; Uint8* sc = screen_color; for (int y = 0; y < 12; y++) { for (int x = 0; x < 16; x++) { Uint8* cm = &char_map[*sm << 3]; Uint8* sbt = sb; for (int l = 0; l < 8; l++) { if (*cm & 128) memcpy(sbt, palette[*sc & 0x0F], 4); else memcpy(sbt, palette[*sc >> 4], 4); sbt += 4; if (*cm & 64) memcpy(sbt, palette[*sc & 0x0F], 4); else memcpy(sbt, palette[*sc >> 4], 4); sbt += 4; if (*cm & 32) memcpy(sbt, palette[*sc & 0x0F], 4); else memcpy(sbt, palette[*sc >> 4], 4); sbt += 4; if (*cm & 16) memcpy(sbt, palette[*sc & 0x0F], 4); else memcpy(sbt, palette[*sc >> 4], 4); sbt += 4; if (*cm & 8) memcpy(sbt, palette[*sc & 0x0F], 4); else memcpy(sbt, palette[*sc >> 4], 4); sbt += 4; if (*cm & 4) memcpy(sbt, palette[*sc & 0x0F], 4); else memcpy(sbt, palette[*sc >> 4], 4); sbt += 4; if (*cm & 2) memcpy(sbt, palette[*sc & 0x0F], 4); else memcpy(sbt, palette[*sc >> 4], 4); sbt += 4; if (*cm & 1) memcpy(sbt, palette[*sc & 0x0F], 4); else memcpy(sbt, palette[*sc >> 4], 4); sbt += 512; cm++; } sm++; sc++; sb += 32; } sb += 3584; } SDL_UpdateTexture(sdlTexture, NULL, screen_buffer, 128 * sizeof(Uint32)); SDL_RenderCopy(sdlRenderer, sdlTexture, &src, &dst); SDL_RenderPresent(sdlRenderer); } void vdp_data_out(const unsigned char& value) { data_stack[data_stack_pos++] = value; } void vdp_cmd_out(const unsigned char& value) { Uint8 n; switch (value) { case VDP_CMD_LOCATE: cursor_y = data_stack[--data_stack_pos]; cursor_x = data_stack[--data_stack_pos]; break; case VDP_CMD_PRINT: for (int i = 0; i < data_stack_pos; i++) { screen_map[cursor_x + (cursor_y << 7)] = data_stack[i]; screen_color[cursor_x + (cursor_y << 7)] = color; cursor_x++; if (cursor_x == 16) { cursor_x = 0; cursor_y++; } } break; case VDP_CMD_PUTCHAR: cursor_x = data_stack[data_stack_pos - 4]; cursor_y = data_stack[data_stack_pos - 3]; screen_map[cursor_x + (cursor_y << 7)] = data_stack[data_stack_pos-2]; screen_color[cursor_x + (cursor_y << 7)] = data_stack[data_stack_pos - 1]; break; case VDP_CMD_SETCHAR: n = data_stack[data_stack_pos - 9]; char_map[(n << 3)] = data_stack[data_stack_pos - 8]; char_map[(n << 3) + 1] = data_stack[data_stack_pos - 7]; char_map[(n << 3) + 2] = data_stack[data_stack_pos - 6]; 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) + 5] = data_stack[data_stack_pos - 3]; char_map[(n << 3) + 6] = data_stack[data_stack_pos - 2]; char_map[(n << 3) + 7] = data_stack[data_stack_pos - 1]; break; case VDP_CMD_PUTSPRITE: break; case VDP_CMD_SETSPRITE: break; case VDP_CMD_FLIP: flip(); break; case VDP_CMD_COLOR: color = data_stack[0]; break; case VDP_CMD_BORDER: border = data_stack[0]; break; } data_stack_pos = 0; } unsigned char vdp_in() { return 0; } /*int main(int argc, char* argv[]) { static bool should_quit = false; static SDL_Event sdlEvent; while (!should_quit) { just_pressed = SDL_SCANCODE_UNKNOWN; while (SDL_PollEvent(&sdlEvent)) { if (sdlEvent.type == SDL_QUIT) { should_quit = true; break; } else if (sdlEvent.type == SDL_KEYDOWN) { //anyKey = true; just_pressed = sdlEvent.key.keysym.scancode; if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_ESCAPE) { should_quit = true; } } } //if (!should_quit) should_quit = currentLoop(); } vbm_quit(); return 0; }*/