⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lowtest.asm

📁 修改DV内存的汇编源代码,在95/98下使用,使用时需仔细.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;=============================================================================
;FILE: LANC.ASM
;
;DESC: Sony LANC Protocol reader (in the future: writer)
;NOTE: Tab width=4
;BY:   H.Wagner / or Industrial Computers GmbH
;DATE: 04.03.1999
;=============================================================================
;Rev  Date       Author   Description
;-----------------------------------------------------------------------------
;=============================================================================

.MODEL  SMALL,SYSCALL
 PAGE   60,132
 TITLE  LANC.ASM
 OPTION PROC:private

.nolist
;  include ???
  include lanc_if.inc
.list

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%
;%                MAIN MODULE
;%
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

PRG_DATA_SEGM SEGMENT PARA PUBLIC 'DATA' USE16

stdout_redir        byte 0          ; 0: stdout is not redirected

user_break          byte 0

current_page        byte ?
page_locked         byte ?          ; 1=address can't be incremented on current page
org 100h
eeprom_page_data    byte 256 dup (?)

PRG_DATA_SEGM ENDS

CODE SEGMENT PARA PUBLIC 'CODE' USE16
.586p

jmp   start

include lanc_ui.asm

start:
  mov   ax, seg PRG_DATA_SEGM
  mov   ds, ax
assume ds:PRG_DATA_SEGM
  mov   al, byte ptr es:[18h+1]
  .if (al != 1)
    mov   stdout_redir, 1
  .endif
  
  call  do_the_job                  ; this could set error code in al
  mov   ah, 4Ch
  int   21h


;in:    es:bx   pointer to start of telegram
;out:   nothing
display_telegram proc uses ax bx cx si

  mov   al, '<'
  call  write_char_tty

  mov   cx, 8
  .repeat
    mov   al, byte ptr es:[bx]
    call  display_byte_hex
    .if (cx > 1)
      mov   al, ' '
      call  write_char_tty
    .endif
    inc   bx
  .untilcxz

  mov   al, '>'
  call  write_char_tty

  mov   si, offset crlf_msg
  call  write_string_tty

  ret

display_telegram endp

fehler_msg byte "Telegram-Empfang-Fehler", 0
display_telegrams proc uses ax bx cx
;xxx
  mov   cx, 20
  .repeat
    call  lanc_if_receive_telegram
    .if carry?
mov si, offset fehler_msg
call write_string_tty
      ret
    .endif
    mov   ah, 0
    call  display_word_dez
    mov   al, ':'
    call  write_char_tty
;    movzx bx, al
;    sub   bx, 8
;    add   bx, offset recv_data
    call  display_telegram
  
  .untilcxz
ret
comment~  
  mov   bx, 5555h
  call  send_word

  mov   bx, 0AAAAh
  call  send_word
  mov   bx, 03333h
  call  send_word


  mov   bx, 08181h
  call  send_word
  mov   bx, 09999h
  call  send_word
  mov   bx, 01818h
  call  send_word
  
  mov   bx, 0101h
  call  send_word
  mov   bx, 0202h
  call  send_word
  mov   bx, 0404h
  call  send_word
  mov   bx, 0808h
  call  send_word
  
  call  lanc_if_receive_telegram
  call  display_telegram
  mov   bx, 0000h
  call  send_word
  mov   bx, 0FFFFh
  call  send_word
  mov   bx, 0000h
  call  send_word
  mov   bx, 0FFFFh
  call  send_word
  mov   bx, 0000h
  call  send_word
  mov   bx, 0FFFFh
  call  lanc_if_receive_telegram
  call  display_telegram
  mov   bx, 0000h
  call  send_word
  mov   bx, 0FFFFh
  call  send_word
  mov   bx, 0000h
  call  send_word
  mov   bx, 0FFFFh
  call  send_word
  mov   bx, 0000h
  call  send_word
  mov   bx, 0FFFFh
endcomment~  

  ret

display_telegrams endp

page_msg    byte "      Dump of Page ",0
page1_msg   byte " (=",0
page2_msg   byte "h)",13,10,0
page_locked_msg   byte "Page is locked (can't increment address)",13,10,0

print_page proc uses ax bx cx si

  mov   si, offset page_msg
  call  write_string_tty
  movzx ax, current_page
  call  display_word_dez
  mov   si, offset page1_msg
  call  write_string_tty
  call  display_byte_hex
  mov   si, offset page2_msg
  call  write_string_tty

  mov   al, page_locked
  .if (al)
    mov   si, offset page_locked_msg
    call  write_string_tty
    ret
  .endif

  mov   bx, offset eeprom_page_data
  mov   cx, 0
  .repeat
    .if !(cx & 0Fh)
      mov   ax, cx
      call  display_word_hex
      mov   al, ':'
      call  write_char_tty
      mov   al, ' '
      call  write_char_tty
    .endif
    mov   al, byte ptr [bx]
    inc   bx
    call  display_byte_hex
    inc   cx
    mov   al, cl
    and   al, 0Fh
    .if (al == 0)
      call  display_crlf
    .else
      .if (al == 8)
        mov   al, ' '
        call  write_char_tty
        mov   al, ' '
        call  write_char_tty
      .else
        mov   al, ' '
        call  write_char_tty
      .endif
    .endif
  .until (cx == 256)

  ret

print_page endp

;in:    al      command, where
;               0   = NOP (used for reading the eeprom)
;               67h = page+
;               65h = page-
;               38h = addr+
;               36h = addr-  (or 54h ???)
;               34h = data+
;               30h = data-
;               32h = store data
;out:   carry set       error
;       carry clear     ok, then
;           es:bx   pointer to last received lanc telegram
rm95_command proc uses ax cx
local send_b1:byte, send_b2:byte

  .if (al == 0) || (al == 67h) || (al == 65h) || (al == 38h) || (al == 36h) || (al == 34h) || (al == 30h) || (al == 32h)
    jmp   ok
  .else
    stc
    ret
  .endif

ok:
  mov   send_b1, 0FFh
  mov   send_b2, al

;  pushf
;  .if (ah == 1)
;    cli
;    call  lanc_if_telegram_syncronize
;  .endif
  .if (send_b2 == 0)
    jmp   read_command
  .endif
  xor   cx, cx
  .repeat
    mov   al, send_b1
    mov   ah, send_b2
    call  lanc_if_send
    call  lanc_if_receive_telegram
    .if (al != NOERROR)
;      popf
mov di, 1234h
      stc
      ret
    .endif
    mov   al, byte ptr es:[bx+5]
    inc   cx
  .until (al == 0F1h) || (cx > 6)
COMMENT ~   ; page may be locked, so address or data commands did not work
  .if (cx > 6)
;    popf
mov di, 1235h
    stc
    ret
  .endif
ENDCOMMENT ~
read_command:
  xor   cx, cx
  .repeat
    mov   al, send_b1
    mov   ah, 0
    call  lanc_if_send
    call  lanc_if_receive_telegram
    .if (al != NOERROR)
;      popf
mov di, 1236h
      stc
      ret
    .endif
    mov   al, byte ptr es:[bx+5]
xor   ah,ah
;call display_word_dez
    inc   cx
  .until (al == 0F0h) || (cx > 100)

  .if (cx > 100)
;    popf
mov di, 1237h
    stc
    ret
  .endif

;  popf
  clc

  ret

rm95_command endp

;in:    ah      page (0-15)
;out:   carry set       error
;       carry clear     ok, then
;           es:bx   pointer to last received lanc telegram
rm95_setpage proc uses ax cx
; new page (np), old page (op)
; pd=np-op
; wenn pd > 0 und pd <= 8 inc page
; wenn pd < 0 oder pd > 8 dec page

local pg:byte, curr_pg:byte
local command:byte

  .if (ah > 15)
    stc
    ret
  .endif

  mov   pg, ah

  mov   al, 0                       ; 0=read eeprom data
  call  rm95_command
  .if carry?
int 3
    ret
  .endif

  mov   ah, es:byte ptr [bx+4]
  shr   ah, 4
  mov   curr_pg, ah
  mov   al, pg
  .if (al < ah)
    add   al, 16
  .endif
  sub   al, ah
  .if (al == 0)
    jmp   pg_ok
  .elseif (al <= 8)        ; inc page
    mov   command, 67h
  .else
    mov   ah, al
    mov   al, 16
    sub   al, ah
    mov   command, 65h
  .endif
  movzx cx, al
  .repeat
    mov   al, command
    call  rm95_command
    .if carry?
int 3
      ret
    .endif
  .untilcxz

pg_ok:

  ret

rm95_setpage endp

;in:    ah      page (0-15)
;out:   carry set       error
;       carry clear     ok, then
rm95_read_page proc uses ax bx cx
local pg:byte, curr_pg:byte, adr:byte, curr_adr:byte, data:byte
local command:byte

  .if (ah > 15)
    stc
    ret
  .endif

  mov   pg, ah
  mov   adr, 0
;xxx
;;mov   ah, pg
  dec   ah
  .if (ah == -1)
    mov   ah, 15
  .endif
  call  rm95_setpage
  inc   ah
  .if (ah == 16)
    mov   ah, 0
  .endif
  call  rm95_setpage
 ; now by this two "rm95_setpage" the address is set to zero in all cases

  mov   cx, 100h
  .repeat
movzx ax, es:byte ptr [bx+4]
shr ax, 4
;call display_word_dez
movzx ax, byte ptr [bx+6]
;call display_word_dez

   ; check the page and address
    mov   al, es:byte ptr [bx+4]
    shr   al, 4
    .if (al != pg)
      stc
      ret
    .endif
    mov   al, es:byte ptr [bx+6]
    mov   ah, cl
    neg   ah
    .if (al != ah)
      stc
      ret
    .endif
   ; store the data
    mov   al, es:byte ptr [bx+7]
    movzx bx, ah
    add   bx, offset eeprom_page_data
    mov   byte ptr [bx], al

   ; switch to next address (if not the last address)
    .if (cx > 1)
      mov   al, 38h                  ; 38h=addr+
      call  rm95_command
      .if carry?
        ret
      .endif
    .endif

  .untilcxz

  mov   al, pg
  mov   current_page, al

  ret

rm95_read_page endp

;in:    ah      page (0-15)
;out:   carry set       error
;       carry clear     ok, then
dump_page proc uses ax bx cx es

  .if (ah > 15)
    stc
    ret
  .endif

  mov   current_page, ah
  xor   al, al
  mov   page_locked, al

  call  rm95_setpage
  .if (carry?)
    ret
  .endif
  mov   al, es:byte ptr [bx+4]
  shr   al, 4
  .if (al != ah)
    stc
    ret
  .endif

  mov   cx, 256
  .repeat

   ; store the data
    mov   al, es:byte ptr [bx+7]
    mov   ah, es:byte ptr [bx+6]
    movzx bx, ah
    add   bx, offset eeprom_page_data
    mov   byte ptr [bx], al

   ; switch to next address (if not the last address)
    .if (cx > 1)
      mov   al, 38h                  ; 38h=addr+
      call  rm95_command
      .if carry?
        ret
      .endif
      mov   al, es:byte ptr [bx+6]   ; get new address
     ; now AH holds the old address and AL the new one
      .if (ah != 255)
        inc   ah
        .if (al != ah)
          mov   al, 1               ; mark wrong address
        .else
          mov   al, 0
        .endif
      .elseif (al != 0)
        mov   al, 1                 ; mark wrong address
      .else
        mov   al, 0
      .endif
      .if (al == 1)
        mov   page_locked, al
        .break
      .endif
    .endif

  .untilcxz

  ret

dump_page endp

dump_all proc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -