flat assembler
Message board for the users of flat assembler.

Index > Windows > Quaternion Julia Sets rendering in 1020-bytes executable

Author
Thread Post new topic Reply to topic
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall 16 May 2019, 19:20
x86 assembly (using fasm of course) + GLSL.
Requires decent GPU and OpenGL 4.1 driver.
https://github.com/michal-z/1kdemo
Post 16 May 2019, 19:20
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4061
Location: vpcmpistri
bitRAKE 17 May 2019, 06:30
Thank you for including all the dependencies - makes playing with it much easier.
Code:
        xchg    ecx,eax
        jecxz   .mainLoop    
1017 bytes, compression is challenging to code for - most my other changes made it larger.

Removing the RETN instruction after [ExitProcess] drops it to 1015 bytes.
Post 17 May 2019, 06:30
View user's profile Send private message Visit poster's website Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall 17 May 2019, 13:07
bitRAKE wrote:
Thank you for including all the dependencies - makes playing with it much easier.
Code:
        xchg    ecx,eax
        jecxz   .mainLoop    
1017 bytes, compression is challenging to code for - most my other changes made it larger.

Removing the RETN instruction after [ExitProcess] drops it to 1015 bytes.


Thanks for looking at it and for the suggestions!
Post 17 May 2019, 13:07
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4061
Location: vpcmpistri
bitRAKE 18 May 2019, 00:55
Another, quite hacky method I tried:
Code:
format MS COFF

extrn '__imp__ExitProcess@4' as ExitProcess:dword
extrn '__imp__CreateWindowExA@48' as CreateWindowEx:dword
extrn '__imp__SetPixelFormat@12' as SetPixelFormat:dword
extrn '__imp__ChoosePixelFormat@8' as ChoosePixelFormat:dword
extrn '__imp__ShowCursor@4' as ShowCursor:dword
extrn '__imp__GetDC@4' as GetDC:dword
extrn '__imp__GetAsyncKeyState@4' as GetAsyncKeyState:dword
extrn '__imp__PeekMessageA@20' as PeekMessage:dword
extrn '__imp__DispatchMessageA@4' as DispatchMessage:dword
extrn '__imp__timeGetTime@0' as timeGetTime:dword
extrn '__imp__timeBeginPeriod@4' as timeBeginPeriod:dword
extrn '__imp__SwapBuffers@4' as SwapBuffers:dword
extrn '__imp__ChangeDisplaySettingsA@8' as ChangeDisplaySettings:dword
extrn '__imp__wglMakeCurrent@8' as wglMakeCurrent:dword
extrn '__imp__wglCreateContext@4' as wglCreateContext:dword
extrn '__imp__wglGetProcAddress@4' as wglGetProcAddress:dword
extrn '__imp__glRecti@16' as glRecti:dword
extrn '__imp__glTexCoord1f@4' as glTexCoord1f:dword
extrn '__imp__SetProcessDPIAware@0' as SetProcessDPIAware:dword

section '.text' code readable executable writeable

_Start:
        call __Start
        dd ScreenSettings
        dd 4                            ; CDS_FULLSCREEN

        dd 0                            ; dwExStyle
        dd S.WinClassName               ; lpClassName
        dd 0                       ; lpWindowName
        dd 91000000h               ; dwStyle = WS_POPUP|WS_VISIBLE|WS_MAXIMIZE
        dd 0                       ; x
        dd 0                       ; y
        dd 0                       ; nWidth
        dd 0                       ; nHeight
        dd 0                       ; hWndParent
        dd 0                       ; hMenu
        dd 0                       ; hInstance
        dd 0                       ; lpParam

        dd PixelFormatDesc

        dd PixelFormatDesc

        dd 0 ; for ShowCursor

        dd S.glUseProgram

        dd S.glCreateShaderProgramv

        dd 8B30h                   ; GL_FRAGMENT_SHADER
        dd 1
        dd ShaderCodePtr

        dd 1                       ; ask for 1 ms timer resolution

        rd 2
Message:
PixelFormatDesc:
    dd 0
    dd 00000021h                          ; PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER
ScreenSettings:
    db 32 dup 0
    dd 0
    dw .size
    dw 0
    dd 001C0000h                          ; DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL
    db 60 dup 0
    dd 32,1920,1080
    dd 11 dup 0
    .size = $-ScreenSettings

ShaderCodePtr dd ShaderCode
ShaderCode:
    file '1kdemo-small.glsl'
    db 0

S.WinClassName db 'edit',0
S.glCreateShaderProgramv db 'glCreateShaderProgramv',0
S.glUseProgram db 'glUseProgram',0


reg_hDC     equ ebx
reg_Prg     equ esi
reg_Time    equ edi

public _Start
__Start:
        pop esp
        call [ChangeDisplaySettings]
        call [SetProcessDPIAware]
        call [CreateWindowEx]
        push eax                        ; hwnd
        call [GetDC]
        push eax                        ; hdc
        mov reg_hDC,eax
        call [ChoosePixelFormat]
        push eax                     ; pixel format id
        push reg_hDC
        call [SetPixelFormat]
        push reg_hDC
        call [wglCreateContext]
        push eax                     ; GL context
        push reg_hDC
        call [wglMakeCurrent]
        call [ShowCursor]
        call [wglGetProcAddress]
        mov reg_Prg,eax         ; pointer to glUseProgram
        call [wglGetProcAddress]
        call eax                        ; glCreateShaderProgramv
        push eax                        ; GL program to use
        call reg_Prg                    ; glUseProgram
        call [timeBeginPeriod]
        call [timeGetTime]
        mov reg_Time,eax                ; beginTime
.mainLoop:
        push 1                  ; PM_REMOVE
        push 0
        push 0
        push 0
        push Message
        call [PeekMessage]
        call [timeGetTime]
        sub eax,reg_Time                ; currentTime = time - beginTime
        push eax
        fild dword [esp]
        fstp dword [esp]
        call [glTexCoord1f]
        push 1
        push 1
        push -1
        push -1
        call [glRecti]
        push reg_hDC
        call [SwapBuffers]
        push 27                         ; VK_ESCAPE
        call [GetAsyncKeyState]
        xchg ecx,eax
        jecxz .mainLoop
        ; no error code?
        call [ExitProcess]    
Unfortunately, the APIs use a lot of stack space, so the sections must be ordered this way to overwrite the API stub and decompression buffer of crickler. No benefit really as the compression context modeler is so good.

32-bit stack calling has so much flexibility.

I did shave some bytes off the shader, though.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 18 May 2019, 00:55
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 18 May 2019, 05:59
Very cool!
Post 18 May 2019, 05:59
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 350
Location: Poland
macgub 27 May 2019, 17:39
Nice !
@randall
If you want you may do animation posibilities: zoom +/-, rotating etc.. Like tthsqe done for Mandelbrotset 2d (see section examples of fasm site). But code of app will be bit larger... And also working in current resolution will be welcome (not all machines are full hd) . Just a few suggestions ... Anyway good luck Exclamation
Post 27 May 2019, 17:39
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.