Prev: DC41 Up: Map Next: DD69
DD02: Item visible
This clips the given item's dimensions to the game window.
Counterpart of vischar_visible see that for further comments.
Used by the routine at setup_item_plotting.
Output
B Lefthand skip (bytes)
C Clipped width (bytes)
D Top skip (rows)
E Clipped height (rows)
F Z if visible, NZ otherwise
First handle the horizontal cases.
item_visible DD02 LD HL,$81B5 Point HL at iso_pos_x (item left edge)
Calculate the right edge of the window in map space.
DD05 LD DE,($81BB) Load map position (both X & Y)
DD09 LD A,E Extract X
DD0A ADD A,$18 Add 24 (number of window columns)
Subtract iso_pos_x giving the distance between the right edge of the window and the current item's left edge (in bytes).
DD0C SUB (HL) available_right = (map_position.x + 24) - item_left_edge
Check for case (E): Item left edge beyond the window's right edge.
DD0D JR Z,iv_not_visible Jump to exit if zero (item left edge at right edge)
DD0F JR C,iv_not_visible Jump to exit if negative (item left edge beyond right edge)
Check for case (D): Item extends outside the window.
DD11 CP $03 Compare result to (item width bytes (2) + 1)
DD13 JP NC,iv_not_clipped_on_right_edge Jump if it fits
Item's right edge is outside the window: clip its width.
DD16 LD B,$00 No lefthand skip
DD18 LD C,A Clipped width = available_right
DD19 JR iv_height Jump to height part
Calculate the right edge of the item.
iv_not_clipped_on_right_edge DD1B LD A,(HL) Load iso_pos_x (item left edge)
DD1C ADD A,$03 item_right_edge = iso_pos_x + (item width bytes (2) + 1)
Subtract the map position's X giving the distance between the current item's right edge and the left edge of the window (in bytes).
DD1E SUB E available_left = item_right_edge - map_position.x
Check for case (A): Item's right edge is beyond the window's left edge.
DD1F JR Z,iv_not_visible Jump to exit if zero (item right edge at left edge)
DD21 JR C,iv_not_visible Jump to exit if negative (item right edge beyond left edge)
Check for case (B): Item's left edge is outside the window and its right edge is inside the window.
DD23 CP $03 Compare result to (item width bytes (2) + 1)
DD25 JP NC,item_visible_0 Jump if it fits
Item's left edge is outside the window: move the lefthand skip into B and the clipped width into C.
DD28 LD C,A Clipped width = available_left
DD29 LD A,$03 Lefthand skip = (item width bytes (2) + 1) - available_left
DD2B SUB C
DD2C LD B,A
DD2D JR iv_height (else)
Case (C): No clipping required.
item_visible_0 DD2F LD B,$00 No lefthand skip
DD31 LD C,$03 Clipped width = (item width bytes (2) + 1)
Handle vertical cases.
Calculate the bottom edge of the window in map space.
iv_height DD33 LD A,D Load the map position's Y and add 17 (number of window rows)
DD34 ADD A,$11
Subtract item's Y giving the distance between the bottom edge of the window and the current item's top (in rows).
DD36 INC HL Point HL at iso_pos.y (item top edge)
DD37 SUB (HL) available_bottom = window_bottom_edge - iso_pos.y
Check for case (E): Item top edge beyond the window's bottom edge.
DD38 JR Z,iv_not_visible Jump to exit if zero (item top edge at bottom edge)
DD3A JR C,iv_not_visible Jump to exit if negative (item top edge beyond bottom edge)
Check for case (D): Item extends outside the window.
DD3C CP $02 Compare result to item_height (2)
DD3E JP NC,iv_not_clipped_on_top_edge Jump if it fits (available_top >= item_height)
Item's bottom edge is outside the window: clip its height.
DD41 LD E,$08 Clipped height = available_bottom (8)
DD43 LD D,$00 No top skip
DD45 JR iv_visible Jump to exit
Calculate the bottom edge of the item.
iv_not_clipped_on_top_edge DD47 LD A,(HL) item_bottom_edge = iso_pos.y + item_height (2)
DD48 ADD A,$02
Subtract map position's Y giving the distance between the current item's bottom edge and the top edge of the window (in rows).
DD4A SUB D available_top = item_bottom_edge - map_pos_y
Check for case (A): Item's bottom edge is beyond the window's top edge.
DD4B JR Z,iv_not_visible Jump to exit if zero (item bottom edge at top edge)
DD4D JR C,iv_not_visible Jump to exit if negative (item bottom edge beyond top edge)
Check for case (B): Item's top edge is outside the window and its bottom edge is inside the window.
DD4F CP $02 Compare result to item_height (2)
DD51 JP NC,item_visible_1 Jump if it fits (available_top >= item_height)
Item's top edge is outside the window: move the top skip into D and the clipped height into E.
DD54 LD A,($8214) Clipped height = item_height - 8
DD57 SUB $08
DD59 LD E,A
DD5A LD D,$08 Top skip = 8
DD5C JR iv_visible (else)
Case (C): No clipping required.
item_visible_1 DD5E LD D,$00 No top skip
DD60 LD A,($8214) Clipped height = item_height
DD63 LD E,A
iv_visible DD64 XOR A Set Z (item is visible)
DD65 RET Return
iv_not_visible DD66 OR $01 Clear Z (item is not visible)
DD68 RET Return
Prev: DC41 Up: Map Next: DD69