Jump to content
IGNORED

Random Emoticons


Recommended Posts

Hello!

image.png.c3da2be02411a7e20ce07a552e6810e4.png 

I wrote my first assembly code and would like to share it here. The temporary name is "Random Emoticons". It's like two smiley faces bumping into walls or each other like Pong, and each time they do so, their facial expressions change and a melody from "For Elise" is played. The one would be appeared on the left in the beginning is the player 0 and the directions to move are changeable with the joypad. This is more like an interactive art piece rather than a game, so there's not set any goals to achieve. *English is not my first language, so please ignore any mistakes!

 

A little bit more about it, it's my first code after completing the online lessons for assembly language by @Gustavo Pezzi on Udemy (PIKUMA), and I took on the challenge to see how much I could build on my own and practice. I am very happy that I have come to understand assembly eventually, so I'd like to thank Gustavo again. ***I swear this is not his ad! And his lessons, which teach us how to use debug mode with Stella, are highly recommended for beginners. About my code, I am surprised that I could achieve most of the functions I wanted to include, but there were still many difficulties, so I thought I would share it here and ask for your advice, please.

 

Below is a list of things that I'd like to improve or implement in the future.

  1. Is it possible to make the background gradient flip up and down in the middle of the screen in the current structure, so that would look like Tron's title screen? *The gradient display is based on 8bitworkshop.
  2. How to position them when they exceed 127? The decimals turn to -128 after 127, so not sure how to handle x and y positions more than 127.
  3. How to set the left edge of the screen to 0 in the x position? Even if I set the X position to 0, the left edge of the screen has a space. Is there a solution?
  4. Is there any way to randomize the initial location of these smileys in the current structure? I studied what's LFSR, but it seems it wouldn't be the one.
  5. Is there any way to make them react only once when the fire button is pressed and then ignore them till we release the button? The only way I could've tried is to stop the whole process until the button is released, which would stop the entire process and the screen would be glitched.
  6. Is there any way to make the melody sound better? I changed the way the melody sounds to something I can understand, based on this by @SpiceWare.
  7. Is there a way to check how much memory is left?
  8. I'd like to know some examples of how to use "Stack" function. It wasn't mentioned much in Gustavo's lessons. When and how can we use it?

 

If there are any other techniques that would help me to better optimize my code, please let me know!

 

Arigato,

Shinji

RandomEmoticons_230720.bin RandomEmoticons_230720.zip

  • Like 3
Link to comment
Share on other sites

Hi Shinji.

 

Regarding items 2, 3, 4, 7, and 8.
 

  • 2) With the 6502 processor, our values either are interpreted from 0 to 255 (unsigned), or -128 to 127 (signed). That's what we can store and represent with one register. But there are ways of representing larger numbers by grouping bytes together. You'll see many implementations use 2 bytes (a word) to split the number into HI-byte and LO-byte. By correctly using the carry flag and carrying the addition or borrowing the subtraction we can even perform ADC and SBC with these 16-bit numbers. So you can interpret the HI and LO bytes as a 16-bit number, allowing you to have a bigger range of values for your game. This is very common in NES programming, where the screen resolution, nametables, and tile numbers often are bigger than 255.
  • 3) There is a great forum post on horizontal positioning and how it relates to clock counts: https://forums.atariage.com/topic/308513-a-working-horizontal-positioning-routine/. I think it's worth going over and checking the routines that the forum users posted and recommend using.
  • 4) You can definitely randomize initial object positions using a simple LFSR routine. I use it all the time for random enemy start positions.
  • 5) Briefly, I like to reserve a byte in memory and store it as PrevButtons. If the current button press state that I just read is equal to the PrevButtons, I bypass the processing.
  • 7) For RAM, I usually can visually see it in Stella (from $80 to $FF) what's not being used. And if you're talking about ROM size, your .bin cart file size can tell you how far you are from 4K (or whatever cart size you are working with).
  • 8) One example of how the stack can be important is when we need to create a backup of important values that you might need again later. For example, the 6502 has only 3 registers, so if you know you'll need the current value of X later, but you need X again to perform some other computation, you can push the value of X to the stack (saving it for later), then you are free to use X for anything else you need, and once you're done you can pull the old value of X from the stack. I do this all the time in some subroutines, where I save the value of a register that I need into the stack, then I can use that register inside the subroutine as I want, and before I leave the subroutine I can simply restore the old value of the register by pulling it from the stack. I was almost sure we covered some examples of this in our course. :)

Sorry for the lack of code in my items. I just had a baby and it's hard to find time to properly address all these details. Hopefully the good people of the forum will be able to assist with more detailed answers.

  • Like 3
Link to comment
Share on other sites

Thank you so much for all the advice, @Gustavo Pezzi!

 

I realize that your lessons were the way much easier to understand with the videos, documents and samples. That means I am actually not confident that I am definitely understanding only those explanations of yours... I will try to see if I can somehow incorporate them into the code one by one, anyway.

 

Enjoy your family time with the baby :)

Link to comment
Share on other sites

  • 3 weeks later...

Thanks a lot to the help of @Gustavo Pezzi and @Dave C, I was able to solve problems 2 and 3. So now both sprites are reachable to the left and the right ends of the screen which is amazing to me. And also with the final version, Player0 and Player1 are both moveable with the joystick and pretty fun to play with someone to push and attack each other. 

 

I know my code is really newby quality, but I'm sharing the finished file here if someone can find it helpful.

 

RandomEmoticons_230809.zipRandomEmoticons_230809.bin

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