; Mooreheim.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 . ; Mooreheim the Dice Game ; ; 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, 4000h 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 CHECKSWITCH6 IN 0FFH ANI 32 CNZ ROLLTHEMBONES IN 0FFH ANI 32 JZ CHECKSWITCH6 CALL OUTPUT CHECKSWITCH7 IN 0FFH ANI 64 CNZ ROLLTHEMBONES IN 0FFH ANI 64 JZ CHECKSWITCH7 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 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 NEWLINE DB CR, LF, 0H YOUROLLED DB "You rolled:", CR, LF, 0H CR equ 0DH LF equ 0AH END