;------------------------------------------------ ; Scientific interface driver routines from BASIC. ; ; B.J.Frost, July 1986, V1.1 ;------------------------------------------------ ; ; This program is loaded and run by the BASIC supplied- ; -driver routines DRV.BAS. ; ; This program is relocatable and performs one read of- ; -the dual-slope A/D converter placing the result into- ; -a string set up by BASIC. ; equates: dsadad equ 0a0h ; dual-slope a/d port ref ; program commences with jump table dsad jr xdsad ; go to A/D read routine stop defb 0f7h ; debug breakpoint ; Read dual slope converter to string descriptor. ; ; 'HL' points to string descriptor, string descriptor ; contains 'byte count, address of string'. BCD read ; from A/D is overwritten into string. ; first, read the A/D data. Four words of raw A/D output ; are pushed to stack. xdsad di ; interrupts off please! ad11 in a,(dsadad) ; get port byte and 80H ; EOC high? jr z,ad11 ; no, loop. ad2 in a,(dsadad) ; read port again and 80H ; EOC low? jr nz, ad2 ; no, loop. ; fetch first BCD digit by DS0=1. ad3 in a,(dsadad) ; get port again ld b,a ; saved and 10H ; digit select 0 is =1 ? jr z,ad3 ; no, loop. ad4 ld a,b ; restore reading and 0fH ; keep BCD push af ; and save to stack. ; fetch digit 1 by DS1,3=0. ad5 in a,(dsadad) ; get port ld b,a ; save reading and 20H ; next digit? jr nz, ad5 ;no. ld a,b ; yes. restore reading and 0fH ; keep BCD push af ; save to stack ; fetch digit 2 by DS2=1. ad6 in a,(dsadad) ; get port ld b,a ; saved and 40H ; next digit? jr z,ad6 ; no. ld a,b ; yes. restore. and 0fH ; keep BCD push af ; save to stack ; fetch digit 3 by DS1,3=0. ad7 in a,(dsadad) ; get port ld b,a ; saved and 20H ; next digit? jr nz, ad7 ; no ld a,b ; yes. restore and 0fH ; keep BCD push af ; save to stack. ; string descriptor pointer in 'HL', data on stack, ; pull off stack LSD first and decode. inc hl ; point stored string addr ld e,(hl) inc hl ld d,(hl) ex de,hl ; got string address to hl ld de,5 add hl,de ; point end of string (LS BCD digit) ; firstly, get the last BCD digit, pop af ; pull from stack add a,30H ; into BCD ld (hl),a ; into string position dec hl ; back up string pointer ; next, get the middle BCD digit, pop af add a,30H ld (hl),a dec hl ; next, get the first BCD digit, pop af add a,30H ld (hl),a dec hl ; do fixed decimal point, ld a,"." ; dec pt ld (hl),a ; to string dec hl ; up pointer ; now get the MSD for 'half' digit and polarity. pop af ; fetch from stack ; do 'half digit: ld b,a ; save it ld c,"0" ; assume zero and 08H ; mask digit bit jr nz, iszer ; is zero (bit is 1) ld c,"1" ; is a one iszer ld (hl),c ; MS digit to string ld a,b ; restore raw MSD value dec hl ; back up string pointer ; now do polarity: ld c,"+" ; assume positive and 04H ; mask polarity jr nz, ispos ; is positive ld c,"-" ; load - character ispos ld (hl),c ; polarity to string ; return to BASIC ret end