It is currently Sat Oct 21, 2017 6:14 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 108 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8  Next
Author Message
 Post subject:
PostPosted: Sat Oct 29, 2005 12:21 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7233
Location: Chexbres, VD, Switzerland
Then you really don't have to cry when someone redirect you to 6502 opcode list or something.
bcc/bcs does branch in function of the carry, but rol/ror can also get it's value into an other value and that's VERY usefull.
After a AND instruction, the carry won't be affected, so it will stay what it was before. To set the carry to a know state, just use sec/clc.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 29, 2005 3:02 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
Yeah, I just realized what's wrong! It never increases the high byte of the map data! Okay, I'm thinking of how I can do this. I have an idea but I don't know how to say it. I wish there was something like "BWA" which is Branch on Wrap Around. That would be SO MUCH EASIER. When something wraps around, is the carry flag affected at all? What flag is affected at a wrap around? I could probably use this to say to increase the high byte! I have to do some thinking...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 29, 2005 3:53 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10066
Location: Rio de Janeiro - Brazil
Quote:
I wish there was something like "BWA" which is Branch on Wrap Around. That would be SO MUCH EASIER. When something wraps around, is the carry flag affected at all? What flag is affected at a wrap around? I could probably use this to say to increase the high byte!


That's the exact idea. If you're using INC or DEC you can detect wrapping around by checking the Z flag. $FF + 1 = $00 (Z flag set). If you're using ADC you can just use the carry flag. If it is set, the number wraped around. There is no need for a "BWA". BEQ or BCS (depending on how you're incrementing the number) will work just fine.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 29, 2005 6:06 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
Quote:
There is no need for a "BWA". BEQ or BCS (depending on how you're incrementing the number) will work just fine.


Put another way, BWA already exists, just as BLT (signed branch if less than) and BGE (signed branch if greater than or equal); they're just spelled differently in an assembler (BEQ/BCS, BCC, and BCS).


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 29, 2005 6:11 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
There's something wrong here, at the end of my reset routine, I did a clc, and then there was my endless loop. Okay, then I went to FCEUXD ultra's debugger, and the carry flag wasn't set, so I went, okay, and I decided to do a test. I changed every clc to an sec, and guess what, the carry flag was never set, according to fceuxd ultra's debugger! why!? I DON'T KNOW! that's really stupid! and if I deleted the clc at the end of the routine, and changed all secs to clc, it would always be set! WHAT'S THE DEAL!? This is causing alot of problems! WHY DOES THIS HAPPEN!? Thank you for helping me you guys, I really appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 29, 2005 6:53 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1389
Every time you perform an addition/subtraction or bit-shift instruction (ADC/ SBC/CMP/CPX/CPY, ASL/LSR/ROL/ROR), the carry flag will be modified. ADC/SBC/ROL/ROR use carry as an input AND and output, while CMP/CPX/CPY/ASL/LSR use it only as an output.

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 30, 2005 12:57 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7233
Location: Chexbres, VD, Switzerland
Just doing clc at the end of the reset routine is totally stupid, scince your indefinite loop won't use the carry.
Use clc/sec before an addition/substaction or while exiting of a routine using carry flag as a parameter, when you know that his state won't be modified between the setup of the carry flag and the use of it.
See what I mean :
Code:
lda Number1
clc
adc Number2
sta Number1 ;PROPRELY add two values

will work fine.
Versus :
Code:
clc
lda Blahbla
sta blahblah
and blahblah
eor blahblah ;Lots of instruction that doesn't affect the carry flag, so it will remain clear
ora blahblah
sta blahblah
tay
lda Blahblah,Y
adc Number2  ;The carry flag... should be clear here
sta Number1

But then, if you modify the code between clc and adc, you may add something modifing the carry flag, and then your adc will go wrong and randomly add 1 more, and you will be angry because you won't found the error.
In some case, like after an ASL where you know that the bit 7 was clear, or typically after a BCS, you can skip the clc before the addition, because you are sure that it's clear, but beware ! If you change your code, you have to don't forget to reconsider that optimization.
The code you posted several topics above looks fine for pointer maths, so I really can't say what's wrong.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 13, 2005 12:30 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
Okay, I swear that %$#@^%#% carry flag hates me! Okay, this is the funniest thing. If I did a clc right before a bcc, the carry flag would still be set! HA! how do you explain that one? I mean, you could explain it like, since that's going on in your NMI routine, their could be something wrong in your endless loop which is traveling at speeds much faster than the NMI. BUT! there's just jmp endlessloop in my endless loop. WELL! I've at least found a temporary way around it! HA! It works! Not something you want to use for big games, though: Here it is:
Code:
         .bank 0
         .org $8000
.incbin "maze.nam"
        ...
        lda #HIGH(bg1)
        sta turd1
        ...
collision1:
   lda #LOW(bg1)
   sta turd
   lda cx
   lsr a
   lsr a
   lsr a
   sta tilex
   lda cy
   lsr a
   lsr a
   lsr a
   sta tiley
   lda tiley
   asl a
   asl a
   asl a
   asl a
   asl a
   sta vara
   clc
   lda tilex
   adc vara
   sta varb
   clc   
   lda turd
   adc varb
   sta turd
   jsr increase
   
noinc11:
   ldy #$00
   lda [turd],y
   bpl nocoll
   lda #01
   sta colflag
   clc
   rts

nocoll:
   lda #$00
   sta colflag
   rts

increase:
   lda tiley
   cmp #$00
   beq store80
   cmp #$08
   beq store81
   cmp #$10
   beq store82
   cmp #$18
   beq store83
   rts

store81:
   lda #$81
   sta turd1
   rts

store82:
   lda #$82
   sta turd1
   rts

store83:
   lda #$83
   sta turd1
   rts

store80:
   lda #$80
   sta turd1
   rts


Yeah, I won't want to store direct values into turd1. But for a one screen/one level game, it will work fine. I need to study the carry flag some more. I swear, the carry flag does nothing I tell it to. Well, it does, but I don't remember ever telling it to do things that it does!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 11:17 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7233
Location: Chexbres, VD, Switzerland
Celius wrote:
Okay, I swear that %$#@^%#% carry flag hates me! Okay, this is the funniest thing. If I did a clc right before a bcc, the carry flag would still be set! HA! how do you explain that one?


clc clears the carry flag, you probably have trouble assembling your code if that doesn't even work.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 12:26 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
Optimization suggestion for 'increase' routine:
Code:
increase:
   lda tiley
   and #$E7   ; if any bit besides $10 or $08 is on
   bne :+     ; skip over
              ; here, we know tiley is $00, $08, $10, or $18, no other value
   lda tiley
   lsr A
   lsr A
   lsr A     ; $00 becomes $00, $08->$01, $10->$02, $18->$03
   ora #$80  ; add #$80 to the deal
   sta turd1
:  rts


If you already know tiley is already either $00, $08, $10, or $18, you can skip over the first 3 instructions. This avoids a big ugly CMP/BEQ chain and shrinks the size of the routine. As well as elimanates the need for those ugly storexx blocks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 3:27 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
I never would have thought of that. It's completely logical though! Okay, I need to use "and" and "ora" and "eor" way more often. I hardly ever use them, and that's not good at all. I'll make those modifications. Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 7:47 pm 
Hmm, my BKG Graphics Test does simple collision. The player moves in 8-pixel increments. Whenever the player tries to move, the game checks first if the tile they're trying to go to is blocked (i.e. he can't go there) and if it is then the player won't move. But you're probably trying something more complicatted, so I'll back out. :)


Top
  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 5:55 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10066
Location: Rio de Janeiro - Brazil
Well, collision with 8 pixel increments can be very simple, but also very ugly. If you're learning about collision, that is the way to start. But no commercial games use it, that I'm aware of. Unless the colision is tile based, but the movement is animated, resulting in smooth animation with no extra complexity. That was often used with RPG's, and loks nice, but is worthless for a platformer.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 10:26 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7233
Location: Chexbres, VD, Switzerland
Thexeder use that, but the games truly suck.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 12:33 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10066
Location: Rio de Janeiro - Brazil
Bregalad wrote:
Thexeder use that, but the games truly suck.

Platformer? If yes it must really suck. I don't think I ever saw a commercial platformer working like this. Maybe on reeeeeally limited systems, way more limited than the NES, but even so...

There would be no acceleration at all... and jumping would absolutelly suck.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 108 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: russellsprouts and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group