UrForth: removed some unused code; oops! fixed bug in C kernel basic compiler (negati...
[urasm.git] / src / libfdc / dskldr_common.h
blobc3b97c61d2eccaf5f5a5ed46dca2bdc28d07e571
1 /*
2 * disk images I/O
3 * coded by Ketmar // Invisible Vector
4 * Understanding is not required. Only obedience.
6 * This program is free software. It comes without any warranty, to
7 * the extent permitted by applicable law. You can redistribute it
8 * and/or modify it under the terms of the Do What The Fuck You Want
9 * To Public License, Version 2, as published by Sam Hocevar. See
10 * http://sam.zoy.org/wtfpl/COPYING for more details.
12 #ifndef LIBFDC_DSKLDR_INTERNAL_COMMON_H
13 #define LIBFDC_DSKLDR_INTERNAL_COMMON_H
16 //==========================================================================
18 // writeui16
20 //==========================================================================
21 static LIBFDC_MAYBE_UNUSED LIBFDC_INLINE void writeui16 (uint8_t *d, uint16_t v) {
22 d[0] = (v&0xff);
23 d[1] = ((v>>8)&0xff);
27 //==========================================================================
29 // writeui32
31 //==========================================================================
32 static LIBFDC_MAYBE_UNUSED LIBFDC_INLINE void writeui32 (uint8_t *d, uint32_t v) {
33 d[0] = (v&0xff);
34 d[1] = ((v>>8)&0xff);
35 d[2] = ((v>>16)&0xff);
36 d[3] = ((v>>24)&0xff);
40 //==========================================================================
42 // getui16
44 //==========================================================================
45 static LIBFDC_MAYBE_UNUSED LIBFDC_INLINE uint16_t getui16 (const void *buf) {
46 return ((((const uint8_t *)buf)[1])<<8)|(((const uint8_t *)buf)[0]);
50 //==========================================================================
52 // freaduint
54 //==========================================================================
55 static LIBFDC_MAYBE_UNUSED int freaduint (FILE *fl, uint32_t *valp, int n) {
56 uint32_t val = 0;
57 int shift = 0;
58 *valp = 0;
59 while (n-- > 0) {
60 uint8_t b;
61 if (fread(&b, 1, 1, fl) != 1) return FLPERR_SHIT;
62 val |= ((uint32_t)b)<<shift;
63 shift += 8;
65 *valp = val;
66 return FLPERR_OK;
70 //==========================================================================
72 // fwriteuint
74 //==========================================================================
75 static LIBFDC_MAYBE_UNUSED int fwriteuint (FILE *fl, uint32_t val, int n) {
76 while (n-- > 0) {
77 uint8_t b = (val&0xff);
78 if (fwrite(&b, 1, 1, fl) != 1) return FLPERR_SHIT;
79 val >>= 8;
81 return FLPERR_OK;
85 #endif