Prev: F3A2 Up: Map Next: F48E
F3C2: Drawing
Used by the routine at ProcessTextToken.
Draws one location picture from line, fill and attribute commands. Pictures are not bitmaps. The pen starts at X=7F and Y=3F (Y counts up from the bottom, so this is screen row 112). 00 ends the picture. 08 followed by two bytes moves the pen. Bit 7 draws a line, bit 6 fills, and bit 5 paints attributes.
Keep the caller's state and aim at the picture.
Drawing F3C2 PUSH IY Keep the caller's registers and aim IY at the picture passed in HL.
F3C4 PUSH HL
F3C5 PUSH HL
F3C6 POP IY
F3C8 PUSH DE
F3C9 PUSH BC
Put the pen at its starting position.
F3CA LD D,$7F Start the pen at X=7F and Y=3F (screen row 112), with the line counters at 01.
F3CC LD E,$3F
F3CE LD B,$01
F3D0 LD C,$01
F3D2 LD L,$01
Each command is one byte. 00 ends the picture.
Drawing_Loop F3D4 LD A,(IY+$00) Finish the picture when the command byte is 00.
F3D7 AND A
F3D8 JP Z,Drawing_Finish
08 moves the pen to the two coordinates that follow.
F3DB INC IY Step past this command and jump ahead to Drawing_Line unless it is 08.
F3DD CP $08
F3DF JR NZ,Drawing_Line
F3E1 LD D,(IY+$00) Read the new X and mark it as a move.
F3E4 SET 7,D
F3E6 INC IY
F3E8 LD E,(IY+$00) Read the new Y and take the next command.
F3EB INC IY
F3ED JR Drawing_Loop
A set bit 7 is a line. Bits 0-2 choose the direction, and the next byte's top bits are the step and its low six bits the length.
Drawing_Line F3EF BIT 7,A Jump to Drawing_Fill if this command does not draw a line.
F3F1 JR Z,Drawing_Fill
F3F3 LD B,A The line direction is bits 0-2 of the command.
F3F4 AND $07
F3F6 LD C,A
F3F7 LD A,B Keep the command's other line field.
F3F8 RRCA
F3F9 AND $3C
F3FB LD B,A
F3FC LD A,(IY+$00) The next byte's low six bits are the line length.
F3FF AND $3F
F401 LD L,A
F402 INC L
F403 LD A,(IY+$00) The top bits of that byte choose the step.
F406 INC IY
F408 RLCA
F409 RLCA
F40A AND $03
F40C OR B
F40D LD B,A
F40E INC B
F40F CALL DrawingLine Call DrawingLine to draw the line.
F412 JR Drawing_Loop Jump back to Drawing_Loop for the next command.
A set bit 6 is a fill. Bits 0-2 are the ink, and the next two bytes are the X and Y to fill from.
Drawing_Fill F414 BIT 6,A Jump to Drawing_Attribute if this command is not a fill.
F416 JR Z,Drawing_Attribute
F418 AND $07 Read the fill X and the ink colour.
F41A PUSH DE
F41B LD D,(IY+$00)
F41E SET 7,D
F420 INC IY
F422 LD E,(IY+$00) Read the fill Y.
F425 INC IY
F427 CALL DrawingFill Call DrawingFill to fill the shape.
F42A POP DE Restore the pen from the stack.
F42B JP Drawing_Loop Take the next command.
A set bit 5 paints attributes. Bits 0-2 become the paper colour, and the next bytes name the squares to paint.
Drawing_Attribute F42E BIT 5,A Take the next command unless this one paints attributes.
F430 JP Z,Drawing_Loop
F433 AND $07 Use bits 0-2 as the paper colour.
F435 RLCA
F436 RLCA
F437 RLCA
F438 PUSH HL
F439 PUSH DE
F43A PUSH BC
F43B LD C,A
F43C LD H,(IY+$00) Read the attribute address.
F43F INC IY
F441 LD A,(IY+$00)
F444 ADD A,$10 Add 10 to the low byte of the attribute address.
F446 LD L,A
F447 INC IY
Drawing_Run F449 LD A,(IY+$00) Stop this attribute run when the command is FF.
F44C INC IY
F44E CP $FF
F450 JR Z,Drawing_AttributeDone
F452 LD B,A The low two bits are the direction and the rest is the run length.
F453 AND $03
F455 LD E,A
F456 LD A,B
F457 RRCA
F458 RRCA
F459 AND $3F
F45B INC A
F45C LD B,A
Drawing_Paint F45D LD A,(HL) Flip the ink when it matches the paper colour being painted, so it stays visible.
F45E AND $07
F460 RLCA
F461 RLCA
F462 RLCA
F463 CP C
F464 JR NZ,Drawing_0
F466 XOR $38
Drawing_0 F468 RRCA Write the paper colour into the attribute byte.
F469 RRCA
F46A RRCA
F46B OR C
F46C LD (HL),A
F46D LD A,E
F46E AND A
Step up when the direction is up.
Drawing_Step F46F CALL Z,AttributeUp Call AttributeUp when the direction is up.
Step right when the direction is right.
F472 DEC A Count down to the rightward direction.
F473 CALL Z,AttributeRight Call AttributeRight when the direction is right.
Step down when the direction is down.
F476 DEC A Count down to the downward direction.
F477 CALL Z,AttributeDown Call AttributeDown when the direction is down.
Step left when the direction is left.
F47A DEC A Count down to the leftward direction.
F47B CALL Z,AttributeLeft Call AttributeLeft when the direction is left.
Repeat for every attribute in the run.
F47E DJNZ Drawing_Paint Repeat from Drawing_Paint for the length of the attribute run.
F480 JR Drawing_Run Read the next attribute run.
Join the next step.
The picture is finished.
Drawing_AttributeDone F482 POP BC Restore the pen from the stack.
F483 POP DE
F484 POP HL
F485 JP Drawing_Loop Take the next picture command.
Return.
Drawing_Finish F488 POP BC Restore the saved count, the saved source, the saved pointer and the saved picture command from the stack.
F489 POP DE
F48A POP HL
F48B POP IY
F48D RET Return.
View the equivalent code in;
Prev: F3A2 Up: Map Next: F48E