1 /*************************************************************************** 2 OutRun Utility Functions & Assembler Helper Functions. 3 4 Common OutRun library functions. 5 Helper functions used to facilitate 68K to C++ porting process. 6 7 Copyright Chris White. 8 See license.txt for more details. 9 ***************************************************************************/ 10 11 #pragma once 12 13 #include "stdint.hpp" 14 15 class outils 16 { 17 public: 18 static const uint8_t DEC_TO_HEX[]; 19 20 outils(); 21 ~outils(); 22 23 static void reset_random_seed(); 24 static uint32_t random(); 25 static int32_t isqrt(int32_t); 26 static uint16_t convert16_dechex(uint16_t); 27 static uint32_t bcd_add(uint32_t, uint32_t); 28 static uint32_t bcd_sub(uint32_t, uint32_t); 29 30 // Inline functions move16(uint32_t src,uint32_t & dst)31 inline static void move16(uint32_t src, uint32_t& dst) 32 { 33 dst = (dst & 0xFFFF0000) + (src & 0xFFFF); 34 } 35 add16(uint32_t src,uint32_t & dst)36 inline static void add16(uint32_t src, uint32_t& dst) 37 { 38 dst = (dst & 0xFFFF0000) + (((dst & 0xFFFF) + (src & 0xFFFF)) & 0xFFFF); 39 } 40 sub16(int32_t src,int32_t & dst)41 inline static void sub16(int32_t src, int32_t& dst) 42 { 43 dst = (dst & 0xFFFF0000) + (((dst & 0xFFFF) - (src & 0xFFFF)) & 0xFFFF); 44 } 45 swap32(int32_t & v)46 inline static void swap32(int32_t& v) 47 { 48 v = ((v & 0xFFFF0000) >> 16) + ((v & 0xFFFF) << 16); 49 } 50 swap32(uint32_t & v)51 inline static void swap32(uint32_t& v) 52 { 53 v = ((v & 0xFFFF0000) >> 16) + ((v & 0xFFFF) << 16); 54 } 55 56 static void convert_counter_to_time(uint16_t counter, uint8_t* converted); 57 58 private: 59 static int32_t next(int32_t, int32_t); 60 static int32_t abs(int32_t); 61 };