Prev: 41242 Up: Map Next: 41354
41244: Allocate Memory
Grows the workspace at 40931 by the size asked for, plus a three-byte header, and returns the new block.
AllocateMemory 41244 PUSH IY Add 3 to the total.
41246 PUSH HL
41247 PUSH DE
41248 PUSH BC
41249 ADD A,3
41251 LD C,A
41252 LD B,0 Start the free-space search and read the list at 40931.
41254 LD HL,(40931)
41257 LD IY,40931 Point IY at the free-space list (40931).
AllocateMemory_Loop 41261 LD A,L Jump ahead to AllocateMemory_TestBitCountLink if the pointer is 0000.
41262 OR H
41263 JR Z,AllocateMemory_TestBitCountLink
41265 LD E,(HL) Jump ahead to AllocateMemory_Next when the high byte of this free block is set.
41266 INC HL
41267 LD D,(HL)
41268 INC HL
41269 LD A,D
41270 AND A
41271 JR NZ,AllocateMemory_Next
41273 LD A,E Jump ahead to AllocateMemory_NextBlock if the first value is below the second.
41274 CP C
41275 JR C,AllocateMemory_NextBlock
AllocateMemory_Next 41277 BIT 0,B Jump ahead to AllocateMemory_KeepAllocationRemember if bit 0 is clear.
41279 JR Z,AllocateMemory_KeepAllocationRemember
41281 PUSH HL Read the pointer saved ahead of this record.
41282 LD L,(IX-2)
41285 LD H,(IX-1)
41288 AND A Compare HL with DE.
41289 SBC HL,DE
41291 POP HL Restore HL from the stack.
41292 JR C,AllocateMemory_NextBlock Jump ahead to AllocateMemory_NextBlock if HL was below DE.
AllocateMemory_KeepAllocationRemember 41294 PUSH HL Copy the allocation into IX and remember the caller's index.
41295 POP IX
41297 LD (41242),IY
41301 SET 0,B Set the mark on this character.
AllocateMemory_NextBlock 41303 PUSH HL Follow the next free block and repeat from AllocateMemory_Loop.
41304 POP IY
41306 LD E,(HL)
41307 INC HL
41308 LD D,(HL)
41309 EX DE,HL
41310 JR AllocateMemory_Loop
See whether bit 0 of the count is set, then read the link stored ahead of this record, then clear the high byte of the count.
AllocateMemory_TestBitCountLink 41312 BIT 0,B Jump ahead to StoreThatByteLinkAhead_JoinStep if bit 0 is clear.
41314 JR Z,StoreThatByteLinkAhead_JoinStep
41316 LD L,(IX-2) Read the pointer saved ahead of this record and count 0.
41319 LD H,(IX-1)
41322 LD B,0
41324 AND A Clear the carry before subtracting the block length from the free space.
41325 SBC HL,BC Measure the pointer against the count.
41327 LD A,H Read the high byte of the pointer.
41328 AND A Clear the carry so a zero high byte means only a few bytes of free space remain.
41329 JR NZ,StoreThatByteLinkAhead Jump to StoreThatByteLinkAhead when the free space still has a high byte.
41331 LD A,L Go to StoreThatByteLinkAhead if at least four bytes of free space remain.
41332 CP 4
41334 JR NC,StoreThatByteLinkAhead
41336 LD IY,(41242) Bring the saved index back from 41242 and read the character id.
41340 LD A,(IX+0)
41343 LD (IY+0),A Store the character id.
41346 LD A,(IX+1) Jump ahead to StoreThatByteLinkAhead_TestBytePreviousMemory to step to the next character record.
41349 LD (IY+1),A
41352 JR StoreThatByteLinkAhead_TestBytePreviousMemory
Prev: 41242 Up: Map Next: 41354