~groovestomp/gsnes

ref: 85e494661af3862ec2f0c9d77df6ce9bdfcde828 gsnes/util.c -rw-r--r-- 1.1 KiB
85e49466 — GrooveStomp Working input and fixed a bug in ADC() 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/******************************************************************************
  GrooveStomp's NES Emulator
  Copyright (c) 2019 Aaron Oman (GrooveStomp)

  File: util.c
  Created: 2019-11-15
  Updated: 2019-11-21
  Author: Aaron Oman
  Notice: GNU AGPLv3 License

  Based off of: One Lone Coder Console Game Engine Copyright (C) 2018 Javidx9
  This program comes with ABSOLUTELY NO WARRANTY.
  This is free software, and you are welcome to redistribute it under certain
  conditions; See LICENSE for details.
 ******************************************************************************/
//! \file util.c
#include <string.h> // memmove

#include "util.h"

void SwapGeneric(void *v1, void *v2, size_t size) {
        char temp[size];
        memmove(temp, v1, size);
        memmove(v1, v2, size);
        memmove(v2, temp, size);
}

void HexToString(uint32_t hex, uint8_t nibbles, char *buf, uint8_t size) {
        if (nibbles > size) {
                nibbles = size;
        }

        for (int i = nibbles - 1; i >= 0; i--, hex >>= 4) {
                buf[i] = "0123456789ABCDEF"[hex & 0xF];
        }

        buf[nibbles] = '\0';
}