MCPcopy Create free account
hub / github.com/dborth/fceugx / MakeTexture

Function MakeTexture

source/gcvideo.cpp:1066–1215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1064 ****************************************************************************/
1065
1066void MakeTexture(const void *src, void *dst, s32 width, s32 height)
1067{
1068 // Calculate base offsets
1069 const s32 borderwidth = (256 - width) / 2;
1070 const s32 borderheight = (240 - height) / 2;
1071
1072 // Initial pointers point directly to the top-left of the rendering area
1073 const u8 *srcBuf = (const u8 *)src + (borderheight << 8) + borderwidth;
1074 u8 *dstBuf = (u8 *)dst + (borderheight * 512) + (borderwidth * 8);
1075
1076 u32 r_src_row=0, r_dst_row=0;
1077 u32 t0=0, t1=0, t2=0, t3=0, w0=0, w1=0;
1078
1079 __asm__ __volatile__ (
1080 "srwi %[width], %[width], 2\n" // width_tiles = width / 4
1081 "srwi %[height], %[height], 2\n" // height_tiles = height / 4
1082
1083 "2: mtctr %[width]\n" // Inner loop X
1084 "mr %[r_src_row], %[src]\n" // Save row start anchors
1085 "mr %[r_dst_row], %[dst]\n"
1086
1087 "1: dcbz 0, %[dst]\n" // ZERO L1 CACHE (32 bytes)
1088
1089 // ----------------------------------------------------
1090 // BLOCK 1: Row 0 & 1, Left Half
1091 // ----------------------------------------------------
1092 "lbz %[t0], 0(%[src])\n"
1093 "lbz %[t1], 1(%[src])\n"
1094 "lbz %[t2], 256(%[src])\n"
1095 "lbz %[t3], 257(%[src])\n"
1096
1097 // Calculate offsets (index * 2 bytes)
1098 "slwi %[t0], %[t0], 1\n"
1099 "slwi %[t1], %[t1], 1\n"
1100 "slwi %[t2], %[t2], 1\n"
1101 "slwi %[t3], %[t3], 1\n"
1102
1103 // Asynchronous Palette Lookups (lhzx)
1104 "lhzx %[t0], %[pal], %[t0]\n"
1105 "lhzx %[t1], %[pal], %[t1]\n"
1106 "lhzx %[t2], %[pal], %[t2]\n"
1107 "lhzx %[t3], %[pal], %[t3]\n"
1108
1109 // Pack into 32-bit registers (w0, w1)
1110 "slwi %[w0], %[t0], 16\n"
1111 "slwi %[w1], %[t2], 16\n"
1112 "or %[w0], %[w0], %[t1]\n"
1113 "or %[w1], %[w1], %[t3]\n"
1114
1115 "stw %[w0], 0(%[dst])\n"
1116 "stw %[w1], 8(%[dst])\n"
1117
1118 // ----------------------------------------------------
1119 // BLOCK 2: Row 0 & 1, Right Half
1120 // ----------------------------------------------------
1121 "lbz %[t0], 2(%[src])\n"
1122 "lbz %[t1], 3(%[src])\n"
1123 "lbz %[t2], 258(%[src])\n"

Callers 1

RenderFrameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected