DIM hin&(360),ref&(360),huello&(180),huellu&(180),r(29),screen%(1)
DIM kurve(600)
DIM u%(90),i%(90)
DIM u(72),i(72)
screen$=SPACE$(32256)
screen%(0)=XBIOS(2)
screen%(1)=INT((VARPTR(screen$)+255)/256)*256
'
REPEAT
  '
  CLS
  PRINT "             Physikprogramme zur Elektrizit„tslehre"
  PRINT "           =========================================="
  PRINT
  PRINT " A   Verst„rkung an einer parabelf”rmigen Kennlinie"
  PRINT
  PRINT " B   Verlauf von U und I auf einem Halbwellendipol"
  PRINT
  PRINT " C   Oberwellenerregung eines geraden Leiters"
  PRINT
  PRINT " D   Rechtecksynthese nach Fourier"
  PRINT
  PRINT " E   Ausbreitung einer elektromagnetischen Welle entlang einer Geraden"
  PRINT
  PRINT " F   Stehende Welle vor total reflektierender Wand"
  PRINT
  PRINT " G   Stehende Welle auf Koaxialkabel mit ver„nderlichem Abschlužwiderstand"
  PRINT
  PRINT
  PRINT " Z   Programmende"
  PRINT
  PRINT
  PRINT " Wahl ?"
  REPEAT
    e$=INKEY$
  UNTIL e$<>""
  CLS
  CLIP 0,0 TO 639,399
  BMOVE XBIOS(2),screen%(1),32000
  '
  '
  SELECT e$
    '
    '
  CASE "A","a"
    '
    ' ARBEITSP: Auswirkung der Wahl des Arbeitspunktes
    '           auf die Verzerrung des Ausgangssignales
    '
    GET 401,20,635,299,re$
    PRINT AT(48,3);"Ia"
    PRINT AT(2,4);"Gittervorspannung „ndern:  <-  ->"
    PRINT AT(2,6);"Eingangsspannung  „ndern:  +    -"
    PRINT AT(2,9);"Programmende:  Taste  q"
    DRAW 250,300
    FOR x=0 TO 149
      y=x*x/100
      DRAW  TO 250+x,300-y
    NEXT x
    SGET bild$
    ugv=-50
    ue=30
    phase=0
    iaalt=200
    REPEAT
      scr(phase MOD 2,(phase+1) MOD 2)
      SPUT bild$
      IF ugv>-150 AND ugv<0
        DEFLINE 2,1,0,0
        DRAW 400+ugv,300 TO 400+ugv,300-(150+ugv)^2/100 TO 400,300-(150+ugv)^2/100
        DEFLINE 1,1,0,0
      ENDIF
      DRAW 400+ugv,399 TO 400+ugv,301
      DRAW 400+ugv+ue*SINQ(phase+3),301
      FOR y=1 TO 98
        DRAW  TO 400+ugv+ue*SINQ(phase+3*y),300+y
      NEXT y
      ug=ugv+ue*SINQ(phase)
      IF ug>0
        ug=0
      ENDIF
      ia=300
      IF ug>-150
        ia=300-(150+ug)^2/100
        IF ug<0
          DEFLINE 3,1,0,0
          DRAW 400+ug,300 TO 400+ug,ia TO 399,ia
          DEFLINE 1,1,0,0
        ENDIF
      ENDIF
      PUT 401,20,re$
      DRAW 400,ia TO 401,iaalt
      IF ugv>-150
        DRAW 400,300-(150+ugv)^2/100 TO 401,300-(150+ugv)^2/100
      ENDIF
      iaalt=ia
      GET 400,20,635,300,re$
      phase=phase+3
      IF phase>359
        phase=0
      ENDIF
      PRINT AT(55,18);"Ug"
      DEFLINE 1,1,0,1
      DRAW 10,300 TO 450,300
      DRAW 400,300 TO 400,20
      DEFLINE 1,1,0,0
      i$=INKEY$
      LPOKE XBIOS(14,1)+6,0
      IF i$<>""
        IF i$="+"
          ue=ue+3
          IF ue>400
            ue=400
          ENDIF
        ENDIF
        IF i$="-"
          ue=ue-3
          IF ue<0
            ue=0
          ENDIF
        ENDIF
        IF LEN(i$)=2
          IF CVI(i$)=75
            ugv=ugv-2
            IF ugv<-350
              ugv=-350
            ENDIF
          ENDIF
          IF CVI(i$)=77
            ugv=ugv+2
            IF ugv>0
              ugv=0
            ENDIF
          ENDIF
        ENDIF
      ENDIF
    UNTIL i$="q"
    scr(0,0)
    '
    '
    '
  CASE "B","b"
    '
    ' DIPOLUI : Spannungs- und Stromverlauf auf einem Dipol
    '
    FOR x=0 TO 54
      u(x)=100*COSQ(10*x/3)
      i(x)=100*SINQ(10*x/3)
    NEXT x
    u=1
    i=1
    REPEAT
      scr(phase MOD 2,(phase+1) MOD 2)
      IF i$="p"
        REPEAT
        UNTIL INKEY$<>""
      ENDIF
      amplu=-COSQ(2*phase)
      ampli=SINQ(2*phase)
      CLS
      PRINT " Spannungsverlauf - u     Stromverlauf - i     Pause - p       Programmende - q"
      IF u
        PRINT " ====================";
      ELSE
        PRINT "                     ";
      ENDIF
      IF i
        PRINT "     ================";
      ELSE
        PRINT "                     ";
      ENDIF
      DRAW 50,220 TO 315,220
      DRAW 325,220 TO 590,220
      DRAW 315,220 TO 315,350
      DRAW 325,220 TO 325,350
      IF u
        DRAW 50,220+amplu*100
        FOR x=0 TO 54
          DRAW  TO 50+10*x,220+amplu*u(x)
        NEXT x
      ENDIF
      IF i
        DRAW 150,220
        FOR x=0 TO 54
          DRAW  TO 50+10*x,220-ampli*i(x)
        NEXT x
      ENDIF
      i$=INKEY$
      LPOKE XBIOS(14,1)+6,0
      IF i$="u"
        u=1-u
        IF u=0 AND i=0
          i=1
        ENDIF
      ENDIF
      IF i$="i"
        i=1-i
        IF i=0 AND u=0
          u=1
        ENDIF
      ENDIF
      IF i$="p"
        PRINT "     ========="
      ENDIF
      INC phase
      IF phase=360
        phase=0
      ENDIF
    UNTIL i$="q"
    scr(0,0)
    '
    '
  CASE "E","e"
    '
    '
    ' ELMAGWEL :  Erzeugt Bilder einer bewegten
    '             elektromagnetischen Welle
    '
    ev=1
    REPEAT
      scr(0,0)
      CLS
      BMOVE screen%(0),screen%(1),32000
      scr(1,0)
      DRAW 0,65 TO 639,385
      IF ew
        DRAW 0,65
        FOR x=0 TO 120
          y=60*SINQ(3*x)
          DRAW  TO x,65-y+x/2
        NEXT x
      ENDIF
      IF mw
        DRAW 0,65
        FOR x=0 TO 120
          y=60*SINQ(3*x)
          DRAW  TO x+y,65+x/2
        NEXT x
      ENDIF
      IF ev
        FOR x=0 TO 120 STEP 6
          y=60*SINQ(3*x)
          DRAW x,65+x/2 TO x,65-y+x/2
        NEXT x
      ENDIF
      IF mv
        FOR x=0 TO 120 STEP 6
          y=60*SINQ(3*x)
          DRAW x,65+x/2 TO x+y,65+x/2
        NEXT x
      ENDIF
      GET 0,17,119,170,a$
      PUT 120,77,a$
      PUT 240,137,a$
      PUT 360,197,a$
      GET 0,17,479,350,a$
      DEFLINE 1,3,0,1
      REPEAT
        x%=0
        y%=0
        REPEAT
          CLS
          PUT x%-120,y%-43,a$
          PUT x%+360,y%+197,a$
          PRINT
          PRINT AT(54,2);"El.  Hllkurve      -  e"
          PRINT AT(54,3);"Mag. Hllkurve      -  m"
          PRINT AT(54,4);"El.  Feldvektoren   -  E"
          PRINT AT(54,5);"Mag. Feldvektoren   -  M"
          PRINT AT(54,6);"Elektrischer Zeiger -  1"
          PRINT AT(54,7);"Magnetischer Zeiger -  2"
          PRINT AT(54,8);"Programmende        -  q"
          IF ew
            PRINT AT(52,2);"*"
          ENDIF
          IF mw
            PRINT AT(52,3);"*"
          ENDIF
          IF ev
            PRINT AT(52,4);"*"
          ENDIF
          IF mv
            PRINT AT(52,5);"*"
          ENDIF
          IF ez
            PRINT AT(52,6);"*"
          ENDIF
          IF mz
            PRINT AT(52,7);"*"
          ENDIF
          IF ez
            LINE 360,245,360,245+60*SINQ(3*x%)
          ENDIF
          IF mz
            LINE 360,245,360+60*SINQ(360-3*x%),245
          ENDIF
          scr(y% MOD 2,(y%+1) MOD 2)
          x%=x%+2
          y%=y%+1
          i$=INKEY$
          LPOKE XBIOS(14,1)+6,0
          SELECT i$
          CASE "e"
            ew=1-ew
          CASE "m"
            mw=1-mw
          CASE "E"
            ev=1-ev
          CASE "M"
            mv=1-mv
          CASE "1"
            ez=1-ez
          CASE "2"
            mz=1-mz
          ENDSELECT
        UNTIL x%>119 OR i$<>""
      UNTIL i$<>""
      DEFLINE 1,1,0,0
    UNTIL i$="q"
    scr(0,0)
    '
    '
  CASE "C","c"
    '
    ' OBERWELL : Spannungs- und Stromverlauf auf einem Dipol,
    '            der auf einer Harmonischen angeregt wird.
    '
    u%=1
    i%=1
    h%=2
    REPEAT
      f=(h%/2-1)/2+1
      FOR x%=0 TO 90
        u%(x%)=100*COSQ(2*h%*x%)/f
        i%(x%)=100*SINQ(2*h%*x%)/f
      NEXT x%
      phase%=0
      REPEAT
        scr(phase% MOD 2,(phase%+1) MOD 2)
        IF i$="p"
          REPEAT
          UNTIL INKEY$<>""
        ENDIF
        amplu=-COSQ(2*phase%)
        ampli=SINQ(2*phase%)
        CLS
        PRINT " Spannung: u    Strom: i    Harmonische: 1..9    Pause: p       Programmende: q"
        IF u%
          PRINT AT(2,2);"==========="
        ENDIF
        IF i%
          PRINT AT(17,2);"========"
        ENDIF
        PRINT AT(2,4);h%-1;". Harmonische      Dipoll„nge = ";h%/2
        PRINT AT(38,4);" * Wellenl„nge      f = ";h%
        PRINT AT(64,4);" * Grundfrequenz"
        DRAW 5,220 TO 635,220
        DRAW 5,221 TO 635,221
        IF u%
          DRAW 5,220+amplu*100/f
          FOR x%=0 TO 90
            DRAW  TO 5+7*x%,220+amplu*u%(x%)
          NEXT x%
        ENDIF
        IF i%
          DRAW 5,220
          FOR x%=0 TO 90
            DRAW  TO 5+7*x%,220-ampli*i%(x%)
          NEXT x%
        ENDIF
        i$=INKEY$
        LPOKE XBIOS(14,1)+6,0
        IF i$<>""
          IF i$="u"
            u%=1-u%
            IF u%=0 AND i%=0
              i%=1
            ENDIF
          ENDIF
          IF i$="i"
            i%=1-i%
            IF i%=0 AND u%=0
              u%=1
            ENDIF
          ENDIF
          IF i$="p"
            PRINT AT(50,2);"========"
          ENDIF
        ENDIF
        INC phase%
        IF phase%=360
          phase%=0
        ENDIF
      UNTIL (VAL(i$)>0 AND VAL(i$)<10) OR i$="q"
      h%=VAL(i$)+1
    UNTIL i$="q"
    scr(0,0)
    '
    '
  CASE "D","d"
    '
    ' RECHTECK : Fourier - Synthese einer Rechteckspannung
    '
    PRINT " Summe aus Grundfrequenz und ungeradzahligen Vielfachen bis zum "
    DRAW 20,145 TO 640,145
    FOR x=0 TO 600 STEP 2
      PSET x+20,145-120*SINQ(x),1
    NEXT x
    DRAW 20,350 TO 620,350
    PRINT AT(2,18);"Als n„chstes wird die      -fache Frequenz mit der Amplitude 1/     addiert"
    SGET a$
    ord=1
    FOR x=0 TO 600
      kurve(x)=120*SIN(x*PI/180)
    NEXT x
    REPEAT
      SPUT a$
      PRINT AT(65,1);ord;" - fachen"
      DRAW 20,145
      FOR x=1 TO 600
        DRAW  TO x+20,145-kurve(x)
      NEXT x
      ord=ord+2
      PRINT AT(24,18);ord
      PRINT AT(65,18);ord
      DRAW 20,350
      FOR x=1 TO 600
        y=120*SIN(ord*x*PI/180)/ord
        DRAW  TO x+20,350-y
        kurve(x)=kurve(x)+y
      NEXT x
      PRINT AT(7,13);"Taste !"
      PRINT AT(5,15);"oder  q  fr"
      PRINT AT(5,16);"Programmende"
      i=INP(2)
      LPOKE XBIOS(14,1)+6,0
    UNTIL i=113
    '
    '
  CASE "F","f"
    '
    ' STEHWELL: Darstellung einer stehenden Welle vor einer reflektierenden Wand
    '
    ARRAYFILL hin&(),0
    ARRAYFILL ref&(),0
    ARRAYFILL huello&(),0
    ARRAYFILL huellu&(),0
    z1&=80
    z2&=160
    z3&=335
    PRINT " Einhllende: e      Seilende lose / fest        Pause: p       Programmende: q"
    PRINT AT(69,5);"hinlaufende"
    PRINT AT(69,6);"Welle"
    PRINT AT(69,10);"reflektierte"
    PRINT AT(69,11);"Welle"
    PRINT AT(69,21);"beobachtete"
    PRINT AT(69,22);"Welle"
    DRAW 0,z1& TO 540,z1&
    DRAW 0,z2& TO 540,z2&
    DRAW 0,z3& TO 540,z3&
    DRAW 540,z1&-33 TO 540,z1&+33
    DRAW 540,z2&-33 TO 540,z2&+33
    DRAW 540,z3&-33 TO 540,z3&+33
    SGET bild$
    anf&=180
    abschl&=1
    REPEAT
      scr(anf& MOD 2,(anf&+1) MOD 2)
      SPUT bild$
      IF e&
        PRINT AT(2,2);"=============="
      ENDIF
      IF abschl&=1
        PRINT AT(31,2);"====     "
      ELSE
        PRINT AT(30,2);"        ===="
      ENDIF
      hin&(anf&)=30*SINQ(6*anf&)
      DRAW 0,hin&(anf&)+z1&
      FOR x&=0 TO 180
        DRAW  TO 3*x&,hin&(x&+anf&)+z1&
      NEXT x&
      ref&(anf&)=abschl&*hin&(anf&+180)
      DRAW 0,ref&(anf&+180)+z2&
      FOR x&=0 TO 180
        DRAW  TO 3*x&,ref&(anf&+180-x&)+z2&
      NEXT x&
      DRAW 0,hin&(anf&)+ref&(anf&+180)+z3&
      FOR x&=0 TO 180
        h&=hin&(x&+anf&)+ref&(anf&+180-x&)
        DRAW  TO 3*x&,h&+z3&
        IF e&
          IF huello&(x&)<h&
            huello&(x&)=h&
          ENDIF
          IF huellu&(x&)>h&
            huellu&(x&)=h&
          ENDIF
        ENDIF
      NEXT x&
      IF e&
        FOR x&=0 TO 180
          DRAW 3*x&,huello&(x&)+z3&
          DRAW 3*x&,huellu&(x&)+z3&
        NEXT x&
      ENDIF
      hin&(anf&+180)=hin&(anf&)
      ref&(anf&+180)=ref&(anf&)
      IF i$="p"
        REPEAT
        UNTIL INP?(2)
        ~INP(2)
      ENDIF
      i$=INKEY$
      LPOKE XBIOS(14,1)+6,0
      IF i$<>""
        IF i$="p"
          PRINT AT(50,2);"========";
        ENDIF
        IF i$="l"
          abschl&=1
        ENDIF
        IF i$="f"
          abschl&=-1
        ENDIF
        IF i$="e"
          e&=1-e&
          IF e&
            FOR n&=0 TO 180
              huello&(n&)=0
              huellu&(n&)=0
            NEXT n&
          ENDIF
        ENDIF
      ENDIF
      DEC anf&
      IF anf&<1
        anf&=180
      ENDIF
    UNTIL i$="q"
    scr(0,0)
    '
    '
    '
  CASE "G","g"
    '
    ' STWKOAX: Darstellung einer stehenden Welle auf einem Koaxialkabel
    '
    ARRAYFILL hin&(),0
    ARRAYFILL ref&(),0
    ARRAYFILL huello&(),0
    ARRAYFILL huellu&(),0
    RESTORE
    FOR n%=0 TO 29
      READ r(n%)
    NEXT n%
    z1%=80
    z2%=160
    z3%=335
    PRINT " R gr”žer/kleiner: +-      Einhllende: e      Pause: p         Programmende: q"
    PRINT AT(69,5);"hinlaufende"
    PRINT AT(69,6);"Welle"
    PRINT AT(69,10);"reflektierte"
    PRINT AT(69,11);"Welle"
    PRINT AT(2,16);"Koaxialkabel mit Wellenwiderstand  50 Ohm          SWR ="
    PRINT AT(70,14);"Abschluž-"
    PRINT AT(70,15);"widerstand"
    PRINT AT(72,19);"Ohm"
    PRINT AT(69,21);"beobachtete"
    PRINT AT(69,22);"Welle"
    DRAW 0,z1% TO 540,z1%
    DRAW 0,z2% TO 540,z2%
    BOX -1,239,540,256
    BOX 555,243,577,251
    DRAW 541,247 TO 554,247
    DRAW 578,247 TO 587,247 TO 587,256 TO 541,256
    DRAW 0,z3% TO 540,z3%
    SGET bild$
    anf%=180
    REPEAT
      scr(anf% MOD 2,(anf%+1) MOD 2)
      SPUT bild$
      PRINT AT(60,16);swr
      PRINT AT(72,18);r(rz%)
      IF e%
        PRINT AT(28,2);"=============="
      ENDIF
      hin&(anf%)=30*SINQ(6*anf%)
      DRAW 0,hin&(anf%)+z1%
      FOR x%=0 TO 180
        DRAW  TO 3*x%,hin&(x%+anf%)+z1%
      NEXT x%
      ref&(anf%)=rf*hin&(anf%+180)
      DRAW 0,ref&(anf%+180)+z2%
      FOR x%=0 TO 180
        DRAW  TO 3*x%,ref&(anf%+180-x%)+z2%
      NEXT x%
      DRAW 0,hin&(anf%)+ref&(anf%+180)+z3%
      FOR x%=0 TO 180
        h%=hin&(x%+anf%)+ref&(anf%+180-x%)
        DRAW  TO 3*x%,h%+z3%
        IF e%
          IF huello&(x%)<h%
            huello&(x%)=h%
          ENDIF
          IF huellu&(x%)>h%
            huellu&(x%)=h%
          ENDIF
        ENDIF
      NEXT x%
      IF e%
        FOR x%=0 TO 180
          DRAW 3*x%,huello&(x%)+z3%
          DRAW 3*x%,huellu&(x%)+z3%
        NEXT x%
      ENDIF
      hin&(anf%+180)=hin&(anf%)
      ref&(anf%+180)=ref&(anf%)
      IF i$="p"
        REPEAT
        UNTIL INP?(2)
        ~INP(2)
      ENDIF
      i$=INKEY$
      LPOKE XBIOS(14,1)+6,0
      IF i$<>""
        IF i$="p"
          PRINT AT(48,2);"========";
        ENDIF
        IF i$="e"
          e%=1-e%
          IF e%
            FOR n%=0 TO 180
              huello&(n%)=0
              huellu&(n%)=0
            NEXT n%
          ENDIF
        ENDIF
        IF i$="+" OR i$="-"
          FOR n%=0 TO 180
            huello&(n%)=0
            huellu&(n%)=0
          NEXT n%
        ENDIF
        IF i$="+"
          INC rz%
          IF rz%>29
            rz%=0
          ENDIF
        ENDIF
        IF i$="-"
          DEC rz%
          IF rz%<0
            rz%=29
          ENDIF
        ENDIF
      ENDIF
      rf=(r(rz%)-50)/(r(rz%)+50)
      swr=ROUND((1+ABS(rf))/(1-ABS(rf)),1)
      DEC anf%
      IF anf%<1
        anf%=180
      ENDIF
    UNTIL i$="q"
    scr(0,0)
    '
    '
  ENDSELECT
  '
UNTIL e$="z" OR e$="Z"
'
'
' Bildschirme umschalten
'
PROCEDURE scr(log&,phys&)
  VOID XBIOS(5,L:screen%(log&),L:screen%(phys&),L:-1)
RETURN
'
DATA .1,1,5,10,12.5,20,25,30,40,45,50,55,60,70,75,80,100,120,150,200
DATA 250,300,400,500,1000,2000,4000,5000,10000,1000000
