// Playstation Driver for AALib // James Russell - 11th October, 1997 #define DEBUG #include #include #include #include #include #include "pad.h" #include "asssert.h" #include "dump.h" #include "aalib.h" #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif #define BIT(x) (1 << (x)) #define SCREEN_WIDTH 320 // screen width and height static short g_Screen_Height; // This one is worked out depending on NTSC/PAL #define PACKETMAX 2048 /* Max GPU packets */ #define PACKETMAX2 (PACKETMAX*24) #define OT_LENGTH 12 static GsOT g_OT[2]; /* Handler of OT */ static GsOT_TAG g_OTTags[2][1<vx = x, (vector)->vy = y, (vector)->vz = z #define KeepWithinRange(quantity, min, max) \ { \ if ((quantity) < (min)) \ (quantity) = (min); \ else if ((quantity) > (max)) \ (quantity) = (max); \ } // ----------------------------------------------------------------------- // ----------------------- PROCEDURES // ----------------------------------------------------------------------- void DealWithControllerPad (void) { long pad = PadRead(); // quit program if (pad & PADstart && pad & PADselect) g_Quit = TRUE; // pause if (pad & PADstart) while (pad & PADstart) pad = PadRead(); } void WaitforPadStart(void) { while(PadRead() & PADstart); while(!(PadRead() & PADstart)); } void aa_psx_InitNewDraw(void) { DealWithControllerPad(); GsSetWorkBase(g_PacketArea[g_ScreenBufferNum]); GsClearOt(0,0,&g_OT[g_ScreenBufferNum]); } void aa_psx_CompleteDraw(void) { DrawSync(0); VSync(0); // ResetGraph(1); GsSwapDispBuff(); GsSortClear(0,0,1,&g_OT[g_ScreenBufferNum]); GsDrawOt(&g_OT[g_ScreenBufferNum]); g_ScreenBufferNum ^= 1; } int aa_psx_init(void *parms) { static int registered = FALSE; short x,y,cell, tpage; RECT recp; GsIMAGE tim1; if(!registered) { PadInit(); SetVideoMode(MODE_PAL); g_Screen_Height = (GetVideoMode() == MODE_NTSC) ? 240 : 256; GsInitGraph(SCREEN_WIDTH,g_Screen_Height,GsOFSGPU,1,0); GsDefDispBuff(0,0,0, (g_Screen_Height<480)?g_Screen_Height:0); g_ScreenBufferNum = GsGetActiveBuff(); g_OT[0].length=OT_LENGTH; g_OT[0].org=&g_OTTags[0][0]; g_OT[1].length=OT_LENGTH; g_OT[1].org=&g_OTTags[1][0]; GsClearOt(0,0,&g_OT[0]); GsClearOt(0,0,&g_OT[1]); // Initialise Sprites GsGetTimInfo((u_long *)(aatxtraw2+4),&tim1); recp.x=tim1.px; recp.y=tim1.py; recp.w=tim1.pw; recp.h=tim1.ph; LoadImage(&recp, tim1.pixel); if((tim1.pmode & 0x7) < 2) { // tim1.cx=1008; recp.x=tim1.cx; recp.y=tim1.cy; recp.w=tim1.cw; recp.h=tim1.ch; *((u_short *)tim1.clut) = (u_short) 0x1; LoadImage(&recp,tim1.clut); } tpage = GetTPage(tim1.pmode & 0x7, // 4 bit CLUT 1, // 0.5 * back + 0.5 * forward semi-transparency tim1.px, // x tim1.py); // y for(y = 0, cell = 0; y < 16*3 ; y++) for(x = 0; x < 16; x++, cell++) { if(y == 32) { tpage = GetTPage(tim1.pmode & 0x7, // 4 bit CLUT 1, // 0.5 * back + 0.5 * forward semi-transparency tim1.px, // x tim1.py+256); // y } g_CharSprite[cell].attribute = BIT(6) | // Brightness OFF. BIT(27); // Rotation OFF. g_CharSprite[cell].x = g_CharSprite[cell].y = 0; g_CharSprite[cell].w = FONTWIDTH; g_CharSprite[cell].h = FONTHEIGHT; g_CharSprite[cell].tpage = tpage; g_CharSprite[cell].u = x * FONTWIDTH; g_CharSprite[cell].v = ((y >= 32)?(y-32):y) * FONTHEIGHT; g_CharSprite[cell].cx = tim1.cx; g_CharSprite[cell].cy = tim1.cy; g_CharSprite[cell].r = g_CharSprite[cell].g = g_CharSprite[cell].b = 128; g_CharSprite[cell].mx = (FONTWIDTH+1)/2; g_CharSprite[cell].my = (FONTHEIGHT+1)/2; g_CharSprite[cell].scalex = g_CharSprite[cell].scaley = ONE; g_CharSprite[cell].rotate = 0; } g_DeviceWidth = SCREEN_WIDTH/FONTWIDTH; g_DeviceHeight = g_Screen_Height/FONTHEIGHT; psx_d.params.font = &font14; registered = TRUE; } return 1; } void aa_psx_uninit(struct aa_context *a) { } void aa_psx_getsize(struct aa_context *a, int *width, int *height) { *width = g_DeviceWidth; *height = g_DeviceHeight; } void aa_psx_flush(struct aa_context *a) { u_short x,y; u_char *p = a->textbuffer; u_char *q = a->attrbuffer; int letter, attribute; int ypos, xpos; for(y = 0, ypos = 0; y < aa_scrheight(a); y++, ypos+= FONTHEIGHT) for(x = 0,xpos = 0; x < aa_scrwidth(a); x++, xpos += FONTWIDTH) { letter = *(p++); attribute = *(q++); if(attribute == AA_REVERSE) { letter+=512; g_CharSprite[letter].x = xpos; g_CharSprite[letter].y = ypos; GsSortFastSprite(&g_CharSprite[letter],&g_OT[g_ScreenBufferNum],0); } else if((letter != 0) && (letter != ' ') && (letter != 0xff)) { if(attribute == AA_DIM) letter += 256; g_CharSprite[letter].x = xpos; g_CharSprite[letter].y = ypos; GsSortFastSprite(&g_CharSprite[letter],&g_OT[g_ScreenBufferNum],0); // GsSortSprite(&g_CharSprite[letter],&g_OT[g_ScreenBufferNum],0); } } } struct aa_driver psx_d = { "psx", "Playstation console driver 1.0", { NULL, AA_NORMAL_MASK | AA_EIGHT | AA_EXTENDED | AA_REVERSE_MASK | AA_DIM_MASK, 80, 25 }, aa_psx_init, aa_psx_uninit, aa_psx_getsize, NULL,NULL,NULL,NULL, aa_psx_flush, NULL };