Changeset 7 for abuse/trunk/src/imlib
- Timestamp:
- Nov 6, 2005, 7:07:59 PM (18 years ago)
- Location:
- abuse/trunk/src/imlib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/include/specs.hpp
r2 r7 7 7 #include <fcntl.h> 8 8 #include <stdlib.h> 9 #include <stdint.h> 9 10 10 11 extern char *spec_types[]; … … 96 97 97 98 // these read and writes, allways read/write Intel endian-ness 98 u nsigned short read_short();99 u nsigned longread_long();100 u nsigned charread_byte();99 uint16_t read_short(); 100 uint32_t read_long(); 101 uint8_t read_byte(); 101 102 double read_double(); 102 void write_short(u nsigned short x);103 void write_long(u nsigned longx);104 void write_byte(u nsigned charx);103 void write_short(uint16_t x); 104 void write_long(uint32_t x); 105 void write_byte(uint8_t x); 105 106 void write_double(double x); 106 107 void set_read_buffer_size(long size); … … 193 194 char *link_filename=NULL);*/ 194 195 195 u nsigned short read_short(FILE *fp);196 u nsigned longread_long(FILE *fp);197 u nsigned short read_other_long(FILE *fp);198 u nsigned longread_other_short(FILE *fp);199 u nsigned charread_byte(FILE *fp);200 201 void write_short(FILE *fp, u nsigned short x);202 void write_long(FILE *fp, u nsigned longx);203 void write_other_short(FILE *fp, u nsigned short x);204 void write_other_long(FILE *fp, u nsigned longx);205 void write_byte(FILE *fp, u nsigned charx);196 uint16_t read_short(FILE *fp); 197 uint32_t read_long(FILE *fp); 198 uint32_t read_other_long(FILE *fp); 199 uint16_t read_other_short(FILE *fp); 200 uint8_t read_byte(FILE *fp); 201 202 void write_short(FILE *fp, uint16_t x); 203 void write_long(FILE *fp, uint32_t x); 204 void write_other_short(FILE *fp, uint16_t x); 205 void write_other_long(FILE *fp, uint32_t x); 206 void write_byte(FILE *fp, uint8_t x); 206 207 207 208 void set_spec_main_file(char *filename, int Search_order); -
abuse/trunk/src/imlib/include/system.h
r2 r7 26 26 // so apps can find unlink 27 27 #include <unistd.h> 28 #include <stdint.h> 28 29 #endif 29 30 30 31 31 #define short_swap(x) (((((u nsigned short) (x)))<<8)|((((unsigned short) (x)))>>8))32 #define short_swap(x) (((((uint16_t) (x)))<<8)|((((uint16_t) (x)))>>8)) 32 33 #define long_swap(x) \ 33 ((( ((u nsigned long)(x)) )>>24)|((( ((unsigned long)(x)) )&0x00ff0000)>>8)| \34 ((( ((u nsigned long)(x)) )&0x0000ff00)<<8)|(( ((unsigned long)(x)) )<<24))34 ((( ((uint32_t)(x)) )>>24)|((( ((uint32_t)(x)) )&0x00ff0000)>>8)| \ 35 ((( ((uint32_t)(x)) )&0x0000ff00)<<8)|(( ((uint32_t)(x)) )<<24)) 35 36 36 37 #if defined BIG_ENDIANS 37 #define LONG int 38 #define LONG int32_t 38 39 #define int_to_intel(x) short_swap(x) 39 40 #define int_to_local(x) int_to_intel(x) … … 43 44 #define long_to_local(x) long_to_intel(x) 44 45 #else 45 #define LONG long46 #define LONG int32_t 46 47 #define int_to_intel(x) (x) 47 48 #define int_to_local(x) (x) -
abuse/trunk/src/imlib/jmalloc.cpp
r4 r7 2 2 #include <string.h> 3 3 #include <stdio.h> 4 #include <stdint.h> 4 5 5 6 #include <specs.hpp> 6 7 //#include <new.h> 7 8 9 #define MEM_CHECK 8 10 //#ifdef MEM_CHECK 9 11 //#define MEM_CLEAR … … 18 20 19 21 #ifdef MEM_CHECK 20 longbreak_mem_point=0; // can be set in debugger, break mem fun will be called when this address is allocated22 intptr_t break_mem_point=0; // can be set in debugger, break mem fun will be called when this address is allocated 21 23 void break_mem_fun() 22 24 { … … 38 40 struct small_block 39 41 { 40 unsigned long size; 41 u nsigned long alloc_list;// bit field saying weither each block is allocated or not.42 small_block *next; 42 unsigned long size; // size of blocks... 43 uint32_t alloc_list; // bit field saying weither each block is allocated or not. 44 small_block *next; // next small block of same size 43 45 #ifdef MEM_CHECK 44 46 char *name[32]; … … 144 146 while (s) 145 147 { 146 147 148 149 150 148 for (x=0;x<32;x++) 149 if (s->alloc_list&(1<<x)) 150 static_list[size]++; 151 152 s=s->next; 151 153 } 152 154 … … 154 156 while (s) 155 157 { 156 157 158 159 160 158 for (x=0;x<32;x++) 159 if (s->alloc_list&(1<<x)) 160 cache_list[size]++; 161 162 s=s->next; 161 163 } 162 164 } … … 177 179 for (int j=0;j<32;j++) 178 180 { 179 180 181 void *next=(void *)(*(((long*)addr)));182 if ((long)next!=(long)s)183 184 185 186 187 188 189 181 if (s->alloc_list&bit) 182 { 183 void *next=(void *)(*(((intptr_t *)addr))); 184 if ((intptr_t)next!=(intptr_t)s) 185 { 186 fprintf(stderr,"inspect : bad pointer\n"); 187 return ; 188 } 189 } 190 bit=bit<<1; 191 addr+=s->size+4; 190 192 } 191 193 } … … 215 217 { 216 218 fprintf(fp,"*** Small Block size = %d ***\n",i); 217 unsigned long bit=1; 218 char *addr=((char *)(s+1)); 219 for (int j=0;j<32;j++) 220 { 221 fprintf(fp,"%p ",addr); 222 if (s->alloc_list&bit) 223 { 224 #ifdef MEM_CHECK 225 fprintf(fp,"%s\n",s->name[j]); 226 #else 227 fprintf(fp,"allocated\n"); 228 #endif 229 } else fprintf(fp,"FREE\n"); 230 bit=bit<<1; 231 addr+=s->size+4; 232 } 233 } 234 } 235 236 237 fprintf(fp,"************** CACHE SPACE ******************\n",block_size); 238 i=0; 239 for (f=cfirst;f;f=f->next,i++) 240 { 241 fprintf(fp,"%4d %p %4d ",i,f,f->size); 242 #ifdef MEM_CHECK 243 if (f->size>0) 244 fprintf(fp,"%s",f->name); 245 else fprintf(fp,"FREE"); 246 #endif 247 fprintf(fp,"\n"); 248 } 249 for (i=0;i<JM_SMALL_SIZE;i++) 250 { 251 for (small_block *s=cblocks[i];s;s=s->next) 252 { 253 fprintf(fp,"*** Small Block size = %d ***\n",i); 254 unsigned long bit=1; 219 uint32_t bit=1; 255 220 char *addr=((char *)(s+1)); 256 221 for (int j=0;j<32;j++) … … 270 235 } 271 236 } 237 238 239 fprintf(fp,"************** CACHE SPACE ******************\n",block_size); 240 i=0; 241 for (f=cfirst;f;f=f->next,i++) 242 { 243 fprintf(fp,"%4d %p %4d ",i,f,f->size); 244 #ifdef MEM_CHECK 245 if (f->size>0) 246 fprintf(fp,"%s",f->name); 247 else fprintf(fp,"FREE"); 248 #endif 249 fprintf(fp,"\n"); 250 } 251 for (i=0;i<JM_SMALL_SIZE;i++) 252 { 253 for (small_block *s=cblocks[i];s;s=s->next) 254 { 255 fprintf(fp,"*** Small Block size = %d ***\n",i); 256 uint32_t bit=1; 257 char *addr=((char *)(s+1)); 258 for (int j=0;j<32;j++) 259 { 260 fprintf(fp,"%p ",addr); 261 if (s->alloc_list&bit) 262 { 263 #ifdef MEM_CHECK 264 fprintf(fp,"%s\n",s->name[j]); 265 #else 266 fprintf(fp,"allocated\n"); 267 #endif 268 } else fprintf(fp,"FREE\n"); 269 bit=bit<<1; 270 addr+=s->size+4; 271 } 272 } 273 } 272 274 } 273 275 274 276 long block_manager::pointer_size(void *ptr) 275 277 { 276 void *next=(void *)(*((( long*)ptr)-1));278 void *next=(void *)(*(((intptr_t *)ptr)-1)); 277 279 if (next>ptr) 278 280 return ((memory_node *)(((char *)ptr)-sizeof(memory_node)))->size; … … 340 342 #ifdef MEM_CHECK 341 343 s->name[0]=strcpy((char *)malloc(strlen(name)+1),name); 342 if (( long)s==break_mem_point)344 if ((intptr_t)s==break_mem_point) 343 345 break_mem_fun(); 344 346 #endif … … 361 363 362 364 #ifdef MEM_CHECK 363 if (( long)addr==break_mem_point)365 if ((intptr_t)addr==break_mem_point) 364 366 break_mem_fun(); 365 367 #endif … … 396 398 s->name=strcpy((char *)malloc(strlen(name)+1),name); 397 399 398 if (( long)s==break_mem_point)400 if ((intptr_t)s==break_mem_point) 399 401 break_mem_fun(); 400 402 … … 425 427 *addr=(long)s; 426 428 #ifdef MEM_CHECK 427 if (( long)s==break_mem_point)429 if ((intptr_t)s==break_mem_point) 428 430 break_mem_fun(); 429 431 #endif … … 440 442 #ifdef MEM_CHECK 441 443 s->name[i]=strcpy((char *)malloc(strlen(name)+1),name); 442 if (( long)s==break_mem_point)444 if ((intptr_t)s==break_mem_point) 443 445 break_mem_fun(); 444 446 #endif … … 473 475 #ifdef MEM_CHECK 474 476 nc->name=strcpy((char *)malloc(strlen(name)+1),name); 475 if (( long)nc==break_mem_point)477 if ((intptr_t)nc==break_mem_point) 476 478 break_mem_fun(); 477 479 #endif … … 499 501 #ifdef MEM_CHECK 500 502 s->name=strcpy((char *)malloc(strlen(name)+1),name); 501 if (( long)s==break_mem_point)503 if ((intptr_t)s==break_mem_point) 502 504 break_mem_fun(); 503 505 #endif … … 696 698 void jmalloc_init(long min_size) 697 699 { 700 fprintf(stderr,"Disabling memory manager, using libc instead\n"); 701 return; 702 698 703 if (bmanage_total) 699 704 fprintf(stderr,"warning : jmalloc_init called twice\n"); … … 722 727 if (mem) 723 728 { 724 725 726 729 bmanage[bmanage_total].init(mem,size,HI_BLOCK); 730 bmanage_total++; 731 fprintf(stderr,"Added himem block (%d bytes)\n",size); 727 732 } 728 733 … … 732 737 bmanage_total++; */ 733 738 734 735 736 739 #ifdef __WATCOMC__ 737 740 if (size!=jmalloc_max_size) … … 739 742 do 740 743 { 741 742 743 744 745 746 747 744 size=low_memory_available(); 745 if (size>jmalloc_min_low_size+0x1000) // save 64K for misc low memory needs 746 { 747 bmanage[bmanage_total].init(alloc_low_memory(size-jmalloc_min_low_size-0x1000),size-jmalloc_min_low_size-0x1000,LOW_BLOCK); 748 bmanage_total++; 749 fprintf(stderr,"Added low memory block (%d bytes)\n",size); 750 } 748 751 } while (size>jmalloc_min_low_size+0x1000); 749 752 if (size<jmalloc_min_low_size) 750 753 { 751 752 754 fprintf(stderr,not_enough_low_memory_message,size,jmalloc_min_low_size); 755 exit(0); 753 756 } 754 757 } 755 758 #endif 756 759 757 758 760 fprintf(stderr,"Memory available : %d\n",j_available()); 759 761 if (j_available()<min_size) … … 762 764 exit(0); 763 765 } 764 765 766 } 766 767 } … … 796 797 void *a; 797 798 if (alloc_space==ALLOC_SPACE_STATIC) 799 { 798 800 a=bmanage[i].static_alloc(size,name); 801 } 799 802 else 803 { 800 804 a=bmanage[i].cache_alloc(size,name); 805 } 801 806 if (a) return a; 802 807 } -
abuse/trunk/src/imlib/specs.cpp
r4 r7 4 4 #include <stdio.h> 5 5 #include <stdlib.h> 6 #include <stdint.h> 6 7 #include <ctype.h> 7 8 #include <fcntl.h> … … 24 25 "Invalid Type", // 3 25 26 "Image", // 4 26 27 "Fore Tile", 27 28 "Back Tile", 28 29 "Character", 29 30 "8 Morph", 30 31 "16 Morph", 31 32 33 34 35 36 37 38 39 40 41 42 43 44 32 "Grue objs", 33 "Extern WAV", 34 "DMX MUS", 35 "Patched morph", 36 "Normal file", 37 "Compress1 file", 38 "Vector Image", 39 "Light list", 40 "Grue fgmap", 41 "Grue bgmap", 42 "Data array", 43 "Character2", 44 "Particle", 45 "Extern lcache" 45 46 }; 46 47 … … 420 421 if (se) 421 422 { 422 423 424 425 423 start_offset=se->offset; 424 current_offset = 0; 425 file_length=se->size; 426 rbuf_start=rbuf_end=0; 426 427 } else 427 428 { 428 429 429 close(fd); 430 fd=-1; 430 431 } 431 432 } … … 548 549 int jFILE::unbuffered_seek(long offset, int whence) // whence=SEEK_SET, SEEK_CUR, SEEK_END, ret=0=success 549 550 { 550 551 552 553 554 555 551 long ret; 552 553 if (fast_load_mode == 2) 554 { 555 switch (whence) 556 { 556 557 case SEEK_SET : 557 558 558 current_offset = start_offset+offset; 559 break; 559 560 case SEEK_END : 560 561 561 current_offset = start_offset+file_length-offset; 562 break; 562 563 case SEEK_CUR : 563 564 564 current_offset += offset; 565 break; 565 566 default: 566 567 567 ret = -1; 568 break; 568 569 } 569 570 571 570 return current_offset; 571 } 572 572 573 switch (whence) 573 574 { … … 584 585 if (ret>=0) 585 586 { 586 587 588 589 587 current_offset = ret - start_offset; 588 if (spec_main_fd == fd) 589 spec_main_offset = ret; 590 return ret; 590 591 } 591 592 else 592 593 } 594 595 596 u nsigned charbFILE::read_byte()597 { u nsigned charx;593 return -1; // if a bad whence, then failure 594 } 595 596 597 uint8_t bFILE::read_byte() 598 { uint8_t x; 598 599 read(&x,1); 599 600 return x; 600 601 } 601 602 602 u nsigned short bFILE::read_short()603 uint16_t bFILE::read_short() 603 604 { 604 u nsigned short x;605 uint16_t x; 605 606 read(&x,2); 606 607 return int_to_local(x); … … 608 609 609 610 610 u nsigned longbFILE::read_long()611 uint32_t bFILE::read_long() 611 612 { 612 u nsigned longx;613 uint32_t x; 613 614 read(&x,4); 614 615 return long_to_local(x); 615 616 } 616 617 617 void bFILE::write_byte(u nsigned charx)618 void bFILE::write_byte(uint8_t x) 618 619 { 619 620 write(&x,1); 620 621 } 621 622 622 void bFILE::write_short(u nsigned short x)623 void bFILE::write_short(uint16_t x) 623 624 { 624 625 x=int_to_local(x); … … 627 628 628 629 629 void bFILE::write_long(u nsigned longx)630 void bFILE::write_long(uint32_t x) 630 631 { 631 632 x=long_to_local(x); … … 912 913 } 913 914 914 u nsigned short read_short(FILE *fp)915 { 916 u nsigned short x;915 uint16_t read_short(FILE *fp) 916 { 917 uint16_t x; 917 918 fread(&x,1,2,fp); 918 919 return int_to_local(x); 919 920 } 920 921 921 u nsigned longread_long(FILE *fp)922 { 923 u nsigned longx;922 uint32_t read_long(FILE *fp) 923 { 924 uint32_t x; 924 925 fread(&x,1,4,fp); 925 return (long)long_to_local(x);926 } 927 void write_short(FILE *fp, u nsigned short x)926 return long_to_local(x); 927 } 928 void write_short(FILE *fp, uint16_t x) 928 929 { 929 930 x=int_to_local(x); … … 931 932 } 932 933 933 void write_long(FILE *fp, u nsigned longx)934 void write_long(FILE *fp, uint32_t x) 934 935 { 935 936 x=long_to_local(x); … … 937 938 } 938 939 939 u nsigned charread_byte(FILE *fp) { return fgetc(fp)&0xff; }940 void write_byte(FILE *fp, u nsigned char x) { fputc(x,fp); }941 942 u nsigned short read_other_long(FILE *fp)943 { 944 u nsigned longx;940 uint8_t read_byte(FILE *fp) { return fgetc(fp)&0xff; } 941 void write_byte(FILE *fp, uint8_t x) { fputc((unsigned char)x,fp); } 942 943 uint32_t read_other_long(FILE *fp) 944 { 945 uint32_t x; 945 946 fread(&x,1,4,fp); 946 947 return big_long_to_local(x); 947 948 } 948 949 949 u nsigned longread_other_short(FILE *fp)950 { 951 u nsigned short x;950 uint16_t read_other_short(FILE *fp) 951 { 952 uint16_t x; 952 953 fread(&x,1,2,fp); 953 954 return big_short_to_local(x); … … 955 956 956 957 957 void write_other_short(FILE *fp, u nsigned short x)958 void write_other_short(FILE *fp, uint16_t x) 958 959 { 959 960 x=big_short_to_local(x); … … 961 962 } 962 963 963 void write_other_long(FILE *fp, u nsigned longx)964 void write_other_long(FILE *fp, uint32_t x) 964 965 { 965 966 x=big_long_to_local(x);
Note: See TracChangeset
for help on using the changeset viewer.