Machine code challenge

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
Hikaru
Microbot
Posts: 100
Joined: Mon Nov 13, 2017 1:42 pm
Location: Russia
Contact:

Re: Machine code challenge

Post by Hikaru »

Err, you might be looking too much into it. There's basically two loops, the outer one makes the edges, the inner one fills the horizontal lines if the Z flag is set. Before entering the overall loop, we set the Z flag using CP A so the first line is filled horizontally. Next time this happens is at the last line, where Z is set by DEC E when E reaches 0. In between these two it's just putting the edges, and the inner loop does nothing apart from INC HL x 30.

Ast A. Moore wrote: Wed Nov 22, 2017 6:17 pm
R-Tape wrote: Wed Nov 22, 2017 4:15 pm I can see Hikaru's makes a blue box, but I still need to work out how it's doing it...
I commented his code. Hope I didn’t make it sound more complicated than it actually is
Scratch that, now I have no idea what's going on in there myself. Well done! :lol:

krt17 wrote: Wed Nov 22, 2017 6:57 pm from Russia with love
23
Not bad. I knew something was off about that JP P: RET construction. :)
Inactive account
krt17
Drutt
Posts: 7
Joined: Wed Nov 22, 2017 6:54 pm

Re: Machine code challenge

Post by krt17 »

and ofc jp p ret equ ret m jr
User avatar
MatGubbins
Dynamite Dan
Posts: 1237
Joined: Mon Nov 13, 2017 11:45 am
Location: Kent, UK

Re: Machine code challenge

Post by MatGubbins »

I had some trouble getting the asm from krt17 to work properly with EmuZWin, it was due to the 0x before the hex, so they were stripped out and replaced with dec for those of us without a working hex head. The colour variable was moved to the start to allow for different borders to be set by the user. It is a magnificent bit of code, that works the screen backwards (bung some HALTs in there to see it in action) and in less bytes too.

Code: Select all

Frame     LD      C,10 ; colour
        ld      hl,23295

        xor     a
        ld      a,23
L2
        ld      b,30
        ld      (hl), c
        dec     hl
L1
        jr      nz,skip
        ld      (hl), c
skip    dec     hl
        djnz    L1

        ld      (hl), c
        dec     hl
        dec     a
        ret     m
        jr      L2
        
Asking for snippets of code from forum members shows us that we all write things in a different way, upper/lower case, hex/dec mixtures
The result is that we learn from each other, new ways of improving the code and hopefully squeezing an extra graphic or something into the end game.
Dave, you have 6 extra bytes so far... use them wisely!
Post Reply