/*
 * Copyright (c) 2019 Clementine Computing LLC.
 *
 * This file is part of PopuFare.
 *
 * PopuFare is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PopuFare is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

#ifndef BYTE_ACCESS_H
#define BYTE_ACCESS_H

/* Conversion routines for accessing
 * integers (short, long, long long)
 * from a byte array.
 *
 * The viper (gcc I assume) does not
 * allow for non frame aligned access.
 * From what I can tell, it clamps
 * the address to the nearest frame
 * depending on the type you're accessing
 * and reads starting from this position.
 * This leads to misframed data being
 * read if you dereference it from a
 * non framed position.  I would
 * also assume writing has the same problem.
 *
 * These functions will read or write
 * short, long or long long (unsigned)
 * integers starting at the pointer location.
 *
 * Storage is least significant byte first.
 * For example:
 *    _uliw(p, 67305985) would write:
 *
 *    p[0] = 0x01
 *    p[1] = 0x02
 *    p[2] = 0x03
 *    p[3] = 0x04
 *
 *    _uli(p) would return 67305985
 *
 */

unsigned short int _usi(void *p);
unsigned long int _uli(void *p);
unsigned long long int _ulli(void *p);

void _usiw(void *p, unsigned short int usi);
void _uliw(void *p, unsigned long int uli);
void _ulliw(void *p, unsigned long long int ulli);


#endif 
