ZX BASIC:WindowPaint
paintWindow
WARNING: THIS subroutine does not check to see if it's writing over the edge of the screen. This is done for speed, but it is the user's job to make sure that all data will fit on the screen!
This subroutine changes the attribute map without actually changing the bitmap that's in it. You can combine this with other routines, such as clearbox, to clear a screen area and reset the attributes, as well as fast plot and draw routines that don't deal with attributes themselves. Also ideal (and originally designed for) use with putChars, which is a fast graphics print routine, that also doesn't do attributes directly. Sprites can be worked up from this basis.
Usage
windowPaint(x AS UBYTE,y AS UBYTE, width AS UBYTE, height AS UBYTE, inkCol AS UBYTE, paperCol AS UBYTE, isBright AS UBYTE, isFlash AS UBYTE) paint (x AS UBYTE,y AS UBYTE, width AS UBYTE, height AS UBYTE, attribute AS UBYTE)
windowPaint calls paint with the required single attribute byte - it's perfectly reasonable to call it directly, if you have the full attribute value ready. windowPaint is really there to make it simpler to construct this byte.
Where
- x is the x value in character co-ordinates
- y is the y value in character co-ordinates
- width is the width in characters
- height is the height in characters
SUB windowPaint(x AS UBYTE,y AS UBYTE, width AS UBYTE, height AS UBYTE, inkCol AS UBYTE, paperCol AS UBYTE, isBright AS UBYTE, isFlash AS UBYTE) paint(x,y,width,height,(isFlash<<7+isBright<<6+paperCol<<3+inkCol)) END SUB
SUB paint (x AS UBYTE,y AS UBYTE, width AS UBYTE, height AS UBYTE, attribute AS UBYTE) ' Copyleft Britlion. Feel free to use as you will. Please attribute me if you use this, however! ASM ld a,(IX+7) ;ypos rrca rrca rrca ; Multiply by 32 ld l,a ; Pass TO L AND 3 ; Mask with 00000011 add a,88 ; 88 * 256 = 22528 - start of attributes. Change this IF you are working with a buffer OR somesuch. ld h,a ; Put it in the High BYTE ld a,l ; We get y value *32 AND 224 ; Mask with 11100000 ld l,a ; Put it in L ld a,(IX+5) ; xpos add a,l ; Add it TO the Low BYTE ld l,a ; Put it back in L, AND we're done. HL=Address. push HL ; SAVE address LD A, (IX+13) ; attribute LD DE,32 LD c,(IX+11) ; height BLPaintHeightLoop: LD b,(IX+9) ; width BLPaintWidthLoop: LD (HL),a ; paint a character INC L ; Move TO the right (Note that we only would have TO inc H IF we are crossing from the right edge TO the left, AND we shouldn't be needing to do that) DJNZ BLPaintWidthLoop BLPaintWidthExitLoop: POP HL ; recover our left edge DEC C JR Z, BLPaintHeightExitLoop ADD HL,DE ; move 32 down PUSH HL ; SAVE it again JP BLPaintHeightLoop BLPaintHeightExitLoop: END ASM END SUB