motor_routinesuncut.s 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. RES_BYTES equ 80
  2. RES_HEIGHT equ 256
  3. PLANE_HEIGHT equ 256
  4. PIXEL_WIDTH equ 480
  5. BYTES_PER_ROW equ PIXEL_WIDTH/8
  6. ***********************************************
  7. ***** MAINROUTINE *****
  8. ***********************************************
  9. mainroutine
  10. cmp.w #-1,direction
  11. beq.s speed_up_move
  12. bsr sync
  13. bsr read_resis
  14. speed_up_move
  15. bsr check_to_see_hit
  16. bsr readmouse
  17. bsr position_screen
  18. bsr step_scan_motor
  19. bsr inc_position
  20. bsr test_for_turn
  21. btst #10,$dff016
  22. bne.s no_save
  23. bra save_the_pic
  24. no_save
  25. btst #6,$bfe001
  26. bne mainroutine
  27. bra no_savey
  28. save_the_pic
  29. bsr save_pic
  30. no_savey
  31. rts
  32. ***********************************************
  33. ***** POSITION SCAN HEAD *****
  34. ***********************************************
  35. position_scan_head
  36. bsr set_scan_motor_read_direction
  37. move.w #10,d7
  38. move_motor_away_from_sensor
  39. bsr sync
  40. bsr step_scan_motor
  41. dbra d7,move_motor_away_from_sensor
  42. bsr set_scan_motor_rewind_direction
  43. move.w #0,d7
  44. find_sensor_touch
  45. add.w #1,d7
  46. cmp.w #PIXEL_WIDTH*2,d7 ;should find button by then
  47. beq.s error_scanner_not_attached
  48. bsr sync
  49. bsr step_scan_motor
  50. bsr check_joy
  51. cmp.w #0,d0
  52. beq.s find_sensor_touch
  53. bsr set_scan_motor_read_direction
  54. moveq #1,d0
  55. rts
  56. error_scanner_not_attached
  57. moveq #0,d0
  58. rts
  59. ***********************************************
  60. ***** CHECK JOY *****
  61. ***********************************************
  62. check_joy
  63. moveq #0,d0
  64. move.w $bfe101,d1
  65. btst #3,d1
  66. beq.s no_click
  67. moveq #1,d0
  68. bra quit_check_joy
  69. no_click
  70. moveq #0,d0
  71. quit_check_joy
  72. rts
  73. ***********************************************
  74. ***** READ RESIS *****
  75. ***********************************************
  76. read_resis
  77. moveq #0,d0
  78. move.b resistance,d0
  79. move.l backscr2,a0
  80. add.l #150*BYTES_PER_ROW,a0
  81. bsr draw_pixel
  82. rts
  83. ***********************************************
  84. ***** SAVE PIC *****
  85. ***********************************************
  86. save_pic
  87. move.l exec,a6 ; use our label
  88. jsr -138(a6) ; enable system tasking
  89. MOVE.L #graf_name,A1
  90. MOVEQ #0,D0
  91. JSR -552(A6) ; OPEN GRAPHICS LIBRARY
  92. MOVE.L D0,a4
  93. MOVE.L #$DFF000,A6
  94. MOVE.L 38(A4),COP1LCH(A6) ; GET SYSTEM COPPER
  95. CLR.W COPJMP1(A6)
  96. bsr open_file
  97. cmp.l #0,d0
  98. beq.s no_save_the_file
  99. bsr write_file
  100. cmp.l #0,d0
  101. beq.s no_save_the_file
  102. bsr close_file
  103. no_save_the_file
  104. *move.l exec,a6 ; use our label
  105. *jsr -132(a6) ; disable system tasking
  106. rts
  107. ***********************************************
  108. ***** TEST FOR TURN *****
  109. ***********************************************
  110. test_for_turn
  111. cmp.w #0,line_pos
  112. ble.s flip_direc
  113. cmp.w #(PIXEL_WIDTH)-1,line_pos
  114. bge.s flip_direc
  115. bra.s quit_test_turn
  116. flip_direc
  117. cmp.w #1,direction
  118. bne.s test2
  119. bsr set_scan_motor_read_direction
  120. bra.s no_way
  121. test2
  122. bsr set_scan_motor_rewind_direction
  123. no_way
  124. quit_test_turn
  125. rts
  126. ***********************************************
  127. ***** SET UP VARIABLES *****
  128. ***********************************************
  129. set_up_variables
  130. move.l backscr4,a0
  131. move.l a0,screen_position
  132. move.w #0,line_pos
  133. rts
  134. ***********************************************
  135. ***** SET UP PARALLEL PORT *****
  136. ***********************************************
  137. set_up_parallel_port
  138. move.b #$ff,$bfe301
  139. rts
  140. ***********************************************
  141. ***** SET SCAN MOTOR REWIND DIRECTION *****
  142. ***********************************************
  143. set_scan_motor_rewind_direction
  144. move.b motor_bits,d0
  145. bset.l #1,d0
  146. move.b d0,motor_bits
  147. rts
  148. ***********************************************
  149. ***** SET PAPER REWIND *****
  150. ***********************************************
  151. set_paper_rewind
  152. move.b motor_bits,d0
  153. bset.l #3,d0
  154. move.b d0,motor_bits
  155. rts
  156. ***********************************************
  157. ***** SET SCAN MOTOR READ DIRECTION *****
  158. ***********************************************
  159. set_scan_motor_read_direction
  160. move.b motor_bits,d0
  161. bclr.l #1,d0
  162. move.b d0,motor_bits
  163. rts
  164. ***********************************************
  165. ***** SET PAPER FEED *****
  166. ***********************************************
  167. set_paper_feed
  168. move.b motor_bits,d0
  169. bclr.l #3,d0
  170. move.b d0,motor_bits
  171. rts
  172. ***********************************************
  173. ***** STEP SCAN MOTOR *****
  174. ***********************************************
  175. step_scan_motor
  176. moveq #0,d0
  177. move.l backscr2,a0
  178. add.l #100*BYTES_PER_ROW,a0
  179. move.w line_pos,d0
  180. move.b motor_bits,d0
  181. bset.l #0,d0 ;high trigger for mot 1
  182. move.b d0,$bfe101
  183. bsr pause
  184. bclr.l #0,d0 ;low trigger for mot 1
  185. move.b d0,$bfe101
  186. bsr pause
  187. rts
  188. ***********************************************
  189. ***** STEP PAPER FEED MOTOR *****
  190. ***********************************************
  191. step_paper_feed_motor
  192. moveq #0,d0
  193. move.l backscr2,a0
  194. add.l #50*BYTES_PER_ROW,a0
  195. move.w line_pos,d0
  196. move.b motor_bits,d0
  197. bset.l #2,d0 ;high trigger for mot 2
  198. move.b d0,$bfe101
  199. bsr pause
  200. bclr.l #2,d0 ;low trigger for mot 2
  201. move.b d0,$bfe101
  202. bsr pause
  203. rts
  204. ***********************************************
  205. ***** MOVE PAPER *****
  206. ***********************************************
  207. move_paper
  208. move.l button_clicked,a0
  209. cmp.b #0,button_data(a0)
  210. beq.s motor_forward
  211. move.b motor_bits,d0
  212. bclr.l #1,d0
  213. move.b d0,motor_bits
  214. bra.s pusle_motor
  215. motor_forward
  216. move.b motor_bits,d0
  217. bset.l #1,d0
  218. move.b d0,motor_bits
  219. pulse_motor
  220. moveq #0,d0
  221. move.l backscr2,a0
  222. add.l #50*BYTES_PER_ROW,a0
  223. move.w line_pos,d0
  224. move.b motor_bits,d0
  225. bset.l #2,d0 ;high trigger for mot 2
  226. move.b d0,$bfe101
  227. bsr pause
  228. bclr.l #2,d0 ;low trigger for mot 2
  229. move.b d0,$bfe101
  230. bsr pause
  231. rts
  232. ***********************************************
  233. ***** PAUSE *****
  234. ***********************************************
  235. pause
  236. move.l d0,-(sp)
  237. move.w #1000,d0
  238. wait
  239. dbra d0,wait
  240. move.l (sp)+,d0
  241. rts
  242. ************************************************
  243. ***** INC POSITION *****
  244. ************************************************
  245. inc_position
  246. cmp.w #1,direction
  247. beq.s scan_forward
  248. bsr check_joy
  249. cmp.w #1,d0
  250. bne.s no_sensor_hit
  251. move.w #0,line_pos
  252. bra.s reverse_direction
  253. no_sensor_hit
  254. cmp.w #0,line_pos
  255. ble.s quit_inc_position
  256. sub.w #1,line_pos
  257. bra.s quit_inc_position
  258. scan_forward
  259. cmp.w #(PIXEL_WIDTH)-1,line_pos
  260. bge reverse_direction
  261. add.w #1,line_pos
  262. bra quit_inc_position
  263. reverse_direction
  264. neg direction
  265. tst direction
  266. bmi arrrg
  267. bsr move_down_line
  268. arrrg
  269. quit_inc_position
  270. rts
  271. ************************************************
  272. ***** CHECK FOR BIT *****
  273. ************************************************
  274. check_for_bit
  275. move.b $bfe001,d1
  276. btst #$7,d1
  277. bne bumtit
  278. moveq #0,d0
  279. bra large
  280. bumtit
  281. moveq #1,d0
  282. large
  283. bsr draw_pixel
  284. rts
  285. ************************************************
  286. ***** MOVE DOWN LINE *****
  287. ************************************************
  288. move_down_line
  289. add.l #BYTES_PER_ROW,screen_position
  290. move.l backscr4,a0
  291. add.l #BYTES_PER_ROW*PLANE_HEIGHT,a0
  292. cmp.l screen_position,a0
  293. bgt.s not_end_bitmap
  294. move.l backscr4,a0
  295. move.l a0,screen_position
  296. not_end_bitmap
  297. bsr step_paper_feed_motor
  298. rts
  299. ************************************************
  300. ***** DRAW PIXEL *****
  301. ************************************************
  302. draw_pixel
  303. tst direction
  304. bpl draw
  305. rts
  306. draw
  307. *send in bit value to d0
  308. move.l screen_position,a0
  309. moveq #0,d1
  310. move.w line_pos,d1
  311. move.w d1,d2
  312. andi.w #$0007,d2
  313. asr #3,d1
  314. add.l d1,a0
  315. move.w #7,d1
  316. sub.w d2,d1
  317. * sub.w #39,d0
  318. * move.w #15,d4
  319. * sub.w d0,d4
  320. * move.b d4,d0
  321. sub.b #60,d0
  322. asr.w #4,d0
  323. move.w #3,d4
  324. draw_in_colour
  325. btst d4,d0
  326. beq.s clear_the_pixel
  327. bset.b d1,(a0)
  328. bra.s do_rest_planes
  329. clear_the_pixel
  330. bclr.b d1,(a0)
  331. do_rest_planes
  332. sub.l #BYTES_PER_ROW*256,a0
  333. dbra d4,draw_in_colour
  334. rts
  335. ************************************************
  336. ***** POSITION SCREEN *****
  337. ************************************************
  338. position_screen
  339. move.w mousex_inc,d3
  340. add.w d3,scrollx_position
  341. move.w mousey_inc,d3
  342. add.w d3,scrolly_position
  343. cmp.w #0,scrolly_position
  344. bge.s lowy_bound_ok
  345. move.w #0,scrolly_position
  346. lowy_bound_ok
  347. cmp.w #(PLANE_HEIGHT-RES_HEIGHT),scrolly_position
  348. ble.s highy_bound_ok
  349. move.w #(PLANE_HEIGHT-RES_HEIGHT),scrolly_position
  350. highy_bound_ok
  351. cmp.w #0,scrollx_position
  352. bge.s low_bound_ok
  353. move.w #0,scrollx_position
  354. low_bound_ok
  355. cmp.w #(BYTES_PER_ROW-RES_BYTES)*8,scrollx_position
  356. ble.s high_bounds_ok
  357. move.w #(BYTES_PER_ROW-RES_BYTES)*8,scrollx_position
  358. high_bounds_ok
  359. moveq #0,d1
  360. moveq #0,d0
  361. move.w scrollx_position,d0
  362. *asr d0 as in high res increase scroll values 2 at a time
  363. *so an increase of 1 pixel = 2 pixels
  364. asr.w #1,d0
  365. move.w d0,d1
  366. andi.w #$0007,d0 ;pixel shift
  367. andi.w #$fff8,d1
  368. asr.w #2,d1 ;words shifted
  369. moveq #0,d2
  370. move.w scrolly_position,d2
  371. asr.w #1,d2 ;cos high res increase by 2
  372. mulu #BYTES_PER_ROW,d2
  373. add.l d2,d1
  374. move.l backscr1,d2
  375. move.l backscr2,d3
  376. move.l backscr3,d4
  377. move.l backscr4,d5
  378. add.l d1,d2
  379. add.l d1,d3
  380. add.l d1,d4
  381. add.l d1,d5
  382. move.w d0,d1
  383. move.w #15,d0
  384. sub.w d1,d0
  385. move.w d0,d1
  386. rol.w #4,d1
  387. or.w d1,d0
  388. move.w d0,scroll_value
  389. MOVE.W D2,PLANELOW
  390. SWAP D2
  391. MOVE.W D2,PLANEHIGH
  392. MOVE.W D3,PLANE2LOW
  393. SWAP D3
  394. MOVE.W D3,PLANE2HIGH
  395. MOVE.W D4,PLANE3LOW
  396. SWAP D4
  397. MOVE.W D4,PLANE3HIGH
  398. MOVE.W D5,PLANE4LOW
  399. SWAP D5
  400. MOVE.W D5,PLANE4HIGH
  401. rts
  402. open_file
  403. **file name in d1
  404. move.l #file_name,d1
  405. move.l #mode_new,d2
  406. move.l dos_handle,a6
  407. jsr open(a6)
  408. beq.s no_file_opened
  409. move.l d0,file_ptr
  410. no_file_opened
  411. rts
  412. write_file
  413. move.l file_ptr,d1
  414. move.l backscr1,d2
  415. move.l #(BYTES_PER_ROW*256)*4,d3
  416. move.l dos_handle,a6
  417. jsr write(a6)
  418. rts
  419. close_file
  420. move.l dos_handle,a6
  421. move.l file_ptr,d1
  422. jsr close(a6)
  423. rts
  424. write_string
  425. *send data in d2
  426. *send length in d3
  427. movem.l d1-d3/a0,-(sp)
  428. move.l printer_handle,d1
  429. move.l dos_handle,a0
  430. jsr write(a0)
  431. movem.l (sp)+,d1-d3/a0
  432. rts
  433. last_mousex dc.w 0
  434. last_mousey dc.w 0
  435. scrollx_position dc.w 0
  436. scrolly_position dc.w 0
  437. mousex_inc dc.w 0
  438. mousey_inc dc.w 0
  439. line_pos dc.w 0
  440. current_task dc.l 0
  441. dos_handle dc.l 0
  442. printer_handle dc.l 0
  443. printer_count dc.w 0
  444. screen_position dc.l 0
  445. direction dc.w 1
  446. direc dc.w -1
  447. resistance dc.b 0
  448. EVEN
  449. file_ptr dc.l 0
  450. motor_bits
  451. dc.b 0
  452. EVEN
  453. dos_name dc.b "dos.library",0
  454. even
  455. file_name dc.b "df1:piccy.pic",0
  456. EVEN