Flying Notes and Bytes Oh My!

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
Scorpion Illuminati
Interested
Posts: 28
Joined: Fri Oct 02, 2015 4:58 pm

Flying Notes and Bytes Oh My!

Post by Scorpion Illuminati » Tue Nov 17, 2015 10:40 pm

Hi guys,

Been having a bit of trouble converting a small bit of code to use less ram and am getting a very strange effect.

Changing this:

Code: Select all

 ; ************************************
      ; initialize everything
      ; ************************************
      move.w #1, (tempo)                                                       ; initialize tempo
      move.w #note_start_position_y, (greennote_position_y)                    ; Set green note's y position
      move.w #note_start_position_y, (rednote_position_y)                      ; Set red note's y position
      move.w #note_start_position_y, (yellownote_position_y)                   ; Set yellow note's y position
      move.w #rockindicator_start_position_x, (rockindicator_position_x)       ; Set rock indicator's x position

      ; ******************************************************************
      ; Main game loop
      ; ******************************************************************
GameLoop:

      ; green note movement code
      move.w (greennote_position_y), d0                                        ; green note y position in d0
      add.w (tempo), d0                                                        ; add the tempo
      cmp.w  #(note_plane_border_offset-note_bounds_bottom), d0                ; does the player miss the note entirely
      blt @GreenNoteNotWithinBounds                                            ; branch if the player hasn't
      move.w #note_start_position_y, d0                                        ; otherwise the player has so move the note back to the top
@GreenNoteNotWithinBounds:
      move.w d0, (greennote_position_y)                                        ; set the green note's position normally

      ; red note movement code
      move.w (rednote_position_y), d0                                          ; red note y position in d0
      add.w (tempo), d0                                                        ; add the tempo
      cmp.w  #(note_plane_border_offset-note_bounds_bottom), d0                ; does the player miss the note entirely
      blt @RedNoteNotWithinBounds                                              ; branch if the player hasn't
      move.w #note_start_position_y, d0                                        ; otherwise the player has so move the note back to the top
@RedNoteNotWithinBounds:
      move.w d0, (rednote_position_y)                                        ; set the red note's position normally

      ; yellow note movement code
      move.w (yellownote_position_y), d0                                       ; yellow note y position in d0
      add.w (tempo), d0                                                        ; add the tempo
      cmp.w  #(note_plane_border_offset-note_bounds_bottom), d0                ; does the player miss the note entirely
      blt @YellowNoteNotWithinBounds                                           ; branch if the player hasn't
      move.w #note_start_position_y, d0                                        ; otherwise the player has so move the note back to the top
@YellowNoteNotWithinBounds:
      move.w d0, (yellownote_position_y)                                       ; set the yellow note's position normally
To this:

Code: Select all

 ; ************************************
      ; initialize everything
      ; ************************************
      move.b #1, (tempo)                                                       ; initialize tempo
      move.w #note_start_position_y, (greennote_position_y)                    ; Set green note's y position
      move.w #note_start_position_y, (rednote_position_y)                      ; Set red note's y position
      move.w #note_start_position_y, (yellownote_position_y)                   ; Set yellow note's y position
      move.w #rockindicator_start_position_x, (rockindicator_position_x)       ; Set rock indicator's x position

      ; ******************************************************************
      ; Main game loop
      ; ******************************************************************
GameLoop:

      ; green note movement code
      move.w (greennote_position_y), d0                                        ; green note y position in d0
      add.b (tempo), d0                                                        ; add the tempo
      cmp.w  #(note_plane_border_offset-note_bounds_bottom), d0                ; does the player miss the note entirely
      blt @GreenNoteNotWithinBounds                                            ; branch if the player hasn't
      move.w #note_start_position_y, d0                                        ; otherwise the player has so move the note back to the top
@GreenNoteNotWithinBounds:
      move.w d0, (greennote_position_y)                                        ; set the green note's position normally

      ; red note movement code
      move.w (rednote_position_y), d0                                          ; red note y position in d0
      add.b (tempo), d0                                                        ; add the tempo
      cmp.w  #(note_plane_border_offset-note_bounds_bottom), d0                ; does the player miss the note entirely
      blt @RedNoteNotWithinBounds                                              ; branch if the player hasn't
      move.w #note_start_position_y, d0                                        ; otherwise the player has so move the note back to the top
@RedNoteNotWithinBounds:
      move.w d0, (rednote_position_y)                                        ; set the red note's position normally

      ; yellow note movement code
      move.w (yellownote_position_y), d0                                       ; yellow note y position in d0
      add.b (tempo), d0                                                        ; add the tempo
      cmp.w  #(note_plane_border_offset-note_bounds_bottom), d0                ; does the player miss the note entirely
      blt @YellowNoteNotWithinBounds                                           ; branch if the player hasn't
      move.w #note_start_position_y, d0                                        ; otherwise the player has so move the note back to the top
@YellowNoteNotWithinBounds:
      move.w d0, (yellownote_position_y)                                       ; set the yellow note's position normally
Causes the notes to gain super speed for some reason. Changing just the initiation code stops it from moving. I'm very new to 68k assembly so i'm gonna chalk it up to a newbie mistake. Any assistance in this matter would be greatly appreciated.

Sincerely,

Scorpion Illuminati
Scorpion Illuminati - An open source rhythm game for the Sega Genesis
http://www.scorpionilluminati.tk

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Flying Notes and Bytes Oh My!

Post by Sik » Wed Nov 18, 2015 2:46 am

ADD.B will only touch the lower byte, but the value you're trying to modify is a word (two bytes)... yeah, not going to fare well. I'd say to just keep tempo as a word and be done with it.

Any reason to optimize this? I mean, the original code seems to be using 10 bytes when you have 65536 worth of them... Look elsewhere to optimize RAM usage. If needed, chances are you aren't touching that much memory in the first place. (Project MD needs like 5KB+stack worth of RAM outside decompression, and it's not exactly very optimized since lots of values are 32-bit)

EDIT: OK nevermind I see you have some sort of buffer around? Still, you're optimizing the wrong value! =P (and first check how much RAM are you actually using, unless you're close to running out it's not worth the effort)
Sik is pronounced as "seek", not as "sick".

Post Reply