Thread: asm game

  1. #16
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    What you want to do is look at sites like osdever.net, which will teach you to code a primitive boot sector as well as a primitive kernel. From there, you will have direct access to the hardware, and, for example, the screen buffer.
    Which will lead you off on huge excursion into the weeds. You really don't want to try to program your own small OS, boot sector, or file system just to make a game in assembly. Booting into protected mode is not all that simple and requires that you set up the GDT, LDT, and IDT. I think you can forego the LDT but it's been so long I just don't know. Matsp would definitely be your source for this but I really feel that your 'game' idea will soon get swallowed by the enormous task of getting your own type of OS running.

  2. #17
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    bump

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Bubba View Post
    Which will lead you off on huge excursion into the weeds. You really don't want to try to program your own small OS, boot sector, or file system just to make a game in assembly. Booting into protected mode is not all that simple and requires that you set up the GDT, LDT, and IDT. I think you can forego the LDT but it's been so long I just don't know. Matsp would definitely be your source for this but I really feel that your 'game' idea will soon get swallowed by the enormous task of getting your own type of OS running.

    I completely agree, this is not the way to learn game programming assembler. For completeness, here is a brief explanation of what you must do:

    You MUST set up a minimal GDT (two entries, one Code Segment and one Data Segment - although if you want to make a "safer" OS, you may want to set up a user-mode variant of both code and data segment as well, and most OS's use some further segments for special purposes).

    You also MUST have an IDT. To begin with, you can get away with setting up the first 18 or so entries to point to a "fault handler" that prints a unique error message for each fault code, so that you can figure out what went wrong (and a lot of things can and will go wrong in the startup before you get it right, I promise). Later on, you will need to have interrupt vectors for any of the hardware you are using, and set up the interrupt controller (APIC or 8259) to match your vectors.

    You probably will want to set up a periodic timer, so that you can use some form of "delay/sleep" functionality.

    Once this is in place, you can get on with your actual code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    Jun 2008
    Posts
    127
    How about I ran my game on the linux kernel in kernel mode? Would linux then allow me to access the screen directly?

  5. #20
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Accessing the screen directly is a moot point. Modern APIs will allow you to do this but via methods which write to buffers rather than via a pointer to video memory.

  6. #21
    Registered User
    Join Date
    Jun 2008
    Posts
    127
    >>via a pointer to video memory
    ah thats how you access the screen directly.
    >>Modern APIs will allow you to do this but via methods which write to buffers
    What do you mean by buffer?

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by herWter View Post
    How about I ran my game on the linux kernel in kernel mode? Would linux then allow me to access the screen directly?
    Rather silly idea. First of all, you'd have to make darn sure that you lock everything down so that no other processor possibly accesses the screen memory - that would pretty much make Linux a single-tasking, single-user OS (and would be pretty difficult to ensure) - otherwise, some other process will write to the screen buffer, and all your graphics gets garbled.

    And as Bubba said, you give graphics commands to modern graphics processors through a buffer. Exactly how that works depends on the driver, but in general, you pass a list of graphics commands to the processor, and it takes those commands and performs them. There may be a single copy involved since executing graphics commands from the user-mode memory would allow the user-mode program to manipulate the graphics commands after they have been issued, which could lead to interesting race-conditions and possibly also security holes. But copying the commands for some drawing is still a whole lot less than copying each pixel and any other work involved with getting the pixels onto the screen (e.g. blending background with foreground pixels, etc).

    If you insist, you can still write nearly all of it in assembler - but it's hard work, and for most parts of the code, you will not see any difference in performance or code-size, since the compiler will do an adequate job.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #23
    Registered User
    Join Date
    Jun 2008
    Posts
    127
    If not accessing the screen directly, then how else would asm make graphical applications? I don't think I have ever seen a library written in assembly let alone for graphics. Is there like an SDL port for asm or something?

  9. #24
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    As long as you know HOW, assembler can call any other language's libraries. How else would a compiled C program work? The compiler generates machine code, which is the ultimate result of assembler too, so you should be able to push the right arguments on the stack in the right order, and perform a call. Depending on the calling convention for that particular library/language, you may need to clean up the stack after the call - or the calling function does it for you.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #25
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    If not accessing the screen directly, then how else would asm make graphical applications? I don't think I have ever seen a library written in assembly let alone for graphics. Is there like an SDL port for asm or something?
    There is a reason for that. It doesn't make sense. APIs are supposed to speed your development time not slow it down. No one today is making pure assembly graphics applications b/c it doesn't make sense to do so when you have Direct3D and OGL which are faster - yes faster - than assembly. The accelerator cards have the graphics rasterization, transformation, and other algos right on the chip. Assembly is super fast but assembly cannot beat hardware. Also modern APIs allow you to write shader programs that are small microcode programs that run on the GPU. You will never beat the performance of this architecture with any assembler. That is the reason no one is attempting to do so.

    Also based on your questions it appears you do not have a grasp of the fundamental relationships between assembler and compiled C/C++ code. This leads me to believe you probably do not have enough assembly experience to get this done.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  3. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM