| The Hobbit (v1.0) | Routines |
| Prev: 8A4D | Up: Map | Next: 8ACC |
|
Fills the area around the point (D,E) with ink colour A (kept at 8C2C for 8B93). It is a scan-line fill: from the starting point it moves left to the edge of the area, then works rightwards along the row, setting each pixel. At every pixel it looks at the pixel above and the pixel below: where an unfilled stretch begins in the row above or below, that position is pushed on the stack as a 'seed' to be filled later. The flags at 8A4D (above) and $8A4E (below) stop it pushing a seed for every pixel of the same stretch. When the row is done, the next seed is popped and the process repeats, until the marker $0080 pushed at the start comes back off the stack.
Because each row is filled from its left-hand end, and seeds are only pushed at the starts of stretches, the fill needs very little stack even for large areas.
|
||||||||||||
| 8A4F | LD ($8C2C),A | Save the fill colour | ||||||||||
| 8A52 | PUSH DE | |||||||||||
| 8A53 | PUSH HL | |||||||||||
| 8A54 | LD HL,$0080 | Push the end marker (a y value of $80 is impossible) | ||||||||||
| 8A57 | PUSH HL | |||||||||||
| 8A58 | CALL $8ACC | Is the pixel at (D,E) set? | ||||||||||
| 8A5B | JR NZ,$8A64 | Yes: we have found the left-hand boundary | ||||||||||
| 8A5D | CALL $8B26 | No: move left | ||||||||||
| 8A60 | JR NZ,$8A58 | Keep going until a set pixel or the edge | ||||||||||
| 8A62 | JR $8A6A | At the left edge of the picture: start here | ||||||||||
| 8A64 | CALL $8B93 | Colour the boundary pixel... | ||||||||||
| 8A67 | CALL $8B1F | ...and step right onto the first empty pixel | ||||||||||
| 8A6A | LD HL,$0000 | Not yet tracking a stretch above or below | ||||||||||
| 8A6D | LD ($8A4D),HL | |||||||||||
| 8A70 | CALL $8B09 | Look at the pixel above | ||||||||||
| 8A73 | LD A,$00 | |||||||||||
| 8A75 | JR Z,$8A8C | At the top edge: nothing to do above | ||||||||||
| 8A77 | CALL $8ACC | Is it set? | ||||||||||
| 8A7A | LD A,$00 | |||||||||||
| 8A7C | JR NZ,$8A87 | Set: not part of the area | ||||||||||
| 8A7E | LD A,($8A4D) | Empty. Already tracking this stretch above? | ||||||||||
| 8A81 | AND A | |||||||||||
| 8A82 | JR NZ,$8A87 | Yes: no new seed | ||||||||||
| 8A84 | PUSH DE | No: push it as a seed | ||||||||||
| 8A85 | LD A,$01 | ...and start tracking | ||||||||||
| 8A87 | PUSH AF | |||||||||||
| 8A88 | CALL $8B18 | Back down to the current row | ||||||||||
| 8A8B | POP AF | |||||||||||
| 8A8C | LD ($8A4D),A | Remember whether we are tracking above | ||||||||||
| 8A8F | CALL $8B18 | Look at the pixel below | ||||||||||
| 8A92 | LD A,$00 | |||||||||||
| 8A94 | JR Z,$8AAB | At the bottom edge: nothing to do below | ||||||||||
| 8A96 | CALL $8ACC | Is it set? | ||||||||||
| 8A99 | LD A,$00 | |||||||||||
| 8A9B | JR NZ,$8AA6 | Set: not part of the area | ||||||||||
| 8A9D | LD A,($8A4E) | Empty. Already tracking this stretch below? | ||||||||||
| 8AA0 | AND A | |||||||||||
| 8AA1 | JR NZ,$8AA6 | Yes: no new seed | ||||||||||
| 8AA3 | PUSH DE | No: push it as a seed | ||||||||||
| 8AA4 | LD A,$01 | ...and start tracking | ||||||||||
| 8AA6 | PUSH AF | |||||||||||
| 8AA7 | CALL $8B09 | Back up to the current row | ||||||||||
| 8AAA | POP AF | |||||||||||
| 8AAB | LD ($8A4E),A | Remember whether we are tracking below | ||||||||||
| 8AAE | CALL $8B93 | Fill this pixel | ||||||||||
| 8AB1 | CALL $8B1F | Step right | ||||||||||
| 8AB4 | JR Z,$8ABE | At the right edge: this row is done | ||||||||||
| 8AB6 | CALL $8ACC | Is the next pixel set? | ||||||||||
| 8AB9 | JR Z,$8A70 | No: carry on along the row | ||||||||||
| 8ABB | CALL $8B93 | Yes: colour the boundary pixel too | ||||||||||
| 8ABE | POP DE | Pop the next seed | ||||||||||
| 8ABF | LD A,E | Is it the end marker? | ||||||||||
| 8AC0 | CP $80 | |||||||||||
| 8AC2 | JR NZ,$8A58 | No: fill from there | ||||||||||
| 8AC4 | LD A,$00 | Done: reset the drawing colour | ||||||||||
| 8AC6 | LD ($8C2C),A | |||||||||||
| 8AC9 | POP HL | |||||||||||
| 8ACA | POP DE | |||||||||||
| 8ACB | RET | |||||||||||
| Prev: 8A4D | Up: Map | Next: 8ACC |