Link

Display Player Stats

Table of contents

  1. Introduction
  2. Override % Glyph With Partial Ankh
  3. Persist Current Cursor
  4. Display Stats for Particular Character
  5. Display Overall Party Attributes
    1. Display Food
    2. Display ???
    3. Branch For Gold vs Ship
    4. Display Gold
    5. Display Ship Strength
  6. Other Sub-Routines Used
  7. Zero Page Locations Used
  8. What Calls This

Introduction

This displays the player stats in the UI.

The vector call is to $0845.

0845  4C C3 10      JMP $10C3

But the actual routine is at $10C3.

Override % Glyph With Partial Ankh

As best I can tell, this initial bit of code overrides rows of the % glyph (at character code $25) with rows of the ankh glyph (at character code $2F) based on whether there are character slots filled or not.

We start by setting the $FE/$FF vector to point to game font.

10C3    A9 E4       LDA #$E4
10C5    85 FF       STA $FF
10C7    A9 00       LDA #$00
10C9    85 FE       STA $FE

We Loop over the party slots with slot number in X, starting with 0.

10CB    A2 00       LDX #$00

Load the first char of the character’s name and check if it’s zero (i.e. there’s no character in that slot)

10CD    BD 00 ED    LDA $ED00,X
10D0    F0 04       BEQ $10D6

If there IS a character, set A = 0 anyway and go to $10DA

10D2    A9 00       LDA #$00
10D4    F0 04       BEQ $10DA

But if there’s no character, load _FE[0x2F].

10D6    A0 2F       LDY #$2F
10D8    B1 FE       LDA ($FE),Y

So at this point A = 0 if there is a character in slot X otherwise A = _FE[0x2F].

Store this A in _FE[0x25].

10DA    A0 25       LDY #$25
10DC    91 FE       STA ($FE),Y

Now add 0x80 to $FE (the next row of the glyphs).

10DE    18          CLC
10DF    A5 FE       LDA $FE
10E1    69 80       ADC #$80
10E3    85 FE       STA $FE

Carry over to $FF if necessary.

10E5    90 02       BCC $10E9
10E7    E6 FF       INC $FF

Now on to next party character (if we’re not done with all 8 slots)

10E9    E8          INX
10EA    E0 08       CPX #$08
10EC    D0 DF       BNE $10CD

Persist Current Cursor

We call a routine to persist the current cursor. We’ll restore it at the end.

10EE    20 63 12    JSR $1263

Push whatever was in $D4 on to the stack so we can restore it later.

10F1    A5 D4       LDA $D4
10F3    48          PHA

We’re going to use $D4 for the character number we’re currently iterating over. $0F contains the party size so we’ll start by setting $D4 to that value and decrement to iterate over all characters in the party.

10F4    A5 0F       LDA $0F
10F6    85 D4       STA $D4

Display Stats for Particular Character

Now we’ll display the stats for the character in slot $D4.

$1002 is a routine that sets $FE/$FF to the character data vector for the character in the slot given by $D4.

The offsets used directly in this routine include:

  • 0x12 — player status (e.g. G or P or D)
  • 0x18 — most-significant digit (of three) of player health
  • 0x19 — lower two digits of player health

Note that $1002 uses $D4 directly so it’s not clear what the LDX is for. It’s not actually clear why $1002 is called here either as it will be called again before $FE/$FF are next accessed.

10F8    A6 D4       LDX $D4
10FA    20 02 10    JSR $1002

Set the cursor row ($CF) to be the character number (the first character is display on row 1 and so on).

10FD    A5 D4       LDA $D4
10FF    85 CF       STA $CF

Set the cursor column ($CE) to 0x18.

1101    A9 18       LDA #$18
1103    85 CE       STA $CE

Display the character number using a routine that outputs a single digit in the accumulator.

1105    A5 D4       LDA $D4
1107    20 8B 10    JSR $108B

Output the character ‘-‘.

110A    A9 AD       LDA #$AD
110C    20 A9 0F    JSR $0FA9

Call a subroutine to display the character’s name.

110F    20 4A 10    JSR $104A

Move cursor to column 0x23 (for the player health)

1112    A9 23       LDA #$23
1114    85 CE       STA $CE

Set up $FE/$FF to point to the right character data vector based on $D4.

1116    20 02 10    JSR $1002

Offset 0x18 into the character data vector is the most-significant digit (of three) of the character’s health. We start by displaying that.

1119    A0 18       LDY #$18
111B    B1 FE       LDA ($FE),Y
111D    20 8B 10    JSR $108B

Offset 0x19 then contains the next two digits (one digit per nibble).

1120    A0 19       LDY #$19
1122    B1 FE       LDA ($FE),Y
1124    20 7C 10    JSR $107C

Offset 0x12 into the character data vector is the player status (G for good, P for poisoned, D for dead, etc). We display that at the cursor.

1127    A0 12       LDY #$12
1129    B1 FE       LDA ($FE),Y
112B    20 A9 0F    JSR $0FA9

We now make an unusual call to a subroutine that handles whether a key has been pressed, and puts it into a buffer if so. I presume this is done at various spots in the code just so we don’t lose keypresses.

112E    20 0C 15    JSR $150C

We’re done with this character, so let’s decrement $D4 (the number of the current character we’re displaying). If we’re not yet at zero, we have another character to do so we’ll loop back.

1131    C6 D4       DEC $D4
1133    D0 C3       BNE $10F8

Display Overall Party Attributes

First of all, set (X, Y) = (0x18, 0x0A) to use for cursor position (text column, text row)

1135    A2 18       LDX #$18
1137    A0 0A       LDY #$0A

Overall party attributes are stored in a vector starting at $ED00 with offsets:

  • 0x10 — first two digits of food
  • 0x11 — next two digits of food
  • 0x13 — first two digits of gold
  • 0x14 — next two digits of gold

Display Food

Print “F:”

1139    20 81 0F    JSR $0F81
113C    C6 BA 00             "F:"

Display first two digits of food. Each nibble is a decimal digit so #$37 = decimal 37.

113F    A0 10       LDY #$10
1141    B9 00 ED    LDA $ED00,Y
1144    20 7C 10    JSR $107C

Display next two digits of food.

1147    A0 11       LDY #$11
1149    B9 00 ED    LDA $ED00,Y
114C    20 7C 10    JSR $107C

Display ???

Next display a space.

114F    A9 A0       LDA #$A0
1151    20 A9 0F    JSR $0FA9

and whatever character is in $C6.

1154    A5 C6       LDA $C6
1156    20 A9 0F    JSR $0FA9

Branch For Gold vs Ship

If the value in $0E is less than 0x14, we skip displaying gold and show ship strength instead (BCC after CMP branches on the accumlator being strictly less than the comparison operand).

1159    A5 0E       LDA $0E
115B    C9 14       CMP #$14
115D    90 1A       BCC $1179

Display Gold

Print “ G:”

115F    20 85 0F    JSR $0F85
1162    A0 C7 BA 00          " G:"

Display the first two digits of gold (party data vector [0x13]).

1166    A0 13       LDY #$13
1168    B9 00 ED    LDA $ED00,Y
116B    20 7C 10    JSR $107C

Display the next two digits of gold (party data vector [0x14]).

116E    A0 14       LDY #$14
1170    B9 00 ED    LDA $ED00,Y
1173    20 7C 10    JSR $107C

Skip displaying ship strength.

1176    4C 87 11    JMP $1187

Display Ship Strength

1179    20 85 0F    JSR $0F85
117C    A0 D3 C8 D0 BA 00    " SHP:"

Ship strength is a two-digit byte in $1B.

1182    A5 1B       LDA $1B
1184    20 7C 10    JSR $107C

We restore the previous value for $D4 we’d put on the stack.

1187    68          PLA
1188    85 D4       STA $D4

Finally we restore the saved cursor and return. This is a jump to tail-optimise. The RTS from this jumped-to routine will act as the return from this routine.

118A    4C 6E 12    JMP $126E

Other Sub-Routines Used

$0F81 — set the current cursor location to the X, Y index registers then display the following null-terminated string (as in $0F85)

$0F85 — display the following null-terminated string at the current cursor location

$0FA9 — display the single character in the accumulator at the current cursor location

$1002 — set up $FE/$FF to point to the right character data vector based on $D4

$104A — display name of character in slot $D4

$107C — display a decimal-encoded byte (one decimal digit per nibble) in the accumulator at the current cursor location

$108B — display a single digit in the accumulator at the current cursor location

$1263 — persist the current cursor location

$126E — restore the saved cursor location

$150C — process and buffer any keypress

Zero Page Locations Used

$0E — if < 0x14, we’re not on a ship

$0F — party size

$1B — ship strength

$C6 — ???

$CE — cursor location (column)

$CF — cursor location (row)

$D4 — variable used for iteration over character number

What Calls This

Many places in ULT4, three in LORD and one in SAVE.