Not a C64 emulator but its alive

Blitz3D Forums/Blitz3D Programming/Not a C64 emulator but its alive

Jimmy(Posted 2011) [#1]
This is not a ready thing, But its alive. Its old material that I have been tinkering with now and then.
I never had the time to finish it, so I'm offering it to everyone here that would happily do some tinkering.

Actually, it's alive and kicking if you feed it full C64 ROM, and working something is just not right with the graphics, probably some number that doesn't get right, nothing else.

You could get the ROM from any C64 emulator they are BASIC.ROM, CHAR.ROM, KERNAL.ROM, a total of 20KB.

For your pleasure I included that below.
Maybe you've entered data statements into a Commodore, but have you ever seen the actual Commodore in data statements? there it is!

Okay, I leave this as it is and hope someone fins it amusing or practical.
The credits should go to whatever secret author is.

UPDATED CREDITS GOES TO
- Marc Dendooven made tutorials and Pascal version
- Blitz conversion and optimizations by moi, yours truly.
- Debugged by Lee Davison and Danny Olsson.

EDIT the C64 did not fit even a single post so you have to find the ROMS, but they are not hard to come around. If you need them just tell me and I could try chop them up or something.
EDIT and so I did manage chopping it up! i am happy. And I hope you are too.
UPDATE keyboard is setup, exit using right mousebutton. Also added correct palette.
UPDATE Went thru code, debugged some bugs, also one should not mess with val to get graphicals into characters instead graphicals are actually an effect of a bug that are still in there somewhere and will correct itself wen the bug does.

EDIT Will upload to CartAdore's offical webpage as soon as possible, together with other materials that goes with it.

I would love seeing a online Monkey version in the future.



Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011


Jimmy(Posted 2011) [#2]
ROM below if you need it

Last edited 2011


Jimmy(Posted 2011) [#3]
C64 Rom is homongous, It did not fit one post I want it here for completeness.



[tiny]Last


Jimmy(Posted 2011) [#4]
Continued.. I do it this way, 3 way post, hope noone would mind this , merge this with the above post to get full code building the roms.


Last edited 2011


Rroff(Posted 2011) [#5]
Scary and cool.

Unless I'm doing something wrong tho it just gets stuck in an infinite loop upon starting and never responds to input.

EDIT: Seems to be missing something elementary in the main loop? its locking the graphics buffer but never rendering/flipping - guessing I'm probably misunderstanding how to use it.

Last edited 2011


Hotshot2005(Posted 2011) [#6]
Bloody Hell! It remind of old c64 basic back then when you did all the data!


Jimmy(Posted 2011) [#7]
@Rroff I tried doing a backbuffer version adding a setbuffer backbuffer() after graphics, and then replacing vwait with flip but then I got the black screen instead, so I don't know why drivers give such different actions. It has no magic though, it's simply a main loop wich could be working with or without buffers as you please to make it. Small differences in drivers and graphcis such as this in Windows confuses me to be honest. You tried left mousebutton right? the actual keyboard isnt implemented.

@Hotshot2005 sexy isn't it, I'm just happy I could get the data created automatically this time, back in the days one was not so lucky.

Last edited 2011


Warner(Posted 2011) [#8]
It might have to do with LockBuffer/UnlockBuffer.
If you add SetBuffer Backbuffer(), then replace VWait with:
UnlockBuffer():Flip:LockBuffer()
the black screen now shows a bunch of C64 characters. That looks nice, but I wasn't able to do much except typing backslashes.

Edit: basic typing can be achieved by adding this line:
kb%=GetKey() If kb Then poke($0277+buff,kb):Poke($C6,buff+1)

to the 'addkey' function.
Edit: I had to add:
val=val - 64
To the "victext" function to see any readable text.

Last edited 2011


Jimmy(Posted 2011) [#9]
OUT OF MEMORY here and there haha that brings back memories if anything. I wonder though why the numbers did not come with the letters.
The PET ASCII map might differ more than I can remember. Noticebly it has some bug, but not one serious enough to not allow it to live well
enough to run ROM. I wished I'd put more time onto this one. Good to see it in the right hands!

Last edited 2011


Matthew Smith(Posted 2011) [#10]
Just for someone else, I just added the Lock/Unlock to the vicText function:

Function vicText(pos,val)
val = val - 64
LockBuffer()
x0=(pos Mod 40)*8 : y0=Int((pos / 40))*8
For xxx=0 To 7 : For yyy=0 To 7
colour=32768 : If (vicPeek($1000+val*8+yyy) And ($80 Shr xxx)) Then colour = 65535
WritePixelFast (x0+xxx) Shl 1,(y0+yyy) Shl 1,colour ; one way doing rasterizing
WritePixelFast 1+(x0+xxx) Shl 1,(y0+yyy) Shl 1,colour ; with abit retro feeling
Next : Next
UnlockBuffer()
End Function


This is pretty cool! would be great to see some more done to this. Yeah on Monkey would be interesting, but not sure how you would write to the image buffer as there is no command like WritePixelFast currently.

Last edited 2011


Danny(Posted 2011) [#11]
WOW - that's so cool to see this code - I never thought it was so (relatively) simple! :) Thanks for posting this!

No wonder that back in them days you were able to actually KNOW every single byte inside your C64 and know what it is, does and works.. ah.. them days...

D.

Last edited 2011


Rroff(Posted 2011) [#12]
@Jimmy - granted I don't really know what I'm doing with it but all I get is a black screen, left mouse button appears to do nothing but right mouse does quit, but the program behaves like its stuck in an infinite loop.

EDIT: Changing the code for UnlockBuffer():Flip:LockBuffer() and using setbuffer does give a bunch of characters and left mouse enters \.

Last edited 2011


Jimmy(Posted 2011) [#13]
@Danny glad you enjoy it, yes many things are relatively simple. But it's complex enought to have a bug still in it, but probably just a single number or so missed, some instruction turned backwards, nothing else. God I've tried fix it before posting this week but failing beeing code-blind at the moment I hope someone else have the time to work it out.

@Rroff Sounds you got it all right, that's the state of it, Adding Matthews changes wil make you able to type any lette not just my backslash mousetest. But that will also kill showing the cursor alive and well (it's still there but the ASCII gets mushed up somehow, try +64 instead of -64 and you get reversed letters plus the cursor). Something is wrong either way but I prefer seeing the blinking cursor so you see it's alive and running.


I also wanted to mention all bufferchanges proposed did not work for me personally, they flicker or they gave a black screen, so I understand there's no general solution for doing graphics on windows. Therefore I'll leave the graphics asis for now.


Adam Novagen(Posted 2011) [#14]
Since no one else has mentioned it yet: instead of using {code} tags, use {codebox} tags for massive submissions like that. It saves the pages and pages of downward scrolling for people reading the post. ;D


Rroff(Posted 2011) [#15]
Shame it doesn't mention that just below the text input box and above the post button - I can never remember which tags to use for a code box (and forget the functionality exists) - tho I probably will now I've made this post.

Last edited 2011


Jimmy(Posted 2011) [#16]
UPDATED!
Got time this evening coding and did some first discoveries on what could be the bug, PEEK, POKE and LO have illegal values at times. Need to trace this backwards to find why this is.

Sourcecode now includes keyboard changes proposed, if you get blackscreen use suggestions above and it should work. Also boxed sourcecode. It's also shorter after cleaning up. Added some tests in the search for bug. It's all there.

Also did some checks and the sparse rasterization used now for graphics has potential to be full original speed on a very very lowend machine. Both fullscreen and windowed.

Very nice.

Last edited 2011


Jimmy(Posted 2011) [#17]
And so Lee got his hands on it and found the bug after a years of miseray this emu deserves to live! :)

Screenshot here
http://postimage.org/image/1a9z20r7o/

I also finally checked the original Pascal source author , Ed64 ( Marc Dendooven )

Blitz conversion by me Jimmy, and finally but not least bugs fixed by Lee Davison and Danny Olsson!
Check out Lees webpage at http://www.themotionstore.com/leeedavison/6502/blitzc64/index.html
And also the 6502 forum
http://forum.6502.org/viewtopic.php?t=1855

It's clean but still abit plump and now is the time for cleaning things up, and optimizing what works.
Adding any things that would make it into a true emulator if wanted, it's still a 6502 emulator though, and VIC TEXTMODE without colourmap is the graphics as of now
you may get smooth update on a low end system, fullscreen or windowed as mentioned earlier.

A good beginning. And wonderful way learning about emulation. Proabablt something for the archives later.

Note that Right now you have to hold shift to get letters, this is all easy to fix later on.
BASICs finally works though, literally :)

UPDATED the bugfixes needed! (By Lee)
CMP, CPX, CPY, ADC, SBC and BIT as well as adding PHP and PLP as functions to handle the break flag properly.
Removed the unnecessary code for negative values and broke the very long multi statement lines into multiple lines with comments.
I made sure that values that were smaller than 32 bit, which is all of them, were masked whenever they were changed and that, as much as possible, it was done the same way every time.

Sorry for any misspellings, these happens during bad long nights without sleep trying find bugs :s They will be corrected after a good night sleep!
Make that a good weeks sleep. ;)



Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011


Jimmy(Posted 2011) [#18]
All along I've tried to keep things very small and readable.
I add comments very scarcley and only when needed. And that "needed" seem to never pop up when it comes to me, the less the better in a way haha, and Lee reminded me of the importance of comments.

Because this code DOES use alot of weird things, and I've tried keep things minimal to make it a great tutorial and emulator "base" kind of thing.

PS The state it is now should not be considered final in any way, but a good start.
This would not be possible without Marc Dendooven and his great spirit and tutorials.

It has no official webpage yet available to the public but I will upload it to the Blitz archives as soon as possible to CartAdore's webpage as soon as possible. I want to save one version to respect Lee and also make a denser yet readable version. My goal 3 years ago was to have an eyes view base for a crude C64 emulator to learn from. Only a few printed papers worth of code.
yet not end up as cryptic the slightest. On the contrary.

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011


Matthew Smith(Posted 2011) [#19]
Nice! Well done! Will take a look once the kids are in bed...


Jimmy(Posted 2011) [#20]
I post same here as to the 6502 forum people,

When I have a good month I will certainly try make an effort (this happens alot as I'm not feeling too good in periods of my life because of sickness).

Wiil upload latest versions to its webpage later on as fits (For example Peter's version and mine is screen compact version for visually impaired). Similiar to the one you got to see one version of.

I see many ppl already starts making use of the tiny emulator, doing online versions etc. Very nice.
This was the very intention, very happy about the results.

Got some ideas how to push the envelope further, but right now I really have to stay laidback to not get worse. Will post here when further progress happens for sure.

I want to personally want to say thankyou one would not know how much work I put down into that little emu.
My sickness is literally worse because of it. Stupid move of me trying to hard.

For the ones who loves the Commodore or just retro and want a breeze of nostalgia
you may check these out, very nice reading.

http://www.commodore128.org/Library/index.php?path=Commodore+64+Books/

Best wishes!
/Jay


Matty(Posted 2011) [#21]
I've not really used a C64 before but when I run this I get all sorts of gibberish characters on the screen when I type...like a whole range of unusual ascii characters....


Matthew Smith(Posted 2011) [#22]
Matty,

The characters shown are the built-in ASCII characters used in Commodore machines. The keys still need further translations. I think if you hold down shift you get the current upper-case char.

Jimmy - thanks for the references. My computer life started on Compute! and C+VG mags with code listings back in the early eighties! Ah the memories of typing into the MLX? editor, page after page of hex codes!!


bashc(Posted 2011) [#23]
I have tested your c64 code Jimmy and it goes for a good way.

My progamning level is not enough to understand your code.
But I love emulators and I use sometimes becouse they makes feel better and relax.

My first computer was an Amstrad cpc 6128 and for this reason it is special for me, but I have had some c64, Msx, Atari ST, etc. which thwere used for me in the past.

Now, those are some broken or in a dark room hehe. It is more easy to try emulators:)

I congratulate you!

Last edited 2011