Subject: Firmware Functions

From: "Cyrano Jones" <cyranojones_lalp@...>
Date: Fri, 14 Dec 2007 08:35:43 -0000

// mailstation.h
//
// Function prototypes and other declarations needed
// for interfacing with the mailstation firmware.

#define sig_init       0x01
#define sig_suspend    0x02
#define sig_goprev     0x03
#define sig_gomain     0x04
#define sig_timer      0x05
#define sig_buttondown 0x06
#define sig_buttonup   0x07
#define sig_keydown    0x08
#define sig_keyup      0x09
#define sig_menu       0x0a

#define sig_draw       0x0d
#define sig_exit       0x14

#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2

typedef uint8_t byte;
typedef uint16_t word;

typedef struct {
   word string_id;
   word menu_id;
   byte scancode;
} FKEY_ITEM;

int get_ramdisk(uint16_t dummy, uint16_t code, uint16_t size);
int resize_ramdisk(int fh, uint16_t newsize);
int   read_ramdisk(int fh, uint8_t * dest, uint16_t n);
int  write_ramdisk(int fh, uint8_t * source, uint16_t n);
int   seek_ramdisk(int fh, int32_t offset, int origin);
int delete_ramdisk(int fh);

int  set_f_key_menu(int who, FKEY_ITEM * dataptr, int n);
void putevent_goprev(void);
int  new_timer(int who, uint16_t msec, int persist);
int  kill_timer(int timer);

int  draw_app_foldertab(char * title);

// These functions operate on dataflash files
int     add_record(uint16_t file, uint16_t n, uint8_t * source);
int  delete_record(uint16_t file, uint16_t rec);
int  modify_record(uint16_t file, uint16_t rec, uint16_t recoffset,
uint16_t n, uint8_t * source);
int   write_record(uint16_t file, uint16_t rec, uint16_t n, uint8_t *
source);
int    read_record(uint16_t file, uint16_t rec, uint16_t n, uint8_t *
dest);
int    delete_file(uint16_t file);
int    rename_file(uint16_t file1, uint16_t file2);
int  number_of_records(WORD filenum);

void enable_interrupts(void);
void disable_interrupts(void);

void delay(WORD msec);
void setled(WORD newstate);
int  low_battery_detect(void);
void cpuhalt(void);
void clearLCD(void);
void test_mode(WORD);

------------------------------------------------------------------
------------------------------------------------------------------

; mailstation.s

; In most cases the only thing needed here is to define the address of
; the firmware function.  SDCC will save most of it's registers when
; it calls another function, but for some reason it leaves the ix
register
; for the called function to save.  So if the mailstation function
happens
; to use ix without saving it first, we need a small wrapper here.

r_get_ramdisk         = 0x05DB
_resize_ramdisk     == 0x05DE
r_read_ramdisk        = 0x05E1
r_write_ramdisk     = 0x05E4
r_seek_ramdisk        = 0x05E7
_delete_ramdisk         == 0x05EA

_set_f_key_menu     == 0x0638
_putevent_goprev     == 0x066E
_new_timer             == 0x070D
_kill_timer         == 0x0713

_draw_app_foldertab == 0x0827

_add_record         == 0x0887
_delete_record         == 0x088D
_modify_record        == 0x0893
_write_record         == 0x0899
_read_record         == 0x089F
_delete_file         == 0x08A5
_rename_file        == 0x08AB

_number_of_records    == 0x08CF
_write_app             == 0x090B

_enable_interrupts     == 0x0A19
_disable_interrupts == 0x0A1B

_delay                 == 0x0A5C
_setled                == 0x0A77
_low_battery_detect == 0x0A7A
_cpuhalt             == 0x0A7D

_test_mode             == 0x0AAC

     .area _CODE
_get_ramdisk::
     ld (ixsave),ix
     pop ix
     ld (retsave),ix
     call r_get_ramdisk
     ld ix,(retsave)
     push ix
     ld ix,(ixsave)
     ret

_read_ramdisk::
     ld (ixsave),ix
     pop ix
     ld (retsave),ix
     call r_read_ramdisk
     ld ix,(retsave)
     push ix
     ld ix,(ixsave)
     ret

_write_ramdisk::
     ld (ixsave),ix
     pop ix
     ld (retsave),ix
     call r_write_ramdisk
     ld ix,(retsave)
     push ix
     ld ix,(ixsave)
     ret

_seek_ramdisk::
     ld (ixsave),ix
     pop ix
     ld (retsave),ix
     call r_seek_ramdisk
     ld ix,(retsave)
     push ix
     ld ix,(ixsave)
     ret

     .area _BSS
ixsave:  .ds 2
retsave: .ds 2

;; possibly a more compact way to wrap???  untested!!!
;
; Each wrapped function has it's own wrapper on the way in...
;_xxxxxxx::
;    ld   (ixsave),ix
;    ld   hl,#commonret
;   ex   (sp),hl
;    ld   (retsave),hl
;    ld   hl,#r_xxxxxxx
;    jp   (hl)

; ...but all wrapped functions use this single instance of ret code on
the way out.
;commonret:
;    ld   ix,(ixsave)
;    ld   de,(retsave)
;    jp   (de)

---

From: "Cyrano Jones" <cyranojones_lalp@...>
Date: Fri, 21 Dec 2007 10:43:42 -0000

> // for interfacing with the mailstation firmware.
<snip>

Here is another, a modal dialog box, with a text message
field, and various combinations of buttons.  I have
tentatively called it "messagebox", but I am interested
in hearing any other suggestions for the name.  Also
any suggestions for the param names, and constant
names would be helpful!

int  messagebox(uint16_t res_str, uint16_t flags);

res_str:
   a resource string number

flags:
   0x0100 = ok

   0x0200 = ok & cancel         (ok default)
   0x2200 = ok & cancel         (cancel default)

   0x0400 = yes & no            (yes default)
   0x2400 = yes & no            (no default)

   0x0800 = yes & no & cancel   (yes default)
   0x2800 = yes & no & cancel   (no default)
   0x4800 = yes & no & cancel   (cancel default)

retval:
   1 = ok
   2 = cancel
   3 = yes
   4 = no

put this in mailstation.s:
_messagebox == 0x07f1

----------------------------------------

Also, there is another function, at 0x0AD0, that
is the same as above except that it takes a normal
string instead of a resource string.  What would
that one be called???  Anybody out there????????

--
CJ