Prev: 56702 Up: Map Next: 56908
56737: Draw/erase foreground scenery items
Used by the routine at 54524.
These drawing/erasing routines are similar to the standard ones at 56309, but because the foreground scenery occupies its own screen area and won't overlap other scenery, they're simplified slightly.
56737 LD A,0 Flag indicating whether (any part of) graphic is visible on screen - set to 0 at start of graphics routine
56739 LD (60117),A
56742 LD HL,(60109) Graphic address pointer to foreground scenery graphics
56745 LD A,(HL) Byte indicating number of tiles within the graphic
56746 INC HL
Tile drawing loop
56747 LD (60112),A Store graphic tile counter
56750 LD C,(HL) Horizontal graphic offset (in pixels)
56751 INC HL
56752 EX DE,HL Swap graphic address pointer into DE
Adjust graphic's screen position with horizontal offset:
56753 LD HL,(60115) Horizontal graphic position on screen in pixels
56756 LD A,C Get horizontal graphics pixel offset value
56757 RLA Rotate the bits left
56758 SBC A,A If this subtract creates a carry, it means the graphic offset is negative, otherwise positive
56759 LD B,A Store this value in B register (255 = negative, 0 = positive)
56760 ADD HL,BC Add (or subtract if negative) the offset from the horizontal graphics position
56761 EX DE,HL Swap into DE
56762 LD A,D Get high byte of offset
56763 CP 0
56765 JP NZ,56901 If not zero it means the horizontal pixel position has gone over 255 and is therefore out of bounds. Jump out here and skip the rest of this tile.
Calculate the graphic's horizontal screen display address column position, and put into the E register:
56768 LD A,E The low byte (in the E register) contains the horizontal pixel position (including offset)
56769 RRA Get the graphic's screen character column by dividing the pixel value by 8
56770 RRA
56771 RRA
56772 AND 31 Filter out bits 5-7 (only values 0-31 needed)
56774 DEC A
56775 CP 28 Right-hand column screen border check
56777 JP NC,56901 No carry means character position is into the right border - jump out here
56780 INC A Increment to return to place after the DEC a few instructions earlier
56781 INC A The horizontal position is stored from column 1 (2nd screen column), whereas screen display address counts from column 0 as the first one, so adjust the horizontal character position by +1 so that it calculates correctly
56782 LD E,A Store adjusted column position in E register
Check for vertical screen (scroll) boundary:
56783 LD C,(HL) Get vertical graphic pixel offset value
56784 LD A,(60114) Graphic's vertical screen position
56787 ADD A,C Add the offset
56788 CP 112 Vertical pixel position 112 is the top of the scroll, out of bounds for drawing graphics
56790 JR NC,56901 No carry here means the object is in the scroll area at the bottom of the screen, and out of bounds for drawing - jump out here
Calculate high byte/vertical part of screen display address:
56792 ADD A,16 The vertical graphic position is stored from the top of the playing area, but the screen display is calculated from the very top of the screen. Therefore add 16 pixels to adjust for the decorative border offset at the top of the screen
56794 LD D,A Store in high byte of screen display address
56795 AND 7 Bits 0-2 indicate pixel number (0-7) in character row
56797 LD C,A Put in C register for safe keeping
56798 INC HL
56799 LD A,1 This is the flag indicating whether (any part of the graphic) is visible on-screen (0 = not visible, 1 = visible)
56801 LD (60117),A It's set here to visible (1) as part of the item is visible
56804 LD A,D Get the graphic's adjusted vertical screen pixel position
56805 RLA Character row is currently indicated by bits 3-5 so shift them left twice to bits 5-7
56806 RLA
56807 AND 224 Get those top three bits (filter out any others)...
56809 ADD A,E ...and combine them with bits 0-4 which hold the column number, to form the screen display address low byte
56810 LD E,A
56811 LD A,D Vertical pixel position, from top of screen display
56812 RRA Divide by 8 to get screen display (character) row
56813 RRA
56814 RRA
56815 AND 24 Bits 3 (8) and 4 (16) include the screen display address high byte character row (0-24)
56817 ADD A,64 Set bit 6 (always set for screen addresses)
56819 ADD A,C C contains the pixel row number in the character line (0-7). Add this to the high byte of the address
56820 LD D,A Put the calculated screen address high byte into the D register
56821 LD B,(HL) Number of bytes in the graphic tile to print
56822 INC HL Advance address pointer to start of tile graphics
56823 EX DE,HL ...and swap into DE register
56824 LD A,(60111) Check draw/erase flag
56827 CP 1
56829 JR Z,56861 If it's DRAW, jump out here....
ERASE graphic pixels on screen:
56831 LD A,H Erase pixels within this character square - get pixel row in character square from screen display address
56832 AND 7 Keep bits 0-2 so that A now contains the pixel row number in the character square
Erase pixel loop. Foreground scenery is out of the way of other room scenery/items so no need to use AND and OR to preserve existing pixels:
56834 LD (HL),0 Clear pixels in this on-screen byte
56836 INC DE Move to next byte of graphic tile (mainly for count purposes)
56837 INC A Increment the pixel row count/number
56838 AND 7
56840 JR Z,56845 If zero we've got to pixel row 8, so jump out here to re-calculate screen display address for the next pixel row
56842 INC H ...Otherwise move down one pixel line
56843 JR 56857 ...And continue clearing the square
Re-calculate screen display address with new pixel row:
56845 LD A,H Reset pixel row (bits 0-2 in high byte of the screen display address)
56846 AND 248
56848 LD H,A
56849 LD A,L Increment column by 32 to move down to next screen row
56850 ADD A,32
56852 JR C,56887 Crossing a 1/3 screen boundary? ...If so, jump out of routine here
56854 LD L,A Otherwise, store the amended screen display address low byte
56855 LD A,0 ...reset the pixel counter to 0...
56857 DJNZ 56834 ...and draw the rest of the bytes in the tile
56859 JR 56891 When finished, go and check if there are more tiles to draw
DRAW graphic pixels on screen:
56861 LD A,(DE) Get graphics byte
56862 LD (HL),A Draw on screen
56863 INC DE Move to next byte of the graphics tile
56864 LD A,H Increment and check the pixel row (bits 0-2 of screen display address high byte)
56865 INC A
56866 AND 7
56868 JR Z,56873 If zero we've got to pixel row 8, so jump out here to re-calculate screen display address for the next pixel row
56870 INC H ...Otherwise, move down one pixel line
56871 JR 56883 ...And continue clearing the square
Re-calculate screen display address with new pixel row:
56873 LD A,H Reset pixel row (bits 0-2 in high byte of the screen display address)
56874 AND 248
56876 LD H,A
56877 LD A,L Increment column by 32 to move down to next screen row
56878 ADD A,32
56880 JR C,56887 Crossing a 1/3 screen boundary? ...If so, jump out of routine here
56882 LD L,A Otherwise, store the amended screen display address low byte
56883 DJNZ 56861 ...and continue to draw the rest of the tile graphic
56885 JR 56891 When finished, go and check if there are more tiles to draw
ERASE or DRAW screen display address has moved into the next third of the screen.
As this will be the bottom third of the screen where the scroll is, there's no need to calculate anything - there's nothing more to erase/draw.
56887 DEC DE DE was prematurely incremented in the loops at 56836 or 56863 so if this was done, revert this change
56888 INC DE Then increment it by the remaining tile bytes, to get to the start of the next tile
56889 DJNZ 56888
Tile finished - check for next tile:
56891 EX DE,HL Swap the screen display address and graphics address pointers
56892 LD A,(60112) Get the graphic tile counter
56895 DEC A Reduce by one
56896 JP NZ,56747 If there are still tiles to draw, go and draw them
56899 JR 56907 Jump to RET at the end of this routine
Jump here if screen position to draw/erase to is in right screen border (from 56777) or into the scroll at the bottom third of the screen (from 56790)
Nothing to draw/erase for the rest of this tile, so can skip past it
56901 INC HL Move pointer to the address holding the number of graphic bytes in this tile
56902 LD B,(HL) Get the byte counter
56903 INC HL Advance to the start of the tile's graphic bytes
56904 EX DE,HL Swap back into DE register pair
56905 JR 56888 Jump to the routine that skips the rest of the bytes
Jump here once all of the tiles have been drawn/erased
56907 RET
Prev: 56702 Up: Map Next: 56908