Alternatively, join us on Discord.

FastClr routine : a very fast way to clear screen !!!

Started by grosged, June 11, 2016, 09:08:29 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DJ Omnimaga


grosged

Better method, again  ;D

Yesterday I discussed with PT_ another method :

its aim is to clear while create coding !!

"Push de" is coded $d5
with "ld de,$d5d5d5",  a "push de" will create 3 "push de" !!..That's the trick :)

In 8bpp mode, whe have to clear 76800 bytes , using PUSHs we need 76800/3=25600 PUSHs
As a PUSH creates 3 PUSHs, we just need to clear/create 1/4 of 25600 = 6400 PUSHs :)
Then we will go inside this huge group of 19200 bytes $d5 to complete the 3/4 remaining to clear !!
Of course, we will write at the very end "ld sp,hl \ ei \ ret" to be able to quit the routine ;)

Here's the routine:
        ld      bc,$c9fbf9      ; pour écrire "ld sp,hl \ ei \ ret"
        ld      de,$d5d5d5      ; $d5=code de "push de"
        or      a               ; en PUSHant $d5d5d5, on crée du code
        sbc     hl, hl          ; (des PUSHs qui créent des PUSHs !!)
        di
        add     hl, sp          ; mémorise SP dans HL
        ld      sp,$D52C03
        push    bc
        ld      b,52
PushLp: .fill 123,$d5           ; 6400 = 52*123+4
        djnz    PushLp          ; là, on "PUSH DE" 6400 fois ( = 1/4 de l'effaçage écran)
        push    de              ; pour ensuite aller dedans!! (car c'est aussi du code!)
        push    de              ; (afin de de poursuivre l'effaçage des 3/4 restants de l'écran)
        push    de
        push    de
        jp      $d52C00-(6400*3)

length = 153 bytes only !

16+16+4+8+4+4+16+10+8+(123*10+13)*52-5+10+10+10+10+17+19200*10+4+4+21= 256803 states !!!

The constraint is we must clear using byte $d5
But that may not be a problem as , in 8bpp mode, we can modify the palette ;)

Snektron

Legends say if you spam more than DJ Omnimaga, you will become a walrus...


DJ Omnimaga

At this rate, you'll have a clear screen routine that it so fast that it will take a negative amount of time to execute, causing time travel of some sort... O.O

tr1p1ea

I like the idea of using the instruction byte as the cleared index, very clever :).

c4ooo

This is amazing  O.O
wont all the pushes cause a stack overflow?

MateoConLechuga

July 10, 2016, 12:51:41 am #21 Last Edit: July 10, 2016, 12:54:13 am by MateoConLechuga
 :-X
Quote from: c4ooo on July 05, 2016, 06:22:57 am
This is amazing  O.O
wont all the pushes cause a stack overflow?

This is literally a modified example from asm in 28 days. If you read the section, it will describe more of what it is doing :)

Of course, I do like the code creation and then executing aspect. Although it would be difficult to implement correctly, it is pretty neat.

c4ooo

Quote from: MateoConLechuga on July 10, 2016, 12:51:41 am
:-X
Quote from: c4ooo on July 05, 2016, 06:22:57 am
This is amazing  O.O
wont all the pushes cause a stack overflow?

This is literally a modified example from asm in 28 days. If you read the section, it will describe more of what it is doing :)

Of course, I do like the code creation and then executing aspect. Although it would be difficult to implement correctly, it is pretty neat.

Ohh you mean page 10? http://tutorials.eeems.ca/ASMin28Days/lesson/day10.htm
TBH i never fully read that guide, merely skimmed over the pages that i needed :P

Powered by EzPortal