title: How to write two bytes to a chunk of RAM repeatedly in Z80 asm
body: <p>I'm trying to write two bytes (color values) to the VRAM of my TI-84 Plus CE-T calculator, which uses the Zilog eZ80 CPU. The VRAM starts at 0xD40000 and is 0x25800 bytes long. The calculator has a built in syscall called <code>MemSet</code>, which fills a chunk of memory with one byte, but I want it to alternate between two different values and store these in memory. I tried using the following code:</p>
  
  <pre><code>#include "includes\ti84pce.inc"
  
      .assume ADL=1
      .org userMem-2
      .db tExtTok,tAsm84CeCmp
  
      call  _homeup
      call  _ClrScrnFull
      ld    hl,13893632     ; = D40000, vram start
      ld    bc,153600       ; = 025800, count/vram length
  j1:
      ld    (hl),31         ; set first byte
      inc   hl
      dec   bc
      jr    z,j2            ; jump to end if count==0
      ld    (hl),0          ; set second byte
      inc   hl
      dec   bc
      jr    z,j2            ; jump to end if count==0
      jp    j1              ; loop
  j2:
      call  _GetKey
      call  _ClrScrnFull
      ret
  </code></pre>
  
  <p>I want it to output 31 00 31 00 31 00... into memory starting at 0xD40000, but instead it seems to change only the first byte and jump to the end after doing so. Any ideas on how to fix this?</p>