Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SeppJ wird es schon wieder löschen wollen, aber ich bin der Meinung, daß dieses Forum hier genau der richtige Ort ist, um die nötige Basis und die nötigen, immer wieder gleichen Grundbausteine zu vermitteln, die es für das Programmier-"Handwerk" braucht. Also hier die GUI:
- ```cpp
- /* Some simple routines for Window handling.
- Yet still in 'development'.
- You give it a string with widgets and then it can
- receive input commands from a cursor and the keys.
- get_input() receives widget changes, you have to
- check for a signal variable and then call the
- routine that you associate with the event.
- Always first put in front the widget that has 'sent'
- the signal . Then use readback() to copy the new
- state into a data structure. With update()
- you should be able to set the signal back
- to zero and also produce text label output
- or create new widgets during runtime.
- Movement of windows could be done when the
- window signals '3' if a certain area is clicked,
- which is 'dispatched' every loop run to a routine
- which polls for mouse cursor movement and locks
- it on window coordinates. '4' is release and
- resizing could be done in a similiar way.
- Display() or so to display the entire stacked
- structure.
- It doesn't work with multitasking or queueing.
- If you want to write some crappy DOS apps,
- you might find it useful.
- The basic idea was to get the input elements of a certain application
- always in front when you need them. So you display them with a resorted stacked list.
- Also, after the first elements were drawn, the drawn parts of the screen get fixated with a
- mask when going the stack downwards.
- The mouse and keyboard input can be catched through the first elements from the left and
- this gets only overwritten when the stack depth gets deeper.
- It can either be catched just that they don't go to elements outside of the focus or for
- actual input. Elements could change input mode by setting certain values.
- For carets, topmost and modal windows, the application programmer has to do certain things
- by himself. For example, topmost windows would be in front right before the display routine
- call and then sorted back to their old position which is saved in the application.
- It is important that the application always knows how the GUI looks like and therefore it
- hangs until upwardly an update was done so it is still consistent.
- If there was timer interrupt triggerd multitasking and no main loop, this perhaps
- also could fail.
- Input from the user may get lost. However, printer and modem are more annoying.
- It may also be necessary to remove messages for removed windows in a loop when they are
- closed.
- To simulate the full multitasking version with C, you have to write a bytecode emulator
- that executes several code sequences at once. Writing a bytecode emulator is quite simple (however,
- a compiler for it is much harder) and you have to simply execute one instruction of each
- through it's calls in the main loop run.
- CLI and STI are important instructions. However, they may not be needed here.
- In that main loop, you could also insert a message queue and a wrapper for the window routines.
- It would be a linked list. When a semaphore in the window structure is 1, it copies the state
- into a message structure, inserts it into the list and sets the semaphore to 0. Then it examines
- the memory of a script. Call it ABI. When a certain byte in the memory is 0, the message structure
- gets copied into a certain area of the memory of the script and the byte is set to 1. This will also include
- other information like some sort of "hwnd" handle. The script would then call some sort of GetMessage() or
- PeekMessage(). The message is then removed from the list.
- The script can then catch that info and process the user command. The other way, inside the memory of the
- script another byte is set and the command for window change is appended somewhere, the message routine in the
- main loop sets the byte to 0 and puts the message with the data needed into the linked list and tries
- to send it to the GUI wrapper when it is ready. The GUI wrapper would then update the window structure with
- some of the routines below.
- Timer-triggered multitasking would require CLI and STI on critical points.
- The wrapper could poll the timer function and that way, it could send double clicks by bundling two
- clicks together into a new message.
- Watch out for layer=framedepth-1 . Needs to be fixed?
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- /*
- Ein einfacher Steuersequenzsstring stellt Fenster dar.
- Die Sequenzen werden mit einem Stapel abgearbeitet und zur Laufzeit umgebaut.
- Es gibt eine Update-Semaphore, die kenntlich macht, dass das betreffende Element
- veraendert wurde.
- Die Hervorhebung ergibt sich aus der Reihenfolge im Stapel.
- Ist das erste Element markiert, wird der Rest nicht mehr verarbeitet.
- Die Verarbeitung zielt dann nur noch auf die Beendigung der Sequenz.
- Cursor bewegen mit h,j,k,u und klicken mit l,
- Konsolenfenster fuer Anzeige gross stellen
- */
- unsigned char screen[160][120];
- unsigned char windStr[1024];
- struct
- {
- int x,y;
- long int xmax, ymax;
- int blocked;
- unsigned int seqstart, seqend;
- signed int firstheap;
- } framestack[20];
- signed int framedepth=0;
- unsigned int pixelbuf[20000][4];
- unsigned int pixcount;
- unsigned char screenz[160][120];
- /*
- Anwendung muss das Nachvorneholen selber initiieren
- Elemente muessen durch Identifier gezielt angesprochen werden
- Datenfeld muss als Pointer abgeelgt werden
- Eingabekommando muss in Fensterelement gespeichert werden, sodass Anwendung
- die Positionierung des Eingabecursors und das Einfuegen des Textes uebernehmen kann
- evtl. Updatesperre
- Löchsen und Erzeugen von Elementen?
- */
- /*
- Wird ein Fenster neu positioniert, oder wollte das Fenstersystem eine Animation
- beim Minimirern oder auch nur beim Radiobuttonaendern zeigen, muss das Aendern eines Objekts,
- das auch ausserdem nicht ganz vorne sein muss, durch einen Routinenaufruf des Fenstersystems
- erfolgen, der nicht einfach nur direkt die Werte aendert?
- Diese Routine gibt den Erfolgsstatus an die Anwendung zurueck?
- */
- /* Ich könnte unten nochmal update() aufrufen und so etwas Tipparbeit sparen?
- */
- typedef
- struct
- {
- unsigned char type;
- unsigned char varname[255];
- unsigned char text[255];
- int x,y;
- int xabs, yabs;
- int xmaxabs;
- long int ymaxabs;
- long int xmax,ymax;
- int command;
- int blocked;
- long int param;
- int visible;
- int visible_abs;
- } obj_state;
- void buildstring(char *string, obj_state *state)
- {
- unsigned char buf[255];
- if ( state->type=='w')
- {
- strcpy(string,"w");
- strcat(string,":");
- strcat(string,state->varname);
- strcat(string,":");
- strcat(string,state->text);
- strcat(string,":");
- itoa(state->xabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->yabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->xmaxabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->ymaxabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->blocked,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->command,buf,10),
- strcat(string,buf);
- strcat(string,":");
- }
- else if ( state->type=='b')
- {
- strcpy(string,"b");
- strcat(string,":");
- strcat(string,state->varname);
- strcat(string,":");
- strcat(string,state->text);
- strcat(string,":");
- itoa(state->xabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->yabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->xmaxabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->ymaxabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->blocked,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->command,buf,10),
- strcat(string,buf);
- strcat(string,":");
- }
- else if ( state->type=='t')
- {
- strcpy(string,"t");
- strcat(string,":");
- strcat(string,state->varname);
- strcat(string,":");
- strcat(string,state->text);
- strcat(string,":");
- itoa(state->xabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->yabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->xmaxabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->ymaxabs,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->blocked,buf,10),
- strcat(string,buf);
- strcat(string,":");
- itoa(state->command,buf,10),
- strcat(string,buf);
- strcat(string,":");
- }
- }
- void disp_edit_text(obj_state *edfield, signed int z)
- {
- long int len;
- len=0;
- while ( edfield->x+len < edfield->xmax && *(unsigned char*)(edfield->ymax+len)!='\0' && len < 9)
- ppix(edfield->x+len, edfield->y, *(unsigned char *)(edfield->ymax+len),z), len++;
- while ( len < 10) ppix(edfield->x+len, edfield->y,219,z), len++;
- }
- unsigned char get_edit_pos(obj_state *edfield, int x, int y )
- {
- int len;
- len=0;
- if ( edfield->y== y && edfield->x <= x )
- {
- while ( 1)
- {
- printf("\aEdfield x ist %d, x ist %d, y Edfield y ist %d, y ist %d",edfield->x, x,edfield->y,y ), getch();
- if ( len > 9 || edfield->x+len >= edfield->xmax) return 'F' ;
- if ( edfield->x+len ==x) return len+0x30;
- len++;
- if ( *(unsigned char *)(edfield->ymax+len)=='\0' ) return 'F';
- }
- }
- else return 'F';
- }
- // andere Routinen koennen readback() und update() aufrufen, spart Tipperei
- void ppix(unsigned int x, unsigned int y, unsigned char value, unsigned int z)
- {
- if ( screenz[x][y]!=255)
- {
- pixelbuf[pixcount][0]=x,
- pixelbuf[pixcount][1]=y,
- pixelbuf[pixcount][2]=value;
- pixelbuf[pixcount][3]=z;
- screenz[x][y]=z;
- pixcount++;
- }
- }
- void releasescreenblock(unsigned int z)
- {
- int x=0, y=0;
- while ( y < 120)
- {
- x=0;
- while ( x < 160)
- {
- if ( screenz[x][y]==z) screenz[x][y]=255;
- x++;
- }
- y++;
- }
- }
- unsigned int cursor[2];
- void disp_elements(void )
- {
- unsigned int type;
- unsigned char text[32];
- unsigned char varname[32];
- unsigned int n2=0;
- unsigned int x,y,xmax,ymax;
- unsigned int blocked;
- unsigned int updateSemaph;
- unsigned char buf[5];
- unsigned int entry_p, exit_p;
- int n=0;
- entry_p=0;
- ppix(cursor[0],cursor[1],'X',1);
- releasescreenblock(1);
- while ( 1 )
- {
- type=windStr[n];
- if ( type=='e')
- {
- framedepth--;
- n++;
- exit_p=n;
- framestack[framedepth].seqend=exit_p;
- releasescreenblock(framedepth+1);
- if ( framedepth==0) return;
- }
- if ( type=='w' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax < xmax+x ?
- framestack[framedepth-1].xmax : xmax+x );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax < ymax+y ?
- framestack[framedepth-1].ymax : ymax+y );
- framestack[framedepth].seqstart=entry_p;
- xmax=framestack[framedepth].xmax;
- ymax=framestack[framedepth].ymax;
- // max irrelevant?
- framedepth++;
- printf("%s %d %d %d %d\n",varname,x,y,xmax,ymax), getch();
- unsigned int drawX, drawY;
- drawX=x+1;
- while ( drawX < xmax )
- {
- drawY=y+1;
- while ( drawY < ymax )
- {
- ppix(drawX,drawY,' ',framedepth);
- drawY++;
- }
- drawX++;
- }
- drawX=x;
- while ( drawX < xmax )
- {
- ppix(drawX,y,'#',framedepth);
- ppix(drawX,ymax,'#',framedepth), drawX++;
- }
- drawY=y;
- while ( drawY < ymax+1 )
- {
- ppix(x,drawY,'#',framedepth);
- ppix(xmax,drawY,'#',framedepth), drawY++;
- }
- n2=0;
- while(n2 < strlen(text) && n2+x < xmax ) ppix(x+1+n2,y,text[n2],framedepth), n2++;
- }
- if ( type=='b' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax < xmax+x ?
- framestack[framedepth-1].xmax : xmax+x );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax < ymax+y ?
- framestack[framedepth-1].ymax : ymax+y );
- framestack[framedepth].seqstart=entry_p;
- xmax=framestack[framedepth].xmax;
- ymax=framestack[framedepth].ymax;
- framedepth++;
- // max irrelevant?
- unsigned int drawX, drawY;
- drawX=x;
- while ( drawX < xmax )
- {
- drawY=y;
- while ( drawY < ymax )
- {
- ppix(drawX,drawY,'*',framedepth);
- drawY++;
- }
- drawX++;
- }
- n2=0;
- while(n2 < strlen(text) ) ppix(x+1+n2,y,text[n2],framedepth), n2++;
- }
- if ( type=='t' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax < xmax+x ?
- framestack[framedepth-1].xmax : xmax+x );
- /*
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax < y+1 ?
- framestack[framedepth-1].ymax : y+1 );
- */
- framestack[framedepth].seqstart=entry_p;
- framedepth++;
- // max irrelevant?
- unsigned int drawX, drawY;
- obj_state edfield;
- edfield.x=x, edfield.y=y,
- edfield.xmax=xmax+x;
- edfield.ymax=ymax;
- drawX=x;
- drawY=y; if ( framestack[framedepth-1].ymax > framestack[framedepth-1].y)
- disp_edit_text(&edfield, framedepth);
- }
- }
- }
- void clearScreen()
- {
- int x=0, y=0;
- while ( y < 80 )
- {
- x=0;
- while ( x < 160 )
- {
- screen[x][y]=' ';
- screenz[x][y]=0;
- x++;
- }
- y++;
- }
- }
- int readback(char *identifier, obj_state *status)
- {
- unsigned int type;
- unsigned char text[32];
- unsigned char varname[32];
- unsigned int n2=0;
- unsigned int x,y,xmax,ymax;
- unsigned int blocked;
- unsigned int updateSemaph;
- unsigned char buf[5];
- unsigned int entry_p, exit_p;
- int weisdown, layer;
- unsigned int xabs, yabs;
- int n=0;
- weisdown=0;
- signed int framepos;
- unsigned char identifiers[10][255];
- unsigned int ident_len=0;
- n=0;
- identifiers[0][0]='\0';
- while ( identifier[n2]!='\0')
- {
- identifiers[ident_len][n]=identifier[n2];
- n2++ ,n++;
- if (identifier[n2]==':' || identifier[n2]=='\0')
- {
- identifiers[ident_len][n]='\0';
- ident_len++;
- if ( identifier[n2]=='\0') break; else n2++;
- n=0;
- }
- }
- printf("%s suche ich", identifiers[0]);
- n2=0;
- framepos=-1;
- n=1;
- framestack[0].firstheap=0;
- while ( n < 20)
- {
- framestack[n].firstheap=-1;
- n++;
- }
- unsigned int ignore;
- ignore=0;
- layer=0;
- n=0;
- while ( 1 )
- {
- type=windStr[n];
- if ( type=='e')
- {
- framedepth--;
- n++;
- exit_p=n;
- framestack[framedepth].seqend=exit_p;
- if ( weisdown==1&& framedepth <= layer
- && layer==ident_len) ignore=1;
- if ( framedepth==0) break;
- }
- //else weisdown=0;
- if ( type=='w' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax < xmax ?
- framestack[framedepth-1].xmax : xmax );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax < ymax ?
- framestack[framedepth-1].ymax : ymax );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- xabs=x, yabs=y;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- drawX=x;
- if ( layer <= ident_len && framedepth-1 <= ident_len&& framedepth-2==layer)
- if ( strcmp(identifiers[layer],varname)==0 )
- {
- //windStr[n-2]='1'; //Semaphore gesetzt
- status->type='w';
- strcpy ( status->text, text), strcpy( status->varname, varname);
- status->x=x, status->y=y,
- status->xmax=xmax, status->ymax=ymax,
- status->xabs=xabs, status->yabs=yabs;
- status->blocked=blocked, status->command=updateSemaph;
- // printf(">>%s geblickt<<", varname), getch();
- weisdown=1;
- layer=framedepth-1;
- framepos=framedepth-1;
- }
- }
- //else
- //framedepth--;
- //printf("%s %d %d %d %d %d\n",varname, x,y,xmax,ymax, weisdown), getch();
- }
- if ( type=='b' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax+x < xmax ?
- framestack[framedepth-1].xmax+x : xmax );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax+y < ymax ?
- framestack[framedepth-1].ymax+y : ymax );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- xabs=x, yabs=y;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- if ( layer <= ident_len && framedepth-1 <= ident_len&& framedepth-2==layer)
- if ( strcmp(identifiers[layer],varname)==0 )
- {
- // windStr[n-2]='1'; //Semaphore gesetzt
- status->type='b';
- strcpy ( status->text, text), strcpy( status->varname, varname);
- status->x=x, status->y=y,
- status->xmax=xmax, status->ymax=ymax,
- status->xabs=xabs, status->yabs=yabs;
- status->blocked=blocked, status->command=updateSemaph;
- //printf("Button geklickt"), getch();
- framepos=framedepth-1;
- layer=framedepth-1;
- weisdown=1;
- }
- //else
- //framedepth--;
- }
- }
- if ( type=='t' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- unsigned long xmaxabs, ymaxabs;
- xmaxabs=xmax, ymaxabs=ymax;
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax+x < xmax ?
- framestack[framedepth-1].xmax+x : xmax );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax+y < ymax ?
- framestack[framedepth-1].ymax+y : ymax );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- xabs=x, yabs=y;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- if ( layer <= ident_len && framedepth-1 <= ident_len&& framedepth-2==layer)
- if ( strcmp(identifiers[layer],varname)==0 )
- {
- // windStr[n-2]='1'; //Semaphore gesetzt
- status->type='t';
- strcpy ( status->text, text), strcpy( status->varname, varname);
- status->x=x, status->y=y,
- status->xmax=xmax, status->ymax=ymax,
- status->xmaxabs=xmaxabs, status->ymaxabs=ymaxabs;
- status->blocked=blocked-0x30, status->command=updateSemaph-0x30;
- //printf("Button geklickt"), getch();
- framepos=framedepth-1;
- layer=framedepth-1;
- weisdown=1;
- }
- }
- }
- }
- // windStr[n-3]='1';
- //framestack[framedepth].seqend=n;
- if ( weisdown==0 ) return 1;
- if ( layer!=ident_len) return 1;
- return 0;
- }
- int putinfront(char *identifier, signed int layers) // wenn -1, voll
- {
- unsigned int type;
- unsigned char text[32];
- unsigned char varname[32];
- unsigned int n2=0;
- unsigned int x,y,xmax,ymax;
- unsigned int blocked;
- unsigned int updateSemaph;
- unsigned char buf[5];
- unsigned int entry_p, exit_p;
- int weisdown, layer;
- int n=0;
- weisdown=0;
- signed int framepos;
- unsigned char identifiers[10][255];
- unsigned int ident_len=0;
- n=0;
- identifiers[0][0]='\0';
- while ( identifier[n2]!='\0')
- {
- identifiers[ident_len][n]=identifier[n2];
- n2++ ,n++;
- if (identifier[n2]==':' || identifier[n2]=='\0')
- {
- identifiers[ident_len][n]='\0';
- ident_len++;
- if ( identifier[n2]=='\0') break; else n2++;
- n=0;
- }
- }
- n2=0;
- framepos=-1;
- n=1;
- framestack[0].firstheap=0;
- while ( n < 20)
- {
- framestack[n].firstheap=-1;
- n++;
- }
- unsigned int ignore;
- ignore=0;
- layer=0;
- n=0;
- // printf("Gehe in putinfront()'s Hauptschleife"), getch();
- while ( 1 )
- {
- type=windStr[n];
- if ( type=='e')
- {
- framedepth--;
- n++;
- exit_p=n;
- framestack[framedepth].seqend=exit_p;
- if ( weisdown==1&& framedepth <= layer
- && layer==ident_len) ignore=1;
- if ( framedepth==0) break;
- }
- //else weisdown=0;
- if ( type=='w' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax < xmax ?
- framestack[framedepth-1].xmax : xmax );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax < ymax ?
- framestack[framedepth-1].ymax : ymax );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- drawX=x;
- if ( layer <= ident_len && framedepth-1 <= ident_len&& framedepth-2==layer)
- if ( strcmp(identifiers[layer],varname)==0 )
- {
- //windStr[n-2]='1'; //Semaphore gesetzt
- // printf(">>%s geklickt<<", varname), getch();
- weisdown=1;
- layer=framedepth-1;
- framepos=framedepth-1;
- }
- }
- //else
- //framedepth--;
- // printf("%s %d %d %d %d %d\n",varname, x,y,xmax,ymax, weisdown), getch();
- }
- if ( type=='b' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax+x < xmax ?
- framestack[framedepth-1].xmax+x : xmax );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax+y < ymax ?
- framestack[framedepth-1].ymax+y : ymax );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- if ( layer <= ident_len && framedepth-1 <= ident_len&& framedepth-2==layer)
- if ( strcmp(identifiers[layer],varname)==0 )
- {
- // windStr[n-2]='1'; //Semaphore gesetzt
- // printf("Button geklickt"), getch();
- framepos=framedepth-1;
- layer=framedepth-1;
- weisdown=1;
- }
- //else
- //framedepth--;
- }
- }
- if ( type=='t' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax+x < xmax ?
- framestack[framedepth-1].xmax+x : xmax );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax+y < ymax ?
- framestack[framedepth-1].ymax+y : ymax );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- if ( layer <= ident_len && framedepth-1 <= ident_len&& framedepth-2==layer)
- if ( strcmp(identifiers[layer],varname)==0 )
- {
- // windStr[n-2]='1'; //Semaphore gesetzt
- // printf("Button geklickt"), getch();
- framepos=framedepth-1;
- layer=framedepth-1;
- weisdown=1;
- }
- //else
- //framedepth--;
- }
- }
- }
- // windStr[n-3]='1';
- //framestack[framedepth].seqend=n;
- if ( weisdown==0 ) return 1;
- if ( layer!=ident_len) return 1;
- framedepth=framepos;
- unsigned char copied[1024];
- unsigned int length;
- while ( framedepth > 0)
- {
- if ( framestack[framedepth].seqend-framestack[framedepth].seqstart >= 0 )
- {
- strncpy(copied,windStr+framestack[framedepth].seqstart,framestack[framedepth].seqend-framestack[framedepth].seqstart);
- copied[framestack[framedepth].seqend-framestack[framedepth].seqstart]='\0';
- }
- else copied[0]='\0';
- length=strlen(windStr);
- strcpy(windStr+framestack[framedepth].seqstart, windStr+framestack[framedepth].seqend);
- memcpy(windStr+framestack[framedepth-1].firstheap+strlen(copied), windStr+framestack[framedepth-1].firstheap, length);
- memcpy(windStr+framestack[framedepth-1].firstheap, copied, strlen(copied));
- // printf("app:%s\ncopied:%s" , windStr,copied ), getch();
- framedepth--;
- }
- return 0;
- }
- #define CHANGE 0
- #define INSERT 1
- #define DELETE 2
- int update(unsigned char *identifier, obj_state *status, int chinode)
- {
- unsigned int type;
- unsigned char text[32];
- unsigned char varname[32];
- unsigned int n2=0;
- unsigned long int x,y,xmax,ymax;
- unsigned int blocked;
- unsigned int updateSemaph;
- unsigned char buf[5];
- unsigned int entry_p, exit_p;
- int weisdown, layer;
- unsigned int xabs, yabs;
- int n=0;
- weisdown=0;
- signed int framepos;
- unsigned char identifiers[10][255];
- unsigned int ident_len=0;
- n=0;
- identifiers[0][0]='\0';
- while ( identifier[n2]!='\0')
- {
- identifiers[ident_len][n]=identifier[n2];
- n2++ ,n++;
- if (identifier[n2]==':' || identifier[n2]=='\0')
- {
- identifiers[ident_len][n]='\0';
- ident_len++;
- if ( identifier[n2]=='\0') break; else n2++;
- n=0;
- }
- }
- n2=0;
- framepos=-1;
- n=1;
- framestack[0].firstheap=0;
- while ( n < 20)
- {
- framestack[n].firstheap=-1;
- n++;
- }
- unsigned int ignore;
- ignore=0;
- layer=0;
- n=0;
- while ( 1 )
- {
- type=windStr[n];
- if ( type=='e')
- {
- framedepth--;
- n++;
- exit_p=n;
- framestack[framedepth].seqend=exit_p;
- if ( weisdown==1&& framedepth <= layer &&
- layer==ident_len ) ignore=1;
- if ( framedepth==0) break;
- }
- //else weisdown=0;
- if ( type=='w' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- unsigned int xmaxabs, ymaxabs;
- xabs=x, yabs=y;
- xmaxabs=xmax, ymaxabs=ymax;
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax < xmax ?
- framestack[framedepth-1].xmax : xmax );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax < ymax ?
- framestack[framedepth-1].ymax : ymax );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- drawX=x;
- if ( layer <= ident_len && framedepth-1 <= ident_len&& framedepth-2==layer)
- if ( strcmp(identifiers[layer],varname)==0 )
- {
- //windStr[n-2]='1'; //Semaphore gesetzt
- if ( chinode!= CHANGE && chinode!=INSERT)
- {
- status->type='w';
- strcpy ( status->text, text), strcpy( status->varname, varname);
- status->x=x, status->y=y,
- status->xmax=xmaxabs, status->ymax=ymaxabs,
- status->xabs=xabs, status->yabs=yabs;
- status->blocked=blocked, status->command=updateSemaph;
- }
- // printf(">>%s geklickt<<", varname), getch();
- weisdown=1;
- layer=framedepth-1;
- framepos=framedepth-1;
- }
- }
- //else
- //framedepth--;
- // printf("%s %d %d %d %d %d\n",varname, x,y,xmax,ymax, weisdown), getch();
- }
- if ( type=='b' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- unsigned int xmaxabs, ymaxabs;
- xabs=x, yabs=y;
- xmaxabs=xmax, ymaxabs=ymax;
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax+x < xmax ?
- framestack[framedepth-1].xmax+x : xmax );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax+y < ymax ?
- framestack[framedepth-1].ymax+y : ymax );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- if ( layer <= ident_len && framedepth-1 <= ident_len&& framedepth-2==layer)
- if ( strcmp(identifiers[layer],varname)==0 )
- {
- // windStr[n-2]='1'; //Semaphore gesetzt
- if ( chinode!= CHANGE && chinode != INSERT)
- {
- status->type='b';
- strcpy ( status->text, text), strcpy( status->varname, varname);
- status->x=x, status->y=y,
- status->xmax=xmaxabs, status->ymax=ymaxabs,
- status->xabs=xabs, status->yabs=yabs;
- status->blocked=blocked, status->command=updateSemaph;
- }
- // printf("Button geklickt"), getch();
- framepos=framedepth-1;
- layer=framedepth-1;
- weisdown=1;
- }
- //else
- //framedepth--;
- }
- }
- if ( type=='t' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- unsigned long int xmaxabs, ymaxabs;
- xabs=x, yabs=y;
- xmaxabs=xmax, ymaxabs=ymax;
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax+x < xmax ?
- framestack[framedepth-1].xmax+x : xmax );
- framestack[framedepth].ymax=ymax; //( framestack[framedepth-1].ymax+y < ymax ?
- // framestack[framedepth-1].ymax+y : ymax );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- if ( layer <= ident_len && framedepth-1 <= ident_len&& framedepth-2==layer)
- if ( strcmp(identifiers[layer],varname)==0 )
- {
- // windStr[n-2]='1'; //Semaphore gesetzt
- if ( chinode!= CHANGE && chinode != INSERT)
- {
- status->type='t';
- strcpy ( status->text, text), strcpy( status->varname, varname);
- status->x=x, status->y=y,
- status->xmax=xmaxabs, status->ymax=ymaxabs,
- status->xabs=xabs, status->yabs=yabs;
- status->blocked=blocked, status->command=updateSemaph;
- }
- // printf("Button geklickt"), getch();
- framepos=framedepth-1;
- layer=framedepth-1;
- weisdown=1;
- }
- //else
- //framedepth--;
- }
- }
- }
- if ( weisdown==0 ) return 1;
- if ( layer!=ident_len) return 1;
- framedepth=framepos;
- unsigned char copied[1024];
- unsigned char converted[255];
- copied[0]='\0';
- if ( chinode==CHANGE|| chinode==INSERT)
- {
- buildstring(copied, status);
- // schauen, ob noch eine Aufwerfung folgt!!
- }
- unsigned char windBak[1024];
- if ( chinode==DELETE)
- {
- strcpy ( windBak,windStr+framestack[layer].seqend);
- strcpy(windStr+framestack[layer].seqstart, copied);
- strcat(windStr, windBak );
- }
- else
- if ( chinode== INSERT )
- {
- strcat(copied,"e"); // das muss nicht sein, da nicht zwingend vorne!
- strcpy ( windBak,windStr+framestack[layer].firstheap);
- strcpy(windStr+framestack[layer].firstheap, copied);
- strcat(windStr, windBak );
- }
- else
- if ( chinode== CHANGE )
- {
- strcpy ( windBak,windStr+framestack[layer].firstheap);
- strcpy(windStr+framestack[layer].seqstart, copied);
- strcat(windStr, windBak );
- }
- // printf("app:%s\ncopied:%s" , windStr,copied ), getch();
- return 0;
- // windStr[n-3]='1';
- //framestack[framedepth].seqend=n;
- }
- void get_input(void)
- {
- unsigned int cmd=0;
- obj_state obj_input;
- unsigned char c;
- if ( kbhit())
- switch ( (c=getch()) )
- {
- case 'u': if ( cursor[1]> 0) cursor[1]--; break;
- case 'j': if ( cursor[1]< 80) cursor[1]++; break;
- case 'h': if ( cursor[0]> 0) cursor[0]--; break;
- case 'k': if ( cursor[0]< 160) cursor[0]++; break;
- case 'l': cmd=1;
- default: if ( c >='A' && c <= 'Z') cmd=2; break;
- }
- if ( cmd==1||cmd==2)
- {
- unsigned int type;
- unsigned char text[32];
- unsigned char varname[32];
- unsigned int n2=0;
- unsigned int x,y,xmax,ymax;
- unsigned int blocked;
- unsigned int updateSemaph;
- unsigned char buf[5];
- unsigned int entry_p, exit_p;
- int weisdown, layer;
- int n=0;
- weisdown=0;
- signed int framepos;
- framepos=-1;
- n=1;
- framestack[0].firstheap=0;
- while ( n < 20)
- {
- framestack[n].firstheap=-1;
- n++;
- }
- unsigned int ignore;
- ignore=0;
- layer=0;
- n=0;
- while ( 1 )
- {
- type=windStr[n];
- if ( type=='e')
- {
- framedepth--;
- n++;
- exit_p=n;
- framestack[framedepth].seqend=exit_p;
- if ( weisdown==1&& framedepth < layer) ignore=1;
- if ( framedepth==0) break;
- }
- //else weisdown=0;
- if ( type=='w' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- unsigned int xabs, yabs, xmaxabs, ymaxabs;
- xabs=x, yabs=y, xmaxabs=xmax, ymaxabs=ymax;
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax < xmax+x ?
- framestack[framedepth-1].xmax : xmax+x );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax < ymax+y ?
- framestack[framedepth-1].ymax : ymax+y );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- xmax=framestack[framedepth].xmax;
- ymax=framestack[framedepth].ymax;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- drawX=x;
- if ( cursor[0] >= x && cursor[0] <= xmax &&
- cursor[1] >= y && cursor[1] <= ymax+1 && blocked=='0' )
- {
- //windStr[n-2]='1'; //Semaphore gesetzt
- obj_input.type='w';
- if ( cursor[1]!=y)
- obj_input.command=1;
- else
- {
- if ( updateSemaph!='3')obj_input.command=3;
- else obj_input.command=4;
- }
- strcpy(obj_input.varname, varname);
- strcpy(obj_input.text,text);
- obj_input.param=0,
- obj_input.xabs=xabs,
- obj_input.yabs=yabs,
- obj_input.xmaxabs=xmaxabs,
- obj_input.ymaxabs=ymaxabs,
- obj_input.blocked=0;
- // printf("\a");
- // printf(">>%s geklickt<<", varname), getch();
- weisdown=1;
- layer=framedepth;
- framepos=framedepth-1;
- }
- else if ( cmd==2)
- {
- obj_input.type='w',
- strcpy(obj_input.varname, varname);
- strcpy(obj_input.text,text);
- obj_input.command=0; // kein Signal
- obj_input.param=0,
- obj_input.xabs=xabs,
- obj_input.yabs=yabs,
- obj_input.xmaxabs=xmaxabs,
- obj_input.ymaxabs=ymaxabs,
- obj_input.blocked=0;
- framepos=framedepth-1;
- layer=framedepth-1;
- weisdown=1;
- }
- }
- //else
- //framedepth--;
- // printf("%s %d %d %d %d %d\n",varname, x,y,xmax,ymax, weisdown), getch();
- }
- if ( type=='b' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- unsigned int xabs, yabs, xmaxabs, ymaxabs;
- xabs=x, yabs=y, xmaxabs=xmax, ymaxabs=ymax;
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax < xmax+x ?
- framestack[framedepth-1].xmax : xmax+x );
- framestack[framedepth].ymax=( framestack[framedepth-1].ymax < ymax+y ?
- framestack[framedepth-1].ymax : ymax+y );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- xmax=framestack[framedepth].xmax;
- ymax=framestack[framedepth].ymax;
- // max irrelevant?
- framedepth++;
- unsigned int drawX, drawY;
- if ( cursor[0] >= x && cursor[0] <= x+xmax &&
- cursor[1] >= y && cursor[1] <= y+ymax&& blocked=='0' )
- {
- obj_input.type='b',
- strcpy(obj_input.varname, varname);
- strcpy(obj_input.text,text);
- obj_input.command=1,
- obj_input.param=0,
- obj_input.xabs=xabs,
- obj_input.yabs=yabs,
- obj_input.xmaxabs=xmaxabs,
- obj_input.ymaxabs=ymaxabs,
- obj_input.blocked=0;
- // windStr[n-2]='1'; //Semaphore gesetzt
- printf("Button geklickt"), getch();
- framepos=framedepth-1;
- layer=framedepth;
- weisdown=1;
- }
- else if ( cmd==2)
- {
- strcpy(obj_input.varname, varname);
- strcpy(obj_input.text,text);
- obj_input.command=0, // Signal ignorieren
- obj_input.param=0,
- obj_input.xabs=xabs,
- obj_input.yabs=yabs,
- obj_input.xmaxabs=xmaxabs,
- obj_input.ymaxabs=ymaxabs,
- obj_input.blocked=0;
- framepos=framedepth-1;
- layer=framedepth;
- weisdown=1;
- }
- //else
- //framedepth--;
- }
- }
- if ( type=='t' )
- {
- entry_p=n;
- // type:'varname':'text':x:y:xsize:ysize:blocked:update
- n++;
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) varname[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- varname[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) text[n2]=windStr[n], n++, n2++;
- if ( windStr[n]==':' )n++; else return;
- text[n2]='\0';
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- x=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- y=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- xmax=atoi(buf);
- if ( windStr[n]==':' )n++; else return;
- n2=0;
- while ( windStr[n]!=':' ) buf[n2]=windStr[n], n++, n2++;
- buf[n2]='\0';
- ymax=atoi(buf);
- n++;
- blocked=windStr[n]; n++, n++;
- updateSemaph=windStr[n]; n++, n++;
- if ( ignore==0)
- {
- unsigned long int xabs, yabs, xmaxabs, ymaxabs;
- xabs=x, yabs=y, xmaxabs=xmax, ymaxabs=ymax;
- framestack[framedepth].x=framestack[framedepth-1].x+x;
- framestack[framedepth].y=framestack[framedepth-1].y+y;
- x=framestack[framedepth].x;
- y=framestack[framedepth].y;
- framestack[framedepth].xmax= ( framestack[framedepth-1].xmax < xmax+x ?
- framestack[framedepth-1].xmax : xmax+x );
- framestack[framedepth].ymax=( framestack[framedepth-1].y < xmax+1 ?
- framestack[framedepth-1].y : xmax+1 );
- framestack[framedepth].seqstart=entry_p;
- framestack[framedepth].firstheap=n;
- xmax=framestack[framedepth].xmax;
- ymax=framestack[framedepth].ymax;
- // max irrelevant?
- framedepth++;
- //printf("Binda\a"), getch();
- obj_state objbuf;
- objbuf.x=x, objbuf.y=y;
- objbuf.xmax=xmax+x, objbuf.ymax=ymax;
- unsigned int drawX, drawY;
- if (framestack[framedepth-1].ymax > framestack[framedepth-1].y)
- {
- if ( cmd==1 &&
- (text[1]=get_edit_pos(&objbuf,cursor[0],cursor[1])) != 'F' )
- {
- obj_input.type='t',
- strcpy(obj_input.varname, varname);
- strcpy(obj_input.text,text);
- obj_input.command=cmd,
- obj_input.xabs=xabs,
- obj_input.yabs=yabs,
- obj_input.xmaxabs=xmaxabs,
- obj_input.ymaxabs=ymaxabs,
- obj_input.blocked=0;
- // windStr[n-2]='1'; //Semaphore gesetzt
- printf("Editierfeld angeklickt"), getch();
- framepos=framedepth-1;
- layer=framedepth;
- weisdown=1;
- }
- else if ( cmd==2)
- {
- obj_input.type='t',
- strcpy(obj_input.varname, varname);
- strcpy(obj_input.text,text);
- obj_input.command=cmd,
- obj_input.xabs=xabs,
- obj_input.yabs=yabs,
- obj_input.xmaxabs=xmaxabs,
- obj_input.ymaxabs=ymaxabs,
- obj_input.blocked=0;
- obj_input.command=cmd,
- obj_input.text[0]=c;
- printf("\a");
- framepos=framedepth-1;
- layer=framedepth;
- weisdown=1;
- }
- }
- //else
- //framedepth--;
- }
- }
- }
- if ( weisdown==1)
- {
- unsigned char strconstr[255];
- unsigned char copied[1024];
- buildstring(strconstr, &obj_input);
- // printf(">>>>>>%s<<<<", strconstr), getch();
- strncpy(copied,windStr+framestack[layer-1].firstheap,strlen(windStr)-framestack[layer-1].firstheap);
- copied[strlen(windStr)-framestack[layer-1].firstheap]='\0';
- memcpy(windStr+framestack[layer-1].seqstart, strconstr, strlen(strconstr)+1);
- strcat(windStr,copied);
- }
- }
- }
- void displayScreen(void)
- {
- system("cls\n");
- int x=0, y=0;
- unsigned char screenz[160][120];
- y=0;
- while ( y < 120)
- {
- x=0;
- while ( x < 160)
- {
- screenz[x][y]=0;
- x++;
- }
- y++;
- }
- x=0,y=0;
- unsigned int n=0;
- while ( n < pixcount)
- {
- //if (screenz[pixelbuf[pixcount][0]][pixelbuf[pixcount][1]] <= pixelbuf[pixcount][3])
- screen[pixelbuf[n][0]][pixelbuf[n][1]]=pixelbuf[n][2] ; // ,
- n++;
- //screenz[pixelbuf[pixcount][0]][pixelbuf[pixcount][1]]=pixelbuf[pixcount][3];
- }
- while ( y < 80 )
- {
- x=0;
- while ( x < 158 )
- {
- printf("%c%c%c%c%c%c%c%c", screen[x][y], screen[x+1][y], screen[x+2][y], screen[x+3][y],
- screen[x+4][y], screen[x+5][y], screen[x+6][y], screen[x+7][y]);
- x+=8;
- }
- printf("\n");
- y++;
- }
- }
- int main(void)
- {
- clock_t delay;
- framestack[0].x=0, framestack[0].y=0,
- framestack[0].xmax=100, framestack[0].ymax=80;
- framestack[0].blocked=0;
- framestack[0].seqstart=0, framestack[0].seqend=strlen(windStr);
- cursor[0]=0, cursor[1]=0;
- obj_state teststat;
- unsigned char text[255];
- unsigned char textptr[30];
- strcpy(text,"Werte");
- itoa((long int)text,textptr,10);
- strcpy(windStr,"w:testfenster:Hello:20:20:30:30:0:0:w:xbutton:XBUTTON:1:1:10:10:0:0:eb:testbutton:OK:5:5:4:3:0:0:eew:test2:Bla:25:27:50:50:0:0:" );
- strcat(windStr,"t:text:Texten:10:10:7:"),
- strcat(windStr,textptr),
- strcat(windStr,":0:0:eee");
- // printf("%s", (unsigned char *)atoi(textptr)), getch();
- //printf("%s", (unsigned char *)(long int)(text)), getch();
- printf("%s",windStr), getch();
- /*
- while (1 )
- {
- delay=clock()+100;
- clearScreen();
- framedepth=1;
- printf(" %d ", strlen(windStr));
- */
- framedepth=1;
- framestack[0].x=0, framestack[0].y=0,
- framestack[0].xmax=100, framestack[0].ymax=80;
- framestack[0].blocked=0;
- framestack[0].seqstart=0, framestack[0].seqend=strlen(windStr);
- printf("%s",windStr), getch();
- readback("test2:text",&teststat);
- framedepth=1;
- framestack[0].x=0, framestack[0].y=0,
- framestack[0].xmax=100, framestack[0].ymax=80;
- framestack[0].blocked=0;
- framestack[0].seqstart=0, framestack[0].seqend=strlen(windStr);
- //printf("Ueberlebt...");
- teststat.x=1;
- teststat.xabs=5;
- teststat.yabs=5;
- teststat.xmaxabs=10;
- teststat.ymaxabs=10;
- strcpy(teststat.varname,"INSERTED");
- strcpy(teststat.text,"IMINSERTED");
- teststat.type='w';
- printf("%d", teststat.ymax);
- update("testfenster:xbutton",&teststat,INSERT);
- framedepth=1;
- framestack[0].x=0, framestack[0].y=0,
- framestack[0].xmax=100, framestack[0].ymax=80;
- framestack[0].blocked=0;
- framestack[0].seqstart=0, framestack[0].seqend=strlen(windStr);
- disp_elements();
- displayScreen();
- printf("\n%s\n", windStr);
- /*
- framestack[0].x=0, framestack[0].y=0,
- framestack[0].xmax=100, framestack[0].ymax=80;
- framestack[0].blocked=0;
- framestack[0].seqstart=0, framestack[0].seqend=strlen(windStr);
- pixcount=0;
- printf("vor disp_elements()");
- disp_elements();
- framedepth=1;
- framestack[0].x=0, framestack[0].y=0,
- framestack[0].xmax=100, framestack[0].ymax=80;
- framestack[0].blocked=0;
- framestack[0].seqstart=0, framestack[0].seqend=strlen(windStr);
- readback("test2:text",&teststat);
- framedepth=1;
- framestack[0].x=0, framestack[0].y=0,
- framestack[0].xmax=100, framestack[0].ymax=80;
- framestack[0].blocked=0;
- framestack[0].seqstart=0, framestack[0].seqend=strlen(windStr);
- if ( teststat.command=='1') putinfront("test2:text",-1);
- framedepth=1;
- framestack[0].x=0, framestack[0].y=0,
- framestack[0].xmax=100, framestack[0].ymax=80;
- framestack[0].blocked=0;
- framestack[0].seqstart=0, framestack[0].seqend=strlen(windStr);
- printf("vor get_input()");
- get_input();
- displayScreen();
- printf("\n%s",windStr);
- //readback("testfenster:testbutton",&teststat);
- //printf("Hallo%s", teststat.text );
- while ( delay > clock());
- }
- */
- }
- ```
- ```
- Das Schönste war, daß ich nach 20 Jahren endlich in der Lage war, ein funktionierendes Grafikadventure im Lucas-Arts-Stil zu schreiben. Ist zwar immer noch eine Schlamperei, aber theoretisch sind wohl alle Probleme gelöst.
- ```cpp
- /*
- Added the path search algorithm from the Miracle C distribution.
- I hope that's it.
- */
- #include <stdio.h>
- #include <time.h>
- #include <fcntl.h>
- #define NUM_SCRIPTS 7 // Number of individual scripts, they're all running simultaneously, give them a semaphore waiting loop to pause them
- #define NUM_OBJECTS 6 // Number of game objects, including actors
- #define GLOBAL_STATES 16 // Number of global state values
- signed int data[1024*NUM_SCRIPTS+GLOBAL_STATES+NUM_OBJECTS*9]; // The shared working memory for the VM scripts
- unsigned int cursor[2]; // Cursor X and Y coordinate
- #define NUM_SENTENCES 3 // Strings to be displayed when something is being 'said', -1 means none
- #define NUM_ROOMS 1 // Number of individual rooms
- unsigned char objnames[NUM_OBJECTS][32]; // Identifier strings for objects
- unsigned char sentences[NUM_SENTENCES][255]; // Sentences data array
- #define OBJ_NUM(n) (1024*NUM_SCRIPTS+GLOBAL_STATES+n*9)
- #define X_SCROLL 1024*NUM_SCRIPTS // X room scrolling
- #define Y_SCROLL 1024*NUM_SCRIPTS+1 // still not implemented
- #define TIMERTICK 1024*NUM_SCRIPTS+2 // When the timer function delivers a new value, it is set to 1, a certain script has to set it to 0 and deliver it
- #define TOUCHING 1024*NUM_SCRIPTS+3
- #define ROOM 1024*NUM_SCRIPTS+4 // Inventory is 1, empty room is 0
- #define ITEM_A 1024*NUM_SCRIPTS+5 // First item ID to be combined in a sentence
- #define ITEM_B 1024*NUM_SCRIPTS+6 // second one
- #define VERB 1024*NUM_SCRIPTS+7 // Verb to be used in a sentence
- #define ACTION_CODE 1024*NUM_SCRIPTS+8 // User command state resulting from the sequence of the clicked stuff
- #define SAY_SENTENCE 1024*NUM_SCRIPTS+9 // Script selection of sentence to be said
- #define PATHSTARTOBJ 1024*NUM_SCRIPTS+10 // Object from which the path search starts
- #define NOACTION 0
- #define LOOK 1
- #define PICK 2
- #define COMBINE 3
- #define PREP_LOOK 4
- #define PREP_PICK 5
- #define PREP_COMBI 6
- #define PREP_COMBI_B 7
- #define WALKTOXY 8
- unsigned char sprite[400*7]; // Sprite patterns, raw 20x20 tiles with 8 bit color depth, linear greyscale, above 240 somewhere means transparency
- unsigned char screen[160][90]; // Screen Buffer
- signed int screenz[160][50]; // Z depth of each coordinate on the screen buffer
- unsigned char *roompatt; // arrays often crash, but today we have OS automatic dynamic memory allocation
- unsigned char *roomz; // The Z depth for room coordinates itself, however, sprites may be put in front of this
- signed int walkmask[32][2][10][NUM_ROOMS]; // X, Y and Z coordinates of walkable coordinates of a room, still needs to be upscaled by a correcting routine
- // just for the path search test
- unsigned char walklayer1[320]={0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,1,1,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,1,0,1,0,0,1,0,0,1,0,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- // initialize the walk mask
- void initwalklayer(void)
- {
- int x=0,z=0;
- while ( z < 10)
- {
- x=0;
- while ( x < 32)
- {
- walkmask[x][1][z][0]=walklayer1[x+z*32];
- walkmask[x][0][z][0]=1;
- if (walklayer1[x+z*32]==1) roompatt[x*10+(z/4+30)*320]=0;
- x++;
- }
- z++;
- }
- }
- signed int passedbox[32][2][10]; // so the path search knows where it was and where it can spread
- // That algorithm assigns each coordinate the shortest cross-formed way from the starting coordinate, afterwards you can trace the way back from the goal
- // by seeking by-one-decremented neighbour points
- signed int shortest;
- int path_recurse(int x, int y, int z, int xg, int yg, int zg, int depth)
- {
- //printf("%d %d %d\n",x,y,z);
- if ( depth > 1999) return;
- if ( x==xg && y == yg && z == zg){ if ( depth-1 < shortest )shortest=depth-1; }
- passedbox[x][y][z]=depth-1;
- signed int buf;
- if ( x > 0 )if (passedbox[x-1][y][z]>depth||passedbox[x-1][y][z]==-3) path_recurse(x-1,y,z,xg,yg,zg,depth+1);
- if ( x < 31) if (passedbox[x+1][y][z]>depth||passedbox[x+1][y][z]==-3)path_recurse(x+1,y,z,xg,yg,zg,depth+1);
- if ( y > 0 ) if (passedbox[x][y-1][z]>depth||passedbox[x][y-1][z]==-3) path_recurse(x,y-1,z,xg,yg,zg,depth+1);
- if ( y < 1 ) if (passedbox[x][y+1][z]>depth||passedbox[x][y+1][z]==-3) path_recurse(x,y+1,z,xg,yg,zg,depth+1);
- if ( z > 0 ) if (passedbox[x][y][z-1]>depth||passedbox[x][y][z-1]==-3) path_recurse(x,y,z-1,xg,yg,zg,depth+1);
- if ( z < 9 ) if (passedbox[x][y][z+1]>depth||passedbox[x][y][z+1]==-3) path_recurse(x,y,z+1,xg,yg,zg,depth+1);
- //printf("%d\n",depth);
- return shortest;
- }
- void markback(int x, int y, int z, int len)
- {
- if ( len ==0 ) passedbox[x][y][z]=-4;
- if ( x > 0 ) if ( passedbox[x-1][y][z]==len-1)markback(x-1,y,z,len-1);
- if ( x < 31 ) if ( passedbox[x+1][y][z]==len-1)markback(x+1,y,z,len-1);
- if ( y > 0 ) if ( passedbox[x][y-1][z]==len-1)markback(x,y-1,z,len-1);
- if ( y < 1 ) if ( passedbox[x][y+1][z]==len-1)markback(x,y+1,z,len-1);
- if ( z < 9 ) if ( passedbox[x][y][z+1]==len-1)markback(x,y,z+1,len-1);
- if ( z > 0 ) if (passedbox[x][y][z-1]==len-1)markback(x,y,z-1,len-1);
- }
- // The thing is, there are just two Y heights, what you would think is Y is actually taken from the Z mask of the clicked coordinate.
- // It still cannot select sprites, however, you can assume that they were transferred with there Z value on the Z mask there before
- // Overlapping of several sprites shall not happen anyway
- // Max could walk through Sam. There was no necessity to implement details like walking around him. Just imagine he did with a time leap.
- // Consider the problems that could cause also.
- void find_path(int obj, int x_, int y_)
- {
- signed int x=data[OBJ_NUM(obj)+0]/10,y=data[OBJ_NUM(obj)+1]/20, z=data[OBJ_NUM(obj)+8]/10;
- x_/=10, y_/=30;
- signed int z_=screenz[x_*10-data[X_SCROLL]][y_*20]/26;
- // pay attention: if sprite was moved in front, coordinates behind cannot be accessed anymore
- //data[OBJ_NUM(obj)+1]=3;
- //y=1; // Z-Maskenfehlenpfusch
- y_=1;
- //printf("Suche den Pfad von %d %d %d nach %d %d %d\n",x,y,z, x_,y_,z_);
- //getch();
- unsigned int c1,c2,c3;
- c3=0;
- while ( c3 < 10)
- {
- c1=0;
- while ( c1 < 32)
- {
- c2=0;
- while ( c2 < 2)
- {
- passedbox[c1][c2][c3]=walkmask[c1][c2][c3][data[ROOM]-2]== 0 ? -3 : -2 ;
- c2++;
- }
- c1++;
- }
- c3++;
- }
- //passedbox[x_][y_][z_]=-3;
- shortest=2000;
- path_recurse(x,y,z,x_,y_,z_,0);
- if ( shortest!=2000)markback(x_,y_,z_,shortest);
- data[OBJ_NUM(obj)+7]=1;
- data[OBJ_NUM(obj)+4]=x*10, data[OBJ_NUM(obj)+5]=y*20, data[OBJ_NUM(obj)+6]=z*10;
- // There's a semaphore to be marked when a path was found.
- // I'm still not sure how to calculate the runtime of the path search, but probably it cannot exceed 1999
- if ( shortest!= 2000)
- {
- //printf("Pfad gefunden.");
- if ( x-1 >= 0) if ( passedbox[x-1][y][z] ==-4 ) shortest= passedbox[x-1][y][z], data[OBJ_NUM(obj)+4]=x*10-10, data[OBJ_NUM(obj)+5]=y*20, data[OBJ_NUM(obj)+6]=z*10;
- if ( x+1 < 32) if ( passedbox[x+1][y][z] ==-4 ) shortest= passedbox[x+1][y][z], data[OBJ_NUM(obj)+4]=x*10+10, data[OBJ_NUM(obj)+5]=y*20, data[OBJ_NUM(obj)+6]=z*10;
- if ( y-1 >= 0) if ( passedbox[x][y-1][z] ==-4 ) shortest= passedbox[x][y-1][z], data[OBJ_NUM(obj)+4]=x*10, data[OBJ_NUM(obj)+5]=y*20-20, data[OBJ_NUM(obj)+6]=z*10;
- if ( y+1 < 2) if ( passedbox[x][y+1][z] ==-4 ) shortest= passedbox[x][y+1][z], data[OBJ_NUM(obj)+4]=x*10, data[OBJ_NUM(obj)+5]=y*20+20, data[OBJ_NUM(obj)+6]=z*10;
- if ( z-1 >= 0) if ( passedbox[x][y][z-1] ==-4 ) shortest= passedbox[x][y][z-1], data[OBJ_NUM(obj)+4]=x*10, data[OBJ_NUM(obj)+5]=y*20, data[OBJ_NUM(obj)+6]=z*10-10;
- if ( z+1 < 10) if ( passedbox[x][y][z+1] ==-4 ) shortest= passedbox[x][y][z+1], data[OBJ_NUM(obj)+4]=x*10, data[OBJ_NUM(obj)+5]=y*20, data[OBJ_NUM(obj)+6]=z*10+10;
- }
- else data[OBJ_NUM(obj)+7]=3; // We found no path
- //printf("Durchgelaufen");
- /*
- printf("%d\n",passedbox[x-1][y][z] );
- printf("%d\n",passedbox[x+1][y][z] );
- printf("%d\n",passedbox[x][y+1][z] );
- printf("%d\n",passedbox[x][y-1][z] );
- printf("%d\n",passedbox[x][y][z+1] );
- printf("%d\n",passedbox[x][y][z-1] );
- */
- //printf("%d\n", shortest);
- //printf("Resultat: %d %d %d",data[OBJ_NUM(obj)+4],data[OBJ_NUM(obj)+5],data[OBJ_NUM(obj)+6]);
- //getch();
- }
- // Draw the level and afterwards draw the sprites
- void drawlevel(void)
- {
- int x,y;
- int room=data[ROOM]-2; // remember: 0 and 1 are special rooms
- y=0;
- while ( y < 50)
- {
- x=0;
- while ( x < 160)
- {
- screenz[x][y]=roomz[x+data[X_SCROLL] +y*320 +room*320*50];
- x++;
- }
- y++;
- }
- y=0;
- while ( y < 50)
- {
- x=0;
- while ( x < 160)
- {
- int c;
- c= roompatt[x+data[X_SCROLL]+y*320+room*320*50];
- if ( c < 64) c=' '; // ASCII can be just like greyscale, it's very ugly having only 4 greyscale values, however, it's still only a test
- else
- if ( c < 96) c=176;
- else
- if ( c < 128) c= 177;
- else
- if ( c < 196) c= '@';
- else c=219;
- screen[x][y]=c ;
- x++;
- }
- y++;
- }
- int n;
- n=0;
- while ( n < NUM_OBJECTS)
- {
- if ( data[OBJ_NUM(n)+3]==room+2 || (data[OBJ_NUM(n)+3]==1 ) ) // first determine if it's in the current room or in the inventory below, subtract the scrolling value...
- put_sprite( data[OBJ_NUM(n)+3] != 1 ? data[OBJ_NUM(n)+0]-data[X_SCROLL] : data[OBJ_NUM(n)+0],data[OBJ_NUM(n)+1],data[OBJ_NUM(n)+2],-96, data[OBJ_NUM(n)+8] );
- n++;
- }
- }
- // Sometimes we need to know whether a certain object is at a certain mouse cursor position.
- // The Y and Z confusion may still be causing trouble... however, we're always clicking objects and not room pattern parts,
- // what can be selected always needs to be placed, use a completely empty and transparent pattern for all of them
- signed int getobjfromcoord( int x, int y )
- {
- int n=0;
- while ( n < NUM_OBJECTS)
- {
- if ( data[OBJ_NUM(n)+3]!=1)
- {
- if ( data[OBJ_NUM(n)+3]==data[ROOM] &&
- fabs ( x - ( data[OBJ_NUM(n)+0]-data[X_SCROLL]+10 ) ) < 15 &&
- fabs ( y - ( data[OBJ_NUM(n)+1]-data[Y_SCROLL]+10 ) ) < 15 ) return n;
- }
- else
- {
- if ( data[OBJ_NUM(n)+3]==1 &&
- fabs ( x - ( data[OBJ_NUM(n)+0] +10 ) ) < 10 &&
- fabs ( y - ( data[OBJ_NUM(n)+1] +10 ) ) < 10 ) return n;
- }
- n++;
- }
- return -1;
- }
- // Is a _certain_ object there?
- signed int getobjNfromcoord( int x, int y, int n )
- {
- if ( data[OBJ_NUM(n)+3]!=1)
- {
- if ( data[OBJ_NUM(n)+3]==data[ROOM] &&
- fabs ( x - ( data[OBJ_NUM(n)+0]-data[X_SCROLL]+10 ) ) < 15 &&
- fabs ( y - ( data[OBJ_NUM(n)+1]-data[Y_SCROLL]+10 ) ) < 55 ) return n;
- }
- return -1;
- }
- // draw the sprite and change the Z mask, there's still the possibility for brightness scaling
- void put_sprite(int xstart,int ystart, int n, int luma, int z)
- {
- int x=0;
- int y=0;
- signed int scroll;
- scroll=0;
- if ( ystart < 50)ystart+=z/4; // Here you can see that i don't know what i'm doing. From a certain aspect, Z could about look like an increased Y
- // printf("Setze es an Position %d %d",xstart-scroll, ystart);
- //printf("%d\n",z);
- while ( y < 20 )
- {
- x=0;
- while ( x < 20 )
- {
- if ( screenz[x+xstart][y+ystart]/50<= z || ystart > 50)
- if ( xstart+x-scroll > 0 && xstart+x-scroll < 160 &&
- ystart+y > 0 && ystart+y < 90 )
- {
- if ( sprite[n*400+x+y*20]<220 ) // eigentlich 255 der Transparenzwert
- {
- if ( sprite[n*400+x+y*20]+luma< 64 )
- screen[xstart+x-scroll][y+ystart]=176;
- else
- if ( sprite[n*400+x+y*20]+luma< 128 )
- screen[xstart+x-scroll][y+ystart]=177;
- else
- if ( sprite[n*400+x+y*20]+luma< 196 )
- screen[xstart+x-scroll][y+ystart]='@';
- else
- //if ( sprite[n*400+x+y*20]+luma< 255 )
- screen[xstart+x-scroll][y+ystart]=219;
- screenz[x][y]=z;
- }
- }
- x++;
- }
- y++;
- }
- }
- /*
- 0 von Beginn: X-Koordinate eines Sprites
- 1 von Beginn: Y-Koordinate eines Sprites
- 2 : Sprite-Phase
- 3: Raum ( 0 kein, 1 Inventory )
- 4: Pfadsuche X
- 5: Pfadsuche Y
- 6: Pfadsuche Z
- 7: Pfadsuche hat Daten 2 Aufruf 1 Abholen
- 8: Z-Daten
- der Rest ist frei
- */
- // A data object needs x, y and z coordinates, for getobjfromcoord() we still ignored z, however, with two lines of code it should be about ok
- // You can assign each data object a sprite tile number, you also assign it a room. The path search will enter it's next coordinates somewhere there,
- // but you can catch the next coordinates only when the value at offset 7 is 1. You have to call the path search again for every animation step.
- // But this is only logical because some things in the room might change while walking
- // Maybe implement the possibility to find an object with a script over, again, a call semaphore, and then you could take it's coordinates from the result
- // Comparing direct coordinates with the touch instruction could also have advantages?
- // each script has it's own instruction memory ( not to confuse with the random-access 'data segment' thing )
- // Each instruction can have two operands
- // and when a script is locked, the VM will continue executing it until it is unlocked and therefore also the core will hang
- struct
- {
- signed int instruction[1024][3];
- signed int instr_ptr;
- unsigned int locked;
- } script[NUM_SCRIPTS];
- #define ADD 0 // some basic mathematical operations, would be practical to extend the VM instruction set, however, multiplication and division are additions
- #define SUB 1 // and subtraction in a loop, did you know that?
- #define MOV 2 // move value from address of second operand to the address of the first operand
- #define IFCMP 3 // when values on the addresses of both operands are equal, don't skip the next instruction, otherwise, add 2 to instr_ptr
- #define JMP 4 // Jump to address of operand 1
- #define LOCK 5 // Don't underestimate the possibility to prevent interruption of a certain script. Without this possibility, correct execution is never guaranteed
- #define UNLOCK 6 // it will also lock the main loop, but our scripts shouldn't be a threat to the 'operating system' anyway
- #define TOUCH 7 // when object of number of operand 1 is close enough to the object with the number of operand 2, set a certain value in script memory to 1,
- // otherwise zero
- // Virtual machine sounds very sophisticated, however, in it's basic form, it's cheap
- void VM_Step(void)
- {
- int n=0;
- while ( n < NUM_SCRIPTS )
- {
- if ( script[n].instruction[script[n].instr_ptr][0]==ADD )
- {
- data[script[n].instruction[script[n].instr_ptr][1]]+=
- data[script[n].instruction[script[n].instr_ptr][2]];
- script[n].instr_ptr++;
- }
- else
- if ( script[n].instruction[script[n].instr_ptr][0]==SUB )
- {
- data[script[n].instruction[script[n].instr_ptr][1]]-=
- data[script[n].instruction[script[n].instr_ptr][2]];
- script[n].instr_ptr++;
- }
- else
- if ( script[n].instruction[script[n].instr_ptr][0]==MOV )
- {
- data[script[n].instruction[script[n].instr_ptr][1]]=
- data[script[n].instruction[script[n].instr_ptr][2]];
- script[n].instr_ptr++;
- }
- else
- if ( script[n].instruction[script[n].instr_ptr][0]==IFCMP )
- {
- if ( data[script[n].instruction[script[n].instr_ptr][1]]==
- data[script[n].instruction[script[n].instr_ptr][2]]);
- else script[n].instr_ptr++;
- script[n].instr_ptr++;
- }
- else
- if ( script[n].instruction[script[n].instr_ptr][0]==JMP )
- {
- script[n].instr_ptr=script[n].instruction[script[n].instr_ptr][1];
- }
- else
- if ( script[n].instruction[script[n].instr_ptr][0]==LOCK )
- {
- //int n2;
- //n2=0;
- //while ( n2< NUM_SCRIPTS ){
- // if (!( n2==n) )
- script[n].locked=1; //n2++; }
- script[n].instr_ptr++;
- }
- else
- if ( script[n].instruction[script[n].instr_ptr][0]==UNLOCK )
- {
- script[n].locked=0;
- script[n].instr_ptr++;
- }
- else if ( script[n].instruction[script[n].instr_ptr][0]==TOUCH)
- {
- long int obj1, obj2;
- obj1=script[n].instruction[script[n].instr_ptr][1];
- obj2=script[n].instruction[script[n].instr_ptr][2];
- if ( fabs(data[1024*NUM_SCRIPTS+GLOBAL_STATES+obj1*9+0]-
- data[1024*NUM_SCRIPTS+GLOBAL_STATES+obj2*9+0] ) < 30 &&
- fabs(data[1024*NUM_SCRIPTS+GLOBAL_STATES+obj1*9+1]-
- data[1024*NUM_SCRIPTS+GLOBAL_STATES+obj2*9+1] ) < 30 &&
- fabs(data[1024*NUM_SCRIPTS+GLOBAL_STATES+obj1*9+8]-
- data[1024*NUM_SCRIPTS+GLOBAL_STATES+obj2*9+8] ) < 30 &&
- data[1024+NUM_SCRIPTS+GLOBAL_STATES+obj1*9+3]==
- data[1024+NUM_SCRIPTS+GLOBAL_STATES+obj2*9+3]
- )
- data[TOUCHING]=1;
- else data[TOUCHING]=0;
- script[n].instr_ptr++;
- }
- if ( script[n].locked==0)n++; else continue;
- }
- }
- int main(void)
- {
- clock_t timertick;
- int pathgoalx, pathgoaly;
- // Load graphic patterns and stuff, the preprocessor is very useful to keep things overviewable
- FILE *pattfile;
- pattfile=fopen(".\\sprites","rb");
- fread(sprite,20*20*6,sizeof(unsigned char),pattfile);
- fclose(pattfile);
- pattfile=fopen(".\\rooms","rb");
- roompatt=malloc(320*50*NUM_ROOMS);
- roomz=malloc(320*50*NUM_ROOMS);
- fread(roompatt,320*50*NUM_ROOMS, sizeof(unsigned char), pattfile);
- fread(roomz,320*50*NUM_ROOMS, sizeof(unsigned char), pattfile);
- fclose(pattfile);
- initwalklayer();
- // One directive, and you already have an assembler.
- // The first value is not exactly the 'code segment', but the script number
- #define VMCODE(n,adress,opcode,op1,op2) script[n].instruction[adress][0]=(opcode),\
- script[n].instruction[adress][1]=(op1),\
- script[n].instruction[adress][2]=(op2),
- // Here our assmbler coding experiments begin.
- // What riddle could we take?
- // We start with basic needs, hand to mouth...
- /*
- VMCODE(0,0,ADD,X_SCROLL,100)
- VMCODE(0,1,JMP,0,0)
- VMCODE(1,0,IFCMP,TIMERTICK,101)
- VMCODE(1,1,MOV,X_SCROLL,0)
- VMCODE(1,2,JMP,0,0)
- VMCODE(1,0,LOCK,0,0)
- VMCODE(1,1,IFCMP,TIMERTICK,101)
- VMCODE(1,2,JMP,5,0)
- VMCODE(1,3,UNLOCK,0,0)
- VMCODE(1,4,JMP,0,0)
- VMCODE(1,5,ADD,2,101)
- VMCODE(1,6,MOV,TIMERTICK,102)
- VMCODE(1,7,UNLOCK,0,0)
- VMCODE(1,8,IFCMP,2,103)
- VMCODE(1,9,MOV,2,0)
- VMCODE(1,10,JMP,0,0)
- VMCODE(2,0,JMP,0,0)
- */
- VMCODE(0,0,UNLOCK,0,0)
- VMCODE(0,1,LOCK,0,0)
- VMCODE(0,2,IFCMP,ACTION_CODE,101)
- VMCODE(0,3,JMP,5,0)
- VMCODE(0,4,JMP,0,0)
- VMCODE(0,5,IFCMP,ITEM_A,105)
- VMCODE(0,6,JMP,8,0)
- VMCODE(0,7,JMP,0,0)
- VMCODE(0,8,MOV,SAY_SENTENCE,102)
- VMCODE(0,9,MOV,OBJ_NUM(1)+3,102)
- VMCODE(0,10,MOV,OBJ_NUM(2)+3,105)
- VMCODE(0,11,MOV,ACTION_CODE,NOACTION)
- VMCODE(0,12,UNLOCK,0,0)
- VMCODE(0,13,JMP,0,0)
- //Pfadsuche
- VMCODE(1,0,UNLOCK,0,0)
- VMCODE(1,1,UNLOCK,0,0)
- VMCODE(1,2,LOCK,0,0)
- VMCODE(1,3,IFCMP,ACTION_CODE,104)
- VMCODE(1,4,JMP,6,0)
- VMCODE(1,5,JMP,0,0)
- VMCODE(1,6,MOV,ACTION_CODE,0)
- VMCODE(1,7,MOV,OBJ_NUM(0)+7,106)
- VMCODE(1,8,JMP,0,0)
- VMCODE(2,0,UNLOCK,0,0)
- VMCODE(2,1,LOCK,0,0)
- VMCODE(2,2,IFCMP,OBJ_NUM(0)+7,105)
- VMCODE(2,3,JMP,5,0)
- VMCODE(2,4,JMP,0,0)
- VMCODE(2,5,MOV,OBJ_NUM(0),OBJ_NUM(0)+4)
- VMCODE(2,6,MOV,OBJ_NUM(0)+1,OBJ_NUM(0)+5)
- VMCODE(2,7,MOV,OBJ_NUM(0)+8,OBJ_NUM(0)+6)
- VMCODE(2,8,MOV,OBJ_NUM(0)+7,102)
- //VMCODE(2,9,MOV,X_SCROLL,OBJ_NUM(0))
- VMCODE(2,9,LOCK,0,0)
- VMCODE(2,10,MOV,OBJ_NUM(0)+7,102)
- VMCODE(2,11,JMP,0,0)
- VMCODE(3,0,IFCMP,OBJ_NUM(0),107)
- VMCODE(3,1,JMP,3,0)
- VMCODE(3,2,JMP,0,0)
- VMCODE(3,3,MOV,X_SCROLL,108 )
- VMCODE(3,4,JMP,0,0)
- VMCODE(4,0,IFCMP,OBJ_NUM(0),108)
- VMCODE(4,1,JMP,3,0)
- VMCODE(4,2,JMP,0,0)
- VMCODE(4,3,MOV,X_SCROLL,102)
- VMCODE(4,4,JMP,0,0)
- // Benutze Zigarettenautomat mit Cash Card
- VMCODE(5,0,UNLOCK,0,0)
- VMCODE(5,1,LOCK,0,0)
- VMCODE(5,2,IFCMP,ACTION_CODE,109)
- VMCODE(5,3,JMP,5,0)
- VMCODE(5,4,JMP,0,0)
- VMCODE(5,5,IFCMP,ITEM_A,110)
- VMCODE(5,6,JMP,8,0)
- VMCODE(5,7,JMP,0,0)
- VMCODE(5,8,IFCMP,ITEM_B,111)
- VMCODE(5,9,JMP,11,0)
- VMCODE(5,10,JMP,0,0)
- VMCODE(5,11,TOUCH,0,5)
- VMCODE(5,12,IFCMP,TOUCHING,105)
- VMCODE(5,13,JMP,15,0)
- VMCODE(5,14,JMP,19,0)
- VMCODE(5,15,MOV,OBJ_NUM(4)+3,105)
- VMCODE(5,16,MOV,ACTION_CODE,NOACTION)
- VMCODE(5,17,UNLOCK,0,0)
- VMCODE(5,18,JMP,0,0)
- VMCODE(5,19,MOV,SAY_SENTENCE,105)
- VMCODE(5,20,JMP,0,0)
- // Benutze Feuerzeug mit Plaquestar Light
- VMCODE(6,0,UNLOCK,0,0)
- VMCODE(6,1,LOCK,0,0)
- VMCODE(6,2,IFCMP,ACTION_CODE,109)
- VMCODE(6,3,JMP,5,0)
- VMCODE(6,4,JMP,0,0)
- VMCODE(6,5,IFCMP,ITEM_A,112)
- VMCODE(6,6,JMP,8,0)
- VMCODE(6,7,JMP,0,0)
- VMCODE(6,8,IFCMP,ITEM_B,113)
- VMCODE(6,9,JMP,11,0)
- VMCODE(6,10,JMP,0,0)
- VMCODE(6,11,MOV,SAY_SENTENCE,110)
- VMCODE(6,12,JMP,0,0)
- // Variablen
- // In the data part, you have to put some values at certain addresses because the byte-code also doesn't support direct values and so on...
- // It would probably also make sense to extend the VM with registers and a stack option, however, theoretically full functionality is provided i guess
- data[101]=LOOK;
- data[102]=0;
- data[103]=10;
- data[104]=WALKTOXY;
- data[105]=1;
- data[106]=2;
- data[107]=140;
- data[108]=130;
- data[109]=COMBINE;
- data[110]=2;
- data[111]=5;
- data[112]=3;
- data[113]=4;
- data[X_SCROLL]=0;
- data[Y_SCROLL]=0;
- data[TIMERTICK]=0;
- data[PATHSTARTOBJ]=0;
- data[ROOM]=2;
- data[OBJ_NUM(0)+3]=2;
- data[OBJ_NUM(0)+2]=0;
- data[OBJ_NUM(0)+0]=0;
- data[OBJ_NUM(0)+1]=20;
- data[OBJ_NUM(0)+8]=50; // war 9
- data[OBJ_NUM(1)+3]=1;
- data[OBJ_NUM(1)+2]=1;
- data[OBJ_NUM(1)+0]=120;
- data[OBJ_NUM(1)+1]=52;
- data[OBJ_NUM(1)+8]=0;
- data[OBJ_NUM(2)+3]=0;
- data[OBJ_NUM(2)+2]=2;
- data[OBJ_NUM(2)+0]=120;
- data[OBJ_NUM(2)+1]=52;
- data[OBJ_NUM(2)+8]=0;
- data[OBJ_NUM(3)+3]=1;
- data[OBJ_NUM(3)+2]=3;
- data[OBJ_NUM(3)+0]=95;
- data[OBJ_NUM(3)+1]=52;
- data[OBJ_NUM(3)+8]=0;
- data[OBJ_NUM(4)+3]=0;
- data[OBJ_NUM(4)+2]=4;
- data[OBJ_NUM(4)+0]=70;
- data[OBJ_NUM(4)+1]=52;
- data[OBJ_NUM(4)+8]=0;
- data[OBJ_NUM(5)+3]=2;
- data[OBJ_NUM(5)+2]=5;
- data[OBJ_NUM(5)+0]=230;
- data[OBJ_NUM(5)+1]=15;
- data[OBJ_NUM(5)+8]=5;
- data[SAY_SENTENCE]=-1;
- data[ACTION_CODE]=NOACTION;
- strcpy(objnames[0],"Billy"); // each object needs a text string
- strcpy(objnames[1],"Wallet");
- strcpy(objnames[2],"Cash Card");
- strcpy(objnames[3],"Cigarette Lighter");
- strcpy(objnames[4],"Plaquestar Light"); // no similarity to real products intended
- strcpy(objnames[5],"Cigarette Machine");
- strcpy(sentences[0],"There's my cash card with a special chip.'");
- strcpy(sentences[1],"I first have to walk to the vending machine.");
- strcpy(sentences[2],"Now I have cancer."); // we're not gonna propagate anything. No irony intended.
- cursor[0]=80, cursor[1]=40;
- timertick=(long int)clock()/10000;
- while (1 )
- {
- VM_Step();
- if ( clock()/10000 != timertick ) data [TIMERTICK]=1, timertick=clock()/10000; // When the timer value goes a second higher or changes significantly,
- // we still will have enough time to transfer the notification into the script memory
- //else data[TIMERTICK]=0;
- int x=0, y=0;
- while ( y < 90)
- {
- x=0;
- while ( x< 160)
- {
- screen[x][y]=' '; // erase the screen
- x++;
- }
- y++;
- }
- unsigned char cmd;
- cmd=0;
- if ( kbhit()) // Keyboard press trigger
- {
- switch(getch())
- {
- case 'h' : if ( cursor[0] > 3 ) cursor[0]-=3; break;
- case 'k' : if ( cursor[0] < 156 ) cursor[0]+=3; break;
- case 'u' : if ( cursor[1] > 3 ) cursor[1]-=3; break;
- case 'j' : if ( cursor[1] < 84 ) cursor[1]+=3; break;
- case 'l' : cmd=1; break;
- }
- }
- // We can only move the cursor with four keys and 'click' with another
- drawlevel(); // It is necessary to also provide the Z information to some other program parts, so this has to be done before
- screen[cursor[0]][cursor[1]]='*';
- screen[20][70]='L',screen[21][70]='o',screen[22][70]='o',screen[23][70]='k', // Nice interface design
- screen[40][70]='P',screen[41][70]='i',screen[42][70]='c',screen[43][70]='k',
- screen[60][70]='U',screen[61][70]='s',screen[62][70]='e';
- // Build the command instructions together when there was a 'click'
- // It may look like a sentence, but internally it are only 3 IDs
- if ( cmd==1 )
- {
- signed int itema;
- if ( fabs ( cursor[0]-22 ) < 5 && fabs (cursor[1]-70 ) < 5 ) data[ACTION_CODE]=PREP_LOOK;
- else
- if ( fabs ( cursor[0]-42 ) < 5 && fabs (cursor[1]-70 ) < 5 ) data[ACTION_CODE]=PREP_PICK;
- else
- if ( fabs ( cursor[0]-61 ) < 5 && fabs (cursor[1]-70 ) < 5 )data[ACTION_CODE]=PREP_COMBI;
- else
- {
- if ( data[ACTION_CODE]==PREP_LOOK)
- {
- if ( (itema=getobjfromcoord(cursor[0],cursor[1]))!= -1)
- {
- data[ACTION_CODE]=LOOK;
- data[ITEM_A]=itema;
- }
- }
- else
- if ( data[ACTION_CODE]==PREP_PICK)
- {
- if ( (itema=getobjfromcoord(cursor[0],cursor[1]))!= -1)
- {
- data[ACTION_CODE]=PICK;
- data[ITEM_A]=itema;
- }
- }
- else
- if ( data[ACTION_CODE]==PREP_COMBI)
- {
- if ( (itema=getobjfromcoord(cursor[0],cursor[1]))!= -1)
- {
- data[ACTION_CODE]=PREP_COMBI_B;
- data[ITEM_A]=itema;
- }
- }
- else
- if ( data[ACTION_CODE]==PREP_COMBI_B)
- {
- signed int itemb;
- if ( (itemb=getobjfromcoord(cursor[0],cursor[1]))!= -1)
- {
- data[ACTION_CODE]=COMBINE;
- data[ITEM_B]=itemb;
- }
- }
- else if ( cursor[1] < 50) data[ACTION_CODE]=WALKTOXY, pathgoalx=cursor[0], pathgoaly=cursor[1]; // buffer the cursor target coordinates
- }
- }
- system("cls\n");
- y=0;
- while ( y < 85)
- {
- x=0;
- while ( x< 160)
- {
- printf("%c%c%c%c%c%c%c%c",screen[x][y], screen[x+1][y], screen[x+2][y], screen[x+3][y],screen[x+4][y],screen[x+5][y],screen[x+6][y],screen[x+7][y]);
- //printf("%c%c%c%c",screen[x][y], screen[x+1][y], screen[x+2][y], screen[x+3][y]);
- x+=8;
- }
- printf("\n");
- y++;
- }
- if ( data[OBJ_NUM(data[PATHSTARTOBJ])+7]==2) // When a script has requested it, run the path search
- if ( getobjNfromcoord(pathgoalx,pathgoaly,data[PATHSTARTOBJ])!=data[PATHSTARTOBJ] )
- find_path(data[PATHSTARTOBJ],pathgoalx+data[X_SCROLL],pathgoaly),data[ACTION_CODE]=WALKTOXY; else {
- data[OBJ_NUM(data[PATHSTARTOBJ])+7]=0,data[ACTION_CODE]=NOACTION; }
- //printf("%d %d", data[OBJ_NUM(0)+4],data[OBJ_NUM(0)+5]);
- // Dump the command sentence
- if ( data[ACTION_CODE]==PREP_LOOK) printf("Look at ");
- if ( data[ACTION_CODE]==PREP_PICK) printf("Pick Up");
- if ( data[ACTION_CODE]==PREP_COMBI) printf("Use");
- if ( data[ACTION_CODE]==LOOK) printf("Look at "), printf("%s",objnames[data[ITEM_A]]);
- if ( data[ACTION_CODE]==PICK) printf("Pick Up "), printf("%s",objnames[data[ITEM_A]]);
- if ( data[ACTION_CODE]==PREP_COMBI_B) printf("Use "), printf("%s",objnames[data[ITEM_A]]);
- if ( data[ACTION_CODE]==COMBINE) printf("Use "), printf("%s",objnames[data[ITEM_A]]), printf(" with "), printf("%s", objnames[data[ITEM_B]]);
- if ( data[SAY_SENTENCE]!=-1) printf("\n%s",sentences[data[SAY_SENTENCE]]);
- }
- }
- ```
- Dann habe ich neulich nochmal die Bezugsverkettung von Crosspoint nachprogrammiert-- Verzeichnisdarstellung als Stack, so wie DosTree...
- ```cpp
- /*
- Use md name to create a directory,
- touch name to create an entry in that directory
- cd name to change to a directory in the current directory
- root xx to go back to the root directory
- current xx to show the name of the current subdirectory
- and finally
- dir xx to visualize the directory tree in 160x90 console resolution
- */
- struct
- {
- signed int nextelem[255];
- unsigned char elems[255][10];
- } datei;
- unsigned char screen[160][120];
- int Xshift,Yshift;
- unsigned int pushelem[255];
- unsigned int pusholdx[255];
- unsigned int pusholdy[255];
- int Stackcount;
- int main(void)
- {
- int x,y;
- unsigned char cmd[255], name[255];
- int n=0,n2=0,n3=0;
- while (n < 255 ) datei.nextelem[n]=-1, n++;
- n=0;
- Stackcount=0;
- int curdir=0;
- datei.nextelem[curdir]=-2;
- datei.elems[curdir][0]='-';
- pushelem[0]=0;
- while (1 )
- {
- scanf ("%s %s", cmd, name );
- if ( strcmp ( cmd, "touch" ) == 0 )
- {
- n=curdir;
- while ( datei.elems[n][0]!='-' ) n=datei.nextelem[n];
- strcpy(datei.elems[n], name );
- datei.nextelem[n]=-3; // Pfuschdihuschdi
- n2=0;
- while ( datei.nextelem[n2] != -1 ) n2++;
- datei.nextelem[n]=(unsigned char)n2;
- datei.elems[n2][0]='-';
- datei.nextelem[n2]=-2; // zeigt es auf kein naechstes Element, ist es frei
- }
- if ( strcmp ( cmd, "md" ) == 0 )
- {
- n=curdir;
- while ( datei.elems[n][0]!='-' ) n=datei.nextelem[n];
- strcpy(datei.elems[n]+2, name );
- datei.nextelem[n]=-3; // Pfuschdihuschdi
- datei.elems[n][0]='~';
- n3=n;
- n2=0;
- while ( datei.nextelem[n2] != -1 ) n2++;
- datei.elems[n][1]=(unsigned char)n2;
- int n4=0;
- n4=n2;
- datei.nextelem[n2]=-3; // Pfuschdihuschdi
- //datei.nextelem[n2]=-2;
- datei.elems[n2][0]='-';
- n2=0;
- while ( datei.nextelem[n2] != -1 ) n2++;
- datei.nextelem[n2]=-2;
- datei.elems[n2][0]='-';
- datei.nextelem[n3]=(unsigned char)n2;
- datei.nextelem[n4]=-2;
- }
- if ( strcmp(cmd,"current")==0)printf("%s>>",datei.elems[curdir]);
- if ( strcmp (cmd,"root")==0 ) curdir=0;
- if ( strcmp ( cmd, "cd" ) == 0 )
- {
- n=curdir;
- while ( datei.elems[n][0]!='-' &&
- (strcmp( datei.elems[ n/*datei.nextelem[n] */ ]+2,name)!=0 ||datei.elems[ n /* datei.nextelem[n] */ ][0]!='~' ) ) n=datei.nextelem[n];
- if ( datei.elems[n][0]!='-') curdir=datei.elems[n][1];
- }
- if ( strcmp(cmd,"dir" ) == 0 )
- {
- y=0;
- while ( y < 90 )
- {
- x=0;
- while ( x < 160 )
- {
- screen[x][y]=' ';
- x++;
- }
- y++;
- }
- Xshift=0, Yshift=0;
- Stackcount=1;
- n=0;
- int Stackcount2=0;
- Stackcount2=0;
- pusholdx[Stackcount2]=0;
- pusholdy[Stackcount2]=0;
- do
- {
- if ( datei.elems[n][0]=='~' )
- {
- n2=2;
- //printf("Verzeichnis: %s",datei.elems[n]), getch();
- x=pusholdx[Stackcount2];
- y=pusholdy[Stackcount2];
- Xshift=x+10;
- Yshift+=5;
- while ( y< Yshift)
- {
- if ( y < Yshift) screen[x][y]==' ' ? screen[x][y]=219:0, y++;
- }
- while ( x< Xshift)
- {
- if ( x < Xshift) screen[x][y]= screen[x][y]==' ' ? screen[x][y]=219:0, x++;
- }
- while ( datei.elems[n][n2]!='\0' ) screen[Xshift+n2-2] [Yshift]=datei.elems[n][n2],n2++;
- Stackcount2++;
- pusholdx[Stackcount2]=Xshift;
- pusholdy[Stackcount2]=Yshift;
- pushelem[Stackcount]=datei.nextelem[n] ;
- n= datei.elems[n][1];
- //n=datei.nextelem[n];
- //printf("%s",datei.elems[n]), getch();
- Stackcount++;
- }
- else
- if ( datei.elems[n][0]=='-' )
- {
- Stackcount--;
- Stackcount2--;
- n=pushelem[Stackcount];
- }
- else
- {
- x=pusholdx[Stackcount2];
- y=pusholdy[Stackcount2];
- Yshift+=5;
- Xshift=x;
- while ( y< Yshift)
- {
- if ( y < Yshift) screen[x][y]==' ' ? screen[x][y]=219:0, y++;
- }
- while ( x< Xshift)
- {
- if ( x < Xshift) screen[x][y]==' ' ? screen[x][y]=219:0, x++;
- }
- n2=0;
- //printf("Flach: %s",datei.elems[n]),getch();
- while ( datei.elems[n][n2]!='\0' ) screen[Xshift+n2] [Yshift]=datei.elems[n][n2],n2++;
- n=datei.nextelem[n];
- pusholdx[Stackcount2]=Xshift;
- pusholdy[Stackcount2]=Yshift;
- }
- } while ( Stackcount > 0 /*|| datei.elems[n][0]!='-' */);
- system("cls\n");
- y=0;
- while ( y < 80 )
- {
- x=0;
- while ( x < 160 )
- {
- printf("%c",screen[x][y] );
- x++;
- }
- printf("\n");
- y++;
- }
- }
- }
- }
- ```
- Ich hoffe, daß die Quelltexte icht den Thread sprengen. Wie gesagt, im derzeitigen Zustand sind sie noch recht häßlich. Aber es dreht sich ja wohl darum, grundlegegende Probleme zu lösen. Und ich glaube, das habe ich dennoch "schön" gemacht.
- Hier noch das Blockscrolling eines 2D-Jump N' Runs:
- ```cpp
- unsigned char level[600]=
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1 };
- unsigned char block[25]={219,219,'@',219,219,
- 219,219,'@',219,219,
- 219,'@','@','@',219,
- 219,219,'@',219,219,
- 219,219,'@',219,219 };
- struct
- {
- int x, y;
- int jump;
- } maennle;
- int main(void)
- {
- int c;
- int scroll_x;
- int block_n;
- unsigned char screen[160][120];
- long int runs=0;
- scroll_x=0;
- maennle.x=30, maennle.y=40;
- maennle.jump=0;
- while ( 1 )
- {
- maennle.y++;
- if ( kbhit() )
- {
- c=getch();
- if ( c=='l' )
- {
- if ( maennle.x/5 +1 < 200-160)
- if (level[maennle.x/5+1+(maennle.y/5)*40]==0) maennle.x++;
- }
- else if ( c=='k' )
- {
- if ( maennle.x/5-1 > 0) if (level[maennle.x/5-1+(maennle.y/5)*40]==0) maennle.x--;
- }
- else if ( c=='o' && maennle.jump==0 )
- {
- if ( ((maennle.y+1)/5) < 15) if (level[maennle.x/5+((maennle.y+1)/5)*40]==1) maennle.jump=10;
- }
- }
- int x,y;
- scroll_x=maennle.x-40 > 0 ? maennle.x-40 : 0;
- if ( scroll_x > 200-160) scroll_x=200-160;
- if ( maennle.jump > 0 &&level[maennle.x/5+((maennle.y-1)/5)*40]==0) maennle.y-=2, maennle.jump--;
- else if ( maennle.jump > 0) maennle.jump--;
- if (level[maennle.x/5+((maennle.y+1)/5)*40]==1 ) maennle.y--;
- if ( maennle.y/5==15) printf("\a");
- x=0, y=0;
- while ( y < 90 )
- {
- x=0;
- while ( x < 160 )
- {
- screen[x][y]=' ';
- x++;
- }
- y++;
- }
- int block_n_start;
- block_n_start=scroll_x/5;
- int offset;
- int y_map;
- offset=scroll_x%5;
- block_n=1;
- while ( block_n < 32 )
- {
- y_map=0;
- while ( y_map < 15 )
- {
- if ( level[block_n_start+block_n+y_map*40]==1 )
- {
- y=0;
- while ( y < 5 )
- {
- x=0;
- while ( x < 5 )
- {
- screen[block_n*5+x-offset][y_map*5+y]=block[x+y*5];
- x++;
- }
- y++;
- }
- }
- y_map++;
- }
- block_n++;
- }
- screen[maennle.x-scroll_x][maennle.y-1]='o';
- screen[maennle.x-scroll_x][maennle.y]='O';
- screen[maennle.x-1-scroll_x][maennle.y]='/';
- screen[maennle.x+1-scroll_x][maennle.y]='\\';
- screen[maennle.x-scroll_x][maennle.y+1]='M';
- screen[maennle.x-scroll_x][maennle.y+2]='|';
- screen[maennle.x+1-scroll_x][maennle.y+2]='|';
- if ( runs%3==0)
- {
- system("cls\n");
- x=0, y=0;
- while ( y < 90 )
- {
- x=0;
- while ( x < 159 )
- {
- if ( x < 4 || x > 155) printf("||||"); else
- printf("%c%c%c%c",screen[x][y],screen[x+1][y],screen[x+2][y],screen[x+3][y]);
- x+=4;
- }
- printf("\n");
- y++;
- }
- }
- runs++;
- }
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment