Author Topic: 32 byte  (Read 16823 times)

0 Members and 1 Guest are viewing this topic.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
32 byte
« on: September 24, 2007 »
Just trying to see if I can do anything with 32 bytes and have this so far:

Code: [Select]
org  100h
mov  al,13h
int  10h
mov ax,0a000h
mov ds,ax

draw_loop:
                mov bx,cx
                mov [bx],dl

add dl,bh ;version 1

                or bl,bh

;add dl,bl ;version 2


                mov [bx],dh

        loop draw_loop

        inc dx

        in al,60h
        dec al
        jnz draw_loop

mov ah,4ch
int 21h           

anyone else come up with anything?

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: 32 byte
« Reply #1 on: September 24, 2007 »
32 bytes?!

Yeah, easy I think...

*twiddles fasm for about an hour*

Code: [Select]
;-------------------------------------------------------------------------------------------
; 32 bytes?!
;
; A red screen by Shockwave!! Wow! I am so sad!!!!
;
;-------------------------------------------------------------------------------------------

        org  100h
        mov  ax,13h
        int  10h
        push 0a000h
        pop es
main:
        xor di,di
        mov cx,64000
loopy:
        mov byte [es:di],4
        inc di
loop loopy
        in al,60h
        dec al
        jnz main
        mov ax, 4c00h
        int 21h
         

Well it assembles to 32 bytes with fasm.... Unfortunately it just draws a red screen :)

I need more practice!         
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 32 byte
« Reply #2 on: September 24, 2007 »
Quote
*twiddles fasm for about an hour*

I think we share the same technique.

came up with 2 things though and put them together. And you've just saved me a byte!

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: 32 byte
« Reply #3 on: September 24, 2007 »
Congratulations on saving the byte! I struggled for ages just trying to get something to fit into 32bytes!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 32 byte
« Reply #4 on: September 24, 2007 »
how you can save a couple of bytes too:

Code: [Select]
org  100h
mov  al,13h   ;load into al (a bit dirty as it assumes ah is clear)
int  10h

push 0a000h   ;cheers shockwave, saved me a byte here
pop ds

draw_loop:
                mov bx,cx
              mov [bx],dl

;add dl,bh ;version 1

                or bl,bh

add dl,bl ;version 2


                mov [bx],dh

        loop draw_loop

        inc dx

        in al,60h
        dec al
        jnz draw_loop

mov ah,4ch ;al is clear since it's the exit condition so only need to load into ah
int 21h               

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: 32 byte
« Reply #5 on: September 24, 2007 »
Hehe, what are you going to do with those 3 bytes?!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 32 byte
« Reply #6 on: September 24, 2007 »
I was already doing that so still at 31 bytes atm :(

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: 32 byte
« Reply #7 on: September 24, 2007 »
Well, this is 23 bytes but you will have to alt+tab out of it.

This is accepted practice in 32 byte intros though :)

Code: [Select]
org  100h
mov  al,13h   ;load into al (a bit dirty as it assumes ah is clear)
int  10h

push 0a000h   ;cheers shockwave, saved me a byte here
pop ds

draw_loop:
                mov bx,cx
              mov [bx],dl

add dl,bh ;version 1

                or bl,bh




                mov [bx],dh

        loop draw_loop

        inc dx

jmp draw_loop         
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 32 byte
« Reply #8 on: September 24, 2007 »
Ah right, thanks. Had thought about that but didn't know it was acceptable.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: 32 byte
« Reply #9 on: September 24, 2007 »
Accepted but you get more respect for including escape checks :D
I got TV static in 20b
Code: [Select]
org 100h

init:les  si,[bx]   ; ES = 0A000h [video buffer]
     mov  al,13h    ; 320 x 200 pixels 256 colours
     int  10h

main:xchg ax,di     ; draw to random pixels in the buffer
     xor  ax,cx     ; play around with the value
     xchg al,ah     ; randomise buffer access
     stosb          ; write pixel to buffer
     loop main

exit:in   ax,60h    ; get keyboard state
     dec  ax        ; try to set value to zero
     jnz  main      ; was it esc key?
     ret            ; if so exit

oh and guys drop this :
Code: [Select]
mov ah,4ch
int 21h
and use this instead :
Code: [Select]
ret

Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 32 byte
« Reply #10 on: September 24, 2007 »
Nice one rain_storm, I can use LDS si,[bx] too and now down to 26 bytes.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: 32 byte
« Reply #11 on: September 24, 2007 »
Exactly since the contents of [bx] is 0A000h at least with modern versions of DOS I wonder what else can be done to bring down the size

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 32 byte
« Reply #12 on: September 24, 2007 »
Here's a an except from the Hugi size coding competition rules about startup registers.  I really respect this competition and they know what they're talking about.
Quote
You may assume that
  ... the registers have these values (all in hex):
      (xx - means an unknown value which MUST NOT be assumed)

          EAX = xxxx****
                AL = 00 if first FCB has valid drive letter,  FF if not
                AH = 00 if second FCB has valid drive letter, FF if not
          EBX = xxxx****
                BL = 00 if first FCB has valid drive letter,  FF if not
                BH = 00 if second FCB has valid drive letter, FF if not
          ECX = xxxx00FF
          EDX = xxxxxxxx
  DX  = CS = DS = ES = SS = xxxx, 0080 <= DX <=9000.
          ESI = xxxx0100
          EDI = xxxxFFFE
          EBP = xxxx09xx
          ESP = xxxxFFFE
          EIP = xxxx0100

  EFLAGS (binary) = xxxxxxxx xxxxxxxx xxxxx01x xx0x0x1x
      i.e.
          DF = 0
          IF = 1
          other flags = x

          WORD [FFFE] = 0000
          Layout of PSP: see [Memory Layout]

  ... that the program is not loaded high.
  ... that DPMI services are available.
  ... FCB functions can be used to access files whose name is given in 8.3
      format.

You must NOT assume that
  ... the  FPU  state is  defined;  you have to use  FINIT  to  initialize it
      before using it.
http://www.hugi.scene.org/compo/

Not sure about the FCB stuff - I think that means that both AX and BX will == 0.

Jim
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 32 byte
« Reply #13 on: September 24, 2007 »
Cool Jim, thanks.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: 32 byte
« Reply #14 on: September 24, 2007 »
Thats useful information thanks Jim
I dont think I will be putting much faith in unitialised registers anymore

Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: 32 byte
« Reply #15 on: September 25, 2007 »
Here's a simple xor texture in 30 bytes, it could be smaller I guess  :)


Code: [Select]
;---------------------------------------------------------------
;
;      Simple XOR texture - by rbraz 2007
;
;---------------------------------------------------------------

org 0x100

mov al,0x13
int 0x10

push 0xa000
pop es

Main:

mov dx, 199
y:
mov cx, 320
x:
mov ax, dx
xor ax, cx
stosb
loop x
dec dx
jnz y

key:
 in   ax,0x60
 dec  ax
 jnz  key

ret
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: 32 byte
« Reply #16 on: September 25, 2007 »
Nice static Rainstorm, and cheers Rbraz for the Xor!
Taking Rain storms tip I had a little bit more space so made this..


It doesn't look like anything though! Just a corrupted moving thing.

Code: [Select]
;-------------------------------------------------------------------------------------------
; 32 bytes.
;
; Fucked up effect by Shockwave!! Wow! I am so sad!!!!
;
;-------------------------------------------------------------------------------------------

        org  100h
        mov  ax,13h
        int  10h
        push 0a000h
        pop es
main:
        xor di,di
        mov cx,64000
loopy:

        mov byte [es:di],al

        inc di
        xchg ax,di
        inc ah
        xchg al,ah

loop loopy
        in al,60h
        dec al
        jnz main
        ret 
Shockwave ^ Codigos
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: 32 byte
« Reply #17 on: September 25, 2007 »
Nice one but there is still some more bytes to come off that
Code: [Select]
mov ax,13h
that requires 2 bytes to hold the value 0013h since its a dword but 13h will fit into 1 byte
assuming AH = 00 this is 1 byte smaller but still does the same job
Code: [Select]
mov al,13h

Now I managed to get a lot of triangles drawn in just 21 bytes I think I will expand apon this one 11 bytes is plenty of room to dress it up a bit

Code: [Select]
org  100h
les  si,[bx]
mov  al,13h
int  10h

main:xchg ax,di
     stosb
     xor  ax,cx
     and  al,ah
     loop main

exit:in   al,60h
     dec  al
     jnz  main
     ret


Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 32 byte
« Reply #18 on: September 25, 2007 »
Managed to mask the background colour and have the triangle thing moving (slowly)

Code: [Select]
org  100h
mov al,13h
int 10h
lds  si,[bx]
draw_loop:
                mov bx,cx     ;copy background pixel address, going to be altered later for foreground pixel address
                mov ax,dx     ;copy background colour value
                and al,080h    ;mask background colour value
                mov [bx], al  ;plot background pixel

                add dl,bh     ;alter colour value for next background pixel

                or bl,bh      ;alter pixel address for foreground
                add bl,dh     ;scroll the foreground   add bx,ax   /   add bl,dh

                mov [bx],bh   ;plot foreground pixel

        loop draw_loop

        inc dx    ;adjust for background colour cycling and for foreground scrolling

        in al,60h
        dec al
        jnz draw_loop
ret           
« Last Edit: September 25, 2007 by Stonemonkey »

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: 32 byte
« Reply #19 on: September 25, 2007 »
That looks sweet the lower tris almost look like reflections in water :D good work getting those two effects working side by side

I put in a v-sync and cycle through the colours my last 32b is almost complete but I think Im gonna have to cut out the escape check to fit in some more

Edit :
preaty much done with this its got better colours which scroll instead of cycle but it came ot the cost of the esc check
Code: [Select]
     org  100h

init:les  si,[bx]  ; ES = 0A000h [video buffer]
     mov  dx,03DAh ; DX = v-sync port address
     mov  al,13h
     int  10h

main:in   al,dx    ; wait for vertical
     test al,8     ; retrace
     jz   main

draw:and  al,bh    ; this piece of code ...
     xchg ah,al    ; ... scrolls the colour

     xor  ax,cx    ; this piece of code ...
     and  al,ah    ; ......................
     xchg ax,di    ; ......................
     add  al,bl    ; ... generates the tris

     stosb
     loop draw
     inc  bx       ; seed the colour value
     jmp  main
« Last Edit: September 25, 2007 by rain_storm »

Challenge Trophies Won: