Tiny C64 (old school)

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

Tiny C64 (old school)

Postby D.J.Peters » Feb 19, 2008 9:50

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[enter]
20 PRINT I[enter]
30 NEXT I[enter]

RUN[enter]

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

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

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 Aug 14, 2019 2:43, edited 13 times in total.
duke4e
Posts: 717
Joined: Dec 04, 2005 0:16
Location: Varazdin, Croatia, Europe
Contact:

Postby duke4e » Feb 19, 2008 10:04

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

Postby DrewPee70 » Feb 19, 2008 19:50

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

Postby anonymous1337 » Feb 19, 2008 20:01

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

Postby DrewPee70 » Feb 19, 2008 20:16

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: 6219
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Feb 20, 2008 9:53

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: 8117
Joined: May 28, 2005 3:28
Contact:

Postby D.J.Peters » Feb 20, 2008 14:24

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

Postby parakeet » Feb 29, 2008 9:05

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:

Postby Hezad » Feb 29, 2008 20:32

Dude that is .. AWESOME !

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

Postby v1ctor » Mar 01, 2008 22:29

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: 2482
Joined: Sep 25, 2005 21:54

Postby srvaldez » Mar 01, 2008 22:57

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

Postby anonymous1337 » Mar 01, 2008 23:09

Why is this in Tips & Tricks, not Projects?

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

Postby D.J.Peters » Mar 02, 2008 2:03

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

Postby fabrizio » Mar 02, 2008 9:32

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: 1704
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Postby Sisophon2001 » Mar 02, 2008 9:38

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?

Return to “Tips and Tricks”

Who is online

Users browsing this forum: Google [Bot] and 2 guests