Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #4986 > unrolled thread

Call Address to Print BASIC Error Message

Started byBill Chatfield <billchatfield1@gmail.com>
First post2019-01-30 15:16 -0800
Last post2019-02-04 01:06 -0800
Articles 16 — 9 participants

Back to article view | Back to comp.sys.apple2.programmer


Contents

  Call Address to Print BASIC Error Message Bill Chatfield <billchatfield1@gmail.com> - 2019-01-30 15:16 -0800
    Re: Call Address to Print BASIC Error Message James Davis <JPD.Enterprises@outlook.com> - 2019-01-30 18:21 -0800
    Re: Call Address to Print BASIC Error Message gids.rs@sasktel.net - 2019-01-30 21:05 -0800
    Re: Call Address to Print BASIC Error Message Tom Porter <laseractiveguy@gmail.com> - 2019-01-31 00:35 -0800
      Re: Call Address to Print BASIC Error Message kegs@provalid.com (Kent Dickey) - 2019-01-31 21:58 -0600
        Re: Call Address to Print BASIC Error Message Michael Pohoreski <michael.pohoreski@gmail.com> - 2019-01-31 22:31 -0800
    Call Address to Print BASIC Error Message Michael Pohoreski <michael.pohoreski@gmail.com> - 2019-01-31 23:01 -0800
      Re: Call Address to Print BASIC Error Message awanderin <awanderin@gmail.com> - 2019-02-02 11:32 -0700
        Re: Call Address to Print BASIC Error Message Jeff Blakeney <CUTjeffrey_blakeney@yahoo.ca> - 2019-02-02 22:56 -0500
          Re: Call Address to Print BASIC Error Message gids.rs@sasktel.net - 2019-02-03 10:19 -0800
            Re: Call Address to Print BASIC Error Message Michael Barry <barrym95838@yahoo.com> - 2019-02-04 00:42 -0800
          Re: Call Address to Print BASIC Error Message Michael Barry <barrym95838@yahoo.com> - 2019-02-04 00:31 -0800
            Re: Call Address to Print BASIC Error Message Jeff Blakeney <CUTjeffrey_blakeney@yahoo.ca> - 2019-02-04 10:27 -0500
              Re: Call Address to Print BASIC Error Message Bill Chatfield <billchatfield1@gmail.com> - 2019-02-09 09:28 -0800
                Re: Call Address to Print BASIC Error Message Michael Pohoreski <michael.pohoreski@gmail.com> - 2019-02-09 13:57 -0800
        Re: Call Address to Print BASIC Error Message Michael Barry <barrym95838@yahoo.com> - 2019-02-04 01:06 -0800

#4986 — Call Address to Print BASIC Error Message

FromBill Chatfield <billchatfield1@gmail.com>
Date2019-01-30 15:16 -0800
SubjectCall Address to Print BASIC Error Message
Message-ID<f52655a8-0fd6-4aee-b345-8631bb8b3b38@googlegroups.com>
If I catch an error with ON ERR GOTO, I still want to print the error message in the error handler. There has to be an address I can CALL to manually print the error message because BASIC normally does print the error message. I don't want the error code. Printing an error code is a waste of time as it forces a human to go look up what the code means, when the computer could have translated the code into a message much quicker and easier. Join my fight to boycott the printing of error codes. :-) Anyone who's worked with DB2 will know what I mean.

10 ON ERR GOTO 100
20 PRINT CHR$(4);"BLAH"
100 POKE 222,0
110 CALL ADDRESS_TO_PRINT_ERROR_MESSAGE
120 RESUME

What is the ADDRESS_TO_PRINT_ERROR_MESSAGE?

[toc] | [next] | [standalone]


#4987

FromJames Davis <JPD.Enterprises@outlook.com>
Date2019-01-30 18:21 -0800
Message-ID<6048426b-2154-4cde-8b2f-73fc741a081e@googlegroups.com>
In reply to#4986
On Wednesday, January 30, 2019 at 3:16:01 PM UTC-8, Bill Chatfield wrote:
> If I catch an error with ON ERR GOTO, I still want to print the error message in the error handler. There has to be an address I can CALL to manually print the error message because BASIC normally does print the error message. I don't want the error code. Printing an error code is a waste of time as it forces a human to go look up what the code means, when the computer could have translated the code into a message much quicker and easier. Join my fight to boycott the printing of error codes. :-) Anyone who's worked with DB2 will know what I mean.
> 
> 10 ON ERR GOTO 100
> 20 PRINT CHR$(4);"BLAH"
> 100 POKE 222,0
> 110 CALL ADDRESS_TO_PRINT_ERROR_MESSAGE
> 120 RESUME
> 
> What is the ADDRESS_TO_PRINT_ERROR_MESSAGE?

Search for a copy of "What's Where in the Apple II"

[toc] | [prev] | [next] | [standalone]


#4988

Fromgids.rs@sasktel.net
Date2019-01-30 21:05 -0800
Message-ID<49199027-4fa0-4e58-bba9-841caca8ebad@googlegroups.com>
In reply to#4986
On Wednesday, January 30, 2019 at 5:16:01 PM UTC-6, Bill Chatfield wrote:
> If I catch an error with ON ERR GOTO, I still want to print the error message in the error handler. There has to be an address I can CALL to manually print the error message because BASIC normally does print the error message. I don't want the error code. Printing an error code is a waste of time as it forces a human to go look up what the code means, when the computer could have translated the code into a message much quicker and easier. Join my fight to boycott the printing of error codes. :-) Anyone who's worked with DB2 will know what I mean.
> 
> 10 ON ERR GOTO 100
> 20 PRINT CHR$(4);"BLAH"
> 100 POKE 222,0
> 110 CALL ADDRESS_TO_PRINT_ERROR_MESSAGE
> 120 RESUME
> 
> What is the ADDRESS_TO_PRINT_ERROR_MESSAGE?


All the errors are listed on Beagle Bros Peeks, Pokes and Pointers Chart.  A handy chart to have.

[toc] | [prev] | [next] | [standalone]


#4989

FromTom Porter <laseractiveguy@gmail.com>
Date2019-01-31 00:35 -0800
Message-ID<a9b04601-f055-4dfc-ab5d-9d470890782f@googlegroups.com>
In reply to#4986
 EG=Peek (218)+Peek (219) * 256:PRINT "ERR# ";PEEK(222);" AT LINE# ";EG

I don't believe there is a call that does this... however I think you could create an EXEC file that as a ton of IF statements and if the PEEK(222) is correct, it will print *that line* to the screen.

I've done it in the past, so I will post it here, done a long time ago, so it may need modification...yes its slow, but its for debug purposes.

IF ER=0     THEN ER$="NEXT without FOR"
IF ER=1    THEN ER$="Language not available"
IF ER=2    THEN ER$="Range error"
IF ER=3    THEN ER$="No device connected"
IF ER=4    THEN ER$="Volume write-protected"
IF ER=5    THEN ER$="End of data"
IF ER=6    THEN ER$="Path/file not found"
IF ER=7    THEN ER$="Incorrect volume number"
IF ER=8    THEN ER$="I/O error"
IF ER=9    THEN ER$="Disk full"
IF ER=10   THEN ER$="File locked"
IF ER=11   THEN ER$="DOS-related syntax error"
IF ER=12   THEN ER$="No buffers available"
IF ER=13   THEN ER$="File type mismatch"
IF ER=14   THEN ER$="Program too large"
IF ER=15   THEN ER$="Illegal direct command"
IF ER=16   THEN ER$="Applesoft syntax error"
IF ER=17   THEN ER$="Directory full"
IF ER=18   THEN ER$="File not open"
IF ER=19   THEN ER$="Duplicate file name"
IF ER=20   THEN ER$="File busy"
IF ER=21   THEN ER$="File(s) still open"
IF ER=22   THEN ER$="RETURN without GOSUB"
IF ER=42   THEN ER$="Out of Data error"
IF ER=53   THEN ER$="Illegal quantity error"
IF ER=56   THEN ER$="RESET was pressed"
IF ER=69   THEN ER$="Overflow error"
IF ER=77   THEN ER$="Out of memory"
IF ER=90   THEN ER$="Undefined statement error"
IF ER=107  THEN ER$="Bad subscript error"
IF ER=120  THEN ER$="Redimensioned array"
IF ER=133  THEN ER$="Divide by zero"
IF ER=163  THEN ER$="Type mismatch error"
IF ER=176  THEN ER$="String too long error"
IF ER=191  THEN ER$="Formula too complex"
IF ER=224  THEN ER$="Undefined function error"
IF ER=254  THEN ER$="Extra ignored"
IF ER=255  THEN ER$="=Break="

[toc] | [prev] | [next] | [standalone]


#4990

Fromkegs@provalid.com (Kent Dickey)
Date2019-01-31 21:58 -0600
Message-ID<F7OdnRKoS8hjXs7BnZ2dnUU7-KXNnZ2d@giganews.com>
In reply to#4989
In article <a9b04601-f055-4dfc-ab5d-9d470890782f@googlegroups.com>,
Tom Porter  <laseractiveguy@gmail.com> wrote:
> EG=Peek (218)+Peek (219) * 256:PRINT "ERR# ";PEEK(222);" AT LINE# ";EG
>
>I don't believe there is a call that does this... however I think you
>could create an EXEC file that as a ton of IF statements and if the
>PEEK(222) is correct, it will print *that line* to the screen.
>
>I've done it in the past, so I will post it here, done a long time ago,
>so it may need modification...yes its slow, but its for debug purposes.
>
>IF ER=0     THEN ER$="NEXT without FOR"
>IF ER=1    THEN ER$="Language not available"
>IF ER=2    THEN ER$="Range error"
>IF ER=3    THEN ER$="No device connected"
>IF ER=4    THEN ER$="Volume write-protected"
>IF ER=5    THEN ER$="End of data"
>IF ER=6    THEN ER$="Path/file not found"
>IF ER=7    THEN ER$="Incorrect volume number"
>IF ER=8    THEN ER$="I/O error"
>IF ER=9    THEN ER$="Disk full"
>IF ER=10   THEN ER$="File locked"
>IF ER=11   THEN ER$="DOS-related syntax error"
>IF ER=12   THEN ER$="No buffers available"
>IF ER=13   THEN ER$="File type mismatch"
>IF ER=14   THEN ER$="Program too large"
>IF ER=15   THEN ER$="Illegal direct command"
>IF ER=16   THEN ER$="Applesoft syntax error"
>IF ER=17   THEN ER$="Directory full"
>IF ER=18   THEN ER$="File not open"
>IF ER=19   THEN ER$="Duplicate file name"
>IF ER=20   THEN ER$="File busy"
>IF ER=21   THEN ER$="File(s) still open"
>IF ER=22   THEN ER$="RETURN without GOSUB"
>IF ER=42   THEN ER$="Out of Data error"
>IF ER=53   THEN ER$="Illegal quantity error"
>IF ER=56   THEN ER$="RESET was pressed"
>IF ER=69   THEN ER$="Overflow error"
>IF ER=77   THEN ER$="Out of memory"
>IF ER=90   THEN ER$="Undefined statement error"
>IF ER=107  THEN ER$="Bad subscript error"
>IF ER=120  THEN ER$="Redimensioned array"
>IF ER=133  THEN ER$="Divide by zero"
>IF ER=163  THEN ER$="Type mismatch error"
>IF ER=176  THEN ER$="String too long error"
>IF ER=191  THEN ER$="Formula too complex"
>IF ER=224  THEN ER$="Undefined function error"
>IF ER=254  THEN ER$="Extra ignored"
>IF ER=255  THEN ER$="=Break="

I believe Applesoft uses the trick that the Applesoft error number is just an
index into a string table, with that table at $D260 (53856).  Each string ends
with a character with the high bit set.  The " ERROR" with a ctrl-g is not
part of the string, but is at offset 248.  So "NEXT WITHOUT FOR" is 16 bytes
long at $d260, and "SYNTAX" is at $d260 + 16 (since 16 is the error number for
SYNTAX ERROR), and "RETURN WITHOUT GOSUB" is at offset 22, etc.  And
"EXTRA IGNORED" does not obey this pattern.

However, the code to grab this info and print it out would be many lines
of BASIC code.  I think you cannot use an Applesoft entry point since it's
not a routine--if Applesoft prints an error message, it stops the program
and goes back to the "]" prompt, and I think it just does all of that
without making the error message a subroutine.

Kent

[toc] | [prev] | [next] | [standalone]


#4991

FromMichael Pohoreski <michael.pohoreski@gmail.com>
Date2019-01-31 22:31 -0800
Message-ID<761382cb-45d3-4473-b168-362cdf4ea289@googlegroups.com>
In reply to#4990
On Thursday, January 31, 2019 at 7:58:59 PM UTC-8, Kent Dickey wrote:
> I believe Applesoft uses the trick that the Applesoft error number is just an
> index into a string table, with that table at $D260 (53856). 

Correct. The main entry point is ERROR @ $D412, with X being the offset from the array of strings @ $D260 to print.

The error message is broken into 4 parts:

* Print <CR>
* Print '?'
* Print the error string
* Print "ERROR"

D412- 24 D8    2400 ERROR  BIT ERRFLG   "ON ERR" TURNED ON?
D414- 10 03    2410        BPL .1       NO
D416- 4C E9 F2 2420        JMP HANDLERR YES
D419- 20 FB DA 2430 .1     JSR CRDO     PRINT <RETURN>
D41C- 20 5A DB 2440        JSR OUTQUES  PRINT "?"
D41F- BD 60 D2 2450 .2     LDA ERROR.MESSAGES,X
D422- 48       2460        PHA          PRINT MESSAGE
D423- 20 5C DB 2470        JSR OUTDO
D426- E8       2480        INX
D427- 68       2490        PLA
D428- 10 F5    2500        BPL .2

D42A- 20 83 D6 2510        JSR STKINI   FIX STACK, ET AL

D42D- A9 50    2520        LDA #QT.ERROR   PRINT " ERROR" AND BELL
D42F- A0 D3    2530        LDY /QT.ERROR
               2540 *--------------------------------
               2550 *      PRINT STRING AT (Y,A)
               2560 *      PRINT CURRENT LINE # UNLESS IN DIRECT MODE
               2570 *      FALL INTO WARM RESTART
               2580 *--------------------------------
               2590 PRINT.ERROR.LINNUM
D431- 20 3A DB 2600        JSR STROUT      PRINT STRING AT (Y,A)


For example, the CONT command @ $D896 prints this error message:

    ?CAN'T CONTINUE ERROR

D898- A2 D2    3040        LDX #ERR.CANTCONT
D89A- A4 7A    3050        LDY OLDTEXT+1     MEANINGFUL RE-ENTRY?
D89C- D0 03    3060        BNE .1            YES
D89E- 4C 12 D4 3070        JMP ERROR         NO

Note that the string "CANT CONTINUE" is @ $D332.


We can reproduce that with this assembly:

               ERR.CANTCONT EQU $D2 ; $D332 - $D260

300: A2 D2     LDX #ERR.CANTCONT
302: 4C 12 D4  JMP ERROR

> I think you cannot use an Applesoft entry point since it's
> not a routine--if Applesoft prints an error message, it stops the program
> and goes back to the "]" prompt, and I think it just does all of that
> without making the error message a subroutine.

Correct, it is part of the main REPL.  Once the main error message is printed, the string "ERROR" is printed @ $D42D and then execution of Applesoft continues @ $D43C RESTART.


If you want to just print the error then this short ML stub could be used:

300:A6 DE           ldx $DE  ; get Applesoft Error number
302:BD 60 D2 .1     lda ERROR.MESSAGES,X
305:48              pha
307:09 80           ora #$80
308:20 5C DB        jsr COUT
30B:E8              inx
30C:68              pla
30D:10 F3           bpl .2
30F:60              rts

300:A6 DE BD 60 D2 48 09 80 20 ED FD E8 68 10 F3 60

Michael

[toc] | [prev] | [next] | [standalone]


#4992

FromMichael Pohoreski <michael.pohoreski@gmail.com>
Date2019-01-31 23:01 -0800
Message-ID<2b9c4542-55b8-4f71-97d1-e0b5ad57b5b4@googlegroups.com>
In reply to#4986
= Demo =

1 DATA 32,251,218,32,90,219,166,222,189,96,210,72,9,128,32,237,253,232,104,16,243,169,80,160,211,76,58,219
2 FOR I = 0 TO 27: READ B: POKE 768+I,B:NEXT
3 REM REPLACE 0 WITH APPROX. ERROR MESG OFFSET SUCH AS 42
4 POKE 222,0
10 CALL 768


= ML =

We can use this ML helper/utility to replicate the Applesoft error printing:

     ORG $300
300  JSR CRDO
     JSR OUTQUES
     LDX ERRSTK-1
308  LDA ERROR.MESG,X
     PHA
     ORA #$80
     JSR COUT
     INX
     PLA
     BPL $308
     LDA #$50 ; Address of
     LDX #$D3 ; ERROR^G
     JMP STROUT

= How it was made =

We can convert the assembly HEX to DATA decimal statements via this JS snippet:

  var asc ="20 FB DA 20 5A DB A6 DE BD 60 D2 48 09 80 20 ED FD E8 68 10 F3 A9 50 A0 D3 4C 3A DB ";
  var n = asc.length, text = "1 DATA ";
  for( var i = 0; i < n; i += 3 )
    text += parseInt( "0x" + asc.substr( i, 2 ), 16 ) + ',';
  console.log( text );
  console.log( "FOR I = 0 TO " + ((i/3)-1) );

[toc] | [prev] | [next] | [standalone]


#4994

Fromawanderin <awanderin@gmail.com>
Date2019-02-02 11:32 -0700
Message-ID<yubpnsaavnc.fsf@gmail.com>
In reply to#4992
Michael Pohoreski <michael.pohoreski@gmail.com> writes:

> = Demo =
>
> 1 DATA 32,251,218,32,90,219,166,222,189,96,210,72,9,128,32,237,253,232,104,16,243,169,80,160,211,76,58,219
> 2 FOR I = 0 TO 27: READ B: POKE 768+I,B:NEXT
> 3 REM REPLACE 0 WITH APPROX. ERROR MESG OFFSET SUCH AS 42
> 4 POKE 222,0
> 10 CALL 768
>
>
> = ML =
>
> We can use this ML helper/utility to replicate the Applesoft error printing:
>
>      ORG $300
> 300  JSR CRDO
>      JSR OUTQUES
>      LDX ERRSTK-1
> 308  LDA ERROR.MESG,X
>      PHA
>      ORA #$80
>      JSR COUT
>      INX
>      PLA
>      BPL $308
>      LDA #$50 ; Address of
>      LDX #$D3 ; ERROR^G
>      JMP STROUT
>
> = How it was made =
>
> We can convert the assembly HEX to DATA decimal statements via this JS snippet:
>
>   var asc ="20 FB DA 20 5A DB A6 DE BD 60 D2 48 09 80 20 ED FD E8 68 10 F3 A9 50 A0 D3 4C 3A DB ";
>   var n = asc.length, text = "1 DATA ";
>   for( var i = 0; i < n; i += 3 )
>     text += parseInt( "0x" + asc.substr( i, 2 ), 16 ) + ',';
>   console.log( text );
>   console.log( "FOR I = 0 TO " + ((i/3)-1) );
>

Here's an all-Applesoft way to do it.  Substitute your choice of error
on line 20...

10  ONERR  GOTO 1000
20  PRINT 1 / 0 : REM Generate error
30  END
1000 BE = 53856
1010 EA = BE +  PEEK (222)
1015  GOSUB 1050
1020 EA = BE + 240: GOSUB 1050
1030  PRINT " IN LINE " PEEK (218) + 256 *  PEEK (219)
1040  END
1050 C =  PEEK (EA): IF C > 0 AND C < 128 THEN  PRINT  CHR$ (C);:EA = EA + 1: GOTO 1050
1055  IF C >  = 128 THEN  PRINT  CHR$ (C);
1060  RETURN

--
Jerry    awanderin at gmail dot com

[toc] | [prev] | [next] | [standalone]


#4996

FromJeff Blakeney <CUTjeffrey_blakeney@yahoo.ca>
Date2019-02-02 22:56 -0500
Message-ID<q35op4$ouf$1@dont-email.me>
In reply to#4994
On 2019-02-02 1:32 p.m., awanderin wrote:
> Here's an all-Applesoft way to do it.  Substitute your choice of error
> on line 20...
> 
> 10  ONERR  GOTO 1000
> 20  PRINT 1 / 0 : REM Generate error
> 30  END
> 1000 BE = 53856
> 1010 EA = BE +  PEEK (222)
> 1015  GOSUB 1050
> 1020 EA = BE + 240: GOSUB 1050
> 1030  PRINT " IN LINE " PEEK (218) + 256 *  PEEK (219)
> 1040  END
> 1050 C =  PEEK (EA): IF C > 0 AND C < 128 THEN  PRINT  CHR$ (C);:EA = EA + 1: GOTO 1050
> 1055  IF C >  = 128 THEN  PRINT  CHR$ (C);
> 1060  RETURN

Just curious why you are checking for C being from 1 to 127 and then 
later checking to see if it is greater than 127.  In both cases you are 
printing CHR$(C).

C will always be between 0 and 255 so the first check could be reduced 
to just "IF C < 128 THEN PRINT CHR$(C);".

I'm assuming you did this to avoid printing the high ASCII last 
character so line 1055 should probably be "IF C > 127 THEN PRINT 
CHR$(C-128);".  However, as we know that the condition that exits the 
loop is that C is greater than 127 all you really need on line 1055 is 
"PRINT CHR$(C-128);".

[toc] | [prev] | [next] | [standalone]


#4997

Fromgids.rs@sasktel.net
Date2019-02-03 10:19 -0800
Message-ID<a633aa85-3b85-43df-bb6b-e34e21daebbe@googlegroups.com>
In reply to#4996
On Saturday, February 2, 2019 at 9:56:21 PM UTC-6, Jeff Blakeney wrote:
> On 2019-02-02 1:32 p.m., awanderin wrote:
> > Here's an all-Applesoft way to do it.  Substitute your choice of error
> > on line 20...
> > 
> > 10  ONERR  GOTO 1000
> > 20  PRINT 1 / 0 : REM Generate error
> > 30  END
> > 1000 BE = 53856
> > 1010 EA = BE +  PEEK (222)
> > 1015  GOSUB 1050
> > 1020 EA = BE + 240: GOSUB 1050
> > 1030  PRINT " IN LINE " PEEK (218) + 256 *  PEEK (219)
> > 1040  END
> > 1050 C =  PEEK (EA): IF C > 0 AND C < 128 THEN  PRINT  CHR$ (C);:EA = EA + 1: GOTO 1050
> > 1055  IF C >  = 128 THEN  PRINT  CHR$ (C);
> > 1060  RETURN
> 
> Just curious why you are checking for C being from 1 to 127 and then 
> later checking to see if it is greater than 127.  In both cases you are 
> printing CHR$(C).
> 
> C will always be between 0 and 255 so the first check could be reduced 
> to just "IF C < 128 THEN PRINT CHR$(C);".
> 
> I'm assuming you did this to avoid printing the high ASCII last 
> character so line 1055 should probably be "IF C > 127 THEN PRINT 
> CHR$(C-128);".  However, as we know that the condition that exits the 
> loop is that C is greater than 127 all you really need on line 1055 is 
> "PRINT CHR$(C-128);".


No need to duplicate the CHR$(C)or have multiple lines.

1050 C= PEEK(EA): PRINT CHR$(C): EA = EA + 1: ON C < 128 GOTO 1050: RETURN

[toc] | [prev] | [next] | [standalone]


#4999

FromMichael Barry <barrym95838@yahoo.com>
Date2019-02-04 00:42 -0800
Message-ID<a370ddcb-2c8f-4090-9346-cf03fe965f1a@googlegroups.com>
In reply to#4997
On Sunday, February 3, 2019 at 10:19:56 AM UTC-8, gid...@sasktel.net wrote:
> 
> No need to duplicate the CHR$(C)or have multiple lines.
> 
> 1050 C= PEEK(EA): PRINT CHR$(C): EA = EA + 1: ON C < 128 GOTO 1050: RETURN

Nice optimization, but you need a ; after CHR$(C) and you also need to
 handle the C = 0 issue or avoid it as I described above with:

1020  PRINT " ERROR" CHR$ (7); 

Mike B. 

[toc] | [prev] | [next] | [standalone]


#4998

FromMichael Barry <barrym95838@yahoo.com>
Date2019-02-04 00:31 -0800
Message-ID<10f55cbd-6c74-4b6a-825e-765889ff747c@googlegroups.com>
In reply to#4996
On Saturday, February 2, 2019 at 7:56:21 PM UTC-8, Jeff Blakeney wrote:
> 
> Just curious why you are checking for C being from 1 to 127 and then 
> later checking to see if it is greater than 127.  In both cases you are 
> printing CHR$(C).
> 
> C will always be between 0 and 255 so the first check could be reduced 
> to just "IF C < 128 THEN PRINT CHR$(C);".
> 
> I'm assuming you did this to avoid printing the high ASCII last 
> character so line 1055 should probably be "IF C > 127 THEN PRINT 
> CHR$(C-128);".  However, as we know that the condition that exits the 
> loop is that C is greater than 127 all you really need on line 1055 is 
> "PRINT CHR$(C-128);".

The loop will also exit if C is 0, (like at 54103), in which case you
 would trigger an illegal quantity error trying to PRINT CHR$(C-128);

Triggering an error while inside your error handler may fall into the
 category of undesirable behavior.  A simple way around that would be
 to replace Jerry's line 1020 with:

1020  PRINT " ERROR" CHR$ (7);

Mike B.

[toc] | [prev] | [next] | [standalone]


#5001

FromJeff Blakeney <CUTjeffrey_blakeney@yahoo.ca>
Date2019-02-04 10:27 -0500
Message-ID<q39ll9$u0r$1@dont-email.me>
In reply to#4998
On 2019-02-04 3:31 a.m., Michael Barry wrote:
> The loop will also exit if C is 0, (like at 54103), in which case you
>   would trigger an illegal quantity error trying to PRINT CHR$(C-128);

In the Jerry's original code, yes, the loop could end if a zero is 
encountered but I did mention in my reply that we know that C will be 
between 0 and 255 so instead of checking for C being greater than 1 or 
less than 128, we could simply check for C being less than 128 and then 
continue looping.  With my corrections the loop would only exit if C was 
128 or greater so CHR$(C-128) would never cause an error.

I seem to recall there being times when you didn't want to print with 
either low ASCII or high ASCII as you might get MouseText or something 
else instead but I no longer remember the details.  Printing CHR$(C-128) 
was just to make all the text low ASCII but probably isn't necessary.

> Triggering an error while inside your error handler may fall into the
>   category of undesirable behavior.
Causing an error in your error handler without having first turned off 
error handling would definitely cause problems.  :)

> A simple way around that would be to replace Jerry's line 1020 with:
> 
> 1020  PRINT " ERROR" CHR$ (7);
I don't see that as fixing possible errors occurring in the error 
handler but that would definitely make it so that you didn't need to 
call a subroutine to print two messages seeing as we know what the 
second one is going to be.  That would mean Jerry's code could be 
reduced to:

10  ONERR  GOTO 1000
20  PRINT 1 / 0 : REM Generate error
30  END
1000 EA = BE + PEEK (222)
1010 C = PEEK (EA): PRINT CHR$(C);: IF C > 127 THEN EA = EA + 1: GOTO 1010
1020 PRINT " ERROR IN LINE " PEEK(218) + 256 * PEEK(219)
1030 END

You could add a CHR$(7) to line 1020 as well if you want the bell and 
could possibly turn off error handling before ending the program.  If I 
remember correctly that is done with POKE 216, 0.

[toc] | [prev] | [next] | [standalone]


#5006

FromBill Chatfield <billchatfield1@gmail.com>
Date2019-02-09 09:28 -0800
Message-ID<eb35a8b3-e80d-4bb4-abcf-17ea292f8db6@googlegroups.com>
In reply to#5001
This is some awesome code! I never would have thought you could do it but, you guys reduced it to just a few lines.

[toc] | [prev] | [next] | [standalone]


#5007

FromMichael Pohoreski <michael.pohoreski@gmail.com>
Date2019-02-09 13:57 -0800
Message-ID<399b265a-4857-4cb9-9ee9-23a38d74d49f@googlegroups.com>
In reply to#5006
/Oblg. Mic. Drop =P

TL:DR;
======

This correctly handles the "BREAK" null-terminating message (null @ $D364) and also matches the output of Ctrl-C since it _doesn't_ print "ERROR".

I included the DEF FN for completeness.  I haven't seen a way to trigger "Illegal direct" when running.

Remove the first "rem" to test each error:

 0  DIM A(1):B$ = "-":FOR I=1 TO 7:B$ = B$ + B$:NEXT:POKE 222,0
 9  ONERR GOTO 1000 
10  rem NEXT     :REM   0 = $D260 Next without for
11  rem SPEED    :REM  16 = $D270 Syntax
12  rem RETURN   :REM  22 = $D276 Return without gosub
13  rem READ A   :REM  42 = $D28A Out of data
14  rem COLOR=-1 :REM  53 = $D295 Illegal quantity
15  rem ? 1E39+1 :REM  69 = $D2A5 Overflow
16  rem HIMEM:0  :REM  77 = $D2AD Out of memory
17  rem GOTO 1   :REM  90 = $D2BA Undef'd statement
18  rem ? A(2)   :REM 107 = $D2BA Bad subscript
19  rem DIM A(2) :REM 120 = $D2D8 Redim'd array
20  rem ? 1/0    :REM 133 = $D2E5 Division by zero
21  DEF FN F(X)=1:REM 149 = $D2F5 Illegal direct (only in direct mode)
22  rem A$ = 3.1 :REM 163 = $D303 Type mismatch
23  rem C$=B$+B$ :REM 176 = $D310 String too long
24  REM Note (*) :REM 191 = $D31F Formula too complex
25  REM Note (**):REM 210 = $D332 Can't continue (only in direct mode)
26  rem ?FN A(1) :REM 224 = $D340 Undef'd function
27  rem STOP     :REM 253 = $D35D Break in; Note (***), error code untouched  @ $D86E
28  rem CONT     :REM 255 ->$D35D Break in; Note (***), error code set to 255 @ $D863
30  ? PEEK(222):END
1000 Z = PEEK(222)=255:EA = 53856 + PEEK(222) - Z:PRINT "?";
1010 C = PEEK (EA): PRINT CHR$(C);: EA = EA + 1: ON C AND C < 128 GOTO 1010:? MID$(" ERROR",1,6*(1-Z) );" IN LINE " PEEK(218)+256 * PEEK(219):END




Cole's, er Michael's, Notes:
============================

(*) Formula too complex

    This is caused when Applesoft tries to allocate more than
    2 string temporaries.  Since Applesoft tends to do garbage collection
    often this was tricky to reproduce but our "friendly" C64 pals
    noticed that the command POS() takes a dummy argument -- we can force
    Applesoft to allocate 3 temporary strings in between garbage collection.

    Direct mode:

        ? POS("")POS("")POS("")
   
    Output:

        01
        ?FORMULA TOO COMPLEX ERROR
   
    We can use string concatenation to remove printing the numeric values

        ? POS("")+POS("")+POS("")

    Output:

        ?FORMULA TOO COMPLEX ERROR
   
    Running mode:
   
        First lets verify we can trigger this message:
   
    Example 1a:

        NEW
        1 C=POS("") + POS("") + POS("")
        7 PRINT C:END
        8 PRINT PEEK(222):END
        RUN

    Output:
   
        ?FORMULA TOO COMPLEX IN 7

    And verify that ONERR works correctly ...
    
    Example 1b:

        NEW
        0 ONERR GOTO 8
        1 ? 1/0
        7 PRINT C:END
        8 PRINT PEEK(222):END
        RUN        

    OUTPUT:
    
        133

    Which is what we expect: Division by zero.

        Unfortunately ONERR GOTO doesn't play nice when this temporary
    string concatenation is triggered. :-/ Adding the error handler stops
    the program!?
    
    Example 1c:

        NEW
        0 ONERR GOTO 8
        1 C=POS("") + POS("") + POS("")
        7 PRINT C:END
        8 PRINT PEEK(222):END
        RUN        

    Annnd we get a hard crash into $0040 (or $3D or $3E) ...
    
    Output:

        0040- A=B4 X=00 Y=01 P=B4 S=FE

    Yikes!

    Let's return (soft warm-start) to Applesoft ...
    
        <Ctrl-C>
        LIST

    ... we *then* get the error message?!
    
        ?FORMULA TOO COMPLEX ERROR

    WTF?  Trying again ...
    
        LIST
        
    ... we *finally* see our program?
    
    Output:

        NEW
        0 ONERR GOTO 8
        1 C=POS("") + POS("") + POS("")
        7 PRINT C:END
        8 PRINT PEEK(222):END
    
    Note: In this state some commands work, such as HOME 

        RUN
        <Ctrl-C>
        HOME
        LIST
    
    But others don't:
    
        RUN
        <Ctrl-C>
        ? 1

    Output:
    
        003E- A=B4 X=00 Y=01 P=B0 S=FE
        ?FORMULA TOO COMPLEX ERROR

    Power cycling, booting DOS 3.3 (8/25/80), and running the program multiple
    times will eventually do nothing -- we can get all sorts of bogus messages:
    
        RUN
        RUN
        ? PEEK(222)
        
    Output
        ?OUT OF MEMORY ERROR

    *sigh*

    Even safely cold-start Applesoft @ $E000

        CALL 57344

    may not get out of this weird state!


    What if we modify line 24 of the original program?

        NEW
         0  DIM A(1):B$ = "-":FOR I=1 TO 7:B$ = B$ + B$:NEXT:POKE 222,0
         9  ONERR GOTO 1000 
        10  rem NEXT     :REM   0 = $D260 Next without for
        11  rem SPEED    :REM  16 = $D270 Syntax
        12  rem RETURN   :REM  22 = $D276 Return without gosub
        13  rem READ A   :REM  42 = $D28A Out of data
        14  rem COLOR=-1 :REM  53 = $D295 Illegal quantity
        15  rem ? 1E39+1 :REM  69 = $D2A5 Overflow
        16  rem HIMEM:0  :REM  77 = $D2AD Out of memory
        17  rem GOTO 1   :REM  90 = $D2BA Undef'd statement
        18  rem ? A(2)   :REM 107 = $D2BA Bad subscript
        19  rem DIM A(2) :REM 120 = $D2D8 Redim'd array
        20  rem ? 1/0    :REM 133 = $D2E5 Division by zero
        21  DEF FN F(X)=1:REM 149 = $D2F5 Illegal direct (only in direct mode)
        22  rem A$ = 3.1 :REM 163 = $D303 Type mismatch
        23  rem C$=B$+B$ :REM 176 = $D310 String too long
        24 C=POS("") + POS("") + POS(""):REM 191 = $D31F Formula too complex
        25  REM Note (**):REM 210 = $D332 Can't continue (only in direct mode)
        26  rem ?FN A(1) :REM 224 = $D340 Undef'd function
        27  rem STOP     :REM 253 = $D35D Break in; Note (***), error code untouched  @ $D86E
        28  rem CONT     :REM 255 ->$D35D Break in; Note (***), error code set to 255 @ $D863
        30  ? PEEK(222):END
        1000 Z = PEEK(222)=255:EA = 53856 + PEEK(222) - Z:PRINT "?";
        1010 C = PEEK (EA): PRINT CHR$(C);: EA = EA + 1: ON C AND C < 128 GOTO 1010:PRINT MID$(" ERROR",1,6*(1-Z) ) ;" IN LINE " PEEK(218)+256 * PEEK(219):END
        RUN
   
    Unfortunately we get a hang!  Ctrl-C doesn't even work!!
    If we Ctrl-Rest and type a command:
    
        LIST

    We then get the error message?!
    
        ?FORMULA TOO COMPLEX ERROR
   
    I haven't been able to consistently reproduce the following BUT sometimes
    running the following program Applesoft is now off in never-never land.
    Once we are in this state ...
    
        NEW
        1 C=POS("") + POS("") + POS("")
        7 PRINT C:END
        8 PRINT PEEK(222):END
        LIST
   
    ... unfortunately, trying to enter in ANY statement is now ignored!
   
       2 REM Where did my program go?!
       LIST

    Output (nothing!):


    Same thing when trying to assigning to a variable:

       2 "Look ma! Comments without REM!"
       LIST

    Output (nothing!):
       
    Reference:
       https://www.c64-wiki.com/wiki/POS


(**) "Can't continue"

    From the Blue Book,"Applesoft II Reference Manaual", 1978, Page 27
    http://www.apple-iigs.info/doc/fichiers/bluebook.pdf
    
    "Remember, if you terminate a program and expect to continue it later,
    you must not get any errors or type in any new program lines. If you do, you
    won't be able to continue and will get a "CAN'T CONTINUE" error. It is
    impossible to continue a direct command. CONT always resumes execution in your
    program when control-C was typed."

    For example:

        NEW
        1 HOME
        RUN
    
    We can "continue" running    

        CONT
    
    Entering in new statement such as 

        2 REM

    Will trigger STKINI ($D683) to be called causing CONT to error.
    
        CONT

        ?CAN'T CONTINUE ERROR

    Running mode:
    
         I haven't been able to figure out a way to trigger this message
    when not in direct mode @ $D898 due to the check at $D89A.
    
    D896- D0 17     CONT   BNE RTS.4         IF NOT END OF STATEMENT, DO NOTHING
    D898- A2 D2            LDX #ERR.CANTCONT
    D89A- A4 7A            LDY OLDTEXT+1     MEANINGFUL RE-ENTRY?
    D89C- D0 03            BNE .1            YES
    D89E- 4C 12 D4         JMP ERROR         NO
    D8A1- A5 79     .1     LDA OLDTEXT       RESTORE TXTPTR
    D8A3- 85 B8            STA TXTPTR
    D8A5- 84 B9            STY TXTPTR+1
    D8A7- A5 77            LDA OLDLIN        RESTORE LINE NUMBER
    D8A9- A4 78            LDY OLDLIN+1
    D8AB- 85 75            STA CURLIN
    D8AD- 84 76            STY CURLIN+1
    D8AF- 60        RTS.4  RTS



(***) Ctrl-C vs STOP

    Ctrl-C may or may not set the error code.

    * By itself, it WON'T. Neither will STOP.
    * When trapped with ON ERROR it WILL set the error code to 255.

    Example 3a:

       NEW
       1 POKE 222,0:GOTO 1
       RUN

       <CTRL-C>
       PRINT PEEK(222)

    Output:
    
       BREAK IN 1
       0

    Example 3b:
    
       NEW
       2 POKE 222,0:STOP
       RUN
       PRINT PEEK(222)

   Output:
   
       BREAK IN 2
       0
       
    Direct Mode:

       STOP @ $D86E prints the message at $D260 + $FD = $D35D @ END4 = $D88A.

       "^mBREAK^g" -- this sadly is inconsistent with the rest of the error messages and is null terminated:

       D35D: DB  0D ; Ctrl-M
       D35E: ASC "BREAK"
       D363: DB  07 ; Ctrl-G
       D364: DB  0  ; Null-terminate string
   
    Running mode:

       STOP and <CTRL-C> prints the two message at:
   
       $D35D "BREAK"
       $D358 " IN "

    They do NOT print "ERROR" like the rest of the error messages do.


Back to Minecraft ...

Michael

[toc] | [prev] | [next] | [standalone]


#5000

FromMichael Barry <barrym95838@yahoo.com>
Date2019-02-04 01:06 -0800
Message-ID<995794d4-c1a8-4a7e-aafb-2f91aca96229@googlegroups.com>
In reply to#4994
On Saturday, February 2, 2019 at 10:32:40 AM UTC-8, awanderin wrote:
> 
> Here's an all-Applesoft way to do it.  Substitute your choice of error
> on line 20...
> 
> 10  ONERR  GOTO 1000
> 20  PRINT 1 / 0 : REM Generate error
> 30  END
> 1000 BE = 53856
> 1010 EA = BE +  PEEK (222)
> 1015  GOSUB 1050
> 1020 EA = BE + 240: GOSUB 1050
> 1030  PRINT " IN LINE " PEEK (218) + 256 *  PEEK (219)
> 1040  END
> 1050 C =  PEEK (EA): IF C > 0 AND C < 128 THEN  PRINT  CHR$ (C);:EA = EA + 1: GOTO 1050
> 1055  IF C >  = 128 THEN  PRINT  CHR$ (C);
> 1060  RETURN
> 
> --
> Jerry    awanderin at gmail dot com

Here's my attempt at an equivalent version:

10  ONERR  GOTO 1000 
20  PRINT 1 / 0 : REM Generate error 
30  END 
1000  FOR EA = 53856 +  PEEK (222) TO 54102 
1010  C =  PEEK (EA):  PRINT  CHR$ (C);
1015  IF C > 127 THEN EA = 54095
1020  NEXT 
1030  PRINT " IN LINE " PEEK (218) + 256 *  PEEK (219) 
1040  END 

Mike B.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.sys.apple2.programmer


csiph-web