Best way to go about writing an emulator?

Best way to go about writing an emulator?

So the next step in my journey of developing the RX-GP16 ISA is writing an x86 based emulator and assembler for it. I have a few ideas for how to do the CPU emulation with virtual registers in memory and having every opcode act as a function pointer to a routine for manipulating that data in ways the ISA describes.

But before I write garbage and burn myself out, I wish to ask some of you more experienced folk how you'd do it. Of course, I dont want to eliminate my critical thinking and innovation but wiser oversight could be of great assistance.

Thank you for all answers in advance!

u/Brutustheman — 7 days ago

The RX-GP16V1P1 ISA documentation

More progress has been made! "Proper" documentation of the instructions has just been uploaded to github, along with the repository being created. This documentation also features some updates on the instructions that my last post got.

Link to the documentation inside the repo

Link to the project repo

Thank you all for your suggestions and feedback! Also as a tangent, I do plan on adding Bus in and Bus out instructions to allow for data flow in and out of the cpu, but I felt that documenting the pre-existing instructions was a better first step. Also, sorry for the poor writing quality and possibly bad formatting, I wrote it all in KATE in a few hours. Enjoy and please do give feedback!

u/Brutustheman — 9 days ago

Lmms fuckery [RANT]

So I've been wanting to get into music making. Problem, I'm not on windows nor paying $$$ for FL studio. Lmms should basically be the same, right? Wrong. Five total hours of trying to get VST working since a lot of soundfonts are unusable without one. /usr/lib/lmms/RemoteVstPlugin not found? Try to sudo cp the VST into the directory. Full absolute filepath of the exe is not a valid target and Lmms in it's infinite wisdom only does some very specific checks and will miss anything that isn't an EXE or DLL. TLDR music software on linux sucks balls. And microphone support for some reason. I want to fight my lack of skill and creativity in the software, not intimately assault my root directory when trying to wrestle the software into atleast half working.

I really need to calm my shit and give up lol

reddit.com
u/Brutustheman — 13 days ago

Custom 16 bit ISA : Revision 1 complete

So a while back I made a post here asking if my instructions then were good. I got some very good suggestions and did some more reading, and today got the simulated hardware fully functional. So, here is the finalized first revision instruction set. Also, first program suggestions are welcome

[settings]
name="RX-GP16-ASM"
variant="REVISION 1"

[fields]

register
r0 000 ; general purpose
r1 001 ; general purpose
r2 010 ; general purpose
r3 011 ; general purpose
r4 100 ; general purpose
rta 101; CALL / ret subroutine return adress. Also viable as GP with programmer oversight
sp 110 ; Stack pointer. 8 bits wide
pc 111 ; Program counter

[instructions]

; BASE INSTRUCTIONS

imm %a(register), %b:U6(immediate)
0000000 aaabbbbbb
# Loads a value into register %a

cpy %a(register), %b(register)
0100000 aaabbb000
# Copies to reg %a from reg %b

stor %b(register), %c(register)
0100001 000bbbccc
# Moves data at register %c to RAM at adress stored in register %b

ldr %a(register), %b(register)
0100010 aaabbb000
# Load data to register %a from ram at adress %b

ovr %c(register)
0100011 000110ccc
# Overwrites highest stack value without push/pop
// Also used in push

strd %a(register)
0100100 aaa110000
# Reads highest stack data without push/pop
// Also used in pop

push %c(register)
0100011 000110ccc 1101100 110110001
# Push value in register %c to the stack
; Increments sp register and does a stack-specific stor
; Takes two cycles but easier to implement

pop %a(register)
0100100 aaa110000 1101111 110110001
# Pop stack value and store in register %a
; Decrements sp by 2 to backtrack before ldr

call %a(register), %b(register)
1101100 110110010 0100011 000110bbb 1000000 aaa000000
# Push return adress at %b onto the stack and jmp to %a
; 3 cycle instruction

ret
0100100 101110000 1101111 110110010 1000000 101000000
# Pop stack value to rta and jmp back
; Does ldr into rta, pops, and jumps

nop
0111111 000000000
# Skip cycle. Wired to any mode/opcode combo that does nothing. Currently mem mode opcode b11111

HLT
0100101 000000000
# Disables PC aka kills the computer

; JUMP INSTRUCTIONS

jmp %a(register)
1000000 aaa000000
# Jumps to ROM adress at %a

jmpls %a(register), %b(register), %c(register)
1000001 aaabbbccc
# Jump to ROM adress at reg %a if reg %b is less than reg %c

jmpgt %a(register), %b(register), %c(register)
1000010 aaabbbccc
# Jump to ROM adress at reg %a if reg %b is more than reg %c

jmpeq %a(register), %b(register), %c(register)
1000011 aaabbbccc
# Jump to ROM adress at reg %a if reg %b is same reg %a

jmpne %a(register), %b(register), %c(register)
1000100 aaabbbccc
# Jump to ROM adress at %a if %b!=%c

; ARITHMETIC INSTRUCTIONS

or %a(register), %b(register), %c(register)
1100000 aaabbbccc
# OR register %b and %c, store in %a

nor %a(register), %b(register), %c(register)
1100001 aaabbbccc
# NOR register %b with register %c, store in %a

not %a(register), %b(register)
1100010 aaabbb000
# NOT register %b, store in %a

and %a(register), %b(register), %c(register)
1100011 aaabbbccc
# AND register %b with %c, store in %a

nand %a(register), %b(register), %c(register)
1100100 aaabbbccc
# NAND register %b with register %c, store in %a

xor %a(register), %b(register), %c(register)
1100101 aaabbbccc
# XOR register %a with register %b, store in %c

xnor %a(register), %b(register), %c(register)
1100110 aaabbbccc
# XNOR register %b with register %c, store in %a

add %a(register), %b(register), %c(register)
1100111 aaabbbccc
# Add register %b and register %c, store in %a

sub %a(register), %b(register), %c(register)
1101000 aaabbbccc
# Subtract register %b and register %c, store in %a

mul %a(register), %b(register), %c(register)
1101001 aaabbbccc
# Multiply register %b with register %c and store in %a

div %a(register), %b(register), %c(register)
1101010 aaabbbccc
# Divide register %b with register %c and store in %a

mod %a(register), %b(register), %c(register)
1101011 aaabbbccc
# Modulo divide register %b with register %c and store in %a

inc %a(register), %b(register), %c:U3(immediate)
1101100 aaabbbccc
# Increment register %b by %c, store in %a

dec %a(register), %b(register), %c:U3(immediate)
1101101 aaabbbccc
# Decrement register %b by %c, store in %a

sr %a(register), %b(register), %c:U3(immediate)
1101111 aaabbbccc
# Shift %b right by %c and store in %a

asr %a(register), %b(register), %c:U3(immediate)
1101111 aaabbbccc
# Signed shift %b right by %c and store in %a

sl %a(register), %b(register), %c:U3(immediate)
1110000 aaabbbccc
# Shift %b left by %c and store in %a

rcm %a(register), %b(register)
1110001 aaabbb000
# Unsigned-signed recast register %b, store in %a. Preserves absolute value

rcz %a(register), %b(register)
1110010 aaabbb000
# Unsigned-signed recast register%b, store in %a. Clamps negative numbers / numbers above 128 to 0
reddit.com
u/Brutustheman — 18 days ago

Very simple 16 bit CPU design I made for fun in a video game

First off, I'm not sure if I'm allowed to post this here, but if it is not allowed please let me know before deleting the post. I wish to learn the rules better.

Anyways, over the few last weeks I've been making a custom 16 bit cpu inside a video game called turing complete. Picture included down below

The CPU in all of it's janky glory

One small note, the game doesnt simulate clock signals in the traditional sense, instead having "cycles" and no need to worry about memory timings. The game also does not allow the simulated logic to change the clockspeed. Still, even with all of this simplification, I am quite proud of making this all by myself.

SPECS:
  REGISTERS:
    GP1
    GP2
    GP3
    GP4
    RTA / GP5
    SP
    PC
  MEMORY:
    256 word sram stack, included inside the chip
    ROM upto 0xFFFF words
    RAM upto 0xFFFF words
  BUS:
    Currently no USB
    4 in-cpu buses
      BUS A : Register data in
      BUS B : Source 1 data out
      BUS C : Source 2 data out
      JMPBS : Bus for jump operand input
EXTRA : 
  Most operations are very flexible, having free sources and a free destination
  Exception to this is the PC register, which is not connected to BUS A
  And thus cannot be written into by normal operations
  RTA / GP5 is used unconditionally for the return adress in RET
  But otherwise is a valid gp register, with the knowledge of data insecurity
reddit.com
u/Brutustheman — 18 days ago

Custom cpu architecture - showcasing some components

Recently I've been having some great fun making my own custom ISA and matching cpu architecture. Having the whole thing as a single schematic was kinda annoying, so I made them as individual parts (and also tried making the wiring a little cleaner). Here are some pictures; comment, critique and enjoy!

Original spaghetti

Instruction decoder

Jump-condition unit

The ALU

The registers. I really like this one aesthetically

reddit.com
u/Brutustheman — 19 days ago

FF7R2 - Midgar zolom rant

OK first of all, what a god awful bossfight. I've had more fun taking a constipated shit. This should be the first real boss in the game after the tutorial, it should not be this fucking hard. Some attacks are almost unavoidable (like the rising attack it does after going under the water) since Cloud has that ds1 fatroll as a fucking dodge. Second of all, why the hell does it need fromsoft level parry timing edging and so much hp. And the damage. good lord. I dont have enough mp nor get enough ATB to fully recover from it's attacks. Ofc, this is probably a beginner issue on my part, and the general balancing just being an issue with the whole FF7R combat, but good lord that was horrible. And the suprise Sephiroth at the end certainly didn't tickle my pickle either. As a disclaimer, I dont necessarily hate FF7R2's combat system, I just wished it did some things closer to FF7R1 (while some things, like perfect parries, FF7R2 does better)

PS. How many downvotes you folk think this is going to get lol

reddit.com
u/Brutustheman — 22 days ago

Custom Instruction set, how practical are the current instructions

Playing Turing complete (hardware design simulator) and got to making my own CPU and ISA. wanted to refine my ISA before making any of my instruction decode logic. [PLS ignore bytecodes] My current instructions are:

register
r0 000 ; general purpose
r1 001 ; general purpose
r2 010 ; general purpose
r3 011 ; general purpose
r4 100 ; general purpose
r5 101 ; general purpose
rta 110 ; CALL / RET subroutine return adress
sp 111 ; stack pointer

; BASE INSTRUCTIONS

imm %a(register), %b:U9(immediate)
000000 aaabbbbbbb
# Loads a value into register

cpy %a(register), %b(register)
0100000 aaabbb000
# Copies to reg %a from reg %b

stor %a(register), %b(register)
0100001 aaabbb000
# Moves data at register %a to RAM at adress stored in register %b

ldr %a(register), %b(register)
0100010 aaabbb000
# Load data to register %a from ram at adress %b

push %a(register)
1001011 111000010 0100001 aaa111000
# Push value in register %a to the stack
; Increments sp register and ldr
; Takes two cycles but easier to implement

pop %a(register)
0100010 aaa111000 1001100 111000010 
# Pop stack value and store in register %a
; Decrements sp by 2 to backtrack after doing ldr

call %a(register)
1001011 111000010 0100010 aaa111000 1000000 aaa000000
# Push return adress at %a onto the stack and jmp to %a
; 3 cycle instruction

ret
0100010 110111000 1001100 111000010 1000000 110000000
# Pop stack value to rta and jmp back
; Does ldr into rta, pops, and jumps

nop
0000001 000000000
# Skip cycle

; JUMP INSTRUCTIONS

jmp %a(register)
1000000 aaa000000
# Jumps to ROM adress at %a

jmpls %a(register), %b(register), %c(register)
1000001 aaabbbccc
# Jump to ROM adress at reg %c if reg %a is less than reg %b

jmplss %a(register), %b(register), %c(register)
1000010 aaabbbccc
# Jump to ROM adress at reg %c if reg %a is less than reg %b. Both compared regs signed

jmgt %a(register), %b(register), %c(register)
1000011 aaabbbccc
# Jump to ROM adress at reg %c if reg %a is more than reg %b

jmpgts %a(register), %b(register), %c(register)
1000100 aaabbbccc
# Jump to ROM adress at reg %c if reg %a is more than reg %b. Both compared signed

jmpeq %a(register), %b(register), %c(register)
1000101 aaabbbccc
# Jump to ROM adress at reg %c if reg %a is same reg %b

jmpne %a(register), %b(register), %c(register)
1000110 aaabbbccc
# Jump to ROM adress at %c if %a!=%b

; ARITHMETIC INSTRUCTIONS

or %a(register), %b(register), %c(register)
1000000 aaabbbccc
# OR register %a and %b, store in %c

and %a(register), %b(register), %c(register)
1000001 aaabbbccc
# AND register %a with register %b, store in %c

not %a(register), %b(register)
1000010 aaabbb000
# NOT register %a, store in %b

nand %a(register), %b(register), %c(register)
1000011 aaabbbccc
# NAND register %a with register %b, store in %c

xor %a(register), %b(register), %c(register)
1000100 aaabbbccc
# XOR register %a with register %b, store in %c

xnor %a(register), %b(register), %c(register)
1000101 aaabbbccc
# XNOR register %a with register %b, store in %c

add %a(register), %b(register), %c(register)
1000110 aaabbbccc
# Add register %a and register %b, store in %c

sub %a(register), %b(register), %c(register)
1000111 aaabbbccc
# Subtract register %a and register %b, store in %c

mul %a(register), %b(register), %c(register)
1001000 aaabbbccc
# Multiply register %a with register %b and store in %c

div %a(register), %b(register), %c(register)
1001001 aaabbbccc
# Divide register %a with register %b and store in %c

mod %a(register), %b(register), %c(register)
1001010 aaabbbccc
# Modulo divide register %a with register %b and store in %c

inc %a(register), %b:U6(immediate)
1001011 aaabbbbbb
# Increment register %a by %b

dec %a(register), %b:U6(immediate)
1001100 aaabbbbbb
# Decrement register %a by %b

sr %a(register), %b(register), %c:U3(immediate)
1001101 aaabbbccc
# Shift %a right by %c and store in %b

asr %a(register), %b(register), %c:U3(immediate)
1001110 aaabbbccc
# Signed shift %a right by %c and store in %b.

sl %a(register), %b(register), %c:U3(immediate)
1001111 aaabbbccc
# Shift %a left by %c and store in %b

Updated instruction set draft. Thank you folk so much for the knowledge you have given thus far!

reddit.com
u/Brutustheman — 26 days ago

My dad is a fucking asshole [RANT + SWEARING]

The first thing he did today when I saw him? Shouted at me for not answering one of his text messages (one message immediately after threatened to not get me food...I'm 17).

All he does is barge into my room to ruin my fun, bother me, or shout at me for something trivial. One day he says that I'm an adult and can make my own choises as he has no control over me, the next he will threaten to take your bicycle away because you dont lock it (ah yes, as if only locking the fucking wheel is going to deter anyone capable of lifting 30lbs). He wont take critisism/negative comments about him (such as, "please take a shower" or "dont get shitfaced today pls") and never wants to be the one in the wrong.

His huge fucking victim complex leads him to blame everyone but himself (such as when he himself ran his car battery dry, and blamed my grandparents who let him use the car for only gas money, and then blamed me for taking "his spare bike" that his morbidly obese self can't even fucking ride, and has not ridden in several years).

I'm slowly going crazy and relapsing in several of my bad habits because this shit genuinely gets on my mental health a lot and I cant even do anything.

I can't even properly convey how infuriating it is to deal with him because he has the intelligence of an LLM hallucinating and making shit up with confidence. No dad, there is no goddamn dark side to programming, that's called a crime here. Especially when he gets drunk, his reality is the defacto truth just because him accepting being wrong is genuinely rare like a millionare shitting a diamond on your hand.

Not to mention the comments. Young girls, older women, anyone good looking enough, gets a perverted comment from him. His phone BG is ai generated porn, just straihgt porn, and that side of his does bleed into real life and it's fucking terrible.

Every time he comes home or leaves his room me and my sister genuinely scatter like fucking bugs because us whispering and laughing quietly = fucking, apparently.

Good lord sometimes I wish I was born with chill parents who actually had stable relationships and didn't have a shitty, narcissistic and controlling personality.

Sorry I subjected you to this complaint rant thing and my horrible use of all letters A-Z.

reddit.com
u/Brutustheman — 29 days ago
▲ 1 r/wacom

Wacom Intuos / One Pen tablet?

So I've been thinking about getting a pen tablet for digital art and texturing (texturing is hell with a mouse) and wanted to ask about your experiences and / or opinions. The (real) price difference in my region between the Intuos M and One S models is around 10€ (One S is around 18€ more than Intuos S because One [size] needs everything specced out individually). I know that Linux supports their hardware quite well so that isn't an issue, but I'd like to ask for experiences regarding feel, user input, physical size, and other possible alternatives. Any and all answers are appreciated!

Originally asked in r/pcgaming but I found out this community is probably better lol

reddit.com
u/Brutustheman — 2 months ago

Are there any ways to optimize this code in any meaningful capacity?

So I'm working on a game engine (stupid, I know, but I enjoy pain) and came to the trouble of realizing that for openGL it'd be good of me to make a VertexArrayObject for each different material. This brought me to try to make some sort of parser for my vertex and UV data to sort them neatly in (3 vertex, 3 UV coordinate, repeat) formation. This code block would need to run once every frame, once for every unique material (several objects can use same VAO as long as textures are the same). Sorry for yapping, here be the code I wrote

#include <vector>
#include <iostream>
#include <string>

//NOTE : in actuality these are of float type, but current content is for readability
std::vector<std::string> VertexThing = {"VERTEX1", "VERTEX2", "VERTEX3", "VERTEX4", "VERTEX5", "VERTEX6", "VERTEX7", "VERTEX8", "VERTEX9"};
std::vector<std::string> TextureUV = {"TEXTURE1", "TEXTURE2", "TEXTURE3", "TEXTURE4", "TEXTURE5", "TEXTURE6", "TEXTURE7", "TEXTURE8", "TEXTURE9"};

std::vector<std::string> FinalBuffer;

int VertexBufferIndex = 0;
int TextureUVIndex = 0;
int FinalBufferIndex = 0;
int OnIteration = 0;

void SortVectors(std::vector<std::string> VertexThing, std::vector<std::string> TextureUV){
    if (VertexThing.size() != TextureUV.size()){
        std::cerr << "[CRITICAL ERROR] : VERTEX AND TEXTURE COORDINATE AMOUNTS DIFFER";
        //call std::exit, here omitted due to lazy
    }
    //NOTE : Error checking earlier ensures that vertex- and texture buffers have same amount of indexes
    while (OnIteration < VertexThing.size()){
        for (VertexBufferIndex = VertexBufferIndex; VertexBufferIndex < OnIteration +3; VertexBufferIndex++){
            FinalBuffer.push_back(VertexThing[VertexBufferIndex]);
        }
        for (TextureUVIndex = TextureUVIndex; TextureUVIndex < OnIteration + 3; TextureUVIndex++){
            FinalBuffer.push_back(TextureUV[TextureUVIndex]);
        }
        OnIteration += 3;
    }
    //omitted in actual code used for my project, just for debug and visualization purposes
    for (FinalBufferIndex = 0; FinalBufferIndex < FinalBuffer.size(); FinalBufferIndex ++){
        std::cout << FinalBuffer[FinalBufferIndex] << "\n";
    }
};
reddit.com
u/Brutustheman — 2 months ago

Good wired mechanical keyboard suggestions?

My current corsair keyboard is starting to have battery failure, so I've been thinking about getting a wired one. I wanted to ask for any suggestions for good 104-key mechanical keyboards. Ideally metal framed, but can also be plastic. Ideally less than 100€ but not an absolute limit. Any suggestions are appreciated!

reddit.com
u/Brutustheman — 2 months ago
▲ 1 r/Minecraft+1 crossposts

Epsilon runtime extreme instability issue

Today I encountered an issue where minecraft will randomly crash in the middle of playing, and refuse to boot up afterwards without a reboot of the whole pc. The error reported was something along the lines of "minecraft epsilon runtime has failed critically and shut down"

For context I do have mods (sodium + iris + cloth config + fabric api + renderscale) aswell as a 6gig RAM allocate, but I do not believe this to be the determinant factor of instability. I'm also on linux, but mc has worked fine before (and still does on my old pc also running the same mods). I'm on the latest AMD drivers aswell.

Any help troubleshooting / figuring out a workaround will be greatly appreciated!

EDIT (s):

Game version is 26.1.2 Kernel version is 7.0.3

reddit.com
u/Brutustheman — 3 months ago