scroll_x_y.s 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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. bsr calculate_scroll_movement
  181. bsr move_scroll
  182. bsr draw_blocks_for_scroll
  183. wait btst.b #6,$bfe001
  184. bne.s main_demo
  185. btst.b #10,$dff016
  186. bne.s main_demo
  187. rts
  188. Single_Mouse_Press
  189. btst #6,$BFE001
  190. Bne out
  191. * move.w #$11,jobba
  192. not_released
  193. btst #6,$BFE001
  194. Beq not_released
  195. out
  196. rts
  197. COPPERL
  198. dc.w bplcono
  199. dc.w $4200
  200. dc.w $102 ; scrolly bit
  201. dc.w $000
  202. dc.w DDFSTRT
  203. dc.w $0030
  204. dc.w DDFSTOP
  205. dc.w $00d8
  206. dc.w bpl1mod
  207. dc.w 20
  208. dc.w bpl2mod
  209. dc.w 20
  210. dc.w $1e4
  211. dc.w $2100
  212. dc.w $10c
  213. dc.w $11
  214. dc.w $1fc
  215. dc.w $0
  216. copper_colours
  217. ds.w 16*2
  218. ************sprites
  219. dc.w $180,$0
  220. dc.w $120 ;all sprite stuff
  221. sprite0h dc.w $0
  222. dc.w $122
  223. sprite0l dc.w 0
  224. dc.w $124
  225. sprite1h dc.w $0
  226. dc.w $126
  227. sprite1l dc.w 0
  228. dc.w $128
  229. sprite2h dc.w $0
  230. dc.w $12a
  231. sprite2l dc.w 0
  232. dc.w $12c
  233. sprite3h dc.w $0
  234. dc.w $12e
  235. sprite3l dc.w 0
  236. dc.w $130
  237. sprite4h dc.w $0
  238. dc.w $132
  239. sprite4l dc.w 0
  240. dc.w $134
  241. sprite5h dc.w $0
  242. dc.w $136
  243. sprite5l dc.w 0
  244. dc.w $138
  245. sprite6h dc.w $0
  246. dc.w $13a
  247. sprite6l dc.w 0
  248. dc.w $13c
  249. sprite7h dc.w $0
  250. dc.w $13e
  251. sprite7l dc.w 0
  252. dc.w $102
  253. scroll_value
  254. dc.w 0
  255. top_of_screen
  256. DC.W $00E0 ;top bank of plane initialisers
  257. Plane1_Hi DC.W 0
  258. DC.W $00E2
  259. Plane1_Lo DC.W 0
  260. DC.W $00E4
  261. Plane2_Hi DC.W 0
  262. DC.W $00E6
  263. Plane2_Lo DC.W 0
  264. DC.W $00E8
  265. Plane3_Hi DC.W 0
  266. DC.W $00Ea
  267. Plane3_Lo DC.W 0
  268. DC.W $00Ec
  269. Plane4_Hi DC.W 0
  270. DC.W $00Ee
  271. Plane4_Lo DC.W 0
  272. scroll_bank_1
  273. dc.w $2c01,$fffe
  274. DC.W $00E0
  275. DC.W 0
  276. DC.W $00E2
  277. DC.W 0
  278. DC.W $00E4
  279. DC.W 0
  280. DC.W $00E6
  281. DC.W 0
  282. DC.W $00E8
  283. DC.W 0
  284. DC.W $00Ea
  285. DC.W 0
  286. DC.W $00Ec
  287. DC.W 0
  288. DC.W $00Ee
  289. DC.W 0
  290. dc.w $180,$fff
  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. draw_pixel
  335. mulu.w #BPR,d1
  336. add.l d1,a0
  337. move.w d0,d3
  338. lsr.w #3,d0 ; get bytes
  339. andi.b #%111,d3 ; pixel bits
  340. moveq #7,d1
  341. sub.b d3,d1
  342. bset.b d1,(a0,d0.w) ;
  343. rts
  344. clear_pixel
  345. mulu.w #BPR,d1
  346. add.l d1,a0
  347. move.w d0,d3
  348. lsr.w #3,d0 ; get bytes
  349. andi.b #%111,d3 ; pixel bits
  350. moveq #7,d1
  351. sub.b d3,d1
  352. bclr.b d1,(a0,d0.w) ;
  353. rts
  354. plane1
  355. dc.l 0
  356. plane2
  357. dc.l 0
  358. plane3
  359. dc.l 0
  360. plane4
  361. dc.l 0
  362. buff_plane1
  363. dc.l 0
  364. buff_plane2
  365. dc.l 0
  366. buff_plane3
  367. dc.l 0
  368. buff_plane4
  369. dc.l 0
  370. *----------------------------SCROLL CODE----------------------
  371. reset
  372. wait_pos rs.w 1
  373. wait_mask rs.w 1
  374. plane_1_hi_ptr rs.w 1
  375. plane_1_hi_val rs.w 1
  376. plane_1_lo_ptr rs.w 1
  377. plane_1_lo_val rs.w 1
  378. plane_2_hi_ptr rs.w 1
  379. plane_2_hi_val rs.w 1
  380. plane_2_lo_ptr rs.w 1
  381. plane_2_lo_val rs.w 1
  382. plane_3_hi_ptr rs.w 1
  383. plane_3_hi_val rs.w 1
  384. plane_3_lo_ptr rs.w 1
  385. plane_3_lo_val rs.w 1
  386. plane_4_hi_ptr rs.w 1
  387. plane_4_hi_val rs.w 1
  388. plane_4_lo_ptr rs.w 1
  389. plane_4_lo_val rs.w 1
  390. TEST_SPEED EQU 4
  391. WAIT_DRAW_BLOCKS EQU 0
  392. START_DRAW_BLOCKS EQU 1
  393. MAP_LINE_SIZE EQU 100
  394. MAP_HEIGHT_SIZE EQU 100
  395. SCROLL_GOING_DOWN EQU -48*BPR ;up from bottom of scroll
  396. SCROLL_GOING_UP EQU -16*BPR
  397. MAP_SCREEN_OFFSET_UP EQU 17*MAP_LINE_SIZE
  398. MAP_SCREEN_OFFSET_DOWN EQU -1*MAP_LINE_SIZE
  399. SCROLL_GOING_LEFT EQU -(BPR*SCROLL_HEIGHT)+42
  400. SCROLL_GOING_RIGHT EQU -(BPR*SCROLL_HEIGHT)
  401. MAP_SCREEN_OFFSET_RIGHT EQU 21
  402. MAP_SCREEN_OFFSET_LEFT EQU 0
  403. NUMBER_OF_Y_BLOCKS_PER_FRAME EQU 7
  404. NUMBER_OF_X_BLOCKS_PER_FRAME EQU 7
  405. ******************************************
  406. **** CALCULATE SCROLL MOVEMENT *****
  407. ******************************************
  408. calculate_scroll_movement
  409. *separate stick from scroll thus this routine can send
  410. *any value to scroll allowing velocity scrolls etc
  411. move.w #0,d0
  412. tst.w xdirec
  413. beq.w no_x_movement
  414. bpl.s scroll_moving_to_right
  415. move.w #-TEST_SPEED,d0
  416. bra.s no_x_movement
  417. scroll_moving_to_right
  418. move.w #TEST_SPEED,d0
  419. no_x_movement
  420. move.w #0,d1
  421. tst.w ydirec
  422. beq.w no_y_movement
  423. bmi.s scroll_moving_down
  424. move.w #-TEST_SPEED,d1
  425. bra.s no_y_movement
  426. scroll_moving_down
  427. move.w #TEST_SPEED,d1
  428. no_y_movement
  429. rts
  430. ******************************************
  431. **** MOVE SCROLL *****
  432. ******************************************
  433. move_scroll
  434. *send in x and y increments in d0 and d1
  435. *-Test x bounds
  436. add.w d0,scroll_x_position
  437. bge.s scroll_x_not_hit_bounds
  438. move.w scroll_x_position,d2
  439. neg.w d2
  440. add.w d2,d0
  441. clr.w scroll_x_position
  442. scroll_x_not_hit_bounds
  443. cmp.w #((MAP_LINE_SIZE-20)*16)-1,scroll_x_position
  444. ble.s scroll_x_not_hit_max_bounds
  445. move.w scroll_x_position,d2
  446. sub.w #((MAP_LINE_SIZE-20)*16)-1,d2
  447. move.w d2,d0
  448. move.w #((MAP_LINE_SIZE-20)*16)-1,scroll_x_position
  449. scroll_x_not_hit_max_bounds
  450. *-<
  451. *-Test y bounds
  452. add.w d1,scroll_y_position
  453. bge.s scroll_not_hit_bounds
  454. move.w scroll_y_position,d2
  455. neg.w d2
  456. add.w d2,d1 ;give proper speed
  457. clr.w scroll_y_position
  458. scroll_not_hit_bounds
  459. cmp.w #(MAP_HEIGHT_SIZE-16)*16,scroll_y_position
  460. ble.s scroll_y_not_hit_max_bounds
  461. move.w scroll_y_position,d2
  462. sub.w #(MAP_HEIGHT_SIZE-16)*16,d2
  463. move.w d2,d1
  464. move.w #(MAP_LINE_SIZE-16)*16,scroll_y_position
  465. scroll_y_not_hit_max_bounds
  466. *-<
  467. bsr check_add_blocks
  468. bsr position_scroll
  469. rts
  470. ******************************************
  471. **** CHECK ADD BLOCKS *****
  472. ******************************************
  473. check_add_blocks
  474. *-Do for y blocks
  475. add.w d1,check_y_add
  476. cmp.w #17,check_y_add
  477. blt.s check_min_add
  478. sub.w #16,check_y_add
  479. move.w #START_DRAW_BLOCKS,y_ready_flag
  480. move.l #SCROLL_GOING_DOWN,add_y_block_direction
  481. bra.s drawing_please_wait
  482. check_min_add
  483. cmp.w #-17,check_y_add
  484. bgt.s drawing_please_wait
  485. move.w #START_DRAW_BLOCKS,y_ready_flag
  486. move.l #SCROLL_GOING_UP,add_y_block_direction
  487. add.w #16,check_y_add
  488. drawing_please_wait
  489. *-<
  490. *- Do for x blocks
  491. add.w d0,check_x_add
  492. cmp.w #17,check_x_add
  493. blt.s check_x_min_add
  494. sub.w #16,check_x_add
  495. move.w #START_DRAW_BLOCKS,x_ready_flag
  496. move.l #SCROLL_GOING_LEFT,add_x_block_direction
  497. bra.s drawing_x_please_wait
  498. check_x_min_add
  499. cmp.w #-17,check_x_add
  500. bgt.s drawing_x_please_wait
  501. move.w #START_DRAW_BLOCKS,x_ready_flag
  502. move.l #SCROLL_GOING_RIGHT,add_x_block_direction
  503. add.w #16,check_x_add
  504. drawing_x_please_wait
  505. *-<
  506. rts
  507. add_y_block_direction dc.l 0
  508. check_y_add dc.w 0
  509. y_ready_flag dc.w 0
  510. add_x_block_direction dc.l 0
  511. check_x_add dc.w 0
  512. x_ready_flag dc.w 0
  513. ******************************************
  514. **** POSITION SCROLL *****
  515. ******************************************
  516. position_scroll
  517. *Positions scroll by the x and y values stored
  518. move.w scroll_x_position,d0
  519. move.w scroll_y_position,d1
  520. position_scroll_along_x
  521. moveq #0,d3
  522. move.w d0,d2
  523. move.w d0,d3
  524. andi.w #$000f,d2 ;shift value
  525. asr.w #4,d3 ;number of blocks in
  526. andi.w #$fff0,d0
  527. asr.w #3,d0
  528. ext.l d0 ;bytes in
  529. neg.w d2
  530. add.w #15,d2
  531. move.w d2,d4
  532. asl.w #4,d2
  533. or.w d2,d4
  534. move.w d4,scroll_value
  535. position_scroll_along_y
  536. *---
  537. moveq #0,d2
  538. move.w d1,d2
  539. asr.w #4,d2
  540. mulu #MAP_LINE_SIZE,d2
  541. move.l #map_data,a0
  542. add.l d2,a0 ;add y
  543. add.l d3,a0 ;add x
  544. move.l a0,current_map_mem_position
  545. *---
  546. ext.l d1
  547. divu #SCROLL_HEIGHT,d1
  548. swap d1 ;this is all we want - split position down screen
  549. neg.w d1 ;so scroll goes right way
  550. add.w #SCROLL_HEIGHT,d1
  551. *---calc where to draw
  552. moveq #0,d3
  553. move.w #SCROLL_HEIGHT,d3 ;position above buffer area
  554. sub.w d1,d3 ;position of buffer area
  555. andi.w #$fff0,d3
  556. asl.w #6,d3
  557. add.l plane1,d3
  558. add.l d0,d3 ;add x in
  559. move.l d3,current_y_screen_position
  560. *------
  561. move.w d1,d2
  562. add.w #$2c,d1
  563. moveq #0,d4
  564. cmp.w #$ff,d1
  565. ble.s not_over_dodgy_line
  566. moveq #1,d4
  567. not_over_dodgy_line
  568. cmp.w #$ff+$2c,d1
  569. ble.s not_off_copper
  570. move.w #-1,d4
  571. bra.s calc_screen_split
  572. not_off_copper
  573. andi.w #$ff,d1 ;so values wraps round
  574. asl.w #8,d1
  575. addq.w #1,d1 ; = wait value
  576. calc_screen_split
  577. neg.w d2
  578. add.w #SCROLL_HEIGHT,d2
  579. asl.w #6,d2 ;mulu by 64 - get line down
  580. ext.l d2
  581. add.l plane1,d2 ;to display at top
  582. move.l plane1,d3 ;top display at split
  583. add.l d0,d2 ;add x in
  584. add.l d0,d3 ;add x in
  585. bsr insert_plane_pointers
  586. rts
  587. ******************************************
  588. **** INSERT PLANE POINTERS *****
  589. ******************************************
  590. insert_plane_pointers
  591. *d1 contains wait value
  592. *d2 = top of display
  593. *d3 = split part of display
  594. *d4 indicates if inserting after 255 gap
  595. tst d4
  596. bmi clear_all_banks
  597. beq.s insert_before_line
  598. insert_after_line
  599. move.l #scroll_bank_2,a0
  600. move.l #scroll_bank_1,a1
  601. bsr fill_banks
  602. rts
  603. insert_before_line
  604. move.l #scroll_bank_1,a0
  605. move.l #scroll_bank_2,a1
  606. bsr fill_banks
  607. rts
  608. clear_all_banks
  609. move.l #scroll_bank_1,a0
  610. move.l #scroll_bank_2,a1
  611. bsr clear_banks
  612. rts
  613. ******************************************
  614. **** FILL BANKS *****
  615. ******************************************
  616. fill_banks
  617. *a0 = bank to fill
  618. *a1 = bank to clear
  619. *d1 = wait
  620. *d2 = top of display
  621. *d3 = split display
  622. *change to copper jump later - but get it working first!!!
  623. * IN USE SPLIT POINTERS
  624. move.w d1,wait_pos(a0)
  625. move.w #$fffe,wait_mask(a0)
  626. move.w #$e2,plane_1_lo_ptr(a0)
  627. move.w d3,plane_1_lo_val(a0)
  628. swap d3
  629. move.w #$e0,plane_1_hi_ptr(a0)
  630. move.w d3,plane_1_hi_val(a0)
  631. swap d3
  632. add.l #SCROLL_HEIGHT*BPR,d3
  633. move.w #$e6,plane_2_lo_ptr(a0)
  634. move.w d3,plane_2_lo_val(a0)
  635. swap d3
  636. move.w #$e4,plane_2_hi_ptr(a0)
  637. move.w d3,plane_2_hi_val(a0)
  638. swap d3
  639. add.l #SCROLL_HEIGHT*BPR,d3
  640. move.w #$ea,plane_3_lo_ptr(a0)
  641. move.w d3,plane_3_lo_val(a0)
  642. swap d3
  643. move.w #$e8,plane_3_hi_ptr(a0)
  644. move.w d3,plane_3_hi_val(a0)
  645. swap d3
  646. add.l #SCROLL_HEIGHT*BPR,d3
  647. move.w #$ee,plane_4_lo_ptr(a0)
  648. move.w d3,plane_4_lo_val(a0)
  649. swap d3
  650. move.w #$ec,plane_4_hi_ptr(a0)
  651. move.w d3,plane_4_hi_val(a0)
  652. * UNUSED SET OF SPLIT POINTERS
  653. move.w #$1f0,wait_pos(a1)
  654. move.w #$1f0,plane_1_hi_ptr(a1)
  655. move.w #$1f0,plane_1_lo_ptr(a1)
  656. move.w #$1f0,plane_2_hi_ptr(a1)
  657. move.w #$1f0,plane_2_lo_ptr(a1)
  658. move.w #$1f0,plane_3_hi_ptr(a1)
  659. move.w #$1f0,plane_3_lo_ptr(a1)
  660. move.w #$1f0,plane_4_hi_ptr(a1)
  661. move.w #$1f0,plane_4_lo_ptr(a1)
  662. * TOP OF SCREEN
  663. move.l #top_of_screen-4,a0 ;so rs.w's work
  664. move.w d2,plane_1_lo_val(a0)
  665. swap d2
  666. move.w d2,plane_1_hi_val(a0)
  667. swap d2
  668. add.l #SCROLL_HEIGHT*BPR,d2
  669. move.w d2,plane_2_lo_val(a0)
  670. swap d2
  671. move.w d2,plane_2_hi_val(a0)
  672. swap d2
  673. add.l #SCROLL_HEIGHT*BPR,d2
  674. move.w d2,plane_3_lo_val(a0)
  675. swap d2
  676. move.w d2,plane_3_hi_val(a0)
  677. swap d2
  678. add.l #SCROLL_HEIGHT*BPR,d2
  679. move.w d2,plane_4_lo_val(a0)
  680. swap d2
  681. move.w d2,plane_4_hi_val(a0)
  682. rts
  683. ******************************************
  684. **** CLEAR BANKS *****
  685. ******************************************
  686. clear_banks
  687. * UNUSED SET OF SPLIT POINTERS 1
  688. move.w #$1f0,wait_pos(a1)
  689. move.w #$1f0,plane_1_hi_ptr(a1)
  690. move.w #$1f0,plane_1_lo_ptr(a1)
  691. move.w #$1f0,plane_2_hi_ptr(a1)
  692. move.w #$1f0,plane_2_lo_ptr(a1)
  693. move.w #$1f0,plane_3_hi_ptr(a1)
  694. move.w #$1f0,plane_3_lo_ptr(a1)
  695. move.w #$1f0,plane_4_hi_ptr(a1)
  696. move.w #$1f0,plane_4_lo_ptr(a1)
  697. * UNUSED SET OF SPLIT POINTERS 2
  698. move.w #$1f0,wait_pos(a0)
  699. move.w #$1f0,plane_1_hi_ptr(a0)
  700. move.w #$1f0,plane_1_lo_ptr(a0)
  701. move.w #$1f0,plane_2_hi_ptr(a0)
  702. move.w #$1f0,plane_2_lo_ptr(a0)
  703. move.w #$1f0,plane_3_hi_ptr(a0)
  704. move.w #$1f0,plane_3_lo_ptr(a0)
  705. move.w #$1f0,plane_4_hi_ptr(a0)
  706. move.w #$1f0,plane_4_lo_ptr(a0)
  707. * TOP OF SCREEN
  708. move.l #top_of_screen-4,a0 ;so rs.w's work
  709. move.w d2,plane_1_lo_val(a0)
  710. swap d2
  711. move.w d2,plane_1_hi_val(a0)
  712. swap d2
  713. add.l #SCROLL_HEIGHT*BPR,d2
  714. move.w d2,plane_2_lo_val(a0)
  715. swap d2
  716. move.w d2,plane_2_hi_val(a0)
  717. swap d2
  718. add.l #SCROLL_HEIGHT*BPR,d2
  719. move.w d2,plane_3_lo_val(a0)
  720. swap d2
  721. move.w d2,plane_3_hi_val(a0)
  722. swap d2
  723. add.l #SCROLL_HEIGHT*BPR,d2
  724. move.w d2,plane_4_lo_val(a0)
  725. swap d2
  726. move.w d2,plane_4_hi_val(a0)
  727. rts
  728. scroll_x_position dc.w 0
  729. scroll_y_position dc.w 0
  730. **********************************************************
  731. *********** DRAW BLOCKS FOR SCROLL ***********
  732. **********************************************************
  733. draw_blocks_for_scroll
  734. tst.w y_ready_flag
  735. beq.s see_if_x_to_draw
  736. move.l current_y_screen_position,a0
  737. move.l current_map_mem_position,a1
  738. bsr draw_y_blocks
  739. bra.s quit_draw_blocks_for_scroll
  740. see_if_x_to_draw
  741. tst.w x_ready_flag
  742. beq.s quit_draw_blocks_for_scroll
  743. move.l current_y_screen_position,a0
  744. move.l current_map_mem_position,a1
  745. bsr draw_x_blocks
  746. quit_draw_blocks_for_scroll
  747. rts
  748. current_y_screen_position dc.l 0
  749. current_x_screen_position dc.l 0
  750. current_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. cmp.l #SCROLL_GOING_UP,add_y_block_direction
  763. bne.s scroll_down
  764. add.l #MAP_SCREEN_OFFSET_DOWN,a1
  765. bra.s draw_blocks_up
  766. scroll_down
  767. add.l #MAP_SCREEN_OFFSET_UP,a1
  768. draw_blocks_up
  769. *-----------draw blocks loop-------------
  770. draw_blocks_main
  771. moveq #0,d0
  772. move.w current_y_map_position,d0
  773. ext.l d0
  774. add.l d0,a1 ;current map position
  775. asl d0 ;get into bytes
  776. add.l d0,a0 ;get to current line
  777. move.w total_number_of_y_blocks_to_draw,d2
  778. moveq #0,d7 ;count number of blocks drawn
  779. init_blit_values
  780. btst #14,dmaconr(a6)
  781. bne.s init_blit_values
  782. move.w #BPR-2,bltdmod(a6)
  783. move.w #0,bltamod(a6)
  784. move.l #$ffffffff,bltafwm(a6)
  785. move.l #$09F00000,bltcon0(A6)
  786. moveq #NUMBER_OF_Y_BLOCKS_PER_FRAME-1,d0
  787. draw_loop
  788. move.l #blocks,a2
  789. moveq #0,d1
  790. move.b (a1),d1
  791. asl.w #7,d1 ;same as mulu (16*2)*4
  792. add.l d1,a2 ;get to correct position in block data
  793. draw_block_on_screen
  794. btst #14,dmaconr(a6)
  795. bne.s draw_block_on_screen
  796. move.l a0,bltdpth(a6) ;screen
  797. move.l a2,bltapth(a6) ;graphics
  798. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  799. move.l a0,a3
  800. add.l #BPR*SCROLL_HEIGHT,a3
  801. add.l #16*2,a2
  802. draw_block_on_screenp2
  803. btst #14,dmaconr(a6)
  804. bne.s draw_block_on_screenp2
  805. move.l a3,bltdpth(a6) ;screen
  806. move.l a2,bltapth(a6) ;graphics
  807. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  808. add.l #BPR*SCROLL_HEIGHT,a3
  809. add.l #16*2,a2
  810. draw_block_on_screenp3
  811. btst #14,dmaconr(a6)
  812. bne.s draw_block_on_screenp3
  813. move.l a3,bltdpth(a6) ;screen
  814. move.l a2,bltapth(a6) ;graphics
  815. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  816. add.l #BPR*SCROLL_HEIGHT,a3
  817. add.l #16*2,a2
  818. draw_block_on_screenp4
  819. btst #14,dmaconr(a6)
  820. bne.s draw_block_on_screenp4
  821. move.l a3,bltdpth(a6) ;screen
  822. move.l a2,bltapth(a6) ;graphics
  823. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  824. done_a_block
  825. addq.l #2,a0 ;next block position along screen
  826. addq.l #1,a1 ;next map position
  827. addq.w #1,current_y_map_position
  828. addq.w #1,d7 ;count number blocks drawn
  829. cmp.w current_y_map_position,d2
  830. bne.s not_yet_done_line
  831. move.w #0,current_y_map_position
  832. move.w #WAIT_DRAW_BLOCKS,y_ready_flag ;done our line now wait for screen to scroll 16
  833. bra.s done_all_blocks
  834. not_yet_done_line
  835. dbra d0,draw_loop
  836. done_all_blocks
  837. rts
  838. **********************************************************
  839. *********** DRAW X BLOCKS ***********
  840. **********************************************************
  841. draw_x_blocks
  842. *current screen mem position in a0
  843. *current map position in a1
  844. **make it draw always on right
  845. add.l add_x_block_direction,a0
  846. cmp.l #SCROLL_GOING_LEFT,add_x_block_direction
  847. bne.s scroll_going_towards_right
  848. add.l #MAP_SCREEN_OFFSET_RIGHT,a1
  849. bra.s draw_x_blocks_straight
  850. scroll_going_towards_right
  851. sub.l #MAP_SCREEN_OFFSET_LEFT,a1
  852. draw_x_blocks_straight
  853. moveq #0,d0
  854. move.w current_x_map_position,d0
  855. move.w d0,d1
  856. mulu #MAP_LINE_SIZE,d0
  857. add.l d0,a1 ;get to current line
  858. mulu #BPR*16,d1
  859. add.l d1,a0 ;current screen block position
  860. cmp.l plane1,a0
  861. bge.s within_plane_still
  862. add.l #SCROLL_HEIGHT*BPR,a0
  863. within_plane_still
  864. move.w total_number_of_x_blocks_to_draw,d2
  865. moveq #0,d7 ;count number of blocks drawn
  866. init_x_blit_values
  867. btst #14,dmaconr(a6)
  868. bne.s init_x_blit_values
  869. move.w #BPR-2,bltdmod(a6)
  870. move.w #0,bltamod(a6)
  871. move.l #$ffffffff,bltafwm(a6)
  872. move.l #$09F00000,bltcon0(A6)
  873. moveq #NUMBER_OF_X_BLOCKS_PER_FRAME-1,d0
  874. draw_x_loop
  875. move.l #blocks,a2
  876. moveq #0,d1
  877. move.b (a1),d1
  878. asl.w #7,d1 ;same as mulu (16*2)*4
  879. add.l d1,a2 ;get to correct position in block data
  880. draw_x_block_on_screen
  881. btst #14,dmaconr(a6)
  882. bne.s draw_x_block_on_screen
  883. move.l a0,bltdpth(a6) ;screen
  884. move.l a2,bltapth(a6) ;graphics
  885. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  886. move.l a0,a3
  887. add.l #BPR*SCROLL_HEIGHT,a3
  888. add.l #16*2,a2
  889. draw_x_block_on_screenp2
  890. btst #14,dmaconr(a6)
  891. bne.s draw_x_block_on_screenp2
  892. move.l a3,bltdpth(a6) ;screen
  893. move.l a2,bltapth(a6) ;graphics
  894. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  895. add.l #BPR*SCROLL_HEIGHT,a3
  896. add.l #16*2,a2
  897. draw_x_block_on_screenp3
  898. btst #14,dmaconr(a6)
  899. bne.s draw_x_block_on_screenp3
  900. move.l a3,bltdpth(a6) ;screen
  901. move.l a2,bltapth(a6) ;graphics
  902. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  903. add.l #BPR*SCROLL_HEIGHT,a3
  904. add.l #16*2,a2
  905. draw_x_block_on_screenp4
  906. btst #14,dmaconr(a6)
  907. bne.s draw_x_block_on_screenp4
  908. move.l a3,bltdpth(a6) ;screen
  909. move.l a2,bltapth(a6) ;graphics
  910. move.w #16<<6+1,bltsize(a6) ;1 word by 16 pixels
  911. done_x_block
  912. add.w #16,d5 ;current y pixel position
  913. add.l #BPR*16,a0
  914. cmp.l plane1,a0
  915. bge.s no_need_to_wrap
  916. add.l #SCROLL_HEIGHT*BPR,a0
  917. no_need_to_wrap
  918. add.l #MAP_LINE_SIZE,a1
  919. addq.w #1,current_x_map_position
  920. addq.w #1,d7 ;count number blocks drawn
  921. cmp.w current_x_map_position,d2
  922. bne.s not_yet_done_x_line
  923. move.w #0,current_x_map_position
  924. move.w #WAIT_DRAW_BLOCKS,x_ready_flag ;done our line now wait for screen to scroll 16
  925. bra.s done_all_x_blocks
  926. not_yet_done_x_line
  927. dbra d0,draw_x_loop
  928. done_all_x_blocks
  929. rts
  930. total_number_of_y_blocks_to_draw dc.w 20
  931. current_y_map_position dc.w 0
  932. total_number_of_x_blocks_to_draw dc.w 20
  933. current_x_map_position dc.w 0
  934. ********************************************************
  935. **** FILL SCREEN WITH BLOCKS ****
  936. ********************************************************
  937. fill_screen_with_blocks
  938. move.l plane1,a0
  939. move.l #map_data,a1
  940. move.w #18-1,d0
  941. do_all_blocks
  942. move.w #START_DRAW_BLOCKS,y_ready_flag
  943. keep_drawing
  944. movem.l a0-a1/d0,-(sp)
  945. bsr draw_blocks_main
  946. movem.l (sp)+,a0-a1/d0
  947. tst y_ready_flag
  948. bne.s keep_drawing
  949. add.l #16*BPR,a0
  950. add.l #MAP_LINE_SIZE,a1
  951. dbra d0,do_all_blocks
  952. move.w #WAIT_DRAW_BLOCKS,y_ready_flag
  953. move.w #START_DRAW_BLOCKS,x_ready_flag
  954. wait_until_done
  955. move.l plane1,a0
  956. add.l #40,a0
  957. move.l #map_data+21,a1
  958. bsr draw_x_blocks_straight
  959. cmp.w #WAIT_DRAW_BLOCKS,x_ready_flag
  960. bne.s wait_until_done
  961. move.w #START_DRAW_BLOCKS,x_ready_flag
  962. wait_until_done2
  963. move.l plane1,a0
  964. add.l #42,a0
  965. move.l #map_data+21,a1
  966. bsr draw_x_blocks_straight
  967. cmp.w #WAIT_DRAW_BLOCKS,x_ready_flag
  968. bne.s wait_until_done2
  969. move.w #WAIT_DRAW_BLOCKS,x_ready_flag
  970. rts
  971. ********************************************************
  972. **** SET UP SCROLL POSITION ****
  973. ********************************************************
  974. set_up_scroll_position
  975. move.w #0,scroll_y_position
  976. rts
  977. include "code:platform/glens_code/joy_routines.s"
  978. blocks
  979. incbin "scratch:empty/testblks"
  980. EVEN
  981. map_data
  982. incbin "scratch:empty/testmapraw"
  983. EVEN