Prev: BDFE Up: Map Next: BEDF
BE0F: Set up a new game, then run the main loop
Used by the routines at GAME_OVER and ENDING_PIT_FRONT.
Entered from START the first time and from GAME_OVER after each game and after the ending (ENDING_PIT_FRONT). The variables from CELL_LOOKED_UP on are cleared, the turn counter taken from FRAMES, the screen cleared and the lookup tables built, and the menu run until a game is started (MENU); then the start tune, the panel (the frame, the heading over the score, the score, the compass and the heading of the view), six lives, a random cell to start in, the first life, the villains and the objects placed, the villains drawn on the panel, and the buildings stocked -- with the third protection check at the end of that (STOCK_BUILDINGS).
The number of lives is not written in the code as a number. It is the opcode of the JR that closes the main loop, at LIVES_BYTE: $18, shifted right twice, is six. A search for a load of six finds nothing, and a poke to that byte breaks the loop; whether it was meant as a guard is not known, but it works as one.
MAIN_LOOP is one turn. Every object record, knight first, is updated by the routine UPDATES gives for its graphic, through the dispatcher and NMIADD; the random number is stirred after each. Then the turn is counted, and unless the ending is under way: a find may appear, a monster, the creature, a bonus; this turn's note of the sound effect; the carried things coloured on the panel; the town and everything in it drawn into the buffer; the knight coloured by his hits; a new life if his record has emptied; the ending if the villains are gone. At END_OF_TURN the buffers go to the screen and are cleared, the flash is kept for the next turn and ended, and the pause key is read.
NEW_GAME BE0F LD HL,CELL_LOOKED_UP clear from CELL_LOOKED_UP to the last monster's record
BE12 LD BC,$024A
This entry point is used by the routine at START.
NEW_GAME_0 BE15 CALL CLEAR_MEMORY clear
BE18 LD HL,(FRAMES) the turn counter starts from FRAMES, which never changes once the game runs
BE1B LD (TURNS),HL
BE1E CALL CLEAR_SCREEN clear the screen, border black
BE21 CALL MAKE_TABLES build the tables for drawing mirrored and shifted
BE24 CALL MENU the menu, until 0 starts a game
BE27 LD DE,TUNE_GAME_START the tune as a game starts
BE2A CALL PLAY_TUNE
BE2D CALL CLEAR_SCREEN clear the screen again
BE30 CALL DRAW_PLAY_FRAME the border and the panel's frame
BE33 CALL DRAW_PANEL_FRAME
BE36 LD HL,$0F38 the heading over the score (SCORE_TEXT)
BE39 LD DE,SCORE_TEXT
BE3C CALL PRINT_TEXT
BE3F CALL PRINT_SCORE the score
BE42 CALL PRINT_COMPASS the compass
BE45 CALL PRINT_HEADING north, or south
BE48 CALL CLEAR_BUFFER clear the play area's buffers
BE4B LD A,$0A top speed 10
BE4D LD (TOP_SPEED),A
BE50 LD A,(LIVES_BYTE) six lives: the JR's opcode at LIVES_BYTE, $18, shifted right twice
BE53 SRL A
BE55 SRL A
BE57 LD (LIVES),A
BE5A CALL RANDOM_START_CELL a random cell to start in, anything but solid
BE5D LD A,$40 facing along U, forward
BE5F LD (START_FACING),A
BE62 CALL FIRST_LIFE the first life: the knight's records, and a life taken
BE65 CALL PLACE_VILLAINS the villains
BE68 CALL PLACE_OBJECTS the objects
BE6B CALL DRAW_VILLAINS the villains on the panel
BE6E CALL STOCK_BUILDINGS stock the buildings, and protection check 3
This entry point is used by the routine at GAME_OVER.
MAIN_LOOP BE71 LD IX,KNIGHT MAIN_LOOP: from the knight's legs
NEXT_OBJECT BE75 LD A,(IX+$00) update the record, by its graphic, through NMIADD
BE78 LD BC,UPDATES
BE7B CALL DISPATCH
BE7E CALL STIR_RANDOM stir the random number after every record
BE81 LD BC,$0010 on to the next, until past the last monster's
BE84 ADD IX,BC
BE86 PUSH IX
BE88 POP HL
BE89 LD BC,START
BE8C AND A
BE8D SBC HL,BC
BE8F JR C,NEXT_OBJECT
BE91 CALL NEXT_TURN count the turn
BE94 LD A,(ENDING) while the ending plays, nothing else
BE97 AND A
BE98 JP NZ,END_OF_TURN
BE9B CALL SPAWN_FIND a find, every sixteenth turn
BE9E CALL SPAWN_MONSTER a monster, every fourth
BEA1 CALL SPAWN_CREATURE the creature, every 256th
BEA4 CALL PLACE_BONUS a bonus, when there is none
BEA7 CALL EFFECT_NOTE this turn's note of the sound effect
BEAA CALL COLOUR_CARRIED colour the carried things on the panel
BEAD CALL DRAW_CELLS draw the town round the knight, and what is in it
BEB0 LD A,(HITS) colour the knight by his hits (KNIGHT_COLOURS): four rows of two cells in the middle of the play area
BEB3 LD HL,KNIGHT_COLOURS
BEB6 CALL ADD_HL_A
BEB9 LD A,(HL)
BEBA EX AF,AF'
BEBB LD HL,$7070
BEBE CALL ATTR_ADDRESS
BEC1 LD B,$04
BEC3 EX AF,AF'
BEC4 CALL COLOUR_KNIGHT
BEC7 CALL NEW_LIFE a new life, if his record is empty
BECA CALL CHECK_QUEST_DONE the ending, if the villains are gone
END_OF_TURN BECD CALL SHOW_PLAY_AREA END_OF_TURN: the buffers to the screen, and cleared with this turn's flash
BED0 LD A,(FLASH) keep the flash for the colours of the next turn, and end it
BED3 LD (LAST_FLASH),A
BED6 XOR A
BED7 LD (FLASH),A
BEDA CALL PAUSE the pause
LIVES_BYTE BEDD JR MAIN_LOOP LIVES_BYTE: round again; this JR's opcode is also the number of lives
Prev: BDFE Up: Map Next: BEDF