Count Object Type 4.5.9

baardbi

Well-known member
In NESmaker there's a great macro that lets you count objects with a certain object flag set. However this does not work if you want to count certain objects without an object flag set or just a certain object type. I made a new modified macro based on the default one in NESmaker. It counts a certain object type (number). This could be useful if you have different player weapon objects but you only want to count one of them.

To use this macro, just copy this code into a new file and call it CountObjectType.asm. Then put that file in the Macros folder: ...\GameEngineData\Routines\BASE_4_5\System\Macros

MACRO CountObjectType arg0
;; arg0 - what object type (number) are we talking about (what objects are we counting?)
LDA arg0
STA tempA
TXA
PHA
TYA
PHA

LDA #$00
STA temp
LDX #$00
countObjectLoop:
LDA Object_status,x
AND #%10000000
BEQ +skipCountingThisObject
LDA Object_type,x
CMP tempA
BNE +skipCountingThisObject
INC temp
+skipCountingThisObject
INX
CPX #TOTAL_MAX_OBJECTS
BNE countObjectLoop


PLA
TAY
PLA
TAX
LDA temp ;; now the accumulator holds the number of that type of object still activated.
ENDM

Example:

CountObjectType #10 ;;; Bomb
CMP #2
BEQ +doThis
JMP +dontDoThis
+doThis

Object numbers start from 0 at the top (player object) then continues down. The first monster object is object 16, then second monster is 17 and so on.
objects.PNG
 

Dietz33

Member
it says CountObjectType #10 ;;; Bomb
why not CountObjectType #0A ;;; Bomb ?? or am i missing something ?
Also getting error , Invalid Instruction
 
Last edited:

baardbi

Well-known member
it says CountObjectType #10 ;;; Bomb
why not CountObjectType #0A ;;; Bomb ?? or am i missing something ?
Also getting error , Invalid Instruction
You can use decimal, hexadecimal or binary whenever you want. The code doesn't care. But yes, $0A is 10 in decimal number format. So you can use both (only one at a time of course). Did you do the macro tutorial I linked in the previous post? You must do that or else NESmaker won't know about the CountObjectType macro.

Can you share the input script here?
 

Dietz33

Member
You can use decimal, hexadecimal or binary whenever you want. The code doesn't care. But yes, $0A is 10 in decimal number format. So you can use both (only one at a time of course). Did you do the macro tutorial I linked in the previous post? You must do that or else NESmaker won't know about the CountObjectType macro.

Can you share the input script here?
you are still awake ? :) yeah i saved your macros in the correct folder and call it inside your input script:
 

Attachments

  • macro1.png
    macro1.png
    7 KB · Views: 9
  • macro2.png
    macro2.png
    25.7 KB · Views: 7
  • macro3.png
    macro3.png
    14.6 KB · Views: 9

baardbi

Well-known member
you are still awake ? :) yeah i saved your macros in the correct folder and call it inside your input script:
In the second picture (macro2.png) it says CountObjectsType... It should be CountObjectType (no s in objects).
 
Top Bottom