Advertisement
Guest User

Untitled

a guest
May 9th, 2018
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.05 KB | None | 0 0
  1. /*
  2. ===========================================================
  3.                 Sony PlayStation 1 Source Code
  4. ===========================================================
  5.                          FONT EXAMPLE
  6. Displays text on the screen using the built in GPU routines
  7. -----------------------------------------------------------
  8.  
  9.     Developer / Programmer..............: SCEI & PSXDEV.net
  10.     Software Ddevelopment Kit...........: PSY-Q
  11.     Last Updated........................: 04/MAY/2017
  12.  
  13.     Original code by SCEI | Edited by PSXDEV.net
  14.    
  15.     NOTE: This example uses double buffering.
  16.  
  17.   Copyright (C) 1994,1995 by Sony Computer Entertainment Inc.
  18.    Sony Computer Entertainment Inc. Development Department.
  19.                    All Rights Reserved.
  20.                    
  21.                     http://psxdev.net/
  22.  
  23. -----------------------------------------------------------*/
  24.  
  25. #include <stdlib.h>
  26. #include <libgte.h>
  27. #include <libgpu.h>
  28. #include <libgs.h>
  29.  
  30. #define OT_LENGTH 1 // the ordertable length
  31. #define PACKETMAX 18 // the maximum number of objects on the screen
  32. #define SCREEN_WIDTH  320 // screen width
  33. #define SCREEN_HEIGHT 240 // screen height (240 NTSC, 256 PAL)
  34.  
  35. GsOT myOT[2]; // ordering table header
  36. GsOT_TAG myOT_TAG[2][1<<OT_LENGTH]; // ordering table unit
  37. PACKET GPUPacketArea[2][PACKETMAX]; // GPU packet data
  38.  
  39. u_long _ramsize   = 0x00200000; // force 2 megabytes of RAM
  40. u_long _stacksize = 0x00004000; // force 16 kilobytes of stack
  41.  
  42. // --------
  43. // INTEGERS
  44. // --------
  45. short CurrentBuffer = 0; // holds the current buffer number
  46.  
  47. // ----------
  48. // PROTOTYPES
  49. // ----------
  50. void graphics(); // inits the GPU
  51. void display(); // updates the GPU (IE: VRAM/SGRAM/framebuffer)
  52.  
  53. const DEBUG = 1; // debugging (1=on, 0=off)
  54.  
  55. // ---------
  56. // FUNCTIONS
  57. // ---------
  58. POLY_F3 pf3;
  59.  
  60. void DrawSolidTri(short x1, short y1, short x2, short y2, short x3, short y3, int r, int g, int b, int ot)
  61. {
  62.     // draw a solid triangle and fill it with rgb colour
  63.     // EG: DrawSolidTri(200,0, 170,30, 230,30, 255,0,255, 0);
  64.     // check the Psy-Q documentation for the coordinates!
  65.  
  66.     SetPolyF3(&pf3);                            // initialise the primitive
  67.     setRGB0(&pf3, r, g, b);                     // set the fill colour (RGB)
  68.     setXY3(&pf3, x1,y1, x2,y2, x3,y3);          // draw 3 lines (3 sets of x/y co-ords)
  69.     DrawPrim(&pf3);                             // copy shape to frame buffer
  70.     //DrawPrim(&pf3);                           // copy shape to frame buffer
  71.     GsSortPoly(&pf3, &myOT[CurrentBuffer], ot); // put the polygon into the order table
  72. }
  73.  
  74.  
  75. void DrawTransTri(short x1, short y1, short x2, short y2, short x3, short y3, int r, int g, int b, int ot)
  76. {
  77.     // draw a transparent triangle
  78.     // the transparency 'colour' is calculated from the fgnd & bgns pixels.
  79.     // EG: DrawTransTri(50,0, 70,60, 130,60, 255,0,255, 0);
  80.  
  81.     SetPolyF3(&pf3);                            // initialize primitive
  82.     setRGB0(&pf3, r, g, b);                     // set the foreground fill colour
  83.     setSemiTrans(&pf3, 1);                      // semi-transparency; 0=off; 1=on
  84.     setXY3(&pf3, x1,y1, x2,y2, x3,y3);          // draw 4 lines (4 sets of x/y co-ords)
  85.     //DrawPrim(&pf3);                           // copy shape to frame buffer
  86.     GsSortPoly(&pf3, &myOT[CurrentBuffer], ot); // put the polygon into the order table
  87. }
  88.  
  89. // ----
  90. // MAIN
  91. // ----
  92. int main()
  93. {
  94.     graphics(); // setup the graphics (seen below)
  95.     FntLoad(960, 256); // load the font from the BIOS into the framebuffer
  96.     SetDumpFnt(FntOpen(5, 20, 320, 240, 0, 512)); // screen X,Y | max text length X,Y | autmatic background clear 0,1 | max characters
  97.    
  98.     if (DEBUG) // should debug be true (equal 1)...
  99.     {
  100.         // print to the TTY stream (only visible if you're using one)
  101.         printf("\n\nHello World\n");
  102.         printf("\nhttp://psxdev.net/");
  103.     }
  104.  
  105.     while (1) // draw and display forever
  106.     {
  107.         FntPrint("             HELLO WORLD\n\n          HTTP://PSXDEV.NET/");
  108.         DrawSolidTri(0, 0, 200, 200, 0, 300, 4, 255, 4, 0);
  109.         display();
  110.     }
  111.  
  112.     return 0; // this will never be reached because we're in a while loop above
  113. }
  114.  
  115. void graphics()
  116. {
  117.     SetVideoMode(1); // PAL mode
  118.     //SetVideoMode(0); // NTSC mode
  119.    
  120.     GsInitGraph(SCREEN_WIDTH, SCREEN_HEIGHT, GsINTER|GsOFSGPU, 1, 0); // set the graphics mode resolutions (GsNONINTER for NTSC, and GsINTER for PAL)
  121.     GsDefDispBuff(0, 0, 0, SCREEN_HEIGHT); // tell the GPU to draw from the top left coordinates of the framebuffer
  122.    
  123.     // init the ordertables
  124.     myOT[0].length = OT_LENGTH;
  125.     myOT[1].length = OT_LENGTH;
  126.     myOT[0].org = myOT_TAG[0];
  127.     myOT[1].org = myOT_TAG[1];
  128.    
  129.     // clear the ordertables
  130.     GsClearOt(0,0,&myOT[0]);
  131.     GsClearOt(0,0,&myOT[1]);
  132. }
  133.  
  134.  
  135. void display()
  136. {
  137.     // refresh the font
  138.     FntFlush(-1);
  139.    
  140.     // get the current buffer
  141.     CurrentBuffer = GsGetActiveBuff();
  142.    
  143.     // setup the packet workbase
  144.     GsSetWorkBase((PACKET*)GPUPacketArea[CurrentBuffer]);
  145.    
  146.     // clear the ordering table
  147.     GsClearOt(0,0, &myOT[CurrentBuffer]);
  148.    
  149.     // wait for all drawing to finish
  150.     DrawSync(0);
  151.    
  152.     // wait for v_blank interrupt
  153.     VSync(0);
  154.    
  155.     // flip the double buffers
  156.     GsSwapDispBuff();
  157.    
  158.     // clear the ordering table with a background color (R,G,B)
  159.     GsSortClear(50,50,50, &myOT[CurrentBuffer]);
  160.    
  161.     // draw the ordering table
  162.     GsDrawOt(&myOT[CurrentBuffer]);
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement