Jump to content

Cycles Depending on Bank


Recommended Posts

I was playing around with expanding my game from 8k to 16k as a test.


I had moved my "inline 6lives_statusbar.asm" to the last bank (bank 4 as opposed to the previous bank 2). I made no other changes to the code.


When I ran in Stella, the game worked but I noticed the cycles would jump more. I was wondering if certain things use more cycles depending on which bank or how many banks you use.

Link to comment
Share on other sites

I think SpiceWare's guess is the only likely explanation. The last bank contains the display kernel, which is why a minikernel needs to go there as well. Before, bank 2 had the display kernel, the minikernel, and all of the other code you had in that bank. Now bank 4 has the display kernel and minikernel, but the bank 2 code hasn't been moved, so your code and data are probably aligned differently. 


You could test this if you want by moving all of your bank 2 code and data to bank 4 to see if it goes back to normal. 


Really though if shifting code like this is causing you to run out of cycles,  a better solution is needed. I would recommend some tasks that don't have to run every single frame, and split them up to run on different frames. 


Also, if you aren't already doing so, try putting some stuff that you are doing in your main loop into vblank instead to free up more cycles. 

Link to comment
Share on other sites

Just now, Karl G said:

Also, it may not be clear that this is a bB question since it was not posted in that subforum, which might cause some confusion. 

I suppose I should have specified that it was bB but I really do appreciate the explanation, as I want to understand more than the dos and donts of bB.  Based off what I had seen, reading the explanation of page crossing makes sense. I was tempted to move bank 2 into bank 4 to see if the issue persists but I agree a better solution is needed.


I had noticed that I get an occasional 263 cycles normally that I have been working on an moving code to after the vblank sounds like it could work.


Implementation of vblank in bB had confused me so I will definitely look into that . I assume I would have to put some code after drawscreen and that would basically take that out of using cycles?

Link to comment
Share on other sites

Whatever code you put in the vblank "function" automatically gets run every frame. You don't call it from anywhere in your code. It gets run from the last bank, so any data tables you reference have to be there, too, although there's nothing preventing you from bankswitching if you need to, so long as you return. 


bB code runs in the overscan time slice. It uses the vblank time slice for housekeeping tasks like positioning sprites and such, but there are still a fair number of unused cycles in vblank. If you move  code to vblank, that code uses the free cycles in the vblank time slice, freeing up cycles from the normal overscan time slice where the rest of your code runs. 

Link to comment
Share on other sites

Thank you very much. I will read up on both the bB process and the 6502 tutorials. I think I have an idea on what to do to. I would imagine that if the cycles are only jumping 3 or 4 and never really above that, the moves would be minimal... 

Link to comment
Share on other sites

So I moved all of bank 2 to bank 4 and the issue stopped. I still have an occasional 263 cycles and while I don't get any screen rolls or jumps on hardware, I still want to try and rectify this so I will look into vblank.   I had tried playing around with vblank, seeing that it took up about 20 bytes, I wasn't able to get things to work since I barely had any space so now I started to moving things around since I have 2 free banks so that I can try using that.


I did move a segment of code that didn't seem to interfere with the cycle issue and moved it to the vblank just as a test and it did eliminate the issue so there is hope!


Thank you again for the explanations.  I do find the underlying cause very interesting and hope to learn more as I progress.  

Edited by KevKelley
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.

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.

  • Recently Browsing   0 members

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