Tiny C64 (old school)
-
- Posts: 1009
- Joined: Oct 11, 2008 7:42
- Location: ABQ, NM
- Contact:
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!
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!
Re: Tiny C64 (old school)
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).
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.Modified push / pull subs fix that:
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.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)
Fix 5: LSR instruction
Zero value sets N-Flag, but should not.
Fix 6: ROL instruction
Zero value sets N-Flag, but should not.
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)
(*) 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
)
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
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
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)
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)
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)
Re:
I think Run/Stop is not implemented. You have to set address $91 to $7F to simulate a pressed stop key.kiyotewolf wrote: One combo I don't know is the SHIFT-RUN/STOP for this emu.
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
Re: Tiny C64 (old school)
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.
or by decreasing or increasing(A also by adc and sbc) egg.
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
egg.
Code: Select all
ldx #$00 'load x with zero
beq label 'check if X is zero, if so jump to label
...
label:
rts
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
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
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Tiny C64 (old school)
@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
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
Re: Tiny C64 (old school)
Great emulator! C64 was my first love and will be the last...
-
- Posts: 54
- Joined: Jun 29, 2014 17:15
Re: Tiny C64 (old school)
This is insanely cool, Thanks for the upload :-)
-
- Posts: 215
- Joined: Dec 14, 2013 0:43
Re: Tiny C64 (old school)
UPDATE:
Improved readability
Added support for playing DVDs(POKE 49152,[track number]).
https://github.com/fatman2021/project-m ... c64dvd.bas
NOTE: mplayer must be installed in order to play dvds.
Improved readability
Added support for playing DVDs(POKE 49152,[track number]).
https://github.com/fatman2021/project-m ... c64dvd.bas
NOTE: mplayer must be installed in order to play dvds.
-
- Posts: 215
- Joined: Dec 14, 2013 0:43
Re: Tiny C64 (old school)
Added support for 32-bit color.
Addresses 49154 through 49157 controls the foreground color.
Addresses 49158 through 49161 controls the background color.
Addresses 49154 through 49157 controls the foreground color.
Addresses 49158 through 49161 controls the background color.
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Tiny C64 (old school)
Strange, I don't seem to recall the original C64 having DVD support...fatman2021 wrote:UPDATE:
Improved readability
Added support for playing DVDs(POKE 49152,[track number]).
https://github.com/fatman2021/project-m ... c64dvd.bas
NOTE: mplayer must be installed in order to play dvds.
-
- Posts: 215
- Joined: Dec 14, 2013 0:43
Re: Tiny C64 (old school)
I recorded this video just for you:counting_pine wrote:Strange, I don't seem to recall the original C64 having DVD support...fatman2021 wrote:UPDATE:
Improved readability
Added support for playing DVDs(POKE 49152,[track number]).
https://github.com/fatman2021/project-m ... c64dvd.bas
NOTE: mplayer must be installed in order to play dvds.
https://www.youtube.com/watch?v=jWhuCdrIc10
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Tiny C64 (old school)
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
!!! mZoom must be greater than 0 !!!
1 = original size, 2 = double ...
3 looks OK for my old eyes.
Joshy
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Tiny C64 (old school)
I added "A little bit about C64 BASIC" see first post.
Joshy
Joshy