[Coco] cprep19 __FILE__ fix?
Michael Furman
n6il at ocs.net
Fri May 27 00:21:13 EDT 2011
On May 25, 2011, at 2:49 PM, Michael Furman wrote:
> Willard, I looked into this a few months ago. Off the top of my haead:
>
> 1) I have some source for the Krieder C library, but when I assembled it, it was not exactly the same as binary copies floating around. This reduces my confidence that the resulting clib after hacking will actually work properly, and makes it difficult to generate a patch that will always work. The date command returns the correct year.
>
> 2) clib's asctime function had some contribution to the problem but the details escape me ATM.
Got time to look at this tonight. First, The date problem contribution from kriederlib is as follows:
00001550 76 00 44 65 63 00 25 73 20 25 73 20 25 32 64 20 |v.Dec.%s %s %2d |
00001560 25 30 32 64 3a 25 30 32 64 3a 25 30 32 64 20 31 |%02d:%02d:%02d 1|
00001570 39 25 30 32 64 0d 00 00 1f 00 1c 00 1f 00 1e 00 |9%02d...........|
So roughly, the library's asctime function calls:
sprintf(buf, "%s %s %2d %02d:%02d:%02d 19%02d",
days[day_of_week],
months[t_month],
t_day,
t_hour,
t_minute,
t_second,
t_year );
Which will result in
Thu May 26 21:05:52 19111
I haven't fixed this yet because of item #2...
We have to be careful on relying on raw-disassembly of things, it can be quite confusing, and sometimes results in errors. The nitros9 build system generates quite a few disk images based on disassemblies. I know that some of them have been confirmed to be exactly the same as the original... but in this case, it's wrong.
The following is code from utime.a module in krieder c lib prepares the month arguments for sprintf: loads the index in D, subtract 1, multiplies it by 4, gets the address of the month table in X, adds them and pushes the result to the stack as an argument for sprintf:
00311 01e7 ec48 ldd 8,u
00312 01e9 830001 subd #1
00313 01ec 58 lslb
00314 01ed 49 rola
00315 01ee 58 lslb
00316 01ef 49 rola
00317 01f0 308d0055 leax >L024a,pcr
00318 01f4 308b leax d,x
00319 01f6 3410 pshs x
The disassembler turned the table into a bunch of junk. Note that the label L024a is actually at 0249 (??)
00361 0248 044a lsr D.SysPrc
00362 0249 L024a equ *-1
00363 024a 61 fcb $61
00364 024b 6e fcb $6e
00365 024c 0046 neg D0046
00366 024e 65 fcb $65
00367 024f 62 fcb $62
00368 0250 004d neg D004d
00369 0252 61 fcb $61
00370 0253 72 fcb $72
00371 0254 0041 neg D0041
00372 0256 707200 neg X7200
00373 0259 4d tsta
00374 025a 61 fcb $61
00375 025b 094a rol D.SysPrc
00376 025d 75 fcb $75
00377 025e 6e fcb $6e
00378 025f 004a neg D004a
00379 0261 75 fcb $75
00380 0262 6c fcb $6c
00381 0263 0041 neg D0041
00382 0265 75 fcb $75
00383 0266 67 fcb $67
00384 0267 0053 neg D0053
00385 0269 65 fcb $65
00386 026a 004f neg X004f
00387 026c 6374 com -12,s
00388 026e 004e neg D004e
00389 0270 6f76 clr -10,s
00390 0272 0044 neg D0044
00391 0274 65 fcb $65
00392 0275 63 fcb $63
00393 0276 0025 neg D0025
This junk has some errors if we look at it with hexdump, we want 4a 61 6e 00 etc.
000002ba 4a 61 6e 00 46 65 | Jan.Fe|
000002c0 62 00 4d 61 72 00 41 70 72 00 4d 61 09 4a 75 6e |b.Mar.Apr.Ma.Jun|
000002d0 00 4a 75 6c 00 41 75 67 00 53 65 00 4f 63 74 00 |.Jul.Aug.Se.Oct.|
000002e0 4e 6f 76 00 44 65 63 00 |Nov.Dec. |
So May, and September are truncated. Based on the code this will result in some bugs. A human would write something like this. Note that these are C-Style NUL terminated strings so we can't use FCS for them:
00377 024a L024a
00378 024a 4a616e fcc /Jan/
00379 024d 00 fcb $00
00380 024e 466562 fcc /Feb/
00381 0251 00 fcb $00
00382 0252 4d6172 fcc /Mar/
00383 0255 00 fcb $00
00384 0256 417072 fcc /Apr/
00385 0259 00 fcb $00
00386 025a 4d6179 fcc /May/
00387 025d 00 fcb $00
00388 025e 4a756e fcc /Jun/
00389 0261 00 fcb $00
00390 0262 4a756c fcc /Jul/
00391 0265 00 fcb $00
00392 0266 417567 fcc /Aug/
00393 0269 00 fcb $00
00394 026a 536570 fcc /Sep/
00395 026d 00 fcb $00
00396 026e 4f6374 fcc /Oct/
00397 0271 00 fcb $00
00398 0272 4e6f76 fcc /Nov/
00399 0275 00 fcb $00
00400 0276 446563 fcc /Dec/
00401 0279 00 fcb $00
Fixed,
000002bb 4a 61 6e 00 46 | Jan.F|
000002c0 65 62 00 4d 61 72 00 41 70 72 00 4d 61 79 00 4a |eb.Mar.Apr.May.J|
000002d0 75 6e 00 4a 75 6c 00 41 75 67 00 53 65 70 00 4f |un.Jul.Aug.Sep.O|
000002e0 63 74 00 4e 6f 76 00 44 65 63 00 |ct.Nov.Dec. |
I have to finish fixing everything before I can proceed with fixing the date problem.
More information about the Coco
mailing list