Re: A86: Efficiency Problem
[Prev][Next][Index][Thread]
Re: A86: Efficiency Problem
It may be beginner, but it still works. I'm a beginner too, and I used
that cp and load system alot before the table was posted. I know it is
slow, but it certainly works as I have several programs based on that.
ZeromusMog@aol.com wrote:
>
> In a message dated 12/10/98 6:16:19 PM Pacific Standard Time, yarin@acc.umu.se
> (JIMMY MARDELL!!!!) writes:
>
> > At 20:27 1998-12-10 -0500, you wrote:
> > >
> > >The following is a fragment(?) of code from a game I'm working on called
> > Nerd
> > >Quest I. It's the a part that displays the current weapon on the status
> > >screen. It seems to me that this code is incredibly ineffiecient, and
> there'
> > s
> > >gotta be a faster way of doing this.
> >
> > Hehe... your source code is probably _the_ classic example of beginners
> > mistakes :-)
> Well, hey. I *AM* beginner. :) If anyone out there wants to use this as an
> example for some turotial, go ahead. Mistakes are for learning from! I
> remember rewriting my first real BASIC game and it was WAY smaller than the
> origional... It's just plain easier after you know all the complicated
> commands (or opcodes)!
>
> Once again, the few lines marked below, I don't understand what they do. My
> policy is that, save for really complex routines that I don't want to tackle
> yet (i.e. dividing routine :), I want to understand what I'm doing...
> especially if it's only a couple lines that I don't understand. (First it's
> three lines, then six, than 27, than 8,316, and next thing you know, your
> ENTIRE assembly program is a cut and paste! Ack!) OK, back on topic.
>
> >
> >
> > Instead of all the checks, you use a lookuptable:
> >
> > ld a,(Weapon) ;Weapon EQU $F602
>
> -----I don't understand from here
> > add a,a
> > ld hl,lookuptable
> > ld d,0
> > ld e,a
> > add hl,de
> -----To here!
>
> If I can recall right, this is slightly different than Dux's routine. I'd look
> it up except I can't get at it w/o a mouse! (If you want to know more about
> that, go ahead and send me a <A HREF="mailto:ZeromusMog@aol.com">personal note
> </A>.)
>
> > call _ldhlind ; $4010 (or LD_HL_MHL)
> > ; And we're done! 14+2*16 = 46 bytes
> > call_puts
> > jp somewhere
> >
> > lookuptable:
> > .dw W1,W2,W3,W4,W5,W6,W7,W8,W9,W10
> > .dw W11,W12,W13,W14,W15,W16
> >
> >
> > ...or the smaller, slightly slower, version...
> >
> > ld hl,DataSection
> > ld a,(Weapon)
> > or a
> > jr z,Done
> > ld b,a
> > xor a
> > SkipStrings:
> > ld c,$FF ; Make sure the loop doesn't terminate because of the counter
> > cpir ; Search string for nullterminating zero (that is - end of
> string)
> > inc hl ; HL -> next string
> > djnz SkipStrings
> > Done:
> > ; Done! 18 bytes
> > call _puts
> > jp somewhere
> >
> > --
> > Real name: Jimmy Mårdell
> > Email: mailto:yarin@acc.umu.se
> > Homepage: http://www.acc.umu.se/~yarin/
> >
> > Icarus Productions homepage: http://icarus.ganymed.org/
References: