Smallest vCPU program

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice.
Post Reply
User avatar
marcelk
Posts: 329
Joined: 13 May 2018, 08:26

Smallest vCPU program

Post by marcelk » 18 Jun 2019, 23:36

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 312 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.
Attachments
Smallest.gt1
GT1 file
(12 Bytes) Downloaded 7 times

User avatar
DavidHK
Posts: 22
Joined: 25 Aug 2019, 12:59

Re: Smallest vCPU program

Post by DavidHK » 27 Aug 2019, 16:41

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.

User avatar
marcelk
Posts: 329
Joined: 13 May 2018, 08:26

Re: Smallest vCPU program

Post by marcelk » 28 Aug 2019, 04:32

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!

User avatar
DavidHK
Posts: 22
Joined: 25 Aug 2019, 12:59

Re: Smallest vCPU program

Post by DavidHK » 29 Aug 2019, 17:39

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.

Post Reply