tmain.s
15.3 KB
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
53
54
55
56
57
58
59
60
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
86
87
88
89
90
91
92
93
94
95
96
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
129
130
131
132
133
134
135
136
137
138
139
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/**************************************************************************
* *
* Copyright (C) 1994, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
*************************************************************************/
/*
* File: tmain.s
* Creator: acorn@sgi.com
* Create Date: Fri Sep 22 11:59:42 PDT 1995
*
* Manufacturing test vector generation
* Based on graphics microcode.
*
*/
#include <rsp.h>
#include <rcp.h>
#include <os.h>
#include <sptask.h>
#include "mbi.h"
#include "tdmem_label.h"
.text TASKBASE # this is coordinated with rspboot.s
.data (DCACHEBASE + RSP_PDATA_OFFSET)
#define MAIN
#include "tdmem_init.h"
.text
#################################################################
#
# Begin task initialization
#
# Register $1 holds the task header address
# format for the task header:
#
# (see task.h)
#
.name rsp_state, $29
.name zero, $0
.name vconst, $v31
.name vconst1, $v30
.name outp, $23
# set state pointer:
addi $29, zero, RSP_STATE_OFFSET
#include "tinit.s"
#################################################################
DMAWaitDL:
jal DMAwait
nop
#################################################################
.unname rsp_state
.unname zero
.unname vconst
.unname vconst1
.unname outp
#include "tst_regs.h"
ori tri_x, zero, START_X # where triangles
ori tri_y, zero, START_Y # will go
ori numtri, zero, 0 # no triangles yet
ori numtst, zero, 0 # no triangles yet
#################################################################
lw parm2, OS_TASK_OFF_DATA(taskhdr) # SetColorImage
lui parm1, 0xff18 #
jal sendCmd #
ori parm1, parm1, 0x013f # 32b, 319 wide
lw parm2, OS_TASK_OFF_DATA_SZ(taskhdr) # SetDepthImage
jal sendCmd #
lui parm1, 0xfe00 #
lw parm2, OS_TASK_OFF_YIELD(taskhdr) # SetTextureImage
sw parm2,0(zero)
lui parm1, 0xfd18 # fmt=0, siz=3 (RGBA32)
jal sendCmd #
# ori parm1, parm1, 0x00ff # 32b, 256 wide
nop
jal sendDL # clr screen,
ori parm1, zero, STARTDL # set OTHERMODE, etc
#################################################################
# lui shadecol, 0xFF00
# ori shadecol, shadecol, 0x08FF # red; full alpha
# ori shadecov, zero, 8 # fully covered
#triloop:
#define STEP_X 2
#define STEP_Y 2
# jal sendNextTri
# nop
# addi shadecov, shadecov, -1
# addi parm1, numtri, -8
# blez parm1, triloop
# addi shadecol, shadecol, (-1*0x100)
# nop
#################################################################
#include "tbl.s"
#################################################################
lui parm1, 0xe900 # fullsync to end DL
jal sendCmd #
ori parm2, zero, 0 #
j TaskDone # all done
##################################################################
##################################################################
################## END OF CODE, START SUBROUTINES ################
##################################################################
##################################################################
##################################################################
# send DL pointed to by parm1
#
sendDL:
ori return_save, return, 0
lw parm2, 0(parm1)
sendDLloop:
jal OutputOpen
addi $18, zero, 8
lw parm3, 4(parm1)
sw parm2, 0(outp)
sw parm3, 4(outp)
lw parm2, 8(parm1)
jal OutputClose
addi outp, outp, 8
bne parm2, zero, sendDLloop
addi parm1, parm1, 8
jr return_save
nop
#
##################################################################
##################################################################
# send rectangle @ DON"T CARE location (upper left -1)
# cov=shadecov
#
sendDCTri:
ori tloc_x, zero, (START_X-STEP_X) # set x,y and send
j sendTri #
ori tloc_y, zero, (START_Y-STEP_Y) #
#
##################################################################
##################################################################
# send a bunch of rects at same pixel to clobber spanbuf
#
#define CLOBBERNUM 32
clobberNextTri:
sh return, RETURN2(zero) # save return address
jal sendDL # set modes for clear
ori parm1, zero, CLPIX_DL #
jal sendNextTri # set "where" & draw 1 tri
ori parm6, zero, CLOBBERNUM #
clobberNTLoop:
jal sendTri # draw another
addi parm6, parm6, -1 #
beq parm6, zero, clobberNTLoop # draw many
nop #
lh return, RETURN2(zero) #
jr return #
nop #
#
##################################################################
##################################################################
# send another rectangle
#
#define SEETEST TEST_LLMT # test to view (or TEST_NONE)
#define FIRSTTRI 0
#define LASTTRI 10000
sendNextTri:
ori tloc_x, zero, START_X # upper left pixel
ori tloc_y, zero, START_Y #
lw parm4, ((SP_DMEM_END&0xffff) - OS_TASK_SIZE + 1 + OS_TASK_OFF_YIELD_SZ)(zero)
bne parm4, numtst, sendDCTri #
nop #
addi numtri, numtri, 1 # 1 more triangle
# addi parm4, numtri, (-1*(FIRSTTRI)) # reacched 1st?
# blez parm4, sendDCTri #
# addi parm4, numtri, (-1*(LASTTRI)) # reached last?
# bgez parm4, sendDCTri #
# nop
#
##################################################################
##################################################################
# send next rectangle
#
sendNewTri:
or tloc_x, tri_x, zero # inc to next pos
addi tri_x, tri_x, STEP_X # and draw pixel
addi parm4, tri_x, (-1*(END_X)) #
bltz parm4, sendTri # end of row?
or tloc_y, tri_y, zero #
addi tri_y, tri_y, STEP_Y # start new row
addi parm4, tri_y, (-1*(END_Y)) #
bltz parm4, sendTri # end of screen?
ori tri_x, zero, START_X #
ori tri_y, zero, START_Y # start again
# addi tri_y, zero, END_Y # end of screen
# addi tri_x, zero, END_X #
# jr return #
# addi parm1, zero, -1 # indicate err
#
##################################################################
##################################################################
# send 1 pix triangle @ x=tloc_x y=tloc_y col=shadecol
# cov=shadecov (0...8)
#
sendTri:
ori return_save, return, 0
jal OutputOpen # get 96 bytes in out buf
addi $18, zero, 96 #
sll parm3, tloc_y, 2 # y
lb parm4, Y_COVERAGE(shadecov) # y subpixel size from coverage lookup
add parm5, parm3, parm4 #
lui parm4, 0xcc80 #
or parm4, parm5, parm4 #
sw parm4, 0(outp) #
sll parm4, parm5, 16 # more y
or parm5, parm3, parm4 #
sw parm5, 4(outp) #
sll parm5, tloc_x, 16 # x
sw parm5, 8(outp) #
sw parm5, 16(outp) #
lb parm4, X_COVERAGE(shadecov) # x subpixel size from coverage lookup
sll parm4, parm4, 14 #
add parm5, parm5, parm4 #
sw parm5, 24(outp) #
sw zero, 12(outp) #
sw zero, 20(outp) #
lb parm5, XS_COVERAGE(shadecov) # MID slope from coverage table
sll parm5, parm5, 9 #
sw parm5, 28(outp) #
srl parm5, shadecol, 24 # red
sll parm5, parm5, 16 #
srl parm4, shadecol, 16 # green
andi parm4, parm4, 0x00ff #
or parm5, parm5, parm4 #
sw parm5, 32(outp) #
andi parm5, shadecol, 0xff00 # blue
sll parm5, parm5, 8 #
andi parm4, shadecol, 0x00ff # alpha
or parm5, parm5, parm4 #
sw parm5, 36(outp)
sw zero, 40(outp) # color slopes
sw zero, 44(outp) #
sw zero, 48(outp) #
sw zero, 52(outp) #
sw zero, 56(outp) #
sw zero, 60(outp) #
sw zero, 64(outp) #
sw zero, 68(outp) #
sw zero, 72(outp) #
sw zero, 76(outp) #
sw zero, 80(outp) #
sw zero, 84(outp) #
sw zero, 88(outp) #
sw zero, 92(outp) #
jal OutputClose # send it
addi outp, outp, 96 #
jr return_save #
nop #
#
##################################################################
##################################################################
# send rectangle @ DON"T CARE location (upper left -1)
# cov=shadecov
#
sendDCRect:
ori tloc_x, zero, (START_X-STEP_X) # set x,y and send
j sendRect #
ori tloc_y, zero, (START_Y-STEP_Y) #
#
##################################################################
##################################################################
# send a bunch of rects at same pixel to clobber spanbuf
#
clobberNextRect:
sh return, RETURN2(zero) # save return address
jal sendDL # set modes for clear
ori parm1, zero, CLPIX_DL #
jal sendNextRect # set "where" & draw 1 tri
ori parm6, zero, CLOBBERNUM #
clobberNRLoop:
jal sendRect # draw another
addi parm6, parm6, -1 #
beq parm6, zero, clobberNRLoop # draw many
nop #
lh return, RETURN2(zero) #
jr return #
nop #
#
##################################################################
##################################################################
# send another rectangle
#
sendNextRect:
ori tloc_x, zero, START_X # upper left pixel
ori tloc_y, zero, START_Y #
lw parm4, ((SP_DMEM_END&0xffff) - OS_TASK_SIZE + 1 + OS_TASK_OFF_YIELD_SZ)(zero)
bne parm4, numtst, sendDCRect #
nop #
addi numtri, numtri, 1 # 1 more Rect
# addi parm4, numtri, (-1*(FIRSTTRI)) # reacched 1st?
# blez parm4, sendDCRect #
# addi parm4, numtri, (-1*(LASTTRI)) # reached last?
# bgez parm4, sendDCRect #
# nop
#
##################################################################
##################################################################
# send next rectangle
#
sendNewRect:
or tloc_x, tri_x, zero # inc to next pos
addi tri_x, tri_x, STEP_X # and draw pixel
addi parm4, tri_x, (-1*(END_X)) #
bltz parm4, sendRect # end of row?
or tloc_y, tri_y, zero #
addi tri_y, tri_y, STEP_Y # start new row
addi parm4, tri_y, (-1*(END_Y)) #
bltz parm4, sendRect # end of screen?
ori tri_x, zero, START_X #
ori tri_y, zero, START_Y # start again
# addi tri_y, zero, END_Y # end of screen
# addi tri_x, zero, END_X #
# jr return #
# addi parm1, zero, -1 # indicate err
#
##################################################################
##################################################################
# send rectangle, h=SIZE_Y w=shadecov s=shadecol
# x=tloc_x, y=tloc_y
#
#define SIZE_Y 20
sendRect:
sh return, RETURN1(zero) #
lui parm1, 0xe400 # textured rectangle cmd
add parm2, tloc_x, shadecov #
sll parm2, parm2, 14 # XH
or parm1, parm1, parm2 #
addi parm2, tloc_y, SIZE_Y # YH
sll parm2, parm2, 2 #
or parm1, parm1, parm2 #
sll parm2, tloc_x, 14 # XL
sll parm3, tloc_y, 2 # YL
jal sendCmd #
or parm2, parm2, parm3 #
sll parm1, shadecol, 21 # S=shadecol T=0
jal sendCmd #
lui parm2, 0x0400 # DSDX=1 DTDY=0
lh return, RETURN1(zero) #
jr return #
#
##################################################################
##################################################################
# send command in parm1, parm2
#
sendCmd:
ori return_save, return, 0
jal OutputOpen
addi $18, zero, 8
sw parm1, 0(outp)
sw parm2, 4(outp)
jal OutputClose
addi outp, outp, 8
jr return_save
nop
#
##################################################################
##################################################################
# Generate next number in sequence:
# sequence = all pow's of two; their +1's & -1's; and negatives of those
#
# 0
# 1
# -1
# 2
# etc
#
nxtnum: # generate seq of all powers
bne parm1, zero, nxtnum_neg # of 2; their +1 & -1; and negs
nop #
nxtnum_return: #
jr return #
addi parm1, parm1, 1 # if 0, do 1 (also finish 2's comp)
nxtnum_neg: #
addi parm2, zero, -1 # negate number (2's comp)
bgtz parm1, nxtnum_return #
xor parm1, parm1, parm2 #
addi parm1, parm1, 1 #
ori parm2, zero, 5 # if %101, do %1000 (add 3)
bne parm1, parm2, nxtnum_3 #
ori parm3, zero, 3 #
jr return #
addi parm1, parm1, 3 #
nxtnum_3: #
beq parm1, parm3, nxtnum_return # if %11, do %100 (add 1)
andi parm2, parm1, 1 #
beq parm2, zero, nxtnum_return # if %...0, do +1 (add 1)
andi parm3, parm1, 2 #
beq parm2, parm1, nxtnum_return # if 1 do 2 (add 1)
nop #
beq parm3, zero, nxtnum_return # if %..01, do -2 (-3, +1)
addi parm1, parm1, -3 #
addi parm1, parm1, 4 # else: +1, <<1 (-3, +4, <<1)
jr return #
sll parm1, parm1, 1 #
#
##################################################################
.unname numtst
##################################################################
#
# Procedure to do DMA reads/writes.
#
# Registers:
#
# $20 mem_addr
# $19 dram_addr
# $18 dma_len
# $17 iswrite?
#
# $11 used as tmp
#
.name mem_addr, $20
.name dram_addr, $19
.name dma_len, $18
.name iswrite, $17
#.name tmp, $16 !! $16 needed as clr2 in lighting
.name tmp, $11
DMAproc:
# request DMA access: (get semaphore)
mfc0 tmp, SP_RESERVED
bne tmp, zero, DMAproc
# note delay slot
# wait for not FULL:
DMAFull:
mfc0 tmp, DMA_FULL
bne tmp, zero, DMAFull
nop
# set DMA registers:
mtc0 mem_addr, DMA_CACHE
# handle writes:
bgtz iswrite, DMAWrite
mtc0 dram_addr, DMA_DRAM
j DMADone
mtc0 dma_len, DMA_READ_LENGTH
DMAWrite:
mtc0 dma_len, DMA_WRITE_LENGTH
DMADone:
jr return
mtc0 zero, SP_RESERVED # delay slot
.unname mem_addr
.unname dram_addr
.unname dma_len
.unname iswrite
.unname tmp
#
#
##################################################################
##################################################################
#
# Procedure to do DMA waits.
#
# Registers:
#
# $11 used as tmp
#
#.name tmp, $20
#.name tmp, $16 !! $16 needed as clr2 in lighting
.name tmp, $11
DMAwait:
# request DMA access: (get semaphore)
mfc0 tmp, SP_RESERVED
bne tmp, zero, DMAwait
# note delay slot
WaitSpin:
mfc0 tmp, DMA_BUSY
bne tmp, zero, WaitSpin
nop
jr return
mtc0 zero, SP_RESERVED # delay slot
.unname tmp
#
#
##################################################################
.unname parm1
.unname parm2
.unname parm3
.unname parm4
.unname parm5
.unname parm6
.unname parm7
##################################################################
#
# other "modules" are appended by #include
#
#==============================================================================
#===== Output module (either DRAM or directly to XBUS) ========================
#==============================================================================
#ifdef OUTPUT_DRAM
# include "toutdram.s"
#else
# include "toutxbus.s"
#endif
#include "tdone.s"
#
#
##################################################################