draw.c
5.55 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
/*---------------------------------------------------------------------*
Copyright (C) 1997 Nintendo.
$RCSfile: draw.c,v $
$Revision: 1.1.1.1 $
$Date: 2002/05/02 03:27:12 $
*---------------------------------------------------------------------*/
#include"headers.h"
extern Gfx *glistp;
extern Dynamic *dynamicp;
extern void *cfb_ptrs[2];
extern int draw_buffer;
extern ctrl Ctrl[4];
extern OSMesgQueue intMessageQ,dmaMessageQ;
extern OSMesg dummyMessage,dmaMessageBuf;
extern OSIoMesg dmaIOMessageBuf;
extern unsigned char ascrom[];
#define G_CC_INT4 0,0,0,PRIMITIVE,0,0,0,TEXEL0
static Mtx IMTX={
0x00010000, 0x00000000, 0x00000001, 0x00000000,
0x00000000, 0x00010000, 0x00000000, 0x00000001,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000
};
extern int timer,resetflag,color,mode,kanadr;
static short palet[16]={0x0000,0x1085,0x2109,0x318D,0x4211,0x5295,0x6319,0x739D,0x8C63,0x9CE7,0xAD6B,0xBDEF,0xCE73,0xDEF7,0xEF7B,0xFFFF};
static int ccode[48]={
0, 0, 0, 0, 0,136, 136, 0, 0, 255,119,204,
0,136, 0, 51,255,170, 255,153, 51, 102,102,102,
255,204,187, 0, 0,255, 255, 0, 0, 255, 0,255,
0,255, 0, 0,255,255, 255,255, 0, 255,255,255};
#include"msg.sjs"
/* CLEAR FRAMEBUFFER */
static void clear_framebuffer(void)
{
gDPPipeSync(glistp++);
gDPSetCycleType(glistp++, G_CYC_FILL);
/* clear color, cvg = FULL or 1 */
gDPSetColorImage(glistp++,G_IM_FMT_RGBA,G_IM_SIZ_16b,SCREEN_WD,cfb_ptrs[draw_buffer]);
gDPSetFillColor(glistp++, GPACK_RGBA5551(0,0,85,1) << 16 | GPACK_RGBA5551(0,0,85,1));
gDPPipeSync(glistp++);
gDPFillRectangle(glistp++,0,0,SCREEN_WD-1,SCREEN_HT-2);
gDPPipeSync(glistp++);
gDPSetCycleType(glistp++,G_CYC_COPY);
}
/* CLEAR Z-BUFFER */
static void clear_zbuffer(void)
{
gDPPipeSync(glistp++);
gDPSetCycleType(glistp++, G_CYC_FILL);
gDPSetMaskImage(glistp++, K0_TO_PHYS(zbuffer));
gDPSetColorImage(glistp++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WD, K0_TO_PHYS(zbuffer));
gDPSetFillColor(glistp++, GPACK_ZDZ(G_MAXFBZ, 0) << 16 | GPACK_ZDZ(G_MAXFBZ, 0));
gDPPipeSync(glistp++);
gDPFillRectangle(glistp++, 0, 0, SCREEN_WD-1, SCREEN_HT-1);
gDPPipeSync(glistp++);
gDPSetColorImage(glistp++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WD, cfb_ptrs[draw_buffer]);
gDPSetDepthSource(glistp++, G_ZS_PIXEL);
}
/* 戳机1矢机山绩 */
void kanchr(int x,int y,int code)
{
int i;
i=LeoGetKAdr(code);
dmaIOMessageBuf.hdr.pri = OS_MESG_PRI_NORMAL;
dmaIOMessageBuf.hdr.retQueue = &dmaMessageQ;
dmaIOMessageBuf.dramAddr = &kbuffer[kanadr];
dmaIOMessageBuf.devAddr = DDROM_FONT_START + i;
dmaIOMessageBuf.size = 128;
handler->transferInfo.cmdType = OS_OTHERS;
osEPiStartDma(handler, &dmaIOMessageBuf, OS_READ);
/* gDPLoadTextureBlock_4b(glistp++,&kbuffer[kanadr],G_IM_FMT_CI,16,16,0,G_TX_CLAMP,G_TX_CLAMP,G_TX_NOMASK,G_TX_NOMASK,G_TX_NOLOD,G_TX_NOLOD); */
gDPLoadTextureBlock_4b(glistp++,&kbuffer[kanadr],G_IM_FMT_I,16,16,0,G_TX_CLAMP,G_TX_CLAMP,G_TX_NOMASK,G_TX_NOMASK,G_TX_NOLOD,G_TX_NOLOD);
gSPTextureRectangle(glistp++,x<<2,y<<2,(x+16)<<2,(y+16)<<2,0,0,0,0x400,0x400);
kanadr+=128;
osRecvMesg(&dmaMessageQ,&dummyMessage,OS_MESG_BLOCK);
}
/* 戳机矢机误山绩 */
void printk(int x,int y,unsigned char *s)
{
int i;
for(i=0;s[i];i+=2,x+=16)kanchr(x,y,s[i]*256+s[i+1]);
}
/* ASCII矢机误山绩 (zは0×2) */
void printa(int x,int y,int z,unsigned char *s)
{
int ofs,i,sx,dx,dy,cy;
for(i=0;s[i];i++){
ofs=LeoGetAAdr((int)s[i]-32+z*192,&dx,&dy,&cy);
dmaIOMessageBuf.hdr.pri = OS_MESG_PRI_NORMAL;
dmaIOMessageBuf.hdr.retQueue = &dmaMessageQ;
dmaIOMessageBuf.dramAddr = &kbuffer[kanadr];
dmaIOMessageBuf.devAddr = DDROM_FONT_START + ofs;
dmaIOMessageBuf.size = 128;
handler->transferInfo.cmdType = OS_OTHERS;
osEPiStartDma(handler, &dmaIOMessageBuf, OS_READ);
sx=(dx+1)&254;
/* gDPLoadTextureBlock_4b(glistp++,&kbuffer[kanadr],G_IM_FMT_I,dx,dy,0,G_TX_CLAMP,G_TX_CLAMP,G_TX_NOMASK,G_TX_NOMASK,G_TX_NOLOD,G_TX_NOLOD); */
gDPLoadTextureTile_4b(glistp++,&kbuffer[kanadr],G_IM_FMT_I,sx,dy,0,0,(sx-1)<<G_TEXTURE_IMAGE_FRAC,(dy-1)<<G_TEXTURE_IMAGE_FRAC,0,G_TX_CLAMP,G_TX_CLAMP,G_TX_NOMASK,G_TX_NOMASK,G_TX_NOLOD,G_TX_NOLOD);
gSPTextureRectangle(glistp++,x<<2,(y-cy)<<2,(x+dx)<<2,(y-cy+dy)<<2,0,0,0,0x400,0x400);
kanadr+=128;x+=dx+1;
osRecvMesg(&dmaMessageQ,&dummyMessage,OS_MESG_BLOCK);
}
}
void dspall(void)
{
printk(24,32,strings[0]);
printk(24,52,strings[1]);
printa(24,88,10,strings[2]);
printa(24,108,11,strings[3]);
}
/* DRAW */
void draw(void)
{
u16 perspNorm;
/* 介袋步 */
gSPDisplayList(glistp++,rdpinit_dl);
gSPDisplayList(glistp++,rspinit_dl);
clear_zbuffer();
clear_framebuffer();
gSPSetGeometryMode(glistp++,G_CULL_BACK | G_SHADING_SMOOTH | G_SHADE);
guPerspective(&dynamicp->projection,&perspNorm,33,320.0/240.0,16,2000,1.0);
gSPPerspNormalize(glistp++,perspNorm);
gSPMatrix(glistp++, K0_TO_PHYS((u32) &(dynamicp->projection)),G_MTX_PROJECTION|G_MTX_LOAD|G_MTX_NOPUSH);
guLookAt(&dynamicp->viewing,0,0,1000,0,0,0,0,1,0);
gSPMatrix(glistp++, K0_TO_PHYS((u32) &(dynamicp->viewing)),G_MTX_MODELVIEW|G_MTX_LOAD|G_MTX_NOPUSH);
/* 称硷肋年 */
gSPDisplayList(glistp++,sprite_dl);
gDPPipeSync(glistp++);
/* gDPSetCycleType(glistp++,G_CYC_COPY); */
gDPSetCycleType(glistp++,G_CYC_1CYCLE);
gDPSetRenderMode(glistp++,G_RM_XLU_SURF,G_RM_XLU_SURF2);
gDPSetCombineMode(glistp++,G_CC_INT4,G_CC_INT4);
gDPSetPrimColor(glistp++,0,0,ccode[color*3],ccode[color*3+1],ccode[color*3+2],255);
kanadr=0;
if(Ctrl[0].nowtrg&0x2000)color=(color+1)&15;
dspall();
osInvalDCache(kbuffer,kanadr);
gDPFullSync(glistp++);
gSPEndDisplayList(glistp++);
}