Page 1 of 1

Smallest vCPU program

Posted: 18 Jun 2019, 23:36
by marcelk
The smallest vCPU application

1. Gives identifiable visual feedback:
- Draws two colored lines (one vertical, one horizontal)
- Continuously blinks a pixel

2. Is interactive:
- Shifts the screen when a button is pressed, restores when released
- Changes line color when this button is an arrow button

3. Behaves consistent and doesn't crash:
- Is compatible with all ROM versions, past, present and future
- Doesn't rely on undocumented features
- Doesn't accidently clobber system variables

4. Is as small as possible
- Occupies 6 bytes of RAM (3 vCPU instructions)
- Loads at a non-intrusive memory location

Smallest.png
Annotated screen capture
Smallest.png (190.11 KiB) Viewed 497 times

Code: Select all

 * file: Docs/Smallest.gt1
 
 0207  21 0e                    LDW   frameCount         |!.|
 0209  f3 17                    DOKE  vPC+1              |..|
 020d  90 07                    BRA   $0209              |..|
 * 6 bytes

 * start at $0207

Believe it or not, there's actually an application for this: to provide some kind of defined behaviour in case a GT1 file is loaded on a Gigatron with an older ROM than required. You don't want it to crash when using functions that aren't present. But you still want it to behave in a manner that's identifiable. The GT1 file itself is responsible, because the Loader wouldn't know any better. So it must be as small as possible(*). A bit silly? Oh sure!

Details on the workings in the comments of Docs/Smallest.gcl.


(*) I guess it's a bit akin to the message "This program cannot be run in DOS mode" present in Windows executables. Same idea, but smaller.

Re: Smallest vCPU program

Posted: 27 Aug 2019, 16:41
by DavidHK
Because of the comment in Smallest.gc1 that mentions disturbing the shift-table I started looking for other similar, small programs. So far I found one that is one byte larger:

Code: Select all

$100 _vAC. [do loop]
In the WozMon monitor you could enter it this way:

Code: Select all

500:11 0 1 f0 18 90 5
500 R
It will set the first video line to the zero page where you can see all kinds of variables changing while the native CPU loop is running. It even shows the 480px vertical resolution in some places.

Since these instructions don't depend on their own location they could also be inserted anywhere else where a program might want to stop its execution and signal that to the user.

Re: Smallest vCPU program

Posted: 28 Aug 2019, 04:32
by marcelk
DavidHK wrote:

Code: Select all

500:11 0 1 f0 18 90 5
500 R
The 90 5 should be 90 3:

Code: Select all

gt1dump.py -d x.gt1 
* file: x.gt1

0500  11 00 01                 LDWI  $0100              |...|
0503  f0 18                    POKE  vAC                |..|
0505  90 03                    BRA   $0505              |..|
* 7 bytes

* start at $0500
It even shows the 480px vertical resolution in some places.
I never noted these subpixels before, and it took me a minute to figure out why they become visible. Very cool!

Re: Smallest vCPU program

Posted: 29 Aug 2019, 17:39
by DavidHK
Thanks for the correction, I still have got a lot to learn about the vCPU and the Gigatron in general. ;-) The function that got placed by Main into page $0500 probably hid my mistake.