add flat assembler toolchain

This commit is contained in:
2024-11-24 23:13:28 -05:00
parent 99e8e4072b
commit dbfd94ea40
302 changed files with 145599 additions and 0 deletions

View File

@ -0,0 +1,326 @@
; DirectDraw programming example
format PE GUI 4.0
entry start
include 'win32a.inc'
include 'ddraw.inc'
section '.text' code readable executable
start:
and [DDraw],0
and [DDSPrimary],0
and [DDSBack],0
and [DDPalette],0
and [DDSPicture],0
invoke GetModuleHandleA,NULL
mov [hinstance],eax
invoke LoadIconA,NULL,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursorA,NULL,IDC_ARROW
mov [wc.hCursor],eax
mov [wc.style],0
mov [wc.lpfnWndProc],WindowProc
mov [wc.cbClsExtra],0
mov [wc.cbWndExtra],0
mov eax,[hinstance]
mov [wc.hInstance],eax
mov [wc.hbrBackground],0
mov dword [wc.lpszMenuName],NULL
mov dword [wc.lpszClassName],_class
invoke RegisterClassA,wc
test eax,eax
jz startup_error
invoke CreateWindowExA,\
0,_class,_title,WS_POPUP+WS_VISIBLE,0,0,0,0,NULL,NULL,[hinstance],NULL
test eax,eax
jz startup_error
mov [hwnd],eax
invoke DirectDrawCreate,NULL,DDraw,NULL
or eax,eax
jnz ddraw_error
cominvk DDraw,SetCooperativeLevel,\
[hwnd],DDSCL_EXCLUSIVE+DDSCL_FULLSCREEN
or eax,eax
jnz ddraw_error
cominvk DDraw,SetDisplayMode,\
640,480,8
or eax,eax
jnz ddraw_error
mov [ddsd.dwSize],sizeof.DDSURFACEDESC
mov [ddsd.dwFlags],DDSD_CAPS+DDSD_BACKBUFFERCOUNT
mov [ddsd.ddsCaps.dwCaps],DDSCAPS_PRIMARYSURFACE+DDSCAPS_FLIP+DDSCAPS_COMPLEX
mov [ddsd.dwBackBufferCount],1
cominvk DDraw,CreateSurface,\
ddsd,DDSPrimary,NULL
or eax,eax
jnz ddraw_error
mov [ddscaps.dwCaps],DDSCAPS_BACKBUFFER
cominvk DDSPrimary,GetAttachedSurface,\
ddscaps,DDSBack
or eax,eax
jnz ddraw_error
mov esi,picture
call load_picture
jc open_error
mov esi,picture
call load_palette
jc open_error
invoke GetTickCount
mov [last_tick],eax
jmp paint
main_loop:
invoke PeekMessageA,msg,NULL,0,0,PM_NOREMOVE
or eax,eax
jz no_message
invoke GetMessageA,msg,NULL,0,0
or eax,eax
jz end_loop
invoke TranslateMessage,msg
invoke DispatchMessageA,msg
jmp main_loop
no_message:
cmp [active],0
je sleep
cominvk DDSPrimary,IsLost
or eax,eax
jz paint
cmp eax,DDERR_SURFACELOST
jne end_loop
cominvk DDSPrimary,Restore
paint:
mov [rect.top],0
mov [rect.bottom],480
mov [rect.left],0
mov [rect.right],640
cominvk DDSBack,BltFast,\
0,0,[DDSPicture],rect,DDBLTFAST_SRCCOLORKEY
or eax,eax
jnz paint_done
movzx eax,[frame]
xor edx,edx
mov ebx,10
div ebx
sal eax,6
add eax,480
mov [rect.top],eax
add eax,64
mov [rect.bottom],eax
sal edx,6
mov [rect.left],edx
add edx,64
mov [rect.right],edx
cominvk DDSBack,BltFast,\
[x],[y],[DDSPicture],rect,DDBLTFAST_SRCCOLORKEY
cominvk DDSPrimary,SetPalette,[DDPalette]
cominvk DDSPrimary,Flip,0,0
paint_done:
invoke GetTickCount
mov ebx,eax
sub ebx,[last_tick]
cmp ebx,20
jb main_loop
add [last_tick],20
inc [frame]
cmp [frame],60
jb main_loop
mov [frame],0
jmp main_loop
sleep:
invoke WaitMessage
jmp main_loop
ddraw_error:
mov eax,_ddraw_error
jmp error
open_error:
mov eax,_open_error
error:
invoke MessageBoxA,[hwnd],eax,_error,MB_OK+MB_ICONERROR
invoke DestroyWindow,[hwnd]
invoke PostQuitMessage,1
jmp main_loop
startup_error:
invoke MessageBoxA,[hwnd],_startup_error,_error,MB_OK+MB_ICONERROR
end_loop:
cmp [DDSPicture],0
je picture_released
cominvk DDSPicture,Release
picture_released:
cmp [DDPalette],0
je palette_released
cominvk DDPalette,Release
palette_released:
cmp [DDSBack],0
je back_surface_released
cominvk DDSPrimary,DeleteAttachedSurface,0,DDSBack
back_surface_released:
cmp [DDSPrimary],0
je primary_surface_released
cominvk DDSPrimary,Release
primary_surface_released:
cmp [DDraw],0
je ddraw_released
cominvk DDraw,Release
ddraw_released:
invoke ExitProcess,[msg.wParam]
include 'gif87a.inc'
proc WindowProc hwnd,wmsg,wparam,lparam
push ebx esi edi
mov eax,[wmsg]
cmp eax,WM_CREATE
je .wmcreate
cmp eax,WM_DESTROY
je .wmdestroy
cmp eax,WM_ACTIVATE
je .wmactivate
cmp eax,WM_SETCURSOR
je .wmsetcursor
cmp eax,WM_MOUSEMOVE
je .wmmousemove
cmp eax,WM_KEYDOWN
je .wmkeydown
.defwindowproc:
invoke DefWindowProcA,[hwnd],[wmsg],[wparam],[lparam]
jmp .finish
.wmcreate:
xor eax,eax
jmp .finish
.wmkeydown:
cmp [wparam],VK_ESCAPE
jne .finish
.wmdestroy:
cominvk DDraw,RestoreDisplayMode
invoke PostQuitMessage,0
xor eax,eax
jmp .finish
.wmactivate:
mov eax,[wparam]
mov [active],al
jmp .finish
.wmsetcursor:
invoke SetCursor,0
xor eax,eax
jmp .finish
.wmmousemove:
movsx eax,word [lparam]
mov [x],eax
movsx eax,word [lparam+2]
mov [y],eax
.finish:
pop edi esi ebx
ret
endp
section '.data' data readable writeable
_title db 'flat assembler DirectDraw application',0
_class db 'FDDRAW32',0
_error db 'Error',0
_startup_error db 'Startup failed.',0
_ddraw_error db 'Direct Draw initialization failed.',0
_open_error db 'Failed opening data file.',0
picture db 'DDRAW.GIF',0
section '.bss' readable writeable
hinstance dd ?
hwnd dd ?
wc WNDCLASS
msg MSG
ddsd DDSURFACEDESC
ddscaps DDSCAPS
DDraw DirectDraw
DDSPrimary DirectDrawSurface
DDSBack DirectDrawSurface
DDSPicture DirectDrawSurface
DDPalette DirectDrawPalette
bytes_count dd ?
last_tick dd ?
frame db ?
active db ?
LZW_bits db ?
LZW_table rd (0F00h-2)*2
buffer rb 40000h
rect RECT
x dd ?
y dd ?
section '.idata' import data readable
library kernel,'KERNEL32.DLL',\
user,'USER32.DLL',\
ddraw,'DDRAW.DLL'
import kernel,\
GetModuleHandleA,'GetModuleHandleA',\
CreateFileA,'CreateFileA',\
ReadFile,'ReadFile',\
CloseHandle,'CloseHandle',\
GetTickCount,'GetTickCount',\
ExitProcess,'ExitProcess'
import user,\
RegisterClassA,'RegisterClassA',\
CreateWindowExA,'CreateWindowExA',\
DestroyWindow,'DestroyWindow',\
DefWindowProcA,'DefWindowProcA',\
GetMessageA,'GetMessageA',\
PeekMessageA,'PeekMessageA',\
TranslateMessage,'TranslateMessage',\
DispatchMessageA,'DispatchMessageA',\
LoadCursorA,'LoadCursorA',\
LoadIconA,'LoadIconA',\
SetCursor,'SetCursor',\
MessageBoxA,'MessageBoxA',\
PostQuitMessage,'PostQuitMessage',\
WaitMessage,'WaitMessage'
import ddraw,\
DirectDrawCreate,'DirectDrawCreate'

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

View File

@ -0,0 +1,424 @@
; DirectDraw interface
interface DirectDraw,\
QueryInterface,\
AddRef,\
Release,\
Compact,\
CreateClipper,\
CreatePalette,\
CreateSurface,\
DuplicateSurface,\
EnumDisplayModes,\
EnumSurfaces,\
FlipToGDISurface,\
GetCaps,\
GetDisplayMode,\
GetFourCCCodes,\
GetGDISurface,\
GetMonitorFrequency,\
GetScanLine,\
GetVerticalBlankStatus,\
Initialize,\
RestoreDisplayMode,\
SetCooperativeLevel,\
SetDisplayMode,\
WaitForVerticalBlank,\
GetAvailableVidMem,\
GetSurfaceFromDC,\
RestoreAllSurfaces,\
TestCooperativeLevel,\
GetDeviceIdentifier,\
StartModeTest,\
EvaluateMode
interface DirectDrawSurface,\
QueryInterface,\
AddRef,\
Release,\
AddAttachedSurface,\
AddOverlayDirtyRect,\
Blt,\
BltBatch,\
BltFast,\
DeleteAttachedSurface,\
EnumAttachedSurfaces,\
EnumOverlayZOrders,\
Flip,\
GetAttachedSurface,\
GetBltStatus,\
GetCaps,\
GetClipper,\
GetColorKey,\
GetDC,\
GetFlipStatus,\
GetOverlayPosition,\
GetPalette,\
GetPixelFormat,\
GetSurfaceDesc,\
Initialize,\
IsLost,\
Lock,\
ReleaseDC,\
Restore,\
SetClipper,\
SetColorKey,\
SetOverlayPosition,\
SetPalette,\
Unlock,\
UpdateOverlay,\
UpdateOverlayDisplay,\
UpdateOverlayZOrder,\
GetDDInterface,\
PageLock,\
PageUnlock,\
SetSurfaceDesc,\
SetPrivateData,\
GetPrivateData,\
FreePrivateData,\
GetUniquenessValue,\
ChangeUniquenessValue,\
SetPriority,\
GetPriority,\
SetLOD,\
GetLOD
interface DirectDrawPalette,\
QueryInterface,\
AddRef,\
Release,\
GetCaps,\
GetEntries,\
Initialize,\
SetEntries
interface DirectDrawClipper,\
QueryInterface,\
AddRef,\
Release,\
GetClipList,\
GetHWnd,\
Initialize,\
IsClipListChanged,\
SetClipList,\
SetHWnd
interface DirectDrawColorControl,\
QueryInterface,\
AddRef,\
Release,\
GetColorControls,\
SetColorControls
interface DirectDrawGammaControl,\
QueryInterface,\
AddRef,\
Release,\
GetGammaRamp,\
SetGammaRamp
struct DDCOLORKEY
dwColorSpaceLowValue dd ?
dwColorSpaceHighValue dd ?
ends
struct DDPIXELFORMAT
dwSize dd ?
dwFlags dd ?
dwFourCC dd ?
union
dwRGBBitCount dd ?
dwYUVBitCount dd ?
dwZBufferBitDepth dd ?
dwAlphaBitDepth dd ?
dwLuminanceBitCount dd ?
dwBumpBitCount dd ?
ends
union
dwRBitMask dd ?
dwYBitMask dd ?
dwStencilBitDepth dd ?
dwLuminanceBitMask dd ?
dwBumpDuBitMask dd ?
ends
union
dwGBitMask dd ?
dwUBitMask dd ?
dwZBitMask dd ?
dwBumpDvBitMask dd ?
ends
union
dwBBitMask dd ?
dwVBitMask dd ?
dwStencilBitMask dd ?
dwBumpLuminanceBitMask dd ?
ends
union
dwRGBAlphaBitMask dd ?
dwYUVAlphaBitMask dd ?
dwLuminanceAlphaBitMask dd ?
dwRGBZBitMask dd ?
dwYUVZBitMask dd ?
ends
ends
struct DDSCAPS
dwCaps dd ?
ends
struct DDSURFACEDESC
dwSize dd ?
dwFlags dd ?
dwHeight dd ?
dwWidth dd ?
union
lPitch dd ?
dwLinearSize dd ?
ends
dwBackBufferCount dd ?
union
dwMipMapCount dd ?
dwZBufferBitDepth dd ?
dwRefreshRate dd ?
ends
dwAlphaBitDepth dd ?
dwReserved dd ?
lpSurface dd ?
ddckCKDestOverlay DDCOLORKEY
ddckCKDestBlt DDCOLORKEY
ddckCKSrcOverlay DDCOLORKEY
ddckCKSrcBlt DDCOLORKEY
ddpfPixelFormat DDPIXELFORMAT
ddsCaps DDSCAPS
ends
; SetCooperativeLevel flags
DDSCL_FULLSCREEN = 000000001h
DDSCL_ALLOWREBOOT = 000000002h
DDSCL_NOWINDOWCHANGES = 000000004h
DDSCL_NORMAL = 000000008h
DDSCL_EXCLUSIVE = 000000010h
DDSCL_ALLOWMODEX = 000000040h
; Blt flags
DDBLT_ALPHADEST = 000000001h
DDBLT_ALPHADESTCONSTOVERRIDE = 000000002h
DDBLT_ALPHADESTNEG = 000000004h
DDBLT_ALPHADESTSURFACEOVERRIDE = 000000008h
DDBLT_ALPHAEDGEBLEND = 000000010h
DDBLT_ALPHASRC = 000000020h
DDBLT_ALPHASRCCONSTOVERRIDE = 000000040h
DDBLT_ALPHASRCNEG = 000000080h
DDBLT_ALPHASRCSURFACEOVERRIDE = 000000100h
DDBLT_ASYNC = 000000200h
DDBLT_COLORFILL = 000000400h
DDBLT_DDFX = 000000800h
DDBLT_DDROPS = 000001000h
DDBLT_KEYDEST = 000002000h
DDBLT_KEYDESTOVERRIDE = 000004000h
DDBLT_KEYSRC = 000008000h
DDBLT_KEYSRCOVERRIDE = 000010000h
DDBLT_ROP = 000020000h
DDBLT_ROTATIONANGLE = 000040000h
DDBLT_ZBUFFER = 000080000h
DDBLT_ZBUFFERDESTCONSTOVERRIDE = 000100000h
DDBLT_ZBUFFERDESTOVERRIDE = 000200000h
DDBLT_ZBUFFERSRCCONSTOVERRIDE = 000400000h
DDBLT_ZBUFFERSRCOVERRIDE = 000800000h
DDBLT_WAIT = 001000000h
DDBLT_DEPTHFILL = 002000000h
; BltFast flags
DDBLTFAST_NOCOLORKEY = 000000000h
DDBLTFAST_SRCCOLORKEY = 000000001h
DDBLTFAST_DESTCOLORKEY = 000000002h
DDBLTFAST_WAIT = 000000010h
; Flip flags
DDFLIP_WAIT = 000000001h
DDFLIP_EVEN = 000000002h
DDFLIP_ODD = 000000004h
; DDSURFACEDESC field flags
DDSD_CAPS = 000000001h
DDSD_HEIGHT = 000000002h
DDSD_WIDTH = 000000004h
DDSD_PITCH = 000000008h
DDSD_BACKBUFFERCOUNT = 000000020h
DDSD_ZBUFFERBITDEPTH = 000000040h
DDSD_ALPHABITDEPTH = 000000080h
DDSD_LPSURFACE = 000000800h
DDSD_PIXELFORMAT = 000001000h
DDSD_CKDESTOVERLAY = 000002000h
DDSD_CKDESTBLT = 000004000h
DDSD_CKSRCOVERLAY = 000008000h
DDSD_CKSRCBLT = 000010000h
DDSD_MIPMAPCOUNT = 000020000h
DDSD_REFRESHRATE = 000040000h
DDSD_LINEARSIZE = 000080000h
DDSD_ALL = 0000FF9EEh
; DirectDrawSurface capability flags
DDSCAPS_RESERVED1 = 000000001h
DDSCAPS_ALPHA = 000000002h
DDSCAPS_BACKBUFFER = 000000004h
DDSCAPS_COMPLEX = 000000008h
DDSCAPS_FLIP = 000000010h
DDSCAPS_FRONTBUFFER = 000000020h
DDSCAPS_OFFSCREENPLAIN = 000000040h
DDSCAPS_OVERLAY = 000000080h
DDSCAPS_PALETTE = 000000100h
DDSCAPS_PRIMARYSURFACE = 000000200h
DDSCAPS_PRIMARYSURFACELEFT = 000000400h
DDSCAPS_SYSTEMMEMORY = 000000800h
DDSCAPS_TEXTURE = 000001000h
DDSCAPS_3DDEVICE = 000002000h
DDSCAPS_VIDEOMEMORY = 000004000h
DDSCAPS_VISIBLE = 000008000h
DDSCAPS_WRITEONLY = 000010000h
DDSCAPS_ZBUFFER = 000020000h
DDSCAPS_OWNDC = 000040000h
DDSCAPS_LIVEVIDEO = 000080000h
DDSCAPS_HWCODEC = 000100000h
DDSCAPS_MODEX = 000200000h
DDSCAPS_MIPMAP = 000400000h
DDSCAPS_RESERVED2 = 000800000h
DDSCAPS_ALLOCONLOAD = 004000000h
DDSCAPS_VIDEOPORT = 008000000h
DDSCAPS_LOCALVIDMEM = 010000000h
DDSCAPS_NONLOCALVIDMEM = 020000000h
DDSCAPS_STANDARDVGAMODE = 040000000h
DDSCAPS_OPTIMIZED = 080000000h
; DirectDrawSurface lock flags
DDLOCK_SURFACEMEMORYPTR = 000000000h
DDLOCK_WAIT = 000000001h
DDLOCK_EVENT = 000000002h
DDLOCK_READONLY = 000000010h
DDLOCK_WRITEONLY = 000000020h
DDLOCK_NOSYSLOCK = 000000800h
; DirectDrawPalette capabilities
DDPCAPS_4BIT = 000000001h
DDPCAPS_8BITENTRIES = 000000002h
DDPCAPS_8BIT = 000000004h
DDPCAPS_INITIALIZE = 000000008h
DDPCAPS_PRIMARYSURFACE = 000000010h
DDPCAPS_PRIMARYSURFACELEFT = 000000020h
DDPCAPS_ALLOW256 = 000000040h
DDPCAPS_VSYNC = 000000080h
DDPCAPS_1BIT = 000000100h
DDPCAPS_2BIT = 000000200h
; DirectDraw errors
DDERR_ALREADYINITIALIZED = 088760000h+5
DDERR_CANNOTATTACHSURFACE = 088760000h+10
DDERR_CANNOTDETACHSURFACE = 088760000h+20
DDERR_CURRENTLYNOTAVAIL = 088760000h+40
DDERR_EXCEPTION = 088760000h+55
DDERR_HEIGHTALIGN = 088760000h+90
DDERR_INCOMPATIBLEPRIMARY = 088760000h+95
DDERR_INVALIDCAPS = 088760000h+100
DDERR_INVALIDCLIPLIST = 088760000h+110
DDERR_INVALIDMODE = 088760000h+120
DDERR_INVALIDOBJECT = 088760000h+130
DDERR_INVALIDPIXELFORMAT = 088760000h+145
DDERR_INVALIDRECT = 088760000h+150
DDERR_LOCKEDSURFACES = 088760000h+160
DDERR_NO3D = 088760000h+170
DDERR_NOALPHAHW = 088760000h+180
DDERR_NOCLIPLIST = 088760000h+205
DDERR_NOCOLORCONVHW = 088760000h+210
DDERR_NOCOOPERATIVELEVELSET = 088760000h+212
DDERR_NOCOLORKEY = 088760000h+215
DDERR_NOCOLORKEYHW = 088760000h+220
DDERR_NODIRECTDRAWSUPPORT = 088760000h+222
DDERR_NOEXCLUSIVEMODE = 088760000h+225
DDERR_NOFLIPHW = 088760000h+230
DDERR_NOGDI = 088760000h+240
DDERR_NOMIRRORHW = 088760000h+250
DDERR_NOTFOUND = 088760000h+255
DDERR_NOOVERLAYHW = 088760000h+260
DDERR_NORASTEROPHW = 088760000h+280
DDERR_NOROTATIONHW = 088760000h+290
DDERR_NOSTRETCHHW = 088760000h+310
DDERR_NOT4BITCOLOR = 088760000h+316
DDERR_NOT4BITCOLORINDEX = 088760000h+317
DDERR_NOT8BITCOLOR = 088760000h+320
DDERR_NOTEXTUREHW = 088760000h+330
DDERR_NOVSYNCHW = 088760000h+335
DDERR_NOZBUFFERHW = 088760000h+340
DDERR_NOZOVERLAYHW = 088760000h+350
DDERR_OUTOFCAPS = 088760000h+360
DDERR_OUTOFVIDEOMEMORY = 088760000h+380
DDERR_OVERLAYCANTCLIP = 088760000h+382
DDERR_OVERLAYCOLORKEYONLYONEACTI = 088760000h+384
DDERR_PALETTEBUSY = 088760000h+387
DDERR_COLORKEYNOTSET = 088760000h+400
DDERR_SURFACEALREADYATTACHED = 088760000h+410
DDERR_SURFACEALREADYDEPENDENT = 088760000h+420
DDERR_SURFACEBUSY = 088760000h+430
DDERR_CANTLOCKSURFACE = 088760000h+435
DDERR_SURFACEISOBSCURED = 088760000h+440
DDERR_SURFACELOST = 088760000h+450
DDERR_SURFACENOTATTACHED = 088760000h+460
DDERR_TOOBIGHEIGHT = 088760000h+470
DDERR_TOOBIGSIZE = 088760000h+480
DDERR_TOOBIGWIDTH = 088760000h+490
DDERR_UNSUPPORTEDFORMAT = 088760000h+510
DDERR_UNSUPPORTEDMASK = 088760000h+520
DDERR_VERTICALBLANKINPROGRESS = 088760000h+537
DDERR_WASSTILLDRAWING = 088760000h+540
DDERR_XALIGN = 088760000h+560
DDERR_INVALIDDIRECTDRAWGUID = 088760000h+561
DDERR_DIRECTDRAWALREADYCREATED = 088760000h+562
DDERR_NODIRECTDRAWHW = 088760000h+563
DDERR_PRIMARYSURFACEALREADYEXIST = 088760000h+564
DDERR_NOEMULATION = 088760000h+565
DDERR_REGIONTOOSMALL = 088760000h+566
DDERR_CLIPPERISUSINGHWND = 088760000h+567
DDERR_NOCLIPPERATTACHED = 088760000h+568
DDERR_NOHWND = 088760000h+569
DDERR_HWNDSUBCLASSED = 088760000h+570
DDERR_HWNDALREADYSET = 088760000h+571
DDERR_NOPALETTEATTACHED = 088760000h+572
DDERR_NOPALETTEHW = 088760000h+573
DDERR_BLTFASTCANTCLIP = 088760000h+574
DDERR_NOBLTHW = 088760000h+575
DDERR_NODDROPSHW = 088760000h+576
DDERR_OVERLAYNOTVISIBLE = 088760000h+577
DDERR_NOOVERLAYDEST = 088760000h+578
DDERR_INVALIDPOSITION = 088760000h+579
DDERR_NOTAOVERLAYSURFACE = 088760000h+580
DDERR_EXCLUSIVEMODEALREADYSET = 088760000h+581
DDERR_NOTFLIPPABLE = 088760000h+582
DDERR_CANTDUPLICATE = 088760000h+583
DDERR_NOTLOCKED = 088760000h+584
DDERR_CANTCREATEDC = 088760000h+585
DDERR_NODC = 088760000h+586
DDERR_WRONGMODE = 088760000h+587
DDERR_IMPLICITLYCREATED = 088760000h+588
DDERR_NOTPALETTIZED = 088760000h+589
DDERR_UNSUPPORTEDMODE = 088760000h+590
DDERR_NOMIPMAPHW = 088760000h+591
DDERR_INVALIDSURFACETYPE = 088760000h+592
DDERR_NOOPTIMIZEHW = 088760000h+600
DDERR_NOTLOADED = 088760000h+601
DDERR_DCALREADYCREATED = 088760000h+620
DDERR_NONONLOCALVIDMEM = 088760000h+630
DDERR_CANTPAGELOCK = 088760000h+640
DDERR_CANTPAGEUNLOCK = 088760000h+660
DDERR_NOTPAGELOCKED = 088760000h+680
DDERR_MOREDATA = 088760000h+690
DDERR_VIDEONOTACTIVE = 088760000h+695
DDERR_DEVICEDOESNTOWNSURFACE = 088760000h+699

View File

@ -0,0 +1,196 @@
virtual at buffer
GIFHEADER:
.ID dd ?
.ver dw ?
.width dw ?
.height dw ?
.bits db ?
.background db ?
.reserved db ?
.length = $ - GIFHEADER
end virtual
load_picture:
invoke CreateFileA,esi,GENERIC_READ,0,0,OPEN_EXISTING,0,0
mov edi,eax
invoke ReadFile,edi,GIFHEADER,40000h,bytes_count,0
invoke CloseHandle,edi
cmp [GIFHEADER.ID],'GIF8'
jne picture_error
cmp [GIFHEADER.ver],'7a'
jne picture_error
mov al,[GIFHEADER.bits]
and al,10000111b
cmp al,10000111b
jne picture_error
add [bytes_count],buffer
mov esi,buffer+GIFHEADER.length+256*3
mov edi,esi
xor eax,eax
find_image:
cmp esi,[bytes_count]
jae picture_error
lodsb
cmp al,','
je image_found
cmp al,'!'
jne picture_error
inc esi
skip_application_data:
lodsb
add esi,eax
or al,al
jnz skip_application_data
jmp find_image
image_found:
add esi,4
xor eax,eax
lodsw
mov ebx,eax
lodsw
inc esi
cmp byte [esi],8
jne picture_error
inc esi
mov [ddsd.dwSize],sizeof.DDSURFACEDESC
mov [ddsd.dwFlags],DDSD_CAPS+DDSD_WIDTH+DDSD_HEIGHT+DDSD_CKSRCBLT
mov [ddsd.ddsCaps.dwCaps],DDSCAPS_OFFSCREENPLAIN+DDSCAPS_SYSTEMMEMORY
mov [ddsd.dwWidth],ebx
mov [ddsd.dwHeight],eax
movzx eax,[GIFHEADER.background]
mov [ddsd.ddckCKSrcBlt.dwColorSpaceLowValue],eax
mov [ddsd.ddckCKSrcBlt.dwColorSpaceHighValue],eax
cominvk DDraw,CreateSurface,\
ddsd,DDSPicture,0
or eax,eax
jnz picture_error
cominvk DDSPicture,Lock,\
0,ddsd,DDLOCK_WAIT,0
mov edi,[ddsd.lpSurface]
mov ebx,esi
movzx ebp,byte [ebx]
inc ebx
add ebp,ebx
mov [LZW_bits],0
LZW_clear:
xor edx,edx
LZW_decompress_loop:
mov ch,9
cmp edx,(100h-2)*8
jbe LZW_read_bits
mov ch,10
cmp edx,(300h-2)*8
jbe LZW_read_bits
mov ch,11
cmp edx,(700h-2)*8
jbe LZW_read_bits
mov ch,12
LZW_read_bits:
mov cl,8
sub cl,[LZW_bits]
LZW_byte_from_stream:
mov al,[ebx]
cmp ebx,ebp
jne LZW_bits_from_byte
movzx ebp,al
inc ebx
mov al,[ebx]
add ebp,ebx
LZW_bits_from_byte:
inc ebx
ror eax,8
sub cl,ch
jz LZW_bits_ready
ja LZW_bits_with_tail
add cl,ch
add cl,8
jmp LZW_byte_from_stream
LZW_bits_with_tail:
dec ebx
shl eax,cl
LZW_bits_ready:
neg cl
and cl,7
mov [LZW_bits],cl
mov cl,ch
rol eax,cl
and eax,0FFFh
cmp eax,100h
jb LZW_single_byte
je LZW_clear
sub eax,102h
jc LZW_end
shl eax,3
cmp eax,edx
ja picture_error
mov ecx,[LZW_table+eax]
mov esi,[LZW_table+eax+4]
mov [LZW_table+edx+4],edi
rep movsb
mov eax,[LZW_table+eax]
inc eax
mov [LZW_table+edx],eax
jmp LZW_decompress_next
LZW_single_byte:
mov [LZW_table+edx],2
mov [LZW_table+edx+4],edi
stosb
LZW_decompress_next:
add edx,8
jmp LZW_decompress_loop
LZW_end:
cominvk DDSPicture,Unlock,0
mov eax,[DDSPicture]
clc
ret
picture_error:
stc
ret
load_palette:
invoke CreateFileA,esi,GENERIC_READ,0,0,OPEN_EXISTING,0,0
mov edi,eax
invoke ReadFile,edi,buffer,GIFHEADER.length+256*3,bytes_count,0
cmp [bytes_count],GIFHEADER.length+256*3
jne picture_error
invoke CloseHandle,edi
cmp [GIFHEADER.ID],'GIF8'
jne picture_error
cmp [GIFHEADER.ver],'7a'
jne picture_error
mov al,[GIFHEADER.bits]
and al,111b
cmp al,111b
jne picture_error
mov esi,buffer+GIFHEADER.length
mov edi,buffer+400h
mov ecx,256
convert_palette:
movsw
movsb
xor al,al
stosb
loop convert_palette
cominvk DDraw,CreatePalette,\
DDPCAPS_8BIT+DDPCAPS_ALLOW256,buffer+400h,DDPalette,0
or eax,eax
jnz picture_error
clc
ret