src/mess/pile.h
| r6076 | r6077 | |
| 1 | | /**************************************************************************** |
| 2 | | |
| 3 | | pile.h |
| 4 | | |
| 5 | | Utility code to implement "piles"; blocks of data that are built up |
| 6 | | and then detached |
| 7 | | |
| 8 | | ****************************************************************************/ |
| 9 | | |
| 10 | | #ifndef PILE_H |
| 11 | | #define PILE_H |
| 12 | | |
| 13 | | #include <stdlib.h> |
| 14 | | #include <stdarg.h> |
| 15 | | |
| 16 | | typedef struct |
| 17 | | { |
| 18 | | void *ptr; |
| 19 | | size_t physical_size; |
| 20 | | size_t logical_size; |
| 21 | | } mess_pile; |
| 22 | | |
| 23 | | void pile_init(mess_pile *pile); |
| 24 | | void pile_delete(mess_pile *pile); |
| 25 | | void pile_clear(mess_pile *pile); |
| 26 | | void *pile_detach(mess_pile *pile); |
| 27 | | int pile_write(mess_pile *pile, const void *ptr, size_t size); |
| 28 | | int pile_writebyte(mess_pile *pile, char byte, size_t size); |
| 29 | | |
| 30 | | INLINE void *pile_getptr(mess_pile *pile) |
| 31 | | { |
| 32 | | return pile->ptr; |
| 33 | | } |
| 34 | | |
| 35 | | INLINE size_t pile_size(mess_pile *pile) |
| 36 | | { |
| 37 | | return pile->logical_size; |
| 38 | | } |
| 39 | | |
| 40 | | int pile_vprintf(mess_pile *pile, const char *fmt, va_list args); |
| 41 | | #ifdef __GNUC__ |
| 42 | | int pile_printf(mess_pile *pile, const char *fmt, ...)/* ATTR_PRINTF(2,3)*/__attribute__((format(printf, 2, 3))); |
| 43 | | #else |
| 44 | | int pile_printf(mess_pile *pile, const char *fmt, ...)/* ATTR_PRINTF(2,3)*/; |
| 45 | | #endif |
| 46 | | int pile_putc(mess_pile *pile, char c); |
| 47 | | int pile_puts(mess_pile *pile, const char *s); |
| 48 | | |
| 49 | | #endif /* PILE_H */ |
| 50 | | |
| 51 | | |
src/mess/pile.c
| r6076 | r6077 | |
| 1 | | /**************************************************************************** |
| 2 | | |
| 3 | | pile.h |
| 4 | | |
| 5 | | Utility code to implement "piles"; blocks of data that are built up |
| 6 | | and then detached |
| 7 | | |
| 8 | | ****************************************************************************/ |
| 9 | | |
| 10 | | #include <string.h> |
| 11 | | #include <stdio.h> |
| 12 | | |
| 13 | | #include "pile.h" |
| 14 | | |
| 15 | | void pile_init(mess_pile *pile) |
| 16 | | { |
| 17 | | pile->ptr = NULL; |
| 18 | | pile->physical_size = 0; |
| 19 | | pile->logical_size = 0; |
| 20 | | } |
| 21 | | |
| 22 | | |
| 23 | | |
| 24 | | void pile_delete(mess_pile *pile) |
| 25 | | { |
| 26 | | if (pile->ptr) |
| 27 | | { |
| 28 | | free(pile->ptr); |
| 29 | | pile_init(pile); |
| 30 | | } |
| 31 | | } |
| 32 | | |
| 33 | | |
| 34 | | |
| 35 | | void pile_clear(mess_pile *pile) |
| 36 | | { |
| 37 | | pile_delete(pile); |
| 38 | | } |
| 39 | | |
| 40 | | |
| 41 | | |
| 42 | | void *pile_detach(mess_pile *pile) |
| 43 | | { |
| 44 | | void *ptr; |
| 45 | | |
| 46 | | ptr = realloc(pile->ptr, pile->logical_size); |
| 47 | | if (!ptr) |
| 48 | | ptr = pile->ptr; |
| 49 | | |
| 50 | | pile_init(pile); |
| 51 | | return ptr; |
| 52 | | } |
| 53 | | |
| 54 | | |
| 55 | | |
| 56 | | int pile_write(mess_pile *pile, const void *ptr, size_t size) |
| 57 | | { |
| 58 | | size_t new_logical_size; |
| 59 | | size_t new_physical_size; |
| 60 | | size_t blocksize = 4096; |
| 61 | | char *new_ptr; |
| 62 | | |
| 63 | | new_logical_size = pile->logical_size + size; |
| 64 | | if (new_logical_size > pile->physical_size) |
| 65 | | { |
| 66 | | new_physical_size = new_logical_size + blocksize; |
| 67 | | new_physical_size -= new_physical_size % blocksize; |
| 68 | | |
| 69 | | new_ptr = (char *) realloc(pile->ptr, new_physical_size); |
| 70 | | if (!new_ptr) |
| 71 | | return -1; |
| 72 | | |
| 73 | | pile->ptr = new_ptr; |
| 74 | | pile->physical_size = new_physical_size; |
| 75 | | } |
| 76 | | memcpy(((char *) pile->ptr) + pile->logical_size, ptr, size); |
| 77 | | pile->logical_size = new_logical_size; |
| 78 | | return 0; |
| 79 | | } |
| 80 | | |
| 81 | | |
| 82 | | |
| 83 | | int pile_writebyte(mess_pile *pile, char byte, size_t size) |
| 84 | | { |
| 85 | | int rc = 0; |
| 86 | | |
| 87 | | while(size--) |
| 88 | | { |
| 89 | | rc = pile_write(pile, &byte, 1); |
| 90 | | if (rc) |
| 91 | | return rc; |
| 92 | | } |
| 93 | | return rc; |
| 94 | | } |
| 95 | | |
| 96 | | |
| 97 | | |
| 98 | | int pile_vprintf(mess_pile *pile, const char *fmt, va_list args) |
| 99 | | { |
| 100 | | int count; |
| 101 | | char buf[1024]; |
| 102 | | |
| 103 | | count = vsnprintf(buf, sizeof(buf) / sizeof(buf[0]), fmt, args); |
| 104 | | if (pile_write(pile, buf, count * sizeof(*buf))) |
| 105 | | return 0; |
| 106 | | return count; |
| 107 | | } |
| 108 | | |
| 109 | | |
| 110 | | |
| 111 | | int pile_printf(mess_pile *pile, const char *fmt, ...) |
| 112 | | { |
| 113 | | int count; |
| 114 | | va_list va; |
| 115 | | |
| 116 | | va_start(va, fmt); |
| 117 | | count = pile_vprintf(pile, fmt, va); |
| 118 | | va_end(va); |
| 119 | | return count; |
| 120 | | } |
| 121 | | |
| 122 | | |
| 123 | | |
| 124 | | int pile_putc(mess_pile *pile, char c) |
| 125 | | { |
| 126 | | return pile_write(pile, &c, sizeof(c)); |
| 127 | | } |
| 128 | | |
| 129 | | |
| 130 | | |
| 131 | | int pile_puts(mess_pile *pile, const char *s) |
| 132 | | { |
| 133 | | size_t size; |
| 134 | | size = strlen(s); |
| 135 | | return pile_write(pile, s, size); |
| 136 | | } |
| 137 | | |
| 138 | | |
src/mess/tools/pile.h
| r0 | r6077 | |
| 1 | /**************************************************************************** |
| 2 | |
| 3 | pile.h |
| 4 | |
| 5 | Utility code to implement "piles"; blocks of data that are built up |
| 6 | and then detached |
| 7 | |
| 8 | ****************************************************************************/ |
| 9 | |
| 10 | #ifndef PILE_H |
| 11 | #define PILE_H |
| 12 | |
| 13 | #include <stdlib.h> |
| 14 | #include <stdarg.h> |
| 15 | |
| 16 | typedef struct |
| 17 | { |
| 18 | void *ptr; |
| 19 | size_t physical_size; |
| 20 | size_t logical_size; |
| 21 | } mess_pile; |
| 22 | |
| 23 | void pile_init(mess_pile *pile); |
| 24 | void pile_delete(mess_pile *pile); |
| 25 | void pile_clear(mess_pile *pile); |
| 26 | void *pile_detach(mess_pile *pile); |
| 27 | int pile_write(mess_pile *pile, const void *ptr, size_t size); |
| 28 | int pile_writebyte(mess_pile *pile, char byte, size_t size); |
| 29 | |
| 30 | INLINE void *pile_getptr(mess_pile *pile) |
| 31 | { |
| 32 | return pile->ptr; |
| 33 | } |
| 34 | |
| 35 | INLINE size_t pile_size(mess_pile *pile) |
| 36 | { |
| 37 | return pile->logical_size; |
| 38 | } |
| 39 | |
| 40 | int pile_vprintf(mess_pile *pile, const char *fmt, va_list args); |
| 41 | #ifdef __GNUC__ |
| 42 | int pile_printf(mess_pile *pile, const char *fmt, ...)/* ATTR_PRINTF(2,3)*/__attribute__((format(printf, 2, 3))); |
| 43 | #else |
| 44 | int pile_printf(mess_pile *pile, const char *fmt, ...)/* ATTR_PRINTF(2,3)*/; |
| 45 | #endif |
| 46 | int pile_putc(mess_pile *pile, char c); |
| 47 | int pile_puts(mess_pile *pile, const char *s); |
| 48 | |
| 49 | #endif /* PILE_H */ |
| 50 | |
| 51 | |
src/mess/tools/tools.mak
| r0 | r6077 | |
| 1 | ###########################################################################
|
| 2 | #
|
| 3 | # tools.mak
|
| 4 | #
|
| 5 | # MESS tools makefile
|
| 6 | #
|
| 7 | ###########################################################################
|
| 8 | |
| 9 | |
| 10 | # add include path to tools directory
|
| 11 | CFLAGS += -I$(MESSSRC)/tools
|
| 12 | |
| 13 | # tools object directory
|
| 14 | MESS_TOOLS = $(MESSOBJ)/tools
|
| 15 | |
| 16 | |
| 17 | ifdef BUILD_IMGTOOL
|
| 18 | include $(MESSSRC)/tools/imgtool/imgtool.mak
|
| 19 | TOOLS += $(IMGTOOL)
|
| 20 | endif
|
| 21 | |
| 22 | ifdef BUILD_CASTOOL
|
| 23 | include $(MESSSRC)/tools/castool/castool.mak
|
| 24 | TOOLS += $(CASTOOL)
|
| 25 | endif
|
| 26 | |
| 27 | ifdef BUILD_MESSTEST
|
| 28 | include $(MESSSRC)/tools/messtest/messtest.mak
|
| 29 | TOOLS += $(MESSTEST)
|
| 30 | endif
|
| 31 | |
| 32 | ifdef BUILD_DAT2HTML
|
| 33 | include $(MESSSRC)/tools/dat2html/dat2html.mak
|
| 34 | TOOLS += $(DAT2HTML)
|
| 35 | endif
|
| 36 | |
| 37 | # include OS-specific MESS stuff
|
| 38 | ifeq ($(OSD),windows)
|
| 39 | include $(MESSSRC)/tools/messdocs/messdocs.mak
|
| 40 | |
| 41 | ifdef BUILD_WIMGTOOL
|
| 42 | include $(MESSSRC)/tools/imgtool/windows/wimgtool.mak
|
| 43 | TOOLS += $(WIMGTOOL)
|
| 44 | endif
|
| 45 | endif
|
src/mess/tools/pile.c
| r0 | r6077 | |
| 1 | /**************************************************************************** |
| 2 | |
| 3 | pile.h |
| 4 | |
| 5 | Utility code to implement "piles"; blocks of data that are built up |
| 6 | and then detached |
| 7 | |
| 8 | ****************************************************************************/ |
| 9 | |
| 10 | #include <string.h> |
| 11 | #include <stdio.h> |
| 12 | |
| 13 | #include "pile.h" |
| 14 | |
| 15 | void pile_init(mess_pile *pile) |
| 16 | { |
| 17 | pile->ptr = NULL; |
| 18 | pile->physical_size = 0; |
| 19 | pile->logical_size = 0; |
| 20 | } |
| 21 | |
| 22 | |
| 23 | |
| 24 | void pile_delete(mess_pile *pile) |
| 25 | { |
| 26 | if (pile->ptr) |
| 27 | { |
| 28 | free(pile->ptr); |
| 29 | pile_init(pile); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | |
| 34 | |
| 35 | void pile_clear(mess_pile *pile) |
| 36 | { |
| 37 | pile_delete(pile); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | |
| 42 | void *pile_detach(mess_pile *pile) |
| 43 | { |
| 44 | void *ptr; |
| 45 | |
| 46 | ptr = realloc(pile->ptr, pile->logical_size); |
| 47 | if (!ptr) |
| 48 | ptr = pile->ptr; |
| 49 | |
| 50 | pile_init(pile); |
| 51 | return ptr; |
| 52 | } |
| 53 | |
| 54 | |
| 55 | |
| 56 | int pile_write(mess_pile *pile, const void *ptr, size_t size) |
| 57 | { |
| 58 | size_t new_logical_size; |
| 59 | size_t new_physical_size; |
| 60 | size_t blocksize = 4096; |
| 61 | char *new_ptr; |
| 62 | |
| 63 | new_logical_size = pile->logical_size + size; |
| 64 | if (new_logical_size > pile->physical_size) |
| 65 | { |
| 66 | new_physical_size = new_logical_size + blocksize; |
| 67 | new_physical_size -= new_physical_size % blocksize; |
| 68 | |
| 69 | new_ptr = (char *) realloc(pile->ptr, new_physical_size); |
| 70 | if (!new_ptr) |
| 71 | return -1; |
| 72 | |
| 73 | pile->ptr = new_ptr; |
| 74 | pile->physical_size = new_physical_size; |
| 75 | } |
| 76 | memcpy(((char *) pile->ptr) + pile->logical_size, ptr, size); |
| 77 | pile->logical_size = new_logical_size; |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | |
| 83 | int pile_writebyte(mess_pile *pile, char byte, size_t size) |
| 84 | { |
| 85 | int rc = 0; |
| 86 | |
| 87 | while(size--) |
| 88 | { |
| 89 | rc = pile_write(pile, &byte, 1); |
| 90 | if (rc) |
| 91 | return rc; |
| 92 | } |
| 93 | return rc; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | |
| 98 | int pile_vprintf(mess_pile *pile, const char *fmt, va_list args) |
| 99 | { |
| 100 | int count; |
| 101 | char buf[1024]; |
| 102 | |
| 103 | count = vsnprintf(buf, sizeof(buf) / sizeof(buf[0]), fmt, args); |
| 104 | if (pile_write(pile, buf, count * sizeof(*buf))) |
| 105 | return 0; |
| 106 | return count; |
| 107 | } |
| 108 | |
| 109 | |
| 110 | |
| 111 | int pile_printf(mess_pile *pile, const char *fmt, ...) |
| 112 | { |
| 113 | int count; |
| 114 | va_list va; |
| 115 | |
| 116 | va_start(va, fmt); |
| 117 | count = pile_vprintf(pile, fmt, va); |
| 118 | va_end(va); |
| 119 | return count; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | |
| 124 | int pile_putc(mess_pile *pile, char c) |
| 125 | { |
| 126 | return pile_write(pile, &c, sizeof(c)); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | |
| 131 | int pile_puts(mess_pile *pile, const char *s) |
| 132 | { |
| 133 | size_t size; |
| 134 | size = strlen(s); |
| 135 | return pile_write(pile, s, size); |
| 136 | } |
| 137 | |
| 138 | |
src/mess/mess.mak
| r6076 | r6077 | |
| 1531 | 1531 | $(MESS_MACHINE)/nes_mmc.o: $(MESSSRC)/machine/nes_ines.c \ |
| 1532 | 1532 | $(MESSSRC)/machine/nes_unif.c \ |
| 1533 | 1533 | |
| 1534 | |
| 1534 | 1535 | #------------------------------------------------- |
| 1535 | 1536 | # layout dependencies |
| 1536 | 1537 | #------------------------------------------------- |
| r6076 | r6077 | |
| 1580 | 1581 | $(MESS_LAYOUT)/z80netb.lh \ |
| 1581 | 1582 | $(MESS_LAYOUT)/z80netf.lh |
| 1582 | 1583 | |
| 1584 | |
| 1583 | 1585 | #------------------------------------------------- |
| 1584 | 1586 | # MESS-specific tools |
| 1585 | 1587 | #------------------------------------------------- |
| 1586 | 1588 | |
| 1587 | | ifdef BUILD_IMGTOOL |
| 1588 | | include $(MESSSRC)/tools/imgtool/imgtool.mak |
| 1589 | | TOOLS += $(IMGTOOL) |
| 1590 | | endif |
| 1589 | include $(MESSSRC)/tools/tools.mak |
| 1591 | 1590 | |
| 1592 | | ifdef BUILD_CASTOOL |
| 1593 | | include $(MESSSRC)/tools/castool/castool.mak |
| 1594 | | TOOLS += $(CASTOOL) |
| 1595 | | endif |
| 1596 | 1591 | |
| 1597 | | ifdef BUILD_MESSTEST |
| 1598 | | include $(MESSSRC)/tools/messtest/messtest.mak |
| 1599 | | TOOLS += $(MESSTEST) |
| 1600 | | endif |
| 1601 | | |
| 1602 | | ifdef BUILD_DAT2HTML |
| 1603 | | include $(MESSSRC)/tools/dat2html/dat2html.mak |
| 1604 | | TOOLS += $(DAT2HTML) |
| 1605 | | endif |
| 1606 | | |
| 1607 | | # include OS-specific MESS stuff |
| 1608 | | ifeq ($(OSD),windows) |
| 1609 | | include $(MESSSRC)/tools/messdocs/messdocs.mak |
| 1610 | | |
| 1611 | | ifdef BUILD_WIMGTOOL |
| 1612 | | include $(MESSSRC)/tools/imgtool/windows/wimgtool.mak |
| 1613 | | TOOLS += $(WIMGTOOL) |
| 1614 | | endif |
| 1615 | | endif |
| 1616 | | |
| 1617 | | |
| 1618 | | |
| 1619 | 1592 | #------------------------------------------------- |
| 1620 | 1593 | # MESS special OSD rules |
| 1621 | 1594 | #------------------------------------------------- |
| 1622 | 1595 | |
| 1623 | | include $(SRC)/mess/osd/$(OSD)/$(OSD).mak |
| 1596 | include $(MESSSRC)/osd/$(OSD)/$(OSD).mak |