home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / CLFEB88.ZIP / C&ASM.LTG next >
Encoding:
Text File  |  1988-02-04  |  7.9 KB  |  293 lines

  1. Interfacing C and Assembler by Jean-Pierre Schachter
  2.  
  3. LISTING 1
  4.  
  5. ODOMETER.C
  6.  
  7. #define  VID00   0XB800
  8.  
  9. int scr_start;
  10.  
  11. main ()
  12.      {
  13.      int i;
  14.      unsigned int whereat, meterset ();
  15.      scr_start = VID00;
  16.      cls ();
  17.      whereat = meterset ();
  18.      for (i=0; i<1000;i++)
  19.          {
  20.          bytmeter (whereat);
  21.          }
  22.      }
  23.  
  24. ; meterset.asm  Sept. 1987 J.-P. Schachter
  25. ; in the Public Domain
  26. ; for linking with ECO-C88 C code
  27. ;
  28. EXTRN       _scr_start:WORD
  29. DGROU╨    grou≡    $c$strtseg¼ $d$dataseg¼ $e$usdseg¼ $f$udseg¼ ì
  30.                 $g$uedseg¼ $h$stkseg¼ $i$end,seg
  31. PGROUP    group    $a$chain,$b$prog
  32. ;
  33. $a$chain        segment    public 'code'
  34. $a$chain        ends
  35. ;
  36. $b$prog        segment    word public 'code'
  37. $b$prog        ends
  38. ;
  39. $c$strtseg    segment    public 'data1'
  40. $c$strtseg    ends
  41. ;
  42. $d$dataseg    segment    word public 'data2'
  43. meter db 0,'-',70h,'0',70h,'0',70h,'0',70h,'0',70h,'0',70h,'-',70h,1
  44. $d$dataseg    ends
  45. ;
  46. $e$usdseg    segment    word public 'data3'
  47. $e$usdseg    ends
  48. ;
  49. $f$udseg    segment    word public 'data4'
  50. $f$udseg    ends
  51. ;
  52. $g$uedseg    segment    word public 'data5'
  53. $g$uedseg    ends
  54. ;
  55. $h$stkseg    segment    word STACK 'data6'
  56. è$h$stkseg    ends
  57. ;
  58. $i$endseg    segment    word public 'data7'
  59. $i$endseg    ends
  60. ;
  61. assume cs:PGROUP,ds:DGROUP,es:DGROUP,ss:DGROUP
  62. ;
  63. $b$prog segment public 'code'
  64.       public _meterset
  65. _meterset    proc
  66.       push   bp
  67.       mov    bp,sp
  68.       push   si
  69.       push   di
  70. ;
  71.       mov    ah,15      ; gets video status
  72.       int    10h
  73.       mov    ah,3       ; puts row, col into dh, dl
  74.       int    10h
  75. ;
  76.       mov    al,dh
  77.       mov    bl,dl
  78.       mov    ah,0
  79.       mov    cx,0A0h
  80.       mul    cx         ; multiply rows by 160
  81. ;
  82.       push   ax
  83.       mov    al,bl
  84.       mov    ah,0
  85.       mov    cx,2
  86.       mul    cx         ; multiply part row by two
  87. ;
  88.       mov    cx,ax
  89.       pop    ax
  90.       add    cx,ax
  91. ;
  92.       mov    ax,_scr_start       ; 0xB800 - comp; 0xB000 - mono
  93.       mov    es,ax               ; set the extra segment to screen
  94.       mov    di,cx               ; offset into di
  95.       sub    di,13
  96.       mov    si, offset meter
  97. ;
  98. re:   lodsb                      ; move the string 'meter' into
  99.       cmp    al,1                
  100.       je     over
  101.       mov    BYTE PTR es:[di],al ; the display
  102.       inc    di
  103.       jmp    re
  104. over:
  105.       mov    ax,cx               ; return the offset for bytmeter
  106. ;
  107.       pop    di
  108.       pop    si
  109.       mov    sp,bp
  110.       pop    bp
  111. è      ret
  112. _meterset    endp
  113. $b$prog      ends
  114.       end
  115.  
  116.  
  117. ; bytmeter.asm Sept. 1987 J.-P. Schachter
  118. ; in the Public Domain
  119. ;
  120. ; bytmeter (*char) take a single ppointer to char as a parameter
  121. ;
  122. EXTRN       _scr_start:WORD
  123. ;
  124. ; insert here the lines in meterset.asm from
  125. ; DGROUP group $c$strtseg, $d$dataseg, $e$usdseg, $f$udseg,
  126. ; to
  127. ; $b$prog segment public 'code'
  128. ;
  129.       public _bytmeter
  130. _bytmeter    proc
  131.       push   bp
  132.       mov    bp,sp
  133.       push   si
  134.       push   di
  135. ;
  136.       mov    ax,_scr_start                ;0xB000 for Monochrome
  137.       mov    si, WORD PTR [bp+4]        ;0xB800 for Composite
  138.       add    si,0Eh                    
  139.       mov    es,ax                  ;set the extra segment to screen
  140.       mov    AH,'9'
  141. over: cmp    AH, BYTE PTR es:[si]
  142.       je     sub
  143.       inc    BYTE PTR es:[si]
  144.       jmp    quit
  145. sub:  mov    BYTE PTR es:[si],'0'
  146.       sub    si,02h
  147.       jmp    over
  148. quit:
  149.       pop    di
  150.       pop    si
  151.       mov    sp,bp
  152.       pop    bp
  153.       ret
  154. _bytmeter    endp
  155. $b$prog      ends
  156.       end
  157.  
  158. LISTING 2
  159.  
  160. select.c
  161.  
  162. main () {
  163.      char title[12];
  164.      hilite (title);
  165.      clrscr ();
  166. è     puts (title);
  167.      }
  168.  
  169. ; hilite.asm (c) Sept. 1987 J.-P. Schachter
  170. ; In the Public Domain for personal use only.
  171. ; for linking with Microsoft C code
  172. ; hilite () takes one parameter, a pointer to a 12 character array.
  173. ;
  174. beep  macro
  175.       mov    ah, 2
  176.       mov    dl, 7
  177.       int    21h
  178.       endm
  179. ;
  180. upper_left      equ      1
  181. screen_start    equ      0b800h
  182. normal_display  equ      6
  183. highlit_display equ      70h
  184. cursor_off      equ      20h
  185. up_arrow        equ      48h
  186. left_arrow      equ      4bh
  187. right_arrow     equ      4dh
  188. down_arrow      equ      50h
  189. top_line        equ      160
  190. bottom_right    equ      3968
  191. bottom_line     equ      3840
  192. ;
  193.       TITLE   hilite
  194.       _TEXT SEGMENT  BYTE PUBLIC 'CODE'
  195.       _TEXT ENDS
  196.       _DATA SEGMENT  WORD PUBLIC 'DATA'
  197.       _DATA ENDS
  198.       CONST SEGMENT  WORD PUBLIC 'CONST'
  199.       CONST ENDS
  200.       _BSS SEGMENT  WORD PUBLIC 'BSS'
  201.       _BSS ENDS
  202. ;
  203. DGROUP GROUP CONST, _BSS, _DATA
  204.       ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  205. ;
  206. _TEXT     SEGMENT
  207. ;
  208.       PUBLIC _hilite
  209. _hilite PROC NEAR
  210.       push   bp
  211.       mov    bp,sp
  212. ;
  213.       mov    si, upper_left             ; initial screen offset value
  214.       mov    ax, screen_start           ; display segment
  215.       mov    es, ax            ; set the extra segment to the display
  216.       mov    cl, normal_display         ; normal attribute
  217.       mov    ch, highlit_display        ; highlighted attribute
  218. ;
  219.       mov    ch, cursor_off             ; cursor turn-off value
  220. è      mov    ah, 1                      ; cursor change routine
  221.       int    10h                        ; turn it off
  222. ;
  223.       call   hi_copy                    ; hilite and copy
  224.       jmp    arrowtest                  ; the input loop follows
  225. onerror:     beep
  226. arrowtest:
  227.       mov    ah, 0
  228.       int    16h                        ; read a character
  229.       cmp    al, 01bh                   ; is it ESC?
  230.       je     quit                       ; Yes? Then quit!
  231.       cmp    ah, up_arrow               ; up arrow?
  232.       je     goup                       ;
  233.       cmp    ah, left_arrow             ; left arrow?
  234.       je     goleft                     ;
  235.       cmp    ah, right_arrow            ; right arrow?
  236.       je     goright                    ;
  237.       cmp    ah, down_arrow             ; down arrow?
  238.       je     godown                     ;
  239.       beep                              ; no? Then Beep!
  240.       jmp    arrowtest                  ; and do it again!
  241. goup:
  242.       cmp    si, top_line               ; On the top line?
  243.       jbe    onerror                    ; Then Beep and do again!
  244.       call   hi_copy
  245.       sub    si, 160
  246.       call   hi_copy
  247.       jmp    arrowtest
  248. goleft:
  249.       cmp    si, upper_left             ; Top left corner?
  250.       jbe    onerror                    ; Then Beep and do again!
  251.       call   hi_copy
  252.       sub    si, 32
  253.       call   hi_copy
  254.       jmp    arrowtest
  255. goright:
  256.       cmp    si, bottom_right           ; Bottom right corner?
  257.       jae    onerror
  258.       call   hi_copy
  259.       add    si, 32
  260.       call   hi_copy
  261.       jmp    arrowtest
  262. godown:
  263.       cmp    si, bottom_line            ; Bottom line?
  264.       jae    onerror
  265.       call   hi_copy
  266.       add    si, 160
  267.       call   hi_copy
  268.       jmp    arrowtest
  269. quit:
  270.       mov    ch, 6                      ; cursor start-line
  271.       mov    cl, 7                      ; cursor end-line
  272.       mov    ah, 1                      ; cursor change routine
  273.       int    10h                        ; turn it off
  274.       mov    sp,bp
  275. è      pop    bp
  276.       ret
  277. _hilite ENDP
  278. ;
  279. hi_copy PROC NEAR
  280.       mov    di, [bp+4]                 ; param 1 into di
  281.       mov    bx, 0                      ; counter to 0
  282.       xchg   cl, ch                     ; toggle attribute
  283. nextchar:
  284.       mov    BYTE PTR es:[si], cl       ; change the attribute
  285.       mov    al, BYTE PTR es:[si-1]     ; character into cl
  286.       add    si, 2                      ; inc the screen counter by 2
  287.       mov    BYTE PTR [di+bx], al       ; cl into buffer 'title'
  288.       inc    bx                         ; inc the buffer counter by 1
  289.       cmp    bx, 12                     ; have we done 12 chars?
  290.       jne    nextchar                   ; if not, do more
  291.       sub    si, 24                     ; back to start of field
  292.       ret
  293. hi_copy ENDP
  294.  _TEXT ENDS
  295.  END
  296.  
  297.