home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / lowlevel / coretest / coretest.asm next >
Assembly Source File  |  1986-07-26  |  15KB  |  428 lines

  1.           page 60,132
  2. title     coretest deluxe
  3. ;         Version 1.0
  4. ;         written by David Fox
  5. ;         copyright (C) 1986
  6. ;
  7. .sall
  8.           if1
  9.             include macros.lib
  10.           endif
  11. codeseg   segment
  12.           assume cs:codeseg,ds:codeseg
  13.           org    100h           ;for COM files
  14. start:
  15.           push   es             ;for restoring at end
  16.           cld                   ;forward
  17.           cls
  18.           locate 3,20           ;sign on and
  19.           print  signon
  20.           locate 4,20           ;print copyright notice
  21.           print  copynote       ;
  22.           mov    ax,0           ;set
  23.           mov    es,ax          ;segment 0 through ES
  24.           mov    ax,es:[413h]    ;get memory size
  25.           push   ax             ;to print out to user
  26.           locate 5,20
  27.           print  rammsg         ;'You have '
  28.           call   bindec         ;on screen
  29.           pop    ax
  30.           mov    dl,64          ;in terms of
  31.           div    dl             ;highest block->A=640K
  32.           mov    lastblock,ax
  33.           print  kmsg           ;'K of memory.'
  34.           locate 6,20
  35.           print  askfile        ;Ask user if he wants to send error
  36.           inkey                 ;messages to a file.
  37.           mov    isfile,al      ; for later testing in error proc
  38.           cmp    al,'y'
  39.           je     getfile
  40.           cmp    al,'Y'
  41.           je     getfile
  42.           jmp    short nofile
  43. getfile:
  44.           locate 6,20
  45.           print  blank1    ; blank out a message
  46.           locate 6,20
  47.           print  filemsg
  48.           input  buffer    ; Get file name from user.
  49.           lea    bx,buffer + 1           ; get actual length of input
  50.           xor    ch,ch                   ; make sure ch =0
  51.           mov    cl,[bx]                 ; and get length.
  52.           lea    bx,buffer + 2           ; ->actual start of input
  53. putz:
  54.           inc    bx                      ; one more time
  55.           loop   putz                    ; terminate with
  56.                                          ; max characters read...
  57.           mov    byte ptr [bx],0         ; Now it's an asciiZ string.
  58.           open   buffer+2                ; Open the file.
  59.           mov    handle,ax               ; save the handle
  60.           extend ax                      ; OPEN EXTEND file
  61. nofile:
  62.           locate 7,20
  63.           print  beginmsg       ;'Begin Ramtest'
  64.           xor    ax,ax          ; es -> block begin
  65. testlp:
  66.           push   ax
  67.           locate 10,20
  68.           pop    ax
  69.           call   setup          ; setup test & print out block message
  70. testlp1:
  71. ; first test to see if es:bx is in range of
  72. ; cs:start to cs:endloc
  73.           call   getsegs
  74. ; compare ch and al, if equal, same segment.
  75.           cmp    al,ch
  76.           jne    goon
  77. sameseg:
  78. ; now compare bx to see in range of begloc-endloc
  79. ; if so, skip memory check in this area
  80.           cmp    bx,begloc
  81.           jge    nexttest
  82.           jmp    short goon
  83. nexttest:
  84.           cmp    bx,endloc
  85.           jle    skipit
  86. goon:
  87. ; to save time, just print out every 16 locations tested.
  88.           call chkdiv        ; check divisibility by 16
  89.           jne  skip
  90.           push  bx              ; print address out
  91.           locate 10,50
  92.           call  binhex
  93.           pop   bx
  94. skip:
  95.           mov   ax,es           ; Are we in segment zero?
  96.           or    ax,ax
  97.           jnz   nozero          ; skip test if yes
  98.                                 ; Check first if address in range of
  99.                                 ; used interrupts.  If so, disable them.
  100.  
  101.           cmp   bx,21h*4+4      ; last address of used interrupt
  102.           jle   skipit          ; go if not less to re-enable interrupts
  103. nozero:
  104.           mov   al,es:[bx]      ; save it
  105.           call  test0           ; test all zeros
  106.           jz     okay           ; all right
  107.           call   error          ; if not...error
  108. okay:
  109.  
  110.           call   testff         ; test all ones
  111.           jz     okay1          ; all right
  112.           call   error          ; if not...error
  113. okay1:
  114.           call   test55         ; test alternating pattern 55
  115.           jz     okay2          ; all right
  116.           call   error          ; if not...error
  117. okay2:
  118.           call   testaa         ; test alternating pattern aa
  119.           jz     okay3          ; all right
  120.           call   error          ; if not...error
  121. okay3:
  122.           mov    es:[bx],al     ; restore byte
  123. skipit:
  124.           dec    bx             ; another
  125.           jnz    testlp1        ; byte
  126.           mov    ax,es          ; another
  127.           inc    ax
  128.           mov    es,ax          ; segment
  129.           cmp    ax,lastblock   ; done yet
  130.           jl     testlp         ; go get another block if not
  131.           print  completemsg    ; 'Completed'
  132.           pop    es
  133.           close  handle         ; Close file.
  134.           int    20h            ;back to dos
  135. ;
  136. ;        PROGRAM  DATA
  137. ;
  138. signon    db     'C O R E T E S T   DELUXE  1.0$'
  139. copynote  db     '(C) 1986  by  David E.  Fox $'
  140. rammsg    db     'You have $'
  141. kmsg      db     'K of memory$'
  142. beginmsg  db     'Begin Ramtest',13,10,'$'
  143. completemsg db   'Completed Ram Test',13,10,'$'
  144. lastblock dw     ?
  145. zerosw    db     ?
  146. save      dw     ?
  147. testmsg   db     'Testing 64K Block # $'
  148. errormsg  db     'Error at Address $'
  149. datemsg   db     'Date is '
  150. askfile   db     'Do you want errors to be sent to a file (y/n) $'
  151. asklen    equ    $-askfile
  152. blank1    db     (asklen+1) dup (' '),'$'
  153. filemsg   db     'Enter file name -->$'
  154. filelen   equ    $-filemsg
  155. filesize  dd     0
  156.           org    filesize
  157. filelow   dw     ?
  158. filehigh  dw     ?
  159. blank2    db     (filelen+1) dup (' '),'$'
  160. buffer    equ    $                        ; Set up for keyboard read
  161. maxsiz    equ    64
  162. maxcnt    db     maxsiz                   ; Maximum count of buffer
  163. realcnt   db     ?                        ; Actual Characters read
  164. inbuf     db     (maxsiz+1) dup (0)       ; Input buffer, forced ASCIIZ
  165.                                           ; string.
  166. crlf      db     10,13,'$'
  167. handle    dw     ?                        ; File handle
  168. filebuf   db     80 dup (0)               ; buffer area
  169. buflen    dw     ?                        ; buffer length
  170. curseg    dw     ?                        ; current seg:offset
  171. curoff    dw     ?                        ; location at memtest error
  172. begloc    dw     start                    ; storage for 20-bit seg:offset
  173. begseg    db     0                        ; representation
  174. endloc    dw     lastloc                  ; of program's starting and
  175. endseg    db     0                        ; ending locations
  176. fileon    db     0                        ; switches for sending output
  177. isfile    db     ?                        ; (errors) to an error file
  178. ;
  179. chkdiv    proc near
  180.           mov  cl,4
  181.           mov  save,bx
  182.           shr  bx,cl         ; After shifting back and forth,
  183.           shl  bx,cl         ; equality means that BX is divisible
  184.           cmp  bx,save       ; by 16.
  185.           mov  bx,save
  186.           ret
  187. chkdiv    endp
  188. ;
  189. binhex    proc   near
  190. ;Converts a 16 bit number to hexadecimal Ascii on screen.
  191. ;
  192.           push   bp         ; set up
  193.  
  194.           mov    bp,sp      ; stack
  195.                             ; [bp] = saved bp
  196.                             ; 2[bp] = return address (near)
  197.                             ; 4[bp] = our data
  198.           mov    bx,4[bp]
  199.           mov    ch,4
  200. rotate:
  201.           mov    cl,4
  202.           rol    bx,cl
  203.           mov    al,bl
  204.           and    al,0fh
  205.           add    al,30h
  206.           cmp    al,3ah
  207.           jl     printit
  208.           add    al,7
  209. printit:
  210.           mov    dl,al
  211.           mov    ah,fileon    ; check send to file buffer
  212.           or     ah,ah
  213.           je     nosend1
  214.           mov    byte ptr [di],dl    ; send char to buffer
  215.           inc    di
  216. nosend1:
  217.           mov    ah,2
  218.           int    21h
  219.           dec    ch
  220.           jnz    rotate
  221.           pop    bp
  222.           ret
  223. binhex    endp
  224. bindec    proc   near
  225. ;Converts a 16 bit number to Decimal Ascii on screen.
  226. ;
  227.           push   bp         ; set up
  228.  
  229.           mov    bp,sp      ; stack
  230.                            ; [bp] = saved bp
  231.                            ; 2[bp] = return address (near)
  232.                            ; 4[bp] = our data
  233.           mov    bx,4[bp]
  234.           mov    zerosw,'y'
  235.           mov    cx,10000d
  236.           call   decdiv
  237.           mov    cx,1000d
  238.           call   decdiv
  239.           mov    cx,100d
  240.           call   decdiv
  241.           mov    cx,10d
  242.           call   decdiv
  243.           mov    cx,1
  244.           call   decdiv
  245.           pop    bp
  246.           ret
  247. bindec    endp
  248. decdiv    proc   near
  249.           mov    ax,bx
  250.           cwd
  251.           div    cx
  252.           mov    bx,dx
  253.           mov    dl,al
  254.           add    dl,30h
  255.           cmp    dl,30h
  256.           jz     itzero
  257.           mov    zerosw,'n'
  258.           jmp    short noblank
  259. itzero:
  260.           cmp    zerosw,'y'
  261.           jnz    noblank
  262.           cmp    cx,1
  263.           jz     noblank
  264.           mov    dl,' '
  265. noblank:
  266.           mov    ah,fileon    ; check send to file buffer
  267.           or     ah,ah
  268.           je     nosend
  269.           mov    byte ptr [di],dl    ; send char to buffer
  270.           inc    di
  271. nosend:
  272.           mov    ah,2
  273.           int    21h
  274.           ret
  275. decdiv    endp
  276.  
  277.  
  278. getsegs   proc   near
  279.           mov    ax,cs          ; cs/16--actual seg.
  280.           mov    cl,4
  281.           shr    ax,cl
  282.           mov    begseg,al
  283.           mov    ch,al
  284.           mov    ax,es
  285.           shr    ax,cl
  286.           mov    endseg,al
  287.           ret
  288. getsegs   endp
  289.  
  290. setup     proc   near
  291.           push   ax
  292.           print  testmsg        ;'Testing block'
  293.           pop    ax
  294.           mov    es,ax          ;       initial segment: 0
  295.           push   ax             ; Print out block # in
  296.           call   bindec         ; Decimal
  297.           pop    ax
  298.           xor    bx,bx          ; es:[bx]  es:0000-es:FFFF
  299.           ret
  300. setup     endp
  301.  
  302. settle    proc  near
  303.           mov   cx,500
  304. setlp:
  305.           loop  setlp
  306.           ret
  307. settle    endp
  308.  
  309. error     proc  near    ;  Error procedure
  310.           mov   cx,256
  311. ;
  312. ; Load the byte in question with successive values from 0-255
  313. ; to check if a real hard error exists.  If none, return.
  314. ;
  315. errlp:
  316.           inc   byte ptr es:[bx]
  317.           loop  errlp
  318.           mov   es:[bx],al  ; restore byte
  319.           mov   curseg,es   ; save off where we are
  320.           mov   curoff,bx
  321.           call  settle      ; wait a bit
  322.           cmp   es:[bx],al  ; then compare
  323.           jnz   real_error  ; If not equal now, there's problems!
  324.           ret
  325. ;
  326. real_error:
  327.           mov   dl,7    ;  Beep
  328.           mov   ah,5    ;  the keyboard
  329.           int   21h
  330.           push  es
  331.           call  binhex  ; Print out segment
  332.           pop   es
  333.           mov   dl,':'  ; a ':'
  334.           mov   ah,5
  335.           int   21h
  336.           push  bx       ; And offset of error
  337.           call  binhex
  338.           pop   bx
  339.           print crlf     ; and end with cr-lf.
  340.           cmp   isfile,'y'  ; send to file?
  341.           je    fileit
  342.           cmp   isfile,'Y'
  343.           je    fileit
  344.  ; didn't want a file, go back
  345.           ret
  346. fileit:
  347.           mov   fileon,1
  348.           push  es
  349.           push  cs
  350.           pop   es    ;new es for string move routines
  351.           lea   si,datemsg               ; move date
  352.           lea   di,filebuf               ; to file
  353.           mov   cx,length datemsg
  354.           rep   movsb
  355.           mov   byte ptr [di],' '        ; move a space
  356.           inc   di                       ; to buffer
  357.           mov   ah,2ah                   ; get dos
  358.           int   21h                      ; date in cx:dx
  359.           push  dx
  360.           mov   cl,8
  361.           shr   dx,cl                    ; prepare to get month
  362.           call  bindec                   ; send it out
  363.           mov   byte ptr [di],'/'        ; and a '/'
  364.           pop   dx
  365.           push  dx
  366.           xor   dh,dh                    ; get day
  367.           call  bindec                   ; send it out
  368.           pop   dx
  369.           mov   word ptr [di],0a0dh      ; send CR/LF
  370.           add   di,2
  371.           lea   dx,filebuf               ; calculate
  372.           sub   di,dx                    ; actual buffer length
  373.           writeseq handle,di,filebuf     ; write to file
  374.           lea   si, errormsg             ; move error message
  375.           lea   di, filebuf              ; to filebuffer
  376.           mov   cx, length errormsg-1    ; don't send '$'
  377.                                          ; ^ this has nothing to do
  378.                                          ;   with my financial
  379.                                          ;   situation
  380.           rep   movsb
  381.           mov   byte ptr [di],' '        ; move a space
  382.           inc   di                       ; to buffer
  383.           push  curseg                   ; current segment
  384.           call  binhex                   ; send it out
  385.           mov   byte ptr [di],':'        ; send colon
  386.           push  curoff                   ; current offset
  387.           call  binhex                   ; send it out
  388.           add   sp,2                     ; balance stack
  389.           mov   word ptr [di],0a0dh      ; send CR/LF
  390.           add   di,2                     ; get actual length
  391.           lea   dx, filebuf
  392.           sub   di,dx
  393.           writeseq handle,di,filebuf     ; and send it out
  394.           pop   es                       ; restore es
  395.           mov   fileon,0
  396. error     endp
  397. test0     proc   near
  398.           mov    byte ptr es:[bx],0      ; test all zeros
  399.           call   settle                  ; wait a bit
  400.           cmp    byte ptr es:[bx],0      ; is it a 0?
  401.           ret
  402. test0     endp
  403.  
  404. testff    proc   near
  405.           mov    byte ptr es:[bx],0ffh   ; test all ones
  406.           call   settle                  ; wait a bit
  407.           cmp    byte ptr es:[bx],0ffh   ; is it all ones?
  408.           ret
  409. testff    endp
  410.  
  411. test55    proc   near
  412.           mov    byte ptr es:[bx],55h    ; test alternating pattern 1
  413.           call   settle                  ; wait a bit
  414.           cmp    byte ptr es:[bx],55h    ; is it right?
  415.           ret
  416. test55    endp
  417.  
  418. testaa    proc   near
  419.           mov    byte ptr es:[bx],0aah   ; test alternating pattern 2
  420.           call   settle                  ; wait a bit
  421.           cmp    byte ptr es:[bx],0aah   ; is it right?
  422.           ret
  423. testaa    endp
  424. lastloc   equ    $        ; last location of program
  425. main      endp
  426. codeseg   ends
  427.           end  start
  428.