Tools for working with Cidco Mailstations
1;
2; This loader app is based around the Yahoo app model used in spew.asm, by Cyrano Jones.
3; The original comments have been removed/replaced. The code itself of course is also
4; replaced to change the functionality, which is to recieve a dynamically specified
5; number of bytes. That's all it does. The screen doesn't even update, in order to
6; make the binary as small as possible.
7;
8; The first two bytes sent from the host make up a 16-bit value of the total number of
9; data bytes to follow. The first byte is the low byte, the second is the high. After
10; those, the actual data is transferred into ram page 1 in slot8000. The total byte
11; count is decremented, and when zero, it jumps to 0x8000 to run the transferred code.
12;
13; This was originally written to be assembled using AS80, which can be found at:
14; http://www.kingswood-consulting.co.uk/assemblers/
15;
16; - FyberOptic (fyberoptic@gmail.com)
17;
18; This has been modified to be assembled with SDCC ASZ80.
19;
20
21 .module loader
22
23 .area _DATA
24 .area _HEADER (ABS)
25 .org 0x4000 ; Apps always start at 0x4000 no matter what
26 ; dataflash page they load from.
27
28 jp eventhandler ; Jump to the start of our code.
29
30 .dw (icons) ; The following is data about the app
31 .dw (caption) ; itself, most of which we won't even
32 .dw (dunno) ; worry about.
33dunno:
34 .db #0
35zip:
36 .dw #0
37zilch:
38 .dw #0
39caption:
40 .dw #0x0001
41 .dw (endcap - caption - 6) ; num of chars
42 .dw #0x0006 ; offset to first char
43 .ascii "Loader" ; the caption string
44endcap:
45
46icons:
47 .dw #0 ; size icon0
48 .dw (icon0 - icons) ; offset to icon0
49 .dw #0 ; size icon1
50 .dw (icon1 - icons) ; offset to icon1 (0x00b5)
51icon0:
52 .dw #0 ; icon width
53 .db #0 ; icon height
54icon1:
55 .dw #0 ; icon width
56 .db #0 ; icon height
57
58 .equ brecvbyte, #0x8027 ; Firmware function in codeflash page 1. Attempts
59 ; to receive a byte. Upon returning, if a = 0, it
60 ; timed out or failed. Otherwise the l register
61 ; holds the received byte.
62
63;----------------------------------------------------------
64; Now for the actual code
65;----------------------------------------------------------
66
67getbyte:
68 push bc ; Preserve BC, HL
69 push hl
70
71 xor a ; Put codeflash page 1 into slot8000.
72 out (#08), a
73 inc a
74 out (#07), a
75
76getbyte2:
77 call brecvbyte ; Try to fetch a byte.
78 or a ; If we didn't get one, try again.
79 jp z, getbyte2
80
81 ld a, l ; Load received byte into A register
82
83 pop hl ; Restore BC, HL
84 pop bc
85 ret
86
87eventhandler:
88 call getbyte ; Get low byte of total bytes to download
89 ld l, a
90
91 call getbyte ; Get high byte of total bytes to download
92 ld h, a
93
94 ld bc, #0x8000 ; Destination address
95nextcodebyte:
96 call getbyte ; Fetch a byte of data
97
98 ld d, a ; Preserve A
99
100 ld a, #1 ; Put ram page 1 into slot8000
101 out (#0x08), a
102 out (#0x07), a
103
104 ld a, d ; Restore A
105
106 ld (bc), a ; Load incoming byte to ram.
107 inc bc ; Inc ram location.
108
109 dec hl ; Dec bytes to be received.
110
111 xor a ; Check if hl = 0; get another byte if not
112 or h
113 jp nz, nextcodebyte
114 xor a
115 or l
116 jp nz, nextcodebyte
117
118 jp 0x8000 ; When done, jump to code!