home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / ansi / avatar1.arj / MEMSHOW.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-08-15  |  9.5 KB  |  335 lines

  1. name memshow
  2. title memshow.asm
  3. subttl Copyright (C) 1990 G. Adam Stanislav. All Rights Reserved.
  4. page 66, 132
  5. .radix 16
  6. .model small
  7.  
  8. comment %
  9.  
  10.         This is an assembly version of memdisp.c Because of less
  11.         overhead it is much faster. However, because it uses
  12.         int 29 and 79, this program cannot be simply redirected
  13.         to a com port while the C version can.
  14.  
  15.         Programmed by: G. Adam Stanislav
  16.         Started on: August 13, 1990
  17.         Completed:  August 15, 1990
  18.  
  19. %
  20.  
  21. ; macros
  22. print   macro   string, stringlen
  23.         local   start
  24.  
  25.         mov     cx, stringlen
  26.         push    si
  27.         lea     si, string
  28.  
  29. start:
  30.         lodsb
  31.         int     29
  32.         loop    start
  33.         pop     si
  34.  
  35. endm
  36.  
  37. page
  38. .data
  39.  
  40. hello   db      16, 12          ; ^V ^R = reset the driver
  41.         db      0C              ; ^L    = cls
  42.         db      0Dh             ; carriage return (if no AVT found)
  43.         db      "memshow.exe: "
  44.         db      "Copyright (C) 1990, G. Adam Stanislav. "
  45.         db      "All Rights Reserved.", 0Dh, 0A
  46. hellolen equ    $-hello
  47.         db      "Sorry, this program requires AVATAR console.", 0Dh, 0A, 0A
  48. sorrylen equ    $-hello
  49. query   db      16, 11, 11      ; ^V ^Q ^Q
  50. querylen equ    $-query
  51. buffer  db      80 dup('*')
  52. avt     db      'AVT'
  53. setup   db      16, 08, 15, 01  ; locate 21, 1
  54.         db      "Controls: PgUp and PgDn: offset +/- 100. ^PgUp and ^PgDn: "
  55.         db      "segment +/- 1000.", 0Dh, 0A
  56.         db      "Alt-PgUp and Alt-PgDn: offset +/- 1000 (enhanced keyboard "
  57.         db      "only).", 0Dh, 0A
  58.         db      16, 01, "oPress <ESC> to quit."
  59.         db      16, '=R'        ; switch to raw parser mode
  60.         db      16, 16, 'G'     ; define window 'G'
  61.         db      03, 03, 01, 14, 50      ; attribute: 3, corners: 3, 1, 20, 80
  62.         db      16, 17, 'G'     ; switch to window 'G'
  63.         db      16, 0F          ; turn clockwise mode on
  64.         db      0C9, 19, 0CDh, 09, 0D1h, 19, 0CDh, 44, 0BBh, 19, 0BAh
  65.         db      10, 0BCh, 19, 0CDh, 44, 0CF, 19, 0CDh, 09, 0C8, 19
  66.         db      0BAh, 10        ; draw the frame
  67.         db      16, 1E          ; turn vertical mode on
  68.         db      16, 08, 02, 0Bh ; locate start of thin line
  69.         db      19, 0B3, 10     ; draw the thin line
  70.         db      16, 16, 'G'     ; redefine window 'G'
  71.         db      03, 04, 02, 13, 0A ; attrib.: 3, corners, 4, 2, 19, 10
  72.         db      16, 08, 01, 01  ; locate 1, 1
  73.         db      19, '0', 40     ; print a bunch of zeros
  74.         db      19, ':', 10     ; print 16 colons vertically
  75.         db      19, '0', 20     ; more zeros
  76. hextbl  db      "0123456789ABCDEF"
  77.         db      16, 22          ; turn wrap off
  78.         db      19, '0', 10     ; and even more zeros
  79.         db      16, 16, 01      ; define window 1
  80.         db      07, 04, 0C, 13, 4F ; attr:7, corners: 4, 12, 19, 79
  81.         db      16, 17, 01      ; switch to window 1
  82.         db      16, 27, 02      ; hide the cursor
  83. setuplen equ    $-setup
  84. aline   db      ' 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  '
  85. dots    db      '................', 0Dh, 16, 04
  86. alinelen equ    $-aline
  87. cleanup db      16, 12          ; reset the driver
  88.         db      16, 08, 18, 01  ; locate 24, 1
  89. cleanuplen equ  $-cleanup
  90. newoffs db      16, 17, 'G'     ; switch to window 'G'
  91.         db      16, 08, 01, 06  ; locate 1, 6
  92.         db      19              ; repeat ...
  93. noffs1  db      0               ; high byte of new offset ...
  94.         db      10, 0Dh, 0A     ; 16 times
  95.         db      19              ; repeat ...
  96. noffs2  db      0               ; low byte of new offset ...
  97.         db      10              ; 16 times
  98.         db      16, 17, 01      ; return to window 1
  99. newoffslen equ  $-newoffs
  100. newseg  db      16, 17, 'G'     ; switch to window 'G'
  101. loc11   db      16, 08, 01, 01  ; locate 1, 1
  102. loc11len equ    $-loc11
  103.         db      19              ; repeat ...
  104. nseg1   db      0               ; highest byte of segment ...
  105.         db      10              ; 16 times
  106.         db      16, 17, 01      ; go back to window 1
  107. newseglen equ   $-newseg
  108. beep    db      16, 13, 0A, 00, 02      ; play middle 'F' for .2 sec
  109.         db      16, 13, 04, 00, 04      ; play middle 'C' for .4 sec
  110. beeplen equ     $-beep
  111.  
  112. even
  113. doffs   dw      0       ; starting offset to display in a window
  114. dseg    dw      0       ; segment to display
  115.  
  116. page
  117. .code
  118.  
  119. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  120. ;;
  121. ;;      This is the main routine of the program which displays
  122. ;;      the memory contents in window 1
  123. ;;
  124. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  125. show:
  126.         print   loc11, loc11len ; locate 1, 1 in window 1
  127.         push    ds
  128.         mov     ax, doffs
  129.         mov     si, ax          ; starting offset
  130.         mov     ax, dseg
  131.         mov     ds, ax          ; segment
  132.         mov     cx, 10          ; larger counter
  133.  
  134. outer_loop:
  135.         push    cx
  136.         mov     cx, 10          ; smaller counter
  137.         lea     di, dots
  138.         lea     bx, aline
  139.  
  140. inner_loop:
  141.         lodsb
  142.         call    printhex
  143.         cmp     al, ' '
  144.         jae     inner_loop_1
  145.         mov     al, '.'
  146.  
  147. inner_loop_1:
  148.         stosb
  149.         loop    inner_loop
  150.         push    ds
  151.         mov     ax, es
  152.         mov     ds, ax
  153.         push    bx
  154.         print   aline, alinelen
  155.         pop     bx
  156.         pop     ds
  157.         pop     cx
  158.         loop    outer_loop
  159.  
  160.         pop     ds
  161.         ret
  162.  
  163. printhex:
  164.         ; convert the byte to a 2-digit hex number
  165.         push    ax
  166.         push    ds
  167.  
  168.         push    es
  169.         pop     ds
  170.         push    bx
  171.         lea     bx, hextbl
  172.         push    ax
  173.         and     al, 0F
  174.         xlat    hextbl
  175.         mov     dl, al
  176.         pop     ax
  177.         shr     al, 1
  178.         shr     al, 1
  179.         shr     al, 1
  180.         shr     al, 1
  181.         xlat    hextbl
  182.         pop     bx
  183.         inc     bx      ; skip the blank or dash
  184.         mov     [bx], al
  185.         inc     bx
  186.         mov     [bx], dl
  187.         inc     bx      ; point at next blank or dash
  188.  
  189.         pop     ds
  190.         pop     ax
  191.         ret
  192.  
  193. begin:
  194.         mov     ax, _data
  195.         mov     ds, ax
  196.         mov     es, ax
  197.         cld
  198.  
  199. ; Check if AVATAR console is loaded by sending a query and reading the reply
  200.  
  201.         print   query, querylen
  202.         lea     di, buffer
  203.  
  204.         mov     cx, 80
  205.         sub     bx, bx          ; Count the number of characters
  206. small_loop:
  207.         int     79              ; Read from stdin
  208.         jc      outaloop
  209.         cmp     al, 0Dh         ; Carriage return?
  210.         je      outaloop
  211.         stosb
  212.         inc     bx
  213.         loop    small_loop
  214.  
  215. outaloop:
  216.         lea     si, buffer
  217.         lea     di, avt
  218.         mov     cx, 3
  219. repe    cmpsb                   ; Compare the two strings
  220.         je      program
  221.  
  222.         print   hello, sorrylen
  223.         ; quit
  224.         mov     ax, 4C02
  225.         int     21
  226.  
  227. program:
  228.         print   hello, hellolen
  229.         print   buffer, bx
  230.  
  231.         ; create necessary windows, print help, etc.
  232.         print   setup, setuplen
  233.  
  234. bigloop:
  235.         call    show            ; display a window full
  236.  
  237. keycheck:
  238.         int     79
  239.         jc      bigloop
  240.  
  241.         ; a key was pressed, see what it was
  242.         cmp     al, 1Bh         ; escape?
  243.         jne     fkey
  244.  
  245. done:
  246.         print   cleanup, cleanuplen
  247.         ; quit
  248.         mov     ax, 4C00
  249.         int     21
  250.  
  251. fkey:
  252.         ; check if it was a function key
  253.         or      al, al
  254.         je      findfkey        ; yes, find out what it is
  255.         jmp     badkey          ; beep
  256.  
  257. findfkey:
  258.         int     79              ; read the function key
  259.  
  260.         ; it was a function key, see which one
  261.         cmp     al, 49          ; Page Up?
  262.         jne     fkey_1
  263.         sub     doffs, 100
  264.  
  265. writeoffset:
  266.         mov     ax, doffs
  267.         lea     bx, hextbl
  268.         mov     al, ah
  269.         and     al, 0F
  270.         xlat    hextbl
  271.         mov     noffs2, al
  272.         mov     al, ah
  273.         shr     al, 1
  274.         shr     al, 1
  275.         shr     al, 1
  276.         shr     al, 1
  277.         xlat    hextbl
  278.         mov     noffs1, al
  279.         print   newoffs, newoffslen
  280.         jmp     keycheck        ; maybe the key is being held down
  281.  
  282. fkey_1:
  283.         cmp     al, 51          ; Page Down?
  284.         jne     fkey_2
  285.         add     doffs, 100
  286.         jmp     short writeoffset
  287.  
  288. fkey_2:
  289.         cmp     al, 99          ; Alt-PgUp of enhanced keyboard?
  290.         jne     fkey_3
  291.         sub     doffs, 1000
  292.         jmp     writeoffset
  293.  
  294. fkey_3:
  295.         cmp     al, 0A1         ; Alt-PgDn of enhanced keyboard?
  296.         jne     fkey_4
  297.         add     doffs, 1000
  298.         jmp     writeoffset
  299.  
  300. fkey_4:
  301.         cmp     al, 84          ; ^PgUp?
  302.         jne     fkey_5
  303.         sub     dseg, 1000
  304.  
  305. writesegment:
  306.         mov     ax, dseg
  307.         mov     al, ah
  308.         shr     al, 1
  309.         shr     al, 1
  310.         shr     al, 1
  311.         shr     al, 1
  312.         lea     bx, hextbl
  313.         xlat    hextbl
  314.         mov     nseg1, al
  315.         print   newseg, newseglen
  316.         jmp     keycheck        ; maybe the key is being held down
  317.  
  318. fkey_5:
  319.         cmp     al, 76          ; ^PgDn?
  320.         jne     fkey_6
  321.         add     dseg, 1000
  322.         jmp     writesegment
  323.  
  324. fkey_6:
  325.         ; invalid key was pressed
  326. badkey:
  327.         print   beep, beeplen
  328.         jmp     keycheck        ; see if another key was pressed
  329.  
  330. .stack
  331.         db      128 dup('Adam')
  332.  
  333. end     begin
  334.  
  335.