Jump to content
IGNORED

Clever way to display a two pixels high missil ?


Recommended Posts

Hi,

 

  Imagine you have the line counter in y register and the y position of a missile in ram (e.g. missile1_y at $80), what is you favorite code to display a two pixel high missile ? I haven't found a solution I am proud of yet and need to concentrate on other things :D

 

Edit : I say "favorite" because I do not have need for shorter code nor faster code for now, just wondering what solutions you find interesting / beautiful.

Edited by Windless
Link to comment
Share on other sites

I think we would need some more input for giving you a good answer here. E.g.

  • Is it a two or a single line kernel?
  • Do you have the line counter in a register?
  • Does it have space or speed optimized?
  • Or a good compromise of both?
  • ...
  • Like 1
Link to comment
Share on other sites

For my current kernel, it is a one line kernel with Y register as the line counter.

 

The development is very early (just testing an idea) so I don't have any space or speed problem yet, my question for now is rather "is there any code you use/know for this problem that you find elegant ?"

Link to comment
Share on other sites

Hmmm…untested and done on the fly. This assumes the stack is pointing to ENAM1.

 

Maybe…

   tya
   sec
   sbc missile1_y
   and #<~[H_MISSILE - 1]
   php


Similar routine is used in Basketball, Breakout, and/or Video Pinball?

 

Edit…in the original post I forgot to include the sec before the subtraction 🤦🏾‍♂️ I also wanted to use your variable name.

 

Also, keep in mind this works because H_MISSILE is a power of 2.

Edited by DEBRO
  • Thanks 1
Link to comment
Share on other sites

14 hours ago, DEBRO said:

Hmmm…untested and done on the fly. This assumes the stack is pointing to ENAM1.

 

Maybe…

   tya
   sbc missileVertPos
   and #<~[H_MISSILE - 1]
   php


Similar routine is used in Basketball, Breakout, and/or Video Pinball?

 

Similar routine in Medieval Mayhem.

 

; RAM

M0yEvenRow   ds 1
M1yEvenRow   ds 1
BLyEvenRow   ds 1

M0yOddRow    ds 1
M1yOddRow    ds 1
BLyOddRow    ds 1

...

; fireball routine

        ldx #2
.fireballLoop

...

        sta M0yEvenRow,x
        sta M0yOddRow,x
        and #1
        beq .decOdd
        dec M0yEvenRow,x
        .byte $2c ; skip dec odd
.decOdd
        dec M0yOddRow,x

...

        dex
        bpl .fireballLoop
        
        
; end of Vertical Blank - NOTE: cannot use JSR during kernel because of this

        ldx #ENABL          ; 2 11
        txs                 ; 2 13

; Kernel, even rows

        cpy BLyEvenRow    ; 3
        php               ; 3  6
        cpy M1yEvenRow    ; 3  9
        php               ; 3 12
        cpy M0yEvenRow    ; 3 15
        php               ; 3 18
        ldx #ENABL        ; 2 20
        txs               ; 2 22


; Kernel odd rows

        cpy BLyOddRow     ; 3  6
        php               ; 3  9
        cpy M1yOddRow     ; 3 12
        php               ; 3 15
        cpy M0yOddRow     ; 3 18
        php               ; 3 21
        ldx #ENABL        ; 2 24
        txs               ; 2 27


; start of Overscan, restore stack pointer

        ldx #$ff          ; init stack pointer so we can use JSR
        txs


 

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

This Medieval Mayhem blog entry* has a link to the Atari 2600 Advanced Programming Guide at MiniDig which contains a section on using the PHP trick for the missiles and ball. Lots of other useful info at MiniDig, so be sure to check it out.  

 

 

==============================================================
==============================================================
Showing Missiles/Ball using PHP
==============================================================
==============================================================

This trick is originally from Combat and is probably the most efficient way to 
display the missiles and/or ball.  This trick just requires that you don't use 
the stack during your kernal.  Recall that:

  ENABL = $1F
  ENAM1 = $1E
  ENAM0 = $1D

In this example I'll show how to use the trick for both missiles.  You can 
easily adapt it for the ball too.  To set the trick up, before your kernal save 
the stack pointer and set the top of the stack to ENAM1+1.

  tsx                    ; Transfer stack pointer to X
  stx SavedStackPointer  ; Store it in RAM
  ldx #ENAM1+1		
  txs                    ; Set the top of the stack to ENAM1+1

Now during the kernal you can compare your scanline counter to your missile 
position register and this will set the zero flag in the processor.  Then to 
enable/disable the missile for that scanline, just push the processor flags onto 
the stack.  The ENAxx registers use bit 1 to enable/disable which corresponds 
with the zero flag in the processor, so the enable/disable will be automatic.  
It takes few cycles and doesn't vary the number of cycles depending on the 
result like branching usually does.

  ; On each line of your the kernal...
  cpy MissilePos1        ; Assumes Y is your kernal line counter
  php
  cpy MissilePos0
  php

Then before you do it again, somewhere on each scanline you need to pull off the 
stack again using two PLA's or PLP's, or you can manually reset the stack 
pointer with ldx #ENAM1+1, txs.

After your kernal, restore the stack pointer:

  ldx SavedStackPointer
  txs

 

 

The comments in that blog entry cover how the PHP trick was expanded with the even/odd lines logic in order to double the height of the missiles and ball.

  • Thanks 1
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...