Prev: 27671 Up: Map Next: 27803
27672: Alter UDG references in the play area for a door, a window, a cup or the bike
Used by the routines at 24028, 27860, 28736 and 64077. The UDG reference tables used by this routine are organised into entries of four bytes each. Each entry corresponds to a single UDG within the matrix of UDGs for the door, window, cup or bike:
Byte Contents
1 y-coordinate
2 x-coordinate
3 UDG reference
4 (bits 0-3) BRIGHT/PAPER attributes
4 (bits 6 & 7) UDG base page identifier
The data tables used are located as follows:
Address Object
56637 Left study door (closed)
56893 Left study door (open)
57088 Right study door (closed)
57344 Right study door (open)
56576 Science Lab storeroom door (closed)
56832 Science Lab storeroom door (open)
57149 Boys' skool door (closed)
57405 Boys' skool door (open)
63744 Skool gate (closed)
64000 Skool gate (open)
56064 Drinks cabinet door (closed)
56320 Drinks cabinet door (open)
55040 Top-floor window (closed)
55296 Top-floor window (open)
55552 Middle-floor window (closed)
55808 Middle-floor window (open)
56081 Cups in the boys' skool (empty)
56694 Leftmost cup in the boys' skool (containing water)
56699 Leftmost cup in the boys' skool (containing sherry)
56950 Middle cup in the boys' skool (containing water)
56955 Middle cup in the boys' skool (containing sherry)
57206 Rightmost cup in the boys' skool (containing water)
57211 Rightmost cup in the boys' skool (containing sherry)
56337 Cup in the girls' skool (empty)
57462 Cup in the girls' skool (containing water)
57467 Cup in the girls' skool (containing sherry)
57600 Tree (with no bike attached)
57856 Tree (with bike attached)
Input
HL UDG reference table address
27672 LD A,(HL) Pick up the y-coordinate (Y) in D
27673 LD D,A
27674 INC A Return if we found the end-of-table marker (255)
27675 RET Z
27676 INC HL Point HL at byte 2 of this table entry
27677 LD E,(HL) Pick up the x-coordinate (X) in E
27678 INC HL Point HL at byte 3 of this table entry
27679 PUSH HL
27680 LD A,(32767) C=leftmost column of the play area on screen
27683 LD C,A
27684 LD A,E Jump if (X,Y) is off-screen (no need to update the screen refresh buffer)
27685 SUB C
27686 JR C,27717
27688 CP 32
27690 JR NC,27717
(X,Y) corresponds to a location that is currently on-screen, so we have to update the screen refresh buffer (SRB).
27692 LD C,A 0<=C<=31 (screen x-coordinate)
27693 AND 7 Point HL at an entry in the 8-byte table at 57720, whose contents are (128, 64, 32, 16, 8, 4, 2, 1)
27695 ADD A,120
27697 LD L,A
27698 LD H,225
27700 LD B,(HL) Pick up this entry in B
27701 LD A,C 0<=A<=31 (screen x-coordinate)
27702 RRCA Point HL at the byte of the SRB corresponding to (X,Y)
27703 RRCA
27704 RRCA
27705 AND 3
27707 ADD A,D
27708 ADD A,D
27709 ADD A,D
27710 ADD A,D
27711 LD L,A
27712 LD H,127
27714 LD A,(HL) Set the appropriate bit in the SRB byte
27715 OR B
27716 LD (HL),A
The UDG reference (i.e. the LSB of the base address of the skool UDG) for the skool location (X,Y) must be modified to reflect the change in status of the door, window, cup or bike.
27717 LD L,E Point HL at the Q value (0<=Q<=143) in page 181 for the x-coordinate X (see 24684)
27718 LD H,181
27720 LD E,(HL) Pick up the Q value in E
27721 LD A,D Set DE to the address where the UDG reference for (X,Y) is stored
27722 ADD A,160
27724 LD D,A
27725 POP HL Point HL at byte 3 of the table entry
27726 LD A,(HL) Pick up the replacement UDG reference in A
27727 INC HL Point HL at byte 4 of the table entry
27728 LD (DE),A Replace the UDG reference for the skool location (X,Y) with the one collected from the table entry
The attribute byte for the skool location (X,Y) must be modified too.
27729 LD A,(HL) Pick up byte 4 of the table entry in A
27730 AND 15 Keep only bits 0-3 (the BRIGHT and PAPER attributes)
27732 LD B,A Copy them to B
27733 LD A,E A=Q (0<=Q<=143)
27734 LD C,A Save the Q value in C for later
27735 ADD A,104 Point DE at byte 180+INT(Q/2) of page Y+160, where the BRIGHT and PAPER attributes for the skool location (X,Y) are stored
27737 SCF
27738 RRA
27739 LD E,A
27740 JR C,27753 Jump if Q is odd (BRIGHT and PAPER in bits 0-3)
27742 LD A,B Shift the BRIGHT and PAPER attributes from bits 0-3 to bits 4-7 of B
27743 RRCA
27744 RRCA
27745 RRCA
27746 RRCA
27747 LD B,A
27748 LD A,(DE) Pick up the current attribute byte for the skool location (X,Y), keeping bits 0-3 as they are
27749 AND 15
27751 JR 27756 Jump forward to adjust bits 4-7 appropriately
27753 LD A,(DE) Pick up the current attribute byte for the skool location (X,Y), keeping bits 4-7 as they are
27754 AND 240
27756 OR B Adjust bits 0-3 (if Q is odd) or bits 4-7 (Q is even) of the attribute byte for the skool location (X,Y)
27757 LD (DE),A
Finally, the base page (128, 136, 144 or 152) for the new skool UDG reference must be set.
27758 LD A,(HL) Pick up byte 4 of the table entry in A again
27759 AND 192 Keep only bits 6 and 7
27761 BIT 6,A Set B=10001000 if these bits are 11, 10000000 (10), 00001000 (01) or 00000000 (00)
27763 JR Z,27767
27765 SUB 56
27767 LD B,A
27768 LD A,C A=Q
27769 LD C,136 C=10001000
27771 SRL A Set A=INT(Q/4), and shift B and C right (Q AND 3) times
27773 JR NC,27779
27775 RRC B
27777 RRC C
27779 SRL A
27781 JR NC,27791
27783 RRC B
27785 RRC C
27787 RRC B
27789 RRC C
27791 ADD A,144 Point DE at byte 144+INT(Q/4) of page Y+160, where the UDG MSB identifier bit-pair for skool location (X,Y) is held (see 24684)
27793 LD E,A
27794 LD A,(DE) Pick up the current MSB identifier byte in A
27795 OR C Replace bits (0,4), (1,5), (2,6) or (3,7) in this byte with the corresponding bits in B
27796 XOR C
27797 OR B
27798 LD (DE),A Store the new MSB identifier byte
Move to the next entry in the table.
27799 INC HL Point HL at the first byte of the next entry in the table
27800 JP 27672 Jump back to process it
Prev: 27671 Up: Map Next: 27803