Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ZX Assembler Inline Basic
#1
ZXB allows you to do stuff that's pretty crazy.

I had a fancy cls routine - that didn't actually clear the screen, just ran a attribute bar over the screen, and then of course you do a CLS from basic afterwards. The effect is the same, but it looks cool.

It wouldn't compile right - the call to the ZX ROM sound routine kept corrupting things. Probably messing with IX and IY registers in naughty ways.

Then it occurred to me.... just compile a beep into the middle. :-)

Look:

Code:
sub clearscreen()
asm
    ld hl, 22528         ; 28000 33     0     88     10ts
    ld de, 32         ; 28003 17     32     0     10ts
l_6d66: push de             ; 28006 213 11ts
    push hl             ; 28007 229 11ts
    ld de, 32         ; 28008 17     32     0     10ts
    ld b, 24         ; 28011 6     22     7ts
l_6d6d: ld (hl), 24     ; Pick your leading bar attribute colour here.
    add hl, de         ; 28015 25     11ts
    djnz l_6d6d         ; 28016 16     251 8/13ts
    push de          ; save our registers before dropping to compiled code.
end asm
beep .05,-20
asm
    pop de           ; recover our register
    pop hl             ; (we didn't need to save HL, because we're resetting it)
    push hl             ; 28032 229 11ts
    ld b, 24         ; 28033 6     22     7ts
l_6d83: ld (hl), 63   ; Pick you final attribute here
    add hl, de         ; 28037 25     11ts
    djnz l_6d83         ; 28038 16     251 8/13ts
    pop hl             ; 28040 225 10ts
    pop de             ; 28041 209 10ts
    dec de             ; 28042 27     6ts
    inc hl             ; 28043 35     6ts
    ld a, d             ; 28044 122 4ts
    or e             ; 28045 179 4ts
    jr nz, l_6d66         ; 28046 32     214 7/12ts
    end asm
    cls : rem actually wipe the bits off the screen - we just ran an attribute bar before!
end sub

CLS
Print "hello world"
pause 1
pause 0

clearscreen()

print "Hello!"

How beautiful is that?
So long as I stack the registers I need (in this case DE), I can find them again when I come back. In a way, it's inline basic in the middle of assembler :-)

Anyway, that's my silliness for the day. Also: This makes for a nice clear screen subroutine. Change the bar colour and the final colour where indicated (and remember, ink and paper should be the same, so it does 'clear' it by hiding any characters on the screen until the CLS.

It's also pretty easy to change the sound (or remove it altogether - but you need something there to slow it down, or you don't see the effect. A busy loop or a pause would work too).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)