📄 cwlib.inc
字号:
;------------------------------------------------------------------------------
;Some simple macro's to let us use either "model small" or "near" with MASM or
;TASM.
;------------------------------------------------------------------------------
ifdef TASM ;declare the memory model if it's
locals @@ ;needed at this point.
jumps
else
option oldstructs
option proc:private
endif
.386
.model small
scode macro
.code
endm
sdata macro
.data
endm
efile macro
endm
extdef macro var ;Declare a variable/routine as
ifdef TASM ;external and public depending on
global var ;whats required. "var" is the name of
else ;the symbol to declare.
externdef var
endif
endm
;------------------------------------------------------------------------------
;Some more general purpose macro's to keep things simple.
;------------------------------------------------------------------------------
pushm MACRO R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,R15,R16
IRP X,<R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,R15,R16> ;REPEAT FOR EACH PARM
IFNB <X> ;IF THIS PARM NOT BLANK
PUSH X ;SAVE THE REGISTER
ENDIF ;END IFNB
ENDM ;END IRP
ENDM
popm macro R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,R15,R16
IRP X,<R16,R15,R14,R13,R12,R11,R10,R9,R8,R7,R6,R5,R4,R3,R2,R1> ;REPEAT FOR EACH PARM
IFNB <X> ;IF THIS PARM NOT BLANK
POP X ;POP THE REGISTER
ENDIF ;END IFNB
ENDM ;END IRP
ENDM
rep_movsb macro
push ecx
shr ecx,2
rep movsd
pop ecx
and ecx,3
rep movsb
endm
rep_movsw macro
push ecx
shr ecx,1
rep movsd
pop ecx
and ecx,1
rep movsw
endm
rep_stosb macro
push eax
mov ah,al
push ax
shl eax,16
pop ax
push ecx
shr ecx,2
rep stosd
pop ecx
and ecx,3
rep stosb
pop eax
endm
rep_stosw macro
push eax
push ax
shl eax,16
pop ax
push ecx
shr ecx,1
rep stosd
pop ecx
and ecx,1
rep stosw
pop eax
endm
;------------------------------------------------------------------------------
;Some useful equates.
;------------------------------------------------------------------------------
b equ byte ptr
w equ word ptr
d equ dword ptr
f equ fword ptr
SK_SHIFTR equ 1
SK_SHIFTL equ 2
SK_CTRL equ 4
SK_ALT equ 8
SK_SCROLL equ 16
SK_NUM equ 32
SK_CAPS equ 64
SK_INS equ 128
;-----------------------------------------------------------------------------
;Switch video memory bank number. This will only be needed if you are writing
;low level video access code.
;-----------------------------------------------------------------------------
Bank macro bankreg
local __noswitch
push eax
mov eax,bankreg ;Get huge video memory address.
shr eax,16 ;isolate the bank number.
cmp ax,ss:CurrentBank ;same as we're already useing?
jz __noswitch
inc ss:InMouse ;stop mouse event interfering.
pushm eax,ebx,ecx,edx
mov bh,0
mov bl,0 ;set both read and write bank numbers
mov dx,ax ;to be the same. At some point I'll
mov cl,ss:BankShift
shl dx,cl
call ss:bankaddress ;change this so that the second call
inc bl ;isn't made if it's not needed.
call ss:bankaddress
popm eax,ebx,ecx,edx
mov ss:CurrentBank,ax ;update the bank number.
dec ss:InMouse ;allow mouse stuff access again.
__noswitch: pop eax
endm
;-----------------------------------------------------------------------------
;Some video mode equates. It's better to use the mode list built during
;initialisation incase a mode is supported that isn't listed here but these
;give easy access to known modes.
;
;Note: Entries with a value of 0 indicate I haven't found out the mode numbers
; YET.
;-------------------------------------------------------------------------
Video320x200x256 equ 13h
Video640x400x256 equ 100h
Video640x480x256 equ 101h
Video800x600x256 equ 103h
Video1024x768x256 equ 105h
Video1152x1024x256 equ 122h
Video1280x1024x256 equ 107h
Video1600x1200x256 equ 124h
;
Video320x200x32k equ 10dh
Video640x400x32k equ 0
Video640x480x32k equ 110h
Video800x600x32k equ 113h
Video1024x768x32k equ 116h
Video1280x1024x32k equ 0
;
Video320x200x64k equ 10eh
Video640x400x64k equ 0
Video640x480x64k equ 111h
Video800x600x64k equ 114h
Video1024x768x64k equ 117h
Video1280x1024x64k equ 0
;
Video320x200x16m equ 0
Video640x400x16m equ 0
Video640x480x16m equ 112h
Video800x600x16m equ 115h
Video1024x768x16m equ 0
Video1280x1024x16m equ 0
;-----------------------------------------------------------------------------
;VESA structures returned by several VESA INT 10h functions. Only needed if
;you do low level access stuff.
;-----------------------------------------------------------------------------
VgaInfoBlock struc
VIB_VESASignature db 'VESA' ;4 signature bytes
VIB_VESAVersion dw ? ;VESA version number
VIB_OEMStringPtr dd ? ;Pointer to OEM string
VIB_Capabilities db 4 dup (?) ;capabilities of the video environment
VIB_VideoModePtr dd ? ;pointer to supported Super VGA modes
VgaInfoBlock ends
ModeInfoBlock struc
;mandatory information
MIB_ModeAttributes dw ? ;mode attributes
MIB_WinAAttributes db ? ;Window A attributes
MIB_WinBAttributes db ? ;Window B attributes
MIB_WinGranularity dw ? ;window granularity
MIB_WinSize dw ? ;window size
MIB_WinASegment dw ? ;Window A start segment
MIB_WinBSegment dw ? ;Window B start segment
MIB_WinFuncPtr dd ? ;pointer to window function
MIB_BytesPerScanLine dw ? ;bytes per scan line
;optional information
MIB_XResolution dw ? ;horizontal resolution
MIB_YResolution dw ? ;vertical resolution
MIB_XCharSize db ? ;character cell width
MIB_YCharSize db ? ;character cell height
MIB_NumberOfPlanes db ? ;number of memory planes
MIB_BitsPerPixel db ? ;bits per pixel
MIB_NumberOfBanks db ? ;number of banks
MIB_MemoryModel db ? ;memory model type
MIB_BankSize db ? ;bank size in K
ModeInfoBlock ends
;-----------------------------------------------------------------------------
;"system" bitmap re-mapping control stuff.
;-----------------------------------------------------------------------------
MaxBMEntries equ 1024 ;number of control entries allocated.
BMT struc
BMT_Flags dd ? ;Flags.
BMT_InUse equ 1 ;Is this entry in use.
BMT_Pointer dd ? ;Pointer to bitmap data.
BMT_Duplicate dd ? ;Pointer to duplicate.
BMT ends
;-----------------------------------------------------------------------------
;Bitmap header used/expected for all bitmap related functions.
;-----------------------------------------------------------------------------
BM struc
BM_Flags dd 0 ;control flags,
;0-3 = data format, 0=256, 1=32k, 2=64k, 3=16m.
BM_PWide dd 0 ;Pixel width. Used for fast calculations.
BM_Wide dd 0 ;width (in pixels) of bitmap.
BM_Depth dd 0 ;depth (in pixels) of bitmap.
BM_XOffset dd 0 ;X offset, only used by fonts, can be used for anything.
BM_YOffset dd 0 ;Y offset, only used by fonts, can be used for anything.
dd 0 ;reserved.
dd 0 ;reserved.
BM ends
;-----------------------------------------------------------------------------
;Window related stuff.
;-----------------------------------------------------------------------------
Split struc
Split_XCoord dd 0
Split_YCoord dd 0
Split_Wide dd 0
Split_Depth dd 0
Split ends
MaxSplits equ 32 ;maximum number of splits per window.
Win struc
Win_Priority dd 0 ;Display priority.
Win_XCoord dd 0 ;X coord.
Win_YCoord dd 0 ;Y coord.
Win_Wide dd 0 ;Width.
Win_Depth dd 0 ;Depth.
Win_Handler dd 0 ;Window control handler.
Win_Splits db (size Split)*MaxSplits dup (0) ;Split list.
Win ends
MaxWinWindows equ 256 ;maximum number of windows.
WinMess_Draw equ 0 ;re-draw of window required.
WinMess_Close equ 1 ;window is being closed.
;-------------------------------------------------------------------------
;Dialog stuff.
;-------------------------------------------------------------------------
DlgMain struc
DlgM_FWide dd ?
DlgM_PWide dd ?
DlgM_FDepth dd ?
DlgM_PDepth dd ?
DlgMain ends
Dlg struc
Dlg_State dd ?
Dlg_FXCoord dd ?
Dlg_PXCoord dd ?
Dlg_FYCoord dd ?
Dlg_PYCoord dd ?
Dlg_FWide dd ?
Dlg_PWide dd ?
Dlg_FDepth dd ?
Dlg_PDepth dd ?
Dlg_Flags dd 0
Dlg_Text dd 0
Dlg ends
;-------------------------------------------------------------------------
;Some general purpose variables from STARTUP.ASM
;-------------------------------------------------------------------------
extdef Startup:near
extdef _Main:near
extdef CodeSegAlias:word
extdef ZeroSelector:word
extdef DataLinearBase:dword
extdef PSPSegment:word
extdef ENVSegment:word
extdef ExecutionPath:byte
extdef ExecutionName:byte
;-----------------------------------------------------------------------------
;Some useful variables from the video related code.
;-----------------------------------------------------------------------------
extdef TimerCount:dword ;timer tick count.
extdef VideoSelector:word ;selector for video memory access.
extdef VideoBase:dword ;linear address for video memory.
extdef BankAddress:dword ;bank switch routine address.
extdef CurrentBankBig:word
extdef CurrentBank:word ;current hardware bank selected.
extdef VideoHardwareWidth:dword
extdef VideoPixelWidth:dword ;bytes per pixel in video memory.
extdef VideoXResolution:dword ;X resolution of current mode.
extdef VideoYResolution:dword ;Y resolution of current mode.
extdef VideoModeFlags:dword ;as yet undefined flags.
extdef VideoMode:dword ;current video mode number.
extdef Forced32kList:word ;table of 32k modes.
extdef Forced64kList:word ;table of 64k modes.
extdef BankShift:byte ;bank shift.
extdef HardwarePalette:byte ;palette last sent to video hardware.
extdef SystemXlat:byte ;table to translate "system" palette
;to real hardware palette.
extdef SystemPalette:byte ;palette used for "system" stuff and
;used as a referance for conversion
;between "system" and hardware.
extdef ValidModeList:word ;list of available modes.
extdef VESABuffer:byte ;temp buffer.
extdef ModeInfoBuffer:byte ;temp buffer.
extdef MouseExcludeCall:dword ;The next 3 are pointers to routines.
extdef MouseOffCall:dword ;Normally they point to a RET but
extdef MouseOnCall:dword ;are patched when useing MOUSE stuff
;in this library so that they do
;what you would expect. The normal
;mouse routines should be called
;unless you want code to work
;without forceing the mouse modules
;to be included.
extdef InMouse:word ;None zero while inside a mouse
;routine OR bank switch code. DON'T
;call bank switch code from hardware
;interrupt handlers when this is
;none zero.
extdef BMTable:dword ;Address of "system" bitmap control
;table.
extdef WinWindowList:dword ;List of window pointers.
extdef BaseWindow:dword ;Base window.
extdef WindowRegionFlag:dword ;Forced region clipping?
extdef WindowRegionX:dword ;definition of region to clip to.
extdef WindowRegionY:dword
extdef WindowRegionW:dword
extdef WindowRegionD:dword
extdef FontBuffer:byte ;somewhere to play with characters.
;-------------------------------------------------------------------------
;Some useful font oriented stuff.
;-------------------------------------------------------------------------
extdef FontTable:dword
extdef SystemFont:dword
extdef FontWidth:dword
extdef FontDepth:dword
;-------------------------------------------------------------------------
;Name: Malloc
;-------------------------------------------------------------------------
;
;Allocate some DS relative memory.
;
;On Entry:
;
;ECX - Bytes required.
;
;On Exit:
;
;Carry set on error and ESI=0 else,
;
;ESI - DS relative address of allocated memory.
;
;All other registers preserved.
;
;-------------------------------------------------------------------------
extdef Malloc:near
;-------------------------------------------------------------------------
;Name: ReMalloc
;-------------------------------------------------------------------------
;
;Re-size previously allocated memory.
;
;On Entry:
;
;ECX - New size.
;ESI - Current address of memory.
;
;On Exit:
;
;Carry set on error and ESI=0 else,
;
;ESI - New address of memory.
;
;All other registers preserved.
;
;-------------------------------------------------------------------------
extdef ReMalloc:near
;-------------------------------------------------------------------------
;Name: Free
;-------------------------------------------------------------------------
;
;Release some memory.
;
;On Entry:
;
;ESI - Address to release.
;
;On Exit:
;
;All registers preserved.
;
;-------------------------------------------------------------------------
extdef Free:near
;-------------------------------------------------------------------------
;Name: OpenFile
;-------------------------------------------------------------------------
;
;Open a file.
;
;On Entry:
;
;EDX - File name.
;
;On Exit:
;
;Carry set on error and EBX=0 else,
;
;EBX - File handle.
;
;-------------------------------------------------------------------------
extdef OpenFile:near
;-------------------------------------------------------------------------
;Name: CreateFile
;-------------------------------------------------------------------------
;
;Create a file.
;
;On Entry:
;
;EDX - File name.
;
;On Exit:
;
;Carry set on error and EBX=0 else,
;
;EBX - File handle.
;
;-------------------------------------------------------------------------
extdef CreateFile:near
;-------------------------------------------------------------------------
;Name: CloseFile
;-------------------------------------------------------------------------
;
;Close a file.
;
;On Entry:
;
;EBX - file handle.
;
;-------------------------------------------------------------------------
extdef CloseFile:near
;-------------------------------------------------------------------------
;Name: DeleteFile
;-------------------------------------------------------------------------
;
;Delete a file.
;
;On Entry:
;
;EDX - File name to delete.
;
;On Exit:
;
;Carry set on error.
;
;ALL registers preserved.
;
;-------------------------------------------------------------------------
extdef DeleteFile:near
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -