[A83] Re: Structs in asm


[Prev][Next][Index][Thread]

[A83] Re: Structs in asm




Structs are VERY easy to do in asm.

Here's an example (objects (sprites)):

;At the beginning, make this:
SpriteCount = 24  ;or whatever you want to put there

;Somewhere in the code (at the end) put this:
SpriteTable: .fill 0,24*8   ;Makes 24 blank sprites

;SpriteTable Information
s_x = 0
s_y = 1
s_sprite = 2
s_class = 3
s_flags =7
;This works out to 8 bytes an object,
;bytes 4-6 are internal variables in this example.

You will need a piece of code to display all the sprites, (check bubble 
bobble source code if you really want this)

Then code to work with the objects:

  ld ix,SpriteTable
  ld b, SpriteCount-1
TheLoop:
  ld a, (ix+s_class)
  or a   ;Check if class 0, skip otherwise
  jr z, SkipSprite
  push ix
  push bc
  call HandleObject
  pop bc
  pop ix
  ld de,8
  add ix,de
  djnz TheLoop
  ret
HandleObject:
  cp 1
  jp z,HandleClass1
  cp 2
  jp z,HandleClass2
  ...
  ret

To actually use the variables, they are at (ix + <variable>).  This example 
system allows the sprite's pictures to be different from the 'class'.

See the Bubble Bobble source code for a real example.
http://bubblebobble.dwedit.cjb.net/


>From: Mike3465@aol.com
>Reply-To: assembly-83@lists.ticalc.org
>To: assembly-83@lists.ticalc.org
>Subject: [A83] Structs in asm
>Date: Sun, 18 Mar 2001 16:03:48 EST
>
>
>Hey guys, I'm sure you all have programmed structs sometime before(yeah 
>blah
>blah blah) and i'm sure you have all realised, but I'm going to write
>something about how to do them in asm, just incase you guys have realised 
>it,
>and would appreciate it(yeah like that will happen)
>
>ok, first step, design the struct, here we decide what data will be placed
>into it and what not
>(example from the code i'll be using for doors)
>;1st 2 bytes, x and y on current map
>;2nd 2 bytes, new map in memory
>;3rd 2 bytes, new x and y cordinates(where to move them too)
>;4th 2 bytes, misc data (need key(1st byte), which key(2nd byte) etc...)
>
>so the data would look like this:
>door:
>     .db 5,2     ;x,y
>     .dw NewMap; Map's name
>     .db 4,3     ;new x and y
>     .db 0,0
>
>and then to get the x and y cordinates i would do this:
>     ld hl,door
>     ld a,(hl)
>     inc hl
>     ld b,(hl)       ;now the x and y cordinates are in a and b respectivly
>
>and to get the new door:
>     ld hl,door
>     inc hl
>     inc hl
>     inc hl  ;maybe i could just say,add hl,3 i dunno
>     ld de,(hl)
>     ld hl,de        ;i could leave this out and just work with de too, but 
>oh
>well
>
>etc...
>
>just a quick thought i had, and thought i would give that bit of "wisdom" 
>out.
>
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com