Prev: D2A2 Up: Map Next: D356
D2B2: OR a 16-pixel picture into the buffer
Used by the routine at DRAW_EDGE.
Draws an edge picture -- a height byte, then two bytes a row, the bottom row first -- at a pixel x and a line y, ORed into the screen buffer (BUFFER). The buffer's lines run up the screen, 24 bytes apiece: line $48 is the bottom of the play area and $B7 its top, and BUFFER_ADDRESS turns x and y into an address. Rows above the top are cut; rows below the bottom are skipped by CLIP_EDGE.
SP reads the picture, a row a POP, the real stack pointer kept in SAVED_SP; the game never enables interrupts. Four cases: x a multiple of 8 or not (bits 1 and 2 of x; bit 0 is ignored, so things move in steps of two pixels), and the first face or the second (DRAW_PASS), which is drawn mirrored. A shifted row covers three buffer bytes, through a pair of pages built by MAKE_TABLES: the part of each picture byte that stays in its buffer byte and the part that falls into the next. The pages at SHIFT_TABLES shift; the ones at MIRROR_TABLES reverse a byte and shift it, for the mirrored face, which also takes the row's two bytes the other way round. An aligned mirrored row reverses each byte through REVERSE_TABLE.
Input
D the y of its bottom row
E its x
HL the picture
PUT_EDGE D2B2 LD A,D Starting below the play area: CLIP_EDGE
D2B3 SUB $48
D2B5 JR C,CLIP_EDGE
D2B7 SUB $70 At or above its top: nothing
D2B9 RET NC
D2BA NEG A = the rows: the height, or as many as fit below the top
D2BC CP (HL)
D2BD JR C,PUT_EDGE_0
D2BF LD A,(HL)
PUT_EDGE_0 D2C0 INC HL
This entry point is used by the routine at CLIP_EDGE.
PUT_EDGE_1 D2C1 EX AF,AF' The count into A'; DE = the buffer address (BUFFER_ADDRESS)
D2C2 EX DE,HL
D2C3 CALL BUFFER_ADDRESS
D2C6 EX DE,HL
D2C7 LD (SAVED_SP),SP SP onto the picture's rows
D2CB LD SP,HL
D2CC LD A,(DRAW_X) Aligned: the plain cases
D2CF AND $06
D2D1 JR Z,PUT_EDGE_6
D2D3 OR $F0 H = $F2, $F4 or $F6, the reversing and shifting pages for a shift of 2, 4 or 6 pixels
D2D5 LD H,A
D2D6 LD A,(DRAW_PASS) The second face is mirrored
D2D9 AND A
D2DA JR NZ,PUT_EDGE_4
D2DC SET 3,H The first: H = $FA, $FC or $FE, the shifting pages
D2DE EX AF,AF'
PUT_EDGE_2 D2DF EX AF,AF' A row: the first byte's part that stays, into the first buffer byte
D2E0 POP BC
D2E1 LD L,C
D2E2 LD A,(DE)
D2E3 OR (HL)
D2E4 LD (DE),A
D2E5 INC DE
D2E6 INC H The part that falls out of it and the second byte's part that stays, into the second
D2E7 LD A,(DE)
D2E8 OR (HL)
D2E9 DEC H
D2EA LD L,B
D2EB OR (HL)
D2EC LD (DE),A
D2ED INC DE The part that falls out of the second, into the third
D2EE INC H
D2EF LD A,(DE)
D2F0 OR (HL)
D2F1 LD (DE),A
D2F2 DEC H
D2F3 EX DE,HL Up a line, 24 bytes on from the first; until the rows run out
D2F4 LD BC,$0016
D2F7 ADD HL,BC
D2F8 EX DE,HL
D2F9 EX AF,AF'
D2FA DEC A
D2FB JR NZ,PUT_EDGE_2
PUT_EDGE_3 D2FD LD SP,(SAVED_SP) The real stack pointer back
D301 RET
PUT_EDGE_4 D302 EX AF,AF' Mirrored: the same, with the row's second byte first, through the reversing pages
PUT_EDGE_5 D303 EX AF,AF'
D304 POP BC
D305 LD L,B
D306 LD A,(DE)
D307 OR (HL)
D308 LD (DE),A
D309 INC DE
D30A INC H
D30B LD A,(DE)
D30C OR (HL)
D30D DEC H
D30E LD L,C
D30F OR (HL)
D310 LD (DE),A
D311 INC DE
D312 INC H
D313 LD A,(DE)
D314 OR (HL)
D315 LD (DE),A
D316 DEC H
D317 EX DE,HL
D318 LD BC,$0016
D31B ADD HL,BC
D31C EX DE,HL
D31D EX AF,AF'
D31E DEC A
D31F JR NZ,PUT_EDGE_5
D321 JR PUT_EDGE_3
PUT_EDGE_6 D323 EX DE,HL Aligned: the two bytes ORed in as they are
D324 LD A,(DRAW_PASS)
D327 AND A
D328 JR NZ,PUT_EDGE_8
D32A LD BC,$0017
D32D EX AF,AF'
PUT_EDGE_7 D32E EX AF,AF'
D32F POP DE
D330 LD A,(HL)
D331 OR E
D332 LD (HL),A
D333 INC HL
D334 LD A,(HL)
D335 OR D
D336 LD (HL),A
D337 ADD HL,BC
D338 EX AF,AF'
D339 DEC A
D33A JR NZ,PUT_EDGE_7
D33C JR PUT_EDGE_3
PUT_EDGE_8 D33E LD B,$F9 Aligned and mirrored: each byte reversed (REVERSE_TABLE), the second first
D340 EX AF,AF'
PUT_EDGE_9 D341 EX AF,AF'
D342 POP DE
D343 LD C,D
D344 LD A,(BC)
D345 OR (HL)
D346 LD (HL),A
D347 INC HL
D348 LD C,E
D349 LD A,(BC)
D34A OR (HL)
D34B LD (HL),A
D34C LD DE,$0017
D34F ADD HL,DE
D350 EX AF,AF'
D351 DEC A
D352 JR NZ,PUT_EDGE_9
D354 JR PUT_EDGE_3
Prev: D2A2 Up: Map Next: D356