Author [EN] [PL] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [ID] Topic: Theou Aegis' Rookie Guide To 6502 ASM Reading  (Read 18559 times)

0 Members and 1 Guest are viewing this topic.

Offline Omegasigma

  • Director
  • Legendary Hunter
  • ****
  • Posts: 834
  • Gender: Male
  • Awards One-Time Show: Not quite a lurker, but posts infrequently and in only few areas.
    • Awards
  • Favorite Game: DraculaX: Rondo of Blood (PC-Engine)
  • Likes:
Re: Theou Aegis' Rookie Guide To 6502 ASM Reading
« Reply #45 on: October 25, 2012, 07:36:06 PM »
0
im glad ive stuck to 3D programming >.> 2D looks scary on a console
Currently Involved in: Vampire blood Chronicals, Project Goldeneye

Offline TheouAegis

  • Amateur Auteur of GMvania
  • Master Hunter
  • *****
  • Posts: 1860
  • Gender: Male
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. The Great Defender will always defend the object of his or her fandom. Hack Master makes creations out of CV parts. (S)he makes Dr. Frankenstein proud.
    • GMvania Developer's Blog
    • Awards
  • Likes:
Re: Theou Aegis' Rookie Guide To 6502 ASM Reading
« Reply #46 on: October 25, 2012, 08:25:24 PM »
0
I had a derp moment just now.

Here's an easier way to convert NES hex-fractions to normal fractions: If the rate of acceleration only occupies the upper nybble (e.g., $10, $40, $80, $C0), just take that upper nybble and divide it by 16. There's your fraction. So the following:

CLC
LDA horz_1
ADC horz_2 @ horz_2=$40
STA horz_1
LDA x
ADC horz_3 @ horz_3=$01
STA x

That's basically saying hspeed=1+4/16
$01 + ($40>>4) / 16

I feel sheepish. Baah.

For when the lower nybble is set as well...

$14 = ((1*16)+4) / 256

But it's just as easy to use hex and tell base 10 to piss off.
« Last Edit: October 25, 2012, 08:34:13 PM by TheouAegis »
Your mom has had more floppies put in her than a Commodore 64!


Follow my lack of progress on my game at my blog:
http://gmvania.blogspot.com

Offline TheouAegis

  • Amateur Auteur of GMvania
  • Master Hunter
  • *****
  • Posts: 1860
  • Gender: Male
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. The Great Defender will always defend the object of his or her fandom. Hack Master makes creations out of CV parts. (S)he makes Dr. Frankenstein proud.
    • GMvania Developer's Blog
    • Awards
  • Likes:
Re: Theou Aegis' Rookie Guide To 6502 ASM Reading
« Reply #47 on: November 17, 2012, 07:57:21 PM »
0
Couldn't remember which topic I was posting this crap in, so I'll post here to bump my thread.  :-X

So I was transcribing the code for the water splashes fishmen and frogs made in CV3. I'm guessing the same code is probably used for the rubble from a broken wall. Well, as it turns out, Konami's programmers made another typo there as well.

To recapitulate, CV3 has four main variables pertaining to movement: the $04F2,X range pertaining to the integral horizontal speed, the $0509,X range pertaining to the fractional horizontal speed, the $0520,X range pertaining to the integral vertical speed, and the $0537,X range pertaining to the fractional vertical speed. Objects will frequently clear these out and then set them when needed. Sometimes all four are set even if they're not actually set to anything just because NES programmers frequently used simple data structures and it's often worth the extra cycles to save ROM space.

The code for the water splashes (and like I said, maybe the wall rubble as I haven't analyzed that yet) doesn't set $0509,X! Instead, where you would expect to see $0509,X you instead see $0537,X! How do I know that's a typo? Three lines down, $0537,X is set again to a different value! What's more, when $0537,X gets set and the index for the data structure is 7, the value gets set to #$81! That's a nonsense value never used for movement values!


I'm probably the only person on these forums that actually cares and perhaps some people are even getting annoyed with my finds, but I don't care. This is my thread and it pertains to Castlevania modding, so it's fucking relevant.  ;D
Your mom has had more floppies put in her than a Commodore 64!


Follow my lack of progress on my game at my blog:
http://gmvania.blogspot.com

Offline Inccubus

  • Wannabe Great Old One
  • Master Hunter
  • *****
  • Posts: 3279
  • Gender: Male
  • Warrior
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. SuperOld Dungeonite: Members who have been around since the oldOLD days. Permanent Resident: Seems to always be around to post/reply.
    • Awards
  • Favorite Game: Vampire Killer (MSX)
  • Likes:
Re: Theou Aegis' Rookie Guide To 6502 ASM Reading
« Reply #48 on: November 19, 2012, 11:09:31 AM »
0
Couldn't remember which topic I was posting this crap in, so I'll post here to bump my thread.  :-X

So I was transcribing the code for the water splashes fishmen and frogs made in CV3. I'm guessing the same code is probably used for the rubble from a broken wall. Well, as it turns out, Konami's programmers made another typo there as well.

To recapitulate, CV3 has four main variables pertaining to movement: the $04F2,X range pertaining to the integral horizontal speed, the $0509,X range pertaining to the fractional horizontal speed, the $0520,X range pertaining to the integral vertical speed, and the $0537,X range pertaining to the fractional vertical speed. Objects will frequently clear these out and then set them when needed. Sometimes all four are set even if they're not actually set to anything just because NES programmers frequently used simple data structures and it's often worth the extra cycles to save ROM space.

The code for the water splashes (and like I said, maybe the wall rubble as I haven't analyzed that yet) doesn't set $0509,X! Instead, where you would expect to see $0509,X you instead see $0537,X! How do I know that's a typo? Three lines down, $0537,X is set again to a different value! What's more, when $0537,X gets set and the index for the data structure is 7, the value gets set to #$81! That's a nonsense value never used for movement values!


I'm probably the only person on these forums that actually cares and perhaps some people are even getting annoyed with my finds, but I don't care. This is my thread and it pertains to Castlevania modding, so it's fucking relevant.  ;D

I love these things. Every time you find a bug like that I add it to my list of things to add to my title screen hack.
"Stuff and things."

Offline TheouAegis

  • Amateur Auteur of GMvania
  • Master Hunter
  • *****
  • Posts: 1860
  • Gender: Male
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. The Great Defender will always defend the object of his or her fandom. Hack Master makes creations out of CV parts. (S)he makes Dr. Frankenstein proud.
    • GMvania Developer's Blog
    • Awards
  • Likes:
Re: Theou Aegis' Rookie Guide To 6502 ASM Reading
« Reply #49 on: November 20, 2012, 08:22:20 AM »
0
Speaking of hacking, I just realized the big-grin smiley here is the same one used by Ed in Cowboy Bebop.
Your mom has had more floppies put in her than a Commodore 64!


Follow my lack of progress on my game at my blog:
http://gmvania.blogspot.com

Offline Inccubus

  • Wannabe Great Old One
  • Master Hunter
  • *****
  • Posts: 3279
  • Gender: Male
  • Warrior
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. SuperOld Dungeonite: Members who have been around since the oldOLD days. Permanent Resident: Seems to always be around to post/reply.
    • Awards
  • Favorite Game: Vampire Killer (MSX)
  • Likes:
Re: Theou Aegis' Rookie Guide To 6502 ASM Reading
« Reply #50 on: November 20, 2012, 06:55:13 PM »
0
Ah, Ed. I imagine that my my own daughter will be just like Ed some day when I get around to that.
"Stuff and things."

Offline TheouAegis

  • Amateur Auteur of GMvania
  • Master Hunter
  • *****
  • Posts: 1860
  • Gender: Male
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. The Great Defender will always defend the object of his or her fandom. Hack Master makes creations out of CV parts. (S)he makes Dr. Frankenstein proud.
    • GMvania Developer's Blog
    • Awards
  • Likes:
Re: Theou Aegis' Rookie Guide To 6502 ASM Reading
« Reply #51 on: May 26, 2013, 11:31:15 PM »
0
Ah, the threads of our pasts return to haunt us!

This post actually has less to do with 6502 ASM and more to do with just understanding one of the binary functions that has been boggling me ever since I started studying NES coding. I never took the time to actually try to understand the purpose of bitwise rotations (ROL and ROR). A bitwise shift is easy enough to understand: shift the bits left and you multiply the value by a power of 2; shift the bits right and you divide the value by a power of 2; shift four times and you move nybbles around. But what is the point of a bitwise rotation and why is such a function not included in Game Maker?

Over time I've come to realize the difference between 8-bit and 16-bit programming. There isn't much of one: some actions take twice as long in 8-bit than in 16-bit because numbers larger than 255 take up more bits than can be handled in a single call. While working with CV3's code, I noticed certain values seemed to essentially be 16-bit values. For example, RAM offsets $0053 and $0054 are the coordinates of the left edge of the view in the room with the upper byte written last; in other words, although it appears in the RAM as $53$54, it is meant to be read as $54$53. A combined value of $82$01 can thus be interpreted as $0182. Yes, I just wrote two 8-bit values as one 16-bit value. By the way, that number would translate to the left edge of the view is at x:386, which would mean Trevor was at x:514 in the room.

A problem arises when working with 16-bit values in an 8-bit environment, namely how to manipulate both bytes at the same time. Consider a bitwise shift to the left. You can't simply shift both bytes equally:

Intended 16-bit LSR:
$0182 << 4 = $1820
False 8-bit LSR:
[$01$82] << 4 = $10$20

How do we get $18$20 from $01$82? The answer is with a rotation. Bitwise shifts on 8-bit and 16-bit hardware set the carry bit of the status byte depending on if the bit that gets dropped during a shift was set or not. Here's a refresher on how bitwise shifts work:

In a logical shift to the right (LSR), the lowest bit is dropped. The highest bit will be void and gets filled in with a 0. Thus 1001>>1 creates X100 (1); X is replaced with 0 and (1) is transferred to the carry bit. In an arithmetic shift to the left (ASL), the highest bit is dropped and the lowest bit will be void. Thus 1001<<1 creates (1) 001X; X is replaced with 0 and (1) is transferred to the carry bit.

Now that's out of the way, a rotation is simply a shift, but instead of filling the void with 0, it fills the void with the carry bit.  So let's look at that value from before, but this time as bits.

0000 0001   1000 0010
$01         $82


The byte you shift first depends on where you are shifting to. This could be confusing on the NES because of the reverse order, so it helps to write it out in 16-bit order as I did here. If you are shifting to the left, you start with the lowest byte ($82); if you are shifting to the right, you start with the highest byte ($01). In this example we want to shift to the left 4 times, so we start with the lowest byte.

0000 0001 (1) 0000 0100


We now perform a rotation in the same direction on the other byte.

0000 001(1)   0000 0100


Do this three more times per our previous example.


0000 0011 (0) 0000 1000
0000 011(0)   0000 1000
0000 0110 (0) 0001 0000
0000 110(0)   0001 0000
0000 1100 (0) 0010 0000
0001 100(0)   0010 0000 ($18$20)


As you can see, that required twice as many steps as a simple 16-bit shift to the left. That's how 16-bit systems are faster than 8-bit systems, even though they can seem to run just as slowly in a poorly programmed game. Game Maker already handles enough bytes, so it has no need for a rotation function.

What this means for me is I can possibly now go back and rewrite my password generator so it's twice as fast and possibly rewrite some code in my current engine to be faster. I've already converted hspd and vspd to 16-bit values, now I just have to work on other 16-bit values (things like score and time I've been handling in 32-bit from the get-go).
Your mom has had more floppies put in her than a Commodore 64!


Follow my lack of progress on my game at my blog:
http://gmvania.blogspot.com

Tags: