📄 autofunc.lst
字号:
313 1 // horizotal position
314 1 wPosBff = msAutoGetPosition(BK0_D0_AOHST_L, ucVSyncTime); // auto horizontal start position detected r
-esult
315 1 if (wPosBff > StandardModeWidth ) // check overflow
316 1 {
317 2 msWriteByte( BK0_00_REGBK, ucBank );
318 2 return FALSE;
319 2 }
320 1 #if 0 // todo: test!!
wPosBff -= 1; // 20051101 Antony patch for Auto-H.Position
#endif
323 1 g_ModeSetting.HStart= wPosBff;
324 1
325 1 msWriteWord(BK0_08_SPRHST_H, wPosBff);
326 1 // g_ModeSetting.DefaultHStart = wPosBff;
327 1
328 1 // vertical positoin
329 1 wPosBff = msAutoGetPosition(BK0_CE_AOVST_L, ucVSyncTime); // auto vertical start position detected res
-ult
330 1 if (wPosBff >StandardModeHeight) // check overflow
331 1 {
332 2 msWriteByte( BK0_00_REGBK, ucBank );
333 2 return FALSE;
334 2 }
335 1 g_ModeSetting.VStart= wPosBff;
336 1
337 1 if( StandardModeHeight == 350 ) // if IBM VGA 640x350 then use 640x400 resolution and move to middle o
-f screen
338 1 wPosBff -= ((400-350)/2);
339 1
340 1 msWriteWord(BK0_06_SPRVST_H, wPosBff);
341 1
342 1 msWriteByte( BK0_00_REGBK, ucBank );
343 1 return TRUE;
344 1 }
345
346 ///////////////////////////////////////////////////////////////////////////////
347 // <Function>: msAdcGetTransPos
348 //
349 // <Description>: Get trans-position.
350 //
351 // <Returns> : Trans-phase.
352 //
353 // <Parameter>: - <Flow> - <Description>
354 //-----------------------------------------------------------------------------
355 // ucVSyncTime - In - VSync time
356 ///////////////////////////////////////////////////////////////////////////////
357 BYTE msAutoGetTransPos(BYTE ucVSyncTime)
358 {
359 1 WORD wComparePos; // compare start position
360 1 BYTE ucAdjustPhase = 0x20, ucPhaseDelta = 0x20; // phase data buffer
361 1
C51 COMPILER V8.18 AUTOFUNC 09/29/2009 23:58:04 PAGE 7
362 1 msAdjustAdcPhase(0x00); // intialize
363 1 wComparePos = msAutoGetPosition(BK0_D0_AOHST_L, ucVSyncTime);
364 1 while (1)
365 1 {
366 2 msAdjustAdcPhase(ucAdjustPhase); // set phase
367 2
368 2 ucPhaseDelta /= 2; // next step
369 2 if (ucPhaseDelta == 0x00) // check end
370 2 break;
371 2
372 2 if (msAutoGetPosition(BK0_D0_AOHST_L, ucVSyncTime) == wComparePos) // find critical phase
373 2 ucAdjustPhase += ucPhaseDelta; // right shift
374 2 else
375 2 ucAdjustPhase -= ucPhaseDelta; // left shift
376 2
377 2 if (msAutoCheckSyncLoss()) // check no signal
378 2 return -1;
379 2
380 2 } // while
381 1
382 1 return (ucAdjustPhase);
383 1 }
384
385 ///////////////////////////////////////////////////////////////////////////////
386 // <Function>: msAutoGetActualWidth
387 //
388 // <Description>: Get actual image width.
389 //
390 // <Returns> : Actual width.
391 //
392 // <Parameter>: - <Flow> - <Description>
393 //-----------------------------------------------------------------------------
394 // ucVSyncTime - In - VSync time
395 ///////////////////////////////////////////////////////////////////////////////
396 WORD msAutoGetActualWidth(BYTE ucVSyncTime)
397 {
398 1 WORD wHStart; // actual horizontal start
399 1
400 1 msAdjustAdcPhase(0x00); // initialize phase value
401 1 wHStart = msAutoGetPosition(BK0_D0_AOHST_L, ucVSyncTime); // horizontal start position
402 1 msAutoGetTransPos(ucVSyncTime); // seek critical phase
403 1
404 1 return ((msAutoGetPosition(BK0_D4_AOHEND_L, ucVSyncTime) - wHStart) + 1); // actual image width
405 1 }
406
407 ///////////////////////////////////////////////////////////////////////////////
408 // <Function>: msAutoTuneHTotal
409 //
410 // <Description>: auto-tune horizontal total.
411 //
412 // <Returns> : Success status.
413 //
414 // <Parameter>: - <Flow> - <Description>
415 //-----------------------------------------------------------------------------
416 // ucVSyncTime - In - VSync time
417 ///////////////////////////////////////////////////////////////////////////////
418 BOOL msAutoTuneHTotal(BYTE ucVSyncTime)
419 {
420 1 WORD wActualWidth; // actual width
421 1 WORD wStdWidth; // standard width
422 1 WORD wHTotalBff; // horizontal total buffer
423 1 BOOL bResult = FALSE;
C51 COMPILER V8.18 AUTOFUNC 09/29/2009 23:58:04 PAGE 8
424 1
425 1 msAdjustAdcPhase(0x00); // initialize phase value
426 1 wActualWidth = msAutoGetPosition(BK0_D4_AOHEND_L, ucVSyncTime) - msAutoGetPosition(BK0_D0_AOHST_L, ucV
-SyncTime);
427 1 // get standard display width
428 1 wStdWidth = StandardModeWidth;
429 1 if (abs(wActualWidth - wStdWidth) > (wStdWidth / 4)) // check actual width over standard
430 1 {
431 2 #ifdef AUTO_DEBUG_EN
putstr("\r\nmsAutoTuneHTotal failed-1");
#endif
434 2 return FALSE;
435 2 }
436 1
437 1 wHTotalBff = g_ModeSetting.HTotal; // intialize horizontal total buffer
438 1 if (abs(wActualWidth - wStdWidth) > 1) // check width difference
439 1 {
440 2 // calculate horizontal total
441 2 wHTotalBff = ((DWORD)g_ModeSetting.HTotal* wStdWidth) / wActualWidth;
442 2 // check over range of adjusting
443 2 if (abs(wHTotalBff - StandardModeHTotal > ADJUST_CLOCK_RANGE))
444 2 {
445 3 #ifdef AUTO_DEBUG_EN
putstr("\r\nmsAutoTuneHTotal failed-2");
printf("\r\nwHTotalBff=%d", wHTotalBff);
printf("\r\nwStdWidth=%d", wStdWidth);
printf("\r\nwActualWidth=%d", wActualWidth);
#endif
451 3 return FALSE;
452 3 }
453 2
454 2 msAdjustAdcClock(wHTotalBff); // set clock
455 2 }
456 1
457 1 // check width
458 1 wActualWidth = msAutoGetActualWidth(ucVSyncTime);
459 1 if (wActualWidth != wStdWidth) // match width
460 1 {
461 2 // adjust horizontal total
462 2 wHTotalBff = wHTotalBff + (wStdWidth - wActualWidth);
463 2 msAdjustAdcClock(wHTotalBff);
464 2
465 2 wActualWidth = msAutoGetActualWidth(ucVSyncTime);
466 2 // adjust horizontal total again
467 2 wHTotalBff = wHTotalBff + (wStdWidth - wActualWidth);
468 2 }
469 1
470 1 if (wHTotalBff & 0x01) // match width and check odd
471 1 {
472 2 msAdjustAdcClock(wHTotalBff - 1); // find decrement
473 2 wActualWidth = msAutoGetActualWidth(ucVSyncTime);
474 2 if (wActualWidth == wStdWidth) // match width
475 2 wHTotalBff--;
476 2 else
477 2 {
478 3 msAdjustAdcClock(wHTotalBff + 1); // find increment
479 3 wActualWidth = msAutoGetActualWidth(ucVSyncTime);
480 3 if (wActualWidth == wStdWidth) // match width
481 3 wHTotalBff++;
482 3 }
483 2 }
484 1
C51 COMPILER V8.18 AUTOFUNC 09/29/2009 23:58:04 PAGE 9
485 1 #ifdef AUTO_DEBUG_EN
printf("\r\nH. Total = %x", wHTotalBff);
printf("(%d)", wHTotalBff);
#endif
489 1
490 1 // check horizontal total range
491 1 if (abs(wHTotalBff - (StandardModeHTotal)) < ADJUST_CLOCK_RANGE)
492 1 {
493 2 g_ModeSetting.HTotal= wHTotalBff;
494 2 bResult = TRUE;
495 2 #ifdef AUTO_DEBUG_EN
putstr("\r\nmsAutoTuneHTotal success");
#endif
498 2 }
499 1
500 1 msAdjustAdcClock(g_ModeSetting.HTotal); // setting ADC clock
501 1 msAdjustAdcPhase(g_ModeSetting.Phase); // setting ADC phase
502 1
503 1 return bResult;
504 1 }
505
506 ///////////////////////////////////////////////////////////////////////////////
507 // <Function>: msAutoGetPhaseVal
508 //
509 // <Description>: get auto phase value.
510 //
511 // <Returns> : auto phase value.
512 ///////////////////////////////////////////////////////////////////////////////
513 DWORD msAutoGetPhaseVal(void)
514 {
515 1 DWordType dwPhaseValBff; // double word buffer
516 1 BYTE ucBank;
517 1
518 1 ucBank = msReadByte( BK0_00_REGBK);
519 1
520 1 msWriteByte( BK0_00_REGBK, REG_BANK_SCALER );
521 1
522 1 msAutoWaitStatusReady(BK0_DB_ATPCTRL, _BIT1);
523 1 dwPhaseValBff.separate._byte0 = msReadByte(BK0_DC_ATPV1);
524 1 dwPhaseValBff.separate._byte1 = msReadByte(BK0_DD_ATPV2);
525 1 dwPhaseValBff.separate._byte2 = msReadByte(BK0_DE_ATPV3);
526 1 dwPhaseValBff.separate._byte3 = msReadByte(BK0_DF_ATPV4);
527 1
528 1 msWriteByte( BK0_00_REGBK, ucBank );
529 1
530 1 return dwPhaseValBff.total;
531 1 }
532
533 ///////////////////////////////////////////////////////////////////////////////
534 // <Function>: msAutoTunePhase
535 //
536 // <Description>: auto-tune phase.
537 //
538 // <Returns> : Success status.
539 //
540 // <Parameter>: - <Flow> - <Description>
541 //-----------------------------------------------------------------------------
542 // ucVSyncTime - In - VSync time
543 ///////////////////////////////////////////////////////////////////////////////
544 #define AUTO_PHASE_STEP 4
545
546 BOOL msAutoTunePhase(BYTE ucVSyncTime)
C51 COMPILER V8.18 AUTOFUNC 09/29/2009 23:58:04 PAGE 10
547 {
548 1 BYTE ucIndex; // loop index
549 1
550 1 DWORD dwAutoPhaseVal; // auto phase value result
551 1 #if AUTO_PHASE_METHOD
{
DWORD dwMiniPhaseVal = -1; // minimum phase value
BYTE ucWorstPhase1, ucWorstPhase2;
ucWorstPhase1 = 0x00; // initizlize
for (ucIndex=ucWorstPhase1; ucIndex<=0x3f; ucIndex+=AUTO_PHASE_STEP)
{
msAdjustAdcPhase(ucIndex);
Delay1ms_WatchDog(ucVSyncTime); // delay 1 frame
dwAutoPhaseVal = msAutoGetPhaseVal();
if (dwAutoPhaseVal < dwMiniPhaseVal) // check minimum
{
ucWorstPhase1 = ucIndex; // refresh best phase
dwMiniPhaseVal = dwAutoPhaseVal; // refresh minimum value
}
if (msAutoCheckSyncLoss()) // check no signal
return FALSE;
} // for
// initizlize
ucWorstPhase2= (ucWorstPhase1 - AUTO_PHASE_STEP + 1) & 0x3f;
ucWorstPhase1 = (ucWorstPhase1 + AUTO_PHASE_STEP) & 0x3f;
dwMiniPhaseVal = -1;
for (ucIndex=ucWorstPhase2; ucIndex!=ucWorstPhase1; ucIndex=((ucIndex+1)&0x3f))
{
msAdjustAdcPhase(ucIndex);
Delay1ms_WatchDog(ucVSyncTime); // delay 1 frame
dwAutoPhaseVal = msAutoGetPhaseVal();
if (dwAutoPhaseVal < dwMiniPhaseVal) // check minimum
{
ucWorstPhase2 = ucIndex; // refresh best phase
dwMiniPhaseVal = dwAutoPhaseVal; // refresh minimum value
}
if (msAutoCheckSyncLoss()) // check no signal
return FALSE;
} // for
g_ModeSetting.Phase = (ucWorstPhase2 + (0x3f / 2)) & 0x3f;
}
#else
596 1 {
597 2 DWORD dwMaxPhaseVal = 0; // maximum phase value
598 2 BYTE ucBestPhase1, ucBestPhase2;
599 2
600 2 ucBestPhase1 = 0x00; // initizlize
601 2 for (ucIndex=ucBestPhase1; ucIndex<=0x3f; ucIndex+=AUTO_PHASE_STEP)
602 2 {
603 3 msAdjustAdcPhase(ucIndex);
604 3 Delay1ms_WatchDog(ucVSyncTime); // delay 1 frame
605 3 dwAutoPhaseVal = msAutoGetPhaseVal();
606 3
607 3 if (dwAutoPhaseVal > dwMaxPhaseVal) // check maximum
608 3 {
C51 COMPILER V8.18 AUTOFUNC 09/29/2009 23:58:04 PAGE 11
609 4 ucBestPhase1 = ucIndex; // refresh best phase
610 4 dwMaxPhaseVal = dwAutoPhaseVal; // refresh maximum value
611 4 }
612 3
613 3 if (msAutoCheckSyncLoss()) // check no signal
614 3 return FALSE;
615 3 } // for
616 2
617 2 // initizlize
618 2 ucBestPhase2= (ucBestPhase1 - AUTO_PHASE_STEP + 1) & 0x3f;
619 2 ucBestPhase1 = (ucBestPhase1 + AUTO_PHASE_STEP) & 0x3f;
620 2 dwMaxPhaseVal = 0;
621 2 for (ucIndex=ucBestPhase2; ucIndex!=ucBestPhase1; ucIndex=((ucIndex+1)&0x3f))
622 2 {
623 3 msAdjustAdcPhase(ucIndex);
624 3 Delay1ms_WatchDog(ucVSyncTime); // delay 1 frame
625 3 dwAutoPhaseVal = msAutoGetPhaseVal();
626 3
627 3 if (dwAutoPhaseVal > dwMaxPhaseVal) // check maximum
628 3 {
629 4 ucBestPhase2 = ucIndex; // refresh best phase
630 4 dwMaxPhaseVal = dwAutoPhaseVal; // refresh maximum value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -