LCC for the Gigatron. Take two.

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
veekoo
Posts: 121
Joined: 07 Jun 2021, 07:07

Re: LCC for the Gigatron. Take two.

Post by veekoo »

Good point. I changed three variables to long type and at output %ld. Close to plus minus 2 147 000 000.
denjhang
Posts: 54
Joined: 02 May 2021, 01:25
Location: yuenan
Contact:

Re: LCC for the Gigatron. Take two.

Post by denjhang »

I want to use LCC to write a game that only uses Gigatron controllers, is this possible right now? My idea is to use a function like getch() to implement it, but it seems that I can't use this function at the moment.

Also, it seems that LCC can't make the gigatron sound. I need some pointers. :idea:
lb3361
Posts: 360
Joined: 17 Feb 2021, 23:07

Re: LCC for the Gigatron. Take two.

Post by lb3361 »

You can include <gigatron/sys.h> and access all the public variables defined by the ROM such as buttonState for instance. You can also call many of the SYS calls such as those that draw sprites, etc. What it lacks are libraries that make this easier.
lb3361
Posts: 360
Joined: 17 Feb 2021, 23:07

Re: LCC for the Gigatron. Take two.

Post by lb3361 »

Profiling with GLCC

The cutting edge GLCC (from github) contains basic profiling abilities. Here is an example of how it works.

First one needs to compile using options "-map=sim" to target the simulator and "--frags" to produce a memory map:

Code: Select all

$ glcc -map=sim gigatron/libc/tst/TSTstrtol.c -o tst.gt1 --frags > tst.frags
This command compiles the program tst.gt1. It also prints a "fragment map" which tells where each function or variable goes in memory. Here are the first few lines of "tst.frags":

Code: Select all

Fragment map
        08a0-08ff (96 bytes)     CODE  main (1/5)                   gigatron/libc/tst/TSTstrtol.c
        0900-08ff (0 byte)       DATA  _@_using_lmov                libc.a(rt_lmov)       
        09a0-09ff (96 bytes)     CODE  main (2/5)                   gigatron/libc/tst/TSTstrtol.c
        0aa0-0afe (95 bytes)     CODE  main (3/5)                   gigatron/libc/tst/TSTstrtol.c
        0ba0-0bfe (95 bytes)     CODE  main (4/5)                   gigatron/libc/tst/TSTstrtol.c
...
The next step is to run the program using the gtsim simulator with option "-prof".

Code: Select all

$ gtsim -rom gigatron/roms/dev.rom -prof tst.prof tst.gt1
This runs the program as usual. It also produces a file "tst.prof" which associates program addresses with spent cycles. Here is how it starts:

Code: Select all

prof={
 # pc: cycs  Number of cycles spent on vCPU instructions at address less than pc
 0x08a0: 20,
 0x08a2: 48,
 0x08a4: 68,
 0x08a6: 96,
 0x08a8: 116,
...
We can then use a small python script that takes these two files and prints how many cycles were spent in each code fragment. Piping this output through "sort -nr" displays them from the most costly to the least costly.

Code: Select all

$ ./gigatron/mapsim/gtprof tst.prof tst.frags | sort -nr
     6235414	TOTAL
     1636568	__@mac32x16                   libc.a(rt_lmul.s)
     1592544	__@lshl1_t0t1                 libc.a(rt_lshl1t0t1.s)
     1256606	_@_ladd                       libc.a(rt_ladd.s)
      547320	_strtol_push                  libc.a(strtol.c)
      207832	_@_fcopyz_                    libc.a(rt_copyz.s)
      193212	_@_lmul                       libc.a(rt_lmul.s)
      142740	_@_lcopy_                     libc.a(rt_lcopy.s)
      125616	worker                        libc.a(strtol.c)
       79062	_@_lcmps                      libc.a(lcmp.s)
       78094	atol                          libc.a(atol.c)
       66364	main                          gigatron/libc/tst/TSTstrtol.c
       61380	atoi                          libc.a(atoi.c)
       35840	_@_rtrn_ff                    libc.a(rt_save.s)
       31920	_@_lshru                      libc.a(rt_lshru.s)
       29680	_@_save_ff                    libc.a(rt_save.s)
       20236	strtoul                       libc.a(strtol.c)
       20236	strtol                        libc.a(strtol.c)
       19824	_@_land                       libc.a(rt_land.s)
       18480	_@_lcmpx                      libc.a(lcmpx.s)
       17406	_strtol_decode_s              libc.a(strtol.c)
       14484	isspace                       libc.a(isspace.c)
       10320	_@_lshl                       libc.a(rt_lshl.s)
        9860	printf                        libsim.a(printf.s)
        9752	_strtol_decode_u              libc.a(strtol.c)
        6864	_@_lexts                      libc.a(rt_lexts.s)
        1248	_@_lneg                       libc.a(rt_lneg.s)
         658	_start                        libsim.a(_start.s)
         568	.callchain                    libsim.a(_start.s)
         442	_init_bss                     libc.a(_init1.c)
         258	_gt1exec                      _gt1exec.s
This program takes 6235414 cycle. Almost half of them are spend in code that performs long multiplication, shifts, and additions. Not too surprising for a program that tests functions strtol().
denjhang
Posts: 54
Joined: 02 May 2021, 01:25
Location: yuenan
Contact:

Re: LCC for the Gigatron. Take two.

Post by denjhang »

Can the current latest GLCC be compiled against ROMvX0?
Last edited by denjhang on 11 Mar 2022, 05:13, edited 1 time in total.
denjhang
Posts: 54
Joined: 02 May 2021, 01:25
Location: yuenan
Contact:

Re: LCC for the Gigatron. Take two.

Post by denjhang »

Code: Select all

typedef struct channel_s {
	char wavA, wavX;
	char keyL, keyH;
	char oscL, oscH;
} channel_t;
I'm confused by this paragraph because I've tried writing various values to channel1.wavA, wavX, keyL, keyH, etc. and nothing comes out.
for example

Code: Select all

channel1.wavA='0';
channel1.wavX='2';

channel1.keyL='1';
channel1.keyH='b';
Oh I see. I added soundTimer=1; and then there is sound.
denjhang
Posts: 54
Joined: 02 May 2021, 01:25
Location: yuenan
Contact:

Re: LCC for the Gigatron. Take two.

Post by denjhang »

Well, now there is a question, how to use GLCC to read the data in the ROM? For example, I need the notesTable located at 0x0900 of the ROM.
lb3361
Posts: 360
Joined: 17 Feb 2021, 23:07

Re: LCC for the Gigatron. Take two.

Post by lb3361 »

denjhang wrote: 10 Mar 2022, 18:35 Well, now there is a question, how to use GLCC to read the data in the ROM? For example, I need the notesTable located at 0x0900 of the ROM.

Code: Select all

#include <gigatron/sys.h>

// Then use  int SYS_Lup(unsigned int addr)
// This is not a real SYS call, just a wrapper around the LUP vCPU opcode.
// Example:

void setup_channel(int c, int noteoffset)
{
	channel_t *chan = &channel(c)
	chan->wavA = 0;
	chan->wavX = 2;
	chan->keyL = SYS_Lup(notestable + noteoffset);
	chan->keyL = SYS_Lup(notestable + noteoffset + 1);
}
denjhang
Posts: 54
Joined: 02 May 2021, 01:25
Location: yuenan
Contact:

Re: LCC for the Gigatron. Take two.

Post by denjhang »

Currently I can control the pitch and volume correctly. So in glcc, how to time it. For example, make a note sound for one second or make a quarter note when the a key of the controller is pressed.
Attachments
music2.c
(1004 Bytes) Downloaded 109 times
denjhang
Posts: 54
Joined: 02 May 2021, 01:25
Location: yuenan
Contact:

Re: LCC for the Gigatron. Take two.

Post by denjhang »

I thought of a way to use frameCount%60 to get one second and reset it periodically.
Attachments
timer1.c
(951 Bytes) Downloaded 107 times
Post Reply