blizzard.c 29 KB

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