scene.org File Archive

File download

<root>­/­parties­/­2022­/­vccc22­/­christmas_star_challenge/diminished_bbcmicromodelb_basic_vc3-2022.zip

File size:
40 016 bytes (39.08K)
File date:
2022-12-30 11:32:13
Download count:
all-time: 4

Preview

  • Diminished_BBCmicroModelB_basic_vc3-2022/ dir
  • Diminished_BBCmicroModelB_basic_vc3-2022/file_id.diz 5.63K
  • Diminished_BBCmicroModelB_basic_vc3-2022/result+source.png 38.63K
  • Diminished_BBCmicroModelB_basic_vc3-2022/sirius.ssd 1.25K
  • Diminished_BBCmicroModelB_basic_vc3-2022/source.txt 76B

file_id.diz

SIRIUS

Author:          Diminished
Category:        Christmas Challenge
System:          BBC Microcomputer System ("BBC Micro"), Model B, OS 1.2
Language:        BASIC (BBC BASIC II)
Len source code: 76
Len exe file:    75
Len code only:   75

Instructions:
The easiest emulator to use is the browser-based jsbeeb:

https://bbcmicro.co.uk/jsbeeb/

Using jsbeeb, select "Discs" from the menu bar, then "From examples or local", and choose the "sirius.ssd" disc image file included with this ZIP. Then, either press Shift + F12 to autoboot the demo, or alternatively type CHAIN "DEMO", and press Enter. Note that on the BBC Micro, the double-quote character " is typed by pressing Shift + 2.

This demo will only work on the Model B -- it will NOT WORK on the Master 128.

(Here are some other viable emulators:)
b-em:               http://b-em.bbcmicro.com/
beebjit:            https://github.com/scarybeasts/beebjit/
BeebEm for Windows: http://www.mkw.me.uk/beebem/
b2:                 https://github.com/tom-seddon/b2


Description:
Acorn's BBC Micro features an operating system in ROM. By printing certain control character sequences, you can activate features of the OS's VDU driver (see  https://beebwiki.mdfs.net/VDU  for full details).

Of interest here is VDU 28 (0x1c), which allows the user to define a text window. For example, you can write a BASIC program such as:

10 MODE 7
20 L=10 : REM left edge
30 B=17 : REM bottom edge
40 R=17 : REM right edge
50 T=10 : REM top edge
60 REM define text window:
70 VDU 28, L, B, R, T
80 REM same as CLS:
90 VDU 12
100 PRINT "Bismarck biss Mark, bis Mark Bismarck biss."

(This example program is also included within the disc image "sirius.ssd"; type CHAIN "EXAMPLE" <Enter> at the BBC Micro BASIC prompt to run it.)

When run, this program will redefine the text window to be a small square in the middle of the screen, and the VDU 12 (clear screen) and PRINT commands will now operate within the boundary of this window.

This demo abuses this text windowing capability to draw filled rectangles, by poking a value into a memory location (856) reserved by the operating system. In graphics modes, this location contains a background colour value that is used to fill the text window when it is cleared, but in the text-only Teletext mode (MODE 7), the ASCII value of this byte is used to fill the window instead. (The ? operator replaces POKE in BBC BASIC):

?856=42

Now, in screen mode 7 (Teletext), a CLS (or VDU 12) command will not clear the text window, but instead fill it with asterisks. This is useful.

Here is a more verbose version of the demo's code, which makes things a bit easier to explain:

10 ?856=42
20 FOR X=-4 TO 4
30 M=20 + ABS X
40 Q=16 + X
50 VDU 28, Q, M, Q, 32-M
60 VDU 12
70 VDU 28, 32-M, Q, M, Q
80 VDU 12
90 VDU 26
100 NEXT

Line 10 sets up the OS poke which makes CLS fill the text window with asterisks, rather than clearing it.

Each iteration of the FOR loop (line 20) will draw a cross, formed of two thin perpendicular rectangles intersecting at a point. X loops from -4 to +4, and a value Q = 16 + X is derived from X. The rectangles are drawn so they intersect at the point (Q, Q):

    Q
 +----->|
 | 
 |      *
Q|      * <-- 50 VDU 28, Q, M, Q, 32-M
 |      *
 v      *
 -  ****\************ <-- 70 VDU 28, 32-M, Q, M, Q
        *\ 
        * \ ...
        *  \       <-  intersection point (Q, Q) moves down and to the right
        *   \ X=0      with each X increment
        *    \ 
        *     \ ...    (X=0 refers to the centre of the finished star shape.)
        *      \ 
        *       \ X=4
        *
        *
        *
        *

The length of the rectangles drawn also needs to change as X increases, to form the 'V' shapes at the top, bottom, left and right of the star. The rectangles must shorten as they approach the centre of the star, then lengthen again once the centre has been passed. This is achieved by taking the absolute value of X in line 30, which will run from 4 to 0 (shortening) and then back to 4 (lengthening) as X increases. Two values -- M and (32-M) -- are derived from this absolute value of X in lines 30 and 40, forming the two ends of each rectangle.

(Only horizontal rectangles are shown here; the vertical ones work just the same.)

                         ---
                           |
       M (right limit)     |
---------------------->|   |
                       |   | Q
32-M                   |   |
(left limit)           |   |    X | ABS(X) |  M | 32-M
------>|               |   v   ---+--------+----+-----
       ***************** ---   -4 |   4    | 24 |  8   |
        ***************        -3 |   3    | 23 |  9   |
         *************         -2 |   2    | 22 |  10  | narrowing
          ***********          -1 |   1    | 21 |  11  v
           *********            0 |   0    | 20 |  12 
          ***********           1 |   1    | 21 |  11  |
         *************          2 |   2    | 22 |  10  | widening
        ***************         3 |   3    | 23 |  9   |
       *****************        4 |   4    | 24 |  8   v
 

Each rectangle is filled with asterisks by a VDU 12 ("clear screen") statement. Finally, a VDU 26 statement is issued, which will un-define the text window. This is necessary to prevent the final asterisk from being scribbled by the '>' prompt character when the program terminates.

Since lines 50, 60, 70, 80 and 90 are all VDU statements, the submitted "DEMO" is able to combine these five VDU statements into one long VDU statement:

VDU 28,Q,M,Q,26-M,7180;26-M,Q,M,Q,12,26

(The semicolon syntax used once here allows sending of a pair of VDU bytes as a 16-bit number "7180;" -- this saves one byte over the simpler sequence "12,28,").


Comments:

Merry Christmas!