Update to fix logic issues

This commit is contained in:
William Moore 2023-10-19 14:37:11 -05:00
parent d8075e1b95
commit c483f5b192

View File

@ -1,303 +1,306 @@
; PokerDice.asm ; PokerDice.asm
; Copyright (C) 2023 William R. Moore ; Copyright (C) 2023 William R. Moore
; ;
; This program is free software: you can redistribute it and/or modify ; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by ; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or ; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version. ; (at your option) any later version.
; ;
; This program is distributed in the hope that it will be useful, ; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of ; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details. ; GNU General Public License for more details.
; ;
; You should have received a copy of the GNU General Public License ; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>. ; along with this program. If not, see <http://www.gnu.org/licenses/>.
; Poker Dice Game Aid ; Poker Dice Game Aid
; ;
; Toggle the first five sense switches to roll the different dice. ; Toggle the first five sense switches to roll the different dice.
; Position 0 = roll ; Position 0 = roll
; Position 1 = hold ; Position 1 = hold
; ;
; Toggle switches 6 and 7 when you want to move on to the next roll ; Toggle switches 6 and 7 when you want to move on to the next roll
; or continue holding the dice. ; or continue holding the dice.
; Once switches 6 and 7 are togged to position 1, the game ends and ; Once switches 6 and 7 are togged to position 1, the game ends and
; your "hand" is displayed. ; your "hand" is displayed.
ORG 100H ORG 100H
; Driver logic ; Driver logic
LXI SP, STACK LXI SP, STACK
PUSH D PUSH D
LXI D, WELCOME LXI D, WELCOME
CALL PRINTS CALL PRINTS
POP D POP D
PUSH D PUSH D
LXI D, NEWLINE LXI D, NEWLINE
CALL PRINTS CALL PRINTS
POP D POP D
LXI H, DICE LXI H, DICE
CALL ROLLTHEMBONES CALL ROLLTHEMBONES
CALL OUTPUT CALL OUTPUT
IN 0FFH ROUND2
ANI 32 IN 0FFH
CNZ ROLLTHEMBONES ANI 32
CALL OUTPUT JZ ROUND2
CALL ROLLTHEMBONES
IN 0FFH CALL OUTPUT
ANI 64
CNZ ROLLTHEMBONES ROUND3
CALL OUTPUT IN 0FFH
ANI 64
JMP 0h JZ ROUND3
CALL ROLLTHEMBONES
ROLLTHEMBONES CALL OUTPUT
CALL ROLL1
MOV M, C JMP 0h
INR L
ROLLTHEMBONES
CALL ROLL2 MOV A, C
MOV M, C CPI 0
INR L JNZ RTB1
CALL ROLL1
CALL ROLL3 MOV M, C
MOV M, C INR 1
INR L CALL ROLL2
MOV M, C
CALL ROLL4 INR 1
MOV M, C CALL ROLL3
INR L MOV M, C
INR 1
CALL ROLL5 CALL ROLL4
MOV M, C MOV M, C
INR 1
DCR L CALL ROLL5
DCR L MOV M, C
DCR L JMP RTBEND
DCR L
RET RTB1
IN 0FFH
; Output the dice results ANI 1
OUTPUT JNZ RTB2
PUSH D CALL ROLL1
LXI D, YOUROLLED MOV M, C
CALL PRINTS RTB2
POP D INR L
IN 0FFH
PUSH D ANI 2
MOV A, M JNZ RTB3
ADI 48 CALL ROLL2
STAX D MOV M, C
CALL PRINTC RTB3
INR L INR L
POP D IN 0FFH
ANI 4
PUSH D JNZ RTB4
LXI D, NEWLINE CALL ROLL3
CALL PRINTS MOV M, C
POP D RTB4
INR L
PUSH D IN 0FFH
MOV A, M ANI 8
ADI 48 JNZ RTB5
STAX D CALL ROLL4
CALL PRINTC MOV M, C
INR L RTB5
POP D INR L
IN 0FFH
PUSH D ANI 16
LXI D, NEWLINE JNZ RTBEND
CALL PRINTS CALL ROLL5
POP D MOV M, C
RTBEND
PUSH D DCR L
MOV A, M DCR L
ADI 48 DCR L
STAX D DCR L
CALL PRINTC RET
INR L
POP D ; Output the dice results
OUTPUT
PUSH D PUSH D
LXI D, NEWLINE LXI D, YOUROLLED
CALL PRINTS CALL PRINTS
POP D POP D
PUSH D PUSH D
MOV A, M MOV A, M
ADI 48 ADI 48
STAX D STAX D
CALL PRINTC CALL PRINTC
INR L INR L
POP D POP D
PUSH D PUSH D
LXI D, NEWLINE LXI D, NEWLINE
CALL PRINTS CALL PRINTS
POP D POP D
PUSH D PUSH D
MOV A, M MOV A, M
ADI 48 ADI 48
STAX D STAX D
CALL PRINTC CALL PRINTC
POP D INR L
POP D
PUSH D
LXI D, NEWLINE PUSH D
CALL PRINTS LXI D, NEWLINE
POP D CALL PRINTS
POP D
DCR L
DCR L PUSH D
DCR L MOV A, M
DCR L ADI 48
STAX D
RET CALL PRINTC
INR L
; Roll the different dice POP D
ROLL1
IN 0FFH PUSH D
ANI 1 LXI D, NEWLINE
JNZ ROLL1_TEST CALL PRINTS
ROLL1_START POP D
MVI C, 0
ROLL1_DIE PUSH D
INR C MOV A, M
MOV A, C ADI 48
CPI 7H STAX D
JZ ROLL1_START CALL PRINTC
IN 0FFH INR L
ANI 1 POP D
JNZ ROLL1_END
JMP ROLL1_DIE PUSH D
ROLL1_TEST LXI D, NEWLINE
MOV A, M CALL PRINTS
CPI 0h POP D
JZ ROLL1_START
ROLL1_END PUSH D
RET MOV A, M
ADI 48
ROLL2 STAX D
IN 0FFh CALL PRINTC
ANI 2 POP D
JNZ ROLL2_TEST
ROLL2_START PUSH D
MVI C, 0 LXI D, NEWLINE
ROLL2_DIE CALL PRINTS
INR C POP D
MOV A, C
CPI 7H DCR L
JZ ROLL2_START DCR L
IN 0FFH DCR L
ANI 2 DCR L
JNZ ROLL2_END
JMP ROLL2_DIE RET
ROLL2_TEST
MOV A, M ; Roll the different dice
CPI 0 ROLL1
JZ ROLL2_START ROLL1_START
ROLL2_END MVI C, 0
RET ROLL1_DIE
INR C
ROLL3 MOV A, C
IN 0FFh CPI 7H
ANI 4 JZ ROLL1_START
JNZ ROLL3_TEST IN 0FFH
ROLL3_START ANI 1
MVI C, 0 JNZ ROLL1_END
ROLL3_DIE JMP ROLL1_DIE
INR C ROLL1_END
MOV A, C RET
CPI 7H
JZ ROLL3_START ROLL2
IN 0FFH ROLL2_START
ANI 4 MVI C, 0
JNZ ROLL3_END ROLL2_DIE
JMP ROLL3_DIE INR C
ROLL3_TEST MOV A, C
MOV A, M CPI 7H
CPI 0 JZ ROLL2_START
JZ ROLL3_START IN 0FFH
ROLL3_END ANI 2
RET JNZ ROLL2_END
JMP ROLL2_DIE
ROLL4 ROLL2_END
IN 0FFH RET
ANI 8
JNZ ROLL4_TEST ROLL3
ROLL4_START ROLL3_START
MVI C, 0 MVI C, 0
ROLL4_DIE ROLL3_DIE
INR C INR C
MOV A, C MOV A, C
CPI 7H CPI 7H
JZ ROLL4_START JZ ROLL3_START
IN 0FFH IN 0FFH
ANI 8 ANI 4
JNZ ROLL4_END JNZ ROLL3_END
JMP ROLL4_DIE JMP ROLL3_DIE
ROLL4_TEST ROLL3_END
MOV A, M RET
CPI 0
JZ ROLL4_START ROLL4
ROLL4_END ROLL4_START
RET MVI C, 0
ROLL4_DIE
ROLL5 INR C
IN 0FFh MOV A, C
ANI 16 CPI 7H
JNZ ROLL5_TEST JZ ROLL4_START
ROLL5_START IN 0FFH
MVI C, 0 ANI 8
ROLL5_DIE JNZ ROLL4_END
INR C JMP ROLL4_DIE
MOV A, C ROLL4_END
CPI 7H RET
JZ ROLL5_START
IN 0FFH ROLL5
ANI 16 ROLL5_START
JNZ ROLL5_END MVI C, 0
JMP ROLL5_DIE ROLL5_DIE
ROLL5_TEST INR C
MOV A, M MOV A, C
CPI 0 CPI 7H
JZ ROLL5_START JZ ROLL5_START
ROLL5_END IN 0FFH
RET ANI 16
JNZ ROLL5_END
; Print a null-terminated string JMP ROLL5_DIE
PRINTS ROLL5_END
PUSH PSW RET
OUT1CH
LDAX D ; LET A = (DE) ; Print a null-terminated string
CPI 0H ; Done when null terminated. PRINTS
JZ PRINTS_DONE PUSH PSW
OUT 1H ; Output the character at the current address to the console OUT1CH
INR E ; Increment the address of the current character LDAX D ; LET A = (DE)
JMP OUT1CH CPI 0H ; Done when null terminated.
PRINTS_DONE JZ PRINTS_DONE
POP PSW OUT 1H ; Output the character at the current address to the console
RET INR E ; Increment the address of the current character
PRINTC JMP OUT1CH
; PUSH PSW PRINTS_DONE
LDAX D ; LET A = (DE) POP PSW
OUT 1H ; Output the character at the current address to the console RET
; POP PSW
RET PRINTC
LDAX D ; LET A = (DE)
SAVE_HL DW 0 OUT 1H ; Output the character at the current address to the console
WELCOME DB "Welcome to the gambling halls of Mooreheim!", 0H RET
DICE DB 0, 0, 0, 0, 0
HELD_DICE DB 0, 0, 0, 0, 0 SAVE_HL DW 0
YOUROLLED DB "You rolled:", CR, LF, 0H WELCOME DB "Welcome to the gambling halls of Mooreheim!", 0H
NEWLINE DB CR, LF, 0H DICE DB 0, 0, 0, 0, 0
CR equ 0DH HELD_DICE DB 0, 0, 0, 0, 0
LF equ 0AH YOUROLLED DB "You rolled:", CR, LF, 0H
STACK equ 2000h NEWLINE DB CR, LF, 0H
END CR equ 0DH
LF equ 0AH
STACK equ 2000h
END