*Very* new to ASM. Where to start?

Página 3/5
1 | 2 | | 4 | 5

Por ARTRAG

Enlighted (6844)

Imagen del ARTRAG

18-09-2005, 19:05

About storing variables, in assembly you can store them
1) in VRAM:
very very slow to access them (you pass throughout the vdp), but you have 128Kbyte. Avoid reading & writing the VRAM as you can

2) in RAM:
slow to access them, but you have 64Kbyte (or more if you swap RAM pages). The paging system is very slow and bad but the Z80 is 8bit...

3) in z80's register
fast, but you have very few of them, IX and IY are the slowest registers to use, BC,DE,BC',DE' are fast,
A and HL are the fastest (in the sense that many operations can be done on HL and A and not so many on the other registers)

Naturally you need all the method in a real life program
About RAM the assembler allows you to give labels to memort locations.
E.G.

X_coord: dw 128
Y_coord: dw 64

Each time you use X_coord in the code,
the assembler will replace it with the address
of the memory location where 128 is.
The same for Y_coord

In this way you can do

ld hl,(X_coord)
ld bc, 4
add hl,bc
ld (x_coord),hl

to incremet the X of 4 pixels

Por Mirg

Expert (88)

Imagen del Mirg

18-09-2005, 19:13

So I assume most games, let's take Nemesis as an example, store their variables in RAM and modify them when needed?

I took Nemesis as an example because I have yet another question. They don't seem to stop coming, do they? Tongue

How does the game handle all those enemies and bullets? Whenever a bullet is fired, does that bullet get its own memory block where direction, coordinates and behavior are stored? And if that's how it works, how does the game know what "objects" are currently alive and need updating?

Can you stack those somehow? Or do you need to manually define a block of memory in which the adresses of the object's data is stored?

Not that I'm currently planning something complicated like that. I'm having a lot of fun just plotting pixels right now. Smile

Por Mirg

Expert (88)

Imagen del Mirg

18-09-2005, 19:26

Oh, heh, I replied to early I see. Smile

X_coord: dw 128
Y_coord: dw 64

Heh, that's quite handy. Thanks, that solves (amonst other things) the cursor-coordinates I needed for a simple 8x8 block "drawing program". Smile

Por pitpan

Prophet (3152)

Imagen del pitpan

18-09-2005, 20:18

Mirg: just in case you haven't seen it yet, you can download asMSX v.0.11 from MSX Workshop. Of course, it is NOT the most powerful cross-assembler around, but it is quite user-friendly and withing this distribution there are two complete games coded in assembler with commented code as well as other simple demos. Check it out. Please note that you can easily convert the source code to other assemblers.

Por Mirg

Expert (88)

Imagen del Mirg

18-09-2005, 20:35

Thanks, pitpan! I'm on a Mac, so I can't use the assembler I'm afraid, but the commented games are *very* educational! There's even code to use a custom font in there. Big smile

Por Manuel

Ascended (18784)

Imagen del Manuel

18-09-2005, 21:41

The program can probably be recompiled for Mac OS X as well, AFAIK pitpan is making sure it will compile in Linux; that will help a lot.

Por pitpan

Prophet (3152)

Imagen del pitpan

18-09-2005, 23:24

Yes, that's the idea. I'm working on the new v.0.12 version and the final release will be opensource. As far as you have a GNU C compiler (GCC) available in your computer [sadly, this excludes MSX], you'll be able to compile it.
But, as you've said, commented games can be easily translated to other assemblers.

Por norakomi

Paragon (1123)

Imagen del norakomi

19-09-2005, 00:11

Whoops, typo, heh. Well, at least the typo is in here instead of in my code, making me wonder why my code's not working. Tongue

And thanks for clearing that up. Big smile
Oh, yeah, one more thing.
the RET which ends the programm will jump back to the assembler,
so in order to see the DOT you put in screen 5,
you should put a loop at the end of your code,
like
JUMP: JP JUMP (basic: 100 goto 100)
(however no CTRL-STOP in assembly, haha)
anyway, make it end when pressing space or something)

and when going back to the assembler jump back to screen 0 !!

screen0:
xor a
call $5f

starting to like assembly ??? (I love it sooo much !!)
LOL!

Por [D-Tail]

Ascended (8259)

Imagen del [D-Tail]

19-09-2005, 08:10

           LD  B,120
WAIT_2SEC: HALT
           DJNZ WAJT_2SEC

Will wait for 2 seconds Wink

Por Mirg

Expert (88)

Imagen del Mirg

19-09-2005, 08:58

I quit my non-textmode programs with this:

CALL $9F ; Bios: CHGET
LD A,0
CALL $5F ; Bios: CHGMOD
RET

That way, I can study my result as long as I like, then I press a key and I'm back in WBASS2. I thought it would be a good idea to examine the BIOS calls a bit before I started playing around with graphical modes. Smile

Oh, yet another question, about key input this time. If I want to check if, for example, ESC is pressed and then only quit if that's true, would that look something like this?

WAIT_ESC: CALL $9f ; Bios: CHGET
          XOR $27
          JPNZ WAIT_ESC
          RET

(I'm at work, so I can't check in WBASS2 now, sadly..)

Página 3/5
1 | 2 | | 4 | 5