Jump to content
  • Advertisement
Romee

Where to start making a game in assembly.

Recommended Posts

Hello everyone,

For learning purposes, I want to try to make a small graphical snake game in assembly. I've thought about where to start and which tools to use and personally I thought about using SDL and C to handle the keyboard input and the graphical output, but I would really like to know from other if there are better/easier ways to do this.

 

Thanks

Share this post


Link to post
Share on other sites
Advertisement

You want to make it in C or in Assembly?

Both are programming languages and, thought it is totally possible to write a game in assembly, is it recommendable? No. Not just because it takes a lot of work do get done, but maintainability is also difficult.

As for in C, you can do it. Lazy Foo has some very practical tutorials with SDL2.

32 minutes ago, Romee said:

but I would really like to know from other if there are better/easier ways to do this.

But, your problem here doesn't seems to be (only) language, but lack of understanding of game architecture. For that, I think this is a good read: http://gameprogrammingpatterns.com/contents.html. The topics State, Game Loop, Update Method and Object Pool are, in my opinion, the most useful to understand how to design a (good) game architecture (at least as a start point).

Share this post


Link to post
Share on other sites
Quote

You want to make it in C or in Assembly?

Both are programming languages and, thought it is totally possible to write a game in assembly, is it recommendable? No. Not just because it takes a lot of work do get done, but maintainability is also difficult.

As for in C, you can do it. Lazy Foo has some very practical tutorials with SDL2.

  1 hour ago, Romee said:

but I would really like to know from other if there are better/easier ways to do this.

But, your problem here doesn't seems to be (only) language, but lack of understanding of game architecture. For that, I think this is a good read: http://gameprogrammingpatterns.com/contents.html. The topics State, Game Loop, Update Method and Object Pool are, in my opinion, the most useful to understand how to design a (good) game architecture (at least as a start point).

First, thanks for the quick reaction. But excuse me for my bad explaination, to me it sounded pretty logical, but I think I was mistaken. Namely, this is my case:

I will be making the game using both Assembly and C. Assembly will be used as the main language of the game, i.e. all the gameplay logic (for example, incrementing position, incrementing scores, etc.) will be done in this language. But, as input handling and graphics drawing is slightly out of the scope of my goal for this small project, I will do that by writing the functions that do that in C, using a media library, like SDL. To call the functions I make in assembly, I use the call instruction. 

This way, I can divide the input handling, graphics drawing, etc. to C and the graphics library and the gameplay logic to assembly. But, my question still remains, is SDL a good option for this, or are there any better solutions.

Thanks by the way for the Game  Architecture link, a long time ago, I made a small game with C++ and SFML, but my knowledge was a bit rusty, so I will read that page without a doubt! :) 

Share this post


Link to post
Share on other sites

Why do you want to do a whole game in assembly?  You'll kill yourself over something that doesn't have much practical use.  Also if you don't plan on becoming an assembly expert the compiler will likely beat you.  If you want to get a feel for assembly from top to bottom try something non-graphical.

My suggestion is if you want to play with assembly try inline assembly in a C/C++ program.  You can also mess with intrinsics if you're interested in SIMD programming.  Inline assembly would be your best bet at getting a taste of assembly.  If you want to go further, your C++ compiler likely outputs assembly as well, so you can make small programs and examine the assembly output to see how the compiler handles it.

Share this post


Link to post
Share on other sites
1 hour ago, Romee said:

First, thanks for the quick reaction. But excuse me for my bad explaination, to me it sounded pretty logical, but I think I was mistaken. Namely, this is my case:

I will be making the game using both Assembly and C. Assembly will be used as the main language of the game, i.e. all the gameplay logic (for example, incrementing position, incrementing scores, etc.) will be done in this language. But, as input handling and graphics drawing is slightly out of the scope of my goal for this small project, I will do that by writing the functions that do that in C, using a media library, like SDL. To call the functions I make in assembly, I use the call instruction. 

This way, I can divide the input handling, graphics drawing, etc. to C and the graphics library and the gameplay logic to assembly. But, my question still remains, is SDL a good option for this, or are there any better solutions.

Thanks by the way for the Game  Architecture link, a long time ago, I made a small game with C++ and SFML, but my knowledge was a bit rusty, so I will read that page without a doubt!  

It's totally up to you, but I wouldn't advise making a game using Assembly if you're looking at being as productive as possible, and looking to reduce the amount of time spent debugging, as well as making future changes. Even using C would be a better option, but I would still not recommend using either for a new game developer.

I would suggest sticking to any language that supports more mainstream OOP concepts like C#, C++, or JAVA.

Are you looking to do this just as a hobby project to toy around with Assembly and C? You're going to be putting yourself through a lot of headaches using Assembly. If you're looking at making the program fun as fast as possible, it's not going to make enough of a difference to avoid other languages like C#, C++, or JAVA with today's machines.

I personally use C++ with SFML, and OpenGL when needed. I was never a fan of C with SDL, but that was way back when it was still version 1, not 2. I've heard good things about SDL 2, so it's worth a look if you're looking at sticking with C along side Assembly.

I wish you the best on this interesting journey.

Share this post


Link to post
Share on other sites

I would say there is merit in making such a simple game in Assembly for classic computers such as the C64, Amiga or ZX Spectrum.  The cpus and memory maps are much easier to learn - especially the 8-bit machines.

The communities for those machines also appreciate new projects.

Share this post


Link to post
Share on other sites

What you want to do is perfectly feasible.

If I understand your intention correctly you want to use the SDL to develop a C framework for your snake game to run in? Something like:

int main()
{
  init();
  
  while (!quit)
  {
    poll_input();	// Update input state
    update_game();	// Call your assembly entry point; assembly code updates the game state and renders to a bitmap
    present();		// Use SDL to display the bitmap
  }
  
  shutdown();
  
  return 0;
}

If that's your approach then it's a sensible way to limit just your game state and logic to being developed in assembly.

I'd recommend first just writing a single routine in assembler and working out how to assemble that and link it with an object file compiled from C, then work out the ABI so you know how to handle parameters and return values, and finally how to share data between the assembly and C parts. Once you have that plumbing in place you can iterate away on your game in assembly.

31 minutes ago, Anri said:

I would say there is merit in making such a simple game in Assembly for classic computers such as the C64, Amiga or ZX Spectrum.  The cpus and memory maps are much easier to learn - especially the 8-bit machines.

The communities for those machines also appreciate new projects.

I agree, I've done a couple of hobby games for the 8-bit Atari, it was the first computer I had and learned to program on and it's a lot of fun and very rewarding to develop for it using an adult's brain and modern dev tools.

Share this post


Link to post
Share on other sites

It is a great learning exercise, and I agree there is much value to it if this is something you want to learn.

11 hours ago, Romee said:

Assembly will be used as the main language of the game, i.e. all the gameplay logic (for example, incrementing position, incrementing scores, etc.) will be done in this language. But, as input handling and graphics drawing is slightly out of the scope of my goal for this small project, I will do that by writing the functions that do that in C, using a media library, like SDL. To call the functions I make in assembly, I use the call instruction. 

Fair enough.  Split it however you want.

12 hours ago, Romee said:

I would really like to know from other if there are better/easier ways to do this.

Sounds like you have a reasonable set of tools.  As you increase in skills you'll want better tools, but it doesn't take much to build what you described.

It has been a few years, but I made several similar projects back in my high school and college days using simple text editors and command-line compilers. It can still be done today.

 

The best question to ask now is:  What is stopping me now?

If nothing is stopping you now, then get to work!   If something is stopping you, identify that one thing and get it resolved. Then once it is resolved, get back to work.

 

So instead of asking if you have the best tools, let's turn it back on you.  What is stopping you from making progress on the project?  Why aren't you typing away at your solution right now?

Share this post


Link to post
Share on other sites
15 hours ago, Romee said:

Hello everyone,

For learning purposes, I want to try to make a small graphical snake game in assembly. I've thought about where to start and which tools to use and personally I thought about using SDL and C to handle the keyboard input and the graphical output, but I would really like to know from other if there are better/easier ways to do this.

Yes, libSDL2 and assembly are a good combination for game development.  I'd recommend using Linux because the traditional toolchain is slightly easier for assembly development (gas, ld, make, and gdb; simpler and more consistent calling conventions; plenty of Free libraries you can leverage) but you can bend your workflow to fit other tools if that's more your thing.

You'll want to stay away from mixing C++ or Objective-C libraries with assembly because of the complication of name mangling.  Other languages like Java, Rust, or the interpreted languages would be painful to use with assembly.

Good luck and enjoy the trip.

Share this post


Link to post
Share on other sites

  • Advertisement
  • Advertisement
  • Popular Tags

  • Similar Content

    • By MarcusAseth
      Hi guys, I'm having a problem rendering with DWrite, and I don't understand why, can you help me figure it out?
      As you can see in the image below, if you look carefully you'll notice that the top of R8 is cut (missing 1 row of pixels), the bottom of R11 is cut again, the 4 in R14 is rendered weird compared to the 4 in R4 and so on, if you look closely you'll spot more yourself.
      I can't figure out why 😕
      Under the image I'll also leave the code, in case I'm doing something wrong like with type conversion or stuff. Any help is much appreciated

      #include "GBAEmulator_PCH.h" #include "Disassembler.h" #include "GBAEmulator.h" Disassembler::Disassembler(LONG width, LONG height, HINSTANCE hInstance, GBAEmulator* emuInstance) : D2DWindowBase(width, height, hInstance, emuInstance), m_background(0.156f, 0.087f, 0.16f, 1.f), m_textFormat{ nullptr } { //Init Window std::string className = "Disassembler"; std::string windowName = "Disassembler"; WNDCLASSEX clientClass{}; clientClass.cbSize = sizeof(WNDCLASSEX); clientClass.style = CS_HREDRAW | CS_VREDRAW; clientClass.lpfnWndProc = GBAEmulator::DisassemblerWinProc; clientClass.hInstance = m_hInstance; //clientClass.hIcon =; TODO: Add Icon clientClass.hCursor = LoadCursor(m_hInstance, IDC_ARROW); clientClass.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1); clientClass.lpszClassName = className.c_str(); //clientClass.hIconSm =; TODO: Add Icon DWORD windowStyle = WS_VISIBLE | WS_CAPTION | WS_MINIMIZEBOX | WS_TABSTOP | WS_SYSMENU; m_isValid = InitWindow(windowName, clientClass, windowStyle, false); //Init DWrite if (m_isValid) m_isValid = InitDWrite(); std::vector<std::wstring> tempEntries{ L"PC: ", L"R0: ", L"R1: ", L"R2: ", L"R3: ", L"R4: ", L"R5: ", L"R6: ", L"R7: ", L"R8: ", L"R9: ", L"R10: ", L"R11: ", L"R12: ", L"R13: ", L"R14: ", L"R15: ", L"R16: " }; std::wstring value = L"-UNDEFINED-"; FLOAT left{}, top{}, right{ 300.f }, bottom{ 50.f }; for (auto& s : tempEntries) { m_entries.emplace_back(TextEntry{ s, value, D2D1_RECT_F{ left, top, right, bottom} }); top += 30.f; bottom += 30.f; } } bool Disassembler::InitDWrite() { //Set Text Format HRESULT hr; hr = m_DWriteFactory->CreateTextFormat( L"consolas", NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 22.f, L"en-US", &m_textFormat ); if (FAILED(hr)) { MessageBox(NULL, "Failed to create TextFormat", "Error", MB_OK); return false; } //Set Colors m_renderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::SkyBlue), &m_fillBrush1 ); m_renderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::Crimson), &m_fillBrush2 ); return true; } Disassembler::~Disassembler() { DestroyWindow(m_hwnd); if (m_textFormat) m_textFormat->Release(); if (m_fillBrush1) m_fillBrush1->Release(); if (m_fillBrush2) m_fillBrush2->Release(); } void Disassembler::Updade(float deltaTime) { } void Disassembler::Draw() { m_renderTarget->BeginDraw(); m_renderTarget->Clear(m_background); for (auto& entry : m_entries) { DrawEntryWithShadow(entry); } m_renderTarget->EndDraw(); } void Disassembler::DrawEntryWithShadow(const TextEntry& entry) { //shadow offset D2D1_RECT_F shadowPos = entry.position; shadowPos.top += 1.05f; shadowPos.left -= 0.95f; //draw text DrawEntry(entry.text, shadowPos, m_fillBrush2); DrawEntry(entry.text, entry.position, m_fillBrush1); D2D1_RECT_F valuePos = entry.position; FLOAT valueOffset = 50.f; valuePos.left += valueOffset; valuePos.right += valueOffset; shadowPos.left += valueOffset; shadowPos.right += valueOffset; //draw value DrawEntry(entry.value, shadowPos, m_fillBrush2); DrawEntry(entry.value, valuePos, m_fillBrush1); } void Disassembler::DrawEntry(const std::wstring& text, const D2D1_RECT_F& pos, ID2D1SolidColorBrush* brush) { m_renderTarget->DrawTextA( text.c_str(), static_cast<UINT>(text.size()), m_textFormat, pos, brush, D2D1_DRAW_TEXT_OPTIONS_NONE ); }  
    • By Catalin Danciu
      Hello,
      In the hopes that my thread is not off-topic or offensive in any way, I dare to ask the following "noob" question:
      what would be the correct way to create sprite animations from 2D *.bmp files?
      I have for reference the 2001 game  Desperados:Wanted Dead or Alive.
      with the help of some tools i found , I was able to extract files containing what seems to be animation frames and frame shadow masks for animating a horse.
      Attached are the archived assets.
      My goal is to recreate the demo level of the game using Unity, for educational purposes.
      I have started by loading the background map layer (also a large bmp file), and next step is to load a 2d character object and animate on the perspective.
       
      Horse_Brown.rar
    • By Alberto Muratore
      Hello, my name is Alberto Muratore and I'm a young game developer specialized in programming.

      Last summer I finished working on Abstract Arena, my first completed project published on Steam. During the development, lasted more than 1 year, I created every aspect of the game except for the audio sector. I previoulsy joined small competitions and had collaborations within the amateur scene, since I started having fun with game development when I was a kid. In the recent months I also started writing videogames reviews for a english-italian website about indie games.

      Abstract Arena Steam page: http://store.steampowered.com/app/678230/Abstract_Arena/
      Abstract Arena website: http://www.abstractarena.com/

          

      I'm currently offering my skills as freelancer in the role of programmer: what I'm searching for is a project that only lacks of the coding part. I'm very good at using the GameMaker: Studio engine, and I already own a license to export on Android platform. I can write code for any genre of 2D games, and I already have experience with the peculiarities of the Android platform (multiple touch controls, accelerometer). I will be able to start working full time only during September, so be aware of that.

      The plan is the following:
      1 - you have an idea about your next project (2D game of any kind, for Windows and/or Android platform),
      2 - you (or your team) create all of the graphics and audio resources,
      3 - I write the whole code for the game (gameplay, menus and anything within the game) putting everything togheter [during September],
      4 - if you like my work you can choose how much to pay for it, and you (or your team) keep the rights to sell the game without sharing any percentage with me.

      Thank you for reading my announcement
      If you have any question, please write me at the following address: albertomurat@gmail.com
    • By N Drew
      I am working on a 2D SideScroller game in my own made game engine using SFML and C++.I am searching for 2D artists,especially pixel artist for making and animating characters,backgrounds and other props that can be made in any Drawing Program.The artist will become part of the team of Hammer Studios and he got a part of the Revenue Sharing.If you are interested send me a mail at:ghiurcutaandrei@gmail.com .If you are not an artist but you want to be a part of our Team,Soon we will be recruiting an C++ AI programmers that worked in SFML/OpenGL.
      We work together using Discord.

    • By JoAndRoPo
      While going through a Game Design Document Template, I came across this heading - Core Game Loop & Core Mechanics Loop. 
      What's the difference? Can you provide some examples of an existing game?  Suppose if I am including these topics in a Game Design Document, how should I explain it so that my team can understand? 
    • By Ds ds
      Hi, my name is Andres, I'm a programmer with a technician degree and a Diploma in C#, looking for a project in Unity to start my career in game development. I don't do it for a paid but a recognition and start a portfolio, preferably a 2D game. Thanks for read, have a nice day. 
       
    • By Doommy
      If someone could assist me through this I would be really grateful. I'm using SharpDX/C#/WinForms but I think this could more apply to directx in general.
      I'm very new to graphics programming and I'm really just trying to do something as simple as displaying a rectangle to the screen.
      Here is my issue:
      I have the below code:
      ----------------------------------------------------------
       var desc = new SwapChainDescription()
                  {
                      BufferCount         = 1,
                      ModeDescription     = new ModeDescription(1024, 768, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                      IsWindowed          = false,
                      OutputHandle        = form.Handle,
                      SampleDescription   = new SampleDescription(1, 0),
                      SwapEffect          = SwapEffect.Discard,
                      Usage               = Usage.RenderTargetOutput
                  };
      I'm not sure if the window is loading in full screen. Actually to make it go full screen I actually have to set the forms property to: this.WindowState        = FormWindowState.Maximized; but that only seems lke Im using a C# code to maximize the form. For instance if I don't set the form to maximize, the form loads at the original size if IsWindowed is set to false. I recall with directx programing using dx7, when I set full screen you could actually see what looked like a display resolution change. I'm not seeing that. It pretty much looks like the form is loaded at the same size as the screen and not the value I provide in modeDescription. This is not what I want as well because I want to set the display to 1024x768 to avoid stretching of my graphics in wide screens.
      Can someone help me make sense of this please.
    • By HomeBrewArcana
      Hey All,
      I'm looking to get into the gaming industry. I've skirted around the idea for a long time, always thinking that I couldn't do it. I've finally decided to take the plunge.
       
      My question is whether it's worth going to school for game design/coding etc. I've been writing content for paper games for a while, and have a good idea of story and some basic design. But I have next to no technical know how. 
       
      My instinct is that such things can be learned with a lot of practice, video tutorials, and more practice. I've also heard that a degree is not really that important, since you get hired based on your portfolio/prototypes. Why not just make the games?
      But won't a degree help with contacts and mentoring--I'm not a great networker.
       
      Of course, it'll plunge me into more debt, but...
      If anyone has advice, let me know. Also any idea of a program to start with: Game Maker, Unity, Godot, Construct, Stencyl--I've heard good things about them all, so much so that I don't know which would be best to start with!
       
      Thanks
    • By bartekm777
      Hello
      About me
      Lvl 28   Programmer (day job: non-gamedev-programmer, making games as a hobby for about 2 years) Some vector art experience - tried to make some assets on my own using vector software and scripts   Some design experience (designing my own games ) About game
      Turn-based fantasy rpg inspired by games like Heroes 3 (also WoG mod), NEO Scavenger, Battle Brothers I would like to create easy to use editor for creating custom scenarios (similar to the one from Heroes 3) World and story are clean slate, I did some drafts but I'm not good at it so it's possibly subject to change I decided to create graphics using vector software + scripts to make it faster (rpg's tend to have lots of assets), also it's more precise and easier to create tileable graphics (for example: rivers, paths) No sound/music work has been done yet Who do I look for?
      Definitely someone with 2d art skills  I would like to focus more on programming 2D animator (skletal animations are preferred) Additional programmer could make development faster Someone for creating sounds/music/both It's a hobby project, I work on it in my free time. In case the project make it to the finish line and get shipped  - I can offer rev-share  
      Below should be few screens of what I already did (about 2 months of work) - some graphics, editor prototype screenshot and game prototype screenshot




  • Advertisement
  • Popular Now

  • Forum Statistics

    • Total Topics
      631373
    • Total Posts
      2999639
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!