It is currently Thu Oct 19, 2017 3:56 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Mon Apr 24, 2017 6:39 pm 
Offline
User avatar

Joined: Sat Jan 03, 2015 5:58 pm
Posts: 367
Location: ...
psycopathicteen wrote:
That's either Billy from Power Rangers finding where the Zeo Crystals are, or Glen Beck finding the Illuminati headquarters.

Bit much hair for Billy iirc (even in Zeo).

My two pieces of advice for neat code mostly apply to assembly programs: don't be afraid to comment plentifully, and if you ever find yourself wanting to use multiple branches of anonymous labels (like --,+++,) don't. Just don't. Why? Because I have no idea what this routine that I wrote does.
Code:
calcrange:


    ld c,a
    ld a,b
    sbc a,13
    jr c,++
    ld b,a
    ld a,c


    cp b
    jr z,++
    jr nc,+
    jp calcno

    +: ld c,a
    ld a,b
    adc a,35
    jr c,++
    ld b,a
    ld a,c
    cp b
    jr z,++
    jr c,++
    jp calcno
    ++: ld a,2
    ld [calc],a
    ret


calcno:
    ld a,1
    ld [calc],a
    ret
    djnz -

    ++: dec hl
    ld [board_loc],hl
    ret

By that I don't mean that I can't figure out that the code calculates the range of something. I mean that what it's calculating the range of is unknown, and how it's doing so is even more unknown. What the anonymous labels point to is pretty much completely unknown. See the redundant wording? Yeah, everything is unknown.

Of course, that little snippet's outdated, and I have added tons of comments since, so sweet, problem solved. It probably took me an hour to add them, though, because by the time I got around to it, I really couldn't remember what the code was doing or how. Not a fun situation.

Oh, and something I didn't care about back when I wrote that: don't put whitespace before label names, at least not as much as you would for opcodes. It's ugly.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google Adsense [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group