Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Space Invaders ... in assembly language! PLZ HALP!

This thread is locked; no one can reply to it. rss feed Print
Space Invaders ... in assembly language! PLZ HALP!
Lupuss.Umbrae
Member #8,387
March 2007
avatar

Hello!

So, my class got the task to write an arcade game(Space Invaders or something simmilar to this) in assembly language. :o Well, what I would like to know:

1. There is a ROM in every computer, which generates ASCII-Chars(is it called video address generator in English?) and we know the memory adress and how to read every bit from every character. Our teacher would really like it, when we would make some graphics instead of using ASCII chars for visualisation("create our own ASCII chars"). I really want to do this, but I have no Idea how to code this.

2. I would like to know, no, I need to know how to write stuff into memory, for enemy coordinates or something.

Would someone please please please with sugar on top give me any advice/link(s)/code example(s)/whatever to meet my endless, evergrowing demand for information?

EDIT:
We work with Borland Turbo Pascal compiler and do inline assembly...

--------------------------------------------------
I'm not a signature, I'm just cleaning here...

mEmO
Member #1,124
March 2001
avatar

Well, I suppose your best bet would be to read up on mode 13h programming. The wikipedia page should give you some pointers (pun intended).

---------------------------------------------
There is only one God, and Connor is his son!
http://www.memocomputers.com
Happy birthday!

kazzmir
Member #1,786
December 2001
avatar

Ah, inline assembly with good ol' pascal. I assume you are in real mode then?( as opposed to protected mode ).

If you are in text mode you can manipulate the ascii graphics by accessing memory at address 0xb800, or in ye olde pascal lingo

memw[ $B800 ] := ...;

To put a character at a specific x,y coordinate simply convert the coordinate into an offset from $B800.

memw[ $B800 + x + y * 80 ] := ...;

So as a real example to put the letter 'a' down you do

memw[ $B800 + x + y * 80 ] := 'a';

I think.. There are ways to add color too by messing with the upper bits of the character

memw[ $B800 + x + y * 80 ] := color shl 8 + 'a';

Or something. Hopefully you can convert memw into assembly, it shouldn't be too difficult.

BTW, if you want 320x200x8 graphics mode, not ascii, you can set it with this assembly

mov $ax, $13
int 10h

And then vga graphics memory is at $a000 instead of $b800.

Mike Farrell
Member #248
April 2000
avatar

See if you can use nasm instead of borland. Borland sucks ass.

Every modern computer comes with the ability to do vesa graphics. If you look in the source code to the old DOS allegro (3.1), you'll see how to use this to set a rather advanced graphics mode (like 320x240x16). Then I'm assuming you use memory mapped io to write directly into the graphics memory.

Be careful that if you're coding in dos without protected mode, you can seriously screw up the system if you "crash" the program. I'd recommend writing this in linux or some other modern OS.

From here on though, I'm not sure how it works. Here's a guess

Assuming the address of a 16-bit framebuffer is 0xA0000
then the instructions to write a white pixel into the first pixel would be (in nasm/intel syntax)

  ;address of fb
  mov ecx, 0xa0000

  ;write 0xffff (16 bits) into first 2 bytes of fb
  mov al, 0xff
  mov [ecx], al
  mov [ecx+1], al

  ;next two bytes
  mov [ecx+2], al
  mov [ecx+3], al

Apparently though its more complicated than that, and you can only write so much at a time. But that should get you started.

one vesa ref:
http://www.delorie.com/djgpp/doc/ug/graphics/vesa.html

Arthur Kalliokoski
Second in Command
February 2005
avatar

I was doing this all the time in the '90's, prolly have some code at home ready to go, but it'll have to wait until tomorrow. I'm saving the post to bring home.

They all watch too much MSNBC... they get ideas.

Lupuss.Umbrae
Member #8,387
March 2007
avatar

Thanks for your answers.
Our teacher said, he wants us to work with mode $03(holy crap...), but I think he wouldn't mind when I choose an other. So, how should I display a space ship, when I can use ASCII only?
We are not allowed to use Turbo Pascal itself, inline assembly only... I mean... we could hack this crap directly into memory...

And...umm... writing stuff into memory is done the same way as writinginto display memory...It was a dumb question, I know...(someone throw a stone at me).

--------------------------------------------------
I'm not a signature, I'm just cleaning here...

kazzmir
Member #1,786
December 2001
avatar

Read my post about $b800.

Lupuss.Umbrae
Member #8,387
March 2007
avatar

I know how to display ASCII characters, kazzmir. You don't really think our teacher would give us such a killer-task instead of two fucking class tests when we are completely unprepared, do you? Maybe I did not exactly explain what I (and my teacher) want... Okay... I know how to put an 'a' on the screen in text mode $03, but I don't know how to turn this simple 'a' into, say, start ship Enterprise. We will maybe learn how to do it, but I just can't wait a week...

--------------------------------------------------
I'm not a signature, I'm just cleaning here...

kazzmir
Member #1,786
December 2001
avatar

Well that is strange because drawing things is a much simpler problem..

If each 'a' is an "ascii pixel" with an x and y coordinate then your star ship is just a set of coordinates. All you have to do is loop through the coordinates and draw on the screen.

Using psuedo-c syntax

// imagine the 1's draw the shape of a ship
char ship[10][10] = 
{{0,0,0,0,0,0,0,0,0},
 {0,0,0,1,1,1,1,0,0},
  ...};

for ( int x = 0; x < 10; x++ ){
   for ( int y = 0; y < 10; y++ ){
      if ( ship[x][y] == 1 ){
          draw_pixel( x, y );
      }
   }
}

So you just need to store the pixels of the ship somewhere in memory.

[edit]
I guess what you are asking is how to alter the 'a' pixel to be some other arrangement of pixels. I think you can modify the bios fonts, which live somewhere in the $e000-$efff zone, but I forget where.

Simon Parzer
Member #3,330
March 2003
avatar

I think what he really wants to know is how to modify the characters in the ASCII table. How an 'a' looks like, how 'b' looks like, how ASCII char 0x12 looks like and so on.
So he can modify the characters themselves and then draw a ship using, say, 4 modified characters.

I know it's possible, but I don't exactly know how.

Arthur Kalliokoski
Second in Command
February 2005
avatar

In other words, he needs to know (effectively) how to draw a space ship given 256 non-transparent sprites? Maybe he could draw a spaceship in a paint program, break that up into 16 x 16 sub bitmaps and modify the text mode font into those.

As for actually modifying the font...
http://www.ctyme.com/intr/rb-0143.htm

They all watch too much MSNBC... they get ideas.

Gr4|\|f
Member #9,499
February 2008
avatar

The only assembly code i've ever done is old Apple II stuff and redcode-94. But here's my advice, based on outdated knowledge:

There's always somewhere in the memory called the screen buffer (500-600 on the Apple II), and there should be a graphics command to change back and forth from ACSII mode to 16 bit pixel mode. Your going to have to find a spot in the mem to define the pixels for your ship, and then have your program your .exe to call that ship to the screen buffer, and switch to 16 bit color mode. I don't know how you would do it on the newer boxes, though. Sorry.

Ping me @ 127.0.0.1

Go to: