home *** CD-ROM | disk | FTP | other *** search
- Interfacing C and Assembler by Jean-Pierre Schachter
-
- LISTING 1
-
- ODOMETER.C
-
- #define VID00 0XB800
-
- int scr_start;
-
- main ()
- {
- int i;
- unsigned int whereat, meterset ();
- scr_start = VID00;
- cls ();
- whereat = meterset ();
- for (i=0; i<1000;i++)
- {
- bytmeter (whereat);
- }
- }
-
- ; meterset.asm Sept. 1987 J.-P. Schachter
- ; in the Public Domain
- ; for linking with ECO-C88 C code
- ;
- EXTRN _scr_start:WORD
- DGROU╨ grou≡ $c$strtseg¼ $d$dataseg¼ $e$usdseg¼ $f$udseg¼ ì
- $g$uedseg¼ $h$stkseg¼ $i$end,seg
- PGROUP group $a$chain,$b$prog
- ;
- $a$chain segment public 'code'
- $a$chain ends
- ;
- $b$prog segment word public 'code'
- $b$prog ends
- ;
- $c$strtseg segment public 'data1'
- $c$strtseg ends
- ;
- $d$dataseg segment word public 'data2'
- meter db 0,'-',70h,'0',70h,'0',70h,'0',70h,'0',70h,'0',70h,'-',70h,1
- $d$dataseg ends
- ;
- $e$usdseg segment word public 'data3'
- $e$usdseg ends
- ;
- $f$udseg segment word public 'data4'
- $f$udseg ends
- ;
- $g$uedseg segment word public 'data5'
- $g$uedseg ends
- ;
- $h$stkseg segment word STACK 'data6'è$h$stkseg ends
- ;
- $i$endseg segment word public 'data7'
- $i$endseg ends
- ;
- assume cs:PGROUP,ds:DGROUP,es:DGROUP,ss:DGROUP
- ;
- $b$prog segment public 'code'
- public _meterset
- _meterset proc
- push bp
- mov bp,sp
- push si
- push di
- ;
- mov ah,15 ; gets video status
- int 10h
- mov ah,3 ; puts row, col into dh, dl
- int 10h
- ;
- mov al,dh
- mov bl,dl
- mov ah,0
- mov cx,0A0h
- mul cx ; multiply rows by 160
- ;
- push ax
- mov al,bl
- mov ah,0
- mov cx,2
- mul cx ; multiply part row by two
- ;
- mov cx,ax
- pop ax
- add cx,ax
- ;
- mov ax,_scr_start ; 0xB800 - comp; 0xB000 - mono
- mov es,ax ; set the extra segment to screen
- mov di,cx ; offset into di
- sub di,13
- mov si, offset meter
- ;
- re: lodsb ; move the string 'meter' into
- cmp al,1
- je over
- mov BYTE PTR es:[di],al ; the display
- inc di
- jmp re
- over:
- mov ax,cx ; return the offset for bytmeter
- ;
- pop di
- pop si
- mov sp,bp
- pop bpè ret
- _meterset endp
- $b$prog ends
- end
-
-
- ; bytmeter.asm Sept. 1987 J.-P. Schachter
- ; in the Public Domain
- ;
- ; bytmeter (*char) take a single ppointer to char as a parameter
- ;
- EXTRN _scr_start:WORD
- ;
- ; insert here the lines in meterset.asm from
- ; DGROUP group $c$strtseg, $d$dataseg, $e$usdseg, $f$udseg,
- ; to
- ; $b$prog segment public 'code'
- ;
- public _bytmeter
- _bytmeter proc
- push bp
- mov bp,sp
- push si
- push di
- ;
- mov ax,_scr_start ;0xB000 for Monochrome
- mov si, WORD PTR [bp+4] ;0xB800 for Composite
- add si,0Eh
- mov es,ax ;set the extra segment to screen
- mov AH,'9'
- over: cmp AH, BYTE PTR es:[si]
- je sub
- inc BYTE PTR es:[si]
- jmp quit
- sub: mov BYTE PTR es:[si],'0'
- sub si,02h
- jmp over
- quit:
- pop di
- pop si
- mov sp,bp
- pop bp
- ret
- _bytmeter endp
- $b$prog ends
- end
-
- LISTING 2
-
- select.c
-
- main () {
- char title[12];
- hilite (title);
- clrscr ();è puts (title);
- }
-
- ; hilite.asm (c) Sept. 1987 J.-P. Schachter
- ; In the Public Domain for personal use only.
- ; for linking with Microsoft C code
- ;
- ; hilite () takes one parameter, a pointer to a 12 character array.
- ;
- beep macro
- mov ah, 2
- mov dl, 7
- int 21h
- endm
- ;
- upper_left equ 1
- screen_start equ 0b800h
- normal_display equ 6
- highlit_display equ 70h
- cursor_off equ 20h
- up_arrow equ 48h
- left_arrow equ 4bh
- right_arrow equ 4dh
- down_arrow equ 50h
- top_line equ 160
- bottom_right equ 3968
- bottom_line equ 3840
- ;
- TITLE hilite
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- _TEXT ENDS
- _DATA SEGMENT WORD PUBLIC 'DATA'
- _DATA ENDS
- CONST SEGMENT WORD PUBLIC 'CONST'
- CONST ENDS
- _BSS SEGMENT WORD PUBLIC 'BSS'
- _BSS ENDS
- ;
- DGROUP GROUP CONST, _BSS, _DATA
- ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
- ;
- _TEXT SEGMENT
- ;
- PUBLIC _hilite
- _hilite PROC NEAR
- push bp
- mov bp,sp
- ;
- mov si, upper_left ; initial screen offset value
- mov ax, screen_start ; display segment
- mov es, ax ; set the extra segment to the display
- mov cl, normal_display ; normal attribute
- mov ch, highlit_display ; highlighted attribute
- ;
- mov ch, cursor_off ; cursor turn-off valueè mov ah, 1 ; cursor change routine
- int 10h ; turn it off
- ;
- call hi_copy ; hilite and copy
- jmp arrowtest ; the input loop follows
- onerror: beep
- arrowtest:
- mov ah, 0
- int 16h ; read a character
- cmp al, 01bh ; is it ESC?
- je quit ; Yes? Then quit!
- cmp ah, up_arrow ; up arrow?
- je goup ;
- cmp ah, left_arrow ; left arrow?
- je goleft ;
- cmp ah, right_arrow ; right arrow?
- je goright ;
- cmp ah, down_arrow ; down arrow?
- je godown ;
- beep ; no? Then Beep!
- jmp arrowtest ; and do it again!
- goup:
- cmp si, top_line ; On the top line?
- jbe onerror ; Then Beep and do again!
- call hi_copy
- sub si, 160
- call hi_copy
- jmp arrowtest
- goleft:
- cmp si, upper_left ; Top left corner?
- jbe onerror ; Then Beep and do again!
- call hi_copy
- sub si, 32
- call hi_copy
- jmp arrowtest
- goright:
- cmp si, bottom_right ; Bottom right corner?
- jae onerror
- call hi_copy
- add si, 32
- call hi_copy
- jmp arrowtest
- godown:
- cmp si, bottom_line ; Bottom line?
- jae onerror
- call hi_copy
- add si, 160
- call hi_copy
- jmp arrowtest
- quit:
- mov ch, 6 ; cursor start-line
- mov cl, 7 ; cursor end-line
- mov ah, 1 ; cursor change routine
- int 10h ; turn it off
- mov sp,bpè pop bp
- ret
- _hilite ENDP
- ;
- hi_copy PROC NEAR
- mov di, [bp+4] ; param 1 into di
- mov bx, 0 ; counter to 0
- xchg cl, ch ; toggle attribute
- nextchar:
- mov BYTE PTR es:[si], cl ; change the attribute
- mov al, BYTE PTR es:[si-1] ; character into cl
- add si, 2 ; inc the screen counter by 2
- mov BYTE PTR [di+bx], al ; cl into buffer 'title'
- inc bx ; inc the buffer counter by 1
- cmp bx, 12 ; have we done 12 chars?
- jne nextchar ; if not, do more
- sub si, 24 ; back to start of field
- ret
- hi_copy ENDP
- _TEXT ENDS
- END
-