|
| 1 | +#Putchars.bas |
| 2 | + |
| 3 | +##Putchars |
| 4 | + |
| 5 | +> **WARNING: This subroutine does not check to see if it's writing over the edge of the screen. |
| 6 | +This is done for speed, but it is the user's job to make sure that all data will fit on the screen!** |
| 7 | + |
| 8 | +###Usage |
| 9 | +There is a an example program that uses this at the end of the page. |
| 10 | + |
| 11 | +``` |
| 12 | +putChars(x as uByte,y as uByte, width as uByte, height as uByte, dataAddress as uInteger) |
| 13 | +``` |
| 14 | + |
| 15 | +Where |
| 16 | + |
| 17 | +* x is the x value in character co-ordinates |
| 18 | +* y is the y value in character co-ordinates |
| 19 | +* width is the width in characters |
| 20 | +* height is the height in characters |
| 21 | +* dataaddress is the memory address of the UDG style bytes for the character being printed. 8 Bytes to a character. The order is top left to bottom right, first column, then second column, and so forth. |
| 22 | + |
| 23 | + |
| 24 | +Prints the graphics data to the screen at the given character co-ordinates. |
| 25 | + |
| 26 | +``` |
| 27 | +SUB putChars(x as uByte,y as uByte, width as uByte, height as uByte, dataAddress as uInteger) |
| 28 | +' Copyleft Britlion. Feel free to use as you will. Please attribute me if you use this, however! |
| 29 | +
|
| 30 | +Asm |
| 31 | + BLPutChar: |
| 32 | + LD a,(IX+5) |
| 33 | + ;AND 31 |
| 34 | + ld l,a |
| 35 | + ld a,(IX+7) ; Y value |
| 36 | + ld d,a |
| 37 | + AND 24 |
| 38 | + add a,64 ; 256 byte "page" for screen - 256*64=16384. Change this if you are working with a screen address elsewhere, such as a buffer. |
| 39 | + ld h,a |
| 40 | + ld a,d |
| 41 | + AND 7 |
| 42 | + rrca |
| 43 | + rrca |
| 44 | + rrca |
| 45 | + OR l |
| 46 | + ld l,a |
| 47 | +
|
| 48 | + PUSH HL ; save our address |
| 49 | +
|
| 50 | + LD E,(IX+12) ; data address |
| 51 | + LD D,(IX+13) |
| 52 | + LD B,(IX+9) ; width |
| 53 | + PUSH BC ; save our column count |
| 54 | +
|
| 55 | + BLPutCharColumnLoop: |
| 56 | +
|
| 57 | + LD B,(IX+11) ; height |
| 58 | +
|
| 59 | + BLPutCharInColumnLoop: |
| 60 | + |
| 61 | + ; gets screen address in HL, and bytes address in DE. Copies the 8 bytes to the screen |
| 62 | + ld a,(DE) ; First Row |
| 63 | + LD (HL),a |
| 64 | + |
| 65 | + INC DE |
| 66 | + INC H |
| 67 | + ld a,(DE) |
| 68 | + LD (HL),a ; second Row |
| 69 | + |
| 70 | + INC DE |
| 71 | + INC H |
| 72 | + ld a,(DE) |
| 73 | + LD (HL),a ; Third Row |
| 74 | + |
| 75 | + INC DE |
| 76 | + INC H |
| 77 | + ld a,(DE) |
| 78 | + LD (HL),a ; Fourth Row |
| 79 | + |
| 80 | + INC DE |
| 81 | + INC H |
| 82 | + ld a,(DE) |
| 83 | + LD (HL),a ; Fifth Row |
| 84 | + |
| 85 | + INC DE |
| 86 | + INC H |
| 87 | + ld a,(DE) |
| 88 | + LD (HL),a ; Sixth Row |
| 89 | + |
| 90 | + INC DE |
| 91 | + INC H |
| 92 | + ld a,(DE) |
| 93 | + LD (HL),a ; Seventh Row |
| 94 | + |
| 95 | + INC DE |
| 96 | + INC H |
| 97 | + ld a,(DE) |
| 98 | + LD (HL),a ; Eigth Row |
| 99 | + |
| 100 | + INC DE ; Move to next data item. |
| 101 | + |
| 102 | + DEC B |
| 103 | + JR Z,BLPutCharNextColumn |
| 104 | + ;The following code calculates the address of the next line down below current HL address. |
| 105 | + PUSH DE ; save DE |
| 106 | + ld a,l |
| 107 | + and 224 |
| 108 | + cp 224 |
| 109 | + jp z,BLPutCharNextThird |
| 110 | +
|
| 111 | + BLPutCharSameThird: |
| 112 | + ld de,-1760 |
| 113 | + ;and a |
| 114 | + add hl,de |
| 115 | + POP DE ; get our data point back. |
| 116 | + jp BLPutCharInColumnLoop |
| 117 | +
|
| 118 | + BLPutCharNextThird: |
| 119 | + ld de,32 |
| 120 | + ;and a |
| 121 | + add hl,de |
| 122 | + POP DE ; get our data point back. |
| 123 | + JP BLPutCharInColumnLoop |
| 124 | +
|
| 125 | + BLPutCharNextColumn: |
| 126 | + POP BC |
| 127 | + POP HL |
| 128 | + DEC B |
| 129 | + JP Z, BLPutCharsEnd |
| 130 | +
|
| 131 | + INC L ; Note this would normally be Increase HL - but block painting should never need to increase H, since that would wrap around. |
| 132 | + PUSH HL |
| 133 | + PUSH BC |
| 134 | + JP BLPutCharColumnLoop |
| 135 | +
|
| 136 | +
|
| 137 | +BLPutCharsEnd: |
| 138 | +
|
| 139 | +End Asm |
| 140 | +END SUB |
| 141 | +``` |
| 142 | + |
| 143 | + |
| 144 | +##Paint |
| 145 | + |
| 146 | +Prints the colour data to the screen at the given character co-ordinates. |
| 147 | + |
| 148 | +## Syntax |
| 149 | +``` |
| 150 | +paint (x as uByte,y as uByte, width as uByte, height as uByte, attribute as ubyte) |
| 151 | +``` |
| 152 | + |
| 153 | +Where |
| 154 | +* x is the x value in character co-ordinates |
| 155 | +* y is the y value in character co-ordinates |
| 156 | +* width is the width in characters |
| 157 | +* height is the height in characters |
| 158 | +* attribute is the byte value of the attribute to paint to the given co-ordinates. (As one would get from the ATTR function) |
| 159 | + |
| 160 | +###Usage |
| 161 | +There is a an example program after the source code. |
| 162 | + |
| 163 | + |
| 164 | +``` |
| 165 | +SUB paint (x as uByte,y as uByte, width as uByte, height as uByte, attribute as ubyte) |
| 166 | +REM Copyleft Britlion. Feel free to use as you will. Please attribute me if you use this, however! |
| 167 | +
|
| 168 | +Asm |
| 169 | + ld a,(IX+7) ;ypos |
| 170 | + rrca |
| 171 | + rrca |
| 172 | + rrca ; Multiply by 32 |
| 173 | + ld l,a ; Pass to L |
| 174 | + and 3 ; Mask with 00000011 |
| 175 | + add a,88 ; 88 * 256 = 22528 - start of attributes. Change this if you are working with a buffer or somesuch. |
| 176 | + ld h,a ; Put it in the High Byte |
| 177 | + ld a,l ; We get y value *32 |
| 178 | + and 224 ; Mask with 11100000 |
| 179 | + ld l,a ; Put it in L |
| 180 | + ld a,(IX+5) ; xpos |
| 181 | + add a,l ; Add it to the Low byte |
| 182 | + ld l,a ; Put it back in L, and we're done. HL=Address. |
| 183 | + |
| 184 | + push HL ; save address |
| 185 | + LD A, (IX+13) ; attribute |
| 186 | + LD DE,32 |
| 187 | + LD c,(IX+11) ; height |
| 188 | + |
| 189 | + BLPaintHeightLoop: |
| 190 | + LD b,(IX+9) ; width |
| 191 | + |
| 192 | + BLPaintWidthLoop: |
| 193 | + LD (HL),a ; paint a character |
| 194 | + 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) |
| 195 | + DJNZ BLPaintWidthLoop |
| 196 | + |
| 197 | + BLPaintWidthExitLoop: |
| 198 | + POP HL ; recover our left edge |
| 199 | + DEC C |
| 200 | + JR Z, BLPaintHeightExitLoop |
| 201 | + |
| 202 | + ADD HL,DE ; move 32 down |
| 203 | + PUSH HL ; save it again |
| 204 | + JP BLPaintHeightLoop |
| 205 | +
|
| 206 | + BLPaintHeightExitLoop: |
| 207 | +end asm |
| 208 | +END SUB |
| 209 | +``` |
| 210 | + |
| 211 | +##PaintData |
| 212 | +Copies the colour data to the screen at the given character co-ordinates. |
| 213 | +The order here is Rows and then Columns; so first row, then second row and so on. |
| 214 | +While this may be awkward, being the other way around to the pixel data, these orders |
| 215 | +are the most efficient speedwise. |
| 216 | + |
| 217 | +Where |
| 218 | +* x is the x value in character co-ordinates |
| 219 | +* y is the y value in character co-ordinates |
| 220 | +* width is the width in characters |
| 221 | +* height is the height in characters |
| 222 | +* address is the address of the data to copy to the screen's attribute area. |
| 223 | + |
| 224 | +###Usage |
| 225 | +There is a an example program that uses this at the end of the page. |
| 226 | + |
| 227 | +``` |
| 228 | +paintData (x as uByte,y as uByte, width as uByte, height as uByte, address as uInteger) |
| 229 | +``` |
| 230 | + |
| 231 | +``` |
| 232 | +SUB paintData (x as uByte,y as uByte, width as uByte, height as uByte, address as uInteger) |
| 233 | +REM Copyleft Britlion. Feel free to use as you will. Please attribute me if you use this, however! |
| 234 | +
|
| 235 | +Asm |
| 236 | + ld a,(IX+7) ;ypos |
| 237 | + rrca |
| 238 | + rrca |
| 239 | + rrca ; Multiply by 32 |
| 240 | + ld l,a ; Pass to L |
| 241 | + and 3 ; Mask with 00000011 |
| 242 | + add a,88 ; 88 * 256 = 22528 - start of attributes. Change this if you are working with a buffer or somesuch. |
| 243 | + ld h,a ; Put it in the High Byte |
| 244 | + ld a,l ; We get y value *32 |
| 245 | + and 224 ; Mask with 11100000 |
| 246 | + ld l,a ; Put it in L |
| 247 | + ld a,(IX+5) ; xpos |
| 248 | + add a,l ; Add it to the Low byte |
| 249 | + ld l,a ; Put it back in L, and we're done. HL=Address. |
| 250 | +
|
| 251 | + push HL ; save address |
| 252 | + LD D, (IX+13) |
| 253 | + LD E, (IX+12) |
| 254 | + LD c,(IX+11) ; height |
| 255 | +
|
| 256 | + BLPaintDataHeightLoop: |
| 257 | + LD b,(IX+9) ; width |
| 258 | +
|
| 259 | + BLPaintDataWidthLoop: |
| 260 | + LD a,(DE) |
| 261 | + LD (HL),a ; paint a character |
| 262 | + 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) |
| 263 | + INC DE |
| 264 | + DJNZ BLPaintDataWidthLoop |
| 265 | +
|
| 266 | + BLPaintDataWidthExitLoop: |
| 267 | + POP HL ; recover our left edge |
| 268 | + DEC C |
| 269 | + JR Z, BLPaintDataHeightExitLoop |
| 270 | + PUSH DE |
| 271 | + LD DE,32 |
| 272 | + ADD HL,DE ; move 32 down |
| 273 | + POP DE |
| 274 | + PUSH HL ; save it again |
| 275 | + JP BLPaintDataHeightLoop |
| 276 | +
|
| 277 | + BLPaintDataHeightExitLoop: |
| 278 | +End Asm |
| 279 | +END SUB |
| 280 | +``` |
| 281 | + |
| 282 | +##Example Program |
| 283 | + |
| 284 | +``` |
| 285 | +goto start |
| 286 | +
|
| 287 | +datapoint: |
| 288 | +Asm |
| 289 | + defb 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32 |
| 290 | + defb 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64 |
| 291 | + defb 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96 |
| 292 | + defb 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128 |
| 293 | +End Asm |
| 294 | +
|
| 295 | +start: |
| 296 | +cls |
| 297 | +putChars(10,10,3,3,@datapoint) |
| 298 | +paint(10,10,3,3,79) |
| 299 | +``` |
0 commit comments