Prev: 5F22 Up: Map Next: 6010
5F80: Creates Background Image
Used by the routine at Change_Background.
Each background uses 4 sets of data "pairs" and a single reference for attribute data (handled separately at Background_Attributes). For example, background 1 uses;
Block UDGs Data
01 626A 6102
02 648A 6157
03 685A 61D9
04 6AE2 624D
Attribute Data 6061
Create_Background 5F80 LD HL,$4080 The first screen address is 4080 which allows space for the "header". This is the top of character block 4. This is then stored in the buffer at Background_Screen_Address.
5F83 LD ($5F02),HL
5F86 LD HL,$5F10 HL=Background address data buffer.
Each background has 4 "sets" of data, so set a counter of 4.
5F89 LD B,$04 B=Initialise block counter.
The block processing loop.
Create_Background_Loop 5F8B PUSH BC Push the counter onto the stack.
Each block contains two address references, one is for UDG data, and one is for positioning data.
5F8C LD E,(HL) Pick up the next background UDG data block and store it at Background_UDG_Data.
5F8D INC HL
5F8E LD D,(HL)
5F8F INC HL
5F90 LD ($5F08),DE
5F94 LD E,(HL) Fetch the address of the next positioning data block and store it in DE.
5F95 INC HL
5F96 LD D,(HL)
5F97 INC HL
5F98 PUSH HL Push the position of the address data buffer (pointing to the start of the next block) onto the stack.
Set up the current screen position, the positioning data and the UDG data block.
5F99 LD HL,($5F02) HL=The current screen address from Background_Screen_Address.
5F9C EX DE,HL Switch DE and HL so DE now holds the screen address and HL holds the start of the positioning data block.
5F9D CALL Background_Fetch_Next Call Background_Fetch_Next.
fgg
5FA0 LD HL,($5F02) HL=The current screen address from Background_Screen_Address.
5FA3 LD BC,$0080 Add 80 to HL.
5FA6 ADD HL,BC
5FA7 BIT 0,H Set the zero flag if we're at a screen section boundary. Skip forward to Background_No_Boundary if not.
5FA9 JR Z,Background_No_Boundary
5FAB LD A,$07 Add 07 to the MSB of HL to handle moving between screen sections.
5FAD ADD A,H
5FAE LD H,A
Background_No_Boundary 5FAF LD ($5F02),HL Stash HL at Background_Screen_Address.
5FB2 POP HL Restores HL and the counter from the stack.
5FB3 POP BC
5FB4 DJNZ Create_Background_Loop Decrease counter by one and loop back to Create_Background_Loop until counter is zero.
Finally, now write the attributes and return.
5FB6 LD E,(HL) Fetch the last address from the Background address data buffer which is the attributes data and call Background_Attributes to process and display in the attributes buffer.
5FB7 INC HL
5FB8 LD D,(HL)
5FB9 EX DE,HL
5FBA CALL Background_Attributes
5FBD RET Return.
Fetch the next positioning data and check for the terminator.
Background_Fetch_Next 5FBE LD A,(HL) Fetch the next positioning data byte.
5FBF INC HL Increase HL by one to point to the next byte.
5FC0 CP (HL) Check if this byte is the same as the previous positioning data byte value.
5FC1 JR NZ,Background_Process Jump to Background_Process if the values are different.
5FC3 AND A Double zero is the terminator, so jump to Background_Return to return if this is detected.
5FC4 JR Z,Background_Return
Process the UDG data.
Background_Process 5FC6 BIT 7,A Check if d7 is set, reset it regardless.
5FC8 RES 7,A
5FCA PUSH AF Push the new positioning data value onto the stack.
5FCB EXX Exchange the registers.
Point HL to the base address of the currently referenced UDG.
5FCC LD C,A Set the LSB of BC to A, and the MSB to 00.
5FCD LD B,$00
5FCF LD L,C Copy the same value into HL.
5FD0 LD H,B
5FD1 ADD HL,BC * 8.
5FD2 ADD HL,HL
5FD3 ADD HL,HL
5FD4 LD BC,($5F08) BC=Fetch the address of the start of the UDG data block from Background_UDG_Data.
5FD8 ADD HL,BC Choose the referenced UDG and store this at Background_Current_UDG.
5FD9 LD ($5F04),HL
5FDC EXX Restore the registers.
5FDD CALL Copy_UDG Call Copy_UDG.
5FE0 CALL Background_Next_Screen_Block Call Background_Next_Screen_Block.
Check if the flag for repetition is set, if so - action it. If not, jump and work on the next position.
5FE3 POP AF Fetch the position data off the stack, as this is AF this also restores the d7 check flag.
5FE4 JR Z,Background_Fetch_Next Jump back to Background_Fetch_Next unless the bit was set.
Using the following position data byte as a counter, copy the current byte this number of times.
5FE6 LD B,(HL) Pick up the position data from HL and store it in B to use as a counter.
5FE7 INC HL Increment HL to point to the next item of position data.
5FE8 DEC B Decrease the counter by one.
Background_Repeat_Copy 5FE9 CALL Copy_UDG Call Copy_UDG.
5FEC CALL Background_Next_Screen_Block Call Background_Next_Screen_Block.
5FEF DJNZ Background_Repeat_Copy Decrease counter by one and loop back to Background_Repeat_Copy until the counter is zero.
5FF1 JR Background_Fetch_Next Jump back round to Background_Fetch_Next.
Used to "just return" after flag checking operations.
Background_Return 5FF3 RET Return.
Copy a single UDG 8x8 block to the screen.
Copy_UDG 5FF4 PUSH DE Push DE (current screen location) and HL (next position data location) onto the stack.
5FF5 PUSH HL
5FF6 LD A,$08 Set a counter of 08 for the number of lines in a character block.
5FF8 LD HL,($5F04) HL=the currently targeted UDG address.
Copy_UDG_Loop 5FFB EX AF,AF' Stash the counter for later.
5FFC LD A,(HL) Copy the UDG data held by HL into the screen buffer currently pointed to by DE.
5FFD LD (DE),A
5FFE INC HL Increment HL by one to point to the next line of the UDG data.
5FFF INC D Increment the MSB of DE by one to point to the line directly below in the screen buffer.
6000 EX AF,AF' Restore the counter.
6001 DEC A Decrease the counter by one.
6002 JR NZ,Copy_UDG_Loop Loop back to Copy_UDG_Loop until the counter is zero.
6004 POP HL Restore the original HL and DE values for screen location and position data from the stack.
6005 POP DE
6006 RET Return.
Handles moving from one screen location block to the next.
Background_Next_Screen_Block 6007 INC DE Increase DE by 1.
6008 BIT 0,D Return if d0 is not set on the MSB of DE. This checks to see if we're at a screen boundary.
600A RET Z
600B LD A,$07 Add 07 to D, so that DE points to the next block down.
600D ADD A,D
600E LD D,A
600F RET Return.
Prev: 5F22 Up: Map Next: 6010