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:
Code:
When running this on the CSE, it will be parsed as this:
Code:
Since 2+$FFFF > $FFFF, it will always jump to address XXXX. In the meantime, when running at the CE, it will look like this:
Code:
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
Code:
When compiling for the CE, this would be
Code:
or something like that. For the CSE, it will look like this:
Code:
Now let's combine this into 1 program. Our frame was this:
Code:
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:
Code:
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:
Code:
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! đ
Code:
Code:
21000000
23
23
01FFFF00
09
DAXXXX00When running this on the CSE, it will be parsed as this:
Code:
ld hl, 0 \ nop
inc hl
inc hl
ld bc, $FFFF \ nop
add hl, bc
jp c, XXXX \ nopSince 2+$FFFF > $FFFF, it will always jump to address XXXX. In the meantime, when running at the CE, it will look like this:
Code:
ld hl, 0
inc hl
inc hl
ld bc, $FFFF00
add hl, bc
jp c, XXXX00But 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
Code:
ld hl, $1234[00]
bcall(_DispHL) or call _DispHLWhen compiling for the CE, this would be
Code:
21003412
CDE01E02Code:
213412
EFFE44Now let's combine this into 1 program. Our frame was this:
Code:
21000000
23
23
01FFFF00
09
DAXXXX00Now 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:
Code:
21000000
23
23
01FFFF00
09
DAXXXX00
21003412
CDE01E02
C9
_Lbl_XXXX:
213412
EFFE44
C9The 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:
Code:
21000000
23
23
01FFFF00
09
DA23A600
21003412
CDE01E02
C9
213412
EFFE44
C9Now, 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! đ




