home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_37.arc / PCDADS-3.FIG < prev    next >
Text File  |  1987-01-08  |  14KB  |  317 lines

  1. ; SDQ.ASM 1/8/87, copyright Russ Eberhart
  2. ; Link with pcpads2c.bas, compiled to pcpads2c.obj, and prefix.obj
  3. ;
  4. data    segment word public 'data'
  5. fa_stor dw 4 dup(?)     ;store 4 channel factors here
  6. of_stor dw 4 dup(?)     ;store 4 channel offsets here
  7. s_trace dw ?            ;1=single trace 0=continuous
  8. s_table dw 4 dup(0)     ;store 4 calculated channel counts
  9. nam_fil db 'c:data.dat',0h ;name of ramdisk file for data
  10. handle  dw ?            ;store file handle here
  11. s_data  dw 2424d dup(0) ;store screenful of data here
  12. data    ends
  13. ;
  14. dgroup  group data      ;define data group,loaded last
  15. ;
  16. stack   segment word stack 'stack'
  17. stk     dw 128 dup(?)   ;define stack area
  18. stack   ends
  19. ;
  20. code    segment byte public  'code'
  21.         assume cs:code,ds:dgroup
  22. ;
  23.         public scndraw
  24. scndraw proc far
  25. ;
  26.         push bp
  27.         mov bp,sp       ;BP points at BASIC stack
  28.                         ;now can read parameters
  29.                         ;from BASIC stack
  30. ;
  31. ;-----------------------
  32. ; Load factors, offsets and single-trace variable
  33. ;
  34.         lea bx,fa_stor  ;point to factor table
  35.         mov di,22d      ;set di to point at fac1%
  36. loop1:  mov si,[bp+di]  ;move fac/off/stn address to SI
  37.         mov ax,[si]     ;move value of variable into AX
  38.         mov [bx],ax     ;move value into table
  39.         add bx,2        ;point to next word in table
  40.         sub di,2        ;point to next variable on stack
  41.         cmp di,4        ;done last variable?
  42.         jnz loop1       ;if not done, jump to loop1
  43. ;-----------------------
  44. ; Check s_trace for "save data", if save, create c:data.dat file
  45. ;  and write offsets and factors to it
  46.         mov cx,s_trace  ;move s_trace to CX to check for save
  47.         and cx,2        ;check for binary 2 = save
  48.         jz newsc        ;if no 2, no save, jump to newscreen
  49.         mov dx,offset nam_fil ;address of file name
  50.         mov cx,0        ;normal file attribute
  51.         mov ah,3ch      ;create file function
  52.         int 21h         ;call dos
  53.         mov handle,ax   ;store handle
  54.         jnc wr_parms    ;if no error, write offsets and factors
  55.         jmp getout      ; if error, get out
  56. wr_parms:
  57.         mov bx,handle   ;put handle in BX
  58.         mov dx,offset fa_stor ;address of bytes to write
  59.         mov cl,16d      ;put number of bytes to write in CL
  60.         mov ch,0        ; and zero out CH
  61.         mov ah,40h      ;write to file function
  62.         int 21h         ;call dos
  63.         jnc newsc       ;if no error, go on
  64.         jmp getout      ; if error, get out
  65. ;-----------------------
  66. ; Set video mode, write screen labels and dot matrix
  67. ;
  68. newsc:  mov ah,0        ;function 0, "set mode"
  69.         mov al,6        ;mode 6: 640x200
  70.         int 10h         ;video I/O int sets mode
  71. ;
  72.         mov cx,4        ;set up for four loops
  73.         mov dh,00       ;initial row
  74.         mov bh,0        ;page no. must be in BH
  75. ;
  76. wrt:    mov ah,2        ;"set cursor" function
  77.         inc dh          ;DH=row=1
  78.         mov dl,03       ;DL=column (0-79)
  79.         int 10h         ;video I/O sets cursor
  80.         mov bl,07       ;color=7 (BH still 0)
  81.         mov al,'4'      ;char to print = 4
  82.         mov ah,0eh      ;"write tty" video service
  83.         int 10h         ;vid I/O prints "4"
  84. ;
  85.         mov ah,2        ;set cursor
  86.         inc dh          ;DH=row=2
  87.         mov dl,03       ;col=3
  88.         int 10h         ;set cursor to 2,3
  89.         mov bl,07       ;color
  90.         mov ax,0e33h    ;"tty" service:char 3 to print
  91.         int 10h         ;prints 3
  92. ;
  93.         mov ah,2        ;set cursor
  94.         inc dh          ;row=3
  95.         mov dl,03       ;col=3
  96.         int 10h         ;set cur 3,3
  97.         mov bl,07       ;color
  98.         mov ax,0e32h    ;"tty":2 to print
  99.         int 10h         ;prints 2
  100. ;
  101.         mov ah,2        ;set cursor
  102.         inc dh          ;row=4
  103.         mov dl,0        ;col=0
  104.         int 10h         ;set cur at 4,0
  105.         mov bl,07       ;color
  106.         mov ax,0e43h    ;tty:C to print
  107.         int 10h         ;prints C, moves cursor
  108.         mov bl,07       ;color
  109.         mov ax,0e20h    ;tty:(space) to print
  110.         int 10h         ;prints (space)
  111.         mov bl,07       ;color
  112.         mov ax,0e20h    ;tty:(space) to print
  113.         int 10h         ;prints (sp)
  114.         mov bl,07       ;color
  115.         mov ax,0e31h    ;tty:1 to print
  116.         int 10h         ;prints 1
  117. ;
  118.         mov ah,2        ;set cursor
  119.         inc dh          ;row=5
  120.         mov dl,0        ;col=0
  121.         int 10h         ;set cur at 5,0
  122.         mov bl,07       ;color
  123.         mov ax,0e48h    ;tty:H to print
  124.         int 10h         ;prints H, moves cur
  125.         mov bl,07       ;color
  126.         mov ax,0e20h    ;tty:(sp) to print
  127.         int 10h         ;print (sp)
  128.         mov bl,07       ;color
  129.         mov ax,0e20h    ;tty:(sp) to print
  130.         int 10h         ;prints (sp)
  131.         mov bl,07       ;color
  132.         mov ax,0e30h    ;tty:0 to print
  133.         int 10h         ;print 0
  134. ;
  135.         mov ah,2        ;set cursor
  136.         inc dh          ;row=6
  137.         mov dl,02       ;col=2
  138.         int 10h         ;set cursor 6,2
  139.         mov bl,07       ;color
  140.         mov ax,0e2dh    ;tty:"-" to print
  141.         int 10h         ;prints "-"
  142.         mov bl,07       ;color
  143.         mov ax,0e31h    ;tty:1 to print
  144.         int 10h         ;print 1
  145. ;
  146.         dec cx          ;another loop done
  147.         jcxz go_on      ;go on if 4 loops done
  148.         jmp wrt         ;do another loop if not
  149. ;
  150. go_on:  mov cl,34h      ;put chan no (4) into CL
  151.         mov dl,0        ;column 0 for all
  152.         mov dh,0        ;initialize row
  153. ;
  154. wch:    mov ah,2        ;set cursor
  155.         add dh,6        ;set row to 6,12,18 or 24
  156.         int 10h         ;set cursor to 0,6or12etc
  157.         mov bl,07       ;color
  158.         mov ah,0eh      ;tty
  159.         mov al,cl       ;move chan no into al
  160.         int 10h         ;prints channel no
  161.         dec cl          ;reduce channel no
  162.         cmp cl,30h      ;done?
  163.         jnz wch         ;no, loop to wch
  164. ;
  165.                         ;now write dot matrix
  166.         mov cx,39d      ;column number
  167. hdots:  mov dx,11d      ;row number
  168. vdots:  mov ax,0c01h    ;write dot:color 1 ????? 7?
  169.         int 10h         ;write dot
  170.         add dx,8d       ;add 8d to row no
  171.         cmp dx,196d     ;compare with 196 (max 195d)
  172.         jb vdots        ;more vertical if less
  173.         add cx,30d      ;add 30 to column
  174.         cmp cx,640d     ;at right of screen yet?
  175.         jb hdots        ;no, another vertical line of dots
  176. ;-----------------------
  177. ; Read channels at port, calculate time counts for each
  178. ;
  179.         mov si,39d      ;set initial column count for data pts
  180. nw_col: mov dx,0201h    ;Game Port address
  181.         mov cx,00ffh    ;counter for loop; gives same res as BAS
  182.         mov bx,000fh    ;bh:# pushes  bl:4-channel mask
  183.         cli             ;briefly disable interrupts
  184.         out dx,al       ;fire the game-port one-shots
  185. stick1: in al,dx        ;read the game port
  186.         and al,0fh      ;mask off switches, allow 4-chan
  187.         cmp al,bl       ;any one-shots dropped yet?
  188.         loopz stick1    ;loop until one drops or timeout
  189.                         ; loop if zero flag set & cx not 0
  190.         jcxz stick2     ;jump on timeout to stick2 (only exit)
  191.         xor al,bl       ;set to 1 those dropped (drop mask)
  192.         mov ah,cl       ;put countdown time count in AH
  193.         push ax         ;save countdown:drop-mask on stack
  194.         inc bh          ;increment # pushes (# dropmasks)
  195.         xor bl,al       ;new dropmask for remaining channels
  196.         jmp stick1      ;jump until TIMEOUT
  197.                         ;could cmp bl,0 : jnz stick1 : here
  198. stick2: or bh,bh        ;test for no valid data (no pushes)
  199.         jz exit         ; if timed out with no drops
  200.         mov dl,bh       ;number of stack pushes (dropmasks)
  201. stick3: lea bx,s_table  ;point to result table
  202.         pop ax          ;get last-saved countdown:dropmask
  203.         not ah          ;convert to plus time interval 
  204.         add ah,1        ; via two's complement
  205.         mov cx,0004h    ;loop counter for number of channels
  206. stick4: shr al,1        ;shift LSB to carry
  207.         jnb stick5      ;jump if CF=0 (if LSB was 0)
  208.         mov [bx],ah      ;if LSB was 1, save val in s_table
  209. stick5: add bx,2        ;point to next s_table location
  210.         loop stick4     ;test next bit, do 4 times total
  211.         dec dl          ;dec. pops (countdown:dropmask)'s remaining
  212.         jnz stick3      ;get next data from stack if any left
  213. exit:   sti             ;set interrupts, exit this area
  214. ;-----------------------
  215. ; Get results, calculate and plot data points
  216. ;
  217.         mov bx,0        ;set up offsets into tables
  218.         mov di,187d     ;put bottom (Ch 1) zero line in DI
  219. read1:  mov cx,s_table[bx] ;get reading into CX
  220.         mov dx,0        ;put zeros in DX (high word)
  221.         mov ax,0ffffh   ;put 65535d in ax
  222.         div cx          ;65535/reading, result in AX
  223.         mov cx,of_stor[bx] ;get offset in CX
  224.         sub ax,cx       ;subtract offset
  225.         jnb read2       ;jump if ax>=cx, -> pos value
  226. ;-----------------------
  227.         not ax          ;if neg value, convert to plus
  228.         add ax,1        ;  via 2's complement
  229.         mov cl,3        ;set up shift left 3
  230.         shl ax,cl       ; shift left 3, multiplies by 8
  231.         mov dx,0        ;put zeros in DX (high word)
  232.                         ;DX:AX now has val for division by fac
  233.         mov cx,fa_stor[bx] ;get factor in CX
  234.         div cx          ;8*(1/data - offset)/factor, res in AX
  235.         mov dx,di       ;put zero line position in DX
  236.         add dx,ax       ;get vertical (row) value to plot
  237.                         ; (value is less than zero)
  238.         jmp plot        ;go to plot point
  239. ;-----------------------
  240. read2:  mov cl,3        ;set up shift left 3
  241.         shl ax,cl       ; shift left 3, multiplies by 8
  242.         mov dx,0        ;put zeros in DX (high word)
  243.                         ;DX:AX now has val for div by factor
  244.         mov cx,fa_stor[bx] ;get factor in CX
  245.         div cx          ;8*91/data - offset)/factor, res in AX
  246.         mov dx,di       ;put zero line position in DX
  247.         sub dx,ax       ;get vertical (row) value to plot
  248.                         ; (value is positive voltage)
  249. ;-----------------------
  250. plot:   mov cx,si       ;move column number into CX
  251.         mov ax,0c01h    ;write-dot:color-1
  252.         int 10h         ;write dot
  253.         sub di,48d      ;set new zero line for next channel
  254.         add bx,2        ;set new offset into tables
  255.         cmp bx,8        ;are all four channels plotted?
  256.         jnz read1       ; no, so get next value to plot
  257.         mov cx,s_trace  ;yes, so see if "save" is active
  258.         and cx,2        ; it is if 2 is set
  259.         jz n_save       ; if no save, go to n_save
  260.         mov bx,0        ;set BX as index to zero
  261.         mov di,si       ;put column count in DI
  262.         sub di,39d      ;normalize to make first column = 0
  263.         shl di,1        ;multiply di by 2, then again
  264.         shl di,1        ; by 2, so mult by 4 so far,
  265.         shl di,1        ; then again by 2, net mult by 8
  266. xy:     mov ax,[s_table + bx] ;put result word in AX
  267.         mov [s_data+di+bx],ax ;put word into data table
  268.         add bx,2        ;increment bx 2 bytes
  269.         cmp bx,8        ;have we put all 4 values in table?
  270.         jnz xy          ; no, put in another word
  271. n_save: inc si          ;increment column index
  272.         cmp si,639      ;are all columns plotted?
  273.         jz trck         ;yes, go to single-trace check
  274.         jmp nw_col      ;no, fire one-shots again
  275. ; If save is activated, save s_data to c:data.dat
  276. trck:   mov cx,s_trace
  277.         and cx,2        ;see if save is active
  278.         jz ns_trck      ;if no save, jump to ns_trck
  279.         mov bx,handle   ;put handle in BX
  280.         mov dx,offset s_data ;put address of data table in DX
  281.         mov cx,4800d    ;put number of bytes in CX
  282.         mov ah,40h      ;write to file function
  283.         int 21h         ;call dos
  284.         jnc ns_trck     ;if no error, go on
  285.         jmp getout      ; if error, get out
  286. ns_trck: mov cx,s_trace ;move single-trace to CX 1-yes 0-no
  287.         and cx,1        ; are we in single trace mode?
  288.         jnz newtr       ; yes, jump to wait for key 
  289.         mov ah,0bh      ;get keyboard status no wait
  290.         int 21h         ;see if key is pressed
  291.         inc al          ; if AL ffh then 
  292.         jz newtr        ; key pressed, see which one
  293.         jmp newsc       ;no key, make new screen
  294. newtr:  mov ah,8h       ;load keyboard wait function
  295.         int 21h         ;get keyboard input
  296.         cmp al,27d      ; is it escape? 
  297.         jz f_close      ;yes, exit the program
  298.         jmp newsc       ;no, make new screen
  299. ;
  300. ; Close the file if it was opened
  301. f_close:
  302.         mov cx,s_trace  ;see if save is active
  303.         and cx,2        ; it is if 2 is set
  304.         jz getout       ; if not, exit program
  305.         mov bx,handle   ; if it is, put handle in BX
  306.         mov ah,3eh      ;close handle function
  307.         int 21h         ;call dos
  308. ;
  309. getout: mov ah,0        ;video funtion 0, set mode
  310.         mov al,3        ;mode 3, 80x25 color, text mode
  311.         int 10h         ;call video i/o routine
  312.         pop bp          ;prepare to return to BASIC
  313.         ret 18d         ;return to BASIC, pop 9 words
  314. scndraw endp
  315. code    ends            ;end of code segment
  316.         end            
  317.