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
- 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:
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 :)
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.
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...
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.
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
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
[Please log in to post a comment]