Routines
| Prev: A1C7 | Up: Map | Next: A24D |
A20C: Join free block IX to the next one if they touch
|
Used by A1C7. NZ if there is no next free block; Z after joining (sizes added, link taken over).
How it works:
1. Work out the address just past this free block: its start plus the size held in its first two bytes.
2. Read the link to the next free block. If there is none, return NZ.
3. If the next free block does not start at exactly that address, return NZ: there is a gap between them.
4. Otherwise add the next block's size to this one's and take over the next block's link, which unhooks it from the list, and return Z.
|
||||||||||||
| A20C | PUSH IX | Save IX on the stack - HL = the start of this block (the size word sits at IX-2) | ||||||||||
| A20E | POP HL | Restore HL from the stack | ||||||||||
| A20F | DEC HL | Step HL back one byte | ||||||||||
| A210 | DEC HL | Step HL back one byte | ||||||||||
| A211 | LD E,(IX-$02) | Read byte -2 of the record at IX into E - Add its size: HL = the address just past it | ||||||||||
| A214 | LD D,(IX-$01) | Read byte -1 of the record at IX into D | ||||||||||
| A217 | ADD HL,DE | Add DE to HL | ||||||||||
| A218 | LD E,(IX+$00) | Read the first byte of the record at IX into E - DE = the link to the next free block | ||||||||||
| A21B | LD D,(IX+$01) | Read byte +1 of the record at IX into D | ||||||||||
| A21E | LD A,D | Copy D into A - No next block: return NZ (nothing to join) | ||||||||||
| A21F | OR E | Set in A the bits that are set in E | ||||||||||
| A220 | JR NZ,$A225 | If the result is not zero, skip ahead to A225 | ||||||||||
| A222 | OR $01 | Make A non-zero, which clears the zero flag, and hand that back to the caller | ||||||||||
| A224 | RET | Return to the caller | ||||||||||
| A225 | AND A | Clear the carry flag, so that the subtraction that follows is a plain one (a compare) - Does this block end where the next one starts? If not, return NZ | ||||||||||
| A226 | SBC HL,DE | Subtract DE from HL (a compare: carry = HL was smaller, zero = equal) | ||||||||||
| A228 | RET NZ | If the two values differ, return | ||||||||||
| A229 | LD L,(IX+$00) | Read the first byte of the record at IX into L - Yes: HL points at the next block | ||||||||||
| A22C | LD H,(IX+$01) | Read byte +1 of the record at IX into H | ||||||||||
| A22F | PUSH BC | Save BC on the stack | ||||||||||
| A230 | LD E,(HL) | Read the byte HL points at into E - DE = its size, BC = its link | ||||||||||
| A231 | INC HL | Step HL on to the next byte | ||||||||||
| A232 | LD D,(HL) | Read the byte HL points at into D | ||||||||||
| A233 | INC HL | Step HL on to the next byte | ||||||||||
| A234 | LD C,(HL) | Read the byte HL points at into C | ||||||||||
| A235 | INC HL | Step HL on to the next byte | ||||||||||
| A236 | LD B,(HL) | Read the byte HL points at into B | ||||||||||
| A237 | LD L,(IX-$02) | Read byte -2 of the record at IX into L - Add its size to this block's | ||||||||||
| A23A | LD H,(IX-$01) | Read byte -1 of the record at IX into H | ||||||||||
| A23D | ADD HL,DE | Add DE to HL | ||||||||||
| A23E | LD (IX-$02),L | Store L in byte -2 of the record at IX | ||||||||||
| A241 | LD (IX-$01),H | Store H in byte -1 of the record at IX | ||||||||||
| A244 | LD (IX+$00),C | Store C in the first byte of the record at IX - and take over its link, unhooking it from the chain | ||||||||||
| A247 | LD (IX+$01),B | Store B in byte +1 of the record at IX | ||||||||||
| A24A | POP BC | Restore BC from the stack | ||||||||||
| A24B | XOR A | Set A to zero, which sets the zero flag for the caller - Return Z: joined | ||||||||||
| A24C | RET | Return to the caller | ||||||||||
| Prev: A1C7 | Up: Map | Next: A24D |