Author |
Message |
- Joined: 24 Jun 1999
- Posts: 1732
- Location: Paris, France
|
Ugliest Code Contest !
Posted: Mon Dec 27, 1999 7:53 pm
|
/* DISPLAY BACKGROUND in VIDEO MODE 3 --------------------------------------------
I am now trying to beat Marat on making the ugliest code possible
I hope to have a good chance to win with this one
Anyone dare to beat me ? */
void Display_Background_3 (void)
{
int x, y=0, z; byte *p_scr, *pattern=BACK_AREA, *tiles_data;
for(;y<192;y+=32,pattern+=96) for(x=0;x<256;y-=32,x+=8)
for(tiles_data=SG_BACK_TILE+(*pattern++<<3),z=0;z<32;z ++)
{
p_scr=screenbuffer->line[y+(z&3)]+x;
p_scr[0]=p_scr[1]=p_scr[2]=p_scr[3]=*tiles_data>>4;
p_scr[4]=p_scr[5]=p_scr[6]=p_scr[7]=*tiles_data&0x0F;
if(!(z&3)){y+=4;tiles_data++;}
}
}
Wow I'm quite proud of this one, it's unreadable - now I can release Meka sources safely ^_^
Zoop
(gotta rework a bit on it now else I won't even be able to maintain the code myself)
|
|
|
Ricardo Bittencourt
|
Beat this
Posted: Mon Dec 27, 1999 9:36 pm
|
; division by 9 written in Z80 assembly code
; originally written by Ricardo Bittencourt
; as a part of a routine to read a sector from msx disk-drives
; enter HL = number from 0 a 1440
; exit A = HL/9
; destroy HL,DE
; clock cycles presented by Z80 and R800 processors
; this is the fastest way to divide a number by 9 in these processors
; without using look-up tables
; ten points to anyone who understand how it works
DIV9: ; Z80 R800
INC HL ; 7 1
LD D,H ; 5 1
LD E,L ; 5 1
ADD HL,HL ; 12 1
ADD HL,HL ; 12 1
ADD HL,HL ; 12 1
SBC HL,DE ; 17 2
LD E,0 ; 8 2
LD D,L ; 5 1
LD A,H ; 5 1
ADD HL,HL ; 12 1
ADD HL,HL ; 12 1
ADD HL,DE ; 12 1
ADC A,E ; 5 1
XOR H ; 5 1
AND 03FH ; 8 2
XOR H ; 5 1
RLCA ; 5 1
RLCA ; 5 1
RET ; total = 157 22
|
|
|
Johannes Holmberg
|
You know I'd 0wn your ass at this, so I won't even post any code :)
Posted: Mon Dec 27, 1999 11:55 pm
|
...but if you really wanna see some ugly code, look at the sprite engine in uNESsential... :)
|
|
|
- Joined: 28 Sep 1999
- Posts: 1197
|
Posted: Tue Dec 28, 1999 4:42 am
|
How about this:
c = ap ? a ? a : b : bp ? b ? b : a : a ? a : b;
May not win for ugliness, but certainly could win a prize for
being impossible to maintain or decipher. ;)
It could be ten times more weird if I threw in an additional
set of tests, but I haven't even figured that out yet. :)
|
|
|
Nyef
|
Posted: Tue Dec 28, 1999 2:19 pm
|
[ code example removed ]
Quote > Wow I'm quite proud of this one, it's unreadable - now I can release Meka sources safely ^_^
That's nothing. Go find the first releases of DarcNES, and look at nes_blit.c. Aside from the unholy mixture of x86 machine code and C structures, it contains the following little gem:
/*
* there are 256 blitters. hence 256 headers and cleanup routines.
* for each pair of blitters x and y where (y = 255 - x), there are
* eight 1 bits and eight 0 bits. taking this data, we come up with
* the following calculation for how much memory we to allocate.
*
* this formula has since been modified for arbitrary length blitters and
* the overhead of clipping the image.
*/
#define SIZECALC(clipside) (((1 << width) * (sizeof(blit_hdr) + sizeof(blit_cleanup))) + ((1 << (width - 1)) * width * (sizeof(blit_0) + sizeof(blit_1))) + ((flags & clipside)? (3 * (1 << width)): 0));
if ((flags & BFL_REVERSED) == 0) {
i = SIZECALC(BFL_LEFTCLIP);
} else {
i = SIZECALC(BFL_RIGHTCLIP);
}
#undef SIZECALC
The function then proceeds to allocate i bytes of memory and, using memcpy() and some direct manipualation, fills the memory with procedures. A procpointer array is then filled with pointers to the procedures. This is done several times.
Of course, the entire approach was Just Plain Wrong, and the code has long since been scrapped. On the other paw, it's things like this that make me confident that I can write a dynarec CPU core whenever I feel like doing so. ^_^
And if you want more unreadable code, see the IOCCC.
Quote > Zoop
> (gotta rework a bit on it now else I won't even be able to maintain the code myself)
--Nyef
|
|
|
Chris
|
Ahhh!!
Posted: Tue Dec 28, 1999 6:18 pm
|
I think you stretched a blood vessel in my brain. I feel so dizzy. Please, all of you should deserve
the trophy for the uglyest programming codes.
Chris :o)
|
|
|
Ricardo Bittencourt
|
Re: Ahhh!!
Posted: Wed Dec 29, 1999 1:36 am
|
Quote > I think you stretched a blood vessel in my brain. I feel so dizzy. Please, all of you should deserve
> the trophy for the uglyest programming codes.
The one who thinks optimized code is ugly will never
reach the Zen of programming
(as said by Ricardo Bittencourt, the illuminated one)
|
|
|
Chris
|
Enlighten me, Mr. Bittencourt.
Posted: Wed Dec 29, 1999 3:52 am
|
Quote > The one who thinks optimized code is ugly will never
> reach the Zen of programming
What is the Zen? Is it some type of..."charma"? A really..."high" point in programming?
Quote > (as said by Ricardo Bittencourt, the illuminated one)
Illuminated?? You've gotta show me a JPEG of yourself so I can see the glow!
Happy holidays and happy new year,
Chris :o)
|
|
|