UNUSUAL-SCREEN-DELETIONS-{CLEAR}-IN-ASSEMBLER -------------------------------------------------------------------------------------------------- TOOL: Built-In ML-Monitor {Commodore C128} Language: Assembler Extra: - Author: Misel Zivanovic Note: (C) 17th DEC 2025 - www.lived.ch, mzretro.ch Information: I coded this one already in 21st of January 2024! Just added now some explanations --------------------------------------------------------------------------------------------------- As we have already learned, the fast way to delete a text screen in assembler would be this method, using BSOUT KERNAL Routine: This equals to BASIC's: PRINT CHR$(147) command to clear the screen. a 00c00 a9 93 lda #$93 a 00c02 20 d2 ff jsr $ffd2 a 00c05 60 rts a 00c06 HOWEVER, that is only what everyone is thinking! NOT TRUE! This one is the real master of the cleaning disaster: 4 BYTES ONLY! {Works only in BANK 15} . 00b00 20 42 c1 jsr $c142 . 00b03 60 rts This below is probably the most common/used one: {Not the shortest, but it looks fancy and cool, haha} a 00b00 a2 00 ldx #$00 a 00b02 a9 20 lda #$20 a 00b04 9d 00 04 sta $0400,x a 00b07 9d 00 05 sta $0500,x a 00b0a 9d 00 06 sta $0600,x a 00b0d 9d e8 06 sta $06e8,x ;NOT $0700 because that would go way over $07e7, dec 2023! Screen end address! a 00b10 e8 inx a 00b11 d0 f1 bne $0b04 a 00b13 60 rts --------------------------------------------------------------------------------------------------- THIS IS ONE FROM ME: Now we are coming to crazy versions! Wondering why would anyone waste space for this when already 6 bytes can do the same! Well, i am the wasting-guy! How could i know such secret information... I strongly believe you should know what to do with this code here: >01300 4c 24 13 a9 51 a2 00 8d:l$.IqB.. >01308 00 07 ee 08 13 d0 f8 ee:..N..PXN >01310 09 13 e8 e0 03 d0 f0 a9:..H..PPI >01318 51 a2 00 9d fd 06 e8 e0:qB....H. >01320 eb d0 f8 60 a9 00 8d 08:KPX.I... >01328 13 a9 04 8d 09 13 4c 03:.I....l. >01330 13 00 ff ff ff ff 00 00:........ --------------------------------------------------------------------------------------------------- EXPLAINED: a 01300 4c 24 13 jmp $1324 Jump to $1324 to reset the values that were messed up during execution a 01303 a9 81 lda #$20 This is SPACE {empty} , to clear the screen. Anything else will fill the screen a 01305 a2 00 ldx #$00 Reset the counter a 01307 8d 00 04 sta $0400 Screen start position a 0130a ee 08 13 inc $1308 Increment Low-Byte 255 positions a 0130d d0 f8 bne $1307 and fall through when 0 {after 255} a 0130f ee 09 13 inc $1309 increment the High-Byte a 01312 e8 inx Increment the counter x a 01313 e0 03 cpx #$03 4 rounds? a 01315 d0 f0 bne $1307 No, repeat a 01317 a9 81 lda #$20 Final part to fill the remaining bytes until dec 2023, hex $07e7 with SPACE a 01319 a2 00 ldx #$00 Reset the counter a 0131b 9d fd 06 sta $06fd,x New start position a 0131e e8 inx Increment x a 0131f e0 ea cpx #$eb Is it dec 235? a 01321 d0 f8 bne $131b No? Repeat a 01323 60 rts If yes, back to the subroutine or BASIC a 01324 a9 00 lda #$00 Lines below are a 01326 8d 08 13 sta $1308 setting values to start values a 01329 a9 04 lda #$04 = $0400 a 0132b 8d 09 13 sta $1309 Low/High-Byte a 0132e 4c 03 13 jmp $1303 Then back to execute deletion! THIS ONE IF FROM THE C128 BOOK, INTERNALS --------------------------------------------------------------------------------------------------- It looks like others are also not happy with the 6 byte solution! Btw. this is supposed to be the faster screen deletion routine... I mean, like anyone can see that. Already the first one is faster than Superman, and it uses just 6 bytes... Not to comment how BASIC 7 command 'SCNCLR' is using assembler routines to delete the screen! Anyway, this not-really-needed CLS routines are highly interesting and that's why everyone loves them! EXAMPLE: Commodore C128 Clear Screen with (misusing) the Stack Pointer (C128 Book, Internals) LDA #$00 ;BANK 15 STA $FF00 ;DISABLE INTERRUPTS SEI LDA #$04 ;NEW START ADDRESS OF THE SP STA $D509 ;IS $0400 IN RAM BANK 0 TSX ;STACK POINTER TO X STX $FD ;AND SAVE CURRENT POINTER LDX #$FF ;SP TO START OF STACK TXS LDY #$03 ;256 BYTES TIMES 4 LDX #$00 ;256-BYTE COUNTER LDA #$20 ;FILL CHARACTER NEXT PHA ;SAVE CHARACTER DEX ;DECREMENT LOOP BNE NEXT ;NEXT CHARACTER INC $D509 ;INCREMENT SP HIGH BYTE DEY ;ALL FOUR BLOCKS FILLED? BNE NEXT ;NO, NOT YET LDX $FD ;GET OLD SP TXS ;AND STORE AGAIN LDA #$01 ;HIGH BYTE OF ORIGINAL STACK STA $D509 ;AND SET CLI ;REENABLE INTERRUPTS RTS ;END OF THE CLEAR ROUTINE --------------------------------------------------------------------------------------------------- IF I CAN FIND MORE OR CAN WRITE MORE, I'LL PUT IT HERE BELOW! 19:25 17.12.2025