/******************************************************************************
*
* project name:    TIGCC Tools Suite
* file name:       tthw.c
* initial date:    13/02/2001
* author:          thomas.nussbaumer@gmx.net
* description:     prints infos from the HW param block
*
*
* Will not work on HW1 calcs with very old AMS 1.00 !!
*
* $Id: tthw.c,v 1.5 2002/02/28 12:32:17 tnussb Exp $
*
******************************************************************************/

#define USE_TI89
#define USE_TI92P

#define OPTIMIZE_ROM_CALLS
#define NO_EXIT_SUPPORT
#define SAVE_SCREEN

#include <tigcclib.h>


typedef struct {
unsigned short size;         // offset 0
unsigned long  hw_id;        // offset 2
unsigned long  hw_rev;       // offset 6
unsigned long  bcode_ver;    // offset 10
unsigned long  bcode_rev;    // offset 14
unsigned long  bcode_build;  // offset 18
unsigned long  hw_type;      // offset 22
unsigned long  width;        // offset 26
unsigned long  height;       // offset 30
unsigned long  vis_width;    // offset 34
unsigned long  vis_height;   // offset 38
} HW_PARAM_BLOCK;


#define STEP_INCREMENT 8

//=============================================================================
// VTI detection routine (thanx, Julien Muchembled)
//
// this routine utilizes a bug in VTI: you can set even non-existing flags in
// the status register and query them later!
//=============================================================================
short IsVTI(void);
asm("IsVTI:\n"
"    trap   #12         /* enter supervisor mode. returns old (%sr) in %d0.w   */\n"
"    move.w #0x3000,%sr /* set a non-existing flag in %sr (but keep s-flag !!) */\n"
"    swap   %d0         /* save %d0.w content in upper part of %d0             */\n"
"    move.w %sr,%d0     /* get %sr content and check for non-existing flag     */\n"
"    btst   #12,%d0     /* this non-existing flag can only be set on the VTI   */\n"
"    bne    __VTI\n"
"    swap   %d0         /* restore old %sr content and return 0                */\n"
"    move.w %d0,%sr\n"
"    moveq  #0,%d0\n"
"    rts\n"
"__VTI:\n"
"    swap   %d0         /* restore old %sr content and return 1                */\n"
"    move.w %d0,%sr\n"
"    moveq  #1,%d0\n"
"    rts");




void _main(void) {
  HW_PARAM_BLOCK* hwpb = FL_getHardwareParmBlock();

  ClearScreen();
  FontSetSys(F_6x8);
  printf_xy(0,0,"== HwParamBlock (%s) ==",IsVTI()? "VTI":"CALC");
  printf_xy(0,STEP_INCREMENT*1,"size        = %u",hwpb->size);
  printf_xy(0,STEP_INCREMENT*2,"hw_id       = %lu (TI%s)",hwpb->hw_id, (hwpb->hw_id==3)?"89":"92p");
  printf_xy(0,STEP_INCREMENT*3,"hw_rev      = %lu",hwpb->hw_rev);
  printf_xy(0,STEP_INCREMENT*4,"bcode_ver   = %lu",hwpb->bcode_ver);
  printf_xy(0,STEP_INCREMENT*5,"bcode_rev   = %lu",hwpb->bcode_rev);
  printf_xy(0,STEP_INCREMENT*6,"bcode_build = %lu",hwpb->bcode_build);

  if (hwpb->size > 22) {
      printf_xy(0,STEP_INCREMENT*7,"hw_type     = %lu (HW2)",hwpb->hw_type);
      printf_xy(0,STEP_INCREMENT*8,"width       = %lu",hwpb->width);
      printf_xy(0,STEP_INCREMENT*9,"height      = %lu",hwpb->height);
      printf_xy(0,STEP_INCREMENT*10,"vis_width   = %lu",hwpb->vis_width);
      printf_xy(0,STEP_INCREMENT*11,"vis_height  = %lu",hwpb->vis_height);
  }
  else {
      printf_xy(0,STEP_INCREMENT*7,"hw_type     = HW1");
  }

  ngetchx();
}

//#############################################################################
//###################### NO MORE FAKES BEYOND THIS LINE #######################
//#############################################################################
//
//=============================================================================
// Revision History
//=============================================================================
//
// $Log: tthw.c,v $
// Revision 1.5  2002/02/28 12:32:17  tnussb
// unnecessary use of variable for y value removed by constants
//
// Revision 1.4  2002/02/11 09:57:21  tnussb
// (1) using now USE_TI89/USE_TI92P macros instead of short's (Lionel Debroux)
// (2) use compiler directive NO_EXIT_SUPPORT (Lionel Debroux)
// (3) minor size modifications
//
// Revision 1.3  2002/02/07 10:02:59  tnussb
// "deprecated multiline asm construct" compiler warning fixed
//
// Revision 1.2  2001/08/04 12:19:37  Thomas Nussbaumer
// stupid bug in display of "calc or VTI" fixed (NOT operator removed)
//
// Revision 1.1  2001/02/13 21:45:13  Thomas Nussbaumer
// initial version
//
