We pass an X,Y pos in DH,DL
Each line is 320 pixels (320 bytes)... we move in 8x8 'blocks' so
we multiply the Xpos by 8, and they Ypos by 320*8
We then add the screen base - 0A000h:0000h
We 'XOR' the sprite with the screen pixels... this 'inverts' the
image on the screen, meaning if it's drawn twice to the same pixel
position it will be removed the second time.
Key reading and moving the sprite
We define the starting position of the sprite, and show the
starting smiley position with our showsprite routine.
We need to process the 4 directions.
We use INT 16h - Function 01 to read the keyboard, this returns NZ
if a key is waiting in the key buffer.
if there is then first we remove the old sprite, then we use INT
16h - Function 00 to get the keycode in AH
If a direction key is pressed, we then check the current smiley
position - if it's already at the edge of the screen, we can't
move again, but if we can, we move in the pressed direction.
We repeat for all 4 directions Up, Down, Left and Right.
Each line of the tilemap is 32 tiles.. each tile is 2 bytes...
the Tilemap base is 0000h:1000h
so our formula for the tile to change is 1000h + (Xpos * 2) +
(Ypos * 64)
Pad reading and moving the sprite
We define the starting position of the sprite, and show the
starting smiley position with our showsprite routine.
We need to process the 4 directions.
we select one of the 3 sets of controls (X-Pad, Y-Pad buttons)
by writing to 0B5h with one of the top 4 bits set.
We then read from 0B5h to get the current state of those buttons
in the bottom 4 bits.
if a key is pressed we first remove the old sprite
We check if each direction key is pressed, we then check the
current smiley position - if it's already at the edge of the
screen, we can't move again, but if we can, we move in the
pressed direction.
We repeat for all 4 directions Up, Down, Left and Right.
We now draw the new sprite position, pause a moment and
repeat.
You can learn more about
key-reading on the wonderswan in this
tutorial here... have fun!