Wednesday, March 14, 2018

A Simple Quiz Game in Commodore 64 Basic a Grade Schooler Could Write


10 print "quizgame"
20 open 1,8,8,"quizfile,r,s"
30 dim answer$(9)
35 i=0
36 p=0:rem points
37 qs$=""
40 input# 1,a$
50 rem print a$
60 if a$="!" goto 900
80 ca=0:rem correct answers
100 type$=left$(a$,1)
130 if type$="q" then qs$=qs$+mid$(a$,2,255)
150 if type$="a" then gosub 200
160 if type$="c" then gosub 250
190 goto 40
200 answer$(i)=mid$(a$,2,255)
210 i=i+1
220 return
250 rem gosub from 160
260 ca=val(mid$(a$,2,1))
270 gosub 300
280 return
300 print qs$
310 for j=0 to i-1:rem gameplay
320 print str$(j+1)+":"+answer$(j)
330 next j
340 i=0
350 get an$:if an$="" goto 350
360 an=val(an$)
370 if ca=an then p=p+1
380 print "your answer was:", an
390 print "correct answer was:",ca
400 print ,answer$(ca-1)
410 return
900 close 1
910 print "number of points:"+str$(p)

So...yeah.
Basically, that's all it took. It reads in a file "quizfile" and lines that start with a q, are part of the question, a lines contain an answer, and c lines are followed by a number indicating which answer was correct.

For an example:
qWhat is your favourite color
aBlue
aRed
aBlue, i mean red!
c1


This is not quite enough, as the ability to create the file is required. A simple solution - and the one I used to write the file was this:

5 dim o$(100)
6 i=1
10 input o$(i)
20 if o$(i)="!" then 100
40 i=i+1
50 goto 10
100 print "end"
105 print i;"lines of text"
107 open 1,8,8,"@0:quizfile,w,s"
110 for j=0 to i
120 print o$(j)
140 print#1,o$(j)
150 next
160 close 1

It's not good enough, though, since you do need the ability to add new questions.
It's also not the simplest possible way, since you could do the whole thing with a goto after the open in a input-print# loop until end symbol, but I often putter around, trying different things, and sometimes the solution can be messy.

simple would be something like this:
10 open 1,8,8,"@0:quizfile,w,s"
20 input a$
30 if a$="!" then 100
40 print# 1,a$
50 goto 20
100 close 1

Well, I'm going to be compassionate towards my younger self. After all, it took me a while to figure out how to write and load from files, and an arcane syntax like "@0:" is more than a bit odd, although I think it means "start writing to the file from this location. Because, otherwise, the file doesn't save, and then, sadness. 

Tuesday, March 13, 2018

Adventures in Commodore 64 Basic

Let me try to get this formatted nicely in HTML:



10  rem decimal to hex byte converter
20  rem need some data, use basicmem
30  begin=4096
40  finish=4128
50  for i=begin to finish
60  v=peek(i)
65  rem numbers start at 48=0
70  hi=int(v/16):lo=v and 15
75  rem numbers start at 48=0
80  lo$=chr$(48+lo)
90  hi$=chr$(48+hi)
100 rem chars start at 65=a
110 if lo>9 then lo$=chr$(55+lo)
120 if hi>9 then hi$=chr$(55+hi)
130 print hi$lo$+" ";
140 cols=cols+1
150 if cols=8 then gosub 200
160 next
170 goto 230
200 print ";"
210 cols=0
220 return
230 rem end

Here's the stylings:
div.commodore {
  border: 60px solid #0088ff;
  color: #0088ff;
  background-color: #0000aa;
  text-transform: uppercase;
  font-family: "Courier", "Courier New";
}


To tell the truth, I've already written a bunch of tiny practice programs.

  1. One that takes in input lines and writes them to file, 
  2. Read lines from file
  3. change the cursor, border and background color - in machine language, put into memory. That was the image in the last post. 
  4. one that tests the hires mode. Things get interesting there
and a few others. However, today I wrote something potentially useful - a bit of code that dumps an area from memory to the screen in hex. Doing that is probably going to be useful, once I get into more machine language stuff, especially as I cannot pretend to own a TASM cartridge or something.
Well.
What I wrote is a START, as, since it being a basic program, it's slow, AND unless I combine it with an interface to edit memory, it doesn't do that much - I can do poke-run loops, but that seems remarkably tedious.

An alternate way would be to translate  this to ASM, then load it to an area in memory, and then activate it via SYS calls.

Still, the output looks cool.
The program dumped is, naturally, the screen-color altering one from my previous post.
A9 is a single-byte LDA, 8D is STA followed by a 2-byte little endian address, 60 is RTS.

I suppose a sys calls is basically just a JSR, then.

Monday, March 12, 2018

Fixing My Childhood Trauma With Commodore 64

Holy Belldandy's Eyebrows, Batman!



Yes, I possessed one of these wonderful machines, wayback. I was even interested in programming with them. Unfortunately, very little materials were available, outside a fairly good computer magazine, and my understanding was really quite poor.

At some point in grade school - between age 9 and 12,  I was quite into it - even if I had tried to trade my C64 for an MSX, because it had direct commands for graphics and sound. However, typing in program listings rarely worked and I really couldn't debug the programs - didn't even know how.  I did try to write a trivial pursuit type question-answers game in the fifth grade, but it was just this awful mess of IF-THENs. I think I tried using DATA statements, but I couldn't quite get it to work, so I gave up on that, and the fact I even remember that, should tell you something.

At that age, I didn't have any money. I couldn't buy ANYTHING, although I did get my parents to buy, and later on had a subscription to the C=magazine. I also think I had ONE book (ISBN 951-832-005-5), but it seems to have vanished at some point. :/

So, as a project, I'm doing some C64 programming, with the following constraints:
- All code is written inside the emulator
- No pre-existing applications are allowed. I don't know if I had any
- I will allow for the internet, which is a bit of a cheat, admittedly, but there are chances I could have gleaned the information from a magazine.

My goals are, roughly:
 - A text editor,
 - A hex editor, capable of writing to disk, for some rough machine code working
 - MAYBE a macroassembler.
 - Various audio/video tests
 - The !"#%¤%& game, it's engine and enough demo questions for a proof of concept.

Since I'm bringing in a generation's worth of computer science knowhow, I can say that the quiz program needs to load the questions from a file on a floppy disk (or perhaps a datassette, too) instead of being hardcoded, and the questions need to be editable with (a, the) text editor.

I do hope to document this, since a "How do I Basic to Macroassembler" does not seem to exist in the 'net at this point.

Thursday, February 8, 2018

Game character stuff.

Something something cast fist?


A lot of what becomes a game is art assets. On a recent interview, a modern game can have 10 Gb of art and maybe 200M of code.

This is a kernel, or a seed of sorts. Also, my camera is not a scanner. Clearly.


I ended up doodling in Piskel a bit. Fun, and usable, but not exactly what I intend to go for.
Just the keyframes, but at this resolution I'm not sure if any more is needed.

Still, I seem to be entering a pixel art kick .

Friday, December 29, 2017

Art Therapy.

That was fun. Goal-less drawing and painting. Did, like, four things. This is one I digitized with an app; The shadows are an artifact of taking a photo, but I kind of like them.


Saturday, November 4, 2017

Why I Stopped Drawing


It's not like I intended to, but in practice, that is what happened. There are zero drawings I've published this year, and what I have drawn, has been of no significance.

I guess a partial reason would be my accumulating wrist injuries, but while pain may train me not to draw, in a Pavlovian sense, it's not the primary reason.

At some point, I started tracking how much time I was taking, while drawing. It was a surprising amount. When drawing, I often entered the flow state, lost my sense of time, and often found I had puttered around with a particular drawing for hours, often past midnight.

Now, this is obviously a good, if not a great thing, for an artist, in some sense. Not in a business-sense, perhaps, but creatively. However, I didn't realize that.

Back when I tried to do a comic on a regular weekly schedule, I began tracking my time-use, mainly to make sure I was actually putting in some hours. This had an unfortunate side effect of me noticing a single panel might take me about 8 hours to draw, plus whatever time was required to edit it later on. Considering a single page has on average five panels, this was basically... not unsustainable, but I was also trying to study at the time.

Heh.

I will graduate one of these years. But, I digress.

Now, I'm not saying that you shouldn't track your work, it's just... be aware of potential unintended consequences, and don't aim for the wrong goal.

Lesson learned: Don't try to be efficient in doing something you love. Just be effective, and enjoy.

Some declarations:
Best free traditional animation application for Windows is Plastic Animation Paper 4.0 Pro. Although, Blender's Grease Pencil comes close. Blender's Grease Pencil is also pretty decent, and it has an integrated dope sheet and all. Blender should be great on zooms and pans and such. Also, Blender's 2.8 is due to have some hefty improvements on the 2d side of things.

Best sprite animation application is ASEprite. The thing that comes closest is Piskel. You can work with GraphicsGale, but I don't think it comes close.

Beyond that, humble Paint.Net is decent for a lot of pixel work. I have three versions of OpenCanvas for painting. (Thanks, Ben!)

Krita is still under evaluation. Synfig... it's rendering seems, bad, basically.

Saturday, June 4, 2016

I Got Science in my Eastern Fantasy!

You wanna know what ruined my night's sleep? I'm going to tell you!

So, of late I've gotten to reading Xianxia novels, and I've been a fan of the idea of ascending through sheer effort for a long time. Also, stories about gods and immortals have always been intriguing.

I've also been doing some research on nutrition and longevity, of late, running into the legend of Li Ching-Yuen. Add to this the various revelations about the dangers of gluten and whatnot, and what came to mind was, as follows:

Someone goes to hermitage on a forested mountain top. What do they eat?
They wouldn't have access to grains, and they'd likely scavenge. So they'd live on a diet of mushrooms, roots, berries, herbs, as well as hunted meat. Basically, a diet consisting of superfoods, adaptogens and such.

In addition, they'd be in a rather cold environment, meaning they'd have a lot of brown adipose tissue, participating in altutuide training, and if they happen on a hot spring ( a favourite of your wandering martial artist training on the mountains ) they might also gain the benefits of hyperthermia, such as increased HGH and EPO.

Not to mention, that come spring, they'd be getting access to a seasonal testosterone dosing - pine pollen is basically testosterone - effectively having nature's own hormone replacement therapy, which would benefit them greatly after passing sixty. It may not be a coincidence that the white pine is a symbol of longevity in China.