Joystick port II with sprites demo.

SYS 64738
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: Joystick port II with sprites demo.

Post by Shaun_B » Tue Jul 08, 2014 4:42 pm

Hi Buzbard,
buzbard wrote:How the heck did you type in line 63999?
I thought I did say that I was using CBM Prg Studio but I must have been thinking about a different thread. Anyway, I always use CBM Prg Studio for BASIC programming as it just makes the process more efficient.
For the msb logic you could use:

Code: Select all

msb = -ff * (xaxis > 255)
Thanks, I'll give it a go.
And when reading and poking data, a for/next loop is faster and more efficient.
It may be slower, but I prefer a -1 at the end of the data or something similar as an exit clause so I don't have to count as I run out of fingers quickly (even though this example is from the user manual) and I'm not very good at counting and/or other maths. In any case, to read large data sets and doing other initialisation stuff, I'd usually switch off the VIC screen and would typically be running BASIC with a SuperCPU.

Regards,

Shaun.


BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.

User avatar
buzbard
Member
Member
Posts: 22
Joined: Sun Apr 13, 2014 9:06 pm
Location: Washington State

Re: Joystick port II with sprites demo.

Post by buzbard » Tue Jul 08, 2014 9:45 pm

Shaun_B wrote:I thought I did say that I was using CBM Prg Studio...
I must've missed that.
It may be slower, but I prefer a -1 at the end of the data or something similar as an exit clause so I don't have to count as I run out of fingers quickly...
You have toes don't you? Just kidding. :lol:
I'd usually switch off the VIC screen and would typically be running BASIC with a SuperCPU.
I don't have one of those, but switching off the VIC is a good idea.
Ray...
It's Ok if you don't agree with me, I can't force you to be right.

User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: Joystick port II with sprites demo.

Post by Shaun_B » Tue Jul 08, 2014 10:05 pm

Thanks buzbard for the counting with toes tips. I never thought of that as I struggle when I get to 10.

For those interested, the following listing demonstrates switching off and on the screen:

Code: Select all

10 poke 53265, peek(53265) and 239
20 poke 198,0: wait 198,1
30 poke 53265, peek(53265) or 16
Line 10 switches the screen off. Line 20 waits for a key press (after clearing the keyboard buffer) and line 30 switches the screen back on again.

You typically don't require keyboard interactions whilst doing your initialisation stuff, so you may also switch off interrupts as I've already said somewhere in this thread (this should quicken things up a little more I think - can anyone confirm this?), but if you require keyboard interactions thereafter remember to switch them back on again :-)

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.

satpro

Re: Joystick port II with sprites demo.

Post by satpro » Tue Jul 08, 2014 10:34 pm

Shaun_B wrote:Thanks buzbard for the counting with toes tips. I never thought of that as I struggle when I get to 10.
Think a little "harder" -- you should be able to get to 21. :D
You typically don't require keyboard interactions whilst doing your initialisation stuff, so you may also switch off interrupts as I've already said somewhere in this thread (this should quicken things up a little more I think - can anyone confirm this?)
Yep! Now your code is running with no interruptions.

User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: Joystick port II with sprites demo.

Post by Shaun_B » Wed Jul 16, 2014 2:59 pm

satpro wrote:
You typically don't require keyboard interactions whilst doing your initialisation stuff, so you may also switch off interrupts as I've already said somewhere in this thread (this should quicken things up a little more I think - can anyone confirm this?)
Yep! Now your code is running with no interruptions.
I would guess that BASIC still requires some house-keeping so I wasn't 100% sure but as with any interpreted language, every millisecond helps.

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.

User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: Joystick port II with sprites demo.

Post by Shaun_B » Mon Sep 08, 2014 11:11 am

Hi all,

Buzbard's trick got me thinking about how to further 'improve' the listing by taking out some more if/then statements, so here's what I eventually came up with:

Code: Select all

10 dim xaxis, yaxis, atemp, spr, index, jtemp, up, down, left
20 dim right, fire, vic, joy, po, bit, cmsb, zero, ff, sd
30 poke 53280,zero:poke 53281,zero
40 gosub 63985
50 print chr$(147)
60 xaxis = 64
70 yaxis = xaxis
80 atemp = left
90 jtemp = atemp+down
100 poke vic+fire, (peek(vic+fire) and cmsb) or (-left*(xaxis>ff))
110 poke vic+atemp, xaxis+(ff*(xaxis>ff))
120 poke vic+jtemp, yaxis
130 joy = bit - peek(po)
140 xaxis = xaxis + abs((joy and right)=right) - abs((joy and left)=left)
150 yaxis = yaxis + abs((joy and up)=up) - abs((joy and down)=down)
160 xaxis = xaxis + abs(xaxis<min) - abs(xaxis > max)
170 yaxis = yaxis + abs(yaxis<zero) - abs(yaxis > ff)
180 on -(joy<>fire) goto 100
190 poke 56334, peek(56334) or 1: rem switches basic interrupts back on
200 end
63985 rem initialisation:
63986 poke 56334, peek(56334) and 254: rem switches off interrupts
63987 fire = 16: right = 8: left  = 4: up = 2: down = 1: po = 56320
63988 bit = 127: cmsb = 251: ff = 255: min = right: max = 334: vic = 53248: sd = 832: spr = 21 
63989 atemp = 13: jtemp = 4: index = 2042
63990 poke vic+spr, jtemp
63991 poke index, atemp
63992 index = zero
63993 read jtemp
63994 if jtemp>-down then poke sd+index, jtemp: index = index+down: goto 63993
63995 return
63996 rem sprite data:
63997 data ,127,,1,255,192,3,255,224,3,231,224,7,217,240,7,223,240,7,217,240,3,231
63998 data 224,3,255,224,3,255,224,2,255,160,1,127,64,1,62,64,,156,128,,156,128
63999 data ,73,,,73,,,62,,,62,,,62,,,28,,-1
Notice that there is no MSB variable now as it's not needed. Also, with keyword abbreviations, you should be able to type this into a real Commodore (I've not tested that though), but I recommend an IDE like CBM prg Studio as it makes editing far easier.

The main loop (move sprite to joystick thing) is now from lines 100 to 180 (was lines 80 to 180); this is because I've done some line renumbering from the start. Lines 80 and 90 that handled the sprite's 'Most significant bit' on the x-axis is now done in line 100; it clears the MSB first with AND logic, if the x position is greater than 255, the bit will be set: in other words, it will OR 0 or OR 4 after the AND depending on the x position (<=255 or >255 respectively).

Buzbard's trick is then used in line 110; because Commodore Boolean values return -1 if true and zero if false, and 255 * -1 is -255, then we're adding either zero or -255 to the x position :-)

Interrupts have been switched off to save a couple of cycles here and there. There are more speed and efficiency savings that can be made to this listing by combining more lines and obfuscating the variables and such like. I've put a minimized example of this listing on Pastebin here: http://pastebin.com/tEdUmhH0

Enjoy,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.

Post Reply Previous topicNext topic