Here is a code I wrote yesterday to check how many specified map16 tiles are in a level (not counting sublevels too). To be used with "LevelASM + INIT"'s INIT routine. The code is somewhat sloppy (I think) and increases the level fade-in time a bit. But I couldn't really find a way to improve this.
I/O:
In: $7E0000: 24-bit pointer to a table with specified map16 tiles.
In: $7E000E: 16-bit size of the table with specified map16 tiles, minus 2.
Out: $7E0006: 16-bit result of how many specified map16 tiles there are within the level. $06 = Low byte, $07 = high byte.
Here is an example usage, which counts the amount of map16 tiles $0000, $002B, $0130, $0132 and $0200 present in the level:
You could make a level where you have to collect every single coin without counting them yourself for example. No hardcoded blocks etc.
I/O:
In: $7E0000: 24-bit pointer to a table with specified map16 tiles.
In: $7E000E: 16-bit size of the table with specified map16 tiles, minus 2.
Out: $7E0006: 16-bit result of how many specified map16 tiles there are within the level. $06 = Low byte, $07 = high byte.
Here is an example usage, which counts the amount of map16 tiles $0000, $002B, $0130, $0132 and $0200 present in the level:
Code
CompareTable: dw $0000,$002B,$0130,$0132,$0200 .end levelinit105: Main: REP #$10 LDA.b #CompareTable STA $00 LDA.b #CompareTable>>8 STA $01 LDA.b #CompareTable>>16 STA $02 LDY.w #CompareTable_end-CompareTable-$02 STY $0E JSL Count LDY $06 STY $0EF9 SEP #$10 RTS Count: PHP SEP #$30 PHA PHY PHX STZ $06 STZ $07 REP #$10 LDX #$37FF Loop: SEP #$20 LDA $7FC800,x XBA LDA $7EC800,x REP #$20 LDY $0E InLoop: CMP [$00],y BNE SkipIn INC $06 SkipIn: DEY DEY BPL InLoop DEX BPL Loop SEP #$30 PLX PLY PLA PLP RTL
You could make a level where you have to collect every single coin without counting them yourself for example. No hardcoded blocks etc.