Tiny C64 (old school)

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Postby kiyotewolf » Aug 12, 2010 4:51

I really love coding for Commodore (did for years), so being able to tinker with this, cause it's in FB source, makes me happy.

I might be able to tinker with it, so I can start to dev emulated C=64 projects now.

I hate using a Windows keyboard for the regular Commodore emulators. They use the actual key positions mapped to the old Commodore keys.

Fortunately, my fingers are trained already to Commodorian style typing.

This emulator, however, maps actual keys to actual keys on the windows keyboard.

The plus is the plus, and so on.

One combo I don't know is the SHIFT-RUN/STOP for this emu.



~Kiyote!
oog
Posts: 124
Joined: Jul 08, 2011 20:34

Re: Tiny C64 (old school)

Postby oog » Oct 14, 2017 9:13

Here are some new bugfixes.

Thanks to Joshy for his C64 / 6502 simulator.
I am actually implementing an experimental 6502 CPU for my 6502 assembler/disassembler project (https://freebasic.net/forum/viewtopic.php?f=7&t=25742).
I used Joshys CPU from this project as a reference and let it run parallel to my own 6502 implementation, because my CPU was very buggy. I checked the register content and memory write access of both simulated CPUs after every step. So I was able to detect different behaviour and bugs.
Here are the bugfixes for Joshys C64 simulator.

Fix 1 : Memory sizes
Some arrays are too small and write operations with C64 poke will cause runtime error 6 (out of bounds array access).

Code: Select all

as ubyte   mem64 (&HFFFF) ' Ram    (64K, &HFFFF instead of &HFFFE)
as ubyte   col   (&H03FF) ' color triples    (1K, &H3FF instead of &H3E7)

Fix 2 : Stackpointer overwrites zeropage
(*) A freeBASIC constructor is evil and does not what you expect!
Because of (*), the initialization of the stack pointer hi-byte fails and the stack overwrites the zeropage.

Code: Select all

(
   constructor CPU6510(lpMem as memory ptr),
   ' stack pointer
   MSB=1
)
Modified push / pull subs fix that:

Code: Select all

sub CPU6510.Push(b as ubyte)
   mem->WriteUByte(&h100 or s,b)
   s-=1
end sub
function CPU6510.PULL as ubyte
   s+=1
   return mem->ReadUbyte(&h100 or s)
end function

Fix 3: Load PC with RESET-Vector from KERNAL ROM
This is not really a bugfix, but it's nicer to load the reset vector from ROM and not from a hard-coded address in the program.

Code: Select all

constructor CPU6510(lpMem as memory ptr)
   ...
   cpu->ph=cpu->mem->ReadUbyte(&HFFFC)
   cpu->pl=cpu->mem->ReadUbyte(&HFFFD)
   (instead of PC=&HFCE2)
end constructor
I guess this will not work within a constructor because of (*). Maybe an extra "CPU-Reset" method would be a good solution.

Fix 4: BIT instruction
The Z-flag depends on A, not X register.
Without this fix it is not possible to assign a string to a variable in direct mode. (BIT - instruction at address $AD90 - Test for string or integer variable - fails)

Code: Select all

   a$="test" : ? a$     ->    Print empty string as result on Tiny C64

Code: Select all

sub INS_BIT(lpCPU as CPU6510_T)
old:   lpCPU->F.z=iif(0=(b and lpCPU->sX),1,0)
new:   lpCPU->F.z=iif(0=(b and lpCPU->sA),1,0)

Fix 5: LSR instruction
Zero value sets N-Flag, but should not.

Code: Select all

sub INS_LSR(lpCPU as CPU6510_T)
old:   lpCPU->F.n=iif(v.slo<1,1,0)
new:   lpCPU->F.n=iif(v.slo<0,1,0)
better:   lpCPU->F.n=0    ' (after shift right bit7 must be always zero)

Fix 6: ROL instruction
Zero value sets N-Flag, but should not.

Code: Select all

sub INS_ROL(lpCPU as CPU6510_T)
old:   lpCPU->F.n=iif(v.slo<1,1,0)
new:   lpCPU->F.n=iif(v.slo<0,1,0)
oog
Posts: 124
Joined: Jul 08, 2011 20:34

Re:

Postby oog » Oct 14, 2017 9:24

kiyotewolf wrote:One combo I don't know is the SHIFT-RUN/STOP for this emu.


I think Run/Stop is not implemented. You have to set address $91 to $7F to simulate a pressed stop key.

In my sim I do it like this:

Code: Select all

      k = InKey
      If k<>"" Then
        If k=Chr(9) Then   ' Tab is the Stop key
          c64.writeMem(&h91,&h7F) ' stop key flag on
        Else
          c64.writeMem(&h91,&h0) ' stop key flag off
          c64.writeMem(&h277 + c64.readMem(&hC6), a2c(k)) ' Store key into C64 keyboard buffer
          c64.writeMem(&hC6, c64.readMem(&hC6) + 1)
        EndIf
      EndIf
Haubitze
Posts: 37
Joined: May 20, 2016 8:42

Re: Tiny C64 (old school)

Postby Haubitze » Oct 15, 2017 13:27

i think the Z-Falg depends on the instruction not on the register, you can check A/X and Y reg of zero by doing this
egg.

Code: Select all

ldx #$00 'load x with zero
beq label 'check if X is zero, if so jump to label
...
label:
rts


or by decreasing or increasing(A also by adc and sbc) egg.

Code: Select all

loop: ldy #$ff 'load y with 255
   lda #$00 'load 0 to A, Z-flag set
   sta $02 ''write A to zeropage 2
        dey       'decrease y by 1, update the z flag
        bne loop 'if y not Zoro jump to loop
        rts


so you can see the Z flag are always re/set ad the programmer of the 6502/10 has to check what register is checked by check the last
instruction.

salute

ps: also the Z-Flag manupulated by the memory manipulating INC/DEC
pps: https://www.c64-wiki.de/wiki/Kategorie:Assembler-Befehl is a nice source to check the opcodes but it is in german
D.J.Peters
Posts: 7780
Joined: May 28, 2005 3:28

Re: Tiny C64 (old school)

Postby D.J.Peters » Oct 15, 2017 16:59

@oog good job

Tiny C64 isn't a project it's a result of a 24 hour coding session to show other coders
"How to emulate hardware in FreeBASIC" this is why I posted it as Tip and Tricks.
Don't accept an 100% accurate emulation posted as Tip and Tricks (never)
A more stable emulation are my Radio Shack TRS 80 MC-10 emulator, posted as a project :-)

How ever it's good if you collect your improvements here.
I'm sure other coders find this infos really useful if they interested in this kind of stuff.

Joshy
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: Tiny C64 (old school)

Postby lizard » Oct 17, 2017 11:49

Great emulator! C64 was my first love and will be the last...
Pim Scheffers
Posts: 40
Joined: Jun 29, 2014 17:15

Re: Tiny C64 (old school)

Postby Pim Scheffers » Oct 19, 2017 13:57

This is insanely cool, Thanks for the upload :-)
fatman2021
Posts: 135
Joined: Dec 14, 2013 0:43

Re: Tiny C64 (old school)

Postby fatman2021 » Mar 03, 2019 16:16

UPDATE:
Improved readability
Added support for playing DVDs(POKE 49152,[track number]).

https://github.com/fatman2021/project-manhattan/blob/master/c64dvd.bas

NOTE: mplayer must be installed in order to play dvds.
fatman2021
Posts: 135
Joined: Dec 14, 2013 0:43

Re: Tiny C64 (old school)

Postby fatman2021 » Mar 04, 2019 1:37

Added support for 32-bit color.

Addresses 49154 through 49157 controls the foreground color.
Addresses 49158 through 49161 controls the background color.

Image
counting_pine
Site Admin
Posts: 6170
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Tiny C64 (old school)

Postby counting_pine » Mar 04, 2019 14:02

fatman2021 wrote:UPDATE:
Improved readability
Added support for playing DVDs(POKE 49152,[track number]).

https://github.com/fatman2021/project-manhattan/blob/master/c64dvd.bas

NOTE: mplayer must be installed in order to play dvds.

Strange, I don't seem to recall the original C64 having DVD support...
fatman2021
Posts: 135
Joined: Dec 14, 2013 0:43

Re: Tiny C64 (old school)

Postby fatman2021 » Mar 04, 2019 17:03

counting_pine wrote:
fatman2021 wrote:UPDATE:
Improved readability
Added support for playing DVDs(POKE 49152,[track number]).

https://github.com/fatman2021/project-manhattan/blob/master/c64dvd.bas

NOTE: mplayer must be installed in order to play dvds.

Strange, I don't seem to recall the original C64 having DVD support...


I recorded this video just for you:
https://www.youtube.com/watch?v=jWhuCdrIc10
D.J.Peters
Posts: 7780
Joined: May 28, 2005 3:28

Re: Tiny C64 (old school)

Postby D.J.Peters » Jul 31, 2019 19:36

Added const as integer mZoom = 3 at top of the "c64.bas" file.

!!! mZoom must be greater than 0 !!!
1 = original size, 2 = double ...

3 looks OK for my old eyes.

Joshy
D.J.Peters
Posts: 7780
Joined: May 28, 2005 3:28

Re: Tiny C64 (old school)

Postby D.J.Peters » Aug 14, 2019 2:44

I added "A little bit about C64 BASIC" see first post.

Joshy

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 13 guests