Release version with working ELSE statement:
MC10_ROM_20.bin
While tests show this to work, it has not been tested as much as I would like, so it should be considered a BETA version.
It is now 11:53 in my time zone so it is as complete as it will get for the retro challenge.
A simple test:
10 FOR I = 1 to 10
20 IF I < 6 THEN PRINT I : ELSE PRINT 10 - I
30 NEXT I
My on again off again blog about whatever computer related hobby projects I happen to be working on at the moment.
Sunday, April 30, 2017
One final note. Tokens that are to be executed are normally grouped together. Since ELSE can't be placed with the other tokens, an additional step has to be taken to test it individually and to point to it's location in the jump table.
This means that calling the ELSE token requires a few more clock cycles than the others.
It's ugly but it works.
This means that calling the ELSE token requires a few more clock cycles than the others.
It's ugly but it works.
Documentation:
Changes
V 1.1 optimizes calls to the CHRGET and CHRGOT functions, removes Microsoft and the programmer's unnecessary text, replaces mathematical constants that are incorrect in the original ROM, and calling CLS with numbers greater than 8 simply clears the screen to the standard green background rather than printing "MICROSOFT",
The V 1.1 ROM file is named: MC10_ROM11.bin
V 2.0 contains all the changes from V 1.1 and adds the ELSE command which is used the same as in Color BASIC. A brief explanation of it's use can be found in 'Getting Started With Color BASIC', or "Getting Started With Extended Color BASIC", and a brief syntax description is on the Color BASIC Wiki.
"Getting Started With Extended Color BASIC" can be found on the internet archive.
https://archive.org/details/Getting_Started_with_Extended_Color_BASIC_1984_Tandy
The V 2.0 ROM file is named MC10_ROM_20.bin
Using the new ROM in VMC10
In order to use the new ROM with the VMC10 emulator, you should copy the ROM image to the ROM folder located inside the directory where you have installed VMC10. Then launch VMC10 and load the new ROM by selecting the "Configure" menu, then select the menu item titled "Memory...".
This will display some systems settings. In the "ROM (Emulator only)" section, click on the "Load 8K BASIC ROM from file" option, then click on the "Browse" button to select the new ROM file.
After you have selected the name of the new ROM file, click "Open" and the file dialog box will close. Click on the "Ok" button at the bottom of the "Configure" menu to save your settings and reset the emulator. BASIC should reload and display the new version number. If BASIC displays V 1.0, you have loaded the original ROM and need to check your settings again.
Using the new ROM in a real MC-10
In order to use the new ROM in a real MC-10, you will need to burn a new 8K EPROM and install it in the computer. This requires some technical expertise and is beyond the scope of this document.
Most MC-10s have the ROM directly soldered to the board making this a delicate procedure as well.
If that is the case with your machine, I suggest you have someone experienced perform the installation for you. It requires desoldering the original ROM, installing a socket in it's place, and then plugging in the new EPROM.. You may be able to have this done for you at the same time you have some other upgrade installed.
There are some lucky people out there with a socketed ROM so it may be worth having a look inside your machine.
Technical Details
Microsoft BASIC tokens start at $80. The reason for this, is that all tokens will have the sign bit set.
When parsing a line of tokenized code, any character with a negative value is easily identified as a keyword token.
In order to add ELSE to Microcolor BASIC, it must be added to the next location in the keyword table. This will assign the next available token which is $C9.
The token for ELSE in Color BASIC on the CoCo is $84. The only way we could match tokens to the original color BASIC would be to completely rearrange tables in the Microcolor BASIC ROM and change tokens in the code where it directly tests for them. That is beyond the scope of this project.
In order to squeeze in the additional code to support the ELSE statement, the address of ROM functions had to change. Any calls to standard ROM routines must be done using the vectors located at the end of the ROM. Any function that does not have a vector should not be called from machine language.
Changes
V 1.1 optimizes calls to the CHRGET and CHRGOT functions, removes Microsoft and the programmer's unnecessary text, replaces mathematical constants that are incorrect in the original ROM, and calling CLS with numbers greater than 8 simply clears the screen to the standard green background rather than printing "MICROSOFT",
The V 1.1 ROM file is named: MC10_ROM11.bin
V 2.0 contains all the changes from V 1.1 and adds the ELSE command which is used the same as in Color BASIC. A brief explanation of it's use can be found in 'Getting Started With Color BASIC', or "Getting Started With Extended Color BASIC", and a brief syntax description is on the Color BASIC Wiki.
"Getting Started With Extended Color BASIC" can be found on the internet archive.
https://archive.org/details/Getting_Started_with_Extended_Color_BASIC_1984_Tandy
The V 2.0 ROM file is named MC10_ROM_20.bin
Using the new ROM in VMC10
In order to use the new ROM with the VMC10 emulator, you should copy the ROM image to the ROM folder located inside the directory where you have installed VMC10. Then launch VMC10 and load the new ROM by selecting the "Configure" menu, then select the menu item titled "Memory...".
This will display some systems settings. In the "ROM (Emulator only)" section, click on the "Load 8K BASIC ROM from file" option, then click on the "Browse" button to select the new ROM file.
After you have selected the name of the new ROM file, click "Open" and the file dialog box will close. Click on the "Ok" button at the bottom of the "Configure" menu to save your settings and reset the emulator. BASIC should reload and display the new version number. If BASIC displays V 1.0, you have loaded the original ROM and need to check your settings again.
Using the new ROM in a real MC-10
In order to use the new ROM in a real MC-10, you will need to burn a new 8K EPROM and install it in the computer. This requires some technical expertise and is beyond the scope of this document.
Most MC-10s have the ROM directly soldered to the board making this a delicate procedure as well.
If that is the case with your machine, I suggest you have someone experienced perform the installation for you. It requires desoldering the original ROM, installing a socket in it's place, and then plugging in the new EPROM.. You may be able to have this done for you at the same time you have some other upgrade installed.
There are some lucky people out there with a socketed ROM so it may be worth having a look inside your machine.
Technical Details
Microsoft BASIC tokens start at $80. The reason for this, is that all tokens will have the sign bit set.
When parsing a line of tokenized code, any character with a negative value is easily identified as a keyword token.
In order to add ELSE to Microcolor BASIC, it must be added to the next location in the keyword table. This will assign the next available token which is $C9.
The token for ELSE in Color BASIC on the CoCo is $84. The only way we could match tokens to the original color BASIC would be to completely rearrange tables in the Microcolor BASIC ROM and change tokens in the code where it directly tests for them. That is beyond the scope of this project.
In order to squeeze in the additional code to support the ELSE statement, the address of ROM functions had to change. Any calls to standard ROM routines must be done using the vectors located at the end of the ROM. Any function that does not have a vector should not be called from machine language.
Decisions, decisions... what should I put in the final release?
Just a quick scan through the code that has all the optimizations reveals hundreds(?) of lines of code that have been changed. A couple of those changes break the interpreter and I haven't had time to track down which ones are the problem. So, I'm going to err on the side of caution, and release a version of the interpreter that adds ELSE to the V1.1 ROM I posted last night. This will meet the goals I set for the project by the deadline. The interpreter is faster, and it adds the ELSE command. But the most important thing is that it will be stable and has the best chance of running everything out there.
A version with a greater speed increase would be nice but it's not going to happen in this time frame. The first problem is that most of the optimizations only cut a few clock cycles each, so you won't see some massive jump in performance. For that, the math library needs to be faster, or the interpreter needs significant changes to how it deals with numbers. There is definitely more speed to be had, but for some massive jump it's going to require more ROM space than I have.
Just a quick scan through the code that has all the optimizations reveals hundreds(?) of lines of code that have been changed. A couple of those changes break the interpreter and I haven't had time to track down which ones are the problem. So, I'm going to err on the side of caution, and release a version of the interpreter that adds ELSE to the V1.1 ROM I posted last night. This will meet the goals I set for the project by the deadline. The interpreter is faster, and it adds the ELSE command. But the most important thing is that it will be stable and has the best chance of running everything out there.
A version with a greater speed increase would be nice but it's not going to happen in this time frame. The first problem is that most of the optimizations only cut a few clock cycles each, so you won't see some massive jump in performance. For that, the math library needs to be faster, or the interpreter needs significant changes to how it deals with numbers. There is definitely more speed to be had, but for some massive jump it's going to require more ROM space than I have.
Saturday, April 29, 2017
It appears it's time to start uploading files.
The first file will be assembly source for generating the original ROM.
The biggest change from the disassembly (other than removal of the leftmost columns) is every JSR >CHRGET and JSR >CHRGOT were replaced with a forced extended address version of the JSR instruction. The assembler Microsoft used clearly didn't take advantage of the direct addressing form of JSR. This alone would have freed up some space in the ROM and saved some clock cycles. Every direct version saves 1 clock cycle, and one byte. It's a small optimization, but the interpreter reads a lot of characters through that routine.
To build the original ROM, comment out (add a semicolon in front of) line 40 which says:
#define VERSION The TASM (Telmark Assembler) is required to build the ROM..
If you leave it in, it will build a ROM displaying V1.1 which uses direct addressing for those calls, uses corrected math constants, removes Microsoft Easter eggs, and removes the programmer's name.
This saves 71 BYTEs and is close to what Microsoft should have produced to begin with.
This is also the file I'm using as a basis for testing other changes.
During testing I encountered one little problem. I've tried testing this and many other optimizations with Ahl's Benchmark (a simple benchmark in Creative computing) and I cannot duplicate the time listed in the magazine with VMC10, even though the new ROM is faster than the original when compared side by side. Either the number in the magazine is off, or the emulator is slow.
Source Code
ROM V 1.1
The first file will be assembly source for generating the original ROM.
The biggest change from the disassembly (other than removal of the leftmost columns) is every JSR >CHRGET and JSR >CHRGOT were replaced with a forced extended address version of the JSR instruction. The assembler Microsoft used clearly didn't take advantage of the direct addressing form of JSR. This alone would have freed up some space in the ROM and saved some clock cycles. Every direct version saves 1 clock cycle, and one byte. It's a small optimization, but the interpreter reads a lot of characters through that routine.
To build the original ROM, comment out (add a semicolon in front of) line 40 which says:
#define VERSION The TASM (Telmark Assembler) is required to build the ROM..
If you leave it in, it will build a ROM displaying V1.1 which uses direct addressing for those calls, uses corrected math constants, removes Microsoft Easter eggs, and removes the programmer's name.
This saves 71 BYTEs and is close to what Microsoft should have produced to begin with.
This is also the file I'm using as a basis for testing other changes.
During testing I encountered one little problem. I've tried testing this and many other optimizations with Ahl's Benchmark (a simple benchmark in Creative computing) and I cannot duplicate the time listed in the magazine with VMC10, even though the new ROM is faster than the original when compared side by side. Either the number in the magazine is off, or the emulator is slow.
Source Code
ROM V 1.1
Sunday, April 23, 2017
Status update.
I really haven't spent much time on anything new since the last post.
There is a bug that seems to be part of the original conversion of the disassembly back to assembly code that did not appear in initial tests, but now it has become a show stopper. This has forced me to go back to my original goal of creating a version of the source code that generates an identical binary to the original ROM. Then I can test individual changes against that code instead of everything all at once. Most of that work is complete but I probably have another 25-50 changes to go before it's ready. It's a couple hours work at the most.
One of the easiest optimizations that came out of this effort was simply using an assembler that properly generates code for direct page references. I'm actually had to force the assembler to generate the original opcodes using FCB and FDB. This alone probably saved enough space vs the Easter eggs to implement the ELSE statement. That's the first change I'll make to the code.
Then I'll insert the ELSE code, followed by a few small optimizations that use D where it's definitely safe.
Two of the optimizations that I want to use involve the CHARGET and storing the pointer to the next line. They will certainly offer a speedup. But to fully support the CHARGET changes requires looking at dozens of subroutines to find out what the X register contains for each one. This is going to take a notebook or whiteboard and several days work. Given the time constraints of the contest, it will have to be in a later release. Storing the pointer to the next line is almost complete, but there is still one condition where it is failing and I need to see what is still messing up the FOR NEXT stack. This optimization may also have to wait.
Everything previously mentioned will certainly offer a small performance increase.. I've also written faster versions of the code that moves strings and made a lot of other modifications that can save clock cycles. When all those are rolled out, Microcolor BASIC will certainly be more responsive. Running two copies of the VMC10 emulator side by side running the same program show a small but noticeable difference.
I have not worked on code to speedup the search for line numbers. I looked at a simple design on paper and I probably need another 50 to 75 bytes for that. It's just not going to fit in the limited ROM space. Maybe some future ah-ha moments will free up enough space, but I have my doubts.
This brings us to the real bottleneck which is the math library. I've made several optimizations but they all have to be retested from scratch thanks to the bug I mentioned. So that's another thing that may not make the release. Sadly, the fastest approach on paper to many of these routines is probably going to exceed available space. It's an 8K ROM, not a Tardis.
Ultimately, I should have a release that supports ELSE and is faster soon. It won't be as fast as I'd like, but there will certainly be follow up releases as I test the other optimizations. Hopefully some of the better ones will be ready before the end of the contest. The fixes to the bad Microsoft math constants can already be used as an option, so that should be in the release as well.
I really haven't spent much time on anything new since the last post.
There is a bug that seems to be part of the original conversion of the disassembly back to assembly code that did not appear in initial tests, but now it has become a show stopper. This has forced me to go back to my original goal of creating a version of the source code that generates an identical binary to the original ROM. Then I can test individual changes against that code instead of everything all at once. Most of that work is complete but I probably have another 25-50 changes to go before it's ready. It's a couple hours work at the most.
One of the easiest optimizations that came out of this effort was simply using an assembler that properly generates code for direct page references. I'm actually had to force the assembler to generate the original opcodes using FCB and FDB. This alone probably saved enough space vs the Easter eggs to implement the ELSE statement. That's the first change I'll make to the code.
Then I'll insert the ELSE code, followed by a few small optimizations that use D where it's definitely safe.
Two of the optimizations that I want to use involve the CHARGET and storing the pointer to the next line. They will certainly offer a speedup. But to fully support the CHARGET changes requires looking at dozens of subroutines to find out what the X register contains for each one. This is going to take a notebook or whiteboard and several days work. Given the time constraints of the contest, it will have to be in a later release. Storing the pointer to the next line is almost complete, but there is still one condition where it is failing and I need to see what is still messing up the FOR NEXT stack. This optimization may also have to wait.
Everything previously mentioned will certainly offer a small performance increase.. I've also written faster versions of the code that moves strings and made a lot of other modifications that can save clock cycles. When all those are rolled out, Microcolor BASIC will certainly be more responsive. Running two copies of the VMC10 emulator side by side running the same program show a small but noticeable difference.
I have not worked on code to speedup the search for line numbers. I looked at a simple design on paper and I probably need another 50 to 75 bytes for that. It's just not going to fit in the limited ROM space. Maybe some future ah-ha moments will free up enough space, but I have my doubts.
This brings us to the real bottleneck which is the math library. I've made several optimizations but they all have to be retested from scratch thanks to the bug I mentioned. So that's another thing that may not make the release. Sadly, the fastest approach on paper to many of these routines is probably going to exceed available space. It's an 8K ROM, not a Tardis.
Ultimately, I should have a release that supports ELSE and is faster soon. It won't be as fast as I'd like, but there will certainly be follow up releases as I test the other optimizations. Hopefully some of the better ones will be ready before the end of the contest. The fixes to the bad Microsoft math constants can already be used as an option, so that should be in the release as well.
Monday, April 10, 2017
And now I messed up the FOR NEXT stack frame when I moved some stuff related to the next line pointer around. This should be fun to track down. <sigh>
Another speed optimization I'm working on involves parsing every character via the CHRGET subroutine. CHRGET is a piece of self modifying code that is copied from ROM to the direct page at startup. The function looks like this:
This also only resulted in a 1 byte increase in code size thanks to removal of a couple STX CHPTR instructions elsewhere. Sadly, only 2 out of 20+ calls can use this optimization without major changes, and neither will speed up program execution.
If someone builds an MC-10 clone using a 68HC11 based microcontroller (as has been suggested in the MC-10 yahoo group), the code could easily be optimized my placing CHRPTR in the Y register. Then every update to CHRPTR just involves loading Y or incrementing Y, and CHRGET becomes INY LDAA ,Y.
This should speed up the interpreter significantly.
Another speed optimization I'm working on involves parsing every character via the CHRGET subroutine. CHRGET is a piece of self modifying code that is copied from ROM to the direct page at startup. The function looks like this:
If we can place CHRPTR in X, we can move this to ROM right in front of BPARSE and reduce it from 22(?) clock cycles to 7(?) clock cycles. If we don't have to update CHRPTR until we exit BPARSE, we save even more clock cycles since BPARSE loops back to CHARGET.;*;* Byte parser subroutine utilizing self-modifying code.;* This routine is copied to RAM at CHRGET ($00EB) during cold start.;*fcb INIDAT-PARSER ; number of bytes to copyPARSER inc CHRPTR+1 ; increment LSB of parse locationbne LF7D8 ; branch if no carryinc CHRPTR ; increment MSB of parse locationLF7D8; ldaa $0000 ; load byte from parse location into ACCAfcb $B6,$00,$00jmp BPARSE ; call back-end of parser routine in ROM
This also only resulted in a 1 byte increase in code size thanks to removal of a couple STX CHPTR instructions elsewhere. Sadly, only 2 out of 20+ calls can use this optimization without major changes, and neither will speed up program execution.
CHRGET2
inx
stx CHRPTR
ldaa ,X ; get the next character
If someone builds an MC-10 clone using a 68HC11 based microcontroller (as has been suggested in the MC-10 yahoo group), the code could easily be optimized my placing CHRPTR in the Y register. Then every update to CHRPTR just involves loading Y or incrementing Y, and CHRGET becomes INY LDAA ,Y.
This should speed up the interpreter significantly.
Subscribe to:
Posts (Atom)