sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

__osViSwapContext.c (2176B)


      1 #include "libultra_internal.h"
      2 #include "PR/rcp.h"
      3 
      4 extern OSViContext *__osViNext;
      5 extern OSViContext *__osViCurr;
      6 
      7 extern u32 __additional_scanline;
      8 
      9 void __osViSwapContext() {
     10     register OSViMode *viMode;
     11     register OSViContext *s1;
     12     u32 origin;
     13     u32 hStart;
     14 #ifdef VERSION_CN
     15     u32 vStart;
     16 #endif
     17     u32 sp34;
     18     u32 field;
     19     field = 0;
     20     s1 = __osViNext;
     21     viMode = s1->modep;
     22     field = IO_READ(VI_V_CURRENT_LINE_REG) & 1;
     23     origin = osVirtualToPhysical(s1->buffer) + viMode->fldRegs[field].origin;
     24     if (s1->unk00 & 2) {
     25         s1->unk20 |= viMode->comRegs.xScale & ~0xfff;
     26     } else {
     27         s1->unk20 = viMode->comRegs.xScale;
     28     }
     29     if (s1->unk00 & 4) {
     30         sp34 = (u32)(viMode->fldRegs[field].yScale & 0xfff);
     31         s1->unk2c = s1->unk24 * sp34;
     32         s1->unk2c |= viMode->fldRegs[field].yScale & ~0xfff;
     33     } else {
     34         s1->unk2c = viMode->fldRegs[field].yScale;
     35     }
     36 
     37 #ifdef VERSION_CN
     38     vStart = viMode->fldRegs[field].vStart - (__additional_scanline << 0x10) + __additional_scanline;
     39 #endif
     40     hStart = viMode->comRegs.hStart;
     41 
     42     if (s1->unk00 & 0x20) {
     43         hStart = 0;
     44     }
     45     if (s1->unk00 & 0x40) {
     46         s1->unk2c = 0;
     47         origin = osVirtualToPhysical(s1->buffer);
     48     }
     49     if (s1->unk00 & 0x80) {
     50         s1->unk2c = (s1->unk28 << 0x10) & 0x3ff0000;
     51         origin = osVirtualToPhysical(s1->buffer);
     52     }
     53     IO_WRITE(VI_ORIGIN_REG, origin);
     54     IO_WRITE(VI_WIDTH_REG, viMode->comRegs.width);
     55     IO_WRITE(VI_BURST_REG, viMode->comRegs.burst);
     56     IO_WRITE(VI_V_SYNC_REG, viMode->comRegs.vSync);
     57     IO_WRITE(VI_H_SYNC_REG, viMode->comRegs.hSync);
     58     IO_WRITE(VI_LEAP_REG, viMode->comRegs.leap);
     59     IO_WRITE(VI_H_START_REG, hStart);
     60 #ifdef VERSION_CN
     61     IO_WRITE(VI_V_START_REG, vStart);
     62 #else
     63     IO_WRITE(VI_V_START_REG, viMode->fldRegs[field].vStart);
     64 #endif
     65     IO_WRITE(VI_V_BURST_REG, viMode->fldRegs[field].vBurst);
     66     IO_WRITE(VI_INTR_REG, viMode->fldRegs[field].vIntr);
     67     IO_WRITE(VI_X_SCALE_REG, s1->unk20);
     68     IO_WRITE(VI_Y_SCALE_REG, s1->unk2c);
     69     IO_WRITE(VI_CONTROL_REG, s1->features);
     70     __osViNext = __osViCurr;
     71     __osViCurr = s1;
     72     *__osViNext = *__osViCurr;
     73 }