Jump to content
IuriNery

Loop through table every X lines?

Recommended Posts

Hello everyone,

 

I'm working on a project and I have a few questions:

 

First, take a look into this code:

 

; Kernel

; ------Kernel                STA WSYNC                LDA INTIM                BNE Kernel                                ; Turn ON Display                STA VBLANK                LDX #48KernelLoop                ; Preload Colors                LDA Screen_1_BKColor-1,X                LDY Screen_1_PFColor-1,X                ; BK/PF Colors                STA WSYNC                STA COLUBK                STY COLUPF                ; Draw Playfield                LDA Screen_1_PF0-1,X                STA PF0                LDA Screen_1_PF1-1,X                STA PF1                LDA Screen_1_PF2-1,X                STA PF2                ; Skip Lines                STA WSYNC                STA WSYNC                STA WSYNC                DEX                BNE KernelLoop                RTS

 

 

As you can see, I'm loading X with #48, because the shape & color tables have 48 values each, this is the result:

post-59407-0-11176700-1558723452.jpg

 

Now to the questions:

1. If I use #96 instead of #48, how do I update the Playfield only every 2 values? (What I'm trying to ask here is how do I modify the #48 and use #96 but still get the same results? So I can draw sprites using the #96 loop).

2. Is it still possible to draw sprites (Player/Ball) using that amount of resources in the Kernel? (Updating the PF & BK like in the code above).

 

Thank you.

Share this post


Link to post
Share on other sites

I think this is what you're asking for. Have you seen my Collect tutorial?

 

                LDX #96
 
KernelLoop
                ; Preload Colors
                LDA Screen_1_BKColor-1,X
                LDY Screen_1_PFColor-1,X
 
                ; BK/PF Colors
                STA WSYNC
                STA COLUBK
                STY COLUPF
 
                ; Draw Playfield
                LDA Screen_1_PF0-1,X
                STA PF0
                LDA Screen_1_PF1-1,X
                STA PF1
                LDA Screen_1_PF2-1,X
                STA PF2
 
                ; Skip Lines
                STA WSYNC
 
                DEX
                BNE KernelLoop
                RTS

Share this post


Link to post
Share on other sites

Hi,

 

Yes, I'm actually studying your tutorial, very good, I'm trying to get the player sprite show in the Playfield, but it's a little complicated, I don't think it's possible using this Kernel that I'm using without some heavy modifications I guess.

 

I tried your code, like this:

post-59407-0-56140800-1558725490.jpg

 

But this is the result:

post-59407-0-21290700-1558725543_thumb.jpg

 

My guess is that the program is trying to access values from the table that are not there?

 

(The tables have only 48 values).

 

What I want is to draw the PF in a #96 loop, but using tables that have 48 values, is this even possible? Maybe using a variable to store the kernel loops?

Share this post


Link to post
Share on other sites

What I want is to draw the PF in a #96 loop, but using tables that have 48 values, is this even possible? Maybe using a variable to store the kernel loops?

That's similar to what I do in Collect. I use Y to control the loop, and a RAM value called ArenaIndex that's loaded into X when it's time to draw the playfield.

Share this post


Link to post
Share on other sites

That's similar to what I do in Collect. I use Y to control the loop, and a RAM value called ArenaIndex that's loaded into X when it's time to draw the playfield.

 

The problem is that I'm using Y for the PF Color, maybe I should make use of some variables...

 

If I understand correctly reading the tutorials, the Player sprites should be draw at the same time as the Playfields/Background? So that way you can control the X/Y position of the sprite, right?

 

So, this is actually impossible to do?

JSR Kernel (draw the PF etc.)

JSR DrawSprites (draw the player)

Share this post


Link to post
Share on other sites
Posted (edited)

Instead of using X for the line counter, you could store it in RAM. To decrement it, use DEC instead of DEX:

                LDA #96
                STA $90    ; This is in RAM. It should be replaced with a label, so its less confusing.
                           ; I havent seen your RAM variables, so this address might already be used somewhere else in your code.
 
KernelLoop
                ; Preload Colors
                LDX $90
                LDA Screen_1_BKColor-1,X
                LDY Screen_1_PFColor-1,X
 
                ; BK/PF Colors
                STA WSYNC
                STA COLUBK
                STY COLUPF

                ; Prepare X for playfield
                LDA $90    ; First, load A with the line counter (1-96)
                LSR        ; This divides A by 2...
                TAX        ; ...and then transfers the result to X (1-48)
 
                ; Draw Playfield
                LDA Screen_1_PF0-1,X
                STA PF0
                LDA Screen_1_PF1-1,X
                STA PF1
                LDA Screen_1_PF2-1,X
                STA PF2
 
                ; Skip Lines
                STA WSYNC
 
                DEC $90        ; Decrement the line counter
                BNE KernelLoop
                RTS
Edited by JeremiahK

Share this post


Link to post
Share on other sites

So, this is actually impossible to do?

JSR Kernel (draw the PF etc.)

JSR DrawSprites (draw the player)

Correct. You're generating the display in real time so you cannot update all of the playfield in one routine, then run another routine for the players as it's too late because the entire screen's already been drawn.

  • Like 1

Share this post


Link to post
Share on other sites

Correct. You're generating the display in real time so you cannot update all of the playfield in one routine, then run another routine for the players as it's too late because the entire screen's already been drawn.

 

Exactly. Everything must be drawn at the same time, playfield, players, missiles, and ball. Some games like Asteroids drew all the asteroids on one frame, and the player on the next, only drawing one or the other. This causes flickering, which is not fun to look at, and should be avoided at all costs.

Share this post


Link to post
Share on other sites

Thanks JeremiahK, I will take a look into your code to see if it works.

I'm also going to take a look into the CollectMini on your tutorial SpiceWare, I think it has some stuff that I can learn from that, and it's less advanced then the actual tutorial itself, so it may be easier for me.

 

Thanks!

Share this post


Link to post
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.

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