Prev: 89EF Up: Map Next: 8F8B
89F9: The main game routine.
Used by the routine at start.
main_routine 89F9 XOR A Set border to black.
89FA OUT ($FE),A
89FC LD ($5C8F),A Set ATTR-T to black.
89FF LD ($5C8D),A Set ATTR-P to black.
8A02 LD A,$FF Set MASK-P to all transparent.
8A04 LD ($5C8E),A
8A07 LD A,$03 Set P-FLAGS to 3 (OVER mode).
8A09 LD ($5C91),A
8A0C DI Disable interrupts.
8A0D CALL CLS Clear the screen.
8A10 LD HL,unknown_table_3 Zero out unknown_table_3, unknown_table_4, WIZCON, computer_player_flag, LAC2F, unknown29, unknown30, unknown31, unknown32, num_dead_wizards, and unknown34.
8A13 LD DE,$AC17
8A16 LD (HL),$00
8A18 LD BC,$001F
8A1B LDIR
8A1D LD HL,possesssed_spell_tables Zero out possesssed_spell_tables.
8A20 LD DE,$7F48
8A23 LD (HL),$00
8A25 LD BC,$013F
8A28 LDIR
8A2A LD HL,map_object_table Zero out map_object_table.
8A2D LD DE,$E020
8A30 LD (HL),$00
8A32 LD BC,$009F
8A35 LDIR
8A37 LD HL,map_animation_timeout_table Zero out map_animation_timeout_table, map_animation_frame_table, map_object_properties_table, fifth_map_table, and sixth_map_table.
8A3A LD DE,$E0C1
8A3D LD (HL),$00
8A3F LD BC,$031F
8A42 LDIR
8A44 LD A,$00 Set CH_LAW to zero.
8A46 LD (CH_LAW),A
8A49 LD A,$5A Set ATTR-T to $5A (bright red on magenta) and draw border.
8A4B LD ($5C8F),A
8A4E CALL ZRDR_P
8A51 LD A,$43 Set ATTR-T to $43 (bright magenta on black).
8A53 LD ($5C8F),A
8A56 LD BC,$0202 Print message M_1 at coordinates (2,2).
8A59 LD A,$00
8A5B CALL M2PRIN
8A5E LD A,$42 Set ATTR-T to $42 (bright red on black).
8A60 LD ($5C8F),A
8A63 LD BC,$0408 Print message M_2 at coordinates (8,4).
8A66 LD A,$01
8A68 CALL M2PRIN
8A6B LD A,$46 Set ATTR-T to $46 (bright yellow on black).
8A6D LD ($5C8F),A
8A70 LD BC,$0902 Print message M_3 at coordinates (2,9).
8A73 LD A,$02
8A75 CALL M2PRIN
8A78 LD A,$44 Set ATTR-T to $44 (bright green on black).
8A7A LD ($5C8F),A
8A7D LD BC,$0B02 Print message M_15 at coordinates (2,11).
8A80 LD A,$0E
8A82 CALL M2PRIN
8A85 LD BC,$0914 Set BC to coordinates (20,9).
8A88 LD A,$01 Set the flag to prevent numbers less than 2 in input.
8A8A LD (no_less_than_2_flag),A
8A8D CALL CHONUM Get number input from 2 to 8. This also appends 4 semi-random bytes to INBUF. When the game is loaded BUFPNT is pointing at the fourth byte in the buffer.
8A90 INC A Increment the number input and store in NO_PLA.
8A91 LD (NO_PLA),A
8A94 LD A,$46 Set ATTR-T to $46 (bright yellow on black).
8A96 LD ($5C8F),A
8A99 LD BC,$0E02 Print message M_9 at coordinates (2,14).
8A9C LD A,$08
8A9E CALL M2PRIN
8AA1 LD A,$43 Set ATTR-T to $43 (bright magenta on black).
8AA3 LD ($5C8F),A
8AA6 LD BC,$1002 Print message M_4 at coordinates (2,16).
8AA9 LD A,$03
8AAB CALL M2PRIN
8AAE LD BC,$0E1D Set coordinates (29,14) and get number input from 1 to 8. This also appends 4 semi-random bytes to INBUF.
8AB1 CALL CHONUM
8AB4 LD (LEVEL),A Store input in LEVEL.
8AB7 SLA A Multiply level by four and add fifteen.
8AB9 SLA A
8ABB ADD A,$0F
8ABD LD (GAMTUN),A Store the result in GAMTUN.
8AC0 LD B,$0A Set B to ten as a loop counter.
REPWAT 8AC2 PUSH BC Call PAUSER ten times to delay for approximately 1.5 seconds.
8AC3 CALL PAUSER
8AC6 POP BC
8AC7 DJNZ REPWAT
8AC9 LD A,$00 Set current_player to zero.
8ACB LD (current_player),A
8ACE LD A,(NO_PLA) Get NO_PLA into B as loop counter.
8AD1 LD B,A
8AD2 LD HL,INBUF Reset BUFPNT to beginning of INBUF. As each user makes selections at the following prompts, semi-random bytes are stored in INBUF. This is then used a source of randomness when assigning spells. The bytes generated above are overwritten.
8AD5 LD (BUFPNT),HL
This is the wizard creation loop where the user enters the wizard name, whether it is a human or computer player, and selects the appearance. The wizard's attributes are then generated randomly.
STALOO 8AD8 PUSH BC Preserve loop counter.
8AD9 CALL CLS Clear the screen.
8ADC LD A,$69 Set ATTR-T to $69 (bright blue on cyan) and draw border.
8ADE LD ($5C8F),A
8AE1 CALL ZRDR_P
8AE4 LD BC,$0202 Set ATTR-T to $46 (bright yellow on black) and print message M_5 at coordinates (2,2).
8AE7 LD A,$46
8AE9 LD ($5C8F),A
8AEC LD A,$04
8AEE CALL M2PRIN
8AF1 LD A,(current_player) Print current player number.
8AF4 ADD A,$31
8AF6 CALL DH_P
8AF9 LD A,$43 Set ATTR-T to $43 (bright magenta on black) and print message M_10 at coordinates (2,4).
8AFB LD ($5C8F),A
8AFE LD BC,$0402
8B01 LD A,$09
8B03 CALL M2PRIN
8B06 CALL get_wizard_object Get address of wizard object data for current player.
8B09 LD A,$00 Set string_length to zero.
8B0B LD (string_length),A
8B0E LD HL,$0602 Set POSPRI to coordinates (2,6) and set ATTR-T to $45 (bright cyan on black).
8B11 LD (POSPRI),HL
8B14 LD A,$45
8B16 LD ($5C8F),A
INPLOO 8B19 CALL $02BF Call KEYBOARD in Spectrum ROM.
8B1C LD (KEY_P),A Store keypress in KEY_P.
8B1F CP $0D If key is 'enter' jump to ENTER.
8B21 JP Z,ENTER
8B24 CP $0C If key is not 'delete' jump to NO_DEL.
8B26 JR NZ,NO_DEL
8B28 LD A,(string_length) If string_length is zero jump back to INPLOO.
8B2B OR A
8B2C JR Z,INPLOO
8B2E LD BC,(POSPRI) Load POSPRI into BC and decrement (move cursor left over letter to delete).
8B32 DEC BC
8B33 LD A,$20 Print space character to blank out letter under cursor.
8B35 CALL DH_P
8B38 LD HL,(POSPRI) Decrement POSPRI again ready for next letter.
8B3B DEC HL
8B3C LD (POSPRI),HL
8B3F LD HL,string_length Decrement string_length.
8B42 DEC (HL)
8B43 LD HL,(player_name_string) Decrement player_name_string pointer (move back over last character).
8B46 DEC HL
8B47 LD (player_name_string),HL
8B4A LD HL,S60 Play key bloop sound effect.
8B4D CALL play_sound_effect_in_HL
8B50 CALL PAUSER Pause for approximately 0.15 seconds then jump back to INPLOO.
8B53 JP INPLOO
NO_DEL 8B56 LD A,(string_length) If string length equals 11 jump back to INPLOO.
8B59 CP $0B
8B5B JP Z,INPLOO
8B5E LD A,(KEY_P) If KEY_P is 'space' jump to SPACE.
8B61 CP $20
8B63 JR Z,SPACE
8B65 CP $41 If KEY_P is less than 'A' or greater than 'z' jump back to INPLOO.
8B67 JP M,INPLOO
8B6A CP $7B
8B6C JP P,INPLOO
SPACE 8B6F LD HL,(player_name_string) Store space character at the position given by the player_name_string pointer.
8B72 LD (HL),A
8B73 INC HL Advance the player_name_string pointer and store.
8B74 LD (player_name_string),HL
8B77 LD HL,string_length Increment string_length.
8B7A INC (HL)
8B7B LD BC,(POSPRI) Load POSPRI into BC and call DH_P to print character still in A (space) at those coordinates.
8B7F CALL DH_P
8B82 LD HL,(POSPRI) Increment POSPRI.
8B85 INC HL
8B86 LD (POSPRI),HL
8B89 LD HL,S60 Play key bloop sound effect.
8B8C CALL play_sound_effect_in_HL
8B8F CALL NKEY2 Append 4 semi-random bytes to INBUF then jump back to INPLOO.
8B92 JP INPLOO
ENTER 8B95 LD A,(string_length) Read string length into A. If zero jump back to INPLOO.
8B98 OR A
8B99 JP Z,INPLOO
8B9C LD H,$00 Set HL = current_player + $29.
8B9E LD A,(current_player)
8BA1 ADD A,$29
8BA3 LD L,A
8BA4 ADD HL,HL Multiply result by four.
8BA5 ADD HL,HL
8BA6 LD DE,game_messages_1 Add result to address of game messages table 1 to point at offset to relevant wizard data.
8BA9 ADD HL,DE
8BAA INC HL Move past address word in table to wizard name length.
8BAB INC HL
8BAC LD A,(string_length) Read string_length variable again and write into table.
8BAF LD (HL),A
8BB0 CALL NKEY2 Append 4 semi-random bytes to INBUF.
8BB3 LD BC,$0902 Set ATTR-T to $43 (bright magenta on black) and print message M_6 at coordinates (2,9).
8BB6 LD A,$43
8BB8 LD ($5C8F),A
8BBB LD A,$05
8BBD CALL M2PRIN
8BC0 LD A,$46 Set ATTR-T to $46 (bright yellow on black).
8BC2 LD ($5C8F),A
8BC5 LD A,$00 Clear computer_player_flag (current player is human).
8BC7 LD (computer_player_flag),A
Y_OR_N 8BCA CALL $02BF Call KEYBOARD in Spectrum ROM.
8BCD CP $59 If keypress is 'Y' jump to YES_CC.
8BCF JR Z,YES_CC
8BD1 CP $4E If keypress is not 'N' jump back to Y_OR_N.
8BD3 JR NZ,Y_OR_N
8BD5 LD BC,$0917 Print message M_8 at coordinates (23,9).
8BD8 LD A,$07
8BDA CALL M2PRIN
8BDD JR NOT_CC Jump to NOT_CC.
YES_CC 8BDF LD BC,$0917 Print message M_9 at 23,9.
8BE2 LD A,$06
8BE4 CALL M2PRIN
8BE7 LD HL,WIZCON Set HL to WIZCON + current_player.
8BEA LD D,$00
8BEC LD A,(current_player)
8BEF LD E,A
8BF0 ADD HL,DE
8BF1 LD (HL),$01 Write $01 to WIZCON + current_player.
8BF3 LD A,$01 Set computer_player_flag.
8BF5 LD (computer_player_flag),A
NOT_CC 8BF8 LD HL,S60 Play key bloop sound effect.
8BFB CALL play_sound_effect_in_HL
8BFE CALL NKEY2 Append 4 semi-random bytes to INBUF.
8C01 LD BC,$0B02 Set ATTR-T to $43 (bright magenta on black) and print message M_13 at coordinates (2,11).
8C04 LD A,$43
8C06 LD ($5C8F),A
8C09 LD A,$0C
8C0B CALL M2PRIN
8C0E LD A,$45 Set ATTR-T to $45 (bright cyan on black) and print message M_14 at coordinates (2,13).
8C10 LD ($5C8F),A
8C13 LD BC,$0D02
8C16 LD A,$0D
8C18 CALL M2PRIN
8C1B LD BC,$0D03 Set POSPRI to coordinates (3,13).
8C1E LD (POSPRI),BC
8C22 LD A,$00 Set NUM to zero.
8C24 LD (NUM),A
8C27 LD B,$08 Set B to eight as a loop counter.
P_WIZL 8C29 PUSH BC Preserve the loop counter.
8C2A LD A,(NUM) Copy NUM to ROMP.
8C2D LD (ROMP),A
8C30 INC A Increment NUM.
8C31 LD (NUM),A
8C34 CALL PR_CHR Call PR_CHR (print character sprite).
8C37 LD BC,(POSPRI) Add three to POSPRI.
8C3B INC BC
8C3C INC BC
8C3D INC BC
8C3E LD (POSPRI),BC
8C42 POP BC Restore loop counter.
8C43 DJNZ P_WIZL Loop back to P_WIZL for eight iterations.
8C45 LD BC,$0B13 Call CHONUM with coordinates (19,11).
8C48 CALL CHONUM
8C4B LD (ROMP),A Store number returned in ROMP.
8C4E LD BC,$0B14 Set POSPRI to coordinates (20,11) and call PR_CHR.
8C51 LD (POSPRI),BC
8C55 CALL PR_CHR
8C58 LD HL,character_1_sprite_pointers Set HL to unknown data block at character_1_sprite_pointers.
8C5B LD D,$00 Multiply ROMP by eight and add to character_1_sprite_pointers to give address of pointer to sprite data for selected character.
8C5D LD A,(ROMP)
8C60 SLA A
8C62 SLA A
8C64 SLA A
8C66 LD E,A
8C67 ADD HL,DE
8C68 LD (current_character_pointer),HL Store result at address in current_character_pointer.
8C6B CALL routine02 Copy pointers to sprite data of chosen character to wizard object data for current player.
8C6E LD A,$43 Set ATTR-T to $43 (bright magenta on black) and print message M_12 at coordinates (2,16).
8C70 LD ($5C8F),A
8C73 LD BC,$1002
8C76 LD A,$0B
8C78 CALL M2PRIN
8C7B LD A,$46 Set ATTR-T to $46 (bright yellow on black) and print message M_14 at coordinates (2,18).
8C7D LD ($5C8F),A
8C80 LD BC,$1202
8C83 LD A,$0D
8C85 CALL M2PRIN
8C88 LD BC,$1203 Set POSPRI to coordinates (3,18).
8C8B LD (POSPRI),BC
8C8F LD HL,ATTAB Set temp_pointer to address of ATTAB (attribute table).
8C92 LD (temp_pointer),HL
8C95 LD B,$08 Set B to eight as loop counter.
COLOO 8C97 PUSH BC Preserve the loop counter.
8C98 LD HL,(temp_pointer) Read byte from address held in temp_pointer.
8C9B LD A,(HL)
8C9C LD ($5C8F),A Store in ATTR-T.
8C9F INC HL Increment HL and store back in temp_pointer.
8CA0 LD (temp_pointer),HL
8CA3 CALL PR_CHR Print character sprite.
8CA6 LD HL,(POSPRI) Add three to POSPRI.
8CA9 LD DE,$0003
8CAC ADD HL,DE
8CAD LD (POSPRI),HL
8CB0 POP BC Restore loop counter from stack.
8CB1 DJNZ COLOO Loop back to COLOO for eight iterations.
8CB3 LD BC,$1010 Set coordinates to (16,16) and get number input from 1 to 8. This also appends 4 semi-random bytes to INBUF.
8CB6 CALL CHONUM
8CB9 LD HL,ATTAB Add number returned to address of ATTAB giving address of byte in attribute table corresponding to chosen colour.
8CBC LD D,$00
8CBE LD E,A
8CBF ADD HL,DE
8CC0 LD A,(HL) Read attribute byte from attribute table and set ATTR-T.
8CC1 LD ($5C8F),A
8CC4 LD BC,$1011 Set POSPRI to coordinates (17,16) and print character sprite.
8CC7 LD (POSPRI),BC
8CCB CALL PR_CHR
8CCE CALL get_wizard_object Get address of first sprite pointer in wizard object data of the current player).
8CD1 LD HL,(temp_pointer) load address of first sprite pointer in wizard object data from temp_pointer into HL and decrement (HL = address of first sprite pointer - 1).
8CD4 DEC HL
8CD5 LD DE,$0003 Set DE to three.
8CD8 LD A,($5C8F) Read ATTR-T onto A.
8CDB LD B,$04 Set B to four as a loop counter.
PUTATL 8CDD ADD HL,DE Add three to HL to point at next attribute byte in wizard data.
8CDE LD (HL),A Write attribute byte to wizard data.
8CDF DJNZ PUTATL Loop back to PUTATL for four iterations.
8CE1 LD A,$00 Set COMPAR to zero.
8CE3 LD (COMPAR),A
8CE6 LD A,(computer_player_flag) If player is human then jump to MAKCHR.
8CE9 OR A
8CEA JR Z,MAKCHR
8CEC LD A,(LEVEL) Else copy LEVEL to COMPAR.
8CEF LD (COMPAR),A
MAKCHR 8CF2 CALL get_wizard_object Get address of first sprite pointer in wizard object data of the current player.
8CF5 LD HL,(player_name_string) Read player_name_string into HL.
8CF8 LD D,$00 Move past player name string to player stats.
8CFA LD E,$0D
8CFC ADD HL,DE
8CFD CALL RANDY Get a random number in the range 0-9.
8D00 SRA A Halve it and add 1.
8D02 INC A
8D03 LD E,A Add COMPAR divided by 2.
8D04 LD A,(COMPAR)
8D07 SRA A
8D09 ADD A,E
8D0A LD (HL),A Store calculated value in first byte of wizard stats (combat).
8D0B INC HL Set second and third bytes of wizard stats to zero (ranged combat and range).
8D0C LD (HL),$00
8D0E INC HL
8D0F LD (HL),$00
8D11 CALL RANDY Get a random number in the range 0-9.
8D14 SRA A Halve it and add 1.
8D16 INC A
8D17 LD E,A Add COMPAR divided by 2.
8D18 LD A,(COMPAR)
8D1B SRA A
8D1D ADD A,E
8D1E INC HL Store in fourth byte of wizard stats (defence).
8D1F LD (HL),A
8D20 INC HL Set fifth byte of wizard stats to 1 (movement allowance).
8D21 LD (HL),$01
8D23 CALL RANDY Get a random number in the range 0-9.
8D26 SRA A Halve it and add 3.
8D28 ADD A,$03
8D2A LD E,A Add COMPAR divided by 4.
8D2B LD A,(COMPAR)
8D2E SRA A
8D30 SRA A
8D32 ADD A,E
8D33 INC HL Store in sixth byte of wizard stats (manoeuvre rating).
8D34 LD (HL),A
8D35 CALL RANDY Get a random number in the range 0-9.
8D38 SRA A Divide it by 4 and add 6.
8D3A SRA A
8D3C ADD A,$06
8D3E INC HL Store in seventh byte of wizard stats (magic resistance).
8D3F LD (HL),A
8D40 CALL RANDY Get a random number in the range 0-9.
8D43 SRA A Halve it and add 11.
8D45 ADD A,$0B
8D47 LD E,A Add COMPAR.
8D48 LD A,(COMPAR)
8D4B ADD A,E
8D4C CP $15 Cap the value at 20.
8D4E JP M,NOTMOR
8D51 LD A,$14
NOTMOR 8D53 INC HL Store value in SPELNO and in eighth byte of wizard stats (spells).
8D54 LD (SPELNO),A
8D57 LD (HL),A
8D58 INC HL Set ninth byte in wizard stats to zero (ability).
8D59 LD (HL),$00
8D5B LD A,(COMPAR) Halve COMPAR and subtract from 5.
8D5E SRA A
8D60 LD E,A
8D61 LD A,$05
8D63 SUB E
8D64 LD (STRENG),A Store result in STRENG.
8D67 CALL RANDY Get a random number in the range 0-9.
8D6A LD E,A If less than STRENG jump to NOABIL.
8D6B LD A,(STRENG)
8D6E CP E
8D6F JP P,NOABIL
8D72 CALL RANDY Get a random number in the range 0-9.
8D75 SRA A Halve it and store in ninth byte of wizard stats (ability).
8D77 SRA A
8D79 LD (HL),A
NOABIL 8D7A CALL GETHIS Get address of current player's first spell in possesssed_spell_tables.
8D7D LD HL,(HISPEL) Decrement HISPEL to first byte in wizard's spells ???
8D80 DEC HL
8D81 LD (HISPEL),HL
8D84 CALL RANDY Get a random number in the range 0-9.
8D87 ADD A,$0C Add 12 to value and store at address in HISPEL ???
8D89 LD HL,(HISPEL)
8D8C LD (HL),A
8D8D INC HL Set first spell to $01 (disbelieve).
8D8E LD (HL),$01
8D90 INC HL Set HISPEL to next address.
8D91 LD (HISPEL),HL
8D94 LD HL,INBUF Reset BUFPNT to beginning of INBUF.
8D97 LD (BUFPNT),HL
8D9A LD A,(SPELNO) Set B to SPELNO as loop counter.
8D9D LD B,A
INSPLO 8D9E PUSH BC Preserve BC.
RIND 8D9F LD A,R Copy R register into A.
8DA1 AND $07 Select lowest three bits.
8DA3 LD H,A Copy to H.
8DA4 LD A,R Get R register into L.
8DA6 LD L,A
8DA7 LD A,(HL) Read byte from a semi-random address in first 2kB of ROM.
8DA8 LD HL,(BUFPNT) Add semi-random byte from address in BUFPNT.
8DAB ADD A,(HL)
8DAC AND $3F Select lowest 6 bits.
8DAE CP $02 Jump back to RIND unless value in the range $02 to $41. This selects any valid spell number excluding disbelieve. The preceding mask also excludes spells $40 and $41 (turmoil) rendering the upper range check unnecessary.
8DB0 JP M,RIND
8DB3 CP $42
8DB5 JP P,RIND
8DB8 INC HL Increment BUFPNT to next semi-random byte.
8DB9 LD (BUFPNT),HL
8DBC LD (CURSP),A Store spell number in CURSP.
8DBF CALL CHAN_C Get address of spell table entry in IX.
8DC2 LD A,(IX+$04) Read fourth byte from spell entry ???
8DC5 LD HL,(HISPEL) Store at address in HISPEL.
8DC8 LD (HL),A
8DC9 INC HL Increment address and copy CURSP there.
8DCA LD A,(CURSP)
8DCD LD (HL),A
8DCE INC HL Increment address and HISPEL pointer.
8DCF LD (HISPEL),HL
8DD2 POP BC Restore loop counter.
8DD3 DJNZ INSPLO Loop back to INSPLO for SPELNO iterations.
8DD5 LD A,(computer_player_flag) If player is human, jump to DONSOR.
8DD8 OR A
8DD9 JR Z,DONSOR
8DDB CALL GETHIS Get address of spells for current player.
8DDE LD HL,(HISPEL) Set HL to address of wizard's first spell number.
8DE1 DEC HL Decrement to address of first entry in possessed spell table.
8DE2 LD B,$13 Set B to 19 as outer loop counter.
OUTL_ 8DE4 PUSH BC Preserve outer loop counter and address in possessed spell table.
8DE5 PUSH HL
8DE6 LD B,$13 Set B to 19 as inner loop counter.
INL_ 8DE8 PUSH BC Preserve inner loop counter.
8DE9 LD E,(HL) Read ??? and spell number from entry address in HL into E and D.
8DEA INC HL
8DEB LD D,(HL)
8DEC INC HL
8DED LD C,(HL) Move forward and read next entry into C and B.
8DEE INC HL
8DEF LD B,(HL)
8DF0 DEC HL Move pointer back to the ??? of the second entry.
8DF1 LD A,C If first ??? is not greater than or equal to second ??? jump to NOBIGA.
8DF2 CP E
8DF3 JR Z,NOBIGA
8DF5 JR C,NOBIGA
8DF7 INC HL Else swap table entries.
8DF8 LD (HL),D
8DF9 DEC HL
8DFA LD (HL),E
8DFB DEC HL
8DFC LD (HL),B
8DFD DEC HL
8DFE LD (HL),C
8DFF INC HL Move pointer back to ??? of the second entry.
8E00 INC HL
NOBIGA 8E01 POP BC Restore inner loop counter and loop back to INL_ for 19 iterations.
8E02 DJNZ INL_
8E04 POP HL Restore address of first table entry and outer loop counter and loop back to OUTL_ for 19 iterations.
8E05 POP BC
8E06 DJNZ OUTL_
DONSOR 8E08 LD A,(current_player) Increment current_player variable.
8E0B INC A
8E0C LD (current_player),A
8E0F POP BC Restore loop counter and jump back to STALOO for NO_PLA iterations.
8E10 DEC B
8E11 JP NZ,STALOO
Next the program sets the starting position of each wizard which depends on the number of players.
8E14 LD A,(NO_PLA) Read NO_PLA into A.
8E17 DEC A Subtract two.
8E18 DEC A
8E19 SLA A Multiply by eight.
8E1B SLA A
8E1D SLA A
8E1F LD HL,STAPOS And add result to address of STAPOS get starting positions for selected number of players.
8E22 LD D,$00
8E24 LD E,A
8E25 ADD HL,DE
8E26 LD (temp_pointer),HL Store this address in variable at temp_pointer.
8E29 LD A,$00 Set current_player variable to zero.
8E2B LD (current_player),A
8E2E LD A,(NO_PLA) Read NO_PLA into B as loop counter.
8E31 LD B,A
PUTIBO 8E32 LD HL,(temp_pointer) Read byte from address held in temp_pointer into A.
8E35 LD A,(HL)
8E36 INC HL Increment address in temporary variable at temp_pointer.
8E37 LD (temp_pointer),HL
8E3A LD HL,map_object_table Set HL to map_object_table.
8E3D LD D,$00 Calculate address in table by adding the value just read from current player offset in STAPOS table.
8E3F LD E,A
8E40 ADD HL,DE
8E41 LD A,(current_player) Add $29 to current_player to get object number of wizard and store at calculated address.
8E44 ADD A,$29
8E46 LD (HL),A
8E47 LD DE,$01E1 Store current_player at corresponding entry in map_object_properties_table.
8E4A ADD HL,DE
8E4B LD A,(current_player)
8E4E LD (HL),A
8E4F INC A Increment current_player variable.
8E50 LD (current_player),A
8E53 DJNZ PUTIBO Loop back to PUTIBO for NO_PLA iterations.
8E55 LD A,$00 Set unknown01 to zero ???
8E57 LD (unknown01),A
8E5A LD A,(NO_PLA) Read NO_PLA into A, double it, add 15 and copy the result to B as a loop counter.
8E5D SLA A
8E5F ADD A,$0F
8E61 LD B,A
This is the main game loop. A loop counter ends the game in a tie after a certain number of turns, which is the number of players multiplied by 2, plus 15.
TURLOO 8E62 PUSH BC Preserve loop counter.
8E63 CALL CAST_S Each player in turn selects their spell, and then the spells are cast.
8E66 LD A,(num_dead_wizards) If only one wizard is alive jump to GO_END.
8E69 INC A
8E6A LD HL,NO_PLA
8E6D CP (HL)
8E6E JR Z,GO_END
8E70 CALL INTERO Call INTERO ???
8E73 CALL TREPUT Call TREPUT ???
8E76 CALL WALKYS Call WALKYS ???
8E79 CALL routine21 Call routine21 ???
8E7C CALL set_IM2_mode Switch to interrupt mode 2.
8E7F LD B,$0A Set B to ten as loop counter.
PAUS_L 8E81 PUSH BC Preserve BC, call PAUSER, Restore BC.
8E82 CALL PAUSER
8E85 POP BC
8E86 DJNZ PAUS_L Loop back to PAUS_L for ten iterations.
8E88 CALL set_IM1_mode Switch to interrupt mode 1.
8E8B LD A,(num_dead_wizards) Compare num_dead_wizards +1 with NO_PLA.
8E8E INC A
8E8F LD HL,NO_PLA
8E92 CP (HL)
GO_END 8E93 POP BC Restore loop counter.
8E94 JR Z,ENDGAM If only one wizard is alive jump to ENDGAM.
8E96 LD HL,unknown01 Increment variable unknown01.
8E99 INC (HL)
8E9A DJNZ TURLOO Loop back to TURLOO for (NO_PLA * 2) + 15 iterations.
8E9C CALL CLS Call CLS ???
8E9F LD A,$01 Set ATTR-T to $01 (dark blue on black).
8EA1 LD ($5C8F),A
LOOPY 8EA4 CALL ATTRDO Call ATTRDO ???
8EA7 CALL ZRDR_P Draw border.
8EAA CALL ATTRDO Call ATTRDO ???
8EAD LD BC,$0202 Print message M_17 at coordinates (2,2).
8EB0 LD A,$10
8EB2 CALL M2PRIN
8EB5 LD HL,unknown_table_3 Set HL to unknown_table_3.
8EB8 LD BC,$030A Set POSPRI to coordinates (10,3).
8EBB LD (POSPRI),BC
8EBF LD A,$29 Set current_player to $29 (the first wizard's name game_messages_1).
8EC1 LD (current_player),A
8EC4 LD A,(NO_PLA) Load NO_PLA into B as loop counter.
8EC7 LD B,A
ZAPEM 8EC8 PUSH BC Preserve BC and HL.
8EC9 PUSH HL
8ECA BIT 4,(HL) Jump to DEDED if bit 4 of byte at address in HL is not zero.
8ECC JR NZ,DEDED
8ECE CALL ATTRDO Call ATTRDO ???
8ED1 LD HL,current_player Load current_player variable back into A (message in message table 1).
8ED4 LD A,(HL)
8ED5 LD BC,(POSPRI) Load BC with POSPRI and increment twice (move two columns right).
8ED9 INC B
8EDA INC B
8EDB LD (POSPRI),BC
8EDF CALL MPRINT Print the wizard name.
DEDED 8EE2 POP HL Restore address and advance to next entry in unknown_table_3.
8EE3 INC HL
8EE4 LD A,(current_player) Increment current_player variable (next row in game message table 1).
8EE7 INC A
8EE8 LD (current_player),A
8EEB POP BC Restore loop counter from stack.
8EEC DJNZ ZAPEM Loop back to ZAPEM for NO_PLA iterations.
8EEE CALL ATTRDO Call ATTRDO ???
8EF1 LD A,$3D Print press_any_key_string at coordinates (0,22).
8EF3 LD BC,$1600
8EF6 CALL MPRINT
8EF9 CALL PAUSER Call PAUSER ???
8EFC CALL $028E Call KEY-SCAN in Spectrum ROM.
8EFF LD A,E Jump back to LOOPY if no key is pressed else return.
8F00 INC A
8F01 JR Z,LOOPY
8F03 RET
ENDGAM 8F04 CALL CLS Call CLS ???
8F07 LD A,$01 Set ATTR-T to $01 (dark blue on black).
8F09 LD ($5C8F),A
LOPY2 8F0C CALL ATTRDO Call ATTRDO ???
8F0F CALL ZRDR_P Draw border.
8F12 CALL ATTRDO Call ATTRDO ???
8F15 LD BC,$0409 Print message M_18 at coordinates (9,4).
8F18 LD A,$11
8F1A CALL M2PRIN
8F1D CALL ATTRDO Call ATTRDO ???
8F20 LD A,$12 Print message M_19 at coordinates (8,8).
8F22 LD BC,$0808
8F25 CALL M2PRIN
8F28 LD A,$13 Print message M_20 at coordinates (8,10).
8F2A LD BC,$0A08
8F2D CALL M2PRIN
8F30 LD A,$13 Print message M_20 at coordinates (8,12).
8F32 LD BC,$0C08
8F35 CALL M2PRIN
8F38 LD A,$13 Print message M_20 at coordinates (8,14).
8F3A LD BC,$0E08
8F3D CALL M2PRIN
8F40 LD A,$12 Print message M_19 at coordinates (8,16).
8F42 LD BC,$1008
8F45 CALL M2PRIN
8F48 CALL ATTRDO Call ATTRDO ???
8F4B LD HL,unknown_table_3 Set HL to address unknown_table_3.
8F4E LD B,$08 Set B to eight as loop counter.
GRONK 8F50 BIT 4,(HL) Jump to main_routine_0 if bit 4 of byte at address in HL is set.
8F52 JR Z,main_routine_0
8F54 INC HL Else move on to next byte.
8F55 DJNZ GRONK Loop back to GRONK for eight iterations.
main_routine_0 8F57 LD A,$31 Subtract loop counter from $31 to get row of wizard in game_messages_1.
8F59 SUB B
8F5A PUSH AF Preserve AF.
8F5B LD BC,$0C0A Load BC with coordinates (10,12).
8F5E LD H,$00 Set HL to four times the value in A.
8F60 LD L,A
8F61 ADD HL,HL
8F62 ADD HL,HL
8F63 LD DE,game_messages_1 Add offset to the address of game messages table 1.
8F66 ADD HL,DE
8F67 INC HL Add two to resulting address to move to length byte.
8F68 INC HL
8F69 LD A,(HL) Read byte into A.
8F6A SRA A Divide by two and copy result to E.
8F6C LD E,A
8F6D LD A,$10 Subtract E from sixteen and copy result to C.
8F6F SUB E
8F70 LD C,A
8F71 POP AF Restore row of game messages table 1.
8F72 CALL MPRINT Print wizard name centred in box.
8F75 CALL ATTRDO Call ATTRDO ???
8F78 LD A,$3D Print press_any_key_string at coordinates (0,22).
8F7A LD BC,$1600
8F7D CALL MPRINT
8F80 CALL PAUSER Call PAUSER ???
8F83 CALL $028E Call KEY-SCAN in ROM to see if a key was pressed.
8F86 LD A,E
8F87 INC E
8F88 JR Z,LOPY2 Loop back to LOPY2 if no key was pressed.
8F8A RET Else return (to BASIC).
Prev: 89EF Up: Map Next: 8F8B