psx_gpu: convert to UAL, load everything from context
[pcsx_rearmed.git] / plugins / gpu-gles / gpulib_if.c
index 569fff4..1f4a23d 100644 (file)
@@ -479,10 +479,15 @@ switch((gdata>>24)&0xff)
 
 static int is_opened;
 
-int renderer_init(void)
+static void set_vram(void *vram)
 {
- psxVub=(void *)gpu.vram;
+ psxVub=vram;
  psxVuw=(unsigned short *)psxVub;
+}
+
+int renderer_init(void)
+{
+ set_vram(gpu.vram);
 
  PSXDisplay.RGB24        = FALSE;                      // init some stuff
  PSXDisplay.Interlaced   = FALSE;
@@ -500,18 +505,38 @@ int renderer_init(void)
  return 0;
 }
 
+void renderer_finish(void)
+{
+}
+
+void renderer_notify_res_change(void)
+{
+}
+
 extern const unsigned char cmd_lengths[256];
 
-void do_cmd_list(unsigned int *list, int list_len)
+// XXX: mostly dupe code from soft peops
+int do_cmd_list(unsigned int *list, int list_len, int *last_cmd)
 {
   unsigned int cmd, len;
-
+  unsigned int *list_start = list;
   unsigned int *list_end = list + list_len;
 
   for (; list < list_end; list += 1 + len)
   {
     cmd = *list >> 24;
     len = cmd_lengths[cmd];
+    if (list + 1 + len > list_end) {
+      cmd = -1;
+      break;
+    }
+
+#ifndef TEST
+    if (cmd == 0xa0 || cmd == 0xc0)
+      break; // image i/o, forward to upper layer
+    else if ((cmd & 0xf8) == 0xe0)
+      gpu.ex_regs[cmd & 7] = list[0];
+#endif
 
     primTableJ[cmd]((void *)list);
 
@@ -519,41 +544,47 @@ void do_cmd_list(unsigned int *list, int list_len)
     {
       case 0x48 ... 0x4F:
       {
-        uint32_t num_vertexes = 1;
-        uint32_t *list_position = &(list[2]);
+        uint32_t num_vertexes = 2;
+        uint32_t *list_position = &(list[3]);
 
         while(1)
         {
-          if((*list_position & 0xf000f000) == 0x50005000 || list_position >= list_end)
+          if(list_position >= list_end) {
+            cmd = -1;
+            goto breakloop;
+          }
+
+          if((*list_position & 0xf000f000) == 0x50005000)
             break;
 
           list_position++;
           num_vertexes++;
         }
 
-        if(num_vertexes > 2)
-          len += (num_vertexes - 2);
-
+        len += (num_vertexes - 2);
         break;
       }
 
       case 0x58 ... 0x5F:
       {
-        uint32_t num_vertexes = 1;
-        uint32_t *list_position = &(list[2]);
+        uint32_t num_vertexes = 2;
+        uint32_t *list_position = &(list[4]);
 
         while(1)
         {
-          if((*list_position & 0xf000f000) == 0x50005000 || list_position >= list_end)
+          if(list_position >= list_end) {
+            cmd = -1;
+            goto breakloop;
+          }
+
+          if((*list_position & 0xf000f000) == 0x50005000)
             break;
 
           list_position += 2;
           num_vertexes++;
         }
 
-        if(num_vertexes > 2)
-          len += (num_vertexes - 2) * 2;
-
+        len += (num_vertexes - 2) * 2;
         break;
       }
 
@@ -571,6 +602,13 @@ void do_cmd_list(unsigned int *list, int list_len)
 #endif
     }
   }
+
+breakloop:
+  gpu.ex_regs[1] &= ~0x1ff;
+  gpu.ex_regs[1] |= lGPUstatusRet & 0x1ff;
+
+  *last_cmd = cmd;
+  return list - list_start;
 }
 
 void renderer_sync_ecmds(uint32_t *ecmds)
@@ -626,11 +664,22 @@ void vout_update(void)
  }
 }
 
+void vout_blank(void)
+{
+}
+
+void vout_set_config(const struct rearmed_cbs *cbs)
+{
+}
+
+static struct rearmed_cbs *cbs;
+
 long GPUopen(void **dpy)
 {
  int ret;
 
- iResX = 800; iResY = 480;
+ iResX = cbs->screen_w;
+ iResY = cbs->screen_h;
  rRatioRect.left   = rRatioRect.top=0;
  rRatioRect.right  = iResX;
  rRatioRect.bottom = iResY;
@@ -641,7 +690,7 @@ long GPUopen(void **dpy)
 
  InitializeTextureStore();                             // init texture mem
 
- ret = GLinitialize();
+ ret = GLinitialize(cbs->gles_display, cbs->gles_surface);
  MakeDisplayLists();
 
  is_opened = 1;
@@ -657,8 +706,6 @@ long GPUclose(void)
  return 0;
 }
 
-static struct rearmed_cbs *cbs;
-
 /* acting as both renderer and vout handler here .. */
 void renderer_set_config(const struct rearmed_cbs *cbs_)
 {
@@ -679,15 +726,23 @@ void renderer_set_config(const struct rearmed_cbs *cbs_)
  bUseFastMdec = cbs->gpu_peopsgl.bUseFastMdec;
  iTexGarbageCollection = cbs->gpu_peopsgl.iTexGarbageCollection;
  iVRamSize = cbs->gpu_peopsgl.iVRamSize;
-}
 
-void vout_set_config(const struct rearmed_cbs *cbs)
-{
+ if (cbs->pl_set_gpu_caps)
+  cbs->pl_set_gpu_caps(GPU_CAP_OWNS_DISPLAY);
+
+ if (is_opened && cbs->gles_display != NULL && cbs->gles_surface != NULL) {
+  // HACK..
+  GPUclose();
+  GPUopen(NULL);
+ }
+
+ set_vram(gpu.vram);
 }
 
 void SetAspectRatio(void)
 {
- cbs->pl_get_layer_pos(&rRatioRect.left, &rRatioRect.top, &rRatioRect.right, &rRatioRect.bottom);
+ if (cbs->pl_get_layer_pos)
+  cbs->pl_get_layer_pos(&rRatioRect.left, &rRatioRect.top, &rRatioRect.right, &rRatioRect.bottom);
 
  glScissor(rRatioRect.left,
            iResY-(rRatioRect.top+rRatioRect.bottom),