29
29
30
30
//#define DATE "20140519"
31
31
#define SWVERSIONMAJOR 0
32
- #define SWVERSIONMINOR 7
32
+ #define SWVERSIONMINOR 8
33
33
//#define DEVID 0x53444e47
34
34
//#define DEVID 0x474e4453 // SDNG reverse!
35
35
@@ -80,12 +80,13 @@ u32 n_actual_mmc_sector;
80
80
unsigned char n_actual_mmc_sector_needswrite ;
81
81
unsigned char atari_sector_buffer [256 ];
82
82
u08 atari_sector_status = 0xff ;
83
+ u16 last_angle_returned ;
83
84
84
85
////does not work correctly any more, don't know why?
85
86
////But we have enaugh RAM free yet
86
87
//#define FileFindBuffer (atari_sector_buffer+256-11) //pri vyhledavani podle nazvu
87
88
char FileFindBuffer [11 ];
88
- char DebugBuffer [14 ];
89
+ char DebugBuffer [20 ];
89
90
90
91
struct GlobalSystemValues GS ;
91
92
struct FileInfoStruct FileInfo ; //< file information for last file accessed
@@ -310,17 +311,38 @@ void Clear_atari_sector_buffer_256()
310
311
////some more globals
311
312
struct sio_cmd cmd_buf ;
312
313
unsigned char virtual_drive_number ;
314
+ unsigned char motor = 0 ;
313
315
//Parameters
314
316
struct SDriveParameters sdrparams ;
315
317
316
318
void process_command (); //define, because it's after main!
317
319
318
320
void sio_debug (char status ) {
319
321
//print the last cmd
320
- sprintf_P (DebugBuffer , PSTR ("%.2x %.2x %.2x %.2x %c" ), cmd_buf .dev , cmd_buf .cmd , cmd_buf .aux1 , cmd_buf .aux2 , status );
322
+ sprintf_P (DebugBuffer , PSTR ("%.2x %.2x %.2x %.2x %c %u " ), cmd_buf .dev , cmd_buf .cmd , cmd_buf .aux1 , cmd_buf .aux2 , status , last_angle_returned );
321
323
outbox (DebugBuffer );
322
324
}
323
325
326
+ void motor_on () {
327
+ TCCR1B = _BV (WGM12 ) | _BV (CS11 ) | _BV (CS10 ); // Timer 1 CTC mode, clk/64 start
328
+ // 16MHz/64 = 250KHz(4µs)
329
+ motor = 1 ;
330
+ Draw_Circle (5 ,5 ,3 ,1 ,Green );
331
+ }
332
+
333
+ void motor_off () {
334
+ TCCR1B = 0 ; // Timer 1 stop
335
+ motor = 0 ;
336
+ Draw_Circle (5 ,5 ,3 ,1 ,Black );
337
+ }
338
+
339
+ ISR (TIMER1_COMPA_vect ) {
340
+ if (motor )
341
+ motor ++ ;
342
+ if (motor > 20 )
343
+ motor_off ();
344
+ }
345
+
324
346
//----- Begin Code ------------------------------------------------------------
325
347
int main (void )
326
348
{
@@ -332,6 +354,17 @@ int main(void)
332
354
PCICR = (1 <<PCIE1 );
333
355
PCMSK1 = (1 <<PCINT13 ); // for CMD_PIN
334
356
357
+ //Analog comperator
358
+ ACSR |= _BV (ACIC ) | _BV (ACD ); // set input capture to AC, and disable it
359
+ // (ICP pin has conflict with touchscreen otherwise, and saves power)
360
+ DIDR0 = 0b11111 ; // disable digital input on analog pins(PC0-PC5), saves also power
361
+ // (are only used as output, btw. PC5 as interrupt)
362
+
363
+ //init timer
364
+ GTCCR |= _BV (PSRSYNC ); // Prescaler reset
365
+ OCR1A = 26042U * 2 ; // max count
366
+ TIMSK1 |= _BV (OCIE1A ); // enable interrupt on compare match(overflow)
367
+
335
368
//SD_CARD_EJECTED:
336
369
337
370
fastsio_active = 0 ;
@@ -778,6 +811,7 @@ void process_command ()
778
811
u08 err ;
779
812
send_ACK ();
780
813
LED_RED_ON (virtual_drive_number ); // LED on
814
+ motor_on ();
781
815
if (FileInfo .percomstate == 2 ) //XXX: Could not work until image exists!
782
816
err = newFile (IMSIZE3 );
783
817
else
@@ -888,6 +922,7 @@ void process_command ()
888
922
if (FileInfo .vDisk -> flags & FLAGS_ATRNEW ) { //create new image
889
923
send_ACK ();
890
924
LED_RED_ON (virtual_drive_number ); // LED on
925
+ motor_on ();
891
926
if (newFile (IMSIZE2 ))
892
927
goto Send_NACK_and_set_FLAGS_WRITEERROR_and_ST_IDLE ;
893
928
else {
@@ -1140,11 +1175,12 @@ bytes 9-11 Drive interface type string "IDE"
1140
1175
if (n_sector == 0 )
1141
1176
goto Send_ERR_and_DATA ;;
1142
1177
1178
+ motor_on ();
1143
1179
if ( !(FileInfo .vDisk -> flags & FLAGS_XEXLOADER ) )
1144
1180
{
1145
1181
if (FileInfo .vDisk -> flags & FLAGS_ATXTYPE )
1146
1182
{
1147
- if (!loadAtxSector (n_sector , & atari_sector_size , & atari_sector_status )) {
1183
+ if (!loadAtxSector (virtual_drive_number , n_sector , & atari_sector_size , & atari_sector_status )) {
1148
1184
goto Send_ERR_and_DATA ;
1149
1185
}
1150
1186
}
@@ -1324,7 +1360,7 @@ bytes 9-11 Drive interface type string "IDE"
1324
1360
1325
1361
FileInfo .percomstate = 0 ;
1326
1362
1327
- atari_sector_buffer [0 ] = 0x10 ; //0x00 motor off 0x10 motor on
1363
+ atari_sector_buffer [0 ] = motor ? 0 : 0x10 ; //0x00 motor off 0x10 motor on
1328
1364
//(FileInfo.vDisk->atr_medium_size); // medium/single
1329
1365
if (FileInfo .vDisk -> flags & FLAGS_ATRMEDIUMSIZE ) atari_sector_buffer [0 ]|=0x80 ;
1330
1366
//((FileInfo.vDisk->atr_sector_size==256)?0x20:0x00); // double/normal sector size
@@ -2056,11 +2092,12 @@ bytes 9-11 Drive interface type string "IDE"
2056
2092
case 0xFF : // set actual directory
2057
2093
{
2058
2094
unsigned char ret ;
2095
+ unsigned char drive = cmd_buf .cmd & 0xf ;
2059
2096
2060
- if ( ( cmd_buf . cmd & 0xf ) < DEVICESNUM )
2097
+ if ( drive < DEVICESNUM )
2061
2098
{
2062
2099
//set pointer to corresponding drive
2063
- FileInfo .vDisk = & vDisk [cmd_buf . cmd & 0xf ];
2100
+ FileInfo .vDisk = & vDisk [drive ];
2064
2101
//copy dir_cluster from tmp Struct
2065
2102
FileInfo .vDisk -> dir_cluster = tmpvDisk .dir_cluster ;
2066
2103
}
@@ -2151,7 +2188,11 @@ bytes 9-11 Drive interface type string "IDE"
2151
2188
atari_sector_buffer [10 ] == 'X' )
2152
2189
{
2153
2190
//ATX
2154
- loadAtxFile (); // TODO: check return value
2191
+ if (drive > 2 ) { // support first 2 drives only because of to less RAM!
2192
+ outbox_P (PSTR ("only 2 drives!" ));
2193
+ break ;
2194
+ }
2195
+ loadAtxFile (drive ); // TODO: check return value
2155
2196
FileInfo .vDisk -> flags |=(FLAGS_DRIVEON |FLAGS_ATXTYPE );
2156
2197
}
2157
2198
else
@@ -2160,11 +2201,11 @@ bytes 9-11 Drive interface type string "IDE"
2160
2201
FileInfo .vDisk -> flags |=FLAGS_DRIVEON |FLAGS_XEXLOADER |FLAGS_ATRMEDIUMSIZE ;
2161
2202
}
2162
2203
2163
- if (( cmd_buf . cmd & 0xf ) != 0 && (( cmd_buf . cmd & 0xf ) < DEVICESNUM ) ) {
2204
+ if (drive != 0 && drive < DEVICESNUM ) {
2164
2205
//set new filename to button
2165
2206
fatGetDirEntry (cmd_buf .aux ,0 );
2166
2207
pretty_name ((char * ) atari_sector_buffer );
2167
- bp = & tft .pages [PAGE_MAIN ].buttons [cmd_buf . cmd & 0xf ];
2208
+ bp = & tft .pages [PAGE_MAIN ].buttons [drive ];
2168
2209
name = pgm_read_ptr (& bp -> name );
2169
2210
strncpy (& name [3 ], (char * )atari_sector_buffer , 12 );
2170
2211
//redraw display only, if we are on
0 commit comments