Although it is an old standby–a rolling pair of dice, this version’s merits are speed and flexibility.
“Dice” begins with a few lines to draw the dice. This is followed by the basic (with machine code) to roll them. Lines 220 and 230 set the screen location for the pips of the first die. Lines 330 and 340 do the same for the second die. The two pairs of POKEs enter a displacement number which is added to the address of the screen by the machine code. I have included the routine at line 500 to calculate the displacement (since this is easier than trying to explain it). RUN 500. You will then be prompted for the row and column values where you would like to place the upper left hand pip of each die. You may then edit them into the program in the lines that POKE 16544 & 16545.
Line 260 determines which character will be printed as the pip. It is currently the “O” character. Line 300 changes the character that is printed (grey grapic) on the last roll of the dice and may be deleted if desired. Line 270 determines how many times the dice will be rolled, which is currently a number from 3 to 5. Line 290 picks a number from 1 to 6 and pokes it into the machine code. This will be the number of pips that are printed.
There is a delay in the machine code at address 16561. It is currently set at 5, but you may want to try a number between 0 to 10. For a quick experiment, try editing line 260 and make it an inverse space, POKE 16561,1 and then RUN the program.
The machine code can be relocated if you calculate new addresses for the POKEs and the USR call. Assume “Start” is where the machine code begins.
LINE ROUTINE OFFSET 310 Call address start +6 230 & 330 Pip location start +30 240 & 340 Pip location start +31 Direct POKE Delay start +47 290 # of pips printed start +70 260 & 300 Character printed start +90
To enter the machine code, you will need a REM line with 103 spaces after the REM or 103 bytes of space in memory elsewhere. Enter the following decimal table with your favorite POKEr program or use the HOT Z listing of the machine code to hex poke the data.
Enter the data left to right, top to bottom.
DECIMAL TABLE
119 107 099 042 065 008 205 032
021 175 006 002 087 030 006 213
030 093 213 030 003 213 213 030
093 213 030 006 213 017 127 001
213 016 233 006 007 042 012 064
209 025 119 016 251 001 001 005
011 120 177 032 251 205 167 014
197 042 012 064 043 034 022 064
062 064 205 086 015 062 006 205
029 021 239 004 036 052 205 167
014 003 225 237 066 078 006 007
062 008 042 012 064 209 025 203
025 048 001 119 016 247 201
BASIC PROGRAM LISTING
1 REM [illegible]
10 REM
20 REM * DICE *
30 REM CHUCK PETERSON
40 REM APRIL, 1985
50 REM
60 REM 16520: ENTER ROUTINE
70 REM 16544/45: OFFSET
80 REM 16561: DELAY
90 REM 16603: PIP CHAR. CODE
95 REM
100 REM OUTLINE DICE
105 PRINT " PRESS ANY KEY TO ROLL THE DICE"
110 LET R=4
120 LET C=3
130 FOR F=1 TO 2
140 PRINT AT R,C;"▒▒▒▒▒▒▒▒▒▒▒"
150 FOR G=1 TO 9
160 PRINT TAB C;"▒ ▒"
170 NEXT G
180 PRINT TAB C;"▒▒▒▒▒▒▒▒▒▒▒"
190 LET R=9
200 LET C=17
210 NEXT F
220 REM ROLL
230 POKE 16544,204
240 POKE 16545,0
250 FOR F=1 TO 2
260 POKE 16603,CODE "O"
270 LET A=INT (RND*4)+4
280 FOR G=1 TO A
300 IF G=A THEN POKE 16603,CODE "▒"
310 LET Z=USR 16520
320 NEXT G
330 POKE 16544,127
340 POKE 16545,1
350 NEXT F
360 RAND
370 GOTO 370-(140 AND INKEY$<>"")
380 REM END ROLL
390 REM
500 REM FIND OFFSET
510 PRINT "OFFSET POKES",,,,
530 PRINT "ROW NUMBER (0 THRU 17)?";
540 INPUT R
550 PRINT TAB 28;R,,,
560 PRINT "COLUMN NUMBER (0 THRU 25)?";
570 INPUT C
580 PRINT TAB 28;C,,,
590 LET OFFSET=R*33+C+1
600 LET X=INT (OFFSET/256)
610 LET Y=OFFSET-256*X
620 PRINT "POKE 16544,";Y,,,,
640 PRINT "POKE 16545,";X
650 STOP
660 REM END FIND OFFSET
670 REM
1000 REM SAVE
1010 SAVE "DICE"
1020 RUN
MACHINE CODE LISTING
4082 77 DATA LD (HL),A
4083 6B Z654 LD L,E
4084 63 LD H,E
4085 2A4108 Z321 LD HL,(0841)
4088 CD2015 INIT CALL STBC
408B AF XOR A
408C 0602 LD B,02
408E 57 LUP1 LD D,A
408F 1E06 LD E,06
4091 D5 PUSH DE
4092 1E5D LD E,5D
4094 D5 PUSH DE
4095 1E03 LD E,03
4097 D5 PUSH DE
4098 D5 PUSH DE
4099 1E5D LD E,5D
409B D5 PUSH DE
409C 1E06 LD E,06
409E D5 PUSH DE
409F 117F01 LD DE,017F
40A2 D5 PUSH DE
40A3 10E9 DJNZ LUP1
40A5 0607 ERAS LD B,07
40A7 2A0C40 LD HL,(DFILE)
40AA D1 LUP2 POP DE
40AB 19 ADD HL,DE
40AC 77 LD (HL),A
40AD 10FB DJNZ LUP2
40AF 010105 DLAY LD BC,0501
40B2 0B LUP3 DEC BC
40B3 78 LD A,B
40B4 B1 OR C
40B5 20FB JR NZ LUP3
40B7 CDA70E CALL UNST
40BA C5 PUSH BC
40BB 2A0C40 LD HL,(DFILE)
40BE 2B DEC HL
40BF 221640 LD (CHADD),HL
40C2 3E40 SET LD A,40
40C4 CD560F RAND CALL SCAN
40C7 3E06 LD A,06
40C9 CD1D15 CALL STKA
40CC EF RST 28H
40CD 04 MULT
40CE 24 INT
40CF 34 END
40D0 CDA70E PTRN CALL UNST
40D3 03 INC BC
40D4 E1 POP HL
40D5 ED42 SBC HL,BC
40D7 4E LD C,(HL)
40D8 0607 PRNT LD B,07
40DA 3E08 LD A,08
40DC 2A0C40 LD HL,(DFILE)
40DF D1 LUP4 POP DE
40E0 19 ADD HL,DE
40E1 CB19 RR C
40E3 3001 JR NC 40E6
40E5 77 LD (HL),A
40E6 10F7 DJNZ LUP4
40E8 C9 RET
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.