	.module demoday.c
	.dbfile demoday.c
	.area data
_pwm_vals::
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 17000
	.area data
	.blkb 2
	.area idata
	.word 17100
	.area data
	.blkb 2
	.area idata
	.word 17200
	.area data
	.blkb 2
	.area idata
	.word 17300
	.area data
	.blkb 2
	.area idata
	.word 17400
	.area data
	.blkb 2
	.area idata
	.word 17500
	.area data
	.blkb 2
	.area idata
	.word 17600
	.area data
	.blkb 2
	.area idata
	.word 17700
	.area data
	.blkb 2
	.area idata
	.word 17800
	.area data
	.blkb 2
	.area idata
	.word 17900
	.area data
	.blkb 2
	.area idata
	.word 18000
	.area data
	.blkb 2
	.area idata
	.word 18100
	.area data
	.blkb 2
	.area idata
	.word 18200
	.area data
	.blkb 2
	.area idata
	.word 18300
	.area data
	.blkb 2
	.area idata
	.word 18400
	.area data
	.blkb 2
	.area idata
	.word 18500
	.area data
	.blkb 2
	.area idata
	.word 18600
	.area data
	.blkb 2
	.area idata
	.word 18700
	.area data
	.blkb 2
	.area idata
	.word 18800
	.area data
	.blkb 2
	.area idata
	.word 18900
	.area data
	.blkb 2
	.area idata
	.word 19000
	.area data
	.blkb 2
	.area idata
	.word 19100
	.area data
	.blkb 2
	.area idata
	.word 19200
	.area data
	.blkb 2
	.area idata
	.word 19300
	.area data
	.blkb 2
	.area idata
	.word 19400
	.area data
	.blkb 2
	.area idata
	.word 19500
	.area data
	.blkb 2
	.area idata
	.word 19600
	.area data
	.blkb 2
	.area idata
	.word 19700
	.area data
	.blkb 2
	.area idata
	.word 19800
	.area data
	.blkb 2
	.area idata
	.word 19900
	.area data
	.blkb 2
	.area idata
	.word 20000
	.area data
	.blkb 2
	.area idata
	.word 20100
	.area data
	.blkb 2
	.area idata
	.word 20200
	.area data
	.blkb 2
	.area idata
	.word 20300
	.area data
	.blkb 2
	.area idata
	.word 20400
	.area data
	.blkb 2
	.area idata
	.word 20500
	.area data
	.blkb 2
	.area idata
	.word 20600
	.area data
	.blkb 2
	.area idata
	.word 20700
	.area data
	.blkb 2
	.area idata
	.word 20800
	.area data
	.blkb 2
	.area idata
	.word 20900
	.area data
	.blkb 2
	.area idata
	.word 21000
	.area data
	.blkb 2
	.area idata
	.word 21100
	.area data
	.blkb 2
	.area idata
	.word 21200
	.area data
	.blkb 2
	.area idata
	.word 21300
	.area data
	.blkb 2
	.area idata
	.word 21400
	.area data
	.blkb 2
	.area idata
	.word 21500
	.area data
	.blkb 2
	.area idata
	.word 21600
	.area data
	.blkb 2
	.area idata
	.word 21700
	.area data
	.blkb 2
	.area idata
	.word 21800
	.area data
	.blkb 2
	.area idata
	.word 21900
	.area data
	.blkb 2
	.area idata
	.word 22000
	.area data
	.blkb 2
	.area idata
	.word 22100
	.area data
	.blkb 2
	.area idata
	.word 22200
	.area data
	.blkb 2
	.area idata
	.word 22300
	.area data
	.blkb 2
	.area idata
	.word 22400
	.area data
	.blkb 2
	.area idata
	.word 22500
	.area data
	.blkb 2
	.area idata
	.word 22600
	.area data
	.blkb 2
	.area idata
	.word 22700
	.area data
	.blkb 2
	.area idata
	.word 22800
	.area data
	.blkb 2
	.area idata
	.word 22900
	.area data
	.blkb 2
	.area idata
	.word 23000
	.area data
	.blkb 2
	.area idata
	.word 23100
	.area data
	.blkb 2
	.area idata
	.word 23200
	.area data
	.blkb 2
	.area idata
	.word 23300
	.area data
	.blkb 2
	.area idata
	.word 23400
	.area data
	.blkb 2
	.area idata
	.word 23500
	.area data
	.blkb 2
	.area idata
	.word 23600
	.area data
	.blkb 2
	.area idata
	.word 23700
	.area data
	.blkb 2
	.area idata
	.word 23800
	.area data
	.blkb 2
	.area idata
	.word 23900
	.area data
	.blkb 2
	.area idata
	.word 24000
	.area data
	.blkb 2
	.area idata
	.word 24100
	.area data
	.blkb 2
	.area idata
	.word 24200
	.area data
	.blkb 2
	.area idata
	.word 24300
	.area data
	.blkb 2
	.area idata
	.word 24400
	.area data
	.blkb 2
	.area idata
	.word 24500
	.area data
	.blkb 2
	.area idata
	.word 24600
	.area data
	.blkb 2
	.area idata
	.word 24700
	.area data
	.blkb 2
	.area idata
	.word 24800
	.area data
	.blkb 2
	.area idata
	.word 24900
	.area data
	.blkb 2
	.area idata
	.word 25000
	.area data
	.blkb 2
	.area idata
	.word 25100
	.area data
	.blkb 2
	.area idata
	.word 25200
	.area data
	.blkb 2
	.area idata
	.word 25300
	.area data
	.blkb 2
	.area idata
	.word 25400
	.area data
	.blkb 2
	.area idata
	.word 25500
	.area data
	.blkb 2
	.area idata
	.word 25600
	.area data
	.blkb 2
	.area idata
	.word 25700
	.area data
	.blkb 2
	.area idata
	.word 25800
	.area data
	.blkb 2
	.area idata
	.word 25900
	.area data
	.blkb 2
	.area idata
	.word 26000
	.area data
	.blkb 2
	.area idata
	.word 26100
	.area data
	.blkb 2
	.area idata
	.word 26200
	.area data
	.blkb 2
	.area idata
	.word 26300
	.area data
	.blkb 2
	.area idata
	.word 26400
	.area data
	.blkb 2
	.area idata
	.word 26500
	.area data
	.blkb 2
	.area idata
	.word 26600
	.area data
	.blkb 2
	.area idata
	.word 26700
	.area data
	.blkb 2
	.area idata
	.word 26800
	.area data
	.blkb 2
	.area idata
	.word 26900
	.area data
	.blkb 2
	.area idata
	.word 27000
	.area data
	.blkb 2
	.area idata
	.word 27100
	.area data
	.blkb 2
	.area idata
	.word 27200
	.area data
	.blkb 2
	.area idata
	.word 27300
	.area data
	.blkb 2
	.area idata
	.word 27400
	.area data
	.blkb 2
	.area idata
	.word 27500
	.area data
	.blkb 2
	.area idata
	.word 27600
	.area data
	.blkb 2
	.area idata
	.word 27700
	.area data
	.blkb 2
	.area idata
	.word 27800
	.area data
	.blkb 2
	.area idata
	.word 27900
	.area data
	.blkb 2
	.area idata
	.word 28000
	.area data
	.blkb 2
	.area idata
	.word 28100
	.area data
	.blkb 2
	.area idata
	.word 28200
	.area data
	.blkb 2
	.area idata
	.word 28300
	.area data
	.blkb 2
	.area idata
	.word 28400
	.area data
	.blkb 2
	.area idata
	.word 28500
	.area data
	.blkb 2
	.area idata
	.word 28600
	.area data
	.blkb 2
	.area idata
	.word 28700
	.area data
	.blkb 2
	.area idata
	.word 28800
	.area data
	.blkb 2
	.area idata
	.word 28900
	.area data
	.blkb 2
	.area idata
	.word 29000
	.area data
	.blkb 2
	.area idata
	.word 29100
	.area data
	.blkb 2
	.area idata
	.word 29200
	.area data
	.blkb 2
	.area idata
	.word 29300
	.area data
	.blkb 2
	.area idata
	.word 29400
	.area data
	.blkb 2
	.area idata
	.word 29500
	.area data
	.blkb 2
	.area idata
	.word 29600
	.area data
	.blkb 2
	.area idata
	.word 29700
	.area data
	.blkb 2
	.area idata
	.word 29800
	.area data
	.blkb 2
	.area idata
	.word 29900
	.area data
	.blkb 2
	.area idata
	.word 30000
	.area data
	.blkb 2
	.area idata
	.word 30100
	.area data
	.blkb 2
	.area idata
	.word 30200
	.area data
	.blkb 2
	.area idata
	.word 30300
	.area data
	.blkb 2
	.area idata
	.word 30400
	.area data
	.blkb 2
	.area idata
	.word 30500
	.area data
	.blkb 2
	.area idata
	.word 30600
	.area data
	.blkb 2
	.area idata
	.word 30700
	.area data
	.blkb 2
	.area idata
	.word 30800
	.area data
	.blkb 2
	.area idata
	.word 30900
	.area data
	.blkb 2
	.area idata
	.word 31000
	.area data
	.blkb 2
	.area idata
	.word 31100
	.area data
	.blkb 2
	.area idata
	.word 31200
	.area data
	.blkb 2
	.area idata
	.word 31300
	.area data
	.blkb 2
	.area idata
	.word 31400
	.area data
	.blkb 2
	.area idata
	.word 31500
	.area data
	.blkb 2
	.area idata
	.word 31600
	.area data
	.blkb 2
	.area idata
	.word 31700
	.area data
	.blkb 2
	.area idata
	.word 31800
	.area data
	.blkb 2
	.area idata
	.word 31900
	.area data
	.blkb 2
	.area idata
	.word 32000
	.area data
	.blkb 2
	.area idata
	.word 32100
	.area data
	.blkb 2
	.area idata
	.word 32200
	.area data
	.blkb 2
	.area idata
	.word 32300
	.area data
	.blkb 2
	.area idata
	.word 32400
	.area data
	.blkb 2
	.area idata
	.word 32500
	.area data
	.blkb 2
	.area idata
	.word 32600
	.area data
	.blkb 2
	.area idata
	.word 32700
	.area data
	.blkb 2
	.area idata
	.word -32736
	.area data
	.blkb 2
	.area idata
	.word -32636
	.area data
	.blkb 2
	.area idata
	.word -32536
	.area data
	.blkb 2
	.area idata
	.word -32436
	.area data
	.blkb 2
	.area idata
	.word -32336
	.area data
	.blkb 2
	.area idata
	.word -32236
	.area data
	.blkb 2
	.area idata
	.word -32136
	.area data
	.blkb 2
	.area idata
	.word -32036
	.area data
	.blkb 2
	.area idata
	.word -31936
	.area data
	.blkb 2
	.area idata
	.word -31836
	.area data
	.blkb 2
	.area idata
	.word -31736
	.area data
	.blkb 2
	.area idata
	.word -31636
	.area data
	.blkb 2
	.area idata
	.word -31536
	.area data
	.blkb 2
	.area idata
	.word -31436
	.area data
	.blkb 2
	.area idata
	.word -31336
	.area data
	.blkb 2
	.area idata
	.word -31236
	.area data
	.blkb 2
	.area idata
	.word -31136
	.area data
	.blkb 2
	.area idata
	.word -31036
	.area data
	.blkb 2
	.area idata
	.word -30936
	.area data
	.blkb 2
	.area idata
	.word -30836
	.area data
	.blkb 2
	.area idata
	.word -30736
	.area data
	.blkb 2
	.area idata
	.word -30636
	.area data
	.blkb 2
	.area idata
	.word -30536
	.area data
	.blkb 2
	.area idata
	.word -30436
	.area data
	.blkb 2
	.area idata
	.word -30336
	.area data
	.blkb 2
	.area idata
	.word -30236
	.area data
	.blkb 2
	.area idata
	.word -30136
	.area data
	.blkb 2
	.area idata
	.word -30036
	.area data
	.blkb 2
	.area idata
	.word -29936
	.area data
	.blkb 2
	.area idata
	.word -29836
	.area data
	.blkb 2
	.area idata
	.word -29736
	.area data
	.blkb 2
	.area idata
	.word -29636
	.area data
	.blkb 2
	.area idata
	.word -29536
	.area data
	.blkb 2
	.area idata
	.word -29436
	.area data
	.blkb 2
	.area idata
	.word -29336
	.area data
	.blkb 2
	.area idata
	.word -29236
	.area data
	.blkb 2
	.area idata
	.word -29136
	.area data
	.blkb 2
	.area idata
	.word -29036
	.area data
	.blkb 2
	.area idata
	.word -28936
	.area data
	.blkb 2
	.area idata
	.word -28836
	.area data
	.blkb 2
	.area idata
	.word -28736
	.area data
	.blkb 2
	.area idata
	.word -28636
	.area data
	.blkb 2
	.area idata
	.word -28536
	.area data
	.blkb 2
	.area idata
	.word -28436
	.area data
	.blkb 2
	.area idata
	.word -28336
	.area data
	.blkb 2
	.area idata
	.word -28236
	.area data
	.blkb 2
	.area idata
	.word -28136
	.area data
	.blkb 2
	.area idata
	.word -28036
	.area data
	.blkb 2
	.area idata
	.word -27936
	.area data
	.blkb 2
	.area idata
	.word -27836
	.area data
	.blkb 2
	.area idata
	.word -27736
	.area data
	.blkb 2
	.area idata
	.word -27636
	.area data
	.blkb 2
	.area idata
	.word -27536
	.area data
	.blkb 2
	.area idata
	.word -27436
	.area data
	.blkb 2
	.area idata
	.word -27336
	.area data
	.blkb 2
	.area idata
	.word -27236
	.area data
	.blkb 2
	.area idata
	.word -27136
	.area data
	.blkb 2
	.area idata
	.word -27036
	.area data
	.blkb 2
	.area idata
	.word -26936
	.area data
	.blkb 2
	.area idata
	.word -26836
	.area data
	.blkb 2
	.area idata
	.word -26736
	.area data
	.blkb 2
	.area idata
	.word -26636
	.area data
	.blkb 2
	.area idata
	.word -26536
	.area data
	.blkb 2
	.area idata
	.word -26436
	.area data
	.blkb 2
	.area idata
	.word -26336
	.area data
	.blkb 2
	.area idata
	.word -26236
	.area data
	.blkb 2
	.area idata
	.word -26136
	.area data
	.blkb 2
	.area idata
	.word -26036
	.area data
	.blkb 2
	.area idata
	.word -25936
	.area data
	.blkb 2
	.area idata
	.word -25836
	.area data
	.blkb 2
	.area idata
	.word -25736
	.area data
	.blkb 2
	.area idata
	.word -25636
	.area data
	.blkb 2
	.area idata
	.word -25536
	.area data
	.blkb 2
	.area idata
	.word -25436
	.area data
	.blkb 2
	.area idata
	.word -25336
	.area data
	.blkb 2
	.area idata
	.word -25236
	.area data
	.blkb 2
	.area idata
	.word -25136
	.area data
	.blkb 2
	.area idata
	.word -25036
	.area data
_Message::
	.blkb 1
	.area idata
	.byte 0
	.area data
_CommandPos::
	.blkb 1
	.area idata
	.byte 0
	.area data
_handleCommandFlag::
	.blkb 1
	.area idata
	.byte 0
	.area data
_handleSampleFlag::
	.blkb 1
	.area idata
	.byte 0
	.area data
_cyl1_pstn::
	.blkb 2
	.area idata
	.word 0
	.area data
_cyl2_pstn::
	.blkb 2
	.area idata
	.word 0
	.area data
_cyl3_pstn::
	.blkb 2
	.area idata
	.word 0
	.area data
_cyl4_pstn::
	.blkb 2
	.area idata
	.word 0
	.area data
_cyl5_pstn::
	.blkb 2
	.area idata
	.word 0
	.area data
_cyl6_pstn::
	.blkb 2
	.area idata
	.word 0
	.area data
_cyl7_pstn::
	.blkb 2
	.area idata
	.word 0
	.area data
_cyl8_pstn::
	.blkb 2
	.area idata
	.word 0
	.area data
_cyl1_des::
	.blkb 2
	.area idata
	.word 100
	.area data
_cyl2_des::
	.blkb 2
	.area idata
	.word 100
	.area data
_cyl3_des::
	.blkb 2
	.area idata
	.word 100
	.area data
_cyl4_des::
	.blkb 2
	.area idata
	.word 100
	.area data
_cyl5_des::
	.blkb 2
	.area idata
	.word 100
	.area data
_cyl6_des::
	.blkb 2
	.area idata
	.word 100
	.area data
_cyl7_des::
	.blkb 2
	.area idata
	.word 100
	.area data
_cyl8_des::
	.blkb 2
	.area idata
	.word 100
	.area data
_error1::
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_error2::
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_error3::
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_error4::
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_error5::
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_error6::
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_error7::
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_error8::
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_K1::
	.blkb 2
	.area idata
	.word 3
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_K2::
	.blkb 2
	.area idata
	.word 3
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_K3::
	.blkb 2
	.area idata
	.word 3
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_K4::
	.blkb 2
	.area idata
	.word 3
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_K5::
	.blkb 2
	.area idata
	.word 3
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_K6::
	.blkb 2
	.area idata
	.word 3
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_K7::
	.blkb 2
	.area idata
	.word 3
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_K8::
	.blkb 2
	.area idata
	.word 3
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
	.blkb 2
	.area idata
	.word 0
	.area data
_motor1::
	.blkb 2
	.area idata
	.word 0
	.area data
_motor2::
	.blkb 2
	.area idata
	.word 0
	.area data
_motor3::
	.blkb 2
	.area idata
	.word 0
	.area data
_motor4::
	.blkb 2
	.area idata
	.word 0
	.area data
_motor5::
	.blkb 2
	.area idata
	.word 0
	.area data
_motor6::
	.blkb 2
	.area idata
	.word 0
	.area data
_motor7::
	.blkb 2
	.area idata
	.word 0
	.area data
_motor8::
	.blkb 2
	.area idata
	.word 0
	.area data
_calc_1ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_calc_1vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_calc_2ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_calc_2vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_calc_3ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_calc_3vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_new_motor_num::
	.blkb 1
	.area idata
	.byte 0
	.area data
_new_motor_spd::
	.blkb 2
	.area idata
	.word 0
	.area data
_comp_motor_spd::
	.blkb 2
	.area idata
	.word 0
	.area data
_first_motor::
	.blkb 1
	.area idata
	.byte 0
	.area data
_same_motor::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc5_reg::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc5_1ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc5_1vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc5_2ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc5_2vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc5_3ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc5_3vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc4_reg::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc4_1ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc4_1vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc4_2ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc4_2vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc4_3ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc4_3vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc3_reg::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc3_1ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc3_1vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc3_2ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc3_2vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc3_3ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc3_3vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc2_reg::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc2_1ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc2_1vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc2_2ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc2_2vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_oc2_3ot::
	.blkb 1
	.area idata
	.byte 0
	.area data
_oc2_3vl::
	.blkb 2
	.area idata
	.word 0
	.area data
_x_preserve::
	.blkb 2
	.area idata
	.word 0
	.area data
_mot_spd::
	.blkb 1
	.area idata
	.byte 0
	.area data
_pwm_port::
	.blkb 2
	.area idata
	.word 20480
	.area data
_wave_period::
	.blkb 2
	.area idata
	.word -5536
	.area data
_RTIcount::
	.blkb 1
	.area idata
	.byte 0
	.area text
;  IX -> 0,x
_init_SCI::
	.dbfile demoday.c
	.dbfunc init_SCI
	.dbline 171
; /*----------------------------------------------------*
;  *Program    : demoday.c                              *
;  *Version    : HC!!-1.0                               *
;  *Programmer : Scott Kanowitz                         *
;  *Contracter : Machine Intelligence Labroatory        *
;  *             University of Florida                  *
;  *Project    : Pneuman                                *
;  *Date       : 3/19/2000                              *
;  *----------------------------------------------------*
;  * Description : A program to run on the HC11 to      *
;  *               control 8 cylinders via a PID        *
;  *               controller and communicate with      *
;  *               the host machine via serial line     *   
;  *----------------------------------------------------*/
; 
; 
; //#include <multvlve.h>
; #include <hc11.h>
; #include <mil.h>
; #include <analog.h>
; #include <pwmvals.h>
; 
; /* Set up interrupt vectors (also at end) */
; extern void _start(void);	/* entry point in crt??.s */
; 
; 
; #pragma interrupt_handler TOC2_isr
; #pragma interrupt_handler TOC3_isr
; #pragma interrupt_handler TOC4_isr
; #pragma interrupt_handler TOC5_isr
; #pragma interrupt_handler SCI_isr
; #pragma interrupt_handler RTI_isr
; 
; 
; 
; #define DUMMY_ENTRY	(void (*)(void))0xFFFF /*used as blank space in inpt vectors*/
; #define COMMAND_LENGTH 7 //(start char) + (5 char command(ie C1150)) + (end char) 
; #define START_CHAR 0x24 //corresponds to $
; #define END_CHAR 0x23 //corresponds to #
; 
; #define P 0
; #define I 1
; #define D 2
; 
; #define TOLERANCE 4
; 
; #define DIR_PORT *(unsigned char *)(0x4000)
; /*--------------------------------------------------*
;  *Global variables									*
;  *													*
;  *--------------------------------------------------*/
; //char cylinderNumber = 0;
; 
; char Message = 0;
; char CommandPos = 0;
; char handleCommandFlag = 0;
; char Command[2* COMMAND_LENGTH];
; 
; char	handleSampleFlag  = 0;
; 
; int 	cyl1_pstn	= 0; 
; int		cyl2_pstn	= 0; 
; int		cyl3_pstn	= 0; 
; int		cyl4_pstn	= 0; 
; int		cyl5_pstn	= 0; 
; int		cyl6_pstn	= 0; 
; int		cyl7_pstn	= 0; 
; int		cyl8_pstn	= 0; 
; 
; int		cyl1_des	= 100; 
; int		cyl2_des	= 100; 
; int		cyl3_des	= 100; 
; int		cyl4_des	= 100; 
; int		cyl5_des	= 100; 
; int		cyl6_des	= 100; 
; int		cyl7_des	= 100; 
; int		cyl8_des	= 100; 
; 
; int error1[3] = {0, 0, 0};
; int error2[3] = {0, 0, 0};
; int error3[3] = {0, 0, 0};
; int error4[3] = {0, 0, 0};
; int error5[3] = {0, 0, 0};
; int error6[3] = {0, 0, 0};
; int error7[3] = {0, 0, 0};
; int error8[3] = {0, 0, 0};
; 
; int K1[3] = {3, 0, 0};
; int K2[3] = {3, 0, 0};
; int K3[3] = {3, 0, 0};
; int K4[3] = {3, 0, 0};
; int K5[3] = {3, 0, 0};
; int K6[3] = {3, 0, 0};
; int K7[3] = {3, 0, 0};
; int K8[3] = {3, 0, 0};
; 
; 
; int motor1        =0; 
; int motor2        =0; 
; int motor3        =0; 
; int motor4        =0; 
; int motor5        =0; 
; int motor6        =0; 
; int motor7        =0; 
; int motor8        =0; 
; 
; char calc_1ot    =0; 
; int calc_1vl     =0; 
; char calc_2ot	 =0; 
; int calc_2vl	 =0; 
; char calc_3ot	 =0; 
; int calc_3vl	 =0; 
; 
; char new_motor_num   = 0; 
; int new_motor_spd	 = 0; 
; int comp_motor_spd	 = 0; 
; char first_motor	 = 0; 
; char same_motor	     = 0; 
; 
; char *oc5_reg		 = 0; 
; char oc5_1ot         = 0; 
; int oc5_1vl          = 0; 
; char oc5_2ot	     = 0; 
; int oc5_2vl	         = 0; 
; char oc5_3ot         = 0; 
; int oc5_3vl          = 0; 
; 
; char *oc4_reg = 0; 
; char oc4_1ot  = 0; 
; int oc4_1vl   = 0; 
; char oc4_2ot  = 0; 
; int oc4_2vl	  = 0; 
; char oc4_3ot  = 0; 
; int oc4_3vl   = 0; 
; 
; char *oc3_reg = 0; 
; char oc3_1ot  = 0; 
; int oc3_1vl   = 0; 
; char oc3_2ot  = 0; 
; int oc3_2vl	  = 0; 
; char oc3_3ot  = 0; 
; int oc3_3vl   = 0; 
; 
; char *oc2_reg = 0; 
; char oc2_1ot  = 0; 
; int oc2_1vl   = 0; 
; char oc2_2ot  = 0; 
; int oc2_2vl	  = 0; 
; char oc2_3ot  = 0; 
; int oc2_3vl   = 0; 
; 
; int x_preserve = 0;
; 
; char mot_spd = 0;
; 
; int pwm_port	= 0x5000;
; 
; int wave_period = 0xEA60;
; 
; char RTIcount	=0;
; 
; 
; /************************************************************
; 
;   INITIALIZATION FUNCTIONS
; 
; *************************************************************/
; 
; /* Set SCI for 9600, 8-n-1, TE, RE, and rx interrupt enabled, tx disabled */
; void init_SCI(){
;   BAUD |= 0X30;
	ldy #0x102b
	bset 0,y,#48
	.dbline 172
;   SCCR1 = 0X00;
	clr 0x102c
	.dbline 173
;   SCCR2 |= 0X2C;
	ldy #0x102d
	bset 0,y,#44
	.dbline 174
;   SCCR2 &= 0X7f;
	ldy #0x102d
	bclr 0,y,#0x80
	.dbline 175
; }
L2:
	rts
;  IX -> 0,x
_init_pulse::
			sei

	.dbfunc init_pulse
	.dbline 182
; 
; 	
; /* Set up oc2-5 to interrupt and dissconnect from pins*/
; void init_pulse()
; {
; 	INTR_OFF();
; 	CLEAR_BIT(TCTL1, 0xFF);	//Disconnect all OCs from pins
	ldy #0x1020
	bclr 0,y,#0xff
	.dbline 183
; 	TOC2 = 3000;
	ldd #3000
	std 0x1018
	.dbline 184
; 	TOC3 = TOC2+3000; //offset all the initial interrupt times
	; vol
	ldd 0x1018
	addd #3000
	std 0x101a
	.dbline 185
; 	TOC4 = TOC3+3000;
	; vol
	ldd 0x101a
	addd #3000
	std 0x101c
	.dbline 186
; 	TOC5 = TOC4+3000; 
	; vol
	ldd 0x101c
	addd #3000
	std 0x101e
	.dbline 187
; 	SET_BIT(TMSK1, 0x78);	//enable oc2-5
	ldy #0x1022
	bset 0,y,#120
	.dbline 188
; 	CLEAR_BIT(PACTL, 0x04); //Enable oc5
	ldy #0x1026
	bclr 0,y,#0x4
			cli

	.dbline 190
; 	INTR_ON(); //turn on interrupts
; }	
L3:
	rts
;  IX -> 0,x
_init_RTI::
	.dbfunc init_RTI
	.dbline 195
; 
; 
; /* Initialize RTI to interrupt every 32.768ms */
; void init_RTI() {
;   PACTL |= 0X03;
	ldy #0x1026
	bset 0,y,#3
	.dbline 196
;   TMSK2 |= 0X40;
	ldy #0x1024
	bset 0,y,#64
	.dbline 197
; }
L4:
	rts
;  IX -> 0,x
;        mot_num -> 9,x
;       new_duty -> 4,x
_multvlve::
	pshb
	psha
	pshx
	pshx
	tsx
	stx 0,x
	.dbfunc multvlve
	.dbline 208
; 
; 
; /************************************************************
; 
;   MULTVLVE function to set up duty_cycles
; 
; *************************************************************/
; 
; void multvlve(int new_duty, char mot_num)
; {
; new_motor_spd = new_duty;
	ldd 4,x
	std _new_motor_spd
	.dbline 209
; new_motor_num = mot_num;
	ldab 9,x
	stab _new_motor_num
		stx _x_preserve
	ldab _new_motor_num
	cmpb #$01
	bne is_motor_2
	ldx _new_motor_spd
	stx _motor1
	ldx _motor2
	stx _comp_motor_spd
	ldab #$01
	stab _first_motor
	jmp calc_motor_times
	is_motor_2:
	cmpb #$02
	bne is_motor_3
	ldx _new_motor_spd
	stx _motor2
	ldx _motor1
	stx _comp_motor_spd
	clr _first_motor
	jmp calc_motor_times

		is_motor_3:
	cmpb #$03
	bne is_motor_4
	ldx _new_motor_spd
	stx _motor3
	ldx _motor4
	stx _comp_motor_spd
	ldab #$01
	stab _first_motor
	jmp calc_motor_times
	is_motor_4:
	cmpb #$04
	bne is_motor_5
	ldx _new_motor_spd
	stx _motor4
	ldx _motor3
	stx _comp_motor_spd
	clr _first_motor
	jmp calc_motor_times

		is_motor_5:
	cmpb #$05
	bne is_motor_6
	ldx _new_motor_spd
	stx _motor5
	ldx _motor6
	stx _comp_motor_spd
	ldab #$01
	stab _first_motor
	jmp calc_motor_times
	is_motor_6:
	cmpb #$06
	bne is_motor_7
	ldx _new_motor_spd
	stx _motor6
	ldx _motor5
	stx _comp_motor_spd
	clr _first_motor
	jmp calc_motor_times

		is_motor_7:
	cmpb #$07
	bne is_motor_8
	ldx _new_motor_spd
	stx _motor7
	ldx _motor8
	stx _comp_motor_spd
	ldab #$01
	stab _first_motor
	jmp calc_motor_times
	is_motor_8:
	cmpb #$08
	bne end_routine
	ldx _new_motor_spd
	stx _motor8
	ldx _motor7
	stx _comp_motor_spd
	clr _first_motor
	bra calc_motor_times
	

		end_routine:
	jmp multvlve_done
	calc_motor_times:
	clr _same_motor
	ldx _new_motor_spd
	cpx _comp_motor_spd
	bne calc_motor_nequ
	ldaa #$01
	staa _same_motor
	calc_motor_nequ:
	cpx _wave_period
	bne calc_mot_con1
	jmp clc_mot_40
	calc_mot_con1:
	cpx #$0000
	bne calc_mot_con2
	jmp clc_mot_00

		calc_mot_con2:
	ldaa _same_motor
	bne calc_motor_same
	cpx _comp_motor_spd
	bls clc_mot_les
	jmp clc_mot_gt
	clc_mot_les:
	stx _calc_1vl
	ldd _comp_motor_spd
	subd _new_motor_spd
	std _calc_2vl
	ldd _wave_period
	cpd _comp_motor_spd
	beq clc_mot_lesc
	subd _calc_2vl
	subd _calc_1vl
	std _calc_3vl
	ldaa #0b00000011
	staa _calc_1ot
	ldaa #0b00000010
	staa _calc_2ot
	ldaa #0b00000000
	staa _calc_3ot
	jmp calc_mot_fin

		clc_mot_lesc:
	subd _new_motor_spd
	subd #1000
	std _calc_3vl
	ldd #1000
	std _calc_2vl
	ldaa _first_motor
	bne is_mot_lessc
	ldaa #0b00000011
	staa _calc_1ot
	ldaa #0b00000001
	staa _calc_3ot
	staa _calc_2ot
	jmp calc_mot_fin
	is_mot_lessc:
	ldaa #0b00000011
	staa _calc_1ot
	ldaa #0b00000010
	staa _calc_3ot
	staa _calc_2ot
	jmp calc_mot_fin

		calc_motor_same:
	ldd _new_motor_spd
	std _calc_1vl
	ldd #1000
	std _calc_2vl
	ldd _wave_period
	subd _calc_2vl
	subd _calc_1vl
	std _calc_3vl
	ldaa #0b00000011
	staa _calc_1ot
	ldaa #$00000000
	staa _calc_3ot
	staa _calc_2ot
	jmp calc_mot_fin

		clc_mot_gt:
	ldd _comp_motor_spd
	cpd #$00
	beq clc_mot_gtr0
	std _calc_1vl
	ldd _new_motor_spd
	subd _comp_motor_spd
	std _calc_2vl
	ldd _wave_period
	subd _calc_2vl
	subd _calc_1vl
	std _calc_3vl
	ldaa _first_motor
	bne is_mot_gtrc
	ldaa #0b00000011
	staa _calc_1ot
	ldaa #0b00000010
	staa _calc_2ot
	ldaa #0b00000000
	staa _calc_3ot
	jmp calc_mot_fin

		is_mot_gtrc:
	ldaa #0b00000011
	staa _calc_1ot
	ldaa #0b00000001
	staa _calc_2ot
	ldaa #0b00000000
	staa _calc_3ot
	jmp calc_mot_fin
	clc_mot_gtr0:
	ldd _new_motor_spd
	std _calc_1vl
	ldd #1000
	std _calc_2vl
	ldd _wave_period
	subd _calc_2vl
	subd _calc_1vl
	std _calc_3vl
	ldaa _first_motor
	bne is_mot_gtrcc
	ldaa #0b00000010
	staa _calc_1ot
	ldaa #0b00000000
	staa _calc_3ot
	staa _calc_2ot
	jmp calc_mot_fin

		is_mot_gtrcc:
	ldaa #0b00000001
	staa _calc_1ot
	ldaa #0b00000000
	staa _calc_3ot
	staa _calc_2ot
	jmp calc_mot_fin
	clc_mot_00:
	ldaa _same_motor
	bne both_zero
	ldd _comp_motor_spd
	cpd _wave_period
	beq clc_mot_0040
	std _calc_1vl
	ldd #1000
	std _calc_2vl
	ldd _wave_period
	subd _calc_2vl
	subd _calc_1vl
	std _calc_3vl
	ldaa _first_motor
	bne is_mot_00
	ldaa #0b00000001
	staa _calc_1ot
	ldaa #0b00000000
	staa _calc_3ot
	staa _calc_2ot
	jmp calc_mot_fin

		is_mot_00:
	ldaa #0b00000010
	staa _calc_1ot
	ldaa #0b00000000
	staa _calc_3ot
	staa _calc_2ot
	jmp calc_mot_fin
	both_zero:
	ldaa #0b00000000
	staa _calc_1ot
	staa _calc_2ot
	staa _calc_3ot
	ldd #1000
	std _calc_1vl
	ldd #1000
	std _calc_2vl
	ldd _wave_period
	subd _calc_2vl
	subd _calc_1vl
	std _calc_3vl
	jmp calc_mot_fin
	clc_mot_0040:
	ldd #1000
	std _calc_1vl
	std _calc_2vl
	ldd _wave_period
	subd _calc_1vl
	subd _calc_2vl
	std _calc_3vl
	ldaa #0b00000010
	ldab _first_motor
	bne is_mot_0040
	ldaa #0b00000001

		is_mot_0040:
	staa _calc_1ot
	staa _calc_2ot
	staa _calc_3ot
	jmp calc_mot_fin
	clc_mot_40:
	ldaa _same_motor
	bne both_40000
	ldd _comp_motor_spd
	cpd #$0000
	bne clc_mot_40c
	ldd #1000
	clc_mot_40c:
	std _calc_1vl
	ldd #1000
	std _calc_2vl
	ldd _wave_period
	subd _calc_2vl
	subd _calc_1vl
	std _calc_3vl
	ldaa _first_motor
	bne is_mot_40
	ldaa #0b00000011
	ldx _comp_motor_spd
	cpx #$0000
	bne clc_mot_40cc
	ldaa #0b00000010
	clc_mot_40cc:
	staa _calc_1ot
	ldaa #0b00000010
	staa _calc_3ot
	staa _calc_2ot
	jmp calc_mot_fin

		is_mot_40:
	ldaa #0b00000011
	ldx _comp_motor_spd
	cpx #$0000
	bne is_mot_40c
	ldaa #0b00000001
	is_mot_40c:
	staa _calc_1ot
	ldaa #0b00000001
	staa _calc_3ot
	staa _calc_2ot
	jmp calc_mot_fin
	both_40000:
	ldd #1000
	std _calc_1vl
	ldd #1000
	std _calc_2vl
	ldd _wave_period
	subd _calc_2vl
	subd _calc_1vl
	std _calc_3vl
	ldaa #0b00000011
	staa _calc_1ot
	staa _calc_2ot
	staa _calc_3ot
	jmp calc_mot_fin

		calc_mot_fin:
	ldy #_oc2_1ot
	ldaa _new_motor_num
	cmpa #$01
	beq jmp_calc_motor_done
	cmpa #$02
	beq jmp_calc_motor_done
	cmpa #$03
	beq calc_motor_34
	cmpa #$04
	beq calc_motor_34
	cmpa #$05
	beq calc_motor_56
	cmpa #$06
	beq calc_motor_56
	bra calc_motor_78
	jmp_calc_motor_done:
	jmp calc_motor_done

		calc_motor_78:
	ldaa _calc_1ot
	lsla
	lsla
	lsla
	lsla
	lsla
	lsla
	staa _calc_1ot
	ldaa _calc_2ot
	lsla
	lsla
	lsla
	lsla
	lsla
	lsla
	staa _calc_2ot
	ldaa _calc_3ot
	lsla
	lsla
	lsla
	lsla
	lsla
	lsla
	staa _calc_3ot
	ldy #_oc5_1ot
	jmp calc_motor_done

		calc_motor_56:
	ldaa _calc_1ot
	lsla
	lsla
	lsla
	lsla
	staa _calc_1ot
	ldaa _calc_2ot
	lsla
	lsla
	lsla
	lsla
	staa _calc_2ot
	ldaa _calc_3ot
	lsla
	lsla
	lsla
	lsla
	staa _calc_3ot
	ldy #_oc4_1ot
	jmp calc_motor_done

		calc_motor_34:
	ldaa _calc_1ot
	lsla
	lsla
	staa _calc_1ot
	ldaa _calc_2ot
	lsla
	lsla
	staa _calc_2ot
	ldaa _calc_3ot
	lsla
	lsla
	staa _calc_3ot
	ldy #_oc3_1ot
	calc_motor_done:
	ldx #_calc_1ot
	ldaa 0,x
	staa 0,y
	inx
	iny
	ldd 0,x
	std 0,y
	inx
	inx
	iny
	iny
	ldaa 0,x
	staa 0,y
	inx
	iny
	ldd 0,x
	std 0,y
	inx
	inx
	iny
	iny
	ldaa 0,x
	staa 0,y
	inx
	iny
	ldd 0,x
	std 0,y
	multvlve_done:
	ldx _x_preserve

	.dbline 644
; 
; 
; asm("stx _x_preserve\n"
; 	"ldab _new_motor_num\n"
; 	"cmpb #$01\n"
; 	"bne is_motor_2\n"
; 	"ldx _new_motor_spd\n"
; 	"stx _motor1\n"
; 	"ldx _motor2\n"
; 	"stx _comp_motor_spd\n"
; 	"ldab #$01\n"
; 	"stab _first_motor\n"
; 	"jmp calc_motor_times\n"
; "is_motor_2:\n"
; 	"cmpb #$02\n"
; 	"bne is_motor_3\n"
; 	"ldx _new_motor_spd\n"
; 	"stx _motor2\n"
; 	"ldx _motor1\n"
; 	"stx _comp_motor_spd\n"
; 	"clr _first_motor\n"
; 	"jmp calc_motor_times");
; asm("is_motor_3:\n"
; 	"cmpb #$03\n"
; 	"bne is_motor_4\n"
; 	"ldx _new_motor_spd\n"
; 	"stx _motor3\n"
; 	"ldx _motor4\n"
; 	"stx _comp_motor_spd\n"
; 	"ldab #$01\n"
; 	"stab _first_motor\n"
; 	"jmp calc_motor_times\n"
; "is_motor_4:\n"
; 	"cmpb #$04\n"
; 	"bne is_motor_5\n"
; 	"ldx _new_motor_spd\n"
; 	"stx _motor4\n"
; 	"ldx _motor3\n"
; 	"stx _comp_motor_spd\n"
; 	"clr _first_motor\n"
; 	"jmp calc_motor_times");
; asm("is_motor_5:\n"
; 	"cmpb #$05\n"
; 	"bne is_motor_6\n"
; 	"ldx _new_motor_spd\n"
; 	"stx _motor5\n"
; 	"ldx _motor6\n"
; 	"stx _comp_motor_spd\n"
; 	"ldab #$01\n"
; 	"stab _first_motor\n"
; 	"jmp calc_motor_times\n"
; "is_motor_6:\n"
; 	"cmpb #$06\n"
; 	"bne is_motor_7\n"
; 	"ldx _new_motor_spd\n"
; 	"stx _motor6\n"
; 	"ldx _motor5\n"
; 	"stx _comp_motor_spd\n"
; 	"clr _first_motor\n"
; 	"jmp calc_motor_times");
; asm("is_motor_7:\n"
; 	"cmpb #$07\n"
; 	"bne is_motor_8\n"
; 	"ldx _new_motor_spd\n"
; 	"stx _motor7\n"
; 	"ldx _motor8\n"
; 	"stx _comp_motor_spd\n"
; 	"ldab #$01\n"
; 	"stab _first_motor\n"
; 	"jmp calc_motor_times\n"
; "is_motor_8:\n"
; 	"cmpb #$08\n"
; 	"bne end_routine\n"
; 	"ldx _new_motor_spd\n"
; 	"stx _motor8\n"
; 	"ldx _motor7\n"
; 	"stx _comp_motor_spd\n"
; 	"clr _first_motor\n"
; 	"bra calc_motor_times\n");
; asm("end_routine:\n"
; 	"jmp multvlve_done\n"
; "calc_motor_times:\n"
; 	"clr _same_motor\n"
; 	"ldx _new_motor_spd\n"
; 	"cpx _comp_motor_spd\n"
; 	"bne calc_motor_nequ\n"
; 	"ldaa #$01\n"
; 	"staa _same_motor\n"
; "calc_motor_nequ:\n"
; 	"cpx _wave_period\n"
; 	"bne calc_mot_con1\n"
; 	"jmp clc_mot_40\n"
; "calc_mot_con1:\n"
; 	"cpx #$0000\n"
; 	"bne calc_mot_con2\n"
; 	"jmp clc_mot_00");
; asm("calc_mot_con2:\n"
; 	"ldaa _same_motor\n"
; 	"bne calc_motor_same\n"
; 	"cpx _comp_motor_spd\n"
; 	"bls clc_mot_les\n"
; 	"jmp clc_mot_gt\n"
; "clc_mot_les:\n"
; 	"stx _calc_1vl\n"
; 	"ldd _comp_motor_spd\n"
; 	"subd _new_motor_spd\n"
; 	"std _calc_2vl\n"
; 	"ldd _wave_period\n"
; 	"cpd _comp_motor_spd\n"
; 	"beq clc_mot_lesc\n"
; 	"subd _calc_2vl\n"
; 	"subd _calc_1vl\n"
; 	"std _calc_3vl\n"
; 	"ldaa #0b00000011\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000010\n"
; 	"staa _calc_2ot\n"
; 	"ldaa #0b00000000\n"
; 	"staa _calc_3ot\n"
; 	"jmp calc_mot_fin");
; asm("clc_mot_lesc:\n"
; 	"subd _new_motor_spd\n"
; 	"subd #1000\n"
; 	"std _calc_3vl\n"
; 	"ldd #1000\n"
; 	"std _calc_2vl\n"
; 	"ldaa _first_motor\n"
; 	"bne is_mot_lessc\n"
; 	"ldaa #0b00000011\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000001\n"
; 	"staa _calc_3ot\n"
; 	"staa _calc_2ot\n"
; 	"jmp calc_mot_fin\n"
; "is_mot_lessc:\n"
; 	"ldaa #0b00000011\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000010\n"
; 	"staa _calc_3ot\n"
; 	"staa _calc_2ot\n"
; 	"jmp calc_mot_fin");
; asm("calc_motor_same:\n"
; 	"ldd _new_motor_spd\n"
; 	"std _calc_1vl\n"
; 	"ldd #1000\n"
; 	"std _calc_2vl\n"
; 	"ldd _wave_period\n"
; 	"subd _calc_2vl\n"
; 	"subd _calc_1vl\n"
; 	"std _calc_3vl\n"
; 	"ldaa #0b00000011\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #$00000000\n"
; 	"staa _calc_3ot\n"
; 	"staa _calc_2ot\n"
; 	"jmp calc_mot_fin");
; asm("clc_mot_gt:\n"
; 	"ldd _comp_motor_spd\n"
; 	"cpd #$00\n"
; 	"beq clc_mot_gtr0\n"
; 	"std _calc_1vl\n"
; 	"ldd _new_motor_spd\n"
; 	"subd _comp_motor_spd\n"
; 	"std _calc_2vl\n"
; 	"ldd _wave_period\n"
; 	"subd _calc_2vl\n"
; 	"subd _calc_1vl\n"
; 	"std _calc_3vl\n"
; 	"ldaa _first_motor\n"
; 	"bne is_mot_gtrc\n"
; 	"ldaa #0b00000011\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000010\n"
; 	"staa _calc_2ot\n"
; 	"ldaa #0b00000000\n"
; 	"staa _calc_3ot\n"
; 	"jmp calc_mot_fin")
; asm("is_mot_gtrc:\n"
; 	"ldaa #0b00000011\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000001\n"
; 	"staa _calc_2ot\n"
; 	"ldaa #0b00000000\n"
; 	"staa _calc_3ot\n"
; 	"jmp calc_mot_fin\n"
; "clc_mot_gtr0:\n"
; 	"ldd _new_motor_spd\n"
; 	"std _calc_1vl\n"
; 	"ldd #1000\n"
; 	"std _calc_2vl\n"
; 	"ldd _wave_period\n"
; 	"subd _calc_2vl\n"
; 	"subd _calc_1vl\n"
; 	"std _calc_3vl\n"
; 	"ldaa _first_motor\n"
; 	"bne is_mot_gtrcc\n"
; 	"ldaa #0b00000010\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000000\n"
; 	"staa _calc_3ot\n"
; 	"staa _calc_2ot\n"
; 	"jmp calc_mot_fin");
; asm("is_mot_gtrcc:\n"
; 	"ldaa #0b00000001\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000000\n"
; 	"staa _calc_3ot\n"
; 	"staa _calc_2ot\n"
; 	"jmp calc_mot_fin\n"
; "clc_mot_00:\n"
; 	"ldaa _same_motor\n"
; 	"bne both_zero\n"
; 	"ldd _comp_motor_spd\n"
; 	"cpd _wave_period\n"
; 	"beq clc_mot_0040\n"
; 	"std _calc_1vl\n"
; 	"ldd #1000\n"
; 	"std _calc_2vl\n"
; 	"ldd _wave_period\n"
; 	"subd _calc_2vl\n"
; 	"subd _calc_1vl\n"
; 	"std _calc_3vl\n"
; 	"ldaa _first_motor\n"
; 	"bne is_mot_00\n"
; 	"ldaa #0b00000001\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000000\n"
; 	"staa _calc_3ot\n"
; 	"staa _calc_2ot\n"
; 	"jmp calc_mot_fin");
; asm("is_mot_00:\n"
; 	"ldaa #0b00000010\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000000\n"
; 	"staa _calc_3ot\n"
; 	"staa _calc_2ot\n"
; 	"jmp calc_mot_fin\n"
; "both_zero:\n"
; 	"ldaa #0b00000000\n"
; 	"staa _calc_1ot\n"
; 	"staa _calc_2ot\n"
; 	"staa _calc_3ot\n"
; 	"ldd #1000\n"
; 	"std _calc_1vl\n"
; 	"ldd #1000\n"
; 	"std _calc_2vl\n"
; 	"ldd _wave_period\n"
; 	"subd _calc_2vl\n"
; 	"subd _calc_1vl\n"
; 	"std _calc_3vl\n"
; 	"jmp calc_mot_fin\n"
; "clc_mot_0040:\n"
; 	"ldd #1000\n"
; 	"std _calc_1vl\n"
; 	"std _calc_2vl\n"
; 	"ldd _wave_period\n"
; 	"subd _calc_1vl\n"
; 	"subd _calc_2vl\n"
; 	"std _calc_3vl\n"
; 	"ldaa #0b00000010\n"
; 	"ldab _first_motor\n"
; 	"bne is_mot_0040\n"
; 	"ldaa #0b00000001");
; asm("is_mot_0040:\n"
; 	"staa _calc_1ot\n"
; 	"staa _calc_2ot\n"
; 	"staa _calc_3ot\n"
; 	"jmp calc_mot_fin\n"
; "clc_mot_40:\n"
; 	"ldaa _same_motor\n"
; 	"bne both_40000\n"
; 	"ldd _comp_motor_spd\n"
; 	"cpd #$0000\n"
; 	"bne clc_mot_40c\n"
; 	"ldd #1000\n"
; "clc_mot_40c:\n"
; 	"std _calc_1vl\n"
; 	"ldd #1000\n"
; 	"std _calc_2vl\n"
; 	"ldd _wave_period\n"
; 	"subd _calc_2vl\n"
; 	"subd _calc_1vl\n"
; 	"std _calc_3vl\n"
; 	"ldaa _first_motor\n"
; 	"bne is_mot_40\n"
; 	"ldaa #0b00000011\n"
; 	"ldx _comp_motor_spd\n"
; 	"cpx #$0000\n"
; 	"bne clc_mot_40cc\n"
; 	"ldaa #0b00000010\n"
; "clc_mot_40cc:\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000010\n"
; 	"staa _calc_3ot\n"
; 	"staa _calc_2ot\n"
; 	"jmp calc_mot_fin");
; asm("is_mot_40:\n"
; 	"ldaa #0b00000011\n"
; 	"ldx _comp_motor_spd\n"
; 	"cpx #$0000\n"
; 	"bne is_mot_40c\n"
; 	"ldaa #0b00000001\n"
; "is_mot_40c:\n"
; 	"staa _calc_1ot\n"
; 	"ldaa #0b00000001\n"
; 	"staa _calc_3ot\n"
; 	"staa _calc_2ot\n"
; 	"jmp calc_mot_fin\n"
; "both_40000:\n"
; 	"ldd #1000\n"
; 	"std _calc_1vl\n"
; 	"ldd #1000\n"
; 	"std _calc_2vl\n"
; 	"ldd _wave_period\n"
; 	"subd _calc_2vl\n"
; 	"subd _calc_1vl\n"
; 	"std _calc_3vl\n"
; 	"ldaa #0b00000011\n"
; 	"staa _calc_1ot\n"
; 	"staa _calc_2ot\n"
; 	"staa _calc_3ot\n"
; 	"jmp calc_mot_fin");
; asm("calc_mot_fin:\n"
; 	"ldy #_oc2_1ot\n"
; 	"ldaa _new_motor_num\n"
; 	"cmpa #$01\n"
; 	"beq jmp_calc_motor_done\n"
; 	"cmpa #$02\n"
; 	"beq jmp_calc_motor_done\n"
; 	"cmpa #$03\n"
; 	"beq calc_motor_34\n"
; 	"cmpa #$04\n"
; 	"beq calc_motor_34\n"
; 	"cmpa #$05\n"
; 	"beq calc_motor_56\n"
; 	"cmpa #$06\n"
; 	"beq calc_motor_56\n"
; 	"bra calc_motor_78\n"
; "jmp_calc_motor_done:\n"
; 	"jmp calc_motor_done");
; asm("calc_motor_78:\n"
; 	"ldaa _calc_1ot\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"staa _calc_1ot\n"
; 	"ldaa _calc_2ot\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"staa _calc_2ot\n"
; 	"ldaa _calc_3ot\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"staa _calc_3ot\n"
; 	"ldy #_oc5_1ot\n"
; 	"jmp calc_motor_done");
; asm("calc_motor_56:\n"
; 	"ldaa _calc_1ot\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"staa _calc_1ot\n"
; 	"ldaa _calc_2ot\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"staa _calc_2ot\n"
; 	"ldaa _calc_3ot\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"staa _calc_3ot\n"
; 	"ldy #_oc4_1ot\n"
; 	"jmp calc_motor_done");
; asm("calc_motor_34:\n"
; 	"ldaa _calc_1ot\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"staa _calc_1ot\n"
; 	"ldaa _calc_2ot\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"staa _calc_2ot\n"
; 	"ldaa _calc_3ot\n"
; 	"lsla\n"
; 	"lsla\n"
; 	"staa _calc_3ot\n"
; 	"ldy #_oc3_1ot\n"
; "calc_motor_done:\n"
; 	"ldx #_calc_1ot\n"
; 	"ldaa 0,x\n"
; 	"staa 0,y\n"
; 	"inx\n"
; 	"iny\n"
; 	"ldd 0,x\n"
; 	"std 0,y\n"
; 	"inx\n"
; 	"inx\n"
; 	"iny\n"
; 	"iny\n"
; 	"ldaa 0,x\n"
; 	"staa 0,y\n"
; 	"inx\n"
; 	"iny\n"
; 	"ldd 0,x\n"
; 	"std 0,y\n"
; 	"inx\n"
; 	"inx\n"
; 	"iny\n"
; 	"iny\n"
; 	"ldaa 0,x\n"
; 	"staa 0,y\n"
; 	"inx\n"
; 	"iny\n"
; 	"ldd 0,x\n"
; 	"std 0,y\n"
; "multvlve_done:\n"
; 	"ldx _x_preserve");
; 	
; 	
; }
L5:
	inx
	inx
	txs
	pulx
	puly
	rts
;  IX -> 0,x
;          ?temp -> 2,x
;          ?temp -> 4,x
;          ?temp -> 6,x
;          ?temp -> 8,x
;          ?temp -> 10,x
;          ?temp -> 12,x
;          ?temp -> 14,x
;          ?temp -> 16,x
;          ?temp -> 18,x
;          ?temp -> 20,x
;          ?temp -> 22,x
;          ?temp -> 24,x
;          ?temp -> 26,x
;          ?temp -> 28,x
;          ?temp -> 30,x
;          ?temp -> 32,x
;     derivative -> 34,x
;       integral -> 36,x
;     proportion -> 38,x
;       new_duty -> 40,x
_pid_controller::
	jsr __enterb
	.byte 0x2a
	.dbfunc pid_controller
	.dbline 655
; 
; /********************************************************/
; /*pid_controller()										*/
; /*function contains all the pid routines to update		*/
; /*the duty cycles										*/
; /*														*/
; /********************************************************/
; 
; void pid_controller(void){
; 
; 	int proportion = 0;
	ldd #0
	std 38,x
	.dbline 656
; 	int integral = 0;
	ldd #0
	std 36,x
	.dbline 657
; 	int derivative = 0;
	ldd #0
	std 34,x
	.dbline 658
; 	int new_duty = 0;
	ldd #0
	std 40,x
	.dbline 664
; 
; 	
; 	//Run pid for cylinder 1
; 		
; 		//shift error values
; 		error1[2] = error1[1];
	ldd _error1+2
	std _error1+4
	.dbline 665
; 		error1[1] = error1[0];
	ldd _error1
	std _error1+2
	.dbline 666
; 		error1[0] = cyl1_des - cyl1_pstn;
	ldd _cyl1_des
	subd _cyl1_pstn
	std _error1
	.dbline 669
; 	
; 		//range for tolerance
; 		if (error1[0] < TOLERANCE & error1[0] > 0 - TOLERANCE){
	ldd _error1
	cpd #4
	bge L14
	ldd #1
	std 32,x
	bra L15
L14:
	ldd #0
	std 32,x
L15:
	ldd _error1
	cpd #-4
	ble L16
	ldd #1
	std 30,x
	bra L17
L16:
	ldd #0
	std 30,x
L17:
	ldd 32,x
	anda 30,x
	andb 31,x
	cpd #0
	beq L10
	.dbline 670
; 			error1[0] = 0; 
	ldd #0
	std _error1
	.dbline 671
; 			multvlve(0, 0x01);
	ldd #1
	pshb
	psha
	ldd #0
	jsr _multvlve
	puly
	.dbline 672
; 		}
	bra L11
L10:
	.dbline 676
; 		else { //run pid
; 	
; 			//calc gains
; 			proportion = K1[P] * error1[0];
	ldd _K1
	ldy _error1
	jsr __muli
	std 38,x
	.dbline 681
; 			//integral = K1[I];  
; 			//derivative = K1[D] * (error1[0] - error1[1]);
; 		
; 			//calc new raw value
; 			new_duty = proportion + integral + derivative;
	ldd 38,x
	addd 36,x
	addd 34,x
	std 40,x
	.dbline 684
; 		
; 		
; 			if (error1[0] < 0) {
	ldd _error1
	bge L18
	.dbline 685
; 				DIR_PORT &= 0xFE;
	ldy #0x4000
	bclr 0,y,#0x1
	.dbline 686
; 			}
	bra L19
L18:
	.dbline 688
; 			else { 
; 				DIR_PORT |= 0x01;
	ldy #0x4000
	bset 0,y,#1
	.dbline 689
; 			}
L19:
	.dbline 692
; 			
; 			//take absolute value of new_duty
; 			if (new_duty < 0){
	ldd 40,x
	bge L20
		ldd 40,x
	subd #1
	coma
	comb
	std 40,x
	

	.dbline 698
; 				asm("ldd %new_duty\n"
; 					"subd #1\n"
; 					"coma\n"
; 					"comb\n"
; 					"std %new_duty\n");
; 			}
L20:
	.dbline 700
; 			//range new_duty to max value
; 			if (new_duty > 236){
	ldd 40,x
	cpd #236
	ble L22
	.dbline 701
; 					new_duty = 236;
	ldd #236
	std 40,x
	.dbline 702
; 				}
L22:
	.dbline 704
; 		
; 			new_duty = pwm_vals[new_duty];
	ldd 40,x
	lsld
	addd #_pwm_vals
	xgdy
	ldd 0,y
	std 40,x
	.dbline 707
; 			
; 		
; 			multvlve(new_duty, 0x01);
	ldd #1
	pshb
	psha
	ldd 40,x
	jsr _multvlve
	puly
	.dbline 709
; 		
; 		}
L11:
	.dbline 714
; 		
;           //Run pid for cylinder 2
; 		
; 		//shift error values
; 		error2[2] = error2[1];
	ldd _error2+2
	std _error2+4
	.dbline 715
; 		error2[1] = error2[0];
	ldd _error2
	std _error2+2
	.dbline 716
; 		error2[0] = cyl2_des - cyl2_pstn;
	ldd _cyl2_des
	subd _cyl2_pstn
	std _error2
	.dbline 719
; 	
; 		//range for tolerance
; 		if (error2[0] < TOLERANCE & error2[0] > 0 - TOLERANCE){
	ldd _error2
	cpd #4
	bge L31
	ldd #1
	std 28,x
	bra L32
L31:
	ldd #0
	std 28,x
L32:
	ldd _error2
	cpd #-4
	ble L33
	ldd #1
	std 26,x
	bra L34
L33:
	ldd #0
	std 26,x
L34:
	ldd 28,x
	anda 26,x
	andb 27,x
	cpd #0
	beq L27
	.dbline 720
; 			error2[0] = 0; 
	ldd #0
	std _error2
	.dbline 721
; 			multvlve(0, 0x02);
	ldd #2
	pshb
	psha
	ldd #0
	jsr _multvlve
	puly
	.dbline 722
; 		}
	bra L28
L27:
	.dbline 726
; 		else { //run pid
; 	
; 			//calc gains
; 			proportion = K2[P] * error2[0];
	ldd _K2
	ldy _error2
	jsr __muli
	std 38,x
	.dbline 731
; 			//integral = K2[I];  
; 			//derivative = K2[D] * (error2[0] - error2[1]);
; 		
; 			//calc new raw value
; 			new_duty = proportion + integral + derivative;
	ldd 38,x
	addd 36,x
	addd 34,x
	std 40,x
	.dbline 734
; 		
; 		
; 			if (error2[0] < 0) {
	ldd _error2
	bge L35
	.dbline 735
; 				DIR_PORT &= 0xFD;
	ldy #0x4000
	bclr 0,y,#0x2
	.dbline 736
; 			}
	bra L36
L35:
	.dbline 738
; 			else { 
; 				DIR_PORT |= 0x02;
	ldy #0x4000
	bset 0,y,#2
	.dbline 739
; 			}
L36:
	.dbline 742
; 			
; 			//take absolute value of new_duty
; 			if (new_duty < 0){
	ldd 40,x
	bge L37
		ldd 40,x
	subd #1
	coma
	comb
	std 40,x
	

	.dbline 748
; 				asm("ldd %new_duty\n"
; 					"subd #1\n"
; 					"coma\n"
; 					"comb\n"
; 					"std %new_duty\n");
; 			}
L37:
	.dbline 750
; 			//range new_duty to max value
; 			if (new_duty > 236){
	ldd 40,x
	cpd #236
	ble L39
	.dbline 751
; 					new_duty = 236;
	ldd #236
	std 40,x
	.dbline 752
; 				}
L39:
	.dbline 754
; 		
; 			new_duty = pwm_vals[new_duty];
	ldd 40,x
	lsld
	addd #_pwm_vals
	xgdy
	ldd 0,y
	std 40,x
	.dbline 757
; 			
; 		
; 			multvlve(new_duty, 0x02);
	ldd #2
	pshb
	psha
	ldd 40,x
	jsr _multvlve
	puly
	.dbline 759
; 		
; 		}		
L28:
	.dbline 765
; 
; 
;          //Run pid for cylinder 3
; 		
; 		//shift error values
; 		error3[2] = error3[1];
	ldd _error3+2
	std _error3+4
	.dbline 766
; 		error3[1] = error3[0];
	ldd _error3
	std _error3+2
	.dbline 767
; 		error3[0] = cyl3_des - cyl3_pstn;
	ldd _cyl3_des
	subd _cyl3_pstn
	std _error3
	.dbline 770
; 	
; 		//range for tolerance
; 		if (error3[0] < TOLERANCE & error3[0] > 0 - TOLERANCE){
	ldd _error3
	cpd #4
	bge L48
	ldd #1
	std 24,x
	bra L49
L48:
	ldd #0
	std 24,x
L49:
	ldd _error3
	cpd #-4
	ble L50
	ldd #1
	std 22,x
	bra L51
L50:
	ldd #0
	std 22,x
L51:
	ldd 24,x
	anda 22,x
	andb 23,x
	cpd #0
	beq L44
	.dbline 771
; 			error3[0] = 0; 
	ldd #0
	std _error3
	.dbline 772
; 			multvlve(0, 0x03);
	ldd #3
	pshb
	psha
	ldd #0
	jsr _multvlve
	puly
	.dbline 773
; 		}
	bra L45
L44:
	.dbline 777
; 		else { //run pid
; 	
; 			//calc gains
; 			proportion = K3[P] * error3[0];
	ldd _K3
	ldy _error3
	jsr __muli
	std 38,x
	.dbline 782
; 			//integral = K3[I];  
; 			//derivative = K3[D] * (error3[0] - error3[1]);
; 		
; 			//calc new raw value
; 			new_duty = proportion + integral + derivative;
	ldd 38,x
	addd 36,x
	addd 34,x
	std 40,x
	.dbline 785
; 		
; 		
; 			if (error3[0] < 0) {
	ldd _error3
	bge L52
	.dbline 786
; 				DIR_PORT &= 0xFB;
	ldy #0x4000
	bclr 0,y,#0x4
	.dbline 787
; 			}
	bra L53
L52:
	.dbline 789
; 			else { 
; 				DIR_PORT |= 0x04;
	ldy #0x4000
	bset 0,y,#4
	.dbline 790
; 			}
L53:
	.dbline 793
; 			
; 			//take absolute value of new_duty
; 			if (new_duty < 0){
	ldd 40,x
	bge L54
		ldd 40,x
	subd #1
	coma
	comb
	std 40,x
	

	.dbline 799
; 				asm("ldd %new_duty\n"
; 					"subd #1\n"
; 					"coma\n"
; 					"comb\n"
; 					"std %new_duty\n");
; 			}
L54:
	.dbline 801
; 			//range new_duty to max value
; 			if (new_duty > 236){
	ldd 40,x
	cpd #236
	ble L56
	.dbline 802
; 					new_duty = 236;
	ldd #236
	std 40,x
	.dbline 803
; 				}
L56:
	.dbline 805
; 		
; 			new_duty = pwm_vals[new_duty];
	ldd 40,x
	lsld
	addd #_pwm_vals
	xgdy
	ldd 0,y
	std 40,x
	.dbline 808
; 			
; 		
; 			multvlve(new_duty, 0x03);
	ldd #3
	pshb
	psha
	ldd 40,x
	jsr _multvlve
	puly
	.dbline 810
; 		
; 		}		
L45:
	.dbline 817
; 
; 
; 
;         //Run pid for cylinder 4
; 		
; 		//shift error values
; 		error4[2] = error4[1];
	ldd _error4+2
	std _error4+4
	.dbline 818
; 		error4[1] = error4[0];
	ldd _error4
	std _error4+2
	.dbline 819
; 		error4[0] = cyl4_des - cyl4_pstn;
	ldd _cyl4_des
	subd _cyl4_pstn
	std _error4
	.dbline 822
; 	
; 		//range for tolerance
; 		if (error4[0] < TOLERANCE & error4[0] > 0 - TOLERANCE){
	ldd _error4
	cpd #4
	bge L65
	ldd #1
	std 20,x
	bra L66
L65:
	ldd #0
	std 20,x
L66:
	ldd _error4
	cpd #-4
	ble L67
	ldd #1
	std 18,x
	bra L68
L67:
	ldd #0
	std 18,x
L68:
	ldd 20,x
	anda 18,x
	andb 19,x
	cpd #0
	beq L61
	.dbline 823
; 			error4[0] = 0; 
	ldd #0
	std _error4
	.dbline 824
; 			multvlve(0, 0x04);
	ldd #4
	pshb
	psha
	ldd #0
	jsr _multvlve
	puly
	.dbline 825
; 		}
	bra L62
L61:
	.dbline 829
; 		else { //run pid
; 	
; 			//calc gains
; 			proportion = K4[P] * error4[0];
	ldd _K4
	ldy _error4
	jsr __muli
	std 38,x
	.dbline 834
; 			//integral = K4[I];  
; 			//derivative = K4[D] * (error4[0] - error4[1]);
; 		
; 			//calc new raw value
; 			new_duty = proportion + integral + derivative;
	ldd 38,x
	addd 36,x
	addd 34,x
	std 40,x
	.dbline 837
; 		
; 		
; 			if (error4[0] < 0) {
	ldd _error4
	bge L69
	.dbline 838
; 				DIR_PORT &= 0xF7;
	ldy #0x4000
	bclr 0,y,#0x8
	.dbline 839
; 			}
	bra L70
L69:
	.dbline 841
; 			else { 
; 				DIR_PORT |= 0x08;
	ldy #0x4000
	bset 0,y,#8
	.dbline 842
; 			}
L70:
	.dbline 845
; 			
; 			//take absolute value of new_duty
; 			if (new_duty < 0){
	ldd 40,x
	bge L71
		ldd 40,x
	subd #1
	coma
	comb
	std 40,x
	

	.dbline 851
; 				asm("ldd %new_duty\n"
; 					"subd #1\n"
; 					"coma\n"
; 					"comb\n"
; 					"std %new_duty\n");
; 			}
L71:
	.dbline 853
; 			//range new_duty to max value
; 			if (new_duty > 236){
	ldd 40,x
	cpd #236
	ble L73
	.dbline 854
; 					new_duty = 236;
	ldd #236
	std 40,x
	.dbline 855
; 				}
L73:
	.dbline 857
; 		
; 			new_duty = pwm_vals[new_duty];
	ldd 40,x
	lsld
	addd #_pwm_vals
	xgdy
	ldd 0,y
	std 40,x
	.dbline 860
; 			
; 		
; 			multvlve(new_duty, 0x04);
	ldd #4
	pshb
	psha
	ldd 40,x
	jsr _multvlve
	puly
	.dbline 862
; 		
; 		}		
L62:
	.dbline 868
; 
; 
;         //Run pid for cylinder 5
; 		
; 		//shift error values
; 		error5[2] = error5[1];
	ldd _error5+2
	std _error5+4
	.dbline 869
; 		error5[1] = error5[0];
	ldd _error5
	std _error5+2
	.dbline 870
; 		error5[0] = cyl5_des - cyl5_pstn;
	ldd _cyl5_des
	subd _cyl5_pstn
	std _error5
	.dbline 873
; 	
; 		//range for tolerance
; 		if (error5[0] < TOLERANCE & error5[0] > 0 - TOLERANCE){
	ldd _error5
	cpd #4
	bge L82
	ldd #1
	std 16,x
	bra L83
L82:
	ldd #0
	std 16,x
L83:
	ldd _error5
	cpd #-4
	ble L84
	ldd #1
	std 14,x
	bra L85
L84:
	ldd #0
	std 14,x
L85:
	ldd 16,x
	anda 14,x
	andb 15,x
	cpd #0
	beq L78
	.dbline 874
; 			error5[0] = 0; 
	ldd #0
	std _error5
	.dbline 875
; 			multvlve(0, 0x05);
	ldd #5
	pshb
	psha
	ldd #0
	jsr _multvlve
	puly
	.dbline 876
; 		}
	bra L79
L78:
	.dbline 880
; 		else { //run pid
; 	
; 			//calc gains
; 			proportion = K5[P] * error5[0];
	ldd _K5
	ldy _error5
	jsr __muli
	std 38,x
	.dbline 885
; 			//integral = K5[I];  
; 			//derivative = K5[D] * (error5[0] - error5[1]);
; 		
; 			//calc new raw value
; 			new_duty = proportion + integral + derivative;
	ldd 38,x
	addd 36,x
	addd 34,x
	std 40,x
	.dbline 888
; 		
; 		
; 			if (error5[0] < 0) {
	ldd _error5
	bge L86
	.dbline 889
; 				DIR_PORT &= 0xEF;
	ldy #0x4000
	bclr 0,y,#0x10
	.dbline 890
; 			}
	bra L87
L86:
	.dbline 892
; 			else { 
; 				DIR_PORT |= 0x10;
	ldy #0x4000
	bset 0,y,#16
	.dbline 893
; 			}
L87:
	.dbline 896
; 			
; 			//take absolute value of new_duty
; 			if (new_duty < 0){
	ldd 40,x
	bge L88
		ldd 40,x
	subd #1
	coma
	comb
	std 40,x
	

	.dbline 902
; 				asm("ldd %new_duty\n"
; 					"subd #1\n"
; 					"coma\n"
; 					"comb\n"
; 					"std %new_duty\n");
; 			}
L88:
	.dbline 904
; 			//range new_duty to max value
; 			if (new_duty > 236){
	ldd 40,x
	cpd #236
	ble L90
	.dbline 905
; 					new_duty = 236;
	ldd #236
	std 40,x
	.dbline 906
; 				}
L90:
	.dbline 908
; 		
; 			new_duty = pwm_vals[new_duty];
	ldd 40,x
	lsld
	addd #_pwm_vals
	xgdy
	ldd 0,y
	std 40,x
	.dbline 911
; 			
; 		
; 			multvlve(new_duty, 0x05);
	ldd #5
	pshb
	psha
	ldd 40,x
	jsr _multvlve
	puly
	.dbline 913
; 		
; 		}		
L79:
	.dbline 919
; 
; 
;         //Run pid for cylinder 6
; 		
; 		//shift error values
; 		error6[2] = error6[1];
	ldd _error6+2
	std _error6+4
	.dbline 920
; 		error6[1] = error6[0];
	ldd _error6
	std _error6+2
	.dbline 921
; 		error6[0] = cyl6_des - cyl6_pstn;
	ldd _cyl6_des
	subd _cyl6_pstn
	std _error6
	.dbline 924
; 	
; 		//range for tolerance
; 		if (error6[0] < TOLERANCE & error6[0] > 0 - TOLERANCE){
	ldd _error6
	cpd #4
	bge L99
	ldd #1
	std 12,x
	bra L100
L99:
	ldd #0
	std 12,x
L100:
	ldd _error6
	cpd #-4
	ble L101
	ldd #1
	std 10,x
	bra L102
L101:
	ldd #0
	std 10,x
L102:
	ldd 12,x
	anda 10,x
	andb 11,x
	cpd #0
	beq L95
	.dbline 925
; 			error6[0] = 0; 
	ldd #0
	std _error6
	.dbline 926
; 			multvlve(0, 0x06);
	ldd #6
	pshb
	psha
	ldd #0
	jsr _multvlve
	puly
	.dbline 927
; 		}
	bra L96
L95:
	.dbline 931
; 		else { //run pid
; 	
; 			//calc gains
; 			proportion = K6[P] * error6[0];
	ldd _K6
	ldy _error6
	jsr __muli
	std 38,x
	.dbline 936
; 			//integral = K6[I];  
; 			//derivative = K6[D] * (error6[0] - error6[1]);
; 		
; 			//calc new raw value
; 			new_duty = proportion + integral + derivative;
	ldd 38,x
	addd 36,x
	addd 34,x
	std 40,x
	.dbline 939
; 		
; 		
; 			if (error6[0] < 0) {
	ldd _error6
	bge L103
	.dbline 940
; 				DIR_PORT &= 0xDF;
	ldy #0x4000
	bclr 0,y,#0x20
	.dbline 941
; 			}
	bra L104
L103:
	.dbline 943
; 			else { 
; 				DIR_PORT |= 0x20;
	ldy #0x4000
	bset 0,y,#32
	.dbline 944
; 			}
L104:
	.dbline 947
; 			
; 			//take absolute value of new_duty
; 			if (new_duty < 0){
	ldd 40,x
	bge L105
		ldd 40,x
	subd #1
	coma
	comb
	std 40,x
	

	.dbline 953
; 				asm("ldd %new_duty\n"
; 					"subd #1\n"
; 					"coma\n"
; 					"comb\n"
; 					"std %new_duty\n");
; 			}
L105:
	.dbline 955
; 			//range new_duty to max value
; 			if (new_duty > 236){
	ldd 40,x
	cpd #236
	ble L107
	.dbline 956
; 					new_duty = 236;
	ldd #236
	std 40,x
	.dbline 957
; 				}
L107:
	.dbline 959
; 		
; 			new_duty = pwm_vals[new_duty];
	ldd 40,x
	lsld
	addd #_pwm_vals
	xgdy
	ldd 0,y
	std 40,x
	.dbline 962
; 			
; 		
; 			multvlve(new_duty, 0x06);
	ldd #6
	pshb
	psha
	ldd 40,x
	jsr _multvlve
	puly
	.dbline 964
; 		
; 		}		
L96:
	.dbline 971
; 
; 
; 
;         //Run pid for cylinder 7
; 		
; 		//shift error values
; 		error7[2] = error7[1];
	ldd _error7+2
	std _error7+4
	.dbline 972
; 		error7[1] = error7[0];
	ldd _error7
	std _error7+2
	.dbline 973
; 		error7[0] = cyl7_des - cyl7_pstn;
	ldd _cyl7_des
	subd _cyl7_pstn
	std _error7
	.dbline 976
; 	
; 		//range for tolerance
; 		if (error7[0] < TOLERANCE & error7[0] > 0 - TOLERANCE){
	ldd _error7
	cpd #4
	bge L116
	ldd #1
	std 8,x
	bra L117
L116:
	ldd #0
	std 8,x
L117:
	ldd _error7
	cpd #-4
	ble L118
	ldd #1
	std 6,x
	bra L119
L118:
	ldd #0
	std 6,x
L119:
	ldd 8,x
	anda 6,x
	andb 7,x
	cpd #0
	beq L112
	.dbline 977
; 			error7[0] = 0; 
	ldd #0
	std _error7
	.dbline 978
; 			multvlve(0, 0x07);
	ldd #7
	pshb
	psha
	ldd #0
	jsr _multvlve
	puly
	.dbline 979
; 		}
	bra L113
L112:
	.dbline 983
; 		else { //run pid
; 	
; 			//calc gains
; 			proportion = K7[P] * error7[0];
	ldd _K7
	ldy _error7
	jsr __muli
	std 38,x
	.dbline 988
; 			//integral = K7[I];  
; 			//derivative = K7[D] * (error7[0] - error7[1]);
; 		
; 			//calc new raw value
; 			new_duty = proportion + integral + derivative;
	ldd 38,x
	addd 36,x
	addd 34,x
	std 40,x
	.dbline 991
; 		
; 		
; 			if (error7[0] < 0) {
	ldd _error7
	bge L120
	.dbline 992
; 				DIR_PORT &= 0xBF;
	ldy #0x4000
	bclr 0,y,#0x40
	.dbline 993
; 			}
	bra L121
L120:
	.dbline 995
; 			else { 
; 				DIR_PORT |= 0x40;
	ldy #0x4000
	bset 0,y,#64
	.dbline 996
; 			}
L121:
	.dbline 999
; 			
; 			//take absolute value of new_duty
; 			if (new_duty < 0){
	ldd 40,x
	bge L122
		ldd 40,x
	subd #1
	coma
	comb
	std 40,x
	

	.dbline 1005
; 				asm("ldd %new_duty\n"
; 					"subd #1\n"
; 					"coma\n"
; 					"comb\n"
; 					"std %new_duty\n");
; 			}
L122:
	.dbline 1007
; 			//range new_duty to max value
; 			if (new_duty > 236){
	ldd 40,x
	cpd #236
	ble L124
	.dbline 1008
; 					new_duty = 236;
	ldd #236
	std 40,x
	.dbline 1009
; 				}
L124:
	.dbline 1011
; 		
; 			new_duty = pwm_vals[new_duty];
	ldd 40,x
	lsld
	addd #_pwm_vals
	xgdy
	ldd 0,y
	std 40,x
	.dbline 1014
; 			
; 		
; 			multvlve(new_duty, 0x07);
	ldd #7
	pshb
	psha
	ldd 40,x
	jsr _multvlve
	puly
	.dbline 1016
; 		
; 		}		
L113:
	.dbline 1023
; 
; 
; 
;         //Run pid for cylinder 8
; 		
; 		//shift error values
; 		error8[2] = error8[1];
	ldd _error8+2
	std _error8+4
	.dbline 1024
; 		error8[1] = error8[0];
	ldd _error8
	std _error8+2
	.dbline 1025
; 		error8[0] = cyl8_des - cyl8_pstn;
	ldd _cyl8_des
	subd _cyl8_pstn
	std _error8
	.dbline 1028
; 	
; 		//range for tolerance
; 		if (error8[0] < TOLERANCE & error8[0] > 0 - TOLERANCE){
	ldd _error8
	cpd #4
	bge L133
	ldd #1
	std 4,x
	bra L134
L133:
	ldd #0
	std 4,x
L134:
	ldd _error8
	cpd #-4
	ble L135
	ldd #1
	std 2,x
	bra L136
L135:
	ldd #0
	std 2,x
L136:
	ldd 4,x
	anda 2,x
	andb 3,x
	cpd #0
	beq L129
	.dbline 1029
; 			error8[0] = 0; 
	ldd #0
	std _error8
	.dbline 1030
; 			multvlve(0, 0x08);
	ldd #8
	pshb
	psha
	ldd #0
	jsr _multvlve
	puly
	.dbline 1031
; 		}
	bra L130
L129:
	.dbline 1035
; 		else { //run pid
; 	
; 			//calc gains
; 			proportion = K8[P] * error8[0];
	ldd _K8
	ldy _error8
	jsr __muli
	std 38,x
	.dbline 1040
; 			//integral = K8[I];  
; 			//derivative = K8[D] * (error8[0] - error8[1]);
; 		
; 			//calc new raw value
; 			new_duty = proportion + integral + derivative;
	ldd 38,x
	addd 36,x
	addd 34,x
	std 40,x
	.dbline 1043
; 		
; 		
; 			if (error8[0] < 0) {
	ldd _error8
	bge L137
	.dbline 1044
; 				DIR_PORT &= 0x7F;
	ldy #0x4000
	bclr 0,y,#0x80
	.dbline 1045
; 			}
	bra L138
L137:
	.dbline 1047
; 			else { 
; 				DIR_PORT |= 0x80;
	ldy #0x4000
	bset 0,y,#128
	.dbline 1048
; 			}
L138:
	.dbline 1051
; 			
; 			//take absolute value of new_duty
; 			if (new_duty < 0){
	ldd 40,x
	bge L139
		ldd 40,x
	subd #1
	coma
	comb
	std 40,x
	

	.dbline 1057
; 				asm("ldd %new_duty\n"
; 					"subd #1\n"
; 					"coma\n"
; 					"comb\n"
; 					"std %new_duty\n");
; 			}
L139:
	.dbline 1059
; 			//range new_duty to max value
; 			if (new_duty > 236){
	ldd 40,x
	cpd #236
	ble L141
	.dbline 1060
; 					new_duty = 236;
	ldd #236
	std 40,x
	.dbline 1061
; 				}
L141:
	.dbline 1063
; 		
; 			new_duty = pwm_vals[new_duty];
	ldd 40,x
	lsld
	addd #_pwm_vals
	xgdy
	ldd 0,y
	std 40,x
	.dbline 1066
; 			
; 		
; 			multvlve(new_duty, 0x08);
	ldd #8
	pshb
	psha
	ldd 40,x
	jsr _multvlve
	puly
	.dbline 1068
; 		
; 		}		
L130:
	.dbline 1073
; 
; 
; 
; 	
; 	handleSampleFlag = 0;
	clr _handleSampleFlag
	.dbline 1074
; }
L6:
	xgdx
	addd #42
	xgdx
	txs
	pulx
	rts
;  IX -> 0,x
;  rMEM -> 2,x
;          ?temp -> 4,x
;          ?temp -> 6,x
;          ?temp -> 8,x
;          ?temp -> 10,x
;    cylinderDes -> 12,x
; cylinderNumber -> 13,x
;        counter -> 14,x
_decode_command::
	jsr __enterb
	.byte 0x10
	.dbfunc decode_command
	.dbline 1086
; 
; 
; /********************************************************/
; /*decode_command()										*/
; /*function to decode the commands recieved on the 		*/
; /*serial port											*/
; /*														*/
; /********************************************************/
; 
; void decode_command(void){
; 
; 	int counter = 0;
	ldd #0
	std 14,x
	.dbline 1087
; 	char cylinderNumber = 0;
	clr 13,x
	.dbline 1088
; 	char cylinderDes = 0;
	clr 12,x
	bra L145
L144:
	.dbline 1094
	ldd 14,x
	addd #1
	std 14,x
	.dbline 1095
L145:
	.dbline 1093
; 	
; 	
; 	//search through command string to find start char 
; 	//in case of bogus data
; 	while(counter < COMMAND_LENGTH && Command[counter] != START_CHAR)
	ldd 14,x
	cpd #7
	bge L147
	ldd 14,x
	addd #_Command
	xgdy
	ldab 0,y
	cmpb #36
	bne L144
L147:
	.dbline 1097
; 	{counter++;
; 	}
; 
; 	if (counter == COMMAND_LENGTH){//bogus data so return
	ldd 14,x
	cpd #7
	bne L148
	.dbline 1098
; 		handleCommandFlag = 0;
	clr _handleCommandFlag
	.dbline 1099
; 		return;
	jmp L143
L148:
	.dbline 1102
; 		} 
; 
; 	switch (Command[counter + 1]){
	ldd 14,x
	addd #_Command+1
	xgdy
	ldab 0,y
	clra
	tstb
	bpl X0
	coma
X0:
	std 10,x
	cpd #67
	beq L154
	jmp L150
L154:
	.dbline 1104
; 		case 'C': //cylinder position value
; 			cylinderNumber = Command[counter + 2] & 0x0F;
	ldd 14,x
	addd #_Command+2
	xgdy
	ldab 0,y
	andb #15
	stab 13,x
	.dbline 1105
; 			Command[counter + 3] &= 0x0F;
	ldd 14,x
	addd #_Command+3
	std 8,x
	ldy 8,x
	pshy ; spill
	ldy 8,x
	puly ; reload
	bclr 0,y,#0xf0
	.dbline 1106
; 			Command[counter + 4] &= 0x0F;
	ldd 14,x
	addd #_Command+4
	std 6,x
	ldy 6,x
	pshy ; spill
	ldy 6,x
	puly ; reload
	bclr 0,y,#0xf0
	.dbline 1107
; 			Command[counter + 5] &= 0x0F;
	ldd 14,x
	addd #_Command+5
	std 4,x
	ldy 4,x
	pshy ; spill
	ldy 4,x
	puly ; reload
	bclr 0,y,#0xf0
	.dbline 1108
; 			cylinderDes = Command[counter + 3] * 100 + Command[counter + 4] * 10 + Command[counter + 5];
	ldd 14,x
	addd #_Command+4
	xgdy
	ldab 0,y
	clra
	tstb
	bpl X1
	coma
X1:
	xgdy
	ldd #10
	jsr __muli
	std 2,x
	ldd 14,x
	addd #_Command+3
	xgdy
	ldab 0,y
	clra
	tstb
	bpl X2
	coma
X2:
	xgdy
	ldd #100
	jsr __muli
	addd 2,x
	pshb ; 
	psha ; spill
	ldd 14,x
	addd #_Command+5
	xgdy
	ldab 0,y
	clra
	tstb
	bpl X3
	coma
X3:
	std 2,x
	pula ; 
	pulb ; reload
	addd 2,x
	stab 12,x
		ldab 13,x
	subb #1
	lslb
	ldaa 12,x
	stx _x_preserve
	ldx #_cyl1_des
	abx
	inx
	staa 0,x
	ldx _x_preserve

	.dbline 1121
; 			//store new command into global variables
; 			asm("ldab %cylinderNumber\n"
; 			"subb #1\n"
; 			"lslb\n"
; 			"ldaa %cylinderDes\n"
; 			"stx _x_preserve\n"
; 			"ldx #_cyl1_des\n"
; 			"abx\n"
; 			"inx\n"
; 			"staa 0,x\n"
; 			"ldx _x_preserve");
; 			
; 			break ;
L150:
L151:
	.dbline 1127
; 		
; 		//put next command case here
; 		
; 	}//ends switch statement
; 	
; 	handleCommandFlag = 0;
	clr _handleCommandFlag
	.dbline 1128
; }
L143:
	xgdx
	addd #16
	xgdx
	txs
	pulx
	rts
;  IX -> 0,x
;           byte -> 5,x
_send_message::
	pshb
	psha
	pshx
	pshx
	tsx
	stx 0,x
	.dbfunc send_message
	.dbline 1139
; 
; /********************************************************/
; /*send_message(byte)									*/
; /*function to send a byte out the serial port			*/
; /*														*/
; /*														*/
; /********************************************************/
; 
; void send_message(char byte)
; {
; 	Message = byte;
	ldab 5,x
	stab _Message
	.dbline 1140
;     SCCR2 |= 0x80;
	ldy #0x102d
	bset 0,y,#128
	.dbline 1141
; }
L162:
	inx
	inx
	txs
	pulx
	puly
	rts
;  IX -> 0,x
;          ?temp -> 3,x
_SCI_isr::
	jsr __enterb
	.byte 0x4
	.dbfunc SCI_isr
	.dbline 1154
; 			 
; /********************************************************/
; /*ISRs													*/
; /*														*/
; /*														*/
; /*														*/
; /********************************************************/
; 
; /* Captures incoming messages of CommandLength bytes */
; /* Sends one byte messages then disables TIE */
; /* SCI isr */
; void SCI_isr() {
;   if(SCSR & 0X20) {
	ldy #0x102e
	brclr 0,y,#32,L164
	.dbline 1155
;     Command[CommandPos] = SCDR;
	ldab _CommandPos
	clra
	tstb
	bpl X4
	coma
X4:
	addd #_Command
	xgdy
	; vol
	ldab 0x102f
	stab 0,y
	.dbline 1156
;     send_message(SCDR);			// Include to echo characters
	; vol
	ldab 0x102f
	clra
	tstb
	bpl X5
	coma
X5:
	jsr _send_message
	.dbline 1157
;     if (++CommandPos == COMMAND_LENGTH) {
	ldab _CommandPos
	addb #1
	stab 3,x
	stab _CommandPos
	ldab 3,x
	cmpb #7
	bne L166
	.dbline 1158
;       CommandPos = 0;
	clr _CommandPos
	.dbline 1159
;     }
L166:
	.dbline 1160
;     if (SCDR == END_CHAR) {
	; vol
	ldab 0x102f
	cmpb #35
	bne L165
	.dbline 1161
;       handleCommandFlag = 1;
	ldab #1
	stab _handleCommandFlag
	.dbline 1163
;     }
;   }
	bra L165
L164:
	.dbline 1164
;   else if(SCSR & 0X80) {
	ldy #0x102e
	brclr 0,y,#128,L170
	.dbline 1165
;     SCDR = Message;
	ldab _Message
	stab 0x102f
	.dbline 1166
;     SCCR2 &= 0X7F;
	ldy #0x102d
	bclr 0,y,#0x80
	.dbline 1167
;   }
L170:
L165:
	.dbline 1169
;   
; }
L163:
	inx
	inx
	inx
	inx
	txs
	pulx
	rti
;  IX -> 0,x
_TOC5_isr::
	.dbfunc TOC5_isr
	.dbline 1175
; 
; 
; /*TOC5_isr- controls motors 7 and 8*/
; void TOC5_isr()
; {
; 	TFLG1 = 0x08;	 //clear interrupt flag
	ldab #8
	stab 0x1023
		ldy _oc5_reg
	ldaa _mot_spd
	anda #$3f
	oraa 0,y
	staa _mot_spd
	ldx _pwm_port
	staa 0,x
	iny
	ldx #$101E
	ldd 0,y
	addd 0,x
	std 0,x
	cpy #_oc5_3vl
	bne oc5_rti
	ldy #_oc5_reg
	oc5_rti:
	iny
	iny
	sty _oc5_reg

	.dbline 1195
;    asm("ldy _oc5_reg\n"
; 	"ldaa _mot_spd\n"
; 	"anda #$3f\n"
; 	"oraa 0,y\n"
; 	"staa _mot_spd\n"
; 	"ldx _pwm_port\n"
; 	"staa 0,x\n"
; 	"iny\n"
; 	"ldx #$101E\n"
; 	"ldd 0,y\n"
; 	"addd 0,x\n"
; 	"std 0,x\n"
; 	"cpy #_oc5_3vl\n"
; 	"bne oc5_rti\n"
; 	"ldy #_oc5_reg\n"
; "oc5_rti:\n"	
; 	"iny\n"
; 	"iny\n"
; 	"sty _oc5_reg"); 
; }
L172:
	rti
;  IX -> 0,x
_TOC4_isr::
	.dbfunc TOC4_isr
	.dbline 1200
; 
; /*TOC4_isr - controls motors 5 and 6*/
; void TOC4_isr()
; {
; 	TFLG1 = 0X10; //clear interrupt flag
	ldab #16
	stab 0x1023
		ldy _oc4_reg
	ldaa _mot_spd
	anda #$cf
	oraa 0,y
	staa _mot_spd
	ldx _pwm_port
	staa 0,x
	iny
	ldx #$101C
	ldd 0,y
	addd 0,x
	std 0,x
	cpy #_oc4_3vl
	bne oc4_rti
	ldy #_oc4_reg
	oc4_rti:
	iny
	iny
	sty _oc4_reg

	.dbline 1220
;    asm("ldy _oc4_reg\n"
; 	"ldaa _mot_spd\n"
; 	"anda #$cf\n"
; 	"oraa 0,y\n"
; 	"staa _mot_spd\n"
; 	"ldx _pwm_port\n"
; 	"staa 0,x\n"
; 	"iny\n"
; 	"ldx #$101C\n"
; 	"ldd 0,y\n"
; 	"addd 0,x\n"
; 	"std 0,x\n"
; 	"cpy #_oc4_3vl\n"
; 	"bne oc4_rti\n"
; 	"ldy #_oc4_reg\n"
; "oc4_rti:\n"	
; 	"iny\n"
; 	"iny\n"
; 	"sty _oc4_reg"); 
; }
L173:
	rti
;  IX -> 0,x
_TOC3_isr::
	.dbfunc TOC3_isr
	.dbline 1226
; 	
; 
; /*TOC3_isr - controls motors 3 and 4*/
; void TOC3_isr()
; {
; 	TFLG1 = 0x20; //clear interrupt flag
	ldab #32
	stab 0x1023
		ldy _oc3_reg
	ldaa _mot_spd
	anda #$f3
	oraa 0,y
	staa _mot_spd
	ldx _pwm_port
	staa 0,x
	iny
	ldx #$101A
	ldd 0,y
	addd 0,x
	std 0,x
	cpy #_oc3_3vl
	bne oc3_rti
	ldy #_oc3_reg
	oc3_rti:
	iny
	iny
	sty _oc3_reg

	.dbline 1246
;    asm("ldy _oc3_reg\n"
; 	"ldaa _mot_spd\n"
; 	"anda #$f3\n"
; 	"oraa 0,y\n"
; 	"staa _mot_spd\n"
; 	"ldx _pwm_port\n"
; 	"staa 0,x\n"
; 	"iny\n"
; 	"ldx #$101A\n"
; 	"ldd 0,y\n"
; 	"addd 0,x\n"
; 	"std 0,x\n"
; 	"cpy #_oc3_3vl\n"
; 	"bne oc3_rti\n"
; 	"ldy #_oc3_reg\n"
; "oc3_rti:\n"	
; 	"iny\n"
; 	"iny\n"
; 	"sty _oc3_reg"); 
; }
L174:
	rti
;  IX -> 0,x
_TOC2_isr::
	.dbfunc TOC2_isr
	.dbline 1253
; 
; 
; 
; /*TOC2_isr - controls motors 1 and 2*/
; void TOC2_isr()
; {
; 	TFLG1 = 0x40; //clear interrupt flag
	ldab #64
	stab 0x1023
		ldy _oc2_reg
	ldaa _mot_spd
	anda #$fc
	oraa 0,y
	staa _mot_spd
	ldx _pwm_port
	staa 0,x
	iny
	ldx #$1018
	ldd 0,y
	addd 0,x
	std 0,x
	cpy #_oc2_3vl
	bne oc2_rti
	ldy #_oc2_reg
	oc2_rti:
	iny
	iny
	sty _oc2_reg

	.dbline 1274
; 	
;    asm("ldy _oc2_reg\n"
; 	"ldaa _mot_spd\n"
; 	"anda #$fc\n"
; 	"oraa 0,y\n"
; 	"staa _mot_spd\n"
; 	"ldx _pwm_port\n"
; 	"staa 0,x\n"
; 	"iny\n"
; 	"ldx #$1018\n"
; 	"ldd 0,y\n"
; 	"addd 0,x\n"
; 	"std 0,x\n"
; 	"cpy #_oc2_3vl\n"
; 	"bne oc2_rti\n"
; 	"ldy #_oc2_reg\n"
; "oc2_rti:\n"	
; 	"iny\n"
; 	"iny\n"
; 	"sty _oc2_reg"); 
; }
L175:
	rti
;  IX -> 0,x
_RTI_isr::
	.dbfunc RTI_isr
	.dbline 1280
; 
; /*RTI_isr - samples analog values on every third interrupt*/
; /*sets a flag to call PID controller*/
; void RTI_isr()
; {
; 	TFLG2 = 0x40; //clear flag
	ldab #64
	stab 0x1025
	.dbline 1281
; 	if (RTIcount < 2)
	ldab _RTIcount
	cmpb #2
	bge L177
	.dbline 1283
; 	{
; 		RTIcount++;
	inc _RTIcount
	.dbline 1284
; 		return;
	bra L176
L177:
	.dbline 1287
; 	}
; 	
; 	RTIcount = 0;
	clr _RTIcount
	.dbline 1290
; 	
; 	//run sample of all 8 cylinders
; 	ADCTL = 0x90	//CCF=1 SCAN=0 MULT=1 CD-CA=0000
	ldab #144
	stab 0x1030
		ldaa #21
	loop:
	deca
	bne loop

		ldaa $1031
	staa _cyl1_pstn + 1
	

		ldaa $1032
	staa _cyl2_pstn + 1
	

		ldaa $1033
	staa _cyl3_pstn + 1
	

		ldaa $1034
	staa _cyl4_pstn + 1
	

	.dbline 1316
; 	//wait for complete samples
; 	asm("ldaa #21\n"
; 		"loop:\n"
; 		"deca\n"
; 		"bne loop");
; 	
; 	//now load in the analog values
; 	//assembly routines to change char to int
; 	
; 	//cyl1_pstn = ADR1;
; 	asm("ldaa $1031\n"
; 		"staa _cyl1_pstn + 1\n");
; 		
; 	//cyl2_pstn = ADR2;
; 	asm("ldaa $1032\n"
; 		"staa _cyl2_pstn + 1\n");
; 			
; 	//cyl3_pstn = ADR3;
; 	asm("ldaa $1033\n"
; 		"staa _cyl3_pstn + 1\n");
; 		
; 	//cyl4_pstn = ADR4;
; 	asm("ldaa $1034\n"
; 		"staa _cyl4_pstn + 1\n");
; 	
; 	ADCTL = 0x94	//CCF=1 SCAN=0 MULT=1 CD-CA=0100
	ldab #148
	stab 0x1030
		ldaa #21
	loop2:
	deca
	bne loop2

		ldaa $1031
	staa _cyl5_pstn + 1
	

		ldaa $1032
	staa _cyl6_pstn + 1
	

		ldaa $1033
	staa _cyl7_pstn + 1
	

		ldaa $1034
	staa _cyl8_pstn + 1
	

	.dbline 1342
; 	//wait for complete samples
; 	asm("ldaa #21\n"
; 		"loop2:\n"
; 		"deca\n"
; 		"bne loop2");
; 		
; 	//cyl5_pstn = ADR1;
; 	asm("ldaa $1031\n"
; 		"staa _cyl5_pstn + 1\n");
; 		
; 	//cyl6_pstn = ADR2;	
; 	asm("ldaa $1032\n"
; 		"staa _cyl6_pstn + 1\n");
; 		
; 	//cyl7_pstn = ADR3;
; 	asm("ldaa $1033\n"
; 		"staa _cyl7_pstn + 1\n");
; 		
; 	//cyl8_pstn = ADR4;
; 	asm("ldaa $1034\n"
; 		"staa _cyl8_pstn + 1\n");
; 	
; 	//finished with sampling
; 	
; 	
; 	handleSampleFlag = 1; //set flag to run pid routine
	ldab #1
	stab _handleSampleFlag
	.dbline 1344
; 	
; }
L176:
	rti
;  IX -> 0,x
;          count -> 2,x
_main::
	jsr __enterb
	.byte 0x4
	.dbfunc main
	.dbline 1356
; 
; /********************************************************/
; /*Begin main function									*/
; /*														*/
; /*														*/
; /*														*/
; /********************************************************/
; 
; void main(void)
; {
; 
; 	int count = 1700;
	ldd #1700
	std 2,x
	.dbline 1360
; 	/*this must be here to initalize the pointers and 
; 	leave them in the correct momory space*/
; 	
; 	oc2_reg = &oc2_1ot;
	ldd #_oc2_1ot
	std _oc2_reg
	.dbline 1361
; 	oc3_reg = &oc3_1ot;
	ldd #_oc3_1ot
	std _oc3_reg
	.dbline 1362
; 	oc4_reg = &oc4_1ot;
	ldd #_oc4_1ot
	std _oc4_reg
	.dbline 1363
; 	oc5_reg = &oc5_1ot;
	ldd #_oc5_1ot
	std _oc5_reg
	.dbline 1365
; 
; 	init_analog();
	jsr _init_analog
	.dbline 1366
; 	init_SCI();
	jsr _init_SCI
	.dbline 1367
; 	init_pulse(); //set up interrupts for oc2-5
	jsr _init_pulse
	.dbline 1368
; 	init_RTI();
	jsr _init_RTI
	bra L181
L180:
	.dbline 1374
; 
;   //printf("\n\n starting\n");
;   //multvlve(20000, 0x01);
; 
; 	while(1){ //main loop 
; 		if(handleSampleFlag){
	tst _handleSampleFlag
	beq L183
	.dbline 1375
; 			pid_controller();
	jsr _pid_controller
	.dbline 1376
; 		}//ends if
L183:
	.dbline 1378
; 		
; 		if(handleCommandFlag){
	tst _handleCommandFlag
	beq L185
	.dbline 1379
; 			decode_command();
	jsr _decode_command
	.dbline 1380
; 		}//ends if
L185:
	.dbline 1382
; 		
; 	}//ends main while
L181:
	bra L180
L179:
	inx
	inx
	inx
	inx
	txs
	pulx
	rts
	.area memory(abs)
	.org 0xffd6
_interrupt_vectors::
	.word _SCI_isr
	.word 65535
	.word 65535
	.word 65535
	.word 65535
	.word _TOC5_isr
	.word _TOC4_isr
	.word _TOC3_isr
	.word _TOC2_isr
	.word 65535
	.word 65535
	.word 65535
	.word 65535
	.word _RTI_isr
	.word 65535
	.word 65535
	.word 65535
	.word 65535
	.word 65535
	.word 65535
	.word __start
	.area data
	.area bss
_Command::
	.blkb 14
