Ejemplo n.º 1
0
double
__libmcr_mx_log(double x, double *err)
{
	int hx, i, j, n, na;
	double y, p, q, q1, qi, q2, s, f1, f2, u, w, s1, s2, w1, w2, z1,
		z2, t1, t2, g1, g2, t;

	hx = HIGH_WORD(x);
	*err = 0.0;
	na = 0;
	/* filter out exception argument */
/* Redundant exception handling code: see __libmcr_log */
#if 0
	if ((hx + 0x00208000) < 0x00308000) {
		/* subnormal,0,negative,inf,nan,huge */
		i = ((unsigned) (hx << 1)) >> 1;
		if (hx >= 0x7ff00000)
			return (x + x);	/* x is inf/nan */
		if ((i | LOW_WORD(x)) == 0)
			return (-one / (x * x));	/* log(+-0) is -inf */
		if (hx < 0)
			return ((x - x) / zero);	/* log(-#) is NaN */
#endif
		if (hx < 0x00100000) {	/* subnormal */
			x *= two54;
			hx = HIGH_WORD(x);
			na = -54;
		}
/* Redundant exception handling code: see __libmcr_log */
#if 0
	}
Ejemplo n.º 2
0
BOOL Dumbfuzzer::GetRandomIoctlAndBuffer(DWORD &iocode, vector<UCHAR> &output, mt19937 *threadRandomProvider)
{
    BOOL bResult=FALSE;
    INT i=0;
    UINT r;
    DWORD size=0, ioctlIndex;

    r = (*threadRandomProvider)();
    // Pick random ioctl def
    ioctlIndex = LOW_WORD(r)%ioStore.size();
    // Get random size between low and high limits (prevent divide by zero)
    if(ioStore[ioctlIndex].dwUpperSize-ioStore[ioctlIndex].dwLowerSize) {
        size = ioStore[ioctlIndex].dwLowerSize+(HIGH_WORD(r)%(ioStore[ioctlIndex].dwUpperSize-ioStore[ioctlIndex].dwLowerSize));
    }
    output.resize(size);
    if(size>4) {
        for(i=0; i<(INT)(size-sizeof(INT)); i+=sizeof(INT)) {
            *(PUINT)(&(output)[i]) = (*threadRandomProvider)();
        }
    }
    // Last DWORD
    r = (*threadRandomProvider)();
    for(INT j=0; i<(INT)size; i++,j+=8) {
        output[i] = (UCHAR)((r>>j)&0xff);
    }
    // Set code
    iocode = ioStore[ioctlIndex].dwIOCTL;
    bResult = TRUE;
    return bResult;
}
Ejemplo n.º 3
0
Archivo: table.c Proyecto: BAM-X/frotz
/*
 * z_loadw, store a value from a table of words.
 *
 *	zargs[0] = address of table
 *	zargs[1] = index of table entry to store
 *
 */
void z_loadw (void)
{
    zword addr = zargs[0] + 2 * zargs[1];
    zword value;

    LOW_WORD (addr, value)

    store (value);

}/* z_loadw */
Ejemplo n.º 4
0
zword Mem::get_header_extension(int entry) {
	zword addr;
	zword val;

	if (h_extension_table == 0 || entry > hx_table_size)
		return 0;

	addr = h_extension_table + 2 * entry;
	LOW_WORD(addr, val);

	return val;   
}
Ejemplo n.º 5
0
/*
 * z_pop_stack, pop n values off the game or user stack and discard them.
 *
 *	zargs[0] = number of values to discard
 *	zargs[1] = address of user stack (optional)
 *
 */
void z_pop_stack (void)
{
    if (zargc == 2) {		/* it's a user stack */

	zword size;
	zword addr = zargs[1];

	LOW_WORD (addr, size)

	size += zargs[0];
	storew (addr, size);

    } else sp += zargs[0];	/* it's the game stack */

}/* z_pop_stack */
Ejemplo n.º 6
0
/*
 * z_inc, increment a variable.
 *
 * 	zargs[0] = variable to increment
 *
 */
void z_inc (void)
{
    zword value;

    if (zargs[0] == 0)
	(*sp)++;
    else if (zargs[0] < 16)
	(*(fp - zargs[0]))++;
    else {
	zword addr = h_globals + 2 * (zargs[0] - 16);
	LOW_WORD (addr, value)
	value++;
	SET_WORD (addr, value)
    }

}/* z_inc */
Ejemplo n.º 7
0
void logic_state_run(uint32_t msg) {
    switch (HIGH_WORD(msg)) {
    case MSG_SWITCH_BRAKE:
        logic_brake(LOW_BYTE(LOW_WORD(msg)));
        break;
    case MSG_SWITCH_LTURN:
        logic_lturn(LOW_BYTE(LOW_WORD(msg)));
        break;
    case MSG_SWITCH_RTURN:
        logic_rturn(LOW_BYTE(LOW_WORD(msg)));
        break;
    case MSG_SWITCH_HEADLAMP:
        logic_headlamp(LOW_BYTE(LOW_WORD(msg)));
        break;
    case MSG_SWITCH_HIGHBEAM:
        logic_highbeam(LOW_BYTE(LOW_WORD(msg)));
        break;
    case MSG_SWITCH_REVERSE:
        logic_reverse(LOW_BYTE(LOW_WORD(msg)));
        break;
    case MSG_BLINKER_BLINK:
        if (blinker_is_on(LAMP_LTURN)) {
            lamp_toggle(LAMP_LTURN);
            usart_send(PACK_WORDS(MSG_LAMP_LTURN, lamp_is_on(LAMP_LTURN)));
        }
        if (blinker_is_on(LAMP_RTURN)) {
            lamp_toggle(LAMP_RTURN);
            usart_send(PACK_WORDS(MSG_LAMP_RTURN, lamp_is_on(LAMP_RTURN)));
        }
        break;
    case MSG_SWITCH_START:
        if (!LOW_WORD(msg)) {
            blinker_disable();
            lamp_disable();
            usart_send(PACK_WORDS(MSG_STANDBY, 0));
            state_set(LOGIC_STANDBY);
            /* TODO: control display module power */
            /* display_power_set(OFF); */
        }
	break;
    case MSG_DISPLAY_READY:
        logic_sync_lamps();
        break;
    default:
        console_log("event ignored");
    }
}
Ejemplo n.º 8
0
/*
 * z_dec_chk, decrement a variable and branch if now less than value.
 *
 * 	zargs[0] = variable to decrement
 * 	zargs[1] = value to check variable against
 *
 */
void z_dec_chk (void)
{
    zword value;

    if (zargs[0] == 0)
	value = --(*sp);
    else if (zargs[0] < 16)
	value = --(*(fp - zargs[0]));
    else {
	zword addr = h_globals + 2 * (zargs[0] - 16);
	LOW_WORD (addr, value)
	value--;
	SET_WORD (addr, value)
    }

    branch ((short) value < (short) zargs[1]);

}/* z_dec_chk */
Ejemplo n.º 9
0
uint8_t receiveSingleFrame() { 
    
    uint8_t ret = LW232_OK;
    uint8_t idx = 0;
    if (CAN_OK == readMsgBufID(&lw232_CanId, &lw232_PacketLen, lw232_Buffer)) {
        if (lw232_CanId > 0x1FFFFFFF) {
            ret = LW232_ERR; // address if totally wrong
        }
        else if (checkPassFilter(lw232_CanId)) {// do we want to skip some addresses?
            if (isExtendedFrame()) {
                printChar(LW232_TR29);
                printFullByte(HIGH_BYTE(HIGH_WORD(lw232_CanId)));
                printFullByte(LOW_BYTE(HIGH_WORD(lw232_CanId)));
                printFullByte(HIGH_BYTE(LOW_WORD(lw232_CanId)));
                printFullByte(LOW_BYTE(LOW_WORD(lw232_CanId)));
            }
            else {
                printChar(LW232_TR11);
                printNibble(HIGH_BYTE(LOW_WORD(lw232_CanId)));
                printFullByte(LOW_BYTE(LOW_WORD(lw232_CanId)));
            }
            //write data len
            printNibble(lw232_PacketLen);
            //write data
            for (idx = 0; idx < lw232_PacketLen; idx++) {
                printFullByte(lw232_Buffer[idx]);
            }
            //write timestamp if needed
            if (lw232_TimeStamp != LW232_TIMESTAMP_OFF) {
                uint32_t time = 0; //millis();
                if (lw232_TimeStamp == LW232_TIMESTAMP_ON_NORMAL) { 
                    // standard LAWICEL protocol. two bytes.
                    time %= 60000;  
                } else {
                    // non standard protocol - 4 bytes timestamp
                    printFullByte(HIGH_BYTE(HIGH_WORD(time)));
                    printFullByte(LOW_BYTE(HIGH_WORD(time)));
                }
                printFullByte(HIGH_BYTE(LOW_WORD(time)));
                printFullByte(LOW_BYTE(LOW_WORD(time)));
            }
        }
    }
    else {
        ret = LW232_ERR;
    }
    return ret;
}
Ejemplo n.º 10
0
void logic_state_standby(uint32_t msg) {
    switch (HIGH_WORD(msg)) {
    case MSG_SWITCH_START:
        if (LOW_WORD(msg)) {
            /* TODO: control display module power */
            /* display_power_set(ON); */
            usart_send(PACK_WORDS(MSG_DISPLAY_RUN, 0));
            logic_sync_lamps();
            state_set(LOGIC_RUN);
        }
	break;
    case MSG_DISPLAY_READY:
        /* The display was powered on but we're in standby mode, presumably */
        /* because the key-switch is off. This is not a normal situation if */
        /* power to the display is controlled by the main module. */
        usart_send(PACK_WORDS(MSG_DISPLAY_RUN, 0));
        break;
    default:
        console_log("event ignored");
    }
}
Ejemplo n.º 11
0
INT8U Can232::receiveSingleFrame() {
    INT8U ret = LW232_OK;
    INT8U idx = 0;
    if (CAN_OK == readMsgBufID(&lw232CanId, &lw232PacketLen, lw232Buffer)) {
        if (lw232CanId > 0x1FFFFFFF) {
            ret = LW232_ERR; // address if totally wrong
        }
        else if (checkPassFilter(lw232CanId)) {// do we want to skip some addresses?
            if (isExtendedFrame()) {
                Serial.print(LW232_TR29);
                HexHelper::printFullByte(HIGH_BYTE(HIGH_WORD(lw232CanId)));
                HexHelper::printFullByte(LOW_BYTE(HIGH_WORD(lw232CanId)));
                HexHelper::printFullByte(HIGH_BYTE(LOW_WORD(lw232CanId)));
                HexHelper::printFullByte(LOW_BYTE(LOW_WORD(lw232CanId)));
            }
            else {
                Serial.print(LW232_TR11);
                HexHelper::printNibble(HIGH_BYTE(LOW_WORD(lw232CanId)));
                HexHelper::printFullByte(LOW_BYTE(LOW_WORD(lw232CanId)));
            }
            //write data len
            HexHelper::printNibble(lw232PacketLen);
            //write data
            for (idx = 0; idx < lw232PacketLen; idx++) {
                HexHelper::printFullByte(lw232Buffer[idx]);
            }
            //write timestamp if needed
            if (lw232TimeStamp != LW232_TIMESTAMP_OFF) {
                INT32U time = millis();
                if (lw232TimeStamp == LW232_TIMESTAMP_ON_NORMAL) { 
                    // standard LAWICEL protocol. two bytes.
                    time %= 60000;  
                } else {
                    // non standard protocol - 4 bytes timestamp
                    HexHelper::printFullByte(HIGH_BYTE(HIGH_WORD(time)));
                    HexHelper::printFullByte(LOW_BYTE(HIGH_WORD(time)));
                }
                HexHelper::printFullByte(HIGH_BYTE(LOW_WORD(time)));
                HexHelper::printFullByte(LOW_BYTE(LOW_WORD(time)));
            }
        }
    }
    else {
        ret = LW232_ERR;
    }
    return ret;
}
Ejemplo n.º 12
0
BOOL Dumbfuzzer::GetRandomIoctlAndBuffer(DWORD &iocode, vector<UCHAR> &output, mt19937 *threadRandomProvider)
{
    BOOL bResult=FALSE;
    INT i=0;
    UINT r;
    DWORD size=0, ioctlIndex;

    r = (*threadRandomProvider)();
    // Pick random ioctl def
    ioctlIndex = LOW_WORD(r)%ioStore.size();
    // Get random size between low and high limits (prevent divide by zero)
    if(ioStore[ioctlIndex].dwUpperSize-ioStore[ioctlIndex].dwLowerSize) {
        size = ioStore[ioctlIndex].dwLowerSize+(HIGH_WORD(r)%(ioStore[ioctlIndex].dwUpperSize-ioStore[ioctlIndex].dwLowerSize));
    }
    // If the sizes are equal, take the upper size
    else if(ioStore[ioctlIndex].dwUpperSize == ioStore[ioctlIndex].dwLowerSize) {
        size = ioStore[ioctlIndex].dwUpperSize;
    }
    output.resize(size);
    if(size>4) {
        for(i=0; i<(INT)(size-sizeof(INT)); i+=sizeof(INT)) {
            *(PUINT)(&(output)[i]) = (*threadRandomProvider)();
        }
    }
    // Last DWORD
    r = (*threadRandomProvider)();
    for(INT j=0; i<(INT)size; i++,j+=8) {
        output[i] = (UCHAR)((r>>j)&0xff);
    }
    // Every once in awhile, shove the size in the first DWORD of buffer
    if (!(r % SHOVE_LENGTH_FREQ) && size > sizeof(DWORD)) {
        *(PDWORD)(&(output)[0]) = size;
    }
    // Set code
    iocode = ioStore[ioctlIndex].dwIOCTL;
    bResult = TRUE;
    return bResult;
}
Ejemplo n.º 13
0
void memory_new_line (void)
{
    zword size;
    zword addr;

    redirect[depth].total += redirect[depth].width;
    redirect[depth].width = 0;

    addr = redirect[depth].table;

    LOW_WORD (addr, size)
    addr += 2;

    if (redirect[depth].xsize != 0xffff) {

	redirect[depth].table = addr + size;
	size = 0;

    } else storeb ((zword) (addr + (size++)), 13);

    storew (redirect[depth].table, size);

}/* memory_new_line */
Ejemplo n.º 14
0
//....Modeless Dialog Box procedure.........................
DLGFN DialogProc (HWND hdlg, UINT msg, UINT wParam,LONG lParam)
{
  int ret;
  TDialog *This = (TDialog *) GetWindowLong(hdlg,DWL_USER);

  switch (msg)
  {
     case WM_INITDIALOG:
        //..... 'This' pointer passed as param from CreateDialogParam()
         SetWindowLong(hdlg,DWL_USER,lParam);
         This = (TDialog *)lParam;
         if (This->modeless()) hModeless = hdlg;
         This->set(hdlg);
         return This->init();

     case WM_COMMAND:
        switch(LOW_WORD(wParam)) {
         case IDOK:
             ret = This->finis();
             if (! ret) return FALSE;  // no, we're not finished yet!
         case IDCANCEL:
             if (This->modeless()) SendMessage(hdlg,WM_CLOSE,0,0L);
                                  else EndDialog(hdlg,wParam==IDOK);
         break;
         default:
             This->command(wParam);
         break;
        }
        return TRUE;

     case WM_CLOSE:
         DestroyWindow(hdlg);
         hModeless = 0;
         break;
  }
  return FALSE;  // we did not process the message...
}
Ejemplo n.º 15
0
void memory_word (const zword *s)
{
    zword size;
    zword addr;
    zword c;

    if (h_version == V6) {

	int width = os_string_width (s);

	if (redirect[depth].xsize != 0xffff)

	    if (redirect[depth].width + width > redirect[depth].xsize) {

		if (*s == ' ' || *s == ZC_INDENT || *s == ZC_GAP)
		    width = os_string_width (++s);

		memory_new_line ();

	    }

	redirect[depth].width += width;

    }

    addr = redirect[depth].table;

    LOW_WORD (addr, size)
    addr += 2;

    while ((c = *s++) != 0)
	storeb ((zword) (addr + (size++)), translate_to_zscii (c));

    storew (redirect[depth].table, size);

}/* memory_word */
Ejemplo n.º 16
0
void z_show_status (void)
{
    zword global0;
    zword global1;
    zword global2;
    zword addr;

    bool brief = FALSE;

    /* One V5 game (Wishbringer Solid Gold) contains this opcode by
       accident, so just return if the version number does not fit */

    if (h_version >= V4)
        return;

    /* Read all relevant global variables from the memory of the
       Z-machine into local variables */

    addr = h_globals;
    LOW_WORD (addr, global0)
    addr += 2;
    LOW_WORD (addr, global1)
    addr += 2;
    LOW_WORD (addr, global2)

    /* Frotz uses window 7 for the status line. Don't forget to select
       reverse and fixed width text style */

    set_window (7);

    print_char (ZC_NEW_STYLE);
    print_char (REVERSE_STYLE | FIXED_WIDTH_STYLE);

    /* If the screen width is below 55 characters then we have to use
       the brief status line format */

    if (h_screen_cols < 55)
        brief = TRUE;

    /* Print the object description for the global variable 0 */

    print_char (' ');
    print_object (global0);

    /* A header flag tells us whether we have to display the current
       time or the score/moves information */

    if (h_config & CONFIG_TIME) {       /* print hours and minutes */

        zword hours = (global1 + 11) % 12 + 1;

        pad_status_line (brief ? 15 : 20);

        print_string ("Time: ");

        if (hours < 10)
            print_char (' ');
        print_num (hours);

        print_char (':');

        if (global2 < 10)
            print_char ('0');
        print_num (global2);

        print_char (' ');

        print_char ((global1 >= 12) ? 'p' : 'a');
        print_char ('m');

    } else {                            /* print score and moves */

        pad_status_line (brief ? 15 : 30);

        print_string (brief ? "S: " : "Score: ");
        print_num (global1);

        pad_status_line (brief ? 8 : 14);

        print_string (brief ? "M: " : "Moves: ");
        print_num (global2);

    }

    /* Pad the end of the status line with spaces */

    pad_status_line (0);

    /* Return to the lower window */

    set_window (0);

}/* z_show_status */
Ejemplo n.º 17
0
extern "C" FARPROC __stdcall dllGetProcAddress(HMODULE hModule, LPCSTR function)
{
  uintptr_t loc = (uintptr_t)_ReturnAddress();

  void* address = NULL;
  LibraryLoader* dll = DllLoaderContainer::GetModule(hModule);

  if( !dll )
  {
    CLog::Log(LOGERROR, "%s - Invalid hModule specified",__FUNCTION__);
    return NULL;
  }

  /* how can somebody get the stupid idea to create such a stupid function */
  /* where you never know if the given pointer is a pointer or a value */
  if( HIGH_WORD(function) == 0 && LOW_WORD(function) < 1000)
  {
    if( dll->ResolveOrdinal(LOW_WORD(function), &address) )
    {
      CLog::Log(LOGDEBUG, "%s(%p(%s), %d) => %p", __FUNCTION__, hModule, dll->GetName(), LOW_WORD(function), address);
    }
    else if( dll->IsSystemDll() )
    {
      char ordinal[5];
      sprintf(ordinal, "%d", LOW_WORD(function));
      address = (void*)create_dummy_function(dll->GetName(), ordinal);

      /* add to tracklist if we are tracking this source dll */
      DllTrackInfo* track = tracker_get_dlltrackinfo(loc);
      if( track )
        tracker_dll_data_track(track->pDll, (uintptr_t)address);

      CLog::Log(LOGDEBUG, "%s - created dummy function %s!%s",__FUNCTION__, dll->GetName(), ordinal);
    }
    else
    {
      address = NULL;
      CLog::Log(LOGDEBUG, "%s(%p(%s), '%s') => %p",__FUNCTION__ , hModule, dll->GetName(), function, address);
    }
  }
  else
  {
    if( dll->ResolveExport(function, &address) )
    {
      CLog::Log(LOGDEBUG, "%s(%p(%s), '%s') => %p",__FUNCTION__ , hModule, dll->GetName(), function, address);
    }
    else
    {
      DllTrackInfo* track = tracker_get_dlltrackinfo(loc);
      /* some dll's require us to always return a function or it will fail, other's  */
      /* decide functionallity depending on if the functions exist and may fail      */
      if( dll->IsSystemDll() && track
       && stricmp(track->pDll->GetName(), "CoreAVCDecoder.ax") == 0 )
      {
        address = (void*)create_dummy_function(dll->GetName(), function);
        tracker_dll_data_track(track->pDll, (uintptr_t)address);
        CLog::Log(LOGDEBUG, "%s - created dummy function %s!%s", __FUNCTION__, dll->GetName(), function);
      }
      else
      {
        address = NULL;
        CLog::Log(LOGDEBUG, "%s(%p(%s), '%s') => %p", __FUNCTION__, hModule, dll->GetName(), function, address);
      }
    }
  }

  return (FARPROC)address;
}
Ejemplo n.º 18
0
enum MHI_STATUS mhi_init_mmio(struct mhi_device_ctxt *mhi_dev_ctxt)
{
	u64 pcie_dword_val = 0;
	u32 pcie_word_val = 0;
	u32 i = 0;
	enum MHI_STATUS ret_val;

	mhi_log(MHI_MSG_INFO, "~~~ Initializing MMIO ~~~\n");
	mhi_dev_ctxt->mmio_addr = mhi_dev_ctxt->dev_props->bar0_base;

	mhi_log(MHI_MSG_INFO, "Bar 0 address is at: 0x%p\n",
			mhi_dev_ctxt->mmio_addr);

	mhi_dev_ctxt->mmio_len = mhi_reg_read(mhi_dev_ctxt->mmio_addr,
							 MHIREGLEN);

	if (0 == mhi_dev_ctxt->mmio_len) {
		mhi_log(MHI_MSG_ERROR, "Received mmio length as zero\n");
		return MHI_STATUS_ERROR;
	}

	mhi_log(MHI_MSG_INFO, "Testing MHI Ver\n");
	mhi_dev_ctxt->dev_props->mhi_ver = mhi_reg_read(
				mhi_dev_ctxt->mmio_addr, MHIVER);
	if (MHI_VERSION != mhi_dev_ctxt->dev_props->mhi_ver) {
		mhi_log(MHI_MSG_CRITICAL, "Bad MMIO version, 0x%x\n",
					mhi_dev_ctxt->dev_props->mhi_ver);

		if (mhi_dev_ctxt->dev_props->mhi_ver == 0xFFFFFFFF)
			ret_val = mhi_wait_for_mdm(mhi_dev_ctxt);
		if (ret_val)
			return MHI_STATUS_ERROR;
	}
	/* Enable the channels */
	for (i = 0; i < MHI_MAX_CHANNELS; ++i) {
			struct mhi_chan_ctxt *chan_ctxt =
				&mhi_dev_ctxt->mhi_ctrl_seg->mhi_cc_list[i];
		if (VALID_CHAN_NR(i))
			chan_ctxt->mhi_chan_state = MHI_CHAN_STATE_ENABLED;
		else
			chan_ctxt->mhi_chan_state = MHI_CHAN_STATE_DISABLED;
	}
	mhi_log(MHI_MSG_INFO,
			"Read back MMIO Ready bit successfully. Moving on..\n");
	mhi_log(MHI_MSG_INFO, "Reading channel doorbell offset\n");

	mhi_dev_ctxt->channel_db_addr = mhi_dev_ctxt->mmio_addr;
	mhi_dev_ctxt->event_db_addr = mhi_dev_ctxt->mmio_addr;

	mhi_dev_ctxt->channel_db_addr += mhi_reg_read_field(
					mhi_dev_ctxt->mmio_addr,
					CHDBOFF, CHDBOFF_CHDBOFF_MASK,
					CHDBOFF_CHDBOFF_SHIFT);

	mhi_log(MHI_MSG_INFO, "Reading event doorbell offset\n");
	mhi_dev_ctxt->event_db_addr += mhi_reg_read_field(
						mhi_dev_ctxt->mmio_addr,
						ERDBOFF, ERDBOFF_ERDBOFF_MASK,
						ERDBOFF_ERDBOFF_SHIFT);

	mhi_log(MHI_MSG_INFO, "Setting all MMIO values.\n");

	mhi_reg_write_field(mhi_dev_ctxt, mhi_dev_ctxt->mmio_addr, MHICFG,
				MHICFG_NER_MASK, MHICFG_NER_SHIFT,
				MHI_MAX_CHANNELS);

	pcie_dword_val = mhi_v2p_addr(mhi_dev_ctxt->mhi_ctrl_seg_info,
			(uintptr_t)mhi_dev_ctxt->mhi_ctrl_seg->mhi_cc_list);
	pcie_word_val = HIGH_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			    mhi_dev_ctxt->mmio_addr, CCABAP_HIGHER,
			    CCABAP_HIGHER_CCABAP_HIGHER_MASK,
			CCABAP_HIGHER_CCABAP_HIGHER_SHIFT, pcie_word_val);
	pcie_word_val = LOW_WORD(pcie_dword_val);

	mhi_reg_write_field(mhi_dev_ctxt, mhi_dev_ctxt->mmio_addr, CCABAP_LOWER,
				CCABAP_LOWER_CCABAP_LOWER_MASK,
				CCABAP_LOWER_CCABAP_LOWER_SHIFT,
				pcie_word_val);

	/* Write the Event Context Base Address Register High and Low parts */
	pcie_dword_val = mhi_v2p_addr(mhi_dev_ctxt->mhi_ctrl_seg_info,
			(uintptr_t)mhi_dev_ctxt->mhi_ctrl_seg->mhi_ec_list);
	pcie_word_val = HIGH_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			mhi_dev_ctxt->mmio_addr, ECABAP_HIGHER,
			ECABAP_HIGHER_ECABAP_HIGHER_MASK,
			ECABAP_HIGHER_ECABAP_HIGHER_SHIFT, pcie_word_val);
	pcie_word_val = LOW_WORD(pcie_dword_val);

	mhi_reg_write_field(mhi_dev_ctxt, mhi_dev_ctxt->mmio_addr, ECABAP_LOWER,
			ECABAP_LOWER_ECABAP_LOWER_MASK,
			ECABAP_LOWER_ECABAP_LOWER_SHIFT, pcie_word_val);


	/* Write the Command Ring Control Register High and Low parts */
	pcie_dword_val = mhi_v2p_addr(mhi_dev_ctxt->mhi_ctrl_seg_info,
		(uintptr_t)mhi_dev_ctxt->mhi_ctrl_seg->mhi_cmd_ctxt_list);
	pcie_word_val = HIGH_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
				mhi_dev_ctxt->mmio_addr, CRCBAP_HIGHER,
				CRCBAP_HIGHER_CRCBAP_HIGHER_MASK,
				CRCBAP_HIGHER_CRCBAP_HIGHER_SHIFT,
				pcie_word_val);
	pcie_word_val = LOW_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			mhi_dev_ctxt->mmio_addr, CRCBAP_LOWER,
			CRCBAP_LOWER_CRCBAP_LOWER_MASK,
			CRCBAP_LOWER_CRCBAP_LOWER_SHIFT,
			pcie_word_val);

	mhi_dev_ctxt->cmd_db_addr = mhi_dev_ctxt->mmio_addr + CRDB_LOWER;
	/* Set the control segment in the MMIO */
	pcie_dword_val = mhi_v2p_addr(mhi_dev_ctxt->mhi_ctrl_seg_info,
				(uintptr_t)mhi_dev_ctxt->mhi_ctrl_seg);
	pcie_word_val = HIGH_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			mhi_dev_ctxt->mmio_addr, MHICTRLBASE_HIGHER,
			MHICTRLBASE_HIGHER_MHICTRLBASE_HIGHER_MASK,
			MHICTRLBASE_HIGHER_MHICTRLBASE_HIGHER_SHIFT,
			pcie_word_val);

	pcie_word_val = LOW_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			mhi_dev_ctxt->mmio_addr, MHICTRLBASE_LOWER,
			MHICTRLBASE_LOWER_MHICTRLBASE_LOWER_MASK,
			MHICTRLBASE_LOWER_MHICTRLBASE_LOWER_SHIFT,
			pcie_word_val);

	pcie_dword_val = mhi_v2p_addr(mhi_dev_ctxt->mhi_ctrl_seg_info,
				(uintptr_t)mhi_dev_ctxt->mhi_ctrl_seg) +
		mhi_get_memregion_len(mhi_dev_ctxt->mhi_ctrl_seg_info) - 1;

	pcie_word_val = HIGH_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			mhi_dev_ctxt->mmio_addr, MHICTRLLIMIT_HIGHER,
			MHICTRLLIMIT_HIGHER_MHICTRLLIMIT_HIGHER_MASK,
			MHICTRLLIMIT_HIGHER_MHICTRLLIMIT_HIGHER_SHIFT,
			pcie_word_val);
	pcie_word_val = LOW_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			mhi_dev_ctxt->mmio_addr, MHICTRLLIMIT_LOWER,
			MHICTRLLIMIT_LOWER_MHICTRLLIMIT_LOWER_MASK,
			MHICTRLLIMIT_LOWER_MHICTRLLIMIT_LOWER_SHIFT,
			pcie_word_val);

	/* Set the data segment in the MMIO */
	pcie_dword_val = MHI_DATA_SEG_WINDOW_START_ADDR;
	pcie_word_val = HIGH_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			mhi_dev_ctxt->mmio_addr, MHIDATABASE_HIGHER,
			MHIDATABASE_HIGHER_MHIDATABASE_HIGHER_MASK,
			MHIDATABASE_HIGHER_MHIDATABASE_HIGHER_SHIFT,
			pcie_word_val);

	pcie_word_val = LOW_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			mhi_dev_ctxt->mmio_addr, MHIDATABASE_LOWER,
			MHIDATABASE_LOWER_MHIDATABASE_LOWER_MASK,
			MHIDATABASE_LOWER_MHIDATABASE_LOWER_SHIFT,
			pcie_word_val);

	pcie_dword_val = MHI_DATA_SEG_WINDOW_END_ADDR;

	pcie_word_val = HIGH_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			mhi_dev_ctxt->mmio_addr, MHIDATALIMIT_HIGHER,
			MHIDATALIMIT_HIGHER_MHIDATALIMIT_HIGHER_MASK,
			MHIDATALIMIT_HIGHER_MHIDATALIMIT_HIGHER_SHIFT,
			pcie_word_val);
	pcie_word_val = LOW_WORD(pcie_dword_val);
	mhi_reg_write_field(mhi_dev_ctxt,
			    mhi_dev_ctxt->mmio_addr, MHIDATALIMIT_LOWER,
			MHIDATALIMIT_LOWER_MHIDATALIMIT_LOWER_MASK,
			MHIDATALIMIT_LOWER_MHIDATALIMIT_LOWER_SHIFT,
			pcie_word_val);

	mhi_log(MHI_MSG_INFO, "Done..\n");
	return MHI_STATUS_SUCCESS;
}
Ejemplo n.º 19
0
WNDFN WndProc (HWND hwnd, UINT msg, UINT wParam,LONG lParam)
//----------------------------------------------------------------------------
{
//  static SWin w;
  static BOOL dragging = FALSE;
  static long MouseTime = 0;
  static UINT size_flags;
  LPMINMAXINFO pSizeInfo;
  long ret;

  TEventWindow *This = (TEventWindow *) GetWindowLong(hwnd,0);

  switch (msg)
  {
     case WM_CREATE:
      {
         LPCREATESTRUCT lpCreat = (LPCREATESTRUCT) lParam;
         PVOID *lpUser;
         lpUser  = (PVOID *)lpCreat->lpCreateParams;

      //..... 'This' pointer passed as first word of creation parms
         SetWindowLong(hwnd,0,(long)lpUser[0]);
         This = (TEventWindow *)lpUser[0];
         This->get_dc()->set_twin(This);
      }
     return 0;

    case WM_SIZE:
      This->size(LOWORD(lParam),HIWORD(lParam));
      return 0;

    case WM_MOVE:
      This->on_move();
      return 0;

    case WM_GETMINMAXINFO:
        if (This && This->cant_resize()) {
          pSizeInfo = (LPMINMAXINFO) lParam;
          pSizeInfo->ptMaxTrackSize = This->fixed_size();
          pSizeInfo->ptMinTrackSize = This->fixed_size();
        }
        return 0;

  //
    case WM_COMMAND:
      if (This->m_dispatcher) { 
            This->m_dispatcher->dispatch(LOW_WORD(wParam),HIWORD(wParam),(Handle)lParam);
            return 0;
      }
      if (This->command(LOW_WORD(wParam))) return 0;
      else break;

   case WM_USER_PLUS:
      return This->handle_user(wParam,lParam);

    case WM_KEYDOWN:
        This->keydown(wParam);
        return 0;

    case WM_CHAR:
         This->on_char(wParam,LOWORD(lParam));  // 1
         return 0;

    case WM_HSCROLL:
       if (This->m_dispatcher) { 
            int id = GetWindowLong((HWND)lParam,GWL_ID);
            This->m_dispatcher->dispatch(id,LOWORD(wParam),(Handle)lParam);
       } 
       return 0;
    case WM_VSCROLL:
       This->vscroll(wParam,This->scroll_bar()->get_pos());
       return 0;

    case WM_PAINT:
     {
        PAINTSTRUCT ps;
        TDC *dc = This->get_dc();
        dc->set_hdc(BeginPaint(hwnd,&ps));
        This->paint(*dc);
        dc->set_hdc(NULL);
        EndPaint(hwnd,&ps);
     }
     return 0;

// Mouse messages....

  case WM_LBUTTONDOWN:
  case WM_LBUTTONUP:
  case WM_RBUTTONDOWN:
  case WM_LBUTTONDBLCLK:
    {
        Point pt(LOWORD(lParam),HIWORD(lParam));
        //pt.to_logical(*This);
     switch (msg) {
        case WM_LBUTTONDOWN:
            This->mouse_down(pt);
         break;
        case WM_LBUTTONUP:
         This->mouse_up(pt);
         break;
        case WM_RBUTTONDOWN:
            This->right_mouse_down(pt);
            break;
        case WM_LBUTTONDBLCLK:
            This->mouse_double_click(pt);
            break;
      }
    }
    return 0;


    case WM_MOUSEMOVE:  // needs different treatment??
     {
        Point pt(LOWORD(lParam),HIWORD(lParam));
          This->mouse_move(pt);
     }
     return 0;

  case WM_ERASEBKGND:
    {
      RECT rt;
      GetClientRect(hwnd,&rt);
      FillRect((HDC)wParam,(LPRECT)&rt, This->m_bkgnd_brush);
    }
    return 0;

  #ifdef _WIN32
  case WM_CTLCOLORSTATIC:
    {
     TControl *ctl = (TControl *)GetWindowLong((HWND)lParam,GWL_USERDATA);
     SetBkColor((HDC)wParam, (COLORREF)This->m_bk_color);
     SetTextColor((HDC)wParam, ctl->get_colour());
    }
    return (long)This->m_bkgnd_brush;
  #endif

  case WM_SETFOCUS:
     This->focus(true);
     return 0;

  case WM_KILLFOCUS:
     This->focus(false);
     return 0;

  case WM_SYSCOMMAND:
     if (This->sys_command(LOW_WORD(wParam))) return 0; //?
     else break;

  case WM_TIMER:
      This->timer();
      return 0;

  case WM_CLOSE:
    if (! This->query_close()) return 0;
    break;  // *NOTE* this was not here!!

  case WM_DESTROY:
    //*fix 1.2.8 This had been commented out; prevents closing via usual window operation. 
    This->destroy();
    if (This->m_hmenu) DeleteObject(This->m_hmenu);  // but why here?
    return 0 ;
 }

 ret = DefWindowProc (hwnd , msg, wParam, lParam) ;

 return ret;
}
Ejemplo n.º 20
0
void init_memory (void)
{
    long size;
    zword addr;
    unsigned n;
    int i, j;

    static struct {
        enum story story_id;
        zword release;
        zbyte serial[6];
    } records[] = {
        {       SHERLOCK,  21, "871214" },
        {       SHERLOCK,  26, "880127" },
        {    BEYOND_ZORK,  47, "870915" },
        {    BEYOND_ZORK,  49, "870917" },
        {    BEYOND_ZORK,  51, "870923" },
        {    BEYOND_ZORK,  57, "871221" },
        {      ZORK_ZERO, 296, "881019" },
        {      ZORK_ZERO, 366, "890323" },
        {      ZORK_ZERO, 383, "890602" },
        {      ZORK_ZERO, 393, "890714" },
        {         SHOGUN, 292, "890314" },
        {         SHOGUN, 295, "890321" },
        {         SHOGUN, 311, "890510" },
        {         SHOGUN, 322, "890706" },
        {         ARTHUR,  54, "890606" },
        {         ARTHUR,  63, "890622" },
        {         ARTHUR,  74, "890714" },
        {        JOURNEY,  26, "890316" },
        {        JOURNEY,  30, "890322" },
        {        JOURNEY,  77, "890616" },
        {        JOURNEY,  83, "890706" },
        { LURKING_HORROR, 203, "870506" },
        { LURKING_HORROR, 219, "870912" },
        { LURKING_HORROR, 221, "870918" },
        {        UNKNOWN,   0, "------" }
    };

    /* Open story file */
    {
        giblorb_map_t *map;
        giblorb_result_t res;
        char magic[4] = "XXXX";
        strid_t file;

        file = game_file_stream;

        fread(magic, 1, 4, file);

        if (!memcmp(magic, "FORM", 4))
        {
            if (giblorb_set_resource_map(file))
                os_fatal("This Blorb file seems to be invalid.");

            map = giblorb_get_resource_map();

            if (giblorb_load_resource(map, giblorb_method_FilePos,
                                      &res, giblorb_ID_Exec, 0))
                os_fatal("This Blorb file does not contain an executable chunk.");
            if (res.chunktype != giblorb_make_id('Z','C','O','D'))
                os_fatal("This Blorb file contains an executable chunk, but it is not a Z-code file.");

            story_fp = file;
            blorb_ofs = res.data.startpos;
            blorb_len = res.length;
        }
        else
        {
            story_fp = file;
            blorb_ofs = 0;
            fseek(story_fp, 0, SEEK_END);
            blorb_len = ftell(story_fp);
        }

    }

    if (blorb_len < 64)
        os_fatal("This file is too small to be a Z-code file.");

    /* Allocate memory for story header */

    if ((zmp = (zbyte *) malloc (64)) == NULL)
        os_fatal ("Out of memory");

    /* Load header into memory */

    fseek(story_fp, blorb_ofs, 0);

    if (fread (zmp, 1, 64, story_fp) != 64)
        os_fatal ("Story file read error");

    /* Copy header fields to global variables */

    LOW_BYTE (H_VERSION, h_version);

    if (h_version < V1 || h_version > V8)
        os_fatal ("Unknown Z-code version");

    if (h_version == V6)
        os_fatal ("Cannot play Z-code version 6");

    LOW_BYTE (H_CONFIG, h_config);

    if (h_version == V3 && (h_config & CONFIG_BYTE_SWAPPED))
        os_fatal ("Byte swapped story file");

    LOW_WORD (H_RELEASE, h_release);
    LOW_WORD (H_RESIDENT_SIZE, h_resident_size);
    LOW_WORD (H_START_PC, h_start_pc);
    LOW_WORD (H_DICTIONARY, h_dictionary);
    LOW_WORD (H_OBJECTS, h_objects);
    LOW_WORD (H_GLOBALS, h_globals);
    LOW_WORD (H_DYNAMIC_SIZE, h_dynamic_size);
    LOW_WORD (H_FLAGS, h_flags);

    for (i = 0, addr = H_SERIAL; i < 6; i++, addr++)
        LOW_BYTE (addr, h_serial[i]);

    /* Auto-detect buggy story files that need special fixes */

    story_id = UNKNOWN;

    for (i = 0; records[i].story_id != UNKNOWN; i++) {

        if (h_release == records[i].release) {

            for (j = 0; j < 6; j++)
                if (h_serial[j] != records[i].serial[j])
                    goto no_match;

            story_id = records[i].story_id;

        }

no_match: ; /* null statement */

    }

    LOW_WORD (H_ABBREVIATIONS, h_abbreviations);
    LOW_WORD (H_FILE_SIZE, h_file_size);

    /* Calculate story file size in bytes */

    if (h_file_size != 0) {

        story_size = (long) 2 * h_file_size;

        if (h_version >= V4)
            story_size *= 2;
        if (h_version >= V6)
            story_size *= 2;

    } else {		/* some old games lack the file size entry */

        story_size = blorb_len;
    }

    LOW_WORD (H_CHECKSUM, h_checksum);
    LOW_WORD (H_ALPHABET, h_alphabet);
    LOW_WORD (H_FUNCTIONS_OFFSET, h_functions_offset);
    LOW_WORD (H_STRINGS_OFFSET, h_strings_offset);
    LOW_WORD (H_TERMINATING_KEYS, h_terminating_keys);
    LOW_WORD (H_EXTENSION_TABLE, h_extension_table);

    /* Zork Zero Macintosh doesn't have the graphics flag set */

    if (story_id == ZORK_ZERO && h_release == 296)
        h_flags |= GRAPHICS_FLAG;

    /* Adjust opcode tables */

    if (h_version <= V4) {
        op0_opcodes[0x09] = z_pop;
        op1_opcodes[0x0f] = z_not;
    } else {
        op0_opcodes[0x09] = z_catch;
        op1_opcodes[0x0f] = z_call_n;
    }

    /* Allocate memory for story data */

    if ((zmp = (zbyte *) realloc (zmp, story_size)) == NULL)
        os_fatal ("Out of memory");

    /* Load story file in chunks of 32KB */

    n = 0x8000;

    for (size = 64; size < story_size; size += n) {

        if (story_size - size < 0x8000)
            n = (unsigned) (story_size - size);

        SET_PC (size);

        if (fread (pcp, 1, n, story_fp) != n)
            os_fatal ("Story file read error");

    }

    /* Read header extension table */

    hx_table_size = get_header_extension (HX_TABLE_SIZE);
    hx_unicode_table = get_header_extension (HX_UNICODE_TABLE);

}/* init_memory */
Ejemplo n.º 21
0
static ssize_t bhi_write(struct file *file,
		const char __user *buf,
		size_t count, loff_t *offp)
{
	enum MHI_STATUS ret_val = MHI_STATUS_SUCCESS;
	u32 pcie_word_val = 0;
	u32 i = 0;
	struct bhi_ctxt_t *bhi_ctxt =
		&(((struct mhi_pcie_dev_info *)file->private_data)->bhi_ctxt);
	struct mhi_device_ctxt *mhi_dev_ctxt =
		&((struct mhi_pcie_dev_info *)file->private_data)->mhi_ctxt;
	size_t amount_copied = 0;
	uintptr_t align_len = 0x1000;
	u32 tx_db_val = 0;

	if (buf == NULL || 0 == count)
		return -EIO;

	if (count > BHI_MAX_IMAGE_SIZE)
		return -ENOMEM;

	wait_event_interruptible(*mhi_dev_ctxt->mhi_ev_wq.bhi_event,
			mhi_dev_ctxt->mhi_state == MHI_STATE_BHI);

	mhi_log(MHI_MSG_INFO, "Entered. User Image size 0x%zx\n", count);

	bhi_ctxt->unaligned_image_loc = kmalloc(count + (align_len - 1),
						GFP_KERNEL);
	if (bhi_ctxt->unaligned_image_loc == NULL)
		return -ENOMEM;

	mhi_log(MHI_MSG_INFO, "Unaligned Img Loc: %p\n",
			bhi_ctxt->unaligned_image_loc);
	bhi_ctxt->image_loc =
			(void *)((uintptr_t)bhi_ctxt->unaligned_image_loc +
		 (align_len - (((uintptr_t)bhi_ctxt->unaligned_image_loc) %
			       align_len)));

	mhi_log(MHI_MSG_INFO, "Aligned Img Loc: %p\n", bhi_ctxt->image_loc);

	bhi_ctxt->image_size = count;

	if (0 != copy_from_user(bhi_ctxt->image_loc, buf, count)) {
		ret_val = -ENOMEM;
		goto bhi_copy_error;
	}
	amount_copied = count;
	/* Flush the writes, in anticipation for a device read */
	wmb();
	mhi_log(MHI_MSG_INFO,
		"Copied image from user at addr: %p\n", bhi_ctxt->image_loc);
	bhi_ctxt->phy_image_loc = dma_map_single(
			&mhi_dev_ctxt->dev_info->plat_dev->dev,
			bhi_ctxt->image_loc,
			bhi_ctxt->image_size,
			DMA_TO_DEVICE);

	if (dma_mapping_error(NULL, bhi_ctxt->phy_image_loc)) {
		ret_val = -EIO;
		goto bhi_copy_error;
	}
	mhi_log(MHI_MSG_INFO,
		"Mapped image to DMA addr 0x%lx:\n",
		(uintptr_t)bhi_ctxt->phy_image_loc);

	bhi_ctxt->image_size = count;

	/* Write the image size */
	pcie_word_val = HIGH_WORD(bhi_ctxt->phy_image_loc);
	mhi_reg_write_field(mhi_dev_ctxt, bhi_ctxt->bhi_base,
				BHI_IMGADDR_HIGH,
				0xFFFFFFFF,
				0,
				pcie_word_val);

	pcie_word_val = LOW_WORD(bhi_ctxt->phy_image_loc);

	mhi_reg_write_field(mhi_dev_ctxt, bhi_ctxt->bhi_base,
				BHI_IMGADDR_LOW,
				0xFFFFFFFF,
				0,
				pcie_word_val);

	pcie_word_val = bhi_ctxt->image_size;
	mhi_reg_write_field(mhi_dev_ctxt, bhi_ctxt->bhi_base, BHI_IMGSIZE,
			0xFFFFFFFF, 0, pcie_word_val);

	pcie_word_val = mhi_reg_read(bhi_ctxt->bhi_base, BHI_IMGTXDB);
	mhi_reg_write_field(mhi_dev_ctxt, bhi_ctxt->bhi_base,
			BHI_IMGTXDB, 0xFFFFFFFF, 0, ++pcie_word_val);

	mhi_reg_write(mhi_dev_ctxt, bhi_ctxt->bhi_base, BHI_INTVEC, 0);

	for (i = 0; i < BHI_POLL_NR_RETRIES; ++i) {
		tx_db_val = mhi_reg_read_field(bhi_ctxt->bhi_base,
						BHI_STATUS,
						BHI_STATUS_MASK,
						BHI_STATUS_SHIFT);
		mhi_log(MHI_MSG_CRITICAL, "BHI STATUS 0x%x\n", tx_db_val);
		if (BHI_STATUS_SUCCESS != tx_db_val)
			mhi_log(MHI_MSG_CRITICAL,
				"Incorrect BHI status: %d retry: %d\n",
				tx_db_val, i);
		else
			break;
		usleep_range(20000, 25000);
	}
	dma_unmap_single(&mhi_dev_ctxt->dev_info->plat_dev->dev,
			bhi_ctxt->phy_image_loc,
			bhi_ctxt->image_size, DMA_TO_DEVICE);

	kfree(bhi_ctxt->unaligned_image_loc);

	ret_val = mhi_init_state_transition(mhi_dev_ctxt,
					STATE_TRANSITION_RESET);
	if (MHI_STATUS_SUCCESS != ret_val) {
		mhi_log(MHI_MSG_CRITICAL,
				"Failed to start state change event\n");
	}
	return amount_copied;

bhi_copy_error:
	kfree(bhi_ctxt->unaligned_image_loc);
	return amount_copied;
}
Ejemplo n.º 22
0
int
__libmcr_k_mx_rem_pio2(double x, double y[])
{
	double z, w, t, r, fn, y0;
	double tx[3];
	int e0, i, j, nx, n, ix, hx, lx, hr, i0;
#ifdef debug
	int ms[10], mw[10], mx[10], my[10], mz[10], nw = 8, mc[10], nz,
		mt[10], mr[10], my0[10];

	nz = __libmcr_k_mi_rem_pio2(x, my, nw);
#endif

	z = fabs(x);
	w = z * INVPIO2;
	hx = HIGH_WORD(x);
	lx = LOW_WORD(x);
	ix = hx & 0x7fffffff;
	/* for |x| <= 1638400 */
	if (ix <= 0x41390000) {
		n = (int) (w + HALF);	/* |x| ~ n*pi/2, n < 2^19 */
#ifdef debug
	printf(" w = %1.20e %08X %08X \n", w, .HIGH_WORD(w), .LOW_WORD(w));
	printf(" HALF = %1.20e\n", HALF);
	printf(" n = %d\n", n);
#endif
		if (ix <= 0x3fe921fa) {
			y[0] = x;
			y[1] = 0;
			return (0);
		}		/* |x| < pi/2 */
		fn = (double) n;
		j = ix >> 20;
		t = fn * PIO2_1;
		w = fn * PIO2_1T;	/* 1st round good to 85 bit */
		r = z - t;
		i0 = 0;
		y0 = r - w;
		hr = HIGH_WORD(r);
		i = (hr & (~0x80000000)) >> 20;
#ifdef debug
		printf("x        = %08X %08X % 1.20e\n",
			HIGH_WORD(x), LOW_WORD(x), x);
		printf("n        = %d\n", n);
		printf("nz       = %d\n", nz);
		printf("n*PIO2_1 = %08X %08X % 1.20e\n",
			HIGH_WORD(t), LOW_WORD(t), t);
		printf("n*PIO2_1T= %08X %08X % 1.20e\n",
			HIGH_WORD(w), LOW_WORD(w), w);
		__libmcr_mi_dtomi(t, mt, nw);
		__libmcr_mi_dtomi(w, mw, nw);
		__libmcr_mi_dtomi(z, mz, nw);
		__libmcr_mm_sub(mz, mt, mr, nw);
		__libmcr_mm_sub(mr, mw, my0, nw);
		printf("z - n*PIO2 =\n");
		PNT(my);
		PNT(my0);
		printf("r = z-t  = %08X %08X % 1.20e\n",
			HIGH_WORD(r), LOW_WORD(r), r);
		printf("y0= r-w  = %08X %08X % 1.20e\n",
			HIGH_WORD(y0), LOW_WORD(y0), y0);
		printf("j = %d, i = %d, j-i=%d > 6?\n", j, i, j - i);
#endif
		while ((j - i) >= 7) { /* 7 bit cancellation (insure 78 bits) */
			t = fn * PIO2_2[i0];  /* at most five loop is suffice */
			z = r;
			j = i;
#ifdef debug
			printf("Are r-t exact?\n");
			printf("r = %08X %08X %1.20e\n", r, r);
			printf("t = %08X %08X %1.20e\n", t, t);
			__libmcr_mi_dtomi(t, mt, nw);
			__libmcr_mi_dtomi(r, mw, nw);
			__libmcr_mm_sub(mw, mt, mt, nw);
#endif
			r -= t;
#ifdef debug
			__libmcr_mi_dtomi(r, mw, nw);
			__libmcr_mm_sub(mw, mt, mt, nw);
			if (mt[2] == 0)
				printf("Yes.\n");
			else
				printf("No.\n");
#endif
			w = fn * PIO2_2[i0 + 1];
			y0 = r - w;
			i0 += 2;
			hr = HIGH_WORD(r);
			i = (hr & (~0x80000000)) >> 20;
#ifdef debug
			printf("w = %08X %08X %1.20e\n", w, w);
			printf("y0= %08X %08X %1.20e\n", y0, y0);
			__libmcr_mi_dtomi(t, mt, nw);
			__libmcr_mi_dtomi(w, mw, nw);
			__libmcr_mm_sub(mr, mt, mr, nw);
			__libmcr_mm_sub(mr, mw, my0, nw);
			printf("z - n*PIO2[%1d] =\n", i0 + 2);
			PNT(my);
			PNT(my0);
			printf("new j = %d, i = %d, j-i=%d > 5?\n",
				j, i, j - i);
#endif
		}
		if (i0 == 0 || (j - i) > 1) {
			r -= y0;
			y[0] = y0;
			y[1] = r - w;
		} else {
			t += y0 - z;
			y[0] = y0;
			y[1] = -w - t;
		}

#ifdef debug
		printf("test final sum (n=%d):\n", n);
		__libmcr_mi_dtomi(y[0], mr, nw);
		printf("y[0]  = % 1.20e ", y[0]);
		PNT(mr);
		__libmcr_mi_dtomi(y[1], mt, nw);
		printf("y[1]  = % 1.20e ", y[1]);
		PNT(mt);
		__libmcr_mm_add(mr, mt, mt, nw);
		printf("y0+y1 = % 1.20e ", y[0] + y[1]);
		PNT(mt);
		PNT(mt);
#endif

		if (hx < 0) {
			y[1] = -y[1];
			y[0] = -y0;
			return (-n);
		} else {
			return (n);
		}
	}