📄 bootrom.asm
字号:
pop cx
cmp ax,cx
jb short FWCRC_Err
inc cx
mov bx,offset buffer
FWCRC_1:
movzx ax,byte ptr [bx]
dec cx
jcxz short FWCRC_2
UpdateCRC
inc bx
jmp short FWCRC_1
FWCRC_Err:
FWCRC_2:
pop dx
pop bx
pop ax
ret
FwriteCRC endp
FillBuf proc near ; shift bitbuf n bits left, read n bits
;
; Input : AX
; Output : None
;
pusha
mov word ptr temp_param,ax ; save
mov cx,ax
mov ax,word ptr bitbuf
shl ax,cl
mov word ptr bitbuf,ax
FB_1:
mov ax,word ptr temp_param
cmp ax,word ptr bitcount
jbe short FB_3
sub ax, word ptr bitcount
mov word ptr temp_param, ax
push ax
mov ax, word ptr subbitbuf
pop cx ; pop out temp_param
shl ax,cl
or word ptr bitbuf, ax
cmp dword ptr compsize,0
je short FB_2
dec dword ptr compsize
push es
mov ax,word ptr SrcSegment
mov es,ax
mov bx,word ptr SrcOffset
movzx ax,byte ptr es:[bx]
mov word ptr subbitbuf,ax
inc word ptr SrcOffset
jnz short @F ;R84
add word ptr SrcSegment,1000h ;R84
@@: ;R84
pop es
jmp short @F
FB_2:
mov word ptr subbitbuf,0
@@:
mov word ptr bitcount,CHAR_BIT
jmp short FB_1
FB_3:
mov ax, word ptr bitcount
sub ax, word ptr temp_param
mov word ptr bitcount,ax
push ax
mov ax, word ptr subbitbuf
pop cx
shr ax,cl
or word ptr bitbuf, ax
popa
ret
FillBuf endp
GetBits proc near
;
; Input : AX
; Output : AX
;
push cx
push bx
mov cx,BITBUFSIZ
sub cx,ax
mov bx,ax ; save a copy for later use
mov ax,word ptr bitbuf
shr ax,cl
push ax ; save returned result
mov ax,bx ; restore original parameter
call FillBuf
pop ax ; returned value
pop bx
pop cx
ret
GetBits endp
InitGetBits proc near
mov word ptr bitbuf,0
mov word ptr subbitbuf,0
mov word ptr bitcount,0
mov ax,BITBUFSIZ
call FillBuf ; with parameter pass-in BITBUFSIZ (16)
ret
InitGetBits endp
HufDecodeStart proc near
call InitGetBits
mov word ptr blocksize,0
ret
HufDecodeStart endp
DecodeStart proc near
call HufDecodeStart
mov word ptr j,0 ; remaining bytes to copy
ret
DecodeStart endp
InitLocalVars proc near
push bx
mov word ptr i,0
mov word ptr k,0
mov word ptr len,0
mov word ptr jutbits,0
mov word ptr avail,0
mov word ptr nextcode,0
mov word ptr vmask,0
xor bx,bx
ILV_1:
cmp bx,34
jae short ILV_2
mov word ptr count[bx],0
mov word ptr weight[bx],0
mov word ptr start[bx],0
add bx,2
jmp short ILV_1
ILV_2:
mov word ptr start[34],0
pop bx
ret
InitLocalVars endp
MakeTable proc near
;
; Input : BX, SI, DX, DI
; Output :
;
pusha
call InitLocalVars ; init local variables and arrays
push bx
mov bx,2
MT_1:
cmp bx,32
ja short MT_2
mov word ptr count[bx],0
inc bx
inc bx
jmp short MT_1
MT_2:
pop cx ; get nchar parameter to cx
push cx ; save nchar for later use
xor bx,bx
MT_3:
cmp bx,cx
jae short MT_4
push si
add si,bx
movzx ax,byte ptr [si]
shl ax,1 ; adjust to word index
mov si,ax
inc word ptr count[si]
pop si
inc bx
jmp short MT_3
MT_4:
mov word ptr start[2],0 ; adjust to word index (from 1 to 2)
mov bx,1
MT_5:
cmp bx,16
ja short MT_6
mov cx,16
sub cx,bx
push bx
shl bx,1
mov ax,word ptr count[bx]
shl ax,cl
add ax,word ptr start[bx]
mov word ptr start[bx+2],ax
pop bx
inc bx
jmp short MT_5
MT_6:
mov ax,1
shl ax,16
cmp ax,word ptr start[34]
je short MT_7
MT_Err:
jmp MT_Exit ; bye ! now
MT_7:
mov cx,16
sub cx,dx
mov word ptr jutbits,cx
mov bx,1
MT_8:
cmp bx,dx
ja short MT_9
push bx ; save bx
shl bx,1 ; adjust to word index
mov ax,word ptr start[bx]
mov cx,word ptr jutbits
shr ax,cl
mov word ptr start[bx],ax
pop bx ; get original index
mov cx,dx
sub cx,bx
mov ax,1
shl ax,cl
push bx ; save index
shl bx,1 ; adjust to word index
mov word ptr weight[bx],ax
pop bx ; get original index
inc bx
jmp short MT_8
MT_9:
cmp bx,16
ja short MT_10
mov cx,16
sub cx,bx
mov ax,1
shl ax,cl
push bx ; save original index
shl bx,1 ; adjust to word index
mov word ptr weight[bx],ax
pop bx ;restore original index
inc bx
jmp short MT_9
MT_10:
mov cx,word ptr jutbits
mov bx,dx
inc bx
shl bx,1 ; adjust to word index
mov ax,word ptr start[bx]
shr ax,cl
mov bx,ax ; store in bx for var i
mov ax,1
shl ax,16
cmp bx,ax
je short MT_12
mov cx,dx
mov ax,1
shl ax,cl
MT_11:
cmp bx,ax
je short MT_12
push bx ; save original index
shl bx,1 ; adjust to word index
add bx,di ; di contains the offset of array table
mov word ptr [bx],0
pop bx
inc bx
jmp short MT_11
MT_12:
pop cx ; restore nchar
; from this point we start using global variable for result
; storing. We might consider to change to use global variable
; instead of pushing/poping a lot of registers later.
mov word ptr avail,cx
mov word ptr nchar,cx ; move this line to the upper
; part of this subroutine
mov cx,15
sub cx,dx
mov ax,1
shl ax,cl
mov word ptr vmask,ax
xor bx,bx ; BX stand for variable ch
MT_13:
cmp bx,word ptr nchar
jae MT_Exit
movzx ax,byte ptr [bx+si] ; si contains the offset of
; array bitlen
mov word ptr len,ax
cmp word ptr len,0
je MT_20 ; continue looping
push bx ; bx contains value of variable ch
mov bx,word ptr len
shl bx,1 ; adjust to word index
mov ax,word ptr start[bx]
add ax,word ptr weight[bx]
mov word ptr nextcode,ax
cmp word ptr len,dx ; dx contains the value of tablebits
ja short MT_15
mov bx,word ptr len
shl bx,1 ; adjust to word index
mov ax,word ptr start[bx]
pop bx ; now bx contains the value of ch
MT_14:
cmp ax,word ptr nextcode
jae MT_19
push di
add di,ax
add di,ax ; adjust to word index
mov word ptr [di],bx
pop di
inc ax
jmp short MT_14
MT_15:
; stack is not yet balanced
; Now BX stored in the stack still contains value of var ch
mov bx,word ptr len
shl bx,1 ; adjust to word index
mov ax,word ptr start[bx]
mov word ptr k,ax
mov cx,word ptr jutbits
shr ax,cl
mov bx,ax
shl bx,1 ; adjust to word index
add bx,di
mov word ptr p,bx ; get the pointer of table[k>>jutbits]
mov bx,word ptr len
sub bx,dx
mov word ptr i,bx
MT_16:
cmp word ptr i,0
je short MT_18
mov bx,word ptr p
cmp word ptr [bx],0
jne short MT_17
mov bx,word ptr avail
shl bx,1 ; adjust to word index
mov word ptr right[bx],0
mov word ptr left[bx],0
mov bx,word ptr p
mov ax,word ptr avail
mov word ptr [bx],ax
inc ax
mov word ptr avail,ax
MT_17:
mov ax,word ptr k
mov bx,word ptr vmask
and ax,bx
jz short MT_17_1
; the following 5 lines of code are converted from "p = &right[*p]"
mov bx,word ptr p
mov ax,word ptr [bx]
shl ax,1 ; adjust to word index
; mov bx,word ptr right
mov bx,offset right
add bx,ax
mov word ptr p,bx
jmp short MT_17_2
MT_17_1:
; the following 5 lines of code are converted from "p = &left[*p]
mov bx,word ptr p
mov ax,word ptr [bx]
shl ax,1 ; adjust to word index
; mov bx,word ptr left
mov bx,offset left
add bx,ax
mov word ptr p,bx
MT_17_2:
mov ax,word ptr k
shl ax,1
mov word ptr k,ax
dec word ptr i
jmp short MT_16
MT_18:
pop bx ; get ch back, and stack now is balanced
xchg ax,bx
mov bx,word ptr p
mov word ptr [bx],ax
xchg ax,bx
MT_19: ; to here BX should contains the value of var ch
push bx
mov bx,word ptr len
shl bx,1 ; adjust to word index
mov ax,word ptr nextcode
mov word ptr start[bx],ax
pop bx
MT_20:
inc bx
jmp MT_13
MT_Exit:
popa
ret
MakeTable endp
ReadCLen proc near
;
; Input : None
; Output : None
;
pusha
mov ax,CBIT
call GetBits
cmp ax,0
jne short RCL_3
mov ax,CBIT
call GetBits ; AX contains the value of var c
mov cx,NC
RCL_1:
mov bx,NC
sub bx,cx
mov byte ptr c_len[bx],0
loop short RCL_1
mov cx,4096
RCL_2:
mov bx,4096
sub bx,cx
mov di,bx
shl di,1 ; prepare word index
mov word ptr c_table[di],ax
loop short RCL_2
jmp RCL_Exit
RCL_3:
mov dx,ax ; AX carry result of n, save n
mov si,0 ; i
RCL_4:
cmp dx,si ; dx -> n, si -> i
jbe RCL_10
mov cx,word ptr BITBUFSIZ
sub cx,8
mov bx,word ptr bitbuf
shr bx,cl
shl bx,1 ; prepare word index
mov di,word ptr pt_table[bx] ; c
cmp di,NT
jb short RCL_7
mov cx,word ptr BITBUFSIZ
sub cx,9
mov bx,1
shl bx,cl ; BX is used to store MASK temporarily
RCL_5:
mov ax,word ptr bitbuf
and ax,bx
jz short RCL_6
shl di,1 ; prepare word index
mov di,word ptr right[di]
jmp short RCL_6_1
RCL_6:
shl di,1 ; prepare word index
mov di,word ptr left[di]
RCL_6_1:
shr bx,1
cmp di,NT
jae short RCL_5
RCL_7:
movzx ax,byte ptr pt_len[di]
call FillBuf
cmp di,2
ja short RCL_9
cmp di,0
jne short RCL_7_1
mov di,1
jmp short RCL_8
RCL_7_1:
cmp di,1
jne short RCL_7_2
mov ax,4 ; prepare input for GetBits
call GetBits ; get a result from AX
add ax,3
mov di,ax
jmp short RCL_8
RCL_7_2:
mov ax,CBIT
call GetBits
add ax,20
mov di,ax
RCL_8: ; while (--c >= 0) c_len[i++] = 0
dec di
cmp di,0
js short RCL_4
mov byte ptr c_len[si],0
inc si
jmp short RCL_8
RCL_9:
mov ax,di
sub ax,2
mov byte ptr c_len[si],al
inc si
jmp RCL_4
RCL_10: ; when i >= n
cmp si,NC
jae short RCL_11
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -