Example program for the Cidco MailStation Z80 computer

powerdown: Poke port 28 manually rather than talk to firmware

The built-in powerdown function will probably be at a different
address on different firmware versions, and it doesn't work properly
with our hijump/lojump shenanigans anyway.

This makes the Power button work again, but I still need to figure
out what else to change before shutting down so the next boot
doesn't go to the "Reset System Data" screen first.

+24 -11
+12 -2
lib/crt0.s
··· 205 205 _exit:: 206 206 call _reboot 207 207 208 - _powerdown_mode:: 209 - call #0x0a6b ; firmware powerdownmode function 208 + _powerdown:: 209 + ; TODO: figure out what else needs to be set before shutting down to 210 + ; prevent it going to the "Reset System Data" screen on next startup 211 + ld hl, (#p28shadow) 212 + ld a, (hl) 213 + set 1, a ; 74c74 pin4 214 + set 0, a ; modem reset 215 + ld (hl), a 216 + di 217 + out (#0x28), a 218 + halt 219 + ret 210 220 211 221 _reboot:: 212 222 jp 0x0000
+1 -1
lib/mailstation.h
··· 87 87 88 88 /* crt0.s */ 89 89 extern void exit(void); 90 - extern void powerdown_mode(void); 90 + extern void powerdown(void); 91 91 extern void new_mail(unsigned char on); 92 92 extern void reboot(void); 93 93 extern void delay(unsigned int millis);
+11 -8
main.c
··· 23 23 24 24 unsigned char lastkey; 25 25 26 - void process_keyboard(void); 26 + int process_keyboard(void); 27 27 void process_input(unsigned char b); 28 28 29 29 int ··· 40 40 printf("Hello, World\n"); 41 41 42 42 for (;;) { 43 - process_keyboard(); 43 + if (process_keyboard() == KEY_POWER) 44 + break; 44 45 } 46 + 47 + return 0; 45 48 } 46 49 47 - void 50 + int 48 51 process_keyboard(void) 49 52 { 50 53 unsigned char b; ··· 60 63 lastkey = b; 61 64 62 65 if (b == 0) 63 - return; 66 + return 0; 64 67 65 68 switch (b) { 66 69 case KEY_POWER: 67 - #if 0 68 - /* XXX: this triggers erroneously */ 69 - powerdown_mode(); 70 - #endif 70 + delay(100); 71 + powerdown(); 71 72 break; 72 73 case KEY_F1: 73 74 break; ··· 90 91 default: 91 92 putchar(b); 92 93 } 94 + 95 + return b; 93 96 }