News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: [Mario Bros Deluxe] [ASM] Coins won't increase anymore  (Read 984 times)

Kaffkas

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
[Mario Bros Deluxe] [ASM] Coins won't increase anymore
« on: July 21, 2019, 05:50:30 am »
I am currently trying to give a 1-Up when 50 Coins are collected, but the Coin counter doesn't increase anymore. Here's the original code that increases the Coin amount:
Code: [Select]
 
ld a, (C1F2)    #Loads the current Coins into a
inc a           #Increases Coins by 1

This is the code I came up with:

Code: [Select]
        ld a, (C1F2)    #Loads the Current coins into a
        jp 3A32         #Jumps to some free space


$3A32   cp a, 50        #Compare the Amount of Coins with 50
        jp nz, 3A3D     #Skips to  $3A3D
        inc a           #Increase the Coins by 1
        ld a, (C17F)    #Loads the Current Lives into a
        inc a           #Increases the Current Lives by 1
        ret             #Returns
$3A3D   inc a           #Increases the amount of Coins
        ret             #Returns


« Last Edit: July 21, 2019, 09:24:10 am by Kaffkas »

#

  • Full Member
  • ***
  • Posts: 147
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #1 on: July 21, 2019, 09:09:56 am »
-
« Last Edit: July 21, 2019, 03:20:46 pm by # »

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 111
  • Самый лысый ромхакер
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #2 on: July 21, 2019, 09:22:15 am »
You might wanna increase coins first and compare them afterwards, instead of increasing it here and there. It is also more correct because by the looks of it you get +1up when collecting 51th coin. And I'm pretty sure 50 in hexadecimal is not 50 in decimal.

And I don't know what platform this is, but maybe you also need to put A back into address after increasing it.
I am the baldest romhacker
NES Romhacking Guide

Kaffkas

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #3 on: July 21, 2019, 09:51:59 am »
And I don't know what platform this is,
It's the Game Boy Color Game, forgot to put it in the Title, sorry.

but maybe you also need to put A back into address after increasing it.

This gave me the Idea to jump back after the the Original Coin increase, and now it kind of works.
This is my code now:
Code: [Select]
         inc a
         cp a, 03
         jp nz, 3A3C
         ld a, (C17F)
         inc a
$3A3C    jp 2D7B

The problem with this is, when I have 2 Coins and collect a third one, the Amount of my current Lives -1 gets added to my coins, not giving me an 1-Up.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 111
  • Самый лысый ромхакер
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #4 on: July 21, 2019, 10:46:55 am »
I don't know gbc assembly. Sounds like you write code in some text file and hope it works. Use debugger and try to figure out your problem
I am the baldest romhacker
NES Romhacking Guide

danke

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 2057
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #5 on: July 21, 2019, 07:36:41 pm »
I am currently trying to give a 1-Up when 50 Coins are collected, but the Coin counter doesn't increase anymore. Here's the original code that increases the Coin amount:
Code: [Select]
 
ld a, (C1F2)    #Loads the current Coins into a
inc a           #Increases Coins by 1

This is the code I came up with:

Code: [Select]
        ld a, (C1F2)    #Loads the Current coins into a
        jp 3A32         #Jumps to some free space


$3A32   cp a, 50        #Compare the Amount of Coins with 50
        jp nz, 3A3D     #Skips to  $3A3D
        inc a           #Increase the Coins by 1
        ld a, (C17F)    #Loads the Current Lives into a
        inc a           #Increases the Current Lives by 1
        ret             #Returns
$3A3D   inc a           #Increases the amount of Coins
        ret             #Returns

Looks like your original code is missing some. We'd need to see more to see what your routine is missing.

Also, you're comparing it against 80 decimal/50 hex, not sure if the coins are stored in hex or decimal.

tvtoon

  • Sr. Member
  • ****
  • Posts: 359
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #6 on: July 21, 2019, 11:56:20 pm »
I didn't research this version, but knowing how others handle data, I think you are coming for a BCD digit or pixel mapping stuff. Not exact hexadecimal stuff, check the VRAM.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6883
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #7 on: July 27, 2019, 07:08:21 pm »
Also, after adding +1 to the lives count, are you storing it back to the lives counter?
And I presume you want to reset the number of coins collected to zero afterwards, don't you?

What you are doing is reading the lives count to the CPU register A, then increasing A. That does not affect the lives counter unless you write A back to the lives count. Is the part I think you are missing.
And you may also want to add a check for max number of lives, to avoid the problem the original NES version of the game had.
"My watch says 30 chickens" Google, 2018

Kaffkas

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #8 on: July 28, 2019, 10:08:24 am »
So, I took another look at it, and this is what I found out:

This is the original Coin Increase and 100 Coin Comparison:
Code: [Select]
2D75:    ld a, (C1F2) | Loads Coins into a
2D78:    inc a        | Increases Coins by 1
2D79:    cp a, 64     | Compares Lives with 100
2D7B:    jr nz, 2D82  | Jump to 2D82 when Coins are not equal to 100
2D7D:    call 2D4E    | This just loads the Lives into a and increases them
2D80:    ld a, 00     | Load 0 into a
2D82:    ld (C1F2), a | Sets the Coins to 0
2D85:    ret          | Returns


This is what I came up with now (I compare the Coins to 3 and 100):
Code: [Select]
2D75:   ld a, (C1F2)
2D78:   jp 3A51

3A51:   cp a, 03      | Compare Coins with 3
        jp nz, 2D82   | Jump to 2D82 when the Coins are not equal to 3
        jp z,  3A6B   | Jump to 3A6B when the Coins are equal to 3
        cp a,  64     | Compare Coins with 100
        jp nz, 2D82   | Jump to 2D82 when the Coins are not equal to 100
        jp z,  2D7D   | Jump to 2D7D when the Coins are equal to 100

3A6B:   call 2D4E
        jp 2D85

When I test this Line by Line with the BGB Debugger, it looks like it works as intended, but the Coins stop increasing at 2 and I get an 1-Up for every Coin I collect.
« Last Edit: July 28, 2019, 10:14:50 am by Kaffkas »

danke

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 2057
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #9 on: July 28, 2019, 01:43:54 pm »
Code: [Select]
cp a,  03
jp z,  3A6B
jp     2D82
cp a,  64
jp z,  2D7D
jp     2D82

Try that?

Kaffkas

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #10 on: July 28, 2019, 02:19:01 pm »
Code: [Select]
cp a,  03
jp z,  3A6B
jp     2D82
cp a,  64
jp z,  2D7D
jp     2D82

Try that?

Still the same Problem, it starts to Increase the Lives when I have 2 Coins.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 111
  • Самый лысый ромхакер
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #11 on: July 29, 2019, 06:41:17 am »
Like I told you before, you need to increase coins first and write them back so these problems won't occur if you don't know how to create conditions and don't mess up in a process. I recommend you to draw a diagram and follow it. Use this for example https://www.lucidchart.com

This is how a correct subroutine should look like:

Call $3A51 (or whatever) subroutine

($3A51) Load coins
Increase coins
Compare to 50 coins
Jump to (1) if true
Compare to 100 coins
Jump to (2) if false
Load 0 to A
(1) Call increase lifes subroutine (my guess is A is not used here, by the looks of original code from your post, despite what you wrote in a comment to this subroutine)
(2) Write coins
Return from $3A51

And this is a safe version in case first one is too complicated for you or if I misunderstood gbc assembly

($3A51) Load coins
Increase coins
Write coins
Load coins
Compare to 50 coins
Jump to (1) if true
Compare to 100 coins
Jump to (2) if false
Load 0 to A
Write coins
(1) Call increase lifes subroutine
(2) Return from $3A51

And don't forget to clean up original code afterwards
« Last Edit: July 29, 2019, 11:42:37 am by Cyneprepou4uk »
I am the baldest romhacker
NES Romhacking Guide

yugisokubodai

  • Full Member
  • ***
  • Posts: 143
    • View Profile
    • Assembly
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #12 on: August 03, 2019, 10:22:54 pm »
I am currently trying to give a 1-Up when 50 Coins are collected, but the Coin counter doesn't increase anymore. Here's the original code that increases the Coin amount:
Code: [Select]
 
ld a, (C1F2)    #Loads the current Coins into a
inc a           #Increases Coins by 1

This is the code I came up with:

Code: [Select]
        ld a, (C1F2)    #Loads the Current coins into a
        jp 3A32         #Jumps to some free space


$3A32   cp a, 50        #Compare the Amount of Coins with 50
        jp nz, 3A3D     #Skips to  $3A3D
        inc a           #Increase the Coins by 1
        ld a, (C17F)    #Loads the Current Lives into a
        inc a           #Increases the Current Lives by 1
        ret             #Returns
$3A3D   inc a           #Increases the amount of Coins
        ret             #Returns

You forgot to store life after increasing it.
You also forgot to reset the counter when it's 50.

Kaffkas

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: [Mario Bros Deluxe] [ASM] Coins won't increase anymore
« Reply #13 on: August 04, 2019, 06:23:12 am »
I've managed to make it work as I intended. Here's the Code:

Code: [Select]
3A51: inc a
      cp a, 32
      jp nz, 3A70
      call 2D54
      ld a, (C1F2)
      inc a
3A5E: ld (C1F2), a
      jp 2D85

3A70: cp a, 64
      jp z, 2D7B
      jp 3A5E
The problem was that I haven't used "ld (C1F2), a" to load the updated Coins back from a at the end, as Cyneprepou4uk told me.
I've also left the Original Code unchanged (except the jump to 3A51), since I wouldn't have to squeeze in the 100 Coin Comparison somewhere else.
Anyway, thanks for helping me getting this to work.