Hello Gentlemen, I would really like to get some help.
This is for people who like reverse engineering.
I am scratching my head over an old piece of assembler code and I just cannot figure it out completely.
What is the Code about?
It is related to the game "Mafia" and is about AI Movement.
I already had a post some long time ago: http://www.lemon64.com/forum/viewtopic.php?t=58978
Consider the blue ai. It wants to get near the red player. It can move left or right because there are two enemies.
The asm program mf-ml.prg is called to decide where the next enemy is (and I got the feeling it is not always the one that is nearest - but maybe I am wrong)
In the BASIC Line of Mafia you find this:
This code calls the mf-ml.prg loaded at adress CS which is $C000 and passes the row and column of the current ai (KP(S,F)) as parameters to the asm code.
The result of the asm code was saved into memory at UA(=167=$A7) and UA+1
based on this the ai decides where to move. And in this case it decided to move to the right:
The Ai looked for positions of enemies - the player and his gang.
Y and X are the Position of a found enemy as row and column.
Y can be -40 or 40 and X -1 or 1.
-40 means: enemy above current ai piece/player
+40 means: enemy below
-1 enemy to the left
+1 enemy to the right
Of course the AI could just use the main player as reference and forget about gang members of the player.
Preisfrage: What does the mf-ml.prg do?
Maybe the easy answer is that you can convert asm into BASIC..? No...? Dream on Kiddo?
What I know: The asm searches the screen for the value $C1. It goes through all lines of the visible screen and looks for $C1...
because this means the red piece is displayed there and so there is the enemy
see http://www.lemon64.com/forum/viewtopic.php?t=58978
How is it handled in the asm code if more than one $C1 is found?
I don't expect a whole answer.. some hints would be great!
Uncommented code is below as answer to this first post because of 10000 character limit
Commented code:
- C000 JSR $B7F1 ;get address into $14/$15 and integer in X, starts normally at $B7EB .. so why start later?
- C003 STX $AC ;$AC = column where ai currently is
- C005 JSR $B7F1
- C008 STX $AD ;$AD = row where ai currently is
- It starts by putting both passed parameters on the stack?
- SYS CR, KP(S,F)-40*Y, Y
- Parameter 1: KP(S,F)-40*Y
- Parameter 2: Y
- Param 1 and 2: current position of ai
- C00A LDA #$00 ;bei 0
- C00C STA $A7
- C00E LDX #$0C
- C010 LDY #$27
- C012 JSR $E9F0 ;fetch screen addresses - Set Pointer to Screen Address of Start of Line because we search the screen
- C015 JSR $EA24 ; Synchronize Color RAM Pointer to Screen Line Pointer
- C018 LDA ($D1),Y ;first run $A0 in ACC - because map km.prg starts with a gray wall that has the value $A0, later this
- ;later is is $20 which is free space
- ;if a red figure is found it evaluates to $C1
- C01A CMP #$C1 ;$C1 is a red figure, if this is found the ai found an enemy