In learning FORTRAN, you sometimes have to simulate complex number functions
without actually using CMPLX(A,B) (which takes the real number A and the
imaginary number B and returns the complex number result) or AIMAG(A) (which
returns the imaginary part of the complex number A). REAL Fortran77 brings an
easy solution: use character strings and simple arithmetic, treating the real
and imaginary parts of the complex numbers separately. Alas, the designers of
Apple FORTRAN chose not to include the character string functions and
procedures.
The following hints at a solution; an end-user wanted to print character
strings in the graphics page using WSTRING(string), which also wasn't
implimented.
The small assembly language function below returns the ascii value of the nth
character of a string. Frustrated Apple FORTRAN programmers will find this
useful.
For the complex function other such routines might need to be written; a
length-of-string and an index function would be very helpful.
;
; Function CHAR1 (string,N)
;
; returns ASCII value of Nth character in string
;
; William B. Judd, TRI, 10/27/83
;
;___________________________________________________________________
.macro pop
pla
sta
.macro push
lda
.func char1,2 ; two parameters
return .equ 0
string .equ 2
n .equ 4
junk .equ 6
pop return ; save return address
pop junk ; discard stack bias
pop junk
pop n ; get n address
pop string ; get string address
lda #0 ; push msb of return value
pha
tay
lda (n),y ; get index value
tay
dey ; reduce offset
lda (string),y ; get nth char
pha ; push value
push return
rts
.end
$EXT integer function char1 2
$uses turtlegraphics
$uses applestuff
c
c to test char1 function
c
program test
character*10 a
a = 'ABCDEFGHIJK'
call inittu
do 10 i=1,10
k = char1(a,i)
10 call wchar (char(k))
c *** hard halt
20 goto 20
end