Tiling 10.4 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; routines in this file are responsible for tiling the backdrops of
; windows.

        [ windowsprite

; this is a 'signed' division macro

        MACRO
$lab    DivRemS $ra,$rb,$rc,$tmp
$lab    CMP     $rb,#0
        BLT     %FT2
        DivRem  $ra,$rb,$rc,$tmp
        B       %FT4
2       RSB     $rb,$rb,#0
        DivRem  $ra,$rb,$rc,$tmp
        RSB     $rb,$rb,#0
        ; modulus should be -ve if divisor is -ve
4
        MEND


plotsprite_tile1        DCB     "tile_1",0,0
plotsprite_tile1_       DCB     "tile_1-",0

        ALIGN

plotspritebackground
        Push    "R0-R5,lr"
; first find sprite tile_1, look in window area, then wimp area
        LDR     R1,plotsprCB
        TEQ     R1,#0
        BEQ     %FT2
        wsaddr  R5,tile_sc_block
        wsaddr  R4,clipx0
        MOV     R14,PC
        MOV     PC,R1
        Pull    "R0-R5,PC"
2
53
        TEQ     R0,#sc_verylightgrey            ; colour 1
Neil Turton's avatar
Neil Turton committed
54 55 56 57 58
        SWINE   XOS_WriteI+16                   ; just clear the area
        Pull    "R0-R5,PC",NE

        LDR     R1,[handle,#w_areaCBptr]
        CMP     R1,#2
Robert Sprowson's avatar
Robert Sprowson committed
59 60
        BLO     %FT3                            ; 0 ==> system, 1 ==> wimp, else user
        MOV     R0,#SpriteReason_SelectSprite
Neil Turton's avatar
Neil Turton committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
        ORR     R0,R0,#256
        ADR     R2,plotsprite_tile1
        SWI     XOS_SpriteOp
        BVS     %FT3

        ADRL    R14,tile_sc_block               ; need to save global tile info as
                                                ; a local tile will overwrite this
        LDMIA   R14!,{R0,R3-R5}
        Push    "R0,R3-R5"
        LDMIA   R14,{R0,R3-R5}
        Push    "R0,R3-R5"

        STR     R1,thisCBptr
        STR     R2,spritename
        MOV     R0,#0
        STR     R0,lengthflags                  ; spritename is a pointer
        BL      cachespritedata

        LDR     R0,pixtable_at
        STR     R0,tile_temptab
        LDR     R0,sprite_log2px
        STR     R0,tile_log2px
        LDR     R0,sprite_log2py
        STR     R0,tile_log2py

86
        LDRB    R14,sprite_needsfactors
Neil Turton's avatar
Neil Turton committed
87
        TEQ     R14,#0
88
        ADRNE   R14,sprite_factors
Neil Turton's avatar
Neil Turton committed
89 90 91 92 93 94 95 96 97

        Push    R3

        LDMNEIA R14,{R0-R3}
        MOVEQ   R0,#0
        ADRL    R14,tile_sc_block
        STMIA   R14,{R0-R3}
        Pull    R3

98
        LDRB    R1,sprite_needsfactors          ; needs preserving
Neil Turton's avatar
Neil Turton committed
99 100 101 102 103
        Push    R1

        B       %FT6
3
        LDR     R2,tiling_sprite
Robert Sprowson's avatar
Robert Sprowson committed
104
        CMP     R2,#0                   ; disabled/not there
Neil Turton's avatar
Neil Turton committed
105
        BEQ     %FT4
Robert Sprowson's avatar
Robert Sprowson committed
106
        CMP     R2,#-1                  ; needs recache
Ben Avison's avatar
Ben Avison committed
107 108 109
        LDRNE   R1,baseofsprites
        BNE     %FT5
        BLEQ    findwimptilesprite
Neil Turton's avatar
Neil Turton committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
        LDRVC   R1,baseofsprites
        BVC     %FT5
4
        SWI     XOS_WriteI+16

        Pull    "R0-R5,PC"              ; can't find it? don't bother

5
        ADRL    R14,tile_sc_block               ; need to save global tile info as
                                                ; a local tile will overwrite this
        LDMIA   R14!,{R0,R3-R5}
        Push    "R0,R3-R5"
        LDMIA   R14,{R0,R3-R5}
        Push    "R0,R3-R5"

        STR     R1,thisCBptr
        STR     R2,spritename
        MOV     R0,#0
        STR     R0,lengthflags                  ; spritename is a pointer

130
        LDRB    R1,sprite_needsfactors          ; needs preserving
Neil Turton's avatar
Neil Turton committed
131 132 133
        Push    R1

        LDR     R0,tile_sc_block
134 135 136 137 138 139
        TEQ     R0, #0
        MOVNE   R0, #-1
        STRB    R0,sprite_needsfactors

        LDR     R0,tile_pixtable
        STR     R0,tile_temptab
Neil Turton's avatar
Neil Turton committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

        LDR     R3,tile_width
        LDR     R4,tile_height
6
        Push    "x0-y1"

        LDR     R0,tile_log2px
        MOV     R3,R3, LSL R0
        LDR     R0,tile_log2py
        MOV     R4,R4, LSL R0
        Push    "R3,R4"                 ; width and height now on stack
        LDR     y1,[handle,#w_way1]
        LDR     x0,[handle,#w_wax0]
        LDR     R0,[handle,#w_scx]
        DivRemS x1,R0,R3,R5             ; need to start 1 sprite left/below origin
        SUB     x0,x0,R0
        LDR     R0,[handle,#w_scy]
        DivRemS x1,R0,R4,R5
        LDR     R4,[sp,#4]
        SUB     y1,y1,R0


7


        ADR     R14,clipx0
        LDMIA   R14,{R0,y0,x1,R14}

        ADD     x1,x1,#1                        ; boundary condition

        SUB     y0,y0,#1                        ; bc
        RSB     y0,R4,y0


        ADD     R14,R14,#1                        ; boundary conditions
8
; get y1 within graphics window bounds
        CMP     y1,R14
        SUBGT   y1,y1,R4
        BGT     %BT8

        SUB     R0,R0,#1                        ; boundary conditions
9
; get x0 within bounds
        CMP     x0,R0
        ADDLT   x0,x0,R3
        BLT     %BT9
        SUB     x0,x0,R3                        ; get it back to left of window



        MOV     R4,y1
10
        MOV     R3,x0
20
        MOV     R5,#8
        BL      tile_putsprite
        LDR     R5,[sp]
        ADD     R3,R3,R5
        CMP     R3,x1
        BLT     %BT20
        LDR     R5,[sp,#4]
        SUB     R4,R4,R5
        CMP     R4,y0
        BGT     %BT10
err
        ADD     SP,SP,#8
err2

        Pull    "x0-y1"

        Pull    R0
212
        STRB    R0,sprite_needsfactors
Neil Turton's avatar
Neil Turton committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226

        ADRL    R14,tile_log2px                         ; restore global tile info
        Pull    "R0-R3"
        STMIA   R14,{R0-R3}
        SUB     R14,R14,#16
        Pull    "R0-R3"
        STMIA   R14,{R0-R3}

        Pull    "R0-R5,PC"

        LTORG

;; Routine to stash tile_1 from wimp area
;; returns R2-> tile_1 or VS
227
findwimptilesprite  Entry "R0-R1"
Neil Turton's avatar
Neil Turton committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
; is tiling disabled by CMOS ?
        MOV     R0,#161
        MOV     R1,#&8c
        SWI     XOS_Byte
        TST     R2,#128
        SETV    NE
        MOVVS   R2,#0
        STRVS   R2,tiling_sprite

        EXIT    VS

        LDR     R14,log2bpp
        MOV     R0,#1
        MOV     R14,R0,LSL R14
        MOV     R0,#0
Ben Avison's avatar
Ben Avison committed
243 244
        CMP     R14,#8
        MOVHI   R0,#"6"
Neil Turton's avatar
Neil Turton committed
245
        CMP     R14,#16
Ben Avison's avatar
Ben Avison committed
246
        MOVHI   R0,#"2"
Neil Turton's avatar
Neil Turton committed
247 248 249 250
        Push    "R0"                            ; now got "2",0 or "6",0 on stack
        ADR     R2,plotsprite_tile1_
        LDMIA   R2,{R0-R1}
        Push    "R0-R1"                         ; now have "tile_1-?#",0 on stack
Ben Avison's avatar
Ben Avison committed
251 252 253 254 255
        CMP     R14,#8
        ADDLS   R0,R14,#"0"
        MOVHI   R0,#"1"
        CMPHI   R14,#16
        MOVHI   R0,#"3"
Neil Turton's avatar
Neil Turton committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
        STRB    R0,[sp,#7]
        BL      findwimpspritefordepth

; try again.
        ADRVS   R14,plotsprite_tile1
        LDMVSIA   R14,{R0-R1}
        Push    "R0-R2",VS                         ; routine expects 12 bytes
        BLVS    findwimpspritefordepth
        EXIT    VS

        LDR     R1,baseofsprites
        STR     R1,thisCBptr
        STR     R2,spritename
        MOV     R0,#0
        STR     R0,lengthflags
        BL      cachespritedata

        STR     R3,tile_width
        STR     R4,tile_height

276
        LDRB    R1,sprite_needsfactors
Neil Turton's avatar
Neil Turton committed
277 278 279
        Push    "R2-R3"

        LDR     R2,tile_pixtable
Ben Avison's avatar
Ben Avison committed
280 281 282
        BICS    R2,R2,#1                        ; incase cache invalidated before mode change
        MOVNE   R0,#ModHandReason_Free
        BLNE    XROS_Module
Neil Turton's avatar
Neil Turton committed
283 284 285

        TEQ     R1,#0

286
        ADRNE   R14,sprite_factors
Neil Turton's avatar
Neil Turton committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313

        LDMNEIA R14,{R0-R3}
        MOVEQ   R0,#0
        ADRL    R14,tile_sc_block
        STMIA   R14,{R0-R3}

        LDR     R0,pixtable_at
        STR     R0,tile_pixtable
        MOV     R0,#0
        STR     R0,pixtable_at                  ; mark as used

        LDR     R0,sprite_log2px
        STR     R0,tile_log2px

        LDR     R0,sprite_log2py
        STR     R0,tile_log2py

        Pull    "R2-R3"
        CLRV
        EXIT

findwimpspritefordepth
; Sprite name to find (tile_1 or tile_1-##) is on stack
        Push    "lr"
        LDR     R2,list_at
        CMP     R2,#0
        BNE     %FT05
314
        MOV     R0,#SpriteReason_SelectSprite+256
315 316 317
      [ SpritePriority
        LDR     R1,baseofhisprites
      |
Neil Turton's avatar
Neil Turton committed
318
        LDR     R1,baseofsprites
319
      ]
Neil Turton's avatar
Neil Turton committed
320 321 322
        ADD     R2,SP,#4
        SWI     XOS_SpriteOp
        BVC     %FT07
323
        MOV     R0,#SpriteReason_SelectSprite+256
324 325 326
      [ SpritePriority
        LDR     R1,baseoflosprites
      |
Neil Turton's avatar
Neil Turton committed
327
        LDR     R1,baseofromsprites
328
      ]
Neil Turton's avatar
Neil Turton committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
        ADD     R2,SP,#4
        SWI     XOS_SpriteOp
        B       %FT07
05
; do it the quick way.
        ADD     R2,SP,#4
        STR     R2,spritename
        BL      getspriteaddr
07
        MOVVS   R2,#0
        STR     R2,tiling_sprite
        Pull    "R14"
        ADD     SP,SP,#12                       ; skip name
        MOV     PC,lr

tile_putsprite
        Push    "R1-R7,LR"
;
347
        LDRB    R0,sprite_needsfactors
Neil Turton's avatar
Neil Turton committed
348 349 350 351 352 353 354
        TEQ     R0,#0                   ; do I need to translate
;
        MOVNE   R0,#SpriteReason_PutSpriteScaled
        ADRNEL  R6,tile_sc_block
        MOVEQ   R0,#SpriteReason_PutSpriteUserCoords

        LDRNE   R7,tile_temptab          ; -> translation table
Ben Avison's avatar
Ben Avison committed
355
        TSTNE   R7,#1
Neil Turton's avatar
Neil Turton committed
356 357 358 359 360 361 362 363 364
        BLNE    get_new_pixtable
;
        LDR     R1,thisCBptr
        LDR     R2,spritename
        ORR     R0,R0,#&200

        SWI     XOS_SpriteOp
        SWIVS   XOS_WriteI+16

Kevin Bracey's avatar
Kevin Bracey committed
365
        Pull    "R1-R7,PC"
Neil Turton's avatar
Neil Turton committed
366

367
get_new_pixtable Entry  "R0-R6"
Neil Turton's avatar
Neil Turton committed
368

Ben Avison's avatar
Ben Avison committed
369
        BIC     R7,R7,#1                ; now an address again
Neil Turton's avatar
Neil Turton committed
370 371 372 373 374 375 376 377

        MOV     R0,#0
        STR     R0,lengthflags
        BL      cachespritedata
        LDR     R0,tile_pixtable
        TEQ     R0,R7
        BNE     %FT05

Ben Avison's avatar
Ben Avison committed
378 379 380
        MOVS    R2,R7
        MOVNE   R0,#ModHandReason_Free
        BLNE    XROS_Module
Neil Turton's avatar
Neil Turton committed
381 382 383 384 385 386 387

        LDR     R7,pixtable_at
        MOV     R6,#0
        STR     R6,pixtable_at
        STR     R7,tile_pixtable
        STR     R7,tile_temptab

Kevin Bracey's avatar
Kevin Bracey committed
388
        EXIT
Neil Turton's avatar
Neil Turton committed
389 390 391 392

05
        ; if tile_temptab and tile_pixtable were different then we must have been
        ; tiling a window with a custom tile. Can't free it either. However, the
Ben Avison's avatar
Ben Avison committed
393
        ; generic table is probably stuffed as well.
Neil Turton's avatar
Neil Turton committed
394 395

        LDR     R7,tile_pixtable
Ben Avison's avatar
Ben Avison committed
396
        ORR     R7,R7,#1
Neil Turton's avatar
Neil Turton committed
397 398 399 400
        STR     R7,tile_pixtable

        LDR     R7,pixtable_at
        STR     R7,tile_temptab
Kevin Bracey's avatar
Kevin Bracey committed
401
        EXIT
Neil Turton's avatar
Neil Turton committed
402 403 404 405 406 407

        LTORG

        ]

        END