Subject: helloapp.asm

From: "Cyrano Jones" <cyranojones_lalp@...>
Date: Thu, 26 Jul 2007 08:19:47 -0000

; Hello World, as a mailstation app.

; As best I can recall, this code has never been tested, mainly
; because I never finished adding function to mailbug that will
; load dataflash.  I am posting this because I believe it correctly
; shows the structure of a mailstation app.

; some functions we will use from the mailstation rom
localize              equ #056b  ;localize(register de = -byteslocal)
draw_app_foldertab    equ #0827  ;Draw_app_foldertab(stringptr)
set_f_key_menu        equ #0638  ;set_f_key_menu(who, dataptr, num_rows)
init_widget_thingy    equ #072B  ;init_widget_thingy(tab16row,
thingyptr)
draw_icon_wc          equ #0743  ;draw_icon_wc(thingyptr, x, y, iconnum)
put_event_go_prev_app equ #066e
defaulthandler        equ #0602  ;defaulthandler(who, tab30.6, signal,
par6, par8)

        ORG  #4000        ; This is *always* #4000, regardless of what
                          ; page you use.

        JP    eventhandler
        DEFW  icons
        DEFW  caption
        DEFW  dunno

dunno: DEFB #00
xpos:  DEFW #0000
ypos:  DEFW #0000

caption:
        DEFW  #0001             ; ?????
        DEFW  endcap-caption-6  ; num of chars
        DEFW  #0006             ; offset to first char
        defm "Hello World"      ; the caption string
endcap:

       org   #4064            ; not sure this is needed

icons:
       defw  icon2 - icon1    ; size icon1
       defw  icon1 - icons    ; offset to icon1   (icon at #406c)
       defw  iconend - icon2  ; size icon2
       defw  icon2 - icons    ; offset to icon2

icon1:
; The first icon is used in the mailstation menu.
;     First the size data (standard mailstation menu icons are 34 x 34)
       defw #0022  ; icon width  (#0022 = 34 dec = 4.25 bytes,
                   ; rounded up, means 5 bytes per row)
       defb #22    ; icon height (34 dec pix rows high)

;     Then the icon bitmap   (lo order bit displays on LEFT of each
byte!)
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#00,#aa,#aa
       defb  #55,#55,#00,#55,#55, #aa,#aa,#00,#aa,#aa
       defb  #55,#55,#00,#55,#55, #aa,#aa,#00,#aa,#aa
       defb  #55,#55,#00,#55,#55, #aa,#aa,#00,#aa,#aa
       defb  #55,#55,#00,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa
       defb  #55,#55,#55,#55,#55, #aa,#aa,#aa,#aa,#aa

icon2:
; In official apps, the second icon would be the TV guide,
; weather, news, etc., stored as a full screen (320 x 128) image.
; This is used when the app needs to draw itself.
; Your app may not need this icon.
       defw  #0030   ; width
       defb  #22     ; height
       defb  #00,#00,#04,#E0,#03,#00, #F0,#01,#0F,#3E,#07,#00
       defb  #9C,#02,#0F,#7F,#0C,#00, #04,#86,#07,#93,#09,#00
       defb  #42,#C2,#01,#A0,#0B,#00, #F3,#44,#9E,#FF,#0A,#00
       defb  #91,#F6,#F3,#F6,#0D,#00, #99,#8C,#4E,#E6,#07,#00
       defb  #F1,#C1,#46,#2E,#06,#00, #93,#40,#44,#44,#0C,#00
       defb  #3E,#C0,#C0,#40,#08,#00, #10,#80,#C0,#41,#0C,#00
       defb  #10,#80,#EB,#27,#06,#00, #18,#00,#3F,#7D,#02,#00
       defb  #08,#00,#00,#C3,#07,#00, #08,#00,#00,#02,#0E,#00
       defb  #18,#80,#31,#FE,#1F,#80, #70,#00,#1F,#FF,#7F,#78
       defb  #E0,#01,#8C,#F8,#DF,#07, #00,#17,#C8,#F0,#CF,#00
       defb  #00,#7C,#58,#E0,#87,#FC, #FF,#FF,#B1,#80,#A3,#07
       defb  #00,#80,#7F,#85,#81,#00, #00,#00,#91,#80,#C0,#0F
       defb  #00,#F0,#FF,#C1,#48,#F8, #C0,#1F,#36,#42,#60,#00
       defb  #7C,#80,#5E,#60,#28,#00, #03,#70,#B5,#E0,#1A,#00
       defb  #00,#0E,#E4,#BB,#07,#00, #80,#01,#24,#06,#01,#00
       defb  #60,#00,#64,#80,#01,#00, #18,#00,#4C,#60,#00,#00
       defb  #04,#00,#88,#39,#00,#00, #00,#00,#08,#0F,#00,#00
iconend:

; -- Above data may need to be at fixed addresses, regardless of the
; -- fact that there seem to be pointers to them in header.  I do
; -- believe there may be cases where mailstation addresses data
; -- directly, without following pointer.
; --
; -- The eventhandler would normally be near end of page, after a
; -- large block of graphic data (standard ms apps are mostly just an
; -- image).  I don't think address matters, as long as jump in header
; -- can find it.

eventhandler:
;eventhandler(who, appstate, signal, this, that)
       ld de,-25         ; local: sp0008-sp0020  (25 dec bytes)
       call localize     ;   par: sp0025, sp0027, sp0029, sp002b, sp002d

;locals
menuitem equ #0008                ; first local is at sp + 8 bytes of
register save
mythingy equ menuitem + 5         ; menuitem + size of menuitem

; parameters
who      equ mythingy + 20 + 4    ; mythingy + size of mythingy + 4 more
bytes of reg save
appstate equ who      + 2
signal   equ appstate + 2
this     equ signal   + 2
that     equ this     + 2

       ld hl,signal    ; a = par4   signal
       add hl,sp
       ld a,(hl)
       ex de,hl

       dec a
       jr z,event_appinit   ; sig = #01  (app init)
       sub 07
       jr z,event_keydown   ; sig = #08  (key down)
       sub 02
       jp z,event_menu      ; sig = #0A  (menu event)
       sub 03
       jr z,event_draw      ; sig = #0D  (draw app)
       jp event_other       ; else

event_appinit:
; draw foldertab
       ld hl,foldertabtext  ; the string
       push hl
       call draw_app_foldertab
       pop de

; set up the f-key menu
       ld hl,menuitem
       add hl,sp
       ld (hl),#36  ; string# of "Back" in string table
       inc hl
       ld (hl),#00
       inc hl
       ld (hl),#64  ; code for menucommand "cm_back"
       inc hl
       ld (hl),#00
       inc hl
       ld (hl),#03  ; scancode for f1 key

       ld hl,#0001
       push hl      ; [-2] push #0001    (n = 1 record)

       ld hl,menuitem+2
       add hl,sp
       push hl      ; [-4] push @menuitem

       ld hl,who+4
       add hl,sp
       ld e,(hl)
       ld d,#00
       push de      ; [-6] push who

       call set_f_key_menu
       pop de
       pop de
       pop de

; return nexstate = 1
       ld hl,#0001
       ret

event_draw:
; draws the datascreen (TV listing, weather, news, etc.)
; First, we need to init a local thingy
       ld hl,mythingy
       add hl,sp
       push hl     ; push @mythingy
       ld hl,#00FF  ; use whole screen window
       push hl
       call init_widget_thingy
       pop de
       pop de

; Next we draw whatever needs drawin'.
; For now, we just draw the 2nd app icon (see header)
; This is how the standard apps display weather, TV listings,
; or news, the displayed info is just a big icon.
; But you would draw anything your app needs to display here.

       ld hl,#0081  ; 2nd app icon, the datascreen
       push hl

       ld hl,(ypos)
       push hl

       ld hl,(xpos)
       push hl

       ld hl,mythingy+6
       add hl,sp
       push hl

       call draw_icon_wc
       ld hl,#0008
       add hl,sp
       ld sp,hl
       jr ret_samestate     ; ret par2

event_keydown:
       ex de,hl    ; hl = @par4
       inc hl
       inc hl
       ld e,(hl)   ; par6  (this)
       inc hl
       ld d,(hl)
       dec de      ; de = this - 1
       ld a,d
       or e
       jr nz,ret_samestate  ; if this <> 1, we're done

; signal was #08  AND  this was #01  (it's the "back" key down)
       call put_event_go_prev_app
       jr ret_samestate     ; ret par2

event_menu:
       ex de,hl    ; hl = @par4
       inc hl
       inc hl
       ld e,(hl)
       inc hl
       ld d,(hl)   ; par6   (this)
       ld hl,#FF9C ; - #64
       add hl,de   ; hl = this - cm_back
       ld a,h
       or l
       jr nz,ret_samestate  ; if this <> #64, then ret par2

; signal was #0A  AND  "this" was #64
       call put_event_go_prev_app
       jr ret_samestate

event_other:
; signal was something else, call default handler.
; I suppose this might be like calling the "inherited" event handler.
; Default handler rets 0 when signal was #13
;                 rets 1 when signal was #14
;                 rets par2 for all other cases

       ld hl,that  ; par8   that
       add hl,sp
       ld e,(hl)
       inc hl
       ld d,(hl)
       push de

       dec hl
       dec hl
       ld d,(hl)
       dec hl      ; par6   this
       ld e,(hl)
       push de

       dec hl
       dec hl      ; par4   signal
       ld e,(hl)
       ld d,00
       push de

       dec hl
       dec hl      ; par2   appstate
       ld e,(hl)
       push de

       dec hl
       dec hl      ; par0   who
       ld e,(hl)
       push de

       call defaulthandler

       ex de,hl    ; de = retval
       ld hl,#000A
       add hl,sp
       ld sp,hl
       ld d,00     ;; ret de (we return same retval)
       ex de,hl
       ret

; after  #0D, #08, #0A,  return par2  (appstate)
; iow, app stays in the same state.
ret_samestate:
       ld hl,appstate
       add hl,sp
       ld e,(hl)
       ld d,00
       ex de,hl    ; ret hl = sp0078  (par2)
       ret

foldertabtext:
       db "Hello World!!!", 0

---

From: "Jeff" <fyberoptic1979@...>
Date: Fri, 27 Jul 2007 04:36:36 -0000

--- In [email-masked], "Cyrano 
> ; shows the structure of a mailstation app.

I had recreated the calculator icon in 1-bit-per-pixel format and was 
searching through the dumped flash in the Files section to see if I 
could match it up to something that might have some icon header that 
I could make out.  Though I have no idea how it even stores those 
built-in apps and whether it would have even helped to find the 
icon.  So thanks for the structure and icon info!

I compiled with as80 (after fixing some of the assembler commands in 
the beginning there, which it complained about them being uppercase) 
and manually entered it into the MS via the hex editor.  A 721 byte 
file ends up being a little longer to type in that one might think, 
but not too bad.  I was able to run the app, got a chuckle from the 
image it displayed, but noticed there was a problem with the tab's 
text.  It was just "! ..." instead of "Hello world!!!".  I realized 
that I didn't put a carriage return after the very last line in the 
assembly file, which resulted in as80 not even parsing that line (a 
good thing to remember), but even when I recompiled and tacked the 
extra bytes onto the end in the hex editor, it still gave me the same 
"! ..." instead of the caption.  So I dunno what's up with that.  But 
the Back button let me exit and such, so the caption issue seems to 
be the only thing possibly wrong.  I went back over the hex I typed 
in, and am fairly sure I didn't mistype anything.  Unless you spot 
anything with the code that could be the issue, I might double-check 
my typing once more when it's not so late.

---

From: "Cyrano Jones" <cyranojones_lalp@...>
Date: Fri, 27 Jul 2007 09:32:49 -0000

> icon.  So thanks for the structure and icon info!

The built-in apps don't use same format.  All of the icons
are in a big table, right after the font data in codeflash page #04

> the beginning there, which it complained about them being uppercase) 

Yeah, by default as80 wants lower case only.  I add the -i switch
to command to allow upper or lower.  I almost always type lowercase
but I must have cut and pasted part of that file from an uppercase
example.

For whatever it's worth, here is my bat file for assembling helloapp,
with a cheat sheet for the options:

..\as80 -x2 -n -i -l -h0 -w200 -ohelloapp.rom helloapp
C:\PROGRA~1\ACCESS~1\WORDPAD.EXE helloapp.lst

REM these are the relevant options for as80
REM -x2 = use z80 extensions to 8080
REM -n  = no optimizations
REM -i  = Ignore case in opcodes
REM -l  = Generate pass 2 listing
REM -h0 = use an infinite page length
REM -w200 = use 200 column page width
REM -dsomevar = define variable
REM -osomefilename = output to file name
REM -lsomefilename = listing file name
REM 
REM -s2 = Write intel-hex file instead of binary file

> file ends up being a little longer to type in that one might think, 

:-)

> image it displayed, 

I hope that was not one of the nudie pix of my girlfriend!
I really don't remember what it is.  I guess it is about the 
size of an icon???

> but noticed there was a problem with the tab's 
> text.  It was just "! ..." instead of "Hello world!!!".  

I just noticed that my assembly listing shows it to be 
713 bytes, not 721.  This might be at the root of the problem???

--CJ

---

From: "Cyrano Jones" <cyranojones_lalp@...>
Date: Fri, 27 Jul 2007 09:46:34 -0000

> 713 bytes, not 721.  This might be at the root of the problem???

I just uploaded my assembly listing of helloapp 
to root of groups file area.

I wonder if I can make a link to it here?
http://tech.groups.yahoo.com/group/mailstation/files/

Hmmmmm. for some reason, it is leaving off the filename.

This time for sure....
http://f1.grp.yahoofs.com/v1/ELSpRqWjDgtU18v23HDt6o742uvu7h8ncRlgZ-MSW23Eq4rYV6ETtnbrMEfZR4M59NkLjszTl5D1JWzMG5MxUQiRh8RD4Hw34ebPhRLkdA/helloapp.lst.txt

Well, that doesn't look right either.  Oh well.

--CJ

---

From: "Jeff" <fyberoptic1979@...>
Date: Fri, 27 Jul 2007 15:11:19 -0000

> I really don't remember what it is. I guess it is about the

lol no such luck on nudie pics.  Let's just say that I'm assuming the 
icon represents who you were at I-Appliance.

> 713 bytes, not 721.  This might be at the root of the problem???

When using your as80 command-line options, I also got 713 bytes.  But 
when I run the program now, it just says "+V" instead of the former 
"! ..."

So I'm not really sure what could be the problem, unless it's 
switching pages during the tab drawing routine.  I wouldn't think so, 
but it's all that comes to mind.

---

From: "Jeff" <fyberoptic1979@...>
Date: Fri, 27 Jul 2007 15:13:18 -0000

--- In [email-masked], "Cyrano 
Jones" <cyranojones_lalp@...> wrote:
> http://f1.grp.yahoofs.com/v1/ELSpRqWjDgtU18v23HDt6o742uvu7h8ncRlgZ-
MSW23Eq4rYV6ETtnbrMEfZR4M59NkLjszTl5D1JWzMG5MxUQiRh8RD4Hw34ebPhRLkdA/
helloapp.lst.txt
> Well, that doesn't look right either.  Oh well.

I think it's using the user's session ID or some other such random 
thing in the url, because it's different when I go to get it.  It's 
even different than it was for me a few minutes ago.  They change it 
up to prevent people from using it to host files outside of the 
group, I guess.

---

From: "Cyrano Jones" <cyranojones_lalp@...>
Date: Mon, 13 Aug 2007 21:53:39 -0000

> but it's all that comes to mind.

That's it!!!

I guess it's not a good idea to pass a pointer to a page that might 
not stay put!!!  :-)  :-)  :-)

It seemed innocent enough to pass a pointer to a constant string
defined within the app.  But the app runs from slot4000, and the 
call to "draw_app_foldertab" uses slot4000, too.  By the time
the string is actually used, several other pages have been slapped
into slot4000, too.  

So, I declared a local var on the stack, and copied it there.
(The stack is in slotC000, which never changes.)

It works now!!!

Thanks!!!

--CJ