Author Topic: PS2 Yabasic reimplemented in JavaScript  (Read 35260 times)

0 Members and 1 Guest are viewing this topic.

Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
    Wotcher folks!

http://www.mrdictionary.net/yabasic/

I've reimplemented the PS2 Yabasic environment in JavaScript.

Tokeniser, parser, lexer, compiler and runtime all written from the ground up. Uses HTML5 canvas, but has a super special (terrible) low-level graphics engine with all the commands written from scratch, so there's no horrible HTML5 antialiased lines ruining your nice demos. The graphics pane is 640x512, so everything should look as good as it can. You'll need a fairly beefy computer to run this. Doesn't require WebGL.

It's more accurate than the Win32 one in some respects, and less accurate than others. Text alignment works in mine, doesn't in Win32, so games/xalthorn/gemocide.txt's tips screen looks better on mine.

It doesn't play very nice with programs that draw to the active display buffer, as it uses double buffering by default. You shouldn't be doing that anyway, right? :)

The menu on the left contains all the sample programs from the yabfiles.zip archive on the YABASIC Source Code Resource Page ( http://members.iinet.net.au/~jimshaw/Yabasic/yabres/yabres.html ), as well as a couple of special guest programs by fizzer of TITAN. You can click any of them to magically AJAXily load them into the editor. Alternatively, the Open and Save buttons let you load/save .txt files from your local computer.

Runs best in Chrome-based browsers.

Things it does do:
  • Keyboard input pretending to be port0 PS2 pad.
  • Run pretty much everything!
  • It compiles complex expressions containing only constants and non-symbol-table-interacting-functions into single values!
  • INKEY$ works, but it returns a strange tangle of the controller mapped onto the keyboard as well as the 'character you would have typed' behaviour of the USB keyboard.
  • Has that weird behaviour where PI and EULER are treated as predefined constants until you over-assign them and then they take on your values.
  • INPUT and INPUT$ are in, and have the strange behaviour where they store up a buffer of characters and eat them up on each variable request. So if you have INPUT a$,b$ : INPUT c,d$,e$ and type in "I want 3 cats please" on the first prompt, the variables all land in their correct places without any further prompts.
  • BEEP (only if you put ?beep in the query string)
  • By complete coincidence, both my MJSYabasic and the original Yabasic sources both compile the program to a weird and compact stack machine representation. You can see a printable ASMlike representation of your program with the Disassemble program, just for kicks. (This is for debugging if you're feeling bonkers. I intended it to allow you to copy and paste it into a separate runtime, so you can use my opcode splatter as input to your own Yabasic runtime outside of JS. (If you're mad.))

Things it doesn't do:
  • Scoped arrays. All arrays are global.
  • Work in the PS3 built-in NetFront browser. BOO! It probably works in any newish Chromium or Firefox in OtherOS, but I don't own a PS3 to see.
  • There aren't any key bindings for port1. Sorry, player two.
  • No HTML5 Gamepad API. I could put it in, but all pads are different (don't believe Ondore's/MDNs lies), so it means making a button selection/calibration screen and all the rest.
  • I don't know if real Yabasic lets you have array references in your own SUBs, but in my one you can't. The only two Yabasic library functions that use array references are TOKEN and SPLIT, which are implemented in my page as special cases of the expression system. This means that apps/xalthorn/clock.txt works!
  • The text slicing functions are not leftvalues. Only one program, games/peterstock/ps2tris.txt, does this, to assign to RIGHT$("Player x", 1) = str$(playerno) to replace the x with the player number. A whole load of work for something you shouldnae be doing, so I didn't implement it. The version of ps2tris.txt in my samples pane is modified to use "Player " + str$(playerno) instead.
  • INPUT and PRINT are lousy. I've found that most existing programs only used those for debugging anyway. Stick to PRINT [single argument] for best results.
  • INKEY$, INKEY$() and INKEY$(n) all return "" instantly, because I haven't done that yet.
  • FOR loops assume that the step and limit values are constant. I've just found a program which DOESN'T assume that, which is a bugger. (for x = 1 to 32 step x : print x : next x should print ascending powers of two, but mine doesn't yet) Fixed the FOR loops so that their starting value, limit and step are always evaluated every loop (even though obviously the start value isn't used). This fixes http://www.dbfinteractive.com/forum/index.php?topic=5944.0

Most modern tablets and phones will run the page wonderfully, but there's the problem of requiring a keyboard for input. You can focus the textbox to bring it up, but aaah, yeah. Bluetooth ones might work! Haven't got one to try.

ESC/CTRL/RETURN/SPACE/[END Yabasic command] exits the fullscreen view.

Pass on the word to Parabellum, Doc, Jimshaw, Xalthorn, Shockwave and all the rest of the Yabasic gang for a nostalgia rush!

Cheers
- MrD

yabasic@mrdic [...] .net[/list]
« Last Edit: June 07, 2015 by MrD »

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #1 on: May 31, 2015 »
WOW! This sounds great! I'll have to try this out.

If it supports GTriangles without too much slowdown, I'll be able to improve my glowb program.
You are our 9001st visitor.
Challenge Trophies Won:

Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #2 on: May 31, 2015 »
Thanks for the warm welcome :)

If you find a program that doesn't work, let me know and I'll try to kick my page into shape.

Now supports dots in identifier names (SERIOUSLY? dots in identifiers, but no objects. what.) so now Tetra Card Game ( http://www.dbfinteractive.com/forum/index.php?topic=2388.0 ) runs. :)

Now supports numeric RESTORE labels, so the triangle game by Tappi ( http://www.dbfinteractive.com/forum/index.php?topic=1284.0 ) works.
« Last Edit: May 31, 2015 by MrD »

Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #3 on: May 31, 2015 »
I think in rain_storms raycaster http://www.dbfinteractive.com/forum/index.php?topic=1163.0 there are some labels which are supposed to be subroutine-local (the labels 01 and 02 are used in two different situations), but I don't acknowledge duplicate labels in my version.

If you take out the label problem (replace with other labels) and inkey$, rain_storms raycaster works!

This also revealed that I had a serious oversight where all arrays were forced local scope instead of forced global scope, oops. All arrays are supposed to be global in my version.

Becauase JavaScript needs to return fully to update the user interface, here's something you might find interesting:

I need to fully return from everything and schedule another function in order to pretend to be constantly running. For double buffered programs, I can return fully when a setdispbuf changes the visible screen (you'd want that aligned with the vblank so that's great). I can't do that for programs which don't use the double buffers, so I've had to make a decision to abort after N opcodes or M drawing operations (this is quite a small number). This means that demos/balroq/cavefly.txt now has an extra cool looking sequence where the first frame is drawn a triangle at a time, due to it not setting the draw and disp buffers apart until the end of the first frame. :)
« Last Edit: May 31, 2015 by MrD »

Offline Yaloopy

  • Death From Above
  • DBF Aficionado
  • ******
  • Posts: 2876
  • Karma: 35
    • View Profile
    • UltraPaste
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #4 on: June 01, 2015 »
Matt you are a legend. This is beyond cool.

Love the whole thing but especially that you can load up all of the files from Jim's archive.

It is 2AM right now but this is amazing and I'll be playing some of the old games (Shockwave's Tank Zone is 13 years old!) all week.
Fuck L. Ron Hubbard and fuck all his clones.
Challenge Trophies Won:

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1217
  • Karma: 230
    • View Profile
    • Homepage
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #5 on: June 01, 2015 »
Wow, awesome work, MrD!
 K+ :cheers:

I watched a number of demo's from shockwave, jim and xalthorn, excellent stuff!  :clap:
I'm going to take a look at tank zone now. :)
« Last Edit: June 01, 2015 by Kirl »
www.kirl.nl
Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #6 on: June 02, 2015 »
WOW What a Amazing Work you have done  :clap:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #7 on: June 02, 2015 »
Now supports dots in identifier names (SERIOUSLY? dots in identifiers, but no objects. what.) so now Tetra Card Game ( http://www.dbfinteractive.com/forum/index.php?topic=2388.0 ) runs. :)
Haha, that's my dot notation. How embarrassing. That was done long ago - and it was done with no real intention of ever being objects (obviously), I just liked the look of it (call my ignorance).

As to the JS compiler - holy! Great work. That's intense to get it working in a browser. Runs quite smoothly in Firefox 38.0.1 on my PC.
Karma+
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #8 on: June 02, 2015 »
That was a poke at Yabasic, not you. :) I'm just surprised that it treats the character as if it were any other character, like an underscore. You're the only person to have tried it!

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #9 on: June 02, 2015 »
A mighty welcome, and wow!!

welldone!! :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #10 on: June 03, 2015 »
I just updated the online version to remove runtime arity awareness.

Up until now, every time any EVAL ran (any Yabasic command or symbolic maths operation), it would check the arity of the call (stored in the opcode) to make sure you were calling it right. But now that's the compiler's job, and there's one less parameter flying around every single tick. Yay.


Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #11 on: June 04, 2015 »
Fixed some bugs. Made the editor visible in IE. Added an optional compatibility mode that forces all 'visible buffer' draws to flush to screen immediately instead of waiting for 20 writes.

This means that games that draw static screens to the visible buffer than enter a loop to draw their title screen will work instead of showing a black screen (games/doctor/... does this a lot). It'll slow down any graphical effects that draw to visible (Paccy's loading screen will be horribly slow as it'll wait vblank for every one of the 400 1-pixel-wide lines it draws as part of its progress bars.) but at least everything works now!

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17407
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #12 on: June 05, 2015 »
Sounds like I have something to do when I get home from work tonight! 😊
Shockwave ^ Codigos
Challenge Trophies Won:

Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #13 on: June 05, 2015 »
I've got the syntax for the INKEY$ call down now. It's really a function call that happens to have three different ways of invocation: INKEY$ without brackets waits indefinitely for key, INKEY$() same, INKEY$(n) has a timeout of n before returning "". But all three handle -held- keys a little differently. Which is nice. I don't think any other Yabasic returny-type function can be invoked without brackets. I've treated TIME$ and DATE$ as special cases of missing variables like PI and EULER so they can be over-assigned (for whatever crazy reason you want to do that for). It doesn't seem accurate, come to think of it, but the over-assigning behaviour I already had works, so there's no reason to make TIME$ and DATE$ functionlike keywords instead of magic variables now.

Making the big array of 200 values for unshifted and shifted INKEY$ values is a job for another time.
« Last Edit: June 05, 2015 by MrD »

Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #14 on: June 06, 2015 »
Fine. INKEY$ is done!

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17407
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #15 on: June 06, 2015 »
I've had an evening of pure fun with this and in some respects I think that the emulator has actually improved the way that some of the more intensive programs run, I especially enjoyed watching Fryer's stuff running at 50fps and tankzone in full frame rate, I never thought I'd see the day :)

Thanks for this emulator!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #16 on: June 07, 2015 »
You're welcome. :P

Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #17 on: June 07, 2015 »
INPUT is in, which makes demos/jinx/prismdmo.txt work!

I think that about wraps it up for Yabasic. :)

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #18 on: June 08, 2015 »
I don't know if any of the yabasic versions did this, but how about being able to play music / sound effects?

btw, the rafryer/fastz.txt demo doesn't run.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline MrD

  • C= 64
  • **
  • Posts: 31
  • Karma: 8
    • View Profile
Re: PS2 Yabasic reimplemented in JavaScript
« Reply #19 on: June 08, 2015 »
Quote
btw, the rafryer/fastz.txt demo doesn't run.
Yes, it does.