alekmaul Posted June 4, 2021 Share Posted June 4, 2021 Hi guys, I'm trying to add new feature to my pvcollib and I began to implement SGM functions I'm currently trying to use external ram, so I added to linker options : Quote LDFLAGS += --xram-loc 0x2000 --xram-size 0x6000 But I have a problem to declare variable in this external ram, how can I put variables at 0x2000 ? I "googled" and found some examples, but they do not work Here, for example, http://fivedots.coe.psu.ac.th/~cj/masd/resources/sdcc-doc/SDCCUdoc-10.html xdata at 0x2000 unsigned char PORTA_8255 ; will produce "sgmramtest.c(12) : syntax error: token -> 'at' ; column 8" If I try xdata unsigned char PORTA_8255 ; I have same error. I also found we must use far, same issue with "far unsigned char PORTA_8255 ;" Same thing with "unsigned char __xdata PORTA_8255 ;" Do someone know how to declare in C langage the use of external ram with sdcc ? Quote Link to comment Share on other sites More sharing options...
Kiwi Posted June 4, 2021 Share Posted June 4, 2021 I've wondered if this trick will work like it does with bankswitching with Megacart. Maybe try, dummy=(*(volatile unsigned char*)0x2000); Probably do --data-loc 0x2000 instead of 0x7000. So it continuous 24KB RAM. SGM is something I will have to tackle eventually and experimentally. Quote Link to comment Share on other sites More sharing options...
alekmaul Posted June 5, 2021 Author Share Posted June 5, 2021 (edited) If you change data-loc, you will lost the 1K original ram of CV. @PkK, any idea if sdcc is able to handle external ram for Z80 ? Edited June 5, 2021 by alekmaul Quote Link to comment Share on other sites More sharing options...
youki Posted June 5, 2021 Share Posted June 5, 2021 (edited) did you try stuff like that byte __at (0x2000) PORTA_255; or __sfr __at (0x2000) PORTA_255; Edited June 5, 2021 by youki Quote Link to comment Share on other sites More sharing options...
alekmaul Posted June 6, 2021 Author Share Posted June 6, 2021 (edited) __sfr __at (0x2000) PORTA_255; seems to work, not byte __at. Another problem, I can't declare array Quote sgmramtest.c(12) : error 141: two or more data types in declaration for 'type_specifier declaration_specifiers - skipped' sgmramtest.c(12) : error 50: Array or Pointer to bit|sbit|sfr not allowed. Edited June 6, 2021 by alekmaul Quote Link to comment Share on other sites More sharing options...
Kiwi Posted June 6, 2021 Share Posted June 6, 2021 23 hours ago, alekmaul said: If you change data-loc, you will lost the 1K original ram of CV. How so? I was thinking it move the origin bytes to 0x2000, anything that above that to 0x8000 would be RAM. So the 1KB would still be mapped. Or does it also move the ram addresses that the bios uses. Quote Link to comment Share on other sites More sharing options...
Kiwi Posted June 6, 2021 Share Posted June 6, 2021 Another thing that comes to mind. When using the SGM memory, it maps out the original 1KB of memory, and it can map out the BIOS too. So I don't think you can use SGM as extended memory on top of the original 1KB of memory since the memory map overlaps to get 33KB and the z80 can't see both at the same time. Unless you need the extra 1KB, you'll have to turn off the SGM to use that memory. I would just enable SGM upon boot, and the bios stuff I believe should use the 0x7000 and up. Have to check the crtcv.map to make sure. Quote Link to comment Share on other sites More sharing options...
youki Posted June 6, 2021 Share Posted June 6, 2021 3 hours ago, alekmaul said: __sfr __at (0x2000) PORTA_255; seems to work, not byte __at. Another problem, I can't declare array Strange because something like that should work : byte __at (0xe000) cellram[32][32]; byte __at (0xe800) tileram[256][8]; But i'm wondering why you need to do that. I was trying to use SGM Ram for one of my project, i add just to set the dataloc to 0x2000 sdcc -mz80 --code-loc 0x8048 --data-loc 0x2000 ... then i allocate my memory normally. Quote Link to comment Share on other sites More sharing options...
Pixelboy Posted June 6, 2021 Share Posted June 6, 2021 1 hour ago, Kiwi said: Another thing that comes to mind. When using the SGM memory, it maps out the original 1KB of memory, and it can map out the BIOS too. So I don't think you can use SGM as extended memory on top of the original 1KB of memory since the memory map overlaps to get 33KB and the z80 can't see both at the same time. Unless you need the extra 1KB, you'll have to turn off the SGM to use that memory. I would just enable SGM upon boot, and the bios stuff I believe should use the 0x7000 and up. Have to check the crtcv.map to make sure. Uh... what? Putting the notion of BIOS overriding aside, all the SGM does is exactly what the ADAM does: It turns a range of addresses into available RAM. This range includes the 1K of RAM of the vanilla ColecoVision, as well as the "mirrored" range around that 1K. So in the end you get 24K of contiguous RAM instead of just 1K. You can extend this range to replace the Coleco BIOS, adding 8K for a total of 32K of RAM, so in that mode, anything in the total addressing range that is not cartridge memory (i.e. all addresses below 8000h) is RAM. Not sure what needs to be done to put the SGM in 32K mode, but when the user presses the reset button on the console, the BIOS automatically becomes available again so the system can reboot normally. Quote Link to comment Share on other sites More sharing options...
Kiwi Posted June 6, 2021 Share Posted June 6, 2021 I opened cygwin to used the --data-loc 0x2000 all the variable including the crt0 stuff are moved to 0x2000. I guess use --data-loc 0x7000 --no-std-crt0 --data-loc 0x2000 --no-std-(project name) might work. The information I got, It seem that it has to enable the SGM first to access the extra RAM. So I see in the debugger in BlueMSX, not everything look correct and 1K still mirrored. I'll have to take time to figure out how to include asm file into c. Quote Link to comment Share on other sites More sharing options...
Tursi Posted June 7, 2021 Share Posted June 7, 2021 If you have the asm file as a separate compilation object, you can just link it in with all your other object files. You can include asm inline in SDCC with _asm, _endasm... sample here: // return the distance between a and b unsigned char distance(unsigned char a, unsigned char b) __naked { a;b; _asm push ix ld ix,#0 add ix,sp ;helpers.c:495: if (a>b) { ld a,5 (ix) sub a,4 (ix) jr NC,mikejmp1 ;helpers.c:496: return a-b; neg ld l,a pop ix ret mikejmp1: ;helpers.c:498: return b-a; ld l,a pop ix ret _endasm ; } (Not the neatest example, but the first one I knew where to find ) 1 Quote Link to comment Share on other sites More sharing options...
Tursi Posted June 7, 2021 Share Posted June 7, 2021 10 hours ago, Kiwi said: The information I got, It seem that it has to enable the SGM first to access the extra RAM. So I see in the debugger in BlueMSX, not everything look correct and 1K still mirrored. I'll have to take time to figure out how to include asm file into c. For what it's worth here - you should initialize your hardware in the crt0 anyway, so that it's available before the C code starts up. You'll want to do it before the crt0 loads initialized data, if your crt does that. Quote Link to comment Share on other sites More sharing options...
alekmaul Posted June 9, 2021 Author Share Posted June 9, 2021 On 6/6/2021 at 12:42 PM, youki said: But i'm wondering why you need to do that. I was trying to use SGM Ram for one of my project, i add just to set the dataloc to 0x2000 sdcc -mz80 --code-loc 0x8048 --data-loc 0x2000 ... then i allocate my memory normally. I just wanted to add it as external memory because it is for my dev kit and I wanted to keep it ok with SGM or no SGM. But you're right, as @Kiwi said also, I will change the data-loc and put a big comment in documentation about the use of SGM ram with the kit. Quote Link to comment Share on other sites More sharing options...
alekmaul Posted June 10, 2021 Author Share Posted June 10, 2021 On 6/7/2021 at 3:02 AM, Tursi said: For what it's worth here - you should initialize your hardware in the crt0 anyway, so that it's available before the C code starts up. You'll want to do it before the crt0 loads initialized data, if your crt does that. this was the reason why I wanted to use SGM as an external RAM ... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.