2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #define _WIN32_WINNT 0x501
30 #include "vompreswin.h"
34 #include "remotewin.h"
40 #include "windowsosd.h"
42 #include "osdwinpixel.h"
44 #include "osdwinvector.h"
49 #include "vsleeptimer.h"
51 void sighandler(int signalReceived);
52 void shutdown(int code);
54 // Global variables --------------------------------------------------------------------------------------------------
67 Sleeptimer* sleeptimer;
70 bool wnd_fullscreen=false;
71 bool wnd_topmost=false;
72 RECT wnd_fs_rect={20,20,768+20,576+20};
73 RECT wnd_fs_rect_client={0,0,768,576};
74 //OSVERSIONINFO windows_ver; //attempt to distigsh windows versions
80 typedef UINT (WINAPI *GETRAWINPUTDATAFNC) (HRAWINPUT,UINT,LPVOID,PUINT,UINT);
81 typedef UINT (WINAPI *REGISTERRAWINPUTDEVICEFNC) (PCRAWINPUTDEVICE,UINT,UINT);
83 GETRAWINPUTDATAFNC dynGetRawInputData=NULL;
84 REGISTERRAWINPUTDEVICEFNC dynRegisterRawInputDevices=NULL;
89 void MILLISLEEP(ULONG a)
96 int getClockRealTime(struct timespec *tp){
100 GetSystemTime(&systime);
101 SystemTimeToFileTime(&systime, (FILETIME*)&filetime);
102 tp->tv_sec = (filetime - WINDOWS_TIME_BASE_OFFSET) / (10 * 1000 * 1000);
103 tp->tv_nsec = ((filetime - WINDOWS_TIME_BASE_OFFSET) % (10 * 1000 * 1000)) * 100;
107 DWORD WINAPI commandthreadStart(void *arg)
113 void LoadRemoteFunctions() {
114 user32dll=LoadLibrary("user32.dll");
115 if (user32dll!=NULL) {
116 dynGetRawInputData=(GETRAWINPUTDATAFNC)GetProcAddress(user32dll,"GetRawInputData");
117 if (dynGetRawInputData!=NULL) {
118 dynRegisterRawInputDevices=(REGISTERRAWINPUTDEVICEFNC)GetProcAddress(user32dll,"RegisterRawInputDevices");
119 if (dynRegisterRawInputDevices!=NULL) {
126 bool InitApp(HINSTANCE hinst,int cmdshow);
128 HWND win_main;//global window handle
129 HWND win;//global child window handle
132 #define ERROR_MSG(str) MessageBox(win_main,str,"Error!",MB_OK|MB_ICONWARNING)
133 INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmdshow)
136 //On Windows we have to init a window, we use DXUT
137 LoadRemoteFunctions();
138 if (!InitApp(hinst,cmdshow)) return false;
139 //Starting Network support
141 int result = WSAStartup(MAKEWORD(2,2),&wsadat);
142 if (result!=NO_ERROR) {
143 ERROR_MSG("Initialising WinSocked: Error at WSAStartup()\n");
147 result= CoInitializeEx(NULL,COINIT_MULTITHREADED );//Initialize COM for DirectShow
149 ERROR_MSG("Initialising COM: Error at Coinitialize()\n");
156 // Init global vars ------------------------------------------------------------------------------------------------
159 remote = new RemoteWin();
161 timers = new Timers();
162 osd = new Osd_TYPE();
164 video = new VideoWin();
165 audio = new AudioWin();
166 boxstack = new BoxStack();
167 command = new Command();
169 sleeptimer = new Sleeptimer();
171 if (!logger || !remote || !led || !osd || !video || !audio || !boxstack || !command || !sleeptimer)
173 ERROR_MSG("Could not create objects. Memory problems?\n");
179 // Get logging module started --------------------------------------------------------------------------------------
181 if (!logger->init(Log::DEBUG, "vompwin.log", true))
183 ERROR_MSG("Could not initialise log object. Aborting.\n");
189 logger->log("Core", Log::INFO, "Starting up...");
193 // Init modules ----------------------------------------------------------------------------------------------------
196 success = remote->init("/dev/rawir");
199 logger->log("Core", Log::INFO, "Remote module initialised");
203 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
209 success = led->init(0);
212 logger->log("Core", Log::INFO, "LED module initialised");
216 logger->log("Core", Log::EMERG, "LED module failed to initialise");
222 success = timers->init();
225 logger->log("Core", Log::INFO, "Timers module initialised");
229 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
235 UCHAR videoFormat = Video::PAL; // PALNTSC FIXME.
237 success = video->init(videoFormat);
240 logger->log("Core", Log::INFO, "Video module initialised");
244 logger->log("Core", Log::EMERG, "Video module failed to initialise");
250 dynamic_cast<WindowsOsd*>(osd)->setWindow(win);
251 success = osd->init();
254 logger->log("Core", Log::INFO, "OSD module initialised");
258 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
263 video->setDefaultAspect();
265 success = audio->init(Audio::MPEG2_PES);
268 logger->log("Core", Log::INFO, "Audio module initialised");
272 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
278 success = vdr->init();
281 logger->log("Core", Log::INFO, "VDR module initialised");
285 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
291 success = boxstack->init();
294 logger->log("Core", Log::INFO, "BoxStack module initialised");
298 logger->log("Core", Log::EMERG, "BoxStack module failed to initialise");
304 success = command->init();
307 logger->log("Core", Log::INFO, "Command module initialised");
311 logger->log("Core", Log::EMERG, "Command module failed to initialise");
317 // Other init ------------------------------------------------------------------------------------------------------
319 logger->log("Core", Log::NOTICE, "Startup successful");
321 // Run main loop ---------------------------------------------------------------------------------------------------
323 // Ok, all major device components and other bits are loaded and ready
324 lastmousemove=timeGetTime();
326 HANDLE commandthread;
327 commandthread= CreateThread(NULL, 0, commandthreadStart, NULL,0,
330 message.message=WM_NULL;
332 while(run && WaitForSingleObject(commandthread,0)==WAIT_TIMEOUT) {
333 if (PeekMessage(&message, NULL, 0,0,PM_REMOVE)!=0) {
334 if (TranslateAccelerator(win_main,acc,&message)==NULL) {
335 TranslateMessage(&message);
336 DispatchMessage(&message);
337 switch (message.message) {
339 run=false; //TODO post exit to command Messages
343 //Render, moved to OSD !
345 //((OsdWin*)osd)->Render();
348 // When that returns quit ------------------------------------------------------------------------------------------
349 WaitForSingleObject(commandthread,INFINITE);
352 if (user32dll) FreeModule(user32dll);
357 bool TranslateMousePosition(POINT *pos) {
360 ScreenToClient(win,pos);
361 GetClientRect(win,&clientrect);
362 if (!PtInRect(&clientrect,*pos)) return false;//Don't pass it further
363 pos->x=((double)pos->x)/((double) (clientrect.right-clientrect.left))
364 *((double)Video::getInstance()->getScreenWidth());
365 pos->y=((double)pos->y)/((double) (clientrect.bottom-clientrect.top))
366 *((double)Video::getInstance()->getScreenHeight());
373 void CalculateWindowSize(RECT * size,ULONG size_mode) {
376 DWORD adjheight,adjwidth;
377 if (!wnd_fullscreen) {
378 DWORD flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU
379 |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX;
380 RECT wnted={50,50,150,150};
381 AdjustWindowRect(&wnted,flags ,false);
382 adjwidth=-wnted.left+wnted.right-100;
383 adjheight=-wnted.top+wnted.bottom-100;
385 adjwidth=adjheight=0;
387 width=size->right-size->left-adjwidth;
388 height=size->bottom-size->top-adjheight;
389 UCHAR mode=Video::PAL;
390 UCHAR aspect=Video::ASPECT4X3;
391 UCHAR tvsize=Video::ASPECT4X3;
393 mode=video->getMode();
394 aspect=((VideoWin*)video)->getAspectRatio();
395 tvsize=((VideoWin*)video)->getPseudoTVsize();
398 double aspectrt=4./3.;
399 if (tvsize==Video::ASPECT16X9) {
400 if (aspect==Video::ASPECT16X9) {
401 aspectrt=4./3.; //looks strange, but it is a 16:9 tv
402 } else if (aspect==Video::ASPECT4X3) {
403 aspectrt=4./3./(16./9.)*(4./3.); //I hope this is correct
405 } else if (tvsize==Video::ASPECT4X3) {
406 if (aspect==Video::ASPECT16X9) {
407 if (mode!=Video::NORMAL) {
412 } else if (aspect==Video::ASPECT4X3) {
416 if (!wnd_fullscreen) {
419 case WMSZ_BOTTOMRIGHT:
422 width=(ULONG)(((double)height)*aspectrt);
423 size->right=size->left+width+adjwidth;
425 case WMSZ_BOTTOMLEFT:
427 width=(ULONG)(((double)height)*aspectrt);
428 size->left=size->right-width-adjwidth;
432 height=(ULONG)(((double)width)/aspectrt);
433 size->bottom=size->top+height+adjheight;
436 MoveWindow(win,0,0,width,height,TRUE);
438 RECT newrect={0,0,width,height};
440 if ((ULONG)(((double)height)*aspectrt)>width) {
441 newlength=(ULONG)(((double)width)/aspectrt);
442 newrect.top+=(height-newlength)/2;
443 newrect.bottom-=(height-newlength);
445 newlength=(ULONG)(((double)height)*aspectrt);
446 newrect.left+=(width-newlength)/2;
447 newrect.right-=(width-newlength);
449 MoveWindow(win,newrect.left,newrect.top,newrect.right,newrect.bottom,TRUE);
454 void AdjustWindow() {
455 if (!wnd_fullscreen) {
457 GetWindowRect(win_main,&winrect);
458 CalculateWindowSize(&winrect,WMSZ_BOTTOM);
459 MoveWindow(win_main,winrect.left,
460 winrect.top,winrect.right-winrect.left,winrect.bottom-winrect.top,true);
463 GetWindowRect(win_main,&winrect);
464 CalculateWindowSize(&winrect,WMSZ_BOTTOM);
469 void ToggleFullscreen() {
470 if (wnd_fullscreen) {
471 wnd_fullscreen=false;
472 SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU
473 |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX);
474 SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
476 SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,wnd_fs_rect.left,wnd_fs_rect.top,
477 wnd_fs_rect.right-wnd_fs_rect.left,
478 wnd_fs_rect.bottom-wnd_fs_rect.top,
479 SWP_DRAWFRAME | SWP_FRAMECHANGED);
480 MoveWindow(win,wnd_fs_rect_client.left,wnd_fs_rect_client.top,
481 wnd_fs_rect_client.right-wnd_fs_rect_client.left,
482 wnd_fs_rect_client.bottom-wnd_fs_rect_client.top,TRUE);
485 GetWindowRect(win_main,&wnd_fs_rect);
486 GetWindowRect(win,&wnd_fs_rect_client);
487 SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP );
488 SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
489 HMONITOR monitor=MonitorFromWindow(win_main,MONITOR_DEFAULTTONEAREST);
491 moninfo.cbSize=sizeof(moninfo);
493 if (!GetMonitorInfo(monitor,&moninfo)) return ;
494 SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,moninfo.rcMonitor.left,moninfo.rcMonitor.top,
495 moninfo.rcMonitor.right,moninfo.rcMonitor.bottom,SWP_FRAMECHANGED);
504 void ToggleTopmost() {
505 wnd_topmost=!wnd_topmost;
506 SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_NOTOPMOST,0,0,
507 0,0,SWP_NOMOVE | SWP_NOSIZE);
510 void CursorUpdate() {
512 GetCursorPos(&cursorpos);
514 asswind=WindowFromPoint(cursorpos);
515 if (asswind!=win_main && asswind!=win) {
516 return ; //not our responsibility
518 if ((timeGetTime()-lastmousemove)<4000 || cmenu) {
519 SetCursor(LoadCursor(NULL,IDC_ARROW));
525 bool ContextMenu(HWND wind,int x,int y) {
528 ScreenToClient(wind,&p);
529 GetClientRect(wind,&clientrect);
530 if (!PtInRect(&clientrect,p)) return false;
531 ClientToScreen(wind,&p);
534 menu=LoadMenu(hinstance,MAKEINTRESOURCE(VOMPMENU));
535 popup=GetSubMenu(menu,0);
536 if (wnd_fullscreen) {
537 CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_CHECKED);
539 CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_UNCHECKED);
542 CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_CHECKED);
544 CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_UNCHECKED);
547 TrackPopupMenu(popup,TPM_RIGHTBUTTON|TPM_LEFTALIGN,x,y,0,wind, NULL);
555 LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam)
561 logger->log("Core", Log::NOTICE, "Window closed, shutting down...");
563 ((RemoteWin*)Remote::getInstance())->SendPower();
567 CalculateWindowSize((RECT*) lparam,wparam);
571 int width = LOWORD(lparam);
572 int height = HIWORD(lparam);
574 if (wparam == SIZE_MAXIMIZED) {
577 } /*else if (wparam == SIZE_MINIMIZED) {
587 if (GetUpdateRect(wind, &r, FALSE)) {
588 BeginPaint(wind, &ps);
589 //Call Painting Mechanism
594 if (((RemoteWin*)remote)->ReceiveButtonVK(wparam)) {
595 return 0L; //We process that Key
597 return DefWindowProc(wind, msg, wparam, lparam);
602 if (((RemoteWin*)remote)->ReceiveButtonCH(wparam)) {
603 return 0L; //We process that Key
605 return DefWindowProc(wind, msg, wparam, lparam);
610 if (((RemoteWin*)remote)->ReceiveButtonAP(GET_APPCOMMAND_LPARAM(lparam))){
611 return TRUE; //yes we process that message
613 return DefWindowProc(wind, msg, wparam, lparam);
622 dynGetRawInputData((HRAWINPUT)lparam,RID_INPUT,NULL,&risize,sizeof(RAWINPUTHEADER));
623 lpit=(LPRAWINPUT)malloc(risize);
624 dynGetRawInputData((HRAWINPUT)lparam,RID_INPUT,lpit,&risize,sizeof(RAWINPUTHEADER));
626 if (lpit->header.dwType==RIM_TYPEHID && lpit->data.hid.dwSizeHid>=2) {
627 DWORD button=lpit->data.hid.bRawData[1] | (lpit->data.hid.bRawData[0]<< 8);
628 if (((RemoteWin*)remote)->ReceiveButtonRI(button)){
630 return 0; //yes we process that message
635 return DefWindowProc(wind, msg, wparam, lparam);
640 if (LOWORD(wparam)==VOMP_FULL_SCREEN) {
644 if (LOWORD(wparam)==VOMP_TOPMOST) {
648 if (((RemoteWin*)remote)->ReceiveButtonAP(LOWORD(wparam))){
649 return 0; //yes we process that message
651 return DefWindowProc(wind, msg, wparam, lparam);
656 if (((HANDLE)wparam)==win) {
660 return DefWindowProc(wind, msg, wparam, lparam);
664 if (wparam==SC_MAXIMIZE) {
667 } else if (wparam==SC_SCREENSAVE || wparam==SC_MONITORPOWER) {
670 return DefWindowProc(wind,msg,wparam, lparam);
675 lastmousemove=timeGetTime();
676 SetCursor(LoadCursor(NULL,IDC_ARROW));
677 SetTimer(wind,VOMP_CURSORUPDATE,4500,NULL);
678 POINT mpos={GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam)};
679 ClientToScreen(wind,&mpos);
680 if (TranslateMousePosition(&mpos)) {
681 Message *mousemes=new Message();
682 mousemes->message=Message::MOUSE_MOVE;
684 mousemes->to=BoxStack::getInstance();
685 mousemes->parameter.num=(mpos.x & 0xFFFF)<< 16| (mpos.y & 0xFFFF);
687 //command->postMessageFromOuterSpace(mousemes);
688 command->postMessageIfNotBusy(mousemes);
692 //return DefWindowProc(wind,msg,wparam, lparam);
696 if (wparam==VOMP_CURSORUPDATE) {
700 return DefWindowProc(wind, msg, wparam, lparam);
704 if (!ContextMenu(wind,GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam))) {
705 return DefWindowProc(wind, msg, wparam, lparam);
710 case WM_LBUTTONDOWN:{
711 POINT mpos={GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam)};
712 ClientToScreen(wind,&mpos);
713 if (TranslateMousePosition(&mpos)) {
714 Message *mousemes=new Message();
715 mousemes->message=Message::MOUSE_LBDOWN;
717 mousemes->to=BoxStack::getInstance();
718 mousemes->parameter.num=(mpos.x & 0xFFFF)<< 16| (mpos.y & 0xFFFF);
720 command->postMessageFromOuterSpace(mousemes);
724 POINT mpos = { GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam) };
725 ClientToScreen(wind, &mpos);
726 if (TranslateMousePosition(&mpos)) {
727 Message *mousemes = new Message();
728 mousemes->message = Message::MOUSE_SCROLL;
729 mousemes->from = NULL;
730 mousemes->to = BoxStack::getInstance();
731 mousemes->parameter.num = (0 & 0xFFFF) << 16 | (GET_WHEEL_DELTA_WPARAM(wparam) &0xFFFF);
732 mousemes->tag = (mpos.x & 0xFFFF) << 16 | (mpos.y & 0xFFFF);
733 command->postMessageFromOuterSpace(mousemes);
738 return DefWindowProc(wind, msg, wparam, lparam);
744 bool InitApp(HINSTANCE hinst,int cmdshow) {
748 wcs.style = CS_HREDRAW | CS_VREDRAW;
749 wcs.lpfnWndProc = WindowProc;
751 wcs.cbWndExtra = sizeof(DWORD);
752 wcs.hInstance = hinst;
755 wcs.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
756 wcs.lpszMenuName = NULL;
757 wcs.lpszClassName = "vomp";
758 acc=LoadAccelerators(hinst,MAKEINTRESOURCE(VOMPACCELERATOR));
759 if (!RegisterClass(&wcs))
761 flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU
762 |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX;
763 RECT wnted={50,50,768+50,576+50};
764 AdjustWindowRect(&wnted,flags ,false);
765 win_main=CreateWindow("vomp","VOMP on Windows",flags, CW_USEDEFAULT,CW_USEDEFAULT,
766 wnted.right-wnted.left,wnted.bottom-wnted.top,NULL,NULL,hinst,NULL);
769 ShowWindow(win_main,SW_SHOWNORMAL);
770 UpdateWindow(win_main);
771 /* in order to handle letterboxing we use a child window */
773 child_wcs.style = CS_HREDRAW | CS_VREDRAW;
774 child_wcs.lpfnWndProc = WindowProc;
775 child_wcs.cbClsExtra = 0;
776 child_wcs.cbWndExtra = sizeof(DWORD);
777 child_wcs.hInstance = hinst;
778 child_wcs.hIcon = NULL;
779 child_wcs.hCursor = NULL;
780 child_wcs.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
781 child_wcs.lpszMenuName = NULL;
782 child_wcs.lpszClassName = "vomp_playback";
783 if (!RegisterClass(&child_wcs))
786 win=CreateWindow("vomp_playback","Vomp Playback Window",WS_VISIBLE | WS_CHILD |WS_CLIPCHILDREN,
787 0,0,768,576,win_main,NULL,hinst,NULL);
790 ShowWindow(win,SW_SHOWNORMAL);
792 if (remotefnc) {//at least windows XP
793 /* We want to support MCE Remote controls*/
794 RAWINPUTDEVICE remote_control_data[4];
795 ZeroMemory(remote_control_data,sizeof(remote_control_data));
796 remote_control_data[0].usUsagePage=0xFFBC;
797 remote_control_data[0].usUsage=0x88;
798 remote_control_data[0].dwFlags=0;
799 remote_control_data[1].usUsagePage=0x0C;
800 remote_control_data[1].usUsage=0x80;
801 remote_control_data[1].dwFlags=0;
802 remote_control_data[2].usUsagePage=0x0C;
803 remote_control_data[2].usUsage=0x01;
804 remote_control_data[2].dwFlags=0;
805 remote_control_data[3].usUsagePage=0x01;
806 remote_control_data[3].usUsage=0x80;
807 remote_control_data[3].dwFlags=0;
808 if (dynRegisterRawInputDevices(remote_control_data,4,sizeof(remote_control_data[0]))!=TRUE) {
809 MessageBox(0,"Registering remote control failed!","Aborting!",0);
821 // -------------------------------------------------------------------------------------------------------------------
823 void shutdown(int code)
827 boxstack->shutdown();
829 logger->log("Core", Log::NOTICE, "BoxStack module shut down");
832 if (command) // shut down command here in case views have posted messages
836 logger->log("Core", Log::NOTICE, "Command module shut down");
843 logger->log("Core", Log::NOTICE, "VDR module shut down");
850 logger->log("Core", Log::NOTICE, "OSD module shut down");
857 logger->log("Core", Log::NOTICE, "Audio module shut down");
864 logger->log("Core", Log::NOTICE, "Video module shut down");
871 logger->log("Core", Log::NOTICE, "Timers module shut down");
878 logger->log("Core", Log::NOTICE, "LED module shut down");
885 logger->log("Core", Log::NOTICE, "Remote module shut down");
890 logger->log("Core", Log::NOTICE, "WOL module shut down");
895 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
902 logger->log("Core", Log::NOTICE, "Sleeptimer module shut down");
908 // -------------------------------------------------------------------------------------------------------------------
910 ULLONG htonll(ULLONG a)
912 return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32)
913 |(ULONG)htonl(((ULONG) (a >> 32))));
916 ULLONG ntohll(ULLONG a)