scroll_x_yhopefull.s 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  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 4
  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. bsr check_add_blocks
  454. bsr position_scroll
  455. rts
  456. ******************************************
  457. **** CHECK ADD BLOCKS *****
  458. ******************************************
  459. check_add_blocks
  460. *-Do for y blocks
  461. add.w d1,check_y_add
  462. cmp.w #16,check_y_add
  463. blt.s check_min_add
  464. sub.w #16,check_y_add
  465. move.w #START_DRAW_BLOCKS,y_ready_flag
  466. move.l #SCROLL_GOING_DOWN,add_y_block_direction
  467. move.l current_screen_position,current_y_screen_position
  468. move.l current_map_mem_position,current_y_map_mem_position
  469. bra.s drawing_please_wait
  470. check_min_add
  471. cmp.w #-16,check_y_add
  472. bgt.s drawing_please_wait
  473. move.w #START_DRAW_BLOCKS,y_ready_flag
  474. move.l #SCROLL_GOING_UP,add_y_block_direction
  475. move.l current_screen_position,current_y_screen_position
  476. move.l current_map_mem_position,current_y_map_mem_position
  477. add.w #16,check_y_add
  478. drawing_please_wait
  479. *-<
  480. *- Do for x blocks
  481. add.w d0,check_x_add
  482. cmp.w #16,check_x_add
  483. blt.s check_x_min_add
  484. sub.w #16,check_x_add
  485. move.w #START_DRAW_BLOCKS,x_ready_flag
  486. move.l #SCROLL_GOING_LEFT,add_x_block_direction
  487. move.l current_screen_position,current_x_screen_position
  488. move.l current_map_mem_position,current_x_map_mem_position
  489. bra.s drawing_x_please_wait
  490. check_x_min_add
  491. cmp.w #-16,check_x_add
  492. bgt.s drawing_x_please_wait
  493. move.w #START_DRAW_BLOCKS,x_ready_flag
  494. move.l #SCROLL_GOING_RIGHT,add_x_block_direction
  495. move.l current_screen_position,current_x_screen_position
  496. move.l current_map_mem_position,current_x_map_mem_position
  497. add.w #16,check_x_add
  498. drawing_x_please_wait
  499. *-<
  500. rts
  501. add_y_block_direction dc.l 0
  502. check_y_add dc.w 0
  503. y_ready_flag dc.w 0
  504. add_x_block_direction dc.l 0
  505. check_x_add dc.w 0
  506. x_ready_flag dc.w 0
  507. ******************************************
  508. **** POSITION SCROLL *****
  509. ******************************************
  510. position_scroll
  511. *Positions scroll by the x and y values stored
  512. move.w scroll_x_position,d0
  513. move.w scroll_y_position,d1
  514. position_scroll_along_x
  515. moveq #0,d3
  516. move.w d0,d2
  517. move.w d0,d3
  518. andi.w #$000f,d2 ;shift value
  519. asr.w #4,d3 ;number of blocks in
  520. andi.w #$fff0,d0
  521. asr.w #3,d0
  522. ext.l d0 ;bytes in
  523. neg.w d2
  524. add.w #15,d2
  525. move.w d2,d4
  526. asl.w #4,d2
  527. or.w d2,d4
  528. move.w d4,scroll_value
  529. position_scroll_along_y
  530. *---
  531. moveq #0,d2
  532. move.w d1,d2
  533. asr.w #4,d2
  534. mulu #MAP_LINE_SIZE,d2
  535. move.l #map_data,a0
  536. add.l d2,a0 ;add y
  537. add.l d3,a0 ;add x
  538. move.l a0,current_map_mem_position
  539. *---
  540. ext.l d1
  541. divu #SCROLL_HEIGHT,d1
  542. swap d1 ;this is all we want - split position down screen
  543. neg.w d1 ;so scroll goes right way
  544. add.w #SCROLL_HEIGHT,d1
  545. *---calc where to draw
  546. moveq #0,d3
  547. move.w #SCROLL_HEIGHT,d3 ;position above buffer area
  548. sub.w d1,d3 ;position of buffer area
  549. andi.w #$fff0,d3
  550. mulu #BPR,d3
  551. * asl.w #6,d3
  552. add.l plane1,d3
  553. add.l d0,d3 ;add x in
  554. move.l d3,current_screen_position
  555. *------
  556. move.w d1,d2
  557. add.w #$2c,d1
  558. moveq #0,d4
  559. cmp.w #$ff,d1
  560. ble.s not_over_dodgy_line
  561. moveq #1,d4
  562. not_over_dodgy_line
  563. cmp.w #$ff+$2c,d1
  564. ble.s not_off_copper
  565. move.w #-1,d4
  566. bra.s calc_screen_split
  567. not_off_copper
  568. andi.w #$ff,d1 ;so values wraps round
  569. asl.w #8,d1
  570. addq.w #1,d1 ; = wait value
  571. calc_screen_split
  572. neg.w d2
  573. add.w #SCROLL_HEIGHT,d2
  574. mulu #BPR,d2
  575. * asl.w #6,d2 ;mulu by 64 - get line down
  576. ext.l d2
  577. add.l plane1,d2 ;to display at top
  578. move.l plane1,d3 ;top display at split
  579. add.l d0,d2 ;add x in
  580. add.l d0,d3 ;add x in
  581. bsr insert_plane_pointers
  582. rts
  583. ******************************************
  584. **** INSERT PLANE POINTERS *****
  585. ******************************************
  586. insert_plane_pointers
  587. *d1 contains wait value
  588. *d2 = top of display
  589. *d3 = split part of display
  590. *d4 indicates if inserting after 255 gap
  591. tst d4
  592. bmi clear_all_banks
  593. beq.s insert_before_line
  594. insert_after_line
  595. move.l #scroll_bank_2,a0
  596. move.l #scroll_bank_1,a1
  597. bsr fill_banks
  598. rts
  599. insert_before_line
  600. move.l #scroll_bank_1,a0
  601. move.l #scroll_bank_2,a1
  602. bsr fill_banks
  603. rts
  604. clear_all_banks
  605. move.l #scroll_bank_1,a0
  606. move.l #scroll_bank_2,a1
  607. bsr clear_banks
  608. rts
  609. ******************************************
  610. **** FILL BANKS *****
  611. ******************************************
  612. fill_banks
  613. *a0 = bank to fill
  614. *a1 = bank to clear
  615. *d1 = wait
  616. *d2 = top of display
  617. *d3 = split display
  618. *change to copper jump later - but get it working first!!!
  619. * IN USE SPLIT POINTERS
  620. move.w d1,wait_pos(a0)
  621. move.w #$fffe,wait_mask(a0)
  622. move.w #$e2,plane_1_lo_ptr(a0)
  623. move.w d3,plane_1_lo_val(a0)
  624. swap d3
  625. move.w #$e0,plane_1_hi_ptr(a0)
  626. move.w d3,plane_1_hi_val(a0)
  627. swap d3
  628. add.l #SCROLL_HEIGHT*BPR,d3
  629. move.w #$e6,plane_2_lo_ptr(a0)
  630. move.w d3,plane_2_lo_val(a0)
  631. swap d3
  632. move.w #$e4,plane_2_hi_ptr(a0)
  633. move.w d3,plane_2_hi_val(a0)
  634. swap d3
  635. add.l #SCROLL_HEIGHT*BPR,d3
  636. move.w #$ea,plane_3_lo_ptr(a0)
  637. move.w d3,plane_3_lo_val(a0)
  638. swap d3
  639. move.w #$e8,plane_3_hi_ptr(a0)
  640. move.w d3,plane_3_hi_val(a0)
  641. swap d3
  642. add.l #SCROLL_HEIGHT*BPR,d3
  643. move.w #$ee,plane_4_lo_ptr(a0)
  644. move.w d3,plane_4_lo_val(a0)
  645. swap d3
  646. move.w #$ec,plane_4_hi_ptr(a0)
  647. move.w d3,plane_4_hi_val(a0)
  648. * UNUSED SET OF SPLIT POINTERS
  649. move.w #$1f0,wait_pos(a1)
  650. move.w #$1f0,plane_1_hi_ptr(a1)
  651. move.w #$1f0,plane_1_lo_ptr(a1)
  652. move.w #$1f0,plane_2_hi_ptr(a1)
  653. move.w #$1f0,plane_2_lo_ptr(a1)
  654. move.w #$1f0,plane_3_hi_ptr(a1)
  655. move.w #$1f0,plane_3_lo_ptr(a1)
  656. move.w #$1f0,plane_4_hi_ptr(a1)
  657. move.w #$1f0,plane_4_lo_ptr(a1)
  658. * TOP OF SCREEN
  659. move.l #top_of_screen-4,a0 ;so rs.w's work
  660. move.w d2,plane_1_lo_val(a0)
  661. swap d2
  662. move.w d2,plane_1_hi_val(a0)
  663. swap d2
  664. add.l #SCROLL_HEIGHT*BPR,d2
  665. move.w d2,plane_2_lo_val(a0)
  666. swap d2
  667. move.w d2,plane_2_hi_val(a0)
  668. swap d2
  669. add.l #SCROLL_HEIGHT*BPR,d2
  670. move.w d2,plane_3_lo_val(a0)
  671. swap d2
  672. move.w d2,plane_3_hi_val(a0)
  673. swap d2
  674. add.l #SCROLL_HEIGHT*BPR,d2
  675. move.w d2,plane_4_lo_val(a0)
  676. swap d2
  677. move.w d2,plane_4_hi_val(a0)
  678. rts
  679. ******************************************
  680. **** CLEAR BANKS *****
  681. ******************************************
  682. clear_banks
  683. * UNUSED SET OF SPLIT POINTERS 1
  684. move.w #$1f0,wait_pos(a1)
  685. move.w #$1f0,plane_1_hi_ptr(a1)
  686. move.w #$1f0,plane_1_lo_ptr(a1)
  687. move.w #$1f0,plane_2_hi_ptr(a1)
  688. move.w #$1f0,plane_2_lo_ptr(a1)
  689. move.w #$1f0,plane_3_hi_ptr(a1)
  690. move.w #$1f0,plane_3_lo_ptr(a1)
  691. move.w #$1f0,plane_4_hi_ptr(a1)
  692. move.w #$1f0,plane_4_lo_ptr(a1)
  693. * UNUSED SET OF SPLIT POINTERS 2
  694. move.w #$1f0,wait_pos(a0)
  695. move.w #$1f0,plane_1_hi_ptr(a0)
  696. move.w #$1f0,plane_1_lo_ptr(a0)
  697. move.w #$1f0,plane_2_hi_ptr(a0)
  698. move.w #$1f0,plane_2_lo_ptr(a0)
  699. move.w #$1f0,plane_3_hi_ptr(a0)
  700. move.w #$1f0,plane_3_lo_ptr(a0)
  701. move.w #$1f0,plane_4_hi_ptr(a0)
  702. move.w #$1f0,plane_4_lo_ptr(a0)
  703. * TOP OF SCREEN
  704. move.l #top_of_screen-4,a0 ;so rs.w's work
  705. move.w d2,plane_1_lo_val(a0)
  706. swap d2
  707. move.w d2,plane_1_hi_val(a0)
  708. swap d2
  709. add.l #SCROLL_HEIGHT*BPR,d2
  710. move.w d2,plane_2_lo_val(a0)
  711. swap d2
  712. move.w d2,plane_2_hi_val(a0)
  713. swap d2
  714. add.l #SCROLL_HEIGHT*BPR,d2
  715. move.w d2,plane_3_lo_val(a0)
  716. swap d2
  717. move.w d2,plane_3_hi_val(a0)
  718. swap d2
  719. add.l #SCROLL_HEIGHT*BPR,d2
  720. move.w d2,plane_4_lo_val(a0)
  721. swap d2
  722. move.w d2,plane_4_hi_val(a0)
  723. rts
  724. scroll_x_position dc.w 0
  725. scroll_y_position dc.w 0
  726. **********************************************************
  727. *********** DRAW BLOCKS FOR SCROLL ***********
  728. **********************************************************
  729. draw_blocks_for_scroll
  730. tst.w y_ready_flag
  731. beq.s see_if_x_to_draw
  732. move.l current_y_screen_position,a0
  733. move.l current_y_map_mem_position,a1
  734. bsr draw_y_blocks
  735. see_if_x_to_draw
  736. tst.w x_ready_flag
  737. beq.s quit_draw_blocks_for_scroll
  738. move.l current_x_screen_position,a0
  739. move.l current_x_map_mem_position,a1
  740. bsr draw_x_blocks
  741. quit_draw_blocks_for_scroll
  742. rts
  743. current_screen_position dc.l 0
  744. current_y_screen_position dc.l 0
  745. current_x_screen_position dc.l 0
  746. current_map_mem_position dc.l 0
  747. current_x_map_mem_position dc.l 0
  748. current_y_map_mem_position dc.l 0
  749. **********************************************************
  750. *********** DRAW Y BLOCKS ***********
  751. **********************************************************
  752. draw_y_blocks
  753. *current screen mem position in a0
  754. *current map position in a1
  755. add.l add_y_block_direction,a0
  756. cmp.l plane1,a0
  757. bge.s draw_inside_plane_area
  758. add.l #SCROLL_HEIGHT*BPR,a0
  759. draw_inside_plane_area
  760. *---- So starts one block back so filling in x strips - see design
  761. subq.l #4,a0
  762. *-<
  763. cmp.l #SCROLL_GOING_UP,add_y_block_direction
  764. bne.s scroll_down
  765. add.l #MAP_SCREEN_OFFSET_DOWN,a1
  766. bra.s draw_blocks_up
  767. scroll_down
  768. add.l #MAP_SCREEN_OFFSET_UP,a1
  769. draw_blocks_up
  770. *-----------draw blocks loop-------------
  771. draw_blocks_main
  772. moveq #0,d0
  773. move.w current_y_map_position,d0
  774. ext.l d0
  775. add.l d0,a1 ;current map position
  776. asl d0 ;get into bytes
  777. add.l d0,a0 ;get to current line
  778. move.w total_number_of_y_blocks_to_draw,d2
  779. moveq #0,d7 ;count number of blocks drawn
  780. init_blit_values
  781. btst #14,dmaconr(a6)
  782. bne.s init_blit_values
  783. move.w #BPR-2,bltdmod(a6)
  784. move.w #0,bltamod(a6)
  785. move.l #$ffffffff,bltafwm(a6)
  786. move.l #$09F00000,bltcon0(A6)
  787. moveq #NUMBER_OF_Y_BLOCKS_PER_FRAME-1,d0
  788. draw_loop
  789. move.l #blocks,a2
  790. moveq #0,d1
  791. move.b (a1),d1
  792. asl.w #7,d1 ;same as mulu (16*2)*4
  793. add.l d1,a2 ;get to correct position in block data
  794. draw_block_on_screen
  795. btst #14,dmaconr(a6)
  796. bne.s draw_block_on_screen
  797. move.l a0,bltdpth(a6) ;screen
  798. move.l a2,bltapth(a6) ;graphics
  799. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  800. move.l a0,a3
  801. add.l #BPR*SCROLL_HEIGHT,a3
  802. add.l #16*2,a2
  803. draw_block_on_screenp2
  804. btst #14,dmaconr(a6)
  805. bne.s draw_block_on_screenp2
  806. move.l a3,bltdpth(a6) ;screen
  807. move.l a2,bltapth(a6) ;graphics
  808. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  809. add.l #BPR*SCROLL_HEIGHT,a3
  810. add.l #16*2,a2
  811. draw_block_on_screenp3
  812. btst #14,dmaconr(a6)
  813. bne.s draw_block_on_screenp3
  814. move.l a3,bltdpth(a6) ;screen
  815. move.l a2,bltapth(a6) ;graphics
  816. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  817. add.l #BPR*SCROLL_HEIGHT,a3
  818. add.l #16*2,a2
  819. draw_block_on_screenp4
  820. btst #14,dmaconr(a6)
  821. bne.s draw_block_on_screenp4
  822. move.l a3,bltdpth(a6) ;screen
  823. move.l a2,bltapth(a6) ;graphics
  824. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  825. done_a_block
  826. addq.l #2,a0 ;next block position along screen
  827. addq.l #1,a1 ;next map position
  828. addq.w #1,current_y_map_position
  829. addq.w #1,d7 ;count number blocks drawn
  830. cmp.w current_y_map_position,d2
  831. bne.s not_yet_done_line
  832. move.w #0,current_y_map_position
  833. move.w #WAIT_DRAW_BLOCKS,y_ready_flag ;done our line now wait for screen to scroll 16
  834. bra.s done_all_blocks
  835. not_yet_done_line
  836. dbra d0,draw_loop
  837. done_all_blocks
  838. rts
  839. **********************************************************
  840. *********** DRAW X BLOCKS ***********
  841. **********************************************************
  842. draw_x_blocks
  843. *current screen mem position in a0
  844. *current map position in a1
  845. **make it draw always on right
  846. add.l add_x_block_direction,a0
  847. cmp.l #SCROLL_GOING_LEFT,add_x_block_direction
  848. bne.s scroll_going_towards_right
  849. add.l #MAP_SCREEN_OFFSET_RIGHT,a1
  850. bra.s draw_x_blocks_straight
  851. scroll_going_towards_right
  852. add.l #MAP_SCREEN_OFFSET_LEFT,a1
  853. draw_x_blocks_straight
  854. moveq #0,d0
  855. move.w current_x_map_position,d0
  856. move.w d0,d1
  857. mulu #MAP_LINE_SIZE,d0
  858. add.l d0,a1 ;get to current line
  859. mulu #BPR*16,d1
  860. add.l d1,a0 ;current screen block position
  861. move.l plane1,a3
  862. cmp.l a3,a0
  863. bge.s within_plane_still
  864. add.l #SCROLL_HEIGHT*BPR,a0
  865. within_plane_still
  866. add.l #BPR*SCROLL_HEIGHT,a3
  867. cmp.l a3,a0
  868. blt.s test2
  869. sub.l #SCROLL_HEIGHT*BPR,a0
  870. test2
  871. move.w total_number_of_x_blocks_to_draw,d2
  872. moveq #0,d7 ;count number of blocks drawn
  873. init_x_blit_values
  874. btst #14,dmaconr(a6)
  875. bne.s init_x_blit_values
  876. move.w #BPR-2,bltdmod(a6)
  877. move.w #0,bltamod(a6)
  878. move.l #$ffffffff,bltafwm(a6)
  879. move.l #$09F00000,bltcon0(A6)
  880. moveq #NUMBER_OF_X_BLOCKS_PER_FRAME-1,d0
  881. draw_x_loop
  882. move.l #blocks,a2
  883. moveq #0,d1
  884. move.b (a1),d1
  885. asl.w #7,d1 ;same as mulu (16*2)*4
  886. add.l d1,a2 ;get to correct position in block data
  887. draw_x_block_on_screen
  888. btst #14,dmaconr(a6)
  889. bne.s draw_x_block_on_screen
  890. move.l a0,bltdpth(a6) ;screen
  891. move.l a2,bltapth(a6) ;graphics
  892. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  893. move.l a0,a3
  894. add.l #BPR*SCROLL_HEIGHT,a3
  895. add.l #16*2,a2
  896. draw_x_block_on_screenp2
  897. btst #14,dmaconr(a6)
  898. bne.s draw_x_block_on_screenp2
  899. move.l a3,bltdpth(a6) ;screen
  900. move.l a2,bltapth(a6) ;graphics
  901. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  902. add.l #BPR*SCROLL_HEIGHT,a3
  903. add.l #16*2,a2
  904. draw_x_block_on_screenp3
  905. btst #14,dmaconr(a6)
  906. bne.s draw_x_block_on_screenp3
  907. move.l a3,bltdpth(a6) ;screen
  908. move.l a2,bltapth(a6) ;graphics
  909. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  910. add.l #BPR*SCROLL_HEIGHT,a3
  911. add.l #16*2,a2
  912. draw_x_block_on_screenp4
  913. btst #14,dmaconr(a6)
  914. bne.s draw_x_block_on_screenp4
  915. move.l a3,bltdpth(a6) ;screen
  916. move.l a2,bltapth(a6) ;graphics
  917. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  918. done_x_block
  919. add.w #16,d5 ;current y pixel position
  920. add.l #BPR*16,a0
  921. move.l plane1,a3
  922. cmp.l a3,a0
  923. bge.s no_need_to_wrap
  924. add.l #SCROLL_HEIGHT*BPR,a0
  925. no_need_to_wrap
  926. add.l #SCROLL_HEIGHT*BPR,a3
  927. cmp.l a3,a0
  928. blt.s test7777
  929. sub.l #SCROLL_HEIGHT*BPR,a0
  930. test7777
  931. add.l #MAP_LINE_SIZE,a1
  932. addq.w #1,current_x_map_position
  933. addq.w #1,d7 ;count number blocks drawn
  934. cmp.w current_x_map_position,d2
  935. bne.s not_yet_done_x_line
  936. move.w #0,current_x_map_position
  937. move.w #WAIT_DRAW_BLOCKS,x_ready_flag ;done our line now wait for screen to scroll 16
  938. bra.s done_all_x_blocks
  939. not_yet_done_x_line
  940. dbra d0,draw_x_loop
  941. done_all_x_blocks
  942. rts
  943. total_number_of_y_blocks_to_draw dc.w 24
  944. current_y_map_position dc.w 0
  945. total_number_of_x_blocks_to_draw dc.w 20
  946. current_x_map_position dc.w 0
  947. ********************************************************
  948. **** FILL SCREEN WITH BLOCKS ****
  949. ********************************************************
  950. fill_screen_with_blocks
  951. move.l plane1,a0
  952. move.l #map_data,a1
  953. move.w #18-1,d0
  954. do_all_blocks
  955. move.w #START_DRAW_BLOCKS,y_ready_flag
  956. keep_drawing
  957. movem.l a0-a1/d0,-(sp)
  958. bsr draw_blocks_main
  959. movem.l (sp)+,a0-a1/d0
  960. tst y_ready_flag
  961. bne.s keep_drawing
  962. add.l #16*BPR,a0
  963. add.l #MAP_LINE_SIZE,a1
  964. dbra d0,do_all_blocks
  965. move.w #WAIT_DRAW_BLOCKS,y_ready_flag
  966. move.w #START_DRAW_BLOCKS,x_ready_flag
  967. wait_until_done
  968. move.l plane1,a0
  969. add.l #40,a0
  970. move.l #map_data+21,a1
  971. bsr draw_x_blocks_straight
  972. cmp.w #WAIT_DRAW_BLOCKS,x_ready_flag
  973. bne.s wait_until_done
  974. move.w #START_DRAW_BLOCKS,x_ready_flag
  975. wait_until_done2
  976. move.l plane1,a0
  977. add.l #42,a0
  978. move.l #map_data+21,a1
  979. bsr draw_x_blocks_straight
  980. cmp.w #WAIT_DRAW_BLOCKS,x_ready_flag
  981. bne.s wait_until_done2
  982. move.w #WAIT_DRAW_BLOCKS,x_ready_flag
  983. rts
  984. ********************************************************
  985. **** SET UP SCROLL POSITION ****
  986. ********************************************************
  987. set_up_scroll_position
  988. clr.w scroll_y_position
  989. clr.w scroll_x_position
  990. clr.w current_x_map_position
  991. clr.w current_y_map_position
  992. clr.w check_x_add
  993. clr.w check_y_add
  994. rts
  995. include "code:platform/glens_code/joy_routines.s"
  996. blocks
  997. incbin "scratch:empty/testblks"
  998. EVEN
  999. map_data
  1000. incbin "scratch:empty/testmapraw"
  1001. EVEN