Jump to content
IGNORED

Assistance Needed with Scanlines


Recommended Posts

Hey friends! 
     Despite making progress, I have run into an issue with the code that I'm struggling to resolve.

      Specifically, I have managed to address the initial hurdle of getting the sprites to draw, albeit with some assistance from a persons code in Andrew Davies' tutorial, which I modified to suit my requirements. However, I am currently facing confusion regarding the output of the code.

       Upon execution, the code segment "Character" generates approximately 50 scanlines, whereas my expectation was for it to produce only 17. Consequently, this discrepancy has led to several complications, notably an oversized play screen that exceeds the standard dimensions of CRT TV displays. Moreover, I have encountered limitations in adjusting the code, as it appears to cap at 313 scanlines, anything more seems to break the entire code.

          Below, I have included the code for your review and potential insights. Any guidance or suggestions you could provide to rectify this issue would be immensely appreciated.

Thank you in advance for your time and assistance.
Yours,
Elijah


           processor 6502

           include "vcs.h"

           include "macro.h"



PFCOL      equ #$A2
BACKGROUND equ #$00
COL0       equ #$1E
sprite_draw equ #$80
            seg.u	vars				; uninitialized segment

           seg main
           ORG $F000
;Created using Atari Dev Studio
;assembly format (bottom to top) -actually i flipped it -elijah
mainplayer

    .byte %01111110 ;

	.byte %01111010 ;

	.byte %01101110 ;

	.byte %01110010 ;

    .byte %01111110 ;

	.byte %00011000 ;

	.byte %00011000 ;

    .byte %00111100 ;

	.byte %01011010 ;

	.byte %00011000 ;

	.byte %00111100 ;

	.byte %00100100 ;

	.byte %01100110 ;

	.byte %00000000 ;

	.byte %00000000 ;

    .byte #%00000000
	




reset		    
                cld         ;clear the decimal flag
                ldX #$ff
                tXs         ;set the stack pointer to "$ff"
            	ldX 	#0 				; Clear RAM and all TIA registers
				lda 	#0 
  
clear       	sta 	0,X 			; $0 to $7F (0-127) reserved OS page zero, $80 to $FF (128-255) user zero page ram.
				inX 
				bne 	clear

				lda 	#%00000001		; Set D0 to reflect the playfield
				sta 	CTRLPF			; Apply to the CTRLPF register

				lda		#PFCOL			
				sta		COLUPF			; Set the PF color

                
                lda #COL0
                sta COLUP0

                sta     WSYNC


                

                SLEEP   19

                sta     RESP0


StartOfFrame
                lda   #%00000010
                sta  VSYNC

                sta WSYNC
                sta WSYNC
                sta WSYNC

                ; turn off vsync
                lda #0
                sta VSYNC

                lda #43
                sta TIM64T

                ldX #0

lvblank    sta WSYNC
                lda INTIM
                bne lvblank

                sleep 24
                STA RESP0
                ldy #17
                ldx #0
                sta VBLANK
 
Drawfield      lda       #%00000000 ;2
                sta PF0 ;3
                sta PF1 ;3
                sta PF2 ;3

                stX COLUBK  ;note, havent loaded background yet, 3
                sta WSYNC  ;3

                inX ;2
                    cpX #133 ;2?
                    bne Drawfield ;2
                ldX #0 ;2
                stx sprite_draw
Character
        cpy 17
        bpl No_Drawing
   ldx sprite_draw
        cpx 17
        beq No_Drawing
        lda mainplayer,x
        sta GRP0
        inx
   stx sprite_draw   
                                       
                
Drawfield2               lda #%11111100 ;2
                sta PF0 ;3
                sta PF1 ;3
                sta PF2 ;3

                lda #BACKGROUND ;load background color,3
                sta COLUBK ;3
                inX ;2
                    cpX #17 ;2
                    bne Drawfield2 ;2
                ldX #0 ;2

No_Drawing                        

              STA WSYNC        

              DEY              ; 192 Scanlines drawn ?

              BNE Character      ; No = Continue


overscan    sta WSYNC
                  inX
                  cpX #30
                  bne overscan

                  jmp StartOfFrame

                  org $FFFA
 

irqvectors
				.word reset         	; NMI
				.word reset         	; RESET
				.word reset         	; IRQ
                
    END


 

Link to comment
Share on other sites

I took a quick look and this jumped out at me:

 

Character
        cpy 17
        bpl No_Drawing
   ldx sprite_draw
        cpx 17
        beq No_Drawing

 

 

The cpy 17 and cpx 17 are comparing against the value retrieved from address 17, which is a mirror of TIA register CXM1P

 

So you're not comparing against 17, but against the collision detection results of missile1/player0 and Missile1/player1.

 

cpy #17 and cpx #17 will compare against the number 17.

Link to comment
Share on other sites

2 hours ago, SpiceWare said:

I took a quick look and this jumped out at me:

 

Character
        cpy 17
        bpl No_Drawing
   ldx sprite_draw
        cpx 17
        beq No_Drawing

 

 

The cpy 17 and cpx 17 are comparing against the value retrieved from address 17, which is a mirror of TIA register CXM1P

 

So you're not comparing against 17, but against the collision detection results of missile1/player0 and Missile1/player1.

 

cpy #17 and cpx #17 will compare against the number 17.

Hi there! That doubtlessly saved me some head ache later, so thank you! But unfortunately that didn't seem to solve the weirdly high screenlines!

Link to comment
Share on other sites

You'll want to learn how Stella's Debugger works to figure this out.  Compile your code after making the cpy #17 and cpx #17 fixes, then load your ROM into Stella:

 

Screenshot2024-02-25at12_33_27PM.thumb.png.fac911d531e50087038361cb7761539d.png

 

Press the ` key on your keyboard (next to 1, above tab, below ESCape) to enter the debugger:

 

image.thumb.png.9f896e2d8acf8e5a373283a9baa860eb.png

 

In the prompt type break Character then hit RETURN:

 

Screenshot2024-02-25at12_37_12PM.thumb.png.d1015c163acbc205084c9dd7eaa04c99.png

 

Hit ` again, your program will run and then reenter the debugger when it gets to Character:

 

Screenshot2024-02-25at12_38_47PM.thumb.png.0bb25f3fc7f2e0ccb292e0c9a52e9af9.png

 

At this point hit the Step button in the upper right to single step through your code.

 

Screenshot2024-02-25at12_42_13PM.thumb.png.29fc69aa297753e980b7596e7735503f.png

 

 

Repeatedly hit Step while watching what the code does, as well as the registry values, the current Scanline and the Scan Cycle position.

 

Screenshot2024-02-25at12_42_17PM.thumb.png.56890af2642da94d7e7a04f85c7ab063.png

 

What I see when stepping thru the program is that after GRP0 is updated the program will do a loop which updates PF0, PF1, and PF2 over multiple scanlines before it does the next update to GRP0. This is what's causing your player to be so tall.

 

 

You might also like to take a look at my Collect tutorial, which covers writing a complete 2K game from scratch.

 

 

 

 

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...