-
Notifications
You must be signed in to change notification settings - Fork 1
/
pg.h
executable file
·212 lines (171 loc) · 5.91 KB
/
pg.h
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
// primitive graphics for Hello World PSP
#ifndef PG_H
#define PG_H
#include <string.h>
//#include "syscall.h"
#include <main.h>
#define RGB(r,g,b) ((((b>>3) & 0x1F)<<10)|(((g>>3) & 0x1F)<<5)|(((r>>3) & 0x1F)<<0)|0x8000)
extern u32 new_pad, now_pad, old_pad;
extern ctrl_data_t paddata;
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 272
#define PIXELSIZE 1 //in short
#define LINESIZE 512 //in short
#define FRAMESIZE 0x44000 //in byte
//480*272 = 60*38
#define CMAX_X 60
#define CMAX_Y 34
#define CMAX2_X 30
#define CMAX2_Y 17
#define CMAX4_X 15
#define CMAX4_Y 8
void pgInit();
void pgWaitV();
void pgWaitVn(unsigned long count);
void pgScreenFrame(long mode,long frame);
void pgScreenFlip();
void pgScreenFlipV();
void pgPrint_drawbg(unsigned long x,unsigned long y,unsigned long color,unsigned long bgcolor,const char *str);
void pgPrint(unsigned long x,unsigned long y,unsigned long color,const char *str);
void pgPrint2(unsigned long x,unsigned long y,unsigned long color,const char *str);
void pgPrint4(unsigned long x,unsigned long y,unsigned long color,const char *str);
void pgPrintf(unsigned long x,unsigned long y,unsigned long color,const char *str, ...);
void pgFillvram(unsigned long color);
void pgBitBlt(unsigned long x,unsigned long y,unsigned long w,unsigned long h,unsigned long mag,const unsigned short *d);
void pgBitBltN1(unsigned long x,unsigned long y,unsigned long *d);
void pgBitBltN15(unsigned long x,unsigned long y,unsigned long *d);
void pgBitBltN2(unsigned long x,unsigned long y,unsigned long h,unsigned long *d);
void pgBitBltStScan(unsigned long x,unsigned long y,unsigned long h,unsigned long *d);
void pgBitBltSt2wotop(unsigned long x,unsigned long y,unsigned long h,unsigned long *d);
void pgBitBltSt2wobot(unsigned long x,unsigned long y,unsigned long h,unsigned long *d);
void pgBitBltSt2Fix(unsigned long x,unsigned long y,unsigned long h,unsigned long mag,const unsigned short *d);
void pgBitBltStFull(unsigned long x,unsigned long y,unsigned long h,unsigned long mag,const unsigned short *d);
void pgBitBltSgb(unsigned long x,unsigned long y,unsigned long *d);
void pgPutChar(unsigned long x,unsigned long y,unsigned long color,unsigned long bgcolor,unsigned char ch,char drawfg,char drawbg,char mag);
void pgDrawFrame(unsigned long x1, unsigned long y1, unsigned long x2, unsigned long y2, unsigned long color);
void pgFillBox(unsigned long x1, unsigned long y1, unsigned long x2, unsigned long y2, unsigned long color);
void mh_print(int x,int y,const char *str,int col);
char *pgGetVramAddr(unsigned long x,unsigned long y);
void readpad(void);
void pgcLocate(unsigned long x, unsigned long y);
void pgcPuthex2(const unsigned long s);
void pgcPuthex8(const unsigned long s);
void pgaSetChannelCallback(int channel, void *callback);
extern u32 now_tick;
//optimize
//long配列をコピー。配列境界は4バイトアラインされている必要あり
static inline void __memcpy4(void *d, void *s, unsigned long c)
{
//for (; c>0; --c) *(((unsigned long *)d)++)=*(((unsigned long *)s)++);
unsigned long *dd=d, *ss=s;
for (; c>0; --c) *dd++ = *ss++;
}
//long配列にセット。配列境界は4バイトアラインされている必要あり
static inline void __memset4(void *d, unsigned long v, unsigned long c)
{
//for (; c>0; --c) *(((unsigned long *)d)++)=v;
unsigned long *dd=d;
for (; c>0; --c) *dd++=v;
}
//long配列をコピー。配列境界は4バイトアラインされている必要あり
//コンパイラの最適化によって予期しないコードが生成されるため、十分に注意のこと。
static inline void __memcpy4aa(void *d, void *s, unsigned long c)
{
unsigned long wk0,wk1,wk2,wk3;
asm volatile (
" .set push" "\n"
" .set noreorder" "\n"
" move %1,%4 " "\n"
" move %2,%5 " "\n"
" move %3,%6 " "\n"
"1: lw %0,0(%2) " "\n"
" addiu %3,%3,-1 " "\n"
" addiu %2,%2,4 " "\n"
" sw %0,0(%1) " "\n"
" bnez %3,1b " "\n"
" addiu %1,%1,4 " "\n"
" .set pop" "\n"
: "=&r" (wk0), // %0
"=&r" (wk1), // %1
"=&r" (wk2), // %2
"=&r" (wk3) // %3
: "r" (d), // %4
"r" (s), // %5
"r" (c) // %6
);
}
//long配列をコピー。配列境界は4バイトアラインされている必要あり
//s,dは参照渡し扱いになるので、リターン後は変更されていると考えたほうが良い
//コンパイラの最適化によって予期しないコードが生成されるため、十分に注意のこと。__memcpy4のほうが安全。
//といいますかcで書いても全然変わらないような。ガンガッタのに。
static inline void __memcpy4a(unsigned long *d, unsigned long *s, unsigned long c)
{
unsigned long wk,counter;
asm volatile (
" .set push" "\n"
" .set noreorder" "\n"
" move %1,%4 " "\n"
"1: lw %0,0(%3) " "\n"
" addiu %1,%1,-1 " "\n"
" addiu %3,%3,4 " "\n"
" sw %0,0(%2) " "\n"
" bnez %1,1b " "\n"
" addiu %2,%2,4 " "\n"
" .set pop" "\n"
: "=&r" (wk), // %0
"=&r" (counter) // %1
: "r" (d), // %2
"r" (s), // %3
"r" (c) // %4
);
}
//#define __USE_MIPS32R2__
static inline void cpy2x(unsigned long *d, unsigned long cc)
{
#ifdef __USE_MIPS32R2__
unsigned long wk0;
asm volatile (
" .set push" "\n"
" .set noreorder" "\n"
" .set mips32r2" "\n"
" srl %0,%2,16" "\n"
" ins %2,%2,16,16" "\n"
" sw %2,0(%1)" "\n"
" ins %0,%0,16,16" "\n"
" sw %0,4(%1)" "\n"
" .set pop" "\n"
: "=&r" (wk0) // %0
: "r" (d), // %1
"r" (cc) // %2
);
#else
*d = (cc&0x0000ffff)|(cc<<16);
*(d+1) = (cc>>16)|(cc&0xffff0000);
#endif
}
static inline void cpy3x(unsigned long *d, unsigned long cc)
{
#ifdef __USE_MIPS32R2__
unsigned long wk0;
asm volatile (
" .set push" "\n"
" .set noreorder" "\n"
" .set mips32r2" "\n"
" sw %2,4(%1)" "\n"
" srl %0,%2,16" "\n"
" ins %2,%2,16,16" "\n"
" sw %2,0(%1)" "\n"
" ins %0,%0,16,16" "\n"
" sw %0,8(%1)" "\n"
" .set pop" "\n"
: "=&r" (wk0) // %0
: "r" (d), // %1
"r" (cc) // %2
);
#else
*d = (cc&0x0000ffff)|(cc<<16);
*(d+1) = cc;
*(d+2) = (cc>>16)|(cc&0xffff0000);
#endif
}
#endif