SPRITES-IN-ASSEMBLER-COLLISIONS! -------------------------------------------------------------------------------------------------- TOOL: EDASS-128 Editor/Assembler {and Commodore C128 ML-Monitor} Language: Assembler Extra: - Author: Misel Zivanovic Note: (C) 05th of May 2026 - www.lived.ch, mzretro.ch --------------------------------------------------------------------------------------------------- Some are saying that collision registers aren't really useful. Does this need to be true? I guess for some it does and for some it doesn't! Is that now making it be good, bad, useful or not? All i can say, using them is working and therefore the question is: Why not use them! There is literally no reason not to use them and many to use them! 1. Easy to use: Just read the register(s) 2. There are : SPRITE<>SPRITE , register 53278 3. And : SPRITE<>GRAPHICS {chars etc..}, register 53279 existing 4. What hit what? No big deal. The register will tell you and you can react accordingly! What's important to know, is to clear the collision detection to avoid double or unwanted collisions. All you have to do to achieve that, is read the register again after the collision {only if it's needed}. This below is a quick and rather large collision demo! {because it is involving all we have learned so far in past few lessons} CONTROL: Use ARROW KEYS to move around SPACE to quit any time. There are 3 SPRITES activated for the collision, or better said, just three will respond if a collision occurs! --------------------------------------------------------------------------------------------------- NOTE: A while back i have also made one collision demo for COMAL-80 {Commodore C64}. Check that one out too. It is more detailed! --------------------------------------------------------------------------------------------------- sprcoll-03.asm -a:0011-a: -e: ; www.lived.ch / mzretro.ch ; (c) 2026 may ; -------------------------------------- ; sprites in assembler! ; on commodore c128! ; ; collisions ; ; -------------------------------------- ; *= $1300 .obj m .bank 15 ; lda #$00 ; bank 15 sta $ff00 ; lda #$93 ; chr$(147) jsr $ffd2 ; clear screen ; lda #$00 sta $d020 ; border & backg. lda #$00 sta $d021 ; colors ; lda #$ff ; all sprites on sta $d015 ; ; -------------------------------------- ; lda #$01 ; disable basic sta $12fd ; interrupt serv. ; to gain sprite ; access ; -------------------------------------- ; ldx #00 ; sprite data spr lda sprite,x ; balls sta $0e00,x inx cpx #64 bne spr ; lda #56 ; pointer to mem ldx #$00 ; location #2 pointer sta 2040,x ; just to have a inx ; random pattern cpx #$07 ; sprite shape bne pointer ; ldy #$00 ; player data go21 ldx #$00 player lda mydata,x sta $0fc0,y iny inx cpx #3 bne player cpy #63 ; sprite=63 bytes bne go21 ; byte 64 is #$00 ; lda #63 ; sprite pointer sta 2047 ; to it ; ; -------------------------------------- ; ldy #$00 ; sprite ldx #$00 ; positions place lda xpos,y ; 0 to 6 sta $d000,x lda ypos,y ; sprite 7 is sta $d001,x ; you, the player lda col,y sta $d027,y inx inx iny cpx #$10 bne place ; ; jmp $419b ; show message ; rts ; ; -------------------------------------- ; ; main loop start ; ; -------------------------------------- ; main lda #$00 sta $d020 ; lda $d4 ; read keyboard cmp #$55 ; input beq left cmp #$53 beq up cmp #$56 beq right cmp #$54 beq down cmp #$3c ; quit (space) beq exit ; -------------------------------------- lda $d01e ; sprite<>sprite cmp #129 ; sprite 1/7 coll beq bars cmp #144 ; sprite 4/7 coll beq bars cmp #192 ; sprite 6/7 coll beq bars jmp main ; ; -------------------------------------- ; bars ldy #3 rast0 lda $d012 cmp #$50 sty $d020 bne rast0 ldy #9 rast1 lda $d012 cmp #$70 sty $d020 bne rast1 lda #$06 sta $d020 ; lda $d01e sta $0400 ; screen info jmp main ; ; -------------------------------------- ; exit lda #$00 ; all sprites off sta $d015 ; and return to rts ; basic ; ; -------------------------------------- ; ;control subroutines ; left dec $d00e ldy slow m0 ldx #$00 m1 dex bne m1 dey bne m0 jmp main ; right inc $d00e ldy slow m2 ldx #$00 m3 dex bne m3 dey bne m2 jmp main ; up dec $d00f ldy slow m4 ldx #$00 m5 dex bne m5 dey bne m4 jmp main ; down inc $d00f ldy slow m6 ldx #$00 m7 dex bne m7 dey bne m6 jmp main ; ; data and co production ltd. ; -------------------------------------- ; xpos .byte 65,65,160,160,160,255 .byte 255,160 ypos .byte 100,170,90,180,140,100 .byte 170,210 col .byte 2,3,4,5,6,7,8 ; ; -------------------------------------- ;sprite ; sprite .byte $01,$ff,$80,$07,$ff,$e0 .byte $1f,$ff,$f8,$3f,$ff,$fc .byte $7f,$ff,$fe,$7f,$ff,$fe .byte $7f,$ff,$fe,$ff,$ff,$ff .byte $ff,$ff,$ff,$ff,$ff,$ff .byte $ff,$ff,$ff,$ff,$ff,$ff .byte $ff,$ff,$ff,$ff,$ff,$ff .byte $7f,$ff,$fe,$7f,$ff,$fe .byte $7f,$ff,$fe,$3f,$ff,$fc .byte $1f,$ff,$f8,$07,$ff,$e0 .byte $01,$ff,$80,$01 ; mydata .byte 0,255,0 ; slow .byte 5