Skip to content

Instantly share code, notes, and snippets.

View fl4shk's full-sized avatar

Andrew Clark fl4shk

  • Missouri, United States
View GitHub Profile
@fl4shk
fl4shk / systemverilog_nonrestoring_divider.sv
Last active October 15, 2017 17:15
Example of Non-Restoring Unsigned or Signed Integer Division in SystemVerilog (compatible with Icarus Verilog's SystemVerilog support, and tested with my Altera Cyclone IV FPGA)
`define WIDTH_TO_MSB_POS(width) ((width) - 1)
// Unsigned (or signed!) integer division
// Don't try to do larger than a 128-bit division with this without
// increasing counter_msb_pos.
// Depending on the FPGA being used and the clock rate, it may be doable to
// perform more than one iterate() per cycle, obtaining faster divisions.
@fl4shk
fl4shk / enum_to_constructor_test_with_x_macros.cpp
Last active April 12, 2017 16:27
C++ templates can be used in a nice way for factory stuff
#include <iostream>
using std::cout;
using std::cin;
using std::cerr;
using std::endl;
// Pass the name of some other macro to list_of_sprite_classes()
#define list_of_sprite_classes(other_macro) \
void sprite::copy_the_oam_entry_to_oam_mirror ( u32 slot_for_oam_mirror )
{
//oam_mirror [slot_for_oam_mirror].attr0 = the_oam_entry.attr0;
//oam_mirror [slot_for_oam_mirror].attr1 = the_oam_entry.attr1;
//oam_mirror [slot_for_oam_mirror].attr2 = the_oam_entry.attr2;
//u32 output;
//asm __volatile__
//(
// "mov r0, %1\n\t"
void player_sprite_stuff::handle_jumping_stuff ( sprite& the_player,
u32 is_jump_key_hit, u32 is_jump_key_held )
{
if ( the_player.on_ground && is_jump_key_hit )
{
the_player.vel.y = jump_vel;
the_player.jump_hold_timer = max_jump_hold_timer;
}
else if ( !the_player.on_ground )
{
u32 next_free_sprite_vram_slot;
u32 sprite_gfx_category_first_vram_slot_list [sgc_count];
void upload_default_sprite_palettes ()
{
//memcpy32 ( obj_pal_ram, the_spritesPal,
// the_spritesPalLen / sizeof (u32) );
memcpy32 ( &( obj_pal_ram [sgc_player * 16] ), the_player_spritesPal,
the_player_spritesPalLen / sizeof (u32) );
u32 next_free_sprite_vram_slot;
u32 sprite_gfx_category_first_vram_slot_list [sgc_count];
void upload_default_sprite_palettes ()
{
//memcpy32 ( obj_pal_ram, the_spritesPal,
// the_spritesPalLen / sizeof (u32) );
memcpy32 ( &( obj_pal_ram [sgc_player * 16] ), the_player_spritesPal,
// There are a total of 16 sprite palettes, each with 15 colors (and one
// transparent "color"). I have decided to combine the identification of
// sprite tilesets and the sprite palette slots into a single enum. This
// should work fine for now.
enum sprite_gfx_category
{
// The player uses sprite palette slot 0
sgc_player,
// Powerup sprites use sprite palette slot 1
enum sprite_type
{
// The Default Sprite
st_default,
// The Player
st_player,
// Powerup Sprites
st_waffle,
#include "test_level.hpp"
const u32 test_level_block_ids [test_level_size]
= {
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
void generate_coll_point_group_16x16 ( const coll_box& the_coll_box,
coll_point_group& the_pt_group )
{
the_pt_group.correct_num_used_points_16x16 ();
// The collision points
vec2_f24p8 & pt_lt = the_pt_group.get_pt_lt_16x16 (),
& pt_lb = the_pt_group.get_pt_lb_16x16 (),
& pt_tl = the_pt_group.get_pt_tl_16x16 (),
& pt_tr = the_pt_group.get_pt_tr_16x16 (),