Jump to content
IGNORED

A worse programmers questions


Sid1968

Recommended Posts

39 minutes ago, TheBF said:

I think you could even define a custom SPLIT3, from the existing components and have just 1 line of text at the top for example making it 256x184 for plotting.

 

Yes, except that the font would then be limited to 32 characters (ASCII 96..127), which would need manipulation similar to TI Basic’s offset to display whatever ASCII subset you desired.

 

It might be possible to manipulate the Pattern Descriptor Table (PDT) to get more characters (at the expense of the already limited number of sprite patterns) if you placed the SPLIT3 text window at the bottom of the display. It still might require manipulation of the PDT. One problem is that the PDT must be on a 2-KiB boundary. If FILES were changed to 1, that would free up 518 bytes more above the Sprite Pattern Descriptor Table (SPDT) for a total of 123 character patterns starting at the bitmap-mode SPDT. I just do not remember whether the PDT can be moved to an arbitrary 2-KiB boundary or must be in the position analogous to its display position as is the case with SPLIT and SPLIT2 modes.

 

...lee

  • Thanks 1
Link to comment
Share on other sites

26 minutes ago, Asmusr said:

 The Missing Link (TML) is an assembly extension to XB that provides bitmap mode, but using that means you have less space for your program data, and the overall space ends up being closer to that of Cortex BASIC. 

Actually, you have the same 24K of room for the XB program. You do have considerably less room for the stack in the VDP which is where strings are kept and (as I remember) subprogram names. There is a section in the manual on how to conserve string space

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

31 minutes ago, Asmusr said:

It doesn't look like Cortex BASIC has the ability to draw text at any point in bitmap mode (256x192), so drawing labels on the tick marks is not something I will attempt to do.

 

Note that TI BASIC, XB, RXB, etc. don't support bitmap mode out-of-the-box. Bitmap mode is using 12K of the 16K video memory, leaving almost no space for program data (the disk DSR also uses some). Tursi showed how you can draw a limited bitmap-like image by redefining character patterns, but this technique is limited by the complexity of the image. The Missing Link (TML) is an assembly extension to XB that provides bitmap mode, but using that means you have less space for your program data, and the overall space ends up being closer to that of Cortex BASIC. 

If you use the SAMS in RXB I could move the normal BIT MAP mode to RAM into upper 24K (12K bit map mode), draw the screen in RAM and use RXB subroutine CALL MOVES to move that RAM to VDP memory.

I do similar to this in RXB SAMS demos all the time, but not with Bitmap mode yet. New thing to do I guess.

Of course normal location of Screen could not be used as that would overwrite all buffers but I guess I could copy them first and when done put them back.

Would need to use CALL USER to do this as way to complicated to do from Programs mode, but Edit mode would work as only the file buffer is needed to keep running, all else in memory is just copied or replaced.

  • Thanks 1
Link to comment
Share on other sites

4 hours ago, senior_falcon said:

Mine is a 1997 SW2. Sadly the rust from the road salt used around here is really chewing up the steel underneath the car. It has 1 or maybe 2 years left before it shuffles off this mortal coil.

Why don't you drive yours?

LOL I bought a 2017 Chevy Cruz from Enterprise Car Rentals at a great price.

And the SW passenger door is staved in from a car hitting me, how many 1993 SW 4 door Saturn's are there, almost none.

I know of one in Portland but I only need that door.

Edited by RXB
Added Text.
  • Like 1
Link to comment
Share on other sites

The issue with the memory consumption of the bitmap mode is of course the same when using Pascal.

The p-system has two code pools on the TI 99/4A. It can run user programs from either VDP RAM or from the 24 K RAM. When using bitmap, I set a pointer which will inform the system about where the available memory starts in VDP RAM. This means that the p-system will load more code in 24 K RAM instead. Fortunately, the p-system has a very good support for segmenting programs, so you don't need all of them in memory at the same time. Thus, with some planning when designing your program, you can still run large programs, without having to handle the memory swapping yourself.

 

It was many years ago now, but if I remember correctly, I save the character patterns as they are in VDP RAM, prior to entering bitmap mode. Then I use these patterns when the special print routine in the graphics package is called. I think I saved characters in the range 32..127, but not outside that. It's at least all normal characters. When I restore to the normal text mode again, I reload these saved characters, but set those in the ranges 0..31 and 128..255 to blank.

 

What's left to do in my turtlegraphics unit is some variations of how to write text. Now it only supports overwrite, i.e. writing by turning pixels on, so the foreground color is used. I did plan to allow underwriting too, i.e. write with the background color, so you can create a text also in a filled field. Plus some other variations.

I've also not implemented the ability to store graphics in files, for later retrieval/reload.

I haven't implemented the viewport concept either. It's a concept where you can limit the impacted part of a screen to a specific box, like from 100,100 to 150,150. Any graphics sent outside this box isn't printed on the screen.

Handy to make a plot window at a part of a screen, without risking plotting into other areas by mistake.

  • Thanks 1
Link to comment
Share on other sites

39 minutes ago, senior_falcon said:

Actually, you have the same 24K of room for the XB program. You do have considerably less room for the stack in the VDP which is where strings are kept and (as I remember) subprogram names. There is a section in the manual on how to conserve string space

String space is what I meant by program data. I couldn't remember what exactly the VDP memory was used for.

  • Thanks 1
Link to comment
Share on other sites

43 minutes ago, RXB said:

LOL I bought a 2017 Chevy Cruz from Enterprise Car Rentals at a great price.

And the SW passenger door is staved in from a car hitting me, how many 1993 SW 4 door Saturn's are there, almost none.

I know of one in Portland but I only need that door.

The Cruz is a nice car with good fuel economy too.

http://www.car-part.com/

With this site (or similar) you can search for your door. They seem to go in the $100-200 range. A fellow whose nom-de-net is Richpin has excellent videos on how to fix Saturn S cars.

  • Like 2
Link to comment
Share on other sites

Nice to see you both, senior_falcon and Rich, talk in a companionate manner. ?

Rich, did I read you right, that you can solve the challenge (including the labeling of the Axis)?


Would be nice to read your progamlisting. ?

 

If i read further right, Cortex Basic can not solve the full labeling.

Till now we dont know if xb256 can solve the challenge. (Is this the right name of senior_falcons version?)

Edited by Sid1968
  • Like 1
Link to comment
Share on other sites

44 minutes ago, Sid1968 said:

Till now we dont know if xb256 can solve the challenge. (Is this the right name of senior_falcons version?)

XB256 is no better at this than any other normal XB. The Missing Link can do it because it gives a full bit mapped screen. Download The Missing Link and run the demo program. (TMLDEMO) In Graphics you will see a sin, cos, tan plot with labelling. There is no mystery in this; all the information you need is in my earlier post.

  • Thanks 1
Link to comment
Share on other sites

11 minutes ago, senior_falcon said:

XB256 is no better at this than any other normal XB. The Missing Link can do it because it gives a full bit mapped screen. Download The Missing Link and run the demo program. (TMLDEMO) In Graphics you will see a sin, cos, tan plot with labelling. There is no mystery in this; all the information you need is in my earlier post.

Thank you. Certainly i accept that you dont want to face the challenge.

Link to comment
Share on other sites

7 hours ago, Asmusr said:

It doesn't look like Cortex BASIC has the ability to draw text at any point in bitmap mode (256x192), so drawing labels on the tick marks is not something I will attempt to do.

 

Note that TI BASIC, XB, RXB, etc. don't support bitmap mode out-of-the-box. Bitmap mode is using 12K of the 16K video memory, leaving almost no space for program data (the disk DSR also uses some). Tursi showed how you can draw a limited bitmap-like image by redefining character patterns, but this technique is limited by the complexity of the image. The Missing Link (TML) is an assembly extension to XB that provides bitmap mode, but using that means you have less space for your program data, and the overall space ends up being closer to that of Cortex BASIC. 

In bitmap mode you can display text on a 32 character by 24 row grid - so easy to add labels if the tick marks happen to align with the character grid (or possibly tweak your axis scales so that they do align). If they don't align, then you could define the label text character bitmaps as stationary sprites which can be positioned with pixel accuracy.

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Stuart said:

In bitmap mode you can display text on a 32 character by 24 row grid - so easy to add labels if the tick marks happen to align with the character grid (or possibly tweak your axis scales so that they do align). If they don't align, then you could define the label text character bitmaps as stationary sprites which can be positioned with pixel accuracy.

In The Missing Link text does not have to align with the 24x32 grid. If you wanted Hello World! at r153 and c121 you would use CALL LINK("PRINT",153,121,"Hello World!) 

No problem getting the axes and the characters aligned. Suppose you wanted to use a 5x7 font giving a screen of 48 rows. Like Prego spaghetti sauce, "It's in there."

Link to comment
Share on other sites

On 10/15/2019 at 4:07 PM, TheBF said:

130 REM  DOTPLOT AT DOTROW,DOTCOL (0-based) 

This is very cool.  I need to try it this way. 

Thanks for taking the rest of my week away Tursi. ;)

Glad you like. I wrote that subroutine more than 30 years ago, and it's always fun to pull it out. ;)

  • Like 1
Link to comment
Share on other sites

17 hours ago, apersson850 said:

I'm aware that there once was a sidecar p-code card for the TI 99/4A. When I asked for a reincarnation of the p-code card, I didn't really consider whether it would be for the box or a sidecar. Today, a sidecar can be quite a bit more compact than the original one, though.

I started working on finding the references that would be needed to move the data to a cartridge, which would be great. But it's complex. :)

 

Link to comment
Share on other sites

On 10/15/2019 at 11:12 PM, Sid1968 said:

Thank you Tursi, very good. Great! Is it possible to improve it?

I don't think "improve" is the right word, you changed the rules after I posted it. ;)

 

There you go. However, until you actually sit and run it yourself, don't ask for more. ;)

 

Spoiler


REM PROGRAM TO DRAW SINE FROM -5 to 5
REM WITH ALL THE LABELS AND WHATEVER
REM - TURSI 2019

REM CC$ - hex codes for each definable character 33-159
REM HPAT$ - lookup tables for adding nibbles in hex
REM FONT$ - 3x5 bit definitions for drawing the 1-5 digits

100 REM PROGRAM START  
110 DIM CC$(127),HPAT$(4),FONT$(5)
120 GOTO 440

REM **************************************************
REM DOTPLOT IS HERE BASED ON THE MYTH THAT THE EARLY
REM LINES OF CODE RUN FASTER.
REM SET DOTROW,DOTCOL, and GOSUB to CALL IT

REM RELIES ON:
REM CURCHAR - the next unused char
REM STARTCHAR - the first definable character (0 in CC$)
REM LASTCHAR - the last definable character (ie: when we run out of ink!)
REM FIXCHAR - special to this version - below are defined chars that we aren't allowed to change

REM The operation is straight-forward. It calculates the screen position, and uses GCHAR to see
REM what is there. If it's a character the subroutine owns (>=FIXCHAR), this means we have already
REM defined it once, so we can just redefine it.

REM If it's the space character (32), we know we can allocate a new character to that location.

REM If it's in our space at all (>=STARTCHAR), then we know it's fixed, otherwise we can't touch it.

REM For a fixed char, we copy the definition that we have stored to a new character for modification.
REM In this app, fixed chars are used for the axes.

REM Finally, if it needed to allocate a new character, we check against LASTCHAR to see if we are
REM out. If we are, then plots that require a new character are ignored, but old chars can still be
REM redefined.

REM Once we know what character to redefine, we calculate which nibble to alter, and based on which
REM pixel inside that nibble we are setting, we use the HPOS lookup tables to add the new pixel to
REM the old value. Then we patch the string back together, CALL CHAR it, and save the new pattern off.

130 REM DOTPLOT AT DOTROW,DOTCOL (0-based)  

REM Classify the character already on the screen
140 MR=INT(DOTROW/8)+1
150 MC=INT(DOTCOL/8)+1
160 CALL GCHAR(MR,MC,CH)
170 IF CH>=FIXCHAR THEN 290
180 IF CH=32 THEN 260
190 IF CH>=STARTCHAR THEN 210
REM If we get here, it was a character we can't change.
200 RETURN

REM Here it is a fixed char, so copy out the pattern and assign a new character
REM Give up if there are no more characters to assign
210 TC$=CC$(CH-STARTCHAR)
220 CH=CURCHAR
230 CURCHAR=CURCHAR+1
240 IF CURCHAR>=LASTCHAR THEN 200
250 GOTO 300

REM Here we're allocating a new empty char to replace a space character.
REM Again, give up if there are no more characters to assign
260 CH=CURCHAR
270 CURCHAR=CURCHAR+1
280 IF CURCHAR>=LASTCHAR THEN 200
290 TC$=CC$(CH-STARTCHAR)

REM Determine the internal row and column. We don't have masking, but this works
REM Once we have that, we can determine which position in the string to change
300 XR=DOTROW-(MR-1)*8
310 XC=DOTCOL-(MC-1)*8
320 P=XR*2+1
330 IF XC<4 THEN 360
340 P=P+1
350 XC=XC-4

REM Now we extract the character from the working string, then use it and the
REM pixel offset to lookup the new character. Then, insert it back into the string.
360 X$=SEG$(TC$,P,1)
370 TT$=SEG$(HPAT$(XC),POS(HEX$,X$,1),1)
380 TC$=SEG$(TC$,1,P-1)&TT$&SEG$(TC$,P+1,16-P)

REM pretty much done! Assign the pattern, save it in our lookup table,
REM plot it to the screen, and return to caller!
390 CALL CHAR(CH,TC$)
400 CC$(CH-STARTCHAR)=TC$
410 CALL HCHAR(MR,MC,CH)
420 RETURN

REM **************************************************
REM this block prepares the plot function.
REM It resets the pattern lookup table to all blanks,
REM sets the CURCHAR,STARTCHAR and LASTCHAR (we use
REM ALL definable characters except space). Finally,
REM We set the lookup tables for hexadecimal conversion
REM and math.

430 REM INIT THE DOT PLOT  
440 FOR A=0 TO 127
450 CC$(A)="0000000000000000"
460 NEXT A
470 CURCHAR=33
480 STARTCHAR=33
490 LASTCHAR=159
500 HEX$="0123456789ABCDEF"
510 HPAT$(0)="89ABCDEF89ABCDEF"
520 HPAT$(1)="45674567CDEFCDEF"
530 HPAT$(2)="23236767ABABEFEF"
540 HPAT$(3)="1133557799BBDDFF"

REM Now we set the colors of all the color sets to black on grey
REM and clear the screen to get started
550 FOR A=1 TO 16
560 CALL COLOR(A,2,15)
570 NEXT A
580 CALL CLEAR

REM **************************************************
REM We were tasked to draw labelled X and Y axes. So first
REM we define normal chars for drawing them. We manually
REM allocate a couple by changing CURCHAR, and we reserve
REM the first two (vertical and horizontal lines) by setting
REM FIXCHAR. This lets the plot function copy our definition
REM when drawing near the lines without changing the character
REM pattern, which would change all of them. Note that the
REM cross in the middle is not a fixed char, since there is
REM only one of them, I don't care if the plot function updates it.

590 REM   DRAW THE AXES  
600 CURCHAR=36
610 FIXCHAR=35
620 CC$(0)="00000000000000FF"
630 CC$(1)="8080808080808080"
640 CC$(2)="80808080808080FF"
650 CALL CHAR(33,CC$(0))
660 CALL CHAR(34,CC$(1))
670 CALL CHAR(35,CC$(2))
680 CALL HCHAR(12,1,33,32)
690 CALL VCHAR(1,17,34,24)
700 CALL HCHAR(12,17,35)

REM Now we're going to start plotting pixels. I set the screen border
REM to blue to show we're working, then gosub to the block which draws
REM the tick marks and the numbers. It's a subroutine mostly cause
REM it was added later.

710 CALL SCREEN(5)
720 GOSUB 870

REM **************************************************
REM now we draw the actual plot. The positioning and the
REM numbers are based on the fact that the ticks on the
REM X axis are indented from the edges of the screen a
REM bit (in order to fit the labels), so we only need to
REM plot 250 pixels, rather than 256. This also lets us
REM stay in integer counting land, with the ticks 25
REM pixels apart.

REM Otherwise, the code is simple enough. We calculate a
REM step (ST) and use that to step the floating point
REM value of X (VALX). Then we just directly load the DOTCOL,
REM and calculate the DOTROW. It's inverted because negative
REM is up in mathland, the scale is 19 because that is the size
REM of ticks on the Y axis, and the offset is 95.5 for two reasons:
REM It's 95 because that is where I placed my origin, and .5 to
REM give free rounding up when we convert it back to an integer.
REM The DOTPLOT function can not deal with fractions so it
REM must always be fed integers.

730 REM PLOT FROM -5 to +5 SIN(X)  
740 FIRST=-5
750 LAST=5
760 ST=(LAST-FIRST)/250
770 VALX=FIRST
780 FOR X=3 TO 253
790 DOTCOL=X
800 DOTROW=INT(-SIN(VALX)*19+95.5)
810 GOSUB 140
820 VALX=VALX+ST
830 NEXT X

REM **************************************************
REM Now we're done. Change the border to grey to indicate
REM completion and then loop forever.

840 REM  SIT FOREVER    
850 CALL SCREEN(15)
860 GOTO 860

REM **************************************************
REM the axes are ticked and labelled here. The code is
REM essentially duplicated for Y, then X, because it was
REM quicker to code that way. ;)

REM first we read in the font data for chars 1-5. The
REM chars are defined as strings with '1' meaning draw
REM a pixel, and anything else meaning don't. The data
REM is arranged as 5 rows of 3 pixels, one string
REM per character.

870 REM  LABEL THE AXES 
880 FOR X=1 TO 5
890 READ FONT$(X)
900 NEXT X

REM Here we count down the Y axis, from -4 to +4
REM calculating that 192 could give us 10 steps
REM with 2 to spare with a step of 19, I went for
REM that, drawing only -4 to +4. L tracks this.

REM the outer Y loop covers the whole shebang,
REM providing the starting row for each tick.

REM this first X loop draws 5 pixels for the tick itself,
REM right across the axis

910  L=-4
920  FOR Y=19 TO 189 STEP 19
930    FOR X=126 TO 130
940      DOTROW=Y
950      DOTCOL=X
960      GOSUB 140
970    NEXT X

REM next, we use the L counter to determine which character
REM to draw, incrementing it afterwards. If we reach '1'
REM (indicating that we were at 0), we skip the character draw

980    FS$=FONT$(ABS(L))
990    L=L+1
1000   IF L=1 THEN 1170

REM otherwise, we will plot the character. A is used to
REM count our way through the font pixel data. The Y2
REM loop counts through the rows, and the X loop counts
REM through the columns. Then all we do is check the
REM definition string. If it's not "1" we skip it, otherwise
REM we load up the position and plot the dot.

1010   A=0
1020   FOR Y2=0 TO 4
1030     FOR X=0 TO 2
1040       A=A+1
1050       IF SEG$(FS$,A,1)<>"1" THEN 1090
1060       DOTROW=Y-2+Y2
1070       DOTCOL=122+X
1080       GOSUB 140
1090     NEXT X
1100   NEXT Y2

REM the next block plots the minus sign, so if L is greater
REM than zero, we can skip it. Otherwise, we use the X loop
REM to plot two pixels to the left of the digit.

1110   IF L>0 THEN 1170
1120   FOR X=0 TO 1
1130     DOTROW=Y
1140     DOTCOL=119+X
1150     GOSUB 140
1160   NEXT X
1170 NEXT Y

REM this is for the X axis, the same as the Y. The step
REM on the X axis is 25, and we push it in just a bit so
REM that we have room for -5 and +5 as well.

1180 L=-5
1190 FOR X=3 TO 253 STEP 25
1200   FOR Y=93 TO 97
1210     DOTROW=Y
1220     DOTCOL=X
1230     GOSUB 140
1240   NEXT Y

1250   FS$=FONT$(ABS(L))
1260   L=L+1
1270   IF L=1 THEN 1440

1280   A=0
1290   FOR Y=0 TO 4
1300     FOR X2=0 TO 2
1310       A=A+1
1320       IF SEG$(FS$,A,1)<>"1" THEN 1360
1330       DOTROW=99+Y
1340       DOTCOL=X+X2
1350       GOSUB 140
1360     NEXT X2
1370   NEXT Y

1380   IF L>0 THEN 1440
1390   FOR X2=0 TO 1
1400     DOTROW=101
1410     DOTCOL=X-3+X2
1420     GOSUB 140
1430   NEXT X2

1440 NEXT X
1450 RETURN

REM **************************************************
REM and here are the font definitions themselves

1460 REM  FONT 3x5, 1,2,3,4,5     
1470 DATA "010110010010111","111001111100111"
1480 DATA "110001010001110","100101111001001","111100110001110"

 

I've documented this one a little further, but most of the comments are NOT in the code. I'm not sure there's enough RAM left for them... might be. Anyway... 

 

image.thumb.png.a65b9cdd4d0c4907d8228872f9e782a5.png

  • Like 6
  • Thanks 1
Link to comment
Share on other sites

10 hours ago, Stuart said:

In bitmap mode you can display text on a 32 character by 24 row grid - so easy to add labels if the tick marks happen to align with the character grid (or possibly tweak your axis scales so that they do align). If they don't align, then you could define the label text character bitmaps as stationary sprites which can be positioned with pixel accuracy.

Stuart that are good news. Why do yourself not face the challenge and show us what Cortex Basic can perform? So far as i can see the labeling of the axis is a more or less hudge problem in some dialects/languages. ?

Edited by Sid1968
Link to comment
Share on other sites

2 hours ago, Tursi said:

I don't think "improve" is the right word, you changed the rules after I posted it. ;)

 

There you go. However, until you actually sit and run it yourself, don't ask for more. ;)

 

  Reveal hidden contents



REM PROGRAM TO DRAW SINE FROM -5 to 5
REM WITH ALL THE LABELS AND WHATEVER
REM - TURSI 2019

REM CC$ - hex codes for each definable character 33-159
REM HPAT$ - lookup tables for adding nibbles in hex
REM FONT$ - 3x5 bit definitions for drawing the 1-5 digits

100 REM PROGRAM START  
110 DIM CC$(127),HPAT$(4),FONT$(5)
120 GOTO 440

REM **************************************************
REM DOTPLOT IS HERE BASED ON THE MYTH THAT THE EARLY
REM LINES OF CODE RUN FASTER.
REM SET DOTROW,DOTCOL, and GOSUB to CALL IT

REM RELIES ON:
REM CURCHAR - the next unused char
REM STARTCHAR - the first definable character (0 in CC$)
REM LASTCHAR - the last definable character (ie: when we run out of ink!)
REM FIXCHAR - special to this version - below are defined chars that we aren't allowed to change

REM The operation is straight-forward. It calculates the screen position, and uses GCHAR to see
REM what is there. If it's a character the subroutine owns (>=FIXCHAR), this means we have already
REM defined it once, so we can just redefine it.

REM If it's the space character (32), we know we can allocate a new character to that location.

REM If it's in our space at all (>=STARTCHAR), then we know it's fixed, otherwise we can't touch it.

REM For a fixed char, we copy the definition that we have stored to a new character for modification.
REM In this app, fixed chars are used for the axes.

REM Finally, if it needed to allocate a new character, we check against LASTCHAR to see if we are
REM out. If we are, then plots that require a new character are ignored, but old chars can still be
REM redefined.

REM Once we know what character to redefine, we calculate which nibble to alter, and based on which
REM pixel inside that nibble we are setting, we use the HPOS lookup tables to add the new pixel to
REM the old value. Then we patch the string back together, CALL CHAR it, and save the new pattern off.

130 REM DOTPLOT AT DOTROW,DOTCOL (0-based)  

REM Classify the character already on the screen
140 MR=INT(DOTROW/8)+1
150 MC=INT(DOTCOL/8)+1
160 CALL GCHAR(MR,MC,CH)
170 IF CH>=FIXCHAR THEN 290
180 IF CH=32 THEN 260
190 IF CH>=STARTCHAR THEN 210
REM If we get here, it was a character we can't change.
200 RETURN

REM Here it is a fixed char, so copy out the pattern and assign a new character
REM Give up if there are no more characters to assign
210 TC$=CC$(CH-STARTCHAR)
220 CH=CURCHAR
230 CURCHAR=CURCHAR+1
240 IF CURCHAR>=LASTCHAR THEN 200
250 GOTO 300

REM Here we're allocating a new empty char to replace a space character.
REM Again, give up if there are no more characters to assign
260 CH=CURCHAR
270 CURCHAR=CURCHAR+1
280 IF CURCHAR>=LASTCHAR THEN 200
290 TC$=CC$(CH-STARTCHAR)

REM Determine the internal row and column. We don't have masking, but this works
REM Once we have that, we can determine which position in the string to change
300 XR=DOTROW-(MR-1)*8
310 XC=DOTCOL-(MC-1)*8
320 P=XR*2+1
330 IF XC<4 THEN 360
340 P=P+1
350 XC=XC-4

REM Now we extract the character from the working string, then use it and the
REM pixel offset to lookup the new character. Then, insert it back into the string.
360 X$=SEG$(TC$,P,1)
370 TT$=SEG$(HPAT$(XC),POS(HEX$,X$,1),1)
380 TC$=SEG$(TC$,1,P-1)&TT$&SEG$(TC$,P+1,16-P)

REM pretty much done! Assign the pattern, save it in our lookup table,
REM plot it to the screen, and return to caller!
390 CALL CHAR(CH,TC$)
400 CC$(CH-STARTCHAR)=TC$
410 CALL HCHAR(MR,MC,CH)
420 RETURN

REM **************************************************
REM this block prepares the plot function.
REM It resets the pattern lookup table to all blanks,
REM sets the CURCHAR,STARTCHAR and LASTCHAR (we use
REM ALL definable characters except space). Finally,
REM We set the lookup tables for hexadecimal conversion
REM and math.

430 REM INIT THE DOT PLOT  
440 FOR A=0 TO 127
450 CC$(A)="0000000000000000"
460 NEXT A
470 CURCHAR=33
480 STARTCHAR=33
490 LASTCHAR=159
500 HEX$="0123456789ABCDEF"
510 HPAT$(0)="89ABCDEF89ABCDEF"
520 HPAT$(1)="45674567CDEFCDEF"
530 HPAT$(2)="23236767ABABEFEF"
540 HPAT$(3)="1133557799BBDDFF"

REM Now we set the colors of all the color sets to black on grey
REM and clear the screen to get started
550 FOR A=1 TO 16
560 CALL COLOR(A,2,15)
570 NEXT A
580 CALL CLEAR

REM **************************************************
REM We were tasked to draw labelled X and Y axes. So first
REM we define normal chars for drawing them. We manually
REM allocate a couple by changing CURCHAR, and we reserve
REM the first two (vertical and horizontal lines) by setting
REM FIXCHAR. This lets the plot function copy our definition
REM when drawing near the lines without changing the character
REM pattern, which would change all of them. Note that the
REM cross in the middle is not a fixed char, since there is
REM only one of them, I don't care if the plot function updates it.

590 REM   DRAW THE AXES  
600 CURCHAR=36
610 FIXCHAR=35
620 CC$(0)="00000000000000FF"
630 CC$(1)="8080808080808080"
640 CC$(2)="80808080808080FF"
650 CALL CHAR(33,CC$(0))
660 CALL CHAR(34,CC$(1))
670 CALL CHAR(35,CC$(2))
680 CALL HCHAR(12,1,33,32)
690 CALL VCHAR(1,17,34,24)
700 CALL HCHAR(12,17,35)

REM Now we're going to start plotting pixels. I set the screen border
REM to blue to show we're working, then gosub to the block which draws
REM the tick marks and the numbers. It's a subroutine mostly cause
REM it was added later.

710 CALL SCREEN(5)
720 GOSUB 870

REM **************************************************
REM now we draw the actual plot. The positioning and the
REM numbers are based on the fact that the ticks on the
REM X axis are indented from the edges of the screen a
REM bit (in order to fit the labels), so we only need to
REM plot 250 pixels, rather than 256. This also lets us
REM stay in integer counting land, with the ticks 25
REM pixels apart.

REM Otherwise, the code is simple enough. We calculate a
REM step (ST) and use that to step the floating point
REM value of X (VALX). Then we just directly load the DOTCOL,
REM and calculate the DOTROW. It's inverted because negative
REM is up in mathland, the scale is 19 because that is the size
REM of ticks on the Y axis, and the offset is 95.5 for two reasons:
REM It's 95 because that is where I placed my origin, and .5 to
REM give free rounding up when we convert it back to an integer.
REM The DOTPLOT function can not deal with fractions so it
REM must always be fed integers.

730 REM PLOT FROM -5 to +5 SIN(X)  
740 FIRST=-5
750 LAST=5
760 ST=(LAST-FIRST)/250
770 VALX=FIRST
780 FOR X=3 TO 253
790 DOTCOL=X
800 DOTROW=INT(-SIN(VALX)*19+95.5)
810 GOSUB 140
820 VALX=VALX+ST
830 NEXT X

REM **************************************************
REM Now we're done. Change the border to grey to indicate
REM completion and then loop forever.

840 REM  SIT FOREVER    
850 CALL SCREEN(15)
860 GOTO 860

REM **************************************************
REM the axes are ticked and labelled here. The code is
REM essentially duplicated for Y, then X, because it was
REM quicker to code that way. ;)

REM first we read in the font data for chars 1-5. The
REM chars are defined as strings with '1' meaning draw
REM a pixel, and anything else meaning don't. The data
REM is arranged as 5 rows of 3 pixels, one string
REM per character.

870 REM  LABEL THE AXES 
880 FOR X=1 TO 5
890 READ FONT$(X)
900 NEXT X

REM Here we count down the Y axis, from -4 to +4
REM calculating that 192 could give us 10 steps
REM with 2 to spare with a step of 19, I went for
REM that, drawing only -4 to +4. L tracks this.

REM the outer Y loop covers the whole shebang,
REM providing the starting row for each tick.

REM this first X loop draws 5 pixels for the tick itself,
REM right across the axis

910  L=-4
920  FOR Y=19 TO 189 STEP 19
930    FOR X=126 TO 130
940      DOTROW=Y
950      DOTCOL=X
960      GOSUB 140
970    NEXT X

REM next, we use the L counter to determine which character
REM to draw, incrementing it afterwards. If we reach '1'
REM (indicating that we were at 0), we skip the character draw

980    FS$=FONT$(ABS(L))
990    L=L+1
1000   IF L=1 THEN 1170

REM otherwise, we will plot the character. A is used to
REM count our way through the font pixel data. The Y2
REM loop counts through the rows, and the X loop counts
REM through the columns. Then all we do is check the
REM definition string. If it's not "1" we skip it, otherwise
REM we load up the position and plot the dot.

1010   A=0
1020   FOR Y2=0 TO 4
1030     FOR X=0 TO 2
1040       A=A+1
1050       IF SEG$(FS$,A,1)<>"1" THEN 1090
1060       DOTROW=Y-2+Y2
1070       DOTCOL=122+X
1080       GOSUB 140
1090     NEXT X
1100   NEXT Y2

REM the next block plots the minus sign, so if L is greater
REM than zero, we can skip it. Otherwise, we use the X loop
REM to plot two pixels to the left of the digit.

1110   IF L>0 THEN 1170
1120   FOR X=0 TO 1
1130     DOTROW=Y
1140     DOTCOL=119+X
1150     GOSUB 140
1160   NEXT X
1170 NEXT Y

REM this is for the X axis, the same as the Y. The step
REM on the X axis is 25, and we push it in just a bit so
REM that we have room for -5 and +5 as well.

1180 L=-5
1190 FOR X=3 TO 253 STEP 25
1200   FOR Y=93 TO 97
1210     DOTROW=Y
1220     DOTCOL=X
1230     GOSUB 140
1240   NEXT Y

1250   FS$=FONT$(ABS(L))
1260   L=L+1
1270   IF L=1 THEN 1440

1280   A=0
1290   FOR Y=0 TO 4
1300     FOR X2=0 TO 2
1310       A=A+1
1320       IF SEG$(FS$,A,1)<>"1" THEN 1360
1330       DOTROW=99+Y
1340       DOTCOL=X+X2
1350       GOSUB 140
1360     NEXT X2
1370   NEXT Y

1380   IF L>0 THEN 1440
1390   FOR X2=0 TO 1
1400     DOTROW=101
1410     DOTCOL=X-3+X2
1420     GOSUB 140
1430   NEXT X2

1440 NEXT X
1450 RETURN

REM **************************************************
REM and here are the font definitions themselves

1460 REM  FONT 3x5, 1,2,3,4,5     
1470 DATA "010110010010111","111001111100111"
1480 DATA "110001010001110","100101111001001","111100110001110"

 

I've documented this one a little further, but most of the comments are NOT in the code. I'm not sure there's enough RAM left for them... might be. Anyway... 

 

image.thumb.png.a65b9cdd4d0c4907d8228872f9e782a5.png

Tursi i dont have to ask for more... ahhh not at least the next challenge comes. ?

My verdict of your work.... Perfect, i bow to you! Thank you very much! ?

 

I like most that you descibed in the comments what you are doing.

This is what this thread is about... LEARNING from each other and SEEING where a dialect/language could need some improvements.

 

Cheers

Sid

Edited by Sid1968
  • Thanks 1
Link to comment
Share on other sites

3 hours ago, Tursi said:

I started working on finding the references that would be needed to move the data to a cartridge, which would be great. But it's complex. :)

Indeed it is. And it's not any easier when you consider that there's an assembly code repositiory in GROM, code which should be transferred to RAM, and run there, and have the correct references to the p-code card when needed.

  • Thanks 1
Link to comment
Share on other sites

1 minute ago, Sid1968 said:

Sorry man, the rules of this challenge are clear. Nobody must face it. Like the others too, listings have to give in this thread.

Sorry man, but this is a forum. You don't set the rules. If you want to make challenges, fine. If somebody solves them in a different way than you thought, face it.

  • Like 1
  • Sad 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...