scroll_x_yhopefull2.s 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. section Generic,Code_C
  2. OPT C-,D+
  3. opt p=68020
  4. BPR EQU 64
  5. GRAPHICS_MOD EQU 0
  6. XSIZE EQU 4
  7. YSIZE EQU 36
  8. XDEST EQU 42
  9. YDEST EQU 164
  10. SCROLL_WIDTH EQU 27
  11. NOP EQU 18
  12. NOC EQU 0
  13. CUSTOM EQU $DFF000
  14. BPLCONO EQU $100
  15. BPLCON1 EQU $102
  16. BPLCON2 EQU $104
  17. BPL1MOD EQU $108
  18. DDFSTRT EQU $092
  19. DDFSTOP EQU $094
  20. DIWSTRT EQU $08E
  21. DIWSTOP EQU $090
  22. VPSOR EQU $004
  23. COLOUR0 EQU $180
  24. COLOUR1 EQU $182
  25. COLOUR2 EQU $184
  26. COLOUR3 EQU $186
  27. DMACON EQU $096
  28. COP1LCH EQU $080
  29. COPJMP1 EQU $088
  30. DMAF_BLITTER EQU $0040
  31. DMAF_BLTDONE EQU $4000
  32. DMAF_BLTNZERO EQU $2000
  33. DMAB_BLTDONE EQU 14
  34. bltddat EQU $000
  35. dmaconr EQU $002
  36. vposr EQU $004
  37. vhposr EQU $006
  38. dskdatr EQU $008
  39. joy0dat EQU $00A
  40. joy1dat EQU $00C
  41. clxdat EQU $00E
  42. bltcon0 EQU $040
  43. bltcon1 EQU $042
  44. bltafwm EQU $044
  45. bltalwm EQU $046
  46. bltcpth EQU $048
  47. bltbpth EQU $04C
  48. bltapth EQU $050
  49. bltdpth EQU $054
  50. bltsize EQU $058
  51. bltcmod EQU $060
  52. bltbmod EQU $062
  53. bltamod EQU $064
  54. bltdmod EQU $066
  55. bltcdat EQU $070
  56. bltbdat EQU $072
  57. bltadat EQU $074
  58. dsksync EQU $07E
  59. cop1lc EQU $080
  60. cop2lc EQU $084
  61. bpl2mod EQU $10A
  62. bpldat EQU $110
  63. intreq EQU $09c
  64. intreqr EQU $01e
  65. MODE_OLDFILE EQU 1005
  66. MODE_NEWFILE EQU 1006
  67. SCROLL_HEIGHT EQU 256+64
  68. OVERSCROLL_OFFSET EQU 10
  69. start:
  70. move.l 4,a6
  71. jsr -132(A6) ;DISABLE tasking
  72. move.l 4,a6
  73. move.l #((OVERSCROLL_OFFSET*2)+SCROLL_HEIGHT*BPR)*8,d0 ;
  74. move.l #1<<1+1<<16,d1 ;chip and clear
  75. jsr -198(a6) ;try
  76. tst.l d0
  77. bne allocated_mem
  78. rts ;otherwise quit
  79. allocated_mem
  80. move.l d0,Memory_Base
  81. add.l #OVERSCROLL_OFFSET*BPR,d0
  82. move.l d0,Plane1
  83. add.l #((SCROLL_HEIGHT+(OVERSCROLL_OFFSET*2))*BPR),d0
  84. move.l d0,plane2
  85. add.l #((SCROLL_HEIGHT+(OVERSCROLL_OFFSET*2))*BPR),d0
  86. move.l d0,plane3
  87. add.l #((SCROLL_HEIGHT+(OVERSCROLL_OFFSET*2))*BPR),d0
  88. move.l d0,plane4
  89. add.l #((SCROLL_HEIGHT+(OVERSCROLL_OFFSET*2))*BPR),d0
  90. move.l d0,buff_plane1
  91. add.l #((SCROLL_HEIGHT+(OVERSCROLL_OFFSET*2))*BPR),d0
  92. move.l d0,buff_plane2
  93. add.l #((SCROLL_HEIGHT+(OVERSCROLL_OFFSET*2))*BPR),d0
  94. move.l d0,buff_plane3
  95. add.l #((SCROLL_HEIGHT+(OVERSCROLL_OFFSET*2))*BPR),d0
  96. move.l d0,buff_plane4
  97. bsr setup
  98. move.w #$0,$dff106
  99. move.l #$dff000,a6
  100. bsr fill_screen_with_blocks
  101. bsr set_up_scroll_position
  102. bsr Main_Demo
  103. QUIT_OUT
  104. MOVE.L 4,A6
  105. JSR -138(A6) ;ENABLE tasking
  106. move.l oldint,$6c
  107. move.l 4,a6
  108. move.l #((OVERSCROLL_OFFSET*2)+SCROLL_HEIGHT*BPR)*8,d0
  109. move.l Memory_Base,a1
  110. jsr -210(a6)
  111. MOVE.L #graf_NAME,A1
  112. MOVEQ #0,D0
  113. JSR -552(A6) ;OPEN GRAPHICS LIBRARY
  114. MOVE.L D0,a4
  115. MOVE.W #$8020,DMACON+$dff000 ; sprites back
  116. move.l 38(a4),$dff080
  117. clr.w $dff088
  118. move.b #$9b,$bfed01
  119. rts
  120. graf_NAME dc.b "graphics.library",0
  121. even
  122. setup
  123. bsr setup_colours
  124. LEA CUSTOM,A0
  125. MOVE.W #0,BPLCON1(A0)
  126. move.w #%1000000,BPLCON2(a0)
  127. move.w #$83a0,DMACON(a0)
  128. MOVE.W #$2C81,DIWSTRT(A0)
  129. MOVE.W #$2cC1,DIWSTOP(A0)
  130. MOVE.L #COPPERL,COP1LCH(A0)
  131. MOVE.W COPJMP1(A0),D0
  132. move.l $6c,oldint
  133. move.l #darkint,$6c
  134. rts
  135. setup_colours
  136. move.w #$180,d0
  137. move.l #copper_colours,a0
  138. move.l #col_list,a1
  139. move.w #16-1,d1
  140. col_loop
  141. move.w d0,(a0)+
  142. move.w (a1)+,(a0)+
  143. add.w #$2,d0
  144. dbra d1,col_loop
  145. rts
  146. col_list
  147. dc.w $000,$f00,$0f0,$00f,$ff0,$0ff,$f0f
  148. dc.w $fff,$77f,$707,$f77,$f7f,$7ff,$777
  149. dc.w $707,$070
  150. ************************************************************
  151. **** D A R K L I T E I N T E R R U P T ****
  152. ************************************************************
  153. darkint
  154. movem.l d0-d7/a0-a6,-(sp)
  155. movem.l (sp)+,d0-d7/a0-a6
  156. dc.w $4ef9
  157. oldint dc.l 0
  158. mt_data dc.l 0
  159. music_flag dc.b 0
  160. even
  161. play_colours
  162. dc.b 0
  163. even
  164. two_channel_flag dc.b 0
  165. even
  166. ************************************************************
  167. ***** S C R E E N S Y N C **********
  168. ************************************************************
  169. sync
  170. move.l #$dff000,a6
  171. move.w #$0010,intreq(a6)
  172. wait_for_bit
  173. btst.b #4,intreqr+1(a6)
  174. beq.s wait_for_bit
  175. rts
  176. home
  177. Main_Demo
  178. bsr sync
  179. bsr get_stick_readings
  180. move.w #$fff,$dff180
  181. bsr calculate_scroll_movement
  182. bsr move_scroll
  183. bsr draw_blocks_for_scroll
  184. move.w #$0,$dff180
  185. wait btst.b #6,$bfe001
  186. bne.s main_demo
  187. btst.b #10,$dff016
  188. bne.s main_demo
  189. rts
  190. Single_Mouse_Press
  191. btst #6,$BFE001
  192. Bne out
  193. * move.w #$11,jobba
  194. not_released
  195. btst #6,$BFE001
  196. Beq not_released
  197. out
  198. rts
  199. COPPERL
  200. dc.w bplcono
  201. dc.w $4200
  202. dc.w $102 ; scrolly bit
  203. dc.w $000
  204. dc.w DDFSTRT
  205. dc.w $0030
  206. dc.w DDFSTOP
  207. dc.w $00d8
  208. dc.w bpl1mod
  209. dc.w (BPR-40)-4
  210. dc.w bpl2mod
  211. dc.w (BPR-40)-4
  212. dc.w $1e4
  213. dc.w $2100
  214. dc.w $10c
  215. dc.w $11
  216. dc.w $1fc
  217. dc.w $0
  218. copper_colours
  219. ds.w 16*2
  220. ************sprites
  221. dc.w $120 ;all sprite stuff
  222. sprite0h dc.w $0
  223. dc.w $122
  224. sprite0l dc.w 0
  225. dc.w $124
  226. sprite1h dc.w $0
  227. dc.w $126
  228. sprite1l dc.w 0
  229. dc.w $128
  230. sprite2h dc.w $0
  231. dc.w $12a
  232. sprite2l dc.w 0
  233. dc.w $12c
  234. sprite3h dc.w $0
  235. dc.w $12e
  236. sprite3l dc.w 0
  237. dc.w $130
  238. sprite4h dc.w $0
  239. dc.w $132
  240. sprite4l dc.w 0
  241. dc.w $134
  242. sprite5h dc.w $0
  243. dc.w $136
  244. sprite5l dc.w 0
  245. dc.w $138
  246. sprite6h dc.w $0
  247. dc.w $13a
  248. sprite6l dc.w 0
  249. dc.w $13c
  250. sprite7h dc.w $0
  251. dc.w $13e
  252. sprite7l dc.w 0
  253. dc.w $102
  254. scroll_value
  255. dc.w 0
  256. top_of_screen
  257. DC.W $00E0 ;top bank of plane initialisers
  258. Plane1_Hi DC.W 0
  259. DC.W $00E2
  260. Plane1_Lo DC.W 0
  261. DC.W $00E4
  262. Plane2_Hi DC.W 0
  263. DC.W $00E6
  264. Plane2_Lo DC.W 0
  265. DC.W $00E8
  266. Plane3_Hi DC.W 0
  267. DC.W $00Ea
  268. Plane3_Lo DC.W 0
  269. DC.W $00Ec
  270. Plane4_Hi DC.W 0
  271. DC.W $00Ee
  272. Plane4_Lo DC.W 0
  273. scroll_bank_1
  274. dc.w $2c01,$fffe
  275. DC.W $00E0
  276. DC.W 0
  277. DC.W $00E2
  278. DC.W 0
  279. DC.W $00E4
  280. DC.W 0
  281. DC.W $00E6
  282. DC.W 0
  283. DC.W $00E8
  284. DC.W 0
  285. DC.W $00Ea
  286. DC.W 0
  287. DC.W $00Ec
  288. DC.W 0
  289. DC.W $00Ee
  290. DC.W 0
  291. dc.w $ffdf,$fffe
  292. scroll_bank_2
  293. dc.w $2c01,$fffe
  294. DC.W $00E0
  295. DC.W 0
  296. DC.W $00E2
  297. DC.W 0
  298. DC.W $00E4
  299. DC.W 0
  300. DC.W $00E6
  301. DC.W 0
  302. DC.W $00E8
  303. DC.W 0
  304. DC.W $00Ea
  305. DC.W 0
  306. DC.W $00Ec
  307. DC.W 0
  308. DC.W $00Ee
  309. DC.W 0
  310. dc.w intreq
  311. dc.w $8010
  312. DC.W $2cff,$FFFE
  313. ds.w 1000*2
  314. display_buffers
  315. move.l plane1,d0
  316. move.l plane2,d1
  317. move.l plane3,d2
  318. move.l plane4,d3
  319. move.w d0,plane1_lo
  320. swap d0
  321. move.w d0,plane1_hi
  322. move.w d1,plane2_lo
  323. swap d1
  324. move.w d1,plane2_hi
  325. move.w d2,plane3_lo
  326. swap d2
  327. move.w d2,plane3_hi
  328. move.w d3,plane4_lo
  329. swap d3
  330. move.w d3,plane4_hi
  331. rts
  332. Blank Dc.l 0
  333. Memory_Base dc.l 0
  334. plane1
  335. dc.l 0
  336. plane2
  337. dc.l 0
  338. plane3
  339. dc.l 0
  340. plane4
  341. dc.l 0
  342. buff_plane1
  343. dc.l 0
  344. buff_plane2
  345. dc.l 0
  346. buff_plane3
  347. dc.l 0
  348. buff_plane4
  349. dc.l 0
  350. *----------------------------SCROLL CODE----------------------
  351. rsreset
  352. wait_pos rs.w 1
  353. wait_mask rs.w 1
  354. plane_1_hi_ptr rs.w 1
  355. plane_1_hi_val rs.w 1
  356. plane_1_lo_ptr rs.w 1
  357. plane_1_lo_val rs.w 1
  358. plane_2_hi_ptr rs.w 1
  359. plane_2_hi_val rs.w 1
  360. plane_2_lo_ptr rs.w 1
  361. plane_2_lo_val rs.w 1
  362. plane_3_hi_ptr rs.w 1
  363. plane_3_hi_val rs.w 1
  364. plane_3_lo_ptr rs.w 1
  365. plane_3_lo_val rs.w 1
  366. plane_4_hi_ptr rs.w 1
  367. plane_4_hi_val rs.w 1
  368. plane_4_lo_ptr rs.w 1
  369. plane_4_lo_val rs.w 1
  370. TEST_SPEED EQU 3
  371. WAIT_DRAW_BLOCKS EQU 0
  372. START_DRAW_BLOCKS EQU 1
  373. MAP_LINE_SIZE EQU 100
  374. MAP_HEIGHT_SIZE EQU 100
  375. SCROLL_GOING_DOWN EQU (-48*BPR) ;up from bottom of scroll
  376. SCROLL_GOING_UP EQU (-32*BPR)
  377. MAP_SCREEN_OFFSET_UP EQU (17*MAP_LINE_SIZE)-2
  378. MAP_SCREEN_OFFSET_DOWN EQU (-2*MAP_LINE_SIZE)-2
  379. SCROLL_GOING_LEFT EQU (-32*BPR)+42
  380. SCROLL_GOING_RIGHT EQU (-32*BPR)-4
  381. MAP_SCREEN_OFFSET_RIGHT EQU (-MAP_LINE_SIZE*2)+21
  382. MAP_SCREEN_OFFSET_LEFT EQU (-MAP_LINE_SIZE*2)-2
  383. NUMBER_OF_Y_BLOCKS_PER_FRAME EQU 8
  384. NUMBER_OF_X_BLOCKS_PER_FRAME EQU 7
  385. ******************************************
  386. **** CALCULATE SCROLL MOVEMENT *****
  387. ******************************************
  388. calculate_scroll_movement
  389. *separate stick from scroll thus this routine can send
  390. *any value to scroll allowing velocity scrolls etc
  391. moveq #0,d0
  392. tst.w xdirec
  393. beq.w no_x_movement
  394. bpl.s scroll_moving_to_right
  395. move.w #-TEST_SPEED,d0
  396. bra.s no_x_movement
  397. scroll_moving_to_right
  398. move.w #TEST_SPEED,d0
  399. no_x_movement
  400. moveq #0,d1
  401. tst.w ydirec
  402. beq.w no_y_movement
  403. bmi.s scroll_moving_down
  404. move.w #-TEST_SPEED,d1
  405. bra.s no_y_movement
  406. scroll_moving_down
  407. move.w #TEST_SPEED,d1
  408. no_y_movement
  409. rts
  410. ******************************************
  411. **** MOVE SCROLL *****
  412. ******************************************
  413. move_scroll
  414. *send in x and y increments in d0 and d1
  415. *-Test x bounds
  416. move.w scroll_x_position,d4
  417. add.w d0,scroll_x_position
  418. bge.s scroll_x_not_hit_bounds
  419. clr.w scroll_x_position
  420. move.w d4,d0
  421. bgt.s x_not_zero
  422. clr.w d0
  423. bra.s scroll_x_not_hit_max_bounds
  424. x_not_zero
  425. add.w scroll_x_position,d0
  426. bra.s scroll_x_not_hit_max_bounds
  427. scroll_x_not_hit_bounds
  428. cmp.w #((MAP_LINE_SIZE-20)*16)-1,scroll_x_position
  429. ble.s scroll_x_not_hit_max_bounds
  430. move.w d4,d2
  431. sub.w #((MAP_LINE_SIZE-20)*16)-1,d2
  432. move.w d2,d0
  433. move.w #((MAP_LINE_SIZE-20)*16)-1,scroll_x_position
  434. scroll_x_not_hit_max_bounds
  435. *-<
  436. *-Test y bounds
  437. move.w scroll_y_position,d4
  438. add.w d1,scroll_y_position
  439. bge.s scroll_not_hit_bounds
  440. move.w scroll_y_position,d2
  441. neg.w d2
  442. add.w d2,d1 ;give proper speed
  443. clr.w scroll_y_position
  444. bra.s scroll_y_not_hit_max_bounds
  445. scroll_not_hit_bounds
  446. cmp.w #(MAP_HEIGHT_SIZE-16)*16,scroll_y_position
  447. ble.s scroll_y_not_hit_max_bounds
  448. move.w d4,d1 ;original scroll pos
  449. sub.w #(MAP_HEIGHT_SIZE-16)*16,d1
  450. move.w #(MAP_HEIGHT_SIZE-16)*16,scroll_y_position
  451. scroll_y_not_hit_max_bounds
  452. *-<
  453. movem.w d0/d1,-(sp)
  454. bsr position_scroll
  455. movem.w (sp)+,d0/d1
  456. bsr check_add_blocks
  457. rts
  458. ******************************************
  459. **** CHECK ADD BLOCKS *****
  460. ******************************************
  461. check_add_blocks
  462. *-Do for y blocks
  463. add.w d1,check_y_add
  464. cmp.w #16,check_y_add
  465. blt.s check_min_add
  466. sub.w #16,check_y_add
  467. move.w #START_DRAW_BLOCKS,y_ready_flag
  468. move.l #SCROLL_GOING_DOWN,add_y_block_direction
  469. move.l current_screen_position,current_y_screen_position
  470. move.l current_map_mem_position,current_y_map_mem_position
  471. bra.s drawing_please_wait
  472. check_min_add
  473. cmp.w #-16,check_y_add
  474. bgt.s drawing_please_wait
  475. move.w #START_DRAW_BLOCKS,y_ready_flag
  476. move.l #SCROLL_GOING_UP,add_y_block_direction
  477. move.l current_screen_position,current_y_screen_position
  478. move.l current_map_mem_position,current_y_map_mem_position
  479. add.w #16,check_y_add
  480. drawing_please_wait
  481. *-<
  482. *- Do for x blocks
  483. add.w d0,check_x_add
  484. cmp.w #16,check_x_add
  485. blt.s check_x_min_add
  486. sub.w #16,check_x_add
  487. move.w #START_DRAW_BLOCKS,x_ready_flag
  488. move.l #SCROLL_GOING_LEFT,add_x_block_direction
  489. move.l current_screen_position,current_x_screen_position
  490. move.l current_map_mem_position,current_x_map_mem_position
  491. bra.s drawing_x_please_wait
  492. check_x_min_add
  493. cmp.w #-16,check_x_add
  494. bgt.s drawing_x_please_wait
  495. move.w #START_DRAW_BLOCKS,x_ready_flag
  496. move.l #SCROLL_GOING_RIGHT,add_x_block_direction
  497. move.l current_screen_position,current_x_screen_position
  498. move.l current_map_mem_position,current_x_map_mem_position
  499. add.w #16,check_x_add
  500. drawing_x_please_wait
  501. *-<
  502. rts
  503. add_y_block_direction dc.l 0
  504. check_y_add dc.w 0
  505. y_ready_flag dc.w 0
  506. add_x_block_direction dc.l 0
  507. check_x_add dc.w 0
  508. x_ready_flag dc.w 0
  509. ******************************************
  510. **** POSITION SCROLL *****
  511. ******************************************
  512. position_scroll
  513. *Positions scroll by the x and y values stored
  514. move.w scroll_x_position,d0
  515. move.w scroll_y_position,d1
  516. position_scroll_along_x
  517. moveq #0,d3
  518. move.w d0,d2
  519. move.w d0,d3
  520. andi.w #$000f,d2 ;shift value
  521. asr.w #4,d3 ;number of blocks in
  522. andi.w #$fff0,d0
  523. asr.w #3,d0
  524. ext.l d0 ;bytes in
  525. neg.w d2
  526. add.w #15,d2
  527. move.w d2,d4
  528. asl.w #4,d2
  529. or.w d2,d4
  530. move.w d4,scroll_value
  531. position_scroll_along_y
  532. *---
  533. moveq #0,d2
  534. move.w d1,d2
  535. asr.w #4,d2
  536. mulu #MAP_LINE_SIZE,d2
  537. move.l #map_data,a0
  538. add.l d2,a0 ;add y
  539. add.l d3,a0 ;add x
  540. move.l a0,current_map_mem_position
  541. *---
  542. ext.l d1
  543. divu #SCROLL_HEIGHT,d1
  544. swap d1 ;this is all we want - split position down screen
  545. neg.w d1 ;so scroll goes right way
  546. add.w #SCROLL_HEIGHT,d1
  547. *---calc where to draw
  548. moveq #0,d3
  549. move.w #SCROLL_HEIGHT,d3 ;position above buffer area
  550. sub.w d1,d3 ;position of buffer area
  551. andi.w #$fff0,d3
  552. mulu #BPR,d3
  553. * asl.w #6,d3
  554. add.l plane1,d3
  555. add.l d0,d3 ;add x in
  556. move.l d3,current_screen_position
  557. *------
  558. move.w d1,d2
  559. add.w #$2c,d1
  560. moveq #0,d4
  561. cmp.w #$ff,d1
  562. ble.s not_over_dodgy_line
  563. moveq #1,d4
  564. not_over_dodgy_line
  565. cmp.w #$ff+$2c,d1
  566. ble.s not_off_copper
  567. move.w #-1,d4
  568. bra.s calc_screen_split
  569. not_off_copper
  570. andi.w #$ff,d1 ;so values wraps round
  571. asl.w #8,d1
  572. addq.w #1,d1 ; = wait value
  573. calc_screen_split
  574. neg.w d2
  575. add.w #SCROLL_HEIGHT,d2
  576. mulu #BPR,d2
  577. * asl.w #6,d2 ;mulu by 64 - get line down
  578. ext.l d2
  579. add.l plane1,d2 ;to display at top
  580. move.l plane1,d3 ;top display at split
  581. add.l d0,d2 ;add x in
  582. add.l d0,d3 ;add x in
  583. bsr insert_plane_pointers
  584. rts
  585. ******************************************
  586. **** INSERT PLANE POINTERS *****
  587. ******************************************
  588. insert_plane_pointers
  589. *d1 contains wait value
  590. *d2 = top of display
  591. *d3 = split part of display
  592. *d4 indicates if inserting after 255 gap
  593. tst d4
  594. bmi clear_all_banks
  595. beq.s insert_before_line
  596. insert_after_line
  597. move.l #scroll_bank_2,a0
  598. move.l #scroll_bank_1,a1
  599. bsr fill_banks
  600. rts
  601. insert_before_line
  602. move.l #scroll_bank_1,a0
  603. move.l #scroll_bank_2,a1
  604. bsr fill_banks
  605. rts
  606. clear_all_banks
  607. move.l #scroll_bank_1,a0
  608. move.l #scroll_bank_2,a1
  609. bsr clear_banks
  610. rts
  611. ******************************************
  612. **** FILL BANKS *****
  613. ******************************************
  614. fill_banks
  615. *a0 = bank to fill
  616. *a1 = bank to clear
  617. *d1 = wait
  618. *d2 = top of display
  619. *d3 = split display
  620. *change to copper jump later - but get it working first!!!
  621. * IN USE SPLIT POINTERS
  622. move.w d1,wait_pos(a0)
  623. move.w #$fffe,wait_mask(a0)
  624. move.w #$e2,plane_1_lo_ptr(a0)
  625. move.w d3,plane_1_lo_val(a0)
  626. swap d3
  627. move.w #$e0,plane_1_hi_ptr(a0)
  628. move.w d3,plane_1_hi_val(a0)
  629. swap d3
  630. add.l #SCROLL_HEIGHT*BPR,d3
  631. move.w #$e6,plane_2_lo_ptr(a0)
  632. move.w d3,plane_2_lo_val(a0)
  633. swap d3
  634. move.w #$e4,plane_2_hi_ptr(a0)
  635. move.w d3,plane_2_hi_val(a0)
  636. swap d3
  637. add.l #SCROLL_HEIGHT*BPR,d3
  638. move.w #$ea,plane_3_lo_ptr(a0)
  639. move.w d3,plane_3_lo_val(a0)
  640. swap d3
  641. move.w #$e8,plane_3_hi_ptr(a0)
  642. move.w d3,plane_3_hi_val(a0)
  643. swap d3
  644. add.l #SCROLL_HEIGHT*BPR,d3
  645. move.w #$ee,plane_4_lo_ptr(a0)
  646. move.w d3,plane_4_lo_val(a0)
  647. swap d3
  648. move.w #$ec,plane_4_hi_ptr(a0)
  649. move.w d3,plane_4_hi_val(a0)
  650. * UNUSED SET OF SPLIT POINTERS
  651. move.w #$1f0,wait_pos(a1)
  652. move.w #$1f0,plane_1_hi_ptr(a1)
  653. move.w #$1f0,plane_1_lo_ptr(a1)
  654. move.w #$1f0,plane_2_hi_ptr(a1)
  655. move.w #$1f0,plane_2_lo_ptr(a1)
  656. move.w #$1f0,plane_3_hi_ptr(a1)
  657. move.w #$1f0,plane_3_lo_ptr(a1)
  658. move.w #$1f0,plane_4_hi_ptr(a1)
  659. move.w #$1f0,plane_4_lo_ptr(a1)
  660. * TOP OF SCREEN
  661. move.l #top_of_screen-4,a0 ;so rs.w's work
  662. move.w d2,plane_1_lo_val(a0)
  663. swap d2
  664. move.w d2,plane_1_hi_val(a0)
  665. swap d2
  666. add.l #SCROLL_HEIGHT*BPR,d2
  667. move.w d2,plane_2_lo_val(a0)
  668. swap d2
  669. move.w d2,plane_2_hi_val(a0)
  670. swap d2
  671. add.l #SCROLL_HEIGHT*BPR,d2
  672. move.w d2,plane_3_lo_val(a0)
  673. swap d2
  674. move.w d2,plane_3_hi_val(a0)
  675. swap d2
  676. add.l #SCROLL_HEIGHT*BPR,d2
  677. move.w d2,plane_4_lo_val(a0)
  678. swap d2
  679. move.w d2,plane_4_hi_val(a0)
  680. rts
  681. ******************************************
  682. **** CLEAR BANKS *****
  683. ******************************************
  684. clear_banks
  685. * UNUSED SET OF SPLIT POINTERS 1
  686. move.w #$1f0,wait_pos(a1)
  687. move.w #$1f0,plane_1_hi_ptr(a1)
  688. move.w #$1f0,plane_1_lo_ptr(a1)
  689. move.w #$1f0,plane_2_hi_ptr(a1)
  690. move.w #$1f0,plane_2_lo_ptr(a1)
  691. move.w #$1f0,plane_3_hi_ptr(a1)
  692. move.w #$1f0,plane_3_lo_ptr(a1)
  693. move.w #$1f0,plane_4_hi_ptr(a1)
  694. move.w #$1f0,plane_4_lo_ptr(a1)
  695. * UNUSED SET OF SPLIT POINTERS 2
  696. move.w #$1f0,wait_pos(a0)
  697. move.w #$1f0,plane_1_hi_ptr(a0)
  698. move.w #$1f0,plane_1_lo_ptr(a0)
  699. move.w #$1f0,plane_2_hi_ptr(a0)
  700. move.w #$1f0,plane_2_lo_ptr(a0)
  701. move.w #$1f0,plane_3_hi_ptr(a0)
  702. move.w #$1f0,plane_3_lo_ptr(a0)
  703. move.w #$1f0,plane_4_hi_ptr(a0)
  704. move.w #$1f0,plane_4_lo_ptr(a0)
  705. * TOP OF SCREEN
  706. move.l #top_of_screen-4,a0 ;so rs.w's work
  707. move.w d2,plane_1_lo_val(a0)
  708. swap d2
  709. move.w d2,plane_1_hi_val(a0)
  710. swap d2
  711. add.l #SCROLL_HEIGHT*BPR,d2
  712. move.w d2,plane_2_lo_val(a0)
  713. swap d2
  714. move.w d2,plane_2_hi_val(a0)
  715. swap d2
  716. add.l #SCROLL_HEIGHT*BPR,d2
  717. move.w d2,plane_3_lo_val(a0)
  718. swap d2
  719. move.w d2,plane_3_hi_val(a0)
  720. swap d2
  721. add.l #SCROLL_HEIGHT*BPR,d2
  722. move.w d2,plane_4_lo_val(a0)
  723. swap d2
  724. move.w d2,plane_4_hi_val(a0)
  725. rts
  726. scroll_x_position dc.w 0
  727. scroll_y_position dc.w 0
  728. **********************************************************
  729. *********** DRAW BLOCKS FOR SCROLL ***********
  730. **********************************************************
  731. draw_blocks_for_scroll
  732. tst.w y_ready_flag
  733. beq.s see_if_x_to_draw
  734. move.l current_y_screen_position,a0
  735. move.l current_y_map_mem_position,a1
  736. bsr draw_y_blocks
  737. see_if_x_to_draw
  738. tst.w x_ready_flag
  739. beq.s quit_draw_blocks_for_scroll
  740. move.l current_x_screen_position,a0
  741. move.l current_x_map_mem_position,a1
  742. bsr draw_x_blocks
  743. quit_draw_blocks_for_scroll
  744. rts
  745. current_screen_position dc.l 0
  746. current_y_screen_position dc.l 0
  747. current_x_screen_position dc.l 0
  748. current_map_mem_position dc.l 0
  749. current_x_map_mem_position dc.l 0
  750. current_y_map_mem_position dc.l 0
  751. **********************************************************
  752. *********** DRAW Y BLOCKS ***********
  753. **********************************************************
  754. draw_y_blocks
  755. *current screen mem position in a0
  756. *current map position in a1
  757. add.l add_y_block_direction,a0
  758. cmp.l plane1,a0
  759. bge.s draw_inside_plane_area
  760. add.l #SCROLL_HEIGHT*BPR,a0
  761. draw_inside_plane_area
  762. *---- So starts one block back so filling in x strips - see design
  763. subq.l #4,a0
  764. *-<
  765. cmp.l #SCROLL_GOING_UP,add_y_block_direction
  766. bne.s scroll_down
  767. add.l #MAP_SCREEN_OFFSET_DOWN,a1
  768. bra.s draw_blocks_up
  769. scroll_down
  770. add.l #MAP_SCREEN_OFFSET_UP,a1
  771. draw_blocks_up
  772. *-----------draw blocks loop-------------
  773. draw_blocks_main
  774. moveq #0,d0
  775. move.w current_y_map_position,d0
  776. ext.l d0
  777. add.l d0,a1 ;current map position
  778. asl d0 ;get into bytes
  779. add.l d0,a0 ;get to current line
  780. move.w total_number_of_y_blocks_to_draw,d2
  781. moveq #0,d7 ;count number of blocks drawn
  782. init_blit_values
  783. btst #14,dmaconr(a6)
  784. bne.s init_blit_values
  785. move.w #BPR-2,bltdmod(a6)
  786. move.w #0,bltamod(a6)
  787. move.l #$ffffffff,bltafwm(a6)
  788. move.l #$09F00000,bltcon0(A6)
  789. moveq #NUMBER_OF_Y_BLOCKS_PER_FRAME-1,d0
  790. draw_loop
  791. move.l #blocks,a2
  792. moveq #0,d1
  793. move.b (a1),d1
  794. asl.w #7,d1 ;same as mulu (16*2)*4
  795. add.l d1,a2 ;get to correct position in block data
  796. draw_block_on_screen
  797. btst #14,dmaconr(a6)
  798. bne.s draw_block_on_screen
  799. move.l a0,bltdpth(a6) ;screen
  800. move.l a2,bltapth(a6) ;graphics
  801. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  802. move.l a0,a3
  803. add.l #BPR*SCROLL_HEIGHT,a3
  804. add.l #16*2,a2
  805. draw_block_on_screenp2
  806. btst #14,dmaconr(a6)
  807. bne.s draw_block_on_screenp2
  808. move.l a3,bltdpth(a6) ;screen
  809. move.l a2,bltapth(a6) ;graphics
  810. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  811. add.l #BPR*SCROLL_HEIGHT,a3
  812. add.l #16*2,a2
  813. draw_block_on_screenp3
  814. btst #14,dmaconr(a6)
  815. bne.s draw_block_on_screenp3
  816. move.l a3,bltdpth(a6) ;screen
  817. move.l a2,bltapth(a6) ;graphics
  818. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  819. add.l #BPR*SCROLL_HEIGHT,a3
  820. add.l #16*2,a2
  821. draw_block_on_screenp4
  822. btst #14,dmaconr(a6)
  823. bne.s draw_block_on_screenp4
  824. move.l a3,bltdpth(a6) ;screen
  825. move.l a2,bltapth(a6) ;graphics
  826. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  827. done_a_block
  828. addq.l #2,a0 ;next block position along screen
  829. addq.l #1,a1 ;next map position
  830. addq.w #1,current_y_map_position
  831. addq.w #1,d7 ;count number blocks drawn
  832. cmp.w current_y_map_position,d2
  833. bne.s not_yet_done_line
  834. move.w #0,current_y_map_position
  835. move.w #WAIT_DRAW_BLOCKS,y_ready_flag ;done our line now wait for screen to scroll 16
  836. bra.s done_all_blocks
  837. not_yet_done_line
  838. dbra d0,draw_loop
  839. done_all_blocks
  840. rts
  841. **********************************************************
  842. *********** DRAW X BLOCKS ***********
  843. **********************************************************
  844. draw_x_blocks
  845. *current screen mem position in a0
  846. *current map position in a1
  847. **make it draw always on right
  848. add.l add_x_block_direction,a0
  849. cmp.l #SCROLL_GOING_LEFT,add_x_block_direction
  850. bne.s scroll_going_towards_right
  851. add.l #MAP_SCREEN_OFFSET_RIGHT,a1
  852. bra.s draw_x_blocks_straight
  853. scroll_going_towards_right
  854. add.l #MAP_SCREEN_OFFSET_LEFT,a1
  855. draw_x_blocks_straight
  856. moveq #0,d0
  857. move.w current_x_map_position,d0
  858. move.w d0,d1
  859. mulu #MAP_LINE_SIZE,d0
  860. add.l d0,a1 ;get to current line
  861. mulu #BPR*16,d1
  862. add.l d1,a0 ;current screen block position
  863. move.l plane1,a3
  864. cmp.l a3,a0
  865. bge.s within_plane_still
  866. add.l #SCROLL_HEIGHT*BPR,a0
  867. within_plane_still
  868. add.l #BPR*SCROLL_HEIGHT,a3
  869. cmp.l a3,a0
  870. blt.s test2
  871. sub.l #SCROLL_HEIGHT*BPR,a0
  872. test2
  873. move.w total_number_of_x_blocks_to_draw,d2
  874. moveq #0,d7 ;count number of blocks drawn
  875. init_x_blit_values
  876. btst #14,dmaconr(a6)
  877. bne.s init_x_blit_values
  878. move.w #BPR-2,bltdmod(a6)
  879. move.w #0,bltamod(a6)
  880. move.l #$ffffffff,bltafwm(a6)
  881. move.l #$09F00000,bltcon0(A6)
  882. moveq #NUMBER_OF_X_BLOCKS_PER_FRAME-1,d0
  883. draw_x_loop
  884. move.l #blocks,a2
  885. moveq #0,d1
  886. move.b (a1),d1
  887. asl.w #7,d1 ;same as mulu (16*2)*4
  888. add.l d1,a2 ;get to correct position in block data
  889. draw_x_block_on_screen
  890. btst #14,dmaconr(a6)
  891. bne.s draw_x_block_on_screen
  892. move.l a0,bltdpth(a6) ;screen
  893. move.l a2,bltapth(a6) ;graphics
  894. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  895. move.l a0,a3
  896. add.l #BPR*SCROLL_HEIGHT,a3
  897. add.l #16*2,a2
  898. draw_x_block_on_screenp2
  899. btst #14,dmaconr(a6)
  900. bne.s draw_x_block_on_screenp2
  901. move.l a3,bltdpth(a6) ;screen
  902. move.l a2,bltapth(a6) ;graphics
  903. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  904. add.l #BPR*SCROLL_HEIGHT,a3
  905. add.l #16*2,a2
  906. draw_x_block_on_screenp3
  907. btst #14,dmaconr(a6)
  908. bne.s draw_x_block_on_screenp3
  909. move.l a3,bltdpth(a6) ;screen
  910. move.l a2,bltapth(a6) ;graphics
  911. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  912. add.l #BPR*SCROLL_HEIGHT,a3
  913. add.l #16*2,a2
  914. draw_x_block_on_screenp4
  915. btst #14,dmaconr(a6)
  916. bne.s draw_x_block_on_screenp4
  917. move.l a3,bltdpth(a6) ;screen
  918. move.l a2,bltapth(a6) ;graphics
  919. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  920. done_x_block
  921. add.w #16,d5 ;current y pixel position
  922. add.l #BPR*16,a0
  923. move.l plane1,a3
  924. cmp.l a3,a0
  925. bge.s no_need_to_wrap
  926. add.l #SCROLL_HEIGHT*BPR,a0
  927. no_need_to_wrap
  928. add.l #SCROLL_HEIGHT*BPR,a3
  929. cmp.l a3,a0
  930. blt.s test7777
  931. sub.l #SCROLL_HEIGHT*BPR,a0
  932. test7777
  933. add.l #MAP_LINE_SIZE,a1
  934. addq.w #1,current_x_map_position
  935. addq.w #1,d7 ;count number blocks drawn
  936. cmp.w current_x_map_position,d2
  937. bne.s not_yet_done_x_line
  938. move.w #0,current_x_map_position
  939. move.w #WAIT_DRAW_BLOCKS,x_ready_flag ;done our line now wait for screen to scroll 16
  940. bra.s done_all_x_blocks
  941. not_yet_done_x_line
  942. dbra d0,draw_x_loop
  943. done_all_x_blocks
  944. rts
  945. total_number_of_y_blocks_to_draw dc.w 24
  946. current_y_map_position dc.w 0
  947. total_number_of_x_blocks_to_draw dc.w 20
  948. current_x_map_position dc.w 0
  949. ********************************************************
  950. **** FILL SCREEN WITH BLOCKS ****
  951. ********************************************************
  952. fill_screen_with_blocks
  953. move.l plane1,a0
  954. move.l #map_data,a1
  955. move.w #18-1,d0
  956. do_all_blocks
  957. move.w #START_DRAW_BLOCKS,y_ready_flag
  958. keep_drawing
  959. movem.l a0-a1/d0,-(sp)
  960. bsr draw_blocks_main
  961. movem.l (sp)+,a0-a1/d0
  962. tst y_ready_flag
  963. bne.s keep_drawing
  964. add.l #16*BPR,a0
  965. add.l #MAP_LINE_SIZE,a1
  966. dbra d0,do_all_blocks
  967. move.w #WAIT_DRAW_BLOCKS,y_ready_flag
  968. move.w #START_DRAW_BLOCKS,x_ready_flag
  969. wait_until_done
  970. move.l plane1,a0
  971. add.l #40,a0
  972. move.l #map_data+21,a1
  973. bsr draw_x_blocks_straight
  974. cmp.w #WAIT_DRAW_BLOCKS,x_ready_flag
  975. bne.s wait_until_done
  976. move.w #START_DRAW_BLOCKS,x_ready_flag
  977. wait_until_done2
  978. move.l plane1,a0
  979. add.l #42,a0
  980. move.l #map_data+21,a1
  981. bsr draw_x_blocks_straight
  982. cmp.w #WAIT_DRAW_BLOCKS,x_ready_flag
  983. bne.s wait_until_done2
  984. move.w #WAIT_DRAW_BLOCKS,x_ready_flag
  985. rts
  986. ********************************************************
  987. **** SET UP SCROLL POSITION ****
  988. ********************************************************
  989. set_up_scroll_position
  990. clr.w scroll_y_position
  991. clr.w scroll_x_position
  992. clr.w current_x_map_position
  993. clr.w current_y_map_position
  994. clr.w check_x_add
  995. clr.w check_y_add
  996. rts
  997. include "code:platform/glens_code/joy_routines.s"
  998. blocks
  999. incbin "scratch:empty/testblks"
  1000. EVEN
  1001. map_data
  1002. incbin "scratch:empty/testmapraw"
  1003. EVEN