DanBoris Posted November 27, 2008 Share Posted November 27, 2008 (edited) Here a quick explanation of branch instructions, hope this helps. I guess branch instructions can be a little tricky because there are other things you need to understand before you can utilize them effectively. First you need to understand the processor status registers. The flags in this register are set or cleared based on the result of a lot of the other instructions. You can look at a 6502 instruction reference to see exactly which instructions set which flags. The flags that the branches can use are: Z – Zero Flag – This is set whenever an instruction results in a zero. So if you do a LDA #$00, the flag will be set, or if the X register contain 1 and you do a DEX, the zero flag will be set. Any other result will clear the zero flag. This is the flag you will probably use most often. C – Carry Flag – This is set whenever the A register rolls over from $FF to $00. So if A contains #$F0 and you do ADC #$20 then the carry flag will be set. This is a really important flag when you are doing 16-bit addition. N – Negative Flag – This is set equal to bit 7 of the result. When doing signed arithmetic bit 7 indicates a negative number thus the name Negative Flag. V – Overflow Flag – This is used when doing BCD arithmetic. It can be pretty confusing so I won’t get into it here. One important thing to remember about these flags, once they are set or cleared they remain in this state until another instruction that affects the flag is executed. Since not every instruction affects every flag it’s possible for a flag to carry over numerous instructions. Once you understand the flags the branch instructions are pretty simple. Each one checks the state of a flag and either branches execution to another memory location, or continues with the next instruction after the branch. The one tricky thing about this is that branches are “relative”. Branch instruction only takes up two bytes, the first byte is the opcode and the second is how far from the current memory location to jump. So if the second byte of a branch is $08 then the 8 will be added to the program counter and that’s where execution will continue. Since only one byte is used for this offset you can only branch 128 bytes forward, or 127 bytes backward. When working in assembler you don’t have to worry much about this offset, you just specify the address (usually a label) you want to branch to and the assembler will calculate the offset. The assembler will also tell you if you try to branch too far. So here are a few examples of the branch instructions: BNE – Branch if not equal (to zero). This will branch if the zero flag is not set. For example: Ldx #$00 loop inx bne loop This piece of code the loop until X rolls over to zero. BEQ is the opposite of BNE, it branches when the zero flag is cleared. If you go through the instruction reference you will find branch instruction that test each flag for being set or being cleared. One more important instruction to understand is the CMP, Compare, instruction. The instruction takes the operand data, subtracts it from the accumulator, set the N, Z, C flags and then discards the result, the accumulator is not modified. Here is an example: Lda $50 CMP #$22 BEQ endgame In this code if memory location $50 contains #$22 the branch will jump to the code at “endgame”. The compare instruction will subtract $22 from the accumulator, so if it contains $22 the result will be zero and the Z flag will be set. BEQ will test for the Z flag being set and take the branch. Edited November 27, 2008 by DanBoris Quote Link to comment Share on other sites More sharing options...
Gorf Posted November 27, 2008 Share Posted November 27, 2008 (edited) The problem they are giving me is the simple fact that I can't seem to understand how or when to use them. The book I've been reading to learn 6502 Assembly Language had done a great job of putting main ASSEMBLY LANGUAGE keywords into BASIC terminology I can understand. For example, the Load and Store commands were shown in both Assembly and BASIC sample codes. (POKE=STA, PEEK=LDA for example). And yes, Dan, THOSE commands. Here are examples of the four most commonly used branch instructions. BEQ lda #THIS cmp #THAT BEQ label ;do stuff here rts label: ;else do different stuff here rts in basic: IF THIS = THAT THEN GOTO Label BNE lda #THIS cmp #THAT BNE label ;do stuff here rts label: ;else do different stuff here rts in basic: IF THIS != THAT THEN GOTO label BCC branch on carry clear. This is good to use as a 'greater than' lda #THIS cmp #THAT BCC label ;do stuff here rts label: ;else do different stuff here rts in basic: IF THIS > THAT THEN GOTO label BCS branch on carry set. This is good to use as a 'less than' lda #THIS cmp #THAT BCS label ;do stuff here rts label: ;else do different stuff here rts in basic: IF THIS < THAT THEN GOTO label These last two can actually act like either a < or > depending on the instructions you are using so be careful(lol I may have screwed that up myself, but I THINK its correct.) You can use BEQ to simulate a 'switch/case' The following loads a switch value then trims it to a value > 4 then determines which case it is. lda switch and #3 cmp #CASE0 beq CASE0Process cmp #CASE1 beq CASE1Process cmp #CASE2 beq CASE2Process cmp #CASE3 beq CASE3Process rts CASE0Process: rts CASE1Process: rts CASE2Process: rts CASE3Process: rts Just some tid bits I hope helps you. Edited November 27, 2008 by Gorf Quote Link to comment Share on other sites More sharing options...
kamakazi Posted December 19, 2008 Author Share Posted December 19, 2008 WOW! You guys are awesome!! I will admit, switching from BASIC to Assembly for the 7800 is a huge leap!! But I'm having fun with it nevertheless. And those did help DAN and GORF, thank you very much. On a sidenote...I found some other interesting information but I'm currently stuck with the timed-internet usage at the public library until I get my own again. Recently relocated and I'm no longer in Arkansas. Have one more question...I was going over some example source codes that was part of MADMAC...what are the "ds" commands or whatever they are? I know I've asked a lot already, and this IS supposed to be on 7800 Programming. I guess I need to change it to Learning Assembly Language for a bit LOL. But I am learning and learning pretty quick. On an update, I've got artwork completed for 5 game ideas I have for the 7800. My top-most favorite of all is a racing game I plan on doing based in part on Gran Turismo. I'm currently calling it Atari GT. This is all that I can give out on it at this time as it is still in development. I'll share some screenshots here as they become available. Thanks again and Happy Holidays to everyone in the forums!! Chow! Quote Link to comment Share on other sites More sharing options...
+selgus Posted December 20, 2008 Share Posted December 20, 2008 Have one more question...I was going over some example source codes that was part of MADMAC...what are the "ds" commands or whatever they are? I know I've asked a lot already, and this IS supposed to be on 7800 Programming. I guess I need to change it to Learning Assembly Language for a bit LOL. But I am learning and learning pretty quick. ds is a pseudo-opcode for "define space", which is followed by an expression to say how many bytes of space to allocate. This is used for reserving a certain number of bytes starting from the current memory address. so: VariableName1: ds 4 VariableName2: ds 2 would define 4 bytes of memory at address VariableName1, followed by 2 bytes of memory at VariableName2. --Selgus Quote Link to comment Share on other sites More sharing options...
+Allan Posted December 20, 2008 Share Posted December 20, 2008 Have one more question...I was going over some example source codes that was part of MADMAC...what are the "ds" commands or whatever they are? I know I've asked a lot already, and this IS supposed to be on 7800 Programming. I guess I need to change it to Learning Assembly Language for a bit LOL. But I am learning and learning pretty quick. It's really part of MADMAC than an assembly language command. Allan Quote Link to comment Share on other sites More sharing options...
Gorf Posted January 20, 2009 Share Posted January 20, 2009 WOW! You guys are awesome!! I will admit, switching from BASIC to Assembly for the 7800 is a huge leap!! But I'm having fun with it nevertheless. And those did help DAN and GORF, thank you very much. Glad I could be useful(for once.) Quote Link to comment Share on other sites More sharing options...
STGuy1040 Posted January 20, 2009 Share Posted January 20, 2009 This may sound like a stupid question, but what would be the best way to develop graphics for the Atari 7800? Plus, what are the color registers and resolution? Quote Link to comment Share on other sites More sharing options...
gdement Posted January 25, 2009 Share Posted January 25, 2009 This may sound like a stupid question, but what would be the best way to develop graphics for the Atari 7800? Plus, what are the color registers and resolution? Personally, I just draw them up in a paint program then when I'm happy I type the data in code. I haven't done much of it though, so maybe people who do more graphics find that tedious. Seems to me the color format isn't very complicated so using a tool just isn't worthwhile. Normally the resolution is about 160x200 (vertical varies a bit depending on the TV) so you need to adjust for the aspect ratio. "The Gimp" can do that, but I'm sure there's many other programs that can do the same. There's a color test ROM somewhere that you could use to see the palette. As far as getting the raw data, I think you could probably extract the values from a palette that Underball and Nabuko78 created for the ProSystem emulator. Quote Link to comment Share on other sites More sharing options...
STGuy1040 Posted January 25, 2009 Share Posted January 25, 2009 This may sound like a stupid question, but what would be the best way to develop graphics for the Atari 7800? Plus, what are the color registers and resolution? Personally, I just draw them up in a paint program then when I'm happy I type the data in code. I haven't done much of it though, so maybe people who do more graphics find that tedious. Seems to me the color format isn't very complicated so using a tool just isn't worthwhile. Normally the resolution is about 160x200 (vertical varies a bit depending on the TV) so you need to adjust for the aspect ratio. "The Gimp" can do that, but I'm sure there's many other programs that can do the same. There's a color test ROM somewhere that you could use to see the palette. As far as getting the raw data, I think you could probably extract the values from a palette that Underball and Nabuko78 created for the ProSystem emulator. Thank you! Your answer has really helped me out. Quote Link to comment Share on other sites More sharing options...
kamakazi Posted February 26, 2009 Author Share Posted February 26, 2009 I would have to determine my answer by what equipment you are using. If you are using a PC...I'm not too sure what to use. I'm using an actual ST 540 for program creating 7800 games. The program I'm "stuck" with for 7800 graphics is an almost perfect Neochrome. I also have an actual copy of EPYX's ART and FILM DIRECTOR which is pretty amazing. If you can find any similar programs for a PC, I'm sure that those will work. I could be wrong as well. There are others on here who have used a PC for programming the 7800 through emulation that would know more. Quote Link to comment Share on other sites More sharing options...
kamakazi Posted February 27, 2009 Author Share Posted February 27, 2009 I'm going to attempt to program the 7800 using a PC instead of an actual Atari ST. Any suggestions on a sprite/art program that will allow me to create graphics for MARIA would be helpful. Any useful programming tricks as well would be nice as well. I have had an original game idea in my head and on paper for a long time now and have created a QuickBASIC version of the game to work out any logic problems and to improve on gameplay as it was developed. I'm hoping to be able to have the 7800 be as faithful to this version graphically. Quote Link to comment Share on other sites More sharing options...
kamakazi Posted February 27, 2009 Author Share Posted February 27, 2009 I'm going to give a rundown of what I'm hoping I understand. I'm posting these here to see if I am on the right track or not. First...the "ds.b #" is the same as DIMinish statements in BASIC. If this is correct, then this: DIM PADDLE(10) is the same as this: paddle: .ds.b 10 I also know that LOAD & STORE are the same as PEEK & POKE (respectively). This should mean that I can translate this: ML=PEEK(####) ML=ML+1 POKE(####),ML into this: .org $#### lda ML inc sta ML Keep in mind, this is just a rough form of what I'm learning and that the #### are there only to represent any number at present. If these were real codes, I'd use actually numbers. I'm hoping I'm on the right track and hope if I'm not, someone will explain why. My only issue with the Load/save commands is when to use X, Y or A. But I'm working on it. Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted February 27, 2009 Share Posted February 27, 2009 The code sequence :- .org $#### lda ML inc sta ML Is better witten as :- inc ML thus avoiding the load to the accumulator and saving cycles. Get yourself a good book on 6502 assembler and look at the available addressing modes. I've also used the following as a handy guide :- http://www.6502.org/tutorials/6502opcodes.html Quote Link to comment Share on other sites More sharing options...
kamakazi Posted February 27, 2009 Author Share Posted February 27, 2009 I own the book Assembly Language Programming for Atari Computers. But it's programming and memory locations are based on the 8-bit computer consoles, not the 7800. I tried a few of the samples forgetting what they were for and then tried to run them on a 7800 emulator. Thanks for clearing up the INC statement. Quote Link to comment Share on other sites More sharing options...
+selgus Posted March 1, 2009 Share Posted March 1, 2009 I own the book Assembly Language Programming for Atari Computers. But it's programming and memory locations are based on the 8-bit computer consoles, not the 7800. I tried a few of the samples forgetting what they were for and then tried to run them on a 7800 emulator. You can try Dan's site, where he has a bunch of docs/links to Atari 7800 technical information. --Selgus Quote Link to comment Share on other sites More sharing options...
+Sauron Posted September 8, 2009 Share Posted September 8, 2009 Just came across this topic and noticed it's loaded with a wealth of information. It's a shame that this hadn't been stickied yet. I'll have to rememdy that. Quote Link to comment Share on other sites More sharing options...
kamakazi Posted February 15, 2010 Author Share Posted February 15, 2010 Goodness I've been away too long. I haven't stopped programming attempts with the 7800, but have postponed it. Looks like I'm going to have to learn all over again. I've started going to college in web designing and got my hands on some pretty cool software. Thank you for pinning this so I could find it again. I do have more questions so here goes: As stated earlier, I plan to use a PC for 7800 programming. Here is what I have so far... Crimson Editor 7800 Emulator DASM Is there anything I'm missing? I currently have a complete Adobe CS4 Suite including Photoshop and other tools. Could any of these be used for graphics? If not, could someone please tell me what graphics program would work best. What I was thinking about attempting was using a ST emulator with all the development software Atari created. This stuff is available online. Would this attempt work? Another approach to gaining knowledge of 7800 programming I thought about was learning the 2600 first. Even if it is another console, it might shed some light on developing 6502 assembly language skills. Thank you to all who have viewed, used, and kept this thread going. I really do appreciate it. Too bad a BASIC translator doesn't exsist for 7800 programming. Learning Assembly alone when all you know is BASIC does put up quite a challenge. Oh, I almost forgot...would anyone know how to test PC based 7800 programming efforts on a real 7800? This is mainly to test for any differences between an emulator and real hardware. Thanks again! Quote Link to comment Share on other sites More sharing options...
+Allan Posted February 15, 2010 Share Posted February 15, 2010 Try the sprite demo here http://www.atarihq.com/danb/a7800.shtml#sourcecode It just moves a ghost around the screen with the joystick. It's a good example to play around with. Allan Quote Link to comment Share on other sites More sharing options...
kamakazi Posted February 15, 2010 Author Share Posted February 15, 2010 Try the sprite demo here http://www.atarihq.com/danb/a7800.shtml#sourcecode It just moves a ghost around the screen with the joystick. It's a good example to play around with. Allan Thanks Allan! I will do so. Quote Link to comment Share on other sites More sharing options...
kamakazi Posted February 15, 2010 Author Share Posted February 15, 2010 (edited) Ok, I was going back over some of the things here to get a refresh. I remember asking about the ds instruction (which was pointed out being a MADMAC thing). However, I have noticed some 7800 source codes using it. Is this a way to set some memory aside for things like graphics? If so, where would be the best place to store graphics? I also am putting the previously mentioned Atari GT on hold in favor of a brick game idea. Figured this would be a little easier to handle. I am editing this to add a link to 6502 Language Set. Here is the link: 6502 Instruction Set Edited February 15, 2010 by kamakazi Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted February 15, 2010 Share Posted February 15, 2010 Is this a way to set some memory aside for things like graphics? If so, where would be the best place to store graphics? It depends on your development environment and target cartridge size. If you use CC65 you can declare the graphics in a segment and let the linker do it or in DASM you'll need to ORG/RORG as appropriate. It also depends on whether or not you have holey DMA enabled as to where the graphics need to be aligned in memory. Quote Link to comment Share on other sites More sharing options...
kamakazi Posted February 15, 2010 Author Share Posted February 15, 2010 Before I post this link to the first page of this thread, take a look at this documentation I found and see if it would help with 7800 programming. Thank you in advance. Atari System Reference Manual It seems to be based on Atari 8-bits, but does give BASIC language cross-references which might help some of us new to Assembly learn the language. Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted February 15, 2010 Share Posted February 15, 2010 Before I post this link to the first page of this thread, take a look at this documentation I found and see if it would help with 7800 programming. I think that it would be far too confusing for a noob to learn the 7800 hardware studying that manual. They aren't even close in hardware terms. The only things that match the 7800 are the joystick port pins and the use of POKEY. Even then POKEY is normally mapped to $4000 and not $D20x on 7800 carts. It would be best to start with the GCC documentation for MARIA and a 6502 assembly language manual. Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted February 15, 2010 Share Posted February 15, 2010 All the atari7800.net links in post #2 are dead for me. Quote Link to comment Share on other sites More sharing options...
+Mitch Posted February 15, 2010 Share Posted February 15, 2010 All the atari7800.net links in post #2 are dead for me. That's because atari7800.net seems to have died. Most of those links were just copies of stuff from other pages anyway. Atari7800.org dev page Atari Museum 7800 tech doc page Dan Boris' 7800 tech page Mitch 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.