I got a preliminary ti_getk() and ti_getch() function working, but it doesn't have all the z88dk bells and whistles like fastmem and naked, and I think I need to disable/enable interrupts


Code:

int ti_getk();
int ti_getch();

#asm
_ti_getk:
 rst     $28
 defw    $4972
 ld       l, a
 ld       h, 0
 ret
_ti_getch:
 rst    $28
 defw    $4018
 ld       l, a
 ld       h, 0
 ret
#endasm


This does the same codes as GetKey in TI BASIC, and you also get the GetCSC codes too. A port read key scanner would be MINT

Also it would be nice to have guards to change the vector if you're using Asm(, DCS, etc

**EDIT**
I'll add a ti_ScanKeys(x) where you can pass in a code https://en.wikibooks.org/wiki/TI_83_Plus_Assembly/Input#Direct_Input and get the byte mask. A z88dk pr would also include a global buffer like how it works in the CE toolchain.
ti_ScanKeys(x) sounds perfect. It's easy to wrap it in C functions that were written for the CE, and it doesn't use any ROM calls, so it is perfectly portable between different calculator models. Woo!

Code:

#ifndef   TI_KEYS_H
#define   TI_KEYS_H

#define   ti_getchar()   ti_getkey()
#define   ti_getch()   ti_getcsc()
#define   ti_ScanKeys(a)   ti_scank(a)

int ti_getkey();
int ti_getcsc();
int ti_scank();

#asm
PUBLIC _ti_getkey
_ti_getkey:
 rst   $28
 defw   $4972
 ld   l, a
 ld   h, 0
 ret
#endasm
#asm
PUBLIC _ti_getcsc
_ti_getcsc:
 rst   $28
 defw   $4018
 ld   l, a
 ld   h, 0
 ret
#endasm
#asm
PUBLIC _ti_scank
_ti_scank:
 ld   l, ( ix + 4 )
 ld   h, ( ix + 5 )
 ret
#endasm

#endif


For later
Also, I can't really figure it out, but does z88dk wrap functions with push/pop of ix,iy and whatnot? So if I put a RET in there, am I just messing the stack up royally?

Code:

#pragma string name SPRITES
#pragma output nostreams
#include <stdio.h>
#include <graphics.h>
#include <games.h>
#include <ti.h>
#include "ti_keys.h"

#define   GATE_SIZE   10
#define   NUM_GATES   2

#define   AND_GATE   gates
#define   OR_GATE      gates+10

typedef unsigned char byte;

char gates[];

#asm
._gates
 defb   8,8      // AND gate
 defb   @01111000
 defb   @11000100
 defb   @01000010
 defb   @01000010
 defb   @01000010
 defb   @01000010
 defb   @11000100
 defb   @01111000
 defb   8,8      // OR gate
 defb   @01111000
 defb   @11000100
 defb   @00100010
 defb   @00100010
 defb   @00100010
 defb   @00100010
 defb   @11000100
 defb   @01111000
#endasm

byte x, y;
char *sprite, *new_sprite_ptr;

void drawspr()
{
   putsprite( SPR_XOR, x, y, sprite );
}

int main()
{
   byte c;

   x = 0;
   y = 0;
   sprite = AND_GATE;
   
   do
   {
      drawspr();
      c = ti_getkey();
      drawspr();
      switch ( c )
      {
         case   3:   y -= ( y > 0 ); break;         // up
         case   4:   y += ( y < ( getmaxy() - 7 ) ); break;   // down
         case   2:   x -= ( x > 0 ); break;         // left
         case   1:   x += ( x < ( getmaxx() - 7 ) ); break;   // right
         case   69:   new_sprite_ptr = sprite + GATE_SIZE;
               sprite = ( ( new_sprite_ptr ) >= ( gates + ( NUM_GATES * GATE_SIZE ) ) ) ? gates : new_sprite_ptr;
               break;               // MODE
         case   9:   goto exit; break;
         default:   break;
      }
   } while ( 1 );
exit:
   return 0;
}


Compiles to 903 bytes. z88dk has even smaller versions of the clib that cut out extraneous stuff but I don't know what it sacrifices so I'd like to experiment with that!
Currently working on the logic simulator, trying to get the heap correctly set up
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement