Some classic BASIC code and one way to do the same thing in BAM

Started by CharlieJV, Jun 11, 2023, 03:09 AM

Previous topic - Next topic

CharlieJV

Nothing revolutionary, and some things changed to fit the way my sponge works:

' Program from Handbook of BASIC: for the IBM PC, XT, AT, PS/2, and compatibles (page 10), 1988
' https://archive.org/details/handbookofbasicf00schn

<!-- Here's a way to quickly comment out a large block of code

' This works as-is in BAM

10 INPUT "Name: "; N$
20 FOR J = 1 TO LEN(N$)
30  L = ASC(MID$(N$,J,1))
40  IF L > 96 AND L < 123 THEN L = L-32
50  CN$ = CN$ + CHR$(l)
60 NEXT J
70 PRINT CN$

 end of commented out code (NOTE: code commented out like this will be excluded from exports) -->

' One way to do the same in BAM
' All about helping me distinguish/identify the pieces


VAR cn$ = "", n$, _
    j%, l%
INPUT "Name: "; n$
FOR j% = 1 TO LEN(n$)
    LET l% = ASC( MID$( n$,j%,1 ) )
    IF BETWEEN( l%, 97, 122 ) THEN LET l% -= 32
    LET cn$ += CHR$(l%)
NEXT j%
PRINT cn$

ZXDunny

So many ways and it leads nicely into your foray into IFF (or in my case IIF):



of course there are better, quicker ways but I do love IIF$ :)

CharlieJV

Quote from: ZXDunny on Jun 11, 2023, 03:03 PMSo many ways and it leads nicely into your foray into IFF (or in my case IIF):



of course there are better, quicker ways but I do love IIF$ :)

That is nicely compact.

Yeah, I'm really liking IIF.  Like so many things, my implementation of it will come with a "time and place" caveat, but that's good.  Eyeing BAM as a no-fuss no-muss handy-dandy thing to learn programming and software development lifecycle concepts, training to think about different ways of doing things (the pluses and minuses) is a good thing.

While watching the hockey game last night, a thought out of nowhere: I'm going to pick one of these old BASIC encyclopedias, and I'm going to go through every statement/function, and find short segments of code to make sure they work in BAM, see what minimal changes need to be done to address any BAM differences/shortcomings, and then "BAM-ify and Charlie-fy" to sanity check BAM thingies.

Strangely cathartic ...

Kind of strange cathartic thing.


ZXDunny

I'm sure we've all been there. I scoured the web for literal years looking for stuff that I wanted to be able to do quickly in SpecBAS. I'm still at it now. It's a monster that has taken over my life.

But it's also fun, you know?

CharlieJV

Another program:

' Program from Handbook of BASIC: for the IBM PC, XT, AT, PS/2, and compatibles (page 39), 1988
' https://archive.org/details/handbookofbasicf00schn


<!-- The program as-is won't work in BAM because BAM requires arrays to be declared

10 SCREEN 0 : CLS : KEY OFF
20 FOR J = 1 TO 9
30   READ A(J)
40   FOR K = 1 TO A(J)
50     LOCATE 19-K, 4+2*J+6*(INT((J-1)/3)
60     PRINT CHR$(176+J MOD 3)
70 NEXT K, J
80 LOCATE 20, 7
90 PRINT "JAN"; SPC(9); "FEB"; SPC(9); "MAR"
100 PRINT : PRINT
110 PRINT TAB(5); CHR$(177); "  1982";
120 PRINT SPC(5); CHR$(178); "  1983";
130 PRINT SPC(5); CHR$(176); "  1984";
140 DATA 12,15,7,5,3,8,4,7,6



'  With the array declared, the program otherwise works as-is
'  However, although BAM recognizes the TAB function, it isn't yet properly implemented
'  So, I replaced TAB with SPC

05 DIM AS INTEGER A(1 TO 9) ' ✏ This line added
10 SCREEN 0 : CLS : KEY OFF
20 FOR J = 1 TO 9
30   READ A(J)
40   FOR K = 1 TO A(J)
50     LOCATE 19-K, 4+2*J+6*(INT((J-1)/3))
60     PRINT CHR$(176+J MOD 3)
70 NEXT K, J
80 LOCATE 20, 7
90 PRINT "JAN"; SPC(9); "FEB"; SPC(9); "MAR"
100 PRINT : PRINT
110 PRINT SPC(5); CHR$(177); "  1982"; ' ✏ replaced TAB(5) with SPC(5)
120 PRINT SPC(5); CHR$(178); "  1983";
130 PRINT SPC(5); CHR$(176); "  1984";
140 DATA 12,15,7,5,3,8,4,7,6

     -->

'  One way to rewrite this for BAM
'  BAM recognizes the "KEY OFF" syntax, but does nothing with it, so removed
'  BAM screen default is 0, and program starts with cleared console

Declarations:
  DIM a%(1 TO 9)
  CONST cm$ = SPC(9) ' space between columns
  
Chart:
  FOR j% = 1 TO 9
      READ a%(j%)
      FOR k% = 1 TO a%(j%)
          LOCATE [ 19 - k% ], _
                 [ 4 + { 2 * j% } + { 6 * [INT( {j% - 1} / 3 )] } ]
          PRINT CHR$( 176  + [ j% MOD 3 ] )
      NEXT k%
  NEXT j%

Footer:
  LOCATE 20, 7
  PRINT "JAN" + cm$ + "FEB" + cm$ + "MAR"
  PRINT : PRINT
  PRINT SPC(5); CHR$(177); "  1982";
  PRINT SPC(5); CHR$(178); "  1983";
  PRINT SPC(5); CHR$(176); "  1984";
    
END

DATA 12,15,7,5,3,8,4,7,6