home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / amiga-flight / programs / demo.asm < prev    next >
Assembly Source File  |  1977-12-31  |  10KB  |  247 lines

  1. *****************************************************************************
  2. ***                              DEMO.ASM                                 ***
  3. ***                                                                       ***
  4. ***    Author : Andrew Duffy                                              ***
  5. ***    Date   : June 1994                                                 ***
  6. ***    Desc.  : This program is a combination of Control.asm to control   ***
  7. ***             the heater/fan and Temperature.asm to show the responses  ***
  8. ***             of the heater temperature.                                ***
  9. ***                                                                       ***
  10. ***                          ©XCNT, 1992-1994.                            ***
  11. *****************************************************************************
  12.  
  13.  
  14. *****************************************************************************
  15. ***                              Includes                                 ***
  16. *****************************************************************************
  17.  
  18.         include    "subrts.h"    Included by default anyway
  19.  
  20. *****************************************************************************
  21. ***                          Initialisation routine                       ***
  22. *****************************************************************************
  23.  
  24.         move.b    #APPS_MOTOR+APPS_HEATER,d0  Initialise the applications board
  25.         jsr    APPS_INIT    (using motor and heater)
  26.  
  27.         move.b    #0,APPS_PORTA    Turn everything off
  28.  
  29.         movea.l    #Instructs,a6    Print instructions
  30.         jsr    OUTSTR
  31.  
  32. *****************************************************************************
  33. ***                         Main control routine                          ***
  34. *****************************************************************************
  35.  
  36. Main        bsr    Get.Temperature
  37.         jsr    INKEY
  38.         beq.s    Main
  39.         jsr    INCH
  40.         bclr    #5,d0        Convert to upper case
  41.         cmp.b    #'F',d0
  42.         beq    Mot_For
  43.         cmp.b    #'B',d0
  44.         beq    Mot_Bac
  45.         cmp.b    #'S',d0
  46.         beq    Mot_Sto
  47.         bset    #5,d0        Convert back to normal case
  48.         cmp.b    #'1',d0
  49.         beq    Heat_On
  50.         cmp.b    #'2',d0
  51.         beq    Heat_Off
  52.         cmp.b    #'.',d0        Was full stop pressed ?
  53.         bne    Main        If not then loop again
  54.  
  55. *****************************************************************************
  56. ***                         Turn everything off                           ***
  57. *****************************************************************************
  58.  
  59.         move.b    #0,APPS_PORTA    Turn everything off
  60.         movea.l    #End,a6        Print exit text
  61.         jsr    OUTSTR
  62.         rts            Exit
  63.  
  64. *****************************************************************************
  65. ***                        Motor forward routine                          ***
  66. *****************************************************************************
  67.  
  68. Mot_For        bclr    #6,APPS_PORTA    Clear bit 6 of Port A
  69.         bset    #7,APPS_PORTA    Set bit 7 of Port A
  70.         movea.l    #Forwards,a6    Output forward message
  71.         jsr    OUTSTR
  72.         bra    Main        Continue at main
  73.  
  74. *****************************************************************************
  75. ***                        Motor backward routine                         ***
  76. *****************************************************************************
  77.  
  78. Mot_Bac        bclr    #7,APPS_PORTA    Clear bit 7 of Port A
  79.         bset    #6,APPS_PORTA    Set bit 6 of Port A
  80.         movea.l    #Backwards,a6    Output backward message
  81.         jsr    OUTSTR
  82.         bra    Main        Continue at main
  83.  
  84. *****************************************************************************
  85. ***                        Motor stopped routine                          ***
  86. *****************************************************************************
  87.  
  88. Mot_Sto        bclr    #7,APPS_PORTA    Clear bit 7 of Port A
  89.         bclr    #6,APPS_PORTA    Clear bit 6 of Port A
  90.         movea.l    #Stopped,a6    Output stopped message
  91.         jsr    OUTSTR
  92.         bra    Main        Continue at main
  93.  
  94. *****************************************************************************
  95. ***                          Heater on routine                            ***
  96. *****************************************************************************
  97.  
  98. Heat_On        bset    #5,APPS_PORTA    Set bit 5 of Port A
  99.         movea.l    #On,a6        Output on message
  100.         jsr    OUTSTR
  101.         bra    Main        Continue at main
  102.  
  103. *****************************************************************************
  104. ***                         Heater off routine                            ***
  105. *****************************************************************************
  106.  
  107. Heat_Off    bclr    #5,APPS_PORTA    Clear bi 5 of Port A
  108.         movea.l    #Off,a6        Output off message
  109.         jsr    OUTSTR
  110.         bra    Main        Continue at main
  111.  
  112. *****************************************************************************
  113. ***                        Get.Temperature routine                        ***
  114. *****************************************************************************
  115.  
  116. Get.Temperature    movem.l    d0-d2,-(a7)    Save all used registers
  117.         move.l    #127,d0        Set up d0 with starting value
  118.         move.l    #128,d1        Set up d1 to half of start value
  119. .Chop        lsr.b    #1,d1        Divide half value by half again
  120.         move.b    d0,APPS_PORTB    Send try value
  121.         move.b    APPS_PORTA,d2
  122.         btst    #3,d2        Check if value was higher or lower
  123.         bne.s    .Higher        If value was higher
  124. .Lower        sub.b    d1,d0        Subtract half value from main value
  125.         cmp.b    #1,d1        Check if all values have been done
  126.         beq.s    .Done
  127.         bra.s    .Chop        Try next value
  128. .Higher        add.b    d1,d0        Add half value to main value
  129.         cmp.b    #1,d1        Check if all values have been done
  130.         beq.s    .Done
  131.         bra.s    .Chop        Try next value
  132.  
  133. .Done        move.b    d0,APPS_PORTB    (This ensures an acurate reading
  134.         move.b    APPS_PORTA,d1    of the heater with single byte
  135.         btst    #3,d1        differences rather than 2 bytes)
  136.         beq.s    .Done2        Value is correct
  137.         add.b    #1,d0        Value incorrect, subtract 1 from it
  138. .Done2        move.w    d0,Temperature    Save Temperature
  139.  
  140. *****************************************************************************
  141. ***                  Temperature found - now draw graph                   ***
  142. *****************************************************************************
  143.  
  144.         move.b    #21,d0        Locate cursor to print
  145.         move.b    #47,d1        out temperature value.
  146.         bsr.s    Locate        Locate cursor
  147.         move.w    Temperature,d0    Temperature between 0 and 255
  148.         jsr    OUT2HEX        Output fan speed
  149.  
  150.         move.b    #18,d0        Locate cursor to print
  151.         move.b    #8,d1        out fan bar graph.
  152.         bsr.s    Locate        Locate cursor
  153.         moveq    #0,d1        Clear d1
  154.         move.w    Temperature,d1    Temperature between 0 and 255
  155.         lsr.b    #2,d1        Divide by four
  156.         move.b    #'*',d0
  157.         bsr.s    Chars        Output characters
  158.         movem.l    (a7)+,d0-d2    Unstack registers
  159.         rts
  160.  
  161. *****************************************************************************
  162. ***                          Locate routine                               ***
  163. *** Locates the cursor at d0 down, d1 across.                             ***
  164. *****************************************************************************
  165.  
  166. Locate        movem.l    d0-d3/a0/a6,-(a7)  Save all used registers
  167.         moveq    #0,d3
  168.         movea.l    #Locate_Seq+2,a0   ANSI locate sequence - Down
  169.         move.b    d0,d3
  170.         bsr.s    .Locate_1       Convert value to text value
  171.         movea.l    #Locate_Seq+5,a0   ANSI locate sequence - Across
  172.         move.b    d1,d3
  173.         bsr.s    .Locate_1       Convert value to text value
  174.         movea.l    #Locate_Seq,a6     Output escape sequence
  175.         jsr    OUTSTR
  176.         movem.l    (a7)+,d0-d3/a0/a6  Unstack registers
  177.         rts
  178.  
  179. .Locate_1    divu    #10,d3           Convert tens first
  180.         bsr    .Locate_1.2
  181. .Locate_1.2    add    #$30,d3           Then units
  182.         move.b    d3,(a0)+
  183.         move.w    #0,d3
  184.         swap    d3
  185.         rts
  186.  
  187. *****************************************************************************
  188. ***                            Chars routine                              ***
  189. *** Prints d1 number of d0.b characters                                   ***
  190. *****************************************************************************
  191.  
  192. Chars        movem.l    d0-d1/a6,-(a7)    Save all used registers
  193. .Chars_1    cmpi.b    #0,d1        Check if all characters done
  194.         beq.s    .Chars_1.2
  195.         jsr        OUTCH        Output 1 character
  196.         subi.b     #1,d1        Decrement number to do
  197.         bra.s    .Chars_1    Repeat
  198. .Chars_1.2    movea.l    #EraseToEnd,a6    Output clear to end string
  199.         jsr    OUTSTR
  200.          movem.l    (a7)+,d0-d1/a6    Unstack registers
  201.         rts                
  202.  
  203. *****************************************************************************
  204. ***                             Variables                                 ***
  205. *****************************************************************************
  206.  
  207. Temperature    ds.w    1
  208.  
  209. *****************************************************************************
  210. ***                              Strings                                  ***
  211. *****************************************************************************
  212.  
  213. EraseToEnd    dc.b    27,'[K',0
  214.         even
  215.  
  216. Locate_Seq    dc.b    27,'[  ;  f',0       ANSI sequence
  217.         even               Re-align code
  218.  
  219. Instructs    dc.b    "Demo.asm",13,10,"========",13,10,13,10
  220.         dc.b    "Ensure that the ADC, Motor, and Heater are all switched on.",13,10
  221.         dc.b    "Select Heater on the Heater/Pot switch, then watch the temperature as you",13,10
  222.         dc.b    "play with the heater and fan actions.",13,10,13,10
  223.         dc.b    "Keys : F to make motor go forwards, B to make motor go backwards, S to stop.",13,10
  224.         dc.b    "       1 to turn heater on, 2 to turn heater off.",13,10
  225.         dc.b    "       Full stop to quit.",13,10,13,10
  226.         dc.b    "Motor Status  : Stopped",13,10
  227.         dc.b    "Heater Status : Off",13,10
  228.         dc.b    27,"[15;30fTemperature - (Percent)"
  229.         dc.b    27,"[17;8f00%  -     -     -     -     - 50% -     -     -     -     - 100%"
  230.         dc.b    27,"[21;32fActual Value :",0
  231.         even
  232. Forwards    dc.b    27,"[12;17fGoing fowards  ",13,10,0
  233.         even
  234. Backwards    dc.b    27,"[12;17fGoing backwards",13,10,0
  235.         even
  236. Stopped        dc.b    27,"[12;17fStopped        ",13,10,0
  237.         even
  238. On        dc.b    27,"[13;17fOn ",13,10,0
  239.         even
  240. Off        dc.b    27,"[13;17fOff",13,10,0
  241.         even
  242. End        dc.b    27,"[23;1fProgram ended normally.",0
  243.  
  244. *****************************************************************************
  245. ***                        End of file DEMO.ASM.                          ***
  246. *****************************************************************************
  247.