While I was a bit working on some ASM for mr womp womp's and my project, I thought of a *good* way to have 1 ASM program, while still keeping the compability with the CSE and the CE. The main difference between that too, is the 2- or 3-byte registers. So I thought of a way to detect whether it is an CE or an CSE.
Code:
21000000
23
23
01FFFF00
09
DAXXXX00
When running this on the CSE, it will be parsed as this:
ld hl, 0 \ nop
inc hl
inc hl
ld bc, $FFFF \ nop
add hl, bc
jp c, XXXX \ nop
Since 2+$FFFF > $FFFF, it will always jump to address XXXX. In the meantime, when running at the CE, it will look like this:
ld hl, 0
inc hl
inc hl
ld bc, $FFFF00
add hl, bc
jp c, XXXX00
But since 2+$FFFF00 < $FFFFFF, this code will never jump to address XXXX00, so that address may be *random*. Now let's practice. Let's say I want to display HL where HL is equal to $1234.
The code for this is ld hl, $1234[00]
bcall(_DispHL) or call _DispHL
When compiling for the CE, this would be 21003412
CDE01E02
or something like that. For the CSE, it will look like this:
213412
EFFE44
Now let's combine this into 1 program. Our frame was this:
21000000
23
23
01FFFF00
09
DAXXXX00
Now let's expand this. Since the calc will jump when overflow, thus when executing from the CSE, the code after the jump (NOT the jump-location) should be for the CE. So it would look like this:
21000000
23
23
01FFFF00
09
DAXXXX00
21003412
CDE01E02
C9
_Lbl_XXXX:
213412
EFFE44
C9
The last task is to figure out what the address of _Lbl_XXXX is. Just count the bytes of the code for the CE, and the bytes of the frame, and at that to _UserMem, or $0BA6, if I'm right. In my case, it would be this:
XXXX = $A623. Thus, my final code would look like this:
21000000
23
23
01FFFF00
09
DA23A600
21003412
CDE01E02
C9
213412
EFFE44
C9
Now, let's final running this on the CSE, would look like this: http://www.rafb.me/results/w8XJmL37.html
And at the CE: http://www.rafb.me/results/M1izML20.html
Note that the stuff that can crash, will never happen.
Hope that this helps to develop cross-compatible games! :D
Isn't the AsmPrgm token different on the two calculators?
I think the token automatically changes when on a different model, right?
Also nice stuff PT_ :)
Quote from: DJ Omnimaga on April 12, 2016, 03:33:32 PM
I think the token automatically changes when on a different model, right?
Also nice stuff PT_ :)
No, I figured out you can't run any z80 program at the CE. When you try it, it says "invalid". Then you need a second program to change the header, ie from the ez80 to the z80 would be $EF $7B -> $EF $69.
Wow, that's strange. I was 100% sure that when you sent a program that contained Asm84Cprgm to a TI-84 Plus, it changed to AsmPrgm and vice-versa and same with the CE. I mean, when you send a TI-82 program to a TI-84+, certain TI-82 commands will change automatically. I guess this is a protection TI added to prevent people from compiling unsquished ASM programs on the wrong calculator model and risking crashing their device.