Jump to content
IGNORED

Programming ASM for 6502 vs. 6507 - Questions.


Recommended Posts

Hey everyone!

 

Question #1: If one learns ASM (or is learning like me) for the 6502, what will happen when the program runs on a 6507? I mean they are not fully compatible at all right?

 

Question #2: Now based on that concept, if one writes for the 6507 will it ALWAYS run on a 6502? Seems like it(?)

 

Question #3: Please name your top five "go to" books for learning ASM programming for the Atari 2600?

 

 

 

 

* Please disregard my massive "newbie-ness" as my previous questions are most assuredly naive in some fashion.

 

 

 

 

Thanks!

 

 

 

JR

Link to comment
Share on other sites

The main differences between 6502 and 6507 is that the 6507 has less address lines so it can only address 8K instead of 64K and it also lacks the IRQ# and NMI# interrupt lines.

 

If you stick to the legal opcodes e.g. those specified in the datasheets of the day you'll be fine. Once you get familiar with the instruction set you might want to start using the stable illegal opcodes. Illegal opcodes are more useful in 2600 programming because cycles are at a premium in your display kernel and space may also be tight if you are targeting 2K or 4K games.

 

Many 6502 books have mistakes (so aren't ideal for beginners in my opinion) but a good general purpose one in the "6502 Reference Guide" by Alan Tully. It covers all the opcodes, their cycle timing, flags affected and available addressing modes. For good routines "Assembler Routines for the 6502" from the "Best of PCW" series and "6502 Software Gourmet Guide and Cookbook" by Robert Hindley are both good. All these books are long out of print but you might be able to snag a copy on ebay if/when they come up.

 

Asking questions in the relevant AA programmers forums for your Atari machine of interest can also draw on a vast array of experience to help you on your way.

Link to comment
Share on other sites

Thanks GroovyBee!

 

No probs!

 

My machines of interest (while vastly different) would be the 2600 and the C-64.

 

An interesting pair ;).

 

Thanks for the ideas on the books! I had not run across them yet. Right now I am just reading "Machine Language for Beginners". http://www.atariarchives.org/mlb/

 

I'm not familiar with that book. I just had a quick look and at first glance it looks like there is a ton of stuff you don't need to know thrown in like BASIC and its not too good on giving you building blocks to work along with. But... its a long time since I first learnt 6502 so take that opinion with a pinch of salt.

Link to comment
Share on other sites

Could you recommend something? The "6502 Reference Guide" maybe?

 

The best way to learn in my opinion is to set yourself little tasks and then build your knowledge and experience on them. Start with something simple like adding 2 numbers together in the accumulator, then add numbers stored in memory locations then work out how to make loops and the equivalent of if/then/else statements and as you learn make the tasks more and more complex. Then when you've got the basics down look at getting a sprite on screen (C64 is probably easiest for that), then learn how to move it around, then get a backdrop up, get the sprite to interact with it in some way and so on.

 

You might find it easier going with the CPU instructions if you find a pure windows based 6502 simulator (I know nothing of Linux or Mac) then you don't have to worry about setting up hardware to get you in a good state. Plus you can single step with ease and check out memory and CPU flags easily.

Link to comment
Share on other sites

Well actually I'm finding that also to be the case.

 

I am actually looking for a "ASM beginners book", but not one for an absolute newbie, because I don't consider myself quite that much of a beginner. :-D

 

Could you recommend something? The "6502 Reference Guide" maybe?

 

Do you see any useful free online books in the links section:

 

www.randomterrain.com/atari-2600-memories-tutorial-andrew-davie-01.html#useful_links

Link to comment
Share on other sites

As always, I recommend this awesome simulator to all 6502 beginners. Write some code, assemble it and debug it to your heart's content. Back when I started learning assembly I would read online documents about how the instructions worked, and then I would go to this simulator and try to do something using what I learned (or thought I learned!). I paid a lot of attention to how the status flags were affected by each instruction, how the stack behaved and how the different addressing modes worked, which IMO are essential things for the understanding of ASM. I made lots of little routines in this simulator, such as multiplication, division, square roots, just to practice and get the hang of how the instructions work.

 

Regarding the differences between 6502 and 6507, there aren't many. The difference between one machine and the other (i.e. 2600 vs C64 vs NES, etc.) is much more significant and has much more impact on the structure of your programs than the subtle differences between the 6502 and 6507. Each machine has different video, audio and input hardware, and the CPU interacts with them through registers mapped to different memory areas. Each machine has RAM and ROM mapped to different places. Those are the things that make any difference.

 

Don't worry too much about this right now, just play around with some pure 6502 in the simulator, testing everything you read in books/documents. Once you get the hang of doing arithmetic and controlling the program flow, you can try making something for a specific machine of your choice, taking its peculiarities into consideration.

Edited by tokumaru
Link to comment
Share on other sites

Could you recommend something? The "6502 Reference Guide" maybe?

 

The best way to learn in my opinion is to set yourself little tasks and then build your knowledge and experience on them. Start with something simple like adding 2 numbers together in the accumulator, then add numbers stored in memory locations then work out how to make loops and the equivalent of if/then/else statements and as you learn make the tasks more and more complex. Then when you've got the basics down look at getting a sprite on screen (C64 is probably easiest for that), then learn how to move it around, then get a backdrop up, get the sprite to interact with it in some way and so on.

 

You might find it easier going with the CPU instructions if you find a pure windows based 6502 simulator (I know nothing of Linux or Mac) then you don't have to worry about setting up hardware to get you in a good state. Plus you can single step with ease and check out memory and CPU flags easily.

 

This is a great idea! Setting little goals to get to a bigger one.

 

Thanks GroovyBee.

Link to comment
Share on other sites

Well actually I'm finding that also to be the case.

 

I am actually looking for a "ASM beginners book", but not one for an absolute newbie, because I don't consider myself quite that much of a beginner. :-D

 

Could you recommend something? The "6502 Reference Guide" maybe?

 

Do you see any useful free online books in the links section:

 

www.randomterrain.com/atari-2600-memories-tutorial-andrew-davie-01.html#useful_links

 

I have been all over your website (or so I thought!) but did not see all those! Nice, and thank your RT!

Link to comment
Share on other sites

As always, I recommend this awesome simulator to all 6502 beginners. Write some code, assemble it and debug it to your heart's content. Back when I started learning assembly I would read online documents about how the instructions worked, and then I would go to this simulator and try to do something using what I learned (or thought I learned!). I paid a lot of attention to how the status flags were affected by each instruction, how the stack behaved and how the different addressing modes worked, which IMO are essential things for the understanding of ASM. I made lots of little routines in this simulator, such as multiplication, division, square roots, just to practice and get the hang of how the instructions work.

 

Regarding the differences between 6502 and 6507, there aren't many. The difference between one machine and the other (i.e. 2600 vs C64 vs NES, etc.) is much more significant and has much more impact on the structure of your programs than the subtle differences between the 6502 and 6507. Each machine has different video, audio and input hardware, and the CPU interacts with them through registers mapped to different memory areas. Each machine has RAM and ROM mapped to different places. Those are the things that make any difference.

 

Don't worry too much about this right now, just play around with some pure 6502 in the simulator, testing everything you read in books/documents. Once you get the hang of doing arithmetic and controlling the program flow, you can try making something for a specific machine of your choice, taking its peculiarities into consideration.

 

That simulator is super cool!

 

I will start messing with it immediately! Thank you very much for all of the pointers tokumaru!

Link to comment
Share on other sites

Setting little goals to get to a bigger one.

 

The other good thing about starting small is that the tasks can be completed relatively quickly so if you don't have much hobby programming time you can get "something" accomplished in whatever time you do have. If you go for a magnum opus as your first game it can be very demotivating if you don't have time to work on it or you hit a problem which you can't solve.

 

You might also want to implement higher level constructs like switch statements in "C", linked lists, bubble sort, quick sort, how to get values out of an array (useful for level maps) and doing multi-byte arithmetic like add, subtract and shift. Routines for BCD arithmetic and its conversion to displayable digits are also useful. Many of these routines (or more likely adaptations of them) will come in handy down the road for game development especially if you need to write sprite multiplexers (I'm mainly thinking of the C64 there).

 

For machines with an abundance of RAM like the C64 you might also want to dabble in self modifying code once you get enough experience under your belt.

Link to comment
Share on other sites

  • 2 weeks later...
Right now I am just reading "Machine Language for Beginners". http://www.atariarchives.org/mlb/

 

I'm not familiar with that book. I just had a quick look and at first glance it looks like there is a ton of stuff you don't need to know thrown in like BASIC and its not too good on giving you building blocks to work along with. But... its a long time since I first learnt 6502 so take that opinion with a pinch of salt.

 

That book was primarily intended to give a somewhat-experienced Basic programmer some idea of how to approach M/L programming without feeling a bit overwhelmed right from the start. It does a pretty good job explaining things at that level, but I could point out flat-out bad advice used in some spots for those who are tackling M/L more-directly rather than opposed to those making an initial leap away from Basic.

Link to comment
Share on other sites

JohhnyRockets,

those are two great platforms to code for but the 2600 is the more challenging because there is no screen memory. There's a Tiny-BASIC compiler out for the 2600 you may want to also try that's very good - Batari Basic.

 

Nukey,

that book looks like an excellent reference for beginners; could you point out one of those spots?

Link to comment
Share on other sites

that book looks like an excellent reference for beginners; could you point out one of those spots?

 

It's pretty much assumed by the author that the user is programming M/L from within Basic, so some of the examples make use of subroutines that exist within the Basic language (Chapter 7 - "Borrowing From Basic").

 

But a worse example comes from the previous chapter (boldface added by me for the full "Whaaa?" effect)...

 

"If you're wondering about the V flag, it is rarely used for anything. You can forget about the branch which depends on it, BVC, too."

 

Nevermind that it's a handy way of branching based on bit 6 status, but let's see where this paragraph is headed...

 

"Only five instructions affect it and it relates to "twos complement" arithmetic which we have not touched on in this book. Like decimal mode or negative numbers, you will be able to construct your ML programs very effectively if you remain in complete ignorance of this mode".

 

Yeah...and spend the next couple months bugfixing since they couldn't be bothered to write a few small paragraphs explaining what the modes do :lol:

 

But wait...there's more:

 

"We have largely avoided discussion of most of the flags in the status register: N, V, B, D, and I. This avoidance has also removed several branch instructions from our consideration: BMI, BPL, BVC, and BVS. These flags and instructions are not usually found in standard ML programs"

 

Erm...OK.

 

"and their use is confined to specialized mathematical or interfacing applications. They will not be of use or interest to the majority of ML programmers."

 

I forgot...what is a majority again?

Link to comment
Share on other sites

Don't get me wrong...the book is still an excellent resource toward the back of it - I have a well-worn copy here on my desk that I used thoughout the 8-bit era up to today. Somebody trying to learn asm from the ground floor should stick to the appendices and try not to get caught up in all the Basic-to-ML discussion (or it's own set of issues/quirks).

 

Given that well-travelled code examples are only a few keystrokes away these days, a memory map is pretty much all you need for quick reference.

Link to comment
Share on other sites

Pah.

 

CLV / BVC is the general accepted way to make up for the missing "BRA" instruction. V flag is used extensively due to it reflecting bit 6 state after a BIT instruction.

 

Rarely implemented, but the /SO pin allows super-quick polling mode interrupt handling. ie, enable the source, CLV then just "WAIT BVC WAIT" while waiting for the "soft interrupt".

 

If you're going to the trouble of writing a book explaining how to use what is effectively a poor man's RISC processor, may as well cover those few seldom used instructions.

  • Like 1
Link to comment
Share on other sites

But they are not "seldom" used in programming. Using BIT$addr and branching via BPL/BMI or BVC/BVS (if bit 7 or bit 6 are off or on respectively) is usually more-efficient than the alternatives. And it's no secret that decimal mode is used in the majority of games for scorekeeping and such - it makes things that much easier to convert the values to display pointers.

Link to comment
Share on other sites

  • 6 years later...
On ‎6‎/‎21‎/‎2012 at 1:15 PM, GroovyBee said:

 

The best way to learn in my opinion is to set yourself little tasks and then build your knowledge and experience on them. Start with something simple like adding 2 numbers together in the accumulator, then add numbers stored in memory locations then work out how to make loops and the equivalent of if/then/else statements and as you learn make the tasks more and more complex. Then when you've got the basics down look at getting a sprite on screen (C64 is probably easiest for that), then learn how to move it around, then get a backdrop up, get the sprite to interact with it in some way and so on.

 

You might find it easier going with the CPU instructions if you find a pure windows based 6502 simulator (I know nothing of Linux or Mac) then you don't have to worry about setting up hardware to get you in a good state. Plus you can single step with ease and check out memory and CPU flags easily.

there is an Atari 2600 IDE in Java if that interests you. go to www.8bitworkshop.com

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...