SPRITES-IN-ASSEMBLER-A-MISTERY! -------------------------------------------------------------------------------------------------- TOOL: EDASS-128 Editor/Assembler {and Commodore C128 ML-Monitor} Language: Assembler Extra: - Author: Misel Zivanovic Note: (C) 03rd of May 2026 - www.lived.ch, mzretro.ch --------------------------------------------------------------------------------------------------- Because Commodore C64 and Commodore C128 have some identical areas, this code will actually run on the C64 Computer, but not on the Commodore C128. And it was written on the C128 Computer! Okay, that's enough for today! Are you for real!!??? How is that possible??? All i can say is: try it out! sprites.asm -a:0011-a: -e: ; -------------------------------------- ; sprites in assembler! ; we will now write a program that ; theoretically should work, but it will ; not do a thing practically! ; on commodore c128! ; -------------------------------------- ; ; this however would work perfectly fine ; on commodore c64! ; ; -------------------------------------- ; *= $1300 .obj m .bank 15 ; lda #$00 sta $d020 ; border & backg. lda #$06 sta $d021 ; color ; lda #$ff ; sprites on sta $d015 ; ; -------------------------------------- ; remove command ; lda #$01 ; semicolons to ; sta $12fd ; enable access ; to sprites ; -------------------------------------- ; lda #2 ; pointer to mem ldx #$08 ; location #2 loop dex ; just to have a sta 2040,x ; random pattern bne loop ; sprite shape ; ldx #$00 ; sprite position ldy #100 ; x & y all 8 storage lda #60 ; sprites sta $d000,x tya sta $d001,x inx inx clc lda storage+1 adc #26 ; distance <> sta storage+1 cpx #16 ; all 7 sprites? bne storage ; no! repeat lda #60 ; put start value sta storage+1 ; of 25 back! rts --------------------------------------------------------------------------------------------------- If you start this, nothing will really happen! Except the change of the screen colors if they were not already the same! So why this isn't working? Very good! Nice question, I like it! As we know already C64 had an editor more powerful than the rest of the gang back in the days and that was already in 1982 {later in Europe or 1983}... Well, Commodore C128 went a bit further and has employed some additional interrupts and added more functionality. Including the one that is now blocking the proper execution of this program and is not letting us access our sprites and a few other things related to that specific interrupt or service. Yes, the word is about the BASIC Interrupt and the status of the location $12fd! As long as this is #$00, it has the control and it won't let you take over the sprite control and a few other things which are directly related to that interrupt service when you are using BASIC! Like sprite movement, sound, collisions etc. Actually, all you need to do is put anything that isn't a zero into that address and it's done! NOTE: Afterwards, a few BASIC commands won't work any longer, as mentioned. You would need to enable this location in order to gain the access back. In other words, you would need to switch back and forth in cases where you must have the access via BASIC/Assembler! And, of course, you can't access both at the same time from BASIC/Assembler! So, just remove the semicolons and you are good to go! ; ; -------------------------------------- ; remove command lda #$01 ; semicolons to sta $12fd ; enable access ; to sprites ; -------------------------------------- ; Now the execution will show different results and you'll get to see how busy some memory locations are even when you do nothing! --------------------------------------------------------------------------------------------------- And we learned again a thing or two. Isn't that wonderful! ;-) Let's add a byte or two more: --------------------------------------------------------------------------------------------------- Sprite coordinates are from $d000 and are coming like a pair/sprite $d000 = x coordinate for sprite #0 $d001 = y coordinate for sprite #0 $d002 = x coordinate for sprite #1 $d003 = y coordinate for sprite #1 and so on for all 8 sprites {0 - 7} writing: ldy #$00 lda #100 loop sta $d000,y iny iny cpx #16 bne loop rts ...would effect only x coordinates and add 100 there for all 8 sprites. Starting with sta $d001 would add 100 in y coordinates for all sprites all thanks to 2x iny which is equal to STEP 2 in BASIC = $d001, $d003, $d005 etc. ---------------------------------------------------------------------------------------------------