NESe (pronounced "Nessie") is a NES emulator based on the e6502 emulator, also written in C with a focus on speed and portability for use on embedded platforms, especially ARM.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

72 satır
1.9KB

  1. #include "sdl_effect.h"
  2. /*
  3. static const uint8_t the_effect[3][3][4] = {
  4. {{14, 0, 216, 204}, {16, 0, 0, 217}, {21, 225, 1, 0},},
  5. {{81, 0, 1, 1}, {83, 1, 0, 3}, {72, 2, 0, 0},},
  6. {{ 5, 0, 252, 245}, { 6, 0, 0, 243}, {10, 236, 1, 0},},
  7. };
  8. static const int effect_w = 3;
  9. static const int effect_h = 3;
  10. */
  11. static const uint8_t the_effect[2][2][4] = {
  12. {{ 25, 0, 0, 0}, { 1, 0, 0, 0},},
  13. {{144, 0, 0, 0}, {133, 0, 0, 0},},
  14. };
  15. static const int effect_w = 2;
  16. static const int effect_h = 2;
  17. sdl_effect* effect_init(SDL_Renderer* renderer,
  18. int view_w, int view_h) {
  19. const int tex_w = view_w * 2;
  20. const int tex_h = view_h * 2;
  21. SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
  22. SDL_Texture* effect = SDL_CreateTexture(
  23. renderer, SDL_PIXELFORMAT_BGRA8888,
  24. SDL_TEXTUREACCESS_STREAMING, tex_w, tex_h
  25. );
  26. void* pixels = NULL;
  27. int pitch = 0;
  28. SDL_LockTexture(effect, NULL, &pixels, &pitch);
  29. uint8_t* dst_line = (uint8_t*)pixels;
  30. for (int y = 0; y < tex_h; ++y) {
  31. uint8_t* dst = dst_line;
  32. for (int x = 0; x < tex_w; ++x) {
  33. dst[0] = the_effect[y % effect_h][x % effect_w][0];
  34. dst[1] = the_effect[y % effect_h][x % effect_w][1];
  35. dst[2] = the_effect[y % effect_h][x % effect_w][2];
  36. dst[3] = the_effect[y % effect_h][x % effect_w][3];
  37. dst += 4;
  38. }
  39. dst_line += pitch;
  40. }
  41. SDL_UnlockTexture(effect);
  42. SDL_SetTextureBlendMode(effect, SDL_BLENDMODE_BLEND);
  43. return (sdl_effect*)effect;
  44. }
  45. void effect_done(sdl_effect* effect) {
  46. if (effect) {
  47. SDL_DestroyTexture((SDL_Texture*)effect);
  48. }
  49. }
  50. void effect_apply(sdl_effect* effect, SDL_Renderer* renderer,
  51. const SDL_Rect* rect) {
  52. if (effect) {
  53. SDL_RenderCopy(renderer, (SDL_Texture*)effect,
  54. NULL, rect);
  55. }
  56. }