1/* HP Scanjet 3900 series - Debugging functions for standalone
2
3   Copyright (C) 2005-2008 Jonathan Bravo Lopez <jkdsoft@gmail.com>
4
5   This file is part of the SANE package.
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
9   as published by the Free Software Foundation; either version 2
10   of the License, or (at your option) any later version.
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
18   along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
20   As a special exception, the authors of SANE give permission for
21   additional uses of the libraries contained in this release of SANE.
22
23   The exception is that, if you link a SANE library with other files
24   to produce an executable, this does not by itself cause the
25   resulting executable to be covered by the GNU General Public
26   License.  Your use of that executable is in no way restricted on
27   account of linking the SANE library code into it.
28
29   This exception does not, however, invalidate any other reasons why
30   the executable file might be covered by the GNU General Public
31   License.
32
33   If you submit changes to SANE to the maintainers to be included in
34   a subsequent release, you agree by submitting the changes that
35   those changes may be distributed with this exception intact.
36
37   If you write modifications of your own for SANE, it is your choice
38   whether to permit this exception to apply to your modifications.
39   If you do not wish that, delete this exception notice.
40*/
41
42/* debugging level messages */
43#define DBG_ERR             0x00	/* Only important errors         */
44#define DBG_VRB             0x01	/* verbose messages              */
45#define DBG_FNC             0x02	/* Function names and parameters */
46#define DBG_CTL             0x03	/* USB Ctl data                  */
47#define DBG_BLK             0x04	/* USB Bulk data                 */
48
49#include <stdarg.h>
50#ifdef HAVE_TIFFIO_H
51#include <tiffio.h>		/* dbg_tiff_save */
52#endif
53
54/* headers */
55
56static void dump_shading (struct st_calibration *myCalib);
57static char *dbg_scantype (SANE_Int type);
58static void dbg_scanmodes (struct st_device *dev);
59static void dbg_motorcurves (struct st_device *dev);
60static void dbg_motormoves (struct st_device *dev);
61static void dbg_hwdcfg (struct st_hwdconfig *params);
62static void dbg_ScanParams (struct st_scanparams *params);
63static void dbg_calibtable (struct st_gain_offset *params);
64static char *dbg_colour (SANE_Int colour);
65static void dbg_motorcfg (struct st_motorcfg *motorcfg);
66static void dbg_buttons (struct st_buttons *buttons);
67static void dbg_sensor (struct st_sensorcfg *sensor);
68static void dbg_timing (struct st_timing *mt);
69static void dbg_sensorclock (struct st_cph *cph);
70static void dbg_tiff_save (char *sFile, SANE_Int width, SANE_Int height,
71			   SANE_Int depth, SANE_Int colortype, SANE_Int res_x,
72			   SANE_Int res_y, SANE_Byte * buffer, SANE_Int size);
73static void dbg_autoref (struct st_scanparams *scancfg, SANE_Byte * pattern,
74			 SANE_Int ser1, SANE_Int ser2, SANE_Int ler);
75
76#ifdef developing
77static void dbg_buffer (SANE_Int level, char *title, SANE_Byte * buffer,
78			SANE_Int size, SANE_Int start);
79static void dbg_registers (SANE_Byte * buffer);
80#endif
81
82#ifdef STANDALONE
83
84/* implementation */
85
86int DBG_LEVEL = 0;
87
88static void
89DBG (int level, const char *msg, ...)
90{
91  va_list ap;
92  va_start (ap, msg);
93
94  if (level <= DBG_LEVEL)
95    vfprintf (stderr, msg, ap);
96
97  va_end (ap);
98}
99
100#endif
101
102/* debugging functions */
103
104static void
105dump_shading (struct st_calibration *myCalib)
106{
107  if (myCalib != NULL)
108    {
109      SANE_Int colour, a;
110      FILE *shadingfile[3];
111
112      shadingfile[0] = fopen ("RShading.txt", "w");
113      shadingfile[1] = fopen ("GShading.txt", "w");
114      shadingfile[2] = fopen ("BShading.txt", "w");
115
116      for (colour = 0; colour < 3; colour++)
117	{
118	  if (shadingfile[colour] != NULL)
119	    {
120	      for (a = 0; a < myCalib->shadinglength; a++)
121		fprintf (shadingfile[colour], "%04i: %04x %04x\n", a,
122			 (unsigned int) myCalib->white_shading[colour][a],
123			 (unsigned int) myCalib->black_shading[colour][a]);
124	      fclose (shadingfile[colour]);
125	    }
126	}
127    }
128}
129
130static char *
131dbg_scantype (SANE_Int type)
132{
133  switch (type)
134    {
135    case ST_NORMAL:
136      return "ST_NORMAL";
137      break;
138    case ST_TA:
139      return "ST_TA";
140      break;
141    case ST_NEG:
142      return "ST_NEG";
143      break;
144    default:
145      return "Unknown";
146      break;
147    }
148}
149
150static void
151dbg_sensorclock (struct st_cph *cph)
152{
153  if (cph != NULL)
154    {
155      DBG (DBG_FNC, " -> cph->p1 = %f\n", cph->p1);
156      DBG (DBG_FNC, " -> cph->p2 = %f\n", cph->p2);
157      DBG (DBG_FNC, " -> cph->ps = %i\n", cph->ps);
158      DBG (DBG_FNC, " -> cph->ge = %i\n", cph->ge);
159      DBG (DBG_FNC, " -> cph->go = %i\n", cph->go);
160    }
161  else
162    DBG (DBG_FNC, " -> cph is NULL\n");
163}
164
165static void
166dbg_timing (struct st_timing *mt)
167{
168  if (mt != NULL)
169    {
170      DBG (DBG_FNC, " -> mt->cdss[0]   = %i\n", _B0 (mt->cdss[0]));
171      DBG (DBG_FNC, " -> mt->cdsc[0]   = %i\n", _B0 (mt->cdsc[0]));
172      DBG (DBG_FNC, " -> mt->cdss[1]   = %i\n", _B0 (mt->cdss[1]));
173      DBG (DBG_FNC, " -> mt->cdsc[1]   = %i\n", _B0 (mt->cdsc[1]));
174      DBG (DBG_FNC, " -> mt->cnpp      = %i\n", _B0 (mt->cnpp));
175      DBG (DBG_FNC, " -> mt->cvtrp0    = %i\n", _B0 (mt->cvtrp[0]));
176      DBG (DBG_FNC, " -> mt->cvtrp1    = %i\n", _B0 (mt->cvtrp[1]));
177      DBG (DBG_FNC, " -> mt->cvtrp2    = %i\n", _B0 (mt->cvtrp[2]));
178      DBG (DBG_FNC, " -> mt->cvtrfpw   = %i\n", _B0 (mt->cvtrfpw));
179      DBG (DBG_FNC, " -> mt->cvtrbpw   = %i\n", _B0 (mt->cvtrbpw));
180      DBG (DBG_FNC, " -> mt->cvtrw     = %i\n", _B0 (mt->cvtrw));
181      DBG (DBG_FNC, " -> mt->clamps    = 0x%08x\n", mt->clamps);
182      DBG (DBG_FNC, " -> mt->clampe    = 0x%08x\n", mt->clampe);
183      DBG (DBG_FNC, " -> mt->adcclkp0  = %f\n", mt->adcclkp[0]);
184      DBG (DBG_FNC, " -> mt->adcclkp1  = %f\n", mt->adcclkp[1]);
185      DBG (DBG_FNC, " -> mt->adcclkp2e = %i\n", mt->adcclkp2e);
186      DBG (DBG_FNC, " -> mt->cphbp2s   = %i\n", mt->cphbp2s);
187      DBG (DBG_FNC, " -> mt->cphbp2e   = %i\n", mt->cphbp2e);
188    }
189  else
190    DBG (DBG_FNC, " -> mt is NULL\n");
191}
192
193static void
194dbg_sensor (struct st_sensorcfg *sensor)
195{
196  if (sensor != NULL)
197    {
198      DBG (DBG_FNC,
199	   " -> type, name, res , {chn_color }, {chn_gray}, {rgb_order }, line_dist, evnodd_dist\n");
200      DBG (DBG_FNC,
201	   " -> ----, ----, --- , {--, --, --}, {--, --  }, {--, --, --}, ---------, -----------\n");
202      DBG (DBG_FNC,
203	   " -> %4i, %4i, %4i, {%2i, %2i, %2i}, {%2i, %2i  }, {%2i, %2i, %2i}, %9i, %11i\n",
204	   sensor->type, sensor->name, sensor->resolution,
205	   sensor->channel_color[0], sensor->channel_color[1],
206	   sensor->channel_color[2], sensor->channel_gray[0],
207	   sensor->channel_gray[1], sensor->rgb_order[0],
208	   sensor->rgb_order[1], sensor->rgb_order[2], sensor->line_distance,
209	   sensor->evenodd_distance);
210    }
211  else
212    DBG (DBG_FNC, " -> sensor is NULL\n");
213}
214
215static void
216dbg_buttons (struct st_buttons *buttons)
217{
218  if (buttons != NULL)
219    {
220      DBG (DBG_FNC, " -> count, btn1, btn2, btn3, btn4, btn5, btn6\n");
221      DBG (DBG_FNC, " -> -----, ----, ----, ----, ----, ----, ----\n");
222      DBG (DBG_FNC, " -> %5i, %4i, %4i, %4i, %4i, %4i, %4i\n",
223	   buttons->count, buttons->mask[0], buttons->mask[1],
224	   buttons->mask[2], buttons->mask[3], buttons->mask[4],
225	   buttons->mask[5]);
226    }
227  else
228    DBG (DBG_FNC, " -> buttons is NULL\n");
229}
230
231static void
232dbg_scanmodes (struct st_device *dev)
233{
234  if (dev->scanmodes_count > 0)
235    {
236      SANE_Int a;
237      struct st_scanmode *reg;
238
239      DBG (DBG_FNC,
240	   " -> ##, ST       , CM        , RES , TM, CV, SR, CLK, CTPC  , BKS , STT, DML, {   Exposure times     }, { Max exposure times   }, MP , MExp16, MExpF, MExp, MRI, MSI, MMTIR, MMTIRH, SK\n");
241      DBG (DBG_FNC,
242	   " -> --, ---------, ----------, --- , --, --, --, ---, ------, ----, ---, ---, {------  ------  ------}, {------  ------  ------}, ---, ------, -----, ----, ---, ---, -----, ------, --\n");
243      for (a = 0; a < dev->scanmodes_count; a++)
244	{
245	  reg = dev->scanmodes[a];
246	  if (reg != NULL)
247	    {
248	      DBG (DBG_FNC,
249		   " -> %2i, %9s, %10s, %4i, %2i, %2i, %2i, %3i, %6i, %4i, %3i, %3i, {%6i, %6i, %6i}, {%6i, %6i, %6i}, %3i, %6i, %5i, %4i, %3i, %3i, %5i, %6i, %2i\n",
250		   a, dbg_scantype (reg->scantype),
251		   dbg_colour (reg->colormode), reg->resolution, reg->timing,
252		   reg->motorcurve, reg->samplerate, reg->systemclock,
253		   reg->ctpc, reg->motorbackstep, reg->scanmotorsteptype,
254		   reg->dummyline, reg->expt[0], reg->expt[1], reg->expt[2],
255		   reg->mexpt[0], reg->mexpt[1], reg->mexpt[2],
256		   reg->motorplus, reg->multiexposurefor16bitmode,
257		   reg->multiexposureforfullspeed, reg->multiexposure,
258		   reg->mri, reg->msi, reg->mmtir, reg->mmtirh,
259		   reg->skiplinecount);
260	    }
261	}
262    }
263}
264
265static void
266dbg_motorcurves (struct st_device *dev)
267{
268  if (dev->mtrsetting != NULL)
269    {
270      struct st_motorcurve *mtc;
271      SANE_Int a = 0;
272
273      while (a < dev->mtrsetting_count)
274	{
275	  DBG (DBG_FNC, " -> Motorcurve %2i: ", a);
276	  mtc = dev->mtrsetting[a];
277	  if (mtc != NULL)
278	    {
279	      DBG (DBG_FNC, "mri=%i msi=%i skip=%i bckstp=%i\n", mtc->mri,
280		   mtc->msi, mtc->skiplinecount, mtc->motorbackstep);
281	      if (mtc->curve_count > 0)
282		{
283		  char *sdata = (char *) malloc (256);
284		  if (sdata != NULL)
285		    {
286		      char *sline = (char *) malloc (256);
287		      if (sline != NULL)
288			{
289			  SANE_Int count;
290			  struct st_curve *crv;
291
292			  DBG (DBG_FNC,
293			       " ->  ##, dir, type      , count, from, to  , steps\n");
294			  DBG (DBG_FNC,
295			       " ->  --, ---, ----------, -----, ----, ----, -----\n");
296
297			  count = 0;
298			  while (count < mtc->curve_count)
299			    {
300			      memset (sline, 0, 256);
301
302			      snprintf (sdata, 256, " ->  %02i, ", count);
303			      strcat (sline, sdata);
304
305			      crv = mtc->curve[count];
306			      if (crv != NULL)
307				{
308				  if (crv->crv_speed == ACC_CURVE)
309				    strcat (sline, "ACC, ");
310				  else
311				    strcat (sline, "DEC, ");
312
313				  switch (crv->crv_type)
314				    {
315				    case CRV_NORMALSCAN:
316				      strcat (sline, "NORMALSCAN, ");
317				      break;
318				    case CRV_PARKHOME:
319				      strcat (sline, "PARKHOME  , ");
320				      break;
321				    case CRV_SMEARING:
322				      strcat (sline, "SMEARING  , ");
323				      break;
324				    case CRV_BUFFERFULL:
325				      strcat (sline, "BUFFERFULL, ");
326				      break;
327				    default:
328				      snprintf (sdata, 256, "unknown %2i, ",
329						crv->crv_type);
330				      strcat (sline, sdata);
331				      break;
332				    }
333
334				  snprintf (sdata, 256, "%5i, ",
335					    crv->step_count);
336				  strcat (sline, sdata);
337				  if (crv->step_count > 0)
338				    {
339				      SANE_Int stpcount = 0;
340
341				      snprintf (sdata, 256, "%4i, %4i| ",
342						crv->step[0],
343						crv->step[crv->step_count -
344							  1]);
345				      strcat (sline, sdata);
346
347				      while (stpcount < crv->step_count)
348					{
349					  if (stpcount == 10)
350					    {
351					      strcat (sline, "...");
352					      break;
353					    }
354					  if (stpcount > 0)
355					    strcat (sline, ", ");
356
357					  snprintf (sdata, 256, "%4i",
358						    crv->step[stpcount]);
359					  strcat (sline, sdata);
360
361					  stpcount++;
362					}
363				      strcat (sline, "\n");
364				    }
365				  else
366				    strcat (sline, "NONE\n");
367				}
368			      else
369				strcat (sline, "NULL ...\n");
370
371			      DBG (DBG_FNC, "%s", sline);
372
373			      count++;
374			    }
375
376			  free (sline);
377			}
378		      free (sdata);
379		    }
380		}
381	    }
382	  else
383	    DBG (DBG_FNC, "NULL\n");
384	  a++;
385	}
386    }
387}
388
389static void
390dbg_motormoves (struct st_device *dev)
391{
392  if (dev->motormove_count > 0)
393    {
394      SANE_Int a;
395      struct st_motormove *reg;
396
397      DBG (DBG_FNC, " -> ##, CLK, CTPC, STT, CV\n");
398      DBG (DBG_FNC, " -> --, ---, ----, ---, --\n");
399      for (a = 0; a < dev->motormove_count; a++)
400	{
401	  reg = dev->motormove[a];
402	  if (reg != NULL)
403	    {
404	      DBG (DBG_FNC, " -> %2i, %3i, %4i, %3i, %2i\n",
405		   a, reg->systemclock, reg->ctpc,
406		   reg->scanmotorsteptype, reg->motorcurve);
407	    }
408	}
409    }
410}
411
412static void
413dbg_hwdcfg (struct st_hwdconfig *params)
414{
415  if (params != NULL)
416    {
417      DBG (DBG_FNC, " -> Low level config:\n");
418      DBG (DBG_FNC, " -> startpos              = %i\n", params->startpos);
419      DBG (DBG_FNC, " -> arrangeline           = %s\n",
420	   (params->arrangeline ==
421	    FIX_BY_SOFT) ? "FIX_BY_SOFT" : (params->arrangeline ==
422					    FIX_BY_HARD) ? "FIX_BY_HARD" :
423	   "FIX_BY_NONE");
424      DBG (DBG_FNC, " -> scantype              = %s\n",
425	   dbg_scantype (params->scantype));
426      DBG (DBG_FNC, " -> compression           = %i\n", params->compression);
427      DBG (DBG_FNC, " -> use_gamma_tables      = %i\n",
428	   params->use_gamma_tables);
429      DBG (DBG_FNC, " -> gamma_tablesize       = %i\n",
430	   params->gamma_tablesize);
431      DBG (DBG_FNC, " -> white_shading         = %i\n",
432	   params->white_shading);
433      DBG (DBG_FNC, " -> black_shading         = %i\n",
434	   params->black_shading);
435      DBG (DBG_FNC, " -> unk3                  = %i\n", params->unk3);
436      DBG (DBG_FNC, " -> motorplus             = %i\n", params->motorplus);
437      DBG (DBG_FNC, " -> static_head           = %i\n", params->static_head);
438      DBG (DBG_FNC, " -> motor_direction       = %s\n",
439	   (params->motor_direction == MTR_FORWARD) ? "FORWARD" : "BACKWARD");
440      DBG (DBG_FNC, " -> dummy_scan            = %i\n", params->dummy_scan);
441      DBG (DBG_FNC, " -> highresolution        = %i\n",
442	   params->highresolution);
443      DBG (DBG_FNC, " -> sensorevenodddistance = %i\n",
444	   params->sensorevenodddistance);
445      DBG (DBG_FNC, " -> calibrate             = %i\n", params->calibrate);
446    }
447}
448
449static void
450dbg_ScanParams (struct st_scanparams *params)
451{
452  if (params != NULL)
453    {
454      DBG (DBG_FNC, " -> Scan params:\n");
455      DBG (DBG_FNC, " -> colormode        = %s\n",
456	   dbg_colour (params->colormode));
457      DBG (DBG_FNC, " -> depth            = %i\n", params->depth);
458      DBG (DBG_FNC, " -> samplerate       = %i\n", params->samplerate);
459      DBG (DBG_FNC, " -> timing           = %i\n", params->timing);
460      DBG (DBG_FNC, " -> channel          = %i\n", params->channel);
461      DBG (DBG_FNC, " -> sensorresolution = %i\n", params->sensorresolution);
462      DBG (DBG_FNC, " -> resolution_x     = %i\n", params->resolution_x);
463      DBG (DBG_FNC, " -> resolution_y     = %i\n", params->resolution_y);
464      DBG (DBG_FNC, " -> left             = %i\n", params->coord.left);
465      DBG (DBG_FNC, " -> width            = %i\n", params->coord.width);
466      DBG (DBG_FNC, " -> top              = %i\n", params->coord.top);
467      DBG (DBG_FNC, " -> height           = %i\n", params->coord.height);
468      DBG (DBG_FNC, " -> shadinglength    = %i\n", params->shadinglength);
469      DBG (DBG_FNC, " -> v157c            = %i\n", params->v157c);
470      DBG (DBG_FNC, " -> bytesperline     = %i\n", params->bytesperline);
471      DBG (DBG_FNC, " -> expt             = %i\n", params->expt);
472      DBG (DBG_FNC, " *> startpos         = %i\n", params->startpos);
473      DBG (DBG_FNC, " *> leftleading      = %i\n", params->leftleading);
474      DBG (DBG_FNC, " *> ser              = %i\n", params->ser);
475      DBG (DBG_FNC, " *> ler              = %i\n", params->ler);
476      DBG (DBG_FNC, " *> scantype         = %s\n",
477	   dbg_scantype (params->scantype));
478    }
479}
480
481static void
482dbg_calibtable (struct st_gain_offset *params)
483{
484  if (params != NULL)
485    {
486      DBG (DBG_FNC, " -> Calib table:\n");
487      DBG (DBG_FNC, " -> type     R     G     B\n");
488      DBG (DBG_FNC, " -> -----   ---   ---   ---B\n");
489      DBG (DBG_FNC, " -> edcg1 = %3i , %3i , %3i\n", params->edcg1[0],
490	   params->edcg1[1], params->edcg1[2]);
491      DBG (DBG_FNC, " -> edcg2 = %3i , %3i , %3i\n", params->edcg2[0],
492	   params->edcg2[1], params->edcg2[2]);
493      DBG (DBG_FNC, " -> odcg1 = %3i , %3i , %3i\n", params->odcg1[0],
494	   params->odcg1[1], params->odcg1[2]);
495      DBG (DBG_FNC, " -> odcg2 = %3i , %3i , %3i\n", params->odcg2[0],
496	   params->odcg2[1], params->odcg2[2]);
497      DBG (DBG_FNC, " -> pag   = %3i , %3i , %3i\n", params->pag[0],
498	   params->pag[1], params->pag[2]);
499      DBG (DBG_FNC, " -> vgag1 = %3i , %3i , %3i\n", params->vgag1[0],
500	   params->vgag1[1], params->vgag1[2]);
501      DBG (DBG_FNC, " -> vgag2 = %3i , %3i , %3i\n", params->vgag2[0],
502	   params->vgag2[1], params->vgag2[2]);
503    }
504}
505
506static char *
507dbg_colour (SANE_Int colour)
508{
509  switch (colour)
510    {
511    case CM_COLOR:
512      return "CM_COLOR";
513      break;
514    case CM_GRAY:
515      return "CM_GRAY";
516      break;
517    case CM_LINEART:
518      return "CM_LINEART";
519      break;
520    default:
521      return "Unknown";
522      break;
523    }
524}
525
526static void
527dbg_motorcfg (struct st_motorcfg *motorcfg)
528{
529  if (motorcfg != NULL)
530    {
531      DBG (DBG_FNC,
532	   " -> type, res , freq, speed, base, high, park, change\n");
533      DBG (DBG_FNC,
534	   " -> ----, --- , ----, -----, ----, ----, ----, ------\n");
535      DBG (DBG_FNC, " -> %4i, %4i, %4i, %5i, %4i, %4i, %4i, %6i\n",
536	   motorcfg->type, motorcfg->resolution, motorcfg->pwmfrequency,
537	   motorcfg->basespeedpps, motorcfg->basespeedmotormove,
538	   motorcfg->highspeedmotormove, motorcfg->parkhomemotormove,
539	   motorcfg->changemotorcurrent);
540    }
541}
542
543static void
544dbg_tiff_save (char *sFile, SANE_Int width, SANE_Int height, SANE_Int depth,
545	       SANE_Int colortype, SANE_Int res_x, SANE_Int res_y,
546	       SANE_Byte * buffer, SANE_Int size)
547{
548#ifdef HAVE_TIFFIO_H
549  if (buffer != NULL)
550    {
551      char *path = getenv ("HOME");
552
553      if (path != NULL)
554	{
555	  char filename[512];
556	  TIFF *image;
557
558	  if (snprintf (filename, 512, "%s/%s", path, sFile) > 0)
559	    {
560	      /* Open the TIFF file */
561	      if ((image = TIFFOpen (filename, "w")) != NULL)
562		{
563		  char desc[256];
564
565		  SANE_Int spp = (colortype == CM_GRAY) ? 1 : 3;
566		  SANE_Int ct =
567		    (colortype ==
568		     CM_GRAY) ? PHOTOMETRIC_MINISBLACK : PHOTOMETRIC_RGB;
569
570		  snprintf (desc, 256, "Created with hp3900 %s",
571			    BACKEND_VRSN);
572
573		  /* We need to set some values for basic tags before we can add any data */
574		  TIFFSetField (image, TIFFTAG_IMAGEWIDTH, width);
575		  TIFFSetField (image, TIFFTAG_IMAGELENGTH, height);
576		  TIFFSetField (image, TIFFTAG_BITSPERSAMPLE, depth);
577		  TIFFSetField (image, TIFFTAG_SAMPLESPERPIXEL, spp);
578
579		  TIFFSetField (image, TIFFTAG_PHOTOMETRIC, ct);
580		  TIFFSetField (image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
581		  TIFFSetField (image, TIFFTAG_PLANARCONFIG,
582				PLANARCONFIG_CONTIG);
583
584		  TIFFSetField (image, TIFFTAG_XRESOLUTION, (double) res_x);
585		  TIFFSetField (image, TIFFTAG_YRESOLUTION, (double) res_y);
586		  TIFFSetField (image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
587		  TIFFSetField (image, TIFFTAG_IMAGEDESCRIPTION, desc);
588
589		  /* Write the information to the file */
590		  TIFFWriteRawStrip (image, 0, buffer, size);
591		  TIFFClose (image);
592		}
593	    }
594	  else
595	    DBG (DBG_ERR, "- dbg_tiff_save: Error generating filename\n");
596	}
597      else
598	DBG (DBG_ERR,
599	     "- dbg_tiff_save: Environment HOME variable does not exist\n");
600    }
601#else
602  /* silent gcc */
603  (void) sFile;
604  (void) width;
605  (void) height;
606  (void) depth;
607  (void) colortype;
608  (void) res_x;
609  (void) res_y;
610  (void) buffer;
611  (void) size;
612
613  DBG (DBG_ERR, "- dbg_tiff_save: tiffio not supported\n");
614#endif
615}
616
617static void
618dbg_autoref (struct st_scanparams *scancfg, SANE_Byte * pattern,
619	     SANE_Int ser1, SANE_Int ser2, SANE_Int ler)
620{
621  /* this function generates post-autoref.tiff */
622  SANE_Byte *img =
623    malloc (sizeof (SANE_Byte) *
624	    (scancfg->coord.width * scancfg->coord.height * 3));
625
626  if (img != NULL)
627    {
628      SANE_Int c, value;
629
630      /* generate image from 1 gray channel to 3 color channels */
631      for (c = 0; c < (scancfg->coord.width * scancfg->coord.height); c++)
632	{
633	  value = *(pattern + c);
634	  *(img + (3 * c)) = value;
635	  *(img + (3 * c) + 1) = value;
636	  *(img + (3 * c) + 2) = value;
637	}
638
639      for (c = 0; c < scancfg->coord.height; c++)
640	{
641	  /* line for first SER */
642	  if (c < (ler + 5))
643	    {
644	      *(img + (scancfg->coord.width * c * 3) + (3 * ser1)) = 0;
645	      *(img + (scancfg->coord.width * c * 3) + (3 * ser1) + 1) = 255;
646	      *(img + (scancfg->coord.width * c * 3) + (3 * ser1) + 2) = 0;
647	    }
648
649	  /* line for second SER */
650	  if (c > (ler - 5))
651	    {
652	      *(img + (scancfg->coord.width * c * 3) + (3 * ser2)) = 90;
653	      *(img + (scancfg->coord.width * c * 3) + (3 * ser2) + 1) = 90;
654	      *(img + (scancfg->coord.width * c * 3) + (3 * ser2) + 2) = 255;
655	    }
656
657	  /* vertical lines of the pointer */
658	  if ((c > (ler - 5)) && (c < (ler + 5)))
659	    {
660	      if ((ser2 - 5) >= 0)
661		{
662		  *(img + (scancfg->coord.width * c * 3) + (3 * (ser2 - 5))) =
663		    255;
664		  *(img + (scancfg->coord.width * c * 3) + (3 * (ser2 - 5)) +
665		    1) = 255;
666		  *(img + (scancfg->coord.width * c * 3) + (3 * (ser2 - 5)) +
667		    2) = 0;
668		}
669
670	      if ((ser2 + 5) < scancfg->coord.width)
671		{
672		  *(img + (scancfg->coord.width * c * 3) + (3 * (ser2 + 5))) =
673		    255;
674		  *(img + (scancfg->coord.width * c * 3) + (3 * (ser2 + 5)) +
675		    1) = 255;
676		  *(img + (scancfg->coord.width * c * 3) + (3 * (ser2 + 5)) +
677		    2) = 0;
678		}
679	    }
680	}
681
682      /* line for first LER */
683      for (c = 0; c < scancfg->coord.width; c++)
684	{
685	  if ((c > (ser1 - 5)) && (c < (ser2 + 5)))
686	    {
687	      if (c != (ser2 - 5))
688		{
689		  *(img + (scancfg->coord.width * ler * 3) + (3 * c)) = 255;
690		  *(img + (scancfg->coord.width * ler * 3) + (3 * c) + 1) =
691		    90;
692		  *(img + (scancfg->coord.width * ler * 3) + (3 * c) + 2) =
693		    90;
694		}
695
696	      /* horizontal lines of the pointer */
697	      if ((c > (ser2 - 5)) && (c < (ser2 + 5)))
698		{
699		  if ((ler - 5) >= 0)
700		    {
701		      *(img + (scancfg->coord.width * (ler - 5) * 3) +
702			(3 * c)) = 255;
703		      *(img + (scancfg->coord.width * (ler - 5) * 3) +
704			(3 * c) + 1) = 255;
705		      *(img + (scancfg->coord.width * (ler - 5) * 3) +
706			(3 * c) + 2) = 0;
707		    }
708
709		  if ((ler + 5) < scancfg->coord.height)
710		    {
711		      *(img + (scancfg->coord.width * (ler + 5) * 3) +
712			(3 * c)) = 255;
713		      *(img + (scancfg->coord.width * (ler + 5) * 3) +
714			(3 * c) + 1) = 255;
715		      *(img + (scancfg->coord.width * (ler + 5) * 3) +
716			(3 * c) + 2) = 0;
717		    }
718		}
719	    }
720	}
721
722      dbg_tiff_save ("post-autoref.tiff", scancfg->coord.width,
723		     scancfg->coord.height, 8, CM_COLOR,
724		     scancfg->resolution_x, scancfg->resolution_y, img,
725		     scancfg->coord.height * scancfg->coord.width * 3);
726
727      /* free generated image */
728      free (img);
729    }
730}
731
732#ifdef developing
733
734static void
735dbg_buffer (SANE_Int level, char *title, SANE_Byte * buffer, SANE_Int size,
736	    SANE_Int start)
737{
738  if (level <= DBG_LEVEL)
739    {
740      DBG (level, "%s    ", title);
741      if ((size > 0) && (buffer != NULL))
742	{
743	  SANE_Int cont, data, offset = 0;
744	  SANE_Int col = 0;
745	  char text[9];
746	  char *sline = NULL;
747	  char *sdata = NULL;
748
749	  sline = (char *) malloc (81);
750	  if (sline != NULL)
751	    {
752	      sdata = (char *) malloc (81);
753	      if (sdata != NULL)
754		{
755		  for (cont = 0; cont < size; cont++)
756		    {
757		      if (col == 0)
758			{
759			  if (cont == 0)
760			    snprintf (sline, 80, " BF: ");
761			  else
762			    snprintf (sline, 80, "               ");
763			  memset (&text, 0, sizeof (text));
764			}
765		      data = _B0 (buffer[cont]);
766		      text[col] = (data > 31) ? data : '·';
767		      snprintf (sdata, 80, "%02x ", data);
768		      sline = strcat (sline, sdata);
769		      col++;
770		      offset++;
771		      if (col == 8)
772			{
773			  col = 0;
774			  snprintf (sdata, 80, " : %s : 0x%04x\n", text,
775				    start + offset - 8);
776			  sline = strcat (sline, sdata);
777			  DBG (level, "%s", sline);
778			  memset (sline, 0, 81);
779			}
780		    }
781		  if (col > 0)
782		    {
783		      for (cont = col; cont < 8; cont++)
784			{
785			  snprintf (sdata, 80, "-- ");
786			  sline = strcat (sline, sdata);
787			  offset++;
788			}
789		      snprintf (sdata, 80, " : %s : 0x%04x\n", text,
790				start + offset - 8);
791		      sline = strcat (sline, sdata);
792		      DBG (level, "%s", sline);
793		      memset (sline, 0, 81);
794		    }
795		  free (sdata);
796		}
797	      free (sline);
798	    }
799	}
800      else
801	DBG (level, "           BF: Empty buffer\n");
802    }
803}
804
805static void
806dbg_registers (SANE_Byte * buffer)
807{
808  /* buffer size must be RT_BUFFER_LEN bytes */
809  /*SANE_Int iValue, iValue2;
810     double dValue;
811
812     DBG(DBG_FNC, "\n----------------------------------------------------\n");
813     DBG(DBG_FNC, """RTS8822 Control Registers Info""\nAddress  Info\n-------  ----\n");
814     iValue = data_lsb_get(&buffer[0x000], 1);
815     DBG(DBG_FNC, "\n0x0000");
816     DBG(DBG_FNC, "   bit[0..3] = systemclock: 0x%02x\n", iValue & 0x0f);
817     DBG(DBG_FNC, "         bit[4]    = 0x%02x : MLOCK\n", (iValue >> 4) & 1);
818     DBG(DBG_FNC, "         bit[5]    = 0x%02x : Bit to reset scanner\n", (iValue >> 5) & 1);
819     DBG(DBG_FNC, "         bit[6]    = 0x%02x : ?\n", (iValue >> 6) & 1);
820     DBG(DBG_FNC, "         bit[7]    = 0x%02x : RTS_IsExecuting\n", (iValue >> 7) & 1);
821
822     iValue = data_lsb_get(&buffer[0x001], 1);
823     DBG(DBG_FNC, "0x0001   bit[0]    = 0x%02x : ?\n", iValue & 1);
824     DBG(DBG_FNC, "         bit[1]    = 0x%02x : (is 1 if has motorcurves)\n", (iValue >> 1) & 1);
825     DBG(DBG_FNC, "         bit[2]    = 0x%02x : ?\n", (iValue >> 2) & 1);
826     DBG(DBG_FNC, "         bit[3]    = 0x%02x : ?\n", (iValue >> 3) & 1);
827     DBG(DBG_FNC, "         bit[4]    = 0x%02x : dummy scan\n", (iValue >> 4) & 1);
828     DBG(DBG_FNC, "         bit[5..7] = 0x%02x : ?\n", (iValue >> 5) & 7);
829
830     dbg_buffer(DBG_FNC, "\n0x0002", &buffer[0x002], 0x0e, 0x02);
831
832     iValue = data_lsb_get(&buffer[0x010], 1);
833     DBG(DBG_FNC, "\n0x0010   bit[0..4] = 0x%02x : cvrs\n", iValue & 0x1f);
834     DBG(DBG_FNC, "         bit[5]    = 0x%02x : Enable CCD\n", ((iValue >> 5) & 1));
835     DBG(DBG_FNC, "         bit[6]    = 0x%02x : Enable CCD channel 1\n", ((iValue >> 6) & 1));
836     DBG(DBG_FNC, "         bit[7]    = 0x%02x : Enable CCD channel 2\n", ((iValue >> 7) & 1));
837
838     iValue = data_lsb_get(&buffer[0x011], 1);
839     DBG(DBG_FNC, "\n0x0011   bit[0..6] = ?: 0x%02x\n", iValue & 0x3f);
840     DBG(DBG_FNC, "         bit[7]    = 0x%02x : sensor type (CCD=0|CIS=1)\n", (iValue >> 7) & 1);
841
842     iValue = data_lsb_get(&buffer[0x012], 1);
843     DBG(DBG_FNC, "0x0012   bit[0..5] = 0x%02x [0x%02x,0x%02x,0x%02x] rgb channel order\n", (iValue & 0x3f), (iValue >> 4) & 3, (iValue >> 2) & 3, iValue & 3);
844     DBG(DBG_FNC, "         bit[6..7] = channels_per_dot : 0x%02x\n", (iValue >> 6) & 3);
845
846     iValue = data_lsb_get(&buffer[0x013], 1);
847     DBG(DBG_FNC, "\n0x0013");
848     DBG(DBG_FNC, "   bit[0..1] = Pre-Amplifier Gain[RED]   : 0x%02x\n", iValue & 3);
849     DBG(DBG_FNC, "         bit[2..3] = Pre-Amplifier Gain[GREEN] : 0x%02x\n", (iValue >> 2) & 3);
850     DBG(DBG_FNC, "         bit[4..5] = Pre-Amplifier Gain[BLUE]  : 0x%02x\n", (iValue >> 4) & 3);
851     DBG(DBG_FNC, "         bit[6]    = ? : 0x%02x\n", (iValue >> 6) & 1);
852     DBG(DBG_FNC, "         bit[7]    = Enable CCD channel 3:  : 0x%02x\n", (iValue >> 7) & 1);
853
854     iValue = data_lsb_get(&buffer[0x014], 1);
855     DBG(DBG_FNC, "\n0x0014");
856     DBG(DBG_FNC, "   bit[0..4] = Variable Gain Amplifier 1 [RED] : 0x%02x\n", iValue & 0x1f);
857     DBG(DBG_FNC, "         bit[5..7] = Top Reference Voltage: 0x%02x\n", (iValue >> 5) & 3);
858
859     iValue = data_lsb_get(&buffer[0x015], 1);
860     DBG(DBG_FNC, "0x0015");
861     DBG(DBG_FNC, "   bit[0..4] = Variable Gain Amplifier 1 [GREEN] : 0x%02x\n", iValue & 0x1f);
862     DBG(DBG_FNC, "         bit[5..7] = Middle Reference Voltage: 0x%02x\n", (iValue >> 5) & 3);
863
864     iValue = data_lsb_get(&buffer[0x016], 1);
865     DBG(DBG_FNC, "0x0016");
866     DBG(DBG_FNC, "   bit[0..4] = Variable Gain Amplifier 1 [BLUE] : 0x%02x\n", iValue & 0x1f);
867     DBG(DBG_FNC, "         bit[5..7] = Bottom Reference Voltage: 0x%02x\n", (iValue >> 5) & 3);
868
869     iValue = data_lsb_get(&buffer[0x017], 1);
870     DBG(DBG_FNC, "0x0017");
871     DBG(DBG_FNC, "   bit[0..4] = Variable Gain Amplifier 2 [RED] : 0x%02x\n", iValue & 0x1f);
872     DBG(DBG_FNC, "         bit[5..7] = Top Reference Voltage: 0x%02x\n", (iValue >> 5) & 3);
873
874     iValue = data_lsb_get(&buffer[0x018], 1);
875     DBG(DBG_FNC, "0x0018");
876     DBG(DBG_FNC, "   bit[0..4] = Variable Gain Amplifier 2 [GREEN] : 0x%02x\n", iValue & 0x1f);
877     DBG(DBG_FNC, "         bit[5..7] = Middle Reference Voltage: 0x%02x\n", (iValue >> 5) & 3);
878
879     iValue = data_lsb_get(&buffer[0x019], 1);
880     DBG(DBG_FNC, "0x0019");
881     DBG(DBG_FNC, "   bit[0..4] = Variable Gain Amplifier 2 [BLUE] : 0x%02x\n", iValue & 0x1f);
882     DBG(DBG_FNC, "         bit[5..7] = Bottom Reference Voltage: 0x%02x\n", (iValue >> 5) & 3);
883
884     iValue = data_lsb_get(&buffer[0x01a], 1);
885     iValue2 = data_lsb_get(&buffer[0x01b], 1);
886     DBG(DBG_FNC, "\n0x001a-0x001b\n");
887     DBG(DBG_FNC, "         Red Even offset 1: 0x%02x\n", ((iValue2 & 0x80) << 1) | iValue);
888     DBG(DBG_FNC, "         Red Even offset 2: 0x%02x\n", iValue2 & 0x3f);
889
890     iValue = data_lsb_get(&buffer[0x01c], 1);
891     iValue2 = data_lsb_get(&buffer[0x01d], 1);
892     DBG(DBG_FNC, "0x001c-0x001d\n");
893     DBG(DBG_FNC, "         Red Odd offset 1: 0x%02x\n", ((iValue2 & 0x80) << 1) | iValue);
894     DBG(DBG_FNC, "         Red Odd offset 2: 0x%02x\n", iValue2 & 0x3f);
895
896     iValue = data_lsb_get(&buffer[0x01e], 1);
897     iValue2 = data_lsb_get(&buffer[0x01f], 1);
898     DBG(DBG_FNC, "0x001e-0x001f\n");
899     DBG(DBG_FNC, "         Green Even offset 1: 0x%02x\n", ((iValue2 & 0x80) << 1) | iValue);
900     DBG(DBG_FNC, "         Green Even offset 2: 0x%02x\n", iValue2 & 0x3f);
901
902     iValue = data_lsb_get(&buffer[0x020], 1);
903     iValue2 = data_lsb_get(&buffer[0x021], 1);
904     DBG(DBG_FNC, "0x0020-0x0021\n");
905     DBG(DBG_FNC, "         Green Odd offset 1: 0x%02x\n", ((iValue2 & 0x80) << 1) | iValue);
906     DBG(DBG_FNC, "         Green Odd offset 2: 0x%02x\n", iValue2 & 0x3f);
907
908     iValue = data_lsb_get(&buffer[0x022], 1);
909     iValue2 = data_lsb_get(&buffer[0x023], 1);
910     DBG(DBG_FNC, "0x0022-0x0023\n");
911     DBG(DBG_FNC, "         Blue Even offset 1: 0x%02x\n", ((iValue2 & 0x80) << 1) | iValue);
912     DBG(DBG_FNC, "         Blue Even offset 2: 0x%02x\n", iValue2 & 0x3f);
913
914     iValue = data_lsb_get(&buffer[0x024], 1);
915     iValue2 = data_lsb_get(&buffer[0x025], 1);
916     DBG(DBG_FNC, "0x0024-0x0025\n");
917     DBG(DBG_FNC, "         Blue Odd offset 1: 0x%02x\n", ((iValue2 & 0x80) << 1) | iValue);
918     DBG(DBG_FNC, "         Blue Odd offset 2: 0x%02x\n", iValue2 & 0x3f);
919
920     dbg_buffer(DBG_FNC, "\n0x0026", &buffer[0x026], 0x03, 0x26);
921
922     iValue = data_lsb_get(&buffer[0x029], 1);
923     DBG(DBG_FNC, "\n0x0029");
924     DBG(DBG_FNC, "   First connection to scanner? : 0x%02x\n", iValue);
925
926     dbg_buffer(DBG_FNC, "\n0x002a", &buffer[0x02a], 0x06, 0x2a);
927
928     DBG(DBG_FNC, "\nExposure times:\n");
929     iValue = data_lsb_get(&buffer[0x030], 3);
930     DBG(DBG_FNC, "0x0030   Line exposure time : %i us\n", iValue);
931
932     iValue = data_lsb_get(&buffer[0x033], 3);
933     DBG(DBG_FNC, "\n0x0033   mexpts[RED]  : %i us\n", iValue);
934
935     iValue = data_lsb_get(&buffer[0x036], 3);
936     DBG(DBG_FNC, "0x0036    expts[RED]  : %i us\n", iValue);
937
938     iValue = data_lsb_get(&buffer[0x039], 3);
939     DBG(DBG_FNC, "0x0039   mexpts[GREEN]: %i us\n", iValue);
940
941     iValue = data_lsb_get(&buffer[0x03c], 3);
942     DBG(DBG_FNC, "0x003c    expts[GREEN]: %i us\n", iValue);
943
944     iValue = data_lsb_get(&buffer[0x03f], 3);
945     DBG(DBG_FNC, "0x003f   mexpts[BLUE] : %i us\n", iValue);
946
947     iValue = data_lsb_get(&buffer[0x042], 3);
948     DBG(DBG_FNC, "0x0042    expts[BLUE] : %i us\n", iValue);
949
950     iValue = data_lsb_get(&buffer[0x045], 1);
951     DBG(DBG_FNC, "\n0x0045   bit[0..4] = timing.cvtrfpw: 0x%02x\n", iValue & 0x1f);
952     DBG(DBG_FNC, "         bit[5] = timing.cvtrp[2]: 0x%02x\n", (iValue >> 5) & 1);
953     DBG(DBG_FNC, "         bit[6] = timing.cvtrp[1]: 0x%02x\n", (iValue >> 6) & 1);
954     DBG(DBG_FNC, "         bit[7] = timing.cvtrp[0]: 0x%02x\n", (iValue >> 7) & 1);
955
956     iValue = data_lsb_get(&buffer[0x046], 1);
957     DBG(DBG_FNC, "0x0046");
958     DBG(DBG_FNC, "   bit[0..4] = timing.cvtrbpw: 0x%02x\n", iValue & 0x1f);
959     DBG(DBG_FNC, "         bit[5..7] = ?: 0x%02x\n", (iValue >> 5) & 3);
960
961     iValue = data_lsb_get(&buffer[0x047], 1);
962     DBG(DBG_FNC, "0x0047");
963     DBG(DBG_FNC, "   timing.cvtrw: 0x%02x\n", iValue);
964
965     iValue = data_lsb_get(&buffer[0x04c], 0x01) & 0x0f;
966     dValue = iValue * pow(2, 32);
967     iValue = data_lsb_get(&buffer[0x04a], 0x02);
968     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x048], 0x02);
969     DBG(DBG_FNC, "\n0x0048 Linear image sensor clock 1\n");
970     DBG(DBG_FNC, "         bit[0..35] = timing.cph0p1: %.0f.\n", dValue);
971     iValue = data_lsb_get(&buffer[0x04c], 0x01);
972     DBG(DBG_FNC, "         bit[36] = timing.cph0go: 0x%02x\n", (iValue >> 4) & 1);
973     DBG(DBG_FNC, "         bit[37] = timing.cph0ge: 0x%02x\n", (iValue >> 5) & 1);
974     DBG(DBG_FNC, "         bit[38] = timing.cph0ps: 0x%02x\n", (iValue >> 6) & 1);
975     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 7) & 1);
976
977     iValue = data_lsb_get(&buffer[0x051], 0x01) & 0x0f;
978     dValue = iValue * pow(2, 32);
979     iValue = data_lsb_get(&buffer[0x04f], 0x02);
980     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x04d], 0x02);
981     DBG(DBG_FNC, "0x004d");
982     DBG(DBG_FNC, "   bit[0..35] = timing.cph0p2: %.0f.\n", dValue);
983
984     iValue = data_lsb_get(&buffer[0x056], 1) & 0x0f;
985     dValue = iValue * pow(2, 32);
986     iValue = data_lsb_get(&buffer[0x054], 2);
987     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x052], 2);
988     DBG(DBG_FNC, "\n0x0052 Linear image sensor clock 2\n");
989     DBG(DBG_FNC, "         bit[0..35] = timing.cph1p1: %.0f.\n", dValue);
990     iValue = data_lsb_get(&buffer[0x056], 1);
991     DBG(DBG_FNC, "         bit[36] = timing.cph1go: 0x%02x\n", (iValue >> 4) & 1);
992     DBG(DBG_FNC, "         bit[37] = timing.cph1ge: 0x%02x\n", (iValue >> 5) & 1);
993     DBG(DBG_FNC, "         bit[38] = timing.cph1ps: 0x%02x\n", (iValue >> 6) & 1);
994     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 7) & 1);
995
996
997     iValue = data_lsb_get(&buffer[0x05b], 0x01) & 0x0f;
998     dValue = iValue * pow(2, 32);
999     iValue = data_lsb_get(&buffer[0x059], 0x02);
1000     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x057], 0x02);
1001     DBG(DBG_FNC, "0x0057");
1002     DBG(DBG_FNC, "   bit[0..35] = timing.cph1p2: %.0f.\n", dValue);
1003     iValue = data_lsb_get(&buffer[0x05b], 0x01);
1004     DBG(DBG_FNC, "         bits[36..39] = %02x\n", (iValue >> 0x04) & 0x0f);
1005     DBG(DBG_FNC, "         bit[36] = ?: %02x\n", (iValue >> 0x04) & 0x01);
1006     DBG(DBG_FNC, "         bit[37] = ?: %02x\n", (iValue >> 0x05) & 0x01);
1007     DBG(DBG_FNC, "         bit[38] = ?: %02x\n", (iValue >> 0x06) & 0x01);
1008     DBG(DBG_FNC, "         bit[39] = ?: %02x\n", (iValue >> 0x07) & 0x01);
1009
1010     iValue = data_lsb_get(&buffer[0x060], 0x01) & 0x0f;
1011     dValue = iValue * pow(2, 32);
1012     iValue = data_lsb_get(&buffer[0x05e], 0x02);
1013     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x05c], 0x02);
1014     DBG(DBG_FNC, "\n0x005c Linear Image Sensor Clock 3\n");
1015     DBG(DBG_FNC, "         bit[0..35] = timing.cph2p1: %.0f.\n", dValue);
1016     iValue = data_lsb_get(&buffer[0x060], 0x01);
1017     DBG(DBG_FNC, "         bit[36] = timing.cph2go: 0x%02x\n", (iValue >> 0x04) & 0x01);
1018     DBG(DBG_FNC, "         bit[37] = timing.cph2ge: 0x%02x\n", (iValue >> 0x05) & 0x01);
1019     DBG(DBG_FNC, "         bit[38] = timing.cph2ps: 0x%02x\n", (iValue >> 0x06) & 0x01);
1020     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 0x07) & 0x01);
1021
1022     iValue = data_lsb_get(&buffer[0x065], 0x01) & 0x0f;
1023     dValue = iValue * pow(2, 32);
1024     iValue = data_lsb_get(&buffer[0x063], 0x02);
1025     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x061], 0x02);
1026     DBG(DBG_FNC, "0x0061");
1027     DBG(DBG_FNC, "   bit[0..35] = timing.cph2p2: %.0f.\n", dValue);
1028     iValue = data_lsb_get(&buffer[0x065], 0x01);
1029     DBG(DBG_FNC, "         bits[36..39] = 0x%02x\n", (iValue >> 0x04) & 0x0f);
1030     DBG(DBG_FNC, "         bit[36] = ?: 0x%02x\n", (iValue >> 0x04) & 0x01);
1031     DBG(DBG_FNC, "         bit[37] = ?: 0x%02x\n", (iValue >> 0x05) & 0x01);
1032     DBG(DBG_FNC, "         bit[38] = ?: 0x%02x\n", (iValue >> 0x06) & 0x01);
1033     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 0x07) & 0x01);
1034
1035     iValue = data_lsb_get(&buffer[0x06a], 0x01) & 0x0f;
1036     dValue = iValue * pow(2, 32);
1037     iValue = data_lsb_get(&buffer[0x068], 0x02);
1038     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x066], 0x02);
1039     DBG(DBG_FNC, "\n0x0066 Linear Image Sensor Clock 4\n");
1040     DBG(DBG_FNC, "         bit[0..35] = timing.cph3p1: %.0f.\n", dValue);
1041     iValue = data_lsb_get(&buffer[0x06a], 0x01);
1042     DBG(DBG_FNC, "         bit[36] = timing.cph3go: 0x%02x\n", (iValue >> 0x04) & 0x01);
1043     DBG(DBG_FNC, "         bit[37] = timing.cph3ge: 0x%02x\n", (iValue >> 0x05) & 0x01);
1044     DBG(DBG_FNC, "         bit[38] = timing.cph3ps: 0x%02x\n", (iValue >> 0x06) & 0x01);
1045     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 0x07) & 0x01);
1046
1047     iValue = data_lsb_get(&buffer[0x06f], 0x01) & 0x0f;
1048     dValue = iValue * pow(2, 32);
1049     iValue = data_lsb_get(&buffer[0x06d], 0x02);
1050     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x06b], 0x02);
1051     DBG(DBG_FNC, "0x006b");
1052     DBG(DBG_FNC, "   bit[0..35] = timing.cph3p2: %.0f.\n", dValue);
1053     iValue = data_lsb_get(&buffer[0x06f], 0x01);
1054     DBG(DBG_FNC, "         bits[36..39] = 0x%02x\n", (iValue >> 0x04) & 0x0f);
1055     DBG(DBG_FNC, "         bit[36] = ?: 0x%02x\n", (iValue >> 0x04) & 0x01);
1056     DBG(DBG_FNC, "         bit[37] = ?: 0x%02x\n", (iValue >> 0x05) & 0x01);
1057     DBG(DBG_FNC, "         bit[38] = ?: 0x%02x\n", (iValue >> 0x06) & 0x01);
1058     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 0x07) & 0x01);
1059
1060     iValue = data_lsb_get(&buffer[0x074], 0x01) & 0x0f;
1061     dValue = iValue * pow(2, 32);
1062     iValue = data_lsb_get(&buffer[0x072], 0x02);
1063     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x070], 0x02);
1064     DBG(DBG_FNC, "\n0x0070 Linear Image Sensor Clock 5\n");
1065     DBG(DBG_FNC, "         bit[0..35] = timing.cph4p1: %.0f.\n", dValue);
1066     iValue = data_lsb_get(&buffer[0x074], 0x01);
1067     DBG(DBG_FNC, "         bit[36] = timing.cph4go: 0x%02x\n", (iValue >> 0x04) & 0x01);
1068     DBG(DBG_FNC, "         bit[37] = timing.cph4ge: 0x%02x\n", (iValue >> 0x05) & 0x01);
1069     DBG(DBG_FNC, "         bit[38] = timing.cph4ps: 0x%02x\n", (iValue >> 0x06) & 0x01);
1070     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 0x07) & 0x01);
1071
1072     iValue = data_lsb_get(&buffer[0x079], 0x01) & 0x0f;
1073     dValue = iValue * pow(2, 32);
1074     iValue = data_lsb_get(&buffer[0x077], 0x02);
1075     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x075], 0x02);
1076     DBG(DBG_FNC, "0x0075");
1077     DBG(DBG_FNC, "   bit[0..35] = timing.cph4p2: %.0f.\n", dValue);
1078     iValue = data_lsb_get(&buffer[0x079], 0x01);
1079     DBG(DBG_FNC, "         bits[36..39] = 0x%02x\n", (iValue >> 0x04) & 0x0f);
1080     DBG(DBG_FNC, "         bit[36] = ?: 0x%02x\n", (iValue >> 0x04) & 0x01);
1081     DBG(DBG_FNC, "         bit[37] = ?: 0x%02x\n", (iValue >> 0x05) & 0x01);
1082     DBG(DBG_FNC, "         bit[38] = ?: 0x%02x\n", (iValue >> 0x06) & 0x01);
1083     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 0x07) & 0x01);
1084
1085     iValue = data_lsb_get(&buffer[0x07e], 0x01) & 0x0f;
1086     dValue = iValue * pow(2, 32);
1087     iValue = data_lsb_get(&buffer[0x07c], 0x02);
1088     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x07a], 0x02);
1089     DBG(DBG_FNC, "\n0x007a Linear Image Sensor Clock 6\n");
1090     DBG(DBG_FNC, "         bit[0..35] = timing.cph5p1: %.0f.\n", dValue);
1091     iValue = data_lsb_get(&buffer[0x07e], 0x01);
1092     DBG(DBG_FNC, "         bit[36] = timing.cph5go: 0x%02x\n", (iValue >> 0x04) & 0x01);
1093     DBG(DBG_FNC, "         bit[37] = timing.cph5ge: 0x%02x\n", (iValue >> 0x05) & 0x01);
1094     DBG(DBG_FNC, "         bit[38] = timing.cph5ps: 0x%02x\n", (iValue >> 0x06) & 0x01);
1095     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 0x07) & 0x01);
1096
1097     iValue = data_lsb_get(&buffer[0x083], 0x01) & 0x0f;
1098     dValue = iValue * pow(2, 32);
1099     iValue = data_lsb_get(&buffer[0x081], 0x02);
1100     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x07f], 0x02);
1101     DBG(DBG_FNC, "0x007f");
1102     DBG(DBG_FNC, "   bit[0..35] = timing.cph5p2: %.0f.\n", dValue);
1103     iValue = data_lsb_get(&buffer[0x083], 0x01);
1104     DBG(DBG_FNC, "         bits[36..39] = 0x%02x\n", (iValue >> 0x04) & 0x0f);
1105     DBG(DBG_FNC, "         bit[36] = ?: 0x%02x\n", (iValue >> 0x04) & 0x01);
1106     DBG(DBG_FNC, "         bit[37] = ?: 0x%02x\n", (iValue >> 0x05) & 0x01);
1107     DBG(DBG_FNC, "         bit[38] = ?: 0x%02x\n", (iValue >> 0x06) & 0x01);
1108     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 0x07) & 0x01);
1109
1110     iValue = data_lsb_get(&buffer[0x084], 3);
1111     DBG(DBG_FNC, "\n0x0084");
1112     DBG(DBG_FNC, "   timing.cphbp2s : 0x%06x\n", iValue);
1113
1114     iValue = data_lsb_get(&buffer[0x087], 3);
1115     DBG(DBG_FNC, "0x0087");
1116     DBG(DBG_FNC, "   timing.cphbp2e : 0x%06x\n", iValue);
1117
1118     iValue = data_lsb_get(&buffer[0x08a], 3);
1119     DBG(DBG_FNC, "0x008a");
1120     DBG(DBG_FNC, "   timing.clamps : 0x%08x\n", iValue);
1121
1122     iValue = data_lsb_get(&buffer[0x08d], 3);
1123     DBG(DBG_FNC, "0x008d");
1124     DBG(DBG_FNC, "   timing.clampe or cphbp2e : 0x%08x\n", iValue);
1125
1126     iValue = data_lsb_get(&buffer[0x092], 0x01);
1127     DBG(DBG_FNC, "\n0x0092 Correlated-Double-Sample 1\n");
1128     DBG(DBG_FNC, "         bit[0..5] = timing.cdss[0]: 0x%02x\n", iValue & 0x3f);
1129     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n", (iValue >> 6) & 3);
1130
1131     iValue = data_lsb_get(&buffer[0x093], 0x01);
1132     DBG(DBG_FNC, "0x0093");
1133     DBG(DBG_FNC, "   bit[0..5] = timing.cdsc[0]: 0x%02x\n", iValue & 0x3f);
1134     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n", (iValue >> 6) & 3);
1135
1136     iValue = data_lsb_get(&buffer[0x094], 0x01);
1137     DBG(DBG_FNC, "\n0x0094 Correlated-Double-Sample 2\n");
1138     DBG(DBG_FNC, "         bit[0..5] = timing.cdss[1]: 0x%02x\n", iValue & 0x3f);
1139     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n", (iValue >> 6) & 3);
1140
1141     iValue = data_lsb_get(&buffer[0x095], 0x01);
1142     DBG(DBG_FNC, "0x0095");
1143     DBG(DBG_FNC, "   bit[0..5] = timing.cdsc[1]: 0x%02x\n", iValue & 0x3f);
1144     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n", (iValue >> 6) & 3);
1145
1146     iValue = data_lsb_get(&buffer[0x096], 0x01);
1147     DBG(DBG_FNC, "0x0096");
1148     DBG(DBG_FNC, "   bit[0..5] = timing.cnpp: 0x%02x\n", iValue & 0x3f);
1149     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n", (iValue >> 6) & 3);
1150
1151     iValue = data_lsb_get(&buffer[0x09b], 0x01) & 0x0f;
1152     dValue = iValue * pow(2, 32);
1153     iValue = data_lsb_get(&buffer[0x099], 0x02);
1154     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x097], 0x02);
1155     DBG(DBG_FNC, "\n0x0097 Analog to Digital Converter clock 1\n");
1156     DBG(DBG_FNC, "         bit[0..35] = timing.adcclkp[0]: %.0f.\n", dValue);
1157     iValue = data_lsb_get(&buffer[0x09b], 0x01);
1158     DBG(DBG_FNC, "         bits[36..39] = 0x%02x\n", (iValue >> 0x04) & 0x0f);
1159     DBG(DBG_FNC, "         bit[36] = ?: 0x%02x\n", (iValue >> 0x04) & 0x01);
1160     DBG(DBG_FNC, "         bit[37] = ?: 0x%02x\n", (iValue >> 0x05) & 0x01);
1161     DBG(DBG_FNC, "         bit[38] = ?: 0x%02x\n", (iValue >> 0x06) & 0x01);
1162     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 0x07) & 0x01);
1163
1164     dbg_buffer(DBG_FNC, "\n0x009c CIS sensor 1", &buffer[0x09c], 0x06, 0x9c);
1165     dbg_buffer(DBG_FNC, "0x00a2 CIS sensor 2", &buffer[0x0a2], 0x06, 0xa2);
1166     dbg_buffer(DBG_FNC, "0x00a8 CIS sensor 3", &buffer[0x0a8], 0x06, 0xa8);
1167
1168     iValue = data_lsb_get(&buffer[0x0ae], 0x01);
1169     DBG(DBG_FNC, "\n0x00ae");
1170     DBG(DBG_FNC, "   bit[0..5] = ?: 0x%02x\n", iValue & 0x3f);
1171     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n", (iValue >> 6) & 3);
1172
1173     iValue = data_lsb_get(&buffer[0x0af], 0x01);
1174     DBG(DBG_FNC, "0x00af");
1175     DBG(DBG_FNC, "   bit[0..2] = ?: 0x%02x\n", iValue & 7);
1176     DBG(DBG_FNC, "         bit[3..7] = ?: 0x%02x\n", (iValue >> 3) & 0x1f);
1177
1178     iValue = data_lsb_get(&buffer[0x0b0], 2);
1179     DBG(DBG_FNC, "\n0x00b0");
1180     DBG(DBG_FNC, "   Left : 0x%04x\n", iValue);
1181
1182     iValue = data_lsb_get(&buffer[0x0b2], 2);
1183     DBG(DBG_FNC, "0x00b2");
1184     DBG(DBG_FNC, "   Right: 0x%04x\n", iValue);
1185
1186     dbg_buffer(DBG_FNC, "\n0x00b4", &buffer[0x0b4], 12, 0xb4);
1187
1188     iValue = data_lsb_get(&buffer[0x0c0], 0x01);
1189     DBG(DBG_FNC, "\n0x00c0");
1190     DBG(DBG_FNC, "   bit[0..4] = resolution ratio: 0x%02x\n", iValue & 0x1f);
1191     DBG(DBG_FNC, "         bit[5..7] = ?: 0x%02x\n", (iValue >> 5) & 7);
1192
1193     iValue = data_lsb_get(&buffer[0x0c5], 0x01) & 0x0f;
1194     dValue = iValue * pow(2, 32);
1195     iValue = data_lsb_get(&buffer[0x0c3], 0x02);
1196     dValue = dValue + (iValue * pow(2, 16)) + data_lsb_get(&buffer[0x0c1], 2);
1197     DBG(DBG_FNC, "\n0x00c1 Analog to Digital Converter clock 2\n");
1198     DBG(DBG_FNC, "         bit[0..35] = timing.adcclkp[1]: %.0f.\n", dValue);
1199     iValue = data_lsb_get(&buffer[0x0c5], 0x01);
1200     DBG(DBG_FNC, "         bits[36..39] = 0x%02x\n", (iValue >> 0x04) & 0x0f);
1201     DBG(DBG_FNC, "         bit[36] = ?: 0x%02x (equal to bit[32])\n", (iValue >> 0x04) & 0x01);
1202     DBG(DBG_FNC, "         bit[37] = ?: 0x%02x\n", (iValue >> 0x05) & 0x01);
1203     DBG(DBG_FNC, "         bit[38] = ?: 0x%02x\n", (iValue >> 0x06) & 0x01);
1204     DBG(DBG_FNC, "         bit[39] = ?: 0x%02x\n", (iValue >> 0x07) & 0x01);
1205
1206     dbg_buffer(DBG_FNC, "\n0x00c6", &buffer[0x0c6], 0x0a, 0xc6);
1207
1208     iValue = ((buffer[0x0d4] & 0x0f) << 0x10) + data_lsb_get(&buffer[0x0d0], 0x02);
1209     DBG(DBG_FNC, "\n0x00d0");
1210     DBG(DBG_FNC, "   Top : 0x%04x\n", iValue);
1211
1212     iValue = ((buffer[0x0d4] & 0xf0) << 0x06)+ data_lsb_get(&buffer[0x0d2], 0x02);
1213     DBG(DBG_FNC, "x00d2");
1214     DBG(DBG_FNC, "   Down: 0x%04x\n", iValue);
1215
1216     iValue = _B0(buffer[0x0d5]);
1217     DBG(DBG_FNC, "0x00d5");
1218     DBG(DBG_FNC, "   ?: 0x%04x\n", iValue);
1219
1220     iValue = data_lsb_get(&buffer[0x0d6], 1);
1221     DBG(DBG_FNC, "\n0x00d6");
1222     DBG(DBG_FNC, "   bit[0..3]    = ? : 0x%02x\n", iValue & 0xf);
1223     DBG(DBG_FNC, "         bit[4..7] = dummyline: 0x%02x\n", (iValue >> 4) & 0xf);
1224
1225     iValue = data_lsb_get(&buffer[0x0d7], 0x01);
1226     DBG(DBG_FNC, "\n0x00d7");
1227     DBG(DBG_FNC, "   bit[0..5] = motor pwm frequency: 0x%02x\n", iValue & 0x3f);
1228     DBG(DBG_FNC, "         bit[6]    = ?: 0x%02x\n", (iValue >> 6) & 1);
1229     DBG(DBG_FNC, "         bit[7]    = motor type: 0x%02x ", (iValue >> 7) & 1);
1230     if (((iValue >> 7) & 1) == MT_OUTPUTSTATE)
1231     DBG(DBG_FNC, ": Output state machine\n");
1232     else DBG(DBG_FNC, "On-Chip PWM\n");
1233
1234     iValue = data_lsb_get(&buffer[0x0d8], 0x01);
1235     DBG(DBG_FNC, "\n0x00d8");
1236     DBG(DBG_FNC, "   bit[0..5] = ?: 0x%02x\n", iValue & 0x3f);
1237     DBG(DBG_FNC, "         bit[6]    = scantype (0=Normal|1=TMA) : 0x%02x\n", (iValue >> 6) & 1);
1238     DBG(DBG_FNC, "         bit[7]    = enable head movement : 0x%02x :", (iValue >> 7) & 1);
1239
1240     iValue = data_lsb_get(&buffer[0x0d9], 0x01);
1241     DBG(DBG_FNC, "\n0x00d9");
1242     DBG(DBG_FNC, "   bit[0..2] = ?: 0x%02x\n", iValue & 7);
1243     DBG(DBG_FNC, "         bit[3]    = ?: 0x%02x\n", (iValue >> 3) & 1);
1244     DBG(DBG_FNC, "         bit[4..6] = motor step type: 0x%02x: ", (iValue >> 4) & 7);
1245     switch((iValue >> 4) & 7)
1246     {
1247     case 0:  DBG(DBG_FNC, "full  (1)\n"); break;
1248     case 1:  DBG(DBG_FNC, "half  (1/2)\n"); break;
1249     case 2:  DBG(DBG_FNC, "quart (1/4)\n"); break;
1250     case 3:  DBG(DBG_FNC, "(1/8)\n"); break;
1251     default: DBG(DBG_FNC, "unknown\n"); break;
1252     }
1253     DBG(DBG_FNC, "         bit[7]    = Motor direction: 0x%02x = ", (iValue >> 7) & 1);
1254     if (((iValue >> 7) & 1) == 0)
1255     DBG(DBG_FNC, "Backward\n");
1256     else DBG(DBG_FNC, "Forward\n");
1257
1258     iValue = data_lsb_get(&buffer[0x0dd], 0x01);
1259     DBG(DBG_FNC, "\n0x00da");
1260     DBG(DBG_FNC, "   msi = 0x%03x\n", ((iValue & 3) << 8) + data_lsb_get(&buffer[0x0da], 1));
1261
1262     DBG(DBG_FNC, "0x00db");
1263     DBG(DBG_FNC, "   motorbackstep1 = 0x%03x\n", ((iValue & 0x0c) << 6)  + data_lsb_get(&buffer[0x0db], 1));
1264
1265     DBG(DBG_FNC, "0x00dc");
1266     DBG(DBG_FNC, "   motorbackstep2 = 0x%03x\n", ((iValue & 0x30) << 4)  + data_lsb_get(&buffer[0x0dc], 1));
1267
1268     iValue = data_lsb_get(&buffer[0x0dd], 0x01);
1269     DBG(DBG_FNC, "0x00dd");
1270     DBG(DBG_FNC, "         bit[7]    = Motor enabled?: 0x%02x = ", (iValue >> 7) & 1);
1271     if (((iValue >> 7) & 1) == 0)
1272     DBG(DBG_FNC, "Yes\n");
1273     else DBG(DBG_FNC, "No\n");
1274
1275     iValue = data_lsb_get(&buffer[0x0de], 0x02);
1276     DBG(DBG_FNC, "\n0x00de");
1277     DBG(DBG_FNC, "   bit[00..11] = ?: 0x%02x\n", iValue & 0xfff);
1278     DBG(DBG_FNC, "         bit[12..15] = ?: 0x%02x\n", (iValue >> 12) & 0x0f);
1279
1280     iValue = data_lsb_get(&buffer[0x0df], 0x01);
1281     DBG(DBG_FNC, "\n0x00df");
1282     DBG(DBG_FNC, "   bit[0..3] = ?: 0x%02x\n", iValue & 0x0f);
1283     DBG(DBG_FNC, "         bit[4]    = has_motorcurves?: 0x%02x\n", (iValue >> 4) & 0x01);
1284     DBG(DBG_FNC, "         bit[5..7] = ?: 0x%02x\n", (iValue >> 5) & 7);
1285
1286     iValue = data_lsb_get(&buffer[0x0e0], 1);
1287     DBG(DBG_FNC, "\n0x00e0   step size - 1 : 0x%02x\n", iValue);
1288
1289     iValue = data_lsb_get(&buffer[0x0e1], 3);
1290     DBG(DBG_FNC, "\n0x00e1   0x%06x : last step of accurve.normalscan table\n", iValue);
1291
1292     iValue = data_lsb_get(&buffer[0x0e4], 3);
1293     DBG(DBG_FNC, "0x00e4   0x%06x : last step of accurve.smearing table\n", iValue);
1294
1295     iValue = data_lsb_get(&buffer[0x0e7], 3);
1296     DBG(DBG_FNC, "0x00e7   0x%06x : last step of accurve.parkhome table\n", iValue);
1297
1298     iValue = data_lsb_get(&buffer[0x0ea], 3);
1299     DBG(DBG_FNC, "0x00ea   0x%06x : last step of deccurve.scanbufferfull table\n", iValue);
1300
1301     iValue = data_lsb_get(&buffer[0x0ed], 3);
1302     DBG(DBG_FNC, "0x00ed   0x%06x : last step of deccurve.normalscan table\n", iValue);
1303
1304     iValue = data_lsb_get(&buffer[0x0f0], 3);
1305     DBG(DBG_FNC, "0x00f0   0x%06x : last step of deccurve.smearing table\n", iValue);
1306
1307     iValue = data_lsb_get(&buffer[0x0f3], 3);
1308     DBG(DBG_FNC, "0x00f3   0x%06x : last step of deccurve.parkhome table\n", iValue);
1309
1310     iValue = data_lsb_get(&buffer[0x0f6], 2);
1311     DBG(DBG_FNC, "\n0x00f6   bit[00..13] = 0x%04x : ptr to accurve.normalscan step table\n", iValue & 0x3fff);
1312     DBG(DBG_FNC, "         bit[14..15] = 0x%04x : ?\n",(iValue >> 14) & 3);
1313
1314     iValue = data_lsb_get(&buffer[0x0f8], 2);
1315     DBG(DBG_FNC, "0x00f8");
1316     DBG(DBG_FNC, "   bit[00..13] = 0x%04x : ptr to deccurve.scanbufferfull step table\n", iValue & 0x3fff);
1317     DBG(DBG_FNC, "         bit[14..15] = 0x%04x : ?\n",(iValue >> 14) & 3);
1318
1319     iValue = data_lsb_get(&buffer[0x0fa], 2);
1320     DBG(DBG_FNC, "0x00fa");
1321     DBG(DBG_FNC, "   bit[00..13] = 0x%04x : ptr to accurve.smearing step table\n", iValue & 0x3fff);
1322     DBG(DBG_FNC, "         bit[14..15] = 0x%04x : ?\n",(iValue >> 14) & 3);
1323
1324     iValue = data_lsb_get(&buffer[0x0fc], 2);
1325     DBG(DBG_FNC, "0x00fc");
1326     DBG(DBG_FNC, "   bit[00..13] = 0x%04x : ptr to deccurve.smearing step table\n", iValue & 0x3fff);
1327     DBG(DBG_FNC, "         bit[14..15] = 0x%04x : ?\n",(iValue >> 14) & 3);
1328
1329     iValue = data_lsb_get(&buffer[0x0fe], 2);
1330     DBG(DBG_FNC, "0x00fe");
1331     DBG(DBG_FNC, "   bit[00..13] = 0x%04x : ptr to deccurve.normalscan step table\n", iValue & 0x3fff);
1332     DBG(DBG_FNC, "         bit[14..15] = 0x%04x : ?\n",(iValue >> 14) & 3);
1333
1334     iValue = data_lsb_get(&buffer[0x100], 2);
1335     DBG(DBG_FNC, "0x0100");
1336     DBG(DBG_FNC, "   bit[00..13] = 0x%04x : ptr to accurve.parkhome step table\n", iValue & 0x3fff);
1337     DBG(DBG_FNC, "         bit[14..15] = 0x%04x : ?\n",(iValue >> 14) & 3);
1338
1339     iValue = data_lsb_get(&buffer[0x102], 2);
1340     DBG(DBG_FNC, "0x0102");
1341     DBG(DBG_FNC, "   bit[00..13] = 0x%04x : ptr to deccurve.parkhome step table\n", iValue & 0x3fff);
1342     DBG(DBG_FNC, "         bit[14..15] = 0x%04x : ?\n",(iValue >> 14) & 3);
1343
1344     dbg_buffer(DBG_FNC, "\n0x0104 Motor resource", &buffer[0x104], 0x20, 0x104);
1345
1346     dbg_buffer(DBG_FNC, "\n0x0124", &buffer[0x124], 0x22, 0x124);
1347
1348     iValue = data_lsb_get(&buffer[0x146], 1);
1349     DBG(DBG_FNC, "\n0x0146");
1350     DBG(DBG_FNC, "   bit[0..3] = Lamp pulse-width modulation frequency : 0x%02x\n", iValue & 0xf);
1351     DBG(DBG_FNC, "         bit[4]    = timer enabled? : 0x%02x\n", (iValue >> 4) & 1);
1352     DBG(DBG_FNC, "         bit[5]    = ? : 0x%02x\n", (iValue >> 5) & 1);
1353     DBG(DBG_FNC, "         bit[6]    = lamp turned on? : 0x%02x\n", (iValue >> 6) & 1);
1354     DBG(DBG_FNC, "         bit[7]    = sensor type : 0x%02x ", (iValue >> 7) & 1);
1355     if (((iValue >> 7) & 1) != 0)
1356     DBG(DBG_FNC, "CCD\n");
1357     else DBG(DBG_FNC, "CIS\n");
1358
1359     iValue = data_lsb_get(&buffer[0x147], 1);
1360     DBG(DBG_FNC, "\n0x0147");
1361     DBG(DBG_FNC, "   time to turn off lamp =  0x%02x (minutes * 2.682163611980331)\n", iValue);
1362
1363     iValue = data_lsb_get(&buffer[0x148], 1);
1364     DBG(DBG_FNC, "\n0x0148");
1365     DBG(DBG_FNC, "   bit[0..5] = Lamp pulse-width modulation duty cycle : 0x%02x\n", iValue & 0x3f);
1366     DBG(DBG_FNC, "         bit[6..7] = ? : 0x%02x\n",(iValue >> 6) & 3);
1367
1368     iValue = data_lsb_get(&buffer[0x149], 1);
1369     DBG(DBG_FNC, "\n0x0149");
1370     DBG(DBG_FNC, "   bit[0..5] = even_odd_distance : 0x%02x\n", iValue & 0x3f);
1371     DBG(DBG_FNC, "         bit[6..7] = ? : 0x%02x\n",(iValue >> 6) & 3);
1372
1373     iValue = data_lsb_get(&buffer[0x14a], 1);
1374     DBG(DBG_FNC, "0x014a");
1375     DBG(DBG_FNC, "   bit[0..5] = sensor line distance : 0x%02x\n", iValue & 0x3f);
1376     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n",(iValue >> 6) & 3);
1377
1378     iValue = data_lsb_get(&buffer[0x14b], 1);
1379     DBG(DBG_FNC, "0x014b");
1380     DBG(DBG_FNC, "   bit[0..5] = sensor line distance + even_odd_distance: 0x%02x\n", iValue & 0x3f);
1381     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n",(iValue >> 6) & 3);
1382
1383     iValue = data_lsb_get(&buffer[0x14c], 1);
1384     DBG(DBG_FNC, "0x014c");
1385     DBG(DBG_FNC, "   bit[0..5] = sensor line distance * 2: 0x%02x\n", iValue & 0x3f);
1386     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n", (iValue >> 6) & 3);
1387
1388     iValue = data_lsb_get(&buffer[0x14d], 1);
1389     DBG(DBG_FNC, "0x014d");
1390     DBG(DBG_FNC, "   bit[0..5] = (sensor line distance * 2) + even_odd_distance: 0x%02x\n", iValue & 0x3f);
1391     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n", (iValue >> 6) & 3);
1392
1393     iValue = data_lsb_get(&buffer[0x14e], 1);
1394     DBG(DBG_FNC, "\n0x014e");
1395     DBG(DBG_FNC, "   bit[0..3] = ?: 0x%02x\n", iValue & 0xf);
1396     DBG(DBG_FNC, "         bit[4]    = ?: 0x%02x\n", (iValue >> 4) & 1);
1397     DBG(DBG_FNC, "         bit[5..7] = ?: 0x%02x\n", (iValue >> 5) & 7);
1398
1399     dbg_buffer(DBG_FNC, "\n0x014f", &buffer[0x14f], 0x05, 0x14f);
1400
1401     iValue = data_lsb_get(&buffer[0x154], 1);
1402     DBG(DBG_FNC, "\n0x0154");
1403     DBG(DBG_FNC, "   bit[0..3] = ?: 0x%02x\n", iValue & 0xf);
1404     DBG(DBG_FNC, "         bit[4..5] = ?: 0x%02x\n", (iValue >> 4) & 3);
1405     DBG(DBG_FNC, "         bit[6..7] = ?: 0x%02x\n", (iValue >> 6) & 7);
1406
1407     iValue = data_lsb_get(&buffer[0x155], 1);
1408     DBG(DBG_FNC, "\n0x0155");
1409     DBG(DBG_FNC, "   bit[0..3] = ?: 0x%02x\n", iValue & 0x0f);
1410     DBG(DBG_FNC, "         bit[4]    = 0x%02x : ", (iValue >> 4) & 1);
1411     if (((iValue >> 4) & 1) == 0)
1412     DBG(DBG_FNC, "flb lamp\n");
1413     else DBG(DBG_FNC, "tma lamp\n");
1414     DBG(DBG_FNC, "         bit[5..7] = ? : 0x%02x\n", (iValue >> 5) & 7);
1415
1416     dbg_buffer(DBG_FNC, "\n0x0156", &buffer[0x156], 0x02, 0x156);
1417
1418     iValue = data_lsb_get(&buffer[0x158], 1);
1419     DBG(DBG_FNC, "\n0x0158");
1420     DBG(DBG_FNC, "   bit[0..3] = %02x : Scanner buttons ", iValue & 0x0f);
1421     if ((iValue & 0x0f) == 0x0f)
1422     DBG(DBG_FNC, "enabled\n");
1423     else DBG(DBG_FNC, "disabled\n");
1424     DBG(DBG_FNC, "         bit[4..7] = ? : 0x%02x\n", (iValue >> 4) & 0x0f);
1425
1426     dbg_buffer(DBG_FNC, "\n0x0159", &buffer[0x159], 11, 0x159);
1427
1428     iValue = data_lsb_get(&buffer[0x164], 1);
1429     DBG(DBG_FNC, "\n0x0164");
1430     DBG(DBG_FNC, "   bit[0..6] = ?: 0x%02x\n", iValue & 0x3f);
1431     DBG(DBG_FNC, "         bit[7]    = ? : 0x%02x\n", (iValue >> 7) & 1);
1432
1433     dbg_buffer(DBG_FNC, "\n0x0165", &buffer[0x165], 3, 0x165);
1434
1435     iValue = data_lsb_get(&buffer[0x168], 1);
1436     DBG(DBG_FNC, "\n0x0168 Buttons status : 0x%02x\n", iValue);
1437     DBG(DBG_FNC, "         bit[0] = button 1 : 0x%02x\n", iValue & 1);
1438     DBG(DBG_FNC, "         bit[1] = button 2 : 0x%02x\n", (iValue >> 1) & 1);
1439     DBG(DBG_FNC, "         bit[2] = button 4 : 0x%02x\n", (iValue >> 2) & 1);
1440     DBG(DBG_FNC, "         bit[3] = button 3 : 0x%02x\n", (iValue >> 3) & 1);
1441     DBG(DBG_FNC, "         bit[4] = button ? : 0x%02x\n", (iValue >> 4) & 1);
1442     DBG(DBG_FNC, "         bit[5] = button ? : 0x%02x\n", (iValue >> 5) & 1);
1443     DBG(DBG_FNC, "         bit[6] = ? : 0x%02x\n", (iValue >> 6) & 1);
1444     DBG(DBG_FNC, "         bit[7] = ? : 0x%02x\n", (iValue >> 7) & 1);
1445
1446     iValue = data_lsb_get(&buffer[0x169], 1);
1447     DBG(DBG_FNC, "\n0x0169", iValue);
1448     DBG(DBG_FNC, "   bit[0]    = ? : 0x%02x\n", iValue & 1);
1449     DBG(DBG_FNC, "         bit[1]    = tma attached? : 0x%02x\n", (iValue >> 1) & 1);
1450     DBG(DBG_FNC, "         bit[2..7] = ? : 0x%02x\n", (iValue >> 2) & 0x3f);
1451
1452     iValue = data_lsb_get(&buffer[0x16a], 1);
1453     DBG(DBG_FNC, "\n0x016a Buttons status 2: 0x%02x\n", iValue);
1454     DBG(DBG_FNC, "         bit[0] = button 1 : 0x%02x\n", iValue & 1);
1455     DBG(DBG_FNC, "         bit[1] = button 2 : 0x%02x\n", (iValue >> 1) & 1);
1456     DBG(DBG_FNC, "         bit[2] = button 4 : 0x%02x\n", (iValue >> 2) & 1);
1457     DBG(DBG_FNC, "         bit[3] = button 3 : 0x%02x\n", (iValue >> 3) & 1);
1458     DBG(DBG_FNC, "         bit[4] = button ? : 0x%02x\n", (iValue >> 4) & 1);
1459     DBG(DBG_FNC, "         bit[5] = button ? : 0x%02x\n", (iValue >> 5) & 1);
1460     DBG(DBG_FNC, "         bit[6] = ? : 0x%02x\n", (iValue >> 6) & 1);
1461     DBG(DBG_FNC, "         bit[7] = ? : 0x%02x\n", (iValue >> 7) & 1);
1462
1463     dbg_buffer(DBG_FNC, "\n0x016b", &buffer[0x16b], 4, 0x16b);
1464
1465     iValue = data_lsb_get(&buffer[0x16f], 1);
1466     DBG(DBG_FNC, "\n0x016f");
1467     DBG(DBG_FNC, "   bit[0..5] = ? : 0x%02x\n", iValue & 0x3f);
1468     DBG(DBG_FNC, "         bit[6] = is lamp at home? : 0x%02x\n", (iValue >> 6) & 1);
1469     DBG(DBG_FNC, "         bit[7] = ?: %02x\n", (iValue >> 7) & 1);
1470
1471     dbg_buffer(DBG_FNC, "\n0x0170", &buffer[0x170], 0x17, 0x170);
1472
1473     iValue = data_lsb_get(&buffer[0x187], 1);
1474     DBG(DBG_FNC, "\n0x0187");
1475     DBG(DBG_FNC, "   bit[0..3] = ? : 0x%02x\n", iValue & 0xf);
1476     DBG(DBG_FNC, "         bit[4..7] = mclkioc : 0x%02x\n", (iValue >> 4) & 0xf);
1477
1478     dbg_buffer(DBG_FNC, "\n0x0188", &buffer[0x188], 0x16, 0x188);
1479
1480     iValue = data_lsb_get(&buffer[0x19e], 2);
1481     DBG(DBG_FNC, "\n0x019e");
1482     DBG(DBG_FNC, "   binary threshold low : 0x%04x\n", (iValue >> 8) + ((iValue << 8) & 0xff00));
1483
1484     iValue = data_lsb_get(&buffer[0x1a0], 2);
1485     DBG(DBG_FNC, "\n0x01a0");
1486     DBG(DBG_FNC, "   binary threshold high : 0x%04x\n", (iValue >> 8) + ((iValue << 8) & 0xff00));
1487
1488     dbg_buffer(DBG_FNC, "\n0x01a2", &buffer[0x1a2], 0x12, 0x1a2);
1489
1490     iValue = data_lsb_get(&buffer[0x1b4], 2);
1491     DBG(DBG_FNC, "\n0x01b4");
1492     DBG(DBG_FNC, "   bit[00..13] = Ptr to red gamma table (table_size * 0) : 0x%04x\n", (iValue & 0x3fff));
1493     DBG(DBG_FNC, "         bit[14..15] = ? : 0x%02x\n", (iValue >> 14) & 3);
1494
1495     iValue = data_lsb_get(&buffer[0x1b6], 2);
1496     DBG(DBG_FNC, "0x01b6");
1497     DBG(DBG_FNC, "   bit[00..13] = Ptr to green gamma table (table_size * 1) : 0x%04x\n", (iValue & 0x3fff));
1498     DBG(DBG_FNC, "         bit[14..15] = ? : 0x%02x\n", (iValue >> 14) & 3);
1499
1500     iValue = data_lsb_get(&buffer[0x1b8], 2);
1501     DBG(DBG_FNC, "0x01b8");
1502     DBG(DBG_FNC, "   bit[00..13] = Ptr to blue gamma table (table_size * 2) : 0x%04x\n", (iValue & 0x3fff));
1503     DBG(DBG_FNC, "         bit[14..15] = ? : 0x%02x\n", (iValue >> 14) & 3);
1504
1505     iValue = data_lsb_get(&buffer[0x1ba], 1);
1506     DBG(DBG_FNC, "\n0x01ba");
1507     DBG(DBG_FNC, "   ? : 0x%02x\n", iValue);
1508
1509     iValue = data_lsb_get(&buffer[0x1bb], 2);
1510     DBG(DBG_FNC, "0x01bb");
1511     DBG(DBG_FNC, "   ? : 0x%04x\n", iValue + ((data_lsb_get(&buffer[0x1bf], 1) & 1) << 16));
1512
1513     iValue = data_lsb_get(&buffer[0x1bd], 2);
1514     DBG(DBG_FNC, "0x01bd");
1515     DBG(DBG_FNC, "   ? : 0x%04x\n", iValue + (((data_lsb_get(&buffer[0x1bf], 1) >> 1) & 3) << 16));
1516
1517     iValue = data_lsb_get(&buffer[0x1c0], 3);
1518     DBG(DBG_FNC, "0x01c0");
1519     DBG(DBG_FNC, "   bit[0..19] = ? : 0x%06x\n", iValue  & 0xfffff);
1520
1521     iValue = data_lsb_get(&buffer[0x1bf], 2);
1522     DBG(DBG_FNC, "\n0x01bf");
1523     DBG(DBG_FNC, "   bit[3..4] = ? : 0x%02x\n", (iValue >> 3) & 3);
1524     DBG(DBG_FNC, "         bit[5..7] = ? : 0x%02x\n", (iValue >> 5) & 7);
1525
1526     iValue = data_lsb_get(&buffer[0x1c2], 3);
1527     DBG(DBG_FNC, "\n0x01c2");
1528     DBG(DBG_FNC, "   bit[4..23] = ? : 0x%06x\n", ((iValue >> 8) & 0xffff) + (((iValue >> 4) & 0xf) << 16));
1529
1530     iValue = data_lsb_get(&buffer[0x1c5], 3);
1531     DBG(DBG_FNC, "0x01c5");
1532     DBG(DBG_FNC, "   bit[00..19] = ? : 0x%06x\n", iValue  & 0xfffff);
1533     DBG(DBG_FNC, "         bit[20..23] = ? : 0x%02x\n", (iValue >> 20)  & 0xf);
1534
1535     dbg_buffer(DBG_FNC, "\n0x01c8", &buffer[0x1c8], 7, 0x1c8);
1536
1537     iValue = data_lsb_get(&buffer[0x1cf], 3);
1538     DBG(DBG_FNC, "\n0x01cf");
1539     DBG(DBG_FNC, "   bit[0] = ? : 0x%02x\n", iValue  & 1);
1540     DBG(DBG_FNC, "         bit[1]    = shading base (0 = 0x4000|1= 0x2000) : 0x%02x\n", (iValue >> 1) & 1);
1541     DBG(DBG_FNC, "         bit[2]    = white shading correction : 0x%02x\n", (iValue >> 2) & 1);
1542     DBG(DBG_FNC, "         bit[3]    = black shading correction : 0x%02x\n", (iValue >> 3) & 1);
1543     DBG(DBG_FNC, "         bit[4..5] = 0x%02x : ", (iValue >> 4) & 3);
1544     switch ((iValue >> 4) & 3)
1545     {
1546     case 0: DBG(DBG_FNC, "8 bits per channel"); break;
1547     case 1: DBG(DBG_FNC, "12 bits per channel"); break;
1548     case 2: DBG(DBG_FNC, "16 bits per channel"); break;
1549     case 3: DBG(DBG_FNC, "lineart mode"); break;
1550     }
1551     DBG(DBG_FNC, "\n");
1552     DBG(DBG_FNC, "         bit[6]    = samplerate: 0x%02x ", (iValue >> 6) & 1);
1553     if (((iValue >> 6) & 1) == PIXEL_RATE)
1554     DBG(DBG_FNC, "PIXEL_RATE\n");
1555     else DBG(DBG_FNC, "LINE_RATE\n");
1556     DBG(DBG_FNC, "         bit[7]    = ? : 0x%02x\n", (iValue >> 7) & 1);
1557
1558     iValue = data_lsb_get(&buffer[0x1d0], 1);
1559     DBG(DBG_FNC, "\n0x01d0");
1560     DBG(DBG_FNC, "   bit[0]    = 0x%02x\n", iValue  & 1);
1561     DBG(DBG_FNC, "         bit[1]    = 0x%02x\n", (iValue >> 1)  & 1);
1562     DBG(DBG_FNC, "         bit[2..3] = gamma table size : 0x%02x ", (iValue >> 2) & 3);
1563     switch ((iValue >> 2)  & 3)
1564     {
1565     case 0: DBG(DBG_FNC, "bit[0] + 0x100") ;break;
1566     case 1: DBG(DBG_FNC, "bit[0] + 0x400") ;break;
1567     case 2: DBG(DBG_FNC, "bit[0] + 0x1000") ;break;
1568     }
1569     DBG(DBG_FNC, "\n");
1570     DBG(DBG_FNC, "         bit[4..5] = ? : 0x%02x\n", (iValue >> 4) & 3);
1571     DBG(DBG_FNC, "         bit[6]    = use gamma tables? : 0x%02x\n", (iValue >> 6) & 1);
1572     DBG(DBG_FNC, "         bit[7]    = ? : 0x%02x\n", (iValue >> 7) & 1);
1573
1574     dbg_buffer(DBG_FNC, "\n0x01d1", &buffer[0x1d1], 0x430, 0x1d1);
1575
1576     DBG(DBG_FNC, "----------------------------------------------------\n\n");
1577   */
1578  /*exit(0); */
1579}
1580#endif
1581