home *** CD-ROM | disk | FTP | other *** search
/ Light / Light_Vol.1_August_1992_Datasphere_Publications_Disk_1_of_2_Side_B.d64 / user.asm (.txt) < prev   
Commodore BASIC  |  2023-02-26  |  13KB  |  568 lines

  1. 1000 ! *******************************
  2. 1010 ! ****
  3. 1020 ! ****    demonstration use of
  4. 1030 ! ****  'spritez' data, written
  5. 1040 ! ****      by ian (NULL)ffe 1991.
  6. 1050 ! ****
  7. 1060 ! **** this routine shows the
  8. 1070 ! **** fundaments of calling the
  9. 1080 ! **** sprite/screen backdrop
  10. 1090 ! **** driver code from within
  11. 1100 ! **** your own program.
  12. 1110 ! **** for this routine to work,
  13. 1120 ! **** all the appropriate motion
  14. 1130 ! **** /sprite/animation/parameter
  15. 1140 ! **** and backdrop data must be
  16. 1150 ! **** present in memory...
  17. 1160 ! **** for more details, see the
  18. 1170 ! **** basic program within
  19. 1180 ! **** 'alldemo' - which contains
  20. 1190 ! **** a copy of this assembled
  21. 1200 ! **** code - check out from
  22. 1210 ! **** location $6000 (24576)....
  23. 1220 ! ********************************
  24. 1230 !
  25. 1240 !
  26. 1250 ! **** locations to be used
  27. 1260 ! **** within the main driver
  28. 1270 ! **** code.
  29. 1280 !
  30. 1290 irqmove=$9059
  31. 1300 initparams=$9505
  32. 1310 seton=$9071
  33. 1320 backdrop=$94ec
  34. 1330 !
  35. 1340 *=24576
  36. 1350 sei
  37. 1360 !
  38. 1370 ! ********************************
  39. 1380 ! set up irq.....
  40. 1390 ! note that a raster split is
  41. 1400 ! to be set up for position 209,
  42. 1410 ! at which point the sprite-mover
  43. 1420 ! code is called, and for test
  44. 1430 ! purposes - the default screen/
  45. 1440 ! character set is re-selected.
  46. 1450 ! a second raster split is at
  47. 1460 ! position 0; this selects
  48. 1470 ! the character/screen memory
  49. 1480 ! for the backdrop images...
  50. 1490 ! of course, if the sprite motion
  51. 1500 ! is required without any of the
  52. 1510 ! backdrops, then make sure that
  53. 1520 ! the correct vic bank is selected
  54. 1530 ! relating to the pre-defined
  55. 1540 ! sprite pointer settings!!
  56. 1550 ! ********************************
  57. 1560 !
  58. 1570 setirq !
  59. 1580 lda #$1b
  60. 1590 sta $d011
  61. 1600 lda #209
  62. 1610 sta $d012
  63. 1620 lda #<irq
  64. 1630 sta $0314
  65. 1640 lda #>irq
  66. 1650 sta $0315
  67. 1660 lda #1
  68. 1670 sta $d019
  69. 1680 sta $d01a
  70. 1690 lda #$7f
  71. 1700 sta $dc0d
  72. 1710 lda $dc0d
  73. 1720 !
  74. 1730 ! initialise sprite positions
  75. 1740 ! for the given screen stored
  76. 1750 ! in location '760' (02f8 hex)
  77. 1760 !
  78. 1770 jsr startoff
  79. 1780 cli
  80. 1790 !
  81. 1800 rts
  82. 1810 ! ...
  83. 1820 !
  84. 1830 ! ...
  85. 1840 irq !
  86. 1850 !
  87. 1860 ! this irq is executed at
  88. 1870 ! raster position 209.
  89. 1880 !
  90. 1890 !   change to hires-mode,
  91. 1900 !   select default bank/screen
  92. 1910 !   and character set.
  93. 1920 !
  94. 1930 !
  95. 1940 lda #200
  96. 1950 sta 53270
  97. 1960 lda #63
  98. 1970 sta 56578
  99. 1980 lda #151
  100. 1990 sta 56576
  101. 2000 lda #23
  102. 2010 sta 53272
  103. 2020 !
  104. 2030 ! set next 'irq' to be triggered
  105. 2040 ! at raster line 'zero'.
  106. 2050 !
  107. 2060 lda #<topirq
  108. 2070 ldy #>topirq
  109. 2080 sta $0314
  110. 2090 sty $0315
  111. 2100 lda #0
  112. 2110 sta $d012
  113. 2120 !
  114. 2130 ! call sprite movement code...
  115. 2140 !
  116. 2150 jsr irqmove
  117. 2160 !
  118. 2170 ! only re-display screen and
  119. 2180 ! initialise sprite movements
  120. 2190 ! if a different screen number
  121. 2200 ! has been requested in location
  122. 2210 ! '760' (02f8 hex)
  123. 2220 !
  124. 2230 lda lastscreen
  125. 2240 cmp 760
  126. 2250 beq same
  127. 2260 jsr startoff
  128. 2270 same !
  129. 2280 !
  130. 2290 !
  131. 2300 irqexit !
  132. 2310 lda $dc0d
  133. 2320 lda #1
  134. 2330 sta $d019
  135. 2340 jmp $ea31
  136. 2350 !
  137. 2360 topirq !
  138. 2370 !
  139. 2380 !
  140. 2390 !  set next irq to be triggered
  141. 2400 !  at raster line 209.
  142. 2410 !
  143. 2420 lda #209
  144. 2430 sta $d012
  145. 2440 !
  146. 2450 ! set multi-colour mode
  147. 2460 !
  148. 2470 lda #216
  149. 2480 sta 53270
  150. 2490 !
  151. 2500 !    select vic bank '3'.
  152. 2510 !    screen at $ec00 (60416)
  153. 2520 !    char. set at $f000 (61440)
  154. 2530 !
  155. 2540 lda 56578
  156. 2550 ora #3
  157. 2560 sta 56578
  158. 2570 sta 56578
  159. 2580 lda 56576
  160. 2590 and #252
  161. 2600 ora #0
  162. 2610 sta 56576
  163. 2620 lda 53272
  164. 2630 and #15
  165. 2640 ora #176
  166. 2650 and #240
  167. 2660 ora #12
  168. 2670 sta 53272
  169. 2680 ldx #<irq
  170. 2690 ldy #>irq
  171. 2700 stx $0314
  172. 2710 sty $0315
  173. 2720 jmp irqexit
  174. 2730 !
  175. 2740 startoff !
  176. 2750 !
  177. 2760 !  set 'start' sprite
  178. 2770 !  information pertinent
  179. 2780 !  to the specified screen number
  180. 2790 !  in '760' (02f8 hex).
  181. 2800 !
  182. 2810 !
  183. 2820 jsr initparams
  184. 2830 ldx #0
  185. 2840 stx $d000+21
  186. 2850 startloop txa
  187. 2860 pha
  188. 2870 !
  189. 2880 !  call initialisation routine
  190. 2890 !  for the sprite number currently
  191. 2900 !  stored in the accumulator.
  192. 2910 !
  193. 2920 jsr seton
  194. 2930 pla
  195. 2940 tax
  196. 2950 inx
  197. 2960 cpx #8
  198. 2970 bne startloop
  199. 2980 !
  200. 2990 !   display screen, if not the
  201. 3000 !   current or 'last screen'.
  202. 3010 !
  203. 3020 lda 760
  204. 3030 sta lastscreen
  205. 3040 lda backdrop
  206. 3050 !
  207. 3060 !  call the 'seuck/block' print
  208. 3070 !
  209. 3080 jsr expascr
  210. 3090 rts
  211. 3100 lastscreen byt 0
  212. 3110 ! **********************************
  213. 3120 !
  214. 3130 !    seuck extension block/screen
  215. 3140 !    expansion routine
  216. 3150 !
  217. 3160 !
  218. 3170 !      first give values to
  219. 3180 !      labels refering to the above
  220. 3190 !
  221. 3200 blockbase=$2100
  222. 3210 screendata=$7000
  223. 3220 bb=blockbase !  a shorter label for
  224. 3230 !               later on!!
  225. 3240 colblock=$2000
  226. 3250 sc=$ec00
  227. 3260 !
  228. 3270 !           used to find colour map
  229. 3280 !           from screen address...
  230. 3290 !
  231. 3300 difference=sc-55296
  232. 3310 !
  233. 3320 !      init zero page locations to
  234. 3330 !      hold the addresses to work on
  235. 3340 !
  236. 3350 blockad=$fe
  237. 3360 colourad=$fc
  238. 3370 screenad=$fa
  239. 3380 sad=$f8
  240. 3390 !
  241. 3400 ! this is all that is required
  242. 3410 ! of you to print a screen!!!
  243. 3420 !
  244. 3430 !
  245. 3440 rts
  246. 3450 ! *****************************
  247. 3460 !
  248. 3470 ! ----------------------------------
  249. 3480 !       the routine below prints
  250. 3490 !       a single block to the screen
  251. 3500 !       at the given x and y coords.
  252. 3510 !      call this routine with:
  253. 3520 !             a=block number
  254. 3530 !end    "xinit" any "yinit"
  255. 3540 !  holding the relevant coordinates.
  256. 3550 !
  257. 3560 ! ----------------------------------
  258. 3570 expblock !
  259. 3580 !
  260. 3590 !
  261. 3600 sta blocknum
  262. 3610 tax
  263. 3620 !
  264. 3630 !
  265. 3640 !     ! get y=block number*2
  266. 3650 !
  267. 3660 asl a !  shift left ie. *2
  268. 3670 tay
  269. 3680 !
  270. 3690 !     get the colour of this block
  271. 3700 lda colblock,x
  272. 3710 sta bcolour
  273. 3720 !
  274. 3730 !   now we need to get the start
  275. 3740 !   addr. of this block's definition
  276. 3750 !
  277. 3760 !   to do this we need to get :-
  278. 3770 !   (block no.*25)+block base addr.
  279. 3780 !   this may take much processor
  280. 3790 !   time as "multiple-addition"
  281. 3800 !   techniques are required.
  282. 3810 !
  283. 3820 ! instead i have set up a 256-byte
  284. 3830 ! table holding each of the 128
  285. 3840 ! block addresses.
  286. 3850 ! to index a particular block def.
  287. 3860 !       index=block no. *2
  288. 3870 !
  289. 3880 !        as y=block no*2
  290. 3890 !
  291. 3900 !
  292. 3910 lda blocktabad,y ! get lo byte
  293. 3920 sta blockad
  294. 3930 lda blocktabad+1,y ! hi byte
  295. 3940 sta blockad+1
  296. 3950 !
  297. 3960 !      simple isn't it, now"?"
  298. 3970 !
  299. 3980 ! this time saving is required
  300. 3990 ! as this routine is called 32
  301. 4000 ! times for each screen - you will
  302. 4010 ! notice the time difference
  303. 4020 ! if the address wasn't tabulated!
  304. 4030 ! we need to bang data onto the
  305. 4040 ! screen like a bat out of hell,
  306. 4050 !  so it's well worth the 256 bytes!
  307. 4060 ! -------------------------------
  308. 4070 !           summary:-
  309. 4080 !  blockad holds block/char addr
  310. 4090 !  for block in "blocknum"
  311. 4100 ! -------------------------------
  312. 4110 !
  313. 4120 !  now get screenad to hold the
  314. 4130 !  screen address for the y coord.
  315. 4140 !
  316. 4150 !    ie. so as screenad holds the
  317. 4160 !    screen address for when x=0.
  318. 4170 !
  319. 4180 !   i am employing the same
  320. 4190 ! ! "get the address out of the
  321. 4200 !   table[171]quick" method again as
  322. 4210 ! it is in the main routine still!
  323. 4220 !    get y coordinate*2 for offset
  324. 4230 !    in the screen address table.
  325. 4240 !
  326. 4250 lda yinit
  327. 4260 asl a
  328. 4270 tay
  329. 4280 lda screentable,y
  330. 4290 sta screenad
  331. 4300 lda screentable+1,y
  332. 4310 sta screenad+1
  333. 4320 !
  334. 4330 !
  335. 4340 !
  336. 4350 !
  337. 4360 ! -----------------------------
  338. 4370 ! now screenad=the y coord address
  339. 4380 ! of the screen for x=0
  340. 4390 ! -----------------------------
  341. 4400 !
  342. 4410 lda #0
  343. 4420 sta blkread !  count through 0-24
  344. 4430 !              chars. in this block
  345. 4440 lda #5
  346. 4450 sta ycount !     height of block
  347. 4460 !
  348. 4470 do1y lda xinit ! each new y coord -
  349. 4480 !                give the x start
  350. 4490 !                index across the
  351. 4500 !                the screen ie.
  352. 4510 !                value from 0-39.
  353. 4520 sta bxcoord
  354. 4530 ldy #5 !         width of block
  355. 4540 sty xcount
  356. 4550 !
  357. 4560 do1x ldy blkread !    index (0-24)
  358. 4570 !                    through block
  359. 4580 !                    definition.
  360. 4590 !
  361. 4600 !           read a char. to print
  362. 4610 !           from this block's base
  363. 4620 !
  364. 4630 readblock lda (blockad),y
  365. 4640 !
  366. 4650 ldy bxcoord !    store on scree
  367. 4660 !              taking into account
  368. 4670 !               the column index
  369. 4680 !
  370. 4690 sta (screenad),y
  371. 4700 !
  372. 4710 !     create the colourmap address
  373. 4720 !     relative from the screen.
  374. 4730 !
  375. 4740 !  note that if a screen address
  376. 4750 !  is being used that is >55296
  377. 4760 !   then the label difference
  378. 4770 !  would need to be changed to:-
  379. 4780 !      difference=scr-55296
  380. 4790 !
  381. 4800 !  and the "adc" instructions
  382. 4810 ! below would need to be changed
  383. 4820 ! to "sbc" - making sure that you
  384. 4830 ! set carry (sec) first instead of
  385. 4840 !   "clc"  - nuff said!
  386. 4850 !
  387. 4860 sec
  388. 4870 lda screenad
  389. 4880 sbc #<difference
  390. 4890 sta colourad
  391. 4900 lda screenad+1
  392. 4910 sbc #>difference
  393. 4920 sta colourad+1
  394. 4930 lda bcolour
  395. 4940 !
  396. 4950 !  y still holds column index
  397. 4960 ! so colour in that char on screen!
  398. 4970 sta (colourad),y
  399. 4980 !
  400. 4990 inc bxcoord !     move along screen
  401. 5000 !                column
  402. 5010 inc blkread !   through 0-24 index
  403. 5020 !               in block
  404. 5030 !
  405. 5040 !
  406. 5050 dec xcount       loop width
  407. 5060 bne do1x
  408. 5070 !
  409. 5080 !
  410. 5090 ! now move down one y coordinate -
  411. 5100 ! just add 40 to the screen addr.
  412. 5110 !
  413. 5120 clc
  414. 5130 lda screenad
  415. 5140 adc #40
  416. 5150 sta screenad
  417. 5160 bcc oke
  418. 5170 inc screenad+1
  419. 5180 !
  420. 5190 oke dec ycount !   loop height
  421. 5200 bne do1y
  422. 5210 rts
  423. 5220 bxcoord byt 0
  424. 5230 blkread byt 0
  425. 5240 xinit byt 0
  426. 5250 yinit byt 0
  427. 5260 blocknum byt 0
  428. 5270 ycount byt 0
  429. 5280 xcount byt 0
  430. 5290 ! -----------------------------
  431. 5300 !
  432. 5310 ! this routine expands a complete
  433. 5320 ! screen by calling the "expand
  434. 5330 ! a block routine" for each of the
  435. 5340 ! 32 blocks on a screen..
  436. 5350 !
  437. 5360 !it is called with a=screen number
  438. 5370 ! - simplicity it'self for you!
  439. 5380 !
  440. 5390 ! ------------------------------
  441. 5400 expascr !
  442. 5410 !
  443. 5420 ! right - what we must do
  444. 5430 ! is find the screen data address.
  445. 5440 ! each data address for a screen
  446. 5450 ! is 32 bytes long - so we must
  447. 5460 ! get (32*screen)+base
  448. 5470 ! of data addresses - ok...
  449. 5480 !
  450. 5490 ldx #0
  451. 5500 sta sad
  452. 5510 stx sad+1 !  init multiply
  453. 5520 !
  454. 5530 clc
  455. 5540 asl sad
  456. 5550 rol sad+1 !             *2
  457. 5560 asl sad
  458. 5570 rol sad+1 !             *4
  459. 5580 asl sad
  460. 5590 rol sad+1 !             *8
  461. 5600 asl sad
  462. 5610 rol sad+1 !             *16
  463. 5620 asl sad
  464. 5630 rol sad+1         !     *32
  465. 5640 !
  466. 5650 !     now to add in the base
  467. 5660 !     address of the screen data
  468. 5670 !
  469. 5680 clc
  470. 5690 lda sad
  471. 5700 adc #<screendata
  472. 5710 sta sad
  473. 5720 lda sad+1
  474. 5730 adc #>screendata
  475. 5740 sta sad+1
  476. 5750 !
  477. 5760 ! --------------------------
  478. 5770 ! wicked! - scrad/+1 h(NULL)lds base
  479. 5780 ! address for the screen - phew!
  480. 5790 ! ---------------------------
  481. 5800 !
  482. 5810 !
  483. 5820 stx xinit !      x coord on screen
  484. 5830 stx yinit !      y   "   "    "
  485. 5840 stx blokc ! index in screen [131]
  486. 5850 !           [164] [135] block numbers
  487. 5860 bka !
  488. 5870 ldy blokc
  489. 5880 lda (sad),y ! [135] block in
  490. 5890 !                 this screen
  491. 5900 !
  492. 5910 inc blokc !  [130] block in screen
  493. 5920 !
  494. 5930 ! bang that block [145][164] the screen !
  495. 5940 jsr [189]block
  496. 5950 !
  497. 5960 lda xinit
  498. 5970 clc
  499. 5980 adc #5 !      start [130] block
  500. 5990 !            al[145]g by 5 characters
  501. 6000 sta xinit
  502. 6010 cmp #40 ! right[171]most column
  503. 6020 !         reached
  504. 6030 !
  505. 6040 bne noxreac
  506. 6050 !
  507. 6060 ! [171][171][177] [139] x reached last column
  508. 6070 !     [167] reset x [164] 0, [175] move
  509. 6080 !     down by 5 y co[176]dinates!!
  510. 6090 !
  511. 6100 lda #0
  512. 6110 sta xinit
  513. 6120 clc
  514. 6130 lda yinit
  515. 6140 adc #5 !      down 5 chars(y)
  516. 6150 sta yinit
  517. 6160 !
  518. 6170 !
  519. 6180 cmp #20 !  check for max y coord.
  520. 6190 !         (must be a multiple of 5
  521. 6200 !          - or else !!!!)
  522. 6210 !
  523. 6220 beq [142]
  524. 6230 noxreac jmp bka
  525. 6240 !
  526. 6250 ! finally the whole screen has
  527. 6260 ! been displayed [171] sit back &
  528. 6270 ! admire your w[176]k..........
  529. 6280 !
  530. 6290 [142] !
  531. 6300 rts
  532. 6310 blokc byt 0
  533. 6320 bcolour byt 0
  534. 6330 !
  535. 6340 !
  536. 6350 !the addresses of block definitions
  537. 6360 ! (all 128 of them!)
  538. 6370 !
  539. 6380 blocktabad !
  540. 6390 w[176] bb,bb[170]25,bb[170]50,bb[170]75,bb[170]100,bb[170]125,bb[170]150,bb[170]175,bb[170]200,bb[170]225
  541. 6400 w[176] bb[170]250,bb[170]275,bb[170]300,bb[170]325
  542. 6410 w[176] bb[170]350,bb[170]375,bb[170]400,bb[170]425
  543. 6420 w[176] bb[170]450,bb[170]475,bb[170]500,bb[170]525
  544. 6430 w[176] bb[170]550,bb[170]575,bb[170]600,bb[170]625
  545. 6440 w[176] bb[170]650,bb[170]675,bb[170]700,bb[170]725,bb[170]750,bb[170]775,bb[170]800,bb[170]825,bb[170]850,bb[170]875
  546. 6450 w[176] bb[170]900,bb[170]925,bb[170]950,bb[170]975,bb[170]1000,bb[170]1025
  547. 6460 w[176] bb[170]1050,bb[170]1075,bb[170]1100,bb[170]1125,bb[170]1150,bb[170]1175,bb[170]1200,bb[170]1225
  548. 6470 w[176] bb[170]1250,bb[170]1275,bb[170]1300,bb[170]1325,bb[170]1350,bb[170]1375,bb[170]1400,bb[170]1425
  549. 6480 w[176] bb[170]1450,bb[170]1475,bb[170]1500,bb[170]1525,bb[170]1550,bb[170]1575,bb[170]1600,bb[170]1625
  550. 6490 w[176] bb[170]1650,bb[170]1675,bb[170]1700,bb[170]1725,bb[170]1750,bb[170]1775,bb[170]1800,bb[170]1825
  551. 6500 w[176] bb[170]1850,bb[170]1875,bb[170]1900,bb[170]1925
  552. 6510 w[176] bb[170]1950,bb[170]1975,bb[170]2000,bb[170]2025,bb[170]2050,bb[170]2075,bb[170]2100,bb[170]2125
  553. 6520 w[176] bb[170]2150,bb[170]2175,bb[170]2200,bb[170]2225,bb[170]2250,bb[170]2275,bb[170]2300,bb[170]2325
  554. 6530 w[176] bb[170]2350,bb[170]2375,bb[170]2400,bb[170]2425,bb[170]2450,bb[170]2475,bb[170]2500,bb[170]2525
  555. 6540 w[176] bb[170]2550,bb[170]2575,bb[170]2600,bb[170]2625,bb[170]2650,bb[170]2675,bb[170]2700,bb[170]2725
  556. 6550 w[176] bb[170]2750,bb[170]2775,bb[170]2800,bb[170]2825,bb[170]2850,bb[170]2875,bb[170]2900,bb[170]2925
  557. 6560 w[176] bb[170]2950,bb[170]2975,bb[170]3000,bb[170]3025,bb[170]3050,bb[170]3075,bb[170]3100,bb[170]3125
  558. 6570 w[176] bb[170]3150,bb[170]3175
  559. 6580 !
  560. 6590 ! [175] the screen addresses.....
  561. 6600 !
  562. 6610 screentable w[176] sc,sc[170]40,sc[170]80,sc[170]120,sc[170]160,sc[170]200,sc[170]240,sc[170]280,sc[170]320
  563. 6620 w[176] sc[170]360,sc[170]400,sc[170]440,sc[170]480,sc[170]520,sc[170]560,sc[170]600,sc[170]640,sc[170]680,sc[170]720
  564. 6630 w[176] sc[170]760,sc[170]800
  565. 6640 !
  566. 6650 !
  567. 6660 !         (c) ijg'1991
  568.