#include #include #define t1 100 unsigned int time1; //video transmission variables char rowCount, colCount; char *screen_pointer, *char_pointer, *screen_pointerR; char lastInputFlag, syncYet, coldStart; char screen[588]; char buffer[14]; char screenUpdate; #define POSY 1 #define POSX 2 #define NEGY 4 #define NEGX 8 #define POSYmask 0x88 #define POSXmask 0x44 #define NEGYmask 0x22 #define NEGXmask 0x11 #define LEFTWARD 1 #define RIGHTWARD 2 //drawing variables #define stdGrad 0xab5 #define stdGradL 12 #define grad4 0x24949 #define grad4L 20 unsigned char segments[64] = { 0, 0, 0, 0, 33, 20, 3, 0, 33, 20, 3, 0, 0, 0, 0, 0, 14, 13, 7, 0, 23, 14, 5, 12, 23, 0, 0, 0, 0, 0, 0, 0, 0, 12, 8, 0, 27, 16, 5, 9, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 30, 18, 6, 7, 38, 7, 0, 0, 0, 0, 0, 0 }; unsigned long gradients[12] = { 0xffff, 0x24949, 0x24949, 0xdddd, 0x5555, 0x8, 0xf7f7, 0x2a55, 0x2, 0xffff, 0x24a5, 0x4891 }; unsigned char gradient_lengths[12] = { 16, 20, 20, 16, 16, 9, 16, 16, 5, 16, 15, 18 }; unsigned int gradient_offsets[21] = { 0, 202, 203, 126, 207, 207, 238, 205, 205, 406, 204, 204, 419, 201, 201, 251, 200, 200, 139, 198, 198 }; unsigned char gradient_offsets_mask[21] = { 0, 0x01, 0x80, 0x80, 0x80, 0x40, 0x80, 0x04, 0x02, 0x80, 0x20, 0x10, 0x01, 0x04, 0x08, 0x01, 0x20, 0x40, 0x01, 0x01, 0x02 }; //game variables /* #define mazeWidth 8 #define mazeByteWidth 4 #define mazeHeight 8 unsigned char maze[32] = { 0x00, 0xd0, 0xd0, 0x00, //0 0x0b, 0x0a, 0x2a, 0xa0, //8 0x00, 0x50, 0x00, 0x00, //16 0x00, 0x1a, 0xa8, 0xae, //24 0xba, 0x40, 0x05, 0x00, //32 0x00, 0x50, 0x96, 0x00, //40 0x00, 0x1a, 0x60, 0x00, //48 0x00, 0x70, 0x00, 0x00 //56 }; */ #define mazeWidth 16 #define mazeByteWidth 8 #define mazeHeight 16 /* unsigned char maze[128] = { 0x00, 0xd0, 0xd0, 0x00, 0x00, 0xd0, 0xd0, 0x00, //0 0x0b, 0x0a, 0x2a, 0xe0, 0x0b, 0x0a, 0x2a, 0xa0, //16 0x00, 0x50, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, //32 0x00, 0x1a, 0xa8, 0xac, 0x00, 0x1a, 0xa8, 0xae, //48 0xba, 0x40, 0x05, 0x03, 0xaa, 0x40, 0x05, 0x00, //64 0x00, 0x50, 0x96, 0x00, 0x00, 0x50, 0x96, 0x00, //80 0x00, 0x1a, 0x60, 0x00, 0x00, 0x1a, 0x60, 0x00, //96 0x00, 0x70, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00 //112 }; #define startPos 64 #define endPos 31 #define startDirection 8 */ unsigned char maze[128] = { 0xd9, 0xaa, 0xc9, 0xa8, 0xaa, 0xa8, 0xaa, 0xc0, 0x55, 0x0d, 0x55, 0x05, 0x00, 0x05, 0x0d, 0x3c, 0x53, 0xa6, 0x57, 0x05, 0x00, 0x05, 0x05, 0x05, 0x1a, 0xaa, 0x0a, 0xa0, 0xe9, 0xa0, 0xa2, 0xa4, 0x50, 0xbc, 0x50, 0xd5, 0x05, 0x05, 0x0d, 0x05, 0x50, 0x05, 0x1a, 0x45, 0x96, 0x01, 0xa2, 0xa4, 0x1a, 0x86, 0x50, 0x55, 0x5b, 0xa6, 0x00, 0x05, 0x50, 0x50, 0x50, 0x75, 0x1a, 0xa8, 0xa8, 0xa4, 0x1e, 0x3a, 0x28, 0xa4, 0x5d, 0x05, 0x05, 0x05, 0x50, 0x00, 0x05, 0x05, 0x05, 0x01, 0xa4, 0x05, 0x3a, 0xa8, 0xa2, 0xc1, 0xa2, 0xa6, 0x05, 0x05, 0x00, 0x05, 0x00, 0x57, 0x9a, 0x8a, 0x82, 0xa4, 0x9a, 0xa2, 0xaa, 0x0a, 0x60, 0x50, 0x50, 0x05, 0x50, 0x9a, 0xac, 0x79, 0xa8, 0x60, 0x5b, 0xa4, 0x50, 0x50, 0x03, 0xa6, 0x05, 0xd0, 0x50, 0x05, 0x3a, 0x2a, 0xaa, 0xaa, 0xa6, 0x3a, 0x2a, 0xa6 }; #define startPos 0 #define endPos 152 #define startDirection 16 unsigned char currentPos; unsigned char maskPos, maskPos_temp, endMask; signed char offsetX, offsetY; signed char direction; char *maze_pointer, *maze_pointer_temp, *end_pointer; signed int i, j, k, l; char a, b, c, d, e; unsigned char mode_length, new_room, showL, showR, showF, showF_last, sideLeftH, sideRightH; unsigned char maskL, maskR, frontMask, leftMask, rightMask, backMask; signed char offsetX_temp, offsetY_temp, rh_length, lh_length; unsigned char buffer1, bufferCounter; unsigned long gradBuffer; unsigned char front, back, left, right, walled, peekDir; //variables for continuous turning unsigned char drawDirection, gOffset, g_oOffset, sOffset; unsigned char tmask1, tmask2, tmask3; //game state variables unsigned char won; //accelerometer vars unsigned char historyCount, startup, AinX, avgX; unsigned int avgXac; signed char diff_x; //fixed point unsigned char AinY, avgY; unsigned int avgYac; signed char diff_y; //fixed point unsigned char frameCount; unsigned char sensorMode; //sound var unsigned char playSound; //sets the mode based on the current facing void set_direction_parameters(void) { if(direction<8) { //UP frontMask = POSYmask; leftMask = NEGXmask; rightMask = POSXmask; backMask = NEGYmask; front = POSY; back = NEGY; left = NEGX; right = POSX; } else if(direction<16) { //RIGHT frontMask = POSXmask; leftMask = POSYmask; rightMask = NEGYmask; backMask = NEGXmask; front = POSX; back = NEGX; left = POSY; right = NEGY; } else if(direction<24) { //DOWN frontMask = NEGYmask; leftMask = POSXmask; rightMask = NEGXmask; backMask = POSYmask; front = NEGY; back = POSY; left = POSX; right = NEGX; } else if(direction<32) { //LEFT frontMask = NEGXmask; leftMask = NEGYmask; rightMask = POSYmask; backMask = POSXmask; front = NEGX; back = POSX; left = NEGY; right = POSY; } } void onesec() { if(coldStart) { //check if it is a cold start. do we need to start a conversation unilaterally? lastInputFlag = lastInputFlag==0?1:0; } else { coldStart = 1; } if(playSound>0) { //check if a sound is being played if(playSound==1) { PORTB = PORTB&0b11001111; //turn off sound playSound = 0; } else { playSound--; } } } //timer 0 compare ISR interrupt [TIM0_COMP] void timer0_compare(void) { //Decrement the timer if not already zero if (time1>0) --time1; if (time1==0) { //every 100ms time1 = t1; onesec(); } } //THIS FUNCTION MOVES THE USER ONE X/Y INCREMENT (MAZE CELL SUBSECTION) //mode defines the direction char move(char mode) { switch(mode) { case POSY: if(!((*maze_pointer)&maskPos&POSYmask && offsetY>=0)) { offsetY++; } else { //cannot move in direction PORTB = PORTB|0x20; //play invalid sound playSound=2; return 0; } if(offsetY>3) { //check next room offsetY -= 8; maze_pointer -= mazeByteWidth; PORTB = PORTB|0x10; playSound=2; //play room movement sound } break; case POSX: if(!((*maze_pointer)&maskPos&POSXmask && offsetX>=0)) { offsetX++; } else { //cannot move in direction PORTB = PORTB|0x20; //play invalid sound playSound=2; return 0; } if(offsetX>3) { //check next room offsetX -= 8; if(maskPos==0x0f) { maze_pointer++; PORTB = PORTB|0x10; //play room movement sound playSound=2; } maskPos = ~maskPos; } break; case NEGY: if(!((*maze_pointer)&maskPos&NEGYmask && offsetY<=0)) { offsetY--; } else { //cannot move in direction PORTB = PORTB|0x20; //play invalid sound playSound=2; return 0; } if(offsetY<-4) { // check next room offsetY += 8; maze_pointer += mazeByteWidth; PORTB = PORTB|0x10; //play room movement sound playSound=2; } break; case NEGX: if(!((*maze_pointer)&maskPos&NEGXmask && offsetX<=0)) { offsetX--; } else { //cannot move in direction PORTB = PORTB|0x20; //play invalid sound playSound=2; return 0; } if(offsetX<-4) { //check next room offsetX += 8; if(maskPos==0xf0) { maze_pointer--; } maskPos = ~maskPos; PORTB = PORTB|0x10; //play room movement sound playSound=2; } break; } return 1; } //returns the bit mask for the room one room in a certain direction without actually moving to it char peek(char mode) { unsigned char mpt2; signed char offset; offset = 0; mpt2 = maskPos_temp; if(mode&POSX) { offset = maskPos_temp==0x0f?1:0; mpt2=~mpt2; } else if(mode&NEGX) { offset = maskPos_temp==0xf0?-1:0; mpt2=~mpt2; } if(mode&POSY) offset -= mazeByteWidth; else if(mode&NEGY) offset += mazeByteWidth; return (*(maze_pointer_temp+offset))&mpt2; } //moves the temporary pointers (maze_pointer_temp, offsetY, offsetX, maskPos_temp) one subsection in the specified direction char explore(char mode) { switch(mode) { case POSY: offsetY_temp++; if(offsetY_temp>3) { //move up maze offsetY_temp -= 8; maze_pointer_temp -= mazeByteWidth; return 1; } break; case NEGY: offsetY_temp--; if(offsetY_temp<-4) { //move down maze offsetY_temp += 8; maze_pointer_temp += mazeByteWidth; return 1; } break; case POSX: offsetX_temp++; if(offsetX_temp>3) { //move right maze offsetX_temp -= 8; if(maskPos_temp==0x0f) maze_pointer_temp++; maskPos_temp = ~maskPos_temp; return 1; } break; case NEGX: offsetX_temp--; if(offsetX_temp<-4) { //move left maze offsetX_temp += 8; if(maskPos_temp==0xf0) maze_pointer_temp--; maskPos_temp = ~maskPos_temp; return 1; } break; } return 0; } //moves the temporary pointers (maze_pointer_temp, maskPos_temp) one cell in the specified direction void explore_step(char mode) { switch(mode) { case POSY: maze_pointer_temp -= mazeByteWidth; break; case NEGY: maze_pointer_temp += mazeByteWidth; break; case POSX: if(maskPos_temp==0x0f) maze_pointer_temp++; maskPos_temp = ~maskPos_temp; break; case NEGX: if(maskPos_temp==0xf0) maze_pointer_temp--; maskPos_temp = ~maskPos_temp; break; } } //draws a horizontal line for a specified length starting from a pixel position defined by mask and start void draw_horizontal_line(char* start, char mask, signed char length) { if(length>0) { //positive length while(mask!=0 && length>0) { //draw until byte limit (*start) = (*start)|mask; length--; mask>>=1; } while(length>=8) { //draw full bytes start++; (*start) = 0xff; length-=8; } mask = 0x80; start++; while(length>0) { //draw leftover (*start) = (*start)|mask; length--; mask>>=1; } } else { //negative length while(mask!=0 && length<0) { //draw until byte limit (*start) = (*start)|mask; length++; mask<<=1; } while(length<=-8) { //draw full bytes start--; (*start) = 0xff; length+=8; } mask = 0x01; start--; while(length<0) { //draw leftover (*start) = (*start)|mask; length++; mask<<=1; } } return; } //draws an line from position defined by start and mask, in direction isPosY for length length, given gradient specified by gradient gradientLen void draw_line(char* start, char mask, char isPosY, signed char length, unsigned int gradient, unsigned char gradientLen) { unsigned int gradientBuffer; unsigned char gradientCounter; gradientBuffer = gradient; gradientCounter = gradientLen; while(length!=0) { (*start) = (*start)|mask; //draw pixel if(length>0) { mask>>=1; length--; if(mask==0) { mask = 0x80; start++; } } else { mask<<=1; length++; if(mask==0) { mask = 0x01; start--; } } if(gradientBuffer&0x1) { //check if we need to move a line up/down if(isPosY>0) { start-=14; } else { start+=14; } } gradientBuffer>>=1; gradientCounter--; if(gradientCounter==0) { gradientBuffer = gradient; gradientCounter = gradientLen; } } } //draws a diamond at position defined by start and mask, for specified length. this is for display the exit of the maze void draw_diamond(char* start, char mask, unsigned char length) { char count; length>>=2; //length/4 while(start>=1; if(mask==0) { mask = 0x80; start++; } } for(count=0;count>=1; if(mask==0) { mask = 0x80; start++; } } for(count=1;count>=1; if(mask==0) { mask = 0x80; start++; } } } void main(void) { { //set up AtoD ADMUX = 0b01100000; ADCSR = 0b11000111; /* PORTB [0] = 1 to 2, (output) [1] = 2 to 1 (input) [2] = sync (output) [4..5] = audio flag (output) */ DDRB=0b00110101; PINB.0 = 0; PINB.4 = 0; PINB.5 = 0; DDRC=0xff; //PORTC = output PORTC=0; DDRD=0xff; //PORTD = output PORTD=0; //accelerometer parameters startup = 1; historyCount = 0; sensorMode = 0; frameCount = 0; //set up timer 0 TIMSK=2; //turn on timer 0 cmp match ISR OCR0 = 250; //set the compare re to 250 time ticks //prescalar to 64 and turn on clear-on-match TCCR0=0b00001011; //video vars syncYet = 2; lastInputFlag = 2; screenUpdate = 1; //game vars won = 0; //sound vars playSound = 0; //calculate starting position currentPos = startPos>>1; if(startPos%2==0) maskPos = 0xf0; else maskPos = 0x0f; maze_pointer = maze + currentPos; //calculate ending pointer if(endPos%2==0) { endMask = 0xf0; } else { endMask = 0x0f; } end_pointer = maze + (endPos>>1); offsetX = 0; offsetY = 0; direction = startDirection; rh_length = -1; //right horizontal length lh_length = 1; //left horizontal length set_direction_parameters(); //crank up the ISRs #asm sei #endasm } while (1) { if(screenUpdate) { //SCREEN UPDATE CODE if(PINB.1!=lastInputFlag) { //check if other side has flagged lastInputFlag = PINB.1; //set flag if(syncYet==2) { //reset variables, generate new frame signal screen_pointer = screen; rowCount = 0; colCount = 0; PORTB = PORTB | 0x04; syncYet--; coldStart = 0; for(i=0;i<14;i++) buffer[i] = 0; } else { if(syncYet==1) { //unset new frame signal PORTB = PORTB & 0xfb; syncYet--; } if(rowCount>7 && rowCount<50) { //top half if(colCount==0) { char_pointer = buffer; PORTD = 0x01; //draw left border *char_pointer = (*screen_pointer++)|(*char_pointer); //OR line with buffer PORTC = *char_pointer++; } else if(colCount==14) { *char_pointer = (*screen_pointer++)|(*char_pointer); PORTD = *char_pointer++; PORTC = 0x80; //draw right border } else { *char_pointer = (*screen_pointer++)|(*char_pointer); PORTD = *char_pointer++; *char_pointer = (*screen_pointer++)|(*char_pointer); PORTC = *char_pointer++; } } else if(rowCount>49 && rowCount<92) { //bottom half if(colCount==0) { char_pointer = buffer; PORTD = 0x01; PORTC = *char_pointer; *char_pointer = (*screen_pointer++)^(*char_pointer); //XOR line with buffer char_pointer++; } else if(colCount==14) { PORTD = *char_pointer; *char_pointer = (*screen_pointer++)^(*char_pointer); char_pointer++; PORTC = 0x80; } else { PORTD = *char_pointer; *char_pointer = (*screen_pointer++)^(*char_pointer); char_pointer++; PORTC = *char_pointer; *char_pointer = (*screen_pointer++)^(*char_pointer); char_pointer++; } } else if(rowCount==7 || rowCount==92) { //draw top/bottom borders if(colCount==0) { PORTD = 0x01; PORTC = 0xff; } else if(colCount==14) { PORTD = 0xff; PORTC = 0x80; } else { PORTD = 0xff; PORTC = 0xff; } } else { PORTD = 0x00; PORTC = 0x00; } colCount+=2; if(colCount==16) { //last column rowCount++; colCount=0; if(rowCount==50) { screen_pointer -= 14; } else if(rowCount>50 && rowCount<92) { //bottom half pointer backing up screen_pointer -= 28; } } if(rowCount==100) { syncYet = 2; screenUpdate = 0; } } PORTB = PORTB ^ 0x01; //flag ready } //SCREEN UPDATE CODE } else if(!won) { //blank the screen screen_pointer = screen; for(i=0;i<588;i++) { (*screen_pointer++) = 0; } //DETECT MOVEMENT if(sensorMode==0) { ADMUX = 0b01100001; AinY = ADCH; //read in Y data ADCSR.6=1; } else { //left/right ADMUX = 0b01100000; AinX = ADCH; //read in X data ADCSR.6=1; if(startup) { //perform averages code avgXac += AinX; avgYac += AinY; historyCount++; if(historyCount==16) { startup = 0; avgX = avgXac>>4; avgY = avgYac>>4; //take averages } } else { frameCount = ~frameCount; //invert frameCount for half speed movement diff_x = AinX-avgX; diff_y = AinY-avgY; if(diff_y>15 || (diff_y>10 && frameCount==0)) { //check for forward movement if(direction==0 || direction==8 || direction==16 || direction==24) { move(back); } else { //turn if not facing cardinal point if(direction%8>4) { direction++; } else { direction--; } if(direction>=32) direction-=32; set_direction_parameters(); } } else if(diff_y<-15 || (diff_y<-10 && frameCount==0)) { //check for backward movement if(direction==0 || direction==8 || direction==16 || direction==24) { move(front); } else { if(direction%8>4) { direction++; } else { direction--; } if(direction>=32) direction-=32; set_direction_parameters(); } } if(diff_x>10 || (diff_x>5 && frameCount==0)) { if(offsetX!=0) { if(offsetX>0) offsetX--; else offsetX++; } else if(offsetY!=0) { if(offsetY>0) offsetY--; else offsetY++; } else { direction++; if(direction>31) direction-=32; set_direction_parameters(); } } else if(diff_x<-10 || (diff_x<-5 && frameCount==0)) { if(offsetX!=0) { if(offsetX>0) offsetX--; else offsetX++; } else if(offsetY!=0) { if(offsetY>0) offsetY--; else offsetY++; } else { direction--; if(direction<0) direction+=32; set_direction_parameters(); } } if(maze_pointer==end_pointer && maskPos == endMask) { //WIN MAZE screen[0] = 0x55; screen[1] = 0x55; screen[2] = 0x55; screen[11] = 0x55; screen[12] = 0x55; screen[13] = 0x55; won = 1; PORTB = PORTB|0x30; playSound=30; } } } sensorMode = 1-sensorMode; if(direction==0 || direction==8 || direction==16 || direction==24) { //START DRAWING maze_pointer_temp = maze_pointer; offsetX_temp = offsetX; offsetY_temp = offsetY; maskPos_temp = maskPos; screen_pointer = screen + 112; screen_pointerR = screen + 125; //STANDARD PATH (backwards/forwards) START maskL = 0x80; maskR = 0x01; mode_length = 3; k=0; showF_last = 0; new_room = 0; rh_length = -1; //counts the length of the empty spaces on the right lh_length = 1; //counts the length of the empty spaces on the left gradBuffer = stdGrad; bufferCounter = 0; sideLeftH = 0; //flags if horizontal line should be drawn on left/right, 0 is horizontal, 1 is negative stdGrad sideRightH = 0; for(i=0;i<24;i++) { //iterate through room segments //read map information if(i==8 || i==16) mode_length--; //decide whether to show walls on the left, right and front showL = (*maze_pointer_temp)&maskPos_temp&leftMask; showR = (*maze_pointer_temp)&maskPos_temp&rightMask; showF = (*maze_pointer_temp)&maskPos_temp&frontMask; //check exit if(maze_pointer_temp==end_pointer && maskPos_temp==endMask) { draw_diamond(screen_pointer,maskL,110-k-k); i = 24; } //check FRONT wall start else if(showF_last && new_room) { //if the last room had a front wall and we are at a new room, draw the wall draw_horizontal_line(screen_pointer,maskL>>1,110-k-k); i = 24; } showF_last = showF; //check FRONT wall end //check SIDE FRONT walls start { if(!showL && i<23) { if(lh_length>0) { if(peek(left)&frontMask) { sideLeftH = 1; } lh_length-=mode_length; if(i==0) {lh_length--; } } else { lh_length-=mode_length; } } else if(lh_length<=0&&new_room) { if(sideLeftH) draw_horizontal_line(screen_pointer,maskL<<1,lh_length); //if the last room on the side had a front wall, draw the wall sideLeftH = 0; lh_length = 1; } if(!showR && i<23) { if(rh_length<0) { if(peek(right)&frontMask) { sideRightH = 1; } rh_length+=mode_length; if(i==0) { rh_length++; } } else { rh_length+=mode_length; } } else if(rh_length>=0&&new_room) { if(sideRightH) draw_horizontal_line(screen_pointerR,maskR>>1,rh_length); sideRightH = 0; rh_length = -1; } } //check SIDE FRONT walls end for(j=0;j>=1; bufferCounter++; if(bufferCounter==stdGradL) { gradBuffer = stdGrad; bufferCounter=0; } if(buffer1>0) { screen_pointer+=14; screen_pointerR+=14; } //check overflows if(maskL==0x01) { maskL = 0x80; maskR = 0x01; screen_pointer++; screen_pointerR--; } else { maskL>>=1; maskR<<=1; } } if(!walled) { //explore space in increments new_room = explore(front); } } //STANDARD PATH (backwards/forwards) END } else { //DRAW TURNING MODE START b = direction&0x3; //step number a = direction&0x4 && b>0; //if direction > 45deg if(a) { gOffset = (4-b)*3; g_oOffset = (3+b)*3; } else { gOffset = b*3; g_oOffset = gOffset; } for(l=2;l>=0;l--) { if(a) { //bigger than 45deg sOffset = ((4-b)<<4)+(l<<2); //segment offset if(l==0) { //determine drawing directions drawDirection = LEFTWARD; tmask1 = rightMask; tmask2 = backMask; peekDir = back; } else if(l==1) { drawDirection = RIGHTWARD; tmask1 = rightMask; tmask2 = frontMask; peekDir = front; } else if(l==2) { drawDirection = LEFTWARD; tmask1 = frontMask; tmask2 = rightMask; peekDir = right; } } else { sOffset = (b<<4)+(l<<2); //segment offset if(l==0) { drawDirection = RIGHTWARD; tmask1 = frontMask; tmask2 = leftMask; peekDir = left; } else if(l==1) { drawDirection = LEFTWARD; tmask1 = frontMask; tmask2 = rightMask; peekDir = right; } else if(l==2) { drawDirection = RIGHTWARD; tmask1 = rightMask; tmask2 = frontMask; peekDir = front; } } maze_pointer_temp = maze_pointer; maskPos_temp = maskPos; screen_pointer = screen + gradient_offsets[g_oOffset+l]; //determine where we should start drawing bufferCounter = 0; gradBuffer = gradients[gOffset+l]; //load gradient tmask3 = gradient_offsets_mask[g_oOffset+l]; //load gradient starting position //check pathways for(i=0;i<3;i++) { if((*maze_pointer_temp)&maskPos_temp&tmask1) { //Check if we should draw front wall if(l==0) { break; } //walls only drawn if l==1 or l==2 bufferCounter = 0; gradBuffer = gradients[gOffset+3-l]; //load gradient //find the length of the wall that needs to be drawn k=0; for(j=i;j<3;j++) { k += segments[sOffset+j]; } k+=segments[sOffset+3]; for(j=2;j>=i && l==1;j--) k+=segments[sOffset-4+j]; if(l==1) { if(segments[sOffset-4+j]>0 && k>0) { k++; } d=-1; } else { d=0; } //draw wall for k pixels length for(j=0;j>=1; bufferCounter++; if(bufferCounter==gradient_lengths[gOffset+3-l]) { gradBuffer = gradients[gOffset+3-l]; bufferCounter = 0; } if(drawDirection == LEFTWARD) { tmask3<<=1; if(tmask3==0) { screen_pointer--; tmask3 = 0x01; } } else if(drawDirection == RIGHTWARD) { tmask3>>=1; if(tmask3==0) { screen_pointer++; tmask3 = 0x80; } } } break; } else {//no front wall, normal drawing mode if(l==2) { d = 0; } else { d = segments[sOffset+i]-1; } if(a) { if(l==2) explore_step(front); else explore_step(right); } else { if(l==2) explore_step(right); else explore_step(front); } c = (*maze_pointer_temp)&maskPos_temp&tmask2; //is there a wall on the side for(j=0;j>=1; bufferCounter++; if(bufferCounter==gradient_lengths[gOffset+l]) { gradBuffer = gradients[gOffset+l]; bufferCounter = 0; } //process gradient leftwards if(drawDirection == LEFTWARD) { tmask3<<=1; if(tmask3==0) { screen_pointer--; tmask3 = 0x01; } } else if(drawDirection == RIGHTWARD) { tmask3>>=1; if(tmask3==0) { screen_pointer++; tmask3 = 0x80; } } } //check for sideway passages if(!c && (peek(peekDir)&tmask1) && segments[sOffset+i]>0 && segments[sOffset+i+1]>0) { if(drawDirection == LEFTWARD) { //draw rightward draw_line(screen_pointer,tmask3>>(l==2?1:2),l==0?1:0,segments[sOffset+i]-1,gradients[gOffset+2],gradient_lengths[gOffset+2]); } else if(drawDirection == RIGHTWARD) { //draw leftward draw_line(screen_pointer,tmask3<<(l==2?1:2),l==0?1:0,(~segments[sOffset+i])+2,gradients[gOffset+2],gradient_lengths[gOffset+2]); } } } } }//DRAW TURNING MODE END } screenUpdate = 1; } } }