Rayback Posted April 25, 2021 Share Posted April 25, 2021 Hi guys, i am new at programming the 6502 processor ( i would like to develop on atari 2600),so im trying to practice up by writing some random stuff. The question for you,expert programmers is the following one: i have written a code,and i tried to add a player on the screen, also i used some variables for setting the y pos and the lines where the sprite can appear. but,anyway,the sprite doesn't work,so i wonder if there is any mistake in the source code and in the opcodes usage. ( i use z26 as emulator) here is the code i made processor 6502 include "vcs.h" include "macro.h" SEG ORG $F000 pline = $81 ypos = $80 ; initializing, cleaning ram and tia registers ldx #$FF lda #0 clea sta $00,x dex bne clea ; setting color for player lda #$18 sta COLUP0 ; setting y pos for player 0 lda #80 sta ypos Reset StartOfFrame ; vsync lda #2 sta VSYNC sta VBLANK sta WSYNC sta WSYNC sta WSYNC lda #0 sta VSYNC ; 37 lines of vetical blank lda #43 sta TIM64T vb sta WSYNC lda INTIM bne vb lda #0 sta VBLANK ; 192 lines of picture ldy #3 lda #$70 sta COLUBK lda #$1E sta COLUPF lda #%11000000 light sta PF0 nop nop lda #%00111000 sta PF1 sta PF2 sta WSYNC dey bne light ; void ldy #15 lda #0 sta PF1 sta PF0 sta PF2 void sta WSYNC dey bne void ; palace ldy #174 lda #$08 sta COLUPF pic sta WSYNC lda #%11111111 sta PF1 sta PF0 sta PF2 checkpl cpy ypos bne skip lda #7 sta pline skip draw ldx pline beq final lda Frame0,X sta GRP0 dec pline final dey bne pic ; over scan ldx #0 lda #2 over sta VBLANK sta WSYNC inx cpx #30 bne over jmp StartOfFrame Frame0 .byte #%10000001 .byte #%11000011 .byte #%01111110 .byte #%00111100 .byte #%00111100 .byte #%11111111 .byte #%10111101 .byte #%00111100 ;finishing org $FFFC InterruptVectors word. Reset word. Reset END Quote Link to comment Share on other sites More sharing options...
Rayback Posted April 25, 2021 Author Share Posted April 25, 2021 1 minute ago, Rayback said: Hi guys, i am new at programming the 6502 processor ( i would like to develop on atari 2600),so im trying to practice up by writing some random stuff. The question for you,expert programmers is the following one: i have written a code,and i tried to add a player on the screen, also i used some variables for setting the y pos and the lines where the sprite can appear. but,anyway,the sprite doesn't work,so i wonder if there is any mistake in the source code and in the opcodes usage. ( i use z26 as emulator) here is the code i made processor 6502 include "vcs.h" include "macro.h" SEG ORG $F000 pline = $81 ypos = $80 ; initializing, cleaning ram and tia registers ldx #$FF lda #0 clea sta $00,x dex bne clea ; setting color for player lda #$18 sta COLUP0 ; setting y pos for player 0 lda #80 sta ypos Reset StartOfFrame ; vsync lda #2 sta VSYNC sta VBLANK sta WSYNC sta WSYNC sta WSYNC lda #0 sta VSYNC ; 37 lines of vetical blank lda #43 sta TIM64T vb sta WSYNC lda INTIM bne vb lda #0 sta VBLANK ; 192 lines of picture ldy #3 lda #$70 sta COLUBK lda #$1E sta COLUPF lda #%11000000 light sta PF0 nop nop lda #%00111000 sta PF1 sta PF2 sta WSYNC dey bne light ; void ldy #15 lda #0 sta PF1 sta PF0 sta PF2 void sta WSYNC dey bne void ; palace ldy #174 lda #$08 sta COLUPF pic sta WSYNC lda #%11111111 sta PF1 sta PF0 sta PF2 checkpl cpy ypos bne skip lda #7 sta pline skip draw ldx pline beq final lda Frame0,X sta GRP0 dec pline final dey bne pic ; over scan ldx #0 lda #2 over sta VBLANK sta WSYNC inx cpx #30 bne over jmp StartOfFrame Frame0 .byte #%10000001 .byte #%11000011 .byte #%01111110 .byte #%00111100 .byte #%00111100 .byte #%11111111 .byte #%10111101 .byte #%00111100 ;finishing org $FFFC InterruptVectors word. Reset word. Reset END further more the code is correctly idented,not like the post Quote Link to comment Share on other sites More sharing options...
Rayback Posted May 1, 2021 Author Share Posted May 1, 2021 On 4/25/2021 at 10:17 PM, Rayback said: Hi guys, i am new at programming the 6502 processor ( i would like to develop on atari 2600),so im trying to practice up by writing some random stuff. The question for you,expert programmers is the following one: i have written a code,and i tried to add a player on the screen, also i used some variables for setting the y pos and the lines where the sprite can appear. but,anyway,the sprite doesn't work,so i wonder if there is any mistake in the source code and in the opcodes usage. ( i use z26 as emulator) here is the code i made processor 6502 include "vcs.h" include "macro.h" SEG ORG $F000 pline = $81 ypos = $80 ; initializing, cleaning ram and tia registers ldx #$FF lda #0 clea sta $00,x dex bne clea ; setting color for player lda #$18 sta COLUP0 ; setting y pos for player 0 lda #80 sta ypos Reset StartOfFrame ; vsync lda #2 sta VSYNC sta VBLANK sta WSYNC sta WSYNC sta WSYNC lda #0 sta VSYNC ; 37 lines of vetical blank lda #43 sta TIM64T vb sta WSYNC lda INTIM bne vb lda #0 sta VBLANK ; 192 lines of picture ldy #3 lda #$70 sta COLUBK lda #$1E sta COLUPF lda #%11000000 light sta PF0 nop nop lda #%00111000 sta PF1 sta PF2 sta WSYNC dey bne light ; void ldy #15 lda #0 sta PF1 sta PF0 sta PF2 void sta WSYNC dey bne void ; palace ldy #174 lda #$08 sta COLUPF pic sta WSYNC lda #%11111111 sta PF1 sta PF0 sta PF2 checkpl cpy ypos bne skip lda #7 sta pline skip draw ldx pline beq final lda Frame0,X sta GRP0 dec pline final dey bne pic ; over scan ldx #0 lda #2 over sta VBLANK sta WSYNC inx cpx #30 bne over jmp StartOfFrame Frame0 .byte #%10000001 .byte #%11000011 .byte #%01111110 .byte #%00111100 .byte #%00111100 .byte #%11111111 .byte #%10111101 .byte #%00111100 ;finishing org $FFFC InterruptVectors word. Reset word. Reset END up Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted May 1, 2021 Share Posted May 1, 2021 You'll get help faster if you upload your source file. player_test.asm On 4/25/2021 at 3:17 PM, Rayback said: i use z26 as emulator I suggest you use Stella, it has an Integrated Debugger (seen in the screenshot below) that helps figure out problems like this. I set a breakpoint at the sta GRP0 then let the code run. It never reaches that bit of code. My folks just arrived so I don't have any more free time to look into this at the moment. My suggestion is to use the debugger to step through the code and see why it's doing something you didn't expect. You may also find my Collect Tutorial useful, it goes over writing a 2K game from start to finish. Stella's Debugger with breakpoint set Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted May 2, 2021 Share Posted May 2, 2021 On 4/26/2021 at 6:19 AM, Rayback said: Frame0 .byte #%10000001 .byte #%11000011 .byte #%01111110 .byte #%00111100 .byte #%00111100 .byte #%11111111 .byte #%10111101 .byte #%00111100 I did not see any obvious issue in the code but regardless of that, the correct usage for the above is without the # The # is generally only used for immediate loads (e.g., lda #2), and not in data statements where the value you write is used verbatim. Double-check that you have your sprite/playfield priorities correct, too! And of course the horizontal position of the sprites. I did not see this in your code. One final suggestion - it's way way better to let the assembler do the variable address/locations for you. You use an uninitialised segment for this... SEG.U ZP ORG $80 ypos ds 1 pline ds 1 another ds 3 Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted May 2, 2021 Share Posted May 2, 2021 (edited) macro.h has a useful macro, CLEAN_START This will do your zp and register clear for you. Your current loop doesn't actually clear location 0 (not that it matters) but just pointing that out! To use a macro, just type its name with at least one leading space on the line. It's pretty whiz-bang and uses about 8 bytes of code to do that! Edited May 2, 2021 by Andrew Davie Quote Link to comment Share on other sites More sharing options...
Rayback Posted May 2, 2021 Author Share Posted May 2, 2021 23 hours ago, SpiceWare said: You'll get help faster if you upload your source file. player_test.asm 1.94 kB · 2 downloads I suggest you use Stella, it has an Integrated Debugger (seen in the screenshot below) that helps figure out problems like this. I set a breakpoint at the sta GRP0 then let the code run. It never reaches that bit of code. My folks just arrived so I don't have any more free time to look into this at the moment. My suggestion is to use the debugger to step through the code and see why it's doing something you didn't expect. You may also find my Collect Tutorial useful, it goes over writing a 2K game from start to finish. Stella's Debugger with breakpoint set Thanks for your answer,im going to install this emulator for sure,seems more advanced Quote Link to comment Share on other sites More sharing options...
Rayback Posted May 2, 2021 Author Share Posted May 2, 2021 3 hours ago, Andrew Davie said: I did not see any obvious issue in the code but regardless of that, the correct usage for the above is without the # The # is generally only used for immediate loads (e.g., lda #2), and not in data statements where the value you write is used verbatim. Double-check that you have your sprite/playfield priorities correct, too! And of course the horizontal position of the sprites. I did not see this in your code. One final suggestion - it's way way better to let the assembler do the variable address/locations for you. You use an uninitialised segment for this... SEG.U ZP ORG $80 ypos ds 1 pline ds 1 another ds 3 Thank you for your tips,i tried to integrate the code with what you said, and the sprite now works, even if (i don't know why) it appears in different locations on the screen every time i open the rom,and using the debugger i have found that is like the processor adds the wrong data from the table Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted May 3, 2021 Share Posted May 3, 2021 On 5/2/2021 at 9:02 AM, Rayback said: Thank you for your tips You're welcome! On 5/2/2021 at 9:02 AM, Rayback said: sprite now works, even if (i don't know why) it appears in different locations on the screen every time i open the rom Looking at the available source I don't see you strobing RESP0, so the X position will be random. The following is from the Stella Programmer's Guide, you can find it here at MiniDig. Quote 7.0 Horizontal Positioning The horizontal position of each object is set by writing to its’ associated reset register (RESP0, RESP1, RESM0, RESM1, RESBL) which are all “strobe” registers (they trigger their function as soon as they are addressed). That causes the object to be positioned wherever the electron bean was in its sweep across the screen when the register was reset. for example, if the electron beam was 60 color clocks into a scan line when RESP0 was written to, player 0 would be positioned 60 color clocks "in” on the next scan line. Whether or not P0 is actually drawn on the screen is a function of the data in the GP0 register, but if it were drawn, it would show up at 60. Resets to these registers anywhere during horizontal blanking will position objects at the left edge of the screen (color clock 0). Since there are 3 color clocks per machine cycle, and it can take up to 5 machine cycles to write the register, the programmer is confined to positioning the objects at 15 color clock intervals across the screen. This “course” positioning is “fine tuned” by the Horizontal Motion, explained in section 8.0. Quote Link to comment Share on other sites More sharing options...
Rayback Posted May 3, 2021 Author Share Posted May 3, 2021 1 hour ago, SpiceWare said: You're welcome! Looking at the available source I don't see you strobing RESP0, so the X position will be random. The following is from the Stella Programmer's Guide, you can find it here at MiniDig. Nice,i will try it Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted May 3, 2021 Share Posted May 3, 2021 1 hour ago, Rayback said: Nice,i will try it Most people end up using a variation of the routine PosObject for setting the X position of objects. ;=============================================================================== ; PosObject ;---------- ; subroutine for setting the X position of any TIA object ; when called, set the following registers: ; A - holds the X position of the object ; X - holds which object to position ; 0 = player0 ; 1 = player1 ; 2 = missile0 ; 3 = missile1 ; 4 = ball ; the routine will set the coarse X position of the object, as well as the ; fine-tune register that will be used when HMOVE is used. ; ; Note: The X position differs based on the object, for player0 and player1 ; 0 is the leftmost pixel while for missile0, missile1 and ball 1 is ; the leftmost pixel: ; players - X range is 0-159 ; missiles - X range is 1-160 ; ball - X range is 1-160 ; Note: Setting players to double or quad size will affect the position of ; the players. ;=============================================================================== PosObject: sec sta WSYNC DivideLoop sbc #15 ; 2 2 - each time thru this loop takes 5 cycles, which is bcs DivideLoop ; 2 4 - the same amount of time it takes to draw 15 pixels eor #7 ; 2 6 - The EOR & ASL statements convert the remainder asl ; 2 8 - of position/15 to the value needed to fine tune asl ; 2 10 - the X position asl ; 2 12 asl ; 2 14 sta.wx HMP0,X ; 5 19 - store fine tuning of X sta RESP0,X ; 4 23 - set coarse X position of object rts ; 6 29 Generally a loop will be used to set the position of all objects. ;=============================================================================== ; PositionObjects ; -------------- ; Updates TIA for X position of all objects ; Updates Kernel variables for Y position of all objects ;=============================================================================== PositionObjects: ldx #4 ; position all objects POloop lda ObjectX,x ; get the object's X position jsr PosObject ; set coarse X position and fine-tune amount dex ; DEcrement X bpl POloop ; Branch PLus so we position all objects sta WSYNC ; wait for end of scanline sta HMOVE ; use fine-tune values to set final X positions Download the source from Step 4 of my tutorial for more info. 1 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.