Firmware Functions (Dec 14, 2007)

(home)
  1. From: "Cyrano Jones" Dec 21, 2007


Subject: Firmware Functions

From: "Cyrano Jones" <cyranojones_lalp@...>

Dec 14, 2007


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

#define sig_init 0x0=
1
#define sig_suspend 0x02
#define sig_goprev 0x03
#define sig_gomai=
n 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

typ=
edef uint8_t byte;
typedef uint16_t word;

typedef struct {
word string_=
id;
word menu_id;
byte scancode;
} FKEY_ITEM;

int get_ramdisk(uint1=
6_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 w=
rite_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_k=
ey_menu(int who, FKEY_ITEM * dataptr, int n);
void putevent_goprev(void);
i=
nt new_timer(int who, uint16_t msec, int persist);
int kill_timer(int tim=
er);

int draw_app_foldertab(char * title);

// These functions operate on=
dataflash files
int add_record(uint16_t file, uint16_t n, uint8_t * so=
urce);
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 * sour=
ce);
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 f=
ile1, uint16_t file2);
int number_of_records(WORD filenum);

void enable_i=
nterrupts(void);
void disable_interrupts(void);

void delay(WORD msec);
voi=
d 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 thi=
ng needed here is to define the address of
; the firmware function. SDCC w=
ill save most of it's registers when
; it calls another function, but for s=
ome 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, w=
e need a small wrapper here.

r_get_ramdisk =3D 0x05DB
_resize_ram=
disk =3D=3D 0x05DE
r_read_ramdisk =3D 0x05E1
r_write_ramdisk =
=3D 0x05E4
r_seek_ramdisk =3D 0x05E7
_delete_ramdisk =3D=3D=
0x05EA

_set_f_key_menu =3D=3D 0x0638
_putevent_goprev =3D=3D 0x06=
6E
_new_timer =3D=3D 0x070D
_kill_timer =3D=3D 0x0713

=
_draw_app_foldertab =3D=3D 0x0827

_add_record =3D=3D 0x0887
_delet=
e_record =3D=3D 0x088D
_modify_record =3D=3D 0x0893
_write_r=
ecord =3D=3D 0x0899
_read_record =3D=3D 0x089F
_delete_file=
=3D=3D 0x08A5
_rename_file =3D=3D 0x08AB

_number_of_record=
s =3D=3D 0x08CF
_write_app =3D=3D 0x090B

_enable_interrupts=
=3D=3D 0x0A19
_disable_interrupts =3D=3D 0x0A1B

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

_test_mode =
=3D=3D 0x0AAC

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

_read_ramdisk::
ld (ixsave),i=
x
pop ix
ld (retsave),ix
call r_read_ramdisk
ld ix,(ret=
save)
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_ram=
disk
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 wa=
y out.
;commonret:
; ld ix,(ixsave)
; ld de,(retsave)
; jp (=
de)


and other declarations needed<br>// for interfacing with the mailstation f=
irmware.<br><br>#define sig_init       0x01<b=
r>#define sig_suspend    0x02<br>#define sig_goprev &nb=
sp;   0x03<br>#define sig_gomain     0x04<br>=
#define sig_timer      0x05<br>#define sig_buttond=
own 0x06<br>#define sig_buttonup   0x07<br>#define sig_keydown&nb=
sp;   0x08<br>#define sig_keyup      0x0=
9<br>#define sig_menu       0x0a<br><br>#defi=
ne sig_draw       0x0d<br>#define sig_exit&nb=
sp;      0x14<br><br><br>#define SEEK_SET 0<br>#de=
fine SEEK_CUR 1<br>#define SEEK_END 2<br><br><br>typedef uint8_t byte;<br>t=
ypedef uint16_t word;<br><br>typedef struct {<br>  word string_id;<br>=
  word menu_id;<br>  byte scancode;<br>} FKEY_ITEM;<br><br><br>in=
t get_ramdisk(uint16_t dummy, uint16_t code, uint16_t size);<br>int resize_=
ramdisk(int fh, uint16_t newsize);<br>int   read_ramdisk(int fh, =
uint8_t * dest, uint16_t n);<br>int  write_ramdisk(int fh, uint8_t * s=
ource, uint16_t n);<br>int   seek_ramdisk(int fh, int32_t offset,=
int origin);<br>int delete_ramdisk(int fh);<br><br><br>int  set_f_key=
_menu(int who, FKEY_ITEM * dataptr, int n);<br>void putevent_goprev(void);<=
br>int  new_timer(int who, uint16_t msec, int persist);<br>int  k=
ill_timer(int timer);<br><br>int  draw_app_foldertab(char * title);<br=
  add_record(uint16_t file, uint16_t n, uint8_t * source);  =
 <br>int  delete_record(uint16_t file, uint16_t rec);  =
;  <br>int  modify_record(uint16_t file, uint16_t rec, uint16_t r=
ecoffset, uint16_t n, uint8_t * source);    <br>int &nb=
sp; write_record(uint16_t file, uint16_t rec, uint16_t n, uint8_t * source)=
;  <br>int    read_record(uint16_t file, uint16_t rec, =
uint16_t n, uint8_t * dest); <br>int    delete_file(uint16_t=
file);<br>int    rename_file(uint16_t file1, uint16_t file2=
);<br>int  number_of_records(WORD filenum);<br> <br>void enable_i=
nterrupts(void);<br>void disable_interrupts(void);<br><br>void delay(WORD m=
sec);<br>void setled(WORD newstate);<br>int  low_battery_detect(void);=
ation.s<br><br>; In most cases the only thing needed here is to define the =
address of<br>; the firmware function.  SDCC will save most of it's re=
gisters when<br>; it calls another function, but for some reason it leaves =
the ix register<br>; for the called function to save.  So if the mails=
tation function happens<br>; to use ix without saving it first, we need a s=
mall wrapper here.<br><br><br>r_get_ramdisk       =
  =3D 0x05DB   <br>_resize_ramdisk     =3D=3D=
0x05DE   <br>r_read_ramdisk       =
=3D 0x05E1   <br>r_write_ramdisk     =3D 0x05E4&n=
bsp;   <br>r_seek_ramdisk        =
=3D 0x05E7     <br>_delete_ramdisk    &n=
bsp;    =3D=3D 0x05EA      &nb=
sp;            =
       <br><br>_set_f_key_menu  &nb=
sp;  =3D=3D 0x0638 <br>_putevent_goprev     =3D=3D 0x06=
6E  <br>_new_timer           &=
nbsp; =3D=3D 0x070D <br>_kill_timer         =
=3D=3D 0x0713 <br><br>_draw_app_foldertab =3D=3D 0x0827 <br><br>_add_record=
        =3D=3D 0x0887   <br>_delet=
e_record         =3D=3D 0x088D  <br=
sp; <br>_write_record         =3D=3D 0x0899&n=
bsp; <br>_read_record         =3D=3D 0x089F&n=
bsp; <br>_delete_file         =3D=3D 0x08A5 <=
br>_rename_file        =3D=3D 0x08AB <br>&nbs=
p;<br>_number_of_records    =3D=3D 0x08CF <br>_write_app&nbs=
p;            =3D=3D 0x090B&nb=
sp; <br><br>_enable_interrupts     =3D=3D 0x0A19  =
         <br>_disable_interrupts =
=3D=3D 0x0A1B  <br><br>_delay       &nbs=
p;         =3D=3D 0x0A5C <br>_setled &nb=
sp;              =3D=
=3D 0x0A77<br>_low_battery_detect =3D=3D 0x0A7A     <br=
x0A7D<br><br>_test_mode           &=
nbsp; =3D=3D 0x0AAC  <br><br><br><br>    .area _CODE<br=
pop ix<br>    ld (retsave),ix<br>    call r_g=
et_ramdisk<br>    ld ix,(retsave)<br>    push=
ix<br>    ld ix,(ixsave)<br>    ret<br><br><=
br>_read_ramdisk::<br>    ld (ixsave),ix<br>  &nbs=
p; pop ix<br>    ld (retsave),ix<br>    call =
r_read_ramdisk<br>    ld ix,(retsave)<br>    =
push ix<br>    ld ix,(ixsave)<br>    ret<br><=
br><br>_write_ramdisk::<br>    ld (ixsave),ix<br>  =
;  pop ix<br>    ld (retsave),ix<br>    =
call r_write_ramdisk<br>    ld ix,(retsave)<br>  &=
nbsp; push ix<br>    ld ix,(ixsave)<br>    re=
t<br><br><br>_seek_ramdisk::<br>    ld (ixsave),ix<br> =
   pop ix<br>    ld (retsave),ix<br>  &n=
bsp; call r_seek_ramdisk<br>    ld ix,(retsave)<br> &nb=
sp;  push ix<br>    ld ix,(ixsave)<br>   =
; ret<br><br>    .area _BSS<br>ixsave:  .ds 2<br>retsav=
e: .ds 2<br><br>;; possibly a more compact way to wrap???  untested!!!=
_xxxxxxx::<br>;    ld   (ixsave),ix<br>; &nbs=
p;  ld   hl,#commonret<br>;   ex   (sp),=
hl<br>;    ld   (retsave),hl<br>;   =
; ld   hl,#r_xxxxxxx<br>;    jp   (hl)<b=
r><br>; ...but all wrapped functions use this single instance of ret code o=
n the way out.<br>;commonret:    <br>;    ld&=
nbsp;  ix,(ixsave)<br>;    ld   de,(retsave)<=
br>;    jp   (de)<br><br><br><br><br></font>



1: Subject: Re: Firmware Functions

(top)

From: "Cyrano Jones" <cyranojones_lalp@...>

Dec 21, 2007



g with the mailstation firmware.

Here is another, a modal dialog bo=
x, with a text message
field, and various combinations of buttons. I have
=
tentatively called it "messagebox", but I am interested
in hearing any othe=
r 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 =3D ok

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

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

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

retval:
1 =3D ok
2 =3D canc=
el
3 =3D yes
4 =3D no

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


Also, there is another f=
unction, 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??? An=
ybody out there????????

CJ


lp@...> wrote:<br>><br>> // mailstation.h<br>> //<br>> // Fu=
nction prototypes and other declarations needed<br>> // for interfacing =
with the mailstation firmware.<br><snip><br><br>Here is another, a mo=
dal dialog box, with a text message<br>field, and various combinations of b=
uttons.  I have <br>tentatively called it "messagebox", but I am inter=
ested <br>in hearing any other suggestions for the name.  Also <br>any=
suggestions for the param names, and constant <br>names would be helpful!<=
br><br>int  messagebox(uint16_t res_str, uint16_t flags);<br><br>res_s=
tr: <br>  a resource string number<br><br>flags:<br>  0x0100 =3D =
     <br><br>  0x0200 =3D <b>ok</b> & cancel&n=
bsp;        (ok default)<br>  0x220=
0 =3D ok & <b>cancel</b>        =
; (cancel default)<br><br>  0x0400 =3D <b>yes</b> & no  =
          (yes default)<br>&nb=
sp; 0x2400 =3D yes & <b>no</b>       =
;     (no default)<br><br>  0x0800 =3D <b>yes</b> =
& no & cancel   (yes default)<br>  0x2800 =3D yes &a=
mp; <b>no</b> & cancel   (no default)<br>  0x4800 =3D ye=
s & no & <b>cancel</b>   (cancel default)<br><br>retval:<=
br>  1 =3D ok<br>  2 =3D cancel<br>  3 =3D yes<br>  4 =
=3D no<br><br><br>put this in mailstation.s:<br>_messagebox =3D=3D 0x07f1<b=
r><br>----------------------------------------<br><br>Also, there is anothe=
r function, at 0x0AD0, that<br>is the same as above except that it takes a =
normal<br>string instead of a resource string.  What would<br>that one=
be called???  Anybody out there????????<br><br>--<br>CJ<br><br><br><b=
r>              &nbs=
p;   </font>