Jump to content
IGNORED

sourcecode-structure (labelstyle)


Otto1980

Recommended Posts

Hi all,

while reading jaguarsourcecodes i found the great Crescent Galaxy :grin:

(i take game.s as an example)

 

i noticed that there are much numberd labels

(.05, .10, .20, .40, and so on... )

 

Now i wonder what or if those number-organized namings got a benefit :-o

is there a special logic in this labelmethod?

 

part of game.s

 

scrolling::
cmp.b #2,levstatus ;2 if scrolling after end of level
bne.b .10
cmp.w #END_LEVEL_DELAY,endlvdel ;there is a delay after the boss is destroyed
beq.b .05
add.w #1,endlvdel ;increase delay counter
rts
.05: addq.w #1,scrlspd ;if levstatus is 2, speed up scrolling
cmp.w #MAX_SCROLLSPD,scrlspd
blt.b .10
move.w #MAX_SCROLLSPD,scrlspd ;set maximum scrolling speed
.10: move.w odomend,d1 ;limit for odomback
move.w odomback,d0 ;current odometer reading
add.w scrlspd,d0 ;add background scrolling speed
cmp.w d1,d0 ;compare end to current odometer
bcs.b .40 ;branch if end > current
;at this point, the odometer has reached its limit
cmp.b #0,levstatus ;playing the level
beq.b .20 ;if odometer reached the first end point, set the second end point
cmp.b #1,levstatus ;already stopped at first stop position
beq.b .60 ;if scrolling has stopped, exit
cmp.b #2,levstatus ;scrolling fast to get to second end point
bne.b .20
move.b #1,levflag ;change level at end of loop
rts
.20: move.b #1,levstatus ;now at first stop point
lea od_end1,a0 ;list of the first end points
lea od_end2,a1 ;list of the end points after level is completed
move.w level,d0 ;get current level
lsl.w #1,d0 ;level * 2
move.w (a0,d0.w),odomback ;set stopped odometer position
move.w (a1,d0.w),odomend ;get new odometer end
clr.w scrlspd ;0 speed until enemies are gone
clr.w scrlspdf ;stop foreground scrolling
rts
.40: move.w d0,odomback ;update new odometer reading
move.w odomfrnt,d0
add.w scrlspdf,d0 ;update foreground odometer
cmp.w #MAX_ODOM_FRONT,d0
bcs.b .50
move.w #MAX_ODOM_FRONT,d0
.50: move.w d0,odomfrnt
.60: rts

 

greets to all

Edited by Otto1980
Link to comment
Share on other sites

Symbols prefaced with a period (".") are local labels, which means that you can have multiple labels with the same name in between regular labels (labels with no period in front).

 

As far as those coders using numbers for their local labels, I'm pretty sure that's purely a matter of style and nothing more. The only way to know for sure would be to contact those guys and ask them why they did it that way. :)

  • Like 2
Link to comment
Share on other sites


CREDCODE rts

MOVE.B #$F8,FADEDIR ;start fade
CLR.B FADEVAL

.WFF
JSR WVBL
JSR FADER
MOVE.B FADEVAL,D0
AND.B #$F0,D0
BNE .WFF

clr.w d0 ;blank the screen
jsr SegaFader

MOVE.B #4,NMIVECSEL

move.l #W6BGC,A0
LEA MAPBASE,A1
JSR file_load


move.l #W6BGM,A0
LEA MAPBASE,A1
JSR file_load

LEA CREDCHAR,A0
LEA MAPBASE,A1
JSR file_load

move.l #CREDPAL,CurPal
clr.w d0
jsr SegaFader

CLR WINDX
CLR WINDY
CLR STIMER

CLR.B FADEVAL ;init fader
MOVE.B #4,FADEDIR

MOVE.B #2,NMIVECSEL

CLR TEMP9
CLR TEMP7

CLR D0
JSR LOADSCREEN_CREDITS ;if titleseq end begin again

MOVE #1,D0
JSR STARTMUSIC ;start music

PRELOOP_CREDITS
JSR WVBL

ADDQ #1,STIMER ;handle clock

JSR FADER ;fade in

JSR GETINPUT ;wait for player to let go of start button

MOVE STICK1,D0 ;in the title screen and edgestick
OR STICK2,D0 ;hold or'ed values of both controllers
MOVE D0,STICK
MOVE EDGESTICK1,D0
OR EDGESTICK2,D0
MOVE D0,EDGESTICK

MOVE STICK,D0
AND #JOY_START,D0
BNE PRELOOP_CREDITS

TITLELOOP_CREDITS
ADDQ #1,STIMER ;handle the clock
JSR FADER ;fade in
JSR GETINPUT ;wait for a start button press

MOVE STICK1,D0
OR STICK2,D0
MOVE D0,STICK
MOVE EDGESTICK1,D0
OR EDGESTICK2,D0
MOVE D0,EDGESTICK

MOVE EDGESTICK,D0
AND #JOY_SELECT+JOY_START,D0
BEQ .NOINPUT
MOVE.B #-8,FADEDIR
MOVE FADEOUTSOUND,D0
JSR STARTSOUND
.NOINPUT
MOVE WINDX,D0 ;joy or buttons start screen change
CMP TEMP9,D0
BNE .NOSEL1
MOVE EDGESTICK,D0
AND #JOY_RIGHT+JOY_UP,D0
BEQ .NOSEL0
SUB #$100,TEMP9
SUB #1,TEMP7
AND #3,TEMP7
MOVE TEMP7,D0
JSR LOADSCREEN_CREDITS
.NOSEL0
MOVE EDGESTICK,D0
AND #JOY_LEFT+JOY_DOWN,D0
BEQ .NOSEL1
ADD #$100,TEMP9
ADD #1,TEMP7
AND #3,TEMP7
MOVE TEMP7,D0
JSR LOADSCREEN_CREDITS
.NOSEL1

MOVE WINDX,D0
CMP TEMP9,D0
BEQ .NOSCROLL
BMI .SCROLLRIGHT
SUBQ #2,WINDX
BRA .NOSCROLL
.SCROLLRIGHT
ADDQ #2,WINDX
.NOSCROLL
TST.B FADEDIR ;if totally faded then bail
BNE .NOEXIT
MOVE.B FADEVAL,D0
AND.B #$F0,D0
BEQ EXIT_CREDITS
.NOEXIT
JSR WVBL
JMP TITLELOOP_CREDITS

;;;ASB:
;;;ASB: ; ******************************* AND WE'RE OUT OF THERE
;;;ASB:

EXIT_CREDITS ;blank the screen and exit
clr.w d0
jsr SegaFader

JSR KILLSOUND
RTS

LOADSCREEN_CREDITS
andi.w #$00ff,d0
asl.w #2,d0
lea CREDSCREENS,a1
move.l (a1,d0.w),A0
LEA MAPBASE,A1
JSR file_load

rts


CREDCHAR
dc.b "CREDCHRM.PP",0
CREDPAL
dc.b "CREDPAL.PP",0
CREDM00
dc.b "CREDM00.PP",0
CREDM01
dc.b "CREDM01.PP",0
CREDM02
dc.b "CREDM02.PP",0
CREDM03
dc.b "CREDM03.PP",0

CREDSCREENS
DC.L CREDM00
DC.L CREDM03
DC.L CREDM02
DC.L CREDM01

Edited by Seedy1812
Link to comment
Share on other sites

It actually code from Bubsy on the Jaguar Sometimes you inherit coding style from previous people / projects / companies. In assembler its better to have labels which mean something rather than numbers. As with all code after a few months you come back to try to fix a bug and its much easier when the code is easier to read. I had the Sega Genesis code to base the game on.

Edited by Seedy1812
  • Like 3
Link to comment
Share on other sites

Here's another example for I-War

********************** Calculate 3D Shapes With The GPU **********************

* Notes:

* These routines add polygons to the polygon list
* This list will need to be drawn separately

* They also set the rotated and projected
* coordinates in the object structure

* Before use:
* Put a pointer to the 3D point buffer in 'shapepoints'
* Put a pointer to the polygon buffer in 'nextpolygon'
* Put the screen clip limits in 'clx,cly,chx,chy'
* Put the graphics origin in 'gox,goy'

* For each view:
* Put the view position in 'viewxcoord,ycoord,zcoord'
* Put the view orientation in 'viewxx,xy,xz,yx,yy,yz,zx,zy,zz'
* Put the view limits in 'viewlx,ly,lz,viewhx,hy,hz'

* For each shape list:
* Put a pointer to the shape list in 'shapelist'

* Long variables must precede any words or bytes
* and must be longword aligned

* For the Gouraud shading
* To make the maths a bit easier
* The lightsource is at (0,0,16384)
* And the gouraud vectors have unit length
* So that means the cosine of the angle between
* the lightsource vector and the gouraud vector
* is simply the gouraud z!

************************** Initialise Shape Routines *************************

	text
	.68000

initshapes:	move.l	#pointbuffer,shapepoints
		rts

*************************** Draw A List Of Shapes ****************************

	phrase
shapes:
	.gpu
	org	gpuprog

	movei	#shapelist,r0			;get list object
	load	(r0),r0

	moveq	#ifirst,r1			;get first object
	add	r0,r1
	load	(r1),r0
	movei	#donelist,r1
	cmpq	#0,r0				;make sure the list
	jump	eq,(r1)				;is not empty
	nop
nextshape:
	movei	#doneshape,r9

	movei	#isxrotated,r5			;flag the object as not
	movei	#isboundlx,r6			;rotated or projected
	movei	#$7fffffff,r7			;initially
	add	r0,r5
	add	r0,r6
	store	r7,(r5)
	store	r7,(r6)

	moveq	#isanimbase,r2			;check there is a
	add	r0,r2				;shape to draw
	load	(r2),r2
	cmpq	#0,r2
	jump	eq,(r9)
	nop

	movei	#isxcoord,r8			;get shape's coords
	add	r0,r8
	load	(r8),r2
	addq	#4,r8
	load	(r8),r3
	addq	#4,r8
	load	(r8),r4

	movei	#viewlx,r8			;check that the shape
	load	(r8),r10			;is inside the view cube
	cmp	r2,r10				;check viewlx
	jump	pl,(r9)
	addq	#4,r8

	load	(r8),r10			;check viewly
	cmp	r3,r10
	jump	pl,(r9)
	addq	#4,r8

	load	(r8),r10			;check viewlz
	cmp	r4,r10
	jump	pl,(r9)
	addq	#4,r8

	load	(r8),r10			;check viewhx
	cmp	r10,r2
	jump	pl,(r9)
	addq	#4,r8

	load	(r8),r10			;check viewhy
	cmp	r10,r3
	jump	pl,(r9)
	addq	#4,r8

	load	(r8),r10			;check viewhz
	cmp	r10,r4
	jump	pl,(r9)
	nop

	movei	#isonscreen,r9			;flag the object as onscreen
	add	r0,r9
	moveq	#1,r5
	storew	r5,(r9)

	movei	#viewxcoord,r9			;subtract viewcoords
	load	(r9),r5
	addq	#4,r9
	load	(r9),r6
	addq	#4,r9
	load	(r9),r7
	sub	r5,r2
	sub	r6,r3
	sub	r7,r4

	movei	#viewxx,r14			;get inverse view matrix
	load	(r14),r5			;by reflecting the view
	addq	#4,r14				;matrix across the leading
	load	(r14),r8			;diagonal
	addq	#4,r14
	load	(r14),r11
	addq	#4,r14
	load	(r14),r6
	addq	#4,r14
	load	(r14),r9
	addq	#4,r14
	load	(r14),r12
	addq	#4,r14
	load	(r14),r7
	addq	#4,r14
	load	(r14),r10
	addq	#4,r14
	load	(r14),r13

	imultn	r2,r5				;rotate shape's coords
	imacn	r3,r8				;with the inverse view matrix
	imacn	r4,r11
	resmac	r14
	imultn	r2,r6
	imacn	r3,r9
	imacn	r4,r12
	resmac	r15
	imultn	r2,r7
	imacn	r3,r10
	imacn	r4,r13
	resmac	r16
	sharq	#14,r14
	sharq	#14,r15
	sharq	#14,r16
	move	r14,r2
	move	r15,r3
	move	r16,r4

	movei	#isxrotated,r1			;store rotated coordinates
	add	r0,r1
	store	r2,(r1)				;for Seedy's radar
	addq	#4,r1
	store	r3,(r1)
	addq	#4,r1
	store	r4,(r1)

	moveq	#isanimbase,r1			;get the shape definition
	movei	#isanimframe,r15
	add	r0,r1
	add	r0,r15
	load	(r1),r1
	load	(r15),r15
	shlq	#2,r15
	add	r15,r1
	load	(r1),r1
	addq	#2,r1

	loadw	(r1),r14			;get shape size and
	addq	#2,r1				;do the screen reject
	movei	#doneshape,r15

	move	r4,r16				;finish if object is
	add	r14,r16				;in front of view plane
	jump	mi,(r15)
	nop

	movei	#-100000,r16			;finish if object is
	sub	r4,r16				;behind view plane
	add	r14,r16
	jump	pl,(r15)
	nop

	move	r2,r17				;have to check against
	move	r3,r18				;view planes
	move	r4,r19

	movei	#16384,r20
.vshrink:
	cmp	r19,r20
	jr	pl,.vshrunk
	nop
	sharq	#4,r17
	sharq	#4,r18
	sharq	#4,r19
	jr	t,.vshrink
.vshrunk:
	add	r14,r19
	movei	#1<<persp,r20

	cmpq	#0,r17				;left or right?
	jr	pl,.right
	nop
.left:
	add	r14,r17				;check against left plane
	movei	#clx,r16
	load	(r16),r16
	imult	r20,r17
	imult	r19,r16
	sub	r16,r17
	jump	mi,(r15)
	nop
	jr	t,.hok
	nop
.right:
	sub	r14,r17				;check against right plane
	movei	#chx,r16
	load	(r16),r16
	imult	r20,r17
	imult	r19,r16
	sub	r17,r16
	jump	mi,(r15)
.hok:
	cmpq	#0,r18				;top or bottom?
	jr	pl,.top
	nop
.bottom:
	add	r14,r18				;check against bottom plane
	movei	#cly,r16
	load	(r16),r16
	imult	r20,r18
	imult	r19,r16
	sub	r16,r18
	jump	mi,(r15)
	nop
	jr	t,.vok
	nop
.top:
	sub	r14,r18				;check against top plane
	movei	#chy,r16
	load	(r16),r16
	imult	r20,r18
	imult	r19,r16
	sub	r18,r16
	jump	mi,(r15)
	nop
.vok:

	move	r2,r17				;calculate projected bounding
	move	r3,r18				;box for this object
	move	r4,r19
	movei	#16384,r21
.oshrink:
	cmp	r19,r21
	jr	pl,.oshrunk
	nop
	sharq	#1,r14
	sharq	#1,r17
	sharq	#1,r18
	sharq	#1,r19
	jr	t,.oshrink
	nop
.oshrunk:
	shlq	#persp,r14			;perspective on radius
	abs	r14
	div	r19,r14
	jr	cs,.rypos
	neg	r14
	neg	r14
.rypos:
	shlq	#persp,r17			;perspective on x
	abs	r17
	div	r19,r17
	jr	cs,.oxpos
	neg	r17
	neg	r17
.oxpos:
	shlq	#persp,r18			;perspective on y
	abs	r18
	div	r19,r18
	jr	cs,.oypos
	neg	r18
	neg	r18
.oypos:
	movei	#isboundlx,r22		      	;save bounding box
	add	r0,r22				;for seedy's targetting
	sharq	#1,r14
	sub	r14,r17
	sub	r14,r18
	store	r17,(r22)			;save low limits
	addq	#4,r22
	store	r18,(r22)
	addq	#4,r22
	add	r14,r14
	add	r14,r17
	add	r14,r18
	store	r17,(r22)			;save high limits
	addq	#4,r22
	store	r18,(r22)

	movei	#isxx,r23			;multiply shape matrix
	add	r0,r23				;with inverse view matrix
	loadw	(r23),r14
	addq	#2,r23
	loadw	(r23),r15
	addq	#2,r23
	loadw	(r23),r16
	addq	#2,r23
	loadw	(r23),r17
	addq	#2,r23
	loadw	(r23),r18
	addq	#2,r23
	loadw	(r23),r19
	addq	#2,r23
	loadw	(r23),r20
	addq	#2,r23
	loadw	(r23),r21
	addq	#2,r23
	loadw	(r23),r22

	imultn	r14,r5				;xx
	imacn	r15,r8
	imacn	r16,r11
	resmac	r23
	moveta	r23,r14
	imultn	r14,r6				;xy
	imacn	r15,r9
	imacn	r16,r12
	resmac	r23
	moveta	r23,r15
	imultn	r14,r7				;xz
	imacn	r15,r10
	imacn	r16,r13
	resmac	r23
	moveta	r23,r16

	imultn	r17,r5				;yx
	imacn	r18,r8
	imacn	r19,r11
	resmac	r23
	moveta	r23,r17
	imultn	r17,r6				;yy
	imacn	r18,r9
	imacn	r19,r12
	resmac	r23
	moveta	r23,r18
	imultn	r17,r7				;yz
	imacn	r18,r10
	imacn	r19,r13
	resmac	r23
	moveta	r23,r19

	imultn	r20,r5				;zx
	imacn	r21,r8
	imacn	r22,r11
	resmac	r23
	moveta	r23,r20
	imultn	r20,r6				;zy
	imacn	r21,r9
	imacn	r22,r12
	resmac	r23
	moveta	r23,r21
	imultn	r20,r7				;zz
	imacn	r21,r10
	imacn	r22,r13
	resmac	r23
	moveta	r23,r22

	movefa	r14,r5				;get result back
	movefa	r15,r6
	movefa	r16,r7
	movefa	r17,r8
	movefa	r18,r9
	movefa	r19,r10
	movefa	r20,r11
	movefa	r21,r12
	movefa	r22,r13
	sharq	#14,r5
	sharq	#14,r6
	sharq	#14,r7
	sharq	#14,r8
	sharq	#14,r9
	sharq	#14,r10
	sharq	#14,r11
	sharq	#14,r12
	sharq	#14,r13

	move	r16,r20
	move	r19,r21

	loadw	(r1),r28			;get number of points
	addq	#2,r1
	movei	#shapepoints,r29
	load	(r29),r29
.dopoints:
	loadw	(r1),r14			;get the unrotated point
	addq	#2,r1
	loadw	(r1),r16
	addq	#2,r1
	loadw	(r1),r15
	addq	#2,r1

	loadw	(r1),r17			;get the unrotated
	addq	#2,r1				;gouraud vector
	loadw	(r1),r18
	addq	#2,r1
	loadw	(r1),r19
	addq	#2,r1
	or	r19,r19

	imultn	r14,r5				;rotate the point
	imacn	r15,r8
	imacn	r16,r11
	resmac	r23
	imultn	r14,r6
	imacn	r15,r9
	imacn	r16,r12
	resmac	r24
	imultn	r14,r7
	imacn	r15,r10
	imacn	r16,r13
	resmac	r25
	sharq	#14,r23
	sharq	#14,r24
	sharq	#14,r25

	add	r2,r23				;add on shape's origin
	add	r3,r24
	add	r4,r25

	imultn	r17,r20				;rotate the gouraud vector
	imacn	r18,r21
	imacn	r19,r22
	resmac	r26
	sharq	#14,r26

	movei	#13184,r27			;scale the cosine
	imult	r27,r26				;can be +- 104
	sharq	#14+7,r26			;for max intensity $e7
	movei	#$80,r27			;or min intensity $18
	add	r27,r26

	movei	#6000+4096,r20			;depth cue the intensity
	sub	r25,r20
	cmpq	#0,r20
	jr	pl,.notsmall
	nop
	moveq	#0,r20
.notsmall:
	movei	#4096,r21
	cmp	r20,r21
	jr	pl,.notbig
	nop
	move	r21,r20
.notbig:
	shrq	#4,r20
	movei	#$18,r22
	sub	r22,r26
	imult	r20,r26
	shrq	#8,r26
	add	r22,r26

	store	r23,(r29)			;store the result
	addq	#4,r29
	store	r24,(r29)
	addq	#4,r29
	store	r25,(r29)
	addq	#4,r29
	store	r26,(r29)
	addq	#4,r29

	movei	#.dopoints,r14			;move onto next point
	subq	#1,r28
	jump	ne,(r14)
	nop

	loadw	(r1),r2				;get number of surfaces
	addq	#2,r1
	movei	#shapepoints,r3			;pointer to surface points
	movei	#nextshaded,r4			;pointer to polygon
	movei	#nexttextured,r31
	load	(r3),r3
	load	(r4),r4
	load	(r31),r31
dosurfaces:
	move	r1,r14				;calculate surface normal
	addq	#4,r14
	loadw	(r14),r15
	addq	#2,r14
	loadw	(r14),r16
	addq	#2,r14
	loadw	(r14),r17
	shlq	#4,r15
	shlq	#4,r16
	shlq	#4,r17
	add	r3,r15
	add	r3,r16
	add	r3,r17
	load	(r15),r5			;get point 0
	addq	#4,r15
	load	(r15),r6
	addq	#4,r15
	load	(r15),r7
	load	(r16),r8			;get point 1
	addq	#4,r16
	load	(r16),r9
	addq	#4,r16
	load	(r16),r10
	load	(r17),r11			;get point 2
	addq	#4,r17
	load	(r17),r12
	addq	#4,r17
	load	(r17),r13
	or	r13,r13

	sub	r8,r11				;get vector from
	sub	r9,r12				;point 1 to point 2
	sub	r10,r13
	sub	r5,r8				;get vector from
	sub	r6,r9				;point 0 to point 1
	sub	r7,r10
	movei	#1<<persp,r14			;get vector from
	add	r14,r7				;viewpoint to point 0

	move	r10,r14				;get surface normal
	move	r8,r15				;using cross product
	move	r9,r16
	neg	r14
	neg	r15
	neg	r16
	imultn	r9,r13				;normal x
	imacn	r12,r14
	resmac	r14
	imultn	r10,r11				;normal y
	imacn	r13,r15
	resmac	r15
	imultn	r8,r12				;normal z
	imacn	r11,r16
	resmac	r16

	movei	#16384,r8			;shrink the normal vector
.s1:
	cmp	r14,r8				;I know this looks awful
	jr	pl,.s2				;but it has to be done...
	nop
	sharq	#4,r14
	sharq	#4,r15
	sharq	#4,r16
	jr	t,.s1
.s2:
	cmp	r15,r8
	jr	pl,.s3
	nop
	sharq	#4,r14
	sharq	#4,r15
	sharq	#4,r16
	jr	t,.s2
.s3:
	cmp	r16,r8
	jr	pl,.s4
	nop
	sharq	#4,r14
	sharq	#4,r15
	sharq	#4,r16
	jr	t,.s3
	nop
.s4:
	neg	r8
.s5:
	cmp	r8,r14
	jr	pl,.s6
	nop
	sharq	#4,r14
	sharq	#4,r15
	sharq	#4,r16
	jr	t,.s5
.s6:
	cmp	r8,r15
	jr	pl,.s7
	nop
	sharq	#4,r14
	sharq	#4,r15
	sharq	#4,r16
	jr	t,.s6
.s7:
	cmp	r8,r16
	jr	pl,.s8
	nop
	sharq	#4,r14
	sharq	#4,r15
	sharq	#4,r16
	jr	t,.s7
	nop
.s8:
	neg	r8
.s9:
	cmp	r5,r8				;shrink the view vector
	jr	pl,.s10
	nop
	sharq	#4,r5
	sharq	#4,r6
	sharq	#4,r7
	jr	t,.s9
.s10:
	cmp	r6,r8
	jr	pl,.s11
	nop
	sharq	#4,r5
	sharq	#4,r6
	sharq	#4,r7
	jr	t,.s10
.s11:
	cmp	r7,r8
	jr	pl,.s12
	nop
	sharq	#4,r5
	sharq	#4,r6
	sharq	#4,r7
	jr	t,.s11
	nop
.s12:
	neg	r8
.s13:
	cmp	r8,r5
	jr	pl,.s14
	nop
	sharq	#4,r5
	sharq	#4,r6
	sharq	#4,r7
	jr	t,.s13
.s14:
	cmp	r8,r6
	jr	pl,.s15
	nop
	sharq	#4,r5
	sharq	#4,r6
	sharq	#4,r7
	jr	t,.s14
.s15:
	cmp	r8,r7
	jr	pl,.s16
	nop
	sharq	#4,r5
	sharq	#4,r6
	sharq	#4,r7
	jr	t,.s15
	nop
.s16:
	movei	#isblowup,r17			;if the object is exploding
	add	r0,r17				;we don't need to check visibility
	loadw	(r17),r17
	cmpq	#0,r17
	movei	#visible,r22
	jump	ne,(r22)
	nop

	imultn	r5,r14				;check the visiblity
	imacn	r6,r15				;using scalar product
	imacn	r7,r16
	resmac	r5
	cmpq	#0,r5
	jump	pl,(r22)
	nop
	addq	#2,r1				;surface is invisible so
	loadw	(r1),r5				;skip past to the next one
	addq	#2,r1
	shlq	#1,r5
	add	r5,r1
	movei	#nextsurf,r5
	jump	t,(r5)
	nop
visible:
	loadw	(r1),r5				;get surfaces' colour
	addq	#2,r1

	movei	#texturesoff,r28		;do all surfaces as
	loadb	(r28),r29			;shaded if textures are off
	cmpq	#0,r29
	jr	eq,shadedsurface
	nop

	movei	#$c000,r28			;should we calculate
	and	r5,r28				;a textured surface?
	movei	#texturedmode,r29
	cmp	r29,r28
	movei	#texturedsurface,r29
	jump	eq,(r29)
	nop

*************************** Calculate A Shaded Surface ***********************

shadedsurface:
	loadw	(r1),r6				;get number of points
	addq	#2,r1				;in this surface
	moveq	#0,r7				;clear points in polygon

	move	r4,r8				;pointer to polygon points
	addq	#8,r8				;room for colour and numpoints

	move	r14,r25				;calc explosion vector
	move	r15,r26
	move	r16,r27
	imult	r17,r25
	imult	r17,r26
	imult	r17,r27
	sharq	#8,r25
	sharq	#8,r26
	sharq	#8,r27
	neg	r25
	neg	r26
	neg	r27

	move	r1,r29				;get last point to
	add	r6,r29				;link with first point
	add	r6,r29
	subq	#2,r29
	loadw	(r29),r29
	shlq	#4,r29
	add	r3,r29
	load	(r29),r14
	addq	#4,r29
	load	(r29),r15
	addq	#4,r29
	load	(r29),r16
	addq	#4,r29
	load	(r29),r17
	or	r17,r17
	add	r25,r14				;add on explosion vector
	add	r26,r15
	add	r27,r16

.dosurface:
	move	r14,r9				;copy end point to start
	move	r15,r10
	move	r16,r11
	move	r17,r12

	loadw	(r1),r29			;get new end point
	addq	#2,r1
	shlq	#4,r29
	add	r3,r29
	load	(r29),r14
	addq	#4,r29
	load	(r29),r15
	addq	#4,r29
	load	(r29),r16
	addq	#4,r29
	load	(r29),r17
	or	r17,r17
	add	r25,r14				;add on explosion vector
	add	r26,r15
	add	r27,r16

	cmpq	#0,r11				;is startpoint off?
	jr	pl,.startok
	cmpq	#0,r16				;is the endpoint off too?
	movei	#.calcnew,r29
	jump	pl,(r29)
	nop
	movei	#.nextpoint,r29			;it is so skip this point
	jump	t,(r29)
.startok:
	move	r9,r19				;save the start point
	move	r10,r20
	move	r11,r22
	movei	#1<<persp,r28
	add	r11,r28

	movei	#16384,r29
.pshrink:
	cmp	r28,r29
	jr	pl,.pshrunk
	nop
	sharq	#1,r19
	sharq	#1,r20
	sharq	#1,r28
	jr	t,.pshrink
	nop
.pshrunk:
	shlq	#persp,r19			;perspective on x
	abs	r19
	div	r28,r19
	jr	cs,.pxpos
	neg	r19
	neg	r19
.pxpos:
	shlq	#persp,r20			;perspective on y
	abs	r20
	div	r28,r20
	jr	cs,.pypos
	neg	r20
	neg	r20
.pypos:
	store	r19,(r8)			;save x,y,z to polygon buffer
	addq	#4,r8
	store	r20,(r8)
	addq	#4,r8
	store	r22,(r8)
	addq	#4,r8
	store	r12,(r8)
	addq	#4,r8
	addq	#1,r7				;another point in polygon

	movei	#.nextpoint,r29			;if the end point is
	cmpq	#0,r16				;off we'll need to
	jump	pl,(r29)			;calculate a new point
	nop
.calcnew:
	cmp	r11,r16
	movei	#.calcout,r29
	jump	pl,(r29)
.calcin:
	move	r9,r19				;get dx,dy,dz,di
	move	r10,r20
	move	r11,r21
	move	r12,r22
	sub	r14,r19
	sub	r15,r20
	sub	r16,r21
	sub	r17,r22

	imult	r16,r19				;calculate cx
	abs	r19
	div	r21,r19
	jr	cc,.cxneg1
	neg	r19
	neg	r19
.cxneg1:
	imult	r16,r20				;calculate cy
	abs	r20
	div	r21,r20
	jr	cc,.cyneg1
	neg	r20
	neg	r20
.cyneg1:
	imult	r16,r22				;calculate ci
	abs	r22
	div	r21,r22
	jr	cc,.cineg1
	neg	r22
	neg	r22
.cineg1:
	add	r14,r19
	add	r15,r20
	add	r17,r22
	movei	#.savepoint,r29
	jump	t,(r29)
	nop
.calcout:
	move	r14,r19				;get dx,dy,dz,di
	move	r15,r20
	move	r16,r21
	move	r17,r22
	sub	r9,r19
	sub	r10,r20
	sub	r11,r21
	sub	r12,r22

	imult	r11,r19				;calculate cx
	abs	r19
	div	r21,r19
	jr	cc,.cxneg2
	neg	r19
	neg	r19
.cxneg2:
	imult	r11,r20				;calculate cy
	abs	r20
	div	r21,r20
	jr	cc,.cyneg2
	neg	r20
	neg	r20
.cyneg2:
	imult	r11,r22				;calculate ci
	abs	r22
	div	r21,r22
	jr	cc,.cineg2
	neg	r22
	neg	r22
.cineg2:
	add	r9,r19
	add	r10,r20
	add	r12,r22

.savepoint:
	moveq	#0,r21				;store the result
	store	r19,(r8)
	addq	#4,r8
	store	r20,(r8)
	addq	#4,r8
	store	r21,(r8)
	addq	#4,r8
	store	r22,(r8)
	addq	#4,r8

	addq	#1,r7				;another point in polygon
.nextpoint:
	movei	#.dosurface,r29			;move onto next
	subq	#1,r6				;point in surface
	jump	ne,(r29)

	cmpq	#3,r7				;check if there are
	movei	#nextsurf,r6			;enough points left
	jump	mi,(r6)
	nop
	store	r7,(r4)				;put the polygon
	addq	#4,r4				;in the list
	store	r5,(r4)
	move	r8,r4

	movei	#numshaded,r29			;increment shaded polygon count
	load	(r29),r28
	addq	#1,r28
	store	r28,(r29)

	jump	t,(r6)
	nop

************************** Calculate A Textured Surface **********************

texturedsurface:
	movei	#$3fff,r30			;mask off surface mode bits
	and	r30,r5
	shlq	#2,r5
	movei	#textures,r30
	add	r5,r30
	load	(r30),r30			;r30 points at the texture
	or	r30,r30
	load	(r30),r5			;get pixelmap
	addq	#4,r30

	loadw	(r1),r6				;get number of points
	addq	#2,r1				;in this surface
	moveq	#0,r7				;clear points in polygon

	move	r31,r8				;pointer to polygon points
	addq	#8,r8				;room for colour and numpoints

	move	r14,r25				;calc explosion vector
	move	r15,r26
	move	r16,r27
	imult	r17,r25
	imult	r17,r26
	imult	r17,r27
	sharq	#8,r25
	sharq	#8,r26
	sharq	#8,r27
	neg	r25
	neg	r26
	neg	r27

	move	r1,r29				;get last point to
	add	r6,r29				;link with first point
	add	r6,r29
	subq	#2,r29
	loadw	(r29),r29
	shlq	#4,r29
	add	r3,r29

	move	r6,r28
	subq	#1,r28
	shlq	#3,r28
	add	r30,r28

	load	(r29),r14
	addq	#4,r29
	load	(r29),r15
	addq	#4,r29
	load	(r29),r16
	load	(r28),r17
	addq	#4,r28
	load	(r28),r18
	or	r18,r18
	add	r25,r14				;add on explosion vector
	add	r26,r15
	add	r27,r16

.dosurface:
	move	r14,r9				;copy end point to start
	move	r15,r10
	move	r16,r11
	move	r17,r12
	move	r18,r13

	loadw	(r1),r29			;get new end point
	addq	#2,r1
	shlq	#4,r29
	add	r3,r29
	load	(r29),r14			;get 3d coordinates
	addq	#4,r29
	load	(r29),r15
	addq	#4,r29
	load	(r29),r16
	load	(r30),r17			;get texture coordinates
	addq	#4,r30
	load	(r30),r18
	addq	#4,r30
	or	r18,r18
	add	r25,r14				;add on explosion vector
	add	r26,r15
	add	r27,r16

	cmpq	#0,r11				;is startpoint off?
	jr	pl,.startok
	cmpq	#0,r16				;is the endpoint off too?
	movei	#.calcnew,r29
	jump	pl,(r29)
	nop
	movei	#.nextpoint,r29			;it is so skip this point
	jump	t,(r29)
.startok:
	move	r9,r19				;save the start point
	move	r10,r20
	move	r11,r22
	movei	#1<<persp,r28
	add	r11,r28

	movei	#16384,r29
.pshrink:
	cmp	r28,r29
	jr	pl,.pshrunk
	nop
	sharq	#1,r19
	sharq	#1,r20
	sharq	#1,r28
	jr	t,.pshrink
	nop
.pshrunk:
	shlq	#persp,r19			;perspective on x
	abs	r19
	div	r28,r19
	jr	cs,.pxpos
	neg	r19
	neg	r19
.pxpos:
	shlq	#persp,r20			;perspective on y
	abs	r20
	div	r28,r20
	jr	cs,.pypos
	neg	r20
	neg	r20
.pypos:
	store	r19,(r8)			;save x,y,z to polygon buffer
	addq	#4,r8
	store	r20,(r8)
	addq	#4,r8
	store	r22,(r8)
	addq	#4,r8
	store	r12,(r8)
	addq	#4,r8
	store	r13,(r8)
	addq	#4,r8
	addq	#1,r7				;another point in polygon

	movei	#.nextpoint,r29			;if the end point is
	cmpq	#0,r16				;off we'll need to
	jump	pl,(r29)			;calculate a new point
.calcnew:
	cmp	r11,r16
	movei	#.calcout,r29
	jump	pl,(r29)
.calcin:
	move	r9,r19				;get dx,dy,dz,di
	move	r10,r20
	move	r11,r21
	move	r12,r22
	move	r13,r23
	sub	r14,r19
	sub	r15,r20
	sub	r16,r21
	sub	r17,r22
	sub	r18,r23

	imult	r16,r19				;calculate cx
	abs	r19
	div	r21,r19
	jr	cc,.cxneg1
	neg	r19
	neg	r19
.cxneg1:
	imult	r16,r20				;calculate cy
	abs	r20
	div	r21,r20
	jr	cc,.cyneg1
	neg	r20
	neg	r20
.cyneg1:
	imult	r16,r22				;calculate ctx
	abs	r22
	div	r21,r22
	jr	cc,.ctxneg1
	neg	r22
	neg	r22
.ctxneg1:
	imult	r16,r23				;calculate cty
	abs	r23
	div	r21,r23
	jr	cc,.ctyneg1
	neg	r23
	neg	r23
.ctyneg1:
	add	r14,r19
	add	r15,r20
	add	r17,r22
	add	r18,r23
	movei	#.savepoint,r29
	jump	t,(r29)
	nop
.calcout:
	move	r14,r19				;get dx,dy,dz,di
	move	r15,r20
	move	r16,r21
	move	r17,r22
	move	r18,r23
	sub	r9,r19
	sub	r10,r20
	sub	r11,r21
	sub	r12,r22
	sub	r13,r23

	imult	r11,r19				;calculate cx
	abs	r19
	div	r21,r19
	jr	cc,.cxneg2
	neg	r19
	neg	r19
.cxneg2:
	imult	r11,r20				;calculate cy
	abs	r20
	div	r21,r20
	jr	cc,.cyneg2
	neg	r20
	neg	r20
.cyneg2:
	imult	r11,r22				;calculate ctx
	abs	r22
	div	r21,r22
	jr	cc,.ctxneg2
	neg	r22
	neg	r22
.ctxneg2:
	imult	r11,r23				;calculate cty
	abs	r23
	div	r21,r23
	jr	cc,.ctyneg2
	neg	r23
	neg	r23
.ctyneg2:
	add	r9,r19
	add	r10,r20
	add	r12,r22
	add	r13,r23

.savepoint:
	moveq	#0,r21				;store the result
	store	r19,(r8)
	addq	#4,r8
	store	r20,(r8)
	addq	#4,r8
	store	r21,(r8)
	addq	#4,r8
	store	r22,(r8)
	addq	#4,r8
	store	r23,(r8)
	addq	#4,r8

	addq	#1,r7				;another point in polygon
.nextpoint:
	movei	#.dosurface,r29			;move onto next
	subq	#1,r6				;point in surface
	jump	ne,(r29)

	cmpq	#3,r7				;check if there are
	jr	mi,nextsurf			;enough points left
	nop
	store	r7,(r31)			;put the polygon
	addq	#4,r31				;in the list
	store	r5,(r31)
	move	r8,r31

	movei	#numtextured,r29		;increment textured polygon count
	load	(r29),r28
	addq	#1,r28
	store	r28,(r29)

nextsurf:
	movei	#dosurfaces,r6			;move onto
	subq	#1,r2				;next surface
	jump	ne,(r6)
	nop

donesurfs:
	movei	#nextshaded,r1			;finished that shape
	movei	#nexttextured,r2
	store	r4,(r1)
	store	r31,(r2)

doneshape:
	moveq	#inext,r1			;go onto next shape
	add	r0,r1
	load	(r1),r0
	movei	#nextshape,r1
	cmpq	#0,r0				;check for end of list
	jump	ne,(r1)
	nop

donelist:
	moveq	#8,r0				;stop gpu
	movei	#G_CTRL,r1
	store	r0,(r1)
.halt:
	jr	t,.halt
	nop

	.68000

endshapes:

******************************* Data Section *********************************

	data

******************************** Variables ***********************************

	even

gpushapes:
	dc.l	shapes,gpuprog,endshapes-shapes

******************************* BSS Section **********************************

	bss

*************************** Shape Point Buffer *******************************

	phrase
pointbuffer:
	ds.b	maxpoints*16			;rotated point buffer

numshaded:
	ds.l	1
numtextured:
	ds.l	1

texturesoff:
	ds.b	1



Link to comment
Share on other sites

It actually code from Bubsy on the Jaguar Sometimes you inherit coding style from previous people / projects / companies. In assembler its better to have labels which mean something rather than numbers. As with all code after a few months you come back to try to fix a bug and its much easier when the code is easier to read. I had the Sega Genesis code to base the game on.

 

Don't go mentioning you got the code for Bubsy. DrClu will start humping your leg and things will get nutty fast.

Edited by JagChris
Link to comment
Share on other sites

Non clean coding give you two avantages :

 

- that was harder for ripper to use your code

 

- in some professionnal way, the company don't want to put you out, because they know they can't modify your code by themself, because they don't understand it !!! :D

  • Like 3
Link to comment
Share on other sites

Which of course implies that DrClu doesn't already have that source code...

 

Wow. Are you guys all waiting on the sidelines ready to high five each other every time one of you posts anything? Its amusing watching you guys 'liking' each others post of every little thing.

 

I've actually never heard of the source code to Bubsy being out there.

Link to comment
Share on other sites

Wow. Are you guys all waiting on the sidelines ready to high five each other every time one of you posts anything? Its amusing watching you guys 'liking' each others post of every little thing.

Got it in one champ, we all keep hitting f5 on all threads, waiting for the right chance to reply. All day long. Every week. Every year.

  • Like 5
Link to comment
Share on other sites

Nope, we're in the middle of the road dodging the traffic that is new releases. It's not 2007 anymore.

 

I'm sure if the source was available back then some asshole would have put it on a CD and sold it.

 

 

Wow. Are you guys all waiting on the sidelines ready to high five each other every time one of you posts anything? Its amusing watching you guys 'liking' each others post of every little thing.

 

I've actually never heard of the source code to Bubsy being out there.

  • Like 3
Link to comment
Share on other sites

im still asking myselfe whats or if there is a benefit of nummberd labels :_(

 

 

As has been said before, it's entirely down to programmer preference, it has no performance gain for the assembled code, it's no different than using longer labels. Probably something a simple as the programmer couldn't think of anything more descriptive for that particular instance, small structure, they just wanted to get it written down and move on.

 

I personally find using longer variables and labels much more helpful, especially when you come to read the code again months or years later, helps you understand whats going on much quicker than a lot of vague references. Much like in C you might have:

 

int x = 20;

 

Yep, x is 20.. but what is x used for?

 

int numEnemies = 20;

 

That's much better, the code is now self documenting (assuming that it really is the number of enemies and not the number of Mariah Carey MP3's it's found in the source directory :D )

 

My own code uses long labels: (snip from a bit of the U-235 SE source ;) )

       moveq   #0,VOUTPUT                                      ; silence!
.voice_skip_loop:
        store   VOUTPUT,(BOUTPUT)                       ; store the output (silence)
        subq    #1,BCOUNT
        jr              NE,.voice_skip_loop
        addqt   #32,BOUTPUT

.normal:                                                                ; normal end of voice processing
        movei   #(DSP_VOICES*(DSP_BUFFERS*4))-4,X       ; for moving the output buffer to next channel
        subq    #1,VCOUNT                                       ; decriment the number of voices
        jr              EQ,.renderdone                          ; if it hits zero no more voices to process
        nop

        movei   #.vloop,JUMPTO                          ; our jump destination is back to the top of the loop
        addq    #32,VTABLE                                      ; next voices dataset
        addq    #4,VCACHE                                       ; move cache along
        addq    #4,VCACHEADR    
        sub             X,BOUTPUT                                       ; set the output buffer position for the next voice
        movei   #DSP_BUFFERS,BCOUNT
        jump    T,(JUMPTO)
        nop
        ;       moveq   #DSP_BUFFERS,BCOUNT



.renderdone:
        load    (STACKPTR),JUMPTO               ; Back from whence we came
        movei   #dsp_render_go,r1
        moveq   #0,r2

        jump    T,(JUMPTO)
        store   r2,(r1)

 

  • Like 4
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...