C1541-III mbed edition

Dependencies:   mbed

Committer:
gertk
Date:
Mon Aug 22 21:11:59 2011 +0000
Revision:
1:0cbbb66a6100
Parent:
0:28557a4d2215
updated the nRESET pin to an interrupt capable pin (p29)

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 1:0cbbb66a6100 33 /* History:
gertk 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 121 2007-06-25 added the sound samples made by Willem K.(Thanks a lot Willem for your excellent work, unfortunatley the
gertk 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 184 The LED fade on and fade off function is discarded because it function as expected.
gertk 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 232 New statemachine functions, the big difference between the new staemachine and the old one is basiccally that the old statemachine
gertk 1:0cbbb66a6100 233 executed the open command BEFORE the UNLISTEN command, while the new statemachine executes the OPEN command AFTER the UNLISTEN
gertk 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 339 2006-01-29 Removal of the redundant block_buffer and dat_buf registers, as a result of better 'fat' and 'ata' routines
gertk 1:0cbbb66a6100 340 2006-01-26 Loading of deleted files was possible, this is now fixed
gertk 1:0cbbb66a6100 341 2006-01-22 Adjusted the 'help' section in the $0 (card directory) for proper reading on a VC-20
gertk 1:0cbbb66a6100 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 1:0cbbb66a6100 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 1:0cbbb66a6100 345 2006-01-18 finished send-error-code routine (although Track and Sector are still hardcoded to 0
gertk 1:0cbbb66a6100 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 1:0cbbb66a6100 347 2006-01-15 continued search for the 'loadin works only the first time' problem
gertk 1:0cbbb66a6100 348 2006-01-12 renamed some routines, rewritten part of the statemachine
gertk 1:0cbbb66a6100 349 2006-01-11 rewritten the main decoder loop (statemachine)
gertk 1:0cbbb66a6100 350 2006-01-10 TALK and LISTEN definitions were mixed up, is corrected improved the FreeIEC routine
gertk 1:0cbbb66a6100 351 2006-01-09 interference problem with other devices on the bus has been solved
gertk 1:0cbbb66a6100 352 2006-01-04 better command decoder
gertk 1:0cbbb66a6100 353 2006-01-02 begining of real/serious command decoder
gertk 1:0cbbb66a6100 354 2006-01-01 corrected small error in directory, now text allignment is correct
gertk 1:0cbbb66a6100 355 2005-12-24 implementation of the actual directory of an D64 emulator file
gertk 1:0cbbb66a6100 356 2005-12-22 fixed the directory, now we can load a dir into the C64
gertk 1:0cbbb66a6100 357 2005-12-18 testing of the IEC-write and TurnAround routines
gertk 1:0cbbb66a6100 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 1:0cbbb66a6100 359 2005-09-20 raw design of fileselection routine
gertk 1:0cbbb66a6100 360 2005-09-21 design of ADC button decoder
gertk 1:0cbbb66a6100 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 1:0cbbb66a6100 363 2005-09-02 figured out how to decode the ImageDirectory, file by file, algoRITHM
gertk 1:0cbbb66a6100 364 2005-09-02 started with the free sectors routine
gertk 0:28557a4d2215 365 */
gertk 0:28557a4d2215 366
gertk 1:0cbbb66a6100 367 /* TO DO:
gertk 1:0cbbb66a6100 368 ------
gertk 1:0cbbb66a6100 369
gertk 1:0cbbb66a6100 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 1:0cbbb66a6100 409 #include <main.h>
gertk 1:0cbbb66a6100 410 #include <hardware.h>
gertk 1:0cbbb66a6100 411 #include <delay.h>
gertk 1:0cbbb66a6100 412 #include <ata.h>
gertk 1:0cbbb66a6100 413 #include <fat.h>
gertk 1:0cbbb66a6100 414 #include <D64_decoder.h>
gertk 1:0cbbb66a6100 415 #include <T64_decoder.h>
gertk 1:0cbbb66a6100 416 #include <IEC_bus.h>
gertk 1:0cbbb66a6100 417
gertk 0:28557a4d2215 418 // #include "string"
gertk 0:28557a4d2215 419 // #include "SDHCFileSystem.h"
gertk 1:0cbbb66a6100 420 //
gertk 0:28557a4d2215 421 // SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs
gertk 1:0cbbb66a6100 422 //
gertk 0:28557a4d2215 423 // int main() {
gertk 1:0cbbb66a6100 424 //
gertk 0:28557a4d2215 425 // FILE *fp = fopen("/sd/myfile.txt", "w");
gertk 0:28557a4d2215 426 // fprintf(fp, "\n\rHello World!\n\r");
gertk 0:28557a4d2215 427 // fclose(fp);
gertk 0:28557a4d2215 428 // }
gertk 1:0cbbb66a6100 429 // IEC hardware connections
gertk 0:28557a4d2215 430 DigitalInOut nSRQ(p18); // DIN6 pin 1
gertk 0:28557a4d2215 431 DigitalInOut nATN(p17); // DIN6 pin 3
gertk 0:28557a4d2215 432 DigitalInOut nCLK(p16); // DIN6 pin 4
gertk 0:28557a4d2215 433 DigitalInOut nDATA(p15); // DIN6 pin 5
gertk 1:0cbbb66a6100 434 // DigitalInOut nRESET(p19);
gertk 1:0cbbb66a6100 435
gertk 0:28557a4d2215 436 InterruptIn nIRQ(p30); // external loop: connect to nATN
gertk 1:0cbbb66a6100 437 InterruptIn nRESET(p29); // DIN6 pin 6
gertk 1:0cbbb66a6100 438
gertk 0:28557a4d2215 439 DigitalIn JUMPER_J2(p21);
gertk 0:28557a4d2215 440 DigitalIn JUMPER_J3(p22);
gertk 0:28557a4d2215 441
gertk 0:28557a4d2215 442 DigitalOut myled1(LED1);
gertk 0:28557a4d2215 443 DigitalOut myled2(LED2);
gertk 0:28557a4d2215 444 DigitalOut myled3(LED3);
gertk 0:28557a4d2215 445 DigitalOut myled4(LED4);
gertk 1:0cbbb66a6100 446
gertk 0:28557a4d2215 447 #define LED_GREEN myled1
gertk 0:28557a4d2215 448 #define LED_RED myled2
gertk 0:28557a4d2215 449
gertk 0:28557a4d2215 450 Timer timeout;
gertk 0:28557a4d2215 451 Serial linktopc(USBTX,USBRX);
gertk 0:28557a4d2215 452
gertk 0:28557a4d2215 453 // #define IEC_ATN_REL() IEC_DDR &= ~IEC_BIT_ATN
gertk 0:28557a4d2215 454 void IEC_ATN_REL() {
gertk 0:28557a4d2215 455 nATN=1;
gertk 0:28557a4d2215 456 nATN.input();
gertk 0:28557a4d2215 457 }
gertk 0:28557a4d2215 458
gertk 0:28557a4d2215 459 // #define IEC_ATN_PULL() IEC_DDR |= IEC_BIT_ATN
gertk 0:28557a4d2215 460 void IEC_ATN_PULL() {
gertk 0:28557a4d2215 461 nATN.output();
gertk 0:28557a4d2215 462 nATN=0;
gertk 0:28557a4d2215 463 }
gertk 0:28557a4d2215 464
gertk 0:28557a4d2215 465 // #define IEC_CLOCK_REL() IEC_DDR &= ~IEC_BIT_CLOCK
gertk 0:28557a4d2215 466 void IEC_CLOCK_REL() {
gertk 0:28557a4d2215 467 nCLK=1;
gertk 0:28557a4d2215 468 nCLK.input();
gertk 0:28557a4d2215 469 }
gertk 0:28557a4d2215 470
gertk 0:28557a4d2215 471 // #define IEC_CLOCK_PULL() IEC_DDR |= IEC_BIT_CLOCK
gertk 0:28557a4d2215 472 void IEC_CLOCK_PULL() {
gertk 0:28557a4d2215 473 nCLK.output();
gertk 0:28557a4d2215 474 nCLK=0;
gertk 0:28557a4d2215 475 }
gertk 0:28557a4d2215 476
gertk 0:28557a4d2215 477 // #define IEC_DATA_REL() IEC_DDR &= ~IEC_BIT_DATA
gertk 0:28557a4d2215 478 void IEC_DATA_REL() {
gertk 0:28557a4d2215 479 nDATA=1;
gertk 0:28557a4d2215 480 nDATA.input();
gertk 0:28557a4d2215 481 }
gertk 0:28557a4d2215 482
gertk 0:28557a4d2215 483 // #define IEC_DATA_PULL() IEC_DDR |= IEC_BIT_DATA
gertk 0:28557a4d2215 484 void IEC_DATA_PULL() {
gertk 0:28557a4d2215 485 nDATA.output();
gertk 0:28557a4d2215 486 nDATA=0;
gertk 0:28557a4d2215 487 }
gertk 0:28557a4d2215 488
gertk 1:0cbbb66a6100 489 void IEC_SRQ_REL() {
gertk 1:0cbbb66a6100 490 nSRQ=1;
gertk 1:0cbbb66a6100 491 nSRQ.input();
gertk 1:0cbbb66a6100 492 }
gertk 1:0cbbb66a6100 493
gertk 1:0cbbb66a6100 494 void IEC_SRQ_PULL() {
gertk 1:0cbbb66a6100 495 nSRQ.output();
gertk 1:0cbbb66a6100 496 nSRQ=0;
gertk 1:0cbbb66a6100 497 }
gertk 1:0cbbb66a6100 498
gertk 0:28557a4d2215 499 int IEC_ATN() {
gertk 0:28557a4d2215 500 nATN.input();
gertk 0:28557a4d2215 501 return nATN;
gertk 0:28557a4d2215 502 }
gertk 0:28557a4d2215 503
gertk 0:28557a4d2215 504 int IEC_CLOCK() {
gertk 0:28557a4d2215 505 nCLK.input();
gertk 0:28557a4d2215 506 return nCLK;
gertk 0:28557a4d2215 507 }
gertk 0:28557a4d2215 508
gertk 0:28557a4d2215 509 int IEC_DATA() {
gertk 0:28557a4d2215 510 nDATA.input();
gertk 0:28557a4d2215 511 return nDATA;
gertk 0:28557a4d2215 512 }
gertk 0:28557a4d2215 513
gertk 1:0cbbb66a6100 514 int IEC_SRQ() {
gertk 1:0cbbb66a6100 515 nSRQ.input();
gertk 1:0cbbb66a6100 516 return nSRQ;
gertk 1:0cbbb66a6100 517 }
gertk 0:28557a4d2215 518
gertk 0:28557a4d2215 519 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 520 /* EEPROM */
gertk 0:28557a4d2215 521 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 522 /*
gertk 0:28557a4d2215 523 __EEPROM_DATA('-','-','-','-','-','-','-','-');
gertk 0:28557a4d2215 524 __EEPROM_DATA('-','-','-','-','-','-','-','-');
gertk 0:28557a4d2215 525 __EEPROM_DATA('-','-','-','-','-','-','-','-');
gertk 0:28557a4d2215 526 __EEPROM_DATA('-','-','-','-','-','-','-','-');
gertk 0:28557a4d2215 527 __EEPROM_DATA('-','-','-','-','-','-','-','-');
gertk 0:28557a4d2215 528 */
gertk 0:28557a4d2215 529 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 530
gertk 0:28557a4d2215 531 /*--------------------------------------------------------*/
gertk 1:0cbbb66a6100 532 /* constants */
gertk 0:28557a4d2215 533 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 534
gertk 0:28557a4d2215 535 #define FALSE 0 /*FALSE*/
gertk 0:28557a4d2215 536 #define TRUE 1 /*TRUE*/
gertk 0:28557a4d2215 537
gertk 0:28557a4d2215 538 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 539
gertk 0:28557a4d2215 540 /*PCB types and versions*/
gertk 1:0cbbb66a6100 541 enum PCBTYPE {v1=10, v1_1, DTV, DTV_C64};
gertk 0:28557a4d2215 542
gertk 0:28557a4d2215 543 /*defines for the IEC-bus statemachine*/
gertk 1:0cbbb66a6100 544 enum IEC_bus_statemachine {IDLE=0, ACTIVE_LISTEN, ACTIVE_TALK};
gertk 0:28557a4d2215 545
gertk 0:28557a4d2215 546 /*blink modes*/
gertk 1:0cbbb66a6100 547 enum LED_modes {LED_OFF=0, LED_ON, LED_ERROR, LED_GR, LED_RD, LED_OR};
gertk 0:28557a4d2215 548
gertk 0:28557a4d2215 549 /*disk-state*/
gertk 1:0cbbb66a6100 550 enum DiskState {NO_CARD=0, CARD_ACTIVE, INVALID_POINTER};
gertk 0:28557a4d2215 551
gertk 0:28557a4d2215 552 /*1541-III commands*/
gertk 1:0cbbb66a6100 553 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 554
gertk 0:28557a4d2215 555 /*filetypes*/
gertk 1:0cbbb66a6100 556 enum Filetypes {SEQUENTIAL=1, RELATIVE, PROGRAM, USER, LENGTH};
gertk 0:28557a4d2215 557
gertk 0:28557a4d2215 558 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 559
gertk 0:28557a4d2215 560 #define BUTTON_SELECTION_RATE 350 /*this value determines the button repetition rate*/
gertk 0:28557a4d2215 561
gertk 0:28557a4d2215 562 /*MMC/SD-card*/
gertk 0:28557a4d2215 563 #define MMCCARD 2 /*card type found reference*/
gertk 1:0cbbb66a6100 564 #define SDCARD 3 /*card type found reference*/
gertk 0:28557a4d2215 565 #define FILENOTFOUND 4 /*filenotfound reference*/
gertk 0:28557a4d2215 566 #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 567
gertk 0:28557a4d2215 568 /*buttons*/
gertk 0:28557a4d2215 569 #define button_none 0 /*numerical value of ADC when no button is pressed*/
gertk 0:28557a4d2215 570 #define button_tolerance 15 /*max. alowable deviation of expected button values*/
gertk 0:28557a4d2215 571 #define button_1 870 /*numerical value of ADC when button-1 is pressed*/
gertk 0:28557a4d2215 572 #define button_2 721 /*numerical value of ADC when button-2 is pressed*/
gertk 0:28557a4d2215 573 #define button_3 575 /*numerical value of ADC when button-3 is pressed*/
gertk 0:28557a4d2215 574 #define button_4 431 /*numerical value of ADC when button-4 is pressed*/
gertk 0:28557a4d2215 575 #define button_5 288 /*numerical value of ADC when button-5 is pressed*/
gertk 0:28557a4d2215 576 #define button_6 145 /*numerical value of ADC when button-6 is pressed*/
gertk 0:28557a4d2215 577
gertk 0:28557a4d2215 578 /*1541-III operational modes/filefilter results*/
gertk 0:28557a4d2215 579 #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 580 #define PRG_FILE 1
gertk 0:28557a4d2215 581 #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 582 #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 583 #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 584 #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 585 #define T64_MODE 6 /*the 1541-III has opened a .T64 file*/
gertk 0:28557a4d2215 586 #define SUBDIRECTORY 100 /*the 1541-III has encountered a subdirectory*/
gertk 0:28557a4d2215 587 #define UNKNOWN 255 /*the 1541-III has encountered a file that has no extension*/
gertk 0:28557a4d2215 588
gertk 0:28557a4d2215 589 #define FILE_NOT_PRESENT 0
gertk 0:28557a4d2215 590 #define FILE_PRESENT 1
gertk 0:28557a4d2215 591
gertk 0:28557a4d2215 592 /*text printing definitions*/
gertk 0:28557a4d2215 593 #define PLAIN 0
gertk 0:28557a4d2215 594 #define BOLD 1
gertk 0:28557a4d2215 595 #define INVERTED 2
gertk 0:28557a4d2215 596
gertk 0:28557a4d2215 597 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 598 /* macro's */
gertk 0:28557a4d2215 599 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 600 #define disable() GIE=0 /*disable interrupts*/
gertk 0:28557a4d2215 601 #define enable() GIE=1 /*enable interrupts*/
gertk 0:28557a4d2215 602
gertk 0:28557a4d2215 603 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 604 /* globals */
gertk 0:28557a4d2215 605 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 606
gertk 0:28557a4d2215 607 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 608 //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 609 unsigned char block_buffer[512]; /*this buffers the data 'as read from' or 'to be written to' the card*/
gertk 0:28557a4d2215 610 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 611 struct DOS_channel_struct DOS_channel[16]; /*this array of structs holds this information about the currently used channels*/
gertk 0:28557a4d2215 612
gertk 0:28557a4d2215 613 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 614 unsigned char PCB_type; /*this value contains the PCB type/version*/
gertk 0:28557a4d2215 615 unsigned int PCB_type_timer; /*this timer determines the actual PCB type detection*/
gertk 0:28557a4d2215 616 unsigned char setting_contrast; /*this is the value belonging to the contrast setting as found in EEPROM*/
gertk 0:28557a4d2215 617 unsigned char VIC20_mode; /*this is the value belonging to the IEC-speed setting as found in EEPROM*/
gertk 0:28557a4d2215 618
gertk 0:28557a4d2215 619 unsigned char devicenumber; /*this var. holds the device number 8,9,10 or 11*/
gertk 0:28557a4d2215 620 unsigned char device_command;
gertk 0:28557a4d2215 621
gertk 0:28557a4d2215 622 unsigned char IEC_state; /*talk, listen or idle*/
gertk 0:28557a4d2215 623 unsigned char channel; /*this register holds the channel value*/
gertk 0:28557a4d2215 624 unsigned char nextfreebuffer; /*this register holds the buffernumber of the next buffer to be used*/
gertk 0:28557a4d2215 625 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 626 unsigned char command; /*this is the unfiltered (as received for the IEC-bus) command*/
gertk 0:28557a4d2215 627 unsigned char command_string[41]; /*this string holds the command details/options*/
gertk 0:28557a4d2215 628 unsigned char filename_string[41]; /*this string (is suppost to) hold(s) the filename*/
gertk 0:28557a4d2215 629 unsigned char oldfilename_string[41]; /*this string (is suppost to) hold(s) the new filename (for renaming routines)*/
gertk 0:28557a4d2215 630 unsigned char value_string[17]; /*this string (is suppost to) hold(s) a value*/
gertk 0:28557a4d2215 631 unsigned char string_pntr;
gertk 0:28557a4d2215 632 unsigned char string_pntr_2;
gertk 0:28557a4d2215 633 unsigned long value_long;
gertk 0:28557a4d2215 634 unsigned char value_1;
gertk 0:28557a4d2215 635 unsigned char value_2;
gertk 0:28557a4d2215 636 unsigned char value_3;
gertk 0:28557a4d2215 637 unsigned char value_4;
gertk 0:28557a4d2215 638 unsigned char filetype_string[41]; /*filetype can be sequential, program, user, etc.*/
gertk 0:28557a4d2215 639 unsigned char RW_string[41]; /*file read or write*/
gertk 0:28557a4d2215 640
gertk 0:28557a4d2215 641 unsigned char error_code = 73; /*this holds the error-message generated by one of the disk routines*/
gertk 0:28557a4d2215 642 unsigned char LastTrack = 0; /*last accessed track variable*/
gertk 0:28557a4d2215 643 unsigned char LastSector = 0; /*last accessed sector variable*/
gertk 0:28557a4d2215 644 unsigned char files_scratched = 0; /**/
gertk 0:28557a4d2215 645
gertk 0:28557a4d2215 646 unsigned char Response_data[5];
gertk 0:28557a4d2215 647
gertk 1:0cbbb66a6100 648 unsigned char file_type; /*this holds the type of the current file or NONE if no file is selected*/
gertk 0:28557a4d2215 649 unsigned int file_number; /*the current file index number, this number is used as a reference for button actions*/
gertk 0:28557a4d2215 650 unsigned int CountedFiles; /*the number of files in the current (root/sub)-directory*/
gertk 0:28557a4d2215 651
gertk 0:28557a4d2215 652 struct file2TYPE file; /*file handle*/
gertk 0:28557a4d2215 653 struct directory_entry dir_entry; /*directory structure inside the D64*/
gertk 0:28557a4d2215 654
gertk 0:28557a4d2215 655 bit button_prev;
gertk 0:28557a4d2215 656 bit button_select;
gertk 0:28557a4d2215 657 bit button_next;
gertk 0:28557a4d2215 658
gertk 0:28557a4d2215 659 unsigned char Blink_mode; /*mode of operation of the blink routine*/
gertk 0:28557a4d2215 660 bit Blink_dir; /*direction of intensity change (up or down)*/
gertk 0:28557a4d2215 661 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 662 unsigned char LED_OFF_delay; /*holds the delay timing value for the LED-OFF time*/
gertk 0:28557a4d2215 663 bit LED_status; /*the current state of the LED is stored here*/
gertk 0:28557a4d2215 664 unsigned char LED_color; /*value to keep track of current LED-color*/
gertk 0:28557a4d2215 665 unsigned char next_LED_color; /*value to keep track of current LED-color*/
gertk 0:28557a4d2215 666 unsigned char DiskState; /*state of the disk (image) inside the drive (1541-III)*/
gertk 0:28557a4d2215 667
gertk 0:28557a4d2215 668 bit EOI; /*End Of Indicator: this flag (when TRUE) indicates that the last byte is being transmitted or received*/
gertk 0:28557a4d2215 669 bit TimeOut; /*Timeout-flag*/
gertk 0:28557a4d2215 670
gertk 0:28557a4d2215 671 unsigned char dirtrack, dirsector, direntry;
gertk 0:28557a4d2215 672 unsigned long lp, lp2;
gertk 0:28557a4d2215 673 unsigned int blocksize;
gertk 0:28557a4d2215 674 unsigned char track, sector;
gertk 0:28557a4d2215 675 unsigned char file_status;
gertk 0:28557a4d2215 676
gertk 0:28557a4d2215 677 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 678 /* local functions */
gertk 0:28557a4d2215 679 /*--------------------------------------------------------*/
gertk 0:28557a4d2215 680 void WaitForString(unsigned char *outputstring, unsigned frame_handshake);
gertk 0:28557a4d2215 681 unsigned char ValueFromString(unsigned char *inputstring, unsigned char *outputvalue);
gertk 0:28557a4d2215 682 unsigned char LongValueFromString(unsigned char *inputstring, unsigned long *outputvalue);
gertk 0:28557a4d2215 683 void ExtractFilenameFromString(unsigned char *input_string, unsigned char *output_string);
gertk 0:28557a4d2215 684 unsigned char SplitStringOn_Sign(unsigned char sign, unsigned char *beforesign_string, unsigned char *aftersign_string);
gertk 0:28557a4d2215 685
gertk 0:28557a4d2215 686 void IEC_direction_statemachine(void);
gertk 0:28557a4d2215 687 void OpenHandler(void);
gertk 0:28557a4d2215 688 void DataHandler(void);
gertk 0:28557a4d2215 689 void AutoDetectPcbType(void);
gertk 0:28557a4d2215 690 void NoCardMenu(void);
gertk 0:28557a4d2215 691 void HardWareTestMenu(void);
gertk 0:28557a4d2215 692 unsigned char CardStatus(void);
gertk 0:28557a4d2215 693 void CountFiles(void);
gertk 0:28557a4d2215 694 unsigned char Init_Card_SPI(void);
gertk 0:28557a4d2215 695 unsigned char FileFilter(void);
gertk 0:28557a4d2215 696
gertk 0:28557a4d2215 697 unsigned char SearchFreeBuffer(void);
gertk 0:28557a4d2215 698
gertk 0:28557a4d2215 699 void Clear_block_buffer(void);
gertk 0:28557a4d2215 700 void SelectD64Image(void);
gertk 0:28557a4d2215 701 void CardDirectory(void);
gertk 0:28557a4d2215 702 void D64Directory(void);
gertk 0:28557a4d2215 703 void T64Directory(void);
gertk 0:28557a4d2215 704 unsigned int SeekFileOnCard(unsigned char *filename, struct file2TYPE *file);
gertk 0:28557a4d2215 705 void LoadFileFromCard(struct file2TYPE *file);
gertk 0:28557a4d2215 706 void LoadD64File(unsigned char trk, unsigned char sec, unsigned int filesizeinblocks);
gertk 0:28557a4d2215 707 unsigned char SaveD64File(void);
gertk 0:28557a4d2215 708 unsigned char CopyD64File(unsigned char trk, unsigned char sec, unsigned int filesizeinblocks);
gertk 0:28557a4d2215 709
gertk 0:28557a4d2215 710 void SetErrorCode(unsigned char error, unsigned char LEDmode);
gertk 0:28557a4d2215 711 void SendErrorMessage(void);
gertk 0:28557a4d2215 712
gertk 0:28557a4d2215 713 void print_device_status(const unsigned char *message);
gertk 0:28557a4d2215 714 void print_D64_name(unsigned char mode);
gertk 0:28557a4d2215 715 void print_D64_TSB(unsigned char trk, unsigned char sec, unsigned int blk, unsigned int total_blk);
gertk 0:28557a4d2215 716
gertk 0:28557a4d2215 717 unsigned char ReadDeviceJumper(void);
gertk 0:28557a4d2215 718 unsigned char ReadButtons(void);
gertk 0:28557a4d2215 719
gertk 0:28557a4d2215 720 void FormatD64File(unsigned char *diskname, unsigned char *diskid);
gertk 0:28557a4d2215 721 /*****************************************************************************************************************/
gertk 0:28557a4d2215 722 /*****************************************************************************************************************/
gertk 0:28557a4d2215 723 /*****************************************************************************************************************/
gertk 0:28557a4d2215 724 /*Interrupt service routines*/
gertk 0:28557a4d2215 725 /*****************************************************************************************************************/
gertk 0:28557a4d2215 726 /*****************************************************************************************************************/
gertk 0:28557a4d2215 727 /*Low-priority interrupt entry point*/
gertk 1:0cbbb66a6100 728 void NotTimeCritical(void) {
gertk 0:28557a4d2215 729
gertk 0:28557a4d2215 730 }
gertk 0:28557a4d2215 731
gertk 0:28557a4d2215 732 /*High-priority interrupt entry point*/
gertk 1:0cbbb66a6100 733 void high_priority(void) {
gertk 0:28557a4d2215 734 unsigned char filter_cnt;
gertk 0:28557a4d2215 735 /*By putting the ATN-line detection on an interrupt-line we detect the ATN-situation independent of*/
gertk 0:28557a4d2215 736 /*other actions, like selecting a new D64 image. This method makes IEC programming less complex*/
gertk 0:28557a4d2215 737 /*the small filter also creates a hold-off time, for some reason this is required*/
gertk 1:0cbbb66a6100 738 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 1:0cbbb66a6100 739 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 1:0cbbb66a6100 740 /*it does however add a more secure ATN-line detection, since the inputlines are not filtered in any other way*/
gertk 1:0cbbb66a6100 741 wait_us(1);
gertk 1:0cbbb66a6100 742 filter_cnt--;
gertk 1:0cbbb66a6100 743 if (filter_cnt == 0) /*when the ATN signal has been proven not to be a glitch*/
gertk 1:0cbbb66a6100 744 { /*we can safely handle the ATN-signal*/
gertk 1:0cbbb66a6100 745 IEC_DATA_PULL();/*join the bus...*/
gertk 1:0cbbb66a6100 746 myled3=1;
gertk 1:0cbbb66a6100 747
gertk 1:0cbbb66a6100 748 break;
gertk 0:28557a4d2215 749 }
gertk 1:0cbbb66a6100 750 }
gertk 1:0cbbb66a6100 751 }
gertk 1:0cbbb66a6100 752
gertk 1:0cbbb66a6100 753 extern "C" void mbed_reset();
gertk 1:0cbbb66a6100 754
gertk 1:0cbbb66a6100 755 void iec_reset_interrupt(void) {
gertk 1:0cbbb66a6100 756 nIRQ.fall(NULL);
gertk 1:0cbbb66a6100 757 nRESET.fall(NULL);
gertk 1:0cbbb66a6100 758 mbed_reset();
gertk 0:28557a4d2215 759 }
gertk 0:28557a4d2215 760
gertk 0:28557a4d2215 761 /*macro*/
gertk 0:28557a4d2215 762 // #define disable_ATN_interrupt() INT0IE = 0 /*disable interrupts on ATN line*/
gertk 0:28557a4d2215 763 // #define enable_ATN_interrupt() INT0IE = 1 /*enable interrupts on ATN line*/
gertk 0:28557a4d2215 764
gertk 1:0cbbb66a6100 765 void enable_ATN_interrupt() {
gertk 1:0cbbb66a6100 766 nIRQ.mode(PullUp);
gertk 0:28557a4d2215 767 nIRQ.fall(&high_priority);
gertk 0:28557a4d2215 768 }
gertk 0:28557a4d2215 769
gertk 1:0cbbb66a6100 770 void enable_RESET_interrupt() {
gertk 1:0cbbb66a6100 771 nRESET.mode(PullUp);
gertk 1:0cbbb66a6100 772 nRESET.fall(&iec_reset_interrupt);
gertk 1:0cbbb66a6100 773 }
gertk 1:0cbbb66a6100 774
gertk 1:0cbbb66a6100 775 void disable_ATN_interrupt() {
gertk 1:0cbbb66a6100 776 nIRQ.fall(NULL);
gertk 0:28557a4d2215 777 }
gertk 0:28557a4d2215 778 /*****************************************************************************************************************/
gertk 0:28557a4d2215 779 /*****************************************************************************************************************/
gertk 0:28557a4d2215 780 /*Main*/
gertk 0:28557a4d2215 781 /*****************************************************************************************************************/
gertk 0:28557a4d2215 782 /*****************************************************************************************************************/
gertk 0:28557a4d2215 783
gertk 1:0cbbb66a6100 784 int main(void) {
gertk 0:28557a4d2215 785
gertk 0:28557a4d2215 786 HardwareInit(); /*init controller registers and I/O-lines*/
gertk 0:28557a4d2215 787 // GetSettingsFromEEPROM(); /*read EEPROM settings*/
gertk 0:28557a4d2215 788 devicenumber = ReadDeviceJumper(); /*read the devicenumber jumper*/
gertk 0:28557a4d2215 789 InitIEC(); /*initialize the IEC-bus levels*/
gertk 1:0cbbb66a6100 790 /*initialize SPI*/
gertk 0:28557a4d2215 791
gertk 0:28557a4d2215 792
gertk 0:28557a4d2215 793 linktopc.baud(115200);
gertk 0:28557a4d2215 794
gertk 0:28557a4d2215 795 timeout.start(); // start timer
gertk 1:0cbbb66a6100 796
gertk 1:0cbbb66a6100 797 // InitLcd(); /*initialize the LCD*/
gertk 0:28557a4d2215 798 AutoDetectPcbType(); /*measure the button capacitor to determine PCB type*/
gertk 0:28557a4d2215 799 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 800 printf("\r\n -----------------------------------------");
gertk 0:28557a4d2215 801 printf("\r\n | |");
gertk 0:28557a4d2215 802 printf("\r\n | |");
gertk 0:28557a4d2215 803 printf("\r\n | --== 1541 - III ==-- |");
gertk 0:28557a4d2215 804 printf("\r\n | (by J.Derogee) |");
gertk 0:28557a4d2215 805 printf("\r\n | (http://jderogee.tripod.com) |");
gertk 0:28557a4d2215 806 printf("\r\n | |");
gertk 0:28557a4d2215 807 printf("\r\n | |");
gertk 0:28557a4d2215 808 printf("\r\n | |");
gertk 0:28557a4d2215 809 printf("\r\n | |");
gertk 0:28557a4d2215 810 printf("\r\n | |");
gertk 0:28557a4d2215 811 printf("\r\n | |");
gertk 0:28557a4d2215 812 printf("\r\n | |");
gertk 0:28557a4d2215 813 printf("\r\n | |");
gertk 0:28557a4d2215 814 printf("\r\n | |");
gertk 0:28557a4d2215 815 printf("\r\n | |");
gertk 0:28557a4d2215 816 printf("\r\n | -------------------------------- |");
gertk 0:28557a4d2215 817 printf("\r\n | ( ) |Firmware vers.: v20%02d-%02d-%02d | |",RELEASE_VERSION,RELEASE_VERSION_SUB,RELEASE_VERSION_SUB_SUB);
gertk 0:28557a4d2215 818 printf("\r\n | |J2 (Device-ID): ID=%1d | |",devicenumber);
gertk 0:28557a4d2215 819 printf("\r\n | |J3 (Bootldr) : ");
gertk 0:28557a4d2215 820 if (JUMPER_J3 == 0)
gertk 1:0cbbb66a6100 821 printf("ACTIVE | |");
gertk 0:28557a4d2215 822 else
gertk 1:0cbbb66a6100 823 printf("DISABLED | |");
gertk 1:0cbbb66a6100 824
gertk 1:0cbbb66a6100 825 printf("\r\n | ( ) |Contrast : 0x%02x | |",setting_contrast); /*show the settings*/
gertk 0:28557a4d2215 826 printf("\r\n | |VIC20-mode : ");
gertk 0:28557a4d2215 827 if (VIC20_mode == TRUE)
gertk 1:0cbbb66a6100 828 printf("TRUE | |");
gertk 0:28557a4d2215 829 else
gertk 1:0cbbb66a6100 830 printf("FALSE | |");
gertk 1:0cbbb66a6100 831
gertk 1:0cbbb66a6100 832 printf("\r\n | |PCB type det. : %05d | |",PCB_type_timer); /*check which kind of PCb we are dealing with...*/
gertk 0:28557a4d2215 833
gertk 0:28557a4d2215 834 /*adjust the startup sequence accordingly and settings depending on the PCB version*/
gertk 1:0cbbb66a6100 835 if (PCB_type == v1) {
gertk 0:28557a4d2215 836 printf("\r\n | ( ) |Detected PCB : 1541-III v1.0 | |");
gertk 0:28557a4d2215 837 // Lcd_show_1541_III(); /*show splash screen*/
gertk 0:28557a4d2215 838 SetIEC_timings(TIMINGS_DEFAULT); /*set timings to default*/
gertk 0:28557a4d2215 839 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 840 }
gertk 0:28557a4d2215 841
gertk 1:0cbbb66a6100 842 if (PCB_type == v1_1) {
gertk 0:28557a4d2215 843 printf("\r\n | ( ) |Detected PCB : 1541-III v1.1 | |");
gertk 1:0cbbb66a6100 844 // Lcd_show_1541_III(); /*show splash screen*/
gertk 0:28557a4d2215 845 SetIEC_timings(TIMINGS_DEFAULT); /*set timings to default*/
gertk 0:28557a4d2215 846 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 847 }
gertk 0:28557a4d2215 848
gertk 1:0cbbb66a6100 849 if (PCB_type == DTV) {
gertk 0:28557a4d2215 850 printf("\r\n | ( ) |Detected PCB : 1541-III DTV | |");
gertk 1:0cbbb66a6100 851 // Lcd_show_1541_III_DTV(); /*show splash screen*/
gertk 0:28557a4d2215 852 SetIEC_timings(TIMINGS_DTV); /*set timings according the settings as requested by Jussi (DTV tested settings)*/
gertk 0:28557a4d2215 853 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 854 }
gertk 0:28557a4d2215 855
gertk 1:0cbbb66a6100 856 if (PCB_type == DTV_C64) {
gertk 0:28557a4d2215 857 printf("\r\n | ( ) |Detected PCB : 1541-III DTV | |");
gertk 1:0cbbb66a6100 858 // Lcd_show_1541_III_DTV(); /*show splash screen*/
gertk 0:28557a4d2215 859 SetIEC_timings(TIMINGS_DEFAULT); /*set default timings */
gertk 1:0cbbb66a6100 860 Blink_block = 235;
gertk 0:28557a4d2215 861 }
gertk 0:28557a4d2215 862
gertk 0:28557a4d2215 863 printf("\r\n | -------------------------------- |");
gertk 0:28557a4d2215 864 printf("\r\n | |");
gertk 0:28557a4d2215 865 printf("\r\n | O O |");
gertk 0:28557a4d2215 866 printf("\r\n | POWER DRIVE |");
gertk 0:28557a4d2215 867 printf("\r\n | |");
gertk 0:28557a4d2215 868 printf("\r\n -----------------------------------------");
gertk 0:28557a4d2215 869 printf("\r\n");
gertk 0:28557a4d2215 870
gertk 0:28557a4d2215 871 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 872 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 1:0cbbb66a6100 873 /*set timings according the VIC-20 settings (25% faster mode)*/
gertk 0:28557a4d2215 874
gertk 0:28557a4d2215 875 printf("\r\n"); /*set cursor to the beginning of the next line (prepare for future (optional) debug printing)*/
gertk 0:28557a4d2215 876 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 877 SetErrorCode(73, LED_ON); /*all is OK, but show ID first, LED is ON as on a real 1541*/
gertk 0:28557a4d2215 878
gertk 1:0cbbb66a6100 879 for (lp=0; lp<MAX_NUMBER_OF_DOS_BUFFERS; lp++) { /*clear the channels*/
gertk 0:28557a4d2215 880 DOS_channel[lp].channel_in_use = FALSE;
gertk 0:28557a4d2215 881 DOS_channel[lp].filename[0] = 0;
gertk 0:28557a4d2215 882 DOS_channel[lp].filetype = 0;
gertk 1:0cbbb66a6100 883 DOS_channel[lp].RW = 0;
gertk 1:0cbbb66a6100 884 DOS_channel[lp].track = 0;
gertk 0:28557a4d2215 885 DOS_channel[lp].sector = 0;
gertk 0:28557a4d2215 886 DOS_channel[lp].buffer_pointer = 0;
gertk 0:28557a4d2215 887 DOS_channel[lp].used_buffer = 255;
gertk 0:28557a4d2215 888 DOS_channel[lp].status = NO_FILE;
gertk 0:28557a4d2215 889 }
gertk 0:28557a4d2215 890
gertk 1:0cbbb66a6100 891 for (lp=0; lp<5; lp++) { /*clear the buffers*/
gertk 0:28557a4d2215 892 DOS_buffer[lp].buffer_in_use = FALSE;
gertk 1:0cbbb66a6100 893 for (lp2=0; lp2<256; lp2++) {
gertk 0:28557a4d2215 894 DOS_buffer[lp].buffer[lp2] = 0;
gertk 0:28557a4d2215 895 }
gertk 0:28557a4d2215 896 }
gertk 0:28557a4d2215 897 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 898
gertk 1:0cbbb66a6100 899 // 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 900 IEC_state = IDLE;
gertk 0:28557a4d2215 901 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 902 DiskState = NO_CARD; /*no card detected yet, so no D64 is selected*/
gertk 0:28557a4d2215 903 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 904 enable_ATN_interrupt(); /*enabling the interrupt makes the system ready for use on the IEC-bus*/
gertk 1:0cbbb66a6100 905 enable_RESET_interrupt();
gertk 1:0cbbb66a6100 906
gertk 1:0cbbb66a6100 907 while (1) {
gertk 0:28557a4d2215 908 IEC_direction_statemachine();
gertk 0:28557a4d2215 909 }
gertk 0:28557a4d2215 910 }
gertk 0:28557a4d2215 911
gertk 0:28557a4d2215 912 /*****************************************************************************************************************/
gertk 0:28557a4d2215 913 /*****************************************************************************************************************/
gertk 0:28557a4d2215 914 #define CARD_DETECT 0 // this should be a hardware pin
gertk 0:28557a4d2215 915
gertk 1:0cbbb66a6100 916 void IEC_direction_statemachine(void) {
gertk 0:28557a4d2215 917 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 918 // 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 919 device_command = CheckForCommand(&command, TRUE);
gertk 1:0cbbb66a6100 920 while (device_command == FALSE) { /*no commands are received so we have time for others things...*/
gertk 1:0cbbb66a6100 921
gertk 1:0cbbb66a6100 922 if (CARD_DETECT == 1) /*check if the card is present*/
gertk 0:28557a4d2215 923 DiskState = NO_CARD; /*no card detected, so no D64 is selected*/
gertk 0:28557a4d2215 924
gertk 1:0cbbb66a6100 925 if (DiskState == NO_CARD) {
gertk 0:28557a4d2215 926 DelayBigMs(1000);
gertk 0:28557a4d2215 927 SetErrorCode(73, LED_OFF); /*all is OK, but show ID first, LED is OFF as on a real 1541*/
gertk 1:0cbbb66a6100 928 // Lcd_clr(); /*clear screen to prepare for more serious info.*/
gertk 0:28557a4d2215 929 NoCardMenu(); /*check if a setting button has been pressed and handle accordingly*/
gertk 1:0cbbb66a6100 930 if (CardStatus()) { /*this routine will only pass until a valid card is present*/
gertk 0:28557a4d2215 931 CountFiles(); /*count all files in the current directory (which is root)*/
gertk 0:28557a4d2215 932 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 933 file_type = NONE; /*after reset or card insertion there is no D64 file selected, so all actions regarding current refer to the card*/
gertk 1:0cbbb66a6100 934 // Lcd_clr();
gertk 0:28557a4d2215 935 print_D64_name(PLAIN);
gertk 0:28557a4d2215 936 print_D64_TSB(0, 0, 0,0); /*print Track, Sector, Block*/
gertk 0:28557a4d2215 937 }
gertk 0:28557a4d2215 938 }
gertk 1:0cbbb66a6100 939 // else
gertk 1:0cbbb66a6100 940 // {
gertk 1:0cbbb66a6100 941 // SelectD64Image(); /*check for user interaction via buttons*/
gertk 1:0cbbb66a6100 942 // }
gertk 0:28557a4d2215 943 device_command = CheckForCommand(&command, TRUE);
gertk 0:28557a4d2215 944 }
gertk 0:28557a4d2215 945
gertk 1:0cbbb66a6100 946 if (CARD_DETECT == 1) /*check again if the card is present, some @#$#@$#@% might have removed it*/
gertk 0:28557a4d2215 947 DiskState = NO_CARD; /*no card detected, so no D64 is selected*/
gertk 0:28557a4d2215 948
gertk 1:0cbbb66a6100 949
gertk 1:0cbbb66a6100 950 switch (device_command) {
gertk 1:0cbbb66a6100 951 case OPEN: { /*here we decode the command string and we check if we are capable of executing the requested action*/
gertk 0:28557a4d2215 952 DOS_channel[channel].channel_in_use = TRUE; /*claim this channel*/
gertk 0:28557a4d2215 953 WaitForString(command_string, TRUE); /*wait for an operator string that ends with an EOI*/
gertk 0:28557a4d2215 954 break;
gertk 0:28557a4d2215 955 }
gertk 1:0cbbb66a6100 956
gertk 1:0cbbb66a6100 957 case DATA: {
gertk 0:28557a4d2215 958 // if (DOS_channel[channel].channel_in_use == TRUE) /*check if this channel has been opened, if not ignore*/
gertk 0:28557a4d2215 959 // {
gertk 1:0cbbb66a6100 960 DataHandler();
gertk 0:28557a4d2215 961 // }
gertk 0:28557a4d2215 962 // else
gertk 0:28557a4d2215 963 // {
gertk 0:28557a4d2215 964 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 965 // printf("\r\nChannel not open! Ignore DATA command"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 966 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 967 // }
gertk 0:28557a4d2215 968 break;
gertk 0:28557a4d2215 969 }
gertk 0:28557a4d2215 970
gertk 1:0cbbb66a6100 971 case CLOSE: {
gertk 0:28557a4d2215 972 // if (channel == 15) /*when the error/command channel is closed, then all files stored in the DOS buffer are closed also*/
gertk 0:28557a4d2215 973 // {
gertk 1:0cbbb66a6100 974 /*to do: close all open files properly*/
gertk 0:28557a4d2215 975 // }
gertk 0:28557a4d2215 976 // else
gertk 0:28557a4d2215 977 // {
gertk 0:28557a4d2215 978 // }
gertk 0:28557a4d2215 979
gertk 1:0cbbb66a6100 980 if (DOS_channel[channel].used_buffer != 255) { /*check if there is a buffer connected to this channel*/
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 1:0cbbb66a6100 988 DOS_channel[channel].RW = 0;
gertk 1:0cbbb66a6100 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 1:0cbbb66a6100 999 }
gertk 1:0cbbb66a6100 1000
gertk 1:0cbbb66a6100 1001 case UNLISTEN: {
gertk 1:0cbbb66a6100 1002 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 1:0cbbb66a6100 1003 if (DOS_channel[channel].channel_in_use == TRUE) { /*check if the previous command on this channel was open*/
gertk 0:28557a4d2215 1004 OpenHandler();
gertk 0:28557a4d2215 1005 }
gertk 1:0cbbb66a6100 1006
gertk 0:28557a4d2215 1007 //turn LED OFF
gertk 0:28557a4d2215 1008 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1009 // printf("\r\nUnlisten\r\n"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1010 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1011 IEC_state = IDLE;
gertk 0:28557a4d2215 1012 }
gertk 0:28557a4d2215 1013 break;
gertk 0:28557a4d2215 1014 }
gertk 1:0cbbb66a6100 1015
gertk 1:0cbbb66a6100 1016 case UNTALK: {
gertk 1:0cbbb66a6100 1017 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 1018 //turn LED OFF
gertk 0:28557a4d2215 1019 IEC_state = IDLE;
gertk 0:28557a4d2215 1020 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1021 // printf("\r\nUntalk\r\n"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1022 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1023
gertk 0:28557a4d2215 1024 }
gertk 0:28557a4d2215 1025 break;
gertk 0:28557a4d2215 1026 }
gertk 0:28557a4d2215 1027
gertk 1:0cbbb66a6100 1028 default: {
gertk 1:0cbbb66a6100 1029 if (device_command == (LISTEN | devicenumber)) {
gertk 0:28557a4d2215 1030 //turn LED ON
gertk 0:28557a4d2215 1031 IEC_state = ACTIVE_LISTEN;
gertk 0:28557a4d2215 1032 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1033 // printf("\r\nListen"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1034 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1035 break;
gertk 0:28557a4d2215 1036 }
gertk 1:0cbbb66a6100 1037
gertk 1:0cbbb66a6100 1038 if (device_command == (TALK | devicenumber)) {
gertk 0:28557a4d2215 1039 //turn LED ON
gertk 0:28557a4d2215 1040 IEC_state = ACTIVE_TALK;
gertk 0:28557a4d2215 1041 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1042 // printf("\r\nTalk"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1043 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1044 break;
gertk 0:28557a4d2215 1045 }
gertk 0:28557a4d2215 1046
gertk 0:28557a4d2215 1047 /*--------------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1048 /* current communication on the bus is incorrect or meant for another device on the bus */
gertk 0:28557a4d2215 1049 /*--------------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1050 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 1051 FreeIEC(); /*get of the bus...*/
gertk 0:28557a4d2215 1052 enable_ATN_interrupt(); /*all is back to normal, enable interrupts on ATN line*/
gertk 0:28557a4d2215 1053 IEC_state = IDLE;
gertk 0:28557a4d2215 1054 break;
gertk 0:28557a4d2215 1055 }
gertk 0:28557a4d2215 1056 }
gertk 0:28557a4d2215 1057
gertk 0:28557a4d2215 1058 myled3=0;
gertk 0:28557a4d2215 1059 }
gertk 0:28557a4d2215 1060
gertk 0:28557a4d2215 1061
gertk 1:0cbbb66a6100 1062 void OpenHandler(void) {
gertk 0:28557a4d2215 1063 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1064 // printf("\r\nOPENHANDLER: "); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1065 // printf("command_string:%s",command_string); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1066 // printf("\r\nchannel:%d",channel); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1067 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1068
gertk 1:0cbbb66a6100 1069 switch (channel) {
gertk 1:0cbbb66a6100 1070 case 0: { /*this channel is used for reading of files*/
gertk 1:0cbbb66a6100 1071 if (DiskState == NO_CARD) {
gertk 0:28557a4d2215 1072 DOS_channel[channel].next_action = ABORT_SENDING;
gertk 0:28557a4d2215 1073 break;
gertk 0:28557a4d2215 1074 }
gertk 0:28557a4d2215 1075
gertk 0:28557a4d2215 1076 /*------------------*/
gertk 0:28557a4d2215 1077 /* '$' = DIRECTORY */
gertk 0:28557a4d2215 1078 /*------------------*/
gertk 0:28557a4d2215 1079 if ((strlen((char *)command_string) == 5) && (strncmp((char *)command_string,"$CARD", 5) == 0 )) /*check the COMPLETE string*/
gertk 0:28557a4d2215 1080 { /*ROOT directory of the card*/
gertk 0:28557a4d2215 1081 file_type = NONE; /*all later actions refer to the CARD and not a D64 file*/
gertk 0:28557a4d2215 1082 DiskState = CARD_ACTIVE; /*this command overrules the buttons*/
gertk 1:0cbbb66a6100 1083 DOS_channel[channel].next_action = CARD_DIRECTORY; /*show the directory of the MMC/SD-card*/
gertk 0:28557a4d2215 1084 print_D64_name(PLAIN);
gertk 0:28557a4d2215 1085 break;
gertk 0:28557a4d2215 1086 }
gertk 1:0cbbb66a6100 1087
gertk 0:28557a4d2215 1088 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 1089 { /*current directory, which may be D64 or ROOT depending on the previous selection*/
gertk 0:28557a4d2215 1090 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 1:0cbbb66a6100 1091 DOS_channel[channel].next_action = CARD_DIRECTORY; /*show the directory of the MMC/SD-card*/
gertk 0:28557a4d2215 1092 else
gertk 0:28557a4d2215 1093 DOS_channel[channel].next_action = DIRECTORY; /*show the directory of the currently selected D64 file*/
gertk 0:28557a4d2215 1094 break;
gertk 0:28557a4d2215 1095 }
gertk 0:28557a4d2215 1096
gertk 1:0cbbb66a6100 1097 if (strncmp("$", (char *)command_string, 1) == 0 ) { /*check the 1st char of the string)*/
gertk 0:28557a4d2215 1098 file_status = SeekFileOnCard(&command_string[1], &file); /*check if file is present or not*/
gertk 1:0cbbb66a6100 1099 if (file_status == FALSE) {
gertk 0:28557a4d2215 1100 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1101 DOS_channel[channel].next_action = ABORT_SENDING; /*the requested directory does not exist*/
gertk 1:0cbbb66a6100 1102 } else {
gertk 0:28557a4d2215 1103 DiskState = CARD_ACTIVE; /*this command overrules the buttons*/
gertk 0:28557a4d2215 1104 file_type = FileFilter(); /*check the type of file to determine the mode of operation*/
gertk 1:0cbbb66a6100 1105 if (file_type == SUBDIRECTORY) { /*check if the user wants to enter a subdirectory*/
gertk 0:28557a4d2215 1106 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 1107 file_number = 0; /*the file_number counter needs to be reset*/
gertk 0:28557a4d2215 1108 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 1109 CountFiles(); /*count all files in the opened directory*/
gertk 1:0cbbb66a6100 1110 DOS_channel[channel].next_action = CARD_DIRECTORY; /*show the (sub)directory of the MMC/SD-card*/
gertk 0:28557a4d2215 1111 print_D64_name(PLAIN); /*update the display*/
gertk 1:0cbbb66a6100 1112 } else {
gertk 0:28557a4d2215 1113 file_number = file_status;
gertk 0:28557a4d2215 1114 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 1115 print_D64_name(PLAIN); /*update the display*/
gertk 0:28557a4d2215 1116 FileSectorScan(&file); /*update the sector location table cache*/
gertk 0:28557a4d2215 1117 D64ReadBAM(); /*update the BAM*/
gertk 0:28557a4d2215 1118 }
gertk 0:28557a4d2215 1119 }
gertk 0:28557a4d2215 1120 break; /*leave the case*/
gertk 0:28557a4d2215 1121 }
gertk 1:0cbbb66a6100 1122
gertk 0:28557a4d2215 1123 /*----------------------*/
gertk 0:28557a4d2215 1124 /* LOAD filename */
gertk 1:0cbbb66a6100 1125 /*----------------------*/
gertk 1:0cbbb66a6100 1126 if (file_type == NONE) { /*check for the currently selected file, if 0 refer to the card and not a D64 file*/
gertk 0:28557a4d2215 1127 file_status = SeekFileOnCard(command_string, &file); /*check if file is present on the card*/
gertk 0:28557a4d2215 1128 DOS_channel[channel].next_action = RD_FILE_FROM_ROOT;
gertk 0:28557a4d2215 1129 break;
gertk 1:0cbbb66a6100 1130 } else {
gertk 0:28557a4d2215 1131 file_status = D64SeekFile(command_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present within a D64 file*/
gertk 0:28557a4d2215 1132 DOS_channel[channel].next_action = RD_FILE;
gertk 0:28557a4d2215 1133 break;
gertk 0:28557a4d2215 1134 }
gertk 0:28557a4d2215 1135 }
gertk 1:0cbbb66a6100 1136
gertk 1:0cbbb66a6100 1137 case 1: { /*this channel is used for writing of files*/
gertk 1:0cbbb66a6100 1138 if (DiskState == NO_CARD) {
gertk 0:28557a4d2215 1139 DOS_channel[channel].next_action = ABORT_RECEIVING;
gertk 0:28557a4d2215 1140 break;
gertk 0:28557a4d2215 1141 }
gertk 0:28557a4d2215 1142
gertk 0:28557a4d2215 1143 /*------------------------------------------------------------*/
gertk 0:28557a4d2215 1144 /* '@' = REPLACE */
gertk 0:28557a4d2215 1145 /* syntax: SAVE"@0:<filename>",x,1 */
gertk 0:28557a4d2215 1146 /* syntax: SAVE"@S:<filename>",8,1 (special for game:commando, int karate, donkey kong)*/
gertk 0:28557a4d2215 1147 /*------------------------------------------------------------*/
gertk 1:0cbbb66a6100 1148 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 1149 SplitStringOn_Sign(':', command_string, filename_string);
gertk 0:28557a4d2215 1150 file_status = D64SeekFile(filename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1151 DOS_channel[channel].next_action = REPLACE_FILE; /*replace a file within the currently selected D64 file*/
gertk 0:28557a4d2215 1152 break;
gertk 0:28557a4d2215 1153 }
gertk 1:0cbbb66a6100 1154
gertk 0:28557a4d2215 1155 /*---------------*/
gertk 0:28557a4d2215 1156 /* SAVE filename */
gertk 1:0cbbb66a6100 1157 /*---------------*/
gertk 1:0cbbb66a6100 1158 if (file_type == NONE) { /*check for the currently selected file, if 0 refer to the card and not a D64 file*/
gertk 0:28557a4d2215 1159 file_status = SeekFileOnCard(command_string, &file); /*check if file is present or not*/
gertk 0:28557a4d2215 1160 DOS_channel[channel].next_action = WR_FILE_TO_ROOT;
gertk 0:28557a4d2215 1161 break;
gertk 1:0cbbb66a6100 1162 } else {
gertk 0:28557a4d2215 1163 file_status = D64SeekFile(command_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1164 DOS_channel[channel].next_action = WR_FILE;
gertk 0:28557a4d2215 1165 break;
gertk 0:28557a4d2215 1166 }
gertk 0:28557a4d2215 1167 }
gertk 0:28557a4d2215 1168
gertk 0:28557a4d2215 1169
gertk 0:28557a4d2215 1170 /*the channels 2-14 are used for the actual file handling that do not use the BASIC LOAD or SAVE commands*/
gertk 1:0cbbb66a6100 1171 case 2:
gertk 1:0cbbb66a6100 1172 ;
gertk 1:0cbbb66a6100 1173 case 3:
gertk 1:0cbbb66a6100 1174 ;
gertk 1:0cbbb66a6100 1175 case 4:
gertk 1:0cbbb66a6100 1176 ;
gertk 1:0cbbb66a6100 1177 case 5:
gertk 1:0cbbb66a6100 1178 ;
gertk 1:0cbbb66a6100 1179 case 6:
gertk 1:0cbbb66a6100 1180 ;
gertk 1:0cbbb66a6100 1181 case 7:
gertk 1:0cbbb66a6100 1182 ;
gertk 1:0cbbb66a6100 1183 case 8:
gertk 1:0cbbb66a6100 1184 ;
gertk 1:0cbbb66a6100 1185 case 9:
gertk 1:0cbbb66a6100 1186 ;
gertk 1:0cbbb66a6100 1187 case 10:
gertk 1:0cbbb66a6100 1188 ;
gertk 1:0cbbb66a6100 1189 case 11:
gertk 1:0cbbb66a6100 1190 ;
gertk 1:0cbbb66a6100 1191 case 12:
gertk 1:0cbbb66a6100 1192 ;
gertk 1:0cbbb66a6100 1193 case 13:
gertk 1:0cbbb66a6100 1194 ;
gertk 1:0cbbb66a6100 1195 case 14: {
gertk 1:0cbbb66a6100 1196 if (command_string[0] == '#') { /*if the user/computer specifies a buffer then handle accordingly...*/
gertk 1:0cbbb66a6100 1197 if (DOS_channel[channel].used_buffer == 255) { /*check if this channel allready has a buffer connected*/
gertk 1:0cbbb66a6100 1198 if (ValueFromString(&command_string[0], &value_1)) { /*check if the user has specified it's own buffer preference*/
gertk 1:0cbbb66a6100 1199 if (DOS_buffer[value_1].buffer_in_use == FALSE) { /*check if this buffer is still available*/
gertk 0:28557a4d2215 1200 DOS_buffer[value_1].buffer_in_use = TRUE; /*this buffer is still free, so we can claim this buffer*/
gertk 0:28557a4d2215 1201 DOS_channel[channel].used_buffer = value_1; /*connect the free buffer to this channel*/
gertk 1:0cbbb66a6100 1202 } else {
gertk 0:28557a4d2215 1203 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 1204 }
gertk 1:0cbbb66a6100 1205 } else {
gertk 0:28557a4d2215 1206 nextfreebuffer = SearchFreeBuffer(); /*since the user does not care which buffer it uses, so the 1541-III may decide which buffer is available*/
gertk 1:0cbbb66a6100 1207 if (nextfreebuffer == 255) {
gertk 0:28557a4d2215 1208 SetErrorCode(70, LED_ERROR); /*No channels available or in other words: no more free buffers */
gertk 1:0cbbb66a6100 1209 } else {
gertk 0:28557a4d2215 1210 DOS_buffer[nextfreebuffer].buffer_in_use = TRUE; /*claim this buffer*/
gertk 0:28557a4d2215 1211 DOS_channel[channel].used_buffer = nextfreebuffer; /*connect the free buffer to this channel*/
gertk 0:28557a4d2215 1212 }
gertk 0:28557a4d2215 1213 }
gertk 0:28557a4d2215 1214 }
gertk 1:0cbbb66a6100 1215 } else {
gertk 0:28557a4d2215 1216 ExtractFilenameFromString(command_string, filename_string); /*extract the filename from the commandstring given by the user/computer*/
gertk 0:28557a4d2215 1217 SplitStringOn_Sign(',', command_string, filetype_string);
gertk 1:0cbbb66a6100 1218 SplitStringOn_Sign(',', filetype_string, RW_string);
gertk 0:28557a4d2215 1219 strcpy((char *)&DOS_channel[channel].filename[0], (char *)filename_string); /*copy the filename into the DOS buffer*/
gertk 0:28557a4d2215 1220
gertk 0:28557a4d2215 1221 /*check for filetype*/
gertk 1:0cbbb66a6100 1222 if ((strncmp("A", (char *)filetype_string, 1) == 0 ) || (strncmp("APPEND",(char *) filetype_string, 6) == 0 )) {
gertk 0:28557a4d2215 1223 DOS_channel[channel].filetype = SEQUENTIAL;
gertk 0:28557a4d2215 1224 //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 1:0cbbb66a6100 1225 } else {
gertk 0:28557a4d2215 1226 /*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 1:0cbbb66a6100 1227 if (strncmp("S", (char *)filetype_string, 1)) {
gertk 0:28557a4d2215 1228 DOS_channel[channel].filetype = SEQUENTIAL;
gertk 0:28557a4d2215 1229 }
gertk 1:0cbbb66a6100 1230 if (strncmp("R", (char *)filetype_string, 1)) {
gertk 0:28557a4d2215 1231 DOS_channel[channel].filetype = RELATIVE;
gertk 0:28557a4d2215 1232 }
gertk 1:0cbbb66a6100 1233 if (strncmp("P", (char *)filetype_string, 1)) {
gertk 0:28557a4d2215 1234 DOS_channel[channel].filetype = PROGRAM;
gertk 0:28557a4d2215 1235 }
gertk 1:0cbbb66a6100 1236 if (strncmp("U", (char *)filetype_string, 1) == 0 ) {
gertk 0:28557a4d2215 1237 DOS_channel[channel].filetype = USER;
gertk 0:28557a4d2215 1238 }
gertk 0:28557a4d2215 1239 // if (strncmp("L", filetype_string, 1))
gertk 0:28557a4d2215 1240 // {
gertk 0:28557a4d2215 1241 // DOS_channel[channel].filetype = USER;
gertk 0:28557a4d2215 1242 // }
gertk 1:0cbbb66a6100 1243
gertk 1:0cbbb66a6100 1244
gertk 0:28557a4d2215 1245 /*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 1:0cbbb66a6100 1246 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 1247 DOS_channel[channel].RW = RD_FILE;
gertk 0:28557a4d2215 1248 file_status = D64SeekFile(filename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 1:0cbbb66a6100 1249 if (file_status == FILE_PRESENT) {
gertk 0:28557a4d2215 1250 DOS_channel[channel].status = FILE_OPEN; /*the file could be found*/
gertk 0:28557a4d2215 1251 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 1252 DOS_channel[channel].sector = sector;
gertk 0:28557a4d2215 1253 DOS_channel[channel].buffer_pointer = 0;
gertk 1:0cbbb66a6100 1254 } else {
gertk 0:28557a4d2215 1255 DOS_channel[channel].status = NO_FILE; /*the file could not be found*/
gertk 0:28557a4d2215 1256 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1257 }
gertk 0:28557a4d2215 1258 }
gertk 0:28557a4d2215 1259
gertk 1:0cbbb66a6100 1260 if ((strncmp("W", (char *)RW_string, 1) == 0 ) || (strncmp("WRITE",(char *) RW_string, 5) == 0 )) {
gertk 0:28557a4d2215 1261 DOS_channel[channel].RW = WR_FILE;
gertk 0:28557a4d2215 1262 file_status = D64SeekFile(filename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 1:0cbbb66a6100 1263 if (file_status == FILE_PRESENT) {
gertk 0:28557a4d2215 1264 DOS_channel[channel].status = NO_FILE; /*the file could not be found*/
gertk 0:28557a4d2215 1265 SetErrorCode(63,LED_ERROR); /*file exists*/
gertk 1:0cbbb66a6100 1266 } else {
gertk 0:28557a4d2215 1267 DOS_channel[channel].status = FILE_OPEN; /*the file could be found*/
gertk 0:28557a4d2215 1268 //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 1269
gertk 0:28557a4d2215 1270 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 1271 DOS_channel[channel].sector = sector;
gertk 0:28557a4d2215 1272 DOS_channel[channel].buffer_pointer = 0;
gertk 0:28557a4d2215 1273 }
gertk 0:28557a4d2215 1274 }
gertk 1:0cbbb66a6100 1275 if ((strncmp("M", (char *)RW_string, 1) == 0 ) || (strncmp("MODIFY", (char *)RW_string, 6) == 0 )) {
gertk 0:28557a4d2215 1276 DOS_channel[channel].RW = MODIFY_FILE;
gertk 0:28557a4d2215 1277 //to do: uitzoeken wat modify precies inhoud...
gertk 0:28557a4d2215 1278 }
gertk 0:28557a4d2215 1279
gertk 0:28557a4d2215 1280 }
gertk 0:28557a4d2215 1281 }
gertk 0:28557a4d2215 1282
gertk 0:28557a4d2215 1283 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1284 printf("\r\nOpen, channel %d", channel); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1285 printf("\r\n channel_in_use:%03d",DOS_channel[channel].channel_in_use);
gertk 0:28557a4d2215 1286 printf("\r\n next_action :%03d",DOS_channel[channel].next_action);
gertk 0:28557a4d2215 1287 printf("\r\n filename[0] :%s",DOS_channel[channel].filename);
gertk 0:28557a4d2215 1288 printf("\r\n filetype :%03d",DOS_channel[channel].filetype);
gertk 0:28557a4d2215 1289 printf("\r\n RW :%03d",DOS_channel[channel].RW);
gertk 0:28557a4d2215 1290 printf("\r\n track :%03d",DOS_channel[channel].track);
gertk 0:28557a4d2215 1291 printf("\r\n sector :%03d",DOS_channel[channel].sector);
gertk 0:28557a4d2215 1292 printf("\r\n buffer_pointer:%03d",DOS_channel[channel].buffer_pointer);
gertk 0:28557a4d2215 1293 printf("\r\n used_buffer :%03d",DOS_channel[channel].used_buffer);
gertk 0:28557a4d2215 1294 printf("\r\n status :%03d",DOS_channel[channel].status);
gertk 0:28557a4d2215 1295 printf("\r\n"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1296 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1297 break;
gertk 0:28557a4d2215 1298 }
gertk 0:28557a4d2215 1299
gertk 1:0cbbb66a6100 1300 case 15: {
gertk 0:28557a4d2215 1301 /*------------------------------------------------------*/
gertk 0:28557a4d2215 1302 /* Set LCD's contrast */
gertk 0:28557a4d2215 1303 /* Syntax: "LCDCONTRAST=<value>" */
gertk 0:28557a4d2215 1304 /* Example: OPEN15,device,15,"LCDCONTRAST=ddd"<RETURN> */
gertk 0:28557a4d2215 1305 /* CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1306 /*------------------------------------------------------*/
gertk 1:0cbbb66a6100 1307 if (strncmp("LCDCONTRAST=",(char *)command_string,12) == 0 ) { /*check the beginning of the string)*/
gertk 0:28557a4d2215 1308 SplitStringOn_Sign('=', command_string, value_string);
gertk 0:28557a4d2215 1309 ValueFromString(value_string, &value_1);
gertk 1:0cbbb66a6100 1310 if (value_1>0 && value_1<255) {
gertk 0:28557a4d2215 1311 setting_contrast = value_1; /*copy new value to the correct register*/
gertk 0:28557a4d2215 1312 // SetContrast(); /*apply new setting*/
gertk 0:28557a4d2215 1313 // SaveSettingsToEEPROM(); /*save value to EEPROM*/
gertk 0:28557a4d2215 1314 print_device_status(" CONTRAST... ");
gertk 1:0cbbb66a6100 1315 } else { /*incorrect value*/
gertk 0:28557a4d2215 1316 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 1317 }
gertk 1:0cbbb66a6100 1318 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1319 }
gertk 1:0cbbb66a6100 1320
gertk 0:28557a4d2215 1321 /*----------------------------------------------------------------*/
gertk 0:28557a4d2215 1322 /* 'N' = NEW - Format a floppy disk */
gertk 0:28557a4d2215 1323 /* Syntax: "NEW:<diskname>,<id>" */
gertk 0:28557a4d2215 1324 /* Example: OPEN 15,8,15,"N:diskname,01"<RETURN> */
gertk 0:28557a4d2215 1325 /* CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1326 /* <diskname> can be up to 16 characters */
gertk 0:28557a4d2215 1327 /* <id> can either be omitted or must be exactly 2 characters long*/
gertk 0:28557a4d2215 1328 /*----------------------------------------------------------------*/
gertk 1:0cbbb66a6100 1329 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 1:0cbbb66a6100 1330 if (file_type == D64_35T_MODE) { //future or TODO: D64_35T_ER_MODE, D64_40T_MODE, D64_40T_ER_MODE
gertk 0:28557a4d2215 1331 print_device_status(" FORMATTING.. ");
gertk 0:28557a4d2215 1332 SplitStringOn_Sign(':', command_string, filename_string);
gertk 0:28557a4d2215 1333 SplitStringOn_Sign(',', filename_string, value_string);
gertk 0:28557a4d2215 1334 FormatD64File(filename_string, value_string);
gertk 1:0cbbb66a6100 1335 } else { /*creating a disk in the root directory is not supported*/
gertk 0:28557a4d2215 1336 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 1337 }
gertk 1:0cbbb66a6100 1338 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1339 }
gertk 1:0cbbb66a6100 1340
gertk 0:28557a4d2215 1341 /*----------------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1342 /* 'S' = SCRATCH (also referred to as 'delete') */
gertk 0:28557a4d2215 1343 /* Syntax: "SCRATCH:<file>" */
gertk 0:28557a4d2215 1344 /* Example: OPEN 15,8,15,"S:filename"<RETURN> */
gertk 0:28557a4d2215 1345 /* CLOSE 15<RETURN> (do not forget otherwise remaining commands may not work) */
gertk 0:28557a4d2215 1346 /* You can use the wild cards '?' and '*' to delete several files at once. */
gertk 0:28557a4d2215 1347 /*----------------------------------------------------------------------------------------*/
gertk 1:0cbbb66a6100 1348 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 1349 SplitStringOn_Sign(':', command_string, filename_string);
gertk 0:28557a4d2215 1350 file_status = D64SeekFile(filename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 1:0cbbb66a6100 1351 if (file_status == FILE_PRESENT) {
gertk 0:28557a4d2215 1352 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 1353 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 1:0cbbb66a6100 1354 while (file_status == FILE_PRESENT) { /*this function uses wildcards, so the same function needs to be repeated, keep checking untill false*/
gertk 0:28557a4d2215 1355 print_device_status(" SCRATCHING.. ");
gertk 0:28557a4d2215 1356 D64ScratchDirEntry(dirtrack, dirsector, direntry);
gertk 0:28557a4d2215 1357 files_scratched++;
gertk 0:28557a4d2215 1358 file_status = D64SeekFile(filename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 0:28557a4d2215 1359 }
gertk 0:28557a4d2215 1360 SetErrorCode(1,LED_OFF);
gertk 1:0cbbb66a6100 1361 } else {
gertk 0:28557a4d2215 1362 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1363 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 1364 }
gertk 1:0cbbb66a6100 1365 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1366 }
gertk 1:0cbbb66a6100 1367
gertk 0:28557a4d2215 1368 /*--------------------------------------------------*/
gertk 0:28557a4d2215 1369 /* 'R' = RENAME - Rename a file */
gertk 0:28557a4d2215 1370 /* Syntax: "RENAME:<newname>=<oldname>" */
gertk 0:28557a4d2215 1371 /* Example: OPEN 15,8,15,"R:newfilename=oldfilename"*/
gertk 0:28557a4d2215 1372 /* CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1373 /*--------------------------------------------------*/
gertk 1:0cbbb66a6100 1374 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 1375 SplitStringOn_Sign(':', command_string, filename_string);
gertk 0:28557a4d2215 1376 SplitStringOn_Sign('=', filename_string, oldfilename_string);
gertk 0:28557a4d2215 1377 file_status = D64SeekFile(oldfilename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 1:0cbbb66a6100 1378 if (file_status == FILE_PRESENT) { /*although the '=0' has to be given in the command, we do not check for it*/
gertk 0:28557a4d2215 1379 print_device_status(" RENAMING.. ");
gertk 0:28557a4d2215 1380 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 1381 D64RenameDirEntry(filename_string, dirtrack, dirsector, direntry);
gertk 0:28557a4d2215 1382 SetErrorCode(0,LED_OFF); /*we exit without error*/
gertk 1:0cbbb66a6100 1383 } else {
gertk 0:28557a4d2215 1384 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1385 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 1386 }
gertk 1:0cbbb66a6100 1387 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1388 }
gertk 1:0cbbb66a6100 1389
gertk 1:0cbbb66a6100 1390
gertk 0:28557a4d2215 1391 /*----------------------------------------*/
gertk 1:0cbbb66a6100 1392 /* INITIALIZE - re-read the BAM from disk */
gertk 0:28557a4d2215 1393 /* Abbreviation: I */
gertk 0:28557a4d2215 1394 /* Syntax: "INITIALIZE" */
gertk 1:0cbbb66a6100 1395 /*----------------------------------------*/
gertk 0:28557a4d2215 1396 /*Currently, this command is not supported */
gertk 1:0cbbb66a6100 1397
gertk 1:0cbbb66a6100 1398
gertk 0:28557a4d2215 1399 /*----------------------------------------------------*/
gertk 0:28557a4d2215 1400 /* VALIDATE - Check and Fix Disk Consistency */
gertk 0:28557a4d2215 1401 /* Abbreviation: V */
gertk 0:28557a4d2215 1402 /* Syntax: "VALIDATE" */
gertk 0:28557a4d2215 1403 /*----------------------------------------------------*/
gertk 0:28557a4d2215 1404 /*Currently, this command is not supported */
gertk 0:28557a4d2215 1405 /*Validate will fix inconsistencies that can be caused by files that where opened but never closed. Beware: Validate also erases all random files! */
gertk 1:0cbbb66a6100 1406
gertk 1:0cbbb66a6100 1407
gertk 0:28557a4d2215 1408 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1409 /* 'C' = COPY - Create a copy of a file on the same disk */
gertk 0:28557a4d2215 1410 /* Syntax: "COPY:<destfile>=<sourcefile>" or "COPY:<destfile>=<sourcefile1>, <sourcefile2>, ..."*/
gertk 0:28557a4d2215 1411 /* If several source files are listed, than the destination file will contain the concatenated contents of all source files. */
gertk 0:28557a4d2215 1412 /*-------------------------------------------------------*/
gertk 1:0cbbb66a6100 1413 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 1414 SplitStringOn_Sign(':', command_string, filename_string);
gertk 0:28557a4d2215 1415 SplitStringOn_Sign('=', filename_string, oldfilename_string);
gertk 0:28557a4d2215 1416 file_status = D64SeekFile(oldfilename_string, &track, &sector, &blocksize, &dirtrack, &dirsector, &direntry); /*check if file is present or not*/
gertk 1:0cbbb66a6100 1417 if (file_status == FILE_PRESENT) {
gertk 0:28557a4d2215 1418 print_device_status(" COPYING... ");
gertk 0:28557a4d2215 1419 CopyD64File(track, sector, blocksize);
gertk 1:0cbbb66a6100 1420 } else {
gertk 0:28557a4d2215 1421 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1422 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 1423 }
gertk 1:0cbbb66a6100 1424 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1425 }
gertk 1:0cbbb66a6100 1426
gertk 0:28557a4d2215 1427 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1428 /* 'M-W' = memory write command */
gertk 0:28557a4d2215 1429 /* 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 1430 /*-------------------------------------------------------*/
gertk 1:0cbbb66a6100 1431 if ((strncmp("M-W",(char *)command_string,3) == 0 )) { // || (strncmp("M-W:", command_string, 4) == 0 )) /*check the COMPLETE string*/
gertk 1:0cbbb66a6100 1432 if ((command_string[3] == 119) && (command_string[4] == 0) && (command_string[5] == 2)) {
gertk 1:0cbbb66a6100 1433 if ((command_string[6] - 32) == (command_string[7] - 64)) { /*check for new device address*/
gertk 0:28557a4d2215 1434 devicenumber = command_string[7] - 64; /*the new IEC device address of this device*/
gertk 0:28557a4d2215 1435 print_device_status(" NEW DEVICE# ");
gertk 0:28557a4d2215 1436 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 1437 print_D64_TSB(0,0,0,0); /*update display with the new device address*/
gertk 0:28557a4d2215 1438 SetErrorCode(0,LED_OFF); /*we exit without error*/
gertk 1:0cbbb66a6100 1439 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1440 }
gertk 0:28557a4d2215 1441 }
gertk 0:28557a4d2215 1442 }
gertk 1:0cbbb66a6100 1443
gertk 0:28557a4d2215 1444 /*--------------------------------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1445 /* 'B-P' = buffer pointer command (i.o.w. Set the buffer pointer used by CHANNEL ??? to point to BYTE ??? */
gertk 0:28557a4d2215 1446 /* Syntax: OPEN 15,8,15,"B-P:";channel;byte:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1447 /* Example: OPEN 15,8,15,"B-P:";5;2:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1448 /* Example: OPEN 15,8,15,"B-P";5;2:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1449 /* Example: OPEN 15,8,15,"B-P 5 2":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1450 /*--------------------------------------------------------------------------------------------------------*/
gertk 1:0cbbb66a6100 1451 if ((strncmp("B-P",(char *)command_string,3) == 0 )) { /*check the string*/
gertk 0:28557a4d2215 1452 string_pntr = 0;
gertk 0:28557a4d2215 1453 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_1); /*search for the 1st number: channel*/
gertk 1:0cbbb66a6100 1454 if (string_pntr_2!=FALSE) {
gertk 0:28557a4d2215 1455 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1456 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_2); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1457 if (string_pntr_2 != FALSE) {
gertk 1:0cbbb66a6100 1458 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 1459 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1460 printf("\r\nB-P command, channel:%02d, BP:%03d",value_1,DOS_channel[DOS_channel[value_1].used_buffer].buffer_pointer);
gertk 0:28557a4d2215 1461 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1462 }
gertk 0:28557a4d2215 1463 }
gertk 0:28557a4d2215 1464 }
gertk 1:0cbbb66a6100 1465
gertk 1:0cbbb66a6100 1466
gertk 0:28557a4d2215 1467 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1468 /* 'B-R' = USER-command 1 (254 bytes, byte 0-1 are skipped) */
gertk 0:28557a4d2215 1469 /* Syntax: OPEN 15,8,15,"B-R"channel;drive;track;sector":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1470 /*-------------------------------------------------------------------------*/
gertk 1:0cbbb66a6100 1471 if ((strncmp("B-R",(char *)command_string,3) == 0 )) { /*check the string*/
gertk 0:28557a4d2215 1472 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 1473 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_1); /*search for the 1st number: channel*/
gertk 1:0cbbb66a6100 1474 if (string_pntr_2!=FALSE) {
gertk 1:0cbbb66a6100 1475 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 1476 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1477 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_2); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1478 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1479 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1480 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_3); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1481 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1482 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1483 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_4); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1484 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1485 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 1486 DOS_channel[value_1].sector = value_4; /*save track and sector info*/
gertk 0:28557a4d2215 1487 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 1:0cbbb66a6100 1488
gertk 0:28557a4d2215 1489 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1490 printf("\r\nB-R command, t:%03d, s:%03d",DOS_channel[value_1].track,DOS_channel[value_1].sector);
gertk 0:28557a4d2215 1491 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1492 }
gertk 0:28557a4d2215 1493 }
gertk 0:28557a4d2215 1494 }
gertk 0:28557a4d2215 1495 }
gertk 0:28557a4d2215 1496 }
gertk 0:28557a4d2215 1497 }
gertk 1:0cbbb66a6100 1498
gertk 1:0cbbb66a6100 1499
gertk 0:28557a4d2215 1500 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1501 /* 'U1' or 'UA' = USER-command 1 (block read, 256 bytes) */
gertk 0:28557a4d2215 1502 /* Syntax: OPEN 15,8,15,"U1:"channel;drive;track;sector":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1503 /* Example: OPEN 15,8,15,"U1:";5;0;18;1:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1504 /* Example: OPEN 15,8,15,"U1";5;0;18;1:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1505 /* Example: OPEN 15,8,15,"U1 5 0 18 1":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1506 /*-------------------------------------------------------------------------*/
gertk 1:0cbbb66a6100 1507 if (((strncmp("UA",(char *)command_string,2) == 0 )) || ((strncmp("U1",(char *)command_string,2) == 0 ))) { /*check the string*/
gertk 0:28557a4d2215 1508 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 1509 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_1); /*search for the 1st number: channel*/
gertk 1:0cbbb66a6100 1510 if (string_pntr_2!=FALSE) {
gertk 1:0cbbb66a6100 1511 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 1512 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1513 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_2); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1514 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1515 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1516 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_3); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1517 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1518 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1519 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_4); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1520 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1521 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 1522 DOS_channel[value_1].sector = value_4; /*save track and sector info*/
gertk 0:28557a4d2215 1523 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 1524
gertk 0:28557a4d2215 1525 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1526 printf("\r\nU1 command, t:%03d, s:%03d",DOS_channel[value_1].track,DOS_channel[value_1].sector);
gertk 0:28557a4d2215 1527 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1528 }
gertk 0:28557a4d2215 1529 }
gertk 0:28557a4d2215 1530 }
gertk 0:28557a4d2215 1531 }
gertk 0:28557a4d2215 1532 }
gertk 0:28557a4d2215 1533 }
gertk 1:0cbbb66a6100 1534
gertk 1:0cbbb66a6100 1535
gertk 0:28557a4d2215 1536 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1537 /* 'B-W' = USER-command 2 (254 bytes block write) */
gertk 0:28557a4d2215 1538 /* Syntax: OPEN 15,8,15,"U2:"channel;drive;track;sector":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1539 /*-------------------------------------------------------------------------*/
gertk 1:0cbbb66a6100 1540 if ((strncmp("B-W",(char *)command_string,3) == 0 )) {
gertk 0:28557a4d2215 1541 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 1542 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_1); /*search for the 1st number: channel*/
gertk 1:0cbbb66a6100 1543 if (string_pntr_2!=FALSE) {
gertk 1:0cbbb66a6100 1544 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 1545 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1546 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_2); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1547 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1548 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1549 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_3); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1550 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1551 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1552 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_4); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1553 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1554 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 1555 DOS_channel[value_1].sector = value_4; /*save track and sector info*/
gertk 0:28557a4d2215 1556 D64BlockWrite_new(DOS_channel[value_1].used_buffer,value_3,value_4); /*write the desired block of the D64 image*/
gertk 0:28557a4d2215 1557
gertk 0:28557a4d2215 1558 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1559 printf("\r\nB-W command, t:%03d, s:%03d",DOS_channel[value_1].track,DOS_channel[value_1].sector);
gertk 0:28557a4d2215 1560 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1561 }
gertk 0:28557a4d2215 1562 }
gertk 0:28557a4d2215 1563 }
gertk 0:28557a4d2215 1564 }
gertk 0:28557a4d2215 1565 }
gertk 0:28557a4d2215 1566 }
gertk 0:28557a4d2215 1567
gertk 0:28557a4d2215 1568 /*-------------------------------------------------------------------------*/
gertk 0:28557a4d2215 1569 /* 'U2' or 'UB' = USER-command 2 (256 byte block write) */
gertk 0:28557a4d2215 1570 /* Syntax: OPEN 15,8,15,"U2:"channel;drive;track;sector":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1571 /* Example: OPEN 15,8,15,"U2:";5;0;18;1:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1572 /* Example: OPEN 15,8,15,"U2";5;0;18;1:CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1573 /* Example: OPEN 15,8,15,"U2 5 0 18 1":CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1574 /*-------------------------------------------------------------------------*/
gertk 1:0cbbb66a6100 1575
gertk 1:0cbbb66a6100 1576 if (((strncmp("U2",(char *)command_string,2) == 0 )) || ((strncmp("UB",(char *)command_string,2) == 0 ))) { /*check the string*/
gertk 0:28557a4d2215 1577 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 1578 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_1); /*search for the 1st number: channel*/
gertk 1:0cbbb66a6100 1579 if (string_pntr_2!=FALSE) {
gertk 1:0cbbb66a6100 1580 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 1581 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1582 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_2); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1583 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1584 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1585 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_3); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1586 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1587 string_pntr = string_pntr + string_pntr_2;
gertk 1:0cbbb66a6100 1588 string_pntr_2=ValueFromString(&command_string[string_pntr],&value_4); /*search for the 2nd number: channel*/
gertk 1:0cbbb66a6100 1589 if (string_pntr_2 != FALSE) {
gertk 0:28557a4d2215 1590 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 1591 DOS_channel[value_1].sector = value_4; /*save track and sector info*/
gertk 0:28557a4d2215 1592 D64BlockWrite_new(DOS_channel[value_1].used_buffer,value_3,value_4); /*write the desired block of the D64 image*/
gertk 0:28557a4d2215 1593
gertk 0:28557a4d2215 1594 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1595 printf("\r\nU2 command, t:%03d, s:%03d",DOS_channel[value_1].track,DOS_channel[value_1].sector);
gertk 0:28557a4d2215 1596 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1597 }
gertk 0:28557a4d2215 1598 }
gertk 0:28557a4d2215 1599 }
gertk 0:28557a4d2215 1600 }
gertk 0:28557a4d2215 1601 }
gertk 0:28557a4d2215 1602 }
gertk 0:28557a4d2215 1603
gertk 1:0cbbb66a6100 1604
gertk 0:28557a4d2215 1605 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1606 /* 'UI-' = USER-command speed up drive by 25% */
gertk 0:28557a4d2215 1607 /* Syntax: OPEN 15,8,15,"UI-":CLOSE 1<RETURN> */
gertk 0:28557a4d2215 1608 /*-------------------------------------------------------*/
gertk 1:0cbbb66a6100 1609 if (strncmp("UI-",(char *)command_string,3) == 0 ) { /*check the string*/
gertk 0:28557a4d2215 1610 print_device_status(" VIC20-MODE ");
gertk 0:28557a4d2215 1611 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 1612 SetIEC_timings(TIMINGS_VIC20); /*set timings according the VIC-20 settings (25% faster mode)*/
gertk 0:28557a4d2215 1613 VIC20_mode = TRUE; /*raise flag*/
gertk 0:28557a4d2215 1614 // SaveSettingsToEEPROM(); /*store new setting*/
gertk 0:28557a4d2215 1615 SetErrorCode(0,LED_OFF); /*we exit without error*/
gertk 1:0cbbb66a6100 1616 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1617 }
gertk 1:0cbbb66a6100 1618
gertk 0:28557a4d2215 1619 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1620 /* 'UI+' = USER-command restore drive speed to normal */
gertk 0:28557a4d2215 1621 /* Syntax: OPEN 15,8,15,"UI+":CLOSE 1<RETURN> */
gertk 0:28557a4d2215 1622 /*-------------------------------------------------------*/
gertk 1:0cbbb66a6100 1623 if (strncmp("UI+",(char *)command_string,3) == 0 ) { /*check the string*/
gertk 0:28557a4d2215 1624 print_device_status(" C64-MODE ");
gertk 0:28557a4d2215 1625 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 1626 SetIEC_timings(TIMINGS_DEFAULT); /*set timings according the default settings (C64 compatible mode)*/
gertk 0:28557a4d2215 1627 VIC20_mode = FALSE; /*raise flag*/
gertk 0:28557a4d2215 1628 // SaveSettingsToEEPROM(); /*store new setting*/
gertk 0:28557a4d2215 1629 SetErrorCode(0,LED_OFF); /*we exit without error*/
gertk 1:0cbbb66a6100 1630 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1631 }
gertk 0:28557a4d2215 1632
gertk 0:28557a4d2215 1633 /*------------------------------*/
gertk 0:28557a4d2215 1634 /* In case none of the above... */
gertk 0:28557a4d2215 1635 /*------------------------------*/
gertk 1:0cbbb66a6100 1636 //to do:syntax error
gertk 1:0cbbb66a6100 1637 DOS_channel[channel].channel_in_use = FALSE; /*no further actions required*/
gertk 0:28557a4d2215 1638 // print_device_status(" "); /*remove the 'action' message from the display*/
gertk 0:28557a4d2215 1639 }
gertk 0:28557a4d2215 1640 }
gertk 0:28557a4d2215 1641 }
gertk 0:28557a4d2215 1642
gertk 1:0cbbb66a6100 1643 void DataHandler(void) {
gertk 0:28557a4d2215 1644 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1645 // printf("\r\nDATAHANDLER"); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1646 // printf("\r\nData, channel %d",channel); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1647 // printf("\r\ncmd_string:%s",command_string); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1648 // printf("\r\nchannel:%d",channel); /*!!! DEBUG ONLY !!!*/
gertk 0:28557a4d2215 1649 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1650
gertk 1:0cbbb66a6100 1651 switch (channel) { /*-------------------------------------------*/
gertk 0:28557a4d2215 1652 case 0: /* this channel is used for reading of files */
gertk 1:0cbbb66a6100 1653 { /*-------------------------------------------*/
gertk 1:0cbbb66a6100 1654 if ((DiskState == NO_CARD) || (DiskState == INVALID_POINTER)) { /*escape sequence when no D64 is selected or no card is present*/
gertk 0:28557a4d2215 1655 DOS_channel[channel].next_action = ABORT_SENDING;
gertk 0:28557a4d2215 1656 }
gertk 1:0cbbb66a6100 1657
gertk 1:0cbbb66a6100 1658 switch (DOS_channel[channel].next_action) {
gertk 1:0cbbb66a6100 1659 case ABORT_SENDING: { /*file not found situation*/
gertk 0:28557a4d2215 1660 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1661 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 1662 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 1663 break;
gertk 0:28557a4d2215 1664 }
gertk 0:28557a4d2215 1665
gertk 1:0cbbb66a6100 1666 case CARD_DIRECTORY: {
gertk 0:28557a4d2215 1667 print_device_status(" LOADING... ");
gertk 0:28557a4d2215 1668 CardDirectory(); /*send the MMC/SD_card Directory information*/
gertk 0:28557a4d2215 1669 print_device_status(" ");
gertk 0:28557a4d2215 1670 break;
gertk 0:28557a4d2215 1671 }
gertk 1:0cbbb66a6100 1672
gertk 1:0cbbb66a6100 1673 case DIRECTORY: {
gertk 0:28557a4d2215 1674 print_device_status(" LOADING DIR. ");
gertk 1:0cbbb66a6100 1675 D64Directory(); /*send ImageDirectory information of the selected drive*/
gertk 0:28557a4d2215 1676 print_device_status(" ");
gertk 0:28557a4d2215 1677 break;
gertk 0:28557a4d2215 1678 }
gertk 1:0cbbb66a6100 1679
gertk 1:0cbbb66a6100 1680 case RD_FILE_FROM_ROOT: {
gertk 1:0cbbb66a6100 1681 if (file_status != FALSE) {
gertk 0:28557a4d2215 1682 print_device_status(" LOADING... ");
gertk 0:28557a4d2215 1683 OutputToRS232();
gertk 0:28557a4d2215 1684 printf("%s",command_string); /*print filename on first line of LCD*/
gertk 0:28557a4d2215 1685 OutputToLCD();
gertk 0:28557a4d2215 1686 LoadFileFromCard(&file);
gertk 0:28557a4d2215 1687 print_device_status(" ");
gertk 1:0cbbb66a6100 1688 } else {
gertk 0:28557a4d2215 1689 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1690 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 1691 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 1692 DOS_channel[channel].next_action = ABORT_SENDING;
gertk 0:28557a4d2215 1693 }
gertk 0:28557a4d2215 1694 break;
gertk 0:28557a4d2215 1695 }
gertk 1:0cbbb66a6100 1696
gertk 1:0cbbb66a6100 1697 case RD_FILE: {
gertk 1:0cbbb66a6100 1698 if (file_status == FILE_PRESENT) {
gertk 0:28557a4d2215 1699 print_device_status(" LOADING... ");
gertk 1:0cbbb66a6100 1700 OutputToRS232();
gertk 0:28557a4d2215 1701 printf("%s",command_string); /*print filename to LCD*/
gertk 0:28557a4d2215 1702 OutputToLCD();
gertk 0:28557a4d2215 1703 LoadD64File(track, sector, blocksize); /*load the actual file from the D64-file*/
gertk 0:28557a4d2215 1704 print_device_status(" ");
gertk 1:0cbbb66a6100 1705 } else {
gertk 0:28557a4d2215 1706 SetErrorCode(62,LED_ERROR); /*file not found*/
gertk 0:28557a4d2215 1707 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 1708 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 1709 DOS_channel[channel].next_action = ABORT_SENDING;
gertk 0:28557a4d2215 1710 print_device_status(" ");
gertk 0:28557a4d2215 1711 }
gertk 0:28557a4d2215 1712 break;
gertk 0:28557a4d2215 1713 }
gertk 0:28557a4d2215 1714 }
gertk 0:28557a4d2215 1715 break;
gertk 0:28557a4d2215 1716 }
gertk 0:28557a4d2215 1717
gertk 1:0cbbb66a6100 1718 /*-------------------------------------------*/
gertk 0:28557a4d2215 1719 case 1: /* this channel is used for writing of files */
gertk 0:28557a4d2215 1720 { /*-------------------------------------------*/
gertk 0:28557a4d2215 1721 if ((DiskState == NO_CARD) || (DiskState == INVALID_POINTER)) /*escape sequence when no D64 is selected or no card is present*/
gertk 0:28557a4d2215 1722 DOS_channel[channel].next_action = ABORT_RECEIVING;
gertk 0:28557a4d2215 1723
gertk 1:0cbbb66a6100 1724 switch (DOS_channel[channel].next_action) {
gertk 1:0cbbb66a6100 1725 case ABORT_RECEIVING: { /*file not found situation*/
gertk 0:28557a4d2215 1726 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 1727 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 1728 break;
gertk 0:28557a4d2215 1729 }
gertk 0:28557a4d2215 1730
gertk 1:0cbbb66a6100 1731 case WR_FILE_TO_ROOT: {
gertk 0:28557a4d2215 1732 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 1733 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 1734 DOS_channel[channel].next_action = ABORT_RECEIVING;
gertk 0:28557a4d2215 1735 break;
gertk 0:28557a4d2215 1736 }
gertk 1:0cbbb66a6100 1737
gertk 1:0cbbb66a6100 1738 case WR_FILE: {
gertk 1:0cbbb66a6100 1739 if (file_status == FILE_NOT_PRESENT) {
gertk 0:28557a4d2215 1740 print_device_status(" SAVING... ");
gertk 1:0cbbb66a6100 1741 OutputToRS232();
gertk 0:28557a4d2215 1742 printf("%s",command_string); /*print filename on first line of LCD*/
gertk 0:28557a4d2215 1743 OutputToLCD();
gertk 0:28557a4d2215 1744 SaveD64File(); /*save the actual file to the D64-file*/
gertk 0:28557a4d2215 1745 print_device_status(" ");
gertk 1:0cbbb66a6100 1746 } else {
gertk 0:28557a4d2215 1747 SetErrorCode(63,LED_ERROR); /*file exists*/
gertk 0:28557a4d2215 1748 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 1749 DOS_channel[channel].next_action = ABORT_RECEIVING;
gertk 0:28557a4d2215 1750 }
gertk 0:28557a4d2215 1751 break;
gertk 0:28557a4d2215 1752 }
gertk 1:0cbbb66a6100 1753
gertk 1:0cbbb66a6100 1754 case REPLACE_FILE: {
gertk 1:0cbbb66a6100 1755 if (file_status == FILE_PRESENT) {
gertk 0:28557a4d2215 1756 print_device_status(" REPLACING.. ");
gertk 0:28557a4d2215 1757 D64ScratchDirEntry(dirtrack, dirsector, direntry); /*remove entry*/
gertk 0:28557a4d2215 1758 files_scratched = 1;
gertk 0:28557a4d2215 1759 strcpy((char *)command_string,(char *) filename_string); /*make sure the save routine uses the correct data, the command without the @0:*/
gertk 0:28557a4d2215 1760 SaveD64File(); /*save the actual file to the D64-file*/
gertk 0:28557a4d2215 1761 print_device_status(" ");
gertk 0:28557a4d2215 1762 }
gertk 0:28557a4d2215 1763 break;
gertk 0:28557a4d2215 1764 }
gertk 0:28557a4d2215 1765 }
gertk 0:28557a4d2215 1766 break;
gertk 0:28557a4d2215 1767 }
gertk 1:0cbbb66a6100 1768
gertk 0:28557a4d2215 1769 case 2:; /*these channels are used for...*/
gertk 1:0cbbb66a6100 1770 case 3:
gertk 1:0cbbb66a6100 1771 ;
gertk 1:0cbbb66a6100 1772 case 4:
gertk 1:0cbbb66a6100 1773 ;
gertk 1:0cbbb66a6100 1774 case 5:
gertk 1:0cbbb66a6100 1775 ;
gertk 1:0cbbb66a6100 1776 case 6:
gertk 1:0cbbb66a6100 1777 ;
gertk 1:0cbbb66a6100 1778 case 7:
gertk 1:0cbbb66a6100 1779 ;
gertk 1:0cbbb66a6100 1780 case 8:
gertk 1:0cbbb66a6100 1781 ;
gertk 1:0cbbb66a6100 1782 case 9:
gertk 1:0cbbb66a6100 1783 ;
gertk 1:0cbbb66a6100 1784 case 10:
gertk 1:0cbbb66a6100 1785 ;
gertk 1:0cbbb66a6100 1786 case 11:
gertk 1:0cbbb66a6100 1787 ;
gertk 1:0cbbb66a6100 1788 case 12:
gertk 1:0cbbb66a6100 1789 ;
gertk 1:0cbbb66a6100 1790 case 13:
gertk 1:0cbbb66a6100 1791 ;
gertk 1:0cbbb66a6100 1792 case 14: {
gertk 1:0cbbb66a6100 1793 if (IEC_state == ACTIVE_TALK) { /*if the drive is expected to TALK... speak now*/
gertk 0:28557a4d2215 1794 EOI = FALSE;
gertk 0:28557a4d2215 1795 LED_GREEN = 1; /*drive LED-ON*/
gertk 0:28557a4d2215 1796 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 1797 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 1:0cbbb66a6100 1798 while (IEC_ATN() == 1) { /* the listener (computer) indicates (by making ATN=0) it requires no more data (for now)*/
gertk 1:0cbbb66a6100 1799 if (command_string[0] == '#') { /*if the user's/computer's last command specified opening a buffer, then handle accordingly...*/
gertk 0:28557a4d2215 1800 command_string[0] = 0; /*make sure the command string is discarded to prevent looping*/
gertk 0:28557a4d2215 1801 IEC_send(DOS_channel[channel].used_buffer); /*send the buffer number of the just opened buffer*/
gertk 1:0cbbb66a6100 1802 } else {
gertk 0:28557a4d2215 1803 // if (DOS_channel[channel].buffer_pointer == 255) /*when the last byte is going to been send*/
gertk 0:28557a4d2215 1804 // {
gertk 0:28557a4d2215 1805 // EOI = TRUE; /*indicate that this is the last byte of the buffer*/
gertk 0:28557a4d2215 1806 // }
gertk 0:28557a4d2215 1807 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 1:0cbbb66a6100 1808 DOS_channel[channel].buffer_pointer++; /*increment buffer pointer by one*/
gertk 0:28557a4d2215 1809 }
gertk 0:28557a4d2215 1810 /*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 1811 while (IEC_DATA() == 0); /*data is released when new data can be handled by the listener (the computer at this stage)*/
gertk 1:0cbbb66a6100 1812 /*OR*/
gertk 1:0cbbb66a6100 1813 /*data is released when ATN goes low because NO MORE data is required*/
gertk 1:0cbbb66a6100 1814 }
gertk 0:28557a4d2215 1815 IEC_undoturnaround();
gertk 0:28557a4d2215 1816 enable_ATN_interrupt(); /*all is back to normal, enable interrupts on ATN line*/
gertk 0:28557a4d2215 1817 SetErrorCode(0,LED_OFF); /*error-code is 0, LED is OFF*/
gertk 0:28557a4d2215 1818 }
gertk 0:28557a4d2215 1819
gertk 1:0cbbb66a6100 1820 if (IEC_state == ACTIVE_LISTEN) { /*if the drive is expected to listen then... we're all ear*/
gertk 1:0cbbb66a6100 1821 OutputToRS232(); /*set standard output to RS232*/
gertk 1:0cbbb66a6100 1822 printf("\r\ntp10 active listen"); /*!!! DEBUG ONLY !!!*/
gertk 1:0cbbb66a6100 1823 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1824 }
gertk 0:28557a4d2215 1825
gertk 0:28557a4d2215 1826 break;
gertk 0:28557a4d2215 1827 }
gertk 1:0cbbb66a6100 1828
gertk 1:0cbbb66a6100 1829 /*---------------------------------------*/
gertk 0:28557a4d2215 1830 case 15: /* this channel is used for DOS-commands */
gertk 0:28557a4d2215 1831 { /*---------------------------------------*/
gertk 0:28557a4d2215 1832 if (IEC_state == ACTIVE_TALK)
gertk 0:28557a4d2215 1833 // if ((IEC_state == ACTIVE_TALK) && (DOS_channel[15].channel_in_use == TRUE))
gertk 0:28557a4d2215 1834 {
gertk 0:28557a4d2215 1835 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1836 /* Reading the error channel is a special situation */
gertk 1:0cbbb66a6100 1837 /* Example: OPEN 15,8,15<RETURN> */
gertk 0:28557a4d2215 1838 /* INPUT#15, A, B$, C, D<RETURN> */
gertk 0:28557a4d2215 1839 /* CLOSE 15<RETURN> */
gertk 0:28557a4d2215 1840 /*-------------------------------------------------------*/
gertk 0:28557a4d2215 1841 SendErrorMessage(); /*this is handled immediately*/
gertk 1:0cbbb66a6100 1842 } else {
gertk 0:28557a4d2215 1843 DOS_channel[channel].channel_in_use = TRUE; /*claim this channel*/
gertk 0:28557a4d2215 1844 WaitForString(command_string, TRUE); /*wait for an operator string that ends with an EOI*/
gertk 0:28557a4d2215 1845 }
gertk 0:28557a4d2215 1846
gertk 0:28557a4d2215 1847 break;
gertk 0:28557a4d2215 1848 }
gertk 0:28557a4d2215 1849 }
gertk 0:28557a4d2215 1850 }
gertk 0:28557a4d2215 1851
gertk 0:28557a4d2215 1852 /*****************************************************************************************************************/
gertk 0:28557a4d2215 1853 /*The following routine will check for the PCB type by testing for the capacitor value on port RA0*/
gertk 0:28557a4d2215 1854 /*During this testing procedure no buttons may be pressed*/
gertk 1:0cbbb66a6100 1855 void AutoDetectPcbType(void) {
gertk 1:0cbbb66a6100 1856
gertk 1:0cbbb66a6100 1857 PCB_type = v1_1; /*typical timer value: 10771 - 10835*/
gertk 0:28557a4d2215 1858 }
gertk 0:28557a4d2215 1859
gertk 1:0cbbb66a6100 1860 void NoCardMenu(void) {
gertk 0:28557a4d2215 1861 // Lcd_XY_address(0,0);
gertk 0:28557a4d2215 1862 putch('o');
gertk 1:0cbbb66a6100 1863 // Lcd_XY_address(0,2);
gertk 0:28557a4d2215 1864 putch(0x16);
gertk 1:0cbbb66a6100 1865 // Lcd_XY_address(0,4);
gertk 0:28557a4d2215 1866 putch('i');
gertk 1:0cbbb66a6100 1867 while (ReadButtons()) {
gertk 0:28557a4d2215 1868 if (button_prev == TRUE) /*decrease contrast (lighter)*/
gertk 0:28557a4d2215 1869 { /*---------------------------*/
gertk 0:28557a4d2215 1870 setting_contrast--;
gertk 1:0cbbb66a6100 1871 if (setting_contrast < 0x81) {
gertk 0:28557a4d2215 1872 setting_contrast = 0x81; /*lower limit*/
gertk 1:0cbbb66a6100 1873 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 1874 printf(" Min. reached ");
gertk 0:28557a4d2215 1875 DelayBigMs(350);
gertk 1:0cbbb66a6100 1876 } else {
gertk 0:28557a4d2215 1877 // SetContrast(); /*apply new setting*/
gertk 1:0cbbb66a6100 1878 // Lcd_XY_address(0,1);
gertk 1:0cbbb66a6100 1879 // Lcd_ProgressBar((0xff-setting_contrast), 0x81);
gertk 1:0cbbb66a6100 1880 // SaveSettingsToEEPROM(); /*save value to EEPROM*/
gertk 0:28557a4d2215 1881 DelayBigMs(200);
gertk 0:28557a4d2215 1882 }
gertk 0:28557a4d2215 1883 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1884 printf("\r\nLCD-Lighter, contrast =%02x",setting_contrast);
gertk 0:28557a4d2215 1885 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 1886 }
gertk 1:0cbbb66a6100 1887
gertk 0:28557a4d2215 1888 if (button_select == TRUE) /*increase contrast (darker)*/
gertk 0:28557a4d2215 1889 { /*--------------------------*/
gertk 0:28557a4d2215 1890 setting_contrast++;
gertk 1:0cbbb66a6100 1891 if (setting_contrast > 0xFE) {
gertk 0:28557a4d2215 1892 setting_contrast = 0xFE; /*upper limit*/
gertk 1:0cbbb66a6100 1893 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 1894 printf(" Max. reached ");
gertk 0:28557a4d2215 1895 DelayBigMs(350);
gertk 1:0cbbb66a6100 1896 } else {
gertk 1:0cbbb66a6100 1897 // SetContrast(); /*apply new setting*/
gertk 1:0cbbb66a6100 1898 // Lcd_XY_address(0,1);
gertk 1:0cbbb66a6100 1899 // Lcd_ProgressBar((0xff-setting_contrast), 0x81);
gertk 1:0cbbb66a6100 1900 // SaveSettingsToEEPROM(); /*save value to EEPROM*/
gertk 0:28557a4d2215 1901 DelayBigMs(200);
gertk 0:28557a4d2215 1902 }
gertk 0:28557a4d2215 1903 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1904 printf("\r\nLCD-Darker, contrast =%02x",setting_contrast);
gertk 0:28557a4d2215 1905 OutputToLCD(); /*set standard output to LCD*/
gertk 1:0cbbb66a6100 1906 }
gertk 1:0cbbb66a6100 1907
gertk 1:0cbbb66a6100 1908 if (button_next == TRUE) { /*info button*/
gertk 0:28557a4d2215 1909 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 1910 printf("\r\nInfo button pressed");
gertk 0:28557a4d2215 1911 OutputToLCD(); /*set standard output to LCD*/
gertk 1:0cbbb66a6100 1912 // Lcd_clr();
gertk 0:28557a4d2215 1913 HardWareTestMenu();
gertk 1:0cbbb66a6100 1914 // Lcd_clr();
gertk 1:0cbbb66a6100 1915 break;
gertk 0:28557a4d2215 1916 }
gertk 0:28557a4d2215 1917 }
gertk 0:28557a4d2215 1918 }
gertk 0:28557a4d2215 1919
gertk 1:0cbbb66a6100 1920 void HardWareTestMenu(void) {
gertk 1:0cbbb66a6100 1921 // Lcd_clr();
gertk 1:0cbbb66a6100 1922 // Lcd_XY_address(0,0);
gertk 0:28557a4d2215 1923 printf("LED test");
gertk 1:0cbbb66a6100 1924 // Lcd_XY_address(0,2);
gertk 0:28557a4d2215 1925 printf("IO & settings");
gertk 0:28557a4d2215 1926 // Lcd_XY_address(0,4);
gertk 0:28557a4d2215 1927 printf("Exit");
gertk 0:28557a4d2215 1928 DelayBigMs(1000);
gertk 1:0cbbb66a6100 1929 while (1) {
gertk 0:28557a4d2215 1930 ReadButtons();
gertk 0:28557a4d2215 1931 if (button_prev == TRUE) /*LED-test routines*/
gertk 0:28557a4d2215 1932 { /*-----------------*/
gertk 1:0cbbb66a6100 1933 // Lcd_clr();
gertk 1:0cbbb66a6100 1934 // Lcd_XY_address(5,2);
gertk 0:28557a4d2215 1935 printf("OFF");
gertk 0:28557a4d2215 1936 LED_GREEN = 0;
gertk 0:28557a4d2215 1937 LED_RED = 0;
gertk 0:28557a4d2215 1938 DelayBigMs(2000);
gertk 1:0cbbb66a6100 1939 // Lcd_XY_address(4,2);
gertk 0:28557a4d2215 1940 printf("green");
gertk 0:28557a4d2215 1941 LED_GREEN = 1;
gertk 0:28557a4d2215 1942 LED_RED = 0;
gertk 0:28557a4d2215 1943 DelayBigMs(2000);
gertk 1:0cbbb66a6100 1944 // Lcd_XY_address(4,2);
gertk 0:28557a4d2215 1945 printf(" red ");
gertk 0:28557a4d2215 1946 LED_GREEN = 0;
gertk 0:28557a4d2215 1947 LED_RED = 1;
gertk 0:28557a4d2215 1948 DelayBigMs(2000);
gertk 1:0cbbb66a6100 1949 // Lcd_XY_address(3,2);
gertk 0:28557a4d2215 1950 printf("red+green");
gertk 0:28557a4d2215 1951 LED_GREEN = 1;
gertk 0:28557a4d2215 1952 LED_RED = 1;
gertk 0:28557a4d2215 1953 DelayBigMs(2000);
gertk 0:28557a4d2215 1954 LED_GREEN = 0;
gertk 0:28557a4d2215 1955 LED_RED = 0;
gertk 1:0cbbb66a6100 1956 break;
gertk 0:28557a4d2215 1957 }
gertk 1:0cbbb66a6100 1958
gertk 0:28557a4d2215 1959 if (button_select == TRUE) /*IO & settings*/
gertk 0:28557a4d2215 1960 { /*-------------*/
gertk 0:28557a4d2215 1961
gertk 1:0cbbb66a6100 1962 // Lcd_XY_address(0,4);
gertk 0:28557a4d2215 1963 printf("Contrast:%02X",setting_contrast);
gertk 1:0cbbb66a6100 1964 // Lcd_XY_address(0,5);
gertk 0:28557a4d2215 1965 printf("PCBtimer:%05d",PCB_type_timer);
gertk 0:28557a4d2215 1966
gertk 1:0cbbb66a6100 1967 DelayBigMs(3000);
gertk 1:0cbbb66a6100 1968 break;
gertk 1:0cbbb66a6100 1969 }
gertk 0:28557a4d2215 1970
gertk 0:28557a4d2215 1971 if (button_next == TRUE) /*Exit-button*/
gertk 0:28557a4d2215 1972 { /*-----------*/
gertk 1:0cbbb66a6100 1973 break;
gertk 0:28557a4d2215 1974 }
gertk 0:28557a4d2215 1975 }
gertk 0:28557a4d2215 1976 }
gertk 0:28557a4d2215 1977
gertk 0:28557a4d2215 1978
gertk 0:28557a4d2215 1979 /*this routine wait for a card to be inserted, once inserted it will be initialised, when all is OK this routine will exit*/
gertk 1:0cbbb66a6100 1980 unsigned char CardStatus(void) {
gertk 0:28557a4d2215 1981 unsigned char err_code;
gertk 0:28557a4d2215 1982
gertk 1:0cbbb66a6100 1983 if (CARD_DETECT == 1) {
gertk 1:0cbbb66a6100 1984 // Lcd_XY_address(4,1);
gertk 1:0cbbb66a6100 1985 // Lcd_CharBold();
gertk 0:28557a4d2215 1986 printf("INSERT");
gertk 1:0cbbb66a6100 1987 // Lcd_XY_address(5,3);
gertk 0:28557a4d2215 1988 printf("CARD");
gertk 1:0cbbb66a6100 1989 // Lcd_CharNormal();
gertk 1:0cbbb66a6100 1990 // Lcd_XY_address(0,5);
gertk 0:28557a4d2215 1991 printf(" (20%02d%02d%02d)",RELEASE_VERSION,RELEASE_VERSION_SUB,RELEASE_VERSION_SUB_SUB);
gertk 1:0cbbb66a6100 1992 DiskState = NO_CARD;
gertk 0:28557a4d2215 1993 return(FALSE);
gertk 0:28557a4d2215 1994 }
gertk 0:28557a4d2215 1995
gertk 1:0cbbb66a6100 1996 // Lcd_clr();
gertk 1:0cbbb66a6100 1997 // Lcd_XY_address(0,0);
gertk 0:28557a4d2215 1998 printf("Card detected ");
gertk 0:28557a4d2215 1999
gertk 0:28557a4d2215 2000 //if(WR_PROTECT == 1) /*check if the SD-cards write protect "switch" has been set*/
gertk 0:28557a4d2215 2001 //{
gertk 0:28557a4d2215 2002 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2003 // printf("Card wr. prot.");
gertk 1:0cbbb66a6100 2004 // DiskState = NO_CARD;
gertk 0:28557a4d2215 2005 // return(FALSE);
gertk 0:28557a4d2215 2006 //}
gertk 0:28557a4d2215 2007
gertk 1:0cbbb66a6100 2008 DelayMs(250); /*do not access card immediatly, wait for card to stabelise*/
gertk 0:28557a4d2215 2009 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2010 printf("Init. card: ");
gertk 0:28557a4d2215 2011 // Lcd_XY_address(0,2); /*set cursor to next line to print error messages*/
gertk 1:0cbbb66a6100 2012 if (Init_Card_SPI()) {
gertk 1:0cbbb66a6100 2013 DelayMs(100); /*do not access card immediatly...*/
gertk 0:28557a4d2215 2014 err_code = FindDrive();
gertk 1:0cbbb66a6100 2015 if (err_code != TRUE) {
gertk 1:0cbbb66a6100 2016 // Lcd_XY_address(0,3);
gertk 1:0cbbb66a6100 2017 switch (err_code) {
gertk 1:0cbbb66a6100 2018 case ERROR_ATAREAD_CMD17: {
gertk 0:28557a4d2215 2019 printf("ATA:err. CMD17"); /*CMD17 does not respond, the command is not accepted...*/
gertk 0:28557a4d2215 2020 break;
gertk 0:28557a4d2215 2021 }
gertk 1:0cbbb66a6100 2022
gertk 1:0cbbb66a6100 2023 case ERROR_ATAREAD_TIMEOUT: {
gertk 0:28557a4d2215 2024 printf("ATA:rd timeout"); /*timeout on waiting for start of data transfer*/
gertk 0:28557a4d2215 2025 break;
gertk 0:28557a4d2215 2026 }
gertk 0:28557a4d2215 2027
gertk 1:0cbbb66a6100 2028 case ERROR_FAT_READBOOTSECTOR: {
gertk 0:28557a4d2215 2029 printf("FAT:read boots");
gertk 0:28557a4d2215 2030 break;
gertk 0:28557a4d2215 2031 }
gertk 0:28557a4d2215 2032
gertk 1:0cbbb66a6100 2033 case ERROR_FAT_JUMPOPCODE: {
gertk 0:28557a4d2215 2034 printf("FAT:jump opcode");
gertk 0:28557a4d2215 2035 break;
gertk 0:28557a4d2215 2036 }
gertk 0:28557a4d2215 2037
gertk 1:0cbbb66a6100 2038 case ERROR_FAT_BLOCKSIZE: {
gertk 0:28557a4d2215 2039 printf("FAT:blocksize ");
gertk 0:28557a4d2215 2040 break;
gertk 0:28557a4d2215 2041 }
gertk 0:28557a4d2215 2042
gertk 1:0cbbb66a6100 2043 case ERROR_FAT_MEDIUM: {
gertk 0:28557a4d2215 2044 printf("FAT:wr. medium ");
gertk 0:28557a4d2215 2045 break;
gertk 0:28557a4d2215 2046 }
gertk 1:0cbbb66a6100 2047
gertk 1:0cbbb66a6100 2048 default: {
gertk 0:28557a4d2215 2049 printf("Undefined.....");
gertk 0:28557a4d2215 2050 break;
gertk 0:28557a4d2215 2051 }
gertk 0:28557a4d2215 2052 }
gertk 1:0cbbb66a6100 2053 // Lcd_XY_address(0,4);
gertk 0:28557a4d2215 2054 printf("Card not supp.");
gertk 1:0cbbb66a6100 2055 } else {
gertk 1:0cbbb66a6100 2056 // Lcd_XY_address(11,1);
gertk 0:28557a4d2215 2057 printf("OK");
gertk 1:0cbbb66a6100 2058 DiskState = CARD_ACTIVE;
gertk 0:28557a4d2215 2059 return(TRUE);
gertk 0:28557a4d2215 2060 }
gertk 0:28557a4d2215 2061 }
gertk 1:0cbbb66a6100 2062 DelayMs(100); /*when initialise failed wait before retry, otherwise the error message could not be read*/
gertk 1:0cbbb66a6100 2063 DiskState = NO_CARD;
gertk 0:28557a4d2215 2064 return(FALSE);
gertk 0:28557a4d2215 2065 }
gertk 0:28557a4d2215 2066
gertk 0:28557a4d2215 2067
gertk 0:28557a4d2215 2068 /*initialise MMC/SD-card in SPI-mode*/
gertk 1:0cbbb66a6100 2069 unsigned char Init_Card_SPI(void) {
gertk 0:28557a4d2215 2070 if (CARD_Init() == FALSE); /*The official initialisation routines as described in most of the documentation*/
gertk 0:28557a4d2215 2071 { /*If the official init fails, try the alternative init*/
gertk 1:0cbbb66a6100 2072 if (CARD_AlternativeInit() == FALSE) { /*The alternative init, required ONLY because SanDisk does not follow the world's standards... <zucht>*/
gertk 0:28557a4d2215 2073 return(FALSE);
gertk 0:28557a4d2215 2074 }
gertk 0:28557a4d2215 2075 }
gertk 0:28557a4d2215 2076
gertk 1:0cbbb66a6100 2077 // Card_CID(); /*request Card - ID*/
gertk 1:0cbbb66a6100 2078 // Card_CSD(); /*request Card Specific Data*/
gertk 1:0cbbb66a6100 2079
gertk 1:0cbbb66a6100 2080 if (CARD_OperatingConditions(Response_data) == FALSE) {
gertk 1:0cbbb66a6100 2081 printf("CARD:err CMD58");
gertk 0:28557a4d2215 2082 return(FALSE);
gertk 1:0cbbb66a6100 2083 } else {
gertk 1:0cbbb66a6100 2084 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 2085 printf("CARD:voltage ");
gertk 0:28557a4d2215 2086 return(FALSE);
gertk 0:28557a4d2215 2087 }
gertk 0:28557a4d2215 2088
gertk 0:28557a4d2215 2089 printf("CARD:OK ");
gertk 0:28557a4d2215 2090 return(TRUE);
gertk 0:28557a4d2215 2091 }
gertk 0:28557a4d2215 2092 }
gertk 0:28557a4d2215 2093
gertk 0:28557a4d2215 2094 /*This routine will count ALL files within the current directory (which could be root or subdirectory)*/
gertk 1:0cbbb66a6100 2095 void CountFiles(void) {
gertk 0:28557a4d2215 2096 print_device_status("COUNTING FILES"); /*inform the user about a possible time consuming task*/
gertk 0:28557a4d2215 2097
gertk 1:0cbbb66a6100 2098 if (FileSearch(&file,0)) { /*search for the first file on the card*/
gertk 0:28557a4d2215 2099 CountedFiles = 1;
gertk 1:0cbbb66a6100 2100 while (FileSearch(&file,1)) { /*goto the next file*/
gertk 0:28557a4d2215 2101 /*count ALL files (even the irrelevant files, since they do occupy diskspace, max 512 files in root you know)*/
gertk 0:28557a4d2215 2102 CountedFiles++; /*increment file-counter*/
gertk 0:28557a4d2215 2103 }
gertk 0:28557a4d2215 2104 FileSearch(&file,0); /*set the search routines back to the first file*/
gertk 1:0cbbb66a6100 2105 } else {
gertk 0:28557a4d2215 2106 CountedFiles = 0;
gertk 0:28557a4d2215 2107 }
gertk 0:28557a4d2215 2108
gertk 1:0cbbb66a6100 2109 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 2110 printf("\r\nNumber of files in current (sub)dir: %d",CountedFiles);
gertk 1:0cbbb66a6100 2111 // OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2112 }
gertk 0:28557a4d2215 2113
gertk 0:28557a4d2215 2114 /*This routine will 'filter' the currently 'selected' file,*/
gertk 0:28557a4d2215 2115 /*when the file does not meet the expected standards it returns 'FALSE'*/
gertk 1:0cbbb66a6100 2116 unsigned char FileFilter(void) {
gertk 0:28557a4d2215 2117 /* Disk type | Size */
gertk 0:28557a4d2215 2118 /* --------------------------+--------*/
gertk 0:28557a4d2215 2119 /* 35 track, no errors | 174848 */
gertk 0:28557a4d2215 2120 /* 35 track, 683 error bytes | 175531 */
gertk 0:28557a4d2215 2121 /* 40 track, no errors | 196608 */
gertk 0:28557a4d2215 2122 /* 40 track, 768 error bytes | 197376 */
gertk 0:28557a4d2215 2123
gertk 1:0cbbb66a6100 2124 if ((file.name[8] == 'P') && (file.name[9] == 'R') && (file.name[10] == 'G')) {
gertk 0:28557a4d2215 2125 return(PRG_FILE);
gertk 0:28557a4d2215 2126 }
gertk 0:28557a4d2215 2127
gertk 1:0cbbb66a6100 2128 if ((file.name[8] == 'D') && (file.name[9] == '6') && (file.name[10] == '4')) {
gertk 0:28557a4d2215 2129 if (file.size == 174848)
gertk 0:28557a4d2215 2130 return(D64_35T_MODE);
gertk 0:28557a4d2215 2131
gertk 0:28557a4d2215 2132 if (file.size == 175531)
gertk 0:28557a4d2215 2133 return(D64_35T_ER_MODE);
gertk 0:28557a4d2215 2134
gertk 0:28557a4d2215 2135 if (file.size == 196608)
gertk 0:28557a4d2215 2136 return(D64_40T_MODE);
gertk 0:28557a4d2215 2137
gertk 0:28557a4d2215 2138 if (file.size == 177376)
gertk 0:28557a4d2215 2139 return(D64_40T_ER_MODE);
gertk 0:28557a4d2215 2140 }
gertk 0:28557a4d2215 2141
gertk 0:28557a4d2215 2142 // if((file.name[8] == 'T') && (file.name[9] == '6') && (file.name[10] == '4'))
gertk 0:28557a4d2215 2143 // {
gertk 0:28557a4d2215 2144 // return(T64_MODE);
gertk 0:28557a4d2215 2145 // }
gertk 0:28557a4d2215 2146
gertk 1:0cbbb66a6100 2147 if ((file.size == 0) && (file.cluster!=0))
gertk 0:28557a4d2215 2148 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 2149
gertk 0:28557a4d2215 2150 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 2151 return(SUBDIRECTORY); /*this subdirectory points to the current directory*/
gertk 0:28557a4d2215 2152
gertk 0:28557a4d2215 2153 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 2154 return(SUBDIRECTORY); /*this subdirectory points to the parent directory (which could be root)*/
gertk 0:28557a4d2215 2155
gertk 0:28557a4d2215 2156 if ((file.name[0] != 0x20) && (file.name[8] == 0x20) && (file.name[9] == 0x20) && (file.name[10] == 0x20))
gertk 0:28557a4d2215 2157 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 2158
gertk 0:28557a4d2215 2159 return(FALSE);
gertk 0:28557a4d2215 2160 }
gertk 0:28557a4d2215 2161
gertk 0:28557a4d2215 2162 /*this routine will search for the next available buffer, when no buffer can be found it responds with 255*/
gertk 1:0cbbb66a6100 2163 unsigned char SearchFreeBuffer(void) {
gertk 0:28557a4d2215 2164 unsigned char lp;
gertk 0:28557a4d2215 2165
gertk 0:28557a4d2215 2166 lp=0;
gertk 1:0cbbb66a6100 2167 while (lp<MAX_NUMBER_OF_DOS_BUFFERS) {
gertk 1:0cbbb66a6100 2168 if (DOS_buffer[lp].buffer_in_use == FALSE) { /*TRUE means that this channel is in use, FALSE means it is available*/
gertk 1:0cbbb66a6100 2169 return(lp); /*return with the number of the available channel*/
gertk 0:28557a4d2215 2170 }
gertk 0:28557a4d2215 2171 lp++;
gertk 0:28557a4d2215 2172 }
gertk 0:28557a4d2215 2173 return(255); /*an error has occurred, there are no free channels left*/
gertk 0:28557a4d2215 2174 }
gertk 0:28557a4d2215 2175
gertk 0:28557a4d2215 2176 /*****************************************************************************************************************/
gertk 0:28557a4d2215 2177
gertk 0:28557a4d2215 2178 /*this routine will wait untill a string has been loaded that is terminated by an EOI*/
gertk 1:0cbbb66a6100 2179 void WaitForString(unsigned char *outputstring, unsigned frame_handshake) {
gertk 0:28557a4d2215 2180 unsigned char cnt;
gertk 0:28557a4d2215 2181
gertk 0:28557a4d2215 2182 TimeOut = FALSE;
gertk 0:28557a4d2215 2183 EOI = FALSE;
gertk 0:28557a4d2215 2184 cnt = 0;
gertk 1:0cbbb66a6100 2185 while ((TimeOut == FALSE) && (EOI == FALSE)) { /*get filename/instruction, this is all data untill an EOI is received*/
gertk 0:28557a4d2215 2186 outputstring[cnt] = IEC_receive(frame_handshake); /*save the received char to a string specified by the caller of this routine*/
gertk 0:28557a4d2215 2187 // printf("%02x", outputstring[cnt]); /*print string to be captured for debug purposes...*/
gertk 0:28557a4d2215 2188 cnt++;
gertk 0:28557a4d2215 2189 }
gertk 0:28557a4d2215 2190 outputstring[cnt] = 0; /*close the string with a "nul"*/
gertk 0:28557a4d2215 2191 }
gertk 0:28557a4d2215 2192
gertk 0:28557a4d2215 2193
gertk 0:28557a4d2215 2194 /*This routine will search for the first 'number' and puts this number into a register*/
gertk 0:28557a4d2215 2195 /*it returns 0 (FALSE) when the number does not fit into an unsigned char*/
gertk 0:28557a4d2215 2196 /*it returns the position of the character AFTER the number. so that this can be used for the next number search...*/
gertk 1:0cbbb66a6100 2197 unsigned char ValueFromString(unsigned char *inputstring, unsigned char *outputvalue) {
gertk 0:28557a4d2215 2198 unsigned char lp;
gertk 1:0cbbb66a6100 2199
gertk 0:28557a4d2215 2200 lp = 0;
gertk 0:28557a4d2215 2201 *outputvalue = 0;
gertk 0:28557a4d2215 2202
gertk 1:0cbbb66a6100 2203 while ((inputstring[lp] < '0') || (inputstring[lp] > '9')) { /*check if this character is not a number*/
gertk 0:28557a4d2215 2204 lp++; /*keep looping until a number is found*/
gertk 1:0cbbb66a6100 2205 if (inputstring[lp] == 0) { /*when the end of the string has been reached, exit false*/
gertk 1:0cbbb66a6100 2206 return(FALSE); /*if there were no numbers at the beginning of this string, return FALSE*/
gertk 0:28557a4d2215 2207 }
gertk 0:28557a4d2215 2208 }
gertk 0:28557a4d2215 2209
gertk 1:0cbbb66a6100 2210 while ((inputstring[lp] >= '0') && (inputstring[lp] <= '9')) { /*check if this character is a number*/
gertk 1:0cbbb66a6100 2211 if (*outputvalue > 25) {
gertk 0:28557a4d2215 2212 return(FALSE); /*the number in the string is larger the 255 and is not a 'unsigned char' exit routine*/
gertk 1:0cbbb66a6100 2213 } else {
gertk 1:0cbbb66a6100 2214 *outputvalue = *outputvalue * 10;
gertk 0:28557a4d2215 2215 *outputvalue = *outputvalue + (inputstring[lp] - '0');
gertk 0:28557a4d2215 2216 lp++;
gertk 0:28557a4d2215 2217 }
gertk 0:28557a4d2215 2218 }
gertk 0:28557a4d2215 2219
gertk 0:28557a4d2215 2220 return(lp); /*the first position directly after the number*/
gertk 0:28557a4d2215 2221 }
gertk 0:28557a4d2215 2222
gertk 0:28557a4d2215 2223
gertk 0:28557a4d2215 2224 /*This routine will search for the first 'number' and puts this number into a register*/
gertk 0:28557a4d2215 2225 /*the number has to start a the first character otherwise it returns false*/
gertk 1:0cbbb66a6100 2226 unsigned char LongValueFromString(unsigned char *inputstring, unsigned long *outputvalue) {
gertk 0:28557a4d2215 2227 unsigned char lp;
gertk 1:0cbbb66a6100 2228
gertk 0:28557a4d2215 2229 lp = 0;
gertk 0:28557a4d2215 2230 *outputvalue = 0;
gertk 0:28557a4d2215 2231
gertk 1:0cbbb66a6100 2232 while ((inputstring[lp] >= '0') && (inputstring[lp] <= '9')) { /*check if this character is a number*/
gertk 1:0cbbb66a6100 2233 *outputvalue = *outputvalue * 10;
gertk 0:28557a4d2215 2234 *outputvalue = *outputvalue + (inputstring[lp] - '0');
gertk 0:28557a4d2215 2235 lp++;
gertk 0:28557a4d2215 2236 }
gertk 0:28557a4d2215 2237
gertk 0:28557a4d2215 2238 return(lp); /*the first position directly after the number*/
gertk 0:28557a4d2215 2239 }
gertk 0:28557a4d2215 2240
gertk 0:28557a4d2215 2241
gertk 0:28557a4d2215 2242 /*this routine extract the filename from the command string, it will remove all unwanted options and leaves the filename only */
gertk 0:28557a4d2215 2243 /*Some of the possible entries to indicate the problem to be solved by this routine: */
gertk 0:28557a4d2215 2244 /*normal open : commandstring = "0:filename,s,r" */
gertk 0:28557a4d2215 2245 /*simplified open: commandstring = "filename,s,r" */
gertk 0:28557a4d2215 2246 /*simplified open: commandstring = "filename" */
gertk 0:28557a4d2215 2247 /*simplified open: commandstring = "0:filename" */
gertk 0:28557a4d2215 2248 /*replacement : commandstring = "@0:filename,s,r" */
gertk 0:28557a4d2215 2249 /*copy : commandstring = "C0:backup=original" */
gertk 0:28557a4d2215 2250 /*multiple copy : commandstring = "COPY0:<destfile>=<sourcefile>" or "COPY:<destfile>=<sourcefile1>, <sourcefile2>, ..." */
gertk 0:28557a4d2215 2251 /*therefore we may conclude that everything AFTER ':' and BEFORE ',' (or end-of-string) is the filename */
gertk 1:0cbbb66a6100 2252 void ExtractFilenameFromString(unsigned char *input_string, unsigned char *output_string) {
gertk 1:0cbbb66a6100 2253 unsigned char tempstring[41];
gertk 0:28557a4d2215 2254
gertk 0:28557a4d2215 2255 strcpy((char *)tempstring, (char *)input_string); /*this is required because the splitstring_on function destroys the inputvalues*/
gertk 0:28557a4d2215 2256 if (!SplitStringOn_Sign(':', tempstring, output_string)) /*remove all characters BEFORE the ':'-sign*/
gertk 0:28557a4d2215 2257 { /*if this succeeds the ':'-sign was found we can continue 'stripping' the string*/
gertk 1:0cbbb66a6100 2258 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 2259 }
gertk 0:28557a4d2215 2260 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 2261 }
gertk 0:28557a4d2215 2262
gertk 0:28557a4d2215 2263
gertk 0:28557a4d2215 2264
gertk 0:28557a4d2215 2265 /*this routine will strip all characters before the given sign*/
gertk 0:28557a4d2215 2266 /*it will return the characters BEFORE the first sign in BEFORE_STRING (sign is not included in the result)*/
gertk 0:28557a4d2215 2267 /*it will return the characters AFTER the first sign in AFTER_STRING (sign is not included in the result)*/
gertk 1:0cbbb66a6100 2268 unsigned char SplitStringOn_Sign(unsigned char sign, unsigned char *beforesign_string, unsigned char *aftersign_string) {
gertk 0:28557a4d2215 2269 unsigned char lp, lp2;
gertk 1:0cbbb66a6100 2270
gertk 0:28557a4d2215 2271 lp = 0;
gertk 1:0cbbb66a6100 2272 while (beforesign_string[lp]) {
gertk 1:0cbbb66a6100 2273 if (beforesign_string[lp] == sign) {
gertk 0:28557a4d2215 2274 lp++;
gertk 0:28557a4d2215 2275 lp2 = 0;
gertk 1:0cbbb66a6100 2276 while (beforesign_string[lp+lp2]) {
gertk 0:28557a4d2215 2277 aftersign_string[lp2] = beforesign_string[lp+lp2];
gertk 0:28557a4d2215 2278 lp2++;
gertk 0:28557a4d2215 2279 }
gertk 0:28557a4d2215 2280 beforesign_string[--lp] = 0; /*terminate the command_string, the :-sign is not included any more in te string*/
gertk 0:28557a4d2215 2281 aftersign_string[lp2] = 0; /*terminate the copied string*/
gertk 0:28557a4d2215 2282 return(TRUE); /*indicate that the conversion (removal of all chars before :-sign) has succeeded*/
gertk 0:28557a4d2215 2283 }
gertk 1:0cbbb66a6100 2284 lp++;
gertk 0:28557a4d2215 2285 }
gertk 0:28557a4d2215 2286 return(FALSE); /*indicate that the conversion (removal of all chars before :-sign) has failed*/
gertk 0:28557a4d2215 2287 }
gertk 0:28557a4d2215 2288
gertk 0:28557a4d2215 2289
gertk 0:28557a4d2215 2290 /*****************************************************************************************************************/
gertk 0:28557a4d2215 2291
gertk 0:28557a4d2215 2292 /*this routine print some prefedined text to the display AND serial port*/
gertk 1:0cbbb66a6100 2293 void print_device_status(const unsigned char *message) {
gertk 0:28557a4d2215 2294 // Lcd_XY_address(0,2);
gertk 0:28557a4d2215 2295 // Lcd_CharBold();
gertk 0:28557a4d2215 2296 printf("%s",message);
gertk 0:28557a4d2215 2297 // Lcd_CharNormal();
gertk 0:28557a4d2215 2298
gertk 0:28557a4d2215 2299 OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 2300 printf("\r\n%s",message);
gertk 0:28557a4d2215 2301 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2302 }
gertk 0:28557a4d2215 2303
gertk 0:28557a4d2215 2304 /*this routine print the name of the current file (which is suppost to be a D64 file)*/
gertk 1:0cbbb66a6100 2305 void print_D64_name(unsigned char mode) {
gertk 0:28557a4d2215 2306 unsigned char i;
gertk 0:28557a4d2215 2307
gertk 0:28557a4d2215 2308 if (mode == INVERTED) /*depending on requested mode print in normal or inverse-mode*/
gertk 0:28557a4d2215 2309 // Lcd_CharInvert();
gertk 1:0cbbb66a6100 2310
gertk 0:28557a4d2215 2311 // Lcd_XY_address(0,0);
gertk 1:0cbbb66a6100 2312 printf("%05d in dir. ",CountedFiles); /*show the total number of files (sub)directory*/
gertk 0:28557a4d2215 2313 // Lcd_XY_address(0,1); /*set cursor to line we want to use*/
gertk 0:28557a4d2215 2314
gertk 1:0cbbb66a6100 2315 if (file_type == NONE) {
gertk 0:28557a4d2215 2316 printf("%05d= ",file_number); /*show the current selection and clear the line*/
gertk 1:0cbbb66a6100 2317 // Lcd_XY_address(6,1); /*set cursor back...*/
gertk 1:0cbbb66a6100 2318 } else {
gertk 0:28557a4d2215 2319 printf("%05d= ",file_number); /*show the current selection and clear the line*/
gertk 1:0cbbb66a6100 2320 // Lcd_XY_address(6,1); /*set cursor back...*/
gertk 1:0cbbb66a6100 2321 for (i=0; i<8; i++) /*print selection (or currently selected) 8.3-filename*/
gertk 0:28557a4d2215 2322 putch(file.name[i]); /*character after character*/
gertk 0:28557a4d2215 2323
gertk 0:28557a4d2215 2324 OutputToRS232(); /*output the same info to the serial port also*/
gertk 0:28557a4d2215 2325 printf("\r\nfilename:");
gertk 1:0cbbb66a6100 2326 for (i=0; i<8; i++) /*print selection (or currently selected) 8.3-filename*/
gertk 0:28557a4d2215 2327 putch(file.name[i]); /*character after character*/
gertk 0:28557a4d2215 2328 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2329 }
gertk 0:28557a4d2215 2330
gertk 0:28557a4d2215 2331 // Lcd_CharNormal();
gertk 0:28557a4d2215 2332 // Lcd_XY_address(0,5);
gertk 1:0cbbb66a6100 2333 printf("%c=%02d ",0x0d,devicenumber); /*print the device number on the display*/
gertk 1:0cbbb66a6100 2334 if (file_type == NONE) /*indicate on the display we are working in the root-dir of the card (HD-mode*/
gertk 1:0cbbb66a6100 2335 printf("Hard-disk");
gertk 1:0cbbb66a6100 2336 if (file_type == SUBDIRECTORY) /*indicate on the display we are working in the root-dir of the card (HD-mode*/
gertk 1:0cbbb66a6100 2337 printf("Hard-disk");
gertk 1:0cbbb66a6100 2338 if (file_type == PRG_FILE) /*...*/
gertk 1:0cbbb66a6100 2339 printf("PRG-file ");
gertk 1:0cbbb66a6100 2340 if (file_type == UNKNOWN) /*...*/
gertk 1:0cbbb66a6100 2341 printf("-UNKNOWN-");
gertk 1:0cbbb66a6100 2342 if (file_type == D64_35T_MODE) /*indicate on the display the D64 file 35 tracks no errors*/
gertk 1:0cbbb66a6100 2343 printf(".D64 35T ");
gertk 1:0cbbb66a6100 2344 if (file_type == D64_35T_ER_MODE) /*indicate on the display the D64 file 35 tracks with errors*/
gertk 1:0cbbb66a6100 2345 printf(".D64 35Te");
gertk 1:0cbbb66a6100 2346 if (file_type == D64_40T_MODE) /*indicate on the display the D64 file 40 tracks no errors*/
gertk 1:0cbbb66a6100 2347 printf(".D64 40T ");
gertk 1:0cbbb66a6100 2348 if (file_type == D64_40T_ER_MODE) /*indicate on the display the D64 file 40 tracks with errors*/
gertk 1:0cbbb66a6100 2349 printf(".D64 40Te");
gertk 1:0cbbb66a6100 2350 if (file_type == T64_MODE) /*indicate on the display the T64*/
gertk 0:28557a4d2215 2351 printf(".T64-mode");
gertk 0:28557a4d2215 2352 }
gertk 0:28557a4d2215 2353
gertk 0:28557a4d2215 2354 /*this routine prints Track Sector and (remaining/loaded) blocks*/
gertk 1:0cbbb66a6100 2355 void print_D64_TSB(unsigned char trk, unsigned char sec, unsigned int blk, unsigned int total_blk) {
gertk 0:28557a4d2215 2356 static unsigned char previous_track;
gertk 0:28557a4d2215 2357 unsigned int blockcounter;
gertk 0:28557a4d2215 2358
gertk 0:28557a4d2215 2359 blockcounter = total_blk - blk; /*calculate the current block*/
gertk 0:28557a4d2215 2360
gertk 1:0cbbb66a6100 2361 // Lcd_XY_address(0,3); /*set the LCD coordinates*/
gertk 1:0cbbb66a6100 2362 // Lcd_ProgressBar(blk, total_blk); /*draw a progress bar*/
gertk 1:0cbbb66a6100 2363 // Lcd_XY_address(0,4); /*set the LCD coordinates*/
gertk 0:28557a4d2215 2364 printf("%c=%02d T=%02d S=%02d",0x0e,error_code,trk,sec); /*show the error code, track and sector*/
gertk 0:28557a4d2215 2365
gertk 0:28557a4d2215 2366 OutputToRS232(); /*output the same info to the serial port also*/
gertk 0:28557a4d2215 2367 printf("\r\n%02d,%02d,%d/%d",trk,sec,blockcounter,total_blk); /*send to serial the Track and sector info*/
gertk 0:28557a4d2215 2368 OutputToLCD(); /*set standard output to LCD*/
gertk 0:28557a4d2215 2369
gertk 0:28557a4d2215 2370 //Sound_TrackChange(trk-previous_track); /*play a sound (if required) of a moving head*/
gertk 0:28557a4d2215 2371 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 2372 }
gertk 0:28557a4d2215 2373
gertk 0:28557a4d2215 2374
gertk 0:28557a4d2215 2375
gertk 0:28557a4d2215 2376 /*this routine is to be used to select a D64 image from the inserted card*/
gertk 1:0cbbb66a6100 2377 void SelectD64Image(void) {
gertk 0:28557a4d2215 2378 unsigned char filefilter_result;
gertk 0:28557a4d2215 2379 unsigned char blink_loop;
gertk 0:28557a4d2215 2380
gertk 0:28557a4d2215 2381 ReadButtons();
gertk 1:0cbbb66a6100 2382 if (button_prev == TRUE) {
gertk 1:0cbbb66a6100 2383 if (file_number == 1) {
gertk 0:28557a4d2215 2384 file_number=0; /*file counter is now '0' which means 'ROOT directory'*/
gertk 0:28557a4d2215 2385 file_type = NONE; /*and because the user has selected root, the selected file_type = NONE*/
gertk 1:0cbbb66a6100 2386 } else {
gertk 1:0cbbb66a6100 2387 if (file_number > 1) {
gertk 1:0cbbb66a6100 2388 if (FileSearch(&file,2)) { /*goto the previous D64 file*/
gertk 0:28557a4d2215 2389 file_number--; /*decrease selected file counter*/
gertk 0:28557a4d2215 2390 }
gertk 0:28557a4d2215 2391 filefilter_result = FileFilter(); /*check the selected file*/
gertk 0:28557a4d2215 2392 file_type = filefilter_result;
gertk 0:28557a4d2215 2393 }
gertk 0:28557a4d2215 2394 }
gertk 0:28557a4d2215 2395 DiskState = INVALID_POINTER;
gertk 1:0cbbb66a6100 2396 // Lcd_XY_address(0,3);
gertk 1:0cbbb66a6100 2397 // Lcd_SelectionBar((CountedFiles-file_number), CountedFiles);
gertk 0:28557a4d2215 2398 print_D64_name(INVERTED); /*write the selection to display in inverted mode*/
gertk 0:28557a4d2215 2399 DelayBigMs(BUTTON_SELECTION_RATE); /*delay determines selection repetition rate*/
gertk 0:28557a4d2215 2400 }
gertk 0:28557a4d2215 2401
gertk 1:0cbbb66a6100 2402 if (button_next == TRUE) {
gertk 1:0cbbb66a6100 2403 if (file_number < CountedFiles) {
gertk 0:28557a4d2215 2404 if (file_number == 0) /*the first file on the card needs no search since it is allready found*/
gertk 0:28557a4d2215 2405 file_number++; /*increase selected file counter*/
gertk 1:0cbbb66a6100 2406 else if (FileSearch(&file,1)) /*goto the next D64 file*/
gertk 1:0cbbb66a6100 2407 file_number++; /*increase selected file counter*/
gertk 0:28557a4d2215 2408 }
gertk 0:28557a4d2215 2409 filefilter_result = FileFilter(); /*check the selected file*/
gertk 0:28557a4d2215 2410 file_type = filefilter_result;
gertk 0:28557a4d2215 2411 DiskState = INVALID_POINTER;
gertk 1:0cbbb66a6100 2412 // Lcd_XY_address(0,3);
gertk 1:0cbbb66a6100 2413 // Lcd_SelectionBar((CountedFiles-file_number), CountedFiles);
gertk 0:28557a4d2215 2414 print_D64_name(INVERTED); /*write the selection to display in inverted mode*/
gertk 0:28557a4d2215 2415 DelayBigMs(BUTTON_SELECTION_RATE); /*delay determines selection repetition rate*/
gertk 0:28557a4d2215 2416 }
gertk 0:28557a4d2215 2417
gertk 1:0cbbb66a6100 2418 if (button_select == TRUE) {
gertk 0:28557a4d2215 2419 filefilter_result = FileFilter(); /*check the selected file*/
gertk 0:28557a4d2215 2420 file_type = filefilter_result;
gertk 0:28557a4d2215 2421
gertk 1:0cbbb66a6100 2422 if (file_number==0) { /*file counter is now '0' which means 'ROOT directory'*/
gertk 0:28557a4d2215 2423 file_type = NONE; /*and because the user has selected root, the selected file_type = NONE*/
gertk 1:0cbbb66a6100 2424 // Lcd_XY_address(0,2); /*set cursor*/
gertk 0:28557a4d2215 2425 printf(" "); /*clear the file_info information*/
gertk 0:28557a4d2215 2426 print_D64_name(PLAIN); /*write the selection to display in normal-mode*/
gertk 0:28557a4d2215 2427 DiskState = CARD_ACTIVE; /*the 1541-III is now functioning as a harddisk*/
gertk 0:28557a4d2215 2428 DelayBigMs(BUTTON_SELECTION_RATE); /*delay determines selection repetition rate*/
gertk 1:0cbbb66a6100 2429 } else {
gertk 1:0cbbb66a6100 2430 if (filefilter_result == SUBDIRECTORY) {
gertk 0:28557a4d2215 2431 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 2432 file_number = 0; /*the file_number counter needs to be reset*/
gertk 0:28557a4d2215 2433 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 1:0cbbb66a6100 2434
gertk 0:28557a4d2215 2435 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 2436 CountFiles(); /*count all files in the opened directory*/
gertk 0:28557a4d2215 2437 print_D64_name(PLAIN); /*write the selection to display in normal-mode, the countvalues are updated*/
gertk 1:0cbbb66a6100 2438 // Lcd_XY_address(0,2); /*set cursor*/
gertk 0:28557a4d2215 2439 printf(" "); /*clear the file_info information*/
gertk 0:28557a4d2215 2440 DiskState = CARD_ACTIVE; /*the 1541-III is now functioning as a harddisk*/
gertk 0:28557a4d2215 2441 DelayBigMs(BUTTON_SELECTION_RATE); /*delay determines selection repetition rate*/
gertk 1:0cbbb66a6100 2442 } else {
gertk 1:0cbbb66a6100 2443 if ((filefilter_result != PRG_FILE) && (filefilter_result != UNKNOWN)) { /*pass all supported D64 files and leave out PRG and unknown files*/
gertk 0:28557a4d2215 2444 FileSectorScan(&file); /*update the sector location table cache*/
gertk 0:28557a4d2215 2445 D64ReadBAM(); /*update the BAM*/
gertk 0:28557a4d2215 2446 DiskState = CARD_ACTIVE; /*the 1541-III is now accessable*/
gertk 1:0cbbb66a6100 2447 // Lcd_XY_address(0,2); /*set cursor*/
gertk 0:28557a4d2215 2448 printf(" "); /*clear the file_info information*/
gertk 0:28557a4d2215 2449 print_D64_name(PLAIN); /*write the selection to display in normal-mode*/
gertk 1:0cbbb66a6100 2450 } else {
gertk 1:0cbbb66a6100 2451 for (blink_loop=4; blink_loop>0; blink_loop--) { /*create a blinking effect to draw attention to this line*/
gertk 1:0cbbb66a6100 2452 // Lcd_CharInvert();
gertk 1:0cbbb66a6100 2453 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2454 printf("Selection err.");
gertk 1:0cbbb66a6100 2455 DelayBigMs(250); /*delay to make sure the message can be read properly*/
gertk 1:0cbbb66a6100 2456 // Lcd_CharNormal();
gertk 1:0cbbb66a6100 2457 // Lcd_XY_address(0,1);
gertk 0:28557a4d2215 2458 printf("Selection err.");
gertk 1:0cbbb66a6100 2459 DelayBigMs(250); /*delay to make sure the message can be read properly*/
gertk 0:28557a4d2215 2460 }
gertk 0:28557a4d2215 2461 print_D64_name(INVERTED); /*write the selection to display in inverted mode*/
gertk 0:28557a4d2215 2462 }
gertk 0:28557a4d2215 2463 }
gertk 0:28557a4d2215 2464 }
gertk 0:28557a4d2215 2465 }
gertk 0:28557a4d2215 2466 }
gertk 0:28557a4d2215 2467
gertk 0:28557a4d2215 2468 /*****************************************************************************************************************/
gertk 0:28557a4d2215 2469 /*almost identical to loading a directory (seen from a C64)*/
gertk 0:28557a4d2215 2470 /*This routine shows 'all' the files on the card*/
gertk 0:28557a4d2215 2471
gertk 0:28557a4d2215 2472 /*Note: 'all' means the files that are OK according the filefilter routine*/
gertk 1:0cbbb66a6100 2473 void CardDirectory(void) {
gertk 0:28557a4d2215 2474 unsigned pass_counter;
gertk 0:28557a4d2215 2475 unsigned char separation_line=FALSE;
gertk 0:28557a4d2215 2476 unsigned char filefilter_result;
gertk 0:28557a4d2215 2477 unsigned int index_cnt;
gertk 0:28557a4d2215 2478 unsigned char lp;
gertk 0:28557a4d2215 2479 unsigned char dir_width;
gertk 0:28557a4d2215 2480 unsigned int blocksize;
gertk 0:28557a4d2215 2481
gertk 0:28557a4d2215 2482 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 2483 EOI = FALSE;
gertk 0:28557a4d2215 2484 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 2485
gertk 0:28557a4d2215 2486 /*----------------*/
gertk 0:28557a4d2215 2487 /*directory header*/
gertk 1:0cbbb66a6100 2488 /*----------------*/
gertk 0:28557a4d2215 2489 IEC_send(0x01); /*load this "program" to start address 0x0401*/
gertk 0:28557a4d2215 2490 IEC_send(0x04);
gertk 0:28557a4d2215 2491
gertk 1:0cbbb66a6100 2492 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 2493 { /* | |*/ /*useable area of a VC-20 dir line*/
gertk 0:28557a4d2215 2494 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 1:0cbbb66a6100 2495 IEC_send(0x01);
gertk 1:0cbbb66a6100 2496 IEC_send(0x01);
gertk 1:0cbbb66a6100 2497 IEC_send(0x00);
gertk 1:0cbbb66a6100 2498 IEC_send(0x00);
gertk 1:0cbbb66a6100 2499 IEC_send(0x20);
gertk 1:0cbbb66a6100 2500 IEC_send(0x12);
gertk 1:0cbbb66a6100 2501 IEC_send(0x20);
gertk 1:0cbbb66a6100 2502 IEC_send(0x22);
gertk 1:0cbbb66a6100 2503 IEC_send_string("CARD DIRECTORY");
gertk 1:0cbbb66a6100 2504 IEC_send(0x22);
gertk 1:0cbbb66a6100 2505 IEC_send(0x00); /*VIC-20 Directory header*/
gertk 1:0cbbb66a6100 2506 IEC_send(0x01);
gertk 1:0cbbb66a6100 2507 IEC_send(0x01);
gertk 1:0cbbb66a6100 2508 IEC_send(0x00);
gertk 1:0cbbb66a6100 2509 IEC_send(0x00);
gertk 1:0cbbb66a6100 2510 IEC_send(0x20);
gertk 1:0cbbb66a6100 2511 IEC_send(0x20);
gertk 1:0cbbb66a6100 2512 IEC_send(0x22);
gertk 1:0cbbb66a6100 2513 IEC_send_string("u``````````i");
gertk 1:0cbbb66a6100 2514 IEC_send(0x22);
gertk 1:0cbbb66a6100 2515 IEC_send(0x00); /*top-line*/
gertk 1:0cbbb66a6100 2516 IEC_send(0x01);
gertk 1:0cbbb66a6100 2517 IEC_send(0x01);
gertk 1:0cbbb66a6100 2518 IEC_send(0x00);
gertk 1:0cbbb66a6100 2519 IEC_send(0x00);
gertk 1:0cbbb66a6100 2520 IEC_send(0x20);
gertk 1:0cbbb66a6100 2521 IEC_send(0x20);
gertk 1:0cbbb66a6100 2522 IEC_send(0x22);
gertk 1:0cbbb66a6100 2523 IEC_send_string("} 1541-III }");
gertk 1:0cbbb66a6100 2524 IEC_send(0x22);
gertk 1:0cbbb66a6100 2525 IEC_send(0x00); /*model*/
gertk 1:0cbbb66a6100 2526 IEC_send(0x01);
gertk 1:0cbbb66a6100 2527 IEC_send(0x01);
gertk 1:0cbbb66a6100 2528 IEC_send(0x00);
gertk 1:0cbbb66a6100 2529 IEC_send(0x00);
gertk 1:0cbbb66a6100 2530 IEC_send(0x20);
gertk 1:0cbbb66a6100 2531 IEC_send(0x20);
gertk 1:0cbbb66a6100 2532 IEC_send(0x22);
gertk 1:0cbbb66a6100 2533 IEC_send_string("}J. DEROGEE}");
gertk 1:0cbbb66a6100 2534 IEC_send(0x22);
gertk 1:0cbbb66a6100 2535 IEC_send(0x00); /*credits*/
gertk 1:0cbbb66a6100 2536 IEC_send(0x01);
gertk 1:0cbbb66a6100 2537 IEC_send(0x01);
gertk 1:0cbbb66a6100 2538 IEC_send(0x00);
gertk 1:0cbbb66a6100 2539 IEC_send(0x00);
gertk 1:0cbbb66a6100 2540 IEC_send(0x20);
gertk 1:0cbbb66a6100 2541 IEC_send(0x20);
gertk 1:0cbbb66a6100 2542 IEC_send(0x22);
gertk 1:0cbbb66a6100 2543 IEC_send_string("}VIC20-MODE}");
gertk 1:0cbbb66a6100 2544 IEC_send(0x22);
gertk 1:0cbbb66a6100 2545 IEC_send(0x00); /*credits*/
gertk 1:0cbbb66a6100 2546 IEC_send(0x01);
gertk 1:0cbbb66a6100 2547 IEC_send(0x01);
gertk 1:0cbbb66a6100 2548 IEC_send(0x00);
gertk 1:0cbbb66a6100 2549 IEC_send(0x00);
gertk 1:0cbbb66a6100 2550 IEC_send(0x20);
gertk 1:0cbbb66a6100 2551 IEC_send(0x20);
gertk 1:0cbbb66a6100 2552 IEC_send(0x22);
gertk 1:0cbbb66a6100 2553 IEC_send_string("j``````````k");
gertk 1:0cbbb66a6100 2554 IEC_send(0x22);
gertk 1:0cbbb66a6100 2555 IEC_send(0x00); /*separation-line*/
gertk 1:0cbbb66a6100 2556 } else {
gertk 0:28557a4d2215 2557 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 1:0cbbb66a6100 2558 IEC_send(0x01);
gertk 1:0cbbb66a6100 2559 IEC_send(0x01);
gertk 1:0cbbb66a6100 2560 IEC_send(0x00);
gertk 1:0cbbb66a6100 2561 IEC_send(0x00);
gertk 1:0cbbb66a6100 2562 IEC_send(0x20);
gertk 1:0cbbb66a6100 2563 IEC_send(0x12);
gertk 1:0cbbb66a6100 2564 IEC_send(0x20);
gertk 1:0cbbb66a6100 2565 IEC_send(0x22);
gertk 1:0cbbb66a6100 2566 IEC_send_string(" CARD DIRECTORY ");
gertk 1:0cbbb66a6100 2567 IEC_send(0x22);
gertk 1:0cbbb66a6100 2568 IEC_send_string(" 00 2A");
gertk 1:0cbbb66a6100 2569 IEC_send(0x00); /*Normal Directory header*/
gertk 1:0cbbb66a6100 2570 IEC_send(0x01);
gertk 1:0cbbb66a6100 2571 IEC_send(0x01);
gertk 1:0cbbb66a6100 2572 IEC_send(0x00);
gertk 1:0cbbb66a6100 2573 IEC_send(0x00);
gertk 1:0cbbb66a6100 2574 IEC_send(0x20);
gertk 1:0cbbb66a6100 2575 IEC_send(0x20);
gertk 1:0cbbb66a6100 2576 IEC_send(0x22);
gertk 1:0cbbb66a6100 2577 IEC_send_string("u````````````````i");
gertk 1:0cbbb66a6100 2578 IEC_send(0x22);
gertk 1:0cbbb66a6100 2579 IEC_send(0x00); /*top-line*/
gertk 1:0cbbb66a6100 2580 IEC_send(0x01);
gertk 1:0cbbb66a6100 2581 IEC_send(0x01);
gertk 1:0cbbb66a6100 2582 IEC_send(0x00);
gertk 1:0cbbb66a6100 2583 IEC_send(0x00);
gertk 1:0cbbb66a6100 2584 IEC_send(0x20);
gertk 1:0cbbb66a6100 2585 IEC_send(0x20);
gertk 1:0cbbb66a6100 2586 IEC_send(0x22);
gertk 1:0cbbb66a6100 2587 IEC_send_string("} 1541-III MBED }");
gertk 1:0cbbb66a6100 2588 IEC_send(0x22);
gertk 1:0cbbb66a6100 2589 IEC_send(0x00); /*model*/
gertk 1:0cbbb66a6100 2590 IEC_send(0x01);
gertk 1:0cbbb66a6100 2591 IEC_send(0x01);
gertk 1:0cbbb66a6100 2592 IEC_send(0x00);
gertk 1:0cbbb66a6100 2593 IEC_send(0x00);
gertk 1:0cbbb66a6100 2594 IEC_send(0x20);
gertk 1:0cbbb66a6100 2595 IEC_send(0x20);
gertk 1:0cbbb66a6100 2596 IEC_send(0x22);
gertk 1:0cbbb66a6100 2597 IEC_send_string("}J.DEROGEE & KGE }");
gertk 1:0cbbb66a6100 2598 IEC_send(0x22);
gertk 1:0cbbb66a6100 2599 IEC_send(0x00); /*credits*/
gertk 1:0cbbb66a6100 2600 IEC_send(0x01);
gertk 1:0cbbb66a6100 2601 IEC_send(0x01);
gertk 1:0cbbb66a6100 2602 IEC_send(0x00);
gertk 1:0cbbb66a6100 2603 IEC_send(0x00);
gertk 1:0cbbb66a6100 2604 IEC_send(0x20);
gertk 1:0cbbb66a6100 2605 IEC_send(0x20);
gertk 1:0cbbb66a6100 2606 IEC_send(0x22);
gertk 1:0cbbb66a6100 2607 IEC_send_string("j````````````````k");
gertk 1:0cbbb66a6100 2608 IEC_send(0x22);
gertk 1:0cbbb66a6100 2609 IEC_send(0x00); /*separation-line*/
gertk 0:28557a4d2215 2610 }
gertk 0:28557a4d2215 2611
gertk 0:28557a4d2215 2612 /*-----------------*/
gertk 0:28557a4d2215 2613 /*directory content*/
gertk 0:28557a4d2215 2614 /*-----------------*/
gertk 0:28557a4d2215 2615
gertk 0:28557a4d2215 2616 pass_counter = 0;
gertk 1:0cbbb66a6100 2617 index_cnt = 0;
gertk 1:0cbbb66a6100 2618 while (pass_counter++ < 3) {
gertk 0:28557a4d2215 2619 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 2620 separation_line = FALSE;
gertk 0:28557a4d2215 2621
gertk 1:0cbbb66a6100 2622 if (FileSearch(&file,0)) {
gertk 1:0cbbb66a6100 2623 do {
gertk 1:0cbbb66a6100 2624 //OutputToRS232(); /*set standard output to RS232*/
gertk 1:0cbbb66a6100 2625 //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 1:0cbbb66a6100 2626 //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 1:0cbbb66a6100 2627 //OutputToLCD(); /*set standard output to LCD*/
gertk 1:0cbbb66a6100 2628
gertk 0:28557a4d2215 2629 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 2630 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 2631 filefilter_result = FileFilter();
gertk 0:28557a4d2215 2632 if ((pass_counter == 1) && (filefilter_result == SUBDIRECTORY) ||
gertk 1:0cbbb66a6100 2633 ((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 1:0cbbb66a6100 2634 ((pass_counter == 3) && ((filefilter_result == PRG_FILE) || (filefilter_result == T64_MODE) || (filefilter_result == UNKNOWN)))) {
gertk 1:0cbbb66a6100 2635 if (separation_line == FALSE) { /*for better readabillity... add a small separation-line (but only if required)*/
gertk 0:28557a4d2215 2636 separation_line = TRUE;
gertk 1:0cbbb66a6100 2637 IEC_send(0x01);
gertk 1:0cbbb66a6100 2638 IEC_send(0x01);
gertk 1:0cbbb66a6100 2639 IEC_send(0x00);
gertk 1:0cbbb66a6100 2640 IEC_send(0x00);
gertk 1:0cbbb66a6100 2641 IEC_send(0x20);
gertk 1:0cbbb66a6100 2642 IEC_send(0x20);
gertk 1:0cbbb66a6100 2643 IEC_send(0x22);
gertk 1:0cbbb66a6100 2644 for (lp=0; lp<(dir_width+1); lp++)
gertk 0:28557a4d2215 2645 IEC_send('`');
gertk 1:0cbbb66a6100 2646 IEC_send(0x22);
gertk 1:0cbbb66a6100 2647 IEC_send(0x00);
gertk 0:28557a4d2215 2648 }
gertk 0:28557a4d2215 2649
gertk 0:28557a4d2215 2650 IEC_send(0x01);
gertk 0:28557a4d2215 2651 IEC_send(0x01);
gertk 0:28557a4d2215 2652
gertk 1:0cbbb66a6100 2653 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 2654 blocksize = file.size / 254; /*calculate blocksize(1 block=254 bytes) from filesize(bytes)*/
gertk 0:28557a4d2215 2655 IEC_send(blocksize%256); /*low-byte of blocksize of file*/
gertk 0:28557a4d2215 2656 IEC_send(blocksize/256); /*high-byte of blocksize of file*/
gertk 1:0cbbb66a6100 2657 if (blocksize < 10) /*if required, add extra space for better allignment*/
gertk 1:0cbbb66a6100 2658 IEC_send(0x20);
gertk 1:0cbbb66a6100 2659
gertk 1:0cbbb66a6100 2660 if (blocksize < 100) /*if required, add extra space for better allignment*/
gertk 1:0cbbb66a6100 2661 IEC_send(0x20);
gertk 1:0cbbb66a6100 2662 } else {
gertk 0:28557a4d2215 2663 IEC_send(0); /*low-byte of blocksize of file*/
gertk 0:28557a4d2215 2664 IEC_send(0); /*high-byte of blocksize of file*/
gertk 1:0cbbb66a6100 2665 IEC_send(0x20);
gertk 1:0cbbb66a6100 2666 IEC_send(0x20);
gertk 0:28557a4d2215 2667 }
gertk 0:28557a4d2215 2668
gertk 0:28557a4d2215 2669 IEC_send(0x22); /*each entry must be starting with the "-sign*/
gertk 0:28557a4d2215 2670 if ((filefilter_result != PRG_FILE) && (filefilter_result != UNKNOWN))
gertk 0:28557a4d2215 2671 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 1:0cbbb66a6100 2672
gertk 1:0cbbb66a6100 2673 if (file.name_lfn[0] == 0) { /*check if this entry has an 8.3-name or LFN-name*/
gertk 0:28557a4d2215 2674 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 2675 lp=7;
gertk 1:0cbbb66a6100 2676 if (((file.name[1]) != ' ') || ((file.name[2]) != ' ') || ((file.name[3]) != ' ') || ((file.name[4]) != ' ') || ((file.name[5]) != ' ') || ((file.name[6]) != ' ') || ((file.name[7]) != ' ')) {
gertk 1:0cbbb66a6100 2677 IEC_send(file.name[1]);
gertk 1:0cbbb66a6100 2678 lp=6;
gertk 1:0cbbb66a6100 2679 }
gertk 1:0cbbb66a6100 2680 if (((file.name[2]) != ' ') || ((file.name[3]) != ' ') || ((file.name[4]) != ' ') || ((file.name[5]) != ' ') || ((file.name[6]) != ' ') || ((file.name[7]) != ' ')) {
gertk 1:0cbbb66a6100 2681 IEC_send(file.name[2]);
gertk 1:0cbbb66a6100 2682 lp=5;
gertk 1:0cbbb66a6100 2683 }
gertk 1:0cbbb66a6100 2684 if (((file.name[3]) != ' ') || ((file.name[4]) != ' ') || ((file.name[5]) != ' ') || ((file.name[6]) != ' ') || ((file.name[7]) != ' ')) {
gertk 1:0cbbb66a6100 2685 IEC_send(file.name[3]);
gertk 1:0cbbb66a6100 2686 lp=4;
gertk 1:0cbbb66a6100 2687 }
gertk 1:0cbbb66a6100 2688 if (((file.name[4]) != ' ') || ((file.name[5]) != ' ') || ((file.name[6]) != ' ') || ((file.name[7]) != ' ')) {
gertk 1:0cbbb66a6100 2689 IEC_send(file.name[4]);
gertk 1:0cbbb66a6100 2690 lp=3;
gertk 1:0cbbb66a6100 2691 }
gertk 1:0cbbb66a6100 2692 if (((file.name[5]) != ' ') || ((file.name[6]) != ' ') || ((file.name[7]) != ' ')) {
gertk 1:0cbbb66a6100 2693 IEC_send(file.name[5]);
gertk 1:0cbbb66a6100 2694 lp=2;
gertk 1:0cbbb66a6100 2695 }
gertk 1:0cbbb66a6100 2696 if (((file.name[6]) != ' ') || ((file.name[7]) != ' ')) {
gertk 1:0cbbb66a6100 2697 IEC_send(file.name[6]);
gertk 1:0cbbb66a6100 2698 lp=1;
gertk 1:0cbbb66a6100 2699 }
gertk 1:0cbbb66a6100 2700 if ((file.name[7]) != ' ') {
gertk 1:0cbbb66a6100 2701 IEC_send(file.name[7]);
gertk 1:0cbbb66a6100 2702 lp=0;
gertk 1:0cbbb66a6100 2703 }
gertk 1:0cbbb66a6100 2704
gertk 0:28557a4d2215 2705 lp = (dir_width - 7) + lp; /*calculate the remaining spaces to fit the VIC20 mode*/
gertk 1:0cbbb66a6100 2706 } else {
gertk 1:0cbbb66a6100 2707 for (lp=0; lp<(dir_width-1); lp++) { /*print the LFN string*/
gertk 0:28557a4d2215 2708 IEC_send(file.name_lfn[lp]);
gertk 1:0cbbb66a6100 2709 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 2710 break;
gertk 0:28557a4d2215 2711
gertk 1:0cbbb66a6100 2712 if (file.name_lfn[lp+1] == 0) /*otherwise on end of string, stop*/
gertk 0:28557a4d2215 2713 break;
gertk 1:0cbbb66a6100 2714 }
gertk 1:0cbbb66a6100 2715
gertk 1:0cbbb66a6100 2716 if (lp==(dir_width-1)) /*check if the filename was displayed partially, if so, then add a *-sign*/
gertk 0:28557a4d2215 2717 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 1:0cbbb66a6100 2718
gertk 0:28557a4d2215 2719 lp = dir_width - lp; /*calculate the remaining number of spaces*/
gertk 0:28557a4d2215 2720 }
gertk 1:0cbbb66a6100 2721
gertk 0:28557a4d2215 2722 IEC_send(0x22); /*each entry must end with the "-sign*/
gertk 0:28557a4d2215 2723 if (filefilter_result == PRG_FILE)
gertk 0:28557a4d2215 2724 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 1:0cbbb66a6100 2725
gertk 1:0cbbb66a6100 2726 while (lp--) /*the remaining location must be filled with spaces*/
gertk 0:28557a4d2215 2727 IEC_send(' ');
gertk 1:0cbbb66a6100 2728
gertk 1:0cbbb66a6100 2729 switch (filefilter_result) {
gertk 1:0cbbb66a6100 2730 case PRG_FILE: {
gertk 0:28557a4d2215 2731 IEC_send('P'); /*print PRG*/
gertk 0:28557a4d2215 2732 IEC_send('R');
gertk 0:28557a4d2215 2733 IEC_send('G');
gertk 0:28557a4d2215 2734 break;
gertk 0:28557a4d2215 2735 }
gertk 0:28557a4d2215 2736
gertk 1:0cbbb66a6100 2737 case D64_35T_MODE:
gertk 1:0cbbb66a6100 2738 ;
gertk 1:0cbbb66a6100 2739 case D64_35T_ER_MODE:
gertk 1:0cbbb66a6100 2740 ;
gertk 1:0cbbb66a6100 2741 case D64_40T_MODE:
gertk 1:0cbbb66a6100 2742 ;
gertk 1:0cbbb66a6100 2743 case D64_40T_ER_MODE: {
gertk 0:28557a4d2215 2744 IEC_send('D'); /*print D64*/
gertk 0:28557a4d2215 2745 IEC_send('6');
gertk 0:28557a4d2215 2746 IEC_send('4');
gertk 0:28557a4d2215 2747 break;
gertk 0:28557a4d2215 2748 }
gertk 0:28557a4d2215 2749
gertk 1:0cbbb66a6100 2750 case T64_MODE: {
gertk 0:28557a4d2215 2751 IEC_send('T'); /*print T64*/
gertk 0:28557a4d2215 2752 IEC_send('6');
gertk 0:28557a4d2215 2753 IEC_send('4');
gertk 0:28557a4d2215 2754 break;
gertk 0:28557a4d2215 2755 }
gertk 0:28557a4d2215 2756
gertk 1:0cbbb66a6100 2757 case SUBDIRECTORY: {
gertk 0:28557a4d2215 2758 IEC_send('D'); /*print DIR*/
gertk 0:28557a4d2215 2759 IEC_send('I');
gertk 0:28557a4d2215 2760 IEC_send('R');
gertk 0:28557a4d2215 2761 break;
gertk 0:28557a4d2215 2762 }
gertk 0:28557a4d2215 2763
gertk 1:0cbbb66a6100 2764 default: {
gertk 0:28557a4d2215 2765 break; /*print nothing*/
gertk 0:28557a4d2215 2766 }
gertk 0:28557a4d2215 2767 }
gertk 1:0cbbb66a6100 2768
gertk 0:28557a4d2215 2769 IEC_send(0x00);
gertk 0:28557a4d2215 2770 }
gertk 1:0cbbb66a6100 2771 } while (FileSearch(&file,1));
gertk 0:28557a4d2215 2772 }
gertk 0:28557a4d2215 2773 }
gertk 0:28557a4d2215 2774
gertk 0:28557a4d2215 2775 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 2776
gertk 0:28557a4d2215 2777 /*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 2778 IEC_send(0x00);
gertk 0:28557a4d2215 2779 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 2780 IEC_send(0x00);
gertk 0:28557a4d2215 2781 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 2782 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 2783 }
gertk 0:28557a4d2215 2784
gertk 0:28557a4d2215 2785
gertk 1:0cbbb66a6100 2786 void D64Directory(void) {
gertk 0:28557a4d2215 2787 unsigned char lp, mode, extra_spaces, track, sector, unused;
gertk 0:28557a4d2215 2788 unsigned int blocksize, blocksfree, read_blocks;
gertk 0:28557a4d2215 2789
gertk 0:28557a4d2215 2790 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 2791 EOI = FALSE;
gertk 0:28557a4d2215 2792 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 2793
gertk 0:28557a4d2215 2794 /*some bytes required for sending a directory entry to a VIC20, C64, C128, etc.*/
gertk 0:28557a4d2215 2795 IEC_send(0x01); /*load this "program" to start address 0x0401*/
gertk 0:28557a4d2215 2796 IEC_send(0x04);
gertk 0:28557a4d2215 2797
gertk 1:0cbbb66a6100 2798 /*Directory header*/
gertk 1:0cbbb66a6100 2799 /*----------------*/
gertk 0:28557a4d2215 2800 D64BlockRead(18,0);
gertk 0:28557a4d2215 2801 read_blocks = 1;
gertk 0:28557a4d2215 2802 print_D64_TSB(18,0,read_blocks, 0);
gertk 0:28557a4d2215 2803 IEC_send(0x01); /*...*/
gertk 0:28557a4d2215 2804 IEC_send(0x01); /*...*/
gertk 0:28557a4d2215 2805 IEC_send(0); /*drive-number of this device, in the beginning of this project used as file pointer/indicator*/
gertk 0:28557a4d2215 2806 IEC_send(0); /*drive-number of this device, in the beginning of this project uses as file pointer/indicator*/
gertk 0:28557a4d2215 2807 IEC_send(0x12); /*RVS-ON (invert characters)*/
gertk 0:28557a4d2215 2808 IEC_send(0x22); /*"-sign*/
gertk 1:0cbbb66a6100 2809 for (lp=144; lp<160; lp++) {
gertk 0:28557a4d2215 2810 IEC_send(RAM_buffer[lp]); /*send the Diskname*/
gertk 0:28557a4d2215 2811 }
gertk 0:28557a4d2215 2812
gertk 0:28557a4d2215 2813 IEC_send(0x22); /*"-sign*/
gertk 0:28557a4d2215 2814 IEC_send(0x20); /*space*/
gertk 0:28557a4d2215 2815 IEC_send(RAM_buffer[162]); /*send the disk-ID byte-0*/
gertk 0:28557a4d2215 2816 IEC_send(RAM_buffer[163]); /*send the disk-ID byte-1*/
gertk 0:28557a4d2215 2817 IEC_send(0x20); /*space*/
gertk 0:28557a4d2215 2818 IEC_send(RAM_buffer[165]); /*send the DOS-version and format-type byte-0*/
gertk 0:28557a4d2215 2819 IEC_send(RAM_buffer[166]); /*send the DOS-version and format-type byte-1*/
gertk 0:28557a4d2215 2820 IEC_send(0x00); /*a byte indicating the end of this "directory-line"*/
gertk 0:28557a4d2215 2821
gertk 1:0cbbb66a6100 2822 /*Directory entry ...*/
gertk 1:0cbbb66a6100 2823 /*-------------------*/
gertk 0:28557a4d2215 2824 mode=0; /*set sector read to first entry*/
gertk 1:0cbbb66a6100 2825 while (D64SeekDirEntry(mode, &track, &sector, &unused)) { /*get directory entry and request the current track and sector*/
gertk 0:28557a4d2215 2826 mode=1; /*set sector read to next entry*/
gertk 0:28557a4d2215 2827 print_D64_TSB(track,sector,read_blocks,0);
gertk 1:0cbbb66a6100 2828 if (dir_entry.filetype != 0x00) { /*scratched files are NOT displayed in the directory*/
gertk 0:28557a4d2215 2829 IEC_send(0x01); /*bytes indicating the beginning of a "directory-line"*/
gertk 0:28557a4d2215 2830 IEC_send(0x01);
gertk 0:28557a4d2215 2831 IEC_send(dir_entry.blocksize_low_byte); /*size of this file low-byte*/
gertk 0:28557a4d2215 2832 IEC_send(dir_entry.blocksize_high_byte); /*size of this file high-byte*/
gertk 0:28557a4d2215 2833 // dir_entry.record_size_relfile = 0x00;
gertk 0:28557a4d2215 2834 blocksize = ((256 * dir_entry.blocksize_high_byte) + dir_entry.blocksize_low_byte);
gertk 0:28557a4d2215 2835 if (blocksize < 10) /*add an extra space(s) to adjust line length*/
gertk 0:28557a4d2215 2836 IEC_send(0x20); /* */
gertk 0:28557a4d2215 2837 if (blocksize < 100) /* */
gertk 0:28557a4d2215 2838 IEC_send(0x20); /* */
gertk 0:28557a4d2215 2839 if (blocksize < 1000) /* */
gertk 0:28557a4d2215 2840 IEC_send(0x20); /* */
gertk 0:28557a4d2215 2841 IEC_send(0x22); /*"-sign*/
gertk 1:0cbbb66a6100 2842
gertk 0:28557a4d2215 2843 extra_spaces = 0;
gertk 1:0cbbb66a6100 2844 for (lp=0; lp<16; lp++) {
gertk 1:0cbbb66a6100 2845 if (dir_entry.filename[lp]== 160)
gertk 0:28557a4d2215 2846 extra_spaces++;
gertk 0:28557a4d2215 2847 else
gertk 0:28557a4d2215 2848 IEC_send(dir_entry.filename[lp]); /*filename of this entrynumber*/
gertk 0:28557a4d2215 2849
gertk 0:28557a4d2215 2850 }
gertk 0:28557a4d2215 2851
gertk 0:28557a4d2215 2852 IEC_send(0x22); /*"-sign*/
gertk 1:0cbbb66a6100 2853 while (extra_spaces != 0) {
gertk 0:28557a4d2215 2854 IEC_send(0x20); /*add some extra spaces for proper allignment*/
gertk 0:28557a4d2215 2855 extra_spaces--;
gertk 0:28557a4d2215 2856 }
gertk 0:28557a4d2215 2857
gertk 0:28557a4d2215 2858 /*filetype*/
gertk 0:28557a4d2215 2859 /*--------*/
gertk 1:0cbbb66a6100 2860 if (dir_entry.filetype > 127) /*when MSB has been set the file has been properly closed*/
gertk 0:28557a4d2215 2861 IEC_send(0x20); /*print a space before the filetype*/
gertk 0:28557a4d2215 2862 else
gertk 0:28557a4d2215 2863 IEC_send(0x2A); /*print a asterix before the filetype to indicate that the file has not been closed (yet)*/
gertk 1:0cbbb66a6100 2864
gertk 1:0cbbb66a6100 2865 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 1:0cbbb66a6100 2866 case 0: {
gertk 0:28557a4d2215 2867 IEC_send(0x44); /*file type = DELeted */
gertk 0:28557a4d2215 2868 IEC_send(0x45);
gertk 0:28557a4d2215 2869 IEC_send(0x4C);
gertk 0:28557a4d2215 2870 break;
gertk 0:28557a4d2215 2871 }
gertk 1:0cbbb66a6100 2872
gertk 1:0cbbb66a6100 2873 case 1: {
gertk 0:28557a4d2215 2874 IEC_send(0x53); /*file type = SEQuential */
gertk 0:28557a4d2215 2875 IEC_send(0x45);
gertk 0:28557a4d2215 2876 IEC_send(0x51);
gertk 0:28557a4d2215 2877 break;
gertk 0:28557a4d2215 2878 }
gertk 1:0cbbb66a6100 2879
gertk 1:0cbbb66a6100 2880 case 2: {
gertk 0:28557a4d2215 2881 IEC_send(0x50); /*file type = PRoGram */
gertk 0:28557a4d2215 2882 IEC_send(0x52);
gertk 0:28557a4d2215 2883 IEC_send(0x47);
gertk 0:28557a4d2215 2884 break;
gertk 0:28557a4d2215 2885 }
gertk 1:0cbbb66a6100 2886
gertk 1:0cbbb66a6100 2887 case 3: {
gertk 0:28557a4d2215 2888 IEC_send(0x55); /*file type = USeR */
gertk 0:28557a4d2215 2889 IEC_send(0x53);
gertk 0:28557a4d2215 2890 IEC_send(0x52);
gertk 0:28557a4d2215 2891 break;
gertk 0:28557a4d2215 2892 }
gertk 1:0cbbb66a6100 2893
gertk 1:0cbbb66a6100 2894
gertk 1:0cbbb66a6100 2895 case 4: {
gertk 0:28557a4d2215 2896 IEC_send(0x52); /*file type = RELative */
gertk 0:28557a4d2215 2897 IEC_send(0x45);
gertk 0:28557a4d2215 2898 IEC_send(0x4C);
gertk 0:28557a4d2215 2899 break;
gertk 0:28557a4d2215 2900 }
gertk 1:0cbbb66a6100 2901
gertk 1:0cbbb66a6100 2902 default: {
gertk 0:28557a4d2215 2903 IEC_send(0x55); /*file type = UNKnown (is only shown if someone uses these values out of spec...*/
gertk 0:28557a4d2215 2904 IEC_send(0x4E);
gertk 0:28557a4d2215 2905 IEC_send(0x4B);
gertk 0:28557a4d2215 2906 break;
gertk 0:28557a4d2215 2907 }
gertk 0:28557a4d2215 2908 }
gertk 1:0cbbb66a6100 2909
gertk 0:28557a4d2215 2910 if (dir_entry.filetype > 191)
gertk 0:28557a4d2215 2911 IEC_send(0x3C); /*print a "<" to indicate a locked file*/
gertk 0:28557a4d2215 2912 else
gertk 0:28557a4d2215 2913 IEC_send(0x20);
gertk 0:28557a4d2215 2914
gertk 0:28557a4d2215 2915 IEC_send(0x20);
gertk 0:28557a4d2215 2916 IEC_send(0x20);
gertk 0:28557a4d2215 2917 IEC_send(0x20);
gertk 0:28557a4d2215 2918 IEC_send(0x00);
gertk 0:28557a4d2215 2919 }
gertk 0:28557a4d2215 2920 }
gertk 0:28557a4d2215 2921
gertk 1:0cbbb66a6100 2922 /*Blocks free "directory-line"*/
gertk 1:0cbbb66a6100 2923 /*----------------------------*/
gertk 0:28557a4d2215 2924 IEC_send(0x01);
gertk 0:28557a4d2215 2925 IEC_send(0x01);
gertk 0:28557a4d2215 2926 blocksfree = D64LoadFreeBlocks(); /*read the number of free blocks from the D64 file*/
gertk 0:28557a4d2215 2927 IEC_send(blocksfree%256); /*low-byte of free blocks value*/
gertk 0:28557a4d2215 2928 IEC_send(blocksfree/256); /*high-byte of free blocks value*/
gertk 0:28557a4d2215 2929 IEC_send_string("BLOCKS FREE. "); /*"Blocks free."*/
gertk 0:28557a4d2215 2930 IEC_send(0x00);
gertk 0:28557a4d2215 2931 IEC_send(0x00);
gertk 0:28557a4d2215 2932 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 2933 IEC_send(0x00);
gertk 0:28557a4d2215 2934 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 2935 SetErrorCode(0, LED_OFF); /*all is OK*/
gertk 0:28557a4d2215 2936 }
gertk 0:28557a4d2215 2937
gertk 1:0cbbb66a6100 2938 void T64Directory(void) {
gertk 0:28557a4d2215 2939 unsigned char lp, mode, extra_spaces, track, sector, unused;
gertk 0:28557a4d2215 2940 unsigned int blocksize, blocksfree, read_blocks;
gertk 0:28557a4d2215 2941
gertk 0:28557a4d2215 2942 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 2943 EOI = FALSE;
gertk 0:28557a4d2215 2944 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 2945
gertk 0:28557a4d2215 2946 /*some bytes required for sending a directory entry to a VIC20, C64, C128, etc.*/
gertk 0:28557a4d2215 2947 IEC_send(0x01); /*load this "program" to start address 0x0401*/
gertk 0:28557a4d2215 2948 IEC_send(0x04);
gertk 0:28557a4d2215 2949
gertk 1:0cbbb66a6100 2950 /*Directory header*/
gertk 1:0cbbb66a6100 2951 /*----------------*/
gertk 0:28557a4d2215 2952 D64BlockRead(18,0);
gertk 0:28557a4d2215 2953 read_blocks = 1;
gertk 0:28557a4d2215 2954 print_D64_TSB(18,0,read_blocks, 0);
gertk 0:28557a4d2215 2955 IEC_send(0x01); /*...*/
gertk 0:28557a4d2215 2956 IEC_send(0x01); /*...*/
gertk 0:28557a4d2215 2957 IEC_send(0); /*drive-number of this device, in the beginning of this project used as file pointer/indicator*/
gertk 0:28557a4d2215 2958 IEC_send(0); /*drive-number of this device, in the beginning of this project uses as file pointer/indicator*/
gertk 0:28557a4d2215 2959 IEC_send(0x12); /*RVS-ON (invert characters)*/
gertk 0:28557a4d2215 2960 IEC_send(0x22); /*"-sign*/
gertk 1:0cbbb66a6100 2961 for (lp=144; lp<160; lp++) {
gertk 0:28557a4d2215 2962 IEC_send(RAM_buffer[lp]); /*send the Diskname*/
gertk 0:28557a4d2215 2963 }
gertk 0:28557a4d2215 2964
gertk 0:28557a4d2215 2965 IEC_send(0x22); /*"-sign*/
gertk 0:28557a4d2215 2966 IEC_send(0x20); /*space*/
gertk 0:28557a4d2215 2967 IEC_send(RAM_buffer[162]); /*send the disk-ID byte-0*/
gertk 0:28557a4d2215 2968 IEC_send(RAM_buffer[163]); /*send the disk-ID byte-1*/
gertk 0:28557a4d2215 2969 IEC_send(0x20); /*space*/
gertk 0:28557a4d2215 2970 IEC_send(RAM_buffer[165]); /*send the DOS-version and format-type byte-0*/
gertk 0:28557a4d2215 2971 IEC_send(RAM_buffer[166]); /*send the DOS-version and format-type byte-1*/
gertk 0:28557a4d2215 2972 IEC_send(0x00); /*a byte indicating the end of this "directory-line"*/
gertk 0:28557a4d2215 2973
gertk 1:0cbbb66a6100 2974 /*Directory entry ...*/
gertk 1:0cbbb66a6100 2975 /*-------------------*/
gertk 0:28557a4d2215 2976 mode=0; /*set sector read to first entry*/
gertk 1:0cbbb66a6100 2977 while (D64SeekDirEntry(mode, &track, &sector, &unused)) { /*get directory entry and request the current track and sector*/
gertk 0:28557a4d2215 2978 mode=1; /*set sector read to next entry*/
gertk 0:28557a4d2215 2979 print_D64_TSB(track,sector,read_blocks,0);
gertk 1:0cbbb66a6100 2980 if (dir_entry.filetype != 0x00) { /*scratched files are NOT displayed in the directory*/
gertk 0:28557a4d2215 2981 IEC_send(0x01); /*bytes indicating the beginning of a "directory-line"*/
gertk 0:28557a4d2215 2982 IEC_send(0x01);
gertk 0:28557a4d2215 2983 IEC_send(dir_entry.blocksize_low_byte); /*size of this file low-byte*/
gertk 0:28557a4d2215 2984 IEC_send(dir_entry.blocksize_high_byte); /*size of this file high-byte*/
gertk 0:28557a4d2215 2985 // dir_entry.record_size_relfile = 0x00;
gertk 0:28557a4d2215 2986 blocksize = ((256 * dir_entry.blocksize_high_byte) + dir_entry.blocksize_low_byte);
gertk 0:28557a4d2215 2987 if (blocksize < 10) /*add an extra space(s) to adjust line length*/
gertk 0:28557a4d2215 2988 IEC_send(0x20); /* */
gertk 0:28557a4d2215 2989 if (blocksize < 100) /* */
gertk 0:28557a4d2215 2990 IEC_send(0x20); /* */
gertk 0:28557a4d2215 2991 if (blocksize < 1000) /* */
gertk 0:28557a4d2215 2992 IEC_send(0x20); /* */
gertk 0:28557a4d2215 2993 IEC_send(0x22); /*"-sign*/
gertk 1:0cbbb66a6100 2994
gertk 0:28557a4d2215 2995 extra_spaces = 0;
gertk 1:0cbbb66a6100 2996 for (lp=0; lp<16; lp++) {
gertk 1:0cbbb66a6100 2997 if (dir_entry.filename[lp]== 160)
gertk 0:28557a4d2215 2998 extra_spaces++;
gertk 0:28557a4d2215 2999 else
gertk 0:28557a4d2215 3000 IEC_send(dir_entry.filename[lp]); /*filename of this entrynumber*/
gertk 0:28557a4d2215 3001
gertk 0:28557a4d2215 3002 }
gertk 0:28557a4d2215 3003
gertk 0:28557a4d2215 3004 IEC_send(0x22); /*"-sign*/
gertk 1:0cbbb66a6100 3005 while (extra_spaces != 0) {
gertk 0:28557a4d2215 3006 IEC_send(0x20); /*add some extra spaces for proper allignment*/
gertk 0:28557a4d2215 3007 extra_spaces--;
gertk 0:28557a4d2215 3008 }
gertk 0:28557a4d2215 3009
gertk 0:28557a4d2215 3010 /*filetype*/
gertk 0:28557a4d2215 3011 /*--------*/
gertk 1:0cbbb66a6100 3012 if (dir_entry.filetype > 127) /*when MSB has been set the file has been properly closed*/
gertk 0:28557a4d2215 3013 IEC_send(0x20); /*print a space before the filetype*/
gertk 0:28557a4d2215 3014 else
gertk 0:28557a4d2215 3015 IEC_send(0x2A); /*print a asterix before the filetype to indicate that the file has not been closed (yet)*/
gertk 1:0cbbb66a6100 3016
gertk 1:0cbbb66a6100 3017 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 1:0cbbb66a6100 3018 case 0: {
gertk 0:28557a4d2215 3019 IEC_send(0x44); /*file type = DELeted */
gertk 0:28557a4d2215 3020 IEC_send(0x45);
gertk 0:28557a4d2215 3021 IEC_send(0x4C);
gertk 0:28557a4d2215 3022 break;
gertk 0:28557a4d2215 3023 }
gertk 1:0cbbb66a6100 3024
gertk 1:0cbbb66a6100 3025 case 1: {
gertk 0:28557a4d2215 3026 IEC_send(0x53); /*file type = SEQuential */
gertk 0:28557a4d2215 3027 IEC_send(0x45);
gertk 0:28557a4d2215 3028 IEC_send(0x51);
gertk 0:28557a4d2215 3029 break;
gertk 0:28557a4d2215 3030 }
gertk 1:0cbbb66a6100 3031
gertk 1:0cbbb66a6100 3032 case 2: {
gertk 0:28557a4d2215 3033 IEC_send(0x50); /*file type = PRoGram */
gertk 0:28557a4d2215 3034 IEC_send(0x52);
gertk 0:28557a4d2215 3035 IEC_send(0x47);
gertk 0:28557a4d2215 3036 break;
gertk 0:28557a4d2215 3037 }
gertk 1:0cbbb66a6100 3038
gertk 1:0cbbb66a6100 3039 case 3: {
gertk 0:28557a4d2215 3040 IEC_send(0x55); /*file type = USeR */
gertk 0:28557a4d2215 3041 IEC_send(0x53);
gertk 0:28557a4d2215 3042 IEC_send(0x52);
gertk 0:28557a4d2215 3043 break;
gertk 0:28557a4d2215 3044 }
gertk 1:0cbbb66a6100 3045
gertk 1:0cbbb66a6100 3046
gertk 1:0cbbb66a6100 3047 case 4: {
gertk 0:28557a4d2215 3048 IEC_send(0x52); /*file type = RELative */
gertk 0:28557a4d2215 3049 IEC_send(0x45);
gertk 0:28557a4d2215 3050 IEC_send(0x4C);
gertk 0:28557a4d2215 3051 break;
gertk 0:28557a4d2215 3052 }
gertk 1:0cbbb66a6100 3053
gertk 1:0cbbb66a6100 3054 default: {
gertk 0:28557a4d2215 3055 IEC_send(0x55); /*file type = UNKnown (is only shown if someone uses these values out of spec...*/
gertk 0:28557a4d2215 3056 IEC_send(0x4E);
gertk 0:28557a4d2215 3057 IEC_send(0x4B);
gertk 0:28557a4d2215 3058 break;
gertk 0:28557a4d2215 3059 }
gertk 0:28557a4d2215 3060 }
gertk 1:0cbbb66a6100 3061
gertk 0:28557a4d2215 3062 if (dir_entry.filetype > 191)
gertk 0:28557a4d2215 3063 IEC_send(0x3C); /*print a "<" to indicate a locked file*/
gertk 0:28557a4d2215 3064 else
gertk 0:28557a4d2215 3065 IEC_send(0x20);
gertk 0:28557a4d2215 3066
gertk 0:28557a4d2215 3067 IEC_send(0x20);
gertk 0:28557a4d2215 3068 IEC_send(0x20);
gertk 0:28557a4d2215 3069 IEC_send(0x20);
gertk 0:28557a4d2215 3070 IEC_send(0x00);
gertk 0:28557a4d2215 3071 }
gertk 0:28557a4d2215 3072 }
gertk 0:28557a4d2215 3073
gertk 1:0cbbb66a6100 3074 /*Blocks free "directory-line"*/
gertk 1:0cbbb66a6100 3075 /*----------------------------*/
gertk 0:28557a4d2215 3076 IEC_send(0x01);
gertk 0:28557a4d2215 3077 IEC_send(0x01);
gertk 0:28557a4d2215 3078 blocksfree = D64LoadFreeBlocks(); /*read the number of free blocks from the D64 file*/
gertk 0:28557a4d2215 3079 IEC_send(blocksfree%256); /*low-byte of free blocks value*/
gertk 0:28557a4d2215 3080 IEC_send(blocksfree/256); /*high-byte of free blocks value*/
gertk 0:28557a4d2215 3081 IEC_send_string("BLOCKS FREE. "); /*"Blocks free."*/
gertk 0:28557a4d2215 3082 IEC_send(0x00);
gertk 0:28557a4d2215 3083 IEC_send(0x00);
gertk 0:28557a4d2215 3084 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 3085 IEC_send(0x00);
gertk 0:28557a4d2215 3086 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 3087 SetErrorCode(0, LED_OFF); /*all is OK*/
gertk 0:28557a4d2215 3088 }
gertk 0:28557a4d2215 3089
gertk 0:28557a4d2215 3090
gertk 0:28557a4d2215 3091 /*this routine will search for a file ON THE CARD that matches the given filename search pattern*/
gertk 0:28557a4d2215 3092 /*the return value (if file is found) will be the index-number of the file as stored on the card*/
gertk 1:0cbbb66a6100 3093 unsigned int SeekFileOnCard(unsigned char *filename, struct file2TYPE *file) {
gertk 0:28557a4d2215 3094 signed char lp;
gertk 0:28557a4d2215 3095 unsigned int index;
gertk 1:0cbbb66a6100 3096
gertk 0:28557a4d2215 3097 index = 0; /*reset the index counter, as we do whish to know what the index of this file (within this (sub)directory) is*/
gertk 1:0cbbb66a6100 3098 if (!FileSearch(file, 0)) /*search for the first file on the card. Attention: screws up secbuf!!*/
gertk 0:28557a4d2215 3099 return(FALSE);
gertk 1:0cbbb66a6100 3100 while (1) {
gertk 0:28557a4d2215 3101 index++;
gertk 1:0cbbb66a6100 3102 lp = -1; /*reset loopcounter*/
gertk 1:0cbbb66a6100 3103 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 1:0cbbb66a6100 3104 if (file->name_lfn[0] == 0) /*check if this entry has an 8.3-name or LFN-name*/
gertk 0:28557a4d2215 3105 { /*this file has no LFN name so we must use the 8.3 information for further searching*/
gertk 1:0cbbb66a6100 3106 do { /*----------------------------------------------------------------------------------*/
gertk 0:28557a4d2215 3107 lp++;
gertk 1:0cbbb66a6100 3108 // OutputToRS232(); /*set standard output to RS232*/
gertk 1:0cbbb66a6100 3109 // printf("\r\n8.3:lp=%02X, %c, %c",lp, file->name[lp], filename[lp]); /*for debug purposes only !!!*/
gertk 1:0cbbb66a6100 3110 // OutputToLCD(); /*set standard output to LCD*/
gertk 1:0cbbb66a6100 3111
gertk 1:0cbbb66a6100 3112 if ((filename[lp] == 0) && (lp==8)) /*when we've succesfully matched all 8 chars of the 8.3 name... we have a match*/
gertk 1:0cbbb66a6100 3113 return(index); /*all the remaining characters of the current file are spaces, we have a match!!!*/
gertk 1:0cbbb66a6100 3114
gertk 1:0cbbb66a6100 3115 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 1:0cbbb66a6100 3116 while (lp<8) {
gertk 0:28557a4d2215 3117 if (file->name[lp] != ' ')
gertk 0:28557a4d2215 3118 break;
gertk 0:28557a4d2215 3119 if (lp==7)
gertk 1:0cbbb66a6100 3120 return(index); /*all the remaining characters of the current file are spaces, we have a match!!!*/
gertk 0:28557a4d2215 3121 lp++;
gertk 0:28557a4d2215 3122 }
gertk 0:28557a4d2215 3123
gertk 1:0cbbb66a6100 3124 if (filename[lp] == 0) /*when the search string has not been ended but the searched filename has... no match*/
gertk 0:28557a4d2215 3125 break; /*we have no match*/
gertk 1:0cbbb66a6100 3126
gertk 0:28557a4d2215 3127 /*wildcard filter*/
gertk 0:28557a4d2215 3128 if (filename[lp] == '?') /*when we encounter an '?', it does not matter what the real char of the filename is*/
gertk 0:28557a4d2215 3129 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 1:0cbbb66a6100 3130
gertk 0:28557a4d2215 3131 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 3132 return(index); /*we have a partial or possible 100% match... but good enough to return with TRUE*/
gertk 1:0cbbb66a6100 3133 } while (file->name[lp] == filename[lp]); /*do the compare of current char of both strings*/
gertk 1:0cbbb66a6100 3134 } else /*this file has an LFN entry, use this for searching*/
gertk 0:28557a4d2215 3135 { /*--------------------------------------------------*/
gertk 1:0cbbb66a6100 3136 do {
gertk 0:28557a4d2215 3137 lp++;
gertk 1:0cbbb66a6100 3138 // OutputToRS232(); /*set standard output to RS232*/
gertk 1:0cbbb66a6100 3139 // printf("\r\nLFN:lp=%02X, %c, %c",lp, file->name_lfn[lp], filename[lp]); /*for debug purposes only !!!*/
gertk 1:0cbbb66a6100 3140 // OutputToLCD(); /*set standard output to LCD*/
gertk 1:0cbbb66a6100 3141
gertk 1:0cbbb66a6100 3142 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 3143 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 3144
gertk 1:0cbbb66a6100 3145 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 3146 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 1:0cbbb66a6100 3147
gertk 1:0cbbb66a6100 3148 if (filename[lp] == 0) /*when the search string has not been ended but the searched filename has... no match*/
gertk 0:28557a4d2215 3149 break; /*we have no match*/
gertk 1:0cbbb66a6100 3150
gertk 0:28557a4d2215 3151 /*wildcard filter*/
gertk 0:28557a4d2215 3152 if (filename[lp] == '?') /*when we encounter an '?', it does not matter what the real char of the filename is*/
gertk 0:28557a4d2215 3153 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 1:0cbbb66a6100 3154
gertk 0:28557a4d2215 3155 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 3156 return(index); /*we have a partial or possible 100% match... but good enough to return with TRUE*/
gertk 1:0cbbb66a6100 3157 } while (file->name_lfn[lp] == filename[lp]); /*do the compare of current char of both strings*/
gertk 0:28557a4d2215 3158 }
gertk 0:28557a4d2215 3159 }
gertk 0:28557a4d2215 3160 if (!FileSearch(file, 1)) /*search for the next file on the card. Attention: screws up secbuf!!*/
gertk 0:28557a4d2215 3161 break;
gertk 0:28557a4d2215 3162 }
gertk 0:28557a4d2215 3163 return(FALSE);
gertk 0:28557a4d2215 3164 }
gertk 0:28557a4d2215 3165
gertk 0:28557a4d2215 3166 /*this routine will load the file indicated by the given struct*/
gertk 1:0cbbb66a6100 3167 void LoadFileFromCard(struct file2TYPE *file) {
gertk 0:28557a4d2215 3168 unsigned char bytecount;
gertk 0:28557a4d2215 3169 unsigned int lp, blocksrem, filesizeinblocks;
gertk 0:28557a4d2215 3170 unsigned long remainingbytecounter;
gertk 0:28557a4d2215 3171
gertk 0:28557a4d2215 3172 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3173 EOI = FALSE;
gertk 0:28557a4d2215 3174 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 3175 remainingbytecounter = file->size;
gertk 0:28557a4d2215 3176 lp = 0;
gertk 0:28557a4d2215 3177 bytecount = 0;
gertk 0:28557a4d2215 3178
gertk 0:28557a4d2215 3179 /*calculate the blocksize of this file*/
gertk 0:28557a4d2215 3180 blocksrem = remainingbytecounter / 254;
gertk 0:28557a4d2215 3181 filesizeinblocks = blocksrem;
gertk 0:28557a4d2215 3182 if ((remainingbytecounter % 254) > 0)
gertk 0:28557a4d2215 3183 blocksrem++;
gertk 0:28557a4d2215 3184 blocksrem--; /*decrement by one, otherwise the countdown will stop at 1, and it must (offcourse) stop at 0*/
gertk 1:0cbbb66a6100 3185
gertk 0:28557a4d2215 3186 FileReadSector(file); /*read the first sector from the card (this is NOT a D64 sector) and contains MORE then 256 bytes*/
gertk 1:0cbbb66a6100 3187 while (remainingbytecounter != 0) {
gertk 0:28557a4d2215 3188 if (bytecount == 0)
gertk 0:28557a4d2215 3189 SetErrorCode(0,LED_ON); /*turn LED on, to create a small blink at every block*/
gertk 0:28557a4d2215 3190 if (bytecount == Blink_block)
gertk 0:28557a4d2215 3191 SetErrorCode(0,LED_OFF); /*turn LED off, to create a small blink at every block*/
gertk 0:28557a4d2215 3192
gertk 1:0cbbb66a6100 3193 if (remainingbytecounter == 1) { /*check for last byte*/
gertk 0:28557a4d2215 3194 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 3195 }
gertk 0:28557a4d2215 3196
gertk 0:28557a4d2215 3197 IEC_send(block_buffer[lp]);
gertk 0:28557a4d2215 3198 remainingbytecounter--;
gertk 0:28557a4d2215 3199 bytecount++;
gertk 0:28557a4d2215 3200 lp++;
gertk 0:28557a4d2215 3201
gertk 1:0cbbb66a6100 3202 if (lp == 512) {
gertk 0:28557a4d2215 3203 FileNextSector(file); /*we must set file pointer to the next sector before we can read the next sector*/
gertk 0:28557a4d2215 3204 FileReadSector(file); /*its time to read another sector*/
gertk 0:28557a4d2215 3205 lp = 0;
gertk 0:28557a4d2215 3206 }
gertk 0:28557a4d2215 3207
gertk 1:0cbbb66a6100 3208 if (bytecount == 254) {
gertk 0:28557a4d2215 3209 blocksrem--; /*another block has been send... update counter*/
gertk 0:28557a4d2215 3210 print_D64_TSB(0, 0, blocksrem, filesizeinblocks); /*print track, sector and remaining blocks*/
gertk 0:28557a4d2215 3211 bytecount = 0;
gertk 0:28557a4d2215 3212 }
gertk 0:28557a4d2215 3213 }
gertk 0:28557a4d2215 3214
gertk 0:28557a4d2215 3215 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 3216 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 3217 }
gertk 0:28557a4d2215 3218
gertk 1:0cbbb66a6100 3219 void LoadD64File(unsigned char trk, unsigned char sec, unsigned int filesizeinblocks) {
gertk 0:28557a4d2215 3220 unsigned char lp;
gertk 0:28557a4d2215 3221 unsigned int blocksrem;
gertk 0:28557a4d2215 3222 unsigned char lasttrack, lastsector;
gertk 0:28557a4d2215 3223
gertk 0:28557a4d2215 3224 blocksrem = filesizeinblocks;
gertk 0:28557a4d2215 3225 EOI = FALSE;
gertk 0:28557a4d2215 3226 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 3227
gertk 1:0cbbb66a6100 3228 while (1) {
gertk 0:28557a4d2215 3229 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3230 print_D64_TSB(trk, sec, blocksrem, filesizeinblocks); /*print track, sector and remaining blocks*/
gertk 0:28557a4d2215 3231 lasttrack = trk; /*keep extra buffer to remember what the last track was*/
gertk 0:28557a4d2215 3232 lastsector = sec; /*keep extra buffer to remember what the last sector was*/
gertk 1:0cbbb66a6100 3233 D64LoadFile_X_Bytes(&file,trk,sec,0,256); /*location of block to load and its size in bytes*/
gertk 0:28557a4d2215 3234 trk = block_buffer[0]; /*track position of the next block*/
gertk 0:28557a4d2215 3235 sec = block_buffer[1]; /*sector position of the next block*/
gertk 0:28557a4d2215 3236 blocksrem--; /*decrement remaining blocks counter*/
gertk 0:28557a4d2215 3237
gertk 1:0cbbb66a6100 3238 if (trk != 0) { /*check on last block*/
gertk 1:0cbbb66a6100 3239 for (lp=2; lp!=0; lp++) {
gertk 1:0cbbb66a6100 3240 IEC_send(block_buffer[lp]); /*transmit the 254 bytes within this block to the listener*/
gertk 1:0cbbb66a6100 3241 if (lp == Blink_block)
gertk 1:0cbbb66a6100 3242 SetErrorCode(0,LED_OFF); /*turn LED off, to create a small blink at every block*/
gertk 0:28557a4d2215 3243 }
gertk 1:0cbbb66a6100 3244 } else { /*transmission of data of the last block*/
gertk 0:28557a4d2215 3245 print_D64_TSB(lasttrack, lastsector, blocksrem, filesizeinblocks); /*print track, sector of the last block*/
gertk 1:0cbbb66a6100 3246 for (lp=2; lp<(sec); lp++) /*transfer the remainder of the loaded last block*/
gertk 0:28557a4d2215 3247 IEC_send(block_buffer[lp]);
gertk 0:28557a4d2215 3248 break;
gertk 0:28557a4d2215 3249 }
gertk 0:28557a4d2215 3250 }
gertk 0:28557a4d2215 3251 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 3252 IEC_send(block_buffer[sec]); /*the position of the last byte is indicated by the value in register 'Sector'*/
gertk 0:28557a4d2215 3253 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 3254 SetErrorCode(0,LED_OFF); /*all is OK*/
gertk 0:28557a4d2215 3255 }
gertk 0:28557a4d2215 3256
gertk 1:0cbbb66a6100 3257 /*Save the file to the D64, this requires the complete DOS handling !!!, since the CBM does not send*/
gertk 1:0cbbb66a6100 3258 /*the filesize, the exact filesize is only known when the file has allready been written. This is too*/
gertk 0:28557a4d2215 3259 /*late to update the progressbar on the LCD, so that's why this bar does not behave as expected*/
gertk 1:0cbbb66a6100 3260 unsigned char SaveD64File(void) {
gertk 0:28557a4d2215 3261 unsigned char lp, fbpt, firsttrack, firstsector, bytecounter;
gertk 0:28557a4d2215 3262 unsigned char track, sector, nexttrack, nextsector;
gertk 0:28557a4d2215 3263 unsigned int blocksize;
gertk 0:28557a4d2215 3264
gertk 0:28557a4d2215 3265 blocksize = 0;
gertk 0:28557a4d2215 3266
gertk 0:28557a4d2215 3267 /*search for the first block location of the file to be saved*/
gertk 1:0cbbb66a6100 3268 if (!D64SeekFreeBlock(&track, &sector)) {
gertk 0:28557a4d2215 3269 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3270 return(FALSE);
gertk 0:28557a4d2215 3271 }
gertk 0:28557a4d2215 3272
gertk 0:28557a4d2215 3273 firsttrack = track;
gertk 0:28557a4d2215 3274 firstsector = sector;
gertk 0:28557a4d2215 3275 nexttrack = track; /*update the track variable*/
gertk 0:28557a4d2215 3276 nextsector = sector; /*update the track variable*/
gertk 0:28557a4d2215 3277 EOI = 0;
gertk 1:0cbbb66a6100 3278 while (EOI == 0) {
gertk 0:28557a4d2215 3279 blocksize++; /*increment blocksize counter*/
gertk 0:28557a4d2215 3280 track = nexttrack; /*update the track variable*/
gertk 0:28557a4d2215 3281 sector = nextsector; /*update the track variable*/
gertk 1:0cbbb66a6100 3282 if (!D64BlockAllocate(track, sector)) { /*claim the next block, update the BAM*/
gertk 1:0cbbb66a6100 3283 SetErrorCode(71,LED_ERROR); /*error: BAM is corrupt a flag has allready been cleared*/
gertk 0:28557a4d2215 3284 return(FALSE); /*somebody or somthing has been messing with the BAM*/
gertk 0:28557a4d2215 3285 }
gertk 0:28557a4d2215 3286 fbpt = D64ReadFreeBlocksPerTrack(track) - 1; /*decrement counter*/
gertk 0:28557a4d2215 3287 D64WriteFreeBlocksPerTrack(track, fbpt); /*save new value to BAM*/
gertk 1:0cbbb66a6100 3288 if (!D64SeekFreeBlock(&nexttrack, &nextsector)) { /*search for the next block location of the file to be saved*/
gertk 0:28557a4d2215 3289 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3290 return(FALSE);
gertk 0:28557a4d2215 3291 }
gertk 0:28557a4d2215 3292 /*the first two bytes of each block consist the 'track' and 'sector' of the next block*/
gertk 0:28557a4d2215 3293 RAM_buffer[0] = nexttrack; /*track of next block*/
gertk 0:28557a4d2215 3294 RAM_buffer[1] = nextsector; /*sector of next block*/
gertk 1:0cbbb66a6100 3295
gertk 0:28557a4d2215 3296 /*collect enough bytes to fill a block*/
gertk 0:28557a4d2215 3297 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 1:0cbbb66a6100 3298 for (lp=2; lp!=0; lp++) {
gertk 0:28557a4d2215 3299 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3300 RAM_buffer[lp] = IEC_receive(TRUE); /*receive a byte and acknowledge with a frame handshake*/
gertk 0:28557a4d2215 3301 bytecounter++;
gertk 0:28557a4d2215 3302 // OutputToRS232(); /*set standard output to RS232*/
gertk 0:28557a4d2215 3303 // printf(",%02x", RAM_buffer[lp]); /*dump all received bytes to serial port*/
gertk 0:28557a4d2215 3304 // OutputToLCD(); /*set standard output to LCD*/
gertk 1:0cbbb66a6100 3305 if (EOI == 1) {
gertk 0:28557a4d2215 3306 RAM_buffer[0] = 0; /*there is no next block so the track value is an impossible one*/
gertk 1:0cbbb66a6100 3307 RAM_buffer[1] = bytecounter; /*there is no next block so the sector value is the position of the last byte*/
gertk 1:0cbbb66a6100 3308 do {
gertk 0:28557a4d2215 3309 RAM_buffer[bytecounter] = 0x00; /*fill the remaining area with 0x00*/
gertk 0:28557a4d2215 3310 bytecounter++;
gertk 1:0cbbb66a6100 3311 } while (bytecounter!=0);
gertk 0:28557a4d2215 3312 break;
gertk 0:28557a4d2215 3313 }
gertk 0:28557a4d2215 3314
gertk 0:28557a4d2215 3315 if (lp == Blink_block)
gertk 0:28557a4d2215 3316 SetErrorCode(0,LED_OFF); /*turn LED off, to create a small blink at every block*/
gertk 0:28557a4d2215 3317 }
gertk 1:0cbbb66a6100 3318
gertk 0:28557a4d2215 3319 print_D64_TSB(track, sector, 0,blocksize); /*print track, sector, remaining blocks and total number of blocks*/
gertk 0:28557a4d2215 3320 D64BlockWrite(track, sector); /*write the block to D64*/
gertk 0:28557a4d2215 3321 }
gertk 0:28557a4d2215 3322
gertk 0:28557a4d2215 3323 /*write the filename to the directory*/
gertk 1:0cbbb66a6100 3324 if (!D64AddDirEntry(0x82,firsttrack,firstsector,command_string,blocksize,0,0,0,0,0)) {
gertk 0:28557a4d2215 3325 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3326 print_D64_TSB(track, sector, blocksize, blocksize); /*print track, sector and remaining blocks and a fully filled bar*/
gertk 0:28557a4d2215 3327 return(FALSE);
gertk 0:28557a4d2215 3328 }
gertk 0:28557a4d2215 3329
gertk 0:28557a4d2215 3330 SetErrorCode(0,LED_OFF); /*all is OK*/
gertk 0:28557a4d2215 3331 print_D64_TSB(track, sector, 0, blocksize); /*print track, sector, remaining blocks creating a fully filled bar*/
gertk 0:28557a4d2215 3332 return(TRUE);
gertk 0:28557a4d2215 3333 }
gertk 0:28557a4d2215 3334
gertk 1:0cbbb66a6100 3335 /*Copy a file within the D64, this requires the complete DOS handling !!!*/
gertk 0:28557a4d2215 3336 /*the filename is stored in command_string*/
gertk 1:0cbbb66a6100 3337 unsigned char CopyD64File(unsigned char trk, unsigned char sec, unsigned int filesizeinblocks) {
gertk 0:28557a4d2215 3338 unsigned int blocksrem;
gertk 0:28557a4d2215 3339 unsigned char fbpt, track, sector, nexttrack, nextsector;
gertk 0:28557a4d2215 3340
gertk 0:28557a4d2215 3341 blocksrem = filesizeinblocks;
gertk 0:28557a4d2215 3342 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3343
gertk 0:28557a4d2215 3344 /*search for the first block location of the new file to be saved*/
gertk 1:0cbbb66a6100 3345 if (!D64SeekFreeBlock(&track, &sector)) {
gertk 0:28557a4d2215 3346 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3347 return(FALSE);
gertk 0:28557a4d2215 3348 }
gertk 0:28557a4d2215 3349
gertk 0:28557a4d2215 3350 /*check if there is enough room free on the disk for the required copy*/
gertk 1:0cbbb66a6100 3351 if (filesizeinblocks > D64LoadFreeBlocks()) { /*read the number of free blocks from the D64 file*/
gertk 0:28557a4d2215 3352 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3353 return(FALSE);
gertk 0:28557a4d2215 3354 }
gertk 0:28557a4d2215 3355
gertk 0:28557a4d2215 3356 /*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 3357 /*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 3358 D64AddDirEntry(0x82,track,sector,filename_string,filesizeinblocks,0,0,0,0,0);
gertk 0:28557a4d2215 3359
gertk 1:0cbbb66a6100 3360 while (blocksrem--) {
gertk 1:0cbbb66a6100 3361 if (!D64BlockAllocate(track, sector)) { /*claim the next block, update the BAM*/
gertk 1:0cbbb66a6100 3362 SetErrorCode(71,LED_ERROR); /*error: BAM is corrupt a flag has allready been cleared*/
gertk 0:28557a4d2215 3363 return(FALSE); /*somebody or somthing has been messing with the BAM*/
gertk 0:28557a4d2215 3364 }
gertk 0:28557a4d2215 3365 fbpt = D64ReadFreeBlocksPerTrack(track) - 1; /*decrement counter*/
gertk 0:28557a4d2215 3366 D64WriteFreeBlocksPerTrack(track, fbpt); /*save new value to BAM*/
gertk 0:28557a4d2215 3367
gertk 0:28557a4d2215 3368 /*search for the first block location of the new file to be saved*/
gertk 1:0cbbb66a6100 3369 if (!D64SeekFreeBlock(&nexttrack, &nextsector)) {
gertk 0:28557a4d2215 3370 SetErrorCode(72,LED_ERROR); /*error: disk or directory full*/
gertk 0:28557a4d2215 3371 return(FALSE);
gertk 0:28557a4d2215 3372 }
gertk 0:28557a4d2215 3373 print_D64_TSB(trk, sec, blocksrem, filesizeinblocks); /*print track, sector and remaining blocks*/
gertk 0:28557a4d2215 3374 D64BlockRead(trk,sec); /*this routine reads a block of a req. track-sector of a D64 into the RAM_buffer*/
gertk 0:28557a4d2215 3375 trk = RAM_buffer[0]; /*the next track to be read*/
gertk 0:28557a4d2215 3376 sec = RAM_buffer[1]; /*the next sector within that track*/
gertk 0:28557a4d2215 3377 RAM_buffer[0] = nexttrack; /*track of next block*/
gertk 1:0cbbb66a6100 3378 RAM_buffer[1] = nextsector; /*sector of next block*/
gertk 0:28557a4d2215 3379 D64BlockWrite(track, sector); /*this routine write the contents of the RAM_buffer to the req. track-sector of the D64 file*/
gertk 0:28557a4d2215 3380
gertk 0:28557a4d2215 3381 track = nexttrack; /*for the next block, set the correct next track and sector*/
gertk 0:28557a4d2215 3382 sector = nextsector;
gertk 0:28557a4d2215 3383 }
gertk 1:0cbbb66a6100 3384
gertk 0:28557a4d2215 3385 /*write last block of the file*/
gertk 0:28557a4d2215 3386 print_D64_TSB(trk, sec, blocksrem, filesizeinblocks); /*print track, sector and remaining blocks*/
gertk 0:28557a4d2215 3387 D64BlockRead(trk,sec); /*this routine reads a block of a req. track-sector of a D64 into the RAM_buffer*/
gertk 0:28557a4d2215 3388 D64BlockWrite(track, sector); /*this routine write the contents of the RAM_buffer to the req. track-sector of the D64 file*/
gertk 0:28557a4d2215 3389 SetErrorCode(0,LED_OFF); /*all is OK*/
gertk 0:28557a4d2215 3390 return(TRUE);
gertk 0:28557a4d2215 3391 }
gertk 0:28557a4d2215 3392
gertk 0:28557a4d2215 3393
gertk 0:28557a4d2215 3394 /*this routine clears the entire block_buffer*/
gertk 1:0cbbb66a6100 3395 void Clear_block_buffer(void) {
gertk 0:28557a4d2215 3396 unsigned int lp;
gertk 0:28557a4d2215 3397
gertk 0:28557a4d2215 3398 lp=0;
gertk 1:0cbbb66a6100 3399 do {
gertk 0:28557a4d2215 3400 block_buffer[lp] = 0x00;
gertk 0:28557a4d2215 3401 lp++;
gertk 1:0cbbb66a6100 3402 } while (lp<512);
gertk 0:28557a4d2215 3403 }
gertk 1:0cbbb66a6100 3404
gertk 0:28557a4d2215 3405 /*this routine formats the currently selected D64 image so it can be used to save your programs/data to*/
gertk 0:28557a4d2215 3406 /*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 3407 /*Attention: this command does not implement the user options (disk label,disk ID). This command is for firmware & media testing purposes only*/
gertk 1:0cbbb66a6100 3408 void FormatD64File(unsigned char *diskname, unsigned char *diskid) { /* '*filename' is actually the complete command_string as given by the user, this referencename is misleading and needs to be changed*/
gertk 0:28557a4d2215 3409
gertk 0:28557a4d2215 3410 unsigned int block_counter=0;
gertk 0:28557a4d2215 3411 unsigned char lp,lp2,tr,se;
gertk 0:28557a4d2215 3412
gertk 0:28557a4d2215 3413 SetErrorCode(0,LED_ON); /*unless we fail we will exit with no error*/
gertk 0:28557a4d2215 3414 print_D64_TSB(0,0,(341-block_counter),341);
gertk 0:28557a4d2215 3415
gertk 0:28557a4d2215 3416 /*fill track 1 upto and including track 17 (all 21) sectors with 0x00*/
gertk 0:28557a4d2215 3417 /*each MMC/SD-card block = 512 bytes, each D64 block = 256 bytes */
gertk 0:28557a4d2215 3418 /*17 tracks * 21 sectors = 357 D64 blocks or 178.5 MMC/SD-card blocks*/
gertk 0:28557a4d2215 3419 Clear_block_buffer(); /*clear the block_buffer*/
gertk 1:0cbbb66a6100 3420 do {
gertk 0:28557a4d2215 3421 D64ConvertBlockToTrackSector((block_counter<<1), &tr, &se);
gertk 0:28557a4d2215 3422 print_D64_TSB(tr,se,(341-block_counter),341);
gertk 1:0cbbb66a6100 3423 FileWriteSector_X(&file, block_counter);
gertk 0:28557a4d2215 3424 block_counter++;
gertk 1:0cbbb66a6100 3425 } while (block_counter < 178);
gertk 0:28557a4d2215 3426
gertk 0:28557a4d2215 3427 block_buffer[256+0] = 18; /*track of next block*/
gertk 0:28557a4d2215 3428 block_buffer[256+1] = 18; /*sector of next block*/
gertk 0:28557a4d2215 3429 block_buffer[256+2] = 65;
gertk 0:28557a4d2215 3430 block_buffer[256+3] = 0;
gertk 0:28557a4d2215 3431 block_buffer[256+4] = 0x15; /*number of sectors within track-1*/
gertk 0:28557a4d2215 3432 block_buffer[256+5] = 0xff;
gertk 0:28557a4d2215 3433 block_buffer[256+6] = 0xff;
gertk 0:28557a4d2215 3434 block_buffer[256+7] = 0x1f;
gertk 0:28557a4d2215 3435 block_buffer[256+8] = 0x15; /*number of sectors within track-2*/
gertk 0:28557a4d2215 3436 block_buffer[256+9] = 0xff;
gertk 0:28557a4d2215 3437 block_buffer[256+10] = 0xff;
gertk 0:28557a4d2215 3438 block_buffer[256+11] = 0x1f;
gertk 0:28557a4d2215 3439 block_buffer[256+12] = 0x15; /*number of sectors within track-3*/
gertk 0:28557a4d2215 3440 block_buffer[256+13] = 0xff;
gertk 0:28557a4d2215 3441 block_buffer[256+14] = 0xff;
gertk 0:28557a4d2215 3442 block_buffer[256+15] = 0x1f;
gertk 0:28557a4d2215 3443 block_buffer[256+16] = 0x15; /*number of sectors within track-4*/
gertk 0:28557a4d2215 3444 block_buffer[256+17] = 0xff;
gertk 0:28557a4d2215 3445 block_buffer[256+18] = 0xff;
gertk 0:28557a4d2215 3446 block_buffer[256+19] = 0x1f;
gertk 0:28557a4d2215 3447 block_buffer[256+20] = 0x15; /*number of sectors within track-5*/
gertk 0:28557a4d2215 3448 block_buffer[256+21] = 0xff;
gertk 0:28557a4d2215 3449 block_buffer[256+22] = 0xff;
gertk 0:28557a4d2215 3450 block_buffer[256+23] = 0x1f;
gertk 0:28557a4d2215 3451 block_buffer[256+24] = 0x15; /*number of sectors within track-6*/
gertk 0:28557a4d2215 3452 block_buffer[256+25] = 0xff;
gertk 0:28557a4d2215 3453 block_buffer[256+26] = 0xff;
gertk 0:28557a4d2215 3454 block_buffer[256+27] = 0x1f;
gertk 0:28557a4d2215 3455 block_buffer[256+28] = 0x15; /*number of sectors within track-7*/
gertk 0:28557a4d2215 3456 block_buffer[256+29] = 0xff;
gertk 0:28557a4d2215 3457 block_buffer[256+30] = 0xff;
gertk 0:28557a4d2215 3458 block_buffer[256+31] = 0x1f;
gertk 0:28557a4d2215 3459 block_buffer[256+32] = 0x15; /*number of sectors within track-8*/
gertk 0:28557a4d2215 3460 block_buffer[256+33] = 0xff;
gertk 0:28557a4d2215 3461 block_buffer[256+34] = 0xff;
gertk 0:28557a4d2215 3462 block_buffer[256+35] = 0x1f;
gertk 0:28557a4d2215 3463 block_buffer[256+36] = 0x15; /*number of sectors within track-9*/
gertk 0:28557a4d2215 3464 block_buffer[256+37] = 0xff;
gertk 0:28557a4d2215 3465 block_buffer[256+38] = 0xff;
gertk 0:28557a4d2215 3466 block_buffer[256+39] = 0x1f;
gertk 0:28557a4d2215 3467 block_buffer[256+40] = 0x15; /*number of sectors within track-10*/
gertk 0:28557a4d2215 3468 block_buffer[256+41] = 0xff;
gertk 0:28557a4d2215 3469 block_buffer[256+42] = 0xff;
gertk 0:28557a4d2215 3470 block_buffer[256+43] = 0x1f;
gertk 0:28557a4d2215 3471 block_buffer[256+44] = 0x15; /*number of sectors within track-11*/
gertk 0:28557a4d2215 3472 block_buffer[256+45] = 0xff;
gertk 0:28557a4d2215 3473 block_buffer[256+46] = 0xff;
gertk 0:28557a4d2215 3474 block_buffer[256+47] = 0x1f;
gertk 0:28557a4d2215 3475 block_buffer[256+48] = 0x15; /*number of sectors within track-12*/
gertk 0:28557a4d2215 3476 block_buffer[256+49] = 0xff;
gertk 0:28557a4d2215 3477 block_buffer[256+50] = 0xff;
gertk 0:28557a4d2215 3478 block_buffer[256+51] = 0x1f;
gertk 0:28557a4d2215 3479 block_buffer[256+52] = 0x15; /*number of sectors within track-13*/
gertk 0:28557a4d2215 3480 block_buffer[256+53] = 0xff;
gertk 0:28557a4d2215 3481 block_buffer[256+54] = 0xff;
gertk 0:28557a4d2215 3482 block_buffer[256+55] = 0x1f;
gertk 0:28557a4d2215 3483 block_buffer[256+56] = 0x15; /*number of sectors within track-14*/
gertk 0:28557a4d2215 3484 block_buffer[256+57] = 0xff;
gertk 0:28557a4d2215 3485 block_buffer[256+58] = 0xff;
gertk 0:28557a4d2215 3486 block_buffer[256+59] = 0x1f;
gertk 0:28557a4d2215 3487 block_buffer[256+60] = 0x15; /*number of sectors within track-15*/
gertk 0:28557a4d2215 3488 block_buffer[256+61] = 0xff;
gertk 0:28557a4d2215 3489 block_buffer[256+62] = 0xff;
gertk 0:28557a4d2215 3490 block_buffer[256+63] = 0x1f;
gertk 0:28557a4d2215 3491 block_buffer[256+64] = 0x15; /*number of sectors within track-16*/
gertk 0:28557a4d2215 3492 block_buffer[256+65] = 0xff;
gertk 0:28557a4d2215 3493 block_buffer[256+66] = 0xff;
gertk 0:28557a4d2215 3494 block_buffer[256+67] = 0x1f;
gertk 0:28557a4d2215 3495 block_buffer[256+68] = 0x15; /*number of sectors within track-17*/
gertk 0:28557a4d2215 3496 block_buffer[256+69] = 0xff;
gertk 0:28557a4d2215 3497 block_buffer[256+70] = 0xff;
gertk 0:28557a4d2215 3498 block_buffer[256+71] = 0x1f;
gertk 0:28557a4d2215 3499 block_buffer[256+72] = 0x11; /*number of sectors within track-18*/
gertk 0:28557a4d2215 3500 block_buffer[256+73] = 0xfc;
gertk 0:28557a4d2215 3501 block_buffer[256+74] = 0xff;
gertk 0:28557a4d2215 3502 block_buffer[256+75] = 0x07;
gertk 0:28557a4d2215 3503 block_buffer[256+76] = 0x13; /*number of sectors within track-19*/
gertk 0:28557a4d2215 3504 block_buffer[256+77] = 0xff;
gertk 0:28557a4d2215 3505 block_buffer[256+78] = 0xff;
gertk 0:28557a4d2215 3506 block_buffer[256+79] = 0x07;
gertk 0:28557a4d2215 3507 block_buffer[256+80] = 0x13; /*number of sectors within track-20*/
gertk 0:28557a4d2215 3508 block_buffer[256+81] = 0xff;
gertk 0:28557a4d2215 3509 block_buffer[256+82] = 0xff;
gertk 0:28557a4d2215 3510 block_buffer[256+83] = 0x07;
gertk 0:28557a4d2215 3511 block_buffer[256+84] = 0x13; /*number of sectors within track-21*/
gertk 0:28557a4d2215 3512 block_buffer[256+85] = 0xff;
gertk 0:28557a4d2215 3513 block_buffer[256+86] = 0xff;
gertk 0:28557a4d2215 3514 block_buffer[256+87] = 0x07;
gertk 0:28557a4d2215 3515 block_buffer[256+88] = 0x13; /*number of sectors within track-22*/
gertk 0:28557a4d2215 3516 block_buffer[256+89] = 0xff;
gertk 0:28557a4d2215 3517 block_buffer[256+90] = 0xff;
gertk 0:28557a4d2215 3518 block_buffer[256+91] = 0x07;
gertk 0:28557a4d2215 3519 block_buffer[256+92] = 0x13; /*number of sectors within track-23*/
gertk 0:28557a4d2215 3520 block_buffer[256+93] = 0xff;
gertk 0:28557a4d2215 3521 block_buffer[256+94] = 0xff;
gertk 0:28557a4d2215 3522 block_buffer[256+95] = 0x07;
gertk 0:28557a4d2215 3523 block_buffer[256+96] = 0x13; /*number of sectors within track-24*/
gertk 0:28557a4d2215 3524 block_buffer[256+97] = 0xff;
gertk 0:28557a4d2215 3525 block_buffer[256+98] = 0xff;
gertk 0:28557a4d2215 3526 block_buffer[256+99] = 0x07;
gertk 0:28557a4d2215 3527 block_buffer[256+100] = 0x12; /*number of sectors within track-25*/
gertk 0:28557a4d2215 3528 block_buffer[256+101] = 0xff;
gertk 0:28557a4d2215 3529 block_buffer[256+102] = 0xff;
gertk 0:28557a4d2215 3530 block_buffer[256+103] = 0x03;
gertk 0:28557a4d2215 3531 block_buffer[256+104] = 0x12; /*number of sectors within track-26*/
gertk 0:28557a4d2215 3532 block_buffer[256+105] = 0xff;
gertk 0:28557a4d2215 3533 block_buffer[256+106] = 0xff;
gertk 0:28557a4d2215 3534 block_buffer[256+107] = 0x03;
gertk 0:28557a4d2215 3535 block_buffer[256+108] = 0x12; /*number of sectors within track-27*/
gertk 0:28557a4d2215 3536 block_buffer[256+109] = 0xff;
gertk 0:28557a4d2215 3537 block_buffer[256+110] = 0xff;
gertk 0:28557a4d2215 3538 block_buffer[256+111] = 0x03;
gertk 0:28557a4d2215 3539 block_buffer[256+112] = 0x12; /*number of sectors within track-28*/
gertk 0:28557a4d2215 3540 block_buffer[256+113] = 0xff;
gertk 0:28557a4d2215 3541 block_buffer[256+114] = 0xff;
gertk 0:28557a4d2215 3542 block_buffer[256+115] = 0x03;
gertk 0:28557a4d2215 3543 block_buffer[256+116] = 0x12; /*number of sectors within track-29*/
gertk 0:28557a4d2215 3544 block_buffer[256+117] = 0xff;
gertk 0:28557a4d2215 3545 block_buffer[256+118] = 0xff;
gertk 0:28557a4d2215 3546 block_buffer[256+119] = 0x03;
gertk 0:28557a4d2215 3547 block_buffer[256+120] = 0x12; /*number of sectors within track-30*/
gertk 0:28557a4d2215 3548 block_buffer[256+121] = 0xff;
gertk 0:28557a4d2215 3549 block_buffer[256+122] = 0xff;
gertk 0:28557a4d2215 3550 block_buffer[256+123] = 0x03;
gertk 0:28557a4d2215 3551 block_buffer[256+124] = 0x11; /*number of sectors within track-31*/
gertk 0:28557a4d2215 3552 block_buffer[256+125] = 0xff;
gertk 0:28557a4d2215 3553 block_buffer[256+126] = 0xff;
gertk 0:28557a4d2215 3554 block_buffer[256+127] = 0x01;
gertk 0:28557a4d2215 3555 block_buffer[256+128] = 0x11; /*number of sectors within track-32*/
gertk 0:28557a4d2215 3556 block_buffer[256+129] = 0xff;
gertk 0:28557a4d2215 3557 block_buffer[256+130] = 0xff;
gertk 0:28557a4d2215 3558 block_buffer[256+131] = 0x01;
gertk 0:28557a4d2215 3559 block_buffer[256+132] = 0x11; /*number of sectors within track-33*/
gertk 0:28557a4d2215 3560 block_buffer[256+133] = 0xff;
gertk 0:28557a4d2215 3561 block_buffer[256+134] = 0xff;
gertk 0:28557a4d2215 3562 block_buffer[256+135] = 0x01;
gertk 0:28557a4d2215 3563 block_buffer[256+136] = 0x11; /*number of sectors within track-34*/
gertk 0:28557a4d2215 3564 block_buffer[256+137] = 0xff;
gertk 0:28557a4d2215 3565 block_buffer[256+138] = 0xff;
gertk 0:28557a4d2215 3566 block_buffer[256+139] = 0x01;
gertk 0:28557a4d2215 3567 block_buffer[256+140] = 0x11; /*number of sectors within track-35*/
gertk 0:28557a4d2215 3568 block_buffer[256+141] = 0xff;
gertk 0:28557a4d2215 3569 block_buffer[256+142] = 0xff;
gertk 0:28557a4d2215 3570 block_buffer[256+143] = 0x01;
gertk 0:28557a4d2215 3571
gertk 0:28557a4d2215 3572 lp2=0;
gertk 0:28557a4d2215 3573 lp=144;
gertk 0:28557a4d2215 3574
gertk 1:0cbbb66a6100 3575 while ((lp<160) && (diskname[lp2] != 0)) /*diskname*/
gertk 0:28557a4d2215 3576 { /*--------*/
gertk 0:28557a4d2215 3577 block_buffer[256+lp] = diskname[lp2]; /*copy character*/
gertk 0:28557a4d2215 3578 lp2++;
gertk 0:28557a4d2215 3579 lp++;
gertk 0:28557a4d2215 3580 }
gertk 1:0cbbb66a6100 3581 while (lp<160) {
gertk 0:28557a4d2215 3582 block_buffer[256+lp] = 160; /*fill unused locations with shifted spaces, default value*/
gertk 0:28557a4d2215 3583 lp++;
gertk 0:28557a4d2215 3584 }
gertk 0:28557a4d2215 3585
gertk 0:28557a4d2215 3586 block_buffer[256+160] = 160;
gertk 0:28557a4d2215 3587 block_buffer[256+161] = 160;
gertk 0:28557a4d2215 3588
gertk 0:28557a4d2215 3589 if (diskid[0] == 0) /*disk-ID*/
gertk 0:28557a4d2215 3590 { /*-------*/
gertk 0:28557a4d2215 3591 block_buffer[256+162] = '0'; /*default value*/
gertk 0:28557a4d2215 3592 block_buffer[256+163] = '0'; /*default value*/
gertk 1:0cbbb66a6100 3593 } else {
gertk 0:28557a4d2215 3594 block_buffer[256+162] = diskid[0]; /*copy character*/
gertk 1:0cbbb66a6100 3595 if (diskid[1] == 0) {
gertk 0:28557a4d2215 3596 block_buffer[256+163] = 160; /*default value*/
gertk 1:0cbbb66a6100 3597 } else {
gertk 0:28557a4d2215 3598 block_buffer[256+163] = diskid[1]; /*copy character*/
gertk 0:28557a4d2215 3599 }
gertk 0:28557a4d2215 3600 }
gertk 0:28557a4d2215 3601
gertk 1:0cbbb66a6100 3602 block_buffer[256+164] = 160;
gertk 0:28557a4d2215 3603 block_buffer[256+165] = 50; /*DOS VERSION*/
gertk 0:28557a4d2215 3604 block_buffer[256+166] = 65; /*DOS VERSION*/
gertk 0:28557a4d2215 3605 block_buffer[256+167] = 160;
gertk 0:28557a4d2215 3606 block_buffer[256+168] = 160;
gertk 0:28557a4d2215 3607 block_buffer[256+169] = 160;
gertk 0:28557a4d2215 3608 block_buffer[256+170] = 160;
gertk 0:28557a4d2215 3609
gertk 0:28557a4d2215 3610 lp = 171;
gertk 1:0cbbb66a6100 3611 while (lp != 0) { /*fill remaining bytes from 171 up to and including 255 with 0x00*/
gertk 0:28557a4d2215 3612 block_buffer[256+lp] = 0x00;
gertk 0:28557a4d2215 3613 lp++;
gertk 0:28557a4d2215 3614 }
gertk 0:28557a4d2215 3615
gertk 0:28557a4d2215 3616 D64ConvertBlockToTrackSector((block_counter<<1), &tr, &se);
gertk 0:28557a4d2215 3617 print_D64_TSB(tr,se,(341-block_counter),341);
gertk 1:0cbbb66a6100 3618 FileWriteSector_X(&file, block_counter);
gertk 0:28557a4d2215 3619 block_counter++;
gertk 0:28557a4d2215 3620
gertk 0:28557a4d2215 3621 /*fill remaining tracks 18-1 to 35-16 with 0x00 */
gertk 0:28557a4d2215 3622 /*each MMC/SD-card block = 512 bytes, each D64 block = 256 bytes */
gertk 0:28557a4d2215 3623 Clear_block_buffer(); /*clear the block_buffer*/
gertk 1:0cbbb66a6100 3624 do {
gertk 0:28557a4d2215 3625 D64ConvertBlockToTrackSector((block_counter<<1), &tr, &se);
gertk 0:28557a4d2215 3626 print_D64_TSB(tr,se,(341-block_counter),341);
gertk 1:0cbbb66a6100 3627 FileWriteSector_X(&file, block_counter);
gertk 0:28557a4d2215 3628 block_counter++;
gertk 1:0cbbb66a6100 3629 } while (block_counter < 342);
gertk 0:28557a4d2215 3630 SetErrorCode(0,LED_OFF);
gertk 0:28557a4d2215 3631 }
gertk 0:28557a4d2215 3632
gertk 0:28557a4d2215 3633 /*this routine is to be used to handle the errorcode and the LED-blink-mode in an easy way*/
gertk 1:0cbbb66a6100 3634 void SetErrorCode(unsigned char error, unsigned char LEDmode) {
gertk 0:28557a4d2215 3635 /*the original 1541 used the LED to display the results of the power-on selftest*/
gertk 0:28557a4d2215 3636 /* No Blink Kernal (E000-FFFF) ROM or 6522 VIA Failure */
gertk 0:28557a4d2215 3637 /* One Blink 6116 RAM Failure */
gertk 0:28557a4d2215 3638 /* Two Blinks Possible Zero Page RAM Failure */
gertk 0:28557a4d2215 3639 /* Three Blinks DOS (C000-CFFF) ROM Failure */
gertk 0:28557a4d2215 3640 /* Four Blinks DOS (C000-CFFF) ROM Failure */
gertk 0:28557a4d2215 3641 /* Five Blinks 6116 RAM Failure */
gertk 0:28557a4d2215 3642 /* Six Blinks 6116 RAM Failure */
gertk 0:28557a4d2215 3643 /* Seven Blinks 6116 RAM Failure */
gertk 0:28557a4d2215 3644 /* Eight Blinks 6116 RAM Failure */
gertk 0:28557a4d2215 3645 /*Note: at this moment the selftest (and it's blinking modes) is/are not supported (yet)*/
gertk 0:28557a4d2215 3646
gertk 1:0cbbb66a6100 3647 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 3648 /*do not change the error_code, because there is no error and the code 73 must be preserved*/
gertk 1:0cbbb66a6100 3649 } else {
gertk 0:28557a4d2215 3650 if (error != error_code) /*only update the screen when the error_code has changed*/
gertk 0:28557a4d2215 3651 { /*because when there is no new info... there is no reason to print to the display what is allready there*/
gertk 1:0cbbb66a6100 3652 error_code = error;
gertk 1:0cbbb66a6100 3653 // 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 3654 printf("%02d",error_code); /*show the error code*/
gertk 0:28557a4d2215 3655 }
gertk 0:28557a4d2215 3656
gertk 1:0cbbb66a6100 3657 // if ((error == 21) || (error == 62)) /*these error(s) create this sound (i.e. error 62 = file not found)*/
gertk 1:0cbbb66a6100 3658 // PlaySample_HeadBangRattle(); /*play sample that suits this error situation*/
gertk 0:28557a4d2215 3659 }
gertk 0:28557a4d2215 3660
gertk 1:0cbbb66a6100 3661 switch (LEDmode) {
gertk 1:0cbbb66a6100 3662 case LED_OFF: {
gertk 1:0cbbb66a6100 3663 // TMR0ON = 0; /*switch timer-0 OFF*/
gertk 0:28557a4d2215 3664 LED_GREEN = 0; /*switch LED-OFF*/
gertk 0:28557a4d2215 3665 LED_RED = 0; /*switch LED-OFF*/
gertk 0:28557a4d2215 3666 break;
gertk 0:28557a4d2215 3667 }
gertk 0:28557a4d2215 3668
gertk 1:0cbbb66a6100 3669 case LED_ON: {
gertk 0:28557a4d2215 3670 // TMR0ON = 0; /*switch timer-0 OFF*/
gertk 0:28557a4d2215 3671 LED_GREEN = 1; /*switch LED-ON*/
gertk 0:28557a4d2215 3672 LED_RED = 0; /*switch LED-ON*/
gertk 0:28557a4d2215 3673 break;
gertk 0:28557a4d2215 3674 }
gertk 0:28557a4d2215 3675
gertk 0:28557a4d2215 3676
gertk 1:0cbbb66a6100 3677 case LED_ERROR: {
gertk 0:28557a4d2215 3678 Blink_mode = LED_ERROR;
gertk 0:28557a4d2215 3679 LED_status = 0; /*status of the LED (0=OFF)*/
gertk 1:0cbbb66a6100 3680 // TMR0H = 0xFF; /*set registers to enter timer-o interrupt as quickly as possible*/
gertk 1:0cbbb66a6100 3681 // TMR0L = 0xFF;
gertk 1:0cbbb66a6100 3682 // TMR0ON = 1; /*switch timer-0 on*/
gertk 0:28557a4d2215 3683 break;
gertk 0:28557a4d2215 3684 }
gertk 0:28557a4d2215 3685
gertk 1:0cbbb66a6100 3686 default: {
gertk 1:0cbbb66a6100 3687 // TMR0ON = 0; /*switch timer-0 OFF*/
gertk 0:28557a4d2215 3688 LED_GREEN = 0; /*switch LED-OFF*/
gertk 0:28557a4d2215 3689 LED_RED = 0; /*switch LED-OFF*/
gertk 0:28557a4d2215 3690 }
gertk 0:28557a4d2215 3691 }
gertk 0:28557a4d2215 3692 }
gertk 0:28557a4d2215 3693
gertk 1:0cbbb66a6100 3694 void SendErrorMessage(void) {
gertk 0:28557a4d2215 3695 EOI = FALSE;
gertk 0:28557a4d2215 3696 LED_GREEN = 1; /*drive LED-ON*/
gertk 0:28557a4d2215 3697 IEC_turnaround(); /*we now SEND data to the bus so... make our device a talker*/
gertk 0:28557a4d2215 3698 IEC_send_number_as_ASCII(error_code); /*send error-code*/
gertk 0:28557a4d2215 3699 IEC_send(0x2C); /*','*/
gertk 0:28557a4d2215 3700
gertk 1:0cbbb66a6100 3701 switch (error_code) {
gertk 1:0cbbb66a6100 3702 case 0: { /*OK (not an error*/
gertk 0:28557a4d2215 3703 IEC_send_string("OK");
gertk 0:28557a4d2215 3704 break;
gertk 0:28557a4d2215 3705 }
gertk 0:28557a4d2215 3706
gertk 1:0cbbb66a6100 3707 case 1: { /*files scratched (not an error)*/
gertk 0:28557a4d2215 3708 IEC_send_string("FILES SCRATCHED");
gertk 0:28557a4d2215 3709 break;
gertk 0:28557a4d2215 3710 }
gertk 0:28557a4d2215 3711
gertk 0:28557a4d2215 3712 case 2:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3713 case 3:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3714 case 4:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3715 case 5:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3716 case 6:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3717 case 7:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3718 case 8:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3719 case 9:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3720 case 10:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3721 case 11:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3722 case 12:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3723 case 13:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3724 case 14:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3725 case 15:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3726 case 16:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3727 case 17:; /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3728 case 18:; /*Unused error message (should be ingnored)*/
gertk 1:0cbbb66a6100 3729 case 19: { /*Unused error message (should be ingnored)*/
gertk 0:28557a4d2215 3730 IEC_send_string("N/A");
gertk 0:28557a4d2215 3731 break;
gertk 0:28557a4d2215 3732 }
gertk 0:28557a4d2215 3733
gertk 0:28557a4d2215 3734 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 3735 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 3736 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 3737 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 3738 case 24:; /*Write verify (on format) */
gertk 1:0cbbb66a6100 3739 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 1:0cbbb66a6100 3740 IEC_send_string("READ ERROR");
gertk 0:28557a4d2215 3741 break;
gertk 0:28557a4d2215 3742 }
gertk 0:28557a4d2215 3743
gertk 0:28557a4d2215 3744 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 1:0cbbb66a6100 3745 case 28: { /*Write error In actual fact, this error never occurs, but it is included for completeness.*/
gertk 1:0cbbb66a6100 3746 IEC_send_string("WRITE ERROR");
gertk 0:28557a4d2215 3747 break;
gertk 0:28557a4d2215 3748 }
gertk 0:28557a4d2215 3749
gertk 1:0cbbb66a6100 3750 case 26: { /*Write protect on Self explanatory. Remove the write-protect tab, and try again.*/
gertk 1:0cbbb66a6100 3751 IEC_send_string("WRITE PROTECT ON");
gertk 0:28557a4d2215 3752 break;
gertk 0:28557a4d2215 3753 }
gertk 0:28557a4d2215 3754
gertk 1:0cbbb66a6100 3755 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 1:0cbbb66a6100 3756 IEC_send_string("DISK ID MISMATCH");
gertk 0:28557a4d2215 3757 break;
gertk 0:28557a4d2215 3758 }
gertk 0:28557a4d2215 3759
gertk 0:28557a4d2215 3760 case 30:; /*general syntax error*/
gertk 0:28557a4d2215 3761 case 31:; /*invalid command*/
gertk 1:0cbbb66a6100 3762 case 32:; /*long line*/
gertk 0:28557a4d2215 3763 case 33:; /*invalid fileSelectedFileName*/
gertk 0:28557a4d2215 3764 case 34:; /*no file given*/
gertk 1:0cbbb66a6100 3765 case 39: { /*command file not found*/
gertk 1:0cbbb66a6100 3766 IEC_send_string("SYNTAX ERROR");
gertk 0:28557a4d2215 3767 break;
gertk 0:28557a4d2215 3768 }
gertk 0:28557a4d2215 3769
gertk 1:0cbbb66a6100 3770 case 50: { /*record not present*/
gertk 1:0cbbb66a6100 3771 IEC_send_string("RECORD NOT PRESENT");
gertk 0:28557a4d2215 3772 break;
gertk 0:28557a4d2215 3773 }
gertk 0:28557a4d2215 3774
gertk 1:0cbbb66a6100 3775 case 51: { /*overflow in record*/
gertk 1:0cbbb66a6100 3776 IEC_send_string("OVERFLOW IN RECORD");
gertk 0:28557a4d2215 3777 break;
gertk 0:28557a4d2215 3778 }
gertk 0:28557a4d2215 3779
gertk 1:0cbbb66a6100 3780 case 52: { /*file too large*/
gertk 1:0cbbb66a6100 3781 IEC_send_string("FILE TOO LARGE");
gertk 0:28557a4d2215 3782 break;
gertk 0:28557a4d2215 3783 }
gertk 0:28557a4d2215 3784
gertk 1:0cbbb66a6100 3785 case 60: { /*File open for write*/
gertk 1:0cbbb66a6100 3786 IEC_send_string("WRITE FILE OPEN");
gertk 0:28557a4d2215 3787 break;
gertk 0:28557a4d2215 3788 }
gertk 0:28557a4d2215 3789
gertk 1:0cbbb66a6100 3790 case 61: { /*File not open*/
gertk 1:0cbbb66a6100 3791 IEC_send_string("FILE NOT OPEN");
gertk 0:28557a4d2215 3792 break;
gertk 0:28557a4d2215 3793 }
gertk 0:28557a4d2215 3794
gertk 1:0cbbb66a6100 3795 case 62: { /*File not found*/
gertk 1:0cbbb66a6100 3796 IEC_send_string("FILE NOT FOUND");
gertk 0:28557a4d2215 3797 break;
gertk 0:28557a4d2215 3798 }
gertk 0:28557a4d2215 3799
gertk 1:0cbbb66a6100 3800 case 63: { /*File exists*/
gertk 1:0cbbb66a6100 3801 IEC_send_string("FILE EXISTS");
gertk 0:28557a4d2215 3802 break;
gertk 0:28557a4d2215 3803 }
gertk 0:28557a4d2215 3804
gertk 1:0cbbb66a6100 3805 case 64: { /*File type mismatch*/
gertk 1:0cbbb66a6100 3806 IEC_send_string("FILE TYPE MISMATCH");
gertk 0:28557a4d2215 3807 break;
gertk 0:28557a4d2215 3808 }
gertk 0:28557a4d2215 3809
gertk 1:0cbbb66a6100 3810 case 65: { /*No block*/
gertk 1:0cbbb66a6100 3811 IEC_send_string("NO BLOCK");
gertk 0:28557a4d2215 3812 break;
gertk 0:28557a4d2215 3813 }
gertk 0:28557a4d2215 3814
gertk 1:0cbbb66a6100 3815 case 66: { /*Illegal track or sector*/
gertk 0:28557a4d2215 3816 IEC_send_string("ILLEGAL TRACK AND SECTOR");
gertk 0:28557a4d2215 3817 break;
gertk 0:28557a4d2215 3818 }
gertk 0:28557a4d2215 3819
gertk 1:0cbbb66a6100 3820 case 67: { /*Illegal system track or sector*/
gertk 0:28557a4d2215 3821 IEC_send_string("ILLEGAL SYSTEM T OR S");
gertk 0:28557a4d2215 3822 break;
gertk 0:28557a4d2215 3823 }
gertk 0:28557a4d2215 3824
gertk 1:0cbbb66a6100 3825 case 70: { /*No channels available*/
gertk 0:28557a4d2215 3826 IEC_send_string("NO CHANNEL");
gertk 0:28557a4d2215 3827 break;
gertk 0:28557a4d2215 3828 }
gertk 0:28557a4d2215 3829
gertk 1:0cbbb66a6100 3830 case 71: { /*Directory error*/
gertk 0:28557a4d2215 3831 IEC_send_string("DIRECTORY ERROR");
gertk 0:28557a4d2215 3832 break;
gertk 0:28557a4d2215 3833 }
gertk 0:28557a4d2215 3834
gertk 1:0cbbb66a6100 3835 case 72: { /*disk full or directory full*/
gertk 0:28557a4d2215 3836 IEC_send_string("DISK FULL");
gertk 0:28557a4d2215 3837 break;
gertk 0:28557a4d2215 3838 }
gertk 0:28557a4d2215 3839
gertk 1:0cbbb66a6100 3840 case 73: { /*DOS mismatch / Powerup message/write attempt with DOS mismatch*/
gertk 0:28557a4d2215 3841 IEC_send_string("V");
gertk 0:28557a4d2215 3842 IEC_send_number_as_ASCII(RELEASE_VERSION);
gertk 0:28557a4d2215 3843 IEC_send('-');
gertk 0:28557a4d2215 3844 IEC_send_number_as_ASCII(RELEASE_VERSION_SUB);
gertk 0:28557a4d2215 3845 IEC_send('-');
gertk 0:28557a4d2215 3846 IEC_send_number_as_ASCII(RELEASE_VERSION_SUB_SUB);
gertk 0:28557a4d2215 3847 break;
gertk 0:28557a4d2215 3848 }
gertk 0:28557a4d2215 3849
gertk 1:0cbbb66a6100 3850 case 74: { /*no disk in drive or no device 1 (8050 only)*/
gertk 0:28557a4d2215 3851 IEC_send_string("DRIVE NOT READY");
gertk 0:28557a4d2215 3852 break;
gertk 0:28557a4d2215 3853 }
gertk 0:28557a4d2215 3854
gertk 1:0cbbb66a6100 3855 default: {
gertk 0:28557a4d2215 3856 IEC_send_string("ERROR UNKNOWN");
gertk 0:28557a4d2215 3857 break;
gertk 0:28557a4d2215 3858 }
gertk 0:28557a4d2215 3859 }
gertk 0:28557a4d2215 3860
gertk 0:28557a4d2215 3861 DelayBigMs(50); /*some small delay to give the computer time to process the string*/
gertk 0:28557a4d2215 3862 IEC_send(0x2C); /*','*/
gertk 0:28557a4d2215 3863 if (error_code == 1) /*check for the FILES SCRATCHED-error*/
gertk 0:28557a4d2215 3864 IEC_send_number_as_ASCII(files_scratched); /*last accessed track variable is replaced by the number of scratched files*/
gertk 0:28557a4d2215 3865 else
gertk 0:28557a4d2215 3866 IEC_send_number_as_ASCII(LastTrack); /*last accessed track variable*/
gertk 0:28557a4d2215 3867 IEC_send(0x2C); /*','*/
gertk 0:28557a4d2215 3868 IEC_send_number_as_ASCII(LastSector); /*last accessed sector variable*/
gertk 0:28557a4d2215 3869 EOI = TRUE; /*indicate the last byte*/
gertk 0:28557a4d2215 3870 IEC_send(0x0D); /*CARRIAGE RETURN*/
gertk 0:28557a4d2215 3871 IEC_undoturnaround(); /*were done talking towards the bus*/
gertk 0:28557a4d2215 3872 SetErrorCode(0,LED_OFF); /*error-code is 0, LED is OFF*/
gertk 0:28557a4d2215 3873 }
gertk 0:28557a4d2215 3874 /*****************************************************************************************************************/
gertk 0:28557a4d2215 3875 /*****************************************************************************************************************/
gertk 0:28557a4d2215 3876 /*****************************************************************************************************************/
gertk 0:28557a4d2215 3877
gertk 1:0cbbb66a6100 3878 unsigned char ReadDeviceJumper(void) {
gertk 0:28557a4d2215 3879 if (JUMPER_J2 == 0) /*check the device number jumper to see what the req. device number should be*/
gertk 0:28557a4d2215 3880 return(8);
gertk 1:0cbbb66a6100 3881 else
gertk 0:28557a4d2215 3882 return(9);
gertk 0:28557a4d2215 3883 }
gertk 0:28557a4d2215 3884
gertk 0:28557a4d2215 3885 /*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 1:0cbbb66a6100 3886 unsigned char ReadButtons(void) {
gertk 1:0cbbb66a6100 3887
gertk 1:0cbbb66a6100 3888 return(FALSE); /*the 1541-III DTV, does NOT support the use of buttons*/
gertk 1:0cbbb66a6100 3889
gertk 0:28557a4d2215 3890 }
gertk 0:28557a4d2215 3891
gertk 0:28557a4d2215 3892
gertk 0:28557a4d2215 3893 /*
gertk 0:28557a4d2215 3894 There's no shame in writing comments in your sourcecode.
gertk 0:28557a4d2215 3895 */