//video gen //D.5 is sync:1000 ohm + diode to 75 ohm resistor //D.6 is video:330 ohm + diode to 75 ohm resistor //B.3 is sound and should have a 10k resistor to gnd #pragma regalloc- //I allocate the registers myself #pragma optsize- //optimize for speed #include #include #include #include #include //cycles = 63.625 * 16 Note NTSC is 63.55 //but this line duration makes each frame exactly 1/60 sec //which is nice for keeping a realtime clock #define lineTime 1018 //debounce states #define noPush 1 #define maybePush 2 #define push 3 #define maybeNoPush 4 #define begin { #define end } #define ScreenTop 30 #define ScreenBot 230 #define width 126 //necessary function prototypes void pbMP(void); void pbNP(void); void pbPushed(void); void pbMNP(void); void pbDebounce(void); void pbMPstart(void); void pbNPstart(void); void pbPushedstart(void); void pbMNPstart(void); void startDebounce(void); void video_putStair(char x); void video_putmonster(char x, char y, char c); void video_smallchar(char x, char y, char c); void video_putsmalls(char x, char y, char *str); //NOTE that v1 to v8 and i must be in registers! register char v1 @4; register char v2 @5; register char v3 @6; register char v4 @7; register char v5 @8; register char v6 @9; register char v7 @10; register char v8 @11; register int i @12; #pragma regalloc+ char syncON, syncOFF; int LineCount; char screen[1600]; unsigned char bpush, pbDBState, dbCount, x, y, xpt, ypt, pHP, drawRoom, room, drawcount, stairX, stairY, stairRoom, newLevel, numMonsters, drawPlayer, monsterTurn, attack, moved; unsigned char t, n, j, gotHit, monAttack, damage, dead, hitnum, dlvl, plvl, maxHP, gainLVL, regenCount, start, finish, naming, beginGame, lett; unsigned int seed, xp, gold, tempscore; //player's initials as entered at the start of the game unsigned char pname[3]; //All the text used in the game char numTest[]="99"; char plevel[]="01"; char pgold[]="0000"; char pxp[]="0000"; char level[]="00"; char LV[]="LV?"; char HP[]="HP?12:12"; char curHP[]="12"; char totHP[]="12"; char expstr[]="EXP?"; char xplv[]="XPLV?"; char gld[]="GOLD?"; char off[]="OFF"; char the[]="THE"; char screen2[]="SCREEN"; char boom[]="BOOM"; char no[]="NO"; char please[]="PLEASE"; char enter[]="ENTER"; char your[]="YOUR"; char initials[]="INITIALS:"; char aaa[]="AAA"; char welcome[]="WELCOME"; char to[]="TO"; char dungeons[]="DUNGEONS"; char of[]="OF"; char doom[]="DOOM"; char game[]="GAME"; char over[]="OVER"; char high[]="HIGH"; char scores[]="SCORES"; //values of experience at which your player gains a level--ie level up from level 1 to 2 at 10exp, 2 to 3 at 20, etc //values follow fibbonacci sequence seeded with 10 and 20 flash unsigned int lvlUp[] = {10, 20, 30, 50, 80, 130, 210, 340, 550, 890, 1440, 2330, 3770, 6100, 9870}; //this code initializes the high score variables stored on the EEPROM eeprom unsigned int highScores[10] = {0,0,0,0,0,0,0,0,0,0}; eeprom unsigned char names[10][3]={ 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0}; //monster structure with all of the necessary characteristics; one per room typedef struct { unsigned char hp, nameVal, str, exp, xPos, yPos, xptm, yptm; } MONSTER; MONSTER mon[4]; //gold structure, one per room typedef struct { unsigned char gldX, gldY, xptg, yptg, gone; unsigned int value; } GOLDSTRUCT; GOLDSTRUCT bling[4]; //Point plot lookup table //One bit masks flash char pos[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; //player and staircase graphics flash char player2[3][5]={ //player 4x5 0b01010000, 0b11100000, 0b01000000, 0b10100000, 0b10010000, //staircase 0b00000000, 0b10000000, 0b11000000, 0b11100000, 0b11110000, //clear character 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}; //monster graphics flash char monsterBMP[4][5]={ //clear character 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b10010000, 0b01100000, 0b11110000, 0b01100000, 0b10010000, //monster 4x5 0b01000000, 0b01100000, 0b11110000, 0b01100000, 0b01100000, 0b00000000, 0b10100000, 0b01000000, 0b10100000, 0b00000000}; //================================ //3x5 font numbers, then letters //packed two per definition for fast //copy to the screen at x-position divisible by 4 flash char smallbitmap[39][5]={ //0 0b11101110, 0b10101010, 0b10101010, 0b10101010, 0b11101110, //1 0b01000100, 0b11001100, 0b01000100, 0b01000100, 0b11101110, //2 0b11101110, 0b00100010, 0b11101110, 0b10001000, 0b11101110, //3 0b11101110, 0b00100010, 0b11101110, 0b00100010, 0b11101110, //4 0b10101010, 0b10101010, 0b11101110, 0b00100010, 0b00100010, //5 0b11101110, 0b10001000, 0b11101110, 0b00100010, 0b11101110, //6 0b11001100, 0b10001000, 0b11101110, 0b10101010, 0b11101110, //7 0b11101110, 0b00100010, 0b01000100, 0b10001000, 0b10001000, //8 0b11101110, 0b10101010, 0b11101110, 0b10101010, 0b11101110, //9 0b11101110, 0b10101010, 0b11101110, 0b00100010, 0b01100110, //: 0b00000000, 0b01000100, 0b00000000, 0b01000100, 0b00000000, //= 0b00000000, 0b11101110, 0b00000000, 0b11101110, 0b00000000, //blank 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //A 0b11101110, 0b10101010, 0b11101110, 0b10101010, 0b10101010, //B 0b11001100, 0b10101010, 0b11101110, 0b10101010, 0b11001100, //C 0b11101110, 0b10001000, 0b10001000, 0b10001000, 0b11101110, //D 0b11001100, 0b10101010, 0b10101010, 0b10101010, 0b11001100, //E 0b11101110, 0b10001000, 0b11101110, 0b10001000, 0b11101110, //F 0b11101110, 0b10001000, 0b11101110, 0b10001000, 0b10001000, //G 0b11101110, 0b10001000, 0b10001000, 0b10101010, 0b11101110, //H 0b10101010, 0b10101010, 0b11101110, 0b10101010, 0b10101010, //I 0b11101110, 0b01000100, 0b01000100, 0b01000100, 0b11101110, //J 0b00100010, 0b00100010, 0b00100010, 0b10101010, 0b11101110, //K 0b10001000, 0b10101010, 0b11001100, 0b11001100, 0b10101010, //L 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b11101110, //M 0b10101010, 0b11101110, 0b11101110, 0b10101010, 0b10101010, //N 0b00000000, 0b11001100, 0b10101010, 0b10101010, 0b10101010, //O 0b01000100, 0b10101010, 0b10101010, 0b10101010, 0b01000100, //P 0b11101110, 0b10101010, 0b11101110, 0b10001000, 0b10001000, //Q 0b01000100, 0b10101010, 0b10101010, 0b11101110, 0b01100110, //R 0b11101110, 0b10101010, 0b11001100, 0b11101110, 0b10101010, //S 0b11101110, 0b10001000, 0b11101110, 0b00100010, 0b11101110, //T 0b11101110, 0b01000100, 0b01000100, 0b01000100, 0b01000100, //U 0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b11101110, //V 0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b01000100, //W 0b10101010, 0b10101010, 0b11101110, 0b11101110, 0b10101010, //X 0b00000000, 0b10101010, 0b01000100, 0b01000100, 0b10101010, //Y 0b10101010, 0b10101010, 0b01000100, 0b01000100, 0b01000100, //Z 0b11101110, 0b00100010, 0b01000100, 0b10001000, 0b11101110}; //================================== //This is the sync generator and raster generator. It MUST be entered from //sleep mode to get accurate timing of the sync pulses #pragma warn- interrupt [TIM1_COMPA] void t1_cmpA(void) { //start the Horizontal sync pulse PORTD = syncON; //update the curent scanline number LineCount ++; //increment the seed for the math random function seed++; //begin inverted (Vertical) synch after line 247 if (LineCount==248) begin syncON = 0b00100000; syncOFF = 0; end //back to regular sync after line 250 if (LineCount==251) begin syncON = 0; syncOFF = 0b00100000; end //start new frame after line 262 if (LineCount==263) begin LineCount = 1; end delay_us(2); //adjust to make 5 us pulses //end sync pulse PORTD = syncOFF; if (LineCount=ScreenTop) begin //compute byte index for beginning of the next line //left-shift 4 would be individual lines // <<3 means line-double the pixels //The 0xfff8 truncates the odd line bit //i=(LineCount-ScreenTop)<<3 & 0xfff8; // #asm push r16 lds r12, _LineCount lds r13, _Linecount+1 ldi r16, 30 sub r12, r16 ldi r16,0 sbc r13, r16 lsl r12 rol r13 lsl r12 rol r13 lsl r12 rol r13 mov r16,r12 andi r16,0xf0 mov r12,r16 pop r16 #endasm //load 16 registers with screen info #asm push r14 push r15 push r16 push r17 push r18 push r19 push r26 push r27 ldi r26,low(_screen) ;base address of screen ldi r27,high(_screen) add r26,r12 ;offset into screen (add i) adc r27,r13 ld r4,x+ ;load 16 registers and inc pointer ld r5,x+ ld r6,x+ ld r7,x+ ld r8,x+ ld r9,x+ ld r10,x+ ld r11,x+ ld r12,x+ ld r13,x+ ld r14,x+ ld r15,x+ ld r16,x+ ld r17,x+ ld r18,x+ ld r19,x pop r27 pop r26 #endasm delay_us(4); //adjust to center image on screen //blast 16 bytes to the screen #asm ;but first a macro to make the code shorter ;the macro takes a register number as a parameter ;and dumps its bits serially to portD.6 ;the nop can be eliminated to make the display narrower .macro videobits ;regnum BST @0,7 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,6 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,5 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,4 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,3 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,2 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,1 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,0 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 .endm videobits r4 ;video line -- byte 1 videobits r5 ;byte 2 videobits r6 ;byte 3 videobits r7 ;byte 4 videobits r8 ;byte 5 videobits r9 ;byte 6 videobits r10 ;byte 7 videobits r11 ;byte 8 videobits r12 ;byte 9 videobits r13 ;byte 10 videobits r14 ;byte 11 videobits r15 ;byte 12 videobits r16 ;byte 13 videobits r17 ;byte 14 videobits r18 ;byte 15 videobits r19 ;byte 16 clt ;clear video after the last pixel on the line IN R30,0x12 BLD R30,6 OUT 0x12,R30 pop r19 pop r18 pop r17 pop r16 pop r15 pop r14 #endasm end } #pragma warn+ //================ //Debounce the pushbuttons void pbDebounce(void) { bpush=(~PINA); switch(pbDBState) { case noPush: pbNP(); break; case maybePush: pbMP(); break; case push: pbPushed(); break; case maybeNoPush: pbMNP(); break; } } //================ //Debounce the pushbuttons during name entry void startDebounce(void) { bpush=(~PINA); switch(pbDBState) { case noPush: pbNPstart(); break; case maybePush: pbMPstart(); break; case push: pbPushedstart(); break; case maybeNoPush: pbMNPstart(); break; } } void pbNP(void) { if (bpush) pbDBState = maybePush; } void pbNPstart(void) { if (bpush) pbDBState = maybePush; } void pbMPstart(void) { if (bpush) { pbDBState=push; //keep the current letter (button C pushed) if (bpush & 0x40) { //keep letter, switch to next pname[n]=lett; video_smallchar((52+(n<<2)), 16, lett); n++; if (n==3) { //user has input his initials beginGame=1; } } //scroll down through alphabet else if (bpush & 0x08) //down { if (lett > 0) lett--; else lett=38; } //scroll up through alphabet else if (bpush & 0x02) //up { if (lett < 38) lett++; else lett=0; } } else pbDBState=noPush; } void pbPushedstart(void) { if (! bpush) { pbDBState=maybeNoPush; } } void pbMNPstart(void) { if (! bpush) pbDBState=noPush; else pbDBState=push; } void pbMP(void) { //lcd_clear(); if (bpush) { pbDBState=push; //process button push(es) //user goes down stairs if button C pushed while user on top of staircase if ((bpush & 0x40) && (x==stairX) && (y==stairY) && (room == stairRoom)) { video_putmonster(bling[room].xptg, bling[room].yptg, 0); drawRoom=1; dlvl++; //increment the dungeon level unless at level 99 if (level[1] == 57) { if (level[0] == 57) { finish=1; } else { level[1] = 48; level[0]++; } } else level[1]++; video_putsmalls(116,2, level); newLevel=1; } /********************************************** //code for rooms //if the user presses towards monster and monster is adjacent, user attacks //if user is next to door and presses towards door, user enters a new room //if user steps off of staircase, redraw it //if user takes a step or makes an attack, allow monster to take a turn //set "moved" flag to keep track of HP regeneration ***********************************************/ else if (room == 0) { if ((bpush & 0x80) && (x < 25)) //right (door) { if (x < 24) { //if the user presses towards monster and monster is adjacent, user attacks if ( (mon[room].hp > 0) && ((mon[room].xPos == x+1) && ((mon[room].yPos == y) || ((mon[room].yPos == y+1) && (bpush & 0x08)) || ((mon[room].yPos == y-1) && (bpush & 0x02)) ))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 0)video_putStair(1); x++; moved=1; monsterTurn=1; } } //go right thru door else if ((x==24)&&(y==8)) { video_putmonster(mon[room].xptm, mon[room].yptm, 0); video_putmonster(bling[room].xptg, bling[room].yptg, 0); room=1; drawRoom=1; x=0; } } if ((bpush & 0x20) && (x > 0)) //left { //if the user presses towards monster and monster is adjacent, user attacks if ( (mon[room].hp > 0) && ((mon[room].xPos == x-1) && ((mon[room].yPos == y) || ((mon[room].yPos == y+1) && (bpush & 0x08)) || ((mon[room].yPos == y-1) && (bpush & 0x02)) ))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 0)video_putStair(1); x--; moved=1; monsterTurn=1; } } if ((bpush & 0x08)) //down (door) { if (y<16) { //if the user presses towards monster and monster is adjacent, user attacks if ((mon[room].hp > 0) && ((mon[room].yPos == y+1) && (mon[room].xPos == x))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 0)video_putStair(1); y++; moved=1; monsterTurn=1; } } else if ((y==16)&&(x==13)) { video_putmonster(mon[room].xptm, mon[room].yptm, 0); video_putmonster(bling[room].xptg, bling[room].yptg, 0); room=2; drawRoom=1; y=0; //monsterTurn=1; } } if ((bpush & 0x02) && (y > 0)) //up { //if the user presses towards monster and monster is adjacent, user attacks if ((mon[room].hp > 0) && ((mon[room].yPos == y-1) && (mon[room].xPos == x))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 0)video_putStair(1); y--; moved=1; monsterTurn=1; } } //up } else if (room == 1) { if ((bpush & 0x80) && (x < 24)) { //if the user presses towards monster and monster is adjacent, user attacks if ( (mon[room].hp > 0) && ((mon[room].xPos == x+1) && ((mon[room].yPos == y) || ((mon[room].yPos == y+1) && (bpush & 0x08)) || ((mon[room].yPos == y-1) && (bpush & 0x02)) ))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 1)video_putStair(1); x++; moved=1; monsterTurn=1; } } //right if ((bpush & 0x20)) //left (door) { if (x > 0) { //if the user presses towards monster and monster is adjacent, user attacks if ( (mon[room].hp > 0) && ((mon[room].xPos == x-1) && ((mon[room].yPos == y) || ((mon[room].yPos == y+1) && (bpush & 0x08)) || ((mon[room].yPos == y-1) && (bpush & 0x02)) ))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 1)video_putStair(1); x--; moved=1; monsterTurn=1; } } else if ((x==0) && (y==8)) { video_putmonster(mon[room].xptm, mon[room].yptm, 0); video_putmonster(bling[room].xptg, bling[room].yptg, 0); room=0; drawRoom=1; x=24; //monsterTurn=1; } } if ((bpush & 0x08)) //down (door) { if (y<16) { //if the user presses towards monster and monster is adjacent, user attacks if ((mon[room].hp > 0) && ((mon[room].yPos == y+1) && (mon[room].xPos == x))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 1)video_putStair(1); y++; moved=1; monsterTurn=1; } } else if ((y==16)&&(x==13)) { video_putmonster(mon[room].xptm, mon[room].yptm, 0); video_putmonster(bling[room].xptg, bling[room].yptg, 0); room=3; drawRoom=1; y=0; //monsterTurn=1; } } if ((bpush & 0x02) && (y > 0)) { //if the user presses towards monster and monster is adjacent, user attacks if ((mon[room].hp > 0) && ((mon[room].yPos == y-1) && (mon[room].xPos == x))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 1)video_putStair(1); y--; moved=1; monsterTurn=1; } } //up } else if (room == 2) { if ((bpush & 0x80) && (x < 25)) //right (door) { if (x < 24) { //if the user presses towards monster and monster is adjacent, user attacks if ( (mon[room].hp > 0) && ((mon[room].xPos == x+1) && ((mon[room].yPos == y) || ((mon[room].yPos == y+1) && (bpush & 0x08)) || ((mon[room].yPos == y-1) && (bpush & 0x02)) ))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 2)video_putStair(1); x++; moved=1; monsterTurn=1; } } else if ((x==24)&&(y==8)) { video_putmonster(mon[room].xptm, mon[room].yptm, 0); video_putmonster(bling[room].xptg, bling[room].yptg, 0); room=3; drawRoom=1; x=0; //monsterTurn=1; } } if ((bpush & 0x20) && (x > 0)) { //if the user presses towards monster and monster is adjacent, user attacks if ( (mon[room].hp > 0) && ((mon[room].xPos == x-1) && ((mon[room].yPos == y) || ((mon[room].yPos == y+1) && (bpush & 0x08)) || ((mon[room].yPos == y-1) && (bpush & 0x02)) ))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 2)video_putStair(1); x--; moved=1; monsterTurn=1; } } //left if ((bpush & 0x08) && (y<16)) { //if the user presses towards monster and monster is adjacent, user attacks if ((mon[room].hp > 0) && ((mon[room].yPos == y+1) && (mon[room].xPos == x))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 2)video_putStair(1); y++; moved=1; monsterTurn=1; } } //down if (bpush & 0x02) //up (door) { if (y > 0) { //if the user presses towards monster and monster is adjacent, user attacks if ((mon[room].hp > 0) && ((mon[room].yPos == y-1) && (mon[room].xPos == x))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 2)video_putStair(1); y--; moved=1; monsterTurn=1; } } else if ((y==0) && (x==13)) { video_putmonster(mon[room].xptm, mon[room].yptm, 0); video_putmonster(bling[room].xptg, bling[room].yptg, 0); room=0; drawRoom=1; y=16; //monsterTurn=1; } } } else { if ((bpush & 0x80) && (x < 24)) { //if the user presses towards monster and monster is adjacent, user attacks if ( (mon[room].hp > 0) && ((mon[room].xPos == x+1) && ((mon[room].yPos == y) || ((mon[room].yPos == y+1) && (bpush & 0x08)) || ((mon[room].yPos == y-1) && (bpush & 0x02)) ))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 3)video_putStair(1); x++; moved=1; monsterTurn=1; } } if ((bpush & 0x20)) //left (door) { if (x > 0) { //if the user presses towards monster and monster is adjacent, user attacks if ( (mon[room].hp > 0) && ((mon[room].xPos == x-1) && ((mon[room].yPos == y) || ((mon[room].yPos == y+1) && (bpush & 0x08)) || ((mon[room].yPos == y-1) && (bpush & 0x02)) ))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 3)video_putStair(1); x--; moved=1; monsterTurn=1; } } else if ((x==0) && (y==8)) { video_putmonster(mon[room].xptm, mon[room].yptm, 0); video_putmonster(bling[room].xptg, bling[room].yptg, 0); room=2; drawRoom=1; x=24; //monsterTurn=1; } } if ((bpush & 0x08) && (y<16)) //down { //if the user presses towards monster and monster is adjacent, user attacks if ((mon[room].hp > 0) && ((mon[room].yPos == y+1) && (mon[room].xPos == x))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom== 3)video_putStair(1); y++; moved=1; monsterTurn=1; } } if (bpush & 0x02) //up (door) { if (y > 0) { //if the user presses towards monster and monster is adjacent, user attacks if ((mon[room].hp > 0) && ((mon[room].yPos == y-1) && (mon[room].xPos == x))) { attack = 1; } else { if ((stairX==x && stairY==y) && stairRoom==3)video_putStair(1); y--; moved=1; monsterTurn=1; } } else if ((y==0) && (x==13)) { video_putmonster(mon[room].xptm, mon[room].yptm, 0); video_putmonster(bling[room].xptg, bling[room].yptg, 0); room=1; drawRoom=1; y=16; } } } } else pbDBState=noPush; } void pbPushed(void) { if (! bpush) { pbDBState=maybeNoPush; } } void pbMNP(void) { if (! bpush) pbDBState=noPush; else pbDBState=push; } //======================================= //================================== //plot one point //at x,y with color 1=white 0=black 2=invert #pragma warn- void video_pt(char x, char y, char c) { #asm ; i=(x>>3) + ((int)y<<4) ; the byte with the pixel in it push r16 ldd r30,y+2 ;get x lsr r30 lsr r30 lsr r30 ;divide x by 8 ldd r12,y+1 ;get y lsl r12 ;mult y by 16 clr r13 lsl r12 rol r13 lsl r12 rol r13 lsl r12 rol r13 add r12, r30 ;add in x/8 ;v2 = screen[i]; r5 ;v3 = pos[x & 7]; r6 ;v4 = c r7 ldi r30,low(_screen) ldi r31,high(_screen) add r30, r12 adc r31, r13 ld r5,Z ;get screen byte ldd r26,y+2 ;get x ldi r27,0 andi r26,0x07 ;form x & 7 ldi r30,low(_pos*2) ldi r31,high(_pos*2) add r30,r26 adc r31,r27 lpm r6,Z ld r16,y ;get c ;if (v4==1) screen[i] = v2 | v3 ; ;if (v4==0) screen[i] = v2 & ~v3; ;if (v4==2) screen[i] = v2 ^ v3 ; cpi r16,1 brne tst0 or r5,r6 tst0: cpi r16,0 brne tst2 com r6 and r5,r6 tst2: cpi r16,2 brne writescrn eor r5,r6 writescrn: ldi r30,low(_screen) ldi r31,high(_screen) add r30, r12 adc r31, r13 st Z, r5 ;write the byte back to the screen pop r16 #endasm } #pragma warn+ //================================== // plot a player graphic or stairs // x and y are coordinates of upper left hand corner of graphic void video_putplayer(char x, char y, char c) { v7 = x; for (v6=0;v6<5;v6++) begin v1 = player2[c][v6]; v8 = y+v6; video_pt(v7, v8, (v1 & 0x80)==0x80); video_pt(v7+1, v8, (v1 & 0x40)==0x40); video_pt(v7+2, v8, (v1 & 0x20)==0x20); video_pt(v7+3, v8, (v1 & 0x10)==0x10); end } //================================== // plot a monster graphic // x and y are coordinates of upper left hand corner of graphic void video_putmonster(char x, char y, char c) { v7 = x; for (v6=0;v6<5;v6++) begin v1 = monsterBMP[c][v6]; v8 = y+v6; video_pt(v7, v8, (v1 & 0x80)==0x80); video_pt(v7+1, v8, (v1 & 0x40)==0x40); video_pt(v7+2, v8, (v1 & 0x20)==0x20); video_pt(v7+3, v8, (v1 & 0x10)==0x10); end } //Draw a staircase //1 is stairs, 2 is clear void video_putStair(char x) { video_putplayer((char)((stairX<<2)+1), (char)((stairY<<2)+1+stairY), x); } //================================== // put a small character on the screen // x-cood must be on divisible by 4 // c is index into bitmap void video_smallchar(char x, char y, char c){ char mask; i=((int)x>>3) + ((int)y<<4) ; if (x == (x & 0xf8)) mask = 0x0f; //f8 else mask = 0xf0; screen[i] = (screen[i] & mask) | (smallbitmap[c][0] & ~mask); screen[i+16] = (screen[i+16] & mask) | (smallbitmap[c][1] & ~mask); screen[i+32] = (screen[i+32] & mask) | (smallbitmap[c][2] & ~mask); screen[i+48] = (screen[i+48] & mask) | (smallbitmap[c][3] & ~mask); screen[i+64] = (screen[i+64] & mask) | (smallbitmap[c][4] & ~mask); } //================================== // put a string of small characters on the screen // x-cood must be on divisible by 4 void video_putsmalls(char x, char y, char *str) { char i ; for (i=0; str[i]!=0; i++) begin if (str[i]>=0x30 && str[i]<=0x3a) video_smallchar(x,y,str[i]-0x30); else video_smallchar(x,y,str[i]-0x40+12); x = x+4; end } //================================== //plot a line //at x1,y1 to x2,y2 with color 1=white 0=black 2=invert //NOTE: this function requires signed chars //Code is from David Rodgers, //"Procedural Elements of Computer Graphics",1985 void video_line(char x1, char y1, char x2, char y2, char c) { int e; signed char dx,dy,j, temp; signed char s1,s2, xchange; signed char x,y; x = x1; y = y1; dx = cabs(x2-x1); dy = cabs(y2-y1); s1 = csign(x2-x1); s2 = csign(y2-y1); xchange = 0; if (dy>dx) begin temp = dx; dx = dy; dy = temp; xchange = 1; end e = ((int)dy<<1) - dx; for (j=0; j<=dx; j++) begin video_pt(x,y,c) ; if (e>=0) begin if (xchange==1) x = x + s1; else y = y + s2; e = e - ((int)dx<<1); end if (xchange==1) y = y + s2; else x = x + s1; e = e + ((int)dy<<1); end } //================================== // set up the ports and timers void main(void) { dbCount = 0; //counter for debouncing PBs pbDBState = noPush; //begin debounce in non-pushed state //initialze flags, counters, XP, gold, HP, etc. drawcount=0; drawRoom=0; hitnum=0; dlvl=1; gotHit=0; monAttack=0; newLevel=0; attack=0; maxHP=12; pHP=12; xp=0; gold=0; regenCount=0; gainLVL=0; start = 1; finish = 0; plvl=1; level[1]++; seed=80; srand(seed); //random number 0 to N-1 //while (N <= (result = rand() / (RAND_MAX/N))); stairX=10; stairY=10; stairRoom=3; /****************************** Monster Generation Code ******************************/ for (n=0; n<4; n++) { mon[n].xPos=12; mon[n].yPos=12; //start out with monsters in rooms 1-3 if (n==0) mon[n].hp=0; else mon[n].hp=6; mon[n].exp=1; mon[n].xptm=(mon[n].xPos << 2) + 1; mon[n].yptm=(mon[n].yPos << 2) + 1 + mon[n].yPos; } //gold generation for (n=0; n<4; n++) { //these will always be the same on level 1 because rand function seeded the same while (24 <= (bling[n].gldX = rand() / (RAND_MAX/24))); while (16 <= (bling[n].gldY = rand() / (RAND_MAX/16))); t=10 * dlvl; while (t <= (bling[n].value = rand() / (RAND_MAX/t))); bling[n].value++; bling[n].gone=0; bling[n].xptg=(bling[n].gldX << 2) + 1; bling[n].yptg=(bling[n].gldY << 2) + 1 + bling[n].gldY; } //init timer 1 to generate sync OCR1A = lineTime; //One NTSC line TCCR1B = 9; //full speed; clear-on-match TCCR1A = 0x00; //turn off pwm and oc lines TIMSK = 0x10; //enable interrupt T1 cmp //init ports DDRA = 0x00; //genesis controller DDRD = 0xf0; //video out //D.5 is sync:1000 ohm + diode to 75 ohm resistor //D.6 is video:330 ohm + diode to 75 ohm resistor //initialize sync constants LineCount = 1; syncON = 0b00000000; syncOFF = 0b00100000; //side lines video_line(0,0,0,99,1); video_line(width,0,width,99,1); //top line & bottom lines video_line(0,0,width,0,1); video_line(0,99,width,99,1); //user's starting position x=10; y=14; //coordinate conversion. Should have used a macro. xpt = (char)((x << 2)+1); //convert x & y coordinates to bigger square ypt = (char)((y << 2)+1+y); //enable sleep mode MCUCR = 0b10000000; #asm ("sei"); //The following loop executes once/video line during lines //1-230, then does all of the frame-end processing while(1) { //stall here until next line starts //sleep enable; mode=idle //use sleep to make entry into sync ISR uniform time #asm ("sleep"); //The following code executes during the vertical blanking //Code here can be as long as //a total of 60 lines x 63.5 uSec/line x 8 cycles/uSec if (LineCount==231) { /************************************************************ / Here a flag system is used to determine which block of code / should execute on a given screen refresh. Additionally, a / counter (drawcount) is used to split computation between a number / of frames. This is particularly important when drawing a / lot and when accessing the EEPROM. If these computations / are not split and more commands are executed than can be / finished during the footer graphic signal, the sync gets / messed up and the system resets. *************************************************************/ /************************************************************ /************* Flags used and explaination **************** / start-set at startup and turned off after user enters initials / finish-when user dies or reaches level 99 this flag is turned on / monAttack-set when the monster decides to attack during its turn / attack-set when the user attacks the monster / newLevel-set when user enters the next dungeon level / drawRoom-set when user enters a new room / monsterTurn-set after user moves or attacks ************************************************************/ if (start) { if (beginGame) { if (drawcount==5) { for (n=0; n<27; n++) { video_smallchar(8+(n<<2), 10, 12); } for (n=0; n<3; n++) { video_smallchar(52+(n<<2), 16, 12); } drawcount++; } else if (drawcount==6) { //print a welcome message then pause video_putsmalls(8, 10, welcome); for(n=0; n<3; n++) { video_smallchar((40+(n<<2)), 10, pname[n]); } video_putsmalls(56, 10, to); video_putsmalls(68, 10, the); video_putsmalls(84, 10, dungeons); video_smallchar(116,10, 12); video_putsmalls(52, 16, of); video_putsmalls(64, 16, doom); drawcount++; } else if (drawcount==179) { //clear the screen for (n=0; n<27; n++) { video_smallchar(8+(n<<2), 10, 12); } for (n=0; n<7; n++) { video_smallchar(52+(n<<2), 16, 12); } drawcount++; } //initialize the game screen else if (drawcount==180) { t=0; n=0; pbDBState = noPush; video_putmonster(bling[room].xptg, bling[room].yptg, 3); //south wall video_line(0,89,52,89,1); video_line(58,89,101,89,1); //east wall video_line(101, 0, 101, 40, 1); video_line(101, 46, 101, 89, 1); video_putsmalls(12, 92, HP); video_putsmalls(104, 2, LV); video_putsmalls(104, 8, expstr); video_putsmalls(108, 14, pxp); video_putsmalls(104, 20, xplv); video_putsmalls(116, 26, plevel); video_putsmalls(104, 32, gld); video_putsmalls(108, 38, pgold); video_putsmalls(116, 2, level); if (stairRoom==0) video_putStair(1); start=0; drawcount = 0; } else drawcount++; } else { if (drawcount==0) { //start up the initial entry mode video_putsmalls(8, 10, please); video_putsmalls(36, 10, enter); video_putsmalls(60, 10, your); video_putsmalls(80, 10, initials); video_putsmalls(52, 16, aaa); n=0; t=0; lett=13; drawcount++; } else if (drawcount == 1) { drawcount++; } else if (drawcount ==2) { drawcount++; } else if (drawcount ==3) { //wait for user to move into the next mode } if (dbCount == 0x01) { startDebounce(); //genesis controller debounce code dbCount=0; } else { dbCount++; } //flash the letter user is currently choosing if (t==30 && n<3) { t=0; video_smallchar((52+(n<<2)), 16, lett); } else t++; if (t==15 && n<3) { video_smallchar((52+(n<<2)), 16, 12); //blank char } } } else if (finish) { //game is over, clear the screen if (drawcount ==0) { video_putmonster(bling[room].xptg, bling[room].yptg, 0); video_putmonster(mon[room].xptm, mon[room].yptm, 0); video_putStair(2); drawcount++; } else if (drawcount == 1) { //clear screen for (n=0; n<7; n++) { for (t=0; t<5; t++) { video_smallchar(104+(t<<2), 2+(6*n), 12); } } drawcount++; } else if (drawcount ==2) { for (n=0; n<8; n++) { video_smallchar(12+(n<<2),92, 12); //clear HP } drawcount++; } else if (drawcount ==3) { //more clearing //south wall video_line(1,89,101,89,0); //east wall video_line(101, 1, 101, 89, 0); drawcount++; } else if (drawcount == 4) { //more clearing //west and north walls video_line(0,0,0,99,1); video_line(0,0,width,0,1); drawcount++; } else if (drawcount == 5) { //more clearing and print "game over" video_putplayer(xpt, ypt, 2); //erase old player video_putsmalls(40, 10, game); video_putsmalls(60, 10, over); drawcount++; } /************************** HIGH SCORE CODE - scan through high score list to find where current score belongs - shift everything below in high score list down one element - populate correct location with current score - pause with "game over" screen - print out high score list **************************/ else if (drawcount == 6) { n=0; while ((gold > highScores[n]) && n <10) { n++; } drawcount++; } else if (drawcount == 7) { if (n > 0) { //now shift bottom half of array for (t=1; t0) { for (j=0; j<3; j++) { video_smallchar(40+(j<<2),16+((9-n)*6),names[n][j]); } pgold[0] = ((tempscore / 1000) % 10)+ 48; pgold[1] = ((tempscore / 100) % 10) + 48; pgold[2] = ((tempscore / 10) % 10) + 48; pgold[3] = (tempscore % 10) + 48; video_putsmalls(68, 16+((9-n)*6), pgold); } n--; drawcount++; } else if (drawcount == 203) { //n==8 tempscore=highScores[n]; if (tempscore>0) { for (j=0; j<3; j++) { video_smallchar(40+(j<<2),16+((9-n)*6),names[n][j]); } pgold[0] = ((tempscore / 1000) % 10)+ 48; pgold[1] = ((tempscore / 100) % 10) + 48; pgold[2] = ((tempscore / 10) % 10) + 48; pgold[3] = (tempscore % 10) + 48; video_putsmalls(68, 16+((9-n)*6), pgold); } n--; drawcount++; } else if (drawcount == 204) { //n==7 tempscore=highScores[n]; if (tempscore>0) { for (j=0; j<3; j++) { video_smallchar(40+(j<<2),16+((9-n)*6),names[n][j]); } pgold[0] = ((tempscore / 1000) % 10)+ 48; pgold[1] = ((tempscore / 100) % 10) + 48; pgold[2] = ((tempscore / 10) % 10) + 48; pgold[3] = (tempscore % 10) + 48; video_putsmalls(68, 16+((9-n)*6), pgold); } n--; drawcount++; } else if (drawcount == 205) { //n==6 tempscore=highScores[n]; if (tempscore>0) { for (j=0; j<3; j++) { video_smallchar(40+(j<<2),16+((9-n)*6),names[n][j]); } pgold[0] = ((tempscore / 1000) % 10)+ 48; pgold[1] = ((tempscore / 100) % 10) + 48; pgold[2] = ((tempscore / 10) % 10) + 48; pgold[3] = (tempscore % 10) + 48; video_putsmalls(68, 16+((9-n)*6), pgold); } n--; drawcount++; } else if (drawcount == 206) { //n==5 tempscore=highScores[n]; if (tempscore>0) { for (j=0; j<3; j++) { video_smallchar(40+(j<<2),16+((9-n)*6),names[n][j]); } pgold[0] = ((tempscore / 1000) % 10)+ 48; pgold[1] = ((tempscore / 100) % 10) + 48; pgold[2] = ((tempscore / 10) % 10) + 48; pgold[3] = (tempscore % 10) + 48; video_putsmalls(68, 16+((9-n)*6), pgold); } n--; drawcount++; } else if (drawcount == 207) { //n==4 tempscore=highScores[n]; if (tempscore>0) { for (j=0; j<3; j++) { video_smallchar(40+(j<<2),16+((9-n)*6),names[n][j]); } pgold[0] = ((tempscore / 1000) % 10)+ 48; pgold[1] = ((tempscore / 100) % 10) + 48; pgold[2] = ((tempscore / 10) % 10) + 48; pgold[3] = (tempscore % 10) + 48; video_putsmalls(68, 16+((9-n)*6), pgold); } n--; drawcount++; } else if (drawcount == 208) { //n==3 tempscore=highScores[n]; if (tempscore>0) { for (j=0; j<3; j++) { video_smallchar(40+(j<<2),16+((9-n)*6),names[n][j]); } pgold[0] = ((tempscore / 1000) % 10)+ 48; pgold[1] = ((tempscore / 100) % 10) + 48; pgold[2] = ((tempscore / 10) % 10) + 48; pgold[3] = (tempscore % 10) + 48; video_putsmalls(68, 16+((9-n)*6), pgold); } n--; drawcount++; } else if (drawcount == 209) { //n==2 tempscore=highScores[n]; if (tempscore>0) { for (j=0; j<3; j++) { video_smallchar(40+(j<<2),16+((9-n)*6),names[n][j]); } pgold[0] = ((tempscore / 1000) % 10)+ 48; pgold[1] = ((tempscore / 100) % 10) + 48; pgold[2] = ((tempscore / 10) % 10) + 48; pgold[3] = (tempscore % 10) + 48; video_putsmalls(68, 16+((9-n)*6), pgold); } n--; drawcount++; } else if (drawcount == 210) { //n==1 tempscore=highScores[n]; if (tempscore>0) { for (j=0; j<3; j++) { video_smallchar(40+(j<<2),16+((9-n)*6),names[n][j]); } pgold[0] = ((tempscore / 1000) % 10)+ 48; pgold[1] = ((tempscore / 100) % 10) + 48; pgold[2] = ((tempscore / 10) % 10) + 48; pgold[3] = (tempscore % 10) + 48; video_putsmalls(68, 16+((9-n)*6), pgold); } n--; drawcount++; } else if (drawcount == 211) { //n==0 tempscore=highScores[n]; if (tempscore>0) { for (j=0; j<3; j++) { video_smallchar(40+(j<<2),16+((9-n)*6),names[n][j]); } pgold[0] = ((tempscore / 1000) % 10)+ 48; pgold[1] = ((tempscore / 100) % 10) + 48; pgold[2] = ((tempscore / 10) % 10) + 48; pgold[3] = (tempscore % 10) + 48; video_putsmalls(68, 16+((9-n)*6), pgold); } n--; drawcount++; } else { } } else { video_putplayer(xpt, ypt, 2); //erase old player if (monAttack) { if (drawcount==0) { //generate some random number to see if you get hit while (40 <= (hitnum = rand() / (RAND_MAX/40))); //25 percent chance of getting hit when on dungeon level 1, 75% chance when on lvl 20 if (dlvl+10 > hitnum) { gotHit=1; //video_putsmalls(116,2, numTest); } drawcount++; } else if (drawcount==1) { if (gotHit) { //damage done to player is 1-4 for every four levels of dungeon //lvl 1 -> 1-4 damage. Level 20, 6-24 damage. n=(dlvl / 4) + 1; for(t=0; t= (20/plvl)) { //increase HP by 1, display them and reset rc pHP++; curHP[0] = (pHP / 10) + 48; curHP[1] = (pHP % 10) + 48; video_putsmalls(24, 92, curHP); regenCount = 0; } } moved=0; } else if (newLevel) { //gen monsters, stair position, etc if (drawcount==0) { srand(seed); while (25 <= (stairX = rand() / (RAND_MAX/25))); while (17 <= (stairY = rand() / (RAND_MAX/17))); while (4 <= (stairRoom = rand() / (RAND_MAX/4))); drawcount++; } else if (drawcount==1) { //draw stairs if they're in the same room on the new level if ((stairRoom == room) && !((stairX == x) && (stairY == y))) video_putStair(1); //erase the monster video_putmonster(mon[room].xptm, mon[room].yptm, 0); drawcount++; } //This code generates new monsters for the next level //monster hitpoints are (1 to 8)*2^(dungeon level / 6) else if (drawcount==2) { n=0; while (23 <= (mon[n].xPos = rand() / (RAND_MAX/23))); while (15 <= (mon[n].yPos = rand() / (RAND_MAX/15))); mon[n].xPos++; mon[n].yPos++; while (8 <= (mon[n].hp = rand() / (RAND_MAX/8))); mon[n].hp++; mon[n].hp << (dlvl / 6); mon[n].exp = dlvl; mon[n].xptm=(mon[n].xPos << 2) + 1; mon[n].yptm=(mon[n].yPos << 2) + 1 + mon[n].yPos; n++; drawcount++; } else if (drawcount==3) { while (23 <= (mon[n].xPos = rand() / (RAND_MAX/23))); while (15 <= (mon[n].yPos = rand() / (RAND_MAX/15))); mon[n].xPos++; mon[n].yPos++; while (8 <= (mon[n].hp = rand() / (RAND_MAX/8))); mon[n].hp++; mon[n].hp << (dlvl / 6); mon[n].exp = dlvl; mon[n].xptm=(mon[n].xPos << 2) + 1; mon[n].yptm=(mon[n].yPos << 2) + 1 + mon[n].yPos; n++; drawcount++; } else if (drawcount==4) { while (23 <= (mon[n].xPos = rand() / (RAND_MAX/23))); while (15 <= (mon[n].yPos = rand() / (RAND_MAX/15))); mon[n].xPos++; mon[n].yPos++; while (8 <= (mon[n].hp = rand() / (RAND_MAX/8))); mon[n].hp++; mon[n].hp << (dlvl / 6); mon[n].exp = dlvl; mon[n].xptm=(mon[n].xPos << 2) + 1; mon[n].yptm=(mon[n].yPos << 2) + 1 + mon[n].yPos; n++; drawcount++; } else if (drawcount==5) { while (23 <= (mon[n].xPos = rand() / (RAND_MAX/23))); while (15 <= (mon[n].yPos = rand() / (RAND_MAX/15))); mon[n].xPos++; mon[n].yPos++; while (8 <= (mon[n].hp = rand() / (RAND_MAX/8))); mon[n].hp++; mon[n].hp << (dlvl / 6); mon[n].exp = dlvl; mon[n].xptm=(mon[n].xPos << 2) + 1; mon[n].yptm=(mon[n].yPos << 2) + 1 + mon[n].yPos; drawcount++; } else if (drawcount == 6) { //generate locations for the gold t=10 * dlvl; for (n=0; n<4; n++) { while (24 <= (bling[n].gldX = rand() / (RAND_MAX/24))); while (16 <= (bling[n].gldY = rand() / (RAND_MAX/16))); } drawcount++; } else if (drawcount == 7) { //generate values for the gold from 1 to (10*dungeon level) for (n=0; n<4; n++) { while (t <= (bling[n].value = rand() / (RAND_MAX/t))); bling[n].value++; bling[n].gone=0; bling[n].xptg=(bling[n].gldX << 2) + 1; bling[n].yptg=(bling[n].gldY << 2) + 1 + bling[n].gldY; } drawcount ++; } else { drawcount=0; newLevel=0; attack=0; monsterTurn=0; } } //player attacks monster else if (attack) { //lvlUp[] = {10, 20, 30, 50, 80, 130, 210, 340, 550, 890, 1440, 2330, 3770, 6100, 9870}; if (drawcount==0) { //random numbers for damage and to see if the player hits the monster while (50 <= (drawcount = rand() / (RAND_MAX/50))); while (4 <= (damage = rand() / (RAND_MAX/4))); damage ++; //always a 50% chance of hitting monster //always 1-4 HP damage to monster if (drawcount > 25) { if (damage < mon[room].hp) { mon[room].hp -= damage; } else { mon[room].hp = 0; } } drawcount=1; } else if (drawcount == 1) { //clear monster and gain experience if it dies if (mon[room].hp == 0) { video_putmonster(mon[room].xptm, mon[room].yptm, 0); xp+=mon[room].exp; pxp[0] = ((xp / 1000)%10) + 48; pxp[1] = ((xp / 100)%10) + 48; pxp[2] = ((xp / 10)%10) + 48; pxp[3] = (xp % 10) + 48; video_putsmalls(108, 14, pxp); } else { //monster gets a turn if not dead monsterTurn = 1; } drawcount++; } else if (drawcount == 2) { if (mon[room].hp ==0) { //check for levelup gainLVL=0; n=plvl-1; while ((n < 15) && (xp >= lvlUp[n])) { //gain level(s) and 1 to 10 HP max and current for each levelup while (10 <= (t = rand() / (RAND_MAX/10))); t++; if ((maxHP+=t) > 99) maxHP = 99; if ((pHP+=t) > 99) pHP = 99; plvl++; n++; gainLVL=1; } } drawcount++; } else { if (gainLVL) { //update the xplv display and hp curHP[0] = (pHP / 10) + 48; curHP[1] = (pHP % 10) + 48; video_putsmalls(24, 92, curHP); totHP[0] = (maxHP / 10) + 48; totHP[1] = (maxHP % 10) + 48; video_putsmalls(36, 92, totHP); plevel[0] = (plvl / 10) + 48; plevel[1] = (plvl % 10) + 48; video_putsmalls(116, 26, plevel); } attack =0; drawcount = 0; } } //After you move, the monster gets a turn to move, attack, etc else if (monsterTurn) { //you've stepped on some gold if ((x == bling[room].gldX) && (y == bling[room].gldY) && (bling[room].gone == 0)) { bling[room].gone = 1; //increase player gold and display gold+=bling[room].value; if (gold > 9999) gold=9999; pgold[0] = ((gold / 1000) % 10)+ 48; pgold[1] = ((gold / 100) % 10) + 48; pgold[2] = ((gold / 10) % 10) + 48; pgold[3] = (gold % 10) + 48; video_putsmalls(108, 38, pgold); } //check to see if monster is alive first //erase monster if (mon[room].hp > 0) { //erase the monster video_putmonster(mon[room].xptm, mon[room].yptm, 0); //if the player is next to the monster, the monster attacks if (((mon[room].xPos + 1 == x) && ((mon[room].yPos + 1 == y) || (mon[room].yPos - 1 == y) || (mon[room].yPos == y))) || ((mon[room].xPos - 1 == x) && ((mon[room].yPos + 1 == y) || (mon[room].yPos - 1 == y) || (mon[room].yPos == y))) || ((mon[room].xPos == x) && ((mon[room].yPos + 1 == y) || (mon[room].yPos - 1 == y)))) { monAttack = 1; } else { //monster will step off stairs, so redraw them if ((mon[room].xPos == stairX) && (mon[room].yPos == stairY) && (room==stairRoom)) video_putStair(1); if ((mon[room].xPos == bling[room].gldX) && (mon[room].yPos == bling[room].gldY) && (bling[room].gone == 0)) video_putmonster(mon[room].xptm, mon[room].yptm, 3); //Monster moves if ((mon[room].xPos + 1 < x) || ((mon[room].xPos + 1 == x) && (mon[room].yPos + 1 < y)) || ((mon[room].xPos + 1 == x) && (mon[room].yPos - 1 > y))) { mon[room].xPos++; } else if ((mon[room].xPos != 0) && ((mon[room].xPos - 1 > x) || ((mon[room].xPos - 1 == x) && (mon[room].yPos + 1 < y)) || ((mon[room].xPos - 1 == x) && (mon[room].yPos - 1 > y)))) { mon[room].xPos--; } if ((mon[room].yPos + 1 < y) || ((mon[room].yPos + 1 == y) && (mon[room].xPos + 1 <= x)) || ((mon[room].yPos + 1 == y) && (mon[room].xPos - 1 >= x))) { mon[room].yPos++; } else if ((mon[room].yPos != 0) && ((mon[room].yPos - 1 > y) || ((mon[room].yPos - 1 == y) && (mon[room].xPos + 1 <= x)) || ((mon[room].yPos - 1 == y) && (mon[room].xPos - 1 >= x)))) { mon[room].yPos--; } } //convert x and y coordinates to actual pixels moved mon[room].xptm=(mon[room].xPos << 2) + 1; mon[room].yptm=(mon[room].yPos << 2) + 1 + mon[room].yPos; //draw monster video_putmonster(mon[room].xptm, mon[room].yptm, 1); } monsterTurn=0; drawcount=0; } //drawing upon entering a new room else if (drawRoom) { //draw gold if it hasn't been picked up already if (bling[room].gone == 0) { video_putmonster(bling[room].xptg, bling[room].yptg, 3); } //draw a monster if it's not dead if (mon[room].hp > 0) { video_putmonster(mon[room].xptm, mon[room].yptm, 1); } if (room==0) { if (drawcount==0) { //west wall video_line(0,0,0,99,1); if (stairRoom==0) video_putStair(1); else (video_putStair(2)); drawcount++; } else if (drawcount == 1) { //north wall video_line(0,0,width,0,1); drawcount++; } else if (drawcount ==2) { //south wall video_line(0,89,101,89,0); video_line(0,89,52,89,1); video_line(58,89,101,89,1); drawcount++; } else if (drawcount ==3) { //east wall video_line(101, 0, 101, 89, 0); video_line(101, 0, 101, 40, 1); video_line(101, 46, 101, 89, 1); drawcount = 0; drawRoom = 0; } } else if (room==1) { if (drawcount==0) { //west wall video_line(0,0,0,99,0); video_line(0,0,0,40,1); video_line(0,46,0,99,1); drawcount++; } else if (drawcount == 1) { //north wall video_line(0,0,width,0,1); if (stairRoom==1) video_putStair(1); else (video_putStair(2)); drawcount++; } else if (drawcount ==2) { //south wall video_line(0,89,101,89,0); video_line(0,89,52,89,1); video_line(58,89,101,89,1); drawcount++; } else if (drawcount ==3) { //east wall video_line(101, 0, 101, 89, 1); drawcount = 0; drawRoom = 0; } } else if (room==2) { if (drawcount==0) { //west wall video_line(0,0,0,99,0); video_line(0,0,0,99,1); if (stairRoom==2) video_putStair(1); else (video_putStair(2)); drawcount++; } else if (drawcount==1) { //north wall video_line(0,0,width,0,0); video_line(0,0,52,0,1); video_line(58,0,width,0,1); drawcount++; } else if (drawcount==2) { //south wall video_line(0,89,101,89,0); video_line(0,89,101,89,1); drawcount++; } else if (drawcount==3) { //east wall video_line(101,0,101,89,0); video_line(101,0,101,40,1); video_line(101,46,101,89,1); drawcount = 0; drawRoom = 0; } } else { if (drawcount==0) { //west wall video_line(0,0,0,99,0); video_line(0,0,0,40,1); video_line(0,46,0,99,1); drawcount++; } else if (drawcount == 1) { //north wall video_line(0,0,width,0,0); video_line(0,0,52,0,1); video_line(58,0,width,0,1); drawcount++; } else if (drawcount ==2) { //south wall video_line(0,89,101,89,1); if (stairRoom==3) video_putStair(1); else (video_putStair(2)); drawcount++; } else if (drawcount ==3) { //east wall video_line(101, 0, 101, 89, 1); drawcount = 0; drawRoom = 0; } } } //OR, debounce the controller (again)! else { dbCount = dbCount ^ 0x01; if (dbCount == 0x01) { pbDebounce(); //genesis controller debounce code xpt = (char)((x << 2)+1); //convert x & y coordinates to bigger square ypt = (char)((y << 2)+1+y); } } video_putplayer(xpt, ypt, 0); //draw new player } //main code } //line 231 } //while } //main