nesdev.com
http://forums.nesdev.com/

MIX
http://forums.nesdev.com/viewtopic.php?f=23&t=16497
Page 1 of 1

Author:  zzo38 [ Fri Sep 15, 2017 12:35 pm ]
Post subject:  MIX

Another old computer is MIX, although I think the hardware has never actually been made. Nevertheless I made up a word game for it. The code below is not MIXAL but is using the MIXPC assembler instead; also, it uses a nonstandard I/O unit 34 as a random number generator (on an implementation that doesn't support this (only MIXPC does support it), replace it with your own random number routine).

Code:
* Public domain word game
        BASE 100  [change this to 64 for use with binary MIX]
CWORD   EQU 0
DISPLAY EQU 3
        ORG 31

        * Load words from cards
        START
        ENT1 -16
1H      INC1 16
        IN WDATA,1(16)
        JBUS *(16)
        LDA WDATA,1
        JAZ 1B
        ST1 NWORDS(0:2)

        * Blank display line
        STZ DISPLAY+2
        STZ DISPLAY+6
        ENT1 DISPLAY+7
        MOVE DISPLAY+6(10)
        TEXT "W: B="
        STA DISPLAY+10(1:2)
        TEXT "L: B="
        STA DISPLAY+12(1:2)

        * Reset counts
RESET   STZ COUNTS
        ENTA 0
        CHAR
        STX DISPLAY+10(3:5)
        STX DISPLAY+12(3:5)

        * Clear letter use buffer
NEWGAME ENT1 LETT+1
        STZ LETT
        MOVE LETT(29)

        * Select random word to use
        IOC 0(34)  [change to whatever method you use for random numbers]
1H      IN 0(34)
        JBUS *(34)
        LDA 0(4:5)
        MUL =16=
NWORDS  DECX
        JXNN 1B
        STX *+1(0:2)
        ENN2
        LDX 0(1:1)
        DIV =5=
        SLAX 5
        INCA 1
        MUL =3=
        STX *+1(0:2)
        DEC2

        * Word found; initialize game
        ENT3 9  [number of remaining guesses]
        ENT1 CWORD
        MOVE WDATA,2(3)
        MOVE DASH(2)

        * Count how many letters
        ENT2 10
        LDA CWORD
        LDX CWORD+1
1H      SLAX 1
        DEC2 1
        JANZ 1B
        LDA CWORD+2
        JAZ 2F
1H      SLA 1
        DEC2 1
        JANZ 1B

        * Put asterisks
2H      LDA STAR
        LDX STAR
        J2N 1F
        SLAX ,2
1H      STA DISPLAY+3
        STX DISPLAY+4
        LDA STAR
        SLA 5,2
        STA DISPLAY+5

        * Fix count of how many letters
        ENN2 -10,2

        * Display game and ask for input
GAME    OUT DISPLAY(19)
        IN INBUF(19)
        JBUS *(19)
        LD1 INBUF(1:1)
        J1Z GAME
        CMP1 ='*'=
        JE RESET
        CMP1 ='Z'=
        JG GAME
        LDA LETT,1
        JANZ GAME

        * Check if letter is in word
        ST1 LETT,1
        ENTA ,1
        MUL =1(1:1),1(2:2),1(3:3),1(4:4),1(5:5)=
        ENT6 WRONG
        ENT4 2
3H      ENT5 5:5
1H      ST5 *+1(4:4)
        CMPX CWORD,4
        JNE 2F
        ST5 *+1(4:4)
        ST1 DISPLAY+3,4
        DEC2 1
        ENT6 RIGHT
2H      DEC5 1:1
        J5NZ 1B
        J4Z ,6
        DEC4 1
        JMP 3B

        * The letter doesn't match
WRONG   LDA DISPLAY
        LDX DISPLAY+1
        INCX ,1
        SLAX 1
        STA DISPLAY
        STX DISPLAY+1
        DEC3 1
        J3NZ GAME
        * You lose
        ENT1 LOSWRD
        MOVE CWORD(3)
        OUT LOSMSG(19)
        LDA COUNTS(3:4)
        INCA 1
        STA COUNTS(3:4)
        CHAR
        STX DISPLAY+12(3:5)
        JMP NEWGAME

        * The letter does match
RIGHT   J2NZ GAME
        * You win
        ENT1 WINWRD
        MOVE CWORD(3)
        OUT WINMSG(19)
        LDA COUNTS(1:2)
        INCA 1
        STA COUNTS(1:2)
        CHAR
        STX DISPLAY+10(3:5)
        JMP NEWGAME

        * Initialized data
DASH    TEXT "--------- "
STAR    TEXT "*****"
LOSMSG  TEXT "* YOU LOSE *  THE WORD IS:  "
LOSWRD  EQU *
        FILL LOSMSG+14
WINMSG  TEXT "* YOU WIN *   THE WORD IS:  "
WINWRD  EQU *
        FILL WINMSG+14

        * Uninitialized data
        END
COUNTS  ORG *+1
LETT    ORG *+30
INBUF   ORG *+14
WDATA   EQU *
        DECK WORDGAME.CRD

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/