Jump to content

Photo

From Hi-Tech C to SDCC


34 replies to this topic

#1 newcoleco OFFLINE  

newcoleco

    Stargunner

  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Mon Feb 2, 2009 12:16 AM

URL : Attached File  sdcctest.zip   688.38KB   202 downloads

* Updates *
2009-02-15 : added : testscr2 - a simple screen mode 3 test, like a kaleidoscope
2009-02-14 : added : (in getput) screen_mode_1_text(), screen_mode3_bitmap(), pset(x,y,color), color = pget(x,y)
2009-02-14 : added : chateau du dragon - a text-adventure game I've never finish
2009-02-06 : added : dacman - my first colecovision game project released in cartridge in year 2000, converted for this compiler.
2009-02-06 : added : mute_all in coleco library (lib4k)
2009-02-05 : bugfix : stop_sound
2009-02-05 : bugfix : updatesprites
2009-02-05 : added : no name - a game sample with a bitmap screen, a charset a sprite movement on screen.
2009-02-05 : bugfix : memset is no more a hidden function inside coleco library, include string.h instead.
2009-02-04 : added : explosion game source code, with converted sound table to coleco sound format.
2009-02-03 : bugfix : clear_sprites (was also missing from coleco.h)
2009-02-02 : bugfix : upload_ascii


Warning : Still in development, beta version available.

After one week of developments, I decided to release the beta version of my actual new ColecoVision programming kit based this time on SDCC compiler.

For those who already use my ColecoVision kit, thie new kit may be a future solution if you want a faster compiler and keep the tools I've made so far for the ColecoVision developments.

This work is based on my optimization of the Coleco library to make my minigames for the minigame compo also called lib4k. This library doesn't support spinners, and the extra third and fourth fire buttons. This kit focus on standard joystick controllers and already available Coleco BIOS functions.

To use this kit, you have to download and install first SDCC for Windows... which is very very easy.

1. Download a snapshot version of SDCC that include a Windows Installer.
2. Start the installer and select the minimum package to install.
3. In the list, make sure z80 library and includes are added.
4. Proceed the installation normally.

Then unzip my zip file somewhere you like. Find "objcopy.exe" inside "tools" folder and move it to the "bin" folder of SDCC.
Find "coleco.h" and "getput1.h" and copy them (not move) into the "include" folder of SDCC.

The kit is now ready.

Copy "CCI.EXE" from tools folder into one of the project folders like "diamond" which is Diamond Dash minigame.
Double clikc on CCI.
Click on the following buttons (in order) "Default", "Compile All", "Link", "Run".
For each DOS popup box waiting for space bar to close, simply press the space bar.

If you have an emulator already associated with "rom" files, then clicking on the "Run" button will try to open the resulting rom with your emulator.

Try this kit at your own risks, but there is no real risk except the libraries are not totally stable.

Edited by newcoleco, Sun Feb 15, 2009 8:28 PM.


#2 youki OFFLINE  

youki

    Stargunner

  • 1,736 posts

Posted Mon Feb 2, 2009 6:18 AM

Thanks for that!

I will try it as soon as possible. :)

#3 youki OFFLINE  

youki

    Stargunner

  • 1,736 posts

Posted Mon Feb 2, 2009 8:56 AM

ok, i have quickly tested . I have just compiled your great bunny game. It works! :)

I'm looking foward to try on my "secret" project , hopefully i'll try tonight. :)

#4 5-11under OFFLINE  

5-11under

    River Patroller

  • 2,093 posts
  • Location:Ontario, Canada

Posted Mon Feb 2, 2009 12:11 PM

Thanks for all of your work on this, Daniel. This will bring C programming for the CV out of the 80's, which in this case, will be a good thing.

Thanks,
5-11under

#5 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Mon Feb 2, 2009 12:15 PM

ok, i have quickly tested . I have just compiled your great bunny game. It works! :)

I'm looking foward to try on my "secret" project , hopefully i'll try tonight. :)

A few hints to convert a Hi-Tech C project into a SDCC project based on this new kit.

First of all, make sure every single constant, including tables, arrays and variables, have now the word "const" beside it. Note that you can leave your "#define" as is.

Second, SDCC is mostly based on C-99 standard so you can use comments //, but keeping your comments /* */ is great.

Third, sometimes the compiler will gives your warnings and error you may not encounter with hi-tech c, for these cases simply try to figure out what is the problem. If you need help, try to find a solution from one of the sample source codes from the kit.

Fourth, if the project compile but the result on screen is buggy, it's normal because this new kit is not stable yet, remember that : it's a beta version.

For SDCC with Windows installer, go here : http://sdcc.sourcefo...nap.php#Windows

Edited by newcoleco, Mon Feb 2, 2009 1:06 PM.


#6 youki OFFLINE  

youki

    Stargunner

  • 1,736 posts

Posted Mon Feb 2, 2009 4:10 PM

Ok, i have quickly tried to compile my project.

It compiles and links (after few modification ).

But when it runs the screen is buggy. I can see almost my screen how it should be but with some bad characters at some place and i can not see my sprites.

#7 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Mon Feb 2, 2009 5:15 PM

Ok, i have quickly tried to compile my project.

It compiles and links (after few modification ).

But when it runs the screen is buggy. I can see almost my screen how it should be but with some bad characters at some place and i can not see my sprites.

Tell me which functions from the libraries you are using and I will try to fix them in priority.

2009-02-02 : bugfix : upload_ascii from coleco library.

2009-02-03 : bugfix : clear_sprites from coleco library, and its declaration was also missing in the coleco.h file.

Edited by newcoleco, Tue Feb 3, 2009 3:48 PM.


#8 youki OFFLINE  

youki

    Stargunner

  • 1,736 posts

Posted Tue Feb 3, 2009 5:12 PM

I tested your last fix , not change in my case.

Here the list of API i use :

screen_mode_2_text()

enable_nmi()
disable_nmi()
rle2vram()
cls()
screen_on()
updatesprites()
put_char()
get_char()
delay()

keypad_1
joypad_1

change_spattern()
rnd_byte()
sprite_simple()

i used also the following one, but i have commented the calls in order to compile.
start_sound()
update_sound()

#9 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Wed Feb 4, 2009 10:21 PM

Thanks for your list, I will investigate on these first.

checking...

screen_mode_2_text() OK /* Cosmo Challenge */

enable_nmi() *OK* /* DACMAN */
disable_nmi()
rle2vram() *OK* /* many */
cls() *OK* /* DACMAN */
screen_on() *OK* /* many */
updatesprites() *FIXED* /* No Name */
put_char() *OK* /* many */
get_char() *OK* /* Diamond Dash */
delay() *OK* /* Cosmo Challenge */

keypad_1 *OK* /* Cosmo Challenge */
joypad_1 *OK* /* Cosmo Challenge */

change_spattern() *OK* /* Explosion */
rnd_byte() *OK* /* Diamond Dash */
sprite_simple() <-- you don't need that one, sprites are not magnified (double in size) by default.

i used also the following one, but i have commented the calls in order to compile.
start_sound()
update_sound()

For the sound part, it's because I focus on using Coleco sound format instead of Marcel's sound format. This way I can compile smaller games like Diamond Dash in 4K or less, even if it's coded in C.

1. If you get the error about a missing snd_table when linking, copy the file "sounds.c" from the "tstscrn" project. It's a dummy empty sound table but you actually need one to make the project compile as a valid rom file.

2. If you do a function like wait_nmi() that loops until the nmi_count flag change because of the nmi interrupt, replace it with something like delay(1);

Sometimes, you will have to find a workaround solution like the point 2 here. I'm sorry about that but it's the reality.

-----

2009-02-06 : added : dacman - my first colecovision game project released in cartridge in year 2000, converted for this compiler.
2009-02-06 : added : mute_all in coleco library (lib4k)
2009-02-05 : bugfix : stop_sound from coleco library (lib4k)
2009-02-05 : bugfix : updatesprites from getput was still working in the way for the hi-tech c stack. it's now fixed.
2009-02-05 : bugfix : conflict between coleco lib (lib4k) and string.h with memset function. use #include <string.h>

Edited by newcoleco, Fri Feb 6, 2009 1:08 AM.


#10 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Fri Feb 6, 2009 1:08 PM

When I did the conversion of DACMAN to work with this new kit, I did saw three (3) things :

1 - SIGNED COORDINATES : the coordinates for put_char and get_char are signed based on the coleco bios function, so if you try an invalid x value like 255, it will be consider as -1 which will put (or get) the character at the end of the line just above. In the orginal getput library (2000-2005), the offset in video memory was calculated with unsigned values for x and y.

2 - X COORDINATE CALCULATED IN CENTER_STRING : was different between the first version of getput and the newer versions getput v1.1+ and it's about the way it deals with odd number of characters to center. In the first getput, if you have 11 characters to center, the calculation for x coordinate gives 10. In the new getput, if you want to center the exact same 11 characters, the calculation for x coordinate gives 11. Remember that x and y coordinates start at (0,0) for the top left corner of the screen. So, the new center_string programmed like 5 years ago now, do print the same 11 characters a bit more to the right than the old version. Wich one is right? none, but it's ok if you know how to deal with it and what you really want to do. And center_string is more a function easy to add in your code instead of put_vram and print_at because you can put it as a place holder or to quickly deal with other parts of the game project you are making.

3 - CLEAR_SPRITES : is no more a valid function to use: it doesn't fit well in the new coleco library called LIB4K, and the conversion to SDCC seems to not work as it supposed to be for no reason. I'm getting stranges result with this function and I find out that it's only in my oldest projects like DACMAN that I used it to clean up the sprites table. But if you know what you are doing, you don't need to use a function to clean the sprites table because all it does is filling part of the sprites table with the Y coordinate at 0xd0 (or 204), which is the indicator for the END OF SPRITE. If I can convert DACMAN to not use clear_sprites, you can do the same for your own projects.

#11 youki OFFLINE  

youki

    Stargunner

  • 1,736 posts

Posted Fri Feb 6, 2009 3:29 PM

Ca marche!!!! Mille Merci!

Thanks a lot, now my game runs correctly with this new kit!!

:)

#12 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Fri Feb 6, 2009 8:02 PM

Ca marche!!!! Mille Merci!

Thanks a lot, now my game runs correctly with this new kit!!

:)

Super! Do not hesitate to contact me again if you have any more troubles with this kit in development.

#13 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Mon Feb 9, 2009 4:36 AM

For personal reasons, I have to stop for a few days all my Coleco developements, including this new kit. But don't worry, I will be back soon.

During this weekend, I did find a new bug in the new kit when I was trying to convert my unfinished text-adventure game "Chateau du Dragon", but I didn't find time to investigate.

Meanwhile, I did a nice little project, short and sweet, to celebrate my 10 years of ColecoVsiion programming. It was February 2, 1999, Breakout, my first game I did program for the ColecoVision. The source code and rom file are available at my dev-fr blog, here:


ColecoVision - my 10 Coleco years celebrations!

Source + ROM : http://newcoleco.dev...0-ans-deja.html

Video:

#14 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Sat Feb 14, 2009 6:41 PM

!!NEW FUNCTIONS!!


It's specially for this new kit, based on an old project I have done before 2005, and a request from someone here.


screen_mode_1_text();

Desc.: To setup the graphic mode 1, which is 32x24 characters on screen, with only 2 colors per 8 characters in the charset. That means it can use all the print functions for the graphic mode 2 except to setup the colors.


screen_mode_3_bitmap();

Desc.: To setup the multicolor mode, which is the 64x48 pixels on screen. This command setup the NAME table to be ready for the functions for the pixels.


pset(x,y,color);

Desc.: To set a color to the pixel at coordinates x,y.


color = pget(x,y);

Desc.: To get the color of the pixel at coordinates x,y.


All these functions are tested OK. :)


The updated library will be available during the day : 2009-02-15.

#15 youki OFFLINE  

youki

    Stargunner

  • 1,736 posts

Posted Fri Feb 20, 2009 6:11 AM

Excellent !!!!

Thanks a lot. The mode 3 is mode i'll definitely test in a project i have in mind!

:)

#16 youki OFFLINE  

youki

    Stargunner

  • 1,736 posts

Posted Mon Mar 23, 2009 3:54 AM

Hi Daniel,

I don't know if it is a bug of the SDCC kit , but i just report it just in case.

the function updatesprites seems to be limited to 26 (or 25) sprites. If you are more sprite defined you have very strange behavior.

Anyway not a problem for me , i solved this issue using your method : put_vram (0x1b00,sprites,<xx>); that works great! :)

#17 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Tue Mar 24, 2009 9:34 AM

Hi Daniel,

I don't know if it is a bug of the SDCC kit , but i just report it just in case.

the function updatesprites seems to be limited to 26 (or 25) sprites. If you are more sprite defined you have very strange behavior.

Anyway not a problem for me , i solved this issue using your method : put_vram (0x1b00,sprites,<xx>); that works great! :)


Thanks for reporting bugs!

Work in progress for a bug I did found myself, I will check your bug right after, let's call it "youki-1".

#18 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Mon Apr 6, 2009 2:17 PM

I'm working on updating the devkit, I will let you know when the new version will be available.

Meanwhile, I did publish a new video on youtube and this time it's about how to install sdcc with this devkit on Windows. Probably someone can do it better, but I don't care for now because I have so many things to do and time is running.

#19 youki OFFLINE  

youki

    Stargunner

  • 1,736 posts

Posted Tue Apr 7, 2009 2:33 PM

Hi Daniel,

I have noticed that in the Build.bat in the lib4k folder a line is missing.

@echo off
echo COMPILING ALL SOURCE FILES
FOR %%c in (./*.s) DO as-z80 -o %%c.o %%c
copy crtcv.s.o crtcv.o
del crtcv.s.o
echo COMPILE LIBRARY
FOR %%c in (./*.o) DO sdcclib cvlib.lib %%c
echo COPY GENERATED FILES
copy cvlib.lib ..
copy coleco.h ..
copy crtcv.o .. <--- this line should be added!
echo CLEAN UP
del *.o
del cvlib.lib

:)

#20 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Tue Apr 7, 2009 3:59 PM

Yes, I knew about this issue when dealing with the Space Harrier project where I had to change the crtcv.s file to activate the default coleco title screen.

What I did in the batch file was simply this :
copy crtcv.s.o ..\crtcv.o

I hope to upload the new version of the devkit with the different fixes... at least we progress to a more stable version each time.

#21 ilmarque OFFLINE  

ilmarque

    Space Invader

  • 25 posts

Posted Wed Apr 8, 2009 8:00 AM

This is neat. Good work :)

Have you tested these on real hardware?
When i tried to run testscr2 on MESS and ColEm i got just a black screen but it worked fine on Vcoleco.
Also, for example in the bunny game ColEm shows only the upper ~1/3 of the screen. Any idea why?

#22 youki OFFLINE  

youki

    Stargunner

  • 1,736 posts

Posted Wed Apr 8, 2009 9:14 AM

This is neat. Good work :)

Have you tested these on real hardware?
When i tried to run testscr2 on MESS and ColEm i got just a black screen but it worked fine on Vcoleco.
Also, for example in the bunny game ColEm shows only the upper ~1/3 of the screen. Any idea why?


Personally i use BlueMSX to test my games. I used VColeco but the sound is different in certain case. and the version i have , i don't know way don' t have the 4 sprites by row limit!!!. I was able to put 6 sprites in a row!!! .. in BlueMSX it works well sprites reacts as real!

#23 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Wed Apr 8, 2009 9:24 AM

This is neat. Good work :)

Have you tested these on real hardware?
When i tried to run testscr2 on MESS and ColEm i got just a black screen but it worked fine on Vcoleco.
Also, for example in the bunny game ColEm shows only the upper ~1/3 of the screen. Any idea why?

For now, I can answer the "only upper 1/3 screen" issue, and it's the emulator fault, and should be fixed for all systems using TMS9928 rendering.

In the video rendering part of the emulator, ColEm and almost all its clones do not emulate the screen mode 2 correctly by assuming that screen mode 2 is always set to use 3 charsets regardless of what is the settings in th video register for pattern and color tables. Screen mode 2 uses in a particular way the video registers for pattern and color table, you can setup even more stangely the color table to make it repeat the same colors through the charset, kinda difficult to understand when you don't try it, but it's a AND mask.

Note : consider here that when I say bit 7 it means the highest bit in a byte.

With screen mode 2, it's :

Control Register 3 (for Color Table)

bit 7 : if set, color table is at 0x2000, at 0x0000 otherwise.
bits 6-0 : AND mask

Control Register 4 (for Pattern Table)

bit 2 : if set, pattern table is at 0x2000, at 0x0000 otherwise.
bits 1-0 : AND mask

Now, consider that you have 10 bits rather than 8 bits to identify a char on screen, but the highest 2 bits are in function of which part of the screen the char is. the upper part (1/3 of the screen) is 00 for the 2 highest bits, the middle part is 01 for the 2 highest bits, and the bottom part is 10 for the 2 highest bits.

The video chip complete the AND masks with 1 for the lower bits the video registers cannot set to make a 10bits AND mask.

So, based on this, if bits 1-0 of the pattern table are 0s then a character on screen is identify the same whatever where it is on screen... and that's how I can use only one charset instead of 3 for the entire screen.

Most of the time, I admit it, the registers are set like this when using screen mode 2 :

reg 3, 0xFF -> 0x2000, AND mask = 1111111111
reg 4, 0x03 -> 0x0000, AND mask = 1111111111

Because bit 7 is 1 for reg3 and bit 2 is 0 for reg 4, the color table is at 0x2000 and the pattern table is at 0x0000... and ColEm just deny the existence of the other bits which setup the AND mask and that makes the video rendering right by pure luck when using this setting for 3 charsets.

For my Coleco projects, I'm using, for a long long time now, the following setting when using screen mode 2 :

reg 3, 0x9F -> 0x2000, AND mask = 0011111111
reg 4, 0x00 -> 0x0000, AND mask = 0011111111

What that does? I'm still using the color table at 0x2000 and the pattern table at 0x0000, but the 2 highest bits in the AND mask are set to 0 to render the color and pattern tables. This way, the 2 extra bits effect for the character being in the top, middle or the bottom part of the screen doesn't matter because the AND mask simply filter them as 00, so only the usual 8bits identify the characters on screen.

I hope this is clear and I hope the programmers of these emulators will fix this long over due issue.

AdamEm, made before year 2000, do emulate the video mode 2 correctly for my games. No problem.

Edited by newcoleco, Wed Apr 8, 2009 9:35 AM.


#24 ilmarque OFFLINE  

ilmarque

    Space Invader

  • 25 posts

Posted Wed Apr 8, 2009 9:35 AM

Ok. Thank you for your quick and in depth answer.
Time to get coding :)

#25 newcoleco OFFLINE  

newcoleco

    Stargunner

  • Topic Starter
  • 1,168 posts
  • In depression
  • Location:Quebec

Posted Wed Apr 8, 2009 12:29 PM

This is neat. Good work :)

Have you tested these on real hardware?
When i tried to run testscr2 on MESS and ColEm i got just a black screen but it worked fine on Vcoleco.
Also, for example in the bunny game ColEm shows only the upper ~1/3 of the screen. Any idea why?

Playing beta version of the some minigames with a real ColecoVision and a good old tvset.

The game "Jump or Die" in this video is showing the engine that I do use for my game Easter Bunny.




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users