repo_name
stringlengths 6
97
| path
stringlengths 3
341
| text
stringlengths 8
1.02M
|
|---|---|---|
jrth/zephyr
|
arch/x86/core/multiboot.c
|
<gh_stars>0
/*
* Copyright (c) 2019 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <arch/x86/multiboot.h>
#ifdef CONFIG_X86_MULTIBOOT_INFO
struct x86_multiboot_info x86_multiboot_info;
#ifdef CONFIG_X86_MULTIBOOT_FRAMEBUF
#include <display/framebuf.h>
static struct framebuf_dev_data multiboot_framebuf_data = {
.width = CONFIG_X86_MULTIBOOT_FRAMEBUF_X,
.height = CONFIG_X86_MULTIBOOT_FRAMEBUF_Y
};
static int multiboot_framebuf_init(struct device *dev)
{
struct framebuf_dev_data *data = FRAMEBUF_DATA(dev);
struct x86_multiboot_info *info = &x86_multiboot_info;
if ((info->flags & X86_MULTIBOOT_INFO_FLAGS_FB) &&
(info->fb_width >= CONFIG_X86_MULTIBOOT_FRAMEBUF_X) &&
(info->fb_height >= CONFIG_X86_MULTIBOOT_FRAMEBUF_Y) &&
(info->fb_bpp == 32) && (info->fb_addr_hi == 0)) {
/*
* We have a usable multiboot framebuffer - it is 32 bpp
* and at least as large as the requested dimensions. Compute
* the pitch and adjust the start address center our canvas.
*/
u16_t adj_x;
u16_t adj_y;
u32_t *buffer;
adj_x = info->fb_width - CONFIG_X86_MULTIBOOT_FRAMEBUF_X;
adj_y = info->fb_height - CONFIG_X86_MULTIBOOT_FRAMEBUF_Y;
data->pitch = (info->fb_pitch / 4) + adj_x;
adj_x /= 2;
adj_y /= 2;
buffer = (uint32_t *) (uintptr_t) info->fb_addr_lo;
buffer += adj_x;
buffer += adj_y * data->pitch;
data->buffer = buffer;
return 0;
} else {
return -ENOTSUP;
}
}
DEVICE_AND_API_INIT(multiboot_framebuf,
"FRAMEBUF",
multiboot_framebuf_init,
&multiboot_framebuf_data,
NULL,
PRE_KERNEL_1,
CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&framebuf_display_api);
#endif /* CONFIG_X86_MULTIBOOT_FRAMEBUF */
#endif /* CONFIG_X86_MULTIBOOT_INFO */
|
jrth/zephyr
|
soc/arm/st_stm32/stm32f4/dts_fixup.h
|
<reponame>jrth/zephyr<gh_stars>0
/* SPDX-License-Identifier: Apache-2.0 */
/* SoC level DTS fixup file */
#define DT_NUM_IRQ_PRIO_BITS DT_ARM_V7M_NVIC_E000E100_ARM_NUM_IRQ_PRIORITY_BITS
#define DT_GPIO_STM32_GPIOA_BASE_ADDRESS DT_ST_STM32_GPIO_40020000_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOA_CLOCK_BITS_0 DT_ST_STM32_GPIO_40020000_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOA_CLOCK_BUS_0 DT_ST_STM32_GPIO_40020000_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOA_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40020000_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOA_LABEL DT_ST_STM32_GPIO_40020000_LABEL
#define DT_GPIO_STM32_GPIOA_SIZE DT_ST_STM32_GPIO_40020000_SIZE
#define DT_GPIO_STM32_GPIOA_CLOCK_BITS DT_ST_STM32_GPIO_40020000_CLOCK_BITS
#define DT_GPIO_STM32_GPIOA_CLOCK_BUS DT_ST_STM32_GPIO_40020000_CLOCK_BUS
#define DT_GPIO_STM32_GPIOB_BASE_ADDRESS DT_ST_STM32_GPIO_40020400_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOB_CLOCK_BITS_0 DT_ST_STM32_GPIO_40020400_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOB_CLOCK_BUS_0 DT_ST_STM32_GPIO_40020400_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOB_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40020400_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOB_LABEL DT_ST_STM32_GPIO_40020400_LABEL
#define DT_GPIO_STM32_GPIOB_SIZE DT_ST_STM32_GPIO_40020400_SIZE
#define DT_GPIO_STM32_GPIOB_CLOCK_BITS DT_ST_STM32_GPIO_40020400_CLOCK_BITS
#define DT_GPIO_STM32_GPIOB_CLOCK_BUS DT_ST_STM32_GPIO_40020400_CLOCK_BUS
#define DT_GPIO_STM32_GPIOC_BASE_ADDRESS DT_ST_STM32_GPIO_40020800_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOC_CLOCK_BITS_0 DT_ST_STM32_GPIO_40020800_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOC_CLOCK_BUS_0 DT_ST_STM32_GPIO_40020800_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOC_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40020800_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOC_LABEL DT_ST_STM32_GPIO_40020800_LABEL
#define DT_GPIO_STM32_GPIOC_SIZE DT_ST_STM32_GPIO_40020800_SIZE
#define DT_GPIO_STM32_GPIOC_CLOCK_BITS DT_ST_STM32_GPIO_40020800_CLOCK_BITS
#define DT_GPIO_STM32_GPIOC_CLOCK_BUS DT_ST_STM32_GPIO_40020800_CLOCK_BUS
#define DT_GPIO_STM32_GPIOD_BASE_ADDRESS DT_ST_STM32_GPIO_40020C00_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOD_CLOCK_BITS_0 DT_ST_STM32_GPIO_40020C00_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOD_CLOCK_BUS_0 DT_ST_STM32_GPIO_40020C00_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOD_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40020C00_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOD_LABEL DT_ST_STM32_GPIO_40020C00_LABEL
#define DT_GPIO_STM32_GPIOD_SIZE DT_ST_STM32_GPIO_40020C00_SIZE
#define DT_GPIO_STM32_GPIOD_CLOCK_BITS DT_ST_STM32_GPIO_40020C00_CLOCK_BITS
#define DT_GPIO_STM32_GPIOD_CLOCK_BUS DT_ST_STM32_GPIO_40020C00_CLOCK_BUS
#define DT_GPIO_STM32_GPIOE_BASE_ADDRESS DT_ST_STM32_GPIO_40021000_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOE_CLOCK_BITS_0 DT_ST_STM32_GPIO_40021000_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOE_CLOCK_BUS_0 DT_ST_STM32_GPIO_40021000_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOE_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40021000_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOE_LABEL DT_ST_STM32_GPIO_40021000_LABEL
#define DT_GPIO_STM32_GPIOE_SIZE DT_ST_STM32_GPIO_40021000_SIZE
#define DT_GPIO_STM32_GPIOE_CLOCK_BITS DT_ST_STM32_GPIO_40021000_CLOCK_BITS
#define DT_GPIO_STM32_GPIOE_CLOCK_BUS DT_ST_STM32_GPIO_40021000_CLOCK_BUS
#define DT_GPIO_STM32_GPIOF_BASE_ADDRESS DT_ST_STM32_GPIO_40021400_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOF_CLOCK_BITS_0 DT_ST_STM32_GPIO_40021400_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOF_CLOCK_BUS_0 DT_ST_STM32_GPIO_40021400_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOF_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40021400_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOF_LABEL DT_ST_STM32_GPIO_40021400_LABEL
#define DT_GPIO_STM32_GPIOF_SIZE DT_ST_STM32_GPIO_40021400_SIZE
#define DT_GPIO_STM32_GPIOF_CLOCK_BITS DT_ST_STM32_GPIO_40021400_CLOCK_BITS
#define DT_GPIO_STM32_GPIOF_CLOCK_BUS DT_ST_STM32_GPIO_40021400_CLOCK_BUS
#define DT_GPIO_STM32_GPIOG_BASE_ADDRESS DT_ST_STM32_GPIO_40021800_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOG_CLOCK_BITS_0 DT_ST_STM32_GPIO_40021800_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOG_CLOCK_BUS_0 DT_ST_STM32_GPIO_40021800_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOG_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40021800_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOG_LABEL DT_ST_STM32_GPIO_40021800_LABEL
#define DT_GPIO_STM32_GPIOG_SIZE DT_ST_STM32_GPIO_40021800_SIZE
#define DT_GPIO_STM32_GPIOG_CLOCK_BITS DT_ST_STM32_GPIO_40021800_CLOCK_BITS
#define DT_GPIO_STM32_GPIOG_CLOCK_BUS DT_ST_STM32_GPIO_40021800_CLOCK_BUS
#define DT_GPIO_STM32_GPIOH_BASE_ADDRESS DT_ST_STM32_GPIO_40021C00_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOH_CLOCK_BITS_0 DT_ST_STM32_GPIO_40021C00_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOH_CLOCK_BUS_0 DT_ST_STM32_GPIO_40021C00_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOH_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40021C00_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOH_LABEL DT_ST_STM32_GPIO_40021C00_LABEL
#define DT_GPIO_STM32_GPIOH_SIZE DT_ST_STM32_GPIO_40021C00_SIZE
#define DT_GPIO_STM32_GPIOH_CLOCK_BITS DT_ST_STM32_GPIO_40021C00_CLOCK_BITS
#define DT_GPIO_STM32_GPIOH_CLOCK_BUS DT_ST_STM32_GPIO_40021C00_CLOCK_BUS
#define DT_GPIO_STM32_GPIOI_BASE_ADDRESS DT_ST_STM32_GPIO_40022000_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOI_CLOCK_BITS_0 DT_ST_STM32_GPIO_40022000_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOI_CLOCK_BUS_0 DT_ST_STM32_GPIO_40022000_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOI_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40022000_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOI_LABEL DT_ST_STM32_GPIO_40022000_LABEL
#define DT_GPIO_STM32_GPIOI_SIZE DT_ST_STM32_GPIO_40022000_SIZE
#define DT_GPIO_STM32_GPIOI_CLOCK_BITS DT_ST_STM32_GPIO_40022000_CLOCK_BITS
#define DT_GPIO_STM32_GPIOI_CLOCK_BUS DT_ST_STM32_GPIO_40022000_CLOCK_BUS
#define DT_GPIO_STM32_GPIOJ_BASE_ADDRESS DT_ST_STM32_GPIO_40022400_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOJ_CLOCK_BITS_0 DT_ST_STM32_GPIO_40022400_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOJ_CLOCK_BUS_0 DT_ST_STM32_GPIO_40022400_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOJ_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40022400_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOJ_LABEL DT_ST_STM32_GPIO_40022400_LABEL
#define DT_GPIO_STM32_GPIOJ_SIZE DT_ST_STM32_GPIO_40022400_SIZE
#define DT_GPIO_STM32_GPIOJ_CLOCK_BITS DT_ST_STM32_GPIO_40022400_CLOCK_BITS
#define DT_GPIO_STM32_GPIOJ_CLOCK_BUS DT_ST_STM32_GPIO_40022400_CLOCK_BUS
#define DT_GPIO_STM32_GPIOK_BASE_ADDRESS DT_ST_STM32_GPIO_40022800_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOK_CLOCK_BITS_0 DT_ST_STM32_GPIO_40022800_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOK_CLOCK_BUS_0 DT_ST_STM32_GPIO_40022800_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOK_CLOCK_CONTROLLER DT_ST_STM32_GPIO_40022800_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOK_LABEL DT_ST_STM32_GPIO_40022800_LABEL
#define DT_GPIO_STM32_GPIOK_SIZE DT_ST_STM32_GPIO_40022800_SIZE
#define DT_GPIO_STM32_GPIOK_CLOCK_BITS DT_ST_STM32_GPIO_40022800_CLOCK_BITS
#define DT_GPIO_STM32_GPIOK_CLOCK_BUS DT_ST_STM32_GPIO_40022800_CLOCK_BUS
#define DT_UART_STM32_USART_1_BASE_ADDRESS DT_ST_STM32_USART_40011000_BASE_ADDRESS
#define DT_UART_STM32_USART_1_BAUD_RATE DT_ST_STM32_USART_40011000_CURRENT_SPEED
#define DT_UART_STM32_USART_1_IRQ_PRI DT_ST_STM32_USART_40011000_IRQ_0_PRIORITY
#define DT_UART_STM32_USART_1_NAME DT_ST_STM32_USART_40011000_LABEL
#define DT_USART_1_IRQ DT_ST_STM32_USART_40011000_IRQ_0
#define DT_UART_STM32_USART_1_CLOCK_BITS DT_ST_STM32_USART_40011000_CLOCK_BITS
#define DT_UART_STM32_USART_1_CLOCK_BUS DT_ST_STM32_USART_40011000_CLOCK_BUS
#define DT_UART_STM32_USART_1_HW_FLOW_CONTROL DT_ST_STM32_USART_40011000_HW_FLOW_CONTROL
#define DT_UART_STM32_USART_2_BASE_ADDRESS DT_ST_STM32_USART_40004400_BASE_ADDRESS
#define DT_UART_STM32_USART_2_BAUD_RATE DT_ST_STM32_USART_40004400_CURRENT_SPEED
#define DT_UART_STM32_USART_2_IRQ_PRI DT_ST_STM32_USART_40004400_IRQ_0_PRIORITY
#define DT_UART_STM32_USART_2_NAME DT_ST_STM32_USART_40004400_LABEL
#define DT_USART_2_IRQ DT_ST_STM32_USART_40004400_IRQ_0
#define DT_UART_STM32_USART_2_CLOCK_BITS DT_ST_STM32_USART_40004400_CLOCK_BITS
#define DT_UART_STM32_USART_2_CLOCK_BUS DT_ST_STM32_USART_40004400_CLOCK_BUS
#define DT_UART_STM32_USART_2_HW_FLOW_CONTROL DT_ST_STM32_USART_40004400_HW_FLOW_CONTROL
#define DT_UART_STM32_USART_3_BASE_ADDRESS DT_ST_STM32_USART_40004800_BASE_ADDRESS
#define DT_UART_STM32_USART_3_BAUD_RATE DT_ST_STM32_USART_40004800_CURRENT_SPEED
#define DT_UART_STM32_USART_3_IRQ_PRI DT_ST_STM32_USART_40004800_IRQ_0_PRIORITY
#define DT_UART_STM32_USART_3_NAME DT_ST_STM32_USART_40004800_LABEL
#define DT_USART_3_IRQ DT_ST_STM32_USART_40004800_IRQ_0
#define DT_UART_STM32_USART_3_CLOCK_BITS DT_ST_STM32_USART_40004800_CLOCK_BITS
#define DT_UART_STM32_USART_3_CLOCK_BUS DT_ST_STM32_USART_40004800_CLOCK_BUS
#define DT_UART_STM32_USART_3_HW_FLOW_CONTROL DT_ST_STM32_USART_40004800_HW_FLOW_CONTROL
#define DT_UART_STM32_UART_4_BASE_ADDRESS DT_ST_STM32_UART_40004C00_BASE_ADDRESS
#define DT_UART_STM32_UART_4_BAUD_RATE DT_ST_STM32_UART_40004C00_CURRENT_SPEED
#define DT_UART_STM32_UART_4_IRQ_PRI DT_ST_STM32_UART_40004C00_IRQ_0_PRIORITY
#define DT_UART_STM32_UART_4_NAME DT_ST_STM32_UART_40004C00_LABEL
#define DT_UART_4_IRQ DT_ST_STM32_UART_40004C00_IRQ_0
#define DT_UART_STM32_UART_4_CLOCK_BITS DT_ST_STM32_UART_40004C00_CLOCK_BITS
#define DT_UART_STM32_UART_4_CLOCK_BUS DT_ST_STM32_UART_40004C00_CLOCK_BUS
#define DT_UART_STM32_UART_4_HW_FLOW_CONTROL DT_ST_STM32_UART_40004C00_HW_FLOW_CONTROL
#define DT_UART_STM32_UART_5_BASE_ADDRESS DT_ST_STM32_UART_40005000_BASE_ADDRESS
#define DT_UART_STM32_UART_5_BAUD_RATE DT_ST_STM32_UART_40005000_CURRENT_SPEED
#define DT_UART_STM32_UART_5_IRQ_PRI DT_ST_STM32_UART_40005000_IRQ_0_PRIORITY
#define DT_UART_STM32_UART_5_NAME DT_ST_STM32_UART_40005000_LABEL
#define DT_UART_5_IRQ DT_ST_STM32_UART_40005000_IRQ_0
#define DT_UART_STM32_UART_5_CLOCK_BITS DT_ST_STM32_UART_40005000_CLOCK_BITS
#define DT_UART_STM32_UART_5_CLOCK_BUS DT_ST_STM32_UART_40005000_CLOCK_BUS
#define DT_UART_STM32_UART_5_HW_FLOW_CONTROL DT_ST_STM32_UART_40005000_HW_FLOW_CONTROL
#define DT_UART_STM32_USART_6_NAME DT_ST_STM32_USART_40011400_LABEL
#define DT_UART_STM32_USART_6_BASE_ADDRESS DT_ST_STM32_USART_40011400_BASE_ADDRESS
#define DT_UART_STM32_USART_6_BAUD_RATE DT_ST_STM32_USART_40011400_CURRENT_SPEED
#define DT_UART_STM32_USART_6_IRQ_PRI DT_ST_STM32_USART_40011400_IRQ_0_PRIORITY
#define DT_USART_6_IRQ DT_ST_STM32_USART_40011400_IRQ_0
#define DT_UART_STM32_USART_6_CLOCK_BITS DT_ST_STM32_USART_40011400_CLOCK_BITS
#define DT_UART_STM32_USART_6_CLOCK_BUS DT_ST_STM32_USART_40011400_CLOCK_BUS
#define DT_UART_STM32_USART_6_HW_FLOW_CONTROL DT_ST_STM32_USART_40011400_HW_FLOW_CONTROL
#define DT_UART_STM32_UART_7_BASE_ADDRESS DT_ST_STM32_UART_40007800_BASE_ADDRESS
#define DT_UART_STM32_UART_7_BAUD_RATE DT_ST_STM32_UART_40007800_CURRENT_SPEED
#define DT_UART_STM32_UART_7_IRQ_PRI DT_ST_STM32_UART_40007800_IRQ_0_PRIORITY
#define DT_UART_STM32_UART_7_NAME DT_ST_STM32_UART_40007800_LABEL
#define DT_UART_7_IRQ DT_ST_STM32_UART_40007800_IRQ_0
#define DT_UART_STM32_UART_7_CLOCK_BITS DT_ST_STM32_UART_40007800_CLOCK_BITS
#define DT_UART_STM32_UART_7_CLOCK_BUS DT_ST_STM32_UART_40007800_CLOCK_BUS
#define DT_UART_STM32_UART_7_HW_FLOW_CONTROL DT_ST_STM32_UART_40007800_HW_FLOW_CONTROL
#define DT_I2C_1_BASE_ADDRESS DT_ST_STM32_I2C_V1_40005400_BASE_ADDRESS
#define DT_I2C_1_EVENT_IRQ_PRI DT_ST_STM32_I2C_V1_40005400_IRQ_EVENT_PRIORITY
#define DT_I2C_1_ERROR_IRQ_PRI DT_ST_STM32_I2C_V1_40005400_IRQ_ERROR_PRIORITY
#define CONFIG_I2C_1_NAME DT_ST_STM32_I2C_V1_40005400_LABEL
#define DT_I2C_1_EVENT_IRQ DT_ST_STM32_I2C_V1_40005400_IRQ_EVENT
#define DT_I2C_1_ERROR_IRQ DT_ST_STM32_I2C_V1_40005400_IRQ_ERROR
#define DT_I2C_1_BITRATE DT_ST_STM32_I2C_V1_40005400_CLOCK_FREQUENCY
#define DT_I2C_1_CLOCK_BITS DT_ST_STM32_I2C_V1_40005400_CLOCK_BITS
#define DT_I2C_1_CLOCK_BUS DT_ST_STM32_I2C_V1_40005400_CLOCK_BUS
#define DT_I2C_2_BASE_ADDRESS DT_ST_STM32_I2C_V1_40005800_BASE_ADDRESS
#define DT_I2C_2_EVENT_IRQ_PRI DT_ST_STM32_I2C_V1_40005800_IRQ_EVENT_PRIORITY
#define DT_I2C_2_ERROR_IRQ_PRI DT_ST_STM32_I2C_V1_40005800_IRQ_ERROR_PRIORITY
#define CONFIG_I2C_2_NAME DT_ST_STM32_I2C_V1_40005800_LABEL
#define DT_I2C_2_EVENT_IRQ DT_ST_STM32_I2C_V1_40005800_IRQ_EVENT
#define DT_I2C_2_ERROR_IRQ DT_ST_STM32_I2C_V1_40005800_IRQ_ERROR
#define DT_I2C_2_BITRATE DT_ST_STM32_I2C_V1_40005800_CLOCK_FREQUENCY
#define DT_I2C_2_CLOCK_BITS DT_ST_STM32_I2C_V1_40005800_CLOCK_BITS
#define DT_I2C_2_CLOCK_BUS DT_ST_STM32_I2C_V1_40005800_CLOCK_BUS
#define DT_I2C_3_BASE_ADDRESS DT_ST_STM32_I2C_V1_40005C00_BASE_ADDRESS
#define DT_I2C_3_EVENT_IRQ_PRI DT_ST_STM32_I2C_V1_40005C00_IRQ_EVENT_PRIORITY
#define DT_I2C_3_ERROR_IRQ_PRI DT_ST_STM32_I2C_V1_40005C00_IRQ_ERROR_PRIORITY
#define CONFIG_I2C_3_NAME DT_ST_STM32_I2C_V1_40005C00_LABEL
#define DT_I2C_3_EVENT_IRQ DT_ST_STM32_I2C_V1_40005C00_IRQ_EVENT
#define DT_I2C_3_ERROR_IRQ DT_ST_STM32_I2C_V1_40005C00_IRQ_ERROR
#define DT_I2C_3_BITRATE DT_ST_STM32_I2C_V1_40005C00_CLOCK_FREQUENCY
#define DT_I2C_3_CLOCK_BITS DT_ST_STM32_I2C_V1_40005C00_CLOCK_BITS
#define DT_I2C_3_CLOCK_BUS DT_ST_STM32_I2C_V1_40005C00_CLOCK_BUS
#define DT_SPI_1_BASE_ADDRESS DT_ST_STM32_SPI_40013000_BASE_ADDRESS
#define DT_SPI_1_IRQ_PRI DT_ST_STM32_SPI_40013000_IRQ_0_PRIORITY
#define DT_SPI_1_NAME DT_ST_STM32_SPI_40013000_LABEL
#define DT_SPI_1_IRQ DT_ST_STM32_SPI_40013000_IRQ_0
#define DT_SPI_1_CLOCK_BITS DT_ST_STM32_SPI_40013000_CLOCK_BITS
#define DT_SPI_1_CLOCK_BUS DT_ST_STM32_SPI_40013000_CLOCK_BUS
#define DT_SPI_2_BASE_ADDRESS DT_ST_STM32_SPI_40003800_BASE_ADDRESS
#define DT_SPI_2_IRQ_PRI DT_ST_STM32_SPI_40003800_IRQ_0_PRIORITY
#define DT_SPI_2_NAME DT_ST_STM32_SPI_40003800_LABEL
#define DT_SPI_2_IRQ DT_ST_STM32_SPI_40003800_IRQ_0
#define DT_SPI_2_CLOCK_BITS DT_ST_STM32_SPI_40003800_CLOCK_BITS
#define DT_SPI_2_CLOCK_BUS DT_ST_STM32_SPI_40003800_CLOCK_BUS
#define DT_SPI_3_BASE_ADDRESS DT_ST_STM32_SPI_40003C00_BASE_ADDRESS
#define DT_SPI_3_IRQ_PRI DT_ST_STM32_SPI_40003C00_IRQ_0_PRIORITY
#define DT_SPI_3_NAME DT_ST_STM32_SPI_40003C00_LABEL
#define DT_SPI_3_IRQ DT_ST_STM32_SPI_40003C00_IRQ_0
#define DT_SPI_3_CLOCK_BITS DT_ST_STM32_SPI_40003C00_CLOCK_BITS
#define DT_SPI_3_CLOCK_BUS DT_ST_STM32_SPI_40003C00_CLOCK_BUS
#define DT_SPI_4_BASE_ADDRESS DT_ST_STM32_SPI_40013400_BASE_ADDRESS
#define DT_SPI_4_IRQ_PRI DT_ST_STM32_SPI_40013400_IRQ_0_PRIORITY
#define DT_SPI_4_NAME DT_ST_STM32_SPI_40013400_LABEL
#define DT_SPI_4_IRQ DT_ST_STM32_SPI_40013400_IRQ_0
#define DT_SPI_4_CLOCK_BITS DT_ST_STM32_SPI_40013400_CLOCK_BITS
#define DT_SPI_4_CLOCK_BUS DT_ST_STM32_SPI_40013400_CLOCK_BUS
#define DT_SPI_5_BASE_ADDRESS DT_ST_STM32_SPI_40015000_BASE_ADDRESS
#define DT_SPI_5_IRQ_PRI DT_ST_STM32_SPI_40015000_IRQ_0_PRIORITY
#define DT_SPI_5_NAME DT_ST_STM32_SPI_40015000_LABEL
#define DT_SPI_5_IRQ DT_ST_STM32_SPI_40015000_IRQ_0
#define DT_SPI_5_CLOCK_BITS DT_ST_STM32_SPI_40015000_CLOCK_BITS
#define DT_SPI_5_CLOCK_BUS DT_ST_STM32_SPI_40015000_CLOCK_BUS
#define DT_SPI_6_BASE_ADDRESS DT_ST_STM32_SPI_40015400_BASE_ADDRESS
#define DT_SPI_6_IRQ_PRI DT_ST_STM32_SPI_40015400_IRQ_0_PRIORITY
#define DT_SPI_6_NAME DT_ST_STM32_SPI_40015400_LABEL
#define DT_SPI_6_IRQ DT_ST_STM32_SPI_40015400_IRQ_0
#define DT_SPI_6_CLOCK_BITS DT_ST_STM32_SPI_40015400_CLOCK_BITS
#define DT_SPI_6_CLOCK_BUS DT_ST_STM32_SPI_40015400_CLOCK_BUS
#define DT_I2S_1_BASE_ADDRESS DT_ST_STM32_I2S_40013000_BASE_ADDRESS
#define DT_I2S_1_IRQ_PRI DT_ST_STM32_I2S_40013000_IRQ_0_PRIORITY
#define DT_I2S_1_NAME DT_ST_STM32_I2S_40013000_LABEL
#define DT_I2S_1_IRQ DT_ST_STM32_I2S_40013000_IRQ_0
#define DT_I2S_1_CLOCK_BITS DT_ST_STM32_I2S_40013000_CLOCK_BITS
#define DT_I2S_1_CLOCK_BUS DT_ST_STM32_I2S_40013000_CLOCK_BUS
#define DT_I2S_2_BASE_ADDRESS DT_ST_STM32_I2S_40003800_BASE_ADDRESS
#define DT_I2S_2_IRQ_PRI DT_ST_STM32_I2S_40003800_IRQ_0_PRIORITY
#define DT_I2S_2_NAME DT_ST_STM32_I2S_40003800_LABEL
#define DT_I2S_2_IRQ DT_ST_STM32_I2S_40003800_IRQ_0
#define DT_I2S_2_CLOCK_BITS DT_ST_STM32_I2S_40003800_CLOCK_BITS
#define DT_I2S_2_CLOCK_BUS DT_ST_STM32_I2S_40003800_CLOCK_BUS
#define DT_I2S_3_BASE_ADDRESS DT_ST_STM32_I2S_40003C00_BASE_ADDRESS
#define DT_I2S_3_IRQ_PRI DT_ST_STM32_I2S_40003C00_IRQ_0_PRIORITY
#define DT_I2S_3_NAME DT_ST_STM32_I2S_40003C00_LABEL
#define DT_I2S_3_IRQ DT_ST_STM32_I2S_40003C00_IRQ_0
#define DT_I2S_3_CLOCK_BITS DT_ST_STM32_I2S_40003C00_CLOCK_BITS
#define DT_I2S_3_CLOCK_BUS DT_ST_STM32_I2S_40003C00_CLOCK_BUS
#define DT_I2S_4_BASE_ADDRESS DT_ST_STM32_I2S_40013400_BASE_ADDRESS
#define DT_I2S_4_IRQ_PRI DT_ST_STM32_I2S_40013400_IRQ_0_PRIORITY
#define DT_I2S_4_NAME DT_ST_STM32_I2S_40013400_LABEL
#define DT_I2S_4_IRQ DT_ST_STM32_I2S_40013400_IRQ_0
#define DT_I2S_4_CLOCK_BITS DT_ST_STM32_I2S_40013400_CLOCK_BITS
#define DT_I2S_4_CLOCK_BUS DT_ST_STM32_I2S_40013400_CLOCK_BUS
#define DT_I2S_5_BASE_ADDRESS DT_ST_STM32_I2S_40015000_BASE_ADDRESS
#define DT_I2S_5_IRQ_PRI DT_ST_STM32_I2S_40015000_IRQ_0_PRIORITY
#define DT_I2S_5_NAME DT_ST_STM32_I2S_40015000_LABEL
#define DT_I2S_5_IRQ DT_ST_STM32_I2S_40015000_IRQ_0
#define DT_I2S_5_CLOCK_BITS DT_ST_STM32_I2S_40015000_CLOCK_BITS
#define DT_I2S_5_CLOCK_BUS DT_ST_STM32_I2S_40015000_CLOCK_BUS
#define DT_I2S_6_BASE_ADDRESS DT_ST_STM32_I2S_40015400_BASE_ADDRESS
#define DT_I2S_6_IRQ_PRI DT_ST_STM32_I2S_40015400_IRQ_0_PRIORITY
#define DT_I2S_6_NAME DT_ST_STM32_I2S_40015400_LABEL
#define DT_I2S_6_IRQ DT_ST_STM32_I2S_40015400_IRQ_0
#define DT_I2S_6_CLOCK_BITS DT_ST_STM32_I2S_40015400_CLOCK_BITS
#define DT_I2S_6_CLOCK_BUS DT_ST_STM32_I2S_40015400_CLOCK_BUS
#define DT_FLASH_DEV_BASE_ADDRESS DT_ST_STM32F4_FLASH_CONTROLLER_40023C00_BASE_ADDRESS
#define DT_FLASH_DEV_NAME DT_ST_STM32F4_FLASH_CONTROLLER_40023C00_LABEL
#ifdef DT_ST_STM32_OTGFS_50000000_BASE_ADDRESS
#define DT_USB_BASE_ADDRESS DT_ST_STM32_OTGFS_50000000_BASE_ADDRESS
#define DT_USB_IRQ DT_ST_STM32_OTGFS_50000000_IRQ_OTGFS
#define DT_USB_IRQ_PRI DT_ST_STM32_OTGFS_50000000_IRQ_OTGFS_PRIORITY
#define DT_USB_NUM_BIDIR_ENDPOINTS DT_ST_STM32_OTGFS_50000000_NUM_BIDIR_ENDPOINTS
#define DT_USB_RAM_SIZE DT_ST_STM32_OTGFS_50000000_RAM_SIZE
#define DT_USB_MAXIMUM_SPEED DT_ST_STM32_OTGFS_50000000_MAXIMUM_SPEED
#define DT_USB_CLOCK_BITS DT_ST_STM32_OTGFS_50000000_CLOCK_BITS
#define DT_USB_CLOCK_BUS DT_ST_STM32_OTGFS_50000000_CLOCK_BUS
#endif /* DT_ST_STM32_OTGFS_50000000_BASE_ADDRESS */
#ifdef DT_ST_STM32_OTGHS_40040000_BASE_ADDRESS
#define DT_USB_HS_BASE_ADDRESS DT_ST_STM32_OTGHS_40040000_BASE_ADDRESS
#define DT_USB_IRQ DT_ST_STM32_OTGHS_40040000_IRQ_OTGHS
#define DT_USB_IRQ_PRI DT_ST_STM32_OTGHS_40040000_IRQ_OTGHS_PRIORITY
#define DT_USB_NUM_BIDIR_ENDPOINTS DT_ST_STM32_OTGHS_40040000_NUM_BIDIR_ENDPOINTS
#define DT_USB_RAM_SIZE DT_ST_STM32_OTGHS_40040000_RAM_SIZE
#define DT_USB_MAXIMUM_SPEED DT_ST_STM32_OTGHS_40040000_MAXIMUM_SPEED
#define DT_USB_CLOCK_BITS DT_ST_STM32_OTGHS_40040000_CLOCK_BITS
#define DT_USB_CLOCK_BUS DT_ST_STM32_OTGHS_40040000_CLOCK_BUS
#endif /* DT_ST_STM32_OTGHS_40040000_BASE_ADDRESS */
#define DT_PWM_STM32_1_DEV_NAME DT_ST_STM32_PWM_40010000_PWM_LABEL
#define DT_PWM_STM32_1_PRESCALER DT_ST_STM32_PWM_40010000_PWM_ST_PRESCALER
#define DT_TIM_STM32_1_BASE_ADDRESS DT_ST_STM32_TIMERS_40010000_BASE_ADDRESS
#define DT_TIM_STM32_1_CLOCK_BITS DT_ST_STM32_TIMERS_40010000_CLOCK_BITS
#define DT_TIM_STM32_1_CLOCK_BUS DT_ST_STM32_TIMERS_40010000_CLOCK_BUS
#define DT_PWM_STM32_2_DEV_NAME DT_ST_STM32_PWM_40000000_PWM_LABEL
#define DT_PWM_STM32_2_PRESCALER DT_ST_STM32_PWM_40000000_PWM_ST_PRESCALER
#define DT_TIM_STM32_2_BASE_ADDRESS DT_ST_STM32_TIMERS_40000000_BASE_ADDRESS
#define DT_TIM_STM32_2_CLOCK_BITS DT_ST_STM32_TIMERS_40000000_CLOCK_BITS
#define DT_TIM_STM32_2_CLOCK_BUS DT_ST_STM32_TIMERS_40000000_CLOCK_BUS
#define DT_PWM_STM32_3_DEV_NAME DT_ST_STM32_PWM_40000400_PWM_LABEL
#define DT_PWM_STM32_3_PRESCALER DT_ST_STM32_PWM_40000400_PWM_ST_PRESCALER
#define DT_TIM_STM32_3_BASE_ADDRESS DT_ST_STM32_TIMERS_40000400_BASE_ADDRESS
#define DT_TIM_STM32_3_CLOCK_BITS DT_ST_STM32_TIMERS_40000400_CLOCK_BITS
#define DT_TIM_STM32_3_CLOCK_BUS DT_ST_STM32_TIMERS_40000400_CLOCK_BUS
#define DT_PWM_STM32_4_DEV_NAME DT_ST_STM32_PWM_40000800_PWM_LABEL
#define DT_PWM_STM32_4_PRESCALER DT_ST_STM32_PWM_40000800_PWM_ST_PRESCALER
#define DT_TIM_STM32_4_BASE_ADDRESS DT_ST_STM32_TIMERS_40000800_BASE_ADDRESS
#define DT_TIM_STM32_4_CLOCK_BITS DT_ST_STM32_TIMERS_40000800_CLOCK_BITS
#define DT_TIM_STM32_4_CLOCK_BUS DT_ST_STM32_TIMERS_40000800_CLOCK_BUS
#define DT_PWM_STM32_5_DEV_NAME DT_ST_STM32_PWM_40000C00_PWM_LABEL
#define DT_PWM_STM32_5_PRESCALER DT_ST_STM32_PWM_40000C00_PWM_ST_PRESCALER
#define DT_TIM_STM32_5_BASE_ADDRESS DT_ST_STM32_TIMERS_40000C00_BASE_ADDRESS
#define DT_TIM_STM32_5_CLOCK_BITS DT_ST_STM32_TIMERS_40000C00_CLOCK_BITS
#define DT_TIM_STM32_5_CLOCK_BUS DT_ST_STM32_TIMERS_40000C00_CLOCK_BUS
#define DT_PWM_STM32_6_DEV_NAME DT_ST_STM32_PWM_40001000_PWM_LABEL
#define DT_PWM_STM32_6_PRESCALER DT_ST_STM32_PWM_40001000_PWM_ST_PRESCALER
#define DT_TIM_STM32_6_BASE_ADDRESS DT_ST_STM32_TIMERS_40001000_BASE_ADDRESS
#define DT_TIM_STM32_6_CLOCK_BITS DT_ST_STM32_TIMERS_40001000_CLOCK_BITS
#define DT_TIM_STM32_6_CLOCK_BUS DT_ST_STM32_TIMERS_40001000_CLOCK_BUS
#define DT_PWM_STM32_7_DEV_NAME DT_ST_STM32_PWM_40001400_PWM_LABEL
#define DT_PWM_STM32_7_PRESCALER DT_ST_STM32_PWM_40001400_PWM_ST_PRESCALER
#define DT_TIM_STM32_7_BASE_ADDRESS DT_ST_STM32_TIMERS_40001400_BASE_ADDRESS
#define DT_TIM_STM32_7_CLOCK_BITS DT_ST_STM32_TIMERS_40001400_CLOCK_BITS
#define DT_TIM_STM32_7_CLOCK_BUS DT_ST_STM32_TIMERS_40001400_CLOCK_BUS
#define DT_PWM_STM32_8_DEV_NAME DT_ST_STM32_PWM_40010400_PWM_LABEL
#define DT_PWM_STM32_8_PRESCALER DT_ST_STM32_PWM_40010400_PWM_ST_PRESCALER
#define DT_TIM_STM32_8_BASE_ADDRESS DT_ST_STM32_TIMERS_40010400_BASE_ADDRESS
#define DT_TIM_STM32_8_CLOCK_BITS DT_ST_STM32_TIMERS_40010400_CLOCK_BITS
#define DT_TIM_STM32_8_CLOCK_BUS DT_ST_STM32_TIMERS_40010400_CLOCK_BUS
#define DT_PWM_STM32_9_DEV_NAME DT_ST_STM32_PWM_40014000_PWM_LABEL
#define DT_PWM_STM32_9_PRESCALER DT_ST_STM32_PWM_40014000_PWM_ST_PRESCALER
#define DT_TIM_STM32_9_BASE_ADDRESS DT_ST_STM32_TIMERS_40014000_BASE_ADDRESS
#define DT_TIM_STM32_9_CLOCK_BITS DT_ST_STM32_TIMERS_40014000_CLOCK_BITS
#define DT_TIM_STM32_9_CLOCK_BUS DT_ST_STM32_TIMERS_40014000_CLOCK_BUS
#define DT_PWM_STM32_10_DEV_NAME DT_ST_STM32_PWM_40014400_PWM_LABEL
#define DT_PWM_STM32_10_PRESCALER DT_ST_STM32_PWM_40014400_PWM_ST_PRESCALER
#define DT_TIM_STM32_10_BASE_ADDRESS DT_ST_STM32_TIMERS_40014400_BASE_ADDRESS
#define DT_TIM_STM32_10_CLOCK_BITS DT_ST_STM32_TIMERS_40014400_CLOCK_BITS
#define DT_TIM_STM32_10_CLOCK_BUS DT_ST_STM32_TIMERS_40014400_CLOCK_BUS
#define DT_PWM_STM32_11_DEV_NAME DT_ST_STM32_PWM_40014800_PWM_LABEL
#define DT_PWM_STM32_11_PRESCALER DT_ST_STM32_PWM_40014800_PWM_ST_PRESCALER
#define DT_TIM_STM32_11_BASE_ADDRESS DT_ST_STM32_TIMERS_40014800_BASE_ADDRESS
#define DT_TIM_STM32_11_CLOCK_BITS DT_ST_STM32_TIMERS_40014800_CLOCK_BITS
#define DT_TIM_STM32_11_CLOCK_BUS DT_ST_STM32_TIMERS_40014800_CLOCK_BUS
#define DT_PWM_STM32_12_DEV_NAME DT_ST_STM32_PWM_40001800_PWM_LABEL
#define DT_PWM_STM32_12_PRESCALER DT_ST_STM32_PWM_40001800_PWM_ST_PRESCALER
#define DT_TIM_STM32_12_BASE_ADDRESS DT_ST_STM32_TIMERS_40001800_BASE_ADDRESS
#define DT_TIM_STM32_12_CLOCK_BITS DT_ST_STM32_TIMERS_40001800_CLOCK_BITS
#define DT_TIM_STM32_12_CLOCK_BUS DT_ST_STM32_TIMERS_40001800_CLOCK_BUS
#define DT_PWM_STM32_13_DEV_NAME DT_ST_STM32_PWM_40001C00_PWM_LABEL
#define DT_PWM_STM32_13_PRESCALER DT_ST_STM32_PWM_40001C00_PWM_ST_PRESCALER
#define DT_TIM_STM32_13_BASE_ADDRESS DT_ST_STM32_TIMERS_40001C00_BASE_ADDRESS
#define DT_TIM_STM32_13_CLOCK_BITS DT_ST_STM32_TIMERS_40001C00_CLOCK_BITS
#define DT_TIM_STM32_13_CLOCK_BUS DT_ST_STM32_TIMERS_40001C00_CLOCK_BUS
#define DT_PWM_STM32_14_DEV_NAME DT_ST_STM32_PWM_40002000_PWM_LABEL
#define DT_PWM_STM32_14_PRESCALER DT_ST_STM32_PWM_40002000_PWM_ST_PRESCALER
#define DT_TIM_STM32_14_BASE_ADDRESS DT_ST_STM32_TIMERS_40002000_BASE_ADDRESS
#define DT_TIM_STM32_14_CLOCK_BITS DT_ST_STM32_TIMERS_40002000_CLOCK_BITS
#define DT_TIM_STM32_14_CLOCK_BUS DT_ST_STM32_TIMERS_40002000_CLOCK_BUS
#define DT_RTC_0_BASE_ADDRESS DT_ST_STM32_RTC_40002800_BASE_ADDRESS
#define DT_RTC_0_IRQ_PRI DT_ST_STM32_RTC_40002800_IRQ_0_PRIORITY
#define DT_RTC_0_IRQ DT_ST_STM32_RTC_40002800_IRQ_0
#define DT_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
#define DT_RTC_0_CLOCK_BITS DT_ST_STM32_RTC_40002800_CLOCK_BITS
#define DT_RTC_0_CLOCK_BUS DT_ST_STM32_RTC_40002800_CLOCK_BUS
#define DT_WDT_0_NAME DT_INST_0_ST_STM32_WATCHDOG_LABEL
#define DT_WWDT_0_BASE_ADDRESS DT_INST_0_ST_STM32_WINDOW_WATCHDOG_BASE_ADDRESS
#define DT_WWDT_0_NAME DT_INST_0_ST_STM32_WINDOW_WATCHDOG_LABEL
#define DT_WWDT_0_IRQ DT_INST_0_ST_STM32_WINDOW_WATCHDOG_IRQ_0
#define DT_WWDT_0_IRQ_PRI DT_INST_0_ST_STM32_WINDOW_WATCHDOG_IRQ_0_PRIORITY
#define DT_WWDT_0_CLOCK_BITS DT_INST_0_ST_STM32_WINDOW_WATCHDOG_CLOCK_BITS
#define DT_WWDT_0_CLOCK_BUS DT_INST_0_ST_STM32_WINDOW_WATCHDOG_CLOCK_BUS
#define DT_ADC_1_BASE_ADDRESS DT_ST_STM32_ADC_40012000_BASE_ADDRESS
#define DT_ADC_1_IRQ DT_ST_STM32_ADC_40012000_IRQ_0
#define DT_ADC_1_IRQ_PRI DT_ST_STM32_ADC_40012000_IRQ_0_PRIORITY
#define DT_ADC_1_NAME DT_ST_STM32_ADC_40012000_LABEL
#define DT_ADC_1_CLOCK_BITS DT_ST_STM32_ADC_40012000_CLOCK_BITS_0
#define DT_ADC_1_CLOCK_BUS DT_ST_STM32_ADC_40012000_CLOCK_BUS_0
/* End of SoC Level DTS fixup file */
|
jrth/zephyr
|
arch/x86/include/intel64/kernel_arch_func.h
|
<gh_stars>0
/*
* Copyright (c) 2019 Intel Corporation
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_FUNC_H_
#define ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_FUNC_H_
#ifndef _ASMLANGUAGE
static ALWAYS_INLINE void
z_set_thread_return_value(struct k_thread *thread, unsigned int value)
{
thread->callee_saved.rax = value;
}
static inline void kernel_arch_init(void)
{
/* nothing */;
}
#endif /* _ASMLANGUAGE */
#endif /* ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_FUNC_H_ */
|
jrth/zephyr
|
include/arch/xtensa/arch.h
|
/*
* Copyright (c) 2016 Cadence Design Systems, Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Xtensa specific kernel interface header
* This header contains the Xtensa specific kernel interface. It is included
* by the generic kernel interface header (include/arch/cpu.h)
*/
#ifndef ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_H_
#define ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_H_
#include <irq.h>
#include <generated_dts_board.h>
#if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__)
#include <arch/common/sys_io.h>
#include <arch/common/ffs.h>
#include <zephyr/types.h>
#include <sw_isr_table.h>
#include <arch/xtensa/irq.h>
#include <xtensa/config/core.h>
#include <arch/common/addr_types.h>
#define STACK_ALIGN 16
/* Xtensa GPRs are often designated by two different names */
#define sys_define_gpr_with_alias(name1, name2) union { u32_t name1, name2; }
#include <arch/xtensa/exc.h>
#ifdef __cplusplus
extern "C" {
#endif
/* internal routine documented in C file, needed by IRQ_CONNECT() macro */
extern void z_irq_priority_set(u32_t irq, u32_t prio, u32_t flags);
/**
* Configure a static interrupt.
*
* All arguments must be computable by the compiler at build time; if this
* can't be done use irq_connect_dynamic() instead.
*
* Internally this function does a few things:
*
* 1. The enum statement has no effect but forces the compiler to only
* accept constant values for the irq_p parameter, very important as the
* numerical IRQ line is used to create a named section.
*
* 2. An instance of _isr_table_entry is created containing the ISR and its
* parameter. If you look at how _sw_isr_table is created, each entry in the
* array is in its own section named by the IRQ line number. What we are doing
* here is to override one of the default entries (which points to the
* spurious IRQ handler) with what was supplied here.
*
* 3. The priority level for the interrupt is configured by a call to
* z_irq_priority_set()
*
* @param irq_p IRQ line number
* @param priority_p Interrupt priority
* @param isr_p Interrupt service routine
* @param isr_param_p ISR parameter
* @param flags_p IRQ options
*
* @return The vector assigned to this interrupt
*/
#define Z_ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
({ \
Z_ISR_DECLARE(irq_p, flags_p, isr_p, isr_param_p); \
irq_p; \
})
/* Spurious interrupt handler. Throws an error if called */
extern void z_irq_spurious(void *unused);
#define XTENSA_ERR_NORET
extern u32_t z_timer_cycle_get_32(void);
#define z_arch_k_cycle_get_32() z_timer_cycle_get_32()
/**
* @brief Explicitly nop operation.
*/
static ALWAYS_INLINE void arch_nop(void)
{
__asm__ volatile("nop");
}
#ifdef __cplusplus
}
#endif
#endif /* !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) */
#endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_H_ */
|
jrth/zephyr
|
arch/x86/include/intel64/kernel_arch_data.h
|
<reponame>jrth/zephyr
/*
* Copyright (c) 2019 Intel Corp.
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_DATA_H_
#define ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_DATA_H_
/*
* Some SSE definitions. Ideally these will ultimately be shared with 32-bit.
*/
#define X86_FXSAVE_SIZE 512 /* size and alignment of buffer ... */
#define X86_FXSAVE_ALIGN 16 /* ... for FXSAVE/FXRSTOR ops */
#define X86_MXCSR_SANE 0x1dc0 /* enable division-by-zero exception */
/*
* A flag for k_thread.thread_state to tell __resume that the thread
* voluntarily switched itself out, so only a portion of the register
* state needs to be restored. See kernel_arch_thread.h and locore.S.
*/
#define _THREAD_SWAPPED BIT(7)
/*
* GDT selectors - these must agree with the GDT layout in locore.S.
*/
#define X86_KERNEL_CS_32 0x08 /* 32-bit kernel code */
#define X86_KERNEL_DS_32 0x10 /* 32-bit kernel data */
#define X86_KERNEL_CS_64 0x18 /* 64-bit kernel code */
#define X86_KERNEL_DS_64 0x20 /* 64-bit kernel data */
#define X86_KERNEL_TSS 0x28 /* 64-bit task state segment */
#endif /* ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_DATA_H_ */
|
jrth/zephyr
|
arch/x86/include/kernel_arch_func.h
|
<reponame>jrth/zephyr<gh_stars>0
/*
* Copyright (c) 2019 Intel Corporation
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_ARCH_X86_INCLUDE_KERNEL_ARCH_FUNC_H_
#define ZEPHYR_ARCH_X86_INCLUDE_KERNEL_ARCH_FUNC_H_
#ifdef CONFIG_X86_LONGMODE
#include <intel64/kernel_arch_func.h>
#else
#include <ia32/kernel_arch_func.h>
#endif
#define z_is_in_isr() (_kernel.nested != 0U)
#endif /* ZEPHYR_ARCH_X86_INCLUDE_KERNEL_ARCH_FUNC_H_ */
|
jrth/zephyr
|
arch/x86/include/offsets_short_arch.h
|
<reponame>jrth/zephyr
/*
* Copyright (c) 2019 Intel Corporation
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_ARCH_X86_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_X86_INCLUDE_OFFSETS_SHORT_ARCH_H_
#ifdef CONFIG_X86_LONGMODE
#include <intel64/offsets_short_arch.h>
#else
#include <ia32/offsets_short_arch.h>
#endif
#endif /* ZEPHYR_ARCH_X86_INCLUDE_OFFSETS_SHORT_ARCH_H_ */
|
jrth/zephyr
|
soc/arm/st_stm32/stm32g0/dts_fixup.h
|
/*
* Copyright (c) 2019 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/
/* SoC level DTS fixup file */
#define DT_NUM_IRQ_PRIO_BITS DT_ARM_V6M_NVIC_E000E100_ARM_NUM_IRQ_PRIORITY_BITS
#define DT_FLASH_DEV_BASE_ADDRESS DT_ST_STM32G0_FLASH_CONTROLLER_40022000_BASE_ADDRESS
#define DT_FLASH_DEV_NAME DT_ST_STM32G0_FLASH_CONTROLLER_40022000_LABEL
#define DT_PWM_STM32_3_DEV_NAME DT_ST_STM32_PWM_40000400_PWM_LABEL
#define DT_PWM_STM32_3_PRESCALER DT_ST_STM32_PWM_40000400_PWM_ST_PRESCALER
/* there is no reference to GPIOE, GPIOG and GPIOH in the dts files */
#define DT_GPIO_STM32_GPIOA_BASE_ADDRESS DT_ST_STM32_GPIO_50000000_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOA_CLOCK_BITS_0 DT_ST_STM32_GPIO_50000000_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOA_CLOCK_BUS_0 DT_ST_STM32_GPIO_50000000_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOA_CLOCK_CONTROLLER DT_ST_STM32_GPIO_50000000_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOA_LABEL DT_ST_STM32_GPIO_50000000_LABEL
#define DT_GPIO_STM32_GPIOA_SIZE DT_ST_STM32_GPIO_50000000_SIZE
#define DT_GPIO_STM32_GPIOA_CLOCK_BITS DT_ST_STM32_GPIO_50000000_CLOCK_BITS
#define DT_GPIO_STM32_GPIOA_CLOCK_BUS DT_ST_STM32_GPIO_50000000_CLOCK_BUS
#define DT_GPIO_STM32_GPIOB_BASE_ADDRESS DT_ST_STM32_GPIO_50000400_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOB_CLOCK_BITS_0 DT_ST_STM32_GPIO_50000400_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOB_CLOCK_BUS_0 DT_ST_STM32_GPIO_50000400_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOB_CLOCK_CONTROLLER DT_ST_STM32_GPIO_50000400_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOB_LABEL DT_ST_STM32_GPIO_50000400_LABEL
#define DT_GPIO_STM32_GPIOB_SIZE DT_ST_STM32_GPIO_50000400_SIZE
#define DT_GPIO_STM32_GPIOB_CLOCK_BITS DT_ST_STM32_GPIO_50000400_CLOCK_BITS
#define DT_GPIO_STM32_GPIOB_CLOCK_BUS DT_ST_STM32_GPIO_50000400_CLOCK_BUS
#define DT_GPIO_STM32_GPIOC_BASE_ADDRESS DT_ST_STM32_GPIO_50000800_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOC_CLOCK_BITS_0 DT_ST_STM32_GPIO_50000800_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOC_CLOCK_BUS_0 DT_ST_STM32_GPIO_50000800_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOC_CLOCK_CONTROLLER DT_ST_STM32_GPIO_50000800_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOC_LABEL DT_ST_STM32_GPIO_50000800_LABEL
#define DT_GPIO_STM32_GPIOC_SIZE DT_ST_STM32_GPIO_50000800_SIZE
#define DT_GPIO_STM32_GPIOC_CLOCK_BITS DT_ST_STM32_GPIO_50000800_CLOCK_BITS
#define DT_GPIO_STM32_GPIOC_CLOCK_BUS DT_ST_STM32_GPIO_50000800_CLOCK_BUS
#define DT_GPIO_STM32_GPIOD_BASE_ADDRESS DT_ST_STM32_GPIO_50000C00_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOD_CLOCK_BITS_0 DT_ST_STM32_GPIO_50000C00_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOD_CLOCK_BUS_0 DT_ST_STM32_GPIO_50000C00_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOD_CLOCK_CONTROLLER DT_ST_STM32_GPIO_50000C00_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOD_LABEL DT_ST_STM32_GPIO_50000C00_LABEL
#define DT_GPIO_STM32_GPIOD_SIZE DT_ST_STM32_GPIO_50000C00_SIZE
#define DT_GPIO_STM32_GPIOD_CLOCK_BITS DT_ST_STM32_GPIO_50000C00_CLOCK_BITS
#define DT_GPIO_STM32_GPIOD_CLOCK_BUS DT_ST_STM32_GPIO_50000C00_CLOCK_BUS
#define DT_GPIO_STM32_GPIOF_BASE_ADDRESS DT_ST_STM32_GPIO_50001400_BASE_ADDRESS
#define DT_GPIO_STM32_GPIOF_CLOCK_BITS_0 DT_ST_STM32_GPIO_50001400_CLOCK_BITS_0
#define DT_GPIO_STM32_GPIOF_CLOCK_BUS_0 DT_ST_STM32_GPIO_50001400_CLOCK_BUS_0
#define DT_GPIO_STM32_GPIOF_CLOCK_CONTROLLER DT_ST_STM32_GPIO_50001400_CLOCK_CONTROLLER
#define DT_GPIO_STM32_GPIOF_LABEL DT_ST_STM32_GPIO_50001400_LABEL
#define DT_GPIO_STM32_GPIOF_SIZE DT_ST_STM32_GPIO_50001400_SIZE
#define DT_GPIO_STM32_GPIOF_CLOCK_BITS DT_ST_STM32_GPIO_50001400_CLOCK_BITS
#define DT_GPIO_STM32_GPIOF_CLOCK_BUS DT_ST_STM32_GPIO_50001400_CLOCK_BUS
/* there is no reference to GPIOE, GPIOG and GPIOH in the dts files */
#define DT_UART_STM32_USART_1_BASE_ADDRESS DT_ST_STM32_USART_40013800_BASE_ADDRESS
#define DT_UART_STM32_USART_1_BAUD_RATE DT_ST_STM32_USART_40013800_CURRENT_SPEED
#define DT_UART_STM32_USART_1_IRQ_PRI DT_ST_STM32_USART_40013800_IRQ_0_PRIORITY
#define DT_UART_STM32_USART_1_NAME DT_ST_STM32_USART_40013800_LABEL
#define DT_USART_1_IRQ DT_ST_STM32_USART_40013800_IRQ_0
#define DT_UART_STM32_USART_1_CLOCK_BITS DT_ST_STM32_USART_40013800_CLOCK_BITS
#define DT_UART_STM32_USART_1_CLOCK_BUS DT_ST_STM32_USART_40013800_CLOCK_BUS
#define DT_UART_STM32_USART_2_BASE_ADDRESS DT_ST_STM32_USART_40004400_BASE_ADDRESS
#define DT_UART_STM32_USART_2_BAUD_RATE DT_ST_STM32_USART_40004400_CURRENT_SPEED
#define DT_UART_STM32_USART_2_IRQ_PRI DT_ST_STM32_USART_40004400_IRQ_0_PRIORITY
#define DT_UART_STM32_USART_2_NAME DT_ST_STM32_USART_40004400_LABEL
#define DT_USART_2_IRQ DT_ST_STM32_USART_40004400_IRQ_0
#define DT_UART_STM32_USART_2_CLOCK_BITS DT_ST_STM32_USART_40004400_CLOCK_BITS
#define DT_UART_STM32_USART_2_CLOCK_BUS DT_ST_STM32_USART_40004400_CLOCK_BUS
#define DT_UART_STM32_USART_2_HW_FLOW_CONTROL DT_ST_STM32_USART_40004400_HW_FLOW_CONTROL
#define DT_WWDT_0_BASE_ADDRESS DT_INST_0_ST_STM32_WINDOW_WATCHDOG_BASE_ADDRESS
#define DT_WWDT_0_NAME DT_INST_0_ST_STM32_WINDOW_WATCHDOG_LABEL
#define DT_WWDT_0_IRQ DT_INST_0_ST_STM32_WINDOW_WATCHDOG_IRQ_0
#define DT_WWDT_0_IRQ_PRI DT_INST_0_ST_STM32_WINDOW_WATCHDOG_IRQ_0_PRIORITY
#define DT_WWDT_0_CLOCK_BITS DT_INST_0_ST_STM32_WINDOW_WATCHDOG_CLOCK_BITS
#define DT_WWDT_0_CLOCK_BUS DT_INST_0_ST_STM32_WINDOW_WATCHDOG_CLOCK_BUS
/* End of SoC Level DTS fixup file */
|
ucsb-cs32-s21/Lab01-STARTER
|
demogData.h
|
<reponame>ucsb-cs32-s21/Lab01-STARTER
#ifndef DEMOG_H
#define DEMOG_H
#include <string>
#include<iostream>
using namespace std;
/*
class to represent county demographic data
from CORGIS
*/
class demogData {
public:
demogData(string inN, string inS, double in65, double in18,
double in5, int totPop14) :
name(inN), state(inS), popOver65(in65), popUnder18(in18),
popUnder5(in5), totalPopulation2014(totPop14) {}
string getName() const { return name; }
friend std::ostream& operator<<(std::ostream &out, const demogData &DD);
private:
const string name;
const string state;
const double popOver65;
const double popUnder18;
const double popUnder5;
const int totalPopulation2014;
};
#endif
|
domantascibas/nmea-rmc-parser
|
src/MessageParser.c
|
<filename>src/MessageParser.c
#include "MessageParser.h"
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define GPRMC_ID_STRING "GPRMC"
uint8_t fieldNumber = 0;
uint8_t fieldOffset = 0;
uint8_t checksum = 0;
bool receivingMessage = false;
bool receivingChecksum = false;
bool isRmcMessage = false;
char field[16];
rmc_t rmcMessage;
void MessageParser_init() {
memset(field, '\0', sizeof(field));
}
void MessageParser_readByte(uint8_t byte, void (*rmc_cb)(rmc_t *rmcData))
{
switch (byte)
{
case '$':
checksum = 0;
fieldNumber = 0;
fieldOffset = 0;
receivingMessage = true;
isRmcMessage = false;
break;
case ',':
checksum ^= byte;
MessageParser_parseMessageField(rmc_cb);
fieldNumber += 1;
fieldOffset = 0;
break;
case '*':
MessageParser_parseMessageField(rmc_cb);
fieldNumber = RMC_CHECKSUM;
fieldOffset = 0;
if (receivingMessage)
{
receivingMessage = false;
receivingChecksum = true;
}
break;
case '\r':
case '\n':
if (receivingChecksum)
{
receivingChecksum = false;
MessageParser_parseMessageField(rmc_cb);
// rmc_cb();
}
break;
default:
field[fieldOffset] = byte;
fieldOffset += 1;
if (receivingMessage)
checksum ^= byte;
break;
}
}
void MessageParser_parseMessageField(void (*rmc_cb)(rmc_t *rmc))
{
uint8_t receivedChecksum;
char tempBuf[4];
float deg;
switch (fieldNumber)
{
case RMC_ID:
if (!strcmp(field, GPRMC_ID_STRING))
isRmcMessage = true;
else
isRmcMessage = false;
break;
case RMC_UTC:
memset(tempBuf, '\0', sizeof(tempBuf));
strncpy(tempBuf, field, 2);
rmcMessage.time.hours = (uint8_t)(atoi(tempBuf));
memset(tempBuf, '\0', sizeof(tempBuf));
memcpy(tempBuf, &field[2], 2);
rmcMessage.time.minutes = (uint8_t)atoi(tempBuf);
memset(tempBuf, '\0', sizeof(tempBuf));
memcpy(tempBuf, &field[4], 2);
rmcMessage.time.seconds = (uint8_t)atoi(tempBuf);
memset(tempBuf, '\0', sizeof(tempBuf));
if (strlen(field) > 9)
memcpy(tempBuf, &field[7], 3);
else
memcpy(tempBuf, &field[7], 2);
rmcMessage.time.milliseconds = (uint16_t)atoi(tempBuf);
break;
case RMC_GPS_STATUS:
if (!strcmp(field, "A"))
{
rmcMessage.status = RMC_DATA_VALID;
}
else
rmcMessage.status = RMC_DATA_INVALID;
break;
case RMC_LATITUDE:
memset(tempBuf, '\0', sizeof(tempBuf));
strncpy(tempBuf, field, 2);
deg = atof(tempBuf);
memset(tempBuf, '\0', sizeof(tempBuf));
memcpy(tempBuf, &field[2], 8);
deg += atof(tempBuf) / 60;
rmcMessage.latitude = (uint32_t)(deg * 1000000);
break;
case RMC_NS:
if (!strcmp(field, "N"))
rmcMessage.ns = RMC_NORTH;
else
rmcMessage.ns = RMC_SOUTH;
break;
case RMC_LONGITUDE:
memset(tempBuf, '\0', sizeof(tempBuf));
strncpy(tempBuf, field, 3);
deg = atof(tempBuf);
memset(tempBuf, '\0', sizeof(tempBuf));
memcpy(tempBuf, &field[3], 8);
deg += atof(tempBuf) / 60;
rmcMessage.longitude = (uint32_t)(deg * 1000000);
break;
case RMC_EW:
if (!strcmp(field, "E"))
rmcMessage.ew = RMC_EAST;
else
rmcMessage.ew = RMC_WEST;
break;
case RMC_SPEED:
rmcMessage.speed = (uint16_t)(atof(field) * 1.852);
break;
case RMC_COURSE_OVER_GROUND:
rmcMessage.course = (uint16_t)(atoi(field));
break;
case RMC_DATE:
memset(tempBuf, '\0', sizeof(tempBuf));
strncpy(tempBuf, field, 2);
rmcMessage.date.day = (uint8_t)atoi(tempBuf);
memset(tempBuf, '\0', sizeof(tempBuf));
memcpy(tempBuf, &field[2], 2);
rmcMessage.date.month = (uint8_t)atoi(tempBuf);
memset(tempBuf, '\0', sizeof(tempBuf));
memcpy(tempBuf, &field[4], 2);
rmcMessage.date.year = 2000 + (uint16_t)atoi(tempBuf);
break;
case RMC_MAGNETIC_VARIATION:
// not supported, should be blank
break;
case RMC_MAGNETIC_VARIATION_EW:
// not supported, should be blank
break;
case RMC_POSITION_MODE:
// not used
break;
case RMC_NAVIGATION_STATUS:
// not used
break;
case RMC_CHECKSUM:
receivedChecksum = (uint8_t)strtol(field, NULL, 16);
if ((receivedChecksum == checksum) && isRmcMessage)
{
rmc_cb(&rmcMessage);
}
break;
}
memset(field, '\0', sizeof(field));
}
|
domantascibas/nmea-rmc-parser
|
src/MessageParser.h
|
<reponame>domantascibas/nmea-rmc-parser
#ifndef _MESSAGE_PARSER_H
#define _MESSAGE_PARSER_H
#include <stdint.h>
/**
* @brief Data status indicator
*/
typedef enum {
RMC_DATA_INVALID,
RMC_DATA_VALID
} rmc_status_t;
/**
* @brief North/South indicator
*/
typedef enum {
RMC_NORTH,
RMC_SOUTH
} rmc_ns_t;
/**
* @brief East/West indicator
*/
typedef enum {
RMC_EAST,
RMC_WEST
} rmc_ew_t;
/**
* @brief Time
*/
typedef struct
{
uint8_t hours; //!< 0-23
uint8_t minutes; //!< 0-59
uint8_t seconds; //!< 0-59
uint16_t milliseconds; //!< 0-999
} rmc_time_t;
/**
* @brief Date
*/
typedef struct
{
uint8_t day; //!< 1-31
uint8_t month; //!< 1-12
uint16_t year; //!< 2000-2999
} rmc_date_t;
/**
* @brief RMC packet data
*/
typedef struct
{
rmc_time_t time;
rmc_status_t status;
uint32_t latitude; //!< Latitude in decimal degrees multiplied by 1 000 000
rmc_ns_t ns;
uint32_t longitude; //!< Longitude in decimal degrees multiplied by 1 000 000
rmc_ew_t ew;
uint16_t speed; //!< Speed in km/h
uint16_t course; //!< Course in degrees
rmc_date_t date;
} rmc_t;
typedef enum {
RMC_ID,
RMC_UTC,
RMC_GPS_STATUS,
RMC_LATITUDE,
RMC_NS,
RMC_LONGITUDE,
RMC_EW,
RMC_SPEED,
RMC_COURSE_OVER_GROUND,
RMC_DATE,
RMC_MAGNETIC_VARIATION,
RMC_MAGNETIC_VARIATION_EW,
RMC_POSITION_MODE,
RMC_NAVIGATION_STATUS,
RMC_CHECKSUM
} rmc_field_t;
#ifdef __cplusplus
extern "C" {
#endif
void MessageParser_init(void);
void MessageParser_readByte(uint8_t, void (*rmc_cb)(rmc_t *));
void MessageParser_parseMessageField(void (*rmc_cb)(rmc_t *));
#ifdef __cplusplus
}
#endif
#endif
|
roscopeco/Xosera
|
xosera_m68k_api/xosera_regs.h
|
/*
* vim: set et ts=4 sw=4
*------------------------------------------------------------
* ___ ___ _
* ___ ___ ___ ___ ___ _____| _| . | |_
* | _| . |_ -| _| . | | | . | . | '_|
* |_| |___|___|___|___|_____|_|_|_|___|___|_,_|
* |_____|
* ------------------------------------------------------------
* Copyright (c) 2021 Xark
* MIT License
*
* Xosera low-level C API to read/write Xosera registers
* ------------------------------------------------------------
*/
#include <stddef.h>
#include <stdint.h>
// NOTE: Since Xosera is using a 6800-style 8-bit bus, it uses only data lines 8-15 of each 16-bit word (i.e., only the
// upper byte of each word) this makes the size of its register map in memory appear doubled and is the reason for
// the pad bytes in the struct below. Byte access is fine but for word or long access to this struct, the MOVEP
// 680x0 instruction should be used (it was designed for this purpose). The xv-set* and xv_get* macros below make
// it easy.
typedef struct _xreg
{
union
{
struct
{
volatile uint8_t h;
volatile uint8_t _h_pad;
volatile uint8_t l;
volatile uint8_t _l_pad;
} b;
const volatile uint16_t w; // NOTE: For use as offset only with xv_setw (and MOVEP.W opcode)
const volatile uint32_t l; // NOTE: For use as offset only with xv_setl (and MOVEP.L opcode)
};
} xreg_t;
// C preprocessor "stringify" to embed #define into inline asm string
#define XV_STR(s) #s
#define XVR_XSTR(s) XV_STR(s)
// Xosera primary register map (See https://github.com/XarkLabs/Xosera/blob/develop/REFERENCE.md)
#define XVR_aux_addr 0x00 // address for AUX read/write via AUX_DATA (see below)
#define XVR_const_val 0x04 // set constant value (e.g. for VRAM fill) TODO
#define XVR_rd_addr 0x08 // set read address for reading from VRAM via DATA/DATA_2
#define XVR_wr_addr 0x0C // set write address for writing to VRAM
#define XVR_data 0x10 // read/write VRAM word at RD/WR_ADDR then add RD/WR_INC
#define XVR_data_2 0x14 // 2nd DATA (to allow for 32-bit read/write to VRAM)
#define XVR_aux_data 0x18 // read/write AUX word at AUX_ADDR
#define XVR_count 0x1C // write blitter count and start operation or read blitter status TODO
#define XVR_rd_inc 0x20 // RD_ADDR increment per word read
#define XVR_wr_inc 0x24 // WR_ADDR increment per word write
#define XVR_wr_mod 0x28 // WR_ADDR increment every `WIDTH` words read (in 2D mode) TODO
#define XVR_rd_mod 0x2C // RD_ADDR increment every `WIDTH` words read (in 2D mode) TODO
#define XVR_width 0x30 // width in words for 2D rectangular blit
#define XVR_blit_ctrl 0x34 // set blitter and other options (reconfigure mode)
#define XVR_unused_e 0x38 // T.B.D. TODO
#define XVR_unused_f 0x3C // T.B.D. TODO
// AUX memory areas
#define XV_AUX_VIDREG 0x0000 // 0x0000-0x000F 16 word video registers (see below)
#define XV_AUX_FONTMEM 0x4000 // 0x4000-0x5FFF 4K words of font memory
#define XV_AUX_COLORMEM 0x8000 // 0x8000-0x80FF 256 word color lookup table (0xXRGB)
#define XV_AUX_AUDMEM 0xC000 // 0xC000-0x??? TODO (audio registers)
// Xosera AUX video registers
#define XVA_dispstart 0x0
#define XVA_dispwidth 0x1
#define XVA_scrollxy 0x2
#define XVA_fontctrl 0x3
#define XVA_gfxctrl 0x4
#define XVA_linestart 0x5
#define XVA_lineintr 0x6
#define XVA_unused_7 0x7
#define XVA_vidwidth 0x8
#define XVA_vidheight 0x9
#define XVA_features 0xA
#define XVA_scanline 0xB
#define XVA_githash_h 0xC
#define XVA_githash_l 0xD
#define XVA_unused_e 0xE
#define XVA_unused_f 0xF
// Xosera register base ptr
extern volatile xreg_t * const xosera_ptr;
// set high byte of xosera_reg xr to 8-bit byte bh
#define xv_setbh(xr, bh) (xosera_ptr[XVR_##xr >> 2].b.h = (bh))
// set low byte of xosera_reg xr to 8-bit byte bl
#define xv_setbl(xr, bl) (xosera_ptr[XVR_##xr >> 2].b.l = (bl))
// set xosera_reg xr to 16-bit word wv
#define xv_setw(xr, wv) \
__asm__ __volatile__("movep.w %[src]," XVR_XSTR(XVR_##xr) "(%[ptr])" \
: \
: [src] "d"((uint16_t)(wv)), [ptr] "a"(xosera_ptr) \
:)
// set xosera_reg xr to 32-bit long lv
#define xv_setl(xr, lv) \
__asm__ __volatile__("movep.l %[src]," XVR_XSTR(XVR_##xr) "(%[ptr])" \
: \
: [src] "d"((uint32_t)(lv)), [ptr] "a"(xosera_ptr) \
:)
// set AUX address to 16-bit word wv
#define xv_aux_setw(xa, wv) \
__asm__ __volatile__("movep.w %[rxa]," XVR_XSTR(XVR_aux_addr) "(%[ptr]) ; " \
"movep.w %[src]," XVR_XSTR(XVR_aux_data) "(%[ptr])" : : [rxa] "d"((xa)), [src] "d"((uint16_t)(wv)), [ptr] "a"(xosera_ptr) :)
// set xosera_aux_reg xar to 16-bit word wv
#define xv_reg_setw(xar, wv) \
__asm__ __volatile__("movep.w %[rxa]," XVR_XSTR(XVR_aux_addr) "(%[ptr]) ; " \
"movep.w %[src]," XVR_XSTR(XVR_aux_data) "(%[ptr])" : : [rxa] "d"((XVA_##xar)), [src] "d"((uint16_t)(wv)), [ptr] "a" (xosera_ptr) :)
// NOTE: Uses clang and gcc supported extension (statement expression), so we must slightly lower shields...
#pragma GCC diagnostic ignored "-Wpedantic" // Yes, I'm slightly cheating (but ugly to have to pass in "return
// variable" - and this is the "low level" API, remember)
// return high byte from xosera_reg xr
#define xv_getbh(xr) (xosera_ptr[XVR_##xr >> 2].b.h)
// return low byte from xosera_reg xr
#define xv_getbl(xr) (xosera_ptr[XVR_##xr >> 2].b.l)
// return 16-bit word from xosera_reg xr
#define xv_getw(xr) \
({ \
uint16_t w; \
__asm__ __volatile__("movep.w " XVR_XSTR(XVR_##xr) "(%[ptr]),%[dst]" \
: [dst] "=d"(w) \
: [ptr] "a"(xosera_ptr) \
:); \
w; \
})
// return 32-bit word from xosera_reg xr and xr+1
#define xv_getl(xr) \
({ \
uint32_t l; \
__asm__ __volatile__("movep.l " XVR_XSTR(XVR_##xr) "(%[ptr]),%[dst]" \
: [dst] "=d"(l) \
: [ptr] "a"(xosera_ptr) \
:); \
l; \
})
// return high byte from AUX address xa
#define xv_aux_getbh(xa) (xv_setw(aux_addr, xa), xosera_ptr[XVR_aux_data >> 2].b.h)
// return low byte from AUX address xa
#define xv_aux_getbl(xa) (xv_setw(aux_addr, xa), xosera_ptr[XVR_aux_data >> 2].b.l)
// return 16-bit word from AUX address xa
#define xv_aux_getw(xa) \
({ \
uint16_t w; \
xv_setw(aux_addr, xa); \
__asm__ __volatile__("movep.w " XVR_XSTR(XVR_aux_data) "(%[ptr]),%[dst]" \
: [dst] "=d"(w) \
: [ptr] "a"(xosera_ptr) \
:); \
w; \
})
// return high byte from xosera_aux_reg xr
#define xv_reg_getbh(xar) xv_aux_getbh(XVA_##xar)
// return low byte from xosera_aux_reg xr
#define xv_reg_getbl(xar) xv_aux_getbl(XVA_##xar)
// return 16-bit word from xosera_aux_reg xr
#define xv_reg_getw(xar) xv_aux_getw(XVA_##xar)
|
roscopeco/Xosera
|
xosera_tester_fast/ST_8x8w.h
|
// Generated by: image_to_mem -i -16 -w -c /Users/kenj/Downloads/Atari_ST_character_set_8x8.png ST_8x8w.h
#include <avr/pgmspace.h>
#include <stdint.h>
const PROGMEM uint16_t ST_8x8w[256 * 4] = {
// 0x00 '\x00'
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
// 0x01 '\x01'
0b0001100000111100,
0b0110011011000011,
0b1110011100100100,
0b0010010000111100,
// 0x02 '\x02'
0b0011110000100100,
0b0010010011100111,
0b1100001101100110,
0b0011110000011000,
// 0x03 '\x03'
0b0001100000011100,
0b1111011010000011,
0b1000001111110110,
0b0001110000011000,
// 0x04 '\x04'
0b0001100000111000,
0b0110111111000001,
0b1100000101101111,
0b0011100000011000,
// 0x05 '\x05'
0b0011110010011001,
0b1100001111100111,
0b1100001110011001,
0b0011110000000000,
// 0x06 '\x06'
0b1111111111111111,
0b1111111011111100,
0b1111100111110011,
0b1110011100000000,
// 0x07 '\x07'
0b1110011111000011,
0b1001100100111100,
0b1001100111000011,
0b1110011100000000,
// 0x08 '\x08'
0b0000000100000011,
0b0000011010001100,
0b1101100001110000,
0b0010000000000000,
// 0x09 '\x09'
0b0111111011000011,
0b1101001111010011,
0b1101101111000011,
0b1100001101111110,
// 0x0a '\x0a'
0b0001100000111100,
0b0011110000111100,
0b0111111000010000,
0b0011100000010000,
// 0x0b '\x0b'
0b0001100000011100,
0b0001011000010000,
0b0001000001110000,
0b1111000001100000,
// 0x0c '\x0c'
0b1111000011000000,
0b1111111011011000,
0b1101111000011000,
0b0001100000000000,
// 0x0d '\x0d'
0b1111000011000000,
0b1101111111011011,
0b1111111100011110,
0b0001101100000000,
// 0x0e '\x0e'
0b0000010100000101,
0b0000010100001101,
0b0000110100011001,
0b0111100101110001,
// 0x0f '\x0f'
0b1010000010100000,
0b1010000010110000,
0b1011000010011000,
0b1001111010001110,
// 0x10 '\x10'
0b0111110011000110,
0b1100011000000000,
0b1100011011000110,
0b0111110000000000,
// 0x11 '\x11'
0b0000011000000110,
0b0000011000000000,
0b0000011000000110,
0b0000011000000000,
// 0x12 '\x12'
0b0111110000000110,
0b0000011001111100,
0b1100000011000000,
0b0111110000000000,
// 0x13 '\x13'
0b0111110000000110,
0b0000011001111100,
0b0000011000000110,
0b0111110000000000,
// 0x14 '\x14'
0b1100011011000110,
0b1100011001111100,
0b0000011000000110,
0b0000011000000000,
// 0x15 '\x15'
0b0111110011000000,
0b1100000001111100,
0b0000011000000110,
0b0111110000000000,
// 0x16 '\x16'
0b0111110011000000,
0b1100000001111100,
0b1100011011000110,
0b0111110000000000,
// 0x17 '\x17'
0b0111110000000110,
0b0000011000000000,
0b0000011000000110,
0b0000011000000000,
// 0x18 '\x18'
0b0111110011000110,
0b1100011001111100,
0b1100011011000110,
0b0111110000000000,
// 0x19 '\x19'
0b0111110011000110,
0b1100011001111100,
0b0000011000000110,
0b0111110000000000,
// 0x1a '\x1a'
0b0000000000000000,
0b0011110000000110,
0b0111111001100110,
0b0011110000000000,
// 0x1b '\x1b'
0b0111100001100000,
0b0111100001100000,
0b0111111000011000,
0b0001111000000000,
// 0x1c '\x1c'
0b0000011100001111,
0b0001111100011000,
0b0001100000010000,
0b0001111000010111,
// 0x1d '\x1d'
0b1111000011111000,
0b1110110000000100,
0b0000010000000100,
0b0011110001010100,
// 0x1e '\x1e'
0b0001000100001011,
0b0000110100000110,
0b0000011100101110,
0b0011100100111000,
// 0x1f '\x1f'
0b0000010000101000,
0b1101100000101000,
0b1101000000010000,
0b1110000000000000,
// 0x20 ' '
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
// 0x21 '!'
0b0001100000011000,
0b0001100000011000,
0b0001100000000000,
0b0001100000000000,
// 0x22 '"'
0b0110011001100110,
0b0110011000000000,
0b0000000000000000,
0b0000000000000000,
// 0x23 '#'
0b0000000001101100,
0b1111111001101100,
0b0110110011111110,
0b0110110000000000,
// 0x24 '$'
0b0001100000111110,
0b0110000000111100,
0b0000011001111100,
0b0001100000000000,
// 0x25 '%'
0b0000000001100110,
0b0110110000011000,
0b0011000001100110,
0b0100011000000000,
// 0x26 '&'
0b0011100001101100,
0b0011100001110000,
0b1101111011001100,
0b0111011000000000,
// 0x27 '''
0b0001100000011000,
0b0001100000000000,
0b0000000000000000,
0b0000000000000000,
// 0x28 '('
0b0000111000011100,
0b0001100000011000,
0b0001100000011100,
0b0000111000000000,
// 0x29 ')'
0b0111000000111000,
0b0001100000011000,
0b0001100000111000,
0b0111000000000000,
// 0x2a '*'
0b0000000001100110,
0b0011110011111111,
0b0011110001100110,
0b0000000000000000,
// 0x2b '+'
0b0000000000011000,
0b0001100001111110,
0b0001100000011000,
0b0000000000000000,
// 0x2c ','
0b0000000000000000,
0b0000000000000000,
0b0000000000110000,
0b0011000001100000,
// 0x2d '-'
0b0000000000000000,
0b0000000001111110,
0b0000000000000000,
0b0000000000000000,
// 0x2e '.'
0b0000000000000000,
0b0000000000000000,
0b0000000000011000,
0b0001100000000000,
// 0x2f '/'
0b0000001000000110,
0b0000110000011000,
0b0011000001100000,
0b0100000000000000,
// 0x30 '0'
0b0011110001100110,
0b0110111001110110,
0b0110011001100110,
0b0011110000000000,
// 0x31 '1'
0b0001100000111000,
0b0001100000011000,
0b0001100000011000,
0b0111111000000000,
// 0x32 '2'
0b0011110001100110,
0b0000011000001100,
0b0001100000110000,
0b0111111000000000,
// 0x33 '3'
0b0111111000001100,
0b0001100000001100,
0b0000011001100110,
0b0011110000000000,
// 0x34 '4'
0b0000110000011100,
0b0011110001101100,
0b0111111000001100,
0b0000110000000000,
// 0x35 '5'
0b0111111001100000,
0b0111110000000110,
0b0000011001100110,
0b0011110000000000,
// 0x36 '6'
0b0011110001100000,
0b0110000001111100,
0b0110011001100110,
0b0011110000000000,
// 0x37 '7'
0b0111111000000110,
0b0000110000011000,
0b0011000000110000,
0b0011000000000000,
// 0x38 '8'
0b0011110001100110,
0b0110011000111100,
0b0110011001100110,
0b0011110000000000,
// 0x39 '9'
0b0011110001100110,
0b0110011000111110,
0b0000011000001100,
0b0011100000000000,
// 0x3a ':'
0b0000000000011000,
0b0001100000000000,
0b0001100000011000,
0b0000000000000000,
// 0x3b ';'
0b0000000000011000,
0b0001100000000000,
0b0001100000011000,
0b0011000000000000,
// 0x3c '<'
0b0000011000001100,
0b0001100000110000,
0b0001100000001100,
0b0000011000000000,
// 0x3d '='
0b0000000000000000,
0b0111111000000000,
0b0000000001111110,
0b0000000000000000,
// 0x3e '>'
0b0110000000110000,
0b0001100000001100,
0b0001100000110000,
0b0110000000000000,
// 0x3f '?'
0b0011110001100110,
0b0000011000001100,
0b0001100000000000,
0b0001100000000000,
// 0x40 '@'
0b0011110001100110,
0b0110111001101010,
0b0110111001100000,
0b0011111000000000,
// 0x41 'A'
0b0001100000111100,
0b0110011001100110,
0b0111111001100110,
0b0110011000000000,
// 0x42 'B'
0b0111110001100110,
0b0110011001111100,
0b0110011001100110,
0b0111110000000000,
// 0x43 'C'
0b0011110001100110,
0b0110000001100000,
0b0110000001100110,
0b0011110000000000,
// 0x44 'D'
0b0111100001101100,
0b0110011001100110,
0b0110011001101100,
0b0111100000000000,
// 0x45 'E'
0b0111111001100000,
0b0110000001111100,
0b0110000001100000,
0b0111111000000000,
// 0x46 'F'
0b0111111001100000,
0b0110000001111100,
0b0110000001100000,
0b0110000000000000,
// 0x47 'G'
0b0011111001100000,
0b0110000001101110,
0b0110011001100110,
0b0011111000000000,
// 0x48 'H'
0b0110011001100110,
0b0110011001111110,
0b0110011001100110,
0b0110011000000000,
// 0x49 'I'
0b0011110000011000,
0b0001100000011000,
0b0001100000011000,
0b0011110000000000,
// 0x4a 'J'
0b0000011000000110,
0b0000011000000110,
0b0000011001100110,
0b0011110000000000,
// 0x4b 'K'
0b0110011001101100,
0b0111100001110000,
0b0111100001101100,
0b0110011000000000,
// 0x4c 'L'
0b0110000001100000,
0b0110000001100000,
0b0110000001100000,
0b0111111000000000,
// 0x4d 'M'
0b1100011011101110,
0b1111111011010110,
0b1100011011000110,
0b1100011000000000,
// 0x4e 'N'
0b0110011001110110,
0b0111111001111110,
0b0110111001100110,
0b0110011000000000,
// 0x4f 'O'
0b0011110001100110,
0b0110011001100110,
0b0110011001100110,
0b0011110000000000,
// 0x50 'P'
0b0111110001100110,
0b0110011001111100,
0b0110000001100000,
0b0110000000000000,
// 0x51 'Q'
0b0011110001100110,
0b0110011001100110,
0b0111011001101100,
0b0011011000000000,
// 0x52 'R'
0b0111110001100110,
0b0110011001111100,
0b0110110001100110,
0b0110011000000000,
// 0x53 'S'
0b0011110001100110,
0b0110000000111100,
0b0000011001100110,
0b0011110000000000,
// 0x54 'T'
0b0111111000011000,
0b0001100000011000,
0b0001100000011000,
0b0001100000000000,
// 0x55 'U'
0b0110011001100110,
0b0110011001100110,
0b0110011001100110,
0b0011111000000000,
// 0x56 'V'
0b0110011001100110,
0b0110011001100110,
0b0110011000111100,
0b0001100000000000,
// 0x57 'W'
0b1100011011000110,
0b1100011011010110,
0b1111111011101110,
0b1100011000000000,
// 0x58 'X'
0b0110011001100110,
0b0011110000011000,
0b0011110001100110,
0b0110011000000000,
// 0x59 'Y'
0b0110011001100110,
0b0110011000111100,
0b0001100000011000,
0b0001100000000000,
// 0x5a 'Z'
0b0111111000000110,
0b0000110000011000,
0b0011000001100000,
0b0111111000000000,
// 0x5b '['
0b0001111000011000,
0b0001100000011000,
0b0001100000011000,
0b0001111000000000,
// 0x5c '\'
0b0100000001100000,
0b0011000000011000,
0b0000110000000110,
0b0000001000000000,
// 0x5d ']'
0b0111100000011000,
0b0001100000011000,
0b0001100000011000,
0b0111100000000000,
// 0x5e '^'
0b0001000000111000,
0b0110110011000110,
0b0000000000000000,
0b0000000000000000,
// 0x5f '_'
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b1111111000000000,
// 0x60 '`'
0b0000000011000000,
0b0110000000110000,
0b0000000000000000,
0b0000000000000000,
// 0x61 'a'
0b0000000000000000,
0b0011110000000110,
0b0011111001100110,
0b0011111000000000,
// 0x62 'b'
0b0110000001100000,
0b0111110001100110,
0b0110011001100110,
0b0111110000000000,
// 0x63 'c'
0b0000000000000000,
0b0011110001100000,
0b0110000001100000,
0b0011110000000000,
// 0x64 'd'
0b0000011000000110,
0b0011111001100110,
0b0110011001100110,
0b0011111000000000,
// 0x65 'e'
0b0000000000000000,
0b0011110001100110,
0b0111111001100000,
0b0011110000000000,
// 0x66 'f'
0b0001110000110000,
0b0111110000110000,
0b0011000000110000,
0b0011000000000000,
// 0x67 'g'
0b0000000000000000,
0b0011111001100110,
0b0110011000111110,
0b0000011001111100,
// 0x68 'h'
0b0110000001100000,
0b0111110001100110,
0b0110011001100110,
0b0110011000000000,
// 0x69 'i'
0b0001100000000000,
0b0011100000011000,
0b0001100000011000,
0b0011110000000000,
// 0x6a 'j'
0b0001100000000000,
0b0001100000011000,
0b0001100000011000,
0b0001100001110000,
// 0x6b 'k'
0b0110000001100000,
0b0110011001101100,
0b0111100001101100,
0b0110011000000000,
// 0x6c 'l'
0b0011100000011000,
0b0001100000011000,
0b0001100000011000,
0b0011110000000000,
// 0x6d 'm'
0b0000000000000000,
0b1110110011111110,
0b1101011011000110,
0b1100011000000000,
// 0x6e 'n'
0b0000000000000000,
0b0111110001100110,
0b0110011001100110,
0b0110011000000000,
// 0x6f 'o'
0b0000000000000000,
0b0011110001100110,
0b0110011001100110,
0b0011110000000000,
// 0x70 'p'
0b0000000000000000,
0b0111110001100110,
0b0110011001100110,
0b0111110001100000,
// 0x71 'q'
0b0000000000000000,
0b0011111001100110,
0b0110011001100110,
0b0011111000000110,
// 0x72 'r'
0b0000000000000000,
0b0111110001100110,
0b0110000001100000,
0b0110000000000000,
// 0x73 's'
0b0000000000000000,
0b0011111001100000,
0b0011110000000110,
0b0111110000000000,
// 0x74 't'
0b0000000000011000,
0b0111111000011000,
0b0001100000011000,
0b0000111000000000,
// 0x75 'u'
0b0000000000000000,
0b0110011001100110,
0b0110011001100110,
0b0011111000000000,
// 0x76 'v'
0b0000000000000000,
0b0110011001100110,
0b0110011000111100,
0b0001100000000000,
// 0x77 'w'
0b0000000000000000,
0b1100011011000110,
0b1101011001111100,
0b0110110000000000,
// 0x78 'x'
0b0000000000000000,
0b0110011000111100,
0b0001100000111100,
0b0110011000000000,
// 0x79 'y'
0b0000000000000000,
0b0110011001100110,
0b0110011000111110,
0b0000011001111100,
// 0x7a 'z'
0b0000000000000000,
0b0111111000001100,
0b0001100000110000,
0b0111111000000000,
// 0x7b '{'
0b0000111000011000,
0b0001100000110000,
0b0001100000011000,
0b0000111000000000,
// 0x7c '|'
0b0001100000011000,
0b0001100000011000,
0b0001100000011000,
0b0001100000011000,
// 0x7d '}'
0b0111000000011000,
0b0001100000001100,
0b0001100000011000,
0b0111000000000000,
// 0x7e '~'
0b0000000001100000,
0b1111001010011110,
0b0000110000000000,
0b0000000000000000,
// 0x7f '\x7f'
0b0000000000011000,
0b0001100000110100,
0b0011010001100010,
0b0111111000000000,
// 0x80 '\x80'
0b0000000000111100,
0b0110011001100000,
0b0110011000111100,
0b0000100000111000,
// 0x81 '\x81'
0b0110011000000000,
0b0000000001100110,
0b0110011001100110,
0b0011111000000000,
// 0x82 '\x82'
0b0000110000011000,
0b0000000000111100,
0b0111111001100000,
0b0011110000000000,
// 0x83 '\x83'
0b0001100001100110,
0b0000000000111100,
0b0000011001111110,
0b0011111000000000,
// 0x84 '\x84'
0b0110011000000000,
0b0011110000000110,
0b0011111001100110,
0b0011111000000000,
// 0x85 '\x85'
0b0011000000011000,
0b0000000000111100,
0b0000011001111110,
0b0011111000000000,
// 0x86 '\x86'
0b0001100000011000,
0b0000000000111100,
0b0000011001111110,
0b0011111000000000,
// 0x87 '\x87'
0b0000000000000000,
0b0011110001100000,
0b0110000000111100,
0b0000100000011000,
// 0x88 '\x88'
0b0001100001100110,
0b0000000000111100,
0b0111111001100000,
0b0011110000000000,
// 0x89 '\x89'
0b0110011000000000,
0b0011110001100110,
0b0111111001100000,
0b0011110000000000,
// 0x8a '\x8a'
0b0011000000011000,
0b0000000000111100,
0b0111111001100000,
0b0011110000000000,
// 0x8b '\x8b'
0b0110011000000000,
0b0000000000111000,
0b0001100000011000,
0b0011110000000000,
// 0x8c '\x8c'
0b0001100001100110,
0b0000000000111000,
0b0001100000011000,
0b0011110000000000,
// 0x8d '\x8d'
0b0110000000110000,
0b0000000000111000,
0b0001100000011000,
0b0011110000000000,
// 0x8e '\x8e'
0b0110011000000000,
0b0001100000111100,
0b0110011001111110,
0b0110011000000000,
// 0x8f '\x8f'
0b0001100000000000,
0b0001100000111100,
0b0110011001111110,
0b0110011000000000,
// 0x90 '\x90'
0b0000110000011000,
0b0111111001100000,
0b0111110001100000,
0b0111111000000000,
// 0x91 '\x91'
0b0000000000000000,
0b0111111000011011,
0b0111111111011000,
0b0111111000000000,
// 0x92 '\x92'
0b0011111101111000,
0b1101100011011110,
0b1111100011011000,
0b1101111100000000,
// 0x93 '\x93'
0b0001100001100110,
0b0000000000111100,
0b0110011001100110,
0b0011110000000000,
// 0x94 '\x94'
0b0110011000000000,
0b0000000000111100,
0b0110011001100110,
0b0011110000000000,
// 0x95 '\x95'
0b0011000000011000,
0b0000000000111100,
0b0110011001100110,
0b0011110000000000,
// 0x96 '\x96'
0b0001100001100110,
0b0000000001100110,
0b0110011001100110,
0b0011111000000000,
// 0x97 '\x97'
0b0011000000011000,
0b0000000001100110,
0b0110011001100110,
0b0011111000000000,
// 0x98 '\x98'
0b0110011000000000,
0b0110011001100110,
0b0110011000111110,
0b0000011001111100,
// 0x99 '\x99'
0b0110011000000000,
0b0011110001100110,
0b0110011001100110,
0b0011110000000000,
// 0x9a '\x9a'
0b0110011000000000,
0b0110011001100110,
0b0110011001100110,
0b0011111000000000,
// 0x9b '\x9b'
0b0001100000011000,
0b0011110001100000,
0b0110000000111100,
0b0001100000011000,
// 0x9c '\x9c'
0b0001110000111010,
0b0011000001111100,
0b0011000000110000,
0b0111111000000000,
// 0x9d '\x9d'
0b0110011001100110,
0b0011110000011000,
0b0011110000011000,
0b0001100000000000,
// 0x9e '\x9e'
0b0001110000110110,
0b0110011001111100,
0b0110011001100110,
0b0111110001100000,
// 0x9f '\x9f'
0b0001111000110000,
0b0111110000110000,
0b0011000000110000,
0b0110000000000000,
// 0xa0 '\xa0'
0b0000110000011000,
0b0000000000111100,
0b0000011001111110,
0b0011111000000000,
// 0xa1 '\xa1'
0b0000110000011000,
0b0000000000111000,
0b0001100000011000,
0b0011110000000000,
// 0xa2 '\xa2'
0b0000110000011000,
0b0000000000111100,
0b0110011001100110,
0b0011110000000000,
// 0xa3 '\xa3'
0b0000110000011000,
0b0000000001100110,
0b0110011001100110,
0b0011111000000000,
// 0xa4 '\xa4'
0b0011010001011000,
0b0000000001111100,
0b0110011001100110,
0b0110011000000000,
// 0xa5 '\xa5'
0b0011010001011000,
0b0000000001100110,
0b0111011001101110,
0b0110011000000000,
// 0xa6 '\xa6'
0b0000000000111100,
0b0000011000111110,
0b0110011000111110,
0b0000000000111100,
// 0xa7 '\xa7'
0b0000000000111100,
0b0110011001100110,
0b0110011000111100,
0b0000000000111100,
// 0xa8 '\xa8'
0b0000000000011000,
0b0000000000011000,
0b0011000001100000,
0b0110011000111100,
// 0xa9 '\xa9'
0b0000000000000000,
0b0000000000111110,
0b0011000000110000,
0b0011000000000000,
// 0xaa '\xaa'
0b0000000000000000,
0b0000000001111100,
0b0000110000001100,
0b0000110000000000,
// 0xab '\xab'
0b1100011011001100,
0b1101100000110110,
0b0110101111000011,
0b1000011000001111,
// 0xac '\xac'
0b1100011011001100,
0b1101100000110110,
0b0110111011010110,
0b1001111100000110,
// 0xad '\xad'
0b0000000000011000,
0b0000000000011000,
0b0001100000011000,
0b0001100000011000,
// 0xae '\xae'
0b0001101100110110,
0b0110110011011000,
0b0110110000110110,
0b0001101100000000,
// 0xaf '\xaf'
0b1101100001101100,
0b0011011000011011,
0b0011011001101100,
0b1101100000000000,
// 0xb0 '\xb0'
0b0011010001011000,
0b0000000000111100,
0b0000011001111110,
0b0011111000000000,
// 0xb1 '\xb1'
0b0011010001011000,
0b0000000000111100,
0b0110011001100110,
0b0011110000000000,
// 0xb2 '\xb2'
0b0000001000111100,
0b0110011001101110,
0b0111011001100110,
0b0011110001000000,
// 0xb3 '\xb3'
0b0000000000000010,
0b0011110001101110,
0b0111011001100110,
0b0011110001000000,
// 0xb4 '\xb4'
0b0000000000000000,
0b0111111011011011,
0b1101111111011000,
0b0111111000000000,
// 0xb5 '\xb5'
0b0111111111011000,
0b1101100011011110,
0b1101100011011000,
0b0111111100000000,
// 0xb6 '\xb6'
0b0011000000011000,
0b0000000000011000,
0b0011110001100110,
0b0111111001100110,
// 0xb7 '\xb7'
0b0011010001011000,
0b0000000000011000,
0b0011110001100110,
0b0111111001100110,
// 0xb8 '\xb8'
0b0011010001011000,
0b0011110001100110,
0b0110011001100110,
0b0110011000111100,
// 0xb9 '\xb9'
0b0110011000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
// 0xba '\xba'
0b0000110000011000,
0b0011000000000000,
0b0000000000000000,
0b0000000000000000,
// 0xbb '\xbb'
0b0000000000010000,
0b0011100000010000,
0b0001000000010000,
0b0000000000000000,
// 0xbc '\xbc'
0b0111101011001010,
0b1100101011001010,
0b0111101000001010,
0b0000101000001010,
// 0xbd '\xbd'
0b0111111011000011,
0b1011110110110001,
0b1011000110111101,
0b1100001101111110,
// 0xbe '\xbe'
0b0111111011000011,
0b1011110110100101,
0b1011100110101101,
0b1100001101111110,
// 0xbf '\xbf'
0b1111000101011011,
0b0101111101010101,
0b0101000100000000,
0b0000000000000000,
// 0xc0 '\xc0'
0b0110011000000000,
0b1110011001100110,
0b0110011011110110,
0b0000011000011100,
// 0xc1 '\xc1'
0b1111011001100110,
0b0110011001100110,
0b0110011011110110,
0b0000011000011100,
// 0xc2 '\xc2'
0b0000000001100110,
0b0111011000111100,
0b0110111001100110,
0b0000000000000000,
// 0xc3 '\xc3'
0b0000000001111100,
0b0000110000001100,
0b0000110001111110,
0b0000000000000000,
// 0xc4 '\xc4'
0b0000000000011110,
0b0000011000001110,
0b0001111000110110,
0b0000000000000000,
// 0xc5 '\xc5'
0b0000000001111110,
0b0000110000001100,
0b0000110000001100,
0b0000000000000000,
// 0xc6 '\xc6'
0b0000000001111100,
0b0000011001100110,
0b0110011001100110,
0b0000000000000000,
// 0xc7 '\xc7'
0b0000000000011100,
0b0000110000001100,
0b0000110000001100,
0b0000000000000000,
// 0xc8 '\xc8'
0b0000000000011110,
0b0000110000000110,
0b0000011000000110,
0b0000000000000000,
// 0xc9 '\xc9'
0b0000000001111110,
0b0011011000110110,
0b0011011000110110,
0b0000000000000000,
// 0xca '\xca'
0b0110000001101110,
0b0110011001100110,
0b0110011001111110,
0b0000000000000000,
// 0xcb '\xcb'
0b0000000000111100,
0b0000110000001100,
0b0000000000000000,
0b0000000000000000,
// 0xcc '\xcc'
0b0000000000111110,
0b0000011000000110,
0b0000011000111110,
0b0000000000000000,
// 0xcd '\xcd'
0b0110000001111110,
0b0000011000000110,
0b0000011000001110,
0b0000000000000000,
// 0xce '\xce'
0b0000000001101100,
0b0011111001100110,
0b0110011001101110,
0b0000000000000000,
// 0xcf '\xcf'
0b0000000000011100,
0b0000110000001100,
0b0000110000111100,
0b0000000000000000,
// 0xd0 '\xd0'
0b0000000000111110,
0b0011011000110110,
0b0011011000011100,
0b0000000000000000,
// 0xd1 '\xd1'
0b0000000000110110,
0b0011011000110110,
0b0011011001111110,
0b0000000000000000,
// 0xd2 '\xd2'
0b0000000001111110,
0b0110011001110110,
0b0000011001111110,
0b0000000000000000,
// 0xd3 '\xd3'
0b0000000001100110,
0b0110011000111100,
0b0000111001111110,
0b0000000000000000,
// 0xd4 '\xd4'
0b0000000000111110,
0b0000011000110110,
0b0011011000110100,
0b0011000000000000,
// 0xd5 '\xd5'
0b0000000001111000,
0b0000110000001100,
0b0000110000001100,
0b0000000000000000,
// 0xd6 '\xd6'
0b0000000011010110,
0b1101011011010110,
0b1101011011111110,
0b0000000000000000,
// 0xd7 '\xd7'
0b0000000001111100,
0b0110110001101100,
0b0110110011101100,
0b0000000000000000,
// 0xd8 '\xd8'
0b0000000000011100,
0b0000110000001100,
0b0000110000001100,
0b0000110000000000,
// 0xd9 '\xd9'
0b0000000000111110,
0b0000011000000110,
0b0000011000000110,
0b0000011000000000,
// 0xda '\xda'
0b0000000011111110,
0b0110011001100110,
0b0110011001111110,
0b0000000000000000,
// 0xdb '\xdb'
0b0000000001111110,
0b0110011001110110,
0b0000011000000110,
0b0000011000000000,
// 0xdc '\xdc'
0b0000000000110110,
0b0011011000011100,
0b0000110000001100,
0b0000110000000000,
// 0xdd '\xdd'
0b0000111000011011,
0b0011110001100110,
0b0110011000111100,
0b1101100001110000,
// 0xde '\xde'
0b0000000000010000,
0b0011100001101100,
0b1100011010000010,
0b0000000000000000,
// 0xdf '\xdf'
0b0110011011110111,
0b1001100110011001,
0b1110111101100110,
0b0000000000000000,
// 0xe0 '\xe0'
0b0000000000000000,
0b0111011011011100,
0b1100100011011100,
0b0111011000000000,
// 0xe1 '\xe1'
0b0001110000110110,
0b0110011001111100,
0b0110011001100110,
0b0111110001100000,
// 0xe2 '\xe2'
0b0000000011111110,
0b0110011001100010,
0b0110000001100000,
0b0110000011111000,
// 0xe3 '\xe3'
0b0000000000000000,
0b1111111001101100,
0b0110110001101100,
0b0110110001001000,
// 0xe4 '\xe4'
0b1111111001100110,
0b0011000000011000,
0b0011000001100110,
0b1111111000000000,
// 0xe5 '\xe5'
0b0000000000011110,
0b0011100001101100,
0b0110110001101100,
0b0011100000000000,
// 0xe6 '\xe6'
0b0000000000000000,
0b0110110001101100,
0b0110110001101100,
0b0111111111000000,
// 0xe7 '\xe7'
0b0000000000000000,
0b0111111000011000,
0b0001100000011000,
0b0001100000010000,
// 0xe8 '\xe8'
0b0011110000011000,
0b0011110001100110,
0b0110011000111100,
0b0001100000111100,
// 0xe9 '\xe9'
0b0000000000111100,
0b0110011001111110,
0b0110011001100110,
0b0011110000000000,
// 0xea '\xea'
0b0000000000111100,
0b0110011001100110,
0b0110011000100100,
0b0110011000000000,
// 0xeb '\xeb'
0b0001110000110110,
0b0111100011011100,
0b1100110011101100,
0b0111100000000000,
// 0xec '\xec'
0b0000110000011000,
0b0011100001010100,
0b0101010000111000,
0b0011000001100000,
// 0xed '\xed'
0b0000000000010000,
0b0111110011010110,
0b1101011011010110,
0b0111110000010000,
// 0xee '\xee'
0b0011111001110000,
0b0110000001111110,
0b0110000001110000,
0b0011111000000000,
// 0xef '\xef'
0b0011110001100110,
0b0110011001100110,
0b0110011001100110,
0b0110011000000000,
// 0xf0 '\xf0'
0b0000000001111110,
0b0000000001111110,
0b0000000001111110,
0b0000000000000000,
// 0xf1 '\xf1'
0b0001100000011000,
0b0111111000011000,
0b0001100000000000,
0b0111111000000000,
// 0xf2 '\xf2'
0b0011000000011000,
0b0000110000011000,
0b0011000000000000,
0b0111111000000000,
// 0xf3 '\xf3'
0b0000110000011000,
0b0011000000011000,
0b0000110000000000,
0b0111111000000000,
// 0xf4 '\xf4'
0b0000000000001110,
0b0001101100011011,
0b0001100000011000,
0b0001100000011000,
// 0xf5 '\xf5'
0b0001100000011000,
0b0001100000011000,
0b1101100011011000,
0b0111000000000000,
// 0xf6 '\xf6'
0b0001100000011000,
0b0000000001111110,
0b0000000000011000,
0b0001100000000000,
// 0xf7 '\xf7'
0b0000000000110010,
0b0100110000000000,
0b0011001001001100,
0b0000000000000000,
// 0xf8 '\xf8'
0b0011100001101100,
0b0011100000000000,
0b0000000000000000,
0b0000000000000000,
// 0xf9 '\xf9'
0b0011100001111100,
0b0011100000000000,
0b0000000000000000,
0b0000000000000000,
// 0xfa '\xfa'
0b0000000000000000,
0b0000000000000000,
0b0001100000011000,
0b0000000000000000,
// 0xfb '\xfb'
0b0000000000000000,
0b0000111100011000,
0b1101100001110000,
0b0011000000000000,
// 0xfc '\xfc'
0b0011100001101100,
0b0110110001101100,
0b0110110000000000,
0b0000000000000000,
// 0xfd '\xfd'
0b0011100001101100,
0b0001100000110000,
0b0111110000000000,
0b0000000000000000,
// 0xfe '\xfe'
0b0111100000001100,
0b0011100000001100,
0b0111100000000000,
0b0000000000000000,
// 0xff '\xff'
0b0000000011111110,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
};
|
roscopeco/Xosera
|
xvid_spi/ftdi_spi.h
|
// ftdi_spi.h - header for FTDI SPI routines
//
// vim: set et ts=4 sw=4
//
// Copyright (c) 2020 Xark - https://hackaday.io/Xark
//
// See top-level LICENSE file for license information. (Hint: MIT)
#if !defined(HOST_SPI_H)
#define HOST_SPI_H
#include <ftdi.h>
#include <stdint.h>
// Thanks to https://github.com/YosysHQ/icestorm/tree/master/iceprog
// for a great example of FPGA FTDI code.
// FTDI signals used on iCE40UP5K boards
//
// PIN | UART | PC Dir | Signal | iCEBreaker | UPduino 3.x
// -------+------+--------+--------+------------+----------------
// ADBUS0 | TXD | output | SCK | FLASH_SCK | spi_sck
// ADBUS1 | RXD | output | COPI | FLASH_IO0 | spi_copi
// ADBUS2 | RTS# | input | CIPO | FLASH_IO1 | spi_cipo
// ADBUS3 | CTS# | output | fpgaCS | LEDR_N ** | led_red ***
// ADBUS4 | DTR# | input* |flashCS | FLASH_SSB | spi_ssn
// ADBUS5 | DSR# | n/a* | nc | nc | nc
// ADBUS6 | DCD# | input* | CDONE | configured | configured
// ADBUS7 | RI# | input* | CRESET | FPGA reset | FPGA reset
//
// * = Set to input since not needed for Xosera SPI communication
// ** = Connected on iCEBreaker 1.0e or above (SPI lights red LED)
// *** = With TP11 connected to R pin (via ~300Ohm resistor, SPI lights red LED)
//
// NOTE: Since UPduino has single channel FT232H, serial_rxd and serial_txd
// UART signals are shared with SPI signals spi_sck and spi_cipo.
// FTDI bit definitions to match above
#define SPI_SCK 0x01
#define SPI_COPI 0x02
#define SPI_CIPO 0x04
#define SPI_CS 0x08
#define SPI_OUTPUTS (SPI_SCK | SPI_COPI | SPI_CS)
#define FTDI_VENDOR 0x0403 // USB vendor ID for FTDI
#define FTDI_FT232H 0x6014 // FT232H Hi-Speed Single Channel USB UART/FIFO
#define FTDI_FT2232H 0x6010 // FT2232H Hi-Speed Dual USB UART/FIFO
#define FTDI_FT4232H 0x6011 // FT4232H Hi-Speed Quad USB UART
extern unsigned int chunksize; // set on open to the maximum size that can be sent/received per call
int host_spi_open(); // open FTDI device for FPGA SPI I/O
int host_spi_close(); // close FTDI device
void host_spi_cs(bool cs); // cs = false to select FPGA peripheral
int host_spi_xfer_bytes(size_t num, uint8_t * buffer); // send and receive num bytes over SPI
#endif // HOST_SPI_H
|
roscopeco/Xosera
|
xosera_tester_fast/vga_8x16.h
|
<reponame>roscopeco/Xosera
// Generated by: image_to_mem -c /Users/kenj/Downloads/vga8x12_extra_chars.png vga_8x16.cpp
#include <avr/pgmspace.h>
#include <stdint.h>
const PROGMEM uint8_t vga_8x16[256 * 16] = {
// 0x00 '\x00'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b11111111, // ########
0b00000000, // ........
// 0x01 '\x01'
0b00000000, // ........
0b00000000, // ........
0b01111110, // .######.
0b10000001, // #......#
0b10100101, // #.#..#.#
0b10000001, // #......#
0b10000001, // #......#
0b10111101, // #.####.#
0b10011001, // #..##..#
0b10000001, // #......#
0b10000001, // #......#
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x02 '\x02'
0b00000000, // ........
0b00000000, // ........
0b01111110, // .######.
0b11111111, // ########
0b11011011, // ##.##.##
0b11111111, // ########
0b11111111, // ########
0b11000011, // ##....##
0b11100111, // ###..###
0b11111111, // ########
0b11111111, // ########
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x03 '\x03'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01101100, // .##.##..
0b11111110, // #######.
0b11111110, // #######.
0b11111110, // #######.
0b11111110, // #######.
0b01111100, // .#####..
0b00111000, // ..###...
0b00010000, // ...#....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x04 '\x04'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00010000, // ...#....
0b00111000, // ..###...
0b01111100, // .#####..
0b11111110, // #######.
0b01111100, // .#####..
0b00111000, // ..###...
0b00010000, // ...#....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x05 '\x05'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00111100, // ..####..
0b00111100, // ..####..
0b11100111, // ###..###
0b11100111, // ###..###
0b11100111, // ###..###
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x06 '\x06'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00111100, // ..####..
0b01111110, // .######.
0b11111111, // ########
0b11111111, // ########
0b01111110, // .######.
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x07 '\x07'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00111100, // ..####..
0b00111100, // ..####..
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x08 '\x08'
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11100111, // ###..###
0b11000011, // ##....##
0b11000011, // ##....##
0b11100111, // ###..###
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
// 0x09 '\x09'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00111100, // ..####..
0b01100110, // .##..##.
0b01000010, // .#....#.
0b01000010, // .#....#.
0b01100110, // .##..##.
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x0a '\x0a'
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11000011, // ##....##
0b10011001, // #..##..#
0b10111101, // #.####.#
0b10111101, // #.####.#
0b10011001, // #..##..#
0b11000011, // ##....##
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
// 0x0b '\x0b'
0b00000000, // ........
0b00000000, // ........
0b00011110, // ...####.
0b00001110, // ....###.
0b00011010, // ...##.#.
0b00110010, // ..##..#.
0b01111000, // .####...
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01111000, // .####...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x0c '\x0c'
0b00000000, // ........
0b00000000, // ........
0b00111100, // ..####..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b00111100, // ..####..
0b00011000, // ...##...
0b01111110, // .######.
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x0d '\x0d'
0b00000000, // ........
0b00000000, // ........
0b00111111, // ..######
0b00110011, // ..##..##
0b00111111, // ..######
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b01110000, // .###....
0b11110000, // ####....
0b11100000, // ###.....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x0e '\x0e'
0b00000000, // ........
0b00000000, // ........
0b01111111, // .#######
0b01100011, // .##...##
0b01111111, // .#######
0b01100011, // .##...##
0b01100011, // .##...##
0b01100011, // .##...##
0b01100011, // .##...##
0b01100111, // .##..###
0b11100111, // ###..###
0b11100110, // ###..##.
0b11000000, // ##......
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x0f '\x0f'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b11011011, // ##.##.##
0b00111100, // ..####..
0b11100111, // ###..###
0b00111100, // ..####..
0b11011011, // ##.##.##
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x10 '\x10'
0b00000000, // ........
0b10000000, // #.......
0b11000000, // ##......
0b11100000, // ###.....
0b11110000, // ####....
0b11111000, // #####...
0b11111110, // #######.
0b11111000, // #####...
0b11110000, // ####....
0b11100000, // ###.....
0b11000000, // ##......
0b10000000, // #.......
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x11 '\x11'
0b00000000, // ........
0b00000010, // ......#.
0b00000110, // .....##.
0b00001110, // ....###.
0b00011110, // ...####.
0b00111110, // ..#####.
0b11111110, // #######.
0b00111110, // ..#####.
0b00011110, // ...####.
0b00001110, // ....###.
0b00000110, // .....##.
0b00000010, // ......#.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x12 '\x12'
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00111100, // ..####..
0b01111110, // .######.
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b01111110, // .######.
0b00111100, // ..####..
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x13 '\x13'
0b00000000, // ........
0b00000000, // ........
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b00000000, // ........
0b01100110, // .##..##.
0b01100110, // .##..##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x14 '\x14'
0b00000000, // ........
0b00000000, // ........
0b01111111, // .#######
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b01111011, // .####.##
0b00011011, // ...##.##
0b00011011, // ...##.##
0b00011011, // ...##.##
0b00011011, // ...##.##
0b00011011, // ...##.##
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x15 '\x15'
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b01100000, // .##.....
0b00111000, // ..###...
0b01101100, // .##.##..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01101100, // .##.##..
0b00111000, // ..###...
0b00001100, // ....##..
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x16 '\x16'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b11111110, // #######.
0b11111110, // #######.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x17 '\x17'
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00111100, // ..####..
0b01111110, // .######.
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b01111110, // .######.
0b00111100, // ..####..
0b00011000, // ...##...
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x18 '\x18'
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00111100, // ..####..
0b01111110, // .######.
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x19 '\x19'
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b01111110, // .######.
0b00111100, // ..####..
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x1a '\x1a'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00001100, // ....##..
0b11111110, // #######.
0b00001100, // ....##..
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x1b '\x1b'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00110000, // ..##....
0b01100000, // .##.....
0b11111110, // #######.
0b01100000, // .##.....
0b00110000, // ..##....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x1c '\x1c'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x1d '\x1d'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00100100, // ..#..#..
0b01100110, // .##..##.
0b11111111, // ########
0b01100110, // .##..##.
0b00100100, // ..#..#..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x1e '\x1e'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00010000, // ...#....
0b00111000, // ..###...
0b00111000, // ..###...
0b01111100, // .#####..
0b01111100, // .#####..
0b11111110, // #######.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x1f '\x1f'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b11111110, // #######.
0b01111100, // .#####..
0b01111100, // .#####..
0b00111000, // ..###...
0b00111000, // ..###...
0b00010000, // ...#....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x20 ' '
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x21 '!'
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00111100, // ..####..
0b00111100, // ..####..
0b00111100, // ..####..
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x22 '"'
0b00000000, // ........
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b00100100, // ..#..#..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x23 '#'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01101100, // .##.##..
0b01101100, // .##.##..
0b11111110, // #######.
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b11111110, // #######.
0b01101100, // .##.##..
0b01101100, // .##.##..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x24 '$'
0b00011000, // ...##...
0b00011000, // ...##...
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000010, // ##....#.
0b11000000, // ##......
0b01111100, // .#####..
0b00000110, // .....##.
0b00000110, // .....##.
0b10000110, // #....##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
// 0x25 '%'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11000010, // ##....#.
0b11000110, // ##...##.
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b11000110, // ##...##.
0b10000110, // #....##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x26 '&'
0b00000000, // ........
0b00000000, // ........
0b00111000, // ..###...
0b01101100, // .##.##..
0b01101100, // .##.##..
0b00111000, // ..###...
0b01110110, // .###.##.
0b11011100, // ##.###..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x27 '''
0b00000000, // ........
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b01100000, // .##.....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x28 '('
0b00000000, // ........
0b00000000, // ........
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00011000, // ...##...
0b00001100, // ....##..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x29 ')'
0b00000000, // ........
0b00000000, // ........
0b00110000, // ..##....
0b00011000, // ...##...
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x2a '*'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01100110, // .##..##.
0b00111100, // ..####..
0b11111111, // ########
0b00111100, // ..####..
0b01100110, // .##..##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x2b '+'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b01111110, // .######.
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x2c ','
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00110000, // ..##....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x2d '-'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x2e '.'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x2f '/'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000010, // ......#.
0b00000110, // .....##.
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b11000000, // ##......
0b10000000, // #.......
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x30 '0'
0b00000000, // ........
0b00000000, // ........
0b00111100, // ..####..
0b01100110, // .##..##.
0b11000011, // ##....##
0b11000011, // ##....##
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b11000011, // ##....##
0b11000011, // ##....##
0b01100110, // .##..##.
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x31 '1'
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00111000, // ..###...
0b01111000, // .####...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x32 '2'
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b00000110, // .....##.
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b11000000, // ##......
0b11000110, // ##...##.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x33 '3'
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b00000110, // .....##.
0b00000110, // .....##.
0b00111100, // ..####..
0b00000110, // .....##.
0b00000110, // .....##.
0b00000110, // .....##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x34 '4'
0b00000000, // ........
0b00000000, // ........
0b00001100, // ....##..
0b00011100, // ...###..
0b00111100, // ..####..
0b01101100, // .##.##..
0b11001100, // ##..##..
0b11111110, // #######.
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00011110, // ...####.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x35 '5'
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11111100, // ######..
0b00000110, // .....##.
0b00000110, // .....##.
0b00000110, // .....##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x36 '6'
0b00000000, // ........
0b00000000, // ........
0b00111000, // ..###...
0b01100000, // .##.....
0b11000000, // ##......
0b11000000, // ##......
0b11111100, // ######..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x37 '7'
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b11000110, // ##...##.
0b00000110, // .....##.
0b00000110, // .....##.
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x38 '8'
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x39 '9'
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111110, // .######.
0b00000110, // .....##.
0b00000110, // .....##.
0b00000110, // .....##.
0b00001100, // ....##..
0b01111000, // .####...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x3a ':'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x3b ';'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00110000, // ..##....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x3c '<'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000110, // .....##.
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b00110000, // ..##....
0b00011000, // ...##...
0b00001100, // ....##..
0b00000110, // .....##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x3d '='
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x3e '>'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01100000, // .##.....
0b00110000, // ..##....
0b00011000, // ...##...
0b00001100, // ....##..
0b00000110, // .....##.
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x3f '?'
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b00001100, // ....##..
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x40 '@'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11011110, // ##.####.
0b11011110, // ##.####.
0b11011110, // ##.####.
0b11011100, // ##.###..
0b11000000, // ##......
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x41 'A'
0b00000000, // ........
0b00000000, // ........
0b00010000, // ...#....
0b00111000, // ..###...
0b01101100, // .##.##..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11111110, // #######.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x42 'B'
0b00000000, // ........
0b00000000, // ........
0b11111100, // ######..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01111100, // .#####..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b11111100, // ######..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x43 'C'
0b00000000, // ........
0b00000000, // ........
0b00111100, // ..####..
0b01100110, // .##..##.
0b11000010, // ##....#.
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11000010, // ##....#.
0b01100110, // .##..##.
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x44 'D'
0b00000000, // ........
0b00000000, // ........
0b11111000, // #####...
0b01101100, // .##.##..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01101100, // .##.##..
0b11111000, // #####...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x45 'E'
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b01100110, // .##..##.
0b01100010, // .##...#.
0b01101000, // .##.#...
0b01111000, // .####...
0b01101000, // .##.#...
0b01100000, // .##.....
0b01100010, // .##...#.
0b01100110, // .##..##.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x46 'F'
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b01100110, // .##..##.
0b01100010, // .##...#.
0b01101000, // .##.#...
0b01111000, // .####...
0b01101000, // .##.#...
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b11110000, // ####....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x47 'G'
0b00000000, // ........
0b00000000, // ........
0b00111100, // ..####..
0b01100110, // .##..##.
0b11000010, // ##....#.
0b11000000, // ##......
0b11000000, // ##......
0b11011110, // ##.####.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01100110, // .##..##.
0b00111010, // ..###.#.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x48 'H'
0b00000000, // ........
0b00000000, // ........
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11111110, // #######.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x49 'I'
0b00000000, // ........
0b00000000, // ........
0b00111100, // ..####..
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x4a 'J'
0b00000000, // ........
0b00000000, // ........
0b00011110, // ...####.
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01111000, // .####...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x4b 'K'
0b00000000, // ........
0b00000000, // ........
0b11100110, // ###..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01101100, // .##.##..
0b01111000, // .####...
0b01111000, // .####...
0b01101100, // .##.##..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b11100110, // ###..##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x4c 'L'
0b00000000, // ........
0b00000000, // ........
0b11110000, // ####....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100010, // .##...#.
0b01100110, // .##..##.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x4d 'M'
0b00000000, // ........
0b00000000, // ........
0b11000011, // ##....##
0b11100111, // ###..###
0b11111111, // ########
0b11111111, // ########
0b11011011, // ##.##.##
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x4e 'N'
0b00000000, // ........
0b00000000, // ........
0b11000110, // ##...##.
0b11100110, // ###..##.
0b11110110, // ####.##.
0b11111110, // #######.
0b11011110, // ##.####.
0b11001110, // ##..###.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x4f 'O'
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x50 'P'
0b00000000, // ........
0b00000000, // ........
0b11111100, // ######..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01111100, // .#####..
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b11110000, // ####....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x51 'Q'
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11010110, // ##.#.##.
0b11011110, // ##.####.
0b01111100, // .#####..
0b00001100, // ....##..
0b00001110, // ....###.
0b00000000, // ........
0b00000000, // ........
// 0x52 'R'
0b00000000, // ........
0b00000000, // ........
0b11111100, // ######..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01111100, // .#####..
0b01101100, // .##.##..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b11100110, // ###..##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x53 'S'
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01100000, // .##.....
0b00111000, // ..###...
0b00001100, // ....##..
0b00000110, // .....##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x54 'T'
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b11011011, // ##.##.##
0b10011001, // #..##..#
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x55 'U'
0b00000000, // ........
0b00000000, // ........
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x56 'V'
0b00000000, // ........
0b00000000, // ........
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b01100110, // .##..##.
0b00111100, // ..####..
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x57 'W'
0b00000000, // ........
0b00000000, // ........
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b11111111, // ########
0b01100110, // .##..##.
0b01100110, // .##..##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x58 'X'
0b00000000, // ........
0b00000000, // ........
0b11000011, // ##....##
0b11000011, // ##....##
0b01100110, // .##..##.
0b00111100, // ..####..
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b01100110, // .##..##.
0b11000011, // ##....##
0b11000011, // ##....##
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x59 'Y'
0b00000000, // ........
0b00000000, // ........
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b01100110, // .##..##.
0b00111100, // ..####..
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x5a 'Z'
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b11000011, // ##....##
0b10000110, // #....##.
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b11000001, // ##.....#
0b11000011, // ##....##
0b11111111, // ########
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x5b '['
0b00000000, // ........
0b00000000, // ........
0b00111100, // ..####..
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x5c '\'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b10000000, // #.......
0b11000000, // ##......
0b11100000, // ###.....
0b01110000, // .###....
0b00111000, // ..###...
0b00011100, // ...###..
0b00001110, // ....###.
0b00000110, // .....##.
0b00000010, // ......#.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x5d ']'
0b00000000, // ........
0b00000000, // ........
0b00111100, // ..####..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x5e '^'
0b00010000, // ...#....
0b00111000, // ..###...
0b01101100, // .##.##..
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x5f '_'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b00000000, // ........
0b00000000, // ........
// 0x60 '`'
0b00110000, // ..##....
0b00110000, // ..##....
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x61 'a'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111000, // .####...
0b00001100, // ....##..
0b01111100, // .#####..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x62 'b'
0b00000000, // ........
0b00000000, // ........
0b11100000, // ###.....
0b01100000, // .##.....
0b01100000, // .##.....
0b01111000, // .####...
0b01101100, // .##.##..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x63 'c'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x64 'd'
0b00000000, // ........
0b00000000, // ........
0b00011100, // ...###..
0b00001100, // ....##..
0b00001100, // ....##..
0b00111100, // ..####..
0b01101100, // .##.##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x65 'e'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11111110, // #######.
0b11000000, // ##......
0b11000000, // ##......
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x66 'f'
0b00000000, // ........
0b00000000, // ........
0b00111000, // ..###...
0b01101100, // .##.##..
0b01100100, // .##..#..
0b01100000, // .##.....
0b11110000, // ####....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b11110000, // ####....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x67 'g'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01110110, // .###.##.
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01111100, // .#####..
0b00001100, // ....##..
0b11001100, // ##..##..
0b01111000, // .####...
0b00000000, // ........
// 0x68 'h'
0b00000000, // ........
0b00000000, // ........
0b11100000, // ###.....
0b01100000, // .##.....
0b01100000, // .##.....
0b01101100, // .##.##..
0b01110110, // .###.##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b11100110, // ###..##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x69 'i'
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00111000, // ..###...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x6a 'j'
0b00000000, // ........
0b00000000, // ........
0b00000110, // .....##.
0b00000110, // .....##.
0b00000000, // ........
0b00001110, // ....###.
0b00000110, // .....##.
0b00000110, // .....##.
0b00000110, // .....##.
0b00000110, // .....##.
0b00000110, // .....##.
0b00000110, // .....##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b00111100, // ..####..
0b00000000, // ........
// 0x6b 'k'
0b00000000, // ........
0b00000000, // ........
0b11100000, // ###.....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100110, // .##..##.
0b01101100, // .##.##..
0b01111000, // .####...
0b01111000, // .####...
0b01101100, // .##.##..
0b01100110, // .##..##.
0b11100110, // ###..##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x6c 'l'
0b00000000, // ........
0b00000000, // ........
0b00111000, // ..###...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x6d 'm'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11100110, // ###..##.
0b11111111, // ########
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x6e 'n'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11011100, // ##.###..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x6f 'o'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x70 'p'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11011100, // ##.###..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01111100, // .#####..
0b01100000, // .##.....
0b01100000, // .##.....
0b11110000, // ####....
0b00000000, // ........
// 0x71 'q'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01110110, // .###.##.
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01111100, // .#####..
0b00001100, // ....##..
0b00001100, // ....##..
0b00011110, // ...####.
0b00000000, // ........
// 0x72 'r'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11011100, // ##.###..
0b01110110, // .###.##.
0b01100110, // .##..##.
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b11110000, // ####....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x73 's'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b01100000, // .##.....
0b00111000, // ..###...
0b00001100, // ....##..
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x74 't'
0b00000000, // ........
0b00000000, // ........
0b00010000, // ...#....
0b00110000, // ..##....
0b00110000, // ..##....
0b11111100, // ######..
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110000, // ..##....
0b00110110, // ..##.##.
0b00011100, // ...###..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x75 'u'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x76 'v'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b01100110, // .##..##.
0b00111100, // ..####..
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x77 'w'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11000011, // ##....##
0b11000011, // ##....##
0b11000011, // ##....##
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b11111111, // ########
0b01100110, // .##..##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x78 'x'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11000011, // ##....##
0b01100110, // .##..##.
0b00111100, // ..####..
0b00011000, // ...##...
0b00111100, // ..####..
0b01100110, // .##..##.
0b11000011, // ##....##
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x79 'y'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111110, // .######.
0b00000110, // .....##.
0b00001100, // ....##..
0b11111000, // #####...
0b00000000, // ........
// 0x7a 'z'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b11001100, // ##..##..
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b11000110, // ##...##.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x7b '{'
0b00000000, // ........
0b00000000, // ........
0b00001110, // ....###.
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b01110000, // .###....
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00001110, // ....###.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x7c '|'
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x7d '}'
0b00000000, // ........
0b00000000, // ........
0b01110000, // .###....
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00001110, // ....###.
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b01110000, // .###....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x7e '~'
0b00000000, // ........
0b00000000, // ........
0b01110110, // .###.##.
0b11011100, // ##.###..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x7f '\x7f'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00010000, // ...#....
0b00111000, // ..###...
0b01101100, // .##.##..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x80 '\x80'
0b00000000, // ........
0b00000000, // ........
0b00111100, // ..####..
0b01100110, // .##..##.
0b11000010, // ##....#.
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11000010, // ##....#.
0b01100110, // .##..##.
0b00111100, // ..####..
0b00001100, // ....##..
0b00000110, // .....##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
// 0x81 '\x81'
0b00000000, // ........
0b00000000, // ........
0b11001100, // ##..##..
0b00000000, // ........
0b00000000, // ........
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x82 '\x82'
0b00000000, // ........
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11111110, // #######.
0b11000000, // ##......
0b11000000, // ##......
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x83 '\x83'
0b00000000, // ........
0b00010000, // ...#....
0b00111000, // ..###...
0b01101100, // .##.##..
0b00000000, // ........
0b01111000, // .####...
0b00001100, // ....##..
0b01111100, // .#####..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x84 '\x84'
0b00000000, // ........
0b00000000, // ........
0b11001100, // ##..##..
0b00000000, // ........
0b00000000, // ........
0b01111000, // .####...
0b00001100, // ....##..
0b01111100, // .#####..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x85 '\x85'
0b00000000, // ........
0b01100000, // .##.....
0b00110000, // ..##....
0b00011000, // ...##...
0b00000000, // ........
0b01111000, // .####...
0b00001100, // ....##..
0b01111100, // .#####..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x86 '\x86'
0b00000000, // ........
0b00111000, // ..###...
0b01101100, // .##.##..
0b00111000, // ..###...
0b00000000, // ........
0b01111000, // .####...
0b00001100, // ....##..
0b01111100, // .#####..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x87 '\x87'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00111100, // ..####..
0b01100110, // .##..##.
0b01100000, // .##.....
0b01100000, // .##.....
0b01100110, // .##..##.
0b00111100, // ..####..
0b00001100, // ....##..
0b00000110, // .....##.
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x88 '\x88'
0b00000000, // ........
0b00010000, // ...#....
0b00111000, // ..###...
0b01101100, // .##.##..
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11111110, // #######.
0b11000000, // ##......
0b11000000, // ##......
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x89 '\x89'
0b00000000, // ........
0b00000000, // ........
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11111110, // #######.
0b11000000, // ##......
0b11000000, // ##......
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x8a '\x8a'
0b00000000, // ........
0b01100000, // .##.....
0b00110000, // ..##....
0b00011000, // ...##...
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11111110, // #######.
0b11000000, // ##......
0b11000000, // ##......
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x8b '\x8b'
0b00000000, // ........
0b00000000, // ........
0b01100110, // .##..##.
0b00000000, // ........
0b00000000, // ........
0b00111000, // ..###...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x8c '\x8c'
0b00000000, // ........
0b00011000, // ...##...
0b00111100, // ..####..
0b01100110, // .##..##.
0b00000000, // ........
0b00111000, // ..###...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x8d '\x8d'
0b00000000, // ........
0b01100000, // .##.....
0b00110000, // ..##....
0b00011000, // ...##...
0b00000000, // ........
0b00111000, // ..###...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x8e '\x8e'
0b00000000, // ........
0b11000110, // ##...##.
0b00000000, // ........
0b00010000, // ...#....
0b00111000, // ..###...
0b01101100, // .##.##..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11111110, // #######.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x8f '\x8f'
0b00111000, // ..###...
0b01101100, // .##.##..
0b00111000, // ..###...
0b00000000, // ........
0b00111000, // ..###...
0b01101100, // .##.##..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11111110, // #######.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x90 '\x90'
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b00000000, // ........
0b11111110, // #######.
0b01100110, // .##..##.
0b01100000, // .##.....
0b01111100, // .#####..
0b01100000, // .##.....
0b01100000, // .##.....
0b01100110, // .##..##.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x91 '\x91'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01101110, // .##.###.
0b00111011, // ..###.##
0b00011011, // ...##.##
0b01111110, // .######.
0b11011000, // ##.##...
0b11011100, // ##.###..
0b01110111, // .###.###
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x92 '\x92'
0b00000000, // ........
0b00000000, // ........
0b00111110, // ..#####.
0b01101100, // .##.##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11111110, // #######.
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001110, // ##..###.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x93 '\x93'
0b00000000, // ........
0b00010000, // ...#....
0b00111000, // ..###...
0b01101100, // .##.##..
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x94 '\x94'
0b00000000, // ........
0b00000000, // ........
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x95 '\x95'
0b00000000, // ........
0b01100000, // .##.....
0b00110000, // ..##....
0b00011000, // ...##...
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x96 '\x96'
0b00000000, // ........
0b00110000, // ..##....
0b01111000, // .####...
0b11001100, // ##..##..
0b00000000, // ........
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x97 '\x97'
0b00000000, // ........
0b01100000, // .##.....
0b00110000, // ..##....
0b00011000, // ...##...
0b00000000, // ........
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x98 '\x98'
0b00000000, // ........
0b00000000, // ........
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111110, // .######.
0b00000110, // .....##.
0b00001100, // ....##..
0b01111000, // .####...
0b00000000, // ........
// 0x99 '\x99'
0b00000000, // ........
0b11000110, // ##...##.
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x9a '\x9a'
0b00000000, // ........
0b11000110, // ##...##.
0b00000000, // ........
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x9b '\x9b'
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b01111110, // .######.
0b11000011, // ##....##
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11000011, // ##....##
0b01111110, // .######.
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x9c '\x9c'
0b00000000, // ........
0b00111000, // ..###...
0b01101100, // .##.##..
0b01100100, // .##..#..
0b01100000, // .##.....
0b11110000, // ####....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b11100110, // ###..##.
0b11111100, // ######..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x9d '\x9d'
0b00000000, // ........
0b00000000, // ........
0b11000011, // ##....##
0b01100110, // .##..##.
0b00111100, // ..####..
0b00011000, // ...##...
0b11111111, // ########
0b00011000, // ...##...
0b11111111, // ########
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x9e '\x9e'
0b00000000, // ........
0b11111100, // ######..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01111100, // .#####..
0b01100010, // .##...#.
0b01100110, // .##..##.
0b01101111, // .##.####
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b11110011, // ####..##
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0x9f '\x9f'
0b00000000, // ........
0b00001110, // ....###.
0b00011011, // ...##.##
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b01111110, // .######.
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b11011000, // ##.##...
0b01110000, // .###....
0b00000000, // ........
0b00000000, // ........
// 0xa0 '\xa0'
0b00000000, // ........
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b00000000, // ........
0b01111000, // .####...
0b00001100, // ....##..
0b01111100, // .#####..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xa1 '\xa1'
0b00000000, // ........
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b00000000, // ........
0b00111000, // ..###...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xa2 '\xa2'
0b00000000, // ........
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xa3 '\xa3'
0b00000000, // ........
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b00000000, // ........
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xa4 '\xa4'
0b00000000, // ........
0b00000000, // ........
0b01110110, // .###.##.
0b11011100, // ##.###..
0b00000000, // ........
0b11011100, // ##.###..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xa5 '\xa5'
0b01110110, // .###.##.
0b11011100, // ##.###..
0b00000000, // ........
0b11000110, // ##...##.
0b11100110, // ###..##.
0b11110110, // ####.##.
0b11111110, // #######.
0b11011110, // ##.####.
0b11001110, // ##..###.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xa6 '\xa6'
0b00000000, // ........
0b00111100, // ..####..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b00111110, // ..#####.
0b00000000, // ........
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xa7 '\xa7'
0b00000000, // ........
0b00111000, // ..###...
0b01101100, // .##.##..
0b01101100, // .##.##..
0b00111000, // ..###...
0b00000000, // ........
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xa8 '\xa8'
0b00000000, // ........
0b00000000, // ........
0b00110000, // ..##....
0b00110000, // ..##....
0b00000000, // ........
0b00110000, // ..##....
0b00110000, // ..##....
0b01100000, // .##.....
0b11000000, // ##......
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xa9 '\xa9'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xaa '\xaa'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b00000110, // .....##.
0b00000110, // .....##.
0b00000110, // .....##.
0b00000110, // .....##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xab '\xab'
0b00000000, // ........
0b11000000, // ##......
0b11000000, // ##......
0b11000010, // ##....#.
0b11000110, // ##...##.
0b11001100, // ##..##..
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b11001110, // ##..###.
0b10011011, // #..##.##
0b00000110, // .....##.
0b00001100, // ....##..
0b00011111, // ...#####
0b00000000, // ........
0b00000000, // ........
// 0xac '\xac'
0b00000000, // ........
0b11000000, // ##......
0b11000000, // ##......
0b11000010, // ##....#.
0b11000110, // ##...##.
0b11001100, // ##..##..
0b00011000, // ...##...
0b00110000, // ..##....
0b01100110, // .##..##.
0b11001110, // ##..###.
0b10010110, // #..#.##.
0b00111110, // ..#####.
0b00000110, // .....##.
0b00000110, // .....##.
0b00000000, // ........
0b00000000, // ........
// 0xad '\xad'
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00111100, // ..####..
0b00111100, // ..####..
0b00111100, // ..####..
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xae '\xae'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00110110, // ..##.##.
0b01101100, // .##.##..
0b11011000, // ##.##...
0b01101100, // .##.##..
0b00110110, // ..##.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xaf '\xaf'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11011000, // ##.##...
0b01101100, // .##.##..
0b00110110, // ..##.##.
0b01101100, // .##.##..
0b11011000, // ##.##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xb0 '\xb0'
0b00010001, // ...#...#
0b01000100, // .#...#..
0b00010001, // ...#...#
0b01000100, // .#...#..
0b00010001, // ...#...#
0b01000100, // .#...#..
0b00010001, // ...#...#
0b01000100, // .#...#..
0b00010001, // ...#...#
0b01000100, // .#...#..
0b00010001, // ...#...#
0b01000100, // .#...#..
0b00010001, // ...#...#
0b01000100, // .#...#..
0b00010001, // ...#...#
0b01000100, // .#...#..
// 0xb1 '\xb1'
0b01010101, // .#.#.#.#
0b10101010, // #.#.#.#.
0b01010101, // .#.#.#.#
0b10101010, // #.#.#.#.
0b01010101, // .#.#.#.#
0b10101010, // #.#.#.#.
0b01010101, // .#.#.#.#
0b10101010, // #.#.#.#.
0b01010101, // .#.#.#.#
0b10101010, // #.#.#.#.
0b01010101, // .#.#.#.#
0b10101010, // #.#.#.#.
0b01010101, // .#.#.#.#
0b10101010, // #.#.#.#.
0b01010101, // .#.#.#.#
0b10101010, // #.#.#.#.
// 0xb2 '\xb2'
0b11011101, // ##.###.#
0b01110111, // .###.###
0b11011101, // ##.###.#
0b01110111, // .###.###
0b11011101, // ##.###.#
0b01110111, // .###.###
0b11011101, // ##.###.#
0b01110111, // .###.###
0b11011101, // ##.###.#
0b01110111, // .###.###
0b11011101, // ##.###.#
0b01110111, // .###.###
0b11011101, // ##.###.#
0b01110111, // .###.###
0b11011101, // ##.###.#
0b01110111, // .###.###
// 0xb3 '\xb3'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xb4 '\xb4'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b11111000, // #####...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xb5 '\xb5'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b11111000, // #####...
0b00011000, // ...##...
0b11111000, // #####...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xb6 '\xb6'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b11110110, // ####.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xb7 '\xb7'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xb8 '\xb8'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111000, // #####...
0b00011000, // ...##...
0b11111000, // #####...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xb9 '\xb9'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b11110110, // ####.##.
0b00000110, // .....##.
0b11110110, // ####.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xba '\xba'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xbb '\xbb'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b00000110, // .....##.
0b11110110, // ####.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xbc '\xbc'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b11110110, // ####.##.
0b00000110, // .....##.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xbd '\xbd'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xbe '\xbe'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b11111000, // #####...
0b00011000, // ...##...
0b11111000, // #####...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xbf '\xbf'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111000, // #####...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xc0 '\xc0'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011111, // ...#####
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xc1 '\xc1'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b11111111, // ########
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xc2 '\xc2'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xc3 '\xc3'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011111, // ...#####
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xc4 '\xc4'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xc5 '\xc5'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b11111111, // ########
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xc6 '\xc6'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011111, // ...#####
0b00011000, // ...##...
0b00011111, // ...#####
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xc7 '\xc7'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110111, // ..##.###
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xc8 '\xc8'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110111, // ..##.###
0b00110000, // ..##....
0b00111111, // ..######
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xc9 '\xc9'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00111111, // ..######
0b00110000, // ..##....
0b00110111, // ..##.###
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xca '\xca'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b11110111, // ####.###
0b00000000, // ........
0b11111111, // ########
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xcb '\xcb'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b00000000, // ........
0b11110111, // ####.###
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xcc '\xcc'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110111, // ..##.###
0b00110000, // ..##....
0b00110111, // ..##.###
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xcd '\xcd'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b00000000, // ........
0b11111111, // ########
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xce '\xce'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b11110111, // ####.###
0b00000000, // ........
0b11110111, // ####.###
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xcf '\xcf'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b11111111, // ########
0b00000000, // ........
0b11111111, // ########
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xd0 '\xd0'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b11111111, // ########
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xd1 '\xd1'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b00000000, // ........
0b11111111, // ########
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xd2 '\xd2'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xd3 '\xd3'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00111111, // ..######
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xd4 '\xd4'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011111, // ...#####
0b00011000, // ...##...
0b00011111, // ...#####
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xd5 '\xd5'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011111, // ...#####
0b00011000, // ...##...
0b00011111, // ...#####
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xd6 '\xd6'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00111111, // ..######
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xd7 '\xd7'
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b11111111, // ########
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
0b00110110, // ..##.##.
// 0xd8 '\xd8'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b11111111, // ########
0b00011000, // ...##...
0b11111111, // ########
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xd9 '\xd9'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b11111000, // #####...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xda '\xda'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011111, // ...#####
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xdb '\xdb'
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
// 0xdc '\xdc'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
// 0xdd '\xdd'
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
0b11110000, // ####....
// 0xde '\xde'
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
0b00001111, // ....####
// 0xdf '\xdf'
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b11111111, // ########
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xe0 '\xe0'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01110110, // .###.##.
0b11011100, // ##.###..
0b11011000, // ##.##...
0b11011000, // ##.##...
0b11011000, // ##.##...
0b11011100, // ##.###..
0b01110110, // .###.##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xe1 '\xe1'
0b00000000, // ........
0b00000000, // ........
0b01111000, // .####...
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11001100, // ##..##..
0b11011000, // ##.##...
0b11001100, // ##..##..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11001100, // ##..##..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xe2 '\xe2'
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b11000000, // ##......
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xe3 '\xe3'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xe4 '\xe4'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b11000110, // ##...##.
0b01100000, // .##.....
0b00110000, // ..##....
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b11000110, // ##...##.
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xe5 '\xe5'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111110, // .######.
0b11011000, // ##.##...
0b11011000, // ##.##...
0b11011000, // ##.##...
0b11011000, // ##.##...
0b11011000, // ##.##...
0b01110000, // .###....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xe6 '\xe6'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01111100, // .#####..
0b01100000, // .##.....
0b01100000, // .##.....
0b11000000, // ##......
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xe7 '\xe7'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01110110, // .###.##.
0b11011100, // ##.###..
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xe8 '\xe8'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111110, // .######.
0b00011000, // ...##...
0b00111100, // ..####..
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b00111100, // ..####..
0b00011000, // ...##...
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xe9 '\xe9'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00111000, // ..###...
0b01101100, // .##.##..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11111110, // #######.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01101100, // .##.##..
0b00111000, // ..###...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xea '\xea'
0b00000000, // ........
0b00000000, // ........
0b00111000, // ..###...
0b01101100, // .##.##..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b11101110, // ###.###.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xeb '\xeb'
0b00000000, // ........
0b00000000, // ........
0b00011110, // ...####.
0b00110000, // ..##....
0b00011000, // ...##...
0b00001100, // ....##..
0b00111110, // ..#####.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b01100110, // .##..##.
0b00111100, // ..####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xec '\xec'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111110, // .######.
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xed '\xed'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000011, // ......##
0b00000110, // .....##.
0b01111110, // .######.
0b11011011, // ##.##.##
0b11011011, // ##.##.##
0b11110011, // ####..##
0b01111110, // .######.
0b01100000, // .##.....
0b11000000, // ##......
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xee '\xee'
0b00000000, // ........
0b00000000, // ........
0b00011100, // ...###..
0b00110000, // ..##....
0b01100000, // .##.....
0b01100000, // .##.....
0b01111100, // .#####..
0b01100000, // .##.....
0b01100000, // .##.....
0b01100000, // .##.....
0b00110000, // ..##....
0b00011100, // ...###..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xef '\xef'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b11000110, // ##...##.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xf0 '\xf0'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b11111110, // #######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xf1 '\xf1'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b01111110, // .######.
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b11111111, // ########
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xf2 '\xf2'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00110000, // ..##....
0b00011000, // ...##...
0b00001100, // ....##..
0b00000110, // .....##.
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b00000000, // ........
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xf3 '\xf3'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00001100, // ....##..
0b00011000, // ...##...
0b00110000, // ..##....
0b01100000, // .##.....
0b00110000, // ..##....
0b00011000, // ...##...
0b00001100, // ....##..
0b00000000, // ........
0b01111110, // .######.
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xf4 '\xf4'
0b00000000, // ........
0b00000000, // ........
0b00001110, // ....###.
0b00011011, // ...##.##
0b00011011, // ...##.##
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
// 0xf5 '\xf5'
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b00011000, // ...##...
0b11011000, // ##.##...
0b11011000, // ##.##...
0b11011000, // ##.##...
0b01110000, // .###....
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xf6 '\xf6'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b01111110, // .######.
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xf7 '\xf7'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01110110, // .###.##.
0b11011100, // ##.###..
0b00000000, // ........
0b01110110, // .###.##.
0b11011100, // ##.###..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xf8 '\xf8'
0b00000000, // ........
0b00111000, // ..###...
0b01101100, // .##.##..
0b01101100, // .##.##..
0b00111000, // ..###...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xf9 '\xf9'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xfa '\xfa'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00011000, // ...##...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xfb '\xfb'
0b00000000, // ........
0b00001111, // ....####
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b00001100, // ....##..
0b11101100, // ###.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b00111100, // ..####..
0b00011100, // ...###..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xfc '\xfc'
0b00000000, // ........
0b11011000, // ##.##...
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b01101100, // .##.##..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xfd '\xfd'
0b00000000, // ........
0b01110000, // .###....
0b11011000, // ##.##...
0b00110000, // ..##....
0b01100000, // .##.....
0b11001000, // ##..#...
0b11111000, // #####...
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xfe '\xfe'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b01111100, // .#####..
0b01111100, // .#####..
0b01111100, // .#####..
0b01111100, // .#####..
0b01111100, // .#####..
0b01111100, // .#####..
0b01111100, // .#####..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// 0xff '\xff'
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
};
|
roscopeco/Xosera
|
xosera_m68k_api/xosera_api.c
|
<gh_stars>0
/*
* vim: set et ts=4 sw=4
*------------------------------------------------------------
* ___ ___ _
* ___ ___ ___ ___ ___ _____| _| . | |_
* | _| . |_ -| _| . | | | . | . | '_|
* |_| |___|___|___|___|_____|_|_|_|___|___|_,_|
* |_____|
* ------------------------------------------------------------
* Copyright (c) 2021 Xark
* MIT License
*
* Xosera low-level C API to read/write Xosera registers
* ------------------------------------------------------------
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <machine.h>
#include "xosera_api.h"
bool xosera_init(int reconfig_num)
{
// check for Xosera presense
for (int r = 0; r < 100; r++)
{
if (xosera_sync())
{
break;
}
cpu_delay(10);
}
// done if configuration if not valid (0 to 3)
if ((reconfig_num & 3) == reconfig_num)
{
xv_setw(const_val, 0xb007);
// set magic "Intel" constant OR'd with config number to make Xosera faint and reconfigure
xv_setw(blit_ctrl, 0x8080 | (reconfig_num << 8)); // reboot FPGA to config_num
cpu_delay(20);
if (xv_getw(const_val) == 0xb007)
{
printf("(reconfig failed)");
}
// wait for Xosera to regain consciousness (takes ~80 milliseconds)
for (int r = 0; r < 100; r++)
{
cpu_delay(20);
if (xosera_sync())
{
break;
}
}
}
return xosera_sync();
}
bool xosera_sync()
{
uint16_t cv = xv_getw(const_val);
xv_setw(const_val, 0x55AA);
if (xv_getw(const_val) != 0x55AA)
{
return false; // not detected
}
xv_setw(const_val, 0xAA55);
if (xv_getw(const_val) != 0xAA55)
{
return false; // not detected
}
xv_setw(const_val, cv);
return true;
}
void xv_vram_fill(int vram_addr, int size, int word_value)
{
xv_setw(wr_addr, vram_addr);
xv_setw(wr_inc, 1);
word_value = (word_value << 16) | (word_value & 0xffff);
if (size & 1)
{
xv_setw(data, word_value);
}
int long_size = size >> 1;
while (long_size--)
{
xv_setl(data, word_value);
}
}
// NOTE: size is in bytes, but assumed to be a multiple of 2 (words)
void xv_copy_to_vram(uint16_t * source, int vram_dest, int size)
{
xv_setw(wr_addr, vram_dest);
xv_setw(wr_inc, 1);
if (size & 2)
{
xv_setw(data, *source++);
}
uint32_t * long_ptr = (uint32_t *)source;
int long_size = size >> 2;
while (long_size--)
{
xv_setl(data, *long_ptr++);
}
}
// NOTE: size is in bytes, but assumed to be a multiple of 2 (words)
void xv_copy_from_vram(int vram_source, uint16_t * dest, int size)
{
xv_setw(rd_addr, vram_source);
xv_setw(rd_inc, 1);
if (size & 2)
{
*dest++ = xv_getw(data);
}
uint32_t * long_ptr = (uint32_t *)dest;
int long_size = size >> 2;
while (long_size--)
{
*long_ptr++ = xv_getl(data);
}
}
|
roscopeco/Xosera
|
rtl/sim/xosera_defs.h
|
#if !defined(XOSERA_DEFS_H)
#define XOSERA_DEFS_H
#define VM_TRACE 1
#define SDL_RENDER 1
#if !defined(SPI_INTERFACE)
#define SPI_INTERFACE 0
#endif
#if !defined(BUS_INTERFACE)
#define BUS_INTERFACE 0
#endif
#if defined(MODE_640x400) // 640x400@70Hz (often treated as 720x400 VGA text mode)
// VGA mode 640x400 @ 70Hz (pixel clock 25.175Mhz)
const double PIXEL_CLOCK_MHZ = 25.175; // pixel clock in MHz
const int VISIBLE_WIDTH = 640; // horizontal active pixels
const int VISIBLE_HEIGHT = 400; // vertical active lines
const int H_FRONT_PORCH = 16; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 96; // H sync pulse pixels
const int H_BACK_PORCH = 48; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 12; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 2; // V sync pulse lines
const int V_BACK_PORCH = 35; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 0; // H sync pulse active level
const int V_SYNC_POLARITY = 1; // V sync pulse active level
#elif defined(MODE_640x400_85) // 640x400@85Hz
// VGA mode 640x480 @ 75Hz (pixel clock 31.5Mhz)
const double PIXEL_CLOCK_MHZ = 31.500; // pixel clock in MHz
const int VISIBLE_WIDTH = 640; // horizontal active pixels
const int VISIBLE_HEIGHT = 400; // vertical active lines
const int H_FRONT_PORCH = 32; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 64; // H sync pulse pixels
const int H_BACK_PORCH = 96; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 1; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 3; // V sync pulse lines
const int V_BACK_PORCH = 41; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 0; // H sync pulse active level
const int V_SYNC_POLARITY = 1; // V sync pulse active level
#elif defined(MODE_640x480) // 640x480@60Hz (default)
// VGA mode 640x480 @ 60Hz (pixel clock 25.175Mhz)
const double PIXEL_CLOCK_MHZ = 25.175; // pixel clock in MHz
const int VISIBLE_WIDTH = 640; // horizontal active pixels
const int VISIBLE_HEIGHT = 480; // vertical active lines
const int H_FRONT_PORCH = 16; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 96; // H sync pulse pixels
const int H_BACK_PORCH = 48; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 10; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 2; // V sync pulse lines
const int V_BACK_PORCH = 33; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 0; // H sync pulse active level
const int V_SYNC_POLARITY = 0; // V sync pulse active level
#elif defined(MODE_640x480_75) // 640x480@75Hz
// VGA mode 640x480 @ 75Hz (pixel clock 31.5Mhz)
const double PIXEL_CLOCK_MHZ = 31.500; // pixel clock in MHz
const int VISIBLE_WIDTH = 640; // horizontal active pixels
const int VISIBLE_HEIGHT = 480; // vertical active lines
const int H_FRONT_PORCH = 16; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 64; // H sync pulse pixels
const int H_BACK_PORCH = 120; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 1; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 3; // V sync pulse lines
const int V_BACK_PORCH = 16; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 0; // H sync pulse active level
const int V_SYNC_POLARITY = 0; // V sync pulse active level
#elif defined(MODE_640x480_85) // 640x480@85Hz
// VGA mode 640x480 @ 85Hz (pixel clock 36.000Mhz)
const double PIXEL_CLOCK_MHZ = 36.000; // pixel clock in MHz
const int VISIBLE_WIDTH = 640; // horizontal active pixels
const int VISIBLE_HEIGHT = 480; // vertical active lines
const int H_FRONT_PORCH = 56; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 56; // H sync pulse pixels
const int H_BACK_PORCH = 80; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 1; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 3; // V sync pulse lines
const int V_BACK_PORCH = 25; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 0; // H sync pulse active level
const int V_SYNC_POLARITY = 0; // V sync pulse active level
#elif defined(MODE_720x400)
// VGA mode 720x400 @ 70Hz (pixel clock 28.322Mhz)
const double PIXEL_CLOCK_MHZ = 28.322; // pixel clock in MHz
const int VISIBLE_WIDTH = 720; // horizontal active pixels
const int VISIBLE_HEIGHT = 400; // vertical active lines
const int H_FRONT_PORCH = 18; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 108; // H sync pulse pixels
const int H_BACK_PORCH = 54; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 12; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 2; // V sync pulse lines
const int V_BACK_PORCH = 35; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 0; // H sync pulse active level
const int V_SYNC_POLARITY = 1; // V sync pulse active level
#elif defined(MODE_848x480) // 848x480@60Hz (works well, 16:9 480p)
// VGA mode 848x480 @ 60Hz (pixel clock 33.750Mhz)
const double PIXEL_CLOCK_MHZ = 33.750; // pixel clock in MHz
const int VISIBLE_WIDTH = 848; // horizontal active pixels
const int VISIBLE_HEIGHT = 480; // vertical active lines
const int H_FRONT_PORCH = 16; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 112; // H sync pulse pixels
const int H_BACK_PORCH = 112; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 6; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 8; // V sync pulse lines
const int V_BACK_PORCH = 23; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 1; // H sync pulse active level
const int V_SYNC_POLARITY = 1; // V sync pulse active level
#elif defined(MODE_800x600) // 800x600@60Hz (out of spec for design on iCE40UP5K)
// VGA mode 800x600 @ 60Hz (pixel clock 40.000Mhz)
const double PIXEL_CLOCK_MHZ = 40.000; // pixel clock in MHz
const int VISIBLE_WIDTH = 800; // horizontal active pixels
const int VISIBLE_HEIGHT = 600; // vertical active lines
const int H_FRONT_PORCH = 40; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 128; // H sync pulse pixels
const int H_BACK_PORCH = 88; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 1; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 4; // V sync pulse lines
const int V_BACK_PORCH = 23; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 1; // H sync pulse active level
const int V_SYNC_POLARITY = 1; // V sync pulse active level
#elif defined(MODE_1024x768) // 1024x768@60Hz (out of spec for design on iCE40UP5K)
// VGA mode 1024x768 @ 60Hz (pixel clock 65.000Mhz)
const double PIXEL_CLOCK_MHZ = 65.000; // pixel clock in MHz
const int VISIBLE_WIDTH = 1024; // horizontal active pixels
const int VISIBLE_HEIGHT = 768; // vertical active lines
const int H_FRONT_PORCH = 24; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 136; // H sync pulse pixels
const int H_BACK_PORCH = 160; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 3; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 6; // V sync pulse lines
const int V_BACK_PORCH = 29; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 0; // H sync pulse active level
const int V_SYNC_POLARITY = 0; // V sync pulse active level
#elif defined(MODE_1280x720) // 1280x720@60Hz (out of spec for design on iCE40UP5K)
// VGA mode 1280x720 @ 60Hz (pixel clock 72.250Mhz)
const double PIXEL_CLOCK_MHZ = 72.250; // pixel clock in MHz
const int VISIBLE_WIDTH = 1280; // horizontal active pixels
const int VISIBLE_HEIGHT = 720; // vertical active lines
const int H_FRONT_PORCH = 110; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 40; // H sync pulse pixels
const int H_BACK_PORCH = 220; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 5; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 5; // V sync pulse lines
const int V_BACK_PORCH = 20; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 1; // H sync pulse active level
const int V_SYNC_POLARITY = 1; // V sync pulse active level
#else
#warning Unknown video mode (or not defined, see Makefile)
const double PIXEL_CLOCK_MHZ = 25.175; // pixel clock in MHz
const int VISIBLE_WIDTH = 640; // horizontal active pixels
const int VISIBLE_HEIGHT = 400; // vertical active lines
const int H_FRONT_PORCH = 16; // H pre-sync (front porch) pixels
const int H_SYNC_PULSE = 96; // H sync pulse pixels
const int H_BACK_PORCH = 48; // H post-sync (back porch) pixels
const int V_FRONT_PORCH = 12; // V pre-sync (front porch) lines
const int V_SYNC_PULSE = 2; // V sync pulse lines
const int V_BACK_PORCH = 35; // V post-sync (back porch) lines
const int H_SYNC_POLARITY = 0; // H sync pulse active level
const int V_SYNC_POLARITY = 1; // V sync pulse active level
#endif
const int TOTAL_WIDTH = H_FRONT_PORCH + H_SYNC_PULSE + H_BACK_PORCH + VISIBLE_WIDTH;
const int TOTAL_HEIGHT = V_FRONT_PORCH + V_SYNC_PULSE + V_BACK_PORCH + VISIBLE_HEIGHT;
const int OFFSCREEN_WIDTH = TOTAL_WIDTH - VISIBLE_WIDTH;
const int OFFSCREEN_HEIGHT = TOTAL_HEIGHT - VISIBLE_HEIGHT;
#endif
|
roscopeco/Xosera
|
xosera_m68k_api/xosera_api.h
|
<filename>xosera_m68k_api/xosera_api.h
/*
* vim: set et ts=4 sw=4
*------------------------------------------------------------
* ___ ___ _
* ___ ___ ___ ___ ___ _____| _| . | |_
* | _| . |_ -| _| . | | | . | . | '_|
* |_| |___|___|___|___|_____|_|_|_|___|___|_,_|
* |_____|
* ------------------------------------------------------------
* Copyright (c) 2021 Xark
* MIT License
*
* Xosera low-level C API to read/write Xosera registers
* ------------------------------------------------------------
*/
#include "xosera_regs.h"
#include <stdbool.h>
#include <stdint.h>
#if defined(delay) // clear out mcBusywait
#undef delay
#endif
#define delay(x) mcDelaymsec10(x / 10);
#define cpu_delay(ms) mcBusywait(ms << 4);
bool xosera_init(int reconfig_num); // true if Xosera present with optional reconfig (if 0 to 3)
bool xosera_sync(); // true if Xosera present
void xv_vram_fill(int vram_addr, int size, int word_value); // fill VRAM with word
void xv_copy_to_vram(uint16_t * source, int vram_dest, int size); // copy to VRAM
void xv_copy_from_vram(int vram_source, uint16_t * dest, int size); // copy from VRAM
|
roscopeco/Xosera
|
xosera_test_m68k/xosera_test_m68k.c
|
/*
* vim: set et ts=4 sw=4
*------------------------------------------------------------
* ___ ___ _
* ___ ___ ___ ___ ___ _____| _| . | |_
* | _| . |_ -| _| . | | | . | . | '_|
* |_| |___|___|___|___|_____|_|_|_|___|___|_,_|
* |_____|
* ------------------------------------------------------------
* Copyright (c) 2021 Xark
* MIT License
*
* Test and tech-demo for Xosera FPGA "graphics card"
* ------------------------------------------------------------
*/
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <basicio.h>
#include <machine.h>
#include <sdfat.h>
#define DELAY_TIME 5000 // human speed
//#define DELAY_TIME 1000 // impatient human speed
//#define DELAY_TIME 100 // machine speed
#include "xosera_api.h"
extern void install_intr(void);
extern void remove_intr(void);
extern volatile uint32_t XFrameCount;
// Define rosco_m68k Xosera board base address pointer (See
// https://github.com/rosco-m68k/hardware-projects/blob/feature/xosera/xosera/code/pld/decoder/ic3_decoder.pld#L25)
volatile xreg_t * const xosera_ptr = (volatile xreg_t * const)0xf80060; // rosco_m68k Xosera base
bool use_sd;
// Xosera default palette
uint16_t def_palette[256] = {
0x0000, 0x000a, 0x00a0, 0x00aa, 0x0a00, 0x0a0a, 0x0aa0, 0x0aaa, 0x0555, 0x055f, 0x05f5, 0x05ff, 0x0f55, 0x0f5f,
0x0ff5, 0x0fff, 0x0213, 0x0435, 0x0546, 0x0768, 0x098a, 0x0bac, 0x0dce, 0x0313, 0x0425, 0x0636, 0x0858, 0x0a7a,
0x0c8c, 0x0eae, 0x0413, 0x0524, 0x0635, 0x0746, 0x0857, 0x0a68, 0x0b79, 0x0500, 0x0801, 0x0a33, 0x0d55, 0x0f78,
0x0fab, 0x0fde, 0x0534, 0x0756, 0x0867, 0x0a89, 0x0b9a, 0x0dbc, 0x0ecd, 0x0200, 0x0311, 0x0533, 0x0744, 0x0966,
0x0b88, 0x0daa, 0x0421, 0x0532, 0x0643, 0x0754, 0x0864, 0x0a75, 0x0b86, 0x0310, 0x0630, 0x0850, 0x0a70, 0x0da3,
0x0fd5, 0x0ff7, 0x0210, 0x0432, 0x0654, 0x0876, 0x0a98, 0x0cba, 0x0edc, 0x0321, 0x0431, 0x0541, 0x0763, 0x0985,
0x0ba7, 0x0dc9, 0x0331, 0x0441, 0x0551, 0x0662, 0x0773, 0x0884, 0x0995, 0x0030, 0x0250, 0x0470, 0x06a0, 0x08c0,
0x0bf3, 0x0ef5, 0x0442, 0x0664, 0x0775, 0x0997, 0x0aa8, 0x0cca, 0x0ddb, 0x0010, 0x0231, 0x0341, 0x0562, 0x0673,
0x0895, 0x0ab7, 0x0130, 0x0241, 0x0351, 0x0462, 0x0573, 0x0694, 0x07a5, 0x0040, 0x0060, 0x0180, 0x03b2, 0x05e5,
0x08f7, 0x0af9, 0x0120, 0x0342, 0x0453, 0x0675, 0x0897, 0x0ab9, 0x0dec, 0x0020, 0x0141, 0x0363, 0x0474, 0x0696,
0x08b8, 0x0ad9, 0x0031, 0x0142, 0x0253, 0x0364, 0x0486, 0x0597, 0x06a8, 0x0033, 0x0054, 0x0077, 0x02a9, 0x04cc,
0x07ff, 0x09ff, 0x0354, 0x0465, 0x0576, 0x0798, 0x08a9, 0x0acb, 0x0ced, 0x0011, 0x0022, 0x0244, 0x0366, 0x0588,
0x0699, 0x08bb, 0x0035, 0x0146, 0x0257, 0x0368, 0x0479, 0x058a, 0x069b, 0x0018, 0x003b, 0x035d, 0x047f, 0x07af,
0x09ce, 0x0cff, 0x0123, 0x0234, 0x0456, 0x0678, 0x089a, 0x0abc, 0x0cde, 0x0013, 0x0236, 0x0347, 0x0569, 0x078b,
0x09ad, 0x0bcf, 0x0226, 0x0337, 0x0448, 0x0559, 0x066a, 0x077c, 0x088d, 0x0209, 0x041c, 0x063f, 0x085f, 0x0b7f,
0x0eaf, 0x0fdf, 0x0446, 0x0557, 0x0779, 0x088a, 0x0aac, 0x0bbd, 0x0ddf, 0x0103, 0x0215, 0x0437, 0x0548, 0x076a,
0x098d, 0x0baf, 0x0315, 0x0426, 0x0537, 0x0648, 0x085a, 0x096b, 0x0a7c, 0x0405, 0x0708, 0x092a, 0x0c4d, 0x0f6f,
0x0f9f, 0x0fbf, 0x0000, 0x0111, 0x0222, 0x0333, 0x0444, 0x0555, 0x0666, 0x0777, 0x0888, 0x0999, 0x0aaa, 0x0bbb,
0x0ccc, 0x0ddd, 0x0eee, 0x0fff};
// dummy global variable
uint32_t global; // this is used to prevent the compiler from optimizing out tests
uint32_t mem_buffer[128 * 1024];
// timer helpers
static uint32_t start_tick;
void timer_start()
{
uint32_t ts = XFrameCount;
uint32_t t;
// this waits for a "fresh tick" to reduce timing jitter
while ((t = XFrameCount) == ts)
;
start_tick = t;
}
uint32_t timer_stop()
{
uint32_t stop_tick = XFrameCount;
return ((stop_tick - start_tick) * 1667) / 100;
}
#if !defined(checkchar) // newer rosco_m68k library addition, this is in case not present
bool checkchar()
{
int rc;
__asm__ __volatile__(
"move.l #6,%%d1\n" // CHECKCHAR
"trap #14\n"
"move.b %%d0,%[rc]\n"
"ext.w %[rc]\n"
"ext.l %[rc]\n"
: [rc] "=d"(rc)
:
: "d0", "d1");
return rc != 0;
}
#endif
bool delay_check(int ms)
{
while (ms > 0)
{
if (checkchar())
{
return true;
}
uint32_t old_framecount = XFrameCount;
while (XFrameCount == old_framecount)
;
ms -= 16;
}
return false;
}
static void dputc(char c)
{
#ifndef __INTELLISENSE__
__asm__ __volatile__(
"move.w %[chr],%%d0\n"
"move.l #2,%%d1\n" // SENDCHAR
"trap #14\n"
:
: [chr] "d"(c)
: "d0", "d1");
#endif
}
static void dprint(const char * str)
{
register char c;
while ((c = *str++) != '\0')
{
if (c == '\n')
{
dputc('\r');
}
dputc(c);
}
}
static char dprint_buff[4096];
static void dprintf(const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
vsnprintf(dprint_buff, sizeof(dprint_buff), fmt, args);
dprint(dprint_buff);
va_end(args);
}
uint16_t screen_addr;
uint8_t text_color = 0x02; // dark green on black
uint8_t text_columns;
uint8_t text_rows;
int8_t text_h;
int8_t text_v;
static void get_textmode_settings()
{
// int mode = 0; // xv_reg_getw(gfxctrl);
// bool v_dbl = mode & 2;
int tile_size = 16; //((xv_reg_getw(fontctrl) & 0xf) + 1) << (v_dbl ? 1 : 0);
screen_addr = 0; // xv_reg_getw(dispstart);
text_columns = xv_reg_getw(dispwidth);
text_rows = (xv_reg_getw(vidheight) + (tile_size - 1)) / tile_size;
}
static void xcls()
{
get_textmode_settings();
xv_setw(wr_addr, screen_addr);
xv_setw(wr_inc, 1);
xv_setbh(data, text_color);
for (uint16_t i = 0; i < (text_columns * text_rows); i++)
{
xv_setbl(data, ' ');
}
xv_setw(wr_addr, screen_addr);
}
static void xmsg(int x, int y, int color, const char * msg)
{
xv_setw(wr_addr, (y * text_columns) + x);
xv_setbh(data, color);
char c;
while ((c = *msg++) != '\0')
{
xv_setbl(data, c);
}
}
void restore_palette()
{
xv_setw(aux_addr, XV_AUX_COLORMEM);
for (int i = 0; i < 256; i++)
{
xv_setw(aux_data, def_palette[i]);
}
}
void test_hello()
{
static const char test_string[] = "Xosera is mostly running happily on rosco_m68k";
static uint16_t test_read[sizeof(test_string)];
xcls();
xmsg(0, 0, 0xa, "WROTE:");
xv_setw(wr_inc, 1); // set write inc
xv_setw(wr_addr, 0x0008); // set write address
xv_setw(data, 0x0200 | test_string[0]); // set full word
for (size_t i = 1; i < sizeof(test_string) - 1; i++)
{
if (i == sizeof(test_string) - 5)
{
xv_setbh(data, 0x04); // test setting bh only (saved, VRAM not altered)
}
xv_setbl(data, test_string[i]); // set byte, will use continue using previous high byte (0x20)
}
// read test
dprintf("Read VRAM test, with auto-increment.\n\n");
dprintf(" Begin: rd_addr=0x0000, rd_inc=0x0001\n");
xv_setw(rd_inc, 1);
xv_setw(rd_addr, 0x0008);
uint16_t * tp = test_read;
for (uint16_t c = 0; c < (sizeof(test_string) - 1); c++)
{
*tp++ = xv_getw(data);
}
uint16_t end_addr = xv_getw(rd_addr);
xmsg(0, 2, 0xa, "READ:");
xv_setw(wr_inc, 1); // set write inc
xv_setw(wr_addr, (text_columns * 2) + 8); // set write address
bool good = true;
for (size_t i = 0; i < sizeof(test_string) - 1; i++)
{
uint16_t v = test_read[i];
xv_setw(data, v);
if ((v & 0xff) != test_string[i])
{
good = false;
}
}
// incremented one extra, because data was already pre-read
if (end_addr != sizeof(test_string) + 8)
{
good = false;
}
dprintf(" End: rd_addr=0x%04x. Test: ", end_addr);
dprintf("%s\n", good ? "good" : "BAD!");
}
void test_vram_speed()
{
xcls();
xv_setw(wr_inc, 1);
xv_setw(wr_addr, 0x0000);
xv_setw(rd_inc, 1);
xv_setw(rd_addr, 0x0000);
int vram_write = 0;
int vram_read = 0;
int main_write = 0;
int main_read = 0;
int reps = 16; // just a few flashes for write test
xmsg(0, 0, 0x02, "VRAM write ");
dprintf("VRAM write x %d\n", reps);
uint32_t v = ((0x0f00 | 'G') << 16) | (0xf000 | 'o');
timer_start();
for (int loop = 0; loop < reps; loop++)
{
uint16_t count = 0x8000; // VRAM long count
do
{
xv_setl(data, v);
} while (--count);
v ^= 0xff00ff00;
}
vram_write = timer_stop();
global = v; // save v so GCC doesn't optimize away test
if (checkchar())
{
return;
}
reps = 32; // main ram test (NOTE: I am not even incrementing pointer below - like "fake
// register" write)
xmsg(0, 0, 0x02, "main RAM write ");
dprintf("main RAM write x %d\n", reps);
timer_start();
for (int loop = 0; loop < reps; loop++)
{
uint32_t * ptr = mem_buffer;
uint16_t count = 0x8000; // VRAM long count
do
{
// *ptr++ = loop; // GCC keeps trying to be clever, we want a fair test
__asm__ __volatile__("move.l %[loop],(%[ptr])" : : [loop] "d"(loop), [ptr] "a"(ptr) :);
} while (--count);
v ^= 0xff00ff00;
}
main_write = timer_stop();
global = v; // save v so GCC doesn't optimize away test
if (checkchar())
{
return;
}
reps = 32; // a bit longer read test (to show stable during read)
xmsg(0, 0, 0x02, "VRAM read ");
dprintf("VRAM read x %d\n", reps);
timer_start();
for (int loop = 0; loop < reps; loop++)
{
uint16_t count = 0x8000; // VRAM long count
do
{
v = xv_getl(data);
} while (--count);
}
vram_read = timer_stop();
global = v; // save v so GCC doesn't optimize away test
if (checkchar())
{
return;
}
reps = 32; // main ram test (NOTE: I am not even incrementing pointer below - like "fake
// register" read)
xmsg(0, 0, 0x02, "main RAM read ");
dprintf("main RAM read x %d\n", reps);
timer_start();
for (int loop = 0; loop < reps; loop++)
{
uint32_t * ptr = mem_buffer;
uint16_t count = 0x8000; // VRAM long count
do
{
// v += *ptr++; // GCC keeps trying to be clever, we want a fair test
__asm__ __volatile__("move.l (%[ptr]),%[v]" : [v] "+d"(v) : [ptr] "a"(ptr) :);
} while (--count);
v ^= 0xff00ff00;
}
main_read = timer_stop();
global = v; // save v so GCC doesn't optimize away test
reps = 32; // a bit longer read test (to show stable during read)
xmsg(0, 0, 0x02, "VRAM slow read ");
dprintf("VRAM slow read x %d\n", reps);
timer_start();
for (int loop = 0; loop < reps; loop++)
{
uint16_t count = 0x8000; // VRAM long count
do
{
xv_setw(rd_addr, 0);
v = xv_getbl(data);
} while (--count);
}
vram_read = timer_stop();
global = v; // save v so GCC doesn't optimize away test
if (checkchar())
{
return;
}
reps = 32; // a bit longer read test (to show stable during read)
xmsg(0, 0, 0x02, "VRAM slow read2");
dprintf("VRAM slow read2 x %d\n", reps);
timer_start();
for (int loop = 0; loop < reps; loop++)
{
uint16_t count = 0x8000; // VRAM long count
do
{
xv_setw(rd_addr, count & 0xff);
v = xv_getbl(data);
} while (--count);
}
vram_read = timer_stop();
global = v; // save v so GCC doesn't optimize away test
if (checkchar())
{
return;
}
dprintf("done\n");
dprintf("MOVEP.L VRAM write 128KB x 16 (2MB) %d ms (%d KB/sec)\n",
vram_write,
(1000 * 128 * reps) / vram_write);
dprintf(
"MOVEP.L VRAM read 128KB x 16 (2MB) %d ms (%d KB/sec)\n", vram_read, (1000 * 128 * reps) / vram_read);
dprintf("MOVE.L main RAM write 128KB x 16 (2MB) %d ms (%d KB/sec)\n",
main_write,
(1000 * 128 * reps) / main_write);
dprintf(
"MOVE.L main RAM read 128KB x 16 (2MB) %d ms (%d KB/sec)\n", main_read, (1000 * 128 * reps) / main_read);
}
uint16_t rosco_m68k_CPUMHz()
{
uint32_t count;
uint32_t tv;
__asm__ __volatile__(
" moveq.l #0,%[count]\n"
" move.w _TIMER_100HZ+2.w,%[tv]\n"
"0: cmp.w _TIMER_100HZ+2.w,%[tv]\n"
" beq.s 0b\n"
" move.w _TIMER_100HZ+2.w,%[tv]\n"
"1: addq.w #1,%[count]\n" // 4 cycles
" cmp.w _TIMER_100HZ+2.w,%[tv]\n" // 12 cycles
" beq.s 1b\n" // 10/8 cycles (taken/not)
: [count] "=d"(count), [tv] "=&d"(tv)
:
:);
uint16_t MHz = ((count * 26) + 500) / 1000;
dprintf("rosco_m68k: m68k CPU speed %d.%d MHz (%d.%d BogoMIPS)\n",
MHz / 10,
MHz % 10,
count * 3 / 10000,
((count * 3) % 10000) / 10);
return (MHz + 5) / 10;
}
static void load_sd_bitmap(const char * filename)
{
dprintf("Loading bitmap: \"%s\"", filename);
void * file = fl_fopen(filename, "r");
if (file != NULL)
{
int cnt = 0;
int vaddr = 0;
while ((cnt = fl_fread(mem_buffer, 1, 512, file)) > 0)
{
/* period every 4KiB, does not noticeably affect speed */
if (!(vaddr % 0x7))
{
dprintf(".");
}
uint16_t * maddr = (uint16_t *)mem_buffer;
xv_setw(wr_addr, vaddr);
for (int i = 0; i < (cnt >> 1); i++)
{
xv_setw(data, *maddr++);
}
vaddr += (cnt >> 1);
}
fl_fclose(file);
dprintf("done!\n");
}
else
{
dprintf(" - FAILED\n");
}
}
static void load_sd_palette(const char * filename)
{
dprintf("Loading colormap: \"%s\"", filename);
void * file = fl_fopen(filename, "r");
if (file != NULL)
{
int cnt = 0;
int vaddr = 0;
while ((cnt = fl_fread(mem_buffer, 1, 512, file)) > 0)
{
/* period every 4KiB, does not noticeably affect speed */
if (!(vaddr % 0x7))
{
dprintf(".");
}
uint16_t * maddr = (uint16_t *)mem_buffer;
xv_setw(aux_addr, XV_AUX_COLORMEM);
for (int i = 0; i < (cnt >> 1); i++)
{
xv_setw(aux_data, *maddr++);
}
vaddr += (cnt >> 1);
}
fl_fclose(file);
dprintf("done!\n");
}
else
{
dprintf(" - FAILED\n");
}
}
uint32_t test_count;
void xosera_test()
{
// flush any input charaters to avoid instant exit
while (checkchar())
{
readchar();
}
dprintf("Xosera_test_m68k\n");
dprintf("\nxosera_init(1)...");
// wait for monitor to unblank
bool success = xosera_init(0);
dprintf("%s (%dx%d)\n", success ? "succeeded" : "FAILED", xv_reg_getw(vidwidth), xv_reg_getw(vidheight));
// D'oh! Uses timer rosco_m68k_CPUMHz();
dprintf("Installing interrupt handler...");
install_intr();
dprintf("okay.\n");
if (delay_check(4000))
{
return;
}
dprintf("Setting scanline interrupt line 399...");
xv_reg_setw(lineintr, 0x818F); // line 399
dprintf("okay.\n");
if (delay_check(2000))
{
return;
}
while (true)
{
uint32_t t = XFrameCount;
int h = t / (60 * 60 * 60);
int m = t / (60 * 60) % 60;
int s = (t / 60) % 60;
dprintf("*** xosera_test_m68k iteration: %d, running %d:%02d:%02d\n", test_count++, h, m, s);
xcls();
uint32_t githash = (xv_reg_getw(githash_h) << 16) | xv_reg_getw(githash_l);
uint16_t width = xv_reg_getw(vidwidth);
uint16_t height = xv_reg_getw(vidheight);
uint16_t features = xv_reg_getw(features);
uint16_t dispstart = xv_reg_getw(dispstart);
uint16_t dispwidth = xv_reg_getw(dispwidth);
uint16_t scrollxy = xv_reg_getw(scrollxy);
uint16_t gfxctrl = xv_reg_getw(gfxctrl);
dprintf("Xosera #%08x\n", githash);
dprintf("Mode: %dx%d Features:0x%04x\n", width, height, features);
dprintf("dispstart:0x%04x dispwidth:0x%04x\n", dispstart, dispwidth);
dprintf(" scrollxy:0x%04x gfxctrl:0x%04x\n", scrollxy, gfxctrl);
for (int y = 0; y < 30; y += 3)
{
xmsg(20, y, (y & 0xf) ? (y & 0xf) : 0xf0, ">>> Xosera rosco_m68k test utility <<<<");
}
if (delay_check(DELAY_TIME))
{
break;
}
if (SD_check_support())
{
dprintf("SD card supported: ");
if (SD_FAT_initialize())
{
dprintf("SD card ready\n");
use_sd = true;
}
else
{
dprintf("no SD card\n");
use_sd = false;
}
}
else
{
dprintf("No SD card support.\n");
}
// 4/8 bpp test
if (use_sd)
{
xv_reg_setw(gfxctrl, 0x0075); // bitmap + 8-bpp + Hx2 + Vx2
xv_reg_setw(dispwidth, 160);
load_sd_palette("/xosera_r1_pal.raw");
load_sd_bitmap("/xosera_r1.raw");
if (delay_check(DELAY_TIME))
{
break;
}
xv_reg_setw(gfxctrl, 0x0000);
}
if (use_sd)
{
xv_reg_setw(gfxctrl, 0x0065); // bitmap + 4-bpp + Hx2 + Vx2
xv_reg_setw(dispwidth, 80);
load_sd_palette("/ST_KingTut_Dpaint_16_pal.raw");
load_sd_bitmap("/ST_KingTut_Dpaint_16.raw");
if (delay_check(DELAY_TIME))
{
break;
}
xv_reg_setw(gfxctrl, 0x0000);
}
if (use_sd)
{
xv_reg_setw(gfxctrl, 0x0065); // bitmap + 4-bpp + Hx2 + Vx2
xv_reg_setw(dispwidth, 80);
load_sd_palette("/escher-relativity_320x240_16_pal.raw");
load_sd_bitmap("/escher-relativity_320x240_16.raw");
if (delay_check(DELAY_TIME))
{
break;
}
xv_reg_setw(gfxctrl, 0x0000);
}
restore_palette();
if (use_sd)
{
xv_reg_setw(gfxctrl, 0x0040); // bitmap + 1-bpp + Hx1 + Vx1
xv_reg_setw(dispwidth, 80);
load_sd_bitmap("/space_shuttle_color_small.raw");
if (delay_check(DELAY_TIME))
{
break;
}
xv_reg_setw(gfxctrl, 0x0000);
}
if (use_sd)
{
xv_reg_setw(gfxctrl, 0x0040); // bitmap + 1-bpp + Hx1 + Vx1
xv_reg_setw(dispwidth, 80);
load_sd_bitmap("/mountains_mono_640x480w.raw");
if (delay_check(DELAY_TIME))
{
break;
}
xv_reg_setw(gfxctrl, 0x0000);
}
if (use_sd)
{
xv_reg_setw(gfxctrl, 0x0040); // bitmap + 1-bpp + Hx1 + Vx1
xv_reg_setw(dispwidth, 80);
load_sd_bitmap("/escher-relativity_640x480w.raw");
if (delay_check(DELAY_TIME))
{
break;
}
xv_reg_setw(gfxctrl, 0x0000);
}
test_hello();
if (delay_check(DELAY_TIME))
{
break;
}
test_vram_speed();
if (delay_check(DELAY_TIME))
{
break;
}
}
xv_reg_setw(gfxctrl, 0x0000);
remove_intr();
while (checkchar())
{
readchar();
}
}
|
jteixeir/42_piscine
|
C06/ex03/ft_sort_params.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteixeir <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/20 14:32:39 by jteixeir #+# #+# */
/* Updated: 2019/10/20 14:57:45 by jteixeir ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] || s2[i])
{
if (s1[i] < s2[i])
return (-1);
if (s1[i] > s2[i])
return (1);
i++;
}
return (0);
}
void ft_swap(char **a, char **b)
{
char *tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i])
{
ft_putchar(str[i]);
i++;
}
}
int main(int argc, char **argv)
{
int i;
i = 1;
while (i < argc - 1)
{
if (ft_strcmp(argv[i], argv[i + 1]) > 0)
{
ft_swap(&argv[i], &argv[i + 1]);
i = 1;
}
else
i++;
}
i = 1;
while (i < argc)
{
ft_putstr(argv[i]);
ft_putchar('\n');
i++;
}
return (0);
}
|
yuexiaona/weiXin
|
Wechat/Wechat/UIBarButtonItem+Extention.h
|
<reponame>yuexiaona/weiXin
//
// UIBarButtonItem+Extention.h
// Wechat
//
// Created by admin on 16/2/2.
// Copyright © 2016年 tarena. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (Extention)
+ (instancetype)itemSetImage:(NSString *)image Target:(id)target action:(SEL)action;
@end
|
yuexiaona/weiXin
|
Wechat/Wechat/BaseNavigationController.h
|
//
// BaseNavigationController.h
// Wechat
//
// Created by admin on 16/2/2.
// Copyright © 2016年 tarena. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface BaseNavigationController : UITableViewController
@end
|
yuexiaona/weiXin
|
Wechat/Wechat/WeiXinTableViewController.h
|
<gh_stars>0
//
// WeiXinTableViewController.h
// Wechat
//
// Created by admin on 16/2/2.
// Copyright © 2016年 tarena. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface WeiXinTableViewController : UITableViewController
@end
|
yuexiaona/weiXin
|
Wechat/Wechat/WXTableBarViewController.h
|
//
// WXTableBarViewController.h
// Wechat
//
// Created by admin on 16/2/1.
// Copyright © 2016年 tarena. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface WXTableBarViewController : UITabBarController
@end
|
LetsBuildRockets/Horizon-Tracker
|
horizonTracker.h
|
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
#include <sys/time.h>
#include <assert.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef _HORIZON_TRACKER_H_
#define _HORIZON_TRACKER_H_
#ifdef __ARMEL__
#include <bcm2835.h>
#define PIN RPI_BPLUS_GPIO_J8_37
#endif
struct timeval tp;
#define PI 3.14159
#define contrastValue 2.7
#define erodeValue 8
#define dilateValue 10
#define epsilonValue 10
enum Mode { UNDEF, SERF, MASTER, USESTILL };
Mode mode = UNDEF;
#endif
|
1184893257/libpag
|
tgfx/src/gpu/opengl/GLState.h
|
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// unless required by applicable law or agreed to in writing, software distributed under the
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
// either express or implied. see the license for the specific language governing permissions
// and limitations under the license.
//
/////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <list>
#include <unordered_map>
#include "GLInterface.h"
namespace tgfx {
enum class GLAttributeType {
ActiveTexture,
BlendEquationSeparate,
BlendFuncSeparate,
CurrentProgram,
ElementBufferBinding,
EnableBlend,
EnableCullFace,
EnableDepth,
EnableDither,
EnableFramebufferSRGB,
EnableScissor,
EnableStencil,
EnableVertexProgramPointSize,
EnableMultisample,
EnableFetchPerSampleARM,
EnablePolygonOffsetFill,
FrameBufferBinding,
ReadFrameBufferBinding,
DrawFrameBufferBinding,
RenderBufferBinding,
PackAlignment,
PackRowLength,
ScissorBox,
TextureBinding,
UnpackAlignment,
UnpackRowLength,
VertexArrayBinding,
VertexAttribute,
VertexBufferBinding,
DepthMask,
Viewport
};
class GLAttribute {
public:
virtual ~GLAttribute() = default;
virtual GLAttributeType type() const = 0;
virtual int priority() const = 0;
virtual void apply(GLState* state) const = 0;
};
class StateRecord {
public:
explicit StateRecord(unsigned currentVAO) : defaultVAO(currentVAO) {
}
unsigned defaultVAO = 0;
std::list<std::shared_ptr<GLAttribute>> defaultAttributes = {};
std::unordered_map<unsigned, std::shared_ptr<GLAttribute>> vertexMap = {};
std::unordered_map<uint32_t, std::shared_ptr<GLAttribute>> textureMap = {};
std::unordered_map<GLAttributeType, std::shared_ptr<GLAttribute>, EnumHasher> attributeMap = {};
};
// TODO(domrjchen): All GL methods that may modify the state should be hooked uniformly onto
// GLState, and the warning output should be added.
class GLState {
public:
explicit GLState(const GLInterface* gl);
void reset();
void save();
void restore();
void activeTexture(unsigned textureUnit);
void blendEquation(unsigned mode);
void blendEquationSeparate(unsigned modeRGB, unsigned modeAlpha);
void blendFunc(unsigned srcFactor, unsigned dstFactor);
void blendFuncSeparate(unsigned srcRGB, unsigned dstRGB, unsigned srcAlpha, unsigned dstAlpha);
void bindFramebuffer(unsigned target, unsigned framebuffer);
void bindRenderbuffer(unsigned target, unsigned renderbuffer);
void bindBuffer(unsigned target, unsigned buffer);
void bindTexture(unsigned target, unsigned texture);
void bindVertexArray(unsigned vertexArray);
void disable(unsigned cap);
void disableVertexAttribArray(unsigned index);
void enable(unsigned cap);
void enableVertexAttribArray(unsigned index);
void pixelStorei(unsigned name, int param);
void scissor(int x, int y, int width, int height);
void viewport(int x, int y, int width, int height);
void useProgram(unsigned program);
void vertexAttribPointer(unsigned index, int size, unsigned type, unsigned char normalized,
int stride, const void* ptr);
void depthMask(unsigned char flag);
const GLInterface* gl = nullptr;
unsigned currentVAO = 0;
unsigned currentTextureUnit = 0;
std::shared_ptr<StateRecord> currentRecord = nullptr;
std::vector<std::shared_ptr<StateRecord>> recordList = {};
void saveVertexAttribute(unsigned index);
std::shared_ptr<GLAttribute> insertAttribute(std::shared_ptr<GLAttribute> attribute) const;
};
class Context;
class GLStateGuard {
public:
explicit GLStateGuard(Context* context);
~GLStateGuard();
private:
GLState* state = nullptr;
};
} // namespace tgfx
|
1184893257/libpag
|
src/rendering/caches/RenderCache.h
|
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// unless required by applicable law or agreed to in writing, software distributed under the
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
// either express or implied. see the license for the specific language governing permissions
// and limitations under the license.
//
/////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <memory>
#include <unordered_set>
#include "TextAtlas.h"
#include "TextGlyphs.h"
#include "gpu/Device.h"
#include "pag/file.h"
#include "pag/pag.h"
#include "rendering/Performance.h"
#include "rendering/filters/LayerFilter.h"
#include "rendering/filters/LayerStylesFilter.h"
#include "rendering/filters/MotionBlurFilter.h"
#include "rendering/graphics/Picture.h"
#include "rendering/graphics/Snapshot.h"
#include "rendering/layers/PAGStage.h"
#include "rendering/readers/BitmapSequenceReader.h"
#include "video/DecodingPolicy.h"
namespace pag {
class RenderCache : public Performance {
public:
explicit RenderCache(PAGStage* stage);
~RenderCache() override;
ID uniqueID() const {
return _uniqueID;
}
void prepareFrame();
void attachToContext(tgfx::Context* current, bool forHitTest = false);
void detachFromContext();
/**
* Returns the total memory usage of this cache.
*/
size_t memoryUsage() const {
return graphicsMemory;
}
/**
* Returns the GPU context associated with this cache.
*/
tgfx::Context* getContext() const {
return context;
}
/**
* If set to false, the getSnapshot() always returns nullptr. The default value is true.
*/
bool snapshotEnabled() const;
/**
* Set the value of snapshotEnabled property.
*/
void setSnapshotEnabled(bool value);
/**
* Returns true if there is snapshot cache available for specified asset ID.
*/
bool hasSnapshot(ID assetID) const {
return snapshotCaches.count(assetID) > 0;
}
/**
* Returns a snapshot cache of specified asset id. Returns null if there is no associated cache
* available. This is a read-only query which is used usually during hit testing.
*/
Snapshot* getSnapshot(ID assetID) const;
/**
* Returns a snapshot cache of specified Image. If there is no associated cache available,
* a new cache will be created by the image. Returns null if the image fails to make a
* new snapshot.
*/
Snapshot* getSnapshot(const Picture* image);
/**
* Frees the snapshot cache associated with specified asset ID immediately.
*/
void removeSnapshot(ID assetID);
TextAtlas* getTextAtlas(ID assetID);
TextAtlas* getTextAtlas(const TextGlyphs* textGlyphs);
void removeTextAtlas(ID assetID);
/**
* Prepares a bitmap task for next getImageBuffer() call.
*/
void prepareImage(ID assetID, std::shared_ptr<tgfx::Image> image);
/**
* Returns a texture buffer cache of specified asset id. Returns null if there is no associated
* cache available.
*/
std::shared_ptr<tgfx::TextureBuffer> getImageBuffer(ID assetID);
uint32_t getContentVersion() const;
bool videoEnabled() const;
void setVideoEnabled(bool value);
bool prepareSequenceReader(Sequence* sequence, Frame targetFrame, DecodingPolicy policy);
std::shared_ptr<SequenceReader> getSequenceReader(Sequence* sequence);
LayerFilter* getFilterCache(LayerStyle* layerStyle);
LayerFilter* getFilterCache(Effect* effect);
MotionBlurFilter* getMotionBlurFilter();
LayerStylesFilter* getLayerStylesFilter(Layer* layer);
void recordImageDecodingTime(int64_t decodingTime);
void recordTextureUploadingTime(int64_t time);
void recordProgramCompilingTime(int64_t time);
void releaseAll();
private:
ID _uniqueID = 0;
PAGStage* stage = nullptr;
uint32_t deviceID = 0;
tgfx::Context* context = nullptr;
int64_t lastTimestamp = 0;
bool hitTestOnly = false;
size_t graphicsMemory = 0;
bool _videoEnabled = true;
bool _snapshotEnabled = true;
std::unordered_set<ID> usedAssets = {};
std::unordered_map<ID, Snapshot*> snapshotCaches = {};
std::list<Snapshot*> snapshotLRU = {};
std::unordered_map<ID, TextAtlas*> textAtlases = {};
std::unordered_map<ID, std::shared_ptr<Task>> imageTasks;
std::unordered_map<ID, std::shared_ptr<SequenceReader>> sequenceCaches;
std::unordered_map<ID, Filter*> filterCaches;
MotionBlurFilter* motionBlurFilter = nullptr;
// bitmap caches:
void clearExpiredBitmaps();
// snapshot caches:
void clearAllSnapshots();
void clearExpiredSnapshots();
// sequence caches:
void clearAllSequenceCaches();
void clearSequenceCache(ID uniqueID);
void clearExpiredSequences();
// filter caches:
LayerFilter* getLayerFilterCache(ID uniqueID, const std::function<LayerFilter*()>& makeFilter);
void clearFilterCache(ID uniqueID);
bool initFilter(Filter* filter);
void preparePreComposeLayer(PreComposeLayer* layer, DecodingPolicy policy);
void prepareImageLayer(PAGImageLayer* layer);
};
} // namespace pag
|
1184893257/libpag
|
tgfx/include/core/Color.h
|
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// unless required by applicable law or agreed to in writing, software distributed under the
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
// either express or implied. see the license for the specific language governing permissions
// and limitations under the license.
//
/////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <cfloat>
#include <cinttypes>
#include <limits>
namespace tgfx {
/**
* RGBA color value, holding four floating point components. Color components are always in a known
* order.
*/
struct Color {
/**
* Red component.
*/
float red;
/**
* Green component.
*/
float green;
/**
* Blue component.
*/
float blue;
/**
* Alpha component.
*/
float alpha;
/**
* Returns an invalid Color.
*/
static const Color& Invalid();
/**
* Returns a fully transparent Color.
*/
static const Color& Transparent();
/**
* Returns a fully opaque black Color.
*/
static const Color& Black();
/**
* Returns a fully opaque white Color.
*/
static const Color& White();
/**
* Returns color value from 8-bit component values.
*/
static Color FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
/**
* Compares Color with other, and returns true if all components are equal.
*/
bool operator==(const Color& other) const {
return alpha == other.alpha && red == other.red && green == other.green && blue == other.blue;
}
/**
* Compares Color with other, and returns true if not all components are equal.
*/
bool operator!=(const Color& other) const {
return !(*this == other);
}
/**
* Returns a pointer to components of Color, for array access.
*/
const float* array() const {
return &red;
}
/**
* Returns a pointer to components of Color, for array access.
*/
float* array() {
return &red;
}
/**
* Returns one component.
* @param index one of: 0 (r), 1 (g), 2 (b), 3 (a)
* @return value corresponding to index.
*/
float operator[](int index) const;
/**
* Returns one component.
* @param index one of: 0 (r), 1 (g), 2 (b), 3 (a)
* @return value corresponding to index.
*/
float& operator[](int index);
/**
* Returns true if all channels are in [0, 1].
**/
bool isValid() const;
/**
* Returns true if Color is an opaque color.
*/
bool isOpaque() const;
/**
* Returns a Color with alpha set to 1.0.
*/
Color makeOpaque() const {
return {red, green, blue, 1.0f};
}
/**
* Returns a Color premultiplied by alpha.
*/
Color premultiply() const {
return {red * alpha, green * alpha, blue * alpha, alpha};
}
/**
* Returns a Color unpremultiplied by alpha.
*/
Color unpremultiply() const;
};
} // namespace tgfx
|
1184893257/libpag
|
tgfx/src/gpu/opengl/GLInterface.h
|
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// unless required by applicable law or agreed to in writing, software distributed under the
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
// either express or implied. see the license for the specific language governing permissions
// and limitations under the license.
//
/////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GLCaps.h"
#include "GLDefines.h"
#include "GLFunctions.h"
#include "GLProcGetter.h"
namespace tgfx {
class GLState;
/**
* NOTE:
* If added API can change OpenGL state, you should add code to recovery it.
* 1. GLInterface.cpp - add HOOK function at HookWithState
* 2. GLState.h/cpp - add hook function and GLAttribute
*/
class GLInterface {
public:
static const GLInterface* GetNative();
GLFunction<GLActiveTexture> activeTexture;
GLFunction<GLAttachShader> attachShader;
GLFunction<GLBindBuffer> bindBuffer;
GLFunction<GLBindFramebuffer> bindFramebuffer;
GLFunction<GLBindRenderbuffer> bindRenderbuffer;
GLFunction<GLBindTexture> bindTexture;
GLFunction<GLBindVertexArray> bindVertexArray;
GLFunction<GLBlendEquation> blendEquation;
GLFunction<GLBlendEquationSeparate> blendEquationSeparate;
GLFunction<GLBlendFunc> blendFunc;
GLFunction<GLBlendFuncSeparate> blendFuncSeparate;
GLFunction<GLBufferData> bufferData;
GLFunction<GLCheckFramebufferStatus> checkFramebufferStatus;
GLFunction<GLClear> clear;
GLFunction<GLClearColor> clearColor;
GLFunction<GLCompileShader> compileShader;
GLFunction<GLCopyTexSubImage2D> copyTexSubImage2D;
GLFunction<GLCreateProgram> createProgram;
GLFunction<GLCreateShader> createShader;
GLFunction<GLDeleteBuffers> deleteBuffers;
GLFunction<GLDeleteFramebuffers> deleteFramebuffers;
GLFunction<GLDeleteProgram> deleteProgram;
GLFunction<GLDeleteRenderbuffers> deleteRenderbuffers;
GLFunction<GLDeleteShader> deleteShader;
GLFunction<GLDeleteTextures> deleteTextures;
GLFunction<GLDeleteVertexArrays> deleteVertexArrays;
GLFunction<GLDepthMask> depthMask;
GLFunction<GLDisable> disable;
GLFunction<GLDisableVertexAttribArray> disableVertexAttribArray;
GLFunction<GLDrawArrays> drawArrays;
GLFunction<GLDrawElements> drawElements;
GLFunction<GLEnable> enable;
GLFunction<GLIsEnabled> isEnabled;
GLFunction<GLEnableVertexAttribArray> enableVertexAttribArray;
GLFunction<GLFinish> finish;
GLFunction<GLFlush> flush;
GLFunction<GLFramebufferRenderbuffer> framebufferRenderbuffer;
GLFunction<GLFramebufferTexture2D> framebufferTexture2D;
GLFunction<GLFramebufferTexture2DMultisample> framebufferTexture2DMultisample;
GLFunction<GLGenBuffers> genBuffers;
GLFunction<GLGenFramebuffers> genFramebuffers;
GLFunction<GLGenRenderbuffers> genRenderbuffers;
GLFunction<GLGenTextures> genTextures;
GLFunction<GLGenVertexArrays> genVertexArrays;
GLFunction<GLGetError> getError;
GLFunction<GLGetIntegerv> getIntegerv;
GLFunction<GLGetBooleanv> getBooleanv;
GLFunction<GLGetProgramInfoLog> getProgramInfoLog;
GLFunction<GLGetProgramiv> getProgramiv;
GLFunction<GLGetRenderbufferParameteriv> getRenderbufferParameteriv;
GLFunction<GLGetShaderInfoLog> getShaderInfoLog;
GLFunction<GLGetShaderiv> getShaderiv;
GLFunction<GLGetString> getString;
GLFunction<GLGetVertexAttribiv> getVertexAttribiv;
GLFunction<GLGetVertexAttribPointerv> getVertexAttribPointerv;
GLFunction<GLGetAttribLocation> getAttribLocation;
GLFunction<GLGetUniformLocation> getUniformLocation;
GLFunction<GLLinkProgram> linkProgram;
GLFunction<GLPixelStorei> pixelStorei;
GLFunction<GLReadPixels> readPixels;
GLFunction<GLRenderbufferStorage> renderbufferStorage;
GLFunction<GLRenderbufferStorageMultisample> renderbufferStorageMultisample;
GLFunction<GLRenderbufferStorageMultisampleAPPLE> renderbufferStorageMultisampleAPPLE;
GLFunction<GLRenderbufferStorageMultisampleEXT> renderbufferStorageMultisampleEXT;
GLFunction<GLResolveMultisampleFramebuffer> resolveMultisampleFramebuffer;
GLFunction<GLBlitFramebuffer> blitFramebuffer;
GLFunction<GLScissor> scissor;
GLFunction<GLShaderSource> shaderSource;
GLFunction<GLTexImage2D> texImage2D;
GLFunction<GLTexParameteri> texParameteri;
GLFunction<GLTexParameteriv> texParameteriv;
GLFunction<GLTexSubImage2D> texSubImage2D;
GLFunction<GLUniform1f> uniform1f;
GLFunction<GLUniform1i> uniform1i;
GLFunction<GLUniform2f> uniform2f;
GLFunction<GLUniform3f> uniform3f;
GLFunction<GLUniform4fv> uniform4fv;
GLFunction<GLUniformMatrix3fv> uniformMatrix3fv;
GLFunction<GLUseProgram> useProgram;
GLFunction<GLVertexAttribPointer> vertexAttribPointer;
GLFunction<GLViewport> viewport;
GLFunction<GLTextureBarrier> textureBarrier;
GLFunction<GLFenceSync> fenceSync;
GLFunction<GLWaitSync> waitSync;
GLFunction<GLDeleteSync> deleteSync;
std::shared_ptr<const GLCaps> caps = nullptr;
private:
static std::unique_ptr<const GLInterface> MakeNativeInterface(const GLProcGetter* getter);
static std::unique_ptr<const GLInterface> HookWithState(const GLInterface* gl, GLState* state);
friend class GLContext;
};
} // namespace tgfx
|
1184893257/libpag
|
tgfx/include/core/Matrix.h
|
<gh_stars>1-10
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// unless required by applicable law or agreed to in writing, software distributed under the
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
// either express or implied. see the license for the specific language governing permissions
// and limitations under the license.
//
/////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <cstring>
#include "core/Rect.h"
namespace tgfx {
/***
* Matrix holds a 3x3 matrix for transforming coordinates. This allows mapping Point and vectors
* with translation, scaling, skewing, rotation, and perspective.
* Matrix elements are in row major order. Matrix does not have a constructor, so it must be
* explicitly initialized. setIdentity() initializes Matrix so it has no effect.
* setTranslate(), setScale(), setSkew(), setRotate(), set9 and setAll() initializes all Matrix
* elements with the corresponding mapping.
*/
class Matrix {
public:
/**
* Sets Matrix to scale by (sx, sy). Returned matrix is:
*
* | sx 0 0 |
* | 0 sy 0 |
* | 0 0 1 |
*
* @param sx horizontal scale factor
* @param sy vertical scale factor
* @return Matrix with scale
*/
static Matrix MakeScale(float sx, float sy) {
Matrix m = {};
m.setScale(sx, sy);
return m;
}
/**
* Sets Matrix to scale by (scale, scale). Returned matrix is:
*
* | scale 0 0 |
* | 0 scale 0 |
* | 0 0 1 |
*
* @param scale horizontal and vertical scale factor
* @return Matrix with scale
*/
static Matrix MakeScale(float scale) {
Matrix m = {};
m.setScale(scale, scale);
return m;
}
/**
* Sets Matrix to translate by (dx, dy). Returned matrix is:
*
* | 1 0 dx |
* | 0 1 dy |
* | 0 0 1 |
*
* @param dx horizontal translation
* @param dy vertical translation
* @return Matrix with translation
*/
static Matrix MakeTrans(float dx, float dy) {
Matrix m = {};
m.setTranslate(dx, dy);
return m;
}
/**
* Sets Matrix to:
*
* | scaleX skewX transX |
* | skewY scaleY transY |
* | pers0 pers1 pers2 |
*
* @param scaleX horizontal scale factor
* @param skewX horizontal skew factor
* @param transX horizontal translation
* @param skewY vertical skew factor
* @param scaleY vertical scale factor
* @param transY vertical translation
* @param pers0 input x-axis perspective factor
* @param pers1 input y-axis perspective factor
* @param pers2 perspective scale factor
* @return Matrix constructed from parameters
*/
static Matrix MakeAll(float scaleX, float skewX, float transX, float skewY, float scaleY,
float transY, float pers0, float pers1, float pers2) {
Matrix m = {};
m.setAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2);
return m;
}
/**
* Returns true if Matrix is identity. Identity matrix is:
*
* | 1 0 0 |
* | 0 1 0 |
* | 0 0 1 |
*
* @return true if Matrix has no effect
*/
bool isIdentity() const {
return values[0] == 1 && values[1] == 0 && values[2] == 0 && values[3] == 0 && values[4] == 1 &&
values[5] == 0 && values[6] == 0 && values[7] == 0 && values[8] == 1;
}
/**
* Returns one matrix value.
*/
float operator[](int index) const {
return values[index];
}
/**
* Returns one matrix value.
*/
float get(int index) const {
return values[index];
}
/**
* Returns scale factor multiplied by x-axis input, contributing to x-axis output. With
* mapPoints(), scales Point along the x-axis.
* @return horizontal scale factor
*/
float getScaleX() const {
return values[SCALE_X];
}
/**
* Returns scale factor multiplied by y-axis input, contributing to y-axis output. With
* mapPoints(), scales Point along the y-axis.
* @return vertical scale factor
*/
float getScaleY() const {
return values[SCALE_Y];
}
/**
* Returns scale factor multiplied by x-axis input, contributing to y-axis output. With
* mapPoints(), skews Point along the y-axis. Skewing both axes can rotate Point.
* @return vertical skew factor
*/
float getSkewY() const {
return values[SKEW_Y];
}
/**
* Returns scale factor multiplied by y-axis input, contributing to x-axis output. With
* mapPoints(), skews Point along the x-axis. Skewing both axes can rotate Point.
* @return horizontal scale factor
*/
float getSkewX() const {
return values[SKEW_X];
}
/**
* Returns translation contributing to x-axis output. With mapPoints(), moves Point along the
* x-axis.
* @return horizontal translation factor
*/
float getTranslateX() const {
return values[TRANS_X];
}
/**
* Returns translation contributing to y-axis output. With mapPoints(), moves Point along the
* y-axis.
* @return vertical translation factor
*/
float getTranslateY() const {
return values[TRANS_Y];
}
/**
* Returns writable Matrix value.
*/
float& operator[](int index) {
return values[index];
}
/**
* Sets Matrix value.
*/
void set(int index, float value) {
values[index] = value;
}
/**
* Sets horizontal scale factor.
* @param v horizontal scale factor to store
*/
void setScaleX(float v) {
this->set(SCALE_X, v);
}
/**
* Sets vertical scale factor.
* @param v vertical scale factor to store
*/
void setScaleY(float v) {
this->set(SCALE_Y, v);
}
/**
* Sets vertical skew factor.
* @param v vertical skew factor to store
*/
void setSkewY(float v) {
this->set(SKEW_Y, v);
}
/**
* Sets horizontal skew factor.
* @param v horizontal skew factor to store
*/
void setSkewX(float v) {
this->set(SKEW_X, v);
}
/**
* Sets horizontal translation.
* @param v horizontal translation to store
*/
void setTranslateX(float v) {
this->set(TRANS_X, v);
}
/**
* Sets vertical translation.
* @param v vertical translation to store
*/
void setTranslateY(float v) {
this->set(TRANS_Y, v);
}
/**
* Sets all values from parameters. Sets matrix to:
*
* | scaleX skewX transX |
* | skewY scaleY transY |
* | persp0 persp1 persp2 |
*
* @param scaleX horizontal scale factor to store
* @param skewX horizontal skew factor to store
* @param transX horizontal translation to store
* @param skewY vertical skew factor to store
* @param scaleY vertical scale factor to store
* @param transY vertical translation to store
* @param persp0 input x-axis values perspective factor to store
* @param persp1 input y-axis values perspective factor to store
* @param persp2 perspective scale factor to store
*/
void setAll(float scaleX, float skewX, float transX, float skewY, float scaleY, float transY,
float persp0, float persp1, float persp2);
void setAffine(float a, float b, float c, float d, float tx, float ty);
/**
* Copies nine scalar values contained by Matrix into buffer, in member value ascending order:
* ScaleX, SkewX, TransX, SkewY, ScaleY, TransY, Persp0, Persp1, Persp2.
* @param buffer storage for nine scalar values
*/
void get9(float buffer[9]) const {
memcpy(buffer, values, 9 * sizeof(float));
}
/**
* Sets Matrix to nine scalar values in buffer, in member value ascending order: ScaleX,
* SkewX, TransX, SkewY, ScaleY, TransY, Persp0, Persp1, Persp2.
*
* Sets matrix to:
*
* | buffer[0] buffer[1] buffer[2] |
* | buffer[3] buffer[4] buffer[5] |
* | buffer[6] buffer[7] buffer[8] |
*
* @param buffer nine scalar values
*/
void set9(const float buffer[9]) {
memcpy(values, buffer, 9 * sizeof(float));
}
/**
* Sets Matrix to identity; which has no effect on mapped Point. Sets Matrix to:
*
* | 1 0 0 |
* | 0 1 0 |
* | 0 0 1 |
*
* Also called setIdentity(); use the one that provides better inline documentation.
*/
void reset();
/**
* Sets Matrix to identity; which has no effect on mapped Point. Sets Matrix to:
*
* | 1 0 0 |
* | 0 1 0 |
* | 0 0 1 |
*
* Also called reset(); use the one that provides better inline documentation.
*/
void setIdentity() {
this->reset();
}
/**
* Sets Matrix to translate by (dx, dy).
* @param dx horizontal translation
* @param dy vertical translation
*/
void setTranslate(float dx, float dy);
/**
* Sets Matrix to scale by sx and sy, about a pivot point at (px, py). The pivot point is
* unchanged when mapped with Matrix.
* @param sx horizontal scale factor
* @param sy vertical scale factor
* @param px pivot on x-axis
* @param py pivot on y-axis
*/
void setScale(float sx, float sy, float px, float py);
/**
* Sets Matrix to scale by sx and sy about at pivot point at (0, 0).
* @param sx horizontal scale factor
* @param sy vertical scale factor
*/
void setScale(float sx, float sy);
/**
* Sets Matrix to rotate by degrees about a pivot point at (px, py). The pivot point is
* unchanged when mapped with Matrix. Positive degrees rotates clockwise.
* @param degrees angle of axes relative to upright axes
* @param px pivot on x-axis
* @param py pivot on y-axis
*/
void setRotate(float degrees, float px, float py);
/**
* Sets Matrix to rotate by degrees about a pivot point at (0, 0). Positive degrees rotates
* clockwise.
* @param degrees angle of axes relative to upright axes
*/
void setRotate(float degrees);
/**
* Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (px, py).
* The pivot point is unchanged when mapped with Matrix.
* Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1).
* Vector length specifies scale.
*/
void setSinCos(float sinV, float cosV, float px, float py);
/**
* Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (0, 0).
* Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1).
* Vector length specifies scale.
*/
void setSinCos(float sinV, float cosV);
/**
* Sets Matrix to skew by kx and ky, about a pivot point at (px, py). The pivot point is
* unchanged when mapped with Matrix.
* @param kx horizontal skew factor
* @param ky vertical skew factor
* @param px pivot on x-axis
* @param py pivot on y-axis
*/
void setSkew(float kx, float ky, float px, float py);
/**
* Sets Matrix to skew by kx and ky, about a pivot point at (0, 0).
* @param kx horizontal skew factor
* @param ky vertical skew factor
*/
void setSkew(float kx, float ky);
/**
* Sets Matrix to Matrix a multiplied by Matrix b. Either a or b may be this.
*
* Given:
*
* | A B C | | J K L |
* a = | D E F |, b = | M N O |
* | G H I | | P Q R |
*
* sets Matrix to:
*
* | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
* a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
* | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
*
* @param a Matrix on left side of multiply expression
* @param b Matrix on right side of multiply expression
*/
void setConcat(const Matrix& a, const Matrix& b);
/**
* Preconcats the matrix with the specified scale. M' = M * S(sx, sy)
*/
void preTranslate(float dx, float dy);
/**
* Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M
*/
void preScale(float sx, float sy, float px, float py);
/**
* Preconcats the matrix with the specified scale. M' = M * S(sx, sy)
*/
void preScale(float sx, float sy);
/**
* Preconcats the matrix with the specified rotation. M' = M * R(degrees, px, py)
*/
void preRotate(float degrees, float px, float py);
/**
* Preconcats the matrix with the specified rotation. M' = M * R(degrees)
*/
void preRotate(float degrees);
/**
* Preconcats the matrix with the specified skew. M' = M * K(kx, ky, px, py)
*/
void preSkew(float kx, float ky, float px, float py);
/**
* Preconcats the matrix with the specified skew. M' = M * K(kx, ky)
*/
void preSkew(float kx, float ky);
/**
* Preconcats the matrix with the specified matrix. M' = M * other
*/
void preConcat(const Matrix& other);
/**
* Postconcats the matrix with the specified translation. M' = T(dx, dy) * M
*/
void postTranslate(float dx, float dy);
/**
* Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M
*/
void postScale(float sx, float sy, float px, float py);
/**
* Postconcats the matrix with the specified scale. M' = S(sx, sy) * M
*/
void postScale(float sx, float sy);
/**
* Postconcats the matrix with the specified rotation. M' = R(degrees, px, py) * M
*/
void postRotate(float degrees, float px, float py);
/**
* Postconcats the matrix with the specified rotation. M' = R(degrees) * M
*/
void postRotate(float degrees);
/**
* Postconcats the matrix with the specified skew. M' = K(kx, ky, px, py) * M
*/
void postSkew(float kx, float ky, float px, float py);
/**
* Postconcats the matrix with the specified skew. M' = K(kx, ky) * M
*/
void postSkew(float kx, float ky);
/**
* Postconcats the matrix with the specified matrix. M' = other * M
*/
void postConcat(const Matrix& other);
/**
* If this matrix can be inverted, return true and if inverse is not null, set inverse to be the
* inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false.
*/
bool invert(Matrix* inverse) const {
if (this->isIdentity()) {
if (inverse) {
inverse->reset();
}
return true;
}
return this->invertNonIdentity(inverse);
}
bool invertible() const;
/**
* Maps src Point array of length count to dst Point array of equal or greater length. Point are
* mapped by multiplying each Point by Matrix. Given:
*
* | A B C | | x |
* Matrix = | D E F |, pt = | y |
* | G H I | | 1 |
*
* where
*
* for (i = 0; i < count; ++i) {
* x = src[i].fX
* y = src[i].fY
* }
*
* each dst Point is computed as:
*
* |A B C| |x| Ax+By+C Dx+Ey+F
* Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
* |G H I| |1| Gx+Hy+I Gx+Hy+I
*
* src and dst may point to the same storage.
*
* @param dst storage for mapped Point
* @param src Point to transform
* @param count number of Point to transform
*/
void mapPoints(Point dst[], const Point src[], int count) const;
/**
* Maps pts Point array of length count in place. Point are mapped by multiplying each Point by
* Matrix. Given:
*
* | A B C | | x |
* Matrix = | D E F |, pt = | y |
* | G H I | | 1 |
*
* where
*
* for (i = 0; i < count; ++i) {
* x = pts[i].fX
* y = pts[i].fY
* }
*
* each resulting pts Point is computed as:
*
* |A B C| |x| Ax+By+C Dx+Ey+F
* Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
* |G H I| |1| Gx+Hy+I Gx+Hy+I
*
* @param pts storage for mapped Point
* @param count number of Point to transform
*/
void mapPoints(Point pts[], int count) const {
this->mapPoints(pts, pts, count);
}
/**
* Maps Point (x, y) to result. Point is mapped by multiplying by Matrix. Given:
*
* | A B C | | x |
* Matrix = | D E F |, pt = | y |
* | G H I | | 1 |
*
* result is computed as:
*
* |A B C| |x| Ax+By+C Dx+Ey+F
* Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
* |G H I| |1| Gx+Hy+I Gx+Hy+I
*
* @param x x-axis value of Point to map
* @param y y-axis value of Point to map
* @param result storage for mapped Point
*/
void mapXY(float x, float y, Point* result) const;
/**
* Returns Point (x, y) multiplied by Matrix. Given:
*
* | A B C | | x |
* Matrix = | D E F |, pt = | y |
* | G H I | | 1 |
*
* result is computed as:
*
* |A B C| |x| Ax+By+C Dx+Ey+F
* Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
* |G H I| |1| Gx+Hy+I Gx+Hy+I
*
* @param x x-axis value of Point to map
* @param y y-axis value of Point to map
* @return mapped Point
*/
Point mapXY(float x, float y) const {
Point result = {};
this->mapXY(x, y, &result);
return result;
}
/**
* Sets dst to bounds of src corners mapped by Matrix.
*/
void mapRect(Rect* dst, const Rect& src) const;
/**
* Sets rect to bounds of rect corners mapped by Matrix. Returns true if mapped corners are
* computed rect corners. Returned value is the same as calling rectStaysRect().
*/
void mapRect(Rect* rect) const {
mapRect(rect, *rect);
}
/**
* Returns bounds of src corners mapped by Matrix.
*/
Rect mapRect(const Rect& src) const {
Rect dst = {};
mapRect(&dst, src);
return dst;
}
/** Compares a and b; returns true if a and b are numerically equal. Returns true even if sign
* of zero values are different. Returns false if either Matrix contains NaN, even if the other
* Matrix also contains NaN.
*/
friend bool operator==(const Matrix& a, const Matrix& b);
/**
* Compares a and b; returns true if a and b are not numerically equal. Returns false even if
* sign of zero values are different. Returns true if either Matrix contains NaN, even if the
* other Matrix also contains NaN.
*/
friend bool operator!=(const Matrix& a, const Matrix& b) {
return !(a == b);
}
/**
* Returns the minimum scaling factor of Matrix by decomposing the scaling and skewing elements.
* Returns -1 if scale factor overflows or Matrix contains perspective.
*/
float getMinScale() const;
/**
* Returns the maximum scaling factor of Matrix by decomposing the scaling and skewing elements.
* Returns -1 if scale factor overflows or Matrix contains perspective.
*/
float getMaxScale() const;
/**
* Returns true if all elements of the matrix are finite. Returns false if any
* element is infinity, or NaN.
*/
bool isFinite() const;
/**
* Returns reference to const identity Matrix. Returned Matrix is set to:
*
* | 1 0 0 |
* | 0 1 0 |
* | 0 0 1 |
*
* @return const identity Matrix
*/
static const Matrix& I();
/**
* Returns reference to a const Matrix with invalid values. Returned Matrix is set to:
*
* | FLT_MAX FLT_MAX FLT_MAX |
* | FLT_MAX FLT_MAX FLT_MAX |
* | FLT_MAX FLT_MAX FLT_MAX |
*
* @return const invalid Matrix
*/
static const Matrix& Invalid();
private:
float values[9];
/**
* Matrix organizes its values in row order. These members correspond to each value in Matrix.
*/
static constexpr int SCALE_X = 0; //!< horizontal scale factor
static constexpr int SKEW_X = 1; //!< horizontal skew factor
static constexpr int TRANS_X = 2; //!< horizontal translation
static constexpr int SKEW_Y = 3; //!< vertical skew factor
static constexpr int SCALE_Y = 4; //!< vertical scale factor
static constexpr int TRANS_Y = 5; //!< vertical translation
static constexpr int PERSP_0 = 6; //!< input x perspective factor
static constexpr int PERSP_1 = 7; //!< input y perspective factor
static constexpr int PERSP_2 = 8; //!< perspective bias
void setScaleTranslate(float sx, float sy, float tx, float ty);
bool invertNonIdentity(Matrix* inverse) const;
bool getMinMaxScaleFactors(float results[2]) const;
};
} // namespace tgfx
|
1184893257/libpag
|
tgfx/include/gpu/opengl/GLRenderTarget.h
|
<reponame>1184893257/libpag
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// unless required by applicable law or agreed to in writing, software distributed under the
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
// either express or implied. see the license for the specific language governing permissions
// and limitations under the license.
//
/////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "core/ImageInfo.h"
#include "gpu/RenderTarget.h"
#include "gpu/opengl/GLFrameBuffer.h"
#include "gpu/opengl/GLTexture.h"
namespace tgfx {
class GLInterface;
/**
* Represents a OpenGL 2D buffer of pixels that can be rendered to.
*/
class GLRenderTarget : public RenderTarget {
public:
/**
* Wraps an OpenGL frame buffer into GLRenderTarget. Please pass the number of samples-per-pixel
* in the sampleCount parameter if the frame buffer was constructed with MSAA enabled. Caller must
* ensure the backend frame buffer is valid for the lifetime of returned GLRenderTarget.
*/
static std::shared_ptr<GLRenderTarget> MakeFrom(Context* context,
const GLFrameBuffer& frameBuffer, int width,
int height, ImageOrigin origin,
int sampleCount = 1);
/**
* Wraps an OpenGL frame buffer into GLRenderTarget. Please pass the number of samples-per-pixel
* in the sampleCount parameter if the frame buffer was constructed with MSAA enabled. The
* returned GLRenderTarget takes ownership of the backend frame buffer.
*/
static std::shared_ptr<GLRenderTarget> MakeAdopted(Context* context,
const GLFrameBuffer& frameBuffer, int width,
int height, ImageOrigin origin,
int sampleCount = 1);
/**
* Returns the GLFrameBuffer associated with this render target.
*/
GLFrameBuffer glFrameBuffer() const {
return renderTargetFBInfo;
}
protected:
void onRelease(Context* context) override;
private:
GLFrameBuffer textureFBInfo = {};
GLFrameBuffer renderTargetFBInfo = {};
unsigned msRenderBufferID = 0;
unsigned textureTarget = 0;
bool externalTexture = false;
/**
* Creates a new render target which uses specified texture as pixel storage. Caller must ensure
* texture is valid for the lifetime of returned render target.
*/
static std::shared_ptr<GLRenderTarget> MakeFrom(Context* context, const GLTexture* texture,
int sampleCount = 1);
GLRenderTarget(int width, int height, ImageOrigin origin, int sampleCount,
GLFrameBuffer frameBuffer, unsigned textureTarget = 0);
void clear(const GLInterface* gl) const;
void resolve(Context* context) const;
/**
* Copies a rect of pixels to dstPixels with specified color type, alpha type and row bytes. Copy
* starts at (srcX, srcY), and does not exceed Surface (width(), height()). Pixels are copied
* only if pixel conversion is possible. Returns true if pixels are copied to dstPixels.
*/
bool readPixels(Context* context, const ImageInfo& dstInfo, void* dstPixels, int srcX = 0,
int srcY = 0) const;
friend class GLSurface;
friend class GLCanvas;
friend class Surface;
};
} // namespace tgfx
|
1184893257/libpag
|
tgfx/src/core/vectors/web/WebMask.h
|
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// unless required by applicable law or agreed to in writing, software distributed under the
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
// either express or implied. see the license for the specific language governing permissions
// and limitations under the license.
//
/////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <emscripten/val.h>
#include "core/Mask.h"
namespace tgfx {
class WebMask : public Mask {
public:
explicit WebMask(int width, int height, emscripten::val webMask)
: Mask(width, height), webMask(webMask) {
}
void fillPath(const Path& path) override;
bool fillText(const TextBlob* textBlob) override;
bool strokeText(const TextBlob* textBlob, const Stroke& stroke) override;
std::shared_ptr<Texture> makeTexture(Context* context) const override;
private:
bool drawText(const TextBlob* textBlob, const Stroke* stroke = nullptr);
emscripten::val webMask = emscripten::val::null();
};
} // namespace tgfx
|
BFL-lab/flip
|
src/flip.h
|
<reponame>BFL-lab/flip
/****************************************************************************
* flip.h version 2.0.2 *
* *
* Copyright (C) 1997 OGMP *
* (Organelle Genome Megasequencing Project), *
* Departement de Biochimie, *
* Universite de Montreal, *
* C.P. 6128, succursale Centre-ville, *
* Montreal, Quebec, Canada, H3C 2J7 *
* *
* Programming: <NAME> (OGMP) *
* Project management: <NAME> (OGMP) *
* E-Mail information: <EMAIL> *
* *
* This software is distributed under the GNU GENERAL PUBLIC LICENSE, as *
* published by the Free Software Foundation. A copy of version 2 of this *
* license should be included in a file called COPYING. If not, write to the *
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
****************************************************************************/
/*-----------------------------------------------------------------------------
flip.h - header file for flip.c
---------------------------------------------------------------------------*/
/*--------------------------
CONSTANTS
--------------------------*/
#define CODON_LG 3 /* The length (in nucleotide) of a codon */
#define MAX_LINE_LG 5000 /* The maximum line length of ANY file read by
flip. Longer lines are truncated */
#define MAX_SEQ_LG 4000000 /* The maximum length a sequence (including all
ogmp spec. chars and spaces) can have */
#define NUC_PER_LINE 60 /* Maximum nb of nuc (including spec. ogmp chars
and spaces) to print on a line in all output
files */
#define AA_PER_LINE 60 /* Maximum nb of aa (including *) to print in
prot.lst and prot.src on a given line */
#define NB_FRAMES 6 /* Six frames total */
#define NB_CHARS 256 /* Number of chars in ascii set */
#define COMPL 1 /* Cst to indicate that some operation has to be
done on file 'compl' */
#define NOCOMPL 0 /* Cst to indicate that some operation has to be
done on file 'nocompl' */
#define DIR_LENGTH 3 /* The length of the arrow (==>) in an annot. */
#define MAX_CTX_LG 12 /* The context is composed of two chunks of nucs
This is the maximum length each of these can
have */
#define VERSION "2.1.2" /* Flip's current version number */
/* Parameters default values */
#define DEF_FASTA_FORMAT 0 /* Default is not to put a '*' after each
contig in prot.lst and prot.src */
#define DEF_GET_DNA 0 /* Default is not to create the file
prot.lst.dna */
#define DEF_NUMBER_PROT 0 /* Default is not to append _<prot_nb> after
the contig name in the output files to
indicate the protein number */
#define DEF_SILENT 0 /* Default is to be verbose (ie display some
informative messages */
#define DEF_CODE_ID 1 /* The default genetic code number (Basic) */
#define DEF_CIRCULAR 0 /* Whether genome is circular or not (default
linear) */
#define DEF_MIN_CODING_REG_LG 20 /* Default minimum length an orf must have in
order to be reported by flip. The stop
codon(if any) is ignored during lg calc */
#define DEF_MIN_PROT_LG 0 /* Default minimum length (calculated from the
first start codon) an orf must have in
order to be reported by flip. The stop
codon(if any) is ignored during lg calc.
If set to 0, the orf does not even need to
have a start to be reported */
#define DEF_TRANS_ALL 0 /* Whether to produce prot.6rf or not
(defaults to no) */
#define DEF_FORCE_MET 0 /* The default value of param.force_met (see
this field for more description) */
/* Default output file names */
#define PROT_6RF_NAME "prot.6rf"
#define PROT_LST_DNA_NAME "prot.lst.dna"
#define PROT_LST_NAME "prot.lst"
#define PROT_SRC_NAME "prot.src"
#define NOCOMPL_NAME "nocompl"
#define COMPL_NAME "compl"
#define PROT_PRM_NAME "prot.prm"
/*----------------------
MACROS
----------------------*/
#define MIN(a,b) ( ((a) < (b)) ? (a) : (b) )
#define MAX(a,b) ( ((a) > (b)) ? (a) : (b) )
/* Is a valid genetic code_id or not */
/* Valid: 1..6, 9..19 */
#define IS_VALID_CODE_ID(a) ( ((a) > 0) && ((a) <= NB_CODES) && ((a) != 7) \
&& ((a) != 8) )
/* Returns 1 if two frame ids refer to frames that are on the same strand */
/* Frame ids on forw strand: 0,1,2 */
/* Frame ids on back strand: 3,4,5 */
#define SAME_STRAND(a,b) ( (( (a)<(NB_FRAMES/2) ) && ( (b)<(NB_FRAMES/2) )) ||\
(( (a)>=(NB_FRAMES/2) ) && ( (b)>=(NB_FRAMES/2) )) )
/*----------------------
TYPEDEFS
----------------------*/
typedef char CODON[CODON_LG+1]; /* A codon */
typedef struct pos_list{ /* A list of char pos in a string */
long int val; /* The pos (0..str_lg-1) */
struct pos_list *next; /* Pointer on next element in list */
} POS_LIST;
typedef struct string_lst{ /* A list of strings */
char *str; /* The string */
struct string_lst *next; /* Pointer on next element in list */
} STRING_LST;
typedef struct annot_lst{ /* List of all annots in a contig */
long int nb_nuc_bef; /* This includes ALL nucs and OGMP chars that
lie BEFORE an annot in a contig. SPACES ARE
NOT INCLUDED */
char *text; /* The annot's text */
struct annot_lst *next; /* Pointer on next element in list */
} ANNOT_LIST;
typedef struct ctg { /* A contig */
char *name; /* The full contig header */
char seq[MAX_SEQ_LG+1]; /* The original sequence fetched from the
input file associated to the contig. It
includes all OGMP chars and spaces
(see function get_next_ctg). Original
casing in input file is preserved */
long int seq_lg; /* The length of the above string */
char *seq_no_blk; /* The sequence but with all the blanks
removed */
long int seq_no_blk_lg; /* Length of the above sequence */
char *clean_seq; /* The sequence with all blanks and spec
OGMP chars removed, uppercased. It
should only contain ACGTN */
long int clean_seq_lg; /* Length of the above seq. */
char *compl_clean_seq; /* The cleaned sequence, reversed and
complemented */
char *compl_seq_no_blk; /* Seq_no_blk reversed and complemented */
POS_LIST *seq_pos; /* Pointer on a list of all the positions
in the original sequence of spec OGMP
chars and spaces */
POS_LIST *seq_no_blk_pos; /* Pointer on a list of all the positions
in the seq_no_blk of spec OGMP chars */
POS_LIST *compl_seq_pos; /* Pointer on a list of all the positions
in the reversed compl. sequence of
spec OGMP chars and spaces */
POS_LIST *compl_seq_no_blk_pos; /* Pointer on a list of all the positions
in the compl_seq_no_blk of spec OGMP
chars */
ANNOT_LIST *annot_lst; /* Pointer on the list of (ordered) annots
for the forw strand */
ANNOT_LIST *compl_annot_lst; /* Pointer on the list of (ordered) annots
for the backw strand */
} CTG;
typedef struct prot { /* An orf */
char *ctg_name; /* Full contig header the orf was found in */
char *aa; /* The orf's complete aa sequence */
long int aa_lg; /* Length of the above string */
char *dna; /* The DNA sequence associated to the aa sequence
When translating the DNA sequence w/ the corresp.
genetic code, you should obtain AA seq, no matter
the strand on which it lies */
long int dna_lg; /* Length of the above string */
long int length; /* Length of the above string, but will not include
the ending '*' if any */
struct prot *next; /* Pointer on the next orf found */
long int begin; /* Index of the nucleotide (1..ctg_lg) at which the
orf begins. If the orf is on the reversed strand,
'begin' refers to the nuc at which the orf ENDS*/
long int end; /* Index of the nucleotide (1..ctg_lg) at which the
orf ends. If the orf is on the reversed strand,
'end' refers to the nuc at which the orf BEGINS*/
int strand; /* 1 if the orf was found on the reverse strand, 0
otherwise */
char *comment; /* All aas upstream from the orf's start codon. If
min_prot_lg is 0, then this comment is empty */
long int comment_lg; /* The length of the above string */
char *context; /* Some context information (some nucs correspoding
to the start and end of the orf, see get_context
for exact context definition) */
} PROT;
typedef struct { /* The application's parameters */
int code_id; /* The genetic code number used */
int circular; /* Whether the gennome is circular or not */
long int min_coding_reg_lg; /* Minimum length an orf must have in order
to be reported by flip. The stop codon
(if any) is ignored during lg calc */
long int min_prot_lg; /* Minimum length (calculated from the
first start codon) an orf must have in
order to be reported by flip. The stop
codon(if any) is ignored during lg calc.
If set to 0, the orf does not even need to
have a start to be reported */
int trans_all; /* 1 if prot.6rf must be produced */
char *s_file; /* Name of the input file */
int *starts; /* Array of 125 ints, one for each codon.
start[x] = 1 iff x is a codon index (see
get_codon_idx) of a start codon */
int force_met; /* 1 => if the first codon of a region is a
start then it's automatically translated
as a metionine ('M'). Default 0. */
int silent; /* Boolean. To display or not some
informative messages */
int number_prot; /* Boolean. Append (or not) "_<protein_nb>"
to the contig name in the output files
to indicate the protein number */
int get_dna; /* Boolean. Indicates if prot.lst.dna
should be produced */
int fasta_format; /* Boolean. Whether or not to separate the
contigs of compl and nocompl by '*' */
} PARAM;
typedef struct frame{ /* Data associated to the reading frames */
/* 6 frames, indexed 0,1,2,3,4,5. Frame 0 and 5 are
always 'in sync'. Same for 1 and 4, 2 and 3 */
char *aa; /* The complete aa sequence obtained when translating
the whole frame */
long int aa_lg; /* Length of the above string */
long int *stop; /* The positions (0..aa_lg-1) of the aas which are stop
codons, according to the current gcode */
long int nb_stop; /* The number of stops in the frame */
long int *start; /* The positions (0..aa_lg-1) of the aas which are
start codons, according to the current gcode */
long int nb_start; /* The number of starts in the frame */
int offset; /* The number of leading nucs (in the cleaned (for fw)
or compl_clean (for back) sequence) discarded before
translation. Frames 0,1,2 always have 0,1,2 (resp.)
offset */
} FRAME[NB_FRAMES];
/*----------------------
PROTOTYPES
----------------------*/
int get_codon_idx( char *s, int idx[] );
int get_next_ctg( FILE *file, CTG *ctg, int comp[], int is_nuc[],
int *read_ctg, PARAM *param, int is_seq_char[] );
int is_blank_line( char *line );
char *trim_seq( char string[] );
void add_contig( CTG **mf, char *name, char *cur_seq, CTG **last_ctg );
void print_ctg( CTG *ctg );
void fill_ctg( CTG *ctg, int comp[], int is_nuc[] );
void mem_err();
void read_err( char *fname );
void trans_all( CTG *ctg, char code[], FRAME frame, int idx[],
PARAM *param );
void translate( FRAME f, char *seq, long int start, long int end,
int idx[], PARAM *p, char code[] );
void init_arrays( int idx[], int comp[], int is_nuc[], int is_aa[],
int is_seq_char[] );
void open_all_files( FILE **prot_lst_dna, FILE **prot_6rf , FILE **seq_file,
FILE **prot_lst, FILE **prot_src, PARAM *param,
FILE **nocompl, FILE **compl, char *seq_file_name );
char *compl_seq( char seq[], long int lg, int comp[] );
void update_prot_6rf( FILE *prot_6rf, FRAME frame, CTG *ctg );
void close_all_files( FILE **prot_lst_dna, FILE **prot_6rf, FILE **seq_file,
FILE **prot_lst, FILE **prot_src, FILE **nocompl,
FILE **compl, PARAM *param );
void find_prot( CTG *ctg, PROT **prot, PARAM *param, FRAME frame );
long int get_p_start( FRAME f, long int r_start, long int r_end,
long int *cur_s_idx );
void add_prot( PROT **prot, PROT **last_prot, long int r_start,
long int r_end, long int p_start, FRAME f, PARAM *param,
CTG *ctg, int f_nb , long int l );
void update_prot_lst_src( PROT **sorted_prot, int nb_prot, FILE *prot_lst,
FILE *prot_src, int number_prot );
void free_mem( CTG *ctg, PROT *prot, FRAME frame, PROT **sorted_prot );
void print_pos( FRAME frame, char *name );
void add_annot( ANNOT_LIST **lst_start, ANNOT_LIST **lst_end,
ANNOT_LIST **compl_lst_start, ANNOT_LIST **compl_lst_end,
char *annot, long int nb_nuc, int *prec_cont );
void update_seq_file( CTG *ctg, FILE *nocompl, int is_compl, int nb_ctg,
int nb_non_empty_ctg, int fasta_format );
void update_nocompl( CTG *ctg, FILE *compl );
int get_nb_spec( POS_LIST **pos_ptr, long int start, long int end );
int ends_with_bksl( char *s );
void get_context( PROT *prot, CTG *ctg );
void parse_cmd_line( int argc, char *argv[], PARAM *param, int is_nuc[],
int is_aa[], char all_codes[NB_CODES][NB_CODONS],
int all_starts[NB_CODES][NB_CODONS], char **code,
int idx[] );
void usage();
int get_starts( char *start_string, PARAM *param, int is_nuc[], int idx[],
char *code );
int get_deviations( char *start_string, int is_nuc[], int is_aa[],
char *code );
void parse_prot_prm( PARAM *param, char **dev_string,
char **starts_string );
int is_comment( char *string );
void parse_prot_prm_err( char *line );
long int nuc_lg( PROT *prot, CTG *ctg, long int seq_start, long int seq_end );
void print_stops( FRAME frame );
void find_wrap_stops( FRAME frame, CTG *ctg, int idx[], char code[],
PARAM *param );
void find_wrap_prot( PROT **prot, PROT **last_prot, CTG *ctg, PARAM *param,
FRAME frame );
long int get_wrap_rg_lg( CTG *ctg, FRAME frame, int order[], int f );
long int get_wrap_prot_lg( CTG *ctg, FRAME frame, int order[], int start_f,
int end_f, long int r_lg, int *start_o_idx,
long int *start_pos );
void add_wrap_prot( PROT **prot, PROT **last_prot, CTG *ctg, PARAM *param,
FRAME frame, int order[], int f, int last_f,
int start_o_idx, long int start_pos, long int r_lg,
long int prot_lg );
void get_wrap_aa( PROT *new_prot, PARAM *param, FRAME frame, int f,
CTG *ctg, char code[], int idx[], int order[],
long int r, int start_o_idx, long int start_pos );
void get_wrap_pos( PROT *new_prot, CTG *ctg, FRAME frame, int f,
int last_f, int start_o_idx, long int start_pos,
PARAM *param, int order[] );
void get_wrap_comment( PROT *new_prot, FRAME frame, int f, CTG *ctg,
char code[], int idx[], int order[],
int start_o_idx, long int start_pos, long int size);
void get_wrap_context( PROT *prot, CTG *ctg );
char *find_arrow_ptr( char *annot, char *arrow_ptr, char *compl_arrow_ptr );
int is_valid_line( char *line, int is_seq_char[] );
void fix_starts( CTG *ctg, PROT *prot, PARAM *param, int idx[],
int is_nuc[], int comp[] );
int prot_compare( const void *p1, const void *p2 );
void sort_prots( PROT *prot, PROT ***sorted_prot, int *nb_prot );
int is_valid_sfile( char *fname );
void get_dna_seq( PROT *prot, CTG *ctg );
void update_prot_lst_dna( PROT **sorted_prot, long int nb_prot,
FILE *prot_lst_dna, int number_prot );
|
BFL-lab/flip
|
src/flip.c
|
/****************************************************************************
* flip.c version 2.0.2 *
* *
* Copyright (C) 1997 OGMP *
* (Organelle Genome Megasequencing Project), *
* Departement de Biochimie, *
* Universite de Montreal, *
* C.P. 6128, succursale Centre-ville, *
* Montreal, Quebec, Canada, H3C 2J7 *
* *
* Programming: <NAME> (OGMP) *
* Project management: <NAME> (OGMP) *
* E-Mail information: <EMAIL> *
* *
* This software is distributed under the GNU GENERAL PUBLIC LICENSE, as *
* published by the Free Software Foundation. A copy of version 2 of this *
* license should be included in a file called COPYING. If not, write to the *
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
****************************************************************************/
/*----------------------------------------------------------------------------
flip.c
An orf finder/translator
---------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <ctype.h>
#include "code.h" /* All the genetic codes & their start codons */
#include "flip.h"
/*----------------------
GLOBAL VARIABLES
----------------------*/
PARAM param; /* The application's parameters */
CTG ctg; /* Current contig */
FILE *seq_file=NULL; /* The input file pointer */
char *code; /* Genetic code used. 125 ints (one foreach codon
idx). */
FRAME frame; /* The 6 reading frames */
int idx[NB_CHARS]; /* Used to get the index of each nuc (see
get_codon_idx) */
int comp[NB_CHARS]; /* To find the complement of a nucleotide */
int is_nuc[NB_CHARS]; /* Whether a char is a nuc or not */
int is_aa[NB_CHARS]; /* Whether a char is a valid amino acid or not */
int is_seq_char[NB_CHARS]; /* If a char is a sequencing char or not (ie
aAcCgGtTnNxX#@!+- or any whitespace*/
FILE *prot_6rf=NULL; /* Pointer on the file of all 6 reading frames */
FILE *prot_lst_dna=NULL; /* Pointer on the file prot.lst.dna */
FILE *prot_lst=NULL; /* Pointer on the file prot.lst */
FILE *prot_src=NULL; /* Pointer on the file prot.src */
PROT *prot; /* Pointer on the list of proteins found */
FILE *nocompl=NULL; /* Pointer on the file nocompl */
FILE *compl=NULL; /* Pointer on the file compl */
int read_ctg = 0; /* If a ctg has been read or not */
int nb_non_empty_ctg = 0; /* Nb of non-empty (ie at least one nuc or OGMP
spec char) contig written to compl and nocompl
so far */
int nb_ctg = 0; /* Nb of contigs (empty or non-emptyz) written to
compl and nocompl so far */
PROT **sorted_prot; /* array of sorted proteins */
int nb_prot; /* the number of found proteins/orf (elements in
sorted_prot) */
/*----------------------
MAIN PROGRAM
----------------------*/
int main( int argc, char *argv[] ){
printf( "Turbo flip %s\n", VERSION );
init_arrays( idx, comp, is_nuc, is_aa, is_seq_char );
parse_cmd_line( argc, argv, ¶m, is_nuc, is_aa, all_codes, all_starts,
&code, idx );
open_all_files( &prot_lst_dna, &prot_6rf, &seq_file, &prot_lst, &prot_src,
¶m, &nocompl, &compl, param.s_file );
while( get_next_ctg( seq_file, &ctg, comp, is_nuc, &read_ctg, ¶m,
is_seq_char ) )
{
#ifdef DEBUG
print_ctg( &ctg );
#endif
prot = NULL;
sorted_prot = NULL;
if( ctg.seq_lg )
{
trans_all( &ctg, code, frame, idx, ¶m );
#ifdef DEBUG
print_stops( frame );
#endif
if( param.trans_all ) update_prot_6rf( prot_6rf, frame, &ctg );
find_prot( &ctg, &prot, ¶m, frame );
sort_prots( prot, &sorted_prot, &nb_prot );
if( param.force_met )
fix_starts( &ctg, prot, ¶m, idx, is_nuc, comp );
update_prot_lst_src( sorted_prot, nb_prot, prot_lst, prot_src,
param.number_prot );
if( param.get_dna )
update_prot_lst_dna( sorted_prot, nb_prot, prot_lst_dna,
param.number_prot );
}
update_seq_file( &ctg, nocompl, NOCOMPL, nb_ctg, nb_non_empty_ctg,
param.fasta_format );
update_seq_file( &ctg, compl, COMPL, nb_ctg, nb_non_empty_ctg,
param.fasta_format );
//free_mem( &ctg, prot, frame, sorted_prot );
nb_ctg++;
if( ctg.seq_lg ) nb_non_empty_ctg++;
}
close_all_files( &prot_lst_dna, &prot_6rf, &seq_file, &prot_lst, &prot_src,
&nocompl, &compl, ¶m);
exit(0);
}
/*----------------------
SUBROUTINES
----------------------*/
/*-----------------------------------------------------------------------------
Name: print_stops
Description: Prints all the positions (0..frame_lg-1) of the stops and starts
for all the frames.
Returns: Nothing
---------------------------------------------------------------------------*/
void print_stops(
FRAME frame /* All the six frames */
)
{
int i,j; /* Loop counters */
/* Print all stops */
for( i=0; i < NB_FRAMES ; i++ ){
printf( "Stop pos for frame %d (offset %d):\n\t", i, frame[i].offset );
for( j=0; j < frame[i].nb_stop ; j++ )
printf( "%ld ", frame[i].stop[j] );
printf( "\n" );
}
/* Print all starts */
printf( "\n" );
for( i=0; i < NB_FRAMES ; i++ ){
printf( "Start pos for frame %d (offset %d):\n\t", i, frame[i].offset );
for( j=0; j < frame[i].nb_start ; j++ )
printf( "%ld ", frame[i].start[j] );
printf( "\n" );
}
}
/*-----------------------------------------------------------------------------
Name: mem_err
Description: Prints an error message that a memory error occured and exits
with an exit status of 1
Returns: Nothing
---------------------------------------------------------------------------*/
void mem_err()
{
fprintf( stderr, "No more memory. Aborting.\n" );
exit(1);
}
/*-----------------------------------------------------------------------------
Name: get_codon_idx
Description: Returns the index associated to a given codon. All 125 codons
(yes, codons with 'N' are included and only uppercased codons
have a defined index) are numbered from 0 to 124. Here are the
first few:
AAA=0, AAC=1, AAG=2, AAT=3, AAN=4,
ATA=5, ATC=6, ATG=7, ATT=8, ATN=9, etc...
It is assumed that s points to a string that contains at least 3
chars
Returns: The index
---------------------------------------------------------------------------*/
int get_codon_idx(
char *s, /* The codon beginning */
int idx[] /* The index of all nucs (see global vars) */
)
{
return( ( 25 * idx[*s] ) + ( 5 * idx[ *(s+1) ] ) + idx[ *(s+2) ] );
}
/*-----------------------------------------------------------------------------
Name: get_next_ctg
Description: Gets the next contig in the input file and fills the current
contig structure. The input file is taken to be in masterfile or
fasta or extended fasta format. There's a limit on the length of
the lines in the file (see constants). Contig headers can be
anything (even duplicates). Verifies that there is a unique
contig if genome is circular.
Returns: 1 if there are no more contigs left to read, 0 otherwise
---------------------------------------------------------------------------*/
int get_next_ctg(
FILE *file, /* The input file's pointer */
CTG *ctg, /* Adress of the current contig structure */
int compl[], /* Array of complement foreach nuc */
int is_nuc[], /* Array telling if char is a nuc or not */
int *read_ctg, /* 1 if a contig was ALREADY read, else 0 */
PARAM *param, /* Adress of the param structure */
int is_seq_char[] /* Array telling if a char is one of
aAcCgGtTnNxX#@!+- or any whitespace*/
)
{
char line[MAX_LINE_LG+1]; /* Buffer. A line */
char *seq_start; /* Will point the start of the ctg's nuc
sequence */
int c; /* A nucleotide */
int line_lg; /* Length of the line read */
long int nb_nuc; /* nb of nucs read so far */
ANNOT_LIST *last_annot; /* Pointer on the last annot read */
ANNOT_LIST *compl_last_annot; /* pointer on the last annot of the list of
annots on the compl strand */
int first_line; /* 1 if current line is the 1st one read */
int prec_cont; /* 1 if the last line read was a line ending
with a "\" (continuation line) */
/* init section */
ctg->name = NULL;
ctg->annot_lst = last_annot = ctg->compl_annot_lst = compl_last_annot = NULL;
ctg->seq[0] = '\0';
nb_nuc = 0;
first_line = 1;
prec_cont = 0;
/* While not eof */
while( ( c = getc( file ) ) != EOF ){
/* A contig header */
if( c == '>' ) {
ungetc( c, file );
/* if we already read one, stop */
if( ctg->name != NULL ) break;
else
/* else, store it */
if( first_line )
if( fgets( line, MAX_LINE_LG, file ) != NULL ){
line_lg = strlen( line );
if( !(ctg->name = (char *) calloc( line_lg+1, sizeof(char) )) )
mem_err();
strcpy( ctg->name, line );
ctg->name[line_lg-1] = '\0'; /* Remove '\n' */
}
else read_err( param->s_file );
else break;
}
/* Then it's a nucleotide line (with optional leading digits) or annot or
blank line */
else{
ungetc( c, file );
if( fgets( line, MAX_LINE_LG, file ) != NULL ){
if( !is_blank_line( line ) )
if( line[0] != ';' ) {
if( prec_cont ){
fprintf( stderr, "Invalid continuation line:\t%s\n", line );
exit(1);
}
prec_cont = 0;
seq_start = trim_seq( line );
if( !is_valid_line( seq_start, is_seq_char ) ){
fprintf( stderr, "Invalid line in %s:\n%s\n", param->s_file,
line );
exit(1);
}
nb_nuc += strlen( seq_start );
strcat( ctg->seq, seq_start );
}
else add_annot( &(ctg->annot_lst), &last_annot,
&(ctg->compl_annot_lst), &compl_last_annot, line,
nb_nuc, &prec_cont );
}
else read_err( param->s_file );
} /* else */
first_line = 0;
} /* while */
/* Check that contig is unique if genome is circular */
if( param->circular && *read_ctg && ctg->name ){
fprintf( stderr, "Multiple contigs for circular genome. Aborting.\n" );
exit(1);
}
/* If contig is not empty and no header was found */
if( strlen( ctg->seq ) && !ctg->name ){
ctg->name = (char *) calloc( strlen( param->s_file ) + 2, sizeof(char) );
ctg->name[0] = '>';
strcpy( ctg->name + 1, param->s_file );
}
/* Fill missing info / adjust some info in ctg */
fill_ctg( ctg, comp, is_nuc );
if( strlen( ctg->seq ) ) *read_ctg = 1;
return( !( feof(file) && !ctg->name ) );
} /* read_seq_file */
/*-----------------------------------------------------------------------------
Name: is_blank_line
Description: Verifies if a line is composed entirely of whitespace chars
The null string is considered to be a blank line.
Returns: 1 if it is so, 0 otherwise
---------------------------------------------------------------------------*/
int is_blank_line(
char line[] /* Pointer on an array of characters */
)
{
int i;
for( i=0 ; i < strlen( line ) ; i++ ){
if( !isspace( line[i] ) ) return(0);
}
return(1);
}
/*-----------------------------------------------------------------------------
Name: read_err
Description: Prints an error message that a read error occured while reading
a given file and exit with an exit status of 1
Returns: Nothing
---------------------------------------------------------------------------*/
void read_err(
char *fname /* The name of the file in which a reading error
occured */
)
{
fprintf( stderr, "Unexpected read error on file %s. Aborting\n" , fname );
exit(1);
}
/*-----------------------------------------------------------------------------
Name: trim_seq
Description: Eliminates all the leading and trailing spaces in a string
Returns: A pointer on the beginning of the trimed sequence
---------------------------------------------------------------------------*/
char * trim_seq(
char string[] /* A pointer on the string to trim */
)
{
int i; /* loop counter */
/* this should trim the leading spaces and/or tabs */
while( (*string) != '\0' && ( isspace( *string ) || isdigit( *string ) ) ){
string++;
}
/* position just before the '\0' and "trim" the trailing spaces */
i = strlen( string ) - 1;
while( i >= 0 && isspace( string[i] ) ){
i--;
}
string[i+1] = '\0'; /* readjust the end */
return( string );
}
/*-----------------------------------------------------------------------------
Name: print_ctg
Description: Debug routine to print all the information stored in memory
regarding the current contig
Returns: Nothing
---------------------------------------------------------------------------*/
void print_ctg(
CTG *ctg /* pointer on the current contig */
)
{
char *seq_ptr; /* Tmp sequence ptr */
char chunk[NUC_PER_LINE+1]; /* Some nucleotides */
ANNOT_LIST *ptr; /* pointer on an annot list */
POS_LIST *pos_ptr; /* pointer on a list of positions */
/* Print original sequence, NUC_PER_LINE nucs per line */
if( ctg->name ) printf( "%s\n", ctg->name );
printf( "Seq_lg = %ld,clean_seq_lg = %ld,", ctg->seq_lg, ctg->clean_seq_lg );
printf( "seq_w_no_blanks_lg = %ld\n", ctg->seq_no_blk_lg );
if( ctg->seq )
for( seq_ptr = ctg->seq; strlen( seq_ptr ) > 0; ){
strncpy( chunk, seq_ptr, NUC_PER_LINE );
if( NUC_PER_LINE <= strlen( seq_ptr ) ) chunk[NUC_PER_LINE] = '\0';
printf( "%s\n", chunk );
seq_ptr +=
strlen( seq_ptr ) > NUC_PER_LINE ? NUC_PER_LINE : strlen( seq_ptr );
}
/* Print cleaned sequence, NUC_PER_LINE nucs per line */
if( ctg->name ) printf( "%s (cleaned)\n", ctg->name );
if( ctg->clean_seq )
for( seq_ptr = ctg->clean_seq; strlen( seq_ptr ) > 0; ){
strncpy( chunk, seq_ptr, NUC_PER_LINE );
if( NUC_PER_LINE <= strlen( seq_ptr ) ) chunk[NUC_PER_LINE] = '\0';
printf( "%s\n", chunk );
seq_ptr +=
strlen( seq_ptr ) > NUC_PER_LINE ? NUC_PER_LINE : strlen( seq_ptr );
}
printf( "\n" );
/* Print all the positions of the non-nucs (ie spaces and spec. ogmp chars)
in original sequence */
printf( "The non nuc pos (forw):\n" );
for( pos_ptr = ctg->seq_pos; pos_ptr; pos_ptr = pos_ptr->next )
printf( "%ld ", pos_ptr->val );
printf( "\n" );
/* Print all the non-nucs chars per se (ie spaces and spec. ogmp chars)
in original sequence */
printf( "The non nuc chars (forw):\n" );
for( pos_ptr = ctg->seq_pos; pos_ptr; pos_ptr = pos_ptr->next )
printf( "%c,", ctg->seq[ pos_ptr->val ] );
printf( "\n" );
/* Print all the positions of the non-nucs (ie spaces and spec. ogmp chars)
in reversed complemented sequence */
printf( "The non nuc pos (back):\n" );
for( pos_ptr = ctg->compl_seq_pos; pos_ptr; pos_ptr = pos_ptr->next )
printf( "%ld ", pos_ptr->val );
printf( "\n" );
/* Print all the non-nucs chars per se (ie spaces and spec. ogmp chars)
in reversed complemented sequence */
printf( "The non nuc chars (back):\n" );
for( pos_ptr = ctg->compl_seq_pos; pos_ptr; pos_ptr = pos_ptr->next )
printf( "%c,", ctg->seq[ ctg->seq_lg - pos_ptr->val - 1 ] );
printf( "\n" );
/* Print all the positions of the non-nucs (ie spec. ogmp chars)
in original sequence whose blanks have already been removed */
printf( "The seq_no_blk non nuc pos (forw):\n" );
for( pos_ptr = ctg->seq_no_blk_pos; pos_ptr; pos_ptr = pos_ptr->next )
printf( "%ld ", pos_ptr->val );
printf( "\n" );
/* Print all the positions of the non-nucs (ie spec. ogmp chars)
in reversed complemented sequence whose blanks have already been
removed */
printf( "The compl_seq_no_blk non nuc pos (back):\n" );
for( pos_ptr = ctg->compl_seq_no_blk_pos; pos_ptr; pos_ptr = pos_ptr->next )
printf( "%ld ", pos_ptr->val );
printf( "\n" );
/* print list of forw and back annotations */
printf( "Here is the list of all annotations (forw):\n" );
for( ptr = ctg->annot_lst ; ptr ; ptr = ptr->next )
printf( "%ld --- Text: %s", ptr->nb_nuc_bef, ptr->text );
printf( "Here is the list of all annotations (back):\n" );
for( ptr = ctg->compl_annot_lst ; ptr ; ptr = ptr->next )
printf( "%ld --- Text: %s", ptr->nb_nuc_bef, ptr->text );
}
/*-----------------------------------------------------------------------------
Name: fill_ctg
Description: Fills the remaining missing info in the current contig structure
(ie calculate seq_lg, complemented and reversed sequence, get
the position of all the non-nucs, etc...)
Returns: Nothing
---------------------------------------------------------------------------*/
void fill_ctg(
CTG *ctg, /* Pointer on current contig structure */
int comp [], /* Array of complemented nucs */
int is_nuc[] /* Array telling if a char is a nuc or not */
)
{
POS_LIST *ptr_int_list = NULL; /* beginning of list of non-nuc pos in
orig sequence (forw) */
POS_LIST *last_int = NULL; /* end of list of non-nuc pos in
original sequence (forw) */
POS_LIST *ptr_int_list2 = NULL; /* beginning of list of OGMP chars
in orig sequence w/no blanks */
POS_LIST *last_int2 = NULL; /* end of list of OGMP chars in
orig sequence w/no blanks */
char *seq_ptr = ctg->seq; /* beginning of original sequence */
POS_LIST *new_int, *new_int2; /* tmp new positions */
POS_LIST *cur_pos; /* pointer on a pos element */
char *clean_seq; /* pointer on the beginning of the
cleaned sequence */
char *seq_no_blk; /* pointer on the beginning of the
sequence w/no blanks */
char *cur_ptr1, *cur_ptr2; /* tmp seq ptrs */
long int i; /* loop counter */
long int nb_spaces; /* nb of spaces seen so far in orig
sequence */
char c; /* a nuc */
ANNOT_LIST *ptr; /* tmp pointer on an annot */
/* Allocate max space for cleaned seq. */
ctg->seq_lg = strlen( seq_ptr );
clean_seq = (char *) calloc( ctg->seq_lg + 1, sizeof( char ) );
seq_no_blk = (char *) calloc( ctg->seq_lg + 1, sizeof( char ) );
/* Compute the uppercased 'cleaned' (ie no other nuc. than ACGTN) sequence */
cur_ptr1 = clean_seq;
cur_ptr2 = seq_no_blk;
for( i=0 ; i < ctg->seq_lg ; i++ ){
c = seq_ptr[i];
/* if it's a nucleotide, add it in uppercase in clean sequence and as is
in seq w/no blanks */
if( is_nuc[c] ){
*cur_ptr1++ = toupper(c);
*cur_ptr2++ = c;
}
/* if not a nucleotide */
else{
/* add position of non-nuc in list of non-nuc associated to original
sequence*/
new_int = (POS_LIST *) malloc( sizeof( POS_LIST ) );
new_int->val = i, new_int->next = NULL;
if( last_int == NULL ) ptr_int_list = last_int = new_int;
else last_int->next = new_int, last_int = new_int;
/* If not a space add char to seq_no_blk. Add pos to list of non-nuc pos
for sequence w/no blanks */
if( !isspace(c) ){
*cur_ptr2++ = c;
new_int2 = (POS_LIST *) malloc( sizeof( POS_LIST ) );
new_int2->val = cur_ptr2 - seq_no_blk - 1, new_int2->next = NULL;
if( last_int2 == NULL ) ptr_int_list2 = last_int2 = new_int2;
else last_int2->next = new_int2, last_int2 = new_int2;
}
}
}
/* terminate cleaned sequence string and seq without blanks string */
*cur_ptr1 = '\0';
*cur_ptr2 = '\0';
/* update the info pointed to by ctg */
ctg->clean_seq = clean_seq;
ctg->clean_seq_lg = strlen( clean_seq );
ctg->seq_no_blk = seq_no_blk;
ctg->seq_no_blk_lg = strlen( seq_no_blk );
ctg->compl_seq_no_blk =
compl_seq( ctg->seq_no_blk, ctg->seq_no_blk_lg, comp );
ctg->compl_clean_seq = compl_seq( ctg->clean_seq, ctg->clean_seq_lg, comp );
ctg->seq_pos = ptr_int_list;
ctg->seq_no_blk_pos = ptr_int_list2;
/* Update positions in list of non-nuc positions for complementary seq */
ctg->compl_seq_pos = NULL;
for( cur_pos = ctg->seq_pos; cur_pos ; cur_pos = cur_pos->next ){
new_int = (POS_LIST *) malloc( sizeof( POS_LIST ) );
new_int->val = ctg->seq_lg - cur_pos->val - 1;
new_int->next = ctg->compl_seq_pos;
ctg->compl_seq_pos = new_int;
}
/* Update positions in list of non-nuc positions for complementary seq w/no
blanks */
ctg->compl_seq_no_blk_pos = NULL;
for( cur_pos = ctg->seq_no_blk_pos; cur_pos ; cur_pos = cur_pos->next ){
new_int = (POS_LIST *) malloc( sizeof( POS_LIST ) );
new_int->val = ctg->seq_no_blk_lg - cur_pos->val - 1;
new_int->next = ctg->compl_seq_no_blk_pos;
ctg->compl_seq_no_blk_pos = new_int;
}
/* Modify the nb_nuc_bef field of all the annots for ctg 'cause it includes
the spaces */
for( ptr = ctg->annot_lst ; ptr ; ptr = ptr->next ){
nb_spaces = 0;
for( cur_pos = ctg->seq_pos ; cur_pos ; cur_pos = cur_pos->next ){
if( cur_pos->val > ptr->nb_nuc_bef - 1 ) break;
if( isspace( ctg->seq[ cur_pos->val ] ) ) nb_spaces++;
}
ptr->nb_nuc_bef -= nb_spaces;
}
/* Adjust the field nb_nuc_bef of annots on compl strand (right now, they're
forw AND they take spaces into account !) */
for( ptr = ctg->compl_annot_lst ; ptr ; ptr = ptr->next ){
nb_spaces = 0;
for( cur_pos = ctg->compl_seq_pos ; cur_pos ; cur_pos = cur_pos->next ){
if( cur_pos->val > ctg->seq_lg - ptr->nb_nuc_bef - 1 ) break;
if( isspace( ctg->seq[ ctg->seq_lg - cur_pos->val - 1 ] ) ) nb_spaces++;
}
ptr->nb_nuc_bef = ctg->seq_lg - ptr->nb_nuc_bef - nb_spaces;
}
}
/*-----------------------------------------------------------------------------
Name: trans_all
Description: Translates the current contig in all six reading frames
Gets the stops and starts
Returns: Nothing
---------------------------------------------------------------------------*/
void trans_all(
CTG *ctg, /* pointer on current contig struct. */
char code[], /* genetic code used */
FRAME frame, /* the six reading frames */
int idx[], /* idx of all nucleotides */
PARAM *param /* application's parameters */
)
{
int i; /* loop counter */
int offset; /* the offset associated to a given frame (see FRAME
typedef) */
char *seq; /* a tmp sequence pointer */
long int aa_lg; /* length of the aa seq associated to a frame */
for( i=0; i < NB_FRAMES ; i++ )
{
offset = i < (NB_FRAMES/2) ?
i % CODON_LG : ( ctg->clean_seq_lg - (NB_FRAMES - i - 1) ) % CODON_LG;
frame[i].offset = offset;
seq = ( i >= NB_FRAMES/2 ) ? ctg->compl_clean_seq : ctg->clean_seq;
aa_lg =
ctg->clean_seq_lg < offset ? 0 : (ctg->clean_seq_lg - offset) / CODON_LG;
frame[i].aa_lg = aa_lg;
if( !(frame[i].aa = (char *) calloc( aa_lg + 1, sizeof(char) ) ) )
mem_err();
if( !(frame[i].stop = (long int*) calloc( aa_lg + 1, sizeof(long int) ) ) )
mem_err();
if( !(frame[i].start = (long int*) calloc( aa_lg + 1, sizeof(long int) ) ))
mem_err();
translate( &(frame[i]), seq, offset, ctg->clean_seq_lg - 1, idx, param,
code );
}
/* This will find all the wrap codons that yield a stop in a frame */
if( param->circular ) find_wrap_stops( frame, ctg, idx, code, param );
}
/*-----------------------------------------------------------------------------
Name: find_wrap_stops
Description: Examines all the wrap-around codons to see if there is a stop or
a start that crosses the split point. If so, the pos is put in
the frame where the stop/start begins. Note that this pos refers
to an aa that DOESN'T EXIST in the frame. It's always gonna be
aa_lg, where aa_lg is the current number of aa in the frame
Returns: Nothing
---------------------------------------------------------------------------*/
void find_wrap_stops(
FRAME frame, /* the six reading frame */
CTG *ctg, /* pointer on the current contig struct */
int idx[], /* index of all nucs */
char code[], /* genetic code used for translation */
PARAM *param /* application's parameters */
)
{
char *seq; /* tmp sequence pointer */
CODON codon; /* a codon */
int f; /* a frame id (0..5) */
int nb_ending; /* the number of trailing nuc in the cleaned sequence for
a given reading frame (ex: cleaned = ACGTACGT,
nb_ending = 2 for fr. 0, 1 for fr. 1 and 0 for fr. 2 */
int code_idx; /* a given codon index */
/* there cannot be a wrap-around prot for this case, so why bother finding
wrap-around codons */
if( ctg->clean_seq_lg < CODON_LG ) return;
/* Scan every frame */
for( f=0; f<NB_FRAMES; f++ ){
seq = ( f >= (NB_FRAMES/2) ) ? ctg->compl_clean_seq : ctg->clean_seq;
nb_ending = ( ctg->clean_seq_lg - frame[f].offset ) % CODON_LG;
/* If there are trailing nucs, there's a wrap-around codon */
if( nb_ending ){
strcpy( codon, seq + ctg->clean_seq_lg - nb_ending );
strncat( codon, seq, CODON_LG - nb_ending ) ;
codon[CODON_LG] = '\0';
code_idx = get_codon_idx( codon, idx );
/* Don't forget here that we store the pos of the AA in the frame that
would yield a stop */
if( code[ code_idx ] == '*' ){
frame[f].stop[ frame[f].nb_stop++ ] =
( ctg->clean_seq_lg - frame[f].offset ) / CODON_LG;
}
/* Don't forget here that we store the pos of the AA in the frame that
would yield a start */
if( param->starts[ code_idx ] ){
frame[f].start[ frame[f].nb_start++ ] =
( ctg->clean_seq_lg - frame[f].offset ) / CODON_LG;
}
} /* if */
} /* for */
}
/*-----------------------------------------------------------------------------
Name: translate
Description: Translate a given nucleotide sequence according to a given
genetic code. The routine translates each codon. Sequence is
assumed to be uppercased and to contain only ACGTN. If
seq_lg % 3 != 0, the trailing nucs are ignored.
Returns: Nothing
---------------------------------------------------------------------------*/
void translate(
FRAME f, /* a given frame */
char *seq, /* pointer on a given nuc sequence */
long int start, /* the first nuc of the region to translate
(0.seq_lg-1) */
long int end, /* the last nuc of the region to translate
(0.seq_lg-1) */
int idx[], /* index of all nucs */
PARAM *param, /* application's parameters */
char code[] /* the genetic code used */
)
{
char *last_ptr; /* ptr on the last nuc of the last codon to translate */
char *cur_ptr; /* ptr on first nuc of first codon to translate */
char *aa_ptr; /* pointer on beginning of resulting aa sequence */
char aa; /* a tmp amino acid */
int code_idx; /* the codon idx of a codon */
long int nb_stop; /* the nb of stops found so far */
long int nb_start; /* the nb of starts found so far */
long int pos; /* a given aa position */
/* init */
aa_ptr = f->aa;
nb_stop = 0;
nb_start = 0;
pos = 0;
/* if there are at least CODON_LG nucs to translate */
if( start + CODON_LG - 1 <= end ) {
last_ptr =
seq + end - ( CODON_LG - 1 ) - ( ( end - start + 1 ) % CODON_LG );
cur_ptr = seq + start;
/* translate all */
while( cur_ptr <= last_ptr ){
code_idx = get_codon_idx( cur_ptr, idx );
aa = code[ code_idx ];
*aa_ptr++ = aa;
/* store stop/start pos if current aa is stoip/start */
if( aa == '*' ) f->stop[nb_stop++] = pos;
if( param->starts[code_idx] ) f->start[nb_start++] = pos;
cur_ptr += CODON_LG;
pos++;
}
}
/* update */
*aa_ptr = '\0';
f->nb_start = nb_start;
f->nb_stop = nb_stop;
}
/*-----------------------------------------------------------------------------
Name: init_arrays
Description: performs some initialization of the basic arrays needed by
flip
Returns: Nothing
---------------------------------------------------------------------------*/
void init_arrays(
int idx[], /* Each nuc has an index, used to compute the
codon index of all codons. This is the array
of all nuc indexes */
int comp[], /* Each nuc has a complement (A->T T->A, etc...)
This is the array of all complements
(including the complement of all OGMP spec.
chars) */
int is_nuc[], /* Array telling, foreach char, if it's a
nucleotide (valid nucs are ACGTNXacgtnx) */
int is_aa[], /* Array telling, foreach char, if it's a valid
amino acid (valid aas are:
- every letter (upper or lower) except:
bBjJoOqQsSuUxXzZ
- * */
int is_seq_char[] /* will tell if a char is a sequencing char
(ie aAcCgGtTnNxX#@!+- or any whitespace) */
)
{
int i; /* loop counter */
/* Init is_seq_char array */
for( i=0; i < NB_CHARS ; i++ )
is_seq_char[i] = isspace(i);
is_seq_char['a'] = is_seq_char['A'] = 1;
is_seq_char['c'] = is_seq_char['C'] = 1;
is_seq_char['g'] = is_seq_char['G'] = 1;
is_seq_char['t'] = is_seq_char['T'] = 1;
//Modified by David To 12th April 2005
//Adding in "x" and "X"
is_seq_char['n'] = is_seq_char['N'] = is_seq_char['x'] = is_seq_char['X'] = 1;
is_seq_char['#'] = is_seq_char['@'] = is_seq_char['!'] = 1;
is_seq_char['+'] = is_seq_char['-'] = 1;
/* Init idx array */
idx['A'] = 0;
idx['C'] = 1;
idx['G'] = 2;
idx['T'] = 3;
idx['N'] = 4;
//Modified by <NAME> 12th April 2005
//Adding in "X"
idx['X'] = 4;
/* Init is_aa array */
for( i=0; i < NB_CHARS ; i++ )
is_aa[i] = isalpha(i);
is_aa['b'] = is_aa['B'] = 0;
is_aa['j'] = is_aa['J'] = 0;
is_aa['o'] = is_aa['O'] = 0;
is_aa['q'] = is_aa['Q'] = 0;
is_aa['s'] = is_aa['S'] = 0;
is_aa['u'] = is_aa['U'] = 0;
is_aa['x'] = is_aa['X'] = 0;
is_aa['z'] = is_aa['Z'] = 0;
is_aa['*'] = 1;
/* Init comp array */
for( i = 0; i < NB_CHARS; i++ ){
comp[i] = i;
}
comp['a'] = 't', comp['A'] = 'T';
comp['t'] = 'a', comp['T'] = 'A';
comp['c'] = 'g', comp['C'] = 'G';
comp['g'] = 'c', comp['G'] = 'C';
comp['+'] = '-';
comp['-'] = '+';
comp['@'] = '#';
comp['#'] = '@';
/* Init is_nuc array */
for( i=0; i < NB_CHARS ; i++ ) is_nuc[i] = 0 ;
is_nuc['a'] = is_nuc['A'] = 1;
is_nuc['c'] = is_nuc['C'] = 1;
is_nuc['g'] = is_nuc['G'] = 1;
is_nuc['t'] = is_nuc['T'] = 1;
is_nuc['n'] = is_nuc['N'] = 1;
//Modified by David To 12th April 2005
//Adding in "X"
is_nuc['x'] = is_nuc['X'] = 1;
}
/*-----------------------------------------------------------------------------
Name: compl_seq
Description: Complements and reverses a given sequence. Sequence is assumed
to composed of aAcCgGtTnNxX@#+- or any whitespace only
Returns: The complemented reversed sequence
---------------------------------------------------------------------------*/
char *compl_seq(
char seq[], /* a tmp nuc pointer */
long int lg, /* the length of the sequence to complement */
int comp[] /* array of all the nuc complements */
)
{
char *compl_seq; /* will contain the complemented reversed sequence */
long int i; /* loop counter */
compl_seq = (char *) calloc( lg+1, sizeof( char ) );
seq += lg-1;
/* reverse and complement */
for( i=0; i < lg ; i++, seq-- ){
compl_seq[i] = comp[ *seq ];
}
compl_seq[i] = '\0';
return( compl_seq );
}
/*-----------------------------------------------------------------------------
Name: open_all_files
Description: opens all the files needed by flip. Exits flip with an exit
status of 1 if anything goes wrong
Returns: nothing
---------------------------------------------------------------------------*/
void open_all_files(
FILE **prot_lst_dna, /* prot.lst.dna file pointer */
FILE **prot_6rf, /* prot.6rf file ptr */
FILE **seq_file, /* input file ptr */
FILE **prot_lst, /* prot.lst file ptr */
FILE **prot_src, /* prot.src file ptr */
PARAM *param, /* param struct pointer */
FILE **nocompl, /* nocompl file ptr */
FILE **compl, /* compl file ptr */
char *seq_file_name /* input file name */
)
{
/* Open prot.lst.dna only if user wants the DNA seq. of each orf */
if( param->get_dna )
if( !( *prot_lst_dna = fopen( PROT_LST_DNA_NAME, "w+" ) ) ){
fprintf(stderr, "File %s could not be opened. Aborting.\n",
PROT_LST_DNA_NAME);
exit(1);
}
/* Open prot.6rf only if user wants all six reading frames fully translated */
if( param->trans_all )
if( !( *prot_6rf = fopen( PROT_6RF_NAME, "w+" ) ) ){
fprintf(stderr, "File %s could not be opened. Aborting.\n",
PROT_6RF_NAME);
exit(1);
}
/* open prot.lst. Exit if error */
if( !( *prot_lst = fopen( PROT_LST_NAME, "w+" ) ) ){
fprintf(stderr, "File %s could not be opened. Aborting.\n", PROT_LST_NAME);
exit(1);
}
/* open prot.src. Exit if error. Print the leading header (filename) now */
if( !( *prot_src = fopen( PROT_SRC_NAME, "w+" ) ) ){
fprintf(stderr, "File %s could not be opened. Aborting.\n", PROT_SRC_NAME);
exit(1);
}
else fprintf( *prot_src, ">%s\n", seq_file_name );
/* open input file. Exit if error*/
if( !( *seq_file = fopen( param->s_file, "r" ) ) ){
fprintf(stderr, "File %s could not be opened. Aborting.\n", param->s_file );
exit(1);
}
/* open nocompl. Exit if error*/
if( !( *nocompl = fopen( NOCOMPL_NAME, "w+" ) ) ){
fprintf(stderr, "File %s could not be opened. Aborting.\n", NOCOMPL_NAME );
exit(1);
}
/* open compl. Exit if error*/
if( !( *compl = fopen( COMPL_NAME, "w+" ) ) ){
fprintf(stderr, "File %s could not be opened. Aborting.\n", COMPL_NAME );
exit(1);
}
}
/*-----------------------------------------------------------------------------
Name: update_prot_6rf
Description: updates the file prot.6rf by writing to it the fully translated
six reading frames associated to the current contig
Returns: Nothing
---------------------------------------------------------------------------*/
void update_prot_6rf(
FILE *prot_6rf, /* pointer on prot.6rf */
FRAME frame, /* the six frames of the current ctg */
CTG *ctg /* ptr on the current contig */
)
{
char chunk[NUC_PER_LINE+1]; /* a chunk (max 60 nucs) of nucleotides */
long int i; /* the number of nucs printed so far */
long int seq_lg; /* length of the clenaed sequence */
char *seq; /* pointer on start of cleaned seq. */
int f; /* tmp frame id (0..5) */
int chunk_lg; /* length of the current printed chunk */
int nb_spaces; /* tmp for formatting */
int f_lg; /* tmp */
char *cur_aa[NB_FRAMES];
/* tmp for pretty formatting of the frames */
int spaces[3][3] = { { 1, 0, 2 }, { 2, 1, 0 }, { 0, 2, 1 } };
fprintf( prot_6rf, "%s\n\n", ctg->name );
i=0;
seq = ctg->clean_seq;
seq_lg = ctg->clean_seq_lg;
for( f=0; f < NB_FRAMES; f++ ){
cur_aa[f] =
f >= (NB_FRAMES/2) ? frame[f].aa + frame[f].aa_lg - 1 : frame[f].aa;
}
/* Print all frames */
while( *seq != '\0' ){
chunk_lg = seq_lg > NUC_PER_LINE ? NUC_PER_LINE : seq_lg;
/* forward frames */
for( f=0 ; f < (NB_FRAMES/2) ; f++ ){
fprintf( prot_6rf, "%s F:%d ", ctg->name, f+1 );
nb_spaces = (f == 2) && (i==0) ? 3 : spaces[f][ i % CODON_LG ];
fprintf( prot_6rf, "%*s", nb_spaces, "" );
f_lg = ( chunk_lg - nb_spaces - 1 ) / CODON_LG + 1;
while( f_lg-- && *cur_aa[f] )
fprintf( prot_6rf, "%c ", *cur_aa[f]++ );
fprintf( prot_6rf, "\n" );
}
/* print nuc sequence */
fprintf( prot_6rf, "%*ld ", (int) strlen( ctg->name ) + 7, i+1 );
strncpy( chunk, seq, chunk_lg );
chunk[chunk_lg] = '\0';
fprintf( prot_6rf, "%s\n", chunk );
/* backward frames */
for( f=NB_FRAMES-1 ; f >= (NB_FRAMES/2) ; f-- ){
fprintf( prot_6rf, "%s F:%d ", ctg->name, f+1 );
nb_spaces = !i && ( f == NB_FRAMES/2 ) ? 3 : spaces[5-f][ i % CODON_LG ];
fprintf( prot_6rf, "%*s", nb_spaces, "" );
f_lg = ( chunk_lg - nb_spaces - 1 ) / CODON_LG + 1;
while( f_lg-- && ( cur_aa[f] >= frame[f].aa ) )
fprintf( prot_6rf, "%c ", *cur_aa[f]-- );
fprintf( prot_6rf, "\n" );
}
fprintf( prot_6rf, "\n\n\n" );
seq += chunk_lg;
seq_lg -= chunk_lg;
i += chunk_lg;
}
}
/*-----------------------------------------------------------------------------
Name: close_all_files
Description: closes all the files that flip used
Returns: Nothing
---------------------------------------------------------------------------*/
void close_all_files(
FILE **prot_lst_dna, /* prot.lst.dna file pointer */
FILE **prot_6rf, /* prot.6rf file ptr */
FILE **seq_file, /* input file ptr */
FILE **prot_lst, /* prot.lst file ptr */
FILE **prot_src, /* prot.src file ptr */
FILE **nocompl, /* nocompl file ptr */
FILE **compl, /* compl file ptr */
PARAM *param /* param struct pointer */
)
{
if( *prot_6rf!=NULL ) fclose( *prot_6rf );
if( *prot_lst_dna!=NULL ) fclose( *prot_lst_dna );
if( *seq_file!=NULL ) fclose( *seq_file );
if( *prot_lst!=NULL ) fclose( *prot_lst );
if( *prot_src!=NULL ) fclose( *prot_src );
if( *nocompl!=NULL ) fclose( *nocompl );
if( *compl!=NULL ) fclose( *compl );
if( !param->silent ){
printf( "Wrote %s\n", NOCOMPL_NAME);
printf( "Wrote %s\n", COMPL_NAME);
printf( "Wrote %s\n", PROT_LST_NAME);
printf( "Wrote %s\n", PROT_SRC_NAME);
if( param->trans_all ) printf( "Wrote %s\n", PROT_6RF_NAME );
if( param->get_dna ) printf( "Wrote %s\n", PROT_LST_DNA_NAME );
}
}
/*-----------------------------------------------------------------------------
Name: find_prot
Description: finds all the proteins in all the frames, including the
wrap-around proteins and saves them .
Returns: Nothing
---------------------------------------------------------------------------*/
void find_prot(
CTG *ctg, /* ptr on current contig */
PROT **prot, /* pointer on the protein list */
PARAM *param, /* ptr on the application's params */
FRAME frame /* all six reading frames */
)
{
PROT *last_prot; /* pointer on the last found prot in the list */
int f; /* a frame_id (0..5) */
int s; /* index of a stop in the list of stops */
long int r_start, r_end; /* two consecutive stop positions (r_end might
point to something that's not a stop for the
last region) */
long int r_lg; /* length of a region (between two consecutive
stops, or aa after last stop) */
long int prot_start;
long int p_lg;
long int cur_s_idx;
last_prot = *prot = NULL;
/* scan all frames */
for( f=0; f<NB_FRAMES; f++ ){
cur_s_idx = 0;
/* scan all regions */
for( s=0; s <= frame[f].nb_stop; s++ ){
/* If genome is circular, first and last regions are skipped */
if( ( !s || (s == frame[f].nb_stop) ) && param->circular ) continue;
r_start = s ? frame[f].stop[s-1] + 1 : 0;
r_end = s == frame[f].nb_stop ? frame[f].aa_lg - 1 : frame[f].stop[s];
r_lg = s == frame[f].nb_stop ? r_end - r_start + 1 : r_end - r_start;
/* does the orf respect the min_codong_reg_lg ? */
if( r_lg >= param->min_coding_reg_lg ){
/* if there is a minimum length (from start codon) the orf must have */
if( param->min_prot_lg ){
prot_start = get_p_start( frame+f, r_start, r_end, &cur_s_idx );
if( prot_start != -1 ){
p_lg = s == frame[f].nb_stop ?
r_end - prot_start + 1 : r_end - prot_start;
if( p_lg >= param->min_prot_lg )
add_prot( prot, &last_prot, r_start, r_end, prot_start,
frame + f, param, ctg, f, p_lg );
}
}
else add_prot( prot, &last_prot, r_start, r_end, -1, frame + f,
param, ctg, f, r_lg );
}
} /* for */
}
if( param->circular ) find_wrap_prot( prot, &last_prot, ctg, param, frame );
}
/*-----------------------------------------------------------------------------
Name: find_wrap_prot
Description: Assuming the genome is circular, finds the proteins that span
across the split point (these don't include proteins for which
only the last stop codon crosses the split poitn, which are
reported by find_prot)
Returns: Nothing
---------------------------------------------------------------------------*/
void find_wrap_prot(
PROT **prot, /* pointer on the ptr on the first prot
in the list of found prot */
PROT **last_prot, /* pointer on the ptr on the last prot
in the list of found prot */
CTG *ctg, /* pointer on the current ctg struct */
PARAM *param, /* pointer on the application's params
structure */
FRAME frame /* the siz reading frames for the ctg */
)
{
int f; /* a frame_id (0..NB_FRAMES-1) */
int cur_f; /* the current frame index (0..NB_FRAMES-1) */
int nb_ending; /* the number of trailing nucs that are ignored
during linear translation of a seq. for a
given frame (ex, if seq=ACTG, then nb_ending
is 1 for frame 0) */
int f_idx; /* a given frame index (0..NB_FRAMES-1) */
int next_f; /* frame index of the frame following a given
one during circular translation */
int order[NB_FRAMES/2]; /* this array gives the order in which the
frame indexes are to be read, starting from
a given frame index. Ex: seq=TAAC and the
current frame is 0. order=(2,1,0,-1) (the -1
is to signal end of reading) */
int nb_pass; /* nb of times we entered a loop */
long int r_lg; /* length of the wrap-around orf */
long int prot_lg; /* length of the wrap-around orf, counted from
the first start codon */
int start_o_idx; /* the index, in the order array, of the frame
where the first start codon is found */
long int start_pos; /* the position of the start aa in the frame
refered to by start_o_idx */
/* Clearly, if clean_seq_lg is < 3, there cannot be ANY wrap-around prots */
if( ctg->clean_seq_lg < CODON_LG ) return;
/* scan all frames */
for( f=0; f < NB_FRAMES ; f++ ){
/* if no stop, then a wrap-around prot cannot start in the current frame */
if( !frame[f].nb_stop ) continue;
/* find next frame (wrap-around-wise) that has a stop */
cur_f = f;
for( f_idx=0; f_idx < NB_FRAMES ; f_idx++ ) order[f_idx] = -1;
nb_pass = 0;
while( 1 ){
nb_ending = ( ctg->clean_seq_lg - frame[cur_f].offset ) % CODON_LG;
/* get frame following current one (wrap-around-wise) */
if( !nb_ending ) nb_ending = CODON_LG;
next_f = -1;
for( f_idx=0; f_idx < NB_FRAMES ; f_idx++ )
if( SAME_STRAND( f_idx, cur_f ) )
if( frame[f_idx].offset == ( CODON_LG - nb_ending ) ){
next_f = f_idx;
break;
}
if( next_f == -1 )
fprintf( stderr, "Impossible, no next frame !\n" ), exit(1);
order[nb_pass++] = next_f;
/* we might have a wrap-around prot here */
if( frame[ next_f].nb_stop ){
/* printf( "Found wrap-around region starting in frame %d and ", f );
printf( "ending in frame %d\n", next_f );
printf( "Order = " );
for( f_idx=0; f_idx < (NB_FRAMES/2) ; f_idx++ )
printf( "%d ", order[f_idx] );
printf( "\n" ); */
r_lg = get_wrap_rg_lg( ctg, frame, order, f );
/* printf( "The region length is %ld\n", r_lg ); */
if( r_lg >= param->min_coding_reg_lg )
if( param->min_prot_lg ){
/* printf( "Seeking a wrap-around prot\n" );*/
prot_lg = get_wrap_prot_lg( ctg, frame, order, f, next_f, r_lg,
&start_o_idx, &start_pos );
if( prot_lg >= param->min_prot_lg ){
/* printf( "A valid prot was found\n" );*/
/* printf( "The calculated protein length is %ld\n", prot_lg );*/
add_wrap_prot( prot, last_prot, ctg, param, frame, order, f,
next_f, start_o_idx, start_pos, r_lg, prot_lg );
}
}
else
add_wrap_prot( prot, last_prot, ctg, param, frame, order, f,
next_f, start_o_idx, start_pos, r_lg, prot_lg );
break;
}
else cur_f = next_f;
}
}
}
/*-----------------------------------------------------------------------------
Name: add_wrap_prot
Description: Custom routine to add a wrap-around protein in the list of all
proteins found.
Returns: Nothing
---------------------------------------------------------------------------*/
void add_wrap_prot(
PROT **prot, /* ptr on the ptr on the first prot */
PROT **last_prot, /* ptr on the ptr on the last prot */
CTG *ctg, /* ptr on the current ctg struct */
PARAM *param, /* ptr on the param struct */
FRAME frame, /* the six reading frames */
int order[], /* the order in which the frames are to
be read (circular-wise, see
find_wrap_prot) */
int f, /* the frame in which the orf starts
(ie leading stop) */
int last_f, /* the frame in which the orf ends (ie
last stop) */
int start_o_idx, /* index, in order array, of the frame
where the first start was found */
long int start_pos, /* pos, in the frame referred to by
start_o_idx, where the first stop aa
was found */
long int r_lg, /* length of the wrap-around orf */
long int prot_lg /* length of the wrap-aournd orf,
counted from the first start codon */
)
{
PROT *new_prot; /* a new protein structure */
int on_rev; /* 1 if protein is on reverse strand, 0 otherwise */
long int length; /* the length of the prot (might be from the first start
codon if param->min_prot_lg > 0). Always includes last
stop. */
if( !( new_prot = (PROT *) malloc( sizeof(PROT) ) ) ) mem_err();
/* get prot length (including last stop) */
length = param->min_prot_lg ? prot_lg + 1 : r_lg + 1;
on_rev = f >= (NB_FRAMES/2);
new_prot->ctg_name = ctg->name;
new_prot->aa_lg = length;
new_prot->length = length-1;
new_prot->strand = on_rev;
/* Get the aa composing the protein */
if( !( new_prot->aa = (char *) calloc( length + 1, sizeof( char ) ) ) )
mem_err();
/* get info associated to wrap-around prot */
get_wrap_aa( new_prot, param, frame, f, ctg, code, idx, order, r_lg,
start_o_idx, start_pos );
get_wrap_pos( new_prot, ctg, frame, f, last_f, start_o_idx, start_pos,
param, order );
if( param->min_prot_lg )
get_wrap_comment( new_prot, frame, f, ctg, code, idx, order, start_o_idx,
start_pos, r_lg - prot_lg );
get_wrap_context( new_prot, ctg );
/* Get orf's DNA sequence if needed */
if( param->get_dna ) get_dna_seq( new_prot, ctg );
else new_prot->dna = NULL;
/* Add in list. Update pointers to start and end of list */
if( *prot ){
(*last_prot)->next = new_prot;
*last_prot = new_prot;
}
else *last_prot = *prot = new_prot;
new_prot->next = NULL;
}
/*-----------------------------------------------------------------------------
Name: get_wrap_context
Description: custom routine to get the context associated to a wrap-around
protein (see get_context for a complete description of the
context). Note that for wrap-around prots, there are ALWAYS
"..." in the context
Returns: Nothing
---------------------------------------------------------------------------*/
void get_wrap_context(
PROT *prot, /* ptr on wrap-around prot */
CTG *ctg /* ptr on current contig */
)
{
long int clean_seq_start = prot->begin - 1; /* first nuc in cleaned seq.
assoc to orf */
long int clean_seq_end = prot->end - 1; /* last nuc in cleaned seq. assoc
to orf */
long int i; /* loop counter */
long int seq_start; /* the position (in the original
seq) of the nuc whose pos is
clean_seq_start in the cleaned
seq. */
long int seq_end; /* the position (in the original
seq) of the nuc whose pos is
clean_seq_end in the cleaned
seq. */
long int chunk_lg; /* a chunk of context */
long int old_lg; /* tmp */
POS_LIST *pos_ptr; /* ptr on the list of non-nuc pos
either in orig or rev compl.
seq */
/* get start in orig sequence */
i = 0;
for( pos_ptr = ctg->seq_pos; pos_ptr ; pos_ptr = pos_ptr->next, i++ ){
if( pos_ptr->val > i + clean_seq_start ) break;
}
seq_start = clean_seq_start + i;
/* get end in original sequence */
i = 0;
for( pos_ptr = ctg->seq_pos; pos_ptr ; pos_ptr = pos_ptr->next, i++ ){
if( pos_ptr->val > i + clean_seq_end ) break;
}
seq_end = clean_seq_end + i;
/* Get C-term and N-term */
prot->context = (char *) calloc( 2*MAX_CTX_LG + 4, sizeof( char ) );
/* Get C-term (or N-term for backw prot) */
if( !prot->strand ){
strncpy( prot->context, ctg->seq + seq_start, MAX_CTX_LG );
prot->context[MAX_CTX_LG] = '\0';
}
else{
chunk_lg = MIN( MAX_CTX_LG, seq_start + 1 );
strncpy( prot->context, ctg->seq + seq_start - chunk_lg + 1, chunk_lg );
prot->context[chunk_lg] = '\0';
}
/* Put separator between the two chunks */
strcat( prot->context, "..." );
old_lg = strlen( prot->context );
/* N-term (or C-term for back) */
if( !prot->strand ){
chunk_lg = MIN( MAX_CTX_LG, seq_end + 1 );
strncat( prot->context, ctg->seq + seq_end - chunk_lg + 1, chunk_lg );
prot->context[old_lg + chunk_lg] = '\0';
}
else{
strncat( prot->context, ctg->seq + seq_end, MAX_CTX_LG );
prot->context[ old_lg + MAX_CTX_LG ] = '\0';
}
}
/*-----------------------------------------------------------------------------
Name: get_wrap_comment
Description: Gets the aa upstream from the first start codon in a wrap-around
orf
Returns: Nothing
---------------------------------------------------------------------------*/
void get_wrap_comment(
PROT *new_prot, /* ptr on the new wrap-around prot */
FRAME frame, /* six reading frames */
int f, /* the frame in which the orf starts (ie
leading stop) */
CTG *ctg, /* ptr on the current ctg struct */
char code[], /* genetic code to use during translation */
int idx[], /* index of each nuc */
int order[], /* the order in which the frames are to be read
(circular-wise, see find_wrap_prot) */
int start_o_idx, /* index, in order array, of the frame where
the first start was found */
long int start_pos, /* pos, in the frame referred to by
start_o_idx, where the first stop aa was
found */
long int size /* length of the wrap-around orf, counted from
the first start codon */
)
{
CODON codon; /* a codon that lies across the split point */
int i; /* loop counter */
long int lg; /* tmp */
long int old_lg; /* tmp */
long int last_stop; /* the pos of the lst stop in f */
int cur_f; /* a frame index (0.NB_FRAMES-1) */
int nb_ending; /* the number of trailing nucs that are ignored during
linear translation of a seq. for a given frame (ex,
if seq=ACTG, then nb_ending is 1 for frame 0) */
char *seq_ptr; /* a tmp sequence ptr */
/* init */
new_prot->comment = (char *) calloc( size + 1, sizeof(char) );
new_prot->comment[0] = '\0';
/* get all comment chunks in all the frames */
for( i = -1 ;; i++ ){
/* the first frame, f, is not in order, so it's a special case */
cur_f = i == -1 ? f : order[i];
/* that's the end of the context */
if( i == start_o_idx ){
/* if the start fr. is also the frame where orf starts, get portion from
(excluding) last stop of frame to (excluding) first start after this
stop */
if( cur_f == f ){
last_stop = frame[f].stop[ frame[f].nb_stop -1 ];
old_lg = strlen( new_prot->comment );
lg = start_pos - last_stop - 1;
strncat( new_prot->comment, frame[f].aa + last_stop + 1, lg );
new_prot->comment[old_lg + lg] = '\0';
}
/* get everything up to (but excluding) the first start in the current
frame */
else{
old_lg = strlen( new_prot->comment );
strncat( new_prot->comment, frame[cur_f].aa, start_pos );
new_prot->comment[old_lg + start_pos] = '\0';
}
break;
}
/* part of the chunk, but not the last part */
else{
/* if we are processing the frame where orf starts, get portion from
(excluding) last stop of frame to end of aa in frame */
if( cur_f == f ){
last_stop = frame[f].stop[ frame[f].nb_stop -1 ];
if( last_stop < frame[f].aa_lg - 1 )
strcpy( new_prot->comment, frame[f].aa + last_stop + 1 );
}
/* if it's not the first chunk, get the whole translated frame */
else strcat( new_prot->comment, frame[cur_f].aa );
/* this will add in the comment the wrap-around codon (if any) */
nb_ending = ctg->clean_seq_lg -
( CODON_LG * frame[cur_f].aa_lg + frame[cur_f].offset );
/* watch out ! If there's a wrap-around, make sure it's not the stop
that's initiating the orf */
if( nb_ending && !( (cur_f == f) && (last_stop >= frame[f].aa_lg - 1) ))
{
seq_ptr = new_prot->strand ? ctg->compl_clean_seq : ctg->clean_seq;
strcpy( codon, seq_ptr + ctg->clean_seq_lg - nb_ending );
strncat( codon, seq_ptr, CODON_LG - nb_ending );
old_lg = strlen( new_prot->comment );
new_prot->comment[old_lg] = code[ get_codon_idx( codon, idx ) ];
new_prot->comment[old_lg+1] = '\0';
}
} /* else */
} /* for */
new_prot->comment_lg = strlen( new_prot->comment );
}
/*-----------------------------------------------------------------------------
Name: get_wrap_aa
Description: gets the amino acid sequence associated to a wrap-around protein
Returns: Nothing
---------------------------------------------------------------------------*/
void get_wrap_aa(
PROT *new_prot, /* ptr on the prot for which we want aa sequence */
PARAM *param, /* ptr on the application's parameter structure */
FRAME frame, /* the six reading frames */
int f, /* the frame idx (0..5) where the orf's initiating
stop was found */
CTG *ctg, /* ptr on current contig struct */
char code[], /* genetic code used during translation */
int idx[], /* index of each nuc */
int order[], /* this array gives the order in which the frame
indexes are to be read, starting from a given
frame index. Ex: seq=TAAC and the current frame
is 0. order=(2,1,0,-1) (the -1 is to signal end
of reading) */
long int r_lg, /* length of the orf (from first to last stop
(excluding the stops themselves) */
int start_o_idx, /* the index, in the order array, of the frame where
the first start codon is found */
long int start_pos /* the position of the start aa in the frame
referred to by start_o_idx */
)
{
long int last_stop; /* position of the last stop of frame f */
int nb_ending; /* the number of trailing nucs that are ignored
during linear translation of a seq. for a given
frame (ex, if seq=ACTG, then nb_ending is 1 for
frame 0) */
char *seq_ptr; /* a tmp seq ptr */
long int old_lg; /* a tmp length */
int i; /* loop counter */
int cur_f; /* a frame index (0..5) */
int on_rev; /* 1 if prot is on backw strand, 0 otherwise */
CODON codon; /* a tmp wrap-around codon */
char *aa_ptr; /* a tmp aa seq ptr */
long int lg; /* position of the last stop in the frame in which
orf ends */
new_prot->aa[0] = '\0';
on_rev = f >= ( NB_FRAMES/2 );
/* if min_prot_lg was specified */
if( param->min_prot_lg )
for( i = start_o_idx ; i < (NB_FRAMES/2); i++ ){
cur_f = i == -1 ? f : order[i];
if( cur_f == -1 ) break;
/* last chunk...*/
if( order[i+1] == -1 ){
old_lg = strlen( new_prot->aa );
aa_ptr = i == start_o_idx ?
frame[cur_f].aa + start_pos : frame[cur_f].aa;
/* if first aa is not a stop, get aa before it */
if( frame[cur_f].stop[0] ){
lg = frame[cur_f].stop[0];
if( i == start_o_idx ) lg -= start_pos;
strncat( new_prot->aa, aa_ptr, lg );
}
else lg = 0;
new_prot->aa[old_lg + lg ] = '*';
new_prot->aa[old_lg + lg + 1 ] = '\0';
}
/* it's not the last chunk */
else
/* first chunk */
if( i == start_o_idx ){
/* if the start is not the last wrap-around codon, get it and all the
aas following it in the same frame */
if( start_pos < frame[cur_f].aa_lg ){
aa_ptr = frame[cur_f].aa + start_pos;
strcpy( new_prot->aa, aa_ptr );
}
/* Add the wrap-around codon (if any) */
nb_ending = ctg->clean_seq_lg -
( CODON_LG * frame[cur_f].aa_lg + frame[cur_f].offset );
if( nb_ending ){
seq_ptr = on_rev ? ctg->compl_clean_seq : ctg->clean_seq;
strcpy( codon, seq_ptr + ctg->clean_seq_lg - nb_ending );
strncat( codon, seq_ptr, CODON_LG - nb_ending );
old_lg = strlen( new_prot->aa );
new_prot->aa[old_lg] = code[ get_codon_idx( codon, idx ) ];
new_prot->aa[old_lg+1] = '\0';
}
}
/* other chunks (ie not first and not last): we get the whole frame */
else{
strcat( new_prot->aa, frame[cur_f].aa );
/* Add wrap-around codon (if any) */
nb_ending = ctg->clean_seq_lg -
( CODON_LG * frame[cur_f].aa_lg + frame[cur_f].offset );
if( nb_ending ){
seq_ptr = on_rev ? ctg->compl_clean_seq : ctg->clean_seq;
strcpy( codon, seq_ptr + ctg->clean_seq_lg - nb_ending );
strncat( codon, seq_ptr, CODON_LG - nb_ending );
old_lg = strlen( new_prot->aa );
new_prot->aa[old_lg] = code[ get_codon_idx( codon, idx ) ];
new_prot->aa[old_lg+1] = '\0';
}
} /* else */
} /* for */
/* If min_prot_lg was not specified */
else{
/* if the last stop in f is not a wrap-around codon, get all aas following
it (if any) */
if( frame[f].stop[ frame[f].nb_stop - 1 ] < frame[f].aa_lg ){
last_stop = frame[f].nb_stop - 1;
strcat( new_prot->aa, frame[f].aa + frame[f].stop[ last_stop ] + 1 );
/* Add wrap-around codon (if any) */
nb_ending =
ctg->clean_seq_lg - ( CODON_LG * frame[f].aa_lg + frame[f].offset );
if( nb_ending ){
seq_ptr = on_rev ? ctg->compl_clean_seq : ctg->clean_seq;
strcpy( codon, seq_ptr + ctg->clean_seq_lg - nb_ending );
strncat( codon, seq_ptr, CODON_LG - nb_ending );
old_lg = strlen( new_prot->aa );
new_prot->aa[old_lg] = code[ get_codon_idx( codon, idx ) ];
new_prot->aa[old_lg+1] = '\0';
}
}
/* get remaining aa chunks */
for( i=0; i < (NB_FRAMES/2); i++ ){
cur_f = order[i];
if( cur_f == -1 ) break;
/* if there's a stop in the current frame, then it's the last chunk. Get
everyhting up to this stop (excluding)*/
if( frame[cur_f].nb_stop ){
strncat( new_prot->aa, frame[cur_f].aa, frame[cur_f].stop[0] );
/* add OB stop */
new_prot->aa[r_lg] = '*';
new_prot->aa[r_lg+1] = '\0';
}
/* no stop in current frame, then we take all the aas in the frame */
else{
strcat( new_prot->aa, frame[cur_f].aa );
/* Add wrap-around codon (if any) */
nb_ending = ctg->clean_seq_lg -
( CODON_LG * frame[cur_f].aa_lg + frame[cur_f].offset );
if( nb_ending ){
seq_ptr = on_rev ? ctg->compl_clean_seq : ctg->clean_seq;
strcpy( codon, seq_ptr + ctg->clean_seq_lg - nb_ending );
strncat( codon, seq_ptr, CODON_LG - nb_ending );
old_lg = strlen( new_prot->aa );
new_prot->aa[old_lg] = code[ get_codon_idx( codon, idx ) ];
new_prot->aa[old_lg+1] = '\0';
}
} /* else */
} /* for */
} /* else */
} /* get_wrap_aa */
/*-----------------------------------------------------------------------------
Name: get wrap_region_lg
Description: Gets the length (in ass) of a wrap-around orf. This length
doesn't include the stops
Returns: the computed length
---------------------------------------------------------------------------*/
long int get_wrap_rg_lg(
CTG *ctg, /* ptr on the current contig */
FRAME frame, /* the six reading frames */
int order[], /* this array gives the order in which the frame indexes
are to be read, starting from a given frame index. Ex:
seq=TAAC and the current frame is 0. order=(2,1,0,-1)
(the -1 is to signal end of reading) */
int f /* the frame in which the orf starts (ie leading stop) */
)
{
long int r_lg; /* will be the sought after region length */
int o_idx; /* loop counter */
int cur_f; /* frme index (0..5) */
/* Get length of chunk of region on first frame */
r_lg = frame[f].aa_lg - frame[f].stop[ frame[f].nb_stop - 1 ] - 1;
/* Add the wrap-around codon, if any */
if( ( ctg->clean_seq_lg - frame[f].offset ) % 3 ) r_lg++;
/* This is to take into account the wrap-around stops whose pos is >= aa_lg,
and so might yield negative region length */
if( r_lg < 0 ) r_lg = 0;
/* Add the length of the other chunks on the other frames */
for( o_idx=0 ; o_idx < (NB_FRAMES/2) ; o_idx++ ){
cur_f = order[o_idx];
if( cur_f == -1 ) break;
/* this indicates the last chunk (ie from first aa to (excluding) the 1st
stop found */
if( frame[cur_f].nb_stop ){
r_lg += frame[cur_f].stop[0];
}
/* get everything */
else{
r_lg += frame[cur_f].aa_lg;
/* Add the wrap-around codon if there is one */
if( ( ctg->clean_seq_lg - frame[cur_f].offset ) % CODON_LG ) r_lg++;
}
}
return( r_lg );
}
/*-----------------------------------------------------------------------------
Name: get_wrap_prot_lg
Description: Gets the length (counted from the first start codon) of an orf
that is assumed to be wrapped around the split point.
The stops are never part of this length computation, but the
start are. Also, sets start_o_idx to be the index, in the order
array of the frame where the first start was found. Also sets
start_pos to be the position of the start (in the frame referred
to by start_o_idx).
Returns: The computed length if the orf has at least one start codon, -1
otherwise
---------------------------------------------------------------------------*/
long int get_wrap_prot_lg(
CTG *ctg, /* ptr on the contig struct */
FRAME frame, /* the six reading frames */
int order[], /* this array gives the order in which the frame
indexes are to be read, starting from a given
frame index. Ex: seq=TAAC and the current frame
is 0. order=(2,1,0,-1) (the -1 is to signal end
of reading) */
int begin_f, /* the frame in which the orf starts (ie leading
stop) */
int end_f, /* the frame in which the orf ends (ie last stop)*/
long int r_lg, /* whole length of the orf (between the two stops)*/
int *start_o_idx, /* index, in order array, of the frame where the
first start will be found. If the 1st start lies
after the last stop of f and before the end of f,
then start_o_idx will be set to -1 */
long int *start_pos /* pos, in the frame referred to by start_o_idx,
where the first stop aa was found */
)
{
long int last_stop_pos; /* position of the last stop in frame f */
long int last_start_idx; /* position of the last start in f */
long int pos; /* a tmp start pos */
int i; /* tmp loop counter */
int cur_f; /* a frame index (0..5) */
int o_idx; /* loop counter */
int tmp_idx; /* tmp order index */
long int prot_lg; /* sought length */
long int stop_idx; /* an index of a stop in the stop array */
last_stop_pos = frame[begin_f].stop[ frame[begin_f].nb_stop - 1 ];
/* Check to see if there's a start that's after this stop in the same frm */
if( frame[begin_f].nb_start ){
last_start_idx = frame[begin_f].nb_start - 1;
*start_pos = -1;
for( i = last_start_idx ; i >= 0 ; i-- ){
pos = frame[begin_f].start[i];
if( pos < last_stop_pos ) break;
*start_pos = pos;
}
/* return the whole orf length minus the portion between the first stop
and the found start */
if( *start_pos != -1 ){
*start_o_idx = -1;
return( r_lg - ( *start_pos - last_stop_pos - 1 ) );
}
}
/* seek a start */
*start_pos = -1;
for( o_idx = 0 ; o_idx < (NB_FRAMES/2) ; o_idx++ ){
cur_f = order[o_idx];
if( cur_f == -1 ) break;
/* we found a start */
if( frame[cur_f].nb_start )
/* if it's in the same frame as the one in ehich the orf ends, make sure
that this start is before the first stop */
if( cur_f == end_f ){
if( frame[cur_f].start[0] < frame[end_f].stop[0] ){
*start_o_idx = o_idx;
*start_pos = frame[cur_f].start[0];
break;
}
}
/* we got what we wanted */
else{
*start_o_idx = o_idx;
*start_pos = frame[cur_f].start[0];
break;
}
}
/* if a stop was found */
if( *start_pos != -1 ){
/* Get the first chunk (might also be the last) */
/* if it's in the frame where the orf ends */
if( cur_f == end_f ){
if( frame[cur_f].nb_stop ){
stop_idx = -1;
for( i = 0 ; i < frame[cur_f].nb_stop; i++ ){
if( frame[cur_f].stop[i] > *start_pos ){
stop_idx = i; break;
}
}
/* if there's a stop after this start, return the length of the chunk
between (including) this start and the stop (excluding) */
if( stop_idx == -1 )
prot_lg = frame[cur_f].aa_lg - *start_pos;
/* else first chunk = from start to end of frame */
else
prot_lg = frame[cur_f].stop[stop_idx] - *start_pos;
}
/* else first chunk = from start to end of frame */
else
prot_lg = frame[cur_f].aa_lg - *start_pos;
}
/* if the start is not in the frame where the orf ends */
else{
prot_lg = frame[cur_f].aa_lg - *start_pos;
/* Add the wrap-around aa, if any */
if( ( ctg->clean_seq_lg - frame[cur_f].offset ) % 3 ) prot_lg++;
}
/* get length of remaining chunks */
for( tmp_idx = o_idx+1; tmp_idx < (NB_FRAMES/2) ; tmp_idx++ ){
cur_f = order[tmp_idx];
if( cur_f == -1 ) break;
/* that's the last chunk */
if( frame[cur_f].nb_stop ){
prot_lg += frame[cur_f].stop[0];
}
/* not last and not first, so get every aa */
else{
prot_lg += frame[cur_f].aa_lg;
/* Add the wrap-around codon if there is one */
if( ( ctg->clean_seq_lg - frame[cur_f].offset ) % CODON_LG ) prot_lg++;
}
}
return( prot_lg );
}
/* No start codon found... */
else return( -1 );
}
/*-----------------------------------------------------------------------------
Name: get_p_start
Description: gets the position of the first aa which is a start aa in the
orf
Returns: The position of the first start aa if there's a start aa in the orf
-1 otherwise
---------------------------------------------------------------------------*/
long int get_p_start(
FRAME f, /* a given frame struct */
long int r_start, /* the position of the first aa of the orf (not
the leading stop!) */
long int r_end, /* the position of the first aa of the orf (if orf
ends w/stop, then it's the stop pos) */
long int *cur_s_idx /* index of the last start, in the starts array,
that was examined to find the previous
protein's start */
)
{
long int pos; /* a tmp start pos */
long int *start_ptr; /* ptr on the starts array assoc. to a frame */
/* find the first start in [r_start, r_end[ */
start_ptr = f->start;
for( ; (*cur_s_idx) < f->nb_start ; (*cur_s_idx)++ ){
pos = start_ptr[*cur_s_idx];
if( pos > r_end ) return( -1 );
if( pos >= r_start ) return( pos );
}
/* if no start, return -1 */
return( -1 );
}
/*-----------------------------------------------------------------------------
Name: add_prot
Description: Adds an orf/protein in list of current detected orfs/proteins
Returns: Nothing
---------------------------------------------------------------------------*/
void add_prot(
PROT **prot, /* ptr on the ptr on the beginning of the list */
PROT **last_prot, /* ptr on the ptr on the end of the list */
long int r_start, /* the position of the first aa of the orf (not the
leading stop!) */
long int r_end, /* the position of the first aa of the orf (not the
leading stop!) */
long int p_start, /* position of the first start in the orf (if any) */
FRAME f, /* frame where the orf was found */
PARAM *param, /* ptr on the application's parameters structure */
CTG *ctg, /* ptr on the current contig structure */
int f_nb, /* frame index of the frame where the orf was found */
long int l /* length of the orf (counted from the first start codon
if param->min_prot_lg ) */
)
{
PROT *new_prot; /* a new prot struct */
long int prot_begin; /* will be r_start if param->min_prot_lg and p_start
otherwise (ie actual orf's start) */
long int p_lg; /* actual prot_lg (why this ? we laready have l...) */
int on_rev; /* 1 if prot is on the reverse strand, 0 otherwise */
long int c_lg; /* length of comment to put in prot.lst (if any) */
prot_begin = param->min_prot_lg ? p_start : r_start;
p_lg = r_end - prot_begin + 1;
if( !( new_prot = (PROT *) malloc( sizeof(PROT) ) ) ) mem_err();
if( !( new_prot->aa = (char *) calloc( p_lg + 2, sizeof( char ) ) ) )
mem_err();
on_rev = f_nb >= (NB_FRAMES/2);
new_prot->ctg_name = ctg->name;
new_prot->aa_lg = p_lg;
new_prot->length = l;
new_prot->strand = on_rev;
strncpy( new_prot->aa, f->aa + prot_begin, p_lg );
/* For prots that are linear but the last stop crosses the split-point */
if( prot_begin + p_lg >= f->aa_lg )
strcat( new_prot->aa, "*" );
new_prot->aa[p_lg] = '\0';
new_prot->begin = CODON_LG * prot_begin + f->offset + 1;
new_prot->end = CODON_LG * r_end + CODON_LG + f->offset;
/* For prots that are linear but the last stop crosses the split-point */
if( new_prot->end > ctg->clean_seq_lg )
new_prot->end = new_prot->end - ctg->clean_seq_lg;
if( on_rev ){
new_prot->begin = ctg->clean_seq_lg - new_prot->begin + 1;
new_prot->end = ctg->clean_seq_lg - new_prot->end + 1;
}
/* Get context info */
get_context( new_prot, ctg );
/* Get DNA seq of AA seq, if needed. */
if( param->get_dna ) get_dna_seq( new_prot, ctg );
else new_prot->dna = NULL;
/* Get comment: all aa upstream from the start codon. If no minimum length
specified for proteins, then no comment */
if( param->min_prot_lg ){
c_lg = p_start - r_start;
if( !( new_prot->comment = (char *) calloc( c_lg + 1, sizeof( char ) ) ) )
mem_err();
strncpy( new_prot->comment, f->aa + r_start, c_lg );
new_prot->comment[c_lg] = '\0';
new_prot->comment_lg = c_lg;
}
else{
new_prot->comment = NULL;
new_prot->comment_lg = 0;
}
/* Add in list. Update pointers to start and end of list */
if( *prot ){
(*last_prot)->next = new_prot;
*last_prot = new_prot;
}
else *last_prot = *prot = new_prot;
new_prot->next = NULL;
}
/*-----------------------------------------------------------------------------
Name: get_wrap_pos
Description: gets the positions, in the cleaned sequence, of the first and
last nucleotides associated to a wrap-around protein. Put them
in the prot structure
Returns: nothing
---------------------------------------------------------------------------*/
void get_wrap_pos(
PROT *new_prot, /* pointer on the new prot */
CTG *ctg, /* pointer on the current contig struct */
FRAME frame, /* the six reading frames */
int f, /* frame index of frame in which orf begins (ie
leading stop) */
int last_f, /* frame index of frame in which orf begins (ie
trailing stop) */
int start_o_idx, /* index, in the order array, of the frame in which
the first start was found (if any) (might be -1
if first start is in f) */
long int start_pos, /* pos of the first start (in frame pointed to by
start_o_idx) */
PARAM *param, /* ptr on the application's param structure */
int order[] /* this array gives the order in which the frame
indexes are to be read, starting from a given
frame index. Ex: seq=TAAC and the current frame
is 0. order=(2,1,0,-1) (the -1 is to signal end
of reading) */
)
{
int start_f; /* index of the frame where first start was found */
long int last_stop_idx; /* index of the last stop (in stop array) of
last_f */
int nb_ending;
/* Get orf begin pos */
/* if param->min_prot_lg, pos is pos of found start */
if( param->min_prot_lg ){
start_f = start_o_idx == -1 ? f : order[start_o_idx];
new_prot->begin = CODON_LG * start_pos + frame[start_f].offset + 1;
}
/* else pos is pos of first nucleotide after leading stop */
else{
last_stop_idx = frame[f].nb_stop - 1;
new_prot->begin = CODON_LG * ( frame[f].stop[last_stop_idx] + 1 ) +
frame[f].offset + 1;
/* the "%" if for when the leading stop is a wrap-around stop */
if( new_prot->begin > ctg->clean_seq_lg )
new_prot->begin = new_prot->begin % ctg->clean_seq_lg;
}
/* Get the orf's end pos */
/* if the first stop is a wrap-around stop */
if( frame[last_f].stop[0] >= frame[last_f].aa_lg ){
nb_ending = ctg->clean_seq_lg -
( frame[last_f].offset + CODON_LG * frame[last_f].aa_lg );
new_prot->end = CODON_LG - nb_ending;
}
/* else if the nuc in clean seq assoc. w/ last nuc of stop */
else
new_prot->end =
CODON_LG * ( frame[last_f].stop[0] + 1 ) + frame[last_f].offset;
/* if on compl strand, reverse and complement positions */
if( new_prot->strand ){
new_prot->begin = ctg->clean_seq_lg - new_prot->begin + 1;
new_prot->end = ctg->clean_seq_lg - new_prot->end + 1;
}
}
/*-----------------------------------------------------------------------------
Name: update_prot_lst_src
Description: puts all orfs found in the current contig in either prot.lst
and prot.src
Returns: Nothing
---------------------------------------------------------------------------*/
void update_prot_lst_src(
PROT **sorted_prot, /* array of sorted proteins */
int nb_prot, /* number of elements in the sorted array */
FILE *prot_lst, /* the prot.lst file pointer */
FILE *prot_src, /* the prot.src file pointer */
int number_prot /* boolean. Indicates if we should append a
"_<protein_nb>" to indicate the protein number
in the output files */
)
{
char chunk[AA_PER_LINE+1]; /* a chunk of aa sequence */
long int i; /* tmp loop counter */
int chunk_lg; /* the length of a chunk of aa sequence */
PROT *prot; /* pointer on a protein */
int prot_idx;
/* if there were no proteins found, leave */
if( !nb_prot ) return;
for( prot_idx = 0; prot_idx < nb_prot; prot_idx++ ){
prot = sorted_prot[prot_idx];
/* Print prot headers in both files */
fprintf( prot_src, ";" );
if( !number_prot ){
fprintf( prot_lst, "%s; ", prot->ctg_name );
fprintf( prot_src, "%s; ", prot->ctg_name );
}
else{
fprintf( prot_lst, "%s_%d; ", prot->ctg_name, prot_idx+1 );
fprintf( prot_src, "%s_%d; ", prot->ctg_name, prot_idx+1 );
}
fprintf( prot_lst, "%s ", prot->strand ? "compl." : "orig." );
fprintf( prot_src, "%s ", prot->strand ? "compl." : "orig." );
fprintf( prot_lst, "%6ld to %6ld ;", prot->begin, prot->end );
fprintf( prot_src, "%6ld to %6ld ;", prot->begin, prot->end );
fprintf( prot_lst, " %s\n", prot->context );
fprintf( prot_src, " %s\n", prot->context );
/* Print comment line if any */
if( prot->comment_lg )
for( i = 0; i < prot->comment_lg ; i += AA_PER_LINE ){
strncpy( chunk, prot->comment + i, AA_PER_LINE );
chunk[AA_PER_LINE] = '\0';
fprintf( prot_lst, ";%s\n", chunk );
fprintf( prot_src, ";%s\n", chunk );
}
/* Print aa sequence formatted to AA_PER_LINE amino acids per line */
/* In prot.lst, the ending stop If any) is printed. */
for( i = 1; i <= prot->aa_lg ; i += AA_PER_LINE ){
strncpy( chunk, prot->aa + i - 1, AA_PER_LINE );
chunk[AA_PER_LINE] = '\0';
fprintf( prot_lst, "%6ld %s\n", i, chunk );
}
/* Print aa sequence formatted to AA_PER_LINE amino acids per line */
/* In prot.src, the ending stop (if any) is NOT printed */
for( i = 1; i <= prot->length; i += AA_PER_LINE ){
chunk_lg = MIN( AA_PER_LINE, prot->length - i + 1 );
strncpy( chunk, prot->aa + i - 1, chunk_lg );
chunk[ chunk_lg ] = '\0';
fprintf( prot_src, "%s\n", chunk );
}
/* Print aa sequence length (only in prot.lst) */
fprintf( prot_lst, "%6ld\n", prot->length );
fprintf( prot_lst, "\n" );
fprintf( prot_src, "\n" );
}
}
static void FreePOSList( POS_LIST *pos )
{
POS_LIST *p, *next;
p = pos;
while( p != NULL )
{
next = p->next;
free( p );
p = next;
}
return;
}
static void FreeAnnotList( ANNOT_LIST *annot )
{
ANNOT_LIST *p, *next;
p = annot;
while( p != NULL )
{
next = p->next;
free( p );
p = next;
}
return;
}
/*-----------------------------------------------------------------------------
Name: free_mem
Description: frees the memory occupied by the prot list, the current contig
structure. Frees the aa sequences associated to each frame along
with their stop and start list
Returns: Nothing
---------------------------------------------------------------------------*/
void free_mem(
CTG *ctg, /* ptr on the current ctg structure */
PROT *prot, /* ptr on the current protein list */
FRAME frame, /* all six reading frames */
PROT **sorted_prot /* array of sorted proteins */
)
{
PROT *p, *next; /* tmp pos list pointers */
int f; /* a frame index (0...5) */
/* Free space occupied by current contig */
if( ctg->name != NULL ) free( ctg->name );
if( ctg->seq_no_blk != NULL ) free( ctg->seq_no_blk );
if( ctg->clean_seq != NULL ) free( ctg->clean_seq );
if( ctg->compl_clean_seq != NULL ) free( ctg->compl_clean_seq );
if( ctg->compl_seq_no_blk != NULL ) free( ctg->compl_seq_no_blk );
FreePOSList( ctg->seq_pos );
FreePOSList( ctg->seq_no_blk_pos );
FreePOSList( ctg->compl_seq_pos );
FreePOSList( ctg->compl_seq_no_blk_pos );
FreeAnnotList( ctg->annot_lst );
FreeAnnotList( ctg->compl_annot_lst );
memset( ctg, 0, sizeof(CTG) );
/* Protein link list */
p = prot;
while( p != NULL )
{
if( p->aa != NULL ) free( p->aa );
/* If we had the orfs DNA seq. free the string */
if( p->dna != NULL ) free( p->dna );
if( p->comment != NULL ) free( p->comment );
if( p->context != NULL ) free( p->context );
next = p->next;
free( p );
p = next;
}
/* Free space occupied by all frame's aa sequences, stop list and start
list */
for( f=0 ; f < NB_FRAMES ; f++ )
{
if( frame[f].aa != NULL ) free( frame[f].aa );
if( frame[f].stop != NULL ) free( frame[f].stop );
if( frame[f].start != NULL ) free( frame[f].start );
}
/* Free space occupied by current array of sorted proteins */
if( sorted_prot != NULL ) free( sorted_prot );
}
/*-----------------------------------------------------------------------------
Name: print_pos
Description: debug routine to print various informations on all frames
Returns: Nothing
---------------------------------------------------------------------------*/
void print_pos(
FRAME frame, /* all the frames */
char *name /* name of the current contig */
)
{
int f, i; /* tmps */
for( f=0 ; f < NB_FRAMES ; f++ ){
printf( "Contig %s frame %d:\n", name, f+1 );
printf( "\t - AA length is %ld\n", strlen( frame[f].aa ) );
printf( "\t - Offset is %d\n", frame[f].offset );
printf( "\t - Number of stops is %ld", frame[f].nb_stop );
printf( "\t - Stop pos: " );
for( i=0; i< frame[f].nb_stop ; i++ ) printf( "%ld,", frame[f].stop[i] );
printf( "\n" );
printf( "\t - Number of starts is %ld", frame[f].nb_start );
printf( "\t - Start pos: " );
for( i=0; i< frame[f].nb_start ; i++ ) printf( "%ld,", frame[f].start[i] );
printf( "\n\n" );
}
}
/*-----------------------------------------------------------------------------
Name: add_annot
Description: adds an annotation in the list of annotations on the forw and
backw strand. While adding the annot in the list of annots on
the backw strand, the arrow is reversed. The routine supports
annots that end with a backslash (indicating an annot that
continues on the next line) and will insert them in both lists
taking this into account.
Returns: nothing
---------------------------------------------------------------------------*/
void add_annot(
ANNOT_LIST **lst_start, /* ptr on ptr of beginning of annot list on
forw strand */
ANNOT_LIST **lst_end, /* ptr on ptr of end of annot list on forw
strand */
ANNOT_LIST **compl_lst_start, /* ptr on ptr of beginning of annot list on
backw strand */
ANNOT_LIST **compl_lst_end, /* ptr on ptr of end of annot list on backw
strand */
char *annot, /* the annotation's text */
long int nb_nuc, /* the nb of nucleotides (does not include
spec. OGMP chars or spaces) that lie
before the annot on the forw. strand */
int *prec_cont /* ptr on a var which = 1 if the last line */
)
{
ANNOT_LIST *new_annot; /* a new annot on the forw strand */
ANNOT_LIST *compl_new_annot; /* a new annot on the backw strand */
char *dir_start; /* tmp */
char *tmp; /* tmp */
int nb_stars; /* the number of stars before/after the arrow
in an annotation */
/* Get new annotation info: text, number of nucleotide preceding the annot */
new_annot = (ANNOT_LIST *) malloc( sizeof(ANNOT_LIST) );
new_annot->nb_nuc_bef = nb_nuc;
new_annot->text = (char *) calloc( strlen(annot) + 1, sizeof(char) );
strcpy( new_annot->text, annot );
new_annot->next = NULL;
/* Add new annot in list of annot on forw strand */
if( *lst_start ) (*lst_end)->next = new_annot;
else *lst_start = new_annot;
*lst_end = new_annot;
/* Get new annotation info: text, nb of nucleotide preceeding the annot */
compl_new_annot = (ANNOT_LIST *) malloc( sizeof(ANNOT_LIST) );
/* The field nb_nuc_bef will be set as if the annot was forward (to be
changed later when we know the length of seq_no_blk */
compl_new_annot->nb_nuc_bef = nb_nuc;
/* Get compl annotation text */
compl_new_annot->text = (char *) calloc( strlen(annot) + 1, sizeof(char) );
strcpy( compl_new_annot->text, annot );
/* Reverse direction of arrow if not a comment */
if( strlen(annot) > 2 && annot[1] != ';' )
/* if( (dir_start = strstr( compl_new_annot->text, "==>" )) ){*/
if( (dir_start = find_arrow_ptr( compl_new_annot->text, "==>", "<==" )) ){
nb_stars = 0;
while( (dir_start > compl_new_annot->text) && *(dir_start-1) == '*' )
nb_stars++, dir_start--;
strncpy( dir_start, "<==", DIR_LENGTH );
tmp = dir_start + DIR_LENGTH - 1;
while( nb_stars ) *(tmp + nb_stars) = '*', nb_stars--;
}
else
if( (dir_start = find_arrow_ptr( compl_new_annot->text, "<==", "==>" )) )
{
nb_stars = 0;
tmp = dir_start + DIR_LENGTH;
while( *(tmp + nb_stars) == '*' ) nb_stars++;
tmp = dir_start + nb_stars;
while( nb_stars ) *(dir_start + nb_stars - 1) = '*', nb_stars--;
strncpy( tmp, "==>", DIR_LENGTH );
}
/* Add new annot in list of annots on back strand */
if( *compl_lst_end )
if( ends_with_bksl( (*compl_lst_end)->text ) ){
compl_new_annot->next = (*compl_lst_end)->next;
(*compl_lst_end)->next = compl_new_annot;
}
else{
compl_new_annot->next = *compl_lst_start;
*compl_lst_start = compl_new_annot;
}
else {
*compl_lst_start = compl_new_annot;
compl_new_annot->next = NULL;
}
*prec_cont = ends_with_bksl( annot );
*compl_lst_end = compl_new_annot;
}
/*-----------------------------------------------------------------------------
Name: update_seq_file
Description: Updates either nocompl or compl w/the information we have on the
current contig
Returns: Nothing
---------------------------------------------------------------------------*/
void update_seq_file(
CTG *ctg, /* ptr on current contig struct */
FILE *nocompl, /* pointer on the file to update (not necess.
nocompl) */
int is_compl, /* 1 if the file to update is compl, 0 otherwise */
int nb_ctg, /* Nb of contigs (empty or not) written to compl
and nocompl so far */
int nb_non_mepty_ctg, /* Nb of non-empty (ie at least one nuc or spec
OGMP char) contig written to compl and nocompl
so far */
int fasta_format /* Boolean. Whether to separate the contigs by '*'
or not */
)
{
char *seq_ptr; /* tmp seq ptr */
ANNOT_LIST *cur_annot; /* tmp annot list ptr */
POS_LIST *cur_non_nuc = ctg->seq_pos; /* tmp ptr on beginning of
list of non-nuc pos on orig
strand */
long int nb_char = 0; /* nb of chars (including spec
OGMP ch.) printed so far*/
long int nb_nuc = 0; /* nb of nucs printed */
long int seq_lg = ctg->seq_no_blk_lg; /* lg of orig seq. w/blanks
stripped */
char chunk[NUC_PER_LINE+1]; /* a chunk of nuc sequence */
int chunk_lg; /* length of this chunk */
int cur_nb_nuc; /* nb of nuc in cur chunk*/
long int tmp; /* tmp */
seq_ptr = is_compl ? ctg->compl_seq_no_blk : ctg->seq_no_blk;
cur_annot = is_compl ? ctg->compl_annot_lst : ctg->annot_lst;
cur_non_nuc = is_compl ? ctg->compl_seq_no_blk_pos : ctg->seq_no_blk_pos;
if( nb_ctg )
fprintf( nocompl, "%s\n\n",
(fasta_format && nb_non_empty_ctg) ? "*": "" );
/* Print ctg name, which might be empty (for header, which is considered as
a contig containing only comments */
if( ctg->name ) fprintf( nocompl, "%s\n", ctg->name );
/* Print all annots that are before the first nuc printed. Set cur_annot to
point after the last annot printed */
for( ; cur_annot && !(cur_annot->nb_nuc_bef) ; cur_annot = cur_annot->next )
fprintf( nocompl, "%s", cur_annot->text );
/* If there are no seq. char to print, leave */
if( !seq_ptr ) return ;
/* Print all nuc w/intermixed annots */
while( *seq_ptr ){
if( cur_annot ){
tmp = cur_annot->nb_nuc_bef - nb_char;
chunk_lg = NUC_PER_LINE > tmp ? tmp : NUC_PER_LINE;
}
else{
tmp = seq_lg - nb_char;
chunk_lg = NUC_PER_LINE > tmp ? tmp : NUC_PER_LINE;
}
strncpy( chunk, seq_ptr, chunk_lg );
chunk[chunk_lg] = '\0';
/* Print seq chars. with nuc count in front of them */
cur_nb_nuc =
chunk_lg - get_nb_spec( &cur_non_nuc, nb_char, nb_char + chunk_lg - 1 );
fprintf( nocompl, "%6ld %s\n", nb_nuc+1, chunk );
/* Print all annots that lie just after the last seq. char. printed */
while( cur_annot && ( cur_annot->nb_nuc_bef == nb_char + chunk_lg ) ){
fprintf( nocompl, "%s", cur_annot->text );
cur_annot = cur_annot->next;
}
/* Update counters */
seq_ptr += chunk_lg;
nb_nuc += cur_nb_nuc;
nb_char += chunk_lg;
}
/* Print annots after last seq. char */
for( ; cur_annot && !(cur_annot->nb_nuc_bef) ; cur_annot = cur_annot->next )
fprintf( nocompl, "%s", cur_annot->text );
/* Print total contig length (in nb of nucleotide) */
if( nb_nuc ) { fprintf( nocompl, ";;%6ld\n", nb_nuc); }
}
/*-----------------------------------------------------------------------------
Name: get_nb_spec
Description: gets the number of special (OGMP) characters in a given sequence
Returns: the number of spec chars found
---------------------------------------------------------------------------*/
int get_nb_spec( POS_LIST **pos_ptr, long int start, long int end )
{
int nb = 0;
while( *pos_ptr && ((*pos_ptr)->val >= start) && ((*pos_ptr)->val <= end) ){
nb++;
*pos_ptr = (*pos_ptr)->next;
}
return( nb );
}
/*-----------------------------------------------------------------------------
Name: ends_with_backslash
Description: Verifies if a given string's last non-whitespace character is
a backslash
Returns: 1 if the last non-whitespace character of the string is '\', 0
otherwise
---------------------------------------------------------------------------*/
int ends_with_bksl(
char *s /* a string */
)
{
char *cur_char;
if( !strlen(s) ) return 0;
for( cur_char = s + strlen(s) - 1 ; cur_char >= s ; cur_char-- ){
if( *cur_char == '\\' ) return (1);
if( !isspace( *cur_char ) ) break;
}
return(0);
}
/*-----------------------------------------------------------------------------
Name: get_context
Description: Gets the context of a linear orf. The context returned always
refers to chunks of chars on the forw original strand.
Suppose that orf starts at nuc x and ends at nuc y (if orf on
forw strand y > x, otherwise x > y (except for orfs for which
the last stop crosses the split point).
-if the orf doesn't end with a stop that crosses the split pnt:
- If abs(x-y) + 1 > 24:
- if the prot is on forw strand:
return: (x,x+11)...(y-11,y)
(where (x,x+11) means chars (including spec. OGMP
chars and spaces) x thru x+11)
- if the prot is on back strand:
return: (x-11,x)..(y,y+11)
- If abs(x-y) + 1 <= 24
- if orf on forw. strand return (x,y)
- if orf on backw strand return (y,x)
-if orf ends with a stop that crosses the split point:
the same proc is applied but:
-if the orf is on the forw. strand, it's taken to end at the
last char of the sequence.
-if the orf is on the back. strand, y is set to be the first
char of the sequence.
Returns: Nothing
---------------------------------------------------------------------------*/
void get_context(
PROT *prot, /* ptr on the current protein */
CTG *ctg /* ptr on the current contig */
)
{
long int clean_seq_start = prot->begin - 1; /* start of prot in cleaned seq
string */
long int clean_seq_end; /* end of prot in cleaned seq
string */
long int seq_start; /* the position (in the original
seq) of the nuc whose pos is
clean_seq_start in the cleaned
seq. */
long int seq_end; /* the position (in the original
seq) of the nuc whose pos is
clean_seq_end in the cleaned
seq. */
long int i; /* loop counter */
long int chunk_lg, old_lg; /* tmp */
POS_LIST *pos_ptr; /* tmp pos list ptr */
long int prot_lg; /* length of the nuc sequence (including spec. OGMP chars
and spaces) associated to prot in orig seq. */
/* This is for prots for which the last stop crosses the split point */
/* The last nuc of this stop will not be given in the context */
if( prot->strand )
if( prot->begin < prot->end ) clean_seq_end = 0;
else clean_seq_end = prot->end - 1;
else
if( prot->begin > prot->end ) clean_seq_end = ctg->clean_seq_lg;
else clean_seq_end = prot->end - 1;
/* get start of sequence in orig forw sequence */
i = 0;
for( pos_ptr = ctg->seq_pos; pos_ptr ; pos_ptr = pos_ptr->next, i++ ){
if( pos_ptr->val > i + clean_seq_start ) break;
}
seq_start = clean_seq_start + i;
/* get start of sequence in orig back sequence */
i = 0;
for( pos_ptr = ctg->seq_pos; pos_ptr ; pos_ptr = pos_ptr->next, i++ ){
if( pos_ptr->val > i + clean_seq_end ) break;
}
seq_end = clean_seq_end + i;
prot_lg = nuc_lg( prot, ctg, seq_start, seq_end );
if( prot_lg >= 2*MAX_CTX_LG ){
/* Get C-term and N-term */
prot->context = (char *) calloc( 2*MAX_CTX_LG + 4, sizeof( char ) );
/* C-term (or N-term for backw) */
if( !prot->strand ){
strncpy( prot->context, ctg->seq + seq_start, MAX_CTX_LG );
prot->context[MAX_CTX_LG] = '\0';
}
else{
chunk_lg = MIN( MAX_CTX_LG, seq_start + 1 );
strncpy( prot->context, ctg->seq + seq_start - chunk_lg + 1, chunk_lg );
prot->context[chunk_lg] = '\0';
}
/* Separator */
strcat( prot->context, "..." );
old_lg = strlen( prot->context );
/* N-term (or C-term for back) */
if( !prot->strand ){
chunk_lg = MIN( MAX_CTX_LG, seq_end + 1 );
strncat( prot->context, ctg->seq + seq_end - chunk_lg + 1, chunk_lg );
prot->context[old_lg + chunk_lg] = '\0';
}
else{
strncat( prot->context, ctg->seq + seq_end, MAX_CTX_LG );
prot->context[ old_lg + MAX_CTX_LG ] = '\0';
}
}
else{
/* Get whole nuc. seq. (including spec. chars & spaces ) assoc. to prot */
prot->context = (char *) calloc( prot_lg + 1, sizeof( char ) );
strncpy( prot->context, ctg->seq + MIN( seq_start, seq_end ), prot_lg );
prot->context[ prot_lg ] = '\0';
}
}
/*-----------------------------------------------------------------------------
Name: parse_cmd_line
Description: parses the command line and fills the param structure. If there
were no switches on the cmd line, tries to read prot.prm.
All unset params are set to the defaults. If min_coding_reg_lg
is unset and min_prot_lg is set, then we set min_coding_reg_lg
to min_prot_lg
Returns: Nothing
---------------------------------------------------------------------------*/
void parse_cmd_line(
int argc, /* nb of cmd line args */
char *argv[], /* all cmd line args */
PARAM *param, /* param structure */
int is_nuc[], /* array telling if a char is a nuc */
int is_aa[], /* array telling if a char is a valid aa */
char all_codes[NB_CODES][NB_CODONS], /* all NCBI's genetic codes */
int all_starts[NB_CODES][NB_CODONS], /* all starts for every genetic
code */
char **code, /* will contain the current code to
use */
int idx[] /* index of each nuc */
)
{
int i; /* loop counter */
char *end; /* tmp */
char *arg_ptr; /* ptr on an arg */
char *starts_string = NULL; /* the starts string passed on the command line*/
char *dev_string = NULL; /* the dev string passed on the command line*/
int has_switches = 0; /* if there were any switches or not */
/* Init param structure to it's default values */
param->code_id = DEF_CODE_ID;
param->circular = DEF_CIRCULAR;
param->min_coding_reg_lg = -1;
param->min_prot_lg = -1;
param->trans_all = DEF_TRANS_ALL;
param->s_file = NULL;
param->starts = NULL;
param->force_met = DEF_FORCE_MET;
param->silent = DEF_SILENT;
param->number_prot = DEF_NUMBER_PROT;
param->get_dna = DEF_GET_DNA;
param->fasta_format = DEF_FASTA_FORMAT;
for( i = 1 ; i < argc-1 ; i++ ){
if( argv[i][0] == '-' ){
if( strlen( argv[i] ) <= 1 ) usage();
switch( argv[i][1] )
{
/* Tell that if first codon is a start, translate it as 'M' */
case 'm':
if( strlen( argv[i] ) > 2 ) usage();
else param->force_met = 1;
has_switches = 1;
break;
/* Set the genome to be circular */
case 'c':
if( strlen( argv[i] ) > 2 ) usage();
else param->circular = 1;
has_switches = 1;
break;
/* Set the amount of messages to display */
case 'S':
if( strlen( argv[i] ) > 2 ) usage();
else param->silent = 1;
break;
/* n = we want proteins to be "numbered" in the output files */
case 'n':
if( strlen( argv[i] ) > 2 ) usage();
else param->number_prot = 1;
break;
/* -D = we want the file prot.lst.dna to be produced */
case 'D':
if( strlen( argv[i] ) > 2 ) usage();
else param->get_dna = 1;
break;
/* -F = separate each contig of compl and nocompl by '*' */
case 'F':
if( strlen( argv[i] ) > 2 ) usage();
else param->fasta_format = 1;
break;
/* User wants to produce prot.6rf (ie translate all frames) */
case 'f':
if( strlen( argv[i] ) > 2 ) usage();
else param->trans_all = 1;
has_switches = 1;
break;
/* User wants to set the minimum coding region length */
case 'l':
if( strlen( argv[i] ) <= 2 )
if( i < argc-1 ) arg_ptr = argv[++i];
else usage();
else arg_ptr = argv[i] + 2;
param->min_coding_reg_lg = strtol( arg_ptr, &end, 10 );
if( *end != '\0' ) usage();
if( param->min_coding_reg_lg <= 0 ) usage();
else{
has_switches = 1;
break;
}
/* User wants to set the minimum protein length */
case 'L':
if( strlen( argv[i] ) <= 2 )
if( i < argc-1 ) arg_ptr = argv[++i];
else usage();
else arg_ptr = argv[i] + 2;
param->min_prot_lg = strtol( arg_ptr, &end, 10 );
if( *end != '\0' ) usage();
if( param->min_prot_lg <= 0 ) usage();
else{
has_switches = 1;
break;
}
/* Set the genetic code to be used during translation */
case 'g':
if( strlen( argv[i] ) <= 2 )
if( i < argc-1 ) arg_ptr = argv[++i];
else usage();
else arg_ptr = argv[i] + 2;
param->code_id = strtol( arg_ptr, &end, 10 );
if( *end != '\0' ) usage();
if( param->code_id <= 0 ) usage();
if( (param->code_id > NB_CODES) || (param->code_id == 7) ||
(param->code_id == 8) ) usage();
else{
break;
}
/* Redefine the start codons */
case 's':
if( strlen( argv[i] ) <= 2 )
if( i < argc-1 ) arg_ptr = argv[++i];
else usage();
else arg_ptr = argv[i] + 2;
starts_string = (char *) calloc( strlen(arg_ptr) + 1, sizeof(char) );
strcpy(starts_string, arg_ptr);
has_switches = 1;
break;
/* Impose deviations to the genetic code used */
case 'd':
if( strlen( argv[i] ) <= 2 )
if( i < argc-1 ) arg_ptr = argv[++i];
else usage();
else arg_ptr = argv[i] + 2;
dev_string = (char *) calloc( strlen(arg_ptr) + 1, sizeof(char) );
strcpy( dev_string, arg_ptr );
has_switches = 1;
break;
default: usage();
}
}
else break;
}
if( i != argc-1 ) usage();
/* if no switches were found, read prot.prm (if it exists ) */
if( !has_switches ) parse_prot_prm( param, &dev_string, &starts_string );
param->s_file = argv[argc-1];
*code = all_codes[ param->code_id - 1 ];
param->starts = all_starts[ param->code_id - 1 ];
if( dev_string )
if( get_deviations( dev_string, is_nuc, is_aa, *code ) ){
fprintf( stderr, "Invalid deviation string %s. Aborting.\n",
dev_string );
usage();
}
if( starts_string )
if( get_starts( starts_string, param, is_nuc, idx, *code ) ){
fprintf( stderr, "Invalid starts string %s. Aborting.\n",
starts_string );
usage();
}
/* If min_prot_lg and min_coding_reg_lg both set: error */
/* If min_prot_lg set but not min_coding_reg_lg, set the later to
min_prot_lg */
/* If min_coding_reg_lg set but not min_prot_lg, set the later to 0 */
/* If neither is set, set both to defaults */
if( ( param->min_coding_reg_lg != -1 ) && ( param->min_prot_lg != -1 ) )
usage();
if( param->min_prot_lg != -1 ) param->min_coding_reg_lg = param->min_prot_lg;
else
if( param->min_coding_reg_lg == -1 )
param->min_coding_reg_lg = DEF_MIN_CODING_REG_LG;
if( param->min_prot_lg == -1 ) param->min_prot_lg = DEF_MIN_PROT_LG;
if( !is_valid_sfile(param->s_file) ){
fprintf(stderr, "Invalid sequence file name %s. Aborting\n",
param->s_file);
usage();
}
/* print params if not silent */
if( !param->silent ){
printf("\nGenetic code used : %d\n", param->code_id );
if( dev_string ){
printf("Deviation(s) : %s\n", dev_string);
}
if( starts_string ){
printf("Start codon(s) to use : %s\n", starts_string);
}
printf("Circular genome ? : %s\n",
param->circular ? "Yes" : "No");
printf("Minimum orf length : %ld\n", param->min_coding_reg_lg );
printf("Minimum protein length : %ld\n", param->min_prot_lg );
printf("Force start codons as 'M' ? : %s\n",
param->force_met ? "Yes" : "No");
printf("\n-----------------\n\n");
}
}
/*-----------------------------------------------------------------------------
Name: usage
Description: prints a usage error message and exits w/ an exit status of 1
Returns: Nothing
---------------------------------------------------------------------------*/
void usage()
{
fprintf(stderr, "Usage: flip [-S] [-c] [-f] [-l length | -L length] [-m]");
fprintf(stderr, " [-d deviation]\n [-s start_codons] [-g gen_code]");
fprintf(stderr, " [-n] [-D] [-F] file\n");
exit(1);
}
/*-----------------------------------------------------------------------------
Name: get_starts
Description: parse the start string read on command line or prot.prm and
updates the starts array. The new starts will replace the old
ones
Returns: 1 if the starts string is invalid, 0 otherwise
---------------------------------------------------------------------------*/
int get_starts(
char *start_string, /* the starts string */
PARAM *param, /* ptr on the param struct */
int is_nuc[], /* array telling if a char is a nuc or not */
int idx[], /* index of all nucs */
char *code /* current genetic code */
)
{
char codon[CODON_LG+1];
long int str_lg;
int start_idx;
int i;
if( !start_string ) return(1);
/* Reinitialize all codons as not being start codons */
for( i=0; i < NB_CODONS ; i++ ){
param->starts[i] = 0;
}
/* while( start_string[i] != '\0' ) printf( "%c", start_string[i++] );*/
str_lg = strlen(start_string);
while( str_lg >= CODON_LG ){
strncpy(codon, start_string, CODON_LG);
codon[CODON_LG] = '\0';
/* get a (possible) codon */
for( i=0 ; i< CODON_LG ; i++ )
if( is_nuc[ codon[i] ] ) codon[i] = toupper( codon[i] );
else return(1);
if( str_lg > CODON_LG )
if( str_lg != (CODON_LG + 1) && ( *(start_string + CODON_LG) == ',' ) ){
str_lg -= CODON_LG+1;
start_string += CODON_LG +1;
}
else return(1);
else{
str_lg -= CODON_LG;
start_string += CODON_LG;
}
/* Verify that codon is not already a stop */
start_idx = get_codon_idx( codon, idx );
if( code[ start_idx ] == '*' ){
fprintf( stderr, "%s defined as both start AND stop codon\n", codon );
return(1);
}
else param->starts[ start_idx ] = 1;
}
if( str_lg ) return(1);
return(0);
}
/*-----------------------------------------------------------------------------
Name: get_deviation
Description: sets deviations to the genetic code according to a deviation
string passed on the command line or read in prot.prm. Casing of
aas are maintained, while codons are all uppercased.
Returns: 1 if the dev string is invalid, 0 otherwise
---------------------------------------------------------------------------*/
int get_deviations(
char *dev_string, /* the dev string */
int is_nuc[], /* array telling if a char is a nuc or not */
int is_aa[], /* array telling if a char is a aa or not */
char code[] /* current genetic code */
)
{
long int str_lg; /* length of the dev string */
char codon[CODON_LG+1]; /* a codon */
char aa; /* an aa */
int i; /* loop counter */
if( !dev_string ) return(1);
/* parse dev string */
str_lg = strlen( dev_string );
while( str_lg >= CODON_LG + 2 ){
strncpy( codon, dev_string, CODON_LG );
codon[CODON_LG] = '\0';
/* Verify that codon is valid */
for( i=0 ; i< CODON_LG ; i++ )
if( is_nuc[ codon[i] ] ) codon[i] = toupper( codon[i] );
else return(1);
if( dev_string[CODON_LG] != '=' ) return(1);
aa = dev_string[ CODON_LG + 1 ];
if( !is_aa[aa] ) return(1);
if( str_lg > CODON_LG + 2 )
if( str_lg != (CODON_LG + 3) && ( dev_string[ CODON_LG + 2 ] == ',' ) ){
str_lg -= CODON_LG + 3;
dev_string += CODON_LG + 3;
}
else return(1);
else{
str_lg -= CODON_LG + 2;
dev_string += CODON_LG + 2;
}
/* Note that casing of the aa is maintained, while codon is uppercased */
code[ get_codon_idx( codon, idx ) ] = aa;
}
/* If str_lg is not 0, dev_string is invalid */
return( str_lg );
}
/*-----------------------------------------------------------------------------
Name: parse_prot_prm
Description: Parses prot.prm to set application's parameters
Returns: Nothing
---------------------------------------------------------------------------*/
void parse_prot_prm(
PARAM *param, /* ptr on application's params */
char **dev_string, /* will contain the dev string read */
char **starts_string /* will contain the starts string read */
)
{
FILE *prm; /* ptr on prot.prm */
char buffer[ MAX_LINE_LG + 1 ]; /* a line in prot.prm */
char f_str[ MAX_LINE_LG + 1 ]; /* tmp */
char field[ MAX_LINE_LG + 1 ]; /* a field id */
char value[ MAX_LINE_LG + 1 ]; /* the value of a field */
char rest[ MAX_LINE_LG + 1 ]; /* the things after the value */
char *end; /* tmp */
int n; /* tmp */
int i; /* loop counter */
if( (prm = fopen( PROT_PRM_NAME, "r" )) ){
if( !param->silent ) printf( "Reading %s\n", PROT_PRM_NAME );
while( fgets( buffer, MAX_LINE_LG, prm ) != NULL ){
if( !is_blank_line( buffer ) && !is_comment( buffer ) ){
/* make sure that line has the format FIELD = VALUE */
if( sscanf( buffer, "%[ \ta-zA-Z0-9]=%s%s", f_str, value, rest ) == 2 )
{
/* Get rid of leading and trailing blanks */
if( (n = sscanf( f_str, "%s%s", field, rest )) != 1 )
parse_prot_prm_err( buffer );
/* Uppercase field id */
for(i=0 ; i < strlen(field) ; i++ ) field[i] = toupper( field[i] );
/* to set the genetic code number */
if( !strcmp( field, "GENCODE" ) ){
param->code_id = strtol( value, &end, 10 );
if( *end != '\0' ) parse_prot_prm_err( buffer );
if( !IS_VALID_CODE_ID( param->code_id ) )
parse_prot_prm_err( buffer );
continue;
}
/* to set the circular genome indicator */
if( !strcmp( field, "CIRCULAR" ) ){
if( strcmp( value, "0" ) && strcmp( value, "1" ) )
parse_prot_prm_err( buffer );
param->circular = atoi( value );
continue;
}
/* to indicate that prot.6rf is to be produced */
if( !strcmp( field, "6RF" ) ){
if( strcmp( value, "0" ) && strcmp( value, "1" ) )
parse_prot_prm_err( buffer );
param->trans_all = atoi( value );
continue;
}
/* to set the min orf length */
if( !strcmp( field, "MINORFLENGTH" ) ){
param->min_coding_reg_lg = strtol( value, &end, 10 );
if( *end ) parse_prot_prm_err( buffer );
continue;
}
/* to set the min prot length (from first start codon) */
if( !strcmp( field, "MINPROTLENGTH" ) ){
param->min_prot_lg = strtol( value, &end, 10 );
if( *end ) parse_prot_prm_err( buffer );
continue;
}
/* to set new starts */
if( !strcmp( field, "STARTS" ) ){
*starts_string =
(char *) calloc( strlen(value) + 1, sizeof(char) );
strcpy( *starts_string, value );
continue;
}
/* to set deviations */
if( !strcmp( field, "DEVIATION" ) ){
*dev_string = (char *) calloc( strlen(value) + 1, sizeof(char) );
strcpy( *dev_string, value );
continue;
}
/* If we're here, the line read is invalid */
parse_prot_prm_err( buffer );
}
else parse_prot_prm_err( buffer );
}
}
fclose( prm );
}
else printf( "Using default parameters\n" );
}
/*-----------------------------------------------------------------------------
Name: is_comment
Description: detects if a given line in prot.prm is a comment (first non-
whitespace is '#')
Returns:1 if line is a comment, 0 otherwise
---------------------------------------------------------------------------*/
int is_comment(
char *string /* a line in prot.prm */
)
{
for( ; *string; string++ ){
if( *string == '#' ) return(1);
if( !isspace( *string ) ) return(0);
}
return(0);
}
/*-----------------------------------------------------------------------------
Name: parse_prot_prm_err
Description: Signals to the user thatprot.prm is in invalid format and
prints an error message including the faulty line, then exits
with an eit status of 1
Returns: Nothing
---------------------------------------------------------------------------*/
void parse_prot_prm_err( char *line )
{
/* Notice that *line is modified... */
if( line[ strlen(line) - 1 ] == '\n' ) line[ strlen(line) - 1 ] = '\0';
fprintf(stderr, "Invalid line \"%s\" in %s. Aborting\n", line,
PROT_PRM_NAME);
exit(1);
}
/*-----------------------------------------------------------------------------
Name: nuc_lg
Description: Gets the length of the nuc. seq.( including spec. OGMP chars
and spaces ) associated to prot in orig seq.
Returns: the computed length
---------------------------------------------------------------------------*/
long int nuc_lg(
PROT *prot, /* pointer on the protein */
CTG *ctg, /* pointer on current contig */
long int seq_start, /* start of prot in original sequence string */
long int seq_end /* end of prot in original sequence string */
)
{
long int lg; /* the length */
/* if length <= total length of the cleaned sequence */
if( seq_start >= seq_end )
if( prot->strand ) lg = seq_start - seq_end + 1;
else lg = ctg->seq_lg - seq_start + 1 + seq_end + 1;
else
if( prot->strand ) lg = ctg->seq_lg - seq_end + 1 + seq_start + 1;
else lg = seq_end - seq_start + 1;
if( CODON_LG * prot->aa_lg > 2 * ctg->clean_seq_lg ){
lg += 2 * ctg->seq_lg;
if( seq_start == seq_end ) lg--;
}
else
if( CODON_LG * prot->aa_lg > ctg->clean_seq_lg ){
lg += ctg->seq_lg;
if( seq_start == seq_end ) lg--;
}
return( lg );
}
/*-----------------------------------------------------------------------------
Name: find_arrow_ptr
Description: Finds a pointer on an arrow string (either '==>' or '<==') in
an annotation. It makes sure that the arrow is actually part
of the annotation and not part of a possible comment at the
end of the annot (by checking that if an arrow is found and
that if the is a semi-colon after the first one of the annot,
then the arrow occurs BEFORE the semi-colon. If there are no
semi-colon aside from the leading one, this check is not done)
It also checks that the arrow is not part of a qualifier text
string.
Returns: The ptr on the valid arrow found, or NULL if no valid arrow was
found
---------------------------------------------------------------------------*/
char *find_arrow_ptr(
char *annot, /* the annot to search in */
char *arrow_ptr, /* ptr on the arrow string to search in 'annot' */
char *compl_arrow_ptr /* ptr on the compl. arrow (for '==>' it's '<==',
and vice-versa) */
)
{
char *ptr;
char *semi_colon_ptr;
char *compl_ptr;
ptr = strstr( annot, arrow_ptr );
if( !ptr ) return(NULL);
semi_colon_ptr = strstr( annot + 1, ";" );
if( semi_colon_ptr && (semi_colon_ptr < ptr) ) return( NULL );
/* try to find the complement arrow (for '==>' it's '<==', and vice-versa)
If there's one before ptr, then return NULL. This will handle the case
"; G-nad5 <== /substitution="G==>A" ", for which, without this loop, a
ptr on the forw arrow would be returned if we sought '==>' */
else{
compl_ptr = strstr( annot, compl_arrow_ptr );
if( compl_ptr && (compl_ptr < ptr) ) return( NULL );
else return( ptr );
}
}
/*-----------------------------------------------------------------------------
Name: is_valid_line
Description: Determines if a line in the masterfile is valid or not
Returns: 1 for valid lines, 0 otherwise
---------------------------------------------------------------------------*/
int is_valid_line(
char *line, /* pointer on the beginning of the line */
int is_seq_char[] /* array telling if a char is one of aAcCgGtTnNxX#@!+- or
any whitespace */
)
{
while( isdigit( *line ) ) line++;
while( isspace( *line ) ) line++;
/* Only sequencing chars are allowed now */
for( ; *line; line++ )
if( !is_seq_char[*line] ) return(0);
return(1);
}
/*-----------------------------------------------------------------------------
Name: fix_starts
Description: Looks at every protein. If one starts with a valid start codon
then the first amino acid of this protein is automatically
changed to 'M'
Returns: Nothing
---------------------------------------------------------------------------*/
void fix_starts(
CTG *ctg,
PROT *prot,
PARAM *param,
int idx[],
int is_nuc[],
int comp[]
)
{
CODON codon;
PROT *cur_prot;
int i;
int inc;
long int pos;
char nuc;
for( cur_prot = prot; cur_prot ; cur_prot = cur_prot->next ){
i = 0;
inc = cur_prot->strand ? -1 : 1;
pos = cur_prot->begin - 1;
while( i != CODON_LG ){
if( is_nuc[ ctg->clean_seq[pos] ] ){
nuc =
cur_prot->strand ? comp[ ctg->clean_seq[pos] ] : ctg->clean_seq[pos];
codon[i++] = toupper( nuc );
}
pos += inc;
if( pos < 0 ) pos = ctg->clean_seq_lg - 1;
if( pos >= ctg->clean_seq_lg ) pos = 0;
}
codon[i] = '\n';
if( param->starts[ get_codon_idx( codon, idx ) ] )
*( cur_prot->aa ) = 'M';
}
}
/*-----------------------------------------------------------------------------
Name: sort_prots
Description: Sorts the proteins according the the function prot_compare (see
below). Takes the list of proteins whose start is pointed to by
prot and builds an array of pointers to prots. After that, the
pointers are sorted according to prot_compare.
Returns: Nothing
---------------------------------------------------------------------------*/
void sort_prots(
PROT *prot, /* The list of all proteins in a contig */
PROT ***sorted_prot, /* Will contain the list of sorted prot pointers */
int *nb_prot /* Will contain the nb of proteins in the contig */
)
{
int i; /* counter */
PROT *cur_prot; /* prot pointer */
/* Calculate number of proteins */
*sorted_prot = NULL;
*nb_prot = 0;
for( cur_prot = prot; cur_prot ; cur_prot = cur_prot->next ) (*nb_prot)++;
/* If there are any */
if( *nb_prot ){
/* stock each protein pointer in an array */
*sorted_prot = (PROT **) calloc( sizeof(PROT *), *nb_prot );
for( i = 0, cur_prot = prot; cur_prot ; cur_prot = cur_prot->next, i++ ){
(*sorted_prot)[i] = cur_prot;
}
/* sort the pointers, according to sort function */
qsort( *sorted_prot, *nb_prot, sizeof(PROT *), prot_compare );
}
}
/*-----------------------------------------------------------------------------
Name: prot_compare
Description: Used to sort proteins: proteins on original strand before
before proteins on compl. strand. For proteins on the original
strand, sort them in increasing order of start position. For
proteins on compl. str., sort them in decreasing order of start
position
Returns: 1, 0 or -1 depending on the comparison between the two protein
pointers
---------------------------------------------------------------------------*/
int prot_compare(
const void *p1,
const void *p2
)
{
PROT *prot1 = * ((PROT **)p1);
PROT *prot2 = * ((PROT **)p2);
int strand1 = prot1->strand;
int strand2 = prot2->strand;
long int begin1 = prot1->begin;
long int begin2 = prot2->begin;
if( strand1 != strand2 ){
return( strand1 - strand2 );
}
else
if( strand1 ){ return( begin2 - begin1 ); }
else{ return( begin1 - begin2 ); }
}
/*-----------------------------------------------------------------------------
Name: is_valid_sfile
Description: Verifies that the sequence file name is valid, ie that it is
not the name of one of the file that flip produces.
Returns: 0 if the file name is invalid, 1 otherwise
---------------------------------------------------------------------------*/
int is_valid_sfile(
char *fname /* pointer on the filename */
)
{
char *tmp; /* temporary char pointer */
tmp = PROT_6RF_NAME;
if( !strcmp(fname, tmp) ) return 0;
tmp = PROT_LST_DNA_NAME;
if( !strcmp(fname, tmp) ) return 0;
tmp = PROT_LST_NAME;
if( !strcmp(fname, tmp) ) return 0;
tmp = PROT_SRC_NAME;
if( !strcmp(fname, tmp) ) return 0;
tmp = NOCOMPL_NAME;
if( !strcmp(fname, tmp) ) return 0;
tmp = COMPL_NAME;
if( !strcmp(fname, tmp) ) return 0;
tmp = PROT_PRM_NAME;
if( !strcmp(fname, tmp) ) return 0;
return 1;
}
/*-----------------------------------------------------------------------------
Name: get_dna_seq
Description: Gets the DNA sequence associated to a given orf
Fills the 'dna' field of the prot structure
Returns: Nothing
----------------------------------------------------------------------------*/
void get_dna_seq(
PROT *prot, /* Pointer on an orf */
CTG *ctg /* Pointer on the contig the orf is in */
)
{
long int dna_start; /* Orf's start (1..ctg_lg) in orig (or reverse) strand.
We always have dna_start <= dna_end for ANY orf,
except the circular ones for which the relationship
might fail */
long int dna_end; /* Orf's end (1..ctg_lg) in orig (or reverse) strand.
We always have dna_start <= dna_end for ANY orf,
except the circular ones for which the relationship
might fail */
char *whole_dna; /* Seq from which the DNA is fetched (orig or rev
strand) */
long int cur_lg; /* Cur lg of DNA chunk fetched */
long int cur_start; /* DNA chunk seq start */
long int cur_end; /* DNA chunk seq end */
prot->dna_lg = CODON_LG * prot->aa_lg;
prot->dna = (char *) calloc( prot->dna_lg + 1, sizeof( char ) );
/* Start/end of the dna sequence, but on the ORIGINAL strand */
dna_start = prot->begin;
dna_end = prot->end;
/* If on reverse strand, we want pos. on rev compl. strand so rev. and compl.
start/end pos */
if( prot->strand ){
dna_start = ctg->clean_seq_lg - dna_start + 1;
dna_end = ctg->clean_seq_lg - dna_end + 1;
}
whole_dna = prot->strand ? ctg->compl_clean_seq : ctg->clean_seq;
/* Get the DNA seq of the orf. Will work even for circular orfs */
cur_lg = 0;
cur_start = dna_start;
cur_end = dna_end;
prot->dna[0] = '\0';
while( cur_lg + cur_end - cur_start + 1 <= prot->dna_lg ){
if( cur_lg + cur_end - cur_start + 1 == prot->dna_lg ){
strncat( prot->dna, whole_dna + cur_start - 1, cur_end - cur_start + 1 );
break;
}
else{
strcat( prot->dna, whole_dna + cur_start - 1 );
cur_lg += ctg->clean_seq_lg - cur_start + 1;
cur_start = 1;
}
}
/* Terminate string properly */
prot->dna[prot->dna_lg] = '\0';
}
/*-----------------------------------------------------------------------------
Name: update_prot_lst_dna
Description: Adds all the orf's DNA (for current contig) in prot.lst.dna
Returns: Nothing
----------------------------------------------------------------------------*/
void update_prot_lst_dna(
PROT **sorted_prot, /* The orfs, in appropriate
order */
long int nb_prot, /* Nb of prots found */
FILE *prot_lst_dna, /* Pointer on prot.lst.dna
file */
int number_prot /* boolean. Indicates if we
should append a
"_<protein_nb>" to indicate
the protein number in the
output files */
)
{
long int prot_idx;
long int i;
char chunk[NUC_PER_LINE+1]; /* a chunk of aa sequence */
/* if there were no proteins found, leave */
if( !nb_prot ) return;
for( prot_idx = 0; prot_idx < nb_prot; prot_idx++ ){
prot = sorted_prot[prot_idx];
/* Print prot headers */
if( !number_prot )
fprintf( prot_lst_dna, "%s; ", prot->ctg_name );
else
fprintf( prot_lst_dna, "%s_%d; ", prot->ctg_name, prot_idx+1 );
fprintf( prot_lst_dna, "%s ", prot->strand ? "compl." : "orig." );
fprintf( prot_lst_dna, "%6ld to %6ld\n", prot->begin, prot->end );
/* Print aa sequence formatted to NUC_PER_LINE nucleotides per line */
/* In prot.lst, the ending stop If any) is printed. */
for( i = 1; i <= prot->dna_lg ; i += NUC_PER_LINE ){
strncpy( chunk, prot->dna + i - 1, NUC_PER_LINE );
chunk[NUC_PER_LINE] = '\0';
fprintf( prot_lst_dna, "%6ld %s\n", i, chunk );
}
fprintf( prot_lst_dna, "\n" );
}
}
|
erikmwerner/QJoyControl
|
eventhandler.h
|
<filename>eventhandler.h
#ifndef EVENTHANDLER_H
#define EVENTHANDLER_H
#include <QtGlobal>
#include <QMap>
/*!
* \brief The JOYCON_BUTTONS enum is used to mask
* button status from the bytes of a standard input report
* the joycons
*/
enum JOYCON_BUTTONS : int {
// byte 3:
R_BUT_Y = 1,
R_BUT_X = 2,
R_BUT_B = 4,
R_BUT_A = 8,
R_BUT_SR = 16,
R_BUT_SL = 32,
R_BUT_R = 64,
R_BUT_ZR = 128,
// byte 4:, & with 256 for key mapping
L_BUT_MINUS= 1,
R_BUT_PLUS = 2,
R_BUT_STICK = 4,
L_BUT_STICK = 8,
R_BUT_HOME = 16,
L_BUT_CAP = 32,
// 64 is unused
CHARGE_GRIP = 128,
// byte 5:, & with 512 for key mapping
L_BUT_DOWN = 1,
L_BUT_UP = 2,
L_BUT_RIGHT = 4,
L_BUT_LEFT = 8,
L_BUT_SR = 16,
L_BUT_SL = 32,
L_BUT_L = 64,
L_BUT_ZL = 128
};
class EventHandler
{
public:
EventHandler();
void handleMouseMove(double dx, double dy);
void handleButtonPress(int button_mask);
void handleButtonRelease(int button_mask);
void addMapping(int from, int to);
void mapToMouseButton(int mask, int button);
private:
//< a map to lookup OS button press from JoyCon buttom press
//< JoyCon buttons from byte 4 are & with 256
//< JoyCon buttons from byte 5 are & with 512
QMap<int,int> keyCodeMap;
QMap<int, unsigned short> qt_to_cg;
bool _left_button_down = false;
bool _right_button_down = false;
};
#endif // EVENTHANDLER_H
|
erikmwerner/QJoyControl
|
mainwindow.h
|
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSystemTrayIcon>
#include "joyconworker.h"
// https://stackoverflow.com/questions/40599038/on-linux-whats-a-good-way-to-to-use-hid-reports-over-usb
class QThread;
class StatusWidget;
class InputMapWidget;
namespace Ui {
class MainWindow;
}
/*!
* \brief The MainWindow class is the root of the QJoyControl GUI.
* It can be shown or hidden, but it will remain alive until the application
* is closed.
*/
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
/*!
* \brief MainWindow default constructor
* \param parent usually a nullptr
*/
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
protected:
void closeEvent(QCloseEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
public slots:
void onShow();
void onHide();
void onCameraImageData(QImage img);
void hideAndClose();
void onNewInputData(QList<int> button_data, QList<double> analog_data);
void onDeviceConnectionChanged(QString sn, const unsigned short pid);
void onJoyConStatusMessage(QString message);
signals:
void connectHID(unsigned short vendor_id,
unsigned short product_id,
const wchar_t *serial_number);
void disconnectHID();
void enableInputStreaming(bool);
void updateIrConfig(ir_image_config);
void captureImage(unsigned char);
private slots:
void onDeviceInfoData(QList<unsigned char> device_info, int joycon_type);
void onTemperatureData(float temp_c);
void onBatteryData(int volt, int percent, int status);
void on_pushButtonCapture_clicked();
void on_pushButtonStream_clicked();
void on_checkBoxDiagnostics_toggled(bool checked);
void on_checkBoxAppNap_toggled(bool checked);
void on_checkBoxIdleSleep_toggled(bool checked);
void on_toolButtonRefresh_clicked();
void on_toolButtonConnect_clicked();
void on_toolButtonDisconnect_clicked();
void on_checkBoxInvertIcon_toggled(bool checked);
void on_pushButtonSaveImage_clicked();
void on_comboBoxColorMap_currentIndexChanged(int index);
void showAbout();
void on_checkBoxLeftClick_toggled(bool checked);
void on_checkBoxRightClick_toggled(bool checked);
private:
Ui::MainWindow *ui;
StatusWidget* _status_widget;
EventHandler* _event_handler = nullptr;
QSystemTrayIcon *_tray_icon = nullptr;
QMenu *_tray_icon_menu;
JoyConWorker* _worker;
QThread* _thread;
QAction *_hide_action;
QAction *_show_action;
QAction *_about_action;
QAction *_quit_action;
bool _force_close = false;
unsigned short _joycon_pid = 0;
QString _joycon_sn = QString();
// hold the last button state received
int _last_button_state[3] = {0,0,0};
QImage _current_image = QImage();
QVector<QRgb> _color_table;
InputMapWidget* _l_mapper = nullptr;
InputMapWidget* _zl_mapper = nullptr;
InputMapWidget* _r_mapper = nullptr;
InputMapWidget* _zr_mapper = nullptr;
qint64 _time_last_update; // keep track of the last time the GUI was updated
void loadSettings();
void setupThread();
void addHidItem(struct hid_device_info* info);
void sendCameraConfig();
void saveSettings();
void handleButtons(QList<int> buttons);
double scaleAnalog(double input);
void createTrayIcon(bool is_inverted);
void testButton(int last_button_state, int _last_button_state, int mask);
};
#endif // MAINWINDOW_H
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/VehicleControllerInterface.h
|
<gh_stars>1-10
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "ObstacleSensorComponent.h"
#include "RoadNode.h"
#include "CoreMinimal.h"
#include "Interface.h"
#include "VehicleControllerInterface.generated.h"
class AUrbanTraffic;
class AVehicleBase;
UINTERFACE(BlueprintType)
class URBANTRAFFIC_API UVehicleControllerInterface : public UInterface
{
GENERATED_BODY()
};
class URBANTRAFFIC_API IVehicleControllerInterface
{
GENERATED_BODY()
// ================================================================
// === VEHICLE BINDING ===
// ================================================================
public:
/* Binds autonomous vehicle. */
void bindVehicle(AVehicleBase* vehicle);
/* Unbinds autonomous vehicle. */
void unbindVehicle();
private:
/* Pointer to autonomous vehicle. */
AVehicleBase* vehicle;
// ================================================================
// === AUTO CONTROLLER ===
// ================================================================
protected:
/* Simulates player input every frame. */
void computeDrivingInput(float deltaSeconds);
private:
/* Sets new destination where our vehicle need to move to. */
void setNewTarget(FVector newTarget);
/* The destination in world space where our vehicle need to move to. */
FVector currentTarget;
/* The obstacle sensor when move forward. */
UObstacleSensorComponent* headSensor;
/* The obstacle sensor when move backward. */
UObstacleSensorComponent* backSensor;
/* The obstacle sensor when turn right. */
UObstacleSensorComponent* rightSensor;
/* The obstacle sensor when turn left. */
UObstacleSensorComponent* leftSensor;
UObstacleSensorComponent* laneSensor;
/* Vehicle control parameters. */
float maxSpeed, speedLimit;
/* When the car begin move backward, keep that direction for at least 1 second.
This behaviour makes the AI looks like human, and prevents dead position. */
float forceBackward = -1;
// ================================================================
// === PATH MANAGEMENT ===
// ================================================================
public:
/* Updates target whenever the current is reached. */
bool updatePathTarget();
/* Is the vehicle came from reversed direction. */
bool invertPath;
private:
/* Switchs to new lane. Called when next target is not equals current target. */
void switchLane(int targetLane, float distance = 3000);
/* Internal check for switch to left lane. */
bool canSwitchLeft();
/* Internal check for switch to right lane. */
bool canSwitchRight();
/* Scheduled path nodes to be followed. */
TArray<URoadNode*> roadNodes;
URoadNodePort* inPort;
/* The current exiting port. */
URoadNodePort* endPort;
/* Next node to be travelled. */
URoadNode* nextNode;
/* Remember current selected lane. */
int currentLane;
bool switchingLane;
// ================================================================
// === DEBUGGING ===
// ================================================================
public:
/* Appends auto controller info to debug string. */
void appendDebugString(FString &string);
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/PawnSpectatorComponent.h
|
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "CoreMinimal.h"
#include "Camera/CameraComponent.h"
#include "Components/SceneComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "PawnSpectatorComponent.generated.h"
UCLASS(ClassGroup = (UrbanTraffic), meta = (BlueprintSpawnableComponent))
class URBANTRAFFIC_API UPawnSpectatorComponent : public USceneComponent
{
GENERATED_BODY()
public:
UPawnSpectatorComponent();
//virtual void BeginPlay() override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
UFUNCTION()
void ToggleSpectatorCamera();
UFUNCTION(BlueprintCallable)
virtual void SetSpectatorCamera(int CameraIndex);
UFUNCTION(BlueprintCallable)
void AddSpectatorCamera(UCameraComponent* Camera, bool bAutoActive);
UFUNCTION(BlueprintCallable)
void RemoveSpectatorCamera(UCameraComponent* Camera);
UFUNCTION(BlueprintCallable)
void ClearSpectatorCameras();
protected:
/* Spring arm for the default camera. */
UPROPERTY(EditDefaultsOnly)
USpringArmComponent* SpringArm;
/* The default camera, at zero index. */
UPROPERTY(EditDefaultsOnly)
UCameraComponent* ChaseCamera;
private:
/* List of all cameras. */
TArray<UCameraComponent*> cameras;
/* Index of the activating camera. */
int cameraIndex;
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/UrbanTraffic.h
|
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "StreetLamp.h"
#include "RoadSegment.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "GameFramework/PlayerStart.h"
#include "Modules/ModuleManager.h"
#include "UrbanTraffic.generated.h"
class FUrbanTrafficModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
};
class AVehicleBase;
UCLASS()
class URBANTRAFFIC_API AUrbanTraffic : public AActor
{
GENERATED_BODY()
public:
AUrbanTraffic();
virtual void OnConstruction(const FTransform& Transform) override;
virtual void PostInitializeComponents() override;
virtual void BeginPlay() override;
virtual void Tick(float DeltaSeconds) override;
virtual void BeginDestroy() override;
// ================================================================
// === ENVIRONMENT SYSTEM ===
// ================================================================
public:
/* Collects lighting objects such as street lights. */
UFUNCTION(BlueprintCallable)
void RebuildLightSystem();
protected:
/* Updates lighting system based on day/night shifting. */
UFUNCTION(BlueprintCallable)
void UpdateLightSystem(float TimerHour, bool ForceUpdate = false);
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Environment", meta = (UIMin = "0", UIMax = "24", ClampMin = "0", ClampMax = "24"))
float TimerStart = 8;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Environment", meta = (UIMin = "1", UIMax = "2000", ClampMin = "1", ClampMax = "2000"))
float TimerSpeed = 100;
private:
/* Collection of light components. */
TArray<USceneComponent*> timedLights;
/* Lighting system state: true at night, false at day. */
bool lightState;
// ================================================================
// === VEHICLE SYSTEM ===
// ================================================================
public:
/* Register managed vehicle. */
UFUNCTION(BlueprintCallable)
void RegisterVehicle(AVehicleBase* Vehicle);
/* Unregister managed vehicle. */
UFUNCTION(BlueprintCallable)
void UnregisterVehicle(AVehicleBase* Vehicle);
/* Finds nearest road node to a position. */
URoadNode* findNearestRoadNode(FVector position);
private:
/* Vehicle road data files. */
UPROPERTY(EditAnywhere, Category = "Vehicle")
TArray<FString> RoadFiles;
/* List of all AI Vehicle classes spawned randomly. */
UPROPERTY(EditAnywhere, Category = "Vehicle")
TArray<TSubclassOf<AVehicleBase>> VehicleTypes;
/* Maximum vehicles can run on the map. */
UPROPERTY(EditAnywhere, Category = "Vehicle", meta = (UIMin = "0", UIMax = "10", ClampMin = "0", ClampMax = "10"))
int VehicleDensity = 5;
/* Cleans previous compiled road path system. */
void cleanRoadSystem();
/* Builds road path system from data file. */
void buildRoadSystem();
/* Update spawn volume at specified node. */
void updateVehicleSpawnVolume(bool isBegin);
/* Stores all computer controlled vehicles. */
TArray<AVehicleBase*> vehicles;
/* Stores all road segments. */
TArray<URoadSegment*> roadSegments;
/* Cached collection vehicle ports. */
TArray<URoadNodePort*> roadPorts;
/* Cached collection of vehicle nodes. */
TArray<URoadNode*> roadNodes;
/* Only update spawn nodes when origin changed. */
URoadNode* spawnOrigin;
/* Cached data for collecting spawn volume nodes and distance from them to origin node. */
TMap<URoadNode*, float> spawnVolumeNodes;
// ================================================================
// === DEMONSTATION ===
// ================================================================
//public:
// UPROPERTY(EditAnywhere, BlueprintReadOnly)
// APawn* PlayerPawn;
//
private:
/* Recursively call before all preload levels is loaded. */
UFUNCTION()
void ConsumePreloadLevels();
UPROPERTY(EditAnywhere)
TArray<FName> PreloadLevels;
UPROPERTY(EditAnywhere, Category = "Demonstration")
bool PossessPlayerAI;
// ================================================================
// === DEBUGGING ===
// ================================================================
private:
/* Display vehicle road paths. */
UPROPERTY(EditAnywhere, NonTransactional, Category = "Debug")
bool DrawRoadPaths;
/* Display guide nodes of vehicle crossroad. */
UPROPERTY(EditAnywhere, NonTransactional, Category = "Debug")
bool DrawRoadCrosses;
/* Display speed limit of vehicle road nodes. */
UPROPERTY(EditAnywhere, NonTransactional, Category = "Debug")
bool DrawRoadLimits;
/* Display speed limit of vehicle road nodes. */
UPROPERTY(EditAnywhere, NonTransactional, Category = "Debug")
bool DrawRoadVectors;
//UFUNCTION(BlueprintCallable, CallInEditor)
//void recaptureNavigation();
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/TrafficLight.h
|
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "CoreMinimal.h"
#include "Engine/StaticMeshActor.h"
#include "Components/BoxComponent.h"
#include "TrafficLight.generated.h"
UENUM(BlueprintType)
enum class TrafficLightState : uint8 {
Red, Yellow, Green, Blink
};
/**
*
*/
UCLASS(Abstract)
class URBANTRAFFIC_API ATrafficLight : public AStaticMeshActor
{
GENERATED_BODY()
public:
ATrafficLight();
virtual void Tick(float DeltaSeconds) override;
virtual void BeginPlay() override;
protected:
/* When the master is set, this will follow its signal, standalone mode will be disabled. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "SynchronousSignal")
ATrafficLight* Master = nullptr;
/* Is this will counter the master light signal, or follow it. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "SynchronousSignal")
bool Reversed = false;
/* Current light state. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "StandaloneSignal")
TrafficLightState LightState = TrafficLightState::Red;
/* The time period which the red lights on. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "StandaloneSignal")
int RedPeriod = 20;
/* The time period which the yellow lights on. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "StandaloneSignal")
int YellowPeriod = 3;
/* The time period which the green lights on. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "StandaloneSignal")
int GreenPeriod = 17;
/* The time period which the yellow lights flash. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "StandaloneSignal")
int BlinkPeriod = 1;
/* Countdown timer determines when the lights change their state. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "StandaloneSignal")
int TickCountdown = 1;
UPROPERTY(VisibleDefaultsOnly, SimpleDisplay, BlueprintReadOnly)
UBoxComponent* VehicleBlocker;
private:
/* Collection of red lights. */
USceneComponent* red;
/* Collection of yellow lights. */
USceneComponent* yellow;
/* Collection of green lights. */
USceneComponent* green;
/* Yellow light on/off state in blink mode. */
bool blinkState = false;
/* Precomputed reversed light state. */
TrafficLightState reversedState;
/* Sets new light state and adjust relevant properties. */
void setLightState(TrafficLightState newState, bool setCountdown = true);
/* Cached slaves which follow this light signal. */
TArray<ATrafficLight*> slaves;
/* Update light state of slaves. */
void updateSlaves();
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/RoadNode.h
|
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
//#include "CoreMinimal.h"
#include "RoadNode.generated.h"
#define DEBUG_ROAD_PATH (1 << 0)
#define DEBUG_ROAD_CROSS (1 << 1)
#define DEBUG_ROAD_LIMIT (1 << 2)
#define DEBUG_ROAD_VECTOR (1 << 3)
class URoadNode;
class URoadNodePort;
class URoadNodeNormal;
class URoadNodeCross;
class URoadNodeGuide;
class URoadSegment;
UENUM(BlueprintType)
enum class RoadNodeType : uint8 {
Null UMETA(DisplayName = "Null Node"),
Port UMETA(DisplayName = "Port Node"),
Normal UMETA(DisplayName = "Normal Node"),
Cross UMETA(DisplayName = "Cross Node"),
Guide UMETA(DisplayName = "Guide Node")
};
UENUM(BlueprintType)
enum class RoadTurnType : uint8 {
None UMETA(DisplayName = "No Turn"),
Left UMETA(DisplayName = "Turn Left"),
Right UMETA(DisplayName = "Turn Right")
};
/**
*
*/
class URBANTRAFFIC_API URoadNode
{
public:
URoadNode(URoadSegment* segment, int nextIndex, FVector position);
virtual ~URoadNode();
/* Determines the type of this node: port, normal, cross, or guide. */
virtual RoadNodeType getNodeType() { return RoadNodeType::Null; }
/* Determines turn type of this node: left, right, or straight. */
virtual RoadTurnType getTurnType();
/* Compiles raw data, only called when raw data is set completely. */
virtual void compileData();
/* Creates persistant visual debug objects. */
virtual void drawDebug(UWorld* world, uint8 debugFlags);
/* Computes target position (in world space) based on this node. */
virtual FVector computeTarget(int lane, bool invert);
/* Gets the segment that holds this node. */
URoadSegment* getSegment();
/* Gets prescaled forward/backward vector. */
FVector getHeadVector(bool invert, float scale = 1.0f);
/* Gets prescaled right/left vector. */
FVector getHandVector(bool invert, float scale = 1.0f);
/* Gets distance from this node to segment's port. */
float getLengthOnSegment(bool invert);
/* Gets distance from this node to next node. */
float getNodeLength(bool invert);
/* Checks if distance from the node to any of ports is under threshold. */
bool isNearAnyPort(float threshold);
FVector findNearestPointOnVectors(FVector position);
// ==================================
// = Raw Data =
// ==================================
/* The index (in local space) of the next node which connected to this node. */
int nextIndex;
/* The position of this node (in world space). */
FVector position;
/* The speed limiter. Max value 1.0 means no limit. */
float speedLimit = 1.0f;
// ==================================
// = Precomputed Data =
// ==================================
/* Precomp, the collection of adjacent-distance pairs. */
TMap<URoadNode*, float> adjacentNodes;
/* Precomp, distance to start port. */
float distanceToStart = 0;
/* Precomp, distance to end port. */
float distanceToEnd = 0;
protected:
/* Referrences to the parent segment. */
URoadSegment* segment;
/* Precomp, node direction vectors. */
FVector forward, backward, right, left;
/* Precomp, distance to the next node. */
float lengthForward = 0;
/* Precomp, distance to the previous node. */
float lengthBackward = 0;
public:
/* Finds node in array which nearest a position. */
static URoadNode* findNearestNode(FVector position, TArray<URoadNode*> &nodes);
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/RoadNodeGuide.h
|
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "RoadNode.h"
#include "CoreMinimal.h"
class URoadTurn;
/**
*
*/
class URBANTRAFFIC_API URoadNodeGuide : public URoadNode
{
public:
URoadNodeGuide(URoadSegment* segment, FVector position, URoadTurn* turnData, float speedLimit);
virtual RoadNodeType getNodeType() { return RoadNodeType::Guide; }
virtual FVector computeTarget(int lane, bool invert) override;
virtual RoadTurnType getTurnType() override;
private:
/* Refers to the start port. */
URoadTurn* turnData;
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/RoadNodePort.h
|
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "RoadNode.h"
#include "CoreMinimal.h"
/**
*
*/
class URBANTRAFFIC_API URoadNodePort : public URoadNode
{
public:
URoadNodePort(URoadSegment* segment, int nextIndex, FVector position, float laneWidth, int numRights, int numLefts);
virtual RoadNodeType getNodeType() { return RoadNodeType::Port; }
virtual void compileData() override;
virtual void drawDebug(UWorld* world, uint8 debugFlags) override;
virtual FVector computeTarget(int lane, bool invert) override;
/* Appends collection of nodes which start from this port. */
RoadTurnType appendRoadNodes(TArray<URoadNode*> &roadNodes);
/* Maintains current vehicle lane, or selects new valid right lane. */
int randomRightLane(int vehicleLane);
/* Gets min index of left lanes. */
int getMinLeft();
/* Gets max index of left lanes. */
int getMaxLeft();
/* Gets min index of right lanes. */
int getMinRight();
/* Gets max index of right lanes. */
int getMaxRight();
// ================================================================
// === RAW DATA ===
// ================================================================
public:
/* Absolute lane width, in centimeters. */
float laneWidth = 500;
/* Number of left lanes of this node. */
int numLefts = 0;
/* Number of right lanes of this node. */
int numRights = 0;
// ================================================================
// === PRECOMPUTED DATA ===
// ================================================================
public:
/* Connects this port to it's adjacent port. */
void connectPort(URoadNodePort* otherPort);
/* Gets connected port of this port. */
URoadNodePort* getConnectedPort();
private:
/* Fix direction vectors when connect to another port. */
void fixDirectionVectors(URoadNodePort* otherPort);
/* Precomp, for lane selection. */
int minLeft, maxLeft, minRight, maxRight;
/* Precomp, connected port comes from other segment. */
URoadNodePort* connectedPort = nullptr;
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/VehicleHardwareComponent.h
|
<filename>Source/UrbanTraffic/Public/VehicleHardwareComponent.h
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "ObstacleSensorComponent.h"
#include "Tools/SimpleSerial.h"
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "VehicleHardwareComponent.generated.h"
// data offsets
#define ARDUINO_OFFSET_STEERING 2
#define ARDUINO_OFFSET_THROTTLE 4
#define ARDUINO_OFFSET_GEAR 5
#define ARDUINO_OFFSET_LIGHT 6
#define ARDUINO_OFFSET_NUMSENSORS 2
#define ARDUINO_OFFSET_FIRSTSENSOR 3
// data flags
#define ARDUINO_FLAG_THROTTLE_FORWARD (1 << 7)
#define ARDUINO_FLAG_THROTTLE_BACKWARD (1 << 6)
#define ARDUINO_FLAG_LIGHT_HALOGEN (1 << 0)
#define ARDUINO_FLAG_LIGHT_HANDBRAKE (1 << 1)
#define ARDUINO_FLAG_LIGHT_LEFTSIDE (1 << 2)
#define ARDUINO_FLAG_LIGHT_RIGHTSIDE (1 << 3)
// hardware ranges
#define WHEEL_ANGLE_MID 92
#define WHEEL_ANGLE_MIN 44
#define WHEEL_ANGLE_MAX 140
#define WHEEL_PULSE_MIN 15828
#define WHEEL_PULSE_MAX 31860
#define MOTOR_ANALOG_MIN 48
#define MOTOR_ANALOG_MAX 255
#define MOTOR_ANALOG_RANGE (MOTOR_ANALOG_MAX-MOTOR_ANALOG_MIN)
UCLASS( ClassGroup=(UrbanTraffic), meta=(BlueprintSpawnableComponent) )
class URBANTRAFFIC_API UVehicleHardwareComponent : public UActorComponent
{
GENERATED_BODY()
public:
UVehicleHardwareComponent();
virtual void BeginPlay() override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
UFUNCTION(BlueprintCallable)
void Connect(FString SerialPort, int Baudrate);
UFUNCTION(BlueprintCallable)
void Disconnect();
UFUNCTION(BlueprintNativeEvent)
void OnGearChanged(int Gear);
UFUNCTION(BlueprintNativeEvent)
void OnBrakeChanged(bool HandBrake);
UFUNCTION(BlueprintNativeEvent)
void OnLightChanged(bool LightState);
UFUNCTION(BlueprintNativeEvent)
void OnSideLightChanged(bool RightSide, bool LeftSide);
protected:
/* The name of device's serial port. */
UPROPERTY(EditAnywhere, BlueprintReadOnly)
FString SerialPort;
/* The baudrate of device's serial port. */
UPROPERTY(EditAnywhere, BlueprintReadOnly)
int Baudrate = 9600;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool IncludeSensorData;
private:
/* The collection of vehicle sensors. */
TArray<UObstacleSensorComponent*> sensors;
/* Arduino serial handler. */
SimpleSerial arduino;
/* Serialization of control signal to be sent. */
uint8_t controlData[8] = { '$', '#', 0, 0, 0, 0, 0, '\r' };
/* Serialization of sensor data to be sent. */
uint8_t sensorData[16] = { '$', '@', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\r' };
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/SceneLoader.h
|
<reponame>mrlordkaj/UrbanTraffic
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "UrbanTraffic.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/BoxComponent.h"
#include "Components/ArrowComponent.h"
#include "SceneLoader.generated.h"
UCLASS()
class URBANTRAFFIC_API ASceneLoader : public AActor
{
GENERATED_BODY()
public:
ASceneLoader();
UFUNCTION(BlueprintImplementableEvent)
void OnPlayerMovedIn();
UFUNCTION(BlueprintImplementableEvent)
void OnPlayerMovedOut();
protected:
UFUNCTION()
void BeginOverlap(UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult &SweepResult);
UFUNCTION()
void EndOverlap(UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex);
private:
UPROPERTY(VisibleAnywhere)
UBoxComponent* Bounding;
UPROPERTY(EditAnywhere)
AUrbanTraffic* TrafficManager;
UPROPERTY(EditAnywhere)
FName LevelName;
FVector inLocation;
void setLevelLoaded(bool load);
#if WITH_EDITOR
UArrowComponent* arrow;
#endif
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/VehicleBase.h
|
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "VehicleHardwareComponent.h"
#include "VehicleAnimation.h"
#include "UrbanVehicleAI.h"
#include "RoadSegment.h"
#include "CoreMinimal.h"
#include "WheeledVehicle.h"
#include "WheeledVehicleMovementComponent.h"
#include "Components/BoxComponent.h"
#include "Components/TimelineComponent.h"
#include "VehicleBase.generated.h"
#define PAINT_PRIMARY "PrimaryPaint"
#define PAINT_SECONDARY "SecondaryPaint"
#define BONE_CHASSIS "chassis"
#define BONE_WHEEL_LF "wheel_lf"
#define BONE_WHEEL_RF "wheel_rf"
#define BONE_WHEEL_LB "wheel_lb"
#define BONE_WHEEL_RB "wheel_rb"
#define BONE_FRONTSEAT "ped_frontseat"
class AUrbanTraffic;
class ACharacterBase;
class UAudioComponent;
USTRUCT(BlueprintType)
struct URBANTRAFFIC_API FVehiclePaint
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
FLinearColor PrimaryColor = FLinearColor::White;
UPROPERTY(EditAnywhere)
FLinearColor SecondaryColor = FLinearColor::Gray;
};
USTRUCT(BlueprintType)
struct URBANTRAFFIC_API FVehicleDoor
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
UCurveFloat* OpenCurve;
UPROPERTY()
UVehicleAnimation* DoorAnimation;
};
UENUM(BlueprintType)
enum class SideLightState : uint8
{
None,
Left,
Right
};
UCLASS(Abstract)
class URBANTRAFFIC_API AVehicleBase : public AWheeledVehicle
{
GENERATED_BODY()
DECLARE_DELEGATE_OneParam(FHandBrakeDelegate, bool);
DECLARE_DELEGATE_OneParam(FSideLightDelegate, SideLightState);
public:
AVehicleBase();
virtual void PostInitializeComponents() override;
virtual void OnConstruction(const FTransform& Transform) override;
virtual void BeginPlay() override;
virtual void Tick(float DeltaSeconds) override;
virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override;
virtual void BeginDestroy() override;
bool Destroy(bool bNetForce = false, bool bShouldModifyLevel = true);
// ================================================================
// === VEHICLE APPEARANCE ===
// ================================================================
public:
/* Randomize vehicle paint colors. */
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Appearance")
void RandomizeVehiclePaint();
/* Applied vehicle paint colors. */
UPROPERTY(EditInstanceOnly, BlueprintReadOnly, Category = "Appearance")
FVehiclePaint VehiclePaint;
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Appearance")
UAudioComponent* EngineSound;
protected:
/* Static mesh for generates wheels. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Appearance")
UStaticMesh* WheelMesh;
/* Collection of all available paint colors. */
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Appearance")
TArray<FVehiclePaint> PaintSets;
private:
/* Light component containers. */
USceneComponent *lights, *brakes, *lefts, *rights;
/* All wheel mesh components. */
TArray<UStaticMeshComponent*> wheelComponents;
// ================================================================
// === VEHICLE ANIMATION ===
// ================================================================
public:
UFUNCTION(BlueprintCallable)
FVector GetSocketRelativeLocation(FName SocketName, bool bReverseSide = false);
UPROPERTY(BlueprintReadOnly)
ACharacterBase* MyDriver;
protected:
UFUNCTION(BlueprintCallable)
void AnimateDoor(FName DoorName, bool bReverse, float Duration = 0.2f);
private:
UPROPERTY(EditDefaultsOnly)
TMap<FName, FVehicleDoor> VehicleDoors;
// ================================================================
// === TRAFFIC SYSTEM MANAGEMENT ===
// ================================================================
public:
/* Finds the point on current segment which nearest to vehicle. */
UFUNCTION(BlueprintCallable)
FVector FindNearestPointOnSegment();
/* Gets distance from vehicle to nearest point on segment. */
UFUNCTION(BlueprintCallable)
float GetDistanceToSegment();
/* Gets absolute lane index. */
UFUNCTION(BlueprintCallable)
float GetAbsoluteLane();
/* Called when vehicle is spawned in the traffic system for demostration. */
void onPlacedInSystem(AUrbanTraffic* manager);
/* Called when vehicle is spawned in the traffic system. */
void onSpawnedInSystem(AUrbanTraffic* manager);
/* TEMPORARY: Checks if a segment can be spawn a new vehicle. */
bool isSpawnableAt(URoadSegment* segment, bool invert);
/* Previous travelled node. */
URoadNode* prevNode;
private:
/* Unregister this vehicle, called when destroy. */
void onDestroyInSystem();
/* Pointer to the traffic manager. */
AUrbanTraffic* trafficManager;
// ================================================================
// === VEHICLE AI ===
// ================================================================
public:
/* Max speed can reach in AI controlled mode. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
float MaxSpeedLimit = 50;
/* Bounding for generates obstacle sensors. */
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly)
UBoxComponent* Bounding;
/* Sets autonomous driving mode. Only valid when bind with VehicleControllerInterface. */
void setAutoMode(bool isAuto);
/* Checks whether autonomus driving mode. */
bool isAutoMode();
private:
/* Vehicle AI controller. */
IVehicleControllerInterface* autoController;
//FVector boundingOffset;
// ================================================================
// === CONTROL DELEGATE ===
// ================================================================
public:
/* Toggles auto control mode. */
UFUNCTION(BlueprintCallable)
void ToggleAutonomous();
/* Toggles halogen light state. */
UFUNCTION(BlueprintCallable)
void ToggleLight();
/* Sets throttle value. */
UFUNCTION(BlueprintCallable)
void SetThrottle(float Throttle);
/* Sets steering value. */
UFUNCTION(BlueprintCallable)
void SetSteering(float Steering);
/* Sets halogen light state. */
UFUNCTION(BlueprintCallable)
void SetLightState(bool bLightState);
/* Sets side light state. */
UFUNCTION(BlueprintCallable)
void SetSideLightState(SideLightState SideState);
UFUNCTION(BlueprintCallable)
SideLightState GetSideLightState();
/* Sets hand brake state. */
UFUNCTION(BlueprintCallable)
void SetHandBrake(bool bHandBrake);
/* Realtime measurement of speed in km/h. */
UPROPERTY(BlueprintReadOnly)
float Speed;
/* Realtime gear level. */
UPROPERTY(BlueprintReadOnly)
int Gear;
/* Realtime throttle value. */
UPROPERTY(BlueprintReadOnly)
float Throttle;
/* Realtime steering value. */
UPROPERTY(BlueprintReadOnly)
float Steering;
/* Realtime angle of front wheels. */
UPROPERTY(BlueprintReadOnly)
float WheelAngle;
private:
/* Current handbrake state, for changes notify. */
bool handBrakeState;
/* Current brake/reverse light state, for changes notify. */
bool brakeLightState = true;
/* Current light state, for changes notify. */
bool lightState = true;
/* Current sidelight state, for changes notify. */
SideLightState sideLightState;
/* Countdown for sidelight blink. */
float sideLightBlink;
// ================================================================
// === EVENT DELEGRATE ===
// ================================================================
public:
void addHandlingListener(UVehicleHardwareComponent* listener);
private:
TArray<UVehicleHardwareComponent*> handlingListeners;
// ================================================================
// === DEBUGGING ===
// ================================================================
public:
//UFUNCTION(BlueprintCallable)
//FString GetSensorDebugString();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool DrawDebugString;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool DrawSegmentTrace;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool DrawTargetHistory;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Debug")
bool DrawObstacleSensors;
private:
void drawDebugInfo();
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/RoadSegment.h
|
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "RoadNode.h"
#include "RoadNodeNormal.h"
#include "RoadNodePort.h"
#include "RoadNodeCross.h"
#include "CoreMinimal.h"
class AUrbanTraffic;
/**
*
*/
class URBANTRAFFIC_API URoadSegment
{
public:
URoadSegment(AUrbanTraffic* manager);
/* Reset precomp data and free their memory. */
~URoadSegment();
/* Compiles runtime data from raw data. */
void compileData(TArray<URoadNode*> newNodes);
void drawDebug(UWorld* world, uint8 debugFlags);
/* Gets cross type node if this is a crossing segment. */
URoadNodeCross* getCrossNode();
/* Gets node by index. */
URoadNode* getNode(int index);
/* Collects all available nodes in this segment. */
TArray<URoadNode*> collectNodes(bool invert);
/* Collects all available ports in this segment. */
TArray<URoadNodePort*> collectPorts(bool invert);
/* Collects all entry (can enter from outside) ports in this segment. */
TArray<URoadNodePort*> collectEntryPorts();
/* Gets total length of this segment. */
float getSegmentLength();
/* Gets length of a point on segment. */
float getLengthOnSegment(FVector position, bool invert);
/* Gets max vehicles from density. */
int computeMaxVehicles(int laneDensity);
private:
/* UrbanTraffic manager actor. */
AUrbanTraffic* manager;
/* Cached data, only set on crossing segment. */
URoadNodeCross* crossNode = nullptr;
/* Stores all nodes in this segment. */
TArray<URoadNode*> nodes;
/* Cached data, for collect all ports. */
TArray<URoadNodePort*> ports;
/* Precomp, total length of segment. */
float segmentLength = 0;
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/ObstacleSensorComponent.h
|
<filename>Source/UrbanTraffic/Public/ObstacleSensorComponent.h
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "CoreMinimal.h"
#include "Components/SceneComponent.h"
#include "ObstacleSensorComponent.generated.h"
/**
*
*/
UCLASS(ClassGroup = (UrbanTraffic), meta = (BlueprintSpawnableComponent))
class URBANTRAFFIC_API UObstacleSensorComponent : public USceneComponent
{
GENERATED_BODY()
public:
UObstacleSensorComponent();
virtual void OnRegister() override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
virtual void SetActive(bool bNewActive, bool bReset = false) override;
/* Checks if any obstacle detected. */
UFUNCTION(BlueprintCallable)
bool IsObstacleDetected();
/* Gets distance to the nearest obstacle if found. */
UFUNCTION(BlueprintCallable)
float GetNearestDistance();
/* Gets normalized factor value. Range from 0 to 1. */
UFUNCTION(BlueprintCallable)
float GetNormalizedValue();
/* Force perform a collision test. */
UFUNCTION(BlueprintCallable)
bool DoCollisionTest();
/* Force perform a collision test with custom length. */
UFUNCTION(BlueprintCallable)
bool DoCustomCollisionTest(float CustomTraceLength, float &ObstacleDistance);
/* Number of testing rays. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (UIMin = "1", UIMax = "11", ClampMin = "1", ClampMax = "11"))
int RayQuantity = 1;
/* Total width of all rays. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (UIMin = "1", UIMax = "1000"))
float TraceWidth;
/* Total angle of all rays. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (UIMin = "0", UIMax = "180"))
float TraceAngle;
/* Base trace length for collision testing. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (UIMin = "0", UIMax = "2000"))
FVector2D TraceLength = FVector2D(0, 1000);
/* Base range for calculate normalized value from obstacle distance. */
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FVector2D NormalizeRange = FVector2D(0, 1);
/* The collision channel of testing. */
UPROPERTY(BlueprintReadWrite)
TEnumAsByte<ECollisionChannel> CollisionChannel = ECollisionChannel::ECC_PhysicsBody;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int SensorDataOrder;
private:
bool obstacleDetected;
float nearestDistance;
TArray<FHitResult> hitResults;
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/VehicleObserverComponent.h
|
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "TrafficLight.h"
#include "VehicleBase.h"
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "VehicleObserverComponent.generated.h"
class UParticleSystemComponent;
class USoundCue;
USTRUCT(BlueprintType)
struct URBANTRAFFIC_API FVehiclePartHealth
{
GENERATED_BODY()
/* The mesh to shown when the part is broken. */
UPROPERTY(EditAnywhere)
UStaticMesh* BrokenMesh;
/* Damage multiplier, higher value easier to destroy. */
UPROPERTY(EditAnywhere, meta = (UIMin = "0", ClampMin = "0"))
float DamageMultiplier = 1;
/* Current health, destroy the part when this value down to zero. */
float currentHealth = 100;
UStaticMeshComponent* brokenMeshComponent;
};
UCLASS( ClassGroup=(UrbanTraffic), meta=(BlueprintSpawnableComponent) )
class URBANTRAFFIC_API UVehicleObserverComponent : public UActorComponent
{
GENERATED_BODY()
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnSignalConflict, ATrafficLight*, TrafficLight);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnVehicleConflict, AVehicleBase*, Vehicle);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnCharacterConflict, ACharacter*, Character);
public:
UVehicleObserverComponent();
virtual void BeginPlay() override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
UFUNCTION(BlueprintCallable)
void GiveExplosion(FVector ExplosionLocation, float BaseDamage);
UFUNCTION(BlueprintCallable)
void GiveDamage(FName PartName, float BaseDamage);
UPROPERTY(BlueprintAssignable)
FOnSignalConflict OnSignalConflict;
UPROPERTY(BlueprintAssignable)
FOnVehicleConflict OnVehicleConflict;
UPROPERTY(BlueprintAssignable)
FOnCharacterConflict OnCharacterConflict;
private:
UFUNCTION()
void OnComponentHit(UPrimitiveComponent* HitComp,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
FVector NormalImpulse,
const FHitResult& Hit);
UFUNCTION()
void BeginOverlap(UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult &SweepResult);
UFUNCTION()
void EndOverlap(UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex);
UFUNCTION()
void RemoveDestroyedPart(FName PartName, UStaticMeshComponent* BrokenMeshComponent);
UPROPERTY(EditDefaultsOnly)
TMap<FName, FVehiclePartHealth> VehicleParts;
UPROPERTY(EditDefaultsOnly)
float AutoRemoveDelay;
/* Cached pointer for owner vehicle. */
AVehicleBase* vehicle;
/* Stores overlapped traffic lights. */
TMap<AActor*, FVector> overlapActors;
// ================================================================
// === FIRE DAMAGE ===
// ================================================================
public:
UFUNCTION(BlueprintCallable)
void GiveFire(float DamagePerSecond);
private:
UPROPERTY(EditDefaultsOnly, Category = "Fire")
float FireScale = 10.0f;
UPROPERTY(EditDefaultsOnly, Category = "Fire")
UParticleSystem* FireTemplate;
UPROPERTY(EditDefaultsOnly, Category = "Fire")
USoundCue* FireSound;
UPROPERTY(EditDefaultsOnly, Category = "Fire")
USoundCue* ExplosionSound;
/* Attached particle component when fire activated. */
UParticleSystemComponent* fireComponent;
/* Damage per seconds given by fire. */
float fireDamage;
/* When this value down to zero, the vehicle will explode. */
float fireHeath = 100.0f;
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/RoadTurn.h
|
<filename>Source/UrbanTraffic/Public/RoadTurn.h<gh_stars>1-10
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "RoadNodeGuide.h"
#include "CoreMinimal.h"
/**
*
*/
class URBANTRAFFIC_API URoadTurn
{
public:
URoadTurn(URoadNodePort* startPort, URoadNodeCross* crossNode, URoadNodePort* endPort);
~URoadTurn();
void drawDebug(UWorld* world, uint8 debugFlags);
/* Collects all nodes, included both ports and guides. */
TArray<URoadNode*> collectNodes();
/* Gets turn type: left, right, or straight. */
RoadTurnType getTurnType();
/* Gets start port. */
URoadNodePort* getStartPort();
/* Gets end port. */
URoadNodePort* getEndPort();
private:
RoadTurnType turnType;
URoadSegment* segment;
TArray<URoadNodeGuide*> guideNodes;
URoadNodePort* startPort;
URoadNodeCross* crossNode;
URoadNodePort* endPort;
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/CharacterBase.h
|
<filename>Source/UrbanTraffic/Public/CharacterBase.h
/*
* The MIT License
*
* Copyright 2020 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "VehicleBase.h"
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "CharacterBase.generated.h"
UCLASS()
class URBANTRAFFIC_API ACharacterBase : public ACharacter
{
GENERATED_BODY()
public:
ACharacterBase();
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
// ================================================================
// === ATTACH/DETACH VEHICLES ===
// ================================================================
public:
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
void BeginGetInVehicle();
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
void BeginGetOutVehicle();
protected:
/* Begin attaching nearest vehicle (start get-in animations). */
UFUNCTION(BlueprintCallable)
void AttachNearestVehicle();
/* Finish detaching current vehicle (finish get-out animations). */
UFUNCTION(BlueprintCallable)
void DetachCurrentVehicle();
UPROPERTY(BlueprintReadOnly)
AVehicleBase* MyVehicle;
private:
UFUNCTION()
void BeginOverlap(UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult &SweepResult);
UFUNCTION()
void EndOverlap(UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex);
TArray<AVehicleBase*> nearVehicles;
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/Tools/SimpleSerial.h
|
<filename>Source/UrbanTraffic/Public/Tools/SimpleSerial.h
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "Windows/AllowWindowsPlatformTypes.h"
#include "Windows/MinWindows.h"
#include "Windows/HideWindowsPlatformTypes.h"
#include <inttypes.h>
//#include <Windows.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include <iostream>
//#include <string>
//#include <string.h>
//#include <chrono>
//#include <thread>
//#include <time.h>
//#include <fstream>
using namespace std;
class SimpleSerial {
private:
bool comConnected = false;
HANDLE comHandler;
COMSTAT comStatus;
DWORD comErrors;
//string syntax_name_;
//char front_delimiter_;
//char end_delimiter_;
//void CustomSyntax(string syntax_type);
public:
~SimpleSerial();
void open(char* comPort, DWORD baudrate);
//string ReadSerialPort(int reply_wait_time, string syntax_type);
int write(uint8_t *data, uint32_t length);
void close();
bool isConnected();
};
|
mrlordkaj/UrbanTraffic
|
Source/UrbanTraffic/Public/RoadNodeCross.h
|
<filename>Source/UrbanTraffic/Public/RoadNodeCross.h
/*
* The MIT License
*
* Copyright 2019 <NAME>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "RoadNodePort.h"
#include "CoreMinimal.h"
class URoadTurn;
/**
*
*/
class URBANTRAFFIC_API URoadNodeCross : public URoadNode
{
public:
~URoadNodeCross();
URoadNodeCross(URoadSegment* segment, int nextIndex, FVector position);
virtual RoadNodeType getNodeType() { return RoadNodeType::Cross; }
virtual void compileData() override;
virtual void drawDebug(UWorld* world, uint8 debugFlags) override;
TArray<URoadTurn*> getPortTurns(URoadNodePort* port);
private:
TMap<URoadNodePort*, TArray<URoadTurn*>> portTurns;
};
|
PLSysSec/haybale
|
tests/bcfiles/struct-O3.c
|
#include <stdlib.h>
struct TwoInts {
int el1;
int el2;
};
struct WithPointer {
volatile struct TwoInts ti;
volatile struct TwoInts* volatile* ti_2;
};
// function that takes a pointer to a struct as an argument
// really the point here is to get a GEP with multiple indices on -O3
__attribute__((noinline))
int called(struct WithPointer* wp, int x) {
wp->ti.el2 = x - 3;
return wp->ti_2[0]->el2;
}
int with_ptr(int x) {
volatile struct TwoInts* ti = (volatile struct TwoInts*) malloc(sizeof(struct TwoInts));
struct WithPointer* wp = (struct WithPointer*) malloc(sizeof(struct WithPointer));
if (wp == NULL || ti == NULL) {
return -1;
}
wp->ti.el2 = 0;
wp->ti_2 = &ti;
wp->ti_2[0] = &wp->ti;
return called(wp, x);
}
|
khorben/daemonize
|
src/main.c
|
<filename>src/main.c
/* $Id$ */
/* Copyright (c) 2020-2021 <NAME> <<EMAIL>> */
/* This file is part of daemonize */
/* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "daemonize.h"
/* main */
/* private */
/* prototypes */
static int _usage(void);
/* public */
/* functions */
/* main */
int main(int argc, char * argv[])
{
DaemonizePrefs prefs;
int o;
memset(&prefs, 0, sizeof(prefs));
prefs.daemon = 1;
while((o = getopt(argc, argv, "BFg:p:u:")) != -1)
switch(o)
{
case 'B':
prefs.daemon = 1;
break;
case 'F':
prefs.daemon = 0;
break;
case 'g':
prefs.groupname = optarg;
break;
case 'p':
prefs.pidfile = optarg;
break;
case 'u':
prefs.username = optarg;
break;
default:
return _usage();
}
if(optind + 1 > argc)
return _usage();
return daemonize(&prefs, argv[optind],
argc - optind - 1, &argv[optind + 1]);
}
/* private */
/* functions */
/* usage */
static int _usage(void)
{
fputs("Usage: " PROGNAME_DAEMONIZE " [-BF][-p filename][-u username][-g group] program [args...]\n"
" -B Run in background\n"
" -F Run in foreground\n"
" -g Use the privileges of this group\n"
" -p Set the PID file\n"
" -u Use the privileges of this user\n", stderr);
return 1;
}
|
khorben/daemonize
|
src/daemonize.c
|
/* $Id$ */
/* Copyright (c) 2020-2021 <NAME> <<EMAIL>> */
/* This file is part of daemonize */
/* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#include <sys/param.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <grp.h>
#include <pwd.h>
#include <errno.h>
#include "common.h"
#include "daemonize.h"
/* Daemonize */
/* private */
/* prototypes */
static int _daemonize_error(char const * message);
static int _daemonize_prefs(DaemonizePrefs const * prefs, char ** env);
/* public */
/* functions */
/* daemonize */
int daemonize(DaemonizePrefs const * prefs, char const * program,
int argc, char * argv[])
{
char ** args;
char * env[2] = { NULL, NULL };
int i;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\", %d, \"%s\")\n", __func__, program,
argc, argv[0]);
#endif
if((args = malloc(sizeof(*args) * (argc + 2))) == NULL)
return _daemonize_error(NULL);
if(prefs != NULL && _daemonize_prefs(prefs, env) != 0)
{
free(args);
return 2;
}
if((args[0] = strdup(program)) == NULL)
{
free(args);
return _daemonize_error("strdup");
}
for(i = 0; i < argc; i++)
args[i + 1] = argv[i];
args[argc + 1] = NULL;
execve(program, args, env);
free(args[0]);
free(args);
free(env[0]);
return _daemonize_error(program);
}
/* private */
/* daemonize_error */
static int _daemonize_error(char const * message)
{
fprintf(stderr, "%s%s%s: %s\n", PROGNAME_DAEMONIZE,
(message != NULL) ? ": " : "",
(message != NULL) ? message : "",
strerror(errno));
return 2;
}
/* daemonize_prefs */
static int _prefs_setgroups(char const * username);
static int _daemonize_prefs(DaemonizePrefs const * prefs, char ** env)
{
struct passwd * pw = NULL;
struct group * gr = NULL;
uid_t uid;
gid_t gid;
size_t len;
FILE * fp = NULL;
const char home[] = "HOME=";
/* lookup the target user if set */
if(prefs->username != NULL)
{
if((pw = getpwnam(prefs->username)) == NULL)
return _daemonize_error(prefs->username);
uid = pw->pw_uid;
gid = pw->pw_gid;
}
/* lookup the target group */
if(prefs->groupname != NULL)
{
if((gr = getgrnam(prefs->groupname)) == NULL)
return _daemonize_error(prefs->groupname);
gid = gr->gr_gid;
}
else if(pw != NULL && (gr = getgrgid(gid)) == NULL)
return _daemonize_error("getgrgid");
/* prepare the environment */
if(pw == NULL && (pw = getpwuid(getuid())) == NULL)
return _daemonize_error("getpwuid");
if(env != NULL && pw->pw_dir != NULL && (len = strlen(pw->pw_dir)) > 0)
{
/* set $HOME */
if((env[0] = malloc(sizeof(home) + len)) == NULL)
return _daemonize_error("malloc");
snprintf(env[0], sizeof(home) + len, "%s%s", home, pw->pw_dir);
}
/* open the PID file before dropping permissions */
if(prefs->pidfile != NULL && (fp = fopen(prefs->pidfile, "w")) == NULL)
{
free(env[0]);
return _daemonize_error(prefs->pidfile);
}
/* set the groups and user if set */
if(gr != NULL)
{
if(setgid(gid) != 0)
_daemonize_error("setgid");
if(setegid(gid) != 0)
_daemonize_error("setegid");
}
if(prefs->username != NULL)
{
_prefs_setgroups(prefs->username);
if(setuid(uid) != 0)
_daemonize_error("setuid");
if(seteuid(uid) != 0)
_daemonize_error("seteuid");
}
/* actually daemonize */
if(prefs->daemon && daemon(0, 0) != 0)
{
if(fp != NULL)
fclose(fp);
free(env[0]);
return _daemonize_error("daemon");
}
/* write the PID file */
if(fp != NULL)
{
/* XXX check for errors */
fprintf(fp, "%u\n", getpid());
if(fclose(fp) != 0)
/* XXX should log instead */
_daemonize_error(prefs->pidfile);
}
return 0;
}
static int _prefs_setgroups(char const * username)
{
int ret;
struct group * gr;
int i;
int n = 0;
gid_t * groups = NULL;
gid_t * p;
setgroupent(1);
while((gr = getgrent()) != NULL)
for(i = 0; gr->gr_mem[i] != NULL; i++)
{
if(strcmp(gr->gr_mem[i], username) != 0)
continue;
if((p = realloc(groups, sizeof(*groups) * (n + 1)))
== NULL)
{
free(groups);
return _daemonize_error("realloc");
}
groups = p;
groups[n++] = gr->gr_gid;
}
endgrent();
ret = setgroups(n, groups);
free(groups);
if(ret != 0)
_daemonize_error("setgroups");
return ret;
}
|
noorus/libminibmcapture
|
include/libminibmcapture.h
|
<filename>include/libminibmcapture.h
// libminibmcapture (c) 2020 noorus
// This software is licensed under the zlib license.
// See the LICENSE file which should be included with
// this source distribution for details.
#pragma once
#include <cstdint>
namespace minibm {
//! \enum DeviceFlags
//! \brief Bitflags that can exist for a given device.
enum DeviceFlags: uint32_t {
Device_CanAutodetectDisplayMode = 1 ///< This device can autodetect the input display mode.
};
# define MINIBM_CALL __stdcall
#ifdef MINIBM_STATIC
extern "C" {
//! \fn void __stdcall get_version( char* out_version, uint32_t versionlen, uint32_t* out_minibmver );
//! \brief Get the library version.
//! \param [out] out_version Pointer to a buffer where the version string will be copied.
//! \param versionlen Length of the buffer pointed to by out_version.
//! \param [out] out_minibmver Pointer to a variable that will receive the libminibmcapture API version number.
void MINIBM_CALL get_version(
char* out_version, uint32_t versionlen, uint32_t* out_minibmver );
//! \fn uint32_t __stdcall get_devices();
//! \brief Get the number of available Blackmagic devices.
//! \returns The number of devices.
uint32_t MINIBM_CALL get_devices();
//! \fn void __stdcall set_options( const char* library_options );
//! \brief Sets a global options string for the library.
//! \param library_options A properly formatted options string.
//! Can be empty or null if no extra options are needed.
void MINIBM_CALL set_options( const char* library_options );
//! \fn bool __stdcall get_device( uint32_t index, char* out_name, uint32_t namelen, int64_t* out_id, uint32_t* out_displaymodecount, uint32_t* out_flags );
//! \brief Get the details of a specific Blackmagic device.
//! \param index Zero-based index of the target device.
//! \param [out] out_name Pointer to a buffer where the device name will be copied.
//! \param namelen Length of the buffer pointed to by out_name.
//! \param [out] out_id Pointer to a variable that will receive the persistent unique device ID.
//! \param [out] out_displaymodecount Pointer to a variable that will receive the number of available display modes on the device.
//! \param [out] out_flags Pointer to a variable that will receive the device flags. \see DeviceFlags
//! \returns True if it succeeds, false if it fails.
bool MINIBM_CALL get_device(
uint32_t index, char* out_name, uint32_t namelen, int64_t* out_id,
uint32_t* out_displaymodecount, uint32_t* out_flags );
//! \fn bool __stdcall get_device_displaymode( uint32_t device, uint32_t displaymode, uint32_t* out_width, uint32_t* out_height, uint32_t* out_timescale, uint32_t* out_frameduration, uint32_t* out_modecode );
//! \brief Get the details of a specifics display mode on a specific Blackmagic device.
//! The display mode's FPS can be calculated by: (timescale / frameduration)
//! \param device Zero-based index of the target device.
//! \param displaymode Zero-based index of the target display mode.
//! \param [out] out_width Pointer to a variable that will receive the width in pixels.
//! \param [out] out_height Pointer to a variable that will receive the height in pixels.
//! \param [out] out_timescale Pointer to a variable that will receive the time scale.
//! \param [out] out_frameduration Pointer to a variable that will receive the frame duration.
//! \param [out] out_modecode Pointer to a variable that will receive the internal unique code for this display mode.
//! \returns True if it succeeds, false if it fails.
bool MINIBM_CALL get_device_displaymode(
uint32_t device, uint32_t displaymode, uint32_t* out_width,
uint32_t* out_height, uint32_t* out_timescale,
uint32_t* out_frameduration, uint32_t* out_modecode );
//! \fn bool __stdcall start_capture_single( uint32_t index, uint32_t modecode, const char* source );
//! \brief Starts capturing on a single Blackmagic device.
//! \param index Zero-based index of the target device.
//! \param modecode The unique code of the display mode to use. Can be found by enumerating get_device_displaymode.
//! \param capture_options A properly formatted string of extra options on how the capture should behave.
//! Can be empty or null if no extra options are needed.
//! \returns True if it succeeds, false if it fails.
bool MINIBM_CALL start_capture_single(
uint32_t index, uint32_t modecode, const char* capture_options );
//! \fn bool __stdcall get_frame_bgra32_blocking( uint32_t* out_width, uint32_t* out_height, uint8_t** out_buffer, uint32_t* out_index );
//! \brief Get a single frame from the currently ongoing capture.
//! The call might block until a new frame is available.
//! It does not have to be called with any exact timing.
//! It will always return the latest received frame, and never the same frame twice.
//! The frame index can be used to figure out the number of possibly skipped frames.
//! The image format is always 32-bit BGRA.
//! \param [out] out_width Pointer to a variable that will receive the frame width in pixels.
//! \param [out] out_height Pointer to a variable that will receive the frame height in pixels.
//! \param [out] out_buffer Pointer to a variable that will receive a pointer to the data buffer.
//! The buffer and data in it will be valid until the next get_frame call or stopped capture.
//! \param [out] out_index Pointer to a variable that will receive the index of the returned frame.
//! Frame index counting will always restart from zero when starting a new capture.
//! \returns True if it succeeds, false if it fails.
bool MINIBM_CALL get_frame_bgra32_blocking(
uint32_t* out_width, uint32_t* out_height, uint8_t** out_buffer,
uint32_t* out_index );
//! \fn void __stdcall stop_capture_single();
//! \brief Stop capturing on a single Blackmagic device.
void MINIBM_CALL stop_capture_single();
//! \fn int __stdcall get_json_length();
//! \brief Gets the length of the needed buffer for JSON output.
//! \returns The JSON length in bytes.
int MINIBM_CALL get_json_length();
//! \fn void __stdcall get_json(char *out_buffer, uint32_t buffer_length);
//! \brief Fills a buffer with a JSON dump of all supported device and display mode data.
//! \param [out] out_buffer Pointer to a buffer that will receive the JSON dump.
//! \param buffer_length Length of the buffer in bytes.
void MINIBM_CALL get_json(char *out_buffer, uint32_t buffer_length);
bool MINIBM_CALL read_frame_bgra32_blocking(uint8_t *buffer, uint32_t len)
}
#else
// Typedefs for dynamically importing the above functions.
# define MINIBM_EXPORT __declspec( dllexport )
typedef void( MINIBM_CALL* fn_get_version )(
char* out_version, uint32_t versionlen, uint32_t* out_minibmver );
typedef uint32_t( MINIBM_CALL* fn_get_devices )();
typedef void( MINIBM_CALL* fn_set_options )(
const char* library_options );
typedef bool( MINIBM_CALL* fn_get_device )(
uint32_t index, char* out_name, uint32_t namelen, int64_t* out_id,
uint32_t* out_displaymodecount, uint32_t* out_flags );
typedef bool( MINIBM_CALL* fn_get_device_displaymode )(
uint32_t device, uint32_t displaymode, uint32_t* out_width,
uint32_t* out_height, uint32_t* out_timescale,
uint32_t* out_frameduration, uint32_t* out_modecode );
typedef bool( MINIBM_CALL* fn_start_capture_single )(
uint32_t index, uint32_t modecode, const char* capture_options );
typedef bool( MINIBM_CALL* fn_get_frame_bgra32_blocking )(
uint32_t* out_width, uint32_t* out_height, uint8_t** out_buffer,
uint32_t* out_index );
typedef void( MINIBM_CALL* fn_stop_capture_single )();
typedef int(MINIBM_CALL* fn_get_json_length)();
typedef void(MINIBM_CALL* fn_get_json)(
char *out_buffer, uint32_t buffer_length);
typedef void(MINIBM_CALL* read_frame_bgra32_blocking)(
char *out_buffer, uint32_t buffer_length);
#endif
}
|
noorus/libminibmcapture
|
libminibmcapture/include/utils.h
|
// libminibmcapture (c) 2020 noorus
// This software is licensed under the zlib license.
// See the LICENSE file which should be included with
// this source distribution for details.
#pragma once
#include "pch.h"
namespace minibm {
class RWLock {
protected:
SRWLOCK lock_;
public:
RWLock() { InitializeSRWLock( &lock_ ); }
inline void lock() { AcquireSRWLockExclusive( &lock_ ); }
inline void unlock() { ReleaseSRWLockExclusive( &lock_ ); }
inline void lockShared() { AcquireSRWLockShared( &lock_ ); }
inline void unlockShared() { ReleaseSRWLockShared( &lock_ ); }
};
class ScopedRWLock {
protected:
RWLock* lock_;
bool exclusive_;
bool locked_;
public:
ScopedRWLock( RWLock* lock, bool exclusive = true ):
lock_( lock ), exclusive_( exclusive ), locked_( true )
{
exclusive_ ? lock_->lock() : lock_->lockShared();
}
void unlock()
{
if ( locked_ )
exclusive_ ? lock_->unlock() : lock_->unlockShared();
locked_ = false;
}
~ScopedRWLock()
{
unlock();
}
};
class Event {
public:
using NativeType = HANDLE;
private:
NativeType handle_;
public:
Event( bool initialState = false ): handle_( 0 )
{
handle_ = CreateEventW( nullptr, TRUE, initialState ? TRUE : FALSE, nullptr );
if ( !handle_ )
throw std::exception( "Event creation failed" );
}
inline void set() { SetEvent( handle_ ); }
inline void reset() { ResetEvent( handle_ ); }
inline bool wait( uint32_t milliseconds = INFINITE ) const
{
return ( WaitForSingleObject( handle_, milliseconds ) == WAIT_OBJECT_0 );
}
inline bool check() const
{
return ( WaitForSingleObject( handle_, 0 ) == WAIT_OBJECT_0 );
}
inline NativeType get() const { return handle_; }
~Event()
{
if ( handle_ )
CloseHandle( handle_ );
}
};
inline string bstrToString( BSTR bstr )
{
auto widelen = SysStringLen( bstr );
auto mblen = WideCharToMultiByte(
CP_ACP, 0,static_cast<wchar_t*>( bstr ),
widelen, nullptr, 0, nullptr, nullptr );
string ret( mblen, '\0' );
mblen = ::WideCharToMultiByte(
CP_ACP, 0, static_cast<wchar_t*>( bstr ),
widelen, &ret[0], mblen, nullptr, nullptr );
return ret;
};
}
|
noorus/libminibmcapture
|
libminibmcapture/include/pch.h
|
<reponame>noorus/libminibmcapture
// libminibmcapture (c) 2020 noorus
// This software is licensed under the zlib license.
// See the LICENSE file which should be included with
// this source distribution for details.
#pragma once
#define NTDDI_VERSION NTDDI_WIN10
#define _WIN32_WINNT _WIN32_WINNT_WIN10
#include <sdkddkver.h>
#include <windows.h>
#include <shellapi.h>
#include <shlobj.h>
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#ifdef _DEBUG
//# define _CRTDBG_MAP_ALLOC
# include <crtdbg.h>
#endif
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <wchar.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <eh.h>
#include <intrin.h>
#include <assert.h>
#undef min
#undef max
#include <exception>
#include <memory>
#include <vector>
#include <list>
#include <map>
#include <string>
#include <cstdint>
#include <algorithm>
#include <atomic>
namespace minibm {
using std::string;
using std::vector;
using std::move;
using std::shared_ptr;
using std::unique_ptr;
using std::atomic;
}
|
noorus/libminibmcapture
|
libminibmcapture/include/minibmcap.h
|
<reponame>noorus/libminibmcapture<gh_stars>1-10
// libminibmcapture (c) 2020 noorus
// This software is licensed under the zlib license.
// See the LICENSE file which should be included with
// this source distribution for details.
#pragma once
#include "pch.h"
#include "utils.h"
#include "libminibmcapture.h"
#include "decklink_api/DeckLinkAPIVersion.h"
#include "DeckLinkAPI_h.h"
namespace minibm {
struct Globals {
bool comInitialized_;
Globals();
bool initialize();
void shutdown();
};
extern Globals g_globals;
class BGRA32VideoFrame: public IDeckLinkVideoFrame {
private:
long width_;
long height_;
BMDFrameFlags flags_;
vector<uint8_t> buffer_;
atomic<uint32_t> refCount_;
public:
BGRA32VideoFrame(): width_( 0 ), height_( 0 ), flags_( 0 ), refCount_( 1 ) {}
BGRA32VideoFrame( long width, long height, BMDFrameFlags flags ):
width_( width ), height_( height ), flags_( flags ), refCount_( 1 )
{
buffer_.resize( width_ * height_ * 4 );
}
inline void resize( long width, long height )
{
width_ = width;
height_ = height;
buffer_.resize( width_ * height_ * 4 );
}
inline void match( IDeckLinkVideoFrame* other )
{
if ( width_ != other->GetWidth() || height_ != other->GetHeight() )
resize( other->GetWidth(), other->GetHeight() );
}
inline const vector<uint8_t>& buffer() const { return buffer_; }
void swap( BGRA32VideoFrame& other )
{
std::swap( width_, other.width_ );
std::swap( height_, other.height_ );
buffer_.swap( other.buffer_ );
}
// IDeckLinkVideoFrame
virtual long STDMETHODCALLTYPE GetWidth() { return width_; }
virtual long STDMETHODCALLTYPE GetHeight() { return height_; }
virtual long STDMETHODCALLTYPE GetRowBytes() { return width_ * 4; }
virtual HRESULT STDMETHODCALLTYPE GetBytes( void** buffer )
{
*buffer = reinterpret_cast<void*>( buffer_.data() );
return S_OK;
}
virtual BMDFrameFlags STDMETHODCALLTYPE GetFlags() { return flags_; }
virtual BMDPixelFormat STDMETHODCALLTYPE GetPixelFormat() { return BMDPixelFormat::bmdFormat8BitBGRA; }
virtual HRESULT STDMETHODCALLTYPE GetAncillaryData( IDeckLinkVideoFrameAncillary** ancillary ) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE GetTimecode( BMDTimecodeFormat format, IDeckLinkTimecode** timecode ) { return E_NOTIMPL; }
// IUnknown
virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID iid, LPVOID* ppv )
{
if ( !ppv )
return E_INVALIDARG;
if ( iid == IID_IUnknown || iid == IID_IDeckLinkVideoFrame )
{
*ppv = this;
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
virtual ULONG STDMETHODCALLTYPE AddRef() { return refCount_.fetch_add( 1 ); }
virtual ULONG STDMETHODCALLTYPE Release()
{
auto nval = refCount_.fetch_sub( 1 );
if ( nval == 0 )
{
delete this;
return 0;
}
return nval;
}
};
class DecklinkDevice;
using DecklinkDeviceVector = vector<DecklinkDevice*>;
struct DisplayMode {
long width_;
long height_;
BMDFieldDominance fields_;
BMDTimeValue frameDuration_;
BMDTimeScale timeScale_;
BMDDisplayMode value_;
DisplayMode(): width_( 0 ), height_( 0 ), fields_( bmdProgressiveFrame ),
frameDuration_( 0 ), timeScale_( 0 ), value_( BMDDisplayMode::bmdModeUnknown ) {}
DisplayMode( IDeckLinkDisplayMode* src )
{
width_ = src->GetWidth();
height_ = src->GetHeight();
value_ = src->GetDisplayMode();
fields_ = src->GetFieldDominance();
src->GetFrameRate( &frameDuration_, &timeScale_ );
}
string format()
{
float fps = ( (float)timeScale_ / (float)frameDuration_ );
char buffer[128];
sprintf_s( buffer, 128, "%ix%i%s %.2f fps", width_, height_,
fields_ == BMDFieldDominance::bmdUnknownFieldDominance ? ""
: fields_ == BMDFieldDominance::bmdLowerFieldFirst ? "i"
: fields_ == BMDFieldDominance::bmdUpperFieldFirst ? "i"
: fields_ == BMDFieldDominance::bmdProgressiveFrame ? "p"
: fields_ == BMDFieldDominance::bmdProgressiveSegmentedFrame ? "psf"
: "",
fps );
return buffer;
}
};
using DisplayModeVector = vector<DisplayMode>;
class DecklinkCapture {
friend class DecklinkDevice;
private:
DecklinkDeviceVector devices_;
DecklinkDevice* currentCaptureDevice_ = nullptr;
IDeckLinkVideoConversion* converter_ = nullptr;
RWLock lock_;
void iterateDevices();
bool convertFrame( IDeckLinkVideoFrame* source, IDeckLinkVideoFrame* destination );
public:
static const string& getVersion();
DecklinkCapture();
~DecklinkCapture();
bool initialize();
inline const DecklinkDeviceVector& getDevices() const
{
return devices_;
}
bool startCaptureSingle( DecklinkDevice* device, BMDDisplayMode displayMode );
bool getFrameBlocking( BGRA32VideoFrame** out_frame, uint32_t& out_index );
void stopCaptureSingle();
void shutdown();
};
class DecklinkDevice: public IDeckLinkInputCallback {
friend class DecklinkCapture;
private:
IDeckLink* decklink_ = nullptr;
IDeckLinkProfileAttributes* attributes_ = nullptr;
IDeckLinkConfiguration* config_ = nullptr;
IDeckLinkInput* input_ = nullptr;
bool applyDetectedMode_ = false;
RWLock lock_;
DecklinkCapture* owner_;
BGRA32VideoFrame frame_;
BGRA32VideoFrame storedFrame_;
Event newFrameEvent_;
atomic<uint32_t> frameIndex_;
uint32_t lastReturnedFrameIndex_;
bool init();
protected:
// IUnknown
virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID iid, LPVOID* ppv );
virtual ULONG STDMETHODCALLTYPE AddRef();
virtual ULONG STDMETHODCALLTYPE Release();
LONG refCount_;
// IDeckLinkDeviceNotificationCallback
virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
BMDVideoInputFormatChangedEvents notificationEvents,
IDeckLinkDisplayMode* newDisplayMode,
BMDDetectedVideoInputFormatFlags detectedSignalFlags );
virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
IDeckLinkVideoInputFrame* videoFrame,
IDeckLinkAudioInputPacket* audioPacket );
public:
string name_;
int64_t id_ = 0;
bool usable_ = false;
bool hasInput_ = false;
bool hasFormatDetection_ = false;
bool capturing_ = false;
BMDPixelFormat pixelFormat_ = bmdFormat8BitYUV;
DisplayMode displayMode_;
DisplayModeVector displayModes_;
DecklinkDevice( DecklinkCapture* owner, IDeckLink* dl );
bool startCapture( BMDDisplayMode displayMode );
bool getFrameBlocking( BGRA32VideoFrame** out_frame, uint32_t& out_index );
void stopCapture();
~DecklinkDevice();
};
}
|
frankjas/libjr
|
libjr/syscalls/jr_getpid.c
|
#include "ezport.h"
#ifdef ostype_winnt
#include <process.h>
#include "jr/syscalls.h"
jr_int jr_getpid ()
{
return _getpid ();
}
#else
#include <unistd.h>
#include "jr/syscalls.h"
jr_int jr_getpid ()
{
return getpid ();
}
#endif
|
frankjas/libjr
|
libjr/struct/net_type.c
|
#include "ezport.h"
#include "jr/nettype.h"
jr_int jr_NetIntPtrCmp (netlong1, netlong2)
const jr_NetInt *netlong1;
const jr_NetInt *netlong2;
{
return (jr_NetIntToHost (*netlong1) - jr_NetIntToHost (*netlong2));
}
jr_int jr_NetUIntPtrCmp (netlong1, netlong2)
const jr_NetUInt *netlong1;
const jr_NetUInt *netlong2;
{
return (jr_NetUIntToHost (*netlong1) - jr_NetUIntToHost (*netlong2));
}
jr_int jr_NetIntPtrCmpRev (netlong1, netlong2)
const jr_NetInt *netlong1;
const jr_NetInt *netlong2;
{
return (jr_NetIntToHost (*netlong2) - jr_NetIntToHost (*netlong1));
}
jr_int jr_NetULongPtrCmp (netlong1, netlong2)
const jr_NetULong *netlong1;
const jr_NetULong *netlong2;
{
jr_ULong long1;
jr_ULong long2;
jr_ULongAsgnNetULong (&long1, *netlong1);
jr_ULongAsgnNetULong (&long2, *netlong2);
return (jr_ULongCmp (long1, long2));
}
jr_int jr_NetLongPtrCmpRev (netlong1, netlong2)
const jr_NetLong *netlong1;
const jr_NetLong *netlong2;
{
jr_Long long1 [1];
jr_Long long2 [1];
jr_LongAsgnNetLong (long1, *netlong1);
jr_LongAsgnNetLong (long2, *netlong2);
return (jr_LongPtrCmp (long2, long1));
}
jr_int jr_NetLongPtrCmp (netlong1, netlong2)
const jr_NetLong *netlong1;
const jr_NetLong *netlong2;
{
jr_Long long1 [1];
jr_Long long2 [1];
jr_LongAsgnNetLong (long1, *netlong1);
jr_LongAsgnNetLong (long2, *netlong2);
return (jr_LongPtrCmp (long1, long2));
}
# define CreateMask(num_bits, shift_amount) \
(~ ((~(0xffffffff << (num_bits))) << (shift_amount)))
void jr_NetBitAsgn (bit_array, bit_value, bit_position, num_bits)
jr_NetUChar * bit_array;
unsigned jr_int bit_value;
jr_int bit_position;
jr_int num_bits;
{
jr_int array_index = bit_position / 8;
jr_int shift_amount;
jr_int mask;
if (num_bits >= 16) {
unsigned jr_int * value_ptr;
value_ptr = (void *) ((char *) bit_array + array_index);
shift_amount = bit_position % 32;
mask = CreateMask (num_bits, shift_amount);
*value_ptr &= mask;
*value_ptr |= bit_value << shift_amount;
}
else if (num_bits >= 8) {
unsigned jr_short * value_ptr;
value_ptr = (void *) ((char *) bit_array + array_index);
shift_amount = bit_position % 16;
mask = CreateMask (num_bits, shift_amount);
*value_ptr &= mask;
*value_ptr |= bit_value << shift_amount;
}
else {
unsigned char * value_ptr;
value_ptr = (void *) ((char *) bit_array + array_index);
shift_amount = bit_position % 8;
mask = CreateMask (num_bits, shift_amount);
*value_ptr &= mask;
*value_ptr |= bit_value << shift_amount;
}
}
#undef CreateMask
# define CreateMask(num_bits, shift_amount) \
((~(0xffffffff << (num_bits))) << (shift_amount))
unsigned jr_int jr_NetBitToHost (bit_array, bit_position, num_bits)
jr_NetUChar * bit_array;
jr_int bit_position;
jr_int num_bits;
{
jr_int array_index = bit_position / 8;
jr_int shift_amount;
jr_int value;
jr_int mask;
if (num_bits >= 16) {
unsigned jr_int * value_ptr;
value_ptr = (void *) ((char *) bit_array + array_index);
shift_amount = bit_position % 32;
mask = CreateMask (num_bits, shift_amount);
value = (*value_ptr & mask) >> shift_amount;
}
else if (num_bits >= 8) {
unsigned jr_short * value_ptr;
value_ptr = (void *) ((char *) bit_array + array_index);
shift_amount = bit_position % 16;
mask = CreateMask (num_bits, shift_amount);
value = (*value_ptr & mask) >> shift_amount;
}
else {
unsigned char * value_ptr;
value_ptr = (void *) ((char *) bit_array + array_index);
shift_amount = bit_position % 8;
mask = CreateMask (num_bits, shift_amount);
value = (*value_ptr & mask) >> shift_amount;
}
return value;
}
|
frankjas/libjr
|
libjr/syscalls/jr_tape.c
|
#include "ezport.h"
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "jr/syscalls.h"
#include "jr/error.h"
jr_int jr_IsTapeFilePtr (fp, error_buf)
FILE * fp;
char * error_buf;
{
struct stat stat_info[1];
jr_int status;
status = fstat (fileno (fp), stat_info);
if (status != 0) {
jr_esprintf (error_buf, "couldn't 'stat' file pointer: %s", strerror (errno));
return -1;
}
return S_ISCHR (stat_info->st_mode);
}
|
frankjas/libjr
|
include/jr/vector.h
|
#ifndef __jr_vector_h___
#define __jr_vector_h___
#include "ezport.h"
#include <stdio.h>
extern char * jr_getenv PROTO((
char ** string_vector,
const char * name_string
)) ;
extern char ** jr_setenv PROTO((
char ** jr_malloced_env_vector,
const char * name_string,
const char * replacement_rhs_string,
char ** old_entry_holder_for_freeing
)) ;
/******** Vectors ********/
extern void jr_VectorPrintDeclaration PROTO((
FILE * wfp,
const char ** string_vector,
const char * variable_name
)) ;
extern void jr_VectorDestroy PROTO((
const void * jr_malloced_items_and_vector
)) ;
extern void jr_VectorUndo PROTO((
const void * jr_malloced_items_vector
)) ;
extern void * jr_VectorCreateWithOneItem PROTO((
const void * zeroth_item_value
)) ;
extern void * jr_VectorCreateFromVectorAndItem PROTO((
void * source_vector,
void * source_item
)) ;
/* items are copied into new vector */
/* placed in new vector at end */
extern void * jr_VectorDup PROTO((
const void * arg,
void * (*savefunc)()
)) ;
extern jr_int jr_VectorLength PROTO((
const void * vector
)) ;
extern void jr_VectorDisplayLikeLs PROTO((
FILE * wfp,
const char ** vector_arg,
jr_int n,
jr_int screen_width
)) ;
extern jr_int jr_VectorFindMaximum PROTO((
const void * vector_arg,
jr_int n,
jr_int (*maxfunc)()
)) ;
/*
* The following may be true:
* "significant_separators" contains the characters which will
* break the line in to words,
*
* "skip_separators" will do so also, but multiple consecutive
* occurances will be skipped over (like whitespace)
*
* Leading "white_space" will be ignored.
* "quotes" will turn off the meaning of any enclosed separators.
*/
extern jr_int jr_VectorizeWithSkipSeparators PROTO((
const char * str,
const char * significant_sep,
const char * skip_sep,
char ** target_vector,
jr_int target_array_bounds
)) ;
extern const char **jr_VectorCreateWithSkipSeparators PROTO ((
const char * str,
const char * significant_sep,
const char * skip_sep
));
extern jr_int jr_VectorizeWithSkipSeparatorsInPlace PROTO((
char * modifiable_string,
const char * significant_sep,
const char * skip_sep,
char ** target_vector,
jr_int target_array_bounds
)) ;
extern jr_int jr_VectorizeIntoWords PROTO((
const char * str,
const char * sep,
char ** target_vector,
jr_int target_array_bounds
)) ;
extern jr_int jr_VectorizeIntoWordsInPlace PROTO((
char * modifiable_string,
const char * sep,
char ** target_vector,
jr_int target_array_bounds
)) ;
extern const char **jr_VectorCreateWithWords PROTO ((
const char * str,
const char * delimiters
));
extern jr_int jr_VectorizeWithQuotes PROTO ((
const char * str,
const char * delimiters,
const char * white_space,
const char * quotes,
char ** vector,
jr_int vector_size
));
extern const char **jr_VectorCreateWithQuotes PROTO ((
const char * str,
const char * delimiters,
const char * white_space,
const char * quotes
));
extern void jr_VectorConcatenate PROTO((
void * target_vector, /* target vector space had better be big enough */
void * source_vector /* items are copied into target vector */
)) ;
#define jr_VectorForEachIndex(vector, i) \
for ((i)=0; (vector)[i] != 0; (i)++)
#define jr_VectorElement(vector, i) ((vector)[i])
extern char * jr_NewStringFromDollarVectorSubstitutions PROTO((
const char * old_string,
char ** env_style_vector
)) ;
extern char ** jr_VectorReadDeclaration PROTO((
FILE * rfp,
char * variable_name,
char * errbuf
)) ;
extern const char **jr_VectorCreateFromCshLikeNameExpansion(
const char * pathname_arg,
jr_int match_slashes,
jr_int match_leading_dot);
extern const char **jr_VectorCreateFromDirectoryNameAndPattern (
const char * directory_name_string,
const char * pattern_string,
jr_int match_slashes,
jr_int match_leading_dot);
#endif
|
frankjas/libjr
|
include/jr/uuid.h
|
#ifndef __jr_uuid_h___
#define __jr_uuid_h___
#include "ezport.h"
#include "jr/misc.h"
typedef struct {
unsigned char uuid_buf [16];
} jr_UUIdStruct;
/*
* A UUID is a 128 bit quantity, or 16 bytes.
*
* Under Linux, the uuid_t type is 16 byte char array typedef.
* So the uuid_buf field above is type compatible with that definition.
*
*
* jr_malloc(): use jr_UUIdAvoidMallocLeak()
*
* The system uuid_generate() function may leave a file open (/dev/urandom).
* To account for this file, call jr_UUIdAvoidMallocLeak()
* before malloc checking is turned on.
*
*/
#define jr_UUID_STRING_LENGTH 36
#define jr_UUIdAsgn(dest_uuid, src_uuid) \
memcpy (dest_uuid, src_uuid, sizeof (jr_UUIdStruct))
extern void jr_UUIdAsgnRandom PROTO ((
jr_UUIdStruct * uuid_info
));
extern void jr_UUIdAsgnTime PROTO ((
jr_UUIdStruct * uuid_info
));
extern void jr_UUIdAsgnFromString PROTO ((
jr_UUIdStruct * uuid_info,
const char * string_buf
));
extern char * jr_UUIdToString PROTO ((
const jr_UUIdStruct * uuid_info,
char * string_buf
));
extern jr_int jr_UUIdCmp PROTO ((
const void * void_ptr_1,
const void * void_ptr_2
));
extern jr_int jr_UUIdHash PROTO ((
const void * void_ptr_1
));
extern void jr_UUIdAvoidMallocLeak PROTO ((void));
#define jr_UUIdAsgnNull(dest_uuid) \
memset (dest_uuid, 0, sizeof (jr_UUIdStruct))
#define jr_UUIdIsNull(dest_uuid) \
jr_memisset (dest_uuid, 0, sizeof (jr_UUIdStruct))
#endif
|
frankjas/libjr
|
libjr/string/envpathx.c
|
<filename>libjr/string/envpathx.c<gh_stars>0
#include "ezport.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jr/string.h"
#include "jr/vector.h"
#include "jr/malloc.h"
char **jr_extendpath(environ_arg, pathname)
char ** environ_arg ;
const char * pathname ;
{
const char * new_dir = pathname ;
char * old_path = (char *) getenv("PATH") ;
char * former_entry ;
if (! old_path) {
environ_arg = jr_setenv(environ_arg, "PATH", pathname, &former_entry) ;
if (former_entry) jr_free(former_entry) ;
}
else {
char new_path[2048] ;
char do_colon[4] ;
jr_int pos ;
if ((pos = jr_SubStringIndex(old_path, pathname)) >= 0) {
char *entry = old_path + pos ;
jr_int len = (jr_int) strlen(pathname) ;
if ((entry[len] == 0) || (entry[len] == ':')) {
return(environ_arg) ;
}
}
do_colon[0] = (*old_path == ':') ? 0 : ':' ;
do_colon[1] = 0 ;
sprintf(new_path, "%s%s%s", new_dir, do_colon, old_path) ;
environ_arg = jr_setenv(environ_arg, "PATH", new_path, &former_entry) ;
if (former_entry) free(former_entry) ;
}
return(environ_arg) ;
}
/* test program is testenv.c */
|
frankjas/libjr
|
libjr/misc/cmpshort.c
|
#include "ezport.h"
#include "jr/misc.h"
jr_int shortcmp(n,m)
short n, m ;
{
return((n)-(m)) ;
}
jr_int shortpcmp(np,mp)
short *np, *mp ;
{
return((*np)-(*mp)) ;
}
jr_int rshortcmp(n,m)
short n, m ;
{
return((m)-(n)) ;
}
jr_int rshortpcmp(np,mp)
short *np, *mp ;
{
return((*mp)-(*np)) ;
}
jr_int jr_ushort_add_max (
unsigned jr_short * ushort_ref,
jr_int addend)
{
if (addend >= 0) {
if (addend >= jr_USHRT_MAX) {
addend = jr_USHRT_MAX;
}
if (*ushort_ref + addend <= jr_USHRT_MAX) {
*ushort_ref = (unsigned jr_short) (*ushort_ref + addend);
}
else {
*ushort_ref = jr_USHRT_MAX;
}
}
else {
if (*ushort_ref + addend < 0) {
*ushort_ref = 0;
}
else {
*ushort_ref = (unsigned jr_short) (*ushort_ref + addend);
}
}
return *ushort_ref;
}
|
frankjas/libjr
|
libjr/syscalls/jr_symlink.c
|
#include "ezport.h"
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "jr/syscalls.h"
#include "jr/error.h"
jr_int jr_SymLink (
const char * link_target_path,
const char * new_link_path,
char * error_buf)
{
jr_int status;
status = symlink (link_target_path, new_link_path);
if (status != 0) {
jr_esprintf (error_buf, "%s", strerror (errno));
status = jr_ConvertErrno (errno);
goto return_status;
}
status = 0;
return_status : {
}
return status;
}
jr_int jr_ReadLink (
const char * link_path,
char * link_target_buf,
jr_int buf_length,
char * error_buf)
{
jr_int status;
status = readlink (link_path, link_target_buf, buf_length);
if (status < 0) {
jr_esprintf (error_buf, "%s", strerror (errno));
status = jr_ConvertErrno (errno);
goto return_status;
}
else if (status == buf_length) {
jr_esprintf (error_buf, "buffer too small");
status = jr_NO_ROOM_ERROR;
goto return_status;
}
/*
** 5/18/08: readlink() doesn't add null byte to buffer.
*/
link_target_buf[status] = 0;
status = 0;
return_status : {
}
return status;
}
|
frankjas/libjr
|
include/jr/inputbuf.h
|
#ifndef _input_bufferh
#define _input_bufferh
#include "ezport.h"
#include <stdio.h>
#include "jr/alist.h"
#include "jr/htable.h"
typedef struct {
jr_AList context_stack [1];
jr_HTable context_names [1];
jr_int eof_line_number;
jr_int eof_column_number;
jr_int eof_byte_offset;
jr_int tab_stops;
} jr_IB_InputBuffer;
typedef struct {
jr_AList unread_chars [1];
jr_int context_type;
char * context_name;
FILE * src_rfp;
char * src_string;
jr_int string_index;
jr_int line_number;
jr_int column_number;
jr_int byte_offset;
jr_int flags;
jr_int tab_stops;
jr_int last_num_columns;
unsigned is_inherited : 1;
unsigned do_fclose_or_free : 1;
unsigned transparent_close : 1;
unsigned saw_new_line : 1;
} jr_IB_ContextType;
extern jr_int jr_IB_NumCharReadCalls;
extern jr_int jr_IB_NumCharsRead;
extern jr_int jr_IB_NumCharsFromString;
extern jr_int jr_IB_NumCharsUnRead;
#define jr_IB_FILE_CONTEXT 1
#define jr_IB_STRING_CONTEXT 2
extern jr_IB_InputBuffer *jr_IB_InputBufferCreate PROTO ((void));
extern void jr_IB_InputBufferInit PROTO ((
jr_IB_InputBuffer * input_buffer
));
extern void jr_IB_InputBufferDestroy PROTO ((
jr_IB_InputBuffer * input_buffer
));
extern void jr_IB_InputBufferUndo PROTO ((
jr_IB_InputBuffer * input_buffer
));
extern void jr_IB_InputBufferReset PROTO ((
jr_IB_InputBuffer * input_buffer
));
extern jr_int jr_IB_getc PROTO ((
jr_IB_InputBuffer * input_buffer
));
extern void jr_IB_ungetc PROTO ((
jr_IB_InputBuffer * input_buffer,
jr_int c
));
#define jr_IB_ExtendedChar(input_buffer) \
((input_buffer)->extended_char)
extern char * jr_IB_gets PROTO ((
jr_IB_InputBuffer * input_buffer,
char * string_buf,
jr_int max_length
));
extern void jr_IB_ungetstring PROTO ((
jr_IB_InputBuffer * input_buffer,
char * string
));
extern char * jr_IB_getword PROTO ((
jr_IB_InputBuffer * input_buffer,
char * string_buf,
jr_int max_length
));
#define jr_IB_DONT_FCLOSE_RFP 0
#define jr_IB_FCLOSE_RFP 1
#define jr_IB_DONT_FREE_STR 0
#define jr_IB_FREE_STR 1
#define jr_IB_DONT_SAVE_NAME 0
#define jr_IB_SAVE_NAME 1
extern void jr_IB_OpenContext PROTO ((
jr_IB_InputBuffer * input_buffer,
jr_int context_type,
const char * context_name,
jr_int do_save_name,
void * context_ptr,
jr_int do_fclose_or_free,
jr_int transparent_close
));
#define jr_IB_OpenFileContext(ib, name, do_save_name, rfp, do_fclose) \
jr_IB_OpenContext (ib, jr_IB_FILE_CONTEXT, name, do_save_name, rfp, do_fclose, 1)
#define jr_IB_OpenStringContext(ib, name, do_save_name, str, do_free) \
jr_IB_OpenContext (ib, jr_IB_STRING_CONTEXT, name, do_save_name, (char *) str, do_free, 1)
/*
* the switch functions will cause EOF to be read, the user has to
* close the context to pop back to the previous context
*/
#define jr_IB_SwitchContextToFile(ib, name, do_save_name, rfp, do_fclose) \
jr_IB_OpenContext (ib, jr_IB_FILE_CONTEXT, name, do_save_name, rfp, do_fclose, 0)
#define jr_IB_SwitchContextToString(ib, name, do_save_name, str, do_free) \
jr_IB_OpenContext (ib, jr_IB_STRING_CONTEXT, name, do_save_name, str, do_free, 0)
extern jr_int jr_IB_CloseCurrentContext PROTO ((
jr_IB_InputBuffer * input_buffer
));
extern void jr_IB_UndoContext PROTO ((
jr_IB_ContextType * input_context
));
extern char * jr_IB_ContextDescription PROTO ((
jr_IB_InputBuffer * input_buffer,
char * string,
jr_int max_size
));
extern void jr_IB_SetCurrentContextName PROTO ((
jr_IB_InputBuffer * input_buffer,
char * string,
jr_int save_name
));
/*
* The EOF info of the last open context
*/
#define jr_IB_EofLine(ib) ((ib)->eof_line_number)
#define jr_IB_EofColumn(ib) ((ib)->eof_column_number)
#define jr_IB_EofOffset(ib) ((ib)->eof_byte_offset)
#define jr_IB_CurrentContext(ib) \
((jr_IB_ContextType *) jr_AListTailPtr((ib)->context_stack))
#define jr_IB_CurrentContextName(ib) \
(jr_IB_CurrentContext (ib)->context_name)
#define jr_IB_CurrentContextLine(ib) \
(jr_IB_CurrentContext (ib)->line_number)
#define jr_IB_CurrentContextColumn(ib) \
(jr_IB_CurrentContext (ib)->column_number)
#define jr_IB_CurrentContextOffset(ib) \
(jr_IB_CurrentContext (ib)->byte_offset)
#define jr_IB_CurrentContextFlags(ib) \
(jr_IB_CurrentContext (ib)->flags)
#define jr_IB_CurrentContextRfp(ib) \
(jr_IB_CurrentContext (ib)->src_rfp)
#define jr_IB_CurrentContextString(ib) \
(jr_IB_CurrentContext (ib)->src_string)
#define jr_IB_SetCurrentContextLine(ib, line) \
(jr_IB_CurrentContext (ib)->line_number = (line))
#define jr_IB_SetCurrentContextColumn(ib, column) \
(jr_IB_CurrentContext (ib)->column_number = (column))
#define jr_IB_SetCurrentContextFlags(ib, line) \
(jr_IB_CurrentContext (ib)->flags = (line))
#define jr_IB_IsNestedContext(ib) \
(jr_AListSize ((ib)->context_stack) > 1)
#define jr_IB_HasContext(ib) \
(jr_AListSize ((ib)->context_stack) > 0)
#define jr_IB_ContextDepth(ib) \
jr_AListSize ((ib)->context_stack)
#define jr_IB_ContextPtr(ib, i) \
((jr_IB_ContextType *) jr_AListElementPtr ((ib)->context_stack, i))
#define jr_IB_ContextName(ib, i) \
(jr_IB_ContextPtr (ib, i)->context_name)
#define jr_IB_ContextLine(ib, i) \
(jr_IB_ContextPtr (ib, i)->line_number)
#define jr_IB_ContextColumn(ib, i) \
(jr_IB_ContextPtr (ib, i)->column_number)
#define jr_IB_ContextOffset(ib, i) \
(jr_IB_ContextPtr (ib, i)->byte_offset)
#define jr_IB_ContextRfp(ib, i) \
(jr_IB_ContextPtr (ib, i)->context_type == jr_IB_FILE_CONTEXT) ? \
jr_IB_ContextPtr (ib, i)->src_rfp : 0 \
)
#define jr_IB_ContextStr(ib, i) \
(jr_IB_ContextPtr (ib, i)->context_type == IB_STR_CONTEXT) ? \
jr_IB_ContextPtr (ib, i)->src_string : 0 \
)
#define jr_IB_ForEachContextIndex(ib, i) \
jr_AListForEachElementIndexRev ((ib)->context_stack, i)
#endif
|
frankjas/libjr
|
libjr/misc/bktrace.c
|
#include "ezport.h"
#include "jr/misc.h"
#ifndef missing_execinfo_h
#include <execinfo.h>
jr_int jr_backtrace (pc_array, pc_array_size)
void ** pc_array;
jr_int pc_array_size;
{
jr_int trace_size;
jr_int q;
trace_size = backtrace (pc_array, pc_array_size);
for (q=0; q < trace_size-1; q++) {
pc_array[q] = pc_array[q+1];
}
return trace_size - 1;
}
#else
jr_int jr_backtrace (pc_array, pc_array_size)
void ** pc_array;
jr_int pc_array_size;
{
return 0;
}
#endif
|
frankjas/libjr
|
libjr/misc/jr_rand.c
|
#include "ezport.h"
#include <apr-1/apr_general.h>
#include "jr/misc.h"
#include "jr/apr.h"
#include "jr/error.h"
jr_int jr_random_bytes (
void * bytes_ptr,
jr_int bytes_length,
char * opt_error_buf)
{
jr_int status;
jr_apr_initialize();
status = apr_generate_random_bytes (bytes_ptr, bytes_length);
if (status != 0) {
if (opt_error_buf) {
jr_esprintf (opt_error_buf, "%s", apr_strerror (status, opt_error_buf, jr_ERROR_LEN));
}
status = jr_ConvertAprErrno (status);
goto return_status;
}
status = 0;
return_status : {
}
return status;
}
|
frankjas/libjr
|
libjr/io/jr_fgets.c
|
#include "ezport.h"
#include <string.h>
#include "jr/io.h"
#include "jr/malloc.h"
jr_int jr_GetWholeLine (line_buf_ref, line_buf_size_ref, rfp)
char ** line_buf_ref;
jr_int * line_buf_size_ref;
FILE * rfp;
{
char * line_buf = *line_buf_ref;
jr_int line_buf_size = *line_buf_size_ref;
jr_int data_length;
if (line_buf_size < 2) {
return 0;
}
line_buf[line_buf_size - 2] = '\n';
/*
** 8/17/06: this is where the newline should be if the whole line is read.
** If it's not a '\n', then it was overwritten the end of a partial line.
*/
if (fgets (line_buf, line_buf_size, rfp) == NULL) {
return -1;
}
while (line_buf[line_buf_size - 2] != '\n') {
data_length = line_buf_size - 1;
line_buf_size *= 2;
line_buf = jr_realloc (line_buf, line_buf_size);
line_buf[line_buf_size - 2] = '\n';
/*
** 8/17/06: this is where the newline should be if the whole line is read.
** If it's not a '\n', then it was overwritten the end of a partial line.
*/
if (fgets (line_buf + data_length, line_buf_size - data_length, rfp) == NULL) {
break;
}
}
*line_buf_ref = line_buf;
*line_buf_size_ref = line_buf_size;
return 0;
}
|
frankjas/libjr
|
libjr/io/http_lib.c
|
<reponame>frankjas/libjr
#define _POSIX_SOURCE
#include "jr/io.h"
char *jr_HTTP_StatusString (http_status)
jr_int http_status;
{
switch (http_status) {
case jr_HTTP_CONTINUE_STATUS : return "Continue";
case jr_HTTP_SUCCESS_STATUS : return "Success";
case jr_HTTP_CREATED_STATUS : return "Created";
case jr_HTTP_ACCEPTED_STATUS : return "Accepted";
case jr_HTTP_NO_CONTENT_STATUS : return "No Content";
case jr_HTTP_MOVED_PERMANENTLY_STATUS : return "Moved Permanently";
case jr_HTTP_FOUND_STATUS : return "Found";
case jr_HTTP_NOT_MODIFIED_STATUS : return "Not Modified";
case jr_HTTP_BAD_REQUEST_STATUS : return "Bad Request";
case jr_HTTP_UNAUTHORIZED_STATUS : return "Unauthorized";
case jr_HTTP_FORBIDDEN_STATUS : return "Forbidden";
case jr_HTTP_NOT_FOUND_STATUS : return "Not Found";
case jr_HTTP_URI_TOO_LONG_STATUS : return "URI Too Long";
case jr_HTTP_SERVER_ERROR_STATUS : return "Internal Server Error";
case jr_HTTP_NOT_IMPLEMENTED_STATUS : return "Not Implemented";
case jr_HTTP_BAD_GATEWAY_STATUS : return "Bad Gateway";
case jr_HTTP_SERVICE_UNAVAILABLE_STATUS : return "Service Unavailable";
}
return "Unknown Status";
}
jr_int jr_ConvertHttpError(
jr_int http_status)
{
switch (http_status) {
case jr_HTTP_CONTINUE_STATUS : return 0;
case jr_HTTP_SUCCESS_STATUS : return 0;
case jr_HTTP_CREATED_STATUS : return 0;
case jr_HTTP_ACCEPTED_STATUS : return 0;
case jr_HTTP_NO_CONTENT_STATUS : return 0;
case jr_HTTP_MOVED_PERMANENTLY_STATUS : return 0;
case jr_HTTP_FOUND_STATUS : return 0;
case jr_HTTP_NOT_MODIFIED_STATUS : return 0;
case jr_HTTP_BAD_REQUEST_STATUS : return jr_MISUSE_ERROR;
case jr_HTTP_UNAUTHORIZED_STATUS : return jr_PERMISSION_ERROR;
case jr_HTTP_FORBIDDEN_STATUS : return jr_PERMISSION_ERROR;
case jr_HTTP_NOT_FOUND_STATUS : return jr_NOT_FOUND_ERROR;
case jr_HTTP_URI_TOO_LONG_STATUS : return jr_MISUSE_ERROR;
case jr_HTTP_SERVER_ERROR_STATUS : return jr_INTERNAL_ERROR;
case jr_HTTP_NOT_IMPLEMENTED_STATUS : return jr_NOT_IMPLEMENTED_ERROR;
case jr_HTTP_BAD_GATEWAY_STATUS : return jr_INTERNAL_ERROR;
case jr_HTTP_SERVICE_UNAVAILABLE_STATUS : return jr_INTERNAL_ERROR;
}
return jr_INTERNAL_ERROR;
}
#if 0
/*
** 5-3-2013: obsoleted by jr_ConvertHttpError() which doesn't depend on jr/http/lib.h
*/
jr_int jr_InetConvertHttpError(
jr_int http_status)
{
switch (http_status) {
case jr_HTTP_CONTINUE_STATUS : return 0;
case jr_HTTP_SUCCESS_STATUS : return 0;
case jr_HTTP_CREATED_STATUS : return 0;
case jr_HTTP_ACCEPTED_STATUS : return 0;
case jr_HTTP_NO_CONTENT_STATUS : return 0;
case jr_HTTP_MOVED_PERMANENTLY_STATUS : return 0;
case jr_HTTP_FOUND_STATUS : return 0;
case jr_HTTP_NOT_MODIFIED_STATUS : return 0;
case jr_HTTP_BAD_REQUEST_STATUS : return jr_HTTP_BAD_REQUEST_ERROR;
case jr_HTTP_UNAUTHORIZED_STATUS : return jr_PERMISSION_ERROR;
case jr_HTTP_FORBIDDEN_STATUS : return jr_INTERNAL_ERROR;
case jr_HTTP_NOT_FOUND_STATUS : return jr_NOT_FOUND_ERROR;
case jr_HTTP_URI_TOO_LONG_STATUS : return jr_HTTP_INPUT_TOO_LONG_ERROR;
case jr_HTTP_SERVER_ERROR_STATUS : return jr_INTERNAL_ERROR;
case jr_HTTP_NOT_IMPLEMENTED_STATUS : return jr_NOT_IMPLEMENTED_ERROR;
case jr_HTTP_BAD_GATEWAY_STATUS : return jr_INTERNAL_ERROR;
case jr_HTTP_SERVICE_UNAVAILABLE_STATUS : return jr_HTTP_CONNECTION_REFUSED;
}
return jr_INTERNAL_ERROR;
}
#endif
|
frankjas/libjr
|
include/jr/xdr.h
|
<gh_stars>0
#ifndef _jr_xdr_h___
#define _jr_xdr_h___
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
/*
* xdr.h, External Data Representation Serialization Routines.
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*/
/*
** 1/25/07 Copied from rpc/types.h and rpc/xdr.h
** modified to use JR types for portability
** bool_t -> jr_int
** u_int -> unsigned jr_int
*/
#ifndef __THROW
/*
** 1/25/07: Missing under Microsoft, a define under GNU
*/
# define __THROW
#endif
/*
* Xdr operations. XDR_ENCODE causes the type to be encoded into the
* stream. XDR_DECODE causes the type to be extracted from the stream.
* XDR_FREE can be used to release the space allocated by an XDR_DECODE
* request.
*/
enum xdr_op {
XDR_ENCODE = 0,
XDR_DECODE = 1,
XDR_FREE = 2
};
/*
* The XDR handle.
* Contains operation which is being applied to the stream,
* an operations vector for the particular implementation (e.g. see xdr_mem.c),
* and two private fields for the use of the particular implementation.
*/
typedef struct XDR XDR;
struct XDR {
enum xdr_op x_op; /* operation; fast additional param */
struct xdr_ops {
jr_int (*x_getlong) (XDR *__xdrs, long *__lp);
/* get a long from underlying stream */
jr_int (*x_putlong) (XDR *__xdrs, const long *__lp);
/* put a long to " */
jr_int (*x_getbytes) (XDR *__xdrs, caddr_t __addr, unsigned int __len);
/* get some bytes from " */
jr_int (*x_putbytes) (XDR *__xdrs, const char *__addr, unsigned jr_int __len);
/* put some bytes to " */
unsigned jr_int (*x_getpostn) (const XDR *__xdrs);
/* returns bytes off from beginning */
jr_int (*x_setpostn) (XDR *__xdrs, unsigned jr_int __pos);
/* lets you reposition the stream */
jr_int *(*x_inline) (XDR *__xdrs, unsigned jr_int __len);
/* buf quick ptr to buffered data */
void (*x_destroy) (XDR *__xdrs);
/* free privates of this xdr_stream */
jr_int (*x_getint32) (XDR *__xdrs, jr_int *__ip);
/* get a int from underlying stream */
jr_int (*x_putint32) (XDR *__xdrs, const jr_int *__ip);
/* put a int to " */
}
*x_ops;
caddr_t x_public; /* users' data */
caddr_t x_private; /* pointer to private data */
caddr_t x_base; /* private used for position info */
unsigned jr_int x_handy; /* extra private word */
};
/* XDR using memory buffers */
extern void xdrmem_create (
XDR * __xdrs,
const caddr_t __addr,
unsigned jr_int __size,
enum xdr_op __xop
) __THROW;
extern jr_int xdr_float (
XDR * __xdrs,
float * __fp
) __THROW;
extern jr_int xdr_double (
XDR * __xdrs,
double * __dp
) __THROW;
#define xdr_setpos(xdrs, pos) \
(*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
#define XDR_GETLONG(xdrs, longp) \
(*(xdrs)->x_ops->x_getlong)(xdrs, longp)
#define XDR_PUTLONG(xdrs, longp) \
(*(xdrs)->x_ops->x_putlong)(xdrs, longp)
#endif
|
frankjas/libjr
|
libjr/syscalls/jr_apr.h
|
<filename>libjr/syscalls/jr_apr.h
#ifndef ___apr_h__
#define ___apr_h__
#include "ezport.h"
#include <apr-1/apr_general.h>
#include <apr-1/apr_pools.h>
#include <apr-1/apr_errno.h>
#include <apr-1/apr_file_io.h>
#include "jr/apr.h"
#include "jr/syscalls.h"
#include "jr/malloc.h"
#include "jr/error.h"
#include "jr/trace.h"
extern void jr_stat_asgn_apr_finfo (
struct jr_stat * jr_stat_ptr,
const apr_finfo_t * apr_finfo_ptr);
extern jr_int jr_stat_prepare_return (
struct jr_stat * opt_jr_stat_ptr,
jr_int flags,
const char ** opt_user_name_ref,
const char ** opt_group_name_ref,
apr_finfo_t * apr_finfo,
apr_pool_t * apr_pool_ptr,
char * error_buf);
#endif
|
frankjas/libjr
|
libjr/string/memrepl.c
|
<filename>libjr/string/memrepl.c
#include "ezport.h"
#include <string.h>
#include "jr/string.h"
#include "jr/trace.h"
#include "jr/malloc.h"
jr_int jr_CountSubByteMatches(source_buf_arg, source_len, pattern_arg, patlen)
const void * source_buf_arg ;
jr_int source_len ;
const void * pattern_arg ;
jr_int patlen ;
{
char * source_buf = (char *) source_buf_arg ;
char * pattern = (char *) pattern_arg ;
jr_int number_of_matches ;
jr_int i ;
if ((source_len == 0) && (patlen == 0)) return(1) ;
if (source_len == 0) return(0) ;
if (patlen == 0) return(source_len) ;
number_of_matches = 0 ;
for (i = 0 ; i <= (source_len - patlen); i++) {
if (memcmp(source_buf+i, pattern, patlen) == 0) {
number_of_matches++ ;
i += patlen ;
}
}
return(number_of_matches) ;
}
void * jr_ReplaceSubByteMatches(source_buf_arg, source_len, old_pattern_arg, old_pattern_len, new_pattern_arg, new_pattern_len)
const void * source_buf_arg ;
jr_int source_len ;
const void * old_pattern_arg ;
jr_int old_pattern_len ;
const void * new_pattern_arg ;
jr_int new_pattern_len ;
{
char * source_buf = (char *) source_buf_arg ;
char * old_pattern = (char *) old_pattern_arg ;
char * new_pattern = (char *) new_pattern_arg ;
char * target_buf ;
jr_int target_len ;
jr_int additional_bytes_needed ;
jr_int number_of_occurences ;
jr_int source_index ;
jr_int target_index ;
number_of_occurences = jr_CountSubByteMatches(source_buf,source_len,old_pattern,old_pattern_len) ;
additional_bytes_needed = number_of_occurences * (new_pattern_len - old_pattern_len) ;
target_len = source_len + additional_bytes_needed ;
target_buf = (char *) jr_malloc((target_len + 1) * sizeof(char)) ;
if (target_buf == 0) {
return(0) ;
}
target_buf[target_len] = 0 ;
target_index = 0 ; source_index = 0 ;
while (source_index <= (source_len - old_pattern_len)) {
if (memcmp(source_buf+source_index, old_pattern, old_pattern_len) == 0) {
/*
* memmove take care of overlapping copies
*/
memmove(target_buf+target_index, new_pattern, new_pattern_len) ;
target_index += new_pattern_len ;
if (old_pattern_len == 0) {
target_buf[target_index] = source_buf[source_index] ;
target_index++ ;
source_index++ ;
if (source_index == source_len) {
break ;
}
}
else {
source_index += old_pattern_len ;
}
}
else {
target_buf[target_index] = source_buf[source_index] ;
target_index++ ;
source_index++ ;
}
}
while (source_index < source_len) {
target_buf[target_index] = source_buf[source_index] ;
target_index++ ;
source_index++ ;
}
return(target_buf) ;
}
char * jr_ReplaceSubStringGlobally(source_buf_arg, old_pattern_arg, new_pattern_arg)
const char * source_buf_arg ;
const char * old_pattern_arg ;
const char * new_pattern_arg ;
{
return
jr_ReplaceSubByteMatches(
source_buf_arg,
(jr_int) strlen(source_buf_arg),
old_pattern_arg,
(jr_int) strlen(old_pattern_arg),
new_pattern_arg,
(jr_int) strlen(new_pattern_arg)
) ;
}
/*
main()
{
char s1[50] ;
char s2[50] ;
char s3[50] ;
char *new ;
jr_set_trace(jr_malloc_stats) ;
jr_set_trace(jr_malloc_calls) ;
while (1) {
printf("Enter the long string in which replacements will be made: ") ;
if (! gets(s1)) exit(0) ;
printf("Enter the pattern: ") ;
if (! gets(s2)) exit(0) ;
printf("Enter the new: ") ;
if (! gets(s3)) exit(0) ;
printf("position of '%s' in '%s' is %d\n",s2,s1, strstr(s1,s2) - s1) ;
if (new = jr_ReplaceSubByteMatches(s1,strlen(s1),s2,strlen(s2),s3,strlen(s3))) {
printf("New string '%s'\n",new) ;
}
else {
perror("jr_ReplaceSubStringGlobally failed ") ;
}
jr_free(new) ;
}
jr_malloc_stats(stdout, "After loop") ;
}
*/
|
frankjas/libjr
|
include/jr/ansi_c/exprnode.h
|
#ifndef __c_expr_node_h__
#define __c_expr_node_h__
#include "ezport.h"
typedef struct c_expr_node {
jr_int node_type;
struct c_expr_node * children [3];
char * identifier_name; /* used for identifiers only, see below */
jr_int value_type;
void (*alloc_fn)(
jr_int op_type,
struct c_expr_node * c_expr_node,
struct c_expr_node * opt_c_expr_node
);
union {
jr_int ival;
unsigned jr_int uval;
double dval;
char * sval;
void * pval;
} c_expr_value;
} jr_C_ExprNodeType;
#define c_expr_ival c_expr_value.ival
#define c_expr_uval c_expr_value.uval
#define c_expr_fval c_expr_value.dval
#define c_expr_dval c_expr_value.dval
#define c_expr_sval c_expr_value.sval
#define c_expr_pval c_expr_value.pval
/******** C Expression Nodes ********/
extern jr_C_ExprNodeType * jr_C_ExprNodeCreate PROTO ((
jr_int node_type,
jr_C_ExprNodeType * child0,
jr_C_ExprNodeType * child1,
jr_C_ExprNodeType * child2
));
extern void jr_C_ExprNodeDestroy PROTO ((
jr_C_ExprNodeType * c_expr_node
));
extern jr_C_ExprNodeType * jr_C_ExprNodeListCreate PROTO ((
jr_int node_type,
jr_C_ExprNodeType * child0,
jr_C_ExprNodeType * child1,
jr_C_ExprNodeType * child2
));
extern jr_C_ExprNodeType * jr_C_ExprNodeListCreateWithNode PROTO((
jr_C_ExprNodeType * c_expr_node
));
extern void jr_C_ExprNodeListAppendNew PROTO ((
jr_C_ExprNodeType * list_node,
jr_int node_type,
jr_C_ExprNodeType * child0,
jr_C_ExprNodeType * child1,
jr_C_ExprNodeType * child2
));
extern void jr_C_ExprNodeListAppendNode PROTO ((
jr_C_ExprNodeType * list_node,
jr_C_ExprNodeType * new_list_node
));
extern void jr_C_ExprNodeListAppendList PROTO ((
jr_C_ExprNodeType * list_node,
jr_C_ExprNodeType * other_list_node
));
extern jr_int jr_C_ExprNodeTraverse PROTO ((
jr_C_ExprNodeType * curr_node,
jr_int (*pre_order_fn) (),
jr_int (*in_order_fn) (),
jr_int (*post_order_fn) (),
void * data_ptr,
char * opt_error_buf
));
extern jr_int jr_C_ExprNodeTraversalDestroy PROTO ((
jr_C_ExprNodeType * c_expr_node
));
extern void jr_C_ExprNodeInitCopy PROTO ((
jr_C_ExprNodeType * new_node,
jr_C_ExprNodeType * c_expr_node
));
extern jr_C_ExprNodeType * jr_C_ExprNodeCreateCopy PROTO ((
jr_C_ExprNodeType * c_expr_node
));
extern jr_int jr_C_ExprNodeToString PROTO ((
char * dest_buf,
jr_int buf_length,
jr_C_ExprNodeType * c_expr_node,
char * error_buf
));
extern jr_int jr_C_ExprNodeEvaluate PROTO ((
jr_C_ExprNodeType * c_expr_node,
void * opt_c_expr,
jr_int (*identifier_fn) (),
jr_int (*function_call_fn) (),
jr_int (*sizeof_fn) (),
void * data_ptr,
char * opt_error_buf
));
/******** Expression Node Macros ********/
#define jr_C_EXPR_NODE_LIST_TYPE -1
#define jr_C_EXPR_VOID_VALUE 0
#define jr_C_EXPR_INT_VALUE 1
#define jr_C_EXPR_UNSIGNED_VALUE 2
#define jr_C_EXPR_FLOAT_VALUE 3
#define jr_C_EXPR_DOUBLE_VALUE 4
#define jr_C_EXPR_STRING_VALUE 5
#define jr_C_EXPR_PTR_VALUE 6
#define jr_C_ExprNodeTypeNumber(c_expr_node) ((c_expr_node)->node_type)
#define jr_C_ExprNodeValueTypeNumber(c_expr_node) ((c_expr_node)->value_type)
#define jr_C_ExprNodeChildPtr(c_expr_node, i) ((c_expr_node)->children[i])
#define jr_C_ExprNodeAllocFn(c_expr_node) ((c_expr_node)->alloc_fn)
#define jr_C_ExprNodeSetAllocFn(c_expr_node, fn) ((c_expr_node)->alloc_fn = (fn))
#define jr_C_ExprNodeCallAllocFn(c_expr_node, op_type, c_expr_node_1, c_expr_node_2) \
((c_expr_node)->alloc_fn( op_type, c_expr_node_1, c_expr_node_2))
#define jr_C_ExprNodeLeftChildPtr(c_expr_node) jr_C_ExprNodeChildPtr(c_expr_node, 0)
#define jr_C_ExprNodeRightChildPtr(c_expr_node) jr_C_ExprNodeChildPtr(c_expr_node, 1)
#define jr_C_ExprNodeExtraChildPtr(c_expr_node) jr_C_ExprNodeChildPtr(c_expr_node, 2)
#define jr_C_ExprNodeLastChildPtr(c_expr_node) jr_C_ExprNodeChildPtr(c_expr_node, 3)
#define jr_C_ExprNodeSetLeftChild( c_expr_node, child_node_ptr) \
(jr_C_ExprNodeLeftChildPtr( c_expr_node) = (child_node_ptr))
#define jr_C_ExprNodeSetRightChild( c_expr_node, child_node_ptr) \
(jr_C_ExprNodeRightChildPtr( c_expr_node) = (child_node_ptr))
#define jr_C_ExprNodeSetExtraChild( c_expr_node, child_node_ptr) \
(jr_C_ExprNodeExtraChildPtr( c_expr_node) = (child_node_ptr))
#define jr_C_ExprNodeSetLastChild( c_expr_node, child_node_ptr) \
(jr_C_ExprNodeLastChildPtr( c_expr_node) = (child_node_ptr))
#define jr_C_ExprNodeCopyValue(dest, src) \
((dest)->value_type = (src)->value_type, (dest)->c_expr_dval = (src)->c_expr_dval)
#define jr_C_ExprNodeSetIntValue(c_expr_node, v) \
((c_expr_node)->value_type = jr_C_EXPR_INT_VALUE, (c_expr_node)->c_expr_ival = (v))
#define jr_C_ExprNodeSetUnsignedValue(c_expr_node, v) \
((c_expr_node)->value_type = jr_C_EXPR_UNSIGNED_VALUE, (c_expr_node)->c_expr_ival = (v))
#define jr_C_ExprNodeSetFloatValue(c_expr_node, v) \
((c_expr_node)->value_type = jr_C_EXPR_FLOAT_VALUE, (c_expr_node)->c_expr_dval = (v))
#define jr_C_ExprNodeSetDoubleValue(c_expr_node, v) \
((c_expr_node)->value_type = jr_C_EXPR_DOUBLE_VALUE, (c_expr_node)->c_expr_dval = (v))
#define jr_C_ExprNodeSetStringValue(c_expr_node, v) \
((c_expr_node)->value_type = jr_C_EXPR_STRING_VALUE, (c_expr_node)->c_expr_sval = (v))
#define jr_C_ExprNodeSetPtrValue(c_expr_node, v) \
((c_expr_node)->value_type = jr_C_EXPR_PTR_VALUE, (c_expr_node)->c_expr_pval = (v))
#define jr_C_ExprNodeSetVoidValue(c_expr_node) \
((c_expr_node)->value_type = jr_C_EXPR_VOID_VALUE, (c_expr_node)->c_expr_dval = (0.0))
#define jr_C_ExprNodeIntValue(c_expr_node) ((c_expr_node)->c_expr_ival)
#define jr_C_ExprNodeUnsignedValue(c_expr_node) ((c_expr_node)->c_expr_uval)
#define jr_C_ExprNodeFloatValue(c_expr_node) ((c_expr_node)->c_expr_dval)
#define jr_C_ExprNodeDoubleValue(c_expr_node) ((c_expr_node)->c_expr_dval)
#define jr_C_ExprNodeStringValue(c_expr_node) ((c_expr_node)->c_expr_sval)
#define jr_C_ExprNodePtrValue(c_expr_node) ((c_expr_node)->c_expr_pval)
#define jr_C_ExprNodeIsVoidValue(c_expr_node) \
((c_expr_node)->value_type == jr_C_EXPR_VOID_VALUE)
#define jr_C_ExprNodeIsIntValue(c_expr_node) \
((c_expr_node)->value_type == jr_C_EXPR_INT_VALUE)
#define jr_C_ExprNodeIsUnsignedValue(c_expr_node) \
((c_expr_node)->value_type == jr_C_EXPR_UNSIGNED_VALUE)
#define jr_C_ExprNodeIsFloatValue(c_expr_node) \
((c_expr_node)->value_type == jr_C_EXPR_FLOAT_VALUE)
#define jr_C_ExprNodeIsDoubleValue(c_expr_node) \
((c_expr_node)->value_type == jr_C_EXPR_DOUBLE_VALUE)
#define jr_C_ExprNodeIsStringValue(c_expr_node) \
((c_expr_node)->value_type == jr_C_EXPR_STRING_VALUE)
#define jr_C_ExprNodeIsPtrValue(c_expr_node) \
((c_expr_node)->value_type == jr_C_EXPR_PTR_VALUE)
#define jr_C_ExprNodeIsIntegerValue(c_expr_node) \
( jr_C_ExprNodeIsIntValue (c_expr_node) \
|| jr_C_ExprNodeIsUnsignedValue (c_expr_node) \
)
#define jr_C_ExprNodeIsNumericValue(c_expr_node) \
( jr_C_ExprNodeIsIntegerValue (c_expr_node) \
|| jr_C_ExprNodeIsFloatValue (c_expr_node) \
|| jr_C_ExprNodeIsDoubleValue (c_expr_node) \
)
#define jr_C_ExprNodeIsTrue(c_expr_node) \
( jr_C_ExprNodeIsDoubleValue (c_expr_node) \
? jr_C_ExprNodeDoubleValue (c_expr_node) != 0 \
: jr_C_ExprNodeIntValue (c_expr_node) != 0 \
)
/*
* The int value will cover all 4 byte values,
* the double value will cover the 8 byte values
*/
#define jr_C_ExprNodeIsFalse(c_expr_node) (! jr_C_ExprNodeIsTrue (c_expr_node))
#define jr_C_ExprNodeIsIdentifier(c_expr_node) ((c_expr_node)->identifier_name)
#define jr_C_ExprNodeIdentifierName(c_expr_node) ((c_expr_node)->identifier_name)
#endif
|
frankjas/libjr
|
libjr/misc/hashshrt.c
|
#include "ezport.h"
#include "jr/misc.h"
/*
Author: <NAME>
Creation Date: March, 1987
*/
jr_int shorthash (i)
short i;
{
return ((i*i)+1);
}
/*
jr_int jr_intphash (n)
jr_int *n;
{
return ((*n * *n)+1);
}
*/
jr_int shortphash (n)
short *n;
{
jr_int i = (*n * *n) ;
if (i < 0) {
i = -i ;
i >>= i ;
}
return (i) ;
}
|
frankjas/libjr
|
libjr/syscalls/jr_epoll.c
|
#include "ezport.h"
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include "jr/epoll.h"
#include "jr/alist.h"
#include "jr/dlist.h"
#include "jr/error.h"
void jr_epoll_event_init_ptr (
struct epoll_event * event_info,
jr_int event_flags,
void * ptr)
{
memset (event_info, 0, sizeof (*event_info));
event_info->events = event_flags;
event_info->data.ptr = ptr;
}
typedef struct {
jr_DList event_list[1];
} jr_EPollType;
typedef struct {
jr_int io_fd;
struct epoll_event event_info[1];
} jr_EPollEventType;
extern void jr_EPollInit (
jr_EPollType * epoll_info_ptr,
jr_int estimated_num_clients);
extern void jr_EPollUndo (
jr_EPollType * epoll_info_ptr);
extern void jr_EPollAddEvent (
jr_EPollType * epoll_info_ptr,
jr_int io_fd,
struct epoll_event * event_info);
extern void jr_EPollEventInit (
jr_EPollEventType * epoll_el_ptr,
jr_int io_fd,
struct epoll_event * event_info);
extern void jr_EPollEventUndo (
jr_EPollEventType * epoll_el_ptr);
void jr_EPollInit (
jr_EPollType * epoll_info_ptr,
jr_int estimated_num_clients)
{
memset (epoll_info_ptr, 0, sizeof (*epoll_info_ptr));
jr_DListInit (epoll_info_ptr->event_list, sizeof (jr_EPollEventType));
}
void jr_EPollUndo (
jr_EPollType * epoll_info_ptr)
{
jr_EPollEventType * epoll_el_ptr;
jr_DListForEachElementPtr (epoll_info_ptr->event_list, epoll_el_ptr) {
jr_EPollEventUndo (epoll_el_ptr);
}
jr_DListUndo (epoll_info_ptr->event_list);
}
void jr_EPollAddEvent (
jr_EPollType * epoll_info_ptr,
jr_int io_fd,
struct epoll_event * event_info)
{
jr_EPollEventType * epoll_el_ptr;
jr_DListForEachElementPtr (epoll_info_ptr->event_list, epoll_el_ptr) {
if (epoll_el_ptr->io_fd == io_fd) {
jr_EPollEventUndo (epoll_el_ptr);
jr_EPollEventInit (epoll_el_ptr, io_fd, event_info);
return;
}
}
epoll_el_ptr = jr_DListNewTailPtr (epoll_info_ptr->event_list);
jr_EPollEventInit (epoll_el_ptr, io_fd, event_info);
}
void jr_EPollDeleteEvent (
jr_EPollType * epoll_info_ptr,
jr_int io_fd)
{
jr_EPollEventType * epoll_el_ptr;
jr_DListForEachElementPtr (epoll_info_ptr->event_list, epoll_el_ptr) {
if (epoll_el_ptr->io_fd == io_fd) {
jr_EPollEventUndo (epoll_el_ptr);
jr_DListDeleteElement (epoll_info_ptr->event_list, epoll_el_ptr);
return;
}
}
}
jr_int jr_EPollWait (
jr_EPollType * epoll_info_ptr,
struct epoll_event * event_array,
jr_int max_events,
jr_int timeout_seconds)
{
jr_EPollEventType * epoll_el_ptr;
jr_int max_fd;
jr_int num_fds;
struct timeval timeout [1];
struct timeval * timeout_ptr = 0;
fd_set read_fd_set[1];
fd_set write_fd_set[1];
jr_int nready;
jr_int num_events;
for (;;) {
FD_ZERO (read_fd_set);
FD_ZERO (write_fd_set);
timeout->tv_sec = timeout_seconds;
timeout->tv_usec = 0;
if (timeout_seconds >= 0) {
timeout_ptr = timeout;
}
else {
timeout_ptr = 0;
}
num_fds = 0;
max_fd = -1;
jr_DListForEachElementPtr (epoll_info_ptr->event_list, epoll_el_ptr) {
if (epoll_el_ptr->event_info->events & EPOLLIN) {
FD_SET (epoll_el_ptr->io_fd, read_fd_set);
}
if (epoll_el_ptr->event_info->events & EPOLLOUT) {
FD_SET (epoll_el_ptr->io_fd, write_fd_set);
}
num_fds++;
if (epoll_el_ptr->io_fd > max_fd) {
max_fd = epoll_el_ptr->io_fd;
}
}
if (max_events < num_fds) {
/*
** 8/14/06: Since each file descriptor returned by select() must be examined,
** the number of events must be >= number of watched fds.
*/
errno = EINVAL;
return jr_INTERNAL_ERROR;
}
nready = select (max_fd + 1, read_fd_set, write_fd_set, 0, timeout_ptr);
if (nready < 0) {
return jr_INTERNAL_ERROR;
}
if (nready == 0) {
return 0;
}
num_events = 0;
jr_DListForEachElementPtr (epoll_info_ptr->event_list, epoll_el_ptr) {
if ( FD_ISSET (epoll_el_ptr->io_fd, read_fd_set)
|| FD_ISSET (epoll_el_ptr->io_fd, write_fd_set)) {
event_array[num_events].data = epoll_el_ptr->event_info->data;
event_array[num_events].events = 0;
if (FD_ISSET (epoll_el_ptr->io_fd, read_fd_set)) {
event_array[num_events].events |= EPOLLIN;
}
if (FD_ISSET (epoll_el_ptr->io_fd, write_fd_set)) {
event_array[num_events].events |= EPOLLOUT;
}
num_events++;
}
}
if (num_events > 0) {
return num_events;
}
}
}
void jr_EPollEventInit (
jr_EPollEventType * epoll_el_ptr,
jr_int io_fd,
struct epoll_event * event_info)
{
memset (epoll_el_ptr, 0, sizeof (*epoll_el_ptr));
epoll_el_ptr->io_fd = io_fd;
memcpy (epoll_el_ptr->event_info, event_info, sizeof (*event_info));
}
void jr_EPollEventUndo (
jr_EPollEventType * epoll_el_ptr)
{
}
#ifdef missing_epoll_in_kernel
jr_AList EPollList[1];
static jr_int EPollListIsInitialized = 0;
static jr_int EPollNumCreates = 0;
jr_int jr_epoll_create (
jr_int estimated_num_clients)
{
jr_EPollType * epoll_info_ptr;
if (!EPollListIsInitialized) {
jr_AListInit (EPollList, sizeof (jr_EPollType));
EPollListIsInitialized = 1;
}
epoll_info_ptr = jr_AListNewTailPtr (EPollList);
jr_EPollInit (epoll_info_ptr, estimated_num_clients);
EPollNumCreates ++;
return 0;
}
jr_int jr_epoll_close (
jr_int epoll_fd)
{
jr_EPollType * epoll_info_ptr;
if (!EPollListIsInitialized || !jr_AListIsValidIndex (EPollList, epoll_fd)) {
errno = EBADF;
return jr_INTERNAL_ERROR;
}
epoll_info_ptr = jr_AListElementPtr (EPollList, epoll_fd);
jr_EPollUndo (epoll_info_ptr);
EPollNumCreates --;
if (EPollNumCreates == 0) {
jr_AListUndo (EPollList);
EPollListIsInitialized = 0;
}
return 0;
}
jr_int jr_epoll_ctl (
jr_int epoll_fd,
jr_int epoll_op,
jr_int io_fd,
struct epoll_event * event_info)
{
jr_EPollType * epoll_info_ptr;
if (!EPollListIsInitialized || !jr_AListIsValidIndex (EPollList, epoll_fd)) {
errno = EBADF;
return jr_INTERNAL_ERROR;
}
epoll_info_ptr = jr_AListElementPtr (EPollList, epoll_fd);
if (epoll_op == EPOLL_CTL_ADD) {
jr_EPollAddEvent (epoll_info_ptr, io_fd, event_info);
}
else if (epoll_op == EPOLL_CTL_MOD) {
jr_EPollAddEvent (epoll_info_ptr, io_fd, event_info);
}
else if (epoll_op == EPOLL_CTL_DEL) {
jr_EPollDeleteEvent (epoll_info_ptr, io_fd);
}
else {
errno = ENOENT;
return jr_INTERNAL_ERROR;
}
return 0;
}
jr_int jr_epoll_wait (
jr_int epoll_fd,
struct epoll_event * event_array,
jr_int max_events,
jr_int timeout_seconds)
{
jr_EPollType * epoll_info_ptr;
jr_int status;
if (!EPollListIsInitialized || !jr_AListIsValidIndex (EPollList, epoll_fd)) {
errno = EBADF;
return jr_INTERNAL_ERROR;
}
epoll_info_ptr = jr_AListElementPtr (EPollList, epoll_fd);
status = jr_EPollWait (epoll_info_ptr, event_array, max_events, timeout_seconds);
return status;
}
#endif
|
frankjas/libjr
|
libjr/htable/htablins.c
|
#include "project.h"
jr_int jr_HTableFindIndexGeneric (htable, key_ptr, is_ptr_value)
jr_HTable * htable;
const void * key_ptr;
jr_int is_ptr_value;
{
jr_int hash_value;
jr_int bucket;
jr_int curr_entry;
jr_int diff;
if (htable->num_buckets == 0) {
return -1;
}
hash_value = (*htable->hashfn) (key_ptr);
if (hash_value < 0) {
/*
* can't have negative hash_values
*/
hash_value *= -1;
}
bucket = hash_value % htable->num_buckets;
curr_entry = htable->buckets_array[bucket];
while (curr_entry != -1) {
if (is_ptr_value) {
diff = (*htable->cmpfn) (
jr_HTableKeyPtrValue (htable, curr_entry), key_ptr, htable->cmp_arg
);
}
else {
diff = (*htable->cmpfn) (
jr_HTableElementPtr (htable, curr_entry), key_ptr, htable->cmp_arg
);
}
if (diff == 0) {
return curr_entry;
}
curr_entry = jr_HTableNextElementIndex(htable, curr_entry);
}
return -1;
}
void *jr_HTableFindPtrGeneric (htable, key_ptr, is_ptr_value)
jr_HTable * htable;
const void * key_ptr;
jr_int is_ptr_value;
{
jr_int index;
index = jr_HTableFindIndexGeneric (htable, key_ptr, is_ptr_value);
if (index == -1) {
return 0;
}
if (is_ptr_value) {
return jr_HTableKeyPtrValue (htable, index);
}
else {
return jr_HTableElementPtr (htable, index);
}
}
jr_int jr_HTableNewIndexGeneric (htable, key_ptr, is_ptr_value)
jr_HTable * htable;
const void * key_ptr;
jr_int is_ptr_value;
{
jr_int curr_index;
jr_int new_index;
jr_int hash_value;
curr_index = jr_HTableFindIndexGeneric (htable, key_ptr, is_ptr_value);
if (curr_index >= 0) {
return -1;
}
new_index = jr_HTableAllocateNewIndex (htable);
if (is_ptr_value) {
jr_HTableKeyPtrValue (htable, new_index) = (void *) key_ptr;
}
hash_value = (*htable->hashfn) (key_ptr);
if (hash_value < 0) {
hash_value *= -1;
}
jr_HTableHashValue(htable, new_index) = hash_value;
jr_HTableNextElementIndex(htable, new_index) = -1;
jr_HTableAddToBucketList (htable, new_index);
if (jr_AListSize (htable->entry_array) > htable->num_buckets) {
jr_HTableIncreaseNumBuckets (htable);
}
return new_index;
}
void *jr_HTableNewPtrGeneric (htable, key_ptr, is_ptr_value)
jr_HTable * htable;
const void * key_ptr;
jr_int is_ptr_value;
{
jr_int index;
index = jr_HTableNewIndexGeneric (htable, key_ptr, is_ptr_value);
if (index == -1) {
return 0;
}
if (is_ptr_value) {
return jr_HTableKeyPtrValue (htable, index);
}
else {
return jr_HTableElementPtr (htable, index);
}
}
void *jr_HTableSetNewElement (htable, key_ptr)
jr_HTable * htable;
const void * key_ptr;
{
void * new_el_ptr;
new_el_ptr = jr_HTableNewElementPtr (htable, key_ptr);
if (new_el_ptr) {
memcpy (new_el_ptr, key_ptr, jr_HTableElementSize (htable));
}
return new_el_ptr;
}
jr_int jr_HTableSetNewElementIndex (htable, key_ptr)
jr_HTable * htable;
const void * key_ptr;
{
jr_int index;
index = jr_HTableNewElementIndex (htable, key_ptr);
if (index >= 0) {
memcpy (jr_HTableElementPtr (htable, index), key_ptr, jr_HTableElementSize (htable));
}
return index;
}
jr_int jr_HTableAllocateNewIndex (htable)
jr_HTable * htable;
{
jr_int new_index;
if (htable->num_deletes) {
new_index = htable->delete_list;
htable->delete_list = jr_HTableNextElementIndex(htable, htable->delete_list);
htable->num_deletes --;
}
else {
jr_AListNewTailPtr (htable->entry_array);
new_index = jr_AListTailIndex (htable->entry_array);
}
return new_index;
}
#ifdef compile_primes_xxx
/*
* From PHP's hash table implementation
*/
unsigned jr_int jr_PrimesForDoubling [] =
{ 5, 11, 19, 53, 107,
223, 463, 983, 1979, 3907,
7963, 16229, 32531, 65407, 130987,
262237, 524521, 1048793, 2097397, 4194103,
8388857, 16777447, 33554201, 67108961, 134217487,
268435697, 536870683, 1073741621, 2147483399
};
unsigned jr_int jr_NumPrimesForDoubling = sizeof(jr_PrimesForDoubling) / sizeof(unsigned jr_int);
#endif
void jr_HTableIncreaseNumBuckets (htable)
jr_HTable * htable;
{
jr_int i;
if (htable->num_buckets >= jr_AListSize (htable->entry_array)) {
return;
}
/* else double the number of entries */
while (htable->num_buckets < jr_AListSize (htable->entry_array)) {
if (htable->num_buckets == 0) {
htable->num_buckets = 8 + 1;
}
else {
/*
* use a fairly prime number, i.e. a power of 2, + 1, since
* more numbers will be relatively prime (i.e. not share any
* divisors) and therefore won't hash to the same buckets
*/
htable->num_buckets = 2 * (htable->num_buckets - 1) + 1;
}
}
if (htable->buckets_array) {
jr_free (htable->buckets_array);
}
htable->buckets_array = jr_malloc (htable->num_buckets * sizeof(jr_int));
for (i = 0; i < htable->num_buckets; i++) {
htable->buckets_array[i] = -1;
/*
* initialize each bucket with the end-of-list value, -1
*/
}
jr_HTableForEachElementIndex (htable, i) {
jr_HTableAddToBucketList (htable, i);
}
}
void jr_HTableAddToBucketList (htable, index)
jr_HTable * htable;
jr_int index;
{
jr_int hash_value;
jr_int bucket;
if (htable->num_buckets == 0) {
return;
}
hash_value = jr_HTableHashValue(htable, index);
bucket = hash_value % htable->num_buckets;
jr_HTableNextElementIndex(htable, index) = htable->buckets_array [bucket];
htable->buckets_array [bucket] = index;
}
void jr_HTableIncreaseCapacity (htable, new_capacity)
jr_HTable * htable;
jr_int new_capacity;
{
jr_AListIncreaseCapacity (htable->entry_array, new_capacity);
}
static jr_HTableElementStruct *jr_HTableEntryPtr (htable, index)
jr_HTable * htable;
jr_int index;
{
if (0) {
/*
* avoid complier non-use error
*/
jr_HTableEntryPtr (htable, 0);
}
return jr_HTableElementInfoPtrWithPrefix (htable, index, jr_HTablePrefixSize (htable));
}
|
frankjas/libjr
|
libjr/syscalls/jr_errno.c
|
#define _POSIX_SOURCE 1
#include "ezport.h"
#ifdef ostype_winnt
# include <winerror.h>
#else
# include <netdb.h>
#endif
#include <errno.h>
#include "jr/error.h"
jr_int jr_ConvertErrno (
jr_int errno_value)
{
switch (errno_value) {
case EACCES : return jr_PERMISSION_ERROR;
case ESRCH :
case ENOENT : return jr_NOT_FOUND_ERROR;
case EIO : return jr_IO_ERROR;
case EFBIG : /* file too big */
case ENOSPC : return jr_NO_ROOM_ERROR; /* no more space on file system */
}
return jr_INTERNAL_ERROR;
}
#ifdef ostype_winnt
jr_int jr_ConvertLastError (
jr_int last_error)
{
switch (last_error) {
case ERROR_ACCESS_DENIED : return jr_PERMISSION_ERROR;
case ERROR_FILE_NOT_FOUND :
case ERROR_PATH_NOT_FOUND : return jr_NOT_FOUND_ERROR;
case ERROR_CRC :
case ERROR_READ_FAULT :
case ERROR_WRITE_FAULT :
case ERROR_GEN_FAILURE : return jr_IO_ERROR;
case ERROR_OUTOFMEMORY :
case ERROR_NOT_ENOUGH_MEMORY:
case ERROR_HANDLE_DISK_FULL : return jr_NO_ROOM_ERROR;
}
return jr_INTERNAL_ERROR;
}
jr_int jr_ConvertGetHostErrno (gethost_errno)
jr_int gethost_errno;
{
switch (gethost_errno) {
case WSAHOST_NOT_FOUND : return jr_NOT_FOUND_ERROR;
case WSATRY_AGAIN : return jr_TIME_OUT_ERROR;
case WSAENETDOWN :
case WSANO_RECOVERY : return jr_IO_ERROR;
case WSANO_DATA : return jr_NOT_FOUND_ERROR;
}
return jr_MISUSE_ERROR;
}
char *jr_GetHostErrnoString (gethost_errno)
jr_int gethost_errno;
{
switch (gethost_errno) {
case WSAHOST_NOT_FOUND : return "no such host";
case WSATRY_AGAIN : return "try again";
case WSAENETDOWN : return "network unavailable";
case WSANO_RECOVERY : return "unrecoverable name server error";
case WSANO_DATA : return "valid hostname, but no address listed";
}
return "internal gethost...() error";
}
#else
jr_int jr_ConvertGetHostErrno (gethost_errno)
jr_int gethost_errno;
{
switch (gethost_errno) {
case HOST_NOT_FOUND : return jr_NOT_FOUND_ERROR;
case TRY_AGAIN : return jr_TIME_OUT_ERROR;
case NO_RECOVERY : return jr_IO_ERROR;
case NO_DATA : return jr_NOT_FOUND_ERROR;
}
return jr_MISUSE_ERROR;
}
char *jr_GetHostErrnoString (gethost_errno)
jr_int gethost_errno;
{
switch (gethost_errno) {
case HOST_NOT_FOUND : return "no such host";
case TRY_AGAIN : return "try again";
case NO_RECOVERY : return "unrecoverable name server error";
case NO_DATA : return "valid hostname, but no address listed";
}
return "invalid gethost...() error number";
}
#endif
|
frankjas/libjr
|
libjr/misc/jr_bswap.c
|
<filename>libjr/misc/jr_bswap.c
#include "ezport.h"
#include "jr/nettype.h"
unsigned jr_int jr_bswap_32 (unsigned jr_int value)
{
/*
** 1/27/07: Little endian: 0123
** Big endian: 3210
*/
value = (0xffff0000 & value) >> 16 | (0x0000ffff & value) << 16;
value = (0xff00ff00 & value) >> 8 | (0x00ff00ff & value) << 8;
return value;
}
unsigned jr_int jr_bswap_16 (unsigned jr_short value)
{
/*
** 1/27/07: Little endian: 01
** Big endian: 10
*/
value = (0xff00 & value) >> 8 | (0x00ff & value) << 8;
return value;
}
#define jr_CLASS_A_MASK 0xff000000
#define jr_CLASS_B_MASK 0xffff0000
#define jr_CLASS_C_MASK 0xffffff00
unsigned jr_int jr_inet_host_number( unsigned jr_int ip_number)
{
ip_number = jr_ntohl( ip_number);
if ((ip_number & 0x80000000) == 0) {
return ip_number & ~jr_CLASS_A_MASK;
}
if ((ip_number & 0xc0000000) == 0x80000000) {
return ip_number & ~jr_CLASS_B_MASK;
}
return ip_number & ~jr_CLASS_C_MASK;
}
unsigned jr_int jr_inet_network_number( unsigned jr_int ip_number)
{
ip_number = jr_ntohl( ip_number);
if ((ip_number & 0x80000000) == 0) {
return (ip_number & jr_CLASS_A_MASK) >> 24;
}
if ((ip_number & 0xc0000000) == 0x80000000) {
return (ip_number & jr_CLASS_B_MASK) >> 16;
}
return (ip_number & jr_CLASS_C_MASK) >> 8;
}
|
frankjas/libjr
|
libjr/syscalls/fd_lock.c
|
#define _POSIX_SOURCE 1
#include "ezport.h"
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <setjmp.h>
#include <sys/file.h>
#include <unistd.h>
#include "jr/syscalls.h"
#include "jr/error.h"
jr_int jr_fcntl_flock (fd, operation, is_blocking)
jr_int fd;
jr_int operation;
jr_int is_blocking;
{
struct flock new_lock [1];
jr_int status;
new_lock->l_whence = SEEK_SET;
new_lock->l_start = 0;
new_lock->l_len = 0;
new_lock->l_type = operation;
if (is_blocking) {
status = fcntl (fd, F_SETLKW, new_lock);
}
else {
status = fcntl (fd, F_SETLK, new_lock);
}
return status;
}
static sigjmp_buf LockEnv ;
static void onalarm(signum)
jr_int signum ;
{
siglongjmp(LockEnv, 1) ;
}
jr_int jr_FileDescReadLock (file_descriptor, time_out, error_buf)
jr_int file_descriptor;
jr_int time_out;
char * error_buf;
{
jr_int return_status;
if (time_out > 0) {
struct sigaction new_action [1];
struct sigaction old_action [1];
unsigned jr_int savealarm = 0 ; /* to shutup 'uninit.' msg */
/*
* break out of the lock if it takes too long
*/
if (sigsetjmp (LockEnv, 1) == 0) {
/*
* setting the jump, if we can't get the lock
*/
new_action->sa_handler = onalarm;
sigemptyset (&new_action->sa_mask);
new_action->sa_flags = SA_RESTART;
savealarm = alarm(0);
sigaction (SIGALRM, new_action, old_action);
alarm (time_out);
/*
* wait for the lock to happen
*/
if (flock (file_descriptor, LOCK_SH) < 0) {
jr_esprintf (error_buf, "couldn't lock file: %s", strerror (errno));
return_status = jr_INTERNAL_ERROR;
}
else {
return_status = 0;
}
}
else {
/*
* we timed out
*/
jr_esprintf (error_buf, "timed out");
return_status = jr_TIME_OUT_ERROR;
}
alarm (0);
sigaction (SIGALRM, old_action, 0);
alarm (savealarm);
}
else {
/*
* try a non-blocking lock
*/
if (flock (file_descriptor, LOCK_SH | LOCK_NB) < 0) {
if (errno == EWOULDBLOCK) {
jr_esprintf (error_buf, "timed out");
return_status = jr_TIME_OUT_ERROR;
}
else {
jr_esprintf (error_buf, "couldn't lock file: %s", strerror (errno));
return_status = jr_INTERNAL_ERROR;
}
}
else {
return_status = 0;
}
}
return return_status;
}
jr_int jr_FileDescWriteLock (file_descriptor, time_out, error_buf)
jr_int file_descriptor;
jr_int time_out;
char * error_buf;
{
jr_int return_status;
if (time_out > 0) {
/*
* break out of the lock if it takes too long
*/
struct sigaction new_action [1];
struct sigaction old_action [1];
unsigned jr_int savealarm = 0 ; /* to shutup 'uninit.' msg */
if (sigsetjmp (LockEnv, 1) == 0) {
/*
* setting the jump, if we can't get the lock
*/
new_action->sa_handler = onalarm;
sigemptyset (&new_action->sa_mask);
new_action->sa_flags = SA_RESTART;
savealarm = alarm(0);
sigaction (SIGALRM, new_action, old_action);
alarm(time_out);
/*
* wait for the lock to happen
*/
if (flock (file_descriptor, LOCK_EX) != 0) {
jr_esprintf (error_buf, "couldn't flock: %s", strerror (errno));
return_status = jr_INTERNAL_ERROR;
}
else {
return_status = 0;
}
}
else {
/*
* we timed out
*/
jr_esprintf (error_buf, "timed out");
return_status = jr_TIME_OUT_ERROR;
}
alarm (0);
sigaction (SIGALRM, old_action, 0);
alarm (savealarm);
}
else {
/*
* try a no-blocking lock
*/
if (flock (file_descriptor, LOCK_EX | LOCK_NB) != 0) {
if (errno != EWOULDBLOCK) {
jr_esprintf (error_buf, "couldn't flock: %s", strerror (errno));
return_status = jr_INTERNAL_ERROR;
}
else {
jr_esprintf (error_buf, "timed out");
return_status = jr_TIME_OUT_ERROR;
}
}
else {
return_status = 0;
}
}
return return_status;
}
void jr_FileDescUnLock (file_descriptor)
jr_int file_descriptor;
{
if (flock (file_descriptor, LOCK_UN) < 0) {
/*
* only possible if file descriptor was bad
*/
}
}
|
frankjas/libjr
|
libjr/misc/jr_uuidc.c
|
#define _POSIX_SOURCE 1
#include "ezport.h"
#include <string.h>
#include "jr/uuid.h"
#include "jr/misc.h"
jr_int jr_UUIdCmp (void_ptr_1, void_ptr_2)
const void * void_ptr_1;
const void * void_ptr_2;
{
const jr_UUIdStruct * uuid_info_1 = void_ptr_1;
const jr_UUIdStruct * uuid_info_2 = void_ptr_2;
jr_int diff;
diff = memcmp (uuid_info_1->uuid_buf, uuid_info_2->uuid_buf, sizeof (uuid_info_1->uuid_buf));
if (diff != 0) {
return diff;
}
return 0;
}
jr_int jr_UUIdHash (void_ptr_1)
const void * void_ptr_1;
{
const jr_UUIdStruct * uuid_info_1 = void_ptr_1;
jr_int hash_value = 0;
char uuid_buf [jr_UUID_STRING_LENGTH + 1];
jr_UUIdToString (uuid_info_1, uuid_buf);
hash_value += jr_strhash_pjw (uuid_buf);
return hash_value;
}
|
frankjas/libjr
|
libjr/missing/setsid.c
|
<reponame>frankjas/libjr<filename>libjr/missing/setsid.c
#define _POSIX_SOURCE 1
#include "ezport.h"
#ifdef missing_setsid
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int setsid()
{
jr_int tty_fd;
pid_t grp_id;
tty_fd = open ("/dev/tty", O_RDONLY) ;
if (tty_fd < 0) return(-1) ;
if (ioctl(tty_fd, TIOCNOTTY, 0) < 0) {
return(-1) ;
}
close(tty_fd) ;
grp_id = getpgrp (0);
/*
* Get the process group of the current process.
* Under POSIX, this function does not take a parameter
*/
if (grp_id != getpid()) {
/*
* If the current process is not a process group leader,
* then make it the leader of its own process group
*/
grp_id = setpgrp (0, getpid());
}
return grp_id;
}
#else
static void NotCalled () /* define this so ranlib doesn't complain */
{
NotCalled (); /* use it so the compiler doesn't complain */
}
#endif
/*
main(argc, argv)
jr_int argc ;
char ** argv ;
{
jr_int pid ;
jr_int old_pgrp ;
jr_int new_pgrp ;
pid = getpid() ;
old_pgrp = getpgrp() ;
fprintf(stdout, "%s : %d has process group %d\n",
argv[0], pid, old_pgrp
) ;
fprintf(stderr, "Enter a return: ") ;
getchar() ;
setsid() ;
fprintf(stderr, "Enter a return: ") ;
getchar() ;
new_pgrp = getpgrp() ;
fprintf(stdout, "%s : %d has process group %d\n",
argv[0], pid, new_pgrp
) ;
exit(0) ;
}
*/
|
frankjas/libjr
|
libjr/syscalls/invoke.c
|
<gh_stars>0
#define _POSIX_SOURCE 1
#include "ezport.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include "jr/syscalls.h"
#include "jr/malloc.h"
#include "jr/error.h"
jr_int jr_Invoke1WayCommandVector (argv, rfp_ptr, error_buf)
char ** argv ;
FILE ** rfp_ptr;
char * error_buf;
{
jr_int parent_rfd;
jr_int childs_wfd;
jr_int childs_pid ;
jr_int datapath[2] ;
FILE * rfp ;
jr_int status;
status = pipe(datapath);
if (status != 0) {
jr_esprintf (error_buf, "couldn't create pipe: %s", strerror (errno));
return -1;
}
parent_rfd = datapath[0] ;
childs_wfd = datapath[1] ;
childs_pid = fork();
if (childs_pid < 0) {
close (parent_rfd);
close (childs_wfd);
jr_esprintf (error_buf, "couldn't spawn process: %s", strerror (errno));
return -1;
}
if (childs_pid == 0) {
close(parent_rfd) ;
if (childs_wfd != STDOUT_FILENO) {
jr_int newfd ;
newfd = dup2 (childs_wfd, STDOUT_FILENO) ;
if (newfd != STDOUT_FILENO) {
fprintf (stderr,
"jr_Invoke1WayCommandVector() child '%s': couldn't redirect stdout: dup2() returned %d\n",
argv[0], newfd
);
exit (1);
}
close(childs_wfd) ;
}
status = execvp(argv[0], argv);
if (status != 0) {
char buf[512] ;
sprintf(buf, "jr_Invoke1WayCommandVector() child: couldn't execvp(%s) ", argv[0]) ;
perror(buf) ;
_exit(errno) ;
}
}
close(childs_wfd);
rfp = fdopen(parent_rfd, "r") ;
if (rfp == NULL) {
jr_esprintf (error_buf, "couldn't open child's stdout: %s", strerror (errno));
kill (childs_pid, SIGKILL);
status = waitpid (childs_pid, 0, 0);
return -1;
}
*rfp_ptr = rfp;
return childs_pid;
}
jr_int jr_Invoke1WayCommandVectorWithStderr (argv, rfp_ptr, error_buf)
char ** argv ;
FILE ** rfp_ptr;
char * error_buf;
{
jr_int parent_rfd;
jr_int childs_wfd;
jr_int childs_pid ;
jr_int datapath[2] ;
FILE * rfp ;
jr_int status;
status = pipe(datapath);
if (status != 0) {
jr_esprintf (error_buf, "couldn't create pipe: %s", strerror (errno));
return -1;
}
parent_rfd = datapath[0] ;
childs_wfd = datapath[1] ;
childs_pid = fork();
if (childs_pid < 0) {
close (parent_rfd);
close (childs_wfd);
jr_esprintf (error_buf, "couldn't spawn process: %s", strerror (errno));
return -1;
}
if (childs_pid == 0) {
jr_int newfd ;
close(parent_rfd) ;
if (childs_wfd != STDOUT_FILENO) {
newfd = dup2 (childs_wfd, STDOUT_FILENO) ;
if (newfd != STDOUT_FILENO) {
fprintf (stderr,
"jr_Invoke1WayCommandVector() child '%s': couldn't redirect stdout: dup2() returned %d != %d\n",
argv[0], newfd, STDOUT_FILENO
);
exit (1);
}
}
newfd = dup2 (childs_wfd, STDERR_FILENO);
if (newfd != STDERR_FILENO) {
fprintf (stderr,
"jr_Invoke1WayCommandVector() child '%s': couldn't redirect stderr: dup2() returned %d != %d\n",
argv[0], newfd, STDERR_FILENO
);
exit (1);
}
if (childs_wfd != STDOUT_FILENO) {
close(childs_wfd) ;
}
status = execvp(argv[0], argv);
if (status != 0) {
char buf[512] ;
sprintf(buf, "jr_Invoke1WayCommandVector() child: couldn't execvp(%s) ", argv[0]) ;
perror(buf) ;
_exit(errno) ;
}
}
close(childs_wfd);
rfp = fdopen(parent_rfd, "r") ;
if (rfp == NULL) {
jr_esprintf (error_buf, "couldn't open child's stdout: %s", strerror (errno));
kill (childs_pid, SIGKILL);
status = waitpid (childs_pid, 0, 0);
close (parent_rfd);
return -1;
}
*rfp_ptr = rfp;
return childs_pid;
}
jr_int jr_InvokeCommandVector (argv, fp_array, num_fps, error_buf)
char ** argv ;
FILE * fp_array[] ;
jr_int num_fps;
char * error_buf;
{
pid_t childs_pid;
jr_int * fd_array;
jr_int i;
jr_int parents_fd = 0; /* to shutup 'uninit.' msg */
jr_int childs_fd = 0;
jr_int status;
if (num_fps > 3) {
jr_esprintf (error_buf, "too many pipes (%d), max is %d", num_fps, 3);
return -1;
}
fd_array = jr_malloc (2 * num_fps * sizeof (jr_int));
for (i=0; i < num_fps; i++) {
status = pipe (fd_array + 2 * i);
if (status != 0) {
jr_esprintf (error_buf, "couldn't open pipe: %s", strerror (errno));
jr_free (fd_array);
return -1;
}
fp_array[i] = 0;
}
childs_pid = fork ();
if (childs_pid < 0) {
jr_esprintf (error_buf, "couldn't spawn process: %s", strerror (errno));
goto return_bad;
}
for (i = 0; i < num_fps; i++) {
switch (i) {
case STDIN_FILENO : {
childs_fd = fd_array [2 * i];
parents_fd = fd_array [2 * i + 1];
break;
}
case STDOUT_FILENO :
case STDERR_FILENO : {
childs_fd = fd_array [2 * i + 1];
parents_fd = fd_array [2 * i];
break;
}
}
if (childs_pid == 0) {
close (parents_fd);
if (childs_fd != i) {
status = dup2 (childs_fd, i);
if (status != i) {
fprintf (stderr,
"jr_InvokeCommandVector() child '%s': couldn't redirect: dup2() returned %d != %d\n",
argv[0], status, i
);
exit (1);
}
close(childs_fd) ;
}
}
else {
close (childs_fd);
if (i == STDIN_FILENO) {
fp_array[i] = fdopen (parents_fd, "w");
}
else {
fp_array[i] = fdopen (parents_fd, "r");
}
if (fp_array[i] == NULL) {
jr_esprintf (error_buf, "couldn't open child's %s: %s",
i == STDIN_FILENO ? "stdin" : i == STDOUT_FILENO ? "stdout" : "stderr",
strerror (errno));
kill (childs_pid, SIGKILL);
status = waitpid (childs_pid, 0, 0);
goto return_bad;
}
}
}
if (childs_pid == 0) {
status = execvp(argv[0], argv);
if (status != 0) {
fprintf (stderr, "jr_InvokeCommandVector() child: couldn't execvp(%s): %s\n",
argv[0], strerror (errno)
) ;
fflush (stderr);
_exit(errno) ;
}
}
if (0) return_bad : {
childs_pid = -1;
for (i = 0; i < num_fps; i++) {
close (fd_array[i]);
if (fp_array[i]) {
fclose (fp_array[i]);
}
}
}
jr_free (fd_array);
return childs_pid;
}
|
frankjas/libjr
|
libjr/io/readfile.c
|
<reponame>frankjas/libjr<gh_stars>0
#include "ezport.h"
#include "jr/io.h"
#include "jr/malloc.h"
#include "jr/error.h"
#include "jr/alist.h"
void * jr_FileNameReadIntoNewMemory(rfn, length_ptr)
const char * rfn ;
unsigned jr_int * length_ptr ;
{
FILE * rfp ;
char * result_buffer ;
rfp = fopen(rfn, "r") ;
if (rfp == NULL) return(0) ;
result_buffer = jr_FilePtrReadIntoNewMemory(rfp, length_ptr) ;
fclose(rfp) ;
return(result_buffer) ;
}
void * jr_FilePtrReadIntoNewMemory(rfp, length_ptr)
FILE * rfp ;
unsigned jr_int * length_ptr ;
{
jr_int num_bytes;
void * file_memory;
jr_AList char_list[1];
jr_int c;
jr_AListInit (char_list, sizeof (char));
while ((c = getc (rfp)) != EOF) {
jr_AListNativeSetNewTail (char_list, c, char);
}
num_bytes = jr_AListSize (char_list); /* must go before adding 0, buffer-extract */
jr_AListNativeSetNewTail (char_list, 0, char);
file_memory = jr_AListExtractBuffer (char_list);
jr_AListUndo (char_list);
*length_ptr = num_bytes;
return (file_memory);
}
|
frankjas/libjr
|
libjr/syscalls/async_fn.h
|
#ifndef __async_fn_h___
#define __async_fn_h___
#define _POSIX_SOURCE 1
#include "ezport.h"
#include <signal.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#include "jr/error.h"
#include "jr/errsim.h"
#include "jr/syscalls.h"
#include "jr/avl_tree.h"
typedef struct {
jr_int call_time;
void (*handler_fn) ();
void * handler_param;
jr_int num_seconds;
unsigned do_repeat : 1;
} jr_AsyncFunctionStruct;
extern void jr_AsyncFunctionHandler (
jr_int signum);
extern void jr_AsyncFunctionInit (
jr_AsyncFunctionStruct * handler_info_ptr,
void (*handler_fn) (),
void * handler_param,
jr_int num_seconds,
jr_int do_repeat);
extern void jr_AsyncFunctionUndo (
jr_AsyncFunctionStruct * handler_info_ptr);
extern jr_int jr_AsyncFunctionCmp (
const void * void_arg_1,
const void * void_arg_2);
#define jr_AsyncFunctionPtr(handler_info_ptr) \
((handler_info_ptr)->handler_fn)
#define jr_AsyncFunctionParam(handler_info_ptr) \
((handler_info_ptr)->handler_param)
#define jr_AsyncFunctionCallTime(handler_info_ptr) \
((handler_info_ptr)->call_time)
#define jr_AsyncFunctionNumSeconds(handler_info_ptr) \
((handler_info_ptr)->num_seconds)
#define jr_AsyncFunctionDoRepeat(handler_info_ptr) \
((handler_info_ptr)->do_repeat)
#define jr_AsyncFunctionSetCallTime(handler_info_ptr, v) \
((handler_info_ptr)->call_time = (v))
#endif
|
frankjas/libjr
|
libjr/string/cremove.c
|
#include "ezport.h"
#include <string.h>
#include "jr/string.h"
void jr_RemoveAllOfChar (s, c)
char * s ;
jr_int c ;
{
char *tp ;
while (tp=(char *)strchr(s,c)) {
for (;*tp;tp++) *tp = tp[1] ;
}
}
/*
void main()
{
char * original = " hello 12345 there 6" ;
char * result ;
jr_int char_val = 'e' ;
s1 = jr_strdup(original) ;
jr_RemoveAllOfChar(result, char_val) ;
fprintf(stdout, "jr_RemoveAllOfChar(%s, '%c') == '%s'\n",
original, char_val,
result
) ;
jr_free(result) ;
}
*/
|
frankjas/libjr
|
libjr/string/vectorio.c
|
<reponame>frankjas/libjr
#include "ezport.h"
#include <stdio.h>
#include "jr/vector.h"
#include "jr/string.h"
#include "jr/malloc.h"
#include "jr/error.h"
#include "jr/alist.h"
char ** jr_VectorReadDeclaration(rfp, variable_name, error_buf)
FILE * rfp ;
char * variable_name ;
char * error_buf ;
{
char value_buf[4096] ;
char linebuf[4096] ;
jr_AList list[1] ;
char * new_string ;
char * trailing_quote ;
char * start_ptr ;
jr_int n ;
jr_AListInit(list, sizeof(char *)) ;
/* fprintf(wfp, "char * %s[] = {\n", variable_name) ; */
fgets(linebuf, sizeof(linebuf), rfp) ;
n = sscanf(linebuf, "char * %[^[ \t\n][] = {", variable_name) ;
if (n != 1) {
jr_esprintf (error_buf, "first line of vector declaration malformed") ;
goto err_return ;
}
while (fgets(linebuf, sizeof(linebuf), rfp) != NULL) {
start_ptr = jr_FirstNonWhiteSpacePtr(linebuf) ;
if (*start_ptr == '}') break ;
if (strncmp(start_ptr, "(char", 5) == 0) {
continue ;
}
n = sscanf(start_ptr, "\"%[^\n]", value_buf) ;
if (n != 1) {
jr_esprintf (error_buf, "malformed vector declaration: '%.32s'",
linebuf
) ;
goto err_return ;
}
trailing_quote = strrchr(value_buf, '\"') ;
if (trailing_quote == 0) {
jr_esprintf (error_buf, "missing end quote: '%.32s'", linebuf) ;
goto err_return ;
}
*trailing_quote = 0 ;
jr_EscapedCharsToControlChars(value_buf) ;
new_string = jr_strdup(value_buf) ;
jr_AListNativeSetNewTail(list, new_string, char *) ;
}
if (0) {
err_return:
jr_AListUndo(list) ;
return(0) ;
}
jr_AListNativeSetNewTail(list, 0, char *) ;
return((char **) jr_AListHeadPtr(list)) ;
}
|
frankjas/libjr
|
libjr/syscalls/jr_hostname.c
|
#include "ezport.h"
#include <apr-1/apr_pools.h>
#include <apr-1/apr_network_io.h>
#include "jr/apr.h"
#include "jr/error.h"
jr_int jr_gethostname(
char * host_name,
jr_int buf_length,
char * error_buf)
{
apr_pool_t * apr_pool_ptr = 0;
jr_int status;
jr_apr_initialize();
apr_pool_create (&apr_pool_ptr, NULL);
status = apr_gethostname( host_name, buf_length, apr_pool_ptr);
if (status != 0) {
jr_esprintf (error_buf, "%s", jr_apr_strerror( status, error_buf));
status = jr_ConvertAprErrno (status);
goto return_status;
}
status = 0;
return_status : {
if (apr_pool_ptr) {
apr_pool_destroy (apr_pool_ptr);
}
}
return status;
}
|
frankjas/libjr
|
libjr/syscalls/jr_exec.c
|
<filename>libjr/syscalls/jr_exec.c
#define _POSIX_SOURCE 1
#include "ezport.h"
#include <stdlib.h>
#include <stdio.h>
#include "jr/syscalls.h"
#include "jr/error.h"
jr_int jr_exec_cmd (
const char * command_str,
char * error_buf)
{
jr_int status;
status = system (command_str);
if (status < 0) {
jr_esprintf (error_buf, "couldn't spawn");
return jr_EXEC_SPAWN_ERROR;
}
if (WIFEXITED (status)) {
jr_esprintf (error_buf, "exit status was %d", WEXITSTATUS (status));
return WEXITSTATUS (status);
}
if (WIFSIGNALED (status)) {
jr_esprintf (error_buf, "process was killed by signal %d (%.64s%.32s)",
WTERMSIG (status), jr_SignalName (WTERMSIG (status)),
WIFCORE (status) ? " core dumped" : ""
);
return jr_EXEC_ERROR;
}
if (WIFSTOPPED (status)) {
jr_esprintf (error_buf, "process was stopped");
return jr_EXEC_ERROR;
}
jr_esprintf (error_buf, "no exit status, not stopped or killed");
return jr_EXEC_INTERNAL_ERROR;
}
|
frankjas/libjr
|
libjr/misc/pslib.c
|
#define _POSIX_SOURCE 1
#include "ezport.h"
#include <string.h>
#include "jr/string.h"
#include "jr/misc.h"
#include "jr/trace.h"
jr_int jr_PostScriptLineGetPageNumber(lbuf)
char * lbuf ;
{
jr_int nitems;
jr_int page_number;
nitems = sscanf (lbuf, "%%%% Page: ? %d", &page_number);
if (nitems != 1) {
return -1;
}
return page_number;
}
char *jr_PostScriptLineGetShowText(lbuf, text)
char *lbuf ;
char *text ;
{
char *ptr ;
char *str ;
*text = 0 ;
if (ptr = strchr (lbuf, '(')) /* ) */ {
jr_int open_paren ;
ptr++ ;
str = ptr ;
for (open_paren=1 ;
(open_paren) && (*ptr); ptr++) {
switch (*ptr) {
case '(' : {
open_paren++ ;
break ;
}
case ')' : {
open_paren-- ;
if (open_paren == 0) {
strncpy(text, str, ptr - str) ;
text[ptr - str] = 0 ;
return(text) ;
}
break ;
}
}
}
}
return(0) ;
}
jr_int jr_PostScriptFileGetBoundingBox (rfp, box_ptr)
FILE * rfp;
jr_PS_BoundingBoxStruct * box_ptr;
{
char lbuf[256] ;
jr_int nitems;
while (fgets(lbuf,sizeof(lbuf),rfp)) {
if (strncmp(lbuf,"%%BoundingBox",13) == 0) {
char *tp ;
for (tp=lbuf; *tp ; tp++) {
if (isdigit(*tp) || (*tp == '-')) break ;
}
nitems = sscanf(tp,"%f %f %f %f",
&box_ptr->lower_left_x, &box_ptr->lower_left_y,
&box_ptr->upper_right_x, &box_ptr->upper_right_y
) ;
if (nitems != 4) {
continue;
}
box_ptr->range_x = box_ptr->upper_right_x - box_ptr->lower_left_x ;
box_ptr->range_y = box_ptr->upper_right_y - box_ptr->lower_left_y ;
if (jr_do_trace (jr_graphics)) {
fprintf(stderr,"\t%%%%Bounding Box: %f %f %f %f",
(box_ptr->lower_left_x),
(box_ptr->lower_left_y),
(box_ptr->upper_right_x),
(box_ptr->upper_right_y)) ;
}
rewind(rfp) ;
return 0;
}
}
rewind(rfp) ;
return -1;
}
void jr_PS_TransformInit (
trans_info,
trans_x, trans_y, scale_x, scale_y,
rotation,
justify, vert_space, page_width, margin_width
)
jr_PS_TransformStruct * trans_info;
float trans_x;
float trans_y;
float scale_x;
float scale_y;
float rotation;
jr_int justify;
float vert_space;
float page_width;
float margin_width;
{
memset (trans_info, 0, sizeof (jr_PS_TransformStruct));
trans_info->trans_x = trans_x;
trans_info->trans_y = trans_y;
trans_info->scale_x = scale_x;
trans_info->scale_y = scale_y;
trans_info->rotation = rotation;
trans_info->justify = justify;
trans_info->vert_space = vert_space;
trans_info->page_width = page_width;
trans_info->margin_width = margin_width;
}
void jr_PostScriptPrintTransform (trans_info, box_ptr, wfp, roff_ps_prefix)
jr_PS_TransformStruct * trans_info;
jr_PS_BoundingBoxStruct * box_ptr;
FILE * wfp;
char * roff_ps_prefix;
{
/* SCALE */
fprintf(wfp,"%s/JR_vi { %3.2f } def\n", roff_ps_prefix, trans_info->vert_space) ;
fprintf(wfp,"%s/JR_llx { %3.2f } def\n", roff_ps_prefix, box_ptr->lower_left_x) ;
fprintf(wfp,"%s/JR_lly { %3.2f } def\n", roff_ps_prefix, box_ptr->lower_left_y) ;
fprintf(wfp,"%s/JR_rx { %3.2f } def\n", roff_ps_prefix, box_ptr->range_x) ;
fprintf(wfp,"%s/JR_ry { %3.2f } def\n", roff_ps_prefix, box_ptr->range_y) ;
fprintf(wfp,"%s/JR_CurrY { currentpoint exch pop } def\n", roff_ps_prefix) ;
fprintf(wfp,"%s/JR_CurrX { currentpoint pop } def\n", roff_ps_prefix) ;
fprintf(wfp,"%s/JR_Factor { JR_vi resolution mul JR_ry div } def\n", roff_ps_prefix) ;
fprintf(wfp,"%s/JR_Inch { resolution JR_Factor div } def\n", roff_ps_prefix) ;
fprintf(wfp,"%s/JR_ToOrig { JR_llx neg JR_lly neg translate } def\n", roff_ps_prefix) ;
fprintf(wfp,"%s/JR_ToCurrY { JR_ToOrig 0.0 JR_CurrY translate } def\n", roff_ps_prefix) ;
fprintf(wfp,"%s/JR_ToCurrP { JR_ToOrig JR_CurrX JR_CurrY translate } def\n", roff_ps_prefix) ;
fprintf(wfp,"%s/JR_Left { JR_ToCurrY JR_Inch %3.2f mul 0.0 translate } def\n",
roff_ps_prefix, trans_info->margin_width
);
fprintf(wfp,"%s/JR_Right { JR_ToCurrY JR_Inch %3.2f mul JR_rx sub 0.0 translate } def\n",
roff_ps_prefix, trans_info->page_width - trans_info->margin_width
);
fprintf(wfp,
"%s/JR_Center { JR_ToCurrY JR_Inch %3.2f mul JR_rx sub 2 div 0.0 translate } def\n",
roff_ps_prefix, trans_info->page_width
);
fprintf(wfp,"%s/JR_ToScale { JR_Factor dup neg scale } def\n", roff_ps_prefix) ;
fprintf(wfp,"%sJR_ToScale\n", roff_ps_prefix) ;
switch (trans_info->justify) {
case 'P': {
fprintf(wfp,"%sJR_ToCurrP\n", roff_ps_prefix) ;
break ;
}
case 'R': {
fprintf(wfp,"%sJR_Right\n", roff_ps_prefix) ;
break ;
}
case 'L': {
fprintf(wfp,"%sJR_Left\n", roff_ps_prefix) ;
break ;
}
case 'C':
default : {
fprintf(wfp,"%sJR_Center\n", roff_ps_prefix) ;
break ;
}
}
if ((trans_info->trans_x + trans_info->trans_y) != 0.0) {
fprintf(wfp,"%s%f JR_Inch mul %f JR_Inch mul translate\n",
roff_ps_prefix, trans_info->trans_x, trans_info->trans_y
) ;
}
if ((trans_info->scale_x != 1.0) || (trans_info->scale_y != 1.0)) {
fprintf(wfp,"%s%f %f scale\n",
roff_ps_prefix, trans_info->scale_x, trans_info->scale_y
) ;
}
if (trans_info->rotation != 0.0) {
fprintf(wfp,"%s%f rotate\n",
roff_ps_prefix, trans_info->rotation
) ;
fprintf(wfp,"%s0 %f sin %f mul neg translate\n",
roff_ps_prefix, trans_info->rotation, -box_ptr->range_y
) ;
}
fprintf(wfp,"%scurrentpoint moveto\n", roff_ps_prefix) ;
}
|
frankjas/libjr
|
libjr/misc/exn_brk.c
|
#include "exn_proj.h"
jr_int jr_ExceptionBreakPoint (status)
jr_int status;
{
/*
* This function servers only as a place to
* set a break point in the debugger.
* This function is called every time an exception
* is raised.
* This function should be compiled with the debugger
* option on
*
* If this function returns non-zero the exception
* won't be thrown.
*/
if (jr_do_trace (jr_exceptions)) {
jr_coredump ();
}
return (status);
}
|
frankjas/libjr
|
libjr/struct/net_dbl.c
|
<gh_stars>0
#define _POSIX_SOURCE 1
#include "ezport.h"
#include "jr/nettype.h"
#include "jr/xdr.h"
static XDR DoubleEncodeXDR[1];
static XDR DoubleDecodeXDR[1];
static jr_int DidInit = 0;
static double DoubleEncodeBuf[16];
static double DoubleDecodeBuf[16];
/*
* Only need 1 double, verified in RPC specifications, 8 bytes per double.
* make it 16 to be sure.
*/
#define DoubleXDR_InitIfNecessary() \
( DidInit ? 0 : (DoubleXDR_Init (), DidInit = 1))
static void DoubleXDR_Init ()
{
xdrmem_create (DoubleEncodeXDR, (caddr_t) DoubleEncodeBuf, sizeof (DoubleEncodeBuf), XDR_ENCODE);
xdrmem_create (DoubleDecodeXDR, (caddr_t) DoubleDecodeBuf, sizeof (DoubleDecodeBuf), XDR_DECODE);
/*
* no need to Undo, since xdr_destroy, for mem xdr's is a null op
*/
DidInit = 1;
}
double jr_NetDoubleToHost (net_double)
jr_NetDouble net_double;
{
double tmp_double = net_double.net_double_value;
DoubleXDR_InitIfNecessary ();
DoubleDecodeBuf[0] = net_double.net_double_value;
xdr_setpos (DoubleDecodeXDR, 0);
xdr_double (DoubleDecodeXDR, &tmp_double);
return tmp_double;
}
void jr_NetDoubleAsgnDouble (net_double_ptr, host_value)
jr_NetDouble * net_double_ptr;
double host_value;
{
DoubleXDR_InitIfNecessary ();
xdr_setpos (DoubleEncodeXDR, 0);
xdr_double (DoubleEncodeXDR, &host_value);
net_double_ptr->net_double_value = DoubleEncodeBuf[0];
}
|
frankjas/libjr
|
libjr/syscalls/termctrl.c
|
#include "ezport.h"
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "jr/syscalls.h"
#include "jr/error.h"
jr_int jr_SetTerminalMode (fd, mode_constant, turn_on_mode, error_buf)
jr_int fd;
jr_int mode_constant ;
jr_int turn_on_mode ;
char * error_buf;
{
struct termios tty_info [1];
jr_int status;
status = tcgetattr (fd, tty_info);
if (status != 0) {
jr_esprintf (error_buf, "couldn't get input attributes: %s", strerror (errno));
status = -1;
goto return_status;
}
switch (mode_constant) {
case jr_CBREAK_MODE : {
if (turn_on_mode) {
tty_info->c_lflag &= ~ICANON;
}
else {
tty_info->c_lflag |= ICANON; /* enable line buffering, ctl char processing */
}
break;
}
default : {
jr_esprintf (error_buf, "unrecognized mode constant %d", mode_constant);
status = -1;
goto return_status;
}
}
status = tcsetattr (fd, TCSANOW, tty_info);
if (status != 0) {
jr_esprintf (error_buf, "couldn't set input attributes: %s", strerror (errno));
status = -1;
goto return_status;
}
status = 0;
return_status : {
}
return status;
}
#ifdef use_old_BSD_tty_functions
#include <sgtty.h>
#include <signal.h>
#include <sys/ioctl.h>
/*
* Should rewrite this using POSIX tc functions
*/
void jr_SetEchoMode(b)
jr_int b ;
{
struct sgttyb otty ;
ioctl(0,TIOCGETP,&otty) ;
if (b) otty.sg_flags |= ECHO ;
else otty.sg_flags &= ~ECHO ;
ioctl(0,TIOCSETP,&otty) ;
}
void jr_SetRawNoEchoMode(b)
jr_int b ;
{
struct sgttyb otty ;
ioctl(0,TIOCGETP,&otty) ;
if (b) {
otty.sg_flags |= CBREAK ;
otty.sg_flags |= RAW ;
otty.sg_flags &= ~ECHO ;
}
else {
otty.sg_flags &= ~CBREAK ;
otty.sg_flags &= ~RAW ;
otty.sg_flags |= ECHO ;
}
ioctl(0,TIOCSETP,&otty) ;
}
void jr_SetRawMode(b)
jr_int b ;
{
struct sgttyb otty ;
ioctl(0,TIOCGETP,&otty) ;
if (b) {
otty.sg_flags |= CBREAK ;
otty.sg_flags |= RAW ;
}
else {
otty.sg_flags &= ~CBREAK ;
otty.sg_flags &= ~RAW ;
}
ioctl(0,TIOCSETP,&otty) ;
}
void jr_SetCbreakMode(b)
jr_int b ;
{
struct sgttyb otty ;
ioctl(0,TIOCGETP,&otty) ;
if (b) otty.sg_flags |= CBREAK ;
else otty.sg_flags &= ~CBREAK ;
ioctl(0,TIOCSETP,&otty) ;
}
void jr_SetEraseAndKillDefaults()
{
struct sgttyb otty ;
ioctl(0,TIOCGETP,&otty) ;
otty.sg_erase = '\010' ; /* erase character == ^H */
otty.sg_kill = '\030' ; /* cancel character == ^X */
ioctl(0,TIOCSETP,&otty) ;
}
#endif
|
frankjas/libjr
|
libjr/misc/pfx_lib.c
|
<filename>libjr/misc/pfx_lib.c<gh_stars>0
#include "pfx_proj.h"
void jr_SetContainers (
char * container_name,
void * container_ptr,
...)
{
va_list arg_list;
jr_PrefixInfoType * prefix_array;
jr_PrefixInfoType prefix_info [1];
jr_int prefix_size;
va_start (arg_list, container_ptr);
jr_PrefixInfoInit (prefix_info, container_name, container_ptr);
if (jr_PrefixInfoNeedsTransformFn (prefix_info)) {
fprintf (stderr,
"jr_SetContainers(): can't set prefixes for type '%s', use %sSetContainers()\n",
container_name,
container_name
);
abort ();
}
prefix_array = jr_PrefixArrayCreateFromVA_List (arg_list, 0);
prefix_size = jr_PrefixArrayInitPrefixes (prefix_array);
jr_PrefixInfoSetPrefixSize (prefix_info, prefix_size);
jr_PrefixInfoInitPrefix (prefix_info);
jr_PrefixInfoUndo (prefix_info);
jr_PrefixArrayDestroy (prefix_array);
}
jr_PrefixInfoType * jr_PrefixArrayCreateFromVA_List (arg_list, needs_transform_fn)
va_list arg_list;
jr_int needs_transform_fn;
{
jr_AList prefix_list[1];
jr_PrefixInfoType * prefix_info;
char * container_name;
void * container_ptr;
jr_int prefix_size;
jr_int element_prefix_size;
jr_AListInit (prefix_list, sizeof (jr_PrefixInfoType));
for ( container_name = va_arg (arg_list, char *);
container_name != 0;
container_name = va_arg (arg_list, char *)
) {
container_ptr = va_arg (arg_list, void *);
prefix_info = jr_AListNewTailPtr (prefix_list);
jr_PrefixInfoInit (prefix_info, container_name, container_ptr);
if (needs_transform_fn && jr_PrefixInfoTransformFn (prefix_info) == 0) {
fprintf (stderr,
"jr_PrefixInfoInit(): type '%s' cannot be used in this parent container.\n",
container_name
);
abort ();
}
}
prefix_size = 0;
jr_AListForEachElementPtrRev (prefix_list, prefix_info) {
element_prefix_size = jr_PrefixInfoElementPrefixSize (prefix_info);
if (element_prefix_size == 0) {
/*
* use the custom prefix size stored in the prefix_size field
*/
element_prefix_size = jr_PrefixInfoPrefixSize (prefix_info);
}
jr_PrefixInfoSetPrefixSize (prefix_info, prefix_size);
prefix_size += element_prefix_size;
}
prefix_info = jr_AListNewTailPtr (prefix_list);
prefix_info->container_name = 0;
prefix_info->prefix_size = prefix_size;
/*
* store the total prefix size in the null elements prefix_size field
*/
prefix_info = jr_AListBufferDup (prefix_list);
jr_AListUndo (prefix_list);
return prefix_info;
}
void jr_PrefixArrayDestroy (prefix_array)
jr_PrefixInfoType * prefix_array;
{
jr_PrefixInfoType * prefix_info;
jr_PrefixArrayForEachInfoPtr (prefix_array, prefix_info) {
jr_PrefixInfoUndo (prefix_info);
}
jr_free (prefix_array);
}
jr_int jr_PrefixArrayInitPrefixes (prefix_array)
jr_PrefixInfoType * prefix_array;
{
jr_PrefixInfoType * prefix_info;
jr_PrefixArrayForEachInfoPtr (prefix_array, prefix_info) {
jr_PrefixInfoInitPrefix (prefix_info);
}
/*
* the total prefix size of the array is stored in the null element's
* prefix_size field
*/
return jr_PrefixInfoPrefixSize (prefix_info);
}
void jr_PrefixInfoInit (prefix_info, container_name, container_ptr)
jr_PrefixInfoType * prefix_info;
char * container_name;
void * container_ptr;
{
jr_PrefixInfoType * static_prefix_info;
memset (prefix_info, 0, sizeof (jr_PrefixInfoType));
prefix_info->container_name = jr_strdup (container_name);
prefix_info->container_ptr = container_ptr;
prefix_info->prefix_size = 0;
jr_PrefixArrayForEachInfoPtr (jr_PrefixInfoArray, static_prefix_info) {
if (strcmp (container_name, static_prefix_info->container_name) == 0) {
prefix_info->prefix_id = static_prefix_info->prefix_id;
prefix_info->prefix_transform_fn = static_prefix_info->prefix_transform_fn;
prefix_info->needs_transform_fn = static_prefix_info->needs_transform_fn;
return;
}
}
fprintf (stderr, "jr_PrefixInfoInit(): can't use '%s' in this way. Use %sSetContainers()\n",
container_name,
container_name
);
abort ();
}
void jr_PrefixInfoUndo (prefix_info)
jr_PrefixInfoType * prefix_info;
{
jr_free (prefix_info->container_name);
}
void jr_PrefixInfoInitPrefix (prefix_info)
jr_PrefixInfoType * prefix_info;
{
void (*set_prefix_size_fn) ();
if (prefix_info->container_ptr == 0) {
return;
}
set_prefix_size_fn = jr_PrefixInfoArray [prefix_info->prefix_id].set_prefix_size_fn;
if (set_prefix_size_fn == 0) {
fprintf (stderr,
"jr_PrefixInfoSetPrefixSize(): container type '%s' can't set the prefix size\n",
jr_PrefixInfoArray [prefix_info->prefix_id].container_name
);
abort ();
}
(*set_prefix_size_fn) (prefix_info->container_ptr, prefix_info->prefix_size);
}
jr_int jr_PrefixInfoElementPrefixSize (prefix_info)
jr_PrefixInfoType * prefix_info;
{
jr_int (*element_prefix_size_fn) ();
jr_PrefixInfoType * static_prefix_info;
static_prefix_info = jr_PrefixInfoArray + prefix_info->prefix_id;
element_prefix_size_fn = static_prefix_info->element_prefix_size_fn;
return (*element_prefix_size_fn) (prefix_info->container_ptr);
}
void jr_PrefixArrayTransformElement (prefix_array, el_ptr, magnitude, which_way, all_elements)
jr_PrefixInfoType * prefix_array;
void * el_ptr;
unsigned jr_int magnitude;
jr_int which_way;
jr_int all_elements;
{
jr_PrefixInfoType * prefix_info;
jr_PrefixArrayForEachInfoPtr (prefix_array, prefix_info) {
if ( jr_PrefixInfoContainerPtr (prefix_info)
&& jr_PrefixInfoTransformFn (prefix_info)) {
(*jr_PrefixInfoTransformFn (prefix_info)) (
jr_PrefixInfoContainerPtr (prefix_info),
el_ptr, magnitude, which_way, all_elements
);
}
}
}
#ifdef links_on_unresolved_functions_only
void jr_PrefixDummyLinkFn()
{
jr_PrefixAddContainerType ("dummy_name", 0, 0, 0, 0);
}
#endif
|
frankjas/libjr
|
libjr/struct/intset.c
|
<gh_stars>0
#include "ezport.h"
#include "jr/intset.h"
#include "jr/malloc.h"
/*
Author: <NAME>
Date: Febuary 17, 1987
*/
jr_IntSet *jr_IntSetCreate ()
{
jr_IntSet *iset = jr_malloc (sizeof (jr_IntSet));
jr_IntSetInit (iset);
return (iset);
}
void jr_IntSetInit (iset)
jr_IntSet *iset;
{
iset->array = 0;
iset->next_index = 0;
iset->max_size = 0;
}
void jr_IntSetDestroy (iset)
jr_IntSet *iset;
{
if (iset->array) jr_free (iset->array);
jr_free (iset);
}
void jr_IntSetUndo (iset)
jr_IntSet *iset;
{
if (iset->array) jr_free (iset->array);
}
void jr_IntSetIncreaseSize (iset, minelements)
jr_IntSet * iset;
jr_int minelements;
{
jr_int new_bytes;
if (minelements < iset->max_size) return;
if (minelements < 2 * iset->max_size) {
minelements = 2 * iset->max_size;
}
new_bytes = minelements * sizeof (jr_int);
if (iset->array) {
iset->array = jr_realloc (iset->array, new_bytes);
}
else {
iset->array = jr_malloc (new_bytes);
}
iset->max_size = (jr_int) jr_malloc_usable_size (iset->array, new_bytes) / sizeof(jr_int);
iset->max_size = minelements;
}
int jr_IntSetFind (iset, n)
jr_IntSet *iset;
jr_int n;
{
jr_int i = jr_IntSetFindIndex(iset, n);
if (i == jr_IntSetSize(iset)) return (0);
if (jr_IntSetElement(iset, i) == n) return (1);
return (0);
}
int jr_IntSetCmp (iseta, isetb)
jr_IntSet *iseta, *isetb;
{
jr_int i;
for (i=0; i < jr_IntSetSize(iseta); i++) {
if (iseta->array[i] != isetb->array[i]) return (1);
}
if (i == jr_IntSetSize(isetb)) return (0);
return (1);
}
void jr_IntSetAddMax (iset, n)
jr_IntSet *iset;
jr_int n;
{
if (iset->next_index == iset->max_size) {
/* the number of elements in it equals the maximum number */
jr_IntSetIncreaseSize (iset, iset->max_size + 1);
}
jr_IntSetElement(iset, iset->next_index) = n;
iset->next_index ++;
}
void jr_IntSetAdd (iset, n)
jr_IntSet *iset;
jr_int n;
{
jr_int j, i = jr_IntSetFindIndex (iset, n);
if (i == jr_IntSetSize(iset)) {
jr_IntSetAddMax (iset, n);
return;
}
if (jr_IntSetElement(iset, i) == n) return;
/* if its already there, do nothing */
/* make space for the element */
if (iset->next_index == iset->max_size) {
/* the number of elements in iset equals the maximum number */
jr_IntSetIncreaseSize (iset, iset->max_size + 1);
}
for (j=iset->next_index - 1; j >= i; j--) {
jr_IntSetElement(iset, j+1) = jr_IntSetElement(iset, j);
}
jr_IntSetElement(iset, i) = n;
iset->next_index ++;
}
void jr_IntSetDelete (iset, n)
jr_IntSet *iset;
jr_int n;
{
jr_int i = jr_IntSetFindIndex (iset, n);
if (i == jr_IntSetSize(iset)) return ;
if (jr_IntSetElement(iset, i) != n) return;
/* if it's not there, do nothing */
for (; i < iset->next_index - 1; i++) {
jr_IntSetElement(iset, i) = jr_IntSetElement(iset, i+1);
}
iset->next_index--;
}
int jr_IntSetFindIndex (iset, n)
jr_IntSet *iset;
jr_int n;
/*
high is either off the end, or mid
from the last iteration. This means
high shouldn't be the comparison key.
So if low and high are 0 apart, mid gets low.
*/
{
jr_int mid, low, high;
register jr_int *array = jr_IntSetArray(iset);
/* do binary search */
low = 0;
high = jr_IntSetSize(iset);
while (low != high) {
mid = low + (high - low)/2;
if (n < array[mid]) high = mid;
else if (n > array[mid]) low = mid + 1;
else {
/* found match */
return (mid);
}
}
return (low);
}
void jr_IntSetAddSet (iseta, isetb)
jr_IntSet *iseta, *isetb;
{
jr_IntSet *isetc = jr_IntSetCreate ();
jr_IntSetUnion (isetc, iseta, isetb);
jr_free (iseta->array);
iseta->array = isetc->array;
iseta->next_index = isetc->next_index;
iseta->max_size = isetc->max_size;
jr_free (isetc);
}
void jr_IntSetUnion (isetc, iseta, isetb)
jr_IntSet *iseta, *isetb, *isetc;
{
jr_int a, b, comp;
jr_int size_a, size_b;
jr_IntSetEmpty(isetc);
a = b = 0;
size_a = jr_IntSetSize(iseta);
size_b = jr_IntSetSize(isetb);
while (a < size_a && b < size_b) {
comp = iseta->array[a] - isetb->array[b];
if (comp < 0) {
jr_IntSetAddMax (isetc, iseta->array[a]);
a++;
}
else if (comp > 0) {
jr_IntSetAddMax (isetc, isetb->array[b]);
b++;
}
else {
jr_IntSetAddMax (isetc, iseta->array[a]);
a++;
b++;
}
}
if (a == size_a) {
for (; b < size_b; b++) {
jr_IntSetAddMax (isetc, isetb->array[b]);
}
}
else if (b == size_b) {
for (; a < size_a; a++) {
jr_IntSetAddMax (isetc, iseta->array[a]);
}
}
}
void jr_IntSetIntersection (isetc, iseta, isetb)
jr_IntSet *iseta, *isetb, *isetc;
{
jr_int a, b;
jr_IntSetEmpty(isetc);
a = b = 0;
while (a < jr_IntSetSize(iseta) && b < jr_IntSetSize(isetb)) {
if (iseta->array[a] < isetb->array[b]) a++;
else if (iseta->array[a] > isetb->array[b]) b++;
else { /* they're equal */
jr_IntSetAddMax (isetc, iseta->array[a++]);
b++;
}
}
}
#ifdef INT_STRING_CONVERSIONS
int *jr_IntSetToIntStr (iset)
jr_IntSet *iset;
{
jr_int *tp;
jr_IntSetAddMax (iset, jr_INT_NULL);
tp = jr_memdup (jr_IntSetArray(iset), iset->next_index * sizeof(jr_int));
iset->next_index --;
/* delete the intnull from it */
return (tp);
}
jr_IntSet *jr_IntSetCreateFromIntStr (ia)
jr_int *ia;
{
jr_IntSet *iset = jr_IntSetCreate ();
jr_int min, last, i, next, size, *tp;
for (size=0; ia[size] != jr_INT_NULL; size++);
tp = (jr_int *) jr_malloc (size * sizeof(jr_int));
for (i=0; i < size; i++) tp[i] = ia[i];
ia = tp;
/* make a copy of the ia. Could sort into tp, but
would take approx. (n^2)/2 times longer, since that
would be n^2 and selection is (n^2)/2 */
next = 0;
while (next < size) {
min = next;
for (i = min+1; i < size; i++) {
if (ia[i] < ia[min]) min = i;
}
if (next == 0 || ia[min] > ia[next-1]) {
/* if there are duplicates then we only add min if
it is greater than the last one added */
i = ia[next];
ia[next] = ia[min];
next++;
}
else { /* min is a duplicate */
size--;
i = ia[size];
ia[size] = ia[min];
/* put min in the end slot, this discards it
since size is deccremented */
}
ia[min] = i;
}
jr_IntSetIncreaseSize (iset, next);
for (i=0; i < next; i++) jr_IntSetElement(iset, i) = ia[i];
iset->next_index = next;
jr_free(tp) ;
return (iset);
}
#endif
|
frankjas/libjr
|
libjr/string/isdigits.c
|
<filename>libjr/string/isdigits.c
#include "ezport.h"
#include <stdio.h>
#include <ctype.h>
#include "jr/string.h"
jr_int jr_StringIsAllDigits(str)
const char *str ;
{
jr_int retval = 0 ;
for (; *str; str++) {
if (! isdigit(*str)) return(0) ;
else retval++ ;
}
return(retval) ;
}
/*
void main()
{
char string[128] ;
jr_int value ;
strcpy(string, "1234t") ;
value = jr_StringIsAllDigits(string) ;
fprintf(stdout, "jr_StringIsAllDigits('%s') == %d\n",
string,
value
) ;
strcpy(string, "234") ;
value = jr_StringIsAllDigits(string) ;
fprintf(stdout, "jr_StringIsAllDigits('%s') == %d\n",
string,
value
) ;
}
*/
|
frankjas/libjr
|
libjr/misc/esis_typ.c
|
#include "esis_prj.h"
void jr_ESIS_TreeInit (tree_info, attr_manager)
jr_ESIS_TreeType * tree_info;
jr_AttributeManagerType * attr_manager;
{
tree_info->attr_manager = attr_manager;
jr_HTableInit (
tree_info->generic_element_table, sizeof (jr_ESIS_GenericElementType),
jr_ESIS_GenericElementHash, jr_ESIS_GenericElementCmp
);
jr_ESIS_GlobalElementListInit (tree_info->element_list);
jr_ESIS_ElementStackInit (tree_info->element_stack);
jr_ESIS_ElementStackPush (tree_info->element_stack, 0);
}
void jr_ESIS_TreeUndo (tree_info)
jr_ESIS_TreeType * tree_info;
{
jr_ESIS_GenericElementType *generic_info;
jr_ESIS_ElementType * element_ptr;
jr_HTableForEachElementPtr (tree_info->generic_element_table, generic_info) {
jr_ESIS_GenericElementUndo (generic_info);
}
jr_HTableUndo (tree_info->generic_element_table);
jr_ESIS_ElementStackUndo (tree_info->element_stack);
jr_ForEachESIS_ElementListPtr (tree_info->element_list, element_ptr) {
jr_ESIS_ElementUndo (element_ptr);
}
jr_ESIS_ElementListUndo (tree_info->element_list);
}
jr_ESIS_ElementType *jr_ESIS_TreeNewElementPtr (tree_info, parent_element_ptr)
jr_ESIS_TreeType * tree_info;
jr_ESIS_ElementType * parent_element_ptr;
{
jr_ESIS_ElementType * element_ptr;
element_ptr = jr_ESIS_ElementListNewElementPtr (tree_info->element_list);
jr_ESIS_ElementInit (element_ptr, tree_info, parent_element_ptr);
if (parent_element_ptr) {
jr_ESIS_ElementAddSubElement (parent_element_ptr, element_ptr);
}
return element_ptr;
}
void jr_ESIS_GenericElementInit (generic_info, name_str)
jr_ESIS_GenericElementType * generic_info;
char * name_str;
{
generic_info->name_str = jr_strdup (name_str);
jr_ESIS_GenericElementListInit (generic_info->element_list);
}
void jr_ESIS_GenericElementUndo (generic_info)
jr_ESIS_GenericElementType * generic_info;
{
jr_free (generic_info->name_str);
jr_ESIS_ElementListUndo (generic_info->element_list);
}
jr_int jr_ESIS_GenericElementHash (void_arg_1)
const void * void_arg_1;
{
const jr_ESIS_GenericElementType * generic_info = void_arg_1;
jr_int hash_value = 0;
hash_value += jr_strhash_pjw (generic_info->name_str);
return hash_value;
}
jr_int jr_ESIS_GenericElementCmp (void_arg_1, void_arg_2)
const void * void_arg_1;
const void * void_arg_2;
{
const jr_ESIS_GenericElementType * generic_info_1 = void_arg_1;
const jr_ESIS_GenericElementType * generic_info_2 = void_arg_2;
jr_int diff;
diff = strcmp (generic_info_1->name_str, generic_info_2->name_str);
if (diff != 0) {
return diff;
}
return 0;
}
void jr_ESIS_ElementInit (element_ptr, tree_info, parent_element_ptr)
jr_ESIS_ElementType * element_ptr;
jr_ESIS_TreeType * tree_info;
jr_ESIS_ElementType * parent_element_ptr;
{
jr_AttributeListInit (element_ptr->attr_list, tree_info->attr_manager);
jr_ESIS_SubElementListInit (element_ptr->sub_element_list);
element_ptr->parent_element_ptr = parent_element_ptr;
jr_AListInit (element_ptr->data_list, sizeof (char *));
}
void jr_ESIS_ElementUndo (element_ptr)
jr_ESIS_ElementType * element_ptr;
{
jr_int i;
jr_AttributeListUndo (element_ptr->attr_list);
jr_ESIS_ElementListUndo (element_ptr->sub_element_list);
jr_AListForEachElementIndex (element_ptr->data_list, i) {
jr_free (jr_AListNativeElement (element_ptr->data_list, i, char *));
}
jr_AListUndo (element_ptr->data_list);
}
void jr_ESIS_ElementSetData (element_ptr, data_str)
jr_ESIS_ElementType * element_ptr;
char * data_str;
{
char * new_data_str = jr_strdup (data_str);
jr_AListNativeSetNewTail (element_ptr->data_list, new_data_str, char *);
}
void jr_ESIS_ElementAddAttribute (element_ptr, attr_name_str, attr_value_str)
jr_ESIS_ElementType * element_ptr;
char * attr_name_str;
char * attr_value_str;
{
if (attr_value_str) {
jr_AttributeListAddAttribute (element_ptr->attr_list, attr_name_str, attr_value_str);
}
}
void jr_ESIS_ElementAddSubElement (parent_element_ptr, element_ptr)
jr_ESIS_ElementType * parent_element_ptr;
jr_ESIS_ElementType * element_ptr;
{
jr_ESIS_ElementListAppendToTail (parent_element_ptr->sub_element_list, element_ptr);
}
void jr_ESIS_IndexInit (esis_index, attr_name_str, opt_generic_name_str)
jr_ESIS_IndexType * esis_index;
char * attr_name_str;
char * opt_generic_name_str;
{
esis_index->attr_name_str = jr_strdup (attr_name_str);
if (opt_generic_name_str) {
esis_index->opt_generic_name_str = jr_strdup (opt_generic_name_str);
}
jr_HTableInit (
esis_index->attr_value_table, sizeof (jr_ESIS_IndexValueType),
jr_ESIS_IndexValueHash, jr_ESIS_IndexValueCmp
);
}
void jr_ESIS_IndexUndo (esis_index)
jr_ESIS_IndexType * esis_index;
{
jr_ESIS_IndexValueType * esis_index_value;
jr_free (esis_index->attr_name_str);
if (esis_index->opt_generic_name_str) {
jr_free (esis_index->opt_generic_name_str);
}
jr_HTableForEachElementPtr (esis_index->attr_value_table, esis_index_value) {
jr_ESIS_IndexValueUndo (esis_index_value);
}
jr_HTableUndo (esis_index->attr_value_table);
}
void jr_ESIS_IndexValueInit (esis_index_value, attr_value_str)
jr_ESIS_IndexValueType * esis_index_value;
char * attr_value_str;
{
esis_index_value->attr_value_str = jr_strdup (attr_value_str);
jr_ESIS_MatchingElementListInit (esis_index_value->matching_element_list);
}
void jr_ESIS_IndexValueUndo (esis_index_value)
jr_ESIS_IndexValueType * esis_index_value;
{
jr_free (esis_index_value->attr_value_str);
jr_ESIS_ElementListUndo (esis_index_value->matching_element_list);
}
jr_int jr_ESIS_IndexValueHash (void_arg_1)
const void * void_arg_1;
{
const jr_ESIS_IndexValueType * esis_index_value = void_arg_1;
jr_int hash_value = 0;
hash_value += jr_strhash_pjw (esis_index_value->attr_value_str);
return hash_value;
}
jr_int jr_ESIS_IndexValueCmp (void_arg_1, void_arg_2)
const void * void_arg_1;
const void * void_arg_2;
{
const jr_ESIS_IndexValueType * esis_index_value_1 = void_arg_1;
const jr_ESIS_IndexValueType * esis_index_value_2 = void_arg_2;
jr_int diff;
diff = strcmp (esis_index_value_1->attr_value_str, esis_index_value_2->attr_value_str);
if (diff != 0) {
return diff;
}
return 0;
}
void jr_ESIS_ElementListInit (element_list)
jr_ESIS_ElementList * element_list;
{
jr_LListInit (element_list->data_list, sizeof (jr_ESIS_ElementType));
}
void jr_ESIS_ElementListUndo (element_list)
jr_ESIS_ElementList * element_list;
{
jr_LListUndo (element_list->data_list);
}
jr_ESIS_ElementType *jr_ESIS_ElementListNewElementPtr (element_list)
jr_ESIS_ElementList * element_list;
{
jr_ESIS_ElementType * element_ptr;
element_ptr = jr_LListNewTailPtr (element_list->data_list);
return element_ptr;
}
void jr_ESIS_GlobalElementListInit (element_list)
jr_ESIS_ElementList * element_list;
{
jr_ESIS_ElementListInit (element_list);
jr_SetContainers (
/* global list */ "jr_LList", 0,
/* generic list */ "jr_LList", 0,
/* sub element */ "jr_LList", 0,
/* matching */ "jr_LList", 0,
0
);
}
void jr_ESIS_GenericElementListInit (element_list)
jr_ESIS_ElementList * element_list;
{
jr_ESIS_ElementListInit (element_list);
jr_SetContainers (
/* global list */ "jr_LList", 0,
/* generic list */ "jr_LList", element_list->data_list,
/* sub element */ "jr_LList", 0,
/* matching */ "jr_LList", 0,
0
);
}
void jr_ESIS_SubElementListInit (element_list)
jr_ESIS_ElementList * element_list;
{
jr_ESIS_ElementListInit (element_list);
jr_SetContainers (
/* global list */ "jr_LList", 0,
/* generic list */ "jr_LList", 0,
/* sub element */ "jr_LList", element_list->data_list,
/* matching */ "jr_LList", 0,
0
);
}
void jr_ESIS_MatchingElementListInit (element_list)
jr_ESIS_ElementList * element_list;
{
jr_ESIS_ElementListInit (element_list);
jr_SetContainers (
/* global list */ "jr_LList", 0,
/* generic list */ "jr_LList", 0,
/* sub element */ "jr_LList", 0,
/* matching */ "jr_LList", element_list->data_list,
0
);
}
void jr_ESIS_ElementStackInit (element_stack)
jr_ESIS_ElementStack * element_stack;
{
jr_AListInit (element_stack->data_list, sizeof (jr_ESIS_ElementType *));
}
void jr_ESIS_ElementStackUndo (element_stack)
jr_ESIS_ElementStack * element_stack;
{
jr_AListUndo (element_stack->data_list);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.