RHillFake Posted September 10, 2014 Share Posted September 10, 2014 In my code, I have if score=0 then goto P1WINS, and earlier the score is equal to 3000 and subtracts by 1 in the main loop. When I start the game, instead of waiting for the score to equal zero, it starts off at the P1WINS unless I remove the if score=0 then goto P1WINS code. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted September 10, 2014 Share Posted September 10, 2014 Could you post the source? Quote Link to comment Share on other sites More sharing options...
bogax Posted September 10, 2014 Share Posted September 10, 2014 In my code, I have if score=0 then goto P1WINS, and earlier the score is equal to 3000 and subtracts by 1 in the main loop. When I start the game, instead of waiting for the score to equal zero, it starts off at the P1WINS unless I remove the if score=0 then goto P1WINS code. Thanks for the help. score is not a normal variable. it's a three byte 6 digit decimal (normal variables are one byte binary) you'll probably have to do something like this dim score1 = score + 1 dim score2 = score + 2 temp1 = (score | score1) | score2 if !temp1 then x=x and yes, do post your code when you ask a question about it Quote Link to comment Share on other sites More sharing options...
RHillFake Posted September 12, 2014 Author Share Posted September 12, 2014 Could you post the source? do post your code when you ask a question about it set tv ntsc set optimization noinlinedata dim lives_compact = 1 dim p0_orientation = c dim p1_orientation = z score=1000 intro01 playfield: ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ end z=0 gosub P0 gosub P1 player0height = 6 player1height = 6 intro01loop COLUBK = $08 COLUPF = $0E COLUP0 = $44 COLUP1 = $64 player0x=25 :player0y=50 player1x=125:player1y=50 if z>19 && switchselect then goto intro02 if joy0fire || joy1fire then goto GAMEPLAY drawscreen z=z+1 goto intro01loop intro02 playfield: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ...............................X ...............................X ........X..............X.......X X.......X..............X.......X X.......X..............X.......X X.......X..............X.......X X.......X..............X........ X............................... X............................... XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end z=0 gosub P0 gosub P1 player0height = 6 player1height = 6 intro02loop COLUBK = $08 COLUPF = $0E COLUP0 = $44 COLUP1 = $64 player0x=25 :player0y=50 player1x=125:player1y=50 if z>9 && switchselect then goto intro01 if joy0fire || joy1fire then goto GAMEPLAY drawscreen z=z+1 goto intro02loop GAMEPLAY gosub P0 gosub P1 player0height = 6 p0_orientation = 0 player1height = 6 p1_orientation = 0 lifecolor=$64 lives=192 main lives: %00000000 %11111111 %11111111 %11111111 %11111111 %11111111 %11111111 %00000000 end if switchreset then reboot COLUP0 = $44 COLUP1 = $64 drawscreen score=score-1 if score<1 then goto P2WINS goto main P2WINS z=0 player1: %00111100 %01000010 %10000001 %10000001 %10000001 %10000001 %01000010 %00111100 end player0: %10000001 %01000010 %00100100 %00011000 %00011000 %00100100 %01000010 %10000001 end P2WINSLOOP drawscreen COLUP0 = $44 COLUP1 = $64 z=z+1 if z>20 && switchreset then reboot goto P2WINSLOOP P0 player0: %0000000 %1111100 %1111100 %0111000 %0111000 %0010000 %0010000 %0000100 %0011100 %1111100 %0111100 %0011100 %0001100 %0000100 %0001000 %0011000 %0111100 %1111100 %0111100 %0001110 %0000010 %0000000 %1100000 %1111000 %1111110 %1111000 %1100000 %0000000 %0000000 %1111111 %0111110 %0111100 %0011000 %0010000 %0000000 %0000011 %0011110 %1111110 %0111100 %0011000 %0001000 %0000000 %0001000 %0001000 %0011100 %0011100 %0111110 %0111110 %0000000 %0100000 %0110000 %0111000 %0111100 %0111110 %0111000 %0100000 %1000000 %1110000 %0111000 %0111110 %0111100 %0011000 %0010000 %0000000 %0000110 %0011110 %1111110 %0011110 %0000110 %0000000 %0010000 %0011000 %0111100 %0111110 %0111100 %1110000 %1000000 %0100000 %0111000 %0111110 %0111100 %0111000 %0110000 %0100000 end return P1 player1: %0000000 %1111100 %1111100 %0111000 %0111000 %0010000 %0010000 %0000100 %0011100 %1111100 %0111100 %0011100 %0001100 %0000100 %0001000 %0011000 %0111100 %1111100 %0111100 %0001110 %0000010 %0000000 %1100000 %1111000 %1111110 %1111000 %1100000 %0000000 %0000000 %1111111 %0111110 %0111100 %0011000 %0010000 %0000000 %0000011 %0011110 %1111110 %0111100 %0011000 %0001000 %0000000 %0001000 %0001000 %0011100 %0011100 %0111110 %0111110 %0000000 %0100000 %0110000 %0111000 %0111100 %0111110 %0111000 %0100000 %1000000 %1110000 %0111000 %0111110 %0111100 %0011000 %0010000 %0000000 %0000110 %0011110 %1111110 %0011110 %0000110 %0000000 %0010000 %0011000 %0111100 %0111110 %0111100 %1110000 %1000000 %0100000 %0111000 %0111110 %0111100 %0111000 %0110000 %0100000 end return inline 6lives.asm Quote Link to comment Share on other sites More sharing options...
RHillFake Posted September 15, 2014 Author Share Posted September 15, 2014 score is not a normal variable. it's a three byte 6 digit decimal (normal variables are one byte binary) you'll probably have to do something like this dim score1 = score + 1 dim score2 = score + 2 temp1 = (score | score1) | score2 if !temp1 then x=x Can someone please help me fit this into my code and explain what it means? I have never worked with temps before. Thanks P.S. I had no idea there was a spiderman emoticon Quote Link to comment Share on other sites More sharing options...
bogax Posted September 15, 2014 Share Posted September 15, 2014 (edited) That's a somewhat involved question. Processor uses 8 bit bytes and does things in binary. You could sort of think of it as similar to how people deal with "normal" (base ten, 0..9) numbers a digit at a time. 8 bits gives you 256 possibilities so it's kinda like the computer uses digits that are 0..256. but you can think of that byte as two hexadecimal, base 16 digits ie like it was two digits that are 0..15 People are used to dealing with base ten so the processor has the abilitiy to treat bytes as decimal for addition and subtraction So instead of treating a byte as two base 16 digits it can treat a byte as two decimal digits. All that to say you get two decimal digits per byte. The score has six digits so it uses three bytes But bB only treats them as a single six digit decimal number for addition with the score An if-then statement does the normal processor/bB thing with bytes So your if then statement with score only uses the first two (least significant) digits of score, ie the first byte (besides the score is in BCD, Binary Coded Decimal and bB let's you use decimal for other stuff but it's actually binary which can mess you up. 10 in BCD is 16 in binary so set the score to 10 and compare to 15 and score>15 is true) You could do an if then on each of the score bytes but since you're testing for 0 there's a simpler faster way. bB is happy with if a | b then but it doesn't like if a | b | c then a | b is a bitwise ORing of a and b "or" ("|") is 0 | 0 = 0 0 | 1 = 1 1 | 0 = 1 1 | 1 = 1 so 1 | (don't care) = 1 a | b does that for corresponding bits in the the bytes and puts the corresponding result bit in to the corresponding bit of the result byte bit0 | bit0 to bit0 of the result like wise for bits 1, 2, .. 7 so if any bit of a, b, c is 1 ie if any of a, b, c is not 0 Then the result of a | b | c will not be zero but if they are all zero the result will be zero. Since you need somewhere to put the result untill you can test it, but only untill you can test it, you use a temp variable. That's what the temp variables are for (well, they're for stuff that the kernel needs a temp variable for but you can use them too since they're only used by the kernel during drawscreen) (bB also uses them for eg passing values to or in function or for doing math or stuff) (except for temp 7 there are 7 temp variables temp1 .. temp6 are used by the kernel during drawscreen temp7 is used for bankswitching) dim score1 = score + 1 is just to give a name to the second byte of the score that you can use in bB. Score is actually a constant that is the location in memory of the variable score. dim score1 = score + 1 just names the next following location in memory score1 And I probaly confused you by using if !temp1 then x=x x=x is just a placeholder because you need something after the then. what you would want is if !temp1 then P2WINS if you give an if statement a single value it will treat it like if value <> 0 then ie a non zero value is true the ! prefix inverts that so if !temp1 then is like if temp1 = 0 then but it's faster and uses less code (less ROM) if the if-then statement is close enough to your target (P2WINS in this case) you don't need the goto and that's also faster and uses less code since P2WINS is right after the if-then statement, what you should actually do is temp1 = score | score1 | score2 if temp1 then main but you may have to add the goto to the if-then if you add more stuff between the if-then and main edit: something I forgot (parenthesis) temp1 = (score | score1) | score2 if temp1 then main If it doesn't have the parenthesis bB will stash score on the stack and compute score1 | score2 first. Edited September 15, 2014 by bogax Quote Link to comment Share on other sites More sharing options...
+cvga Posted September 16, 2014 Share Posted September 16, 2014 Thank you for posting that ^^^^. i think it will help me debug an issue I had with some code I had written awhile back also. Quote Link to comment Share on other sites More sharing options...
RHillFake Posted September 16, 2014 Author Share Posted September 16, 2014 That's a somewhat involved question. Processor uses 8 bit bytes and does things in binary. You could sort of think of it as similar to how people deal with "normal" (base ten, 0..9) numbers a digit at a time. 8 bits gives you 256 possibilities so it's kinda like the computer uses digits that are 0..256. but you can think of that byte as two hexadecimal, base 16 digits ie like it was two digits that are 0..15 People are used to dealing with base ten so the processor has the abilitiy to treat bytes as decimal for addition and subtraction So instead of treating a byte as two base 16 digits it can treat a byte as two decimal digits. All that to say you get two decimal digits per byte. The score has six digits so it uses three bytes But bB only treats them as a single six digit decimal number for addition with the score An if-then statement does the normal processor/bB thing with bytes So your if then statement with score only uses the first two (least significant) digits of score, ie the first byte (besides the score is in BCD, Binary Coded Decimal and bB let's you use decimal for other stuff but it's actually binary which can mess you up. 10 in BCD is 16 in binary so set the score to 10 and compare to 15 and score>15 is true) You could do an if then on each of the score bytes but since you're testing for 0 there's a simpler faster way. bB is happy with if a | b then but it doesn't like if a | b | c then a | b is a bitwise ORing of a and b "or" ("|") is 0 | 0 = 0 0 | 1 = 1 1 | 0 = 1 1 | 1 = 1 so 1 | (don't care) = 1 a | b does that for corresponding bits in the the bytes and puts the corresponding result bit in to the corresponding bit of the result byte bit0 | bit0 to bit0 of the result like wise for bits 1, 2, .. 7 so if any bit of a, b, c is 1 ie if any of a, b, c is not 0 Then the result of a | b | c will not be zero but if they are all zero the result will be zero. Since you need somewhere to put the result untill you can test it, but only untill you can test it, you use a temp variable. That's what the temp variables are for (well, they're for stuff that the kernel needs a temp variable for but you can use them too since they're only used by the kernel during drawscreen) (bB also uses them for eg passing values to or in function or for doing math or stuff) (except for temp 7 there are 7 temp variables temp1 .. temp6 are used by the kernel during drawscreen temp7 is used for bankswitching) dim score1 = score + 1 is just to give a name to the second byte of the score that you can use in bB. Score is actually a constant that is the location in memory of the variable score. dim score1 = score + 1 just names the next following location in memory score1 And I probaly confused you by using if !temp1 then x=x x=x is just a placeholder because you need something after the then. what you would want is if !temp1 then P2WINS if you give an if statement a single value it will treat it like if value <> 0 then ie a non zero value is true the ! prefix inverts that so if !temp1 then is like if temp1 = 0 then but it's faster and uses less code (less ROM) if the if-then statement is close enough to your target (P2WINS in this case) you don't need the goto and that's also faster and uses less code since P2WINS is right after the if-then statement, what you should actually do is temp1 = score | score1 | score2 if temp1 then main but you may have to add the goto to the if-then if you add more stuff between the if-then and main edit: something I forgot (parenthesis) temp1 = (score | score1) | score2 if temp1 then main If it doesn't have the parenthesis bB will stash score on the stack and compute score1 | score2 first. I still have no idea how to get this working in the code. Thanks for trying to explain. I am not very good at programming. Could you put it in the code I gave for an example? Quote Link to comment Share on other sites More sharing options...
bogax Posted September 16, 2014 Share Posted September 16, 2014 I still have no idea how to get this working in the code. Thanks for trying to explain. I am not very good at programming. Could you put it in the code I gave for an example? set tv ntsc set optimization noinlinedata dim lives_compact = 1 dim p0_orientation = c dim p1_orientation = z dim score1 = score + 1 dim score2 = score + 2 score=1000 intro01 playfield: ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ end z=0 gosub P0 gosub P1 player0height = 6 player1height = 6 intro01loop COLUBK = $08 COLUPF = $0E COLUP0 = $44 COLUP1 = $64 player0x=25 :player0y=50 player1x=125:player1y=50 if z>19 && switchselect then goto intro02 if joy0fire || joy1fire then goto GAMEPLAY drawscreen z=z+1 goto intro01loop intro02 playfield: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ...............................X ...............................X ........X..............X.......X X.......X..............X.......X X.......X..............X.......X X.......X..............X.......X X.......X..............X........ X............................... X............................... XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end z=0 gosub P0 gosub P1 player0height = 6 player1height = 6 intro02loop COLUBK = $08 COLUPF = $0E COLUP0 = $44 COLUP1 = $64 player0x=25 :player0y=50 player1x=125:player1y=50 if z>9 && switchselect then goto intro01 if joy0fire || joy1fire then goto GAMEPLAY drawscreen z=z+1 goto intro02loop GAMEPLAY gosub P0 gosub P1 player0height = 6 p0_orientation = 0 player1height = 6 p1_orientation = 0 lifecolor=$64 lives=192 main lives: %00000000 %11111111 %11111111 %11111111 %11111111 %11111111 %11111111 %00000000 end if switchreset then reboot COLUP0 = $44 COLUP1 = $64 drawscreen score=score-1 temp1 = (score | score1) | score2 if temp1 then main P2WINS z=0 player1: %00111100 %01000010 %10000001 %10000001 %10000001 %10000001 %01000010 %00111100 end player0: %10000001 %01000010 %00100100 %00011000 %00011000 %00100100 %01000010 %10000001 end P2WINSLOOP drawscreen COLUP0 = $44 COLUP1 = $64 z=z+1 if z>20 && switchreset then reboot goto P2WINSLOOP P0 player0: %0000000 %1111100 %1111100 %0111000 %0111000 %0010000 %0010000 %0000100 %0011100 %1111100 %0111100 %0011100 %0001100 %0000100 %0001000 %0011000 %0111100 %1111100 %0111100 %0001110 %0000010 %0000000 %1100000 %1111000 %1111110 %1111000 %1100000 %0000000 %0000000 %1111111 %0111110 %0111100 %0011000 %0010000 %0000000 %0000011 %0011110 %1111110 %0111100 %0011000 %0001000 %0000000 %0001000 %0001000 %0011100 %0011100 %0111110 %0111110 %0000000 %0100000 %0110000 %0111000 %0111100 %0111110 %0111000 %0100000 %1000000 %1110000 %0111000 %0111110 %0111100 %0011000 %0010000 %0000000 %0000110 %0011110 %1111110 %0011110 %0000110 %0000000 %0010000 %0011000 %0111100 %0111110 %0111100 %1110000 %1000000 %0100000 %0111000 %0111110 %0111100 %0111000 %0110000 %0100000 end return P1 player1: %0000000 %1111100 %1111100 %0111000 %0111000 %0010000 %0010000 %0000100 %0011100 %1111100 %0111100 %0011100 %0001100 %0000100 %0001000 %0011000 %0111100 %1111100 %0111100 %0001110 %0000010 %0000000 %1100000 %1111000 %1111110 %1111000 %1100000 %0000000 %0000000 %1111111 %0111110 %0111100 %0011000 %0010000 %0000000 %0000011 %0011110 %1111110 %0111100 %0011000 %0001000 %0000000 %0001000 %0001000 %0011100 %0011100 %0111110 %0111110 %0000000 %0100000 %0110000 %0111000 %0111100 %0111110 %0111000 %0100000 %1000000 %1110000 %0111000 %0111110 %0111100 %0011000 %0010000 %0000000 %0000110 %0011110 %1111110 %0011110 %0000110 %0000000 %0010000 %0011000 %0111100 %0111110 %0111100 %1110000 %1000000 %0100000 %0111000 %0111110 %0111100 %0111000 %0110000 %0100000 end return inline 6lives.asm 1 Quote Link to comment Share on other sites More sharing options...
RHillFake Posted September 16, 2014 Author Share Posted September 16, 2014 set tv ntsc set optimization noinlinedata dim lives_compact = 1 dim p0_orientation = c dim p1_orientation = z dim score1 = score + 1 dim score2 = score + 2 score=1000 intro01 playfield: ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ end z=0 gosub P0 gosub P1 player0height = 6 player1height = 6 intro01loop COLUBK = $08 COLUPF = $0E COLUP0 = $44 COLUP1 = $64 player0x=25 :player0y=50 player1x=125:player1y=50 if z>19 && switchselect then goto intro02 if joy0fire || joy1fire then goto GAMEPLAY drawscreen z=z+1 goto intro01loop intro02 playfield: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ...............................X ...............................X ........X..............X.......X X.......X..............X.......X X.......X..............X.......X X.......X..............X.......X X.......X..............X........ X............................... X............................... XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end z=0 gosub P0 gosub P1 player0height = 6 player1height = 6 intro02loop COLUBK = $08 COLUPF = $0E COLUP0 = $44 COLUP1 = $64 player0x=25 :player0y=50 player1x=125:player1y=50 if z>9 && switchselect then goto intro01 if joy0fire || joy1fire then goto GAMEPLAY drawscreen z=z+1 goto intro02loop GAMEPLAY gosub P0 gosub P1 player0height = 6 p0_orientation = 0 player1height = 6 p1_orientation = 0 lifecolor=$64 lives=192 main lives: %00000000 %11111111 %11111111 %11111111 %11111111 %11111111 %11111111 %00000000 end if switchreset then reboot COLUP0 = $44 COLUP1 = $64 drawscreen score=score-1 temp1 = (score | score1) | score2 if temp1 then main P2WINS z=0 player1: %00111100 %01000010 %10000001 %10000001 %10000001 %10000001 %01000010 %00111100 end player0: %10000001 %01000010 %00100100 %00011000 %00011000 %00100100 %01000010 %10000001 end P2WINSLOOP drawscreen COLUP0 = $44 COLUP1 = $64 z=z+1 if z>20 && switchreset then reboot goto P2WINSLOOP P0 player0: %0000000 %1111100 %1111100 %0111000 %0111000 %0010000 %0010000 %0000100 %0011100 %1111100 %0111100 %0011100 %0001100 %0000100 %0001000 %0011000 %0111100 %1111100 %0111100 %0001110 %0000010 %0000000 %1100000 %1111000 %1111110 %1111000 %1100000 %0000000 %0000000 %1111111 %0111110 %0111100 %0011000 %0010000 %0000000 %0000011 %0011110 %1111110 %0111100 %0011000 %0001000 %0000000 %0001000 %0001000 %0011100 %0011100 %0111110 %0111110 %0000000 %0100000 %0110000 %0111000 %0111100 %0111110 %0111000 %0100000 %1000000 %1110000 %0111000 %0111110 %0111100 %0011000 %0010000 %0000000 %0000110 %0011110 %1111110 %0011110 %0000110 %0000000 %0010000 %0011000 %0111100 %0111110 %0111100 %1110000 %1000000 %0100000 %0111000 %0111110 %0111100 %0111000 %0110000 %0100000 end return P1 player1: %0000000 %1111100 %1111100 %0111000 %0111000 %0010000 %0010000 %0000100 %0011100 %1111100 %0111100 %0011100 %0001100 %0000100 %0001000 %0011000 %0111100 %1111100 %0111100 %0001110 %0000010 %0000000 %1100000 %1111000 %1111110 %1111000 %1100000 %0000000 %0000000 %1111111 %0111110 %0111100 %0011000 %0010000 %0000000 %0000011 %0011110 %1111110 %0111100 %0011000 %0001000 %0000000 %0001000 %0001000 %0011100 %0011100 %0111110 %0111110 %0000000 %0100000 %0110000 %0111000 %0111100 %0111110 %0111000 %0100000 %1000000 %1110000 %0111000 %0111110 %0111100 %0011000 %0010000 %0000000 %0000110 %0011110 %1111110 %0011110 %0000110 %0000000 %0010000 %0011000 %0111100 %0111110 %0111100 %1110000 %1000000 %0100000 %0111000 %0111110 %0111100 %0111000 %0110000 %0100000 end return inline 6lives.asm Thanks for all the help (sprite tables, gravity, this). I have no idea what I was doing wrong when inserting this into the code :\ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.