|
| 1 | +#WindowPaint |
| 2 | + |
| 3 | +##paintWindow |
| 4 | + |
| 5 | +>**WARNING: THIS subroutine does not check to see if it's writing over the edge of the |
| 6 | +> screen. This is done for speed, but it is the user's job to make sure that all |
| 7 | +> data will fit on the screen!** |
| 8 | +
|
| 9 | +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. |
| 10 | +Also ideal (and originally designed for) use with `putChars`, which is a fast graphics print routine, that also doesn't do attributes directly. |
| 11 | +Sprites can be worked up from this basis. |
| 12 | + |
| 13 | +###Usage |
| 14 | + |
| 15 | +``` |
| 16 | +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) |
| 17 | +paint (x as uByte,y as uByte, width as uByte, height as uByte, attribute as ubyte) |
| 18 | +``` |
| 19 | + |
| 20 | +`windowPaint` calls paint with the required single attribute byte - it's perfectly reasonable to call it directly, |
| 21 | +if you have the full attribute value ready. windowPaint is really there to make it simpler to construct this byte. |
| 22 | + |
| 23 | + |
| 24 | +Where |
| 25 | +* x is the x value in character co-ordinates |
| 26 | +* y is the y value in character co-ordinates |
| 27 | +* width is the width in characters |
| 28 | +* height is the height in characters |
| 29 | + |
| 30 | + |
| 31 | +``` |
| 32 | +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) |
| 33 | + paint(x,y,width,height,(isFlash<<7+isBright<<6+paperCol<<3+inkCol)) |
| 34 | +END SUB |
| 35 | +
|
| 36 | +
|
| 37 | +SUB paint (x as uByte,y as uByte, width as uByte, height as uByte, attribute as ubyte) |
| 38 | + REM Copyleft Britlion. Feel free to use as you will. Please attribute me if you use this, however! |
| 39 | +
|
| 40 | + asm |
| 41 | + ld a,(IX+7) ;ypos |
| 42 | + rrca |
| 43 | + rrca |
| 44 | + rrca ; Multiply by 32 |
| 45 | + ld l,a ; Pass to L |
| 46 | + and 3 ; Mask with 00000011 |
| 47 | + add a,88 ; 88 * 256 = 22528 - start of attributes. Change this if you are working with a buffer or somesuch. |
| 48 | + ld h,a ; Put it in the High Byte |
| 49 | + ld a,l ; We get y value *32 |
| 50 | + and 224 ; Mask with 11100000 |
| 51 | + ld l,a ; Put it in L |
| 52 | + ld a,(IX+5) ; xpos |
| 53 | + add a,l ; Add it to the Low byte |
| 54 | + ld l,a ; Put it back in L, and we're done. HL=Address. |
| 55 | + |
| 56 | + push HL ; save address |
| 57 | + LD A, (IX+13) ; attribute |
| 58 | + LD DE,32 |
| 59 | + LD c,(IX+11) ; height |
| 60 | + |
| 61 | + BLPaintHeightLoop: |
| 62 | + LD b,(IX+9) ; width |
| 63 | + |
| 64 | + BLPaintWidthLoop: |
| 65 | + LD (HL),a ; paint a character |
| 66 | + 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) |
| 67 | + DJNZ BLPaintWidthLoop |
| 68 | + |
| 69 | + BLPaintWidthExitLoop: |
| 70 | + POP HL ; recover our left edge |
| 71 | + DEC C |
| 72 | + JR Z, BLPaintHeightExitLoop |
| 73 | + |
| 74 | + ADD HL,DE ; move 32 down |
| 75 | + PUSH HL ; save it again |
| 76 | + JP BLPaintHeightLoop |
| 77 | +
|
| 78 | + BLPaintHeightExitLoop: |
| 79 | + end asm |
| 80 | +END SUB |
| 81 | +``` |
0 commit comments