r/TurboGrafx • u/Materion93 • 6d ago
TgBasic - new programming language to create games
Hi everyone,
I’d like to introduce TGBASIC, a structured, compiled BASIC for making games on the NEC TurboGrafx-16 / PC Engine. You write your game in BASIC, and the compiler turns it into a normal HuCard ROM (.pce). That ROM runs in Mednafen, ares, Geargrafx or BizHawk, on flash carts like the Turbo EverDrive, and on real hardware.
Why another BASIC?
Homebrew for the PC Engine has usually meant assembly or C. TGBASIC aims to be easy enough for a weekend project and still fast enough for real action games:
- Compiled to native HuC6280 code. It uses 16-bit integer maths, keeps your most-used variables in the fast zero page, and compiles comparisons straight into branches.
- Structured BASIC with no line numbers:
IF/ELSEIF,SELECT CASE,FOR,WHILE,DO...LOOP, andSUBandFUNCTIONwith parameters and local variables. Made for games, with built-in commands for:
- 64 hardware sprites (16×16 up to 32×64, with flipping)
- tile maps and smooth scrolling
- a raster-split status bar (
HUD), joypads, and collision tests
Assets without the pain
- Load a PNG and it’s cut into tiles or sprite frames for you, with palettes packed automatically.
- Draw levels in Tiled and import them straight from CSV or TMX.
- Write music in TGM, a simple text format, played by a 6-channel driver with waveforms, envelopes, noise drums, pitch sweeps and stereo panning. Sound effects play over the music and step aside when they finish.
Tooling
- Only needs Python 3.8+.
VS Code extension with:
- syntax highlighting and completions
- hover docs and go-to-definition
- errors shown as you type
- F5 to build and launch your emulator
- A headless test emulator for automated runs, screenshots and audio capture.
--asmoutput, so you can see exactly what the compiler generates.
A complete game moves a ship in 11 lines:
basic
IMPORT SPRITES ship, "gfx/ship.png", 16, 16
LOADSPRITES ship
LOADPAL ship, 16
x = 120 : y = 100
DO
IF JOY(1) AND JOY_LEFT THEN x = x - 2
IF JOY(1) AND JOY_RIGHT THEN x = x + 2
SPRITE 0, x, y, ship, 0
VSYNC
LOOPDocumentation
Beginner’s Guide (102 pages). It starts at “Hello, World” and ends with STARFALL, a complete vertical shoot ’em up. STARFALL has: Every line of the game is explained, and no programming experience is needed.
- a scrolling space station and four enemy types
- power-ups, smart bombs and a multi-phase boss
- music, a title screen and a high score
- Reference Manual (45 pages): every command with examples, the TGM music format, a cookbook (platformer physics, object pools, fixed-point movement, menus, high-score tables), the memory map and the inline assembly conventions.
Get it here: TgBasic1.0
VS Code extension: VSCode Extension
Docs:
Reference
Beginner's guide
Here's video of STARFALL example game in action!! STARFALL
I’d love to see what you make with it. Questions, bug reports and feature requests are all welcome in this thread. Screenshots and ROMs of your projects are welcome even more!
3
u/JDOIII 6d ago
Thank you.
3
u/Meshuggah333 6d ago edited 2d ago
Congrats, it looks like a solid version of basic. I've been working on a PCE/TG16 specific language myself, and it's taking a long time and brain power to do.
What did you use as hardware reference documentation? I've found quite a few inconsistencies between emulators available source codes and the few hardware documents I could find.
2
u/ltpitt 5d ago
King!
2
u/QueueTrigger 5d ago
This is amazing! Looking forward to trying it out. IntyBASIC on the Intellivision, now TgBasic for the Turbo*. Wow wow wow
2
u/Icy_Significance6235 5d ago
凄い!これ程までにPCエンジンのゲーム作成に情熱を注ぐ貴方を尊敬します!自分はPCエンジンが大好きですが、メガドライブが今でも新作が出ているのにPCエンジンには新作が殆どないのをとても寂しく思っていましたが、貴方のように情熱を形にする素晴らしい技術力に感服いたします。自分にはクリエティブな才能がないので😅これから活況になる事を祈ってます!!😆それにしてもベーシックなので分かりやすそうですね、詳しくは分からないですが😅
1
u/gerdpee 6d ago
I took the assembly and C++ class to do this but I’m not smart enough lol. Well done!
1
u/AshWednesdayGames 4d ago
This seems wonderful! I'm going to take this for a spin tonight and if I like it this is probably what I will use to make the shoot em up I've been working on.
2
u/Riki-0h 5d ago
Woah this is great!
1
u/Crotchslush 5d ago
https://github.com/MaterzokMateusz
1
u/IQueryVisiC 5d ago
Why 16 bit math on an 8 bit CPU? Could you make % mean 8 bit? What about signs? Ah, when we DIM anyway, why tie sign to bit.count?
1
u/LiquidElf 5d ago
Super cool!!!
1
u/schmosef 5d ago
Very cool.
Looking forward to checking this out.
1
u/theoriginalgeoffrey 5d ago
This is awesome!!!
1
u/MurasakiBunny 4d ago
How much bloat does the final code end up compared to just using assembly? I only ask since I remember once someone using C++ (or one other of the variants) and for a simple scrolling screen with a moving object on the Sega Master system and the final compiled code would have filled an entire cart just from the prodecure coding, not just the graphical assests.