blizzard.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. /*
  2. * Epson S1D13744/S1D13745 (Blizzard/Hailstorm/Tornado) LCD/TV controller.
  3. *
  4. * Copyright (C) 2008 Nokia Corporation
  5. * Written by Andrzej Zaborowski <andrew@openedhand.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 or
  10. * (at your option) version 3 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "qemu-common.h"
  21. #include "console.h"
  22. #include "devices.h"
  23. #include "vga_int.h"
  24. #include "pixel_ops.h"
  25. typedef void (*blizzard_fn_t)(uint8_t *, const uint8_t *, unsigned int);
  26. typedef struct {
  27. uint8_t reg;
  28. uint32_t addr;
  29. int swallow;
  30. int pll;
  31. int pll_range;
  32. int pll_ctrl;
  33. uint8_t pll_mode;
  34. uint8_t clksel;
  35. int memenable;
  36. int memrefresh;
  37. uint8_t timing[3];
  38. int priority;
  39. uint8_t lcd_config;
  40. int x;
  41. int y;
  42. int skipx;
  43. int skipy;
  44. uint8_t hndp;
  45. uint8_t vndp;
  46. uint8_t hsync;
  47. uint8_t vsync;
  48. uint8_t pclk;
  49. uint8_t u;
  50. uint8_t v;
  51. uint8_t yrc[2];
  52. int ix[2];
  53. int iy[2];
  54. int ox[2];
  55. int oy[2];
  56. int enable;
  57. int blank;
  58. int bpp;
  59. int invalidate;
  60. int mx[2];
  61. int my[2];
  62. uint8_t mode;
  63. uint8_t effect;
  64. uint8_t iformat;
  65. uint8_t source;
  66. DisplayState *state;
  67. blizzard_fn_t *line_fn_tab[2];
  68. void *fb;
  69. uint8_t hssi_config[3];
  70. uint8_t tv_config;
  71. uint8_t tv_timing[4];
  72. uint8_t vbi;
  73. uint8_t tv_x;
  74. uint8_t tv_y;
  75. uint8_t tv_test;
  76. uint8_t tv_filter_config;
  77. uint8_t tv_filter_idx;
  78. uint8_t tv_filter_coeff[0x20];
  79. uint8_t border_r;
  80. uint8_t border_g;
  81. uint8_t border_b;
  82. uint8_t gamma_config;
  83. uint8_t gamma_idx;
  84. uint8_t gamma_lut[0x100];
  85. uint8_t matrix_ena;
  86. uint8_t matrix_coeff[0x12];
  87. uint8_t matrix_r;
  88. uint8_t matrix_g;
  89. uint8_t matrix_b;
  90. uint8_t pm;
  91. uint8_t status;
  92. uint8_t rgbgpio_dir;
  93. uint8_t rgbgpio;
  94. uint8_t gpio_dir;
  95. uint8_t gpio;
  96. uint8_t gpio_edge[2];
  97. uint8_t gpio_irq;
  98. uint8_t gpio_pdown;
  99. struct {
  100. int x;
  101. int y;
  102. int dx;
  103. int dy;
  104. int len;
  105. int buflen;
  106. void *buf;
  107. void *data;
  108. uint16_t *ptr;
  109. int angle;
  110. int pitch;
  111. blizzard_fn_t line_fn;
  112. } data;
  113. } BlizzardState;
  114. /* Bytes(!) per pixel */
  115. static const int blizzard_iformat_bpp[0x10] = {
  116. 0,
  117. 2, /* RGB 5:6:5*/
  118. 3, /* RGB 6:6:6 mode 1 */
  119. 3, /* RGB 8:8:8 mode 1 */
  120. 0, 0,
  121. 4, /* RGB 6:6:6 mode 2 */
  122. 4, /* RGB 8:8:8 mode 2 */
  123. 0, /* YUV 4:2:2 */
  124. 0, /* YUV 4:2:0 */
  125. 0, 0, 0, 0, 0, 0,
  126. };
  127. static inline void blizzard_rgb2yuv(int r, int g, int b,
  128. int *y, int *u, int *v)
  129. {
  130. *y = 0x10 + ((0x838 * r + 0x1022 * g + 0x322 * b) >> 13);
  131. *u = 0x80 + ((0xe0e * b - 0x04c1 * r - 0x94e * g) >> 13);
  132. *v = 0x80 + ((0xe0e * r - 0x0bc7 * g - 0x247 * b) >> 13);
  133. }
  134. static void blizzard_window(BlizzardState *s)
  135. {
  136. uint8_t *src, *dst;
  137. int bypp[2];
  138. int bypl[3];
  139. int y;
  140. blizzard_fn_t fn = s->data.line_fn;
  141. if (!fn)
  142. return;
  143. if (s->mx[0] > s->data.x)
  144. s->mx[0] = s->data.x;
  145. if (s->my[0] > s->data.y)
  146. s->my[0] = s->data.y;
  147. if (s->mx[1] < s->data.x + s->data.dx)
  148. s->mx[1] = s->data.x + s->data.dx;
  149. if (s->my[1] < s->data.y + s->data.dy)
  150. s->my[1] = s->data.y + s->data.dy;
  151. bypp[0] = s->bpp;
  152. bypp[1] = (ds_get_bits_per_pixel(s->state) + 7) >> 3;
  153. bypl[0] = bypp[0] * s->data.pitch;
  154. bypl[1] = bypp[1] * s->x;
  155. bypl[2] = bypp[0] * s->data.dx;
  156. src = s->data.data;
  157. dst = s->fb + bypl[1] * s->data.y + bypp[1] * s->data.x;
  158. for (y = s->data.dy; y > 0; y --, src += bypl[0], dst += bypl[1])
  159. fn(dst, src, bypl[2]);
  160. }
  161. static int blizzard_transfer_setup(BlizzardState *s)
  162. {
  163. if (s->source > 3 || !s->bpp ||
  164. s->ix[1] < s->ix[0] || s->iy[1] < s->iy[0])
  165. return 0;
  166. s->data.angle = s->effect & 3;
  167. s->data.line_fn = s->line_fn_tab[!!s->data.angle][s->iformat];
  168. s->data.x = s->ix[0];
  169. s->data.y = s->iy[0];
  170. s->data.dx = s->ix[1] - s->ix[0] + 1;
  171. s->data.dy = s->iy[1] - s->iy[0] + 1;
  172. s->data.len = s->bpp * s->data.dx * s->data.dy;
  173. s->data.pitch = s->data.dx;
  174. if (s->data.len > s->data.buflen) {
  175. s->data.buf = g_realloc(s->data.buf, s->data.len);
  176. s->data.buflen = s->data.len;
  177. }
  178. s->data.ptr = s->data.buf;
  179. s->data.data = s->data.buf;
  180. s->data.len /= 2;
  181. return 1;
  182. }
  183. static void blizzard_reset(BlizzardState *s)
  184. {
  185. s->reg = 0;
  186. s->swallow = 0;
  187. s->pll = 9;
  188. s->pll_range = 1;
  189. s->pll_ctrl = 0x14;
  190. s->pll_mode = 0x32;
  191. s->clksel = 0x00;
  192. s->memenable = 0;
  193. s->memrefresh = 0x25c;
  194. s->timing[0] = 0x3f;
  195. s->timing[1] = 0x13;
  196. s->timing[2] = 0x21;
  197. s->priority = 0;
  198. s->lcd_config = 0x74;
  199. s->x = 8;
  200. s->y = 1;
  201. s->skipx = 0;
  202. s->skipy = 0;
  203. s->hndp = 3;
  204. s->vndp = 2;
  205. s->hsync = 1;
  206. s->vsync = 1;
  207. s->pclk = 0x80;
  208. s->ix[0] = 0;
  209. s->ix[1] = 0;
  210. s->iy[0] = 0;
  211. s->iy[1] = 0;
  212. s->ox[0] = 0;
  213. s->ox[1] = 0;
  214. s->oy[0] = 0;
  215. s->oy[1] = 0;
  216. s->yrc[0] = 0x00;
  217. s->yrc[1] = 0x30;
  218. s->u = 0;
  219. s->v = 0;
  220. s->iformat = 3;
  221. s->source = 0;
  222. s->bpp = blizzard_iformat_bpp[s->iformat];
  223. s->hssi_config[0] = 0x00;
  224. s->hssi_config[1] = 0x00;
  225. s->hssi_config[2] = 0x01;
  226. s->tv_config = 0x00;
  227. s->tv_timing[0] = 0x00;
  228. s->tv_timing[1] = 0x00;
  229. s->tv_timing[2] = 0x00;
  230. s->tv_timing[3] = 0x00;
  231. s->vbi = 0x10;
  232. s->tv_x = 0x14;
  233. s->tv_y = 0x03;
  234. s->tv_test = 0x00;
  235. s->tv_filter_config = 0x80;
  236. s->tv_filter_idx = 0x00;
  237. s->border_r = 0x10;
  238. s->border_g = 0x80;
  239. s->border_b = 0x80;
  240. s->gamma_config = 0x00;
  241. s->gamma_idx = 0x00;
  242. s->matrix_ena = 0x00;
  243. memset(&s->matrix_coeff, 0, sizeof(s->matrix_coeff));
  244. s->matrix_r = 0x00;
  245. s->matrix_g = 0x00;
  246. s->matrix_b = 0x00;
  247. s->pm = 0x02;
  248. s->status = 0x00;
  249. s->rgbgpio_dir = 0x00;
  250. s->gpio_dir = 0x00;
  251. s->gpio_edge[0] = 0x00;
  252. s->gpio_edge[1] = 0x00;
  253. s->gpio_irq = 0x00;
  254. s->gpio_pdown = 0xff;
  255. }
  256. static inline void blizzard_invalidate_display(void *opaque) {
  257. BlizzardState *s = (BlizzardState *) opaque;
  258. s->invalidate = 1;
  259. }
  260. static uint16_t blizzard_reg_read(void *opaque, uint8_t reg)
  261. {
  262. BlizzardState *s = (BlizzardState *) opaque;
  263. switch (reg) {
  264. case 0x00: /* Revision Code */
  265. return 0xa5;
  266. case 0x02: /* Configuration Readback */
  267. return 0x83; /* Macrovision OK, CNF[2:0] = 3 */
  268. case 0x04: /* PLL M-Divider */
  269. return (s->pll - 1) | (1 << 7);
  270. case 0x06: /* PLL Lock Range Control */
  271. return s->pll_range;
  272. case 0x08: /* PLL Lock Synthesis Control 0 */
  273. return s->pll_ctrl & 0xff;
  274. case 0x0a: /* PLL Lock Synthesis Control 1 */
  275. return s->pll_ctrl >> 8;
  276. case 0x0c: /* PLL Mode Control 0 */
  277. return s->pll_mode;
  278. case 0x0e: /* Clock-Source Select */
  279. return s->clksel;
  280. case 0x10: /* Memory Controller Activate */
  281. case 0x14: /* Memory Controller Bank 0 Status Flag */
  282. return s->memenable;
  283. case 0x18: /* Auto-Refresh Interval Setting 0 */
  284. return s->memrefresh & 0xff;
  285. case 0x1a: /* Auto-Refresh Interval Setting 1 */
  286. return s->memrefresh >> 8;
  287. case 0x1c: /* Power-On Sequence Timing Control */
  288. return s->timing[0];
  289. case 0x1e: /* Timing Control 0 */
  290. return s->timing[1];
  291. case 0x20: /* Timing Control 1 */
  292. return s->timing[2];
  293. case 0x24: /* Arbitration Priority Control */
  294. return s->priority;
  295. case 0x28: /* LCD Panel Configuration */
  296. return s->lcd_config;
  297. case 0x2a: /* LCD Horizontal Display Width */
  298. return s->x >> 3;
  299. case 0x2c: /* LCD Horizontal Non-display Period */
  300. return s->hndp;
  301. case 0x2e: /* LCD Vertical Display Height 0 */
  302. return s->y & 0xff;
  303. case 0x30: /* LCD Vertical Display Height 1 */
  304. return s->y >> 8;
  305. case 0x32: /* LCD Vertical Non-display Period */
  306. return s->vndp;
  307. case 0x34: /* LCD HS Pulse-width */
  308. return s->hsync;
  309. case 0x36: /* LCd HS Pulse Start Position */
  310. return s->skipx >> 3;
  311. case 0x38: /* LCD VS Pulse-width */
  312. return s->vsync;
  313. case 0x3a: /* LCD VS Pulse Start Position */
  314. return s->skipy;
  315. case 0x3c: /* PCLK Polarity */
  316. return s->pclk;
  317. case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
  318. return s->hssi_config[0];
  319. case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
  320. return s->hssi_config[1];
  321. case 0x42: /* High-speed Serial Interface Tx Mode */
  322. return s->hssi_config[2];
  323. case 0x44: /* TV Display Configuration */
  324. return s->tv_config;
  325. case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits */
  326. return s->tv_timing[(reg - 0x46) >> 1];
  327. case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
  328. return s->vbi;
  329. case 0x50: /* TV Horizontal Start Position */
  330. return s->tv_x;
  331. case 0x52: /* TV Vertical Start Position */
  332. return s->tv_y;
  333. case 0x54: /* TV Test Pattern Setting */
  334. return s->tv_test;
  335. case 0x56: /* TV Filter Setting */
  336. return s->tv_filter_config;
  337. case 0x58: /* TV Filter Coefficient Index */
  338. return s->tv_filter_idx;
  339. case 0x5a: /* TV Filter Coefficient Data */
  340. if (s->tv_filter_idx < 0x20)
  341. return s->tv_filter_coeff[s->tv_filter_idx ++];
  342. return 0;
  343. case 0x60: /* Input YUV/RGB Translate Mode 0 */
  344. return s->yrc[0];
  345. case 0x62: /* Input YUV/RGB Translate Mode 1 */
  346. return s->yrc[1];
  347. case 0x64: /* U Data Fix */
  348. return s->u;
  349. case 0x66: /* V Data Fix */
  350. return s->v;
  351. case 0x68: /* Display Mode */
  352. return s->mode;
  353. case 0x6a: /* Special Effects */
  354. return s->effect;
  355. case 0x6c: /* Input Window X Start Position 0 */
  356. return s->ix[0] & 0xff;
  357. case 0x6e: /* Input Window X Start Position 1 */
  358. return s->ix[0] >> 3;
  359. case 0x70: /* Input Window Y Start Position 0 */
  360. return s->ix[0] & 0xff;
  361. case 0x72: /* Input Window Y Start Position 1 */
  362. return s->ix[0] >> 3;
  363. case 0x74: /* Input Window X End Position 0 */
  364. return s->ix[1] & 0xff;
  365. case 0x76: /* Input Window X End Position 1 */
  366. return s->ix[1] >> 3;
  367. case 0x78: /* Input Window Y End Position 0 */
  368. return s->ix[1] & 0xff;
  369. case 0x7a: /* Input Window Y End Position 1 */
  370. return s->ix[1] >> 3;
  371. case 0x7c: /* Output Window X Start Position 0 */
  372. return s->ox[0] & 0xff;
  373. case 0x7e: /* Output Window X Start Position 1 */
  374. return s->ox[0] >> 3;
  375. case 0x80: /* Output Window Y Start Position 0 */
  376. return s->oy[0] & 0xff;
  377. case 0x82: /* Output Window Y Start Position 1 */
  378. return s->oy[0] >> 3;
  379. case 0x84: /* Output Window X End Position 0 */
  380. return s->ox[1] & 0xff;
  381. case 0x86: /* Output Window X End Position 1 */
  382. return s->ox[1] >> 3;
  383. case 0x88: /* Output Window Y End Position 0 */
  384. return s->oy[1] & 0xff;
  385. case 0x8a: /* Output Window Y End Position 1 */
  386. return s->oy[1] >> 3;
  387. case 0x8c: /* Input Data Format */
  388. return s->iformat;
  389. case 0x8e: /* Data Source Select */
  390. return s->source;
  391. case 0x90: /* Display Memory Data Port */
  392. return 0;
  393. case 0xa8: /* Border Color 0 */
  394. return s->border_r;
  395. case 0xaa: /* Border Color 1 */
  396. return s->border_g;
  397. case 0xac: /* Border Color 2 */
  398. return s->border_b;
  399. case 0xb4: /* Gamma Correction Enable */
  400. return s->gamma_config;
  401. case 0xb6: /* Gamma Correction Table Index */
  402. return s->gamma_idx;
  403. case 0xb8: /* Gamma Correction Table Data */
  404. return s->gamma_lut[s->gamma_idx ++];
  405. case 0xba: /* 3x3 Matrix Enable */
  406. return s->matrix_ena;
  407. case 0xbc ... 0xde: /* Coefficient Registers */
  408. return s->matrix_coeff[(reg - 0xbc) >> 1];
  409. case 0xe0: /* 3x3 Matrix Red Offset */
  410. return s->matrix_r;
  411. case 0xe2: /* 3x3 Matrix Green Offset */
  412. return s->matrix_g;
  413. case 0xe4: /* 3x3 Matrix Blue Offset */
  414. return s->matrix_b;
  415. case 0xe6: /* Power-save */
  416. return s->pm;
  417. case 0xe8: /* Non-display Period Control / Status */
  418. return s->status | (1 << 5);
  419. case 0xea: /* RGB Interface Control */
  420. return s->rgbgpio_dir;
  421. case 0xec: /* RGB Interface Status */
  422. return s->rgbgpio;
  423. case 0xee: /* General-purpose IO Pins Configuration */
  424. return s->gpio_dir;
  425. case 0xf0: /* General-purpose IO Pins Status / Control */
  426. return s->gpio;
  427. case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
  428. return s->gpio_edge[0];
  429. case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
  430. return s->gpio_edge[1];
  431. case 0xf6: /* GPIO Interrupt Status */
  432. return s->gpio_irq;
  433. case 0xf8: /* GPIO Pull-down Control */
  434. return s->gpio_pdown;
  435. default:
  436. fprintf(stderr, "%s: unknown register %02x\n", __FUNCTION__, reg);
  437. return 0;
  438. }
  439. }
  440. static void blizzard_reg_write(void *opaque, uint8_t reg, uint16_t value)
  441. {
  442. BlizzardState *s = (BlizzardState *) opaque;
  443. switch (reg) {
  444. case 0x04: /* PLL M-Divider */
  445. s->pll = (value & 0x3f) + 1;
  446. break;
  447. case 0x06: /* PLL Lock Range Control */
  448. s->pll_range = value & 3;
  449. break;
  450. case 0x08: /* PLL Lock Synthesis Control 0 */
  451. s->pll_ctrl &= 0xf00;
  452. s->pll_ctrl |= (value << 0) & 0x0ff;
  453. break;
  454. case 0x0a: /* PLL Lock Synthesis Control 1 */
  455. s->pll_ctrl &= 0x0ff;
  456. s->pll_ctrl |= (value << 8) & 0xf00;
  457. break;
  458. case 0x0c: /* PLL Mode Control 0 */
  459. s->pll_mode = value & 0x77;
  460. if ((value & 3) == 0 || (value & 3) == 3)
  461. fprintf(stderr, "%s: wrong PLL Control bits (%i)\n",
  462. __FUNCTION__, value & 3);
  463. break;
  464. case 0x0e: /* Clock-Source Select */
  465. s->clksel = value & 0xff;
  466. break;
  467. case 0x10: /* Memory Controller Activate */
  468. s->memenable = value & 1;
  469. break;
  470. case 0x14: /* Memory Controller Bank 0 Status Flag */
  471. break;
  472. case 0x18: /* Auto-Refresh Interval Setting 0 */
  473. s->memrefresh &= 0xf00;
  474. s->memrefresh |= (value << 0) & 0x0ff;
  475. break;
  476. case 0x1a: /* Auto-Refresh Interval Setting 1 */
  477. s->memrefresh &= 0x0ff;
  478. s->memrefresh |= (value << 8) & 0xf00;
  479. break;
  480. case 0x1c: /* Power-On Sequence Timing Control */
  481. s->timing[0] = value & 0x7f;
  482. break;
  483. case 0x1e: /* Timing Control 0 */
  484. s->timing[1] = value & 0x17;
  485. break;
  486. case 0x20: /* Timing Control 1 */
  487. s->timing[2] = value & 0x35;
  488. break;
  489. case 0x24: /* Arbitration Priority Control */
  490. s->priority = value & 1;
  491. break;
  492. case 0x28: /* LCD Panel Configuration */
  493. s->lcd_config = value & 0xff;
  494. if (value & (1 << 7))
  495. fprintf(stderr, "%s: data swap not supported!\n", __FUNCTION__);
  496. break;
  497. case 0x2a: /* LCD Horizontal Display Width */
  498. s->x = value << 3;
  499. break;
  500. case 0x2c: /* LCD Horizontal Non-display Period */
  501. s->hndp = value & 0xff;
  502. break;
  503. case 0x2e: /* LCD Vertical Display Height 0 */
  504. s->y &= 0x300;
  505. s->y |= (value << 0) & 0x0ff;
  506. break;
  507. case 0x30: /* LCD Vertical Display Height 1 */
  508. s->y &= 0x0ff;
  509. s->y |= (value << 8) & 0x300;
  510. break;
  511. case 0x32: /* LCD Vertical Non-display Period */
  512. s->vndp = value & 0xff;
  513. break;
  514. case 0x34: /* LCD HS Pulse-width */
  515. s->hsync = value & 0xff;
  516. break;
  517. case 0x36: /* LCD HS Pulse Start Position */
  518. s->skipx = value & 0xff;
  519. break;
  520. case 0x38: /* LCD VS Pulse-width */
  521. s->vsync = value & 0xbf;
  522. break;
  523. case 0x3a: /* LCD VS Pulse Start Position */
  524. s->skipy = value & 0xff;
  525. break;
  526. case 0x3c: /* PCLK Polarity */
  527. s->pclk = value & 0x82;
  528. /* Affects calculation of s->hndp, s->hsync and s->skipx. */
  529. break;
  530. case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
  531. s->hssi_config[0] = value;
  532. break;
  533. case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
  534. s->hssi_config[1] = value;
  535. if (((value >> 4) & 3) == 3)
  536. fprintf(stderr, "%s: Illegal active-data-links value\n",
  537. __FUNCTION__);
  538. break;
  539. case 0x42: /* High-speed Serial Interface Tx Mode */
  540. s->hssi_config[2] = value & 0xbd;
  541. break;
  542. case 0x44: /* TV Display Configuration */
  543. s->tv_config = value & 0xfe;
  544. break;
  545. case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits 0 */
  546. s->tv_timing[(reg - 0x46) >> 1] = value;
  547. break;
  548. case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
  549. s->vbi = value;
  550. break;
  551. case 0x50: /* TV Horizontal Start Position */
  552. s->tv_x = value;
  553. break;
  554. case 0x52: /* TV Vertical Start Position */
  555. s->tv_y = value & 0x7f;
  556. break;
  557. case 0x54: /* TV Test Pattern Setting */
  558. s->tv_test = value;
  559. break;
  560. case 0x56: /* TV Filter Setting */
  561. s->tv_filter_config = value & 0xbf;
  562. break;
  563. case 0x58: /* TV Filter Coefficient Index */
  564. s->tv_filter_idx = value & 0x1f;
  565. break;
  566. case 0x5a: /* TV Filter Coefficient Data */
  567. if (s->tv_filter_idx < 0x20)
  568. s->tv_filter_coeff[s->tv_filter_idx ++] = value;
  569. break;
  570. case 0x60: /* Input YUV/RGB Translate Mode 0 */
  571. s->yrc[0] = value & 0xb0;
  572. break;
  573. case 0x62: /* Input YUV/RGB Translate Mode 1 */
  574. s->yrc[1] = value & 0x30;
  575. break;
  576. case 0x64: /* U Data Fix */
  577. s->u = value & 0xff;
  578. break;
  579. case 0x66: /* V Data Fix */
  580. s->v = value & 0xff;
  581. break;
  582. case 0x68: /* Display Mode */
  583. if ((s->mode ^ value) & 3)
  584. s->invalidate = 1;
  585. s->mode = value & 0xb7;
  586. s->enable = value & 1;
  587. s->blank = (value >> 1) & 1;
  588. if (value & (1 << 4))
  589. fprintf(stderr, "%s: Macrovision enable attempt!\n", __FUNCTION__);
  590. break;
  591. case 0x6a: /* Special Effects */
  592. s->effect = value & 0xfb;
  593. break;
  594. case 0x6c: /* Input Window X Start Position 0 */
  595. s->ix[0] &= 0x300;
  596. s->ix[0] |= (value << 0) & 0x0ff;
  597. break;
  598. case 0x6e: /* Input Window X Start Position 1 */
  599. s->ix[0] &= 0x0ff;
  600. s->ix[0] |= (value << 8) & 0x300;
  601. break;
  602. case 0x70: /* Input Window Y Start Position 0 */
  603. s->iy[0] &= 0x300;
  604. s->iy[0] |= (value << 0) & 0x0ff;
  605. break;
  606. case 0x72: /* Input Window Y Start Position 1 */
  607. s->iy[0] &= 0x0ff;
  608. s->iy[0] |= (value << 8) & 0x300;
  609. break;
  610. case 0x74: /* Input Window X End Position 0 */
  611. s->ix[1] &= 0x300;
  612. s->ix[1] |= (value << 0) & 0x0ff;
  613. break;
  614. case 0x76: /* Input Window X End Position 1 */
  615. s->ix[1] &= 0x0ff;
  616. s->ix[1] |= (value << 8) & 0x300;
  617. break;
  618. case 0x78: /* Input Window Y End Position 0 */
  619. s->iy[1] &= 0x300;
  620. s->iy[1] |= (value << 0) & 0x0ff;
  621. break;
  622. case 0x7a: /* Input Window Y End Position 1 */
  623. s->iy[1] &= 0x0ff;
  624. s->iy[1] |= (value << 8) & 0x300;
  625. break;
  626. case 0x7c: /* Output Window X Start Position 0 */
  627. s->ox[0] &= 0x300;
  628. s->ox[0] |= (value << 0) & 0x0ff;
  629. break;
  630. case 0x7e: /* Output Window X Start Position 1 */
  631. s->ox[0] &= 0x0ff;
  632. s->ox[0] |= (value << 8) & 0x300;
  633. break;
  634. case 0x80: /* Output Window Y Start Position 0 */
  635. s->oy[0] &= 0x300;
  636. s->oy[0] |= (value << 0) & 0x0ff;
  637. break;
  638. case 0x82: /* Output Window Y Start Position 1 */
  639. s->oy[0] &= 0x0ff;
  640. s->oy[0] |= (value << 8) & 0x300;
  641. break;
  642. case 0x84: /* Output Window X End Position 0 */
  643. s->ox[1] &= 0x300;
  644. s->ox[1] |= (value << 0) & 0x0ff;
  645. break;
  646. case 0x86: /* Output Window X End Position 1 */
  647. s->ox[1] &= 0x0ff;
  648. s->ox[1] |= (value << 8) & 0x300;
  649. break;
  650. case 0x88: /* Output Window Y End Position 0 */
  651. s->oy[1] &= 0x300;
  652. s->oy[1] |= (value << 0) & 0x0ff;
  653. break;
  654. case 0x8a: /* Output Window Y End Position 1 */
  655. s->oy[1] &= 0x0ff;
  656. s->oy[1] |= (value << 8) & 0x300;
  657. break;
  658. case 0x8c: /* Input Data Format */
  659. s->iformat = value & 0xf;
  660. s->bpp = blizzard_iformat_bpp[s->iformat];
  661. if (!s->bpp)
  662. fprintf(stderr, "%s: Illegal or unsupported input format %x\n",
  663. __FUNCTION__, s->iformat);
  664. break;
  665. case 0x8e: /* Data Source Select */
  666. s->source = value & 7;
  667. /* Currently all windows will be "destructive overlays". */
  668. if ((!(s->effect & (1 << 3)) && (s->ix[0] != s->ox[0] ||
  669. s->iy[0] != s->oy[0] ||
  670. s->ix[1] != s->ox[1] ||
  671. s->iy[1] != s->oy[1])) ||
  672. !((s->ix[1] - s->ix[0]) & (s->iy[1] - s->iy[0]) &
  673. (s->ox[1] - s->ox[0]) & (s->oy[1] - s->oy[0]) & 1))
  674. fprintf(stderr, "%s: Illegal input/output window positions\n",
  675. __FUNCTION__);
  676. blizzard_transfer_setup(s);
  677. break;
  678. case 0x90: /* Display Memory Data Port */
  679. if (!s->data.len && !blizzard_transfer_setup(s))
  680. break;
  681. *s->data.ptr ++ = value;
  682. if (-- s->data.len == 0)
  683. blizzard_window(s);
  684. break;
  685. case 0xa8: /* Border Color 0 */
  686. s->border_r = value;
  687. break;
  688. case 0xaa: /* Border Color 1 */
  689. s->border_g = value;
  690. break;
  691. case 0xac: /* Border Color 2 */
  692. s->border_b = value;
  693. break;
  694. case 0xb4: /* Gamma Correction Enable */
  695. s->gamma_config = value & 0x87;
  696. break;
  697. case 0xb6: /* Gamma Correction Table Index */
  698. s->gamma_idx = value;
  699. break;
  700. case 0xb8: /* Gamma Correction Table Data */
  701. s->gamma_lut[s->gamma_idx ++] = value;
  702. break;
  703. case 0xba: /* 3x3 Matrix Enable */
  704. s->matrix_ena = value & 1;
  705. break;
  706. case 0xbc ... 0xde: /* Coefficient Registers */
  707. s->matrix_coeff[(reg - 0xbc) >> 1] = value & ((reg & 2) ? 0x80 : 0xff);
  708. break;
  709. case 0xe0: /* 3x3 Matrix Red Offset */
  710. s->matrix_r = value;
  711. break;
  712. case 0xe2: /* 3x3 Matrix Green Offset */
  713. s->matrix_g = value;
  714. break;
  715. case 0xe4: /* 3x3 Matrix Blue Offset */
  716. s->matrix_b = value;
  717. break;
  718. case 0xe6: /* Power-save */
  719. s->pm = value & 0x83;
  720. if (value & s->mode & 1)
  721. fprintf(stderr, "%s: The display must be disabled before entering "
  722. "Standby Mode\n", __FUNCTION__);
  723. break;
  724. case 0xe8: /* Non-display Period Control / Status */
  725. s->status = value & 0x1b;
  726. break;
  727. case 0xea: /* RGB Interface Control */
  728. s->rgbgpio_dir = value & 0x8f;
  729. break;
  730. case 0xec: /* RGB Interface Status */
  731. s->rgbgpio = value & 0xcf;
  732. break;
  733. case 0xee: /* General-purpose IO Pins Configuration */
  734. s->gpio_dir = value;
  735. break;
  736. case 0xf0: /* General-purpose IO Pins Status / Control */
  737. s->gpio = value;
  738. break;
  739. case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
  740. s->gpio_edge[0] = value;
  741. break;
  742. case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
  743. s->gpio_edge[1] = value;
  744. break;
  745. case 0xf6: /* GPIO Interrupt Status */
  746. s->gpio_irq &= value;
  747. break;
  748. case 0xf8: /* GPIO Pull-down Control */
  749. s->gpio_pdown = value;
  750. break;
  751. default:
  752. fprintf(stderr, "%s: unknown register %02x\n", __FUNCTION__, reg);
  753. break;
  754. }
  755. }
  756. uint16_t s1d13745_read(void *opaque, int dc)
  757. {
  758. BlizzardState *s = (BlizzardState *) opaque;
  759. uint16_t value = blizzard_reg_read(s, s->reg);
  760. if (s->swallow -- > 0)
  761. return 0;
  762. if (dc)
  763. s->reg ++;
  764. return value;
  765. }
  766. void s1d13745_write(void *opaque, int dc, uint16_t value)
  767. {
  768. BlizzardState *s = (BlizzardState *) opaque;
  769. if (s->swallow -- > 0)
  770. return;
  771. if (dc) {
  772. blizzard_reg_write(s, s->reg, value);
  773. if (s->reg != 0x90 && s->reg != 0x5a && s->reg != 0xb8)
  774. s->reg += 2;
  775. } else
  776. s->reg = value & 0xff;
  777. }
  778. void s1d13745_write_block(void *opaque, int dc,
  779. void *buf, size_t len, int pitch)
  780. {
  781. BlizzardState *s = (BlizzardState *) opaque;
  782. while (len > 0) {
  783. if (s->reg == 0x90 && dc &&
  784. (s->data.len || blizzard_transfer_setup(s)) &&
  785. len >= (s->data.len << 1)) {
  786. len -= s->data.len << 1;
  787. s->data.len = 0;
  788. s->data.data = buf;
  789. if (pitch)
  790. s->data.pitch = pitch;
  791. blizzard_window(s);
  792. s->data.data = s->data.buf;
  793. continue;
  794. }
  795. s1d13745_write(opaque, dc, *(uint16_t *) buf);
  796. len -= 2;
  797. buf += 2;
  798. }
  799. return;
  800. }
  801. static void blizzard_update_display(void *opaque)
  802. {
  803. BlizzardState *s = (BlizzardState *) opaque;
  804. int y, bypp, bypl, bwidth;
  805. uint8_t *src, *dst;
  806. if (!s->enable)
  807. return;
  808. if (s->x != ds_get_width(s->state) || s->y != ds_get_height(s->state)) {
  809. s->invalidate = 1;
  810. qemu_console_resize(s->state, s->x, s->y);
  811. }
  812. if (s->invalidate) {
  813. s->invalidate = 0;
  814. if (s->blank) {
  815. bypp = (ds_get_bits_per_pixel(s->state) + 7) >> 3;
  816. memset(ds_get_data(s->state), 0, bypp * s->x * s->y);
  817. return;
  818. }
  819. s->mx[0] = 0;
  820. s->mx[1] = s->x;
  821. s->my[0] = 0;
  822. s->my[1] = s->y;
  823. }
  824. if (s->mx[1] <= s->mx[0])
  825. return;
  826. bypp = (ds_get_bits_per_pixel(s->state) + 7) >> 3;
  827. bypl = bypp * s->x;
  828. bwidth = bypp * (s->mx[1] - s->mx[0]);
  829. y = s->my[0];
  830. src = s->fb + bypl * y + bypp * s->mx[0];
  831. dst = ds_get_data(s->state) + bypl * y + bypp * s->mx[0];
  832. for (; y < s->my[1]; y ++, src += bypl, dst += bypl)
  833. memcpy(dst, src, bwidth);
  834. dpy_update(s->state, s->mx[0], s->my[0],
  835. s->mx[1] - s->mx[0], y - s->my[0]);
  836. s->mx[0] = s->x;
  837. s->mx[1] = 0;
  838. s->my[0] = s->y;
  839. s->my[1] = 0;
  840. }
  841. static void blizzard_screen_dump(void *opaque, const char *filename) {
  842. BlizzardState *s = (BlizzardState *) opaque;
  843. blizzard_update_display(opaque);
  844. if (s && ds_get_data(s->state))
  845. ppm_save(filename, s->state->surface);
  846. }
  847. #define DEPTH 8
  848. #include "blizzard_template.h"
  849. #define DEPTH 15
  850. #include "blizzard_template.h"
  851. #define DEPTH 16
  852. #include "blizzard_template.h"
  853. #define DEPTH 24
  854. #include "blizzard_template.h"
  855. #define DEPTH 32
  856. #include "blizzard_template.h"
  857. void *s1d13745_init(qemu_irq gpio_int)
  858. {
  859. BlizzardState *s = (BlizzardState *) g_malloc0(sizeof(*s));
  860. s->fb = g_malloc(0x180000);
  861. s->state = graphic_console_init(blizzard_update_display,
  862. blizzard_invalidate_display,
  863. blizzard_screen_dump, NULL, s);
  864. switch (ds_get_bits_per_pixel(s->state)) {
  865. case 0:
  866. s->line_fn_tab[0] = s->line_fn_tab[1] =
  867. g_malloc0(sizeof(blizzard_fn_t) * 0x10);
  868. break;
  869. case 8:
  870. s->line_fn_tab[0] = blizzard_draw_fn_8;
  871. s->line_fn_tab[1] = blizzard_draw_fn_r_8;
  872. break;
  873. case 15:
  874. s->line_fn_tab[0] = blizzard_draw_fn_15;
  875. s->line_fn_tab[1] = blizzard_draw_fn_r_15;
  876. break;
  877. case 16:
  878. s->line_fn_tab[0] = blizzard_draw_fn_16;
  879. s->line_fn_tab[1] = blizzard_draw_fn_r_16;
  880. break;
  881. case 24:
  882. s->line_fn_tab[0] = blizzard_draw_fn_24;
  883. s->line_fn_tab[1] = blizzard_draw_fn_r_24;
  884. break;
  885. case 32:
  886. s->line_fn_tab[0] = blizzard_draw_fn_32;
  887. s->line_fn_tab[1] = blizzard_draw_fn_r_32;
  888. break;
  889. default:
  890. fprintf(stderr, "%s: Bad color depth\n", __FUNCTION__);
  891. exit(1);
  892. }
  893. blizzard_reset(s);
  894. return s;
  895. }