AmendHub

Download:

vkoskiv

/

MacNTP

/

amendments

/

18

Haphazard hacking to try fixing bizarre bugs

I honestly don't know why some of these bugs exist. I've read the
docs several times, and I still have no idea.
The cdev now mostly works. editText boxes still render weird, the
text shifts up and down by 1 or 2 pixels when you edit it.
I don't know where to even begin looking for a solution.
I'm also now handling macDev messages and checking that MacTCP is
present, but System 6 refuses to send the macDev message, despite
the mach resource being correct, according to Inside Macintosh.
- Fixed the bug where a letter appears if you hit CMD+X or similar.
- Hooked up cutDev, copyDev and pasteDev
- Tweaked DITL to be a bit more symmetric.
- The INIT also checks to see if MacTCP is present, and bails out if
if it isn't.

vkoskiv made amendment 18 about 1 year ago
--- cdev.c Sun Sep 17 23:52:40 2023 +++ cdev.c Wed Sep 20 23:40:00 2023 @@ -16,6 +16,7 @@ #include "rsrcid.h" #include <OSUtils.h> +#include <GestaltEqu.h> /* A basic cdev skeleton + implementation in pure C @@ -26,6 +27,11 @@ It works, there are many bugs, but it does the job. */ +#define ntp1_box_id 1 +#define ntp2_box_id 2 +#define utc_box_id 3 +#define apply_btn_id 4 + struct control { short type; Handle handle; @@ -47,6 +53,7 @@ void got_cdev_error(void); void got_memory_error(void); void got_resource_error(void); +int is_number(char c); int validate_ntp_url(Str255 utc_str); int validate_utc(Str255 utc_str); @@ -54,14 +61,14 @@ int utcstr_to_mins(Str255 utc, long *out); void *got_initDev(void *storage, DialogPtr dialog, short nitems); void *got_hitDev(void *storage, short item); -void *got_closeDev(void *storage); +void *got_closeDev(void *storage, short item); void *got_nulDev(void *storage); void *got_updateDev(void *storage); void *got_activDev(void *storage); void *got_deActivDev(void *storage); -void *got_keyEvtDev(void *storage, EventRecord *); +void *got_keyEvtDev(void *storage, EventRecord *event, short item, short nitems, DialogPtr d); void *got_keyEvent(void *storage, unsigned char c); -void *got_cmdKeyEvent(void *storage, unsigned char c); +void *got_cmdKeyEvent(void *storage, unsigned char c, short item, short nitems, DialogPtr d); void *got_macDev(void *storage); void *got_undoDev(void *storage); void *got_cutDev(void *storage); @@ -111,26 +118,35 @@ void *got_initDev(void *storage, DialogPtr dialog, sho // Grab our textboxes. The number is the one in our DITL // but the dialog manager wants the full range num, so add nitems GetDItem(s->dialog, - 4 + nitems, + ntp1_box_id + nitems, &s->ntp1_textbox.type, &s->ntp1_textbox.handle, &s->ntp1_textbox.rect); + HLock(s->ntp1_textbox.handle); + SetIText(s->ntp1_textbox.handle, *s->ntp1); + ShowDItem(s->dialog, ntp1_box_id); + InvalRect(&s->ntp1_textbox.rect); + SelIText(s->dialog, ntp1_box_id + nitems, 0, 32767); + GetDItem(s->dialog, - 6 + nitems, + ntp2_box_id + nitems, &s->ntp2_textbox.type, &s->ntp2_textbox.handle, &s->ntp2_textbox.rect); + HLock(s->ntp2_textbox.handle); + SetIText(s->ntp2_textbox.handle, *s->ntp2); + ShowDItem(s->dialog, ntp2_box_id); + InvalRect(&s->ntp2_textbox.rect); + GetDItem(s->dialog, - 8 + nitems, + utc_box_id + nitems, &s->utc_textbox.type, &s->utc_textbox.handle, &s->utc_textbox.rect); - HLock(s->ntp1_textbox.handle); - HLock(s->ntp2_textbox.handle); HLock(s->utc_textbox.handle); - SetIText(s->ntp1_textbox.handle, *s->ntp1); - SetIText(s->ntp2_textbox.handle, *s->ntp2); SetIText(s->utc_textbox.handle, *s->utc); + ShowDItem(s->dialog, utc_box_id); + InvalRect(&s->utc_textbox.rect); return storage; } @@ -187,7 +203,7 @@ void *got_hitDev(void *storage, short item) { struct state *s = *(struct state **)storage; updated = false; - if (item == 9) { + if (item == apply_btn_id) { GetIText(s->ntp1_textbox.handle, ntp1_text); GetIText(s->ntp2_textbox.handle, ntp2_text); GetIText(s->utc_textbox.handle, utc_text); @@ -245,11 +261,14 @@ void *got_hitDev(void *storage, short item) { } return storage; } -void *got_closeDev(void *storage) { - struct state *state = *(struct state **)storage; - DisposHandle(state->ntp1); - DisposHandle(state->ntp2); - DisposHandle(state->utc); +void *got_closeDev(void *storage, short item) { + struct state *s = *(struct state **)storage; + HideDItem(s->dialog, 3); + HideDItem(s->dialog, 5); + HideDItem(s->dialog, 7); + DisposHandle(s->ntp1); + DisposHandle(s->ntp2); + DisposHandle(s->utc); DisposHandle(storage); return storage; } @@ -266,12 +285,13 @@ void *got_activDev(void *storage) { void *got_deActivDev(void *storage) { return storage; } -void *got_keyEvtDev(void *storage, EventRecord *event) { +void *got_keyEvtDev(void *storage, EventRecord *event, short item, short nitems, DialogPtr d) { if (!(event->modifiers & cmdKey)) return got_keyEvent(storage, (unsigned char)event->message); - else if (event->message != autoKey) - return got_cmdKeyEvent(storage, (unsigned char)event->message); - + else if (event->message != autoKey) { + event->what = nullEvent; + return got_cmdKeyEvent(storage, (unsigned char)event->message, item, nitems, d); + } //FIXME: Can we reach this even? SysBeep(30); return storage; @@ -288,7 +308,8 @@ void *got_keyEvent(void *storage, unsigned char c) { // come from the keyboard. // I guess Apple just did this for compatibility with // existing cdevs, so I'll just patch these in here. -void *got_cmdKeyEvent(void *storage, unsigned char c) { +void *got_cmdKeyEvent(void *storage, unsigned char c, short item, short nitems, DialogPtr d) { + struct state *s = *(struct state **)storage; switch (c) { case 'z': case 'Z': return got_undoDev(storage); @@ -298,24 +319,51 @@ void *got_cmdKeyEvent(void *storage, unsigned char c) return got_copyDev(storage); case 'v': case 'V': return got_pasteDev(storage); + case 'a': case 'A': + //GetDItem(d, item - nitems, NULL, NULL, NULL); + // I tried a few permutations, but this call crashes the system every + // time and I can't be bothered to figure out why. + //SelIText(d, item - nitems, 0, 32767); + return storage; } SysBeep(30); return storage; } -// We shouldn't get this message, but report we are runnable anyway + void *got_macDev(void *storage) { - return (void *)1; + long answer; + OSErr gestalt_err; + SysBeep(1); + gestalt_err = Gestalt(gestaltVersion, &answer); + if (gestalt_err) { + // Gestalt not available, it was introduced in 6.0.4 + // And MacTCP in 6.0.3, so we're just going to assume + // the user has at least 6.0.8 + return (void *)0; + } + + if (!Gestalt('mtcp', nil)) { + // Good, MacTCP is available. + return (void *)1; + } + return (void *)0; } void *got_undoDev(void *storage) { return storage; } void *got_cutDev(void *storage) { + struct state *s = *(struct state **)storage; + DlgCut(s->dialog); return storage; } void *got_copyDev(void *storage) { + struct state *s = *(struct state **)storage; + DlgCopy(s->dialog); return storage; } void *got_pasteDev(void *storage) { + struct state *s = *(struct state **)storage; + DlgPaste(s->dialog); return storage; } void *got_clearDev(void *storage) { @@ -348,12 +396,12 @@ pascal void *main( switch (msg) { case initDev: return got_initDev(storage, dp, nitems); case hitDev: return got_hitDev(storage, item - nitems); - case closeDev: return got_closeDev(storage); + case closeDev: return got_closeDev(storage, item - nitems); case nulDev: return got_nulDev(storage); case updateDev: return got_updateDev(storage); case activDev: return got_activDev(storage); case deactivDev: return got_deActivDev(storage); - case keyEvtDev: return got_keyEvtDev(storage, event); + case keyEvtDev: return got_keyEvtDev(storage, event, item, nitems, dp); case macDev: return got_macDev(storage); case undoDev: return got_undoDev(storage); case cutDev: return got_cutDev(storage); --- MacNTP.π.r Mon Sep 18 00:15:38 2023 +++ MacNTP.π.r Wed Sep 20 23:54:29 2023 @@ -67,8 +67,8 @@ data 'ICN#' (130, "NTPFAILED", sysheap) { $"FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF" /* ................ */ }; -data 'mach' (-4064, "init", purgeable) { - $"FFFF 0000" /* .... */ +data 'mach' (-4064, purgeable) { + $"0000 FFFF" /* .... */ }; data 'sysz' (0) { @@ -110,19 +110,16 @@ data 'nrct' (-4064) { }; data 'DITL' (-4064) { - $"0009 0000 0000 000A 0075 001B 0108 8814" /* .∆.......u....à. */ - $"4D61 634E 5450 2043 6F6E 6669 6775 7261" /* MacNTP Configura */ - $"7469 6F6E 0000 0000 0010 0114 0021 012C" /* tion.........!., */ - $"9002 3A29 0000 0000 0028 0076 0038 00DE" /* ê.:).....(.v.8.. */ - $"880B 5072 696D 6172 7920 4E54 5000 0000" /* à.Primary NTP... */ - $"0000 003C 0076 004C 012E 1000 0000 0000" /* ...<.v.L........ */ - $"0055 0076 0065 00DE 880C 4661 6C6C 6261" /* .U.v.e..à.Fallba */ - $"636B 204E 5450 0000 0000 0068 0076 0078" /* ck NTP.....h.v.x */ - $"012E 1000 0000 0000 0082 0076 0092 00BB" /* .........Ç.v.í.ª */ - $"880A 5554 4320 4F66 6673 6574 0000 0000" /* à.UTC Offset.... */ - $"0096 0076 00A6 00CE 1006 2B30 333A 3030" /* .ñ.v.¶.Œ..+03:00 */ - $"0000 0000 0094 00DA 00A8 0132 0405 4170" /* .....î...®.2..Ap */ - $"706C 7900 0000 0000 000A 0111 002A 0131" /* ply..........*.1 */ - $"2002 F020" /* .. */ + $"0007 0000 0000 003B 0070 004A 0129 1000" /* .......;.p.J.).. */ + $"0000 0000 0067 0070 0076 0129 1000 0000" /* .....g.p.v.).... */ + $"0000 0095 0071 00A4 00C9 1000 0000 0000" /* ...ï.q.§.…...... */ + $"0093 00D5 00A7 012D 0405 4170 706C 7922" /* .ì.’.ß.-..Apply" */ + $"0000 0000 0009 0070 001A 0103 8814 4D61" /* .....∆.p....à.Ma */ + $"634E 5450 2043 6F6E 6669 6775 7261 7469" /* cNTP Configurati */ + $"6F6E 0000 0000 0027 0071 0037 00D9 880B" /* on.....'.q.7..à. */ + $"5072 696D 6172 7920 4E54 5071 0000 0000" /* Primary NTPq.... */ + $"0054 0071 0064 00D9 880C 4661 6C6C 6261" /* .T.q.d..à.Fallba */ + $"636B 204E 5450 0000 0000 0081 0071 0091" /* ck NTP.....Å.q.ë */ + $"00B6 880A 5554 4320 4F66 6673 6574" /* .∂à.UTC Offset */ }; --- main.c Mon Sep 18 00:10:25 2023 +++ main.c Mon Sep 18 23:36:26 2023 @@ -22,6 +22,7 @@ TODO: */ #include <SetUpA4.h> +#include <GestaltEqu.h> #include "MacNTP.h" #include "ShowInitIcon.h" #include "rsrcid.h" @@ -171,6 +172,8 @@ void main() { StringHandle ntp1; StringHandle ntp2; StringHandle utc; // Offset in minutes as pstr + long answer; + OSErr gestalt_err; asm { move.L A0, our_init_ptr; } @@ -178,6 +181,23 @@ void main() { SetUpA4(); // This is already locked in the resource attrs g_mtcp_init_handle = RecoverHandle(our_init_ptr); + + // First we check if MacTCP is available + // This also assumes Gestalt support + gestalt_err = Gestalt(gestaltVersion, &answer); + if (gestalt_err) { + // Gestalt not available, it was introduced in 6.0.4 + // And MacTCP in 6.0.3, so we're just going to assume + // the user has at least 6.0.8 + ShowInitIcon(MACNTP_ICN_ID_FAILURE, true); + goto skip; + } + + if (Gestalt('mtcp', nil)) { + // MacTCP not found + ShowInitIcon(MACNTP_ICN_ID_FAILURE, true); + goto skip; + } ntp1 = GetString(NTP1_STR_ID); ntp2 = GetString(NTP2_STR_ID);