CodeWalrus

Development => Calculators => Calculator News, Coding, Help & Talk => Topic started by: Snektron on January 09, 2015, 05:41:10 PM

Title: Axiom LUT Troubles
Post by: Snektron on January 09, 2015, 05:41:10 PM
So im trying to do a fast square in an Axiom.
im using a LUT i generated but it keeps outputting the wrong values.

.dw ShdDraw_
.db AXM_ALL
.dw $00F3
.db AXM_SUB
.db AXM_1ARG
.org 0
ld l, 0
call squareL
bcall(_DispHL)
bcall(_getKey)
ret

; square l, return in hl
squareL:
ld hl, (SqLUT)
ret

SqLUT:
.dw $0000, $0001, $0004, $0009, $0010, $0019...
ShdDraw_:

This is the code for the Command, and obviously the LUT is way bigger so i stripped it a bit down.
For debugging purposes i print the first byte at hl, which should be 0 but isn't...
Anyone got an idea of what im doing wrong? q.q

EDIT: Looks like it's something with a 16-bit load command
EDIT2: I have the 0! now for the rest of the values...
EDIT3: Okay so i did some data analysing...
Seems like verything up until 22 goes OK... then
23^2 is 39598... then the values are offset 1 for a few numbers (eg 25^2 displays as 26^2)
after a while its just random values...
also my code now looks like this:


squareL:
ld h, 0
sla l
rl h ;l*2 in hl
REP_NEXT
ld de, SqLUT
add hl, de ; address in hl
dec hl
ld d, (hl)
inc hl
ld e, (hl)
ex de, hl
ret

SqLUT:
.dw $0000, $0001, $0004, $0009, $0010, $0019, $0024, $0031... etc

EDIT4: Ok so ive narrowed the problem down to the loading the address into hl part...

ld hl, SqLUT + 96  ; for debugging purposes, this is one of the faulty numbers (48)
dec hl
ld d, (hl)
inc hl
ld e, (hl)
ex de, hl

EDIT5: My god... it finally works... don't have any dea of how i fixed it though...
EDIT6: Oh nvm, it worked in my test program... not in the axiom (im getting tired of this)
EDIT7: I finally got it working! :D
If someone wants to know what the correct way is:
Axe uses a few bytes for special things (like loading into 16bit registers). If those bytes are in your data,
axe will replace them and everything will fail :(.'
The solution is to make another Axiom command, but with AXM_DATA as type.
The special bytes will not be applied to commands with this byte set.


.dw some_command_
.db AXM_ALL
.dw token
.db AXM_SUB
.db AXM_1ARG
.org $0000
REP_NEXT ; don't forget
ld hl, sub_Axiom2 ; replace the 2 with whatever # command your data block is at
; start of the data address is now in hl
some_command_:

.dw data_block_
.db AXM_ALL
.dw $0000   ; it can only be called from other commands
.db AXM_DATA
.db AXM_1ARG
.org $0000
; data here
data_block_:
Title: Re: Axiom LUT Troubles
Post by: Dream of Omnimaga on January 10, 2015, 05:32:24 AM
Sorry to hear that it doesn't work still. Hopefully someone can help soon (although I think only one or two CodeWalrus members know ASM >.<). If you don't get any help, you might need to ask Runer112 on Omnimaga since he's the current maintainer of Axe.
Title: Re: Axiom LUT Troubles
Post by: Snektron on January 10, 2015, 11:16:48 AM
Yeah i think ill probably have to do that
EDIT: IT WORKS! :D
Title: Re: Axiom LUT Troubles
Post by: Dream of Omnimaga on January 10, 2015, 12:30:23 PM
Awesome to hear :D. Could you tell us what caused the problem?
Title: Re: Axiom LUT Troubles
Post by: Snektron on January 10, 2015, 12:33:32 PM
I've already updated the post :P
Title: Re: Axiom LUT Troubles
Post by: Dream of Omnimaga on January 10, 2015, 07:08:52 PM
Not sure if I understand. Was it some sort of data usage conflict?
Title: Re: Axiom LUT Troubles
Post by: Thecoder1998 on January 10, 2015, 10:00:48 PM
Nice work!
Title: Re: Axiom LUT Troubles
Post by: Snektron on January 10, 2015, 11:28:49 PM
Quote from: DJ Omnimaga on January 10, 2015, 07:08:52 PM
Not sure if I understand. Was it some sort of data usage conflict?
Sort of...
Since axioms are not always in the same ram area (eg if theres code before the command), axe updates it when it compiles the program.
This means the addresses of each call, jump etc needs to be  changed as well, However, it does not change 16-bit loading (like labels).
To make this manually happen is to place a special byte 7F, 40 or 49 before the command. If the data contains one of these characters, it gets removed.
In order to keep the data intact, it needs to be placed in a special "command" with as type AXM_DATA. Then, one can load the starting address of this command
with ld rr, sub_Axiom# (where # the #'th command in the axiom is), prefixed with 7F.
Since the byte gets removed during compilation, we need to tell the assembler that it's "not there". Axe included a small define for this in it's include file, "REP_NEXT".