home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_06 / 9n06042a < prev    next >
Text File  |  1991-03-01  |  5KB  |  109 lines

  1. ;-- Listing 1    (RDSCRN.ASM)
  2. ;                APL to C Interface Routine
  3. ;
  4. ;                When called from APL,
  5. ;                 -  BX contains argument pointer,
  6. ;                 -  CX contains result pointer.
  7. ;
  8. ;                Note that this will create a Binary Image!
  9.  
  10. _TEXT       SEGMENT             ; define code segment
  11.             assume cs:_TEXT, ds:_TEXT, ss:_TEXT, es:_TEXT
  12.  
  13. EXTRN       _result_size:NEAR
  14. EXTRN       _read_screen_blocks:NEAR
  15.  
  16.             org     0h      ; APL starts at 0
  17. start:      db 10 dup(90h)  ; need 10 NOPs to get offsets
  18.                             ; (relative to CS) correct.
  19.                             ; These would be dropped in APL
  20.             jmp     short begin
  21.  
  22. ; ... insert constants and data here - will be relative to CS
  23. arg_ptr     dw      0       ; stptr of arg
  24. arg_data    dw      0       ; where data starts in argument
  25. arg_rows    dw      0       ; number of rows in argument
  26. res_ptr     dw      0       ; stptr of result
  27. res_type    db      1       ; define result type of char
  28. res_rank    db      2       ;   "    rank as 2 dim matrix
  29. res_rows    dw      0       ; nbr rows in result - filled in later
  30. res_cols    dw      0       ; nbr cols in result     "     "   "
  31.  
  32. begin:
  33. main      proc   far            ; APL needs far return
  34.           push   cx
  35.           push   dx
  36.           push   ds
  37.           push   si
  38.  
  39.           int    3              ; useful for debugging purposes!
  40.  
  41.           mov    cs:arg_ptr,bx  ; save argument pointer
  42.           mov    cs:res_ptr,cx  ; save result pointer
  43.  
  44.           ; check that input variable proper type, rank and size
  45.           mov    ds,[bx]        ; load argument SEGMENT to DS
  46.           mov    si,6           ; SI pts to rank,type of APL arg
  47.           lodsw                 ; load rank,type to AX
  48.           cmp    al,2           ; is 2 byte integer?
  49.           jne    bummer         ; no, quit
  50.           mov    cx,1           ; for vector,init CX w/1 row in arg
  51.           cmp    ah,1           ; is vector? (ie,rank=1)
  52.           je     arg_chk        ; yes, get on with it,check arg size
  53.           cmp    ah,2           ; is 2 dim matrix? (ie,rank=2)
  54.           jne    bummer         ; nope, quit
  55.           mov    cx,[si]        ; yes, get next word, 1st dim to CX
  56.           inc    si             ; get SI to pt to last dimension
  57.           inc    si             ; for rank 2 matrix
  58.           jmp    arg_chk        ; ok .. check argument size
  59.  
  60. bummer:   int    0              ; signal domain error + quit
  61.  
  62. arg_chk:  ; check that last dimension = 4
  63.           lodsw                 ; load last dimension to AX
  64.           cmp    ax,4           ; if not 4
  65.           jne    bummer         ; quit with error
  66.           mov    cs:arg_data,si ; save this for posterity
  67.           mov    cs:arg_rows,cx ;        d i t t o
  68.  
  69. res_size: ; Call RESULT_SIZE to calculate size of final result
  70.           lea    ax,res_cols    ; get offset of #cols
  71.           push   cs             ;  .. push segment
  72.           push   ax             ;  .. and offset
  73.           lea    ax,res_rows    ; get offset of # rows
  74.           push   cs             ;  .. push segment
  75.           push   ax             ;  .. and offset
  76.           push   ds             ; push Argument Segment to C
  77.           push   si             ; push Argument data start to C
  78.           push   cx             ; number of rows in argument
  79.           call   _result_size
  80.           add    sp,14
  81.  
  82. make_res: ; create final result object, assign to APL variable
  83.           mov    al,0           ; set for fn 0
  84.           mov    bx,cs:res_ptr  ; load result pointer to BX
  85.           push   cs
  86.           pop    es             ; set up ES:SI with variable
  87.           lea    si,res_type    ; info - type,rank,size(s)
  88.           int    0c8h           ; do the work ...
  89.  
  90. fill_res: ; Call READ_SCREEND_BLOCKS to fill in final result
  91.           push   es             ; load ptr to result from above
  92.           push   di             ; ES:DI pts to data start ...
  93.           push   cs:res_cols    ; load up max nbr cols to C
  94.           push   ds             ; push argument Segment to C
  95.           push   cs:arg_data    ; push arg data start to C
  96.           push   cs:arg_rows    ; number of rows in argument
  97.           call   _read_screen_blocks ; read in data into result
  98.           add    sp,12
  99.  
  100.           pop    si
  101.           pop    ds
  102.           pop    dx
  103.           pop    cx
  104.  
  105.           retf
  106. main      endp
  107. _TEXT     ends
  108.           end    start
  109.