;Move sprite, according to fixed direction ;by Richard/TND DirectionUp = 0 ;UP value DirectionDown = 1 ;DOWN value DirectionLeft = 2 ;LEFT value DirectionRight = 3 ;RIGHT value !to "movedirection.prg",cbm *=$0801 !basic 2064 ;SYS2064 called *=$0810 lda #$37 ;Enable KERNAL sta $01 jsr $e544 ;Fast kernal clear screen ;Create a solid square sprite as frame $80 ldx #$00 FillSPR lda #$ff sta $2000,x inx cpx #$40 bne FillSPR ;Clear screen (for now) lda #$02 sta $d020 lda #$00 sta $d021 ;Draw the sprite objects to sprite hw ldx #$00 DrawSPR lda #$80 sta $07f8,x lda ColourTable,x sta $d027,x inx cpx #8 bne DrawSPR ;Set starting position for all of the sprites ;we are going to move all 8 sprites. ldx #$00 PosSprites lda PosTable,x sta ObjPos,x inx cpx #16 bne PosSprites ;Now fix / enable all of the sprites on screen lda #$ff sta $d015 ;Create a simple raster loop to call subroutines ;(Alternatively you can use an IRQ instead if you ;wish). RasterLoop lda #$fa cmp $d012 bne *-3 jsr ExpandMSB ;Expand object/sprite X position jsr MoveObjects ;Movement code jmp RasterLoop ;Infinite loop through raster ;Make object positions into actual hardware sprite pointers ExpandMSB ldx #$00 Loop1 lda ObjPos+1,x ;Pick Y position from position table sta $d001,x ;Store to hardware sprite Y lda ObjPos,x ;Pick X position from position table asl ror $d010 ;Allow sprites to move whole screen sta $d000,x ;Store to hardware sprite X inx ;ObjPos table X, and Y are one after inx ;another. So increment one step and another cpx #16 ;16 bytes read. bne Loop1 ;Else continue loop rts ;Call JSR subroutines to move each sprite individually MoveObjects jsr MoveSpriteObject1 jsr MoveSpriteObject2 jsr MoveSpriteObject3 jsr MoveSpriteObject4 jsr MoveSpriteObject5 jsr MoveSpriteObject6 jsr MoveSpriteObject7 jsr MoveSpriteObject8 rts ;The main macro which sets direction for each sprite !macro setspritedirection objectDir, objectX, objectY { lda objectDir cmp #DirectionUp bne .notMoveUp jmp .moveUp .notMoveUp cmp #DirectionDown bne .notMoveDown jmp .moveDown .notMoveDown cmp #DirectionLeft bne .notMoveLeft jmp .moveLeft .notMoveLeft cmp #DirectionRight bne .notMoveRight jmp .moveRight .notMoveRight ;Error rts ;Move sprite object upwards until it reaches set limit .moveUp lda objectY sec sbc #2 ;Speed of upwards movement cmp #$32 ;Upper position limit reached? bcs .UpdateUp lda #DirectionDown ;Force direction of sprite to go down sta objectDir rts .UpdateUp sta objectY rts ;Move sprite object downwards until it reaches a limit .moveDown lda objectY clc adc #2 ;Speed of downwards movement cmp #$f2 ;Lower position reached? bcc .UpdateDown lda #DirectionUp ;Force direction of sprite to go up sta objectDir rts .UpdateDown sta objectY rts ;Move sprite object left .moveLeft lda objectX sec sbc #1 ;Speed left cmp #$0c ;Left most position bcs .UpdateLeft lda #DirectionRight ;Force direction of sprite to go right sta objectDir rts .UpdateLeft sta objectX rts ;Move sprite object right .moveRight lda objectX clc adc #1 ;Speed right cmp #$a2 bcc .UpdateRight lda #DirectionLeft ;Force direction of sprite to go left sta objectDir rts .UpdateRight sta objectX rts } ;For each subroutine, call macro command to move ;all 8 sprites, according to set direction. MoveSpriteObject1 +setspritedirection Sprite1Dir, ObjPos, ObjPos+1 MoveSpriteObject2 +setspritedirection Sprite2Dir, ObjPos+2, ObjPos+3 MoveSpriteObject3 +setspritedirection Sprite3Dir, ObjPos+4, ObjPos+5 MoveSpriteObject4 +setspritedirection Sprite4Dir, ObjPos+6, ObjPos+7 MoveSpriteObject5 +setspritedirection Sprite5Dir, ObjPos+8, ObjPos+9 MoveSpriteObject6 +setspritedirection Sprite6Dir, ObjPos+10, ObjPos+11 MoveSpriteObject7 +setspritedirection Sprite7Dir, ObjPos+12, ObjPos+13 MoveSpriteObject8 +setspritedirection Sprite8Dir, ObjPos+14, ObjPos+15 rts ;Some pointers ;Sprite movement direction Sprite1Dir !byte 0 ;Starting direction for each sprite Sprite2Dir !byte 1 Sprite3Dir !byte 2 ;0 = UP, 1 = DOWN, 2 = LEFT, 3 = RIGHT Sprite4Dir !byte 3 Sprite5Dir !byte 0 Sprite6Dir !byte 1 Sprite7Dir !byte 2 Sprite8Dir !byte 3 ;Sprite position table (X then Y per sprite) PosTable !byte $40,$70 ;All of these represent X, Y co-ords !byte $10,$40 ;for each object (sprite) position !byte $60,$90 ;which is then called through a loop !byte $70,$60 ;and is placed to the C64's hardware. !byte $90,$d0 !byte $50,$80 !byte $30,$50 !byte $20,$a0 ObjPos !byte $00,$00 ;Object 1 X,Y (Sprite 0) !byte $00,$00 ;Object 2 X,Y (Sprite 1) !byte $00,$00 ;Object 3 X,Y (Sprite 2) !byte $00,$00 ;Object 4 X,Y (Sprite 3) !byte $00,$00 ;Object 5 X,Y (Sprite 4) !byte $00,$00 ;Object 6 X,Y (Sprite 5) !byte $00,$00 ;Object 7 X,Y (Sprite 6) !byte $00,$00 ;Object 8 X,Y (Sprite 7) ;Finally sprite colour ColourTable !byte $0a,$04,$0d,$03,$07,$0e,$05,$0f