Jump to content
IGNORED

Counting CPU cycles and RAM usage


Recommended Posts

Hello again!  Another n00b here with likely n00bish questions.  Does the Stella debugger count up the CPU cycles per scan line automatically and display them somewhere?  I'm trying to understand why some changes I make to Pitfall don't work and was curious if there is a way to count up CPU cycles other than literally going through the ASM disassembly code for the screen you're currently on and picking the appropriate currently used parts/subroutines?  

 

The second question is regarding how to count up used RAM.  I know the Stella debugger has a tool where it shows the entire RAM layout that I think turns red when the value changes but I was curious if there was a full count accessible somewhere.  I'm used a muted B&W palette on my hack so I may be able to free up some ROM for future potential changes/improvements but wasn't sure if there was an easy way to track it all.  I'm used assembly language via tweaking the disassembled code and not bB for the moment.

 

Thanks in advance for any help!

Edited by LatchKeyKid
Link to comment
Share on other sites

The Stella Debugger page covers using the debugger.

 

When single-stepping thru the code you can see:

  • red = TIA's current position on scanline
  • green = cycle count so far for current scanline
  • blue = next instruction to be executed

 

576513398_ScreenShot2022-06-14at10_30_50AM.thumb.png.767754a538ba1189e9ef05ce762542c0.png

 

 

To determine unused RAM I usually put an ECHO statement in the source code.

 

        SEG.U VARS
        ORG $80
        
EarlyHMjmp      ds 2
ScoreKernelCounter ds 1
Mode ds 1       ; 0 = menu, 1 = game, $80 = easter egg
EEframe ds 1;
Sleep5  ds 1    ; dec Sleep5 instead of SLEEP 5
TitlePosition:  ds 1    ; 0 = $30, $80 = $40

...

 echo "----",($00FE - *) , "bytes of RAM left"
; $FE - $FF 2 byte stack (used by JSR)
; temp variables in STACK RAM
; no JSRs can be called when these are used
SRtemp1 EQU $FE
SRtemp2 EQU $FF

 

The $00FE means JSR only goes down 1 level - ie a subroutine never uses JSR itself.

If your subroutines also JSR to another subroutine then change it to $00FC.

If those subroutines JSR to another subroutine change it to $00FA, and so on.

 

 

  • Like 3
Link to comment
Share on other sites

Thanks!  That's alot more detailed than the debugger window explanation I found (which admittedly wasn't on the github page).  That definitely shows me the info I need!

 

For your echo statement, that's in assembly, correct?  Do I put the whole code quote (minus the ...) into the assembly code or just the second half that starts with the "echo" statement?  Do I have to put it in the main kernel for example or can it go anywhere?  I'm really new to this all trying to make sense of it after reading some webpages and watching youtube videos (the sum total of my programming knowledge at this point).

Edited by LatchKeyKid
Link to comment
Share on other sites

1 hour ago, LatchKeyKid said:

For your echo statement, that's in assembly, correct? 

 

Correct, you'll see the output when you compile the project.

 

1 hour ago, LatchKeyKid said:

Do I put the whole code quote (minus the ...) into the assembly code or just the second half that starts with the "echo" statement?

 

Just need to put this line after all of the RAM definitions and adjust the value of FE based on how many nested levels of JSR can occur.

 echo "----",($00FE - *) , "bytes of RAM left"

 

For Pitfall that'd be just before the MACROS comment:

 

;===============================================================================
; Z P - V A R I A B L E S
;===============================================================================

    SEG.U   Variables
    ORG     $80

livesPat            .byte   ;           number of lives, stored as displayed pattern ($a0 = 3, $80 = 2, $00 = 1)
random              .byte   ;           all scenes are generated randomly with this
random2             .byte   ;           used for random object animation
joystick            .byte   ;           stores joystick directions
...
jumpMode            .byte   ; = $f5     similar to jumpIndex (JTZ: superfluous?)
temp1               .byte
temp2               .byte
temp3               .byte

 echo "----",($00FE - *) , "bytes of RAM left"

;===============================================================================
; M A C R O S
;===============================================================================

  MAC FILL_NOP
    IF FILL_OPT
      REPEAT {1}
         NOP
      REPEND
    ENDIF
  ENDM

 

  • Like 1
Link to comment
Share on other sites

Thanks again.  I tried a quick entry and it gave me an unknown mnemonic error with a few ratches down for JSR (ctrl-F finds it 21 times with 13 unique calls when repeats are taken out by my count... I don't know how many are nested but will have to check tonight).  Coding is definitely more difficult even with a hack than I had anticipated.  Changing sprites and colors turned out to be mostly copy paste fun but stuff that I thought would also be simple like adding a walking sound or intro/outro tune and changing the broken up ladder to a knotted vine have turned out to be way beyond my capabilities.  I'm starting to think that it might be "easier" to learn and remake the game in bBatari rather than tweak the assembly.

Link to comment
Share on other sites

28 minutes ago, alex_79 said:

Did you to put at least a space or tab character before "echo", like in @SpiceWare example? Only labels can start at the beginning of the line.

 

I most certainly did NOT but that did the trick.  5 bytes to play with!  I didn't catch that in the post and just lined it up with the labels above.  That's indicative of my incredibly poor (lack of) knowledge base I was referring to in the previous post.  I'm humble enough to admit that, like Jon Snow, I know nuthin.

31 minutes ago, orange808 said:

That sounds tricky, because you really want to hit the motion register on every line to draw vines. No bB kernel for that.

I was able to figure out how to change the size of the ball from the quad that the ladder uses to other sizes but I'd also need to

 

1) make it appear every scanline instead of repeating with gaps

2) shift it to the center of where the player sprite climbs as a baseline and then code a static vertical minor left right wave pattern  (no fancy motion... just a minimally static but swayed vine with "leaves")

3) also alternate in a pattern knots by shifting the size from a base width of one to two

 

I run into issues like the Stella debugger saying on scanlines where the ladder is that the ball is size 2 but I thought it is coded as quad pixel width based on the assembly (#%100101).  I assumed 0 in the stella debugger is not-present (as it turns to zero when off) and 1 for one pixed, 2 for double, etc.

 

I'm sure from the various sigs here of accomplished programmers that these issues are trivial but to the uninitiated they're quite daunting.  That's why I'm wondering if I'm better off instead trying to learn how to code Pitfall in bB instead of tweaking the assembly.

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