| |
| #define LITEX_INTEGRATION |
|
|
| |
| #define CCOMPILE |
|
|
| |
| #include "compiler.h" |
| #include "uintN_t.h" |
| #include "intN_t.h" |
| #include "float_e_m_t_helper.h" |
|
|
| |
| |
| #include "pipelinec_app_config.h" |
|
|
| #include "pipelinec_compat.h" |
| #include "fixed_type.h" |
|
|
| |
| |
| #pragma FUNC_WIRES reset_state |
| #pragma FUNC_WIRES reset_state0 |
|
|
| |
| #include "buttons/buttons.c" |
|
|
| |
| #if COLOR_DECOMP == 3 |
| #define PIXEL_OVER_CLK_RATIO 3 |
| #endif |
|
|
| |
| |
| #ifdef LITEX_INTEGRATION |
| #include "vga/external_vga_timing.c" |
| #include "vga/external_vga_output.c" |
| #elif defined(POCKET_INTEGRATION) |
| |
| |
| #include "vga/external_vga_output.c" |
| #else |
| |
| |
| #include "dvi/dvi_pmod.c" |
| #endif |
|
|
| |
| #define get_scene() state.scene |
| #include "tr_pipelinec.gen.c" |
|
|
| |
| #define FRAME_CLK_MHZ 6e-5 |
| uint1_t frame_clock; |
| DECL_OUTPUT(uint1_t, frame_clock) |
| uint1_t frame_clock_rising_edge; |
| uint1_t frame_clock_falling_edge; |
| |
| |
| void frame_clock_logic(uint16_t x, uint16_t y, bool active) |
| { |
| |
| static uint1_t frame_clock_reg; |
| |
| frame_clock = frame_clock_reg; |
| frame_clock_rising_edge = 0; |
| frame_clock_falling_edge = 0; |
|
|
| |
| if( active & |
| (x==(FRAME_WIDTH/2)) & |
| (y==(FRAME_HEIGHT/2)) |
| ){ |
| frame_clock_reg = 0; |
| frame_clock_falling_edge = 1; |
| } |
| |
| else if(active & |
| (x==(FRAME_WIDTH-1)) & |
| (y==(FRAME_HEIGHT-1)) |
| ){ |
| frame_clock_reg = 1; |
| frame_clock_rising_edge = 1; |
| } |
| } |
|
|
| |
| |
| |
| |
| #ifndef POCKET_INTEGRATION |
| CLK_MHZ(frame_clock, FRAME_CLK_MHZ) |
|
|
| |
| |
| |
| uint1_t pixel_clock; |
| CLK_MHZ(pixel_clock, PIXEL_CLK_MHZ) |
| |
| MAIN_MHZ(pixel, PIXEL_CLK_MHZ) |
| #pragma FUNC_WIRES pixel |
| void pixel(uint1_t clock) |
| { |
| pixel_clock = clock; |
| } |
| #endif |
|
|
| |
| |
| #define UART_CLK_MHZ PIXEL_CLK_MHZ |
| #include "uart/uart_mac.c" |
| |
| |
| uint4_t uart_buttons; |
| MAIN_MHZ(uart_buttons_rx, UART_CLK_MHZ) |
| void uart_buttons_rx() |
| { |
| static uint4_t uart_buttons_reg; |
| uart_buttons = uart_buttons_reg; |
| |
| uart_rx_mac_out_ready = 1; |
| |
| if(uart_rx_mac_word_out.valid) |
| { |
| uart_buttons_reg = uart_rx_mac_word_out.data; |
| } |
| } |
| |
| |
| uint4_t buttons_or_uart; |
| #pragma ASYNC_WIRE buttons_or_uart |
| |
| MAIN_MHZ(uart_buttons_tx, UART_CLK_MHZ) |
| void uart_buttons_tx() |
| { |
| static uint4_t buttons_or_uart_reg; |
| buttons_or_uart = buttons_or_uart_reg; |
| |
| |
| uart_tx_mac_word_in.valid = frame_clock_rising_edge; |
| uart_tx_mac_word_in.data = buttons_or_uart_reg; |
| |
| |
| |
| |
| if(frame_clock_falling_edge) |
| { |
| |
| |
| buttons_or_uart_reg = buttons | uart_buttons; |
| } |
| } |
|
|
| |
| typedef struct user_input_t |
| { |
| uint1_t jump_pressed; |
| uint1_t reset_pressed; |
| }user_input_t; |
| inline user_input_t get_user_input() |
| { |
| user_input_t i; |
| |
| #ifdef __PIPELINEC__ |
| |
| i.jump_pressed = buttons_or_uart >> 0; |
| i.reset_pressed = buttons_or_uart >> 3; |
| #else |
| |
| i.jump_pressed = 1; |
| i.reset_pressed = 0; |
| #endif |
| return i; |
| } |
|
|
| |
| volatile full_state_t state; |
| #pragma ASYNC_WIRE state |
| MAIN_MHZ(frame_logic, FRAME_CLK_MHZ) |
| void frame_logic() |
| { |
| static uint1_t power_on_reset = 1; |
| static full_state_t state_reg; |
| state = state_reg; |
|
|
| |
| user_input_t ui = get_user_input(); |
|
|
| |
| state_reg = full_update(state_reg, ui.reset_pressed | power_on_reset, ui.jump_pressed); |
| power_on_reset = 0; |
| } |
|
|
| |
| typedef struct color_decomp_rgb_buffer_t{ |
| vga_signals_t vga_signals; |
| pixel_t pixel; |
| }color_decomp_rgb_buffer_t; |
| color_decomp_rgb_buffer_t color_decomp_rgb_buffer( |
| uint8_t current_color_channel, uint8_t color_value, |
| vga_signals_t vga_signals |
| ){ |
| color_decomp_rgb_buffer_t o; |
| static pixel_t pixel_reg; |
| o.pixel = pixel_reg; |
| static vga_signals_t vga_signals_reg; |
| o.vga_signals = vga_signals_reg; |
|
|
| |
| vga_signals_reg = vga_signals; |
| |
| |
| if(current_color_channel==0){ |
| pixel_reg.r = color_value; |
| }else if(current_color_channel==1){ |
| pixel_reg.g = color_value; |
| }else{ |
| pixel_reg.b = color_value; |
| } |
|
|
| return o; |
| } |
|
|
| |
| MAIN_MHZ(pixel_logic, PIXEL_CLK_MHZ) |
| void pixel_logic() |
| { |
| |
| vga_signals_t vga_signals = vga_timing(); |
|
|
| |
| frame_clock_logic(vga_signals.pos.x, vga_signals.pos.y, vga_signals.active & vga_signals.valid); |
|
|
| #ifndef COLOR_DECOMP |
| |
| |
| pixel_t color = render_pixel(vga_signals.pos.x, vga_signals.pos.y); |
| #else |
| #if COLOR_DECOMP == 1 |
| pixel_t color; |
| color = render_pixel(vga_signals.pos.x, vga_signals.pos.y, 0); |
| color.g = color.r; |
| color.b = color.r; |
| #else |
| |
| uint8_t current_color_channel = vga_signals.overclock_counter; |
| pixel_t color = render_pixel(vga_signals.pos.x, vga_signals.pos.y, current_color_channel); |
| |
| color_decomp_rgb_buffer_t rgb_buf = color_decomp_rgb_buffer( |
| current_color_channel, color.r, |
| vga_signals |
| ); |
| vga_signals = rgb_buf.vga_signals; |
| color = rgb_buf.pixel; |
| #endif |
| #endif |
|
|
| |
| pmod_register_outputs(vga_signals, color); |
| } |
|
|
| #include "opt_primitives.c" |
| #include "fp_overloads.c" |
|
|
|
|