News:

Welcome to RetroCoders Community

Main Menu

GW Basic - Matrix Rain by BlackJack

Started by ron77, Nov 21, 2023, 06:08 AM

Previous topic - Next topic

ron77

10 ON TIMER(25) GOSUB 160: TIMER ON
20 DEFINT A-Z:RANDOMIZE TIMER:DEF SEG=&HB800
30 DIM MMI(80),MROW(80,5),MMODE(80,5)
40 DEF FNG(N)=N-(INT(20*RND)+5)
50 ' Initialize.
60 FOR I=0 TO 1999:POKE I*2+1,0:POKE I*2,INT(256*RND):NEXT
70 FOR COL=0 TO 79:R=0:MODE=-1
80 FOR I=1 TO 5:R=FNG(R):MROW(COL,I)=R:MODE=NOT MODE:MMODE(COL,I)=MODE:NEXT
90 MMI(COL)=5:NEXT
100 ' Main loop.
110 WHILE INKEY$="":FOR COL=0 TO 79
120 FOR I=1 TO 5:R=MROW(COL,I):R=R+1:MROW(COL,I)=R:IF R<0 THEN 150
130 A=(R*80+COL)*2+1:IF MMODE(COL,I) THEN POKE A,0:GOTO 140:ELSE POKE A,10:IF R THEN POKE A-160,2
140 IF R=25 THEN J=MMI(COL):MMODE(COL,I)=NOT MMODE(COL,J):MROW(COL,I)=FNG(MROW(COL,J)):MMI(COL)=I
150 NEXT:NEXT:WEND
160 REM TME:
170 CLS: COLOR 2
180 WHILE INKEY$ <> CHR$(27)
190 LOCATE 15, 30
200 PRINT " THE MATRIX HAS YOU"
210 WEND
220 END


johnno56

Curious... What function do the "pokes" provide?
May your journey be free of incident.  Live long and prosper.

__blackjack__

The POKEs put the characters and the colours to the screen. Even then it is unbearably slow on a 8086 IBM PC (or clone) clocked at ~10 Mhz.  Compiled with BASCOM it is just fast enough.

From CGA cards onwards there is a 80×25 character screen in colour.  The screen memory is at 0xB8000.  Every byte at an even address has the character value and the bytes at odd addresses have the foreground and background colour of the character.

Following is a small program that shows all 256 possible characters, waits for a key press, and the colours the displayed characters in all possible combinations:

10 DEFINT A-Z:DEF SEG=&HB800
20 CLS:FOR I=0 TO 15:FOR J=0 TO 15:POKE 160*I+J*2,I*16+J:NEXT:NEXT
30 WHILE INKEY$="":WEND
40 FOR I=0 TO 15:FOR J=0 TO 15:POKE 160*I+J*2+1,I*16+J:NEXT:NEXT
50 WHILE INKEY$="":WEND

The default setting of the video cards is to use the highest bit of the background colour as flag to blink the characters (in hardware), so the first 8 colours repeat as background colour, instead of having the 8 bright colours there.
Two is the oddest prime.