C1541-III mbed edition

Dependencies:   mbed

Committer:
gertk
Date:
Mon Aug 22 05:48:51 2011 +0000
Revision:
0:28557a4d2215
Child:
1:0cbbb66a6100
very early test version, works only with FAT16 formatted sd cards

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gertk 0:28557a4d2215 1 /*==================================================================================*/
gertk 0:28557a4d2215 2 /*== This software is designed to be compiled by the Hi-Tech PIC Ccompiler ==*/
gertk 0:28557a4d2215 3 /*== ==*/
gertk 0:28557a4d2215 4 /*== Attention, make sure to compile with the following options selected: ==*/
gertk 0:28557a4d2215 5 /*== printf: integer + long + float ==*/
gertk 0:28557a4d2215 6 /*==================================================================================*/
gertk 0:28557a4d2215 7 /* 1541-III (simply said: a 1541 clone that uses MMC/SD-cards) */
gertk 0:28557a4d2215 8 /* */
gertk 0:28557a4d2215 9 /* This is MAIN */
gertk 0:28557a4d2215 10 /* ------------ */
gertk 0:28557a4d2215 11 /* */
gertk 0:28557a4d2215 12 /* This program is designed to control the 1541-III project: */
gertk 0:28557a4d2215 13 /* The 1541-III project is a device to be connected to the IEC-bus of a C64 */
gertk 0:28557a4d2215 14 /* The device will act as if it was a 1541 diskdrive. The diskimages are to be */
gertk 0:28557a4d2215 15 /* stored on a MMC or SD-card in the D64 file format (the most common emulator file */
gertk 0:28557a4d2215 16 /* for C64 disk images. By selecting a specific D64 file on the card you select the */
gertk 0:28557a4d2215 17 /* diskimage to be seen by the connected C64. By mimmicing a 1541 drive the C64 does*/
gertk 0:28557a4d2215 18 /* not require any extra software while keeping the flexability of a modern medium. */
gertk 0:28557a4d2215 19 /* This way the huge amount of software on the WEB becomes available on your stock */
gertk 0:28557a4d2215 20 /* C64, like the good old days, checking out your new 'disks' full with hours of fun*/
gertk 0:28557a4d2215 21 /* */
gertk 0:28557a4d2215 22 /* Note: */
gertk 0:28557a4d2215 23 /* a sector on a 5,25" disk has the size of 256 bytes, this is also called a block */
gertk 0:28557a4d2215 24 /* */
gertk 0:28557a4d2215 25 /* ATTENTION: all settings are calculated for a crystal freq. of 20MHz */
gertk 0:28557a4d2215 26 /* */
gertk 0:28557a4d2215 27 /*----------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 28
gertk 0:28557a4d2215 29 #define RELEASE_VERSION 8 /*last 2 digits of Year */
gertk 0:28557a4d2215 30 #define RELEASE_VERSION_SUB 2 /*Month */
gertk 0:28557a4d2215 31 #define RELEASE_VERSION_SUB_SUB 27 /*Day */
gertk 0:28557a4d2215 32
gertk 0:28557a4d2215 33 /* History:
gertk 0:28557a4d2215 34 --------
gertk 0:28557a4d2215 35
gertk 0:28557a4d2215 36 IMPORTANT to implement ASAP, IEC abort: the computer sends an ATN during data transfer from device to computer, the device sees that this is a special situation and aborts, freeing up the bus and the computer will get it's prompt back (test this by loading a program and pressing run/stop during loading)
gertk 0:28557a4d2215 37 (this information was supplied by: Dirk (a.k.a. SKERN, from www.dienstagstreff.de)
gertk 0:28557a4d2215 38
gertk 0:28557a4d2215 39 debug datahandler!!!
gertk 0:28557a4d2215 40 2011-08-22 First version of this software ported to mbed by Gert van der Knokke
gertk 0:28557a4d2215 41 2008-02-27 release date of this wonderfull version
gertk 0:28557a4d2215 42 2008-02-20 removed the T64 detection in the filefilter routine. Simply because the T64 is not supported yet and showing the T64 files in the card directory would give the wrong impression or simply said it would be confusing.
gertk 0:28557a4d2215 43 2008-02-17 fixed the spaces at the end of a filename-bug (in routine D64Directory()). When a filename has normal (0x20) spaces at the end these are filtered out, so you do not see them in the loaded directory. But since the fileseek routines encounter them they never will report a match (because the last two chars (spaces) are missing)
gertk 0:28557a4d2215 44 The routine ImageDirectory is renamed to D64Directory simply because the D64 directory routine cannot easily be transformed into something universal
gertk 0:28557a4d2215 45 2008-02-15 added a default value to error_code declaration
gertk 0:28557a4d2215 46 made the separation line in the card-directory a bit nicer and added an extra check that removed the undesired first seperator line
gertk 0:28557a4d2215 47 2008-02-14 changed the serial debugging output to some nice ASCII/art looking debugging output (filling some spare minutes)
gertk 0:28557a4d2215 48 did some T64-file preparations...
gertk 0:28557a4d2215 49 2008-02-12 The save bug as reported 21-08-2007 by: Andreas Ekmark - "File not found error" if the save was successful. - "File found ok" if the save failed
gertk 0:28557a4d2215 50 As suggested this is indeed the status from the "does file exist" check that must occur prior tosaving that is still reported after the save...
gertk 0:28557a4d2215 51 The probem lies in the not correctly updating of the display and the incorrect updating of the register error_code in the routine set errorcode
gertk 0:28557a4d2215 52 2008-02-11 fixed a problem with the 1541-III powered directly by the VIC20's cassetteport. The 1541-III will hang with the drive LED=green and the LCD in the splash-screen mode. This problem does not occur when the 1541-III is in bootloader-mode. It appears that the VIC20's IEC bus is not stable directly after powerup (causing the 1541-III to trigger falsely and wainting endlessly for signals that never come. Waiting for 2 seconds (as a normal drive does) and then enabling the ATN interrupt solves this problem.
gertk 0:28557a4d2215 53 2008-02-10 removed write protect check as it does not have any value and can be very anoying
gertk 0:28557a4d2215 54 so now you can use a card wether it is or isn't write protected with the "switch" on the side (SD-card card only)
gertk 0:28557a4d2215 55 2008-02-08 fixed the problem in FAT.c (filesearch) regarding the backwards searching within subdirectories.
gertk 0:28557a4d2215 56 As this only is a problem with the use of the buttons... it was discovered at the last moment and now it is fixed. Subdirectories are now FULLY functional <hurray>
gertk 0:28557a4d2215 57 2008-02-05 tested the VIC20 mode on a real vic20, and as expected, there where still too much chars on one line, fixed
gertk 0:28557a4d2215 58 2008-02-04 fixed a smull bug in seekfileoncard() routine. it failed in finding a file of exactly 8 characters long (8.3 name). This situation was not checked, it is now fixed.
gertk 0:28557a4d2215 59 2008-02-01 improved (fat.c) filesearch routine for subdirectory support, it appears to work
gertk 0:28557a4d2215 60 2008-01-31 testing of subdirs
gertk 0:28557a4d2215 61 2008-01-25 added some extra output on the LCD contrast setting, when a user presses a button it shows on the serial port
gertk 0:28557a4d2215 62 2008-01-15 countfiles now show the user that it is counting files (message to display)
gertk 0:28557a4d2215 63 loading of carddirectory now displays the progressbar as it should, during loading you can clearly see the 3 different passes (notice the change in barspeed) this is caused by the fact that the number of files does not match the number of subdirectories and does not match the number of images (ie D64)
gertk 0:28557a4d2215 64 2008-01-12 fixed problem with root selection when using buttons (these routines required changes due to the added subdir functionality)
gertk 0:28557a4d2215 65 during selection using the buttons, the display uses a bar. This bar was a simple progress bar which is confusing as file selection has nothing to do with progress,
gertk 0:28557a4d2215 66 so this is now changed to sort of slider, like you may know from "modern" operating systems like Windows
gertk 0:28557a4d2215 67 Seekfileoncard return the file index (again)
gertk 0:28557a4d2215 68 Print_file_info routine has become obsolete, as this information is allready in the display (bottom right) in the form of the mode of operation
gertk 0:28557a4d2215 69 The directory is shown in 3 passes (pass-1=subdirs, pass-2=images, pass-3=files), the third pass shows filesize in blocks (as in any other directory)
gertk 0:28557a4d2215 70 Added the suggestions made by jussi, to the LCD routines for better LCD clone compatibillity
gertk 0:28557a4d2215 71 2008-01-11 restoring of the button functions, these functions required changes due to the added subdir functionality
gertk 0:28557a4d2215 72 2008-01-10 added countfiles routine (counting files can be usefull after all)
gertk 0:28557a4d2215 73 2008-01-08 Playing with subdirs (part...+2)
gertk 0:28557a4d2215 74 nu is er de uitzondering Root (index 0) maar eigenlijk is dit geen uitzondering.
gertk 0:28557a4d2215 75 Alle subdirs heben deze optie ook. index 0 betekent eigenlijk niets meer dan dat er geen D64 file geselecteerd is en dat we in de harddiskmode zitten
gertk 0:28557a4d2215 76 2008-01-07 Playing with subdirs (part...+1)
gertk 0:28557a4d2215 77 2008-01-05 Playing with subdirs (part...)
gertk 0:28557a4d2215 78 2008-01-04 The routine D64Directory is renamed to ImageDirectory, this because in the future not only D64 will be supported, by keeping all filetypes under the same directory routine, the software stays easy to read. But the name D64Directory is misleading if it reads more the D64's, so the name D64Directory is changed into ImageDirectory as it will show the contents of the image-file in directory style
gertk 0:28557a4d2215 79 2008-01-03 REQUIRES MANUAL CHANGE: the file pointer (when a directory is loaded is no longer a reference to the fileindex. since the fileindex principle has been dropped as it will be no longer practical when used in combination with subdirectories)
gertk 0:28557a4d2215 80 2008-01-02 removal of code that uses index number to refer to files
gertk 0:28557a4d2215 81 REQUIRES MANUAL CHANGE- it is no longer possible to use $0 bla bla bla for D64 file searches, although simple in use. It is no longer practical when files are stored in subdirs. It would take to long to scan the card after insertion and the filenumber would have to be 5 digits to address all possible files on a 1 GByte card
gertk 0:28557a4d2215 82 2007-12-26 counting the number of files on the card is a silly thing to do when we want to break open the 512 file barier by using subdirectories, so these routines are removed
gertk 0:28557a4d2215 83 the files are now displayed in groups when the carddirectory is loaded. Dir, D64, PRG-files this makes it easier to read (looks more organised as well (but's thats because its organised offcourse)
gertk 0:28557a4d2215 84 Sorting on alfabetical order is not going to happen as it would take too much memory or would be too time consuming
gertk 0:28557a4d2215 85 2007-12-23 added the routines to show a directory, the difficult part has yet to come... using these directories, something for the next few... weeks?!?!
gertk 0:28557a4d2215 86 2007-12-23 worked on directory formatting (i.o.w. the results caused by LOAD"$CARD"), now the directory width is different for the normal and the VIC20 mode (select by using the UI+ command to set the IEC speed)
gertk 0:28557a4d2215 87 when used in VIC-20 mode the directory width is limitted to 20 characters, so it displays nicely on a VIC-20
gertk 0:28557a4d2215 88 when used in normal mode the directory width is limitted to 28 characters, so that it holds the max amount of info, while being compatible with normal directory sizes
gertk 0:28557a4d2215 89 Every entry that needs to be loaded as a directory now is display with a proceeding $-sign.
gertk 0:28557a4d2215 90 This because the .PRG and .D64 files are no longer printed with their extension in the filename, but displayed as TYPE at the end of the line.
gertk 0:28557a4d2215 91 On a SX this might be a bit difficult to read (if you are in a hurry). By adding the $-sign, it becomes more clear how to load it AND
gertk 0:28557a4d2215 92 it saves the user the trouble of inserting the $-sign in the directory entry when he/she wants to load it.
gertk 0:28557a4d2215 93 Changed the search routine "SeekFileOnCard" in order to work with the longer filenames and to accept filenames without extensions
gertk 0:28557a4d2215 94 2007-12-21 worked on directory formatting (making sure that it looks OK after LOAD"$")
gertk 0:28557a4d2215 95 also created 2 different directory looks. A small look for the VIC20 and a normal look for others.
gertk 0:28557a4d2215 96 Also the VIC20 mode (25% higher IEC-speed is kept in EEPROM, so the user has to configure this only once as long as he/she uses a VIC20)
gertk 0:28557a4d2215 97 Simply use the standard UI- and UI+ commands to toggle between normal and VIC20 mode (see manual)
gertk 0:28557a4d2215 98 2007-12-20 worked on longfilenames
gertk 0:28557a4d2215 99 2007-12-19 now that longfilenames profe to be functional, let's apply them in the carddirecory routine(s)
gertk 0:28557a4d2215 100 2007-12-18 experimenting with FAT extra's (playing with longfilenames)
gertk 0:28557a4d2215 101 2007-10-27 a small change in LCD_nokia_3310.c (see it's history) solved the inverted character problem, now lines of inverted
gertk 0:28557a4d2215 102 char look beter and the contrast is not disturbed. I expect that this would solve other contrast problem as well,
gertk 0:28557a4d2215 103 there are people out there with LCD's that for some reason have a very "light" contrast and are difficult to read when
gertk 0:28557a4d2215 104 the display's content changes rapidly, it must be something likes this.
gertk 0:28557a4d2215 105 2007-10-25 removed the 1541-III SX detection as the 1541-III inside my SX is nothing more then a v1.0 upgraded to v1.1
gertk 0:28557a4d2215 106 2007-10-24 added the 1541-III dtv C64 edition to the list of recognized devices
gertk 0:28557a4d2215 107 2007-10-18 added the 1541-III second batch to the list of recognized devices
gertk 0:28557a4d2215 108 2007-10-17 added some extra features for hardware testing
gertk 0:28557a4d2215 109 when no card is inserted and the user pushes the i-button then the hardwaretestmenu is entered
gertk 0:28557a4d2215 110 2007-10-11 used the enum statement for the first time, it simplifies constant coding... a little
gertk 0:28557a4d2215 111 2007-08-15 still lot's of work to be done, but this version is suitable for beta-release... so release it!
gertk 0:28557a4d2215 112 people have been waiting long enough for a more stable release... so give it to them although it's not 100%
gertk 0:28557a4d2215 113 it IS better then the previous versions.
gertk 0:28557a4d2215 114 2007-06-30 added a mode of operation indicator, to show if we are operating in D64 mode or HD mode (root dir of card)
gertk 0:28557a4d2215 115 during button selection the progress-bar indicates where we are in the directory
gertk 0:28557a4d2215 116 during button selection some additional file information is shown on the third line
gertk 0:28557a4d2215 117 2007-06-28 small changes in display layout, moved index to error-line
gertk 0:28557a4d2215 118 2007-06-26 placed sample at seterrorcode. This is the best location because this requires only one place where the same sound can be connected to multiple error situations
gertk 0:28557a4d2215 119 display line-2 now shows the last error code (if not 0 or 73 (directly after reset))
gertk 0:28557a4d2215 120 the filename that is being loaded or saved is not displayed to the display any more (only visible via serial port)
gertk 0:28557a4d2215 121 2007-06-25 added the sound samples made by Willem K.(Thanks a lot Willem for your excellent work, unfortunatley the
gertk 0:28557a4d2215 122 hardware does not allow it to play the samples to it's full quality, but the sounds are still very
gertk 0:28557a4d2215 123 distinctive and recognisable as 1541 drive sounds)
gertk 0:28557a4d2215 124 2007-05-17 added a clear display line after the execution of LOAD, SAVE etc.
gertk 0:28557a4d2215 125 2007-05-15 the last few days have been spend with typing old listings from books to further test the current firmware
gertk 0:28557a4d2215 126 2007-05-10 the main do, while loop that checked for ATN was changed to a while(ATN... loop, that had a check for the release of the data line, this solved all my problems
gertk 0:28557a4d2215 127 set the delay to 1000uSec, no problems any more.
gertk 0:28557a4d2215 128 2007-05-09 the new delay location and new value of 100uS was set back to 200uS (still at the new (better) location (the main loop)
gertk 0:28557a4d2215 129 2007-04-25 IEC_bus.c CheckForCommand had an delay of 200uS to ensure the "frame to release of ATN'-time" of min 20uS, this is removed and now in the higher level IEC staemachine (main.c)
gertk 0:28557a4d2215 130 the new location of this delay ensure a quicker response time when waiting for a command
gertk 0:28557a4d2215 131 2007-04-24 stared at the code tried to analyze what went wrong, failed to solve it
gertk 0:28557a4d2215 132 2007-04-23 IECUNDOTURNAROUND should not check on clock, corrected in IEC_bus.C
gertk 0:28557a4d2215 133 2007-04-21 demonstration of project at Maarssen, a very pleasant day. Learned that directories on the card make the 1541-III fail completely although it looks like it all works at first.
gertk 0:28557a4d2215 134 timing within the GET# handling is not 100% correct, adding some printf's for more info and suddenly there np problme no more, investigate further...
gertk 0:28557a4d2215 135 2007-04-18 added interrupt disabling within the datahandler, when the drive becomes a talker (caused by GET# statements) we must disable interrupts otherwise when the computer indicates the last GET# by pulling ATN low, we'd lock up because the interrupt pulls the data-line low and we still need to undo the turnaround (this was a tricky one, thank you my dear (DIY, 5Euro and self written visual basic software for windows PC's) PC logic analyzer
gertk 0:28557a4d2215 136 2007-04-15 removed the: print_device_status(" "); this was the last statement of the openhandler, this statement should not be needed at this location in the code!
gertk 0:28557a4d2215 137 removed the: print_device_status(" "); this was the last statement of the datahandler, this statement should not be needed at this location in the code!
gertk 0:28557a4d2215 138 ---------- Vacation @ Lommersbergen
gertk 0:28557a4d2215 139 2007-04-09 set the ATN interrupt filter value back to 25, tested with different values but 5 gives problems, 25 not, so we keep it at 25 (for now, keep this in mind, we need to get to the bottom of this someday)
gertk 0:28557a4d2215 140 note to myself: it apears that disabling of the buttons solves a lot of my problems, perhaps the AD conversion eats up so much time that it disturbs the IEC communication when it's not meant for us!
gertk 0:28557a4d2215 141 ATTENTION improved readbuttons() routine, it now FIRST checks if a button is pressed and THEN checks which button, this saves a lot of conversion time when no button is pressed, this time becomes available to the statemachine which now can respond much faster to events
gertk 0:28557a4d2215 142 | the LED RITHM blinking routines interfere with the IEC timing! DAMN! (those blinking routines I liked the most)
gertk 0:28557a4d2215 143 -> LED RITHM routines removed (all that beautifull work for nothing). But what is the use of a beautifull blinking LED when it interferes with the IEC-bus...
gertk 0:28557a4d2215 144 2007-04-07 - Bugfix in FAT.C reported and fixed by Mattias Olsson
gertk 0:28557a4d2215 145 - Intensive trafic on a different device may cause the 1541-III to trigger false, disturbing the communication between the CBM computer and the other device
gertk 0:28557a4d2215 146 Some additional checks are added to make sure that the 1541-III handles the UNTALK and UNLISTEN event ONLY when the 1541-III allready has left the IEC IDLE state
gertk 0:28557a4d2215 147 2007-04-05 added the function to readout the result of the opened buffer (GET#1, A$ directly after OPEN 1,8,2,"#")
gertk 0:28557a4d2215 148 2007-04-03 'fixed' bug in B-P command, it appeared that the real bug was in my BASIC program on my C64 (stupid typo regarding dev ID's,
gertk 0:28557a4d2215 149 so it worked on a real drive (8) but not on the 1541-III (9), if I had only swapped the devices to the other ID's the problem
gertk 0:28557a4d2215 150 would appread to be in the 1541 drive, which made it obvious that it was in the C64 program all along. But I had to find it
gertk 0:28557a4d2215 151 out the hard way (offcourse))
gertk 0:28557a4d2215 152 2007-04-02 worked on the same 'problem' again
gertk 0:28557a4d2215 153 2007-04-01 continue of the prev. day
gertk 0:28557a4d2215 154 the check IEC_CLOCK == 1 in UNDOTURNAROUND now has a time-out, simply to improve reliablillity... it helps a lot!
gertk 0:28557a4d2215 155 separated B-R and U1, since the first is 254 bytes and the second if the full 256 byte block-read
gertk 0:28557a4d2215 156 separated B-W and U2, since the first is 254 bytes and the second if the full 256 byte block-write
gertk 0:28557a4d2215 157 2007-03-31 data command (in IEC statemachine) now holds the check if the selected channel is opened, if the selected channel is not opened then the DATA command will be ignored (as it would on a normal drive)
gertk 0:28557a4d2215 158 testing and debugging the effects on the 1541-III when the C64 uses the GET# and INPUT# statement in a directory reading program that does not use the LOAD"$" syntax but U1 and B-P, the results are promissing, I'm on the right track...
gertk 0:28557a4d2215 159 2007-03-30 worked on the U1 and U2 command
gertk 0:28557a4d2215 160 added a buffer pointer to the D64blockread function and named this function D64blockread_new
gertk 0:28557a4d2215 161 added a buffer pointer to the D64blockwrite function and named this function D64blockwrite_new
gertk 0:28557a4d2215 162 replaced the code located under "errochannelhandler" under the openhandler (where it belongs)
gertk 0:28557a4d2215 163 2007-03-29 worked on the U1 and U2 command, these commands are handled in an identical way as the B-P command
gertk 0:28557a4d2215 164 2007-03-28 worked on the b-p command to get an idea of how the info is send towards the 1541 (this low level stuf is described nowhere and examples are very diverse,
gertk 0:28557a4d2215 165 although the mean the same, it is very confusing to say the least. But it becomes more and more clearer everyday...)
gertk 0:28557a4d2215 166 Improved the routine "valuefromstring" so it can now scan for a number, the first character in the tested string does not has to be a number. This makes it more flexible to use.
gertk 0:28557a4d2215 167 Also this routine returns the input string with a pointer to the last location (so you know where to find the second number etc.)
gertk 0:28557a4d2215 168 2007-03-27 worked on the open command and the b-p command
gertk 0:28557a4d2215 169 2007-03-26 created the DOS_buffer and DOS_channel structures to hold all the required information
gertk 0:28557a4d2215 170 2007-03-25 complete rework on the open command and on the buffer definitions... I was wrong all along (damn...)
gertk 0:28557a4d2215 171 removed the independent BAM_buffer in order to use the DOS_buffer at buffer location #4 (DOS_buffer[4].buffer[..]) as you'd expect it to found as it was a real drive
gertk 0:28557a4d2215 172 replaced the variable Dos_buffer.status to NextAction in order to keep track of the next action of this device
gertk 0:28557a4d2215 173 2007-03-23 added more comments and worked on the openhandler (made some small progress, but lots of work to be done)
gertk 0:28557a4d2215 174 2007-03-22 added extra comments (over serial) for easier debugging of new code
gertk 0:28557a4d2215 175 2007-03-20 just staring at the code...
gertk 0:28557a4d2215 176 2007-03-18 worked on the channel handling, lots of work to do... but very important so it must be done,
gertk 0:28557a4d2215 177 but it takes a lot of time before i will get it right, it's very confusing to implement (although
gertk 0:28557a4d2215 178 the concept is very clear and logical, the low level handling makes it complex and therefore
gertk 0:28557a4d2215 179 confusing if not written down correctly the first time
gertk 0:28557a4d2215 180 2007-03-15 changed the blinking routines to use only green in the first batch of 1541-III's (they do not have a tri-color LED)
gertk 0:28557a4d2215 181 added filter on ATN-line, to prevent possible glitches from false triggering the ATN-interrupt
gertk 0:28557a4d2215 182 2007-03-12 Created the color cycle routine
gertk 0:28557a4d2215 183 Created a small blink at every transmitted/received block
gertk 0:28557a4d2215 184 The LED fade on and fade off function is discarded because it function as expected.
gertk 0:28557a4d2215 185 The results are not worth the effort of coding the huge line of exeptions (fading leds are wanted at startup blabla but not during loading,
gertk 0:28557a4d2215 186 you might miss an important event, it creates additional loading delays which are anoying with small files etc.)
gertk 0:28557a4d2215 187 2007-03-08 LED fade-on/off function, the LED does not go on and off its fades gently to the required state
gertk 0:28557a4d2215 188 2007-03-07 replaced the labels RITHM and normal by LED_RITHM and LED_ERROR which is the correct and non confusing label that it should be all along. The new colors are: on=green, error=red, rithm=green+red
gertk 0:28557a4d2215 189 2007-03-05 tri-color led support, for new batch 1541-III DTV a red/green LED has been added to compensate for the lack of a display
gertk 0:28557a4d2215 190 2007-01-30 ...
gertk 0:28557a4d2215 191 2007-01-25 started with the coding of the following commands: B-P:, U1: and U2:
gertk 0:28557a4d2215 192 2006-12-27 start of EEPROM read/write support, this will be finished when sequential file handling is supported, since the EEPROM is best to be handled as a seq. file
gertk 0:28557a4d2215 193 2006-12-06 release date of firmware version
gertk 0:28557a4d2215 194 2006-11-21 reworked improvement... now also the disk-ID is used (if given by user)
gertk 0:28557a4d2215 195 simplified the splitstring on comma, column and equal into one routine: splitstringon_sign, where the sign to 'split on' must be given
gertk 0:28557a4d2215 196 2006-11-20 improved formatting routine, now the diskname is actually used (if given by user)
gertk 0:28557a4d2215 197 2006-11-15 Added some extra print to serial port, so you don't need the display if you're connected to the serial port (can't see why, as a terminal is larger then a nokia display)
gertk 0:28557a4d2215 198 BUG:direct loading of a prg file from root does not seem to work any more !?!?! thought it was fixed
gertk 0:28557a4d2215 199 Fixed: caused by checking for FILE_PRESENT, which should be !=FALSE, because the new routine have more output then TRUE or FALSE
gertk 0:28557a4d2215 200 2006-11-13 Added contrast setting under iec command control: open15,device,15,"LCDCONTRAST=ddd";close15
gertk 0:28557a4d2215 201 2006-11-12 Implemented the copy function, there was allready a beginning for several weeks, but never really implemented until now.
gertk 0:28557a4d2215 202 2006-11-11 Sint Maarten, dus de bel gaat vaak...
gertk 0:28557a4d2215 203 Finished the routines and testing of the D64 file selection (directory loading) by name entry
gertk 0:28557a4d2215 204 I.o.w. instead of LOAD"$24",8 you can now specify the filename LOAD"$filename.D64" (where filename must be exactly 8 chars and for the lazy ones, just use the *-wildcard)
gertk 0:28557a4d2215 205 Setting of device ID using software is functional
gertk 0:28557a4d2215 206 2006-11-09 started with the D64 file selection by name (user request, because currently it is D64 file selection by index only)
gertk 0:28557a4d2215 207 2006-11-08 did some additional testing on the save situation where no card is present, but it apears that this is vitually not responding to the data.
gertk 0:28557a4d2215 208 According to the logic analyser a real drive handles identical. This was not what I expected because this means that on a real drive and the 1541-III
gertk 0:28557a4d2215 209 when a user want to save data to a drive without a disk the user has to wait several seconds before the drive returns and then no confirmation is given until the errorchannel is read.
gertk 0:28557a4d2215 210 2006-11-07 added some extra checkpoints for card removal, there were some situations where the user could bypass the card removal checking routines,
gertk 0:28557a4d2215 211 causing unexpected behavior. This is now fixed.
gertk 0:28557a4d2215 212 2006-11-06 did some testing on the load with and without card inserted
gertk 0:28557a4d2215 213 2006-11-05 BUG: when trying to load from device 10 (on a computer where nothing is connected as device-10, the 1541-III prevent the error "device not present"from happening
gertk 0:28557a4d2215 214 BUGFIX: the FREEIEC routine in combination with the disabling of the ATN-based interrupt solved the problem
gertk 0:28557a4d2215 215 2006-11-03 BUG: the "unsigned char index_cnt;" in "void CardDirectory(void)" prevented the user from using more then 255 files on a single card
gertk 0:28557a4d2215 216 BUGFIX: "unsigned int index_cnt;", unfortunately I could not test this myself, since I could only store max. 247 files to my SD-card, strange, why !?!?! (they promissed me 512max.)
gertk 0:28557a4d2215 217 User request: added an extra space so that when more then 99files are stored on the card, the directory is still nicely aligned
gertk 0:28557a4d2215 218 BUG:loading of .PRG files does not seem to work when the whole filename is entered,
gertk 0:28557a4d2215 219 but it does work when a part of the filename followed by a * is entered... curious, but true?
gertk 0:28557a4d2215 220 BUGFIX: the CBM computers do not recognize the '~'-sign and when printed to screen
gertk 0:28557a4d2215 221 they show a pi-sign. Unfortunately, this sign cannot be entered during load/save.
gertk 0:28557a4d2215 222 so when doing this a 0xff value is substituted. Very unfortunate because this means
gertk 0:28557a4d2215 223 the comparison for the filenamesearch fails. By replacing the '~'-sign by the '/'-sign
gertk 0:28557a4d2215 224 these problems are simply avoided and all works as intended.
gertk 0:28557a4d2215 225 2006-11-02 ALL routines are functional again, hurray for me, wahoo!!!
gertk 0:28557a4d2215 226 2006-11-02 making all 1541-III functions functional again as it was intended. So that you can use
gertk 0:28557a4d2215 227 OPEN 15,9,15,"S:blabla"
gertk 0:28557a4d2215 228 as well as:
gertk 0:28557a4d2215 229 OPEN 15,9,15
gertk 0:28557a4d2215 230 PRINT#15,"S:blabla"
gertk 0:28557a4d2215 231 2006-11-01 1541-III is functional again HURRAY !!!
gertk 0:28557a4d2215 232 New statemachine functions, the big difference between the new staemachine and the old one is basiccally that the old statemachine
gertk 0:28557a4d2215 233 executed the open command BEFORE the UNLISTEN command, while the new statemachine executes the OPEN command AFTER the UNLISTEN
gertk 0:28557a4d2215 234 command, this is a big difference, suddenly some mysterious delays that could not been found in the specs are not required any
gertk 0:28557a4d2215 235 more. Suddenly it becomes clear that the strange delays were not neccessary after all as long as the proper statemachine was used.
gertk 0:28557a4d2215 236 2006-10-31 statemachine is better but not funcional yet... getting there
gertk 0:28557a4d2215 237 2006-10-30 fucked up the statemachine pretty bad... but it's the only way to build something better. Start with rebuilding it
gertk 0:28557a4d2215 238 tomorrow (in the mean time I feel like crying and I am very glad that I made beackups of the previous version, just in case I can't put it back together)
gertk 0:28557a4d2215 239 2006-10-25 placed the LOAD routines in channel-0 (thats the location where these routine belong in the real 1541)
gertk 0:28557a4d2215 240 placed the SAVE routines in channel-0 (thats the location where these routine belong in the real 1541)
gertk 0:28557a4d2215 241 fixed serious bug in the seekfreeblock(D64_decoder.c), the routine could point to a free block inside track18, this is evil. This bug is fixed. Now a free block for saving purposes will never be allocated in track-18
gertk 0:28557a4d2215 242 2006-10-24 changed LOAD"$0" for LOAD"$CARD" and make the LOAD"$"=LOAD"$0" this should provide enough support for the Prophet64 to operate with the 1541-III
gertk 0:28557a4d2215 243 load and save routines are only avaiable under channel 0 and 1
gertk 0:28557a4d2215 244 2006-10-23 the errorchannel was threated as a single channel only used for error messages, but in fact it is used for much more... which I only started to realize when I tried to implement more commands that also used the channel 15 (errorchannel)
gertk 0:28557a4d2215 245 because of this it was possible to use the command :
gertk 0:28557a4d2215 246 OPEN 15,9,15,"N:blabla"
gertk 0:28557a4d2215 247 but not the command:
gertk 0:28557a4d2215 248 OPEN 15,9,15
gertk 0:28557a4d2215 249 PRINT#15,"N:blabla"
gertk 0:28557a4d2215 250 this is now fixed (both commands work) since the errorchannel is not only used for the handling of the errormessages
gertk 0:28557a4d2215 251 2006-10-21 timing selection possible by using the UI- and UI+ command. for the DTV users this is not required as timings are automatically set to the fastest possible value (as determined by Jussi S.)
gertk 0:28557a4d2215 252 .D64-file selection by using the command sequence: OPEN1,8,1,"$x":CLOSE1 Did not change the display of the 1541-III, this is fixed. No the D64 filename on the display is only changed when a new file is selected
gertk 0:28557a4d2215 253 changed the routine print_device_status(const unsigned char *message), it accepted only values that it decoded into a string, that was nonsens and creates only large unreradable code, now that is changed so it accepts constant strings
gertk 0:28557a4d2215 254 this also makes it easier to print the same line to the serial port (usefull if you don't have an LCD connected or want to log the actions)
gertk 0:28557a4d2215 255 2006-10-20 made a beginning in implementing the 'adjusted' IEC-bus timings for the DTV (also required for the faster VIC-20 mode (user-command UI-)
gertk 0:28557a4d2215 256 2006-10-16 replaced the '.' in the errorcode 73 for '-' which should be better regarding readabillity
gertk 0:28557a4d2215 257 2006-10-15 shortened the default errorcode by nine characters (removed 1541-III<space>), it now only shows the versionnumber of the software
gertk 0:28557a4d2215 258 added a new device-type 1541-III v1_1 (to indicate the second batch. Actually this is only a detail, since there is no real difference in the first and second batch.
gertk 0:28557a4d2215 259 2006-10-13 changed to MPLAB v7.40, did nothing else, was to busy handling pre-orders, packing 1541-III's and sticking address labels on the box...
gertk 0:28557a4d2215 260 2006-10-11 tested the use of deselectingt the card, this did not hep in reducing operating current, therefore no changes where made regrading the CS-line
gertk 0:28557a4d2215 261 2006-10-02 added the 1541-III DTV splash screen (so you can see if the correct system is detected, even if you have no terminal attached, well you have to have a display offcourse.... But if you do... it would really nice)
gertk 0:28557a4d2215 262 made also the definition for the SX version of the 1541-III... why? Because that's what this projects started, so if I come to the point of building the 1541-III into my SX then it at least has an appropriate startupscreen.
gertk 0:28557a4d2215 263 2006-10-01 added the autodetect routines (detect which PCB where dealing with, 1541-III or 1541-III dtv). This makes distribution of new firmware versions much easier. Also it is much clearer to the outside world to understand that the 1541-III and the 1541-III DTV use the same firmware, how do you explain to a non-technical user that the 1541-III and the DTV version use the same software if you cannot use the same hex-file...
gertk 0:28557a4d2215 264 2006-09-13 when browsing through my 1541-II user's guide I found a different replcae command then I (assumed was correct) found in the "werken met de commodore disk drive" book (R0:<newname>=0:<oldname>). Changed it into the version the 1541-II manual describes (R0:<newname>=<oldname>)
gertk 0:28557a4d2215 265 the replace command functions very well regarding the highscore of Int. Karate, but for some reason Commando cannot read back the highscore svaed by the same routines, after loading highscore the program crashes
gertk 0:28557a4d2215 266 2006-09-12 REPLACE-command (combination of SCRATCH and SAVE), tested it and it works, commando does not work with it ?!?!? further testing required
gertk 0:28557a4d2215 267 2006-09-11 RENAME-command is functional
gertk 0:28557a4d2215 268 scratch command now includes the correct error handling, the error-code 1 shows the number of files scratched in the last track value
gertk 0:28557a4d2215 269 2006-09-10 scratch function nows also includes the use of wildcards (identical to file-loading wildcards)
gertk 0:28557a4d2215 270 also an harmless bug was found, 'the 16th char of each dir entry was not printed when the directory was loaded' (<15 should have been <16) FIXED
gertk 0:28557a4d2215 271 2006-09-05 fixed a small directory problem which made the first file invisible, this was OK but due to the introduction of the new routines a small thinking error was made.
gertk 0:28557a4d2215 272 2006-09-04 a small step further with write support
gertk 0:28557a4d2215 273 2006-09-03 spend all day searching for a bug that wasn't there. The 1541-III behaved strange after I modified my code heavily. It looked like a pointer problem, But no such problem was in my code. At the end it was clear, my 1541-II was switched off and caused erratic behaviour on the bus, resetting my 1541-III at the strangest moments
gertk 0:28557a4d2215 274 2006-09-02 added struct for each directory entry and changed the directory loading routines so that the use the new and simplified block read routines
gertk 0:28557a4d2215 275 also now all large buffers are defined in main.c (cause there is where you want to keep an overview of your resources
gertk 0:28557a4d2215 276 2006-08-31 moved all low level D64 acces routines to: D64_decoder.c
gertk 0:28557a4d2215 277 2006-08-30 created the BLOCK-WRITE routine, which is actually a very simple command, just dump some data to the D64 (only read the 512 block, change 256bytes then write back)
gertk 0:28557a4d2215 278 created the BLOCK-READ routine, which is even easier then BLOCK-WRITE
gertk 0:28557a4d2215 279 created the BLOCK-ALLOCATE routine,...
gertk 0:28557a4d2215 280 created the BLOCK-FREE routine,...
gertk 0:28557a4d2215 281 The actual command using the above routines still has to be written... (so much to do in so little time)
gertk 0:28557a4d2215 282 2006-08-28 added the testing function 'n:' this function tests the block write to card routine
gertk 0:28557a4d2215 283 so now we can format a d64 according to default settings, this only works for the smallest D64 files, other files will NOT be reset completely, thats why this command is for testing only!!!
gertk 0:28557a4d2215 284 2006-08-23 some cards had problems, it apears that these cards where not functioning according specs, read the whole story in the file:ata.c
gertk 0:28557a4d2215 285 improved filefilter routines and combined them into one single routine, this makes the software easier to maintain
gertk 0:28557a4d2215 286 simplified some areas of the code thanks to the Lcd_CharBold() function, saves a lot of putch(...)
gertk 0:28557a4d2215 287 2006-08-21 added more debugging info in order to find the problem regarding the problems with some card not being supported...
gertk 0:28557a4d2215 288 2006-08-17 improved contrast setting button response. The firmware version is now shown on the display when no card is inserted (was allready shown on the serial port at startup but normally this option is never used (only for firmware upgrades))
gertk 0:28557a4d2215 289 2006-08-16 the contrast settings are now stored in EEPROM, so you configure it only once and use it forever without the need of changing it again at every startup
gertk 0:28557a4d2215 290 2006-08-15 added subroutines to set the displays contrast, very important since there seems to be some slight difference between the old and new types of display
gertk 0:28557a4d2215 291 contrast can only be changed when no card is inserted !!!
gertk 0:28557a4d2215 292 2006-08-12 added PWM-output on RB3, this for future support of speaker (thinks of clicks on every track change, disk swap, buttonpress etc.) Now at power-up or reset it plays "halleluj.wav", as a small easter egg since nobody is informed about this feature.
gertk 0:28557a4d2215 293 2006-07-09 changed the read file statemachine, now the read is combined with write, since the command sequence is allmost identical
gertk 0:28557a4d2215 294 corrected the file-locked indicator (it was printed BEFORE the filetype while it should be printed AFTER... silly me)
gertk 0:28557a4d2215 295 track & sector values print to display routine were printed after loading of the block, it is better to print BEFORE loading cause this makes more sense
gertk 0:28557a4d2215 296 added an extra print track and sector routine to properly display the last track and sector of the loaded file
gertk 0:28557a4d2215 297 routine 'Count_files_on_card' only counted the D64 files but it should count ALL files, otherwise you can have an indexnumber higher then the 'number of files on card', that would look stupid!
gertk 0:28557a4d2215 298 removed stupid, stupid, stupid little BUG which prevented the second-last byte from being transferred during load, causing some files to fail after loading
gertk 0:28557a4d2215 299 2006-07-05 improved start-up behaviour, now the 1541-III does not 'hang-up' when accessed without card (basically removal of some busyloops
gertk 0:28557a4d2215 300 added textual message 'LOADING' to the loading related actions (SAVING, DELETING etc. is offcourse to be expected)
gertk 0:28557a4d2215 301 2006-07-04 changed release version number into release version data (thats easier to track changes in the history, you never know...)
gertk 0:28557a4d2215 302 2006-07-03 buttons, functions great, you cannot select a non D64 file
gertk 0:28557a4d2215 303 detection of card removal during operation
gertk 0:28557a4d2215 304 2006-07-02 added functional button selection, but it functions only once?!?!
gertk 0:28557a4d2215 305 added a simple retry mechanism in 'Init_Card_SPI'
gertk 0:28557a4d2215 306 2006-06-30 fixed silly bug in card detect & write protect detection routines
gertk 0:28557a4d2215 307 2006-06-27 changed the ADC registers to the correct 18F2620 ADC registers settings (the 18F2620 has not 2 but 3 regsiters)
gertk 0:28557a4d2215 308 2006-06-23 changed the device to 18F2620 (the prototype device was 18252 the 2620 can do MUCH more for allmost the same price)
gertk 0:28557a4d2215 309 removed the small demo-sequence
gertk 0:28557a4d2215 310 2006-05-20 hacked in a small demo-sequence for the next HCC-meeting in Maarsen, this for use on the "poormans 4K-pixel beamer"
gertk 0:28557a4d2215 311 2006-04-20 improvement in startup screen, now the splash screen stays partially visible exposing only the 1541-III logo (nice)
gertk 0:28557a4d2215 312 2006-04-12 implementation of the ATN under interrupt, this is required for future routine (like file selection using buttons) 2006-04-03 added splash screen at power-up
gertk 0:28557a4d2215 313 ATN under interrupt has the advantage that the computer is confirmed that the device is present while being busy with other things, now we do not have to leave every loop within 1mS or except 'device not present', it is all handled in the interrupt (hurray!!)
gertk 0:28557a4d2215 314 2006-04-02 added extra display functionality, like a progress bar (for loading and saving)
gertk 0:28557a4d2215 315 2006-03-31 2nd day of testing the nokia 3310 lcd, it works
gertk 0:28557a4d2215 316 2006-02-28 some modifications required for the new PCB design and some testing routines
gertk 0:28557a4d2215 317 2006-03-13 when the user tries to acces a directory that is not there, future actions will refer to the card.
gertk 0:28557a4d2215 318 2006-03-10 the file not found problem solved, I needed to release the bus, hurray. Attila, thanks for the information, really appreciate it
gertk 0:28557a4d2215 319 2006-02-22 added frame_handshake signal for later use (trying to solve the file not found situation)
gertk 0:28557a4d2215 320 2006-02-20 Loading of .PRG files is now possible, the search routine will check the filename up to the first 8 chars
gertk 0:28557a4d2215 321 Preparing INT0 for interrupt handling of the ATN-line
gertk 0:28557a4d2215 322 2006-02-19 Loading of .PRG files from the ROOT of the MMC/SD-card is now possible, still have the program the file search routine, it now only recognizes the * wildcard
gertk 0:28557a4d2215 323 2006-02-18 Today was the day of the big presentation at Commdore GG in Maarsen. Well.. it was not exactly a big presentation. But the interest for this project exceeded my wildest dreams. A giant motivation boost!!
gertk 0:28557a4d2215 324 preparing code for the loading of .PRG file from the root directory, this may be usefull for loading a special start-up program for exploring the MMC/SD-card or whatever (it's a 'future' user request)
gertk 0:28557a4d2215 325 2006-2-9/17 Nothing, code is stable now, do nothing untill the presentation at commodore GG has passed
gertk 0:28557a4d2215 326 2006-02-08 added a routine 'print_D64_TSB' to make sure that the same things (Track Sector Blocks) are printed in the same manor
gertk 0:28557a4d2215 327 added the DOT in the 8.3 filename representation in the 'card directory' routine, also added an extra space for better alligment
gertk 0:28557a4d2215 328 2006-02-07 added file selection directly (and only) after reset
gertk 0:28557a4d2215 329 also added a routine 'print_D64_name' to make sure the same things (filename) are printed in the same manor (the best way to achieve this is by a single routine)
gertk 0:28557a4d2215 330 2006-02-05 added LED blinking codes to the existing error messages
gertk 0:28557a4d2215 331 2006-02-04 added interrupt routines to realise the LED blinking (req. for the original LED blinking error indicators)
gertk 0:28557a4d2215 332 2006-02-03 implemented filter on filesize and extension, this means only D64 files are shown (command: LOAD"$0",DEVICE)
gertk 0:28557a4d2215 333 2006-02-02 improvements in code layout... i.o.w. making it more readable, fixed some FAT bugs, tremendous speed improvement !!!
gertk 0:28557a4d2215 334 Benchmark results: | filename | #blocks | 1541-II | 1541-III | Conclusion
gertk 0:28557a4d2215 335 --------------------+-------------------+---------+----------+----------+----------------
gertk 0:28557a4d2215 336 | Flimbo's Quest | 172 | 1:42 | 1:20 | (78% of the time req. by a real 1541, i.o.w. this drives operates at 127,5% of the speed of a real 1541)
gertk 0:28557a4d2215 337 | | | | |
gertk 0:28557a4d2215 338
gertk 0:28557a4d2215 339 2006-01-29 Removal of the redundant block_buffer and dat_buf registers, as a result of better 'fat' and 'ata' routines
gertk 0:28557a4d2215 340 2006-01-26 Loading of deleted files was possible, this is now fixed
gertk 0:28557a4d2215 341 2006-01-22 Adjusted the 'help' section in the $0 (card directory) for proper reading on a VC-20
gertk 0:28557a4d2215 342 2006-01-20 it appeared that the presence of a real 1541-II on the bus, creates the situation where some delays are not required. Make sure we test WITH AND WITHOUT other devices on the bus !!! A 100uS delay is required after det. of the first checkforcommand in our 'statemachine'
gertk 0:28557a4d2215 343 2006-01-19 removed unnecessary PRINTF's, added printf filename near LOADD64FILE
gertk 0:28557a4d2215 344 2006-01-19 fixed ValueFromString bug (didn't clear the variable, worked 1 time) fixed directory loading bug (it failed LOAD"$1",9 but not the rest)
gertk 0:28557a4d2215 345 2006-01-18 finished send-error-code routine (although Track and Sector are still hardcoded to 0
gertk 0:28557a4d2215 346 2006-01-16 still searching for problem of the previous day... found the problem was in the release of the bus, fixed in unlisten with FREEIEC routine.
gertk 0:28557a4d2215 347 2006-01-15 continued search for the 'loadin works only the first time' problem
gertk 0:28557a4d2215 348 2006-01-12 renamed some routines, rewritten part of the statemachine
gertk 0:28557a4d2215 349 2006-01-11 rewritten the main decoder loop (statemachine)
gertk 0:28557a4d2215 350 2006-01-10 TALK and LISTEN definitions were mixed up, is corrected improved the FreeIEC routine
gertk 0:28557a4d2215 351 2006-01-09 interference problem with other devices on the bus has been solved
gertk 0:28557a4d2215 352 2006-01-04 better command decoder
gertk 0:28557a4d2215 353 2006-01-02 begining of real/serious command decoder
gertk 0:28557a4d2215 354 2006-01-01 corrected small error in directory, now text allignment is correct
gertk 0:28557a4d2215 355 2005-12-24 implementation of the actual directory of an D64 emulator file
gertk 0:28557a4d2215 356 2005-12-22 fixed the directory, now we can load a dir into the C64
gertk 0:28557a4d2215 357 2005-12-18 testing of the IEC-write and TurnAround routines
gertk 0:28557a4d2215 358 2005-10/12 gathering data about the IEC-bus, build a logic ananlyser to monitor the IEC-bus activity of a real C64 and 1541-II
gertk 0:28557a4d2215 359 2005-09-20 raw design of fileselection routine
gertk 0:28557a4d2215 360 2005-09-21 design of ADC button decoder
gertk 0:28557a4d2215 361 2005-09-22 design of user interface
gertk 0:28557a4d2215 362 2005-09-26 figured out how to read the disks name from the correct track sector
gertk 0:28557a4d2215 363 2005-09-02 figured out how to decode the ImageDirectory, file by file, algoRITHM
gertk 0:28557a4d2215 364 2005-09-02 started with the free sectors routine
gertk 0:28557a4d2215 365 */
gertk 0:28557a4d2215 366
gertk 0:28557a4d2215 367 /* TO DO:
gertk 0:28557a4d2215 368 ------
gertk 0:28557a4d2215 369
gertk 0:28557a4d2215 370 for specific "to do" (pieces of missing code) use the following keyword (use search function of editor):
gertk 0:28557a4d2215 371 //to do:
gertk 0:28557a4d2215 372
gertk 0:28557a4d2215 373 -replace D64blockread functioncall(s) for D64blockread_new and discard the D64blockread, then rename the D64blockread_new to D64blockread
gertk 0:28557a4d2215 374 -replace D64blockwrite functioncall(s) for D64blockwrite_new and discard the D64blockwrite, then rename the D64blockwrite_new to D64blockwrite
gertk 0:28557a4d2215 375
gertk 0:28557a4d2215 376 - the index number can only display 999 entries, theorectically a 2GB card can store 11000 entries (spread over several directories and in 8.3 to save space)
gertk 0:28557a4d2215 377 so there are two options... leave out the index number or enlarge the indexnumber to 5 digits instead of 3
gertk 0:28557a4d2215 378
gertk 0:28557a4d2215 379 - controleren of er nog (andere) plekken zijn waar "extractfilenamefromstring" gebruikt kan worden
gertk 0:28557a4d2215 380 - controleren of er nog op plaatsen gebruik word gemaakt van IEC_undoturnaround, dit zou IEC_letgo moeten zijn simpelweg omdat undo_turnaround niet gedefinieerd is in de IEC specs
gertk 0:28557a4d2215 381
gertk 0:28557a4d2215 382 - hoe zit het met de 1541-III dtv in de versie met de tri-color LED, zit daar ook een condensator aan de ingang om te detetcteren dat het een andere versie is?
gertk 0:28557a4d2215 383
gertk 0:28557a4d2215 384 - loading of a directory without typeing LOAD"$",8 (zie de boeken voor voorbeeld programma's)
gertk 0:28557a4d2215 385 - block read and write... B-W en B-R, deze zijn nu nog voor de 256byte maar moeten uiteraard voor de 254 byte versie zijn, de 1e twee bytes overslaan !?!?
gertk 0:28557a4d2215 386
gertk 0:28557a4d2215 387 - the 1541-III fails to function in combination with a C128
gertk 0:28557a4d2215 388
gertk 0:28557a4d2215 389 - the routine "void SendErrorMessage(void)" is designed to transmit ALL 4 values(byte,byte,string,byte) of the error message, but what if a user request only the first(byte), how is this handled by a real 1541?
gertk 0:28557a4d2215 390 check for EOI bij elke stap
gertk 0:28557a4d2215 391
gertk 0:28557a4d2215 392 - Make note in manual about unrecognised characters (see bugfix of 2006-11-03)
gertk 0:28557a4d2215 393
gertk 0:28557a4d2215 394 - support for eror-bytes in extended 35- and 40-track .D64 files
gertk 0:28557a4d2215 395 */
gertk 0:28557a4d2215 396
gertk 0:28557a4d2215 397 /* Notes to myself:
gertk 0:28557a4d2215 398 ----------------
gertk 0:28557a4d2215 399 -C128 problem NOT 1541-III: CAN'T LOAD OUTRUN.PRG ANY MORE IF LOADED CBM CRASHES!!! THE ABOVE IS CAUSED SIMPLY BECAUSE THIS FILE FAILS TO FUNCTION ON MY C128 ON WHICH I TEST MOSTLY. IT FUNCTIONS PERFECTLY ON MY C64
gertk 0:28557a4d2215 400
gertk 0:28557a4d2215 401 -when teh C64 screen is "blanked" it should be possible to adjust the timings from 60uS to 20uS, since the VIC is not interfering (or doesn't it work like this)
gertk 0:28557a4d2215 402
gertk 0:28557a4d2215 403 */
gertk 0:28557a4d2215 404
gertk 0:28557a4d2215 405 /*----------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 406
gertk 0:28557a4d2215 407 // example of sd card access
gertk 0:28557a4d2215 408 #include "mbed.h"
gertk 0:28557a4d2215 409 // #include "string"
gertk 0:28557a4d2215 410 // #include "SDHCFileSystem.h"
gertk 0:28557a4d2215 411 //
gertk 0:28557a4d2215 412 // SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs
gertk 0:28557a4d2215 413 //
gertk 0:28557a4d2215 414 // int main() {
gertk 0:28557a4d2215 415 //
gertk 0:28557a4d2215 416 // FILE *fp = fopen("/sd/myfile.txt", "w");
gertk 0:28557a4d2215 417 // fprintf(fp, "\n\rHello World!\n\r");
gertk 0:28557a4d2215 418 // fclose(fp);
gertk 0:28557a4d2215 419 // }
gertk 0:28557a4d2215 420 // IEC hardware connections
gertk 0:28557a4d2215 421 DigitalInOut nSRQ(p18); // DIN6 pin 1
gertk 0:28557a4d2215 422 DigitalInOut nATN(p17); // DIN6 pin 3
gertk 0:28557a4d2215 423 DigitalInOut nCLK(p16); // DIN6 pin 4
gertk 0:28557a4d2215 424 DigitalInOut nDATA(p15); // DIN6 pin 5
gertk 0:28557a4d2215 425 DigitalInOut nRESET(p19); // DIN6 pin 6
gertk 0:28557a4d2215 426
gertk 0:28557a4d2215 427 InterruptIn nIRQ(p30); // external loop: connect to nATN
gertk 0:28557a4d2215 428
gertk 0:28557a4d2215 429 DigitalIn JUMPER_J2(p21);
gertk 0:28557a4d2215 430 DigitalIn JUMPER_J3(p22);
gertk 0:28557a4d2215 431
gertk 0:28557a4d2215 432 DigitalOut myled1(LED1);
gertk 0:28557a4d2215 433 DigitalOut myled2(LED2);
gertk 0:28557a4d2215 434 DigitalOut myled3(LED3);
gertk 0:28557a4d2215 435 DigitalOut myled4(LED4);
gertk 0:28557a4d2215 436
gertk 0:28557a4d2215 437 #define LED_GREEN myled1
gertk 0:28557a4d2215 438 #define LED_RED myled2
gertk 0:28557a4d2215 439
gertk 0:28557a4d2215 440 Timer timeout;
gertk 0:28557a4d2215 441 Serial linktopc(USBTX,USBRX);
gertk 0:28557a4d2215 442
gertk 0:28557a4d2215 443 // #define IEC_ATN_REL() IEC_DDR &= ~IEC_BIT_ATN
gertk 0:28557a4d2215 444 void IEC_ATN_REL() {
gertk 0:28557a4d2215 445 nATN=1;
gertk 0:28557a4d2215 446 nATN.input();
gertk 0:28557a4d2215 447 }
gertk 0:28557a4d2215 448
gertk 0:28557a4d2215 449 // #define IEC_ATN_PULL() IEC_DDR |= IEC_BIT_ATN
gertk 0:28557a4d2215 450 void IEC_ATN_PULL() {
gertk 0:28557a4d2215 451 nATN.output();
gertk 0:28557a4d2215 452 nATN=0;
gertk 0:28557a4d2215 453 }
gertk 0:28557a4d2215 454
gertk 0:28557a4d2215 455 // #define IEC_CLOCK_REL() IEC_DDR &= ~IEC_BIT_CLOCK
gertk 0:28557a4d2215 456 void IEC_CLOCK_REL() {
gertk 0:28557a4d2215 457 nCLK=1;
gertk 0:28557a4d2215 458 nCLK.input();
gertk 0:28557a4d2215 459 }
gertk 0:28557a4d2215 460
gertk 0:28557a4d2215 461 // #define IEC_CLOCK_PULL() IEC_DDR |= IEC_BIT_CLOCK
gertk 0:28557a4d2215 462 void IEC_CLOCK_PULL() {
gertk 0:28557a4d2215 463 nCLK.output();
gertk 0:28557a4d2215 464 nCLK=0;
gertk 0:28557a4d2215 465 }
gertk 0:28557a4d2215 466
gertk 0:28557a4d2215 467 // #define IEC_DATA_REL() IEC_DDR &= ~IEC_BIT_DATA
gertk 0:28557a4d2215 468 void IEC_DATA_REL() {
gertk 0:28557a4d2215 469 nDATA=1;
gertk 0:28557a4d2215 470 nDATA.input();
gertk 0:28557a4d2215 471 }
gertk 0:28557a4d2215 472
gertk 0:28557a4d2215 473 // #define IEC_DATA_PULL() IEC_DDR |= IEC_BIT_DATA
gertk 0:28557a4d2215 474 void IEC_DATA_PULL() {
gertk 0:28557a4d2215 475 nDATA.output();
gertk 0:28557a4d2215 476 nDATA=0;
gertk 0:28557a4d2215 477 }
gertk 0:28557a4d2215 478
gertk 0:28557a4d2215 479 int IEC_ATN() {
gertk 0:28557a4d2215 480 nATN.input();
gertk 0:28557a4d2215 481 return nATN;
gertk 0:28557a4d2215 482 }
gertk 0:28557a4d2215 483
gertk 0:28557a4d2215 484 int IEC_CLOCK() {
gertk 0:28557a4d2215 485 nCLK.input();
gertk 0:28557a4d2215 486 return nCLK;
gertk 0:28557a4d2215 487 }
gertk 0:28557a4d2215 488
gertk 0:28557a4d2215 489 int IEC_DATA() {
gertk 0:28557a4d2215 490 nDATA.input();
gertk 0:28557a4d2215 491 return nDATA;
gertk 0:28557a4d2215 492 }
gertk 0:28557a4d2215 493
gertk 0:28557a4d2215 494
gertk 0:28557a4d2215 495
gertk 0:28557a4d2215 496 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 497 /* includes */
gertk 0:28557a4d2215 498 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 499 #include <mbed.h>
gertk 0:28557a4d2215 500
gertk 0:28557a4d2215 501 // #include <stdio.h>
gertk 0:28557a4d2215 502 // #include <stdlib.h>
gertk 0:28557a4d2215 503 // #include <string.h>
gertk 0:28557a4d2215 504 // #include <math.h>
gertk 0:28557a4d2215 505 #include <main.h>
gertk 0:28557a4d2215 506 #include <hardware.h>
gertk 0:28557a4d2215 507 #include <delay.h>
gertk 0:28557a4d2215 508 #include <ata.h>
gertk 0:28557a4d2215 509 #include <fat.h>
gertk 0:28557a4d2215 510 #include <D64_decoder.h>
gertk 0:28557a4d2215 511 #include <T64_decoder.h>
gertk 0:28557a4d2215 512 #include <IEC_bus.h>
gertk 0:28557a4d2215 513
gertk 0:28557a4d2215 514 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 515 /* EEPROM */
gertk 0:28557a4d2215 516 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 517 /*
gertk 0:28557a4d2215 518 __EEPROM_DATA('-','-','-','-','-','-','-','-');
gertk 0:28557a4d2215 519 __EEPROM_DATA('-','-','-','-','-','-','-','-');
gertk 0:28557a4d2215 520 __EEPROM_DATA('-','-','-','-','-','-','-','-');
gertk 0:28557a4d2215 521 __EEPROM_DATA('-','-','-','-','-','-','-','-');
gertk 0:28557a4d2215 522 __EEPROM_DATA('-','-','-','-','-','-','-','-');
gertk 0:28557a4d2215 523 */
gertk 0:28557a4d2215 524 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 525
gertk 0:28557a4d2215 526 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 527 /* constants */
gertk 0:28557a4d2215 528 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 529
gertk 0:28557a4d2215 530 #define FALSE 0 /*FALSE*/
gertk 0:28557a4d2215 531 #define TRUE 1 /*TRUE*/
gertk 0:28557a4d2215 532
gertk 0:28557a4d2215 533 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 534
gertk 0:28557a4d2215 535 /*PCB types and versions*/
gertk 0:28557a4d2215 536 enum PCBTYPE{v1=10, v1_1, DTV, DTV_C64};
gertk 0:28557a4d2215 537
gertk 0:28557a4d2215 538 /*defines for the IEC-bus statemachine*/
gertk 0:28557a4d2215 539 enum IEC_bus_statemachine{IDLE=0, ACTIVE_LISTEN, ACTIVE_TALK};
gertk 0:28557a4d2215 540
gertk 0:28557a4d2215 541 /*blink modes*/
gertk 0:28557a4d2215 542 enum LED_modes{LED_OFF=0, LED_ON, LED_ERROR, LED_GR, LED_RD, LED_OR};
gertk 0:28557a4d2215 543
gertk 0:28557a4d2215 544 /*disk-state*/
gertk 0:28557a4d2215 545 enum DiskState{NO_CARD=0, CARD_ACTIVE, INVALID_POINTER};
gertk 0:28557a4d2215 546
gertk 0:28557a4d2215 547 /*1541-III commands*/
gertk 0:28557a4d2215 548 enum Commandset{ABORT=0, ABORT_SENDING, ABORT_RECEIVING, NO_FILE, FILE_OPEN, NEW_D64, CARD_DIRECTORY, DIRECTORY, RD_FILE, RD_FILE_FROM_ROOT, WR_FILE, WR_FILE_TO_ROOT, REPLACE_FILE, SCRATCH_FILE, RENAME_FILE, COPY_FILE, SET_DEVICEADDR, USER_IEC_SPD_UP, USER_IEC_SPD_DWN, MODIFY_FILE, MODIFY_FILE_TO_ROOT};
gertk 0:28557a4d2215 549
gertk 0:28557a4d2215 550 /*filetypes*/
gertk 0:28557a4d2215 551 enum Filetypes{SEQUENTIAL=1, RELATIVE, PROGRAM, USER, LENGTH};
gertk 0:28557a4d2215 552
gertk 0:28557a4d2215 553 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 554
gertk 0:28557a4d2215 555 #define BUTTON_SELECTION_RATE 350 /*this value determines the button repetition rate*/
gertk 0:28557a4d2215 556
gertk 0:28557a4d2215 557 /*MMC/SD-card*/
gertk 0:28557a4d2215 558 #define MMCCARD 2 /*card type found reference*/
gertk 0:28557a4d2215 559 #define SDCARD 3 /*card type found reference*/
gertk 0:28557a4d2215 560 #define FILENOTFOUND 4 /*filenotfound reference*/
gertk 0:28557a4d2215 561 #define SUPPVOLT 0x3C /*mask and compare value for cards that support 3.0-3.1, 3.1-3.2, 3.2-3.3, 3.3-3.4 Volt*/
gertk 0:28557a4d2215 562
gertk 0:28557a4d2215 563 /*buttons*/
gertk 0:28557a4d2215 564 #define button_none 0 /*numerical value of ADC when no button is pressed*/
gertk 0:28557a4d2215 565 #define button_tolerance 15 /*max. alowable deviation of expected button values*/
gertk 0:28557a4d2215 566 #define button_1 870 /*numerical value of ADC when button-1 is pressed*/
gertk 0:28557a4d2215 567 #define button_2 721 /*numerical value of ADC when button-2 is pressed*/
gertk 0:28557a4d2215 568 #define button_3 575 /*numerical value of ADC when button-3 is pressed*/
gertk 0:28557a4d2215 569 #define button_4 431 /*numerical value of ADC when button-4 is pressed*/
gertk 0:28557a4d2215 570 #define button_5 288 /*numerical value of ADC when button-5 is pressed*/
gertk 0:28557a4d2215 571 #define button_6 145 /*numerical value of ADC when button-6 is pressed*/
gertk 0:28557a4d2215 572
gertk 0:28557a4d2215 573 /*1541-III operational modes/filefilter results*/
gertk 0:28557a4d2215 574 #define NONE 0 /*the 1541-III has currently no file selected. I.o.w. the 1541-III works in the root directory and can load files directly from the card*/
gertk 0:28557a4d2215 575 #define PRG_FILE 1
gertk 0:28557a4d2215 576 #define D64_35T_MODE 2 /*the 1541-III has opened a .D64 file (35 tracks no errors) and works as of your working with a real 1541 disk drive*/
gertk 0:28557a4d2215 577 #define D64_35T_ER_MODE 3 /*the 1541-III has opened a .D64 file (35 tracks with errors) and works as of your working with a real 1541 disk drive*/
gertk 0:28557a4d2215 578 #define D64_40T_MODE 4 /*the 1541-III has opened a .D64 file (40 tracks no errors) and works as of your working with a real 1541 disk drive*/
gertk 0:28557a4d2215 579 #define D64_40T_ER_MODE 5 /*the 1541-III has opened a .D64 file (40 tracks with errors) and works as of your working with a real 1541 disk drive*/
gertk 0:28557a4d2215 580 #define T64_MODE 6 /*the 1541-III has opened a .T64 file*/
gertk 0:28557a4d2215 581 #define SUBDIRECTORY 100 /*the 1541-III has encountered a subdirectory*/
gertk 0:28557a4d2215 582 #define UNKNOWN 255 /*the 1541-III has encountered a file that has no extension*/
gertk 0:28557a4d2215 583
gertk 0:28557a4d2215 584 #define FILE_NOT_PRESENT 0
gertk 0:28557a4d2215 585 #define FILE_PRESENT 1
gertk 0:28557a4d2215 586
gertk 0:28557a4d2215 587 /*text printing definitions*/
gertk 0:28557a4d2215 588 #define PLAIN 0
gertk 0:28557a4d2215 589 #define BOLD 1
gertk 0:28557a4d2215 590 #define INVERTED 2
gertk 0:28557a4d2215 591
gertk 0:28557a4d2215 592 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 593 /* macro's */
gertk 0:28557a4d2215 594 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 595 #define disable() GIE=0 /*disable interrupts*/
gertk 0:28557a4d2215 596 #define enable() GIE=1 /*enable interrupts*/
gertk 0:28557a4d2215 597
gertk 0:28557a4d2215 598 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 599 /* globals */
gertk 0:28557a4d2215 600 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 601
gertk 0:28557a4d2215 602 unsigned char RAM_buffer[256]; /*this is the buffer capable of holding one 256 byte block, a memory area to which the user or the 1541-III can write/read data to/from*/
gertk 0:28557a4d2215 603 //unsigned char BAM_buffer[162]; /*this buffer holds the Block Allocation Map, required for when we want to write to the D64 (max 40 tracks)*/
gertk 0:28557a4d2215 604 unsigned char block_buffer[512]; /*this buffers the data 'as read from' or 'to be written to' the card*/
gertk 0:28557a4d2215 605 struct DOS_buffer_struct DOS_buffer[MAX_NUMBER_OF_DOS_BUFFERS]; /*this array of structs holds the information about the possible channels*/
gertk 0:28557a4d2215 606 struct DOS_channel_struct DOS_channel[16]; /*this array of structs holds this information about the currently used channels*/
gertk 0:28557a4d2215 607
gertk 0:28557a4d2215 608 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 609 unsigned char PCB_type; /*this value contains the PCB type/version*/
gertk 0:28557a4d2215 610 unsigned int PCB_type_timer; /*this timer determines the actual PCB type detection*/
gertk 0:28557a4d2215 611 unsigned char setting_contrast; /*this is the value belonging to the contrast setting as found in EEPROM*/
gertk 0:28557a4d2215 612 unsigned char VIC20_mode; /*this is the value belonging to the IEC-speed setting as found in EEPROM*/
gertk 0:28557a4d2215 613
gertk 0:28557a4d2215 614 unsigned char devicenumber; /*this var. holds the device number 8,9,10 or 11*/
gertk 0:28557a4d2215 615 unsigned char device_command;
gertk 0:28557a4d2215 616
gertk 0:28557a4d2215 617 unsigned char IEC_state; /*talk, listen or idle*/
gertk 0:28557a4d2215 618 unsigned char channel; /*this register holds the channel value*/
gertk 0:28557a4d2215 619 unsigned char nextfreebuffer; /*this register holds the buffernumber of the next buffer to be used*/
gertk 0:28557a4d2215 620 unsigned char ChannelUsesBuffer[16]; /*small array to keep track of which channel uses what buffer (to drive you mad... MAD I SAY!$#%$#%$#$%#)*/
gertk 0:28557a4d2215 621 unsigned char command; /*this is the unfiltered (as received for the IEC-bus) command*/
gertk 0:28557a4d2215 622 unsigned char command_string[41]; /*this string holds the command details/options*/
gertk 0:28557a4d2215 623 unsigned char filename_string[41]; /*this string (is suppost to) hold(s) the filename*/
gertk 0:28557a4d2215 624 unsigned char oldfilename_string[41]; /*this string (is suppost to) hold(s) the new filename (for renaming routines)*/
gertk 0:28557a4d2215 625 unsigned char value_string[17]; /*this string (is suppost to) hold(s) a value*/
gertk 0:28557a4d2215 626 unsigned char string_pntr;
gertk 0:28557a4d2215 627 unsigned char string_pntr_2;
gertk 0:28557a4d2215 628 unsigned long value_long;
gertk 0:28557a4d2215 629 unsigned char value_1;
gertk 0:28557a4d2215 630 unsigned char value_2;
gertk 0:28557a4d2215 631 unsigned char value_3;
gertk 0:28557a4d2215 632 unsigned char value_4;
gertk 0:28557a4d2215 633 unsigned char filetype_string[41]; /*filetype can be sequential, program, user, etc.*/
gertk 0:28557a4d2215 634 unsigned char RW_string[41]; /*file read or write*/
gertk 0:28557a4d2215 635
gertk 0:28557a4d2215 636 unsigned char error_code = 73; /*this holds the error-message generated by one of the disk routines*/
gertk 0:28557a4d2215 637 unsigned char LastTrack = 0; /*last accessed track variable*/
gertk 0:28557a4d2215 638 unsigned char LastSector = 0; /*last accessed sector variable*/
gertk 0:28557a4d2215 639 unsigned char files_scratched = 0; /**/
gertk 0:28557a4d2215 640
gertk 0:28557a4d2215 641 unsigned char Response_data[5];
gertk 0:28557a4d2215 642
gertk 0:28557a4d2215 643 unsigned char file_type; /*this holds the type of the current file or NONE if no file is selected*/
gertk 0:28557a4d2215 644 unsigned int file_number; /*the current file index number, this number is used as a reference for button actions*/
gertk 0:28557a4d2215 645 unsigned int CountedFiles; /*the number of files in the current (root/sub)-directory*/
gertk 0:28557a4d2215 646
gertk 0:28557a4d2215 647 struct file2TYPE file; /*file handle*/
gertk 0:28557a4d2215 648 struct directory_entry dir_entry; /*directory structure inside the D64*/
gertk 0:28557a4d2215 649
gertk 0:28557a4d2215 650 bit button_prev;
gertk 0:28557a4d2215 651 bit button_select;
gertk 0:28557a4d2215 652 bit button_next;
gertk 0:28557a4d2215 653
gertk 0:28557a4d2215 654 unsigned char Blink_mode; /*mode of operation of the blink routine*/
gertk 0:28557a4d2215 655 bit Blink_dir; /*direction of intensity change (up or down)*/
gertk 0:28557a4d2215 656 unsigned char Blink_block; /*holds the byte-number on which the LED should go off in order to create a blink at every block*/
gertk 0:28557a4d2215 657 unsigned char LED_OFF_delay; /*holds the delay timing value for the LED-OFF time*/
gertk 0:28557a4d2215 658 bit LED_status; /*the current state of the LED is stored here*/
gertk 0:28557a4d2215 659 unsigned char LED_color; /*value to keep track of current LED-color*/
gertk 0:28557a4d2215 660 unsigned char next_LED_color; /*value to keep track of current LED-color*/
gertk 0:28557a4d2215 661 unsigned char DiskState; /*state of the disk (image) inside the drive (1541-III)*/
gertk 0:28557a4d2215 662
gertk 0:28557a4d2215 663 bit EOI; /*End Of Indicator: this flag (when TRUE) indicates that the last byte is being transmitted or received*/
gertk 0:28557a4d2215 664 bit TimeOut; /*Timeout-flag*/
gertk 0:28557a4d2215 665
gertk 0:28557a4d2215 666 unsigned char dirtrack, dirsector, direntry;
gertk 0:28557a4d2215 667 unsigned long lp, lp2;
gertk 0:28557a4d2215 668 unsigned int blocksize;
gertk 0:28557a4d2215 669 unsigned char track, sector;
gertk 0:28557a4d2215 670 unsigned char file_status;
gertk 0:28557a4d2215 671
gertk 0:28557a4d2215 672 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 673 /* local functions */
gertk 0:28557a4d2215 674 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 675 void WaitForString(unsigned char *outputstring, unsigned frame_handshake);
gertk 0:28557a4d2215 676 unsigned char ValueFromString(unsigned char *inputstring, unsigned char *outputvalue);
gertk 0:28557a4d2215 677 unsigned char LongValueFromString(unsigned char *inputstring, unsigned long *outputvalue);
gertk 0:28557a4d2215 678 void ExtractFilenameFromString(unsigned char *input_string, unsigned char *output_string);
gertk 0:28557a4d2215 679 unsigned char SplitStringOn_Sign(unsigned char sign, unsigned char *beforesign_string, unsigned char *aftersign_string);
gertk 0:28557a4d2215 680
gertk 0:28557a4d2215 681 void IEC_direction_statemachine(void);
gertk 0:28557a4d2215 682 void OpenHandler(void);
gertk 0:28557a4d2215 683 void DataHandler(void);
gertk 0:28557a4d2215 684 void AutoDetectPcbType(void);
gertk 0:28557a4d2215 685 void NoCardMenu(void);
gertk 0:28557a4d2215 686 void HardWareTestMenu(void);
gertk 0:28557a4d2215 687 unsigned char CardStatus(void);
gertk 0:28557a4d2215 688 void CountFiles(void);
gertk 0:28557a4d2215 689 unsigned char Init_Card_SPI(void);
gertk 0:28557a4d2215 690 unsigned char FileFilter(void);
gertk 0:28557a4d2215 691
gertk 0:28557a4d2215 692 unsigned char SearchFreeBuffer(void);
gertk 0:28557a4d2215 693
gertk 0:28557a4d2215 694 void Clear_block_buffer(void);
gertk 0:28557a4d2215 695 void SelectD64Image(void);
gertk 0:28557a4d2215 696 void CardDirectory(void);
gertk 0:28557a4d2215 697 void D64Directory(void);
gertk 0:28557a4d2215 698 void T64Directory(void);
gertk 0:28557a4d2215 699 unsigned int SeekFileOnCard(unsigned char *filename, struct file2TYPE *file);
gertk 0:28557a4d2215 700 void LoadFileFromCard(struct file2TYPE *file);
gertk 0:28557a4d2215 701 void LoadD64File(unsigned char trk, unsigned char sec, unsigned int filesizeinblocks);
gertk 0:28557a4d2215 702 unsigned char SaveD64File(void);
gertk 0:28557a4d2215 703 unsigned char CopyD64File(unsigned char trk, unsigned char sec, unsigned int filesizeinblocks);
gertk 0:28557a4d2215 704
gertk 0:28557a4d2215 705 void SetErrorCode(unsigned char error, unsigned char LEDmode);
gertk 0:28557a4d2215 706 void SendErrorMessage(void);
gertk 0:28557a4d2215 707
gertk 0:28557a4d2215 708 void print_device_status(const unsigned char *message);
gertk 0:28557a4d2215 709 void print_D64_name(unsigned char mode);
gertk 0:28557a4d2215 710 void print_D64_TSB(unsigned char trk, unsigned char sec, unsigned int blk, unsigned int total_blk);
gertk 0:28557a4d2215 711
gertk 0:28557a4d2215 712 unsigned char ReadDeviceJumper(void);
gertk 0:28557a4d2215 713 unsigned char ReadButtons(void);
gertk 0:28557a4d2215 714
gertk 0:28557a4d2215 715 void FormatD64File(unsigned char *diskname, unsigned char *diskid);
gertk 0:28557a4d2215 716 /*****************************************************************************************************************/
gertk 0:28557a4d2215 717 /*****************************************************************************************************************/
gertk 0:28557a4d2215 718 /*****************************************************************************************************************/
gertk 0:28557a4d2215 719 /*Interrupt service routines*/
gertk 0:28557a4d2215 720 /*****************************************************************************************************************/
gertk 0:28557a4d2215 721 /*****************************************************************************************************************/
gertk 0:28557a4d2215 722 /*Low-priority interrupt entry point*/
gertk 0:28557a4d2215 723 void NotTimeCritical(void)
gertk 0:28557a4d2215 724 {
gertk 0:28557a4d2215 725
gertk 0:28557a4d2215 726 }
gertk 0:28557a4d2215 727
gertk 0:28557a4d2215 728 /*High-priority interrupt entry point*/
gertk 0:28557a4d2215 729 void high_priority(void)
gertk 0:28557a4d2215 730 {
gertk 0:28557a4d2215 731 unsigned char filter_cnt;
gertk 0:28557a4d2215 732 /*By putting the ATN-line detection on an interrupt-line we detect the ATN-situation independent of*/
gertk 0:28557a4d2215 733 /*other actions, like selecting a new D64 image. This method makes IEC programming less complex*/
gertk 0:28557a4d2215 734 /*the small filter also creates a hold-off time, for some reason this is required*/
gertk 0:28557a4d2215 735 filter_cnt = 25; /*check the ATN line it must be kept low for a few cycles at least otherwise it might have been a glitch*/
gertk 0:28557a4d2215 736 while(IEC_ATN() == 0) /*although this filter does add some latency to the start of a data transfer, it is not noticeable in practice*/
gertk 0:28557a4d2215 737 {
gertk 0:28557a4d2215 738 /*it does however add a more secure ATN-line detection, since the inputlines are not filtered in any other way*/
gertk 0:28557a4d2215 739 wait_us(1);
gertk 0:28557a4d2215 740 filter_cnt--;
gertk 0:28557a4d2215 741 if (filter_cnt == 0) /*when the ATN signal has been proven not to be a glitch*/
gertk 0:28557a4d2215 742 { /*we can safely handle the ATN-signal*/
gertk 0:28557a4d2215 743 IEC_DATA_PULL();/*join the bus...*/
gertk 0:28557a4d2215 744 myled3=1;
gertk 0:28557a4d2215 745
gertk 0:28557a4d2215 746 break;
gertk 0:28557a4d2215 747 }
gertk 0:28557a4d2215 748 }
gertk 0:28557a4d2215 749 }
gertk 0:28557a4d2215 750
gertk 0:28557a4d2215 751 /*macro*/
gertk 0:28557a4d2215 752 // #define disable_ATN_interrupt() INT0IE = 0 /*disable interrupts on ATN line*/
gertk 0:28557a4d2215 753 // #define enable_ATN_interrupt() INT0IE = 1 /*enable interrupts on ATN line*/
gertk 0:28557a4d2215 754
gertk 0:28557a4d2215 755 void enable_ATN_interrupt(){
gertk 0:28557a4d2215 756 nIRQ.fall(&high_priority);
gertk 0:28557a4d2215 757 }
gertk 0:28557a4d2215 758
gertk 0:28557a4d2215 759 void disable_ATN_interrupt(){
gertk 0:28557a4d2215 760 nIRQ.fall(NULL);
gertk 0:28557a4d2215 761 }
gertk 0:28557a4d2215 762 /*****************************************************************************************************************/
gertk 0:28557a4d2215 763 /*****************************************************************************************************************/
gertk 0:28557a4d2215 764 /*Main*/
gertk 0:28557a4d2215 765 /*****************************************************************************************************************/
gertk 0:28557a4d2215 766 /*****************************************************************************************************************/
gertk 0:28557a4d2215 767
gertk 0:28557a4d2215 768 int main(void)
gertk 0:28557a4d2215 769 {
gertk 0:28557a4d2215 770
gertk 0:28557a4d2215 771 HardwareInit(); /*init controller registers and I/O-lines*/
gertk 0:28557a4d2215 772 // GetSettingsFromEEPROM(); /*read EEPROM settings*/
gertk 0:28557a4d2215 773 devicenumber = ReadDeviceJumper(); /*read the devicenumber jumper*/
gertk 0:28557a4d2215 774 InitIEC(); /*initialize the IEC-bus levels*/
gertk 0:28557a4d2215 775 /*initialize SPI*/
gertk 0:28557a4d2215 776
gertk 0:28557a4d2215 777
gertk 0:28557a4d2215 778 linktopc.baud(115200);
gertk 0:28557a4d2215 779
gertk 0:28557a4d2215 780 timeout.start(); // start timer
gertk 0:28557a4d2215 781
gertk 0:28557a4d2215 782 // InitLcd(); /*initialize the LCD*/
gertk 0:28557a4d2215 783 AutoDetectPcbType(); /*measure the button capacitor to determine PCB type*/
gertk 0:28557a4d2215 784 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 785 printf("\r\n -----------------------------------------");
gertk 0:28557a4d2215 786 printf("\r\n | |");
gertk 0:28557a4d2215 787 printf("\r\n | |");
gertk 0:28557a4d2215 788 printf("\r\n | --== 1541 - III ==-- |");
gertk 0:28557a4d2215 789 printf("\r\n | (by J.Derogee) |");
gertk 0:28557a4d2215 790 printf("\r\n | (http://jderogee.tripod.com) |");
gertk 0:28557a4d2215 791 printf("\r\n | |");
gertk 0:28557a4d2215 792 printf("\r\n | |");
gertk 0:28557a4d2215 793 printf("\r\n | |");
gertk 0:28557a4d2215 794 printf("\r\n | |");
gertk 0:28557a4d2215 795 printf("\r\n | |");
gertk 0:28557a4d2215 796 printf("\r\n | |");
gertk 0:28557a4d2215 797 printf("\r\n | |");
gertk 0:28557a4d2215 798 printf("\r\n | |");
gertk 0:28557a4d2215 799 printf("\r\n | |");
gertk 0:28557a4d2215 800 printf("\r\n | |");
gertk 0:28557a4d2215 801 printf("\r\n | -------------------------------- |");
gertk 0:28557a4d2215 802 printf("\r\n | ( ) |Firmware vers.: v20%02d-%02d-%02d | |",RELEASE_VERSION,RELEASE_VERSION_SUB,RELEASE_VERSION_SUB_SUB);
gertk 0:28557a4d2215 803 printf("\r\n | |J2 (Device-ID): ID=%1d | |",devicenumber);
gertk 0:28557a4d2215 804 printf("\r\n | |J3 (Bootldr) : ");
gertk 0:28557a4d2215 805 if (JUMPER_J3 == 0)
gertk 0:28557a4d2215 806 printf("ACTIVE | |");
gertk 0:28557a4d2215 807 else
gertk 0:28557a4d2215 808 printf("DISABLED | |");
gertk 0:28557a4d2215 809
gertk 0:28557a4d2215 810 printf("\r\n | ( ) |Contrast : 0x%02x | |",setting_contrast); /*show the settings*/
gertk 0:28557a4d2215 811 printf("\r\n | |VIC20-mode : ");
gertk 0:28557a4d2215 812 if (VIC20_mode == TRUE)
gertk 0:28557a4d2215 813 printf("TRUE | |");
gertk 0:28557a4d2215 814 else
gertk 0:28557a4d2215 815 printf("FALSE | |");
gertk 0:28557a4d2215 816
gertk 0:28557a4d2215 817 printf("\r\n | |PCB type det. : %05d | |",PCB_type_timer); /*check which kind of PCb we are dealing with...*/
gertk 0:28557a4d2215 818
gertk 0:28557a4d2215 819 /*adjust the startup sequence accordingly and settings depending on the PCB version*/
gertk 0:28557a4d2215 820 if (PCB_type == v1)
gertk 0:28557a4d2215 821 {
gertk 0:28557a4d2215 822 printf("\r\n | ( ) |Detected PCB : 1541-III v1.0 | |");
gertk 0:28557a4d2215 823 // Lcd_show_1541_III(); /*show splash screen*/
gertk 0:28557a4d2215 824 SetIEC_timings(TIMINGS_DEFAULT); /*set timings to default*/
gertk 0:28557a4d2215 825 Blink_block = 235; /*i.e. set the value to 225 to get a short off-time (it count to 254 and then goes on again), set value to 255 and it never blinks*/
gertk 0:28557a4d2215 826 }
gertk 0:28557a4d2215 827
gertk 0:28557a4d2215 828 if (PCB_type == v1_1)
gertk 0:28557a4d2215 829 {
gertk 0:28557a4d2215 830 printf("\r\n | ( ) |Detected PCB : 1541-III v1.1 | |");
gertk 0:28557a4d2215 831 // Lcd_show_1541_III(); /*show splash screen*/
gertk 0:28557a4d2215 832 SetIEC_timings(TIMINGS_DEFAULT); /*set timings to default*/
gertk 0:28557a4d2215 833 Blink_block = 235; /*i.e. set the value to 225 to get a short off-time (it count to 254 and then goes on again), set value to 255 and it never blinks*/
gertk 0:28557a4d2215 834 }
gertk 0:28557a4d2215 835
gertk 0:28557a4d2215 836 if (PCB_type == DTV)
gertk 0:28557a4d2215 837 {
gertk 0:28557a4d2215 838 printf("\r\n | ( ) |Detected PCB : 1541-III DTV | |");
gertk 0:28557a4d2215 839 // Lcd_show_1541_III_DTV(); /*show splash screen*/
gertk 0:28557a4d2215 840 SetIEC_timings(TIMINGS_DTV); /*set timings according the settings as requested by Jussi (DTV tested settings)*/
gertk 0:28557a4d2215 841 Blink_block = 235; /*i.e. set the value to 225 to get a short off-time (it count to 254 and then goes on again), set value to 255 and it never blinks*/
gertk 0:28557a4d2215 842 }
gertk 0:28557a4d2215 843
gertk 0:28557a4d2215 844 if (PCB_type == DTV_C64)
gertk 0:28557a4d2215 845 {
gertk 0:28557a4d2215 846 printf("\r\n | ( ) |Detected PCB : 1541-III DTV | |");
gertk 0:28557a4d2215 847 // Lcd_show_1541_III_DTV(); /*show splash screen*/
gertk 0:28557a4d2215 848 SetIEC_timings(TIMINGS_DEFAULT); /*set default timings */
gertk 0:28557a4d2215 849 Blink_block = 235;
gertk 0:28557a4d2215 850 }
gertk 0:28557a4d2215 851
gertk 0:28557a4d2215 852 printf("\r\n | -------------------------------- |");
gertk 0:28557a4d2215 853 printf("\r\n | |");
gertk 0:28557a4d2215 854 printf("\r\n | O O |");
gertk 0:28557a4d2215 855 printf("\r\n | POWER DRIVE |");
gertk 0:28557a4d2215 856 printf("\r\n | |");
gertk 0:28557a4d2215 857 printf("\r\n -----------------------------------------");
gertk 0:28557a4d2215 858 printf("\r\n");
gertk 0:28557a4d2215 859
gertk 0:28557a4d2215 860 if (VIC20_mode == TRUE) /*when the user has selected the VIC20 mode, respect that setting and use it again. This is more userfriedly then setting it every time the system start/resets*/
gertk 0:28557a4d2215 861 SetIEC_timings(TIMINGS_VIC20); /*the VIC20_mode is not only a speed setting. It is a mode where the card directory is adjusted for a smaller (24 instead of 40 columns) screen*/
gertk 0:28557a4d2215 862 /*set timings according the VIC-20 settings (25% faster mode)*/
gertk 0:28557a4d2215 863
gertk 0:28557a4d2215 864 printf("\r\n"); /*set cursor to the beginning of the next line (prepare for future (optional) debug printing)*/
gertk 0:28557a4d2215 865 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 866 SetErrorCode(73, LED_ON); /*all is OK, but show ID first, LED is ON as on a real 1541*/
gertk 0:28557a4d2215 867
gertk 0:28557a4d2215 868 for(lp=0; lp<MAX_NUMBER_OF_DOS_BUFFERS; lp++) /*clear the channels*/
gertk 0:28557a4d2215 869 {
gertk 0:28557a4d2215 870 DOS_channel[lp].channel_in_use = FALSE;
gertk 0:28557a4d2215 871 DOS_channel[lp].filename[0] = 0;
gertk 0:28557a4d2215 872 DOS_channel[lp].filetype = 0;
gertk 0:28557a4d2215 873 DOS_channel[lp].RW = 0;
gertk 0:28557a4d2215 874 DOS_channel[lp].track = 0;
gertk 0:28557a4d2215 875 DOS_channel[lp].sector = 0;
gertk 0:28557a4d2215 876 DOS_channel[lp].buffer_pointer = 0;
gertk 0:28557a4d2215 877 DOS_channel[lp].used_buffer = 255;
gertk 0:28557a4d2215 878 DOS_channel[lp].status = NO_FILE;
gertk 0:28557a4d2215 879 }
gertk 0:28557a4d2215 880
gertk 0:28557a4d2215 881 for(lp=0; lp<5; lp++) /*clear the buffers*/
gertk 0:28557a4d2215 882 {
gertk 0:28557a4d2215 883 DOS_buffer[lp].buffer_in_use = FALSE;
gertk 0:28557a4d2215 884 for(lp2=0; lp2<256; lp2++)
gertk 0:28557a4d2215 885 {
gertk 0:28557a4d2215 886 DOS_buffer[lp].buffer[lp2] = 0;
gertk 0:28557a4d2215 887 }
gertk 0:28557a4d2215 888 }
gertk 0:28557a4d2215 889 DOS_buffer[4].buffer_in_use = TRUE; /*this buffer location (or channel) is used for holding the disks BAM, therefore it is not free to be used by the user*/
gertk 0:28557a4d2215 890
gertk 0:28557a4d2215 891 DelayBigMs(2000); /*a small delay to keep the splash-screen visible and to ensure that the connected computer has powered up correctly, this is mainly required for the VIC20. Although the DTV version does not have an LCD (mostly) waiting 2 seconds after powerup is good practice anyway, as the IEC-bus may not be stable yet (a real drive has the same delay)*/
gertk 0:28557a4d2215 892 IEC_state = IDLE;
gertk 0:28557a4d2215 893 file_type = NONE; /*after reset or card insertion there is no D64 file selected, so all actions regarding current refer to the card*/
gertk 0:28557a4d2215 894 DiskState = NO_CARD; /*no card detected yet, so no D64 is selected*/
gertk 0:28557a4d2215 895 file_type = NONE; /*and because the user has selected nothing yet we are in the root, the selected file_type = NONE, as there is no image file selected and we are operating in harddiskmode*/
gertk 0:28557a4d2215 896 enable_ATN_interrupt(); /*enabling the interrupt makes the system ready for use on the IEC-bus*/
gertk 0:28557a4d2215 897 while(1)
gertk 0:28557a4d2215 898 {
gertk 0:28557a4d2215 899 IEC_direction_statemachine();
gertk 0:28557a4d2215 900 }
gertk 0:28557a4d2215 901 }
gertk 0:28557a4d2215 902
gertk 0:28557a4d2215 903 /*****************************************************************************************************************/
gertk 0:28557a4d2215 904 /*****************************************************************************************************************/
gertk 0:28557a4d2215 905 #define CARD_DETECT 0 // this should be a hardware pin
gertk 0:28557a4d2215 906
gertk 0:28557a4d2215 907 void IEC_direction_statemachine(void)
gertk 0:28557a4d2215 908 {
gertk 0:28557a4d2215 909 DelayBigUs(1000); /*'frame to release of ATN'-time is at least 20uS, so we wait a bit longer before we check the status of the ATN-line... otherwise we may be interpret it incorrectly*/
gertk 0:28557a4d2215 910 // DelayBigUs(200); /*'frame to release of ATN'-time is at least 20uS, so we wait a bit longer before we check the status of the ATN-line... otherwise we may be interpret it incorrectly*/
gertk 0:28557a4d2215 911 device_command = CheckForCommand(&command, TRUE);
gertk 0:28557a4d2215 912 while (device_command == FALSE) /*no commands are received so we have time for others things...*/
gertk 0:28557a4d2215 913 {
gertk 0:28557a4d2215 914
gertk 0:28557a4d2215 915 if(CARD_DETECT == 1) /*check if the card is present*/
gertk 0:28557a4d2215 916 DiskState = NO_CARD; /*no card detected, so no D64 is selected*/
gertk 0:28557a4d2215 917
gertk 0:28557a4d2215 918 if(DiskState == NO_CARD)
gertk 0:28557a4d2215 919 {
gertk 0:28557a4d2215 920 DelayBigMs(1000);
gertk 0:28557a4d2215 921 SetErrorCode(73, LED_OFF); /*all is OK, but show ID first, LED is OFF as on a real 1541*/
gertk 0:28557a4d2215 922 // Lcd_clr(); /*clear screen to prepare for more serious info.*/
gertk 0:28557a4d2215 923 NoCardMenu(); /*check if a setting button has been pressed and handle accordingly*/
gertk 0:28557a4d2215 924 if (CardStatus()) /*this routine will only pass until a valid card is present*/
gertk 0:28557a4d2215 925 {
gertk 0:28557a4d2215 926 CountFiles(); /*count all files in the current directory (which is root)*/
gertk 0:28557a4d2215 927 SetErrorCode(73, LED_OFF); /*all is OK (but show ID first) set LED to color cycle to indicate that this is the first time we enter the root after card insertion or reset. Meaning that the selected file is 0 (the card itself)*/
gertk 0:28557a4d2215 928 file_type = NONE; /*after reset or card insertion there is no D64 file selected, so all actions regarding current refer to the card*/
gertk 0:28557a4d2215 929 // Lcd_clr();
gertk 0:28557a4d2215 930 print_D64_name(PLAIN);
gertk 0:28557a4d2215 931 print_D64_TSB(0, 0, 0,0); /*print Track, Sector, Block*/
gertk 0:28557a4d2215 932 }
gertk 0:28557a4d2215 933 }
gertk 0:28557a4d2215 934 // else
gertk 0:28557a4d2215 935 // {
gertk 0:28557a4d2215 936 // SelectD64Image(); /*check for user interaction via buttons*/
gertk 0:28557a4d2215 937 // }
gertk 0:28557a4d2215 938 device_command = CheckForCommand(&command, TRUE);
gertk 0:28557a4d2215 939 }
gertk 0:28557a4d2215 940
gertk 0:28557a4d2215 941 if(CARD_DETECT == 1) /*check again if the card is present, some @#$#@$#@% might have removed it*/
gertk 0:28557a4d2215 942 DiskState = NO_CARD; /*no card detected, so no D64 is selected*/
gertk 0:28557a4d2215 943
gertk 0:28557a4d2215 944
gertk 0:28557a4d2215 945 switch (device_command)
gertk 0:28557a4d2215 946 {
gertk 0:28557a4d2215 947 case OPEN: /*here we decode the command string and we check if we are capable of executing the requested action*/
gertk 0:28557a4d2215 948 {
gertk 0:28557a4d2215 949 DOS_channel[channel].channel_in_use = TRUE; /*claim this channel*/
gertk 0:28557a4d2215 950 WaitForString(command_string, TRUE); /*wait for an operator string that ends with an EOI*/
gertk 0:28557a4d2215 951 break;
gertk 0:28557a4d2215 952 }
gertk 0:28557a4d2215 953
gertk 0:28557a4d2215 954 case DATA:
gertk 0:28557a4d2215 955 {
gertk 0:28557a4d2215 956 // if (DOS_channel[channel].channel_in_use == TRUE) /*check if this channel has been opened, if not ignore*/
gertk 0:28557a4d2215 957 // {
gertk 0:28557a4d2215 958 DataHandler();
gertk 0:28557a4d2215 959 // }
gertk 0:28557a4d2215 960 // else
gertk 0:28557a4d2215 961 // {
gertk 0:28557a4d2215 962 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 963 // printf("\r\nChannel not open! Ignore DATA command"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 964 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 965 // }
gertk 0:28557a4d2215 966 break;
gertk 0:28557a4d2215 967 }
gertk 0:28557a4d2215 968
gertk 0:28557a4d2215 969 case CLOSE:
gertk 0:28557a4d2215 970 {
gertk 0:28557a4d2215 971 // if (channel == 15) /*when the error/command channel is closed, then all files stored in the DOS buffer are closed also*/
gertk 0:28557a4d2215 972 // {
gertk 0:28557a4d2215 973 /*to do: close all open files properly*/
gertk 0:28557a4d2215 974 // }
gertk 0:28557a4d2215 975 // else
gertk 0:28557a4d2215 976 // {
gertk 0:28557a4d2215 977 // }
gertk 0:28557a4d2215 978
gertk 0:28557a4d2215 979 if (DOS_channel[channel].used_buffer != 255) /*check if there is a buffer connected to this channel*/
gertk 0:28557a4d2215 980 {
gertk 0:28557a4d2215 981 DOS_buffer[DOS_channel[channel].used_buffer].buffer_in_use = FALSE; /*free the buffer that was connected to this channel. now this buffer is free to use for newly opened channels that might require a buffer*/
gertk 0:28557a4d2215 982 }
gertk 0:28557a4d2215 983
gertk 0:28557a4d2215 984 /*set the channel information back to default, although i doubt that the original 1541 does this...*/
gertk 0:28557a4d2215 985 DOS_channel[channel].channel_in_use = FALSE;
gertk 0:28557a4d2215 986 DOS_channel[channel].filename[0] = 0;
gertk 0:28557a4d2215 987 DOS_channel[channel].filetype = 0;
gertk 0:28557a4d2215 988 DOS_channel[channel].RW = 0;
gertk 0:28557a4d2215 989 DOS_channel[channel].track = 0;
gertk 0:28557a4d2215 990 DOS_channel[channel].sector = 0;
gertk 0:28557a4d2215 991 DOS_channel[channel].buffer_pointer = 0;
gertk 0:28557a4d2215 992 DOS_channel[channel].used_buffer = 255;
gertk 0:28557a4d2215 993 DOS_channel[channel].status = NO_FILE;
gertk 0:28557a4d2215 994
gertk 0:28557a4d2215 995 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 996 printf("\r\nClose"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 997 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 998 break;
gertk 0:28557a4d2215 999 }
gertk 0:28557a4d2215 1000
gertk 0:28557a4d2215 1001 case UNLISTEN:
gertk 0:28557a4d2215 1002 {
gertk 0:28557a4d2215 1003 if (IEC_state != IDLE) /*make sure that this command is not the last command of a different device, if it is our device we are not IDLE anymore since the this device would have it's status set to a different thing the IDLE*/
gertk 0:28557a4d2215 1004 {
gertk 0:28557a4d2215 1005 if (DOS_channel[channel].channel_in_use == TRUE) /*check if the previous command on this channel was open*/
gertk 0:28557a4d2215 1006 {
gertk 0:28557a4d2215 1007 OpenHandler();
gertk 0:28557a4d2215 1008 }
gertk 0:28557a4d2215 1009
gertk 0:28557a4d2215 1010 //turn LED OFF
gertk 0:28557a4d2215 1011 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1012 // printf("\r\nUnlisten\r\n"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1013 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1014 IEC_state = IDLE;
gertk 0:28557a4d2215 1015 }
gertk 0:28557a4d2215 1016 break;
gertk 0:28557a4d2215 1017 }
gertk 0:28557a4d2215 1018
gertk 0:28557a4d2215 1019 case UNTALK:
gertk 0:28557a4d2215 1020 {
gertk 0:28557a4d2215 1021 if (IEC_state != IDLE) /*make sure that this command is not the last command of a different device, if it is our device we are not IDLE anymore since the this device would have it's status set to a different thing the IDLE*/
gertk 0:28557a4d2215 1022 {
gertk 0:28557a4d2215 1023 //turn LED OFF
gertk 0:28557a4d2215 1024 IEC_state = IDLE;
gertk 0:28557a4d2215 1025 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1026 // printf("\r\nUntalk\r\n"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1027 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1028
gertk 0:28557a4d2215 1029 }
gertk 0:28557a4d2215 1030 break;
gertk 0:28557a4d2215 1031 }
gertk 0:28557a4d2215 1032
gertk 0:28557a4d2215 1033 default:
gertk 0:28557a4d2215 1034 {
gertk 0:28557a4d2215 1035 if (device_command == (LISTEN | devicenumber))
gertk 0:28557a4d2215 1036 {
gertk 0:28557a4d2215 1037 //turn LED ON
gertk 0:28557a4d2215 1038 IEC_state = ACTIVE_LISTEN;
gertk 0:28557a4d2215 1039 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1040 // printf("\r\nListen"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1041 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1042 break;
gertk 0:28557a4d2215 1043 }
gertk 0:28557a4d2215 1044
gertk 0:28557a4d2215 1045 if (device_command == (TALK | devicenumber))
gertk 0:28557a4d2215 1046 {
gertk 0:28557a4d2215 1047 //turn LED ON
gertk 0:28557a4d2215 1048 IEC_state = ACTIVE_TALK;
gertk 0:28557a4d2215 1049 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1050 // printf("\r\nTalk"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1051 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1052 break;
gertk 0:28557a4d2215 1053 }
gertk 0:28557a4d2215 1054
gertk 0:28557a4d2215 1055 /*--------------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1056 /* current communication on the bus is incorrect or meant for another device on the bus */
gertk 0:28557a4d2215 1057 /*--------------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1058 disable_ATN_interrupt(); /*By disabling the ATN interrupt we do not interfer with the data that is meant for another device on the bus*/
gertk 0:28557a4d2215 1059 FreeIEC(); /*get of the bus...*/
gertk 0:28557a4d2215 1060 enable_ATN_interrupt(); /*all is back to normal, enable interrupts on ATN line*/
gertk 0:28557a4d2215 1061 IEC_state = IDLE;
gertk 0:28557a4d2215 1062 break;
gertk 0:28557a4d2215 1063 }
gertk 0:28557a4d2215 1064 }
gertk 0:28557a4d2215 1065
gertk 0:28557a4d2215 1066 myled3=0;
gertk 0:28557a4d2215 1067 }
gertk 0:28557a4d2215 1068
gertk 0:28557a4d2215 1069
gertk 0:28557a4d2215 1070 void OpenHandler(void)
gertk 0:28557a4d2215 1071 {
gertk 0:28557a4d2215 1072 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1073 // printf("\r\nOPENHANDLER: "); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1074 // printf("command_string:%s",command_string); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1075 // printf("\r\nchannel:%d",channel); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1076 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1077
gertk 0:28557a4d2215 1078 switch(channel)
gertk 0:28557a4d2215 1079 {
gertk 0:28557a4d2215 1080 case 0: /*this channel is used for reading of files*/
gertk 0:28557a4d2215 1081 {
gertk 0:28557a4d2215 1082 if(DiskState == NO_CARD)
gertk 0:28557a4d2215 1083 {
gertk 0:28557a4d2215 1084 DOS_channel[channel].next_action = ABORT_SENDING;
gertk 0:28557a4d2215 1085 break;
gertk 0:28557a4d2215 1086 }
gertk 0:28557a4d2215 1087
gertk 0:28557a4d2215 1088 /*------------------*/
gertk 0:28557a4d2215 1089 /* '$' = DIRECTORY */
gertk 0:28557a4d2215 1090 /*------------------*/
gertk 0:28557a4d2215 1091 if ((strlen((char *)command_string) == 5) && (strncmp((char *)command_string,"$CARD", 5) == 0 )) /*check the COMPLETE string*/
gertk 0:28557a4d2215 1092 { /*ROOT directory of the card*/
gertk 0:28557a4d2215 1093 file_type = NONE; /*all later actions refer to the CARD and not a D64 file*/
gertk 0:28557a4d2215 1094 DiskState = CARD_ACTIVE; /*this command overrules the buttons*/
gertk 0:28557a4d2215 1095 DOS_channel[channel].next_action = CARD_DIRECTORY; /*show the directory of the MMC/SD-card*/
gertk 0:28557a4d2215 1096 print_D64_name(PLAIN);
gertk 0:28557a4d2215 1097 break;
gertk 0:28557a4d2215 1098 }
gertk 0:28557a4d2215 1099
gertk 0:28557a4d2215 1100 if (((strlen((char *)command_string) == 1) && (strncmp((char *)command_string,"$", 1) == 0 )) || ((strlen((char *)command_string) == 2) && (strncmp((char *)command_string,"$0", 2) == 0 ))) /*check the COMPLETE string*/
gertk 0:28557a4d2215 1101 { /*current directory, which may be D64 or ROOT depending on the previous selection*/
gertk 0:28557a4d2215 1102 if ((file_type == NONE) || (file_type == SUBDIRECTORY)) /*check for the currently selected file, if 0 refer to the card and not a D64 file*/
gertk 0:28557a4d2215 1103 DOS_channel[channel].next_action = CARD_DIRECTORY; /*show the directory of the MMC/SD-card*/
gertk 0:28557a4d2215 1104 else
gertk 0:28557a4d2215 1105 DOS_channel[channel].next_action = DIRECTORY; /*show the directory of the currently selected D64 file*/
gertk 0:28557a4d2215 1106 break;
gertk 0:28557a4d2215 1107 }
gertk 0:28557a4d2215 1108
gertk 0:28557a4d2215 1109 if (strncmp("$", (char *)command_string, 1) == 0 ) /*check the 1st char of the string)*/
gertk 0:28557a4d2215 1110 {
gertk 0:28557a4d2215 1111 file_status = SeekFileOnCard(&command_string[1], &file); /*check if file is present or not*/
gertk 0:28557a4d2215 1112 if (file_status == FALSE)
gertk 0:28557a4d2215 1113 {
gertk 0:28557a4d2215 1114 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1115 DOS_channel[channel].next_action = ABORT_SENDING; /*the requested directory does not exist*/
gertk 0:28557a4d2215 1116 }
gertk 0:28557a4d2215 1117 else
gertk 0:28557a4d2215 1118 {
gertk 0:28557a4d2215 1119 DiskState = CARD_ACTIVE; /*this command overrules the buttons*/
gertk 0:28557a4d2215 1120 file_type = FileFilter(); /*check the type of file to determine the mode of operation*/
gertk 0:28557a4d2215 1121 if(file_type == SUBDIRECTORY) /*check if the user wants to enter a subdirectory*/
gertk 0:28557a4d2215 1122 {
gertk 0:28557a4d2215 1123 OpenSubDirectory(&file); /*the user request to enter a subdirectory, so we call the routine that setts all registers in the correct way in order to use subdirectories properly*/
gertk 0:28557a4d2215 1124 file_number = 0; /*the file_number counter needs to be reset*/
gertk 0:28557a4d2215 1125 file_type = NONE; /*and because the user has selected a (sub)directory, the selected file_type = NONE, as there is no image file selected and we are operating in harddiskmode*/
gertk 0:28557a4d2215 1126 CountFiles(); /*count all files in the opened directory*/
gertk 0:28557a4d2215 1127 DOS_channel[channel].next_action = CARD_DIRECTORY; /*show the (sub)directory of the MMC/SD-card*/
gertk 0:28557a4d2215 1128 print_D64_name(PLAIN); /*update the display*/
gertk 0:28557a4d2215 1129 }
gertk 0:28557a4d2215 1130 else
gertk 0:28557a4d2215 1131 {
gertk 0:28557a4d2215 1132 file_number = file_status;
gertk 0:28557a4d2215 1133 DOS_channel[channel].next_action = DIRECTORY; /*show the directory of the requested D64 file (but only if the actions below do not fail offcourse)*/
gertk 0:28557a4d2215 1134 print_D64_name(PLAIN); /*update the display*/
gertk 0:28557a4d2215 1135 FileSectorScan(&file); /*update the sector location table cache*/
gertk 0:28557a4d2215 1136 D64ReadBAM(); /*update the BAM*/
gertk 0:28557a4d2215 1137 }
gertk 0:28557a4d2215 1138 }
gertk 0:28557a4d2215 1139 break; /*leave the case*/
gertk 0:28557a4d2215 1140 }
gertk 0:28557a4d2215 1141
gertk 0:28557a4d2215 1142 /*----------------------*/
gertk 0:28557a4d2215 1143 /* LOAD filename */
gertk 0:28557a4d2215 1144 /*----------------------*/
gertk 0:28557a4d2215 1145 if (file_type == NONE) /*check for the currently selected file, if 0 refer to the card and not a D64 file*/
gertk 0:28557a4d2215 1146 {
gertk 0:28557a4d2215 1147 file_status = SeekFileOnCard(command_string, &file); /*check if file is present on the card*/
gertk 0:28557a4d2215 1148 DOS_channel[channel].next_action = RD_FILE_FROM_ROOT;
gertk 0:28557a4d2215 1149 break;
gertk 0:28557a4d2215 1150 }
gertk 0:28557a4d2215 1151 else
gertk 0:28557a4d2215 1152 {
gertk 0:28557a4d2215 1153 file_status = D64SeekFile(command_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present within a D64 file*/
gertk 0:28557a4d2215 1154 DOS_channel[channel].next_action = RD_FILE;
gertk 0:28557a4d2215 1155 break;
gertk 0:28557a4d2215 1156 }
gertk 0:28557a4d2215 1157 }
gertk 0:28557a4d2215 1158
gertk 0:28557a4d2215 1159 case 1: /*this channel is used for writing of files*/
gertk 0:28557a4d2215 1160 {
gertk 0:28557a4d2215 1161 if(DiskState == NO_CARD)
gertk 0:28557a4d2215 1162 {
gertk 0:28557a4d2215 1163 DOS_channel[channel].next_action = ABORT_RECEIVING;
gertk 0:28557a4d2215 1164 break;
gertk 0:28557a4d2215 1165 }
gertk 0:28557a4d2215 1166
gertk 0:28557a4d2215 1167 /*------------------------------------------------------------*/
gertk 0:28557a4d2215 1168 /* '@' = REPLACE */
gertk 0:28557a4d2215 1169 /* syntax: SAVE"@0:<filename>",x,1 */
gertk 0:28557a4d2215 1170 /* syntax: SAVE"@S:<filename>",8,1 (special for game:commando, int karate, donkey kong)*/
gertk 0:28557a4d2215 1171 /*------------------------------------------------------------*/
gertk 0:28557a4d2215 1172 if ((strncmp("@:", (char *)command_string, 2) == 0 ) || (strncmp("@0:",(char *) command_string, 3) == 0 ) || (strncmp("@S:", (char *)command_string, 3) == 0 )) /*check the beginning of the string)*/
gertk 0:28557a4d2215 1173 {
gertk 0:28557a4d2215 1174 SplitStringOn_Sign(':', command_string, filename_string);
gertk 0:28557a4d2215 1175 file_status = D64SeekFile(filename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1176 DOS_channel[channel].next_action = REPLACE_FILE; /*replace a file within the currently selected D64 file*/
gertk 0:28557a4d2215 1177 break;
gertk 0:28557a4d2215 1178 }
gertk 0:28557a4d2215 1179
gertk 0:28557a4d2215 1180 /*---------------*/
gertk 0:28557a4d2215 1181 /* SAVE filename */
gertk 0:28557a4d2215 1182 /*---------------*/
gertk 0:28557a4d2215 1183 if (file_type == NONE) /*check for the currently selected file, if 0 refer to the card and not a D64 file*/
gertk 0:28557a4d2215 1184 {
gertk 0:28557a4d2215 1185 file_status = SeekFileOnCard(command_string, &file); /*check if file is present or not*/
gertk 0:28557a4d2215 1186 DOS_channel[channel].next_action = WR_FILE_TO_ROOT;
gertk 0:28557a4d2215 1187 break;
gertk 0:28557a4d2215 1188 }
gertk 0:28557a4d2215 1189 else
gertk 0:28557a4d2215 1190 {
gertk 0:28557a4d2215 1191 file_status = D64SeekFile(command_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1192 DOS_channel[channel].next_action = WR_FILE;
gertk 0:28557a4d2215 1193 break;
gertk 0:28557a4d2215 1194 }
gertk 0:28557a4d2215 1195 }
gertk 0:28557a4d2215 1196
gertk 0:28557a4d2215 1197
gertk 0:28557a4d2215 1198 /*the channels 2-14 are used for the actual file handling that do not use the BASIC LOAD or SAVE commands*/
gertk 0:28557a4d2215 1199 case 2:;
gertk 0:28557a4d2215 1200 case 3:;
gertk 0:28557a4d2215 1201 case 4:;
gertk 0:28557a4d2215 1202 case 5:;
gertk 0:28557a4d2215 1203 case 6:;
gertk 0:28557a4d2215 1204 case 7:;
gertk 0:28557a4d2215 1205 case 8:;
gertk 0:28557a4d2215 1206 case 9:;
gertk 0:28557a4d2215 1207 case 10:;
gertk 0:28557a4d2215 1208 case 11:;
gertk 0:28557a4d2215 1209 case 12:;
gertk 0:28557a4d2215 1210 case 13:;
gertk 0:28557a4d2215 1211 case 14:
gertk 0:28557a4d2215 1212 {
gertk 0:28557a4d2215 1213 if (command_string[0] == '#') /*if the user/computer specifies a buffer then handle accordingly...*/
gertk 0:28557a4d2215 1214 {
gertk 0:28557a4d2215 1215 if (DOS_channel[channel].used_buffer == 255) /*check if this channel allready has a buffer connected*/
gertk 0:28557a4d2215 1216 {
gertk 0:28557a4d2215 1217 if (ValueFromString(&command_string[0], &value_1)) /*check if the user has specified it's own buffer preference*/
gertk 0:28557a4d2215 1218 {
gertk 0:28557a4d2215 1219 if (DOS_buffer[value_1].buffer_in_use == FALSE) /*check if this buffer is still available*/
gertk 0:28557a4d2215 1220 {
gertk 0:28557a4d2215 1221 DOS_buffer[value_1].buffer_in_use = TRUE; /*this buffer is still free, so we can claim this buffer*/
gertk 0:28557a4d2215 1222 DOS_channel[channel].used_buffer = value_1; /*connect the free buffer to this channel*/
gertk 0:28557a4d2215 1223 }
gertk 0:28557a4d2215 1224 else
gertk 0:28557a4d2215 1225 {
gertk 0:28557a4d2215 1226 SetErrorCode(70, LED_ERROR); /*the requested buffer is allready in use, close the current situtation properly before we let the new situation claim this buffer*/
gertk 0:28557a4d2215 1227 }
gertk 0:28557a4d2215 1228 }
gertk 0:28557a4d2215 1229 else
gertk 0:28557a4d2215 1230 {
gertk 0:28557a4d2215 1231 nextfreebuffer = SearchFreeBuffer(); /*since the user does not care which buffer it uses, so the 1541-III may decide which buffer is available*/
gertk 0:28557a4d2215 1232 if (nextfreebuffer == 255)
gertk 0:28557a4d2215 1233 {
gertk 0:28557a4d2215 1234 SetErrorCode(70, LED_ERROR); /*No channels available or in other words: no more free buffers */
gertk 0:28557a4d2215 1235 }
gertk 0:28557a4d2215 1236 else
gertk 0:28557a4d2215 1237 {
gertk 0:28557a4d2215 1238 DOS_buffer[nextfreebuffer].buffer_in_use = TRUE; /*claim this buffer*/
gertk 0:28557a4d2215 1239 DOS_channel[channel].used_buffer = nextfreebuffer; /*connect the free buffer to this channel*/
gertk 0:28557a4d2215 1240 }
gertk 0:28557a4d2215 1241 }
gertk 0:28557a4d2215 1242 }
gertk 0:28557a4d2215 1243 }
gertk 0:28557a4d2215 1244 else
gertk 0:28557a4d2215 1245 {
gertk 0:28557a4d2215 1246 ExtractFilenameFromString(command_string, filename_string); /*extract the filename from the commandstring given by the user/computer*/
gertk 0:28557a4d2215 1247 SplitStringOn_Sign(',', command_string, filetype_string);
gertk 0:28557a4d2215 1248 SplitStringOn_Sign(',', filetype_string, RW_string);
gertk 0:28557a4d2215 1249 strcpy((char *)&DOS_channel[channel].filename[0], (char *)filename_string); /*copy the filename into the DOS buffer*/
gertk 0:28557a4d2215 1250
gertk 0:28557a4d2215 1251 /*check for filetype*/
gertk 0:28557a4d2215 1252 if ((strncmp("A", (char *)filetype_string, 1) == 0 ) || (strncmp("APPEND",(char *) filetype_string, 6) == 0 ))
gertk 0:28557a4d2215 1253 {
gertk 0:28557a4d2215 1254 DOS_channel[channel].filetype = SEQUENTIAL;
gertk 0:28557a4d2215 1255 //to do: zoek hier naar het einde van de sequentiele file en zet de bufferpointer track en sector waardes in de DOS buffer op de correcte waardes
gertk 0:28557a4d2215 1256 }
gertk 0:28557a4d2215 1257 else
gertk 0:28557a4d2215 1258 {
gertk 0:28557a4d2215 1259 /*check for the filetype SEQ, REL, PRG, USR, LENGTH (checking for only the first letter is sufficient to check for all variations of the word sequential, program, etc)*/
gertk 0:28557a4d2215 1260 if (strncmp("S", (char *)filetype_string, 1))
gertk 0:28557a4d2215 1261 {
gertk 0:28557a4d2215 1262 DOS_channel[channel].filetype = SEQUENTIAL;
gertk 0:28557a4d2215 1263 }
gertk 0:28557a4d2215 1264 if (strncmp("R", (char *)filetype_string, 1))
gertk 0:28557a4d2215 1265 {
gertk 0:28557a4d2215 1266 DOS_channel[channel].filetype = RELATIVE;
gertk 0:28557a4d2215 1267 }
gertk 0:28557a4d2215 1268 if (strncmp("P", (char *)filetype_string, 1))
gertk 0:28557a4d2215 1269 {
gertk 0:28557a4d2215 1270 DOS_channel[channel].filetype = PROGRAM;
gertk 0:28557a4d2215 1271 }
gertk 0:28557a4d2215 1272 if (strncmp("U", (char *)filetype_string, 1) == 0 )
gertk 0:28557a4d2215 1273 {
gertk 0:28557a4d2215 1274 DOS_channel[channel].filetype = USER;
gertk 0:28557a4d2215 1275 }
gertk 0:28557a4d2215 1276 // if (strncmp("L", filetype_string, 1))
gertk 0:28557a4d2215 1277 // {
gertk 0:28557a4d2215 1278 // DOS_channel[channel].filetype = USER;
gertk 0:28557a4d2215 1279 // }
gertk 0:28557a4d2215 1280
gertk 0:28557a4d2215 1281
gertk 0:28557a4d2215 1282 /*check if file is to be used as a Read, Write or Modify (checking for only the first letter is sufficient to check for all variations of the word)*/
gertk 0:28557a4d2215 1283 if ((RW_string[0]==0) || (strncmp("R", (char *)RW_string, 1) == 0 )) /*when not defined or defined as R, then the file is to be used for READ functions*/
gertk 0:28557a4d2215 1284 {
gertk 0:28557a4d2215 1285 DOS_channel[channel].RW = RD_FILE;
gertk 0:28557a4d2215 1286 file_status = D64SeekFile(filename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1287 if (file_status == FILE_PRESENT)
gertk 0:28557a4d2215 1288 {
gertk 0:28557a4d2215 1289 DOS_channel[channel].status = FILE_OPEN; /*the file could be found*/
gertk 0:28557a4d2215 1290 DOS_channel[channel].track = track; /*save, the location of the first byte regarding this file on the "disk", to the appropriate registers*/
gertk 0:28557a4d2215 1291 DOS_channel[channel].sector = sector;
gertk 0:28557a4d2215 1292 DOS_channel[channel].buffer_pointer = 0;
gertk 0:28557a4d2215 1293 }
gertk 0:28557a4d2215 1294 else
gertk 0:28557a4d2215 1295 {
gertk 0:28557a4d2215 1296 DOS_channel[channel].status = NO_FILE; /*the file could not be found*/
gertk 0:28557a4d2215 1297 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1298 }
gertk 0:28557a4d2215 1299 }
gertk 0:28557a4d2215 1300
gertk 0:28557a4d2215 1301 if ((strncmp("W", (char *)RW_string, 1) == 0 ) || (strncmp("WRITE",(char *) RW_string, 5) == 0 ))
gertk 0:28557a4d2215 1302 {
gertk 0:28557a4d2215 1303 DOS_channel[channel].RW = WR_FILE;
gertk 0:28557a4d2215 1304 file_status = D64SeekFile(filename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1305 if (file_status == FILE_PRESENT)
gertk 0:28557a4d2215 1306 {
gertk 0:28557a4d2215 1307 DOS_channel[channel].status = NO_FILE; /*the file could not be found*/
gertk 0:28557a4d2215 1308 SetErrorCode(63,LED_ERROR); /*file exists*/
gertk 0:28557a4d2215 1309 }
gertk 0:28557a4d2215 1310 else
gertk 0:28557a4d2215 1311 {
gertk 0:28557a4d2215 1312 DOS_channel[channel].status = FILE_OPEN; /*the file could be found*/
gertk 0:28557a4d2215 1313 //to do: maak in de directory structuur een nieuwe file aan maar sluit deze (uiteraard niet af), deze file word ook wel een 'splat' file genoemd
gertk 0:28557a4d2215 1314
gertk 0:28557a4d2215 1315 DOS_channel[channel].track = track; /*save, the location of the first byte regarding this file on the "disk", to the appropriate registers*/
gertk 0:28557a4d2215 1316 DOS_channel[channel].sector = sector;
gertk 0:28557a4d2215 1317 DOS_channel[channel].buffer_pointer = 0;
gertk 0:28557a4d2215 1318 }
gertk 0:28557a4d2215 1319 }
gertk 0:28557a4d2215 1320 if ((strncmp("M", (char *)RW_string, 1) == 0 ) || (strncmp("MODIFY", (char *)RW_string, 6) == 0 ))
gertk 0:28557a4d2215 1321 {
gertk 0:28557a4d2215 1322 DOS_channel[channel].RW = MODIFY_FILE;
gertk 0:28557a4d2215 1323 //to do: uitzoeken wat modify precies inhoud...
gertk 0:28557a4d2215 1324 }
gertk 0:28557a4d2215 1325
gertk 0:28557a4d2215 1326 }
gertk 0:28557a4d2215 1327 }
gertk 0:28557a4d2215 1328
gertk 0:28557a4d2215 1329 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1330 printf("\r\nOpen, channel %d", channel); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1331 printf("\r\n channel_in_use:%03d",DOS_channel[channel].channel_in_use);
gertk 0:28557a4d2215 1332 printf("\r\n next_action :%03d",DOS_channel[channel].next_action);
gertk 0:28557a4d2215 1333 printf("\r\n filename[0] :%s",DOS_channel[channel].filename);
gertk 0:28557a4d2215 1334 printf("\r\n filetype :%03d",DOS_channel[channel].filetype);
gertk 0:28557a4d2215 1335 printf("\r\n RW :%03d",DOS_channel[channel].RW);
gertk 0:28557a4d2215 1336 printf("\r\n track :%03d",DOS_channel[channel].track);
gertk 0:28557a4d2215 1337 printf("\r\n sector :%03d",DOS_channel[channel].sector);
gertk 0:28557a4d2215 1338 printf("\r\n buffer_pointer:%03d",DOS_channel[channel].buffer_pointer);
gertk 0:28557a4d2215 1339 printf("\r\n used_buffer :%03d",DOS_channel[channel].used_buffer);
gertk 0:28557a4d2215 1340 printf("\r\n status :%03d",DOS_channel[channel].status);
gertk 0:28557a4d2215 1341 printf("\r\n"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1342 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1343 break;
gertk 0:28557a4d2215 1344 }
gertk 0:28557a4d2215 1345
gertk 0:28557a4d2215 1346 case 15:
gertk 0:28557a4d2215 1347 {
gertk 0:28557a4d2215 1348 /*------------------------------------------------------*/
gertk 0:28557a4d2215 1349 /* Set LCD's contrast */
gertk 0:28557a4d2215 1350 /* Syntax: "LCDCONTRAST=<value>" */
gertk 0:28557a4d2215 1351 /* Example: OPEN15,device,15,"LCDCONTRAST=ddd"<RETURN> */
gertk 0:28557a4d2215 1352 /* CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1353 /*------------------------------------------------------*/
gertk 0:28557a4d2215 1354 if (strncmp("LCDCONTRAST=",(char *)command_string,12) == 0 ) /*check the beginning of the string)*/
gertk 0:28557a4d2215 1355 {
gertk 0:28557a4d2215 1356 SplitStringOn_Sign('=', command_string, value_string);
gertk 0:28557a4d2215 1357 ValueFromString(value_string, &value_1);
gertk 0:28557a4d2215 1358 if (value_1>0 && value_1<255)
gertk 0:28557a4d2215 1359 {
gertk 0:28557a4d2215 1360 setting_contrast = value_1; /*copy new value to the correct register*/
gertk 0:28557a4d2215 1361 // SetContrast(); /*apply new setting*/
gertk 0:28557a4d2215 1362 // SaveSettingsToEEPROM(); /*save value to EEPROM*/
gertk 0:28557a4d2215 1363 print_device_status(" CONTRAST... ");
gertk 0:28557a4d2215 1364 }
gertk 0:28557a4d2215 1365 else
gertk 0:28557a4d2215 1366 { /*incorrect value*/
gertk 0:28557a4d2215 1367 FreeIEC(); /*BUT... since there's no use in receiving data we cannot process, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1368 }
gertk 0:28557a4d2215 1369 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1370 }
gertk 0:28557a4d2215 1371
gertk 0:28557a4d2215 1372 /*----------------------------------------------------------------*/
gertk 0:28557a4d2215 1373 /* 'N' = NEW - Format a floppy disk */
gertk 0:28557a4d2215 1374 /* Syntax: "NEW:<diskname>,<id>" */
gertk 0:28557a4d2215 1375 /* Example: OPEN 15,8,15,"N:diskname,01"<RETURN> */
gertk 0:28557a4d2215 1376 /* CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1377 /* <diskname> can be up to 16 characters */
gertk 0:28557a4d2215 1378 /* <id> can either be omitted or must be exactly 2 characters long*/
gertk 0:28557a4d2215 1379 /*----------------------------------------------------------------*/
gertk 0:28557a4d2215 1380 if ((strncmp("N:",(char *)command_string,2) == 0 ) || (strncmp("N0:",(char *)command_string,3) == 0 ) || (strncmp("NEW:",(char *)command_string,4) == 0 ) || (strncmp("NEW0:",(char *)command_string,5) == 0 )) /*check the beginning of the string)*/
gertk 0:28557a4d2215 1381 {
gertk 0:28557a4d2215 1382 if (file_type == D64_35T_MODE) //future or TODO: D64_35T_ER_MODE, D64_40T_MODE, D64_40T_ER_MODE
gertk 0:28557a4d2215 1383 {
gertk 0:28557a4d2215 1384 print_device_status(" FORMATTING.. ");
gertk 0:28557a4d2215 1385 SplitStringOn_Sign(':', command_string, filename_string);
gertk 0:28557a4d2215 1386 SplitStringOn_Sign(',', filename_string, value_string);
gertk 0:28557a4d2215 1387 FormatD64File(filename_string, value_string);
gertk 0:28557a4d2215 1388 }
gertk 0:28557a4d2215 1389 else
gertk 0:28557a4d2215 1390 { /*creating a disk in the root directory is not supported*/
gertk 0:28557a4d2215 1391 FreeIEC(); /*BUT... since there's no use in receiving data we cannot process, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1392 }
gertk 0:28557a4d2215 1393 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1394 }
gertk 0:28557a4d2215 1395
gertk 0:28557a4d2215 1396 /*----------------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1397 /* 'S' = SCRATCH (also referred to as 'delete') */
gertk 0:28557a4d2215 1398 /* Syntax: "SCRATCH:<file>" */
gertk 0:28557a4d2215 1399 /* Example: OPEN 15,8,15,"S:filename"<RETURN> */
gertk 0:28557a4d2215 1400 /* CLOSE 15<RETURN> (do not forget otherwise remaining commands may not work) */
gertk 0:28557a4d2215 1401 /* You can use the wild cards '?' and '*' to delete several files at once. */
gertk 0:28557a4d2215 1402 /*----------------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1403 if ((strncmp("S:",(char *)command_string,2) == 0 ) || (strncmp("S0:",(char *)command_string,3) == 0 ) || (strncmp("SCRATCH:",(char *)command_string,8) == 0 ) || (strncmp("SCRATCH0:",(char *)command_string,9) == 0 )) /*check the beginning of the string)*/
gertk 0:28557a4d2215 1404 {
gertk 0:28557a4d2215 1405 SplitStringOn_Sign(':', command_string, filename_string);
gertk 0:28557a4d2215 1406 file_status = D64SeekFile(filename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1407 if (file_status == FILE_PRESENT)
gertk 0:28557a4d2215 1408 {
gertk 0:28557a4d2215 1409 files_scratched = 0; /*the error message abuses this variable for the number of files scratched, so... we must do this also to simulate the 1541 as good as possible*/
gertk 0:28557a4d2215 1410 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 1411 while(file_status == FILE_PRESENT) /*this function uses wildcards, so the same function needs to be repeated, keep checking untill false*/
gertk 0:28557a4d2215 1412 {
gertk 0:28557a4d2215 1413 print_device_status(" SCRATCHING.. ");
gertk 0:28557a4d2215 1414 D64ScratchDirEntry(dirtrack, dirsector, direntry);
gertk 0:28557a4d2215 1415 files_scratched++;
gertk 0:28557a4d2215 1416 file_status = D64SeekFile(filename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1417 }
gertk 0:28557a4d2215 1418 SetErrorCode(1,LED_OFF);
gertk 0:28557a4d2215 1419 }
gertk 0:28557a4d2215 1420 else
gertk 0:28557a4d2215 1421 {
gertk 0:28557a4d2215 1422 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1423 FreeIEC(); /*BUT... since there's no use in receiving data we cannot process, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1424 }
gertk 0:28557a4d2215 1425 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1426 }
gertk 0:28557a4d2215 1427
gertk 0:28557a4d2215 1428 /*--------------------------------------------------*/
gertk 0:28557a4d2215 1429 /* 'R' = RENAME - Rename a file */
gertk 0:28557a4d2215 1430 /* Syntax: "RENAME:<newname>=<oldname>" */
gertk 0:28557a4d2215 1431 /* Example: OPEN 15,8,15,"R:newfilename=oldfilename"*/
gertk 0:28557a4d2215 1432 /* CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1433 /*--------------------------------------------------*/
gertk 0:28557a4d2215 1434 if ((strncmp("R:",(char *)command_string,2) == 0 ) || (strncmp("R0:",(char *)command_string,3) == 0 ) || (strncmp("RENAME:",(char *)command_string,7) == 0 ) || (strncmp("RENAME0:",(char *)command_string,8) == 0 )) /*check the beginning of the string)*/
gertk 0:28557a4d2215 1435 {
gertk 0:28557a4d2215 1436 SplitStringOn_Sign(':', command_string, filename_string);
gertk 0:28557a4d2215 1437 SplitStringOn_Sign('=', filename_string, oldfilename_string);
gertk 0:28557a4d2215 1438 file_status = D64SeekFile(oldfilename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1439 if (file_status == FILE_PRESENT) /*although the '=0' has to be given in the command, we do not check for it*/
gertk 0:28557a4d2215 1440 {
gertk 0:28557a4d2215 1441 print_device_status(" RENAMING.. ");
gertk 0:28557a4d2215 1442 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 1443 D64RenameDirEntry(filename_string, dirtrack, dirsector, direntry);
gertk 0:28557a4d2215 1444 SetErrorCode(0,LED_OFF); /*we exit without error*/
gertk 0:28557a4d2215 1445 }
gertk 0:28557a4d2215 1446 else
gertk 0:28557a4d2215 1447 {
gertk 0:28557a4d2215 1448 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1449 FreeIEC(); /*BUT... since there's no use in receiving data we cannot process, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1450 }
gertk 0:28557a4d2215 1451 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1452 }
gertk 0:28557a4d2215 1453
gertk 0:28557a4d2215 1454
gertk 0:28557a4d2215 1455 /*----------------------------------------*/
gertk 0:28557a4d2215 1456 /* INITIALIZE - re-read the BAM from disk */
gertk 0:28557a4d2215 1457 /* Abbreviation: I */
gertk 0:28557a4d2215 1458 /* Syntax: "INITIALIZE" */
gertk 0:28557a4d2215 1459 /*----------------------------------------*/
gertk 0:28557a4d2215 1460 /*Currently, this command is not supported */
gertk 0:28557a4d2215 1461
gertk 0:28557a4d2215 1462
gertk 0:28557a4d2215 1463 /*----------------------------------------------------*/
gertk 0:28557a4d2215 1464 /* VALIDATE - Check and Fix Disk Consistency */
gertk 0:28557a4d2215 1465 /* Abbreviation: V */
gertk 0:28557a4d2215 1466 /* Syntax: "VALIDATE" */
gertk 0:28557a4d2215 1467 /*----------------------------------------------------*/
gertk 0:28557a4d2215 1468 /*Currently, this command is not supported */
gertk 0:28557a4d2215 1469 /*Validate will fix inconsistencies that can be caused by files that where opened but never closed. Beware: Validate also erases all random files! */
gertk 0:28557a4d2215 1470
gertk 0:28557a4d2215 1471
gertk 0:28557a4d2215 1472 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1473 /* 'C' = COPY - Create a copy of a file on the same disk */
gertk 0:28557a4d2215 1474 /* Syntax: "COPY:<destfile>=<sourcefile>" or "COPY:<destfile>=<sourcefile1>, <sourcefile2>, ..."*/
gertk 0:28557a4d2215 1475 /* If several source files are listed, than the destination file will contain the concatenated contents of all source files. */
gertk 0:28557a4d2215 1476 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1477 if ((strncmp("C:",(char *)command_string,2) == 0 ) || (strncmp("C0:",(char *)command_string,3) == 0 ) || (strncmp("COPY:",(char *)command_string,5) == 0 ) || (strncmp("COPY0:",(char *)command_string,6) == 0 )) /*check the beginning of the string)*/
gertk 0:28557a4d2215 1478 {
gertk 0:28557a4d2215 1479 SplitStringOn_Sign(':', command_string, filename_string);
gertk 0:28557a4d2215 1480 SplitStringOn_Sign('=', filename_string, oldfilename_string);
gertk 0:28557a4d2215 1481 file_status = D64SeekFile(oldfilename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1482 if (file_status == FILE_PRESENT)
gertk 0:28557a4d2215 1483 {
gertk 0:28557a4d2215 1484 print_device_status(" COPYING... ");
gertk 0:28557a4d2215 1485 CopyD64File(track, sector, blocksize);
gertk 0:28557a4d2215 1486 }
gertk 0:28557a4d2215 1487 else
gertk 0:28557a4d2215 1488 {
gertk 0:28557a4d2215 1489 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1490 FreeIEC(); /*BUT... since there's no use in receiving data we cannot process, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1491 }
gertk 0:28557a4d2215 1492 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1493 }
gertk 0:28557a4d2215 1494
gertk 0:28557a4d2215 1495 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1496 /* 'M-W' = memory write command */
gertk 0:28557a4d2215 1497 /* Syntax: OPEN 15,8,15,"M-W"CHR$(lowbyteaddr)CHR$(highbyteaddr)CHR$(numberofmemorylocations)CHR$(data)CHR$(data)CHR$(data):CLOSE 1<RETURN> */
gertk 0:28557a4d2215 1498 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1499 if ((strncmp("M-W",(char *)command_string,3) == 0 )) // || (strncmp("M-W:", command_string, 4) == 0 )) /*check the COMPLETE string*/
gertk 0:28557a4d2215 1500 {
gertk 0:28557a4d2215 1501 if((command_string[3] == 119) && (command_string[4] == 0) && (command_string[5] == 2))
gertk 0:28557a4d2215 1502 {
gertk 0:28557a4d2215 1503 if((command_string[6] - 32) == (command_string[7] - 64)) /*check for new device address*/
gertk 0:28557a4d2215 1504 {
gertk 0:28557a4d2215 1505 devicenumber = command_string[7] - 64; /*the new IEC device address of this device*/
gertk 0:28557a4d2215 1506 print_device_status(" NEW DEVICE# ");
gertk 0:28557a4d2215 1507 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 1508 print_D64_TSB(0,0,0,0); /*update display with the new device address*/
gertk 0:28557a4d2215 1509 SetErrorCode(0,LED_OFF); /*we exit without error*/
gertk 0:28557a4d2215 1510 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1511 }
gertk 0:28557a4d2215 1512 }
gertk 0:28557a4d2215 1513 }
gertk 0:28557a4d2215 1514
gertk 0:28557a4d2215 1515 /*--------------------------------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1516 /* 'B-P' = buffer pointer command (i.o.w. Set the buffer pointer used by CHANNEL ??? to point to BYTE ??? */
gertk 0:28557a4d2215 1517 /* Syntax: OPEN 15,8,15,"B-P:";channel;byte:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1518 /* Example: OPEN 15,8,15,"B-P:";5;2:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1519 /* Example: OPEN 15,8,15,"B-P";5;2:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1520 /* Example: OPEN 15,8,15,"B-P 5 2":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1521 /*--------------------------------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1522 if ((strncmp("B-P",(char *)command_string,3) == 0 )) /*check the string*/
gertk 0:28557a4d2215 1523 {
gertk 0:28557a4d2215 1524 string_pntr = 0;
gertk 0:28557a4d2215 1525 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_1); /*search for the 1st number: channel*/
gertk 0:28557a4d2215 1526 if (string_pntr_2!=FALSE)
gertk 0:28557a4d2215 1527 {
gertk 0:28557a4d2215 1528 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1529 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_2); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1530 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1531 {
gertk 0:28557a4d2215 1532 DOS_channel[value_1].buffer_pointer = value_2; /*the BufferPointer of this channel (used when reading/writing the connected buffer), needs to be set to value_2*/
gertk 0:28557a4d2215 1533 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1534 printf("\r\nB-P command, channel:%02d, BP:%03d",value_1,DOS_channel[DOS_channel[value_1].used_buffer].buffer_pointer);
gertk 0:28557a4d2215 1535 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1536 }
gertk 0:28557a4d2215 1537 }
gertk 0:28557a4d2215 1538 }
gertk 0:28557a4d2215 1539
gertk 0:28557a4d2215 1540
gertk 0:28557a4d2215 1541 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1542 /* 'B-R' = USER-command 1 (254 bytes, byte 0-1 are skipped) */
gertk 0:28557a4d2215 1543 /* Syntax: OPEN 15,8,15,"B-R"channel;drive;track;sector":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1544 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1545 if ((strncmp("B-R",(char *)command_string,3) == 0 )) /*check the string*/
gertk 0:28557a4d2215 1546 {
gertk 0:28557a4d2215 1547 string_pntr = 2; /*whatever the command, skip the first 2 characters in searching for the first number. Otherwise the 1 from U1 might be recognised as a value, which it is not*/
gertk 0:28557a4d2215 1548 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_1); /*search for the 1st number: channel*/
gertk 0:28557a4d2215 1549 if (string_pntr_2!=FALSE)
gertk 0:28557a4d2215 1550 {
gertk 0:28557a4d2215 1551 if (DOS_channel[value_1].used_buffer!=255) /*check if the specified channel has been connected to a buffer, if not ignore the rest of the command*/
gertk 0:28557a4d2215 1552 {
gertk 0:28557a4d2215 1553 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1554 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_2); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1555 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1556 {
gertk 0:28557a4d2215 1557 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1558 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_3); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1559 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1560 {
gertk 0:28557a4d2215 1561 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1562 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_4); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1563 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1564 {
gertk 0:28557a4d2215 1565 DOS_channel[value_1].track = value_3; /*we have all the info we need, so save this info the the appropriate registers and we're done*/
gertk 0:28557a4d2215 1566 DOS_channel[value_1].sector = value_4; /*save track and sector info*/
gertk 0:28557a4d2215 1567 D64BlockRead_new(DOS_channel[value_1].used_buffer,value_3,value_4); /*read the desired block of the D64 image and store it into the desired buffer*/
gertk 0:28557a4d2215 1568
gertk 0:28557a4d2215 1569 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1570 printf("\r\nB-R command, t:%03d, s:%03d",DOS_channel[value_1].track,DOS_channel[value_1].sector);
gertk 0:28557a4d2215 1571 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1572 }
gertk 0:28557a4d2215 1573 }
gertk 0:28557a4d2215 1574 }
gertk 0:28557a4d2215 1575 }
gertk 0:28557a4d2215 1576 }
gertk 0:28557a4d2215 1577 }
gertk 0:28557a4d2215 1578
gertk 0:28557a4d2215 1579
gertk 0:28557a4d2215 1580 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1581 /* 'U1' or 'UA' = USER-command 1 (block read, 256 bytes) */
gertk 0:28557a4d2215 1582 /* Syntax: OPEN 15,8,15,"U1:"channel;drive;track;sector":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1583 /* Example: OPEN 15,8,15,"U1:";5;0;18;1:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1584 /* Example: OPEN 15,8,15,"U1";5;0;18;1:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1585 /* Example: OPEN 15,8,15,"U1 5 0 18 1":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1586 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1587 if (((strncmp("UA",(char *)command_string,2) == 0 )) || ((strncmp("U1",(char *)command_string,2) == 0 ))) /*check the string*/
gertk 0:28557a4d2215 1588 {
gertk 0:28557a4d2215 1589 string_pntr = 2; /*whatever the command, skip the first 2 characters in searching for the first number. Otherwise the 1 from U1 might be recognised as a value, which it is not*/
gertk 0:28557a4d2215 1590 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_1); /*search for the 1st number: channel*/
gertk 0:28557a4d2215 1591 if (string_pntr_2!=FALSE)
gertk 0:28557a4d2215 1592 {
gertk 0:28557a4d2215 1593 if (DOS_channel[value_1].used_buffer!=255) /*check if the specified channel has been connected to a buffer, if not ignore the rest of the command*/
gertk 0:28557a4d2215 1594 {
gertk 0:28557a4d2215 1595 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1596 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_2); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1597 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1598 {
gertk 0:28557a4d2215 1599 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1600 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_3); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1601 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1602 {
gertk 0:28557a4d2215 1603 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1604 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_4); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1605 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1606 {
gertk 0:28557a4d2215 1607 DOS_channel[value_1].track = value_3; /*we have all the info we need, so save this info the the appropriate registers and we're done*/
gertk 0:28557a4d2215 1608 DOS_channel[value_1].sector = value_4; /*save track and sector info*/
gertk 0:28557a4d2215 1609 D64BlockRead_new(DOS_channel[value_1].used_buffer,value_3,value_4); /*read the desired block of the D64 image and store it into the desired buffer*/
gertk 0:28557a4d2215 1610
gertk 0:28557a4d2215 1611 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1612 printf("\r\nU1 command, t:%03d, s:%03d",DOS_channel[value_1].track,DOS_channel[value_1].sector);
gertk 0:28557a4d2215 1613 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1614 }
gertk 0:28557a4d2215 1615 }
gertk 0:28557a4d2215 1616 }
gertk 0:28557a4d2215 1617 }
gertk 0:28557a4d2215 1618 }
gertk 0:28557a4d2215 1619 }
gertk 0:28557a4d2215 1620
gertk 0:28557a4d2215 1621
gertk 0:28557a4d2215 1622 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1623 /* 'B-W' = USER-command 2 (254 bytes block write) */
gertk 0:28557a4d2215 1624 /* Syntax: OPEN 15,8,15,"U2:"channel;drive;track;sector":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1625 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1626 if ((strncmp("B-W",(char *)command_string,3) == 0 ))
gertk 0:28557a4d2215 1627 {
gertk 0:28557a4d2215 1628 string_pntr = 2; /*whatever the command, skip the first 2 characters in searching for the first number. Otherwise the 2 from U2 might be recognised as a value, which it is not*/
gertk 0:28557a4d2215 1629 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_1); /*search for the 1st number: channel*/
gertk 0:28557a4d2215 1630 if (string_pntr_2!=FALSE)
gertk 0:28557a4d2215 1631 {
gertk 0:28557a4d2215 1632 if (DOS_channel[value_1].used_buffer!=255) /*check if the specified channel has been connected to a buffer, if not ignore the rest of the command*/
gertk 0:28557a4d2215 1633 {
gertk 0:28557a4d2215 1634 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1635 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_2); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1636 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1637 {
gertk 0:28557a4d2215 1638 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1639 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_3); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1640 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1641 {
gertk 0:28557a4d2215 1642 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1643 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_4); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1644 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1645 {
gertk 0:28557a4d2215 1646 DOS_channel[value_1].track = value_3; /*we have all the info we need, so save this info the the appropriate registers and we're done*/
gertk 0:28557a4d2215 1647 DOS_channel[value_1].sector = value_4; /*save track and sector info*/
gertk 0:28557a4d2215 1648 D64BlockWrite_new(DOS_channel[value_1].used_buffer,value_3,value_4); /*write the desired block of the D64 image*/
gertk 0:28557a4d2215 1649
gertk 0:28557a4d2215 1650 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1651 printf("\r\nB-W command, t:%03d, s:%03d",DOS_channel[value_1].track,DOS_channel[value_1].sector);
gertk 0:28557a4d2215 1652 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1653 }
gertk 0:28557a4d2215 1654 }
gertk 0:28557a4d2215 1655 }
gertk 0:28557a4d2215 1656 }
gertk 0:28557a4d2215 1657 }
gertk 0:28557a4d2215 1658 }
gertk 0:28557a4d2215 1659
gertk 0:28557a4d2215 1660 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1661 /* 'U2' or 'UB' = USER-command 2 (256 byte block write) */
gertk 0:28557a4d2215 1662 /* Syntax: OPEN 15,8,15,"U2:"channel;drive;track;sector":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1663 /* Example: OPEN 15,8,15,"U2:";5;0;18;1:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1664 /* Example: OPEN 15,8,15,"U2";5;0;18;1:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1665 /* Example: OPEN 15,8,15,"U2 5 0 18 1":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1666 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1667
gertk 0:28557a4d2215 1668 if (((strncmp("U2",(char *)command_string,2) == 0 )) || ((strncmp("UB",(char *)command_string,2) == 0 ))) /*check the string*/
gertk 0:28557a4d2215 1669 {
gertk 0:28557a4d2215 1670 string_pntr = 2; /*whatever the command, skip the first 2 characters in searching for the first number. Otherwise the 2 from U2 might be recognised as a value, which it is not*/
gertk 0:28557a4d2215 1671 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_1); /*search for the 1st number: channel*/
gertk 0:28557a4d2215 1672 if (string_pntr_2!=FALSE)
gertk 0:28557a4d2215 1673 {
gertk 0:28557a4d2215 1674 if (DOS_channel[value_1].used_buffer!=255) /*check if the specified channel has been connected to a buffer, if not ignore the rest of the command*/
gertk 0:28557a4d2215 1675 {
gertk 0:28557a4d2215 1676 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1677 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_2); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1678 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1679 {
gertk 0:28557a4d2215 1680 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1681 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_3); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1682 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1683 {
gertk 0:28557a4d2215 1684 string_pntr = string_pntr + string_pntr_2;
gertk 0:28557a4d2215 1685 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_4); /*search for the 2nd number: channel*/
gertk 0:28557a4d2215 1686 if (string_pntr_2 != FALSE)
gertk 0:28557a4d2215 1687 {
gertk 0:28557a4d2215 1688 DOS_channel[value_1].track = value_3; /*we have all the info we need, so save this info the the appropriate registers and we're done*/
gertk 0:28557a4d2215 1689 DOS_channel[value_1].sector = value_4; /*save track and sector info*/
gertk 0:28557a4d2215 1690 D64BlockWrite_new(DOS_channel[value_1].used_buffer,value_3,value_4); /*write the desired block of the D64 image*/
gertk 0:28557a4d2215 1691
gertk 0:28557a4d2215 1692 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1693 printf("\r\nU2 command, t:%03d, s:%03d",DOS_channel[value_1].track,DOS_channel[value_1].sector);
gertk 0:28557a4d2215 1694 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1695 }
gertk 0:28557a4d2215 1696 }
gertk 0:28557a4d2215 1697 }
gertk 0:28557a4d2215 1698 }
gertk 0:28557a4d2215 1699 }
gertk 0:28557a4d2215 1700 }
gertk 0:28557a4d2215 1701
gertk 0:28557a4d2215 1702
gertk 0:28557a4d2215 1703 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1704 /* 'UI-' = USER-command speed up drive by 25% */
gertk 0:28557a4d2215 1705 /* Syntax: OPEN 15,8,15,"UI-":CLOSE 1<RETURN> */
gertk 0:28557a4d2215 1706 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1707 if (strncmp("UI-",(char *)command_string,3) == 0 ) /*check the string*/
gertk 0:28557a4d2215 1708 {
gertk 0:28557a4d2215 1709 print_device_status(" VIC20-MODE ");
gertk 0:28557a4d2215 1710 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 1711 SetIEC_timings(TIMINGS_VIC20); /*set timings according the VIC-20 settings (25% faster mode)*/
gertk 0:28557a4d2215 1712 VIC20_mode = TRUE; /*raise flag*/
gertk 0:28557a4d2215 1713 // SaveSettingsToEEPROM(); /*store new setting*/
gertk 0:28557a4d2215 1714 SetErrorCode(0,LED_OFF); /*we exit without error*/
gertk 0:28557a4d2215 1715 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1716 }
gertk 0:28557a4d2215 1717
gertk 0:28557a4d2215 1718 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1719 /* 'UI+' = USER-command restore drive speed to normal */
gertk 0:28557a4d2215 1720 /* Syntax: OPEN 15,8,15,"UI+":CLOSE 1<RETURN> */
gertk 0:28557a4d2215 1721 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1722 if (strncmp("UI+",(char *)command_string,3) == 0 ) /*check the string*/
gertk 0:28557a4d2215 1723 {
gertk 0:28557a4d2215 1724 print_device_status(" C64-MODE ");
gertk 0:28557a4d2215 1725 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 1726 SetIEC_timings(TIMINGS_DEFAULT); /*set timings according the default settings (C64 compatible mode)*/
gertk 0:28557a4d2215 1727 VIC20_mode = FALSE; /*raise flag*/
gertk 0:28557a4d2215 1728 // SaveSettingsToEEPROM(); /*store new setting*/
gertk 0:28557a4d2215 1729 SetErrorCode(0,LED_OFF); /*we exit without error*/
gertk 0:28557a4d2215 1730 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1731 }
gertk 0:28557a4d2215 1732
gertk 0:28557a4d2215 1733 /*------------------------------*/
gertk 0:28557a4d2215 1734 /* In case none of the above... */
gertk 0:28557a4d2215 1735 /*------------------------------*/
gertk 0:28557a4d2215 1736 //to do:syntax error
gertk 0:28557a4d2215 1737 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1738 // print_device_status(" "); /*remove the 'action' message from the display*/
gertk 0:28557a4d2215 1739 }
gertk 0:28557a4d2215 1740 }
gertk 0:28557a4d2215 1741 }
gertk 0:28557a4d2215 1742
gertk 0:28557a4d2215 1743 void DataHandler(void)
gertk 0:28557a4d2215 1744 {
gertk 0:28557a4d2215 1745 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1746 // printf("\r\nDATAHANDLER"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1747 // printf("\r\nData, channel %d",channel); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1748 // printf("\r\ncmd_string:%s",command_string); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1749 // printf("\r\nchannel:%d",channel); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1750 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1751
gertk 0:28557a4d2215 1752 switch(channel)
gertk 0:28557a4d2215 1753 { /*-------------------------------------------*/
gertk 0:28557a4d2215 1754 case 0: /* this channel is used for reading of files */
gertk 0:28557a4d2215 1755 { /*-------------------------------------------*/
gertk 0:28557a4d2215 1756 if ((DiskState == NO_CARD) || (DiskState == INVALID_POINTER)) /*escape sequence when no D64 is selected or no card is present*/
gertk 0:28557a4d2215 1757 {
gertk 0:28557a4d2215 1758 DOS_channel[channel].next_action = ABORT_SENDING;
gertk 0:28557a4d2215 1759 }
gertk 0:28557a4d2215 1760
gertk 0:28557a4d2215 1761 switch(DOS_channel[channel].next_action)
gertk 0:28557a4d2215 1762 {
gertk 0:28557a4d2215 1763 case ABORT_SENDING: /*file not found situation*/
gertk 0:28557a4d2215 1764 {
gertk 0:28557a4d2215 1765 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1766 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 1767 FreeIEC(); /*BUT... since there's nothing to send, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1768 break;
gertk 0:28557a4d2215 1769 }
gertk 0:28557a4d2215 1770
gertk 0:28557a4d2215 1771 case CARD_DIRECTORY:
gertk 0:28557a4d2215 1772 {
gertk 0:28557a4d2215 1773 print_device_status(" LOADING... ");
gertk 0:28557a4d2215 1774 CardDirectory(); /*send the MMC/SD_card Directory information*/
gertk 0:28557a4d2215 1775 print_device_status(" ");
gertk 0:28557a4d2215 1776 break;
gertk 0:28557a4d2215 1777 }
gertk 0:28557a4d2215 1778
gertk 0:28557a4d2215 1779 case DIRECTORY:
gertk 0:28557a4d2215 1780 {
gertk 0:28557a4d2215 1781 print_device_status(" LOADING DIR. ");
gertk 0:28557a4d2215 1782 D64Directory(); /*send ImageDirectory information of the selected drive*/
gertk 0:28557a4d2215 1783 print_device_status(" ");
gertk 0:28557a4d2215 1784 break;
gertk 0:28557a4d2215 1785 }
gertk 0:28557a4d2215 1786
gertk 0:28557a4d2215 1787 case RD_FILE_FROM_ROOT:
gertk 0:28557a4d2215 1788 {
gertk 0:28557a4d2215 1789 if (file_status != FALSE)
gertk 0:28557a4d2215 1790 {
gertk 0:28557a4d2215 1791 print_device_status(" LOADING... ");
gertk 0:28557a4d2215 1792 OutputToRS232();
gertk 0:28557a4d2215 1793 printf("%s",command_string); /*print filename on first line of LCD*/
gertk 0:28557a4d2215 1794 OutputToLCD();
gertk 0:28557a4d2215 1795 LoadFileFromCard(&file);
gertk 0:28557a4d2215 1796 print_device_status(" ");
gertk 0:28557a4d2215 1797 }
gertk 0:28557a4d2215 1798 else
gertk 0:28557a4d2215 1799 {
gertk 0:28557a4d2215 1800 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1801 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 1802 FreeIEC(); /*BUT... since there's nothing to send, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1803 DOS_channel[channel].next_action = ABORT_SENDING;
gertk 0:28557a4d2215 1804 }
gertk 0:28557a4d2215 1805 break;
gertk 0:28557a4d2215 1806 }
gertk 0:28557a4d2215 1807
gertk 0:28557a4d2215 1808 case RD_FILE:
gertk 0:28557a4d2215 1809 {
gertk 0:28557a4d2215 1810 if (file_status == FILE_PRESENT)
gertk 0:28557a4d2215 1811 {
gertk 0:28557a4d2215 1812 print_device_status(" LOADING... ");
gertk 0:28557a4d2215 1813 OutputToRS232();
gertk 0:28557a4d2215 1814 printf("%s",command_string); /*print filename to LCD*/
gertk 0:28557a4d2215 1815 OutputToLCD();
gertk 0:28557a4d2215 1816 LoadD64File(track, sector, blocksize); /*load the actual file from the D64-file*/
gertk 0:28557a4d2215 1817 print_device_status(" ");
gertk 0:28557a4d2215 1818 }
gertk 0:28557a4d2215 1819 else
gertk 0:28557a4d2215 1820 {
gertk 0:28557a4d2215 1821 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1822 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 1823 FreeIEC(); /*BUT... since there's nothing to send, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1824 DOS_channel[channel].next_action = ABORT_SENDING;
gertk 0:28557a4d2215 1825 print_device_status(" ");
gertk 0:28557a4d2215 1826 }
gertk 0:28557a4d2215 1827 break;
gertk 0:28557a4d2215 1828 }
gertk 0:28557a4d2215 1829 }
gertk 0:28557a4d2215 1830 break;
gertk 0:28557a4d2215 1831 }
gertk 0:28557a4d2215 1832
gertk 0:28557a4d2215 1833 /*-------------------------------------------*/
gertk 0:28557a4d2215 1834 case 1: /* this channel is used for writing of files */
gertk 0:28557a4d2215 1835 { /*-------------------------------------------*/
gertk 0:28557a4d2215 1836 if ((DiskState == NO_CARD) || (DiskState == INVALID_POINTER)) /*escape sequence when no D64 is selected or no card is present*/
gertk 0:28557a4d2215 1837 DOS_channel[channel].next_action = ABORT_RECEIVING;
gertk 0:28557a4d2215 1838
gertk 0:28557a4d2215 1839 switch(DOS_channel[channel].next_action)
gertk 0:28557a4d2215 1840 {
gertk 0:28557a4d2215 1841 case ABORT_RECEIVING: /*file not found situation*/
gertk 0:28557a4d2215 1842 {
gertk 0:28557a4d2215 1843 SetErrorCode(28,LED_ERROR);/*write error (a message that normally would not be possible but was created for completeness in the DOS. Now we can use it...)*/
gertk 0:28557a4d2215 1844 FreeIEC(); /*BUT... since there's no use in receiving data we cannot process, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1845 break;
gertk 0:28557a4d2215 1846 }
gertk 0:28557a4d2215 1847
gertk 0:28557a4d2215 1848 case WR_FILE_TO_ROOT:
gertk 0:28557a4d2215 1849 {
gertk 0:28557a4d2215 1850 SetErrorCode(28,LED_ERROR);/*write error (a message that normally would not be possible but was created for completeness in the DOS. Now we can use it...)*/
gertk 0:28557a4d2215 1851 FreeIEC(); /*BUT... since there's no use in receiving data we cannot process, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1852 DOS_channel[channel].next_action = ABORT_RECEIVING;
gertk 0:28557a4d2215 1853 break;
gertk 0:28557a4d2215 1854 }
gertk 0:28557a4d2215 1855
gertk 0:28557a4d2215 1856 case WR_FILE:
gertk 0:28557a4d2215 1857 {
gertk 0:28557a4d2215 1858 if (file_status == FILE_NOT_PRESENT)
gertk 0:28557a4d2215 1859 {
gertk 0:28557a4d2215 1860 print_device_status(" SAVING... ");
gertk 0:28557a4d2215 1861 OutputToRS232();
gertk 0:28557a4d2215 1862 printf("%s",command_string); /*print filename on first line of LCD*/
gertk 0:28557a4d2215 1863 OutputToLCD();
gertk 0:28557a4d2215 1864 SaveD64File(); /*save the actual file to the D64-file*/
gertk 0:28557a4d2215 1865 print_device_status(" ");
gertk 0:28557a4d2215 1866 }
gertk 0:28557a4d2215 1867 else
gertk 0:28557a4d2215 1868 {
gertk 0:28557a4d2215 1869 SetErrorCode(63,LED_ERROR); /*file exists*/
gertk 0:28557a4d2215 1870 FreeIEC(); /*BUT... since there's no use in receiving data we cannot process, free the bus and the computer will detect this as an valid error situation*/
gertk 0:28557a4d2215 1871 DOS_channel[channel].next_action = ABORT_RECEIVING;
gertk 0:28557a4d2215 1872 }
gertk 0:28557a4d2215 1873 break;
gertk 0:28557a4d2215 1874 }
gertk 0:28557a4d2215 1875
gertk 0:28557a4d2215 1876 case REPLACE_FILE:
gertk 0:28557a4d2215 1877 {
gertk 0:28557a4d2215 1878 if (file_status == FILE_PRESENT)
gertk 0:28557a4d2215 1879 {
gertk 0:28557a4d2215 1880 print_device_status(" REPLACING.. ");
gertk 0:28557a4d2215 1881 D64ScratchDirEntry(dirtrack, dirsector, direntry); /*remove entry*/
gertk 0:28557a4d2215 1882 files_scratched = 1;
gertk 0:28557a4d2215 1883 strcpy((char *)command_string,(char *) filename_string); /*make sure the save routine uses the correct data, the command without the @0:*/
gertk 0:28557a4d2215 1884 SaveD64File(); /*save the actual file to the D64-file*/
gertk 0:28557a4d2215 1885 print_device_status(" ");
gertk 0:28557a4d2215 1886 }
gertk 0:28557a4d2215 1887 break;
gertk 0:28557a4d2215 1888 }
gertk 0:28557a4d2215 1889 }
gertk 0:28557a4d2215 1890 break;
gertk 0:28557a4d2215 1891 }
gertk 0:28557a4d2215 1892
gertk 0:28557a4d2215 1893 case 2:; /*these channels are used for...*/
gertk 0:28557a4d2215 1894 case 3:;
gertk 0:28557a4d2215 1895 case 4:;
gertk 0:28557a4d2215 1896 case 5:;
gertk 0:28557a4d2215 1897 case 6:;
gertk 0:28557a4d2215 1898 case 7:;
gertk 0:28557a4d2215 1899 case 8:;
gertk 0:28557a4d2215 1900 case 9:;
gertk 0:28557a4d2215 1901 case 10:;
gertk 0:28557a4d2215 1902 case 11:;
gertk 0:28557a4d2215 1903 case 12:;
gertk 0:28557a4d2215 1904 case 13:;
gertk 0:28557a4d2215 1905 case 14:
gertk 0:28557a4d2215 1906 {
gertk 0:28557a4d2215 1907 if (IEC_state == ACTIVE_TALK) /*if the drive is expected to TALK... speak now*/
gertk 0:28557a4d2215 1908 {
gertk 0:28557a4d2215 1909 EOI = FALSE;
gertk 0:28557a4d2215 1910 LED_GREEN = 1; /*drive LED-ON*/
gertk 0:28557a4d2215 1911 disable_ATN_interrupt(); /*since we are a talker now and the listener may interrupt us with an ATN, we must disable interrupts on ATN line, otherwise we create a lock up situation (ATN interrupt pulls data-line low)*/
gertk 0:28557a4d2215 1912 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 1913 while(IEC_ATN() == 1) /* the listener (computer) indicates (by making ATN=0) it requires no more data (for now)*/
gertk 0:28557a4d2215 1914 {
gertk 0:28557a4d2215 1915 if (command_string[0] == '#') /*if the user's/computer's last command specified opening a buffer, then handle accordingly...*/
gertk 0:28557a4d2215 1916 {
gertk 0:28557a4d2215 1917 command_string[0] = 0; /*make sure the command string is discarded to prevent looping*/
gertk 0:28557a4d2215 1918 IEC_send(DOS_channel[channel].used_buffer); /*send the buffer number of the just opened buffer*/
gertk 0:28557a4d2215 1919 }
gertk 0:28557a4d2215 1920 else
gertk 0:28557a4d2215 1921 {
gertk 0:28557a4d2215 1922 // if (DOS_channel[channel].buffer_pointer == 255) /*when the last byte is going to been send*/
gertk 0:28557a4d2215 1923 // {
gertk 0:28557a4d2215 1924 // EOI = TRUE; /*indicate that this is the last byte of the buffer*/
gertk 0:28557a4d2215 1925 // }
gertk 0:28557a4d2215 1926 IEC_send(DOS_buffer[DOS_channel[channel].used_buffer].buffer[DOS_channel[channel].buffer_pointer]); /*get the data from the buffer connected to this channel at the bufferposition as pointed to by the buffer-pointer*/
gertk 0:28557a4d2215 1927 DOS_channel[channel].buffer_pointer++; /*increment buffer pointer by one*/
gertk 0:28557a4d2215 1928 }
gertk 0:28557a4d2215 1929 /*wait for the listener (computer) to release the data-line (ready to receive data), this may take forever... (according the IEC-bus definition)*/
gertk 0:28557a4d2215 1930 while (IEC_DATA() == 0); /*data is released when new data can be handled by the listener (the computer at this stage)*/
gertk 0:28557a4d2215 1931 /*OR*/
gertk 0:28557a4d2215 1932 /*data is released when ATN goes low because NO MORE data is required*/
gertk 0:28557a4d2215 1933 }
gertk 0:28557a4d2215 1934 IEC_undoturnaround();
gertk 0:28557a4d2215 1935 enable_ATN_interrupt(); /*all is back to normal, enable interrupts on ATN line*/
gertk 0:28557a4d2215 1936 SetErrorCode(0,LED_OFF); /*error-code is 0, LED is OFF*/
gertk 0:28557a4d2215 1937 }
gertk 0:28557a4d2215 1938
gertk 0:28557a4d2215 1939 if (IEC_state == ACTIVE_LISTEN) /*if the drive is expected to listen then... we're all ear*/
gertk 0:28557a4d2215 1940 {
gertk 0:28557a4d2215 1941 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1942 printf("\r\ntp10 active listen"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1943 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1944 }
gertk 0:28557a4d2215 1945
gertk 0:28557a4d2215 1946 break;
gertk 0:28557a4d2215 1947 }
gertk 0:28557a4d2215 1948
gertk 0:28557a4d2215 1949 /*---------------------------------------*/
gertk 0:28557a4d2215 1950 case 15: /* this channel is used for DOS-commands */
gertk 0:28557a4d2215 1951 { /*---------------------------------------*/
gertk 0:28557a4d2215 1952 if (IEC_state == ACTIVE_TALK)
gertk 0:28557a4d2215 1953 // if ((IEC_state == ACTIVE_TALK) && (DOS_channel[15].channel_in_use == TRUE))
gertk 0:28557a4d2215 1954 {
gertk 0:28557a4d2215 1955 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1956 /* Reading the error channel is a special situation */
gertk 0:28557a4d2215 1957 /* Example: OPEN 15,8,15<RETURN> */
gertk 0:28557a4d2215 1958 /* INPUT#15, A, B$, C, D<RETURN> */
gertk 0:28557a4d2215 1959 /* CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1960 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1961 SendErrorMessage(); /*this is handled immediately*/
gertk 0:28557a4d2215 1962 }
gertk 0:28557a4d2215 1963 else
gertk 0:28557a4d2215 1964 {
gertk 0:28557a4d2215 1965 DOS_channel[channel].channel_in_use = TRUE; /*claim this channel*/
gertk 0:28557a4d2215 1966 WaitForString(command_string, TRUE); /*wait for an operator string that ends with an EOI*/
gertk 0:28557a4d2215 1967 }
gertk 0:28557a4d2215 1968
gertk 0:28557a4d2215 1969 break;
gertk 0:28557a4d2215 1970 }
gertk 0:28557a4d2215 1971 }
gertk 0:28557a4d2215 1972 }
gertk 0:28557a4d2215 1973
gertk 0:28557a4d2215 1974 /*****************************************************************************************************************/
gertk 0:28557a4d2215 1975 /*The following routine will check for the PCB type by testing for the capacitor value on port RA0*/
gertk 0:28557a4d2215 1976 /*During this testing procedure no buttons may be pressed*/
gertk 0:28557a4d2215 1977 void AutoDetectPcbType(void)
gertk 0:28557a4d2215 1978 {
gertk 0:28557a4d2215 1979
gertk 0:28557a4d2215 1980 PCB_type = v1_1; /*typical timer value: 10771 - 10835*/
gertk 0:28557a4d2215 1981 }
gertk 0:28557a4d2215 1982
gertk 0:28557a4d2215 1983 void NoCardMenu(void)
gertk 0:28557a4d2215 1984 {
gertk 0:28557a4d2215 1985 // Lcd_XY_address(0,0);
gertk 0:28557a4d2215 1986 putch('o');
gertk 0:28557a4d2215 1987 // Lcd_XY_address(0,2);
gertk 0:28557a4d2215 1988 putch(0x16);
gertk 0:28557a4d2215 1989 // Lcd_XY_address(0,4);
gertk 0:28557a4d2215 1990 putch('i');
gertk 0:28557a4d2215 1991 while(ReadButtons())
gertk 0:28557a4d2215 1992 {
gertk 0:28557a4d2215 1993 if (button_prev == TRUE) /*decrease contrast (lighter)*/
gertk 0:28557a4d2215 1994 { /*---------------------------*/
gertk 0:28557a4d2215 1995 setting_contrast--;
gertk 0:28557a4d2215 1996 if (setting_contrast < 0x81)
gertk 0:28557a4d2215 1997 {
gertk 0:28557a4d2215 1998 setting_contrast = 0x81; /*lower limit*/
gertk 0:28557a4d2215 1999 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2000 printf(" Min. reached ");
gertk 0:28557a4d2215 2001 DelayBigMs(350);
gertk 0:28557a4d2215 2002 }
gertk 0:28557a4d2215 2003 else
gertk 0:28557a4d2215 2004 {
gertk 0:28557a4d2215 2005 // SetContrast(); /*apply new setting*/
gertk 0:28557a4d2215 2006 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2007 // Lcd_ProgressBar((0xff-setting_contrast), 0x81);
gertk 0:28557a4d2215 2008 // SaveSettingsToEEPROM(); /*save value to EEPROM*/
gertk 0:28557a4d2215 2009 DelayBigMs(200);
gertk 0:28557a4d2215 2010 }
gertk 0:28557a4d2215 2011 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 2012 printf("\r\nLCD-Lighter, contrast =%02x",setting_contrast);
gertk 0:28557a4d2215 2013 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2014 }
gertk 0:28557a4d2215 2015
gertk 0:28557a4d2215 2016 if (button_select == TRUE) /*increase contrast (darker)*/
gertk 0:28557a4d2215 2017 { /*--------------------------*/
gertk 0:28557a4d2215 2018 setting_contrast++;
gertk 0:28557a4d2215 2019 if (setting_contrast > 0xFE)
gertk 0:28557a4d2215 2020 {
gertk 0:28557a4d2215 2021 setting_contrast = 0xFE; /*upper limit*/
gertk 0:28557a4d2215 2022 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2023 printf(" Max. reached ");
gertk 0:28557a4d2215 2024 DelayBigMs(350);
gertk 0:28557a4d2215 2025 }
gertk 0:28557a4d2215 2026 else
gertk 0:28557a4d2215 2027 {
gertk 0:28557a4d2215 2028 // SetContrast(); /*apply new setting*/
gertk 0:28557a4d2215 2029 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2030 // Lcd_ProgressBar((0xff-setting_contrast), 0x81);
gertk 0:28557a4d2215 2031 // SaveSettingsToEEPROM(); /*save value to EEPROM*/
gertk 0:28557a4d2215 2032 DelayBigMs(200);
gertk 0:28557a4d2215 2033 }
gertk 0:28557a4d2215 2034 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 2035 printf("\r\nLCD-Darker, contrast =%02x",setting_contrast);
gertk 0:28557a4d2215 2036 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2037 }
gertk 0:28557a4d2215 2038
gertk 0:28557a4d2215 2039 if (button_next == TRUE) /*info button*/
gertk 0:28557a4d2215 2040 {
gertk 0:28557a4d2215 2041 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 2042 printf("\r\nInfo button pressed");
gertk 0:28557a4d2215 2043 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2044 // Lcd_clr();
gertk 0:28557a4d2215 2045 HardWareTestMenu();
gertk 0:28557a4d2215 2046 // Lcd_clr();
gertk 0:28557a4d2215 2047 break;
gertk 0:28557a4d2215 2048 }
gertk 0:28557a4d2215 2049 }
gertk 0:28557a4d2215 2050 }
gertk 0:28557a4d2215 2051
gertk 0:28557a4d2215 2052 void HardWareTestMenu(void)
gertk 0:28557a4d2215 2053 {
gertk 0:28557a4d2215 2054 // Lcd_clr();
gertk 0:28557a4d2215 2055 // Lcd_XY_address(0,0);
gertk 0:28557a4d2215 2056 printf("LED test");
gertk 0:28557a4d2215 2057 // Lcd_XY_address(0,2);
gertk 0:28557a4d2215 2058 printf("IO & settings");
gertk 0:28557a4d2215 2059 // Lcd_XY_address(0,4);
gertk 0:28557a4d2215 2060 printf("Exit");
gertk 0:28557a4d2215 2061 DelayBigMs(1000);
gertk 0:28557a4d2215 2062 while(1)
gertk 0:28557a4d2215 2063 {
gertk 0:28557a4d2215 2064 ReadButtons();
gertk 0:28557a4d2215 2065 if (button_prev == TRUE) /*LED-test routines*/
gertk 0:28557a4d2215 2066 { /*-----------------*/
gertk 0:28557a4d2215 2067 // Lcd_clr();
gertk 0:28557a4d2215 2068 // Lcd_XY_address(5,2);
gertk 0:28557a4d2215 2069 printf("OFF");
gertk 0:28557a4d2215 2070 LED_GREEN = 0;
gertk 0:28557a4d2215 2071 LED_RED = 0;
gertk 0:28557a4d2215 2072 DelayBigMs(2000);
gertk 0:28557a4d2215 2073 // Lcd_XY_address(4,2);
gertk 0:28557a4d2215 2074 printf("green");
gertk 0:28557a4d2215 2075 LED_GREEN = 1;
gertk 0:28557a4d2215 2076 LED_RED = 0;
gertk 0:28557a4d2215 2077 DelayBigMs(2000);
gertk 0:28557a4d2215 2078 // Lcd_XY_address(4,2);
gertk 0:28557a4d2215 2079 printf(" red ");
gertk 0:28557a4d2215 2080 LED_GREEN = 0;
gertk 0:28557a4d2215 2081 LED_RED = 1;
gertk 0:28557a4d2215 2082 DelayBigMs(2000);
gertk 0:28557a4d2215 2083 // Lcd_XY_address(3,2);
gertk 0:28557a4d2215 2084 printf("red+green");
gertk 0:28557a4d2215 2085 LED_GREEN = 1;
gertk 0:28557a4d2215 2086 LED_RED = 1;
gertk 0:28557a4d2215 2087 DelayBigMs(2000);
gertk 0:28557a4d2215 2088 LED_GREEN = 0;
gertk 0:28557a4d2215 2089 LED_RED = 0;
gertk 0:28557a4d2215 2090 break;
gertk 0:28557a4d2215 2091 }
gertk 0:28557a4d2215 2092
gertk 0:28557a4d2215 2093 if (button_select == TRUE) /*IO & settings*/
gertk 0:28557a4d2215 2094 { /*-------------*/
gertk 0:28557a4d2215 2095
gertk 0:28557a4d2215 2096 // Lcd_XY_address(0,4);
gertk 0:28557a4d2215 2097 printf("Contrast:%02X",setting_contrast);
gertk 0:28557a4d2215 2098 // Lcd_XY_address(0,5);
gertk 0:28557a4d2215 2099 printf("PCBtimer:%05d",PCB_type_timer);
gertk 0:28557a4d2215 2100
gertk 0:28557a4d2215 2101 DelayBigMs(3000);
gertk 0:28557a4d2215 2102 break;
gertk 0:28557a4d2215 2103 }
gertk 0:28557a4d2215 2104
gertk 0:28557a4d2215 2105 if (button_next == TRUE) /*Exit-button*/
gertk 0:28557a4d2215 2106 { /*-----------*/
gertk 0:28557a4d2215 2107 break;
gertk 0:28557a4d2215 2108 }
gertk 0:28557a4d2215 2109 }
gertk 0:28557a4d2215 2110 }
gertk 0:28557a4d2215 2111
gertk 0:28557a4d2215 2112
gertk 0:28557a4d2215 2113 /*this routine wait for a card to be inserted, once inserted it will be initialised, when all is OK this routine will exit*/
gertk 0:28557a4d2215 2114 unsigned char CardStatus(void)
gertk 0:28557a4d2215 2115 {
gertk 0:28557a4d2215 2116 unsigned char err_code;
gertk 0:28557a4d2215 2117
gertk 0:28557a4d2215 2118 if(CARD_DETECT == 1)
gertk 0:28557a4d2215 2119 {
gertk 0:28557a4d2215 2120 // Lcd_XY_address(4,1);
gertk 0:28557a4d2215 2121 // Lcd_CharBold();
gertk 0:28557a4d2215 2122 printf("INSERT");
gertk 0:28557a4d2215 2123 // Lcd_XY_address(5,3);
gertk 0:28557a4d2215 2124 printf("CARD");
gertk 0:28557a4d2215 2125 // Lcd_CharNormal();
gertk 0:28557a4d2215 2126 // Lcd_XY_address(0,5);
gertk 0:28557a4d2215 2127 printf(" (20%02d%02d%02d)",RELEASE_VERSION,RELEASE_VERSION_SUB,RELEASE_VERSION_SUB_SUB);
gertk 0:28557a4d2215 2128 DiskState = NO_CARD;
gertk 0:28557a4d2215 2129 return(FALSE);
gertk 0:28557a4d2215 2130 }
gertk 0:28557a4d2215 2131
gertk 0:28557a4d2215 2132 // Lcd_clr();
gertk 0:28557a4d2215 2133 // Lcd_XY_address(0,0);
gertk 0:28557a4d2215 2134 printf("Card detected ");
gertk 0:28557a4d2215 2135
gertk 0:28557a4d2215 2136 //if(WR_PROTECT == 1) /*check if the SD-cards write protect "switch" has been set*/
gertk 0:28557a4d2215 2137 //{
gertk 0:28557a4d2215 2138 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2139 // printf("Card wr. prot.");
gertk 0:28557a4d2215 2140 // DiskState = NO_CARD;
gertk 0:28557a4d2215 2141 // return(FALSE);
gertk 0:28557a4d2215 2142 //}
gertk 0:28557a4d2215 2143
gertk 0:28557a4d2215 2144 DelayS(2); /*do not access card immediatly, wait for card to stabelise*/
gertk 0:28557a4d2215 2145 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2146 printf("Init. card: ");
gertk 0:28557a4d2215 2147 // Lcd_XY_address(0,2); /*set cursor to next line to print error messages*/
gertk 0:28557a4d2215 2148 if (Init_Card_SPI())
gertk 0:28557a4d2215 2149 {
gertk 0:28557a4d2215 2150 DelayS(1); /*do not access card immediatly...*/
gertk 0:28557a4d2215 2151 err_code = FindDrive();
gertk 0:28557a4d2215 2152 if(err_code != TRUE)
gertk 0:28557a4d2215 2153 {
gertk 0:28557a4d2215 2154 // Lcd_XY_address(0,3);
gertk 0:28557a4d2215 2155 switch(err_code)
gertk 0:28557a4d2215 2156 {
gertk 0:28557a4d2215 2157 case ERROR_ATAREAD_CMD17:
gertk 0:28557a4d2215 2158 {
gertk 0:28557a4d2215 2159 printf("ATA:err. CMD17"); /*CMD17 does not respond, the command is not accepted...*/
gertk 0:28557a4d2215 2160 break;
gertk 0:28557a4d2215 2161 }
gertk 0:28557a4d2215 2162
gertk 0:28557a4d2215 2163 case ERROR_ATAREAD_TIMEOUT:
gertk 0:28557a4d2215 2164 {
gertk 0:28557a4d2215 2165 printf("ATA:rd timeout"); /*timeout on waiting for start of data transfer*/
gertk 0:28557a4d2215 2166 break;
gertk 0:28557a4d2215 2167 }
gertk 0:28557a4d2215 2168
gertk 0:28557a4d2215 2169 case ERROR_FAT_READBOOTSECTOR:
gertk 0:28557a4d2215 2170 {
gertk 0:28557a4d2215 2171 printf("FAT:read boots");
gertk 0:28557a4d2215 2172 break;
gertk 0:28557a4d2215 2173 }
gertk 0:28557a4d2215 2174
gertk 0:28557a4d2215 2175 case ERROR_FAT_JUMPOPCODE:
gertk 0:28557a4d2215 2176 {
gertk 0:28557a4d2215 2177 printf("FAT:jump opcode");
gertk 0:28557a4d2215 2178 break;
gertk 0:28557a4d2215 2179 }
gertk 0:28557a4d2215 2180
gertk 0:28557a4d2215 2181 case ERROR_FAT_BLOCKSIZE:
gertk 0:28557a4d2215 2182 {
gertk 0:28557a4d2215 2183 printf("FAT:blocksize ");
gertk 0:28557a4d2215 2184 break;
gertk 0:28557a4d2215 2185 }
gertk 0:28557a4d2215 2186
gertk 0:28557a4d2215 2187 case ERROR_FAT_MEDIUM:
gertk 0:28557a4d2215 2188 {
gertk 0:28557a4d2215 2189 printf("FAT:wr. medium ");
gertk 0:28557a4d2215 2190 break;
gertk 0:28557a4d2215 2191 }
gertk 0:28557a4d2215 2192
gertk 0:28557a4d2215 2193 default:
gertk 0:28557a4d2215 2194 {
gertk 0:28557a4d2215 2195 printf("Undefined.....");
gertk 0:28557a4d2215 2196 break;
gertk 0:28557a4d2215 2197 }
gertk 0:28557a4d2215 2198 }
gertk 0:28557a4d2215 2199 // Lcd_XY_address(0,4);
gertk 0:28557a4d2215 2200 printf("Card not supp.");
gertk 0:28557a4d2215 2201 }
gertk 0:28557a4d2215 2202 else
gertk 0:28557a4d2215 2203 {
gertk 0:28557a4d2215 2204 // Lcd_XY_address(11,1);
gertk 0:28557a4d2215 2205 printf("OK");
gertk 0:28557a4d2215 2206 DiskState = CARD_ACTIVE;
gertk 0:28557a4d2215 2207 return(TRUE);
gertk 0:28557a4d2215 2208 }
gertk 0:28557a4d2215 2209 }
gertk 0:28557a4d2215 2210 DelayS(4); /*when initialise failed wait before retry, otherwise the error message could not be read*/
gertk 0:28557a4d2215 2211 DiskState = NO_CARD;
gertk 0:28557a4d2215 2212 return(FALSE);
gertk 0:28557a4d2215 2213 }
gertk 0:28557a4d2215 2214
gertk 0:28557a4d2215 2215
gertk 0:28557a4d2215 2216 /*initialise MMC/SD-card in SPI-mode*/
gertk 0:28557a4d2215 2217 unsigned char Init_Card_SPI(void)
gertk 0:28557a4d2215 2218 {
gertk 0:28557a4d2215 2219 if (CARD_Init() == FALSE); /*The official initialisation routines as described in most of the documentation*/
gertk 0:28557a4d2215 2220 { /*If the official init fails, try the alternative init*/
gertk 0:28557a4d2215 2221 if (CARD_AlternativeInit() == FALSE) /*The alternative init, required ONLY because SanDisk does not follow the world's standards... <zucht>*/
gertk 0:28557a4d2215 2222 {
gertk 0:28557a4d2215 2223 return(FALSE);
gertk 0:28557a4d2215 2224 }
gertk 0:28557a4d2215 2225 }
gertk 0:28557a4d2215 2226
gertk 0:28557a4d2215 2227 Card_CID(); /*request Card - ID*/
gertk 0:28557a4d2215 2228 Card_CSD(); /*request Card Specific Data*/
gertk 0:28557a4d2215 2229
gertk 0:28557a4d2215 2230 if (CARD_OperatingConditions(Response_data) == FALSE)
gertk 0:28557a4d2215 2231 {
gertk 0:28557a4d2215 2232 printf("CARD:err CMD58");
gertk 0:28557a4d2215 2233 return(FALSE);
gertk 0:28557a4d2215 2234 }
gertk 0:28557a4d2215 2235 else
gertk 0:28557a4d2215 2236 {
gertk 0:28557a4d2215 2237 if ((Response_data[2] & SUPPVOLT) != SUPPVOLT) /*mask and compare for cards that support 3.0-3.1, 3.1-3.2, 3.2-3.3, 3.3-3.4 Volt*/
gertk 0:28557a4d2215 2238 {
gertk 0:28557a4d2215 2239 printf("CARD:voltage ");
gertk 0:28557a4d2215 2240 return(FALSE);
gertk 0:28557a4d2215 2241 }
gertk 0:28557a4d2215 2242
gertk 0:28557a4d2215 2243 printf("CARD:OK ");
gertk 0:28557a4d2215 2244 return(TRUE);
gertk 0:28557a4d2215 2245 }
gertk 0:28557a4d2215 2246 }
gertk 0:28557a4d2215 2247
gertk 0:28557a4d2215 2248 /*This routine will count ALL files within the current directory (which could be root or subdirectory)*/
gertk 0:28557a4d2215 2249 void CountFiles(void)
gertk 0:28557a4d2215 2250 {
gertk 0:28557a4d2215 2251 print_device_status("COUNTING FILES"); /*inform the user about a possible time consuming task*/
gertk 0:28557a4d2215 2252
gertk 0:28557a4d2215 2253 if (FileSearch(&file,0)) /*search for the first file on the card*/
gertk 0:28557a4d2215 2254 {
gertk 0:28557a4d2215 2255 CountedFiles = 1;
gertk 0:28557a4d2215 2256 while (FileSearch(&file,1)) /*goto the next file*/
gertk 0:28557a4d2215 2257 {
gertk 0:28557a4d2215 2258 /*count ALL files (even the irrelevant files, since they do occupy diskspace, max 512 files in root you know)*/
gertk 0:28557a4d2215 2259 CountedFiles++; /*increment file-counter*/
gertk 0:28557a4d2215 2260 }
gertk 0:28557a4d2215 2261 FileSearch(&file,0); /*set the search routines back to the first file*/
gertk 0:28557a4d2215 2262 }
gertk 0:28557a4d2215 2263 else
gertk 0:28557a4d2215 2264 {
gertk 0:28557a4d2215 2265 CountedFiles = 0;
gertk 0:28557a4d2215 2266 }
gertk 0:28557a4d2215 2267
gertk 0:28557a4d2215 2268 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 2269 printf("\r\nNumber of files in current (sub)dir: %d",CountedFiles);
gertk 0:28557a4d2215 2270 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2271 }
gertk 0:28557a4d2215 2272
gertk 0:28557a4d2215 2273 /*This routine will 'filter' the currently 'selected' file,*/
gertk 0:28557a4d2215 2274 /*when the file does not meet the expected standards it returns 'FALSE'*/
gertk 0:28557a4d2215 2275 unsigned char FileFilter(void)
gertk 0:28557a4d2215 2276 {
gertk 0:28557a4d2215 2277 /* Disk type | Size */
gertk 0:28557a4d2215 2278 /* --------------------------+--------*/
gertk 0:28557a4d2215 2279 /* 35 track, no errors | 174848 */
gertk 0:28557a4d2215 2280 /* 35 track, 683 error bytes | 175531 */
gertk 0:28557a4d2215 2281 /* 40 track, no errors | 196608 */
gertk 0:28557a4d2215 2282 /* 40 track, 768 error bytes | 197376 */
gertk 0:28557a4d2215 2283
gertk 0:28557a4d2215 2284 if((file.name[8] == 'P') && (file.name[9] == 'R') && (file.name[10] == 'G'))
gertk 0:28557a4d2215 2285 {
gertk 0:28557a4d2215 2286 return(PRG_FILE);
gertk 0:28557a4d2215 2287 }
gertk 0:28557a4d2215 2288
gertk 0:28557a4d2215 2289 if ((file.name[8] == 'D') && (file.name[9] == '6') && (file.name[10] == '4'))
gertk 0:28557a4d2215 2290 {
gertk 0:28557a4d2215 2291 if (file.size == 174848)
gertk 0:28557a4d2215 2292 return(D64_35T_MODE);
gertk 0:28557a4d2215 2293
gertk 0:28557a4d2215 2294 if (file.size == 175531)
gertk 0:28557a4d2215 2295 return(D64_35T_ER_MODE);
gertk 0:28557a4d2215 2296
gertk 0:28557a4d2215 2297 if (file.size == 196608)
gertk 0:28557a4d2215 2298 return(D64_40T_MODE);
gertk 0:28557a4d2215 2299
gertk 0:28557a4d2215 2300 if (file.size == 177376)
gertk 0:28557a4d2215 2301 return(D64_40T_ER_MODE);
gertk 0:28557a4d2215 2302 }
gertk 0:28557a4d2215 2303
gertk 0:28557a4d2215 2304 // if((file.name[8] == 'T') && (file.name[9] == '6') && (file.name[10] == '4'))
gertk 0:28557a4d2215 2305 // {
gertk 0:28557a4d2215 2306 // return(T64_MODE);
gertk 0:28557a4d2215 2307 // }
gertk 0:28557a4d2215 2308
gertk 0:28557a4d2215 2309 if ((file.size == 0) && (file.cluster!=0))
gertk 0:28557a4d2215 2310 return(SUBDIRECTORY); /*normal subdirectories are files with a length 0 and only the rootdirectory points to cluster=0, meaning that subdirectories NEVER point to cluster 0*/
gertk 0:28557a4d2215 2311
gertk 0:28557a4d2215 2312 if ((file.name[0] == '.') && (file.name[1] == ' ') && (file.name[2] == ' ') && (file.name[3] == ' ') && (file.name[4] == ' ') && (file.name[5] == ' ') && (file.name[6] == ' ') && (file.name[7] == ' '))
gertk 0:28557a4d2215 2313 return(SUBDIRECTORY); /*this subdirectory points to the current directory*/
gertk 0:28557a4d2215 2314
gertk 0:28557a4d2215 2315 if ((file.name[0] == '.') && (file.name[1] == '.') && (file.name[2] == ' ') && (file.name[3] == ' ') && (file.name[4] == ' ') && (file.name[5] == ' ') && (file.name[6] == ' ') && (file.name[7] == ' '))
gertk 0:28557a4d2215 2316 return(SUBDIRECTORY); /*this subdirectory points to the parent directory (which could be root)*/
gertk 0:28557a4d2215 2317
gertk 0:28557a4d2215 2318 if ((file.name[0] != 0x20) && (file.name[8] == 0x20) && (file.name[9] == 0x20) && (file.name[10] == 0x20))
gertk 0:28557a4d2215 2319 return(UNKNOWN); /*when a filename has no extension, show it simply because it could be a file belonging to an IDE64 fixed game*/
gertk 0:28557a4d2215 2320
gertk 0:28557a4d2215 2321 return(FALSE);
gertk 0:28557a4d2215 2322 }
gertk 0:28557a4d2215 2323
gertk 0:28557a4d2215 2324 /*this routine will search for the next available buffer, when no buffer can be found it responds with 255*/
gertk 0:28557a4d2215 2325 unsigned char SearchFreeBuffer(void)
gertk 0:28557a4d2215 2326 {
gertk 0:28557a4d2215 2327 unsigned char lp;
gertk 0:28557a4d2215 2328
gertk 0:28557a4d2215 2329 lp=0;
gertk 0:28557a4d2215 2330 while(lp<MAX_NUMBER_OF_DOS_BUFFERS)
gertk 0:28557a4d2215 2331 {
gertk 0:28557a4d2215 2332 if (DOS_buffer[lp].buffer_in_use == FALSE) /*TRUE means that this channel is in use, FALSE means it is available*/
gertk 0:28557a4d2215 2333 {
gertk 0:28557a4d2215 2334 return(lp); /*return with the number of the available channel*/
gertk 0:28557a4d2215 2335 }
gertk 0:28557a4d2215 2336 lp++;
gertk 0:28557a4d2215 2337 }
gertk 0:28557a4d2215 2338 return(255); /*an error has occurred, there are no free channels left*/
gertk 0:28557a4d2215 2339 }
gertk 0:28557a4d2215 2340
gertk 0:28557a4d2215 2341 /*****************************************************************************************************************/
gertk 0:28557a4d2215 2342
gertk 0:28557a4d2215 2343 /*this routine will wait untill a string has been loaded that is terminated by an EOI*/
gertk 0:28557a4d2215 2344 void WaitForString(unsigned char *outputstring, unsigned frame_handshake)
gertk 0:28557a4d2215 2345 {
gertk 0:28557a4d2215 2346 unsigned char cnt;
gertk 0:28557a4d2215 2347
gertk 0:28557a4d2215 2348 TimeOut = FALSE;
gertk 0:28557a4d2215 2349 EOI = FALSE;
gertk 0:28557a4d2215 2350 cnt = 0;
gertk 0:28557a4d2215 2351 while((TimeOut == FALSE) && (EOI == FALSE)) /*get filename/instruction, this is all data untill an EOI is received*/
gertk 0:28557a4d2215 2352 {
gertk 0:28557a4d2215 2353 outputstring[cnt] = IEC_receive(frame_handshake); /*save the received char to a string specified by the caller of this routine*/
gertk 0:28557a4d2215 2354 // printf("%02x", outputstring[cnt]); /*print string to be captured for debug purposes...*/
gertk 0:28557a4d2215 2355 cnt++;
gertk 0:28557a4d2215 2356 }
gertk 0:28557a4d2215 2357 outputstring[cnt] = 0; /*close the string with a "nul"*/
gertk 0:28557a4d2215 2358 }
gertk 0:28557a4d2215 2359
gertk 0:28557a4d2215 2360
gertk 0:28557a4d2215 2361 /*This routine will search for the first 'number' and puts this number into a register*/
gertk 0:28557a4d2215 2362 /*it returns 0 (FALSE) when the number does not fit into an unsigned char*/
gertk 0:28557a4d2215 2363 /*it returns the position of the character AFTER the number. so that this can be used for the next number search...*/
gertk 0:28557a4d2215 2364 unsigned char ValueFromString(unsigned char *inputstring, unsigned char *outputvalue)
gertk 0:28557a4d2215 2365 {
gertk 0:28557a4d2215 2366 unsigned char lp;
gertk 0:28557a4d2215 2367
gertk 0:28557a4d2215 2368 lp = 0;
gertk 0:28557a4d2215 2369 *outputvalue = 0;
gertk 0:28557a4d2215 2370
gertk 0:28557a4d2215 2371 while ((inputstring[lp] < '0') || (inputstring[lp] > '9')) /*check if this character is not a number*/
gertk 0:28557a4d2215 2372 {
gertk 0:28557a4d2215 2373 lp++; /*keep looping until a number is found*/
gertk 0:28557a4d2215 2374 if (inputstring[lp] == 0) /*when the end of the string has been reached, exit false*/
gertk 0:28557a4d2215 2375 {
gertk 0:28557a4d2215 2376 return(FALSE); /*if there were no numbers at the beginning of this string, return FALSE*/
gertk 0:28557a4d2215 2377 }
gertk 0:28557a4d2215 2378 }
gertk 0:28557a4d2215 2379
gertk 0:28557a4d2215 2380 while ((inputstring[lp] >= '0') && (inputstring[lp] <= '9')) /*check if this character is a number*/
gertk 0:28557a4d2215 2381 {
gertk 0:28557a4d2215 2382 if (*outputvalue > 25)
gertk 0:28557a4d2215 2383 {
gertk 0:28557a4d2215 2384 return(FALSE); /*the number in the string is larger the 255 and is not a 'unsigned char' exit routine*/
gertk 0:28557a4d2215 2385 }
gertk 0:28557a4d2215 2386 else
gertk 0:28557a4d2215 2387 {
gertk 0:28557a4d2215 2388 *outputvalue = *outputvalue * 10;
gertk 0:28557a4d2215 2389 *outputvalue = *outputvalue + (inputstring[lp] - '0');
gertk 0:28557a4d2215 2390 lp++;
gertk 0:28557a4d2215 2391 }
gertk 0:28557a4d2215 2392 }
gertk 0:28557a4d2215 2393
gertk 0:28557a4d2215 2394 return(lp); /*the first position directly after the number*/
gertk 0:28557a4d2215 2395 }
gertk 0:28557a4d2215 2396
gertk 0:28557a4d2215 2397
gertk 0:28557a4d2215 2398 /*This routine will search for the first 'number' and puts this number into a register*/
gertk 0:28557a4d2215 2399 /*the number has to start a the first character otherwise it returns false*/
gertk 0:28557a4d2215 2400 unsigned char LongValueFromString(unsigned char *inputstring, unsigned long *outputvalue)
gertk 0:28557a4d2215 2401 {
gertk 0:28557a4d2215 2402 unsigned char lp;
gertk 0:28557a4d2215 2403
gertk 0:28557a4d2215 2404 lp = 0;
gertk 0:28557a4d2215 2405 *outputvalue = 0;
gertk 0:28557a4d2215 2406
gertk 0:28557a4d2215 2407 while ((inputstring[lp] >= '0') && (inputstring[lp] <= '9')) /*check if this character is a number*/
gertk 0:28557a4d2215 2408 {
gertk 0:28557a4d2215 2409 *outputvalue = *outputvalue * 10;
gertk 0:28557a4d2215 2410 *outputvalue = *outputvalue + (inputstring[lp] - '0');
gertk 0:28557a4d2215 2411 lp++;
gertk 0:28557a4d2215 2412 }
gertk 0:28557a4d2215 2413
gertk 0:28557a4d2215 2414 return(lp); /*the first position directly after the number*/
gertk 0:28557a4d2215 2415 }
gertk 0:28557a4d2215 2416
gertk 0:28557a4d2215 2417
gertk 0:28557a4d2215 2418 /*this routine extract the filename from the command string, it will remove all unwanted options and leaves the filename only */
gertk 0:28557a4d2215 2419 /*Some of the possible entries to indicate the problem to be solved by this routine: */
gertk 0:28557a4d2215 2420 /*normal open : commandstring = "0:filename,s,r" */
gertk 0:28557a4d2215 2421 /*simplified open: commandstring = "filename,s,r" */
gertk 0:28557a4d2215 2422 /*simplified open: commandstring = "filename" */
gertk 0:28557a4d2215 2423 /*simplified open: commandstring = "0:filename" */
gertk 0:28557a4d2215 2424 /*replacement : commandstring = "@0:filename,s,r" */
gertk 0:28557a4d2215 2425 /*copy : commandstring = "C0:backup=original" */
gertk 0:28557a4d2215 2426 /*multiple copy : commandstring = "COPY0:<destfile>=<sourcefile>" or "COPY:<destfile>=<sourcefile1>, <sourcefile2>, ..." */
gertk 0:28557a4d2215 2427 /*therefore we may conclude that everything AFTER ':' and BEFORE ',' (or end-of-string) is the filename */
gertk 0:28557a4d2215 2428 void ExtractFilenameFromString(unsigned char *input_string, unsigned char *output_string)
gertk 0:28557a4d2215 2429 {
gertk 0:28557a4d2215 2430 unsigned char tempstring[41];
gertk 0:28557a4d2215 2431
gertk 0:28557a4d2215 2432 strcpy((char *)tempstring, (char *)input_string); /*this is required because the splitstring_on function destroys the inputvalues*/
gertk 0:28557a4d2215 2433 if (!SplitStringOn_Sign(':', tempstring, output_string)) /*remove all characters BEFORE the ':'-sign*/
gertk 0:28557a4d2215 2434 { /*if this succeeds the ':'-sign was found we can continue 'stripping' the string*/
gertk 0:28557a4d2215 2435 strcpy((char *)output_string, (char *)input_string); /*when the commandstring does not contain a ':' the outputstring is empty, so we must fill it with the inputstring in order to continue*/
gertk 0:28557a4d2215 2436 }
gertk 0:28557a4d2215 2437 SplitStringOn_Sign(',', output_string, tempstring); /*remove all characters after the ','-sign and store the result in outputstring. If does not matter if this fails (because there is no ','-sign) because the outputstring is still correct. as it contains all caracters BEFORE the ','-sign (even if it isn't there*/
gertk 0:28557a4d2215 2438 }
gertk 0:28557a4d2215 2439
gertk 0:28557a4d2215 2440
gertk 0:28557a4d2215 2441
gertk 0:28557a4d2215 2442 /*this routine will strip all characters before the given sign*/
gertk 0:28557a4d2215 2443 /*it will return the characters BEFORE the first sign in BEFORE_STRING (sign is not included in the result)*/
gertk 0:28557a4d2215 2444 /*it will return the characters AFTER the first sign in AFTER_STRING (sign is not included in the result)*/
gertk 0:28557a4d2215 2445 unsigned char SplitStringOn_Sign(unsigned char sign, unsigned char *beforesign_string, unsigned char *aftersign_string)
gertk 0:28557a4d2215 2446 {
gertk 0:28557a4d2215 2447 unsigned char lp, lp2;
gertk 0:28557a4d2215 2448
gertk 0:28557a4d2215 2449 lp = 0;
gertk 0:28557a4d2215 2450 while(beforesign_string[lp])
gertk 0:28557a4d2215 2451 {
gertk 0:28557a4d2215 2452 if (beforesign_string[lp] == sign)
gertk 0:28557a4d2215 2453 {
gertk 0:28557a4d2215 2454 lp++;
gertk 0:28557a4d2215 2455 lp2 = 0;
gertk 0:28557a4d2215 2456 while(beforesign_string[lp+lp2])
gertk 0:28557a4d2215 2457 {
gertk 0:28557a4d2215 2458 aftersign_string[lp2] = beforesign_string[lp+lp2];
gertk 0:28557a4d2215 2459 lp2++;
gertk 0:28557a4d2215 2460 }
gertk 0:28557a4d2215 2461 beforesign_string[--lp] = 0; /*terminate the command_string, the :-sign is not included any more in te string*/
gertk 0:28557a4d2215 2462 aftersign_string[lp2] = 0; /*terminate the copied string*/
gertk 0:28557a4d2215 2463 return(TRUE); /*indicate that the conversion (removal of all chars before :-sign) has succeeded*/
gertk 0:28557a4d2215 2464 }
gertk 0:28557a4d2215 2465 lp++;
gertk 0:28557a4d2215 2466 }
gertk 0:28557a4d2215 2467 return(FALSE); /*indicate that the conversion (removal of all chars before :-sign) has failed*/
gertk 0:28557a4d2215 2468 }
gertk 0:28557a4d2215 2469
gertk 0:28557a4d2215 2470
gertk 0:28557a4d2215 2471 /*****************************************************************************************************************/
gertk 0:28557a4d2215 2472
gertk 0:28557a4d2215 2473 /*this routine print some prefedined text to the display AND serial port*/
gertk 0:28557a4d2215 2474 void print_device_status(const unsigned char *message)
gertk 0:28557a4d2215 2475 {
gertk 0:28557a4d2215 2476 // Lcd_XY_address(0,2);
gertk 0:28557a4d2215 2477 // Lcd_CharBold();
gertk 0:28557a4d2215 2478 printf("%s",message);
gertk 0:28557a4d2215 2479 // Lcd_CharNormal();
gertk 0:28557a4d2215 2480
gertk 0:28557a4d2215 2481 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 2482 printf("\r\n%s",message);
gertk 0:28557a4d2215 2483 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2484 }
gertk 0:28557a4d2215 2485
gertk 0:28557a4d2215 2486 /*this routine print the name of the current file (which is suppost to be a D64 file)*/
gertk 0:28557a4d2215 2487 void print_D64_name(unsigned char mode)
gertk 0:28557a4d2215 2488 {
gertk 0:28557a4d2215 2489 unsigned char i;
gertk 0:28557a4d2215 2490
gertk 0:28557a4d2215 2491 if (mode == INVERTED) /*depending on requested mode print in normal or inverse-mode*/
gertk 0:28557a4d2215 2492 // Lcd_CharInvert();
gertk 0:28557a4d2215 2493
gertk 0:28557a4d2215 2494 // Lcd_XY_address(0,0);
gertk 0:28557a4d2215 2495 printf("%05d in dir. ",CountedFiles); /*show the total number of files (sub)directory*/
gertk 0:28557a4d2215 2496 // Lcd_XY_address(0,1); /*set cursor to line we want to use*/
gertk 0:28557a4d2215 2497
gertk 0:28557a4d2215 2498 if(file_type == NONE)
gertk 0:28557a4d2215 2499 {
gertk 0:28557a4d2215 2500 printf("%05d= ",file_number); /*show the current selection and clear the line*/
gertk 0:28557a4d2215 2501 // Lcd_XY_address(6,1); /*set cursor back...*/
gertk 0:28557a4d2215 2502 }
gertk 0:28557a4d2215 2503 else
gertk 0:28557a4d2215 2504 {
gertk 0:28557a4d2215 2505 printf("%05d= ",file_number); /*show the current selection and clear the line*/
gertk 0:28557a4d2215 2506 // Lcd_XY_address(6,1); /*set cursor back...*/
gertk 0:28557a4d2215 2507 for(i=0;i<8;i++) /*print selection (or currently selected) 8.3-filename*/
gertk 0:28557a4d2215 2508 putch(file.name[i]); /*character after character*/
gertk 0:28557a4d2215 2509
gertk 0:28557a4d2215 2510 OutputToRS232(); /*output the same info to the serial port also*/
gertk 0:28557a4d2215 2511 printf("\r\nfilename:");
gertk 0:28557a4d2215 2512 for(i=0;i<8;i++) /*print selection (or currently selected) 8.3-filename*/
gertk 0:28557a4d2215 2513 putch(file.name[i]); /*character after character*/
gertk 0:28557a4d2215 2514 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2515 }
gertk 0:28557a4d2215 2516
gertk 0:28557a4d2215 2517 // Lcd_CharNormal();
gertk 0:28557a4d2215 2518 // Lcd_XY_address(0,5);
gertk 0:28557a4d2215 2519 printf("%c=%02d ",0x0d,devicenumber); /*print the device number on the display*/
gertk 0:28557a4d2215 2520 if(file_type == NONE) /*indicate on the display we are working in the root-dir of the card (HD-mode*/
gertk 0:28557a4d2215 2521 printf("Hard-disk");
gertk 0:28557a4d2215 2522 if(file_type == SUBDIRECTORY) /*indicate on the display we are working in the root-dir of the card (HD-mode*/
gertk 0:28557a4d2215 2523 printf("Hard-disk");
gertk 0:28557a4d2215 2524 if(file_type == PRG_FILE) /*...*/
gertk 0:28557a4d2215 2525 printf("PRG-file ");
gertk 0:28557a4d2215 2526 if(file_type == UNKNOWN) /*...*/
gertk 0:28557a4d2215 2527 printf("-UNKNOWN-");
gertk 0:28557a4d2215 2528 if(file_type == D64_35T_MODE) /*indicate on the display the D64 file 35 tracks no errors*/
gertk 0:28557a4d2215 2529 printf(".D64 35T ");
gertk 0:28557a4d2215 2530 if(file_type == D64_35T_ER_MODE) /*indicate on the display the D64 file 35 tracks with errors*/
gertk 0:28557a4d2215 2531 printf(".D64 35Te");
gertk 0:28557a4d2215 2532 if(file_type == D64_40T_MODE) /*indicate on the display the D64 file 40 tracks no errors*/
gertk 0:28557a4d2215 2533 printf(".D64 40T ");
gertk 0:28557a4d2215 2534 if(file_type == D64_40T_ER_MODE) /*indicate on the display the D64 file 40 tracks with errors*/
gertk 0:28557a4d2215 2535 printf(".D64 40Te");
gertk 0:28557a4d2215 2536 if(file_type == T64_MODE) /*indicate on the display the T64*/
gertk 0:28557a4d2215 2537 printf(".T64-mode");
gertk 0:28557a4d2215 2538 }
gertk 0:28557a4d2215 2539
gertk 0:28557a4d2215 2540 /*this routine prints Track Sector and (remaining/loaded) blocks*/
gertk 0:28557a4d2215 2541 void print_D64_TSB(unsigned char trk, unsigned char sec, unsigned int blk, unsigned int total_blk)
gertk 0:28557a4d2215 2542 {
gertk 0:28557a4d2215 2543 static unsigned char previous_track;
gertk 0:28557a4d2215 2544 unsigned int blockcounter;
gertk 0:28557a4d2215 2545
gertk 0:28557a4d2215 2546 blockcounter = total_blk - blk; /*calculate the current block*/
gertk 0:28557a4d2215 2547
gertk 0:28557a4d2215 2548 // Lcd_XY_address(0,3); /*set the LCD coordinates*/
gertk 0:28557a4d2215 2549 // Lcd_ProgressBar(blk, total_blk); /*draw a progress bar*/
gertk 0:28557a4d2215 2550 // Lcd_XY_address(0,4); /*set the LCD coordinates*/
gertk 0:28557a4d2215 2551 printf("%c=%02d T=%02d S=%02d",0x0e,error_code,trk,sec); /*show the error code, track and sector*/
gertk 0:28557a4d2215 2552
gertk 0:28557a4d2215 2553 OutputToRS232(); /*output the same info to the serial port also*/
gertk 0:28557a4d2215 2554 printf("\r\n%02d,%02d,%d/%d",trk,sec,blockcounter,total_blk); /*send to serial the Track and sector info*/
gertk 0:28557a4d2215 2555 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2556
gertk 0:28557a4d2215 2557 //Sound_TrackChange(trk-previous_track); /*play a sound (if required) of a moving head*/
gertk 0:28557a4d2215 2558 previous_track = trk; /*keep track of the number of tracks we move within the disk, this in order to simulate the sound properly*/
gertk 0:28557a4d2215 2559 }
gertk 0:28557a4d2215 2560
gertk 0:28557a4d2215 2561
gertk 0:28557a4d2215 2562
gertk 0:28557a4d2215 2563 /*this routine is to be used to select a D64 image from the inserted card*/
gertk 0:28557a4d2215 2564 void SelectD64Image(void)
gertk 0:28557a4d2215 2565 {
gertk 0:28557a4d2215 2566 unsigned char filefilter_result;
gertk 0:28557a4d2215 2567 unsigned char blink_loop;
gertk 0:28557a4d2215 2568
gertk 0:28557a4d2215 2569 ReadButtons();
gertk 0:28557a4d2215 2570 if (button_prev == TRUE)
gertk 0:28557a4d2215 2571 {
gertk 0:28557a4d2215 2572 if (file_number == 1)
gertk 0:28557a4d2215 2573 {
gertk 0:28557a4d2215 2574 file_number=0; /*file counter is now '0' which means 'ROOT directory'*/
gertk 0:28557a4d2215 2575 file_type = NONE; /*and because the user has selected root, the selected file_type = NONE*/
gertk 0:28557a4d2215 2576 }
gertk 0:28557a4d2215 2577 else
gertk 0:28557a4d2215 2578 {
gertk 0:28557a4d2215 2579 if (file_number > 1)
gertk 0:28557a4d2215 2580 {
gertk 0:28557a4d2215 2581 if (FileSearch(&file,2)) /*goto the previous D64 file*/
gertk 0:28557a4d2215 2582 {
gertk 0:28557a4d2215 2583 file_number--; /*decrease selected file counter*/
gertk 0:28557a4d2215 2584 }
gertk 0:28557a4d2215 2585 filefilter_result = FileFilter(); /*check the selected file*/
gertk 0:28557a4d2215 2586 file_type = filefilter_result;
gertk 0:28557a4d2215 2587 }
gertk 0:28557a4d2215 2588 }
gertk 0:28557a4d2215 2589 DiskState = INVALID_POINTER;
gertk 0:28557a4d2215 2590 // Lcd_XY_address(0,3);
gertk 0:28557a4d2215 2591 // Lcd_SelectionBar((CountedFiles-file_number), CountedFiles);
gertk 0:28557a4d2215 2592 print_D64_name(INVERTED); /*write the selection to display in inverted mode*/
gertk 0:28557a4d2215 2593 DelayBigMs(BUTTON_SELECTION_RATE); /*delay determines selection repetition rate*/
gertk 0:28557a4d2215 2594 }
gertk 0:28557a4d2215 2595
gertk 0:28557a4d2215 2596 if (button_next == TRUE)
gertk 0:28557a4d2215 2597 {
gertk 0:28557a4d2215 2598 if (file_number < CountedFiles)
gertk 0:28557a4d2215 2599 {
gertk 0:28557a4d2215 2600 if (file_number == 0) /*the first file on the card needs no search since it is allready found*/
gertk 0:28557a4d2215 2601 file_number++; /*increase selected file counter*/
gertk 0:28557a4d2215 2602 else
gertk 0:28557a4d2215 2603 if (FileSearch(&file,1)) /*goto the next D64 file*/
gertk 0:28557a4d2215 2604 file_number++; /*increase selected file counter*/
gertk 0:28557a4d2215 2605 }
gertk 0:28557a4d2215 2606 filefilter_result = FileFilter(); /*check the selected file*/
gertk 0:28557a4d2215 2607 file_type = filefilter_result;
gertk 0:28557a4d2215 2608 DiskState = INVALID_POINTER;
gertk 0:28557a4d2215 2609 // Lcd_XY_address(0,3);
gertk 0:28557a4d2215 2610 // Lcd_SelectionBar((CountedFiles-file_number), CountedFiles);
gertk 0:28557a4d2215 2611 print_D64_name(INVERTED); /*write the selection to display in inverted mode*/
gertk 0:28557a4d2215 2612 DelayBigMs(BUTTON_SELECTION_RATE); /*delay determines selection repetition rate*/
gertk 0:28557a4d2215 2613 }
gertk 0:28557a4d2215 2614
gertk 0:28557a4d2215 2615 if (button_select == TRUE)
gertk 0:28557a4d2215 2616 {
gertk 0:28557a4d2215 2617 filefilter_result = FileFilter(); /*check the selected file*/
gertk 0:28557a4d2215 2618 file_type = filefilter_result;
gertk 0:28557a4d2215 2619
gertk 0:28557a4d2215 2620 if (file_number==0) /*file counter is now '0' which means 'ROOT directory'*/
gertk 0:28557a4d2215 2621 {
gertk 0:28557a4d2215 2622 file_type = NONE; /*and because the user has selected root, the selected file_type = NONE*/
gertk 0:28557a4d2215 2623 // Lcd_XY_address(0,2); /*set cursor*/
gertk 0:28557a4d2215 2624 printf(" "); /*clear the file_info information*/
gertk 0:28557a4d2215 2625 print_D64_name(PLAIN); /*write the selection to display in normal-mode*/
gertk 0:28557a4d2215 2626 DiskState = CARD_ACTIVE; /*the 1541-III is now functioning as a harddisk*/
gertk 0:28557a4d2215 2627 DelayBigMs(BUTTON_SELECTION_RATE); /*delay determines selection repetition rate*/
gertk 0:28557a4d2215 2628 }
gertk 0:28557a4d2215 2629 else
gertk 0:28557a4d2215 2630 {
gertk 0:28557a4d2215 2631 if (filefilter_result == SUBDIRECTORY)
gertk 0:28557a4d2215 2632 {
gertk 0:28557a4d2215 2633 OpenSubDirectory(&file); /*the user request to enter a subdirectory, so we call the routine that setts all registers in the correct way in order to use subdirectories properly*/
gertk 0:28557a4d2215 2634 file_number = 0; /*the file_number counter needs to be reset*/
gertk 0:28557a4d2215 2635 file_type = NONE; /*and because the user has selected a (sub)directory, the selected file_type = NONE, as there is no image file selected and we are operating in harddiskmode*/
gertk 0:28557a4d2215 2636
gertk 0:28557a4d2215 2637 print_D64_name(PLAIN); /*write the selection to display in normal-mode, this clears up the display, but with the incorrect filecount values*/
gertk 0:28557a4d2215 2638 CountFiles(); /*count all files in the opened directory*/
gertk 0:28557a4d2215 2639 print_D64_name(PLAIN); /*write the selection to display in normal-mode, the countvalues are updated*/
gertk 0:28557a4d2215 2640 // Lcd_XY_address(0,2); /*set cursor*/
gertk 0:28557a4d2215 2641 printf(" "); /*clear the file_info information*/
gertk 0:28557a4d2215 2642 DiskState = CARD_ACTIVE; /*the 1541-III is now functioning as a harddisk*/
gertk 0:28557a4d2215 2643 DelayBigMs(BUTTON_SELECTION_RATE); /*delay determines selection repetition rate*/
gertk 0:28557a4d2215 2644 }
gertk 0:28557a4d2215 2645 else
gertk 0:28557a4d2215 2646 {
gertk 0:28557a4d2215 2647 if ((filefilter_result != PRG_FILE) && (filefilter_result != UNKNOWN)) /*pass all supported D64 files and leave out PRG and unknown files*/
gertk 0:28557a4d2215 2648 {
gertk 0:28557a4d2215 2649 FileSectorScan(&file); /*update the sector location table cache*/
gertk 0:28557a4d2215 2650 D64ReadBAM(); /*update the BAM*/
gertk 0:28557a4d2215 2651 DiskState = CARD_ACTIVE; /*the 1541-III is now accessable*/
gertk 0:28557a4d2215 2652 // Lcd_XY_address(0,2); /*set cursor*/
gertk 0:28557a4d2215 2653 printf(" "); /*clear the file_info information*/
gertk 0:28557a4d2215 2654 print_D64_name(PLAIN); /*write the selection to display in normal-mode*/
gertk 0:28557a4d2215 2655 }
gertk 0:28557a4d2215 2656 else
gertk 0:28557a4d2215 2657 {
gertk 0:28557a4d2215 2658 for (blink_loop=4;blink_loop>0;blink_loop--) /*create a blinking effect to draw attention to this line*/
gertk 0:28557a4d2215 2659 {
gertk 0:28557a4d2215 2660 // Lcd_CharInvert();
gertk 0:28557a4d2215 2661 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2662 printf("Selection err.");
gertk 0:28557a4d2215 2663 DelayBigMs(250); /*delay to make sure the message can be read properly*/
gertk 0:28557a4d2215 2664 // Lcd_CharNormal();
gertk 0:28557a4d2215 2665 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2666 printf("Selection err.");
gertk 0:28557a4d2215 2667 DelayBigMs(250); /*delay to make sure the message can be read properly*/
gertk 0:28557a4d2215 2668 }
gertk 0:28557a4d2215 2669 print_D64_name(INVERTED); /*write the selection to display in inverted mode*/
gertk 0:28557a4d2215 2670 }
gertk 0:28557a4d2215 2671 }
gertk 0:28557a4d2215 2672 }
gertk 0:28557a4d2215 2673 }
gertk 0:28557a4d2215 2674 }
gertk 0:28557a4d2215 2675
gertk 0:28557a4d2215 2676 /*****************************************************************************************************************/
gertk 0:28557a4d2215 2677 /*almost identical to loading a directory (seen from a C64)*/
gertk 0:28557a4d2215 2678 /*This routine shows 'all' the files on the card*/
gertk 0:28557a4d2215 2679
gertk 0:28557a4d2215 2680 /*Note: 'all' means the files that are OK according the filefilter routine*/
gertk 0:28557a4d2215 2681 void CardDirectory(void)
gertk 0:28557a4d2215 2682 {
gertk 0:28557a4d2215 2683 unsigned pass_counter;
gertk 0:28557a4d2215 2684 unsigned char separation_line=FALSE;
gertk 0:28557a4d2215 2685 unsigned char filefilter_result;
gertk 0:28557a4d2215 2686 unsigned int index_cnt;
gertk 0:28557a4d2215 2687 unsigned char lp;
gertk 0:28557a4d2215 2688 unsigned char dir_width;
gertk 0:28557a4d2215 2689 unsigned int blocksize;
gertk 0:28557a4d2215 2690
gertk 0:28557a4d2215 2691 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 2692 EOI = FALSE;
gertk 0:28557a4d2215 2693 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 2694
gertk 0:28557a4d2215 2695 /*----------------*/
gertk 0:28557a4d2215 2696 /*directory header*/
gertk 0:28557a4d2215 2697 /*----------------*/
gertk 0:28557a4d2215 2698 IEC_send(0x01); /*load this "program" to start address 0x0401*/
gertk 0:28557a4d2215 2699 IEC_send(0x04);
gertk 0:28557a4d2215 2700
gertk 0:28557a4d2215 2701 if (VIC20_mode == TRUE) /*for better readabillity on a VIC-20 the card directory is displayed in a smallscreen and a widescreen version*/
gertk 0:28557a4d2215 2702 { /* | |*/ /*useable area of a VC-20 dir line*/
gertk 0:28557a4d2215 2703 dir_width = 10; /*the number of places that a VIC20 file entry may occupy in order to fit the screen width of 22 chars*/
gertk 0:28557a4d2215 2704 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x12); IEC_send(0x20); IEC_send(0x22); IEC_send_string("CARD DIRECTORY"); IEC_send(0x22); IEC_send(0x00); /*VIC-20 Directory header*/
gertk 0:28557a4d2215 2705 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x20); IEC_send(0x22); IEC_send_string("u``````````i"); IEC_send(0x22); IEC_send(0x00); /*top-line*/
gertk 0:28557a4d2215 2706 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x20); IEC_send(0x22); IEC_send_string("} 1541-III }"); IEC_send(0x22); IEC_send(0x00); /*model*/
gertk 0:28557a4d2215 2707 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x20); IEC_send(0x22); IEC_send_string("}J. DEROGEE}"); IEC_send(0x22); IEC_send(0x00); /*credits*/
gertk 0:28557a4d2215 2708 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x20); IEC_send(0x22); IEC_send_string("}VIC20-MODE}"); IEC_send(0x22); IEC_send(0x00); /*credits*/
gertk 0:28557a4d2215 2709 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x20); IEC_send(0x22); IEC_send_string("j``````````k"); IEC_send(0x22); IEC_send(0x00); /*separation-line*/
gertk 0:28557a4d2215 2710 }
gertk 0:28557a4d2215 2711 else
gertk 0:28557a4d2215 2712 {
gertk 0:28557a4d2215 2713 dir_width = 17; /*the number of places that a C64/C128/C16 etc. file entry may occupy in order to fit the screen width of 40 chars*/
gertk 0:28557a4d2215 2714 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x12); IEC_send(0x20); IEC_send(0x22); IEC_send_string(" CARD DIRECTORY "); IEC_send(0x22); IEC_send_string(" 00 2A"); IEC_send(0x00); /*Normal Directory header*/
gertk 0:28557a4d2215 2715 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x20); IEC_send(0x22); IEC_send_string("u````````````````i"); IEC_send(0x22); IEC_send(0x00); /*top-line*/
gertk 0:28557a4d2215 2716 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x20); IEC_send(0x22); IEC_send_string("} 1541-III MBED }"); IEC_send(0x22); IEC_send(0x00); /*model*/
gertk 0:28557a4d2215 2717 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x20); IEC_send(0x22); IEC_send_string("}J.DEROGEE & KGE }"); IEC_send(0x22); IEC_send(0x00); /*credits*/
gertk 0:28557a4d2215 2718 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x20); IEC_send(0x22); IEC_send_string("j````````````````k"); IEC_send(0x22); IEC_send(0x00); /*separation-line*/
gertk 0:28557a4d2215 2719 }
gertk 0:28557a4d2215 2720
gertk 0:28557a4d2215 2721 /*-----------------*/
gertk 0:28557a4d2215 2722 /*directory content*/
gertk 0:28557a4d2215 2723 /*-----------------*/
gertk 0:28557a4d2215 2724
gertk 0:28557a4d2215 2725 pass_counter = 0;
gertk 0:28557a4d2215 2726 index_cnt = 0;
gertk 0:28557a4d2215 2727 while(pass_counter++ < 3)
gertk 0:28557a4d2215 2728 {
gertk 0:28557a4d2215 2729 if (pass_counter != 1) /*print a seperator line BETWEEN the different file types, pass_counter 1 means the first and between means ALL EXCEPT 1 (because thee is nothing before 1, so the line could bever be in between)*/
gertk 0:28557a4d2215 2730 separation_line = FALSE;
gertk 0:28557a4d2215 2731
gertk 0:28557a4d2215 2732 if(FileSearch(&file,0))
gertk 0:28557a4d2215 2733 {
gertk 0:28557a4d2215 2734 do
gertk 0:28557a4d2215 2735 {
gertk 0:28557a4d2215 2736 //OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 2737 //printf("\r\n8.3:%c%c%c%c%c%c%c%c",file.name[0],file.name[1],file.name[2],file.name[3],file.name[4],file.name[5],file.name[6],file.name[7]); /*for debug purposes only !!!*/
gertk 0:28557a4d2215 2738 //printf("\r\nlfn:%c%c%c%c%c%c%c%c%c%c%c%c",file.name_lfn[0],file.name_lfn[1],file.name_lfn[2],file.name_lfn[3],file.name_lfn[4],file.name_lfn[5],file.name_lfn[6],file.name_lfn[7],file.name_lfn[8],file.name_lfn[9],file.name_lfn[10],file.name_lfn[11]); /*for debug purposes only !!!*/
gertk 0:28557a4d2215 2739 //OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2740
gertk 0:28557a4d2215 2741 print_D64_TSB(0, 0, (3*CountedFiles-index_cnt), 3*CountedFiles); /*print track, sector and progress bar, since were are making 3 passes, the counter is used 3 times (3 passes)*/
gertk 0:28557a4d2215 2742 index_cnt++; /*for the best results... arrange the files on filetype, directories first, the D64's of all types, then PRG-files*/
gertk 0:28557a4d2215 2743 filefilter_result = FileFilter();
gertk 0:28557a4d2215 2744 if ((pass_counter == 1) && (filefilter_result == SUBDIRECTORY) ||
gertk 0:28557a4d2215 2745 ((pass_counter == 2) && ((filefilter_result == D64_35T_MODE) || (filefilter_result == D64_35T_ER_MODE) || (filefilter_result == D64_40T_MODE) || (filefilter_result == D64_40T_ER_MODE))) ||
gertk 0:28557a4d2215 2746 ((pass_counter == 3) && ((filefilter_result == PRG_FILE) || (filefilter_result == T64_MODE) || (filefilter_result == UNKNOWN))))
gertk 0:28557a4d2215 2747 {
gertk 0:28557a4d2215 2748 if (separation_line == FALSE) /*for better readabillity... add a small separation-line (but only if required)*/
gertk 0:28557a4d2215 2749 {
gertk 0:28557a4d2215 2750 separation_line = TRUE;
gertk 0:28557a4d2215 2751 IEC_send(0x01); IEC_send(0x01); IEC_send(0x00); IEC_send(0x00); IEC_send(0x20); IEC_send(0x20); IEC_send(0x22);
gertk 0:28557a4d2215 2752 for(lp=0;lp<(dir_width+1);lp++)
gertk 0:28557a4d2215 2753 IEC_send('`');
gertk 0:28557a4d2215 2754 IEC_send(0x22); IEC_send(0x00);
gertk 0:28557a4d2215 2755 }
gertk 0:28557a4d2215 2756
gertk 0:28557a4d2215 2757 IEC_send(0x01);
gertk 0:28557a4d2215 2758 IEC_send(0x01);
gertk 0:28557a4d2215 2759
gertk 0:28557a4d2215 2760 if (pass_counter == 3) /*in the third pass we show all the file information, as these are not images or directories, but actual files*/
gertk 0:28557a4d2215 2761 {
gertk 0:28557a4d2215 2762 blocksize = file.size / 254; /*calculate blocksize(1 block=254 bytes) from filesize(bytes)*/
gertk 0:28557a4d2215 2763 IEC_send(blocksize%256); /*low-byte of blocksize of file*/
gertk 0:28557a4d2215 2764 IEC_send(blocksize/256); /*high-byte of blocksize of file*/
gertk 0:28557a4d2215 2765 if(blocksize < 10) /*if required, add extra space for better allignment*/
gertk 0:28557a4d2215 2766 IEC_send(0x20);
gertk 0:28557a4d2215 2767
gertk 0:28557a4d2215 2768 if(blocksize < 100) /*if required, add extra space for better allignment*/
gertk 0:28557a4d2215 2769 IEC_send(0x20);
gertk 0:28557a4d2215 2770 }
gertk 0:28557a4d2215 2771 else
gertk 0:28557a4d2215 2772 {
gertk 0:28557a4d2215 2773 IEC_send(0); /*low-byte of blocksize of file*/
gertk 0:28557a4d2215 2774 IEC_send(0); /*high-byte of blocksize of file*/
gertk 0:28557a4d2215 2775 IEC_send(0x20);
gertk 0:28557a4d2215 2776 IEC_send(0x20);
gertk 0:28557a4d2215 2777 }
gertk 0:28557a4d2215 2778
gertk 0:28557a4d2215 2779 IEC_send(0x22); /*each entry must be starting with the "-sign*/
gertk 0:28557a4d2215 2780 if ((filefilter_result != PRG_FILE) && (filefilter_result != UNKNOWN))
gertk 0:28557a4d2215 2781 IEC_send('$'); /*proceed each image (.D64 or similar) or subdirectory with a $-sign, to indicate that it has to be loaded as an directory*/
gertk 0:28557a4d2215 2782
gertk 0:28557a4d2215 2783 if(file.name_lfn[0] == 0) /*check if this entry has an 8.3-name or LFN-name*/
gertk 0:28557a4d2215 2784 {
gertk 0:28557a4d2215 2785 IEC_send(file.name[0]); /*8.3 filename WITHOUT the extra spaces (looks much better as the LFN has the same look by nature)*/
gertk 0:28557a4d2215 2786 lp=7;
gertk 0:28557a4d2215 2787 if(((file.name[1]) != ' ') || ((file.name[2]) != ' ') || ((file.name[3]) != ' ') || ((file.name[4]) != ' ') || ((file.name[5]) != ' ') || ((file.name[6]) != ' ') || ((file.name[7]) != ' '))
gertk 0:28557a4d2215 2788 { IEC_send(file.name[1]); lp=6;}
gertk 0:28557a4d2215 2789 if(((file.name[2]) != ' ') || ((file.name[3]) != ' ') || ((file.name[4]) != ' ') || ((file.name[5]) != ' ') || ((file.name[6]) != ' ') || ((file.name[7]) != ' '))
gertk 0:28557a4d2215 2790 { IEC_send(file.name[2]); lp=5;}
gertk 0:28557a4d2215 2791 if(((file.name[3]) != ' ') || ((file.name[4]) != ' ') || ((file.name[5]) != ' ') || ((file.name[6]) != ' ') || ((file.name[7]) != ' '))
gertk 0:28557a4d2215 2792 { IEC_send(file.name[3]); lp=4;}
gertk 0:28557a4d2215 2793 if(((file.name[4]) != ' ') || ((file.name[5]) != ' ') || ((file.name[6]) != ' ') || ((file.name[7]) != ' '))
gertk 0:28557a4d2215 2794 { IEC_send(file.name[4]); lp=3;}
gertk 0:28557a4d2215 2795 if(((file.name[5]) != ' ') || ((file.name[6]) != ' ') || ((file.name[7]) != ' '))
gertk 0:28557a4d2215 2796 { IEC_send(file.name[5]); lp=2;}
gertk 0:28557a4d2215 2797 if(((file.name[6]) != ' ') || ((file.name[7]) != ' '))
gertk 0:28557a4d2215 2798 { IEC_send(file.name[6]); lp=1;}
gertk 0:28557a4d2215 2799 if((file.name[7]) != ' ')
gertk 0:28557a4d2215 2800 { IEC_send(file.name[7]); lp=0;}
gertk 0:28557a4d2215 2801
gertk 0:28557a4d2215 2802 lp = (dir_width - 7) + lp; /*calculate the remaining spaces to fit the VIC20 mode*/
gertk 0:28557a4d2215 2803 }
gertk 0:28557a4d2215 2804 else
gertk 0:28557a4d2215 2805 {
gertk 0:28557a4d2215 2806 for(lp=0;lp<(dir_width-1);lp++) /*print the LFN string*/
gertk 0:28557a4d2215 2807 {
gertk 0:28557a4d2215 2808 IEC_send(file.name_lfn[lp]);
gertk 0:28557a4d2215 2809 if ((file.name_lfn[lp+1] == '.') && (file.name_lfn[lp+5] == 0)) /*print the string, BUT without the last for characters (but only for files with a 3 letter extension, which are the .D64, .PRG, etc)*/
gertk 0:28557a4d2215 2810 break;
gertk 0:28557a4d2215 2811
gertk 0:28557a4d2215 2812 if (file.name_lfn[lp+1] == 0) /*otherwise on end of string, stop*/
gertk 0:28557a4d2215 2813 break;
gertk 0:28557a4d2215 2814 }
gertk 0:28557a4d2215 2815
gertk 0:28557a4d2215 2816 if (lp==(dir_width-1)) /*check if the filename was displayed partially, if so, then add a *-sign*/
gertk 0:28557a4d2215 2817 IEC_send('*'); /*the max ammount of displayable characters was printed, but there where more characters to print, so we add a *-sign to keep compatible with the search routines*/
gertk 0:28557a4d2215 2818
gertk 0:28557a4d2215 2819 lp = dir_width - lp; /*calculate the remaining number of spaces*/
gertk 0:28557a4d2215 2820 }
gertk 0:28557a4d2215 2821
gertk 0:28557a4d2215 2822 IEC_send(0x22); /*each entry must end with the "-sign*/
gertk 0:28557a4d2215 2823 if (filefilter_result == PRG_FILE)
gertk 0:28557a4d2215 2824 lp++; /*since this entry did not start with the $-sign, we must add an extra space at the end to keep length of each line identical*/
gertk 0:28557a4d2215 2825
gertk 0:28557a4d2215 2826 while(lp--) /*the remaining location must be filled with spaces*/
gertk 0:28557a4d2215 2827 IEC_send(' ');
gertk 0:28557a4d2215 2828
gertk 0:28557a4d2215 2829 switch (filefilter_result)
gertk 0:28557a4d2215 2830 {
gertk 0:28557a4d2215 2831 case PRG_FILE:
gertk 0:28557a4d2215 2832 {
gertk 0:28557a4d2215 2833 IEC_send('P'); /*print PRG*/
gertk 0:28557a4d2215 2834 IEC_send('R');
gertk 0:28557a4d2215 2835 IEC_send('G');
gertk 0:28557a4d2215 2836 break;
gertk 0:28557a4d2215 2837 }
gertk 0:28557a4d2215 2838
gertk 0:28557a4d2215 2839 case D64_35T_MODE:;
gertk 0:28557a4d2215 2840 case D64_35T_ER_MODE:;
gertk 0:28557a4d2215 2841 case D64_40T_MODE:;
gertk 0:28557a4d2215 2842 case D64_40T_ER_MODE:
gertk 0:28557a4d2215 2843 {
gertk 0:28557a4d2215 2844 IEC_send('D'); /*print D64*/
gertk 0:28557a4d2215 2845 IEC_send('6');
gertk 0:28557a4d2215 2846 IEC_send('4');
gertk 0:28557a4d2215 2847 break;
gertk 0:28557a4d2215 2848 }
gertk 0:28557a4d2215 2849
gertk 0:28557a4d2215 2850 case T64_MODE:
gertk 0:28557a4d2215 2851 {
gertk 0:28557a4d2215 2852 IEC_send('T'); /*print T64*/
gertk 0:28557a4d2215 2853 IEC_send('6');
gertk 0:28557a4d2215 2854 IEC_send('4');
gertk 0:28557a4d2215 2855 break;
gertk 0:28557a4d2215 2856 }
gertk 0:28557a4d2215 2857
gertk 0:28557a4d2215 2858 case SUBDIRECTORY:
gertk 0:28557a4d2215 2859 {
gertk 0:28557a4d2215 2860 IEC_send('D'); /*print DIR*/
gertk 0:28557a4d2215 2861 IEC_send('I');
gertk 0:28557a4d2215 2862 IEC_send('R');
gertk 0:28557a4d2215 2863 break;
gertk 0:28557a4d2215 2864 }
gertk 0:28557a4d2215 2865
gertk 0:28557a4d2215 2866 default:
gertk 0:28557a4d2215 2867 {
gertk 0:28557a4d2215 2868 break; /*print nothing*/
gertk 0:28557a4d2215 2869 }
gertk 0:28557a4d2215 2870 }
gertk 0:28557a4d2215 2871
gertk 0:28557a4d2215 2872 IEC_send(0x00);
gertk 0:28557a4d2215 2873 }
gertk 0:28557a4d2215 2874 }
gertk 0:28557a4d2215 2875 while(FileSearch(&file,1));
gertk 0:28557a4d2215 2876 }
gertk 0:28557a4d2215 2877 }
gertk 0:28557a4d2215 2878
gertk 0:28557a4d2215 2879 FileSearch(&file,0); /*select the first file on the card, this to please all other routines using the filesearch() routine, this since selected_D64file is set to 0*/
gertk 0:28557a4d2215 2880
gertk 0:28557a4d2215 2881 /*PROPERLY END THIS DIRECTORY, BUT DO NOT PRINT THE FREE BLOCKS TEXT... IT WOULD NOT MAKE ANY SENSE, since the limitation is in the 512 files in root-dir limit*/
gertk 0:28557a4d2215 2882 IEC_send(0x00);
gertk 0:28557a4d2215 2883 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 2884 IEC_send(0x00);
gertk 0:28557a4d2215 2885 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 2886 SetErrorCode(0, LED_OFF); /*all is OK, set the LED blinking mode to 'RITHM' to indicate that we have done somthing on a higher level then something within a D64-file*/
gertk 0:28557a4d2215 2887 }
gertk 0:28557a4d2215 2888
gertk 0:28557a4d2215 2889
gertk 0:28557a4d2215 2890 void D64Directory(void)
gertk 0:28557a4d2215 2891 {
gertk 0:28557a4d2215 2892 unsigned char lp, mode, extra_spaces, track, sector, unused;
gertk 0:28557a4d2215 2893 unsigned int blocksize, blocksfree, read_blocks;
gertk 0:28557a4d2215 2894
gertk 0:28557a4d2215 2895 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 2896 EOI = FALSE;
gertk 0:28557a4d2215 2897 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 2898
gertk 0:28557a4d2215 2899 /*some bytes required for sending a directory entry to a VIC20, C64, C128, etc.*/
gertk 0:28557a4d2215 2900 IEC_send(0x01); /*load this "program" to start address 0x0401*/
gertk 0:28557a4d2215 2901 IEC_send(0x04);
gertk 0:28557a4d2215 2902
gertk 0:28557a4d2215 2903 /*Directory header*/
gertk 0:28557a4d2215 2904 /*----------------*/
gertk 0:28557a4d2215 2905 D64BlockRead(18,0);
gertk 0:28557a4d2215 2906 read_blocks = 1;
gertk 0:28557a4d2215 2907 print_D64_TSB(18,0,read_blocks, 0);
gertk 0:28557a4d2215 2908 IEC_send(0x01); /*...*/
gertk 0:28557a4d2215 2909 IEC_send(0x01); /*...*/
gertk 0:28557a4d2215 2910 IEC_send(0); /*drive-number of this device, in the beginning of this project used as file pointer/indicator*/
gertk 0:28557a4d2215 2911 IEC_send(0); /*drive-number of this device, in the beginning of this project uses as file pointer/indicator*/
gertk 0:28557a4d2215 2912 IEC_send(0x12); /*RVS-ON (invert characters)*/
gertk 0:28557a4d2215 2913 IEC_send(0x22); /*"-sign*/
gertk 0:28557a4d2215 2914 for(lp=144;lp<160;lp++)
gertk 0:28557a4d2215 2915 {
gertk 0:28557a4d2215 2916 IEC_send(RAM_buffer[lp]); /*send the Diskname*/
gertk 0:28557a4d2215 2917 }
gertk 0:28557a4d2215 2918
gertk 0:28557a4d2215 2919 IEC_send(0x22); /*"-sign*/
gertk 0:28557a4d2215 2920 IEC_send(0x20); /*space*/
gertk 0:28557a4d2215 2921 IEC_send(RAM_buffer[162]); /*send the disk-ID byte-0*/
gertk 0:28557a4d2215 2922 IEC_send(RAM_buffer[163]); /*send the disk-ID byte-1*/
gertk 0:28557a4d2215 2923 IEC_send(0x20); /*space*/
gertk 0:28557a4d2215 2924 IEC_send(RAM_buffer[165]); /*send the DOS-version and format-type byte-0*/
gertk 0:28557a4d2215 2925 IEC_send(RAM_buffer[166]); /*send the DOS-version and format-type byte-1*/
gertk 0:28557a4d2215 2926 IEC_send(0x00); /*a byte indicating the end of this "directory-line"*/
gertk 0:28557a4d2215 2927
gertk 0:28557a4d2215 2928 /*Directory entry ...*/
gertk 0:28557a4d2215 2929 /*-------------------*/
gertk 0:28557a4d2215 2930 mode=0; /*set sector read to first entry*/
gertk 0:28557a4d2215 2931 while(D64SeekDirEntry(mode, &track, &sector, &unused)) /*get directory entry and request the current track and sector*/
gertk 0:28557a4d2215 2932 {
gertk 0:28557a4d2215 2933 mode=1; /*set sector read to next entry*/
gertk 0:28557a4d2215 2934 print_D64_TSB(track,sector,read_blocks,0);
gertk 0:28557a4d2215 2935 if (dir_entry.filetype != 0x00) /*scratched files are NOT displayed in the directory*/
gertk 0:28557a4d2215 2936 {
gertk 0:28557a4d2215 2937 IEC_send(0x01); /*bytes indicating the beginning of a "directory-line"*/
gertk 0:28557a4d2215 2938 IEC_send(0x01);
gertk 0:28557a4d2215 2939 IEC_send(dir_entry.blocksize_low_byte); /*size of this file low-byte*/
gertk 0:28557a4d2215 2940 IEC_send(dir_entry.blocksize_high_byte); /*size of this file high-byte*/
gertk 0:28557a4d2215 2941 // dir_entry.record_size_relfile = 0x00;
gertk 0:28557a4d2215 2942 blocksize = ((256 * dir_entry.blocksize_high_byte) + dir_entry.blocksize_low_byte);
gertk 0:28557a4d2215 2943 if (blocksize < 10) /*add an extra space(s) to adjust line length*/
gertk 0:28557a4d2215 2944 IEC_send(0x20); /* */
gertk 0:28557a4d2215 2945 if (blocksize < 100) /* */
gertk 0:28557a4d2215 2946 IEC_send(0x20); /* */
gertk 0:28557a4d2215 2947 if (blocksize < 1000) /* */
gertk 0:28557a4d2215 2948 IEC_send(0x20); /* */
gertk 0:28557a4d2215 2949 IEC_send(0x22); /*"-sign*/
gertk 0:28557a4d2215 2950
gertk 0:28557a4d2215 2951 extra_spaces = 0;
gertk 0:28557a4d2215 2952 for(lp=0;lp<16;lp++)
gertk 0:28557a4d2215 2953 {
gertk 0:28557a4d2215 2954 if(dir_entry.filename[lp]== 160)
gertk 0:28557a4d2215 2955 extra_spaces++;
gertk 0:28557a4d2215 2956 else
gertk 0:28557a4d2215 2957 IEC_send(dir_entry.filename[lp]); /*filename of this entrynumber*/
gertk 0:28557a4d2215 2958
gertk 0:28557a4d2215 2959 }
gertk 0:28557a4d2215 2960
gertk 0:28557a4d2215 2961 IEC_send(0x22); /*"-sign*/
gertk 0:28557a4d2215 2962 while(extra_spaces != 0)
gertk 0:28557a4d2215 2963 {
gertk 0:28557a4d2215 2964 IEC_send(0x20); /*add some extra spaces for proper allignment*/
gertk 0:28557a4d2215 2965 extra_spaces--;
gertk 0:28557a4d2215 2966 }
gertk 0:28557a4d2215 2967
gertk 0:28557a4d2215 2968 /*filetype*/
gertk 0:28557a4d2215 2969 /*--------*/
gertk 0:28557a4d2215 2970 if (dir_entry.filetype > 127) /*when MSB has been set the file has been properly closed*/
gertk 0:28557a4d2215 2971 IEC_send(0x20); /*print a space before the filetype*/
gertk 0:28557a4d2215 2972 else
gertk 0:28557a4d2215 2973 IEC_send(0x2A); /*print a asterix before the filetype to indicate that the file has not been closed (yet)*/
gertk 0:28557a4d2215 2974
gertk 0:28557a4d2215 2975 switch (0x07 & dir_entry.filetype) /*the type of file is stored in the first byte (MSB is file open/closed, 3 lowest bits are of interest here ...*/
gertk 0:28557a4d2215 2976 {
gertk 0:28557a4d2215 2977 case 0:
gertk 0:28557a4d2215 2978 {
gertk 0:28557a4d2215 2979 IEC_send(0x44); /*file type = DELeted */
gertk 0:28557a4d2215 2980 IEC_send(0x45);
gertk 0:28557a4d2215 2981 IEC_send(0x4C);
gertk 0:28557a4d2215 2982 break;
gertk 0:28557a4d2215 2983 }
gertk 0:28557a4d2215 2984
gertk 0:28557a4d2215 2985 case 1:
gertk 0:28557a4d2215 2986 {
gertk 0:28557a4d2215 2987 IEC_send(0x53); /*file type = SEQuential */
gertk 0:28557a4d2215 2988 IEC_send(0x45);
gertk 0:28557a4d2215 2989 IEC_send(0x51);
gertk 0:28557a4d2215 2990 break;
gertk 0:28557a4d2215 2991 }
gertk 0:28557a4d2215 2992
gertk 0:28557a4d2215 2993 case 2:
gertk 0:28557a4d2215 2994 {
gertk 0:28557a4d2215 2995 IEC_send(0x50); /*file type = PRoGram */
gertk 0:28557a4d2215 2996 IEC_send(0x52);
gertk 0:28557a4d2215 2997 IEC_send(0x47);
gertk 0:28557a4d2215 2998 break;
gertk 0:28557a4d2215 2999 }
gertk 0:28557a4d2215 3000
gertk 0:28557a4d2215 3001 case 3:
gertk 0:28557a4d2215 3002 {
gertk 0:28557a4d2215 3003 IEC_send(0x55); /*file type = USeR */
gertk 0:28557a4d2215 3004 IEC_send(0x53);
gertk 0:28557a4d2215 3005 IEC_send(0x52);
gertk 0:28557a4d2215 3006 break;
gertk 0:28557a4d2215 3007 }
gertk 0:28557a4d2215 3008
gertk 0:28557a4d2215 3009
gertk 0:28557a4d2215 3010 case 4:
gertk 0:28557a4d2215 3011 {
gertk 0:28557a4d2215 3012 IEC_send(0x52); /*file type = RELative */
gertk 0:28557a4d2215 3013 IEC_send(0x45);
gertk 0:28557a4d2215 3014 IEC_send(0x4C);
gertk 0:28557a4d2215 3015 break;
gertk 0:28557a4d2215 3016 }
gertk 0:28557a4d2215 3017
gertk 0:28557a4d2215 3018 default:
gertk 0:28557a4d2215 3019 {
gertk 0:28557a4d2215 3020 IEC_send(0x55); /*file type = UNKnown (is only shown if someone uses these values out of spec...*/
gertk 0:28557a4d2215 3021 IEC_send(0x4E);
gertk 0:28557a4d2215 3022 IEC_send(0x4B);
gertk 0:28557a4d2215 3023 break;
gertk 0:28557a4d2215 3024 }
gertk 0:28557a4d2215 3025 }
gertk 0:28557a4d2215 3026
gertk 0:28557a4d2215 3027 if (dir_entry.filetype > 191)
gertk 0:28557a4d2215 3028 IEC_send(0x3C); /*print a "<" to indicate a locked file*/
gertk 0:28557a4d2215 3029 else
gertk 0:28557a4d2215 3030 IEC_send(0x20);
gertk 0:28557a4d2215 3031
gertk 0:28557a4d2215 3032 IEC_send(0x20);
gertk 0:28557a4d2215 3033 IEC_send(0x20);
gertk 0:28557a4d2215 3034 IEC_send(0x20);
gertk 0:28557a4d2215 3035 IEC_send(0x00);
gertk 0:28557a4d2215 3036 }
gertk 0:28557a4d2215 3037 }
gertk 0:28557a4d2215 3038
gertk 0:28557a4d2215 3039 /*Blocks free "directory-line"*/
gertk 0:28557a4d2215 3040 /*----------------------------*/
gertk 0:28557a4d2215 3041 IEC_send(0x01);
gertk 0:28557a4d2215 3042 IEC_send(0x01);
gertk 0:28557a4d2215 3043 blocksfree = D64LoadFreeBlocks(); /*read the number of free blocks from the D64 file*/
gertk 0:28557a4d2215 3044 IEC_send(blocksfree%256); /*low-byte of free blocks value*/
gertk 0:28557a4d2215 3045 IEC_send(blocksfree/256); /*high-byte of free blocks value*/
gertk 0:28557a4d2215 3046 IEC_send_string("BLOCKS FREE. "); /*"Blocks free."*/
gertk 0:28557a4d2215 3047 IEC_send(0x00);
gertk 0:28557a4d2215 3048 IEC_send(0x00);
gertk 0:28557a4d2215 3049 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 3050 IEC_send(0x00);
gertk 0:28557a4d2215 3051 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 3052 SetErrorCode(0, LED_OFF); /*all is OK*/
gertk 0:28557a4d2215 3053 }
gertk 0:28557a4d2215 3054
gertk 0:28557a4d2215 3055 void T64Directory(void)
gertk 0:28557a4d2215 3056 {
gertk 0:28557a4d2215 3057 unsigned char lp, mode, extra_spaces, track, sector, unused;
gertk 0:28557a4d2215 3058 unsigned int blocksize, blocksfree, read_blocks;
gertk 0:28557a4d2215 3059
gertk 0:28557a4d2215 3060 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3061 EOI = FALSE;
gertk 0:28557a4d2215 3062 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 3063
gertk 0:28557a4d2215 3064 /*some bytes required for sending a directory entry to a VIC20, C64, C128, etc.*/
gertk 0:28557a4d2215 3065 IEC_send(0x01); /*load this "program" to start address 0x0401*/
gertk 0:28557a4d2215 3066 IEC_send(0x04);
gertk 0:28557a4d2215 3067
gertk 0:28557a4d2215 3068 /*Directory header*/
gertk 0:28557a4d2215 3069 /*----------------*/
gertk 0:28557a4d2215 3070 D64BlockRead(18,0);
gertk 0:28557a4d2215 3071 read_blocks = 1;
gertk 0:28557a4d2215 3072 print_D64_TSB(18,0,read_blocks, 0);
gertk 0:28557a4d2215 3073 IEC_send(0x01); /*...*/
gertk 0:28557a4d2215 3074 IEC_send(0x01); /*...*/
gertk 0:28557a4d2215 3075 IEC_send(0); /*drive-number of this device, in the beginning of this project used as file pointer/indicator*/
gertk 0:28557a4d2215 3076 IEC_send(0); /*drive-number of this device, in the beginning of this project uses as file pointer/indicator*/
gertk 0:28557a4d2215 3077 IEC_send(0x12); /*RVS-ON (invert characters)*/
gertk 0:28557a4d2215 3078 IEC_send(0x22); /*"-sign*/
gertk 0:28557a4d2215 3079 for(lp=144;lp<160;lp++)
gertk 0:28557a4d2215 3080 {
gertk 0:28557a4d2215 3081 IEC_send(RAM_buffer[lp]); /*send the Diskname*/
gertk 0:28557a4d2215 3082 }
gertk 0:28557a4d2215 3083
gertk 0:28557a4d2215 3084 IEC_send(0x22); /*"-sign*/
gertk 0:28557a4d2215 3085 IEC_send(0x20); /*space*/
gertk 0:28557a4d2215 3086 IEC_send(RAM_buffer[162]); /*send the disk-ID byte-0*/
gertk 0:28557a4d2215 3087 IEC_send(RAM_buffer[163]); /*send the disk-ID byte-1*/
gertk 0:28557a4d2215 3088 IEC_send(0x20); /*space*/
gertk 0:28557a4d2215 3089 IEC_send(RAM_buffer[165]); /*send the DOS-version and format-type byte-0*/
gertk 0:28557a4d2215 3090 IEC_send(RAM_buffer[166]); /*send the DOS-version and format-type byte-1*/
gertk 0:28557a4d2215 3091 IEC_send(0x00); /*a byte indicating the end of this "directory-line"*/
gertk 0:28557a4d2215 3092
gertk 0:28557a4d2215 3093 /*Directory entry ...*/
gertk 0:28557a4d2215 3094 /*-------------------*/
gertk 0:28557a4d2215 3095 mode=0; /*set sector read to first entry*/
gertk 0:28557a4d2215 3096 while(D64SeekDirEntry(mode, &track, &sector, &unused)) /*get directory entry and request the current track and sector*/
gertk 0:28557a4d2215 3097 {
gertk 0:28557a4d2215 3098 mode=1; /*set sector read to next entry*/
gertk 0:28557a4d2215 3099 print_D64_TSB(track,sector,read_blocks,0);
gertk 0:28557a4d2215 3100 if (dir_entry.filetype != 0x00) /*scratched files are NOT displayed in the directory*/
gertk 0:28557a4d2215 3101 {
gertk 0:28557a4d2215 3102 IEC_send(0x01); /*bytes indicating the beginning of a "directory-line"*/
gertk 0:28557a4d2215 3103 IEC_send(0x01);
gertk 0:28557a4d2215 3104 IEC_send(dir_entry.blocksize_low_byte); /*size of this file low-byte*/
gertk 0:28557a4d2215 3105 IEC_send(dir_entry.blocksize_high_byte); /*size of this file high-byte*/
gertk 0:28557a4d2215 3106 // dir_entry.record_size_relfile = 0x00;
gertk 0:28557a4d2215 3107 blocksize = ((256 * dir_entry.blocksize_high_byte) + dir_entry.blocksize_low_byte);
gertk 0:28557a4d2215 3108 if (blocksize < 10) /*add an extra space(s) to adjust line length*/
gertk 0:28557a4d2215 3109 IEC_send(0x20); /* */
gertk 0:28557a4d2215 3110 if (blocksize < 100) /* */
gertk 0:28557a4d2215 3111 IEC_send(0x20); /* */
gertk 0:28557a4d2215 3112 if (blocksize < 1000) /* */
gertk 0:28557a4d2215 3113 IEC_send(0x20); /* */
gertk 0:28557a4d2215 3114 IEC_send(0x22); /*"-sign*/
gertk 0:28557a4d2215 3115
gertk 0:28557a4d2215 3116 extra_spaces = 0;
gertk 0:28557a4d2215 3117 for(lp=0;lp<16;lp++)
gertk 0:28557a4d2215 3118 {
gertk 0:28557a4d2215 3119 if(dir_entry.filename[lp]== 160)
gertk 0:28557a4d2215 3120 extra_spaces++;
gertk 0:28557a4d2215 3121 else
gertk 0:28557a4d2215 3122 IEC_send(dir_entry.filename[lp]); /*filename of this entrynumber*/
gertk 0:28557a4d2215 3123
gertk 0:28557a4d2215 3124 }
gertk 0:28557a4d2215 3125
gertk 0:28557a4d2215 3126 IEC_send(0x22); /*"-sign*/
gertk 0:28557a4d2215 3127 while(extra_spaces != 0)
gertk 0:28557a4d2215 3128 {
gertk 0:28557a4d2215 3129 IEC_send(0x20); /*add some extra spaces for proper allignment*/
gertk 0:28557a4d2215 3130 extra_spaces--;
gertk 0:28557a4d2215 3131 }
gertk 0:28557a4d2215 3132
gertk 0:28557a4d2215 3133 /*filetype*/
gertk 0:28557a4d2215 3134 /*--------*/
gertk 0:28557a4d2215 3135 if (dir_entry.filetype > 127) /*when MSB has been set the file has been properly closed*/
gertk 0:28557a4d2215 3136 IEC_send(0x20); /*print a space before the filetype*/
gertk 0:28557a4d2215 3137 else
gertk 0:28557a4d2215 3138 IEC_send(0x2A); /*print a asterix before the filetype to indicate that the file has not been closed (yet)*/
gertk 0:28557a4d2215 3139
gertk 0:28557a4d2215 3140 switch (0x07 & dir_entry.filetype) /*the type of file is stored in the first byte (MSB is file open/closed, 3 lowest bits are of interest here ...*/
gertk 0:28557a4d2215 3141 {
gertk 0:28557a4d2215 3142 case 0:
gertk 0:28557a4d2215 3143 {
gertk 0:28557a4d2215 3144 IEC_send(0x44); /*file type = DELeted */
gertk 0:28557a4d2215 3145 IEC_send(0x45);
gertk 0:28557a4d2215 3146 IEC_send(0x4C);
gertk 0:28557a4d2215 3147 break;
gertk 0:28557a4d2215 3148 }
gertk 0:28557a4d2215 3149
gertk 0:28557a4d2215 3150 case 1:
gertk 0:28557a4d2215 3151 {
gertk 0:28557a4d2215 3152 IEC_send(0x53); /*file type = SEQuential */
gertk 0:28557a4d2215 3153 IEC_send(0x45);
gertk 0:28557a4d2215 3154 IEC_send(0x51);
gertk 0:28557a4d2215 3155 break;
gertk 0:28557a4d2215 3156 }
gertk 0:28557a4d2215 3157
gertk 0:28557a4d2215 3158 case 2:
gertk 0:28557a4d2215 3159 {
gertk 0:28557a4d2215 3160 IEC_send(0x50); /*file type = PRoGram */
gertk 0:28557a4d2215 3161 IEC_send(0x52);
gertk 0:28557a4d2215 3162 IEC_send(0x47);
gertk 0:28557a4d2215 3163 break;
gertk 0:28557a4d2215 3164 }
gertk 0:28557a4d2215 3165
gertk 0:28557a4d2215 3166 case 3:
gertk 0:28557a4d2215 3167 {
gertk 0:28557a4d2215 3168 IEC_send(0x55); /*file type = USeR */
gertk 0:28557a4d2215 3169 IEC_send(0x53);
gertk 0:28557a4d2215 3170 IEC_send(0x52);
gertk 0:28557a4d2215 3171 break;
gertk 0:28557a4d2215 3172 }
gertk 0:28557a4d2215 3173
gertk 0:28557a4d2215 3174
gertk 0:28557a4d2215 3175 case 4:
gertk 0:28557a4d2215 3176 {
gertk 0:28557a4d2215 3177 IEC_send(0x52); /*file type = RELative */
gertk 0:28557a4d2215 3178 IEC_send(0x45);
gertk 0:28557a4d2215 3179 IEC_send(0x4C);
gertk 0:28557a4d2215 3180 break;
gertk 0:28557a4d2215 3181 }
gertk 0:28557a4d2215 3182
gertk 0:28557a4d2215 3183 default:
gertk 0:28557a4d2215 3184 {
gertk 0:28557a4d2215 3185 IEC_send(0x55); /*file type = UNKnown (is only shown if someone uses these values out of spec...*/
gertk 0:28557a4d2215 3186 IEC_send(0x4E);
gertk 0:28557a4d2215 3187 IEC_send(0x4B);
gertk 0:28557a4d2215 3188 break;
gertk 0:28557a4d2215 3189 }
gertk 0:28557a4d2215 3190 }
gertk 0:28557a4d2215 3191
gertk 0:28557a4d2215 3192 if (dir_entry.filetype > 191)
gertk 0:28557a4d2215 3193 IEC_send(0x3C); /*print a "<" to indicate a locked file*/
gertk 0:28557a4d2215 3194 else
gertk 0:28557a4d2215 3195 IEC_send(0x20);
gertk 0:28557a4d2215 3196
gertk 0:28557a4d2215 3197 IEC_send(0x20);
gertk 0:28557a4d2215 3198 IEC_send(0x20);
gertk 0:28557a4d2215 3199 IEC_send(0x20);
gertk 0:28557a4d2215 3200 IEC_send(0x00);
gertk 0:28557a4d2215 3201 }
gertk 0:28557a4d2215 3202 }
gertk 0:28557a4d2215 3203
gertk 0:28557a4d2215 3204 /*Blocks free "directory-line"*/
gertk 0:28557a4d2215 3205 /*----------------------------*/
gertk 0:28557a4d2215 3206 IEC_send(0x01);
gertk 0:28557a4d2215 3207 IEC_send(0x01);
gertk 0:28557a4d2215 3208 blocksfree = D64LoadFreeBlocks(); /*read the number of free blocks from the D64 file*/
gertk 0:28557a4d2215 3209 IEC_send(blocksfree%256); /*low-byte of free blocks value*/
gertk 0:28557a4d2215 3210 IEC_send(blocksfree/256); /*high-byte of free blocks value*/
gertk 0:28557a4d2215 3211 IEC_send_string("BLOCKS FREE. "); /*"Blocks free."*/
gertk 0:28557a4d2215 3212 IEC_send(0x00);
gertk 0:28557a4d2215 3213 IEC_send(0x00);
gertk 0:28557a4d2215 3214 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 3215 IEC_send(0x00);
gertk 0:28557a4d2215 3216 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 3217 SetErrorCode(0, LED_OFF); /*all is OK*/
gertk 0:28557a4d2215 3218 }
gertk 0:28557a4d2215 3219
gertk 0:28557a4d2215 3220
gertk 0:28557a4d2215 3221 /*this routine will search for a file ON THE CARD that matches the given filename search pattern*/
gertk 0:28557a4d2215 3222 /*the return value (if file is found) will be the index-number of the file as stored on the card*/
gertk 0:28557a4d2215 3223 unsigned int SeekFileOnCard(unsigned char *filename, struct file2TYPE *file)
gertk 0:28557a4d2215 3224 {
gertk 0:28557a4d2215 3225 signed char lp;
gertk 0:28557a4d2215 3226 unsigned int index;
gertk 0:28557a4d2215 3227
gertk 0:28557a4d2215 3228 index = 0; /*reset the index counter, as we do whish to know what the index of this file (within this (sub)directory) is*/
gertk 0:28557a4d2215 3229 if (!FileSearch(file, 0)) /*search for the first file on the card. Attention: screws up secbuf!!*/
gertk 0:28557a4d2215 3230 return(FALSE);
gertk 0:28557a4d2215 3231 while(1)
gertk 0:28557a4d2215 3232 {
gertk 0:28557a4d2215 3233 index++;
gertk 0:28557a4d2215 3234 lp = -1; /*reset loopcounter*/
gertk 0:28557a4d2215 3235 if (FileFilter() != FALSE) /*files that are not recognized by the filefilter will be excluded from the search. Simply because these files are not shown to user when he/she requests the cards directory*/
gertk 0:28557a4d2215 3236 {
gertk 0:28557a4d2215 3237 if(file->name_lfn[0] == 0) /*check if this entry has an 8.3-name or LFN-name*/
gertk 0:28557a4d2215 3238 { /*this file has no LFN name so we must use the 8.3 information for further searching*/
gertk 0:28557a4d2215 3239 do /*----------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 3240 {
gertk 0:28557a4d2215 3241 lp++;
gertk 0:28557a4d2215 3242 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 3243 // printf("\r\n8.3:lp=%02X, %c, %c",lp, file->name[lp], filename[lp]); /*for debug purposes only !!!*/
gertk 0:28557a4d2215 3244 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 3245
gertk 0:28557a4d2215 3246 if((filename[lp] == 0) && (lp==8)) /*when we've succesfully matched all 8 chars of the 8.3 name... we have a match*/
gertk 0:28557a4d2215 3247 return(index); /*all the remaining characters of the current file are spaces, we have a match!!!*/
gertk 0:28557a4d2215 3248
gertk 0:28557a4d2215 3249 if(filename[lp] == 0) /*when we have reached end of the searched filename but the current file has more characters then check if all further characters of file are spaces*/
gertk 0:28557a4d2215 3250 while(lp<8)
gertk 0:28557a4d2215 3251 {
gertk 0:28557a4d2215 3252 if (file->name[lp] != ' ')
gertk 0:28557a4d2215 3253 break;
gertk 0:28557a4d2215 3254 if (lp==7)
gertk 0:28557a4d2215 3255 return(index); /*all the remaining characters of the current file are spaces, we have a match!!!*/
gertk 0:28557a4d2215 3256 lp++;
gertk 0:28557a4d2215 3257 }
gertk 0:28557a4d2215 3258
gertk 0:28557a4d2215 3259 if(filename[lp] == 0) /*when the search string has not been ended but the searched filename has... no match*/
gertk 0:28557a4d2215 3260 break; /*we have no match*/
gertk 0:28557a4d2215 3261
gertk 0:28557a4d2215 3262 /*wildcard filter*/
gertk 0:28557a4d2215 3263 if (filename[lp] == '?') /*when we encounter an '?', it does not matter what the real char of the filename is*/
gertk 0:28557a4d2215 3264 file->name[lp] = '?'; /*therefore we can replace the real char by a '?' so that the comparison (at the end of this loop) can still be valid*/
gertk 0:28557a4d2215 3265
gertk 0:28557a4d2215 3266 if (filename[lp] == '*') /*when we have come so far and detected a * in our search string... we may consider this a match*/
gertk 0:28557a4d2215 3267 return(index); /*we have a partial or possible 100% match... but good enough to return with TRUE*/
gertk 0:28557a4d2215 3268 }
gertk 0:28557a4d2215 3269 while(file->name[lp] == filename[lp]); /*do the compare of current char of both strings*/
gertk 0:28557a4d2215 3270 }
gertk 0:28557a4d2215 3271 else /*this file has an LFN entry, use this for searching*/
gertk 0:28557a4d2215 3272 { /*--------------------------------------------------*/
gertk 0:28557a4d2215 3273 do
gertk 0:28557a4d2215 3274 {
gertk 0:28557a4d2215 3275 lp++;
gertk 0:28557a4d2215 3276 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 3277 // printf("\r\nLFN:lp=%02X, %c, %c",lp, file->name_lfn[lp], filename[lp]); /*for debug purposes only !!!*/
gertk 0:28557a4d2215 3278 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 3279
gertk 0:28557a4d2215 3280 if((filename[lp] == 0) && (file->name_lfn[lp]== '.')) /*when we have reached the extension if the file, we may consider this a match*/
gertk 0:28557a4d2215 3281 return(index); /*we have a match and we may asume that the extension is correct as well because the filefilter has allready checked this as a OK file, so how big is the chance that there are a .PRG and a .D64 with identical names ?!?!*/
gertk 0:28557a4d2215 3282
gertk 0:28557a4d2215 3283 if((filename[lp] == 0) && (file->name_lfn[lp]== 0)) /*when we have reached the end of both strings, this is the perfect match*/
gertk 0:28557a4d2215 3284 return(index); /*we have a match and we may asume that the extension is correct as well because the filefilter has allready checked this as a OK file, so how big is the chance that there are a .PRG and a .D64 with identical names ?!?!*/
gertk 0:28557a4d2215 3285
gertk 0:28557a4d2215 3286 if(filename[lp] == 0) /*when the search string has not been ended but the searched filename has... no match*/
gertk 0:28557a4d2215 3287 break; /*we have no match*/
gertk 0:28557a4d2215 3288
gertk 0:28557a4d2215 3289 /*wildcard filter*/
gertk 0:28557a4d2215 3290 if (filename[lp] == '?') /*when we encounter an '?', it does not matter what the real char of the filename is*/
gertk 0:28557a4d2215 3291 file->name_lfn[lp] = '?'; /*therefore we can replace the real char by a '?' so that the comparison (at the end of this loop) can still be valid*/
gertk 0:28557a4d2215 3292
gertk 0:28557a4d2215 3293 if (filename[lp] == '*') /*when we have come so far and detected a * in our search string... we may consider this a match*/
gertk 0:28557a4d2215 3294 return(index); /*we have a partial or possible 100% match... but good enough to return with TRUE*/
gertk 0:28557a4d2215 3295 }
gertk 0:28557a4d2215 3296 while(file->name_lfn[lp] == filename[lp]); /*do the compare of current char of both strings*/
gertk 0:28557a4d2215 3297 }
gertk 0:28557a4d2215 3298 }
gertk 0:28557a4d2215 3299 if (!FileSearch(file, 1)) /*search for the next file on the card. Attention: screws up secbuf!!*/
gertk 0:28557a4d2215 3300 break;
gertk 0:28557a4d2215 3301 }
gertk 0:28557a4d2215 3302 return(FALSE);
gertk 0:28557a4d2215 3303 }
gertk 0:28557a4d2215 3304
gertk 0:28557a4d2215 3305 /*this routine will load the file indicated by the given struct*/
gertk 0:28557a4d2215 3306 void LoadFileFromCard(struct file2TYPE *file)
gertk 0:28557a4d2215 3307 {
gertk 0:28557a4d2215 3308 unsigned char bytecount;
gertk 0:28557a4d2215 3309 unsigned int lp, blocksrem, filesizeinblocks;
gertk 0:28557a4d2215 3310 unsigned long remainingbytecounter;
gertk 0:28557a4d2215 3311
gertk 0:28557a4d2215 3312 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3313 EOI = FALSE;
gertk 0:28557a4d2215 3314 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 3315 remainingbytecounter = file->size;
gertk 0:28557a4d2215 3316 lp = 0;
gertk 0:28557a4d2215 3317 bytecount = 0;
gertk 0:28557a4d2215 3318
gertk 0:28557a4d2215 3319 /*calculate the blocksize of this file*/
gertk 0:28557a4d2215 3320 blocksrem = remainingbytecounter / 254;
gertk 0:28557a4d2215 3321 filesizeinblocks = blocksrem;
gertk 0:28557a4d2215 3322 if ((remainingbytecounter % 254) > 0)
gertk 0:28557a4d2215 3323 blocksrem++;
gertk 0:28557a4d2215 3324 blocksrem--; /*decrement by one, otherwise the countdown will stop at 1, and it must (offcourse) stop at 0*/
gertk 0:28557a4d2215 3325
gertk 0:28557a4d2215 3326 FileReadSector(file); /*read the first sector from the card (this is NOT a D64 sector) and contains MORE then 256 bytes*/
gertk 0:28557a4d2215 3327 while(remainingbytecounter != 0)
gertk 0:28557a4d2215 3328 {
gertk 0:28557a4d2215 3329 if (bytecount == 0)
gertk 0:28557a4d2215 3330 SetErrorCode(0,LED_ON); /*turn LED on, to create a small blink at every block*/
gertk 0:28557a4d2215 3331 if (bytecount == Blink_block)
gertk 0:28557a4d2215 3332 SetErrorCode(0,LED_OFF); /*turn LED off, to create a small blink at every block*/
gertk 0:28557a4d2215 3333
gertk 0:28557a4d2215 3334 if (remainingbytecounter == 1) /*check for last byte*/
gertk 0:28557a4d2215 3335 {
gertk 0:28557a4d2215 3336 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 3337 }
gertk 0:28557a4d2215 3338
gertk 0:28557a4d2215 3339 IEC_send(block_buffer[lp]);
gertk 0:28557a4d2215 3340 remainingbytecounter--;
gertk 0:28557a4d2215 3341 bytecount++;
gertk 0:28557a4d2215 3342 lp++;
gertk 0:28557a4d2215 3343
gertk 0:28557a4d2215 3344 if (lp == 512)
gertk 0:28557a4d2215 3345 {
gertk 0:28557a4d2215 3346 FileNextSector(file); /*we must set file pointer to the next sector before we can read the next sector*/
gertk 0:28557a4d2215 3347 FileReadSector(file); /*its time to read another sector*/
gertk 0:28557a4d2215 3348 lp = 0;
gertk 0:28557a4d2215 3349 }
gertk 0:28557a4d2215 3350
gertk 0:28557a4d2215 3351 if (bytecount == 254)
gertk 0:28557a4d2215 3352 {
gertk 0:28557a4d2215 3353 blocksrem--; /*another block has been send... update counter*/
gertk 0:28557a4d2215 3354 print_D64_TSB(0, 0, blocksrem, filesizeinblocks); /*print track, sector and remaining blocks*/
gertk 0:28557a4d2215 3355 bytecount = 0;
gertk 0:28557a4d2215 3356 }
gertk 0:28557a4d2215 3357 }
gertk 0:28557a4d2215 3358
gertk 0:28557a4d2215 3359 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 3360 SetErrorCode(0, LED_OFF); /*all is OK, set the LED blinking mode to 'RITHM' to indicate that we have done somthing on a higher level then something within a D64-file*/
gertk 0:28557a4d2215 3361 }
gertk 0:28557a4d2215 3362
gertk 0:28557a4d2215 3363 void LoadD64File(unsigned char trk, unsigned char sec, unsigned int filesizeinblocks)
gertk 0:28557a4d2215 3364 {
gertk 0:28557a4d2215 3365 unsigned char lp;
gertk 0:28557a4d2215 3366 unsigned int blocksrem;
gertk 0:28557a4d2215 3367 unsigned char lasttrack, lastsector;
gertk 0:28557a4d2215 3368
gertk 0:28557a4d2215 3369 blocksrem = filesizeinblocks;
gertk 0:28557a4d2215 3370 EOI = FALSE;
gertk 0:28557a4d2215 3371 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 3372
gertk 0:28557a4d2215 3373 while(1)
gertk 0:28557a4d2215 3374 {
gertk 0:28557a4d2215 3375 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3376 print_D64_TSB(trk, sec, blocksrem, filesizeinblocks); /*print track, sector and remaining blocks*/
gertk 0:28557a4d2215 3377 lasttrack = trk; /*keep extra buffer to remember what the last track was*/
gertk 0:28557a4d2215 3378 lastsector = sec; /*keep extra buffer to remember what the last sector was*/
gertk 0:28557a4d2215 3379 D64LoadFile_X_Bytes(&file,trk,sec,0,256); /*location of block to load and its size in bytes*/
gertk 0:28557a4d2215 3380 trk = block_buffer[0]; /*track position of the next block*/
gertk 0:28557a4d2215 3381 sec = block_buffer[1]; /*sector position of the next block*/
gertk 0:28557a4d2215 3382 blocksrem--; /*decrement remaining blocks counter*/
gertk 0:28557a4d2215 3383
gertk 0:28557a4d2215 3384 if (trk != 0) /*check on last block*/
gertk 0:28557a4d2215 3385 {
gertk 0:28557a4d2215 3386 for(lp=2;lp!=0;lp++)
gertk 0:28557a4d2215 3387 {
gertk 0:28557a4d2215 3388 IEC_send(block_buffer[lp]); /*transmit the 254 bytes within this block to the listener*/
gertk 0:28557a4d2215 3389 if (lp == Blink_block)
gertk 0:28557a4d2215 3390 SetErrorCode(0,LED_OFF); /*turn LED off, to create a small blink at every block*/
gertk 0:28557a4d2215 3391 }
gertk 0:28557a4d2215 3392 }
gertk 0:28557a4d2215 3393 else /*transmission of data of the last block*/
gertk 0:28557a4d2215 3394 {
gertk 0:28557a4d2215 3395 print_D64_TSB(lasttrack, lastsector, blocksrem, filesizeinblocks); /*print track, sector of the last block*/
gertk 0:28557a4d2215 3396 for(lp=2;lp<(sec);lp++) /*transfer the remainder of the loaded last block*/
gertk 0:28557a4d2215 3397 IEC_send(block_buffer[lp]);
gertk 0:28557a4d2215 3398 break;
gertk 0:28557a4d2215 3399 }
gertk 0:28557a4d2215 3400 }
gertk 0:28557a4d2215 3401 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 3402 IEC_send(block_buffer[sec]); /*the position of the last byte is indicated by the value in register 'Sector'*/
gertk 0:28557a4d2215 3403 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 3404 SetErrorCode(0,LED_OFF); /*all is OK*/
gertk 0:28557a4d2215 3405 }
gertk 0:28557a4d2215 3406
gertk 0:28557a4d2215 3407 /*Save the file to the D64, this requires the complete DOS handling !!!, since the CBM does not send*/
gertk 0:28557a4d2215 3408 /*the filesize, the exact filesize is only known when the file has allready been written. This is too*/
gertk 0:28557a4d2215 3409 /*late to update the progressbar on the LCD, so that's why this bar does not behave as expected*/
gertk 0:28557a4d2215 3410 unsigned char SaveD64File(void)
gertk 0:28557a4d2215 3411 {
gertk 0:28557a4d2215 3412 unsigned char lp, fbpt, firsttrack, firstsector, bytecounter;
gertk 0:28557a4d2215 3413 unsigned char track, sector, nexttrack, nextsector;
gertk 0:28557a4d2215 3414 unsigned int blocksize;
gertk 0:28557a4d2215 3415
gertk 0:28557a4d2215 3416 blocksize = 0;
gertk 0:28557a4d2215 3417
gertk 0:28557a4d2215 3418 /*search for the first block location of the file to be saved*/
gertk 0:28557a4d2215 3419 if (!D64SeekFreeBlock(&track, &sector))
gertk 0:28557a4d2215 3420 {
gertk 0:28557a4d2215 3421 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3422 return(FALSE);
gertk 0:28557a4d2215 3423 }
gertk 0:28557a4d2215 3424
gertk 0:28557a4d2215 3425 firsttrack = track;
gertk 0:28557a4d2215 3426 firstsector = sector;
gertk 0:28557a4d2215 3427 nexttrack = track; /*update the track variable*/
gertk 0:28557a4d2215 3428 nextsector = sector; /*update the track variable*/
gertk 0:28557a4d2215 3429 EOI = 0;
gertk 0:28557a4d2215 3430 while(EOI == 0)
gertk 0:28557a4d2215 3431 {
gertk 0:28557a4d2215 3432 blocksize++; /*increment blocksize counter*/
gertk 0:28557a4d2215 3433 track = nexttrack; /*update the track variable*/
gertk 0:28557a4d2215 3434 sector = nextsector; /*update the track variable*/
gertk 0:28557a4d2215 3435 if (!D64BlockAllocate(track, sector)) /*claim the next block, update the BAM*/
gertk 0:28557a4d2215 3436 {
gertk 0:28557a4d2215 3437 SetErrorCode(71,LED_ERROR); /*error: BAM is corrupt a flag has allready been cleared*/
gertk 0:28557a4d2215 3438 return(FALSE); /*somebody or somthing has been messing with the BAM*/
gertk 0:28557a4d2215 3439 }
gertk 0:28557a4d2215 3440 fbpt = D64ReadFreeBlocksPerTrack(track) - 1; /*decrement counter*/
gertk 0:28557a4d2215 3441 D64WriteFreeBlocksPerTrack(track, fbpt); /*save new value to BAM*/
gertk 0:28557a4d2215 3442 if (!D64SeekFreeBlock(&nexttrack, &nextsector)) /*search for the next block location of the file to be saved*/
gertk 0:28557a4d2215 3443 {
gertk 0:28557a4d2215 3444 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3445 return(FALSE);
gertk 0:28557a4d2215 3446 }
gertk 0:28557a4d2215 3447 /*the first two bytes of each block consist the 'track' and 'sector' of the next block*/
gertk 0:28557a4d2215 3448 RAM_buffer[0] = nexttrack; /*track of next block*/
gertk 0:28557a4d2215 3449 RAM_buffer[1] = nextsector; /*sector of next block*/
gertk 0:28557a4d2215 3450
gertk 0:28557a4d2215 3451 /*collect enough bytes to fill a block*/
gertk 0:28557a4d2215 3452 bytecounter = 2; /*byte counter to keep track of the position of the last byte within the file, since the first 2 bytes of the block are allways filled with non-data, we must add an offset of 2*/
gertk 0:28557a4d2215 3453 for(lp=2;lp!=0;lp++)
gertk 0:28557a4d2215 3454 {
gertk 0:28557a4d2215 3455 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3456 RAM_buffer[lp] = IEC_receive(TRUE); /*receive a byte and acknowledge with a frame handshake*/
gertk 0:28557a4d2215 3457 bytecounter++;
gertk 0:28557a4d2215 3458 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 3459 // printf(",%02x", RAM_buffer[lp]); /*dump all received bytes to serial port*/
gertk 0:28557a4d2215 3460 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 3461 if (EOI == 1)
gertk 0:28557a4d2215 3462 {
gertk 0:28557a4d2215 3463 RAM_buffer[0] = 0; /*there is no next block so the track value is an impossible one*/
gertk 0:28557a4d2215 3464 RAM_buffer[1] = bytecounter; /*there is no next block so the sector value is the position of the last byte*/
gertk 0:28557a4d2215 3465 do
gertk 0:28557a4d2215 3466 {
gertk 0:28557a4d2215 3467 RAM_buffer[bytecounter] = 0x00; /*fill the remaining area with 0x00*/
gertk 0:28557a4d2215 3468 bytecounter++;
gertk 0:28557a4d2215 3469 }
gertk 0:28557a4d2215 3470 while(bytecounter!=0);
gertk 0:28557a4d2215 3471 break;
gertk 0:28557a4d2215 3472 }
gertk 0:28557a4d2215 3473
gertk 0:28557a4d2215 3474 if (lp == Blink_block)
gertk 0:28557a4d2215 3475 SetErrorCode(0,LED_OFF); /*turn LED off, to create a small blink at every block*/
gertk 0:28557a4d2215 3476 }
gertk 0:28557a4d2215 3477
gertk 0:28557a4d2215 3478 print_D64_TSB(track, sector, 0,blocksize); /*print track, sector, remaining blocks and total number of blocks*/
gertk 0:28557a4d2215 3479 D64BlockWrite(track, sector); /*write the block to D64*/
gertk 0:28557a4d2215 3480 }
gertk 0:28557a4d2215 3481
gertk 0:28557a4d2215 3482 /*write the filename to the directory*/
gertk 0:28557a4d2215 3483 if (!D64AddDirEntry(0x82,firsttrack,firstsector,command_string,blocksize,0,0,0,0,0))
gertk 0:28557a4d2215 3484 {
gertk 0:28557a4d2215 3485 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3486 print_D64_TSB(track, sector, blocksize, blocksize); /*print track, sector and remaining blocks and a fully filled bar*/
gertk 0:28557a4d2215 3487 return(FALSE);
gertk 0:28557a4d2215 3488 }
gertk 0:28557a4d2215 3489
gertk 0:28557a4d2215 3490 SetErrorCode(0,LED_OFF); /*all is OK*/
gertk 0:28557a4d2215 3491 print_D64_TSB(track, sector, 0, blocksize); /*print track, sector, remaining blocks creating a fully filled bar*/
gertk 0:28557a4d2215 3492 return(TRUE);
gertk 0:28557a4d2215 3493 }
gertk 0:28557a4d2215 3494
gertk 0:28557a4d2215 3495 /*Copy a file within the D64, this requires the complete DOS handling !!!*/
gertk 0:28557a4d2215 3496 /*the filename is stored in command_string*/
gertk 0:28557a4d2215 3497 unsigned char CopyD64File(unsigned char trk, unsigned char sec, unsigned int filesizeinblocks)
gertk 0:28557a4d2215 3498 {
gertk 0:28557a4d2215 3499 unsigned int blocksrem;
gertk 0:28557a4d2215 3500 unsigned char fbpt, track, sector, nexttrack, nextsector;
gertk 0:28557a4d2215 3501
gertk 0:28557a4d2215 3502 blocksrem = filesizeinblocks;
gertk 0:28557a4d2215 3503 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3504
gertk 0:28557a4d2215 3505 /*search for the first block location of the new file to be saved*/
gertk 0:28557a4d2215 3506 if (!D64SeekFreeBlock(&track, &sector))
gertk 0:28557a4d2215 3507 {
gertk 0:28557a4d2215 3508 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3509 return(FALSE);
gertk 0:28557a4d2215 3510 }
gertk 0:28557a4d2215 3511
gertk 0:28557a4d2215 3512 /*check if there is enough room free on the disk for the required copy*/
gertk 0:28557a4d2215 3513 if (filesizeinblocks > D64LoadFreeBlocks()) /*read the number of free blocks from the D64 file*/
gertk 0:28557a4d2215 3514 {
gertk 0:28557a4d2215 3515 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3516 return(FALSE);
gertk 0:28557a4d2215 3517 }
gertk 0:28557a4d2215 3518
gertk 0:28557a4d2215 3519 /*write the filename to the directory, we can do that since we know the size of the file (ehhh. that's if it is written correctly*/
gertk 0:28557a4d2215 3520 /*but we may asume that this is the case for normal disk use. This saves us a lot of checkking. And creates a more readable code */
gertk 0:28557a4d2215 3521 D64AddDirEntry(0x82,track,sector,filename_string,filesizeinblocks,0,0,0,0,0);
gertk 0:28557a4d2215 3522
gertk 0:28557a4d2215 3523 while(blocksrem--)
gertk 0:28557a4d2215 3524 {
gertk 0:28557a4d2215 3525 if (!D64BlockAllocate(track, sector)) /*claim the next block, update the BAM*/
gertk 0:28557a4d2215 3526 {
gertk 0:28557a4d2215 3527 SetErrorCode(71,LED_ERROR); /*error: BAM is corrupt a flag has allready been cleared*/
gertk 0:28557a4d2215 3528 return(FALSE); /*somebody or somthing has been messing with the BAM*/
gertk 0:28557a4d2215 3529 }
gertk 0:28557a4d2215 3530 fbpt = D64ReadFreeBlocksPerTrack(track) - 1; /*decrement counter*/
gertk 0:28557a4d2215 3531 D64WriteFreeBlocksPerTrack(track, fbpt); /*save new value to BAM*/
gertk 0:28557a4d2215 3532
gertk 0:28557a4d2215 3533 /*search for the first block location of the new file to be saved*/
gertk 0:28557a4d2215 3534 if (!D64SeekFreeBlock(&nexttrack, &nextsector))
gertk 0:28557a4d2215 3535 {
gertk 0:28557a4d2215 3536 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3537 return(FALSE);
gertk 0:28557a4d2215 3538 }
gertk 0:28557a4d2215 3539 print_D64_TSB(trk, sec, blocksrem, filesizeinblocks); /*print track, sector and remaining blocks*/
gertk 0:28557a4d2215 3540 D64BlockRead(trk,sec); /*this routine reads a block of a req. track-sector of a D64 into the RAM_buffer*/
gertk 0:28557a4d2215 3541 trk = RAM_buffer[0]; /*the next track to be read*/
gertk 0:28557a4d2215 3542 sec = RAM_buffer[1]; /*the next sector within that track*/
gertk 0:28557a4d2215 3543 RAM_buffer[0] = nexttrack; /*track of next block*/
gertk 0:28557a4d2215 3544 RAM_buffer[1] = nextsector; /*sector of next block*/
gertk 0:28557a4d2215 3545 D64BlockWrite(track, sector); /*this routine write the contents of the RAM_buffer to the req. track-sector of the D64 file*/
gertk 0:28557a4d2215 3546
gertk 0:28557a4d2215 3547 track = nexttrack; /*for the next block, set the correct next track and sector*/
gertk 0:28557a4d2215 3548 sector = nextsector;
gertk 0:28557a4d2215 3549 }
gertk 0:28557a4d2215 3550
gertk 0:28557a4d2215 3551 /*write last block of the file*/
gertk 0:28557a4d2215 3552 print_D64_TSB(trk, sec, blocksrem, filesizeinblocks); /*print track, sector and remaining blocks*/
gertk 0:28557a4d2215 3553 D64BlockRead(trk,sec); /*this routine reads a block of a req. track-sector of a D64 into the RAM_buffer*/
gertk 0:28557a4d2215 3554 D64BlockWrite(track, sector); /*this routine write the contents of the RAM_buffer to the req. track-sector of the D64 file*/
gertk 0:28557a4d2215 3555 SetErrorCode(0,LED_OFF); /*all is OK*/
gertk 0:28557a4d2215 3556 return(TRUE);
gertk 0:28557a4d2215 3557 }
gertk 0:28557a4d2215 3558
gertk 0:28557a4d2215 3559
gertk 0:28557a4d2215 3560 /*this routine clears the entire block_buffer*/
gertk 0:28557a4d2215 3561 void Clear_block_buffer(void)
gertk 0:28557a4d2215 3562 {
gertk 0:28557a4d2215 3563 unsigned int lp;
gertk 0:28557a4d2215 3564
gertk 0:28557a4d2215 3565 lp=0;
gertk 0:28557a4d2215 3566 do
gertk 0:28557a4d2215 3567 {
gertk 0:28557a4d2215 3568 block_buffer[lp] = 0x00;
gertk 0:28557a4d2215 3569 lp++;
gertk 0:28557a4d2215 3570 }
gertk 0:28557a4d2215 3571 while(lp<512);
gertk 0:28557a4d2215 3572 }
gertk 0:28557a4d2215 3573
gertk 0:28557a4d2215 3574 /*this routine formats the currently selected D64 image so it can be used to save your programs/data to*/
gertk 0:28557a4d2215 3575 /*the abillity not being able to create a new file saves us the effort of implementing a lot of FAT related actions*/
gertk 0:28557a4d2215 3576 /*Attention: this command does not implement the user options (disk label,disk ID). This command is for firmware & media testing purposes only*/
gertk 0:28557a4d2215 3577 void FormatD64File(unsigned char *diskname, unsigned char *diskid)
gertk 0:28557a4d2215 3578 { /* '*filename' is actually the complete command_string as given by the user, this referencename is misleading and needs to be changed*/
gertk 0:28557a4d2215 3579
gertk 0:28557a4d2215 3580 unsigned int block_counter=0;
gertk 0:28557a4d2215 3581 unsigned char lp,lp2,tr,se;
gertk 0:28557a4d2215 3582
gertk 0:28557a4d2215 3583 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3584 print_D64_TSB(0,0,(341-block_counter),341);
gertk 0:28557a4d2215 3585
gertk 0:28557a4d2215 3586 /*fill track 1 upto and including track 17 (all 21) sectors with 0x00*/
gertk 0:28557a4d2215 3587 /*each MMC/SD-card block = 512 bytes, each D64 block = 256 bytes */
gertk 0:28557a4d2215 3588 /*17 tracks * 21 sectors = 357 D64 blocks or 178.5 MMC/SD-card blocks*/
gertk 0:28557a4d2215 3589 Clear_block_buffer(); /*clear the block_buffer*/
gertk 0:28557a4d2215 3590 do
gertk 0:28557a4d2215 3591 {
gertk 0:28557a4d2215 3592 D64ConvertBlockToTrackSector((block_counter<<1), &tr, &se);
gertk 0:28557a4d2215 3593 print_D64_TSB(tr,se,(341-block_counter),341);
gertk 0:28557a4d2215 3594 FileWriteSector_X(&file, block_counter);
gertk 0:28557a4d2215 3595 block_counter++;
gertk 0:28557a4d2215 3596 }
gertk 0:28557a4d2215 3597 while(block_counter < 178);
gertk 0:28557a4d2215 3598
gertk 0:28557a4d2215 3599 block_buffer[256+0] = 18; /*track of next block*/
gertk 0:28557a4d2215 3600 block_buffer[256+1] = 18; /*sector of next block*/
gertk 0:28557a4d2215 3601 block_buffer[256+2] = 65;
gertk 0:28557a4d2215 3602 block_buffer[256+3] = 0;
gertk 0:28557a4d2215 3603 block_buffer[256+4] = 0x15; /*number of sectors within track-1*/
gertk 0:28557a4d2215 3604 block_buffer[256+5] = 0xff;
gertk 0:28557a4d2215 3605 block_buffer[256+6] = 0xff;
gertk 0:28557a4d2215 3606 block_buffer[256+7] = 0x1f;
gertk 0:28557a4d2215 3607 block_buffer[256+8] = 0x15; /*number of sectors within track-2*/
gertk 0:28557a4d2215 3608 block_buffer[256+9] = 0xff;
gertk 0:28557a4d2215 3609 block_buffer[256+10] = 0xff;
gertk 0:28557a4d2215 3610 block_buffer[256+11] = 0x1f;
gertk 0:28557a4d2215 3611 block_buffer[256+12] = 0x15; /*number of sectors within track-3*/
gertk 0:28557a4d2215 3612 block_buffer[256+13] = 0xff;
gertk 0:28557a4d2215 3613 block_buffer[256+14] = 0xff;
gertk 0:28557a4d2215 3614 block_buffer[256+15] = 0x1f;
gertk 0:28557a4d2215 3615 block_buffer[256+16] = 0x15; /*number of sectors within track-4*/
gertk 0:28557a4d2215 3616 block_buffer[256+17] = 0xff;
gertk 0:28557a4d2215 3617 block_buffer[256+18] = 0xff;
gertk 0:28557a4d2215 3618 block_buffer[256+19] = 0x1f;
gertk 0:28557a4d2215 3619 block_buffer[256+20] = 0x15; /*number of sectors within track-5*/
gertk 0:28557a4d2215 3620 block_buffer[256+21] = 0xff;
gertk 0:28557a4d2215 3621 block_buffer[256+22] = 0xff;
gertk 0:28557a4d2215 3622 block_buffer[256+23] = 0x1f;
gertk 0:28557a4d2215 3623 block_buffer[256+24] = 0x15; /*number of sectors within track-6*/
gertk 0:28557a4d2215 3624 block_buffer[256+25] = 0xff;
gertk 0:28557a4d2215 3625 block_buffer[256+26] = 0xff;
gertk 0:28557a4d2215 3626 block_buffer[256+27] = 0x1f;
gertk 0:28557a4d2215 3627 block_buffer[256+28] = 0x15; /*number of sectors within track-7*/
gertk 0:28557a4d2215 3628 block_buffer[256+29] = 0xff;
gertk 0:28557a4d2215 3629 block_buffer[256+30] = 0xff;
gertk 0:28557a4d2215 3630 block_buffer[256+31] = 0x1f;
gertk 0:28557a4d2215 3631 block_buffer[256+32] = 0x15; /*number of sectors within track-8*/
gertk 0:28557a4d2215 3632 block_buffer[256+33] = 0xff;
gertk 0:28557a4d2215 3633 block_buffer[256+34] = 0xff;
gertk 0:28557a4d2215 3634 block_buffer[256+35] = 0x1f;
gertk 0:28557a4d2215 3635 block_buffer[256+36] = 0x15; /*number of sectors within track-9*/
gertk 0:28557a4d2215 3636 block_buffer[256+37] = 0xff;
gertk 0:28557a4d2215 3637 block_buffer[256+38] = 0xff;
gertk 0:28557a4d2215 3638 block_buffer[256+39] = 0x1f;
gertk 0:28557a4d2215 3639 block_buffer[256+40] = 0x15; /*number of sectors within track-10*/
gertk 0:28557a4d2215 3640 block_buffer[256+41] = 0xff;
gertk 0:28557a4d2215 3641 block_buffer[256+42] = 0xff;
gertk 0:28557a4d2215 3642 block_buffer[256+43] = 0x1f;
gertk 0:28557a4d2215 3643 block_buffer[256+44] = 0x15; /*number of sectors within track-11*/
gertk 0:28557a4d2215 3644 block_buffer[256+45] = 0xff;
gertk 0:28557a4d2215 3645 block_buffer[256+46] = 0xff;
gertk 0:28557a4d2215 3646 block_buffer[256+47] = 0x1f;
gertk 0:28557a4d2215 3647 block_buffer[256+48] = 0x15; /*number of sectors within track-12*/
gertk 0:28557a4d2215 3648 block_buffer[256+49] = 0xff;
gertk 0:28557a4d2215 3649 block_buffer[256+50] = 0xff;
gertk 0:28557a4d2215 3650 block_buffer[256+51] = 0x1f;
gertk 0:28557a4d2215 3651 block_buffer[256+52] = 0x15; /*number of sectors within track-13*/
gertk 0:28557a4d2215 3652 block_buffer[256+53] = 0xff;
gertk 0:28557a4d2215 3653 block_buffer[256+54] = 0xff;
gertk 0:28557a4d2215 3654 block_buffer[256+55] = 0x1f;
gertk 0:28557a4d2215 3655 block_buffer[256+56] = 0x15; /*number of sectors within track-14*/
gertk 0:28557a4d2215 3656 block_buffer[256+57] = 0xff;
gertk 0:28557a4d2215 3657 block_buffer[256+58] = 0xff;
gertk 0:28557a4d2215 3658 block_buffer[256+59] = 0x1f;
gertk 0:28557a4d2215 3659 block_buffer[256+60] = 0x15; /*number of sectors within track-15*/
gertk 0:28557a4d2215 3660 block_buffer[256+61] = 0xff;
gertk 0:28557a4d2215 3661 block_buffer[256+62] = 0xff;
gertk 0:28557a4d2215 3662 block_buffer[256+63] = 0x1f;
gertk 0:28557a4d2215 3663 block_buffer[256+64] = 0x15; /*number of sectors within track-16*/
gertk 0:28557a4d2215 3664 block_buffer[256+65] = 0xff;
gertk 0:28557a4d2215 3665 block_buffer[256+66] = 0xff;
gertk 0:28557a4d2215 3666 block_buffer[256+67] = 0x1f;
gertk 0:28557a4d2215 3667 block_buffer[256+68] = 0x15; /*number of sectors within track-17*/
gertk 0:28557a4d2215 3668 block_buffer[256+69] = 0xff;
gertk 0:28557a4d2215 3669 block_buffer[256+70] = 0xff;
gertk 0:28557a4d2215 3670 block_buffer[256+71] = 0x1f;
gertk 0:28557a4d2215 3671 block_buffer[256+72] = 0x11; /*number of sectors within track-18*/
gertk 0:28557a4d2215 3672 block_buffer[256+73] = 0xfc;
gertk 0:28557a4d2215 3673 block_buffer[256+74] = 0xff;
gertk 0:28557a4d2215 3674 block_buffer[256+75] = 0x07;
gertk 0:28557a4d2215 3675 block_buffer[256+76] = 0x13; /*number of sectors within track-19*/
gertk 0:28557a4d2215 3676 block_buffer[256+77] = 0xff;
gertk 0:28557a4d2215 3677 block_buffer[256+78] = 0xff;
gertk 0:28557a4d2215 3678 block_buffer[256+79] = 0x07;
gertk 0:28557a4d2215 3679 block_buffer[256+80] = 0x13; /*number of sectors within track-20*/
gertk 0:28557a4d2215 3680 block_buffer[256+81] = 0xff;
gertk 0:28557a4d2215 3681 block_buffer[256+82] = 0xff;
gertk 0:28557a4d2215 3682 block_buffer[256+83] = 0x07;
gertk 0:28557a4d2215 3683 block_buffer[256+84] = 0x13; /*number of sectors within track-21*/
gertk 0:28557a4d2215 3684 block_buffer[256+85] = 0xff;
gertk 0:28557a4d2215 3685 block_buffer[256+86] = 0xff;
gertk 0:28557a4d2215 3686 block_buffer[256+87] = 0x07;
gertk 0:28557a4d2215 3687 block_buffer[256+88] = 0x13; /*number of sectors within track-22*/
gertk 0:28557a4d2215 3688 block_buffer[256+89] = 0xff;
gertk 0:28557a4d2215 3689 block_buffer[256+90] = 0xff;
gertk 0:28557a4d2215 3690 block_buffer[256+91] = 0x07;
gertk 0:28557a4d2215 3691 block_buffer[256+92] = 0x13; /*number of sectors within track-23*/
gertk 0:28557a4d2215 3692 block_buffer[256+93] = 0xff;
gertk 0:28557a4d2215 3693 block_buffer[256+94] = 0xff;
gertk 0:28557a4d2215 3694 block_buffer[256+95] = 0x07;
gertk 0:28557a4d2215 3695 block_buffer[256+96] = 0x13; /*number of sectors within track-24*/
gertk 0:28557a4d2215 3696 block_buffer[256+97] = 0xff;
gertk 0:28557a4d2215 3697 block_buffer[256+98] = 0xff;
gertk 0:28557a4d2215 3698 block_buffer[256+99] = 0x07;
gertk 0:28557a4d2215 3699 block_buffer[256+100] = 0x12; /*number of sectors within track-25*/
gertk 0:28557a4d2215 3700 block_buffer[256+101] = 0xff;
gertk 0:28557a4d2215 3701 block_buffer[256+102] = 0xff;
gertk 0:28557a4d2215 3702 block_buffer[256+103] = 0x03;
gertk 0:28557a4d2215 3703 block_buffer[256+104] = 0x12; /*number of sectors within track-26*/
gertk 0:28557a4d2215 3704 block_buffer[256+105] = 0xff;
gertk 0:28557a4d2215 3705 block_buffer[256+106] = 0xff;
gertk 0:28557a4d2215 3706 block_buffer[256+107] = 0x03;
gertk 0:28557a4d2215 3707 block_buffer[256+108] = 0x12; /*number of sectors within track-27*/
gertk 0:28557a4d2215 3708 block_buffer[256+109] = 0xff;
gertk 0:28557a4d2215 3709 block_buffer[256+110] = 0xff;
gertk 0:28557a4d2215 3710 block_buffer[256+111] = 0x03;
gertk 0:28557a4d2215 3711 block_buffer[256+112] = 0x12; /*number of sectors within track-28*/
gertk 0:28557a4d2215 3712 block_buffer[256+113] = 0xff;
gertk 0:28557a4d2215 3713 block_buffer[256+114] = 0xff;
gertk 0:28557a4d2215 3714 block_buffer[256+115] = 0x03;
gertk 0:28557a4d2215 3715 block_buffer[256+116] = 0x12; /*number of sectors within track-29*/
gertk 0:28557a4d2215 3716 block_buffer[256+117] = 0xff;
gertk 0:28557a4d2215 3717 block_buffer[256+118] = 0xff;
gertk 0:28557a4d2215 3718 block_buffer[256+119] = 0x03;
gertk 0:28557a4d2215 3719 block_buffer[256+120] = 0x12; /*number of sectors within track-30*/
gertk 0:28557a4d2215 3720 block_buffer[256+121] = 0xff;
gertk 0:28557a4d2215 3721 block_buffer[256+122] = 0xff;
gertk 0:28557a4d2215 3722 block_buffer[256+123] = 0x03;
gertk 0:28557a4d2215 3723 block_buffer[256+124] = 0x11; /*number of sectors within track-31*/
gertk 0:28557a4d2215 3724 block_buffer[256+125] = 0xff;
gertk 0:28557a4d2215 3725 block_buffer[256+126] = 0xff;
gertk 0:28557a4d2215 3726 block_buffer[256+127] = 0x01;
gertk 0:28557a4d2215 3727 block_buffer[256+128] = 0x11; /*number of sectors within track-32*/
gertk 0:28557a4d2215 3728 block_buffer[256+129] = 0xff;
gertk 0:28557a4d2215 3729 block_buffer[256+130] = 0xff;
gertk 0:28557a4d2215 3730 block_buffer[256+131] = 0x01;
gertk 0:28557a4d2215 3731 block_buffer[256+132] = 0x11; /*number of sectors within track-33*/
gertk 0:28557a4d2215 3732 block_buffer[256+133] = 0xff;
gertk 0:28557a4d2215 3733 block_buffer[256+134] = 0xff;
gertk 0:28557a4d2215 3734 block_buffer[256+135] = 0x01;
gertk 0:28557a4d2215 3735 block_buffer[256+136] = 0x11; /*number of sectors within track-34*/
gertk 0:28557a4d2215 3736 block_buffer[256+137] = 0xff;
gertk 0:28557a4d2215 3737 block_buffer[256+138] = 0xff;
gertk 0:28557a4d2215 3738 block_buffer[256+139] = 0x01;
gertk 0:28557a4d2215 3739 block_buffer[256+140] = 0x11; /*number of sectors within track-35*/
gertk 0:28557a4d2215 3740 block_buffer[256+141] = 0xff;
gertk 0:28557a4d2215 3741 block_buffer[256+142] = 0xff;
gertk 0:28557a4d2215 3742 block_buffer[256+143] = 0x01;
gertk 0:28557a4d2215 3743
gertk 0:28557a4d2215 3744 lp2=0;
gertk 0:28557a4d2215 3745 lp=144;
gertk 0:28557a4d2215 3746
gertk 0:28557a4d2215 3747 while((lp<160) && (diskname[lp2] != 0)) /*diskname*/
gertk 0:28557a4d2215 3748 { /*--------*/
gertk 0:28557a4d2215 3749 block_buffer[256+lp] = diskname[lp2]; /*copy character*/
gertk 0:28557a4d2215 3750 lp2++;
gertk 0:28557a4d2215 3751 lp++;
gertk 0:28557a4d2215 3752 }
gertk 0:28557a4d2215 3753 while (lp<160)
gertk 0:28557a4d2215 3754 {
gertk 0:28557a4d2215 3755 block_buffer[256+lp] = 160; /*fill unused locations with shifted spaces, default value*/
gertk 0:28557a4d2215 3756 lp++;
gertk 0:28557a4d2215 3757 }
gertk 0:28557a4d2215 3758
gertk 0:28557a4d2215 3759 block_buffer[256+160] = 160;
gertk 0:28557a4d2215 3760 block_buffer[256+161] = 160;
gertk 0:28557a4d2215 3761
gertk 0:28557a4d2215 3762 if (diskid[0] == 0) /*disk-ID*/
gertk 0:28557a4d2215 3763 { /*-------*/
gertk 0:28557a4d2215 3764 block_buffer[256+162] = '0'; /*default value*/
gertk 0:28557a4d2215 3765 block_buffer[256+163] = '0'; /*default value*/
gertk 0:28557a4d2215 3766 }
gertk 0:28557a4d2215 3767 else
gertk 0:28557a4d2215 3768 {
gertk 0:28557a4d2215 3769 block_buffer[256+162] = diskid[0]; /*copy character*/
gertk 0:28557a4d2215 3770 if (diskid[1] == 0)
gertk 0:28557a4d2215 3771 {
gertk 0:28557a4d2215 3772 block_buffer[256+163] = 160; /*default value*/
gertk 0:28557a4d2215 3773 }
gertk 0:28557a4d2215 3774 else
gertk 0:28557a4d2215 3775 {
gertk 0:28557a4d2215 3776 block_buffer[256+163] = diskid[1]; /*copy character*/
gertk 0:28557a4d2215 3777 }
gertk 0:28557a4d2215 3778 }
gertk 0:28557a4d2215 3779
gertk 0:28557a4d2215 3780 block_buffer[256+164] = 160;
gertk 0:28557a4d2215 3781 block_buffer[256+165] = 50; /*DOS VERSION*/
gertk 0:28557a4d2215 3782 block_buffer[256+166] = 65; /*DOS VERSION*/
gertk 0:28557a4d2215 3783 block_buffer[256+167] = 160;
gertk 0:28557a4d2215 3784 block_buffer[256+168] = 160;
gertk 0:28557a4d2215 3785 block_buffer[256+169] = 160;
gertk 0:28557a4d2215 3786 block_buffer[256+170] = 160;
gertk 0:28557a4d2215 3787
gertk 0:28557a4d2215 3788 lp = 171;
gertk 0:28557a4d2215 3789 while (lp != 0) /*fill remaining bytes from 171 up to and including 255 with 0x00*/
gertk 0:28557a4d2215 3790 {
gertk 0:28557a4d2215 3791 block_buffer[256+lp] = 0x00;
gertk 0:28557a4d2215 3792 lp++;
gertk 0:28557a4d2215 3793 }
gertk 0:28557a4d2215 3794
gertk 0:28557a4d2215 3795 D64ConvertBlockToTrackSector((block_counter<<1), &tr, &se);
gertk 0:28557a4d2215 3796 print_D64_TSB(tr,se,(341-block_counter),341);
gertk 0:28557a4d2215 3797 FileWriteSector_X(&file, block_counter);
gertk 0:28557a4d2215 3798 block_counter++;
gertk 0:28557a4d2215 3799
gertk 0:28557a4d2215 3800 /*fill remaining tracks 18-1 to 35-16 with 0x00 */
gertk 0:28557a4d2215 3801 /*each MMC/SD-card block = 512 bytes, each D64 block = 256 bytes */
gertk 0:28557a4d2215 3802 Clear_block_buffer(); /*clear the block_buffer*/
gertk 0:28557a4d2215 3803 do
gertk 0:28557a4d2215 3804 {
gertk 0:28557a4d2215 3805 D64ConvertBlockToTrackSector((block_counter<<1), &tr, &se);
gertk 0:28557a4d2215 3806 print_D64_TSB(tr,se,(341-block_counter),341);
gertk 0:28557a4d2215 3807 FileWriteSector_X(&file, block_counter);
gertk 0:28557a4d2215 3808 block_counter++;
gertk 0:28557a4d2215 3809 }
gertk 0:28557a4d2215 3810 while(block_counter < 342);
gertk 0:28557a4d2215 3811 SetErrorCode(0,LED_OFF);
gertk 0:28557a4d2215 3812 }
gertk 0:28557a4d2215 3813
gertk 0:28557a4d2215 3814 /*this routine is to be used to handle the errorcode and the LED-blink-mode in an easy way*/
gertk 0:28557a4d2215 3815 void SetErrorCode(unsigned char error, unsigned char LEDmode)
gertk 0:28557a4d2215 3816 {
gertk 0:28557a4d2215 3817 /*the original 1541 used the LED to display the results of the power-on selftest*/
gertk 0:28557a4d2215 3818 /* No Blink Kernal (E000-FFFF) ROM or 6522 VIA Failure */
gertk 0:28557a4d2215 3819 /* One Blink 6116 RAM Failure */
gertk 0:28557a4d2215 3820 /* Two Blinks Possible Zero Page RAM Failure */
gertk 0:28557a4d2215 3821 /* Three Blinks DOS (C000-CFFF) ROM Failure */
gertk 0:28557a4d2215 3822 /* Four Blinks DOS (C000-CFFF) ROM Failure */
gertk 0:28557a4d2215 3823 /* Five Blinks 6116 RAM Failure */
gertk 0:28557a4d2215 3824 /* Six Blinks 6116 RAM Failure */
gertk 0:28557a4d2215 3825 /* Seven Blinks 6116 RAM Failure */
gertk 0:28557a4d2215 3826 /* Eight Blinks 6116 RAM Failure */
gertk 0:28557a4d2215 3827 /*Note: at this moment the selftest (and it's blinking modes) is/are not supported (yet)*/
gertk 0:28557a4d2215 3828
gertk 0:28557a4d2215 3829 if ((error == 0) && (error_code == 73)) /*when there is no error-73 to maintain (ROM version), change to the new error_code*/
gertk 0:28557a4d2215 3830 {
gertk 0:28557a4d2215 3831 /*do not change the error_code, because there is no error and the code 73 must be preserved*/
gertk 0:28557a4d2215 3832 }
gertk 0:28557a4d2215 3833 else
gertk 0:28557a4d2215 3834 {
gertk 0:28557a4d2215 3835 if (error != error_code) /*only update the screen when the error_code has changed*/
gertk 0:28557a4d2215 3836 { /*because when there is no new info... there is no reason to print to the display what is allready there*/
gertk 0:28557a4d2215 3837 error_code = error;
gertk 0:28557a4d2215 3838 // Lcd_XY_address(2,4); /*if there is any printing to the display to be done, it must be done on line...*/
gertk 0:28557a4d2215 3839 printf("%02d",error_code); /*show the error code*/
gertk 0:28557a4d2215 3840 }
gertk 0:28557a4d2215 3841
gertk 0:28557a4d2215 3842 // if ((error == 21) || (error == 62)) /*these error(s) create this sound (i.e. error 62 = file not found)*/
gertk 0:28557a4d2215 3843 // PlaySample_HeadBangRattle(); /*play sample that suits this error situation*/
gertk 0:28557a4d2215 3844 }
gertk 0:28557a4d2215 3845
gertk 0:28557a4d2215 3846 switch(LEDmode)
gertk 0:28557a4d2215 3847 {
gertk 0:28557a4d2215 3848 case LED_OFF:
gertk 0:28557a4d2215 3849 {
gertk 0:28557a4d2215 3850 // TMR0ON = 0; /*switch timer-0 OFF*/
gertk 0:28557a4d2215 3851 LED_GREEN = 0; /*switch LED-OFF*/
gertk 0:28557a4d2215 3852 LED_RED = 0; /*switch LED-OFF*/
gertk 0:28557a4d2215 3853 break;
gertk 0:28557a4d2215 3854 }
gertk 0:28557a4d2215 3855
gertk 0:28557a4d2215 3856 case LED_ON:
gertk 0:28557a4d2215 3857 {
gertk 0:28557a4d2215 3858 // TMR0ON = 0; /*switch timer-0 OFF*/
gertk 0:28557a4d2215 3859 LED_GREEN = 1; /*switch LED-ON*/
gertk 0:28557a4d2215 3860 LED_RED = 0; /*switch LED-ON*/
gertk 0:28557a4d2215 3861 break;
gertk 0:28557a4d2215 3862 }
gertk 0:28557a4d2215 3863
gertk 0:28557a4d2215 3864
gertk 0:28557a4d2215 3865 case LED_ERROR:
gertk 0:28557a4d2215 3866 {
gertk 0:28557a4d2215 3867 Blink_mode = LED_ERROR;
gertk 0:28557a4d2215 3868 LED_status = 0; /*status of the LED (0=OFF)*/
gertk 0:28557a4d2215 3869 // TMR0H = 0xFF; /*set registers to enter timer-o interrupt as quickly as possible*/
gertk 0:28557a4d2215 3870 // TMR0L = 0xFF;
gertk 0:28557a4d2215 3871 // TMR0ON = 1; /*switch timer-0 on*/
gertk 0:28557a4d2215 3872 break;
gertk 0:28557a4d2215 3873 }
gertk 0:28557a4d2215 3874
gertk 0:28557a4d2215 3875 default:
gertk 0:28557a4d2215 3876 {
gertk 0:28557a4d2215 3877 // TMR0ON = 0; /*switch timer-0 OFF*/
gertk 0:28557a4d2215 3878 LED_GREEN = 0; /*switch LED-OFF*/
gertk 0:28557a4d2215 3879 LED_RED = 0; /*switch LED-OFF*/
gertk 0:28557a4d2215 3880 }
gertk 0:28557a4d2215 3881 }
gertk 0:28557a4d2215 3882 }
gertk 0:28557a4d2215 3883
gertk 0:28557a4d2215 3884 void SendErrorMessage(void)
gertk 0:28557a4d2215 3885 {
gertk 0:28557a4d2215 3886 EOI = FALSE;
gertk 0:28557a4d2215 3887 LED_GREEN = 1; /*drive LED-ON*/
gertk 0:28557a4d2215 3888 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 3889 IEC_send_number_as_ASCII(error_code); /*send error-code*/
gertk 0:28557a4d2215 3890 IEC_send(0x2C); /*','*/
gertk 0:28557a4d2215 3891
gertk 0:28557a4d2215 3892 switch (error_code)
gertk 0:28557a4d2215 3893 {
gertk 0:28557a4d2215 3894 case 0: /*OK (not an error*/
gertk 0:28557a4d2215 3895 {
gertk 0:28557a4d2215 3896 IEC_send_string("OK");
gertk 0:28557a4d2215 3897 break;
gertk 0:28557a4d2215 3898 }
gertk 0:28557a4d2215 3899
gertk 0:28557a4d2215 3900 case 1: /*files scratched (not an error)*/
gertk 0:28557a4d2215 3901 {
gertk 0:28557a4d2215 3902 IEC_send_string("FILES SCRATCHED");
gertk 0:28557a4d2215 3903 break;
gertk 0:28557a4d2215 3904 }
gertk 0:28557a4d2215 3905
gertk 0:28557a4d2215 3906 case 2:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3907 case 3:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3908 case 4:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3909 case 5:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3910 case 6:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3911 case 7:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3912 case 8:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3913 case 9:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3914 case 10:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3915 case 11:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3916 case 12:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3917 case 13:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3918 case 14:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3919 case 15:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3920 case 16:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3921 case 17:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3922 case 18:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3923 case 19: /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3924 {
gertk 0:28557a4d2215 3925 IEC_send_string("N/A");
gertk 0:28557a4d2215 3926 break;
gertk 0:28557a4d2215 3927 }
gertk 0:28557a4d2215 3928
gertk 0:28557a4d2215 3929 case 20:; /*Header descriptor byte not found ($08) Each sector is preceeded by an 8-byte header block, which starts with the value $08. If this value is not $08, this error is generated*/
gertk 0:28557a4d2215 3930 case 21:; /*Each sector data block and header block are preceeded by SYNC marks. If *no* sync sequence is found, then the whole track is unreadable, and likely unformatted.*/
gertk 0:28557a4d2215 3931 case 22:; /*Data descriptor byte not found ($07) Each sector data block is preceeded by the value $07, the[]= "data block" descriptor. If this value is not there, this error is generated. Each encoded sector has actually 260 bytes. First is the descriptor byte, then follows the 256 bytes of data, a checksum, and two[]= "off" bytes.*/
gertk 0:28557a4d2215 3932 case 23:; /*Checksum error in data block The checksum of the data read of the disk is calculated, and compared against the one stored at the end of the sector. If there's a discrepancy, this error is generated.*/
gertk 0:28557a4d2215 3933 case 24:; /*Write verify (on format) */
gertk 0:28557a4d2215 3934 case 27: /*Checksum error in header block The 8-byte header block contains a checksum value, calculated by XOR'ing the TRACK, SECTOR, ID1 and ID2 values. If this checksum is wrong, this error is generated.*/
gertk 0:28557a4d2215 3935 {
gertk 0:28557a4d2215 3936 IEC_send_string("READ ERROR");
gertk 0:28557a4d2215 3937 break;
gertk 0:28557a4d2215 3938 }
gertk 0:28557a4d2215 3939
gertk 0:28557a4d2215 3940 case 25:; /*Write verify error Once the GCR-encoded sector is written out, the drive waits for the sector to come around again and verifies the whole 325-byte GCR block. Any errors encountered will generate this error.*/
gertk 0:28557a4d2215 3941 case 28: /*Write error In actual fact, this error never occurs, but it is included for completeness.*/
gertk 0:28557a4d2215 3942 {
gertk 0:28557a4d2215 3943 IEC_send_string("WRITE ERROR");
gertk 0:28557a4d2215 3944 break;
gertk 0:28557a4d2215 3945 }
gertk 0:28557a4d2215 3946
gertk 0:28557a4d2215 3947 case 26: /*Write protect on Self explanatory. Remove the write-protect tab, and try again.*/
gertk 0:28557a4d2215 3948 {
gertk 0:28557a4d2215 3949 IEC_send_string("WRITE PROTECT ON");
gertk 0:28557a4d2215 3950 break;
gertk 0:28557a4d2215 3951 }
gertk 0:28557a4d2215 3952
gertk 0:28557a4d2215 3953 case 29: /*Disk sector ID mismatch The ID's from the header block of the currently read sector are compared against the ones from the header of 18/0. If there is a mismatch, this error is generated.*/
gertk 0:28557a4d2215 3954 {
gertk 0:28557a4d2215 3955 IEC_send_string("DISK ID MISMATCH");
gertk 0:28557a4d2215 3956 break;
gertk 0:28557a4d2215 3957 }
gertk 0:28557a4d2215 3958
gertk 0:28557a4d2215 3959 case 30:; /*general syntax error*/
gertk 0:28557a4d2215 3960 case 31:; /*invalid command*/
gertk 0:28557a4d2215 3961 case 32:; /*long line*/
gertk 0:28557a4d2215 3962 case 33:; /*invalid fileSelectedFileName*/
gertk 0:28557a4d2215 3963 case 34:; /*no file given*/
gertk 0:28557a4d2215 3964 case 39: /*command file not found*/
gertk 0:28557a4d2215 3965 {
gertk 0:28557a4d2215 3966 IEC_send_string("SYNTAX ERROR");
gertk 0:28557a4d2215 3967 break;
gertk 0:28557a4d2215 3968 }
gertk 0:28557a4d2215 3969
gertk 0:28557a4d2215 3970 case 50: /*record not present*/
gertk 0:28557a4d2215 3971 {
gertk 0:28557a4d2215 3972 IEC_send_string("RECORD NOT PRESENT");
gertk 0:28557a4d2215 3973 break;
gertk 0:28557a4d2215 3974 }
gertk 0:28557a4d2215 3975
gertk 0:28557a4d2215 3976 case 51: /*overflow in record*/
gertk 0:28557a4d2215 3977 {
gertk 0:28557a4d2215 3978 IEC_send_string("OVERFLOW IN RECORD");
gertk 0:28557a4d2215 3979 break;
gertk 0:28557a4d2215 3980 }
gertk 0:28557a4d2215 3981
gertk 0:28557a4d2215 3982 case 52: /*file too large*/
gertk 0:28557a4d2215 3983 {
gertk 0:28557a4d2215 3984 IEC_send_string("FILE TOO LARGE");
gertk 0:28557a4d2215 3985 break;
gertk 0:28557a4d2215 3986 }
gertk 0:28557a4d2215 3987
gertk 0:28557a4d2215 3988 case 60: /*File open for write*/
gertk 0:28557a4d2215 3989 {
gertk 0:28557a4d2215 3990 IEC_send_string("WRITE FILE OPEN");
gertk 0:28557a4d2215 3991 break;
gertk 0:28557a4d2215 3992 }
gertk 0:28557a4d2215 3993
gertk 0:28557a4d2215 3994 case 61: /*File not open*/
gertk 0:28557a4d2215 3995 {
gertk 0:28557a4d2215 3996 IEC_send_string("FILE NOT OPEN");
gertk 0:28557a4d2215 3997 break;
gertk 0:28557a4d2215 3998 }
gertk 0:28557a4d2215 3999
gertk 0:28557a4d2215 4000 case 62: /*File not found*/
gertk 0:28557a4d2215 4001 {
gertk 0:28557a4d2215 4002 IEC_send_string("FILE NOT FOUND");
gertk 0:28557a4d2215 4003 break;
gertk 0:28557a4d2215 4004 }
gertk 0:28557a4d2215 4005
gertk 0:28557a4d2215 4006 case 63: /*File exists*/
gertk 0:28557a4d2215 4007 {
gertk 0:28557a4d2215 4008 IEC_send_string("FILE EXISTS");
gertk 0:28557a4d2215 4009 break;
gertk 0:28557a4d2215 4010 }
gertk 0:28557a4d2215 4011
gertk 0:28557a4d2215 4012 case 64: /*File type mismatch*/
gertk 0:28557a4d2215 4013 {
gertk 0:28557a4d2215 4014 IEC_send_string("FILE TYPE MISMATCH");
gertk 0:28557a4d2215 4015 break;
gertk 0:28557a4d2215 4016 }
gertk 0:28557a4d2215 4017
gertk 0:28557a4d2215 4018 case 65: /*No block*/
gertk 0:28557a4d2215 4019 {
gertk 0:28557a4d2215 4020 IEC_send_string("NO BLOCK");
gertk 0:28557a4d2215 4021 break;
gertk 0:28557a4d2215 4022 }
gertk 0:28557a4d2215 4023
gertk 0:28557a4d2215 4024 case 66: /*Illegal track or sector*/
gertk 0:28557a4d2215 4025 {
gertk 0:28557a4d2215 4026 IEC_send_string("ILLEGAL TRACK AND SECTOR");
gertk 0:28557a4d2215 4027 break;
gertk 0:28557a4d2215 4028 }
gertk 0:28557a4d2215 4029
gertk 0:28557a4d2215 4030 case 67: /*Illegal system track or sector*/
gertk 0:28557a4d2215 4031 {
gertk 0:28557a4d2215 4032 IEC_send_string("ILLEGAL SYSTEM T OR S");
gertk 0:28557a4d2215 4033 break;
gertk 0:28557a4d2215 4034 }
gertk 0:28557a4d2215 4035
gertk 0:28557a4d2215 4036 case 70: /*No channels available*/
gertk 0:28557a4d2215 4037 {
gertk 0:28557a4d2215 4038 IEC_send_string("NO CHANNEL");
gertk 0:28557a4d2215 4039 break;
gertk 0:28557a4d2215 4040 }
gertk 0:28557a4d2215 4041
gertk 0:28557a4d2215 4042 case 71: /*Directory error*/
gertk 0:28557a4d2215 4043 {
gertk 0:28557a4d2215 4044 IEC_send_string("DIRECTORY ERROR");
gertk 0:28557a4d2215 4045 break;
gertk 0:28557a4d2215 4046 }
gertk 0:28557a4d2215 4047
gertk 0:28557a4d2215 4048 case 72: /*disk full or directory full*/
gertk 0:28557a4d2215 4049 {
gertk 0:28557a4d2215 4050 IEC_send_string("DISK FULL");
gertk 0:28557a4d2215 4051 break;
gertk 0:28557a4d2215 4052 }
gertk 0:28557a4d2215 4053
gertk 0:28557a4d2215 4054 case 73: /*DOS mismatch / Powerup message/write attempt with DOS mismatch*/
gertk 0:28557a4d2215 4055 {
gertk 0:28557a4d2215 4056 IEC_send_string("V");
gertk 0:28557a4d2215 4057 IEC_send_number_as_ASCII(RELEASE_VERSION);
gertk 0:28557a4d2215 4058 IEC_send('-');
gertk 0:28557a4d2215 4059 IEC_send_number_as_ASCII(RELEASE_VERSION_SUB);
gertk 0:28557a4d2215 4060 IEC_send('-');
gertk 0:28557a4d2215 4061 IEC_send_number_as_ASCII(RELEASE_VERSION_SUB_SUB);
gertk 0:28557a4d2215 4062 break;
gertk 0:28557a4d2215 4063 }
gertk 0:28557a4d2215 4064
gertk 0:28557a4d2215 4065 case 74: /*no disk in drive or no device 1 (8050 only)*/
gertk 0:28557a4d2215 4066 {
gertk 0:28557a4d2215 4067 IEC_send_string("DRIVE NOT READY");
gertk 0:28557a4d2215 4068 break;
gertk 0:28557a4d2215 4069 }
gertk 0:28557a4d2215 4070
gertk 0:28557a4d2215 4071 default:
gertk 0:28557a4d2215 4072 {
gertk 0:28557a4d2215 4073 IEC_send_string("ERROR UNKNOWN");
gertk 0:28557a4d2215 4074 break;
gertk 0:28557a4d2215 4075 }
gertk 0:28557a4d2215 4076 }
gertk 0:28557a4d2215 4077
gertk 0:28557a4d2215 4078 DelayBigMs(50); /*some small delay to give the computer time to process the string*/
gertk 0:28557a4d2215 4079 IEC_send(0x2C); /*','*/
gertk 0:28557a4d2215 4080 if (error_code == 1) /*check for the FILES SCRATCHED-error*/
gertk 0:28557a4d2215 4081 IEC_send_number_as_ASCII(files_scratched); /*last accessed track variable is replaced by the number of scratched files*/
gertk 0:28557a4d2215 4082 else
gertk 0:28557a4d2215 4083 IEC_send_number_as_ASCII(LastTrack); /*last accessed track variable*/
gertk 0:28557a4d2215 4084 IEC_send(0x2C); /*','*/
gertk 0:28557a4d2215 4085 IEC_send_number_as_ASCII(LastSector); /*last accessed sector variable*/
gertk 0:28557a4d2215 4086 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 4087 IEC_send(0x0D); /*CARRIAGE RETURN*/
gertk 0:28557a4d2215 4088 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 4089 SetErrorCode(0,LED_OFF); /*error-code is 0, LED is OFF*/
gertk 0:28557a4d2215 4090 }
gertk 0:28557a4d2215 4091 /*****************************************************************************************************************/
gertk 0:28557a4d2215 4092 /*****************************************************************************************************************/
gertk 0:28557a4d2215 4093 /*****************************************************************************************************************/
gertk 0:28557a4d2215 4094
gertk 0:28557a4d2215 4095 unsigned char ReadDeviceJumper(void)
gertk 0:28557a4d2215 4096 {
gertk 0:28557a4d2215 4097 if (JUMPER_J2 == 0) /*check the device number jumper to see what the req. device number should be*/
gertk 0:28557a4d2215 4098 return(8);
gertk 0:28557a4d2215 4099 else
gertk 0:28557a4d2215 4100 return(9);
gertk 0:28557a4d2215 4101 }
gertk 0:28557a4d2215 4102
gertk 0:28557a4d2215 4103 /*read the buttons using the ADC, the multiplexed buttons require only one IO-pin. The only thing is... only one button can be pressed/detected at the same time*/
gertk 0:28557a4d2215 4104 unsigned char ReadButtons(void)
gertk 0:28557a4d2215 4105 {
gertk 0:28557a4d2215 4106
gertk 0:28557a4d2215 4107 return(FALSE); /*the 1541-III DTV, does NOT support the use of buttons*/
gertk 0:28557a4d2215 4108
gertk 0:28557a4d2215 4109 }
gertk 0:28557a4d2215 4110
gertk 0:28557a4d2215 4111
gertk 0:28557a4d2215 4112 /*
gertk 0:28557a4d2215 4113 There's no shame in writing comments in your sourcecode.
gertk 0:28557a4d2215 4114 */