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