Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Memory Management
#2
britlion Wrote:Why not just put your org lower, have your low non speed critical functions, use align to hop to 32768 and stick a defs 6912, 0 to skip your screen buffer zone?

That's an idea except that would make the compiler runtime low as well
so that is not an option. Or place the screen buffer at top and experiment
with the ORG so the program compiles right up to the screen buffer and
that would work with some programs but you would have no control over
what goes where and the runtime again would be at the low end of the
memory.

I rewrote the ATTR routine and it is as follows:
Code:
Declare sub SetAttr (ByVal Line as ubyte, ByVal Column as ubyte, ByVal NumberOfCells as uinteger)

Dim AttrAddress as uinteger = 22528
---
bla
----

Sub SetAttr (ByVal Line as ubyte, ByVal Column as ubyte, ByVal NumberOfCells as uinteger)

'Dim AttrAddress as uinteger = 22528
'Dim EndAttrAddress as uinteger
'Dim AttrColor as ubyte at 23693
'AttrAddress = AttrAddress + (cast(uinteger, Line) shl 5) + cast(uinteger, Column) ' Line * 32
'EndAttrAddress = AttrAddress + NumberOfCells

AttrAddress = AttrAddress
Asm
push hl
ld l, (ix+5)
ld h, 0
add hl, hl
add hl, hl
add hl, hl
add hl, hl
add hl, hl
ex de, hl
pop hl
add hl, de
push hl
ld l, (ix+7)
ld h, 0
ex de, hl
pop hl
add hl, de
ld c, (ix+8)
ld b, 0
ld a, (23693)
ld e, a
SetAttrCopy:
ld a, e
ld (hl), a
inc hl
dec bc
ld a, b
or c
jr nz, SetAttrCopy
End asm

'Do
'  Poke AttrAddress, AttrColor
'  AttrAddress = AttrAddress + 1
'Loop until AttrAddress = EndAttrAddress

End sub

NumberOfCells is treated as a ubyte in the ASM code instead of uinteger, it
saves me one indexing instruction, the BC register pair. The declareation
of AttrAddress is moved into global scobe instead of local as that saves in
indexing instuctions as well and they are slow.

If i rem out the global declaration of AttrAddress and the ASM section and
"AttrAddress = AttrAddress" and unrem the other parts then the resulting
code is 90 bytes larger with 22 indexing instructions instead of three and
of those 10 are in the Do-Loop section if I counted correctly.

I use AttrAddress = AttrAddress to make sure that it is the HL register pair
before the code moves on. The resulting code with O2 is:
ld hl, (_AttrAddress)
ld (_AttrAddress), hl

If the O3 level get's smarter isn't there a danger that is will be optimized out?
Does it matter for I did compile this without "AttrAddress = AttrAddress" and
it did work fine but that could have been luck for this is the first uinteger
variable declared in the global scobe and as such it could have been in HL
I don't know but I would never depend on such luck so the question does
matter.

Maybe someone can use this code.

Darkstar.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)