Research / Megadrive Programming / Loops & arrays Loops in 68k are very limited... Forget about while- or for-like loops ;) For loops, you use DBcc. Usually, programmers just use DBF or DBRA (which mean the same). First operand is a data register that will be decremented and the second one is a label where to loop if this data register isn't -1. Example: lea ($1234).l,a0 This example will go back to the Loop label 8 times (d0 + 1). It's not that hard... I won't show the other DBcc instructions because they are practically useless. Maybe later, when I'll write an instruction list... Second part of this chapter will be arrays. Well, I call them arrays, but they really aren't. Those are just sets of bytes, words, longwords that are readed depending on some variable. For instance, we want to load a different music depending on the current level: moveq #0,d0 ;clear d0 I thought 5 damn minutes about how should I explain this XD. The move.b (a0,d0.w),d0 instruction moves a byte at a0 + d0 to d0. Let's examine 3 possibilities (GHZ - 00, LZ - 01, MZ - 02) GHZ: I hope you get it... This chapter was short but very important, so if you don't understand something, read it 10 times =P And you can always ask on the forums. Back | Printer friendly << 5. Editing the game code |