<commit_before>package com.rox.emu.p6502.dbg.ui.component;

import com.rox.emu.p6502.Registers;

import javax.swing.*;
import java.awt.*;

/**
 * A UI component intended to display 6502 registers and their state
 */
public class RegisterPanel extends JPanel {
    private Registers registers;

    private final int bitSize = 40;
    private final int byteSize = (bitSize*8);
    private final int padding = 10;
    private final int bitFontSize = 40;
    private final int valueFontSize = 11;

    @Override
    public void paint(Graphics g) {
        super.paint(g);

        setPreferredSize(new Dimension(1200,0));
        setMinimumSize(new Dimension(1200,0));

        if (g instanceof Graphics2D){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        }

        if (registers != null)
            drawRegisters(g, 20, 20);
    }

    private void drawRegisters(Graphics g, int x, int y) {
        int yLocation = y;
        int xLocation = x;
        int rowSize = padding + bitSize;
        int secondByteColumn = byteSize + xLocation + padding;

        drawByte(g, secondByteColumn, yLocation, registers.getRegister(Registers.REG_ACCUMULATOR), Registers.getRegisterName(Registers.REG_ACCUMULATOR));

        yLocation += rowSize;
        drawByte(g, secondByteColumn, yLocation, registers.getRegister(Registers.REG_Y_INDEX), Registers.getRegisterName(Registers.REG_Y_INDEX));

        yLocation += rowSize;
        drawByte(g, secondByteColumn, yLocation, registers.getRegister(Registers.REG_X_INDEX), Registers.getRegisterName(Registers.REG_X_INDEX));

        //TODO this needs a combined value display
        yLocation += rowSize;
        drawByte(g, xLocation, yLocation, registers.getRegister(Registers.REG_PC_HIGH), Registers.getRegisterName(Registers.REG_PC_HIGH));
        drawByte(g, secondByteColumn, yLocation, registers.getRegister(Registers.REG_PC_LOW), Registers.getRegisterName(Registers.REG_PC_LOW));

        yLocation += rowSize;
        g.setColor(Color.lightGray);
        g.fillRect(secondByteColumn + (2 * bitSize), yLocation, bitSize, bitSize);
        drawFlags(g, secondByteColumn, yLocation, registers.getRegister(Registers.REG_STATUS), "NV BDIZC".toCharArray());
    }

    private void drawFlags(Graphics g, int startX, int startY, int byteValue, char[] values){
        char[] bitValues = to8BitString(byteValue).toCharArray();

        g.setColor(Color.lightGray);
        for (int i=0; i<8; i++){
            g.setColor((bitValues[i] == '1') ? Color.black : Color.lightGray);
            drawBit(g, startX + (i*bitSize), startY, values[i]);
        }
        g.setColor(Color.BLACK);
        g.drawRect(startX, startY, byteSize, bitSize);
    }

    private void drawByte(Graphics g, int startX, int startY, int byteValue, String name){
        char[] bitValues = to8BitString(byteValue).toCharArray();

        g.setColor(Color.lightGray);
        for (int i=0; i<8; i++){
            drawBit(g, startX + (i*bitSize), startY, bitValues[i]);
        }
        g.setColor(Color.BLACK);
        g.drawRect(startX, startY, byteSize, bitSize);

        g.setColor(Color.RED);

        g.setFont(new Font("Courier New", Font.PLAIN, valueFontSize));
        String values = "(" + fromSignedByte(byteValue) + ", 0x" + Integer.toHexString(byteValue) + ")";
        g.drawString(values, (startX+byteSize-bitSize), startY-1);<commit_msg>Moving register values to be inside the register byte horizontal limits<commit_after>package com.rox.emu.p6502.dbg.ui.component;

import com.rox.emu.p6502.Registers;

import javax.swing.*;
import java.awt.*;

/**
 * A UI component intended to display 6502 registers and their state
 */
public class RegisterPanel extends JPanel {
    private Registers registers;

    private final int bitSize = 40;
    private final int byteSize = (bitSize*8);
    private final int padding = 10;
    private final int bitFontSize = 40;
    private final int valueFontSize = 11;

    @Override
    public void paint(Graphics g) {
        super.paint(g);

        setPreferredSize(new Dimension(1200,0));
        setMinimumSize(new Dimension(1200,0));

        if (g instanceof Graphics2D){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        }

        if (registers != null)
            drawRegisters(g, 20, 20);
    }

    private void drawRegisters(Graphics g, int x, int y) {
        int yLocation = y;
        int xLocation = x;
        int rowSize = padding + bitSize;
        int secondByteColumn = byteSize + xLocation + padding;

        drawByte(g, secondByteColumn, yLocation, registers.getRegister(Registers.REG_ACCUMULATOR), Registers.getRegisterName(Registers.REG_ACCUMULATOR));

        yLocation += rowSize;
        drawByte(g, secondByteColumn, yLocation, registers.getRegister(Registers.REG_Y_INDEX), Registers.getRegisterName(Registers.REG_Y_INDEX));

        yLocation += rowSize;
        drawByte(g, secondByteColumn, yLocation, registers.getRegister(Registers.REG_X_INDEX), Registers.getRegisterName(Registers.REG_X_INDEX));

        //TODO this needs a combined value display
        yLocation += rowSize;
        drawByte(g, xLocation, yLocation, registers.getRegister(Registers.REG_PC_HIGH), Registers.getRegisterName(Registers.REG_PC_HIGH));
        drawByte(g, secondByteColumn, yLocation, registers.getRegister(Registers.REG_PC_LOW), Registers.getRegisterName(Registers.REG_PC_LOW));

        yLocation += rowSize;
        g.setColor(Color.lightGray);
        g.fillRect(secondByteColumn + (2 * bitSize), yLocation, bitSize, bitSize);
        drawFlags(g, secondByteColumn, yLocation, registers.getRegister(Registers.REG_STATUS), "NV BDIZC".toCharArray());
    }

    private void drawFlags(Graphics g, int startX, int startY, int byteValue, char[] values){
        char[] bitValues = to8BitString(byteValue).toCharArray();

        g.setColor(Color.lightGray);
        for (int i=0; i<8; i++){
            g.setColor((bitValues[i] == '1') ? Color.black : Color.lightGray);
            drawBit(g, startX + (i*bitSize), startY, values[i]);
        }
        g.setColor(Color.BLACK);
        g.drawRect(startX, startY, byteSize, bitSize);
    }

    private void drawByte(Graphics g, int startX, int startY, int byteValue, String name){
        char[] bitValues = to8BitString(byteValue).toCharArray();

        g.setColor(Color.lightGray);
        for (int i=0; i<8; i++){
            drawBit(g, startX + (i*bitSize), startY, bitValues[i]);
        }
        g.setColor(Color.BLACK);
        g.drawRect(startX, startY, byteSize, bitSize);

        g.setColor(Color.RED);

        g.setFont(new Font("Courier New", Font.PLAIN, valueFontSize));
        String values = "(" + fromSignedByte(byteValue) + ", 0x" + Integer.toHexString(byteValue) + ")";
        g.drawString(values, (startX + byteSize - bitSize - (values.length() * (valueFontSize/2))), startY-1);
{'fraction_non_alphanumeric': 0.11554800339847068, 'fraction_numerical': 0.014301897479467572, 'mean_word_length': 3.2910085054678007, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1116287', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2172, 'n_words': 479}