The Fourth 512-byte OS Contest!

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).

What is your favorite entry for the fourth 512-byte OS contest ?

Poll ended at Sun Jan 31, 2010 6:52 am

waveos by waga
1
6%
wordsmith by coddy
0
No votes
mon86 by a427
6
35%
bsantm by Gigasoft
2
12%
scrollroad by MessiahAndrw
2
12%
fractalscroll by Gigasoft
1
6%
snake by Cjreek
0
No votes
ethernet by XanClic
3
18%
spatiallife by Krap
2
12%
terrain/butterfly by js
0
No votes
 
Total votes: 17

earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: The Fourth 512-byte OS Contest!

Post by earlz »

Yea, I think I know what I'm going to do now.. I'm thinking I could make an at least partial FORTH interpreter... that would be pretty neat and the syntax is easy enough to parse in assembly(without tearing my hair out)
a427
Member
Member
Posts: 40
Joined: Sun Mar 15, 2009 9:45 pm

Re: The Fourth 512-byte OS Contest!

Post by a427 »

Well, apparently quite a lot of other people were in fact interested in this fourth 512 asm compo.
Nice !

Let's hope we can set the closing date..

I propose 2010 january 15th ?
What do you think ?

About an eventual prize, I don't think it's so important..
The previous compos did not feature a winning prize, AFAIK, and I guess we like to compete for the fun, anyway...

Concerning the compo requirements (SSE2, etc..), there are none, except for the obvious :

-the compo entry shall fit a 512 bytes binary single file
-it must be bootable by an x86 compatible BIOS + CPU in real mode
-it's a damn plus if we can quick test it with qemu, bochs, etc..

other than that, everything is allowed !
(8086, pentium 4 instructions sets; BIOS interrupts, etc...)
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: The Fourth 512-byte OS Contest!

Post by earlz »

a427 wrote:Well, apparently quite a lot of other people were in fact interested in this fourth 512 asm compo.
Nice !

Let's hope we can set the closing date..

I propose 2010 january 15th ?
What do you think ?

About an eventual prize, I don't think it's so important..
The previous compos did not feature a winning prize, AFAIK, and I guess we like to compete for the fun, anyway...

Concerning the compo requirements (SSE2, etc..), there are none, except for the obvious :

-the compo entry shall fit a 512 bytes binary single file
-it must be bootable by an x86 compatible BIOS + CPU in real mode
-it's a damn plus if we can quick test it with qemu, bochs, etc..

other than that, everything is allowed !
(8086, pentium 4 instructions sets; BIOS interrupts, etc...)
I assume that 64bit is allowed also then(if someone dares to tackle that in 512 bytes)

and yea, a little update to my project..

My forth OS so far is going pretty well but running out of space fast(now at 470 bytes)..
It will print `ok` at the end of commands. It supports a stack of 4096 bytes. It supports the standard +,-,@,and ! words/operators. Also, I put in 2 extensions for `^` and `&` for writing and reading the current segment data will be writtent o(respectively)

My next task will be implementing the do while word, which could make it sorta close to turning complete(if you double the while structure as an if structure)
js
Member
Member
Posts: 38
Joined: Thu Feb 26, 2009 1:45 am

Re: The Fourth 512-byte OS Contest!

Post by js »

A byte is a byte...

Here's a hack for the gamers in you.

To understand / use such a thing, you need a twisted mind -- but I guess anybody trying to write a 512-byte demo has one.

It increments / decrements two registers representing x and y position when you press left/right/up/down arrowed keys. And it's only 28 bytes, including jumping back to the main loop at the end of the work, and not blocking if no key was pressed (so you can continue redrawing the screen while no key is pressed). I included a few pieces of code to make a mini-demo out of it, but that's not counted in the 28 bytes.

It works by building an inc/dec bx/dx opcode from scratch into ax, moving this value just before the main loop (overwriting the initialization stuff you left there) and jumping to that location.

If somebody knows a smaller hack to achieve the same result, I *really* am interested.

Have fun !

Note: If you can't download the attachments, I've stored them here too : http://jahvascriptmaniac.free.fr/2010/p ... tkey-hack/
Attachments
getkey-28-bytes-cleaned.img.asm
Compiled bootsector image
(512 Bytes) Downloaded 148 times
getkey-28-bytes-cleaned.asm
Assembly source code
(2.95 KiB) Downloaded 207 times
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: The Fourth 512-byte OS Contest!

Post by thepowersgang »

My friend, this is one of the most clever tricks I have seen for quite a while!
We could do with a size hacks wiki page or something like that for these things.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
js
Member
Member
Posts: 38
Joined: Thu Feb 26, 2009 1:45 am

Re: The Fourth 512-byte OS Contest!

Post by js »

[font=small]Note : if this is too much off topic, please tell me, I'll move it into a new topic.[/font]
thepowersgang wrote:My friend, this is one of the most clever tricks I have seen for quite a while!
We could do with a size hacks wiki page or something like that for these things.
Thanks ;)

I actually spent a whole day on it, maybe two...
I investigated the following possibilities, in approx. order of size, decreasing :

Trivial, unoptimized, but you can easily change the keycodes

Code: Select all

cmp ah,KEYCODE_UP
jne .1
    inc dx
.1
cmp ah,KEYCODE_DOWN
jne .2
    dec dx
.2
cmp ah,KEYCODE_RIGHT
jne .3
    inc bx
.3
cmp ah,KEYCODE_LEFT
jne .4
    dec bx
.4
A "tree" of bit-testing hacks
Choose HACK1 so that :

Code: Select all

    0 == (HACK1 & KEYCODE_UP) == (HACK1 & KEYCODE_DOWN)
    1 == (HACK1 & KEYCODE_LEFT) == (HACK1 & KEYCODE_RIGHT)
Choose HACK2 so that :

Code: Select all

    0 == (HACK2 & KEYCODE_UP)
    1 == (HACK2 & KEYCODE_DOWN)
Choose HACK3 so that :

Code: Select all

    0 == (HACK3 & KEYCODE_LEFT)
    1 == (HACK2 & KEYCODE_RIGHT)

Code: Select all

mov al,ah
and al,HACK1
jnz .horizontal
    and ah,HACK2
    jnz .down
        inc dx
    .down
        dec dx
.horizontal
    and ah,HACK3
    jnz .right
        dec bx
    .right
        inc bx
Choose jump adress hack
The arrow keys scancodes have the following property : if you zero out their least significant bit, then they each have their first bit counting from the right in a different position. Luckily, the 'bsf' (bit search forward) instruction returns the position of the rightmost set bit.

0101 0000 DOWN
0100 1000 UP
0100 1101 RIGHT
0100 1011 LEFT

Code: Select all

mainloop:
    ; Do something
    
    ; Check for next key
    mov ah, 0x01
    int 16h
    jz mainloop
        ; Manage pressed key and jump back to mainloop
        xor ax,ax
        int 16h

        and ax, 0x1e00    ; keep bits 1,2,3 and 4
        bsf ax, ax    ; see top of the file to see why this works...
        shl ax,1    ; each case takes two opcodes (inc/dec, ret)
        add ax, .do_movements - 16 - 2
        call ax

        jmp short mainloop

        ; the 'call' just above will call one of these.
        .do_movements:
        dec bx
        ret
        inc bx
        ret
        dec dx
        ret
        inc dx
        ret
Dynamic code generation
The hack I used

Code as data hack
I didn't try this one.

Principle : when you have some random data, say the adress of your back buffer, you can actually put a value that represents one or severall opcodes. Then, at some point, you jump onto those opcodes. better be a jump you must do anyway, cause otherwise you'll use up two bytes for the extra jump.

It's even better if you can dynamically generate an opcode just before those data-code bytes ;)
a427
Member
Member
Posts: 40
Joined: Sun Mar 15, 2009 9:45 pm

Re: The Fourth 512-byte OS Contest!

Post by a427 »

@js: nice job !

I'm sure it can help some guys to shrink bytes and improve their 512 asm compo !

Maybe you can even participate yourself ?

What about choosing a deadline ?

Are there more people interested, or should we keep the 15th januray 2010 ?
js
Member
Member
Posts: 38
Joined: Thu Feb 26, 2009 1:45 am

Re: The Fourth 512-byte OS Contest!

Post by js »

a427 wrote:I'm sure it can help some guys to shrink bytes and improve their 512 asm compo !
That's why I posted it ;-)
a427 wrote:Maybe you can even participate yourself ?
Of course I am participating...
a427 wrote:Are there more people interested, or should we keep the 15th januray 2010 ?
I'm ok with that deadline. I discovered this thread on december 30, (when this deadline was suggested), and started coding immediately...
Cjreek
Member
Member
Posts: 70
Joined: Thu May 28, 2009 2:41 pm
Location: Germany

Re: The Fourth 512-byte OS Contest!

Post by Cjreek »

Hi,

Here's my 512 Byte OS. It's the well known game "Snake". You've to compile it with FASM. NASM will create a file which is a little bit larger than 512 bytes.
Attachments
snake.asm
The source code. Comments are only german.
(5.96 KiB) Downloaded 414 times
snake.zip
The game OS
(595 Bytes) Downloaded 306 times
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: The Fourth 512-byte OS Contest!

Post by Dex »

earlz wrote:Yea, I think I know what I'm going to do now.. I'm thinking I could make an at least partial FORTH interpreter... that would be pretty neat and the syntax is easy enough to parse in assembly(without tearing my hair out)
There was a FORTH interpreter in the first 512b compo, so it can be done.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: The Fourth 512-byte OS Contest!

Post by earlz »

Dex wrote:
earlz wrote:Yea, I think I know what I'm going to do now.. I'm thinking I could make an at least partial FORTH interpreter... that would be pretty neat and the syntax is easy enough to parse in assembly(without tearing my hair out)
There was a FORTH interpreter in the first 512b compo, so it can be done.
Was it a complete enough Forth implementation to be turing complete? Cause I'm seriously giving up if so lol
a427
Member
Member
Posts: 40
Joined: Sun Mar 15, 2009 9:45 pm

Re: The Fourth 512-byte OS Contest!

Post by a427 »

Wow, we have now quite a pretty amount of entries !

Thank you all for your enthusiasm !!

I edited the main post to list the already submitted entries, with proper links..

The deadline for the compo has been accepted as January 15th 2010 (friday)

Yet I'm not too sure how we will process the votes...

Can somebody with previous experience give some hints how to set up the votes ?
User avatar
Thomas
Member
Member
Posts: 281
Joined: Thu Jun 04, 2009 11:12 pm

Re: The Fourth 512-byte OS Contest!

Post by Thomas »

Hi,
I am in this time.But I am in the middle do lot many things :).I am not sure,whether I will be able to make it.I am writing a small speaker piano :).You press some buttons and you hear music from the pc speaker :) .

--Thomas
User avatar
XanClic
Member
Member
Posts: 138
Joined: Wed Feb 13, 2008 9:38 am

Re: The Fourth 512-byte OS Contest!

Post by XanClic »

Hi,

This is my contribution to this contest. It's an OS running in real mode which is capable of sending an ARP network packet over an RTL8139 network card. That means you can resolve IP addresses to MAC addresses in the current LAN. Once it's started, you enter your IP and the IP to be resolved. Then it'll print your MAC and (hopefully :wink:) the destination's MAC address.

You need to assemble it with FASM, maybe it also works with NASM, some adjustment and -O99.

There's a constant in the code called "Os_level". You can choose a level to reduce the size of the binary (though it's always 512 bytes if you don't remove the padding at the end). The code contains detailed explanations of all five levels. Here are the resulting sizes (with "times 510-($-$$) db 0" commented out):
Os =
  • 0: 507 bytes
  • 1: 441 bytes
  • 2: 414 bytes
  • 3: 388 bytes
  • 4: 312 bytes
PS: If you don't have an RTL8139 card available, you can test it with qemu and:

Code: Select all

qemu -fda arp.img -net user -net nic,model=rtl8139
Qemu won't care about your IP (as far as I know), though only values between 10.0.2.15 and 10.0.2.254 are in the narrow sense correct. As a destination you may try 10.0.2.2 (the gateway and DHCP server) or 10.0.2.3 (the DNS server). There should also be another server on 10.0.2.4, but I didn't find anything.
Attachments
arp.img.bz2
Compiled source code, padded to 1474560 Bytes
(622 Bytes) Downloaded 249 times
arp.bin.gz
Compiled source code (Os_level = 0)
(525 Bytes) Downloaded 253 times
arp.asm
Source code
(14.25 KiB) Downloaded 427 times
a427
Member
Member
Posts: 40
Joined: Sun Mar 15, 2009 9:45 pm

Re: The Fourth 512-byte OS Contest!

Post by a427 »

@XanClic: amazing !!!
Post Reply