@@ -1,6 +1,47 @@
# pragma once
# include "gte_instruction.hpp"
// GTE Overview
// GTE Data Register Summary (cop2r0-31)
//
// `mtc2` (Move To Coprocessor 2): Sets a Data Register (0– 31).
// `mfc2` (Move From Coprocessor 2): Gets a Data Register (0– 31).
//
// | cop2r0-1 | 3xS16 | VXY0,VZ0 | Vector 0 (X,Y,Z) |
// | cop2r2-3 | 3xS16 | VXY1,VZ1 | Vector 1 (X,Y,Z) |
// | cop2r4-5 | 3xS16 | VXY2,VZ2 | Vector 2 (X,Y,Z) |
// | cop2r6 | 4xU8 | RGBC | Color/code value |
// | cop2r7 | 1xU16 | OTZ | Average Z value (for Ordering Table) |
// | cop2r8 | 1xS16 | IR0 | 16bit Accumulator (Interpolate) |
// | cop2r9-11 | 3xS16 | IR1,IR2,IR3 | 16bit Accumulator (Vector) |
// | cop2r12-15 | 6xS16 | SXY0,SXY1,SXY2,SXYP | Screen XY-coordinate FIFO (3 stages) |
// | cop2r16-19 | 4xU16 | SZ0,SZ1,SZ2,SZ3 | Screen Z-coordinate FIFO (4 stages) |
// | cop2r20-22 | 12xU8 | RGB0,RGB1,RGB2 | Color CRGB-code/color FIFO (3 stages) |
// | cop2r23 | 4xU8 | (RES1) | Prohibited |
// | cop2r24 | 1xS32 | MAC0 | 32bit Maths Accumulators (Value) |
// | cop2r25-27 | 3xS32 | MAC1,MAC2,MAC3 | 32bit Maths Accumulators (Vector) |
// | cop2r28-29 | 1xU15 | IRGB,ORGB | Convert RGB Color (48bit vs 15bit) |
// | cop2r30-31 | 2xS32 | LZCS,LZCR | Count Leading-Zeroes/Ones (sign bits) |
//
// GTE Control Register Summary (cop2r32-63)
// ctc2 (Copy To Control Coprocessor 2): Sets a Control Register (cnt0– 31).
// cfc2 (Copy From Control Coprocessor 2): Gets a Control Register (cnt0– 31).
//
// | cop2r32-36 9xS16 RT11RT12,..,RT33 | Rotation matrix (3x3) | cnt0-4 |
// | cop2r37-39 3x 32 TRX,TRY,TRZ | Translation vector (X,Y,Z) | cnt5-7 |
// | cop2r40-44 9xS16 L11L12,..,L33 | Light source matrix (3x3) | cnt8-12 |
// | cop2r45-47 3x 32 RBK,GBK,BBK | Background color (R,G,B) | cnt13-15 |
// | cop2r48-52 9xS16 LR1LR2,..,LB3 | Light color matrix source (3x3) | cnt16-20 |
// | cop2r53-55 3x 32 RFC,GFC,BFC | Far color (R,G,B) | cnt21-23 |
// | cop2r56-57 2x 32 OFX,OFY | Screen offset (X,Y) | cnt24-25 | (1bit sign, 15bit integer, 16bit fraction)
// | cop2r58 BuggyU16 H | Projection plane distance. | cnt26 | (0bit sign, 16bit integer, 0bit fraction)
// | cop2r59 S16 DQA | Depth queing parameter A (coeff) | cnt27 |
// | cop2r60 32 DQB | Depth queing parameter B (offset) | cnt28 |
// | cop2r61-62 2xS16 ZSF3,ZSF4 | Average Z scale factors | cnt29-30 |
// | cop2r63 U20 FLAG | Returns any calculation errors | cnt31 |
namespace JabyEngine {
namespace GTE {
static constexpr auto StackSize = 16 ;
@@ -213,6 +254,19 @@ namespace JabyEngine {
__asm__ volatile ( " ctc2 $13, $25 " : : " r " ( off_x ) , " r " ( off_y ) : " $12 " , " $13 " ) ;
}
static void get_geom_offset ( int32_t & off_x , int32_t & off_y ) {
int32_t raw_x , raw_y ;
__asm__ volatile (
" cfc2 %0, $24 \n "
" cfc2 %1, $25 "
: " =r " ( raw_x ) , " =r " ( raw_y )
) ;
off_x = raw_x > > 16 ;
off_y = raw_y > > 16 ;
}
/*
SetGeomScreen(h)
@@ -222,6 +276,18 @@ namespace JabyEngine {
__asm__ volatile ( " ctc2 %0, $26 " : : " r " ( h ) ) ;
}
/*
GetGeomScreen() (???)
Get distance from viewpoint to screen.
*/
static int32_t get_geom_screen ( ) {
int32_t h ;
__asm__ volatile ( " cfc2 %0, $26 " : " =r " ( h ) ) ;
return h ;
}
// Implementations for the MATRIX struct
inline MATRIX & MATRIX : : comp ( const MATRIX & matrix ) {
return comp_matrix ( matrix , * this , * this ) ;