Another question

This is a discussion on Another question within the Game Programming forums, part of the General Programming Boards category; I want to write this game I've been blabbering on about, without using a commercial API. Thus I need to ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Another question

    I want to write this game I've been blabbering on about, without using a commercial API. Thus I need to know something. I know you can't call hardware interrupt directly (i.e. by using inline assembly) if compiling to a 32bit .exe, so I was going to use turbo pascal.

    I just wanted to know what my options are as far as writing what will essentially be an engine from scratch.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    I think you're going the wrong way about this. Hardware interrupts are outdated and only used for backwards compatibility. You have to use an API such as OpenGL or DirectX because they guarantee you that they will work on a variety of hardware. Most graphics hardware only supports OpenGL and DirectX. So in order to write an engine from scratch I recommend you buy an OpenGL book and learn it. If you write it using Hardware interrupts I assume you will end up with a Software engine which will be much slower than the equivilent opengl based implementation because it will be unable to take advantage of the hardware layers. If that is what you want you are better off using GDI or SDL which are also APIs.

    GDI is the lowest level Windows API you will find for 2d graphics but it does not use hardware. SDL is a higher-level cross-platform API which allows for both 2d and 3d graphics and is capable of using OpenGL for hardware interaction.

    But if you want to write an outdated DOS graphics program, it's really up to you.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I never really looked at it like that. I guess I should take the OpenGL route with a book then.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Well I've done it just out of interest; I've started writing an engine from scratch using nothing but Turbo Pascal 7 and assembly where required. It'll just be a toy engine for now and possibly never used for a game.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  5. #5
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Sounds like you want to get really low level with this, which isn't a bad thing. OpenGL is definitely the way to go if you want to get away from Pascal (which you eventually will, trust me). OpenGL is a pretty low level API. In fact, most of the functions are set up so that it's like you're using the video cards instruction set. Then you can eventually get into Shader assembly, which is pretty neat.

  6. #6
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Yeah I didn't really want to do it in Pascal, it just has easy access to int's and since I don't 'know' assembly...
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  7. #7
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    it just has easy access to int's
    I'm unaware of a language that makes it difficult to handle numbers. Perhaps I don't understand what you mean by that?

  8. #8
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    Maybe I'm wrong, but he probably means interrupts (as in hardware interrupts).
    Programming Your Mom. http://www.dandongs.com/

  9. #9
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    First off, hardware interrupts are just that - hardware. You cannot invoke a hardware interrupt. An example of a hardware interrupt is on your sound card. The DMA chip is programmed for half the length of the sound sample and the card is as well. The programmer then writes an interrupt handler to catch a hardware interrupt from the card. When the DSP chip on the sound card reaches the end of the programmed length of the sample, it fires off a hardware interrupt on a certain IRQ channel - which one is purely up to the manufacturer of the card, but most used IRQ 3 through IRQ 7 in the DOS days. These IRQs are NOT actually 3, 5, and 7 on the list of all 255 interrupts. IRQ 5 actually is about IRQ 55 hex - but it was known as IRQ 5 and called that by Creative Labs and other companies that manufactured sound cards. The hardware interrupt is then fired which signals that the sound sample has finished playing or finished iterating through the data. Now your interrupt handler catches the interrupt (after correct setup of the PIC) which then would load more data into the circular buffer. It's a circular buffer - always loading into the section that just finished playing and always playing the section that just finished loading. In this way the load cursor will never conflict with the play cursor (essentially the pointers will never overlap) so there is no danger of getting a popping sound when playing large sound files.

    Hardware interrupts cannot be invoked from software - they must be hardware generated. Now software interrupts can be invoked and they can be invoked from XP as well inside of a DOS session. Don't be so sure that the emulator won't do just what you want it to. I've yet to find any software interrupts that behave unexpectedly inside of XP. However, DMA, PIC, and other types of programming will probably fail miserably. But this code should compile and run fine under TC 1.0 with TASM 5.0.

    Code:
    void SetMode13h(void)
    {
      asm {
        mov  ax,13h
        int 10h
       }
    }
    
    void ResetMouse(void)
    {
       asm {
         mov ax,0000h
         int 33h
       }
    }
    
    void ShowMouse(void)
    {
      asm {
        mov ax,01h
        int 33h
      }
    }
    
    void HideMouse(void)
    {
      asm {
        mov ax,02h
        int 33h
      }
    }
    
    struct Mouse
    {
      int x,y,button;
    }
    
    void GetMouseButtonDown(Mouse &outMouseData)
    {
      asm {
        mov ax,03h
        int 33h
    
      }
      outMouseData.button=_BX;
      outMouseData.x=_CX >> 1;         //Divide by 2 only if in mode 320x200x256
      outMouseData.y=_DX;
    }
    Try it.

  10. #10
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by CrazyNorman
    Maybe I'm wrong, but he probably means interrupts (as in hardware interrupts).
    Yes I did .

    It's coming along nicely but I feel there are already many area of improvement.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  11. #11
    Registered User
    Join Date
    Jul 2005
    Posts
    5

    Post

    Here's a link to a tutorial on DOS game programming: <a href="http://www3.telus.net/alexander_russell/ course/introduction.htm">This is the link.</a> You learn to access the hardware directly and all that good low-level stuff...

    EDIT: I guess HTML links don't work here. How does one make a link on these forums?
    Last edited by ProgramWizard; 08-06-2005 at 06:46 AM. Reason: My link didn't work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21