New Mega Drive/Genesis compiler in the works!

Talk about development tools here

Moderator: BigEvilCorporation

Post Reply
elusive
Very interested
Posts: 57
Joined: Fri Jan 27, 2012 12:03 am

New Mega Drive/Genesis compiler in the works!

Post by elusive » Thu Nov 19, 2015 9:31 pm

Hey everyone!
Over the last few weeks, I've been working on a new Genesis/Mega Drive compiler. I know most of you here prefer C or ASM, so this may disappoint you a little bit, but it's a BASIC compiler called Second Basic.

*dodges a tomato or 12* :P

Don't get me wrong, I know C is generally a better compiler, but I have this special place in my heart for BASIC.

Onto some details:
It's using BEX's ASM library, for the most part. I've asked Devster about it previously, even posted on his forums about it, so while I haven't heard anything back, I'm going to assume for the time being that it's okay to use his ASM library (if he does object, I'll respect his wishes, of course).

I know BEX gets a lot of flack, and while the ASM library isn't the best that it could be, it's just a starting point until I get a better grasp on ASM (which this project has definitely helped that process quite a bit!) and can do what I can to improve the behind-the-scenes stuff.

Anyway, it's still early in the builds and only supports a handful of commands at the moment, but I did hit a big milestone in that it's actually functional with math operations, variables (including arrays as of last night), and a lot of fixed functionality that was either broken in BEX, or just wasn't there.

Here's a quick video of an earlier build from last week: https://www.youtube.com/watch?v=XjMke6H ... e=youtu.be

Here's the code used in the video:

Code: Select all

        players = 1
	
	IF players < 2 THEN	
		pal& = LBLPTR&(sdpal)
	END IF
	
	PALETTES pal&,0,0,16,224	' set the palette to black
	PRINT "Fading Test"
	
	FOR i = 7 TO 0 STEP -1
		PALETTES pal&,0,0,16,i<<5
		SLEEP 3
	NEXT
sdpal:
	DATAINT $0EEE,$0EC4,$0EA2,$0CA4,$0C60,$06CE,$008E,$006E ' Palette: 0
	DATAINT $000E,$0802,$0A82,$0000,$0CCC,$048E,$0ECE,$0ECE
	DATAINT $0CCC,$0CA2,$0C80,$0A82,$0A40,$04AC,$006C,$004C ' Palette: 0
	DATAINT $000C,$0600,$0860,$0000,$0AAA,$024C,$0CAC,$0CAC
	DATAINT $0AAA,$0A82,$0A60,$0860,$0820,$028A,$004A,$002A ' Palette: 0
	DATAINT $000A,$0400,$0640,$0000,$0888,$002A,$0A8A,$0A8A
	DATAINT $0888,$0860,$0840,$0640,$0600,$0068,$0028,$0008 ' Palette: 0
	DATAINT $0008,$0200,$0420,$0000,$0666,$0008,$0868,$0868
	DATAINT $0666,$0640,$0620,$0420,$0400,$0046,$0006,$0006 ' Palette: 0
	DATAINT $0006,$0000,$0200,$0000,$0444,$0006,$0646,$0646
	DATAINT $0444,$0420,$0400,$0200,$0200,$0024,$0004,$0004 ' Palette: 0
	DATAINT $0004,$0000,$0000,$0000,$0222,$0004,$0424,$0424
	DATAINT $0222,$0200,$0200,$0000,$0000,$0002,$0002,$0002 ' Palette: 0
	DATAINT $0002,$0000,$0000,$0000,$0000,$0002,$0202,$0202
	DATAINT $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000 ' Palette: 0
	DATAINT $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000

One thing I'd like to point out about the code above: In BEX, you couldn't use a long variable with the address of a line label in most functions (drawtiles, palettes, etc), which I found kind of annoying (maybe I'm just a bad programmer :P ), so I made that an option in Second Basic, as well as a few other bells and whistles :)

The reason why I decided to start this project is because I've started running into a lot of annoyances with BEX (such as if you accidentally double tap F5, the IDE will crash and all unsaved work will be lost), and more annoying than that is the compiler error that occurs after the code reaches a certain length, or too many user functions are created. I wrote a program to fix the compiler issue (change BSR to JSR) so that this wasn't an issue anymore, but instead of writing little add on applications to keep a presumed project as dead (no updates in almost 5 or 6 years, Devster rarely posts these days), I figured it would just be better to rebuild the compiler and use the existing ASM framework for compatibility and to save time (aside from learning ASM or C)

Anywho, I can hardly wait until it's ready for an actual release! :)

Cheers!

elusive
Very interested
Posts: 57
Joined: Fri Jan 27, 2012 12:03 am

Re: New Mega Drive/Genesis compiler in the works!

Post by elusive » Thu Nov 19, 2015 9:34 pm

One other thing I wanted to mention: Stef gave the go-ahead to use his XGM Driver as the built in music and sound effects driver for this compiler :D

User avatar
Natsumi
Very interested
Posts: 81
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: New Mega Drive/Genesis compiler in the works!

Post by Natsumi » Thu Nov 19, 2015 10:16 pm

I hope when you release this, the asm output will be clean and reasonable. BEX, I believe, had a constant issue with nonsensical asm output, with code that was redundant, terrible and utterly unoptimized, or plain insane use of opcodes (such as addi.l #0,d0 as opposed to tst.l d0, or sub.l d0,d0 as opposed to clr.l d0 or moveq #0,d0)

elusive
Very interested
Posts: 57
Joined: Fri Jan 27, 2012 12:03 am

Re: New Mega Drive/Genesis compiler in the works!

Post by elusive » Thu Nov 19, 2015 10:39 pm

Natsumi wrote:I hope when you release this, the asm output will be clean and reasonable. BEX, I believe, had a constant issue with nonsensical asm output, with code that was redundant, terrible and utterly unoptimized, or plain insane use of opcodes (such as addi.l #0,d0 as opposed to tst.l d0, or sub.l d0,d0 as opposed to clr.l d0 or moveq #0,d0)
The ASM output will most likely be identical to BEX's to start off with. Like I mentioned, I'm not too familiar with ASM (though I'm learning), but some stuff I had cleaned up (like using FOR...NEXT loops or IF...THEN blocks output 3 or 4 line labels, but only 2 were needed).

I'll definitely take a look at those commands that you mentioned and see if I can't add them in and keep it functioning :)

elusive
Very interested
Posts: 57
Joined: Fri Jan 27, 2012 12:03 am

Re: New Mega Drive/Genesis compiler in the works!

Post by elusive » Mon Nov 23, 2015 2:33 am

Arrays are now supported/functional :D

Here's a video using some more commands than the previous video: https://youtu.be/R1PvJxevEKU

The code from the video:

Code: Select all

	DIM b(1,2,3,4) AS INTEGER
	b(1,2,0,0) = 50
	b(1,2,0,0) = b(1,2,0,0) + 1
	LOADTILES MyTiles,295,100
	PALETTES sdpal,0,0,16,224
		
	RELOAD logoscreen
	FOR y = 0 TO 27
		FOR x = 0 TO 39
			READINT z
			DRAWTILE 99+z,x,y
		NEXT
	NEXT
	IF b(1,2,0,0) = 51 THEN pal& = LBLPTR&(sdpal)
	FOR i = 7 TO 0 STEP -1
		PALETTES pal&,0,0,16,i<<5
		SLEEP 3
	NEXT

sdpal:
	DATAINT $0EEE,$00EE,$0E0E,$000E,$0EE0,$0000,$004E,$006E
	DATAINT $008E,$00AE,$00CE,$0E40,$0E60,$0E80,$0EA0,$0EC0
	DATAINT $0CCC,$00CC,$0C0C,$000C,$0CC0,$0000,$002C,$004C
	DATAINT $006C,$008C,$00AC,$0C20,$0C40,$0C60,$0C80,$0CA0
	DATAINT $0AAA,$00AA,$0A0A,$000A,$0AA0,$0000,$000A,$002A
	DATAINT $004A,$006A,$008A,$0A00,$0A20,$0A40,$0A60,$0A80
	DATAINT $0888,$0088,$0808,$0008,$0880,$0000,$0008,$0008
	DATAINT $0028,$0048,$0068,$0800,$0800,$0820,$0840,$0860
	DATAINT $0666,$0066,$0606,$0006,$0660,$0000,$0006,$0006
	DATAINT $0006,$0026,$0046,$0600,$0600,$0600,$0620,$0640
	DATAINT $0444,$0044,$0404,$0004,$0440,$0000,$0004,$0004
	DATAINT $0004,$0004,$0024,$0400,$0400,$0400,$0400,$0420
	DATAINT $0222,$0022,$0202,$0002,$0220,$0000,$0002,$0002
	DATAINT $0002,$0002,$0002,$0200,$0200,$0200,$0200,$0200
	DATAINT $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
	DATAINT $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000

logoscreen:
	$INCLUDE "c:\dev\sd_map.sbs", @SBS

MyTiles:
	DATAFILE c:\dev\sd_logo.bnx, BIN
Cheers!

RetroGames
Interested
Posts: 34
Joined: Mon Oct 19, 2015 12:34 pm

Re: New Mega Drive/Genesis compiler in the works!

Post by RetroGames » Mon Nov 23, 2015 4:08 am

I like assembly, but I also like BASIC. I hope your project is a great success! 8)

elusive
Very interested
Posts: 57
Joined: Fri Jan 27, 2012 12:03 am

Re: New Mega Drive/Genesis compiler in the works!

Post by elusive » Tue Nov 24, 2015 9:04 pm

RetroGames wrote:I like assembly, but I also like BASIC. I hope your project is a great success! 8)
Thanks :)

I was going to post an update here the other night, but it was getting late after a few other forum updates (and then dental surgery yesterday), so here's the update:

I have arrays working now (which was a pain to get implemented :P), and a video demonstrating some conditionals, the use of external data files and source code files, and drawing tiles: https://youtu.be/R1PvJxevEKU

Cheers!

elusive
Very interested
Posts: 57
Joined: Fri Jan 27, 2012 12:03 am

Re: New Mega Drive/Genesis compiler in the works!

Post by elusive » Mon Nov 30, 2015 9:18 pm

Hey everyone! For those interested in this project, I released an alpha build last night: http://www.second-dimension.com/secondbasic.zip

Included with the installation are a handful of examples and the user guide/command reference. I recommend installing to a folder outside of the Program Files folder, at least on Vista and new operating systems, as the UAC will cause you grief.

Anyway, while there's a plethora of things to get done, it is functional and simple games can be made :) Most of the options in the Preferences don't do anything at the moment, though you can set the Paths for the external applications and emulator and such, and have the compiler launch the emulator after a successful compile.

I'm hoping to update the EXE each week with the new functions and commands that I get done throughout the week, so I'll be sure to post those updates as well :)

If any bugs or issues pop up, let me know!

Cheers!

elusive
Very interested
Posts: 57
Joined: Fri Jan 27, 2012 12:03 am

Re: New Mega Drive/Genesis compiler in the works!

Post by elusive » Thu Dec 03, 2015 9:37 pm

Natsumi wrote:I hope when you release this, the asm output will be clean and reasonable. BEX, I believe, had a constant issue with nonsensical asm output, with code that was redundant, terrible and utterly unoptimized, or plain insane use of opcodes (such as addi.l #0,d0 as opposed to tst.l d0, or sub.l d0,d0 as opposed to clr.l d0 or moveq #0,d0)
I'm no master at ASM, so I'll be using mostly the BEX ASM library, though the deeper I get into this project, the more ASM I'm able to understand and learning, so I'm hoping to address those issues (I've also done a few small changes in regards to that, though there's going to be a lot more). Any suggestions and tips you can offer for this project in that regard would be greatly appreciated).

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest