📄 bootrom.asm
字号:
mov byte ptr c_len[si],0
inc si
jmp short RCL_10
RCL_11:
mov bx,NC ; bx -- parameter 1
mov si,offset c_len ; prepare parameter 2
mov dx,12 ; dx -- parameter 3
mov di,offset c_table ; prepare parameter 4
call MakeTable
RCL_Exit:
popa
ret
ReadCLen endp
ReadPtLen proc near
;
; Input : SI->nn(int), AX->nbit(int), DI->i_special(int)
; Output : None
;
pusha
push ax ; save nbits for later use
call GetBits
mov dx,ax ; save n
cmp dx,0
pop ax
jne short RPL_3_1
call GetBits ; get a result put it in AX for var c
xor bx,bx
RPL_1:
cmp bx,si
jae short RPL_2
mov byte ptr pt_len[bx],0
inc bx
jmp short RPL_1
RPL_2:
xor bx,bx
RPL_3:
cmp bx,512 ; word index
jae RPL_Exit ; bye !
mov word ptr pt_table[bx],ax
add bx,2 ; moving pointer 1 word forward
jmp short RPL_3
RPL_3_1:
xor bx,bx ; i
RPL_4:
cmp bx,dx ; i < n ?
jae RPL_10
mov cx,BITBUFSIZ
sub cx,3
mov ax, word ptr bitbuf
shr ax,cl
push di ; save parameter since we want to use di
mov di,ax ; save for later var c referencing
cmp di,7
jne short RPL_6
mov cx,BITBUFSIZ
sub cx,4
mov ax,1
shl ax,cl ; variable mask is ready
RPL_5:
mov cx,word ptr bitbuf
and cx,ax
jz short RPL_6
shr ax,1
inc di
jmp short RPL_5
RPL_6: ; fillbuf((c < 7) ? 3 : c - 3)
mov ax,3
cmp di,7
jb short RPL_7
mov ax,di
sub ax,3
RPL_7:
call FillBuf
mov ax,di
mov byte ptr pt_len[bx],al
inc bx
pop di
cmp bx,di
; jne short RPL_10
jne short RPL_4
mov ax,2
call GetBits
RPL_8:
dec ax
cmp ax,0
js short RPL_4 ; loop back
mov byte ptr pt_len[bx],0
inc bx
jmp short RPL_8
RPL_10: ; while (i >= n)
cmp bx,si ; while (i < nn) loop
jae short RPL_11
mov byte ptr pt_len[bx],0
inc bx
jmp short RPL_10
RPL_11:
mov bx,si ; prepare parameter for MakeTable call
mov si,offset pt_len
mov dx,8
mov di,offset pt_table
call MakeTable
RPL_Exit:
popa
ret
ReadPtLen endp
DecodeC proc near
;
; Input : None
; OutPut : AX
;
push bx
push cx
push si
push di
cmp word ptr blocksize,0
jne short DC_1
mov ax,16
call GetBits
mov word ptr blocksize,ax
mov si,NT
mov ax,TBIT
mov di,3
call ReadPtLen ; NT, TBIT, 3
call ReadCLen
mov si,NP
mov ax,PBIT
mov di,-1
call ReadPtLen ; NP, PBIT, -1
DC_1:
dec word ptr blocksize
mov cx,BITBUFSIZ
sub cx,12
mov ax, word ptr bitbuf
shr ax,cl
mov bx,ax ; used as index
shl bx,1 ; adjust to word index
mov ax, word ptr c_table[bx]
mov si,ax ; use SI to represent J
cmp ax,NC
jb short DC_4
mov ax,1
mov cx,BITBUFSIZ
sub cx,13
shl ax,cl
DC_2:
; variable MASK is stored in AX
mov bx, word ptr bitbuf
and bx,ax
mov bx,si ; get variable j, prepare word index
jnz short DC_3
shl bx,1 ; adjust to word index
mov si,word ptr left[bx]
jmp short DC_3_1
DC_3:
shl bx,1 ; adjust to word index
mov si,word ptr right[bx]
DC_3_1:
shr ax,1
cmp si,NC
jae short DC_2
DC_4:
movzx ax,byte ptr c_len[si]
call FillBuf
mov ax,si ; value to be returned
DC_Exit :
pop di
pop si
pop cx
pop bx
ret
DecodeC endp
DecodeP proc near
;
; Input : None
; Output : BX
;
push ax
push cx
push si
mov cx,BITBUFSIZ
sub cx,8
mov ax, word ptr bitbuf
shr ax,cl
mov bx,ax ; used as index
shl bx,1 ; adjust to word index
mov ax, word ptr pt_table[bx]
mov si,ax ; use SI to represent J
cmp ax,NP
jb short DP_4
mov cx,BITBUFSIZ
sub cx,9
mov ax,1
shl ax,cl
DP_1:
; variable MASK is stored in AX
mov bx, word ptr bitbuf
and bx,ax
mov bx,si ; get variable j, prepare word index
jnz short DP_2
shl bx,1 ; adjust to word index
mov si,word ptr left[bx]
jmp short DP_3
DP_2:
shl bx,1 ; adjust to word index
mov si,word ptr right[bx]
DP_3:
shr ax,1
cmp si,NP
jae short DP_1
DP_4:
movzx ax,byte ptr pt_len[si]
call FillBuf
cmp si,0
je short DP_5
mov cx,si
dec cx
mov ax,1
shl ax,cl
mov cx,ax ; store temp result
mov ax,si
dec ax
call GetBits
add ax,cx
mov si,ax
DP_5:
mov bx,si
DP_Exit:
pop si
pop cx
pop ax
ret
DecodeP endp
Decode proc near
;
; Input : CX and Buffer
;
pusha
; xor bx,bx ; i
mov bx,word ptr s_i
xor si,si ; r
D_2:
dec word ptr j ; remaining bytes to copy to
cmp word ptr j,0
js short D_3
mov al,byte ptr buffer[bx]
mov byte ptr buffer[si],al
inc bx
mov ax,DICSIZ
dec ax
and bx,ax
inc si
cmp si,cx ;
jne short D_2
mov word ptr s_i,bx ; save
popa
ret
D_3:
call DecodeC ; return result in AX
cmp ax,UCHAR_MAX
ja short D_4
mov byte ptr buffer[si],al
inc si
cmp si,cx
jne short D_3
mov word ptr s_i,bx ; save
popa
ret
D_4: ; j = c - (UCHAR_MAX + 1 - THRESHOLD)
sub ax,UCHAR_MAX
dec ax
add ax,THRESHOLD
mov word ptr j, ax
mov ax,si
call DecodeP ; return result in BX
sub ax,bx
dec ax
mov bx,ax
mov ax,DICSIZ
dec ax
and bx,ax ; i = BX
D_4_1:
dec word ptr j
cmp word ptr j, 0
js short D_3
mov al,byte ptr buffer[bx]
mov byte ptr buffer[si],al
mov ax,DICSIZ
dec ax
inc bx
and bx,ax ; i = BX
inc si
cmp si,cx
je short D_6 ; bye now!
jmp short D_4_1 ; go back to while loop
; D_5:
; jmp short D_3
D_6:
mov word ptr s_i,bx ; save
popa
ret
Decode endp
public Extract
Extract proc near
pusha
; Get file name string starting point
; save file name length
mov bx,NAMELENIDX
mov bl,byte ptr Header[bx]
mov byte ptr namelen,bl
; print message on screen
; compress/decompress method recognition
mov word ptr crc,INIT_CRC
movzx dx,byte ptr Header[3] ; get mrthod
mov byte ptr Header[3],20h ; fill with blank
; decompress starts here
call DecodeStart
Ex_1:
cmp dword ptr origsize,0
je short Ex_3
mov ecx,DICSIZ ; assume origsize is smalller than DIGSIZ
cmp dword ptr origsize, DICSIZ
ja short @F
mov ecx,dword ptr origsize
@@:
push ecx
call Decode ; with parameter cx and buffer
call FwriteCRC ; with buffer, cx andOutFileHandle
; display '.' to tell user the program is running
pop ecx
mov eax,dword ptr origsize
sub eax,ecx
mov dword ptr origsize,eax
jmp short Ex_1
Ex_3:
popa
ret
Extract endp
;R108A start
;[]==============================================================[]
;
; Expand:
;
;Saves: NONE
;
;Entry: ES : SEGMENT of Source Data
; BX : OFFSET of Source Data
; DX : Segment of Expand Data buffer
;
;Exit: NONE
;
;Author: Award
;Date: 11/16/94
;
;[]==============================================================[]
ASSUME CS:DGROUP,DS:EXP_DATA
Expand proc near
push ax
push bx
push es ; save source segment
;R137 start
;----- Get decompress code address and store to Temp Expand pool
mov di,Temp_EXP_Seg
mov ds,di
mov di,Temp_EXP_Off
mov word ptr ds:[di],offset Expand
cmp byte ptr es:[bx+12h],40h ;Is decomress segment?
jne short Not_POST_USE ;No,goto decompress
cmp byte ptr es:[bx+11h],0 ;already record?
jne short Record_to_buffer ;No,goto record
;R137A cmp word ptr ds:[di+4],0 ;already record?
cmp dword ptr ds:[di+4],0 ;R137A already record?
jne short Not_POST_USE ;Yes,goto decompress
Record_to_buffer:
movzx dx,byte ptr es:[bx+011h]
sub es:[bx+1],dl ;recalculate checksum
mov byte ptr es:[bx+11h],0 ;mask decompress segment to 4000h
inc dx
shl dx,2
add di,dx
mov ds:[di],bx
mov cx,es
mov ds:[di+2],cx
movzx ecx,byte ptr es:[bx]
add ecx,es:[bx+7]
add ecx,COMPRESSED_UNKNOW_BYTE ;unknow bytes
jmp @F
Not_POST_USE:
;---------------------------------------------------
;R137 end
; Init data segment registers
mov ds,dx
; Initialize EXP_DATA segment, in case there's garbage left
push ds
pop es
xor di,di
mov cx,4000h
xor ax,ax
repz stosw
; Read compressed data from segment:offset
pop es
push es
mov word ptr SrcSegment, es
mov word ptr SrcOffset,bx
; Temp Target Segment, Offset
; make CRC table
call MakeCRCTable
; read header
call ReadHeader
jc short @F ; error, something wrong
mov ax,ExpSegment
mov TgtSegment,ax
mov ax,ExpOffset
mov TgtOffset,ax
;-- calculate compressed total size and return when decompress complete
mov ecx,compsize ;compressed size
xor eax,eax
mov al,headersize ;compressed header size
add ecx,eax
add ecx,COMPRESSED_UNKNOW_BYTE ;unknow bytes
mov edx,origsize ;R148
push edx ;R148
push ecx
;R137 start
;check data is store type or compress type
cmp byte ptr es:[bx+5],'0' ;Is store type?
jne short Not_Store ;No,jump
push ds
push si
push bx
pop si
mov di,ExpOffset
movzx ax,byte ptr headersize ;compressed header size
add ax,2 ;store unknow bytes
add si,ax
mov cx,word ptr compsize ;compressed size
mov ax,ExpSegment
push es
pop ds
mov es,ax
rep movsb ;move data to target
pop si
pop ds
jmp short Expand_Over
Not_Store:
;R137 end
push word ptr TgtSegment
push word ptr TgtOffset
push dword ptr origsize
; extract content from compressed file
call Extract
pop dword ptr origsize
pop word ptr TgtOffset
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -