Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MegaZeux 2.70 release.

  • Loading branch information...
commit 058a44dccf69245b1b5e04c9ea4e60ab7bcf0a41 1 parent a405f15
@ajs1984 authored
View
10 Makefile
@@ -53,16 +53,6 @@ sfx.obj+sfx_edit.obj+sprite.obj+string.obj+timer.obj+window.obj+vlayer.obj
all: megazeux.exe fix.exe getpw.exe killgbl.exe txt2hlp.exe ver1to2.exe
-#
-# Exo documented that as of 2.68, this file had to be compiled
-# to assembly and then converted to machine code by tasm. This is
-# because of the 387 "fsin" instruction which bcc doesn't understand.
-#
-# The -B flag achieves this, but must not be used project-wide.
-#
-counter.obj: counter.cpp
- @$(CC) -B -c counter.cpp
-
megazeux.exe: $(obj)
@$(TLINK) /m/c/d/P-/L$(LIBPATH) @&&|
c0l.obj+$(lobj)+robo_ed.obj,megazeux,megazeux,mse_cl.lib+cl.lib
View
786 boardmem.cpp
@@ -50,7 +50,8 @@
//1. This is really rare- Checks for ems, then conventional, then disk.
//Doesn't affect board_sizes[]. If conv_mem_ok is 0, then only ems and disk
//are checked.
-char allocate_board_space(long size,unsigned char id,char conv_mem_ok) {
+char allocate_board_space(long size,unsigned char id,char conv_mem_ok)
+{
int t1,ems_pages;
FILE *fp;
//Check for ems first...
@@ -58,56 +59,62 @@ char allocate_board_space(long size,unsigned char id,char conv_mem_ok) {
ems_pages=(int)(size>>14);
if(size&16383) ems_pages++;
t1=alloc_EMS(ems_pages);
- if(t1) {
+ if(t1)
+ {
//Got it!
board_where[id]=W_EMS;
board_offsets[id].EMS.handle=t1;
board_offsets[id].EMS.page=0;
board_filenames[id*FILENAME_SIZE]=0;
return 0;
- }
+ }
//Nope.. try conventional
// SPIDER'S NOTE: WILL NOT USE CONVENTIONAL, DISABLED
- if(conv_mem_ok) {
+ if(conv_mem_ok)
+ {
board_offsets[id].mem=(unsigned char *)farmalloc(size);
- if(board_offsets[id].mem) {
+ if(board_offsets[id].mem)
+ {
//Got it!
board_where[id]=W_MEMORY;
board_filenames[id*FILENAME_SIZE]=0;
return 0;
- }
+ }
//Retry after clearing sfx cache
free_sam_cache(1);
board_offsets[id].mem=(unsigned char *)farmalloc(size);
- if(board_offsets[id].mem) {
+ if(board_offsets[id].mem)
+ {
//Got it!
board_where[id]=W_MEMORY;
board_filenames[id*FILENAME_SIZE]=0;
return 0;
- }
}
- //Nope.. try disk
+ }
+ //Nope.. try disk
//Make temporary filename
str_cpy(&board_filenames[id*FILENAME_SIZE],"~MZTMPXXXXXX");
mktemp(&board_filenames[id*FILENAME_SIZE]);
//Open..
fp=fopen(&board_filenames[id*FILENAME_SIZE],"wb");
- if(fp==NULL) {
+ if(fp==NULL)
+ {
//Error
board_filenames[id*FILENAME_SIZE]=0;
return 1;
- }
+ }
//Try to solidify room
fseek(fp,size-1,SEEK_SET);
fputc(0,fp);
fseek(fp,size,SEEK_SET);
- if(ftell(fp)<size) {
+ if(ftell(fp)<size)
+ {
//Not enough room on hard drive
fclose(fp);
unlink(&board_filenames[id*FILENAME_SIZE]);
board_filenames[id*FILENAME_SIZE]=0;
return 2;
- }
+ }
//Room made!
fclose(fp);
board_where[id]=W_TEMPFILE;
@@ -117,9 +124,11 @@ char allocate_board_space(long size,unsigned char id,char conv_mem_ok) {
//Deallocates the space allocated to id given. Sets where to W_NOWHERE and
//clears all others except for board_sizes[].
-void deallocate_board_space(unsigned char id) {
+void deallocate_board_space(unsigned char id)
+{
//According to type...
- switch(board_where[id]) {
+ switch(board_where[id])
+ {
case W_EMS:
//EMS- deallocate.
free_EMS(board_offsets[id].EMS.handle);
@@ -132,7 +141,7 @@ void deallocate_board_space(unsigned char id) {
//Temp file- delete.
unlink(&board_filenames[id*FILENAME_SIZE]);
break;
- }
+ }
//Reset variables for id
board_where[id]=W_NOWHERE;
board_offsets[id].offset=0;
@@ -141,133 +150,163 @@ void deallocate_board_space(unsigned char id) {
//Returns size array would take up RLE2 encoded, using current x size and
//y size.
-unsigned int RLE2_size(unsigned char far *plane) {
+unsigned int RLE2_size(unsigned char far *plane)
+{
unsigned int size=4;//4 for x/y size
int t1,t2;
int runchar=-1,runsize=-1,chr;
- for(t1=0;t1<board_ysiz;t1++) {
- for(t2=0;t2<board_xsiz;t2++) {
+
+ for(t1=0;t1<board_ysiz;t1++)
+ {
+ for(t2=0;t2<board_xsiz;t2++)
+ {
//Get char
chr=plane[t1*max_bxsiz+t2];
//Continue run?
- if(chr==runchar) {
+ if(chr==runchar)
+ {
//Yep.
runsize++;
//Run size at max of 127?
- if(runsize==127) {
+ if(runsize==127)
+ {
//Store run and reset it.
size+=2;
runchar=runsize=-1;
- }
}
- else {
+ }
+ else
+ {
//Nope- Store current run...
- if((runchar<128)&&(runsize==1)) size++;
- else if(runchar>-1) size+=2;
+ if((runchar<128)&&(runsize==1)) size++;
+ else if(runchar>-1) size+=2;
//...and set up for a new run.
runchar=chr;
runsize=1;
- }
- //Loop.
}
+ //Loop.
}
+ }
//Store last run, if any
- if((runchar<128)&&(runsize==1)) size++;
- else if(runchar>-1) size+=2;
+ if((runchar<128)&&(runsize==1)) size++;
+ else if(runchar>-1) size+=2;
//Done- return size.
return size;
}
//Stores plane in where as RLE2 compressed, using current x/y sizes.
//Returns size.
-unsigned int RLE2_store(unsigned char far *where,unsigned char far *plane) {
+unsigned int RLE2_store(unsigned char far *where,unsigned char far *plane)
+{
unsigned int size=4;//4 for x/y size
int t1,t2;
int runchar=-1,runsize=-1,chr;
+
+ //board_xsiz = 100;
+ //board_ysiz = 50;
+
where[0]=board_xsiz&255; where[1]=board_xsiz>>8;
where[2]=board_ysiz&255; where[3]=board_ysiz>>8;
- for(t1=0;t1<board_ysiz;t1++) {
- for(t2=0;t2<board_xsiz;t2++) {
+
+
+ for(t1=0;t1<board_ysiz;t1++)
+ {
+ for(t2=0;t2<board_xsiz;t2++)
+ {
//Get char
chr=plane[t1*max_bxsiz+t2];
//Continue run?
- if(chr==runchar) {
+ if(chr==runchar)
+ {
//Yep.
runsize++;
//Run size at max of 127?
- if(runsize==127) {
+ if(runsize==127)
+ {
//Store run and reset it.
where[size++]=runsize|128;
where[size++]=runchar;
runchar=runsize=-1;
- }
}
- else {
+ }
+ else
+ {
//Nope- Store current run...
- if((runchar<128)&&(runsize==1)) where[size++]=runchar;
- else if(runchar>-1) {
+ if((runchar<128)&&(runsize==1)) where[size++]=runchar;
+ else if(runchar>-1)
+ {
where[size++]=runsize|128;
where[size++]=runchar;
- }
+ }
//...and set up for a new run.
runchar=chr;
runsize=1;
- }
- //Loop.
}
+ //Loop.
}
+ }
//Store last run, if any
- if((runchar<128)&&(runsize==1)) where[size++]=runchar;
- else if(runchar>-1) {
+ if((runchar<128)&&(runsize==1)) where[size++]=runchar;
+ else if(runchar>-1)
+ {
where[size++]=runsize|128;
where[size++]=runchar;
- }
+ }
//Done.
return size;
}
//Stores plane in file as RLE2 compressed, using current x/y sizes.
-void RLE2_save(FILE *fp,unsigned char far *plane) {
+void RLE2_save(FILE *fp,unsigned char far *plane)
+{
int t1,t2;
int runchar=-1,runsize=-1,chr;
+
fwrite(&board_xsiz,2,1,fp);
fwrite(&board_ysiz,2,1,fp);
- for(t1=0;t1<board_ysiz;t1++) {
- for(t2=0;t2<board_xsiz;t2++) {
+ for(t1=0;t1<board_ysiz;t1++)
+ {
+ for(t2=0;t2<board_xsiz;t2++)
+ {
//Get char
chr=plane[t1*max_bxsiz+t2];
//Continue run?
- if(chr==runchar) {
+ if(chr==runchar)
+ {
//Yep.
runsize++;
//Run size at max of 127?
- if(runsize==127) {
+ if(runsize==127)
+ {
//Store run and reset it.
fputc(runsize|128,fp);
fputc(runchar,fp);
runchar=runsize=-1;
- }
}
- else {
+ }
+ else
+ {
//Nope- Store current run...
- if((runchar<128)&&(runsize==1)) fputc(runchar,fp);
- else if(runchar>-1) {
+ if((runchar<128)&&(runsize==1)) fputc(runchar,fp);
+ else if(runchar>-1)
+ {
fputc(runsize|128,fp);
fputc(runchar,fp);
- }
+ }
//...and set up for a new run.
runchar=chr;
runsize=1;
- }
- //Loop.
}
+ //Loop.
}
+ }
//Store last run, if any
- if((runchar<128)&&(runsize==1)) fputc(runchar,fp);
- else if(runchar>-1) {
+ if((runchar<128)&&(runsize==1)) fputc(runchar,fp);
+ else if(runchar>-1)
+ {
fputc(runsize|128,fp);
fputc(runchar,fp);
- }
+ }
//Done.
}
@@ -275,88 +314,110 @@ void RLE2_save(FILE *fp,unsigned char far *plane) {
//Also sets board_xsiz and board_ysiz unless specified otherwise.
//Returns byte count of RLE2 read.
unsigned int RLE2_read(unsigned char far *where,unsigned char far *plane,
- char change_xysizes) {
+ char change_xysizes)
+{
unsigned int pos=4;//2 for x/y size
int t1,t2,t3,xsiz=where[0]+(where[1]<<8),ysiz=where[2]+(where[3]<<8);
+
int runsize,chr;
- if(change_xysizes) {
+ if(change_xysizes)
+ {
board_xsiz=xsiz;
board_ysiz=ysiz;
- }
+ }
t1=t2=0;//y and x position
- do {
+ do
+ {
chr=where[pos++];
- if(!(chr&128)) {//Regular character
+ if(!(chr&128))
+ {//Regular character
plane[t1*max_bxsiz+t2]=chr;
- if((++t2)>=xsiz) {
+ if((++t2)>=xsiz)
+ {
t2=0;
if((++t1)>=ysiz) goto done;
- }
}
- else {
+ }
+ else
+ {
//A run
runsize=chr&127;
chr=where[pos++];
- for(t3=0;t3<runsize;t3++) {
+ for(t3=0;t3<runsize;t3++)
+ {
plane[t1*max_bxsiz+t2]=chr;
- if((++t2)>=xsiz) {
+ if((++t2)>=xsiz)
+ {
t2=0;
if((++t1)>=ysiz) goto done;
- }
}
}
+ }
} while(1);
-done:
+ done:
//Done!
return pos;
}
//Reads RLE2-compressed plane from file and puts into plane.
//Also sets board_xsiz and board_ysiz unless specified otherwise.
-void RLE2_load(FILE *fp,unsigned char far *plane,char change_xysizes) {
+void RLE2_load(FILE *fp,unsigned char far *plane,char change_xysizes)
+{
int t1,t2,t3,xsiz,ysiz;
int runsize,chr;
fread(&xsiz,2,1,fp);
fread(&ysiz,2,1,fp);
- if(change_xysizes) {
+
+ //xsiz = 100;
+ //ysiz = 50;
+
+ if(change_xysizes)
+ {
board_xsiz=xsiz;
board_ysiz=ysiz;
- }
+ }
t1=t2=0;//y and x position
- do {
+ do
+ {
chr=fgetc(fp);
- if(!(chr&128)) {//Regular character
+ if(!(chr&128))
+ {//Regular character
plane[t1*max_bxsiz+t2]=chr;
- if((++t2)>=xsiz) {
+ if((++t2)>=xsiz)
+ {
t2=0;
if((++t1)>=ysiz) goto done;
- }
}
- else {
+ }
+ else
+ {
//A run
runsize=chr&127;
chr=fgetc(fp);
- for(t3=0;t3<runsize;t3++) {
+ for(t3=0;t3<runsize;t3++)
+ {
plane[t1*max_bxsiz+t2]=chr;
- if((++t2)>=xsiz) {
+ if((++t2)>=xsiz)
+ {
t2=0;
if((++t1)>=ysiz) goto done;
- }
}
}
+ }
} while(1);
-done:
+ done:
//Done!
}
//Gets size current board would take up, were it stored.
-long size_of_current_board(void) {
+long size_of_current_board(void)
+{
long size=224;//Size of info other than board and robots/etc
int t1,count=0;
//Count robots
for(t1=1;t1<NUM_ROBOTS;t1++)
- if(robots[t1].used) count=t1;
- //Add room for robots and all their programs plus the count itself
+ if(robots[t1].used) count=t1;
+ //Add room for robots and all their programs plus the count itself
size+=sizeof(Robot)*count;
if(count)
for(t1=0;t1<count;t1++)
@@ -365,7 +426,7 @@ long size_of_current_board(void) {
count=0;
for(t1=1;t1<NUM_SCROLLS;t1++)
if(scrolls[t1].used) count=t1;
- //Add room for scrolls and all their texts plus the count itself
+ //Add room for scrolls and all their texts plus the count itself
size+=sizeof(Scroll)*count;
if(count)
for(t1=0;t1<count;t1++)
@@ -374,15 +435,16 @@ long size_of_current_board(void) {
count=0;
for(t1=1;t1<NUM_SENSORS;t1++)
if(sensors[t1].used) count=t1;
- //Add room for sensors plus the count itself
+ //Add room for sensors plus the count itself
size+=sizeof(Sensor)*count;
//If overlay on, add room for 2 bytes (one for overlay mode, one
//for indicator bit) and RLE2 of both planes
- if(overlay_mode) {
+ if(overlay_mode)
+ {
size+=2;
size+=RLE2_size(overlay);
size+=RLE2_size(overlay_color);
- }
+ }
//Finally, add room for all six planes, RLE2 encoded, and return
size+=RLE2_size(level_id);
size+=RLE2_size(level_color);
@@ -396,7 +458,8 @@ long size_of_current_board(void) {
//board_sizes and other board variables MUST be accurate. Returns non-0
//if out of room in memory and on disk for working, or for misc. errors.
//Does not affect and is not affected by a current object or global robot.
-char store_current(unsigned char id) {
+char store_current(unsigned char id)
+{
unsigned char far *ptr;//Where to store for mem/ems
unsigned char far *old_ptr;//Saves old ems allocated ptr
FILE *fp;//Where to store for tempfile (or ems if pressed for space)
@@ -406,57 +469,64 @@ char store_current(unsigned char id) {
//has two major parts- The code for memory/ems, and the code for temp
//files.
//Switch according to storage type.
- switch(board_where[id]) {
+ switch(board_where[id])
+ {
case W_MEMORY:
case W_EMS:
//If EMS, allocate a temporary area to allow storage in conventional
//memory for now, then copy to EMS later. If not possible, we use a
//temp file and then copy THAT to EMS later. If no room for a temp
//file... return error.
- if(board_where[id]==W_EMS) {
+ if(board_where[id]==W_EMS)
+ {
//Allocate a temporary area
ptr=(unsigned char far *)farmalloc(board_sizes[id]);
- if(ptr==NULL) {
+ if(ptr==NULL)
+ {
//No room in mem- try a temp file
//Make temporary filename
str_cpy(&board_filenames[id*FILENAME_SIZE],"~MZTMPXXXXXX");
mktemp(&board_filenames[id*FILENAME_SIZE]);
//Open..
fp=fopen(&board_filenames[id*FILENAME_SIZE],"wb+");
- if(fp==NULL) {
+ if(fp==NULL)
+ {
//Error
board_filenames[id*FILENAME_SIZE]=0;
return 1;
- }
+ }
//Try to make room
fseek(fp,board_sizes[id],SEEK_SET);
- if(ftell(fp)!=(board_sizes[id])) {
+ if(ftell(fp)!=(board_sizes[id]))
+ {
//Not enough room on hard drive
fclose(fp);
unlink(&board_filenames[id*FILENAME_SIZE]);
board_filenames[id*FILENAME_SIZE]=0;
return 2;
- }
+ }
//Room made! Solidify.
fseek(fp,-1,SEEK_CUR);
fputc(0,fp);
fclose(fp);
//Go to tempfile storage
goto store_tempfile;
- }
- else old_ptr=ptr;
}
+ else old_ptr=ptr;
+ }
else ptr=(unsigned char far *)board_offsets[id].mem;
*(ptr++)=max_bsiz_mode;
//Store RLE2 stuff
- if(overlay_mode) {
+ if(overlay_mode)
+ {
*(ptr++)=0;
*(ptr++)=overlay_mode;
ptr+=RLE2_store((unsigned char far*)ptr,overlay);
normalize(ptr);
ptr+=RLE2_store((unsigned char far*)ptr,overlay_color);
normalize(ptr);
- }
+ }
+
ptr+=RLE2_store((unsigned char far *)ptr,level_id);
normalize(ptr);
ptr+=RLE2_store((unsigned char far *)ptr,level_color);
@@ -532,66 +602,73 @@ char store_current(unsigned char id) {
//Robot count
count=0;
for(t1=1;t1<NUM_ROBOTS;t1++)
- if(robots[t1].used) count=t1;
+ if(robots[t1].used) count=t1;
*(ptr++)=count;
//Robots themselves
prepare_robot_mem();
- if(count) {
- for(t1=1;t1<=count;t1++) {
+ if(count)
+ {
+ for(t1=1;t1<=count;t1++)
+ {
//Copy robot t1
mem_cpy((char far *)ptr,(char far *)&robots[t1],sizeof(Robot));
ptr+=sizeof(Robot);
normalize(ptr);
mem_cpy((char far *)ptr,
- (char far *)&robot_mem[robots[t1].program_location],
- robots[t1].program_length);
+ (char far *)&robot_mem[robots[t1].program_location],
+ robots[t1].program_length);
ptr+=robots[t1].program_length;
- }
}
+ }
//Scroll count
count=0;
for(t1=1;t1<NUM_SCROLLS;t1++)
if(scrolls[t1].used) count=t1;
*(ptr++)=count;
//Scrolls themselves
- if(count) {
- for(t1=1;t1<=count;t1++) {
+ if(count)
+ {
+ for(t1=1;t1<=count;t1++)
+ {
//Copy scroll t1
mem_cpy((char far *)ptr,(char far *)&scrolls[t1],sizeof(Scroll));
ptr+=sizeof(Scroll);
normalize(ptr);
mem_cpy((char far *)ptr,
- (char far *)&robot_mem[scrolls[t1].mesg_location],
- scrolls[t1].mesg_size);
+ (char far *)&robot_mem[scrolls[t1].mesg_location],
+ scrolls[t1].mesg_size);
ptr+=scrolls[t1].mesg_size;
- }
}
+ }
//Sensor count
count=0;
for(t1=1;t1<NUM_SENSORS;t1++)
if(sensors[t1].used) count=t1;
*(ptr++)=count;
//Sensors themselves
- if(count) {
- for(t1=1;t1<=count;t1++) {
+ if(count)
+ {
+ for(t1=1;t1<=count;t1++)
+ {
//Copy sensor t1
mem_cpy((char far *)ptr,(char far *)&sensors[t1],sizeof(Sensor));
ptr+=sizeof(Sensor);
- }
}
+ }
//All copied! Return if memory...
- if(board_where[id]==W_MEMORY) return 0;
+ if(board_where[id]==W_MEMORY) return 0;
//...otherwise copy to EMS.
//Copy a page at a time...
t1=board_offsets[id].EMS.page;//Current page
copied=0;//Copied nothing so far.
ptr=old_ptr;//Use original pointer
- do {
+ do
+ {
//Map page
map_page_EMS(board_offsets[id].EMS.handle,0,t1);
//Copy a page, or part of a page if that's all that's left.
tcpy=16384;
- if((copied+tcpy)>board_sizes[id]) //Too much...
+ if((copied+tcpy)>board_sizes[id]) //Too much...
tcpy=(int)(board_sizes[id]-(unsigned long)copied);
//Now copy it...
mem_cpy(page_frame_EMS,(char far *)ptr,tcpy);
@@ -606,24 +683,26 @@ char store_current(unsigned char id) {
farfree(old_ptr);
return 0;
case W_TEMPFILE:
- store_tempfile:
+ store_tempfile:
//This is storage in a tempfile, sometimes a subfuction of storage
//in EMS.
//Open file...
fp=fopen(&board_filenames[id*FILENAME_SIZE],"rb+");
- if(fp==NULL) {
+ if(fp==NULL)
+ {
if(board_where[id]==W_EMS) board_filenames[id*FILENAME_SIZE]=0;
return 1;//Error...
- }
+ }
//...and begin output!
fputc(max_bsiz_mode,fp);
//Store RLE2 stuff
- if(overlay_mode) {
+ if(overlay_mode)
+ {
fputc(0,fp);
fputc(overlay_mode,fp);
RLE2_save(fp,overlay);
RLE2_save(fp,overlay_color);
- }
+ }
RLE2_save(fp,level_id);
RLE2_save(fp,level_color);
RLE2_save(fp,level_param);
@@ -681,58 +760,65 @@ char store_current(unsigned char id) {
//Robot count
count=0;
for(t1=1;t1<NUM_ROBOTS;t1++)
- if(robots[t1].used) count=t1;
+ if(robots[t1].used) count=t1;
fputc(count,fp);
//Robots themselves
prepare_robot_mem();
- if(count) {
- for(t1=1;t1<=count;t1++) {
+ if(count)
+ {
+ for(t1=1;t1<=count;t1++)
+ {
//Copy robot t1
fwrite(&robots[t1],sizeof(Robot),1,fp);
fwrite(&robot_mem[robots[t1].program_location],1,
- robots[t1].program_length,fp);
- }
+ robots[t1].program_length,fp);
}
+ }
//Scroll count
count=0;
for(t1=1;t1<NUM_SCROLLS;t1++)
if(scrolls[t1].used) count=t1;
fputc(count,fp);
//Scrolls themselves
- if(count) {
- for(t1=1;t1<=count;t1++) {
+ if(count)
+ {
+ for(t1=1;t1<=count;t1++)
+ {
//Copy scroll t1
fwrite(&scrolls[t1],sizeof(Scroll),1,fp);
fwrite(&robot_mem[scrolls[t1].mesg_location],1,
- scrolls[t1].mesg_size,fp);
- }
+ scrolls[t1].mesg_size,fp);
}
+ }
//Sensor count
count=0;
for(t1=1;t1<NUM_SENSORS;t1++)
if(sensors[t1].used) count=t1;
fputc(count,fp);
//Sensors themselves
- if(count) {
+ if(count)
+ {
for(t1=1;t1<=count;t1++) //Copy sensor t1
fwrite(&sensors[t1],sizeof(Sensor),1,fp);
- }
+ }
//All saved! Return if tempfile...
- if(board_where[id]==W_TEMPFILE) {
+ if(board_where[id]==W_TEMPFILE)
+ {
fclose(fp);
return 0;
- }
+ }
//...otherwise copy to EMS.
//Copy a page at a time...
t1=board_offsets[id].EMS.page;//Current page
copied=0;//Copied nothing so far.
fseek(fp,0,SEEK_SET);//Return to start of file
- do {
+ do
+ {
//Map page
map_page_EMS(board_offsets[id].EMS.handle,0,t1);
//Copy a page, or part of a page if that's all that's left.
tcpy=16384;
- if((copied+tcpy)>board_sizes[id]) //Too much...
+ if((copied+tcpy)>board_sizes[id]) //Too much...
tcpy=(int)(board_sizes[id]-(unsigned long)copied);
//Now copy it...
fread(page_frame_EMS,tcpy,1,fp);
@@ -746,7 +832,7 @@ char store_current(unsigned char id) {
unlink(&board_filenames[id*FILENAME_SIZE]);
board_filenames[id*FILENAME_SIZE]=0;
return 0;
- }
+ }
return 3;
}
@@ -756,7 +842,8 @@ char store_current(unsigned char id) {
//Returns 4 if out of robot memory. (This is usually due to a large current
//robot/scroll or a large global robot) Does not affect current object or
//global robot.
-char grab_current(unsigned char id) {
+char grab_current(unsigned char id)
+{
unsigned char far *ptr;//Where to grab from for mem/ems
unsigned char far *old_ptr;//Saves old ems allocated ptr
FILE *fp;//Where to grab from for tempfile (or ems if pressed for space)
@@ -767,101 +854,123 @@ char grab_current(unsigned char id) {
//has two major parts- The code for memory/ems, and the code for temp
//files.
//Switch according to storage type.
- switch(board_where[id]) {
+
+ switch(board_where[id])
+ {
case W_EMS:
//If EMS, allocate a temporary area to allow storage in conventional
//memory for now, then copy to robots/etc. later. If not possible,
//we use a temp file and then copy THAT to mem. later. If no room
//for a temp file... return error.
- if(board_where[id]==W_EMS) {
- //Allocate a temporary area
- ptr=(unsigned char far *)farmalloc(board_sizes[id]);
- if(ptr==NULL) {
- //No room in mem- try a temp file
- //Make temporary filename
- str_cpy(&board_filenames[id*FILENAME_SIZE],"~MZTMPXXXXXX");
- mktemp(&board_filenames[id*FILENAME_SIZE]);
- //Open..
- fp=fopen(&board_filenames[id*FILENAME_SIZE],"wb+");
- if(fp==NULL) {
- //Error
- board_filenames[id*FILENAME_SIZE]=0;
- return 1;
- }
- //Try to make room
- fseek(fp,board_sizes[id],SEEK_SET);
- if(ftell(fp)!=(board_sizes[id])) {
- //Not enough room on hard drive
- fclose(fp);
- unlink(&board_filenames[id*FILENAME_SIZE]);
- board_filenames[id*FILENAME_SIZE]=0;
- return 2;
- }
- //Room made! Solidify.
- fseek(fp,-1,SEEK_CUR);
- fputc(0,fp);
- //Load from EMS
- //Copy a page at a time...
- t1=board_offsets[id].EMS.page;//Current page
- copied=0;//Copied nothing so far.
- fseek(fp,0,SEEK_SET);//Return to start of file
- do {
- //Map page
- map_page_EMS(board_offsets[id].EMS.handle,0,t1);
- //Copy a page, or part of a page if that's all that's left.
- tcpy=16384;
- if((copied+tcpy)>board_sizes[id]) //Too much...
- tcpy=(int)(board_sizes[id]-(unsigned long)copied);
- //Now copy it...
- fwrite(page_frame_EMS,tcpy,1,fp);
- //...increment status...
- copied+=tcpy;
- t1++;//Page
- //...loop.
- } while(copied<board_sizes[id]);
- //All copied! Close file and jump to tempfile code
- fclose(fp);
- goto grab_tempfile;
- }
- //Allocated. Copy from EMS to memory first...
- old_ptr=ptr;
- //Copy a page at a time...
- t1=board_offsets[id].EMS.page;//Current page
- copied=0;//Copied nothing so far.
- do {
- //Map page
- map_page_EMS(board_offsets[id].EMS.handle,0,t1);
- //Copy a page, or part of a page if that's all that's left.
- tcpy=16384;
- if((copied+tcpy)>board_sizes[id]) //Too much...
- tcpy=(int)(board_sizes[id]-(unsigned long)copied);
- //Now copy it...
- mem_cpy((char far *)ptr,page_frame_EMS,tcpy);
- //...increment status...
- copied+=tcpy;
- ptr+=tcpy;
- normalize(ptr);
- t1++;//Page
- //...loop.
- } while(copied<board_sizes[id]);
- //All copied! Now do regular memory code.
- ptr=old_ptr;//Restore pointer
- goto grab_memory;
- }
+ //Allocate a temporary area
+ ptr=(unsigned char far *)farmalloc(board_sizes[id]);
+ if(ptr==NULL)
+ {
+ //No room in mem- try a temp file
+ //Make temporary filename
+ str_cpy(&board_filenames[id*FILENAME_SIZE],"~MZTMPXXXXXX");
+ mktemp(&board_filenames[id*FILENAME_SIZE]);
+ //Open..
+ fp=fopen(&board_filenames[id*FILENAME_SIZE],"wb+");
+ if(fp==NULL)
+ {
+ //Error
+ board_filenames[id*FILENAME_SIZE]=0;
+ return 1;
+ }
+ //Try to make room
+ fseek(fp,board_sizes[id],SEEK_SET);
+ if(ftell(fp)!=(board_sizes[id]))
+ {
+ //Not enough room on hard drive
+ fclose(fp);
+ unlink(&board_filenames[id*FILENAME_SIZE]);
+ board_filenames[id*FILENAME_SIZE]=0;
+ return 2;
+ }
+ //Room made! Solidify.
+ fseek(fp,-1,SEEK_CUR);
+ fputc(0,fp);
+ //Load from EMS
+ //Copy a page at a time...
+ t1=board_offsets[id].EMS.page;//Current page
+ copied=0;//Copied nothing so far.
+ fseek(fp,0,SEEK_SET);//Return to start of file
+ do
+ {
+ //Map page
+ map_page_EMS(board_offsets[id].EMS.handle,0,t1);
+ //Copy a page, or part of a page if that's all that's left.
+ tcpy=16384;
+ if((copied+tcpy)>board_sizes[id]) //Too much...
+ tcpy=(int)(board_sizes[id]-(unsigned long)copied);
+ //Now copy it...
+ fwrite(page_frame_EMS,tcpy,1,fp);
+ //...increment status...
+ copied+=tcpy;
+ t1++;//Page
+ //...loop.
+ } while(copied<board_sizes[id]);
+ //All copied! Close file and jump to tempfile code
+ fclose(fp);
+ goto grab_tempfile;
+ }
+ //Allocated. Copy from EMS to memory first...
+ old_ptr=ptr;
+ //Copy a page at a time...
+ t1=board_offsets[id].EMS.page;//Current page
+ copied=0;//Copied nothing so far.
+ do
+ {
+ //Map page
+ map_page_EMS(board_offsets[id].EMS.handle,0,t1);
+ //Copy a page, or part of a page if that's all that's left.
+ tcpy=16384;
+ if((copied+tcpy)>board_sizes[id]) //Too much...
+ tcpy=(int)(board_sizes[id]-(unsigned long)copied);
+ //Now copy it...
+ mem_cpy((char far *)ptr,page_frame_EMS,tcpy);
+ //...increment status...
+ copied+=tcpy;
+ ptr+=tcpy;
+ normalize(ptr);
+ t1++;//Page
+ //...loop.
+ } while(copied<board_sizes[id]);
+ //All copied! Now do regular memory code.
+ ptr=old_ptr;//Restore pointer
+ goto grab_memory;
+
case W_MEMORY:
ptr=(unsigned char far *)board_offsets[id].mem;
- grab_memory:
+
+ grab_memory:
+
//Clear overlay
overlay_mode=0;
- for(t1=0;t1<10000;t1++) {
+ for(t1=0;t1<10000;t1++)
+ {
level_id[t1]=level_under_id[t1]=level_param[t1]=level_under_param[t1]=0;
level_color[t1]=level_under_color[t1]=overlay_color[t1]=7;
overlay[t1]=32;
- }
+ }
max_bsiz_mode=*(ptr++);
convert_max_bsiz_mode();
//Load RLE2 stuff
- if(*ptr==0) {
+
+ // Oh Greg NO. According to the board specs, the first byte being 0 here
+ // means that there's no overlay. Otherwise, this byte is the first byte of
+ // the board width for the level stuff. But what Greg didn't realize is that
+ // the first byte can be 0 for a board without overlay if the width is 256.
+ // So if the width is 256, it will try to load an overlay that's not there and
+ // totally eat the game. Solution? Um... well you can't just check the entire
+ // word because the latter 8bits won't necessarily be 0. So 0 1 bytes mean
+ // either 256 width no overlay, or overlay mode 1, you can't tell the
+ // difference. You can guess by looking at the word following this one to see
+ // if it's less than 26 (which it must be for the board to be 256 wide) but
+ // this value in overlay mode may be less than 256.
+ if(*ptr == 0)
+ {
//Overlay
ptr++;
overlay_mode=*(ptr++);
@@ -869,7 +978,8 @@ char grab_current(unsigned char id) {
normalize(ptr);
ptr+=RLE2_read((unsigned char far *)ptr,overlay_color);
normalize(ptr);
- }
+ }
+
ptr+=RLE2_read((unsigned char far *)ptr,level_id);
normalize(ptr);
ptr+=RLE2_read((unsigned char far *)ptr,level_color);
@@ -882,13 +992,14 @@ char grab_current(unsigned char id) {
normalize(ptr);
ptr+=RLE2_read((unsigned char far *)ptr,level_under_param);
normalize(ptr);
+
//Read variables- Due to the way they are stored in DATA.ASM,
//they can all be read as a series of 210 bytes starting at
//mod_playing. Appropriate code to read each individually is
//also included in case this ever fails. To use the individual
//code, define the symbol SAVE_INDIVIDUAL.
-#ifndef SAVE_INDIVIDUAL
+#ifndef SAVE_INDIVIDUAL
mem_cpy(mod_playing,(char far *)ptr,207+FILENAME_SIZE);
ptr+=207+FILENAME_SIZE;
#else
@@ -896,7 +1007,7 @@ char grab_current(unsigned char id) {
ptr+=FILENAME_SIZE;
viewport_x=*(ptr++);
- viewport_y=*(ptr++);
+ viewport_y=*(ptr++);
viewport_xsiz=*(ptr++);
viewport_ysiz=*(ptr++);
can_shoot=*(ptr++);
@@ -943,21 +1054,29 @@ char grab_current(unsigned char id) {
volume_inc=*(ptr++);
volume_target=*(ptr++);
#endif
+
//Before doing robots/scrolls, make sure all but #0 and global
//are allocated to the minimum. Also clear all sensors.
prepare_robot_mem();
+
for(t1=1;t1<NUM_ROBOTS;t1++)
clear_robot(t1);
+
for(t1=1;t1<NUM_SCROLLS;t1++)
clear_scroll(t1);
+
for(t1=1;t1<NUM_SENSORS;t1++)
clear_sensor(t1);
+
//Robots- get count, then load 'em up. All must be allocated
//first. A mis-allocation frees any ems memory and returns error
//code #4.
+
count=*(ptr++);
- if(count) {
- for(t1=1;t1<=count;t1++) {
+ if(count)
+ {
+ for(t1=1;t1<=count;t1++)
+ {
//Read robot t1
oldsize=robots[t1].program_length;
oldloc=robots[t1].program_location;
@@ -967,22 +1086,26 @@ char grab_current(unsigned char id) {
newsize=robots[t1].program_length;
robots[t1].program_length=oldsize;
robots[t1].program_location=oldloc;
- if(reallocate_robot_mem(T_ROBOT,t1,newsize)) {
+ if(reallocate_robot_mem(T_ROBOT,t1,newsize))
+ {
//Error in allocation.
//EMS- delete temp area
if(board_where[id]==W_EMS) farfree(ptr);
return 4;
- }
+ }
//Load in robot
mem_cpy((char far *)&robot_mem[robots[t1].program_location],
- (char far *)ptr,robots[t1].program_length);
+ (char far *)ptr,robots[t1].program_length);
ptr+=robots[t1].program_length;
- }
}
+ }
+
//Scroll count
count=*(ptr++);
- if(count) {
- for(t1=1;t1<=count;t1++) {
+ if(count)
+ {
+ for(t1=1;t1<=count;t1++)
+ {
//Read scroll t1
oldsize=scrolls[t1].mesg_size;
oldloc=scrolls[t1].mesg_location;
@@ -992,57 +1115,64 @@ char grab_current(unsigned char id) {
newsize=scrolls[t1].mesg_size;
scrolls[t1].mesg_size=oldsize;
scrolls[t1].mesg_location=oldloc;
- if(reallocate_robot_mem(T_SCROLL,t1,newsize)) {
+ if(reallocate_robot_mem(T_SCROLL,t1,newsize))
+ {
//Error in allocation.
//EMS- delete temp area
if(board_where[id]==W_EMS) farfree(ptr);
return 4;
- }
+ }
mem_cpy((char far *)&robot_mem[scrolls[t1].mesg_location],
- (char far *)ptr,scrolls[t1].mesg_size);
+ (char far *)ptr,scrolls[t1].mesg_size);
ptr+=scrolls[t1].mesg_size;
- }
}
+ }
+
//Sensor count
count=*(ptr++);
- if(count) {
- for(t1=1;t1<=count;t1++) {
+ if(count)
+ {
+ for(t1=1;t1<=count;t1++)
+ {
//Read sensor t1
mem_cpy((char far *)&sensors[t1],(char far *)ptr,sizeof(Sensor));
ptr+=sizeof(Sensor);
- }
}
+ }
//All grabbed! Return if memory...
- if(board_where[id]==W_MEMORY) return 0;
+ if(board_where[id]==W_MEMORY) return 0;
//...otherwise free EMS temp memory.
farfree(old_ptr);
return 0;
case W_TEMPFILE:
- grab_tempfile:
+ grab_tempfile:
//This is loading from a tempfile, sometimes a subfuction of loading
//from EMS.
//Open file...
fp=fopen(&board_filenames[id*FILENAME_SIZE],"rb");
- if(fp==NULL) {
+ if(fp==NULL)
+ {
if(board_where[id]==W_EMS) board_filenames[id*FILENAME_SIZE]=0;
return 1;//Error...
- }
+ }
//...and begin input!
//Clear overlay
overlay_mode=0;
- for(t1=0;t1<10000;t1++) {
+ for(t1=0;t1<10000;t1++)
+ {
level_id[t1]=level_under_id[t1]=level_param[t1]=level_under_param[t1]=0;
level_color[t1]=level_under_color[t1]=overlay_color[t1]=7;
overlay[t1]=32;
- }
+ }
max_bsiz_mode=fgetc(fp);
convert_max_bsiz_mode();
//Overlay
- if(fgetc(fp)==0) {
+ if(fgetc(fp)==0)
+ {
overlay_mode=fgetc(fp);
RLE2_load(fp,overlay);
RLE2_load(fp,overlay_color);
- }
+ }
else fseek(fp,-1,SEEK_CUR);
//load RLE2 stuff
RLE2_load(fp,level_id);
@@ -1113,8 +1243,10 @@ char grab_current(unsigned char id) {
//first. A mis-allocation frees any ems memory and returns error
//code #4.
count=fgetc(fp);
- if(count) {
- for(t1=1;t1<=count;t1++) {
+ if(count)
+ {
+ for(t1=1;t1<=count;t1++)
+ {
//Read robot t1
oldsize=robots[t1].program_length;
oldloc=robots[t1].program_location;
@@ -1122,25 +1254,29 @@ char grab_current(unsigned char id) {
newsize=robots[t1].program_length;
robots[t1].program_length=oldsize;
robots[t1].program_location=oldloc;
- if(reallocate_robot_mem(T_ROBOT,t1,newsize)) {
+ if(reallocate_robot_mem(T_ROBOT,t1,newsize))
+ {
//Error in allocation.
fclose(fp);
//EMS- delete temp file
- if(board_where[id]==W_EMS) {
+ if(board_where[id]==W_EMS)
+ {
unlink(&board_filenames[id*FILENAME_SIZE]);
board_filenames[id*FILENAME_SIZE]=0;
- }
- return 4;
}
+ return 4;
+ }
//Load in robot
fread(&robot_mem[robots[t1].program_location],1,
- robots[t1].program_length,fp);
- }
+ robots[t1].program_length,fp);
}
+ }
//Scroll count
count=fgetc(fp);
- if(count) {
- for(t1=1;t1<=count;t1++) {
+ if(count)
+ {
+ for(t1=1;t1<=count;t1++)
+ {
//Read scroll t1
oldsize=scrolls[t1].mesg_size;
oldloc=scrolls[t1].mesg_location;
@@ -1148,34 +1284,37 @@ char grab_current(unsigned char id) {
newsize=scrolls[t1].mesg_size;
scrolls[t1].mesg_size=oldsize;
scrolls[t1].mesg_location=oldloc;
- if(reallocate_robot_mem(T_SCROLL,t1,newsize)) {
+ if(reallocate_robot_mem(T_SCROLL,t1,newsize))
+ {
//Error in allocation.
fclose(fp);
//EMS- delete temp file
- if(board_where[id]==W_EMS) {
+ if(board_where[id]==W_EMS)
+ {
unlink(&board_filenames[id*FILENAME_SIZE]);
board_filenames[id*FILENAME_SIZE]=0;
- }
- return 4;
}
- fread(&robot_mem[scrolls[t1].mesg_location],1,
- scrolls[t1].mesg_size,fp);
+ return 4;
}
+ fread(&robot_mem[scrolls[t1].mesg_location],1,
+ scrolls[t1].mesg_size,fp);
}
+ }
//Sensor count
count=fgetc(fp);
- if(count) {
+ if(count)
+ {
for(t1=1;t1<=count;t1++) //Read sensor t1
fread(&sensors[t1],sizeof(Sensor),1,fp);
- }
+ }
//All loaded! Return if tempfile...
fclose(fp);
- if(board_where[id]==W_TEMPFILE) return 0;
+ if(board_where[id]==W_TEMPFILE) return 0;
//...otherwise erase EMS file.
unlink(&board_filenames[id*FILENAME_SIZE]);
board_filenames[id*FILENAME_SIZE]=0;
return 0;
- }
+ }
return 3;
}
@@ -1185,24 +1324,27 @@ char grab_current(unsigned char id) {
//to save time for the same result. Returns non-0 for misc. errors.
//Set loading to non-0 to load FROM file, 0 to save TO file.
char disk_board(unsigned char id,FILE *fp,char loading,
- unsigned char xor_with) {
+ unsigned char xor_with)
+{
unsigned int siz,cpg1,buffsize;
long copied=0,tmp;
char far *ptr;
FILE *destfp;
//Switch according to storage type.
- switch(board_where[id]) {
+ switch(board_where[id])
+ {
case W_MEMORY:
//Simply do a fread then a mem_xor. Must be read in chunks in case
//size is larger than an unsigned int.
ptr=(char far *)board_offsets[id].mem;
- do {
+ do
+ {
siz=(unsigned int)(board_sizes[id]-copied);
- if((board_sizes[id]-copied)>32768U) siz=32768U;
+ if((board_sizes[id]-copied)>32768U) siz=32768U;
if(!loading)//If saving, must xor first, but later xor again
- //to restore memory copy to normal.
+ //to restore memory copy to normal.
if(xor_with) mem_xor(ptr,siz,xor_with);
- if(loading) fread(ptr,siz,1,fp);//LOAD
+ if(loading) fread(ptr,siz,1,fp);//LOAD
else fwrite(ptr,siz,1,fp);//SAVE
if(xor_with) mem_xor(ptr,siz,xor_with);
copied+=siz;
@@ -1213,14 +1355,15 @@ char disk_board(unsigned char id,FILE *fp,char loading,
case W_EMS:
//Simply do a fread then a mem_xor. Read in chunks of one page.
cpg1=board_offsets[id].EMS.page;
- do {
+ do
+ {
map_page_EMS(board_offsets[id].EMS.handle,0,cpg1);
siz=(unsigned int)(board_sizes[id]-copied);
if((board_sizes[id]-copied)>16384) siz=16384;
if(!loading)//If saving, must xor first, but later xor again
- //to restore memory copy to normal.
+ //to restore memory copy to normal.
if(xor_with) mem_xor(page_frame_EMS,siz,xor_with);
- if(loading) fread(page_frame_EMS,siz,1,fp);//LOAD
+ if(loading) fread(page_frame_EMS,siz,1,fp);//LOAD
else fwrite(page_frame_EMS,siz,1,fp);//SAVE
if(xor_with) mem_xor(page_frame_EMS,siz,xor_with);
copied+=siz;
@@ -1237,26 +1380,28 @@ char disk_board(unsigned char id,FILE *fp,char loading,
//buffers from fp to dest file, xor'ing if required. If buffer
//cannot be allocated, does it directly. (IE one byte at a time)
copied=farcoreleft();
- if(copied>32768U) buffsize=32768U;
+ if(copied>32768U) buffsize=32768U;
else buffsize=(unsigned int)copied;
- if(buffsize>=128) {
+ if(buffsize>=128)
+ {
//Allocate buffer
ptr=(char far *)farmalloc(buffsize);
- if(ptr==NULL) //Huh? Ok we'll do singles..
+ if(ptr==NULL) //Huh? Ok we'll do singles..
goto transfer_bytewise;
//Do transferring
copied=0;
- do {
+ do
+ {
//Pick size
siz=((unsigned int)(board_sizes[id]-copied));
if(board_sizes[id]>buffsize) siz=buffsize;
//Read
- if(loading) fread(ptr,siz,1,fp);
+ if(loading) fread(ptr,siz,1,fp);
else fread(ptr,siz,1,destfp);
//XOR
if(xor_with) mem_xor(ptr,siz,xor_with);
//Write
- if(loading) fwrite(ptr,siz,1,destfp);
+ if(loading) fwrite(ptr,siz,1,destfp);
else fwrite(ptr,siz,1,fp);
//Update variables
copied+=siz;
@@ -1265,26 +1410,30 @@ char disk_board(unsigned char id,FILE *fp,char loading,
farfree(ptr);
fclose(destfp);
return 0;
- }
- transfer_bytewise:
+ }
+ transfer_bytewise:
//Couldn't allocate memory buffer. Do transfer byte by byte...
tmp=board_sizes[id];
- if(xor_with) {
- for(;copied<tmp;copied++) {//Read, XOR, and write
- if(loading) fputc(fgetc(fp)^xor_with,destfp);
+ if(xor_with)
+ {
+ for(;copied<tmp;copied++)
+ {//Read, XOR, and write
+ if(loading) fputc(fgetc(fp)^xor_with,destfp);
else fputc(fgetc(destfp)^xor_with,fp);
- }
}
- else {
- for(;copied<tmp;copied++) {//Read, XOR, and write
- if(loading) fputc(fgetc(fp),destfp);
+ }
+ else
+ {
+ for(;copied<tmp;copied++)
+ {//Read, XOR, and write
+ if(loading) fputc(fgetc(fp),destfp);
else fputc(fgetc(destfp),fp);
- }
}
+ }
//Done! Close file.
fclose(destfp);
return 0;
- }
+ }
//Misc. error
return 2;
}
@@ -1293,7 +1442,8 @@ char disk_board(unsigned char id,FILE *fp,char loading,
//conventional memory to either EMS or disk. If there is no more room on
//disk/EMS, then boards are no longer moved. Runs a meter.
-void free_up_board_memory(void) {
+void free_up_board_memory(void)
+{
int t1,t2,nmb=0,nb_done=0;
unsigned char far *tmp_ptr;
unsigned char far *ptr;
@@ -1302,42 +1452,48 @@ void free_up_board_memory(void) {
char temp=curr_rmem_status;
FILE *fp;
//Count boards
- for(t1=0;t1<NUM_BOARDS;t1++) {
- if(board_where[t1]==W_MEMORY) nmb++;
- }
+ for(t1=0;t1<NUM_BOARDS;t1++)
+ {
+ if(board_where[t1]==W_MEMORY) nmb++;
+ }
if(nmb==0) return;//None to swap!
save_screen(current_pg_seg);
meter("Swapping boards to disk/EMS...",current_pg_seg,nb_done,nmb);
//Go through the boards, picking out those in conventional memory...
- for(t1=0;t1<NUM_BOARDS;t1++) {
- if(board_where[t1]==W_MEMORY) {
+ for(t1=0;t1<NUM_BOARDS;t1++)
+ {
+ if(board_where[t1]==W_MEMORY)
+ {
//Ok, board #t1 is in conventional memory. Now we need to try to
//allocate a new area for it in anything BUT conventional memory.
//First, since the allocate function destroys the allocation
//variables, we need to save board_offset. (board_where is obvious
//and board_sizes/board_filenames are not affected)
tmp_ptr=board_offsets[t1].mem;
- if(allocate_board_space(board_sizes[t1],t1,0)) {
+ if(allocate_board_space(board_sizes[t1],t1,0))
+ {
//No room. Restore variables and return.
board_offsets[t1].mem=tmp_ptr;
board_where[t1]=W_MEMORY;
restore_screen(current_pg_seg);
return;
- }
+ }
//Aha, new area allocated. Switch for EMS or disk.
- switch(board_where[t1]) {
+ switch(board_where[t1])
+ {
case W_EMS:
//Copy to EMS from tmp_ptr for board_sizes[t1] bytes.
//Copy a page at a time...
t2=board_offsets[t1].EMS.page;//Current page
copied=0;//Copied nothing so far.
ptr=tmp_ptr;//Use a copy of the ptr so we save it
- do {
+ do
+ {
//Map page
map_page_EMS(board_offsets[t1].EMS.handle,0,t2);
//Copy a page, or part of a page if that's all that's left.
tcpy=16384;
- if((copied+tcpy)>board_sizes[t1]) //Too much...
+ if((copied+tcpy)>board_sizes[t1]) //Too much...
tcpy=(int)(board_sizes[t1]-(unsigned long)copied);
//Now copy it...
mem_cpy(page_frame_EMS,(char far *)ptr,tcpy);
@@ -1353,17 +1509,19 @@ void free_up_board_memory(void) {
case W_TEMPFILE:
//We're saving memory to a disk file. REAL simple.
fp=fopen(&board_filenames[t1*FILENAME_SIZE],"rb+");
- if(fp==NULL) {
+ if(fp==NULL)
+ {
//Not gonna work.
board_offsets[t1].mem=tmp_ptr;
board_where[t1]=W_MEMORY;
board_filenames[t1*FILENAME_SIZE]=0;
break;
- }
+ }
//Do in chunks of 32768 bytes.
ptr=tmp_ptr;
copied=0;
- do {
+ do
+ {
tcpy=(unsigned int)board_sizes[t1];
if(board_sizes[t1]>32768U) tcpy=32768U;
fwrite(ptr,tcpy,1,fp);//SAVE
@@ -1378,19 +1536,21 @@ void free_up_board_memory(void) {
//Error.
restore_screen(current_pg_seg);
error("Error accessing boards",2,20,current_pg_seg,0x0701);
- }
+ }
//All done with THIS board.
meter_interior(current_pg_seg,++nb_done,nmb);
- }
- //Loop to next board.
}
+ //Loop to next board.
+ }
restore_screen(current_pg_seg);
//All done totally.
prepare_robot_mem(temp);
}
-void convert_max_bsiz_mode(void) {
- switch(max_bsiz_mode) {
+void convert_max_bsiz_mode(void)
+{
+ switch(max_bsiz_mode)
+ {
case 0:
max_bxsiz=60;
max_bysiz=166;
@@ -1411,5 +1571,5 @@ void convert_max_bsiz_mode(void) {
max_bxsiz=400;
max_bysiz=25;
break;
- }
+ }
}
View
237 coms.txt
@@ -1,237 +0,0 @@
-[str] = variable name, array location
-## = variable name, array location, number,function
-
-Data Types
-counter = float
-array = float[]
-string = char[]
-
-INPUT COMMAND
-getString
-keyPressed
-mouseClick
-
-
-DATA COMMAND
-set int [str] ##
-set string [str] "...."
-set float [str] ##.##
-
-
-inc [str] ##
-dec [str] ##
-
-
-
-Functions
-
-multiply [str] ##
-divide [str] ##
-
-pow [str] ##
-log [str] ##,##
-
-abs [str]
-
-rshift [str]
-lshift [str]
-
-
-
-String Commands
-
-
-
-
-
-
-
-
-
-
-
-
-
-ID EOC Command
---- --- -------
-0 x End
-1 x Die
-2 x Wait [##]
-3 Cycle [##]
-4 x g Go [dir] [##]
-5 g Walk [dir]
-
-7 g Char [ch]
-8 g Color [col]
-9 x g Gotoxy [-#] [-#]
-
-10 Set [str] [##]
-11 Inc [str] [##]
-12 Dec [str] [##]
-
-16 If [str] [!<>=] [##] [str]
-
-18 g If [cond] [str]
-19 g If not [cond] [str]
-20 If any [color/thing/param] [str] (different)
-21 If not any [color/thing/param] [str] (different)
-22 If [color/thing/param] [dir] [str] (different)
-23 If not [color/thing/param] [dir] [str] (different)
-24 If [color/thing/param] [-#] -#] [str] (different)
-25 g If [-#] [-#] [str]
-26 If [dir] player [color/thing/param] [str] (different)
-
-27 Double [str]
-28 Half [str]
-29 Goto [str]
-30 Send [str] [str]
-
-36 * Endgame
-
-38 Mod [str]
-39 Sam [##] [str]
-40 Volume [##]
-41 End mod
-42 End sam
-43 Play [str]
-44 End play
-45 Wait play [str]
-46 Wait play
-47 (blank line)
-48 Sfx [##]
-49 Play sfx [str]
-
-51 * Lockself
-52 * Unlockself
-
-53 g Send [dir] [label]
-54 Zap [str] [##]
-55 Restore [str] [##]
-
-56 * Lock [str] dir
-57 * Unlock [str]
-
-68 x g Try [dir] [str]
-
-71 g Switch [dir] [dir]
-
-81 Send [-#] [-#] [str]
-82 x * Copyrobot [str]
-83 x * Copyrobot [-#] [-#]
-84 x*g Copyrobot [dir]
-85 g Duplicate self [dir]
-86 Duplicate self [-#] [-#]
-
-95 Inc [str] random [##] [##]
-96 Dec [str] random [##] [##]
-97 Set [str] random [##] [##]
-
-101 x /[str]
-102 *[str]
-103 [[str]
-104 ?[str];[str]
-105 ?[str];[str];[str]
-106 :[str]
-107 .[str]
-108 |[str]
-
-110 * Scrollview [dir] [##]
-111 Input string [str]
-112 If string [str] [str]
-113 If string not [str] [str]
-114 If string matches [str] [str]
-116 %[str]
-117 &[str]
-118 x Move all [color/thing/param] [dir] (different)
-119 x Copy [-#] [-#] [-#] [-#]
-120 Set edge color [col]
-121 Board [dir] [str]
-122 Board [dir] none
-
-124 g Become pushable
-125 g Become nonpushable
-
-132 x g Copy [dir] [dir]
-133 g Become lavawalker
-134 g Become nonlavawalker
-135 Change [color/thing/param] [color/thing/param] (Diff. from ver 1.0?)
-140 Pre Rel self (In MZX 2.0, unpredictable/useless for use w/global robot)
-142 Pre Rel counters
-144 Jump mod order [##]
-150 Save player position (In MZX 2.0, saves to position 1)
-151 Restore player position (In MZX 2.0, uses position 1)
-152 Exchange player position (In MZX 2.0, uses position 1)
-153 Set mesg column [##]
-154 Center mesg
-155 Clear mesg
-156 * Resetview
-157 Sam [##] [##]
-158 ODT Volume [str]
-159 * Scrollbase color [col]
-160 * Scrollcorner color [col] (Diff. from MZX 1.03)
-161 * Scrolltitle color [col]
-162 * Scrollpointer color [col]
-163 * Scrollarrow color [col]
-164 Viewport [##] [##] (Not param checked until MZX 2.0)
-165 Viewport size [##] [##] (Not param checked until MZX 2.0)
-166 ODT Set mesg column [str]
-167 ODT Message row [str]
-168 Save player position [##]
-169 Restore player position [##]
-170 Exchange player position [##]
-171 Restore player position [##] duplicate self
-172 Exchange player position [##] duplicate self
-
-193 Pre Rel self first (Unpredictable/useless for use w/global robot)
-194 Pre Rel self last (Unpredictable/useless for use w/global robot)
-197 Pre Rel counters first
-198 Pre Rel counters last
-199 Mod fade out
-200 Mod fade in [str]
-
-201 x Copy block [-#] [-#] [##] [##] [-#] [-#]
-
-202 Clip input
-
-203 g Push [dir]
-
-204 Scroll char [ch] [dir]
-205 Flip char [ch] [dir]
-206 Copy char [ch] [ch]
-
-211 Color intensity [##] percent
-212 Color intensity [##] [##] percent
-213 x Color fade out
-214 x Color fade in
-215 Set color [##] [##] [##] [##]
-216 Load char set [str]
-217 Multiply [str] [##]
-218 Divide [str] [##]
-219 Modulo [str] [##]
-220 Player char [dir] [ch]
-221
-222 Load palette [str]
-223
-224 Mod fade [##] [##] (target/speed)
-225 * Scrollview [-#] [-#]
-226 x Swap world [str]
-227 * If alignedrobot [str] [str]
-228
-229 * Lockscroll
-230 * Unlockscroll
-231 If first string [str] [str]
-232 Persistent go [str] (waits until it can move then moves)
-233 Wait mod fade
-235 Enable saving
-236 Disable saving
-239 Overlay on
-240 Overlay static
-241 Overlay transparent
-242 Put [col] [ch] overlay [-#] [-#]
-243 x Copy overlay block [-#] [-#] [##] [##] [-#] [-#]
-247 Write overlay [col] [str] [-#] [-#]
-251 Loop start
-252 Loop [##]
-253 Abort loop
-254 Disable mesg edge
-255 Enable mesg edge
View
474 counter.cpp
@@ -61,14 +61,17 @@
#include "mod.h"
#include "palette.h"
#include "vlayer.h"
+#include "trig.h"
+// Loading robots...
+#include "robo_ed.h"
+
+#include "error.h"
long off;
char fileio;
+int robot_id;
char file_in[12];
char file_out[12];
-int multiplier;
-int divider;
-int c_divisions;
// I took away the mzxakversion stuff. So you no longer
// have to set "mzxakversion" to 1. -Koji
@@ -185,27 +188,9 @@ int get_counter(char far *name,unsigned char id)
{
if(c_divisions)
{
- int sin_return;
int theta = (int)(strtol(name + 3, NULL, 10)) % c_divisions;
- // Do sin
- asm {
- shl theta, 1
- fild word ptr theta
- fldpi
- fmulp st(1), st(0)
- fidiv word ptr c_divisions
-
- // If compiling with Borland C/TC++ 3.0 and it doesn't get
- // past here it's because the compiler can't normally cope with
- // 386/387 instructions like this. To get around it, you should
- // turn on "compile through assembler" in the compiler options.
- // This will, however, make you unable to compile other larger
- // modules, so you need to then turn it off when those are compiling.
- fsin
- fimul word ptr multiplier
- fistp word ptr sin_return
- }
- return(sin_return);
+ int retval = sin(theta);
+ return retval;
}
}
@@ -213,20 +198,9 @@ int get_counter(char far *name,unsigned char id)
{
if(c_divisions)
{
- int cos_return;
int theta = (int)(strtol(name + 3, NULL, 10)) % c_divisions;
- // Do cos
- asm {
- shl theta, 1
- fild word ptr theta
- fldpi
- fmulp st(1), st(0)
- fidiv word ptr c_divisions
- fcos
- fimul word ptr multiplier
- fistp word ptr cos_return
- }
- return(cos_return);
+ int ret_val = cos(theta);
+ return ret_val;
}
}
@@ -234,24 +208,11 @@ int get_counter(char far *name,unsigned char id)
{
if(c_divisions)
{
- int tan_return;
int theta = (int)(strtol(name + 3, NULL, 10)) % c_divisions;
if((theta + (c_divisions >> 2)) % (c_divisions >> 1))
{
- //return((int)(tan((theta * M_PI * 2)/c_divisions) * multiplier));
- // Do tan
- asm {
- shl theta, 1
- fild word ptr theta
- fldpi
- fmulp st(1), st(0)
- fidiv word ptr c_divisions
- fptan
- fstp st(0)
- fimul word ptr multiplier
- fistp word ptr tan_return
- }
- return(tan_return);
+ int ret_val = tan(theta);
+ return ret_val;
}
}
}
@@ -260,23 +221,9 @@ int get_counter(char far *name,unsigned char id)
{
if(divider)
{
- int atan_return;
- int val = strtol(name + 4, NULL, 10);
- double const_2pi = 6.2831853071796;
- if((val <= divider) && (val >= -divider))
- {
- asm {
- fild word ptr val
- fidiv word ptr divider
- fld1
- fpatan
- fimul word ptr c_divisions
- fld const_2pi
- fdivp
- fistp word ptr atan_return
- }
- return(atan_return);
- }
+ int val = (int)strtol(name + 4, NULL, 10);
+ int ret_val = atan(val);
+ return ret_val;
}
}
@@ -284,27 +231,11 @@ int get_counter(char far *name,unsigned char id)
{
if(divider)
{
- int asin_return;
- int val = strtol(name + 4, NULL, 10);
- double const_2pi = 6.2831853071796;
- if((val <= divider) && (val >= -divider))
- {
- // asin(a) = atan(a/sqrt(1 - a^2))
- asm {
- fild word ptr val
- fidiv word ptr divider
- fld st(0) // put a in st(1)
- fmul st(0), st(0) // square a
- fld1 // load 1
- fsubrp // 1 - a^2
- fsqrt // take sqrt
- fpatan
- fimul word ptr c_divisions
- fld const_2pi
- fdivp
- fistp word ptr asin_return
- }
- return(asin_return);
+ int val = (int)strtol(name + 4, NULL, 10);
+ if((val <= divider) && (val >= -divider))
+ {
+ int ret_val = asin(val);
+ return ret_val;
}
}
}
@@ -313,28 +244,11 @@ int get_counter(char far *name,unsigned char id)
{
if(divider)
{
- int acos_return;
- int val = strtol(name + 4, NULL, 10);
- double const_2pi = 6.2831853071796;
- if((val <= divider) && (val >= -divider))
- {
- // asin(a) = atan(sqrt(1 - a^2)/a)
- asm {
- fild word ptr val
- fidiv word ptr divider
- fld st(0) // put a in st(1)
- fmul st(0), st(0) // square a
- fld1 // load 1
- fsubrp // 1 - a^2
- fsqrt // take sqrt
- fxch // swap st(0) and st(1)
- fpatan
- fimul word ptr c_divisions
- fld const_2pi
- fdivp
- fistp word ptr acos_return
- }
- return(acos_return);
+ int val = (int)strtol(name + 4, NULL, 10);
+ if((val <= divider) && (val >= -divider))
+ {
+ int ret_val = acos(val);
+ return ret_val;
}
}
}
@@ -343,7 +257,7 @@ int get_counter(char far *name,unsigned char id)
if(!strn_cmp(name, "SQRT", 4))
{
- int val = (int)(strtol(name + 4, NULL, 10));
+ int val = (int)strtol(name + 4, NULL, 10);
if(val >= 0)
{
int sqrt_return;
@@ -358,7 +272,7 @@ int get_counter(char far *name,unsigned char id)
if(!strn_cmp(name, "ABS", 3))
{
- int val = (int)(strtol(name + 3, NULL, 10));
+ int val = (int)strtol(name + 3, NULL, 10);
if(val < 0) val = -val;
return(val);
}
@@ -409,6 +323,34 @@ int get_counter(char far *name,unsigned char id)
fileio = 6;
}
+ if(!strn_cmp(name, "load_robot", 10))
+ {
+ robot_id = get_rparam(name + 10, id);
+ if(robot_id == -1) return -1;
+ fileio = 9;
+ }
+
+ if(!strn_cmp(name, "save_robot", 10))
+ {
+ robot_id = get_rparam(name + 10, id);
+ if(robot_id == -1) return -1;
+ fileio = 10;
+ }
+
+ if(!strn_cmp(name, "load_bc", 7))
+ {
+ robot_id = get_rparam(name + 7, id);
+ if(robot_id == -1) return -1;
+ fileio = 11;
+ }
+
+ if(!strn_cmp(name, "save_bc", 7))
+ {
+ robot_id = get_rparam(name + 7, id);
+ if(robot_id == -1) return -1;
+ fileio = 12;
+ }
+
//Open input_file! -Koji
if(!strn_cmp(name, "FREAD", 5))
{
@@ -426,17 +368,17 @@ int get_counter(char far *name,unsigned char id)
//Reads a counter from input_file - Exo
if(!str_cmp(name + 5, "_COUNTER"))
{
- return(fgetc(input_file) | fgetc(input_file) << 8);
+ return((fgetc(input_file)) | (fgetc(input_file) << 8));
}
if(!str_cmp(name + 5, "_POS"))
{
- return(ftell(input_file) & 32767);
+ return((int)(ftell(input_file) & 32767));
}
if(!str_cmp(name + 5, "_PAGE"))
{
- return(ftell(input_file) >> 15);
+ return((int)(ftell(input_file) >> 15));
}
//Reads from input_file. -Koji
@@ -473,12 +415,12 @@ int get_counter(char far *name,unsigned char id)
if(!str_cmp(name + 6,"_POS"))
{
- return(ftell(output_file) & 32767);
+ return((int)(ftell(output_file) & 32767));
}
if(!str_cmp(name + 6,"_PAGE"))
{
- return(ftell(output_file) >> 15);
+ return((int)(ftell(output_file) >> 15));
}
}
@@ -532,8 +474,8 @@ int get_counter(char far *name,unsigned char id)
if(!strn_cmp(next, "_CLIST", 6))
{
- spr_num = (int)strtol(next + 6, NULL, 10);
- return(collision_list.collisions[spr_num]);
+ spr_num = strtol(next + 6, NULL, 10);
+ return(collision_list.collisions[spr_num]);
}
spr_num = (unsigned char)strtol(next, &next, 10);
@@ -597,22 +539,22 @@ int get_counter(char far *name,unsigned char id)
{
return smzx_mode;
}
- if((name[5] == 'R') || (name[5] == 'r'))
+ if(!str_cmp(name + 5, "R"))
{
int c;
- c = strtol(name + 6, NULL, 10) & 255;
+ c = (int)strtol(name + 6, NULL, 10) & 255;
return smzx_mode2_palette[c * 3];
}
- if((name[5] == 'G') || (name[5] == 'g'))
+ if(!str_cmp(name + 5, "G"))
{
int c;
- c = strtol(name + 6, NULL, 10) & 255;
+ c = (int)strtol(name + 6, NULL, 10) & 255;
return smzx_mode2_palette[(c * 3) + 1];
}
- if((name[5] == 'B') || (name[5] == 'b'))
+ if(!str_cmp(name + 5, "B"))
{
int c;
- c = strtol(name + 6, NULL, 10) & 255;
+ c = (int)strtol(name + 6, NULL, 10) & 255;
return smzx_mode2_palette[(c * 3) + 2];
}
}
@@ -703,7 +645,7 @@ int get_counter(char far *name,unsigned char id)
{
if(!str_cmp(name + 3, "_PRESSED"))
{
- return key_get;
+ return (unsigned char)key_get;
}
if(!str_cmp(name + 3, "_RELEASE"))
{
@@ -734,7 +676,7 @@ int get_counter(char far *name,unsigned char id)
}
else
{
- int n = strtol(name + 3, NULL, 10) & 0x7F;
+ int n = (int)strtol(name + 3, NULL, 10) & 0x7F;
return state_table[n];
}
}
@@ -829,7 +771,7 @@ int get_counter(char far *name,unsigned char id)
if(!strn_cmp(name, "RID", 3))
{
int i;
- for(i = 0; i < NUM_ROBOTS; i++)
+ for(i = 0; i < NUM_ROBOTS + 1; i++)
{
if(!str_cmp(robots[i].robot_name, name + 3))
{
@@ -841,7 +783,7 @@ int get_counter(char far *name,unsigned char id)
if((name[0] == 'R') || (name[0] == 'r'))
{
char far *next;
- unsigned int n = strtol(name + 1, &next, 10);
+ unsigned int n = (unsigned int)strtol(name + 1, &next, 10);
if(*next == '.')
{
return(get_counter(next + 1, n));
@@ -1063,11 +1005,11 @@ int get_counter(char far *name,unsigned char id)
void set_counter(char far *name,int value,unsigned char id)
{
int t1;
-//File protocal -Koji
+//File protocol -Koji
if(fileio > 0)
{ //This can be good thing or a bad thing...
//I'd say it'd be wise to seclude a new game
- //inside a it's own folder to fight against
+ //inside a its own folder to fight against
//a posible viral threat. -Koji
// I changed if's to a switch. - Exo
@@ -1113,44 +1055,36 @@ void set_counter(char far *name,int value,unsigned char id)
}
case 4:
{
+ // Save .sav file.
//Store current
store_current();
//Save game
- save_world(name);
+ save_world(name, 1, 0);
//Reload current
select_current(curr_board);
break;
}
case 5:
- {
- // Load game
- int last_board = curr_board;
- store_current();
- clear_current();
- end_mod();
- if(!load_world(name, 2, 1, 0))
- {
- char temp[12];
- if(board_where[curr_board]!=W_NOWHERE)
- select_current(curr_board);
- else select_current(0);
- send_robot_def(0,10);
- str_cpy(temp, mod_playing);
- if(temp[0])
- {
- load_mod(temp);
- }
- if(get_counter("CURSORSTATE", 0) == 0)
- {
- m_hide();
- }
- }
- else
- {
- load_mod(mod_playing);
- select_current(last_board);
- }
- break;
+ {
+ // Load world
+ char faded = 0;
+
+ // Gotta do this a little early
+ fileio = 0;
+
+ // Clear world and reload
+ clear_world();
+ load_world(name, 0, 1, &faded);
+
+ if(board_where[curr_board] != W_NOWHERE)
+ select_current(curr_board);
+ else select_current(0);
+
+ send_robot_def(0, 10);
+
+ force_state = 2;
+
+ break;
}
// Load SMZX palette
case 6:
@@ -1162,12 +1096,12 @@ void set_counter(char far *name,int value,unsigned char id)
case 7:
{
int temp = robots[id].cur_prog_line;
- // First set the current line to 0
- robots[id].cur_prog_line = 0;
+ // First set the current line to 1
+ robots[id].cur_prog_line = 1;
//Store current
store_current();
//Save game
- save_world(name, 0, 0);
+ save_world(name);
//Reload current
select_current(curr_board);
robots[id].cur_prog_line = temp;
@@ -1185,6 +1119,189 @@ void set_counter(char far *name,int value,unsigned char id)
str_cpy(file_out, name);
break;
}
+ case 9:
+ {
+ // Load robot
+ FILE *robot_file;
+ unsigned char file_in[256];
+ unsigned char file_out[256];
+ unsigned char far *loc;
+ unsigned int mem_used = 0;
+ int ret_length;
+
+ if(id == GLOBAL_ROBOT)
+ {
+ prepare_robot_mem(0);
+ }
+
+ robot_file = fopen(name, "rt");
+
+ if(robot_file == NULL)
+ {
+ break;
+ }
+
+ if(robot_free_mem < 31744)
+ {
+ reallocate_robot_mem(1, robot_id, robot_free_mem);
+ }
+ else
+ {
+ reallocate_robot_mem(1, robot_id, 31744);
+ }
+
+ loc = robot_mem + robots[robot_id].program_location;
+ prepare_robot_mem(0);
+
+ *loc = 255;
+ loc++;
+ mem_used++;
+
+ while(fgets(file_in, 256, robot_file) != NULL)
+ {
+ *(file_in + str_len(file_in) - 1) = 0;
+
+ if(string_to_robot(file_in, file_out, &ret_length)) break;
+
+ mem_cpy(loc, file_out, ret_length);
+ loc += ret_length;
+ mem_used += ret_length;
+
+ sprintf(file_out, "%d", ret_length);
+ }
+ *loc = 0;
+ mem_used++;
+
+ reallocate_robot_mem(1, robot_id, mem_used);
+
+ robots[robot_id].cur_prog_line = 1;
+
+ if(robot_id == id)
+ {
+ force_state = 1;
+ }
+ else
+ {
+ force_state = 3;
+ }
+
+ if(id == GLOBAL_ROBOT)
+ {
+ prepare_robot_mem(1);