Subject: Re: Merlin Newsgroups: comp.sys.apple2.programmer From: dempson@actrix.gen.nz (David Empson) Date: Thu, 6 May 1999 02:02:25 +1200 Message-ID: <1drcux5.76ai83k4omrzN@dempson.actrix.gen.nz> References: <7gn8vo$h4d$1@nnrp1.dejanews.com> <7gnj6g$qq0$1@nnrp1.dejanews.com> Organization: Empsoft X-Newsreader: MacSOUP 2.3 NNTP-Posting-Host: 202.49.157.176 X-Trace: 6 May 1999 02:00:36 NZST, 202.49.157.176 Lines: 91 Path: lobby!newstf02.news.aol.com!portc04.blue.aol.com!newsfeed.mathworks.com!news-peer.gip.net!news.gsl.net!gip.net!newspeer.monmouth.com!newsfeed.clear.net.nz!usenet.net.nz!news.iprolink.co.nz!news.actrix.gen.nz!dempson wrote: > I don't know how to define a spot in the program for 8 BYTES of storage > yet, so I put XXX. > > > > Label1 XXX 12345678 ;define 8 BYTES of data, the first byte is > ;LABEL1, the second is label1+1,etc > > Label2 XXX 12345678 > > Label3 XXX 12345678 > > > LabelTableL XXX XX XX XX ;lobytes of table > > LabelTableH XXX XX XX XX ;hibytes of table > > Is there a way I can tell Merlin to build a lookuptable for label1-label3? This is a messy way of implementing the lookup table, because you have to tell Merlin to get the low and high order byte of the address of each entry, which is fiddly. The end result would be something like this: Label1 DFB 1,2,3,4,5,6,7,8 ; or whatever Label2 DFB 9,10,11,12,13,14,15 Label3 DFB 16,17,18,19,20,21,22 LabelTableL DFB Label1,>Label2,>Label3 The "<" and ">" directive mean "low byte of address" and "high byte of address" respectively. You can also use them in immediate instructions, e.g. LDA #Label1 STA Ptr+1 (In this case, you could omit the "<" directive, because DFB always gets the low order byte of the operand. Leaving the directive there is clearer.) Now, getting back to your pointer table: a cleaner way of doing this would be to use the DA directive and store each pointer as a 16-bit value, like this: Label1 DFB 1,2,3,4,5,6,7,8 ; or whatever Label2 DFB 9,10,11,12,13,14,15 Label3 DFB 16,17,18,19,20,21,22 LabelTable DA Label1,Label2,Label3 To use the lookup table, your code needs to double the index into LabelTable, e.g. * Assuming X contains the index, i.e. 0, 1 or 2: TXA ASL TAX LDA LabelTable,x STA Ptr LDA LabelTable+1,x STA Ptr+1 Another point to consider: if the data structures referenced by your pointer table are all the same size, and the size is a power of two, then you could just calculate the relative address of the data structure. (If the number of bytes in each entry is not a power of two, then a table lookup is probably easier than having to implement a multiply routine.) For example, if your Label1, Label2 and Label3 tables each contain eight bytes, and you want to access an arbitrary table, you could use this: * Assuming X contains the table number, i.e. 0, 1 or 2: TXA ASL ASL ASL ADC #Label1 * Note: the following ADC is only needed if you might have crossed * a page boundary. ADC #0 STA Ptr+1 -- David Empson dempson@actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand