Page 2 of 5
Posted: Mon 25 Apr, 2005 3:16 pm
by Jim e
Man, now I wanna know what dwedit said. anyway, this a clearscreen routine, it was said somewhere else in prgm help. I figure it's good to put here too.
Code: Select all
;instead of
ld hl,gbuf
ld (hl),0
ld de,gbuf+1
ld bc,767
ldir
; try this
Clearbuf:
di ;becuase so many of you don't believe me when
ld hl,0 ; I say it is safe to have interrupts enabled.
ld d,h
ld e,l
add hl,sp
ld b,32
ld sp,gbuf+768
CBloop:
push de
push de
push de
push de
push de
push de
push de
push de
push de
push de
push de
push de
djnz CBloop
ls sp,hl
ret
The ret can be removed if you are only clearing the screen once in you prgram, but if not call it to clear the screen.
Posted: Mon 25 Apr, 2005 4:09 pm
by Kalimero
To check if a 16 bit value equals zero:
Posted: Mon 25 Apr, 2005 4:49 pm
by CoBB
Comparing two 16-bit values without destroying them:
This will also work with less arithmetic-friendly register pairs like BC and DE.
Posted: Mon 25 Apr, 2005 6:50 pm
by MissingIntellect
Jim e wrote:anyway, this a clearscreen routine, it was said somewhere else in prgm help. I figure it's good to put here too.
I believe that it's CoBB's routine, though I may be mistaken. Quite ingenious.
Posted: Mon 25 Apr, 2005 6:55 pm
by CoBB
I use 8 pushes in mine, but it's indeed practically the same.
Posted: Mon 25 Apr, 2005 7:01 pm
by Jim e
I don't who first came up with it, but i know I've used that for more than 3 or 4 years.
Posted: Mon 25 Apr, 2005 7:44 pm
by CoBB
I guess lots of people. It's not the most original idea around, really...
Posted: Mon 25 Apr, 2005 8:01 pm
by Gambit
Normally, you would use the following to increment a variable:
But if hl is not tied up and all you do is check flags, use indirection:
Code: Select all
ld hl,var
inc (hl)
ld a,(hl) ;Optional
@AndySoft: I think you were confusing immediate numbers and addresses... well, here is how
I keep it straight:
Code: Select all
ld hl,$5647 ;loads $56 -> h and $47 into l
Code: Select all
ld hl,86*256+71 ;also loads $56 -> h and $47 into l
Straight and simple. But lets say you want to store 0 -> (penCol) and 56 -> (penRow) with a 16-bit register; what I do is "reverse" them by imagining an X was drawn. So, by drawing the 'X', penCol should be first in the formula:
Code: Select all
ld hl,56*256+0 ;56 comes first
\ /
\ /
X
/ \
V V
ld (penCol),hl
It would also be handy to remember that
penCol comes before
penRow and
curRow comes before
curCol. Hope this helps anyone who gets confused
Posted: Mon 25 Apr, 2005 8:30 pm
by benryves
Gambit wrote:
Code: Select all
ld hl,86*256+71 ;also loads $56 -> h and $47 into l
Note that TASM will NOT compile that - you'd need to do it like this:
Code: Select all
ld hl,(86*256)+71 ;also loads $56 -> h and $47 into l
Posted: Mon 25 Apr, 2005 8:38 pm
by Jim e
I never had problems doing that. Though I know tasm doesn't do order of operations, it just goes in order from first to last.
Posted: Mon 25 Apr, 2005 9:03 pm
by benryves
I'm using TASM 3.2, and it won't parse it correctly for me...
Posted: Mon 25 Apr, 2005 9:14 pm
by Jim e
so am i.
Tasm wrote:Version 3.2b Feb, 2000
Posted: Mon 25 Apr, 2005 9:34 pm
by DarkerLine
Gambit wrote:Code: Select all
ld hl,$5647 ;loads $56 -> h and $47 into l
Code: Select all
ld hl,86*256+71 ;also loads $56 -> h and $47 into l
But the
opcode for that is $21 $47 $56, not $21 $56 $47, for those of us who are on-calc-inclined.
Posted: Mon 25 Apr, 2005 10:18 pm
by Stickmanofdoom
You might want to check out
http://www.shiar.org/ticalcs/z80optim.php for many optimizations.
Fast ways to divide A by powers of 2:
Code: Select all
div_2:
srl a
ret
div_4:
rra
rra
and %00111111
ret
div_8:
rra
rra
rra
and %00011111
ret
div_16:
rra
rra
rra
rra
and %00001111
ret
div_32:
rlca
rlca
rlca
and %00000111
ret
div_64:
rlca
rlca
and %00000011
ret
div_128:
rlca
and %00000001
ret
Thanks to CoBB for pointing out the div_8 to me.
Posted: Mon 25 Apr, 2005 10:22 pm
by koolmansam375
Yea i didnt know the ordering :-/ . You might have to switch it around to make it work correctly :p
well another optimization! : if you need to do (in either direction
instead use
also a useful instruction if you use either in a routine and need to save the other.