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