Beispiel #1
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;
}
Beispiel #2
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;
}