@@ -197,6 +197,14 @@ struct CPMTime // non-standard time structure
197197 uint16_t minute;
198198 uint16_t second;
199199 uint16_t millisecond;
200+
201+ void swap_endian ()
202+ {
203+ hour = flip_endian16 ( hour );
204+ minute = flip_endian16 ( minute );
205+ second = flip_endian16 ( second );
206+ millisecond = flip_endian16 ( millisecond );
207+ }
200208};
201209
202210#pragma pack( push, 1 )
@@ -205,6 +213,11 @@ struct CPM3DateTime
205213 uint16_t day; // day 1 is 1 January 1978
206214 uint8_t hour; // packed bcd (nibbles for each digit)
207215 uint8_t minute; // packed bcd
216+
217+ void swap_endian ()
218+ {
219+ day = flip_endian16 ( day );
220+ }
208221};
209222
210223uint8_t packBCD ( uint8_t x )
@@ -224,6 +237,15 @@ struct DiskParameterBlock // for BDOS 31. https://www.seasip.info/Cpm/format22.h
224237 uint8_t al1; // Directory allocation bitmap, second byte
225238 uint16_t cks; // Checksum vector size, 0 for a fixed disc
226239 uint16_t off; // Offset, number of reserved tracks
240+
241+ void swap_endian ()
242+ {
243+ spt = flip_endian16 ( spt );
244+ dsm = flip_endian16 ( dsm );
245+ drm = flip_endian16 ( drm );
246+ cks = flip_endian16 ( cks );
247+ off = flip_endian16 ( off );
248+ }
227249};
228250#pragma pack(pop)
229251
@@ -1630,7 +1652,15 @@ char get_next_kbd_char()
16301652 if ( g_fileInputOffset < g_fileInputText.size () )
16311653 return g_fileInputText[ g_fileInputOffset++ ];
16321654
1633- return (char ) ConsoleConfiguration::portable_getch ();
1655+ char c = (char ) ConsoleConfiguration::portable_getch ();
1656+ // tracer.Trace( "get_next_kbd_char got %d from portable_getch\n", c );
1657+ if ( 10 == c ) // linux and windows will return LF, not CR, which is what CP/M apps require
1658+ {
1659+ // many cp/m apps require CR, not LF to terminate a line
1660+ tracer.Trace ( " get_next_kbd_char translated LF 10 to CR 13\n " );
1661+ c = 13 ;
1662+ }
1663+ return c;
16341664} // get_next_kbd_char
16351665
16361666bool is_kbd_char_available ()
@@ -2867,6 +2897,11 @@ uint8_t x80_invoke_hook()
28672897 ptime->minute = packBCD ( (uint8_t ) plocal->tm_min );
28682898 reg.a = packBCD ( (uint8_t ) plocal->tm_sec );
28692899#endif
2900+
2901+ #ifdef TARGET_BIG_ENDIAN
2902+ ptime->swap_endian ();
2903+ #endif
2904+
28702905 set_bdos_status ();
28712906 break ;
28722907 }
@@ -2894,6 +2929,10 @@ uint8_t x80_invoke_hook()
28942929 ptime->second = (uint16_t ) plocal->tm_sec ;
28952930 ptime->millisecond = (uint16_t ) ( ms / 10 ); // hundredths of a second;
28962931#endif
2932+
2933+ #ifdef TARGET_BIG_ENDIAN
2934+ ptime->swap_endian ();
2935+ #endif
28972936 set_bdos_status ();
28982937 break ;
28992938 }
@@ -3034,16 +3073,15 @@ void help()
30343073 exit ( 0 );
30353074} // help
30363075
3037-
3038- void version () // Display version information
3076+ void version ()
30393077{
30403078#ifdef NDEBUG
30413079 const char * flavor = " Release" ;
30423080#else
30433081 const char * flavor = " Debug" ;
30443082#endif
3045- printf (" %s: Version %s%s%s %s Compiled: " , FILENAME, VERSION, BUILD, COMMIT_ID, flavor);
3046- if (__DATE__[4 ] == ' ' )
3083+ printf (" %s: Version %s%s%s %s Compiled: " , FILENAME, VERSION, BUILD, COMMIT_ID, flavor );
3084+ if ( ' ' == __DATE__[4 ] )
30473085 printf ( " 0%c %c%c%c %s %s\n " , __DATE__[5 ], __DATE__[0 ], __DATE__[1 ], __DATE__[2 ], &__DATE__[7 ], __TIME__ );
30483086 else
30493087 printf ( " %c%c %c%c%c %s %s\n " , __DATE__[4 ], __DATE__[5 ], __DATE__[0 ], __DATE__[1 ], __DATE__[2 ], &__DATE__[7 ], __TIME__ );
@@ -3206,8 +3244,8 @@ int main( int argc, char * argv[] )
32063244 if ( ' V' == ca )
32073245 {
32083246 version ();
3209- printf ( " License CC0 1.0 Universal: See <https://creativecommons.org/publicdomain/zero/1.0/>.\n " );
3210- exit ( 0 );
3247+ printf (" License CC0 1.0 Universal: See <https://creativecommons.org/publicdomain/zero/1.0/>.\n " );
3248+ exit (0 );
32113249 }
32123250#if defined( _WIN32 ) // Windows only
32133251 else if ( ' C' == parg[1 ] ) // MT - moved other wise option would be converted to lower case before it was tested
@@ -3450,6 +3488,10 @@ int main( int argc, char * argv[] )
34503488 pdpb->cks = 64 ;
34513489 pdpb->off = 0 ;
34523490
3491+ #ifdef TARGET_BIG_ENDIAN
3492+ pdpb->swap_endian ();
3493+ #endif
3494+
34533495 reg.powerOn (); // set default values of registers
34543496 reg.pc = 0x100 ;
34553497 reg.sp = BDOS_ENTRY - 2 ; // the stack is written to below this address. 2 bytes here are zero for ret from app
0 commit comments