Skip to content

Commit 7b304dc

Browse files
authored
Merge pull request #7 from kbr-net/v08
V08
2 parents 8d91c36 + e5d75b5 commit 7b304dc

File tree

7 files changed

+211
-63
lines changed

7 files changed

+211
-63
lines changed

.gitignore

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
atmega328-hx8347g/
2-
!atmega328-hx8347g/Makefile
3-
atmega328-ili9329/
4-
!atmega328-ili9329/Makefile
5-
atmega328-ili9341/
6-
!atmega328-ili9341/Makefile
7-
!atmega328-ili9341/README
8-
sdrive-ctrl/
1+
atmega328-*/
2+
!atmega328-*/Makefile
3+
!atmega328-*/README
4+
sdrive-ctrl/*.com
95
.idea/

HISTORY

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v0.8:
2+
- drive motor simulation
3+
- support for timing based sector access on ATX files
4+
- some more fixes in ATX file handling
5+
- added support for ILI9340 display
6+
17
v0.7:
28
- fixed error in FileFind function
39
- fixed scrolling issue on tape- and debug page

SDrive.c

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
//#define DATE "20140519"
3131
#define SWVERSIONMAJOR 0
32-
#define SWVERSIONMINOR 7
32+
#define SWVERSIONMINOR 8
3333
//#define DEVID 0x53444e47
3434
//#define DEVID 0x474e4453 // SDNG reverse!
3535

@@ -80,12 +80,13 @@ u32 n_actual_mmc_sector;
8080
unsigned char n_actual_mmc_sector_needswrite;
8181
unsigned char atari_sector_buffer[256];
8282
u08 atari_sector_status = 0xff;
83+
u16 last_angle_returned;
8384

8485
////does not work correctly any more, don't know why?
8586
////But we have enaugh RAM free yet
8687
//#define FileFindBuffer (atari_sector_buffer+256-11) //pri vyhledavani podle nazvu
8788
char FileFindBuffer[11];
88-
char DebugBuffer[14];
89+
char DebugBuffer[20];
8990

9091
struct GlobalSystemValues GS;
9192
struct FileInfoStruct FileInfo; //< file information for last file accessed
@@ -310,17 +311,38 @@ void Clear_atari_sector_buffer_256()
310311
////some more globals
311312
struct sio_cmd cmd_buf;
312313
unsigned char virtual_drive_number;
314+
unsigned char motor = 0;
313315
//Parameters
314316
struct SDriveParameters sdrparams;
315317

316318
void process_command(); //define, because it's after main!
317319

318320
void sio_debug (char status) {
319321
//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);
321323
outbox(DebugBuffer);
322324
}
323325

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+
324346
//----- Begin Code ------------------------------------------------------------
325347
int main(void)
326348
{
@@ -332,6 +354,17 @@ int main(void)
332354
PCICR = (1<<PCIE1);
333355
PCMSK1 = (1<<PCINT13); // for CMD_PIN
334356

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+
335368
//SD_CARD_EJECTED:
336369

337370
fastsio_active=0;
@@ -778,6 +811,7 @@ void process_command ()
778811
u08 err;
779812
send_ACK();
780813
LED_RED_ON(virtual_drive_number); // LED on
814+
motor_on();
781815
if (FileInfo.percomstate == 2) //XXX: Could not work until image exists!
782816
err = newFile(IMSIZE3);
783817
else
@@ -888,6 +922,7 @@ void process_command ()
888922
if (FileInfo.vDisk->flags & FLAGS_ATRNEW) { //create new image
889923
send_ACK();
890924
LED_RED_ON(virtual_drive_number); // LED on
925+
motor_on();
891926
if(newFile(IMSIZE2))
892927
goto Send_NACK_and_set_FLAGS_WRITEERROR_and_ST_IDLE;
893928
else {
@@ -1140,11 +1175,12 @@ bytes 9-11 Drive interface type string "IDE"
11401175
if(n_sector==0)
11411176
goto Send_ERR_and_DATA;;
11421177

1178+
motor_on();
11431179
if( !(FileInfo.vDisk->flags & FLAGS_XEXLOADER) )
11441180
{
11451181
if(FileInfo.vDisk->flags & FLAGS_ATXTYPE)
11461182
{
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)) {
11481184
goto Send_ERR_and_DATA;
11491185
}
11501186
}
@@ -1324,7 +1360,7 @@ bytes 9-11 Drive interface type string "IDE"
13241360

13251361
FileInfo.percomstate=0;
13261362

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
13281364
//(FileInfo.vDisk->atr_medium_size); // medium/single
13291365
if (FileInfo.vDisk->flags & FLAGS_ATRMEDIUMSIZE) atari_sector_buffer[0]|=0x80;
13301366
//((FileInfo.vDisk->atr_sector_size==256)?0x20:0x00); // double/normal sector size
@@ -2056,11 +2092,12 @@ bytes 9-11 Drive interface type string "IDE"
20562092
case 0xFF: // set actual directory
20572093
{
20582094
unsigned char ret;
2095+
unsigned char drive = cmd_buf.cmd & 0xf;
20592096

2060-
if ( (cmd_buf.cmd&0xf) < DEVICESNUM )
2097+
if ( drive < DEVICESNUM )
20612098
{
20622099
//set pointer to corresponding drive
2063-
FileInfo.vDisk = &vDisk[cmd_buf.cmd&0xf];
2100+
FileInfo.vDisk = &vDisk[drive];
20642101
//copy dir_cluster from tmp Struct
20652102
FileInfo.vDisk->dir_cluster=tmpvDisk.dir_cluster;
20662103
}
@@ -2151,7 +2188,11 @@ bytes 9-11 Drive interface type string "IDE"
21512188
atari_sector_buffer[10] == 'X' )
21522189
{
21532190
//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
21552196
FileInfo.vDisk->flags|=(FLAGS_DRIVEON|FLAGS_ATXTYPE);
21562197
}
21572198
else
@@ -2160,11 +2201,11 @@ bytes 9-11 Drive interface type string "IDE"
21602201
FileInfo.vDisk->flags|=FLAGS_DRIVEON|FLAGS_XEXLOADER|FLAGS_ATRMEDIUMSIZE;
21612202
}
21622203

2163-
if((cmd_buf.cmd&0xf) != 0 && ((cmd_buf.cmd&0xf) < DEVICESNUM)) {
2204+
if(drive != 0 && drive < DEVICESNUM) {
21642205
//set new filename to button
21652206
fatGetDirEntry(cmd_buf.aux,0);
21662207
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];
21682209
name = pgm_read_ptr(&bp->name);
21692210
strncpy(&name[3], (char*)atari_sector_buffer, 12);
21702211
//redraw display only, if we are on

0 commit comments

Comments
 (0)