Skip to navigation

Revs on the BBC Micro

Track geometry: GetSectionCoords

Name: GetSectionCoords [Show more] Type: Subroutine Category: Track geometry Summary: Copy two three-part 16-bit coordinates from the track section data Deep dive: Building a 3D track from sections and segments
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * GetFirstSegment calls GetSectionCoords

This routine is normally called with X as a multiple of 3 in the range 0 to 117, representing track segments 0 to 39. The routine copies the following track section coordinates from the track section data for section Y * 8: * xTrackSectionI * yTrackSectionI * zTrackSectionI and stores them in the X-th coordinate in (xSegmentCoordI, ySegmentCoordI, zSegmentCoordI). It also copies the following track section coordinates: * xTrackSectionO * yTrackSectionI * zTrackSectionO and stores them in the X-th coordinate in (xSegmentCoordO, ySegmentCoordO, zSegmentCoordO). Note that the y-coordinate is set to the same value as the y-coordinate from the first copy. It also sets thisVectorNumber to trackSectionFrom for the Y-th track section data. Specifically, this copies data from the Y-th track section entry: (xTrackSectionIHi xTrackSectionILo) (yTrackSectionIHi yTrackSectionILo) (zTrackSectionIHi zTrackSectionILo) (xTrackSectionOHi xTrackSectionOLo) (yTrackSectionIHi yTrackSectionILo) (zTrackSectionOHi zTrackSectionOLo) trackSectionFrom and stores it in the X-th track segment: (xSegmentCoordIHi xSegmentCoordILo) (ySegmentCoordIHi ySegmentCoordILo) (zSegmentCoordIHi zSegmentCoordILo) (xSegmentCoordOHi xSegmentCoordOLo) (ySegmentCoordOHi ySegmentCoordOLo) (zSegmentCoordOHi zSegmentCoordOLo) thisVectorNumber
Arguments: Y The number of the track section * 8 whose coordinates we want to fetch X The index * 3 of the track segment where we store the coordinates
.GetSectionCoords JSR GetSectionCoord \ Copy the following 16-bit coordinate: \ \ * The Y-th xTrackSectionI to the X-th xSegmentCoordI \ \ * The Y-th yTrackSectionI to the X-th ySegmentCoordI \ \ * The Y-th zTrackSectionI to the X-th zSegmentCoordI LDA xTrackSectionOLo,Y \ Copy the following 16-bit coordinate: STA xSegmentCoordOLo,X \ LDA zTrackSectionOLo,Y \ * The Y-th xTrackSectionO to the X-th xSegmentCoordO STA zSegmentCoordOLo,X \ \ * The Y-th zTrackSectionO to the X-th zSegmentCoordO \ \ starting with the low bytes LDA xTrackSectionOHi,Y \ And then the high bytes STA xSegmentCoordOHi,X LDA zTrackSectionOHi,Y STA zSegmentCoordOHi,X LDA trackSectionFrom,Y \ Set thisVectorNumber = the Y-th trackSectionFrom STA thisVectorNumber \ Fall through into CopySectionData to copy the \ following 16-bit coordinate: \ \ * The Y-th yTrackSectionI to the X-th ySegmentCoordO \ \ This works because the call to GetSectionCoord already \ stored the Y-th yTrackSectionI in the X-th \ ySegmentCoordI, and the following now copies that into \ the X-th ySegmentCoordO