[a06aa8b] | 1 | /*
|
---|
| 2 | * Copyright (C) 2017 The Contributors
|
---|
| 3 | *
|
---|
| 4 | * This program is free software: you can redistribute it and/or modify
|
---|
| 5 | * it under the terms of the GNU General Public License as published by
|
---|
| 6 | * the Free Software Foundation, either version 3 of the License, or (at
|
---|
| 7 | * your option) any later version.
|
---|
| 8 | *
|
---|
| 9 | * This program is distributed in the hope that it will be useful, but
|
---|
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 12 | * General Public License for more details.
|
---|
| 13 | *
|
---|
| 14 | * A copy of the GNU General Public License can be found in the file
|
---|
[2147e53] | 15 | * "gpl.txt" in the top directory of this repository.
|
---|
[a06aa8b] | 16 | */
|
---|
| 17 |
|
---|
| 18 | #include <all.h>
|
---|
| 19 |
|
---|
[4c71d39] | 20 | #define ver(...) _ver(vid_verbose, 0, __VA_ARGS__)
|
---|
| 21 | #define ver2(...) _ver(vid_verbose, 1, __VA_ARGS__)
|
---|
| 22 | #define ver3(...) _ver(vid_verbose, 2, __VA_ARGS__)
|
---|
[a06aa8b] | 23 |
|
---|
[4c71d39] | 24 | int32_t vid_verbose = 0;
|
---|
[a06aa8b] | 25 |
|
---|
[ac4e192] | 26 | #define SCR_W 512
|
---|
| 27 | #define SCR_H 350
|
---|
| 28 | #define VBL_H 50
|
---|
| 29 |
|
---|
| 30 | #define REG_VCR0 0
|
---|
| 31 | #define REG_VCR1 1
|
---|
| 32 | #define REG_RWBA 2
|
---|
| 33 | #define REG_DSBA 5
|
---|
| 34 | #define REG_ODTBA 7
|
---|
| 35 | #define REG_ATBA 8
|
---|
[b6f5f64] | 36 | #define REG_CGBA 10
|
---|
[ac4e192] | 37 | #define REG_ATBAC 11
|
---|
| 38 |
|
---|
| 39 | #define VCR0_UCF 0x0001
|
---|
| 40 | #define VCR0_DEN 0x0008
|
---|
| 41 |
|
---|
| 42 | #define DSBA_BS1 0x0080
|
---|
| 43 | #define DSBA_BS0 0x0100
|
---|
| 44 |
|
---|
| 45 | #define REG_OFF 0x200
|
---|
| 46 | #define PAL_OFF 0x40000
|
---|
| 47 |
|
---|
[f285858] | 48 | #define OD0_TDE 0x0004
|
---|
[ac4e192] | 49 | #define OD0_BLA 0x0010
|
---|
[f285858] | 50 | #define OD0_CB 0x0800
|
---|
[ac4e192] | 51 |
|
---|
[fffab34] | 52 | #define AT_UND 0x0100
|
---|
[b6f5f64] | 53 | #define AT_CG 0x8000
|
---|
| 54 |
|
---|
[ac4e192] | 55 | #define WIN_SZ_W 0x10000
|
---|
| 56 | #define MEM_SZ_W 0x20000
|
---|
| 57 |
|
---|
| 58 | #define N_BANKS 2
|
---|
| 59 |
|
---|
[f285858] | 60 | #define SCALE(_x) (_x * 2)
|
---|
| 61 |
|
---|
| 62 | #define WIN_W SCALE(SCR_W)
|
---|
| 63 | #define WIN_H SCALE(SCR_H)
|
---|
| 64 |
|
---|
| 65 | typedef struct {
|
---|
[e26a632] | 66 | int32_t y, h;
|
---|
| 67 | } ver_t;
|
---|
| 68 |
|
---|
| 69 | typedef struct {
|
---|
| 70 | int32_t x, w;
|
---|
| 71 | int32_t n_vers;
|
---|
| 72 | ver_t vers[SCR_H / 2];
|
---|
[f285858] | 73 | uint16_t *mem;
|
---|
| 74 | bool tran;
|
---|
[b6f5f64] | 75 | int32_t fon_h;
|
---|
| 76 | } obj_t;
|
---|
[f285858] | 77 |
|
---|
[ac4e192] | 78 | static int32_t reg_off = REG_OFF;
|
---|
| 79 |
|
---|
| 80 | static uint16_t mem[MEM_SZ_W];
|
---|
| 81 | static int32_t bank = 0;
|
---|
| 82 |
|
---|
[f285858] | 83 | static uint32_t pal[16];
|
---|
| 84 |
|
---|
[b6f5f64] | 85 | static obj_t objs[16];
|
---|
| 86 | static int32_t n_objs = 0;
|
---|
[f285858] | 87 |
|
---|
| 88 | static SDL_Window *win;
|
---|
[4ed9bfe] | 89 | uint32_t vid_win;
|
---|
| 90 |
|
---|
[f285858] | 91 | static SDL_Renderer *ren;
|
---|
| 92 | static SDL_Texture *tex;
|
---|
| 93 | static SDL_atomic_t frame;
|
---|
| 94 |
|
---|
[e26a632] | 95 | static uint16_t *rend_bm(uint16_t *vid, int32_t w, int32_t h, uint32_t *pix, int32_t pitch)
|
---|
[b6f5f64] | 96 | {
|
---|
| 97 | for (int32_t y = 0; y < h; ++y) {
|
---|
| 98 | for (int32_t x = 0; x < w / 4; ++x) {
|
---|
| 99 | uint16_t v4 = *vid++;
|
---|
| 100 |
|
---|
| 101 | *pix++ = pal[(v4 & 0x000f) >> 0];
|
---|
| 102 | *pix++ = pal[(v4 & 0x00f0) >> 4];
|
---|
| 103 | *pix++ = pal[(v4 & 0x0f00) >> 8];
|
---|
| 104 | *pix++ = pal[(v4 & 0xf000) >> 12];
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | pix += pitch / 4 - w;
|
---|
| 108 | }
|
---|
[e26a632] | 109 |
|
---|
| 110 | return vid;
|
---|
[b6f5f64] | 111 | }
|
---|
| 112 |
|
---|
[e26a632] | 113 | static uint16_t *rend_tx(uint16_t *vid, int32_t w, int32_t h, int32_t fon_h,
|
---|
[b6f5f64] | 114 | uint32_t *pix, int32_t pitch)
|
---|
| 115 | {
|
---|
| 116 | int32_t cgba = mem[REG_CGBA];
|
---|
| 117 |
|
---|
| 118 | uint16_t *cg0 = mem + ((cgba & 0x00f0) << 8);
|
---|
| 119 | uint16_t *cg1 = mem + ((cgba & 0x000f) << 12);
|
---|
| 120 |
|
---|
| 121 | int32_t line = fon_h - 1;
|
---|
| 122 |
|
---|
| 123 | for (int32_t y = 0; y < h; ++y) {
|
---|
| 124 | uint16_t *walk = vid;
|
---|
| 125 |
|
---|
| 126 | for (int32_t col2 = 0; col2 < w / 16; ++col2) {
|
---|
| 127 | uint16_t ch2 = *walk++;
|
---|
| 128 |
|
---|
| 129 | for (int32_t i = 0; i < 2; ++i) {
|
---|
| 130 | int32_t ch = (uint8_t)ch2;
|
---|
| 131 | int32_t at = *walk++;
|
---|
| 132 |
|
---|
| 133 | int32_t bg = at & 0x000f;
|
---|
| 134 | int32_t fg = (at & 0x00f0) >> 4;
|
---|
| 135 |
|
---|
[fffab34] | 136 | int32_t bits;
|
---|
| 137 |
|
---|
| 138 | if ((at & AT_UND) != 0 && line == 1) {
|
---|
| 139 | bits = 0xff;
|
---|
| 140 | }
|
---|
| 141 | else {
|
---|
| 142 | uint16_t *cg = (at & AT_CG) != 0 ? cg0 : cg1;
|
---|
| 143 | bits = cg[256 * line + ch];
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[b6f5f64] | 146 | int32_t mask = 0x01;
|
---|
| 147 |
|
---|
| 148 | for (int32_t k = 0; k < 8; ++k) {
|
---|
| 149 | *pix++ = (bits & mask) != 0 ? pal[fg] : pal[bg];
|
---|
| 150 | mask <<= 1;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | ch2 >>= 8;
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | if (--line < 0) {
|
---|
| 158 | line = fon_h - 1;
|
---|
| 159 | vid = walk;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | pix += pitch / 4 - w;
|
---|
| 163 | }
|
---|
[e26a632] | 164 |
|
---|
| 165 | return vid;
|
---|
[b6f5f64] | 166 | }
|
---|
| 167 |
|
---|
[f285858] | 168 | void vid_sdl(void)
|
---|
| 169 | {
|
---|
| 170 | ver3("vid_sdl()");
|
---|
| 171 |
|
---|
| 172 | static int32_t last = 0;
|
---|
| 173 | int32_t now = SDL_AtomicGet(&frame);
|
---|
| 174 |
|
---|
| 175 | if (last == now) {
|
---|
| 176 | ver3("no update");
|
---|
| 177 | return;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | last = now;
|
---|
| 181 |
|
---|
| 182 | if (SDL_RenderFillRect(ren, NULL) < 0) {
|
---|
| 183 | fail("SDL_RenderFillRect() failed: %s", SDL_GetError());
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | if (SDL_LockMutex(cpu_mutex) < 0) {
|
---|
| 187 | fail("SDL_LockMutex() failed: %s", SDL_GetError());
|
---|
| 188 | }
|
---|
| 189 |
|
---|
[b6f5f64] | 190 | for (int32_t i = 0; i < n_objs; ++i) {
|
---|
| 191 | obj_t *obj = objs + i;
|
---|
[f285858] | 192 |
|
---|
[b6f5f64] | 193 | pal[0] = obj->tran ? pal[0] & 0xffffff00 : pal[0] | 0x000000ff;
|
---|
[e26a632] | 194 | uint16_t *m = obj->mem;
|
---|
[f285858] | 195 |
|
---|
[e26a632] | 196 | for (int32_t k = 0; k < obj->n_vers; ++k) {
|
---|
| 197 | SDL_Rect src = {
|
---|
| 198 | .x = 0, .y = 0, .w = obj->w, .h = obj->vers[k].h
|
---|
| 199 | };
|
---|
[f285858] | 200 |
|
---|
[e26a632] | 201 | void *buf;
|
---|
| 202 | int32_t pitch;
|
---|
[b6f5f64] | 203 |
|
---|
[e26a632] | 204 | if (SDL_LockTexture(tex, &src, &buf, &pitch) < 0) {
|
---|
| 205 | fail("SDL_LockTexture() failed: %s", SDL_GetError());
|
---|
| 206 | }
|
---|
[f285858] | 207 |
|
---|
[e26a632] | 208 | if (obj->fon_h < 0) {
|
---|
| 209 | m = rend_bm(m, obj->w, obj->vers[k].h, buf, pitch);
|
---|
| 210 | }
|
---|
| 211 | else {
|
---|
| 212 | m = rend_tx(m, obj->w, obj->vers[k].h, obj->fon_h, buf, pitch);
|
---|
| 213 | }
|
---|
[f285858] | 214 |
|
---|
[e26a632] | 215 | SDL_UnlockTexture(tex);
|
---|
[f285858] | 216 |
|
---|
[e26a632] | 217 | SDL_Rect dst = {
|
---|
| 218 | .x = SCALE(obj->x), .y = SCALE(obj->vers[k].y),
|
---|
| 219 | .w = SCALE(obj->w), .h = SCALE(obj->vers[k].h)
|
---|
| 220 | };
|
---|
[f285858] | 221 |
|
---|
[e26a632] | 222 | ver2("vid rend %d %d %dx%d -> (%d, %d) (%d, %d) %dx%d",
|
---|
| 223 | i, k,
|
---|
| 224 | obj->w, obj->vers[k].h,
|
---|
| 225 | obj->x, obj->vers[k].y,
|
---|
| 226 | SCALE(obj->x), SCALE(obj->vers[k].y),
|
---|
| 227 | SCALE(obj->w), SCALE(obj->vers[k].h));
|
---|
[f285858] | 228 |
|
---|
[e26a632] | 229 | if (SDL_RenderCopy(ren, tex, &src, &dst) < 0) {
|
---|
| 230 | fail("SDL_RenderCopy() failed: %s", SDL_GetError());
|
---|
| 231 | }
|
---|
[f285858] | 232 | }
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | if (SDL_UnlockMutex(cpu_mutex) < 0) {
|
---|
| 236 | fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | SDL_RenderPresent(ren);
|
---|
| 240 | }
|
---|
[ac4e192] | 241 |
|
---|
[a06aa8b] | 242 | void vid_init(void)
|
---|
| 243 | {
|
---|
| 244 | ver("vid init");
|
---|
[f285858] | 245 |
|
---|
| 246 | win = SDL_CreateWindow("Display", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
---|
| 247 | WIN_W, WIN_H, 0);
|
---|
| 248 |
|
---|
| 249 | if (win == NULL) {
|
---|
| 250 | fail("SDL_CreateWindow() failed: %s", SDL_GetError());
|
---|
| 251 | }
|
---|
[4ed9bfe] | 252 |
|
---|
| 253 | vid_win = SDL_GetWindowID(win);
|
---|
| 254 |
|
---|
| 255 | if (vid_win == 0) {
|
---|
| 256 | fail("SDL_GetWindowID() failed: %s", SDL_GetError());
|
---|
| 257 | }
|
---|
[f285858] | 258 |
|
---|
| 259 | ren = SDL_CreateRenderer(win, -1, 0);
|
---|
| 260 |
|
---|
| 261 | if (ren == NULL) {
|
---|
| 262 | fail("SDL_CreateRenderer() failed: %s", SDL_GetError());
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | if (SDL_SetRenderDrawColor(ren, 0x00, 0x00, 0x00, 0xff) < 0) {
|
---|
| 266 | fail("SDL_SetRenderDrawColor() failed: %s", SDL_GetError());
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING,
|
---|
| 270 | SCR_W, SCR_H);
|
---|
| 271 |
|
---|
| 272 | if (tex == NULL) {
|
---|
| 273 | fail("SDL_CreateTexture() failed: %s", SDL_GetError());
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | if (SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND) < 0) {
|
---|
| 277 | fail("SDL_SetTextureBlendMode() failed: %s", SDL_GetError());
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | SDL_AtomicSet(&frame, 1);
|
---|
[a06aa8b] | 281 | }
|
---|
| 282 |
|
---|
| 283 | void vid_quit(void)
|
---|
| 284 | {
|
---|
| 285 | ver("vid quit");
|
---|
[f285858] | 286 |
|
---|
| 287 | SDL_DestroyTexture(tex);
|
---|
| 288 | SDL_DestroyRenderer(ren);
|
---|
| 289 | SDL_DestroyWindow(win);
|
---|
[a06aa8b] | 290 | }
|
---|
| 291 |
|
---|
[3c30832] | 292 | bool vid_exec(void)
|
---|
[a06aa8b] | 293 | {
|
---|
[4c71d39] | 294 | ver3("vid exec");
|
---|
[ac4e192] | 295 |
|
---|
| 296 | static int32_t skip = 99999;
|
---|
| 297 | static int32_t line = 99999;
|
---|
| 298 |
|
---|
| 299 | if (++skip < 10) {
|
---|
| 300 | ver3("vid skip %d", skip);
|
---|
| 301 | return false;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | skip = 0;
|
---|
| 305 | int32_t vcr0 = mem[REG_VCR0];
|
---|
| 306 |
|
---|
| 307 | if ((vcr0 & VCR0_DEN) == 0) {
|
---|
| 308 | ver3("vid dis");
|
---|
| 309 | return false;
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | if (++line < SCR_H + VBL_H) {
|
---|
| 313 | ver3("vid line %d", line);
|
---|
| 314 |
|
---|
| 315 | if (line < SCR_H) {
|
---|
| 316 | ++mem[REG_ATBAC];
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | return line == SCR_H;
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | // We get here every 4,000 invocations -> 25 fps.
|
---|
| 323 |
|
---|
| 324 | ver2("vid frame");
|
---|
| 325 | line = 0;
|
---|
| 326 |
|
---|
| 327 | int32_t dsba = mem[REG_DSBA];
|
---|
| 328 | bank = ((dsba & DSBA_BS0) != 0 ? 1 : 0) + ((dsba & DSBA_BS1) != 0 ? 2 : 0);
|
---|
| 329 |
|
---|
| 330 | int32_t rwba = mem[REG_RWBA];
|
---|
| 331 | reg_off = (rwba & 0xfff0) << 1;
|
---|
| 332 |
|
---|
| 333 | int32_t atba = mem[REG_ATBA];
|
---|
| 334 | mem[REG_ATBAC] = (uint16_t)atba;
|
---|
| 335 |
|
---|
| 336 | int32_t odtba = mem[REG_ODTBA] & 0xffc0;
|
---|
[f285858] | 337 |
|
---|
[b6f5f64] | 338 | n_objs = 0;
|
---|
[ac4e192] | 339 |
|
---|
| 340 | for (int32_t i = 0; i < 16; ++i) {
|
---|
[f285858] | 341 | int32_t flips[SCR_H];
|
---|
| 342 | int32_t n_flips = 0;
|
---|
[ac4e192] | 343 |
|
---|
| 344 | uint16_t *od = mem + odtba + 4 * i;
|
---|
| 345 |
|
---|
| 346 | if ((od[0] & OD0_BLA) != 0) {
|
---|
[f285858] | 347 | ver3("vid obj %d blanked", i);
|
---|
[ac4e192] | 348 | continue;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
[4f967e8] | 351 | int32_t w64 = (od[1] & 0xfc00) >> 10;
|
---|
[ac4e192] | 352 |
|
---|
[4f967e8] | 353 | if (w64 == 0) {
|
---|
[f285858] | 354 | ver3("vid obj %d empty", i);
|
---|
[ac4e192] | 355 | continue;
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | int32_t mask = 1 << i;
|
---|
| 359 |
|
---|
| 360 | for (int32_t k = 0; k < SCR_H; ++k) {
|
---|
| 361 | if ((mem[atba + k] & mask) == 0) {
|
---|
[f285858] | 362 | flips[n_flips] = k;
|
---|
| 363 | ++n_flips;
|
---|
[ac4e192] | 364 | }
|
---|
| 365 | }
|
---|
| 366 |
|
---|
[f285858] | 367 | if (n_flips == 0) {
|
---|
| 368 | ver3("vid obj %d unused", i);
|
---|
[ac4e192] | 369 | continue;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
[e26a632] | 372 | if (n_flips % 2 != 0) {
|
---|
[f285858] | 373 | flips[n_flips] = SCR_H;
|
---|
| 374 | ++n_flips;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | bool cb = (od[0] & OD0_CB) != 0;
|
---|
| 378 | bool tde = (od[0] & OD0_TDE) != 0;
|
---|
| 379 |
|
---|
| 380 | int32_t x = (od[1] & 0x03ff) * 2;
|
---|
[4f967e8] | 381 | int32_t off, fon_h, w;
|
---|
[f285858] | 382 |
|
---|
[b6f5f64] | 383 | if (cb) {
|
---|
[4f967e8] | 384 | off = od[2];
|
---|
[b6f5f64] | 385 | int32_t vcr1 = mem[REG_VCR1];
|
---|
[4f967e8] | 386 | fon_h = (vcr1 & 0xf000) >> 12;
|
---|
| 387 | w = w64 * 4 / 3 * 2 * 8;
|
---|
[f285858] | 388 | }
|
---|
| 389 | else {
|
---|
[4f967e8] | 390 | off = ((od[0] & 0x00c0) << 10) | od[2];
|
---|
| 391 | fon_h = -1;
|
---|
| 392 | w = w64 * 16;
|
---|
[f285858] | 393 | }
|
---|
[b6f5f64] | 394 |
|
---|
[4f967e8] | 395 | obj_t *obj = objs + n_objs;
|
---|
| 396 |
|
---|
[b6f5f64] | 397 | obj->x = x;
|
---|
| 398 | obj->w = w;
|
---|
[e26a632] | 399 | obj->n_vers = n_flips / 2;
|
---|
| 400 |
|
---|
| 401 | for (int32_t k = 0; k < obj->n_vers; ++k) {
|
---|
| 402 | obj->vers[k].y = flips[2 * k];
|
---|
| 403 | obj->vers[k].h = flips[2 * k + 1] - flips[2 * k];
|
---|
| 404 | }
|
---|
| 405 |
|
---|
[b6f5f64] | 406 | obj->mem = mem + off;
|
---|
| 407 | obj->tran = tde;
|
---|
[4f967e8] | 408 | obj->fon_h = fon_h;
|
---|
[b6f5f64] | 409 |
|
---|
[e26a632] | 410 | ver2("vid obj %d %c %c %d:%d %d+%d %d 0x%05x",
|
---|
| 411 | i, cb ? 'c' : 'b', tde ? 't' : '-', flips[0], flips[1], x, w, fon_h, off);
|
---|
[b6f5f64] | 412 |
|
---|
| 413 | ++n_objs;
|
---|
[ac4e192] | 414 | }
|
---|
| 415 |
|
---|
[f285858] | 416 | SDL_AtomicAdd(&frame, 1);
|
---|
[3c30832] | 417 | return false;
|
---|
[a06aa8b] | 418 | }
|
---|
| 419 |
|
---|
| 420 | uint32_t vid_read(uint32_t off, int32_t sz)
|
---|
| 421 | {
|
---|
[ac4e192] | 422 | ver2("vid rd %d 0x%05x:%d", bank, off, sz * 8);
|
---|
| 423 |
|
---|
| 424 | int32_t off16 = (int32_t)(off / 2);
|
---|
| 425 |
|
---|
| 426 | if (sz != 2 || bank >= N_BANKS || off % 2 != 0 || off16 >= WIN_SZ_W) {
|
---|
| 427 | fail("invalid vid rd %d %u:%d", bank, off, sz * 8);
|
---|
| 428 | }
|
---|
| 429 |
|
---|
| 430 | if (off16 >= reg_off && off16 < reg_off + 16) {
|
---|
[a9861f3] | 431 | return mem[off16 - reg_off];
|
---|
[f285858] | 432 | }
|
---|
| 433 |
|
---|
[a9861f3] | 434 | return mem[bank * WIN_SZ_W + off16];
|
---|
[a06aa8b] | 435 | }
|
---|
| 436 |
|
---|
| 437 | void vid_write(uint32_t off, int32_t sz, uint32_t val)
|
---|
| 438 | {
|
---|
[ac4e192] | 439 | ver2("vid wr %d 0x%05x:%d 0x%0*x", bank, off, sz * 8, sz * 2, val);
|
---|
| 440 |
|
---|
| 441 | int32_t off16 = (int32_t)(off / 2);
|
---|
| 442 |
|
---|
| 443 | if (sz != 2 || bank >= N_BANKS || off % 2 != 0 || (off16 >= WIN_SZ_W && off16 != PAL_OFF)) {
|
---|
| 444 | fail("invalid vid wr %d %u:%d", bank, off, sz * 8);
|
---|
| 445 | }
|
---|
| 446 |
|
---|
[f285858] | 447 | if (off16 == PAL_OFF) {
|
---|
| 448 | int32_t i_pal = ((int32_t)val & 0x03c0) >> 6;
|
---|
| 449 |
|
---|
| 450 | uint32_t r = ((val & 0x0004) >> 1) | ((val & 0x0020) >> 5);
|
---|
| 451 | uint32_t g = ((val & 0x0002) >> 0) | ((val & 0x0010) >> 4);
|
---|
| 452 | uint32_t b = ((val & 0x0001) << 1) | ((val & 0x0008) >> 3);
|
---|
| 453 |
|
---|
| 454 | r = (r ^ 3) * 85;
|
---|
| 455 | g = (g ^ 3) * 85;
|
---|
| 456 | b = (b ^ 3) * 85;
|
---|
| 457 |
|
---|
| 458 | pal[i_pal] = (r << 24) | (g << 16) | (b << 8) | 0xff;
|
---|
[a9861f3] | 459 | return;
|
---|
[f285858] | 460 | }
|
---|
[a9861f3] | 461 |
|
---|
| 462 | if (off16 >= reg_off && off16 < reg_off + 16) {
|
---|
[ac4e192] | 463 | mem[off16 - reg_off] = (uint16_t)val;
|
---|
[a9861f3] | 464 | return;
|
---|
[ac4e192] | 465 | }
|
---|
| 466 |
|
---|
[a9861f3] | 467 | mem[bank * WIN_SZ_W + off16] = (uint16_t)val;
|
---|
[a06aa8b] | 468 | }
|
---|