Need help on ASM programming

By Chardson

Champion (411)

Chardson's picture

24-01-2005, 06:01

Hello, I am a newbie in asm programming. But I have programmed games in C and Java. But MSX is such a wonderful machine and I want to enter with a game for MSXdev'05. Well, I know Z80 asm (after 6 months studying it ^^) and I know some of MSX Hardware. I started creating a test demo, but couldn't make some things I wanted. Just want to remember that my questions are related to MSX1. So, here it goes:

1- How to make multicolored sprites like ones found in Ar Yie Kung Fu 2? In fact, even in Maze of Galious, Popolon's face has diferent color from his body, but with screen 2 properties, it is not possible.

2- How to control the speed of sprite moves? I made a sprite that moves with the directional pad presses, but even a fast tap makes the sprite cross the screen.

3- Related to question above. How to handle clock in MSX1? In java and C we move sprites acording to time. And also we freeze a screen (like opening ones) using time routines. How is it done in assembly? (MSX1 do not have that blessed clock IC Sad )

4- I searched in the MSX2 Technical Handbook but did not find how to read keyboard presses. I can read directional and trigger presses through GTSTCK and similar routines. But how is done to read a "P" press for pausing the game, for exemple?

5- I couldn't use expanded sprites for some reason, even after setting bit 0 of R#1 (as specified in MSX2THB). Any tips?

Thanks for the audience Smile

Login or register to post comments

By BiFi

Enlighted (4348)

BiFi's picture

24-01-2005, 08:10

Here are some answers:

  1. Multicolored sprites are done with 1 sprite per color. You need to make 2 seperate patterns to make a sprite with 2 colors.
  2. and
  3. Most of the time this is done by putting the routine on an interrupt, in this case the VDP interrupt, which is triggered 50 or 60 times per second. You can put a routine on it by putting a jump on the H.TIMI hook which is located on address $FD9F. The routine is called each time the VDP triggers the interrupt. You need a counter that hits a certain value to speed down action where necessary.
  4. There's a built-in routine for that called SNSMAT which is located on address 41. It requires the number of the row you want to scan (your example: P is on row 4, bit 5). If this bit is reset (z-flag set) the key is pressed.
  5. There are 4 types of sprite settings and I doubt if you really want the one you explained:
    • 8*8 normal
    • 8*8 magnified (this is the one you will get when you set bit 0 of R#1)
    • 16*16 normal
    • 16*16 magnified

    Are you sure you want 8*8 magnified? If you don't and you want 16*16 normal, you'll need to set but 1 or R#1 instead.

A valuable site for MSX assembly developers is MSX Assembly Page. It contains all sorts of information on MSX development, like the keyboard matrix. You can find tables with rows and bits to scan to see if a certain key is pressed.

I hope it helps.

By viejo_archivero

Paragon (1395)

viejo_archivero's picture

24-01-2005, 09:34

Hello, I am a newbie in asm programming. But I have programmed games in C and Java. But MSX is such a wonderful machine and I want to enter with a game for MSXdev'05.

First of all, good luck at MSXdev05, Charson!. With MSX1 sprites could use 1 color only, so overlapping sprites will do the trick... but beware putting 5 sprites in a row, because the 5th one will disappear!. Just play around with it, and test a lot of MSX1 games just to examine how the coders face the sprite thing... Smile

Again, good luck with your project Smile

By Maggoo

Paragon (1214)

Maggoo's picture

24-01-2005, 09:44


1- How to make multicolored sprites like ones found in Ar Yie Kung Fu 2? In fact, even in Maze of Galious, Popolon's face has diferent color from his body, but with screen 2 properties, it is not possible.

Use multiple sprites. However you'll be limited to 4 on the same horizontal.

2- How to control the speed of sprite moves? I made a sprite that moves with the directional pad presses, but even a fast tap makes the sprite cross the screen.

Easy way is to add a "HALT" command in you loop, if interrupts are enabled that is.

3- Related to question above. How to handle clock in MSX1? In java and C we move sprites acording to time. And also we freeze a screen (like opening ones) using time routines. How is it done in assembly? (MSX1 do not have that blessed clock IC Sad )

Nope, on computers like MSX you don't move sprites according to clock, you do it according to screen interrupt (vertical refresh interrupt). Again, a simple way to do that is the simple "halt", it waits for the next interrupt, and is usally sync with the vertical refresh which occurs every 1/50 or 1/60 of a second.

By wolf_

Ambassador_ (9903)

wolf_'s picture

24-01-2005, 10:32

about multicolor-sprites... observe for example nemesis 2, when you 'start' you're in space and you've to blast series of blue'ish enemies ... those are (screen2-)tiles.. so: if something's moving with 8 pixels at a time, consider using characters instead of sprites ... you've 2 colors per line then..

By Edwin

Paragon (1182)

Edwin's picture

24-01-2005, 10:49

For timing you can also check bit 7 of the status register. This will flip to 1 at the start of the vertical blank. The advantage is that this also works with the interrupts disabled. Of course you have to keep track of all timing yourself as checking this bit for turning to 1 is effectively a wait loop.

A good summary of tech imformation can be found at:
www.work.de/nocash/portar.htm

By Sonic_aka_T

Enlighted (4130)

Sonic_aka_T's picture

24-01-2005, 15:49

Indeed, never underestimate the power of EI + HALT. It can be very handy, especially if you're still testing and don't have your ISR in place yet. There's even circumstances in which a clever use of HALT is really all you need... Can be ideal at times, and certainly easier than hanging a gazillion things on the interrupt.

Another way to time stuff can be by using JIFFY (FC9E/FC9F) which increases by one every interrupt. I'm not sure if MSX1 computers have that variable, although I see no reason why it shouldn't... I used to use that a lot too, when I first started coding in assembly...

By ro

Scribe (4540)

ro's picture

24-01-2005, 16:23

or POLL the interrupt (e.g. using a status byte)
or put the sprite on interrupt

simply put. the msx is too fast for your eyes. ghehe. (obvious you have to TIME everything.. mostly using the trusty Vertical Blank interrupt..)
there's so much more to explore there...

moving a sprite on screen is 1. making a smooth game is another.
you'd be better of making some animation engine or sumpfn.

good luck

By ro

Scribe (4540)

ro's picture

24-01-2005, 16:24


Another way to time stuff can be by using JIFFY (FC9E/FC9F) which increases by one every interrupt. I'm not sure if MSX1 computers have that variable, although I see no reason why it shouldn't... I used to use that a lot too, when I first started coding in assembly...

Be carefull; that byte is only set during STANDARD BIOS routine #38. So when building own interrupt modes, this byte will be dead.... (unless you increase it yo self m'kay)

By Sonic_aka_T

Enlighted (4130)

Sonic_aka_T's picture

24-01-2005, 16:48

True, but I think our learning MSX friend shouldn't be bothered with making his own ISRs just yet. The BIOS is a powerful tool when you're still learning how the MSX system works. Heck, I still use CHGMOD all the time, don't see the need to increase my sourcecode with tables or a bunch of outs just so I can say I don't use the BIOS. It's handy, so make use of it. Only switch the BIOS off if it's really in your way. That probably won't be for a long time though, and I really only see the need for custom ISR's on MSX2 systems where you can split and stuff...

By Chardson

Champion (411)

Chardson's picture

24-01-2005, 17:04

Wow, thanks for the feedback Smile

ro, I know there is a long way to go if I want make a decent game. But even if I succeed in it, I don't expect to win any prizes from MSXdev'05. It is just for fun. I really love programming and assembly is the lenguage I like most (Java OO is very nice too).

BiFi, about the expanded 8x8 sprite, I am just making tests to see the possibilities. Probably in the end I will stick with 16x16 sprites.

To solve the sprite limitations in a row, I think the best thing to do is change their numbers every VBlank. At least that's how they used to do with Master System.

Thanks everyone.