base:8_sprite_starfield
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:8_sprite_starfield [2015-04-17 04:30] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== 8 Sprite Starfield ==== | ||
+ | This piece of source, done in ACME shows you a very simple way to create a simple star field/space feature, using 8 sprites. Basically this is a simple routine that will wrap 8 stars across the screen, according to the speed table. Maybe some other time I'll work on a routine which will display more than 8 stars in its simplest form. | ||
+ | < | ||
+ | ; | ||
+ | ;Simple sprite starfield by Richard Bayliss | ||
+ | ; | ||
+ | sync = $0340 | ||
+ | starpos = $0350 | ||
+ | |||
+ | !to " | ||
+ | |||
+ | * = $0900 | ||
+ | sei | ||
+ | jsr $ff81 ; Clear the screen | ||
+ | lda #$00 ;Black border + screen | ||
+ | sta $d020 | ||
+ | sta $d021 | ||
+ | lda #$ff | ||
+ | sta $d015 ;Turn on all sprites | ||
+ | lda # | ||
+ | sta $d017 ;No sprite expansion X | ||
+ | sta $d01b ;Sprites in front of chars | ||
+ | sta $d01d ;No sprite expansion Y | ||
+ | ldx #$00 | ||
+ | clr2000 | ||
+ | sta $2000,x ;Fill $2000 with zero | ||
+ | inx | ||
+ | bne clr2000 | ||
+ | lda #$01 ;Create a dot for the sprite starfield | ||
+ | sta $2000 | ||
+ | ldx #$00 | ||
+ | setsprs | ||
+ | sta $07f8,x | ||
+ | lda #$01 ;All sprites are white | ||
+ | sta $d027,x | ||
+ | inx | ||
+ | cpx #$08 ;Do the sprite creation 8 times | ||
+ | bne setsprs | ||
+ | ldx #$00 | ||
+ | positions | ||
+ | sta starpos+0,x ;Create data memory for current sprite position | ||
+ | inx | ||
+ | cpx #$10 | ||
+ | bne positions | ||
+ | |||
+ | lda #<irq ;You should know this bit already ;) | ||
+ | sta $0314 | ||
+ | lda #>irq | ||
+ | sta $0315 | ||
+ | lda #$00 | ||
+ | sta $d012 | ||
+ | lda #$7f | ||
+ | sta $dc0d | ||
+ | lda #$1b | ||
+ | sta $d011 | ||
+ | lda #$01 | ||
+ | sta $d01a | ||
+ | cli | ||
+ | mainloop | ||
+ | sta sync ;correctly | ||
+ | lda sync | ||
+ | waitsync | ||
+ | bne cont | ||
+ | jmp waitsync | ||
+ | cont | ||
+ | jsr movestars | ||
+ | jmp mainloop | ||
+ | |||
+ | expdpos | ||
+ | xpdloop | ||
+ | sta $d001, | ||
+ | lda starpos+0,x ;Read virtual memory from starpos (odd number values) | ||
+ | asl | ||
+ | ror $d010 ;increase the screen limit for sprite x position | ||
+ | sta $d000,x ;Write memory to the actual sprite x position | ||
+ | inx | ||
+ | inx | ||
+ | cpx #$10 | ||
+ | bne xpdloop | ||
+ | rts | ||
+ | |||
+ | movestars | ||
+ | moveloop | ||
+ | clc | ||
+ | adc starspeed+0, | ||
+ | sta starpos+0,x | ||
+ | inx ; Add 2 to each value of the loop | ||
+ | inx ; | ||
+ | cpx #$10 ;Once reached 16 times rts else repeat moveloop | ||
+ | bne moveloop | ||
+ | rts | ||
+ | |||
+ | irq inc $d019 ;You should also know this bit already | ||
+ | lda #$00 | ||
+ | sta $d012 | ||
+ | lda #$01 | ||
+ | sta sync | ||
+ | jmp $ea31 | ||
+ | |||
+ | ;Data tables for the sprite positions | ||
+ | ; x y | ||
+ | postable | ||
+ | !byte $00,$40 | ||
+ | !byte $00,$48 | ||
+ | !byte $00,$50 | ||
+ | !byte $00,$58 | ||
+ | !byte $00,$60 | ||
+ | !byte $00,$68 | ||
+ | !byte $00,$70 | ||
+ | !byte $00,$78 | ||
+ | |||
+ | ;Data tables for speed of the moving stars (erm dots) | ||
+ | ; | ||
+ | starspeed | ||
+ | !byte $05,$00 ;varied speeds of the moving stars. :) | ||
+ | !byte $06,$00 | ||
+ | !byte $07,$00 | ||
+ | !byte $06,$00 | ||
+ | !byte $04,$00 | ||
+ | !byte $07,$00 | ||
+ | !byte $05,$00 | ||
+ | !byte $00,$00 | ||
+ | </ |
base/8_sprite_starfield.txt · Last modified: 2015-04-17 04:30 by 127.0.0.1