+nanochess Posted April 28 Share Posted April 28 Hi all. CVBasic the integer BASIC cross-compiler for Colecovision, MSX, and SG1000 has come a long way in a few months! I'm surprised how so fast people are making games with it. After thinking about it a lot, I've decided on a way to implement bank-switching on CVBasic! Bank-switching is supported for Colecovision with Megacart-style banking, for SG1000 using Sega mapper ($fffe), and for MSX using ASCII16 mapper. Again all the platform details are handled by CVBasic, you only need to code the best possible program 😉 What can you code in 1 MB of ROM? Changes in v0.5.0: * New statements BANK ROM (for selection ROM size from 128K, 256K, 512K, or 1MB!), BANK to select a bank for following code/data, and BANK SELECT to select a bank to access. * Added example bank.bas for basic usage of BANK. * New statement SPRITE FLICKER ON/OFF. * Optimization of code generation for NEXT. * Optimization of several 8-bit and 16-bit operations in common usage (typically saving hundreds of bytes in medium-size programs) * Added patch to make SG1000 compilations compatible with SC3000. Changes in v0.5.1: * Added SIGNED and UNSIGNED keywords to tag variables (both 8-bit and 16-bit) this enables signed comparisons, division, and modulo. * Added OPTION EXPLICIT and OPTION WARNINGS. * Added scrolling example contributed by @artrag * The MSX target now supports 0-9, - and = for CONT1.KEY. * Added new target Spectravideo SVI-318/328 (using option --svi) * Better assembler output for DATA. * Optimized addition by 256. * Optimized byte variable multiplied by 256. * Optimized extra RET generated when using RETURN. * Optimized use of Z flag. * Optimized AND/OR/XOR of constant with 8-bit variable. * Optimized code generation to avoid unnecessary PUSH/POP. * More powerful optimization taking note of register usage. * Reports open control block at end of procedure/program. * Solved bug of undetected unfinished loop at global level. * Solved bug of joystick not working in SC3000. * Solved bug when subtracting two pointers (VARPTR) * Solved bug where error would indicate wrong file (INCLUDE) * Solved bug where Megacart didn't worked with --sgm, nor the NTSC variable. Enjoy it! Edit: Book now available! Programming Games for Colecovision (250 pages, paperback) from lulu.com you can see also a preview video Edit2: Hardcover now available! And also ebook. cvbasic_v0.5.0.zip cvbasic_v0.5.1.zip 12 3 Quote Link to comment Share on other sites More sharing options...
+nanochess Posted April 28 Author Share Posted April 28 BTW I'll be glad to know how many bytes you save in your final binary when compiling with this new version. Quote Link to comment Share on other sites More sharing options...
abeker Posted April 28 Share Posted April 28 Oh wow, the generated assembly code looks much better now On my small code (~1KB) the new version saves about 160 bytes! There's still room for improvement, for example when you use a logical operator in an IF-statement the generated assembly code is a bit weird compared to when using logical operators in assignments. ; IF level(cursor_index) AND 64 THEN LD A,(cvb_CURSOR_INDEX) LD L,A LD H,0 LD DE,array_LEVEL ADD HL,DE LD L,(HL) LD H,0 LD A,L AND 64 LD L,A LD H,0 LD A,H OR L JP Z,cv27 vs. ; tile = level(cursor_index) AND (32+3) LD A,(cvb_CURSOR_INDEX) LD L,A LD H,0 LD DE,array_LEVEL ADD HL,DE LD A,(HL) AND 35 LD (cvb_TILE),A In this case LD HL,(cvb_CURSOR_INDEX) / LD H,0 will also save one byte and two cycles. You probably now these 'tricks': When subtracting a 16bit constant number, just make it negative and add it. Increasing/decreasing an 8bit number by one can be optimized, LD HL,variable / INC (HL) or DEC (HL). When assigning the same value to multiple variables, it can be loaded in a register just once. In my game players can use both joysticks, so I just use CONT.<DIRECTION> all the time. This could probably just be LD HL,(joy1_data) / LD A,H / OR L. I just skimmed through the assembly code, but there's probably more, I can check more thoroughly if you'd like. Or use the excellent MDL tool made by Santiago Ontañón (it doesn't like the currently generated assembly code due to the # character in labels). 1 Quote Link to comment Share on other sites More sharing options...
+nanochess Posted April 28 Author Share Posted April 28 41 minutes ago, abeker said: Oh wow, the generated assembly code looks much better now On my small code (~1KB) the new version saves about 160 bytes! There's still room for improvement, for example when you use a logical operator in an IF-statement the generated assembly code is a bit weird compared to when using logical operators in assignments. ; IF level(cursor_index) AND 64 THEN LD A,(cvb_CURSOR_INDEX) LD L,A LD H,0 LD DE,array_LEVEL ADD HL,DE LD L,(HL) LD H,0 LD A,L AND 64 LD L,A LD H,0 LD A,H OR L JP Z,cv27 vs. ; tile = level(cursor_index) AND (32+3) LD A,(cvb_CURSOR_INDEX) LD L,A LD H,0 LD DE,array_LEVEL ADD HL,DE LD A,(HL) AND 35 LD (cvb_TILE),A In this case LD HL,(cvb_CURSOR_INDEX) / LD H,0 will also save one byte and two cycles. You probably now these 'tricks': When subtracting a 16bit constant number, just make it negative and add it. Increasing/decreasing an 8bit number by one can be optimized, LD HL,variable / INC (HL) or DEC (HL). When assigning the same value to multiple variables, it can be loaded in a register just once. In my game players can use both joysticks, so I just use CONT.<DIRECTION> all the time. This could probably just be LD HL,(joy1_data) / LD A,H / OR L. I just skimmed through the assembly code, but there's probably more, I can check more thoroughly if you'd like. Or use the excellent MDL tool made by Santiago Ontañón (it doesn't like the currently generated assembly code due to the # character in labels). Thanks for the suggestions! I'm glad you have nice savings in byte usage. Your first IF can be optimized if you add the period character to the 64 constant. This way, CVBasic gets it as an 8-bit constant. Quote Link to comment Share on other sites More sharing options...
artrag Posted April 28 Share Posted April 28 Awesome ! and the generated ASM looks better than the one generated by SDCC for C sources 1 1 Quote Link to comment Share on other sites More sharing options...
Jess Ragan Posted April 29 Share Posted April 29 So that's one megabyte? Like eight megabits, as advertised on Strider for the Sega Genesis? Dang. Will someone have the dedication and sheer force of will to make a ColecoVision game of that size? That falls into "epic RPG" status. Not even Kirby's Adventure at six megabits was that large! Quote Link to comment Share on other sites More sharing options...
+5-11under Posted April 29 Share Posted April 29 21 minutes ago, Jess Ragan said: So that's one megabyte? Like eight megabits, as advertised on Strider for the Sega Genesis? Dang. Will someone have the dedication and sheer force of will to make a ColecoVision game of that size? That falls into "epic RPG" status. Not even Kirby's Adventure at six megabits was that large! If it helps, my boards can handle up to "HalfMega", or 512KB. 128KB is more common, and is somewhat cheaper. 2 Quote Link to comment Share on other sites More sharing options...
+nanochess Posted April 29 Author Share Posted April 29 1 hour ago, Jess Ragan said: So that's one megabyte? Like eight megabits, as advertised on Strider for the Sega Genesis? Dang. Will someone have the dedication and sheer force of will to make a ColecoVision game of that size? That falls into "epic RPG" status. Not even Kirby's Adventure at six megabits was that large! That's right. Eight megabits. 1 Quote Link to comment Share on other sites More sharing options...
Révo Posted April 29 Share Posted April 29 I'm so glad to see bank-switching on CVBASIC, thank you so much! This last version made me save 0,2kb on my game^^ Are you planning to release and sell a book about CVBASIC? Where is that Donkey Kong clone game? 2 Quote Link to comment Share on other sites More sharing options...
ZippyOasys Posted April 29 Share Posted April 29 1 hour ago, Révo said: Are you planning to release and sell a book about CVBASIC? Where is that Donkey Kong clone game? I think he said he is, along with the Monkey Moon example. Quote Link to comment Share on other sites More sharing options...
+nanochess Posted April 29 Author Share Posted April 29 2 hours ago, Révo said: I'm so glad to see bank-switching on CVBASIC, thank you so much! This last version made me save 0,2kb on my game^^ Are you planning to release and sell a book about CVBASIC? Where is that Donkey Kong clone game? 7 minutes ago, ZippyOasys said: I think he said he is, along with the Monkey Moon example. That's right. The game is Monkey Moon, and the book is almost around the corner. 3 Quote Link to comment Share on other sites More sharing options...
Tony Cruise Posted April 30 Share Posted April 30 I have updated my sprite and tile editor to support CVBasic format, let me know if I have missed anything. New version is available here. 3 1 Quote Link to comment Share on other sites More sharing options...
Jess Ragan Posted April 30 Share Posted April 30 Oh, that would be nice. Shame I was doing the Byron game through the command menu with TMScolor. Slightly less convenient, as you can imagine. Quote Link to comment Share on other sites More sharing options...
SiRioKD Posted April 30 Share Posted April 30 Hi, reading in SMS memory mapper info I found this: $fffc Cartridge RAM mapper control $fffd Mapper slot 0 control $fffe Mapper slot 1 control $ffff Mapper slot 2 control If you want to change page 2 ($8000-BFFF) you probably need to use ld ($ffff),a In the initializazion part of mapper the code you can find is: ld hl, $0000 ; Set FFFC to 0, FFFD (Slot 0, $0400-$3FFF) to 0 ld ($FFFC), hl ld hl, $0201 ; Set FFFE (Slot 1, $4000-$7FFF) to 1, FFFF (Slot 2, $8000-$BFFF) to 2 ld ($FFFE), hl https://www.smspower.org/Development/MemoryMap 1 Quote Link to comment Share on other sites More sharing options...
+nanochess Posted April 30 Author Share Posted April 30 5 hours ago, Tony Cruise said: I have updated my sprite and tile editor to support CVBasic format, let me know if I have missed anything. New version is available here. Pretty cool. Thanks! People working in Windows surely will appreciate it. A question because I don't see a edit control to enter the label. Can be used a label name like cvb_sprites_bitmap? It is because CVBasic adds the cvb_* part to access labels. 1 hour ago, SiRioKD said: Hi, reading in SMS memory mapper info I found this: $fffc Cartridge RAM mapper control $fffd Mapper slot 0 control $fffe Mapper slot 1 control $ffff Mapper slot 2 control If you want to change page 2 ($8000-BFFF) you probably need to use ld ($ffff),a In the initializazion part of mapper the code you can find is: ld hl, $0000 ; Set FFFC to 0, FFFD (Slot 0, $0400-$3FFF) to 0 ld ($FFFC), hl ld hl, $0201 ; Set FFFE (Slot 1, $4000-$7FFF) to 1, FFFF (Slot 2, $8000-$BFFF) to 2 ld ($FFFE), hl https://www.smspower.org/Development/MemoryMap Yes, CVBasic already initializes $fffe for SG1000. The other parts are set on RESET. For compatibility reasons, I've set $0000-$3fff as a fixed bank, and $4000-$7fff as the switchable bank, so it reflects the MSX and Colecovision mappers. Of course, this mapper for SG1000 is kind of extending the standard because so far I don't know any SG1000 game using bank switching, so it would be more for Sega Master System consoles. 1 Quote Link to comment Share on other sites More sharing options...
OriginalJohn Posted April 30 Share Posted April 30 (edited) 7 hours ago, Tony Cruise said: I have updated my sprite and tile editor to support CVBasic format, let me know if I have missed anything. New version is available here. Outstanding - this is awesome news! @Tony Cruise Would it be possible to add a button to the Screen Layouts tab that will remove any unused chars from the character set list? Thanks Edited April 30 by OriginalJohn Quote Link to comment Share on other sites More sharing options...
Tony Cruise Posted May 1 Share Posted May 1 9 hours ago, OriginalJohn said: Outstanding - this is awesome news! @Tony Cruise Would it be possible to add a button to the Screen Layouts tab that will remove any unused chars from the character set list? Thanks That's a good idea - I will have a look at that for the next update. 1 Quote Link to comment Share on other sites More sharing options...
Tony Cruise Posted May 1 Share Posted May 1 10 hours ago, nanochess said: Pretty cool. Thanks! People working in Windows surely will appreciate it. A question because I don't see a edit control to enter the label. Can be used a label name like cvb_sprites_bitmap? It is because CVBasic adds the cvb_* part to access labels. Yes, CVBasic already initializes $fffe for SG1000. The other parts are set on RESET. For compatibility reasons, I've set $0000-$3fff as a fixed bank, and $4000-$7fff as the switchable bank, so it reflects the MSX and Colecovision mappers. Of course, this mapper for SG1000 is kind of extending the standard because so far I don't know any SG1000 game using bank switching, so it would be more for Sega Master System consoles. Yes, you can add labels to individual sprites, each tileset and each tile layout. Just type over the automatically generated name with the new name. 2 1 Quote Link to comment Share on other sites More sharing options...
SiRioKD Posted May 2 Share Posted May 2 Hi, I put the essential code for SG-1000/SC-3000 used in Sega games. I added the correct initialization code and the keyboard (SC-3000 and external SK-1100 for SG-1000) support for joystick (only player 1 so far). https://github.com/siriokds/SC-3000-Keyboard-support/blob/main/SG-1000_SC-3000_essentials.asm Enjoy. 4 Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted May 2 Share Posted May 2 I hope moving up the chain of sega consoles eventually leads to Sega Master System support. Perhaps Sega Genesis support by using the z80 and compatible VDP modes. Flashable boards and shells for Sega Genesis are cheap and easy. Plus, many more Sega Genesis enthusiasts out there Quote Link to comment Share on other sites More sharing options...
ZippyOasys Posted May 2 Share Posted May 2 Just out of curiosity, I wonder if you could add support for the SG-1000 Arcade hardware. https://segaretro.org/SG-1000-based_arcade_hardware Quote Link to comment Share on other sites More sharing options...
SiRioKD Posted May 2 Share Posted May 2 Hi, here's my modified prologue: https://github.com/siriokds/SC-3000-Keyboard-support/blob/main/cvbasic_prologue.asm * Inserted the initial VDP initialization delay needed with these machines with no bios. * Added the SC-3000/SG-1000 player-1 keys from keyboard if present. 2 Quote Link to comment Share on other sites More sharing options...
Jess Ragan Posted May 2 Share Posted May 2 Heh, I think I've been talking to you on another forum! For the record, I don't know if I can compress the graphics in the game without losing visual quality. (Which would be a shame, as graphics are a highlight in WESEB.) I know Nanochess mentioned something called "pletter" in the instructions, but I don't know how that works. I'm pretty sure I don't want the code to get so complicated that I can't keep track of it, though. I've noticed that SG-1000 games can be slightly larger than ColecoVision games, up to 48K. How does CV Basic handle games for that system and the MSX? Same hard limit on cart size? 1 Quote Link to comment Share on other sites More sharing options...
thegeps Posted May 2 Share Posted May 2 Pletter is a file compressor. It compress your files on PC and provide you a fast decompressor in Z80 asm to be included in your sources. I presume that if CVBasic will support pletter compression then it will be totally automatic by some dedicated new command (as the ones he added for cartrige pages switching) There are megarom cartridges also for colecovision, so no worry about it 1 Quote Link to comment Share on other sites More sharing options...
carlsson Posted May 2 Share Posted May 2 When you generate graphics through tmscolor -z, your data will be compressed with the Pletter algorithm. Once you insert it into your program, you load as characters or sprites by adding the PLETTER keyword so the compiler knows this data actually is compressed. That is a non-destructive compression, think ZIP in order to save ROM space. While the manual doesn't say, I suppose it might take a little longer to load such data than if it was uncompressed straight from ROM. Since you can DEFINE VRAM at any address with compressed data, I suppose it could be a use case if you keep e.g. changeable level data in a part of VRAM that you VPEEK and VPOKE against all the time. In that case, you would have compressed your levels manually using a Pletter compressor, which is not what you asked for. 1 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.