Prev: DEF9 Up: Map Next: DFBC
DF33: Print spell names on the scroll
Used by the routines at E641 and E699.
Checks each spell in the spell index at 6DFC, to see if Maroc has it.
For each spell found (up to 5), prints the spell name text on the scroll, and plays a short sound effect.
scroll spell example
DF33 LD A,($EAE2) Spell list index
DF36 LD ($EAE5),A Copy spell list index into spell list counter
DF39 LD DE,($EAE3) Address pointer to the start of spell list text at 6DFC
DF3D LD A,$01 Scroll text line counter (1-5)
DF3F LD ($EAC7),A
DF42 LD HL,$504A Screen address of top text line of scroll, 3 characters from the left hand side
DF45 LD ($EADE),HL Put screen display address in temp store for retrieving later
DF48 LD B,$08 Move address pointer along 8 bytes to get to the first/next spell text (e.g. "MOVE" at 6E04)
DF4A INC DE
DF4B DJNZ $DF4A
DF4D LD ($EAA1),DE Store spell text address pointer
DF51 LD ($EAA4),HL Store the screen display address
DF54 LD A,$08 Store length of text string to print - spell texts at 6DFC are padded with spaces to make them all 8 characters long
DF56 LD ($EAA3),A
DF59 CALL $E2E0 Print the spell text on the scroll
DF5C LD HL,($EAA1) Retrieve the spell text address pointer - this is now pointing at the data after the spell text, e.g. 6E0C.
This section runs through each spell and checks to see if the player has collected it. If so, the text can be printed on the scroll.
Five spells are always displayed on the scroll in a wraparound vertical scrolling list. If the player has fewer than five spells, one or more will show at least once.
At the start of the game the player only has the 'MOVE' spell, so this appears five times.
DF5F LD A,($EB69) Total number of spells to check - 27
DF62 LD C,A
DF63 LD A,($EAE5) Spell list counter
DF66 CP C Check if at the end (spell #27)
DF67 JR NZ,$DF70
DF69 LD A,$00 If so, reset counter to zero...
DF6B LD HL,($EB65) ...and return the spell name text address pointer to the start of the list, e.g. 6DFC.
DF6E JR $DF71
DF70 INC A If we're not at the end of the list, increment the spell list counter.
DF71 LD ($EAE5),A
DF74 LD A,(HL) Get the the first byte (after the spell name).
DF75 CP $10 Check if this byte = 16, which indicates the player has collected the spell
DF77 JR Z,$DF7F If so, jump out and print the spell name
DF79 LD BC,$0010 The player hasn't collected this spell, so move the spell text address pointer along 16 bytes to the next spell and repeat the checking loop.
DF7C ADD HL,BC
DF7D JR $DF5F
Spell name to print found (Maroc has this spell).
First, play a short sound as the player scrolls through the spell list:
DF7F OUT ($FE),A The 'A' register is 16 from previous routine (bit 4 is set), so it's used here to switch the speaker on
DF81 LD A,($EAA6) Counter (initialized at 5) which is used to determine an incremental series of 5 tones, while the player holds down a key to scroll through the spell list
DF84 CP $00 Counter = 0?
DF86 JR Z,$DF95 If so, skip next routine (this keeps the tone at its highest pitch)
DF88 RLA Take counter and x 2
DF89 RLA 5 rotates to shift bits 0-2 of the counter into bits 5-7
DF8A RLA
DF8B RLA
DF8C RLA
DF8D AND $E0 Filter out unwanted bits 0-4
DF8F LD B,A Store in B to act as a second counter
DF90 CALL $DB06 Routine that generates a pseudo-random number.
DF93 DJNZ $DF90 ...The output from the CALLed routine isn't used, it's just called multiple times to provide a handy short delay for the speaker toggle effect/sound.
Spell text line print checks
DF95 LD A,($EAC7) Continue to check the spell index (at 6DFC) to see which spells Maroc has, and print them on the scroll
DF98 CP $05 5 spells can be printed on the scroll. Have they all been done?
DF9A JR Z,$DFBB If so, jump straight to RET at the end of this routine
DF9C INC A Otherwise, increment the scroll text line counter
DF9D LD ($EAC7),A ...and re-store.
DFA0 CP $03 Are we on spell text line number 3?
DFA2 JR NZ,$DFAD
DFA4 LD A,($EAE5) If so, this is the spell in the middle of the scroll, that the selection arrow is pointing at
DFA7 LD ($EAE6),A So set the 'currently highlighted' spell as this one
DFAA LD ($EAE7),HL ...and also store the address pointer to this spell's data (6DFC).
Prep for printing next line of text:
DFAD EX DE,HL Put the current spell index list address pointer into the DE register, ready for checking/printing any other spells the Maroc might have (from DF45)
DFAE LD HL,($EADE) Retrieve the screen display address
DFB1 LD BC,$0120 Move the screen display address down 9 pixels ready for the next line of spell text. 288 is 256 (one pixel line down) plus 32 (8 pixel lines down).
DFB4 ADD HL,BC
DFB5 LD A,$00 Toggle speaker (bit 4) off
DFB7 OUT ($FE),A
DFB9 JR $DF45 Keep checking for spells to print
DFBB RET RETurn after 5 spells printed
Prev: DEF9 Up: Map Next: DFBC