Tiny C64 (old school)

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Tiny C64 (old school)

Post by D.J.Peters »

Image
[ESC] = quit
[F2] = load
[F3] = save

Download right click and save as: c64.bas

A little bit about the C64 BASIC

first all what you type on the C64 are in upper case
print "hello"
are
PRINT "HELLO"

In "direct mode"
BASIC commands can be typed and are directly executed after you press [enter]
command[:command][enter]

Example: show the number of free bytes for BASIC in direct mode

PRINT FRE(0)+65536[enter]

In "program mode"
BASIC commands are entered after a line number and stored in BASIC memory
number command [: command]

Example: print the numbers 1-10
10 FOR I=1 to 10
20 PRINT I
30 NEXT I


RUN[enter]

A BASIC program can be "list"ed
LIST[enter]

many commands have a shortcut
for example RUN or LIST
R[shift]+U
L[shift]+I

If your C64 BASIC program are longer than the screen
you can "list" only program lines you are looking for:

list 20
20 PRINT I


list -20
10 FOR I=1 to 10
20 PRINT I


list 20-
20 PRINT I
30 NEXT I


list 10-20
10 FOR I=1 to 10
20 PRINT I


In C64 BASIC you don't have label's or sub's
you jump from current executed line to another with:
goto linenumber

or you jump to a sub routine with:
gosub linenumber

the end of a sub routine must be marked with:
return

here are a short gosub example

10 print "line 10"
20 gosub 100
30 print "line 30"
40 end
100 print "line 100"
110 return


This mini C64 emulator I wrote in one night
has no fancy sprites or sound but you can
create fumy games with the famous Commodore font chars
the chars and colors can be poked directly in the video and color ram.

All about the C64 BASIC commands !
german:
https://www.c64-wiki.de/wiki/BASIC
english:
https://www.c64-wiki.com/wiki/BASIC

Joshy
Last edited by D.J.Peters on Oct 12, 2022 19:40, edited 16 times in total.
duke4e
Posts: 717
Joined: Dec 04, 2005 0:16
Location: Varazdin, Croatia, Europe
Contact:

Post by duke4e »

Woah, nice emulator!

Now I want to download a joystic and a bunch of casettes :P
DrewPee70
Posts: 4
Joined: Oct 01, 2007 12:25

oldschool.bas

Post by DrewPee70 »

What version of freebasic does this use? I have 0.16 . . . doesn't compile - something to do with public? Regards Drew
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: oldschool.bas

Post by anonymous1337 »

DrewPee70 wrote:What version of freebasic does this use? I have 0.16 . . . doesn't compile - something to do with public? Regards Drew
FB Dinosaur (.16)... >.>;;
DrewPee70
Posts: 4
Joined: Oct 01, 2007 12:25

Post by DrewPee70 »

Yeah I know but I had a lot of problems with 0.17 - so haven't updated yet!!! I will try the latest version and see if my old code still works?

Drew
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

Yeah, there have been a lot of features added since version 0.16, so it's not unusual now for code not to work in old compiler versions.
In version 0.18 though, there's been more effort made to provide compatibility with older programs, and the compiler offers multiple dialects - fb (the new default), deprecated (approximately compatible to version 0.16b and qb (designed to be more compatible with QBASIC). Currently, deprecated is probably the option that will best suit your code.
See this page for more details:
http://www.freebasic.net/wiki/wikka.php ... erdialects

What sort of problems have you had trying to upgrade? We're hoping to try and reduce the compatibility issues with older compiler versions.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

If any plays with the Commodore 64 BASIC i added save and load

[F2] save basic prg
[F3] load basic prg

the BASIC tokens are saved not the ASCII text

Joshy

Code: Select all

10 FOR I=0 to 999
20 POKE 55269+I,I and 15
30 NEXT
parakeet
Posts: 48
Joined: Mar 30, 2006 15:46
Location: Lille, France

totally bluffed

Post by parakeet »

Gosh, I'm totally astonished by the elegance of the code, this is by far the best code posted on these forums for a while... This is a machine I knew very well and your program covers a lot of subjects. However the rom should not be made public like this, should it ?
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

Dude that is .. AWESOME !

Is it me or it's the first real emulator coded with FB ?
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Post by v1ctor »

At first i thought it was just a C64-like interpreter, but it's actually a full emulator.. great work - i also agree that the code looks elegant :).
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Post by srvaldez »

D.J.Peters, this is amazing, but I think there may be a corrupt ROM dump or bug, try ?1/3 or ?1/9
?4/2 and ?5/2 is OK.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

Why is this in Tips & Tricks, not Projects?

Do you code like 200LOC a minute or something? D:
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

srvaldez@
Sorry must be a wrong status flag in the CPU emulation i will debug it next week

anonymous1337@
It would be an project if you will emulate the VIC, SID, PIA I+II and 1541 too
so it's only a tip how to emulate a CPU

Joshy
fabrizio
Posts: 73
Joined: Sep 29, 2006 13:39
Location: Roma, Italy

Post by fabrizio »

A really great great program!
Thanks for the code.



@Hezad: i think so, my try was uncomplete http://www.freebasic.net/forum/viewtopic.php?t=9807
Sisophon2001
Posts: 1706
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Post by Sisophon2001 »

How does it work? Are the data statements a program that loads into the emulator?

Garvan

PS. And is the BASIC language used documented some place?
Post Reply