Prev: 48735 Up: Map Next: 49002
48930: Sort Draw List
Used by the routine at MainLoop.
Sorts the draw list, so that the sprites that are highest up the screen are drawn first. Sprites at the same height are drawn from left to right. It is a bubble sort, which is repeated until there is a pass without any swaps.
SortDrawList 48930 LD A,(54104) Return if there are fewer than two entries in the list.
48933 AND A
48934 RET Z
SortDrawList_Pass 48935 LD DE,54103 Point DE at the height of the first entry.
48938 LD HL,54106 Point HL at DrawListEntries_SecondHeight.
48941 XOR A Clear the flag that records that a swap was made.
48942 EX AF,AF'
SortDrawList_Compare 48943 LD A,(DE) Fetch the height of the first entry...
48944 CP (HL) ...and compare it with the height of the second.
48945 DEC HL Point at the horizontal positions.
48946 DEC DE
48947 JR C,SortDrawList_Swap Jump to swap them if the first is lower.
48949 JR NZ,SortDrawList_InOrder Jump if the first is higher, as they are in order.
48951 LD A,(DE) Otherwise fetch the horizontal position of the first entry.
48952 LD C,A
48953 LD A,(HL) Compare it with the horizontal position of the second.
48954 CP C
48955 JR NC,SortDrawList_InOrder Jump if they are in order.
SortDrawList_Swap 48957 EX AF,AF' Record that a swap has been made.
48958 OR 1
48960 EX AF,AF'
48961 DEC HL Point at the types.
48962 DEC DE
48963 LD A,(DE) Swap the types.
48964 LD C,(HL)
48965 LD (HL),A
48966 LD A,C
48967 LD (DE),A
48968 INC DE Point at the horizontal positions.
48969 INC HL
48970 LD A,(DE) Swap the horizontal positions.
48971 LD C,(HL)
48972 LD (HL),A
48973 LD A,C
48974 LD (DE),A
48975 INC DE Point at the heights.
48976 INC HL
48977 LD A,(DE) Swap the heights.
48978 LD C,(HL)
48979 LD (HL),A
48980 LD A,C
48981 LD (DE),A
SortDrawList_Advance 48982 INC DE Point at the type of the next entry.
48983 INC HL
48984 LD A,(HL) Jump if there are no more entries.
48985 AND A
48986 JR Z,SortDrawList_Finish
48988 INC DE Point at the heights of the entries.
48989 INC HL
48990 INC DE
48991 INC HL
48992 JR SortDrawList_Compare Loop back to compare them.
SortDrawList_Finish 48994 EX AF,AF' Go round again if any swap was made.
48995 JR NZ,SortDrawList_Pass
48997 RET Return.
SortDrawList_InOrder 48998 INC DE Point at the heights and jump.
48999 INC HL
49000 JR SortDrawList_Advance
Prev: 48735 Up: Map Next: 49002