Log In  

Hey guys,
I was playing with crazy idea in my mind again and just wanted to give it a go. I was wondering how hard it would be to create emulator for PICO8. Program that can load catridges and play them (read bbs player without bbs). Since it's all based on lua (witch I have no experience implementing) and I am really bad at bitwise operations (witch are really crucial when working with retro stuff) I decided to create one to learn something new. Here is my first attempt. Far from being good or complete and I don't know if I would ever want to finish it...but...you never know :D

Some facts:

  • written in C# .NET 4.5 profile
  • used NLua library/wrapper for code execution
  • cartridge loading from png files (anyone want .net library for this? I can create one)
  • screen is blitted to windows form directly, no graphics libraries used so it's not very fast when scaled up
  • implemented features:
    • _update/_draw methods calling
    • fully working palette manipulation (pal, palt)
    • flipping graphics from ram to vram (flip)
    • clear screen buffer (cls)
    • full implementation of basic sprite drawing (spr)
    • some mathematical functions (flr, sin, cos)

Ps: I am Windows Phone user, I don't think there will ever be official player for my mobile platform so I will maybe create my own :D

Current testing cartridge:

Cart #13732 | 2015-09-06 | Code ▽ | Embed ▽ | No License

P#13733 2015-09-05 21:53 ( Edited 2015-09-13 11:33)

awesome =) I'm doing the same thing but using love2d as a base.

implemented most stuff, but don't have png cart loading yet or sfx.

P#13735 2015-09-05 22:09 ( Edited 2015-09-06 02:09)

I can send you loading routine in C# if this can help you ;)

And yes, sfx will be hardest part I think...

P#13736 2015-09-05 22:12 ( Edited 2015-09-06 02:21)

Hey AfBu, would love to see that if you don't mind sharing!

P#14004 2015-09-11 08:30 ( Edited 2015-09-11 12:30)

Hi guys!

Wow! I am glad I found this thread :) Because I have been working on something similar too. I started making an emulator but then I thought it would be fun to make my own tool/virtual computer of something between Pico-8 and SmileBasic or Family Basic. Then I started working on a virtual computer thingy with my own limitations.

Don't get me wrong, I love Pico-8 and Zep has done a great job and I am actually working on a little game for it as well.

But I like the challenge and I really have fun with that sort of low-level programming.

Perhaps it will happen like in the 80s where we had so many different 8bit computers but this time they are virtual :)

P#14008 2015-09-11 09:41 ( Edited 2015-09-11 13:41)

Hey impbox, sorry for the delay, this week I had nearly no free time. Here is routine I am using for decoding cart's source code. No graphics decoding is done, since I am using same method of working with ram as real pico does - copying graphics from spritesheet to video-part of memory, then blitting entire video-part memory into vram and finally decoding it to rgb and displaying it.


Currently I am using NLua wrapper but I will try to rewrite it to use MoonSharp (complete port of lua to .net) so it will be easier to port it to other .net/mono supported platforms.

P#14073 2015-09-12 18:53 ( Edited 2015-09-12 22:53)

Oh and I have another question on you if you are writing emulator as well:

How are you dealing with differences of pico's flavour of lua? Like += operators, short if statements (wthout then..end) etc.?

Currenty I am parsing sourcecode by few regular expressions and replacing those shorthandy by standard lua code, but I think there must be better solution. I will take look into MoonSharp library itself and try to implement those directly into it...

P#14074 2015-09-12 18:59 ( Edited 2015-09-12 22:59)

Thanks AfBu!

I'm doing the same with the pico's lua, += and the like are easy to search and replace, likewise != for ~=.

The if shorthand however is basically impossible without implementing a full parser, but I have a search replace that handles some instances of it, but not all.

P#14093 2015-09-12 23:36 ( Edited 2015-09-13 03:36)

Correct me if I'm wrong, but are nested parentheses the issue? You could write a quick parser to just go through the first set of parentheses associated with the if (increment/decrement until depth=0), then check if the next token is "then" and if not add it and replace the next '\n' with " end\n". You could also make a regex to extract all instances of "if(" (with any spacing) as a starting point.

PICO-8 crashes if you try the shorthand syntax with a newline inside the parentheses, so it's probably using the newline and just checking if the if line contains "then", and if not then doing something similar. I think this code will crash it though:

if(a) if(b) both() --may be a syntax error
if(a and
    b) both() --definitely syntax error
P#14096 2015-09-13 00:36 ( Edited 2015-09-13 04:40)

I'm looking at nested parentheses already, that's fine.

if(a and b) foo
if(a and
 b) foo

are working correctly.

but the problem is things like:

if(a) and (b) then foo end

which could match the same pattern used for the shortcut
so it gets expanded to

if(a) then and (b) then foo end end
P#14098 2015-09-13 01:39 ( Edited 2015-09-13 05:40)

@AfBu thank you. I will add it to PicoStudio, my (.net/c#) application for modifying carts outside of pico.

P#14105 2015-09-13 07:33 ( Edited 2015-09-13 11:33)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-02-24 12:18:55 | 0.015s | Q:24