Changeset f285858 in buchla-emu
- Timestamp:
- 08/20/2017 04:13:15 PM (7 years ago)
- Branches:
- master
- Children:
- b48c8a5
- Parents:
- ac4e192
- Location:
- emu
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/all.h
rac4e192 rf285858 97 97 extern void vid_write(uint32_t off, int32_t sz, uint32_t val); 98 98 99 extern void vid_sdl(void); 100 99 101 extern void tim_init(void); 100 102 extern void tim_quit(void); -
emu/sdl.c
rac4e192 rf285858 27 27 28 28 static sdl_func_t sdl_funcs[] = { 29 ser_sdl 29 ser_sdl, vid_sdl 30 30 }; 31 31 -
emu/vid.c
rac4e192 rf285858 45 45 #define PAL_OFF 0x40000 46 46 47 #define OD0_TDE 0x0004 47 48 #define OD0_BLA 0x0010 49 #define OD0_CB 0x0800 48 50 49 51 #define WIN_SZ_W 0x10000 … … 52 54 #define N_BANKS 2 53 55 56 #define SCALE(_x) (_x * 2) 57 58 #define WIN_W SCALE(SCR_W) 59 #define WIN_H SCALE(SCR_H) 60 61 typedef struct { 62 int32_t x, y, w, h; 63 uint16_t *mem; 64 bool tran; 65 } bm_obj_t; 66 54 67 static int32_t reg_off = REG_OFF; 55 68 … … 57 70 static int32_t bank = 0; 58 71 59 static int32_t pal[16]; 60 static int32_t i_pal = 0; 72 static uint32_t pal[16]; 73 74 static bm_obj_t bm_objs[16]; 75 static int32_t n_bm_objs = 0; 76 77 static SDL_Window *win; 78 static SDL_Renderer *ren; 79 static SDL_Texture *tex; 80 static SDL_atomic_t frame; 81 82 void vid_sdl(void) 83 { 84 ver3("vid_sdl()"); 85 86 static int32_t last = 0; 87 int32_t now = SDL_AtomicGet(&frame); 88 89 if (last == now) { 90 ver3("no update"); 91 return; 92 } 93 94 last = now; 95 96 if (SDL_RenderFillRect(ren, NULL) < 0) { 97 fail("SDL_RenderFillRect() failed: %s", SDL_GetError()); 98 } 99 100 void *buf; 101 int32_t pitch; 102 103 if (SDL_LockMutex(cpu_mutex) < 0) { 104 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 105 } 106 107 for (int32_t i = 0; i < n_bm_objs; ++i) { 108 bm_obj_t *bm_obj = bm_objs + i; 109 110 pal[0] = bm_obj->tran ? pal[0] & 0xffffff00 : pal[0] | 0x000000ff; 111 112 SDL_Rect src = { 113 .x = 0, .y = 0, .w = bm_obj->w, .h = bm_obj->h 114 }; 115 116 if (SDL_LockTexture(tex, &src, &buf, &pitch) < 0) { 117 fail("SDL_LockTexture() failed: %s", SDL_GetError()); 118 } 119 120 uint32_t *pix = buf; 121 uint16_t *vid = bm_obj->mem; 122 123 for (int32_t y = 0; y < src.h; ++y) { 124 for (int32_t x = 0; x < src.w / 4; ++x) { 125 uint16_t v4 = *vid++; 126 127 *pix++ = pal[(v4 & 0x000f) >> 0]; 128 *pix++ = pal[(v4 & 0x00f0) >> 4]; 129 *pix++ = pal[(v4 & 0x0f00) >> 8]; 130 *pix++ = pal[(v4 & 0xf000) >> 12]; 131 } 132 133 pix += pitch / 4 - src.w; 134 } 135 136 SDL_UnlockTexture(tex); 137 138 SDL_Rect dst = { 139 .x = SCALE(bm_obj->x), .y = SCALE(bm_obj->y), 140 .w = SCALE(bm_obj->w), .h = SCALE(bm_obj->h) 141 }; 142 143 ver2("vid rend %d %dx%d -> (%d, %d) (%d, %d) %dx%d", 144 i, 145 bm_obj->w, bm_obj->h, 146 bm_obj->x, bm_obj->y, 147 SCALE(bm_obj->x), SCALE(bm_obj->y), 148 SCALE(bm_obj->w), SCALE(bm_obj->h)); 149 150 if (SDL_RenderCopy(ren, tex, &src, &dst) < 0) { 151 fail("SDL_RenderCopy() failed: %s", SDL_GetError()); 152 } 153 } 154 155 if (SDL_UnlockMutex(cpu_mutex) < 0) { 156 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 157 } 158 159 SDL_RenderPresent(ren); 160 } 61 161 62 162 void vid_init(void) 63 163 { 64 164 ver("vid init"); 165 166 win = SDL_CreateWindow("Display", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 167 WIN_W, WIN_H, 0); 168 169 if (win == NULL) { 170 fail("SDL_CreateWindow() failed: %s", SDL_GetError()); 171 } 172 173 ren = SDL_CreateRenderer(win, -1, 0); 174 175 if (ren == NULL) { 176 fail("SDL_CreateRenderer() failed: %s", SDL_GetError()); 177 } 178 179 if (SDL_SetRenderDrawColor(ren, 0x00, 0x00, 0x00, 0xff) < 0) { 180 fail("SDL_SetRenderDrawColor() failed: %s", SDL_GetError()); 181 } 182 183 tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, 184 SCR_W, SCR_H); 185 186 if (tex == NULL) { 187 fail("SDL_CreateTexture() failed: %s", SDL_GetError()); 188 } 189 190 if (SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND) < 0) { 191 fail("SDL_SetTextureBlendMode() failed: %s", SDL_GetError()); 192 } 193 194 SDL_AtomicSet(&frame, 1); 65 195 } 66 196 … … 68 198 { 69 199 ver("vid quit"); 200 201 SDL_DestroyTexture(tex); 202 SDL_DestroyRenderer(ren); 203 SDL_DestroyWindow(win); 70 204 } 71 205 … … 115 249 116 250 int32_t odtba = mem[REG_ODTBA] & 0xffc0; 117 int32_t y_beg[16], y_end[16]; 251 252 if (SDL_LockMutex(cpu_mutex) < 0) { 253 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 254 } 255 256 n_bm_objs = 0; 118 257 119 258 for (int32_t i = 0; i < 16; ++i) { 120 y_beg[i] = -1;121 y_end[i] = -1;259 int32_t flips[SCR_H]; 260 int32_t n_flips = 0; 122 261 123 262 uint16_t *od = mem + odtba + 4 * i; 124 263 125 264 if ((od[0] & OD0_BLA) != 0) { 126 ver3(" obj %d blanked", i);265 ver3("vid obj %d blanked", i); 127 266 continue; 128 267 } … … 131 270 132 271 if (w == 0) { 133 ver3(" obj %d empty", i);272 ver3("vid obj %d empty", i); 134 273 continue; 135 274 } … … 139 278 for (int32_t k = 0; k < SCR_H; ++k) { 140 279 if ((mem[atba + k] & mask) == 0) { 141 if (y_beg[i] < 0) { 142 y_beg[i] = k; 143 } 144 else if (y_end[i] < 0) { 145 y_end[i] = k; 146 } 280 flips[n_flips] = k; 281 ++n_flips; 147 282 } 148 283 } 149 284 150 if ( y_beg[i] <0) {151 ver3(" obj %d unused", i);285 if (n_flips == 0) { 286 ver3("vid obj %d unused", i); 152 287 continue; 153 288 } 154 289 155 int32_t x = od[1] & 0x03ff; 156 ver2("obj %d %d:%d %d+%d", i, y_beg[i], y_end[i], x, w); 157 } 158 159 int32_t vcr1 = mem[REG_VCR1]; 160 int32_t fon_h = (vcr1 & 0xf000) >> 12; 161 290 if (n_flips == 1) { 291 flips[n_flips] = SCR_H; 292 ++n_flips; 293 } 294 295 bool cb = (od[0] & OD0_CB) != 0; 296 bool tde = (od[0] & OD0_TDE) != 0; 297 298 int32_t x = (od[1] & 0x03ff) * 2; 299 int32_t off = ((od[0] & 0x00c0) << 10) | od[2]; 300 301 ver2("vid obj %d %c %c %d:%d %d+%d 0x%05x", 302 i, cb ? 'c' : 'b', tde ? 't' : '-', flips[0], flips[1], x, w, off); 303 304 if (!cb) { 305 bm_obj_t *bm_obj = bm_objs + n_bm_objs; 306 307 bm_obj->x = x; 308 bm_obj->y = flips[0]; 309 bm_obj->w = w; 310 bm_obj->h = flips[1] - flips[0]; 311 bm_obj->mem = mem + off; 312 bm_obj->tran = tde; 313 314 ++n_bm_objs; 315 } 316 else { 317 int32_t vcr1 = mem[REG_VCR1]; 318 int32_t fon_h = (vcr1 & 0xf000) >> 12; 319 } 320 } 321 322 if (SDL_UnlockMutex(cpu_mutex) < 0) { 323 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 324 } 325 326 SDL_AtomicAdd(&frame, 1); 162 327 return false; 163 328 } … … 173 338 } 174 339 340 uint32_t res; 341 342 if (SDL_LockMutex(cpu_mutex) < 0) { 343 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 344 } 345 175 346 if (off16 >= reg_off && off16 < reg_off + 16) { 176 return mem[off16 - reg_off]; 177 } 178 179 return mem[bank * WIN_SZ_W + off16]; 347 res = mem[off16 - reg_off]; 348 } 349 else { 350 res = mem[bank * WIN_SZ_W + off16]; 351 } 352 353 if (SDL_UnlockMutex(cpu_mutex) < 0) { 354 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 355 } 356 357 return res; 180 358 } 181 359 … … 190 368 } 191 369 370 if (SDL_LockMutex(cpu_mutex) < 0) { 371 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 372 } 373 192 374 if (off16 == PAL_OFF) { 193 pal[i_pal] = (int32_t)val; 194 i_pal = (i_pal + 1) % 16; 195 return; 196 } 197 198 if (off16 >= reg_off && off16 < reg_off + 16) { 375 int32_t i_pal = ((int32_t)val & 0x03c0) >> 6; 376 377 uint32_t r = ((val & 0x0004) >> 1) | ((val & 0x0020) >> 5); 378 uint32_t g = ((val & 0x0002) >> 0) | ((val & 0x0010) >> 4); 379 uint32_t b = ((val & 0x0001) << 1) | ((val & 0x0008) >> 3); 380 381 r = (r ^ 3) * 85; 382 g = (g ^ 3) * 85; 383 b = (b ^ 3) * 85; 384 385 pal[i_pal] = (r << 24) | (g << 16) | (b << 8) | 0xff; 386 } 387 else if (off16 >= reg_off && off16 < reg_off + 16) { 199 388 mem[off16 - reg_off] = (uint16_t)val; 200 return; 201 } 202 203 mem[bank * WIN_SZ_W + off16] = (uint16_t)val; 204 } 389 } 390 else { 391 mem[bank * WIN_SZ_W + off16] = (uint16_t)val; 392 } 393 394 if (SDL_UnlockMutex(cpu_mutex) < 0) { 395 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 396 } 397 }
Note:
See TracChangeset
for help on using the changeset viewer.