Jump to content




The early stages of my Computercraft emulator


24 replies to this topic

#1 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 30 August 2016 - 01:22 AM



Currently it cannot read keys through the screen, not all APIs are implemented, and it doesn't use the CC font due to a bug (and if you think you know how to fix it, the associated code (and the place i prefer your solution) is here)
It's basically just a lua output window.

Should i put it on GitHub or is it too early yet?

#2 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 30 August 2016 - 02:40 AM

Posted Image


This error is produced from the computercraft's own bios.lua.
Making progress!

#3 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 30 August 2016 - 08:48 AM

The emulator now has a GitHub page: https://github.com/Admicos/CCPY
If you want to help, go right there!

#4 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 30 August 2016 - 10:15 AM

Posted Image
This error happens at rom/apis/colours Line 3 and is the only error currently blocking progress. It thinks colors is a "userdata" when it's a table. Any help appriciated

EDIT: Also a error at rom/apis/term line 45, but that's due to how native is (NOT) implemented. A fix for that would be appriciated too..

Edited by Admicos, 30 August 2016 - 10:20 AM.


#5 CrazedProgrammer

  • Members
  • 484 posts
  • LocationWageningen, The Netherlands

Posted 31 August 2016 - 08:34 AM

Are you sure you're passing a Lua table and not a custom wrapper object?

#6 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 31 August 2016 - 08:36 AM

View PostCrazedProgrammer, on 31 August 2016 - 08:34 AM, said:

Are you sure you're passing a Lua table and not a custom wrapper object?

I AM actually passing a custom class, why didn't i think of remaking it in Lua. (sighs)

I guess programming without sleep REALLY doesn't work.

EDIT: That actually worked!

Edited by Admicos, 31 August 2016 - 08:47 AM.


#7 CrazedProgrammer

  • Members
  • 484 posts
  • LocationWageningen, The Netherlands

Posted 31 August 2016 - 11:41 PM

No problem, glad I could help!

#8 CompuTech

  • Members
  • 262 posts
  • LocationNowhere, somewhere, and everywhere.

Posted 01 September 2016 - 05:49 AM

I love CC emulators, I'm excited to see how yours does!

#9 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 01 September 2016 - 07:58 AM

I think i fixed the term.native error, but i am now stuck with "attempt to yield across C-Call boundary" which i have absolutely no idea how to fix.

EDIT: It might be due to a function that isn't implemented as bios.lua 178 (where the error probably happens) is os.pullEventRaw, which isn't implemented.
EDIT 2: Confirmed, as implementing it will change the error.
EDIT 3: Getting the same error again. os.pullEventRaw is implemented(-ish as the filter currently doesn't work)
EDIT 4: There are a error i couldn't see. Let's see what it is
EDIT 6: It seems like it can't iterate over "native" in the term API. I think i know why though
EDIT 7: Does someone know how to send Python classes in Lua as modifiable, because i think that's the issue (probably not, and it's probably modifiable by default.)

Edited by Admicos, 01 September 2016 - 08:30 AM.


#10 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 6,574 posts
  • LocationTasmania (AU)

Posted 02 September 2016 - 05:19 AM

As an educated guess, it sounds like you're trying to run bios.lua directly, as opposed to running it within a Lua coroutine. CC sticks it within one so that the one VM can run one copy for each active system in the world - your emulator will presumably only handle one system at a time, but bios.lua expects to be running within a coroutine regardless.

In psuedocode (you may not even be using Lua for this directly):

local myCoroutine = coroutine.create(loadfile("bios.lua"))
local ok, requestedEvent = coroutine.resume(myCoroutine)

while coroutine.status(myCoroutine) ~= "dead" do
        -- Generate an event, put its parameters into a table called eg "myEvent".
        -- If you have nothing to generate an event with (eg the user hasn't typed anything, no timers have expired, yadda yadda,
        --    ... then pause here until you do.

        if not requestedEvent or requestedEvent == myEvent[1] then
        	ok, requestedEvent = coroutine.resume(myCoroutine, unpack(myEvent))
        end
end

-- End emulation, system has stopped.

Assuming you're already familiar with coroutines, it may still be worth reading chapter four onwards of this. If it doesn't make sense, then you may instead be better off reading the whole thing.

#11 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 02 September 2016 - 07:38 AM

View PostBomb Bloke, on 02 September 2016 - 05:19 AM, said:

As an educated guess, it sounds like you're trying to run bios.lua directly, as opposed to running it within a Lua coroutine. CC sticks it within one so that the one VM can run one copy for each active system in the world - your emulator will presumably only handle one system at a time, but bios.lua expects to be running within a coroutine regardless.

In psuedocode (you may not even be using Lua for this directly):

local myCoroutine = coroutine.create(loadfile("bios.lua"))
local ok, requestedEvent = coroutine.resume(myCoroutine)

while coroutine.status(myCoroutine) ~= "dead" do
		-- Generate an event, put its parameters into a table called eg "myEvent".
		-- If you have nothing to generate an event with (eg the user hasn't typed anything, no timers have expired, yadda yadda,
		--	... then pause here until you do.

		if not requestedEvent or requestedEvent == myEvent[1] then
			ok, requestedEvent = coroutine.resume(myCoroutine, unpack(myEvent))
		end
end

-- End emulation, system has stopped.

Assuming you're already familiar with coroutines, it may still be worth reading chapter four onwards of this. If it doesn't make sense, then you may instead be better off reading the whole thing.

Thanks for the info.

EDIT: If my memory is correct, then this just fixed a error, i think. (there is still one though, i think i have an idea)

Edited by Admicos, 02 September 2016 - 08:03 AM.


#12 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 02 September 2016 - 08:26 AM

I can (posssibly) run the shell now as the error suggests that it tries to open the shell.

Now let's tune the fs api a bit and try now.

#13 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 02 September 2016 - 09:46 AM

guys?
Posted Image


Make a filler RS api and possibly no errors!

EDIT: No errors on the shell, yay! Now let's try events.
EDIT 2: Events are now causing the c-call boundary error, i'm gonna try some more stuff.
EDIT 3: Also, the events don't register either. Let me try a different method.
EDIT 4: Events now register properly, now let't try the cc part.
EDIT 5: I made the events all in Lua, to hopefully be more compatible. But still no CC reaction.
EDIT 6: I just saw that bios.lua implements its own pullEventRaw that is just a coroutine.yield. *facepalming intensifies*

Edited by Admicos, 02 September 2016 - 03:32 PM.


#14 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 04 September 2016 - 03:33 PM



I think i just got a modified bios to get the events, but they are all nil, gotta figure this out.

Edited by Admicos, 04 September 2016 - 03:42 PM.


#15 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 6,574 posts
  • LocationTasmania (AU)

Posted 05 September 2016 - 01:00 AM

My experience with Python is minimal, but if I'm reading things correctly, your code may incorrectly resume the computer's coroutine here - this "update" method gets called every time the loop here notices an event, but not every event pygame.event.wait() collects is added to the CC system's queue.

You should not resume CC's coroutine if you have no relevant events to pass in, and you should furthermore discard any events which mismatch a set event filter (other than "terminate").

#16 ashnwill

  • Members
  • 5 posts

Posted 09 October 2016 - 04:09 AM

I don't know if you're still working on this, but the computercraft font has all the letters centered in their little rectangle in the terminal's grid rather than leaning to the left

#17 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 09 October 2016 - 03:20 PM

View Postashnwill, on 09 October 2016 - 04:09 AM, said:

I don't know if you're still working on this, but the computercraft font has all the letters centered in their little rectangle in the terminal's grid rather than leaning to the left
i know and i'm trying to fix it, and i kind of stopped it for a month or so, will try to make it work once github gets unblocked :(

#18 EldidiStroyrr

  • Members
  • 946 posts
  • LocationPot Land

Posted 20 October 2016 - 11:47 AM

View PostAdmicos, on 09 October 2016 - 03:20 PM, said:

i know and i'm trying to fix it, and i kind of stopped it for a month or so, will try to make it work once github gets unblocked :(

Damn, man. It must be a horrible time to live in Turkey, huh? Can you access the Tor project?

#19 Admicos

  • Members
  • 197 posts
  • LocationTurkey

Posted 20 October 2016 - 04:36 PM

View PostEldidiStroyrr, on 20 October 2016 - 11:47 AM, said:

View PostAdmicos, on 09 October 2016 - 03:20 PM, said:

i know and i'm trying to fix it, and i kind of stopped it for a month or so, will try to make it work once github gets unblocked :(

Damn, man. It must be a horrible time to live in Turkey, huh? Can you access the Tor project?

It's unblocked already and yes i can access Tor.

#20 Piorjade

  • Members
  • 231 posts
  • LocationComputer, Germany

Posted 21 October 2016 - 07:08 PM

Will we be able to use custom CC versions with this?
Or does it implement CC?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users