Not to be funny homie, but u should try typing that same question in a google search engine or youtube. There's literally tons of info, videos, articles, websites etc that will give u what you're looking for, and for free.
It seems like u have a basic idea, but try doing a bit more research and take some notes. These internet and social media literally is a sea, even an ocean, of info.
The square machine u speak of is a drum machine. Some drum machines are standalone, and others are Midi based (meaning u have to plug it into a computer). Its all up to u. Good luck on your journey.