User Tools

Site Tools


base:flexible_32_sprite_multiplexer

Flexible 32 Sprite Multiplexer

Here's an example of a flexible 32 Sprite Multiplexer with dynamic interrupts and very fast y-pos sorting. I wanted to use this in a sequel of Vincent, a jump and run game I wrote in 1990. The sorting routine is based on 'Bubble a la Rune' and uses an unrolled approach using zeropage variables for speed. It should be one of the fastest multiplexers around.

Should assemble with Dasm 2.12 or newer.

Written in 1994 by The Human Code Machine / Masters' Design Group.

 	PROCESSOR 6502

	ORG $C000
;--------------------------------------
;VARBASE

VARBASE	EQU $02

AREG	EQU VARBASE+$000
XREG	EQU VARBASE+$001
YREG	EQU VARBASE+$002

ABUF	EQU VARBASE+$003
XBUF	EQU VARBASE+$004
YBUF	EQU VARBASE+$005

IOBUF	EQU VARBASE+$006

FLAG	EQU VARBASE+$007

BUFFER	EQU VARBASE+$008

MAXSPR	EQU VARBASE+$009
COUNTER	EQU VARBASE+$00A

COUNTERX1	EQU VARBASE+$00B
COUNTERX2	EQU VARBASE+$00C

COUNTERY1	EQU VARBASE+$00D
COUNTERY2	EQU VARBASE+$00E

XDIF	EQU VARBASE+$00F
YDIF	EQU VARBASE+$010

XSPEED	EQU VARBASE+$011
YSPEED	EQU VARBASE+$012

XOFFSET	EQU VARBASE+$13
YOFFSET	EQU VARBASE+$14

JUMPLO	EQU VARBASE+$15
JUMPHI	EQU VARBASE+$16

BAL	EQU VARBASE+$17
BAH	EQU VARBASE+$18

OLDLO	EQU VARBASE+$19
OLDHI	EQU VARBASE+$1A

INDEXTABLE	EQU $E0

;--------------------------------------
;MEMORY
SPRITEPOINTER	EQU $07F8

;--------------------------------------
;VALUES

ITEMS	EQU 32

;--------------------------------------
;MACROS

;--------------------------------------
START	SUBROUTINE
	SEI
	CLD
	LDA #$35
	STA $01

	LDX #$FF
	TXS
	INX

	STX $D021
	STX $DC0E
	STX $D020

	INX
	STX $D01A

	LDA #$1B
	STA $D011

	LDA #<MAININTER
	STA $FFFE
	LDA #>MAININTER
	STA $FFFF

	LDA #$7F
	STA $DC0D

	LDA #$20
	STA $D012

	LDX #$02
	LDA #$80
.3	STA $00,X
	INX
	BNE .3

	LDA #$FF
.4	STA $2000,X
	INX
	BNE .4

	LDA #24
	STA MAXSPR

	LDA #$40
	STA XOFFSET

	LDA #$00
	STA YOFFSET

	LDA #$FF
	STA XSPEED

	LDA #$01
	STA YSPEED

	LDA #$0A
	STA XDIF
	LDA #$09
	STA YDIF

	JSR INITSORT

.2	CLI
	JMP .2	
;--------------------------------------
MAININTER	SUBROUTINE
	STA AREG
	STX XREG
	STY YREG

	DEC $D020

	LDA #$00
	STA $D017
	STA $D01B
	STA $D01D
	STA $D01C

	LDX MAXSPR
	CPX #$09
	BCS .MORETHAN8

	LDA #$4C	;JMP $0000
	STA .SWITCH

	LDA .ACTIVATETAB,X
	STA $D015

	LDA .JUMPLO,X
	STA JUMPLO
	LDA .JUMPHI,X
	STA JUMPHI
	LDA #$00
	STA $D010
	JMP (JUMPLO)

.MORETHAN8	LDA #$FF
	STA $D015
	LDA #$08
	STA COUNTER

	LDA #$2C	;BIT $0000
	STA .SWITCH
	LDA #$00

;--------------------------------------
.DOSPR7	LDY INDEXTABLE+7
	LDX YTABLE,Y
	STX $D00F
	LDX XTABLELO,Y
	STX $D00E
	LDX FRAME,Y
	STX SPRITEPOINTER+7
	LDX COLOR,Y
	STX $D02E
	LDX XTABLEHI,Y
	BEQ .DOSPR6
	LDA #$80
;--------------------------------------
.DOSPR6	LDY INDEXTABLE+6
	LDX YTABLE,Y
	STX $D00D
	LDX XTABLELO,Y
	STX $D00C
	LDX FRAME,Y
	STX SPRITEPOINTER+6
	LDX COLOR,Y
	STX $D02D
	LDX XTABLEHI,Y
	BEQ .DOSPR5
	ORA #$40
;--------------------------------------
.DOSPR5	LDY INDEXTABLE+5
	LDX YTABLE,Y
	STX $D00B
	LDX XTABLELO,Y
	STX $D00A
	LDX FRAME,Y
	STX SPRITEPOINTER+5
	LDX COLOR,Y
	STX $D02C
	LDX XTABLEHI,Y
	BEQ .DOSPR4
	ORA #$20
;--------------------------------------
.DOSPR4	LDY INDEXTABLE+4
	LDX YTABLE,Y
	STX $D009
	LDX XTABLELO,Y
	STX $D008
	LDX FRAME,Y
	STX SPRITEPOINTER+4
	LDX COLOR,Y
	STX $D02B
	LDX XTABLEHI,Y
	BEQ .DOSPR3
	ORA #$10
;--------------------------------------
.DOSPR3	LDY INDEXTABLE+3
	LDX YTABLE,Y
	STX $D007
	LDX XTABLELO,Y
	STX $D006
	LDX FRAME,Y
	STX SPRITEPOINTER+3
	LDX COLOR,Y
	STX $D02A
	LDX XTABLEHI,Y
	BEQ .DOSPR2
	ORA #$08
;--------------------------------------
.DOSPR2	LDY INDEXTABLE+2
	LDX YTABLE,Y
	STX $D005
	LDX XTABLELO,Y
	STX $D004
	LDX FRAME,Y
	STX SPRITEPOINTER+2
	LDX COLOR,Y
	STX $D029
	LDX XTABLEHI,Y
	BEQ .DOSPR1
	ORA #$04
;--------------------------------------
.DOSPR1	LDY INDEXTABLE+1
	LDX YTABLE,Y
	STX $D003
	LDX XTABLELO,Y
	STX $D002
	LDX FRAME,Y
	STX SPRITEPOINTER+1
	LDX COLOR,Y
	STX $D028
	LDX XTABLEHI,Y
	BEQ .DOSPR0
	ORA #$02
;--------------------------------------
.DOSPR0	LDY INDEXTABLE
	LDX YTABLE,Y
	STX $D001
	LDX XTABLELO,Y
	STX $D000
	LDX FRAME,Y
	STX SPRITEPOINTER
	LDX COLOR,Y
	STX $D027

	INC $D020

	LDX XTABLEHI,Y
	BEQ .OVER
	ORA #$01
.OVER	STA $D010
.SWITCH	JMP EXITINTER

	LDX XREG
	CLC
	LDY COUNTER
;--------------------------------------
.NEXTSPR0	LDA $D001
	ADC #$17
	SBC $D012
	BCC .BLIT0
	CMP #$03
	BCS .NEXT0
	LDA #$03
.NEXT0	CLC
	ADC $D012
	STA $D012

	LDA #<INTER0
	STA $FFFE
	LDA #>INTER0
	STA $FFFF

	INC $D019
	LDA $DC0D

	LDA AREG
	LDY YREG
	RTI

INTER0	STA AREG
	STY YREG

	LDY COUNTER

.BLIT0	LDA INDEXTABLE,Y
	TAY

	LDA YTABLE,Y
	STA $D001
	LDA XTABLELO,Y
	STA $D000
	LDA FRAME,Y
	STA SPRITEPOINTER
	LDA COLOR,Y
	STA $D027

	LDA XTABLEHI,Y
	BEQ .NO0
	LDA #$01
	ORA $D010
	BNE .YES0
.NO0	LDA #$FE
	AND $D010
.YES0	STA $D010

	LDY COUNTER
	INY
	STY COUNTER

	CPY MAXSPR
	BNE .NEXTSPR1
	JMP EXITINTER

;--------------------------------------
.NEXTSPR1	LDA $D003
	ADC #$17
	SBC $D012
	BCC .BLIT1
	CMP #$03
	BCS .NEXT1
	LDA #$03
.NEXT1	CLC
	ADC $D012
	STA $D012

	LDA #<INTER1
	STA $FFFE
	LDA #>INTER1
	STA $FFFF

	INC $D019
	LDA $DC0D

	LDA AREG
	LDY YREG
	RTI

INTER1	STA AREG
	STY YREG

	LDY COUNTER

.BLIT1	LDA INDEXTABLE,Y
	TAY

	LDA YTABLE,Y
	STA $D003
	LDA XTABLELO,Y
	STA $D002
	LDA FRAME,Y
	STA SPRITEPOINTER+1
	LDA COLOR,Y
	STA $D028

	LDA XTABLEHI,Y
	BEQ .NO1
	LDA #$02
	ORA $D010
	BNE .YES1
.NO1	LDA #$FD
	AND $D010
.YES1	STA $D010

	LDY COUNTER
	INY
	STY COUNTER
	CPY MAXSPR
	BNE .NEXTSPR2
	JMP EXITINTER

;--------------------------------------
.NEXTSPR2	LDA $D005
	ADC #$17
	SBC $D012
	BCC .BLIT2
	CMP #$03
	BCS .NEXT2
	LDA #$03
.NEXT2	CLC
	ADC $D012
	STA $D012

	LDA #<INTER2
	STA $FFFE
	LDA #>INTER2
	STA $FFFF

	INC $D019
	LDA $DC0D

	LDA AREG
	LDY YREG
	RTI

INTER2	STA AREG
	STY YREG

	LDY COUNTER

.BLIT2	LDA INDEXTABLE,Y
	TAY

	LDA YTABLE,Y
	STA $D005
	LDA XTABLELO,Y
	STA $D004
	LDA FRAME,Y
	STA SPRITEPOINTER+2
	LDA COLOR,Y
	STA $D029

	LDA XTABLEHI,Y
	BEQ .NO2
	LDA #$04
	ORA $D010
	BNE .YES2
.NO2	LDA #$FB
	AND $D010
.YES2	STA $D010

	LDY COUNTER
	INY
	STY COUNTER

	CPY MAXSPR
	BNE .NEXTSPR3
	JMP EXITINTER

;--------------------------------------
.NEXTSPR3	LDA $D007
	ADC #$17
	SBC $D012
	BCC .BLIT3
	CMP #$03
	BCS .NEXT3
	LDA #$03
.NEXT3	CLC
	ADC $D012
	STA $D012

	LDA #<INTER3
	STA $FFFE
	LDA #>INTER3
	STA $FFFF

	INC $D019
	LDA $DC0D

	LDA AREG
	LDY YREG
	RTI

INTER3	STA AREG
	STY YREG

	LDY COUNTER

.BLIT3	LDA INDEXTABLE,Y
	TAY

	LDA YTABLE,Y
	STA $D007
	LDA XTABLELO,Y
	STA $D006
	LDA FRAME,Y
	STA SPRITEPOINTER+3
	LDA COLOR,Y
	STA $D02A

	LDA XTABLEHI,Y
	BEQ .NO3
	LDA #$08
	ORA $D010
	BNE .YES3
.NO3	LDA #$F7
	AND $D010
.YES3	STA $D010

	LDY COUNTER
	INY
	STY COUNTER

	CPY MAXSPR
	BNE .NEXTSPR4
	JMP EXITINTER

;--------------------------------------
.NEXTSPR4	LDA $D009
	ADC #$17
	SBC $D012
	BCC .BLIT4
	CMP #$03
	BCS .NEXT4
	LDA #$03
.NEXT4	CLC
	ADC $D012
	STA $D012

	LDA #<INTER4
	STA $FFFE
	LDA #>INTER4
	STA $FFFF

	INC $D019
	LDA $DC0D

	LDA AREG
	LDY YREG
	RTI

INTER4	STA AREG
	STY YREG

	LDY COUNTER

.BLIT4	LDA INDEXTABLE,Y
	TAY

	LDA YTABLE,Y
	STA $D009
	LDA XTABLELO,Y
	STA $D008
	LDA FRAME,Y
	STA SPRITEPOINTER+4
	LDA COLOR,Y
	STA $D02B

	LDA XTABLEHI,Y
	BEQ .NO4
	LDA #$10
	ORA $D010
	BNE .YES4
.NO4	LDA #$EF
	AND $D010
.YES4	STA $D010

	LDY COUNTER
	INY
	STY COUNTER

	CPY MAXSPR
	BNE .NEXTSPR5
	JMP EXITINTER

;--------------------------------------
.NEXTSPR5	LDA $D00B
	ADC #$17
	SBC $D012
	BCC .BLIT5
	CMP #$03
	BCS .NEXT5
	LDA #$03
.NEXT5	CLC
	ADC $D012
	STA $D012

	LDA #<INTER5
	STA $FFFE
	LDA #>INTER5
	STA $FFFF

	INC $D019
	LDA $DC0D

	LDA AREG
	LDY YREG
	RTI

INTER5	STA AREG
	STY YREG

	LDY COUNTER

.BLIT5	LDA INDEXTABLE,Y
	TAY

	LDA YTABLE,Y
	STA $D00B
	LDA XTABLELO,Y
	STA $D00A
	LDA FRAME,Y
	STA SPRITEPOINTER+5
	LDA COLOR,Y
	STA $D02C

	LDA XTABLEHI,Y
	BEQ .NO5
	LDA #$20
	ORA $D010
	BNE .YES5
.NO5	LDA #$DF
	AND $D010
.YES5	STA $D010

	LDY COUNTER
	INY
	STY COUNTER

	CPY MAXSPR
	BNE .NEXTSPR6
	JMP EXITINTER

;--------------------------------------
.NEXTSPR6	LDA $D00D
	ADC #$17
	SBC $D012
	BCC .BLIT6
	CMP #$03
	BCS .NEXT6
	LDA #$03
.NEXT6	CLC
	ADC $D012
	STA $D012

	LDA #<INTER6
	STA $FFFE
	LDA #>INTER6
	STA $FFFF

	INC $D019
	LDA $DC0D

	LDA AREG
	LDY YREG
	RTI

INTER6	STA AREG
	STY YREG

	LDY COUNTER

.BLIT6	LDA INDEXTABLE,Y
	TAY

	LDA YTABLE,Y
	STA $D00D
	LDA XTABLELO,Y
	STA $D00C
	LDA FRAME,Y
	STA SPRITEPOINTER+6
	LDA COLOR,Y
	STA $D02D

	LDA XTABLEHI,Y
	BEQ .NO6
	LDA #$40
	ORA $D010
	BNE .YES6
.NO6	LDA #$BF
	AND $D010
.YES6	STA $D010

	LDY COUNTER
	INY
	STY COUNTER

	CPY MAXSPR
	BNE .NEXTSPR7
	JMP EXITINTER

;--------------------------------------
.NEXTSPR7	LDA $D00F
	ADC #$17
	SBC $D012
	BCC .BLIT7
	CMP #$03
	BCS .NEXT7
	LDA #$03
.NEXT7	CLC
	ADC $D012
	STA $D012

	LDA #<INTER7
	STA $FFFE
	LDA #>INTER7
	STA $FFFF

	INC $D019
	LDA $DC0D

	LDA AREG
	LDY YREG
	RTI

INTER7	STA AREG
	STY YREG

	LDY COUNTER

.BLIT7	LDA INDEXTABLE,Y
	TAY

	LDA YTABLE,Y
	STA $D00F
	LDA XTABLELO,Y
	STA $D00E
	LDA FRAME,Y
	STA SPRITEPOINTER+7
	LDA COLOR,Y
	STA $D02E

	LDA XTABLEHI,Y
	BEQ .NO7
	LDA #$80
	ORA $D010
	BNE .YES7
.NO7	LDA #$7F
	AND $D010
.YES7	STA $D010

	LDY COUNTER
	INY
	STY COUNTER

	CPY MAXSPR
	BEQ EXITINTER
	JMP .NEXTSPR0

.JUMPLO	DC.B #<EXITINTER,#<.DOSPR0,#<.DOSPR1,#<.DOSPR2
	DC.B #<.DOSPR3,#<.DOSPR4,#<.DOSPR5,#<.DOSPR6
	DC.B #<.DOSPR7

.JUMPHI	DC.B #>EXITINTER,#>.DOSPR0,#>.DOSPR1,#>.DOSPR2
	DC.B #>.DOSPR3,#>.DOSPR4,#>.DOSPR5,#>.DOSPR6
	DC.B #>.DOSPR7

.ACTIVATETAB	DC.B $00,$01,$03,$07,$0F,$1F,$3F,$7F,$FF

;--------------------------------------
EXITINTER	SUBROUTINE
	LDA #$EF
	CMP $DC01
	BEQ .OVER

	DEC $D020
	JSR MOVE
	DEC $D020
	JSR SORT
	LDA #$00
	STA $D020
	
.OVER	LDA #<MAININTER
	STA $FFFE
	LDA #>MAININTER
	STA $FFFF

	LDA #$20
	STA $D012

	INC $D019
	LDA $DC0D
	LDA AREG
	LDX XREG
	LDY YREG
	RTI

;--------------------------------------
INITSORT	SUBROUTINE
	LDX MAXSPR
	DEX
.1	TXA
	STA INDEXTABLE,X
	DEX
	BPL .1

	LDA #<SORTSTART
	STA BAL
	LDA #>SORTSTART
	STA BAH

	LDY #$00
.2	LDA BAL
	STA SORTLO,Y
	LDA BAH
	STA SORTHI,Y

	LDA BAL
	CLC
	ADC #18
	STA BAL
	BCC .OVER
	INC BAH
.OVER	INY
	CPY #ITEMS-1
	BNE .2
	RTS

;--------------------------------------
SORT	SUBROUTINE
	LDA MAXSPR
	CMP #$02
	BCC .EXIT
	SBC #$02
	TAY
	LDA SORTLO,Y
	STA BAL
	LDA SORTHI,Y
	STA BAH
	LDY #$00
	LDA #$60
	STA (BAL),Y
	JSR .OVER0
	LDY #$00
	LDA #$A4
	STA (BAL),Y
.EXIT	RTS

.OVER0	LDY INDEXTABLE+1
.BACK0	LDX INDEXTABLE
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER1
	STX INDEXTABLE+1
	STY INDEXTABLE

SORTSTART
.OVER1	LDY INDEXTABLE+2
.BACK1	LDX INDEXTABLE+1
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER2
	STX INDEXTABLE+2
	STY INDEXTABLE+1
	BCC .BACK0

.OVER2	LDY INDEXTABLE+3
.BACK2	LDX INDEXTABLE+2
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER3
	STX INDEXTABLE+3
	STY INDEXTABLE+2
	BCC .BACK1

.OVER3	LDY INDEXTABLE+4
.BACK3	LDX INDEXTABLE+3
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER4
	STX INDEXTABLE+4
	STY INDEXTABLE+3
	BCC .BACK2

.OVER4	LDY INDEXTABLE+5
.BACK4	LDX INDEXTABLE+4
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER5
	STX INDEXTABLE+5
	STY INDEXTABLE+4
	BCC .BACK3

.OVER5	LDY INDEXTABLE+6
.BACK5	LDX INDEXTABLE+5
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER6
	STX INDEXTABLE+6
	STY INDEXTABLE+5
	BCC .BACK4

.OVER6	LDY INDEXTABLE+7
.BACK6	LDX INDEXTABLE+6
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER7
	STX INDEXTABLE+7
	STY INDEXTABLE+6
	BCC .BACK5

.OVER7	LDY INDEXTABLE+8
.BACK7	LDX INDEXTABLE+7
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER8
	STX INDEXTABLE+8
	STY INDEXTABLE+7
	BCC .BACK6

.OVER8	LDY INDEXTABLE+9
.BACK8	LDX INDEXTABLE+8
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER9
	STX INDEXTABLE+9
	STY INDEXTABLE+8
	BCC .BACK7

.OVER9	LDY INDEXTABLE+10
.BACK9	LDX INDEXTABLE+9
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER10
	STX INDEXTABLE+10
	STY INDEXTABLE+9
	BCC .BACK8

.OVER10	LDY INDEXTABLE+11
.BACK10	LDX INDEXTABLE+10
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER11
	STX INDEXTABLE+11
	STY INDEXTABLE+10
	BCC .BACK9

;-------------------
.OVER11	LDY INDEXTABLE+12
.BACK11	LDX INDEXTABLE+11
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER12
	STX INDEXTABLE+12
	STY INDEXTABLE+11
	BCC .BACK10

.OVER12	LDY INDEXTABLE+13
.BACK12	LDX INDEXTABLE+12
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER13
	STX INDEXTABLE+13
	STY INDEXTABLE+12
	BCC .BACK11

.OVER13	LDY INDEXTABLE+14
.BACK13	LDX INDEXTABLE+13
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER14
	STX INDEXTABLE+14
	STY INDEXTABLE+13
	BCC .BACK12

.OVER14	LDY INDEXTABLE+15
.BACK14	LDX INDEXTABLE+14
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER15
	STX INDEXTABLE+15
	STY INDEXTABLE+14
	BCC .BACK13

.OVER15	LDY INDEXTABLE+16
.BACK15	LDX INDEXTABLE+15
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER16
	STX INDEXTABLE+16
	STY INDEXTABLE+15
	BCC .BACK14

.OVER16	LDY INDEXTABLE+17
.BACK16	LDX INDEXTABLE+16
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER17
	STX INDEXTABLE+17
	STY INDEXTABLE+16
	BCC .BACK15

.OVER17	LDY INDEXTABLE+18
.BACK17	LDX INDEXTABLE+17
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER18
	STX INDEXTABLE+18
	STY INDEXTABLE+17
	BCC .BACK16

.OVER18	LDY INDEXTABLE+19
.BACK18	LDX INDEXTABLE+18
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER19
	STX INDEXTABLE+19
	STY INDEXTABLE+18
	BCC .BACK17

.OVER19	LDY INDEXTABLE+20
.BACK19	LDX INDEXTABLE+19
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER20
	STX INDEXTABLE+20
	STY INDEXTABLE+19
	BCC .BACK18

.OVER20	LDY INDEXTABLE+21
.BACK20	LDX INDEXTABLE+20
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER21
	STX INDEXTABLE+21
	STY INDEXTABLE+20
	BCC .BACK19
;-------------------
.OVER21	LDY INDEXTABLE+22
.BACK21	LDX INDEXTABLE+21
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER22
	STX INDEXTABLE+22
	STY INDEXTABLE+21
	BCC .BACK20

.OVER22	LDY INDEXTABLE+23
.BACK22	LDX INDEXTABLE+22
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER23
	STX INDEXTABLE+23
	STY INDEXTABLE+22
	BCC .BACK21

.OVER23	LDY INDEXTABLE+24
.BACK23	LDX INDEXTABLE+23
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER24
	STX INDEXTABLE+24
	STY INDEXTABLE+23
	BCC .BACK22

.OVER24	LDY INDEXTABLE+25
.BACK24	LDX INDEXTABLE+24
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER25
	STX INDEXTABLE+25
	STY INDEXTABLE+24
	BCC .BACK23

.OVER25	LDY INDEXTABLE+26
.BACK25	LDX INDEXTABLE+25
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER26
	STX INDEXTABLE+26
	STY INDEXTABLE+25
	BCC .BACK24

.OVER26	LDY INDEXTABLE+27
.BACK26	LDX INDEXTABLE+26
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER27
	STX INDEXTABLE+27
	STY INDEXTABLE+26
	BCC .BACK25

.OVER27	LDY INDEXTABLE+28
.BACK27	LDX INDEXTABLE+27
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER28
	STX INDEXTABLE+28
	STY INDEXTABLE+27
	BCC .BACK26

.OVER28	LDY INDEXTABLE+29
.BACK28	LDX INDEXTABLE+28
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER29
	STX INDEXTABLE+29
	STY INDEXTABLE+28
	BCC .BACK27

.OVER29	LDY INDEXTABLE+30
.BACK29	LDX INDEXTABLE+29
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER30
	STX INDEXTABLE+30
	STY INDEXTABLE+29
	BCC .BACK28

.OVER30	LDY INDEXTABLE+31
.BACK30	LDX INDEXTABLE+30
	LDA YTABLE,Y
	CMP YTABLE,X
	BCS .OVER31
	STX INDEXTABLE+31
	STY INDEXTABLE+30
	BCC .BACK29
.OVER31	LDY INDEXTABLE
	RTS


SORTLO	DS.B ITEMS-1
SORTHI	DS.B ITEMS-1

;--------------------------------------
MOVE	SUBROUTINE
	LDY MAXSPR
	DEY
	BMI .EXIT

.1	LDA COUNTERX2
	CLC
	ADC XDIF
	STA COUNTERX2
	CLC
	ADC COUNTERX1
	TAX
	LDA SINX,X
	STA XTABLELO,Y
	LDA SINXHI,X
	STA XTABLEHI,Y

	LDA COUNTERY2
	CLC
	ADC YDIF
	STA COUNTERY2
	CLC
	ADC COUNTERY1
	TAX
	LDA SINY,X
	STA YTABLE,Y

	DEY
	BPL .1

.EXIT	LDA XOFFSET
	STA COUNTERX2
	LDA YOFFSET
	STA COUNTERY2

	LDA COUNTERX1
	CLC
	ADC XSPEED
	STA COUNTERX1

	LDA COUNTERY1
	CLC
	ADC YSPEED
	STA COUNTERY1

	RTS
;--------------------------------------
YTABLE	DC.B $34,$38,$3C,$40,$44,$48,$4C,$50
	DC.B $74,$78,$7C,$80,$84,$88,$8C,$90
	DC.B $60,$60,$75,$75,$A4,$A8,$AC,$B0
	DC.B $54,$58,$5C,$60,$64,$68,$6C,$70

XTABLELO	DC.B $20,$40,$60,$80,$A0,$C0,$E0,$FF
	DC.B $20,$40,$60,$80,$A0,$C0,$E0,$FF
	DC.B $80,$98,$80,$98,$A0,$C0,$E0,$FF
	DC.B $20,$40,$60,$80,$A0,$C0,$E0,$FF

XTABLEHI	DC.B $00,$00,$00,$00,$00,$00,$00,$00
	DC.B $00,$00,$00,$00,$00,$00,$00,$00
	DC.B $00,$00,$00,$00,$00,$00,$00,$00
	DC.B $00,$00,$00,$00,$00,$00,$00,$00

COLOR	DC.B $01,$02,$03,$04,$05,$06,$07,$08
	DC.B $09,$0A,$0B,$0C,$0D,$0E,$0F,$01
	DC.B $01,$02,$03,$04,$05,$06,$07,$08
	DC.B $09,$0A,$0B,$0C,$0D,$0E,$0F,$01

FRAME	DC.B $80,$80,$80,$80,$80,$80,$80,$80
	DC.B $80,$80,$80,$80,$80,$80,$80,$80
	DC.B $80,$80,$80,$80,$80,$80,$80,$80
	DC.B $80,$80,$80,$80,$80,$80,$80,$80

MSBTAB	DC.B $01,$02,$04,$08,$10,$20,$40,$80

SINX
 DC.B $AF,$B2,$B6,$B9,$BD,$C1,$C4,$C8,$CB,$CF,$D2,$D6,$D9,$DD,$E0,$E3
 DC.B $E7,$EA,$ED,$F1,$F4,$F7,$FA,$FD,$00,$03,$06,$09,$0B,$0E,$11,$13
 DC.B $16,$18,$1B,$1D,$1F,$21,$24,$26,$28,$2A,$2B,$2D,$2F,$30,$32,$33
 DC.B $35,$36,$37,$38,$39,$3A,$3B,$3C,$3C,$3D,$3D,$3E,$3E,$3E,$3E,$3E
 DC.B $3E,$3E,$3E,$3E,$3D,$3D,$3C,$3C,$3B,$3A,$39,$38,$37,$36,$35,$33
 DC.B $32,$30,$2F,$2D,$2B,$2A,$28,$26,$24,$21,$1F,$1D,$1B,$18,$16,$13
 DC.B $11,$0E,$0B,$09,$06,$03,$00,$FD,$FA,$F7,$F4,$F1,$ED,$EA,$E7,$E3
 DC.B $E0,$DD,$D9,$D6,$D2,$CF,$CB,$C8,$C4,$C1,$BD,$B9,$B6,$B2,$AF,$AB
 DC.B $A7,$A4,$A0,$9D,$99,$95,$92,$8E,$8B,$87,$84,$80,$7D,$79,$76,$73
 DC.B $6F,$6C,$69,$65,$62,$5F,$5C,$59,$56,$53,$50,$4D,$4B,$48,$45,$43
 DC.B $40,$3E,$3B,$39,$37,$35,$32,$30,$2E,$2C,$2B,$29,$27,$26,$24,$23
 DC.B $21,$20,$1F,$1E,$1D,$1C,$1B,$1A,$1A,$19,$19,$18,$18,$18,$18,$18
 DC.B $18,$18,$18,$18,$19,$19,$1A,$1A,$1B,$1C,$1D,$1E,$1F,$20,$21,$23
 DC.B $24,$26,$27,$29,$2B,$2C,$2E,$30,$32,$35,$37,$39,$3B,$3E,$40,$43
 DC.B $45,$48,$4B,$4D,$50,$53,$56,$59,$5C,$5F,$62,$65,$69,$6C,$6F,$73
 DC.B $76,$79,$7D,$80,$84,$87,$8B,$8E,$92,$95,$99,$9D,$A0,$A4,$A7,$AB

SINXHI
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$01,$01,$01,$01
 DC.B $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
 DC.B $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
 DC.B $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
 DC.B $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
 DC.B $01,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
 DC.B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00

SINY
 DC.B $8D,$8F,$92,$94,$96,$98,$9A,$9C,$9F,$A1,$A3,$A5,$A7,$A9,$AB,$AD
 DC.B $AF,$B1,$B3,$B5,$B7,$B9,$BB,$BC,$BE,$C0,$C2,$C3,$C5,$C7,$C8,$CA
 DC.B $CB,$CD,$CE,$D0,$D1,$D2,$D4,$D5,$D6,$D7,$D8,$D9,$DA,$DB,$DC,$DD
 DC.B $DE,$DF,$E0,$E0,$E1,$E1,$E2,$E2,$E3,$E3,$E3,$E4,$E4,$E4,$E4,$E4
 DC.B $E4,$E4,$E4,$E4,$E3,$E3,$E3,$E2,$E2,$E1,$E1,$E0,$E0,$DF,$DE,$DD
 DC.B $DC,$DB,$DA,$D9,$D8,$D7,$D6,$D5,$D4,$D2,$D1,$D0,$CE,$CD,$CB,$CA
 DC.B $C8,$C7,$C5,$C3,$C2,$C0,$BE,$BC,$BB,$B9,$B7,$B5,$B3,$B1,$AF,$AD
 DC.B $AB,$A9,$A7,$A5,$A3,$A1,$9F,$9C,$9A,$98,$96,$94,$92,$8F,$8D,$8B
 DC.B $89,$87,$84,$82,$80,$7E,$7C,$7A,$77,$75,$73,$71,$6F,$6D,$6B,$69
 DC.B $67,$65,$63,$61,$5F,$5D,$5B,$5A,$58,$56,$54,$53,$51,$4F,$4E,$4C
 DC.B $4B,$49,$48,$46,$45,$44,$42,$41,$40,$3F,$3E,$3D,$3C,$3B,$3A,$39
 DC.B $38,$37,$36,$36,$35,$35,$34,$34,$33,$33,$33,$32,$32,$32,$32,$32
 DC.B $32,$32,$32,$32,$33,$33,$33,$34,$34,$35,$35,$36,$36,$37,$38,$39
 DC.B $3A,$3B,$3C,$3D,$3E,$3F,$40,$41,$42,$44,$45,$46,$48,$49,$4B,$4C
 DC.B $4E,$4F,$51,$53,$54,$56,$58,$5A,$5B,$5D,$5F,$61,$63,$65,$67,$69
 DC.B $6B,$6D,$6F,$71,$73,$75,$77,$7A,$7C,$7E,$80,$82,$84,$87,$89,$8B
 DC.B $FF
base/flexible_32_sprite_multiplexer.txt · Last modified: 2015-04-17 04:31 (external edit)