Jump to content

Photo

Example of how to use DSR functions from GCC - Reading GPL 3.0

programming example gcc dsrlnk dsr

1 reply to this topic

#1 tschak909 ONLINE  

tschak909

    River Patroller

  • 3,160 posts
  • Location:USA

Posted Sun Feb 17, 2019 3:13 PM

Hello,

 

Since PLATOTERM is licensed under the GNU Public License, I have written a piece of accessory software that opens, and displays a copy of the GNU Public License 3.0 from a file. The TIPI version loads this from the web, courtesy of the PI.HTTP level 3 interface, which is very nifty.

 

I do think that the dsr_xxxx functions here should be folded into libti99, but this is something that @tursillion may want to think about...

 

Thanks to jedimatt42 for these functions, which I pulled from TIPICFG's source code.

 

I have uploaded it to github, if you want to use it:

https://github.com/t...platoterm99-gpl

 

You can run the program if you have a TIPI:

CALL TIPI("PI.HTTP://TI99.IRATA.ONLINE/COPYING")
 

And for the purposes of discussion, I am posting the code here, as well:

#include <files.h>

#include <string.h>
#include <system.h>
#include <conio.h>

#define VPAB 0x3000
#define FBUF 0x3200

int force_quit=0;

unsigned char dsr_openDV(struct PAB* pab, char* fname, int vdpbuffer, unsigned char flags);
unsigned char dsr_close(struct PAB* pab);
unsigned char dsr_read(struct PAB* pab, int recordNumber);

void initPab(struct PAB* pab) {
  pab->OpCode = DSR_OPEN;
  pab->Status = DSR_TYPE_DISPLAY | DSR_TYPE_VARIABLE | DSR_TYPE_SEQUENTIAL | DSR_TYPE_INPUT;
  pab->RecordLength = 80;
  pab->RecordNumber = 0;
  pab->ScreenOffset = 0;
  pab->NameLength = 0;
  pab->CharCount = 0;
}

// Configures a PAB for filename and DV80, and opens the file
unsigned char dsr_openDV(struct PAB* pab, char* fname, int vdpbuffer, unsigned char flags) {
  initPab(pab);
  pab->OpCode = DSR_OPEN;
  pab->Status = DSR_TYPE_DISPLAY | DSR_TYPE_VARIABLE | DSR_TYPE_SEQUENTIAL | flags;
  pab->RecordLength = 80;
  pab->pName = fname;
  pab->VDPBuffer = vdpbuffer;

  return dsrlnk(pab, VPAB);
}

unsigned char dsr_close(struct PAB* pab) {
  pab->OpCode = DSR_CLOSE;

  return dsrlnk(pab, VPAB);
}

// the data read is in FBUF, the length read in pab->CharCount
// typically passing 0 in for record number will let the controller
// auto-increment it.
unsigned char dsr_read(struct PAB* pab, int recordNumber) {
  pab->OpCode = DSR_READ;
  pab->RecordNumber = recordNumber;
  pab->CharCount = 0;

  unsigned char result = dsrlnk(pab, VPAB);
  vdpmemread(VPAB + 5, (&pab->CharCount), 1);
  return result;
}

void main(void)
{
  struct PAB pab;
  set_text();
  charsetlc();
  clrscr();
  bgcolor(COLOR_CYAN);
  textcolor(COLOR_BLACK);
  gotoxy(0,0);
  unsigned char ferr = dsr_openDV(&pab,"PI.HTTP://TI99.IRATA.ONLINE/COPYING.TXT",FBUF,DSR_TYPE_INPUT);
  if (ferr)
    {
      cprintf("Could not open License from web.");
      for (;;) {}
    }
  int i=0;
  unsigned char ch;
  while (ferr == DSR_ERR_NONE)
    {
      unsigned char cbuf[81];
      ferr = dsr_read(&pab,0);

      if (ferr == DSR_ERR_NONE)
        {
          vdpmemread(FBUF,cbuf,pab.CharCount);
          cbuf[pab.CharCount]=0;
          cprintf("%s",cbuf);
        }

      if (i>4)
        {
          i=0;
          cprintf("                                       \r\n");
          cprintf("  -- PRESS ANY KEY TO CONTINUE -- ");
          ch=cgetc();
          clrscr();
        }
      else
        {
          i++; // Get next record.
        }
    }

  cprintf("                                        \r\n");
  cprintf("  END OF LICENSE. PRESS ANY KEY TO QUIT. ");
  ch=cgetc();

  ferr = dsr_close(&pab);
}

 

Hope it is useful.

-Thom



#2 tschak909 ONLINE  

tschak909

    River Patroller

  • Topic Starter
  • 3,160 posts
  • Location:USA

Posted Mon Feb 18, 2019 2:05 AM

Attached File  TI-GPL.jpg   452.53KB   1 downloads







Also tagged with one or more of these keywords: programming example, gcc, dsrlnk, dsr

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users