📄 rw_soft_dog.asm
字号:
code segment 'CODE'
assume cs:code,ds:code,es:code
org 100h
start: jmp begin
usage db 'USAGE: BOX [/R]|[/W]|[/E]',0ah,0dh
db ' /R---Read data form EEPROM.',0DH,0AH
DB ' /W---Write data to EEPROM.',0DH,0AH
DB ' /E---Erase data in EEPROM.',0DH,0AH
DB ' Read and write data in file BOX.DAT',0DH,0AH,24H
msgok db 'Successfully done!',0ah,0dh,24h
msgerr db 'error in file!',07h,0ah,0dh,24h
file db 'box.dat',0
; macro
; data->state
statport macro
inc dx
endm
; state->data
_statport macro
dec dx
endm
; data->ctrl
ctrlport macro
inc dx
inc dx
endm
; ctrl->data
_ctrlport macro
dec dx
dec dx
endm
;
EC_NotReady equ 1 ;EEPROM Option over time
ErrorCode db 0
V31_Mode equ 00000001B ;SK->data D3
_VCC equ 00010000B ;VCC->DATA D0
_CS equ 00000010B ;CS->DATA D7 AND CTORL D0
_DI equ 00100000B ;DI->DATA D6
_DO equ 00010000B ;DO->STATA D6
; D4 LINK VCC
setvcc macro
push ax
in al,dx
or al,_VCC ;data4 high
out dx,al
pop ax
endm
; set EEPROM CS HIGH (-AUTOFEED LINK CS)
setcs macro
push ax
ctrlport
in al,dx
and al,not _CS ;-auto feed high
out dx,al
_ctrlport
pop ax
endm
;set EEPROM CS LOW
clearcs macro
push ax
ctrlport
in al,dx
or al,_CS
out dx,al
_ctrlport
pop ax
endm
; sk->low
clearSK macro
push ax
in al,dx
and al,not V31_Mode
out dx,al
pop ax
endm
; sk->high
clockSK macro
push ax
in al,dx
and al,not V31_Mode
out dx,al
or al,V31_Mode
out dx,al
pop ax
endm
; DI->low D5-DI
clearDI macro
push ax
in al,dx
and al,not _DI
out dx,al
pop ax
endm
; 1bit data -> AH.7
SendBit macro
local SendBit_1
push ax
in al,dx
or al,_DI ;AH.7=1 DI->HIGH
test ah,80h
jnz SendBit_1
and al,not _DI ;AH.7=0 DI->LOW
SendBit_1: out dx,al
clocksk
pop ax
endm
; send 1 byte data , data-ah
sendByte macro
local sendByte_lp1,_cmp1
push ax
push cx
mov cx,8
sendByte_lp1:
sendbit
shl ah,1
dec cx
jcxz _cmp1
jmp sendByte_lp1
_cmp1: pop cx
pop ax
endm
; send 1 word
sendWord macro
sendbyte
xchg al,ah
sendbyte
xchg al,ah
endm
; get 1 bit
getBit macro
local Getbit_1
clocksk
statport
in al,dx
mov ah,80h
test al,_DO
jnz getbit_1
not ah
GetBit_1: _statport
endm
; get 1 word->BX
GetWord macro
local getword_1,_cmp1
push ax
push cx
mov cx,10h
getword_1:
getbit
rcl ah,1
rcl bx,1
dec cx
jcxz _cmp1
jmp getword_1
_cmp1: pop cx
pop ax
endm
;
startChipOp macro
LoDelayHiCS
push ax
mov ah,80h
sendbit
pop ax
endm
;
LoDelayHiCS macro
clearDI
clearSK
clearCS
ClockSK
SetCS
ClearSK
endm
;
WaitReady macro
local waitready_lp1,waitready_2,_cmp1,__exit,__exit1
push ax
push cx
LoDelayHiCS
mov cx,800h
waitready_lp1:
getbit
test ah,80h
jnz waitready_2
dec cx
jcxz _cmp1
jmp waitready_lp1
_cmp1: ; jmp waitready_2
mov al,EC_NotReady
stc
jmp __exit
waitready_2:
clearCS
clc
jmp __exit1
__exit: mov cs:Errorcode,al
__exit1: pop cx
pop ax
endm
; in: AH:EEPROM address(D5..D0)
; DX:LPT
; OUT: DATA->BX
_eep_read macro
startchipop
and ah,3fh
or ah,80h ;READ OpCode=10ssssss
sendbyte
clearDI
getWord
lodelayhics
endm
; IN: DX-LPT
; OUT:
_EEP_EWEN macro
push ax
startchipop
mov ah,30h ;EWEN OpCode=0011xxxx
sendbyte
lodelayhics
pop ax
endm
; IN:
; AH:EEPROM ADDRESS(D5..D0)
; DX:LPT
; BX:WORD
; OUT:
_EEP_WRITE macro
startchipop
and ah,3fh
or ah,40h ;WRITE OpCode=01ssssss
sendbyte
mov ax,bx
sendword
waitready
endm
; IN:
; AH:EEPROM ADDRESS (D5..D0)
; DX:LPT
; OUT:
_EEP_ERASE macro
startchipop
and ah,3fh
or ah,0c0h ;ERASE OpCode=11ssssss
sendbyte
waitready
endm
; IN:
; DX:LPT
; OUT:
_EEP_EWDS macro
startchipop
mov ah,0
sendbyte
lodelayhics
endm
; IN:
; DX:LPT PORT ADDRESS
; AH:EEPROM ADDRESS
; ES:DI: DATA BUFFERS ADDRESS
; CL:READ DATA LONG
; OUT:
; AL=OP STATUS 00
_BBRead macro
local __1,__9e,__9d,__exit,__cmpl
cld
xor ch,ch
mov cs:errorcode,0
setvcc
__1: push ax
_EEP_READ
cmp cs:errorcode,0
je __9d
jmp __9e
__9d: mov ax,bx
stosw
pop ax
inc ah
dec cx
jcxz __cmpl
jmp __1
__cmpl: clc
jmp __exit
__9e: pop ax
stc
__exit: mov al,cs:errorcode
endm
; IN:
; DX:LPT ADDRESS
; AH:EPPROM ADDRESS
; DS:SI=DATA BUFFERS ADDRESS
; CL:WRITE DATA LeNG
; OUT:
; AL=OP STATUS 00
_BBWrite macro
local __1,__9e,__9d,__9f,__exit,__cmpl
mov cs:errorcode,0
setvcc
_EEP_EWEN
cmp cs:errorcode,0
je __9d
jmp __9e
__9d: cld
xor ch,ch
__1: ; lodelayhics
push ax
push ax
lodsw
mov bx,ax
pop ax
_EEP_WRITE
cmp cs:errorcode,0
je __9f
jmp __9e
__9f: pop ax
inc ah
dec cx
jcxz __cmpl
jmp __1
__cmpl: _EEP_EWDS
clc
jmp __exit
__9e: pop ax
stc
__exit: mov al,cs:errorcode
endm
; IN:
; DX:LPT ADDRESS
; AH:EEPROM ADDRESS
; CL:ERASE DATA LONG
; OUT:
; AL=00
_BBErase macro
local __1,__9e,__9d,_9f,__exit,__cmpl
mov cs:errorcode,0
setvcc
_EEP_EWEN
cmp cs:errorcode,0
je __9d
jmp __9e
__9d: cld
xor ch,ch
__1: push ax
_EEP_ERASE
cmp cs:errorcode,0
je __9f
jmp __9e
__9f: pop ax
inc ah
dec cx
jcxz __cmpl
jmp __1
__cmpl: _EEP_EWDS
clc
jmp __exit
__9e: pop ax
stc
__exit: mov al,cs:errorcode
endm
begin: cld
xor ch,ch
mov di,80h
mov cl,[di]
inc di
mov al,'/'
repne scasb
mov dx,offset usage
jcxz error1
JMP N
ERROR1: JMP ERROR
FILE_ERR1: JMP FILE_ERR
N: mov al,[di]
and al,5fh
cmp al,'W'
jz _write
cmp al,'R'
jz _r
cmp al,'E'
jz _e
jnz error1
_r: jmp _read
_e: jmp _erase
_write:
mov dx,offset file
mov ax,3d00h
int 21h
jc file_err1
mov bx,ax
push bx
mov dx,offset buffer
mov cx,80h
mov ah,3fh
int 21h
jc file_err1
mov si,dx
mov cx,40h
push es
xor ax,ax
mov es,ax
mov di,408h
push cx
mov cx,3
a2: mov ax,es:[di]
cmp ax,0
jnz a1
inc di
inc di
loop a2
pop cx
pop es
jmp file_err1
;jz File_err1
a1: pop cx
pop es
mov dx,ax
xor ax,ax
_BBWrite
pop bx
cmp cs:errorcode,0
jnz _err
jmp ok
_err: mov ah,3eh
int 21h
_file_err: jmp file_err
_erase:
push ds
xor ax,ax
mov ds,ax
mov si,408h
push cx
mov cx,3
b2: mov ax,[si]
;pop ds
cmp ax,0
jnz b1
inc si
inc si
loop b2
pop cx
pop ds
jmp _file_err
b1: pop cx
pop ds
mov dx,ax
mov cx,40h
xor ax,ax
_BBErase
cmp cs:errorcode,0
jnz __file_err
mov dx,offset msgok
jmp exit
__file_err: jmp file_err
_read:
mov dx,offset file
xor cx,cx
mov ax,3c01h
int 21h
jc __file_err
mov bx,ax
push bx
xor al,al
mov dx,offset buffer
mov di,dx
push di
mov cx,40h
push ds
push cx
xor ax,ax
mov ds,ax
mov cx,3
mov si,408h
c2: mov ax,[si]
cmp ax,0
jnz c1
inc si
inc si
loop c2
pop cx
pop ds
jmp __file_err
c1: pop cx
pop ds
mov dx,ax
xor ax,ax
_BBRead
jc file_err
mov cx,80h
pop di
pop bx
mov dx,di
mov ah,40h
int 21h
jc file_err
ok: mov ah,3eh
int 21h
xor al,al
mov dx,offset msgok
jmp exit
file_err:
mov dx,offset msgerr
error: mov al,1
exit: mov ah,9
int 21h
exit1: mov ah,4ch
int 21h
pc =$
buffer=pc
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -