| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
Linked list
Hello all,
Can someone tell me how to implement a dynamic linked list in assembler, or perhaps give me a link to where I can find something on this?!
This is to be used in a isometric engine(to store objects in a room), If there is another (better) structure than a linked list to use in 6502 assembly please tell me.
Ta. |
|
| |
Radiant
Registered: Sep 2004 Posts: 639 |
I'd go for an array list (sort of, in any case!).
Quick and contrived examples for 8 objects with x and y positions:
; Access the x position of the first object in the list
ldx object_list
lda object_x, x
; Access the y position of all objects in the list,
; first to last
ldy #$00
@loop:
ldx object_list,y
lda object_y,x
iny
cpy #$08
bne @loop
object_list:
.byte $00 ; Object ID's, so objects can be sorted
.byte $01 ; freely etc.
.byte $02
.byte $03
.byte $04
.byte $05
.byte $06
.byte $07
object_x:
.byte $20 ; x positions for objects, ordered by
.byte $30 ; object ID
.byte $40
.byte $50
.byte $60
.byte $70
.byte $80
.byte $90
object_y:
.byte $10 ; y positions ordered by object ID
.byte $20
.byte $30
.byte $40
.byte $50
.byte $60
.byte $70
.byte $80
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
in general you DONT want to do linked list in assembly. Modern languages hide a lot of work wich are a lot of trouble & slow to do on a 6510. (you'll need a mechanism to find empty memory chunks, a mechanism which bookkeeps free/used memory, a mechanism to defrag memory & reorder used places, etc)
radiantx's suggestion is the way to go. |
| |
HCL
Registered: Feb 2003 Posts: 728 |
Agree. In demo-coding you'll probably avoid using linked lists at all, but for tools etc it might come handy. Then Radiantx's example is useful.
I implemented a similar looking binary-tree 100 years ago to use in a Huffman-encoder. Runs with ok performance thanx to the linearized implementation. D0de, maybe i should post that encoder some day.. i used it in several demos already, perhaps someone else would also use it :P. [Edit] The decoder has been used in demos, not the encoder of course. [/Edit] |
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
Thank you guys, it seems quite simple that array list thingy(ta radiantx) :) HCL post that on codebase soon (before you forget). |