Prev: 24354 Up: Map Next: 24592
24448: 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
1 25194 24834
2 25738 24919
3 26714 25049
4 27362 25165
Attribute Data 24673
Create_Background 24448 LD HL,16512 The first screen address is 16512 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.
24451 LD (24322),HL
24454 LD HL,24336 HL=Background address data buffer.
Each background has 4 "sets" of data, so set a counter of 4.
24457 LD B,4 B=Initialise block counter.
The block processing loop.
Create_Background_Loop 24459 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.
24460 LD E,(HL) Pick up the next background UDG data block and store it at Background_UDG_Data.
24461 INC HL
24462 LD D,(HL)
24463 INC HL
24464 LD (24328),DE
24468 LD E,(HL) Fetch the address of the next positioning data block and store it in DE.
24469 INC HL
24470 LD D,(HL)
24471 INC HL
24472 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.
24473 LD HL,(24322) HL=The current screen address from Background_Screen_Address.
24476 EX DE,HL Switch DE and HL so DE now holds the screen address and HL holds the start of the positioning data block.
24477 CALL Background_Fetch_Next Call Background_Fetch_Next.
fgg
24480 LD HL,(24322) HL=The current screen address from Background_Screen_Address.
24483 LD BC,128 Add 128 to HL.
24486 ADD HL,BC
24487 BIT 0,H Set the zero flag if we're at a screen section boundary. Skip forward to Background_No_Boundary if not.
24489 JR Z,Background_No_Boundary
24491 LD A,7 Add 7 to the MSB of HL to handle moving between screen sections.
24493 ADD A,H
24494 LD H,A
Background_No_Boundary 24495 LD (24322),HL Stash HL at Background_Screen_Address.
24498 POP HL Restores HL and the counter from the stack.
24499 POP BC
24500 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.
24502 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.
24503 INC HL
24504 LD D,(HL)
24505 EX DE,HL
24506 CALL Background_Attributes
24509 RET Return.
Fetch the next positioning data and check for the terminator.
Background_Fetch_Next 24510 LD A,(HL) Fetch the next positioning data byte.
24511 INC HL Increase HL by one to point to the next byte.
24512 CP (HL) Check if this byte is the same as the previous positioning data byte value.
24513 JR NZ,Background_Process Jump to Background_Process if the values are different.
24515 AND A Double zero is the terminator, so jump to Background_Return to return if this is detected.
24516 JR Z,Background_Return
Process the UDG data.
Background_Process 24518 BIT 7,A Check if d7 is set, reset it regardless.
24520 RES 7,A
24522 PUSH AF Push the new positioning data value onto the stack.
24523 EXX Exchange the registers.
Point HL to the base address of the currently referenced UDG.
24524 LD C,A Set the LSB of BC to A, and the MSB to 0.
24525 LD B,0
24527 LD L,C Copy the same value into HL.
24528 LD H,B
24529 ADD HL,BC * 8.
24530 ADD HL,HL
24531 ADD HL,HL
24532 LD BC,(24328) BC=Fetch the address of the start of the UDG data block from Background_UDG_Data.
24536 ADD HL,BC Choose the referenced UDG and store this at Background_Current_UDG.
24537 LD (24324),HL
24540 EXX Restore the registers.
24541 CALL Copy_UDG Call Copy_UDG.
24544 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.
24547 POP AF Fetch the position data off the stack, as this is AF this also restores the d7 check flag.
24548 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.
24550 LD B,(HL) Pick up the position data from HL and store it in B to use as a counter.
24551 INC HL Increment HL to point to the next item of position data.
24552 DEC B Decrease the counter by one.
Background_Repeat_Copy 24553 CALL Copy_UDG Call Copy_UDG.
24556 CALL Background_Next_Screen_Block Call Background_Next_Screen_Block.
24559 DJNZ Background_Repeat_Copy Decrease counter by one and loop back to Background_Repeat_Copy until the counter is zero.
24561 JR Background_Fetch_Next Jump back round to Background_Fetch_Next.
Used to "just return" after flag checking operations.
Background_Return 24563 RET Return.
Copy a single UDG 8x8 block to the screen.
Copy_UDG 24564 PUSH DE Push DE (current screen location) and HL (next position data location) onto the stack.
24565 PUSH HL
24566 LD A,8 Set a counter of 8 for the number of lines in a character block.
24568 LD HL,(24324) HL=the currently targeted UDG address.
Copy_UDG_Loop 24571 EX AF,AF' Stash the counter for later.
24572 LD A,(HL) Copy the UDG data held by HL into the screen buffer currently pointed to by DE.
24573 LD (DE),A
24574 INC HL Increment HL by one to point to the next line of the UDG data.
24575 INC D Increment the MSB of DE by one to point to the line directly below in the screen buffer.
24576 EX AF,AF' Restore the counter.
24577 DEC A Decrease the counter by one.
24578 JR NZ,Copy_UDG_Loop Loop back to Copy_UDG_Loop until the counter is zero.
24580 POP HL Restore the original HL and DE values for screen location and position data from the stack.
24581 POP DE
24582 RET Return.
Handles moving from one screen location block to the next.
Background_Next_Screen_Block 24583 INC DE Increase DE by 1.
24584 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.
24586 RET Z
24587 LD A,7 Add 7 to D, so that DE points to the next block down.
24589 ADD A,D
24590 LD D,A
24591 RET Return.
Prev: 24354 Up: Map Next: 24592