Changeset cd50b8c in buchla-emu for emu


Ignore:
Timestamp:
09/09/2017 01:45:47 PM (7 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
c6f1cf5
Parents:
18e37d6
Message:

Simplified rendering.

Location:
emu
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • emu/lcd.c

    r18e37d6 rcd50b8c  
    2727#define WIN_H (64 * 2)
    2828
    29 #define CON_BGR 0x00000000
    30 #define CON_DRW 0xFFFFFFFF
    31 #define CON_FGR ((SDL_Color){ .r = 255, .b = 255, .g = 255, .a = 255 })
     29#define GFX_BGR 0x00000000
     30#define GFX_FGR 0xFFFFFFFF
     31
     32#define TXT_BGR 0x000000FF
     33#define TXT_FGR ((SDL_Color){ .r = 255, .b = 255, .g = 255, .a = 255 })
    3234
    3335#define REG_ARG 0
     
    5961#define GFX_W 85
    6062#define GFX_H 64
     63#define GFX_PIX 6
    6164
    6265#define BASE_TXT 0x0000
     
    7881static int32_t fon_w, fon_h;
    7982
    80 static int32_t sur_w, sur_h;
    81 static SDL_Surface *sur;
    82 static SDL_Surface *gfx_sur;
     83static int32_t txt_w, txt_h;
     84static SDL_Surface *txt;
     85static SDL_Texture *gfx;
    8386
    8487static int32_t com;
     
    101104        last = now;
    102105
    103         if (SDL_FillRect(sur, NULL, CON_BGR) < 0) {
     106        void *buf;
     107        int32_t pitch;
     108
     109        if (SDL_LockTexture(gfx, NULL, &buf, &pitch) < 0) {
     110                fail("SDL_LockTexture() failed: %s", SDL_GetError());
     111        }
     112
     113        uint32_t *pix = buf;
     114
     115        for (int32_t y = 0; y < GFX_H; ++y) {
     116                for (int32_t x = 0; x < GFX_W * GFX_PIX; ++x) {
     117                        *pix++ = GFX_BGR;
     118                }
     119
     120                pix += pitch / 4 - GFX_W * GFX_PIX;
     121        }
     122
     123        if (SDL_AtomicGet(&ena) == 0) {
     124                SDL_UnlockTexture(gfx);
     125
     126                if (SDL_RenderCopy(ren, gfx, NULL, NULL) < 0) {
     127                        fail("SDL_RenderCopy() failed: %s", SDL_GetError());
     128                }
     129
     130                SDL_RenderPresent(ren);
     131                return;
     132        }
     133
     134        pix = buf;
     135
     136        for (int32_t y = 0; y < GFX_H; ++y) {
     137                for (int32_t x = 0; x < GFX_W; ++x) {
     138                        uint8_t b = mem_gfx[y * GFX_W + x];
     139
     140                        for (int32_t p = 0; p < GFX_PIX; ++p) {
     141                                if ((b & (1 << (7 - p))) != 0) {
     142                                        *pix = GFX_FGR;
     143                                }
     144
     145                                ++pix;
     146                        }
     147                }
     148
     149                pix += pitch / 4 - GFX_W * GFX_PIX;
     150        }
     151
     152        SDL_UnlockTexture(gfx);
     153
     154        if (SDL_FillRect(txt, NULL, TXT_BGR) < 0) {
    104155                fail("SDL_FillRect() failed: %s", SDL_GetError());
    105         }
    106 
    107         if (SDL_AtomicGet(&ena) == 0) {
    108                 return;
    109156        }
    110157
     
    116163                }
    117164
    118                 for (int32_t x = 0; x < TXT_W; ++x) {
    119                         uint8_t c = mem_txt[y * TXT_W + x];
    120                         line[x] = (char)(c == 0x00 ? ' ' : c);
    121                 }
    122 
    123                 line[TXT_W] = 0;
     165                memcpy(line, mem_txt + y * TXT_W, TXT_W);
    124166
    125167                if (SDL_UnlockMutex(cpu_mutex) < 0) {
     
    127169                }
    128170
    129                 SDL_Surface *lin = TTF_RenderText_Blended(fon, line, CON_FGR);
     171                for (int32_t x = 0; x < TXT_W; ++x) {
     172                        if (line[x] == 0x00) {
     173                                line[x] = ' ';
     174                        }
     175                }
     176
     177                line[TXT_W] = 0;
     178
     179                SDL_Surface *lin = TTF_RenderText_Blended(fon, line, TXT_FGR);
    130180
    131181                if (lin == NULL) {
     
    133183                }
    134184
    135                 if (SDL_BlitSurface(lin, NULL, sur, &(SDL_Rect){
     185                if (SDL_BlitSurface(lin, NULL, txt, &(SDL_Rect){
    136186                        .x = 0,
    137187                        .y = y * fon_h,
     
    145195        }
    146196
    147         SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, sur);
     197        SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, txt);
    148198
    149199        if (tex == NULL) {
     
    155205        }
    156206
    157         for (int32_t y = 0; y < GFX_H * GFX_W; ++y) {
    158                 for (int32_t p = 7; p > 1; --p) {
    159                         uint32_t col = CON_BGR;
    160                         if ((mem_gfx[y] & (1 << p)) > 0) {
    161                                 col = CON_DRW;
    162                         }
    163 
    164                         if (SDL_FillRect(gfx_sur, &(SDL_Rect){
    165                                 .x = y % 85 * fon_w + (8 - p) * fon_w / 6,
    166                                 .y = y / 85 * fon_h / 8,
    167                                 .w = fon_w / 6 + 1,
    168                                 .h = fon_h / 8 + 1
    169                         }, col) < 0) {
    170                                 fail("SDL_FillRect() failed: %s", SDL_GetError());
    171                         }
    172                 }
    173         }
    174 
    175         SDL_Texture *gfx_tex = SDL_CreateTextureFromSurface(ren, gfx_sur);
    176 
    177         if (gfx_tex == NULL) {
    178                 fail("SDL_CreateTextureFromSurface() failed: %s", SDL_GetError());
    179         }
    180 
    181         if (SDL_SetTextureBlendMode(gfx_tex, SDL_BLENDMODE_ADD) < 0) {
    182                 fail("SDL_SetTextureBlendMode() failed: %s", SDL_GetError());
    183         }
    184 
    185         if (SDL_RenderCopy(ren, gfx_tex, NULL, NULL) < 0) {
     207        SDL_DestroyTexture(tex);
     208
     209        if (SDL_RenderCopy(ren, gfx, NULL, NULL) < 0) {
    186210                fail("SDL_RenderCopy() failed: %s", SDL_GetError());
    187211        }
    188212
    189         SDL_DestroyTexture(tex);
    190         SDL_DestroyTexture(gfx_tex);
    191213        SDL_RenderPresent(ren);
    192214}
     
    196218        ver("lcd init");
    197219
    198         win = SDL_CreateWindow("Front LCD", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
     220        win = SDL_CreateWindow("LCD", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
    199221                        WIN_W, WIN_H, 0);
    200222
     
    209231        }
    210232
    211         SDL_AtomicSet(&frame, 1);
    212         SDL_AtomicSet(&ena, 0);
     233        gfx = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING,
     234                        GFX_W * GFX_PIX, GFX_H);
     235
     236        if (gfx == NULL) {
     237                fail("SDL_CreateTexture() failed: %s", SDL_GetError());
     238        }
     239
     240        if (SDL_SetTextureBlendMode(gfx, SDL_BLENDMODE_BLEND) < 0) {
     241                fail("SDL_SetTextureBlendMode() failed: %s", SDL_GetError());
     242        }
    213243
    214244        SDL_RWops *ops = SDL_RWFromFile(font, "rb");
     
    230260        }
    231261
    232         sur_w = TXT_W * fon_w;
    233         sur_h = TXT_H * fon_h;
    234 
    235         sur = SDL_CreateRGBSurface(0, sur_w, sur_h, 32, 0, 0, 0, 0);
    236 
    237         if (sur == NULL) {
     262        txt_w = TXT_W * fon_w;
     263        txt_h = TXT_H * fon_h;
     264
     265        txt = SDL_CreateRGBSurfaceWithFormat(0, txt_w, txt_h, 32, SDL_PIXELFORMAT_RGBA8888);
     266
     267        if (txt == NULL) {
    238268                fail("SDL_CreateRGBSurface() failed: %s", SDL_GetError());
    239269        }
    240270
    241         gfx_sur = SDL_CreateRGBSurface(0, sur_w, sur_h, 32, 0, 0, 0, 0);
    242 
    243         if (gfx_sur == NULL) {
    244                 fail("SDL_CreateRGBSurface() failed: %s", SDL_GetError());
    245         }
    246 
    247         for (int32_t y = 0; y < TXT_W * TXT_H; ++y) {
    248                 mem_txt[y] = ' ';
     271        for (int32_t i = 0; i < TXT_W * TXT_H; ++i) {
     272                mem_txt[i] = ' ';
    249273        }
    250274}
     
    254278        ver("lcd quit");
    255279
    256         SDL_FreeSurface(sur);
    257         SDL_FreeSurface(gfx_sur);
     280        SDL_FreeSurface(txt);
    258281        TTF_CloseFont(fon);
     282
     283        SDL_DestroyTexture(gfx);
    259284
    260285        SDL_DestroyRenderer(ren);
     
    272297        ver2("lcd rd %u:%d", off, sz * 8);
    273298
    274         if (sz != 1 || off > 0) {
     299        if (sz != 1 || off != 1) {
    275300                fail("invalid lcd rd %u:%d", off, sz * 8);
    276301        }
  • emu/vid.c

    r18e37d6 rcd50b8c  
    231231        ver("vid init");
    232232
    233         win = SDL_CreateWindow("Display", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
     233        win = SDL_CreateWindow("Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
    234234                        WIN_W, WIN_H, 0);
    235235
Note: See TracChangeset for help on using the changeset viewer.