Prev: E967 Up: Map Next: E9EF
E991: Blit Display Buffer To Screen
Used by the routine at GameStart.
Compare the primary and secondary display buffers and blit changed tiles to the Spectrum screen. Tiles with attribute bit 07 set are horizontally mirrored via BitmapMirrorLookup (see Blit_DisplayBufferRowLoop).
Choose which display buffer is "live" versus "previous" from DisplayBufferSelectFlag.
Blit_DisplayBuffer E991 LD IX,$5800 Point IX at the attribute file (5800 (attribute buffer)).
E995 LD HL,$63A0 Point HL at Primary Display Buffer (PrimaryDisplayBuffer).
E998 LD DE,$6B20 Point DE at Secondary Display Buffer (SecondaryDisplayBuffer).
E99B LD A,($72EA) Load A with the display-buffer select flag (DisplayBufferSelectFlag).
E99E OR A Is the display-buffer select flag (DisplayBufferSelectFlag) zero? If so, jump to Blit_DisplayBuffer_AfterSelect.
E99F JR Z,Blit_DisplayBuffer_AfterSelect
E9A1 EX DE,HL Exchange DE and HL.
After selecting primary/secondary, walk 14 rows × 20 columns for dirty tiles.
Blit_DisplayBuffer_AfterSelect E9A2 PUSH DE Copy DE into IY (using the stack).
E9A3 POP IY
E9A5 LD B,$14 Load B with 14.
Begin one display-buffer row of 20 tile comparisons.
Blit_DisplayBufferLoop E9A7 PUSH BC Stash BC on the stack.
E9A8 LD B,$20 Load B with loop count 20.
Compare one tile's graphic-set / type / attribute triple against the secondary buffer.
Blit_DisplayBufferLoopB E9AA PUSH BC Stash BC on the stack.
E9AB LD A,(HL) Fetch the next primary-buffer graphic-set byte.
E9AC INC HL Advance the display-buffer pointer in HL by one byte.
E9AD OR A Is A zero? If so, jump to Blit_DisplayBufferLoopB6.
E9AE JP Z,Blit_DisplayBufferLoopB6
E9B1 LD C,A Keep the remaining count in C.
E9B2 LD E,$00 Load E with 00.
E9B4 CP (IY+$00) Does A match the referenced entity's type? If not, jump to Blit_DisplayBufferLoopB2.
E9B7 JR NZ,Blit_DisplayBufferLoopB2
E9B9 INC E Advance the low byte of the pointer/offset in DE.
Match the tile's entity-type byte; count matches in E.
Blit_DisplayBufferLoopB2 E9BA LD A,(HL) Fetch the next script byte.
E9BB OR A Is the next script byte zero? If so, jump to Blit_DisplayBufferLoopB6.
E9BC JR Z,Blit_DisplayBufferLoopB6
E9BE LD B,A Keep a copy of A in B.
E9BF CP (IY+$01) Does A match the referenced entity's flags byte 1? If not, jump to Blit_DisplayBufferLoopB3.
E9C2 JR NZ,Blit_DisplayBufferLoopB3
E9C4 INC E Advance the low byte of the pointer/offset in DE.
Match the tile's attribute byte; blit via Blit_DisplayBufferRow unless both prior bytes already matched.
Blit_DisplayBufferLoopB3 E9C5 INC HL Advance the display-buffer pointer in HL by one byte.
E9C6 LD A,(HL) Fetch the next script byte.
E9C7 CP (IY+$02) Does A match the referenced entity's flags byte 2? If not, jump to Blit_DisplayBufferLoopB4.
E9CA JR NZ,Blit_DisplayBufferLoopB4
E9CC BIT 1,E Is bit 01 of E set? If so, jump to Blit_DisplayBufferLoopB5.
E9CE JR NZ,Blit_DisplayBufferLoopB5
Blit this changed tile to the Spectrum screen through Blit_DisplayBufferRow.
Blit_DisplayBufferLoopB4 E9D0 PUSH HL Stash HL on the stack.
E9D1 CALL Blit_DisplayBufferRow Call Blit_DisplayBufferRow to blit Display Buffer Row.
E9D4 POP HL Restore HL from the stack.
Advance past this tile's triple and move to the next attribute column.
Blit_DisplayBufferLoopB5 E9D5 INC HL Advance the display-buffer pointer in HL by one byte.
E9D6 INC IX Advance IX to the next attribute-file column.
E9D8 LD DE,$0003 Load DE with 0003.
E9DB ADD IY,DE IY+=DE.
E9DD POP BC Restore BC from the stack.
E9DE DJNZ Blit_DisplayBufferLoopB Decrease the loop counter in B and jump to Blit_DisplayBufferLoopB if more iterations remain.
E9E0 POP BC Restore BC from the stack.
E9E1 DEC B Decrease B by one.
E9E2 JP NZ,Blit_DisplayBufferLoop Jump to Blit_DisplayBufferLoop to continue if the comparison did not match.
E9E5 RET Return.
Treat a zero graphic-set as "blank": force bit 06 and skip the blit.
Blit_DisplayBufferLoopB6 E9E6 INC HL Advance the display-buffer pointer in HL by one byte.
E9E7 LD A,(HL) Fetch the next script byte.
E9E8 SET 6,A Set bit 06 of A.
E9EA LD (IX+$00),A Set the current entity's entity type.
E9ED JR Blit_DisplayBufferLoopB5 Jump to Blit_DisplayBufferLoopB5 to continue the loop.
Prev: E967 Up: Map Next: E9EF