main.s 22 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. MUSIC_ON_OR_OFF = 0
  2. FUNC_MAIN = 1
  3. TESTING = 1
  4. USE_JOYSTICK = 1
  5. USE_MOUSE = 0
  6. IFD USE_MOUSE
  7. MSPRITE_HEIGHT = 16
  8. ENDC
  9. ; INCLUDE custom.i
  10. ; INCLUDE myheader.i
  11. ; INCLUDE what_key.s
  12. ; INCLUDE funcs.f
  13. ******************************************************************************
  14. xdef _main
  15. _main
  16. move.w INTENAR,old_ena
  17. move.w DMACONR,old_dma
  18. IFND OS_LEGAL
  19. move.w #%0111111111011111,INTENA ; turn off all interuppts
  20. move.w #%1100000000101000,INTENA ; sets vert blank
  21. move.w #$7fff,INTREQ
  22. move.l #$00fc0c8e,100
  23. move.l #$00fc0ce2,104
  24. move.l #$00fc0d14,108
  25. move.l #$00fc0d6c,112
  26. move.l #$00fc0dfa,116
  27. move.l #$00fc0e40,120
  28. move.l #$00fc0e86,124
  29. ENDC
  30. movem.l d0-d7/a0-a6,-(sp)
  31. jsr _setup_libs
  32. jsr _setup_keyboard
  33. jsr _setup_vbi
  34. jsr _setup_screens
  35. jsr _swap_screens
  36. IFD MUSIC_ON_OR_OFF
  37. jsr mt_init
  38. ENDC
  39. jsr _display
  40. IFD MUSIC_ON_OR_OFF
  41. jsr mt_end
  42. ENDC
  43. jsr _reset_system
  44. movem.l (sp)+,d0-d7/a0-a6
  45. rts
  46. xdef _reset_system
  47. _reset_system
  48. movem.l d0-d7/a0-a6,-(sp)
  49. move.w #$7fff,INTENA ;reset the old interupt values
  50. move.w #$7fff,DMACON ;reset dmacon old values
  51. jsr _reset_keyboard
  52. jsr _reset_vbi
  53. jsr _reset_copper
  54. move.w old_ena,d0
  55. or.w #$8000,d0
  56. move.w d0,INTENA
  57. move.w old_dma,d0
  58. or.w #$8000,d0
  59. move.w d0,DMACON
  60. movem.l (sp)+,d0-d7/a0-a6
  61. rts
  62. ******************************************************************************
  63. old_ena dc.w 0
  64. old_dma dc.w 0
  65. ******************************************************************************
  66. xdef _copper_list
  67. _copper_list
  68. dc.l _copper_mem1
  69. dc.l _copper_mem2
  70. ******************************************************************************
  71. xdef _reset_copper
  72. _reset_copper
  73. movem.l a0/d0,-(sp)
  74. move.l _GFXBase,a0
  75. move.l 38(a0),d0
  76. move.l d0,COP1LC
  77. move.w COPJMP1,d0
  78. movem.l (sp)+,a0/d0
  79. rts
  80. *************************************************************
  81. xdef _reset_vbi
  82. _reset_vbi
  83. move.l 20,d0
  84. move.l _old2_int_vec,20
  85. move.l d0,_old2_int_vec
  86. move.l 108,d0
  87. move.l _old1_int_vec,108
  88. move.l d0,_old1_int_vec
  89. rts
  90. *************************************************************
  91. xdef _setup_vbi
  92. _setup_vbi
  93. move.l a0,-(sp)
  94. IFD OS_LEGAL
  95. move.w #%0000000001110000,INTENA
  96. ENDC
  97. move.l 108,_old1_int_vec
  98. lea _vbi_interupt,a0
  99. move.l a0,108
  100. move.l 20,_old2_int_vec
  101. lea _div_by_zero,a0
  102. move.l a0,20
  103. IFD OS_LEGAL
  104. move.w #%1100000000110000,INTENA
  105. ELSEIF
  106. move.w #%1000000000100000,INTENA
  107. move.w #%0000000000100000,INTREQ
  108. ENDC
  109. move.l (sp)+,a0
  110. rts
  111. xdef _do_ints
  112. IFD OS_LEGAL
  113. _do_ints dc.w 1
  114. ELSEIF
  115. _do_ints dc.w 0
  116. ENDC
  117. **************************************************************************
  118. _ijoy1
  119. dc.w 0,-1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0,-1,-1
  120. _ijoy2
  121. dc.w 0, 1, 1, 1,-1, 0, 0, 0,-1, 0, 0, 0,-1, 0
  122. **************************************************************************
  123. _joy_table1
  124. dc.w 0
  125. dc.w 0
  126. dc.w 1
  127. dc.w 1
  128. dc.w 0
  129. dc.w 0 ; not used
  130. dc.w 0 ; not used
  131. dc.w 1
  132. dc.w -1
  133. dc.w 0 ; not used
  134. dc.w 0 ; not used
  135. dc.w 0 ; not used
  136. dc.w -1
  137. dc.w -1
  138. **************************************************************************
  139. _joy_table2
  140. dc.w 0
  141. dc.w 1
  142. dc.w 1
  143. dc.w 0
  144. dc.w -1
  145. dc.w 0 ; not used
  146. dc.w 0 ; not used
  147. dc.w -1
  148. dc.w -1
  149. dc.w 0 ; not used
  150. dc.w 0 ; not used
  151. dc.w 0 ; not used
  152. dc.w 0
  153. dc.w 1
  154. *************************************************************
  155. xdef _vbi_interupt
  156. _vbi_interupt
  157. movem.l d0-d7/a0-a6,-(sp)
  158. move.w INTREQR,d0
  159. and.w INTENAR,d0
  160. and.w #%0100000000100000,d0
  161. beq .not_this_time
  162. IFD USE_JOYSTICK
  163. move.l D0,-(sp)
  164. move.w $dff00c,d0
  165. and.w #$0303,d0
  166. bclr #8,d0
  167. beq.s .zero1
  168. bset #2,d0
  169. .zero1
  170. bclr #9,d0
  171. beq.s .zero2
  172. bset #3,d0
  173. .zero2
  174. add.w d0,d0
  175. move.w _joy_table1(PC,d0.w),_dx_joy
  176. move.w _joy_table2(PC,d0.w),_dy_joy
  177. .fire_test
  178. btst.b #7,$bfe0ff
  179. bne.s .no_fire
  180. add.w #1,_fire
  181. bra.s .fire1_done
  182. .no_fire
  183. move.w #0,_fire
  184. .fire1_done
  185. move.w #$c000,$dff034 ; set potgo to correct status
  186. move.w $dff016,d0
  187. btst.l #14,d0 ; check the button in potgo_read
  188. bne.s .no_fire2
  189. add.w #1,_fire2
  190. bra.s .fire2_done
  191. .no_fire2
  192. move.w #0,_fire2
  193. .fire2_done
  194. move.w #$000,$dff034 ; set potgo to correct status
  195. cmp.w #255,_fire
  196. blt.s .end
  197. move.w #255,_fire
  198. .end
  199. move.l (sp)+,D0
  200. ENDC
  201. IFD USE_MOUSE
  202. jsr _vbi_mouse
  203. ENDC
  204. IFD MUSIC_ON_OR_OFF
  205. jsr mt_music
  206. ENDC
  207. ;corrupts registers
  208. *******************************
  209. move.w #1,_vbi_done
  210. addq.w #1,_vbi_timer
  211. *******************************
  212. .not_this_time
  213. tst.w _do_ints
  214. beq.s .not_dos
  215. movem.l (sp)+,d0-d7/a0-a6
  216. move.l _old1_int_vec,-(sp)
  217. rts
  218. .not_dos
  219. move.w #%0000000000100000,INTREQ
  220. movem.l (sp)+,d0-d7/a0-a6
  221. _div_by_zero
  222. rte
  223. ************************************************************
  224. ************************************************************
  225. Copper equr A0
  226. CColour equr A1
  227. Custom equr D0
  228. Display equr D1
  229. DWork1 equr D2
  230. Sprite equr D3
  231. StartCopper equr D4
  232. xdef _setup_screens
  233. _setup_screens
  234. movem.l d1/a0/a1/a2,-(sp)
  235. IFD USE_MOUSE
  236. jsr _setup_mouse
  237. ENDC
  238. lea _screen_mem,a0
  239. move.l a0,Display
  240. move.l Display,_d_screen
  241. lea _copper_mem1,Copper
  242. lea _pallet,CColour
  243. lea _copper_list,a2
  244. jsr _make_copper
  245. add.l #4,Copper
  246. move.l Copper,(a2)+
  247. lea _copper_mem2,Copper
  248. add.l #SCREEN_WIDTH*SCREEN_HEIGHT*NO_PLANES,Display
  249. move.l Display,_w_screen
  250. jsr _make_copper
  251. add.l #4,Copper
  252. move.l Copper,(a2)
  253. movem.l (sp)+,d1/a0/a1/a2
  254. rts
  255. _pallet
  256. incbin data/pal.dat
  257. ; dc.w $000,$111,$222,$333,$444,$555,$666,$777
  258. ; dc.w $888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff
  259. *************************************************************
  260. xdef _make_copper
  261. _make_copper
  262. movem.l Custom-StartCopper/Copper-CColour,-(sp)
  263. * the first 4 bytes of the copper list is used for dummy sprites
  264. move.l Copper,StartCopper
  265. clr.l (Copper)+
  266. * first set up all the defaults for the screen
  267. move.l #$009c0010,(Copper)+ Set the INTREQ to tell me we are at the TVP
  268. move.l #$01004200,(Copper)+ BPLCON0
  269. ; move.l #$01020044,(Copper)+ BPLCON1
  270. move.l #$01020000,(Copper)+ BPLCON1
  271. move.l #$01040024,(Copper)+ BPLCON2
  272. tst.w _pal
  273. beq.s ntsc
  274. move.l #$008e3681,(Copper)+ DIWSTRT
  275. move.l #$0090fec1,(Copper)+ DIWSTOP
  276. bra.s pal_continue
  277. ntsc
  278. move.l #$008e2c81,(Copper)+ DIWSTRT
  279. move.l #$0090f4c1,(Copper)+ DIWSTOP
  280. pal_continue
  281. move.l #$00920038,(Copper)+ DFFSTRT
  282. move.l #$009400d0,(Copper)+ DFFSTOP
  283. move.l #$01080000,(Copper)+ BPL1MOD
  284. move.l #$010a0000,(Copper)+ BPL2MOD
  285. * set up the colour table
  286. IFD USE_MOUSE
  287. move.w #31,DWork1
  288. ELSEIF
  289. move.w #(1<<NO_PLANES)-1,DWork1
  290. ENDC
  291. move.w #$180,Custom
  292. setup_colour_table
  293. move.w Custom,(Copper)+
  294. move.w (CColour)+,(Copper)+
  295. addq.w #2,Custom
  296. dbra DWork1,setup_colour_table
  297. * D0 contions offset for bitplane pointers
  298. move.w #$E0,Custom
  299. move.w #NO_PLANES-1,DWork1
  300. .make_copper_planes
  301. move.w Custom,(Copper)+
  302. addq.w #2,Custom
  303. swap Display
  304. move.w Display,(Copper)+
  305. move.w Custom,(Copper)+
  306. addq.w #2,Custom
  307. swap Display
  308. move.w Display,(Copper)+
  309. add.l #SCREEN_WIDTH*SCREEN_HEIGHT,Display
  310. dbra DWork1,.make_copper_planes
  311. * D1 contains offset for sprite pointers
  312. move.w #$120,Custom
  313. move.w #7,DWork1
  314. ;if s\pinter data is defined then we must set up a sprite for this screen
  315. IFD USE_MOUSE
  316. move.l #_pointer_data,Sprite ;add sprite 0
  317. swap Sprite
  318. move.w Custom,(Copper)+
  319. move.w Sprite,(Copper)+
  320. add.w #2,Custom
  321. swap Sprite
  322. move.w Custom,(Copper)+
  323. move.w Sprite,(Copper)+
  324. add.w #2,Custom
  325. add.l #18*4,Sprite ;adjust for size of pointer
  326. swap Sprite
  327. move.w Custom,(Copper)+
  328. move.w Sprite,(Copper)+
  329. add.w #2,Custom
  330. swap Sprite
  331. move.w Custom,(Copper)+
  332. move.w Sprite,(Copper)+
  333. add.w #2,Custom
  334. sub.w #2,DWork1
  335. ENDC
  336. .make_copper_sprites
  337. move.w Custom,(Copper)+
  338. addq.w #2,Custom
  339. swap StartCopper
  340. move.w StartCopper,(Copper)+
  341. move.w Custom,(Copper)+
  342. addq.w #2,Custom
  343. swap StartCopper
  344. move.w StartCopper,(Copper)+
  345. dbra DWork1,.make_copper_sprites
  346. * terminate the copper list
  347. move.l #$0901ff00,(Copper)+ WAIT FOR BOTTOM OF DISPLAY
  348. IFD OS_LEGAL
  349. move.l #$009c8030,(Copper)+ Set the INTREQ to tell me we are at the BVP
  350. ELSEIF
  351. move.l #$009c8030,(Copper)+ Set the INTREQ to tell me we are at the BVP
  352. ENDC
  353. move.l #$fffffffe,(Copper)
  354. move.w #$83c0,DMACON
  355. move.l #0,$dff140 ;newbit
  356. addq.l #4,StartCopper
  357. move.l StartCopper,COP1LC
  358. move.l StartCopper,_showing
  359. movem.l (sp)+,Custom-StartCopper/Copper-CColour
  360. rts
  361. *************************************************************
  362. xdef _setup_keyboard
  363. _setup_keyboard
  364. move.w #%0000000000001000,INTENA
  365. move.l $68,old_keyboard_int
  366. lea keyboard_interupt,a0
  367. move.l a0,$68
  368. move.w #%1100000000001000,INTENA
  369. rts
  370. xdef _reset_keyboard
  371. _reset_keyboard
  372. move.w #%0000000000001000,INTENA
  373. move.l $68,d0
  374. move.l old_keyboard_int,$68
  375. move.l d0,old_keyboard_int
  376. move.w #%1100000000001000,INTENA
  377. rts
  378. xdef keyboard_interupt
  379. keyboard_interupt
  380. movem.l d0/a0,-(sp) ;save all registers
  381. move.b $bfec01,d0 ;load in the keyboard value no matter if we are in the system keyboard or not
  382. move.b d0,_iinkey ;store the raw key into iinkey
  383. move.b d0,_iiinkey
  384. tst.w _da_flag ;are we using the system keyboard ?
  385. ; beq.s its_not_the_system
  386. cmp.b #KF_10,d0
  387. bne.s .not_system_escape
  388. btst #0,_scr_system
  389. bne.s .not_system
  390. bset #0,_scr_system
  391. move.l _GFXBase,a0
  392. move.l 38(a0),d0
  393. move.w #1,_da_flag
  394. bra.s .alter_copper
  395. .not_system
  396. bclr #0,_scr_system
  397. move.l _showing,d0
  398. clr.w _da_flag
  399. .alter_copper
  400. move.l d0,COP1LC
  401. move.b _iinkey,d0
  402. .not_system_escape
  403. and.w #$ff,d0 ;now set the keyon value
  404. lea _key_on,a0
  405. btst #0,d0
  406. beq.s .key_up
  407. add.b #1,(a0,d0.w)
  408. .key_up
  409. move.b #0,1(a0,d0.w)
  410. movem.l (sp)+,d0/a0
  411. move.l old_keyboard_int,-(sp) ;call system interupt
  412. rts
  413. its_not_the_system
  414. ; move.b #%01110111,$bfee01
  415. ; clr.b _iinkey ;cleak the old keyboard valu
  416. ; move.b $bfed01,d0 ;is this a keyboard interupt
  417. ; and.b #$8,d0 ;is it a keyboard interupt
  418. ; beq.s .not_keyboard
  419. ; move.b $bfec01,d0 ;load in the keyboard value
  420. ; move.b #$0,$bfec01
  421. ; or.b #$40,$bfee01 ;yes so do somthing strange
  422. cmp.b #KF_10,d0 ;is it an escape
  423. bne.s .not_escape
  424. bset #0,_scr_system ;yes so switch to system
  425. move.l _GFXBase,a0
  426. move.l 38(a0),d0
  427. move.w #1,_da_flag
  428. move.l d0,COP1LC
  429. move.b _iinkey,d0
  430. .not_escape
  431. ; move.b d0,_iinkey ;save iinkey
  432. lea _key_on,a0
  433. and.w #$ff,d0 ;now set the keyon value
  434. btst #0,d0
  435. bne.s .down
  436. move.b d0,(a0,d0.w)
  437. bra.s .done
  438. .down
  439. clr.b 1(a0,d0.w)
  440. .done
  441. ; move.b #$ff,$bfec01
  442. ; andi.b #$bf,$bfee01 ;repole the stange one
  443. .not_keyboard
  444. ; move.b #%10001000,$bfee01
  445. move.w #$8,INTREQ
  446. movem.l (sp)+,d0/a0 ;restore the registers
  447. rte
  448. even
  449. old_keyboard_int dc.l 0
  450. LIB_OPEN EQU -408
  451. xdef _setup_libs
  452. _setup_libs
  453. movem.l a1/a6/d0,-(sp)
  454. ;open the dos base
  455. move.l 4,a6 ; exec base
  456. lea DOS_Name,a1 ; library to open
  457. jsr LIB_OPEN(a6)
  458. move.l d0,_DosBase
  459. ;open the gfxbase
  460. move.l 4,a6 ; exec base
  461. lea GFX_Name,a1 ; library to open
  462. jsr LIB_OPEN(a6)
  463. move.l d0,_GFXBase
  464. move.l d0,a1
  465. move.w $ce(a1),d0 ;GfxBase->DisplayFlags
  466. and.w #4,d0
  467. move.w d0,_pal
  468. IFD OS_LEGAL
  469. ;make sure no requesters come up
  470. move.l 4,a6 ;exec base
  471. sub.l a1,a1 ;set name to null for out task
  472. jsr -294(a6)
  473. move.l d0,a1 ;task structure
  474. move.l #-1,184(a1) ;set window ptr to -1
  475. ENDC
  476. movem.l (sp)+,a1/a6/d0
  477. rts
  478. xdef _DosBase,_GFXBase
  479. _DosBase dc.l 0
  480. _GFXBase dc.l 0
  481. GFX_Name dc.b "graphics.library",0
  482. EVEN
  483. DOS_Name dc.b "dos.library",0
  484. EVEN
  485. **************************************************************
  486. xdef _swap_screens
  487. _swap_screens
  488. movem.l d0/a0,-(sp)
  489. move.l _d_screen,a0
  490. move.l _w_screen,_d_screen
  491. move.l a0,_w_screen
  492. eor.l #4,_toggle
  493. lea _copper_list,a0
  494. add.l _toggle,a0
  495. move.l (a0),_showing
  496. move.l (a0),COP1LC
  497. clr.w _vbi_done
  498. add.l #1,_time
  499. movem.l (sp)+,d0/a0
  500. rts
  501. xdef _showing
  502. xdef _scr_system
  503. xdef _toggle
  504. _toggle dc.l 0
  505. _showing dc.l 0
  506. _scr_system dc.l 0
  507. **************************************************************
  508. xdef _wait_vbi
  509. _wait_vbi
  510. .loop
  511. tst.w _vbi_done
  512. beq.s .loop
  513. rts
  514. **************************************************************
  515. IFD USE_MOUSE
  516. MSprite equr A0
  517. Scratch equr D0
  518. VStart equr D1
  519. HStart equr D2
  520. VStop equr D3
  521. xdef _vbi_mouse
  522. _vbi_mouse:
  523. move.w JOY0DAT,D0
  524. and.w #$00ff,D0
  525. move.w _old_mousex,D1
  526. move.w D0,_old_mousex
  527. sub.w D1,D0
  528. cmp.w #127,D0
  529. ble.s .NO_X_SUB
  530. sub.w #256,D0
  531. .NO_X_SUB
  532. cmp.w #-127,D0
  533. bge.s .NO_X_ADD
  534. add.w #256,D0
  535. .NO_X_ADD
  536. add.w _big_mousex,D0
  537. bpl.s .X_IS_PLUS
  538. move.w #0,D0
  539. .X_IS_PLUS
  540. cmp.w #639,D0
  541. ble.s .X_IN_BOUNDS
  542. move.w #639,D0
  543. .X_IN_BOUNDS
  544. move.w D0,_big_mousex
  545. lsr.w #1,D0
  546. * push the mouse x on to the stack for the sprite interupt
  547. move.w D0,_mmousex removed for now
  548. add.w #64,D0
  549. move.w D0,-(sp)
  550. move.w JOY0DAT,D0
  551. move.w #8,D1
  552. lsr.w D1,D0
  553. move.w _old_mousey,D1
  554. move.w D0,_old_mousey
  555. sub.w D1,D0
  556. cmp.w #127,D0
  557. ble.s .NO_Y_SUB
  558. sub.w #256,D0
  559. .NO_Y_SUB
  560. cmp.w #-127,D0
  561. bge.s .NO_Y_ADD
  562. add.w #256,D0
  563. .NO_Y_ADD
  564. add.w _big_mousey,D0
  565. bpl.s .Y_IS_PLUS
  566. move.w #0,D0
  567. .Y_IS_PLUS
  568. cmp.w _mouse_limit,D0
  569. ble .Y_IN_BOUNDS
  570. move.w _mouse_limit,D0
  571. .Y_IN_BOUNDS
  572. move.w D0,_big_mousey
  573. lsr.w #1,D0
  574. * push the mousey on to the stack for the sprite
  575. move.w D0,_mmousey
  576. move.w D0,-(sp)
  577. ;do the left and right buttons
  578. move.b $bfe0ff,d0
  579. and.w #$40,D0
  580. bne.s .left_is_up
  581. move.w #1,d0
  582. tst.w _mleft_button
  583. bne.s .left_done
  584. tst.w _left_button
  585. bne.s .left_done
  586. move.w d0,_left_button ;set right button to 1 (on)
  587. move.l _mmousex,_mousex
  588. bra.s .left_done
  589. .left_is_up
  590. move.w #0,d0
  591. .left_done
  592. move.w d0,_mleft_button ;reftect actual state
  593. move.w #$0c00,$dff034
  594. move.w $dff016,D0
  595. and.w #$0400,D0
  596. bne.s .right_is_up
  597. move.w #1,d0
  598. tst.w _mright_button
  599. bne.s .right_done
  600. tst.w _right_button
  601. bne.s .right_done
  602. move.w d0,_right_button ;set right button to 1 (on)
  603. move.l _mmousex,_mousex
  604. bra.s .right_done
  605. .right_is_up
  606. move.w #0,d0
  607. .right_done
  608. move.w d0,_mright_button ;reftect actual state
  609. clr.w -(sp) ;move the pointer
  610. bsr.s _move_pointer
  611. add.l #6,sp
  612. rts
  613. xdef _setup_mouse
  614. _setup_mouse:
  615. movem.l d0-d1,-(sp)
  616. move.w JOY0DAT,D0
  617. and.w #$00ff,D0
  618. move.w D0,_old_mousex
  619. move.w JOY0DAT,D0
  620. move.w #8,D1
  621. lsr.w D1,D0
  622. move.w D0,_old_mousey
  623. movem.l (sp)+,d0-d1
  624. rts
  625. xdef _move_pointer
  626. _move_pointer:
  627. movem.l Scratch-VStop/MSprite,-(sp)
  628. move.w 4+4*5(sp),Scratch
  629. move.w 6+4*5(sp),VStart
  630. move.w 8+4*5(sp),HStart
  631. ; get the address of the sprite
  632. lea _pointer_data,MSprite
  633. move.b 3+18*4(MSprite),VStop
  634. and.b #$80,VStop
  635. ; calculate HSTART must add on the left of the screen
  636. add.w #64,HStart
  637. ; add.w #64+8,HStart
  638. lsr.w #1,HStart
  639. bcc.s .hstart_bit_is_0
  640. bset #0,VStop
  641. .hstart_bit_is_0
  642. move.b HStart,1(MSprite)
  643. move.b HStart,1+18*4(MSprite)
  644. ; must add on the top of screen border
  645. ; add.w #44,VStart
  646. ; add.w #46,VStart
  647. add.w #54,VStart
  648. tst.w _pal
  649. bne.s .ntsc
  650. sub.w #10,VStart
  651. .ntsc
  652. btst #8,VStart
  653. beq.s .vstart_bit_is_0
  654. bset #2,VStop
  655. .vstart_bit_is_0
  656. move.b VStart,0(MSprite)
  657. move.b VStart,18*4(MSprite)
  658. * calculate VSTOP by addin in the height and subtracting 1
  659. add.w #MSPRITE_HEIGHT,VStart
  660. btst #8,VStart
  661. beq.s .vstop_bit_is_0
  662. bset #1,VStop
  663. .vstop_bit_is_0
  664. move.b VStart,2(MSprite)
  665. move.b VStart,2+18*4(MSprite)
  666. * move the stop bit in sprite word
  667. move.b VStop,3(MSprite)
  668. move.b VStop,3+18*4(MSprite)
  669. movem.l (sp)+,Scratch-VStop/MSprite
  670. rts
  671. _old_mousex dc.w 0
  672. _old_mousey dc.w 0
  673. _big_mousex dc.w 0
  674. _big_mousey dc.w 0
  675. _mouse_limit dc.w 399
  676. ENDC
  677. IFD USE_SERIAL
  678. ************************ EQUATES ********************************
  679. *
  680. *
  681. ************************ REGISTER EQUATES ************************
  682. * A0 A1 A2 A3 A4 A5 A6 A7
  683. Address equr a0
  684. Serial equr a1
  685. * D0 D1 D2 D3 D4 D5 D6 D7
  686. Math equr d1 !
  687. Length equr d1 !
  688. Mode equr d2
  689. ************************** setserial ****************************
  690. * set baud_rate of serial port
  691. *
  692. *
  693. *****************************************************************
  694. xdef _setup_serial
  695. _setup_serial
  696. move.w #$0801,INTENA
  697. move.l $64,old_level_1
  698. move.l $74,old_level_5
  699. jsr _set_serial
  700. move.l #_w_ser_buff,$64
  701. move.l #_r_ser_buff,$74
  702. move.w #$8801,INTENA
  703. rts
  704. _reset_serial
  705. move.w #$0801,INTENA
  706. move.l old_level_1,d0
  707. move.l $64,old_level_1
  708. move.l d0,$64
  709. move.l old_level_5,d0
  710. move.l $74,old_level_5
  711. move.l d0,$74
  712. move.w #$8801,INTENA
  713. rts
  714. xdef _set_serial
  715. _set_serial
  716. movem.l Serial/Math,-(sp)
  717. lea _serial,Serial
  718. clr.l Scratch
  719. move.w SE_BAUD_RATE(Serial),Scratch
  720. lsl.w #3,Scratch
  721. sub.w SE_BAUD_RATE(Serial),Scratch
  722. move.l #3579098,Math
  723. divu SE_BAUD_RATE(Serial),Math
  724. sub.w #1,Math
  725. move.w Math,SERPER
  726. move.w #$8801,INTENA
  727. move.w #$0801,INTREQ
  728. move.b $bfd000,Math
  729. and.b #%00111111,Math
  730. move.b Math,$bfd000
  731. movem.l (a7)+,Serial/Math
  732. rts
  733. xdef _clear_serial
  734. _clear_serial
  735. movem.l a0,-(sp)
  736. lea _serial,a0
  737. clr.w SE_READ_POS(a0)
  738. clr.w SE_WRITE_POS(a0)
  739. movem.l (sp)+,a0
  740. rts
  741. xdef _r_ser_buff
  742. _r_ser_buff
  743. movem.l d0/a0,-(sp)
  744. move.w $dff01c,d0
  745. and.w $dff01e,d0
  746. btst #11,d0
  747. beq.s .not_mine
  748. lea _serial,a0
  749. move.w SE_WRITE_POS(a0),d0
  750. move.b SERDATR+1,SE_BUFFER(a0,d0.w)
  751. add.w #1,d0
  752. cmp.w #SE_BUFFER_LEN,d0
  753. bne.s .buffer_not_full
  754. move.w #0,d0
  755. .buffer_not_full
  756. move.w d0,SE_WRITE_POS(a0)
  757. move.w #$0800,INTREQ
  758. movem.l (sp)+,d0/a0
  759. rte
  760. .not_mine
  761. IFD OS_LEGAL
  762. movem.l (sp)+,d0/a0
  763. move.l old_level_5,-(sp)
  764. rts
  765. ELSEIF
  766. and.w #$18,d0
  767. move.w d0,INTREQ
  768. movem.l (sp)+,d0/a0
  769. ENDC
  770. rte
  771. xdef _w_ser_buff
  772. _w_ser_buff
  773. movem.l d0/a0,-(sp)
  774. move.w INTREQR,d0
  775. and.w INTENAR,d0
  776. beq.s .no_call
  777. or.b d0,_hello
  778. btst #0,d0
  779. beq.s .not_mine
  780. move.w #$0001,INTENA
  781. lea _serial,a0
  782. move.w #0,SE_WRITE_READY(a0)
  783. move.w #$0001,INTREQ
  784. move.w #$8001,INTENA
  785. and.w #%110,d0
  786. bne.s .not_mine
  787. movem.l (sp)+,d0/a0
  788. rte
  789. .not_mine
  790. IFD OS_LEGAL
  791. movem.l (sp)+,d0/a0
  792. move.l old_level_1,-(sp)
  793. rts
  794. ELSEIF
  795. and.w #$7,d0
  796. move.w d0,INTREQ
  797. movem.l (sp)+,d0/a0
  798. ENDC
  799. .no_call
  800. rte
  801. xdef _ww_ser_buff
  802. _ww_ser_buff
  803. movem.l d0/a0,-(sp)
  804. move.w $dff01c,d0
  805. and.w $dff01e,d0
  806. add.w #1,_hello
  807. btst #0,d0
  808. beq.s .not_mine
  809. lea _serial,a0
  810. move.w #0,SE_WRITE_READY(a0)
  811. move.w #$1,INTREQ
  812. movem.l (sp)+,d0/a0
  813. rte
  814. .not_mine
  815. IFD OS_LEGAL
  816. movem.l (sp)+,d0/a0
  817. move.l old_level_1,-(sp)
  818. rts
  819. ELSEIF
  820. and.w #$7,d0
  821. move.w d0,INTREQ
  822. movem.l (sp)+,d0/a0
  823. ENDC
  824. rte
  825. ************************** read_serial **************************
  826. * read serial port
  827. *
  828. * buffer a0 (long)
  829. * Length d0 (word)
  830. * Mode d1 (word)
  831. *
  832. *****************************************************************
  833. xdef _read_serial
  834. _read_serial
  835. movem.l a0/a1/d1/d2,-(sp)
  836. move.w d0,Length
  837. move.w d1,Mode
  838. lea _serial,Serial
  839. read_next_char
  840. tst.w Mode
  841. bra dont_break_read
  842. beq dont_break_read
  843. tst.w _shift
  844. beq dont_break_read
  845. cmp.w _iinkey,Scratch
  846. bne dont_break_read
  847. bra abort_read
  848. dont_break_read
  849. move.w SE_READ_POS(Serial),Scratch
  850. cmp.w SE_WRITE_POS(Serial),Scratch
  851. beq.s read_next_char
  852. move.b SE_BUFFER(Serial,Scratch.w),(Address)
  853. add.w #1,Scratch
  854. cmp.w #SE_BUFFER_LEN,Scratch
  855. bne.s buffer_not_at_end
  856. move.w #0,Scratch
  857. buffer_not_at_end
  858. move.w Scratch,SE_READ_POS(Serial)
  859. tst.w Length
  860. bne.s read_till_length
  861. tst.b (Address)+
  862. bne read_next_char
  863. move.b #0,(Address)
  864. bra.s end_of_read
  865. read_till_length
  866. add.l #1,Address
  867. sub.w #1,Length
  868. bne read_next_char
  869. end_of_read
  870. move.l #0,Scratch
  871. abort_read
  872. tst.w Scratch
  873. movem.l (sp)+,a0/a1/d1/d2
  874. rts
  875. ************************** write_serial **************************
  876. * write to serial port
  877. *
  878. * buffer a0 (long) Address
  879. * Length d0 (word) Length
  880. * Mode d1 (word) Mode
  881. *
  882. *****************************************************************
  883. xdef _write_serial
  884. _write_serial
  885. movem.l a0/a1/d1/d2,-(sp)
  886. move.w d0,Length
  887. move.w d1,Mode
  888. sub.w #1,Length
  889. lea _serial,Serial
  890. write_buffer_not_empty
  891. tst.w Mode
  892. bra dont_break_write
  893. beq dont_break_write
  894. tst.w _shift
  895. beq dont_break_write
  896. jsr _keyboard
  897. cmp.w Mode,Scratch
  898. bne dont_break_write
  899. bra abort_write
  900. dont_break_write
  901. tst.w SE_WRITE_READY(Serial)
  902. bne.s write_buffer_not_empty
  903. moveq #0,Scratch
  904. move.b (Address)+,Scratch
  905. or.w #$0100,Scratch
  906. move.w #1,SE_WRITE_READY(Serial)
  907. move.w Scratch,SERDAT
  908. dbra Length,write_buffer_not_empty
  909. move.l #0,Scratch
  910. abort_write
  911. movem.l (sp)+,a0/a1/d1/d2
  912. rts
  913. ENDC
  914. IFD OS_LEGAL
  915. **************************************************************************
  916. * all oslegal dos stuff Sun Apr 1 11:42:37 1990
  917. **************************************************************************
  918. xdef _Open
  919. _Open
  920. movem.l a0/d1-d2,-(sp)
  921. moveq #0,d0
  922. move.l 3*4+4(sp),d1
  923. move.l 3*4+8(sp),d2
  924. move.l _DosBase,a0
  925. jsr -30(a0)
  926. movem.l (sp)+,a0/d1-d2
  927. rts
  928. xdef _Close
  929. _Close
  930. movem.l a0/d1,-(sp)
  931. move.l 2*4+4(sp),d1
  932. move.l _DosBase,a0
  933. jsr -36(a0)
  934. movem.l (sp)+,a0/d1
  935. rts
  936. xdef _Read
  937. _Read
  938. movem.l a0/d1-d3,-(sp)
  939. moveq #0,d0
  940. move.l 4*4+4(sp),d1
  941. beq.s .the_end
  942. move.l 4*4+8(sp),d2
  943. beq.s .the_end
  944. move.l 4*4+12(sp),d3
  945. beq.s .the_end
  946. move.l _DosBase,a0
  947. jsr -42(a0)
  948. .the_end
  949. movem.l (sp)+,a0/d1-d3
  950. rts
  951. xdef _Write
  952. _Write
  953. movem.l a0/d1-d3,-(sp)
  954. moveq #0,d0
  955. move.l 4*4+4(sp),d1
  956. beq.s .the_end
  957. move.l 4*4+8(sp),d2
  958. beq.s .the_end
  959. move.l 4*4+12(sp),d3
  960. beq.s .the_end
  961. move.l _DosBase,a0
  962. jsr -48(a0)
  963. .the_end
  964. movem.l (sp)+,a0/d1-d3
  965. rts
  966. xdef _Seek
  967. _Seek
  968. movem.l a0/d1-d3,-(sp)
  969. moveq #0,d0
  970. move.l 4*4+4(sp),d1
  971. beq.s .the_end
  972. move.l 4*4+8(sp),d2
  973. move.l 4*4+12(sp),d3
  974. move.l _DosBase,a0
  975. jsr -66(a0)
  976. .the_end
  977. movem.l (sp)+,a0/d1-d3
  978. rts
  979. ENDC
  980. ***********************************************************
  981. _pointer_data
  982. incbin data/pointer.dat
  983. dc.l 0
  984. ;;;;;