Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

You need an actual VIC.

Moderator: Moderators

Post Reply
User avatar
beamrider
Vic 20 Scientist
Posts: 1452
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

Post by beamrider »

Mike wrote: Sat Jun 06, 2020 3:28 am This one gets the middle red stripe right:

Code: Select all

1 PRINT"{BLU,3 C=-POUND,RED,4 C=-I,C=-F}"
2 FORT=1TO3:PRINT"{BLU,3 C=-+,RED,4 C=-I,C=-F}":NEXT
3 FORT=1TO3:PRINT"{RED,7 C=-I,C=-F,BLU}":NEXT
chysn wrote:This is a bit stylized and simplistic, but so are we.
Though it may become valid on this zoom step, should the US ever grow to 336 States. :shock:

... :mrgreen:
btw, is there a tool on the PC to convert this to something that can be directly pasted into VICE ?
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

Post by chysn »

beamrider wrote: Mon Jun 08, 2020 8:16 am btw, is there a tool on the PC to convert this to something that can be directly pasted into VICE ?
I use shell scripts that combine petcat and c1541 to generate a .d64 file that has whatever I need for a particular test. Then I can just drag that .d64 file onto the emulator. For example:

Code: Select all

## Build BASIC test suite
petcat -w2 -o vic/6502test.prg -- tests/6502test.bas
c1541 vic/wax.d64 -write vic/6502test.prg
Is that what you mean?
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

Post by Mike »

Mike wrote:

Code: Select all

1 PRINT"{BLU,3 C=-POUND,RED,4 C=-I,C=-F}"
2 FORT=1TO3:PRINT"{BLU,3 C=-+,RED,4 C=-I,C=-F}":NEXT
3 FORT=1TO3:PRINT"{RED,7 C=-I,C=-F,BLU}":NEXT
beamrider wrote:btw, is there a tool on the PC to convert this to something that can be directly pasted into VICE?
Fun fact: you're seeing the output of a self-written converter specifically aimed to produce quoted PETSCII, as a means of documentation or as a means to (re-)type it in.

I just didn't bother to include a download link in this case, as I don't think it's too much of a burden to type in 3 lines of BASIC code.
User avatar
beamrider
Vic 20 Scientist
Posts: 1452
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

Post by beamrider »

Image

I wasn't sure if the format used by Mike is standard for encoding of these ControlCodes used by Commodore Editors?

I tried to paste into BasEdit and CbmPrg but neither seemed to work when I generated a prg from them.

I also tried pasting directly into VICE.
User avatar
vicist
Vic 20 Afficionado
Posts: 352
Joined: Tue Oct 09, 2012 5:26 am
Location: Sheffield, UK

Re: Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

Post by vicist »

CBM PrgStudio friendly version:-

Code: Select all

1 PRINT"{BLUE}{CM POUND*3}{RED}{CM I*4}{CM F}"
2 FORT=1TO3:PRINT"{BLUE}{CM +*3}{RED}{CM I*4}{CM F}":NEXT
3 FORT=1TO3:PRINT"{RED}{CM I*7}{CM F}{BLUE}":NEXT
User avatar
beamrider
Vic 20 Scientist
Posts: 1452
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

Post by beamrider »

cool thanks :D

Not that I'm too lazy to type in 3 lines of code, just wanted to understand whether there was some standard way of encoding these. It would appear not.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

Post by Mike »

beamrider wrote:[...] just wanted to understand whether there was some standard way of encoding these. It would appear not.
For what matters, here's the source of the program I use to produce quoted PETSCII:

Code: Select all

/*
 *  petscii.c - conversion from PETSCII to ASCII
 *
 *        creation date: 2004-12-26  Michael Kircher
 *       date of change: 2005-01-31  Michael Kircher
 *  - 0x9B corrected to {CTRL-SHIFT-+}
 *       date of change: 2007-07-28  Michael Kircher
 *  - {ARROW UP} not anymore quoted, now rendered as '^'
 *  - rendering of {ARROW LEFT} replaced by {<-}
 *  date of last change: 2014-05-25  Michael Kircher
 *  - glyph of ISO 8859-1 0xA3 not in 7-bit ASCII, replaced by {POUND}
 *  - command line parser does extended checks on parameters
 *  - byte explicitly typed as unsigned char to prevent out of bounds
 *    accesses into the array petscii[] on machines that have char
 *    signed by default.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define CR 13
#define BUFFER_LEN 256

char *petscii[256]=
{
  "~CTRL-@","~CTRL-A","~CTRL-B","~STOP","~CTRL-D","~WHT","~CTRL-F","~CTRL-G",
  "~CTRL-H","~CTRL-I","~CTRL-J","~CTRL-K","~CTRL-L","~RETURN","~CTRL-N","~CTRL-O",
  "~CTRL-P","~DOWN","~RVS ON","~HOME","~DEL","~CTRL-U","~CTRL-V","~CTRL-W",
  "~CTRL-X","~CTRL-Y","~CTRL-Z","~CTRL-[","~RED","~RIGHT","~GRN","~BLU",
  "~SPACE","!","\"","#","$","%","&","\'","(",")","*","+",",","-",".","/",
  "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?",
  "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O",
  "P","Q","R","S","T","U","V","W","X","Y","Z","[","~POUND","]","^","~<-",
  "~SHIFT-*","~SHIFT-A","~SHIFT-B","~SHIFT-C","~SHIFT-D","~SHIFT-E","~SHIFT-F","~SHIFT-G",
  "~SHIFT-H","~SHIFT-I","~SHIFT-J","~SHIFT-K","~SHIFT-L","~SHIFT-M","~SHIFT-N","~SHIFT-O",
  "~SHIFT-P","~SHIFT-Q","~SHIFT-R","~SHIFT-S","~SHIFT-T","~SHIFT-U","~SHIFT-V","~SHIFT-W",
  "~SHIFT-X","~SHIFT-Y","~SHIFT-Z","~SHIFT-+","~C=--","~SHIFT--","~PI","~C=-*",
  "~CTRL-SHIFT-@","~CTRL-SHIFT-A","~CTRL-SHIFT-B","~RUN","~CTRL-SHIFT-D","~F1","~F3","~F5",
  "~F7","~F2","~F4","~F6","~F8","~SHIFT-RETURN","~CTRL-SHIFT-N","~CTRL-SHIFT-O",
  "~BLK","~UP","~RVS OFF","~CLR","~INST","~CTRL-SHIFT-U","~CTRL-SHIFT-V","~CTRL-SHIFT-W",
  "~CTRL-SHIFT-X","~CTRL-SHIFT-Y","~CTRL-SHIFT-Z","~CTRL-SHIFT-+","~PUR","~LEFT","~YEL","~CYN",
  "~SHIFT-SPACE","~C=-K","~C=-I","~C=-T","~C=-@","~C=-G","~C=-+","~C=-M",
  "~C=-POUND","~SHIFT-POUND","~C=-N","~C=-Q","~C=-D","~C=-Z","~C=-S","~C=-P",
  "~C=-A","~C=-E","~C=-R","~C=-W","~C=-H","~C=-J","~C=-L","~C=-Y",
  "~C=-U","~C=-O","~SHIFT-@","~C=-F","~C=-C","~C=-X","~C=-V","~C=-B",
  "~SHIFT-*","~SHIFT-A","~SHIFT-B","~SHIFT-C","~SHIFT-D","~SHIFT-E","~SHIFT-F","~SHIFT-G",
  "~SHIFT-H","~SHIFT-I","~SHIFT-J","~SHIFT-K","~SHIFT-L","~SHIFT-M","~SHIFT-N","~SHIFT-O",
  "~SHIFT-P","~SHIFT-Q","~SHIFT-R","~SHIFT-S","~SHIFT-T","~SHIFT-U","~SHIFT-V","~SHIFT-W",
  "~SHIFT-X","~SHIFT-Y","~SHIFT-Z","~SHIFT-+","~C=--","~SHIFT--","~PI","~C=-*",
  "~SHIFT-SPACE","~C=-K","~C=-I","~C=-T","~C=-@","~C=-G","~C=-+","~C=-M",
  "~C=-POUND","~SHIFT-POUND","~C=-N","~C=-Q","~C=-D","~C=-Z","~C=-S","~C=-P",
  "~C=-A","~C=-E","~C=-R","~C=-W","~C=-H","~C=-J","~C=-L","~C=-Y",
  "~C=-U","~C=-O","~SHIFT-@","~C=-F","~C=-C","~C=-X","~C=-V","~PI"
};

typedef enum {false,true} boolean;

void getline(char *dest, int n, FILE *stream)
{
  int c;
  int i;
    
  for(i=0;i<n-1;i++)
  {
    c=getc(stream);
    if(CR == c || EOF == c) break;
    dest[i]=(char)c;
  }
  /* When n-1 non CR, non EOF characters have been read, check */   
  /* the next character. If it _is_ a CR or EOF, just drop it. */
  if(i == n-1)
  {
    c=getc(stream);
    if(CR != c && EOF != c) ungetc(c,stream);
  }
  /* Terminate. */
  dest[i]='\0';
}

int main(int argc, char *argv[])
{
  char line[BUFFER_LEN];
  FILE *in_file,*out_file;

  if(3 != argc)
  {
    fprintf(stderr,"%s: Syntax: %s <in_file> <out_file>\n",argv[0],argv[0]);
    exit(EXIT_FAILURE);
  }

  if(NULL == (in_file=fopen(argv[1],"rb")))
  {
    fprintf(stderr,"%s: Error: couldn't open file '%s' for read access.\n",argv[0],argv[1]);
    exit(EXIT_FAILURE);
  }

  if(NULL == (out_file=fopen(argv[2],"wb")))
  {
    fprintf(stderr,"%s: Error: couldn't open file '%s' for write access.\n",argv[0],argv[2]);
    exit(EXIT_FAILURE);
  }

  while(!feof(in_file))
  {
    int len,pos,count;
    unsigned char byte;
    boolean quoted,do_quote,last_was_quoted;

    getline(line,BUFFER_LEN,in_file);
    len=(int)strlen(line);
    pos=0;
    last_was_quoted=false;
    for(pos=0; pos<len; pos+=count)
    {
      byte=line[pos];
      quoted='~'==petscii[byte][0];
      for(count=1; quoted && pos+count<len && (char)byte==line[pos+count]; count++) {}
      do_quote=quoted && !(' '==byte && 1==count);
      if(!do_quote)
      {
        if(last_was_quoted) fputc('}',out_file);
        if(' '==byte)
          fputc(' ',out_file);
        else
          fputc(petscii[byte][0],out_file);
      }
      else
      {
        if(last_was_quoted) fputc(',',out_file); else fputc('{',out_file);
        if(count>1)
          fprintf(out_file,"%d %s",count,petscii[byte]+1);
        else
          fprintf(out_file,"%s",petscii[byte]+1);
      }
      last_was_quoted=do_quote;
    }
    if(last_was_quoted) fputc('}',out_file);
    fprintf(out_file,"\n");
  }
  fclose(in_file);
  fclose(out_file);
  
  exit(EXIT_SUCCESS);
}
Greetings,

Michael
groepaz
Vic 20 Scientist
Posts: 1188
Joined: Wed Aug 25, 2010 5:30 pm

Re: Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

Post by groepaz »

There never was a "standard" for this... pretty much every magazine made up their own, slightly different, version :) petcat supports two or three different variants iirc.
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

Post by chysn »

groepaz wrote: Sun Jun 28, 2020 8:40 am There never was a "standard" for this... pretty much every magazine made up their own, slightly different, version :) petcat supports two or three different variants iirc.
Yeah, the documentation for petcat mentions three-letter abbreviations like {blk} and {cyn}, but when I put in {black} and {cyan}, everything works just fine. So far, all of my wild guesses have worked :)

The worst ones were just regular print-outs with reversed graphics, like the ones at the end of the VIC-20 manual. Even with a key, it was hard to figure out exactly which reversed horizontal or vertical line you were looking at.
Last edited by chysn on Wed Jul 01, 2020 5:21 am, edited 1 time in total.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Noizer
Vic 20 Devotee
Posts: 297
Joined: Tue May 15, 2018 12:00 pm
Location: Europa

Re: Standards for quoted PETSCII? (split/OT from: Union Jack / lock-down challenge, [...])

Post by Noizer »

I'm afraid that this may be out of topic and I don't know if anyone have done it already on vicy.
Animated petscii's. I think it's a nice way to don't bother about redefined charset, memory wastings. "Do your thing".
Of course made on some sort of X converter.
See this for example. (How can I know you saw this already? :wink: )
https://youtu.be/33kN2ns2xb0
Valid rule today as earlier: 1 Byte = 8 Bits
-._/classes instead of masses\_.-
Post Reply