Prev: 6065 Up: Map Next: 612E
606C: Print a tile
Used by the routines at 61C2, 61F8 and 62A0. Copies a tile of the play area into the back buffer at E170, superimposes character sprite tiles as appropriate, and then copies the resultant tile to the screen. Also sets the corresponding attribute byte.
The play area graphic data is laid out across pages 0x80 to 0xB5:
Page(s) Bytes Contents
0x80-0x87 0x00-0xFF Skool graphic data
0x88-0x8F 0x00-0xFF Skool graphic data
0x90-0x97 0x00-0xFF Skool graphic data (except bytes 0x01, 0x0B, 0x15, 0x1E)
0x98-0x9F 0x00-0xF9 Skool graphic data (except bytes 0xE0-0xEF)
0xA0-0xB4 0x00-0x8F LSBs of tile base addresses
0x90-0xB3 Tile MSB indicator bit-pairs (see below)
0xB4-0xFB Tile BRIGHT/PAPER attribute nibbles
0xB5 0x00-0xBF Q (0x00<=Q<=0x8F; see below)
For the tile at skool coordinates (X,Y) (0<=X<=191, 0<=Y<=20), the column pointer Q (0x00<=Q<=0x8F) is collected from byte X of page 0xB5. Then Q and Y together determine the location of the attribute byte, and where to look up the base address of the tile graphic data.
The BRIGHT/PAPER bits for row Y are arranged in a set of 144 nibbles in bytes 0xB4-0xFB of page Y+0xA0, from bits 7-4 of byte 0xB4 (nibble 0x00) to bits 3-0 of byte 0xFB (nibble 0x8F). Q is the index of the nibble that corresponds to the tile at (X,Y). In other words, the BRIGHT/PAPER bits for the skool location (X,Y) can be found in byte 0xB4+INT(Q/2) of page Y+0xA0: bits 4-7 if Q is even, bits 0-3 if Q is odd.
By default, the INK is 0 (black). However, if the BRIGHT/PAPER bits are all 0, this indicates a tile with non-black INK, of which there are normally four: the three shields in MR WACKER's study (which are red, blue, and red), and the top of the entrance to the girls' skool (which is blue). (However, when the left study door is open - which never happens in an unhacked game - there is a fifth tile with non-black INK: the top of the left study doorway, which is magenta.) When a tile has non-black INK, the BRIGHT/PAPER bits are taken from byte 0xB4+INT(Q/2) of page Y+0xA1 (i.e. the attribute byte corresponding to the skool location (X,Y+1)); then the INK is 2 (red) if Q is even, 1 (blue) if 4|Q-1, or 3 (magenta) if 4|Q-3.
So much for the attributes. The LSB of the base address of the tile graphic data is found in byte Q of page Y+0xA0. Information on which MSB (0x80, 0x88, 0x90 or 0x98) applies is arranged in a set of 144 bit-pairs in bytes 0x90-0xB3 of page Y+0xA0. Bit-pair 0x00 is bits 7 and 3 of byte 0x90; bit-pair 0x01 is bits 6 and 2; bit-pair 0x02 is bits 5 and 1; bit-pair 0x03 is bits 4 and 0; bit-pair 0x04 is bits 7 and 3 of byte 0x91; and so on up to bit-pair 0x8F, which is bits 4 and 0 of byte 0xB3. Q is the index of the bit-pair that corresponds to the tile at (X,Y). In other words, the tile MSB indicator for the skool location (X,Y) can be found in byte 0x90+INT(Q/4) of page Y+0xA0: bits 7 and 3 if 4|Q, 6 and 2 if 4|Q-1, 5 and 1 if 4|Q-2, 4 and 0 if 4|Q-3. The bit-pair forms a 2-digit binary number from 0 to 3; if we call this P, then the MSB is 0x80+8P.
To summarise, then, the attributes and graphic data for the tile at skool location (X,Y) can be found thus, where Q=PEEK(B500+X):
Data Look at...
BRIGHT/PAPER Nibble Q of bytes 0xB4-0xFB in page Y+0xA0 (or Y+0xA1 if nibble Q in page Y+0xA0 is 0)
INK 0 if nibble Q in page Y+0xA0 is not 0; 1, 2 or 3 as explained above otherwise
Tile LSB Byte Q in page Y+0xA0
Tile MSB Bit-pair Q of bytes 0x90-0xB3 in page Y+0xA0
Input
H Screen row number (0-20)
L Screen column number (0-31)
606C PUSH HL
606D LD A,H Compute the appropriate attribute file address in BC and the appropriate display file address in DE
606E AND $18
6070 LD D,A
6071 LD A,H
6072 RRCA
6073 RRCA
6074 RRCA
6075 LD H,A
6076 AND $E0
6078 ADD A,L
6079 LD E,A
607A LD C,A
607B LD A,H
607C AND $03
607E ADD A,$58
6080 LD B,A
6081 SET 6,D
6083 EX DE,HL Place the display file address on the stack and get (row,col) back in HL
6084 EX (SP),HL
6085 LD A,($7FFF) A=leftmost column of the play area on screen (0-160)
6088 ADD A,L L=X: column of the play area corresponding to the character square under consideration (0-191)
6089 LD L,A
608A PUSH HL Push the skool coordinates (X,Y) onto the stack
608B LD A,H A=Y (0-20)
608C LD H,$B5 HL=B500+X
608E LD L,(HL) L=Q (0x00<=Q<=0x8F)
608F ADD A,$A0 H=Y+0xA0
6091 LD H,A
6092 LD E,L E=Q (0x00<=Q<=0x8F)
6093 LD A,L A=Q
6094 RRA Is Q odd?
6095 JR C,$60B2 Jump if so
Q (the contents of (B500+X)) is even, which means the PAPER colour and BRIGHT status can be found in bits 4-7 of byte 0xB4+Q/2 in page Y+0xA0. At this point A=Q/2.
6097 ADD A,$B4 0xB4<=A<=0xFB
6099 LD L,A Point HL at the attribute byte
609A LD A,(HL) Pick up the attribute byte in A
609B AND $F0 The PAPER colour and BRIGHT status are in bits 4-7
609D RR A Shift them into bits 3-6
609F JR NZ,$60C6 Jump if this character square has INK 0
We are dealing with one of the few character squares with non-black INK. In this case the PAPER colour and BRIGHT status can be found in bits 4-7 (since Q is even) of byte 0xB4+Q/2 in page Y+0xA1.
60A1 INC H Point HL at the attribute byte in page Y+0xA1
60A2 LD A,(HL) Pick up the attribute byte in A
60A3 AND $F0 The PAPER colour and BRIGHT status are in bits 4-7
60A5 RRA Shift them into bits 3-6
60A6 LD L,A L holds the PAPER colour and BRIGHT status
60A7 LD A,E A=Q (0x00<=Q<=0x8F)
60A8 AND $03 A=0, 1, 2 or 3
60AA JR NZ,$60AE Jump if the INK is blue, red, or magenta
60AC ADD A,$02 A=2: INK 2 (red)
60AE OR L OR on the PAPER colour and BRIGHT status
60AF DEC H H=Y+0xA0
60B0 JR $60C6 Jump forward to transfer the attribute byte in A onto the screen
Q (the contents of (B500+X)) is odd, which means the PAPER colour and BRIGHT status can be found in bits 0-3 of byte 0xB4+(Q-1)/2 in page Y+0xA0. At this point A=(Q-1)/2.
60B2 ADD A,$B4 0xB4<=A<=0xFB
60B4 LD L,A Point HL at the attribute byte
60B5 LD A,(HL) Pick up the attribute byte in A
60B6 AND $0F The PAPER colour and BRIGHT status are in bits 0-3
60B8 JR NZ,$60C3 Jump if this character square has INK 0
We are dealing with one of the few character squares with non-black INK. In this case the PAPER colour and BRIGHT status can be found in bits 0-3 (since Q is odd) of byte 0xB4+(Q-1)/2 in page Y+0xA1.
60BA INC H Point HL at the attribute byte in page Y+0xA1
60BB LD A,(HL) Pick up the attribute byte in A
60BC AND $0F The PAPER colour and BRIGHT status are in bits 0-3
60BE ADD A,A Shift the PAPER and BRIGHT bits from bits 0-3 to bits 3-6
60BF ADD A,A
60C0 ADD A,A
60C1 JR $60A6 Jump back to fill in the INK bits
60C3 ADD A,A Shift the PAPER and BRIGHT bits from bits 0-3 to bits 3-6, and set the INK to 0
60C4 ADD A,A
60C5 ADD A,A
60C6 NOP Do nothing (during the startup sequence), or poke the attribute byte onto the screen (this instruction is set to LD (BC),A before the game starts; see 53A0)
The appropriate attribute byte has been poked onto the screen. Now to find the appropriate tile graphic data.
60C7 LD L,E L=Q (0x00<=Q<=0x8F), H=Y+0xA0
60C8 LD E,(HL) E=LSB of the base address of the tile graphic data
60C9 LD A,$88 A=10001000
60CB SRL L Shift A right (Q AND 3) times
60CD JR NC,$60D0
60CF RRCA
60D0 SRL L
60D2 JR NC,$60D6
60D4 RRCA
60D5 RRCA
60D6 LD C,A C=10001000, 01000100, 00100010 or 00010001
60D7 LD A,L Point HL at the byte containing the MSB indicator bit-pair: H=Y+0xA0, 0x90<=L=0x90+INT(Q/4)<=0xB3
60D8 ADD A,$90
60DA LD L,A
60DB LD A,C A=10001000, 01000100, 00100010 or 00010001
60DC AND (HL) Keep only the bits of the bit-pair
The base page of the tile graphic data depends on the bits set in A.
60DD LD D,$80
60DF CP $10 Are any of bits 4-7 in A set?
60E1 JR C,$60E5 Jump if not
60E3 LD D,$90
60E5 AND $0F Are any of bits 0-3 in A set?
60E7 JR Z,$60EB Jump if not
60E9 SET 3,D
Now D=0x80, 0x88, 0x90 or 0x98, and DE points at the first byte of the graphic data for the tile at skool coordinates (X,Y).
60EB LD HL,$E170 We're going to copy the tile into the 8-byte back buffer at E170
60EE LD B,$08
60F0 XOR A Use a blank graphic byte (during startup), or collect the tile graphic byte (this instruction is set to LD A,(DE) before the game starts; see 53A0)
60F1 INC D Point DE at the next graphic byte
60F2 LD (HL),A Copy the graphic byte into the back buffer
60F3 INC L Move to the next slot in the back buffer
60F4 DJNZ $60F0 Jump back until the entire tile has been copied
The appropriate play area tile has been copied into the back buffer at E170. Now it's time to superimpose game character sprite tiles (if any).
60F6 LD H,$B7 0xB7=character number of little girl no. 1
60F8 POP DE D=Y (0-20), E=X (0-191)
60F9 LD A,($7FFF) A=leftmost column of the play area on screen (0-160)
60FC CP $78 This x-coordinate is roughly halfway between the tree and the gate
60FE JR C,$610B Jump if columns 144 onwards (girls' skool + half the girls' playground) are off-screen
6100 LD B,$07 7 little girls
6102 CALL $6000 Superimpose graphic bytes for the little girls if necessary
6105 LD H,$C6 0xC6=character number of little boy no. 9
6107 LD B,$11 2 little boys, 11 main characters, plus the objects using character buffers 0xD3-0xD6
6109 JR $611E
610B CP $50 This is the x-coordinate of the assembly hall stage (or thereabouts)
610D JR C,$611A Jump if columns 104 onwards (everything to the right of the tree, roughly) are off-screen
610F LD B,$03 3 little girls (0xB7-0xB9)
6111 CALL $6000 Superimpose graphic bytes for these little girls if necessary
6114 LD H,$C1 0xC1=character number of little boy no. 4
6116 LD B,$16 7 little boys, 11 main characters, plus the objects using character buffers 0xD3-0xD6
6118 JR $611E
611A LD H,$BE 0xBE=character number of little boy no. 1
611C LD B,$19 All 10 little boys, 11 main characters, plus the objects using character buffers 0xD3-0xD6
611E CALL $6000 Superimpose graphic bytes for these characters if necessary
6121 LD HL,$E170 The 8-byte back buffer at E170 now contains the tile to be copied to the screen
6124 POP DE Retrieve the appropriate display file address in DE
This entry point is used by the routine at 693D.
6125 LD B,$08 There are 8 bytes per character square
6127 LD A,(HL) Transfer the graphic bytes to the screen
6128 LD (DE),A
6129 INC L
612A INC D
612B DJNZ $6127
612D RET
Prev: 6065 Up: Map Next: 612E