Example #1
0
static int		recv_screen_80	(CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap)
{
	int ret;
	uint8_t * buffer;

	*bitmap = (uint8_t *)ticalcs_alloc_screen(TI80_COLS * TI80_ROWS / 8);
	if (*bitmap == NULL)
	{
		return ERR_MALLOC;
	}

	sc->width = TI80_COLS;
	sc->height = TI80_ROWS;
	sc->clipped_width = TI80_COLS;
	sc->clipped_height = TI80_ROWS;
	sc->pixel_format = CALC_PIXFMT_MONO;

	ret = ti80_send_SCR(handle);
	if (!ret)
	{
		ret = ti80_recv_ACK(handle, NULL);
		if (!ret)
		{
			uint16_t max_cnt;
			ret = ti80_recv_XDP(handle, &max_cnt, handle->buffer);
			if (!ret)
			{
				int stripe, row, i = 0;
				buffer = (uint8_t *)(handle->buffer);
				for (stripe = 7; stripe >= 0; stripe--)
				{
					for (row = 0; row < TI80_ROWS; row++)
					{
						(*bitmap)[row * TI80_COLS / 8 + stripe] = buffer[i++];
					}
				}
			}
		}
	}

	if (ret)
	{
		ticalcs_free_screen(*bitmap);
		*bitmap = NULL;
	}

	return ret;
}
Example #2
0
static int		recv_screen	(CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap)
{
	int ret;
	CalcInfos infos;

	// First of all, we have to identify the Nspire model.
	ret = get_version(handle, &infos);
	if (!ret)
	{
		if (infos.bits_per_pixel == 4)
		{
			// Nspire (CAS) Clickpad or Touchpad.
			sc->pixel_format = CALC_PIXFMT_GRAY_4;
		}
		else if (infos.bits_per_pixel == 16)
		{
			// Nspire (CAS) CX or CM.
			sc->pixel_format = CALC_PIXFMT_RGB_565_LE;
		}
		else
		{
			ticalcs_critical(_("Unknown calculator model with %d bpp\n"), infos.bits_per_pixel);
			return ERR_UNSUPPORTED; // THIS RETURNS !
		}

		// Do screenshot
		ret = nsp_session_open(handle, NSP_SID_SCREEN_RLE);
		if (!ret)
		{
			ret = nsp_cmd_s_screen_rle(handle, 0);
			if (!ret)
			{
				uint32_t size = 0;
				uint8_t cmd, *data;

				ret = nsp_cmd_r_screen_rle(handle, &cmd, &size, &data);
				if (!ret)
				{
					sc->width = sc->clipped_width = (((uint16_t)data[8]) << 8) | data[9];
					sc->height = sc->clipped_height = (((uint16_t)data[10]) << 8) | data[11];
					size = (  (((uint32_t)data[0]) << 24)
					        | (((uint32_t)data[1]) << 16)
					        | (((uint32_t)data[2]) <<  8)
					        | (((uint32_t)data[3])      ));
					g_free(data);

					if (sc->width > 320)
					{
						ticalcs_critical("%s: no calculator model known to this library has screens of width > 320 pixels", __FUNCTION__);
						ret = ERR_INVALID_PACKET;
					}
					else if (sc->height > 240)
					{
						ticalcs_critical("%s: no calculator model known to this library has screens of height > 240 pixels", __FUNCTION__);
						ret = ERR_INVALID_PACKET;
					}
					else if (size > 2 * sc->width * sc->height)
					{
						ticalcs_critical("%s: no calculator model known to this library uses more than 16 bpp", __FUNCTION__);
						ret = ERR_INVALID_PACKET;
					}
					else
					{
						ret = nsp_cmd_r_screen_rle(handle, &cmd, &size, &data);
						if (!ret)
						{
							uint32_t len = sc->width * sc->height * infos.bits_per_pixel / 8;
							uint8_t * dst = ticalcs_alloc_screen(len);
							if (dst != NULL)
							{
								ret = ticalcs_screen_nspire_rle_uncompress(sc->pixel_format, data, size, dst, len);
								if (!ret)
								{
									*bitmap = dst;
								}
								else
								{
									ticalcs_free_screen(dst);
								}
							}
							else
							{
								ret = ERR_MALLOC;
							}
							g_free(data);
						}
					}
				}
			}

			DO_CLOSE_SESSION(handle);
		}
	}

	return ret;
}
Example #3
0
static int		recv_screen	(CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap)
{
	int ret;

	*bitmap = (uint8_t *)ticalcs_alloc_screen(65537U);
	if (*bitmap == NULL)
	{
		return ERR_MALLOC;
	}

	if (handle->model == CALC_TI82)
	{
		sc->width = TI82_COLS;
		sc->height = TI82_ROWS;
		sc->clipped_width = TI82_COLS;
		sc->clipped_height = TI82_ROWS;
	}
	else if (handle->model == CALC_TI83)
	{
		sc->width = TI83_COLS;
		sc->height = TI83_ROWS;
		sc->clipped_width = TI83_COLS;
		sc->clipped_height = TI83_ROWS;
	}
	else if (handle->model == CALC_TI85)
	{
		sc->width = TI85_COLS;
		sc->height = TI85_ROWS;
		sc->clipped_width = TI85_COLS;
		sc->clipped_height = TI85_ROWS;
	}
	else
	{
		sc->width = TI86_COLS;
		sc->height = TI86_ROWS;
		sc->clipped_width = TI86_COLS;
		sc->clipped_height = TI86_ROWS;
	}
	sc->pixel_format = CALC_PIXFMT_MONO;

	ret = SEND_SCR(handle);
	if (!ret)
	{
		ret = RECV_ACK(handle, NULL);
		if (!ret)
		{
			uint16_t max_cnt;
			ret = RECV_XDP(handle, &max_cnt, *bitmap);
			if (!ret || ret == ERR_CHECKSUM) // problem with checksum
			{
				*bitmap = ticalcs_realloc_screen(*bitmap, (handle->model < CALC_TI85) ? TI82_COLS * TI82_ROWS / 8 : TI85_COLS * TI85_ROWS / 8);
				ret = SEND_ACK(handle);
			}
		}
	}

	if (ret)
	{
		ticalcs_free_screen(*bitmap);
		*bitmap = NULL;
	}

	return ret;
}
Example #4
0
static int		recv_screen	(CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap)
{
	int ret;
	uint8_t *buffer = handle->buffer2;
	uint8_t *data = NULL;

	data = (uint8_t *)ticalcs_alloc_screen(65537U);
	if (data == NULL)
	{
		return ERR_MALLOC;
	}

	ret = SEND_SCR(handle);
	if (!ret)
	{
		ret = RECV_ACK(handle, NULL);
		if (!ret)
		{
			uint16_t pktsize;
			ret = RECV_XDP(handle, &pktsize, data);
			if (!ret || ret == ERR_CHECKSUM) // problem with checksum
			{
				ret = SEND_ACK(handle);
				if (!ret)
				{
					if (pktsize == TI73_COLS * TI73_ROWS / 8)
					{
						/* TI-73 / 83+ / 84+ */
						sc->width = TI73_COLS;
						sc->height = TI73_ROWS;
						sc->clipped_width = TI73_COLS;
						sc->clipped_height = TI73_ROWS;
						sc->pixel_format = CALC_PIXFMT_MONO;
						*bitmap = ticalcs_realloc_screen(data, TI73_COLS * TI73_ROWS / 8);
					}
					else
					{
						/* TI-84+CSE */
						uint32_t size = pktsize;

						sc->width = TI84PC_COLS;
						sc->height = TI84PC_ROWS;
						sc->clipped_width = TI84PC_COLS;
						sc->clipped_height = TI84PC_ROWS;
						sc->pixel_format = CALC_PIXFMT_RGB_565_LE;

						while (1)
						{
							ret = RECV_XDP(handle, &pktsize, buffer);
							if (ret == ERR_EOT)
							{
								ret = SEND_ACK(handle);
								break;
							}

							*bitmap = ticalcs_realloc_screen(data, size + pktsize);
							if (*bitmap != NULL)
							{
								data = *bitmap;
								memcpy(data + size, buffer, pktsize);
								size += pktsize;

								ret = SEND_ACK(handle);
								if (ret)
								{
									break;
								}

								handle->updat->max1 = TI84PC_COLS * TI84PC_ROWS * 2;
								handle->updat->cnt1 = size;
								ticalcs_update_pbar(handle);
							}
							else
							{
								ticalcs_free_screen(data);
								ret = ERR_MALLOC;
								break;
							}
						}

						if (!ret)
						{
							*bitmap = ticalcs_alloc_screen(TI84PC_ROWS * TI84PC_COLS * 2);
							ret = ticalcs_screen_84pcse_rle_uncompress(data, size, *bitmap, TI84PC_ROWS * TI84PC_COLS * 2);
						}
					}
				}
			}
		}
	}

	if (ret)
	{
		ticalcs_free_screen(*bitmap);
		*bitmap = NULL;
	}

	return ret;
}