Unlimited HostingFree Joomla TemplatesProfessional Joomla Templates
J - Google AdSense
Home Revival News Beyond Basic - Part 5
Banner

Beyond Basic - Part 5


Facebook!

Written By: Tony Cruise

First Published: Micro’s Gazette – Issue 003 (May/June 1989)

 

This issue I will start to detail the collision detection routine to go with the automatic sprite routines from last issue.  But first here is a list of the conversions for SVI-318/328 to MSX.

Part 1

The SVI-318/328 use the port 8C to change slots.  So to change between the RAM and ROM slots use:

ROM to RAM RAM to ROM
LD A,0FH LD A,(FE64H)
OUT (88H),A OUT (8CH),A
IN A,(90H)
LD (FE64H),A
AND FDH
OUT (8CH),A

Part 2 Onwards

Here is a list of ROM calls, RAM locations and HOOK addresses to use instead of the MSX values.

  • HGONE = FF57H,
  • HTIMI = FF5AH,
  • SCRMOD = FE3AH
  • SETWRT = 373CH,
  • SETRD = 3747H

Change the following port calls to:

  • OUT (98H),A becomes OUT (80H),A
  • IN A,(98H) becomes IN A,(84H)

This list will be expanded if necessary, each issue.

Sprite Collision Detection

Now onto this months routine.   Our routine will test the collision of one sprite (you specify) with all 31 others.  A table of flags will be used to show which sprites the one specified is colliding with.  The size of each sprite will be specified by a X and Y with from 0 to 15 (There is no zero width, work out the real value and subtract one).  For the routine to work effectively, your sprite shapes should be drawn from the top left hand corner of the sprite shape pattern.

e.g. X width 5, Y width 2

To make the routine easier to understand I have split it into two sections.  The section I will show this issue is the actual test routine, that tests whether two specified sprites are colliding and setting the carry flag if so.  The values of the registers on entry are:

  • HL points to sprite 1 VRAM table location
  • DE points to sprite 2 VRAM table location
  • B lower 4 bits, y width and top 4 bits, x width for sprite 1
  • C lower 4 bits, y width and top 4 bits, x width for sprite 2

Machine Code Program

1 ; Subroutine to test the collision of two sprites
2 ;
3 ;
4 ;
5 ; Label settings
6 ;
7 SETRD EQU 0050H ; Video read
8 ;
C0FA E5 9 START PUSH HL ; Save registers
C0FB D5 10 PUSH DE ;
C0FC C5 11 PUSH BC ;
C0FD 78 12 LD A,B ; Get Y velocity 1
C0FE E60F 13 AND 15 ;
C100 47 14 LD B,A ;
C101 79 15 LD A,C ; Get Y velocity 2
C102 E60F 16 AND 15 ;
C104 4F 17 LD C,A ;
C105 CD55C1 18 CALL RDVRM ; Get Y1 value
C108 80 19 ADD A,B ; Add velocity
C109 47 20 LD B,A ;
C10A EB 21 EX DE,HL ; Get Y2 value
C10B CD55C1 22 CALL RDVRM ;
C10E EB 23 EX DE,HL ;
C10F B8 24 CP B ; Hit?
C110 3040 25 JR NC,NOHIT ; No – Exit loop
C112 EB 26 EX DE,HL ; Get Y2 value
C113 CD55C1 27 CALL RDVRM ;
C116 EB 28 EX DE,HL ;
C117 81 29 ADD A,C ; Add velocity
C118 4F 30 LD C,A ;
C119 CD55C1 31 CALL RDVRM ; Get Y1 velocity
C11C B9 32 CP C ; Hit?
C11D 3033 33 JR NC,NOHIT ; No – Exit loop
C11F C1 34 POP BC ; Restore BC
C120 C5 35 PUSH BC ; Resave BC
C121 23 36 INC HL ; Increment pointers
C122 13 37 INC DE ;
C123 CB38 38 SRL B ; Get X velocity 1
C125 CB38 39 SRL B ;
C127 CB38 40 SRL B ;
C129 CB38 41 SRL B ;
C12B CB39 42 SRL C ; Get X velocity 2
C12D CB39 43 SRL C ;
C12F CB39 44 SRL C ;
C131 CB39 45 SRL C ;
C133 CD55C1 46 CALL RDVRM ; Get Y1 value
C136 80 47 ADD A,B ; Add velocity
C137 47 48 LD B,A ;
C138 EB 49 EX DE,HL ; Get Y2 velocity
C139 CD55C1 50 CALL RDVRM ;
C13C EB 51 EX DE,HL ;
C13D B8 52 CP B ; Hit?
C13E 3012 53 JR NC,NOHIT ; No – Exit loop
C140 EB 54 EX DE,HL ; Get Y2 value
C141 CD55C1 55 CALL RDVRM ;
C144 EB 56 EX DE,HL ;
C145 81 57 ADD A,C ; Add velocity
C146 4F 58 LD C,A ;
C147 CD55C1 59 CALL RDVRM ; Get Y1 value
C14A B9 60 CP C ; Hit?
C14B 3005 61 JR NC,NOHIT ; No – Exit loop
C14D 37 62 SCF ; Set carry flag
C14E C1 63 EXIT POP BC ; Restore registers
C14F D1 64 POP DE ;
C150 E1 65 POP HL ;
C151 C9 66 RET ; Return from routine
C152 AF 67 NOHIT XOR A ; Clear flags
C153 18F9 68 JR EXIT ; Go to EXIT
C155 69 ;
C155 70 ; Subroutine to read a byte from VRAM
C155 71 ;
C155 CD5000 72 RDVRM CALL SETRD ; Set screen location
C158 D898 73 IN A,(98H) ; Get value
C15A C9 74 RET ;
C15B 75 ;
76 END

 

 

 



Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! Mixx! Free and Open Source Software News Google! Live! StumbleUpon! Twitter! LinkedIn! TwitThis Joomla Free PHP

Last Updated (Tuesday, 09 June 2009 12:12)