Terminal program for MailStation devices
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

crt0: Dynamically determine port shadow vars based on firmware version

Only do modem ISR patching on 2.54 because it needs work on other
versions, but since the default source is SOURCE_WIFI now,
WiFiStation should at least work with other versions.

Tested on 2.54 and 1.73 (eMessage)

+118 -30
+89 -10
crt0.s
··· 120 120 jp SLOT_ADDR + (hijump - start) 121 121 122 122 hijump: 123 - ; SP is now in SLOT_ADDR, put our new RAM page into RUN_DEVICE/PAGE 123 + ; PC is now in SLOT_ADDR, put our new RAM page into RUN_DEVICE/PAGE 124 124 out (#RUN_DEVICE), a 125 125 out (#RUN_PAGE), a 126 126 ··· 128 128 jp RUN_ADDR + (lojump - start) 129 129 130 130 lojump: 131 - call patch_isr ; install new ISR 131 + call find_shadows 132 132 call _main ; main c code 133 133 jp _exit 134 134 135 + ; set location of port shadow variables depending on firmware version 136 + find_shadows: 137 + ld a, (#0x0037) ; firmware major version 138 + cp #0x2 139 + jr z, ver_2 140 + cp #0x1 141 + jr z, ver_1 142 + unrecognized_firmware: ; we can't blink because that requires 143 + jp 0x0 ; port and fw function addresses 144 + ver_1: 145 + ld a, (#0x0036) ; firmware minor version 146 + cp #0x73 147 + jr z, ver_1_73 148 + jr unrecognized_firmware 149 + ver_1_73: ; eMessage 1.73CID 150 + ld hl, #p2shadow 151 + ld (hl), #0xdb9f 152 + ret 153 + ver_2: 154 + ld a, (#0x0036) ; firmware minor version 155 + cp #0x54 156 + jr z, ver_2_54 157 + jr unrecognized_firmware 158 + ver_2_54: ; MailStation 2.54 159 + ld hl, #p2shadow 160 + ld (hl), #0xdba2 161 + ld hl, #p3shadow 162 + ld (hl), #0xdba3 163 + ld hl, #p28shadow 164 + ld (hl), #0xdba0 165 + call patch_isr ; 2.54 works with patched modem ISR 166 + ret 167 + 135 168 .area _DATA 169 + 170 + ; shadow locations 171 + p2shadow: 172 + .dw #0xdba2 173 + p3shadow: 174 + .dw #0xdba3 175 + p28shadow: 176 + .dw #0xdba0 177 + delay_func: 178 + jp 0x0a5c 136 179 137 180 _msTERM_version:: 138 181 .db #VERSION ··· 170 213 push af 171 214 ld a, 4(ix) 172 215 cp #0 216 + ld hl, (p2shadow) 173 217 jr z, light_off 174 218 light_on: 175 - ld a, (p2shadow) 219 + ld a, (hl) 176 220 set 4, a 177 221 jr write_p2 178 222 light_off: 179 - ld a, (p2shadow) 223 + ld a, (hl) 180 224 res 4, a 181 225 write_p2: 182 - ld (p2shadow), a 226 + ld (hl), a 183 227 out (#0x02), a ; write p2shadow to port2 184 228 pop af 185 229 pop hl ··· 199 243 ld l, 4(ix) 200 244 ld h, 5(ix) 201 245 push hl 202 - call #0x0a5c 246 + call delay_func 203 247 pop hl 204 248 pop hl 205 249 pop bc ··· 207 251 pop ix 208 252 ret 209 253 254 + ; blink(unsigned int millis) 255 + ; turn new mail LED on, wait millis, turn it off, wait millis 256 + _blink:: 257 + push ix 258 + ld ix, #0 259 + add ix, sp 260 + push hl 261 + ld l, #1 262 + push hl 263 + call _new_mail ; turn it on 264 + pop hl 265 + ld l, 4(ix) 266 + ld h, 5(ix) 267 + push hl 268 + call _delay ; wait 269 + pop hl 270 + ld l, #0 271 + push hl 272 + call _new_mail ; turn it off 273 + pop hl 274 + ld l, 4(ix) 275 + ld h, 5(ix) 276 + push hl 277 + call _delay ; wait 278 + pop hl 279 + pop af 280 + pop ix 281 + ret 282 + 210 283 ; void lcd_sleep(void) 211 284 ; turn the LCD off 212 285 _lcd_sleep:: 213 286 di 214 - ld a, (p2shadow) 287 + push hl 288 + ld hl, (p2shadow) 289 + ld a, (hl) 215 290 and #0b01111111 ; LCD_ON - turn port2 bit 7 off 216 - ld (p2shadow), a 291 + ld (hl), a 217 292 out (#0x02), a ; write p2shadow to port2 293 + pop hl 218 294 ei 219 295 ret 220 296 ··· 223 299 ; turn the LCD on 224 300 _lcd_wake:: 225 301 di 226 - ld a, (p2shadow) 302 + push hl 303 + ld hl, (p2shadow) 304 + ld a, (hl) 227 305 or #0b10000000 ; LCD_ON - turn port2 bit 7 on 228 - ld (p2shadow), a 306 + ld (hl), a 229 307 out (#0x02), a ; write p2shadow to port2 308 + pop hl 230 309 ei 231 310 ret 232 311
+8 -5
isr.s
··· 71 71 ;set 5, a ; 5 for RTC 72 72 set 2, a ; 2 for keyboard 73 73 set 1, a ; 1 for keyboard 74 - ld (p3shadow), a ; store this mask in p3shadow 74 + ld hl, (p3shadow) 75 + ld (hl), a ; store this mask in p3shadow 75 76 out (0x3), a 76 77 ei ; here we go! 77 78 ret ··· 97 98 out (0x3), a 98 99 jp isrout 99 100 isr_7: 100 - ld a, (p3shadow) 101 + ld hl, (p3shadow) 102 + ld a, (hl) 101 103 res 7, a 102 104 out (0x3), a ; reset interrupt 103 - ld a, (p3shadow) 105 + ld a, (hl) 104 106 out (0x3), a ; set mask back to p3shadow 105 107 call 0x3b19 ; default power button handler 106 108 jp isrout 107 109 isr_6: 108 - ld a, (p3shadow) 110 + ld hl, (p3shadow) 111 + ld a, (hl) 109 112 res 6, a 110 113 out (0x3), a ; reset interrupt 111 - ld a, (p3shadow) 114 + ld a, (hl) 112 115 out (0x3), a ; set mask back to p3shadow 113 116 call _modem_isr 114 117 jp isrout
+1
mailstation.h
··· 97 97 extern void new_mail(unsigned char on); 98 98 extern void reboot(void); 99 99 extern void delay(unsigned int millis); 100 + extern void blink(unsigned int millis); 100 101 extern void lcd_paint(void); 101 102 extern unsigned char read_port(unsigned char port); 102 103
+4 -5
mailstation.inc
··· 11 11 .globl SLOT_DEVICE 12 12 .globl SLOT_PAGE 13 13 14 - ; for firmware v2.54 15 - ; variables 16 - .equ p2shadow, #0xdba2 17 - .equ p3shadow, #0xdba3 18 - .equ p28shadow, #0xdba0 14 + ; per-firmware version port shadow variables 15 + .globl p2shadow 16 + .globl p3shadow 17 + .globl p28shadow 19 18 20 19 ; functions 21 20 .equ get_keycode_from_buffer,#0x0a9a
+9 -6
modem.s
··· 94 94 ld a, #0 95 95 ld (_modem_buf_pos), a 96 96 call 0x3dbe ; disable caller id? 97 - ld a, (p3shadow) 97 + ld hl, (p3shadow) 98 + ld a, (hl) 98 99 res 7, a ; disable caller id interrupt 99 - ld (p3shadow),a 100 + ld (hl),a 100 101 out (#0x03), a 101 102 in a, (#0x29) ; XXX what is port 29? 102 103 or #0x0c 103 104 out (#0x29), a 104 - ld a, (p28shadow) 105 + ld hl, (p28shadow) 106 + ld a, (hl) 105 107 set 2, a 106 108 res 3, a 107 - ld (p28shadow), a 109 + ld (hl), a 108 110 out (#0x28), a ; XXX what is port 28? 109 111 xor a 110 112 ld (#0xe63b), a ; no idea what these shadow vars are ··· 116 118 ld (#0xe638), a 117 119 in a, (#SLOT_DEVICE) ; store old slot device 118 120 push af 119 - ld a, (p2shadow) ; read p2shadow 121 + ld hl, (p2shadow) 122 + ld a, (hl) ; read p2shadow 120 123 res 5, a 121 - ld (p2shadow), a ; write p2shadow 124 + ld (hl), a ; write p2shadow 122 125 out (#0x02), a ; also write it to port2 123 126 ld hl, #300 124 127 push hl
+7 -4
putchar.s
··· 62 62 ld ix, #0 63 63 add ix, sp 64 64 push de 65 - ld a, (p2shadow) 65 + push hl 66 + ld hl, (p2shadow) 67 + ld a, (hl) 66 68 and #0b11110111 ; CAS(0) - turn port2 bit 3 off 67 - ld (p2shadow), a 69 + ld (hl), a 68 70 out (#0x02), a ; write p2shadow to port2 69 71 ld de, #LCD_START 70 72 ld a, 4(ix) 71 73 ld (de), a ; write col argument 72 - ld a, (p2shadow) 74 + ld a, (hl) 73 75 or #0b00001000 ; CAS(1) - turn port2 bit 3 on 74 - ld (p2shadow), a 76 + ld (hl), a 75 77 out (#0x02), a 78 + pop hl 76 79 pop de 77 80 ld sp, ix 78 81 pop ix