Skip to content

Commit cfb1d11

Browse files
committed
Changes and bugfixes
1 parent 3392d19 commit cfb1d11

9 files changed

+189
-63
lines changed

Changelog

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Most recent changes are placed at the top
22

3+
20140725
4+
Fixed some minor bugs related to compression.
5+
Added clipboard support for saving as text.
6+
37
20140725
48
Added new histogram based hue tile picking options
59
Fixed a bug related to Yliluoma 1 where which row is not checked

callback_tilemap.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ void load_image_to_tilemap(Fl_Widget*,void*o){
250250
h=loaded_image->h();
251251
printf("image width: %d image height: %d\n",w,h);
252252
uint32_t w8,h8;
253-
uint32_t wt,ht,wr,hr;
253+
uint32_t wt,ht;
254+
int wr,hr;
254255
wr=w%tilebitw;
255256
hr=h%tilebith;
256257
w8=w/currentProject->tileC->sizex;
@@ -262,7 +263,7 @@ void load_image_to_tilemap(Fl_Widget*,void*o){
262263
if((currentProject->gameSystem==NES)&&(currentProject->subSystem=NES2x2)){
263264
if((wr-8)>0)
264265
++w8;
265-
if((hr-8)>0)
266+
if((int)(hr-8)>0)
266267
++h8;
267268
}
268269
wt=w8*currentProject->tileC->sizex;

callbacks_palette.cpp

+26-9
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,42 @@ void save_palette(Fl_Widget*, void* start_end){
4242
return;
4343
uint8_t end = atoi(returned)+1;
4444
int type=askSaveType();
45-
if (load_file_generic("Save palette",true)==true){
45+
int clipboard;
46+
if(type){
47+
clipboard=clipboardAsk();
48+
if(clipboard==2)
49+
return;
50+
}else
51+
clipboard=0;
52+
bool pickedFile;
53+
if(clipboard)
54+
pickedFile=true;
55+
else
56+
pickedFile=load_file_generic("Save palette",true);
57+
if(pickedFile){
4658
FILE * myfile;
47-
if (type){
59+
if(clipboard)
60+
myfile=0;//When file is null for the function saveBinAsText clipboard will be used
61+
else if(type)
4862
myfile = fopen(the_file.c_str(),"w");
49-
}else
63+
else
5064
myfile = fopen(the_file.c_str(),"wb");
51-
if (likely(myfile!=0)){
65+
if (likely(myfile||clipboard)){
5266
//save the palette
5367
if (type){
5468
char comment[512];
5569
snprintf(comment,512,"Colors %d-%d",start,end-1);
70+
int bits;
5671
if(currentProject->gameSystem==sega_genesis){
5772
start*=2;//Be sure to keep this in sync with the other if statment shortly below
5873
end*=2;
59-
}
60-
if (saveBinAsText(currentProject->palDat+start,end-start,myfile,type,comment,"palDat")==false){
74+
bits=16;
75+
}else
76+
bits=8;
77+
if (saveBinAsText(currentProject->palDat+start,end-start,myfile,type,comment,"palDat",bits)==false){
6178
fl_alert("Error: can not save file %s",the_file.c_str());
6279
return;
6380
}
64-
fputs("};",myfile);
6581
}else{
6682
if(currentProject->gameSystem==sega_genesis){
6783
start*=2;
@@ -72,9 +88,10 @@ void save_palette(Fl_Widget*, void* start_end){
7288
return;
7389
}
7490
}
75-
fclose(myfile);
91+
if(myfile)
92+
fclose(myfile);
7693
}else
77-
fl_alert("myfile.is_open() returned false that means there was an error in creating the file");
94+
fl_alert("Cannot open file %s",the_file.c_str());
7895
}
7996
}
8097
void update_palette(Fl_Widget* o, void* v){

classtilemap.cpp

+41-15
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,30 @@ bool tileMap::saveToFile(){
243243
size_t fileSize;
244244
int type,compression;
245245
uint8_t* mapptr;
246-
if (load_file_generic("Save tilemap to",true)){
247-
type=askSaveType();
246+
type=askSaveType();
247+
int clipboard;
248+
if(type){
249+
clipboard=clipboardAsk();
250+
if(clipboard==2)
251+
return true;
252+
}else
253+
clipboard=0;
254+
bool pickedFile;
255+
if(clipboard)
256+
pickedFile=true;
257+
else
258+
pickedFile=load_file_generic("Save tilemap to",true);
259+
if(pickedFile){
248260
compression=compressionAsk();
249261
if(compression<0)
250262
return true;
251-
if(type){
263+
if(clipboard)
264+
myfile=0;
265+
else if(type)
252266
myfile = fopen(the_file.c_str(),"w");
253-
}else
267+
else
254268
myfile = fopen(the_file.c_str(),"wb");
255-
if (likely(myfile!=0)){
269+
if (likely(myfile||clipboard)){
256270
switch (currentProject->gameSystem){
257271
case sega_genesis:
258272
{uint16_t * TheMap;
@@ -302,26 +316,38 @@ bool tileMap::saveToFile(){
302316
}
303317
if(type){
304318
char temp[2048];
305-
snprintf(temp,2048,"Width %d Height %d %s",mapSizeW,mapSizeH*amt,typeToText(type));
306-
if(!saveBinAsText(mapptr,fileSize,myfile,type,temp,"mapDat")){
319+
snprintf(temp,2048,"Width %d Height %d %s",mapSizeW,mapSizeH*amt,typeToText(compression));
320+
int bits;
321+
if((currentProject->gameSystem==sega_genesis)&&(!compression))
322+
bits=16;
323+
else
324+
bits=8;
325+
if(!saveBinAsText(mapptr,fileSize,myfile,type,temp,"mapDat",bits)){
307326
free(mapptr);
308327
return false;
309328
}
310329
}else
311330
fwrite(mapptr,1,fileSize,myfile);
312331
free(mapptr);
313-
fclose(myfile);
332+
if(myfile)
333+
fclose(myfile);
314334
puts("File Saved");
315335
}else
316336
return false;
317337
}
318338
if (currentProject->gameSystem == NES){
319-
if (load_file_generic("Save attributes to",true) == true) {
320-
if(type){
339+
if(clipboard)
340+
fl_alert("Copy the data to clipboard and press okay after this tilemap attributes will be copied to clipboard");
341+
else
342+
pickedFile=load_file_generic("Save attributes to",true);
343+
if(pickedFile){
344+
if(clipboard)
345+
myfile=0;
346+
else if(type)
321347
myfile = fopen(the_file.c_str(),"w");
322-
}else
348+
else
323349
myfile = fopen(the_file.c_str(),"wb");
324-
if (likely(myfile!=0)) {
350+
if (likely(myfile||clipboard)) {
325351
uint8_t * AttrMap = (uint8_t *)malloc((mapSizeW/4)*(mapSizeH*amt/4));
326352
uint8_t * freeAttrMap=AttrMap;
327353
for (y=0;y<mapSizeH*amt;y+=4){
@@ -333,13 +359,13 @@ bool tileMap::saveToFile(){
333359
//AttrMap-=(mapSizeW/4)*(mapSizeH/4);
334360
printf("%d %d\n",AttrMap,freeAttrMap);
335361
if(type){
336-
if(saveBinAsText(freeAttrMap,(mapSizeW/4)*(mapSizeH*amt/4),myfile,type,0,"mapDatAttr")==false)
362+
if(saveBinAsText(freeAttrMap,(mapSizeW/4)*(mapSizeH*amt/4),myfile,type,0,"mapDatAttr",8)==false)
337363
return false;
338-
fputs("};",myfile);
339364
}else
340365
fwrite(freeAttrMap,1,(mapSizeW/4)*(mapSizeH*amt/4),myfile);
341366
free(freeAttrMap);
342-
fclose(myfile);
367+
if(myfile)
368+
fclose(myfile);
343369
puts("File Saved");
344370
}else
345371
return false;

filemisc.cpp

+73-19
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,96 @@
1818
#include <stdint.h>
1919
#include "gui.h"
2020
#include "filemisc.h"
21+
#include "includes.h"
22+
int clipboardAsk(void){
23+
return fl_choice("File or clipboard?","File","Clipboard","Cancel");
24+
}
2125
int askSaveType(void){
2226
return MenuPopup("How would you like the file saved?","Set if the file is saved as binary C header bex or asm",4,"Binary","C header","Asm","BEX");
2327
}
24-
bool saveBinAsText(void * ptr,size_t sizeBin,FILE * fp,int type,const char*comment,const char*label){
28+
bool saveBinAsText(void * ptr,size_t sizeBin,FILE * fp,int type,const char*comment,const char*label,int bits){
2529
/*!
2630
This function saves binary data as plain text useful for c headers each byte is seperated by a comma
31+
To use the clipboard specify file as NULL
2732
Returns True on sucess false on error
2833
Type can be:
2934
1 - c header
3035
2 - asm
3136
3 - bex
3237
*/
33-
uint8_t * dat=(uint8_t *)ptr;
38+
uint8_t * dat8=(uint8_t *)ptr;
39+
uint16_t * dat16=(uint16_t *)ptr;
40+
uint32_t * dat32=(uint32_t *)ptr;
3441
char endc=',';
42+
std::string temp;
43+
unsigned mask=(bits/8)-1;
44+
char tmp[16];
45+
if(mask){
46+
if(sizeBin&mask){
47+
fl_alert("Error filetype unaligned to %d bits",bits);
48+
return false;
49+
}
50+
sizeBin/=mask+1;
51+
}
3552
if(comment){
3653
switch(type){
3754
case 1:
38-
fputs("// ",fp);
55+
temp.assign("// ");
3956
break;
4057
case 2:
41-
fputs("; ",fp);
58+
temp.assign("; ");
4259
break;
4360
case 3:
44-
fputs("' ",fp);
61+
temp.assign("' ");
4562
break;
4663
}
47-
fputs(comment,fp);
48-
fputc('\n',fp);
64+
temp.append(comment);
65+
temp.push_back('\n');
4966
}
5067
switch(type){
5168
case 1:
52-
fprintf(fp,"const uint8_t %s[]={\n",label);
69+
temp.append("const uint");
70+
snprintf(tmp,16,"%d",bits);
71+
temp.append(tmp);
72+
temp.append("_t ");
73+
temp.append(label);
74+
temp.append("[]={");
5375
break;
5476
case 2:
5577
case 3:
56-
fputs(label,fp);
57-
fputs(":\n",fp);
78+
temp.append(label);
79+
temp.push_back(':');
5880
break;
5981
}
6082
for (size_t x=0;x<sizeBin;++x){
6183
if ((x&31)==0){
62-
if (fputc('\n',fp)==0)
63-
return false;
84+
temp.push_back('\n');
6485
switch(type){
6586
case 2:
66-
fputs("\tdc.b ",fp);
87+
switch(bits){
88+
case 8:
89+
temp.append("\tdc.b ");
90+
break;
91+
case 16:
92+
temp.append("\tdc.w ");
93+
break;
94+
case 32:
95+
temp.append("\tdc.l ");
96+
break;
97+
}
6798
break;
6899
case 3:
69-
fputs("\tdata ",fp);
100+
switch(bits){
101+
case 8:
102+
temp.append("\tdata ");
103+
break;
104+
case 16:
105+
temp.append("\tdataint ");
106+
break;
107+
case 32:
108+
temp.append("\tdatalong ");
109+
break;
110+
}
70111
break;
71112
}
72113
}
@@ -76,13 +117,26 @@ bool saveBinAsText(void * ptr,size_t sizeBin,FILE * fp,int type,const char*comme
76117
endc=',';
77118
if(x==(sizeBin-1))
78119
endc='\n';
120+
switch(bits){
121+
case 8:
122+
snprintf(tmp,16,"%u",*dat8++);
123+
break;
124+
case 16:
125+
snprintf(tmp,16,"%u",*dat16++);
126+
break;
127+
case 32:
128+
snprintf(tmp,16,"%u",*dat32++);
129+
break;
130+
}
131+
temp.append(tmp);
79132
if(endc)
80-
fprintf(fp,"%d%c",*dat,endc);
81-
else
82-
fprintf(fp,"%d",*dat);
83-
++dat;
133+
temp.push_back(endc);
84134
}
85135
if(type==1)
86-
fputs("};\n",fp);
136+
temp.append("};\n");
137+
if(fp)
138+
fputs(temp.c_str(),fp);
139+
else
140+
Fl::copy(temp.c_str(),temp.length(),1);
87141
return true;
88142
}

filemisc.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
along with Retro Graphics Toolkit. If not, see <http://www.gnu.org/licenses/>.
1515
Copyright Sega16 (or whatever you wish to call me) (2012-2014)
1616
*/
17+
int clipboardAsk(void);
1718
int askSaveType(void);
18-
bool saveBinAsText(void * ptr,size_t sizeBin,FILE * fp,int type,const char*comment,const char*label);
19+
bool saveBinAsText(void * ptr,size_t sizeBin,FILE * fp,int type,const char*comment,const char*label,int bits);

make_win

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CC=i686-pc-mingw32-gcc
22
CPP=i686-pc-mingw32-g++
3+
STRIP=i686-pc-mingw32-strip
34
#to compile on windows you must compile fltk
45
#I compiled fltk in a folder named fltk-1.3.2 which is in the Retro Graphics tookit directory
56
#if that is not the case for you edit the makefile changing paths
@@ -18,6 +19,7 @@ all: $(EXECUTABLE)
1819

1920
$(EXECUTABLE): $(OBJECTS)
2021
$(CPP) $(LDFLAGS) $(OBJECTS) $(LINKER) -o $@
22+
$(STRIP) $(EXECUTABLE)
2123
.c.o:
2224
$(CC) $(CFLAGS) $< -o $@
2325
.cpp.o:

0 commit comments

Comments
 (0)