package net.katsuster.ememu.riscv.core;

import net.katsuster.ememu.generic.*;

/**
 * RISC-V 64 のレジスタファイルです。
 */
public class RV64RegFile implements Reg64File {
    public static final int RISCV_REGFILE_SIZE = 33;

    private Reg64[] regs_usr;

    //現在選択されているレジスタセットです
    private Reg64[] regs;

    public RV64RegFile() {
        String[] name_usr = {
                "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
                "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
                "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
                "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
                "pc",
        };

        regs_usr = new Reg64[RISCV_REGFILE_SIZE];
        for (int i = 0; i < RISCV_REGFILE_SIZE; i++) {
            regs_usr[i] = new Reg64(name_usr[i], 0);
        }

        regs = regs_usr;
    }

    @Override
    public Reg64 getReg(int n) {
        return regs[n];
    }

    @Override
    public String toString() {
        StringBuilder b = new StringBuilder();

        for (int i = 0; i < 32; i += 4) {
            b.append(String.format("  %3s: %08x, %3s: %08x, %3s: %08x, %3s: %08x, \n",
                    getReg(i).getName(), getReg(i).getValue(),
                    getReg(i + 1).getName(), getReg(i + 1).getValue(),
                    getReg(i + 2).getName(), getReg(i + 2).getValue(),
                    getReg(i + 3).getName(), getReg(i + 3).getValue()));
        }
        b.append(String.format("  %s, %s\n",
                getReg(32).toString(), getReg(32).toString()));

        return b.toString();
    }
}

@@ -370,59 +370,60 @@
    %22
-r0
+zero
 %22,
- 
  %22r
-1
+a
 %22,  %22
-r2
+sp
 %22,  %22
-r3
+gp
 %22,  %22
-r4
+tp
 %22,  %22
-r5
+t0
 %22,  %22
-r6
+t1
 %22,  %22
-r7
+t2
 %22,%0A 
@@ -442,59 +442,59 @@
    %22
-r8
+fp
 %22,  
-%22r9
+ %22s1
 %22,  %22
-r1
+a
 0%22,
+ 
  %22
-r1
+a
 1%22, 
-%22r1
+ %22a
 2%22, 
-%22r1
+ %22a
 3%22, 
-%22r1
+ %22a
 4%22, 
-%22r1
+ %22a
 5%22,%0A
@@ -514,60 +514,60 @@
    %22
-r1
+a
 6%22, 
-%22r17%22, %22r18
+  %22a7%22,  %22s2
 %22,
+ 
  %22
-r19%22, %22r20%22, %22r21
+s3%22,  %22s4%22,  %22s5
 %22,
+ 
  %22
-r22%22, %22r23
+s6%22,  %22s7
 %22,%0A 
@@ -586,60 +586,60 @@
    %22
-r24%22, %22r25
+s8%22,   %22s9
 %22,
+ 
  %22
-r26
+s10
 %22, %22
-r27
+s11
 %22, %22
-r28%22, %22r29
+t3%22,  %22t4
 %22,
+ 
  %22
-r30%22, %22r31
+t5%22,  %22t6
 %22,%0A 

fix register name