📄 asm_2_htm.asm
字号:
; Get the file size
;===============================
invoke GetFileSize, hFile, NULL
mov Src_Size, eax
;================================
; test for an error
;================================
.if eax == -1
jmp err
.endif
;==============================================
; Allocate enough memeory to hold the file
;==============================================
invoke GlobalAlloc, GMEM_FIXED, Src_Size
mov hSrc_Memory, eax
mov Spot, 0
;===================================
; test for an error
;===================================
.if eax == 0
jmp err
.endif
;==============================================
; Allocate a worst case scenario memory
; for compression program
;==============================================
mov eax, Src_Size
shl eax, 4
invoke GlobalAlloc, GMEM_FIXED, eax
mov hDest_Memory, eax
;===============================
; test for an error
;===============================
.if eax == 0
jmp err
.endif
;===================================
; Put the file into memory
;===================================
invoke ReadFile, hFile, hSrc_Memory, Src_Size, offset Amount_Read, NULL
;===============================
; test for an error
;===============================
.if eax == 0
jmp err
.endif
;============================
; Close the handle
;============================
invoke CloseHandle,hFile
;===================================
; Set the number written to zero
;===================================
mov written, 0
done:
return 1
err:
;============================
; Close the handle
;============================
invoke CloseHandle,hFile
return 0
Open endp
;########################################################################
; END of Open
;########################################################################
;########################################################################
; ConvertFile Function
;########################################################################
ConvertFile proc
;=====================================
; Code to convert the chosen file
;=====================================
;=====================================
; Local Variables
;=====================================
LOCAL ending_spot:DWORD
LOCAL Word_Spot:BYTE
LOCAL Count:DWORD
;=====================================
; Initialize our ending and word spot
;=====================================
mov eax, hSrc_Memory
add eax, Src_Size
mov ending_spot, eax
mov Word_Spot, 0
;=====================================
; Set the count to zero
;=====================================
mov Count, 0
;=====================================
; Update the screen
;=====================================
invoke UpdateScreen
;=====================================
; Clear out our Word buffer
;=====================================
mov cl, 0
mov eax, offset szWord
.while cl <= MAX_WORD_SIZE
mov BYTE PTR [eax], 0
inc eax
inc cl
.endw
;========================================
; Set processing to TRUE, Time Count 0
;========================================
mov Processing, TRUE
mov Time_Count, 0
;=====================================
; Copy into header one the first part
; we will write to the file's memory
; this consists of the file title
;=====================================
mov dwArgs, offset szFileTitle
invoke wvsprintfA,ADDR szHeaderBuffer,ADDR szHeaderTemp1, offset dwArgs
;=====================================
; Now write out our first header
;=====================================
invoke wvsprintfA, hDest_Memory, ADDR szHeaderBuffer,0
;=====================================
; Add the number written and advance
; the memory handle by that amount
;=====================================
add written, eax
add hDest_Memory, eax
;=====================================
; Place the defualt color for the
; background into the string. If they
; have selected a different color it
; will have replaced that string
;=====================================
mov dwArgs+0, offset szDEFAULT_BACKGROUND
mov dwArgs+4, offset szDEFAULT_TEXT
invoke wvsprintfA,ADDR szHeaderBuffer,ADDR szHeaderTemp2, offset dwArgs
;=====================================
; Now write out our final part of the
; header to the file
;=====================================
invoke wvsprintfA, hDest_Memory, ADDR szHeaderBuffer,0
;=====================================
; Add the number written and advance
; the memory handle by that amount
;=====================================
add written, eax
add hDest_Memory, eax
;=====================================
; This is the start of our main loop
; it will parse our file and write out
; the necassary info to the
; destination memory
;=====================================
top:
;====================================
; Increment the count
;====================================
inc Count
;====================================
; If count == 2000 update the screen
;====================================
.if Count == 2000
;==========================
; Update it
;==========================
invoke UpdateScreen
;=========================
; Increment Time Count
;=========================
inc Time_Count
;=========================
; Reset if greter than 4
;=========================
.if Time_Count > 4
mov Time_Count, 0
.endif
;=========================
; Reset the Count
;=========================
mov Count, 0
.endif
;=====================================
; Parse until the end test
;=====================================
mov eax, ending_spot
.if hSrc_Memory <= eax
;============================
; Put the character into the
; Word at pos Word_Spot
;============================
mov eax, offset szWord
add al, Word_Spot
mov ecx, hSrc_Memory
xor ebx, ebx
mov bl, BYTE PTR [ecx]
mov BYTE PTR [eax], bl
;============================
; Increment our source memory
; and the word spot
;============================
inc hSrc_Memory
inc Word_Spot
;========================================
; Start with the larger tests for the
; keywords, psuedo-ops, types, and the
; multi line comment. If this fails try
; the single character things
;========================================
;===========================================
; First lets' do a few tests to skip over if
; not needed to the smaller stuff
;===========================================
mov al, Word_Spot
.if al < 2
;======================
; Jump over this stuff
;======================
jmp skipbig
.endif
;===================================
; Perform the second test by seeing
; if the next char is a terminator
;===================================
mov eax, hSrc_Memory
mov bl, BYTE PTR [eax]
.if bl == 32 || bl == 9 || bl == 10 || bl == 13 || bl == 44 || bl == 93
;===================================
; Do nothing it means we
; have a word to test against
;===================================
.else
;======================
; Jump over this stuff
;======================
jmp skipbig
.endif
;==========================================
; Start this off by checking the keywords
;==========================================
invoke IsKeyword, offset szWord, Word_Spot
;==========================================
; If it wasn't a keyword then try a psuedo
;==========================================
.if eax == 0
;================================
; Try the psuedo op
;================================
invoke IsPsuedo, offset szWord, Word_Spot
;================================
; Did this fail also????
;================================
.if eax == 0
;==========================
; Well then try a type
;==========================
invoke IsType, offset szWord, Word_Spot
;=============================
; Did this one fail too??
;=============================
.if eax == 0
;==========================
; Try a register test
;==========================
invoke IsReg, offset szWord, Word_Spot
;=============================
; Did we fail this??
;==============================
.if eax == 0
;==========================
; Finally try a comment
;==========================
invoke IsComment, offset szWord, Word_Spot
;=============================
; Did this one fail too??
;=============================
.if eax == 0
;==========================
; Do nothing last test
;==========================
.else
;=====================================
; Reset Word_Spot to zero
;=====================================
mov Word_Spot, 0
;===================
; Back to the top
;===================
jmp top
.endif
.else
;=============================
; Reset Word_Spot to zero
;=============================
mov Word_Spot, 0
;===================
; Back to the top
;===================
jmp top
.endif
.else
;=====================================
; Reset Word_Spot to zero
;=====================================
mov Word_Spot, 0
;===================
; Back to the top
;===================
jmp top
.endif
.else
;=====================================
; Reset Word_Spot to zero
;=====================================
mov Word_Spot, 0
;===================
; Back to the top
;===================
jmp top
.endif
.else
;=====================================
; Reset Word_Spot to zero
;=====================================
mov Word_Spot, 0
;===================
; Back to the top
;===================
jmp top
.endif
skipbig:
;========================================
; Make the tests for any of the single
; char stuff: strings, and comments
;========================================
mov eax, offset szWord
add al, Word_Spot
dec eax
xor ebx, ebx
mov bl, BYTE PTR [eax]
.if bl == ';'
;======================================
; Process a single line comment
;======================================
;======================================
; If buffer has more than one char then
; empty it
;======================================
.if Word_Spot > 1
;=======================
; Has chars so empty it
;=======================
mov eax, 0
xor edx, edx
mov dl, Word_Spot
dec dl
.while al < dl
;============================
; Write them out to the file
;============================
push eax
mov ebx, offset szWord
add ebx, eax
mov cl, BYTE PTR [ebx]
mov BYTE PTR [ebx], 0
push edx
invoke WriteChar, cl
pop edx
pop eax
inc al
.endw
.endif
;======================================
; Setup and write out the comment color
; and the delimiter
;======================================
mov dwArgs, offset szDEFAULT_COMMENT
invoke wvsprintfA,ADDR szFontBuffer,ADDR szFontTemp, offset dwArgs
invoke wvsprintfA, hDest_Memory, ADDR szFontBuffer, 0
;=====================================
; Add the number written and advance
; the memory handle by that amount
;=====================================
add written, eax
add hDest_Memory, eax
;======================================
; Write out the comment symbol
;======================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -