0

In the process of attempting to write assembly for my TI-84 PlusCE I came across an odd "bug". Consider the following code:

#include "includes\ti84pce.inc"

s_mem_start = saveSScreen

 .assume ADL=1
 .org userMem-2
 .db tExtTok,tAsm84CeCmp

 ;relevant portion
 ld HL, s_mem_start
 ld DE, 2
 ADD HL, DE
 ld D, H
 ld E, L

 ld A, (HL)
 call _PutC
 ld A, (DE)
 call _PutC
 ;/relevant portion

 ret

saveSScreen is a portion of free ram. _PutC is a rom call that prints the value of A to the screen. See this chart: http://tibasicdev.wikidot.com/83lgfont. I have confirmed the _PutC does not affect any registers. The output of this code to the screen is v[CursorInsertSecond]. (CursorInsertSecond is a character on the calculator). These are equivalent to the hex 03 or 73 and E5. I can't tell if the v is the regular v or the italic v.

Clearly (HL) and (DE) are accessing different parts of memory. This is also the same when using BC. The odd thing is I can't find this information recorded anywhere. It would seem a major detriment to only have one register pair for accessing memory. Indeed it has made my own code feel very bloated.

The final odd thing that I have noticed is that this only seems to apply when adding to HL. Consider this code: (Minus the header portion).

 ld HL, s_mem_start + 2
 ld DE, s_mem_start + 2

 ld A, (HL)
 call _PutC
 ld A, (DE)
 call _PutC

This results in the output vv. What could be going on here? Why do (HL) and (DE) give different outputs but only some of the time.

user197974
  • 229
  • 2
  • 6
  • My guess is that `_PutC` corrupts your data at `s_mem_start+2`. Maybe it isn't free ram after all :) What happens if you do the `(DE)` load before the first `_PutC` and push the value then pop it for the second invocation? What happens if you first print the `(DE)` and the `(HL)` second? – Jester Aug 08 '20 at 22:22
  • @Jester every result is the same no matter what combination of stuff I do. The ram is used for storing a back up of the screen so I find it highly unlikely that it is being overwritten. This also wouldn't explain why the second piece of code works differently. – user197974 Aug 08 '20 at 22:26
  • The second code as shown uses `s_mem_start` and not `s_mem_start+2`. Maybe try that then? – Jester Aug 08 '20 at 22:34
  • @Jester no dice. Two vs instead of ns though. I'll edit the question to fix that. – user197974 Aug 08 '20 at 22:37

1 Answers1

8

It turns out that the ti84plusce actually runs ez80 assembly. In ez80 assembly HL, BC, and DE are three bytes not two. My code only copied two of the bytes and thus the addresses got messed up.

user197974
  • 229
  • 2
  • 6
  • yeah, we discussed this not so long ago in [this topic](https://stackoverflow.com/questions/57483503/how-to-write-two-bytes-to-a-chunk-of-ram-repeatedly-in-z80-asm/57494588#57494588) – tum_ Sep 26 '20 at 19:44