Changeset cd50b8c in buchla-emu
- Timestamp:
- 09/09/2017 01:45:47 PM (7 years ago)
- Branches:
- master
- Children:
- c6f1cf5
- Parents:
- 18e37d6
- Location:
- emu
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/lcd.c
r18e37d6 rcd50b8c 27 27 #define WIN_H (64 * 2) 28 28 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 }) 32 34 33 35 #define REG_ARG 0 … … 59 61 #define GFX_W 85 60 62 #define GFX_H 64 63 #define GFX_PIX 6 61 64 62 65 #define BASE_TXT 0x0000 … … 78 81 static int32_t fon_w, fon_h; 79 82 80 static int32_t sur_w, sur_h;81 static SDL_Surface * sur;82 static SDL_ Surface *gfx_sur;83 static int32_t txt_w, txt_h; 84 static SDL_Surface *txt; 85 static SDL_Texture *gfx; 83 86 84 87 static int32_t com; … … 101 104 last = now; 102 105 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) { 104 155 fail("SDL_FillRect() failed: %s", SDL_GetError()); 105 }106 107 if (SDL_AtomicGet(&ena) == 0) {108 return;109 156 } 110 157 … … 116 163 } 117 164 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); 124 166 125 167 if (SDL_UnlockMutex(cpu_mutex) < 0) { … … 127 169 } 128 170 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); 130 180 131 181 if (lin == NULL) { … … 133 183 } 134 184 135 if (SDL_BlitSurface(lin, NULL, sur, &(SDL_Rect){185 if (SDL_BlitSurface(lin, NULL, txt, &(SDL_Rect){ 136 186 .x = 0, 137 187 .y = y * fon_h, … … 145 195 } 146 196 147 SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, sur);197 SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, txt); 148 198 149 199 if (tex == NULL) { … … 155 205 } 156 206 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) { 186 210 fail("SDL_RenderCopy() failed: %s", SDL_GetError()); 187 211 } 188 212 189 SDL_DestroyTexture(tex);190 SDL_DestroyTexture(gfx_tex);191 213 SDL_RenderPresent(ren); 192 214 } … … 196 218 ver("lcd init"); 197 219 198 win = SDL_CreateWindow(" FrontLCD", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,220 win = SDL_CreateWindow("LCD", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 199 221 WIN_W, WIN_H, 0); 200 222 … … 209 231 } 210 232 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 } 213 243 214 244 SDL_RWops *ops = SDL_RWFromFile(font, "rb"); … … 230 260 } 231 261 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) { 238 268 fail("SDL_CreateRGBSurface() failed: %s", SDL_GetError()); 239 269 } 240 270 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] = ' '; 249 273 } 250 274 } … … 254 278 ver("lcd quit"); 255 279 256 SDL_FreeSurface(sur); 257 SDL_FreeSurface(gfx_sur); 280 SDL_FreeSurface(txt); 258 281 TTF_CloseFont(fon); 282 283 SDL_DestroyTexture(gfx); 259 284 260 285 SDL_DestroyRenderer(ren); … … 272 297 ver2("lcd rd %u:%d", off, sz * 8); 273 298 274 if (sz != 1 || off > 0) {299 if (sz != 1 || off != 1) { 275 300 fail("invalid lcd rd %u:%d", off, sz * 8); 276 301 } -
emu/vid.c
r18e37d6 rcd50b8c 231 231 ver("vid init"); 232 232 233 win = SDL_CreateWindow(" Display", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,233 win = SDL_CreateWindow("Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 234 234 WIN_W, WIN_H, 0); 235 235
Note:
See TracChangeset
for help on using the changeset viewer.