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
Wrap
Commodore BASIC
|
2023-02-26
|
13KB
|
568 lines
1000 ! *******************************
1010 ! ****
1020 ! **** demonstration use of
1030 ! **** 'spritez' data, written
1040 ! **** by ian (NULL)ffe 1991.
1050 ! ****
1060 ! **** this routine shows the
1070 ! **** fundaments of calling the
1080 ! **** sprite/screen backdrop
1090 ! **** driver code from within
1100 ! **** your own program.
1110 ! **** for this routine to work,
1120 ! **** all the appropriate motion
1130 ! **** /sprite/animation/parameter
1140 ! **** and backdrop data must be
1150 ! **** present in memory...
1160 ! **** for more details, see the
1170 ! **** basic program within
1180 ! **** 'alldemo' - which contains
1190 ! **** a copy of this assembled
1200 ! **** code - check out from
1210 ! **** location $6000 (24576)....
1220 ! ********************************
1230 !
1240 !
1250 ! **** locations to be used
1260 ! **** within the main driver
1270 ! **** code.
1280 !
1290 irqmove=$9059
1300 initparams=$9505
1310 seton=$9071
1320 backdrop=$94ec
1330 !
1340 *=24576
1350 sei
1360 !
1370 ! ********************************
1380 ! set up irq.....
1390 ! note that a raster split is
1400 ! to be set up for position 209,
1410 ! at which point the sprite-mover
1420 ! code is called, and for test
1430 ! purposes - the default screen/
1440 ! character set is re-selected.
1450 ! a second raster split is at
1460 ! position 0; this selects
1470 ! the character/screen memory
1480 ! for the backdrop images...
1490 ! of course, if the sprite motion
1500 ! is required without any of the
1510 ! backdrops, then make sure that
1520 ! the correct vic bank is selected
1530 ! relating to the pre-defined
1540 ! sprite pointer settings!!
1550 ! ********************************
1560 !
1570 setirq !
1580 lda #$1b
1590 sta $d011
1600 lda #209
1610 sta $d012
1620 lda #<irq
1630 sta $0314
1640 lda #>irq
1650 sta $0315
1660 lda #1
1670 sta $d019
1680 sta $d01a
1690 lda #$7f
1700 sta $dc0d
1710 lda $dc0d
1720 !
1730 ! initialise sprite positions
1740 ! for the given screen stored
1750 ! in location '760' (02f8 hex)
1760 !
1770 jsr startoff
1780 cli
1790 !
1800 rts
1810 ! ...
1820 !
1830 ! ...
1840 irq !
1850 !
1860 ! this irq is executed at
1870 ! raster position 209.
1880 !
1890 ! change to hires-mode,
1900 ! select default bank/screen
1910 ! and character set.
1920 !
1930 !
1940 lda #200
1950 sta 53270
1960 lda #63
1970 sta 56578
1980 lda #151
1990 sta 56576
2000 lda #23
2010 sta 53272
2020 !
2030 ! set next 'irq' to be triggered
2040 ! at raster line 'zero'.
2050 !
2060 lda #<topirq
2070 ldy #>topirq
2080 sta $0314
2090 sty $0315
2100 lda #0
2110 sta $d012
2120 !
2130 ! call sprite movement code...
2140 !
2150 jsr irqmove
2160 !
2170 ! only re-display screen and
2180 ! initialise sprite movements
2190 ! if a different screen number
2200 ! has been requested in location
2210 ! '760' (02f8 hex)
2220 !
2230 lda lastscreen
2240 cmp 760
2250 beq same
2260 jsr startoff
2270 same !
2280 !
2290 !
2300 irqexit !
2310 lda $dc0d
2320 lda #1
2330 sta $d019
2340 jmp $ea31
2350 !
2360 topirq !
2370 !
2380 !
2390 ! set next irq to be triggered
2400 ! at raster line 209.
2410 !
2420 lda #209
2430 sta $d012
2440 !
2450 ! set multi-colour mode
2460 !
2470 lda #216
2480 sta 53270
2490 !
2500 ! select vic bank '3'.
2510 ! screen at $ec00 (60416)
2520 ! char. set at $f000 (61440)
2530 !
2540 lda 56578
2550 ora #3
2560 sta 56578
2570 sta 56578
2580 lda 56576
2590 and #252
2600 ora #0
2610 sta 56576
2620 lda 53272
2630 and #15
2640 ora #176
2650 and #240
2660 ora #12
2670 sta 53272
2680 ldx #<irq
2690 ldy #>irq
2700 stx $0314
2710 sty $0315
2720 jmp irqexit
2730 !
2740 startoff !
2750 !
2760 ! set 'start' sprite
2770 ! information pertinent
2780 ! to the specified screen number
2790 ! in '760' (02f8 hex).
2800 !
2810 !
2820 jsr initparams
2830 ldx #0
2840 stx $d000+21
2850 startloop txa
2860 pha
2870 !
2880 ! call initialisation routine
2890 ! for the sprite number currently
2900 ! stored in the accumulator.
2910 !
2920 jsr seton
2930 pla
2940 tax
2950 inx
2960 cpx #8
2970 bne startloop
2980 !
2990 ! display screen, if not the
3000 ! current or 'last screen'.
3010 !
3020 lda 760
3030 sta lastscreen
3040 lda backdrop
3050 !
3060 ! call the 'seuck/block' print
3070 !
3080 jsr expascr
3090 rts
3100 lastscreen byt 0
3110 ! **********************************
3120 !
3130 ! seuck extension block/screen
3140 ! expansion routine
3150 !
3160 !
3170 ! first give values to
3180 ! labels refering to the above
3190 !
3200 blockbase=$2100
3210 screendata=$7000
3220 bb=blockbase ! a shorter label for
3230 ! later on!!
3240 colblock=$2000
3250 sc=$ec00
3260 !
3270 ! used to find colour map
3280 ! from screen address...
3290 !
3300 difference=sc-55296
3310 !
3320 ! init zero page locations to
3330 ! hold the addresses to work on
3340 !
3350 blockad=$fe
3360 colourad=$fc
3370 screenad=$fa
3380 sad=$f8
3390 !
3400 ! this is all that is required
3410 ! of you to print a screen!!!
3420 !
3430 !
3440 rts
3450 ! *****************************
3460 !
3470 ! ----------------------------------
3480 ! the routine below prints
3490 ! a single block to the screen
3500 ! at the given x and y coords.
3510 ! call this routine with:
3520 ! a=block number
3530 !end "xinit" any "yinit"
3540 ! holding the relevant coordinates.
3550 !
3560 ! ----------------------------------
3570 expblock !
3580 !
3590 !
3600 sta blocknum
3610 tax
3620 !
3630 !
3640 ! ! get y=block number*2
3650 !
3660 asl a ! shift left ie. *2
3670 tay
3680 !
3690 ! get the colour of this block
3700 lda colblock,x
3710 sta bcolour
3720 !
3730 ! now we need to get the start
3740 ! addr. of this block's definition
3750 !
3760 ! to do this we need to get :-
3770 ! (block no.*25)+block base addr.
3780 ! this may take much processor
3790 ! time as "multiple-addition"
3800 ! techniques are required.
3810 !
3820 ! instead i have set up a 256-byte
3830 ! table holding each of the 128
3840 ! block addresses.
3850 ! to index a particular block def.
3860 ! index=block no. *2
3870 !
3880 ! as y=block no*2
3890 !
3900 !
3910 lda blocktabad,y ! get lo byte
3920 sta blockad
3930 lda blocktabad+1,y ! hi byte
3940 sta blockad+1
3950 !
3960 ! simple isn't it, now"?"
3970 !
3980 ! this time saving is required
3990 ! as this routine is called 32
4000 ! times for each screen - you will
4010 ! notice the time difference
4020 ! if the address wasn't tabulated!
4030 ! we need to bang data onto the
4040 ! screen like a bat out of hell,
4050 ! so it's well worth the 256 bytes!
4060 ! -------------------------------
4070 ! summary:-
4080 ! blockad holds block/char addr
4090 ! for block in "blocknum"
4100 ! -------------------------------
4110 !
4120 ! now get screenad to hold the
4130 ! screen address for the y coord.
4140 !
4150 ! ie. so as screenad holds the
4160 ! screen address for when x=0.
4170 !
4180 ! i am employing the same
4190 ! ! "get the address out of the
4200 ! table[171]quick" method again as
4210 ! it is in the main routine still!
4220 ! get y coordinate*2 for offset
4230 ! in the screen address table.
4240 !
4250 lda yinit
4260 asl a
4270 tay
4280 lda screentable,y
4290 sta screenad
4300 lda screentable+1,y
4310 sta screenad+1
4320 !
4330 !
4340 !
4350 !
4360 ! -----------------------------
4370 ! now screenad=the y coord address
4380 ! of the screen for x=0
4390 ! -----------------------------
4400 !
4410 lda #0
4420 sta blkread ! count through 0-24
4430 ! chars. in this block
4440 lda #5
4450 sta ycount ! height of block
4460 !
4470 do1y lda xinit ! each new y coord -
4480 ! give the x start
4490 ! index across the
4500 ! the screen ie.
4510 ! value from 0-39.
4520 sta bxcoord
4530 ldy #5 ! width of block
4540 sty xcount
4550 !
4560 do1x ldy blkread ! index (0-24)
4570 ! through block
4580 ! definition.
4590 !
4600 ! read a char. to print
4610 ! from this block's base
4620 !
4630 readblock lda (blockad),y
4640 !
4650 ldy bxcoord ! store on scree
4660 ! taking into account
4670 ! the column index
4680 !
4690 sta (screenad),y
4700 !
4710 ! create the colourmap address
4720 ! relative from the screen.
4730 !
4740 ! note that if a screen address
4750 ! is being used that is >55296
4760 ! then the label difference
4770 ! would need to be changed to:-
4780 ! difference=scr-55296
4790 !
4800 ! and the "adc" instructions
4810 ! below would need to be changed
4820 ! to "sbc" - making sure that you
4830 ! set carry (sec) first instead of
4840 ! "clc" - nuff said!
4850 !
4860 sec
4870 lda screenad
4880 sbc #<difference
4890 sta colourad
4900 lda screenad+1
4910 sbc #>difference
4920 sta colourad+1
4930 lda bcolour
4940 !
4950 ! y still holds column index
4960 ! so colour in that char on screen!
4970 sta (colourad),y
4980 !
4990 inc bxcoord ! move along screen
5000 ! column
5010 inc blkread ! through 0-24 index
5020 ! in block
5030 !
5040 !
5050 dec xcount loop width
5060 bne do1x
5070 !
5080 !
5090 ! now move down one y coordinate -
5100 ! just add 40 to the screen addr.
5110 !
5120 clc
5130 lda screenad
5140 adc #40
5150 sta screenad
5160 bcc oke
5170 inc screenad+1
5180 !
5190 oke dec ycount ! loop height
5200 bne do1y
5210 rts
5220 bxcoord byt 0
5230 blkread byt 0
5240 xinit byt 0
5250 yinit byt 0
5260 blocknum byt 0
5270 ycount byt 0
5280 xcount byt 0
5290 ! -----------------------------
5300 !
5310 ! this routine expands a complete
5320 ! screen by calling the "expand
5330 ! a block routine" for each of the
5340 ! 32 blocks on a screen..
5350 !
5360 !it is called with a=screen number
5370 ! - simplicity it'self for you!
5380 !
5390 ! ------------------------------
5400 expascr !
5410 !
5420 ! right - what we must do
5430 ! is find the screen data address.
5440 ! each data address for a screen
5450 ! is 32 bytes long - so we must
5460 ! get (32*screen)+base
5470 ! of data addresses - ok...
5480 !
5490 ldx #0
5500 sta sad
5510 stx sad+1 ! init multiply
5520 !
5530 clc
5540 asl sad
5550 rol sad+1 ! *2
5560 asl sad
5570 rol sad+1 ! *4
5580 asl sad
5590 rol sad+1 ! *8
5600 asl sad
5610 rol sad+1 ! *16
5620 asl sad
5630 rol sad+1 ! *32
5640 !
5650 ! now to add in the base
5660 ! address of the screen data
5670 !
5680 clc
5690 lda sad
5700 adc #<screendata
5710 sta sad
5720 lda sad+1
5730 adc #>screendata
5740 sta sad+1
5750 !
5760 ! --------------------------
5770 ! wicked! - scrad/+1 h(NULL)lds base
5780 ! address for the screen - phew!
5790 ! ---------------------------
5800 !
5810 !
5820 stx xinit ! x coord on screen
5830 stx yinit ! y " " "
5840 stx blokc ! index in screen [131]
5850 ! [164] [135] block numbers
5860 bka !
5870 ldy blokc
5880 lda (sad),y ! [135] block in
5890 ! this screen
5900 !
5910 inc blokc ! [130] block in screen
5920 !
5930 ! bang that block [145][164] the screen !
5940 jsr [189]block
5950 !
5960 lda xinit
5970 clc
5980 adc #5 ! start [130] block
5990 ! al[145]g by 5 characters
6000 sta xinit
6010 cmp #40 ! right[171]most column
6020 ! reached
6030 !
6040 bne noxreac
6050 !
6060 ! [171][171][177] [139] x reached last column
6070 ! [167] reset x [164] 0, [175] move
6080 ! down by 5 y co[176]dinates!!
6090 !
6100 lda #0
6110 sta xinit
6120 clc
6130 lda yinit
6140 adc #5 ! down 5 chars(y)
6150 sta yinit
6160 !
6170 !
6180 cmp #20 ! check for max y coord.
6190 ! (must be a multiple of 5
6200 ! - or else !!!!)
6210 !
6220 beq [142]
6230 noxreac jmp bka
6240 !
6250 ! finally the whole screen has
6260 ! been displayed [171] sit back &
6270 ! admire your w[176]k..........
6280 !
6290 [142] !
6300 rts
6310 blokc byt 0
6320 bcolour byt 0
6330 !
6340 !
6350 !the addresses of block definitions
6360 ! (all 128 of them!)
6370 !
6380 blocktabad !
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
6400 w[176] bb[170]250,bb[170]275,bb[170]300,bb[170]325
6410 w[176] bb[170]350,bb[170]375,bb[170]400,bb[170]425
6420 w[176] bb[170]450,bb[170]475,bb[170]500,bb[170]525
6430 w[176] bb[170]550,bb[170]575,bb[170]600,bb[170]625
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
6450 w[176] bb[170]900,bb[170]925,bb[170]950,bb[170]975,bb[170]1000,bb[170]1025
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
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
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
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
6500 w[176] bb[170]1850,bb[170]1875,bb[170]1900,bb[170]1925
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
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
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
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
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
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
6570 w[176] bb[170]3150,bb[170]3175
6580 !
6590 ! [175] the screen addresses.....
6600 !
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
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
6630 w[176] sc[170]760,sc[170]800
6640 !
6650 !
6660 ! (c) ijg'1991