scroll_x_ynoflic.s 23 KB

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