Quantcast

Page 1 of 3 123 LastLast
Results 1 to 15 of 31

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

  1. #1
    Wildside Expert dra600n's Avatar
    Join Date
    Jan 2011
    Posts
    208
    Rep Power
    21

    Default New Mega Drive/Genesis compiler in the works!

    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=XjMk...ature=youtu.be

    Here's the code used in the video:
    Code:
            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!

    ETA: One other thing I wanted to mention - Stef gave the permission to use his XGM driver as the built in Music and Sound Effects driver for this compiler

  2. #2
    Smith's Minister of War Hero of Algol Kamahl's Avatar
    Join Date
    Jan 2011
    Location
    Belgium
    Age
    29
    Posts
    8,423
    Rep Power
    137

    Default

    I don't get the hate for BASIC, it's a nice language. Far less "wordy" than Pascal for one, more readable than C. It's all in the quality of the compiler really. FreeBasic does pretty well for example.
    Last edited by Kamahl; 11-19-2015 at 07:45 PM.
    This thread needs more... ENGINEERS

  3. #3
    WCPO Agent
    Join Date
    Aug 2014
    Location
    France
    Posts
    800
    Rep Power
    35

    Default

    Quote Originally Posted by Kamahl View Post
    I don't get the hate for BASIC, it's a nice language. Far less "wordy" than Pascal for one, more readable than C. It's all in the quality of the compiler really. FreeBasic does pretty well for example.
    It's because you're too young. Early BASICs, everyone hates now, were filled with line numbers and GOTO. "Modern" basic (the 1st one of this kind I used was GFA Basic in the late 80s) looks much more like Pascal than like the old ones).

    That said, I'd pretty much prefer a Python (even less verbose, forces code to be readable).

  4. #4
    Smith's Minister of War Hero of Algol Kamahl's Avatar
    Join Date
    Jan 2011
    Location
    Belgium
    Age
    29
    Posts
    8,423
    Rep Power
    137

    Default

    Quote Originally Posted by tryphon View Post
    It's because you're too young. Early BASICs, everyone hates now, were filled with line numbers and GOTO.
    That said, I'd pretty much prefer a Python (even less verbose, forces code to be readable).
    Pfff, I played around with a spectrum, I entered some commands, it ain't that bad. It had ifs, subroutines and for loops, one could avoid the damn line numbers. I feel sorry for anyone who tried to do anything serious with it though...

    And yeah python is pretty nice, though for a language that prides itself in readability it sure likes to do __this__. Whoever came up with that crap needs to never decide on anything ever again.
    This thread needs more... ENGINEERS

  5. #5
    WCPO Agent
    Join Date
    Aug 2014
    Location
    France
    Posts
    800
    Rep Power
    35

    Default

    I coded a complete assembler and recursive functions on a MO5 (similar to a Spectrum), I hate BASIC since

    I don't really see what's really wrong with __this__.
    I mean, that's so ugly that you know for sure that it isn't something you want to use too often, which was the goal I guess

    I'd say I'm not totally sure dynamic typing is so great, if I had to complain about Python. But that would be nitpicking.

    I've just discovered the module ast. Impressive. It should be possible to make a subset of Python that can :

    * either be executed like a standard python script, using a module that mimics the Megadrive functions

    * or be compiled directly in 68000 code.

    That's definitely something to think about. After Shnobi...
    Last edited by tryphon; 11-20-2015 at 08:18 AM.

  6. #6
    Smith's Minister of War Hero of Algol Kamahl's Avatar
    Join Date
    Jan 2011
    Location
    Belgium
    Age
    29
    Posts
    8,423
    Rep Power
    137

    Default

    Quote Originally Posted by tryphon View Post
    I don't really see what's really wrong with __this__.
    I mean, that's so ugly that you know for sure that it isn't something you want to use too often, which was the goal I guess
    If you're using classes you have to use __init__ to write the constructor and __del__ for the destructor. One of those is pretty much mandatory, and so is the other if you're wrapping some operating system component (like a file). Are you saying I don't want to use object oriented programming often ?

    Or the classic:

    if __name__ == "__main__":
    main()

    needed to avoid the "import executes code" problem.

    It's mandatory ugly, and that makes no sense in a language that prides itself in readability.
    This thread needs more... ENGINEERS

  7. #7
    WCPO Agent
    Join Date
    Aug 2014
    Location
    France
    Posts
    800
    Rep Power
    35

    Default

    If you implement your own file-wrapping class, you're doing something high-level, so the guy who reads your code must be able to cope with __it__ : it's a safeguard

    But tbh, the __thing__ iin itself I don't find ugly (much less that all circumvolutions you find in C++).

    What can be ugly is that you can redefine things like __call__ or __setattr__, which can lead to utterly ununderstandable code and bugs. But when used correctly, it's also a strength.

    Concering OOP, after using it the most possible, I avoid it the most I can now

  8. #8
    Smith's Minister of War Hero of Algol Kamahl's Avatar
    Join Date
    Jan 2011
    Location
    Belgium
    Age
    29
    Posts
    8,423
    Rep Power
    137

    Default

    Quote Originally Posted by tryphon View Post
    If you implement your own file-wrapping class, you're doing something high-level, so the guy who reads your code must be able to cope with __it__ : it's a safeguard
    If a guy is reading the implementation of a class I'm assuming he knows what a class is and how it works, otherwise why look at it?

    Quote Originally Posted by tryphon View Post
    Concering OOP, after using it the most possible, I avoid it the most I can now
    As you should, the whole "everything is an object" mantra is a classic case of everything looking like a nail if all you have is a hammer. Still, when used for what it's best at, wrapping things into higher level concepts, it's great.
    This thread needs more... ENGINEERS

  9. #9
    WCPO Agent LinkueiBR's Avatar
    Join Date
    Oct 2013
    Posts
    972
    Rep Power
    39

    Default

    Awesome dra600n!
    VISUAL SHOCK!
    SPEED SHOCK!
    SOUND SHOCK!
    NOW IS TIME TO THE 68000 HEART ON FIRE!


    Shadow of the Beast II - Enhanced Colors:
    http://www.romhacking.net/hacks/2275/

    Sunset Riders - Enhanced Colors:
    http://www.romhacking.net/hacks/2287/

    Turrican - Fixed:
    http://www.romhacking.net/hacks/2535/

  10. #10
    Wildside Expert dra600n's Avatar
    Join Date
    Jan 2011
    Posts
    208
    Rep Power
    21

    Default

    Quote Originally Posted by LinkueiBR View Post
    Awesome dra600n!
    Thanks!

    I've never used Python or Pascal, so while I would love to weigh in on the side discussion, I can't (though it's really interesting to see a civil conversation on different programming languages for once, so keep at it :P )

    Not much of an update since the first post, but I did start getting multi-dimensional arrays working (which I seriously hope nobody uses as they're a messy bunch, and much slower than just assigning a value to a non-dimensioned variable instead, but for the sake of BEX compatibility.... :P ). I should've done the array handling much sooner than now because it is kind of a pain in the rear process, and adding in new functions and commands is a much faster process.

  11. #11
    Wildside Expert dra600n's Avatar
    Join Date
    Jan 2011
    Posts
    208
    Rep Power
    21

    Default

    Arrays are now supported/functional

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

    The code from the video:
    Code:
    	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!

  12. #12
    Wildside Expert dra600n's Avatar
    Join Date
    Jan 2011
    Posts
    208
    Rep Power
    21

    Default

    Second Basic is finally ready to be used (at least for small projects)! Not all of the commands and functions are in there yet, but there's more than enough to get a game started. Sorry for the delay on this news/update. I had to fix a few bugs I found when making the examples, and some of them were rather tricky Everything in the examples compiles, so there shouldn't be many issues with the currently supported commands and functions.

    If there are any bugs (ie, won't compile but the IDE doesn't catch the error), let me know (and the code you were using).

    A lot of the config options aren't usable yet, so aside from launching an emulator and changing colors, don't expect the rest to work (well, most of them, anyway :P)

    The download link: http://www.second-dimension.com/secondbasic.zip...

    Cheers!

  13. #13
    Comrade as in friend. Master of Shinobi ComradeOj's Avatar
    Join Date
    Dec 2012
    Location
    New Mexico, USA
    Age
    24
    Posts
    1,322
    Rep Power
    56

    Default

    Neat!

    I don't know any basic, but maybe it's time I gave it a shot! I just downloaded it and was able to compile one of the test programs. I also was able to run it just fine in linux using wine, if anyone is interested.
    Modded consoles:
    Master System (v7040) with s-video & direct AV out
    Model 1 with 10mhz overclock & halt switches
    Model 1 with 10mhz 68010
    Model 2 VA2.3 with unfiltered Mega Amp, & s-video
    Model 3 VA1 with compatibility fixes & s-video
    32X with s-video
    Visit my web site at www.mode5.net
    Or my collection of homebrew Genesis games, programs, and music on SEGA-16!

  14. #14
    ding-doaw Raging in the Streets tomaitheous's Avatar
    Join Date
    Sep 2007
    Location
    Sonoran Desert
    Age
    42
    Posts
    3,981
    Rep Power
    75

    Default

    So.. this is BASIC compiled to the native processor? No interpreter running on the 68k side? Does BEX also compile to native 68k instructions?

  15. #15
    Wildside Expert dra600n's Avatar
    Join Date
    Jan 2011
    Posts
    208
    Rep Power
    21

    Default

    Quote Originally Posted by ComradeOj View Post
    Neat!

    I don't know any basic, but maybe it's time I gave it a shot! I just downloaded it and was able to compile one of the test programs. I also was able to run it just fine in linux using wine, if anyone is interested.
    Awesome! Another member on the BEX forums also confirmed it worked well on Linux using WINE If you have any questions, feel free to ask for help

    Quote Originally Posted by tomaitheous View Post
    So.. this is BASIC compiled to the native processor? No interpreter running on the 68k side? Does BEX also compile to native 68k instructions?
    Correct to both. BEX translates the BASIC code to ASM, so no interpreter is running on the 68k or z80, and Second Basic pretty much does the identical thing using BEX's ASM library, with some modifications and fixes. For instance, in BEX, the INCLUDE command is broken and doesn't work at all (I'm assuming the parser confuses it with the ASM command?), as well as many other serious bugs that won't get fixed in BEX (author seems to have abandoned the project) that causes the compiler to crash, and in a few instances, won't compile the ASM source.

    I've also added some really cool features that will be in the next update One of them is loading a tile from a variable (something that would've been useful in a lot of situations).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •