further unification and refactoring
[picodrive.git] / platform / psp / asm_utils.s
... / ...
CommitLineData
1# vim:filetype=mips
2
3# some asm utils
4# (c) Copyright 2007, Grazvydas "notaz" Ignotas
5# All Rights Reserved
6
7.set noreorder
8.set noat
9
10.data
11.align 4
12
13.byte 0, 1, 6, 11, 16, 21, 26, 31 # -4
14.byte 0, 2, 7, 12, 16, 21, 26, 31 # -3
15.byte 0, 3, 7, 12, 17, 22, 26, 31 # -2
16.byte 0, 4, 8, 13, 17, 22, 26, 31 # -1
17pal_gmtab:
18.byte 0, 5, 10, 15, 16, 21, 26, 31 # 0
19.byte 0, 6, 10, 15, 19, 23, 27, 31
20.byte 0, 7, 11, 15, 19, 23, 27, 31
21.byte 0, 8, 12, 16, 19, 23, 27, 31
22.byte 0, 9, 12, 16, 20, 24, 27, 31
23.byte 0, 10, 13, 17, 20, 24, 27, 31
24.byte 0, 10, 14, 17, 21, 24, 28, 31
25.byte 0, 11, 15, 18, 21, 24, 28, 31
26.byte 0, 12, 15, 18, 22, 25, 28, 31
27.byte 0, 13, 16, 19, 22, 25, 28, 31
28.byte 0, 14, 17, 20, 22, 25, 28, 31 # 10
29.byte 0, 15, 17, 20, 23, 26, 28, 31
30.byte 0, 16, 18, 21, 23, 26, 28, 31
31.byte 0, 16, 19, 21, 24, 26, 29, 31
32.byte 0, 17, 20, 22, 24, 26, 29, 31
33.byte 0, 18, 20, 22, 25, 27, 29, 31
34.byte 0, 19, 21, 23, 25, 27, 29, 31 # 16
35
36.text
37.align 4
38
39# bbbb bggg gggr rrrr
40
41#.global pal_gmtab
42.global do_pal_convert # dest, src, gammaa_val, black_lvl
43
44do_pal_convert:
45 bnez $a2, dpc_gma
46 li $t0, 64/2
47 bnez $a3, dpc_gma
48 lui $t2, 0x00e
49 ori $t2, 0x00e
50 lui $t3, 0x006
51 ori $t3, 0x006
52 lui $t4, 0x0e0
53 ori $t4, 0x0e0
54 lui $t6, 0xe00
55 ori $t6, 0xe00
56 lui $t7, 0x600
57 ori $t7, 0x600
58
59dpc_loop:
60 lw $v0, 0($a1)
61 addiu $a1, 4
62 and $v1, $v0, $t2 # r
63 sll $v1, 1
64 and $t9, $v0, $t3
65 srl $t9, 1
66 or $v1, $t9 # r
67 and $t9, $v0, $t4 # g
68 sll $t8, $t9, 3
69 or $v1, $t8
70 or $v1, $t9 # g
71 and $t9, $v0, $t6 # b
72 sll $t9, 4
73 or $v1, $t9
74 and $t9, $v0, $t7
75 sll $t9, 2
76 or $v1, $t9 # b
77 sw $v1, 0($a0)
78 addiu $t0, -1
79 bnez $t0, dpc_loop
80 addiu $a0, 4
81
82 jr $ra
83 nop
84
85# non-zero gamma
86dpc_gma:
87 slt $t2, $a2, $0
88 sll $a2, 3
89 lui $t1, %hi(pal_gmtab)
90 addiu $t1, %lo(pal_gmtab)
91 addu $a2, $t1
92 beqz $a3, dpc_gma_loop
93 sb $0, 0($a2) # black level 0
94 bnez $t2, dpc_gma_loop # gamma < 0, keep black at 0
95 addiu $a3, -2
96 slt $t2, $a3, $0 # t2 = a3_orig == 1 ? 1 : 0
97 lb $t1, 1($a2)
98 addiu $t1, -2
99 srlv $t1, $t1, $t2
100 sb $t1, 0($a2)
101
102dpc_gma_loop:
103 lw $v0, 0($a1)
104 addiu $a1, 4
105 ext $v1, $v0, 1, 3
106 addu $v1, $a2
107 lb $v1, 0($v1)
108 ext $t1, $v0, 5, 3
109 addu $t1, $a2
110 lb $t1, 0($t1)
111 ext $t2, $v0, 9, 3
112 addu $t2, $a2
113 lb $t2, 0($t2)
114 ext $t3, $v0, 17, 3
115 addu $t3, $a2
116 lb $t3, 0($t3)
117 ext $t4, $v0, 21, 3
118 addu $t4, $a2
119 lb $t4, 0($t4)
120 ext $t5, $v0, 25, 3
121 addu $t5, $a2
122 lb $t5, 0($t5)
123 ins $v1, $t1, 6, 5
124 ins $v1, $t2, 11, 5
125 ins $v1, $t3, 16, 5
126 ins $v1, $t4, 22, 5
127 ins $v1, $t5, 27, 5
128 sw $v1, 0($a0)
129 addiu $t0, -1
130 bnez $t0, dpc_gma_loop
131 addiu $a0, 4
132
133 jr $ra
134 nop
135