Starfield Question

By mighty.m

Expert (116)

mighty.m's picture

23-09-2003, 18:45

Okay, the post about the scrolldemo's got my blood pumping again and I'm kinda continueing some lil' scroll-thingie I started around last year's Christmas holiday (Hi Chaos, hi Grauw) Smile as an ASM-rookie.

Anyhow, the scroll is quite allright, but now I wanna know how to make a nice starfield in ASM... (The kind Fuzzy Logic used in their Muzax 3) (hi Ro Wink)

Can you guys give me some pointers? (Must say, I'm not THAT bright... in coding... Wink

ahwell, any help is apreciated....

Login or register to post comments

By BiFi

Enlighted (4348)

BiFi's picture

23-09-2003, 19:47

First, how many stars do you want to display?
Second, how many different speeds (layers) do you want the starfield to have?
Third, how do you want to display them? And this needs some more explaining:

- The easiest way is using sprites, though it's limited to 32 stars that way.
- You can also use the VDP PSET command and you can do more stars that way. Using PSET you need to keep track of 2 sets of coordinates for each star (1 to display the 'new' star, 1 to remove the 'old' star).
- You can also decide to use 2 pages to move the stars. You have a page you have on the screen and a page to build up. Every time you need to build up the non-displayed page with the star positions for the next step and display it. The now non-displayed page is cleared and built up with the stars for the next step. The you display that page again. And you do that all the time.

To start with, I'd recommend doing it with sprites first. That's it for the theoretical part. Wink

By snout

Ascended (15187)

snout's picture

23-09-2003, 19:51

Hmmm I think the PSET method is quite easy to understand. Both Latok and I managed to create starfields in the ol days! Smile

By BiFi

Enlighted (4348)

BiFi's picture

23-09-2003, 20:17

PSET in asm? The basic with sprites is the following:

- set up a 1 pixel sprite pattern
- set up the sprite color
- randomize positions

the next steps are looped:
- update coordinate(s) of all sprites
- write the whole table to the sprite attribute table

Though I think some sources might be useful. I'll dig up a source with a sprite starfield to put in here.

By mighty.m

Expert (116)

mighty.m's picture

23-09-2003, 20:41

Thnx BiFi !!!

By BiFi

Enlighted (4348)

BiFi's picture

23-09-2003, 20:56

Here it is:<TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="mrc-small">Code:</font><HR></TD></TR><TR><TD><FONT class="mrc-small"><PRE>; Simple star-loop (in 7 bitplanez, yer N.O.P. the only one!)
;
; By BiFi 1994
;
ORG &HC000

START: LD A,15 ; COLOR 15,0,0
LD HL,0
LD (&HF3E9),A
LD (&HF3EA),HL
CALL &H62

LD A,5 ; SCREEN 5
CALL &H5F

LD C,&H99 ; FOR I=1 TO 7:COLOR=(I,I,I,I):NEXT I
LD DE,&H0190
OUT (C),D
OUT (C),E
LD A,&H77
LD B,7
INC C
PLT_LP: OUT (C),A
OUT (C),A
SUB &H11
DJNZ PLT_LP

LD HL,&H7800 ; FOR I=0 TO 6:SPRITE$(I)=128:NEXT I
LD B,7
SPR_LP: PUSH BC
LD B,7
LD A,128
CALL &H0177
INC HL
SPRITE: LD A,0
CALL &H0177
INC HL
DJNZ SPRITE
POP BC
DJNZ SPR_LP

LD HL,&H7400 ; FOR I=0 TO 6:COLOR SPRITE(I)=I+1:NEXT I
LD DE,CLRTAB
LD B,32
SPRCLR: LD A,(DE)
CALL &H0177
PUSH BC
LD BC,16
ADD HL,BC
POP BC
INC DE
DJNZ SPRCLR

DI ; It'z time to set the TIMI-hook
LD BC,5
LD DE,OLD_HK
LD HL,&HFD9F
PUSH BC
PUSH HL
LDIR
POP DE
POP BC
LD HL,NEW_HK
LDIR
EI

SPC: LD A,0
CALL &HD8
JR Z,SPC

DI
LD BC,5
LD DE,&HFD9F
LD HL,OLD_HK
LDIR

XOR A
JP &H5F

NEW_HK: JP HOOK
RET
RET

HOOK: PUSH AF
PUSH BC
PUSH DE
PUSH HL
PUSH IX
LD B,32
LD DE,4
LD IX,SPR_AT
MV_SPR: LD C,(IX+2)
LD A,(IX+1)
INC C
SUB C
LD (IX+1),A
ADD IX,DE
DJNZ MV_SPR
LD BC,128
LD HL,SPR_AT
LD DE,&H7600
CALL &H5C
POP IX
POP HL
POP DE
POP BC
POP AF
OLD_HK: DB 201,201,201,201,201

CLRTAB: DB 7,7,7,7,7,6,6,6,6
DB 5,5,5,5,5,4,4,4,4
DB 3,3,3,3,3,2,2,2,2
DB 1,1,1,1,1

SPR_AT: DB 108,118,0,0,115,240,0,0
DB 137,212,0,0,13,91,0,0
DB 199,152,0,0,119,47,1,0
DB 165,4,1,0,17,93,1,0
DB 183,46,1,0,49,198,2,0
DB 43,223,2,0,117,58,2,0
DB 114,159,2,0,1,1,2,0
DB 17,164,3,0,196,65,3,0
DB 91,72,3,0,42,96,3,0
DB 179,61,4,0,151,218,4,0
DB 108,250,4,0,14,102,4,0
DB 126,153,4,0,41,57,5,0
DB 16,81,5,0,109,8,5,0
DB 42,167,5,0,56,218,6,0
DB 113,129,6,0,166,75,6,0
DB 86,83,6,0,209,244,6,0
</PRE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE>

By anonymous

incognito ergo sum (116)

anonymous's picture

23-09-2003, 22:13

plz snout, fix the linelenght of CODE ^^;

Anyway, sprite starfield is NOT limited to 32 sprites.
Especially if you only scroll them horizontally, it's possible to do sprite multiplexing. In the current game I'm programming, I'm using around 60 sprites, multiplexed twice (so I COULD use 96).

This involves some tricky line interrupt stuff, so probably only for the more advanced programmer. Too bad you can't fix the 8-sprites per line limit with tricks :/

By BiFi

Enlighted (4348)

BiFi's picture

23-09-2003, 22:19

GuyveR800, indeed I came up with the sprite multiplexing too but I think it's a bit too much right now for a beginner. And besides, I didn't know about sprite multiplexing back then. I did one with vertical movement too, using cursor control from this source.

By mighty.m

Expert (116)

mighty.m's picture

24-09-2003, 11:56

thnx BiFi, I'll try to start analyzing the code when I get home from work this evening Wink

By [WYZ]

Champion (447)

[WYZ]'s picture

24-09-2003, 14:14

Try to tranlate this really BASIC program to ASM:

10 SCREEN 1

; clear 0-23
100 FOR A%=0 TO 8*23
110 VPOKE A%,0
120 NEXT

; Random organize
130 FOR A%=0 TO 31
140 B%=23*RND(1)
150 FOR C%=0 TO 23
160 VPOKE 6144+C%*32+A%,B%
170 B%=B%+1:B%=B% MOD 23
180 NEXT:NEXT

; scroll
200 B%=0
210 VPOKE B%,1
220 VPOKE C%,0
230 C%=B%:B%=B%+1:B%=B% MOD (23*8)
240 GOTO 200

By this simple way, you can make a lot of layers. oO