• Welcome to Dark Bit Factory & Gravity.
 

trying to port tajs trinnity example

Started by ninogenio, July 08, 2007

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Stonemonkey

I was in the middle of replying with something about having had a look to see if I could do the loops differently but couldn't find anything that made any difference when I noticed that.

ninogenio

ive actually just got the size down to 1012 bytes by writing these bits out long hand.


Dim Shared As ZString * 15 glnameA => "glCreateShader"
Dim Shared As ZString * 15 glnameB => "glShaderSource"
Dim Shared As ZString * 16 glnameC => "glCompileShader"
Dim Shared As ZString * 16 glnameD => "glCreateProgram"
Dim Shared As ZString * 15 glnameE => "glAttachShader"
Dim Shared As ZString * 14 glnameF => "glLinkProgram"
Dim Shared As ZString * 13 glnameG => "glUseProgram"



glFP( 0 ) = Cast( GenFP , wglGetProcAddress( glnameA ) )
glFP( 1 ) = Cast( GenFP , wglGetProcAddress( glnameB ) )
glFP( 2 ) = Cast( GenFP , wglGetProcAddress( glnameC ) )
glFP( 3 ) = Cast( GenFP , wglGetProcAddress( glnameD ) )
glFP( 4 ) = Cast( GenFP , wglGetProcAddress( glnameE ) )
glFP( 5 ) = Cast( GenFP , wglGetProcAddress( glnameF ) )
glFP( 6 ) = Cast( GenFP , wglGetProcAddress( glnameG ) )
Challenge Trophies Won:

taj

#22
Utterly awesome work - karma++! I would never have believed it - a basic glsl program in <1k.

heres a wild idea that might save a few more bytes. Try changing:


gluSphere( gluNewQuadric() , 1.6 , 200 , 200 )
gluSphere( gluNewQuadric() , 1.04 , 200 , 200 )
gluSphere( gluNewQuadric() , 0.4 , 200 , 200 )


to

gluSphere( gluNewQuadric() , 1.6015625000f , 200 , 200 )
gluSphere( gluNewQuadric() , 1.0390625000f , 200 , 200 )
gluSphere( gluNewQuadric() , 0.4003906250f , 200 , 200 )


In theory this makes the code easier to compress, but it doesnt work for me. Then again, your trick of writing out the loop doesnt work for me so its all a bit black magic.
Chris
Challenge Trophies Won:

ninogenio

wow that takes me down to 1003 bytes thanks chris! k+


Challenge Trophies Won:

Jim

Can you try changing the loop to while/wend?

while GetAsyncKeyState(VK_ESCAPE) = 0
wend

And unfortunately, for Vista, you need to add

ExitProcess(0)

at the very end, otherwise it won't quite properly :(

Jim
Challenge Trophies Won:

ninogenio

yeah no probs jim here you go.

its went back up to 1012 bytes with that.
Challenge Trophies Won:

Jim

I just wanted to see if do/while was smaller than while/wend.  Some compilers optimise one better than the other.

If you disassemble these .o files you can see there's a chunk of stuff that looks like this

jmp fb_static_initialisers
nop
nop
nop
...
nop
fb_static_initialisers:
jmp fb_RtInit

The fbc compiler always adds this to bring in the runtime libraries.
That's a real shame as it's quite probably wasting 10 or 20 bytes compared with the C version.  Maybe I could try to blank that out of the .o before sending it to crinkler.

Jim
Challenge Trophies Won:

ninogenio

#27
ahh i see if you can save between 10 to 20 bytes that would be really cool!

i cant belive benny got this down to 990 bytes with visual studio although i think we are beating dev c as the original trinity is 1024 bytes so we are in between the two.

-edit just tested the while/wend without exit process and it goes from 1003 to 1007 bytes so it is actually a little more expensive.
Challenge Trophies Won:

taj

Nino, Jim, I guess the NOPS are completely optimised out by the compressor.
Still 1012 is bloody brilliant. Is this the first 1k BASIC exe ever?

Chris
Challenge Trophies Won:

Jim

QuoteIs this the first 1k BASIC exe ever?
I would think so :)

Jim
Challenge Trophies Won:

Shockwave

Mindblowing :D

Now a 1KB must be released with Freebasic. K+ Nino, great port!!!! (Yes it works here now )
Shockwave ^ Codigos
Challenge Trophies Won:

ninogenio

#31
cheers for your feedback guys, but really this is all down to jim its all his fb tiny hacking im using and without it this couldnt be done so thanks big guy  :cheers:

if jim finds a way to save any more bytes ill update this and in the mean time ill see if i can come up with an original fb 1k worthy of a release *gulp*.
Challenge Trophies Won:

ninogenio

@jim how would i go about dissasembling the .o files id quite like to have a little mess around?
Challenge Trophies Won:

Stonemonkey

The compiler option -r should give you the asm output iirc.