Prev: B09F Up: Map Next: B197
B0E6: Put a character into the sprite buffer
Used by the routines at B9D6, EFC7 and F177.
Input
IY The base address of the character buffer (BC67 - BC6B)
This routine was copied from a similar one in Pyjamarama.
B0E6 EXX Exchange main registers.
B0E7 LD E,(IY+$23) Put the graphic address in DE. (BC8A / BC8F)
B0EA LD D,(IY+$28)
B0ED LD ($A83B),SP Store a copy of the stack pointer. (A83B)
B0F1 LD H,(IY+$00) Put the frame number in HL.
B0F4 LD L,$00
B0F6 SRL H Halve it to get the correct offset.
B0F8 RR L
B0FA ADD HL,DE Add the base address.
B0FB LD SP,HL Point the stack at the graphic to draw.
B0FC LD A,(IY+$05) Get the X co-ordinate.
B0FF LD B,A Store this in B.
B100 AND $07 Put the bottom 3 bits (as the frame number) in B189 which modifies later code.
B102 LD ($B189),A
B105 INC A Add 1 and store in B129 and B145 which modifies later code.
B106 LD ($B129),A
B109 LD ($B145),A
B10C LD A,B Put the top 5 bits (as the byte) as a value in B17B which modifies later code.
B10D AND $F8
B10F RRCA
B110 RRCA
B111 RRCA
B112 LD ($B17B),A
B115 ADD A,$02 Add 2 and put this in E.
B117 LD E,A
B118 LD C,$20 14 rows to draw.
B11A LD L,(IY+$0A) Put the Y co-ordinate in HL.
B11D LD H,$00
B11F ADD HL,HL Multiply by 16 to get a suitable offset.
B120 ADD HL,HL
B121 ADD HL,HL
B122 ADD HL,HL
B123 ADD HL,HL
B124 LD D,$63 Set the high byte of DE to the sprite buffer.
B126 ADD HL,DE Add the offset.
B127 POP DE Put the next byte (mask) in DE.
B128 LD B,$00 Set B to the number of times to loop. (was modified earlier in the code)
B12A DEC B If this is frame 0, nothing else is needed here, and only two bytes need updating instead of three.
B12B JR Z,$B139
If this isn't frame 0, everything needs shifting to the right to be in sync.
B12D SCF Set the carry flag, so the following RR instructions put it in bit 7.
B12E LD A,$FF Set the initial mask as FF (all bits).
B130 RR E Rotate the mask in E, then through D, taking the carry flag through each time.
B132 RR D
B134 RRA Shift the mask by one pixel.
B135 DJNZ $B130 Loop while there is more to do.
At this point, HL points to the address in the sprite buffer to update.
B137 AND (HL) Do a logical AND of the byte against the mask in A.
B138 LD (HL),A
B139 DEC HL Move back an entry in the sprite buffer.
B13A LD A,(HL) Do a logical AND of the byte against the mask in D.
B13B AND D
B13C LD (HL),A
B13D DEC HL Move back an entry in the sprite buffer.
B13E LD A,(HL) Do a logical AND of the byte against the mask in E.
B13F AND E
B140 LD (HL),A
B141 INC HL Move forward to the next position in the buffer.
B142 INC HL
B143 POP DE Put the next byte (data) in DE.
B144 LD B,$00 Set B to the number of times to loop. (Was modified in earlier code)
B146 DEC B If this is frame 0, nothing else is needed here, and two bytes need updating instead of three. } If this isn't frame 0, everything needs shifting to the right to be in sync.
B147 JR Z,$B153
B149 XOR A Set the initial data as 0 (no bits).
B14A SRL E Rotate the byte in E, putting 0 in bit 7.
B14C RR D Rotate the byte in D, using the carry.
B14E RRA Shift the data by one pixel.
B14F DJNZ $B14A Loop while there is more to do.
B151 OR (HL) Do a logical OR of the byte against the data in A.
B152 LD (HL),A
B153 DEC HL Move back an entry in the sprite buffer.
B154 LD A,(HL) Do a logical OR of the byte against the data in D.
B155 OR D
B156 LD (HL),A
B157 DEC HL Move back an entry in the sprite buffer.
B158 LD A,(HL) Do a logical OR of the byte against the data in E.
B159 OR E
B15A LD (HL),A
B15B LD DE,$0022 Move to the next row.
B15E ADD HL,DE
B15F DEC C Decrement the number of rows left.
B160 JP NZ,$B127 Jump back if there are more rows to draw.
Now handle the attributes.
B163 LD A,(IY+$0A) Get the bottom 3 bits of the Y co-ordinate, as the sub-component.
B166 AND $07
B168 JR Z,$B16E If this equals 0, set 4 rows to draw, otherwise 45.
B16A LD B,$05
B16C JR $B170
B16E LD B,$04
B170 LD A,(IY+$0A) Get the top 5 bits of the Y co-ordinate, as the byte.
B173 AND $F8
B175 LD H,$00 Put this in HL.
B177 LD L,A
B178 ADD HL,HL Multiply by 4.
B179 ADD HL,HL
B17A LD DE,$FB00 Add the base address to get a location in the attribute buffer. (FC00)
B17D ADD HL,DE
B17E LD DE,$001E Set DE as the offset to move between rows.
B181 LD C,(IY+$1E) Put the attribute to use in C. (BC85)
B184 LD (HL),C Set the attribute for the next two bytes.
B185 INC HL
B186 LD (HL),C
B187 INC HL
B188 LD A,$FF Put the X offset in A. (This is modified by earlier code)
B18A OR A Is the offset zero?
B18B JR Z,$B18E If it is, jump forward, no more calculations needed.
B18D LD (HL),C Otherwise set the attribute for the third byte. which is needed on frames other than 0 that span a byte boundary.
B18E ADD HL,DE Move forward a row and back two columns.
B18F DJNZ $B184 Loop while there is more to draw.
B191 EXX Exchange main registers.
B192 LD SP,($A83B) Restore the stack and return.
B196 RET
Prev: B09F Up: Map Next: B197